Browse code

- rearranged structure fields and removed DIGEST_DOMAIN again (now used by default)

Jan Janak authored on 05/03/2003 10:43:11
Showing 3 changed files
... ...
@@ -115,7 +115,7 @@ dig_err_t check_dig_cred(dig_cred_t* _c)
115 115
 	dig_err_t res = E_DIG_OK;
116 116
 
117 117
 	     /* Username must be present */
118
-	if (_c->username.s == 0) res |= E_DIG_USERNAME;
118
+	if (_c->username.whole.s == 0) res |= E_DIG_USERNAME;
119 119
 
120 120
 	     /* Realm must be present */
121 121
 	if (_c->realm.s == 0) res |= E_DIG_REALM;
... ...
@@ -151,10 +151,10 @@ void print_cred(dig_cred_t* _c)
151 151
 {
152 152
 	printf("===Digest credentials===\n");
153 153
 	if (_c) {
154
-		printf("Username  = \'%.*s\'\n", _c->username.len, _c->username.s);
155
-#ifdef DIGEST_DOMAIN
156
-		printf("Domain    = \'%.*s\'\n", _c->domain.len, _c->domain.s);
157
-#endif
154
+		printf("Username\n");
155
+		printf("+--whole  = \'%.*s\'\n", _c->username.whole.len, _c->username.whole.s);
156
+		printf("+--user   = \'%.*s\'\n", _c->username.user.len, _c->username.user.s);
157
+		printf("\\--domain = \'%.*s\'\n", _c->username.domain.len, _c->username.domain.s);
158 158
 		printf("Realm     = \'%.*s\'\n", _c->realm.len, _c->realm.s);
159 159
 		printf("Nonce     = \'%.*s\'\n", _c->nonce.len, _c->nonce.s);
160 160
 		printf("URI       = \'%.*s\'\n", _c->uri.len, _c->uri.s);
... ...
@@ -186,18 +186,18 @@ static inline int parse_digest_param(str* _s, dig_cred_t* _c)
186 186
 	      * body content will be stored
187 187
 	      */
188 188
 	switch(t) {
189
-	case PAR_USERNAME:  ptr = &(_c->username);    break;
190
-	case PAR_REALM:     ptr = &(_c->realm);       break;
191
-	case PAR_NONCE:     ptr = &(_c->nonce);       break;
192
-	case PAR_URI:       ptr = &(_c->uri);         break;
193
-	case PAR_RESPONSE:  ptr = &(_c->response);    break;
194
-	case PAR_CNONCE:    ptr = &(_c->cnonce);      break;
195
-	case PAR_OPAQUE:    ptr = &(_c->opaque);      break;
196
-	case PAR_QOP:       ptr = &(_c->qop.qop_str); break;
197
-	case PAR_NC:        ptr = &(_c->nc);          break;
198
-	case PAR_ALGORITHM: ptr = &(_c->alg.alg_str); break;
199
-	case PAR_OTHER:     ptr = &dummy;             break;
200
-	default:            ptr = &dummy;             break;
189
+	case PAR_USERNAME:  ptr = &(_c->username.whole);  break;
190
+	case PAR_REALM:     ptr = &(_c->realm);           break;
191
+	case PAR_NONCE:     ptr = &(_c->nonce);           break;
192
+	case PAR_URI:       ptr = &(_c->uri);             break;
193
+	case PAR_RESPONSE:  ptr = &(_c->response);        break;
194
+	case PAR_CNONCE:    ptr = &(_c->cnonce);          break;
195
+	case PAR_OPAQUE:    ptr = &(_c->opaque);          break;
196
+	case PAR_QOP:       ptr = &(_c->qop.qop_str);     break;
197
+	case PAR_NC:        ptr = &(_c->nc);              break;
198
+	case PAR_ALGORITHM: ptr = &(_c->alg.alg_str);     break;
199
+	case PAR_OTHER:     ptr = &dummy;                 break;
200
+	default:            ptr = &dummy;                 break;
201 201
 	}
202 202
 
203 203
 	     /* If the first character is qoute, it is
... ...
@@ -264,29 +264,26 @@ static inline void parse_algorithm(struct algorithm* _a)
264 264
 	}	
265 265
 }
266 266
 
267
-#ifdef DIGEST_DOMAIN
267
+
268 268
 /*
269
- * Parse username for domain
269
+ * Parse username for user and domain parts
270 270
  */
271
-static inline void parse_domain(struct dig_cred* _c)
271
+static inline void parse_username(struct username* _u)
272 272
 {
273 273
 	char* d;
274 274
 
275
-	if (_c->username.len <= 2) return;
275
+	_u->user = _u->whole;
276
+	if (_u->whole.len <= 2) return;
276 277
 
277
-	d = q_memchr(_c->username.s, '@', _c->username.len);
278
+	d = q_memchr(_u->whole.s, '@', _u->whole.len);
278 279
 
279 280
 	if (d) {
280
-		_c->domain.s = d;
281
-		_c->domain.len = _c->username.len - (d - _c->username.s) - 1;
282
-		_c->username.len = d - _c->username.s;
281
+		_u->domain.s = d;
282
+		_u->domain.len = _u->whole.len - (d - _u->whole.s) - 1;
283
+		_u->user.len = d - _u->user.s;
283 284
 	}
284 285
 }
285 286
 
286
-#endif
287
-
288
-
289
-
290 287
 
291 288
 /*
292 289
  * Parse Digest credentials parameter, one by one
... ...
@@ -325,9 +322,7 @@ static inline int parse_digest_params(str* _s, dig_cred_t* _c)
325 322
 		parse_algorithm(&(_c->alg));
326 323
 	}
327 324
 
328
-#ifdef DIGEST_DOMAIN
329
-	parse_domain(_c);
330
-#endif
325
+	parse_username(&_c->username);
331 326
 
332 327
 	return 0;
333 328
 }
... ...
@@ -67,24 +67,29 @@ struct qp {
67 67
 };
68 68
 
69 69
 
70
+/* Username structure */
71
+struct username {
72
+	str whole;        /* The whole username parameter value */
73
+	str user;         /* username part only */
74
+	str domain;       /* Domain part only */
75
+};
76
+
77
+
70 78
 /*
71 79
  * Parsed digest credentials
72 80
  */
73 81
 typedef struct dig_cred {
74
-	str username;         /* Username */
75
-#ifdef DIGEST_DOMAIN
76
-	str domain;           /* Domain contained in username */
77
-#endif
78
-	str realm;            /* Realm */
79
-	str nonce;            /* Nonce value */
80
-	str uri;              /* URI */
81
-	str response;         /* Response string */
82
-	str algorithm;        /* Algorithm in string representation */
83
-	struct algorithm alg; /* Type of algorithm used */
84
-	str cnonce;           /* Cnonce value */
85
-	str opaque;           /* Opaque data string */
86
-	struct qp qop;        /* Quality Of Protection */
87
-	str nc;               /* Nonce count parameter */
82
+	struct username username;   /* Username */
83
+	str realm;                  /* Realm */
84
+	str nonce;                  /* Nonce value */
85
+	str uri;                    /* URI */
86
+	str response;               /* Response string */
87
+	str algorithm;              /* Algorithm in string representation */
88
+	struct algorithm alg;       /* Type of algorithm used */
89
+	str cnonce;                 /* Cnonce value */
90
+	str opaque;                 /* Opaque data string */
91
+	struct qp qop;              /* Quality Of Protection */
92
+	str nc;                     /* Nonce count parameter */
88 93
 } dig_cred_t;
89 94
 
90 95