Mercurial > pidgin.yaz
comparison libpurple/protocols/simple/simple.c @ 19997:6e93a79b2ae5
Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 13 Sep 2007 21:34:55 +0000 |
parents | 44b4e8bd759b |
children | 885320299776 9acf4a2ef166 5723dbc6212d |
comparison
equal
deleted
inserted
replaced
19996:c9f994a88f5f | 19997:6e93a79b2ae5 |
---|---|
691 static char *get_contact(struct simple_account_data *sip) { | 691 static char *get_contact(struct simple_account_data *sip) { |
692 return g_strdup_printf("<sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"", sip->username, purple_network_get_my_ip(-1), sip->listenport, sip->udp ? "udp" : "tcp"); | 692 return g_strdup_printf("<sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"", sip->username, purple_network_get_my_ip(-1), sip->listenport, sip->udp ? "udp" : "tcp"); |
693 } | 693 } |
694 | 694 |
695 static void do_register_exp(struct simple_account_data *sip, int expire) { | 695 static void do_register_exp(struct simple_account_data *sip, int expire) { |
696 char *uri = g_strdup_printf("sip:%s", sip->servername); | 696 char *uri, *to, *contact, *hdr; |
697 char *to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | 697 |
698 char *contact = get_contact(sip); | 698 /* Set our default expiration to 900, |
699 char *hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire); | 699 * as done in the initialization of the simple_account_data |
700 * structure. | |
701 */ | |
702 if (!expire) | |
703 expire = 900; | |
704 | |
705 sip->reregister = time(NULL) + expire - 50; | |
706 | |
707 uri = g_strdup_printf("sip:%s", sip->servername); | |
708 to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | |
709 contact = get_contact(sip); | |
710 hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire); | |
700 g_free(contact); | 711 g_free(contact); |
701 | 712 |
702 sip->registerstatus = 1; | 713 sip->registerstatus = SIMPLE_REGISTER_SENT; |
703 | |
704 if(expire) { | |
705 sip->reregister = time(NULL) + expire - 50; | |
706 } else { | |
707 sip->reregister = time(NULL) + 600; | |
708 } | |
709 | 714 |
710 send_sip_request(sip->gc, "REGISTER", uri, to, hdr, "", NULL, | 715 send_sip_request(sip->gc, "REGISTER", uri, to, hdr, "", NULL, |
711 process_register_response); | 716 process_register_response); |
712 | 717 |
713 g_free(hdr); | 718 g_free(hdr); |
1011 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | 1016 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { |
1012 gchar *tmp; | 1017 gchar *tmp; |
1013 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); | 1018 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); |
1014 switch (msg->response) { | 1019 switch (msg->response) { |
1015 case 200: | 1020 case 200: |
1016 if(sip->registerstatus < 3) { /* registered */ | 1021 if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */ |
1017 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { | 1022 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { |
1018 send_publish(sip); | 1023 send_publish(sip); |
1019 } | 1024 } |
1020 } | 1025 } |
1021 sip->registerstatus = 3; | 1026 sip->registerstatus = SIMPLE_REGISTER_COMPLETE; |
1022 purple_connection_set_state(sip->gc, PURPLE_CONNECTED); | 1027 purple_connection_set_state(sip->gc, PURPLE_CONNECTED); |
1023 | 1028 |
1024 /* get buddies from blist */ | 1029 /* get buddies from blist */ |
1025 simple_get_buddies(sip->gc); | 1030 simple_get_buddies(sip->gc); |
1026 | 1031 |
1030 simple_subscribe_buddylist(sip); | 1035 simple_subscribe_buddylist(sip); |
1031 } | 1036 } |
1032 | 1037 |
1033 break; | 1038 break; |
1034 case 401: | 1039 case 401: |
1035 if(sip->registerstatus != 2) { | 1040 if(sip->registerstatus != SIMPLE_REGISTER_RETRY) { |
1036 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries); | 1041 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries); |
1037 if(sip->registrar.retries > 3) { | 1042 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { |
1043 purple_debug_info("simple", "Setting wants_to_die to true.\n"); | |
1038 sip->gc->wants_to_die = TRUE; | 1044 sip->gc->wants_to_die = TRUE; |
1039 purple_connection_error(sip->gc, _("Incorrect password.")); | 1045 purple_connection_error(sip->gc, _("Incorrect password.")); |
1040 return TRUE; | 1046 return TRUE; |
1041 } | 1047 } |
1042 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); | 1048 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); |
1043 fill_auth(sip, tmp, &sip->registrar); | 1049 fill_auth(sip, tmp, &sip->registrar); |
1044 sip->registerstatus = 2; | 1050 sip->registerstatus = SIMPLE_REGISTER_RETRY; |
1051 do_register(sip); | |
1052 } | |
1053 break; | |
1054 default: | |
1055 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { | |
1056 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); | |
1057 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { | |
1058 sip->gc->wants_to_die = TRUE; | |
1059 purple_connection_error(sip->gc, _("Unknown server response.")); | |
1060 return TRUE; | |
1061 } | |
1062 sip->registerstatus = SIMPLE_REGISTER_RETRY; | |
1045 do_register(sip); | 1063 do_register(sip); |
1046 } | 1064 } |
1047 break; | 1065 break; |
1048 } | 1066 } |
1049 return TRUE; | 1067 return TRUE; |
1325 /* ignore provisional response */ | 1343 /* ignore provisional response */ |
1326 purple_debug_info("simple", "got trying response\n"); | 1344 purple_debug_info("simple", "got trying response\n"); |
1327 } else { | 1345 } else { |
1328 sip->proxy.retries = 0; | 1346 sip->proxy.retries = 0; |
1329 if(!strcmp(trans->msg->method, "REGISTER")) { | 1347 if(!strcmp(trans->msg->method, "REGISTER")) { |
1330 if(msg->response == 401) sip->registrar.retries++; | 1348 |
1331 else sip->registrar.retries = 0; | 1349 /* This is encountered when a REGISTER request was ... |
1350 */ | |
1351 if(msg->response == 401) { | |
1352 /* denied until further authentication was provided. */ | |
1353 sip->registrar.retries++; | |
1354 } | |
1355 else if (msg->response != 200) { | |
1356 /* denied for some other reason! */ | |
1357 sip->registrar.retries++; | |
1358 } | |
1359 else { | |
1360 /* accepted! */ | |
1361 sip->registrar.retries = 0; | |
1362 } | |
1332 } else { | 1363 } else { |
1333 if(msg->response == 401) { | 1364 if(msg->response == 401) { |
1365 /* This is encountered when a generic (MESSAGE, NOTIFY, etc) | |
1366 * was denied until further authorization is provided. | |
1367 */ | |
1334 gchar *resend, *auth, *ptmp; | 1368 gchar *resend, *auth, *ptmp; |
1335 | 1369 |
1336 if(sip->registrar.retries > 4) return; | 1370 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) return; |
1337 sip->registrar.retries++; | 1371 sip->registrar.retries++; |
1338 | 1372 |
1339 ptmp = sipmsg_find_header(msg, "WWW-Authenticate"); | 1373 ptmp = sipmsg_find_header(msg, "WWW-Authenticate"); |
1340 | 1374 |
1341 fill_auth(sip, ptmp, &sip->registrar); | 1375 fill_auth(sip, ptmp, &sip->registrar); |
1345 g_free(auth); | 1379 g_free(auth); |
1346 resend = sipmsg_to_string(trans->msg); | 1380 resend = sipmsg_to_string(trans->msg); |
1347 /* resend request */ | 1381 /* resend request */ |
1348 sendout_pkt(sip->gc, resend); | 1382 sendout_pkt(sip->gc, resend); |
1349 g_free(resend); | 1383 g_free(resend); |
1384 } else { | |
1385 /* Reset any count of retries that may have | |
1386 * accumulated in the above branch. | |
1387 */ | |
1388 sip->registrar.retries = 0; | |
1350 } | 1389 } |
1351 } | 1390 } |
1352 if(trans->callback) { | 1391 if(trans->callback) { |
1353 /* call the callback to process response*/ | 1392 /* call the callback to process response*/ |
1354 (trans->callback)(sip, msg, trans); | 1393 (trans->callback)(sip, msg, trans); |
1694 { | 1733 { |
1695 struct simple_account_data *sip = gc->proto_data; | 1734 struct simple_account_data *sip = gc->proto_data; |
1696 | 1735 |
1697 if(sip) { | 1736 if(sip) { |
1698 /* unregister */ | 1737 /* unregister */ |
1699 do_register_exp(sip, 0); | 1738 if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE) |
1739 do_register_exp(sip, 0); | |
1700 connection_free_all(sip); | 1740 connection_free_all(sip); |
1701 | 1741 |
1702 if (sip->query_data != NULL) | 1742 if (sip->query_data != NULL) |
1703 purple_dnsquery_destroy(sip->query_data); | 1743 purple_dnsquery_destroy(sip->query_data); |
1704 | 1744 |