aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gns.h6
-rw-r--r--src/gns/gns_api.c252
-rw-r--r--src/gns/gns_api.h3
-rw-r--r--src/gns/gns_tld_api.c233
-rw-r--r--src/gns/gnunet-bcd.c582
-rw-r--r--src/gns/gnunet-dns2gns.c801
-rw-r--r--src/gns/gnunet-gns-benchmark.c522
-rw-r--r--src/gns/gnunet-gns-import.c425
-rw-r--r--src/gns/gnunet-gns-proxy.c4189
-rw-r--r--src/gns/gnunet-service-gns.c471
-rw-r--r--src/gns/gnunet-service-gns.h6
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c427
-rw-r--r--src/gns/gnunet-service-gns_interceptor.h4
-rw-r--r--src/gns/gnunet-service-gns_resolver.c3252
-rw-r--r--src/gns/gnunet-service-gns_resolver.h24
-rw-r--r--src/gns/gnunet_w32nsp_lib.h5
-rw-r--r--src/gns/nss/nss_gns.c193
-rw-r--r--src/gns/nss/nss_gns_query.c138
-rw-r--r--src/gns/nss/nss_gns_query.h18
-rw-r--r--src/gns/plugin_block_gns.c176
-rw-r--r--src/gns/plugin_gnsrecord_gns.c305
-rw-r--r--src/gns/plugin_rest_gns.c275
-rw-r--r--src/gns/test_gns_proxy.c554
-rw-r--r--src/gns/w32resolver.h3
24 files changed, 6510 insertions, 6354 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h
index 8465f49f9..1fa812c23 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -33,7 +33,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
33/** 33/**
34 * Message from client to GNS service to lookup records. 34 * Message from client to GNS service to lookup records.
35 */ 35 */
36struct LookupMessage { 36struct LookupMessage
37{
37 /** 38 /**
38 * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP 39 * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP
39 */ 40 */
@@ -72,7 +73,8 @@ struct LookupMessage {
72/** 73/**
73 * Message from GNS service to client: new results. 74 * Message from GNS service to client: new results.
74 */ 75 */
75struct LookupResultMessage { 76struct LookupResultMessage
77{
76 /** 78 /**
77 * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 79 * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT
78 */ 80 */
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 62f250959..fe0707baa 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -34,12 +34,13 @@
34#include "gns_api.h" 34#include "gns_api.h"
35 35
36 36
37#define LOG(kind, ...) GNUNET_log_from(kind, "gns-api", __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log_from (kind, "gns-api", __VA_ARGS__)
38 38
39/** 39/**
40 * Handle to a lookup request 40 * Handle to a lookup request
41 */ 41 */
42struct GNUNET_GNS_LookupRequest { 42struct GNUNET_GNS_LookupRequest
43{
43 /** 44 /**
44 * DLL 45 * DLL
45 */ 46 */
@@ -83,7 +84,7 @@ struct GNUNET_GNS_LookupRequest {
83 * @param handle the handle to the GNS service 84 * @param handle the handle to the GNS service
84 */ 85 */
85static void 86static void
86reconnect(struct GNUNET_GNS_Handle *handle); 87reconnect (struct GNUNET_GNS_Handle *handle);
87 88
88 89
89/** 90/**
@@ -92,12 +93,12 @@ reconnect(struct GNUNET_GNS_Handle *handle);
92 * @param cls the handle 93 * @param cls the handle
93 */ 94 */
94static void 95static void
95reconnect_task(void *cls) 96reconnect_task (void *cls)
96{ 97{
97 struct GNUNET_GNS_Handle *handle = cls; 98 struct GNUNET_GNS_Handle *handle = cls;
98 99
99 handle->reconnect_task = NULL; 100 handle->reconnect_task = NULL;
100 reconnect(handle); 101 reconnect (handle);
101} 102}
102 103
103 104
@@ -107,16 +108,16 @@ reconnect_task(void *cls)
107 * @param handle our handle 108 * @param handle our handle
108 */ 109 */
109static void 110static void
110force_reconnect(struct GNUNET_GNS_Handle *handle) 111force_reconnect (struct GNUNET_GNS_Handle *handle)
111{ 112{
112 GNUNET_MQ_destroy(handle->mq); 113 GNUNET_MQ_destroy (handle->mq);
113 handle->mq = NULL; 114 handle->mq = NULL;
114 handle->reconnect_backoff 115 handle->reconnect_backoff
115 = GNUNET_TIME_STD_BACKOFF(handle->reconnect_backoff); 116 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
116 handle->reconnect_task 117 handle->reconnect_task
117 = GNUNET_SCHEDULER_add_delayed(handle->reconnect_backoff, 118 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
118 &reconnect_task, 119 &reconnect_task,
119 handle); 120 handle);
120} 121}
121 122
122 123
@@ -129,15 +130,15 @@ force_reconnect(struct GNUNET_GNS_Handle *handle)
129 * @param error error code 130 * @param error error code
130 */ 131 */
131static void 132static void
132mq_error_handler(void *cls, 133mq_error_handler (void *cls,
133 enum GNUNET_MQ_Error error) 134 enum GNUNET_MQ_Error error)
134{ 135{
135 struct GNUNET_GNS_Handle *handle = cls; 136 struct GNUNET_GNS_Handle *handle = cls;
136 137
137 LOG(GNUNET_ERROR_TYPE_WARNING, 138 LOG (GNUNET_ERROR_TYPE_WARNING,
138 "Problem with message queue. error: %i\n", 139 "Problem with message queue. error: %i\n",
139 error); 140 error);
140 force_reconnect(handle); 141 force_reconnect (handle);
141} 142}
142 143
143 144
@@ -148,23 +149,23 @@ mq_error_handler(void *cls,
148 * @param loookup_msg the incoming message 149 * @param loookup_msg the incoming message
149 */ 150 */
150static int 151static int
151check_result(void *cls, 152check_result (void *cls,
152 const struct LookupResultMessage *lookup_msg) 153 const struct LookupResultMessage *lookup_msg)
153{ 154{
154 size_t mlen = ntohs(lookup_msg->header.size) - sizeof(*lookup_msg); 155 size_t mlen = ntohs (lookup_msg->header.size) - sizeof(*lookup_msg);
155 uint32_t rd_count = ntohl(lookup_msg->rd_count); 156 uint32_t rd_count = ntohl (lookup_msg->rd_count);
156 struct GNUNET_GNSRECORD_Data rd[rd_count]; 157 struct GNUNET_GNSRECORD_Data rd[rd_count];
157 158
158 (void)cls; 159 (void) cls;
159 if (GNUNET_SYSERR == 160 if (GNUNET_SYSERR ==
160 GNUNET_GNSRECORD_records_deserialize(mlen, 161 GNUNET_GNSRECORD_records_deserialize (mlen,
161 (const char*)&lookup_msg[1], 162 (const char*) &lookup_msg[1],
162 rd_count, 163 rd_count,
163 rd)) 164 rd))
164 { 165 {
165 GNUNET_break(0); 166 GNUNET_break (0);
166 return GNUNET_SYSERR; 167 return GNUNET_SYSERR;
167 } 168 }
168 return GNUNET_OK; 169 return GNUNET_OK;
169} 170}
170 171
@@ -176,21 +177,21 @@ check_result(void *cls,
176 * @param loookup_msg the incoming message 177 * @param loookup_msg the incoming message
177 */ 178 */
178static void 179static void
179handle_result(void *cls, 180handle_result (void *cls,
180 const struct LookupResultMessage *lookup_msg) 181 const struct LookupResultMessage *lookup_msg)
181{ 182{
182 struct GNUNET_GNS_Handle *handle = cls; 183 struct GNUNET_GNS_Handle *handle = cls;
183 size_t mlen = ntohs(lookup_msg->header.size) - sizeof(*lookup_msg); 184 size_t mlen = ntohs (lookup_msg->header.size) - sizeof(*lookup_msg);
184 uint32_t rd_count = ntohl(lookup_msg->rd_count); 185 uint32_t rd_count = ntohl (lookup_msg->rd_count);
185 struct GNUNET_GNSRECORD_Data rd[rd_count]; 186 struct GNUNET_GNSRECORD_Data rd[rd_count];
186 uint32_t r_id = ntohl(lookup_msg->id); 187 uint32_t r_id = ntohl (lookup_msg->id);
187 struct GNUNET_GNS_LookupRequest *lr; 188 struct GNUNET_GNS_LookupRequest *lr;
188 GNUNET_GNS_LookupResultProcessor proc; 189 GNUNET_GNS_LookupResultProcessor proc;
189 void *proc_cls; 190 void *proc_cls;
190 191
191 LOG(GNUNET_ERROR_TYPE_DEBUG, 192 LOG (GNUNET_ERROR_TYPE_DEBUG,
192 "Received lookup reply from GNS service (%u records)\n", 193 "Received lookup reply from GNS service (%u records)\n",
193 (unsigned int)rd_count); 194 (unsigned int) rd_count);
194 for (lr = handle->lookup_head; NULL != lr; lr = lr->next) 195 for (lr = handle->lookup_head; NULL != lr; lr = lr->next)
195 if (lr->r_id == r_id) 196 if (lr->r_id == r_id)
196 break; 197 break;
@@ -199,20 +200,21 @@ handle_result(void *cls,
199 proc = lr->lookup_proc; 200 proc = lr->lookup_proc;
200 proc_cls = lr->proc_cls; 201 proc_cls = lr->proc_cls;
201 202
202 GNUNET_assert(GNUNET_OK == 203 GNUNET_assert (GNUNET_OK ==
203 GNUNET_GNSRECORD_records_deserialize(mlen, 204 GNUNET_GNSRECORD_records_deserialize (mlen,
204 (const char*)&lookup_msg[1], 205 (const
205 rd_count, 206 char*) &lookup_msg[1],
206 rd)); 207 rd_count,
207 proc(proc_cls, 208 rd));
208 rd_count, 209 proc (proc_cls,
209 rd); 210 rd_count,
210 GNUNET_CONTAINER_DLL_remove(handle->lookup_head, 211 rd);
211 handle->lookup_tail, 212 GNUNET_CONTAINER_DLL_remove (handle->lookup_head,
212 lr); 213 handle->lookup_tail,
214 lr);
213 if (NULL != lr->env) 215 if (NULL != lr->env)
214 GNUNET_MQ_discard(lr->env); 216 GNUNET_MQ_discard (lr->env);
215 GNUNET_free(lr); 217 GNUNET_free (lr);
216} 218}
217 219
218 220
@@ -222,31 +224,31 @@ handle_result(void *cls,
222 * @param handle the handle to the GNS service 224 * @param handle the handle to the GNS service
223 */ 225 */
224static void 226static void
225reconnect(struct GNUNET_GNS_Handle *handle) 227reconnect (struct GNUNET_GNS_Handle *handle)
226{ 228{
227 struct GNUNET_MQ_MessageHandler handlers[] = { 229 struct GNUNET_MQ_MessageHandler handlers[] = {
228 GNUNET_MQ_hd_var_size(result, 230 GNUNET_MQ_hd_var_size (result,
229 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, 231 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT,
230 struct LookupResultMessage, 232 struct LookupResultMessage,
231 handle), 233 handle),
232 GNUNET_MQ_handler_end() 234 GNUNET_MQ_handler_end ()
233 }; 235 };
234 236
235 GNUNET_assert(NULL == handle->mq); 237 GNUNET_assert (NULL == handle->mq);
236 LOG(GNUNET_ERROR_TYPE_DEBUG, 238 LOG (GNUNET_ERROR_TYPE_DEBUG,
237 "Trying to connect to GNS\n"); 239 "Trying to connect to GNS\n");
238 handle->mq = GNUNET_CLIENT_connect(handle->cfg, 240 handle->mq = GNUNET_CLIENT_connect (handle->cfg,
239 "gns", 241 "gns",
240 handlers, 242 handlers,
241 &mq_error_handler, 243 &mq_error_handler,
242 handle); 244 handle);
243 if (NULL == handle->mq) 245 if (NULL == handle->mq)
244 return; 246 return;
245 for (struct GNUNET_GNS_LookupRequest *lh = handle->lookup_head; 247 for (struct GNUNET_GNS_LookupRequest *lh = handle->lookup_head;
246 NULL != lh; 248 NULL != lh;
247 lh = lh->next) 249 lh = lh->next)
248 GNUNET_MQ_send_copy(handle->mq, 250 GNUNET_MQ_send_copy (handle->mq,
249 lh->env); 251 lh->env);
250} 252}
251 253
252 254
@@ -257,18 +259,18 @@ reconnect(struct GNUNET_GNS_Handle *handle)
257 * @return handle to the GNS service, or NULL on error 259 * @return handle to the GNS service, or NULL on error
258 */ 260 */
259struct GNUNET_GNS_Handle * 261struct GNUNET_GNS_Handle *
260GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) 262GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
261{ 263{
262 struct GNUNET_GNS_Handle *handle; 264 struct GNUNET_GNS_Handle *handle;
263 265
264 handle = GNUNET_new(struct GNUNET_GNS_Handle); 266 handle = GNUNET_new (struct GNUNET_GNS_Handle);
265 handle->cfg = cfg; 267 handle->cfg = cfg;
266 reconnect(handle); 268 reconnect (handle);
267 if (NULL == handle->mq) 269 if (NULL == handle->mq)
268 { 270 {
269 GNUNET_free(handle); 271 GNUNET_free (handle);
270 return NULL; 272 return NULL;
271 } 273 }
272 return handle; 274 return handle;
273} 275}
274 276
@@ -279,20 +281,20 @@ GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
279 * @param handle handle of the GNS connection to stop 281 * @param handle handle of the GNS connection to stop
280 */ 282 */
281void 283void
282GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle) 284GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
283{ 285{
284 if (NULL != handle->mq) 286 if (NULL != handle->mq)
285 { 287 {
286 GNUNET_MQ_destroy(handle->mq); 288 GNUNET_MQ_destroy (handle->mq);
287 handle->mq = NULL; 289 handle->mq = NULL;
288 } 290 }
289 if (NULL != handle->reconnect_task) 291 if (NULL != handle->reconnect_task)
290 { 292 {
291 GNUNET_SCHEDULER_cancel(handle->reconnect_task); 293 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
292 handle->reconnect_task = NULL; 294 handle->reconnect_task = NULL;
293 } 295 }
294 GNUNET_assert(NULL == handle->lookup_head); 296 GNUNET_assert (NULL == handle->lookup_head);
295 GNUNET_free(handle); 297 GNUNET_free (handle);
296} 298}
297 299
298 300
@@ -303,17 +305,17 @@ GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
303 * @return closure from the lookup result processor 305 * @return closure from the lookup result processor
304 */ 306 */
305void * 307void *
306GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr) 308GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr)
307{ 309{
308 struct GNUNET_GNS_Handle *handle = lr->gns_handle; 310 struct GNUNET_GNS_Handle *handle = lr->gns_handle;
309 void *ret; 311 void *ret;
310 312
311 GNUNET_CONTAINER_DLL_remove(handle->lookup_head, 313 GNUNET_CONTAINER_DLL_remove (handle->lookup_head,
312 handle->lookup_tail, 314 handle->lookup_tail,
313 lr); 315 lr);
314 GNUNET_MQ_discard(lr->env); 316 GNUNET_MQ_discard (lr->env);
315 ret = lr->proc_cls; 317 ret = lr->proc_cls;
316 GNUNET_free(lr); 318 GNUNET_free (lr);
317 return ret; 319 return ret;
318} 320}
319 321
@@ -331,13 +333,13 @@ GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr)
331 * @return handle to the get request 333 * @return handle to the get request
332 */ 334 */
333struct GNUNET_GNS_LookupRequest* 335struct GNUNET_GNS_LookupRequest*
334GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, 336GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
335 const char *name, 337 const char *name,
336 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, 338 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
337 uint32_t type, 339 uint32_t type,
338 enum GNUNET_GNS_LocalOptions options, 340 enum GNUNET_GNS_LocalOptions options,
339 GNUNET_GNS_LookupResultProcessor proc, 341 GNUNET_GNS_LookupResultProcessor proc,
340 void *proc_cls) 342 void *proc_cls)
341{ 343{
342 /* IPC to shorten gns names, return shorten_handle */ 344 /* IPC to shorten gns names, return shorten_handle */
343 struct LookupMessage *lookup_msg; 345 struct LookupMessage *lookup_msg;
@@ -345,40 +347,40 @@ GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle,
345 size_t nlen; 347 size_t nlen;
346 348
347 if (NULL == name) 349 if (NULL == name)
348 { 350 {
349 GNUNET_break(0); 351 GNUNET_break (0);
350 return NULL; 352 return NULL;
351 } 353 }
352 LOG(GNUNET_ERROR_TYPE_DEBUG, 354 LOG (GNUNET_ERROR_TYPE_DEBUG,
353 "Trying to lookup `%s' in GNS\n", 355 "Trying to lookup `%s' in GNS\n",
354 name); 356 name);
355 nlen = strlen(name) + 1; 357 nlen = strlen (name) + 1;
356 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*lr)) 358 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*lr))
357 { 359 {
358 GNUNET_break(0); 360 GNUNET_break (0);
359 return NULL; 361 return NULL;
360 } 362 }
361 lr = GNUNET_new(struct GNUNET_GNS_LookupRequest); 363 lr = GNUNET_new (struct GNUNET_GNS_LookupRequest);
362 lr->gns_handle = handle; 364 lr->gns_handle = handle;
363 lr->lookup_proc = proc; 365 lr->lookup_proc = proc;
364 lr->proc_cls = proc_cls; 366 lr->proc_cls = proc_cls;
365 lr->r_id = handle->r_id_gen++; 367 lr->r_id = handle->r_id_gen++;
366 lr->env = GNUNET_MQ_msg_extra(lookup_msg, 368 lr->env = GNUNET_MQ_msg_extra (lookup_msg,
367 nlen, 369 nlen,
368 GNUNET_MESSAGE_TYPE_GNS_LOOKUP); 370 GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
369 lookup_msg->id = htonl(lr->r_id); 371 lookup_msg->id = htonl (lr->r_id);
370 lookup_msg->options = htons((uint16_t)options); 372 lookup_msg->options = htons ((uint16_t) options);
371 lookup_msg->zone = *zone; 373 lookup_msg->zone = *zone;
372 lookup_msg->type = htonl(type); 374 lookup_msg->type = htonl (type);
373 GNUNET_memcpy(&lookup_msg[1], 375 GNUNET_memcpy (&lookup_msg[1],
374 name, 376 name,
375 nlen); 377 nlen);
376 GNUNET_CONTAINER_DLL_insert(handle->lookup_head, 378 GNUNET_CONTAINER_DLL_insert (handle->lookup_head,
377 handle->lookup_tail, 379 handle->lookup_tail,
378 lr); 380 lr);
379 if (NULL != handle->mq) 381 if (NULL != handle->mq)
380 GNUNET_MQ_send_copy(handle->mq, 382 GNUNET_MQ_send_copy (handle->mq,
381 lr->env); 383 lr->env);
382 return lr; 384 return lr;
383} 385}
384 386
diff --git a/src/gns/gns_api.h b/src/gns/gns_api.h
index 7e07f909f..003955bdd 100644
--- a/src/gns/gns_api.h
+++ b/src/gns/gns_api.h
@@ -32,7 +32,8 @@
32/** 32/**
33 * Connection to the GNS service. 33 * Connection to the GNS service.
34 */ 34 */
35struct GNUNET_GNS_Handle { 35struct GNUNET_GNS_Handle
36{
36 /** 37 /**
37 * Configuration to use. 38 * Configuration to use.
38 */ 39 */
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c
index 0692199e3..e646efc3e 100644
--- a/src/gns/gns_tld_api.c
+++ b/src/gns/gns_tld_api.c
@@ -35,13 +35,14 @@
35#include "gns_api.h" 35#include "gns_api.h"
36 36
37 37
38#define LOG(kind, ...) GNUNET_log_from(kind, "gns-tld-api", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "gns-tld-api", __VA_ARGS__)
39 39
40 40
41/** 41/**
42 * Handle to a lookup request 42 * Handle to a lookup request
43 */ 43 */
44struct GNUNET_GNS_LookupWithTldRequest { 44struct GNUNET_GNS_LookupWithTldRequest
45{
45 /** 46 /**
46 * handle to gns 47 * handle to gns
47 */ 48 */
@@ -103,11 +104,11 @@ struct GNUNET_GNS_LookupWithTldRequest {
103 * or @a name if @a name does not contain a "." 104 * or @a name if @a name does not contain a "."
104 */ 105 */
105static const char * 106static const char *
106get_tld(const char *name) 107get_tld (const char *name)
107{ 108{
108 const char *tld; 109 const char *tld;
109 110
110 tld = strrchr(name, (unsigned char)'.'); 111 tld = strrchr (name, (unsigned char) '.');
111 if (NULL == tld) 112 if (NULL == tld)
112 tld = name; 113 tld = name;
113 else 114 else
@@ -123,18 +124,18 @@ get_tld(const char *name)
123 * @param tld what to eat (can be more than just the tld) 124 * @param tld what to eat (can be more than just the tld)
124 */ 125 */
125static void 126static void
126eat_tld(char *name, const char *tld) 127eat_tld (char *name, const char *tld)
127{ 128{
128 GNUNET_assert(0 < strlen(name)); 129 GNUNET_assert (0 < strlen (name));
129 if ((NULL == tld) || (strlen(name) == strlen(tld))) 130 if ((NULL == tld) || (strlen (name) == strlen (tld)))
130 { 131 {
131 strcpy(name, GNUNET_GNS_EMPTY_LABEL_AT); 132 strcpy (name, GNUNET_GNS_EMPTY_LABEL_AT);
132 } 133 }
133 else 134 else
134 { 135 {
135 GNUNET_assert(strlen(tld) < strlen(name)); 136 GNUNET_assert (strlen (tld) < strlen (name));
136 name[strlen(name) - strlen(tld) - 1] = '\0'; 137 name[strlen (name) - strlen (tld) - 1] = '\0';
137 } 138 }
138} 139}
139 140
140 141
@@ -146,15 +147,15 @@ eat_tld(char *name, const char *tld)
146 * @param rd array of @a rd_count records with the results 147 * @param rd array of @a rd_count records with the results
147 */ 148 */
148static void 149static void
149process_lookup_result(void *cls, 150process_lookup_result (void *cls,
150 uint32_t rd_count, 151 uint32_t rd_count,
151 const struct GNUNET_GNSRECORD_Data *rd) 152 const struct GNUNET_GNSRECORD_Data *rd)
152{ 153{
153 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; 154 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
154 155
155 ltr->lr = NULL; 156 ltr->lr = NULL;
156 ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd); 157 ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd);
157 GNUNET_GNS_lookup_with_tld_cancel(ltr); 158 GNUNET_GNS_lookup_with_tld_cancel (ltr);
158} 159}
159 160
160 161
@@ -165,16 +166,16 @@ process_lookup_result(void *cls,
165 * @param pkey public key to use for the zone, can be NULL 166 * @param pkey public key to use for the zone, can be NULL
166 */ 167 */
167static void 168static void
168lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr, 169lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr,
169 const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) 170 const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
170{ 171{
171 ltr->lr = GNUNET_GNS_lookup(ltr->gns_handle, 172 ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle,
172 ltr->name, 173 ltr->name,
173 pkey, 174 pkey,
174 ltr->type, 175 ltr->type,
175 ltr->options, 176 ltr->options,
176 &process_lookup_result, 177 &process_lookup_result,
177 ltr); 178 ltr);
178} 179}
179 180
180 181
@@ -188,38 +189,38 @@ lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr,
188 * @param name name of the ego 189 * @param name name of the ego
189 */ 190 */
190static void 191static void
191identity_zone_cb(void *cls, 192identity_zone_cb (void *cls,
192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 193 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
193 const char *ego_name) 194 const char *ego_name)
194{ 195{
195 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; 196 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
196 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 197 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
197 198
198 ltr->id_co = NULL; 199 ltr->id_co = NULL;
199 if (NULL == priv) 200 if (NULL == priv)
200 { 201 {
201 /* no matching ego found */ 202 /* no matching ego found */
202 ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); 203 ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL);
203 return; 204 return;
204 } 205 }
205 /* Final case: TLD matches one of our egos */ 206 /* Final case: TLD matches one of our egos */
206 if (0 == strcmp(ltr->name, ego_name)) 207 if (0 == strcmp (ltr->name, ego_name))
207 { 208 {
208 /* name matches ego name perfectly, only "@" remains */ 209 /* name matches ego name perfectly, only "@" remains */
209 strcpy(ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); 210 strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT);
210 } 211 }
211 else 212 else
212 { 213 {
213 GNUNET_assert(strlen(ego_name) < strlen(ltr->name)); 214 GNUNET_assert (strlen (ego_name) < strlen (ltr->name));
214 ltr->name[strlen(ltr->name) - strlen(ego_name) - 1] = '\0'; 215 ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0';
215 } 216 }
216 /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ 217 /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */
217 if (NULL == strchr(ltr->name, (unsigned char)'.')) 218 if (NULL == strchr (ltr->name, (unsigned char) '.'))
218 ltr->options = GNUNET_GNS_LO_NO_DHT; 219 ltr->options = GNUNET_GNS_LO_NO_DHT;
219 else 220 else
220 ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; 221 ltr->options = GNUNET_GNS_LO_LOCAL_MASTER;
221 GNUNET_CRYPTO_ecdsa_key_get_public(priv, &pkey); 222 GNUNET_CRYPTO_ecdsa_key_get_public (priv, &pkey);
222 lookup_with_public_key(ltr, &pkey); 223 lookup_with_public_key (ltr, &pkey);
223} 224}
224 225
225 226
@@ -237,12 +238,12 @@ identity_zone_cb(void *cls,
237 * @return handle to the get request, NULL on error (i.e. bad configuration) 238 * @return handle to the get request, NULL on error (i.e. bad configuration)
238 */ 239 */
239struct GNUNET_GNS_LookupWithTldRequest * 240struct GNUNET_GNS_LookupWithTldRequest *
240GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, 241GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
241 const char *name, 242 const char *name,
242 uint32_t type, 243 uint32_t type,
243 enum GNUNET_GNS_LocalOptions options, 244 enum GNUNET_GNS_LocalOptions options,
244 GNUNET_GNS_LookupResultProcessor2 proc, 245 GNUNET_GNS_LookupResultProcessor2 proc,
245 void *proc_cls) 246 void *proc_cls)
246{ 247{
247 struct GNUNET_GNS_LookupWithTldRequest *ltr; 248 struct GNUNET_GNS_LookupWithTldRequest *ltr;
248 const char *tld; 249 const char *tld;
@@ -250,70 +251,70 @@ GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle,
250 char *zonestr; 251 char *zonestr;
251 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 252 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
252 253
253 ltr = GNUNET_new(struct GNUNET_GNS_LookupWithTldRequest); 254 ltr = GNUNET_new (struct GNUNET_GNS_LookupWithTldRequest);
254 ltr->gns_handle = handle; 255 ltr->gns_handle = handle;
255 ltr->name = GNUNET_strdup(name); 256 ltr->name = GNUNET_strdup (name);
256 ltr->type = type; 257 ltr->type = type;
257 ltr->options = options; 258 ltr->options = options;
258 ltr->lookup_proc = proc; 259 ltr->lookup_proc = proc;
259 ltr->lookup_proc_cls = proc_cls; 260 ltr->lookup_proc_cls = proc_cls;
260 /* start with trivial case: TLD is zkey */ 261 /* start with trivial case: TLD is zkey */
261 tld = get_tld(ltr->name); 262 tld = get_tld (ltr->name);
262 if (GNUNET_OK == 263 if (GNUNET_OK ==
263 GNUNET_CRYPTO_ecdsa_public_key_from_string(tld, strlen(tld), &pkey)) 264 GNUNET_CRYPTO_ecdsa_public_key_from_string (tld, strlen (tld), &pkey))
264 { 265 {
265 eat_tld(ltr->name, tld); 266 eat_tld (ltr->name, tld);
266 lookup_with_public_key(ltr, &pkey); 267 lookup_with_public_key (ltr, &pkey);
267 return ltr; 268 return ltr;
268 } 269 }
269 270
270 /* second case: domain is mapped in our configuration file */ 271 /* second case: domain is mapped in our configuration file */
271 for (const char *domain = name; NULL != domain; 272 for (const char *domain = name; NULL != domain;
272 domain = strchr(domain, (unsigned char)'.')) 273 domain = strchr (domain, (unsigned char) '.'))
274 {
275 if ('.' == domain[0])
276 domain++;
277 GNUNET_asprintf (&dot_tld, ".%s", domain);
278 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (handle->cfg,
279 "gns",
280 dot_tld,
281 &zonestr))
273 { 282 {
274 if ('.' == domain[0]) 283 if (GNUNET_OK !=
275 domain++; 284 GNUNET_CRYPTO_ecdsa_public_key_from_string (zonestr,
276 GNUNET_asprintf(&dot_tld, ".%s", domain); 285 strlen (zonestr),
277 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(handle->cfg, 286 &pkey))
278 "gns", 287 {
279 dot_tld, 288 GNUNET_log_config_invalid (
280 &zonestr)) 289 GNUNET_ERROR_TYPE_ERROR,
281 { 290 "gns",
282 if (GNUNET_OK != 291 dot_tld,
283 GNUNET_CRYPTO_ecdsa_public_key_from_string(zonestr, 292 _ ("Expected a base32-encoded public zone key\n"));
284 strlen(zonestr), 293 GNUNET_free (zonestr);
285 &pkey)) 294 GNUNET_free (dot_tld);
286 { 295 GNUNET_free (ltr->name);
287 GNUNET_log_config_invalid( 296 GNUNET_free (ltr);
288 GNUNET_ERROR_TYPE_ERROR, 297 return NULL;
289 "gns", 298 }
290 dot_tld, 299 eat_tld (ltr->name, &dot_tld[1]);
291 _("Expected a base32-encoded public zone key\n")); 300 GNUNET_free (zonestr);
292 GNUNET_free(zonestr); 301 GNUNET_free (dot_tld);
293 GNUNET_free(dot_tld); 302 lookup_with_public_key (ltr, &pkey);
294 GNUNET_free(ltr->name); 303 return ltr;
295 GNUNET_free(ltr);
296 return NULL;
297 }
298 eat_tld(ltr->name, &dot_tld[1]);
299 GNUNET_free(zonestr);
300 GNUNET_free(dot_tld);
301 lookup_with_public_key(ltr, &pkey);
302 return ltr;
303 }
304 GNUNET_free(dot_tld);
305 } 304 }
305 GNUNET_free (dot_tld);
306 }
306 ltr->id_co = 307 ltr->id_co =
307 GNUNET_IDENTITY_ego_lookup_by_suffix(ltr->gns_handle->cfg, 308 GNUNET_IDENTITY_ego_lookup_by_suffix (ltr->gns_handle->cfg,
308 ltr->name, 309 ltr->name,
309 &identity_zone_cb, 310 &identity_zone_cb,
310 ltr); 311 ltr);
311 if (NULL == ltr->id_co) 312 if (NULL == ltr->id_co)
312 { 313 {
313 GNUNET_free(ltr->name); 314 GNUNET_free (ltr->name);
314 GNUNET_free(ltr); 315 GNUNET_free (ltr);
315 return NULL; 316 return NULL;
316 } 317 }
317 return ltr; 318 return ltr;
318} 319}
319 320
@@ -325,23 +326,23 @@ GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle,
325 * @return closure from the lookup result processor 326 * @return closure from the lookup result processor
326 */ 327 */
327void * 328void *
328GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr) 329GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr)
329{ 330{
330 void *ret = ltr->lookup_proc_cls; 331 void *ret = ltr->lookup_proc_cls;
331 332
332 if (NULL != ltr->id_co) 333 if (NULL != ltr->id_co)
333 { 334 {
334 GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(ltr->id_co); 335 GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (ltr->id_co);
335 ltr->id_co = NULL; 336 ltr->id_co = NULL;
336 } 337 }
337 if (NULL != ltr->lr) 338 if (NULL != ltr->lr)
338 { 339 {
339 GNUNET_GNS_lookup_cancel(ltr->lr); 340 GNUNET_GNS_lookup_cancel (ltr->lr);
340 ltr->lr = NULL; 341 ltr->lr = NULL;
341 } 342 }
342 GNUNET_free_non_null(ltr->longest_match); 343 GNUNET_free_non_null (ltr->longest_match);
343 GNUNET_free(ltr->name); 344 GNUNET_free (ltr->name);
344 GNUNET_free(ltr); 345 GNUNET_free (ltr);
345 return ret; 346 return ret;
346} 347}
347 348
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index c34372b17..d6de86fa0 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -81,7 +81,8 @@ static char *resfile;
81static uint16_t port = 8888; 81static uint16_t port = 8888;
82 82
83 83
84struct Entry { 84struct Entry
85{
85 const char *formname; 86 const char *formname;
86 const char *texname; 87 const char *texname;
87}; 88};
@@ -91,14 +92,14 @@ struct Entry {
91 * Main request handler. 92 * Main request handler.
92 */ 93 */
93static int 94static int
94access_handler_callback(void *cls, 95access_handler_callback (void *cls,
95 struct MHD_Connection *connection, 96 struct MHD_Connection *connection,
96 const char *url, 97 const char *url,
97 const char *method, 98 const char *method,
98 const char *version, 99 const char *version,
99 const char *upload_data, 100 const char *upload_data,
100 size_t *upload_data_size, 101 size_t *upload_data_size,
101 void **con_cls) 102 void **con_cls)
102{ 103{
103 static int dummy; 104 static int dummy;
104 static const struct Entry map[] = { { "prefix", "prefix" }, 105 static const struct Entry map[] = { { "prefix", "prefix" },
@@ -113,153 +114,154 @@ access_handler_callback(void *cls,
113 { "orga", "orga" }, 114 { "orga", "orga" },
114 { "departmenti18n", "departmentde" }, 115 { "departmenti18n", "departmentde" },
115 { "departmenten", "departmenten" }, 116 { "departmenten", "departmenten" },
116 { "subdepartmenti18n", "subdepartmentde" }, 117 { "subdepartmenti18n",
118 "subdepartmentde" },
117 { "subdepartmenten", "subdepartmenten" }, 119 { "subdepartmenten", "subdepartmenten" },
118 { "jobtitlei18n", "jobtitlegerman" }, 120 { "jobtitlei18n", "jobtitlegerman" },
119 { "jobtitleen", "jobtitleenglish" }, 121 { "jobtitleen", "jobtitleenglish" },
120 { "subdepartmenten", "subdepartmenten" }, 122 { "subdepartmenten", "subdepartmenten" },
121 { NULL, NULL } }; 123 { NULL, NULL } };
122 124
123 (void)cls; 125 (void) cls;
124 (void)version; 126 (void) version;
125 (void)upload_data; 127 (void) upload_data;
126 (void)upload_data_size; 128 (void) upload_data_size;
127 if (0 != strcmp(method, MHD_HTTP_METHOD_GET)) 129 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
132 _ ("Refusing `%s' request to HTTP server\n"),
133 method);
134 return MHD_NO;
135 }
136 if (NULL == *con_cls)
137 {
138 (*con_cls) = &dummy;
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n");
140 return MHD_YES; /* send 100 continue */
141 }
142 if (0 == strcasecmp (url, "/"))
143 return MHD_queue_response (connection, MHD_HTTP_OK, main_response);
144 if (0 == strcasecmp (url, "/submit.pdf"))
145 {
146 unsigned int i;
147 char *p;
148 char *tmp;
149 char *deffile;
150 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
151 size_t slen;
152 FILE *f;
153 struct stat st;
154 struct MHD_Response *response;
155 int fd;
156 int ret;
157
158 const char *gpg_fp = MHD_lookup_connection_value (connection,
159 MHD_GET_ARGUMENT_KIND,
160 "gpgfingerprint");
161 const char *gns_nick = MHD_lookup_connection_value (connection,
162 MHD_GET_ARGUMENT_KIND,
163 "gnsnick");
164 const char *gnskey =
165 MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "gnskey");
166 if ((NULL == gnskey) ||
167 (GNUNET_OK !=
168 GNUNET_CRYPTO_ecdsa_public_key_from_string (gnskey,
169 strlen (gnskey),
170 &pub)))
128 { 171 {
129 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 172 return MHD_queue_response (connection,
130 _("Refusing `%s' request to HTTP server\n"), 173 MHD_HTTP_OK,
131 method); 174 invalid_gnskey_response);
175 }
176 tmp = GNUNET_DISK_mkdtemp (gnskey);
177 if (NULL == tmp)
178 {
179 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mktemp", gnskey);
132 return MHD_NO; 180 return MHD_NO;
133 } 181 }
134 if (NULL == *con_cls) 182 GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex");
183 f = fopen (deffile, "w");
184 if (NULL == f)
135 { 185 {
136 (*con_cls) = &dummy; 186 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile);
137 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n"); 187 GNUNET_free (deffile);
138 return MHD_YES; /* send 100 continue */ 188 GNUNET_DISK_directory_remove (tmp);
189 GNUNET_free (tmp);
190 return MHD_NO;
139 } 191 }
140 if (0 == strcasecmp(url, "/")) 192 for (i = 0; NULL != map[i].formname; i++)
141 return MHD_queue_response(connection, MHD_HTTP_OK, main_response);
142 if (0 == strcasecmp(url, "/submit.pdf"))
143 { 193 {
144 unsigned int i; 194 const char *val = MHD_lookup_connection_value (connection,
145 char *p; 195 MHD_GET_ARGUMENT_KIND,
146 char *tmp; 196 map[i].formname);
147 char *deffile; 197 if (NULL != val)
148 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 198 fprintf (f, "\\def\\%s{%s}\n", map[i].texname, val);
149 size_t slen; 199 else
150 FILE *f; 200 fprintf (f, "\\def\\%s{}\n", map[i].texname);
151 struct stat st; 201 }
152 struct MHD_Response *response; 202 if (NULL != gpg_fp)
153 int fd; 203 {
154 int ret; 204 char *gpg1;
155 205 char *gpg2;
156 const char *gpg_fp = MHD_lookup_connection_value(connection, 206
157 MHD_GET_ARGUMENT_KIND, 207 slen = strlen (gpg_fp);
158 "gpgfingerprint"); 208 gpg1 = GNUNET_strndup (gpg_fp, slen / 2);
159 const char *gns_nick = MHD_lookup_connection_value(connection, 209 gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]);
160 MHD_GET_ARGUMENT_KIND, 210 fprintf (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
161 "gnsnick"); 211 GNUNET_free (gpg2);
162 const char *gnskey = 212 GNUNET_free (gpg1);
163 MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "gnskey"); 213 }
164 if ((NULL == gnskey) || 214 fprintf (f,
165 (GNUNET_OK != 215 "\\def\\gns{%s/%s}\n",
166 GNUNET_CRYPTO_ecdsa_public_key_from_string(gnskey, 216 gnskey,
167 strlen(gnskey), 217 (NULL == gns_nick) ? "" : gns_nick);
168 &pub))) 218 fclose (f);
169 { 219 GNUNET_asprintf (
170 return MHD_queue_response(connection, 220 &p,
171 MHD_HTTP_OK, 221 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
172 invalid_gnskey_response); 222 tmp,
173 } 223 resfile);
174 tmp = GNUNET_DISK_mkdtemp(gnskey); 224 GNUNET_free (deffile);
175 if (NULL == tmp) 225 ret = system (p);
176 { 226 if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret)))
177 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mktemp", gnskey); 227 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "system", p);
178 return MHD_NO; 228 GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "gns-bcd.pdf");
179 } 229 fd = open (deffile, O_RDONLY);
180 GNUNET_asprintf(&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex"); 230 if (-1 == fd)
181 f = fopen(deffile, "w"); 231 {
182 if (NULL == f) 232 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile);
183 { 233 GNUNET_free (deffile);
184 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", deffile); 234 GNUNET_free (p);
185 GNUNET_free(deffile); 235 GNUNET_DISK_directory_remove (tmp);
186 GNUNET_DISK_directory_remove(tmp); 236 GNUNET_free (tmp);
187 GNUNET_free(tmp); 237 return MHD_NO;
188 return MHD_NO; 238 }
189 } 239 GNUNET_break (0 == stat (deffile, &st));
190 for (i = 0; NULL != map[i].formname; i++) 240 if (NULL ==
191 { 241 (response = MHD_create_response_from_fd ((size_t) st.st_size, fd)))
192 const char *val = MHD_lookup_connection_value(connection, 242 {
193 MHD_GET_ARGUMENT_KIND, 243 GNUNET_break (0);
194 map[i].formname); 244 GNUNET_break (0 == close (fd));
195 if (NULL != val) 245 GNUNET_free (deffile);
196 fprintf(f, "\\def\\%s{%s}\n", map[i].texname, val); 246 GNUNET_free (p);
197 else 247 GNUNET_DISK_directory_remove (tmp);
198 fprintf(f, "\\def\\%s{}\n", map[i].texname); 248 GNUNET_free (tmp);
199 } 249 return MHD_NO;
200 if (NULL != gpg_fp) 250 }
201 { 251 (void) MHD_add_response_header (response,
202 char *gpg1;
203 char *gpg2;
204
205 slen = strlen(gpg_fp);
206 gpg1 = GNUNET_strndup(gpg_fp, slen / 2);
207 gpg2 = GNUNET_strdup(&gpg_fp[slen / 2]);
208 fprintf(f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
209 GNUNET_free(gpg2);
210 GNUNET_free(gpg1);
211 }
212 fprintf(f,
213 "\\def\\gns{%s/%s}\n",
214 gnskey,
215 (NULL == gns_nick) ? "" : gns_nick);
216 fclose(f);
217 GNUNET_asprintf(
218 &p,
219 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
220 tmp,
221 resfile);
222 GNUNET_free(deffile);
223 ret = system(p);
224 if (WIFSIGNALED(ret) || (0 != WEXITSTATUS(ret)))
225 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "system", p);
226 GNUNET_asprintf(&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "gns-bcd.pdf");
227 fd = open(deffile, O_RDONLY);
228 if (-1 == fd)
229 {
230 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", deffile);
231 GNUNET_free(deffile);
232 GNUNET_free(p);
233 GNUNET_DISK_directory_remove(tmp);
234 GNUNET_free(tmp);
235 return MHD_NO;
236 }
237 GNUNET_break(0 == stat(deffile, &st));
238 if (NULL ==
239 (response = MHD_create_response_from_fd((size_t)st.st_size, fd)))
240 {
241 GNUNET_break(0);
242 GNUNET_break(0 == close(fd));
243 GNUNET_free(deffile);
244 GNUNET_free(p);
245 GNUNET_DISK_directory_remove(tmp);
246 GNUNET_free(tmp);
247 return MHD_NO;
248 }
249 (void)MHD_add_response_header(response,
250 MHD_HTTP_HEADER_CONTENT_TYPE, 252 MHD_HTTP_HEADER_CONTENT_TYPE,
251 "application/pdf"); 253 "application/pdf");
252 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 254 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
253 MHD_destroy_response(response); 255 MHD_destroy_response (response);
254 GNUNET_free(deffile); 256 GNUNET_free (deffile);
255 GNUNET_free(p); 257 GNUNET_free (p);
256 GNUNET_DISK_directory_remove(tmp); 258 GNUNET_DISK_directory_remove (tmp);
257 GNUNET_free(tmp); 259 GNUNET_free (tmp);
258 return ret; 260 return ret;
259 } 261 }
260 return MHD_queue_response(connection, 262 return MHD_queue_response (connection,
261 MHD_HTTP_NOT_FOUND, 263 MHD_HTTP_NOT_FOUND,
262 not_found_response); 264 not_found_response);
263} 265}
264 266
265 267
@@ -268,7 +270,7 @@ access_handler_callback(void *cls,
268 * starts the task waiting for them. 270 * starts the task waiting for them.
269 */ 271 */
270static struct GNUNET_SCHEDULER_Task * 272static struct GNUNET_SCHEDULER_Task *
271prepare_daemon(struct MHD_Daemon *daemon_handle); 273prepare_daemon (struct MHD_Daemon *daemon_handle);
272 274
273 275
274/** 276/**
@@ -276,13 +278,13 @@ prepare_daemon(struct MHD_Daemon *daemon_handle);
276 * and schedule the next run. 278 * and schedule the next run.
277 */ 279 */
278static void 280static void
279run_daemon(void *cls) 281run_daemon (void *cls)
280{ 282{
281 struct MHD_Daemon *daemon_handle = cls; 283 struct MHD_Daemon *daemon_handle = cls;
282 284
283 http_task = NULL; 285 http_task = NULL;
284 GNUNET_assert(MHD_YES == MHD_run(daemon_handle)); 286 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
285 http_task = prepare_daemon(daemon_handle); 287 http_task = prepare_daemon (daemon_handle);
286} 288}
287 289
288 290
@@ -291,7 +293,7 @@ run_daemon(void *cls)
291 * starts the task waiting for them. 293 * starts the task waiting for them.
292 */ 294 */
293static struct GNUNET_SCHEDULER_Task * 295static struct GNUNET_SCHEDULER_Task *
294prepare_daemon(struct MHD_Daemon *daemon_handle) 296prepare_daemon (struct MHD_Daemon *daemon_handle)
295{ 297{
296 struct GNUNET_SCHEDULER_Task *ret; 298 struct GNUNET_SCHEDULER_Task *ret;
297 fd_set rs; 299 fd_set rs;
@@ -304,28 +306,28 @@ prepare_daemon(struct MHD_Daemon *daemon_handle)
304 int haveto; 306 int haveto;
305 struct GNUNET_TIME_Relative tv; 307 struct GNUNET_TIME_Relative tv;
306 308
307 FD_ZERO(&rs); 309 FD_ZERO (&rs);
308 FD_ZERO(&ws); 310 FD_ZERO (&ws);
309 FD_ZERO(&es); 311 FD_ZERO (&es);
310 wrs = GNUNET_NETWORK_fdset_create(); 312 wrs = GNUNET_NETWORK_fdset_create ();
311 wws = GNUNET_NETWORK_fdset_create(); 313 wws = GNUNET_NETWORK_fdset_create ();
312 max = -1; 314 max = -1;
313 GNUNET_assert(MHD_YES == MHD_get_fdset(daemon_handle, &rs, &ws, &es, &max)); 315 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
314 haveto = MHD_get_timeout(daemon_handle, &timeout); 316 haveto = MHD_get_timeout (daemon_handle, &timeout);
315 if (haveto == MHD_YES) 317 if (haveto == MHD_YES)
316 tv.rel_value_us = (uint64_t)timeout * 1000LL; 318 tv.rel_value_us = (uint64_t) timeout * 1000LL;
317 else 319 else
318 tv = GNUNET_TIME_UNIT_FOREVER_REL; 320 tv = GNUNET_TIME_UNIT_FOREVER_REL;
319 GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); 321 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
320 GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); 322 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
321 ret = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, 323 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
322 tv, 324 tv,
323 wrs, 325 wrs,
324 wws, 326 wws,
325 &run_daemon, 327 &run_daemon,
326 daemon_handle); 328 daemon_handle);
327 GNUNET_NETWORK_fdset_destroy(wrs); 329 GNUNET_NETWORK_fdset_destroy (wrs);
328 GNUNET_NETWORK_fdset_destroy(wws); 330 GNUNET_NETWORK_fdset_destroy (wws);
329 return ret; 331 return ret;
330} 332}
331 333
@@ -336,41 +338,41 @@ prepare_daemon(struct MHD_Daemon *daemon_handle)
336 * @return #GNUNET_OK on success 338 * @return #GNUNET_OK on success
337 */ 339 */
338static int 340static int
339server_start() 341server_start ()
340{ 342{
341 if (0 == port) 343 if (0 == port)
342 { 344 {
343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
344 _("Invalid port number %u. Exiting.\n"), 346 _ ("Invalid port number %u. Exiting.\n"),
345 port); 347 port);
346 return GNUNET_SYSERR; 348 return GNUNET_SYSERR;
347 } 349 }
348 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 350 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 _("Businesscard HTTP server starts on %u\n"), 351 _ ("Businesscard HTTP server starts on %u\n"),
350 port); 352 port);
351 daemon_handle = MHD_start_daemon(MHD_USE_DUAL_STACK | MHD_USE_DEBUG, 353 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG,
352 port, 354 port,
353 NULL /* accept_policy_callback */, 355 NULL /* accept_policy_callback */,
354 NULL, 356 NULL,
355 &access_handler_callback, 357 &access_handler_callback,
356 NULL, 358 NULL,
357 MHD_OPTION_CONNECTION_LIMIT, 359 MHD_OPTION_CONNECTION_LIMIT,
358 (unsigned int)512, 360 (unsigned int) 512,
359 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 361 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
360 (unsigned int)2, 362 (unsigned int) 2,
361 MHD_OPTION_CONNECTION_TIMEOUT, 363 MHD_OPTION_CONNECTION_TIMEOUT,
362 (unsigned int)60, 364 (unsigned int) 60,
363 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 365 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
364 (size_t)(16 * 1024), 366 (size_t) (16 * 1024),
365 MHD_OPTION_END); 367 MHD_OPTION_END);
366 if (NULL == daemon_handle) 368 if (NULL == daemon_handle)
367 { 369 {
368 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 370 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
369 _("Could not start businesscard HTTP server on port %u\n"), 371 _ ("Could not start businesscard HTTP server on port %u\n"),
370 (unsigned int)port); 372 (unsigned int) port);
371 return GNUNET_SYSERR; 373 return GNUNET_SYSERR;
372 } 374 }
373 http_task = prepare_daemon(daemon_handle); 375 http_task = prepare_daemon (daemon_handle);
374 return GNUNET_OK; 376 return GNUNET_OK;
375} 377}
376 378
@@ -379,40 +381,40 @@ server_start()
379 * Stop HTTP server. 381 * Stop HTTP server.
380 */ 382 */
381static void 383static void
382server_stop(void *cls) 384server_stop (void *cls)
383{ 385{
384 (void)cls; 386 (void) cls;
385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n"); 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n");
386 if (NULL != http_task) 388 if (NULL != http_task)
387 { 389 {
388 GNUNET_SCHEDULER_cancel(http_task); 390 GNUNET_SCHEDULER_cancel (http_task);
389 http_task = NULL; 391 http_task = NULL;
390 } 392 }
391 if (NULL != daemon_handle) 393 if (NULL != daemon_handle)
392 { 394 {
393 MHD_stop_daemon(daemon_handle); 395 MHD_stop_daemon (daemon_handle);
394 daemon_handle = NULL; 396 daemon_handle = NULL;
395 } 397 }
396 if (NULL != main_response) 398 if (NULL != main_response)
397 { 399 {
398 MHD_destroy_response(main_response); 400 MHD_destroy_response (main_response);
399 main_response = NULL; 401 main_response = NULL;
400 } 402 }
401 if (NULL != invalid_gnskey_response) 403 if (NULL != invalid_gnskey_response)
402 { 404 {
403 MHD_destroy_response(invalid_gnskey_response); 405 MHD_destroy_response (invalid_gnskey_response);
404 invalid_gnskey_response = NULL; 406 invalid_gnskey_response = NULL;
405 } 407 }
406 if (NULL != not_found_response) 408 if (NULL != not_found_response)
407 { 409 {
408 MHD_destroy_response(not_found_response); 410 MHD_destroy_response (not_found_response);
409 not_found_response = NULL; 411 not_found_response = NULL;
410 } 412 }
411 if (NULL != resfile) 413 if (NULL != resfile)
412 { 414 {
413 GNUNET_free(resfile); 415 GNUNET_free (resfile);
414 resfile = NULL; 416 resfile = NULL;
415 } 417 }
416} 418}
417 419
418 420
@@ -425,66 +427,66 @@ server_stop(void *cls)
425 * @param c configuration 427 * @param c configuration
426 */ 428 */
427static void 429static void
428run(void *cls, 430run (void *cls,
429 char *const *args, 431 char *const *args,
430 const char *cfgfile, 432 const char *cfgfile,
431 const struct GNUNET_CONFIGURATION_Handle *c) 433 const struct GNUNET_CONFIGURATION_Handle *c)
432{ 434{
433 struct stat st; 435 struct stat st;
434 char *dir; 436 char *dir;
435 char *fn; 437 char *fn;
436 int fd; 438 int fd;
437 439
438 (void)cls; 440 (void) cls;
439 (void)args; 441 (void) args;
440 (void)cfgfile; 442 (void) cfgfile;
441 cfg = c; 443 cfg = c;
442 dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); 444 dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
443 GNUNET_assert(NULL != dir); 445 GNUNET_assert (NULL != dir);
444 GNUNET_asprintf(&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html"); 446 GNUNET_asprintf (&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html");
445 GNUNET_asprintf(&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex"); 447 GNUNET_asprintf (&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex");
446 GNUNET_free(dir); 448 GNUNET_free (dir);
447 fd = open(fn, O_RDONLY); 449 fd = open (fn, O_RDONLY);
448 if (-1 == fd) 450 if (-1 == fd)
449 { 451 {
450 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); 452 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
451 GNUNET_free(fn); 453 GNUNET_free (fn);
452 return; 454 return;
453 } 455 }
454 if (0 != stat(fn, &st)) 456 if (0 != stat (fn, &st))
455 { 457 {
456 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); 458 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
457 GNUNET_free(fn); 459 GNUNET_free (fn);
458 GNUNET_break(0 == close(fd)); 460 GNUNET_break (0 == close (fd));
459 return; 461 return;
460 } 462 }
461 GNUNET_free(fn); 463 GNUNET_free (fn);
462 if (NULL == 464 if (NULL ==
463 (main_response = MHD_create_response_from_fd((size_t)st.st_size, fd))) 465 (main_response = MHD_create_response_from_fd ((size_t) st.st_size, fd)))
464 { 466 {
465 GNUNET_break(0); 467 GNUNET_break (0);
466 GNUNET_break(0 == close(fd)); 468 GNUNET_break (0 == close (fd));
467 return; 469 return;
468 } 470 }
469 (void)MHD_add_response_header(main_response, 471 (void) MHD_add_response_header (main_response,
470 MHD_HTTP_HEADER_CONTENT_TYPE, 472 MHD_HTTP_HEADER_CONTENT_TYPE,
471 "text/html"); 473 "text/html");
472 invalid_gnskey_response = 474 invalid_gnskey_response =
473 MHD_create_response_from_buffer(strlen(INVALID_GNSKEY), 475 MHD_create_response_from_buffer (strlen (INVALID_GNSKEY),
474 INVALID_GNSKEY, 476 INVALID_GNSKEY,
475 MHD_RESPMEM_PERSISTENT); 477 MHD_RESPMEM_PERSISTENT);
476 (void)MHD_add_response_header(invalid_gnskey_response, 478 (void) MHD_add_response_header (invalid_gnskey_response,
477 MHD_HTTP_HEADER_CONTENT_TYPE, 479 MHD_HTTP_HEADER_CONTENT_TYPE,
478 "text/html"); 480 "text/html");
479 not_found_response = MHD_create_response_from_buffer(strlen(NOT_FOUND), 481 not_found_response = MHD_create_response_from_buffer (strlen (NOT_FOUND),
480 NOT_FOUND, 482 NOT_FOUND,
481 MHD_RESPMEM_PERSISTENT); 483 MHD_RESPMEM_PERSISTENT);
482 (void)MHD_add_response_header(not_found_response, 484 (void) MHD_add_response_header (not_found_response,
483 MHD_HTTP_HEADER_CONTENT_TYPE, 485 MHD_HTTP_HEADER_CONTENT_TYPE,
484 "text/html"); 486 "text/html");
485 if (GNUNET_OK != server_start()) 487 if (GNUNET_OK != server_start ())
486 return; 488 return;
487 GNUNET_SCHEDULER_add_shutdown(&server_stop, NULL); 489 GNUNET_SCHEDULER_add_shutdown (&server_stop, NULL);
488} 490}
489 491
490 492
@@ -496,33 +498,33 @@ run(void *cls,
496 * @return 0 ok, 1 on error 498 * @return 0 ok, 1 on error
497 */ 499 */
498int 500int
499main(int argc, char *const *argv) 501main (int argc, char *const *argv)
500{ 502{
501 struct GNUNET_GETOPT_CommandLineOption options[] = { 503 struct GNUNET_GETOPT_CommandLineOption options[] = {
502 GNUNET_GETOPT_option_uint16('p', 504 GNUNET_GETOPT_option_uint16 ('p',
503 "port", 505 "port",
504 "PORT", 506 "PORT",
505 gettext_noop( 507 gettext_noop (
506 "Run HTTP serve on port PORT (default is 8888)"), 508 "Run HTTP serve on port PORT (default is 8888)"),
507 &port), 509 &port),
508 GNUNET_GETOPT_OPTION_END 510 GNUNET_GETOPT_OPTION_END
509 }; 511 };
510 int ret; 512 int ret;
511 513
512 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 514 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
513 return 2; 515 return 2;
514 GNUNET_log_setup("gnunet-bcd", "WARNING", NULL); 516 GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL);
515 ret = (GNUNET_OK == 517 ret = (GNUNET_OK ==
516 GNUNET_PROGRAM_run(argc, 518 GNUNET_PROGRAM_run (argc,
517 argv, 519 argv,
518 "gnunet-bcd", 520 "gnunet-bcd",
519 _("GNUnet HTTP server to create business cards"), 521 _ ("GNUnet HTTP server to create business cards"),
520 options, 522 options,
521 &run, 523 &run,
522 NULL)) 524 NULL))
523 ? 0 525 ? 0
524 : 1; 526 : 1;
525 GNUNET_free((void *)argv); 527 GNUNET_free ((void *) argv);
526 return ret; 528 return ret;
527} 529}
528 530
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 4058aba99..a1ae888dd 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -37,7 +37,8 @@
37/** 37/**
38 * Data kept per request. 38 * Data kept per request.
39 */ 39 */
40struct Request { 40struct Request
41{
41 /** 42 /**
42 * Socket to use for sending the reply. 43 * Socket to use for sending the reply.
43 */ 44 */
@@ -155,39 +156,39 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
155 * @param cls unused 156 * @param cls unused
156 */ 157 */
157static void 158static void
158do_shutdown(void *cls) 159do_shutdown (void *cls)
159{ 160{
160 (void)cls; 161 (void) cls;
161 if (NULL != t4) 162 if (NULL != t4)
162 { 163 {
163 GNUNET_SCHEDULER_cancel(t4); 164 GNUNET_SCHEDULER_cancel (t4);
164 t4 = NULL; 165 t4 = NULL;
165 } 166 }
166 if (NULL != t6) 167 if (NULL != t6)
167 { 168 {
168 GNUNET_SCHEDULER_cancel(t6); 169 GNUNET_SCHEDULER_cancel (t6);
169 t6 = NULL; 170 t6 = NULL;
170 } 171 }
171 if (NULL != listen_socket4) 172 if (NULL != listen_socket4)
172 { 173 {
173 GNUNET_NETWORK_socket_close(listen_socket4); 174 GNUNET_NETWORK_socket_close (listen_socket4);
174 listen_socket4 = NULL; 175 listen_socket4 = NULL;
175 } 176 }
176 if (NULL != listen_socket6) 177 if (NULL != listen_socket6)
177 { 178 {
178 GNUNET_NETWORK_socket_close(listen_socket6); 179 GNUNET_NETWORK_socket_close (listen_socket6);
179 listen_socket6 = NULL; 180 listen_socket6 = NULL;
180 } 181 }
181 if (NULL != gns) 182 if (NULL != gns)
182 { 183 {
183 GNUNET_GNS_disconnect(gns); 184 GNUNET_GNS_disconnect (gns);
184 gns = NULL; 185 gns = NULL;
185 } 186 }
186 if (NULL != dns_stub) 187 if (NULL != dns_stub)
187 { 188 {
188 GNUNET_DNSSTUB_stop(dns_stub); 189 GNUNET_DNSSTUB_stop (dns_stub);
189 dns_stub = NULL; 190 dns_stub = NULL;
190 } 191 }
191} 192}
192 193
193 194
@@ -197,38 +198,38 @@ do_shutdown(void *cls)
197 * @param request context for the request. 198 * @param request context for the request.
198 */ 199 */
199static void 200static void
200send_response(struct Request *request) 201send_response (struct Request *request)
201{ 202{
202 char *buf; 203 char *buf;
203 size_t size; 204 size_t size;
204 ssize_t sret; 205 ssize_t sret;
205 206
206 if (GNUNET_SYSERR == 207 if (GNUNET_SYSERR ==
207 GNUNET_DNSPARSER_pack(request->packet, 208 GNUNET_DNSPARSER_pack (request->packet,
208 UINT16_MAX /* is this not too much? */, 209 UINT16_MAX /* is this not too much? */,
209 &buf, 210 &buf,
210 &size)) 211 &size))
211 { 212 {
212 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 213 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
213 _("Failed to pack DNS response into UDP packet!\n")); 214 _ ("Failed to pack DNS response into UDP packet!\n"));
214 } 215 }
215 else 216 else
216 { 217 {
217 sret = GNUNET_NETWORK_socket_sendto(request->lsock, 218 sret = GNUNET_NETWORK_socket_sendto (request->lsock,
218 buf, 219 buf,
219 size, 220 size,
220 request->addr, 221 request->addr,
221 request->addr_len); 222 request->addr_len);
222 if ((sret < 0) || 223 if ((sret < 0) ||
223 (size != (size_t)sret)) 224 (size != (size_t) sret))
224 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, 225 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
225 "sendto"); 226 "sendto");
226 GNUNET_free(buf); 227 GNUNET_free (buf);
227 } 228 }
228 GNUNET_SCHEDULER_cancel(request->timeout_task); 229 GNUNET_SCHEDULER_cancel (request->timeout_task);
229 GNUNET_DNSPARSER_free_packet(request->packet); 230 GNUNET_DNSPARSER_free_packet (request->packet);
230 GNUNET_free(request->udp_msg); 231 GNUNET_free (request->udp_msg);
231 GNUNET_free(request); 232 GNUNET_free (request);
232} 233}
233 234
234 235
@@ -238,18 +239,18 @@ send_response(struct Request *request)
238 * @param cls `struct Request *` of the request to clean up 239 * @param cls `struct Request *` of the request to clean up
239 */ 240 */
240static void 241static void
241do_timeout(void *cls) 242do_timeout (void *cls)
242{ 243{
243 struct Request *request = cls; 244 struct Request *request = cls;
244 245
245 if (NULL != request->packet) 246 if (NULL != request->packet)
246 GNUNET_DNSPARSER_free_packet(request->packet); 247 GNUNET_DNSPARSER_free_packet (request->packet);
247 if (NULL != request->lookup) 248 if (NULL != request->lookup)
248 GNUNET_GNS_lookup_with_tld_cancel(request->lookup); 249 GNUNET_GNS_lookup_with_tld_cancel (request->lookup);
249 if (NULL != request->dns_lookup) 250 if (NULL != request->dns_lookup)
250 GNUNET_DNSSTUB_resolve_cancel(request->dns_lookup); 251 GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup);
251 GNUNET_free(request->udp_msg); 252 GNUNET_free (request->udp_msg);
252 GNUNET_free(request); 253 GNUNET_free (request);
253} 254}
254 255
255 256
@@ -261,28 +262,28 @@ do_timeout(void *cls)
261 * @param r size of the DNS payload 262 * @param r size of the DNS payload
262 */ 263 */
263static void 264static void
264dns_result_processor(void *cls, 265dns_result_processor (void *cls,
265 const struct GNUNET_TUN_DnsHeader *dns, 266 const struct GNUNET_TUN_DnsHeader *dns,
266 size_t r) 267 size_t r)
267{ 268{
268 struct Request *request = cls; 269 struct Request *request = cls;
269 270
270 if (NULL == dns) 271 if (NULL == dns)
271 { 272 {
272 /* DNSSTUB gave up, so we trigger timeout early */ 273 /* DNSSTUB gave up, so we trigger timeout early */
273 GNUNET_SCHEDULER_cancel(request->timeout_task); 274 GNUNET_SCHEDULER_cancel (request->timeout_task);
274 do_timeout(request); 275 do_timeout (request);
275 return; 276 return;
276 } 277 }
277 if (request->original_request_id != dns->id) 278 if (request->original_request_id != dns->id)
278 { 279 {
279 /* for a another query, ignore */ 280 /* for a another query, ignore */
280 return; 281 return;
281 } 282 }
282 request->packet = GNUNET_DNSPARSER_parse((char*)dns, 283 request->packet = GNUNET_DNSPARSER_parse ((char*) dns,
283 r); 284 r);
284 GNUNET_DNSSTUB_resolve_cancel(request->dns_lookup); 285 GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup);
285 send_response(request); 286 send_response (request);
286} 287}
287 288
288 289
@@ -295,10 +296,10 @@ dns_result_processor(void *cls,
295 * @param rd the records in reply 296 * @param rd the records in reply
296 */ 297 */
297static void 298static void
298result_processor(void *cls, 299result_processor (void *cls,
299 int was_gns, 300 int was_gns,
300 uint32_t rd_count, 301 uint32_t rd_count,
301 const struct GNUNET_GNSRECORD_Data *rd) 302 const struct GNUNET_GNSRECORD_Data *rd)
302{ 303{
303 struct Request *request = cls; 304 struct Request *request = cls;
304 struct GNUNET_DNSPARSER_Packet *packet; 305 struct GNUNET_DNSPARSER_Packet *packet;
@@ -306,22 +307,22 @@ result_processor(void *cls,
306 307
307 request->lookup = NULL; 308 request->lookup = NULL;
308 if (GNUNET_NO == was_gns) 309 if (GNUNET_NO == was_gns)
309 { 310 {
310 /* TLD not configured for GNS, fall back to DNS */ 311 /* TLD not configured for GNS, fall back to DNS */
311 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
312 "Using DNS resolver IP `%s' to resolve `%s'\n", 313 "Using DNS resolver IP `%s' to resolve `%s'\n",
313 dns_ip, 314 dns_ip,
314 request->packet->queries[0].name); 315 request->packet->queries[0].name);
315 request->original_request_id = request->packet->id; 316 request->original_request_id = request->packet->id;
316 GNUNET_DNSPARSER_free_packet(request->packet); 317 GNUNET_DNSPARSER_free_packet (request->packet);
317 request->packet = NULL; 318 request->packet = NULL;
318 request->dns_lookup = GNUNET_DNSSTUB_resolve(dns_stub, 319 request->dns_lookup = GNUNET_DNSSTUB_resolve (dns_stub,
319 request->udp_msg, 320 request->udp_msg,
320 request->udp_msg_size, 321 request->udp_msg_size,
321 &dns_result_processor, 322 &dns_result_processor,
322 request); 323 request);
323 return; 324 return;
324 } 325 }
325 packet = request->packet; 326 packet = request->packet;
326 packet->flags.query_or_response = 1; 327 packet->flags.query_or_response = 1;
327 packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; 328 packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR;
@@ -331,63 +332,63 @@ result_processor(void *cls,
331 packet->flags.recursion_available = 1; 332 packet->flags.recursion_available = 1;
332 packet->flags.message_truncated = 0; 333 packet->flags.message_truncated = 0;
333 packet->flags.authoritative_answer = 0; 334 packet->flags.authoritative_answer = 0;
334 //packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ??? 335 // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
335 for (uint32_t i = 0; i < rd_count; i++) 336 for (uint32_t i = 0; i < rd_count; i++)
337 {
338 // FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD
339 // here? Or should we do this in libgnunetgns?
340 rec.expiration_time.abs_value_us = rd[i].expiration_time;
341 switch (rd[i].record_type)
336 { 342 {
337 // FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD 343 case GNUNET_DNSPARSER_TYPE_A:
338 // here? Or should we do this in libgnunetgns? 344 GNUNET_assert (sizeof(struct in_addr) == rd[i].data_size);
339 rec.expiration_time.abs_value_us = rd[i].expiration_time; 345 rec.name = GNUNET_strdup (packet->queries[0].name);
340 switch (rd[i].record_type) 346 rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
341 { 347 rec.type = GNUNET_DNSPARSER_TYPE_A;
342 case GNUNET_DNSPARSER_TYPE_A: 348 rec.data.raw.data = GNUNET_new (struct in_addr);
343 GNUNET_assert(sizeof(struct in_addr) == rd[i].data_size); 349 GNUNET_memcpy (rec.data.raw.data,
344 rec.name = GNUNET_strdup(packet->queries[0].name); 350 rd[i].data,
345 rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 351 rd[i].data_size);
346 rec.type = GNUNET_DNSPARSER_TYPE_A; 352 rec.data.raw.data_len = sizeof(struct in_addr);
347 rec.data.raw.data = GNUNET_new(struct in_addr); 353 GNUNET_array_append (packet->answers,
348 GNUNET_memcpy(rec.data.raw.data, 354 packet->num_answers,
349 rd[i].data, 355 rec);
350 rd[i].data_size); 356 break;
351 rec.data.raw.data_len = sizeof(struct in_addr); 357
352 GNUNET_array_append(packet->answers, 358 case GNUNET_DNSPARSER_TYPE_AAAA:
353 packet->num_answers, 359 GNUNET_assert (sizeof(struct in6_addr) == rd[i].data_size);
354 rec); 360 rec.name = GNUNET_strdup (packet->queries[0].name);
355 break; 361 rec.data.raw.data = GNUNET_new (struct in6_addr);
356 362 rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
357 case GNUNET_DNSPARSER_TYPE_AAAA: 363 rec.type = GNUNET_DNSPARSER_TYPE_AAAA;
358 GNUNET_assert(sizeof(struct in6_addr) == rd[i].data_size); 364 GNUNET_memcpy (rec.data.raw.data,
359 rec.name = GNUNET_strdup(packet->queries[0].name); 365 rd[i].data,
360 rec.data.raw.data = GNUNET_new(struct in6_addr); 366 rd[i].data_size);
361 rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 367 rec.data.raw.data_len = sizeof(struct in6_addr);
362 rec.type = GNUNET_DNSPARSER_TYPE_AAAA; 368 GNUNET_array_append (packet->answers,
363 GNUNET_memcpy(rec.data.raw.data, 369 packet->num_answers,
364 rd[i].data, 370 rec);
365 rd[i].data_size); 371 break;
366 rec.data.raw.data_len = sizeof(struct in6_addr); 372
367 GNUNET_array_append(packet->answers, 373 case GNUNET_DNSPARSER_TYPE_CNAME:
368 packet->num_answers, 374 rec.name = GNUNET_strdup (packet->queries[0].name);
369 rec); 375 rec.data.hostname = GNUNET_strdup (rd[i].data);
370 break; 376 rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
371 377 rec.type = GNUNET_DNSPARSER_TYPE_CNAME;
372 case GNUNET_DNSPARSER_TYPE_CNAME: 378 GNUNET_memcpy (rec.data.hostname,
373 rec.name = GNUNET_strdup(packet->queries[0].name); 379 rd[i].data,
374 rec.data.hostname = GNUNET_strdup(rd[i].data); 380 rd[i].data_size);
375 rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 381 GNUNET_array_append (packet->answers,
376 rec.type = GNUNET_DNSPARSER_TYPE_CNAME; 382 packet->num_answers,
377 GNUNET_memcpy(rec.data.hostname, 383 rec);
378 rd[i].data, 384 break;
379 rd[i].data_size); 385
380 GNUNET_array_append(packet->answers, 386 default:
381 packet->num_answers, 387 /* skip */
382 rec); 388 break;
383 break;
384
385 default:
386 /* skip */
387 break;
388 }
389 } 389 }
390 send_response(request); 390 }
391 send_response (request);
391} 392}
392 393
393 394
@@ -401,73 +402,73 @@ result_processor(void *cls,
401 * @param udp_msg_size number of bytes in @a udp_msg 402 * @param udp_msg_size number of bytes in @a udp_msg
402 */ 403 */
403static void 404static void
404handle_request(struct GNUNET_NETWORK_Handle *lsock, 405handle_request (struct GNUNET_NETWORK_Handle *lsock,
405 const void *addr, 406 const void *addr,
406 size_t addr_len, 407 size_t addr_len,
407 const char *udp_msg, 408 const char *udp_msg,
408 size_t udp_msg_size) 409 size_t udp_msg_size)
409{ 410{
410 struct Request *request; 411 struct Request *request;
411 struct GNUNET_DNSPARSER_Packet *packet; 412 struct GNUNET_DNSPARSER_Packet *packet;
412 413
413 packet = GNUNET_DNSPARSER_parse(udp_msg, 414 packet = GNUNET_DNSPARSER_parse (udp_msg,
414 udp_msg_size); 415 udp_msg_size);
415 if (NULL == packet) 416 if (NULL == packet)
416 { 417 {
417 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 418 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
418 _("Cannot parse DNS request from %s\n"), 419 _ ("Cannot parse DNS request from %s\n"),
419 GNUNET_a2s(addr, addr_len)); 420 GNUNET_a2s (addr, addr_len));
420 return; 421 return;
421 } 422 }
422 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n", 424 "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n",
424 packet->queries[0].name, 425 packet->queries[0].name,
425 (unsigned int)packet->flags.query_or_response, 426 (unsigned int) packet->flags.query_or_response,
426 (int)packet->num_answers, 427 (int) packet->num_answers,
427 (int)packet->num_authority_records, 428 (int) packet->num_authority_records,
428 (int)packet->num_additional_records); 429 (int) packet->num_additional_records);
429 if ((0 != packet->flags.query_or_response) || 430 if ((0 != packet->flags.query_or_response) ||
430 (0 != packet->num_answers) || 431 (0 != packet->num_answers) ||
431 (0 != packet->num_authority_records)) 432 (0 != packet->num_authority_records))
432 { 433 {
433 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 434 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
434 _("Received malformed DNS request from %s\n"), 435 _ ("Received malformed DNS request from %s\n"),
435 GNUNET_a2s(addr, addr_len)); 436 GNUNET_a2s (addr, addr_len));
436 GNUNET_DNSPARSER_free_packet(packet); 437 GNUNET_DNSPARSER_free_packet (packet);
437 return; 438 return;
438 } 439 }
439 if ((1 != packet->num_queries)) 440 if ((1 != packet->num_queries))
440 { 441 {
441 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 442 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
442 _("Received unsupported DNS request from %s\n"), 443 _ ("Received unsupported DNS request from %s\n"),
443 GNUNET_a2s(addr, 444 GNUNET_a2s (addr,
444 addr_len)); 445 addr_len));
445 GNUNET_DNSPARSER_free_packet(packet); 446 GNUNET_DNSPARSER_free_packet (packet);
446 return; 447 return;
447 } 448 }
448 request = GNUNET_malloc(sizeof(struct Request) + addr_len); 449 request = GNUNET_malloc (sizeof(struct Request) + addr_len);
449 request->lsock = lsock; 450 request->lsock = lsock;
450 request->packet = packet; 451 request->packet = packet;
451 request->addr = &request[1]; 452 request->addr = &request[1];
452 request->addr_len = addr_len; 453 request->addr_len = addr_len;
453 GNUNET_memcpy(&request[1], 454 GNUNET_memcpy (&request[1],
454 addr, 455 addr,
455 addr_len); 456 addr_len);
456 request->udp_msg_size = udp_msg_size; 457 request->udp_msg_size = udp_msg_size;
457 request->udp_msg = GNUNET_memdup(udp_msg, 458 request->udp_msg = GNUNET_memdup (udp_msg,
458 udp_msg_size); 459 udp_msg_size);
459 request->timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, 460 request->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
460 &do_timeout, 461 &do_timeout,
461 request); 462 request);
462 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Calling GNS on `%s'\n", 464 "Calling GNS on `%s'\n",
464 packet->queries[0].name); 465 packet->queries[0].name);
465 request->lookup = GNUNET_GNS_lookup_with_tld(gns, 466 request->lookup = GNUNET_GNS_lookup_with_tld (gns,
466 packet->queries[0].name, 467 packet->queries[0].name,
467 packet->queries[0].type, 468 packet->queries[0].type,
468 GNUNET_NO, 469 GNUNET_NO,
469 &result_processor, 470 &result_processor,
470 request); 471 request);
471} 472}
472 473
473 474
@@ -477,49 +478,49 @@ handle_request(struct GNUNET_NETWORK_Handle *lsock,
477 * @param cls the 'listen_socket4' 478 * @param cls the 'listen_socket4'
478 */ 479 */
479static void 480static void
480read_dns4(void *cls) 481read_dns4 (void *cls)
481{ 482{
482 struct sockaddr_in v4; 483 struct sockaddr_in v4;
483 socklen_t addrlen; 484 socklen_t addrlen;
484 ssize_t size; 485 ssize_t size;
485 const struct GNUNET_SCHEDULER_TaskContext *tc; 486 const struct GNUNET_SCHEDULER_TaskContext *tc;
486 487
487 GNUNET_assert(listen_socket4 == cls); 488 GNUNET_assert (listen_socket4 == cls);
488 t4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 489 t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
489 listen_socket4, 490 listen_socket4,
490 &read_dns4, 491 &read_dns4,
491 listen_socket4); 492 listen_socket4);
492 tc = GNUNET_SCHEDULER_get_task_context(); 493 tc = GNUNET_SCHEDULER_get_task_context ();
493 if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason)) 494 if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason))
494 return; /* shutdown? */ 495 return; /* shutdown? */
495 size = GNUNET_NETWORK_socket_recvfrom_amount(listen_socket4); 496 size = GNUNET_NETWORK_socket_recvfrom_amount (listen_socket4);
496 if (0 > size) 497 if (0 > size)
497 { 498 {
498 GNUNET_break(0); 499 GNUNET_break (0);
499 return; /* read error!? */ 500 return; /* read error!? */
500 } 501 }
501 { 502 {
502 char buf[size + 1]; 503 char buf[size + 1];
503 ssize_t sret; 504 ssize_t sret;
504 505
505 addrlen = sizeof(v4); 506 addrlen = sizeof(v4);
506 sret = GNUNET_NETWORK_socket_recvfrom(listen_socket4, 507 sret = GNUNET_NETWORK_socket_recvfrom (listen_socket4,
507 buf, 508 buf,
508 size + 1, 509 size + 1,
509 (struct sockaddr *)&v4, 510 (struct sockaddr *) &v4,
510 &addrlen); 511 &addrlen);
511 if (0 > sret) 512 if (0 > sret)
512 { 513 {
513 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, 514 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
514 "recvfrom"); 515 "recvfrom");
515 return; 516 return;
516 } 517 }
517 GNUNET_break(size == sret); 518 GNUNET_break (size == sret);
518 handle_request(listen_socket4, 519 handle_request (listen_socket4,
519 &v4, 520 &v4,
520 addrlen, 521 addrlen,
521 buf, 522 buf,
522 size); 523 size);
523 } 524 }
524} 525}
525 526
@@ -530,49 +531,49 @@ read_dns4(void *cls)
530 * @param cls the 'listen_socket6' 531 * @param cls the 'listen_socket6'
531 */ 532 */
532static void 533static void
533read_dns6(void *cls) 534read_dns6 (void *cls)
534{ 535{
535 struct sockaddr_in6 v6; 536 struct sockaddr_in6 v6;
536 socklen_t addrlen; 537 socklen_t addrlen;
537 ssize_t size; 538 ssize_t size;
538 const struct GNUNET_SCHEDULER_TaskContext *tc; 539 const struct GNUNET_SCHEDULER_TaskContext *tc;
539 540
540 GNUNET_assert(listen_socket6 == cls); 541 GNUNET_assert (listen_socket6 == cls);
541 t6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 542 t6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
542 listen_socket6, 543 listen_socket6,
543 &read_dns6, 544 &read_dns6,
544 listen_socket6); 545 listen_socket6);
545 tc = GNUNET_SCHEDULER_get_task_context(); 546 tc = GNUNET_SCHEDULER_get_task_context ();
546 if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason)) 547 if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason))
547 return; /* shutdown? */ 548 return; /* shutdown? */
548 size = GNUNET_NETWORK_socket_recvfrom_amount(listen_socket6); 549 size = GNUNET_NETWORK_socket_recvfrom_amount (listen_socket6);
549 if (0 > size) 550 if (0 > size)
550 { 551 {
551 GNUNET_break(0); 552 GNUNET_break (0);
552 return; /* read error!? */ 553 return; /* read error!? */
553 } 554 }
554 { 555 {
555 char buf[size]; 556 char buf[size];
556 ssize_t sret; 557 ssize_t sret;
557 558
558 addrlen = sizeof(v6); 559 addrlen = sizeof(v6);
559 sret = GNUNET_NETWORK_socket_recvfrom(listen_socket6, 560 sret = GNUNET_NETWORK_socket_recvfrom (listen_socket6,
560 buf, 561 buf,
561 size, 562 size,
562 (struct sockaddr *)&v6, 563 (struct sockaddr *) &v6,
563 &addrlen); 564 &addrlen);
564 if (0 > sret) 565 if (0 > sret)
565 { 566 {
566 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, 567 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
567 "recvfrom"); 568 "recvfrom");
568 return; 569 return;
569 } 570 }
570 GNUNET_break(size == sret); 571 GNUNET_break (size == sret);
571 handle_request(listen_socket6, 572 handle_request (listen_socket6,
572 &v6, 573 &v6,
573 addrlen, 574 addrlen,
574 buf, 575 buf,
575 size); 576 size);
576 } 577 }
577} 578}
578 579
@@ -586,150 +587,150 @@ read_dns6(void *cls)
586 * @param c configuration 587 * @param c configuration
587 */ 588 */
588static void 589static void
589run(void *cls, 590run (void *cls,
590 char *const *args, 591 char *const *args,
591 const char *cfgfile, 592 const char *cfgfile,
592 const struct GNUNET_CONFIGURATION_Handle *c) 593 const struct GNUNET_CONFIGURATION_Handle *c)
593{ 594{
594 char *addr_str; 595 char *addr_str;
595 596
596 (void)cls; 597 (void) cls;
597 (void)args; 598 (void) args;
598 (void)cfgfile; 599 (void) cfgfile;
599 cfg = c; 600 cfg = c;
600 if (NULL == dns_ip) 601 if (NULL == dns_ip)
601 { 602 {
602 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
603 _("No DNS server specified!\n")); 604 _ ("No DNS server specified!\n"));
604 return;
605 }
606 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
607 NULL);
608 if (NULL == (gns = GNUNET_GNS_connect(cfg)))
609 return; 605 return;
610 GNUNET_assert(NULL != (dns_stub = GNUNET_DNSSTUB_start(128))); 606 }
607 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
608 NULL);
609 if (NULL == (gns = GNUNET_GNS_connect (cfg)))
610 return;
611 GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128)));
611 if (GNUNET_OK != 612 if (GNUNET_OK !=
612 GNUNET_DNSSTUB_add_dns_ip(dns_stub, 613 GNUNET_DNSSTUB_add_dns_ip (dns_stub,
613 dns_ip)) 614 dns_ip))
614 { 615 {
615 GNUNET_DNSSTUB_stop(dns_stub); 616 GNUNET_DNSSTUB_stop (dns_stub);
616 GNUNET_GNS_disconnect(gns); 617 GNUNET_GNS_disconnect (gns);
617 gns = NULL; 618 gns = NULL;
618 return; 619 return;
619 } 620 }
620 621
621 /* Get address to bind to */ 622 /* Get address to bind to */
622 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(c, "dns2gns", 623 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns",
623 "BIND_TO", 624 "BIND_TO",
624 &addr_str)) 625 &addr_str))
625 { 626 {
626 //No address specified 627 // No address specified
627 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 628 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
628 "Don't know what to bind to...\n"); 629 "Don't know what to bind to...\n");
629 GNUNET_free(addr_str); 630 GNUNET_free (addr_str);
630 GNUNET_SCHEDULER_shutdown(); 631 GNUNET_SCHEDULER_shutdown ();
631 return; 632 return;
632 } 633 }
633 if (1 != inet_pton(AF_INET, addr_str, &address)) 634 if (1 != inet_pton (AF_INET, addr_str, &address))
634 { 635 {
635 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 636 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
636 "Unable to parse address %s\n", 637 "Unable to parse address %s\n",
637 addr_str); 638 addr_str);
638 GNUNET_free(addr_str); 639 GNUNET_free (addr_str);
639 GNUNET_SCHEDULER_shutdown(); 640 GNUNET_SCHEDULER_shutdown ();
640 return; 641 return;
641 } 642 }
642 GNUNET_free(addr_str); 643 GNUNET_free (addr_str);
643 /* Get address to bind to */ 644 /* Get address to bind to */
644 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(c, "dns2gns", 645 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns",
645 "BIND_TO6", 646 "BIND_TO6",
646 &addr_str)) 647 &addr_str))
647 { 648 {
648 //No address specified 649 // No address specified
649 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
650 "Don't know what to bind6 to...\n"); 651 "Don't know what to bind6 to...\n");
651 GNUNET_free(addr_str); 652 GNUNET_free (addr_str);
652 GNUNET_SCHEDULER_shutdown(); 653 GNUNET_SCHEDULER_shutdown ();
653 return; 654 return;
654 } 655 }
655 if (1 != inet_pton(AF_INET6, addr_str, &address6)) 656 if (1 != inet_pton (AF_INET6, addr_str, &address6))
656 { 657 {
657 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
658 "Unable to parse IPv6 address %s\n", 659 "Unable to parse IPv6 address %s\n",
659 addr_str); 660 addr_str);
660 GNUNET_free(addr_str); 661 GNUNET_free (addr_str);
661 GNUNET_SCHEDULER_shutdown(); 662 GNUNET_SCHEDULER_shutdown ();
662 return; 663 return;
663 } 664 }
664 GNUNET_free(addr_str); 665 GNUNET_free (addr_str);
665 666
666 listen_socket4 = GNUNET_NETWORK_socket_create(PF_INET, 667 listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET,
667 SOCK_DGRAM, 668 SOCK_DGRAM,
668 IPPROTO_UDP); 669 IPPROTO_UDP);
669 if (NULL != listen_socket4) 670 if (NULL != listen_socket4)
670 { 671 {
671 struct sockaddr_in v4; 672 struct sockaddr_in v4;
672 673
673 memset(&v4, 0, sizeof(v4)); 674 memset (&v4, 0, sizeof(v4));
674 v4.sin_family = AF_INET; 675 v4.sin_family = AF_INET;
675 v4.sin_addr.s_addr = address; 676 v4.sin_addr.s_addr = address;
676#if HAVE_SOCKADDR_IN_SIN_LEN 677#if HAVE_SOCKADDR_IN_SIN_LEN
677 v4.sin_len = sizeof(v4); 678 v4.sin_len = sizeof(v4);
678#endif 679#endif
679 v4.sin_port = htons(listen_port); 680 v4.sin_port = htons (listen_port);
680 if (GNUNET_OK != 681 if (GNUNET_OK !=
681 GNUNET_NETWORK_socket_bind(listen_socket4, 682 GNUNET_NETWORK_socket_bind (listen_socket4,
682 (struct sockaddr *)&v4, 683 (struct sockaddr *) &v4,
683 sizeof(v4))) 684 sizeof(v4)))
684 { 685 {
685 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); 686 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
686 GNUNET_NETWORK_socket_close(listen_socket4); 687 GNUNET_NETWORK_socket_close (listen_socket4);
687 listen_socket4 = NULL; 688 listen_socket4 = NULL;
688 }
689 } 689 }
690 listen_socket6 = GNUNET_NETWORK_socket_create(PF_INET6, 690 }
691 SOCK_DGRAM, 691 listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6,
692 IPPROTO_UDP); 692 SOCK_DGRAM,
693 IPPROTO_UDP);
693 if (NULL != listen_socket6) 694 if (NULL != listen_socket6)
694 { 695 {
695 struct sockaddr_in6 v6; 696 struct sockaddr_in6 v6;
696 697
697 memset(&v6, 0, sizeof(v6)); 698 memset (&v6, 0, sizeof(v6));
698 v6.sin6_family = AF_INET6; 699 v6.sin6_family = AF_INET6;
699 v6.sin6_addr = address6; 700 v6.sin6_addr = address6;
700#if HAVE_SOCKADDR_IN_SIN_LEN 701#if HAVE_SOCKADDR_IN_SIN_LEN
701 v6.sin6_len = sizeof(v6); 702 v6.sin6_len = sizeof(v6);
702#endif 703#endif
703 v6.sin6_port = htons(listen_port); 704 v6.sin6_port = htons (listen_port);
704 if (GNUNET_OK != 705 if (GNUNET_OK !=
705 GNUNET_NETWORK_socket_bind(listen_socket6, 706 GNUNET_NETWORK_socket_bind (listen_socket6,
706 (struct sockaddr *)&v6, 707 (struct sockaddr *) &v6,
707 sizeof(v6))) 708 sizeof(v6)))
708 { 709 {
709 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); 710 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
710 GNUNET_NETWORK_socket_close(listen_socket6); 711 GNUNET_NETWORK_socket_close (listen_socket6);
711 listen_socket6 = NULL; 712 listen_socket6 = NULL;
712 }
713 } 713 }
714 }
714 if ((NULL == listen_socket4) && 715 if ((NULL == listen_socket4) &&
715 (NULL == listen_socket6)) 716 (NULL == listen_socket6))
716 { 717 {
717 GNUNET_GNS_disconnect(gns); 718 GNUNET_GNS_disconnect (gns);
718 gns = NULL; 719 gns = NULL;
719 GNUNET_DNSSTUB_stop(dns_stub); 720 GNUNET_DNSSTUB_stop (dns_stub);
720 dns_stub = NULL; 721 dns_stub = NULL;
721 return; 722 return;
722 } 723 }
723 if (NULL != listen_socket4) 724 if (NULL != listen_socket4)
724 t4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 725 t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
725 listen_socket4, 726 listen_socket4,
726 &read_dns4, 727 &read_dns4,
727 listen_socket4); 728 listen_socket4);
728 if (NULL != listen_socket6) 729 if (NULL != listen_socket6)
729 t6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 730 t6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
730 listen_socket6, 731 listen_socket6,
731 &read_dns6, 732 &read_dns6,
732 listen_socket6); 733 listen_socket6);
733} 734}
734 735
735 736
@@ -741,39 +742,41 @@ run(void *cls,
741 * @return 0 ok, 1 on error 742 * @return 0 ok, 1 on error
742 */ 743 */
743int 744int
744main(int argc, 745main (int argc,
745 char *const *argv) 746 char *const *argv)
746{ 747{
747 struct GNUNET_GETOPT_CommandLineOption options[] = { 748 struct GNUNET_GETOPT_CommandLineOption options[] = {
748 GNUNET_GETOPT_option_string('d', 749 GNUNET_GETOPT_option_string ('d',
749 "dns", 750 "dns",
750 "IP", 751 "IP",
751 gettext_noop("IP of recursive DNS resolver to use (required)"), 752 gettext_noop (
752 &dns_ip), 753 "IP of recursive DNS resolver to use (required)"),
753 GNUNET_GETOPT_option_uint('p', 754 &dns_ip),
754 "port", 755 GNUNET_GETOPT_option_uint ('p',
755 "UDPPORT", 756 "port",
756 gettext_noop("UDP port to listen on for inbound DNS requests; default: 2853"), 757 "UDPPORT",
757 &listen_port), 758 gettext_noop (
759 "UDP port to listen on for inbound DNS requests; default: 2853"),
760 &listen_port),
758 GNUNET_GETOPT_OPTION_END 761 GNUNET_GETOPT_OPTION_END
759 }; 762 };
760 int ret; 763 int ret;
761 764
762 if (GNUNET_OK != 765 if (GNUNET_OK !=
763 GNUNET_STRINGS_get_utf8_args(argc, argv, 766 GNUNET_STRINGS_get_utf8_args (argc, argv,
764 &argc, &argv)) 767 &argc, &argv))
765 return 2; 768 return 2;
766 GNUNET_log_setup("gnunet-dns2gns", 769 GNUNET_log_setup ("gnunet-dns2gns",
767 "WARNING", 770 "WARNING",
768 NULL); 771 NULL);
769 ret = 772 ret =
770 (GNUNET_OK == 773 (GNUNET_OK ==
771 GNUNET_PROGRAM_run(argc, argv, 774 GNUNET_PROGRAM_run (argc, argv,
772 "gnunet-dns2gns", 775 "gnunet-dns2gns",
773 _("GNUnet DNS-to-GNS proxy (a DNS server)"), 776 _ ("GNUnet DNS-to-GNS proxy (a DNS server)"),
774 options, 777 options,
775 &run, NULL)) ? 0 : 1; 778 &run, NULL)) ? 0 : 1;
776 GNUNET_free((void*)argv); 779 GNUNET_free ((void*) argv);
777 return ret; 780 return ret;
778} 781}
779 782
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c
index b64201f10..d85b9e203 100644
--- a/src/gns/gnunet-gns-benchmark.c
+++ b/src/gns/gnunet-gns-benchmark.c
@@ -31,12 +31,13 @@
31/** 31/**
32 * How long do we wait at least between requests by default? 32 * How long do we wait at least between requests by default?
33 */ 33 */
34#define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1) 34#define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply ( \
35 GNUNET_TIME_UNIT_MILLISECONDS, 1)
35 36
36/** 37/**
37 * How long do we wait until we consider a request failed by default? 38 * How long do we wait until we consider a request failed by default?
38 */ 39 */
39#define DEF_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) 40#define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
40 41
41 42
42/** 43/**
@@ -45,7 +46,8 @@
45 * However, this process does not change how it acts 46 * However, this process does not change how it acts
46 * based on the category. 47 * based on the category.
47 */ 48 */
48enum RequestCategory { 49enum RequestCategory
50{
49 RC_SHARED = 0, 51 RC_SHARED = 0,
50 RC_PRIVATE = 1, 52 RC_PRIVATE = 1,
51 /** 53 /**
@@ -60,7 +62,8 @@ enum RequestCategory {
60 * thus optimizing it is crucial for the overall memory consumption of 62 * thus optimizing it is crucial for the overall memory consumption of
61 * the zone importer. 63 * the zone importer.
62 */ 64 */
63struct Request { 65struct Request
66{
64 /** 67 /**
65 * Active requests are kept in a DLL. 68 * Active requests are kept in a DLL.
66 */ 69 */
@@ -188,11 +191,11 @@ static int g2d;
188 * @param req request to free 191 * @param req request to free
189 */ 192 */
190static void 193static void
191free_request(struct Request *req) 194free_request (struct Request *req)
192{ 195{
193 if (NULL != req->lr) 196 if (NULL != req->lr)
194 GNUNET_GNS_lookup_with_tld_cancel(req->lr); 197 GNUNET_GNS_lookup_with_tld_cancel (req->lr);
195 GNUNET_free(req); 198 GNUNET_free (req);
196} 199}
197 200
198 201
@@ -205,32 +208,32 @@ free_request(struct Request *req)
205 * @param rd the records in reply 208 * @param rd the records in reply
206 */ 209 */
207static void 210static void
208process_result(void *cls, 211process_result (void *cls,
209 int gns_tld, 212 int gns_tld,
210 uint32_t rd_count, 213 uint32_t rd_count,
211 const struct GNUNET_GNSRECORD_Data *rd) 214 const struct GNUNET_GNSRECORD_Data *rd)
212{ 215{
213 struct Request *req = cls; 216 struct Request *req = cls;
214 217
215 (void)gns_tld; 218 (void) gns_tld;
216 (void)rd_count; 219 (void) rd_count;
217 (void)rd; 220 (void) rd;
218 active_cnt--; 221 active_cnt--;
219 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 "Got response for request `%s'\n", 223 "Got response for request `%s'\n",
221 req->hostname); 224 req->hostname);
222 req->lr = NULL; 225 req->lr = NULL;
223 req->latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); 226 req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
224 GNUNET_CONTAINER_DLL_remove(act_head, 227 GNUNET_CONTAINER_DLL_remove (act_head,
225 act_tail, 228 act_tail,
226 req); 229 req);
227 GNUNET_CONTAINER_DLL_insert(succ_head, 230 GNUNET_CONTAINER_DLL_insert (succ_head,
228 succ_tail, 231 succ_tail,
229 req); 232 req);
230 replies[req->cat]++; 233 replies[req->cat]++;
231 latency_sum[req->cat] 234 latency_sum[req->cat]
232 = GNUNET_TIME_relative_add(latency_sum[req->cat], 235 = GNUNET_TIME_relative_add (latency_sum[req->cat],
233 req->latency); 236 req->latency);
234} 237}
235 238
236 239
@@ -240,69 +243,69 @@ process_result(void *cls,
240 * @param cls NULL 243 * @param cls NULL
241 */ 244 */
242static void 245static void
243process_queue(void *cls) 246process_queue (void *cls)
244{ 247{
245 struct Request *req; 248 struct Request *req;
246 struct GNUNET_TIME_Relative duration; 249 struct GNUNET_TIME_Relative duration;
247 250
248 (void)cls; 251 (void) cls;
249 t = NULL; 252 t = NULL;
250 /* check for expired requests */ 253 /* check for expired requests */
251 while (NULL != (req = act_head)) 254 while (NULL != (req = act_head))
252 { 255 {
253 duration = GNUNET_TIME_absolute_get_duration(req->op_start_time); 256 duration = GNUNET_TIME_absolute_get_duration (req->op_start_time);
254 if (duration.rel_value_us < timeout.rel_value_us) 257 if (duration.rel_value_us < timeout.rel_value_us)
255 break; 258 break;
256 GNUNET_CONTAINER_DLL_remove(act_head, 259 GNUNET_CONTAINER_DLL_remove (act_head,
257 act_tail, 260 act_tail,
258 req); 261 req);
259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Failing request `%s' due to timeout\n", 263 "Failing request `%s' due to timeout\n",
261 req->hostname); 264 req->hostname);
262 failures[req->cat]++; 265 failures[req->cat]++;
263 active_cnt--; 266 active_cnt--;
264 free_request(req); 267 free_request (req);
265 } 268 }
266 if (NULL == (req = todo_head)) 269 if (NULL == (req = todo_head))
270 {
271 struct GNUNET_TIME_Absolute at;
272
273 if (NULL == (req = act_head))
267 { 274 {
268 struct GNUNET_TIME_Absolute at; 275 GNUNET_SCHEDULER_shutdown ();
269
270 if (NULL == (req = act_head))
271 {
272 GNUNET_SCHEDULER_shutdown();
273 return;
274 }
275 at = GNUNET_TIME_absolute_add(req->op_start_time,
276 timeout);
277 t = GNUNET_SCHEDULER_add_at(at,
278 &process_queue,
279 NULL);
280 return; 276 return;
281 } 277 }
282 GNUNET_CONTAINER_DLL_remove(todo_head, 278 at = GNUNET_TIME_absolute_add (req->op_start_time,
283 todo_tail, 279 timeout);
284 req); 280 t = GNUNET_SCHEDULER_add_at (at,
285 GNUNET_CONTAINER_DLL_insert_tail(act_head, 281 &process_queue,
286 act_tail, 282 NULL);
287 req); 283 return;
284 }
285 GNUNET_CONTAINER_DLL_remove (todo_head,
286 todo_tail,
287 req);
288 GNUNET_CONTAINER_DLL_insert_tail (act_head,
289 act_tail,
290 req);
288 lookups[req->cat]++; 291 lookups[req->cat]++;
289 active_cnt++; 292 active_cnt++;
290 req->op_start_time = GNUNET_TIME_absolute_get(); 293 req->op_start_time = GNUNET_TIME_absolute_get ();
291 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
292 "Starting request `%s' (%u in parallel)\n", 295 "Starting request `%s' (%u in parallel)\n",
293 req->hostname, 296 req->hostname,
294 active_cnt); 297 active_cnt);
295 req->lr = GNUNET_GNS_lookup_with_tld(gns, 298 req->lr = GNUNET_GNS_lookup_with_tld (gns,
296 req->hostname, 299 req->hostname,
297 g2d 300 g2d
298 ? GNUNET_GNSRECORD_TYPE_GNS2DNS 301 ? GNUNET_GNSRECORD_TYPE_GNS2DNS
299 : GNUNET_GNSRECORD_TYPE_ANY, 302 : GNUNET_GNSRECORD_TYPE_ANY,
300 GNUNET_GNS_LO_DEFAULT, 303 GNUNET_GNS_LO_DEFAULT,
301 &process_result, 304 &process_result,
302 req); 305 req);
303 t = GNUNET_SCHEDULER_add_delayed(request_delay, 306 t = GNUNET_SCHEDULER_add_delayed (request_delay,
304 &process_queue, 307 &process_queue,
305 NULL); 308 NULL);
306} 309}
307 310
308 311
@@ -314,11 +317,11 @@ process_queue(void *cls)
314 * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2. 317 * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2.
315 */ 318 */
316static int 319static int
317compare_req(const void *c1, 320compare_req (const void *c1,
318 const void *c2) 321 const void *c2)
319{ 322{
320 const struct Request *r1 = *(void **)c1; 323 const struct Request *r1 = *(void **) c1;
321 const struct Request *r2 = *(void **)c2; 324 const struct Request *r2 = *(void **) c2;
322 325
323 if (r1->latency.rel_value_us < r2->latency.rel_value_us) 326 if (r1->latency.rel_value_us < r2->latency.rel_value_us)
324 return -1; 327 return -1;
@@ -334,101 +337,101 @@ compare_req(const void *c1,
334 * @param cls NULL 337 * @param cls NULL
335 */ 338 */
336static void 339static void
337do_shutdown(void *cls) 340do_shutdown (void *cls)
338{ 341{
339 struct Request *req; 342 struct Request *req;
340 struct Request **ra[RC_MAX]; 343 struct Request **ra[RC_MAX];
341 unsigned int rp[RC_MAX]; 344 unsigned int rp[RC_MAX];
342 345
343 (void)cls; 346 (void) cls;
344 for (enum RequestCategory rc = 0; rc < RC_MAX; rc++) 347 for (enum RequestCategory rc = 0; rc < RC_MAX; rc++)
345 { 348 {
346 ra[rc] = GNUNET_new_array(replies[rc], 349 ra[rc] = GNUNET_new_array (replies[rc],
347 struct Request *); 350 struct Request *);
348 rp[rc] = 0; 351 rp[rc] = 0;
349 } 352 }
350 for (req = succ_head; NULL != req; req = req->next) 353 for (req = succ_head; NULL != req; req = req->next)
351 { 354 {
352 GNUNET_assert(rp[req->cat] < replies[req->cat]); 355 GNUNET_assert (rp[req->cat] < replies[req->cat]);
353 ra[req->cat][rp[req->cat]++] = req; 356 ra[req->cat][rp[req->cat]++] = req;
354 } 357 }
355 for (enum RequestCategory rc = 0; rc < RC_MAX; rc++) 358 for (enum RequestCategory rc = 0; rc < RC_MAX; rc++)
356 { 359 {
357 unsigned int off; 360 unsigned int off;
358 361
359 fprintf(stdout, 362 fprintf (stdout,
360 "Category %u\n", 363 "Category %u\n",
361 rc); 364 rc);
362 fprintf(stdout, 365 fprintf (stdout,
363 "\tlookups: %u replies: %u failures: %u\n", 366 "\tlookups: %u replies: %u failures: %u\n",
364 lookups[rc], 367 lookups[rc],
365 replies[rc], 368 replies[rc],
366 failures[rc]); 369 failures[rc]);
367 if (0 == rp[rc]) 370 if (0 == rp[rc])
368 continue; 371 continue;
369 qsort(ra[rc], 372 qsort (ra[rc],
370 rp[rc], 373 rp[rc],
371 sizeof(struct Request *), 374 sizeof(struct Request *),
372 &compare_req); 375 &compare_req);
373 latency_sum[rc] = GNUNET_TIME_relative_divide(latency_sum[rc], 376 latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc],
374 replies[rc]); 377 replies[rc]);
375 fprintf(stdout, 378 fprintf (stdout,
376 "\taverage: %s\n", 379 "\taverage: %s\n",
377 GNUNET_STRINGS_relative_time_to_string(latency_sum[rc], 380 GNUNET_STRINGS_relative_time_to_string (latency_sum[rc],
378 GNUNET_YES)); 381 GNUNET_YES));
379 off = rp[rc] * 50 / 100; 382 off = rp[rc] * 50 / 100;
380 fprintf(stdout, 383 fprintf (stdout,
381 "\tmedian(50): %s\n", 384 "\tmedian(50): %s\n",
382 GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, 385 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
383 GNUNET_YES)); 386 GNUNET_YES));
384 off = rp[rc] * 75 / 100; 387 off = rp[rc] * 75 / 100;
385 fprintf(stdout, 388 fprintf (stdout,
386 "\tquantile(75): %s\n", 389 "\tquantile(75): %s\n",
387 GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, 390 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
388 GNUNET_YES)); 391 GNUNET_YES));
389 off = rp[rc] * 90 / 100; 392 off = rp[rc] * 90 / 100;
390 fprintf(stdout, 393 fprintf (stdout,
391 "\tquantile(90): %s\n", 394 "\tquantile(90): %s\n",
392 GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, 395 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
393 GNUNET_YES)); 396 GNUNET_YES));
394 off = rp[rc] * 99 / 100; 397 off = rp[rc] * 99 / 100;
395 fprintf(stdout, 398 fprintf (stdout,
396 "\tquantile(99): %s\n", 399 "\tquantile(99): %s\n",
397 GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, 400 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
398 GNUNET_YES)); 401 GNUNET_YES));
399 GNUNET_free(ra[rc]); 402 GNUNET_free (ra[rc]);
400 } 403 }
401 if (NULL != t) 404 if (NULL != t)
402 { 405 {
403 GNUNET_SCHEDULER_cancel(t); 406 GNUNET_SCHEDULER_cancel (t);
404 t = NULL; 407 t = NULL;
405 } 408 }
406 while (NULL != (req = act_head)) 409 while (NULL != (req = act_head))
407 { 410 {
408 GNUNET_CONTAINER_DLL_remove(act_head, 411 GNUNET_CONTAINER_DLL_remove (act_head,
409 act_tail, 412 act_tail,
410 req); 413 req);
411 free_request(req); 414 free_request (req);
412 } 415 }
413 while (NULL != (req = succ_head)) 416 while (NULL != (req = succ_head))
414 { 417 {
415 GNUNET_CONTAINER_DLL_remove(succ_head, 418 GNUNET_CONTAINER_DLL_remove (succ_head,
416 succ_tail, 419 succ_tail,
417 req); 420 req);
418 free_request(req); 421 free_request (req);
419 } 422 }
420 while (NULL != (req = todo_head)) 423 while (NULL != (req = todo_head))
421 { 424 {
422 GNUNET_CONTAINER_DLL_remove(todo_head, 425 GNUNET_CONTAINER_DLL_remove (todo_head,
423 todo_tail, 426 todo_tail,
424 req); 427 req);
425 free_request(req); 428 free_request (req);
426 } 429 }
427 if (NULL != gns) 430 if (NULL != gns)
428 { 431 {
429 GNUNET_GNS_disconnect(gns); 432 GNUNET_GNS_disconnect (gns);
430 gns = NULL; 433 gns = NULL;
431 } 434 }
432} 435}
433 436
434 437
@@ -439,32 +442,32 @@ do_shutdown(void *cls)
439 * @param cat category of the @a hostname 442 * @param cat category of the @a hostname
440 */ 443 */
441static void 444static void
442queue(const char *hostname, 445queue (const char *hostname,
443 enum RequestCategory cat) 446 enum RequestCategory cat)
444{ 447{
445 struct Request *req; 448 struct Request *req;
446 const char *dot; 449 const char *dot;
447 size_t hlen; 450 size_t hlen;
448 451
449 dot = strchr(hostname, 452 dot = strchr (hostname,
450 (unsigned char)'.'); 453 (unsigned char) '.');
451 if (NULL == dot) 454 if (NULL == dot)
452 { 455 {
453 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
454 "Refusing invalid hostname `%s' (lacks '.')\n", 457 "Refusing invalid hostname `%s' (lacks '.')\n",
455 hostname); 458 hostname);
456 return; 459 return;
457 } 460 }
458 hlen = strlen(hostname) + 1; 461 hlen = strlen (hostname) + 1;
459 req = GNUNET_malloc(sizeof(struct Request) + hlen); 462 req = GNUNET_malloc (sizeof(struct Request) + hlen);
460 req->cat = cat; 463 req->cat = cat;
461 req->hostname = (char *)&req[1]; 464 req->hostname = (char *) &req[1];
462 GNUNET_memcpy(&req[1], 465 GNUNET_memcpy (&req[1],
463 hostname, 466 hostname,
464 hlen); 467 hlen);
465 GNUNET_CONTAINER_DLL_insert(todo_head, 468 GNUNET_CONTAINER_DLL_insert (todo_head,
466 todo_tail, 469 todo_tail,
467 req); 470 req);
468} 471}
469 472
470 473
@@ -474,7 +477,7 @@ queue(const char *hostname,
474 * @param cls NULL 477 * @param cls NULL
475 */ 478 */
476static void 479static void
477process_stdin(void *cls) 480process_stdin (void *cls)
478{ 481{
479 static struct GNUNET_TIME_Absolute last; 482 static struct GNUNET_TIME_Absolute last;
480 static uint64_t idot; 483 static uint64_t idot;
@@ -482,48 +485,48 @@ process_stdin(void *cls)
482 char hn[256]; 485 char hn[256];
483 char in[270]; 486 char in[270];
484 487
485 (void)cls; 488 (void) cls;
486 t = NULL; 489 t = NULL;
487 while (NULL != 490 while (NULL !=
488 fgets(in, 491 fgets (in,
489 sizeof(in), 492 sizeof(in),
490 stdin)) 493 stdin))
494 {
495 if (strlen (in) > 0)
496 hn[strlen (in) - 1] = '\0'; /* eat newline */
497 if ((2 != sscanf (in,
498 "%u %255s",
499 &cat,
500 hn)) ||
501 (cat >= RC_MAX))
491 { 502 {
492 if (strlen(in) > 0) 503 fprintf (stderr,
493 hn[strlen(in) - 1] = '\0'; /* eat newline */ 504 "Malformed input line `%s', skipping\n",
494 if ((2 != sscanf(in, 505 in);
495 "%u %255s", 506 continue;
496 &cat,
497 hn)) ||
498 (cat >= RC_MAX))
499 {
500 fprintf(stderr,
501 "Malformed input line `%s', skipping\n",
502 in);
503 continue;
504 }
505 if (0 == idot)
506 last = GNUNET_TIME_absolute_get();
507 idot++;
508 if (0 == idot % 100000)
509 {
510 struct GNUNET_TIME_Relative delta;
511
512 delta = GNUNET_TIME_absolute_get_duration(last);
513 last = GNUNET_TIME_absolute_get();
514 fprintf(stderr,
515 "Read 100000 domain names in %s\n",
516 GNUNET_STRINGS_relative_time_to_string(delta,
517 GNUNET_YES));
518 }
519 queue(hn,
520 (enum RequestCategory)cat);
521 } 507 }
522 fprintf(stderr, 508 if (0 == idot)
523 "Done reading %llu domain names\n", 509 last = GNUNET_TIME_absolute_get ();
524 (unsigned long long)idot); 510 idot++;
525 t = GNUNET_SCHEDULER_add_now(&process_queue, 511 if (0 == idot % 100000)
526 NULL); 512 {
513 struct GNUNET_TIME_Relative delta;
514
515 delta = GNUNET_TIME_absolute_get_duration (last);
516 last = GNUNET_TIME_absolute_get ();
517 fprintf (stderr,
518 "Read 100000 domain names in %s\n",
519 GNUNET_STRINGS_relative_time_to_string (delta,
520 GNUNET_YES));
521 }
522 queue (hn,
523 (enum RequestCategory) cat);
524 }
525 fprintf (stderr,
526 "Done reading %llu domain names\n",
527 (unsigned long long) idot);
528 t = GNUNET_SCHEDULER_add_now (&process_queue,
529 NULL);
527} 530}
528 531
529 532
@@ -537,25 +540,25 @@ process_stdin(void *cls)
537 * @param cfg configuration 540 * @param cfg configuration
538 */ 541 */
539static void 542static void
540run(void *cls, 543run (void *cls,
541 char *const *args, 544 char *const *args,
542 const char *cfgfile, 545 const char *cfgfile,
543 const struct GNUNET_CONFIGURATION_Handle *cfg) 546 const struct GNUNET_CONFIGURATION_Handle *cfg)
544{ 547{
545 (void)cls; 548 (void) cls;
546 (void)args; 549 (void) args;
547 (void)cfgfile; 550 (void) cfgfile;
548 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 551 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
549 NULL); 552 NULL);
550 gns = GNUNET_GNS_connect(cfg); 553 gns = GNUNET_GNS_connect (cfg);
551 if (NULL == gns) 554 if (NULL == gns)
552 { 555 {
553 GNUNET_break(0); 556 GNUNET_break (0);
554 GNUNET_SCHEDULER_shutdown(); 557 GNUNET_SCHEDULER_shutdown ();
555 return; 558 return;
556 } 559 }
557 t = GNUNET_SCHEDULER_add_now(&process_stdin, 560 t = GNUNET_SCHEDULER_add_now (&process_stdin,
558 NULL); 561 NULL);
559} 562}
560 563
561 564
@@ -567,44 +570,47 @@ run(void *cls,
567 * @return 0 on success 570 * @return 0 on success
568 */ 571 */
569int 572int
570main(int argc, 573main (int argc,
571 char *const*argv) 574 char *const*argv)
572{ 575{
573 int ret = 0; 576 int ret = 0;
574 struct GNUNET_GETOPT_CommandLineOption options[] = { 577 struct GNUNET_GETOPT_CommandLineOption options[] = {
575 GNUNET_GETOPT_option_relative_time('d', 578 GNUNET_GETOPT_option_relative_time ('d',
576 "delay", 579 "delay",
577 "RELATIVETIME", 580 "RELATIVETIME",
578 gettext_noop("how long to wait between queries"), 581 gettext_noop (
579 &request_delay), 582 "how long to wait between queries"),
580 GNUNET_GETOPT_option_relative_time('t', 583 &request_delay),
581 "timeout", 584 GNUNET_GETOPT_option_relative_time ('t',
582 "RELATIVETIME", 585 "timeout",
583 gettext_noop("how long to wait for an answer"), 586 "RELATIVETIME",
584 &timeout), 587 gettext_noop (
585 GNUNET_GETOPT_option_flag('2', 588 "how long to wait for an answer"),
586 "g2d", 589 &timeout),
587 gettext_noop("look for GNS2DNS records instead of ANY"), 590 GNUNET_GETOPT_option_flag ('2',
588 &g2d), 591 "g2d",
592 gettext_noop (
593 "look for GNS2DNS records instead of ANY"),
594 &g2d),
589 GNUNET_GETOPT_OPTION_END 595 GNUNET_GETOPT_OPTION_END
590 }; 596 };
591 597
592 if (GNUNET_OK != 598 if (GNUNET_OK !=
593 GNUNET_STRINGS_get_utf8_args(argc, argv, 599 GNUNET_STRINGS_get_utf8_args (argc, argv,
594 &argc, &argv)) 600 &argc, &argv))
595 return 2; 601 return 2;
596 timeout = DEF_TIMEOUT; 602 timeout = DEF_TIMEOUT;
597 request_delay = DEF_REQUEST_DELAY; 603 request_delay = DEF_REQUEST_DELAY;
598 if (GNUNET_OK != 604 if (GNUNET_OK !=
599 GNUNET_PROGRAM_run(argc, 605 GNUNET_PROGRAM_run (argc,
600 argv, 606 argv,
601 "gnunet-gns-benchmark", 607 "gnunet-gns-benchmark",
602 "resolve GNS names and measure performance", 608 "resolve GNS names and measure performance",
603 options, 609 options,
604 &run, 610 &run,
605 NULL)) 611 NULL))
606 ret = 1; 612 ret = 1;
607 GNUNET_free((void*)argv); 613 GNUNET_free ((void*) argv);
608 return ret; 614 return ret;
609} 615}
610 616
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c
index cd354eee4..064294234 100644
--- a/src/gns/gnunet-gns-import.c
+++ b/src/gns/gnunet-gns-import.c
@@ -67,7 +67,8 @@ static char *private_zone_pkey;
67/** 67/**
68 * String version of PKEY for pin-zone. 68 * String version of PKEY for pin-zone.
69 */ 69 */
70static char *pin_zone_pkey = "72QC35CO20UJN1E91KPJFNT9TG4CLKAPB4VK9S3Q758S9MLBRKOG"; 70static char *pin_zone_pkey =
71 "72QC35CO20UJN1E91KPJFNT9TG4CLKAPB4VK9S3Q758S9MLBRKOG";
71 72
72/** 73/**
73 * Set to GNUNET_YES if private record was found; 74 * Set to GNUNET_YES if private record was found;
@@ -86,13 +87,13 @@ static int ret;
86 87
87 88
88static int 89static int
89run_process_and_wait(int pipe_control, 90run_process_and_wait (int pipe_control,
90 enum GNUNET_OS_InheritStdioFlags std_inheritance, 91 enum GNUNET_OS_InheritStdioFlags std_inheritance,
91 struct GNUNET_DISK_PipeHandle *pipe_stdin, 92 struct GNUNET_DISK_PipeHandle *pipe_stdin,
92 struct GNUNET_DISK_PipeHandle *pipe_stdout, 93 struct GNUNET_DISK_PipeHandle *pipe_stdout,
93 enum GNUNET_OS_ProcessStatusType *st, 94 enum GNUNET_OS_ProcessStatusType *st,
94 unsigned long *code, 95 unsigned long *code,
95 const char *filename, ...) 96 const char *filename, ...)
96{ 97{
97 static struct GNUNET_OS_Process *p; 98 static struct GNUNET_OS_Process *p;
98 int arglen; 99 int arglen;
@@ -101,88 +102,88 @@ run_process_and_wait(int pipe_control,
101 char *argp; 102 char *argp;
102 va_list ap, apc1, apc2; 103 va_list ap, apc1, apc2;
103 104
104 va_start(ap, filename); 105 va_start (ap, filename);
105 va_copy(apc1, ap); 106 va_copy (apc1, ap);
106 va_copy(apc2, ap); 107 va_copy (apc2, ap);
107 arglen = 0; 108 arglen = 0;
108 while (NULL != (arg = va_arg(apc1, char *))) 109 while (NULL != (arg = va_arg (apc1, char *)))
109 arglen += strlen(arg) + 1; 110 arglen += strlen (arg) + 1;
110 va_end(apc1); 111 va_end (apc1);
111 args = argp = GNUNET_malloc(arglen); 112 args = argp = GNUNET_malloc (arglen);
112 while (NULL != (arg = va_arg(apc2, char *))) 113 while (NULL != (arg = va_arg (apc2, char *)))
113 { 114 {
114 strcpy(argp, arg); 115 strcpy (argp, arg);
115 argp += strlen(arg); 116 argp += strlen (arg);
116 *argp = ' '; 117 *argp = ' ';
117 argp += 1; 118 argp += 1;
118 } 119 }
119 va_end(apc2); 120 va_end (apc2);
120 if (arglen > 0) 121 if (arglen > 0)
121 argp[-1] = '\0'; 122 argp[-1] = '\0';
122 p = GNUNET_OS_start_process_va(pipe_control, std_inheritance, 123 p = GNUNET_OS_start_process_va (pipe_control, std_inheritance,
123 pipe_stdin, 124 pipe_stdin,
124 pipe_stdout, 125 pipe_stdout,
125 NULL, 126 NULL,
126 filename, ap); 127 filename, ap);
127 va_end(ap); 128 va_end (ap);
128 if (NULL == p) 129 if (NULL == p)
129 { 130 {
130 ret = 3; 131 ret = 3;
131 fprintf(stderr, "Failed to run `%s'\n", args); 132 fprintf (stderr, "Failed to run `%s'\n", args);
132 GNUNET_free(args); 133 GNUNET_free (args);
133 return 1; 134 return 1;
134 } 135 }
135 136
136 if (GNUNET_OK != GNUNET_OS_process_wait(p)) 137 if (GNUNET_OK != GNUNET_OS_process_wait (p))
137 { 138 {
138 ret = 4; 139 ret = 4;
139 fprintf(stderr, "Failed to wait for `%s'\n", args); 140 fprintf (stderr, "Failed to wait for `%s'\n", args);
140 GNUNET_free(args); 141 GNUNET_free (args);
141 return 1; 142 return 1;
142 } 143 }
143 144
144 switch (GNUNET_OS_process_status(p, st, code)) 145 switch (GNUNET_OS_process_status (p, st, code))
145 { 146 {
146 case GNUNET_OK: 147 case GNUNET_OK:
147 break; 148 break;
148 149
149 case GNUNET_NO: 150 case GNUNET_NO:
150 ret = 5; 151 ret = 5;
151 fprintf(stderr, "`%s' is still running\n", args); 152 fprintf (stderr, "`%s' is still running\n", args);
152 GNUNET_free(args); 153 GNUNET_free (args);
153 return 1; 154 return 1;
154 155
155 default: 156 default:
156 case GNUNET_SYSERR: 157 case GNUNET_SYSERR:
157 ret = 6; 158 ret = 6;
158 fprintf(stderr, "Failed to check the status of `%s'\n", args); 159 fprintf (stderr, "Failed to check the status of `%s'\n", args);
159 GNUNET_free(args); 160 GNUNET_free (args);
160 return 1; 161 return 1;
161 } 162 }
162 return 0; 163 return 0;
163} 164}
164 165
165static void 166static void
166check_pkey(unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, 167check_pkey (unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd,
167 char *pk, int *found_rec) 168 char *pk, int *found_rec)
168{ 169{
169 int i; 170 int i;
170 171
171 for (i = 0; i < rd_len; i++) 172 for (i = 0; i < rd_len; i++)
172 { 173 {
173 char *s; 174 char *s;
174 if (GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type || 175 if ((GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type) ||
175 rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) 176 (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
176 continue; 177 continue;
177 s = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, 178 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
178 rd[i].data, 179 rd[i].data,
179 rd[i].data_size); 180 rd[i].data_size);
180 if (NULL == s) 181 if (NULL == s)
181 continue; 182 continue;
182 if (0 == strcmp(s, pk)) 183 if (0 == strcmp (s, pk))
183 *found_rec = GNUNET_YES; 184 *found_rec = GNUNET_YES;
184 GNUNET_free(s); 185 GNUNET_free (s);
185 } 186 }
186} 187}
187 188
188/** 189/**
@@ -195,54 +196,62 @@ check_pkey(unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd,
195 * @param rd array of records with data to store 196 * @param rd array of records with data to store
196 */ 197 */
197static void 198static void
198zone_iterator(void *cls, 199zone_iterator (void *cls,
199 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 200 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
200 const char *rname, unsigned int rd_len, 201 const char *rname, unsigned int rd_len,
201 const struct GNUNET_GNSRECORD_Data *rd) 202 const struct GNUNET_GNSRECORD_Data *rd)
202{ 203{
203 if (NULL != rname) 204 if (NULL != rname)
204 { 205 {
205 if (0 == strcmp(rname, "private")) 206 if (0 == strcmp (rname, "private"))
206 check_pkey(rd_len, rd, private_zone_pkey, &found_private_rec); 207 check_pkey (rd_len, rd, private_zone_pkey, &found_private_rec);
207 else if (0 == strcmp(rname, "pin")) 208 else if (0 == strcmp (rname, "pin"))
208 check_pkey(rd_len, rd, pin_zone_pkey, &found_pin_rec); 209 check_pkey (rd_len, rd, pin_zone_pkey, &found_pin_rec);
209 } 210 }
210 GNUNET_NAMESTORE_zone_iterator_next(list_it); 211 GNUNET_NAMESTORE_zone_iterator_next (list_it);
211} 212}
212 213
213static void 214static void
214zone_iteration_error(void *cls) 215zone_iteration_error (void *cls)
215{ 216{
216 enum GNUNET_OS_ProcessStatusType st; 217 enum GNUNET_OS_ProcessStatusType st;
217 unsigned long code; 218 unsigned long code;
218 219
219 if (!found_private_rec) 220 if (! found_private_rec)
221 {
222 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
223 NULL, NULL, &st, &code,
224 "gnunet-namestore",
225 "gnunet-namestore", "-z", "master-zone",
226 "-a", "-e", "never", "-n", "private", "-p",
227 "-t", "PKEY", "-V",
228 private_zone_pkey, NULL))
220 { 229 {
221 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 230 ret = 8;
222 "gnunet-namestore", 231 return;
223 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "private", "-p", "-t", "PKEY", "-V", private_zone_pkey, NULL))
224 {
225 ret = 8;
226 return;
227 }
228 } 232 }
229 if (!found_pin_rec) 233 }
234 if (! found_pin_rec)
235 {
236 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
237 NULL, NULL, &st, &code,
238 "gnunet-namestore",
239 "gnunet-namestore", "-z", "master-zone",
240 "-a", "-e", "never", "-n", "pin", "-p", "-t",
241 "PKEY", "-V", pin_zone_pkey,
242 NULL))
230 { 243 {
231 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 244 ret = 10;
232 "gnunet-namestore", 245 return;
233 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "pin", "-p", "-t", "PKEY", "-V", pin_zone_pkey, NULL))
234 {
235 ret = 10;
236 return;
237 }
238 } 246 }
247 }
239 list_it = NULL; 248 list_it = NULL;
240 GNUNET_SCHEDULER_shutdown(); 249 GNUNET_SCHEDULER_shutdown ();
241} 250}
242 251
243 252
244static void 253static void
245zone_iteration_finished(void *cls) 254zone_iteration_finished (void *cls)
246{ 255{
247} 256}
248 257
@@ -281,42 +290,47 @@ zone_iteration_finished(void *cls)
281 * must thus no longer be used 290 * must thus no longer be used
282 */ 291 */
283static void 292static void
284get_ego(void *cls, 293get_ego (void *cls,
285 struct GNUNET_IDENTITY_Ego *ego, 294 struct GNUNET_IDENTITY_Ego *ego,
286 void **ctx, 295 void **ctx,
287 const char *identifier) 296 const char *identifier)
288{ 297{
289 static struct GNUNET_CRYPTO_EcdsaPublicKey pk; 298 static struct GNUNET_CRYPTO_EcdsaPublicKey pk;
290 299
291 if (NULL == ego) 300 if (NULL == ego)
301 {
302 if ((NULL == master_zone_pkey) ||
303 (NULL == private_zone_pkey) )
292 { 304 {
293 if (NULL == master_zone_pkey || 305 ret = 11;
294 NULL == private_zone_pkey) 306 GNUNET_SCHEDULER_shutdown ();
295 {
296 ret = 11;
297 GNUNET_SCHEDULER_shutdown();
298 return;
299 }
300 list_it = GNUNET_NAMESTORE_zone_iteration_start(ns,
301 &master_pk, &zone_iteration_error, NULL, &zone_iterator, NULL, &zone_iteration_finished, NULL);
302 if (NULL == list_it)
303 {
304 ret = 12;
305 GNUNET_SCHEDULER_shutdown();
306 }
307 return; 307 return;
308 } 308 }
309 GNUNET_IDENTITY_ego_get_public_key(ego, &pk); 309 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
310 &master_pk,
311 &zone_iteration_error,
312 NULL, &zone_iterator, NULL,
313 &zone_iteration_finished,
314 NULL);
315 if (NULL == list_it)
316 {
317 ret = 12;
318 GNUNET_SCHEDULER_shutdown ();
319 }
320 return;
321 }
322 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
310 if (NULL != identifier) 323 if (NULL != identifier)
324 {
325 if ((NULL == master_zone_pkey) &&(0 == strcmp ("master-zone", identifier)) )
311 { 326 {
312 if (NULL == master_zone_pkey && 0 == strcmp("master-zone", identifier)) 327 master_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
313 { 328 master_pk = *GNUNET_IDENTITY_ego_get_private_key (ego);
314 master_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk);
315 master_pk = *GNUNET_IDENTITY_ego_get_private_key(ego);
316 }
317 else if (NULL == private_zone_pkey && 0 == strcmp("private-zone", identifier))
318 private_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk);
319 } 329 }
330 else if ((NULL == private_zone_pkey) &&(0 == strcmp ("private-zone",
331 identifier)) )
332 private_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
333 }
320} 334}
321 335
322/** 336/**
@@ -325,27 +339,27 @@ get_ego(void *cls,
325 * @param cls NULL 339 * @param cls NULL
326 */ 340 */
327static void 341static void
328shutdown_task(void *cls) 342shutdown_task (void *cls)
329{ 343{
330 GNUNET_free_non_null(master_zone_pkey); 344 GNUNET_free_non_null (master_zone_pkey);
331 master_zone_pkey = NULL; 345 master_zone_pkey = NULL;
332 GNUNET_free_non_null(private_zone_pkey); 346 GNUNET_free_non_null (private_zone_pkey);
333 private_zone_pkey = NULL; 347 private_zone_pkey = NULL;
334 if (NULL != list_it) 348 if (NULL != list_it)
335 { 349 {
336 GNUNET_NAMESTORE_zone_iteration_stop(list_it); 350 GNUNET_NAMESTORE_zone_iteration_stop (list_it);
337 list_it = NULL; 351 list_it = NULL;
338 } 352 }
339 if (NULL != ns) 353 if (NULL != ns)
340 { 354 {
341 GNUNET_NAMESTORE_disconnect(ns); 355 GNUNET_NAMESTORE_disconnect (ns);
342 ns = NULL; 356 ns = NULL;
343 } 357 }
344 if (NULL != sh) 358 if (NULL != sh)
345 { 359 {
346 GNUNET_IDENTITY_disconnect(sh); 360 GNUNET_IDENTITY_disconnect (sh);
347 sh = NULL; 361 sh = NULL;
348 } 362 }
349} 363}
350 364
351/** 365/**
@@ -357,71 +371,87 @@ shutdown_task(void *cls)
357 * @param c configuration 371 * @param c configuration
358 */ 372 */
359static void 373static void
360run(void *cls, char *const *args, const char *cfgfile, 374run (void *cls, char *const *args, const char *cfgfile,
361 const struct GNUNET_CONFIGURATION_Handle *c) 375 const struct GNUNET_CONFIGURATION_Handle *c)
362{ 376{
363 enum GNUNET_OS_ProcessStatusType st; 377 enum GNUNET_OS_ProcessStatusType st;
364 unsigned long code; 378 unsigned long code;
365 379
366 cfg = c; 380 cfg = c;
367 381
368 if (0 != run_process_and_wait(GNUNET_NO, 0, NULL, NULL, &st, &code, 382 if (0 != run_process_and_wait (GNUNET_NO, 0, NULL, NULL, &st, &code,
369 "gnunet-arm", 383 "gnunet-arm",
370 "gnunet-arm", "-I", NULL)) 384 "gnunet-arm", "-I", NULL))
371 { 385 {
372 if (7 == ret) 386 if (7 == ret)
373 fprintf(stderr, "GNUnet is not running, please start GNUnet before running import\n"); 387 fprintf (stderr,
374 return; 388 "GNUnet is not running, please start GNUnet before running import\n");
375 } 389 return;
390 }
376 391
377 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 392 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
378 "gnunet-identity", 393 NULL, NULL, &st, &code,
379 "gnunet-identity", "-C", "master-zone", NULL)) 394 "gnunet-identity",
395 "gnunet-identity", "-C", "master-zone", NULL))
380 return; 396 return;
381 397
382 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 398 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
383 "gnunet-identity", 399 NULL, NULL, &st, &code,
384 "gnunet-identity", "-C", "private-zone", NULL)) 400 "gnunet-identity",
401 "gnunet-identity", "-C", "private-zone", NULL))
385 return; 402 return;
386 403
387 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 404 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
388 "gnunet-identity", 405 NULL, NULL, &st, &code,
389 "gnunet-identity", "-C", "sks-zone", NULL)) 406 "gnunet-identity",
407 "gnunet-identity", "-C", "sks-zone", NULL))
390 return; 408 return;
391 409
392 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 410 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
393 "gnunet-identity", 411 NULL, NULL, &st, &code,
394 "gnunet-identity", "-e", "master-zone", "-s", "gns-master", NULL)) 412 "gnunet-identity",
413 "gnunet-identity", "-e", "master-zone", "-s",
414 "gns-master", NULL))
395 return; 415 return;
396 416
397 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 417 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
398 "gnunet-identity", 418 NULL, NULL, &st, &code,
399 "gnunet-identity", "-e", "master-zone", "-s", "namestore", NULL)) 419 "gnunet-identity",
420 "gnunet-identity", "-e", "master-zone", "-s",
421 "namestore", NULL))
400 return; 422 return;
401 423
402 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 424 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
403 "gnunet-identity", 425 NULL, NULL, &st, &code,
404 "gnunet-identity", "-e", "master-zone", "-s", "gns-proxy", NULL)) 426 "gnunet-identity",
427 "gnunet-identity", "-e", "master-zone", "-s",
428 "gns-proxy", NULL))
405 return; 429 return;
406 430
407 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 431 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
408 "gnunet-identity", 432 NULL, NULL, &st, &code,
409 "gnunet-identity", "-e", "master-zone", "-s", "gns-intercept", NULL)) 433 "gnunet-identity",
434 "gnunet-identity", "-e", "master-zone", "-s",
435 "gns-intercept", NULL))
410 return; 436 return;
411 437
412 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 438 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
413 "gnunet-identity", 439 NULL, NULL, &st, &code,
414 "gnunet-identity", "-e", "private-zone", "-s", "gns-private", NULL)) 440 "gnunet-identity",
441 "gnunet-identity", "-e", "private-zone", "-s",
442 "gns-private", NULL))
415 return; 443 return;
416 444
417 if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 445 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
418 "gnunet-identity", 446 NULL, NULL, &st, &code,
419 "gnunet-identity", "-e", "sks-zone", "-s", "fs-sks", NULL)) 447 "gnunet-identity",
448 "gnunet-identity", "-e", "sks-zone", "-s",
449 "fs-sks", NULL))
420 return; 450 return;
421 451
422 ns = GNUNET_NAMESTORE_connect(cfg); 452 ns = GNUNET_NAMESTORE_connect (cfg);
423 sh = GNUNET_IDENTITY_connect(cfg, &get_ego, NULL); 453 sh = GNUNET_IDENTITY_connect (cfg, &get_ego, NULL);
424 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 454 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
425} 455}
426 456
427 457
@@ -433,23 +463,24 @@ run(void *cls, char *const *args, const char *cfgfile,
433 * @return 0 ok, 1 on error 463 * @return 0 ok, 1 on error
434 */ 464 */
435int 465int
436main(int argc, char *const *argv) 466main (int argc, char *const *argv)
437{ 467{
438 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 468 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
439 GNUNET_GETOPT_OPTION_END 469 GNUNET_GETOPT_OPTION_END
440 }; 470 };
441 int r; 471 int r;
442 472
443 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 473 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
444 return 2; 474 return 2;
445 475
446 GNUNET_log_setup("gnunet-gns-import", "WARNING", NULL); 476 GNUNET_log_setup ("gnunet-gns-import", "WARNING", NULL);
447 ret = 0; 477 ret = 0;
448 r = GNUNET_PROGRAM_run(argc, argv, "gnunet-gns-import", 478 r = GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-import",
449 _("This program will import some GNS authorities into your GNS namestore."), 479 _ (
450 options, 480 "This program will import some GNS authorities into your GNS namestore."),
451 &run, NULL); 481 options,
452 GNUNET_free((void*)argv); 482 &run, NULL);
483 GNUNET_free ((void*) argv);
453 return GNUNET_OK == r ? ret : 1; 484 return GNUNET_OK == r ? ret : 1;
454} 485}
455 486
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 6285a8fcd..2a39efef2 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -94,13 +94,15 @@
94/** 94/**
95 * After how long do we clean up unused MHD TLS instances? 95 * After how long do we clean up unused MHD TLS instances?
96 */ 96 */
97#define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) 97#define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply ( \
98 GNUNET_TIME_UNIT_MINUTES, 5)
98 99
99/** 100/**
100 * After how long do we clean up Socks5 handles that failed to show any activity 101 * After how long do we clean up Socks5 handles that failed to show any activity
101 * with their respective MHD instance? 102 * with their respective MHD instance?
102 */ 103 */
103#define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 104#define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply ( \
105 GNUNET_TIME_UNIT_SECONDS, 15)
104 106
105 107
106/** 108/**
@@ -111,12 +113,12 @@
111 * @param rc return code from curl 113 * @param rc return code from curl
112 */ 114 */
113#define LOG_CURL_EASY(level, fun, rc) \ 115#define LOG_CURL_EASY(level, fun, rc) \
114 GNUNET_log(level, \ 116 GNUNET_log (level, \
115 _("%s failed at %s:%d: `%s'\n"), \ 117 _ ("%s failed at %s:%d: `%s'\n"), \
116 fun, \ 118 fun, \
117 __FILE__, \ 119 __FILE__, \
118 __LINE__, \ 120 __LINE__, \
119 curl_easy_strerror(rc)) 121 curl_easy_strerror (rc))
120 122
121 123
122/* *************** Socks protocol definitions (move to TUN?) ****************** */ 124/* *************** Socks protocol definitions (move to TUN?) ****************** */
@@ -135,7 +137,8 @@
135/** 137/**
136 * Commands in Socks5. 138 * Commands in Socks5.
137 */ 139 */
138enum Socks5Commands { 140enum Socks5Commands
141{
139 /** 142 /**
140 * Establish TCP/IP stream. 143 * Establish TCP/IP stream.
141 */ 144 */
@@ -156,7 +159,8 @@ enum Socks5Commands {
156/** 159/**
157 * Address types in Socks5. 160 * Address types in Socks5.
158 */ 161 */
159enum Socks5AddressType { 162enum Socks5AddressType
163{
160 /** 164 /**
161 * IPv4 address. 165 * IPv4 address.
162 */ 166 */
@@ -177,7 +181,8 @@ enum Socks5AddressType {
177/** 181/**
178 * Status codes in Socks5 response. 182 * Status codes in Socks5 response.
179 */ 183 */
180enum Socks5StatusCode { 184enum Socks5StatusCode
185{
181 SOCKS5_STATUS_REQUEST_GRANTED = 0, 186 SOCKS5_STATUS_REQUEST_GRANTED = 0,
182 SOCKS5_STATUS_GENERAL_FAILURE = 1, 187 SOCKS5_STATUS_GENERAL_FAILURE = 1,
183 SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE = 2, 188 SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE = 2,
@@ -193,7 +198,8 @@ enum Socks5StatusCode {
193/** 198/**
194 * Client hello in Socks5 protocol. 199 * Client hello in Socks5 protocol.
195 */ 200 */
196struct Socks5ClientHelloMessage { 201struct Socks5ClientHelloMessage
202{
197 /** 203 /**
198 * Should be #SOCKS_VERSION_5. 204 * Should be #SOCKS_VERSION_5.
199 */ 205 */
@@ -211,7 +217,8 @@ struct Socks5ClientHelloMessage {
211/** 217/**
212 * Server hello in Socks5 protocol. 218 * Server hello in Socks5 protocol.
213 */ 219 */
214struct Socks5ServerHelloMessage { 220struct Socks5ServerHelloMessage
221{
215 /** 222 /**
216 * Should be #SOCKS_VERSION_5. 223 * Should be #SOCKS_VERSION_5.
217 */ 224 */
@@ -228,7 +235,8 @@ struct Socks5ServerHelloMessage {
228/** 235/**
229 * Client socks request in Socks5 protocol. 236 * Client socks request in Socks5 protocol.
230 */ 237 */
231struct Socks5ClientRequestMessage { 238struct Socks5ClientRequestMessage
239{
232 /** 240 /**
233 * Should be #SOCKS_VERSION_5. 241 * Should be #SOCKS_VERSION_5.
234 */ 242 */
@@ -260,7 +268,8 @@ struct Socks5ClientRequestMessage {
260/** 268/**
261 * Server response to client requests in Socks5 protocol. 269 * Server response to client requests in Socks5 protocol.
262 */ 270 */
263struct Socks5ServerResponseMessage { 271struct Socks5ServerResponseMessage
272{
264 /** 273 /**
265 * Should be #SOCKS_VERSION_5. 274 * Should be #SOCKS_VERSION_5.
266 */ 275 */
@@ -295,7 +304,8 @@ struct Socks5ServerResponseMessage {
295/** 304/**
296 * A structure for CA cert/key 305 * A structure for CA cert/key
297 */ 306 */
298struct ProxyCA { 307struct ProxyCA
308{
299 /** 309 /**
300 * The certificate 310 * The certificate
301 */ 311 */
@@ -311,7 +321,8 @@ struct ProxyCA {
311/** 321/**
312 * Structure for GNS certificates 322 * Structure for GNS certificates
313 */ 323 */
314struct ProxyGNSCertificate { 324struct ProxyGNSCertificate
325{
315 /** 326 /**
316 * The certificate as PEM 327 * The certificate as PEM
317 */ 328 */
@@ -328,7 +339,8 @@ struct ProxyGNSCertificate {
328/** 339/**
329 * A structure for all running Httpds 340 * A structure for all running Httpds
330 */ 341 */
331struct MhdHttpList { 342struct MhdHttpList
343{
332 /** 344 /**
333 * DLL for httpds 345 * DLL for httpds
334 */ 346 */
@@ -372,7 +384,8 @@ struct MhdHttpList {
372/** 384/**
373 * The socks phases. 385 * The socks phases.
374 */ 386 */
375enum SocksPhase { 387enum SocksPhase
388{
376 /** 389 /**
377 * We're waiting to get the client hello. 390 * We're waiting to get the client hello.
378 */ 391 */
@@ -428,7 +441,8 @@ enum SocksPhase {
428/** 441/**
429 * A header list 442 * A header list
430 */ 443 */
431struct HttpResponseHeader { 444struct HttpResponseHeader
445{
432 /** 446 /**
433 * DLL 447 * DLL
434 */ 448 */
@@ -453,7 +467,8 @@ struct HttpResponseHeader {
453/** 467/**
454 * A structure for socks requests 468 * A structure for socks requests
455 */ 469 */
456struct Socks5Request { 470struct Socks5Request
471{
457 /** 472 /**
458 * DLL. 473 * DLL.
459 */ 474 */
@@ -673,17 +688,17 @@ static struct GNUNET_NETWORK_Handle *lsock6;
673/** 688/**
674 * The listen task ID for IPv4 689 * The listen task ID for IPv4
675 */ 690 */
676static struct GNUNET_SCHEDULER_Task * ltask4; 691static struct GNUNET_SCHEDULER_Task *ltask4;
677 692
678/** 693/**
679 * The listen task ID for IPv6 694 * The listen task ID for IPv6
680 */ 695 */
681static struct GNUNET_SCHEDULER_Task * ltask6; 696static struct GNUNET_SCHEDULER_Task *ltask6;
682 697
683/** 698/**
684 * The cURL download task (curl multi API). 699 * The cURL download task (curl multi API).
685 */ 700 */
686static struct GNUNET_SCHEDULER_Task * curl_download_task; 701static struct GNUNET_SCHEDULER_Task *curl_download_task;
687 702
688/** 703/**
689 * The cURL multi handle 704 * The cURL multi handle
@@ -751,7 +766,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
751 * @param hd the daemon to run now. 766 * @param hd the daemon to run now.
752 */ 767 */
753static void 768static void
754run_mhd_now(struct MhdHttpList *hd); 769run_mhd_now (struct MhdHttpList *hd);
755 770
756 771
757/** 772/**
@@ -760,79 +775,79 @@ run_mhd_now(struct MhdHttpList *hd);
760 * @param s5r the handle to destroy 775 * @param s5r the handle to destroy
761 */ 776 */
762static void 777static void
763cleanup_s5r(struct Socks5Request *s5r) 778cleanup_s5r (struct Socks5Request *s5r)
764{ 779{
765 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
766 "Cleaning up socks request\n"); 781 "Cleaning up socks request\n");
767 if (NULL != s5r->curl) 782 if (NULL != s5r->curl)
768 { 783 {
769 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Cleaning up cURL handle\n"); 785 "Cleaning up cURL handle\n");
771 curl_multi_remove_handle(curl_multi, 786 curl_multi_remove_handle (curl_multi,
772 s5r->curl); 787 s5r->curl);
773 curl_easy_cleanup(s5r->curl); 788 curl_easy_cleanup (s5r->curl);
774 s5r->curl = NULL; 789 s5r->curl = NULL;
775 } 790 }
776 if (s5r->suspended) 791 if (s5r->suspended)
777 { 792 {
778 s5r->suspended = GNUNET_NO; 793 s5r->suspended = GNUNET_NO;
779 MHD_resume_connection(s5r->con); 794 MHD_resume_connection (s5r->con);
780 } 795 }
781 curl_slist_free_all(s5r->headers); 796 curl_slist_free_all (s5r->headers);
782 if (NULL != s5r->hosts) 797 if (NULL != s5r->hosts)
783 { 798 {
784 curl_slist_free_all(s5r->hosts); 799 curl_slist_free_all (s5r->hosts);
785 } 800 }
786 if ((NULL != s5r->response) && 801 if ((NULL != s5r->response) &&
787 (curl_failure_response != s5r->response)) 802 (curl_failure_response != s5r->response))
788 { 803 {
789 MHD_destroy_response(s5r->response); 804 MHD_destroy_response (s5r->response);
790 s5r->response = NULL; 805 s5r->response = NULL;
791 } 806 }
792 if (NULL != s5r->rtask) 807 if (NULL != s5r->rtask)
793 { 808 {
794 GNUNET_SCHEDULER_cancel(s5r->rtask); 809 GNUNET_SCHEDULER_cancel (s5r->rtask);
795 s5r->rtask = NULL; 810 s5r->rtask = NULL;
796 } 811 }
797 if (NULL != s5r->timeout_task) 812 if (NULL != s5r->timeout_task)
798 { 813 {
799 GNUNET_SCHEDULER_cancel(s5r->timeout_task); 814 GNUNET_SCHEDULER_cancel (s5r->timeout_task);
800 s5r->timeout_task = NULL; 815 s5r->timeout_task = NULL;
801 } 816 }
802 if (NULL != s5r->wtask) 817 if (NULL != s5r->wtask)
803 { 818 {
804 GNUNET_SCHEDULER_cancel(s5r->wtask); 819 GNUNET_SCHEDULER_cancel (s5r->wtask);
805 s5r->wtask = NULL; 820 s5r->wtask = NULL;
806 } 821 }
807 if (NULL != s5r->gns_lookup) 822 if (NULL != s5r->gns_lookup)
808 { 823 {
809 GNUNET_GNS_lookup_with_tld_cancel(s5r->gns_lookup); 824 GNUNET_GNS_lookup_with_tld_cancel (s5r->gns_lookup);
810 s5r->gns_lookup = NULL; 825 s5r->gns_lookup = NULL;
811 } 826 }
812 if (NULL != s5r->sock) 827 if (NULL != s5r->sock)
813 { 828 {
814 if (SOCKS5_SOCKET_WITH_MHD <= s5r->state) 829 if (SOCKS5_SOCKET_WITH_MHD <= s5r->state)
815 GNUNET_NETWORK_socket_free_memory_only_(s5r->sock); 830 GNUNET_NETWORK_socket_free_memory_only_ (s5r->sock);
816 else 831 else
817 GNUNET_NETWORK_socket_close(s5r->sock); 832 GNUNET_NETWORK_socket_close (s5r->sock);
818 s5r->sock = NULL; 833 s5r->sock = NULL;
819 } 834 }
820 GNUNET_CONTAINER_DLL_remove(s5r_head, 835 GNUNET_CONTAINER_DLL_remove (s5r_head,
821 s5r_tail, 836 s5r_tail,
822 s5r); 837 s5r);
823 GNUNET_free_non_null(s5r->domain); 838 GNUNET_free_non_null (s5r->domain);
824 GNUNET_free_non_null(s5r->leho); 839 GNUNET_free_non_null (s5r->leho);
825 GNUNET_free_non_null(s5r->url); 840 GNUNET_free_non_null (s5r->url);
826 for (unsigned int i = 0; i < s5r->num_danes; i++) 841 for (unsigned int i = 0; i < s5r->num_danes; i++)
827 GNUNET_free(s5r->dane_data[i]); 842 GNUNET_free (s5r->dane_data[i]);
828 GNUNET_free(s5r); 843 GNUNET_free (s5r);
829} 844}
830 845
831 846
832/* ************************* HTTP handling with cURL *********************** */ 847/* ************************* HTTP handling with cURL *********************** */
833 848
834static void 849static void
835curl_download_prepare(); 850curl_download_prepare ();
836 851
837 852
838/** 853/**
@@ -847,89 +862,89 @@ curl_download_prepare();
847 * @return number of bytes written to @a buf 862 * @return number of bytes written to @a buf
848 */ 863 */
849static ssize_t 864static ssize_t
850mhd_content_cb(void *cls, 865mhd_content_cb (void *cls,
851 uint64_t pos, 866 uint64_t pos,
852 char* buf, 867 char*buf,
853 size_t max) 868 size_t max)
854{ 869{
855 struct Socks5Request *s5r = cls; 870 struct Socks5Request *s5r = cls;
856 size_t bytes_to_copy; 871 size_t bytes_to_copy;
857 872
858 if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || 873 if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) ||
859 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) 874 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state))
860 { 875 {
861 /* we're still not done with the upload, do not yet 876 /* we're still not done with the upload, do not yet
862 start the download, the IO buffer is still full 877 start the download, the IO buffer is still full
863 with upload data. */ 878 with upload data. */
864 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
865 "Pausing MHD download %s%s, not yet ready for download\n", 880 "Pausing MHD download %s%s, not yet ready for download\n",
866 s5r->domain, 881 s5r->domain,
867 s5r->url); 882 s5r->url);
868 return 0; /* not yet ready for data download */ 883 return 0; /* not yet ready for data download */
869 } 884 }
870 bytes_to_copy = GNUNET_MIN(max, 885 bytes_to_copy = GNUNET_MIN (max,
871 s5r->io_len); 886 s5r->io_len);
872 if ((0 == bytes_to_copy) && 887 if ((0 == bytes_to_copy) &&
873 (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state)) 888 (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state))
889 {
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 "Pausing MHD download %s%s, no data available\n",
892 s5r->domain,
893 s5r->url);
894 if (NULL != s5r->curl)
895 {
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
897 "Continuing CURL interaction for %s%s\n",
898 s5r->domain,
899 s5r->url);
900 if (GNUNET_YES == s5r->curl_paused)
901 {
902 s5r->curl_paused = GNUNET_NO;
903 curl_easy_pause (s5r->curl,
904 CURLPAUSE_CONT);
905 }
906 curl_download_prepare ();
907 }
908 if (GNUNET_NO == s5r->suspended)
874 { 909 {
875 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 910 MHD_suspend_connection (s5r->con);
876 "Pausing MHD download %s%s, no data available\n", 911 s5r->suspended = GNUNET_YES;
877 s5r->domain,
878 s5r->url);
879 if (NULL != s5r->curl)
880 {
881 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
882 "Continuing CURL interaction for %s%s\n",
883 s5r->domain,
884 s5r->url);
885 if (GNUNET_YES == s5r->curl_paused)
886 {
887 s5r->curl_paused = GNUNET_NO;
888 curl_easy_pause(s5r->curl,
889 CURLPAUSE_CONT);
890 }
891 curl_download_prepare();
892 }
893 if (GNUNET_NO == s5r->suspended)
894 {
895 MHD_suspend_connection(s5r->con);
896 s5r->suspended = GNUNET_YES;
897 }
898 return 0; /* more data later */
899 } 912 }
913 return 0; /* more data later */
914 }
900 if ((0 == bytes_to_copy) && 915 if ((0 == bytes_to_copy) &&
901 (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state)) 916 (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state))
902 { 917 {
903 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
904 "Completed MHD download %s%s\n", 919 "Completed MHD download %s%s\n",
905 s5r->domain, 920 s5r->domain,
906 s5r->url); 921 s5r->url);
907 return MHD_CONTENT_READER_END_OF_STREAM; 922 return MHD_CONTENT_READER_END_OF_STREAM;
908 } 923 }
909 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
910 "Writing %llu/%llu bytes to %s%s\n", 925 "Writing %llu/%llu bytes to %s%s\n",
911 (unsigned long long)bytes_to_copy, 926 (unsigned long long) bytes_to_copy,
912 (unsigned long long)s5r->io_len, 927 (unsigned long long) s5r->io_len,
913 s5r->domain, 928 s5r->domain,
914 s5r->url); 929 s5r->url);
915 GNUNET_memcpy(buf, 930 GNUNET_memcpy (buf,
916 s5r->io_buf, 931 s5r->io_buf,
917 bytes_to_copy); 932 bytes_to_copy);
918 memmove(s5r->io_buf, 933 memmove (s5r->io_buf,
919 &s5r->io_buf[bytes_to_copy], 934 &s5r->io_buf[bytes_to_copy],
920 s5r->io_len - bytes_to_copy); 935 s5r->io_len - bytes_to_copy);
921 s5r->io_len -= bytes_to_copy; 936 s5r->io_len -= bytes_to_copy;
922 if ((NULL != s5r->curl) && 937 if ((NULL != s5r->curl) &&
923 (GNUNET_YES == s5r->curl_paused)) 938 (GNUNET_YES == s5r->curl_paused))
924 { 939 {
925 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "Continuing CURL interaction for %s%s\n", 941 "Continuing CURL interaction for %s%s\n",
927 s5r->domain, 942 s5r->domain,
928 s5r->url); 943 s5r->url);
929 s5r->curl_paused = GNUNET_NO; 944 s5r->curl_paused = GNUNET_NO;
930 curl_easy_pause(s5r->curl, 945 curl_easy_pause (s5r->curl,
931 CURLPAUSE_CONT); 946 CURLPAUSE_CONT);
932 } 947 }
933 return bytes_to_copy; 948 return bytes_to_copy;
934} 949}
935 950
@@ -943,7 +958,7 @@ mhd_content_cb(void *cls,
943 * @return #GNUNET_OK if the certificate is valid 958 * @return #GNUNET_OK if the certificate is valid
944 */ 959 */
945static int 960static int
946check_ssl_certificate(struct Socks5Request *s5r) 961check_ssl_certificate (struct Socks5Request *s5r)
947{ 962{
948 unsigned int cert_list_size; 963 unsigned int cert_list_size;
949 const gnutls_datum_t *chainp; 964 const gnutls_datum_t *chainp;
@@ -955,113 +970,115 @@ check_ssl_certificate(struct Socks5Request *s5r)
955 const char *name; 970 const char *name;
956 971
957 s5r->ssl_checked = GNUNET_YES; 972 s5r->ssl_checked = GNUNET_YES;
958 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "Checking X.509 certificate\n"); 974 "Checking X.509 certificate\n");
960 if (CURLE_OK != 975 if (CURLE_OK !=
961 curl_easy_getinfo(s5r->curl, 976 curl_easy_getinfo (s5r->curl,
962 CURLINFO_TLS_SESSION, 977 CURLINFO_TLS_SESSION,
963 &tlsinfo)) 978 &tlsinfo))
964 return GNUNET_SYSERR; 979 return GNUNET_SYSERR;
965 if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend) 980 if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend)
966 { 981 {
967 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 982 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
968 _("Unsupported CURL TLS backend %d\n"), 983 _ ("Unsupported CURL TLS backend %d\n"),
969 tlsinfo->backend); 984 tlsinfo->backend);
970 return GNUNET_SYSERR; 985 return GNUNET_SYSERR;
971 } 986 }
972 chainp = gnutls_certificate_get_peers(tlsinfo->internals, 987 chainp = gnutls_certificate_get_peers (tlsinfo->internals,
973 &cert_list_size); 988 &cert_list_size);
974 if ((!chainp) || 989 if ((! chainp) ||
975 (0 == cert_list_size)) 990 (0 == cert_list_size))
976 return GNUNET_SYSERR; 991 return GNUNET_SYSERR;
977 992
978 size = sizeof(certdn); 993 size = sizeof(certdn);
979 /* initialize an X.509 certificate structure. */ 994 /* initialize an X.509 certificate structure. */
980 gnutls_x509_crt_init(&x509_cert); 995 gnutls_x509_crt_init (&x509_cert);
981 gnutls_x509_crt_import(x509_cert, 996 gnutls_x509_crt_import (x509_cert,
982 chainp, 997 chainp,
983 GNUTLS_X509_FMT_DER); 998 GNUTLS_X509_FMT_DER);
984 999
985 if (0 != (rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, 1000 if (0 != (rc = gnutls_x509_crt_get_dn_by_oid (x509_cert,
986 GNUTLS_OID_X520_COMMON_NAME, 1001 GNUTLS_OID_X520_COMMON_NAME,
987 0, /* the first and only one */ 1002 0, /* the first and only one */
988 0 /* no DER encoding */, 1003 0 /* no DER encoding */,
989 certdn, 1004 certdn,
990 &size))) 1005 &size)))
991 { 1006 {
992 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1007 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
993 _("Failed to fetch CN from cert: %s\n"), 1008 _ ("Failed to fetch CN from cert: %s\n"),
994 gnutls_strerror(rc)); 1009 gnutls_strerror (rc));
995 gnutls_x509_crt_deinit(x509_cert); 1010 gnutls_x509_crt_deinit (x509_cert);
996 return GNUNET_SYSERR; 1011 return GNUNET_SYSERR;
997 } 1012 }
998 /* check for TLSA/DANE records */ 1013 /* check for TLSA/DANE records */
999#if HAVE_GNUTLS_DANE 1014#if HAVE_GNUTLS_DANE
1000 if (0 != s5r->num_danes) 1015 if (0 != s5r->num_danes)
1001 { 1016 {
1002 dane_state_t dane_state; 1017 dane_state_t dane_state;
1003 dane_query_t dane_query; 1018 dane_query_t dane_query;
1004 unsigned int verify; 1019 unsigned int verify;
1005 1020
1006 /* FIXME: add flags to gnutls to NOT read UNBOUND_ROOT_KEY_FILE here! */ 1021 /* FIXME: add flags to gnutls to NOT read UNBOUND_ROOT_KEY_FILE here! */
1007 if (0 != (rc = dane_state_init(&dane_state, 1022 if (0 != (rc = dane_state_init (&dane_state,
1008#ifdef DANE_F_IGNORE_DNSSEC 1023#ifdef DANE_F_IGNORE_DNSSEC
1009 DANE_F_IGNORE_DNSSEC | 1024 DANE_F_IGNORE_DNSSEC |
1010#endif 1025#endif
1011 DANE_F_IGNORE_LOCAL_RESOLVER))) 1026 DANE_F_IGNORE_LOCAL_RESOLVER)))
1012 { 1027 {
1013 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1028 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1014 _("Failed to initialize DANE: %s\n"), 1029 _ ("Failed to initialize DANE: %s\n"),
1015 dane_strerror(rc)); 1030 dane_strerror (rc));
1016 gnutls_x509_crt_deinit(x509_cert); 1031 gnutls_x509_crt_deinit (x509_cert);
1017 return GNUNET_SYSERR; 1032 return GNUNET_SYSERR;
1018 } 1033 }
1019 s5r->dane_data[s5r->num_danes] = NULL; 1034 s5r->dane_data[s5r->num_danes] = NULL;
1020 s5r->dane_data_len[s5r->num_danes] = 0; 1035 s5r->dane_data_len[s5r->num_danes] = 0;
1021 if (0 != (rc = dane_raw_tlsa(dane_state, 1036 if (0 != (rc = dane_raw_tlsa (dane_state,
1022 &dane_query, 1037 &dane_query,
1023 s5r->dane_data, 1038 s5r->dane_data,
1024 s5r->dane_data_len, 1039 s5r->dane_data_len,
1025 GNUNET_YES, 1040 GNUNET_YES,
1026 GNUNET_NO))) 1041 GNUNET_NO)))
1027 { 1042 {
1028 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1029 _("Failed to parse DANE record: %s\n"), 1044 _ ("Failed to parse DANE record: %s\n"),
1030 dane_strerror(rc)); 1045 dane_strerror (rc));
1031 dane_state_deinit(dane_state); 1046 dane_state_deinit (dane_state);
1032 gnutls_x509_crt_deinit(x509_cert); 1047 gnutls_x509_crt_deinit (x509_cert);
1033 return GNUNET_SYSERR; 1048 return GNUNET_SYSERR;
1034 } 1049 }
1035 if (0 != (rc = dane_verify_crt_raw(dane_state, 1050 if (0 != (rc = dane_verify_crt_raw (dane_state,
1036 chainp, 1051 chainp,
1037 cert_list_size, 1052 cert_list_size,
1038 gnutls_certificate_type_get(tlsinfo->internals), 1053 gnutls_certificate_type_get (
1039 dane_query, 1054 tlsinfo->internals),
1040 0, 0, 1055 dane_query,
1041 &verify))) 1056 0, 0,
1042 { 1057 &verify)))
1043 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1058 {
1044 _("Failed to verify TLS connection using DANE: %s\n"), 1059 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1045 dane_strerror(rc)); 1060 _ ("Failed to verify TLS connection using DANE: %s\n"),
1046 dane_query_deinit(dane_query); 1061 dane_strerror (rc));
1047 dane_state_deinit(dane_state); 1062 dane_query_deinit (dane_query);
1048 gnutls_x509_crt_deinit(x509_cert); 1063 dane_state_deinit (dane_state);
1049 return GNUNET_SYSERR; 1064 gnutls_x509_crt_deinit (x509_cert);
1050 } 1065 return GNUNET_SYSERR;
1051 if (0 != verify) 1066 }
1052 { 1067 if (0 != verify)
1053 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1068 {
1054 _("Failed DANE verification failed with GnuTLS verify status code: %u\n"), 1069 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1055 verify); 1070 _ (
1056 dane_query_deinit(dane_query); 1071 "Failed DANE verification failed with GnuTLS verify status code: %u\n"),
1057 dane_state_deinit(dane_state); 1072 verify);
1058 gnutls_x509_crt_deinit(x509_cert); 1073 dane_query_deinit (dane_query);
1059 return GNUNET_SYSERR; 1074 dane_state_deinit (dane_state);
1060 } 1075 gnutls_x509_crt_deinit (x509_cert);
1061 dane_query_deinit(dane_query); 1076 return GNUNET_SYSERR;
1062 dane_state_deinit(dane_state);
1063 /* success! */
1064 } 1077 }
1078 dane_query_deinit (dane_query);
1079 dane_state_deinit (dane_state);
1080 /* success! */
1081 }
1065 else 1082 else
1066#endif 1083#endif
1067 { 1084 {
@@ -1070,27 +1087,28 @@ check_ssl_certificate(struct Socks5Request *s5r)
1070 if (NULL != s5r->leho) 1087 if (NULL != s5r->leho)
1071 name = s5r->leho; 1088 name = s5r->leho;
1072 if (NULL != name) 1089 if (NULL != name)
1090 {
1091 if (0 == (rc = gnutls_x509_crt_check_hostname (x509_cert,
1092 name)))
1073 { 1093 {
1074 if (0 == (rc = gnutls_x509_crt_check_hostname(x509_cert, 1094 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1075 name))) 1095 _ (
1076 { 1096 "TLS certificate subject name (%s) does not match `%s': %d\n"),
1077 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1097 certdn,
1078 _("TLS certificate subject name (%s) does not match `%s': %d\n"), 1098 name,
1079 certdn, 1099 rc);
1080 name, 1100 gnutls_x509_crt_deinit (x509_cert);
1081 rc);
1082 gnutls_x509_crt_deinit(x509_cert);
1083 return GNUNET_SYSERR;
1084 }
1085 }
1086 else
1087 {
1088 /* we did not even have the domain name!? */
1089 GNUNET_break(0);
1090 return GNUNET_SYSERR; 1101 return GNUNET_SYSERR;
1091 } 1102 }
1103 }
1104 else
1105 {
1106 /* we did not even have the domain name!? */
1107 GNUNET_break (0);
1108 return GNUNET_SYSERR;
1109 }
1092 } 1110 }
1093 gnutls_x509_crt_deinit(x509_cert); 1111 gnutls_x509_crt_deinit (x509_cert);
1094 return GNUNET_OK; 1112 return GNUNET_OK;
1095} 1113}
1096 1114
@@ -1108,10 +1126,10 @@ check_ssl_certificate(struct Socks5Request *s5r)
1108 * @return size of processed bytes 1126 * @return size of processed bytes
1109 */ 1127 */
1110static size_t 1128static size_t
1111curl_check_hdr(void *buffer, 1129curl_check_hdr (void *buffer,
1112 size_t size, 1130 size_t size,
1113 size_t nmemb, 1131 size_t nmemb,
1114 void *cls) 1132 void *cls)
1115{ 1133{
1116 struct Socks5Request *s5r = cls; 1134 struct Socks5Request *s5r = cls;
1117 struct HttpResponseHeader *header; 1135 struct HttpResponseHeader *header;
@@ -1127,178 +1145,178 @@ curl_check_hdr(void *buffer,
1127 int domain_matched; 1145 int domain_matched;
1128 char *tok; 1146 char *tok;
1129 1147
1130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1131 "Receiving HTTP response header from CURL\n"); 1149 "Receiving HTTP response header from CURL\n");
1132 /* first, check TLS certificate */ 1150 /* first, check TLS certificate */
1133 if ((GNUNET_YES != s5r->ssl_checked) && 1151 if ((GNUNET_YES != s5r->ssl_checked) &&
1134 (GNUNET_YES == s5r->is_tls)) 1152 (GNUNET_YES == s5r->is_tls))
1135 //(HTTPS_PORT == s5r->port)) 1153 // (HTTPS_PORT == s5r->port))
1136 { 1154 {
1137 if (GNUNET_OK != check_ssl_certificate(s5r)) 1155 if (GNUNET_OK != check_ssl_certificate (s5r))
1138 return 0; 1156 return 0;
1139 } 1157 }
1140 ndup = GNUNET_strndup(buffer, 1158 ndup = GNUNET_strndup (buffer,
1141 bytes); 1159 bytes);
1142 hdr_type = strtok(ndup, 1160 hdr_type = strtok (ndup,
1143 ":"); 1161 ":");
1144 if (NULL == hdr_type) 1162 if (NULL == hdr_type)
1145 { 1163 {
1146 GNUNET_free(ndup); 1164 GNUNET_free (ndup);
1147 return bytes; 1165 return bytes;
1148 } 1166 }
1149 hdr_val = strtok(NULL, 1167 hdr_val = strtok (NULL,
1150 ""); 1168 "");
1151 if (NULL == hdr_val) 1169 if (NULL == hdr_val)
1152 { 1170 {
1153 GNUNET_free(ndup); 1171 GNUNET_free (ndup);
1154 return bytes; 1172 return bytes;
1155 } 1173 }
1156 if (' ' == *hdr_val) 1174 if (' ' == *hdr_val)
1157 hdr_val++; 1175 hdr_val++;
1158 1176
1159 /* custom logic for certain header types */ 1177 /* custom logic for certain header types */
1160 new_cookie_hdr = NULL; 1178 new_cookie_hdr = NULL;
1161 if ((NULL != s5r->leho) && 1179 if ((NULL != s5r->leho) &&
1162 (0 == strcasecmp(hdr_type, 1180 (0 == strcasecmp (hdr_type,
1163 MHD_HTTP_HEADER_SET_COOKIE))) 1181 MHD_HTTP_HEADER_SET_COOKIE)))
1164 1182
1165 { 1183 {
1166 new_cookie_hdr = GNUNET_malloc(strlen(hdr_val) + 1184 new_cookie_hdr = GNUNET_malloc (strlen (hdr_val)
1167 strlen(s5r->domain) + 1); 1185 + strlen (s5r->domain) + 1);
1168 offset = 0; 1186 offset = 0;
1169 domain_matched = GNUNET_NO; /* make sure we match domain at most once */ 1187 domain_matched = GNUNET_NO; /* make sure we match domain at most once */
1170 for (tok = strtok(hdr_val, ";"); NULL != tok; tok = strtok(NULL, ";")) 1188 for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";"))
1189 {
1190 if ((0 == strncasecmp (tok,
1191 " domain",
1192 strlen (" domain"))) &&
1193 (GNUNET_NO == domain_matched))
1194 {
1195 domain_matched = GNUNET_YES;
1196 cookie_domain = tok + strlen (" domain") + 1;
1197 if (strlen (cookie_domain) < strlen (s5r->leho))
1171 { 1198 {
1172 if ((0 == strncasecmp(tok, 1199 delta_cdomain = strlen (s5r->leho) - strlen (cookie_domain);
1173 " domain", 1200 if (0 == strcasecmp (cookie_domain,
1174 strlen(" domain"))) && 1201 s5r->leho + delta_cdomain))
1175 (GNUNET_NO == domain_matched)) 1202 {
1176 { 1203 offset += sprintf (new_cookie_hdr + offset,
1177 domain_matched = GNUNET_YES; 1204 " domain=%s;",
1178 cookie_domain = tok + strlen(" domain") + 1; 1205 s5r->domain);
1179 if (strlen(cookie_domain) < strlen(s5r->leho)) 1206 continue;
1180 { 1207 }
1181 delta_cdomain = strlen(s5r->leho) - strlen(cookie_domain);
1182 if (0 == strcasecmp(cookie_domain,
1183 s5r->leho + delta_cdomain))
1184 {
1185 offset += sprintf(new_cookie_hdr + offset,
1186 " domain=%s;",
1187 s5r->domain);
1188 continue;
1189 }
1190 }
1191 else if (0 == strcmp(cookie_domain,
1192 s5r->leho))
1193 {
1194 offset += sprintf(new_cookie_hdr + offset,
1195 " domain=%s;",
1196 s5r->domain);
1197 continue;
1198 }
1199 else if (('.' == cookie_domain[0]) &&
1200 (0 == strcmp(&cookie_domain[1],
1201 s5r->leho)))
1202 {
1203 offset += sprintf(new_cookie_hdr + offset,
1204 " domain=.%s;",
1205 s5r->domain);
1206 continue;
1207 }
1208 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1209 _("Cookie domain `%s' supplied by server is invalid\n"),
1210 tok);
1211 }
1212 GNUNET_memcpy(new_cookie_hdr + offset,
1213 tok,
1214 strlen(tok));
1215 offset += strlen(tok);
1216 new_cookie_hdr[offset++] = ';';
1217 } 1208 }
1218 hdr_val = new_cookie_hdr; 1209 else if (0 == strcmp (cookie_domain,
1219 } 1210 s5r->leho))
1220
1221 new_location = NULL;
1222 if (0 == strcasecmp(MHD_HTTP_HEADER_TRANSFER_ENCODING,
1223 hdr_type))
1224 {
1225 /* Ignore transfer encoding, set automatically by MHD if required */
1226 goto cleanup;
1227 }
1228 if ((0 == strcasecmp(MHD_HTTP_HEADER_LOCATION,
1229 hdr_type)))
1230 {
1231 char *leho_host;
1232
1233 GNUNET_asprintf(&leho_host,
1234 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1235 ? "http://%s"
1236 : "https://%s",
1237 s5r->leho);
1238 if (0 == strncmp(leho_host,
1239 hdr_val,
1240 strlen(leho_host)))
1241 { 1211 {
1242 GNUNET_asprintf(&new_location, 1212 offset += sprintf (new_cookie_hdr + offset,
1243 "%s%s%s", 1213 " domain=%s;",
1244 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) 1214 s5r->domain);
1245 ? "http://" 1215 continue;
1246 : "https://",
1247 s5r->domain,
1248 hdr_val + strlen(leho_host));
1249 hdr_val = new_location;
1250 } 1216 }
1251 GNUNET_free(leho_host); 1217 else if (('.' == cookie_domain[0]) &&
1252 } 1218 (0 == strcmp (&cookie_domain[1],
1253 if (0 == strcasecmp(MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, 1219 s5r->leho)))
1254 hdr_type))
1255 {
1256 char *leho_host;
1257
1258 GNUNET_asprintf(&leho_host,
1259 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1260 ? "http://%s"
1261 : "https://%s",
1262 s5r->leho);
1263 if (0 == strncmp(leho_host,
1264 hdr_val,
1265 strlen(leho_host)))
1266 { 1220 {
1267 GNUNET_asprintf(&new_location, 1221 offset += sprintf (new_cookie_hdr + offset,
1268 "%s%s", 1222 " domain=.%s;",
1269 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) 1223 s5r->domain);
1270 ? "http://" 1224 continue;
1271 : "https://",
1272 s5r->domain);
1273 hdr_val = new_location;
1274 } 1225 }
1275 GNUNET_free(leho_host); 1226 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1227 _ ("Cookie domain `%s' supplied by server is invalid\n"),
1228 tok);
1229 }
1230 GNUNET_memcpy (new_cookie_hdr + offset,
1231 tok,
1232 strlen (tok));
1233 offset += strlen (tok);
1234 new_cookie_hdr[offset++] = ';';
1276 } 1235 }
1236 hdr_val = new_cookie_hdr;
1237 }
1238
1239 new_location = NULL;
1240 if (0 == strcasecmp (MHD_HTTP_HEADER_TRANSFER_ENCODING,
1241 hdr_type))
1242 {
1243 /* Ignore transfer encoding, set automatically by MHD if required */
1244 goto cleanup;
1245 }
1246 if ((0 == strcasecmp (MHD_HTTP_HEADER_LOCATION,
1247 hdr_type)))
1248 {
1249 char *leho_host;
1250
1251 GNUNET_asprintf (&leho_host,
1252 (GNUNET_YES != s5r->is_tls) // (HTTPS_PORT != s5r->port)
1253 ? "http://%s"
1254 : "https://%s",
1255 s5r->leho);
1256 if (0 == strncmp (leho_host,
1257 hdr_val,
1258 strlen (leho_host)))
1259 {
1260 GNUNET_asprintf (&new_location,
1261 "%s%s%s",
1262 (GNUNET_YES != s5r->is_tls) // (HTTPS_PORT != s5r->port)
1263 ? "http://"
1264 : "https://",
1265 s5r->domain,
1266 hdr_val + strlen (leho_host));
1267 hdr_val = new_location;
1268 }
1269 GNUNET_free (leho_host);
1270 }
1271 if (0 == strcasecmp (MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
1272 hdr_type))
1273 {
1274 char *leho_host;
1275
1276 GNUNET_asprintf (&leho_host,
1277 (GNUNET_YES != s5r->is_tls) // (HTTPS_PORT != s5r->port)
1278 ? "http://%s"
1279 : "https://%s",
1280 s5r->leho);
1281 if (0 == strncmp (leho_host,
1282 hdr_val,
1283 strlen (leho_host)))
1284 {
1285 GNUNET_asprintf (&new_location,
1286 "%s%s",
1287 (GNUNET_YES != s5r->is_tls) // (HTTPS_PORT != s5r->port)
1288 ? "http://"
1289 : "https://",
1290 s5r->domain);
1291 hdr_val = new_location;
1292 }
1293 GNUNET_free (leho_host);
1294 }
1277 1295
1278 /* MHD does not allow certain characters in values, remove those */ 1296 /* MHD does not allow certain characters in values, remove those */
1279 if (NULL != (tok = strchr(hdr_val, '\n'))) 1297 if (NULL != (tok = strchr (hdr_val, '\n')))
1280 *tok = '\0'; 1298 *tok = '\0';
1281 if (NULL != (tok = strchr(hdr_val, '\r'))) 1299 if (NULL != (tok = strchr (hdr_val, '\r')))
1282 *tok = '\0'; 1300 *tok = '\0';
1283 if (NULL != (tok = strchr(hdr_val, '\t'))) 1301 if (NULL != (tok = strchr (hdr_val, '\t')))
1284 *tok = '\0'; 1302 *tok = '\0';
1285 if (0 != strlen(hdr_val)) /* Rely in MHD to set those */ 1303 if (0 != strlen (hdr_val)) /* Rely in MHD to set those */
1286 { 1304 {
1287 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1288 "Adding header %s: %s to MHD response\n", 1306 "Adding header %s: %s to MHD response\n",
1289 hdr_type, 1307 hdr_type,
1290 hdr_val); 1308 hdr_val);
1291 header = GNUNET_new(struct HttpResponseHeader); 1309 header = GNUNET_new (struct HttpResponseHeader);
1292 header->type = GNUNET_strdup(hdr_type); 1310 header->type = GNUNET_strdup (hdr_type);
1293 header->value = GNUNET_strdup(hdr_val); 1311 header->value = GNUNET_strdup (hdr_val);
1294 GNUNET_CONTAINER_DLL_insert(s5r->header_head, 1312 GNUNET_CONTAINER_DLL_insert (s5r->header_head,
1295 s5r->header_tail, 1313 s5r->header_tail,
1296 header); 1314 header);
1297 } 1315 }
1298cleanup: 1316cleanup:
1299 GNUNET_free(ndup); 1317 GNUNET_free (ndup);
1300 GNUNET_free_non_null(new_cookie_hdr); 1318 GNUNET_free_non_null (new_cookie_hdr);
1301 GNUNET_free_non_null(new_location); 1319 GNUNET_free_non_null (new_location);
1302 return bytes; 1320 return bytes;
1303} 1321}
1304 1322
@@ -1312,73 +1330,73 @@ cleanup:
1312 * already initialized before 1330 * already initialized before
1313 */ 1331 */
1314static int 1332static int
1315create_mhd_response_from_s5r(struct Socks5Request *s5r) 1333create_mhd_response_from_s5r (struct Socks5Request *s5r)
1316{ 1334{
1317 long resp_code; 1335 long resp_code;
1318 double content_length; 1336 double content_length;
1319 1337
1320 if (NULL != s5r->response) 1338 if (NULL != s5r->response)
1321 { 1339 {
1322 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1323 "Response already set!\n"); 1341 "Response already set!\n");
1324 return GNUNET_SYSERR; 1342 return GNUNET_SYSERR;
1325 } 1343 }
1326 1344
1327 GNUNET_break(CURLE_OK == 1345 GNUNET_break (CURLE_OK ==
1328 curl_easy_getinfo(s5r->curl, 1346 curl_easy_getinfo (s5r->curl,
1329 CURLINFO_RESPONSE_CODE, 1347 CURLINFO_RESPONSE_CODE,
1330 &resp_code)); 1348 &resp_code));
1331 GNUNET_break(CURLE_OK == 1349 GNUNET_break (CURLE_OK ==
1332 curl_easy_getinfo(s5r->curl, 1350 curl_easy_getinfo (s5r->curl,
1333 CURLINFO_CONTENT_LENGTH_DOWNLOAD, 1351 CURLINFO_CONTENT_LENGTH_DOWNLOAD,
1334 &content_length)); 1352 &content_length));
1335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1336 "Creating MHD response with code %d and size %d for %s%s\n", 1354 "Creating MHD response with code %d and size %d for %s%s\n",
1337 (int)resp_code, 1355 (int) resp_code,
1338 (int)content_length, 1356 (int) content_length,
1339 s5r->domain, 1357 s5r->domain,
1340 s5r->url); 1358 s5r->url);
1341 s5r->response_code = resp_code; 1359 s5r->response_code = resp_code;
1342 s5r->response = MHD_create_response_from_callback((-1 == content_length) 1360 s5r->response = MHD_create_response_from_callback ((-1 == content_length)
1343 ? MHD_SIZE_UNKNOWN 1361 ? MHD_SIZE_UNKNOWN
1344 : content_length, 1362 : content_length,
1345 IO_BUFFERSIZE, 1363 IO_BUFFERSIZE,
1346 &mhd_content_cb, 1364 &mhd_content_cb,
1347 s5r, 1365 s5r,
1348 NULL); 1366 NULL);
1349 for (struct HttpResponseHeader *header = s5r->header_head; 1367 for (struct HttpResponseHeader *header = s5r->header_head;
1350 NULL != header; 1368 NULL != header;
1351 header = header->next) 1369 header = header->next)
1352 { 1370 {
1353 if (0 == strcasecmp(header->type, 1371 if (0 == strcasecmp (header->type,
1354 MHD_HTTP_HEADER_CONTENT_LENGTH)) 1372 MHD_HTTP_HEADER_CONTENT_LENGTH))
1355 continue; /* MHD won't let us mess with those, for good reason */ 1373 continue; /* MHD won't let us mess with those, for good reason */
1356 if ((0 == strcasecmp(header->type, 1374 if ((0 == strcasecmp (header->type,
1357 MHD_HTTP_HEADER_TRANSFER_ENCODING)) && 1375 MHD_HTTP_HEADER_TRANSFER_ENCODING)) &&
1358 ((0 == strcasecmp(header->value, 1376 ((0 == strcasecmp (header->value,
1359 "identity")) || 1377 "identity")) ||
1360 (0 == strcasecmp(header->value, 1378 (0 == strcasecmp (header->value,
1361 "chunked")))) 1379 "chunked"))))
1362 continue; /* MHD won't let us mess with those, for good reason */ 1380 continue; /* MHD won't let us mess with those, for good reason */
1363 if (MHD_YES != 1381 if (MHD_YES !=
1364 MHD_add_response_header(s5r->response, 1382 MHD_add_response_header (s5r->response,
1365 header->type, 1383 header->type,
1366 header->value)) 1384 header->value))
1367 { 1385 {
1368 GNUNET_break(0); 1386 GNUNET_break (0);
1369 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1387 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1370 "Failed to add header `%s:%s'\n", 1388 "Failed to add header `%s:%s'\n",
1371 header->type, 1389 header->type,
1372 header->value); 1390 header->value);
1373 }
1374 } 1391 }
1392 }
1375 /* force connection to be closed after each request, as we 1393 /* force connection to be closed after each request, as we
1376 do not support HTTP pipelining (yet, FIXME!) */ 1394 do not support HTTP pipelining (yet, FIXME!) */
1377 /*GNUNET_break (MHD_YES == 1395 /*GNUNET_break (MHD_YES ==
1378 MHD_add_response_header (s5r->response, 1396 MHD_add_response_header (s5r->response,
1379 MHD_HTTP_HEADER_CONNECTION, 1397 MHD_HTTP_HEADER_CONNECTION,
1380 "close"));*/ 1398 "close"));*/
1381 MHD_resume_connection(s5r->con); 1399 MHD_resume_connection (s5r->con);
1382 s5r->suspended = GNUNET_NO; 1400 s5r->suspended = GNUNET_NO;
1383 return GNUNET_OK; 1401 return GNUNET_OK;
1384} 1402}
@@ -1395,70 +1413,70 @@ create_mhd_response_from_s5r(struct Socks5Request *s5r)
1395 * @return number of bytes handled 1413 * @return number of bytes handled
1396 */ 1414 */
1397static size_t 1415static size_t
1398curl_download_cb(void *ptr, 1416curl_download_cb (void *ptr,
1399 size_t size, 1417 size_t size,
1400 size_t nmemb, 1418 size_t nmemb,
1401 void* ctx) 1419 void*ctx)
1402{ 1420{
1403 struct Socks5Request *s5r = ctx; 1421 struct Socks5Request *s5r = ctx;
1404 size_t total = size * nmemb; 1422 size_t total = size * nmemb;
1405 1423
1406 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1407 "Receiving %ux%u bytes for `%s%s' from cURL to download\n", 1425 "Receiving %ux%u bytes for `%s%s' from cURL to download\n",
1408 (unsigned int)size, 1426 (unsigned int) size,
1409 (unsigned int)nmemb, 1427 (unsigned int) nmemb,
1410 s5r->domain, 1428 s5r->domain,
1411 s5r->url); 1429 s5r->url);
1412 if (NULL == s5r->response) 1430 if (NULL == s5r->response)
1413 GNUNET_assert(GNUNET_OK == 1431 GNUNET_assert (GNUNET_OK ==
1414 create_mhd_response_from_s5r(s5r)); 1432 create_mhd_response_from_s5r (s5r));
1415 if ((SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) && 1433 if ((SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) &&
1416 (0 == s5r->io_len)) 1434 (0 == s5r->io_len))
1417 { 1435 {
1418 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1419 "Previous upload finished... starting DOWNLOAD.\n"); 1437 "Previous upload finished... starting DOWNLOAD.\n");
1420 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1438 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1421 } 1439 }
1422 if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || 1440 if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) ||
1423 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) 1441 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state))
1424 { 1442 {
1425 /* we're still not done with the upload, do not yet 1443 /* we're still not done with the upload, do not yet
1426 start the download, the IO buffer is still full 1444 start the download, the IO buffer is still full
1427 with upload data. */ 1445 with upload data. */
1428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1429 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n", 1447 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n",
1430 s5r->domain, 1448 s5r->domain,
1431 s5r->url); 1449 s5r->url);
1432 s5r->curl_paused = GNUNET_YES; 1450 s5r->curl_paused = GNUNET_YES;
1433 return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ 1451 return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */
1434 } 1452 }
1435 if (sizeof(s5r->io_buf) - s5r->io_len < total) 1453 if (sizeof(s5r->io_buf) - s5r->io_len < total)
1436 { 1454 {
1437 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1438 "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n", 1456 "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n",
1439 s5r->domain, 1457 s5r->domain,
1440 s5r->url, 1458 s5r->url,
1441 (unsigned long long)sizeof(s5r->io_buf), 1459 (unsigned long long) sizeof(s5r->io_buf),
1442 (unsigned long long)s5r->io_len, 1460 (unsigned long long) s5r->io_len,
1443 (unsigned long long)total); 1461 (unsigned long long) total);
1444 s5r->curl_paused = GNUNET_YES; 1462 s5r->curl_paused = GNUNET_YES;
1445 return CURL_WRITEFUNC_PAUSE; /* not enough space */ 1463 return CURL_WRITEFUNC_PAUSE; /* not enough space */
1446 } 1464 }
1447 GNUNET_memcpy(&s5r->io_buf[s5r->io_len], 1465 GNUNET_memcpy (&s5r->io_buf[s5r->io_len],
1448 ptr, 1466 ptr,
1449 total); 1467 total);
1450 s5r->io_len += total; 1468 s5r->io_len += total;
1451 if (GNUNET_YES == s5r->suspended) 1469 if (GNUNET_YES == s5r->suspended)
1452 { 1470 {
1453 MHD_resume_connection(s5r->con); 1471 MHD_resume_connection (s5r->con);
1454 s5r->suspended = GNUNET_NO; 1472 s5r->suspended = GNUNET_NO;
1455 } 1473 }
1456 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1457 "Received %llu bytes of payload via cURL from %s\n", 1475 "Received %llu bytes of payload via cURL from %s\n",
1458 (unsigned long long)total, 1476 (unsigned long long) total,
1459 s5r->domain); 1477 s5r->domain);
1460 if (s5r->io_len == total) 1478 if (s5r->io_len == total)
1461 run_mhd_now(s5r->hd); 1479 run_mhd_now (s5r->hd);
1462 return total; 1480 return total;
1463} 1481}
1464 1482
@@ -1474,64 +1492,64 @@ curl_download_cb(void *ptr,
1474 * @return number of bytes copied to @a buf 1492 * @return number of bytes copied to @a buf
1475 */ 1493 */
1476static size_t 1494static size_t
1477curl_upload_cb(void *buf, 1495curl_upload_cb (void *buf,
1478 size_t size, 1496 size_t size,
1479 size_t nmemb, 1497 size_t nmemb,
1480 void *cls) 1498 void *cls)
1481{ 1499{
1482 struct Socks5Request *s5r = cls; 1500 struct Socks5Request *s5r = cls;
1483 size_t len = size * nmemb; 1501 size_t len = size * nmemb;
1484 size_t to_copy; 1502 size_t to_copy;
1485 1503
1486 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1487 "Receiving %ux%u bytes for `%s%s' from cURL to upload\n", 1505 "Receiving %ux%u bytes for `%s%s' from cURL to upload\n",
1488 (unsigned int)size, 1506 (unsigned int) size,
1489 (unsigned int)nmemb, 1507 (unsigned int) nmemb,
1490 s5r->domain, 1508 s5r->domain,
1491 s5r->url); 1509 s5r->url);
1492 1510
1493 if ((0 == s5r->io_len) && 1511 if ((0 == s5r->io_len) &&
1494 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state)) 1512 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state))
1495 { 1513 {
1496 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1497 "Pausing CURL UPLOAD %s%s, need more data\n", 1515 "Pausing CURL UPLOAD %s%s, need more data\n",
1498 s5r->domain, 1516 s5r->domain,
1499 s5r->url); 1517 s5r->url);
1500 return CURL_READFUNC_PAUSE; 1518 return CURL_READFUNC_PAUSE;
1501 } 1519 }
1502 if ((0 == s5r->io_len) && 1520 if ((0 == s5r->io_len) &&
1503 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) 1521 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state))
1522 {
1523 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1524 if (GNUNET_YES == s5r->curl_paused)
1504 { 1525 {
1505 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1526 s5r->curl_paused = GNUNET_NO;
1506 if (GNUNET_YES == s5r->curl_paused) 1527 curl_easy_pause (s5r->curl,
1507 { 1528 CURLPAUSE_CONT);
1508 s5r->curl_paused = GNUNET_NO; 1529 }
1509 curl_easy_pause(s5r->curl, 1530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1510 CURLPAUSE_CONT); 1531 "Completed CURL UPLOAD %s%s\n",
1511 } 1532 s5r->domain,
1512 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1533 s5r->url);
1513 "Completed CURL UPLOAD %s%s\n", 1534 return 0; /* upload finished, can now download */
1514 s5r->domain, 1535 }
1515 s5r->url);
1516 return 0; /* upload finished, can now download */
1517 }
1518 if ((SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && 1536 if ((SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) &&
1519 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state)) 1537 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state))
1520 { 1538 {
1521 GNUNET_break(0); 1539 GNUNET_break (0);
1522 return CURL_READFUNC_ABORT; 1540 return CURL_READFUNC_ABORT;
1523 } 1541 }
1524 to_copy = GNUNET_MIN(s5r->io_len, 1542 to_copy = GNUNET_MIN (s5r->io_len,
1525 len); 1543 len);
1526 GNUNET_memcpy(buf, 1544 GNUNET_memcpy (buf,
1527 s5r->io_buf, 1545 s5r->io_buf,
1528 to_copy); 1546 to_copy);
1529 memmove(s5r->io_buf, 1547 memmove (s5r->io_buf,
1530 &s5r->io_buf[to_copy], 1548 &s5r->io_buf[to_copy],
1531 s5r->io_len - to_copy); 1549 s5r->io_len - to_copy);
1532 s5r->io_len -= to_copy; 1550 s5r->io_len -= to_copy;
1533 if (s5r->io_len + to_copy == sizeof(s5r->io_buf)) 1551 if (s5r->io_len + to_copy == sizeof(s5r->io_buf))
1534 run_mhd_now(s5r->hd); /* got more space for upload now */ 1552 run_mhd_now (s5r->hd); /* got more space for upload now */
1535 return to_copy; 1553 return to_copy;
1536} 1554}
1537 1555
@@ -1546,14 +1564,14 @@ curl_upload_cb(void *buf,
1546 * @param cls closure 1564 * @param cls closure
1547 */ 1565 */
1548static void 1566static void
1549curl_task_download(void *cls); 1567curl_task_download (void *cls);
1550 1568
1551 1569
1552/** 1570/**
1553 * Ask cURL for the select() sets and schedule cURL operations. 1571 * Ask cURL for the select() sets and schedule cURL operations.
1554 */ 1572 */
1555static void 1573static void
1556curl_download_prepare() 1574curl_download_prepare ()
1557{ 1575{
1558 CURLMcode mret; 1576 CURLMcode mret;
1559 fd_set rs; 1577 fd_set rs;
@@ -1565,63 +1583,64 @@ curl_download_prepare()
1565 long to; 1583 long to;
1566 struct GNUNET_TIME_Relative rtime; 1584 struct GNUNET_TIME_Relative rtime;
1567 1585
1568 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1569 "Scheduling CURL interaction\n"); 1587 "Scheduling CURL interaction\n");
1570 if (NULL != curl_download_task) 1588 if (NULL != curl_download_task)
1571 { 1589 {
1572 GNUNET_SCHEDULER_cancel(curl_download_task); 1590 GNUNET_SCHEDULER_cancel (curl_download_task);
1573 curl_download_task = NULL; 1591 curl_download_task = NULL;
1574 } 1592 }
1575 max = -1; 1593 max = -1;
1576 FD_ZERO(&rs); 1594 FD_ZERO (&rs);
1577 FD_ZERO(&ws); 1595 FD_ZERO (&ws);
1578 FD_ZERO(&es); 1596 FD_ZERO (&es);
1579 if (CURLM_OK != (mret = curl_multi_fdset(curl_multi, 1597 if (CURLM_OK != (mret = curl_multi_fdset (curl_multi,
1580 &rs, 1598 &rs,
1581 &ws, 1599 &ws,
1582 &es, 1600 &es,
1583 &max))) 1601 &max)))
1584 { 1602 {
1585 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1586 "%s failed at %s:%d: `%s'\n", 1604 "%s failed at %s:%d: `%s'\n",
1587 "curl_multi_fdset", __FILE__, __LINE__, 1605 "curl_multi_fdset", __FILE__, __LINE__,
1588 curl_multi_strerror(mret)); 1606 curl_multi_strerror (mret));
1589 return; 1607 return;
1590 } 1608 }
1591 to = -1; 1609 to = -1;
1592 GNUNET_break(CURLM_OK == 1610 GNUNET_break (CURLM_OK ==
1593 curl_multi_timeout(curl_multi, 1611 curl_multi_timeout (curl_multi,
1594 &to)); 1612 &to));
1595 if (-1 == to) 1613 if (-1 == to)
1596 rtime = GNUNET_TIME_UNIT_FOREVER_REL; 1614 rtime = GNUNET_TIME_UNIT_FOREVER_REL;
1597 else 1615 else
1598 rtime = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1616 rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1599 to); 1617 to);
1600 if (-1 != max) 1618 if (-1 != max)
1601 { 1619 {
1602 grs = GNUNET_NETWORK_fdset_create(); 1620 grs = GNUNET_NETWORK_fdset_create ();
1603 gws = GNUNET_NETWORK_fdset_create(); 1621 gws = GNUNET_NETWORK_fdset_create ();
1604 GNUNET_NETWORK_fdset_copy_native(grs, 1622 GNUNET_NETWORK_fdset_copy_native (grs,
1605 &rs, 1623 &rs,
1606 max + 1); 1624 max + 1);
1607 GNUNET_NETWORK_fdset_copy_native(gws, 1625 GNUNET_NETWORK_fdset_copy_native (gws,
1608 &ws, 1626 &ws,
1609 max + 1); 1627 max + 1);
1610 curl_download_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1628 curl_download_task = GNUNET_SCHEDULER_add_select (
1611 rtime, 1629 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1612 grs, 1630 rtime,
1613 gws, 1631 grs,
1632 gws,
1633 &curl_task_download,
1634 curl_multi);
1635 GNUNET_NETWORK_fdset_destroy (gws);
1636 GNUNET_NETWORK_fdset_destroy (grs);
1637 }
1638 else
1639 {
1640 curl_download_task = GNUNET_SCHEDULER_add_delayed (rtime,
1614 &curl_task_download, 1641 &curl_task_download,
1615 curl_multi); 1642 curl_multi);
1616 GNUNET_NETWORK_fdset_destroy(gws); 1643 }
1617 GNUNET_NETWORK_fdset_destroy(grs);
1618 }
1619 else
1620 {
1621 curl_download_task = GNUNET_SCHEDULER_add_delayed(rtime,
1622 &curl_task_download,
1623 curl_multi);
1624 }
1625} 1644}
1626 1645
1627 1646
@@ -1631,7 +1650,7 @@ curl_download_prepare()
1631 * @param cls closure, NULL 1650 * @param cls closure, NULL
1632 */ 1651 */
1633static void 1652static void
1634curl_task_download(void *cls) 1653curl_task_download (void *cls)
1635{ 1654{
1636 int running; 1655 int running;
1637 int msgnum; 1656 int msgnum;
@@ -1640,109 +1659,109 @@ curl_task_download(void *cls)
1640 struct Socks5Request *s5r; 1659 struct Socks5Request *s5r;
1641 1660
1642 curl_download_task = NULL; 1661 curl_download_task = NULL;
1643 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1644 "Running CURL interaction\n"); 1663 "Running CURL interaction\n");
1645 do 1664 do
1646 { 1665 {
1647 running = 0; 1666 running = 0;
1648 mret = curl_multi_perform(curl_multi, 1667 mret = curl_multi_perform (curl_multi,
1649 &running); 1668 &running);
1650 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1651 "Checking CURL multi status: %d\n", 1670 "Checking CURL multi status: %d\n",
1652 mret); 1671 mret);
1653 while (NULL != (msg = curl_multi_info_read(curl_multi, 1672 while (NULL != (msg = curl_multi_info_read (curl_multi,
1654 &msgnum))) 1673 &msgnum)))
1674 {
1675 GNUNET_break (CURLE_OK ==
1676 curl_easy_getinfo (msg->easy_handle,
1677 CURLINFO_PRIVATE,
1678 (char **) &s5r));
1679 if (NULL == s5r)
1680 {
1681 GNUNET_break (0);
1682 continue;
1683 }
1684 switch (msg->msg)
1685 {
1686 case CURLMSG_NONE:
1687 /* documentation says this is not used */
1688 GNUNET_break (0);
1689 break;
1690
1691 case CURLMSG_DONE:
1692 switch (msg->data.result)
1655 { 1693 {
1656 GNUNET_break(CURLE_OK == 1694 case CURLE_OK:
1657 curl_easy_getinfo(msg->easy_handle, 1695 case CURLE_GOT_NOTHING:
1658 CURLINFO_PRIVATE, 1696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1659 (char **)&s5r)); 1697 "CURL download %s%s completed.\n",
1660 if (NULL == s5r) 1698 s5r->domain,
1661 { 1699 s5r->url);
1662 GNUNET_break(0); 1700 if (NULL == s5r->response)
1663 continue; 1701 {
1664 } 1702 GNUNET_assert (GNUNET_OK ==
1665 switch (msg->msg) 1703 create_mhd_response_from_s5r (s5r));
1666 { 1704 }
1667 case CURLMSG_NONE: 1705 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
1668 /* documentation says this is not used */ 1706 if (GNUNET_YES == s5r->suspended)
1669 GNUNET_break(0); 1707 {
1670 break; 1708 MHD_resume_connection (s5r->con);
1671 1709 s5r->suspended = GNUNET_NO;
1672 case CURLMSG_DONE: 1710 }
1673 switch (msg->data.result) 1711 run_mhd_now (s5r->hd);
1674 { 1712 break;
1675 case CURLE_OK: 1713
1676 case CURLE_GOT_NOTHING: 1714 default:
1677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1715 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1678 "CURL download %s%s completed.\n", 1716 "Download curl %s%s failed: %s\n",
1679 s5r->domain, 1717 s5r->domain,
1680 s5r->url); 1718 s5r->url,
1681 if (NULL == s5r->response) 1719 curl_easy_strerror (msg->data.result));
1682 { 1720 /* FIXME: indicate error somehow? close MHD connection badly as well? */
1683 GNUNET_assert(GNUNET_OK == 1721 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
1684 create_mhd_response_from_s5r(s5r)); 1722 if (GNUNET_YES == s5r->suspended)
1685 } 1723 {
1686 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; 1724 MHD_resume_connection (s5r->con);
1687 if (GNUNET_YES == s5r->suspended) 1725 s5r->suspended = GNUNET_NO;
1688 { 1726 }
1689 MHD_resume_connection(s5r->con); 1727 run_mhd_now (s5r->hd);
1690 s5r->suspended = GNUNET_NO; 1728 break;
1691 }
1692 run_mhd_now(s5r->hd);
1693 break;
1694
1695 default:
1696 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1697 "Download curl %s%s failed: %s\n",
1698 s5r->domain,
1699 s5r->url,
1700 curl_easy_strerror(msg->data.result));
1701 /* FIXME: indicate error somehow? close MHD connection badly as well? */
1702 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
1703 if (GNUNET_YES == s5r->suspended)
1704 {
1705 MHD_resume_connection(s5r->con);
1706 s5r->suspended = GNUNET_NO;
1707 }
1708 run_mhd_now(s5r->hd);
1709 break;
1710 }
1711 if (NULL == s5r->response)
1712 s5r->response = curl_failure_response;
1713 break;
1714
1715 case CURLMSG_LAST:
1716 /* documentation says this is not used */
1717 GNUNET_break(0);
1718 break;
1719
1720 default:
1721 /* unexpected status code */
1722 GNUNET_break(0);
1723 break;
1724 }
1725 } 1729 }
1726 ; 1730 if (NULL == s5r->response)
1731 s5r->response = curl_failure_response;
1732 break;
1733
1734 case CURLMSG_LAST:
1735 /* documentation says this is not used */
1736 GNUNET_break (0);
1737 break;
1738
1739 default:
1740 /* unexpected status code */
1741 GNUNET_break (0);
1742 break;
1743 }
1727 } 1744 }
1745 ;
1746 }
1728 while (mret == CURLM_CALL_MULTI_PERFORM); 1747 while (mret == CURLM_CALL_MULTI_PERFORM);
1729 if (CURLM_OK != mret) 1748 if (CURLM_OK != mret)
1730 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1749 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1731 "%s failed at %s:%d: `%s'\n", 1750 "%s failed at %s:%d: `%s'\n",
1732 "curl_multi_perform", __FILE__, __LINE__, 1751 "curl_multi_perform", __FILE__, __LINE__,
1733 curl_multi_strerror(mret)); 1752 curl_multi_strerror (mret));
1734 if (0 == running) 1753 if (0 == running)
1754 {
1755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1756 "Suspending cURL multi loop, no more events pending\n");
1757 if (NULL != curl_download_task)
1735 { 1758 {
1736 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1759 GNUNET_SCHEDULER_cancel (curl_download_task);
1737 "Suspending cURL multi loop, no more events pending\n"); 1760 curl_download_task = NULL;
1738 if (NULL != curl_download_task)
1739 {
1740 GNUNET_SCHEDULER_cancel(curl_download_task);
1741 curl_download_task = NULL;
1742 }
1743 return; /* nothing more in progress */
1744 } 1761 }
1745 curl_download_prepare(); 1762 return; /* nothing more in progress */
1763 }
1764 curl_download_prepare ();
1746} 1765}
1747 1766
1748 1767
@@ -1763,28 +1782,28 @@ curl_task_download(void *cls)
1763 * @return #MHD_YES to continue to iterate 1782 * @return #MHD_YES to continue to iterate
1764 */ 1783 */
1765static int 1784static int
1766con_val_iter(void *cls, 1785con_val_iter (void *cls,
1767 enum MHD_ValueKind kind, 1786 enum MHD_ValueKind kind,
1768 const char *key, 1787 const char *key,
1769 const char *value) 1788 const char *value)
1770{ 1789{
1771 struct Socks5Request *s5r = cls; 1790 struct Socks5Request *s5r = cls;
1772 char *hdr; 1791 char *hdr;
1773 1792
1774 if ((0 == strcasecmp(MHD_HTTP_HEADER_HOST, 1793 if ((0 == strcasecmp (MHD_HTTP_HEADER_HOST,
1775 key)) && 1794 key)) &&
1776 (NULL != s5r->leho)) 1795 (NULL != s5r->leho))
1777 value = s5r->leho; 1796 value = s5r->leho;
1778 GNUNET_asprintf(&hdr, 1797 GNUNET_asprintf (&hdr,
1779 "%s: %s", 1798 "%s: %s",
1780 key, 1799 key,
1781 value); 1800 value);
1782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1783 "Adding HEADER `%s' to HTTP request\n", 1802 "Adding HEADER `%s' to HTTP request\n",
1784 hdr); 1803 hdr);
1785 s5r->headers = curl_slist_append(s5r->headers, 1804 s5r->headers = curl_slist_append (s5r->headers,
1786 hdr); 1805 hdr);
1787 GNUNET_free(hdr); 1806 GNUNET_free (hdr);
1788 return MHD_YES; 1807 return MHD_YES;
1789} 1808}
1790 1809
@@ -1813,14 +1832,14 @@ con_val_iter(void *cls,
1813 * error while handling the request 1832 * error while handling the request
1814 */ 1833 */
1815static int 1834static int
1816create_response(void *cls, 1835create_response (void *cls,
1817 struct MHD_Connection *con, 1836 struct MHD_Connection *con,
1818 const char *url, 1837 const char *url,
1819 const char *meth, 1838 const char *meth,
1820 const char *ver, 1839 const char *ver,
1821 const char *upload_data, 1840 const char *upload_data,
1822 size_t *upload_data_size, 1841 size_t *upload_data_size,
1823 void **con_cls) 1842 void **con_cls)
1824{ 1843{
1825 struct Socks5Request *s5r = *con_cls; 1844 struct Socks5Request *s5r = *con_cls;
1826 char *curlurl; 1845 char *curlurl;
@@ -1833,415 +1852,415 @@ create_response(void *cls,
1833 size_t left; 1852 size_t left;
1834 1853
1835 if (NULL == s5r) 1854 if (NULL == s5r)
1836 { 1855 {
1837 GNUNET_break(0); 1856 GNUNET_break (0);
1838 return MHD_NO; 1857 return MHD_NO;
1839 } 1858 }
1840 s5r->con = con; 1859 s5r->con = con;
1841 /* Fresh connection. */ 1860 /* Fresh connection. */
1842 if (SOCKS5_SOCKET_WITH_MHD == s5r->state) 1861 if (SOCKS5_SOCKET_WITH_MHD == s5r->state)
1862 {
1863 /* first time here, initialize curl handle */
1864 if (s5r->is_gns)
1843 { 1865 {
1844 /* first time here, initialize curl handle */ 1866 sa = (const struct sockaddr *) &s5r->destination_address;
1845 if (s5r->is_gns) 1867 switch (sa->sa_family)
1846 { 1868 {
1847 sa = (const struct sockaddr *)&s5r->destination_address; 1869 case AF_INET:
1848 switch (sa->sa_family) 1870 s4 = (const struct sockaddr_in *) &s5r->destination_address;
1849 { 1871 if (NULL == inet_ntop (AF_INET,
1850 case AF_INET: 1872 &s4->sin_addr,
1851 s4 = (const struct sockaddr_in *)&s5r->destination_address; 1873 ipstring,
1852 if (NULL == inet_ntop(AF_INET, 1874 sizeof(ipstring)))
1853 &s4->sin_addr,
1854 ipstring,
1855 sizeof(ipstring)))
1856 {
1857 GNUNET_break(0);
1858 return MHD_NO;
1859 }
1860 GNUNET_snprintf(ipaddr,
1861 sizeof(ipaddr),
1862 "%s",
1863 ipstring);
1864 port = ntohs(s4->sin_port);
1865 break;
1866
1867 case AF_INET6:
1868 s6 = (const struct sockaddr_in6 *)&s5r->destination_address;
1869 if (NULL == inet_ntop(AF_INET6,
1870 &s6->sin6_addr,
1871 ipstring,
1872 sizeof(ipstring)))
1873 {
1874 GNUNET_break(0);
1875 return MHD_NO;
1876 }
1877 GNUNET_snprintf(ipaddr,
1878 sizeof(ipaddr),
1879 "%s",
1880 ipstring);
1881 port = ntohs(s6->sin6_port);
1882 break;
1883
1884 default:
1885 GNUNET_break(0);
1886 return MHD_NO;
1887 }
1888 }
1889 else
1890 {
1891 port = s5r->port;
1892 }
1893 if (NULL == s5r->curl)
1894 s5r->curl = curl_easy_init();
1895 if (NULL == s5r->curl)
1896 return MHD_queue_response(con,
1897 MHD_HTTP_INTERNAL_SERVER_ERROR,
1898 curl_failure_response);
1899 curl_easy_setopt(s5r->curl,
1900 CURLOPT_HEADERFUNCTION,
1901 &curl_check_hdr);
1902 curl_easy_setopt(s5r->curl,
1903 CURLOPT_HEADERDATA,
1904 s5r);
1905 curl_easy_setopt(s5r->curl,
1906 CURLOPT_FOLLOWLOCATION,
1907 0);
1908 if (s5r->is_gns)
1909 curl_easy_setopt(s5r->curl,
1910 CURLOPT_IPRESOLVE,
1911 CURL_IPRESOLVE_V4);
1912 curl_easy_setopt(s5r->curl,
1913 CURLOPT_CONNECTTIMEOUT,
1914 600L);
1915 curl_easy_setopt(s5r->curl,
1916 CURLOPT_TIMEOUT,
1917 600L);
1918 curl_easy_setopt(s5r->curl,
1919 CURLOPT_NOSIGNAL,
1920 1L);
1921 curl_easy_setopt(s5r->curl,
1922 CURLOPT_HTTP_CONTENT_DECODING,
1923 0);
1924 curl_easy_setopt(s5r->curl,
1925 CURLOPT_NOSIGNAL,
1926 1L);
1927 curl_easy_setopt(s5r->curl,
1928 CURLOPT_PRIVATE,
1929 s5r);
1930 curl_easy_setopt(s5r->curl,
1931 CURLOPT_VERBOSE,
1932 0L);
1933 /**
1934 * Pre-populate cache to resolve Hostname.
1935 * This is necessary as the DNS name in the CURLOPT_URL is used
1936 * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication
1937 */
1938 if (NULL != s5r->leho)
1939 {
1940 char *curl_hosts;
1941
1942 GNUNET_asprintf(&curl_hosts,
1943 "%s:%d:%s",
1944 s5r->leho,
1945 port,
1946 ipaddr);
1947 s5r->hosts = curl_slist_append(NULL,
1948 curl_hosts);
1949 curl_easy_setopt(s5r->curl,
1950 CURLOPT_RESOLVE,
1951 s5r->hosts);
1952 GNUNET_free(curl_hosts);
1953 }
1954 if (s5r->is_gns)
1955 {
1956 GNUNET_asprintf(&curlurl,
1957 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1958 ? "http://%s:%d%s"
1959 : "https://%s:%d%s",
1960 (NULL != s5r->leho)
1961 ? s5r->leho
1962 : ipaddr,
1963 port,
1964 s5r->url);
1965 }
1966 else
1967 {
1968 GNUNET_asprintf(&curlurl,
1969 (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port)
1970 ? "http://%s:%d%s"
1971 : "https://%s:%d%s",
1972 s5r->domain,
1973 port,
1974 s5r->url);
1975 }
1976 curl_easy_setopt(s5r->curl,
1977 CURLOPT_URL,
1978 curlurl);
1979 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1980 "Launching %s CURL interaction, fetching `%s'\n",
1981 (s5r->is_gns) ? "GNS" : "DNS",
1982 curlurl);
1983 GNUNET_free(curlurl);
1984 if (0 == strcasecmp(meth,
1985 MHD_HTTP_METHOD_PUT))
1986 {
1987 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
1988 curl_easy_setopt(s5r->curl,
1989 CURLOPT_UPLOAD,
1990 1L);
1991 curl_easy_setopt(s5r->curl,
1992 CURLOPT_WRITEFUNCTION,
1993 &curl_download_cb);
1994 curl_easy_setopt(s5r->curl,
1995 CURLOPT_WRITEDATA,
1996 s5r);
1997 GNUNET_assert(CURLE_OK ==
1998 curl_easy_setopt(s5r->curl,
1999 CURLOPT_READFUNCTION,
2000 &curl_upload_cb));
2001 curl_easy_setopt(s5r->curl,
2002 CURLOPT_READDATA,
2003 s5r);
2004 {
2005 const char *us;
2006 long upload_size = 0;
2007
2008 us = MHD_lookup_connection_value(con,
2009 MHD_HEADER_KIND,
2010 MHD_HTTP_HEADER_CONTENT_LENGTH);
2011 if ((1 == sscanf(us,
2012 "%ld",
2013 &upload_size)) &&
2014 (upload_size >= 0))
2015 {
2016 curl_easy_setopt(s5r->curl,
2017 CURLOPT_INFILESIZE,
2018 upload_size);
2019 }
2020 }
2021 }
2022 else if (0 == strcasecmp(meth, MHD_HTTP_METHOD_POST))
2023 {
2024 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
2025 curl_easy_setopt(s5r->curl,
2026 CURLOPT_POST,
2027 1L);
2028 curl_easy_setopt(s5r->curl,
2029 CURLOPT_WRITEFUNCTION,
2030 &curl_download_cb);
2031 curl_easy_setopt(s5r->curl,
2032 CURLOPT_WRITEDATA,
2033 s5r);
2034 curl_easy_setopt(s5r->curl,
2035 CURLOPT_READFUNCTION,
2036 &curl_upload_cb);
2037 curl_easy_setopt(s5r->curl,
2038 CURLOPT_READDATA,
2039 s5r);
2040 {
2041 const char *us;
2042 long upload_size;
2043
2044 upload_size = 0;
2045 us = MHD_lookup_connection_value(con,
2046 MHD_HEADER_KIND,
2047 MHD_HTTP_HEADER_CONTENT_LENGTH);
2048 if ((NULL != us) &&
2049 (1 == sscanf(us,
2050 "%ld",
2051 &upload_size)) &&
2052 (upload_size >= 0))
2053 {
2054 curl_easy_setopt(s5r->curl,
2055 CURLOPT_INFILESIZE,
2056 upload_size);
2057 }
2058 else
2059 {
2060 curl_easy_setopt(s5r->curl,
2061 CURLOPT_INFILESIZE,
2062 upload_size);
2063 }
2064 }
2065 }
2066 else if (0 == strcasecmp(meth,
2067 MHD_HTTP_METHOD_HEAD))
2068 {
2069 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2070 curl_easy_setopt(s5r->curl,
2071 CURLOPT_NOBODY,
2072 1L);
2073 }
2074 else if (0 == strcasecmp(meth,
2075 MHD_HTTP_METHOD_OPTIONS))
2076 {
2077 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2078 curl_easy_setopt(s5r->curl,
2079 CURLOPT_CUSTOMREQUEST,
2080 "OPTIONS");
2081 curl_easy_setopt(s5r->curl,
2082 CURLOPT_WRITEFUNCTION,
2083 &curl_download_cb);
2084 curl_easy_setopt(s5r->curl,
2085 CURLOPT_WRITEDATA,
2086 s5r);
2087 }
2088 else if (0 == strcasecmp(meth,
2089 MHD_HTTP_METHOD_GET))
2090 {
2091 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2092 curl_easy_setopt(s5r->curl,
2093 CURLOPT_HTTPGET,
2094 1L);
2095 curl_easy_setopt(s5r->curl,
2096 CURLOPT_WRITEFUNCTION,
2097 &curl_download_cb);
2098 curl_easy_setopt(s5r->curl,
2099 CURLOPT_WRITEDATA,
2100 s5r);
2101 }
2102 else if (0 == strcasecmp(meth,
2103 MHD_HTTP_METHOD_DELETE))
2104 { 1875 {
2105 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1876 GNUNET_break (0);
2106 curl_easy_setopt(s5r->curl, 1877 return MHD_NO;
2107 CURLOPT_CUSTOMREQUEST,
2108 "DELETE");
2109 curl_easy_setopt(s5r->curl,
2110 CURLOPT_WRITEFUNCTION,
2111 &curl_download_cb);
2112 curl_easy_setopt(s5r->curl,
2113 CURLOPT_WRITEDATA,
2114 s5r);
2115 } 1878 }
2116 else 1879 GNUNET_snprintf (ipaddr,
1880 sizeof(ipaddr),
1881 "%s",
1882 ipstring);
1883 port = ntohs (s4->sin_port);
1884 break;
1885
1886 case AF_INET6:
1887 s6 = (const struct sockaddr_in6 *) &s5r->destination_address;
1888 if (NULL == inet_ntop (AF_INET6,
1889 &s6->sin6_addr,
1890 ipstring,
1891 sizeof(ipstring)))
2117 { 1892 {
2118 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1893 GNUNET_break (0);
2119 _("Unsupported HTTP method `%s'\n"),
2120 meth);
2121 curl_easy_cleanup(s5r->curl);
2122 s5r->curl = NULL;
2123 return MHD_NO; 1894 return MHD_NO;
2124 } 1895 }
1896 GNUNET_snprintf (ipaddr,
1897 sizeof(ipaddr),
1898 "%s",
1899 ipstring);
1900 port = ntohs (s6->sin6_port);
1901 break;
2125 1902
2126 if (0 == strcasecmp(ver, MHD_HTTP_VERSION_1_0)) 1903 default:
1904 GNUNET_break (0);
1905 return MHD_NO;
1906 }
1907 }
1908 else
1909 {
1910 port = s5r->port;
1911 }
1912 if (NULL == s5r->curl)
1913 s5r->curl = curl_easy_init ();
1914 if (NULL == s5r->curl)
1915 return MHD_queue_response (con,
1916 MHD_HTTP_INTERNAL_SERVER_ERROR,
1917 curl_failure_response);
1918 curl_easy_setopt (s5r->curl,
1919 CURLOPT_HEADERFUNCTION,
1920 &curl_check_hdr);
1921 curl_easy_setopt (s5r->curl,
1922 CURLOPT_HEADERDATA,
1923 s5r);
1924 curl_easy_setopt (s5r->curl,
1925 CURLOPT_FOLLOWLOCATION,
1926 0);
1927 if (s5r->is_gns)
1928 curl_easy_setopt (s5r->curl,
1929 CURLOPT_IPRESOLVE,
1930 CURL_IPRESOLVE_V4);
1931 curl_easy_setopt (s5r->curl,
1932 CURLOPT_CONNECTTIMEOUT,
1933 600L);
1934 curl_easy_setopt (s5r->curl,
1935 CURLOPT_TIMEOUT,
1936 600L);
1937 curl_easy_setopt (s5r->curl,
1938 CURLOPT_NOSIGNAL,
1939 1L);
1940 curl_easy_setopt (s5r->curl,
1941 CURLOPT_HTTP_CONTENT_DECODING,
1942 0);
1943 curl_easy_setopt (s5r->curl,
1944 CURLOPT_NOSIGNAL,
1945 1L);
1946 curl_easy_setopt (s5r->curl,
1947 CURLOPT_PRIVATE,
1948 s5r);
1949 curl_easy_setopt (s5r->curl,
1950 CURLOPT_VERBOSE,
1951 0L);
1952 /**
1953 * Pre-populate cache to resolve Hostname.
1954 * This is necessary as the DNS name in the CURLOPT_URL is used
1955 * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication
1956 */
1957 if (NULL != s5r->leho)
1958 {
1959 char *curl_hosts;
1960
1961 GNUNET_asprintf (&curl_hosts,
1962 "%s:%d:%s",
1963 s5r->leho,
1964 port,
1965 ipaddr);
1966 s5r->hosts = curl_slist_append (NULL,
1967 curl_hosts);
1968 curl_easy_setopt (s5r->curl,
1969 CURLOPT_RESOLVE,
1970 s5r->hosts);
1971 GNUNET_free (curl_hosts);
1972 }
1973 if (s5r->is_gns)
1974 {
1975 GNUNET_asprintf (&curlurl,
1976 (GNUNET_YES != s5r->is_tls) // (HTTPS_PORT != s5r->port)
1977 ? "http://%s:%d%s"
1978 : "https://%s:%d%s",
1979 (NULL != s5r->leho)
1980 ? s5r->leho
1981 : ipaddr,
1982 port,
1983 s5r->url);
1984 }
1985 else
1986 {
1987 GNUNET_asprintf (&curlurl,
1988 (GNUNET_YES != s5r->is_tls) // (HTTPS_PORT != s5r->port)
1989 ? "http://%s:%d%s"
1990 : "https://%s:%d%s",
1991 s5r->domain,
1992 port,
1993 s5r->url);
1994 }
1995 curl_easy_setopt (s5r->curl,
1996 CURLOPT_URL,
1997 curlurl);
1998 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1999 "Launching %s CURL interaction, fetching `%s'\n",
2000 (s5r->is_gns) ? "GNS" : "DNS",
2001 curlurl);
2002 GNUNET_free (curlurl);
2003 if (0 == strcasecmp (meth,
2004 MHD_HTTP_METHOD_PUT))
2005 {
2006 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
2007 curl_easy_setopt (s5r->curl,
2008 CURLOPT_UPLOAD,
2009 1L);
2010 curl_easy_setopt (s5r->curl,
2011 CURLOPT_WRITEFUNCTION,
2012 &curl_download_cb);
2013 curl_easy_setopt (s5r->curl,
2014 CURLOPT_WRITEDATA,
2015 s5r);
2016 GNUNET_assert (CURLE_OK ==
2017 curl_easy_setopt (s5r->curl,
2018 CURLOPT_READFUNCTION,
2019 &curl_upload_cb));
2020 curl_easy_setopt (s5r->curl,
2021 CURLOPT_READDATA,
2022 s5r);
2023 {
2024 const char *us;
2025 long upload_size = 0;
2026
2027 us = MHD_lookup_connection_value (con,
2028 MHD_HEADER_KIND,
2029 MHD_HTTP_HEADER_CONTENT_LENGTH);
2030 if ((1 == sscanf (us,
2031 "%ld",
2032 &upload_size)) &&
2033 (upload_size >= 0))
2127 { 2034 {
2128 curl_easy_setopt(s5r->curl, 2035 curl_easy_setopt (s5r->curl,
2129 CURLOPT_HTTP_VERSION, 2036 CURLOPT_INFILESIZE,
2130 CURL_HTTP_VERSION_1_0); 2037 upload_size);
2131 } 2038 }
2132 else if (0 == strcasecmp(ver, MHD_HTTP_VERSION_1_1)) 2039 }
2040 }
2041 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST))
2042 {
2043 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
2044 curl_easy_setopt (s5r->curl,
2045 CURLOPT_POST,
2046 1L);
2047 curl_easy_setopt (s5r->curl,
2048 CURLOPT_WRITEFUNCTION,
2049 &curl_download_cb);
2050 curl_easy_setopt (s5r->curl,
2051 CURLOPT_WRITEDATA,
2052 s5r);
2053 curl_easy_setopt (s5r->curl,
2054 CURLOPT_READFUNCTION,
2055 &curl_upload_cb);
2056 curl_easy_setopt (s5r->curl,
2057 CURLOPT_READDATA,
2058 s5r);
2059 {
2060 const char *us;
2061 long upload_size;
2062
2063 upload_size = 0;
2064 us = MHD_lookup_connection_value (con,
2065 MHD_HEADER_KIND,
2066 MHD_HTTP_HEADER_CONTENT_LENGTH);
2067 if ((NULL != us) &&
2068 (1 == sscanf (us,
2069 "%ld",
2070 &upload_size)) &&
2071 (upload_size >= 0))
2133 { 2072 {
2134 curl_easy_setopt(s5r->curl, 2073 curl_easy_setopt (s5r->curl,
2135 CURLOPT_HTTP_VERSION, 2074 CURLOPT_INFILESIZE,
2136 CURL_HTTP_VERSION_1_1); 2075 upload_size);
2137 } 2076 }
2138 else 2077 else
2139 { 2078 {
2140 curl_easy_setopt(s5r->curl, 2079 curl_easy_setopt (s5r->curl,
2141 CURLOPT_HTTP_VERSION, 2080 CURLOPT_INFILESIZE,
2142 CURL_HTTP_VERSION_NONE); 2081 upload_size);
2143 } 2082 }
2083 }
2084 }
2085 else if (0 == strcasecmp (meth,
2086 MHD_HTTP_METHOD_HEAD))
2087 {
2088 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2089 curl_easy_setopt (s5r->curl,
2090 CURLOPT_NOBODY,
2091 1L);
2092 }
2093 else if (0 == strcasecmp (meth,
2094 MHD_HTTP_METHOD_OPTIONS))
2095 {
2096 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2097 curl_easy_setopt (s5r->curl,
2098 CURLOPT_CUSTOMREQUEST,
2099 "OPTIONS");
2100 curl_easy_setopt (s5r->curl,
2101 CURLOPT_WRITEFUNCTION,
2102 &curl_download_cb);
2103 curl_easy_setopt (s5r->curl,
2104 CURLOPT_WRITEDATA,
2105 s5r);
2106 }
2107 else if (0 == strcasecmp (meth,
2108 MHD_HTTP_METHOD_GET))
2109 {
2110 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2111 curl_easy_setopt (s5r->curl,
2112 CURLOPT_HTTPGET,
2113 1L);
2114 curl_easy_setopt (s5r->curl,
2115 CURLOPT_WRITEFUNCTION,
2116 &curl_download_cb);
2117 curl_easy_setopt (s5r->curl,
2118 CURLOPT_WRITEDATA,
2119 s5r);
2120 }
2121 else if (0 == strcasecmp (meth,
2122 MHD_HTTP_METHOD_DELETE))
2123 {
2124 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2125 curl_easy_setopt (s5r->curl,
2126 CURLOPT_CUSTOMREQUEST,
2127 "DELETE");
2128 curl_easy_setopt (s5r->curl,
2129 CURLOPT_WRITEFUNCTION,
2130 &curl_download_cb);
2131 curl_easy_setopt (s5r->curl,
2132 CURLOPT_WRITEDATA,
2133 s5r);
2134 }
2135 else
2136 {
2137 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2138 _ ("Unsupported HTTP method `%s'\n"),
2139 meth);
2140 curl_easy_cleanup (s5r->curl);
2141 s5r->curl = NULL;
2142 return MHD_NO;
2143 }
2144 2144
2145 if (GNUNET_YES == s5r->is_tls) //(HTTPS_PORT == s5r->port) 2145 if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0))
2146 { 2146 {
2147 curl_easy_setopt(s5r->curl, 2147 curl_easy_setopt (s5r->curl,
2148 CURLOPT_USE_SSL, 2148 CURLOPT_HTTP_VERSION,
2149 CURLUSESSL_ALL); 2149 CURL_HTTP_VERSION_1_0);
2150 if (0 < s5r->num_danes) 2150 }
2151 curl_easy_setopt(s5r->curl, 2151 else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1))
2152 CURLOPT_SSL_VERIFYPEER, 2152 {
2153 0L); 2153 curl_easy_setopt (s5r->curl,
2154 else 2154 CURLOPT_HTTP_VERSION,
2155 curl_easy_setopt(s5r->curl, 2155 CURL_HTTP_VERSION_1_1);
2156 CURLOPT_SSL_VERIFYPEER, 2156 }
2157 1L); 2157 else
2158 /* Disable cURL checking the hostname, as we will check ourselves 2158 {
2159 as only we have the domain name or the LEHO or the DANE record */ 2159 curl_easy_setopt (s5r->curl,
2160 curl_easy_setopt(s5r->curl, 2160 CURLOPT_HTTP_VERSION,
2161 CURLOPT_SSL_VERIFYHOST, 2161 CURL_HTTP_VERSION_NONE);
2162 0L); 2162 }
2163 } 2163
2164 if (GNUNET_YES == s5r->is_tls) // (HTTPS_PORT == s5r->port)
2165 {
2166 curl_easy_setopt (s5r->curl,
2167 CURLOPT_USE_SSL,
2168 CURLUSESSL_ALL);
2169 if (0 < s5r->num_danes)
2170 curl_easy_setopt (s5r->curl,
2171 CURLOPT_SSL_VERIFYPEER,
2172 0L);
2164 else 2173 else
2165 { 2174 curl_easy_setopt (s5r->curl,
2166 curl_easy_setopt(s5r->curl, 2175 CURLOPT_SSL_VERIFYPEER,
2167 CURLOPT_USE_SSL, 2176 1L);
2168 CURLUSESSL_NONE); 2177 /* Disable cURL checking the hostname, as we will check ourselves
2169 } 2178 as only we have the domain name or the LEHO or the DANE record */
2179 curl_easy_setopt (s5r->curl,
2180 CURLOPT_SSL_VERIFYHOST,
2181 0L);
2182 }
2183 else
2184 {
2185 curl_easy_setopt (s5r->curl,
2186 CURLOPT_USE_SSL,
2187 CURLUSESSL_NONE);
2188 }
2170 2189
2171 if (CURLM_OK != 2190 if (CURLM_OK !=
2172 curl_multi_add_handle(curl_multi, 2191 curl_multi_add_handle (curl_multi,
2173 s5r->curl)) 2192 s5r->curl))
2174 { 2193 {
2175 GNUNET_break(0); 2194 GNUNET_break (0);
2176 curl_easy_cleanup(s5r->curl); 2195 curl_easy_cleanup (s5r->curl);
2177 s5r->curl = NULL; 2196 s5r->curl = NULL;
2178 return MHD_NO; 2197 return MHD_NO;
2179 }
2180 MHD_get_connection_values(con,
2181 MHD_HEADER_KIND,
2182 (MHD_KeyValueIterator) & con_val_iter,
2183 s5r);
2184 curl_easy_setopt(s5r->curl,
2185 CURLOPT_HTTPHEADER,
2186 s5r->headers);
2187 curl_download_prepare();
2188 return MHD_YES;
2189 } 2198 }
2199 MHD_get_connection_values (con,
2200 MHD_HEADER_KIND,
2201 (MHD_KeyValueIterator) & con_val_iter,
2202 s5r);
2203 curl_easy_setopt (s5r->curl,
2204 CURLOPT_HTTPHEADER,
2205 s5r->headers);
2206 curl_download_prepare ();
2207 return MHD_YES;
2208 }
2190 2209
2191 /* continuing to process request */ 2210 /* continuing to process request */
2192 if (0 != *upload_data_size) 2211 if (0 != *upload_data_size)
2212 {
2213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2214 "Processing %u bytes UPLOAD\n",
2215 (unsigned int) *upload_data_size);
2216
2217 /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else
2218 * upload callback is not called!
2219 */
2220 curl_easy_setopt (s5r->curl,
2221 CURLOPT_POSTFIELDSIZE,
2222 *upload_data_size);
2223
2224 left = GNUNET_MIN (*upload_data_size,
2225 sizeof(s5r->io_buf) - s5r->io_len);
2226 GNUNET_memcpy (&s5r->io_buf[s5r->io_len],
2227 upload_data,
2228 left);
2229 s5r->io_len += left;
2230 *upload_data_size -= left;
2231 GNUNET_assert (NULL != s5r->curl);
2232 if (GNUNET_YES == s5r->curl_paused)
2193 { 2233 {
2194 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2234 s5r->curl_paused = GNUNET_NO;
2195 "Processing %u bytes UPLOAD\n", 2235 curl_easy_pause (s5r->curl,
2196 (unsigned int)*upload_data_size); 2236 CURLPAUSE_CONT);
2197
2198 /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else
2199 * upload callback is not called!
2200 */
2201 curl_easy_setopt(s5r->curl,
2202 CURLOPT_POSTFIELDSIZE,
2203 *upload_data_size);
2204
2205 left = GNUNET_MIN(*upload_data_size,
2206 sizeof(s5r->io_buf) - s5r->io_len);
2207 GNUNET_memcpy(&s5r->io_buf[s5r->io_len],
2208 upload_data,
2209 left);
2210 s5r->io_len += left;
2211 *upload_data_size -= left;
2212 GNUNET_assert(NULL != s5r->curl);
2213 if (GNUNET_YES == s5r->curl_paused)
2214 {
2215 s5r->curl_paused = GNUNET_NO;
2216 curl_easy_pause(s5r->curl,
2217 CURLPAUSE_CONT);
2218 }
2219 return MHD_YES;
2220 } 2237 }
2238 return MHD_YES;
2239 }
2221 if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) 2240 if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state)
2222 { 2241 {
2223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2224 "Finished processing UPLOAD\n"); 2243 "Finished processing UPLOAD\n");
2225 s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; 2244 s5r->state = SOCKS5_SOCKET_UPLOAD_DONE;
2226 } 2245 }
2227 if (NULL == s5r->response) 2246 if (NULL == s5r->response)
2228 { 2247 {
2229 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2230 "Waiting for HTTP response for %s%s...\n", 2249 "Waiting for HTTP response for %s%s...\n",
2231 s5r->domain, 2250 s5r->domain,
2232 s5r->url); 2251 s5r->url);
2233 MHD_suspend_connection(con); 2252 MHD_suspend_connection (con);
2234 s5r->suspended = GNUNET_YES; 2253 s5r->suspended = GNUNET_YES;
2235 return MHD_YES; 2254 return MHD_YES;
2236 } 2255 }
2237 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2238 "Queueing response for %s%s with MHD\n", 2257 "Queueing response for %s%s with MHD\n",
2239 s5r->domain, 2258 s5r->domain,
2240 s5r->url); 2259 s5r->url);
2241 run_mhd_now(s5r->hd); 2260 run_mhd_now (s5r->hd);
2242 return MHD_queue_response(con, 2261 return MHD_queue_response (con,
2243 s5r->response_code, 2262 s5r->response_code,
2244 s5r->response); 2263 s5r->response);
2245} 2264}
2246 2265
2247 2266
@@ -2258,51 +2277,51 @@ create_response(void *cls,
2258 * @param toe reason for request termination (ignored) 2277 * @param toe reason for request termination (ignored)
2259 */ 2278 */
2260static void 2279static void
2261mhd_completed_cb(void *cls, 2280mhd_completed_cb (void *cls,
2262 struct MHD_Connection *connection, 2281 struct MHD_Connection *connection,
2263 void **con_cls, 2282 void **con_cls,
2264 enum MHD_RequestTerminationCode toe) 2283 enum MHD_RequestTerminationCode toe)
2265{ 2284{
2266 struct Socks5Request *s5r = *con_cls; 2285 struct Socks5Request *s5r = *con_cls;
2267 2286
2268 if (NULL == s5r) 2287 if (NULL == s5r)
2269 return; 2288 return;
2270 if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) 2289 if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe)
2271 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2272 "MHD encountered error handling request: %d\n", 2291 "MHD encountered error handling request: %d\n",
2273 toe); 2292 toe);
2274 if (NULL != s5r->curl) 2293 if (NULL != s5r->curl)
2275 { 2294 {
2276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2277 "Removing cURL handle (MHD interaction complete)\n"); 2296 "Removing cURL handle (MHD interaction complete)\n");
2278 curl_multi_remove_handle(curl_multi, 2297 curl_multi_remove_handle (curl_multi,
2279 s5r->curl); 2298 s5r->curl);
2280 curl_slist_free_all(s5r->headers); 2299 curl_slist_free_all (s5r->headers);
2281 s5r->headers = NULL; 2300 s5r->headers = NULL;
2282 curl_easy_reset(s5r->curl); 2301 curl_easy_reset (s5r->curl);
2283 s5r->rbuf_len = 0; 2302 s5r->rbuf_len = 0;
2284 s5r->wbuf_len = 0; 2303 s5r->wbuf_len = 0;
2285 s5r->io_len = 0; 2304 s5r->io_len = 0;
2286 curl_download_prepare(); 2305 curl_download_prepare ();
2287 } 2306 }
2288 if ((NULL != s5r->response) && 2307 if ((NULL != s5r->response) &&
2289 (curl_failure_response != s5r->response)) 2308 (curl_failure_response != s5r->response))
2290 MHD_destroy_response(s5r->response); 2309 MHD_destroy_response (s5r->response);
2291 for (struct HttpResponseHeader *header = s5r->header_head; 2310 for (struct HttpResponseHeader *header = s5r->header_head;
2292 NULL != header; 2311 NULL != header;
2293 header = s5r->header_head) 2312 header = s5r->header_head)
2294 { 2313 {
2295 GNUNET_CONTAINER_DLL_remove(s5r->header_head, 2314 GNUNET_CONTAINER_DLL_remove (s5r->header_head,
2296 s5r->header_tail, 2315 s5r->header_tail,
2297 header); 2316 header);
2298 GNUNET_free(header->type); 2317 GNUNET_free (header->type);
2299 GNUNET_free(header->value); 2318 GNUNET_free (header->value);
2300 GNUNET_free(header); 2319 GNUNET_free (header);
2301 } 2320 }
2302 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2303 "Finished request for %s\n", 2322 "Finished request for %s\n",
2304 s5r->url); 2323 s5r->url);
2305 GNUNET_free(s5r->url); 2324 GNUNET_free (s5r->url);
2306 s5r->state = SOCKS5_SOCKET_WITH_MHD; 2325 s5r->state = SOCKS5_SOCKET_WITH_MHD;
2307 s5r->url = NULL; 2326 s5r->url = NULL;
2308 s5r->response = NULL; 2327 s5r->response = NULL;
@@ -2320,58 +2339,58 @@ mhd_completed_cb(void *cls,
2320 * @param toe connection notification type 2339 * @param toe connection notification type
2321 */ 2340 */
2322static void 2341static void
2323mhd_connection_cb(void *cls, 2342mhd_connection_cb (void *cls,
2324 struct MHD_Connection *connection, 2343 struct MHD_Connection *connection,
2325 void **con_cls, 2344 void **con_cls,
2326 enum MHD_ConnectionNotificationCode cnc) 2345 enum MHD_ConnectionNotificationCode cnc)
2327{ 2346{
2328 struct Socks5Request *s5r; 2347 struct Socks5Request *s5r;
2329 const union MHD_ConnectionInfo *ci; 2348 const union MHD_ConnectionInfo *ci;
2330 int sock; 2349 int sock;
2331 2350
2332 switch (cnc) 2351 switch (cnc)
2352 {
2353 case MHD_CONNECTION_NOTIFY_STARTED:
2354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection started...\n");
2355 ci = MHD_get_connection_info (connection,
2356 MHD_CONNECTION_INFO_CONNECTION_FD);
2357 if (NULL == ci)
2333 { 2358 {
2334 case MHD_CONNECTION_NOTIFY_STARTED: 2359 GNUNET_break (0);
2335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connection started...\n"); 2360 return;
2336 ci = MHD_get_connection_info(connection, 2361 }
2337 MHD_CONNECTION_INFO_CONNECTION_FD); 2362 sock = ci->connect_fd;
2338 if (NULL == ci) 2363 for (s5r = s5r_head; NULL != s5r; s5r = s5r->next)
2339 { 2364 {
2340 GNUNET_break(0); 2365 if (GNUNET_NETWORK_get_fd (s5r->sock) == sock)
2341 return; 2366 {
2342 } 2367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2343 sock = ci->connect_fd; 2368 "Context set...\n");
2344 for (s5r = s5r_head; NULL != s5r; s5r = s5r->next) 2369 s5r->ssl_checked = GNUNET_NO;
2345 { 2370 *con_cls = s5r;
2346 if (GNUNET_NETWORK_get_fd(s5r->sock) == sock) 2371 break;
2347 { 2372 }
2348 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2373 }
2349 "Context set...\n"); 2374 break;
2350 s5r->ssl_checked = GNUNET_NO;
2351 *con_cls = s5r;
2352 break;
2353 }
2354 }
2355 break;
2356
2357 case MHD_CONNECTION_NOTIFY_CLOSED:
2358 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2359 "Connection closed... cleaning up\n");
2360 s5r = *con_cls;
2361 if (NULL == s5r)
2362 {
2363 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2364 "Connection stale!\n");
2365 return;
2366 }
2367 cleanup_s5r(s5r);
2368 curl_download_prepare();
2369 *con_cls = NULL;
2370 break;
2371 2375
2372 default: 2376 case MHD_CONNECTION_NOTIFY_CLOSED:
2373 GNUNET_break(0); 2377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2378 "Connection closed... cleaning up\n");
2379 s5r = *con_cls;
2380 if (NULL == s5r)
2381 {
2382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2383 "Connection stale!\n");
2384 return;
2374 } 2385 }
2386 cleanup_s5r (s5r);
2387 curl_download_prepare ();
2388 *con_cls = NULL;
2389 break;
2390
2391 default:
2392 GNUNET_break (0);
2393 }
2375} 2394}
2376 2395
2377/** 2396/**
@@ -2388,34 +2407,34 @@ mhd_connection_cb(void *cls,
2388 * @return the `struct Socks5Request` that this @a connection is for 2407 * @return the `struct Socks5Request` that this @a connection is for
2389 */ 2408 */
2390static void * 2409static void *
2391mhd_log_callback(void *cls, 2410mhd_log_callback (void *cls,
2392 const char *url, 2411 const char *url,
2393 struct MHD_Connection *connection) 2412 struct MHD_Connection *connection)
2394{ 2413{
2395 struct Socks5Request *s5r; 2414 struct Socks5Request *s5r;
2396 const union MHD_ConnectionInfo *ci; 2415 const union MHD_ConnectionInfo *ci;
2397 2416
2398 ci = MHD_get_connection_info(connection, 2417 ci = MHD_get_connection_info (connection,
2399 MHD_CONNECTION_INFO_SOCKET_CONTEXT); 2418 MHD_CONNECTION_INFO_SOCKET_CONTEXT);
2400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing %s\n", url); 2419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing %s\n", url);
2401 if (NULL == ci) 2420 if (NULL == ci)
2402 { 2421 {
2403 GNUNET_break(0); 2422 GNUNET_break (0);
2404 return NULL; 2423 return NULL;
2405 } 2424 }
2406 s5r = ci->socket_context; 2425 s5r = ci->socket_context;
2407 if (NULL != s5r->url) 2426 if (NULL != s5r->url)
2408 { 2427 {
2409 GNUNET_break(0); 2428 GNUNET_break (0);
2410 return NULL; 2429 return NULL;
2411 } 2430 }
2412 s5r->url = GNUNET_strdup(url); 2431 s5r->url = GNUNET_strdup (url);
2413 if (NULL != s5r->timeout_task) 2432 if (NULL != s5r->timeout_task)
2414 { 2433 {
2415 GNUNET_SCHEDULER_cancel(s5r->timeout_task); 2434 GNUNET_SCHEDULER_cancel (s5r->timeout_task);
2416 s5r->timeout_task = NULL; 2435 s5r->timeout_task = NULL;
2417 } 2436 }
2418 GNUNET_assert(s5r->state == SOCKS5_SOCKET_WITH_MHD); 2437 GNUNET_assert (s5r->state == SOCKS5_SOCKET_WITH_MHD);
2419 return s5r; 2438 return s5r;
2420} 2439}
2421 2440
@@ -2426,22 +2445,22 @@ mhd_log_callback(void *cls,
2426 * @param hd daemon to stop 2445 * @param hd daemon to stop
2427 */ 2446 */
2428static void 2447static void
2429kill_httpd(struct MhdHttpList *hd) 2448kill_httpd (struct MhdHttpList *hd)
2430{ 2449{
2431 GNUNET_CONTAINER_DLL_remove(mhd_httpd_head, 2450 GNUNET_CONTAINER_DLL_remove (mhd_httpd_head,
2432 mhd_httpd_tail, 2451 mhd_httpd_tail,
2433 hd); 2452 hd);
2434 GNUNET_free_non_null(hd->domain); 2453 GNUNET_free_non_null (hd->domain);
2435 MHD_stop_daemon(hd->daemon); 2454 MHD_stop_daemon (hd->daemon);
2436 if (NULL != hd->httpd_task) 2455 if (NULL != hd->httpd_task)
2437 { 2456 {
2438 GNUNET_SCHEDULER_cancel(hd->httpd_task); 2457 GNUNET_SCHEDULER_cancel (hd->httpd_task);
2439 hd->httpd_task = NULL; 2458 hd->httpd_task = NULL;
2440 } 2459 }
2441 GNUNET_free_non_null(hd->proxy_cert); 2460 GNUNET_free_non_null (hd->proxy_cert);
2442 if (hd == httpd) 2461 if (hd == httpd)
2443 httpd = NULL; 2462 httpd = NULL;
2444 GNUNET_free(hd); 2463 GNUNET_free (hd);
2445} 2464}
2446 2465
2447 2466
@@ -2451,12 +2470,12 @@ kill_httpd(struct MhdHttpList *hd)
2451 * @param cls the `struct MhdHttpList *` 2470 * @param cls the `struct MhdHttpList *`
2452 */ 2471 */
2453static void 2472static void
2454kill_httpd_task(void *cls) 2473kill_httpd_task (void *cls)
2455{ 2474{
2456 struct MhdHttpList *hd = cls; 2475 struct MhdHttpList *hd = cls;
2457 2476
2458 hd->httpd_task = NULL; 2477 hd->httpd_task = NULL;
2459 kill_httpd(hd); 2478 kill_httpd (hd);
2460} 2479}
2461 2480
2462 2481
@@ -2466,7 +2485,7 @@ kill_httpd_task(void *cls)
2466 * @param cls the `struct MhdHttpList *` of the daemon that is being run 2485 * @param cls the `struct MhdHttpList *` of the daemon that is being run
2467 */ 2486 */
2468static void 2487static void
2469do_httpd(void *cls); 2488do_httpd (void *cls);
2470 2489
2471 2490
2472/** 2491/**
@@ -2477,7 +2496,7 @@ do_httpd(void *cls);
2477 * @param hd the daemon to schedule 2496 * @param hd the daemon to schedule
2478 */ 2497 */
2479static void 2498static void
2480schedule_httpd(struct MhdHttpList *hd) 2499schedule_httpd (struct MhdHttpList *hd)
2481{ 2500{
2482 fd_set rs; 2501 fd_set rs;
2483 fd_set ws; 2502 fd_set ws;
@@ -2489,63 +2508,63 @@ schedule_httpd(struct MhdHttpList *hd)
2489 MHD_UNSIGNED_LONG_LONG timeout; 2508 MHD_UNSIGNED_LONG_LONG timeout;
2490 struct GNUNET_TIME_Relative tv; 2509 struct GNUNET_TIME_Relative tv;
2491 2510
2492 FD_ZERO(&rs); 2511 FD_ZERO (&rs);
2493 FD_ZERO(&ws); 2512 FD_ZERO (&ws);
2494 FD_ZERO(&es); 2513 FD_ZERO (&es);
2495 max = -1; 2514 max = -1;
2496 if (MHD_YES != 2515 if (MHD_YES !=
2497 MHD_get_fdset(hd->daemon, 2516 MHD_get_fdset (hd->daemon,
2498 &rs, 2517 &rs,
2499 &ws, 2518 &ws,
2500 &es, 2519 &es,
2501 &max)) 2520 &max))
2502 { 2521 {
2503 kill_httpd(hd); 2522 kill_httpd (hd);
2504 return; 2523 return;
2505 } 2524 }
2506 haveto = MHD_get_timeout(hd->daemon, 2525 haveto = MHD_get_timeout (hd->daemon,
2507 &timeout); 2526 &timeout);
2508 if (MHD_YES == haveto) 2527 if (MHD_YES == haveto)
2509 tv.rel_value_us = (uint64_t)timeout * 1000LL; 2528 tv.rel_value_us = (uint64_t) timeout * 1000LL;
2510 else 2529 else
2511 tv = GNUNET_TIME_UNIT_FOREVER_REL; 2530 tv = GNUNET_TIME_UNIT_FOREVER_REL;
2512 if (-1 != max) 2531 if (-1 != max)
2513 { 2532 {
2514 wrs = GNUNET_NETWORK_fdset_create(); 2533 wrs = GNUNET_NETWORK_fdset_create ();
2515 wws = GNUNET_NETWORK_fdset_create(); 2534 wws = GNUNET_NETWORK_fdset_create ();
2516 GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); 2535 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
2517 GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); 2536 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
2518 } 2537 }
2519 else 2538 else
2520 { 2539 {
2521 wrs = NULL; 2540 wrs = NULL;
2522 wws = NULL; 2541 wws = NULL;
2523 } 2542 }
2524 if (NULL != hd->httpd_task) 2543 if (NULL != hd->httpd_task)
2525 { 2544 {
2526 GNUNET_SCHEDULER_cancel(hd->httpd_task); 2545 GNUNET_SCHEDULER_cancel (hd->httpd_task);
2527 hd->httpd_task = NULL; 2546 hd->httpd_task = NULL;
2528 } 2547 }
2529 if ((MHD_YES != haveto) && 2548 if ((MHD_YES != haveto) &&
2530 (-1 == max) && 2549 (-1 == max) &&
2531 (hd != httpd)) 2550 (hd != httpd))
2532 { 2551 {
2533 /* daemon is idle, kill after timeout */ 2552 /* daemon is idle, kill after timeout */
2534 hd->httpd_task = GNUNET_SCHEDULER_add_delayed(MHD_CACHE_TIMEOUT, 2553 hd->httpd_task = GNUNET_SCHEDULER_add_delayed (MHD_CACHE_TIMEOUT,
2535 &kill_httpd_task, 2554 &kill_httpd_task,
2536 hd); 2555 hd);
2537 } 2556 }
2538 else 2557 else
2539 { 2558 {
2540 hd->httpd_task = 2559 hd->httpd_task =
2541 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 2560 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
2542 tv, wrs, wws, 2561 tv, wrs, wws,
2543 &do_httpd, hd); 2562 &do_httpd, hd);
2544 } 2563 }
2545 if (NULL != wrs) 2564 if (NULL != wrs)
2546 GNUNET_NETWORK_fdset_destroy(wrs); 2565 GNUNET_NETWORK_fdset_destroy (wrs);
2547 if (NULL != wws) 2566 if (NULL != wws)
2548 GNUNET_NETWORK_fdset_destroy(wws); 2567 GNUNET_NETWORK_fdset_destroy (wws);
2549} 2568}
2550 2569
2551 2570
@@ -2555,13 +2574,13 @@ schedule_httpd(struct MhdHttpList *hd)
2555 * @param cls the `struct MhdHttpList` of the daemon that is being run 2574 * @param cls the `struct MhdHttpList` of the daemon that is being run
2556 */ 2575 */
2557static void 2576static void
2558do_httpd(void *cls) 2577do_httpd (void *cls)
2559{ 2578{
2560 struct MhdHttpList *hd = cls; 2579 struct MhdHttpList *hd = cls;
2561 2580
2562 hd->httpd_task = NULL; 2581 hd->httpd_task = NULL;
2563 MHD_run(hd->daemon); 2582 MHD_run (hd->daemon);
2564 schedule_httpd(hd); 2583 schedule_httpd (hd);
2565} 2584}
2566 2585
2567 2586
@@ -2571,12 +2590,12 @@ do_httpd(void *cls)
2571 * @param hd the daemon to run now. 2590 * @param hd the daemon to run now.
2572 */ 2591 */
2573static void 2592static void
2574run_mhd_now(struct MhdHttpList *hd) 2593run_mhd_now (struct MhdHttpList *hd)
2575{ 2594{
2576 if (NULL != hd->httpd_task) 2595 if (NULL != hd->httpd_task)
2577 GNUNET_SCHEDULER_cancel(hd->httpd_task); 2596 GNUNET_SCHEDULER_cancel (hd->httpd_task);
2578 hd->httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, 2597 hd->httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd,
2579 hd); 2598 hd);
2580} 2599}
2581 2600
2582 2601
@@ -2588,30 +2607,30 @@ run_mhd_now(struct MhdHttpList *hd)
2588 * @return NULL on error 2607 * @return NULL on error
2589 */ 2608 */
2590static void* 2609static void*
2591load_file(const char* filename, 2610load_file (const char*filename,
2592 unsigned int* size) 2611 unsigned int*size)
2593{ 2612{
2594 void *buffer; 2613 void *buffer;
2595 uint64_t fsize; 2614 uint64_t fsize;
2596 2615
2597 if (GNUNET_OK != 2616 if (GNUNET_OK !=
2598 GNUNET_DISK_file_size(filename, 2617 GNUNET_DISK_file_size (filename,
2599 &fsize, 2618 &fsize,
2600 GNUNET_YES, 2619 GNUNET_YES,
2601 GNUNET_YES)) 2620 GNUNET_YES))
2602 return NULL; 2621 return NULL;
2603 if (fsize > MAX_PEM_SIZE) 2622 if (fsize > MAX_PEM_SIZE)
2604 return NULL; 2623 return NULL;
2605 *size = (unsigned int)fsize; 2624 *size = (unsigned int) fsize;
2606 buffer = GNUNET_malloc(*size); 2625 buffer = GNUNET_malloc (*size);
2607 if (fsize != 2626 if (fsize !=
2608 GNUNET_DISK_fn_read(filename, 2627 GNUNET_DISK_fn_read (filename,
2609 buffer, 2628 buffer,
2610 (size_t)fsize)) 2629 (size_t) fsize))
2611 { 2630 {
2612 GNUNET_free(buffer); 2631 GNUNET_free (buffer);
2613 return NULL; 2632 return NULL;
2614 } 2633 }
2615 return buffer; 2634 return buffer;
2616} 2635}
2617 2636
@@ -2624,25 +2643,25 @@ load_file(const char* filename,
2624 * @return #GNUNET_OK on success 2643 * @return #GNUNET_OK on success
2625 */ 2644 */
2626static int 2645static int
2627load_key_from_file(gnutls_x509_privkey_t key, 2646load_key_from_file (gnutls_x509_privkey_t key,
2628 const char* keyfile) 2647 const char*keyfile)
2629{ 2648{
2630 gnutls_datum_t key_data; 2649 gnutls_datum_t key_data;
2631 int ret; 2650 int ret;
2632 2651
2633 key_data.data = load_file(keyfile, 2652 key_data.data = load_file (keyfile,
2634 &key_data.size); 2653 &key_data.size);
2635 if (NULL == key_data.data) 2654 if (NULL == key_data.data)
2636 return GNUNET_SYSERR; 2655 return GNUNET_SYSERR;
2637 ret = gnutls_x509_privkey_import(key, &key_data, 2656 ret = gnutls_x509_privkey_import (key, &key_data,
2638 GNUTLS_X509_FMT_PEM); 2657 GNUTLS_X509_FMT_PEM);
2639 if (GNUTLS_E_SUCCESS != ret) 2658 if (GNUTLS_E_SUCCESS != ret)
2640 { 2659 {
2641 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2660 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2642 _("Unable to import private key from file `%s'\n"), 2661 _ ("Unable to import private key from file `%s'\n"),
2643 keyfile); 2662 keyfile);
2644 } 2663 }
2645 GNUNET_free_non_null(key_data.data); 2664 GNUNET_free_non_null (key_data.data);
2646 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; 2665 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
2647} 2666}
2648 2667
@@ -2655,26 +2674,26 @@ load_key_from_file(gnutls_x509_privkey_t key,
2655 * @return #GNUNET_OK on success 2674 * @return #GNUNET_OK on success
2656 */ 2675 */
2657static int 2676static int
2658load_cert_from_file(gnutls_x509_crt_t crt, 2677load_cert_from_file (gnutls_x509_crt_t crt,
2659 const char* certfile) 2678 const char*certfile)
2660{ 2679{
2661 gnutls_datum_t cert_data; 2680 gnutls_datum_t cert_data;
2662 int ret; 2681 int ret;
2663 2682
2664 cert_data.data = load_file(certfile, 2683 cert_data.data = load_file (certfile,
2665 &cert_data.size); 2684 &cert_data.size);
2666 if (NULL == cert_data.data) 2685 if (NULL == cert_data.data)
2667 return GNUNET_SYSERR; 2686 return GNUNET_SYSERR;
2668 ret = gnutls_x509_crt_import(crt, 2687 ret = gnutls_x509_crt_import (crt,
2669 &cert_data, 2688 &cert_data,
2670 GNUTLS_X509_FMT_PEM); 2689 GNUTLS_X509_FMT_PEM);
2671 if (GNUTLS_E_SUCCESS != ret) 2690 if (GNUTLS_E_SUCCESS != ret)
2672 { 2691 {
2673 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2692 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2674 _("Unable to import certificate from `%s'\n"), 2693 _ ("Unable to import certificate from `%s'\n"),
2675 certfile); 2694 certfile);
2676 } 2695 }
2677 GNUNET_free_non_null(cert_data.data); 2696 GNUNET_free_non_null (cert_data.data);
2678 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; 2697 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
2679} 2698}
2680 2699
@@ -2686,7 +2705,7 @@ load_cert_from_file(gnutls_x509_crt_t crt,
2686 * @return a struct holding the PEM data, NULL on error 2705 * @return a struct holding the PEM data, NULL on error
2687 */ 2706 */
2688static struct ProxyGNSCertificate * 2707static struct ProxyGNSCertificate *
2689generate_gns_certificate(const char *name) 2708generate_gns_certificate (const char *name)
2690{ 2709{
2691 unsigned int serial; 2710 unsigned int serial;
2692 size_t key_buf_size; 2711 size_t key_buf_size;
@@ -2696,65 +2715,66 @@ generate_gns_certificate(const char *name)
2696 struct tm *tm_data; 2715 struct tm *tm_data;
2697 struct ProxyGNSCertificate *pgc; 2716 struct ProxyGNSCertificate *pgc;
2698 2717
2699 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2700 "Generating x.509 certificate for `%s'\n", 2719 "Generating x.509 certificate for `%s'\n",
2701 name); 2720 name);
2702 GNUNET_break(GNUTLS_E_SUCCESS == gnutls_x509_crt_init(&request)); 2721 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_init (&request));
2703 GNUNET_break(GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key(request, proxy_ca.key)); 2722 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key (request,
2704 pgc = GNUNET_new(struct ProxyGNSCertificate); 2723 proxy_ca.key));
2705 gnutls_x509_crt_set_dn_by_oid(request, 2724 pgc = GNUNET_new (struct ProxyGNSCertificate);
2706 GNUTLS_OID_X520_COUNTRY_NAME, 2725 gnutls_x509_crt_set_dn_by_oid (request,
2707 0, 2726 GNUTLS_OID_X520_COUNTRY_NAME,
2708 "ZZ", 2727 0,
2709 strlen("ZZ")); 2728 "ZZ",
2710 gnutls_x509_crt_set_dn_by_oid(request, 2729 strlen ("ZZ"));
2711 GNUTLS_OID_X520_ORGANIZATION_NAME, 2730 gnutls_x509_crt_set_dn_by_oid (request,
2712 0, 2731 GNUTLS_OID_X520_ORGANIZATION_NAME,
2713 "GNU Name System", 2732 0,
2714 strlen("GNU Name System")); 2733 "GNU Name System",
2715 gnutls_x509_crt_set_dn_by_oid(request, 2734 strlen ("GNU Name System"));
2716 GNUTLS_OID_X520_COMMON_NAME, 2735 gnutls_x509_crt_set_dn_by_oid (request,
2717 0, 2736 GNUTLS_OID_X520_COMMON_NAME,
2718 name, 2737 0,
2719 strlen(name)); 2738 name,
2720 gnutls_x509_crt_set_subject_alternative_name(request, 2739 strlen (name));
2721 GNUTLS_SAN_DNSNAME, 2740 gnutls_x509_crt_set_subject_alternative_name (request,
2722 name); 2741 GNUTLS_SAN_DNSNAME,
2723 GNUNET_break(GNUTLS_E_SUCCESS == 2742 name);
2724 gnutls_x509_crt_set_version(request, 2743 GNUNET_break (GNUTLS_E_SUCCESS ==
2725 3)); 2744 gnutls_x509_crt_set_version (request,
2726 gnutls_rnd(GNUTLS_RND_NONCE, 2745 3));
2727 &serial, 2746 gnutls_rnd (GNUTLS_RND_NONCE,
2728 sizeof(serial)); 2747 &serial,
2729 gnutls_x509_crt_set_serial(request, 2748 sizeof(serial));
2730 &serial, 2749 gnutls_x509_crt_set_serial (request,
2731 sizeof(serial)); 2750 &serial,
2732 etime = time(NULL); 2751 sizeof(serial));
2733 tm_data = localtime(&etime); 2752 etime = time (NULL);
2753 tm_data = localtime (&etime);
2734 tm_data->tm_hour--; 2754 tm_data->tm_hour--;
2735 etime = mktime(tm_data); 2755 etime = mktime (tm_data);
2736 gnutls_x509_crt_set_activation_time(request, 2756 gnutls_x509_crt_set_activation_time (request,
2737 etime); 2757 etime);
2738 tm_data->tm_year++; 2758 tm_data->tm_year++;
2739 etime = mktime(tm_data); 2759 etime = mktime (tm_data);
2740 gnutls_x509_crt_set_expiration_time(request, 2760 gnutls_x509_crt_set_expiration_time (request,
2741 etime); 2761 etime);
2742 gnutls_x509_crt_sign2(request, 2762 gnutls_x509_crt_sign2 (request,
2743 proxy_ca.cert, 2763 proxy_ca.cert,
2744 proxy_ca.key, 2764 proxy_ca.key,
2745 GNUTLS_DIG_SHA512, 2765 GNUTLS_DIG_SHA512,
2746 0); 2766 0);
2747 key_buf_size = sizeof(pgc->key); 2767 key_buf_size = sizeof(pgc->key);
2748 cert_buf_size = sizeof(pgc->cert); 2768 cert_buf_size = sizeof(pgc->cert);
2749 gnutls_x509_crt_export(request, 2769 gnutls_x509_crt_export (request,
2750 GNUTLS_X509_FMT_PEM, 2770 GNUTLS_X509_FMT_PEM,
2751 pgc->cert, 2771 pgc->cert,
2752 &cert_buf_size); 2772 &cert_buf_size);
2753 gnutls_x509_privkey_export(proxy_ca.key, 2773 gnutls_x509_privkey_export (proxy_ca.key,
2754 GNUTLS_X509_FMT_PEM, 2774 GNUTLS_X509_FMT_PEM,
2755 pgc->key, 2775 pgc->key,
2756 &key_buf_size); 2776 &key_buf_size);
2757 gnutls_x509_crt_deinit(request); 2777 gnutls_x509_crt_deinit (request);
2758 return pgc; 2778 return pgc;
2759} 2779}
2760 2780
@@ -2767,9 +2787,9 @@ generate_gns_certificate(const char *name)
2767 * @param ap arguments to @a fm 2787 * @param ap arguments to @a fm
2768 */ 2788 */
2769static void 2789static void
2770mhd_error_log_callback(void *cls, 2790mhd_error_log_callback (void *cls,
2771 const char *fm, 2791 const char *fm,
2772 va_list ap) 2792 va_list ap)
2773{ 2793{
2774 /* do nothing */ 2794 /* do nothing */
2775} 2795}
@@ -2782,49 +2802,56 @@ mhd_error_log_callback(void *cls,
2782 * @return NULL on error 2802 * @return NULL on error
2783 */ 2803 */
2784static struct MhdHttpList * 2804static struct MhdHttpList *
2785lookup_ssl_httpd(const char* domain) 2805lookup_ssl_httpd (const char*domain)
2786{ 2806{
2787 struct MhdHttpList *hd; 2807 struct MhdHttpList *hd;
2788 struct ProxyGNSCertificate *pgc; 2808 struct ProxyGNSCertificate *pgc;
2789 2809
2790 if (NULL == domain) 2810 if (NULL == domain)
2791 { 2811 {
2792 GNUNET_break(0); 2812 GNUNET_break (0);
2793 return NULL; 2813 return NULL;
2794 } 2814 }
2795 for (hd = mhd_httpd_head; NULL != hd; hd = hd->next) 2815 for (hd = mhd_httpd_head; NULL != hd; hd = hd->next)
2796 if ((NULL != hd->domain) && 2816 if ((NULL != hd->domain) &&
2797 (0 == strcmp(hd->domain, domain))) 2817 (0 == strcmp (hd->domain, domain)))
2798 return hd; 2818 return hd;
2799 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2800 "Starting fresh MHD HTTPS instance for domain `%s'\n", 2820 "Starting fresh MHD HTTPS instance for domain `%s'\n",
2801 domain); 2821 domain);
2802 pgc = generate_gns_certificate(domain); 2822 pgc = generate_gns_certificate (domain);
2803 hd = GNUNET_new(struct MhdHttpList); 2823 hd = GNUNET_new (struct MhdHttpList);
2804 hd->is_ssl = GNUNET_YES; 2824 hd->is_ssl = GNUNET_YES;
2805 hd->domain = GNUNET_strdup(domain); 2825 hd->domain = GNUNET_strdup (domain);
2806 hd->proxy_cert = pgc; 2826 hd->proxy_cert = pgc;
2807 hd->daemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, 2827 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL
2808 0, 2828 | MHD_USE_NO_LISTEN_SOCKET
2809 NULL, NULL, 2829 | MHD_ALLOW_SUSPEND_RESUME,
2810 &create_response, hd, 2830 0,
2811 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, 2831 NULL, NULL,
2812 MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, 2832 &create_response, hd,
2813 MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, 2833 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned
2814 MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, 2834 int) 16,
2815 MHD_OPTION_EXTERNAL_LOGGER, &mhd_error_log_callback, NULL, 2835 MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb,
2816 MHD_OPTION_HTTPS_MEM_KEY, pgc->key, 2836 NULL,
2817 MHD_OPTION_HTTPS_MEM_CERT, pgc->cert, 2837 MHD_OPTION_NOTIFY_CONNECTION,
2818 MHD_OPTION_END); 2838 &mhd_connection_cb, NULL,
2839 MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback,
2840 NULL,
2841 MHD_OPTION_EXTERNAL_LOGGER,
2842 &mhd_error_log_callback, NULL,
2843 MHD_OPTION_HTTPS_MEM_KEY, pgc->key,
2844 MHD_OPTION_HTTPS_MEM_CERT, pgc->cert,
2845 MHD_OPTION_END);
2819 if (NULL == hd->daemon) 2846 if (NULL == hd->daemon)
2820 { 2847 {
2821 GNUNET_free(pgc); 2848 GNUNET_free (pgc);
2822 GNUNET_free(hd); 2849 GNUNET_free (hd);
2823 return NULL; 2850 return NULL;
2824 } 2851 }
2825 GNUNET_CONTAINER_DLL_insert(mhd_httpd_head, 2852 GNUNET_CONTAINER_DLL_insert (mhd_httpd_head,
2826 mhd_httpd_tail, 2853 mhd_httpd_tail,
2827 hd); 2854 hd);
2828 return hd; 2855 return hd;
2829} 2856}
2830 2857
@@ -2837,12 +2864,12 @@ lookup_ssl_httpd(const char* domain)
2837 * @param cls the `struct Socks5Request *` 2864 * @param cls the `struct Socks5Request *`
2838 */ 2865 */
2839static void 2866static void
2840timeout_s5r_handshake(void *cls) 2867timeout_s5r_handshake (void *cls)
2841{ 2868{
2842 struct Socks5Request *s5r = cls; 2869 struct Socks5Request *s5r = cls;
2843 2870
2844 s5r->timeout_task = NULL; 2871 s5r->timeout_task = NULL;
2845 cleanup_s5r(s5r); 2872 cleanup_s5r (s5r);
2846} 2873}
2847 2874
2848 2875
@@ -2855,7 +2882,7 @@ timeout_s5r_handshake(void *cls)
2855 * @param s5r socks request that has reached the final stage 2882 * @param s5r socks request that has reached the final stage
2856 */ 2883 */
2857static void 2884static void
2858setup_data_transfer(struct Socks5Request *s5r) 2885setup_data_transfer (struct Socks5Request *s5r)
2859{ 2886{
2860 struct MhdHttpList *hd; 2887 struct MhdHttpList *hd;
2861 int fd; 2888 int fd;
@@ -2864,49 +2891,49 @@ setup_data_transfer(struct Socks5Request *s5r)
2864 char *domain; 2891 char *domain;
2865 2892
2866 if (GNUNET_YES == s5r->is_tls) 2893 if (GNUNET_YES == s5r->is_tls)
2867 { 2894 {
2868 GNUNET_asprintf(&domain, 2895 GNUNET_asprintf (&domain,
2869 "%s", 2896 "%s",
2870 s5r->domain);
2871 hd = lookup_ssl_httpd(domain);
2872 if (NULL == hd)
2873 {
2874 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2875 _("Failed to start HTTPS server for `%s'\n"),
2876 s5r->domain); 2897 s5r->domain);
2877 cleanup_s5r(s5r); 2898 hd = lookup_ssl_httpd (domain);
2878 GNUNET_free(domain); 2899 if (NULL == hd)
2879 return; 2900 {
2880 } 2901 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2902 _ ("Failed to start HTTPS server for `%s'\n"),
2903 s5r->domain);
2904 cleanup_s5r (s5r);
2905 GNUNET_free (domain);
2906 return;
2881 } 2907 }
2908 }
2882 else 2909 else
2883 { 2910 {
2884 domain = NULL; 2911 domain = NULL;
2885 GNUNET_assert(NULL != httpd); 2912 GNUNET_assert (NULL != httpd);
2886 hd = httpd; 2913 hd = httpd;
2887 } 2914 }
2888 fd = GNUNET_NETWORK_get_fd(s5r->sock); 2915 fd = GNUNET_NETWORK_get_fd (s5r->sock);
2889 addr = GNUNET_NETWORK_get_addr(s5r->sock); 2916 addr = GNUNET_NETWORK_get_addr (s5r->sock);
2890 len = GNUNET_NETWORK_get_addrlen(s5r->sock); 2917 len = GNUNET_NETWORK_get_addrlen (s5r->sock);
2891 s5r->state = SOCKS5_SOCKET_WITH_MHD; 2918 s5r->state = SOCKS5_SOCKET_WITH_MHD;
2892 if (MHD_YES != 2919 if (MHD_YES !=
2893 MHD_add_connection(hd->daemon, 2920 MHD_add_connection (hd->daemon,
2894 fd, 2921 fd,
2895 addr, 2922 addr,
2896 len)) 2923 len))
2897 { 2924 {
2898 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2925 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2899 _("Failed to pass client to MHD\n")); 2926 _ ("Failed to pass client to MHD\n"));
2900 cleanup_s5r(s5r); 2927 cleanup_s5r (s5r);
2901 GNUNET_free_non_null(domain); 2928 GNUNET_free_non_null (domain);
2902 return; 2929 return;
2903 } 2930 }
2904 s5r->hd = hd; 2931 s5r->hd = hd;
2905 schedule_httpd(hd); 2932 schedule_httpd (hd);
2906 s5r->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_HANDSHAKE_TIMEOUT, 2933 s5r->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_HANDSHAKE_TIMEOUT,
2907 &timeout_s5r_handshake, 2934 &timeout_s5r_handshake,
2908 s5r); 2935 s5r);
2909 GNUNET_free_non_null(domain); 2936 GNUNET_free_non_null (domain);
2910} 2937}
2911 2938
2912 2939
@@ -2919,61 +2946,61 @@ setup_data_transfer(struct Socks5Request *s5r)
2919 * @param cls the closure with the `struct Socks5Request` 2946 * @param cls the closure with the `struct Socks5Request`
2920 */ 2947 */
2921static void 2948static void
2922do_write(void *cls) 2949do_write (void *cls)
2923{ 2950{
2924 struct Socks5Request *s5r = cls; 2951 struct Socks5Request *s5r = cls;
2925 ssize_t len; 2952 ssize_t len;
2926 2953
2927 s5r->wtask = NULL; 2954 s5r->wtask = NULL;
2928 len = GNUNET_NETWORK_socket_send(s5r->sock, 2955 len = GNUNET_NETWORK_socket_send (s5r->sock,
2929 s5r->wbuf, 2956 s5r->wbuf,
2930 s5r->wbuf_len); 2957 s5r->wbuf_len);
2931 if (len <= 0) 2958 if (len <= 0)
2932 { 2959 {
2933 /* write error: connection closed, shutdown, etc.; just clean up */ 2960 /* write error: connection closed, shutdown, etc.; just clean up */
2934 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2961 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2935 "Write Error\n"); 2962 "Write Error\n");
2936 cleanup_s5r(s5r); 2963 cleanup_s5r (s5r);
2937 return; 2964 return;
2938 } 2965 }
2939 memmove(s5r->wbuf, 2966 memmove (s5r->wbuf,
2940 &s5r->wbuf[len], 2967 &s5r->wbuf[len],
2941 s5r->wbuf_len - len); 2968 s5r->wbuf_len - len);
2942 s5r->wbuf_len -= len; 2969 s5r->wbuf_len -= len;
2943 if (s5r->wbuf_len > 0) 2970 if (s5r->wbuf_len > 0)
2944 { 2971 {
2945 /* not done writing */ 2972 /* not done writing */
2946 s5r->wtask = 2973 s5r->wtask =
2947 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 2974 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2948 s5r->sock, 2975 s5r->sock,
2949 &do_write, s5r); 2976 &do_write, s5r);
2950 return; 2977 return;
2951 } 2978 }
2952 2979
2953 /* we're done writing, continue with state machine! */ 2980 /* we're done writing, continue with state machine! */
2954 2981
2955 switch (s5r->state) 2982 switch (s5r->state)
2956 { 2983 {
2957 case SOCKS5_INIT: 2984 case SOCKS5_INIT:
2958 GNUNET_assert(0); 2985 GNUNET_assert (0);
2959 break; 2986 break;
2960 2987
2961 case SOCKS5_REQUEST: 2988 case SOCKS5_REQUEST:
2962 GNUNET_assert(NULL != s5r->rtask); 2989 GNUNET_assert (NULL != s5r->rtask);
2963 break; 2990 break;
2964 2991
2965 case SOCKS5_DATA_TRANSFER: 2992 case SOCKS5_DATA_TRANSFER:
2966 setup_data_transfer(s5r); 2993 setup_data_transfer (s5r);
2967 return; 2994 return;
2968 2995
2969 case SOCKS5_WRITE_THEN_CLEANUP: 2996 case SOCKS5_WRITE_THEN_CLEANUP:
2970 cleanup_s5r(s5r); 2997 cleanup_s5r (s5r);
2971 return; 2998 return;
2972 2999
2973 default: 3000 default:
2974 GNUNET_break(0); 3001 GNUNET_break (0);
2975 break; 3002 break;
2976 } 3003 }
2977} 3004}
2978 3005
2979 3006
@@ -2984,21 +3011,21 @@ do_write(void *cls)
2984 * @param sc status code to return 3011 * @param sc status code to return
2985 */ 3012 */
2986static void 3013static void
2987signal_socks_failure(struct Socks5Request *s5r, 3014signal_socks_failure (struct Socks5Request *s5r,
2988 enum Socks5StatusCode sc) 3015 enum Socks5StatusCode sc)
2989{ 3016{
2990 struct Socks5ServerResponseMessage *s_resp; 3017 struct Socks5ServerResponseMessage *s_resp;
2991 3018
2992 s_resp = (struct Socks5ServerResponseMessage *)&s5r->wbuf[s5r->wbuf_len]; 3019 s_resp = (struct Socks5ServerResponseMessage *) &s5r->wbuf[s5r->wbuf_len];
2993 memset(s_resp, 0, sizeof(struct Socks5ServerResponseMessage)); 3020 memset (s_resp, 0, sizeof(struct Socks5ServerResponseMessage));
2994 s_resp->version = SOCKS_VERSION_5; 3021 s_resp->version = SOCKS_VERSION_5;
2995 s_resp->reply = sc; 3022 s_resp->reply = sc;
2996 s5r->state = SOCKS5_WRITE_THEN_CLEANUP; 3023 s5r->state = SOCKS5_WRITE_THEN_CLEANUP;
2997 if (NULL != s5r->wtask) 3024 if (NULL != s5r->wtask)
2998 s5r->wtask = 3025 s5r->wtask =
2999 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 3026 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
3000 s5r->sock, 3027 s5r->sock,
3001 &do_write, s5r); 3028 &do_write, s5r);
3002} 3029}
3003 3030
3004 3031
@@ -3008,26 +3035,26 @@ signal_socks_failure(struct Socks5Request *s5r,
3008 * @param s5r request to return success status message for 3035 * @param s5r request to return success status message for
3009 */ 3036 */
3010static void 3037static void
3011signal_socks_success(struct Socks5Request *s5r) 3038signal_socks_success (struct Socks5Request *s5r)
3012{ 3039{
3013 struct Socks5ServerResponseMessage *s_resp; 3040 struct Socks5ServerResponseMessage *s_resp;
3014 3041
3015 s_resp = (struct Socks5ServerResponseMessage *)&s5r->wbuf[s5r->wbuf_len]; 3042 s_resp = (struct Socks5ServerResponseMessage *) &s5r->wbuf[s5r->wbuf_len];
3016 s_resp->version = SOCKS_VERSION_5; 3043 s_resp->version = SOCKS_VERSION_5;
3017 s_resp->reply = SOCKS5_STATUS_REQUEST_GRANTED; 3044 s_resp->reply = SOCKS5_STATUS_REQUEST_GRANTED;
3018 s_resp->reserved = 0; 3045 s_resp->reserved = 0;
3019 s_resp->addr_type = SOCKS5_AT_IPV4; 3046 s_resp->addr_type = SOCKS5_AT_IPV4;
3020 /* zero out IPv4 address and port */ 3047 /* zero out IPv4 address and port */
3021 memset(&s_resp[1], 3048 memset (&s_resp[1],
3022 0, 3049 0,
3023 sizeof(struct in_addr) + sizeof(uint16_t)); 3050 sizeof(struct in_addr) + sizeof(uint16_t));
3024 s5r->wbuf_len += sizeof(struct Socks5ServerResponseMessage) + 3051 s5r->wbuf_len += sizeof(struct Socks5ServerResponseMessage)
3025 sizeof(struct in_addr) + sizeof(uint16_t); 3052 + sizeof(struct in_addr) + sizeof(uint16_t);
3026 if (NULL == s5r->wtask) 3053 if (NULL == s5r->wtask)
3027 s5r->wtask = 3054 s5r->wtask =
3028 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 3055 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
3029 s5r->sock, 3056 s5r->sock,
3030 &do_write, s5r); 3057 &do_write, s5r);
3031} 3058}
3032 3059
3033 3060
@@ -3040,10 +3067,10 @@ signal_socks_success(struct Socks5Request *s5r)
3040 * @param rd record data 3067 * @param rd record data
3041 */ 3068 */
3042static void 3069static void
3043handle_gns_result(void *cls, 3070handle_gns_result (void *cls,
3044 int tld, 3071 int tld,
3045 uint32_t rd_count, 3072 uint32_t rd_count,
3046 const struct GNUNET_GNSRECORD_Data *rd) 3073 const struct GNUNET_GNSRECORD_Data *rd)
3047{ 3074{
3048 struct Socks5Request *s5r = cls; 3075 struct Socks5Request *s5r = cls;
3049 const struct GNUNET_GNSRECORD_Data *r; 3076 const struct GNUNET_GNSRECORD_Data *r;
@@ -3053,122 +3080,122 @@ handle_gns_result(void *cls,
3053 s5r->is_gns = tld; 3080 s5r->is_gns = tld;
3054 got_ip = GNUNET_NO; 3081 got_ip = GNUNET_NO;
3055 for (uint32_t i = 0; i < rd_count; i++) 3082 for (uint32_t i = 0; i < rd_count; i++)
3083 {
3084 r = &rd[i];
3085 switch (r->record_type)
3056 { 3086 {
3057 r = &rd[i]; 3087 case GNUNET_DNSPARSER_TYPE_A:
3058 switch (r->record_type) 3088 {
3059 { 3089 struct sockaddr_in *in;
3060 case GNUNET_DNSPARSER_TYPE_A: 3090
3091 if (sizeof(struct in_addr) != r->data_size)
3061 { 3092 {
3062 struct sockaddr_in *in; 3093 GNUNET_break_op (0);
3063 3094 break;
3064 if (sizeof(struct in_addr) != r->data_size) 3095 }
3065 { 3096 if (GNUNET_YES == got_ip)
3066 GNUNET_break_op(0); 3097 break;
3067 break; 3098 if (GNUNET_OK !=
3068 } 3099 GNUNET_NETWORK_test_pf (PF_INET))
3069 if (GNUNET_YES == got_ip) 3100 break;
3070 break; 3101 got_ip = GNUNET_YES;
3071 if (GNUNET_OK != 3102 in = (struct sockaddr_in *) &s5r->destination_address;
3072 GNUNET_NETWORK_test_pf(PF_INET)) 3103 in->sin_family = AF_INET;
3073 break; 3104 GNUNET_memcpy (&in->sin_addr,
3074 got_ip = GNUNET_YES; 3105 r->data,
3075 in = (struct sockaddr_in *)&s5r->destination_address; 3106 r->data_size);
3076 in->sin_family = AF_INET; 3107 in->sin_port = htons (s5r->port);
3077 GNUNET_memcpy(&in->sin_addr,
3078 r->data,
3079 r->data_size);
3080 in->sin_port = htons(s5r->port);
3081#if HAVE_SOCKADDR_IN_SIN_LEN 3108#if HAVE_SOCKADDR_IN_SIN_LEN
3082 in->sin_len = sizeof(*in); 3109 in->sin_len = sizeof(*in);
3083#endif 3110#endif
3084 } 3111 }
3085 break; 3112 break;
3113
3114 case GNUNET_DNSPARSER_TYPE_AAAA:
3115 {
3116 struct sockaddr_in6 *in;
3086 3117
3087 case GNUNET_DNSPARSER_TYPE_AAAA: 3118 if (sizeof(struct in6_addr) != r->data_size)
3088 { 3119 {
3089 struct sockaddr_in6 *in; 3120 GNUNET_break_op (0);
3090 3121 break;
3091 if (sizeof(struct in6_addr) != r->data_size) 3122 }
3092 { 3123 if (GNUNET_YES == got_ip)
3093 GNUNET_break_op(0); 3124 break;
3094 break; 3125 if (GNUNET_YES == disable_v6)
3095 } 3126 break;
3096 if (GNUNET_YES == got_ip) 3127 if (GNUNET_OK !=
3097 break; 3128 GNUNET_NETWORK_test_pf (PF_INET6))
3098 if (GNUNET_YES == disable_v6) 3129 break;
3099 break; 3130 /* FIXME: allow user to disable IPv6 per configuration option... */
3100 if (GNUNET_OK != 3131 got_ip = GNUNET_YES;
3101 GNUNET_NETWORK_test_pf(PF_INET6)) 3132 in = (struct sockaddr_in6 *) &s5r->destination_address;
3102 break; 3133 in->sin6_family = AF_INET6;
3103 /* FIXME: allow user to disable IPv6 per configuration option... */ 3134 GNUNET_memcpy (&in->sin6_addr,
3104 got_ip = GNUNET_YES; 3135 r->data,
3105 in = (struct sockaddr_in6 *)&s5r->destination_address; 3136 r->data_size);
3106 in->sin6_family = AF_INET6; 3137 in->sin6_port = htons (s5r->port);
3107 GNUNET_memcpy(&in->sin6_addr,
3108 r->data,
3109 r->data_size);
3110 in->sin6_port = htons(s5r->port);
3111#if HAVE_SOCKADDR_IN_SIN_LEN 3138#if HAVE_SOCKADDR_IN_SIN_LEN
3112 in->sin6_len = sizeof(*in); 3139 in->sin6_len = sizeof(*in);
3113#endif 3140#endif
3114 } 3141 }
3115 break; 3142 break;
3116 3143
3117 case GNUNET_GNSRECORD_TYPE_VPN: 3144 case GNUNET_GNSRECORD_TYPE_VPN:
3118 GNUNET_break(0); /* should have been translated within GNS */ 3145 GNUNET_break (0); /* should have been translated within GNS */
3119 break; 3146 break;
3120 3147
3121 case GNUNET_GNSRECORD_TYPE_LEHO: 3148 case GNUNET_GNSRECORD_TYPE_LEHO:
3122 GNUNET_free_non_null(s5r->leho); 3149 GNUNET_free_non_null (s5r->leho);
3123 s5r->leho = GNUNET_strndup(r->data, 3150 s5r->leho = GNUNET_strndup (r->data,
3124 r->data_size); 3151 r->data_size);
3125 break; 3152 break;
3153
3154 case GNUNET_GNSRECORD_TYPE_BOX:
3155 {
3156 const struct GNUNET_GNSRECORD_BoxRecord *box;
3126 3157
3127 case GNUNET_GNSRECORD_TYPE_BOX: 3158 if (r->data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord))
3128 { 3159 {
3129 const struct GNUNET_GNSRECORD_BoxRecord *box; 3160 GNUNET_break_op (0);
3130
3131 if (r->data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord))
3132 {
3133 GNUNET_break_op(0);
3134 break;
3135 }
3136 box = r->data;
3137 if ((ntohl(box->record_type) != GNUNET_DNSPARSER_TYPE_TLSA) ||
3138 (ntohs(box->protocol) != IPPROTO_TCP) ||
3139 (ntohs(box->service) != s5r->port))
3140 break; /* BOX record does not apply */
3141 if (s5r->num_danes >= MAX_DANES)
3142 {
3143 GNUNET_break(0); /* MAX_DANES too small */
3144 break;
3145 }
3146 s5r->is_tls = GNUNET_YES; /* This should be TLS */
3147 s5r->dane_data_len[s5r->num_danes]
3148 = r->data_size - sizeof(struct GNUNET_GNSRECORD_BoxRecord);
3149 s5r->dane_data[s5r->num_danes]
3150 = GNUNET_memdup(&box[1],
3151 s5r->dane_data_len[s5r->num_danes]);
3152 s5r->num_danes++;
3153 break; 3161 break;
3154 } 3162 }
3155 3163 box = r->data;
3156 default: 3164 if ((ntohl (box->record_type) != GNUNET_DNSPARSER_TYPE_TLSA) ||
3157 /* don't care */ 3165 (ntohs (box->protocol) != IPPROTO_TCP) ||
3166 (ntohs (box->service) != s5r->port))
3167 break; /* BOX record does not apply */
3168 if (s5r->num_danes >= MAX_DANES)
3169 {
3170 GNUNET_break (0); /* MAX_DANES too small */
3158 break; 3171 break;
3159 } 3172 }
3173 s5r->is_tls = GNUNET_YES; /* This should be TLS */
3174 s5r->dane_data_len[s5r->num_danes]
3175 = r->data_size - sizeof(struct GNUNET_GNSRECORD_BoxRecord);
3176 s5r->dane_data[s5r->num_danes]
3177 = GNUNET_memdup (&box[1],
3178 s5r->dane_data_len[s5r->num_danes]);
3179 s5r->num_danes++;
3180 break;
3181 }
3182
3183 default:
3184 /* don't care */
3185 break;
3160 } 3186 }
3187 }
3161 if ((GNUNET_YES != got_ip) && 3188 if ((GNUNET_YES != got_ip) &&
3162 (GNUNET_YES == tld)) 3189 (GNUNET_YES == tld))
3163 { 3190 {
3164 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3165 "Name resolution failed to yield useful IP address.\n"); 3192 "Name resolution failed to yield useful IP address.\n");
3166 signal_socks_failure(s5r, 3193 signal_socks_failure (s5r,
3167 SOCKS5_STATUS_GENERAL_FAILURE); 3194 SOCKS5_STATUS_GENERAL_FAILURE);
3168 return; 3195 return;
3169 } 3196 }
3170 s5r->state = SOCKS5_DATA_TRANSFER; 3197 s5r->state = SOCKS5_DATA_TRANSFER;
3171 signal_socks_success(s5r); 3198 signal_socks_success (s5r);
3172} 3199}
3173 3200
3174 3201
@@ -3179,13 +3206,13 @@ handle_gns_result(void *cls,
3179 * @param len number of bytes in read buffer to advance 3206 * @param len number of bytes in read buffer to advance
3180 */ 3207 */
3181static void 3208static void
3182clear_from_s5r_rbuf(struct Socks5Request *s5r, 3209clear_from_s5r_rbuf (struct Socks5Request *s5r,
3183 size_t len) 3210 size_t len)
3184{ 3211{
3185 GNUNET_assert(len <= s5r->rbuf_len); 3212 GNUNET_assert (len <= s5r->rbuf_len);
3186 memmove(s5r->rbuf, 3213 memmove (s5r->rbuf,
3187 &s5r->rbuf[len], 3214 &s5r->rbuf[len],
3188 s5r->rbuf_len - len); 3215 s5r->rbuf_len - len);
3189 s5r->rbuf_len -= len; 3216 s5r->rbuf_len -= len;
3190} 3217}
3191 3218
@@ -3196,7 +3223,7 @@ clear_from_s5r_rbuf(struct Socks5Request *s5r,
3196 * @param cls the closure with the `struct Socks5Request` 3223 * @param cls the closure with the `struct Socks5Request`
3197 */ 3224 */
3198static void 3225static void
3199do_s5r_read(void *cls) 3226do_s5r_read (void *cls)
3200{ 3227{
3201 struct Socks5Request *s5r = cls; 3228 struct Socks5Request *s5r = cls;
3202 const struct Socks5ClientHelloMessage *c_hello; 3229 const struct Socks5ClientHelloMessage *c_hello;
@@ -3207,196 +3234,198 @@ do_s5r_read(void *cls)
3207 const struct GNUNET_SCHEDULER_TaskContext *tc; 3234 const struct GNUNET_SCHEDULER_TaskContext *tc;
3208 3235
3209 s5r->rtask = NULL; 3236 s5r->rtask = NULL;
3210 tc = GNUNET_SCHEDULER_get_task_context(); 3237 tc = GNUNET_SCHEDULER_get_task_context ();
3211 if ((NULL != tc->read_ready) && 3238 if ((NULL != tc->read_ready) &&
3212 (GNUNET_NETWORK_fdset_isset(tc->read_ready, 3239 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
3213 s5r->sock))) 3240 s5r->sock)))
3214 { 3241 {
3215 rlen = GNUNET_NETWORK_socket_recv(s5r->sock, 3242 rlen = GNUNET_NETWORK_socket_recv (s5r->sock,
3216 &s5r->rbuf[s5r->rbuf_len], 3243 &s5r->rbuf[s5r->rbuf_len],
3217 sizeof(s5r->rbuf) - s5r->rbuf_len); 3244 sizeof(s5r->rbuf) - s5r->rbuf_len);
3218 if (rlen <= 0) 3245 if (rlen <= 0)
3219 { 3246 {
3220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3221 "socks5 client disconnected.\n"); 3248 "socks5 client disconnected.\n");
3222 cleanup_s5r(s5r); 3249 cleanup_s5r (s5r);
3223 return; 3250 return;
3224 }
3225 s5r->rbuf_len += rlen;
3226 } 3251 }
3227 s5r->rtask = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 3252 s5r->rbuf_len += rlen;
3228 s5r->sock, 3253 }
3229 &do_s5r_read, s5r); 3254 s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3230 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3255 s5r->sock,
3231 "Processing %zu bytes of socks data in state %d\n", 3256 &do_s5r_read, s5r);
3232 s5r->rbuf_len, 3257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3233 s5r->state); 3258 "Processing %zu bytes of socks data in state %d\n",
3259 s5r->rbuf_len,
3260 s5r->state);
3234 switch (s5r->state) 3261 switch (s5r->state)
3235 { 3262 {
3236 case SOCKS5_INIT: 3263 case SOCKS5_INIT:
3237 c_hello = (const struct Socks5ClientHelloMessage*)&s5r->rbuf; 3264 c_hello = (const struct Socks5ClientHelloMessage*) &s5r->rbuf;
3238 if ((s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage)) || 3265 if ((s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage)) ||
3239 (s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage) + c_hello->num_auth_methods)) 3266 (s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage)
3240 return; /* need more data */ 3267 + c_hello->num_auth_methods))
3241 if (SOCKS_VERSION_5 != c_hello->version) 3268 return; /* need more data */
3242 { 3269 if (SOCKS_VERSION_5 != c_hello->version)
3243 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3270 {
3244 _("Unsupported socks version %d\n"), 3271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3245 (int)c_hello->version); 3272 _ ("Unsupported socks version %d\n"),
3246 cleanup_s5r(s5r); 3273 (int) c_hello->version);
3247 return; 3274 cleanup_s5r (s5r);
3248 }
3249 clear_from_s5r_rbuf(s5r,
3250 sizeof(struct Socks5ClientHelloMessage) + c_hello->num_auth_methods);
3251 GNUNET_assert(0 == s5r->wbuf_len);
3252 s_hello = (struct Socks5ServerHelloMessage *)&s5r->wbuf;
3253 s5r->wbuf_len = sizeof(struct Socks5ServerHelloMessage);
3254 s_hello->version = SOCKS_VERSION_5;
3255 s_hello->auth_method = SOCKS_AUTH_NONE;
3256 GNUNET_assert(NULL == s5r->wtask);
3257 s5r->wtask = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
3258 s5r->sock,
3259 &do_write, s5r);
3260 s5r->state = SOCKS5_REQUEST;
3261 return; 3275 return;
3276 }
3277 clear_from_s5r_rbuf (s5r,
3278 sizeof(struct Socks5ClientHelloMessage)
3279 + c_hello->num_auth_methods);
3280 GNUNET_assert (0 == s5r->wbuf_len);
3281 s_hello = (struct Socks5ServerHelloMessage *) &s5r->wbuf;
3282 s5r->wbuf_len = sizeof(struct Socks5ServerHelloMessage);
3283 s_hello->version = SOCKS_VERSION_5;
3284 s_hello->auth_method = SOCKS_AUTH_NONE;
3285 GNUNET_assert (NULL == s5r->wtask);
3286 s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
3287 s5r->sock,
3288 &do_write, s5r);
3289 s5r->state = SOCKS5_REQUEST;
3290 return;
3262 3291
3263 case SOCKS5_REQUEST: 3292 case SOCKS5_REQUEST:
3264 c_req = (const struct Socks5ClientRequestMessage *)&s5r->rbuf; 3293 c_req = (const struct Socks5ClientRequestMessage *) &s5r->rbuf;
3265 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage)) 3294 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage))
3266 return; 3295 return;
3267 switch (c_req->command) 3296 switch (c_req->command)
3268 { 3297 {
3269 case SOCKS5_CMD_TCP_STREAM: 3298 case SOCKS5_CMD_TCP_STREAM:
3270 /* handled below */ 3299 /* handled below */
3271 break; 3300 break;
3272 3301
3273 default: 3302 default:
3274 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3275 _("Unsupported socks command %d\n"), 3304 _ ("Unsupported socks command %d\n"),
3276 (int)c_req->command); 3305 (int) c_req->command);
3277 signal_socks_failure(s5r, 3306 signal_socks_failure (s5r,
3278 SOCKS5_STATUS_COMMAND_NOT_SUPPORTED); 3307 SOCKS5_STATUS_COMMAND_NOT_SUPPORTED);
3279 return; 3308 return;
3280 } 3309 }
3281 switch (c_req->addr_type) 3310 switch (c_req->addr_type)
3282 { 3311 {
3283 case SOCKS5_AT_IPV4: 3312 case SOCKS5_AT_IPV4:
3284 { 3313 {
3285 const struct in_addr *v4 = (const struct in_addr *)&c_req[1]; 3314 const struct in_addr *v4 = (const struct in_addr *) &c_req[1];
3286 const uint16_t *port = (const uint16_t *)&v4[1]; 3315 const uint16_t *port = (const uint16_t *) &v4[1];
3287 struct sockaddr_in *in; 3316 struct sockaddr_in *in;
3288 3317
3289 s5r->port = ntohs(*port); 3318 s5r->port = ntohs (*port);
3290 alen = sizeof(struct in_addr); 3319 alen = sizeof(struct in_addr);
3291 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + 3320 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage)
3292 alen + sizeof(uint16_t)) 3321 + alen + sizeof(uint16_t))
3293 return; /* need more data */ 3322 return; /* need more data */
3294 in = (struct sockaddr_in *)&s5r->destination_address; 3323 in = (struct sockaddr_in *) &s5r->destination_address;
3295 in->sin_family = AF_INET; 3324 in->sin_family = AF_INET;
3296 in->sin_addr = *v4; 3325 in->sin_addr = *v4;
3297 in->sin_port = *port; 3326 in->sin_port = *port;
3298#if HAVE_SOCKADDR_IN_SIN_LEN 3327#if HAVE_SOCKADDR_IN_SIN_LEN
3299 in->sin_len = sizeof(*in); 3328 in->sin_len = sizeof(*in);
3300#endif 3329#endif
3301 s5r->state = SOCKS5_DATA_TRANSFER; 3330 s5r->state = SOCKS5_DATA_TRANSFER;
3302 } 3331 }
3303 break; 3332 break;
3304 3333
3305 case SOCKS5_AT_IPV6: 3334 case SOCKS5_AT_IPV6:
3306 { 3335 {
3307 const struct in6_addr *v6 = (const struct in6_addr *)&c_req[1]; 3336 const struct in6_addr *v6 = (const struct in6_addr *) &c_req[1];
3308 const uint16_t *port = (const uint16_t *)&v6[1]; 3337 const uint16_t *port = (const uint16_t *) &v6[1];
3309 struct sockaddr_in6 *in; 3338 struct sockaddr_in6 *in;
3310 3339
3311 s5r->port = ntohs(*port); 3340 s5r->port = ntohs (*port);
3312 alen = sizeof(struct in6_addr); 3341 alen = sizeof(struct in6_addr);
3313 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + 3342 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage)
3314 alen + sizeof(uint16_t)) 3343 + alen + sizeof(uint16_t))
3315 return; /* need more data */ 3344 return; /* need more data */
3316 in = (struct sockaddr_in6 *)&s5r->destination_address; 3345 in = (struct sockaddr_in6 *) &s5r->destination_address;
3317 in->sin6_family = AF_INET6; 3346 in->sin6_family = AF_INET6;
3318 in->sin6_addr = *v6; 3347 in->sin6_addr = *v6;
3319 in->sin6_port = *port; 3348 in->sin6_port = *port;
3320#if HAVE_SOCKADDR_IN_SIN_LEN 3349#if HAVE_SOCKADDR_IN_SIN_LEN
3321 in->sin6_len = sizeof(*in); 3350 in->sin6_len = sizeof(*in);
3322#endif 3351#endif
3323 s5r->state = SOCKS5_DATA_TRANSFER; 3352 s5r->state = SOCKS5_DATA_TRANSFER;
3324 } 3353 }
3325 break; 3354 break;
3326 3355
3327 case SOCKS5_AT_DOMAINNAME: 3356 case SOCKS5_AT_DOMAINNAME:
3328 { 3357 {
3329 const uint8_t *dom_len; 3358 const uint8_t *dom_len;
3330 const char *dom_name; 3359 const char *dom_name;
3331 const uint16_t *port; 3360 const uint16_t *port;
3332 3361
3333 dom_len = (const uint8_t *)&c_req[1]; 3362 dom_len = (const uint8_t *) &c_req[1];
3334 alen = *dom_len + 1; 3363 alen = *dom_len + 1;
3335 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + 3364 if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage)
3336 alen + sizeof(uint16_t)) 3365 + alen + sizeof(uint16_t))
3337 return; /* need more data */ 3366 return; /* need more data */
3338 dom_name = (const char *)&dom_len[1]; 3367 dom_name = (const char *) &dom_len[1];
3339 port = (const uint16_t*)&dom_name[*dom_len]; 3368 port = (const uint16_t*) &dom_name[*dom_len];
3340 s5r->domain = GNUNET_strndup(dom_name, 3369 s5r->domain = GNUNET_strndup (dom_name,
3341 *dom_len); 3370 *dom_len);
3342 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3343 "Requested connection is to %s:%d\n", 3372 "Requested connection is to %s:%d\n",
3344 //(HTTPS_PORT == s5r->port) ? "s" : "", 3373 // (HTTPS_PORT == s5r->port) ? "s" : "",
3345 s5r->domain, 3374 s5r->domain,
3346 ntohs(*port)); 3375 ntohs (*port));
3347 s5r->state = SOCKS5_RESOLVING; 3376 s5r->state = SOCKS5_RESOLVING;
3348 s5r->port = ntohs(*port); 3377 s5r->port = ntohs (*port);
3349 s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO; 3378 s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO;
3350 s5r->gns_lookup = GNUNET_GNS_lookup_with_tld(gns_handle, 3379 s5r->gns_lookup = GNUNET_GNS_lookup_with_tld (gns_handle,
3351 s5r->domain, 3380 s5r->domain,
3352 GNUNET_DNSPARSER_TYPE_A, 3381 GNUNET_DNSPARSER_TYPE_A,
3353 GNUNET_NO /* only cached */, 3382 GNUNET_NO /* only cached */,
3354 &handle_gns_result, 3383 &handle_gns_result,
3355 s5r); 3384 s5r);
3356 break; 3385 break;
3357 } 3386 }
3358 3387
3359 default: 3388 default:
3360 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3389 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3361 _("Unsupported socks address type %d\n"), 3390 _ ("Unsupported socks address type %d\n"),
3362 (int)c_req->addr_type); 3391 (int) c_req->addr_type);
3363 signal_socks_failure(s5r, 3392 signal_socks_failure (s5r,
3364 SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED); 3393 SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED);
3365 return;
3366 }
3367 clear_from_s5r_rbuf(s5r,
3368 sizeof(struct Socks5ClientRequestMessage) +
3369 alen + sizeof(uint16_t));
3370 if (0 != s5r->rbuf_len)
3371 {
3372 /* read more bytes than healthy, why did the client send more!? */
3373 GNUNET_break_op(0);
3374 signal_socks_failure(s5r,
3375 SOCKS5_STATUS_GENERAL_FAILURE);
3376 return;
3377 }
3378 if (SOCKS5_DATA_TRANSFER == s5r->state)
3379 {
3380 /* if we are not waiting for GNS resolution, signal success */
3381 signal_socks_success(s5r);
3382 }
3383 /* We are done reading right now */
3384 GNUNET_SCHEDULER_cancel(s5r->rtask);
3385 s5r->rtask = NULL;
3386 return; 3394 return;
3387 3395 }
3388 case SOCKS5_RESOLVING: 3396 clear_from_s5r_rbuf (s5r,
3389 GNUNET_assert(0); 3397 sizeof(struct Socks5ClientRequestMessage)
3398 + alen + sizeof(uint16_t));
3399 if (0 != s5r->rbuf_len)
3400 {
3401 /* read more bytes than healthy, why did the client send more!? */
3402 GNUNET_break_op (0);
3403 signal_socks_failure (s5r,
3404 SOCKS5_STATUS_GENERAL_FAILURE);
3390 return; 3405 return;
3406 }
3407 if (SOCKS5_DATA_TRANSFER == s5r->state)
3408 {
3409 /* if we are not waiting for GNS resolution, signal success */
3410 signal_socks_success (s5r);
3411 }
3412 /* We are done reading right now */
3413 GNUNET_SCHEDULER_cancel (s5r->rtask);
3414 s5r->rtask = NULL;
3415 return;
3391 3416
3392 case SOCKS5_DATA_TRANSFER: 3417 case SOCKS5_RESOLVING:
3393 GNUNET_assert(0); 3418 GNUNET_assert (0);
3394 return; 3419 return;
3395 3420
3396 default: 3421 case SOCKS5_DATA_TRANSFER:
3397 GNUNET_assert(0); 3422 GNUNET_assert (0);
3398 return; 3423 return;
3399 } 3424
3425 default:
3426 GNUNET_assert (0);
3427 return;
3428 }
3400} 3429}
3401 3430
3402 3431
@@ -3407,46 +3436,46 @@ do_s5r_read(void *cls)
3407 * @param tc the scheduler context 3436 * @param tc the scheduler context
3408 */ 3437 */
3409static void 3438static void
3410do_accept(void *cls) 3439do_accept (void *cls)
3411{ 3440{
3412 struct GNUNET_NETWORK_Handle *lsock = cls; 3441 struct GNUNET_NETWORK_Handle *lsock = cls;
3413 struct GNUNET_NETWORK_Handle *s; 3442 struct GNUNET_NETWORK_Handle *s;
3414 struct Socks5Request *s5r; 3443 struct Socks5Request *s5r;
3415 3444
3416 GNUNET_assert(NULL != lsock); 3445 GNUNET_assert (NULL != lsock);
3417 if (lsock == lsock4) 3446 if (lsock == lsock4)
3418 ltask4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 3447 ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3419 lsock, 3448 lsock,
3420 &do_accept, 3449 &do_accept,
3421 lsock); 3450 lsock);
3422 else if (lsock == lsock6) 3451 else if (lsock == lsock6)
3423 ltask6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 3452 ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3424 lsock, 3453 lsock,
3425 &do_accept, 3454 &do_accept,
3426 lsock); 3455 lsock);
3427 else 3456 else
3428 GNUNET_assert(0); 3457 GNUNET_assert (0);
3429 s = GNUNET_NETWORK_socket_accept(lsock, 3458 s = GNUNET_NETWORK_socket_accept (lsock,
3430 NULL, 3459 NULL,
3431 NULL); 3460 NULL);
3432 if (NULL == s) 3461 if (NULL == s)
3433 { 3462 {
3434 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, 3463 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3435 "accept"); 3464 "accept");
3436 return; 3465 return;
3437 } 3466 }
3438 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3439 "Got an inbound connection, waiting for data\n"); 3468 "Got an inbound connection, waiting for data\n");
3440 s5r = GNUNET_new(struct Socks5Request); 3469 s5r = GNUNET_new (struct Socks5Request);
3441 GNUNET_CONTAINER_DLL_insert(s5r_head, 3470 GNUNET_CONTAINER_DLL_insert (s5r_head,
3442 s5r_tail, 3471 s5r_tail,
3443 s5r); 3472 s5r);
3444 s5r->sock = s; 3473 s5r->sock = s;
3445 s5r->state = SOCKS5_INIT; 3474 s5r->state = SOCKS5_INIT;
3446 s5r->rtask = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 3475 s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3447 s5r->sock, 3476 s5r->sock,
3448 &do_s5r_read, 3477 &do_s5r_read,
3449 s5r); 3478 s5r);
3450} 3479}
3451 3480
3452 3481
@@ -3459,63 +3488,63 @@ do_accept(void *cls)
3459 * @param cls closure 3488 * @param cls closure
3460 */ 3489 */
3461static void 3490static void
3462do_shutdown(void *cls) 3491do_shutdown (void *cls)
3463{ 3492{
3464 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3493 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3465 "Shutting down...\n"); 3494 "Shutting down...\n");
3466 /* MHD requires resuming before destroying the daemons */ 3495 /* MHD requires resuming before destroying the daemons */
3467 for (struct Socks5Request *s5r = s5r_head; 3496 for (struct Socks5Request *s5r = s5r_head;
3468 NULL != s5r; 3497 NULL != s5r;
3469 s5r = s5r->next) 3498 s5r = s5r->next)
3499 {
3500 if (s5r->suspended)
3470 { 3501 {
3471 if (s5r->suspended) 3502 s5r->suspended = GNUNET_NO;
3472 { 3503 MHD_resume_connection (s5r->con);
3473 s5r->suspended = GNUNET_NO;
3474 MHD_resume_connection(s5r->con);
3475 }
3476 } 3504 }
3505 }
3477 while (NULL != mhd_httpd_head) 3506 while (NULL != mhd_httpd_head)
3478 kill_httpd(mhd_httpd_head); 3507 kill_httpd (mhd_httpd_head);
3479 while (NULL != s5r_head) 3508 while (NULL != s5r_head)
3480 cleanup_s5r(s5r_head); 3509 cleanup_s5r (s5r_head);
3481 if (NULL != lsock4) 3510 if (NULL != lsock4)
3482 { 3511 {
3483 GNUNET_NETWORK_socket_close(lsock4); 3512 GNUNET_NETWORK_socket_close (lsock4);
3484 lsock4 = NULL; 3513 lsock4 = NULL;
3485 } 3514 }
3486 if (NULL != lsock6) 3515 if (NULL != lsock6)
3487 { 3516 {
3488 GNUNET_NETWORK_socket_close(lsock6); 3517 GNUNET_NETWORK_socket_close (lsock6);
3489 lsock6 = NULL; 3518 lsock6 = NULL;
3490 } 3519 }
3491 if (NULL != curl_multi) 3520 if (NULL != curl_multi)
3492 { 3521 {
3493 curl_multi_cleanup(curl_multi); 3522 curl_multi_cleanup (curl_multi);
3494 curl_multi = NULL; 3523 curl_multi = NULL;
3495 } 3524 }
3496 if (NULL != gns_handle) 3525 if (NULL != gns_handle)
3497 { 3526 {
3498 GNUNET_GNS_disconnect(gns_handle); 3527 GNUNET_GNS_disconnect (gns_handle);
3499 gns_handle = NULL; 3528 gns_handle = NULL;
3500 } 3529 }
3501 if (NULL != curl_download_task) 3530 if (NULL != curl_download_task)
3502 { 3531 {
3503 GNUNET_SCHEDULER_cancel(curl_download_task); 3532 GNUNET_SCHEDULER_cancel (curl_download_task);
3504 curl_download_task = NULL; 3533 curl_download_task = NULL;
3505 } 3534 }
3506 if (NULL != ltask4) 3535 if (NULL != ltask4)
3507 { 3536 {
3508 GNUNET_SCHEDULER_cancel(ltask4); 3537 GNUNET_SCHEDULER_cancel (ltask4);
3509 ltask4 = NULL; 3538 ltask4 = NULL;
3510 } 3539 }
3511 if (NULL != ltask6) 3540 if (NULL != ltask6)
3512 { 3541 {
3513 GNUNET_SCHEDULER_cancel(ltask6); 3542 GNUNET_SCHEDULER_cancel (ltask6);
3514 ltask6 = NULL; 3543 ltask6 = NULL;
3515 } 3544 }
3516 gnutls_x509_crt_deinit(proxy_ca.cert); 3545 gnutls_x509_crt_deinit (proxy_ca.cert);
3517 gnutls_x509_privkey_deinit(proxy_ca.key); 3546 gnutls_x509_privkey_deinit (proxy_ca.key);
3518 gnutls_global_deinit(); 3547 gnutls_global_deinit ();
3519} 3548}
3520 3549
3521 3550
@@ -3525,34 +3554,34 @@ do_shutdown(void *cls)
3525 * @return NULL on error 3554 * @return NULL on error
3526 */ 3555 */
3527static struct GNUNET_NETWORK_Handle * 3556static struct GNUNET_NETWORK_Handle *
3528bind_v4() 3557bind_v4 ()
3529{ 3558{
3530 struct GNUNET_NETWORK_Handle *ls; 3559 struct GNUNET_NETWORK_Handle *ls;
3531 struct sockaddr_in sa4; 3560 struct sockaddr_in sa4;
3532 int eno; 3561 int eno;
3533 3562
3534 memset(&sa4, 0, sizeof(sa4)); 3563 memset (&sa4, 0, sizeof(sa4));
3535 sa4.sin_family = AF_INET; 3564 sa4.sin_family = AF_INET;
3536 sa4.sin_port = htons(port); 3565 sa4.sin_port = htons (port);
3537 sa4.sin_addr.s_addr = address; 3566 sa4.sin_addr.s_addr = address;
3538#if HAVE_SOCKADDR_IN_SIN_LEN 3567#if HAVE_SOCKADDR_IN_SIN_LEN
3539 sa4.sin_len = sizeof(sa4); 3568 sa4.sin_len = sizeof(sa4);
3540#endif 3569#endif
3541 ls = GNUNET_NETWORK_socket_create(AF_INET, 3570 ls = GNUNET_NETWORK_socket_create (AF_INET,
3542 SOCK_STREAM, 3571 SOCK_STREAM,
3543 0); 3572 0);
3544 if (NULL == ls) 3573 if (NULL == ls)
3545 return NULL; 3574 return NULL;
3546 if (GNUNET_OK != 3575 if (GNUNET_OK !=
3547 GNUNET_NETWORK_socket_bind(ls, 3576 GNUNET_NETWORK_socket_bind (ls,
3548 (const struct sockaddr *)&sa4, 3577 (const struct sockaddr *) &sa4,
3549 sizeof(sa4))) 3578 sizeof(sa4)))
3550 { 3579 {
3551 eno = errno; 3580 eno = errno;
3552 GNUNET_NETWORK_socket_close(ls); 3581 GNUNET_NETWORK_socket_close (ls);
3553 errno = eno; 3582 errno = eno;
3554 return NULL; 3583 return NULL;
3555 } 3584 }
3556 return ls; 3585 return ls;
3557} 3586}
3558 3587
@@ -3563,34 +3592,34 @@ bind_v4()
3563 * @return NULL on error 3592 * @return NULL on error
3564 */ 3593 */
3565static struct GNUNET_NETWORK_Handle * 3594static struct GNUNET_NETWORK_Handle *
3566bind_v6() 3595bind_v6 ()
3567{ 3596{
3568 struct GNUNET_NETWORK_Handle *ls; 3597 struct GNUNET_NETWORK_Handle *ls;
3569 struct sockaddr_in6 sa6; 3598 struct sockaddr_in6 sa6;
3570 int eno; 3599 int eno;
3571 3600
3572 memset(&sa6, 0, sizeof(sa6)); 3601 memset (&sa6, 0, sizeof(sa6));
3573 sa6.sin6_family = AF_INET6; 3602 sa6.sin6_family = AF_INET6;
3574 sa6.sin6_port = htons(port); 3603 sa6.sin6_port = htons (port);
3575 sa6.sin6_addr = address6; 3604 sa6.sin6_addr = address6;
3576#if HAVE_SOCKADDR_IN_SIN_LEN 3605#if HAVE_SOCKADDR_IN_SIN_LEN
3577 sa6.sin6_len = sizeof(sa6); 3606 sa6.sin6_len = sizeof(sa6);
3578#endif 3607#endif
3579 ls = GNUNET_NETWORK_socket_create(AF_INET6, 3608 ls = GNUNET_NETWORK_socket_create (AF_INET6,
3580 SOCK_STREAM, 3609 SOCK_STREAM,
3581 0); 3610 0);
3582 if (NULL == ls) 3611 if (NULL == ls)
3583 return NULL; 3612 return NULL;
3584 if (GNUNET_OK != 3613 if (GNUNET_OK !=
3585 GNUNET_NETWORK_socket_bind(ls, 3614 GNUNET_NETWORK_socket_bind (ls,
3586 (const struct sockaddr *)&sa6, 3615 (const struct sockaddr *) &sa6,
3587 sizeof(sa6))) 3616 sizeof(sa6)))
3588 { 3617 {
3589 eno = errno; 3618 eno = errno;
3590 GNUNET_NETWORK_socket_close(ls); 3619 GNUNET_NETWORK_socket_close (ls);
3591 errno = eno; 3620 errno = eno;
3592 return NULL; 3621 return NULL;
3593 } 3622 }
3594 return ls; 3623 return ls;
3595} 3624}
3596 3625
@@ -3604,211 +3633,216 @@ bind_v6()
3604 * @param c configuration 3633 * @param c configuration
3605 */ 3634 */
3606static void 3635static void
3607run(void *cls, 3636run (void *cls,
3608 char *const *args, 3637 char *const *args,
3609 const char *cfgfile, 3638 const char *cfgfile,
3610 const struct GNUNET_CONFIGURATION_Handle *c) 3639 const struct GNUNET_CONFIGURATION_Handle *c)
3611{ 3640{
3612 char* cafile_cfg = NULL; 3641 char*cafile_cfg = NULL;
3613 char* cafile; 3642 char*cafile;
3614 char* addr_str; 3643 char*addr_str;
3615 struct MhdHttpList *hd; 3644 struct MhdHttpList *hd;
3616 3645
3617 cfg = c; 3646 cfg = c;
3618 3647
3619 /* Get address to bind to */ 3648 /* Get address to bind to */
3620 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "gns-proxy", 3649 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy",
3621 "BIND_TO", 3650 "BIND_TO",
3622 &addr_str)) 3651 &addr_str))
3623 { 3652 {
3624 //No address specified 3653 // No address specified
3625 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3626 "Don't know what to bind to...\n"); 3655 "Don't know what to bind to...\n");
3627 GNUNET_free(addr_str); 3656 GNUNET_free (addr_str);
3628 GNUNET_SCHEDULER_shutdown(); 3657 GNUNET_SCHEDULER_shutdown ();
3629 return; 3658 return;
3630 } 3659 }
3631 if (1 != inet_pton(AF_INET, addr_str, &address)) 3660 if (1 != inet_pton (AF_INET, addr_str, &address))
3632 { 3661 {
3633 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3634 "Unable to parse address %s\n", 3663 "Unable to parse address %s\n",
3635 addr_str); 3664 addr_str);
3636 GNUNET_free(addr_str); 3665 GNUNET_free (addr_str);
3637 GNUNET_SCHEDULER_shutdown(); 3666 GNUNET_SCHEDULER_shutdown ();
3638 return; 3667 return;
3639 } 3668 }
3640 GNUNET_free(addr_str); 3669 GNUNET_free (addr_str);
3641 /* Get address to bind to */ 3670 /* Get address to bind to */
3642 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "gns-proxy", 3671 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy",
3643 "BIND_TO6", 3672 "BIND_TO6",
3644 &addr_str)) 3673 &addr_str))
3645 { 3674 {
3646 //No address specified 3675 // No address specified
3647 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3676 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3648 "Don't know what to bind6 to...\n"); 3677 "Don't know what to bind6 to...\n");
3649 GNUNET_free(addr_str); 3678 GNUNET_free (addr_str);
3650 GNUNET_SCHEDULER_shutdown(); 3679 GNUNET_SCHEDULER_shutdown ();
3651 return; 3680 return;
3652 } 3681 }
3653 if (1 != inet_pton(AF_INET6, addr_str, &address6)) 3682 if (1 != inet_pton (AF_INET6, addr_str, &address6))
3654 { 3683 {
3655 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3656 "Unable to parse IPv6 address %s\n", 3685 "Unable to parse IPv6 address %s\n",
3657 addr_str); 3686 addr_str);
3658 GNUNET_free(addr_str); 3687 GNUNET_free (addr_str);
3659 GNUNET_SCHEDULER_shutdown(); 3688 GNUNET_SCHEDULER_shutdown ();
3660 return; 3689 return;
3661 } 3690 }
3662 GNUNET_free(addr_str); 3691 GNUNET_free (addr_str);
3663 3692
3664 if (NULL == (curl_multi = curl_multi_init())) 3693 if (NULL == (curl_multi = curl_multi_init ()))
3665 { 3694 {
3666 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3695 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3667 "Failed to create cURL multi handle!\n"); 3696 "Failed to create cURL multi handle!\n");
3668 return; 3697 return;
3669 } 3698 }
3670 cafile = cafile_opt; 3699 cafile = cafile_opt;
3671 if (NULL == cafile) 3700 if (NULL == cafile)
3672 { 3701 {
3673 if (GNUNET_OK != 3702 if (GNUNET_OK !=
3674 GNUNET_CONFIGURATION_get_value_filename(cfg, 3703 GNUNET_CONFIGURATION_get_value_filename (cfg,
3675 "gns-proxy", 3704 "gns-proxy",
3676 "PROXY_CACERT", 3705 "PROXY_CACERT",
3677 &cafile_cfg)) 3706 &cafile_cfg))
3678 { 3707 {
3679 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 3708 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
3680 "gns-proxy", 3709 "gns-proxy",
3681 "PROXY_CACERT"); 3710 "PROXY_CACERT");
3682 return; 3711 return;
3683 }
3684 cafile = cafile_cfg;
3685 } 3712 }
3686 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3713 cafile = cafile_cfg;
3687 "Using `%s' as CA\n", 3714 }
3688 cafile); 3715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3716 "Using `%s' as CA\n",
3717 cafile);
3689 3718
3690 gnutls_global_init(); 3719 gnutls_global_init ();
3691 gnutls_x509_crt_init(&proxy_ca.cert); 3720 gnutls_x509_crt_init (&proxy_ca.cert);
3692 gnutls_x509_privkey_init(&proxy_ca.key); 3721 gnutls_x509_privkey_init (&proxy_ca.key);
3693 3722
3694 if ((GNUNET_OK != 3723 if ((GNUNET_OK !=
3695 load_cert_from_file(proxy_ca.cert, 3724 load_cert_from_file (proxy_ca.cert,
3696 cafile)) || 3725 cafile)) ||
3697 (GNUNET_OK != 3726 (GNUNET_OK !=
3698 load_key_from_file(proxy_ca.key, 3727 load_key_from_file (proxy_ca.key,
3699 cafile))) 3728 cafile)))
3700 { 3729 {
3701 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3730 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3702 _("Failed to load X.509 key and certificate from `%s'\n"), 3731 _ ("Failed to load X.509 key and certificate from `%s'\n"),
3703 cafile); 3732 cafile);
3704 gnutls_x509_crt_deinit(proxy_ca.cert); 3733 gnutls_x509_crt_deinit (proxy_ca.cert);
3705 gnutls_x509_privkey_deinit(proxy_ca.key); 3734 gnutls_x509_privkey_deinit (proxy_ca.key);
3706 gnutls_global_deinit(); 3735 gnutls_global_deinit ();
3707 GNUNET_free_non_null(cafile_cfg); 3736 GNUNET_free_non_null (cafile_cfg);
3708 return; 3737 return;
3709 } 3738 }
3710 GNUNET_free_non_null(cafile_cfg); 3739 GNUNET_free_non_null (cafile_cfg);
3711 if (NULL == (gns_handle = GNUNET_GNS_connect(cfg))) 3740 if (NULL == (gns_handle = GNUNET_GNS_connect (cfg)))
3712 { 3741 {
3713 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3714 "Unable to connect to GNS!\n"); 3743 "Unable to connect to GNS!\n");
3715 gnutls_x509_crt_deinit(proxy_ca.cert); 3744 gnutls_x509_crt_deinit (proxy_ca.cert);
3716 gnutls_x509_privkey_deinit(proxy_ca.key); 3745 gnutls_x509_privkey_deinit (proxy_ca.key);
3717 gnutls_global_deinit(); 3746 gnutls_global_deinit ();
3718 return; 3747 return;
3719 } 3748 }
3720 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 3749 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
3721 NULL); 3750 NULL);
3722 3751
3723 /* Open listen socket for socks proxy */ 3752 /* Open listen socket for socks proxy */
3724 lsock6 = bind_v6(); 3753 lsock6 = bind_v6 ();
3725 if (NULL == lsock6) 3754 if (NULL == lsock6)
3755 {
3756 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3757 "bind");
3758 }
3759 else
3760 {
3761 if (GNUNET_OK !=
3762 GNUNET_NETWORK_socket_listen (lsock6,
3763 5))
3726 { 3764 {
3727 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, 3765 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3728 "bind"); 3766 "listen");
3767 GNUNET_NETWORK_socket_close (lsock6);
3768 lsock6 = NULL;
3729 } 3769 }
3730 else 3770 else
3731 { 3771 {
3732 if (GNUNET_OK != 3772 ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3733 GNUNET_NETWORK_socket_listen(lsock6, 3773 lsock6,
3734 5)) 3774 &do_accept,
3735 { 3775 lsock6);
3736 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
3737 "listen");
3738 GNUNET_NETWORK_socket_close(lsock6);
3739 lsock6 = NULL;
3740 }
3741 else
3742 {
3743 ltask6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
3744 lsock6,
3745 &do_accept,
3746 lsock6);
3747 }
3748 } 3776 }
3749 lsock4 = bind_v4(); 3777 }
3778 lsock4 = bind_v4 ();
3750 if (NULL == lsock4) 3779 if (NULL == lsock4)
3780 {
3781 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3782 "bind");
3783 }
3784 else
3785 {
3786 if (GNUNET_OK !=
3787 GNUNET_NETWORK_socket_listen (lsock4,
3788 5))
3751 { 3789 {
3752 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, 3790 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3753 "bind"); 3791 "listen");
3792 GNUNET_NETWORK_socket_close (lsock4);
3793 lsock4 = NULL;
3754 } 3794 }
3755 else 3795 else
3756 { 3796 {
3757 if (GNUNET_OK != 3797 ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3758 GNUNET_NETWORK_socket_listen(lsock4, 3798 lsock4,
3759 5)) 3799 &do_accept,
3760 { 3800 lsock4);
3761 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
3762 "listen");
3763 GNUNET_NETWORK_socket_close(lsock4);
3764 lsock4 = NULL;
3765 }
3766 else
3767 {
3768 ltask4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
3769 lsock4,
3770 &do_accept,
3771 lsock4);
3772 }
3773 } 3801 }
3802 }
3774 if ((NULL == lsock4) && 3803 if ((NULL == lsock4) &&
3775 (NULL == lsock6)) 3804 (NULL == lsock6))
3776 { 3805 {
3777 GNUNET_SCHEDULER_shutdown(); 3806 GNUNET_SCHEDULER_shutdown ();
3778 return; 3807 return;
3779 } 3808 }
3780 if (0 != curl_global_init(CURL_GLOBAL_WIN32)) 3809 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
3781 { 3810 {
3782 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3811 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3783 "cURL global init failed!\n"); 3812 "cURL global init failed!\n");
3784 GNUNET_SCHEDULER_shutdown(); 3813 GNUNET_SCHEDULER_shutdown ();
3785 return; 3814 return;
3786 } 3815 }
3787 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3788 "Proxy listens on port %u\n", 3817 "Proxy listens on port %u\n",
3789 (unsigned int)port); 3818 (unsigned int) port);
3790 3819
3791 /* start MHD daemon for HTTP */ 3820 /* start MHD daemon for HTTP */
3792 hd = GNUNET_new(struct MhdHttpList); 3821 hd = GNUNET_new (struct MhdHttpList);
3793 hd->daemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, 3822 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET
3794 0, 3823 | MHD_ALLOW_SUSPEND_RESUME,
3795 NULL, NULL, 3824 0,
3796 &create_response, hd, 3825 NULL, NULL,
3797 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, 3826 &create_response, hd,
3798 MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, 3827 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned
3799 MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, 3828 int) 16,
3800 MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, 3829 MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb,
3801 MHD_OPTION_END); 3830 NULL,
3831 MHD_OPTION_NOTIFY_CONNECTION,
3832 &mhd_connection_cb, NULL,
3833 MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback,
3834 NULL,
3835 MHD_OPTION_END);
3802 if (NULL == hd->daemon) 3836 if (NULL == hd->daemon)
3803 { 3837 {
3804 GNUNET_free(hd); 3838 GNUNET_free (hd);
3805 GNUNET_SCHEDULER_shutdown(); 3839 GNUNET_SCHEDULER_shutdown ();
3806 return; 3840 return;
3807 } 3841 }
3808 httpd = hd; 3842 httpd = hd;
3809 GNUNET_CONTAINER_DLL_insert(mhd_httpd_head, 3843 GNUNET_CONTAINER_DLL_insert (mhd_httpd_head,
3810 mhd_httpd_tail, 3844 mhd_httpd_tail,
3811 hd); 3845 hd);
3812} 3846}
3813 3847
3814 3848
@@ -3820,53 +3854,54 @@ run(void *cls,
3820 * @return 0 ok, 1 on error 3854 * @return 0 ok, 1 on error
3821 */ 3855 */
3822int 3856int
3823main(int argc, 3857main (int argc,
3824 char *const *argv) 3858 char *const *argv)
3825{ 3859{
3826 struct GNUNET_GETOPT_CommandLineOption options[] = { 3860 struct GNUNET_GETOPT_CommandLineOption options[] = {
3827 GNUNET_GETOPT_option_uint16('p', 3861 GNUNET_GETOPT_option_uint16 ('p',
3828 "port", 3862 "port",
3829 NULL, 3863 NULL,
3830 gettext_noop("listen on specified port (default: 7777)"), 3864 gettext_noop (
3831 &port), 3865 "listen on specified port (default: 7777)"),
3832 GNUNET_GETOPT_option_string('a', 3866 &port),
3833 "authority", 3867 GNUNET_GETOPT_option_string ('a',
3834 NULL, 3868 "authority",
3835 gettext_noop("pem file to use as CA"), 3869 NULL,
3836 &cafile_opt), 3870 gettext_noop ("pem file to use as CA"),
3837 GNUNET_GETOPT_option_flag('6', 3871 &cafile_opt),
3838 "disable-ivp6", 3872 GNUNET_GETOPT_option_flag ('6',
3839 gettext_noop("disable use of IPv6"), 3873 "disable-ivp6",
3840 &disable_v6), 3874 gettext_noop ("disable use of IPv6"),
3875 &disable_v6),
3841 3876
3842 GNUNET_GETOPT_OPTION_END 3877 GNUNET_GETOPT_OPTION_END
3843 }; 3878 };
3844 static const char* page = 3879 static const char*page =
3845 "<html><head><title>gnunet-gns-proxy</title>" 3880 "<html><head><title>gnunet-gns-proxy</title>"
3846 "</head><body>cURL fail</body></html>"; 3881 "</head><body>cURL fail</body></html>";
3847 int ret; 3882 int ret;
3848 3883
3849 if (GNUNET_OK != 3884 if (GNUNET_OK !=
3850 GNUNET_STRINGS_get_utf8_args(argc, argv, 3885 GNUNET_STRINGS_get_utf8_args (argc, argv,
3851 &argc, &argv)) 3886 &argc, &argv))
3852 return 2; 3887 return 2;
3853 GNUNET_log_setup("gnunet-gns-proxy", 3888 GNUNET_log_setup ("gnunet-gns-proxy",
3854 "WARNING", 3889 "WARNING",
3855 NULL); 3890 NULL);
3856 curl_failure_response 3891 curl_failure_response
3857 = MHD_create_response_from_buffer(strlen(page), 3892 = MHD_create_response_from_buffer (strlen (page),
3858 (void *)page, 3893 (void *) page,
3859 MHD_RESPMEM_PERSISTENT); 3894 MHD_RESPMEM_PERSISTENT);
3860 3895
3861 ret = 3896 ret =
3862 (GNUNET_OK == 3897 (GNUNET_OK ==
3863 GNUNET_PROGRAM_run(argc, argv, 3898 GNUNET_PROGRAM_run (argc, argv,
3864 "gnunet-gns-proxy", 3899 "gnunet-gns-proxy",
3865 _("GNUnet GNS proxy"), 3900 _ ("GNUnet GNS proxy"),
3866 options, 3901 options,
3867 &run, NULL)) ? 0 : 1; 3902 &run, NULL)) ? 0 : 1;
3868 MHD_destroy_response(curl_failure_response); 3903 MHD_destroy_response (curl_failure_response);
3869 GNUNET_free_non_null((char *)argv); 3904 GNUNET_free_non_null ((char *) argv);
3870 return ret; 3905 return ret;
3871} 3906}
3872 3907
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 5bfaf4859..57ab393b0 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -46,7 +46,8 @@ struct GnsClient;
46/** 46/**
47 * Handle to a lookup operation from client via API. 47 * Handle to a lookup operation from client via API.
48 */ 48 */
49struct ClientLookupHandle { 49struct ClientLookupHandle
50{
50 /** 51 /**
51 * We keep these in a DLL. 52 * We keep these in a DLL.
52 */ 53 */
@@ -77,7 +78,8 @@ struct ClientLookupHandle {
77/** 78/**
78 * Information we track per connected client. 79 * Information we track per connected client.
79 */ 80 */
80struct GnsClient { 81struct GnsClient
82{
81 /** 83 /**
82 * The client 84 * The client
83 */ 85 */
@@ -104,7 +106,8 @@ struct GnsClient {
104 * Representation of a TLD, mapping the respective TLD string 106 * Representation of a TLD, mapping the respective TLD string
105 * (i.e. ".gnu") to the respective public key of the zone. 107 * (i.e. ".gnu") to the respective public key of the zone.
106 */ 108 */
107struct GNS_TopLevelDomain { 109struct GNS_TopLevelDomain
110{
108 /** 111 /**
109 * Kept in a DLL, as there are unlikely enough of these to 112 * Kept in a DLL, as there are unlikely enough of these to
110 * warrant a hash map. 113 * warrant a hash map.
@@ -173,25 +176,25 @@ static struct GNS_TopLevelDomain *tld_tail;
173 * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not 176 * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not
174 */ 177 */
175int 178int
176GNS_find_tld(const char *tld_str, 179GNS_find_tld (const char *tld_str,
177 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) 180 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
178{ 181{
179 if ('\0' == *tld_str) 182 if ('\0' == *tld_str)
180 return GNUNET_NO; 183 return GNUNET_NO;
181 for (struct GNS_TopLevelDomain *tld = tld_head; 184 for (struct GNS_TopLevelDomain *tld = tld_head;
182 NULL != tld; 185 NULL != tld;
183 tld = tld->next) 186 tld = tld->next)
187 {
188 if (0 == strcasecmp (tld_str,
189 tld->tld))
184 { 190 {
185 if (0 == strcasecmp(tld_str, 191 *pkey = tld->pkey;
186 tld->tld)) 192 return GNUNET_YES;
187 {
188 *pkey = tld->pkey;
189 return GNUNET_YES;
190 }
191 } 193 }
194 }
192 if (GNUNET_OK == 195 if (GNUNET_OK ==
193 GNUNET_GNSRECORD_zkey_to_pkey(tld_str + 1, 196 GNUNET_GNSRECORD_zkey_to_pkey (tld_str + 1,
194 pkey)) 197 pkey))
195 return GNUNET_YES; /* TLD string *was* the public key */ 198 return GNUNET_YES; /* TLD string *was* the public key */
196 return GNUNET_NO; 199 return GNUNET_NO;
197} 200}
@@ -205,12 +208,12 @@ GNS_find_tld(const char *tld_str,
205 * or @a name if @a name does not contain a "." 208 * or @a name if @a name does not contain a "."
206 */ 209 */
207const char * 210const char *
208GNS_get_tld(const char *name) 211GNS_get_tld (const char *name)
209{ 212{
210 const char *tld; 213 const char *tld;
211 214
212 tld = strrchr(name, 215 tld = strrchr (name,
213 (unsigned char)'.'); 216 (unsigned char) '.');
214 if (NULL == tld) 217 if (NULL == tld)
215 tld = name; 218 tld = name;
216 else 219 else
@@ -225,39 +228,39 @@ GNS_get_tld(const char *name)
225 * @param cls unused, NULL 228 * @param cls unused, NULL
226 */ 229 */
227static void 230static void
228shutdown_task(void *cls) 231shutdown_task (void *cls)
229{ 232{
230 struct GNS_TopLevelDomain *tld; 233 struct GNS_TopLevelDomain *tld;
231 234
232 (void)cls; 235 (void) cls;
233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 "Shutting down!\n"); 237 "Shutting down!\n");
235 GNS_interceptor_done(); 238 GNS_interceptor_done ();
236 GNS_resolver_done(); 239 GNS_resolver_done ();
237 if (NULL != statistics) 240 if (NULL != statistics)
238 { 241 {
239 GNUNET_STATISTICS_destroy(statistics, 242 GNUNET_STATISTICS_destroy (statistics,
240 GNUNET_NO); 243 GNUNET_NO);
241 statistics = NULL; 244 statistics = NULL;
242 } 245 }
243 if (NULL != namecache_handle) 246 if (NULL != namecache_handle)
244 { 247 {
245 GNUNET_NAMECACHE_disconnect(namecache_handle); 248 GNUNET_NAMECACHE_disconnect (namecache_handle);
246 namecache_handle = NULL; 249 namecache_handle = NULL;
247 } 250 }
248 if (NULL != dht_handle) 251 if (NULL != dht_handle)
249 { 252 {
250 GNUNET_DHT_disconnect(dht_handle); 253 GNUNET_DHT_disconnect (dht_handle);
251 dht_handle = NULL; 254 dht_handle = NULL;
252 } 255 }
253 while (NULL != (tld = tld_head)) 256 while (NULL != (tld = tld_head))
254 { 257 {
255 GNUNET_CONTAINER_DLL_remove(tld_head, 258 GNUNET_CONTAINER_DLL_remove (tld_head,
256 tld_tail, 259 tld_tail,
257 tld); 260 tld);
258 GNUNET_free(tld->tld); 261 GNUNET_free (tld->tld);
259 GNUNET_free(tld); 262 GNUNET_free (tld);
260 } 263 }
261} 264}
262 265
263 266
@@ -269,27 +272,27 @@ shutdown_task(void *cls)
269 * @param app_ctx @a client 272 * @param app_ctx @a client
270 */ 273 */
271static void 274static void
272client_disconnect_cb(void *cls, 275client_disconnect_cb (void *cls,
273 struct GNUNET_SERVICE_Client *client, 276 struct GNUNET_SERVICE_Client *client,
274 void *app_ctx) 277 void *app_ctx)
275{ 278{
276 struct ClientLookupHandle *clh; 279 struct ClientLookupHandle *clh;
277 struct GnsClient *gc = app_ctx; 280 struct GnsClient *gc = app_ctx;
278 281
279 (void)cls; 282 (void) cls;
280 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "Client %p disconnected\n", 284 "Client %p disconnected\n",
282 client); 285 client);
283 while (NULL != (clh = gc->clh_head)) 286 while (NULL != (clh = gc->clh_head))
284 { 287 {
285 if (NULL != clh->lookup) 288 if (NULL != clh->lookup)
286 GNS_resolver_lookup_cancel(clh->lookup); 289 GNS_resolver_lookup_cancel (clh->lookup);
287 GNUNET_CONTAINER_DLL_remove(gc->clh_head, 290 GNUNET_CONTAINER_DLL_remove (gc->clh_head,
288 gc->clh_tail, 291 gc->clh_tail,
289 clh); 292 clh);
290 GNUNET_free(clh); 293 GNUNET_free (clh);
291 } 294 }
292 GNUNET_free(gc); 295 GNUNET_free (gc);
293} 296}
294 297
295 298
@@ -302,17 +305,17 @@ client_disconnect_cb(void *cls,
302 * @return internal namestore client structure for this client 305 * @return internal namestore client structure for this client
303 */ 306 */
304static void * 307static void *
305client_connect_cb(void *cls, 308client_connect_cb (void *cls,
306 struct GNUNET_SERVICE_Client *client, 309 struct GNUNET_SERVICE_Client *client,
307 struct GNUNET_MQ_Handle *mq) 310 struct GNUNET_MQ_Handle *mq)
308{ 311{
309 struct GnsClient *gc; 312 struct GnsClient *gc;
310 313
311 (void)cls; 314 (void) cls;
312 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Client %p connected\n", 316 "Client %p connected\n",
314 client); 317 client);
315 gc = GNUNET_new(struct GnsClient); 318 gc = GNUNET_new (struct GnsClient);
316 gc->client = client; 319 gc->client = client;
317 gc->mq = mq; 320 gc->mq = mq;
318 return gc; 321 return gc;
@@ -327,9 +330,9 @@ client_connect_cb(void *cls,
327 * @param rd the record data 330 * @param rd the record data
328 */ 331 */
329static void 332static void
330send_lookup_response(void *cls, 333send_lookup_response (void *cls,
331 uint32_t rd_count, 334 uint32_t rd_count,
332 const struct GNUNET_GNSRECORD_Data *rd) 335 const struct GNUNET_GNSRECORD_Data *rd)
333{ 336{
334 struct ClientLookupHandle *clh = cls; 337 struct ClientLookupHandle *clh = cls;
335 struct GnsClient *gc = clh->gc; 338 struct GnsClient *gc = clh->gc;
@@ -337,46 +340,46 @@ send_lookup_response(void *cls,
337 struct LookupResultMessage *rmsg; 340 struct LookupResultMessage *rmsg;
338 ssize_t len; 341 ssize_t len;
339 342
340 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Sending LOOKUP_RESULT message with %u results\n", 344 "Sending LOOKUP_RESULT message with %u results\n",
342 (unsigned int)rd_count); 345 (unsigned int) rd_count);
343 len = GNUNET_GNSRECORD_records_get_size(rd_count, 346 len = GNUNET_GNSRECORD_records_get_size (rd_count,
344 rd); 347 rd);
345 if (len < 0) 348 if (len < 0)
346 { 349 {
347 GNUNET_break(0); 350 GNUNET_break (0);
348 GNUNET_SERVICE_client_drop(gc->client); 351 GNUNET_SERVICE_client_drop (gc->client);
349 return; 352 return;
350 } 353 }
351 if (len > UINT16_MAX - sizeof(*rmsg)) 354 if (len > UINT16_MAX - sizeof(*rmsg))
352 { 355 {
353 GNUNET_break(0); 356 GNUNET_break (0);
354 GNUNET_SERVICE_client_drop(gc->client); 357 GNUNET_SERVICE_client_drop (gc->client);
355 return; 358 return;
356 } 359 }
357 env = GNUNET_MQ_msg_extra(rmsg, 360 env = GNUNET_MQ_msg_extra (rmsg,
358 len, 361 len,
359 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); 362 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
360 rmsg->id = clh->request_id; 363 rmsg->id = clh->request_id;
361 rmsg->rd_count = htonl(rd_count); 364 rmsg->rd_count = htonl (rd_count);
362 GNUNET_assert(len == 365 GNUNET_assert (len ==
363 GNUNET_GNSRECORD_records_serialize(rd_count, 366 GNUNET_GNSRECORD_records_serialize (rd_count,
364 rd, 367 rd,
365 len, 368 len,
366 (char*)&rmsg[1])); 369 (char*) &rmsg[1]));
367 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(gc->client), 370 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (gc->client),
368 env); 371 env);
369 GNUNET_CONTAINER_DLL_remove(gc->clh_head, 372 GNUNET_CONTAINER_DLL_remove (gc->clh_head,
370 gc->clh_tail, 373 gc->clh_tail,
371 clh); 374 clh);
372 GNUNET_free(clh); 375 GNUNET_free (clh);
373 GNUNET_STATISTICS_update(statistics, 376 GNUNET_STATISTICS_update (statistics,
374 "Completed lookups", 1, 377 "Completed lookups", 1,
375 GNUNET_NO); 378 GNUNET_NO);
376 GNUNET_STATISTICS_update(statistics, 379 GNUNET_STATISTICS_update (statistics,
377 "Records resolved", 380 "Records resolved",
378 rd_count, 381 rd_count,
379 GNUNET_NO); 382 GNUNET_NO);
380} 383}
381 384
382 385
@@ -388,19 +391,19 @@ send_lookup_response(void *cls,
388 * @return #GNUNET_OK if @a l_msg is well-formed 391 * @return #GNUNET_OK if @a l_msg is well-formed
389 */ 392 */
390static int 393static int
391check_lookup(void *cls, 394check_lookup (void *cls,
392 const struct LookupMessage *l_msg) 395 const struct LookupMessage *l_msg)
393{ 396{
394 size_t nlen; 397 size_t nlen;
395 398
396 (void)cls; 399 (void) cls;
397 GNUNET_MQ_check_zero_termination(l_msg); 400 GNUNET_MQ_check_zero_termination (l_msg);
398 nlen = ntohs(l_msg->header.size) - sizeof(struct LookupMessage); 401 nlen = ntohs (l_msg->header.size) - sizeof(struct LookupMessage);
399 if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH) 402 if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
400 { 403 {
401 GNUNET_break(0); 404 GNUNET_break (0);
402 return GNUNET_SYSERR; 405 return GNUNET_SYSERR;
403 } 406 }
404 return GNUNET_OK; 407 return GNUNET_OK;
405} 408}
406 409
@@ -413,8 +416,8 @@ check_lookup(void *cls,
413 * @param message the message 416 * @param message the message
414 */ 417 */
415static void 418static void
416handle_lookup(void *cls, 419handle_lookup (void *cls,
417 const struct LookupMessage *sh_msg) 420 const struct LookupMessage *sh_msg)
418{ 421{
419 struct GnsClient *gc = cls; 422 struct GnsClient *gc = cls;
420 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1]; 423 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1];
@@ -422,47 +425,48 @@ handle_lookup(void *cls,
422 char *nameptr = name; 425 char *nameptr = name;
423 const char *utf_in; 426 const char *utf_in;
424 427
425 GNUNET_SERVICE_client_continue(gc->client); 428 GNUNET_SERVICE_client_continue (gc->client);
426 utf_in = (const char *)&sh_msg[1]; 429 utf_in = (const char *) &sh_msg[1];
427 GNUNET_STRINGS_utf8_tolower(utf_in, 430 GNUNET_STRINGS_utf8_tolower (utf_in,
428 nameptr); 431 nameptr);
429 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "Received LOOKUP `%s' message\n", 433 "Received LOOKUP `%s' message\n",
431 name); 434 name);
432 clh = GNUNET_new(struct ClientLookupHandle); 435 clh = GNUNET_new (struct ClientLookupHandle);
433 GNUNET_CONTAINER_DLL_insert(gc->clh_head, 436 GNUNET_CONTAINER_DLL_insert (gc->clh_head,
434 gc->clh_tail, 437 gc->clh_tail,
435 clh); 438 clh);
436 clh->gc = gc; 439 clh->gc = gc;
437 clh->request_id = sh_msg->id; 440 clh->request_id = sh_msg->id;
438 if ((GNUNET_DNSPARSER_TYPE_A == ntohl(sh_msg->type)) && 441 if ((GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) &&
439 (GNUNET_OK != v4_enabled)) 442 (GNUNET_OK != v4_enabled))
440 { 443 {
441 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "LOOKUP: Query for A record but AF_INET not supported!"); 445 "LOOKUP: Query for A record but AF_INET not supported!");
443 send_lookup_response(clh, 446 send_lookup_response (clh,
444 0, 447 0,
445 NULL); 448 NULL);
446 return; 449 return;
447 } 450 }
448 if ((GNUNET_DNSPARSER_TYPE_AAAA == ntohl(sh_msg->type)) && 451 if ((GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) &&
449 (GNUNET_OK != v6_enabled)) 452 (GNUNET_OK != v6_enabled))
450 { 453 {
451 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
452 "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); 455 "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
453 send_lookup_response(clh, 456 send_lookup_response (clh,
454 0, 457 0,
455 NULL); 458 NULL);
456 return; 459 return;
457 } 460 }
458 clh->lookup = GNS_resolver_lookup(&sh_msg->zone, 461 clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
459 ntohl(sh_msg->type), 462 ntohl (sh_msg->type),
460 name, 463 name,
461 (enum GNUNET_GNS_LocalOptions)ntohs(sh_msg->options), 464 (enum GNUNET_GNS_LocalOptions) ntohs (
462 &send_lookup_response, clh); 465 sh_msg->options),
463 GNUNET_STATISTICS_update(statistics, 466 &send_lookup_response, clh);
464 "Lookup attempts", 467 GNUNET_STATISTICS_update (statistics,
465 1, GNUNET_NO); 468 "Lookup attempts",
469 1, GNUNET_NO);
466} 470}
467 471
468 472
@@ -475,36 +479,37 @@ handle_lookup(void *cls,
475 * @param value value for the option, public key for TLDs 479 * @param value value for the option, public key for TLDs
476 */ 480 */
477static void 481static void
478read_service_conf(void *cls, 482read_service_conf (void *cls,
479 const char *section, 483 const char *section,
480 const char *option, 484 const char *option,
481 const char *value) 485 const char *value)
482{ 486{
483 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 487 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
484 struct GNS_TopLevelDomain *tld; 488 struct GNS_TopLevelDomain *tld;
485 489
486 (void)cls; 490 (void) cls;
487 (void)section; 491 (void) section;
488 if (option[0] != '.') 492 if (option[0] != '.')
489 return; 493 return;
490 if (GNUNET_OK != 494 if (GNUNET_OK !=
491 GNUNET_STRINGS_string_to_data(value, 495 GNUNET_STRINGS_string_to_data (value,
492 strlen(value), 496 strlen (value),
493 &pk, 497 &pk,
494 sizeof(pk))) 498 sizeof(pk)))
495 { 499 {
496 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, 500 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
497 section, 501 section,
498 option, 502 option,
499 _("Properly base32-encoded public key required")); 503 _ (
500 return; 504 "Properly base32-encoded public key required"));
501 } 505 return;
502 tld = GNUNET_new(struct GNS_TopLevelDomain); 506 }
503 tld->tld = GNUNET_strdup(&option[1]); 507 tld = GNUNET_new (struct GNS_TopLevelDomain);
508 tld->tld = GNUNET_strdup (&option[1]);
504 tld->pkey = pk; 509 tld->pkey = pk;
505 GNUNET_CONTAINER_DLL_insert(tld_head, 510 GNUNET_CONTAINER_DLL_insert (tld_head,
506 tld_tail, 511 tld_tail,
507 tld); 512 tld);
508} 513}
509 514
510 515
@@ -516,66 +521,66 @@ read_service_conf(void *cls,
516 * @param c configuration to use 521 * @param c configuration to use
517 */ 522 */
518static void 523static void
519run(void *cls, 524run (void *cls,
520 const struct GNUNET_CONFIGURATION_Handle *c, 525 const struct GNUNET_CONFIGURATION_Handle *c,
521 struct GNUNET_SERVICE_Handle *service) 526 struct GNUNET_SERVICE_Handle *service)
522{ 527{
523 unsigned long long max_parallel_bg_queries = 16; 528 unsigned long long max_parallel_bg_queries = 16;
524 529
525 GNUNET_CONFIGURATION_iterate_section_values(c, 530 GNUNET_CONFIGURATION_iterate_section_values (c,
526 "gns", 531 "gns",
527 &read_service_conf, 532 &read_service_conf,
528 NULL); 533 NULL);
529 v6_enabled = GNUNET_NETWORK_test_pf(PF_INET6); 534 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
530 v4_enabled = GNUNET_NETWORK_test_pf(PF_INET); 535 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
531 namecache_handle = GNUNET_NAMECACHE_connect(c); 536 namecache_handle = GNUNET_NAMECACHE_connect (c);
532 if (NULL == namecache_handle) 537 if (NULL == namecache_handle)
533 { 538 {
534 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 539 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
535 _("Failed to connect to the namecache!\n")); 540 _ ("Failed to connect to the namecache!\n"));
536 GNUNET_SCHEDULER_shutdown(); 541 GNUNET_SCHEDULER_shutdown ();
537 return; 542 return;
538 } 543 }
539 if (GNUNET_OK == 544 if (GNUNET_OK ==
540 GNUNET_CONFIGURATION_get_value_number(c, 545 GNUNET_CONFIGURATION_get_value_number (c,
541 "gns", 546 "gns",
542 "MAX_PARALLEL_BACKGROUND_QUERIES", 547 "MAX_PARALLEL_BACKGROUND_QUERIES",
543 &max_parallel_bg_queries)) 548 &max_parallel_bg_queries))
544 { 549 {
545 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
546 "Number of allowed parallel background queries: %llu\n", 551 "Number of allowed parallel background queries: %llu\n",
547 max_parallel_bg_queries); 552 max_parallel_bg_queries);
548 } 553 }
549 dht_handle = GNUNET_DHT_connect(c, 554 dht_handle = GNUNET_DHT_connect (c,
550 (unsigned int)max_parallel_bg_queries); 555 (unsigned int) max_parallel_bg_queries);
551 if (NULL == dht_handle) 556 if (NULL == dht_handle)
552 { 557 {
553 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 558 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
554 _("Could not connect to DHT!\n")); 559 _ ("Could not connect to DHT!\n"));
555 GNUNET_SCHEDULER_add_now(&shutdown_task, 560 GNUNET_SCHEDULER_add_now (&shutdown_task,
556 NULL); 561 NULL);
557 return; 562 return;
558 } 563 }
559 GNS_resolver_init(namecache_handle, 564 GNS_resolver_init (namecache_handle,
560 dht_handle, 565 dht_handle,
561 c, 566 c,
562 max_parallel_bg_queries); 567 max_parallel_bg_queries);
563 if ((GNUNET_YES == 568 if ((GNUNET_YES ==
564 GNUNET_CONFIGURATION_get_value_yesno(c, 569 GNUNET_CONFIGURATION_get_value_yesno (c,
565 "gns", 570 "gns",
566 "INTERCEPT_DNS")) && 571 "INTERCEPT_DNS")) &&
567 (GNUNET_SYSERR == 572 (GNUNET_SYSERR ==
568 GNS_interceptor_init(c))) 573 GNS_interceptor_init (c)))
569 { 574 {
570 GNUNET_break(0); 575 GNUNET_break (0);
571 GNUNET_SCHEDULER_add_now(&shutdown_task, 576 GNUNET_SCHEDULER_add_now (&shutdown_task,
572 NULL); 577 NULL);
573 return; 578 return;
574 } 579 }
575 statistics = GNUNET_STATISTICS_create("gns", 580 statistics = GNUNET_STATISTICS_create ("gns",
576 c); 581 c);
577 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 582 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
578 NULL); 583 NULL);
579} 584}
580 585
581 586
@@ -589,11 +594,11 @@ GNUNET_SERVICE_MAIN
589 &client_connect_cb, 594 &client_connect_cb,
590 &client_disconnect_cb, 595 &client_disconnect_cb,
591 NULL, 596 NULL,
592 GNUNET_MQ_hd_var_size(lookup, 597 GNUNET_MQ_hd_var_size (lookup,
593 GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 598 GNUNET_MESSAGE_TYPE_GNS_LOOKUP,
594 struct LookupMessage, 599 struct LookupMessage,
595 NULL), 600 NULL),
596 GNUNET_MQ_handler_end()); 601 GNUNET_MQ_handler_end ());
597 602
598 603
599/* end of gnunet-service-gns.c */ 604/* end of gnunet-service-gns.c */
diff --git a/src/gns/gnunet-service-gns.h b/src/gns/gnunet-service-gns.h
index 2c17ca72a..2a432f8aa 100644
--- a/src/gns/gnunet-service-gns.h
+++ b/src/gns/gnunet-service-gns.h
@@ -35,8 +35,8 @@
35 * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not 35 * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not
36 */ 36 */
37int 37int
38GNS_find_tld(const char *tld_str, 38GNS_find_tld (const char *tld_str,
39 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); 39 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey);
40 40
41 41
42/** 42/**
@@ -47,7 +47,7 @@ GNS_find_tld(const char *tld_str,
47 * or @a name if @a name does not contain a "." 47 * or @a name if @a name does not contain a "."
48 */ 48 */
49const char * 49const char *
50GNS_get_tld(const char *name); 50GNS_get_tld (const char *name);
51 51
52 52
53#endif 53#endif
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index e56aaef47..d6ee7f91c 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -37,7 +37,8 @@
37 * Handle to a DNS intercepted 37 * Handle to a DNS intercepted
38 * reslution request 38 * reslution request
39 */ 39 */
40struct InterceptLookupHandle { 40struct InterceptLookupHandle
41{
41 /** 42 /**
42 * We keep these in a DLL. 43 * We keep these in a DLL.
43 */ 44 */
@@ -89,8 +90,8 @@ static struct InterceptLookupHandle *ilh_tail;
89 * @param rd the record data 90 * @param rd the record data
90 */ 91 */
91static void 92static void
92reply_to_dns(void *cls, uint32_t rd_count, 93reply_to_dns (void *cls, uint32_t rd_count,
93 const struct GNUNET_GNSRECORD_Data *rd) 94 const struct GNUNET_GNSRECORD_Data *rd)
94{ 95{
95 struct InterceptLookupHandle *ilh = cls; 96 struct InterceptLookupHandle *ilh = cls;
96 struct GNUNET_DNSPARSER_Packet *packet = ilh->packet; 97 struct GNUNET_DNSPARSER_Packet *packet = ilh->packet;
@@ -122,130 +123,138 @@ reply_to_dns(void *cls, uint32_t rd_count,
122 (by ignoring records where this flag is set if there is any 123 (by ignoring records where this flag is set if there is any
123 other record of that type in the result set) */ 124 other record of that type in the result set) */
124 for (i = 0; i < rd_count; i++) 125 for (i = 0; i < rd_count; i++)
126 {
127 if (rd[i].record_type == query->type)
128 {
129 answer_records[i - skip_answers].name = query->name;
130 answer_records[i - skip_answers].type = rd[i].record_type;
131 switch (rd[i].record_type)
132 {
133 case GNUNET_DNSPARSER_TYPE_NS:
134 case GNUNET_DNSPARSER_TYPE_CNAME:
135 case GNUNET_DNSPARSER_TYPE_PTR:
136 answer_records[i - skip_answers].data.hostname
137 = GNUNET_DNSPARSER_parse_name (rd[i].data,
138 rd[i].data_size,
139 &off);
140 if ((off != rd[i].data_size) ||
141 (NULL == answer_records[i].data.hostname))
142 {
143 GNUNET_break_op (0);
144 skip_answers++;
145 }
146 break;
147
148 case GNUNET_DNSPARSER_TYPE_SOA:
149 answer_records[i - skip_answers].data.soa
150 = GNUNET_DNSPARSER_parse_soa (rd[i].data,
151 rd[i].data_size,
152 &off);
153 if ((off != rd[i].data_size) ||
154 (NULL == answer_records[i].data.soa))
155 {
156 GNUNET_break_op (0);
157 skip_answers++;
158 }
159 break;
160
161 case GNUNET_DNSPARSER_TYPE_SRV:
162 /* FIXME: SRV is not yet supported */
163 skip_answers++;
164 break;
165
166 case GNUNET_DNSPARSER_TYPE_MX:
167 answer_records[i - skip_answers].data.mx
168 = GNUNET_DNSPARSER_parse_mx (rd[i].data,
169 rd[i].data_size,
170 &off);
171 if ((off != rd[i].data_size) ||
172 (NULL == answer_records[i].data.hostname))
173 {
174 GNUNET_break_op (0);
175 skip_answers++;
176 }
177 break;
178
179 default:
180 answer_records[i - skip_answers].data.raw.data_len = rd[i].data_size;
181 answer_records[i - skip_answers].data.raw.data = (char*) rd[i].data;
182 break;
183 }
184 GNUNET_break (0 == (rd[i - skip_answers].flags
185 & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION));
186 answer_records[i - skip_answers].expiration_time.abs_value_us =
187 rd[i].expiration_time;
188 answer_records[i - skip_answers].dns_traffic_class =
189 GNUNET_TUN_DNS_CLASS_INTERNET;
190 }
191 else
125 { 192 {
126 if (rd[i].record_type == query->type) 193 additional_records[i - skip_additional].name = query->name;
194 additional_records[i - skip_additional].type = rd[i].record_type;
195 switch (rd[i].record_type)
196 {
197 case GNUNET_DNSPARSER_TYPE_NS:
198 case GNUNET_DNSPARSER_TYPE_CNAME:
199 case GNUNET_DNSPARSER_TYPE_PTR:
200 additional_records[i - skip_additional].data.hostname
201 = GNUNET_DNSPARSER_parse_name (rd[i].data,
202 rd[i].data_size,
203 &off);
204 if ((off != rd[i].data_size) ||
205 (NULL == additional_records[i].data.hostname))
206 {
207 GNUNET_break_op (0);
208 skip_additional++;
209 }
210 break;
211
212 case GNUNET_DNSPARSER_TYPE_SOA:
213 additional_records[i - skip_additional].data.soa
214 = GNUNET_DNSPARSER_parse_soa (rd[i].data,
215 rd[i].data_size,
216 &off);
217 if ((off != rd[i].data_size) ||
218 (NULL == additional_records[i].data.hostname))
127 { 219 {
128 answer_records[i - skip_answers].name = query->name; 220 GNUNET_break_op (0);
129 answer_records[i - skip_answers].type = rd[i].record_type; 221 skip_additional++;
130 switch (rd[i].record_type)
131 {
132 case GNUNET_DNSPARSER_TYPE_NS:
133 case GNUNET_DNSPARSER_TYPE_CNAME:
134 case GNUNET_DNSPARSER_TYPE_PTR:
135 answer_records[i - skip_answers].data.hostname
136 = GNUNET_DNSPARSER_parse_name(rd[i].data,
137 rd[i].data_size,
138 &off);
139 if ((off != rd[i].data_size) ||
140 (NULL == answer_records[i].data.hostname))
141 {
142 GNUNET_break_op(0);
143 skip_answers++;
144 }
145 break;
146
147 case GNUNET_DNSPARSER_TYPE_SOA:
148 answer_records[i - skip_answers].data.soa
149 = GNUNET_DNSPARSER_parse_soa(rd[i].data,
150 rd[i].data_size,
151 &off);
152 if ((off != rd[i].data_size) ||
153 (NULL == answer_records[i].data.soa))
154 {
155 GNUNET_break_op(0);
156 skip_answers++;
157 }
158 break;
159
160 case GNUNET_DNSPARSER_TYPE_SRV:
161 /* FIXME: SRV is not yet supported */
162 skip_answers++;
163 break;
164
165 case GNUNET_DNSPARSER_TYPE_MX:
166 answer_records[i - skip_answers].data.mx
167 = GNUNET_DNSPARSER_parse_mx(rd[i].data,
168 rd[i].data_size,
169 &off);
170 if ((off != rd[i].data_size) ||
171 (NULL == answer_records[i].data.hostname))
172 {
173 GNUNET_break_op(0);
174 skip_answers++;
175 }
176 break;
177
178 default:
179 answer_records[i - skip_answers].data.raw.data_len = rd[i].data_size;
180 answer_records[i - skip_answers].data.raw.data = (char*)rd[i].data;
181 break;
182 }
183 GNUNET_break(0 == (rd[i - skip_answers].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION));
184 answer_records[i - skip_answers].expiration_time.abs_value_us = rd[i].expiration_time;
185 answer_records[i - skip_answers].dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
186 } 222 }
187 else 223 break;
224
225 case GNUNET_DNSPARSER_TYPE_MX:
226 additional_records[i - skip_additional].data.mx
227 = GNUNET_DNSPARSER_parse_mx (rd[i].data,
228 rd[i].data_size,
229 &off);
230 if ((off != rd[i].data_size) ||
231 (NULL == additional_records[i].data.hostname))
188 { 232 {
189 additional_records[i - skip_additional].name = query->name; 233 GNUNET_break_op (0);
190 additional_records[i - skip_additional].type = rd[i].record_type; 234 skip_additional++;
191 switch (rd[i].record_type)
192 {
193 case GNUNET_DNSPARSER_TYPE_NS:
194 case GNUNET_DNSPARSER_TYPE_CNAME:
195 case GNUNET_DNSPARSER_TYPE_PTR:
196 additional_records[i - skip_additional].data.hostname
197 = GNUNET_DNSPARSER_parse_name(rd[i].data,
198 rd[i].data_size,
199 &off);
200 if ((off != rd[i].data_size) ||
201 (NULL == additional_records[i].data.hostname))
202 {
203 GNUNET_break_op(0);
204 skip_additional++;
205 }
206 break;
207
208 case GNUNET_DNSPARSER_TYPE_SOA:
209 additional_records[i - skip_additional].data.soa
210 = GNUNET_DNSPARSER_parse_soa(rd[i].data,
211 rd[i].data_size,
212 &off);
213 if ((off != rd[i].data_size) ||
214 (NULL == additional_records[i].data.hostname))
215 {
216 GNUNET_break_op(0);
217 skip_additional++;
218 }
219 break;
220
221 case GNUNET_DNSPARSER_TYPE_MX:
222 additional_records[i - skip_additional].data.mx
223 = GNUNET_DNSPARSER_parse_mx(rd[i].data,
224 rd[i].data_size,
225 &off);
226 if ((off != rd[i].data_size) ||
227 (NULL == additional_records[i].data.hostname))
228 {
229 GNUNET_break_op(0);
230 skip_additional++;
231 }
232 break;
233
234 case GNUNET_DNSPARSER_TYPE_SRV:
235 /* FIXME: SRV is not yet supported */
236 skip_answers++;
237 break;
238
239 default:
240 additional_records[i - skip_additional].data.raw.data_len = rd[i].data_size;
241 additional_records[i - skip_additional].data.raw.data = (char*)rd[i].data;
242 break;
243 }
244 GNUNET_break(0 == (rd[i - skip_additional].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION));
245 additional_records[i - skip_additional].expiration_time.abs_value_us = rd[i].expiration_time;
246 additional_records[i - skip_additional].dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
247 } 235 }
236 break;
237
238 case GNUNET_DNSPARSER_TYPE_SRV:
239 /* FIXME: SRV is not yet supported */
240 skip_answers++;
241 break;
242
243 default:
244 additional_records[i - skip_additional].data.raw.data_len =
245 rd[i].data_size;
246 additional_records[i - skip_additional].data.raw.data =
247 (char*) rd[i].data;
248 break;
249 }
250 GNUNET_break (0 == (rd[i - skip_additional].flags
251 & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION));
252 additional_records[i - skip_additional].expiration_time.abs_value_us =
253 rd[i].expiration_time;
254 additional_records[i - skip_additional].dns_traffic_class =
255 GNUNET_TUN_DNS_CLASS_INTERNET;
248 } 256 }
257 }
249 packet->num_answers = num_answers - skip_answers; 258 packet->num_answers = num_answers - skip_answers;
250 packet->num_additional_records = rd_count - num_answers - skip_additional; 259 packet->num_additional_records = rd_count - num_answers - skip_additional;
251 packet->flags.authoritative_answer = 1; 260 packet->flags.authoritative_answer = 1;
@@ -254,32 +263,32 @@ reply_to_dns(void *cls, uint32_t rd_count,
254 else 263 else
255 packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; 264 packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR;
256 packet->flags.query_or_response = 1; 265 packet->flags.query_or_response = 1;
257 ret = GNUNET_DNSPARSER_pack(packet, 266 ret = GNUNET_DNSPARSER_pack (packet,
258 1024, /* maximum allowed size for DNS reply */ 267 1024, /* maximum allowed size for DNS reply */
259 &buf, 268 &buf,
260 &len); 269 &len);
261 if (GNUNET_OK != ret) 270 if (GNUNET_OK != ret)
262 { 271 {
263 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 272 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
264 _("Error converting GNS response to DNS response!\n")); 273 _ ("Error converting GNS response to DNS response!\n"));
265 if (GNUNET_NO == ret) 274 if (GNUNET_NO == ret)
266 GNUNET_free(buf); 275 GNUNET_free (buf);
267 } 276 }
268 else 277 else
269 { 278 {
270 GNUNET_DNS_request_answer(ilh->request_handle, 279 GNUNET_DNS_request_answer (ilh->request_handle,
271 len, 280 len,
272 buf); 281 buf);
273 GNUNET_free(buf); 282 GNUNET_free (buf);
274 } 283 }
275 packet->num_answers = 0; 284 packet->num_answers = 0;
276 packet->answers = NULL; 285 packet->answers = NULL;
277 packet->num_additional_records = 0; 286 packet->num_additional_records = 0;
278 packet->additional_records = NULL; 287 packet->additional_records = NULL;
279 GNUNET_DNSPARSER_free_packet(packet); 288 GNUNET_DNSPARSER_free_packet (packet);
280 } 289 }
281 GNUNET_CONTAINER_DLL_remove(ilh_head, ilh_tail, ilh); 290 GNUNET_CONTAINER_DLL_remove (ilh_head, ilh_tail, ilh);
282 GNUNET_free(ilh); 291 GNUNET_free (ilh);
283} 292}
284 293
285 294
@@ -292,61 +301,61 @@ reply_to_dns(void *cls, uint32_t rd_count,
292 * @param request UDP payload of the DNS request 301 * @param request UDP payload of the DNS request
293 */ 302 */
294static void 303static void
295handle_dns_request(void *cls, 304handle_dns_request (void *cls,
296 struct GNUNET_DNS_RequestHandle *rh, 305 struct GNUNET_DNS_RequestHandle *rh,
297 size_t request_length, 306 size_t request_length,
298 const char *request) 307 const char *request)
299{ 308{
300 struct GNUNET_DNSPARSER_Packet *p; 309 struct GNUNET_DNSPARSER_Packet *p;
301 struct InterceptLookupHandle *ilh; 310 struct InterceptLookupHandle *ilh;
302 struct GNUNET_CRYPTO_EcdsaPublicKey zone; 311 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
303 312
304 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
305 "Hijacked a DNS request. Processing.\n"); 314 "Hijacked a DNS request. Processing.\n");
306 if (NULL == (p = GNUNET_DNSPARSER_parse(request, request_length))) 315 if (NULL == (p = GNUNET_DNSPARSER_parse (request, request_length)))
307 { 316 {
308 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 317 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
309 "Received malformed DNS packet, leaving it untouched.\n"); 318 "Received malformed DNS packet, leaving it untouched.\n");
310 GNUNET_DNS_request_forward(rh); 319 GNUNET_DNS_request_forward (rh);
311 GNUNET_DNSPARSER_free_packet(p); 320 GNUNET_DNSPARSER_free_packet (p);
312 return; 321 return;
313 } 322 }
314 323
315 /* Check TLD and decide if we or legacy dns is responsible */ 324 /* Check TLD and decide if we or legacy dns is responsible */
316 if (1 != p->num_queries) 325 if (1 != p->num_queries)
317 { 326 {
318 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
319 "Not exactly one query in DNS packet. Forwarding untouched.\n"); 328 "Not exactly one query in DNS packet. Forwarding untouched.\n");
320 GNUNET_DNS_request_forward(rh); 329 GNUNET_DNS_request_forward (rh);
321 GNUNET_DNSPARSER_free_packet(p); 330 GNUNET_DNSPARSER_free_packet (p);
322 return; 331 return;
323 } 332 }
324 333
325 /* Check for GNS TLDs. */ 334 /* Check for GNS TLDs. */
326 if (GNUNET_YES == 335 if (GNUNET_YES ==
327 GNS_find_tld(GNS_get_tld(p->queries[0].name), 336 GNS_find_tld (GNS_get_tld (p->queries[0].name),
328 &zone)) 337 &zone))
329 { 338 {
330 /* Start resolution in GNS */ 339 /* Start resolution in GNS */
331 ilh = GNUNET_new(struct InterceptLookupHandle); 340 ilh = GNUNET_new (struct InterceptLookupHandle);
332 GNUNET_CONTAINER_DLL_insert(ilh_head, 341 GNUNET_CONTAINER_DLL_insert (ilh_head,
333 ilh_tail, 342 ilh_tail,
334 ilh); 343 ilh);
335 ilh->packet = p; 344 ilh->packet = p;
336 ilh->request_handle = rh; 345 ilh->request_handle = rh;
337 ilh->lookup = GNS_resolver_lookup(&zone, 346 ilh->lookup = GNS_resolver_lookup (&zone,
338 p->queries[0].type, 347 p->queries[0].type,
339 p->queries[0].name, 348 p->queries[0].name,
340 GNUNET_NO, 349 GNUNET_NO,
341 &reply_to_dns, ilh); 350 &reply_to_dns, ilh);
342 return; 351 return;
343 } 352 }
344 /* This request does not concern us. Forward to real DNS. */ 353 /* This request does not concern us. Forward to real DNS. */
345 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
346 "Request for `%s' is forwarded to DNS untouched.\n", 355 "Request for `%s' is forwarded to DNS untouched.\n",
347 p->queries[0].name); 356 p->queries[0].name);
348 GNUNET_DNS_request_forward(rh); 357 GNUNET_DNS_request_forward (rh);
349 GNUNET_DNSPARSER_free_packet(p); 358 GNUNET_DNSPARSER_free_packet (p);
350} 359}
351 360
352 361
@@ -357,20 +366,20 @@ handle_dns_request(void *cls,
357 * @return #GNUNET_OK on success 366 * @return #GNUNET_OK on success
358 */ 367 */
359int 368int
360GNS_interceptor_init(const struct GNUNET_CONFIGURATION_Handle *c) 369GNS_interceptor_init (const struct GNUNET_CONFIGURATION_Handle *c)
361{ 370{
362 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 371 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
363 "DNS hijacking enabled. Connecting to DNS service.\n"); 372 "DNS hijacking enabled. Connecting to DNS service.\n");
364 dns_handle = GNUNET_DNS_connect(c, 373 dns_handle = GNUNET_DNS_connect (c,
365 GNUNET_DNS_FLAG_PRE_RESOLUTION, 374 GNUNET_DNS_FLAG_PRE_RESOLUTION,
366 &handle_dns_request, 375 &handle_dns_request,
367 NULL); 376 NULL);
368 if (NULL == dns_handle) 377 if (NULL == dns_handle)
369 { 378 {
370 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
371 _("Failed to connect to the DNS service!\n")); 380 _ ("Failed to connect to the DNS service!\n"));
372 return GNUNET_SYSERR; 381 return GNUNET_SYSERR;
373 } 382 }
374 return GNUNET_YES; 383 return GNUNET_YES;
375} 384}
376 385
@@ -379,25 +388,25 @@ GNS_interceptor_init(const struct GNUNET_CONFIGURATION_Handle *c)
379 * Disconnect from interceptor 388 * Disconnect from interceptor
380 */ 389 */
381void 390void
382GNS_interceptor_done() 391GNS_interceptor_done ()
383{ 392{
384 struct InterceptLookupHandle *ilh; 393 struct InterceptLookupHandle *ilh;
385 394
386 while (NULL != (ilh = ilh_head)) 395 while (NULL != (ilh = ilh_head))
387 { 396 {
388 GNUNET_CONTAINER_DLL_remove(ilh_head, 397 GNUNET_CONTAINER_DLL_remove (ilh_head,
389 ilh_tail, 398 ilh_tail,
390 ilh); 399 ilh);
391 GNS_resolver_lookup_cancel(ilh->lookup); 400 GNS_resolver_lookup_cancel (ilh->lookup);
392 GNUNET_DNS_request_drop(ilh->request_handle); 401 GNUNET_DNS_request_drop (ilh->request_handle);
393 GNUNET_DNSPARSER_free_packet(ilh->packet); 402 GNUNET_DNSPARSER_free_packet (ilh->packet);
394 GNUNET_free(ilh); 403 GNUNET_free (ilh);
395 } 404 }
396 if (NULL != dns_handle) 405 if (NULL != dns_handle)
397 { 406 {
398 GNUNET_DNS_disconnect(dns_handle); 407 GNUNET_DNS_disconnect (dns_handle);
399 dns_handle = NULL; 408 dns_handle = NULL;
400 } 409 }
401} 410}
402 411
403/* end of gnunet-service-gns_interceptor.c */ 412/* end of gnunet-service-gns_interceptor.c */
diff --git a/src/gns/gnunet-service-gns_interceptor.h b/src/gns/gnunet-service-gns_interceptor.h
index 10e1acab6..7f9733c2a 100644
--- a/src/gns/gnunet-service-gns_interceptor.h
+++ b/src/gns/gnunet-service-gns_interceptor.h
@@ -35,12 +35,12 @@
35 * @return #GNUNET_YES on success #GNUNET_SYSERR on error 35 * @return #GNUNET_YES on success #GNUNET_SYSERR on error
36 */ 36 */
37int 37int
38GNS_interceptor_init(const struct GNUNET_CONFIGURATION_Handle *c); 38GNS_interceptor_init (const struct GNUNET_CONFIGURATION_Handle *c);
39 39
40/** 40/**
41 * Stops the interceptor 41 * Stops the interceptor
42 */ 42 */
43void 43void
44GNS_interceptor_done(void); 44GNS_interceptor_done (void);
45 45
46#endif 46#endif
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index da54f3dd5..41b04e1ae 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -45,17 +45,19 @@
45/** 45/**
46 * Default DHT timeout for lookups. 46 * Default DHT timeout for lookups.
47 */ 47 */
48#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 48#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply ( \
49 GNUNET_TIME_UNIT_SECONDS, 60)
49 50
50/** 51/**
51 * Default timeout for DNS lookups. 52 * Default timeout for DNS lookups.
52 */ 53 */
53#define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 54#define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply ( \
55 GNUNET_TIME_UNIT_SECONDS, 15)
54 56
55/** 57/**
56 * Default timeout for VPN redirections. 58 * Default timeout for VPN redirections.
57 */ 59 */
58#define VPN_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) 60#define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
59 61
60/** 62/**
61 * DHT replication level 63 * DHT replication level
@@ -80,7 +82,8 @@ struct AuthorityChain;
80 * responsible DNS server hostname in a GNS2DNS recursive 82 * responsible DNS server hostname in a GNS2DNS recursive
81 * resolution. 83 * resolution.
82 */ 84 */
83struct Gns2DnsPending { 85struct Gns2DnsPending
86{
84 /** 87 /**
85 * Kept in a DLL. 88 * Kept in a DLL.
86 */ 89 */
@@ -126,7 +129,8 @@ struct GNS_ResolverHandle;
126 * DLL to hold the authority chain we had to pass in the resolution 129 * DLL to hold the authority chain we had to pass in the resolution
127 * process. 130 * process.
128 */ 131 */
129struct AuthorityChain { 132struct AuthorityChain
133{
130 /** 134 /**
131 * This is a DLL. 135 * This is a DLL.
132 */ 136 */
@@ -156,13 +160,15 @@ struct AuthorityChain {
156 /** 160 /**
157 * Information about the resolver authority for this label. 161 * Information about the resolver authority for this label.
158 */ 162 */
159 union { 163 union
164 {
160 /** 165 /**
161 * The zone of the GNS authority 166 * The zone of the GNS authority
162 */ 167 */
163 struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority; 168 struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority;
164 169
165 struct { 170 struct
171 {
166 /** 172 /**
167 * Domain of the DNS resolver that is the authority. 173 * Domain of the DNS resolver that is the authority.
168 * (appended to construct the DNS name to resolve; 174 * (appended to construct the DNS name to resolve;
@@ -205,7 +211,8 @@ struct AuthorityChain {
205/** 211/**
206 * A result we got from DNS. 212 * A result we got from DNS.
207 */ 213 */
208struct DnsResult { 214struct DnsResult
215{
209 /** 216 /**
210 * Kept in DLL. 217 * Kept in DLL.
211 */ 218 */
@@ -242,7 +249,8 @@ struct DnsResult {
242/** 249/**
243 * Closure for #vpn_allocation_cb. 250 * Closure for #vpn_allocation_cb.
244 */ 251 */
245struct VpnContext { 252struct VpnContext
253{
246 /** 254 /**
247 * Which resolution process are we processing. 255 * Which resolution process are we processing.
248 */ 256 */
@@ -274,7 +282,8 @@ struct VpnContext {
274 * Handle to a currenty pending resolution. On result (positive or 282 * Handle to a currenty pending resolution. On result (positive or
275 * negative) the #GNS_ResultProcessor is called. 283 * negative) the #GNS_ResultProcessor is called.
276 */ 284 */
277struct GNS_ResolverHandle { 285struct GNS_ResolverHandle
286{
278 /** 287 /**
279 * DLL 288 * DLL
280 */ 289 */
@@ -298,7 +307,7 @@ struct GNS_ResolverHandle {
298 /** 307 /**
299 * closure passed to @e proc 308 * closure passed to @e proc
300 */ 309 */
301 void* proc_cls; 310 void*proc_cls;
302 311
303 /** 312 /**
304 * Handle for DHT lookups. should be NULL if no lookups are in progress 313 * Handle for DHT lookups. should be NULL if no lookups are in progress
@@ -416,7 +425,8 @@ struct GNS_ResolverHandle {
416/** 425/**
417 * Active namestore caching operations. 426 * Active namestore caching operations.
418 */ 427 */
419struct CacheOps { 428struct CacheOps
429{
420 /** 430 /**
421 * Organized in a DLL. 431 * Organized in a DLL.
422 */ 432 */
@@ -506,19 +516,19 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
506 * @return #GNUNET_YES if canonical 516 * @return #GNUNET_YES if canonical
507 */ 517 */
508/* dead, but keep for now */ int 518/* dead, but keep for now */ int
509is_canonical(const char *name) 519is_canonical (const char *name)
510{ 520{
511 const char *pos; 521 const char *pos;
512 const char *dot; 522 const char *dot;
513 523
514 if (NULL == strchr(name, 524 if (NULL == strchr (name,
515 (unsigned char)'.')) 525 (unsigned char) '.'))
516 return GNUNET_YES; 526 return GNUNET_YES;
517 if ('_' != name[0]) 527 if ('_' != name[0])
518 return GNUNET_NO; 528 return GNUNET_NO;
519 pos = &name[1]; 529 pos = &name[1];
520 while (NULL != (dot = strchr(pos, 530 while (NULL != (dot = strchr (pos,
521 (unsigned char)'.'))) 531 (unsigned char) '.')))
522 if ('_' != dot[1]) 532 if ('_' != dot[1])
523 return GNUNET_NO; 533 return GNUNET_NO;
524 else 534 else
@@ -536,22 +546,23 @@ is_canonical(const char *name)
536 * @return updated name 546 * @return updated name
537 */ 547 */
538static char * 548static char *
539translate_dot_plus(struct GNS_ResolverHandle *rh, 549translate_dot_plus (struct GNS_ResolverHandle *rh,
540 char *name) 550 char *name)
541{ 551{
542 char *ret; 552 char *ret;
543 size_t s_len = strlen(name); 553 size_t s_len = strlen (name);
544 554
545 if (0 != strcmp(&name[s_len - 2], 555 if (0 != strcmp (&name[s_len - 2],
546 ".+")) 556 ".+"))
547 return name; /* did not end in ".+" */ 557 return name; /* did not end in ".+" */
548 GNUNET_assert(GNUNET_YES == rh->ac_tail->gns_authority); 558 GNUNET_assert (GNUNET_YES == rh->ac_tail->gns_authority);
549 GNUNET_asprintf(&ret, 559 GNUNET_asprintf (&ret,
550 "%.*s.%s", 560 "%.*s.%s",
551 (int)(s_len - 2), 561 (int) (s_len - 2),
552 name, 562 name,
553 GNUNET_GNSRECORD_pkey_to_zkey(&rh->ac_tail->authority_info.gns_authority)); 563 GNUNET_GNSRECORD_pkey_to_zkey (
554 GNUNET_free(name); 564 &rh->ac_tail->authority_info.gns_authority));
565 GNUNET_free (name);
555 return ret; 566 return ret;
556} 567}
557 568
@@ -563,12 +574,12 @@ translate_dot_plus(struct GNS_ResolverHandle *rh,
563 * @param cls the `struct GNS_ResolverHandle` 574 * @param cls the `struct GNS_ResolverHandle`
564 */ 575 */
565static void 576static void
566GNS_resolver_lookup_cancel_(void *cls) 577GNS_resolver_lookup_cancel_ (void *cls)
567{ 578{
568 struct GNS_ResolverHandle *rh = cls; 579 struct GNS_ResolverHandle *rh = cls;
569 580
570 rh->task_id = NULL; 581 rh->task_id = NULL;
571 GNS_resolver_lookup_cancel(rh); 582 GNS_resolver_lookup_cancel (rh);
572} 583}
573 584
574 585
@@ -578,14 +589,14 @@ GNS_resolver_lookup_cancel_(void *cls)
578 * @param rh the resolution to fail 589 * @param rh the resolution to fail
579 */ 590 */
580static void 591static void
581fail_resolution(struct GNS_ResolverHandle *rh) 592fail_resolution (struct GNS_ResolverHandle *rh)
582{ 593{
583 rh->proc(rh->proc_cls, 594 rh->proc (rh->proc_cls,
584 0, 595 0,
585 NULL); 596 NULL);
586 GNUNET_assert(NULL == rh->task_id); 597 GNUNET_assert (NULL == rh->task_id);
587 rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, 598 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
588 rh); 599 rh);
589} 600}
590 601
591 602
@@ -595,12 +606,12 @@ fail_resolution(struct GNS_ResolverHandle *rh)
595 * @param cls the `struct GNS_ResolverHandle` 606 * @param cls the `struct GNS_ResolverHandle`
596 */ 607 */
597static void 608static void
598timeout_resolution(void *cls) 609timeout_resolution (void *cls)
599{ 610{
600 struct GNS_ResolverHandle *rh = cls; 611 struct GNS_ResolverHandle *rh = cls;
601 612
602 rh->task_id = NULL; 613 rh->task_id = NULL;
603 fail_resolution(rh); 614 fail_resolution (rh);
604} 615}
605 616
606 617
@@ -622,7 +633,7 @@ timeout_resolution(void *cls)
622 * @return NULL if there are no more labels 633 * @return NULL if there are no more labels
623 */ 634 */
624static char * 635static char *
625resolver_lookup_get_next_label(struct GNS_ResolverHandle *rh) 636resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh)
626{ 637{
627 const char *rp; 638 const char *rp;
628 const char *dot; 639 const char *dot;
@@ -635,71 +646,73 @@ resolver_lookup_get_next_label(struct GNS_ResolverHandle *rh)
635 646
636 if (0 == rh->name_resolution_pos) 647 if (0 == rh->name_resolution_pos)
637 return NULL; 648 return NULL;
638 dot = memrchr(rh->name, 649 dot = memrchr (rh->name,
639 (int)'.', 650 (int) '.',
640 rh->name_resolution_pos); 651 rh->name_resolution_pos);
641 if (NULL == dot) 652 if (NULL == dot)
642 { 653 {
643 /* done, this was the last one */ 654 /* done, this was the last one */
644 len = rh->name_resolution_pos; 655 len = rh->name_resolution_pos;
645 rp = rh->name; 656 rp = rh->name;
646 rh->name_resolution_pos = 0; 657 rh->name_resolution_pos = 0;
647 } 658 }
648 else 659 else
649 { 660 {
650 /* advance by one label */ 661 /* advance by one label */
651 len = rh->name_resolution_pos - (dot - rh->name) - 1; 662 len = rh->name_resolution_pos - (dot - rh->name) - 1;
652 rp = dot + 1; 663 rp = dot + 1;
653 rh->name_resolution_pos = dot - rh->name; 664 rh->name_resolution_pos = dot - rh->name;
654 } 665 }
655 rh->protocol = 0; 666 rh->protocol = 0;
656 rh->service = 0; 667 rh->service = 0;
657 ret = GNUNET_strndup(rp, len); 668 ret = GNUNET_strndup (rp, len);
658 /* If we have labels starting with underscore with label on 669 /* If we have labels starting with underscore with label on
659 * the right (SRV/DANE/BOX case), determine port/protocol; 670 * the right (SRV/DANE/BOX case), determine port/protocol;
660 * The format of `rh->name` must be "_PORT._PROTOCOL". 671 * The format of `rh->name` must be "_PORT._PROTOCOL".
661 */ 672 */
662 if (('_' == rh->name[0]) && 673 if (('_' == rh->name[0]) &&
663 (NULL != (dot = memrchr(rh->name, 674 (NULL != (dot = memrchr (rh->name,
664 (int)'.', 675 (int) '.',
665 rh->name_resolution_pos))) && 676 rh->name_resolution_pos))) &&
666 ('_' == dot[1]) && 677 ('_' == dot[1]) &&
667 (NULL == memrchr(rh->name, 678 (NULL == memrchr (rh->name,
668 (int)'.', 679 (int) '.',
669 dot - rh->name))) 680 dot - rh->name)))
681 {
682 srv_name = GNUNET_strndup (&rh->name[1],
683 (dot - rh->name) - 1);
684 proto_name = GNUNET_strndup (&dot[2],
685 rh->name_resolution_pos - (dot - rh->name)
686 - 1);
687 rh->name_resolution_pos = 0;
688 pe = getprotobyname (proto_name);
689 if (NULL == pe)
670 { 690 {
671 srv_name = GNUNET_strndup(&rh->name[1], 691 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
672 (dot - rh->name) - 1); 692 _ ("Protocol `%s' unknown, skipping labels.\n"),
673 proto_name = GNUNET_strndup(&dot[2], 693 proto_name);
674 rh->name_resolution_pos - (dot - rh->name) - 1); 694 GNUNET_free (proto_name);
675 rh->name_resolution_pos = 0; 695 GNUNET_free (srv_name);
676 pe = getprotobyname(proto_name); 696 return ret;
677 if (NULL == pe) 697 }
678 { 698 se = getservbyname (srv_name,
679 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 699 proto_name);
680 _("Protocol `%s' unknown, skipping labels.\n"), 700 if (NULL == se)
681 proto_name); 701 {
682 GNUNET_free(proto_name); 702 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
683 GNUNET_free(srv_name); 703 _ (
684 return ret; 704 "Service `%s' unknown for protocol `%s', skipping labels.\n"),
685 } 705 srv_name,
686 se = getservbyname(srv_name, 706 proto_name);
687 proto_name); 707 GNUNET_free (proto_name);
688 if (NULL == se) 708 GNUNET_free (srv_name);
689 { 709 return ret;
690 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
691 _("Service `%s' unknown for protocol `%s', skipping labels.\n"),
692 srv_name,
693 proto_name);
694 GNUNET_free(proto_name);
695 GNUNET_free(srv_name);
696 return ret;
697 }
698 rh->protocol = pe->p_proto;
699 rh->service = se->s_port;
700 GNUNET_free(proto_name);
701 GNUNET_free(srv_name);
702 } 710 }
711 rh->protocol = pe->p_proto;
712 rh->service = se->s_port;
713 GNUNET_free (proto_name);
714 GNUNET_free (srv_name);
715 }
703 return ret; 716 return ret;
704} 717}
705 718
@@ -710,7 +723,7 @@ resolver_lookup_get_next_label(struct GNS_ResolverHandle *rh)
710 * @param rh resolution process that has culminated in a result 723 * @param rh resolution process that has culminated in a result
711 */ 724 */
712static void 725static void
713transmit_lookup_dns_result(struct GNS_ResolverHandle *rh) 726transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
714{ 727{
715 struct DnsResult *pos; 728 struct DnsResult *pos;
716 unsigned int n; 729 unsigned int n;
@@ -724,31 +737,31 @@ transmit_lookup_dns_result(struct GNS_ResolverHandle *rh)
724 737
725 i = 0; 738 i = 0;
726 for (pos = rh->dns_result_head; NULL != pos; pos = pos->next) 739 for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
740 {
741 rd[i].data = pos->data;
742 rd[i].data_size = pos->data_size;
743 rd[i].record_type = pos->record_type;
744 if (0 == pos->expiration_time)
727 { 745 {
728 rd[i].data = pos->data; 746 rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
729 rd[i].data_size = pos->data_size; 747 rd[i].expiration_time = 0;
730 rd[i].record_type = pos->record_type;
731 if (0 == pos->expiration_time)
732 {
733 rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
734 rd[i].expiration_time = 0;
735 }
736 else
737 {
738 rd[i].flags = GNUNET_GNSRECORD_RF_NONE;
739 rd[i].expiration_time = pos->expiration_time;
740 }
741 i++;
742 } 748 }
743 GNUNET_assert(i == n); 749 else
744 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 750 {
745 "Transmitting standard DNS result with %u records\n", 751 rd[i].flags = GNUNET_GNSRECORD_RF_NONE;
746 n); 752 rd[i].expiration_time = pos->expiration_time;
747 rh->proc(rh->proc_cls, 753 }
748 n, 754 i++;
749 rd); 755 }
756 GNUNET_assert (i == n);
757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
758 "Transmitting standard DNS result with %u records\n",
759 n);
760 rh->proc (rh->proc_cls,
761 n,
762 rd);
750 } 763 }
751 GNS_resolver_lookup_cancel(rh); 764 GNS_resolver_lookup_cancel (rh);
752} 765}
753 766
754 767
@@ -762,25 +775,25 @@ transmit_lookup_dns_result(struct GNS_ResolverHandle *rh)
762 * @param data binary data to return in DNS record 775 * @param data binary data to return in DNS record
763 */ 776 */
764static void 777static void
765add_dns_result(struct GNS_ResolverHandle *rh, 778add_dns_result (struct GNS_ResolverHandle *rh,
766 uint64_t expiration_time, 779 uint64_t expiration_time,
767 uint32_t record_type, 780 uint32_t record_type,
768 size_t data_size, 781 size_t data_size,
769 const void *data) 782 const void *data)
770{ 783{
771 struct DnsResult *res; 784 struct DnsResult *res;
772 785
773 res = GNUNET_malloc(sizeof(struct DnsResult) + data_size); 786 res = GNUNET_malloc (sizeof(struct DnsResult) + data_size);
774 res->expiration_time = expiration_time; 787 res->expiration_time = expiration_time;
775 res->data_size = data_size; 788 res->data_size = data_size;
776 res->record_type = record_type; 789 res->record_type = record_type;
777 res->data = &res[1]; 790 res->data = &res[1];
778 GNUNET_memcpy(&res[1], 791 GNUNET_memcpy (&res[1],
779 data, 792 data,
780 data_size); 793 data_size);
781 GNUNET_CONTAINER_DLL_insert(rh->dns_result_head, 794 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
782 rh->dns_result_tail, 795 rh->dns_result_tail,
783 res); 796 res);
784} 797}
785 798
786 799
@@ -793,47 +806,47 @@ add_dns_result(struct GNS_ResolverHandle *rh,
793 * @param addrlen length of the address 806 * @param addrlen length of the address
794 */ 807 */
795static void 808static void
796handle_dns_result(void *cls, 809handle_dns_result (void *cls,
797 const struct sockaddr *addr, 810 const struct sockaddr *addr,
798 socklen_t addrlen) 811 socklen_t addrlen)
799{ 812{
800 struct GNS_ResolverHandle *rh = cls; 813 struct GNS_ResolverHandle *rh = cls;
801 const struct sockaddr_in *sa4; 814 const struct sockaddr_in *sa4;
802 const struct sockaddr_in6 *sa6; 815 const struct sockaddr_in6 *sa6;
803 816
804 if (NULL == addr) 817 if (NULL == addr)
805 { 818 {
806 rh->std_resolve = NULL; 819 rh->std_resolve = NULL;
807 transmit_lookup_dns_result(rh); 820 transmit_lookup_dns_result (rh);
808 return; 821 return;
809 } 822 }
810 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
811 "Received %u bytes of DNS IP data\n", 824 "Received %u bytes of DNS IP data\n",
812 addrlen); 825 addrlen);
813 switch (addr->sa_family) 826 switch (addr->sa_family)
814 { 827 {
815 case AF_INET: 828 case AF_INET:
816 sa4 = (const struct sockaddr_in *)addr; 829 sa4 = (const struct sockaddr_in *) addr;
817 add_dns_result(rh, 830 add_dns_result (rh,
818 0 /* expiration time is unknown */, 831 0 /* expiration time is unknown */,
819 GNUNET_DNSPARSER_TYPE_A, 832 GNUNET_DNSPARSER_TYPE_A,
820 sizeof(struct in_addr), 833 sizeof(struct in_addr),
821 &sa4->sin_addr); 834 &sa4->sin_addr);
822 break; 835 break;
823 836
824 case AF_INET6: 837 case AF_INET6:
825 sa6 = (const struct sockaddr_in6 *)addr; 838 sa6 = (const struct sockaddr_in6 *) addr;
826 add_dns_result(rh, 839 add_dns_result (rh,
827 0 /* expiration time is unknown */, 840 0 /* expiration time is unknown */,
828 GNUNET_DNSPARSER_TYPE_AAAA, 841 GNUNET_DNSPARSER_TYPE_AAAA,
829 sizeof(struct in6_addr), 842 sizeof(struct in6_addr),
830 &sa6->sin6_addr); 843 &sa6->sin6_addr);
831 break; 844 break;
832 845
833 default: 846 default:
834 GNUNET_break(0); 847 GNUNET_break (0);
835 break; 848 break;
836 } 849 }
837} 850}
838 851
839 852
@@ -844,7 +857,7 @@ handle_dns_result(void *cls,
844 * @param tc task context 857 * @param tc task context
845 */ 858 */
846static void 859static void
847recursive_resolution(void *cls); 860recursive_resolution (void *cls);
848 861
849 862
850/** 863/**
@@ -854,7 +867,7 @@ recursive_resolution(void *cls);
854 * @param cls closure with `struct GNS_ResolverHandle *rh` 867 * @param cls closure with `struct GNS_ResolverHandle *rh`
855 */ 868 */
856static void 869static void
857start_resolver_lookup(void *cls); 870start_resolver_lookup (void *cls);
858 871
859 872
860/** 873/**
@@ -866,9 +879,9 @@ start_resolver_lookup(void *cls);
866 * @param dns_len number of bytes in @a dns 879 * @param dns_len number of bytes in @a dns
867 */ 880 */
868static void 881static void
869dns_result_parser(void *cls, 882dns_result_parser (void *cls,
870 const struct GNUNET_TUN_DnsHeader *dns, 883 const struct GNUNET_TUN_DnsHeader *dns,
871 size_t dns_len) 884 size_t dns_len)
872{ 885{
873 struct GNS_ResolverHandle *rh = cls; 886 struct GNS_ResolverHandle *rh = cls;
874 struct GNUNET_DNSPARSER_Packet *p; 887 struct GNUNET_DNSPARSER_Packet *p;
@@ -876,85 +889,86 @@ dns_result_parser(void *cls,
876 unsigned int rd_count; 889 unsigned int rd_count;
877 890
878 if (NULL == dns) 891 if (NULL == dns)
879 { 892 {
880 rh->dns_request = NULL; 893 rh->dns_request = NULL;
881 GNUNET_SCHEDULER_cancel(rh->task_id); 894 GNUNET_SCHEDULER_cancel (rh->task_id);
882 rh->task_id = NULL; 895 rh->task_id = NULL;
883 fail_resolution(rh); 896 fail_resolution (rh);
884 return; 897 return;
885 } 898 }
886 if (rh->original_dns_id != dns->id) 899 if (rh->original_dns_id != dns->id)
887 { 900 {
888 /* DNS answer, but for another query */ 901 /* DNS answer, but for another query */
889 return; 902 return;
890 } 903 }
891 p = GNUNET_DNSPARSER_parse((const char *)dns, 904 p = GNUNET_DNSPARSER_parse ((const char *) dns,
892 dns_len); 905 dns_len);
893 if (NULL == p) 906 if (NULL == p)
894 { 907 {
895 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 908 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
896 _("Failed to parse DNS response\n")); 909 _ ("Failed to parse DNS response\n"));
897 return; 910 return;
898 } 911 }
899 912
900 /* We got a result from DNS */ 913 /* We got a result from DNS */
901 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
902 "Received DNS response for `%s' with %u answers\n", 915 "Received DNS response for `%s' with %u answers\n",
903 rh->ac_tail->label, 916 rh->ac_tail->label,
904 (unsigned int)p->num_answers); 917 (unsigned int) p->num_answers);
905 if ((p->num_answers > 0) && 918 if ((p->num_answers > 0) &&
906 (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && 919 (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) &&
907 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type)) 920 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type))
908 { 921 {
909 int af; 922 int af;
910 923
911 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 924 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
912 "Got CNAME `%s' from DNS for `%s'\n", 925 "Got CNAME `%s' from DNS for `%s'\n",
913 p->answers[0].data.hostname, 926 p->answers[0].data.hostname,
914 rh->name); 927 rh->name);
915 if (NULL != rh->std_resolve) 928 if (NULL != rh->std_resolve)
916 { 929 {
917 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 930 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
918 "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n", 931 "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n",
919 rh->name); 932 rh->name);
920 GNUNET_RESOLVER_request_cancel(rh->std_resolve); 933 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
921 } 934 }
922 GNUNET_free(rh->name); 935 GNUNET_free (rh->name);
923 rh->name = GNUNET_strdup(p->answers[0].data.hostname); 936 rh->name = GNUNET_strdup (p->answers[0].data.hostname);
924 rh->name_resolution_pos = strlen(rh->name); 937 rh->name_resolution_pos = strlen (rh->name);
925 switch (rh->record_type) 938 switch (rh->record_type)
926 { 939 {
927 case GNUNET_DNSPARSER_TYPE_A: 940 case GNUNET_DNSPARSER_TYPE_A:
928 af = AF_INET; 941 af = AF_INET;
929 break; 942 break;
930 943
931 case GNUNET_DNSPARSER_TYPE_AAAA: 944 case GNUNET_DNSPARSER_TYPE_AAAA:
932 af = AF_INET6; 945 af = AF_INET6;
933 break; 946 break;
934 947
935 default: 948 default:
936 af = AF_UNSPEC; 949 af = AF_UNSPEC;
937 break; 950 break;
938 }
939 if (NULL != rh->leho)
940 add_dns_result(rh,
941 GNUNET_TIME_UNIT_HOURS.rel_value_us,
942 GNUNET_GNSRECORD_TYPE_LEHO,
943 strlen(rh->leho),
944 rh->leho);
945 rh->std_resolve = GNUNET_RESOLVER_ip_get(rh->name,
946 af,
947 DNS_LOOKUP_TIMEOUT,
948 &handle_dns_result,
949 rh);
950 GNUNET_DNSPARSER_free_packet(p);
951 GNUNET_DNSSTUB_resolve_cancel(rh->dns_request);
952 rh->dns_request = NULL;
953 return;
954 } 951 }
952 if (NULL != rh->leho)
953 add_dns_result (rh,
954 GNUNET_TIME_UNIT_HOURS.rel_value_us,
955 GNUNET_GNSRECORD_TYPE_LEHO,
956 strlen (rh->leho),
957 rh->leho);
958 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name,
959 af,
960 DNS_LOOKUP_TIMEOUT,
961 &handle_dns_result,
962 rh);
963 GNUNET_DNSPARSER_free_packet (p);
964 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
965 rh->dns_request = NULL;
966 return;
967 }
955 968
956 /* convert from (parsed) DNS to (binary) GNS format! */ 969 /* convert from (parsed) DNS to (binary) GNS format! */
957 rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; 970 rd_count = p->num_answers + p->num_authority_records
971 + p->num_additional_records;
958 { 972 {
959 struct GNUNET_GNSRECORD_Data rd[rd_count + 1]; /* +1 for LEHO */ 973 struct GNUNET_GNSRECORD_Data rd[rd_count + 1]; /* +1 for LEHO */
960 int skip; 974 int skip;
@@ -964,157 +978,158 @@ dns_result_parser(void *cls,
964 978
965 buf_off = 0; 979 buf_off = 0;
966 skip = 0; 980 skip = 0;
967 memset(rd, 981 memset (rd,
968 0, 982 0,
969 sizeof(rd)); 983 sizeof(rd));
970 for (unsigned int i = 0; i < rd_count; i++) 984 for (unsigned int i = 0; i < rd_count; i++)
985 {
986 if (i < p->num_answers)
987 rec = &p->answers[i];
988 else if (i < p->num_answers + p->num_authority_records)
989 rec = &p->authority_records[i - p->num_answers];
990 else
991 rec = &p->additional_records[i - p->num_answers
992 - p->num_authority_records];
993 /* As we copied the full DNS name to 'rh->ac_tail->label', this
994 should be the correct check to see if this record is actually
995 a record for our label... */
996 if (0 != strcmp (rec->name,
997 rh->ac_tail->label))
971 { 998 {
972 if (i < p->num_answers) 999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
973 rec = &p->answers[i]; 1000 "Dropping record `%s', does not match desired name `%s'\n",
974 else if (i < p->num_answers + p->num_authority_records) 1001 rec->name,
975 rec = &p->authority_records[i - p->num_answers]; 1002 rh->ac_tail->label);
976 else 1003 skip++;
977 rec = &p->additional_records[i - p->num_answers - p->num_authority_records]; 1004 continue;
978 /* As we copied the full DNS name to 'rh->ac_tail->label', this 1005 }
979 should be the correct check to see if this record is actually 1006 rd[i - skip].record_type = rec->type;
980 a record for our label... */ 1007 rd[i - skip].expiration_time = rec->expiration_time.abs_value_us;
981 if (0 != strcmp(rec->name, 1008 switch (rec->type)
982 rh->ac_tail->label))
983 {
984 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
985 "Dropping record `%s', does not match desired name `%s'\n",
986 rec->name,
987 rh->ac_tail->label);
988 skip++;
989 continue;
990 }
991 rd[i - skip].record_type = rec->type;
992 rd[i - skip].expiration_time = rec->expiration_time.abs_value_us;
993 switch (rec->type)
994 {
995 case GNUNET_DNSPARSER_TYPE_A:
996 if (rec->data.raw.data_len != sizeof(struct in_addr))
997 {
998 GNUNET_break_op(0);
999 skip++;
1000 continue;
1001 }
1002 rd[i - skip].data_size = rec->data.raw.data_len;
1003 rd[i - skip].data = rec->data.raw.data;
1004 break;
1005
1006 case GNUNET_DNSPARSER_TYPE_AAAA:
1007 if (rec->data.raw.data_len != sizeof(struct in6_addr))
1008 {
1009 GNUNET_break_op(0);
1010 skip++;
1011 continue;
1012 }
1013 rd[i - skip].data_size = rec->data.raw.data_len;
1014 rd[i - skip].data = rec->data.raw.data;
1015 break;
1016
1017 case GNUNET_DNSPARSER_TYPE_CNAME:
1018 case GNUNET_DNSPARSER_TYPE_PTR:
1019 case GNUNET_DNSPARSER_TYPE_NS:
1020 buf_start = buf_off;
1021 if (GNUNET_OK !=
1022 GNUNET_DNSPARSER_builder_add_name(buf,
1023 sizeof(buf),
1024 &buf_off,
1025 rec->data.hostname))
1026 {
1027 GNUNET_break(0);
1028 skip++;
1029 continue;
1030 }
1031 rd[i - skip].data_size = buf_off - buf_start;
1032 rd[i - skip].data = &buf[buf_start];
1033 break;
1034
1035 case GNUNET_DNSPARSER_TYPE_SOA:
1036 buf_start = buf_off;
1037 if (GNUNET_OK !=
1038 GNUNET_DNSPARSER_builder_add_soa(buf,
1039 sizeof(buf),
1040 &buf_off,
1041 rec->data.soa))
1042 {
1043 GNUNET_break(0);
1044 skip++;
1045 continue;
1046 }
1047 rd[i - skip].data_size = buf_off - buf_start;
1048 rd[i - skip].data = &buf[buf_start];
1049 break;
1050
1051 case GNUNET_DNSPARSER_TYPE_MX:
1052 buf_start = buf_off;
1053 if (GNUNET_OK !=
1054 GNUNET_DNSPARSER_builder_add_mx(buf,
1055 sizeof(buf),
1056 &buf_off,
1057 rec->data.mx))
1058 {
1059 GNUNET_break(0);
1060 skip++;
1061 continue;
1062 }
1063 rd[i - skip].data_size = buf_off - buf_start;
1064 rd[i - skip].data = &buf[buf_start];
1065 break;
1066
1067 case GNUNET_DNSPARSER_TYPE_SRV:
1068 buf_start = buf_off;
1069 if (GNUNET_OK !=
1070 GNUNET_DNSPARSER_builder_add_srv(buf,
1071 sizeof(buf),
1072 &buf_off,
1073 rec->data.srv))
1074 {
1075 GNUNET_break(0);
1076 skip++;
1077 continue;
1078 }
1079 rd[i - skip].data_size = buf_off - buf_start;
1080 rd[i - skip].data = &buf[buf_start];
1081 break;
1082
1083 default:
1084 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1085 _("Skipping record of unsupported type %d\n"),
1086 rec->type);
1087 skip++;
1088 continue;
1089 }
1090 } /* end of for all records in answer */
1091 if (NULL != rh->leho)
1092 { 1009 {
1093 rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO; 1010 case GNUNET_DNSPARSER_TYPE_A:
1094 rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1011 if (rec->data.raw.data_len != sizeof(struct in_addr))
1095 rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; 1012 {
1096 rd[rd_count - skip].data = rh->leho; 1013 GNUNET_break_op (0);
1097 rd[rd_count - skip].data_size = strlen(rh->leho); 1014 skip++;
1098 skip--; /* skip one LESS */ 1015 continue;
1099 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1016 }
1100 "Adding LEHO %s\n", 1017 rd[i - skip].data_size = rec->data.raw.data_len;
1101 rh->leho); 1018 rd[i - skip].data = rec->data.raw.data;
1019 break;
1020
1021 case GNUNET_DNSPARSER_TYPE_AAAA:
1022 if (rec->data.raw.data_len != sizeof(struct in6_addr))
1023 {
1024 GNUNET_break_op (0);
1025 skip++;
1026 continue;
1027 }
1028 rd[i - skip].data_size = rec->data.raw.data_len;
1029 rd[i - skip].data = rec->data.raw.data;
1030 break;
1031
1032 case GNUNET_DNSPARSER_TYPE_CNAME:
1033 case GNUNET_DNSPARSER_TYPE_PTR:
1034 case GNUNET_DNSPARSER_TYPE_NS:
1035 buf_start = buf_off;
1036 if (GNUNET_OK !=
1037 GNUNET_DNSPARSER_builder_add_name (buf,
1038 sizeof(buf),
1039 &buf_off,
1040 rec->data.hostname))
1041 {
1042 GNUNET_break (0);
1043 skip++;
1044 continue;
1045 }
1046 rd[i - skip].data_size = buf_off - buf_start;
1047 rd[i - skip].data = &buf[buf_start];
1048 break;
1049
1050 case GNUNET_DNSPARSER_TYPE_SOA:
1051 buf_start = buf_off;
1052 if (GNUNET_OK !=
1053 GNUNET_DNSPARSER_builder_add_soa (buf,
1054 sizeof(buf),
1055 &buf_off,
1056 rec->data.soa))
1057 {
1058 GNUNET_break (0);
1059 skip++;
1060 continue;
1061 }
1062 rd[i - skip].data_size = buf_off - buf_start;
1063 rd[i - skip].data = &buf[buf_start];
1064 break;
1065
1066 case GNUNET_DNSPARSER_TYPE_MX:
1067 buf_start = buf_off;
1068 if (GNUNET_OK !=
1069 GNUNET_DNSPARSER_builder_add_mx (buf,
1070 sizeof(buf),
1071 &buf_off,
1072 rec->data.mx))
1073 {
1074 GNUNET_break (0);
1075 skip++;
1076 continue;
1077 }
1078 rd[i - skip].data_size = buf_off - buf_start;
1079 rd[i - skip].data = &buf[buf_start];
1080 break;
1081
1082 case GNUNET_DNSPARSER_TYPE_SRV:
1083 buf_start = buf_off;
1084 if (GNUNET_OK !=
1085 GNUNET_DNSPARSER_builder_add_srv (buf,
1086 sizeof(buf),
1087 &buf_off,
1088 rec->data.srv))
1089 {
1090 GNUNET_break (0);
1091 skip++;
1092 continue;
1093 }
1094 rd[i - skip].data_size = buf_off - buf_start;
1095 rd[i - skip].data = &buf[buf_start];
1096 break;
1097
1098 default:
1099 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1100 _ ("Skipping record of unsupported type %d\n"),
1101 rec->type);
1102 skip++;
1103 continue;
1102 } 1104 }
1103 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1105 } /* end of for all records in answer */
1104 "Returning DNS response for `%s' with %u answers\n", 1106 if (NULL != rh->leho)
1105 rh->ac_tail->label, 1107 {
1106 (unsigned int)(rd_count - skip)); 1108 rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO;
1107 rh->proc(rh->proc_cls, 1109 rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1108 rd_count - skip, 1110 rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us;
1109 rd); 1111 rd[rd_count - skip].data = rh->leho;
1110 GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); 1112 rd[rd_count - skip].data_size = strlen (rh->leho);
1113 skip--; /* skip one LESS */
1114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1115 "Adding LEHO %s\n",
1116 rh->leho);
1117 }
1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1119 "Returning DNS response for `%s' with %u answers\n",
1120 rh->ac_tail->label,
1121 (unsigned int) (rd_count - skip));
1122 rh->proc (rh->proc_cls,
1123 rd_count - skip,
1124 rd);
1125 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
1111 rh->dns_request = NULL; 1126 rh->dns_request = NULL;
1112 } 1127 }
1113 GNUNET_DNSPARSER_free_packet(p); 1128 GNUNET_DNSPARSER_free_packet (p);
1114 if (NULL != rh->task_id) 1129 if (NULL != rh->task_id)
1115 GNUNET_SCHEDULER_cancel(rh->task_id); /* should be timeout task */ 1130 GNUNET_SCHEDULER_cancel (rh->task_id); /* should be timeout task */
1116 rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, 1131 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
1117 rh); 1132 rh);
1118} 1133}
1119 1134
1120 1135
@@ -1127,7 +1142,7 @@ dns_result_parser(void *cls,
1127 * @param rh resolution information 1142 * @param rh resolution information
1128 */ 1143 */
1129static void 1144static void
1130recursive_dns_resolution(struct GNS_ResolverHandle *rh) 1145recursive_dns_resolution (struct GNS_ResolverHandle *rh)
1131{ 1146{
1132 struct AuthorityChain *ac; 1147 struct AuthorityChain *ac;
1133 struct GNUNET_DNSPARSER_Query *query; 1148 struct GNUNET_DNSPARSER_Query *query;
@@ -1137,54 +1152,55 @@ recursive_dns_resolution(struct GNS_ResolverHandle *rh)
1137 int ret; 1152 int ret;
1138 1153
1139 ac = rh->ac_tail; 1154 ac = rh->ac_tail;
1140 GNUNET_assert(NULL != ac); 1155 GNUNET_assert (NULL != ac);
1141 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1142 "Starting DNS lookup for `%s'\n", 1157 "Starting DNS lookup for `%s'\n",
1143 ac->label); 1158 ac->label);
1144 GNUNET_assert(GNUNET_NO == ac->gns_authority); 1159 GNUNET_assert (GNUNET_NO == ac->gns_authority);
1145 query = GNUNET_new(struct GNUNET_DNSPARSER_Query); 1160 query = GNUNET_new (struct GNUNET_DNSPARSER_Query);
1146 query->name = GNUNET_strdup(ac->label); 1161 query->name = GNUNET_strdup (ac->label);
1147 query->type = rh->record_type; 1162 query->type = rh->record_type;
1148 query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 1163 query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
1149 p = GNUNET_new(struct GNUNET_DNSPARSER_Packet); 1164 p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
1150 p->queries = query; 1165 p->queries = query;
1151 p->num_queries = 1; 1166 p->num_queries = 1;
1152 p->id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 1167 p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1153 UINT16_MAX); 1168 UINT16_MAX);
1154 p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY; 1169 p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY;
1155 p->flags.recursion_desired = 1; 1170 p->flags.recursion_desired = 1;
1156 ret = GNUNET_DNSPARSER_pack(p, 1171 ret = GNUNET_DNSPARSER_pack (p,
1157 1024, 1172 1024,
1158 &dns_request, 1173 &dns_request,
1159 &dns_request_length); 1174 &dns_request_length);
1160 if (GNUNET_OK != ret) 1175 if (GNUNET_OK != ret)
1161 { 1176 {
1162 GNUNET_break(0); 1177 GNUNET_break (0);
1163 rh->proc(rh->proc_cls, 1178 rh->proc (rh->proc_cls,
1164 0, 1179 0,
1165 NULL); 1180 NULL);
1166 GNUNET_assert(NULL == rh->task_id); 1181 GNUNET_assert (NULL == rh->task_id);
1167 rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, 1182 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
1168 rh); 1183 rh);
1169 } 1184 }
1170 else 1185 else
1171 { 1186 {
1172 rh->original_dns_id = p->id; 1187 rh->original_dns_id = p->id;
1173 GNUNET_assert(NULL != ac->authority_info.dns_authority.dns_handle); 1188 GNUNET_assert (NULL != ac->authority_info.dns_authority.dns_handle);
1174 GNUNET_assert(NULL == rh->dns_request); 1189 GNUNET_assert (NULL == rh->dns_request);
1175 rh->leho = GNUNET_strdup(ac->label); 1190 rh->leho = GNUNET_strdup (ac->label);
1176 rh->dns_request = GNUNET_DNSSTUB_resolve(ac->authority_info.dns_authority.dns_handle, 1191 rh->dns_request = GNUNET_DNSSTUB_resolve (
1177 dns_request, 1192 ac->authority_info.dns_authority.dns_handle,
1178 dns_request_length, 1193 dns_request,
1179 &dns_result_parser, 1194 dns_request_length,
1180 rh); 1195 &dns_result_parser,
1181 rh->task_id = GNUNET_SCHEDULER_add_delayed(DNS_LOOKUP_TIMEOUT, 1196 rh);
1182 &timeout_resolution, 1197 rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT,
1183 rh); 1198 &timeout_resolution,
1184 } 1199 rh);
1200 }
1185 if (GNUNET_SYSERR != ret) 1201 if (GNUNET_SYSERR != ret)
1186 GNUNET_free(dns_request); 1202 GNUNET_free (dns_request);
1187 GNUNET_DNSPARSER_free_packet(p); 1203 GNUNET_DNSPARSER_free_packet (p);
1188} 1204}
1189 1205
1190 1206
@@ -1197,87 +1213,88 @@ recursive_dns_resolution(struct GNS_ResolverHandle *rh)
1197 * authority chain tail 1213 * authority chain tail
1198 */ 1214 */
1199static void 1215static void
1200handle_gns_cname_result(struct GNS_ResolverHandle *rh, 1216handle_gns_cname_result (struct GNS_ResolverHandle *rh,
1201 const char *cname) 1217 const char *cname)
1202{ 1218{
1203 size_t nlen; 1219 size_t nlen;
1204 char *res; 1220 char *res;
1205 struct AuthorityChain *ac; 1221 struct AuthorityChain *ac;
1206 int af; 1222 int af;
1207 1223
1208 nlen = strlen(cname); 1224 nlen = strlen (cname);
1209 if ((nlen > 2) && 1225 if ((nlen > 2) &&
1210 (0 == strcmp(".+", 1226 (0 == strcmp (".+",
1211 &cname[nlen - 2]))) 1227 &cname[nlen - 2])))
1228 {
1229 /* CNAME resolution continues relative to current domain */
1230 if (0 == rh->name_resolution_pos)
1212 { 1231 {
1213 /* CNAME resolution continues relative to current domain */ 1232 res = GNUNET_strndup (cname, nlen - 2);
1214 if (0 == rh->name_resolution_pos) 1233 rh->name_resolution_pos = nlen - 2;
1215 {
1216 res = GNUNET_strndup(cname, nlen - 2);
1217 rh->name_resolution_pos = nlen - 2;
1218 }
1219 else
1220 {
1221 GNUNET_asprintf(&res,
1222 "%.*s.%.*s",
1223 (int)rh->name_resolution_pos,
1224 rh->name,
1225 (int)(nlen - 2),
1226 cname);
1227 rh->name_resolution_pos = strlen(res);
1228 }
1229 GNUNET_free(rh->name);
1230 rh->name = res;
1231 ac = GNUNET_new(struct AuthorityChain);
1232 ac->rh = rh;
1233 ac->gns_authority = GNUNET_YES;
1234 ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority;
1235 ac->label = resolver_lookup_get_next_label(rh);
1236 /* add AC to tail */
1237 GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head,
1238 rh->ac_tail,
1239 ac);
1240 rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution,
1241 rh);
1242 return;
1243 } 1234 }
1244 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1235 else
1245 "Got CNAME `%s' from GNS for `%s'\n",
1246 cname,
1247 rh->name);
1248 if (NULL != rh->std_resolve)
1249 { 1236 {
1250 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1237 GNUNET_asprintf (&res,
1251 "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n", 1238 "%.*s.%.*s",
1252 rh->name); 1239 (int) rh->name_resolution_pos,
1253 GNUNET_RESOLVER_request_cancel(rh->std_resolve); 1240 rh->name,
1241 (int) (nlen - 2),
1242 cname);
1243 rh->name_resolution_pos = strlen (res);
1254 } 1244 }
1245 GNUNET_free (rh->name);
1246 rh->name = res;
1247 ac = GNUNET_new (struct AuthorityChain);
1248 ac->rh = rh;
1249 ac->gns_authority = GNUNET_YES;
1250 ac->authority_info.gns_authority =
1251 rh->ac_tail->authority_info.gns_authority;
1252 ac->label = resolver_lookup_get_next_label (rh);
1253 /* add AC to tail */
1254 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1255 rh->ac_tail,
1256 ac);
1257 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1258 rh);
1259 return;
1260 }
1261 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1262 "Got CNAME `%s' from GNS for `%s'\n",
1263 cname,
1264 rh->name);
1265 if (NULL != rh->std_resolve)
1266 {
1267 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1268 "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n",
1269 rh->name);
1270 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
1271 }
1255 /* name is absolute, go to DNS */ 1272 /* name is absolute, go to DNS */
1256 GNUNET_free(rh->name); 1273 GNUNET_free (rh->name);
1257 rh->name = GNUNET_strdup(cname); 1274 rh->name = GNUNET_strdup (cname);
1258 rh->name_resolution_pos = strlen(rh->name); 1275 rh->name_resolution_pos = strlen (rh->name);
1259 switch (rh->record_type) 1276 switch (rh->record_type)
1260 { 1277 {
1261 case GNUNET_DNSPARSER_TYPE_A: 1278 case GNUNET_DNSPARSER_TYPE_A:
1262 af = AF_INET; 1279 af = AF_INET;
1263 break; 1280 break;
1264 1281
1265 case GNUNET_DNSPARSER_TYPE_AAAA: 1282 case GNUNET_DNSPARSER_TYPE_AAAA:
1266 af = AF_INET6; 1283 af = AF_INET6;
1267 break; 1284 break;
1268 1285
1269 default: 1286 default:
1270 af = AF_UNSPEC; 1287 af = AF_UNSPEC;
1271 break; 1288 break;
1272 } 1289 }
1273 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Doing standard DNS lookup for `%s'\n", 1291 "Doing standard DNS lookup for `%s'\n",
1275 rh->name); 1292 rh->name);
1276 rh->std_resolve = GNUNET_RESOLVER_ip_get(rh->name, 1293 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name,
1277 af, 1294 af,
1278 DNS_LOOKUP_TIMEOUT, 1295 DNS_LOOKUP_TIMEOUT,
1279 &handle_dns_result, 1296 &handle_dns_result,
1280 rh); 1297 rh);
1281} 1298}
1282 1299
1283 1300
@@ -1289,9 +1306,9 @@ handle_gns_cname_result(struct GNS_ResolverHandle *rh,
1289 * @param rd array of records with data to store 1306 * @param rd array of records with data to store
1290 */ 1307 */
1291static void 1308static void
1292handle_gns_resolution_result(void *cls, 1309handle_gns_resolution_result (void *cls,
1293 unsigned int rd_count, 1310 unsigned int rd_count,
1294 const struct GNUNET_GNSRECORD_Data *rd); 1311 const struct GNUNET_GNSRECORD_Data *rd);
1295 1312
1296 1313
1297/** 1314/**
@@ -1309,9 +1326,9 @@ handle_gns_resolution_result(void *cls,
1309 * specified target peer; NULL on error 1326 * specified target peer; NULL on error
1310 */ 1327 */
1311static void 1328static void
1312vpn_allocation_cb(void *cls, 1329vpn_allocation_cb (void *cls,
1313 int af, 1330 int af,
1314 const void *address) 1331 const void *address)
1315{ 1332{
1316 struct VpnContext *vpn_ctx = cls; 1333 struct VpnContext *vpn_ctx = cls;
1317 struct GNS_ResolverHandle *rh = vpn_ctx->rh; 1334 struct GNS_ResolverHandle *rh = vpn_ctx->rh;
@@ -1320,49 +1337,52 @@ vpn_allocation_cb(void *cls,
1320 1337
1321 vpn_ctx->vpn_request = NULL; 1338 vpn_ctx->vpn_request = NULL;
1322 rh->vpn_ctx = NULL; 1339 rh->vpn_ctx = NULL;
1323 GNUNET_assert(GNUNET_OK == 1340 GNUNET_assert (GNUNET_OK ==
1324 GNUNET_GNSRECORD_records_deserialize((size_t)vpn_ctx->rd_data_size, 1341 GNUNET_GNSRECORD_records_deserialize (
1325 vpn_ctx->rd_data, 1342 (size_t) vpn_ctx->rd_data_size,
1326 vpn_ctx->rd_count, 1343 vpn_ctx->rd_data,
1327 rd)); 1344 vpn_ctx->rd_count,
1345 rd));
1328 for (i = 0; i < vpn_ctx->rd_count; i++) 1346 for (i = 0; i < vpn_ctx->rd_count; i++)
1347 {
1348 if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type)
1329 { 1349 {
1330 if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) 1350 switch (af)
1331 { 1351 {
1332 switch (af) 1352 case AF_INET:
1333 { 1353 rd[i].record_type = GNUNET_DNSPARSER_TYPE_A;
1334 case AF_INET: 1354 rd[i].data_size = sizeof(struct in_addr);
1335 rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; 1355 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (
1336 rd[i].data_size = sizeof(struct in_addr); 1356 VPN_TIMEOUT).abs_value_us;
1337 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT).abs_value_us; 1357 rd[i].flags = 0;
1338 rd[i].flags = 0; 1358 rd[i].data = address;
1339 rd[i].data = address; 1359 break;
1340 break; 1360
1341 1361 case AF_INET6:
1342 case AF_INET6: 1362 rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA;
1343 rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; 1363 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (
1344 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT).abs_value_us; 1364 VPN_TIMEOUT).abs_value_us;
1345 rd[i].flags = 0; 1365 rd[i].flags = 0;
1346 rd[i].data = address; 1366 rd[i].data = address;
1347 rd[i].data_size = sizeof(struct in6_addr); 1367 rd[i].data_size = sizeof(struct in6_addr);
1348 break; 1368 break;
1349 1369
1350 default: 1370 default:
1351 GNUNET_assert(0); 1371 GNUNET_assert (0);
1352 } 1372 }
1353 break; 1373 break;
1354 }
1355 } 1374 }
1356 GNUNET_assert(i < vpn_ctx->rd_count); 1375 }
1376 GNUNET_assert (i < vpn_ctx->rd_count);
1357 if (0 == vpn_ctx->rd_count) 1377 if (0 == vpn_ctx->rd_count)
1358 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1378 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1359 _("VPN returned empty result for `%s'\n"), 1379 _ ("VPN returned empty result for `%s'\n"),
1360 rh->name); 1380 rh->name);
1361 handle_gns_resolution_result(rh, 1381 handle_gns_resolution_result (rh,
1362 vpn_ctx->rd_count, 1382 vpn_ctx->rd_count,
1363 rd); 1383 rd);
1364 GNUNET_free(vpn_ctx->rd_data); 1384 GNUNET_free (vpn_ctx->rd_data);
1365 GNUNET_free(vpn_ctx); 1385 GNUNET_free (vpn_ctx);
1366} 1386}
1367 1387
1368 1388
@@ -1374,7 +1394,7 @@ vpn_allocation_cb(void *cls,
1374 * @param ac context for GNS2DNS resolution 1394 * @param ac context for GNS2DNS resolution
1375 */ 1395 */
1376static void 1396static void
1377continue_with_gns2dns(struct AuthorityChain *ac) 1397continue_with_gns2dns (struct AuthorityChain *ac)
1378{ 1398{
1379 struct GNS_ResolverHandle *rh = ac->rh; 1399 struct GNS_ResolverHandle *rh = ac->rh;
1380 1400
@@ -1382,23 +1402,23 @@ continue_with_gns2dns(struct AuthorityChain *ac)
1382 (GNUNET_NO == ac->authority_info.dns_authority.found)) 1402 (GNUNET_NO == ac->authority_info.dns_authority.found))
1383 return; /* more pending and none found yet */ 1403 return; /* more pending and none found yet */
1384 if (GNUNET_NO == ac->authority_info.dns_authority.found) 1404 if (GNUNET_NO == ac->authority_info.dns_authority.found)
1385 { 1405 {
1386 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1406 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1387 "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n", 1407 "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n",
1388 ac->authority_info.dns_authority.name); 1408 ac->authority_info.dns_authority.name);
1389 fail_resolution(rh); 1409 fail_resolution (rh);
1390 return; 1410 return;
1391 } 1411 }
1392 if (GNUNET_NO != ac->authority_info.dns_authority.launched) 1412 if (GNUNET_NO != ac->authority_info.dns_authority.launched)
1393 return; /* already running, do not launch again! */ 1413 return; /* already running, do not launch again! */
1394 /* recurse */ 1414 /* recurse */
1395 ac->authority_info.dns_authority.launched = GNUNET_YES; 1415 ac->authority_info.dns_authority.launched = GNUNET_YES;
1396 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1397 "Will continue resolution using DNS to resolve `%s'\n", 1417 "Will continue resolution using DNS to resolve `%s'\n",
1398 ac->label); 1418 ac->label);
1399 GNUNET_assert(NULL == rh->task_id); 1419 GNUNET_assert (NULL == rh->task_id);
1400 rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, 1420 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1401 rh); 1421 rh);
1402} 1422}
1403 1423
1404 1424
@@ -1411,95 +1431,97 @@ continue_with_gns2dns(struct AuthorityChain *ac)
1411 * @param rd addresses for the DNS resolver (presumably) 1431 * @param rd addresses for the DNS resolver (presumably)
1412 */ 1432 */
1413static void 1433static void
1414handle_gns2dns_result(void *cls, 1434handle_gns2dns_result (void *cls,
1415 unsigned int rd_count, 1435 unsigned int rd_count,
1416 const struct GNUNET_GNSRECORD_Data *rd) 1436 const struct GNUNET_GNSRECORD_Data *rd)
1417{ 1437{
1418 struct Gns2DnsPending *gp = cls; 1438 struct Gns2DnsPending *gp = cls;
1419 struct AuthorityChain *ac = gp->ac; 1439 struct AuthorityChain *ac = gp->ac;
1420 1440
1421 GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, 1441 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1422 ac->authority_info.dns_authority.gp_tail, 1442 ac->authority_info.dns_authority.gp_tail,
1423 gp); 1443 gp);
1424 /* enable cleanup of 'rh' handle that automatically comes after we return, 1444 /* enable cleanup of 'rh' handle that automatically comes after we return,
1425 and which expects 'rh' to be in the #rlh_head DLL. */ 1445 and which expects 'rh' to be in the #rlh_head DLL. */
1426 if (NULL != gp->rh) 1446 if (NULL != gp->rh)
1427 { 1447 {
1428 GNUNET_CONTAINER_DLL_insert(rlh_head, 1448 GNUNET_CONTAINER_DLL_insert (rlh_head,
1429 rlh_tail, 1449 rlh_tail,
1430 gp->rh); 1450 gp->rh);
1431 gp->rh = NULL; 1451 gp->rh = NULL;
1432 } 1452 }
1433 GNUNET_free(gp); 1453 GNUNET_free (gp);
1434 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1435 "Received %u results for IP address of DNS server for GNS2DNS transition\n", 1455 "Received %u results for IP address of DNS server for GNS2DNS transition\n",
1436 rd_count); 1456 rd_count);
1437 /* find suitable A/AAAA record */ 1457 /* find suitable A/AAAA record */
1438 for (unsigned int j = 0; j < rd_count; j++) 1458 for (unsigned int j = 0; j < rd_count; j++)
1459 {
1460 switch (rd[j].record_type)
1439 { 1461 {
1440 switch (rd[j].record_type) 1462 case GNUNET_DNSPARSER_TYPE_A:
1441 { 1463 {
1442 case GNUNET_DNSPARSER_TYPE_A: 1464 struct sockaddr_in v4;
1443 {
1444 struct sockaddr_in v4;
1445 1465
1446 if (sizeof(struct in_addr) != rd[j].data_size) 1466 if (sizeof(struct in_addr) != rd[j].data_size)
1447 { 1467 {
1448 GNUNET_break_op(0); 1468 GNUNET_break_op (0);
1449 continue; 1469 continue;
1450 } 1470 }
1451 memset(&v4, 1471 memset (&v4,
1452 0, 1472 0,
1453 sizeof(v4)); 1473 sizeof(v4));
1454 v4.sin_family = AF_INET; 1474 v4.sin_family = AF_INET;
1455 v4.sin_port = htons(53); 1475 v4.sin_port = htons (53);
1456#if HAVE_SOCKADDR_IN_SIN_LEN 1476#if HAVE_SOCKADDR_IN_SIN_LEN
1457 v4.sin_len = (u_char)sizeof(v4); 1477 v4.sin_len = (u_char) sizeof(v4);
1458#endif 1478#endif
1459 GNUNET_memcpy(&v4.sin_addr, 1479 GNUNET_memcpy (&v4.sin_addr,
1460 rd[j].data, 1480 rd[j].data,
1461 sizeof(struct in_addr)); 1481 sizeof(struct in_addr));
1462 if (GNUNET_OK == 1482 if (GNUNET_OK ==
1463 GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, 1483 GNUNET_DNSSTUB_add_dns_sa (
1464 (const struct sockaddr *)&v4)) 1484 ac->authority_info.dns_authority.dns_handle,
1465 ac->authority_info.dns_authority.found = GNUNET_YES; 1485 (const struct sockaddr *) &v4))
1466 break; 1486 ac->authority_info.dns_authority.found = GNUNET_YES;
1467 } 1487 break;
1488 }
1468 1489
1469 case GNUNET_DNSPARSER_TYPE_AAAA: 1490 case GNUNET_DNSPARSER_TYPE_AAAA:
1470 { 1491 {
1471 struct sockaddr_in6 v6; 1492 struct sockaddr_in6 v6;
1472 1493
1473 if (sizeof(struct in6_addr) != rd[j].data_size) 1494 if (sizeof(struct in6_addr) != rd[j].data_size)
1474 { 1495 {
1475 GNUNET_break_op(0); 1496 GNUNET_break_op (0);
1476 continue; 1497 continue;
1477 } 1498 }
1478 /* FIXME: might want to check if we support IPv6 here, 1499 /* FIXME: might want to check if we support IPv6 here,
1479 and otherwise skip this one and hope we find another */ 1500 and otherwise skip this one and hope we find another */
1480 memset(&v6, 1501 memset (&v6,
1481 0, 1502 0,
1482 sizeof(v6)); 1503 sizeof(v6));
1483 v6.sin6_family = AF_INET6; 1504 v6.sin6_family = AF_INET6;
1484 v6.sin6_port = htons(53); 1505 v6.sin6_port = htons (53);
1485#if HAVE_SOCKADDR_IN_SIN_LEN 1506#if HAVE_SOCKADDR_IN_SIN_LEN
1486 v6.sin6_len = (u_char)sizeof(v6); 1507 v6.sin6_len = (u_char) sizeof(v6);
1487#endif 1508#endif
1488 GNUNET_memcpy(&v6.sin6_addr, 1509 GNUNET_memcpy (&v6.sin6_addr,
1489 rd[j].data, 1510 rd[j].data,
1490 sizeof(struct in6_addr)); 1511 sizeof(struct in6_addr));
1491 if (GNUNET_OK == 1512 if (GNUNET_OK ==
1492 GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, 1513 GNUNET_DNSSTUB_add_dns_sa (
1493 (const struct sockaddr *)&v6)) 1514 ac->authority_info.dns_authority.dns_handle,
1494 ac->authority_info.dns_authority.found = GNUNET_YES; 1515 (const struct sockaddr *) &v6))
1495 break; 1516 ac->authority_info.dns_authority.found = GNUNET_YES;
1496 } 1517 break;
1518 }
1497 1519
1498 default: 1520 default:
1499 break; 1521 break;
1500 }
1501 } 1522 }
1502 continue_with_gns2dns(ac); 1523 }
1524 continue_with_gns2dns (ac);
1503} 1525}
1504 1526
1505 1527
@@ -1511,9 +1533,9 @@ handle_gns2dns_result(void *cls,
1511 * @param addrlen length of @a addr 1533 * @param addrlen length of @a addr
1512 */ 1534 */
1513static void 1535static void
1514handle_gns2dns_ip(void *cls, 1536handle_gns2dns_ip (void *cls,
1515 const struct sockaddr *addr, 1537 const struct sockaddr *addr,
1516 socklen_t addrlen) 1538 socklen_t addrlen)
1517{ 1539{
1518 struct Gns2DnsPending *gp = cls; 1540 struct Gns2DnsPending *gp = cls;
1519 struct AuthorityChain *ac = gp->ac; 1541 struct AuthorityChain *ac = gp->ac;
@@ -1522,44 +1544,44 @@ handle_gns2dns_ip(void *cls,
1522 struct sockaddr_in6 *v6; 1544 struct sockaddr_in6 *v6;
1523 1545
1524 if (NULL == addr) 1546 if (NULL == addr)
1525 { 1547 {
1526 /* DNS resolution finished */ 1548 /* DNS resolution finished */
1527 if (0 == gp->num_results) 1549 if (0 == gp->num_results)
1528 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1550 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1529 "Failed to use DNS to resolve name of DNS resolver\n"); 1551 "Failed to use DNS to resolve name of DNS resolver\n");
1530 GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, 1552 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1531 ac->authority_info.dns_authority.gp_tail, 1553 ac->authority_info.dns_authority.gp_tail,
1532 gp); 1554 gp);
1533 GNUNET_free(gp); 1555 GNUNET_free (gp);
1534 continue_with_gns2dns(ac); 1556 continue_with_gns2dns (ac);
1535 return; 1557 return;
1536 } 1558 }
1537 GNUNET_memcpy(&ss, 1559 GNUNET_memcpy (&ss,
1538 addr, 1560 addr,
1539 addrlen); 1561 addrlen);
1540 switch (ss.ss_family) 1562 switch (ss.ss_family)
1541 { 1563 {
1542 case AF_INET: 1564 case AF_INET:
1543 v4 = (struct sockaddr_in *)&ss; 1565 v4 = (struct sockaddr_in *) &ss;
1544 v4->sin_port = htons(53); 1566 v4->sin_port = htons (53);
1545 gp->num_results++; 1567 gp->num_results++;
1546 break; 1568 break;
1547 1569
1548 case AF_INET6: 1570 case AF_INET6:
1549 v6 = (struct sockaddr_in6 *)&ss; 1571 v6 = (struct sockaddr_in6 *) &ss;
1550 v6->sin6_port = htons(53); 1572 v6->sin6_port = htons (53);
1551 gp->num_results++; 1573 gp->num_results++;
1552 break; 1574 break;
1553 1575
1554 default: 1576 default:
1555 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1577 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1556 "Unsupported AF %d\n", 1578 "Unsupported AF %d\n",
1557 ss.ss_family); 1579 ss.ss_family);
1558 return; 1580 return;
1559 } 1581 }
1560 if (GNUNET_OK == 1582 if (GNUNET_OK ==
1561 GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, 1583 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
1562 (struct sockaddr *)&ss)) 1584 (struct sockaddr *) &ss))
1563 ac->authority_info.dns_authority.found = GNUNET_YES; 1585 ac->authority_info.dns_authority.found = GNUNET_YES;
1564} 1586}
1565 1587
@@ -1571,27 +1593,27 @@ handle_gns2dns_ip(void *cls,
1571 * @param rd record with CNAME to resolve recursively 1593 * @param rd record with CNAME to resolve recursively
1572 */ 1594 */
1573static void 1595static void
1574recursive_cname_resolution(struct GNS_ResolverHandle *rh, 1596recursive_cname_resolution (struct GNS_ResolverHandle *rh,
1575 const struct GNUNET_GNSRECORD_Data *rd) 1597 const struct GNUNET_GNSRECORD_Data *rd)
1576{ 1598{
1577 char *cname; 1599 char *cname;
1578 size_t off; 1600 size_t off;
1579 1601
1580 off = 0; 1602 off = 0;
1581 cname = GNUNET_DNSPARSER_parse_name(rd->data, 1603 cname = GNUNET_DNSPARSER_parse_name (rd->data,
1582 rd->data_size, 1604 rd->data_size,
1583 &off); 1605 &off);
1584 if ((NULL == cname) || 1606 if ((NULL == cname) ||
1585 (off != rd->data_size)) 1607 (off != rd->data_size))
1586 { 1608 {
1587 GNUNET_break_op(0); /* record not well-formed */ 1609 GNUNET_break_op (0); /* record not well-formed */
1588 GNUNET_free_non_null(cname); 1610 GNUNET_free_non_null (cname);
1589 fail_resolution(rh); 1611 fail_resolution (rh);
1590 return; 1612 return;
1591 } 1613 }
1592 handle_gns_cname_result(rh, 1614 handle_gns_cname_result (rh,
1593 cname); 1615 cname);
1594 GNUNET_free(cname); 1616 GNUNET_free (cname);
1595} 1617}
1596 1618
1597 1619
@@ -1602,34 +1624,34 @@ recursive_cname_resolution(struct GNS_ResolverHandle *rh,
1602 * @param rd record with PKEY to resolve recursively 1624 * @param rd record with PKEY to resolve recursively
1603 */ 1625 */
1604static void 1626static void
1605recursive_pkey_resolution(struct GNS_ResolverHandle *rh, 1627recursive_pkey_resolution (struct GNS_ResolverHandle *rh,
1606 const struct GNUNET_GNSRECORD_Data *rd) 1628 const struct GNUNET_GNSRECORD_Data *rd)
1607{ 1629{
1608 struct AuthorityChain *ac; 1630 struct AuthorityChain *ac;
1609 1631
1610 /* delegation to another zone */ 1632 /* delegation to another zone */
1611 if (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != 1633 if (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) !=
1612 rd->data_size) 1634 rd->data_size)
1613 { 1635 {
1614 GNUNET_break_op(0); 1636 GNUNET_break_op (0);
1615 fail_resolution(rh); 1637 fail_resolution (rh);
1616 return; 1638 return;
1617 } 1639 }
1618 /* expand authority chain */ 1640 /* expand authority chain */
1619 ac = GNUNET_new(struct AuthorityChain); 1641 ac = GNUNET_new (struct AuthorityChain);
1620 ac->rh = rh; 1642 ac->rh = rh;
1621 ac->gns_authority = GNUNET_YES; 1643 ac->gns_authority = GNUNET_YES;
1622 GNUNET_memcpy(&ac->authority_info.gns_authority, 1644 GNUNET_memcpy (&ac->authority_info.gns_authority,
1623 rd->data, 1645 rd->data,
1624 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 1646 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
1625 ac->label = resolver_lookup_get_next_label(rh); 1647 ac->label = resolver_lookup_get_next_label (rh);
1626 /* add AC to tail */ 1648 /* add AC to tail */
1627 GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, 1649 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1628 rh->ac_tail, 1650 rh->ac_tail,
1629 ac); 1651 ac);
1630 /* recurse */ 1652 /* recurse */
1631 rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, 1653 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1632 rh); 1654 rh);
1633} 1655}
1634 1656
1635 1657
@@ -1644,9 +1666,9 @@ recursive_pkey_resolution(struct GNS_ResolverHandle *rh,
1644 * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd 1666 * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd
1645 */ 1667 */
1646static int 1668static int
1647recursive_gns2dns_resolution(struct GNS_ResolverHandle *rh, 1669recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1648 unsigned int rd_count, 1670 unsigned int rd_count,
1649 const struct GNUNET_GNSRECORD_Data *rd) 1671 const struct GNUNET_GNSRECORD_Data *rd)
1650{ 1672{
1651 struct AuthorityChain *ac; 1673 struct AuthorityChain *ac;
1652 const char *tld; 1674 const char *tld;
@@ -1654,157 +1676,158 @@ recursive_gns2dns_resolution(struct GNS_ResolverHandle *rh,
1654 1676
1655 ns = NULL; 1677 ns = NULL;
1656 /* expand authority chain */ 1678 /* expand authority chain */
1657 ac = GNUNET_new(struct AuthorityChain); 1679 ac = GNUNET_new (struct AuthorityChain);
1658 ac->rh = rh; 1680 ac->rh = rh;
1659 ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start(4); 1681 ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start (4);
1660 1682
1661 for (unsigned int i = 0; i < rd_count; i++) 1683 for (unsigned int i = 0; i < rd_count; i++)
1662 { 1684 {
1663 char *ip; 1685 char *ip;
1664 char *n; 1686 char *n;
1665 size_t off; 1687 size_t off;
1666 struct Gns2DnsPending *gp; 1688 struct Gns2DnsPending *gp;
1667 struct GNUNET_CRYPTO_EcdsaPublicKey zone; 1689 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
1668 struct sockaddr_in v4; 1690 struct sockaddr_in v4;
1669 struct sockaddr_in6 v6; 1691 struct sockaddr_in6 v6;
1670 1692
1671 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) 1693 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
1672 continue; 1694 continue;
1673 off = 0; 1695 off = 0;
1674 n = GNUNET_DNSPARSER_parse_name(rd[i].data, 1696 n = GNUNET_DNSPARSER_parse_name (rd[i].data,
1697 rd[i].data_size,
1698 &off);
1699 ip = GNUNET_DNSPARSER_parse_name (rd[i].data,
1675 rd[i].data_size, 1700 rd[i].data_size,
1676 &off); 1701 &off);
1677 ip = GNUNET_DNSPARSER_parse_name(rd[i].data, 1702 if ((NULL == n) ||
1678 rd[i].data_size, 1703 (NULL == ip) ||
1679 &off); 1704 (off != rd[i].data_size))
1680 if ((NULL == n) || 1705 {
1681 (NULL == ip) || 1706 GNUNET_break_op (0);
1682 (off != rd[i].data_size)) 1707 GNUNET_free_non_null (n);
1683 { 1708 GNUNET_free_non_null (ip);
1684 GNUNET_break_op(0); 1709 continue;
1685 GNUNET_free_non_null(n); 1710 }
1686 GNUNET_free_non_null(ip); 1711 /* resolve 'ip' to determine the IP(s) of the DNS
1687 continue; 1712 resolver to use for lookup of 'ns' */
1688 } 1713 if (NULL != ns)
1689 /* resolve 'ip' to determine the IP(s) of the DNS 1714 {
1690 resolver to use for lookup of 'ns' */ 1715 if (0 != strcasecmp (ns,
1691 if (NULL != ns) 1716 n))
1692 { 1717 {
1693 if (0 != strcasecmp(ns, 1718 /* NS values must all be the same for all GNS2DNS records,
1694 n)) 1719 anything else leads to insanity */
1695 { 1720 GNUNET_break_op (0);
1696 /* NS values must all be the same for all GNS2DNS records, 1721 GNUNET_free (n);
1697 anything else leads to insanity */ 1722 GNUNET_free (ip);
1698 GNUNET_break_op(0); 1723 continue;
1699 GNUNET_free(n); 1724 }
1700 GNUNET_free(ip); 1725 GNUNET_free (n);
1701 continue; 1726 }
1702 } 1727 else
1703 GNUNET_free(n); 1728 {
1704 } 1729 ns = n;
1705 else 1730 }
1706 {
1707 ns = n;
1708 }
1709 1731
1710 /* check if 'ip' is already an IPv4/IPv6 address */ 1732 /* check if 'ip' is already an IPv4/IPv6 address */
1711 if ((1 == inet_pton(AF_INET, 1733 if ((1 == inet_pton (AF_INET,
1712 ip, 1734 ip,
1713 &v4)) || 1735 &v4)) ||
1714 (1 == inet_pton(AF_INET6, 1736 (1 == inet_pton (AF_INET6,
1715 ip, 1737 ip,
1716 &v6))) 1738 &v6)))
1717 { 1739 {
1718 GNUNET_break(GNUNET_OK == 1740 GNUNET_break (GNUNET_OK ==
1719 GNUNET_DNSSTUB_add_dns_ip(ac->authority_info.dns_authority.dns_handle, 1741 GNUNET_DNSSTUB_add_dns_ip (
1720 ip)); 1742 ac->authority_info.dns_authority.dns_handle,
1721 ac->authority_info.dns_authority.found = GNUNET_YES; 1743 ip));
1722 GNUNET_free(ip); 1744 ac->authority_info.dns_authority.found = GNUNET_YES;
1723 continue; 1745 GNUNET_free (ip);
1724 } 1746 continue;
1725 tld = GNS_get_tld(ip); 1747 }
1726 if (0 != strcmp(tld, 1748 tld = GNS_get_tld (ip);
1727 "+")) 1749 if (0 != strcmp (tld,
1728 { 1750 "+"))
1729 /* 'ip' is a DNS name */ 1751 {
1730 gp = GNUNET_new(struct Gns2DnsPending); 1752 /* 'ip' is a DNS name */
1731 gp->ac = ac; 1753 gp = GNUNET_new (struct Gns2DnsPending);
1732 GNUNET_CONTAINER_DLL_insert(ac->authority_info.dns_authority.gp_head,
1733 ac->authority_info.dns_authority.gp_tail,
1734 gp);
1735 gp->dns_rh = GNUNET_RESOLVER_ip_get(ip,
1736 AF_UNSPEC,
1737 GNUNET_TIME_UNIT_FOREVER_REL,
1738 &handle_gns2dns_ip,
1739 gp);
1740 GNUNET_free(ip);
1741 continue;
1742 }
1743 /* 'ip' should be a GNS name */
1744 gp = GNUNET_new(struct Gns2DnsPending);
1745 gp->ac = ac; 1754 gp->ac = ac;
1746 GNUNET_CONTAINER_DLL_insert(ac->authority_info.dns_authority.gp_head, 1755 GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head,
1747 ac->authority_info.dns_authority.gp_tail, 1756 ac->authority_info.dns_authority.gp_tail,
1748 gp); 1757 gp);
1749 gp->rh = GNUNET_new(struct GNS_ResolverHandle); 1758 gp->dns_rh = GNUNET_RESOLVER_ip_get (ip,
1750 ip = translate_dot_plus(rh, 1759 AF_UNSPEC,
1751 ip); 1760 GNUNET_TIME_UNIT_FOREVER_REL,
1752 tld = GNS_get_tld(ip); 1761 &handle_gns2dns_ip,
1753 if (GNUNET_OK != 1762 gp);
1754 GNUNET_GNSRECORD_zkey_to_pkey(tld, 1763 GNUNET_free (ip);
1755 &zone)) 1764 continue;
1756 { 1765 }
1757 GNUNET_break_op(0); 1766 /* 'ip' should be a GNS name */
1758 GNUNET_free(ip); 1767 gp = GNUNET_new (struct Gns2DnsPending);
1759 continue; 1768 gp->ac = ac;
1760 } 1769 GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head,
1761 gp->rh->authority_zone = zone; 1770 ac->authority_info.dns_authority.gp_tail,
1762 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1771 gp);
1763 "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n", 1772 gp->rh = GNUNET_new (struct GNS_ResolverHandle);
1764 ip, 1773 ip = translate_dot_plus (rh,
1765 ns); 1774 ip);
1766 gp->rh->name = ip; 1775 tld = GNS_get_tld (ip);
1767 gp->rh->name_resolution_pos = strlen(ip) - strlen(tld) - 1; 1776 if (GNUNET_OK !=
1768 gp->rh->proc = &handle_gns2dns_result; 1777 GNUNET_GNSRECORD_zkey_to_pkey (tld,
1769 gp->rh->proc_cls = gp; 1778 &zone))
1770 gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY;
1771 gp->rh->options = GNUNET_GNS_LO_DEFAULT;
1772 gp->rh->loop_limiter = rh->loop_limiter + 1;
1773 gp->rh->task_id
1774 = GNUNET_SCHEDULER_add_now(&start_resolver_lookup,
1775 gp->rh);
1776 } /* end 'for all records' */
1777
1778 if (NULL == ns)
1779 { 1779 {
1780 /* not a single GNS2DNS record found */ 1780 GNUNET_break_op (0);
1781 GNUNET_free(ac); 1781 GNUNET_free (ip);
1782 return GNUNET_SYSERR; 1782 continue;
1783 } 1783 }
1784 GNUNET_assert(strlen(ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH); 1784 gp->rh->authority_zone = zone;
1785 strcpy(ac->authority_info.dns_authority.name, 1785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1786 ns); 1786 "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n",
1787 ip,
1788 ns);
1789 gp->rh->name = ip;
1790 gp->rh->name_resolution_pos = strlen (ip) - strlen (tld) - 1;
1791 gp->rh->proc = &handle_gns2dns_result;
1792 gp->rh->proc_cls = gp;
1793 gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY;
1794 gp->rh->options = GNUNET_GNS_LO_DEFAULT;
1795 gp->rh->loop_limiter = rh->loop_limiter + 1;
1796 gp->rh->task_id
1797 = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
1798 gp->rh);
1799 } /* end 'for all records' */
1800
1801 if (NULL == ns)
1802 {
1803 /* not a single GNS2DNS record found */
1804 GNUNET_free (ac);
1805 return GNUNET_SYSERR;
1806 }
1807 GNUNET_assert (strlen (ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH);
1808 strcpy (ac->authority_info.dns_authority.name,
1809 ns);
1787 /* for DNS recursion, the label is the full DNS name, 1810 /* for DNS recursion, the label is the full DNS name,
1788 created from the remainder of the GNS name and the 1811 created from the remainder of the GNS name and the
1789 name in the NS record */ 1812 name in the NS record */
1790 GNUNET_asprintf(&ac->label, 1813 GNUNET_asprintf (&ac->label,
1791 "%.*s%s%s", 1814 "%.*s%s%s",
1792 (int)rh->name_resolution_pos, 1815 (int) rh->name_resolution_pos,
1793 rh->name, 1816 rh->name,
1794 (0 != rh->name_resolution_pos) ? "." : "", 1817 (0 != rh->name_resolution_pos) ? "." : "",
1795 ns); 1818 ns);
1796 GNUNET_free(ns); 1819 GNUNET_free (ns);
1797 GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, 1820 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1798 rh->ac_tail, 1821 rh->ac_tail,
1799 ac); 1822 ac);
1800 if (strlen(ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) 1823 if (strlen (ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
1801 { 1824 {
1802 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1825 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1803 _("GNS lookup resulted in DNS name that is too long (`%s')\n"), 1826 _ ("GNS lookup resulted in DNS name that is too long (`%s')\n"),
1804 ac->label); 1827 ac->label);
1805 return GNUNET_SYSERR; 1828 return GNUNET_SYSERR;
1806 } 1829 }
1807 continue_with_gns2dns(ac); 1830 continue_with_gns2dns (ac);
1808 return GNUNET_OK; 1831 return GNUNET_OK;
1809} 1832}
1810 1833
@@ -1817,9 +1840,9 @@ recursive_gns2dns_resolution(struct GNS_ResolverHandle *rh,
1817 * @param rd array of records with data to store 1840 * @param rd array of records with data to store
1818 */ 1841 */
1819static void 1842static void
1820handle_gns_resolution_result(void *cls, 1843handle_gns_resolution_result (void *cls,
1821 unsigned int rd_count, 1844 unsigned int rd_count,
1822 const struct GNUNET_GNSRECORD_Data *rd) 1845 const struct GNUNET_GNSRECORD_Data *rd)
1823{ 1846{
1824 struct GNS_ResolverHandle *rh = cls; 1847 struct GNS_ResolverHandle *rh = cls;
1825 char *cname; 1848 char *cname;
@@ -1835,442 +1858,450 @@ handle_gns_resolution_result(void *cls,
1835 struct GNUNET_GNSRECORD_Data rd_new[rd_count]; 1858 struct GNUNET_GNSRECORD_Data rd_new[rd_count];
1836 unsigned int rd_off; 1859 unsigned int rd_off;
1837 1860
1838 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1861 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1839 "Resolution succeeded for `%s' in zone %s, got %u records\n", 1862 "Resolution succeeded for `%s' in zone %s, got %u records\n",
1840 rh->ac_tail->label, 1863 rh->ac_tail->label,
1841 GNUNET_GNSRECORD_z2s(&rh->ac_tail->authority_info.gns_authority), 1864 GNUNET_GNSRECORD_z2s (&rh->ac_tail->authority_info.gns_authority),
1842 rd_count); 1865 rd_count);
1843 if (0 == rd_count) 1866 if (0 == rd_count)
1867 {
1868 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1869 _ ("GNS lookup failed (zero records found for `%s')\n"),
1870 rh->name);
1871 fail_resolution (rh);
1872 return;
1873 }
1874
1875 if (0 == rh->name_resolution_pos)
1876 {
1877 /* top-level match, are we done yet? */
1878 if ((rd_count > 0) &&
1879 (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) &&
1880 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type))
1844 { 1881 {
1845 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1882 off = 0;
1846 _("GNS lookup failed (zero records found for `%s')\n"), 1883 cname = GNUNET_DNSPARSER_parse_name (rd[0].data,
1847 rh->name); 1884 rd[0].data_size,
1848 fail_resolution(rh); 1885 &off);
1886 if ((NULL == cname) ||
1887 (off != rd[0].data_size))
1888 {
1889 GNUNET_break_op (0);
1890 GNUNET_free_non_null (cname);
1891 fail_resolution (rh);
1892 return;
1893 }
1894 handle_gns_cname_result (rh,
1895 cname);
1896 GNUNET_free (cname);
1849 return; 1897 return;
1850 } 1898 }
1851 1899 /* If A/AAAA was requested, but we got a VPN
1852 if (0 == rh->name_resolution_pos) 1900 record, we convert it to A/AAAA using GNUnet VPN */
1901 if ((GNUNET_DNSPARSER_TYPE_A == rh->record_type) ||
1902 (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type))
1853 { 1903 {
1854 /* top-level match, are we done yet? */ 1904 for (unsigned int i = 0; i < rd_count; i++)
1855 if ((rd_count > 0) && 1905 {
1856 (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) && 1906 switch (rd[i].record_type)
1857 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type))
1858 { 1907 {
1859 off = 0; 1908 case GNUNET_GNSRECORD_TYPE_VPN:
1860 cname = GNUNET_DNSPARSER_parse_name(rd[0].data, 1909 {
1861 rd[0].data_size, 1910 af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET :
1862 &off); 1911 AF_INET6;
1863 if ((NULL == cname) || 1912 if (sizeof(struct GNUNET_TUN_GnsVpnRecord) >
1864 (off != rd[0].data_size)) 1913 rd[i].data_size)
1865 { 1914 {
1866 GNUNET_break_op(0); 1915 GNUNET_break_op (0);
1867 GNUNET_free_non_null(cname); 1916 fail_resolution (rh);
1868 fail_resolution(rh);
1869 return; 1917 return;
1870 } 1918 }
1871 handle_gns_cname_result(rh, 1919 vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data;
1872 cname); 1920 vname = (const char *) &vpn[1];
1873 GNUNET_free(cname); 1921 if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct
1874 return; 1922 GNUNET_TUN_GnsVpnRecord)
1875 } 1923 ])
1876 /* If A/AAAA was requested, but we got a VPN
1877 record, we convert it to A/AAAA using GNUnet VPN */
1878 if ((GNUNET_DNSPARSER_TYPE_A == rh->record_type) ||
1879 (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type))
1880 {
1881 for (unsigned int i = 0; i < rd_count; i++)
1882 {
1883 switch (rd[i].record_type)
1884 {
1885 case GNUNET_GNSRECORD_TYPE_VPN:
1886 {
1887 af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6;
1888 if (sizeof(struct GNUNET_TUN_GnsVpnRecord) >
1889 rd[i].data_size)
1890 {
1891 GNUNET_break_op(0);
1892 fail_resolution(rh);
1893 return;
1894 }
1895 vpn = (const struct GNUNET_TUN_GnsVpnRecord *)rd[i].data;
1896 vname = (const char *)&vpn[1];
1897 if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct GNUNET_TUN_GnsVpnRecord)])
1898 {
1899 GNUNET_break_op(0);
1900 fail_resolution(rh);
1901 return;
1902 }
1903 GNUNET_TUN_service_name_to_hash(vname,
1904 &vhash);
1905 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1906 "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
1907 GNUNET_i2s(&vpn->peer),
1908 vname,
1909 (int)af,
1910 (int)ntohs(vpn->proto));
1911 vpn_ctx = GNUNET_new(struct VpnContext);
1912 rh->vpn_ctx = vpn_ctx;
1913 vpn_ctx->rh = rh;
1914 vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size(rd_count,
1915 rd);
1916 if (vpn_ctx->rd_data_size < 0)
1917 {
1918 GNUNET_break_op(0);
1919 GNUNET_free(vpn_ctx);
1920 fail_resolution(rh);
1921 return;
1922 }
1923 vpn_ctx->rd_data = GNUNET_malloc((size_t)vpn_ctx->rd_data_size);
1924 vpn_ctx->rd_count = rd_count;
1925 GNUNET_assert(vpn_ctx->rd_data_size ==
1926 GNUNET_GNSRECORD_records_serialize(rd_count,
1927 rd,
1928 (size_t)vpn_ctx->rd_data_size,
1929 vpn_ctx->rd_data));
1930 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer(vpn_handle,
1931 af,
1932 ntohs(vpn->proto),
1933 &vpn->peer,
1934 &vhash,
1935 GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT),
1936 &vpn_allocation_cb,
1937 vpn_ctx);
1938 return;
1939 }
1940
1941 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
1942 {
1943 /* delegation to DNS */
1944 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1945 "Found GNS2DNS record, delegating to DNS!\n");
1946 if (GNUNET_OK ==
1947 recursive_gns2dns_resolution(rh,
1948 rd_count,
1949 rd))
1950 return;
1951 else
1952 goto fail;
1953 }
1954
1955 default:
1956 break;
1957 } /* end: switch */
1958 } /* end: for rd */
1959 } /* end: name_resolution_pos */
1960 /* convert relative names in record values to absolute names,
1961 using 'scratch' array for memory allocations */
1962 scratch_off = 0;
1963 rd_off = 0;
1964 for (unsigned int i = 0; i < rd_count; i++)
1965 {
1966 GNUNET_assert(rd_off <= i);
1967 if ((0 != rh->protocol) &&
1968 (0 != rh->service) &&
1969 (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type))
1970 continue; /* we _only_ care about boxed records */
1971
1972 GNUNET_assert(rd_off < rd_count);
1973 rd_new[rd_off] = rd[i];
1974 /* Check if the embedded name(s) end in "+", and if so,
1975 replace the "+" with the zone at "ac_tail", changing the name
1976 to a ".ZONEKEY". The name is allocated on the 'scratch' array,
1977 so we can free it afterwards. */
1978 switch (rd[i].record_type)
1979 { 1924 {
1980 case GNUNET_DNSPARSER_TYPE_CNAME: 1925 GNUNET_break_op (0);
1926 fail_resolution (rh);
1927 return;
1928 }
1929 GNUNET_TUN_service_name_to_hash (vname,
1930 &vhash);
1931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1932 "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
1933 GNUNET_i2s (&vpn->peer),
1934 vname,
1935 (int) af,
1936 (int) ntohs (vpn->proto));
1937 vpn_ctx = GNUNET_new (struct VpnContext);
1938 rh->vpn_ctx = vpn_ctx;
1939 vpn_ctx->rh = rh;
1940 vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
1941 rd);
1942 if (vpn_ctx->rd_data_size < 0)
1981 { 1943 {
1982 char *cname; 1944 GNUNET_break_op (0);
1983 1945 GNUNET_free (vpn_ctx);
1984 off = 0; 1946 fail_resolution (rh);
1985 cname = GNUNET_DNSPARSER_parse_name(rd[i].data, 1947 return;
1986 rd[i].data_size,
1987 &off);
1988 if ((NULL == cname) ||
1989 (off != rd[i].data_size))
1990 {
1991 GNUNET_break_op(0); /* record not well-formed */
1992 }
1993 else
1994 {
1995 cname = translate_dot_plus(rh, cname);
1996 GNUNET_break(NULL != cname);
1997 scratch_start = scratch_off;
1998 if (GNUNET_OK !=
1999 GNUNET_DNSPARSER_builder_add_name(scratch,
2000 sizeof(scratch),
2001 &scratch_off,
2002 cname))
2003 {
2004 GNUNET_break(0);
2005 }
2006 else
2007 {
2008 GNUNET_assert(rd_off < rd_count);
2009 rd_new[rd_off].data = &scratch[scratch_start];
2010 rd_new[rd_off].data_size = scratch_off - scratch_start;
2011 rd_off++;
2012 }
2013 }
2014 GNUNET_free_non_null(cname);
2015 } 1948 }
2016 break; 1949 vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size);
1950 vpn_ctx->rd_count = rd_count;
1951 GNUNET_assert (vpn_ctx->rd_data_size ==
1952 GNUNET_GNSRECORD_records_serialize (rd_count,
1953 rd,
1954 (size_t) vpn_ctx
1955 ->rd_data_size,
1956 vpn_ctx->rd_data));
1957 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
1958 af,
1959 ntohs (
1960 vpn->proto),
1961 &vpn->peer,
1962 &vhash,
1963 GNUNET_TIME_relative_to_absolute (
1964 VPN_TIMEOUT),
1965 &
1966 vpn_allocation_cb,
1967 vpn_ctx);
1968 return;
1969 }
2017 1970
2018 case GNUNET_DNSPARSER_TYPE_SOA: 1971 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
2019 { 1972 {
2020 struct GNUNET_DNSPARSER_SoaRecord *soa; 1973 /* delegation to DNS */
1974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1975 "Found GNS2DNS record, delegating to DNS!\n");
1976 if (GNUNET_OK ==
1977 recursive_gns2dns_resolution (rh,
1978 rd_count,
1979 rd))
1980 return;
1981 else
1982 goto fail;
1983 }
1984
1985 default:
1986 break;
1987 } /* end: switch */
1988 } /* end: for rd */
1989 } /* end: name_resolution_pos */
1990 /* convert relative names in record values to absolute names,
1991 using 'scratch' array for memory allocations */
1992 scratch_off = 0;
1993 rd_off = 0;
1994 for (unsigned int i = 0; i < rd_count; i++)
1995 {
1996 GNUNET_assert (rd_off <= i);
1997 if ((0 != rh->protocol) &&
1998 (0 != rh->service) &&
1999 (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type))
2000 continue; /* we _only_ care about boxed records */
2001
2002 GNUNET_assert (rd_off < rd_count);
2003 rd_new[rd_off] = rd[i];
2004 /* Check if the embedded name(s) end in "+", and if so,
2005 replace the "+" with the zone at "ac_tail", changing the name
2006 to a ".ZONEKEY". The name is allocated on the 'scratch' array,
2007 so we can free it afterwards. */
2008 switch (rd[i].record_type)
2009 {
2010 case GNUNET_DNSPARSER_TYPE_CNAME:
2011 {
2012 char *cname;
2021 2013
2022 off = 0; 2014 off = 0;
2023 soa = GNUNET_DNSPARSER_parse_soa(rd[i].data, 2015 cname = GNUNET_DNSPARSER_parse_name (rd[i].data,
2024 rd[i].data_size, 2016 rd[i].data_size,
2025 &off); 2017 &off);
2026 if ((NULL == soa) || 2018 if ((NULL == cname) ||
2027 (off != rd[i].data_size)) 2019 (off != rd[i].data_size))
2028 { 2020 {
2029 GNUNET_break_op(0); /* record not well-formed */ 2021 GNUNET_break_op (0); /* record not well-formed */
2030 } 2022 }
2031 else 2023 else
2032 { 2024 {
2033 soa->mname = translate_dot_plus(rh, soa->mname); 2025 cname = translate_dot_plus (rh, cname);
2034 soa->rname = translate_dot_plus(rh, soa->rname); 2026 GNUNET_break (NULL != cname);
2035 scratch_start = scratch_off; 2027 scratch_start = scratch_off;
2036 if (GNUNET_OK != 2028 if (GNUNET_OK !=
2037 GNUNET_DNSPARSER_builder_add_soa(scratch, 2029 GNUNET_DNSPARSER_builder_add_name (scratch,
2038 sizeof(scratch), 2030 sizeof(scratch),
2039 &scratch_off, 2031 &scratch_off,
2040 soa)) 2032 cname))
2041 { 2033 {
2042 GNUNET_break(0); 2034 GNUNET_break (0);
2043 }
2044 else
2045 {
2046 GNUNET_assert(rd_off < rd_count);
2047 rd_new[rd_off].data = &scratch[scratch_start];
2048 rd_new[rd_off].data_size = scratch_off - scratch_start;
2049 rd_off++;
2050 }
2051 }
2052 if (NULL != soa)
2053 GNUNET_DNSPARSER_free_soa(soa);
2054 } 2035 }
2055 break; 2036 else
2056
2057 case GNUNET_DNSPARSER_TYPE_MX:
2058 { 2037 {
2059 struct GNUNET_DNSPARSER_MxRecord *mx; 2038 GNUNET_assert (rd_off < rd_count);
2060 2039 rd_new[rd_off].data = &scratch[scratch_start];
2061 off = 0; 2040 rd_new[rd_off].data_size = scratch_off - scratch_start;
2062 mx = GNUNET_DNSPARSER_parse_mx(rd[i].data, 2041 rd_off++;
2063 rd[i].data_size,
2064 &off);
2065 if ((NULL == mx) ||
2066 (off != rd[i].data_size))
2067 {
2068 GNUNET_break_op(0); /* record not well-formed */
2069 }
2070 else
2071 {
2072 mx->mxhost = translate_dot_plus(rh, mx->mxhost);
2073 scratch_start = scratch_off;
2074 if (GNUNET_OK !=
2075 GNUNET_DNSPARSER_builder_add_mx(scratch,
2076 sizeof(scratch),
2077 &scratch_off,
2078 mx))
2079 {
2080 GNUNET_break(0);
2081 }
2082 else
2083 {
2084 GNUNET_assert(rd_off < rd_count);
2085 rd_new[rd_off].data = &scratch[scratch_start];
2086 rd_new[rd_off].data_size = scratch_off - scratch_start;
2087 rd_off++;
2088 }
2089 }
2090 if (NULL != mx)
2091 GNUNET_DNSPARSER_free_mx(mx);
2092 } 2042 }
2093 break; 2043 }
2044 GNUNET_free_non_null (cname);
2045 }
2046 break;
2094 2047
2095 case GNUNET_DNSPARSER_TYPE_SRV: 2048 case GNUNET_DNSPARSER_TYPE_SOA:
2096 { 2049 {
2097 struct GNUNET_DNSPARSER_SrvRecord *srv; 2050 struct GNUNET_DNSPARSER_SoaRecord *soa;
2098 2051
2099 off = 0; 2052 off = 0;
2100 srv = GNUNET_DNSPARSER_parse_srv(rd[i].data, 2053 soa = GNUNET_DNSPARSER_parse_soa (rd[i].data,
2101 rd[i].data_size, 2054 rd[i].data_size,
2102 &off); 2055 &off);
2103 if ((NULL == srv) || 2056 if ((NULL == soa) ||
2104 (off != rd[i].data_size)) 2057 (off != rd[i].data_size))
2105 { 2058 {
2106 GNUNET_break_op(0); /* record not well-formed */ 2059 GNUNET_break_op (0); /* record not well-formed */
2107 } 2060 }
2108 else 2061 else
2109 { 2062 {
2110 srv->target = translate_dot_plus(rh, srv->target); 2063 soa->mname = translate_dot_plus (rh, soa->mname);
2111 scratch_start = scratch_off; 2064 soa->rname = translate_dot_plus (rh, soa->rname);
2112 if (GNUNET_OK != 2065 scratch_start = scratch_off;
2113 GNUNET_DNSPARSER_builder_add_srv(scratch, 2066 if (GNUNET_OK !=
2114 sizeof(scratch), 2067 GNUNET_DNSPARSER_builder_add_soa (scratch,
2115 &scratch_off, 2068 sizeof(scratch),
2116 srv)) 2069 &scratch_off,
2117 { 2070 soa))
2118 GNUNET_break(0); 2071 {
2119 } 2072 GNUNET_break (0);
2120 else
2121 {
2122 GNUNET_assert(rd_off < rd_count);
2123 rd_new[rd_off].data = &scratch[scratch_start];
2124 rd_new[rd_off].data_size = scratch_off - scratch_start;
2125 rd_off++;
2126 }
2127 }
2128 if (NULL != srv)
2129 GNUNET_DNSPARSER_free_srv(srv);
2130 } 2073 }
2131 break; 2074 else
2132
2133 case GNUNET_GNSRECORD_TYPE_NICK:
2134 { 2075 {
2135 const char *nick; 2076 GNUNET_assert (rd_off < rd_count);
2136 2077 rd_new[rd_off].data = &scratch[scratch_start];
2137 nick = rd[i].data; 2078 rd_new[rd_off].data_size = scratch_off - scratch_start;
2138 if ((rd[i].data_size > 0) && 2079 rd_off++;
2139 (nick[rd[i].data_size - 1] != '\0'))
2140 {
2141 GNUNET_break_op(0);
2142 break;
2143 }
2144 break;
2145 } 2080 }
2081 }
2082 if (NULL != soa)
2083 GNUNET_DNSPARSER_free_soa (soa);
2084 }
2085 break;
2146 2086
2147 case GNUNET_GNSRECORD_TYPE_PKEY: 2087 case GNUNET_DNSPARSER_TYPE_MX:
2088 {
2089 struct GNUNET_DNSPARSER_MxRecord *mx;
2090
2091 off = 0;
2092 mx = GNUNET_DNSPARSER_parse_mx (rd[i].data,
2093 rd[i].data_size,
2094 &off);
2095 if ((NULL == mx) ||
2096 (off != rd[i].data_size))
2097 {
2098 GNUNET_break_op (0); /* record not well-formed */
2099 }
2100 else
2101 {
2102 mx->mxhost = translate_dot_plus (rh, mx->mxhost);
2103 scratch_start = scratch_off;
2104 if (GNUNET_OK !=
2105 GNUNET_DNSPARSER_builder_add_mx (scratch,
2106 sizeof(scratch),
2107 &scratch_off,
2108 mx))
2148 { 2109 {
2149 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 2110 GNUNET_break (0);
2150 2111 }
2151 if (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) 2112 else
2152 { 2113 {
2153 GNUNET_break_op(0); 2114 GNUNET_assert (rd_off < rd_count);
2154 break; 2115 rd_new[rd_off].data = &scratch[scratch_start];
2155 } 2116 rd_new[rd_off].data_size = scratch_off - scratch_start;
2156 GNUNET_memcpy(&pub,
2157 rd[i].data,
2158 rd[i].data_size);
2159 rd_off++; 2117 rd_off++;
2160 if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type)
2161 {
2162 /* try to resolve "@" */
2163 struct AuthorityChain *ac;
2164
2165 ac = GNUNET_new(struct AuthorityChain);
2166 ac->rh = rh;
2167 ac->gns_authority = GNUNET_YES;
2168 ac->authority_info.gns_authority = pub;
2169 ac->label = GNUNET_strdup(GNUNET_GNS_EMPTY_LABEL_AT);
2170 GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head,
2171 rh->ac_tail,
2172 ac);
2173 rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution,
2174 rh);
2175 return;
2176 }
2177 } 2118 }
2178 break; 2119 }
2120 if (NULL != mx)
2121 GNUNET_DNSPARSER_free_mx (mx);
2122 }
2123 break;
2179 2124
2180 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 2125 case GNUNET_DNSPARSER_TYPE_SRV:
2126 {
2127 struct GNUNET_DNSPARSER_SrvRecord *srv;
2128
2129 off = 0;
2130 srv = GNUNET_DNSPARSER_parse_srv (rd[i].data,
2131 rd[i].data_size,
2132 &off);
2133 if ((NULL == srv) ||
2134 (off != rd[i].data_size))
2135 {
2136 GNUNET_break_op (0); /* record not well-formed */
2137 }
2138 else
2139 {
2140 srv->target = translate_dot_plus (rh, srv->target);
2141 scratch_start = scratch_off;
2142 if (GNUNET_OK !=
2143 GNUNET_DNSPARSER_builder_add_srv (scratch,
2144 sizeof(scratch),
2145 &scratch_off,
2146 srv))
2181 { 2147 {
2182 /* delegation to DNS */ 2148 GNUNET_break (0);
2183 if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type)
2184 {
2185 rd_off++;
2186 break; /* do not follow to DNS, we wanted the GNS2DNS record! */
2187 }
2188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2189 "Found GNS2DNS record, delegating to DNS!\n");
2190 if (GNUNET_OK ==
2191 recursive_gns2dns_resolution(rh,
2192 rd_count,
2193 rd))
2194 return;
2195 else
2196 goto fail;
2197 } 2149 }
2198 2150 else
2199 case GNUNET_GNSRECORD_TYPE_BOX:
2200 { 2151 {
2201 /* unbox SRV/TLSA records if a specific one was requested */ 2152 GNUNET_assert (rd_off < rd_count);
2202 if ((0 != rh->protocol) && 2153 rd_new[rd_off].data = &scratch[scratch_start];
2203 (0 != rh->service) && 2154 rd_new[rd_off].data_size = scratch_off - scratch_start;
2204 (rd[i].data_size >= sizeof(struct GNUNET_GNSRECORD_BoxRecord))) 2155 rd_off++;
2205 {
2206 const struct GNUNET_GNSRECORD_BoxRecord *box;
2207
2208 box = rd[i].data;
2209 if ((ntohs(box->protocol) == rh->protocol) &&
2210 (ntohs(box->service) == rh->service))
2211 {
2212 /* Box matches, unbox! */
2213 GNUNET_assert(rd_off < rd_count);
2214 rd_new[rd_off].record_type = ntohl(box->record_type);
2215 rd_new[rd_off].data_size -= sizeof(struct GNUNET_GNSRECORD_BoxRecord);
2216 rd_new[rd_off].data = &box[1];
2217 rd_off++;
2218 }
2219 }
2220 else
2221 {
2222 /* no specific protocol/service specified, preserve all BOX
2223 records (for modern, GNS-enabled applications) */
2224 rd_off++;
2225 }
2226 break;
2227 } 2156 }
2157 }
2158 if (NULL != srv)
2159 GNUNET_DNSPARSER_free_srv (srv);
2160 }
2161 break;
2162
2163 case GNUNET_GNSRECORD_TYPE_NICK:
2164 {
2165 const char *nick;
2166
2167 nick = rd[i].data;
2168 if ((rd[i].data_size > 0) &&
2169 (nick[rd[i].data_size - 1] != '\0'))
2170 {
2171 GNUNET_break_op (0);
2172 break;
2173 }
2174 break;
2175 }
2176
2177 case GNUNET_GNSRECORD_TYPE_PKEY:
2178 {
2179 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
2180
2181 if (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))
2182 {
2183 GNUNET_break_op (0);
2184 break;
2185 }
2186 GNUNET_memcpy (&pub,
2187 rd[i].data,
2188 rd[i].data_size);
2189 rd_off++;
2190 if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type)
2191 {
2192 /* try to resolve "@" */
2193 struct AuthorityChain *ac;
2194
2195 ac = GNUNET_new (struct AuthorityChain);
2196 ac->rh = rh;
2197 ac->gns_authority = GNUNET_YES;
2198 ac->authority_info.gns_authority = pub;
2199 ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT);
2200 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
2201 rh->ac_tail,
2202 ac);
2203 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
2204 rh);
2205 return;
2206 }
2207 }
2208 break;
2209
2210 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
2211 {
2212 /* delegation to DNS */
2213 if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type)
2214 {
2215 rd_off++;
2216 break; /* do not follow to DNS, we wanted the GNS2DNS record! */
2217 }
2218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2219 "Found GNS2DNS record, delegating to DNS!\n");
2220 if (GNUNET_OK ==
2221 recursive_gns2dns_resolution (rh,
2222 rd_count,
2223 rd))
2224 return;
2225 else
2226 goto fail;
2227 }
2228
2229 case GNUNET_GNSRECORD_TYPE_BOX:
2230 {
2231 /* unbox SRV/TLSA records if a specific one was requested */
2232 if ((0 != rh->protocol) &&
2233 (0 != rh->service) &&
2234 (rd[i].data_size >= sizeof(struct GNUNET_GNSRECORD_BoxRecord)))
2235 {
2236 const struct GNUNET_GNSRECORD_BoxRecord *box;
2228 2237
2229 default: 2238 box = rd[i].data;
2239 if ((ntohs (box->protocol) == rh->protocol) &&
2240 (ntohs (box->service) == rh->service))
2241 {
2242 /* Box matches, unbox! */
2243 GNUNET_assert (rd_off < rd_count);
2244 rd_new[rd_off].record_type = ntohl (box->record_type);
2245 rd_new[rd_off].data_size -= sizeof(struct
2246 GNUNET_GNSRECORD_BoxRecord);
2247 rd_new[rd_off].data = &box[1];
2230 rd_off++; 2248 rd_off++;
2231 break; 2249 }
2232 } /* end: switch */ 2250 }
2233 } /* end: for rd_count */ 2251 else
2234 2252 {
2235 /* yes, we are done, return result */ 2253 /* no specific protocol/service specified, preserve all BOX
2236 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2254 records (for modern, GNS-enabled applications) */
2237 "Returning GNS response for `%s' with %u answers\n", 2255 rd_off++;
2238 rh->ac_tail->label, 2256 }
2239 rd_off); 2257 break;
2240 rh->proc(rh->proc_cls, 2258 }
2241 rd_off,
2242 rd_new);
2243 rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_,
2244 rh);
2245 return;
2246 }
2247 2259
2248 switch (rd[0].record_type) 2260 default:
2249 { 2261 rd_off++;
2250 case GNUNET_DNSPARSER_TYPE_CNAME: 2262 break;
2251 GNUNET_break_op(1 == rd_count); /* CNAME should be unique */ 2263 } /* end: switch */
2252 recursive_cname_resolution(rh, 2264 } /* end: for rd_count */
2253 &rd[0]); 2265
2254 return; 2266 /* yes, we are done, return result */
2267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2268 "Returning GNS response for `%s' with %u answers\n",
2269 rh->ac_tail->label,
2270 rd_off);
2271 rh->proc (rh->proc_cls,
2272 rd_off,
2273 rd_new);
2274 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2275 rh);
2276 return;
2277 }
2255 2278
2256 case GNUNET_GNSRECORD_TYPE_PKEY: 2279 switch (rd[0].record_type)
2257 GNUNET_break_op(1 == rd_count); /* PKEY should be unique */ 2280 {
2258 recursive_pkey_resolution(rh, 2281 case GNUNET_DNSPARSER_TYPE_CNAME:
2282 GNUNET_break_op (1 == rd_count); /* CNAME should be unique */
2283 recursive_cname_resolution (rh,
2259 &rd[0]); 2284 &rd[0]);
2260 return; 2285 return;
2261 2286
2262 default: 2287 case GNUNET_GNSRECORD_TYPE_PKEY:
2263 if (GNUNET_OK == 2288 GNUNET_break_op (1 == rd_count); /* PKEY should be unique */
2264 recursive_gns2dns_resolution(rh, 2289 recursive_pkey_resolution (rh,
2265 rd_count, 2290 &rd[0]);
2266 rd)) 2291 return;
2267 return; 2292
2268 break; 2293 default:
2269 } 2294 if (GNUNET_OK ==
2295 recursive_gns2dns_resolution (rh,
2296 rd_count,
2297 rd))
2298 return;
2299 break;
2300 }
2270fail: 2301fail:
2271 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2302 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2272 _("GNS lookup recursion failed (no delegation record found)\n")); 2303 _ ("GNS lookup recursion failed (no delegation record found)\n"));
2273 fail_resolution(rh); 2304 fail_resolution (rh);
2274} 2305}
2275 2306
2276 2307
@@ -2283,21 +2314,21 @@ fail:
2283 * @param emsg error message 2314 * @param emsg error message
2284 */ 2315 */
2285static void 2316static void
2286namecache_cache_continuation(void *cls, 2317namecache_cache_continuation (void *cls,
2287 int32_t success, 2318 int32_t success,
2288 const char *emsg) 2319 const char *emsg)
2289{ 2320{
2290 struct CacheOps *co = cls; 2321 struct CacheOps *co = cls;
2291 2322
2292 co->namecache_qe_cache = NULL; 2323 co->namecache_qe_cache = NULL;
2293 if (GNUNET_OK != success) 2324 if (GNUNET_OK != success)
2294 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2325 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2295 _("Failed to cache GNS resolution: %s\n"), 2326 _ ("Failed to cache GNS resolution: %s\n"),
2296 emsg); 2327 emsg);
2297 GNUNET_CONTAINER_DLL_remove(co_head, 2328 GNUNET_CONTAINER_DLL_remove (co_head,
2298 co_tail, 2329 co_tail,
2299 co); 2330 co);
2300 GNUNET_free(co); 2331 GNUNET_free (co);
2301} 2332}
2302 2333
2303 2334
@@ -2319,88 +2350,91 @@ namecache_cache_continuation(void *cls,
2319 * @param data pointer to the result data 2350 * @param data pointer to the result data
2320 */ 2351 */
2321static void 2352static void
2322handle_dht_response(void *cls, 2353handle_dht_response (void *cls,
2323 struct GNUNET_TIME_Absolute exp, 2354 struct GNUNET_TIME_Absolute exp,
2324 const struct GNUNET_HashCode *key, 2355 const struct GNUNET_HashCode *key,
2325 const struct GNUNET_PeerIdentity *get_path, 2356 const struct GNUNET_PeerIdentity *get_path,
2326 unsigned int get_path_length, 2357 unsigned int get_path_length,
2327 const struct GNUNET_PeerIdentity *put_path, 2358 const struct GNUNET_PeerIdentity *put_path,
2328 unsigned int put_path_length, 2359 unsigned int put_path_length,
2329 enum GNUNET_BLOCK_Type type, 2360 enum GNUNET_BLOCK_Type type,
2330 size_t size, 2361 size_t size,
2331 const void *data) 2362 const void *data)
2332{ 2363{
2333 struct GNS_ResolverHandle *rh = cls; 2364 struct GNS_ResolverHandle *rh = cls;
2334 struct AuthorityChain *ac = rh->ac_tail; 2365 struct AuthorityChain *ac = rh->ac_tail;
2335 const struct GNUNET_GNSRECORD_Block *block; 2366 const struct GNUNET_GNSRECORD_Block *block;
2336 struct CacheOps *co; 2367 struct CacheOps *co;
2337 2368
2338 (void)exp; 2369 (void) exp;
2339 (void)key; 2370 (void) key;
2340 (void)get_path; 2371 (void) get_path;
2341 (void)get_path_length; 2372 (void) get_path_length;
2342 (void)put_path; 2373 (void) put_path;
2343 (void)put_path_length; 2374 (void) put_path_length;
2344 (void)type; 2375 (void) type;
2345 GNUNET_DHT_get_stop(rh->get_handle); 2376 GNUNET_DHT_get_stop (rh->get_handle);
2346 rh->get_handle = NULL; 2377 rh->get_handle = NULL;
2347 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); 2378 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
2348 rh->dht_heap_node = NULL; 2379 rh->dht_heap_node = NULL;
2349 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2350 "Handling response from the DHT\n"); 2381 "Handling response from the DHT\n");
2351 if (size < sizeof(struct GNUNET_GNSRECORD_Block)) 2382 if (size < sizeof(struct GNUNET_GNSRECORD_Block))
2352 { 2383 {
2353 /* how did this pass DHT block validation!? */ 2384 /* how did this pass DHT block validation!? */
2354 GNUNET_break(0); 2385 GNUNET_break (0);
2355 fail_resolution(rh); 2386 fail_resolution (rh);
2356 return; 2387 return;
2357 } 2388 }
2358 block = data; 2389 block = data;
2359 if (size != 2390 if (size !=
2360 ntohl(block->purpose.size) + 2391 ntohl (block->purpose.size)
2361 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + 2392 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
2362 sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) 2393 + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))
2363 { 2394 {
2364 /* how did this pass DHT block validation!? */ 2395 /* how did this pass DHT block validation!? */
2365 GNUNET_break(0); 2396 GNUNET_break (0);
2366 fail_resolution(rh); 2397 fail_resolution (rh);
2367 return; 2398 return;
2368 } 2399 }
2369 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2370 "Decrypting DHT block of size %u for `%s', expires %s\n", 2401 "Decrypting DHT block of size %u for `%s', expires %s\n",
2371 ntohl(block->purpose.size), 2402 ntohl (block->purpose.size),
2372 rh->name, 2403 rh->name,
2373 GNUNET_STRINGS_absolute_time_to_string(exp)); 2404 GNUNET_STRINGS_absolute_time_to_string (exp));
2374 if (GNUNET_OK != 2405 if (GNUNET_OK !=
2375 GNUNET_GNSRECORD_block_decrypt(block, 2406 GNUNET_GNSRECORD_block_decrypt (block,
2376 &ac->authority_info.gns_authority, 2407 &ac->authority_info.gns_authority,
2377 ac->label, 2408 ac->label,
2378 &handle_gns_resolution_result, 2409 &handle_gns_resolution_result,
2379 rh)) 2410 rh))
2380 { 2411 {
2381 GNUNET_break_op(0); /* block was ill-formed */ 2412 GNUNET_break_op (0); /* block was ill-formed */
2382 fail_resolution(rh); 2413 fail_resolution (rh);
2383 return; 2414 return;
2384 } 2415 }
2385 if (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us) 2416 if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (
2386 { 2417 block->expiration_time)).
2387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2418 rel_value_us)
2388 "Received expired block from the DHT, will not cache it.\n"); 2419 {
2389 return; 2420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2390 } 2421 "Received expired block from the DHT, will not cache it.\n");
2422 return;
2423 }
2391 if (GNUNET_YES == disable_cache) 2424 if (GNUNET_YES == disable_cache)
2392 return; 2425 return;
2393 /* Cache well-formed blocks */ 2426 /* Cache well-formed blocks */
2394 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2395 "Caching response from the DHT in namecache\n"); 2428 "Caching response from the DHT in namecache\n");
2396 co = GNUNET_new(struct CacheOps); 2429 co = GNUNET_new (struct CacheOps);
2397 co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache(namecache_handle, 2430 co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache (namecache_handle,
2398 block, 2431 block,
2399 &namecache_cache_continuation, 2432 &
2400 co); 2433 namecache_cache_continuation,
2401 GNUNET_CONTAINER_DLL_insert(co_head, 2434 co);
2402 co_tail, 2435 GNUNET_CONTAINER_DLL_insert (co_head,
2403 co); 2436 co_tail,
2437 co);
2404} 2438}
2405 2439
2406 2440
@@ -2411,30 +2445,32 @@ handle_dht_response(void *cls,
2411 * @param query key to use in the DHT lookup 2445 * @param query key to use in the DHT lookup
2412 */ 2446 */
2413static void 2447static void
2414start_dht_request(struct GNS_ResolverHandle *rh, 2448start_dht_request (struct GNS_ResolverHandle *rh,
2415 const struct GNUNET_HashCode *query) 2449 const struct GNUNET_HashCode *query)
2416{ 2450{
2417 struct GNS_ResolverHandle *rx; 2451 struct GNS_ResolverHandle *rx;
2418 2452
2419 GNUNET_assert(NULL == rh->get_handle); 2453 GNUNET_assert (NULL == rh->get_handle);
2420 rh->get_handle = GNUNET_DHT_get_start(dht_handle, 2454 rh->get_handle = GNUNET_DHT_get_start (dht_handle,
2421 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 2455 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
2422 query, 2456 query,
2423 DHT_GNS_REPLICATION_LEVEL, 2457 DHT_GNS_REPLICATION_LEVEL,
2424 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 2458 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
2425 NULL, 0, 2459 NULL, 0,
2426 &handle_dht_response, rh); 2460 &handle_dht_response, rh);
2427 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert(dht_lookup_heap, 2461 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
2428 rh, 2462 rh,
2429 GNUNET_TIME_absolute_get().abs_value_us); 2463 GNUNET_TIME_absolute_get ().
2430 if (GNUNET_CONTAINER_heap_get_size(dht_lookup_heap) > max_allowed_background_queries) 2464 abs_value_us);
2431 { 2465 if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) >
2432 /* fail longest-standing DHT request */ 2466 max_allowed_background_queries)
2433 rx = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap); 2467 {
2434 rx->dht_heap_node = NULL; 2468 /* fail longest-standing DHT request */
2435 GNUNET_assert(NULL != rx); 2469 rx = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
2436 fail_resolution(rx); 2470 rx->dht_heap_node = NULL;
2437 } 2471 GNUNET_assert (NULL != rx);
2472 fail_resolution (rx);
2473 }
2438} 2474}
2439 2475
2440 2476
@@ -2447,19 +2483,19 @@ start_dht_request(struct GNS_ResolverHandle *rh,
2447 * @param rd array of records with data to store 2483 * @param rd array of records with data to store
2448 */ 2484 */
2449static void 2485static void
2450handle_gns_namecache_resolution_result(void *cls, 2486handle_gns_namecache_resolution_result (void *cls,
2451 unsigned int rd_count, 2487 unsigned int rd_count,
2452 const struct GNUNET_GNSRECORD_Data *rd) 2488 const struct GNUNET_GNSRECORD_Data *rd)
2453{ 2489{
2454 struct GNS_ResolverHandle *rh = cls; 2490 struct GNS_ResolverHandle *rh = cls;
2455 2491
2456 if (0 == rd_count) 2492 if (0 == rd_count)
2457 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2458 _("GNS namecache returned empty result for `%s'\n"), 2494 _ ("GNS namecache returned empty result for `%s'\n"),
2459 rh->name); 2495 rh->name);
2460 handle_gns_resolution_result(rh, 2496 handle_gns_resolution_result (rh,
2461 rd_count, 2497 rd_count,
2462 rd); 2498 rd);
2463} 2499}
2464 2500
2465 2501
@@ -2470,71 +2506,76 @@ handle_gns_namecache_resolution_result(void *cls,
2470 * @param block block that was stored in the namecache 2506 * @param block block that was stored in the namecache
2471 */ 2507 */
2472static void 2508static void
2473handle_namecache_block_response(void *cls, 2509handle_namecache_block_response (void *cls,
2474 const struct GNUNET_GNSRECORD_Block *block) 2510 const struct GNUNET_GNSRECORD_Block *block)
2475{ 2511{
2476 struct GNS_ResolverHandle *rh = cls; 2512 struct GNS_ResolverHandle *rh = cls;
2477 struct AuthorityChain *ac = rh->ac_tail; 2513 struct AuthorityChain *ac = rh->ac_tail;
2478 const char *label = ac->label; 2514 const char *label = ac->label;
2479 const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; 2515 const struct GNUNET_CRYPTO_EcdsaPublicKey *auth =
2516 &ac->authority_info.gns_authority;
2480 struct GNUNET_HashCode query; 2517 struct GNUNET_HashCode query;
2481 2518
2482 GNUNET_assert(NULL != rh->namecache_qe); 2519 GNUNET_assert (NULL != rh->namecache_qe);
2483 rh->namecache_qe = NULL; 2520 rh->namecache_qe = NULL;
2484 if (((GNUNET_GNS_LO_DEFAULT == rh->options) || 2521 if (((GNUNET_GNS_LO_DEFAULT == rh->options) ||
2485 ((GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && 2522 ((GNUNET_GNS_LO_LOCAL_MASTER == rh->options) &&
2486 (ac != rh->ac_head))) && 2523 (ac != rh->ac_head))) &&
2487 ((NULL == block) || 2524 ((NULL == block) ||
2488 (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us))) 2525 (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (
2489 { 2526 block->expiration_time)).
2490 /* namecache knows nothing; try DHT lookup */ 2527 rel_value_us)))
2491 GNUNET_GNSRECORD_query_from_public_key(auth, 2528 {
2492 label, 2529 /* namecache knows nothing; try DHT lookup */
2493 &query); 2530 GNUNET_GNSRECORD_query_from_public_key (auth,
2494 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2531 label,
2495 "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", 2532 &query);
2496 ac->label, 2533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2497 GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority), 2534 "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
2498 GNUNET_h2s(&query)); 2535 ac->label,
2499 start_dht_request(rh, &query); 2536 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
2500 return; 2537 GNUNET_h2s (&query));
2501 } 2538 start_dht_request (rh, &query);
2539 return;
2540 }
2502 2541
2503 if ((NULL == block) || 2542 if ((NULL == block) ||
2504 (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us)) 2543 (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (
2505 { 2544 block->expiration_time)).
2506 /* DHT not permitted and no local result, fail */ 2545 rel_value_us))
2507 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2546 {
2508 "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n", 2547 /* DHT not permitted and no local result, fail */
2509 ac->label, 2548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2510 GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); 2549 "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n",
2511 fail_resolution(rh); 2550 ac->label,
2512 return; 2551 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2513 } 2552 fail_resolution (rh);
2514 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2553 return;
2515 "Received result from namecache for label `%s'\n", 2554 }
2516 ac->label); 2555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2556 "Received result from namecache for label `%s'\n",
2557 ac->label);
2517 2558
2518 if (GNUNET_OK != 2559 if (GNUNET_OK !=
2519 GNUNET_GNSRECORD_block_decrypt(block, 2560 GNUNET_GNSRECORD_block_decrypt (block,
2520 auth, 2561 auth,
2521 label, 2562 label,
2522 &handle_gns_namecache_resolution_result, 2563 &handle_gns_namecache_resolution_result,
2523 rh)) 2564 rh))
2524 { 2565 {
2525 GNUNET_break_op(0); /* block was ill-formed */ 2566 GNUNET_break_op (0); /* block was ill-formed */
2526 /* try DHT instead */ 2567 /* try DHT instead */
2527 GNUNET_GNSRECORD_query_from_public_key(auth, 2568 GNUNET_GNSRECORD_query_from_public_key (auth,
2528 label, 2569 label,
2529 &query); 2570 &query);
2530 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2531 "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", 2572 "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
2532 ac->label, 2573 ac->label,
2533 GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority), 2574 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
2534 GNUNET_h2s(&query)); 2575 GNUNET_h2s (&query));
2535 start_dht_request(rh, &query); 2576 start_dht_request (rh, &query);
2536 return; 2577 return;
2537 } 2578 }
2538} 2579}
2539 2580
2540 2581
@@ -2544,32 +2585,32 @@ handle_namecache_block_response(void *cls,
2544 * @param rh query we are processing 2585 * @param rh query we are processing
2545 */ 2586 */
2546static void 2587static void
2547recursive_gns_resolution_namecache(struct GNS_ResolverHandle *rh) 2588recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh)
2548{ 2589{
2549 struct AuthorityChain *ac = rh->ac_tail; 2590 struct AuthorityChain *ac = rh->ac_tail;
2550 struct GNUNET_HashCode query; 2591 struct GNUNET_HashCode query;
2551 2592
2552 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2553 "Starting GNS resolution for `%s' in zone %s\n", 2594 "Starting GNS resolution for `%s' in zone %s\n",
2554 ac->label, 2595 ac->label,
2555 GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); 2596 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2556 GNUNET_GNSRECORD_query_from_public_key(&ac->authority_info.gns_authority, 2597 GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority,
2557 ac->label, 2598 ac->label,
2558 &query); 2599 &query);
2559 if (GNUNET_YES != disable_cache) 2600 if (GNUNET_YES != disable_cache)
2560 { 2601 {
2561 rh->namecache_qe 2602 rh->namecache_qe
2562 = GNUNET_NAMECACHE_lookup_block(namecache_handle, 2603 = GNUNET_NAMECACHE_lookup_block (namecache_handle,
2563 &query, 2604 &query,
2564 &handle_namecache_block_response, 2605 &handle_namecache_block_response,
2565 rh); 2606 rh);
2566 GNUNET_assert(NULL != rh->namecache_qe); 2607 GNUNET_assert (NULL != rh->namecache_qe);
2567 } 2608 }
2568 else 2609 else
2569 { 2610 {
2570 start_dht_request(rh, 2611 start_dht_request (rh,
2571 &query); 2612 &query);
2572 } 2613 }
2573} 2614}
2574 2615
2575 2616
@@ -2580,22 +2621,22 @@ recursive_gns_resolution_namecache(struct GNS_ResolverHandle *rh)
2580 * @param is_valid #GNUNET_YES if the zone was not yet revoked 2621 * @param is_valid #GNUNET_YES if the zone was not yet revoked
2581 */ 2622 */
2582static void 2623static void
2583handle_revocation_result(void *cls, 2624handle_revocation_result (void *cls,
2584 int is_valid) 2625 int is_valid)
2585{ 2626{
2586 struct GNS_ResolverHandle *rh = cls; 2627 struct GNS_ResolverHandle *rh = cls;
2587 struct AuthorityChain *ac = rh->ac_tail; 2628 struct AuthorityChain *ac = rh->ac_tail;
2588 2629
2589 rh->rev_check = NULL; 2630 rh->rev_check = NULL;
2590 if (GNUNET_YES != is_valid) 2631 if (GNUNET_YES != is_valid)
2591 { 2632 {
2592 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2633 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2593 _("Zone %s was revoked, resolution fails\n"), 2634 _ ("Zone %s was revoked, resolution fails\n"),
2594 GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); 2635 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2595 fail_resolution(rh); 2636 fail_resolution (rh);
2596 return; 2637 return;
2597 } 2638 }
2598 recursive_gns_resolution_namecache(rh); 2639 recursive_gns_resolution_namecache (rh);
2599} 2640}
2600 2641
2601 2642
@@ -2605,18 +2646,18 @@ handle_revocation_result(void *cls,
2605 * @param rh query we are processing 2646 * @param rh query we are processing
2606 */ 2647 */
2607static void 2648static void
2608recursive_gns_resolution_revocation(struct GNS_ResolverHandle *rh) 2649recursive_gns_resolution_revocation (struct GNS_ResolverHandle *rh)
2609{ 2650{
2610 struct AuthorityChain *ac = rh->ac_tail; 2651 struct AuthorityChain *ac = rh->ac_tail;
2611 2652
2612 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2613 "Starting revocation check for zone %s\n", 2654 "Starting revocation check for zone %s\n",
2614 GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); 2655 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2615 rh->rev_check = GNUNET_REVOCATION_query(cfg, 2656 rh->rev_check = GNUNET_REVOCATION_query (cfg,
2616 &ac->authority_info.gns_authority, 2657 &ac->authority_info.gns_authority,
2617 &handle_revocation_result, 2658 &handle_revocation_result,
2618 rh); 2659 rh);
2619 GNUNET_assert(NULL != rh->rev_check); 2660 GNUNET_assert (NULL != rh->rev_check);
2620} 2661}
2621 2662
2622 2663
@@ -2626,23 +2667,23 @@ recursive_gns_resolution_revocation(struct GNS_ResolverHandle *rh)
2626 * @param cls the `struct GNS_ResolverHandle` of the resolution 2667 * @param cls the `struct GNS_ResolverHandle` of the resolution
2627 */ 2668 */
2628static void 2669static void
2629recursive_resolution(void *cls) 2670recursive_resolution (void *cls)
2630{ 2671{
2631 struct GNS_ResolverHandle *rh = cls; 2672 struct GNS_ResolverHandle *rh = cls;
2632 2673
2633 rh->task_id = NULL; 2674 rh->task_id = NULL;
2634 if (MAX_RECURSION < rh->loop_limiter++) 2675 if (MAX_RECURSION < rh->loop_limiter++)
2635 { 2676 {
2636 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2677 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2637 "Encountered unbounded recursion resolving `%s'\n", 2678 "Encountered unbounded recursion resolving `%s'\n",
2638 rh->name); 2679 rh->name);
2639 fail_resolution(rh); 2680 fail_resolution (rh);
2640 return; 2681 return;
2641 } 2682 }
2642 if (GNUNET_YES == rh->ac_tail->gns_authority) 2683 if (GNUNET_YES == rh->ac_tail->gns_authority)
2643 recursive_gns_resolution_revocation(rh); 2684 recursive_gns_resolution_revocation (rh);
2644 else 2685 else
2645 recursive_dns_resolution(rh); 2686 recursive_dns_resolution (rh);
2646} 2687}
2647 2688
2648 2689
@@ -2653,7 +2694,7 @@ recursive_resolution(void *cls)
2653 * @param cls the `struct GNS_ResolverHandle` 2694 * @param cls the `struct GNS_ResolverHandle`
2654 */ 2695 */
2655static void 2696static void
2656start_resolver_lookup(void *cls) 2697start_resolver_lookup (void *cls)
2657{ 2698{
2658 struct GNS_ResolverHandle *rh = cls; 2699 struct GNS_ResolverHandle *rh = cls;
2659 struct AuthorityChain *ac; 2700 struct AuthorityChain *ac;
@@ -2661,61 +2702,61 @@ start_resolver_lookup(void *cls)
2661 struct in6_addr v6; 2702 struct in6_addr v6;
2662 2703
2663 rh->task_id = NULL; 2704 rh->task_id = NULL;
2664 if (1 == inet_pton(AF_INET, 2705 if (1 == inet_pton (AF_INET,
2665 rh->name, 2706 rh->name,
2666 &v4)) 2707 &v4))
2667 { 2708 {
2668 /* name is IPv4 address, pretend it's an A record */ 2709 /* name is IPv4 address, pretend it's an A record */
2669 struct GNUNET_GNSRECORD_Data rd; 2710 struct GNUNET_GNSRECORD_Data rd;
2670 2711
2671 rd.data = &v4; 2712 rd.data = &v4;
2672 rd.data_size = sizeof(v4); 2713 rd.data_size = sizeof(v4);
2673 rd.expiration_time = UINT64_MAX; 2714 rd.expiration_time = UINT64_MAX;
2674 rd.record_type = GNUNET_DNSPARSER_TYPE_A; 2715 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
2675 rd.flags = 0; 2716 rd.flags = 0;
2676 rh->proc(rh->proc_cls, 2717 rh->proc (rh->proc_cls,
2677 1, 2718 1,
2678 &rd); 2719 &rd);
2679 GNUNET_assert(NULL == rh->task_id); 2720 GNUNET_assert (NULL == rh->task_id);
2680 rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, 2721 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2681 rh); 2722 rh);
2682 return; 2723 return;
2683 } 2724 }
2684 if (1 == inet_pton(AF_INET6, 2725 if (1 == inet_pton (AF_INET6,
2685 rh->name, 2726 rh->name,
2686 &v6)) 2727 &v6))
2687 { 2728 {
2688 /* name is IPv6 address, pretend it's an AAAA record */ 2729 /* name is IPv6 address, pretend it's an AAAA record */
2689 struct GNUNET_GNSRECORD_Data rd; 2730 struct GNUNET_GNSRECORD_Data rd;
2690 2731
2691 rd.data = &v6; 2732 rd.data = &v6;
2692 rd.data_size = sizeof(v6); 2733 rd.data_size = sizeof(v6);
2693 rd.expiration_time = UINT64_MAX; 2734 rd.expiration_time = UINT64_MAX;
2694 rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; 2735 rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA;
2695 rd.flags = 0; 2736 rd.flags = 0;
2696 rh->proc(rh->proc_cls, 2737 rh->proc (rh->proc_cls,
2697 1, 2738 1,
2698 &rd); 2739 &rd);
2699 GNUNET_assert(NULL == rh->task_id); 2740 GNUNET_assert (NULL == rh->task_id);
2700 rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, 2741 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2701 rh); 2742 rh);
2702 return; 2743 return;
2703 } 2744 }
2704 2745
2705 ac = GNUNET_new(struct AuthorityChain); 2746 ac = GNUNET_new (struct AuthorityChain);
2706 ac->rh = rh; 2747 ac->rh = rh;
2707 ac->label = resolver_lookup_get_next_label(rh); 2748 ac->label = resolver_lookup_get_next_label (rh);
2708 if (NULL == ac->label) 2749 if (NULL == ac->label)
2709 /* name was just the "TLD", so we default to label 2750 /* name was just the "TLD", so we default to label
2710 #GNUNET_GNS_EMPTY_LABEL_AT */ 2751 #GNUNET_GNS_EMPTY_LABEL_AT */
2711 ac->label = GNUNET_strdup(GNUNET_GNS_EMPTY_LABEL_AT); 2752 ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT);
2712 ac->gns_authority = GNUNET_YES; 2753 ac->gns_authority = GNUNET_YES;
2713 ac->authority_info.gns_authority = rh->authority_zone; 2754 ac->authority_info.gns_authority = rh->authority_zone;
2714 GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, 2755 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
2715 rh->ac_tail, 2756 rh->ac_tail,
2716 ac); 2757 ac);
2717 rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, 2758 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
2718 rh); 2759 rh);
2719} 2760}
2720 2761
2721 2762
@@ -2732,31 +2773,31 @@ start_resolver_lookup(void *cls)
2732 * @return handle to cancel operation 2773 * @return handle to cancel operation
2733 */ 2774 */
2734struct GNS_ResolverHandle * 2775struct GNS_ResolverHandle *
2735GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, 2776GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2736 uint32_t record_type, 2777 uint32_t record_type,
2737 const char *name, 2778 const char *name,
2738 enum GNUNET_GNS_LocalOptions options, 2779 enum GNUNET_GNS_LocalOptions options,
2739 GNS_ResultProcessor proc, 2780 GNS_ResultProcessor proc,
2740 void *proc_cls) 2781 void *proc_cls)
2741{ 2782{
2742 struct GNS_ResolverHandle *rh; 2783 struct GNS_ResolverHandle *rh;
2743 2784
2744 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2745 "Starting lookup for `%s'\n", 2786 "Starting lookup for `%s'\n",
2746 name); 2787 name);
2747 rh = GNUNET_new(struct GNS_ResolverHandle); 2788 rh = GNUNET_new (struct GNS_ResolverHandle);
2748 GNUNET_CONTAINER_DLL_insert(rlh_head, 2789 GNUNET_CONTAINER_DLL_insert (rlh_head,
2749 rlh_tail, 2790 rlh_tail,
2750 rh); 2791 rh);
2751 rh->authority_zone = *zone; 2792 rh->authority_zone = *zone;
2752 rh->proc = proc; 2793 rh->proc = proc;
2753 rh->proc_cls = proc_cls; 2794 rh->proc_cls = proc_cls;
2754 rh->options = options; 2795 rh->options = options;
2755 rh->record_type = record_type; 2796 rh->record_type = record_type;
2756 rh->name = GNUNET_strdup(name); 2797 rh->name = GNUNET_strdup (name);
2757 rh->name_resolution_pos = strlen(name); 2798 rh->name_resolution_pos = strlen (name);
2758 rh->task_id = GNUNET_SCHEDULER_add_now(&start_resolver_lookup, 2799 rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
2759 rh); 2800 rh);
2760 return rh; 2801 return rh;
2761} 2802}
2762 2803
@@ -2767,107 +2808,108 @@ GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2767 * @param rh resolution to abort 2808 * @param rh resolution to abort
2768 */ 2809 */
2769void 2810void
2770GNS_resolver_lookup_cancel(struct GNS_ResolverHandle *rh) 2811GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
2771{ 2812{
2772 struct DnsResult *dr; 2813 struct DnsResult *dr;
2773 struct AuthorityChain *ac; 2814 struct AuthorityChain *ac;
2774 struct VpnContext *vpn_ctx; 2815 struct VpnContext *vpn_ctx;
2775 2816
2776 GNUNET_CONTAINER_DLL_remove(rlh_head, 2817 GNUNET_CONTAINER_DLL_remove (rlh_head,
2777 rlh_tail, 2818 rlh_tail,
2778 rh); 2819 rh);
2779 if (NULL != rh->dns_request) 2820 if (NULL != rh->dns_request)
2780 { 2821 {
2781 GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); 2822 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
2782 rh->dns_request = NULL; 2823 rh->dns_request = NULL;
2783 } 2824 }
2784 while (NULL != (ac = rh->ac_head)) 2825 while (NULL != (ac = rh->ac_head))
2826 {
2827 GNUNET_CONTAINER_DLL_remove (rh->ac_head,
2828 rh->ac_tail,
2829 ac);
2830 if (GNUNET_NO == ac->gns_authority)
2785 { 2831 {
2786 GNUNET_CONTAINER_DLL_remove(rh->ac_head, 2832 struct Gns2DnsPending *gp;
2787 rh->ac_tail,
2788 ac);
2789 if (GNUNET_NO == ac->gns_authority)
2790 {
2791 struct Gns2DnsPending *gp;
2792 2833
2793 while (NULL != (gp = ac->authority_info.dns_authority.gp_head)) 2834 while (NULL != (gp = ac->authority_info.dns_authority.gp_head))
2794 { 2835 {
2795 GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, 2836 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
2796 ac->authority_info.dns_authority.gp_tail, 2837 ac->authority_info.dns_authority.gp_tail,
2797 gp); 2838 gp);
2798 if (NULL != gp->rh) 2839 if (NULL != gp->rh)
2799 { 2840 {
2800 /* rh->g2dc->rh is NOT in the DLL yet, so to enable us 2841 /* rh->g2dc->rh is NOT in the DLL yet, so to enable us
2801 using GNS_resolver_lookup_cancel here, we need to 2842 using GNS_resolver_lookup_cancel here, we need to
2802 add it first... */ 2843 add it first... */
2803 GNUNET_CONTAINER_DLL_insert(rlh_head, 2844 GNUNET_CONTAINER_DLL_insert (rlh_head,
2804 rlh_tail, 2845 rlh_tail,
2805 gp->rh); 2846 gp->rh);
2806 GNUNET_assert(NULL == gp->rh->task_id); 2847 GNUNET_assert (NULL == gp->rh->task_id);
2807 gp->rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, 2848 gp->rh->task_id = GNUNET_SCHEDULER_add_now (
2808 gp->rh); 2849 &GNS_resolver_lookup_cancel_,
2809 gp->rh = NULL; 2850 gp->rh);
2810 } 2851 gp->rh = NULL;
2811 if (NULL != gp->dns_rh)
2812 {
2813 GNUNET_RESOLVER_request_cancel(gp->dns_rh);
2814 gp->dns_rh = NULL;
2815 }
2816 GNUNET_free(gp);
2817 }
2818 GNUNET_DNSSTUB_stop(ac->authority_info.dns_authority.dns_handle);
2819 } 2852 }
2820 GNUNET_free(ac->label); 2853 if (NULL != gp->dns_rh)
2821 GNUNET_free(ac); 2854 {
2855 GNUNET_RESOLVER_request_cancel (gp->dns_rh);
2856 gp->dns_rh = NULL;
2857 }
2858 GNUNET_free (gp);
2859 }
2860 GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle);
2822 } 2861 }
2862 GNUNET_free (ac->label);
2863 GNUNET_free (ac);
2864 }
2823 if (NULL != rh->task_id) 2865 if (NULL != rh->task_id)
2824 { 2866 {
2825 GNUNET_SCHEDULER_cancel(rh->task_id); 2867 GNUNET_SCHEDULER_cancel (rh->task_id);
2826 rh->task_id = NULL; 2868 rh->task_id = NULL;
2827 } 2869 }
2828 if (NULL != rh->get_handle) 2870 if (NULL != rh->get_handle)
2829 { 2871 {
2830 GNUNET_DHT_get_stop(rh->get_handle); 2872 GNUNET_DHT_get_stop (rh->get_handle);
2831 rh->get_handle = NULL; 2873 rh->get_handle = NULL;
2832 } 2874 }
2833 if (NULL != rh->dht_heap_node) 2875 if (NULL != rh->dht_heap_node)
2834 { 2876 {
2835 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); 2877 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
2836 rh->dht_heap_node = NULL; 2878 rh->dht_heap_node = NULL;
2837 } 2879 }
2838 if (NULL != (vpn_ctx = rh->vpn_ctx)) 2880 if (NULL != (vpn_ctx = rh->vpn_ctx))
2839 { 2881 {
2840 GNUNET_VPN_cancel_request(vpn_ctx->vpn_request); 2882 GNUNET_VPN_cancel_request (vpn_ctx->vpn_request);
2841 GNUNET_free(vpn_ctx->rd_data); 2883 GNUNET_free (vpn_ctx->rd_data);
2842 GNUNET_free(vpn_ctx); 2884 GNUNET_free (vpn_ctx);
2843 } 2885 }
2844 if (NULL != rh->namecache_qe) 2886 if (NULL != rh->namecache_qe)
2845 { 2887 {
2846 GNUNET_NAMECACHE_cancel(rh->namecache_qe); 2888 GNUNET_NAMECACHE_cancel (rh->namecache_qe);
2847 rh->namecache_qe = NULL; 2889 rh->namecache_qe = NULL;
2848 } 2890 }
2849 if (NULL != rh->rev_check) 2891 if (NULL != rh->rev_check)
2850 { 2892 {
2851 GNUNET_REVOCATION_query_cancel(rh->rev_check); 2893 GNUNET_REVOCATION_query_cancel (rh->rev_check);
2852 rh->rev_check = NULL; 2894 rh->rev_check = NULL;
2853 } 2895 }
2854 if (NULL != rh->std_resolve) 2896 if (NULL != rh->std_resolve)
2855 { 2897 {
2856 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2857 "Canceling standard DNS resolution\n"); 2899 "Canceling standard DNS resolution\n");
2858 GNUNET_RESOLVER_request_cancel(rh->std_resolve); 2900 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
2859 rh->std_resolve = NULL; 2901 rh->std_resolve = NULL;
2860 } 2902 }
2861 while (NULL != (dr = rh->dns_result_head)) 2903 while (NULL != (dr = rh->dns_result_head))
2862 { 2904 {
2863 GNUNET_CONTAINER_DLL_remove(rh->dns_result_head, 2905 GNUNET_CONTAINER_DLL_remove (rh->dns_result_head,
2864 rh->dns_result_tail, 2906 rh->dns_result_tail,
2865 dr); 2907 dr);
2866 GNUNET_free(dr); 2908 GNUNET_free (dr);
2867 } 2909 }
2868 GNUNET_free_non_null(rh->leho); 2910 GNUNET_free_non_null (rh->leho);
2869 GNUNET_free(rh->name); 2911 GNUNET_free (rh->name);
2870 GNUNET_free(rh); 2912 GNUNET_free (rh);
2871} 2913}
2872 2914
2873 2915
@@ -2883,24 +2925,24 @@ GNS_resolver_lookup_cancel(struct GNS_ResolverHandle *rh)
2883 * @param max_bg_queries maximum number of parallel background queries in dht 2925 * @param max_bg_queries maximum number of parallel background queries in dht
2884 */ 2926 */
2885void 2927void
2886GNS_resolver_init(struct GNUNET_NAMECACHE_Handle *nc, 2928GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc,
2887 struct GNUNET_DHT_Handle *dht, 2929 struct GNUNET_DHT_Handle *dht,
2888 const struct GNUNET_CONFIGURATION_Handle *c, 2930 const struct GNUNET_CONFIGURATION_Handle *c,
2889 unsigned long long max_bg_queries) 2931 unsigned long long max_bg_queries)
2890{ 2932{
2891 cfg = c; 2933 cfg = c;
2892 namecache_handle = nc; 2934 namecache_handle = nc;
2893 dht_handle = dht; 2935 dht_handle = dht;
2894 dht_lookup_heap = 2936 dht_lookup_heap =
2895 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 2937 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2896 max_allowed_background_queries = max_bg_queries; 2938 max_allowed_background_queries = max_bg_queries;
2897 disable_cache = GNUNET_CONFIGURATION_get_value_yesno(cfg, 2939 disable_cache = GNUNET_CONFIGURATION_get_value_yesno (cfg,
2898 "namecache", 2940 "namecache",
2899 "DISABLE"); 2941 "DISABLE");
2900 if (GNUNET_YES == disable_cache) 2942 if (GNUNET_YES == disable_cache)
2901 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2943 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2902 "Namecache disabled\n"); 2944 "Namecache disabled\n");
2903 vpn_handle = GNUNET_VPN_connect(cfg); 2945 vpn_handle = GNUNET_VPN_connect (cfg);
2904} 2946}
2905 2947
2906 2948
@@ -2908,30 +2950,30 @@ GNS_resolver_init(struct GNUNET_NAMECACHE_Handle *nc,
2908 * Shutdown resolver 2950 * Shutdown resolver
2909 */ 2951 */
2910void 2952void
2911GNS_resolver_done() 2953GNS_resolver_done ()
2912{ 2954{
2913 struct GNS_ResolverHandle *rh; 2955 struct GNS_ResolverHandle *rh;
2914 struct CacheOps *co; 2956 struct CacheOps *co;
2915 2957
2916 /* abort active resolutions */ 2958 /* abort active resolutions */
2917 while (NULL != (rh = rlh_head)) 2959 while (NULL != (rh = rlh_head))
2918 { 2960 {
2919 rh->proc(rh->proc_cls, 2961 rh->proc (rh->proc_cls,
2920 0, 2962 0,
2921 NULL); 2963 NULL);
2922 GNS_resolver_lookup_cancel(rh); 2964 GNS_resolver_lookup_cancel (rh);
2923 } 2965 }
2924 while (NULL != (co = co_head)) 2966 while (NULL != (co = co_head))
2925 { 2967 {
2926 GNUNET_CONTAINER_DLL_remove(co_head, 2968 GNUNET_CONTAINER_DLL_remove (co_head,
2927 co_tail, 2969 co_tail,
2928 co); 2970 co);
2929 GNUNET_NAMECACHE_cancel(co->namecache_qe_cache); 2971 GNUNET_NAMECACHE_cancel (co->namecache_qe_cache);
2930 GNUNET_free(co); 2972 GNUNET_free (co);
2931 } 2973 }
2932 GNUNET_CONTAINER_heap_destroy(dht_lookup_heap); 2974 GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
2933 dht_lookup_heap = NULL; 2975 dht_lookup_heap = NULL;
2934 GNUNET_VPN_disconnect(vpn_handle); 2976 GNUNET_VPN_disconnect (vpn_handle);
2935 vpn_handle = NULL; 2977 vpn_handle = NULL;
2936 dht_handle = NULL; 2978 dht_handle = NULL;
2937 namecache_handle = NULL; 2979 namecache_handle = NULL;
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 8865f3c95..cc918fd90 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -39,17 +39,17 @@
39 * @param max_bg_queries maximum amount of background queries 39 * @param max_bg_queries maximum amount of background queries
40 */ 40 */
41void 41void
42GNS_resolver_init(struct GNUNET_NAMECACHE_Handle *nc, 42GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc,
43 struct GNUNET_DHT_Handle *dht, 43 struct GNUNET_DHT_Handle *dht,
44 const struct GNUNET_CONFIGURATION_Handle *c, 44 const struct GNUNET_CONFIGURATION_Handle *c,
45 unsigned long long max_bg_queries); 45 unsigned long long max_bg_queries);
46 46
47 47
48/** 48/**
49 * Cleanup resolver: Terminate pending lookups 49 * Cleanup resolver: Terminate pending lookups
50 */ 50 */
51void 51void
52GNS_resolver_done(void); 52GNS_resolver_done (void);
53 53
54 54
55/** 55/**
@@ -84,12 +84,12 @@ typedef void
84 * @return handle to cancel operation 84 * @return handle to cancel operation
85 */ 85 */
86struct GNS_ResolverHandle * 86struct GNS_ResolverHandle *
87GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, 87GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
88 uint32_t record_type, 88 uint32_t record_type,
89 const char *name, 89 const char *name,
90 enum GNUNET_GNS_LocalOptions options, 90 enum GNUNET_GNS_LocalOptions options,
91 GNS_ResultProcessor proc, 91 GNS_ResultProcessor proc,
92 void *proc_cls); 92 void *proc_cls);
93 93
94 94
95/** 95/**
@@ -98,6 +98,6 @@ GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
98 * @param rh resolution to abort 98 * @param rh resolution to abort
99 */ 99 */
100void 100void
101GNS_resolver_lookup_cancel(struct GNS_ResolverHandle *rh); 101GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh);
102 102
103#endif 103#endif
diff --git a/src/gns/gnunet_w32nsp_lib.h b/src/gns/gnunet_w32nsp_lib.h
index 0316245ff..9d19ff2aa 100644
--- a/src/gns/gnunet_w32nsp_lib.h
+++ b/src/gns/gnunet_w32nsp_lib.h
@@ -1,9 +1,10 @@
1#if !defined(GNUNET_W32NSP_LIB_H) 1#if ! defined(GNUNET_W32NSP_LIB_H)
2#define GNUNET_W32NSP_LIB_H 2#define GNUNET_W32NSP_LIB_H
3 3
4#include <basetyps.h> 4#include <basetyps.h>
5 5
6/* E0D24085-622C-4A93-9A0018-034469DE28DA */ 6/* E0D24085-622C-4A93-9A0018-034469DE28DA */
7DEFINE_GUID(GNUNET_NAMESPACE_PROVIDER_DNS, 0xE0D24085L, 0x622C, 0x4A93, 0x9A, 0x18, 0x03, 0x44, 0x69, 0xDE, 0x28, 0xDA); 7DEFINE_GUID (GNUNET_NAMESPACE_PROVIDER_DNS, 0xE0D24085L, 0x622C, 0x4A93, 0x9A,
8 0x18, 0x03, 0x44, 0x69, 0xDE, 0x28, 0xDA);
8 9
9#endif /* GNUNET_W32NSP_LIB_H */ 10#endif /* GNUNET_W32NSP_LIB_H */
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c
index 43fc030b9..beae4d15e 100644
--- a/src/gns/nss/nss_gns.c
+++ b/src/gns/nss/nss_gns.c
@@ -37,9 +37,9 @@
37 37
38/** macro to align idx to 32bit boundary */ 38/** macro to align idx to 32bit boundary */
39#define ALIGN(idx) do { \ 39#define ALIGN(idx) do { \
40 if (idx % sizeof(void*)) \ 40 if (idx % sizeof(void*)) \
41 idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ 41 idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \
42 } while (0) 42} while (0)
43 43
44 44
45/** 45/**
@@ -55,13 +55,13 @@
55 * @return a nss_status code 55 * @return a nss_status code
56 */ 56 */
57enum nss_status 57enum nss_status
58_nss_gns_gethostbyname2_r(const char *name, 58_nss_gns_gethostbyname2_r (const char *name,
59 int af, 59 int af,
60 struct hostent *result, 60 struct hostent *result,
61 char *buffer, 61 char *buffer,
62 size_t buflen, 62 size_t buflen,
63 int *errnop, 63 int *errnop,
64 int *h_errnop) 64 int *h_errnop)
65{ 65{
66 struct userdata u; 66 struct userdata u;
67 enum nss_status status = NSS_STATUS_UNAVAIL; 67 enum nss_status status = NSS_STATUS_UNAVAIL;
@@ -86,97 +86,98 @@ _nss_gns_gethostbyname2_r(const char *name,
86 if ((af != AF_INET) && 86 if ((af != AF_INET) &&
87 (af != AF_INET6)) 87 (af != AF_INET6))
88#endif 88#endif
89 { 89 {
90 *errnop = EINVAL; 90 *errnop = EINVAL;
91 *h_errnop = NO_RECOVERY; 91 *h_errnop = NO_RECOVERY;
92 92
93 goto finish; 93 goto finish;
94 } 94 }
95 95
96 address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t); 96 address_length = (af == AF_INET) ? sizeof(ipv4_address_t) :
97 sizeof(ipv6_address_t);
97 if (buflen < 98 if (buflen <
98 sizeof(char*) + /* alias names */ 99 sizeof(char*) /* alias names */
99 strlen(name) + 1) 100 + strlen (name) + 1)
100 { /* official name */ 101 { /* official name */
101 *errnop = ERANGE; 102 *errnop = ERANGE;
102 *h_errnop = NO_RECOVERY; 103 *h_errnop = NO_RECOVERY;
103 status = NSS_STATUS_TRYAGAIN; 104 status = NSS_STATUS_TRYAGAIN;
104 105
105 goto finish; 106 goto finish;
106 } 107 }
107 u.count = 0; 108 u.count = 0;
108 u.data_len = 0; 109 u.data_len = 0;
109 i = gns_resolve_name(af, 110 i = gns_resolve_name (af,
110 name, 111 name,
111 &u); 112 &u);
112 if (-1 == i) 113 if (-1 == i)
113 { 114 {
114 *errnop = errno; 115 *errnop = errno;
115 status = NSS_STATUS_UNAVAIL; 116 status = NSS_STATUS_UNAVAIL;
116 *h_errnop = NO_RECOVERY; 117 *h_errnop = NO_RECOVERY;
117 goto finish; 118 goto finish;
118 } 119 }
119 if (-2 == i) 120 if (-2 == i)
120 { 121 {
121 *errnop = ENOENT; 122 *errnop = ENOENT;
122 *h_errnop = NO_RECOVERY; 123 *h_errnop = NO_RECOVERY;
123 status = NSS_STATUS_UNAVAIL; 124 status = NSS_STATUS_UNAVAIL;
124 goto finish; 125 goto finish;
125 } 126 }
126 if (-3 == i) 127 if (-3 == i)
127 { 128 {
128 *errnop = ETIMEDOUT; 129 *errnop = ETIMEDOUT;
129 *h_errnop = HOST_NOT_FOUND; 130 *h_errnop = HOST_NOT_FOUND;
130 status = NSS_STATUS_NOTFOUND; 131 status = NSS_STATUS_NOTFOUND;
131 goto finish; 132 goto finish;
132 } 133 }
133 if (0 == u.count) 134 if (0 == u.count)
134 { 135 {
135 *errnop = 0; /* success */ 136 *errnop = 0; /* success */
136 *h_errnop = NO_DATA; /* success */ 137 *h_errnop = NO_DATA; /* success */
137 status = NSS_STATUS_NOTFOUND; 138 status = NSS_STATUS_NOTFOUND;
138 goto finish; 139 goto finish;
139 } 140 }
140 /* Alias names */ 141 /* Alias names */
141 *((char**)buffer) = NULL; 142 *((char**) buffer) = NULL;
142 result->h_aliases = (char**)buffer; 143 result->h_aliases = (char**) buffer;
143 idx = sizeof(char*); 144 idx = sizeof(char*);
144 145
145 /* Official name */ 146 /* Official name */
146 strcpy(buffer + idx, 147 strcpy (buffer + idx,
147 name); 148 name);
148 result->h_name = buffer + idx; 149 result->h_name = buffer + idx;
149 idx += strlen(name) + 1; 150 idx += strlen (name) + 1;
150 151
151 ALIGN(idx); 152 ALIGN (idx);
152 153
153 result->h_addrtype = af; 154 result->h_addrtype = af;
154 result->h_length = address_length; 155 result->h_length = address_length;
155 156
156 /* Check if there's enough space for the addresses */ 157 /* Check if there's enough space for the addresses */
157 if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1)) 158 if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1))
158 { 159 {
159 *errnop = ERANGE; 160 *errnop = ERANGE;
160 *h_errnop = NO_RECOVERY; 161 *h_errnop = NO_RECOVERY;
161 status = NSS_STATUS_TRYAGAIN; 162 status = NSS_STATUS_TRYAGAIN;
162 goto finish; 163 goto finish;
163 } 164 }
164 /* Addresses */ 165 /* Addresses */
165 astart = idx; 166 astart = idx;
166 l = u.count * address_length; 167 l = u.count * address_length;
167 if (0 != l) 168 if (0 != l)
168 memcpy(buffer + astart, 169 memcpy (buffer + astart,
169 &u.data, 170 &u.data,
170 l); 171 l);
171 /* address_length is a multiple of 32bits, so idx is still aligned 172 /* address_length is a multiple of 32bits, so idx is still aligned
172 * correctly */ 173 * correctly */
173 idx += l; 174 idx += l;
174 175
175 /* Address array address_length is always a multiple of 32bits */ 176 /* Address array address_length is always a multiple of 32bits */
176 for (i = 0; i < u.count; i++) 177 for (i = 0; i < u.count; i++)
177 ((char**)(buffer + idx))[i] = buffer + astart + address_length * i; 178 ((char**) (buffer + idx))[i] = buffer + astart + address_length * i;
178 ((char**)(buffer + idx))[i] = NULL; 179 ((char**) (buffer + idx))[i] = NULL;
179 result->h_addr_list = (char**)(buffer + idx); 180 result->h_addr_list = (char**) (buffer + idx);
180 181
181 status = NSS_STATUS_SUCCESS; 182 status = NSS_STATUS_SUCCESS;
182 183
@@ -197,20 +198,20 @@ finish:
197 * @return a nss_status code 198 * @return a nss_status code
198 */ 199 */
199enum nss_status 200enum nss_status
200_nss_gns_gethostbyname_r(const char *name, 201_nss_gns_gethostbyname_r (const char *name,
201 struct hostent *result, 202 struct hostent *result,
202 char *buffer, 203 char *buffer,
203 size_t buflen, 204 size_t buflen,
204 int *errnop, 205 int *errnop,
205 int *h_errnop) 206 int *h_errnop)
206{ 207{
207 return _nss_gns_gethostbyname2_r(name, 208 return _nss_gns_gethostbyname2_r (name,
208 AF_UNSPEC, 209 AF_UNSPEC,
209 result, 210 result,
210 buffer, 211 buffer,
211 buflen, 212 buflen,
212 errnop, 213 errnop,
213 h_errnop); 214 h_errnop);
214} 215}
215 216
216 217
@@ -229,21 +230,21 @@ _nss_gns_gethostbyname_r(const char *name,
229 * @return NSS_STATUS_UNAVAIL 230 * @return NSS_STATUS_UNAVAIL
230 */ 231 */
231enum nss_status 232enum nss_status
232_nss_gns_gethostbyaddr_r(const void* addr, 233_nss_gns_gethostbyaddr_r (const void*addr,
233 int len, 234 int len,
234 int af, 235 int af,
235 struct hostent *result, 236 struct hostent *result,
236 char *buffer, 237 char *buffer,
237 size_t buflen, 238 size_t buflen,
238 int *errnop, 239 int *errnop,
239 int *h_errnop) 240 int *h_errnop)
240{ 241{
241 (void)addr; 242 (void) addr;
242 (void)len; 243 (void) len;
243 (void)af; 244 (void) af;
244 (void)result; 245 (void) result;
245 (void)buffer; 246 (void) buffer;
246 (void)buflen; 247 (void) buflen;
247 *errnop = EINVAL; 248 *errnop = EINVAL;
248 *h_errnop = NO_RECOVERY; 249 *h_errnop = NO_RECOVERY;
249 /* NOTE we allow to leak this into DNS so no NOTFOUND */ 250 /* NOTE we allow to leak this into DNS so no NOTFOUND */
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c
index 8af618618..fb431919b 100644
--- a/src/gns/nss/nss_gns_query.c
+++ b/src/gns/nss/nss_gns_query.c
@@ -33,12 +33,12 @@
33#define TIMEOUT "5s" 33#define TIMEOUT "5s"
34 34
35static void 35static void
36kwait(pid_t chld) 36kwait (pid_t chld)
37{ 37{
38 int ret; 38 int ret;
39 39
40 kill(chld, SIGKILL); 40 kill (chld, SIGKILL);
41 waitpid(chld, &ret, 0); 41 waitpid (chld, &ret, 0);
42} 42}
43 43
44 44
@@ -55,7 +55,7 @@ kwait(pid_t chld)
55 * else 0 55 * else 0
56 */ 56 */
57int 57int
58gns_resolve_name(int af, const char *name, struct userdata *u) 58gns_resolve_name (int af, const char *name, struct userdata *u)
59{ 59{
60 FILE *p; 60 FILE *p;
61 char line[128]; 61 char line[128];
@@ -63,85 +63,85 @@ gns_resolve_name(int af, const char *name, struct userdata *u)
63 int out[2]; 63 int out[2];
64 pid_t pid; 64 pid_t pid;
65 65
66 if (0 != pipe(out)) 66 if (0 != pipe (out))
67 return -1; 67 return -1;
68 pid = fork(); 68 pid = fork ();
69 if (-1 == pid) 69 if (-1 == pid)
70 return -1; 70 return -1;
71 if (0 == pid) 71 if (0 == pid)
72 { 72 {
73 char *argv[] = { "gnunet-gns", 73 char *argv[] = { "gnunet-gns",
74 "-r", 74 "-r",
75 "-t", 75 "-t",
76 (AF_INET6 == af) ? "AAAA" : "A", 76 (AF_INET6 == af) ? "AAAA" : "A",
77 "-u", 77 "-u",
78 (char *)name, 78 (char *) name,
79 "-T", 79 "-T",
80 TIMEOUT, 80 TIMEOUT,
81 NULL }; 81 NULL };
82 82
83 (void)close(STDOUT_FILENO); 83 (void) close (STDOUT_FILENO);
84 if ((0 != close(out[0])) || 84 if ((0 != close (out[0])) ||
85 (STDOUT_FILENO != dup2(out[1], STDOUT_FILENO))) 85 (STDOUT_FILENO != dup2 (out[1], STDOUT_FILENO)))
86 _exit(1); 86 _exit (1);
87 (void)execvp("gnunet-gns", argv); 87 (void) execvp ("gnunet-gns", argv);
88 _exit(1); 88 _exit (1);
89 } 89 }
90 (void)close(out[1]); 90 (void) close (out[1]);
91 p = fdopen(out[0], "r"); 91 p = fdopen (out[0], "r");
92 if (NULL == p) 92 if (NULL == p)
93 {
94 kwait (pid);
95 return -1;
96 }
97 while (NULL != fgets (line, sizeof(line), p))
98 {
99 if (u->count >= MAX_ENTRIES)
100 break;
101 if (line[strlen (line) - 1] == '\n')
93 { 102 {
94 kwait(pid); 103 line[strlen (line) - 1] = '\0';
95 return -1; 104 if (AF_INET == af)
96 } 105 {
97 while (NULL != fgets(line, sizeof(line), p)) 106 if (inet_pton (af, line, &u->data.ipv4[u->count]))
98 { 107 {
99 if (u->count >= MAX_ENTRIES) 108 u->count++;
100 break; 109 u->data_len += sizeof(ipv4_address_t);
101 if (line[strlen(line) - 1] == '\n') 110 }
111 else
112 {
113 (void) fclose (p);
114 kwait (pid);
115 errno = EINVAL;
116 return -1;
117 }
118 }
119 else if (AF_INET6 == af)
120 {
121 if (inet_pton (af, line, &u->data.ipv6[u->count]))
122 {
123 u->count++;
124 u->data_len += sizeof(ipv6_address_t);
125 }
126 else
102 { 127 {
103 line[strlen(line) - 1] = '\0'; 128 (void) fclose (p);
104 if (AF_INET == af) 129 kwait (pid);
105 { 130 errno = EINVAL;
106 if (inet_pton(af, line, &u->data.ipv4[u->count])) 131 return -1;
107 {
108 u->count++;
109 u->data_len += sizeof(ipv4_address_t);
110 }
111 else
112 {
113 (void)fclose(p);
114 kwait(pid);
115 errno = EINVAL;
116 return -1;
117 }
118 }
119 else if (AF_INET6 == af)
120 {
121 if (inet_pton(af, line, &u->data.ipv6[u->count]))
122 {
123 u->count++;
124 u->data_len += sizeof(ipv6_address_t);
125 }
126 else
127 {
128 (void)fclose(p);
129 kwait(pid);
130 errno = EINVAL;
131 return -1;
132 }
133 }
134 } 132 }
133 }
135 } 134 }
136 (void)fclose(p); 135 }
137 waitpid(pid, &ret, 0); 136 (void) fclose (p);
138 if (!WIFEXITED(ret)) 137 waitpid (pid, &ret, 0);
138 if (! WIFEXITED (ret))
139 return -1; 139 return -1;
140 if (4 == WEXITSTATUS(ret)) 140 if (4 == WEXITSTATUS (ret))
141 return -2; /* not for GNS */ 141 return -2; /* not for GNS */
142 if (3 == ret) 142 if (3 == ret)
143 return -3; /* timeout -> not found */ 143 return -3; /* timeout -> not found */
144 if ((2 == WEXITSTATUS(ret)) || (1 == WEXITSTATUS(ret))) 144 if ((2 == WEXITSTATUS (ret)) || (1 == WEXITSTATUS (ret)))
145 return -2; /* launch failure -> service unavailable */ 145 return -2; /* launch failure -> service unavailable */
146 return 0; 146 return 0;
147} 147}
diff --git a/src/gns/nss/nss_gns_query.h b/src/gns/nss/nss_gns_query.h
index 1901dd6c4..43bf21646 100644
--- a/src/gns/nss/nss_gns_query.h
+++ b/src/gns/nss/nss_gns_query.h
@@ -28,20 +28,24 @@
28/* Maximum number of entries to return */ 28/* Maximum number of entries to return */
29#define MAX_ENTRIES 16 29#define MAX_ENTRIES 16
30 30
31typedef struct { 31typedef struct
32{
32 uint32_t address; 33 uint32_t address;
33} ipv4_address_t; 34} ipv4_address_t;
34 35
35 36
36typedef struct { 37typedef struct
38{
37 uint8_t address[16]; 39 uint8_t address[16];
38} ipv6_address_t; 40} ipv6_address_t;
39 41
40 42
41struct userdata { 43struct userdata
44{
42 int count; 45 int count;
43 int data_len; /* only valid when doing reverse lookup */ 46 int data_len; /* only valid when doing reverse lookup */
44 union { 47 union
48 {
45 ipv4_address_t ipv4[MAX_ENTRIES]; 49 ipv4_address_t ipv4[MAX_ENTRIES];
46 ipv6_address_t ipv6[MAX_ENTRIES]; 50 ipv6_address_t ipv6[MAX_ENTRIES];
47 char *name[MAX_ENTRIES]; 51 char *name[MAX_ENTRIES];
@@ -62,8 +66,8 @@ struct userdata {
62 * else 0 66 * else 0
63 */ 67 */
64int 68int
65gns_resolve_name(int af, 69gns_resolve_name (int af,
66 const char *name, 70 const char *name,
67 struct userdata *userdata); 71 struct userdata *userdata);
68 72
69#endif 73#endif
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index 71cd78a8e..f4f5f906c 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -56,37 +56,38 @@
56 * by this @a type of block (this is not an error) 56 * by this @a type of block (this is not an error)
57 */ 57 */
58static struct GNUNET_BLOCK_Group * 58static struct GNUNET_BLOCK_Group *
59block_plugin_gns_create_group(void *cls, 59block_plugin_gns_create_group (void *cls,
60 enum GNUNET_BLOCK_Type type, 60 enum GNUNET_BLOCK_Type type,
61 uint32_t nonce, 61 uint32_t nonce,
62 const void *raw_data, 62 const void *raw_data,
63 size_t raw_data_size, 63 size_t raw_data_size,
64 va_list va) 64 va_list va)
65{ 65{
66 unsigned int bf_size; 66 unsigned int bf_size;
67 const char *guard; 67 const char *guard;
68 68
69 guard = va_arg(va, const char *); 69 guard = va_arg (va, const char *);
70 if (0 == strcmp(guard, 70 if (0 == strcmp (guard,
71 "seen-set-size")) 71 "seen-set-size"))
72 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), 72 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned
73 BLOOMFILTER_K); 73 int),
74 else if (0 == strcmp(guard, 74 BLOOMFILTER_K);
75 "filter-size")) 75 else if (0 == strcmp (guard,
76 bf_size = va_arg(va, unsigned int); 76 "filter-size"))
77 bf_size = va_arg (va, unsigned int);
77 else 78 else
78 { 79 {
79 GNUNET_break(0); 80 GNUNET_break (0);
80 bf_size = GNS_BF_SIZE; 81 bf_size = GNS_BF_SIZE;
81 } 82 }
82 GNUNET_break(NULL == va_arg(va, const char *)); 83 GNUNET_break (NULL == va_arg (va, const char *));
83 return GNUNET_BLOCK_GROUP_bf_create(cls, 84 return GNUNET_BLOCK_GROUP_bf_create (cls,
84 bf_size, 85 bf_size,
85 BLOOMFILTER_K, 86 BLOOMFILTER_K,
86 type, 87 type,
87 nonce, 88 nonce,
88 raw_data, 89 raw_data,
89 raw_data_size); 90 raw_data_size);
90} 91}
91 92
92 93
@@ -110,16 +111,16 @@ block_plugin_gns_create_group(void *cls,
110 * @return characterization of result 111 * @return characterization of result
111 */ 112 */
112static enum GNUNET_BLOCK_EvaluationResult 113static enum GNUNET_BLOCK_EvaluationResult
113block_plugin_gns_evaluate(void *cls, 114block_plugin_gns_evaluate (void *cls,
114 struct GNUNET_BLOCK_Context *ctx, 115 struct GNUNET_BLOCK_Context *ctx,
115 enum GNUNET_BLOCK_Type type, 116 enum GNUNET_BLOCK_Type type,
116 struct GNUNET_BLOCK_Group *bg, 117 struct GNUNET_BLOCK_Group *bg,
117 enum GNUNET_BLOCK_EvaluationOptions eo, 118 enum GNUNET_BLOCK_EvaluationOptions eo,
118 const struct GNUNET_HashCode *query, 119 const struct GNUNET_HashCode *query,
119 const void *xquery, 120 const void *xquery,
120 size_t xquery_size, 121 size_t xquery_size,
121 const void *reply_block, 122 const void *reply_block,
122 size_t reply_block_size) 123 size_t reply_block_size)
123{ 124{
124 const struct GNUNET_GNSRECORD_Block *block; 125 const struct GNUNET_GNSRECORD_Block *block;
125 struct GNUNET_HashCode h; 126 struct GNUNET_HashCode h;
@@ -128,48 +129,50 @@ block_plugin_gns_evaluate(void *cls,
128 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 129 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
129 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 130 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
130 if (NULL == reply_block) 131 if (NULL == reply_block)
132 {
133 if (0 != xquery_size)
131 { 134 {
132 if (0 != xquery_size) 135 GNUNET_break_op (0);
133 { 136 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
134 GNUNET_break_op(0);
135 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
136 }
137 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
138 } 137 }
138 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
139 }
139 140
140 /* this is a reply */ 141 /* this is a reply */
141 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) 142 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block))
142 { 143 {
143 GNUNET_break_op(0); 144 GNUNET_break_op (0);
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 145 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
145 } 146 }
146 block = reply_block; 147 block = reply_block;
147 if (ntohl(block->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != 148 if (ntohl (block->purpose.size) + sizeof(struct
149 GNUNET_CRYPTO_EcdsaSignature)
150 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) !=
148 reply_block_size) 151 reply_block_size)
149 { 152 {
150 GNUNET_break_op(0); 153 GNUNET_break_op (0);
151 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 154 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
152 } 155 }
153 GNUNET_CRYPTO_hash(&block->derived_key, 156 GNUNET_CRYPTO_hash (&block->derived_key,
154 sizeof(block->derived_key), 157 sizeof(block->derived_key),
155 &h); 158 &h);
156 if (0 != GNUNET_memcmp(&h, query)) 159 if (0 != GNUNET_memcmp (&h, query))
157 { 160 {
158 GNUNET_break_op(0); 161 GNUNET_break_op (0);
159 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 162 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
160 } 163 }
161 if (GNUNET_OK != 164 if (GNUNET_OK !=
162 GNUNET_GNSRECORD_block_verify(block)) 165 GNUNET_GNSRECORD_block_verify (block))
163 { 166 {
164 GNUNET_break_op(0); 167 GNUNET_break_op (0);
165 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 168 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
166 } 169 }
167 GNUNET_CRYPTO_hash(reply_block, 170 GNUNET_CRYPTO_hash (reply_block,
168 reply_block_size, 171 reply_block_size,
169 &chash); 172 &chash);
170 if (GNUNET_YES == 173 if (GNUNET_YES ==
171 GNUNET_BLOCK_GROUP_bf_test_and_set(bg, 174 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
172 &chash)) 175 &chash))
173 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 176 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
174 return GNUNET_BLOCK_EVALUATION_OK_MORE; 177 return GNUNET_BLOCK_EVALUATION_OK_MORE;
175} 178}
@@ -187,25 +190,25 @@ block_plugin_gns_evaluate(void *cls,
187 * (or if extracting a key from a block of this type does not work) 190 * (or if extracting a key from a block of this type does not work)
188 */ 191 */
189static int 192static int
190block_plugin_gns_get_key(void *cls, 193block_plugin_gns_get_key (void *cls,
191 enum GNUNET_BLOCK_Type type, 194 enum GNUNET_BLOCK_Type type,
192 const void *reply_block, 195 const void *reply_block,
193 size_t reply_block_size, 196 size_t reply_block_size,
194 struct GNUNET_HashCode *key) 197 struct GNUNET_HashCode *key)
195{ 198{
196 const struct GNUNET_GNSRECORD_Block *block; 199 const struct GNUNET_GNSRECORD_Block *block;
197 200
198 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 201 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
199 return GNUNET_SYSERR; 202 return GNUNET_SYSERR;
200 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) 203 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block))
201 { 204 {
202 GNUNET_break_op(0); 205 GNUNET_break_op (0);
203 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 206 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
204 } 207 }
205 block = reply_block; 208 block = reply_block;
206 GNUNET_CRYPTO_hash(&block->derived_key, 209 GNUNET_CRYPTO_hash (&block->derived_key,
207 sizeof(block->derived_key), 210 sizeof(block->derived_key),
208 key); 211 key);
209 return GNUNET_OK; 212 return GNUNET_OK;
210} 213}
211 214
@@ -214,16 +217,15 @@ block_plugin_gns_get_key(void *cls,
214 * Entry point for the plugin. 217 * Entry point for the plugin.
215 */ 218 */
216void * 219void *
217libgnunet_plugin_block_gns_init(void *cls) 220libgnunet_plugin_block_gns_init (void *cls)
218{ 221{
219 static enum GNUNET_BLOCK_Type types[] = 222 static enum GNUNET_BLOCK_Type types[] = {
220 {
221 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 223 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
222 GNUNET_BLOCK_TYPE_ANY /* end of list */ 224 GNUNET_BLOCK_TYPE_ANY /* end of list */
223 }; 225 };
224 struct GNUNET_BLOCK_PluginFunctions *api; 226 struct GNUNET_BLOCK_PluginFunctions *api;
225 227
226 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); 228 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
227 api->evaluate = &block_plugin_gns_evaluate; 229 api->evaluate = &block_plugin_gns_evaluate;
228 api->get_key = &block_plugin_gns_get_key; 230 api->get_key = &block_plugin_gns_get_key;
229 api->create_group = &block_plugin_gns_create_group; 231 api->create_group = &block_plugin_gns_create_group;
@@ -236,11 +238,11 @@ libgnunet_plugin_block_gns_init(void *cls)
236 * Exit point from the plugin. 238 * Exit point from the plugin.
237 */ 239 */
238void * 240void *
239libgnunet_plugin_block_gns_done(void *cls) 241libgnunet_plugin_block_gns_done (void *cls)
240{ 242{
241 struct GNUNET_BLOCK_PluginFunctions *api = cls; 243 struct GNUNET_BLOCK_PluginFunctions *api = cls;
242 244
243 GNUNET_free(api); 245 GNUNET_free (api);
244 return NULL; 246 return NULL;
245} 247}
246 248
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 094307ea3..e0bc4fb0c 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -44,49 +44,49 @@
44 * @return NULL on error, otherwise human-readable representation of the value 44 * @return NULL on error, otherwise human-readable representation of the value
45 */ 45 */
46static char * 46static char *
47gns_value_to_string(void *cls, 47gns_value_to_string (void *cls,
48 uint32_t type, 48 uint32_t type,
49 const void *data, 49 const void *data,
50 size_t data_size) 50 size_t data_size)
51{ 51{
52 const char *cdata; 52 const char *cdata;
53 53
54 switch (type) 54 switch (type)
55 { 55 {
56 case GNUNET_GNSRECORD_TYPE_PKEY: 56 case GNUNET_GNSRECORD_TYPE_PKEY:
57 if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) 57 if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))
58 return NULL; 58 return NULL;
59 return GNUNET_CRYPTO_ecdsa_public_key_to_string(data); 59 return GNUNET_CRYPTO_ecdsa_public_key_to_string (data);
60 60
61 case GNUNET_GNSRECORD_TYPE_NICK: 61 case GNUNET_GNSRECORD_TYPE_NICK:
62 return GNUNET_strndup(data, data_size); 62 return GNUNET_strndup (data, data_size);
63 63
64 case GNUNET_GNSRECORD_TYPE_LEHO: 64 case GNUNET_GNSRECORD_TYPE_LEHO:
65 return GNUNET_strndup(data, data_size); 65 return GNUNET_strndup (data, data_size);
66 66
67 case GNUNET_GNSRECORD_TYPE_GNS2DNS: { 67 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
68 char *ns; 68 char *ns;
69 char *ip; 69 char *ip;
70 size_t off; 70 size_t off;
71 char *nstr; 71 char *nstr;
72 72
73 off = 0; 73 off = 0;
74 ns = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 74 ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
75 ip = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 75 ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
76 if ((NULL == ns) || (NULL == ip) || (off != data_size)) 76 if ((NULL == ns) || (NULL == ip) || (off != data_size))
77 { 77 {
78 GNUNET_break_op(0); 78 GNUNET_break_op (0);
79 GNUNET_free_non_null(ns); 79 GNUNET_free_non_null (ns);
80 GNUNET_free_non_null(ip); 80 GNUNET_free_non_null (ip);
81 return NULL; 81 return NULL;
82 } 82 }
83 GNUNET_asprintf(&nstr, "%s@%s", ns, ip); 83 GNUNET_asprintf (&nstr, "%s@%s", ns, ip);
84 GNUNET_free_non_null(ns); 84 GNUNET_free_non_null (ns);
85 GNUNET_free_non_null(ip); 85 GNUNET_free_non_null (ip);
86 return nstr; 86 return nstr;
87 } 87 }
88 88
89 case GNUNET_GNSRECORD_TYPE_VPN: { 89 case GNUNET_GNSRECORD_TYPE_VPN: {
90 struct GNUNET_TUN_GnsVpnRecord vpn; 90 struct GNUNET_TUN_GnsVpnRecord vpn;
91 char *vpn_str; 91 char *vpn_str;
92 92
@@ -94,16 +94,16 @@ gns_value_to_string(void *cls,
94 if ((data_size <= sizeof(vpn)) || ('\0' != cdata[data_size - 1])) 94 if ((data_size <= sizeof(vpn)) || ('\0' != cdata[data_size - 1]))
95 return NULL; /* malformed */ 95 return NULL; /* malformed */
96 /* need to memcpy for alignment */ 96 /* need to memcpy for alignment */
97 GNUNET_memcpy(&vpn, data, sizeof(vpn)); 97 GNUNET_memcpy (&vpn, data, sizeof(vpn));
98 GNUNET_asprintf(&vpn_str, 98 GNUNET_asprintf (&vpn_str,
99 "%u %s %s", 99 "%u %s %s",
100 (unsigned int)ntohs(vpn.proto), 100 (unsigned int) ntohs (vpn.proto),
101 (const char *)GNUNET_i2s_full(&vpn.peer), 101 (const char *) GNUNET_i2s_full (&vpn.peer),
102 (const char *)&cdata[sizeof(vpn)]); 102 (const char *) &cdata[sizeof(vpn)]);
103 return vpn_str; 103 return vpn_str;
104 } 104 }
105 105
106 case GNUNET_GNSRECORD_TYPE_BOX: { 106 case GNUNET_GNSRECORD_TYPE_BOX: {
107 struct GNUNET_GNSRECORD_BoxRecord box; 107 struct GNUNET_GNSRECORD_BoxRecord box;
108 uint32_t rt; 108 uint32_t rt;
109 char *box_str; 109 char *box_str;
@@ -112,26 +112,26 @@ gns_value_to_string(void *cls,
112 cdata = data; 112 cdata = data;
113 if (data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord)) 113 if (data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord))
114 return NULL; /* malformed */ 114 return NULL; /* malformed */
115 GNUNET_memcpy(&box, data, sizeof(box)); 115 GNUNET_memcpy (&box, data, sizeof(box));
116 rt = ntohl(box.record_type); 116 rt = ntohl (box.record_type);
117 ival = GNUNET_GNSRECORD_value_to_string(rt, 117 ival = GNUNET_GNSRECORD_value_to_string (rt,
118 &cdata[sizeof(box)], 118 &cdata[sizeof(box)],
119 data_size - sizeof(box)); 119 data_size - sizeof(box));
120 if (NULL == ival) 120 if (NULL == ival)
121 return NULL; /* malformed */ 121 return NULL; /* malformed */
122 GNUNET_asprintf(&box_str, 122 GNUNET_asprintf (&box_str,
123 "%u %u %u %s", 123 "%u %u %u %s",
124 (unsigned int)ntohs(box.protocol), 124 (unsigned int) ntohs (box.protocol),
125 (unsigned int)ntohs(box.service), 125 (unsigned int) ntohs (box.service),
126 (unsigned int)rt, 126 (unsigned int) rt,
127 ival); 127 ival);
128 GNUNET_free(ival); 128 GNUNET_free (ival);
129 return box_str; 129 return box_str;
130 } 130 }
131 131
132 default: 132 default:
133 return NULL; 133 return NULL;
134 } 134 }
135} 135}
136 136
137 137
@@ -147,112 +147,112 @@ gns_value_to_string(void *cls,
147 * @return #GNUNET_OK on success 147 * @return #GNUNET_OK on success
148 */ 148 */
149static int 149static int
150gns_string_to_value(void *cls, 150gns_string_to_value (void *cls,
151 uint32_t type, 151 uint32_t type,
152 const char *s, 152 const char *s,
153 void **data, 153 void **data,
154 size_t *data_size) 154 size_t *data_size)
155{ 155{
156 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 156 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
157 157
158 if (NULL == s) 158 if (NULL == s)
159 return GNUNET_SYSERR; 159 return GNUNET_SYSERR;
160 switch (type) 160 switch (type)
161 {
162 case GNUNET_GNSRECORD_TYPE_PKEY:
163 if (GNUNET_OK !=
164 GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey))
161 { 165 {
162 case GNUNET_GNSRECORD_TYPE_PKEY: 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 if (GNUNET_OK != 167 _ ("Unable to parse PKEY record `%s'\n"),
164 GNUNET_CRYPTO_ecdsa_public_key_from_string(s, strlen(s), &pkey)) 168 s);
165 { 169 return GNUNET_SYSERR;
166 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 170 }
167 _("Unable to parse PKEY record `%s'\n"), 171 *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
168 s); 172 GNUNET_memcpy (*data, &pkey, sizeof(pkey));
169 return GNUNET_SYSERR; 173 *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
170 } 174 return GNUNET_OK;
171 *data = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey); 175
172 GNUNET_memcpy(*data, &pkey, sizeof(pkey)); 176 case GNUNET_GNSRECORD_TYPE_NICK:
173 *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); 177 *data = GNUNET_strdup (s);
174 return GNUNET_OK; 178 *data_size = strlen (s);
175 179 return GNUNET_OK;
176 case GNUNET_GNSRECORD_TYPE_NICK: 180
177 *data = GNUNET_strdup(s); 181 case GNUNET_GNSRECORD_TYPE_LEHO:
178 *data_size = strlen(s); 182 *data = GNUNET_strdup (s);
179 return GNUNET_OK; 183 *data_size = strlen (s);
180 184 return GNUNET_OK;
181 case GNUNET_GNSRECORD_TYPE_LEHO: 185
182 *data = GNUNET_strdup(s); 186 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
183 *data_size = strlen(s);
184 return GNUNET_OK;
185
186 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
187 char nsbuf[514]; 187 char nsbuf[514];
188 char *cpy; 188 char *cpy;
189 char *at; 189 char *at;
190 size_t off; 190 size_t off;
191 191
192 cpy = GNUNET_strdup(s); 192 cpy = GNUNET_strdup (s);
193 at = strchr(cpy, '@'); 193 at = strchr (cpy, '@');
194 if (NULL == at) 194 if (NULL == at)
195 { 195 {
196 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 _("Unable to parse GNS2DNS record `%s'\n"), 197 _ ("Unable to parse GNS2DNS record `%s'\n"),
198 s); 198 s);
199 GNUNET_free(cpy); 199 GNUNET_free (cpy);
200 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
201 } 201 }
202 *at = '\0'; 202 *at = '\0';
203 at++; 203 at++;
204 204
205 off = 0; 205 off = 0;
206 if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name(nsbuf, 206 if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf,
207 sizeof(nsbuf), 207 sizeof(nsbuf),
208 &off, 208 &off,
209 cpy)) || 209 cpy)) ||
210 (GNUNET_OK != 210 (GNUNET_OK !=
211 GNUNET_DNSPARSER_builder_add_name(nsbuf, sizeof(nsbuf), &off, at))) 211 GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, at)))
212 { 212 {
213 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
214 _("Failed to serialize GNS2DNS record with value `%s'\n"), 214 _ ("Failed to serialize GNS2DNS record with value `%s'\n"),
215 s); 215 s);
216 GNUNET_free(cpy); 216 GNUNET_free (cpy);
217 return GNUNET_SYSERR; 217 return GNUNET_SYSERR;
218 } 218 }
219 GNUNET_free(cpy); 219 GNUNET_free (cpy);
220 *data_size = off; 220 *data_size = off;
221 *data = GNUNET_malloc(off); 221 *data = GNUNET_malloc (off);
222 GNUNET_memcpy(*data, nsbuf, off); 222 GNUNET_memcpy (*data, nsbuf, off);
223 return GNUNET_OK; 223 return GNUNET_OK;
224 } 224 }
225 225
226 case GNUNET_GNSRECORD_TYPE_VPN: { 226 case GNUNET_GNSRECORD_TYPE_VPN: {
227 struct GNUNET_TUN_GnsVpnRecord *vpn; 227 struct GNUNET_TUN_GnsVpnRecord *vpn;
228 char s_peer[103 + 1]; 228 char s_peer[103 + 1];
229 char s_serv[253 + 1]; 229 char s_serv[253 + 1];
230 unsigned int proto; 230 unsigned int proto;
231 231
232 if (3 != sscanf(s, "%u %103s %253s", &proto, s_peer, s_serv)) 232 if (3 != sscanf (s, "%u %103s %253s", &proto, s_peer, s_serv))
233 { 233 {
234 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 234 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
235 _("Unable to parse VPN record string `%s'\n"), 235 _ ("Unable to parse VPN record string `%s'\n"),
236 s); 236 s);
237 return GNUNET_SYSERR; 237 return GNUNET_SYSERR;
238 } 238 }
239 *data_size = sizeof(struct GNUNET_TUN_GnsVpnRecord) + strlen(s_serv) + 1; 239 *data_size = sizeof(struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
240 *data = vpn = GNUNET_malloc(*data_size); 240 *data = vpn = GNUNET_malloc (*data_size);
241 if (GNUNET_OK != 241 if (GNUNET_OK !=
242 GNUNET_CRYPTO_eddsa_public_key_from_string((char *)s_peer, 242 GNUNET_CRYPTO_eddsa_public_key_from_string ((char *) s_peer,
243 strlen(s_peer), 243 strlen (s_peer),
244 &vpn->peer.public_key)) 244 &vpn->peer.public_key))
245 { 245 {
246 GNUNET_free(vpn); 246 GNUNET_free (vpn);
247 *data_size = 0; 247 *data_size = 0;
248 return GNUNET_SYSERR; 248 return GNUNET_SYSERR;
249 } 249 }
250 vpn->proto = htons((uint16_t)proto); 250 vpn->proto = htons ((uint16_t) proto);
251 strcpy((char *)&vpn[1], s_serv); 251 strcpy ((char *) &vpn[1], s_serv);
252 return GNUNET_OK; 252 return GNUNET_OK;
253 } 253 }
254 254
255 case GNUNET_GNSRECORD_TYPE_BOX: { 255 case GNUNET_GNSRECORD_TYPE_BOX: {
256 struct GNUNET_GNSRECORD_BoxRecord *box; 256 struct GNUNET_GNSRECORD_BoxRecord *box;
257 size_t rest; 257 size_t rest;
258 unsigned int protocol; 258 unsigned int protocol;
@@ -261,32 +261,32 @@ gns_string_to_value(void *cls,
261 void *bval; 261 void *bval;
262 size_t bval_size; 262 size_t bval_size;
263 263
264 if (3 != sscanf(s, "%u %u %u ", &protocol, &service, &record_type)) 264 if (3 != sscanf (s, "%u %u %u ", &protocol, &service, &record_type))
265 { 265 {
266 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
267 _("Unable to parse BOX record string `%s'\n"), 267 _ ("Unable to parse BOX record string `%s'\n"),
268 s); 268 s);
269 return GNUNET_SYSERR; 269 return GNUNET_SYSERR;
270 } 270 }
271 rest = snprintf(NULL, 0, "%u %u %u ", protocol, service, record_type); 271 rest = snprintf (NULL, 0, "%u %u %u ", protocol, service, record_type);
272 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value(record_type, 272 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record_type,
273 &s[rest], 273 &s[rest],
274 &bval, 274 &bval,
275 &bval_size)) 275 &bval_size))
276 return GNUNET_SYSERR; 276 return GNUNET_SYSERR;
277 *data_size = sizeof(struct GNUNET_GNSRECORD_BoxRecord) + bval_size; 277 *data_size = sizeof(struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
278 *data = box = GNUNET_malloc(*data_size); 278 *data = box = GNUNET_malloc (*data_size);
279 box->protocol = htons(protocol); 279 box->protocol = htons (protocol);
280 box->service = htons(service); 280 box->service = htons (service);
281 box->record_type = htonl(record_type); 281 box->record_type = htonl (record_type);
282 GNUNET_memcpy(&box[1], bval, bval_size); 282 GNUNET_memcpy (&box[1], bval, bval_size);
283 GNUNET_free(bval); 283 GNUNET_free (bval);
284 return GNUNET_OK; 284 return GNUNET_OK;
285 } 285 }
286 286
287 default: 287 default:
288 return GNUNET_SYSERR; 288 return GNUNET_SYSERR;
289 } 289 }
290} 290}
291 291
292 292
@@ -294,7 +294,8 @@ gns_string_to_value(void *cls,
294 * Mapping of record type numbers to human-readable 294 * Mapping of record type numbers to human-readable
295 * record type names. 295 * record type names.
296 */ 296 */
297static struct { 297static struct
298{
298 const char *name; 299 const char *name;
299 uint32_t number; 300 uint32_t number;
300} gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, 301} gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY },
@@ -314,13 +315,13 @@ static struct {
314 * @return corresponding number, UINT32_MAX on error 315 * @return corresponding number, UINT32_MAX on error
315 */ 316 */
316static uint32_t 317static uint32_t
317gns_typename_to_number(void *cls, const char *gns_typename) 318gns_typename_to_number (void *cls, const char *gns_typename)
318{ 319{
319 unsigned int i; 320 unsigned int i;
320 321
321 i = 0; 322 i = 0;
322 while ((NULL != gns_name_map[i].name) && 323 while ((NULL != gns_name_map[i].name) &&
323 (0 != strcasecmp(gns_typename, gns_name_map[i].name))) 324 (0 != strcasecmp (gns_typename, gns_name_map[i].name)))
324 i++; 325 i++;
325 return gns_name_map[i].number; 326 return gns_name_map[i].number;
326} 327}
@@ -334,7 +335,7 @@ gns_typename_to_number(void *cls, const char *gns_typename)
334 * @return corresponding typestring, NULL on error 335 * @return corresponding typestring, NULL on error
335 */ 336 */
336static const char * 337static const char *
337gns_number_to_typename(void *cls, uint32_t type) 338gns_number_to_typename (void *cls, uint32_t type)
338{ 339{
339 unsigned int i; 340 unsigned int i;
340 341
@@ -352,11 +353,11 @@ gns_number_to_typename(void *cls, uint32_t type)
352 * @return the exported block API 353 * @return the exported block API
353 */ 354 */
354void * 355void *
355libgnunet_plugin_gnsrecord_gns_init(void *cls) 356libgnunet_plugin_gnsrecord_gns_init (void *cls)
356{ 357{
357 struct GNUNET_GNSRECORD_PluginFunctions *api; 358 struct GNUNET_GNSRECORD_PluginFunctions *api;
358 359
359 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); 360 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
360 api->value_to_string = &gns_value_to_string; 361 api->value_to_string = &gns_value_to_string;
361 api->string_to_value = &gns_string_to_value; 362 api->string_to_value = &gns_string_to_value;
362 api->typename_to_number = &gns_typename_to_number; 363 api->typename_to_number = &gns_typename_to_number;
@@ -372,11 +373,11 @@ libgnunet_plugin_gnsrecord_gns_init(void *cls)
372 * @return NULL 373 * @return NULL
373 */ 374 */
374void * 375void *
375libgnunet_plugin_gnsrecord_gns_done(void *cls) 376libgnunet_plugin_gnsrecord_gns_done (void *cls)
376{ 377{
377 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 378 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
378 379
379 GNUNET_free(api); 380 GNUNET_free (api);
380 return NULL; 381 return NULL;
381} 382}
382 383
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 2fc103ef6..cdcdd6cf8 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -65,14 +65,16 @@ static char *allow_methods;
65/** 65/**
66 * @brief struct returned by the initialization function of the plugin 66 * @brief struct returned by the initialization function of the plugin
67 */ 67 */
68struct Plugin { 68struct Plugin
69{
69 const struct GNUNET_CONFIGURATION_Handle *cfg; 70 const struct GNUNET_CONFIGURATION_Handle *cfg;
70}; 71};
71 72
72/** 73/**
73 * The request handle 74 * The request handle
74 */ 75 */
75struct RequestHandle { 76struct RequestHandle
77{
76 /** 78 /**
77 * Connection to GNS 79 * Connection to GNS
78 */ 80 */
@@ -140,36 +142,36 @@ struct RequestHandle {
140 * @param handle Handle to clean up 142 * @param handle Handle to clean up
141 */ 143 */
142static void 144static void
143cleanup_handle(void *cls) 145cleanup_handle (void *cls)
144{ 146{
145 struct RequestHandle *handle = cls; 147 struct RequestHandle *handle = cls;
146 148
147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
148 150
149 if (NULL != handle->gns_lookup) 151 if (NULL != handle->gns_lookup)
150 { 152 {
151 GNUNET_GNS_lookup_with_tld_cancel(handle->gns_lookup); 153 GNUNET_GNS_lookup_with_tld_cancel (handle->gns_lookup);
152 handle->gns_lookup = NULL; 154 handle->gns_lookup = NULL;
153 } 155 }
154 if (NULL != handle->gns) 156 if (NULL != handle->gns)
155 { 157 {
156 GNUNET_GNS_disconnect(handle->gns); 158 GNUNET_GNS_disconnect (handle->gns);
157 handle->gns = NULL; 159 handle->gns = NULL;
158 } 160 }
159 161
160 if (NULL != handle->timeout_task) 162 if (NULL != handle->timeout_task)
161 { 163 {
162 GNUNET_SCHEDULER_cancel(handle->timeout_task); 164 GNUNET_SCHEDULER_cancel (handle->timeout_task);
163 handle->timeout_task = NULL; 165 handle->timeout_task = NULL;
164 } 166 }
165 if (NULL != handle->url) 167 if (NULL != handle->url)
166 GNUNET_free(handle->url); 168 GNUNET_free (handle->url);
167 if (NULL != handle->name) 169 if (NULL != handle->name)
168 GNUNET_free(handle->name); 170 GNUNET_free (handle->name);
169 if (NULL != handle->emsg) 171 if (NULL != handle->emsg)
170 GNUNET_free(handle->emsg); 172 GNUNET_free (handle->emsg);
171 173
172 GNUNET_free(handle); 174 GNUNET_free (handle);
173} 175}
174 176
175 177
@@ -179,40 +181,40 @@ cleanup_handle(void *cls)
179 * @param cls the `struct RequestHandle` 181 * @param cls the `struct RequestHandle`
180 */ 182 */
181static void 183static void
182do_error(void *cls) 184do_error (void *cls)
183{ 185{
184 struct RequestHandle *handle = cls; 186 struct RequestHandle *handle = cls;
185 struct MHD_Response *resp; 187 struct MHD_Response *resp;
186 json_t *json_error = json_object(); 188 json_t *json_error = json_object ();
187 char *response; 189 char *response;
188 190
189 if (NULL != handle->timeout_task) 191 if (NULL != handle->timeout_task)
190 GNUNET_SCHEDULER_cancel(handle->timeout_task); 192 GNUNET_SCHEDULER_cancel (handle->timeout_task);
191 handle->timeout_task = NULL; 193 handle->timeout_task = NULL;
192 if (NULL == handle->emsg) 194 if (NULL == handle->emsg)
193 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_ERROR_UNKNOWN); 195 handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_ERROR_UNKNOWN);
194 196
195 json_object_set_new(json_error, "error", json_string(handle->emsg)); 197 json_object_set_new (json_error, "error", json_string (handle->emsg));
196 198
197 if (0 == handle->response_code) 199 if (0 == handle->response_code)
198 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 200 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
199 response = json_dumps(json_error, 0); 201 response = json_dumps (json_error, 0);
200 resp = GNUNET_REST_create_response(response); 202 resp = GNUNET_REST_create_response (response);
201 handle->proc(handle->proc_cls, resp, handle->response_code); 203 handle->proc (handle->proc_cls, resp, handle->response_code);
202 json_decref(json_error); 204 json_decref (json_error);
203 GNUNET_free(response); 205 GNUNET_free (response);
204 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 206 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
205} 207}
206 208
207 209
208static void 210static void
209do_timeout(void *cls) 211do_timeout (void *cls)
210{ 212{
211 struct RequestHandle *handle = cls; 213 struct RequestHandle *handle = cls;
212 214
213 handle->timeout_task = NULL; 215 handle->timeout_task = NULL;
214 handle->response_code = MHD_HTTP_REQUEST_TIMEOUT; 216 handle->response_code = MHD_HTTP_REQUEST_TIMEOUT;
215 do_error(handle); 217 do_error (handle);
216} 218}
217 219
218 220
@@ -225,10 +227,10 @@ do_timeout(void *cls)
225 * @param rd the records in reply 227 * @param rd the records in reply
226 */ 228 */
227static void 229static void
228handle_gns_response(void *cls, 230handle_gns_response (void *cls,
229 int was_gns, 231 int was_gns,
230 uint32_t rd_count, 232 uint32_t rd_count,
231 const struct GNUNET_GNSRECORD_Data *rd) 233 const struct GNUNET_GNSRECORD_Data *rd)
232{ 234{
233 struct RequestHandle *handle = cls; 235 struct RequestHandle *handle = cls;
234 struct MHD_Response *resp; 236 struct MHD_Response *resp;
@@ -238,22 +240,22 @@ handle_gns_response(void *cls,
238 handle->gns_lookup = NULL; 240 handle->gns_lookup = NULL;
239 241
240 if (GNUNET_NO == was_gns) 242 if (GNUNET_NO == was_gns)
241 { 243 {
242 handle->response_code = MHD_HTTP_NOT_FOUND; 244 handle->response_code = MHD_HTTP_NOT_FOUND;
243 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); 245 handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_NOT_FOUND);
244 GNUNET_SCHEDULER_add_now(&do_error, handle); 246 GNUNET_SCHEDULER_add_now (&do_error, handle);
245 return; 247 return;
246 } 248 }
247 249
248 result_obj = GNUNET_JSON_from_gnsrecord(handle->name, rd, rd_count); 250 result_obj = GNUNET_JSON_from_gnsrecord (handle->name, rd, rd_count);
249 251
250 result = json_dumps(result_obj, 0); 252 result = json_dumps (result_obj, 0);
251 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
252 resp = GNUNET_REST_create_response(result); 254 resp = GNUNET_REST_create_response (result);
253 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); 255 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
254 GNUNET_free(result); 256 GNUNET_free (result);
255 json_decref(result_obj); 257 json_decref (result_obj);
256 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 258 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
257} 259}
258 260
259 261
@@ -265,9 +267,9 @@ handle_gns_response(void *cls,
265 * @param cls the RequestHandle 267 * @param cls the RequestHandle
266 */ 268 */
267void 269void
268get_gns_cont(struct GNUNET_REST_RequestHandle *con_handle, 270get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
269 const char *url, 271 const char *url,
270 void *cls) 272 void *cls)
271{ 273{
272 struct RequestHandle *handle = cls; 274 struct RequestHandle *handle = cls;
273 struct GNUNET_HashCode key; 275 struct GNUNET_HashCode key;
@@ -276,50 +278,50 @@ get_gns_cont(struct GNUNET_REST_RequestHandle *con_handle,
276 278
277 name = NULL; 279 name = NULL;
278 handle->name = NULL; 280 handle->name = NULL;
279 if (strlen(GNUNET_REST_API_NS_GNS) < strlen(handle->url)) 281 if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url))
280 { 282 {
281 name = &handle->url[strlen(GNUNET_REST_API_NS_GNS) + 1]; 283 name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1];
282 } 284 }
283 285
284 if (NULL == name) 286 if (NULL == name)
285 { 287 {
286 handle->response_code = MHD_HTTP_NOT_FOUND; 288 handle->response_code = MHD_HTTP_NOT_FOUND;
287 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); 289 handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_NOT_FOUND);
288 GNUNET_SCHEDULER_add_now(&do_error, handle); 290 GNUNET_SCHEDULER_add_now (&do_error, handle);
289 return; 291 return;
290 } 292 }
291 if (0 >= strlen(name)) 293 if (0 >= strlen (name))
292 { 294 {
293 handle->response_code = MHD_HTTP_NOT_FOUND; 295 handle->response_code = MHD_HTTP_NOT_FOUND;
294 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); 296 handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_NOT_FOUND);
295 GNUNET_SCHEDULER_add_now(&do_error, handle); 297 GNUNET_SCHEDULER_add_now (&do_error, handle);
296 return; 298 return;
297 } 299 }
298 handle->name = GNUNET_strdup(name); 300 handle->name = GNUNET_strdup (name);
299 301
300 handle->record_type = UINT32_MAX; 302 handle->record_type = UINT32_MAX;
301 GNUNET_CRYPTO_hash(GNUNET_REST_GNS_PARAM_RECORD_TYPE, 303 GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_RECORD_TYPE,
302 strlen(GNUNET_REST_GNS_PARAM_RECORD_TYPE), 304 strlen (GNUNET_REST_GNS_PARAM_RECORD_TYPE),
303 &key); 305 &key);
304 if (GNUNET_YES == 306 if (GNUNET_YES ==
305 GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, &key)) 307 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
306 { 308 {
307 record_type = 309 record_type =
308 GNUNET_CONTAINER_multihashmap_get(con_handle->url_param_map, &key); 310 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
309 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); 311 handle->record_type = GNUNET_GNSRECORD_typename_to_number (record_type);
310 } 312 }
311 313
312 if (UINT32_MAX == handle->record_type) 314 if (UINT32_MAX == handle->record_type)
313 { 315 {
314 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; 316 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
315 } 317 }
316 318
317 handle->gns_lookup = GNUNET_GNS_lookup_with_tld(handle->gns, 319 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
318 handle->name, 320 handle->name,
319 handle->record_type, 321 handle->record_type,
320 GNUNET_NO, 322 GNUNET_NO,
321 &handle_gns_response, 323 &handle_gns_response,
322 handle); 324 handle);
323} 325}
324 326
325 327
@@ -331,18 +333,18 @@ get_gns_cont(struct GNUNET_REST_RequestHandle *con_handle,
331 * @param cls the RequestHandle 333 * @param cls the RequestHandle
332 */ 334 */
333static void 335static void
334options_cont(struct GNUNET_REST_RequestHandle *con_handle, 336options_cont (struct GNUNET_REST_RequestHandle *con_handle,
335 const char *url, 337 const char *url,
336 void *cls) 338 void *cls)
337{ 339{
338 struct MHD_Response *resp; 340 struct MHD_Response *resp;
339 struct RequestHandle *handle = cls; 341 struct RequestHandle *handle = cls;
340 342
341 //independent of path return all options 343 // independent of path return all options
342 resp = GNUNET_REST_create_response(NULL); 344 resp = GNUNET_REST_create_response (NULL);
343 MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); 345 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
344 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); 346 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
345 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 347 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
346 return; 348 return;
347} 349}
348 350
@@ -353,7 +355,7 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle,
353 * @param handle the request handle 355 * @param handle the request handle
354 */ 356 */
355static void 357static void
356init_cont(struct RequestHandle *handle) 358init_cont (struct RequestHandle *handle)
357{ 359{
358 struct GNUNET_REST_RequestHandlerError err; 360 struct GNUNET_REST_RequestHandlerError err;
359 static const struct GNUNET_REST_RequestHandler handlers[] = 361 static const struct GNUNET_REST_RequestHandler handlers[] =
@@ -362,11 +364,11 @@ init_cont(struct RequestHandle *handle)
362 GNUNET_REST_HANDLER_END }; 364 GNUNET_REST_HANDLER_END };
363 365
364 if (GNUNET_NO == 366 if (GNUNET_NO ==
365 GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) 367 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
366 { 368 {
367 handle->response_code = err.error_code; 369 handle->response_code = err.error_code;
368 GNUNET_SCHEDULER_add_now(&do_error, handle); 370 GNUNET_SCHEDULER_add_now (&do_error, handle);
369 } 371 }
370} 372}
371 373
372 374
@@ -382,30 +384,30 @@ init_cont(struct RequestHandle *handle)
382 * @return GNUNET_OK if request accepted 384 * @return GNUNET_OK if request accepted
383 */ 385 */
384static void 386static void
385rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, 387rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
386 GNUNET_REST_ResultProcessor proc, 388 GNUNET_REST_ResultProcessor proc,
387 void *proc_cls) 389 void *proc_cls)
388{ 390{
389 struct RequestHandle *handle = GNUNET_new(struct RequestHandle); 391 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
390 392
391 handle->response_code = 0; 393 handle->response_code = 0;
392 handle->timeout = 394 handle->timeout =
393 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60); 395 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60);
394 handle->proc_cls = proc_cls; 396 handle->proc_cls = proc_cls;
395 handle->proc = proc; 397 handle->proc = proc;
396 handle->rest_handle = rest_handle; 398 handle->rest_handle = rest_handle;
397 399
398 handle->url = GNUNET_strdup(rest_handle->url); 400 handle->url = GNUNET_strdup (rest_handle->url);
399 if (handle->url[strlen(handle->url) - 1] == '/') 401 if (handle->url[strlen (handle->url) - 1] == '/')
400 handle->url[strlen(handle->url) - 1] = '\0'; 402 handle->url[strlen (handle->url) - 1] = '\0';
401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
402 handle->gns = GNUNET_GNS_connect(cfg); 404 handle->gns = GNUNET_GNS_connect (cfg);
403 init_cont(handle); 405 init_cont (handle);
404 406
405 handle->timeout_task = 407 handle->timeout_task =
406 GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_timeout, handle); 408 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
407 409
408 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
409} 411}
410 412
411 413
@@ -416,7 +418,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
416 * @return NULL on error, otherwise the plugin context 418 * @return NULL on error, otherwise the plugin context
417 */ 419 */
418void * 420void *
419libgnunet_plugin_rest_gns_init(void *cls) 421libgnunet_plugin_rest_gns_init (void *cls)
420{ 422{
421 static struct Plugin plugin; 423 static struct Plugin plugin;
422 struct GNUNET_REST_Plugin *api; 424 struct GNUNET_REST_Plugin *api;
@@ -424,21 +426,21 @@ libgnunet_plugin_rest_gns_init(void *cls)
424 cfg = cls; 426 cfg = cls;
425 if (NULL != plugin.cfg) 427 if (NULL != plugin.cfg)
426 return NULL; /* can only initialize once! */ 428 return NULL; /* can only initialize once! */
427 memset(&plugin, 0, sizeof(struct Plugin)); 429 memset (&plugin, 0, sizeof(struct Plugin));
428 plugin.cfg = cfg; 430 plugin.cfg = cfg;
429 api = GNUNET_new(struct GNUNET_REST_Plugin); 431 api = GNUNET_new (struct GNUNET_REST_Plugin);
430 api->cls = &plugin; 432 api->cls = &plugin;
431 api->name = GNUNET_REST_API_NS_GNS; 433 api->name = GNUNET_REST_API_NS_GNS;
432 api->process_request = &rest_process_request; 434 api->process_request = &rest_process_request;
433 GNUNET_asprintf(&allow_methods, 435 GNUNET_asprintf (&allow_methods,
434 "%s, %s, %s, %s, %s", 436 "%s, %s, %s, %s, %s",
435 MHD_HTTP_METHOD_GET, 437 MHD_HTTP_METHOD_GET,
436 MHD_HTTP_METHOD_POST, 438 MHD_HTTP_METHOD_POST,
437 MHD_HTTP_METHOD_PUT, 439 MHD_HTTP_METHOD_PUT,
438 MHD_HTTP_METHOD_DELETE, 440 MHD_HTTP_METHOD_DELETE,
439 MHD_HTTP_METHOD_OPTIONS); 441 MHD_HTTP_METHOD_OPTIONS);
440 442
441 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Gns REST API initialized\n")); 443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n"));
442 return api; 444 return api;
443} 445}
444 446
@@ -450,18 +452,17 @@ libgnunet_plugin_rest_gns_init(void *cls)
450 * @return always NULL 452 * @return always NULL
451 */ 453 */
452void * 454void *
453libgnunet_plugin_rest_gns_done(void *cls) 455libgnunet_plugin_rest_gns_done (void *cls)
454{ 456{
455 struct GNUNET_REST_Plugin *api = cls; 457 struct GNUNET_REST_Plugin *api = cls;
456 struct Plugin *plugin = api->cls; 458 struct Plugin *plugin = api->cls;
457 459
458 plugin->cfg = NULL; 460 plugin->cfg = NULL;
459 461
460 GNUNET_free_non_null(allow_methods); 462 GNUNET_free_non_null (allow_methods);
461 GNUNET_free(api); 463 GNUNET_free (api);
462 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Gns REST plugin is finished\n"); 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Gns REST plugin is finished\n");
463 return NULL; 465 return NULL;
464} 466}
465 467
466/* end of plugin_rest_gns.c */ 468/* end of plugin_rest_gns.c */
467
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c
index 2df422731..02a9fc01e 100644
--- a/src/gns/test_gns_proxy.c
+++ b/src/gns/test_gns_proxy.c
@@ -37,7 +37,7 @@
37 37
38#define TEST_DOMAIN "www.test" 38#define TEST_DOMAIN "www.test"
39 39
40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
41 41
42/** 42/**
43 * Return value for 'main'. 43 * Return value for 'main'.
@@ -59,9 +59,9 @@ static char *url;
59 59
60static struct GNUNET_OS_Process *proxy_proc; 60static struct GNUNET_OS_Process *proxy_proc;
61 61
62static char* cafile_opt; 62static char*cafile_opt;
63 63
64static char* cafile_srv; 64static char*cafile_srv;
65 65
66static uint16_t port; 66static uint16_t port;
67 67
@@ -69,7 +69,8 @@ static gnutls_x509_crt_t proxy_cert;
69 69
70static gnutls_x509_privkey_t proxy_key; 70static gnutls_x509_privkey_t proxy_key;
71 71
72struct CBC { 72struct CBC
73{
73 char buf[1024]; 74 char buf[1024];
74 size_t pos; 75 size_t pos;
75}; 76};
@@ -84,30 +85,30 @@ static struct CBC cbc;
84 * @return NULL on error 85 * @return NULL on error
85 */ 86 */
86static void* 87static void*
87load_file(const char* filename, 88load_file (const char*filename,
88 unsigned int* size) 89 unsigned int*size)
89{ 90{
90 void *buffer; 91 void *buffer;
91 uint64_t fsize; 92 uint64_t fsize;
92 93
93 if (GNUNET_OK != 94 if (GNUNET_OK !=
94 GNUNET_DISK_file_size(filename, 95 GNUNET_DISK_file_size (filename,
95 &fsize, 96 &fsize,
96 GNUNET_YES, 97 GNUNET_YES,
97 GNUNET_YES)) 98 GNUNET_YES))
98 return NULL; 99 return NULL;
99 if (fsize > MAX_PEM_SIZE) 100 if (fsize > MAX_PEM_SIZE)
100 return NULL; 101 return NULL;
101 *size = (unsigned int)fsize; 102 *size = (unsigned int) fsize;
102 buffer = GNUNET_malloc(*size); 103 buffer = GNUNET_malloc (*size);
103 if (fsize != 104 if (fsize !=
104 GNUNET_DISK_fn_read(filename, 105 GNUNET_DISK_fn_read (filename,
105 buffer, 106 buffer,
106 (size_t)fsize)) 107 (size_t) fsize))
107 { 108 {
108 GNUNET_free(buffer); 109 GNUNET_free (buffer);
109 return NULL; 110 return NULL;
110 } 111 }
111 return buffer; 112 return buffer;
112} 113}
113 114
@@ -119,25 +120,25 @@ load_file(const char* filename,
119 * @return #GNUNET_OK on success 120 * @return #GNUNET_OK on success
120 */ 121 */
121static int 122static int
122load_key_from_file(gnutls_x509_privkey_t key, 123load_key_from_file (gnutls_x509_privkey_t key,
123 const char* keyfile) 124 const char*keyfile)
124{ 125{
125 gnutls_datum_t key_data; 126 gnutls_datum_t key_data;
126 int ret; 127 int ret;
127 128
128 key_data.data = load_file(keyfile, 129 key_data.data = load_file (keyfile,
129 &key_data.size); 130 &key_data.size);
130 if (NULL == key_data.data) 131 if (NULL == key_data.data)
131 return GNUNET_SYSERR; 132 return GNUNET_SYSERR;
132 ret = gnutls_x509_privkey_import(key, &key_data, 133 ret = gnutls_x509_privkey_import (key, &key_data,
133 GNUTLS_X509_FMT_PEM); 134 GNUTLS_X509_FMT_PEM);
134 if (GNUTLS_E_SUCCESS != ret) 135 if (GNUTLS_E_SUCCESS != ret)
135 { 136 {
136 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
137 _("Unable to import private key from file `%s'\n"), 138 _ ("Unable to import private key from file `%s'\n"),
138 keyfile); 139 keyfile);
139 } 140 }
140 GNUNET_free_non_null(key_data.data); 141 GNUNET_free_non_null (key_data.data);
141 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; 142 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
142} 143}
143 144
@@ -149,108 +150,109 @@ load_key_from_file(gnutls_x509_privkey_t key,
149 * @return #GNUNET_OK on success 150 * @return #GNUNET_OK on success
150 */ 151 */
151static int 152static int
152load_cert_from_file(gnutls_x509_crt_t crt, 153load_cert_from_file (gnutls_x509_crt_t crt,
153 const char* certfile) 154 const char*certfile)
154{ 155{
155 gnutls_datum_t cert_data; 156 gnutls_datum_t cert_data;
156 int ret; 157 int ret;
157 158
158 cert_data.data = load_file(certfile, 159 cert_data.data = load_file (certfile,
159 &cert_data.size); 160 &cert_data.size);
160 if (NULL == cert_data.data) 161 if (NULL == cert_data.data)
161 return GNUNET_SYSERR; 162 return GNUNET_SYSERR;
162 ret = gnutls_x509_crt_import(crt, 163 ret = gnutls_x509_crt_import (crt,
163 &cert_data, 164 &cert_data,
164 GNUTLS_X509_FMT_PEM); 165 GNUTLS_X509_FMT_PEM);
165 if (GNUTLS_E_SUCCESS != ret) 166 if (GNUTLS_E_SUCCESS != ret)
166 { 167 {
167 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 _("Unable to import certificate from `%s'\n"), 169 _ ("Unable to import certificate from `%s'\n"),
169 certfile); 170 certfile);
170 } 171 }
171 GNUNET_free_non_null(cert_data.data); 172 GNUNET_free_non_null (cert_data.data);
172 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; 173 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
173} 174}
174 175
175static size_t 176static size_t
176copy_buffer(void *ptr, size_t size, size_t nmemb, void *ctx) 177copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
177{ 178{
178 struct CBC *cbc = ctx; 179 struct CBC *cbc = ctx;
179 180
180 if (cbc->pos + size * nmemb > sizeof(cbc->buf)) 181 if (cbc->pos + size * nmemb > sizeof(cbc->buf))
181 return 0; /* overflow */ 182 return 0; /* overflow */
182 GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb); 183 GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
183 cbc->pos += size * nmemb; 184 cbc->pos += size * nmemb;
184 return size * nmemb; 185 return size * nmemb;
185} 186}
186 187
187 188
188static int 189static int
189mhd_ahc(void *cls, 190mhd_ahc (void *cls,
190 struct MHD_Connection *connection, 191 struct MHD_Connection *connection,
191 const char *url, 192 const char *url,
192 const char *method, 193 const char *method,
193 const char *version, 194 const char *version,
194 const char *upload_data, size_t *upload_data_size, 195 const char *upload_data, size_t *upload_data_size,
195 void **unused) 196 void **unused)
196{ 197{
197 static int ptr; 198 static int ptr;
198 struct MHD_Response *response; 199 struct MHD_Response *response;
199 int ret; 200 int ret;
200 201
201 if (0 != strcmp("GET", method)) 202 if (0 != strcmp ("GET", method))
202 return MHD_NO; /* unexpected method */ 203 return MHD_NO; /* unexpected method */
203 if (&ptr != *unused) 204 if (&ptr != *unused)
204 { 205 {
205 *unused = &ptr; 206 *unused = &ptr;
206 return MHD_YES; 207 return MHD_YES;
207 } 208 }
208 *unused = NULL; 209 *unused = NULL;
209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); 210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 response = MHD_create_response_from_buffer(strlen(url), 211 "MHD sends respose for request to URL `%s'\n", url);
211 (void *)url, 212 response = MHD_create_response_from_buffer (strlen (url),
212 MHD_RESPMEM_MUST_COPY); 213 (void *) url,
213 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 214 MHD_RESPMEM_MUST_COPY);
214 MHD_destroy_response(response); 215 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
216 MHD_destroy_response (response);
215 if (ret == MHD_NO) 217 if (ret == MHD_NO)
216 { 218 {
217 global_ret = 1; 219 global_ret = 1;
218 abort(); 220 abort ();
219 } 221 }
220 global_ret = 0; 222 global_ret = 0;
221 return ret; 223 return ret;
222} 224}
223 225
224 226
225static void 227static void
226do_shutdown() 228do_shutdown ()
227{ 229{
228 if (mhd_task_id != NULL) 230 if (mhd_task_id != NULL)
229 { 231 {
230 GNUNET_SCHEDULER_cancel(mhd_task_id); 232 GNUNET_SCHEDULER_cancel (mhd_task_id);
231 mhd_task_id = NULL; 233 mhd_task_id = NULL;
232 } 234 }
233 if (curl_task_id != NULL) 235 if (curl_task_id != NULL)
234 { 236 {
235 GNUNET_SCHEDULER_cancel(curl_task_id); 237 GNUNET_SCHEDULER_cancel (curl_task_id);
236 curl_task_id = NULL; 238 curl_task_id = NULL;
237 } 239 }
238 if (NULL != mhd) 240 if (NULL != mhd)
239 { 241 {
240 MHD_stop_daemon(mhd); 242 MHD_stop_daemon (mhd);
241 mhd = NULL; 243 mhd = NULL;
242 } 244 }
243 GNUNET_free_non_null(url); 245 GNUNET_free_non_null (url);
244 246
245 if (NULL != proxy_proc) 247 if (NULL != proxy_proc)
246 { 248 {
247 (void)GNUNET_OS_process_kill(proxy_proc, SIGKILL); 249 (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL);
248 GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(proxy_proc)); 250 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proxy_proc));
249 GNUNET_OS_process_destroy(proxy_proc); 251 GNUNET_OS_process_destroy (proxy_proc);
250 proxy_proc = NULL; 252 proxy_proc = NULL;
251 } 253 }
252 url = NULL; 254 url = NULL;
253 GNUNET_SCHEDULER_shutdown(); 255 GNUNET_SCHEDULER_shutdown ();
254} 256}
255 257
256 258
@@ -258,19 +260,19 @@ do_shutdown()
258 * Function to run the HTTP client. 260 * Function to run the HTTP client.
259 */ 261 */
260static void 262static void
261curl_main(void); 263curl_main (void);
262 264
263 265
264static void 266static void
265curl_task(void *cls) 267curl_task (void *cls)
266{ 268{
267 curl_task_id = NULL; 269 curl_task_id = NULL;
268 curl_main(); 270 curl_main ();
269} 271}
270 272
271 273
272static void 274static void
273curl_main() 275curl_main ()
274{ 276{
275 fd_set rs; 277 fd_set rs;
276 fd_set ws; 278 fd_set ws;
@@ -284,93 +286,94 @@ curl_main()
284 struct CURLMsg *msg; 286 struct CURLMsg *msg;
285 287
286 max = 0; 288 max = 0;
287 FD_ZERO(&rs); 289 FD_ZERO (&rs);
288 FD_ZERO(&ws); 290 FD_ZERO (&ws);
289 FD_ZERO(&es); 291 FD_ZERO (&es);
290 curl_multi_perform(multi, &running); 292 curl_multi_perform (multi, &running);
291 if (running == 0) 293 if (running == 0)
294 {
295 GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running)));
296 if (msg->msg == CURLMSG_DONE)
292 { 297 {
293 GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running))); 298 if (msg->data.result != CURLE_OK)
294 if (msg->msg == CURLMSG_DONE) 299 {
295 { 300 fprintf (stderr,
296 if (msg->data.result != CURLE_OK) 301 "%s failed at %s:%d: `%s'\n",
297 { 302 "curl_multi_perform",
298 fprintf(stderr, 303 __FILE__,
299 "%s failed at %s:%d: `%s'\n", 304 __LINE__, curl_easy_strerror (msg->data.result));
300 "curl_multi_perform", 305 global_ret = 1;
301 __FILE__, 306 }
302 __LINE__, curl_easy_strerror(msg->data.result));
303 global_ret = 1;
304 }
305 }
306 curl_multi_remove_handle(multi, curl);
307 curl_multi_cleanup(multi);
308 curl_easy_cleanup(curl);
309 curl = NULL;
310 multi = NULL;
311 if (cbc.pos != strlen("/hello_world"))
312 {
313 GNUNET_break(0);
314 global_ret = 2;
315 }
316 if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world")))
317 {
318 GNUNET_break(0);
319 global_ret = 3;
320 }
321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
322 do_shutdown();
323 return;
324 } 307 }
325 GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max)); 308 curl_multi_remove_handle (multi, curl);
326 if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || 309 curl_multi_cleanup (multi);
310 curl_easy_cleanup (curl);
311 curl = NULL;
312 multi = NULL;
313 if (cbc.pos != strlen ("/hello_world"))
314 {
315 GNUNET_break (0);
316 global_ret = 2;
317 }
318 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
319 {
320 GNUNET_break (0);
321 global_ret = 3;
322 }
323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
324 do_shutdown ();
325 return;
326 }
327 GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
328 if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) ||
327 (-1 == timeout)) 329 (-1 == timeout))
328 delay = GNUNET_TIME_UNIT_SECONDS; 330 delay = GNUNET_TIME_UNIT_SECONDS;
329 else 331 else
330 delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int)timeout); 332 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
331 GNUNET_NETWORK_fdset_copy_native(&nrs, 333 (unsigned int) timeout);
332 &rs, 334 GNUNET_NETWORK_fdset_copy_native (&nrs,
333 max + 1); 335 &rs,
334 GNUNET_NETWORK_fdset_copy_native(&nws, 336 max + 1);
335 &ws, 337 GNUNET_NETWORK_fdset_copy_native (&nws,
336 max + 1); 338 &ws,
337 curl_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 339 max + 1);
338 delay, 340 curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
339 &nrs, 341 delay,
340 &nws, 342 &nrs,
341 &curl_task, 343 &nws,
342 NULL); 344 &curl_task,
345 NULL);
343} 346}
344 347
345 348
346static void 349static void
347start_curl(void *cls) 350start_curl (void *cls)
348{ 351{
349 curl_task_id = NULL; 352 curl_task_id = NULL;
350 GNUNET_asprintf(&url, 353 GNUNET_asprintf (&url,
351 "https://%s:%d/hello_world", 354 "https://%s:%d/hello_world",
352 TEST_DOMAIN, port); 355 TEST_DOMAIN, port);
353 curl = curl_easy_init(); 356 curl = curl_easy_init ();
354 curl_easy_setopt(curl, CURLOPT_URL, url); 357 curl_easy_setopt (curl, CURLOPT_URL, url);
355 //curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world"); 358 // curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world");
356 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &copy_buffer); 359 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
357 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc); 360 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
358 curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); 361 curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
359 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L); 362 curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
360 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15L); 363 curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L);
361 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); 364 curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
362 curl_easy_setopt(curl, CURLOPT_CAINFO, cafile_opt); 365 curl_easy_setopt (curl, CURLOPT_CAINFO, cafile_opt);
363 //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L); 366 // curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L);
364 //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L); 367 // curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L);
365 curl_easy_setopt(curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); 368 curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777");
366 369
367 multi = curl_multi_init(); 370 multi = curl_multi_init ();
368 GNUNET_assert(multi != NULL); 371 GNUNET_assert (multi != NULL);
369 GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl)); 372 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
370 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
371 "Beginning HTTP download from `%s'\n", 374 "Beginning HTTP download from `%s'\n",
372 url); 375 url);
373 curl_main(); 376 curl_main ();
374} 377}
375 378
376 379
@@ -387,12 +390,12 @@ start_curl(void *cls)
387 * specified target peer; NULL on error 390 * specified target peer; NULL on error
388 */ 391 */
389static void 392static void
390commence_testing(void *cls) 393commence_testing (void *cls)
391{ 394{
392 curl_task_id = 395 curl_task_id =
393 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 396 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
394 &start_curl, 397 &start_curl,
395 NULL); 398 NULL);
396} 399}
397 400
398 401
@@ -400,20 +403,20 @@ commence_testing(void *cls)
400 * Function to keep the HTTP server running. 403 * Function to keep the HTTP server running.
401 */ 404 */
402static void 405static void
403mhd_main(void); 406mhd_main (void);
404 407
405 408
406static void 409static void
407mhd_task(void *cls) 410mhd_task (void *cls)
408{ 411{
409 mhd_task_id = NULL; 412 mhd_task_id = NULL;
410 MHD_run(mhd); 413 MHD_run (mhd);
411 mhd_main(); 414 mhd_main ();
412} 415}
413 416
414 417
415static void 418static void
416mhd_main() 419mhd_main ()
417{ 420{
418 struct GNUNET_NETWORK_FDSet nrs; 421 struct GNUNET_NETWORK_FDSet nrs;
419 struct GNUNET_NETWORK_FDSet nws; 422 struct GNUNET_NETWORK_FDSet nws;
@@ -424,30 +427,30 @@ mhd_main()
424 unsigned MHD_LONG_LONG timeout; 427 unsigned MHD_LONG_LONG timeout;
425 struct GNUNET_TIME_Relative delay; 428 struct GNUNET_TIME_Relative delay;
426 429
427 GNUNET_assert(NULL == mhd_task_id); 430 GNUNET_assert (NULL == mhd_task_id);
428 FD_ZERO(&rs); 431 FD_ZERO (&rs);
429 FD_ZERO(&ws); 432 FD_ZERO (&ws);
430 FD_ZERO(&es); 433 FD_ZERO (&es);
431 max_fd = -1; 434 max_fd = -1;
432 GNUNET_assert(MHD_YES == 435 GNUNET_assert (MHD_YES ==
433 MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd)); 436 MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
434 if (MHD_YES == MHD_get_timeout(mhd, &timeout)) 437 if (MHD_YES == MHD_get_timeout (mhd, &timeout))
435 delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 438 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
436 (unsigned int)timeout); 439 (unsigned int) timeout);
437 else 440 else
438 delay = GNUNET_TIME_UNIT_FOREVER_REL; 441 delay = GNUNET_TIME_UNIT_FOREVER_REL;
439 GNUNET_NETWORK_fdset_copy_native(&nrs, 442 GNUNET_NETWORK_fdset_copy_native (&nrs,
440 &rs, 443 &rs,
441 max_fd + 1); 444 max_fd + 1);
442 GNUNET_NETWORK_fdset_copy_native(&nws, 445 GNUNET_NETWORK_fdset_copy_native (&nws,
443 &ws, 446 &ws,
444 max_fd + 1); 447 max_fd + 1);
445 mhd_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 448 mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
446 delay, 449 delay,
447 &nrs, 450 &nrs,
448 &nws, 451 &nws,
449 &mhd_task, 452 &mhd_task,
450 NULL); 453 NULL);
451} 454}
452 455
453 456
@@ -460,105 +463,108 @@ mhd_main()
460 * @param c configuration 463 * @param c configuration
461 */ 464 */
462static void 465static void
463run(void *cls, 466run (void *cls,
464 char *const *args, 467 char *const *args,
465 const char *cfgfile, 468 const char *cfgfile,
466 const struct GNUNET_CONFIGURATION_Handle *c) 469 const struct GNUNET_CONFIGURATION_Handle *c)
467{ 470{
468 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "Using `%s' as CA\n", 472 "Using `%s' as CA\n",
470 cafile_srv); 473 cafile_srv);
471 char cert[MAX_PEM_SIZE]; 474 char cert[MAX_PEM_SIZE];
472 char key[MAX_PEM_SIZE]; 475 char key[MAX_PEM_SIZE];
473 size_t key_buf_size; 476 size_t key_buf_size;
474 size_t cert_buf_size; 477 size_t cert_buf_size;
475 478
476 gnutls_global_init(); 479 gnutls_global_init ();
477 gnutls_x509_crt_init(&proxy_cert); 480 gnutls_x509_crt_init (&proxy_cert);
478 gnutls_x509_privkey_init(&proxy_key); 481 gnutls_x509_privkey_init (&proxy_key);
479 482
480 if ((GNUNET_OK != 483 if ((GNUNET_OK !=
481 load_cert_from_file(proxy_cert, 484 load_cert_from_file (proxy_cert,
482 cafile_srv)) || 485 cafile_srv)) ||
483 (GNUNET_OK != 486 (GNUNET_OK !=
484 load_key_from_file(proxy_key, 487 load_key_from_file (proxy_key,
485 cafile_srv))) 488 cafile_srv)))
486 { 489 {
487 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 490 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
488 _("Failed to load X.509 key and certificate from `%s'\n"), 491 _ ("Failed to load X.509 key and certificate from `%s'\n"),
489 cafile_srv); 492 cafile_srv);
490 gnutls_x509_crt_deinit(proxy_cert); 493 gnutls_x509_crt_deinit (proxy_cert);
491 gnutls_x509_privkey_deinit(proxy_key); 494 gnutls_x509_privkey_deinit (proxy_key);
492 gnutls_global_deinit(); 495 gnutls_global_deinit ();
493 return; 496 return;
494 } 497 }
495 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 498 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
496 NULL); 499 NULL);
497 key_buf_size = sizeof(key); 500 key_buf_size = sizeof(key);
498 cert_buf_size = sizeof(cert); 501 cert_buf_size = sizeof(cert);
499 gnutls_x509_crt_export(proxy_cert, 502 gnutls_x509_crt_export (proxy_cert,
500 GNUTLS_X509_FMT_PEM, 503 GNUTLS_X509_FMT_PEM,
501 cert, 504 cert,
502 &cert_buf_size); 505 &cert_buf_size);
503 gnutls_x509_privkey_export(proxy_key, 506 gnutls_x509_privkey_export (proxy_key,
504 GNUTLS_X509_FMT_PEM, 507 GNUTLS_X509_FMT_PEM,
505 key, 508 key,
506 &key_buf_size); 509 &key_buf_size);
507 mhd = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SSL | MHD_ALLOW_SUSPEND_RESUME, port, 510 mhd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL
508 NULL, NULL, 511 | MHD_ALLOW_SUSPEND_RESUME, port,
509 &mhd_ahc, NULL, 512 NULL, NULL,
510 MHD_OPTION_HTTPS_MEM_KEY, key, 513 &mhd_ahc, NULL,
511 MHD_OPTION_HTTPS_MEM_CERT, cert, 514 MHD_OPTION_HTTPS_MEM_KEY, key,
512 MHD_OPTION_END); 515 MHD_OPTION_HTTPS_MEM_CERT, cert,
513 GNUNET_assert(NULL != mhd); 516 MHD_OPTION_END);
514 mhd_main(); 517 GNUNET_assert (NULL != mhd);
515 518 mhd_main ();
516 GNUNET_SCHEDULER_add_now(&commence_testing, 519
517 NULL); 520 GNUNET_SCHEDULER_add_now (&commence_testing,
521 NULL);
518} 522}
519 523
520int 524int
521main(int argc, char *const *argv) 525main (int argc, char *const *argv)
522{ 526{
523 struct GNUNET_GETOPT_CommandLineOption options[] = { 527 struct GNUNET_GETOPT_CommandLineOption options[] = {
524 GNUNET_GETOPT_option_uint16('p', 528 GNUNET_GETOPT_option_uint16 ('p',
525 "port", 529 "port",
526 NULL, 530 NULL,
527 gettext_noop("listen on specified port (default: 7777)"), 531 gettext_noop (
528 &port), 532 "listen on specified port (default: 7777)"),
529 GNUNET_GETOPT_option_string('A', 533 &port),
530 "curlcert", 534 GNUNET_GETOPT_option_string ('A',
531 NULL, 535 "curlcert",
532 gettext_noop("pem file to use as CA"), 536 NULL,
533 &cafile_opt), 537 gettext_noop ("pem file to use as CA"),
534 GNUNET_GETOPT_option_string('S', 538 &cafile_opt),
535 "servercert", 539 GNUNET_GETOPT_option_string ('S',
536 NULL, 540 "servercert",
537 gettext_noop("pem file to use for the server"), 541 NULL,
538 &cafile_srv), 542 gettext_noop (
543 "pem file to use for the server"),
544 &cafile_srv),
539 545
540 GNUNET_GETOPT_OPTION_END 546 GNUNET_GETOPT_OPTION_END
541 }; 547 };
542 548
543 if (0 != curl_global_init(CURL_GLOBAL_WIN32)) 549 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
544 { 550 {
545 fprintf(stderr, "failed to initialize curl\n"); 551 fprintf (stderr, "failed to initialize curl\n");
546 return 2; 552 return 2;
547 } 553 }
548 if (GNUNET_OK != 554 if (GNUNET_OK !=
549 GNUNET_STRINGS_get_utf8_args(argc, argv, 555 GNUNET_STRINGS_get_utf8_args (argc, argv,
550 &argc, &argv)) 556 &argc, &argv))
551 return 2; 557 return 2;
552 GNUNET_log_setup("gnunet-gns-proxy-test", 558 GNUNET_log_setup ("gnunet-gns-proxy-test",
553 "WARNING", 559 "WARNING",
554 NULL); 560 NULL);
555 if (GNUNET_OK != GNUNET_PROGRAM_run(argc, argv, 561 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv,
556 "gnunet-gns-proxy-test", 562 "gnunet-gns-proxy-test",
557 _("GNUnet GNS proxy test"), 563 _ ("GNUnet GNS proxy test"),
558 options, 564 options,
559 &run, NULL)) 565 &run, NULL))
560 return 1; 566 return 1;
561 GNUNET_free_non_null((char *)argv); 567 GNUNET_free_non_null ((char *) argv);
562 return global_ret; 568 return global_ret;
563} 569}
564 570
diff --git a/src/gns/w32resolver.h b/src/gns/w32resolver.h
index 17521ba50..c404e37d3 100644
--- a/src/gns/w32resolver.h
+++ b/src/gns/w32resolver.h
@@ -50,7 +50,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
50 * The last W32RESOLVER_RESPONSE will just be a header without any data 50 * The last W32RESOLVER_RESPONSE will just be a header without any data
51 * (used to indicate the end of the list). 51 * (used to indicate the end of the list).
52 */ 52 */
53struct GNUNET_W32RESOLVER_GetMessage { 53struct GNUNET_W32RESOLVER_GetMessage
54{
54 /** 55 /**
55 * Type: GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST 56 * Type: GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST
56 */ 57 */