Mercurial > pidgin
comparison src/protocols/simple/simple.c @ 11341:3f0fda678686
[gaim-migrate @ 13555]
- small compatibility improvements for gizmo/linphone
- // -> /* */
- removed some mem leaks
committer: Tailor Script <tailor@pidgin.im>
| author | Thomas Butter <tbutter> |
|---|---|
| date | Thu, 25 Aug 2005 06:59:20 +0000 |
| parents | 1696caba7db2 |
| children | 03d9507f05a9 |
comparison
equal
deleted
inserted
replaced
| 11340:e9d0d944b9d2 | 11341:3f0fda678686 |
|---|---|
| 67 return "simple"; | 67 return "simple"; |
| 68 } | 68 } |
| 69 | 69 |
| 70 static void simple_keep_alive(GaimConnection *gc) { | 70 static void simple_keep_alive(GaimConnection *gc) { |
| 71 struct simple_account_data *sip = gc->proto_data; | 71 struct simple_account_data *sip = gc->proto_data; |
| 72 if(sip->udp) { // in case of UDP send a packet only with a 0 byte to | 72 if(sip->udp) { /* in case of UDP send a packet only with a 0 byte to |
| 73 // stay in the NAT table | 73 remain in the NAT table */ |
| 74 gchar buf[2]={0,0}; | 74 gchar buf[2]={0,0}; |
| 75 gaim_debug_info("simple", "sending keep alive\n"); | 75 gaim_debug_info("simple", "sending keep alive\n"); |
| 76 sendto(sip->fd, buf, 1, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)); | 76 sendto(sip->fd, buf, 1, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)); |
| 77 } | 77 } |
| 78 return; | 78 return; |
| 442 strlen(body), | 442 strlen(body), |
| 443 body); | 443 body); |
| 444 g_free(branch); | 444 g_free(branch); |
| 445 g_free(callid); | 445 g_free(callid); |
| 446 | 446 |
| 447 // add to running transactions | 447 /* add to ongoing transactions */ |
| 448 | 448 |
| 449 transactions_add_buf(sip, buf, tc); | 449 transactions_add_buf(sip, buf, tc); |
| 450 | 450 |
| 451 sendout_pkt(gc,buf); | 451 sendout_pkt(gc,buf); |
| 452 | 452 |
| 458 | 458 |
| 459 char *uri = g_strdup_printf("sip:%s",sip->servername); | 459 char *uri = g_strdup_printf("sip:%s",sip->servername); |
| 460 char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername); | 460 char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername); |
| 461 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->listenport, sip->udp ? "udp" : "tcp", expire); | 461 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->listenport, sip->udp ? "udp" : "tcp", expire); |
| 462 | 462 |
| 463 // allow one auth try per register | 463 /* allow one auth try per register */ |
| 464 sip->proxy.fouroseven = 0; | 464 sip->proxy.fouroseven = 0; |
| 465 sip->registrar.fouroseven = 0; | 465 sip->registrar.fouroseven = 0; |
| 466 | 466 |
| 467 if(expire) { | 467 if(expire) { |
| 468 sip->reregister = time(NULL) + expire - 50; | 468 sip->reregister = time(NULL) + expire - 50; |
| 469 } else { | 469 } else { |
| 470 sip->reregister = time(NULL) + 600; | 470 sip->reregister = time(NULL) + 600; |
| 471 } | 471 } |
| 472 send_sip_request(sip->gc,"REGISTER",uri,to, contact, "", NULL, process_register_response); | 472 send_sip_request(sip->gc,"REGISTER",uri,to, contact, "", NULL, process_register_response); |
| 473 g_free(contact); | |
| 473 g_free(uri); | 474 g_free(uri); |
| 474 g_free(to); | 475 g_free(to); |
| 475 } | 476 } |
| 476 | 477 |
| 477 static void do_register(struct simple_account_data *sip) { | 478 static void do_register(struct simple_account_data *sip) { |
| 484 | 485 |
| 485 if(!from) return NULL; | 486 if(!from) return NULL; |
| 486 gaim_debug_info("simple", "parsing address out of %s\n",from); | 487 gaim_debug_info("simple", "parsing address out of %s\n",from); |
| 487 tmp = strchr(from, '<'); | 488 tmp = strchr(from, '<'); |
| 488 | 489 |
| 489 // i hate the different SIP UA behaviours... | 490 /* i hate the different SIP UA behaviours... */ |
| 490 if(tmp) { // sip address in <...> | 491 if(tmp) { /* sip address in <...> */ |
| 491 from = tmp+1; | 492 from = tmp+1; |
| 492 tmp = strchr(from,'>'); | 493 tmp = strchr(from,'>'); |
| 493 if(tmp) { | 494 if(tmp) { |
| 494 from = g_strndup(from,tmp-from); | 495 from = g_strndup(from,tmp-from); |
| 495 } else { | 496 } else { |
| 505 gaim_debug_info("simple", "got %s\n",from); | 506 gaim_debug_info("simple", "got %s\n",from); |
| 506 return from; | 507 return from; |
| 507 } | 508 } |
| 508 | 509 |
| 509 static gboolean process_subscribe_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | 510 static gboolean process_subscribe_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { |
| 510 gchar *to = parse_from(sipmsg_find_header(tc->msg,"To")); // cant be NULL since it is our own msg | 511 gchar *to = parse_from(sipmsg_find_header(tc->msg,"To")); /* cant be NULL since it is our own msg */ |
| 511 | 512 |
| 512 | 513 |
| 513 if(msg->response==200 || msg->response==202) { | 514 if(msg->response==200 || msg->response==202) { |
| 514 return TRUE; | 515 return TRUE; |
| 515 } | 516 } |
| 516 | 517 |
| 517 // we can not subscribe -> user is offline (TODO unknown status?) | 518 /* we can not subscribe -> user is offline (TODO unknown status?) */ |
| 518 | 519 |
| 519 gaim_prpl_got_user_status(sip->account, to, "offline", NULL); | 520 gaim_prpl_got_user_status(sip->account, to, "offline", NULL); |
| 520 g_free(to); | 521 g_free(to); |
| 521 return TRUE; | 522 return TRUE; |
| 522 } | 523 } |
| 523 | 524 |
| 524 static void simple_subscribe(struct simple_account_data *sip, struct simple_buddy *buddy) { | 525 static void simple_subscribe(struct simple_account_data *sip, struct simple_buddy *buddy) { |
| 525 gchar *contact = "Expires: 900\r\nAccept: application/pidf+xml\r\nEvent: presence\r\n"; | 526 gchar *contact = "Expires: 300\r\nAccept: application/pidf+xml\r\nEvent: presence\r\n"; |
| 526 gchar *to; | 527 gchar *to; |
| 527 if(strstr(buddy->name,"sip:")) to = g_strdup(buddy->name); | 528 if(strstr(buddy->name,"sip:")) to = g_strdup(buddy->name); |
| 528 else to = g_strdup_printf("sip:%s",buddy->name); | 529 else to = g_strdup_printf("sip:%s",buddy->name); |
| 529 // subscribe to buddy presence | 530 contact = g_strdup_printf("%sContact: <%s@%s>\r\n", contact, sip->username, sip->servername); |
| 530 // we dont need to know the status so we do not need a callback | 531 /* subscribe to buddy presence |
| 532 * we dont need to know the status so we do not need a callback */ | |
| 531 | 533 |
| 532 send_sip_request(sip->gc, "SUBSCRIBE",to, to, contact, "", NULL, process_subscribe_response); | 534 send_sip_request(sip->gc, "SUBSCRIBE",to, to, contact, "", NULL, process_subscribe_response); |
| 533 | 535 |
| 534 g_free(to); | 536 g_free(to); |
| 535 | 537 g_free(contact); |
| 536 // resubscribe before of subscription expires | 538 |
| 537 // add some jitter | 539 /* resubscribe before subscription expires */ |
| 538 buddy->resubscribe = time(NULL)+550+(rand()%50); | 540 /* add some jitter */ |
| 541 buddy->resubscribe = time(NULL)+250+(rand()%50); | |
| 539 } | 542 } |
| 540 | 543 |
| 541 static void simple_buddy_resub(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) { | 544 static void simple_buddy_resub(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) { |
| 542 time_t curtime = time(NULL); | 545 time_t curtime = time(NULL); |
| 543 | 546 gaim_debug_info("simple","buddy resub\n"); |
| 544 if(buddy->resubscribe < curtime) { | 547 if(buddy->resubscribe < curtime) { |
| 545 gaim_debug(GAIM_DEBUG_MISC, "simple", "simple_buddy_resub %s\n",name); | 548 gaim_debug(GAIM_DEBUG_MISC, "simple", "simple_buddy_resub %s\n",name); |
| 546 simple_subscribe(sip, buddy); | 549 simple_subscribe(sip, buddy); |
| 547 } | 550 } |
| 548 } | 551 } |
| 553 while(tmp) { | 556 while(tmp) { |
| 554 struct transaction *trans = tmp->data; | 557 struct transaction *trans = tmp->data; |
| 555 tmp = tmp->next; | 558 tmp = tmp->next; |
| 556 gaim_debug_info("simple", "have open transaction age: %d\n", currtime- trans->time); | 559 gaim_debug_info("simple", "have open transaction age: %d\n", currtime- trans->time); |
| 557 if((currtime - trans->time > 5) && trans->retries >= 1) { | 560 if((currtime - trans->time > 5) && trans->retries >= 1) { |
| 558 // TODO 408 | 561 /* TODO 408 */ |
| 559 } else { | 562 } else { |
| 560 if((currtime - trans->time > 2) && trans->retries == 0) { | 563 if((currtime - trans->time > 2) && trans->retries == 0) { |
| 561 trans->retries++; | 564 trans->retries++; |
| 562 sendout_sipmsg(sip, trans->msg); | 565 sendout_sipmsg(sip, trans->msg); |
| 563 } | 566 } |
| 567 } | 570 } |
| 568 | 571 |
| 569 static gboolean register_timeout(struct simple_account_data *sip) { | 572 static gboolean register_timeout(struct simple_account_data *sip) { |
| 570 GSList *tmp; | 573 GSList *tmp; |
| 571 time_t curtime = time(NULL); | 574 time_t curtime = time(NULL); |
| 572 // register again if first registration expires | 575 /* register again if first registration expires */ |
| 573 if(sip->reregister < curtime) { | 576 if(sip->reregister < curtime) { |
| 574 do_register(sip); | 577 do_register(sip); |
| 575 } | 578 } |
| 576 | 579 gaim_debug_info("simple","in register timeout\n"); |
| 577 // check for every subscription if we need to resubscribe | 580 /* check for every subscription if we need to resubscribe */ |
| 578 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip); | 581 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip); |
| 579 | 582 |
| 580 // remove a timed out suscriber | 583 /* remove a timed out suscriber */ |
| 581 | 584 |
| 582 tmp = sip->watcher; | 585 tmp = sip->watcher; |
| 583 while(tmp) { | 586 while(tmp) { |
| 584 struct simple_watcher *watcher = tmp->data; | 587 struct simple_watcher *watcher = tmp->data; |
| 585 if(watcher->expire < curtime) { | 588 if(watcher->expire < curtime) { |
| 691 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | 694 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { |
| 692 gchar *tmp; | 695 gchar *tmp; |
| 693 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); | 696 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); |
| 694 switch (msg->response) { | 697 switch (msg->response) { |
| 695 case 200: | 698 case 200: |
| 696 if(sip->registerstatus<3) { // registered | 699 if(sip->registerstatus<3) { /* registered */ |
| 697 send_publish(sip); | 700 send_publish(sip); |
| 698 } | 701 } |
| 699 sip->registerstatus=3; | 702 sip->registerstatus=3; |
| 700 gaim_connection_set_state(sip->gc, GAIM_CONNECTED); | 703 gaim_connection_set_state(sip->gc, GAIM_CONNECTED); |
| 704 | |
| 705 /* get buddies from blist */ | |
| 706 simple_get_buddies(sip->gc); | |
| 707 | |
| 701 register_timeout(sip); | 708 register_timeout(sip); |
| 702 break; | 709 break; |
| 703 case 401: | 710 case 401: |
| 704 if(sip->registerstatus!=2) { | 711 if(sip->registerstatus!=2) { |
| 705 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); | 712 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); |
| 823 g_free(doc); | 830 g_free(doc); |
| 824 } | 831 } |
| 825 | 832 |
| 826 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | 833 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { |
| 827 if(msg->response != 200) { | 834 if(msg->response != 200) { |
| 828 // never send again | 835 /* never send again */ |
| 829 sip->republish = -1; | 836 sip->republish = -1; |
| 830 } | 837 } |
| 831 return TRUE; | 838 return TRUE; |
| 832 } | 839 } |
| 833 | 840 |
| 834 static void send_publish(struct simple_account_data *sip) { | 841 static void send_publish(struct simple_account_data *sip) { |
| 835 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | 842 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); |
| 836 gchar *doc = gen_pidf(sip); | 843 gchar *doc = gen_pidf(sip); |
| 837 send_sip_request(sip->gc, "PUBLISH", uri, uri, "Expires: 600\r\nEvent: presence\r\nContent-Type: application/pidf+xml\r\nAccept: application/pidf+xml\r\n", doc, NULL, process_publish_response); | 844 send_sip_request(sip->gc, "PUBLISH", uri, uri, "Expires: 600\r\nEvent: presence\r\nContent-Type: application/pidf+xml\r\n", doc, NULL, process_publish_response); |
| 838 sip->republish = time(NULL) + 500; | 845 sip->republish = time(NULL) + 500; |
| 839 g_free(doc); | 846 g_free(doc); |
| 840 } | 847 } |
| 841 | 848 |
| 842 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { | 849 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { |
| 850 struct simple_watcher *watcher = watcher_find(sip, from); | 857 struct simple_watcher *watcher = watcher_find(sip, from); |
| 851 if(!ourtag) { | 858 if(!ourtag) { |
| 852 tagadded = TRUE; | 859 tagadded = TRUE; |
| 853 ourtag = gentag(); | 860 ourtag = gentag(); |
| 854 } | 861 } |
| 855 if(!watcher) { // new subscription | 862 if(!watcher) { /* new subscription */ |
| 856 watcher = watcher_create(sip, from, callid, ourtag, theirtag); | 863 watcher = watcher_create(sip, from, callid, ourtag, theirtag); |
| 857 } | 864 } |
| 858 if(tagadded) { | 865 if(tagadded) { |
| 859 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag); | 866 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag); |
| 860 sipmsg_remove_header(msg, "To"); | 867 sipmsg_remove_header(msg, "To"); |
| 873 send_notify(sip, watcher); | 880 send_notify(sip, watcher); |
| 874 } | 881 } |
| 875 | 882 |
| 876 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) { | 883 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) { |
| 877 int found = 0; | 884 int found = 0; |
| 878 if( msg->response == 0 ) { // request | 885 if( msg->response == 0 ) { /* request */ |
| 879 if(!strcmp(msg->method, "MESSAGE")) { | 886 if(!strcmp(msg->method, "MESSAGE")) { |
| 880 process_incoming_message(sip, msg); | 887 process_incoming_message(sip, msg); |
| 881 found = 1; | 888 found = 1; |
| 882 } | 889 } |
| 883 if(!strcmp(msg->method, "NOTIFY")) { | 890 if(!strcmp(msg->method, "NOTIFY")) { |
| 889 found = 1; | 896 found = 1; |
| 890 } | 897 } |
| 891 if(!found) { | 898 if(!found) { |
| 892 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL); | 899 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL); |
| 893 } | 900 } |
| 894 } else { // response | 901 } else { /* response */ |
| 895 struct transaction *trans = transactions_find(sip, msg); | 902 struct transaction *trans = transactions_find(sip, msg); |
| 896 if(trans) { | 903 if(trans) { |
| 897 if(msg->response == 407) { | 904 if(msg->response == 407) { |
| 898 if(sip->proxy.fouroseven>3) return; | 905 if(sip->proxy.fouroseven>3) return; |
| 899 sip->proxy.fouroseven++; | 906 sip->proxy.fouroseven++; |
| 900 // do proxy authentication | 907 /* do proxy authentication */ |
| 901 | 908 |
| 902 gchar *ptmp = sipmsg_find_header(msg,"Proxy-Authenticate"); | 909 gchar *ptmp = sipmsg_find_header(msg,"Proxy-Authenticate"); |
| 903 gchar *resend; | 910 gchar *resend; |
| 904 gchar *auth; | 911 gchar *auth; |
| 905 | 912 |
| 914 auth = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n",sip->username, sip->proxy.realm, sip->proxy.nonce, trans->msg->target, noncecount, response); | 921 auth = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n",sip->username, sip->proxy.realm, sip->proxy.nonce, trans->msg->target, noncecount, response); |
| 915 sipmsg_remove_header(msg, "Proxy-Authorization"); | 922 sipmsg_remove_header(msg, "Proxy-Authorization"); |
| 916 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth); | 923 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth); |
| 917 g_free(auth); | 924 g_free(auth); |
| 918 resend = sipmsg_to_string(trans->msg); | 925 resend = sipmsg_to_string(trans->msg); |
| 919 // resend request | 926 /* resend request */ |
| 920 sendout_pkt(sip->gc, resend); | 927 sendout_pkt(sip->gc, resend); |
| 921 g_free(resend); | 928 g_free(resend); |
| 922 } else { | 929 } else { |
| 923 sip->proxy.fouroseven = 0; | 930 sip->proxy.fouroseven = 0; |
| 924 if(msg->response == 401) sip->registrar.fouroseven++; | 931 if(msg->response == 401) sip->registrar.fouroseven++; |
| 925 else sip->registrar.fouroseven = 0; | 932 else sip->registrar.fouroseven = 0; |
| 926 if(trans->callback) { | 933 if(trans->callback) { |
| 927 // call the callback to process response | 934 /* call the callback to process response*/ |
| 928 (trans->callback)(sip, msg, trans); | 935 (trans->callback)(sip, msg, trans); |
| 929 } | 936 } |
| 930 transactions_remove(sip, trans); | 937 transactions_remove(sip, trans); |
| 931 } | 938 } |
| 932 found = 1; | 939 found = 1; |
| 946 struct sipmsg *msg; | 953 struct sipmsg *msg; |
| 947 int restlen; | 954 int restlen; |
| 948 | 955 |
| 949 cur = conn->inbuf; | 956 cur = conn->inbuf; |
| 950 | 957 |
| 951 // according to the RFC remove CRLF at the beginning | 958 /* according to the RFC remove CRLF at the beginning */ |
| 952 while(*cur == '\r' || *cur == '\n') { | 959 while(*cur == '\r' || *cur == '\n') { |
| 953 cur++; | 960 cur++; |
| 954 } | 961 } |
| 955 if(cur != conn->inbuf) { | 962 if(cur != conn->inbuf) { |
| 956 memmove(conn->inbuf, cur, conn->inbufused-(cur-conn->inbuf)); | 963 memmove(conn->inbuf, cur, conn->inbufused-(cur-conn->inbuf)); |
| 957 conn->inbufused=strlen(conn->inbuf); | 964 conn->inbufused=strlen(conn->inbuf); |
| 958 } | 965 } |
| 959 | 966 |
| 960 // Received a full Header? | 967 /* Received a full Header? */ |
| 961 if((cur = strstr(conn->inbuf, "\r\n\r\n"))!=NULL) { | 968 if((cur = strstr(conn->inbuf, "\r\n\r\n"))!=NULL) { |
| 962 time_t currtime = time(NULL); | 969 time_t currtime = time(NULL); |
| 963 cur += 2; | 970 cur += 2; |
| 964 cur[0] = '\0'; | 971 cur[0] = '\0'; |
| 965 gaim_debug_info("simple","\n\nreceived - %s\n######\n%s\n#######\n\n",ctime(&currtime), conn->inbuf); | 972 gaim_debug_info("simple","\n\nreceived - %s\n######\n%s\n#######\n\n",ctime(&currtime), conn->inbuf); |
| 977 conn->inbufused=strlen(conn->inbuf); | 984 conn->inbufused=strlen(conn->inbuf); |
| 978 } else { | 985 } else { |
| 979 sipmsg_free(msg); | 986 sipmsg_free(msg); |
| 980 return; | 987 return; |
| 981 } | 988 } |
| 982 // sipmsg_print(msg); | |
| 983 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process response response: %d\n", msg->response); | 989 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process response response: %d\n", msg->response); |
| 984 process_input_message(sip,msg); | 990 process_input_message(sip,msg); |
| 985 } else { | 991 } else { |
| 986 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a incomplete sip msg: %s\n", conn->inbuf); | 992 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a incomplete sip msg: %s\n", conn->inbuf); |
| 987 } | 993 } |
| 1020 | 1026 |
| 1021 if ((len = read(source, conn->inbuf + conn->inbufused, SIMPLE_BUF_INC - 1)) <= 0) { | 1027 if ((len = read(source, conn->inbuf + conn->inbufused, SIMPLE_BUF_INC - 1)) <= 0) { |
| 1022 gaim_debug_info("simple","simple_input_cb: read error\n"); | 1028 gaim_debug_info("simple","simple_input_cb: read error\n"); |
| 1023 connection_remove(sip, source); | 1029 connection_remove(sip, source); |
| 1024 if(sip->fd == source) sip->fd = -1; | 1030 if(sip->fd == source) sip->fd = -1; |
| 1025 // gaim_connection_error(gc, _("Read error")); | |
| 1026 return; | 1031 return; |
| 1027 } | 1032 } |
| 1028 if(len == 0) { | 1033 if(len == 0) { |
| 1029 // connection was closed | 1034 /* connection was closed */ |
| 1030 connection_remove(sip, source); | 1035 connection_remove(sip, source); |
| 1031 if(sip->fd == source) sip->fd = -1; | 1036 if(sip->fd == source) sip->fd = -1; |
| 1032 } | 1037 } |
| 1033 | 1038 |
| 1034 conn->inbufused += len; | 1039 conn->inbufused += len; |
| 1061 return; | 1066 return; |
| 1062 } | 1067 } |
| 1063 | 1068 |
| 1064 sip->fd = source; | 1069 sip->fd = source; |
| 1065 | 1070 |
| 1066 // get buddies from blist | |
| 1067 simple_get_buddies(gc); | |
| 1068 | 1071 |
| 1069 conn = connection_create(sip, source); | 1072 conn = connection_create(sip, source); |
| 1070 | 1073 |
| 1071 // get the local ip | 1074 /* get the local ip */ |
| 1072 sip->ip = g_strdup(gaim_network_get_my_ip(source)); | 1075 sip->ip = g_strdup(gaim_network_get_my_ip(source)); |
| 1073 | 1076 |
| 1074 do_register(sip); | 1077 do_register(sip); |
| 1075 | 1078 |
| 1076 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); | 1079 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); |
| 1129 hosttoconnect = g_strdup(sip->servername); | 1132 hosttoconnect = g_strdup(sip->servername); |
| 1130 } else { | 1133 } else { |
| 1131 hosttoconnect = g_strdup(gaim_account_get_string(account, "proxy", sip->servername)); | 1134 hosttoconnect = g_strdup(gaim_account_get_string(account, "proxy", sip->servername)); |
| 1132 } | 1135 } |
| 1133 | 1136 |
| 1134 // TCP case | 1137 /* TCP case */ |
| 1135 if(! sip->udp) { | 1138 if(! sip->udp) { |
| 1136 // search for SRV record | 1139 /* search for SRV record */ |
| 1137 serveradr = getserver(hosttoconnect, "_sip._tcp"); | 1140 serveradr = getserver(hosttoconnect, "_sip._tcp"); |
| 1138 gaim_debug_info("simple","connecting to %s port %d", serveradr->name, serveradr->port); | 1141 gaim_debug_info("simple","connecting to %s port %d", serveradr->name, serveradr->port); |
| 1139 | 1142 |
| 1140 // open tcp connection to the server | 1143 /* open tcp connection to the server */ |
| 1141 error = gaim_proxy_connect(account, serveradr->name, serveradr->port, login_cb, gc); | 1144 error = gaim_proxy_connect(account, serveradr->name, serveradr->port, login_cb, gc); |
| 1142 if(error) { | 1145 if(error) { |
| 1143 gaim_connection_error(gc, _("Couldn't create socket")); | 1146 gaim_connection_error(gc, _("Couldn't create socket")); |
| 1144 } | 1147 } |
| 1145 | 1148 |
| 1146 // create socket for incoming connections | 1149 /* create socket for incoming connections */ |
| 1147 sip->listenfd = gaim_network_listen_range(5060, 5080); | 1150 sip->listenfd = gaim_network_listen_range(5060, 5080); |
| 1148 if(sip->listenfd == -1) { | 1151 if(sip->listenfd == -1) { |
| 1149 gaim_connection_error(gc, _("Could not create listen socket")); | 1152 gaim_connection_error(gc, _("Could not create listen socket")); |
| 1150 return; | 1153 return; |
| 1151 } | 1154 } |
| 1152 sip->listenport = gaim_network_get_port_from_fd(sip->listenfd); | 1155 sip->listenport = gaim_network_get_port_from_fd(sip->listenfd); |
| 1153 gaim_input_add(sip->listenfd, GAIM_INPUT_READ, simple_newconn_cb, gc); | 1156 gaim_input_add(sip->listenfd, GAIM_INPUT_READ, simple_newconn_cb, gc); |
| 1154 } else { // UDP | 1157 } else { /* UDP */ |
| 1155 // search for SRV record | 1158 /* search for SRV record */ |
| 1156 struct sockaddr_in addr; | 1159 struct sockaddr_in addr; |
| 1157 struct hostent *h; | 1160 struct hostent *h; |
| 1158 | 1161 |
| 1159 serveradr = getserver(hosttoconnect, "_sip._udp"); | 1162 serveradr = getserver(hosttoconnect, "_sip._udp"); |
| 1160 gaim_debug_info("simple", "using udp with server %s and port %d", serveradr->name, serveradr->port); | 1163 gaim_debug_info("simple", "using udp with server %s and port %d", serveradr->name, serveradr->port); |
| 1168 } | 1171 } |
| 1169 sip->listenport = ntohs(addr.sin_port); | 1172 sip->listenport = ntohs(addr.sin_port); |
| 1170 sip->listenfd = sip->fd; | 1173 sip->listenfd = sip->fd; |
| 1171 | 1174 |
| 1172 gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, gc); | 1175 gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, gc); |
| 1173 // TODO - change to new SRV impl. | 1176 /* TODO - change to new SRV impl. */ |
| 1174 sip->serveraddr.sin_family = AF_INET; | 1177 sip->serveraddr.sin_family = AF_INET; |
| 1175 sip->serveraddr.sin_port = htons(serveradr->port); | 1178 sip->serveraddr.sin_port = htons(serveradr->port); |
| 1176 | 1179 |
| 1177 h = gethostbyname(serveradr->name); | 1180 h = gethostbyname(serveradr->name); |
| 1178 sip->serveraddr.sin_addr.s_addr = ((struct in_addr*)h->h_addr)->s_addr; | 1181 sip->serveraddr.sin_addr.s_addr = ((struct in_addr*)h->h_addr)->s_addr; |
| 1181 do_register(sip); | 1184 do_register(sip); |
| 1182 | 1185 |
| 1183 } | 1186 } |
| 1184 g_free(hosttoconnect); | 1187 g_free(hosttoconnect); |
| 1185 | 1188 |
| 1186 // register timeout callback for register / subscribe renewal | 1189 /* register timeout callback for register / subscribe renewal */ |
| 1187 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)register_timeout, sip); | 1190 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)register_timeout, sip); |
| 1188 } | 1191 } |
| 1189 | 1192 |
| 1190 static void simple_close(GaimConnection *gc) | 1193 static void simple_close(GaimConnection *gc) |
| 1191 { | 1194 { |
| 1192 struct simple_account_data *sip = gc->proto_data; | 1195 struct simple_account_data *sip = gc->proto_data; |
| 1193 | 1196 |
| 1194 // unregister | 1197 /* unregister */ |
| 1195 do_register_exp(sip, 0); | 1198 do_register_exp(sip, 0); |
| 1196 // if(sip) { | 1199 if(sip) { |
| 1197 if(0) { | |
| 1198 if(sip->servername) g_free(sip->servername); | 1200 if(sip->servername) g_free(sip->servername); |
| 1199 if(sip->username) g_free(sip->username); | 1201 if(sip->username) g_free(sip->username); |
| 1200 if(sip->password) g_free(sip->password); | 1202 if(sip->password) g_free(sip->password); |
| 1201 if(sip->registrar.nonce) g_free(sip->registrar.nonce); | 1203 if(sip->registrar.nonce) g_free(sip->registrar.nonce); |
| 1202 if(sip->registrar.realm) g_free(sip->registrar.nonce); | 1204 if(sip->registrar.realm) g_free(sip->registrar.realm); |
| 1203 if(sip->proxy.nonce) g_free(sip->proxy.nonce); | 1205 if(sip->proxy.nonce) g_free(sip->proxy.nonce); |
| 1204 if(sip->proxy.realm) g_free(sip->proxy.realm); | 1206 if(sip->proxy.realm) g_free(sip->proxy.realm); |
| 1205 // if(sip->registertimeout) gaim_timeout_remove(sip->registertimeout); | |
| 1206 if(sip->sendlater) g_free(sip->sendlater); | 1207 if(sip->sendlater) g_free(sip->sendlater); |
| 1207 if(sip->ip) g_free(sip->ip); | 1208 if(sip->ip) g_free(sip->ip); |
| 1208 sip->servername = sip->username = sip->password = sip->registrar.nonce = sip->registrar.realm = sip->proxy.nonce = sip->proxy.realm = sip->sendlater = sip->ip = 0; | 1209 sip->servername = sip->username = sip->password = sip->registrar.nonce = sip->registrar.realm = sip->proxy.nonce = sip->proxy.realm = sip->sendlater = sip->ip = NULL; |
| 1209 } | 1210 } |
| 1210 // if(gc->proto_data) g_free(gc->proto_data); | 1211 if(gc->proto_data) g_free(gc->proto_data); |
| 1211 // gc->proto_data = 0; | 1212 gc->proto_data = 0; |
| 1212 // TODO free connections | 1213 /* TODO free connections */ |
| 1213 } | 1214 } |
| 1214 | 1215 |
| 1215 static GaimPluginProtocolInfo prpl_info = | 1216 static GaimPluginProtocolInfo prpl_info = |
| 1216 { | 1217 { |
| 1217 0, | 1218 0, |
| 1315 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | 1316 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
| 1316 option = gaim_account_option_bool_new(_("Use Proxy"), "useproxy", FALSE); | 1317 option = gaim_account_option_bool_new(_("Use Proxy"), "useproxy", FALSE); |
| 1317 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | 1318 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
| 1318 option = gaim_account_option_string_new(_("Proxy"), "proxy", ""); | 1319 option = gaim_account_option_string_new(_("Proxy"), "proxy", ""); |
| 1319 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | 1320 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
| 1320 // _simple_plugin = plugin; | |
| 1321 } | 1321 } |
| 1322 | 1322 |
| 1323 GAIM_INIT_PLUGIN(simple, _init_plugin, info); | 1323 GAIM_INIT_PLUGIN(simple, _init_plugin, info); |
