aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_client.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-22 13:41:23 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-22 13:41:23 +0000
commit802a9598bed7f149466072f6e6834559bab2cd2e (patch)
treefc2e6c81d202299b45725831966af818428d05d8 /src/transport/plugin_transport_http_client.c
parent014487cd170b00d258264cc86392b8d91bdf0616 (diff)
downloadgnunet-802a9598bed7f149466072f6e6834559bab2cd2e.tar.gz
gnunet-802a9598bed7f149466072f6e6834559bab2cd2e.zip
changes
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r--src/transport/plugin_transport_http_client.c143
1 files changed, 85 insertions, 58 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index c2dda5efc..e2967745e 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -41,6 +41,9 @@
41#include "gnunet_statistics_service.h" 41#include "gnunet_statistics_service.h"
42#include "gnunet_transport_service.h" 42#include "gnunet_transport_service.h"
43#include "gnunet_transport_plugin.h" 43#include "gnunet_transport_plugin.h"
44#include "plugin_transport_http_common.h"
45#include <curl/curl.h>
46
44 47
45#define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING 48#define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING
46 49
@@ -126,10 +129,39 @@ struct HTTP_Client_Plugin
126 struct GNUNET_TRANSPORT_PluginEnvironment *env; 129 struct GNUNET_TRANSPORT_PluginEnvironment *env;
127 130
128 /** 131 /**
129 * List of open sessions. 132 * Linked list head of open sessions.
133 */
134 struct Session *head;
135
136 /**
137 * Linked list tail of open sessions.
138 */
139 struct Session *tail;
140
141 /**
142 * Plugin name
143 */
144 char *name;
145
146 /**
147 * Protocol
148 */
149 char *protocol;
150
151 /**
152 * use IPv6
153 */
154 uint16_t use_ipv6;
155
156 /**
157 * use IPv4
130 */ 158 */
131 struct Session *sessions; 159 uint16_t use_ipv4;
132 160
161 /**
162 * cURL Multihandle
163 */
164 CURLM *curl_multi_handle;
133}; 165};
134 166
135 167
@@ -195,33 +227,32 @@ http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ
195 // FIXME 227 // FIXME
196} 228}
197 229
198
199/**
200 * Convert the transports address to a nice, human-readable
201 * format.
202 *
203 * @param cls closure
204 * @param type name of the transport that generated the address
205 * @param addr one of the addresses of the host, NULL for the last address
206 * the specific address format depends on the transport
207 * @param addrlen length of the address
208 * @param numeric should (IP) addresses be displayed in numeric form?
209 * @param timeout after how long should we give up?
210 * @param asc function to call on each string
211 * @param asc_cls closure for asc
212 */
213static void 230static void
214http_client_plugin_address_pretty_printer (void *cls, const char *type, 231client_stop (struct HTTP_Client_Plugin *plugin)
215 const void *addr, size_t addrlen,
216 int numeric,
217 struct GNUNET_TIME_Relative timeout,
218 GNUNET_TRANSPORT_AddressStringCallback
219 asc, void *asc_cls)
220{ 232{
221 asc (asc_cls, NULL); 233 if (NULL != plugin->curl_multi_handle)
234 {
235 curl_multi_cleanup (plugin->curl_multi_handle);
236 plugin->curl_multi_handle = NULL;
237 }
238 curl_global_cleanup ();
222} 239}
223 240
224 241static int
242client_start (struct HTTP_Client_Plugin *plugin)
243{
244 curl_global_init (CURL_GLOBAL_ALL);
245 plugin->curl_multi_handle = curl_multi_init ();
246
247 if (NULL == plugin->curl_multi_handle)
248 {
249 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
250 _("Could not initialize curl multi handle, failed to start %s plugin!\n"),
251 plugin->name);
252 return GNUNET_SYSERR;
253 }
254 return GNUNET_OK;
255}
225 256
226/** 257/**
227 * Another peer has suggested an address for this 258 * Another peer has suggested an address for this
@@ -240,31 +271,25 @@ http_client_plugin_address_suggested (void *cls, const void *addr, size_t addrle
240{ 271{
241 /* struct Plugin *plugin = cls; */ 272 /* struct Plugin *plugin = cls; */
242 273
243 /* check if the address is plausible; if so, 274 /* A HTTP/S client does not have any valid address so:*/
244 * add it to our list! */ 275 return GNUNET_NO;
245 return GNUNET_OK;
246} 276}
247 277
248
249/** 278/**
250 * Function called for a quick conversion of the binary address to 279 * Exit point from the plugin.
251 * a numeric address. Note that the caller must not free the
252 * address and that the next call to this function is allowed
253 * to override the address again.
254 *
255 * @param cls closure
256 * @param addr binary address
257 * @param addrlen length of the address
258 * @return string representing the same address
259 */ 280 */
260static const char * 281void *
261http_client_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 282LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
262{ 283{
263 GNUNET_break (0); 284 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
264 return NULL; 285 struct HTTP_Client_Plugin *plugin = api->cls;
265}
266 286
287 client_stop (plugin);
267 288
289 GNUNET_free (plugin);
290 GNUNET_free (api);
291 return NULL;
292}
268 293
269 294
270/** 295/**
@@ -283,25 +308,27 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
283 api->cls = plugin; 308 api->cls = plugin;
284 api->send = &http_client_plugin_send; 309 api->send = &http_client_plugin_send;
285 api->disconnect = &http_client_plugin_disconnect; 310 api->disconnect = &http_client_plugin_disconnect;
286 api->address_pretty_printer = &http_client_plugin_address_pretty_printer;
287 api->check_address = &http_client_plugin_address_suggested; 311 api->check_address = &http_client_plugin_address_suggested;
288 api->address_to_string = &http_client_plugin_address_to_string;
289 return api;
290}
291 312
313 api->address_to_string = &http_common_plugin_address_to_string;
314 api->string_to_address = &http_common_plugin_string_to_address;
315 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
292 316
293/** 317#if BUILD_HTTPS
294 * Exit point from the plugin. 318 plugin->name = "transport-https_client";
295 */ 319 plugin->protocol = "https";
296void * 320#else
297LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) 321 plugin->name = "transport-http_client";
298{ 322 plugin->protocol = "http";
299 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 323#endif
300 struct HTTP_Client_Plugin *plugin = api->cls;
301 324
302 GNUNET_free (plugin); 325 /* Start client */
303 GNUNET_free (api); 326 if (GNUNET_SYSERR == client_start (plugin))
304 return NULL; 327 {
328 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
329 return NULL;
330 }
331 return api;
305} 332}
306 333
307/* end of plugin_transport_http_client.c */ 334/* end of plugin_transport_http_client.c */