comparison src/protocols/simple/simple.c @ 12760:c5acba513363

[gaim-migrate @ 15107] Request the public IP everytime it is used since there may be information or a new IP. committer: Tailor Script <tailor@pidgin.im>
author Thomas Butter <tbutter>
date Sun, 08 Jan 2006 01:16:23 +0000
parents 505bc707b641
children 53218d758ba9
comparison
equal deleted inserted replaced
12759:019d0e4d8d65 12760:c5acba513363
67 rand() & 0xFFFF, 67 rand() & 0xFFFF,
68 rand() & 0xFFFF, 68 rand() & 0xFFFF,
69 rand() & 0xFFFF); 69 rand() & 0xFFFF);
70 } 70 }
71 71
72 static char *get_my_ip() {
73 static char my_ip[42];
74 const char *tmp = gaim_network_get_public_ip();
75
76 if(!tmp || !strcmp(tmp,"0.0.0.0")) {
77 tmp = gaim_network_get_my_ip(-1);
78 }
79 if(!tmp) strcpy(my_ip, "0.0.0.0");
80 strcpy(my_ip, tmp);
81 return my_ip;
82 }
83
72 static const char *simple_list_icon(GaimAccount *a, GaimBuddy *b) { 84 static const char *simple_list_icon(GaimAccount *a, GaimBuddy *b) {
73 return "simple"; 85 return "simple";
74 } 86 }
75 87
76 static void simple_keep_alive(GaimConnection *gc) { 88 static void simple_keep_alive(GaimConnection *gc) {
536 buf = auth_header(sip, &sip->proxy, method, url); 548 buf = auth_header(sip, &sip->proxy, method, url);
537 auth = g_strdup_printf("Proxy-Authorization: %s", buf); 549 auth = g_strdup_printf("Proxy-Authorization: %s", buf);
538 g_free(buf); 550 g_free(buf);
539 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth); 551 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth);
540 } 552 }
541 553
542 if(!sip->ip || !strcmp(sip->ip,"0.0.0.0") || !strcmp(sip->ip,"127.0.0.1")) { /* if there was no known ip retry now */
543 if(gaim_network_get_public_ip()) {
544 g_free(sip->ip);
545 sip->ip = g_strdup(gaim_network_get_public_ip());
546 }
547 }
548 buf = g_strdup_printf("%s %s SIP/2.0\r\n" 554 buf = g_strdup_printf("%s %s SIP/2.0\r\n"
549 "Via: SIP/2.0/%s %s:%d;branch=%s\r\n" 555 "Via: SIP/2.0/%s %s:%d;branch=%s\r\n"
550 "From: <sip:%s@%s>;tag=%s\r\n" 556 "From: <sip:%s@%s>;tag=%s\r\n"
551 "To: <%s>%s%s\r\n" 557 "To: <%s>%s%s\r\n"
552 "Max-Forwards: 10\r\n" 558 "Max-Forwards: 10\r\n"
556 "%s%s" 562 "%s%s"
557 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", 563 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
558 method, 564 method,
559 url, 565 url,
560 sip->udp ? "UDP" : "TCP", 566 sip->udp ? "UDP" : "TCP",
561 sip->ip ? sip->ip : "", 567 get_my_ip(),
562 sip->listenport, 568 sip->listenport,
563 branch, 569 branch,
564 sip->username, 570 sip->username,
565 sip->servername, 571 sip->servername,
566 dialog ? dialog->ourtag : gentag(), 572 dialog ? dialog->ourtag : gentag(),
587 } 593 }
588 594
589 static void do_register_exp(struct simple_account_data *sip, int expire) { 595 static void do_register_exp(struct simple_account_data *sip, int expire) {
590 char *uri = g_strdup_printf("sip:%s",sip->servername); 596 char *uri = g_strdup_printf("sip:%s",sip->servername);
591 char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername); 597 char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername);
592 char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, sip->ip ? sip->ip : "", sip->listenport, sip->udp ? "udp" : "tcp", expire); 598 char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, get_my_ip(), sip->listenport, sip->udp ? "udp" : "tcp", expire);
593 599
594 sip->registerstatus = 1; 600 sip->registerstatus = 1;
595 601
596 if(expire) { 602 if(expire) {
597 sip->reregister = time(NULL) + expire - 50; 603 sip->reregister = time(NULL) + expire - 50;
1183 1189
1184 sip->fd = source; 1190 sip->fd = source;
1185 1191
1186 conn = connection_create(sip, source); 1192 conn = connection_create(sip, source);
1187 1193
1188 /* get the local ip */
1189 sip->ip = g_strdup(gaim_network_get_my_ip(source));
1190
1191 do_register(sip); 1194 do_register(sip);
1192 1195
1193 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); 1196 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc);
1194 } 1197 }
1195 1198
1272 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc); 1275 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc);
1273 sip->serveraddr.sin_family = AF_INET; 1276 sip->serveraddr.sin_family = AF_INET;
1274 sip->serveraddr.sin_port = htons(port); 1277 sip->serveraddr.sin_port = htons(port);
1275 1278
1276 sip->serveraddr.sin_addr.s_addr = ((struct in_addr*)h->h_addr)->s_addr; 1279 sip->serveraddr.sin_addr.s_addr = ((struct in_addr*)h->h_addr)->s_addr;
1277 sip->ip = g_strdup(gaim_network_get_my_ip(-1));
1278 sip->resendtimeout = gaim_timeout_add(2500, (GSourceFunc)resend_timeout, sip); 1280 sip->resendtimeout = gaim_timeout_add(2500, (GSourceFunc)resend_timeout, sip);
1279 do_register(sip); 1281 do_register(sip);
1280 } 1282 }
1281 } 1283 }
1282 1284
1347 g_free(sip->registrar.nonce); 1349 g_free(sip->registrar.nonce);
1348 g_free(sip->registrar.realm); 1350 g_free(sip->registrar.realm);
1349 g_free(sip->proxy.nonce); 1351 g_free(sip->proxy.nonce);
1350 g_free(sip->proxy.realm); 1352 g_free(sip->proxy.realm);
1351 g_free(sip->sendlater); 1353 g_free(sip->sendlater);
1352 g_free(sip->ip);
1353 g_free(sip->realhostname); 1354 g_free(sip->realhostname);
1354 if(sip->listenpa) gaim_input_remove(sip->listenpa); 1355 if(sip->listenpa) gaim_input_remove(sip->listenpa);
1355 if(sip->resendtimeout) gaim_timeout_remove(sip->resendtimeout); 1356 if(sip->resendtimeout) gaim_timeout_remove(sip->resendtimeout);
1356 if(sip->registertimeout) gaim_timeout_remove(sip->registertimeout); 1357 if(sip->registertimeout) gaim_timeout_remove(sip->registertimeout);
1357 sip->servername = sip->username = sip->password = sip->registrar.nonce = sip->registrar.realm = sip->proxy.nonce = sip->proxy.realm = sip->sendlater = sip->ip = sip->realhostname = NULL; 1358 sip->servername = sip->username = sip->password = sip->registrar.nonce = sip->registrar.realm = sip->proxy.nonce = sip->proxy.realm = sip->sendlater = sip->realhostname = NULL;
1358 } 1359 }
1359 g_free(gc->proto_data); 1360 g_free(gc->proto_data);
1360 gc->proto_data = NULL; 1361 gc->proto_data = NULL;
1361 } 1362 }
1362 1363