diff options
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index 5dd3413e1..0c9bfffc8 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -28,6 +28,80 @@ | |||
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | #include "gnunet_transport_plugin.h" | 29 | #include "gnunet_transport_plugin.h" |
30 | 30 | ||
31 | struct SplittedHTTPAddress | ||
32 | { | ||
33 | char *protocoll; | ||
34 | char *host; | ||
35 | char *port; | ||
36 | char *path; | ||
37 | }; | ||
38 | |||
39 | struct SplittedHTTPAddress * | ||
40 | http_split_address (const char * addr) | ||
41 | { | ||
42 | struct SplittedHTTPAddress *sp; | ||
43 | char *src = GNUNET_strdup (addr); | ||
44 | char *protocoll_start = NULL; | ||
45 | char *host_start = NULL; | ||
46 | char *port_start = NULL; | ||
47 | char *path_start = NULL; | ||
48 | |||
49 | protocoll_start = src; | ||
50 | sp = GNUNET_malloc (sizeof (struct SplittedHTTPAddress)); | ||
51 | |||
52 | host_start = strstr (src, "://"); | ||
53 | if (NULL == host_start) | ||
54 | { | ||
55 | GNUNET_free (src); | ||
56 | GNUNET_free (sp); | ||
57 | return NULL; | ||
58 | } | ||
59 | |||
60 | host_start[0] = '\0'; | ||
61 | sp->protocoll = GNUNET_strdup (protocoll_start); | ||
62 | |||
63 | host_start += strlen ("://"); | ||
64 | if (strlen (host_start) == 0) | ||
65 | if (NULL == host_start) | ||
66 | { | ||
67 | GNUNET_free (src); | ||
68 | GNUNET_free (sp); | ||
69 | return NULL; | ||
70 | } | ||
71 | port_start = strstr (host_start, ":"); | ||
72 | if (NULL == port_start) | ||
73 | { | ||
74 | path_start = strstr (host_start, "/"); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | port_start[0] = '\0'; | ||
79 | port_start ++; | ||
80 | sp->host = GNUNET_strdup (host_start); | ||
81 | path_start = strstr (port_start, "/"); | ||
82 | } | ||
83 | |||
84 | if (NULL == path_start) | ||
85 | { | ||
86 | if (NULL != port_start) | ||
87 | sp->port = GNUNET_strdup (port_start); | ||
88 | sp->path = NULL; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | if (NULL != port_start) | ||
93 | { | ||
94 | path_start[0] = '\0'; | ||
95 | sp->port = GNUNET_strdup (port_start); | ||
96 | path_start[0] = '/'; | ||
97 | } | ||
98 | sp->path = GNUNET_strdup(path_start); | ||
99 | } | ||
100 | GNUNET_free (src); | ||
101 | fprintf (stderr, "protocoll: `%s', host `%s' port `%s' path `%s'\n", sp->protocoll, sp->host, sp->port, sp->path); | ||
102 | return sp; | ||
103 | } | ||
104 | |||
31 | /** | 105 | /** |
32 | * Convert the transports address to a nice, human-readable | 106 | * Convert the transports address to a nice, human-readable |
33 | * format. | 107 | * format. |
@@ -59,6 +133,7 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
59 | asc (asc_cls, NULL); | 133 | asc (asc_cls, NULL); |
60 | return; | 134 | return; |
61 | } | 135 | } |
136 | http_split_address (addr); | ||
62 | asc (asc_cls, saddr); | 137 | asc (asc_cls, saddr); |
63 | asc (asc_cls, NULL); | 138 | asc (asc_cls, NULL); |
64 | } | 139 | } |