diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-23 16:39:06 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-23 16:39:06 +0000 |
commit | 23c25488aa4ed08ce2ebb67e9fff031e23b0cb39 (patch) | |
tree | a2635f627a35274806065663d1edaea6eb7bebc2 /src/transport/plugin_transport_http.c | |
parent | d3bc6a83ba461e0d0dcc2c415c536f0c6116261b (diff) | |
download | gnunet-23c25488aa4ed08ce2ebb67e9fff031e23b0cb39.tar.gz gnunet-23c25488aa4ed08ce2ebb67e9fff031e23b0cb39.zip |
- code deduplication
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 111 |
1 files changed, 51 insertions, 60 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 8e3bd737c..5bc7d4f01 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -741,14 +741,12 @@ http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | static void | 744 | static void * |
745 | nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, | 745 | find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen) |
746 | socklen_t addrlen) | ||
747 | { | 746 | { |
748 | struct Plugin *plugin = cls; | 747 | int af; |
749 | struct IPv4HttpAddressWrapper *w_t4 = NULL; | 748 | struct IPv4HttpAddressWrapper *w_t4 = NULL; |
750 | struct IPv6HttpAddressWrapper *w_t6 = NULL; | 749 | struct IPv6HttpAddressWrapper *w_t6 = NULL; |
751 | int af; | ||
752 | 750 | ||
753 | af = addr->sa_family; | 751 | af = addr->sa_family; |
754 | switch (af) | 752 | switch (af) |
@@ -773,8 +771,52 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
773 | break; | 771 | break; |
774 | w_t4 = w_t4->next; | 772 | w_t4 = w_t4->next; |
775 | } | 773 | } |
774 | return w_t4; | ||
775 | break; | ||
776 | case AF_INET6: | ||
777 | w_t6 = plugin->ipv6_addr_head; | ||
778 | struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; | ||
779 | |||
780 | while (w_t6) | ||
781 | { | ||
782 | int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, | ||
783 | sizeof (struct in6_addr)); | ||
784 | |||
785 | if (res == 0) | ||
786 | { | ||
787 | if (a6->sin6_port != w_t6->addr6.u6_port) | ||
788 | res = -1; | ||
789 | } | ||
790 | if (0 == res) | ||
791 | break; | ||
792 | w_t6 = w_t6->next; | ||
793 | } | ||
794 | return w_t6; | ||
795 | break; | ||
796 | default: | ||
797 | return NULL; | ||
798 | } | ||
799 | |||
800 | |||
801 | } | ||
802 | |||
803 | static void | ||
804 | nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, | ||
805 | socklen_t addrlen) | ||
806 | { | ||
807 | struct Plugin *plugin = cls; | ||
808 | struct IPv4HttpAddressWrapper *w_t4 = NULL; | ||
809 | struct IPv6HttpAddressWrapper *w_t6 = NULL; | ||
810 | int af; | ||
811 | |||
812 | af = addr->sa_family; | ||
813 | switch (af) | ||
814 | { | ||
815 | case AF_INET: | ||
816 | w_t4 = find_address (plugin, addr, addrlen); | ||
776 | if (w_t4 == NULL) | 817 | if (w_t4 == NULL) |
777 | { | 818 | { |
819 | struct sockaddr_in *a4 = (struct sockaddr_in *) addr; | ||
778 | w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper)); | 820 | w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper)); |
779 | memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr)); | 821 | memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr)); |
780 | w_t4->addr.u4_port = a4->sin_port; | 822 | w_t4->addr.u4_port = a4->sin_port; |
@@ -794,27 +836,11 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
794 | 836 | ||
795 | break; | 837 | break; |
796 | case AF_INET6: | 838 | case AF_INET6: |
797 | w_t6 = plugin->ipv6_addr_head; | 839 | w_t6 = find_address (plugin, addr, addrlen); |
798 | struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; | ||
799 | |||
800 | while (w_t6) | ||
801 | { | ||
802 | int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, | ||
803 | sizeof (struct in6_addr)); | ||
804 | |||
805 | if (res == 0) | ||
806 | { | ||
807 | if (a6->sin6_port != w_t6->addr6.u6_port) | ||
808 | res = -1; | ||
809 | } | ||
810 | if (0 == res) | ||
811 | break; | ||
812 | w_t6 = w_t6->next; | ||
813 | } | ||
814 | if (w_t6 == NULL) | 840 | if (w_t6 == NULL) |
815 | { | 841 | { |
816 | w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper)); | 842 | w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper)); |
817 | 843 | struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; | |
818 | memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr)); | 844 | memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr)); |
819 | w_t6->addr6.u6_port = a6->sin6_port; | 845 | w_t6->addr6.u6_port = a6->sin6_port; |
820 | 846 | ||
@@ -850,26 +876,7 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
850 | switch (af) | 876 | switch (af) |
851 | { | 877 | { |
852 | case AF_INET: | 878 | case AF_INET: |
853 | w_t4 = plugin->ipv4_addr_head; | 879 | w_t4 = find_address (plugin, addr, addrlen); |
854 | struct sockaddr_in *a4 = (struct sockaddr_in *) addr; | ||
855 | |||
856 | while (w_t4 != NULL) | ||
857 | { | ||
858 | int res = memcmp (&w_t4->addr.ipv4_addr, | ||
859 | &a4->sin_addr, | ||
860 | sizeof (struct in_addr)); | ||
861 | |||
862 | if (res == 0) | ||
863 | { | ||
864 | if (a4->sin_port != w_t4->addr.u4_port) | ||
865 | res = -1; | ||
866 | } | ||
867 | |||
868 | if (0 == res) | ||
869 | break; | ||
870 | w_t4 = w_t4->next; | ||
871 | } | ||
872 | if (w_t4 == NULL) | ||
873 | return; | 880 | return; |
874 | 881 | ||
875 | #if DEBUG_HTTP | 882 | #if DEBUG_HTTP |
@@ -887,23 +894,7 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
887 | GNUNET_free (w_t4); | 894 | GNUNET_free (w_t4); |
888 | break; | 895 | break; |
889 | case AF_INET6: | 896 | case AF_INET6: |
890 | w_t6 = plugin->ipv6_addr_head; | 897 | w_t6 = find_address (plugin, addr, addrlen); |
891 | struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr; | ||
892 | |||
893 | while (w_t6) | ||
894 | { | ||
895 | int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, | ||
896 | sizeof (struct in6_addr)); | ||
897 | |||
898 | if (res == 0) | ||
899 | { | ||
900 | if (a6->sin6_port != w_t6->addr6.u6_port) | ||
901 | res = -1; | ||
902 | } | ||
903 | if (0 == res) | ||
904 | break; | ||
905 | w_t6 = w_t6->next; | ||
906 | } | ||
907 | if (w_t6 == NULL) | 898 | if (w_t6 == NULL) |
908 | return; | 899 | return; |
909 | #if DEBUG_HTTP | 900 | #if DEBUG_HTTP |