Browse Source

*** empty log message ***

Jan Janak 23 years ago
parent
commit
303ee7809d
6 changed files with 60 additions and 52 deletions
  1. 9 0
      parser/digest/digest.c
  2. 41 45
      parser/digest/digest_parser.c
  3. 5 0
      parser/hf.c
  4. 0 2
      parser/msg_parser.c
  5. 4 4
      parser/parse_event.c
  6. 1 1
      parser/parse_expires.c

+ 9 - 0
parser/digest/digest.c

@@ -10,6 +10,9 @@
 #include <stdio.h>          /* printf */
 
 
+/*
+ * Create and initialize a new credentials structure
+ */
 static inline int new_credentials(struct hdr_field* _h)
 {
 	auth_body_t* b;
@@ -31,6 +34,9 @@ static inline int new_credentials(struct hdr_field* _h)
 }
 
 
+/*
+ * Parse digest credentials
+ */
 int parse_credentials(struct hdr_field* _h)
 {
 	int res;
@@ -54,6 +60,9 @@ int parse_credentials(struct hdr_field* _h)
 }
 
 
+/*
+ * Free all memory
+ */
 void free_credentials(auth_body_t** _b)
 {
 	pkg_free(*_b);

+ 41 - 45
parser/digest/digest_parser.c

@@ -22,14 +22,6 @@
 #define ALG_MD5SESS_STR "MD5-sess"
 
 
-static inline int parse_quoted(str* _s, str* _r);
-static inline int parse_token(str* _s, str* _r);
-static inline int parse_digest_param(str* _s, dig_cred_t* _c);
-static inline int parse_digest_params(str* _s, dig_cred_t* _c);
-static int parse_qop(struct qp* _q);
-static int parse_algorithm(struct algorithm* _a);
-
-
 /*
  * Parse quoted string in a parameter body
  * return the string without quotes in _r
@@ -120,6 +112,11 @@ static inline int parse_token(str* _s, str* _r)
 		}
 	}
  out:
+	     /* Empty token is error */
+	if (i == 0) {
+	        return -2;
+	}
+
 	     /* Save length of the token */
         _r->len = i;
 
@@ -129,7 +126,7 @@ static inline int parse_token(str* _s, str* _r)
 	_s->s = _s->s + i;
 	_s->len -= i;
 
-	     /* Everyting went OK */
+	     /* Everything went OK */
 	return 0;
 }
 
@@ -179,7 +176,7 @@ static inline int parse_digest_param(str* _s, dig_cred_t* _c)
 	     /* If the first character is qoute, it is
 	      * a quoted string, otherwise it is a token
 	      */
