Mercurial > pidgin.yaz
comparison src/upnp.c @ 11213:ff728e84d59a
[gaim-migrate @ 13344]
Changes by Adam Warrington
Fixes a crash on UPnP timeout
committer: Tailor Script <tailor@pidgin.im>
author | Thomas Butter <tbutter> |
---|---|
date | Mon, 08 Aug 2005 21:43:44 +0000 |
parents | a015b1cb7368 |
children | d3755a7ddd82 |
comparison
equal
deleted
inserted
replaced
11212:46086fcc82b7 | 11213:ff728e84d59a |
---|---|
149 } | 149 } |
150 | 150 |
151 | 151 |
152 static void | 152 static void |
153 gaim_upnp_timeout(gpointer data, | 153 gaim_upnp_timeout(gpointer data, |
154 gint source, | 154 gint source, |
155 GaimInputCondition cond) | 155 GaimInputCondition cond) |
156 { | 156 { |
157 HRD* hrd = data; | 157 HRD* hrd = data; |
158 | 158 |
159 gaim_input_remove(hrd->inpa); | 159 gaim_input_remove(hrd->inpa); |
242 hrd->recvBuffer = NULL; | 242 hrd->recvBuffer = NULL; |
243 hrd->totalSizeRecv = 0; | 243 hrd->totalSizeRecv = 0; |
244 hrd->done = FALSE; | 244 hrd->done = FALSE; |
245 | 245 |
246 hrd->recvBuffer = (char*)malloc(MAX_DESCRIPTION_RECIEVE_SIZE); | 246 hrd->recvBuffer = (char*)malloc(MAX_DESCRIPTION_RECIEVE_SIZE); |
247 if(hrd == NULL) { | 247 if(hrd->recvBuffer == NULL) { |
248 gaim_debug_info("upnp", | 248 gaim_debug_info("upnp", |
249 "gaim_upnp_http_request(): Failed in recvBuffer MALLOC\n\n"); | 249 "gaim_upnp_http_request(): Failed in recvBuffer MALLOC\n\n"); |
250 free(hrd); | 250 free(hrd); |
251 return NULL; | 251 return NULL; |
252 } | 252 } |
642 int sizeRecv; | 642 int sizeRecv; |
643 HRD* hrd = data; | 643 HRD* hrd = data; |
644 | 644 |
645 gaim_timeout_remove(hrd->tima); | 645 gaim_timeout_remove(hrd->tima); |
646 length = sizeof(struct sockaddr_in); | 646 length = sizeof(struct sockaddr_in); |
647 hrd->recvBuffer = (char*)malloc(MAX_DISCOVERY_RECIEVE_SIZE); | |
648 | 647 |
649 do { | 648 do { |
650 sizeRecv = recvfrom(sock, hrd->recvBuffer, | 649 sizeRecv = recvfrom(sock, hrd->recvBuffer, |
651 MAX_DISCOVERY_RECIEVE_SIZE, 0, | 650 MAX_DISCOVERY_RECIEVE_SIZE, 0, |
652 (struct sockaddr*)&from, &length); | 651 (struct sockaddr*)&from, &length); |
661 | 660 |
662 gaim_input_remove(hrd->inpa); | 661 gaim_input_remove(hrd->inpa); |
663 hrd->done = TRUE; | 662 hrd->done = TRUE; |
664 return; | 663 return; |
665 } | 664 } |
665 | |
666 | 666 |
667 | 667 |
668 char* | 668 char* |
669 gaim_upnp_discover(void) | 669 gaim_upnp_discover(void) |
670 { | 670 { |
676 struct hostent *hp; | 676 struct hostent *hp; |
677 char sendMessage[] = SEARCH_REQUEST_STRING; | 677 char sendMessage[] = SEARCH_REQUEST_STRING; |
678 char *controlURL = NULL; | 678 char *controlURL = NULL; |
679 | 679 |
680 HRD* hrd = (HRD*)malloc(sizeof(HRD)); | 680 HRD* hrd = (HRD*)malloc(sizeof(HRD)); |
681 hrd->recvBuffer = NULL; | 681 if(hrd == NULL) { |
682 hrd->done = FALSE; | 682 gaim_debug_info("upnp", |
683 "gaim_upnp_discover(): Failed in hrd MALLOC\n\n"); | |
684 return NULL; | |
685 } | |
683 | 686 |
684 sock = socket(AF_INET, SOCK_DGRAM, 0); | 687 sock = socket(AF_INET, SOCK_DGRAM, 0); |
685 if (sock == -1) { | 688 if (sock == -1) { |
686 close(sock); | 689 close(sock); |
687 gaim_debug_info("upnp", | 690 gaim_debug_info("upnp", |
688 "gaim_upnp_discover(): Failed In sock creation\n\n"); | 691 "gaim_upnp_discover(): Failed In sock creation\n\n"); |
692 free(hrd->recvBuffer); | |
693 free(hrd); | |
689 return NULL; | 694 return NULL; |
690 } | 695 } |
691 | 696 |
692 memset(&server, 0, sizeof(struct sockaddr)); | 697 memset(&server, 0, sizeof(struct sockaddr)); |
693 server.sin_family = AF_INET; | 698 server.sin_family = AF_INET; |
694 if((hp = gethostbyname(HTTPMU_HOST_ADDRESS)) == NULL) { | 699 if((hp = gethostbyname(HTTPMU_HOST_ADDRESS)) == NULL) { |
695 close(sock); | 700 close(sock); |
696 gaim_debug_info("upnp", | 701 gaim_debug_info("upnp", |
697 "gaim_upnp_discover(): Failed In gethostbyname\n\n"); | 702 "gaim_upnp_discover(): Failed In gethostbyname\n\n"); |
703 free(hrd->recvBuffer); | |
704 free(hrd); | |
698 return NULL; | 705 return NULL; |
699 } | 706 } |
700 | 707 |
701 memcpy(&server.sin_addr, | 708 memcpy(&server.sin_addr, |
702 hp->h_addr_list[0], | 709 hp->h_addr_list[0], |
707 we should retry the send NUM_UDP_ATTEMPTS times */ | 714 we should retry the send NUM_UDP_ATTEMPTS times */ |
708 for(i = 0; i < NUM_UDP_ATTEMPTS; i++) { | 715 for(i = 0; i < NUM_UDP_ATTEMPTS; i++) { |
709 sentSuccess = TRUE; | 716 sentSuccess = TRUE; |
710 recvSuccess = TRUE; | 717 recvSuccess = TRUE; |
711 totalSizeSent = 0; | 718 totalSizeSent = 0; |
719 | |
720 hrd->recvBuffer = NULL; | |
721 hrd->totalSizeRecv = 0; | |
722 hrd->done = FALSE; | |
723 | |
724 hrd->recvBuffer = (char*)malloc(MAX_DISCOVERY_RECIEVE_SIZE); | |
725 if(hrd->recvBuffer == NULL) { | |
726 gaim_debug_info("upnp", | |
727 "gaim_upnp_discover(): Failed in hrd->recvBuffer MALLOC\n\n"); | |
728 free(hrd); | |
729 return NULL; | |
730 } | |
712 | 731 |
713 while(totalSizeSent < strlen(sendMessage)) { | 732 while(totalSizeSent < strlen(sendMessage)) { |
714 sizeSent = sendto(sock,(void*)&sendMessage[totalSizeSent], | 733 sizeSent = sendto(sock,(void*)&sendMessage[totalSizeSent], |
715 strlen(&sendMessage[totalSizeSent]),0, | 734 strlen(&sendMessage[totalSizeSent]),0, |
716 (struct sockaddr*)&server, | 735 (struct sockaddr*)&server, |
740 if((controlURL= | 759 if((controlURL= |
741 gaim_upnp_parse_discover_response(hrd->recvBuffer, | 760 gaim_upnp_parse_discover_response(hrd->recvBuffer, |
742 strlen(hrd->recvBuffer)))==NULL) { | 761 strlen(hrd->recvBuffer)))==NULL) { |
743 gaim_debug_info("upnp", | 762 gaim_debug_info("upnp", |
744 "gaim_upnp_discover(): Failed In parse response\n\n"); | 763 "gaim_upnp_discover(): Failed In parse response\n\n"); |
764 free(hrd->recvBuffer); | |
765 free(hrd); | |
745 return NULL; | 766 return NULL; |
746 } | 767 } |
747 } | 768 } |
748 } | 769 } |
749 | 770 |
750 /* if sent success and recv successful, then break */ | 771 /* if sent success and recv successful, then break */ |
751 if(sentSuccess && recvSuccess) { | 772 if(sentSuccess && recvSuccess) { |
752 i = NUM_UDP_ATTEMPTS; | 773 i = NUM_UDP_ATTEMPTS; |
753 } | 774 } |
754 } | 775 } |
776 | |
777 if(hrd->recvBuffer != NULL) { | |
778 free(hrd->recvBuffer); | |
779 } | |
780 free(hrd); | |
781 | |
755 if(!sentSuccess || !recvSuccess) { | 782 if(!sentSuccess || !recvSuccess) { |
756 close(sock); | 783 close(sock); |
757 gaim_debug_info("upnp", | 784 gaim_debug_info("upnp", |
758 "gaim_upnp_discover(): Failed In sent/recv success\n\n"); | 785 "gaim_upnp_discover(): Failed In sent/recv success\n\n"); |
759 return NULL; | 786 return NULL; |