| 695 } |
695 } |
| 696 } |
696 } |
| 697 return TRUE; |
697 return TRUE; |
| 698 } |
698 } |
| 699 |
699 |
| 700 static gboolean register_timeout(struct simple_account_data *sip) { |
700 static gboolean subscribe_timeout(struct simple_account_data *sip) { |
| 701 GSList *tmp; |
701 GSList *tmp; |
| 702 time_t curtime = time(NULL); |
702 time_t curtime = time(NULL); |
| 703 /* register again if first registration expires */ |
703 /* register again if first registration expires */ |
| 704 if(sip->reregister < curtime) { |
704 if(sip->reregister < curtime) { |
| 705 do_register(sip); |
705 do_register(sip); |
| 706 } |
706 } |
| 707 gaim_debug_info("simple","in register timeout\n"); |
|
| 708 /* check for every subscription if we need to resubscribe */ |
707 /* check for every subscription if we need to resubscribe */ |
| 709 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip); |
708 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip); |
| 710 |
709 |
| 711 /* remove a timed out suscriber */ |
710 /* remove a timed out suscriber */ |
| 712 |
711 |
| 809 gaim_connection_set_state(sip->gc, GAIM_CONNECTED); |
808 gaim_connection_set_state(sip->gc, GAIM_CONNECTED); |
| 810 |
809 |
| 811 /* get buddies from blist */ |
810 /* get buddies from blist */ |
| 812 simple_get_buddies(sip->gc); |
811 simple_get_buddies(sip->gc); |
| 813 |
812 |
| 814 register_timeout(sip); |
813 subscribe_timeout(sip); |
| 815 break; |
814 break; |
| 816 case 401: |
815 case 401: |
| 817 if(sip->registerstatus!=2) { |
816 if(sip->registerstatus!=2) { |
| 818 gaim_debug_info("simple","REGISTER retries %d\n",sip->registrar.retries); |
817 gaim_debug_info("simple","REGISTER retries %d\n",sip->registrar.retries); |
| 819 if(sip->registrar.retries>3) { |
818 if(sip->registrar.retries>3) { |
| 1232 sip->listenfd = sip->fd; |
1233 sip->listenfd = sip->fd; |
| 1233 |
1234 |
| 1234 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc); |
1235 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc); |
| 1235 |
1236 |
| 1236 sip->resendtimeout = gaim_timeout_add(2500, (GSourceFunc) resend_timeout, sip); |
1237 sip->resendtimeout = gaim_timeout_add(2500, (GSourceFunc) resend_timeout, sip); |
| |
1238 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip); |
| 1237 do_register(sip); |
1239 do_register(sip); |
| 1238 } |
1240 } |
| 1239 |
1241 |
| 1240 static void srvresolved(GaimSrvResponse *resp, int results, gpointer data) { |
1242 static void srvresolved(GaimSrvResponse *resp, int results, gpointer data) { |
| 1241 struct simple_account_data *sip = (struct simple_account_data*) data; |
1243 struct simple_account_data *sip = (struct simple_account_data*) data; |
| 1332 gaim_srv_resolve("sip","tcp",hosttoconnect,srvresolved, sip); |
1334 gaim_srv_resolve("sip","tcp",hosttoconnect,srvresolved, sip); |
| 1333 } else { /* UDP */ |
1335 } else { /* UDP */ |
| 1334 gaim_srv_resolve("sip","udp",hosttoconnect,srvresolved, sip); |
1336 gaim_srv_resolve("sip","udp",hosttoconnect,srvresolved, sip); |
| 1335 } |
1337 } |
| 1336 g_free(hosttoconnect); |
1338 g_free(hosttoconnect); |
| 1337 |
|
| 1338 /* register timeout callback for register / subscribe renewal */ |
|
| 1339 /* TODO: What if the timeout is called before gaim_srv_resolve() finishes?! */ |
|
| 1340 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)register_timeout, sip); |
|
| 1341 } |
1339 } |
| 1342 |
1340 |
| 1343 static void simple_close(GaimConnection *gc) |
1341 static void simple_close(GaimConnection *gc) |
| 1344 { |
1342 { |
| 1345 struct simple_account_data *sip = gc->proto_data; |
1343 struct simple_account_data *sip = gc->proto_data; |