Mercurial > pidgin
comparison src/protocols/simple/simple.c @ 12746:4f7dab030b1a
[gaim-migrate @ 15093]
abstract to a function and robustify the rest of the attribute parsing
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 06 Jan 2006 06:33:46 +0000 |
parents | e788741f4840 |
children | dd271caf25b0 |
comparison
equal
deleted
inserted
replaced
12745:e788741f4840 | 12746:4f7dab030b1a |
---|---|
297 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n", sip->username, auth->realm, auth->nonce, target, noncecount, response); | 297 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n", sip->username, auth->realm, auth->nonce, target, noncecount, response); |
298 g_free(response); | 298 g_free(response); |
299 return ret; | 299 return ret; |
300 } | 300 } |
301 | 301 |
302 static char * parse_attribute(const char *attrname, char *source) { | |
303 char *tmp, *tmp2, *retval = NULL; | |
304 int len = strlen(attrname); | |
305 | |
306 if(!strncmp(source, attrname, len)) { | |
307 tmp = source + len; | |
308 tmp2 = g_strstr_len(tmp, strlen(tmp), "\""); | |
309 if(tmp2) | |
310 retval = g_strndup(tmp, tmp2 - tmp); | |
311 } | |
312 | |
313 return retval; | |
314 } | |
315 | |
302 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { | 316 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { |
303 int i=0; | 317 int i=0; |
304 char *tmp; | 318 char *tmp; |
305 char *tmp2; | |
306 gchar **parts; | 319 gchar **parts; |
307 if(!hdr) { | 320 if(!hdr) { |
308 gaim_debug_error("simple", "fill_auth: hdr==NULL\n"); | 321 gaim_debug_error("simple", "fill_auth: hdr==NULL\n"); |
309 return; | 322 return; |
310 } | 323 } |
313 gaim_debug_info("simple", "found NTLM\n"); | 326 gaim_debug_info("simple", "found NTLM\n"); |
314 auth->type = 2; | 327 auth->type = 2; |
315 if(!auth->nonce && !auth->nc) { | 328 if(!auth->nonce && !auth->nc) { |
316 parts = g_strsplit(hdr, " ", 0); | 329 parts = g_strsplit(hdr, " ", 0); |
317 while(parts[i]) { | 330 while(parts[i]) { |
318 if(!strncmp(parts[i],"targetname",10)) { | 331 if((tmp = parse_attribute("targetname=\"", |
319 auth->target = g_strndup(parts[i]+12,strlen(parts[i]+12)-1); | 332 parts[i]))) { |
333 auth->target = tmp; | |
320 } | 334 } |
321 if(!strncmp(parts[i],"realm",5)) { | 335 else if((tmp = parse_attribute("realm=\"", |
322 tmp = strstr(hdr, "realm="); | 336 parts[i]))) { |
323 tmp += 7; | 337 auth->realm = tmp; |
324 tmp2 = strchr(tmp, '"'); | |
325 *tmp2 = 0; | |
326 auth->realm = g_strdup(tmp); | |
327 *tmp2 = '"'; | |
328 } | 338 } |
329 i++; | 339 i++; |
330 } | 340 } |
331 g_strfreev(parts); | 341 g_strfreev(parts); |
332 parts = NULL; | 342 parts = NULL; |
340 } | 350 } |
341 | 351 |
342 auth->type = 1; | 352 auth->type = 1; |
343 parts = g_strsplit(hdr, " ", 0); | 353 parts = g_strsplit(hdr, " ", 0); |
344 while(parts[i]) { | 354 while(parts[i]) { |
345 if(!strncmp(parts[i], "nonce", 5)) { | 355 if((tmp = parse_attribute("nonce=\"", parts[i]))) { |
346 tmp = g_strstr_len(parts[i] + 7, | 356 auth->nonce = tmp; |
347 strlen(parts[i] + 7), "\""); | 357 } |
348 if (tmp) { | 358 else if((tmp = parse_attribute("realm=\"", parts[i]))) { |
349 auth->nonce = g_strndup(parts[i] + 7, | 359 auth->realm = tmp; |
350 tmp - (parts[i] + 7)); | |
351 } | |
352 } | |
353 else if(!strncmp(parts[i], "realm", 5)) { | |
354 tmp = g_strstr_len(parts[i] + 7, | |
355 strlen(parts[i] + 7), "\""); | |
356 if (tmp) { | |
357 auth->realm = g_strndup(parts[i] + 7, | |
358 tmp - (parts[i] + 7)); | |
359 } | |
360 } | 360 } |
361 i++; | 361 i++; |
362 } | 362 } |
363 g_strfreev(parts); | 363 g_strfreev(parts); |
364 | 364 |
1052 } else { | 1052 } else { |
1053 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction"); | 1053 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction"); |
1054 } | 1054 } |
1055 } | 1055 } |
1056 if(!found) { | 1056 if(!found) { |
1057 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a unknown sip message with method %sand response %d\n",msg->method, msg->response); | 1057 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a unknown sip message with method %s and response %d\n",msg->method, msg->response); |
1058 } | 1058 } |
1059 } | 1059 } |
1060 | 1060 |
1061 static void process_input(struct simple_account_data *sip, struct sip_connection *conn) | 1061 static void process_input(struct simple_account_data *sip, struct sip_connection *conn) |
1062 { | 1062 { |