... | ... |
@@ -10,6 +10,9 @@ |
10 | 10 |
#include <stdio.h> /* printf */ |
11 | 11 |
|
12 | 12 |
|
13 |
+/* |
|
14 |
+ * Create and initialize a new credentials structure |
|
15 |
+ */ |
|
13 | 16 |
static inline int new_credentials(struct hdr_field* _h) |
14 | 17 |
{ |
15 | 18 |
auth_body_t* b; |
... | ... |
@@ -31,6 +34,9 @@ static inline int new_credentials(struct hdr_field* _h) |
31 | 34 |
} |
32 | 35 |
|
33 | 36 |
|
37 |
+/* |
|
38 |
+ * Parse digest credentials |
|
39 |
+ */ |
|
34 | 40 |
int parse_credentials(struct hdr_field* _h) |
35 | 41 |
{ |
36 | 42 |
int res; |
... | ... |
@@ -54,6 +60,9 @@ int parse_credentials(struct hdr_field* _h) |
54 | 60 |
} |
55 | 61 |
|
56 | 62 |
|
63 |
+/* |
|
64 |
+ * Free all memory |
|
65 |
+ */ |
|
57 | 66 |
void free_credentials(auth_body_t** _b) |
58 | 67 |
{ |
59 | 68 |
pkg_free(*_b); |
... | ... |
@@ -22,14 +22,6 @@ |
22 | 22 |
#define ALG_MD5SESS_STR "MD5-sess" |
23 | 23 |
|
24 | 24 |
|
25 |
-static inline int parse_quoted(str* _s, str* _r); |
|
26 |
-static inline int parse_token(str* _s, str* _r); |
|
27 |
-static inline int parse_digest_param(str* _s, dig_cred_t* _c); |
|
28 |
-static inline int parse_digest_params(str* _s, dig_cred_t* _c); |
|
29 |
-static int parse_qop(struct qp* _q); |
|
30 |
-static int parse_algorithm(struct algorithm* _a); |
|
31 |
- |
|
32 |
- |
|
33 | 25 |
/* |
34 | 26 |
* Parse quoted string in a parameter body |
35 | 27 |
* return the string without quotes in _r |
... | ... |
@@ -120,6 +112,11 @@ static inline int parse_token(str* _s, str* _r) |
120 | 112 |
} |
121 | 113 |
} |
122 | 114 |
out: |
115 |
+ /* Empty token is error */ |
|
116 |
+ if (i == 0) { |
|
117 |
+ return -2; |
|
118 |
+ } |
|
119 |
+ |
|
123 | 120 |
/* Save length of the token */ |
124 | 121 |
_r->len = i; |
125 | 122 |
|
... | ... |
@@ -129,7 +126,7 @@ static inline int parse_token(str* _s, str* _r) |
129 | 126 |
_s->s = _s->s + i; |
130 | 127 |
_s->len -= i; |
131 | 128 |
|
132 |
- /* Everyting went OK */ |
|
129 |
+ /* Everything went OK */ |
|
133 | 130 |
return 0; |
134 | 131 |
} |
135 | 132 |
|
... | ... |
@@ -179,7 +176,7 @@ static inline int parse_digest_param(str* _s, dig_cred_t* _c) |
179 | 176 |
/* If the first character is qoute, it is |
180 | 177 |
* a quoted string, otherwise it is a token |
181 | 178 |
*/ |
182 |
- if (*(_s->s) == '\"') { |
|
179 |
+ if (_s->s[0] == '\"') { |
|
183 | 180 |
if (parse_quoted(_s, ptr) < 0) { |
184 | 181 |
return -3; |
185 | 182 |
} |
... | ... |
@@ -193,6 +190,39 @@ static inline int parse_digest_param(str* _s, dig_cred_t* _c) |
193 | 190 |
} |
194 | 191 |
|
195 | 192 |
|
193 |
+/* |
|
194 |
+ * Parse qop parameter body |
|
195 |
+ */ |
|
196 |
+static inline int parse_qop(struct qp* _q) |
|
197 |
+{ |
|
198 |
+ if (!strncasecmp(_q->qop_str.s, QOP_AUTH_STR, _q->qop_str.len)) { |
|
199 |
+ _q->qop_parsed = QOP_AUTH; |
|
200 |
+ } else if (!strncasecmp(_q->qop_str.s, QOP_AUTHINT_STR, _q->qop_str.len)) { |
|
201 |
+ _q->qop_parsed = QOP_AUTHINT; |
|
202 |
+ } else { |
|
203 |
+ _q->qop_parsed = QOP_OTHER; |
|
204 |
+ } |
|
205 |
+ |
|
206 |
+ return 0; |
|
207 |
+} |
|
208 |
+ |
|
209 |
+ |
|
210 |
+/* |
|
211 |
+ * Parse algorithm parameter body |
|
212 |
+ */ |
|
213 |
+static inline int parse_algorithm(struct algorithm* _a) |
|
214 |
+{ |
|
215 |
+ if (!strncasecmp(_a->alg_str.s, ALG_MD5_STR, _a->alg_str.len)) { |
|
216 |
+ _a->alg_parsed = ALG_MD5; |
|
217 |
+ } else if (!strncasecmp(_a->alg_str.s, ALG_MD5SESS_STR, _a->alg_str.len)) { |
|
218 |
+ _a->alg_parsed = ALG_MD5SESS; |
|
219 |
+ } else { |
|
220 |
+ _a->alg_parsed = ALG_OTHER; |
|
221 |
+ } |
|
222 |
+ |
|
223 |
+ return 0; |
|
224 |
+} |
|
225 |
+ |
|
196 | 226 |
|
197 | 227 |
/* |
198 | 228 |
* Parse Digest credentials parameter, one by one |
... | ... |
@@ -239,40 +269,6 @@ static inline int parse_digest_params(str* _s, dig_cred_t* _c) |
239 | 269 |
} |
240 | 270 |
|
241 | 271 |
|
242 |
-/* |
|
243 |
- * Parse qop parameter body |
|
244 |
- */ |
|
245 |
-static int parse_qop(struct qp* _q) |
|
246 |
-{ |
|
247 |
- if (!strncasecmp(_q->qop_str.s, QOP_AUTH_STR, _q->qop_str.len)) { |
|
248 |
- _q->qop_parsed = QOP_AUTH; |
|
249 |
- } else if (!strncasecmp(_q->qop_str.s, QOP_AUTHINT_STR, _q->qop_str.len)) { |
|
250 |
- _q->qop_parsed = QOP_AUTHINT; |
|
251 |
- } else { |
|
252 |
- _q->qop_parsed = QOP_OTHER; |
|
253 |
- } |
|
254 |
- |
|
255 |
- return 0; |
|
256 |
-} |
|
257 |
- |
|
258 |
- |
|
259 |
-/* |
|
260 |
- * Parse algorithm parameter body |
|
261 |
- */ |
|
262 |
-static int parse_algorithm(struct algorithm* _a) |
|
263 |
-{ |
|
264 |
- if (!strncasecmp(_a->alg_str.s, ALG_MD5_STR, _a->alg_str.len)) { |
|
265 |
- _a->alg_parsed = ALG_MD5; |
|
266 |
- } else if (!strncasecmp(_a->alg_str.s, ALG_MD5SESS_STR, _a->alg_str.len)) { |
|
267 |
- _a->alg_parsed = ALG_MD5SESS; |
|
268 |
- } else { |
|
269 |
- _a->alg_parsed = ALG_OTHER; |
|
270 |
- } |
|
271 |
- |
|
272 |
- return 0; |
|
273 |
-} |
|
274 |
- |
|
275 |
- |
|
276 | 272 |
/* |
277 | 273 |
* We support Digest authentication only |
278 | 274 |
* |
... | ... |
@@ -286,7 +282,7 @@ int parse_digest_cred(str* _s, dig_cred_t* _c) |
286 | 282 |
str tmp; |
287 | 283 |
|
288 | 284 |
/* Make a temporary copy, we are |
289 |
- * gonna to modify it |
|
285 |
+ * going to modify it |
|
290 | 286 |
*/ |
291 | 287 |
tmp.s = _s->s; |
292 | 288 |
tmp.len = _s->len; |
... | ... |
@@ -12,6 +12,7 @@ |
12 | 12 |
#include "digest/digest.h" /* free_credentials */ |
13 | 13 |
#include "parse_event.h" |
14 | 14 |
#include "parse_expires.h" |
15 |
+#include "contact/parse_contact.h" |
|
15 | 16 |
|
16 | 17 |
|
17 | 18 |
/* |
... | ... |
@@ -51,6 +52,10 @@ void clean_hdr_field(struct hdr_field* hf) |
51 | 52 |
free_expires((exp_body_t**)(&(hf->parsed))); |
52 | 53 |
break; |
53 | 54 |
|
55 |
+ case HDR_CONTACT: |
|
56 |
+ free_contact((contact_body_t**)(&(hf->parsed))); |
|
57 |
+ break; |
|
58 |
+ |
|
54 | 59 |
default: |
55 | 60 |
LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n", |
56 | 61 |
hf->type); |
... | ... |
@@ -59,10 +59,10 @@ static inline int event_parser(char* _s, int _l, event_t* _e) |
59 | 59 |
|
60 | 60 |
end = skip_token_nodot(tmp.s, tmp.len); |
61 | 61 |
|
62 |
- tmp.len = end - tmp.s; |
|
62 |
+ _e->text.len = end - tmp.s; |
|
63 | 63 |
|
64 |
- if ((tmp.len == PRES_STR_LEN) && |
|
65 |
- !strncasecmp(PRES_STR, tmp.s, tmp.len)) { |
|
64 |
+ if ((_e->text.len == PRES_STR_LEN) && |
|
65 |
+ !strncasecmp(PRES_STR, tmp.s, _e->text.len)) { |
|
66 | 66 |
_e->parsed = EVENT_PRESENCE; |
67 | 67 |
} else { |
68 | 68 |
_e->parsed = EVENT_OTHER; |
... | ... |
@@ -118,7 +118,7 @@ void free_event(event_t** _e) |
118 | 118 |
void print_event(event_t* _e) |
119 | 119 |
{ |
120 | 120 |
printf("===Event===\n"); |
121 |
- printf("text : %.*s\n", _e->text.len, _e->text.s); |
|
121 |
+ printf("text : \'%.*s\'\n", _e->text.len, _e->text.s); |
|
122 | 122 |
printf("parsed: %s\n", |
123 | 123 |
(_e->parsed == EVENT_PRESENCE) ? ("EVENT_PRESENCE") : ("EVENT_OTHER")); |
124 | 124 |
printf("===/Event===\n"); |
... | ... |
@@ -100,7 +100,7 @@ void free_expires(exp_body_t** _e) |
100 | 100 |
void print_expires(exp_body_t* _e) |
101 | 101 |
{ |
102 | 102 |
printf("===Expires===\n"); |
103 |
- printf("text: %.*s\n", _e->text.len, _e->text.s); |
|
103 |
+ printf("text: \'%.*s\'\n", _e->text.len, _e->text.s); |
|
104 | 104 |
printf("val : %d\n", _e->val); |
105 | 105 |
printf("===/Expires===\n"); |
106 | 106 |
} |