-	if (*(_s->s) == '\"') {
+	if (_s->s[0] == '\"') {
 		if (parse_quoted(_s, ptr) < 0) {
 			return -3;
 		}
@@ -193,6 +190,39 @@ static inline int parse_digest_param(str* _s, dig_cred_t* _c)
 }
 
 
+/*
+ * Parse qop parameter body
+ */
+static inline int parse_qop(struct qp* _q)
+{
+	if (!strncasecmp(_q->qop_str.s, QOP_AUTH_STR, _q->qop_str.len)) {
+		_q->qop_parsed = QOP_AUTH;
+	} else if (!strncasecmp(_q->qop_str.s, QOP_AUTHINT_STR, _q->qop_str.len)) {
+		_q->qop_parsed = QOP_AUTHINT;
+	} else {
+		_q->qop_parsed = QOP_OTHER;
+	}
+	
+	return 0;
+}
+
+
+/*
+ * Parse algorithm parameter body
+ */
+static inline int parse_algorithm(struct algorithm* _a)
+{
+	if (!strncasecmp(_a->alg_str.s, ALG_MD5_STR, _a->alg_str.len)) {
+		_a->alg_parsed = ALG_MD5;
+	} else if (!strncasecmp(_a->alg_str.s, ALG_MD5SESS_STR, _a->alg_str.len)) {
+		_a->alg_parsed = ALG_MD5SESS;
+	} else {
+		_a->alg_parsed = ALG_OTHER;
+	}
+
+	return 0;
+}
+
 
 /*
  * Parse Digest credentials parameter, one by one
@@ -239,40 +269,6 @@ static inline int parse_digest_params(str* _s, dig_cred_t* _c)
 }
 
 
-/*
- * Parse qop parameter body
- */
-static int parse_qop(struct qp* _q)
-{
-	if (!strncasecmp(_q->qop_str.s, QOP_AUTH_STR, _q->qop_str.len)) {
-		_q->qop_parsed = QOP_AUTH;
-	} else if (!strncasecmp(_q->qop_str.s, QOP_AUTHINT_STR, _q->qop_str.len)) {
-		_q->qop_parsed = QOP_AUTHINT;
-	} else {
-		_q->qop_parsed = QOP_OTHER;
-	}
-	
-	return 0;
-}
-
-
-/*
- * Parse algorithm parameter body
- */
-static int parse_algorithm(struct algorithm* _a)
-{
-	if (!strncasecmp(_a->alg_str.s, ALG_MD5_STR, _a->alg_str.len)) {
-		_a->alg_parsed = ALG_MD5;
-	} else if (!strncasecmp(_a->alg_str.s, ALG_MD5SESS_STR, _a->alg_str.len)) {
-		_a->alg_parsed = ALG_MD5SESS;
-	} else {
-		_a->alg_parsed = ALG_OTHER;
-	}
-
-	return 0;
-}
-
-
 /*
  * We support Digest authentication only
  *
@@ -286,7 +282,7 @@ int parse_digest_cred(str* _s, dig_cred_t* _c)
 	str tmp;
 
 	     /* Make a temporary copy, we are
-	      * gonna to modify it 
+	      * going to modify it 
 	      */
 	tmp.s = _s->s;
 	tmp.len = _s->len;

+ 5 - 0
parser/hf.c

@@ -12,6 +12,7 @@
 #include "digest/digest.h" /* free_credentials */
 #include "parse_event.h"
 #include "parse_expires.h"
+#include "contact/parse_contact.h"
 
 
 /* 
@@ -51,6 +52,10 @@ void clean_hdr_field(struct hdr_field* hf)
 			free_expires((exp_body_t**)(&(hf->parsed)));
 			break;
 
+		case HDR_CONTACT:
+			free_contact((contact_body_t**)(&(hf->parsed)));
+			break;
+
 		default:
 			LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
 			    hf->type);

+ 0 - 2
parser/msg_parser.c

@@ -19,8 +19,6 @@
 #include "../globals.h"
 #include "parse_hname2.h"
 
-
-
 #ifdef DEBUG_DMALLOC
 #include <mem/dmalloc.h>
 #endif

+ 4 - 4
parser/parse_event.c

@@ -59,10 +59,10 @@ static inline int event_parser(char* _s, int _l, event_t* _e)
 
 	end = skip_token_nodot(tmp.s, tmp.len);
 
-	tmp.len = end - tmp.s;
+	_e->text.len = end - tmp.s;
 
-	if ((tmp.len == PRES_STR_LEN) && 
-	    !strncasecmp(PRES_STR, tmp.s, tmp.len)) {
+	if ((_e->text.len == PRES_STR_LEN) && 
+	    !strncasecmp(PRES_STR, tmp.s, _e->text.len)) {
 		_e->parsed = EVENT_PRESENCE;
 	} else {
 		_e->parsed = EVENT_OTHER;
@@ -118,7 +118,7 @@ void free_event(event_t** _e)
 void print_event(event_t* _e)
 {
 	printf("===Event===\n");
-	printf("text  : %.*s\n", _e->text.len, _e->text.s);
+	printf("text  : \'%.*s\'\n", _e->text.len, _e->text.s);
 	printf("parsed: %s\n", 
 	       (_e->parsed == EVENT_PRESENCE) ? ("EVENT_PRESENCE") : ("EVENT_OTHER"));
 	printf("===/Event===\n");

+ 1 - 1
parser/parse_expires.c

@@ -100,7 +100,7 @@ void free_expires(exp_body_t** _e)
 void print_expires(exp_body_t* _e)
 {
 	printf("===Expires===\n");
-	printf("text: %.*s\n", _e->text.len, _e->text.s);
+	printf("text: \'%.*s\'\n", _e->text.len, _e->text.s);
 	printf("val : %d\n", _e->val);
 	printf("===/Expires===\n");
 }