Mercurial > pidgin.yaz
comparison src/protocols/simple/simple.c @ 12745:e788741f4840
[gaim-migrate @ 15092]
This should fix authentication. The nonce and realm were being parsed incorrectly - I broke the nonce completely earlier when trying to fix it being partially broken. This should also fix the Content-Length header having the wrong value for acknowledgements and errors (albeit somewhat ugly).
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 06 Jan 2006 06:00:51 +0000 |
parents | 2b61e6ed85c3 |
children | 4f7dab030b1a |
comparison
equal
deleted
inserted
replaced
12744:fcd9477e4476 | 12745:e788741f4840 |
---|---|
341 | 341 |
342 auth->type = 1; | 342 auth->type = 1; |
343 parts = g_strsplit(hdr, " ", 0); | 343 parts = g_strsplit(hdr, " ", 0); |
344 while(parts[i]) { | 344 while(parts[i]) { |
345 if(!strncmp(parts[i], "nonce", 5)) { | 345 if(!strncmp(parts[i], "nonce", 5)) { |
346 auth->nonce = g_strndup(parts[i]+7,strlen(parts[i]+7)-2); | 346 tmp = g_strstr_len(parts[i] + 7, |
347 strlen(parts[i] + 7), "\""); | |
348 if (tmp) { | |
349 auth->nonce = g_strndup(parts[i] + 7, | |
350 tmp - (parts[i] + 7)); | |
351 } | |
347 } | 352 } |
348 else if(!strncmp(parts[i], "realm", 5)) { | 353 else if(!strncmp(parts[i], "realm", 5)) { |
349 auth->realm = g_strndup(parts[i]+7,strlen(parts[i]+7)-2); | 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 } | |
350 } | 360 } |
351 i++; | 361 i++; |
352 } | 362 } |
353 g_strfreev(parts); | 363 g_strfreev(parts); |
354 | 364 |
355 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce, auth->realm); | 365 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce ? auth->nonce : "(null)", auth->realm ? auth->realm : "(null)"); |
356 | 366 |
357 auth->digest_session_key = gaim_cipher_http_digest_calculate_session_key( | 367 auth->digest_session_key = gaim_cipher_http_digest_calculate_session_key( |
358 "md5", sip->username, auth->realm, sip->password, auth->nonce, NULL); | 368 "md5", sip->username, auth->realm, sip->password, auth->nonce, NULL); |
359 | 369 |
360 auth->nc=1; | 370 auth->nc=1; |
444 | 454 |
445 static void send_sip_response(GaimConnection *gc, struct sipmsg *msg, int code, char *text, char *body) { | 455 static void send_sip_response(GaimConnection *gc, struct sipmsg *msg, int code, char *text, char *body) { |
446 GSList *tmp = msg->headers; | 456 GSList *tmp = msg->headers; |
447 gchar *name; | 457 gchar *name; |
448 gchar *value; | 458 gchar *value; |
459 gchar zero[2] = {'0', '\0'}; | |
449 GString *outstr = g_string_new(""); | 460 GString *outstr = g_string_new(""); |
450 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text); | 461 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text); |
451 while(tmp) { | 462 while(tmp) { |
452 name = ((struct siphdrelement*) (tmp->data))->name; | 463 name = ((struct siphdrelement*) (tmp->data))->name; |
453 value = ((struct siphdrelement*) (tmp->data))->value; | 464 value = ((struct siphdrelement*) (tmp->data))->value; |
465 | |
466 /* When sending the acknowlegements and errors, the content length from the original | |
467 message is still here, but there is no body; we need to make sure we're sending the | |
468 correct content length */ | |
469 if(strcmp(name, "Content-Length") == 0 && !body) { | |
470 value = zero; | |
471 } | |
472 | |
454 g_string_append_printf(outstr, "%s: %s\r\n", name, value); | 473 g_string_append_printf(outstr, "%s: %s\r\n", name, value); |
455 tmp = g_slist_next(tmp); | 474 tmp = g_slist_next(tmp); |
456 } | 475 } |
457 g_string_append_printf(outstr, "\r\n%s", body ? body : ""); | 476 g_string_append_printf(outstr, "\r\n%s", body ? body : ""); |
458 sendout_pkt(gc, outstr->str); | 477 sendout_pkt(gc, outstr->str); |
977 g_free(callid); | 996 g_free(callid); |
978 g_free(expire); | 997 g_free(expire); |
979 } | 998 } |
980 | 999 |
981 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) { | 1000 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) { |
982 int found = 0; | 1001 gboolean found = FALSE; |
983 if( msg->response == 0 ) { /* request */ | 1002 if(msg->response == 0) { /* request */ |
984 if(!strcmp(msg->method, "MESSAGE")) { | 1003 if(!strcmp(msg->method, "MESSAGE")) { |
985 process_incoming_message(sip, msg); | 1004 process_incoming_message(sip, msg); |
986 found = 1; | 1005 found = TRUE; |
987 } | 1006 } else if(!strcmp(msg->method, "NOTIFY")) { |
988 if(!strcmp(msg->method, "NOTIFY")) { | |
989 process_incoming_notify(sip, msg); | 1007 process_incoming_notify(sip, msg); |
990 found = 1; | 1008 found = TRUE; |
991 } | 1009 } else if(!strcmp(msg->method, "SUBSCRIBE")) { |
992 if(!strcmp(msg->method, "SUBSCRIBE")) { | |
993 process_incoming_subscribe(sip, msg); | 1010 process_incoming_subscribe(sip, msg); |
994 found = 1; | 1011 found = TRUE; |
995 } | 1012 } else { |
996 if(!found) { | |
997 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL); | 1013 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL); |
998 } | 1014 } |
999 } else { /* response */ | 1015 } else { /* response */ |
1000 struct transaction *trans = transactions_find(sip, msg); | 1016 struct transaction *trans = transactions_find(sip, msg); |
1001 if(trans) { | 1017 if(trans) { |
1030 (trans->callback)(sip, msg, trans); | 1046 (trans->callback)(sip, msg, trans); |
1031 } | 1047 } |
1032 transactions_remove(sip, trans); | 1048 transactions_remove(sip, trans); |
1033 } | 1049 } |
1034 } | 1050 } |
1035 found = 1; | 1051 found = TRUE; |
1036 } else { | 1052 } else { |
1037 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction"); | 1053 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction"); |
1038 } | 1054 } |
1039 } | 1055 } |
1040 if(!found) { | 1056 if(!found) { |