diff options
author | Moon <moon@140774ce-b5e7-0310-ab8b-a85725594a96> | 2010-11-14 14:44:14 +0000 |
---|---|---|
committer | Moon <moon@140774ce-b5e7-0310-ab8b-a85725594a96> | 2010-11-14 14:44:14 +0000 |
commit | 229129d604db814f4c5bf87daddb50384c5e3109 (patch) | |
tree | 87521613a159a1036cd50e7ec8e61e6444acb495 /src | |
parent | e225bf6dafda3428bf4224281b25da778a8d3749 (diff) | |
download | gnunet-229129d604db814f4c5bf87daddb50384c5e3109.tar.gz gnunet-229129d604db814f4c5bf87daddb50384c5e3109.zip |
fix choosing UPnP device URL and device type
Diffstat (limited to 'src')
-rw-r--r-- | src/nat/upnp-discover.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/nat/upnp-discover.c b/src/nat/upnp-discover.c index 39ed389a6..5e955db45 100644 --- a/src/nat/upnp-discover.c +++ b/src/nat/upnp-discover.c | |||
@@ -682,18 +682,20 @@ get_absolute_url (const char *ref_url, int is_desc_file, const char *raw_url) | |||
682 | 682 | ||
683 | 683 | ||
684 | /** | 684 | /** |
685 | * Construct control URL for device from its description URL and | 685 | * Construct control URL and service type for device from its description URL |
686 | * UPNP_IGD_Data_ information. This involves resolving relative paths | 686 | * and UPNP_IGD_Data_ information. This involves resolving relative paths |
687 | * and choosing between Common Interface Config and interface-specific | 687 | * and choosing between Common Interface Config and interface-specific |
688 | * paths. | 688 | * paths. |
689 | * | 689 | * |
690 | * @param desc_url URL to the description file of the device | 690 | * @param desc_url URL to the description file of the device |
691 | * @param data IGD information obtained from the description file | 691 | * @param data IGD information obtained from the description file |
692 | * @returns a URL to control the IGD device, or the empty string | 692 | * @param control_url place to store a URL to control the IGD device (will be |
693 | * in case of failure | 693 | * the empty string in case of failure) |
694 | * @param service_type place to store the service type corresponding to control_url | ||
695 | * (will be the empty string in case of failure) | ||
694 | */ | 696 | */ |
695 | static char * | 697 | static void |
696 | format_control_urls (const char *desc_url, struct UPNP_IGD_Data_ *data) | 698 | format_control_urls (const char *desc_url, struct UPNP_IGD_Data_ *data, char **control_url, char **service_type) |
697 | { | 699 | { |
698 | const char *ref_url; | 700 | const char *ref_url; |
699 | int is_desc_file; | 701 | int is_desc_file; |
@@ -710,11 +712,22 @@ format_control_urls (const char *desc_url, struct UPNP_IGD_Data_ *data) | |||
710 | } | 712 | } |
711 | 713 | ||
712 | if (data->control_url[0] != '\0') | 714 | if (data->control_url[0] != '\0') |
713 | return get_absolute_url (ref_url, is_desc_file, data->control_url); | 715 | { |
716 | *control_url = get_absolute_url (ref_url, is_desc_file, data->control_url); | ||
717 | *service_type = GNUNET_strdup (data->service_type); | ||
718 | } | ||
714 | else if (data->control_url_CIF[0] != '\0') | 719 | else if (data->control_url_CIF[0] != '\0') |
715 | return get_absolute_url (ref_url, is_desc_file, data->control_url_CIF); | 720 | { |
721 | *control_url = get_absolute_url (ref_url, is_desc_file, data->control_url_CIF); | ||
722 | *service_type = GNUNET_strdup (data->service_type_CIF); | ||
723 | } | ||
716 | else | 724 | else |
717 | return GNUNET_strdup (""); | 725 | { |
726 | /* If no suitable URL-service type pair was found, set both to empty | ||
727 | * to avoid pretending things will work */ | ||
728 | *control_url = GNUNET_strdup (""); | ||
729 | *service_type = GNUNET_strdup (""); | ||
730 | } | ||
718 | } | 731 | } |
719 | 732 | ||
720 | static void get_valid_igd (struct UPNP_discover_cls *cls); | 733 | static void get_valid_igd (struct UPNP_discover_cls *cls); |
@@ -789,16 +802,9 @@ get_valid_igd_receive (char *desc, void *data) | |||
789 | memset (igd_data, 0, sizeof (struct UPNP_IGD_Data_)); | 802 | memset (igd_data, 0, sizeof (struct UPNP_IGD_Data_)); |
790 | UPNP_IGD_parse_desc_ (desc, strlen (desc), igd_data); | 803 | UPNP_IGD_parse_desc_ (desc, strlen (desc), igd_data); |
791 | 804 | ||
792 | cls->current_dev->control_url = | 805 | format_control_urls (cls->current_dev->desc_url, igd_data, |
793 | format_control_urls (cls->current_dev->desc_url, igd_data); | 806 | &cls->current_dev->control_url, |
794 | 807 | &cls->current_dev->service_type); | |
795 | if (igd_data->service_type != '\0') | ||
796 | cls->current_dev->service_type = GNUNET_strdup (igd_data->service_type); | ||
797 | else if (igd_data->service_type_CIF != '\0') | ||
798 | cls->current_dev->service_type = | ||
799 | GNUNET_strdup (igd_data->service_type_CIF); | ||
800 | else | ||
801 | cls->current_dev->service_type = GNUNET_strdup (""); | ||
802 | 808 | ||
803 | cls->current_dev->data = igd_data; | 809 | cls->current_dev->data = igd_data; |
804 | 810 | ||