diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-28 14:51:35 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-28 14:51:35 +0000 |
commit | 0d3fc76af81e705237ab7ccebe6d5c3c71d1757f (patch) | |
tree | 0bfe097d5cf246871cdcd0c1458e3c18b0c7c7b2 /src | |
parent | 5800c4bf0fec9d1c48be72570b8af5ed3ec29e2f (diff) | |
download | gnunet-0d3fc76af81e705237ab7ccebe6d5c3c71d1757f.tar.gz gnunet-0d3fc76af81e705237ab7ccebe6d5c3c71d1757f.zip |
changes
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index f13884507..e71b16e93 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -144,6 +144,90 @@ http_common_address_from_socket (const char *protocol, const struct sockaddr *ad | |||
144 | } | 144 | } |
145 | 145 | ||
146 | /** | 146 | /** |
147 | * Create a socketaddr from a HTTP address | ||
148 | * | ||
149 | * @param protocol protocol | ||
150 | * @param addr sockaddr * address | ||
151 | * @param addrlen length of the address | ||
152 | * @param res the result: | ||
153 | * GNUNET_SYSERR, invalid input, | ||
154 | * GNUNET_YES: could convert to ip, | ||
155 | * GNUNET_NO: valid input but could not convert to ip (hostname?) | ||
156 | * @return the string | ||
157 | */ | ||
158 | struct sockaddr * | ||
159 | http_common_socket_from_address (const void *addr, size_t addrlen, int *res) | ||
160 | { | ||
161 | struct sockaddr_storage *s; | ||
162 | char *addrs; | ||
163 | char *addrs_org; | ||
164 | char *addrs_end; | ||
165 | (*res) = GNUNET_SYSERR; | ||
166 | |||
167 | if (NULL == addr) | ||
168 | { | ||
169 | GNUNET_break (0); | ||
170 | return NULL; | ||
171 | } | ||
172 | if (0 >= addrlen) | ||
173 | { | ||
174 | GNUNET_break (0); | ||
175 | return NULL; | ||
176 | } | ||
177 | if (((char *) addr)[addrlen-1] != '\0') | ||
178 | { | ||
179 | GNUNET_break (0); | ||
180 | return NULL; | ||
181 | } | ||
182 | |||
183 | addrs_org = strdup ((char *) addr); | ||
184 | addrs = strstr (addrs_org , "://"); | ||
185 | if (NULL == addrs) | ||
186 | { | ||
187 | GNUNET_break (0); | ||
188 | GNUNET_free (addrs_org); | ||
189 | return NULL; | ||
190 | } | ||
191 | |||
192 | if (strlen (addrs) < 3) | ||
193 | { | ||
194 | GNUNET_break (0); | ||
195 | GNUNET_free (addrs_org); | ||
196 | return NULL; | ||
197 | } | ||
198 | |||
199 | addrs += 3; | ||
200 | |||
201 | addrs_end = strchr (addrs, '/'); | ||
202 | if (NULL != addrs_end) | ||
203 | addrs[strlen (addrs) - strlen(addrs_end)] = '\0'; | ||
204 | |||
205 | s = GNUNET_malloc (sizeof (struct sockaddr_storage)); | ||
206 | if (GNUNET_SYSERR == GNUNET_STRINGS_to_address_ip (addrs, strlen(addrs), s)) | ||
207 | { | ||
208 | /* could be a hostname */ | ||
209 | GNUNET_free (s); | ||
210 | GNUNET_free (addrs_org); | ||
211 | (*res) = GNUNET_NO; | ||
212 | return NULL; | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) | ||
217 | { | ||
218 | GNUNET_break (0); | ||
219 | GNUNET_free (s); | ||
220 | GNUNET_free (addrs_org); | ||
221 | (*res) = GNUNET_SYSERR; | ||
222 | return NULL; | ||
223 | } | ||
224 | } | ||
225 | (*res) = GNUNET_YES; | ||
226 | GNUNET_free (addrs_org); | ||
227 | return (struct sockaddr *) s; | ||
228 | } | ||
229 | |||
230 | /** | ||
147 | * Get the length of an address | 231 | * Get the length of an address |
148 | * | 232 | * |
149 | * @param addr address | 233 | * @param addr address |