diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/gns | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/gns')
30 files changed, 7889 insertions, 7848 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h index 3b41de83c..8465f49f9 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -33,8 +33,7 @@ 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 | */ |
36 | struct LookupMessage | 36 | struct LookupMessage { |
37 | { | ||
38 | /** | 37 | /** |
39 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP | 38 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP |
40 | */ | 39 | */ |
@@ -73,10 +72,9 @@ struct LookupMessage | |||
73 | /** | 72 | /** |
74 | * Message from GNS service to client: new results. | 73 | * Message from GNS service to client: new results. |
75 | */ | 74 | */ |
76 | struct LookupResultMessage | 75 | struct LookupResultMessage { |
77 | { | ||
78 | /** | 76 | /** |
79 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT | 77 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT |
80 | */ | 78 | */ |
81 | struct GNUNET_MessageHeader header; | 79 | struct GNUNET_MessageHeader header; |
82 | 80 | ||
@@ -91,7 +89,6 @@ struct LookupResultMessage | |||
91 | uint32_t rd_count GNUNET_PACKED; | 89 | uint32_t rd_count GNUNET_PACKED; |
92 | 90 | ||
93 | /* followed by rd_count GNUNET_GNSRECORD_Data structs*/ | 91 | /* followed by rd_count GNUNET_GNSRECORD_Data structs*/ |
94 | |||
95 | }; | 92 | }; |
96 | 93 | ||
97 | 94 | ||
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index ba83b73cd..62f250959 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gns_api.c | 21 | * @file gns/gns_api.c |
22 | * @brief library to access the GNS service | 22 | * @brief library to access the GNS service |
@@ -34,14 +34,12 @@ | |||
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 | */ |
42 | struct GNUNET_GNS_LookupRequest | 42 | struct GNUNET_GNS_LookupRequest { |
43 | { | ||
44 | |||
45 | /** | 43 | /** |
46 | * DLL | 44 | * DLL |
47 | */ | 45 | */ |
@@ -76,7 +74,6 @@ struct GNUNET_GNS_LookupRequest | |||
76 | * request id | 74 | * request id |
77 | */ | 75 | */ |
78 | uint32_t r_id; | 76 | uint32_t r_id; |
79 | |||
80 | }; | 77 | }; |
81 | 78 | ||
82 | 79 | ||
@@ -86,7 +83,7 @@ struct GNUNET_GNS_LookupRequest | |||
86 | * @param handle the handle to the GNS service | 83 | * @param handle the handle to the GNS service |
87 | */ | 84 | */ |
88 | static void | 85 | static void |
89 | reconnect (struct GNUNET_GNS_Handle *handle); | 86 | reconnect(struct GNUNET_GNS_Handle *handle); |
90 | 87 | ||
91 | 88 | ||
92 | /** | 89 | /** |
@@ -95,12 +92,12 @@ reconnect (struct GNUNET_GNS_Handle *handle); | |||
95 | * @param cls the handle | 92 | * @param cls the handle |
96 | */ | 93 | */ |
97 | static void | 94 | static void |
98 | reconnect_task (void *cls) | 95 | reconnect_task(void *cls) |
99 | { | 96 | { |
100 | struct GNUNET_GNS_Handle *handle = cls; | 97 | struct GNUNET_GNS_Handle *handle = cls; |
101 | 98 | ||
102 | handle->reconnect_task = NULL; | 99 | handle->reconnect_task = NULL; |
103 | reconnect (handle); | 100 | reconnect(handle); |
104 | } | 101 | } |
105 | 102 | ||
106 | 103 | ||
@@ -110,16 +107,16 @@ reconnect_task (void *cls) | |||
110 | * @param handle our handle | 107 | * @param handle our handle |
111 | */ | 108 | */ |
112 | static void | 109 | static void |
113 | force_reconnect (struct GNUNET_GNS_Handle *handle) | 110 | force_reconnect(struct GNUNET_GNS_Handle *handle) |
114 | { | 111 | { |
115 | GNUNET_MQ_destroy (handle->mq); | 112 | GNUNET_MQ_destroy(handle->mq); |
116 | handle->mq = NULL; | 113 | handle->mq = NULL; |
117 | handle->reconnect_backoff | 114 | handle->reconnect_backoff |
118 | = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); | 115 | = GNUNET_TIME_STD_BACKOFF(handle->reconnect_backoff); |
119 | handle->reconnect_task | 116 | handle->reconnect_task |
120 | = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, | 117 | = GNUNET_SCHEDULER_add_delayed(handle->reconnect_backoff, |
121 | &reconnect_task, | 118 | &reconnect_task, |
122 | handle); | 119 | handle); |
123 | } | 120 | } |
124 | 121 | ||
125 | 122 | ||
@@ -132,15 +129,15 @@ force_reconnect (struct GNUNET_GNS_Handle *handle) | |||
132 | * @param error error code | 129 | * @param error error code |
133 | */ | 130 | */ |
134 | static void | 131 | static void |
135 | mq_error_handler (void *cls, | 132 | mq_error_handler(void *cls, |
136 | enum GNUNET_MQ_Error error) | 133 | enum GNUNET_MQ_Error error) |
137 | { | 134 | { |
138 | struct GNUNET_GNS_Handle *handle = cls; | 135 | struct GNUNET_GNS_Handle *handle = cls; |
139 | 136 | ||
140 | LOG (GNUNET_ERROR_TYPE_WARNING, | 137 | LOG(GNUNET_ERROR_TYPE_WARNING, |
141 | "Problem with message queue. error: %i\n", | 138 | "Problem with message queue. error: %i\n", |
142 | error); | 139 | error); |
143 | force_reconnect (handle); | 140 | force_reconnect(handle); |
144 | } | 141 | } |
145 | 142 | ||
146 | 143 | ||
@@ -151,23 +148,23 @@ mq_error_handler (void *cls, | |||
151 | * @param loookup_msg the incoming message | 148 | * @param loookup_msg the incoming message |
152 | */ | 149 | */ |
153 | static int | 150 | static int |
154 | check_result (void *cls, | 151 | check_result(void *cls, |
155 | const struct LookupResultMessage *lookup_msg) | 152 | const struct LookupResultMessage *lookup_msg) |
156 | { | 153 | { |
157 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); | 154 | size_t mlen = ntohs(lookup_msg->header.size) - sizeof(*lookup_msg); |
158 | uint32_t rd_count = ntohl (lookup_msg->rd_count); | 155 | uint32_t rd_count = ntohl(lookup_msg->rd_count); |
159 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 156 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
160 | 157 | ||
161 | (void) cls; | 158 | (void)cls; |
162 | if (GNUNET_SYSERR == | 159 | if (GNUNET_SYSERR == |
163 | GNUNET_GNSRECORD_records_deserialize (mlen, | 160 | GNUNET_GNSRECORD_records_deserialize(mlen, |
164 | (const char*) &lookup_msg[1], | 161 | (const char*)&lookup_msg[1], |
165 | rd_count, | 162 | rd_count, |
166 | rd)) | 163 | rd)) |
167 | { | 164 | { |
168 | GNUNET_break (0); | 165 | GNUNET_break(0); |
169 | return GNUNET_SYSERR; | 166 | return GNUNET_SYSERR; |
170 | } | 167 | } |
171 | return GNUNET_OK; | 168 | return GNUNET_OK; |
172 | } | 169 | } |
173 | 170 | ||
@@ -179,21 +176,21 @@ check_result (void *cls, | |||
179 | * @param loookup_msg the incoming message | 176 | * @param loookup_msg the incoming message |
180 | */ | 177 | */ |
181 | static void | 178 | static void |
182 | handle_result (void *cls, | 179 | handle_result(void *cls, |
183 | const struct LookupResultMessage *lookup_msg) | 180 | const struct LookupResultMessage *lookup_msg) |
184 | { | 181 | { |
185 | struct GNUNET_GNS_Handle *handle = cls; | 182 | struct GNUNET_GNS_Handle *handle = cls; |
186 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); | 183 | size_t mlen = ntohs(lookup_msg->header.size) - sizeof(*lookup_msg); |
187 | uint32_t rd_count = ntohl (lookup_msg->rd_count); | 184 | uint32_t rd_count = ntohl(lookup_msg->rd_count); |
188 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 185 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
189 | uint32_t r_id = ntohl (lookup_msg->id); | 186 | uint32_t r_id = ntohl(lookup_msg->id); |
190 | struct GNUNET_GNS_LookupRequest *lr; | 187 | struct GNUNET_GNS_LookupRequest *lr; |
191 | GNUNET_GNS_LookupResultProcessor proc; | 188 | GNUNET_GNS_LookupResultProcessor proc; |
192 | void *proc_cls; | 189 | void *proc_cls; |
193 | 190 | ||
194 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 191 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
195 | "Received lookup reply from GNS service (%u records)\n", | 192 | "Received lookup reply from GNS service (%u records)\n", |
196 | (unsigned int) rd_count); | 193 | (unsigned int)rd_count); |
197 | for (lr = handle->lookup_head; NULL != lr; lr = lr->next) | 194 | for (lr = handle->lookup_head; NULL != lr; lr = lr->next) |
198 | if (lr->r_id == r_id) | 195 | if (lr->r_id == r_id) |
199 | break; | 196 | break; |
@@ -202,20 +199,20 @@ handle_result (void *cls, | |||
202 | proc = lr->lookup_proc; | 199 | proc = lr->lookup_proc; |
203 | proc_cls = lr->proc_cls; | 200 | proc_cls = lr->proc_cls; |
204 | 201 | ||
205 | GNUNET_assert (GNUNET_OK == | 202 | GNUNET_assert(GNUNET_OK == |
206 | GNUNET_GNSRECORD_records_deserialize (mlen, | 203 | GNUNET_GNSRECORD_records_deserialize(mlen, |
207 | (const char*) &lookup_msg[1], | 204 | (const char*)&lookup_msg[1], |
208 | rd_count, | 205 | rd_count, |
209 | rd)); | 206 | rd)); |
210 | proc (proc_cls, | 207 | proc(proc_cls, |
211 | rd_count, | 208 | rd_count, |
212 | rd); | 209 | rd); |
213 | GNUNET_CONTAINER_DLL_remove (handle->lookup_head, | 210 | GNUNET_CONTAINER_DLL_remove(handle->lookup_head, |
214 | handle->lookup_tail, | 211 | handle->lookup_tail, |
215 | lr); | 212 | lr); |
216 | if (NULL != lr->env) | 213 | if (NULL != lr->env) |
217 | GNUNET_MQ_discard (lr->env); | 214 | GNUNET_MQ_discard(lr->env); |
218 | GNUNET_free (lr); | 215 | GNUNET_free(lr); |
219 | } | 216 | } |
220 | 217 | ||
221 | 218 | ||
@@ -225,31 +222,31 @@ handle_result (void *cls, | |||
225 | * @param handle the handle to the GNS service | 222 | * @param handle the handle to the GNS service |
226 | */ | 223 | */ |
227 | static void | 224 | static void |
228 | reconnect (struct GNUNET_GNS_Handle *handle) | 225 | reconnect(struct GNUNET_GNS_Handle *handle) |
229 | { | 226 | { |
230 | struct GNUNET_MQ_MessageHandler handlers[] = { | 227 | struct GNUNET_MQ_MessageHandler handlers[] = { |
231 | GNUNET_MQ_hd_var_size (result, | 228 | GNUNET_MQ_hd_var_size(result, |
232 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, | 229 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, |
233 | struct LookupResultMessage, | 230 | struct LookupResultMessage, |
234 | handle), | 231 | handle), |
235 | GNUNET_MQ_handler_end () | 232 | GNUNET_MQ_handler_end() |
236 | }; | 233 | }; |
237 | 234 | ||
238 | GNUNET_assert (NULL == handle->mq); | 235 | GNUNET_assert(NULL == handle->mq); |
239 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 236 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
240 | "Trying to connect to GNS\n"); | 237 | "Trying to connect to GNS\n"); |
241 | handle->mq = GNUNET_CLIENT_connect (handle->cfg, | 238 | handle->mq = GNUNET_CLIENT_connect(handle->cfg, |
242 | "gns", | 239 | "gns", |
243 | handlers, | 240 | handlers, |
244 | &mq_error_handler, | 241 | &mq_error_handler, |
245 | handle); | 242 | handle); |
246 | if (NULL == handle->mq) | 243 | if (NULL == handle->mq) |
247 | return; | 244 | return; |
248 | for (struct GNUNET_GNS_LookupRequest *lh = handle->lookup_head; | 245 | for (struct GNUNET_GNS_LookupRequest *lh = handle->lookup_head; |
249 | NULL != lh; | 246 | NULL != lh; |
250 | lh = lh->next) | 247 | lh = lh->next) |
251 | GNUNET_MQ_send_copy (handle->mq, | 248 | GNUNET_MQ_send_copy(handle->mq, |
252 | lh->env); | 249 | lh->env); |
253 | } | 250 | } |
254 | 251 | ||
255 | 252 | ||
@@ -260,18 +257,18 @@ reconnect (struct GNUNET_GNS_Handle *handle) | |||
260 | * @return handle to the GNS service, or NULL on error | 257 | * @return handle to the GNS service, or NULL on error |
261 | */ | 258 | */ |
262 | struct GNUNET_GNS_Handle * | 259 | struct GNUNET_GNS_Handle * |
263 | GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 260 | GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
264 | { | 261 | { |
265 | struct GNUNET_GNS_Handle *handle; | 262 | struct GNUNET_GNS_Handle *handle; |
266 | 263 | ||
267 | handle = GNUNET_new (struct GNUNET_GNS_Handle); | 264 | handle = GNUNET_new(struct GNUNET_GNS_Handle); |
268 | handle->cfg = cfg; | 265 | handle->cfg = cfg; |
269 | reconnect (handle); | 266 | reconnect(handle); |
270 | if (NULL == handle->mq) | 267 | if (NULL == handle->mq) |
271 | { | 268 | { |
272 | GNUNET_free (handle); | 269 | GNUNET_free(handle); |
273 | return NULL; | 270 | return NULL; |
274 | } | 271 | } |
275 | return handle; | 272 | return handle; |
276 | } | 273 | } |
277 | 274 | ||
@@ -282,20 +279,20 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
282 | * @param handle handle of the GNS connection to stop | 279 | * @param handle handle of the GNS connection to stop |
283 | */ | 280 | */ |
284 | void | 281 | void |
285 | GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | 282 | GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle) |
286 | { | 283 | { |
287 | if (NULL != handle->mq) | 284 | if (NULL != handle->mq) |
288 | { | 285 | { |
289 | GNUNET_MQ_destroy (handle->mq); | 286 | GNUNET_MQ_destroy(handle->mq); |
290 | handle->mq = NULL; | 287 | handle->mq = NULL; |
291 | } | 288 | } |
292 | if (NULL != handle->reconnect_task) | 289 | if (NULL != handle->reconnect_task) |
293 | { | 290 | { |
294 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 291 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); |
295 | handle->reconnect_task = NULL; | 292 | handle->reconnect_task = NULL; |
296 | } | 293 | } |
297 | GNUNET_assert (NULL == handle->lookup_head); | 294 | GNUNET_assert(NULL == handle->lookup_head); |
298 | GNUNET_free (handle); | 295 | GNUNET_free(handle); |
299 | } | 296 | } |
300 | 297 | ||
301 | 298 | ||
@@ -306,17 +303,17 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | |||
306 | * @return closure from the lookup result processor | 303 | * @return closure from the lookup result processor |
307 | */ | 304 | */ |
308 | void * | 305 | void * |
309 | GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) | 306 | GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr) |
310 | { | 307 | { |
311 | struct GNUNET_GNS_Handle *handle = lr->gns_handle; | 308 | struct GNUNET_GNS_Handle *handle = lr->gns_handle; |
312 | void *ret; | 309 | void *ret; |
313 | 310 | ||
314 | GNUNET_CONTAINER_DLL_remove (handle->lookup_head, | 311 | GNUNET_CONTAINER_DLL_remove(handle->lookup_head, |
315 | handle->lookup_tail, | 312 | handle->lookup_tail, |
316 | lr); | 313 | lr); |
317 | GNUNET_MQ_discard (lr->env); | 314 | GNUNET_MQ_discard(lr->env); |
318 | ret = lr->proc_cls; | 315 | ret = lr->proc_cls; |
319 | GNUNET_free (lr); | 316 | GNUNET_free(lr); |
320 | return ret; | 317 | return ret; |
321 | } | 318 | } |
322 | 319 | ||
@@ -334,13 +331,13 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) | |||
334 | * @return handle to the get request | 331 | * @return handle to the get request |
335 | */ | 332 | */ |
336 | struct GNUNET_GNS_LookupRequest* | 333 | struct GNUNET_GNS_LookupRequest* |
337 | GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | 334 | GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, |
338 | const char *name, | 335 | const char *name, |
339 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 336 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, |
340 | uint32_t type, | 337 | uint32_t type, |
341 | enum GNUNET_GNS_LocalOptions options, | 338 | enum GNUNET_GNS_LocalOptions options, |
342 | GNUNET_GNS_LookupResultProcessor proc, | 339 | GNUNET_GNS_LookupResultProcessor proc, |
343 | void *proc_cls) | 340 | void *proc_cls) |
344 | { | 341 | { |
345 | /* IPC to shorten gns names, return shorten_handle */ | 342 | /* IPC to shorten gns names, return shorten_handle */ |
346 | struct LookupMessage *lookup_msg; | 343 | struct LookupMessage *lookup_msg; |
@@ -348,40 +345,40 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
348 | size_t nlen; | 345 | size_t nlen; |
349 | 346 | ||
350 | if (NULL == name) | 347 | if (NULL == name) |
351 | { | 348 | { |
352 | GNUNET_break (0); | 349 | GNUNET_break(0); |
353 | return NULL; | 350 | return NULL; |
354 | } | 351 | } |
355 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 352 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
356 | "Trying to lookup `%s' in GNS\n", | 353 | "Trying to lookup `%s' in GNS\n", |
357 | name); | 354 | name); |
358 | nlen = strlen (name) + 1; | 355 | nlen = strlen(name) + 1; |
359 | if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*lr)) | 356 | if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*lr)) |
360 | { | 357 | { |
361 | GNUNET_break (0); | 358 | GNUNET_break(0); |
362 | return NULL; | 359 | return NULL; |
363 | } | 360 | } |
364 | lr = GNUNET_new (struct GNUNET_GNS_LookupRequest); | 361 | lr = GNUNET_new(struct GNUNET_GNS_LookupRequest); |
365 | lr->gns_handle = handle; | 362 | lr->gns_handle = handle; |
366 | lr->lookup_proc = proc; | 363 | lr->lookup_proc = proc; |
367 | lr->proc_cls = proc_cls; | 364 | lr->proc_cls = proc_cls; |
368 | lr->r_id = handle->r_id_gen++; | 365 | lr->r_id = handle->r_id_gen++; |
369 | lr->env = GNUNET_MQ_msg_extra (lookup_msg, | 366 | lr->env = GNUNET_MQ_msg_extra(lookup_msg, |
370 | nlen, | 367 | nlen, |
371 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP); | 368 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP); |
372 | lookup_msg->id = htonl (lr->r_id); | 369 | lookup_msg->id = htonl(lr->r_id); |
373 | lookup_msg->options = htons ((uint16_t) options); | 370 | lookup_msg->options = htons((uint16_t)options); |
374 | lookup_msg->zone = *zone; | 371 | lookup_msg->zone = *zone; |
375 | lookup_msg->type = htonl (type); | 372 | lookup_msg->type = htonl(type); |
376 | GNUNET_memcpy (&lookup_msg[1], | 373 | GNUNET_memcpy(&lookup_msg[1], |
377 | name, | 374 | name, |
378 | nlen); | 375 | nlen); |
379 | GNUNET_CONTAINER_DLL_insert (handle->lookup_head, | 376 | GNUNET_CONTAINER_DLL_insert(handle->lookup_head, |
380 | handle->lookup_tail, | 377 | handle->lookup_tail, |
381 | lr); | 378 | lr); |
382 | if (NULL != handle->mq) | 379 | if (NULL != handle->mq) |
383 | GNUNET_MQ_send_copy (handle->mq, | 380 | GNUNET_MQ_send_copy(handle->mq, |
384 | lr->env); | 381 | lr->env); |
385 | return lr; | 382 | return lr; |
386 | } | 383 | } |
387 | 384 | ||
diff --git a/src/gns/gns_api.h b/src/gns/gns_api.h index 40fdbfacd..7e07f909f 100644 --- a/src/gns/gns_api.h +++ b/src/gns/gns_api.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gns_api.h | 21 | * @file gns/gns_api.h |
22 | * @brief shared data structures of libgnunetgns | 22 | * @brief shared data structures of libgnunetgns |
@@ -32,9 +32,7 @@ | |||
32 | /** | 32 | /** |
33 | * Connection to the GNS service. | 33 | * Connection to the GNS service. |
34 | */ | 34 | */ |
35 | struct GNUNET_GNS_Handle | 35 | struct GNUNET_GNS_Handle { |
36 | { | ||
37 | |||
38 | /** | 36 | /** |
39 | * Configuration to use. | 37 | * Configuration to use. |
40 | */ | 38 | */ |
@@ -69,7 +67,6 @@ struct GNUNET_GNS_Handle | |||
69 | * Request Id generator. Incremented by one for each request. | 67 | * Request Id generator. Incremented by one for each request. |
70 | */ | 68 | */ |
71 | uint32_t r_id_gen; | 69 | uint32_t r_id_gen; |
72 | |||
73 | }; | 70 | }; |
74 | 71 | ||
75 | 72 | ||
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c index f36b31acf..0692199e3 100644 --- a/src/gns/gns_tld_api.c +++ b/src/gns/gns_tld_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gns_tld_api.c | 21 | * @file gns/gns_tld_api.c |
22 | * @brief library to access the GNS service, including TLD lookup | 22 | * @brief library to access the GNS service, including TLD lookup |
@@ -35,15 +35,13 @@ | |||
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 | */ |
44 | struct GNUNET_GNS_LookupWithTldRequest | 44 | struct GNUNET_GNS_LookupWithTldRequest { |
45 | { | ||
46 | |||
47 | /** | 45 | /** |
48 | * handle to gns | 46 | * handle to gns |
49 | */ | 47 | */ |
@@ -105,11 +103,11 @@ struct GNUNET_GNS_LookupWithTldRequest | |||
105 | * or @a name if @a name does not contain a "." | 103 | * or @a name if @a name does not contain a "." |
106 | */ | 104 | */ |
107 | static const char * | 105 | static const char * |
108 | get_tld (const char *name) | 106 | get_tld(const char *name) |
109 | { | 107 | { |
110 | const char *tld; | 108 | const char *tld; |
111 | 109 | ||
112 | tld = strrchr (name, (unsigned char) '.'); | 110 | tld = strrchr(name, (unsigned char)'.'); |
113 | if (NULL == tld) | 111 | if (NULL == tld) |
114 | tld = name; | 112 | tld = name; |
115 | else | 113 | else |
@@ -125,18 +123,18 @@ get_tld (const char *name) | |||
125 | * @param tld what to eat (can be more than just the tld) | 123 | * @param tld what to eat (can be more than just the tld) |
126 | */ | 124 | */ |
127 | static void | 125 | static void |
128 | eat_tld (char *name, const char *tld) | 126 | eat_tld(char *name, const char *tld) |
129 | { | 127 | { |
130 | GNUNET_assert (0 < strlen (name)); | 128 | GNUNET_assert(0 < strlen(name)); |
131 | if ((NULL == tld) || (strlen (name) == strlen (tld))) | 129 | if ((NULL == tld) || (strlen(name) == strlen(tld))) |
132 | { | 130 | { |
133 | strcpy (name, GNUNET_GNS_EMPTY_LABEL_AT); | 131 | strcpy(name, GNUNET_GNS_EMPTY_LABEL_AT); |
134 | } | 132 | } |
135 | else | 133 | else |
136 | { | 134 | { |
137 | GNUNET_assert (strlen (tld) < strlen (name)); | 135 | GNUNET_assert(strlen(tld) < strlen(name)); |
138 | name[strlen (name) - strlen (tld) - 1] = '\0'; | 136 | name[strlen(name) - strlen(tld) - 1] = '\0'; |
139 | } | 137 | } |
140 | } | 138 | } |
141 | 139 | ||
142 | 140 | ||
@@ -148,15 +146,15 @@ eat_tld (char *name, const char *tld) | |||
148 | * @param rd array of @a rd_count records with the results | 146 | * @param rd array of @a rd_count records with the results |
149 | */ | 147 | */ |
150 | static void | 148 | static void |
151 | process_lookup_result (void *cls, | 149 | process_lookup_result(void *cls, |
152 | uint32_t rd_count, | 150 | uint32_t rd_count, |
153 | const struct GNUNET_GNSRECORD_Data *rd) | 151 | const struct GNUNET_GNSRECORD_Data *rd) |
154 | { | 152 | { |
155 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; | 153 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; |
156 | 154 | ||
157 | ltr->lr = NULL; | 155 | ltr->lr = NULL; |
158 | ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd); | 156 | ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd); |
159 | GNUNET_GNS_lookup_with_tld_cancel (ltr); | 157 | GNUNET_GNS_lookup_with_tld_cancel(ltr); |
160 | } | 158 | } |
161 | 159 | ||
162 | 160 | ||
@@ -167,16 +165,16 @@ process_lookup_result (void *cls, | |||
167 | * @param pkey public key to use for the zone, can be NULL | 165 | * @param pkey public key to use for the zone, can be NULL |
168 | */ | 166 | */ |
169 | static void | 167 | static void |
170 | lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, | 168 | lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr, |
171 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 169 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) |
172 | { | 170 | { |
173 | ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle, | 171 | ltr->lr = GNUNET_GNS_lookup(ltr->gns_handle, |
174 | ltr->name, | 172 | ltr->name, |
175 | pkey, | 173 | pkey, |
176 | ltr->type, | 174 | ltr->type, |
177 | ltr->options, | 175 | ltr->options, |
178 | &process_lookup_result, | 176 | &process_lookup_result, |
179 | ltr); | 177 | ltr); |
180 | } | 178 | } |
181 | 179 | ||
182 | 180 | ||
@@ -190,38 +188,38 @@ lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, | |||
190 | * @param name name of the ego | 188 | * @param name name of the ego |
191 | */ | 189 | */ |
192 | static void | 190 | static void |
193 | identity_zone_cb (void *cls, | 191 | identity_zone_cb(void *cls, |
194 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 192 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
195 | const char *ego_name) | 193 | const char *ego_name) |
196 | { | 194 | { |
197 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; | 195 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; |
198 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 196 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
199 | 197 | ||
200 | ltr->id_co = NULL; | 198 | ltr->id_co = NULL; |
201 | if (NULL == priv) | 199 | if (NULL == priv) |
202 | { | 200 | { |
203 | /* no matching ego found */ | 201 | /* no matching ego found */ |
204 | ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); | 202 | ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_NO, 0, NULL); |
205 | return; | 203 | return; |
206 | } | 204 | } |
207 | /* Final case: TLD matches one of our egos */ | 205 | /* Final case: TLD matches one of our egos */ |
208 | if (0 == strcmp (ltr->name, ego_name)) | 206 | if (0 == strcmp(ltr->name, ego_name)) |
209 | { | 207 | { |
210 | /* name matches ego name perfectly, only "@" remains */ | 208 | /* name matches ego name perfectly, only "@" remains */ |
211 | strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); | 209 | strcpy(ltr->name, GNUNET_GNS_EMPTY_LABEL_AT); |
212 | } | 210 | } |
213 | else | 211 | else |
214 | { | 212 | { |
215 | GNUNET_assert (strlen (ego_name) < strlen (ltr->name)); | 213 | GNUNET_assert(strlen(ego_name) < strlen(ltr->name)); |
216 | ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0'; | 214 | ltr->name[strlen(ltr->name) - strlen(ego_name) - 1] = '\0'; |
217 | } | 215 | } |
218 | /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ | 216 | /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */ |
219 | if (NULL == strchr (ltr->name, (unsigned char) '.')) | 217 | if (NULL == strchr(ltr->name, (unsigned char)'.')) |
220 | ltr->options = GNUNET_GNS_LO_NO_DHT; | 218 | ltr->options = GNUNET_GNS_LO_NO_DHT; |
221 | else | 219 | else |
222 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; | 220 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; |
223 | GNUNET_CRYPTO_ecdsa_key_get_public (priv, &pkey); | 221 | GNUNET_CRYPTO_ecdsa_key_get_public(priv, &pkey); |
224 | lookup_with_public_key (ltr, &pkey); | 222 | lookup_with_public_key(ltr, &pkey); |
225 | } | 223 | } |
226 | 224 | ||
227 | 225 | ||
@@ -239,12 +237,12 @@ identity_zone_cb (void *cls, | |||
239 | * @return handle to the get request, NULL on error (i.e. bad configuration) | 237 | * @return handle to the get request, NULL on error (i.e. bad configuration) |
240 | */ | 238 | */ |
241 | struct GNUNET_GNS_LookupWithTldRequest * | 239 | struct GNUNET_GNS_LookupWithTldRequest * |
242 | GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | 240 | GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, |
243 | const char *name, | 241 | const char *name, |
244 | uint32_t type, | 242 | uint32_t type, |
245 | enum GNUNET_GNS_LocalOptions options, | 243 | enum GNUNET_GNS_LocalOptions options, |
246 | GNUNET_GNS_LookupResultProcessor2 proc, | 244 | GNUNET_GNS_LookupResultProcessor2 proc, |
247 | void *proc_cls) | 245 | void *proc_cls) |
248 | { | 246 | { |
249 | struct GNUNET_GNS_LookupWithTldRequest *ltr; | 247 | struct GNUNET_GNS_LookupWithTldRequest *ltr; |
250 | const char *tld; | 248 | const char *tld; |
@@ -252,70 +250,70 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
252 | char *zonestr; | 250 | char *zonestr; |
253 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 251 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
254 | 252 | ||
255 | ltr = GNUNET_new (struct GNUNET_GNS_LookupWithTldRequest); | 253 | ltr = GNUNET_new(struct GNUNET_GNS_LookupWithTldRequest); |
256 | ltr->gns_handle = handle; | 254 | ltr->gns_handle = handle; |
257 | ltr->name = GNUNET_strdup (name); | 255 | ltr->name = GNUNET_strdup(name); |
258 | ltr->type = type; | 256 | ltr->type = type; |
259 | ltr->options = options; | 257 | ltr->options = options; |
260 | ltr->lookup_proc = proc; | 258 | ltr->lookup_proc = proc; |
261 | ltr->lookup_proc_cls = proc_cls; | 259 | ltr->lookup_proc_cls = proc_cls; |
262 | /* start with trivial case: TLD is zkey */ | 260 | /* start with trivial case: TLD is zkey */ |
263 | tld = get_tld (ltr->name); | 261 | tld = get_tld(ltr->name); |
264 | if (GNUNET_OK == | 262 | if (GNUNET_OK == |
265 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tld, strlen (tld), &pkey)) | 263 | GNUNET_CRYPTO_ecdsa_public_key_from_string(tld, strlen(tld), &pkey)) |
266 | { | 264 | { |
267 | eat_tld (ltr->name, tld); | 265 | eat_tld(ltr->name, tld); |
268 | lookup_with_public_key (ltr, &pkey); | 266 | lookup_with_public_key(ltr, &pkey); |
269 | return ltr; | 267 | return ltr; |
270 | } | 268 | } |
271 | 269 | ||
272 | /* second case: domain is mapped in our configuration file */ | 270 | /* second case: domain is mapped in our configuration file */ |
273 | for (const char *domain = name; NULL != domain; | 271 | for (const char *domain = name; NULL != domain; |
274 | domain = strchr (domain, (unsigned char) '.')) | 272 | domain = strchr(domain, (unsigned char)'.')) |
275 | { | ||
276 | if ('.' == domain[0]) | ||
277 | domain++; | ||
278 | GNUNET_asprintf (&dot_tld, ".%s", domain); | ||
279 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (handle->cfg, | ||
280 | "gns", | ||
281 | dot_tld, | ||
282 | &zonestr)) | ||
283 | { | 273 | { |
284 | if (GNUNET_OK != | 274 | if ('.' == domain[0]) |
285 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zonestr, | 275 | domain++; |
286 | strlen (zonestr), | 276 | GNUNET_asprintf(&dot_tld, ".%s", domain); |
287 | &pkey)) | 277 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(handle->cfg, |
288 | { | 278 | "gns", |
289 | GNUNET_log_config_invalid ( | 279 | dot_tld, |
290 | GNUNET_ERROR_TYPE_ERROR, | 280 | &zonestr)) |
291 | "gns", | 281 | { |
292 | dot_tld, | 282 | if (GNUNET_OK != |
293 | _ ("Expected a base32-encoded public zone key\n")); | 283 | GNUNET_CRYPTO_ecdsa_public_key_from_string(zonestr, |
294 | GNUNET_free (zonestr); | 284 | strlen(zonestr), |
295 | GNUNET_free (dot_tld); | 285 | &pkey)) |
296 | GNUNET_free (ltr->name); | 286 | { |
297 | GNUNET_free (ltr); | 287 | GNUNET_log_config_invalid( |
298 | return NULL; | 288 | GNUNET_ERROR_TYPE_ERROR, |
299 | } | 289 | "gns", |
300 | eat_tld (ltr->name, &dot_tld[1]); | 290 | dot_tld, |
301 | GNUNET_free (zonestr); | 291 | _("Expected a base32-encoded public zone key\n")); |
302 | GNUNET_free (dot_tld); | 292 | GNUNET_free(zonestr); |
303 | lookup_with_public_key (ltr, &pkey); | 293 | GNUNET_free(dot_tld); |
304 | return ltr; | 294 | GNUNET_free(ltr->name); |
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 | } | 305 | } |
306 | GNUNET_free (dot_tld); | ||
307 | } | ||
308 | ltr->id_co = | 306 | ltr->id_co = |
309 | GNUNET_IDENTITY_ego_lookup_by_suffix (ltr->gns_handle->cfg, | 307 | GNUNET_IDENTITY_ego_lookup_by_suffix(ltr->gns_handle->cfg, |
310 | ltr->name, | 308 | ltr->name, |
311 | &identity_zone_cb, | 309 | &identity_zone_cb, |
312 | ltr); | 310 | ltr); |
313 | if (NULL == ltr->id_co) | 311 | if (NULL == ltr->id_co) |
314 | { | 312 | { |
315 | GNUNET_free (ltr->name); | 313 | GNUNET_free(ltr->name); |
316 | GNUNET_free (ltr); | 314 | GNUNET_free(ltr); |
317 | return NULL; | 315 | return NULL; |
318 | } | 316 | } |
319 | return ltr; | 317 | return ltr; |
320 | } | 318 | } |
321 | 319 | ||
@@ -327,23 +325,23 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
327 | * @return closure from the lookup result processor | 325 | * @return closure from the lookup result processor |
328 | */ | 326 | */ |
329 | void * | 327 | void * |
330 | GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr) | 328 | GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr) |
331 | { | 329 | { |
332 | void *ret = ltr->lookup_proc_cls; | 330 | void *ret = ltr->lookup_proc_cls; |
333 | 331 | ||
334 | if (NULL != ltr->id_co) | 332 | if (NULL != ltr->id_co) |
335 | { | 333 | { |
336 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (ltr->id_co); | 334 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(ltr->id_co); |
337 | ltr->id_co = NULL; | 335 | ltr->id_co = NULL; |
338 | } | 336 | } |
339 | if (NULL != ltr->lr) | 337 | if (NULL != ltr->lr) |
340 | { | 338 | { |
341 | GNUNET_GNS_lookup_cancel (ltr->lr); | 339 | GNUNET_GNS_lookup_cancel(ltr->lr); |
342 | ltr->lr = NULL; | 340 | ltr->lr = NULL; |
343 | } | 341 | } |
344 | GNUNET_free_non_null (ltr->longest_match); | 342 | GNUNET_free_non_null(ltr->longest_match); |
345 | GNUNET_free (ltr->name); | 343 | GNUNET_free(ltr->name); |
346 | GNUNET_free (ltr); | 344 | GNUNET_free(ltr); |
347 | return ret; | 345 | return ret; |
348 | } | 346 | } |
349 | 347 | ||
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c index 368afbbf5..181c30d8d 100644 --- a/src/gns/gnunet-bcd.c +++ b/src/gns/gnunet-bcd.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file gns/gnunet-bcd.c | 22 | * @file gns/gnunet-bcd.c |
@@ -81,8 +81,7 @@ static char *resfile; | |||
81 | static uint16_t port = 8888; | 81 | static uint16_t port = 8888; |
82 | 82 | ||
83 | 83 | ||
84 | struct Entry | 84 | struct Entry { |
85 | { | ||
86 | const char *formname; | 85 | const char *formname; |
87 | const char *texname; | 86 | const char *texname; |
88 | }; | 87 | }; |
@@ -92,175 +91,175 @@ struct Entry | |||
92 | * Main request handler. | 91 | * Main request handler. |
93 | */ | 92 | */ |
94 | static int | 93 | static int |
95 | access_handler_callback (void *cls, | 94 | access_handler_callback(void *cls, |
96 | struct MHD_Connection *connection, | 95 | struct MHD_Connection *connection, |
97 | const char *url, | 96 | const char *url, |
98 | const char *method, | 97 | const char *method, |
99 | const char *version, | 98 | const char *version, |
100 | const char *upload_data, | 99 | const char *upload_data, |
101 | size_t *upload_data_size, | 100 | size_t *upload_data_size, |
102 | void **con_cls) | 101 | void **con_cls) |
103 | { | 102 | { |
104 | static int dummy; | 103 | static int dummy; |
105 | static const struct Entry map[] = {{"prefix", "prefix"}, | 104 | static const struct Entry map[] = { { "prefix", "prefix" }, |
106 | {"name", "name"}, | 105 | { "name", "name" }, |
107 | {"suffix", "suffix"}, | 106 | { "suffix", "suffix" }, |
108 | {"street", "street"}, | 107 | { "street", "street" }, |
109 | {"city", "city"}, | 108 | { "city", "city" }, |
110 | {"phone", "phone"}, | 109 | { "phone", "phone" }, |
111 | {"fax", "fax"}, | 110 | { "fax", "fax" }, |
112 | {"email", "email"}, | 111 | { "email", "email" }, |
113 | {"homepage", "homepage"}, | 112 | { "homepage", "homepage" }, |
114 | {"orga", "orga"}, | 113 | { "orga", "orga" }, |
115 | {"departmenti18n", "departmentde"}, | 114 | { "departmenti18n", "departmentde" }, |
116 | {"departmenten", "departmenten"}, | 115 | { "departmenten", "departmenten" }, |
117 | {"subdepartmenti18n", "subdepartmentde"}, | 116 | { "subdepartmenti18n", "subdepartmentde" }, |
118 | {"subdepartmenten", "subdepartmenten"}, | 117 | { "subdepartmenten", "subdepartmenten" }, |
119 | {"jobtitlei18n", "jobtitlegerman"}, | 118 | { "jobtitlei18n", "jobtitlegerman" }, |
120 | {"jobtitleen", "jobtitleenglish"}, | 119 | { "jobtitleen", "jobtitleenglish" }, |
121 | {"subdepartmenten", "subdepartmenten"}, | 120 | { "subdepartmenten", "subdepartmenten" }, |
122 | {NULL, NULL}}; | 121 | { NULL, NULL } }; |
123 | 122 | ||
124 | (void) cls; | 123 | (void)cls; |
125 | (void) version; | 124 | (void)version; |
126 | (void) upload_data; | 125 | (void)upload_data; |
127 | (void) upload_data_size; | 126 | (void)upload_data_size; |
128 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 127 | if (0 != strcmp(method, MHD_HTTP_METHOD_GET)) |
129 | { | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
131 | _ ("Refusing `%s' request to HTTP server\n"), | ||
132 | method); | ||
133 | return MHD_NO; | ||
134 | } | ||
135 | if (NULL == *con_cls) | ||
136 | { | ||
137 | (*con_cls) = &dummy; | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n"); | ||
139 | return MHD_YES; /* send 100 continue */ | ||
140 | } | ||
141 | if (0 == strcasecmp (url, "/")) | ||
142 | return MHD_queue_response (connection, MHD_HTTP_OK, main_response); | ||
143 | if (0 == strcasecmp (url, "/submit.pdf")) | ||
144 | { | ||
145 | unsigned int i; | ||
146 | char *p; | ||
147 | char *tmp; | ||
148 | char *deffile; | ||
149 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
150 | size_t slen; | ||
151 | FILE *f; | ||
152 | struct stat st; | ||
153 | struct MHD_Response *response; | ||
154 | int fd; | ||
155 | int ret; | ||
156 | |||
157 | const char *gpg_fp = MHD_lookup_connection_value (connection, | ||
158 | MHD_GET_ARGUMENT_KIND, | ||
159 | "gpgfingerprint"); | ||
160 | const char *gns_nick = MHD_lookup_connection_value (connection, | ||
161 | MHD_GET_ARGUMENT_KIND, | ||
162 | "gnsnick"); | ||
163 | const char *gnskey = | ||
164 | MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "gnskey"); | ||
165 | if ((NULL == gnskey) || | ||
166 | (GNUNET_OK != | ||
167 | GNUNET_CRYPTO_ecdsa_public_key_from_string (gnskey, | ||
168 | strlen (gnskey), | ||
169 | &pub))) | ||
170 | { | ||
171 | return MHD_queue_response (connection, | ||
172 | MHD_HTTP_OK, | ||
173 | invalid_gnskey_response); | ||
174 | } | ||
175 | tmp = GNUNET_DISK_mkdtemp (gnskey); | ||
176 | if (NULL == tmp) | ||
177 | { | ||
178 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mktemp", gnskey); | ||
179 | return MHD_NO; | ||
180 | } | ||
181 | GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex"); | ||
182 | f = fopen (deffile, "w"); | ||
183 | if (NULL == f) | ||
184 | { | 128 | { |
185 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile); | 129 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
186 | GNUNET_free (deffile); | 130 | _("Refusing `%s' request to HTTP server\n"), |
187 | GNUNET_DISK_directory_remove (tmp); | 131 | method); |
188 | GNUNET_free (tmp); | ||
189 | return MHD_NO; | 132 | return MHD_NO; |
190 | } | 133 | } |
191 | for (i = 0; NULL != map[i].formname; i++) | 134 | if (NULL == *con_cls) |
192 | { | ||
193 | const char *val = MHD_lookup_connection_value (connection, | ||
194 | MHD_GET_ARGUMENT_KIND, | ||
195 | map[i].formname); | ||
196 | if (NULL != val) | ||
197 | fprintf (f, "\\def\\%s{%s}\n", map[i].texname, val); | ||
198 | else | ||
199 | fprintf (f, "\\def\\%s{}\n", map[i].texname); | ||
200 | } | ||
201 | if (NULL != gpg_fp) | ||
202 | { | ||
203 | char *gpg1; | ||
204 | char *gpg2; | ||
205 | |||
206 | slen = strlen (gpg_fp); | ||
207 | gpg1 = GNUNET_strndup (gpg_fp, slen / 2); | ||
208 | gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]); | ||
209 | fprintf (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2); | ||
210 | GNUNET_free (gpg2); | ||
211 | GNUNET_free (gpg1); | ||
212 | } | ||
213 | fprintf (f, | ||
214 | "\\def\\gns{%s/%s}\n", | ||
215 | gnskey, | ||
216 | (NULL == gns_nick) ? "" : gns_nick); | ||
217 | fclose (f); | ||
218 | GNUNET_asprintf ( | ||
219 | &p, | ||
220 | "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null", | ||
221 | tmp, | ||
222 | resfile); | ||
223 | GNUNET_free (deffile); | ||
224 | ret = system (p); | ||
225 | if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret))) | ||
226 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "system", p); | ||
227 | GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "gns-bcd.pdf"); | ||
228 | fd = open (deffile, O_RDONLY); | ||
229 | if (-1 == fd) | ||
230 | { | 135 | { |
231 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile); | 136 | (*con_cls) = &dummy; |
232 | GNUNET_free (deffile); | 137 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n"); |
233 | GNUNET_free (p); | 138 | return MHD_YES; /* send 100 continue */ |
234 | GNUNET_DISK_directory_remove (tmp); | ||
235 | GNUNET_free (tmp); | ||
236 | return MHD_NO; | ||
237 | } | 139 | } |
238 | GNUNET_break (0 == STAT (deffile, &st)); | 140 | if (0 == strcasecmp(url, "/")) |
239 | if (NULL == | 141 | return MHD_queue_response(connection, MHD_HTTP_OK, main_response); |
240 | (response = MHD_create_response_from_fd ((size_t) st.st_size, fd))) | 142 | if (0 == strcasecmp(url, "/submit.pdf")) |
241 | { | 143 | { |
242 | GNUNET_break (0); | 144 | unsigned int i; |
243 | GNUNET_break (0 == CLOSE (fd)); | 145 | char *p; |
244 | GNUNET_free (deffile); | 146 | char *tmp; |
245 | GNUNET_free (p); | 147 | char *deffile; |
246 | GNUNET_DISK_directory_remove (tmp); | 148 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
247 | GNUNET_free (tmp); | 149 | size_t slen; |
248 | return MHD_NO; | 150 | FILE *f; |
249 | } | 151 | struct stat st; |
250 | (void) MHD_add_response_header (response, | 152 | struct MHD_Response *response; |
153 | int fd; | ||
154 | int ret; | ||
155 | |||
156 | const char *gpg_fp = MHD_lookup_connection_value(connection, | ||
157 | MHD_GET_ARGUMENT_KIND, | ||
158 | "gpgfingerprint"); | ||
159 | const char *gns_nick = MHD_lookup_connection_value(connection, | ||
160 | MHD_GET_ARGUMENT_KIND, | ||
161 | "gnsnick"); | ||
162 | const char *gnskey = | ||
163 | MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "gnskey"); | ||
164 | if ((NULL == gnskey) || | ||
165 | (GNUNET_OK != | ||
166 | GNUNET_CRYPTO_ecdsa_public_key_from_string(gnskey, | ||
167 | strlen(gnskey), | ||
168 | &pub))) | ||
169 | { | ||
170 | return MHD_queue_response(connection, | ||
171 | MHD_HTTP_OK, | ||
172 | invalid_gnskey_response); | ||
173 | } | ||
174 | tmp = GNUNET_DISK_mkdtemp(gnskey); | ||
175 | if (NULL == tmp) | ||
176 | { | ||
177 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mktemp", gnskey); | ||
178 | return MHD_NO; | ||
179 | } | ||
180 | GNUNET_asprintf(&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex"); | ||
181 | f = fopen(deffile, "w"); | ||
182 | if (NULL == f) | ||
183 | { | ||
184 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", deffile); | ||
185 | GNUNET_free(deffile); | ||
186 | GNUNET_DISK_directory_remove(tmp); | ||
187 | GNUNET_free(tmp); | ||
188 | return MHD_NO; | ||
189 | } | ||
190 | for (i = 0; NULL != map[i].formname; i++) | ||
191 | { | ||
192 | const char *val = MHD_lookup_connection_value(connection, | ||
193 | MHD_GET_ARGUMENT_KIND, | ||
194 | map[i].formname); | ||
195 | if (NULL != val) | ||
196 | fprintf(f, "\\def\\%s{%s}\n", map[i].texname, val); | ||
197 | else | ||
198 | fprintf(f, "\\def\\%s{}\n", map[i].texname); | ||
199 | } | ||
200 | if (NULL != gpg_fp) | ||
201 | { | ||
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, | ||
251 | MHD_HTTP_HEADER_CONTENT_TYPE, | 250 | MHD_HTTP_HEADER_CONTENT_TYPE, |
252 | "application/pdf"); | 251 | "application/pdf"); |
253 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 252 | ret = MHD_queue_response(connection, MHD_HTTP_OK, response); |
254 | MHD_destroy_response (response); | 253 | MHD_destroy_response(response); |
255 | GNUNET_free (deffile); | 254 | GNUNET_free(deffile); |
256 | GNUNET_free (p); | 255 | GNUNET_free(p); |
257 | GNUNET_DISK_directory_remove (tmp); | 256 | GNUNET_DISK_directory_remove(tmp); |
258 | GNUNET_free (tmp); | 257 | GNUNET_free(tmp); |
259 | return ret; | 258 | return ret; |
260 | } | 259 | } |
261 | return MHD_queue_response (connection, | 260 | return MHD_queue_response(connection, |
262 | MHD_HTTP_NOT_FOUND, | 261 | MHD_HTTP_NOT_FOUND, |
263 | not_found_response); | 262 | not_found_response); |
264 | } | 263 | } |
265 | 264 | ||
266 | 265 | ||
@@ -269,7 +268,7 @@ access_handler_callback (void *cls, | |||
269 | * starts the task waiting for them. | 268 | * starts the task waiting for them. |
270 | */ | 269 | */ |
271 | static struct GNUNET_SCHEDULER_Task * | 270 | static struct GNUNET_SCHEDULER_Task * |
272 | prepare_daemon (struct MHD_Daemon *daemon_handle); | 271 | prepare_daemon(struct MHD_Daemon *daemon_handle); |
273 | 272 | ||
274 | 273 | ||
275 | /** | 274 | /** |
@@ -277,13 +276,13 @@ prepare_daemon (struct MHD_Daemon *daemon_handle); | |||
277 | * and schedule the next run. | 276 | * and schedule the next run. |
278 | */ | 277 | */ |
279 | static void | 278 | static void |
280 | run_daemon (void *cls) | 279 | run_daemon(void *cls) |
281 | { | 280 | { |
282 | struct MHD_Daemon *daemon_handle = cls; | 281 | struct MHD_Daemon *daemon_handle = cls; |
283 | 282 | ||
284 | http_task = NULL; | 283 | http_task = NULL; |
285 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); | 284 | GNUNET_assert(MHD_YES == MHD_run(daemon_handle)); |
286 | http_task = prepare_daemon (daemon_handle); | 285 | http_task = prepare_daemon(daemon_handle); |
287 | } | 286 | } |
288 | 287 | ||
289 | 288 | ||
@@ -292,7 +291,7 @@ run_daemon (void *cls) | |||
292 | * starts the task waiting for them. | 291 | * starts the task waiting for them. |
293 | */ | 292 | */ |
294 | static struct GNUNET_SCHEDULER_Task * | 293 | static struct GNUNET_SCHEDULER_Task * |
295 | prepare_daemon (struct MHD_Daemon *daemon_handle) | 294 | prepare_daemon(struct MHD_Daemon *daemon_handle) |
296 | { | 295 | { |
297 | struct GNUNET_SCHEDULER_Task *ret; | 296 | struct GNUNET_SCHEDULER_Task *ret; |
298 | fd_set rs; | 297 | fd_set rs; |
@@ -305,28 +304,28 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
305 | int haveto; | 304 | int haveto; |
306 | struct GNUNET_TIME_Relative tv; | 305 | struct GNUNET_TIME_Relative tv; |
307 | 306 | ||
308 | FD_ZERO (&rs); | 307 | FD_ZERO(&rs); |
309 | FD_ZERO (&ws); | 308 | FD_ZERO(&ws); |
310 | FD_ZERO (&es); | 309 | FD_ZERO(&es); |
311 | wrs = GNUNET_NETWORK_fdset_create (); | 310 | wrs = GNUNET_NETWORK_fdset_create(); |
312 | wws = GNUNET_NETWORK_fdset_create (); | 311 | wws = GNUNET_NETWORK_fdset_create(); |
313 | max = -1; | 312 | max = -1; |
314 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); | 313 | GNUNET_assert(MHD_YES == MHD_get_fdset(daemon_handle, &rs, &ws, &es, &max)); |
315 | haveto = MHD_get_timeout (daemon_handle, &timeout); | 314 | haveto = MHD_get_timeout(daemon_handle, &timeout); |
316 | if (haveto == MHD_YES) | 315 | if (haveto == MHD_YES) |
317 | tv.rel_value_us = (uint64_t) timeout * 1000LL; | 316 | tv.rel_value_us = (uint64_t)timeout * 1000LL; |
318 | else | 317 | else |
319 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 318 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
320 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | 319 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); |
321 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 320 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); |
322 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 321 | ret = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, |
323 | tv, | 322 | tv, |
324 | wrs, | 323 | wrs, |
325 | wws, | 324 | wws, |
326 | &run_daemon, | 325 | &run_daemon, |
327 | daemon_handle); | 326 | daemon_handle); |
328 | GNUNET_NETWORK_fdset_destroy (wrs); | 327 | GNUNET_NETWORK_fdset_destroy(wrs); |
329 | GNUNET_NETWORK_fdset_destroy (wws); | 328 | GNUNET_NETWORK_fdset_destroy(wws); |
330 | return ret; | 329 | return ret; |
331 | } | 330 | } |
332 | 331 | ||
@@ -337,41 +336,41 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
337 | * @return #GNUNET_OK on success | 336 | * @return #GNUNET_OK on success |
338 | */ | 337 | */ |
339 | static int | 338 | static int |
340 | server_start () | 339 | server_start() |
341 | { | 340 | { |
342 | if (0 == port) | 341 | if (0 == port) |
343 | { | 342 | { |
344 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 343 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
345 | _ ("Invalid port number %u. Exiting.\n"), | 344 | _("Invalid port number %u. Exiting.\n"), |
346 | port); | 345 | port); |
347 | return GNUNET_SYSERR; | 346 | return GNUNET_SYSERR; |
348 | } | 347 | } |
349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 348 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
350 | _ ("Businesscard HTTP server starts on %u\n"), | 349 | _("Businesscard HTTP server starts on %u\n"), |
351 | port); | 350 | port); |
352 | daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG, | 351 | daemon_handle = MHD_start_daemon(MHD_USE_DUAL_STACK | MHD_USE_DEBUG, |
353 | port, | 352 | port, |
354 | NULL /* accept_policy_callback */, | 353 | NULL /* accept_policy_callback */, |
355 | NULL, | 354 | NULL, |
356 | &access_handler_callback, | 355 | &access_handler_callback, |
357 | NULL, | 356 | NULL, |
358 | MHD_OPTION_CONNECTION_LIMIT, | 357 | MHD_OPTION_CONNECTION_LIMIT, |
359 | (unsigned int) 512, | 358 | (unsigned int)512, |
360 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 359 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
361 | (unsigned int) 2, | 360 | (unsigned int)2, |
362 | MHD_OPTION_CONNECTION_TIMEOUT, | 361 | MHD_OPTION_CONNECTION_TIMEOUT, |
363 | (unsigned int) 60, | 362 | (unsigned int)60, |
364 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 363 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
365 | (size_t) (16 * 1024), | 364 | (size_t)(16 * 1024), |
366 | MHD_OPTION_END); | 365 | MHD_OPTION_END); |
367 | if (NULL == daemon_handle) | 366 | if (NULL == daemon_handle) |
368 | { | 367 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 368 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
370 | _ ("Could not start businesscard HTTP server on port %u\n"), | 369 | _("Could not start businesscard HTTP server on port %u\n"), |
371 | (unsigned int) port); | 370 | (unsigned int)port); |
372 | return GNUNET_SYSERR; | 371 | return GNUNET_SYSERR; |
373 | } | 372 | } |
374 | http_task = prepare_daemon (daemon_handle); | 373 | http_task = prepare_daemon(daemon_handle); |
375 | return GNUNET_OK; | 374 | return GNUNET_OK; |
376 | } | 375 | } |
377 | 376 | ||
@@ -380,40 +379,40 @@ server_start () | |||
380 | * Stop HTTP server. | 379 | * Stop HTTP server. |
381 | */ | 380 | */ |
382 | static void | 381 | static void |
383 | server_stop (void *cls) | 382 | server_stop(void *cls) |
384 | { | 383 | { |
385 | (void) cls; | 384 | (void)cls; |
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n"); | 385 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n"); |
387 | if (NULL != http_task) | 386 | if (NULL != http_task) |
388 | { | 387 | { |
389 | GNUNET_SCHEDULER_cancel (http_task); | 388 | GNUNET_SCHEDULER_cancel(http_task); |
390 | http_task = NULL; | 389 | http_task = NULL; |
391 | } | 390 | } |
392 | if (NULL != daemon_handle) | 391 | if (NULL != daemon_handle) |
393 | { | 392 | { |
394 | MHD_stop_daemon (daemon_handle); | 393 | MHD_stop_daemon(daemon_handle); |
395 | daemon_handle = NULL; | 394 | daemon_handle = NULL; |
396 | } | 395 | } |
397 | if (NULL != main_response) | 396 | if (NULL != main_response) |
398 | { | 397 | { |
399 | MHD_destroy_response (main_response); | 398 | MHD_destroy_response(main_response); |
400 | main_response = NULL; | 399 | main_response = NULL; |
401 | } | 400 | } |
402 | if (NULL != invalid_gnskey_response) | 401 | if (NULL != invalid_gnskey_response) |
403 | { | 402 | { |
404 | MHD_destroy_response (invalid_gnskey_response); | 403 | MHD_destroy_response(invalid_gnskey_response); |
405 | invalid_gnskey_response = NULL; | 404 | invalid_gnskey_response = NULL; |
406 | } | 405 | } |
407 | if (NULL != not_found_response) | 406 | if (NULL != not_found_response) |
408 | { | 407 | { |
409 | MHD_destroy_response (not_found_response); | 408 | MHD_destroy_response(not_found_response); |
410 | not_found_response = NULL; | 409 | not_found_response = NULL; |
411 | } | 410 | } |
412 | if (NULL != resfile) | 411 | if (NULL != resfile) |
413 | { | 412 | { |
414 | GNUNET_free (resfile); | 413 | GNUNET_free(resfile); |
415 | resfile = NULL; | 414 | resfile = NULL; |
416 | } | 415 | } |
417 | } | 416 | } |
418 | 417 | ||
419 | 418 | ||
@@ -426,66 +425,66 @@ server_stop (void *cls) | |||
426 | * @param c configuration | 425 | * @param c configuration |
427 | */ | 426 | */ |
428 | static void | 427 | static void |
429 | run (void *cls, | 428 | run(void *cls, |
430 | char *const *args, | 429 | char *const *args, |
431 | const char *cfgfile, | 430 | const char *cfgfile, |
432 | const struct GNUNET_CONFIGURATION_Handle *c) | 431 | const struct GNUNET_CONFIGURATION_Handle *c) |
433 | { | 432 | { |
434 | struct stat st; | 433 | struct stat st; |
435 | char *dir; | 434 | char *dir; |
436 | char *fn; | 435 | char *fn; |
437 | int fd; | 436 | int fd; |
438 | 437 | ||
439 | (void) cls; | 438 | (void)cls; |
440 | (void) args; | 439 | (void)args; |
441 | (void) cfgfile; | 440 | (void)cfgfile; |
442 | cfg = c; | 441 | cfg = c; |
443 | dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 442 | dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); |
444 | GNUNET_assert (NULL != dir); | 443 | GNUNET_assert(NULL != dir); |
445 | GNUNET_asprintf (&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html"); | 444 | GNUNET_asprintf(&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html"); |
446 | GNUNET_asprintf (&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex"); | 445 | GNUNET_asprintf(&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex"); |
447 | GNUNET_free (dir); | 446 | GNUNET_free(dir); |
448 | fd = open (fn, O_RDONLY); | 447 | fd = open(fn, O_RDONLY); |
449 | if (-1 == fd) | 448 | if (-1 == fd) |
450 | { | 449 | { |
451 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); | 450 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); |
452 | GNUNET_free (fn); | 451 | GNUNET_free(fn); |
453 | return; | 452 | return; |
454 | } | 453 | } |
455 | if (0 != STAT (fn, &st)) | 454 | if (0 != STAT(fn, &st)) |
456 | { | 455 | { |
457 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); | 456 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); |
458 | GNUNET_free (fn); | 457 | GNUNET_free(fn); |
459 | GNUNET_break (0 == CLOSE (fd)); | 458 | GNUNET_break(0 == CLOSE(fd)); |
460 | return; | 459 | return; |
461 | } | 460 | } |
462 | GNUNET_free (fn); | 461 | GNUNET_free(fn); |
463 | if (NULL == | 462 | if (NULL == |
464 | (main_response = MHD_create_response_from_fd ((size_t) st.st_size, fd))) | 463 | (main_response = MHD_create_response_from_fd((size_t)st.st_size, fd))) |
465 | { | 464 | { |
466 | GNUNET_break (0); | 465 | GNUNET_break(0); |
467 | GNUNET_break (0 == CLOSE (fd)); | 466 | GNUNET_break(0 == CLOSE(fd)); |
468 | return; | 467 | return; |
469 | } | 468 | } |
470 | (void) MHD_add_response_header (main_response, | 469 | (void)MHD_add_response_header(main_response, |
471 | MHD_HTTP_HEADER_CONTENT_TYPE, | 470 | MHD_HTTP_HEADER_CONTENT_TYPE, |
472 | "text/html"); | 471 | "text/html"); |
473 | invalid_gnskey_response = | 472 | invalid_gnskey_response = |
474 | MHD_create_response_from_buffer (strlen (INVALID_GNSKEY), | 473 | MHD_create_response_from_buffer(strlen(INVALID_GNSKEY), |
475 | INVALID_GNSKEY, | 474 | INVALID_GNSKEY, |
476 | MHD_RESPMEM_PERSISTENT); | 475 | MHD_RESPMEM_PERSISTENT); |
477 | (void) MHD_add_response_header (invalid_gnskey_response, | 476 | (void)MHD_add_response_header(invalid_gnskey_response, |
478 | MHD_HTTP_HEADER_CONTENT_TYPE, | 477 | MHD_HTTP_HEADER_CONTENT_TYPE, |
479 | "text/html"); | 478 | "text/html"); |
480 | not_found_response = MHD_create_response_from_buffer (strlen (NOT_FOUND), | 479 | not_found_response = MHD_create_response_from_buffer(strlen(NOT_FOUND), |
481 | NOT_FOUND, | 480 | NOT_FOUND, |
482 | MHD_RESPMEM_PERSISTENT); | 481 | MHD_RESPMEM_PERSISTENT); |
483 | (void) MHD_add_response_header (not_found_response, | 482 | (void)MHD_add_response_header(not_found_response, |
484 | MHD_HTTP_HEADER_CONTENT_TYPE, | 483 | MHD_HTTP_HEADER_CONTENT_TYPE, |
485 | "text/html"); | 484 | "text/html"); |
486 | if (GNUNET_OK != server_start ()) | 485 | if (GNUNET_OK != server_start()) |
487 | return; | 486 | return; |
488 | GNUNET_SCHEDULER_add_shutdown (&server_stop, NULL); | 487 | GNUNET_SCHEDULER_add_shutdown(&server_stop, NULL); |
489 | } | 488 | } |
490 | 489 | ||
491 | 490 | ||
@@ -497,33 +496,33 @@ run (void *cls, | |||
497 | * @return 0 ok, 1 on error | 496 | * @return 0 ok, 1 on error |
498 | */ | 497 | */ |
499 | int | 498 | int |
500 | main (int argc, char *const *argv) | 499 | main(int argc, char *const *argv) |
501 | { | 500 | { |
502 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 501 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
503 | 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 | int ret; | 510 | int ret; |
512 | 511 | ||
513 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 512 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
514 | return 2; | 513 | return 2; |
515 | GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL); | 514 | GNUNET_log_setup("gnunet-bcd", "WARNING", NULL); |
516 | ret = (GNUNET_OK == | 515 | ret = (GNUNET_OK == |
517 | GNUNET_PROGRAM_run (argc, | 516 | GNUNET_PROGRAM_run(argc, |
518 | argv, | 517 | argv, |
519 | "gnunet-bcd", | 518 | "gnunet-bcd", |
520 | _ ("GNUnet HTTP server to create business cards"), | 519 | _("GNUnet HTTP server to create business cards"), |
521 | options, | 520 | options, |
522 | &run, | 521 | &run, |
523 | NULL)) | 522 | NULL)) |
524 | ? 0 | 523 | ? 0 |
525 | : 1; | 524 | : 1; |
526 | GNUNET_free ((void *) argv); | 525 | GNUNET_free((void *)argv); |
527 | return ret; | 526 | return ret; |
528 | } | 527 | } |
529 | 528 | ||
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index d2eabf02c..4058aba99 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet-dns2gns.c | 21 | * @file gnunet-dns2gns.c |
22 | * @brief DNS server that translates DNS requests to GNS | 22 | * @brief DNS server that translates DNS requests to GNS |
@@ -37,8 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * Data kept per request. | 38 | * Data kept per request. |
39 | */ | 39 | */ |
40 | struct Request | 40 | struct Request { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Socket to use for sending the reply. | 42 | * Socket to use for sending the reply. |
44 | */ | 43 | */ |
@@ -156,39 +155,39 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
156 | * @param cls unused | 155 | * @param cls unused |
157 | */ | 156 | */ |
158 | static void | 157 | static void |
159 | do_shutdown (void *cls) | 158 | do_shutdown(void *cls) |
160 | { | 159 | { |
161 | (void) cls; | 160 | (void)cls; |
162 | if (NULL != t4) | 161 | if (NULL != t4) |
163 | { | 162 | { |
164 | GNUNET_SCHEDULER_cancel (t4); | 163 | GNUNET_SCHEDULER_cancel(t4); |
165 | t4 = NULL; | 164 | t4 = NULL; |
166 | } | 165 | } |
167 | if (NULL != t6) | 166 | if (NULL != t6) |
168 | { | 167 | { |
169 | GNUNET_SCHEDULER_cancel (t6); | 168 | GNUNET_SCHEDULER_cancel(t6); |
170 | t6 = NULL; | 169 | t6 = NULL; |
171 | } | 170 | } |
172 | if (NULL != listen_socket4) | 171 | if (NULL != listen_socket4) |
173 | { | 172 | { |
174 | GNUNET_NETWORK_socket_close (listen_socket4); | 173 | GNUNET_NETWORK_socket_close(listen_socket4); |
175 | listen_socket4 = NULL; | 174 | listen_socket4 = NULL; |
176 | } | 175 | } |
177 | if (NULL != listen_socket6) | 176 | if (NULL != listen_socket6) |
178 | { | 177 | { |
179 | GNUNET_NETWORK_socket_close (listen_socket6); | 178 | GNUNET_NETWORK_socket_close(listen_socket6); |
180 | listen_socket6 = NULL; | 179 | listen_socket6 = NULL; |
181 | } | 180 | } |
182 | if (NULL != gns) | 181 | if (NULL != gns) |
183 | { | 182 | { |
184 | GNUNET_GNS_disconnect (gns); | 183 | GNUNET_GNS_disconnect(gns); |
185 | gns = NULL; | 184 | gns = NULL; |
186 | } | 185 | } |
187 | if (NULL != dns_stub) | 186 | if (NULL != dns_stub) |
188 | { | 187 | { |
189 | GNUNET_DNSSTUB_stop (dns_stub); | 188 | GNUNET_DNSSTUB_stop(dns_stub); |
190 | dns_stub = NULL; | 189 | dns_stub = NULL; |
191 | } | 190 | } |
192 | } | 191 | } |
193 | 192 | ||
194 | 193 | ||
@@ -198,38 +197,38 @@ do_shutdown (void *cls) | |||
198 | * @param request context for the request. | 197 | * @param request context for the request. |
199 | */ | 198 | */ |
200 | static void | 199 | static void |
201 | send_response (struct Request *request) | 200 | send_response(struct Request *request) |
202 | { | 201 | { |
203 | char *buf; | 202 | char *buf; |
204 | size_t size; | 203 | size_t size; |
205 | ssize_t sret; | 204 | ssize_t sret; |
206 | 205 | ||
207 | if (GNUNET_SYSERR == | 206 | if (GNUNET_SYSERR == |
208 | GNUNET_DNSPARSER_pack (request->packet, | 207 | GNUNET_DNSPARSER_pack(request->packet, |
209 | UINT16_MAX /* is this not too much? */, | 208 | UINT16_MAX /* is this not too much? */, |
210 | &buf, | 209 | &buf, |
211 | &size)) | 210 | &size)) |
212 | { | 211 | { |
213 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 212 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
214 | _("Failed to pack DNS response into UDP packet!\n")); | 213 | _("Failed to pack DNS response into UDP packet!\n")); |
215 | } | 214 | } |
216 | else | 215 | else |
217 | { | 216 | { |
218 | sret = GNUNET_NETWORK_socket_sendto (request->lsock, | 217 | sret = GNUNET_NETWORK_socket_sendto(request->lsock, |
219 | buf, | 218 | buf, |
220 | size, | 219 | size, |
221 | request->addr, | 220 | request->addr, |
222 | request->addr_len); | 221 | request->addr_len); |
223 | if ( (sret < 0) || | 222 | if ((sret < 0) || |
224 | (size != (size_t) sret) ) | 223 | (size != (size_t)sret)) |
225 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 224 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
226 | "sendto"); | 225 | "sendto"); |
227 | GNUNET_free (buf); | 226 | GNUNET_free(buf); |
228 | } | 227 | } |
229 | GNUNET_SCHEDULER_cancel (request->timeout_task); | 228 | GNUNET_SCHEDULER_cancel(request->timeout_task); |
230 | GNUNET_DNSPARSER_free_packet (request->packet); | 229 | GNUNET_DNSPARSER_free_packet(request->packet); |
231 | GNUNET_free (request->udp_msg); | 230 | GNUNET_free(request->udp_msg); |
232 | GNUNET_free (request); | 231 | GNUNET_free(request); |
233 | } | 232 | } |
234 | 233 | ||
235 | 234 | ||
@@ -239,18 +238,18 @@ send_response (struct Request *request) | |||
239 | * @param cls `struct Request *` of the request to clean up | 238 | * @param cls `struct Request *` of the request to clean up |
240 | */ | 239 | */ |
241 | static void | 240 | static void |
242 | do_timeout (void *cls) | 241 | do_timeout(void *cls) |
243 | { | 242 | { |
244 | struct Request *request = cls; | 243 | struct Request *request = cls; |
245 | 244 | ||
246 | if (NULL != request->packet) | 245 | if (NULL != request->packet) |
247 | GNUNET_DNSPARSER_free_packet (request->packet); | 246 | GNUNET_DNSPARSER_free_packet(request->packet); |
248 | if (NULL != request->lookup) | 247 | if (NULL != request->lookup) |
249 | GNUNET_GNS_lookup_with_tld_cancel (request->lookup); | 248 | GNUNET_GNS_lookup_with_tld_cancel(request->lookup); |
250 | if (NULL != request->dns_lookup) | 249 | if (NULL != request->dns_lookup) |
251 | GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); | 250 | GNUNET_DNSSTUB_resolve_cancel(request->dns_lookup); |
252 | GNUNET_free (request->udp_msg); | 251 | GNUNET_free(request->udp_msg); |
253 | GNUNET_free (request); | 252 | GNUNET_free(request); |
254 | } | 253 | } |
255 | 254 | ||
256 | 255 | ||
@@ -262,28 +261,28 @@ do_timeout (void *cls) | |||
262 | * @param r size of the DNS payload | 261 | * @param r size of the DNS payload |
263 | */ | 262 | */ |
264 | static void | 263 | static void |
265 | dns_result_processor (void *cls, | 264 | dns_result_processor(void *cls, |
266 | const struct GNUNET_TUN_DnsHeader *dns, | 265 | const struct GNUNET_TUN_DnsHeader *dns, |
267 | size_t r) | 266 | size_t r) |
268 | { | 267 | { |
269 | struct Request *request = cls; | 268 | struct Request *request = cls; |
270 | 269 | ||
271 | if (NULL == dns) | 270 | if (NULL == dns) |
272 | { | 271 | { |
273 | /* DNSSTUB gave up, so we trigger timeout early */ | 272 | /* DNSSTUB gave up, so we trigger timeout early */ |
274 | GNUNET_SCHEDULER_cancel (request->timeout_task); | 273 | GNUNET_SCHEDULER_cancel(request->timeout_task); |
275 | do_timeout (request); | 274 | do_timeout(request); |
276 | return; | 275 | return; |
277 | } | 276 | } |
278 | if (request->original_request_id != dns->id) | 277 | if (request->original_request_id != dns->id) |
279 | { | 278 | { |
280 | /* for a another query, ignore */ | 279 | /* for a another query, ignore */ |
281 | return; | 280 | return; |
282 | } | 281 | } |
283 | request->packet = GNUNET_DNSPARSER_parse ((char*)dns, | 282 | request->packet = GNUNET_DNSPARSER_parse((char*)dns, |
284 | r); | 283 | r); |
285 | GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); | 284 | GNUNET_DNSSTUB_resolve_cancel(request->dns_lookup); |
286 | send_response (request); | 285 | send_response(request); |
287 | } | 286 | } |
288 | 287 | ||
289 | 288 | ||
@@ -296,10 +295,10 @@ dns_result_processor (void *cls, | |||
296 | * @param rd the records in reply | 295 | * @param rd the records in reply |
297 | */ | 296 | */ |
298 | static void | 297 | static void |
299 | result_processor (void *cls, | 298 | result_processor(void *cls, |
300 | int was_gns, | 299 | int was_gns, |
301 | uint32_t rd_count, | 300 | uint32_t rd_count, |
302 | const struct GNUNET_GNSRECORD_Data *rd) | 301 | const struct GNUNET_GNSRECORD_Data *rd) |
303 | { | 302 | { |
304 | struct Request *request = cls; | 303 | struct Request *request = cls; |
305 | struct GNUNET_DNSPARSER_Packet *packet; | 304 | struct GNUNET_DNSPARSER_Packet *packet; |
@@ -307,22 +306,22 @@ result_processor (void *cls, | |||
307 | 306 | ||
308 | request->lookup = NULL; | 307 | request->lookup = NULL; |
309 | if (GNUNET_NO == was_gns) | 308 | if (GNUNET_NO == was_gns) |
310 | { | 309 | { |
311 | /* TLD not configured for GNS, fall back to DNS */ | 310 | /* TLD not configured for GNS, fall back to DNS */ |
312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 311 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
313 | "Using DNS resolver IP `%s' to resolve `%s'\n", | 312 | "Using DNS resolver IP `%s' to resolve `%s'\n", |
314 | dns_ip, | 313 | dns_ip, |
315 | request->packet->queries[0].name); | 314 | request->packet->queries[0].name); |
316 | request->original_request_id = request->packet->id; | 315 | request->original_request_id = request->packet->id; |
317 | GNUNET_DNSPARSER_free_packet (request->packet); | 316 | GNUNET_DNSPARSER_free_packet(request->packet); |
318 | request->packet = NULL; | 317 | request->packet = NULL; |
319 | request->dns_lookup = GNUNET_DNSSTUB_resolve (dns_stub, | 318 | request->dns_lookup = GNUNET_DNSSTUB_resolve(dns_stub, |
320 | request->udp_msg, | 319 | request->udp_msg, |
321 | request->udp_msg_size, | 320 | request->udp_msg_size, |
322 | &dns_result_processor, | 321 | &dns_result_processor, |
323 | request); | 322 | request); |
324 | return; | 323 | return; |
325 | } | 324 | } |
326 | packet = request->packet; | 325 | packet = request->packet; |
327 | packet->flags.query_or_response = 1; | 326 | packet->flags.query_or_response = 1; |
328 | packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; | 327 | packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; |
@@ -333,59 +332,62 @@ result_processor (void *cls, | |||
333 | packet->flags.message_truncated = 0; | 332 | packet->flags.message_truncated = 0; |
334 | packet->flags.authoritative_answer = 0; | 333 | packet->flags.authoritative_answer = 0; |
335 | //packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ??? | 334 | //packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ??? |
336 | for (uint32_t i=0;i<rd_count;i++) | 335 | for (uint32_t i = 0; i < rd_count; i++) |
337 | { | 336 | { |
338 | // FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD | 337 | // FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD |
339 | // here? Or should we do this in libgnunetgns? | 338 | // here? Or should we do this in libgnunetgns? |
340 | rec.expiration_time.abs_value_us = rd[i].expiration_time; | 339 | rec.expiration_time.abs_value_us = rd[i].expiration_time; |
341 | switch (rd[i].record_type) | 340 | switch (rd[i].record_type) |
342 | { | 341 | { |
343 | case GNUNET_DNSPARSER_TYPE_A: | 342 | case GNUNET_DNSPARSER_TYPE_A: |
344 | GNUNET_assert (sizeof (struct in_addr) == rd[i].data_size); | 343 | GNUNET_assert(sizeof(struct in_addr) == rd[i].data_size); |
345 | rec.name = GNUNET_strdup (packet->queries[0].name); | 344 | rec.name = GNUNET_strdup(packet->queries[0].name); |
346 | rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 345 | rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
347 | rec.type = GNUNET_DNSPARSER_TYPE_A; | 346 | rec.type = GNUNET_DNSPARSER_TYPE_A; |
348 | rec.data.raw.data = GNUNET_new (struct in_addr); | 347 | rec.data.raw.data = GNUNET_new(struct in_addr); |
349 | GNUNET_memcpy (rec.data.raw.data, | 348 | GNUNET_memcpy(rec.data.raw.data, |
350 | rd[i].data, | 349 | rd[i].data, |
351 | rd[i].data_size); | 350 | rd[i].data_size); |
352 | rec.data.raw.data_len = sizeof (struct in_addr); | 351 | rec.data.raw.data_len = sizeof(struct in_addr); |
353 | GNUNET_array_append (packet->answers, | 352 | GNUNET_array_append(packet->answers, |
354 | packet->num_answers, | 353 | packet->num_answers, |
355 | rec); | 354 | rec); |
356 | break; | 355 | break; |
357 | case GNUNET_DNSPARSER_TYPE_AAAA: | 356 | |
358 | GNUNET_assert (sizeof (struct in6_addr) == rd[i].data_size); | 357 | case GNUNET_DNSPARSER_TYPE_AAAA: |
359 | rec.name = GNUNET_strdup (packet->queries[0].name); | 358 | GNUNET_assert(sizeof(struct in6_addr) == rd[i].data_size); |
360 | rec.data.raw.data = GNUNET_new (struct in6_addr); | 359 | rec.name = GNUNET_strdup(packet->queries[0].name); |
361 | rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 360 | rec.data.raw.data = GNUNET_new(struct in6_addr); |
362 | rec.type = GNUNET_DNSPARSER_TYPE_AAAA; | 361 | rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
363 | GNUNET_memcpy (rec.data.raw.data, | 362 | rec.type = GNUNET_DNSPARSER_TYPE_AAAA; |
364 | rd[i].data, | 363 | GNUNET_memcpy(rec.data.raw.data, |
365 | rd[i].data_size); | 364 | rd[i].data, |
366 | rec.data.raw.data_len = sizeof (struct in6_addr); | 365 | rd[i].data_size); |
367 | GNUNET_array_append (packet->answers, | 366 | rec.data.raw.data_len = sizeof(struct in6_addr); |
368 | packet->num_answers, | 367 | GNUNET_array_append(packet->answers, |
369 | rec); | 368 | packet->num_answers, |
370 | break; | 369 | rec); |
371 | case GNUNET_DNSPARSER_TYPE_CNAME: | 370 | break; |
372 | rec.name = GNUNET_strdup (packet->queries[0].name); | 371 | |
373 | rec.data.hostname = GNUNET_strdup (rd[i].data); | 372 | case GNUNET_DNSPARSER_TYPE_CNAME: |
374 | rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 373 | rec.name = GNUNET_strdup(packet->queries[0].name); |
375 | rec.type = GNUNET_DNSPARSER_TYPE_CNAME; | 374 | rec.data.hostname = GNUNET_strdup(rd[i].data); |
376 | GNUNET_memcpy (rec.data.hostname, | 375 | rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
377 | rd[i].data, | 376 | rec.type = GNUNET_DNSPARSER_TYPE_CNAME; |
378 | rd[i].data_size); | 377 | GNUNET_memcpy(rec.data.hostname, |
379 | GNUNET_array_append (packet->answers, | 378 | rd[i].data, |
380 | packet->num_answers, | 379 | rd[i].data_size); |
381 | rec); | 380 | GNUNET_array_append(packet->answers, |
382 | break; | 381 | packet->num_answers, |
383 | default: | 382 | rec); |
384 | /* skip */ | 383 | break; |
385 | break; | 384 | |
386 | } | 385 | default: |
386 | /* skip */ | ||
387 | break; | ||
388 | } | ||
387 | } | 389 | } |
388 | send_response (request); | 390 | send_response(request); |
389 | } | 391 | } |
390 | 392 | ||
391 | 393 | ||
@@ -399,73 +401,73 @@ result_processor (void *cls, | |||
399 | * @param udp_msg_size number of bytes in @a udp_msg | 401 | * @param udp_msg_size number of bytes in @a udp_msg |
400 | */ | 402 | */ |
401 | static void | 403 | static void |
402 | handle_request (struct GNUNET_NETWORK_Handle *lsock, | 404 | handle_request(struct GNUNET_NETWORK_Handle *lsock, |
403 | const void *addr, | 405 | const void *addr, |
404 | size_t addr_len, | 406 | size_t addr_len, |
405 | const char *udp_msg, | 407 | const char *udp_msg, |
406 | size_t udp_msg_size) | 408 | size_t udp_msg_size) |
407 | { | 409 | { |
408 | struct Request *request; | 410 | struct Request *request; |
409 | struct GNUNET_DNSPARSER_Packet *packet; | 411 | struct GNUNET_DNSPARSER_Packet *packet; |
410 | 412 | ||
411 | packet = GNUNET_DNSPARSER_parse (udp_msg, | 413 | packet = GNUNET_DNSPARSER_parse(udp_msg, |
412 | udp_msg_size); | 414 | udp_msg_size); |
413 | if (NULL == packet) | 415 | if (NULL == packet) |
414 | { | 416 | { |
415 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 417 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
416 | _("Cannot parse DNS request from %s\n"), | 418 | _("Cannot parse DNS request from %s\n"), |
417 | GNUNET_a2s (addr, addr_len)); | 419 | GNUNET_a2s(addr, addr_len)); |
418 | return; | 420 | return; |
419 | } | 421 | } |
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 422 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
421 | "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n", | 423 | "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n", |
422 | packet->queries[0].name, | 424 | packet->queries[0].name, |
423 | (unsigned int) packet->flags.query_or_response, | 425 | (unsigned int)packet->flags.query_or_response, |
424 | (int) packet->num_answers, | 426 | (int)packet->num_answers, |
425 | (int) packet->num_authority_records, | 427 | (int)packet->num_authority_records, |
426 | (int) packet->num_additional_records); | 428 | (int)packet->num_additional_records); |
427 | if ( (0 != packet->flags.query_or_response) || | 429 | if ((0 != packet->flags.query_or_response) || |
428 | (0 != packet->num_answers) || | 430 | (0 != packet->num_answers) || |
429 | (0 != packet->num_authority_records)) | 431 | (0 != packet->num_authority_records)) |
430 | { | 432 | { |
431 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 433 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
432 | _("Received malformed DNS request from %s\n"), | 434 | _("Received malformed DNS request from %s\n"), |
433 | GNUNET_a2s (addr, addr_len)); | 435 | GNUNET_a2s(addr, addr_len)); |
434 | GNUNET_DNSPARSER_free_packet (packet); | 436 | GNUNET_DNSPARSER_free_packet(packet); |
435 | return; | 437 | return; |
436 | } | 438 | } |
437 | if ( (1 != packet->num_queries) ) | 439 | if ((1 != packet->num_queries)) |
438 | { | 440 | { |
439 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 441 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
440 | _("Received unsupported DNS request from %s\n"), | 442 | _("Received unsupported DNS request from %s\n"), |
441 | GNUNET_a2s (addr, | 443 | GNUNET_a2s(addr, |
442 | addr_len)); | 444 | addr_len)); |
443 | GNUNET_DNSPARSER_free_packet (packet); | 445 | GNUNET_DNSPARSER_free_packet(packet); |
444 | return; | 446 | return; |
445 | } | 447 | } |
446 | request = GNUNET_malloc (sizeof (struct Request) + addr_len); | 448 | request = GNUNET_malloc(sizeof(struct Request) + addr_len); |
447 | request->lsock = lsock; | 449 | request->lsock = lsock; |
448 | request->packet = packet; | 450 | request->packet = packet; |
449 | request->addr = &request[1]; | 451 | request->addr = &request[1]; |
450 | request->addr_len = addr_len; | 452 | request->addr_len = addr_len; |
451 | GNUNET_memcpy (&request[1], | 453 | GNUNET_memcpy(&request[1], |
452 | addr, | 454 | addr, |
453 | addr_len); | 455 | addr_len); |
454 | request->udp_msg_size = udp_msg_size; | 456 | request->udp_msg_size = udp_msg_size; |
455 | request->udp_msg = GNUNET_memdup (udp_msg, | 457 | request->udp_msg = GNUNET_memdup(udp_msg, |
456 | udp_msg_size); | 458 | udp_msg_size); |
457 | request->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 459 | request->timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
458 | &do_timeout, | 460 | &do_timeout, |
459 | request); | 461 | request); |
460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 462 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
461 | "Calling GNS on `%s'\n", | 463 | "Calling GNS on `%s'\n", |
462 | packet->queries[0].name); | 464 | packet->queries[0].name); |
463 | request->lookup = GNUNET_GNS_lookup_with_tld (gns, | 465 | request->lookup = GNUNET_GNS_lookup_with_tld(gns, |
464 | packet->queries[0].name, | 466 | packet->queries[0].name, |
465 | packet->queries[0].type, | 467 | packet->queries[0].type, |
466 | GNUNET_NO, | 468 | GNUNET_NO, |
467 | &result_processor, | 469 | &result_processor, |
468 | request); | 470 | request); |
469 | } | 471 | } |
470 | 472 | ||
471 | 473 | ||
@@ -475,49 +477,49 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
475 | * @param cls the 'listen_socket4' | 477 | * @param cls the 'listen_socket4' |
476 | */ | 478 | */ |
477 | static void | 479 | static void |
478 | read_dns4 (void *cls) | 480 | read_dns4(void *cls) |
479 | { | 481 | { |
480 | struct sockaddr_in v4; | 482 | struct sockaddr_in v4; |
481 | socklen_t addrlen; | 483 | socklen_t addrlen; |
482 | ssize_t size; | 484 | ssize_t size; |
483 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 485 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
484 | 486 | ||
485 | GNUNET_assert (listen_socket4 == cls); | 487 | GNUNET_assert(listen_socket4 == cls); |
486 | t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 488 | t4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
487 | listen_socket4, | 489 | listen_socket4, |
488 | &read_dns4, | 490 | &read_dns4, |
489 | listen_socket4); | 491 | listen_socket4); |
490 | tc = GNUNET_SCHEDULER_get_task_context (); | 492 | tc = GNUNET_SCHEDULER_get_task_context(); |
491 | if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason)) | 493 | if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason)) |
492 | return; /* shutdown? */ | 494 | return; /* shutdown? */ |
493 | size = GNUNET_NETWORK_socket_recvfrom_amount (listen_socket4); | 495 | size = GNUNET_NETWORK_socket_recvfrom_amount(listen_socket4); |
494 | if (0 > size) | 496 | if (0 > size) |
495 | { | 497 | { |
496 | GNUNET_break (0); | 498 | GNUNET_break(0); |
497 | return; /* read error!? */ | 499 | return; /* read error!? */ |
498 | } | 500 | } |
499 | { | 501 | { |
500 | char buf[size + 1]; | 502 | char buf[size + 1]; |
501 | ssize_t sret; | 503 | ssize_t sret; |
502 | 504 | ||
503 | addrlen = sizeof (v4); | 505 | addrlen = sizeof(v4); |
504 | sret = GNUNET_NETWORK_socket_recvfrom (listen_socket4, | 506 | sret = GNUNET_NETWORK_socket_recvfrom(listen_socket4, |
505 | buf, | 507 | buf, |
506 | size + 1, | 508 | size + 1, |
507 | (struct sockaddr *) &v4, | 509 | (struct sockaddr *)&v4, |
508 | &addrlen); | 510 | &addrlen); |
509 | if (0 > sret) | 511 | if (0 > sret) |
510 | { | 512 | { |
511 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 513 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
512 | "recvfrom"); | 514 | "recvfrom"); |
513 | return; | 515 | return; |
514 | } | 516 | } |
515 | GNUNET_break (size == sret); | 517 | GNUNET_break(size == sret); |
516 | handle_request (listen_socket4, | 518 | handle_request(listen_socket4, |
517 | &v4, | 519 | &v4, |
518 | addrlen, | 520 | addrlen, |
519 | buf, | 521 | buf, |
520 | size); | 522 | size); |
521 | } | 523 | } |
522 | } | 524 | } |
523 | 525 | ||
@@ -528,49 +530,49 @@ read_dns4 (void *cls) | |||
528 | * @param cls the 'listen_socket6' | 530 | * @param cls the 'listen_socket6' |
529 | */ | 531 | */ |
530 | static void | 532 | static void |
531 | read_dns6 (void *cls) | 533 | read_dns6(void *cls) |
532 | { | 534 | { |
533 | struct sockaddr_in6 v6; | 535 | struct sockaddr_in6 v6; |
534 | socklen_t addrlen; | 536 | socklen_t addrlen; |
535 | ssize_t size; | 537 | ssize_t size; |
536 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 538 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
537 | 539 | ||
538 | GNUNET_assert (listen_socket6 == cls); | 540 | GNUNET_assert(listen_socket6 == cls); |
539 | t6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 541 | t6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
540 | listen_socket6, | 542 | listen_socket6, |
541 | &read_dns6, | 543 | &read_dns6, |
542 | listen_socket6); | 544 | listen_socket6); |
543 | tc = GNUNET_SCHEDULER_get_task_context (); | 545 | tc = GNUNET_SCHEDULER_get_task_context(); |
544 | if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason)) | 546 | if (0 == (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason)) |
545 | return; /* shutdown? */ | 547 | return; /* shutdown? */ |
546 | size = GNUNET_NETWORK_socket_recvfrom_amount (listen_socket6); | 548 | size = GNUNET_NETWORK_socket_recvfrom_amount(listen_socket6); |
547 | if (0 > size) | 549 | if (0 > size) |
548 | { | 550 | { |
549 | GNUNET_break (0); | 551 | GNUNET_break(0); |
550 | return; /* read error!? */ | 552 | return; /* read error!? */ |
551 | } | 553 | } |
552 | { | 554 | { |
553 | char buf[size]; | 555 | char buf[size]; |
554 | ssize_t sret; | 556 | ssize_t sret; |
555 | 557 | ||
556 | addrlen = sizeof (v6); | 558 | addrlen = sizeof(v6); |
557 | sret = GNUNET_NETWORK_socket_recvfrom (listen_socket6, | 559 | sret = GNUNET_NETWORK_socket_recvfrom(listen_socket6, |
558 | buf, | 560 | buf, |
559 | size, | 561 | size, |
560 | (struct sockaddr *) &v6, | 562 | (struct sockaddr *)&v6, |
561 | &addrlen); | 563 | &addrlen); |
562 | if (0 > sret) | 564 | if (0 > sret) |
563 | { | 565 | { |
564 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 566 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
565 | "recvfrom"); | 567 | "recvfrom"); |
566 | return; | 568 | return; |
567 | } | 569 | } |
568 | GNUNET_break (size == sret); | 570 | GNUNET_break(size == sret); |
569 | handle_request (listen_socket6, | 571 | handle_request(listen_socket6, |
570 | &v6, | 572 | &v6, |
571 | addrlen, | 573 | addrlen, |
572 | buf, | 574 | buf, |
573 | size); | 575 | size); |
574 | } | 576 | } |
575 | } | 577 | } |
576 | 578 | ||
@@ -584,149 +586,150 @@ read_dns6 (void *cls) | |||
584 | * @param c configuration | 586 | * @param c configuration |
585 | */ | 587 | */ |
586 | static void | 588 | static void |
587 | run (void *cls, | 589 | run(void *cls, |
588 | char *const *args, | 590 | char *const *args, |
589 | const char *cfgfile, | 591 | const char *cfgfile, |
590 | const struct GNUNET_CONFIGURATION_Handle *c) | 592 | const struct GNUNET_CONFIGURATION_Handle *c) |
591 | { | 593 | { |
592 | char *addr_str; | 594 | char *addr_str; |
593 | (void) cls; | 595 | |
594 | (void) args; | 596 | (void)cls; |
595 | (void) cfgfile; | 597 | (void)args; |
598 | (void)cfgfile; | ||
596 | cfg = c; | 599 | cfg = c; |
597 | if (NULL == dns_ip) | 600 | if (NULL == dns_ip) |
598 | { | 601 | { |
599 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 602 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
600 | _("No DNS server specified!\n")); | 603 | _("No DNS server specified!\n")); |
601 | return; | 604 | return; |
602 | } | 605 | } |
603 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 606 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
604 | NULL); | 607 | NULL); |
605 | if (NULL == (gns = GNUNET_GNS_connect (cfg))) | 608 | if (NULL == (gns = GNUNET_GNS_connect(cfg))) |
606 | return; | 609 | return; |
607 | GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128))); | 610 | GNUNET_assert(NULL != (dns_stub = GNUNET_DNSSTUB_start(128))); |
608 | if (GNUNET_OK != | 611 | if (GNUNET_OK != |
609 | GNUNET_DNSSTUB_add_dns_ip (dns_stub, | 612 | GNUNET_DNSSTUB_add_dns_ip(dns_stub, |
610 | dns_ip)) | 613 | dns_ip)) |
611 | { | 614 | { |
612 | GNUNET_DNSSTUB_stop (dns_stub); | 615 | GNUNET_DNSSTUB_stop(dns_stub); |
613 | GNUNET_GNS_disconnect (gns); | 616 | GNUNET_GNS_disconnect(gns); |
614 | gns = NULL; | 617 | gns = NULL; |
615 | return; | 618 | return; |
616 | } | 619 | } |
617 | 620 | ||
618 | /* Get address to bind to */ | 621 | /* Get address to bind to */ |
619 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns", | 622 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(c, "dns2gns", |
620 | "BIND_TO", | 623 | "BIND_TO", |
621 | &addr_str)) | 624 | &addr_str)) |
622 | { | 625 | { |
623 | //No address specified | 626 | //No address specified |
624 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 627 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
625 | "Don't know what to bind to...\n"); | 628 | "Don't know what to bind to...\n"); |
626 | GNUNET_free (addr_str); | 629 | GNUNET_free(addr_str); |
627 | GNUNET_SCHEDULER_shutdown (); | 630 | GNUNET_SCHEDULER_shutdown(); |
628 | return; | 631 | return; |
629 | } | 632 | } |
630 | if (1 != inet_pton (AF_INET, addr_str, &address)) | 633 | if (1 != inet_pton(AF_INET, addr_str, &address)) |
631 | { | 634 | { |
632 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 635 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
633 | "Unable to parse address %s\n", | 636 | "Unable to parse address %s\n", |
634 | addr_str); | 637 | addr_str); |
635 | GNUNET_free (addr_str); | 638 | GNUNET_free(addr_str); |
636 | GNUNET_SCHEDULER_shutdown (); | 639 | GNUNET_SCHEDULER_shutdown(); |
637 | return; | 640 | return; |
638 | } | 641 | } |
639 | GNUNET_free (addr_str); | 642 | GNUNET_free(addr_str); |
640 | /* Get address to bind to */ | 643 | /* Get address to bind to */ |
641 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns", | 644 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(c, "dns2gns", |
642 | "BIND_TO6", | 645 | "BIND_TO6", |
643 | &addr_str)) | 646 | &addr_str)) |
644 | { | 647 | { |
645 | //No address specified | 648 | //No address specified |
646 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 649 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
647 | "Don't know what to bind6 to...\n"); | 650 | "Don't know what to bind6 to...\n"); |
648 | GNUNET_free (addr_str); | 651 | GNUNET_free(addr_str); |
649 | GNUNET_SCHEDULER_shutdown (); | 652 | GNUNET_SCHEDULER_shutdown(); |
650 | return; | 653 | return; |
651 | } | 654 | } |
652 | if (1 != inet_pton (AF_INET6, addr_str, &address6)) | 655 | if (1 != inet_pton(AF_INET6, addr_str, &address6)) |
653 | { | 656 | { |
654 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 657 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
655 | "Unable to parse IPv6 address %s\n", | 658 | "Unable to parse IPv6 address %s\n", |
656 | addr_str); | 659 | addr_str); |
657 | GNUNET_free (addr_str); | 660 | GNUNET_free(addr_str); |
658 | GNUNET_SCHEDULER_shutdown (); | 661 | GNUNET_SCHEDULER_shutdown(); |
659 | return; | 662 | return; |
660 | } | 663 | } |
661 | GNUNET_free (addr_str); | 664 | GNUNET_free(addr_str); |
662 | 665 | ||
663 | listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET, | 666 | listen_socket4 = GNUNET_NETWORK_socket_create(PF_INET, |
664 | SOCK_DGRAM, | 667 | SOCK_DGRAM, |
665 | IPPROTO_UDP); | 668 | IPPROTO_UDP); |
666 | if (NULL != listen_socket4) | 669 | if (NULL != listen_socket4) |
667 | { | 670 | { |
668 | struct sockaddr_in v4; | 671 | struct sockaddr_in v4; |
669 | 672 | ||
670 | memset (&v4, 0, sizeof (v4)); | 673 | memset(&v4, 0, sizeof(v4)); |
671 | v4.sin_family = AF_INET; | 674 | v4.sin_family = AF_INET; |
672 | v4.sin_addr.s_addr = address; | 675 | v4.sin_addr.s_addr = address; |
673 | #if HAVE_SOCKADDR_IN_SIN_LEN | 676 | #if HAVE_SOCKADDR_IN_SIN_LEN |
674 | v4.sin_len = sizeof (v4); | 677 | v4.sin_len = sizeof(v4); |
675 | #endif | 678 | #endif |
676 | v4.sin_port = htons (listen_port); | 679 | v4.sin_port = htons(listen_port); |
677 | if (GNUNET_OK != | 680 | if (GNUNET_OK != |
678 | GNUNET_NETWORK_socket_bind (listen_socket4, | 681 | GNUNET_NETWORK_socket_bind(listen_socket4, |
679 | (struct sockaddr *) &v4, | 682 | (struct sockaddr *)&v4, |
680 | sizeof (v4))) | 683 | sizeof(v4))) |
681 | { | 684 | { |
682 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 685 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); |
683 | GNUNET_NETWORK_socket_close (listen_socket4); | 686 | GNUNET_NETWORK_socket_close(listen_socket4); |
684 | listen_socket4 = NULL; | 687 | listen_socket4 = NULL; |
688 | } | ||
685 | } | 689 | } |
686 | } | 690 | listen_socket6 = GNUNET_NETWORK_socket_create(PF_INET6, |
687 | listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6, | 691 | SOCK_DGRAM, |
688 | SOCK_DGRAM, | 692 | IPPROTO_UDP); |
689 | IPPROTO_UDP); | ||
690 | if (NULL != listen_socket6) | 693 | if (NULL != listen_socket6) |
691 | { | 694 | { |
692 | struct sockaddr_in6 v6; | 695 | struct sockaddr_in6 v6; |
693 | 696 | ||
694 | memset (&v6, 0, sizeof (v6)); | 697 | memset(&v6, 0, sizeof(v6)); |
695 | v6.sin6_family = AF_INET6; | 698 | v6.sin6_family = AF_INET6; |
696 | v6.sin6_addr = address6; | 699 | v6.sin6_addr = address6; |
697 | #if HAVE_SOCKADDR_IN_SIN_LEN | 700 | #if HAVE_SOCKADDR_IN_SIN_LEN |
698 | v6.sin6_len = sizeof (v6); | 701 | v6.sin6_len = sizeof(v6); |
699 | #endif | 702 | #endif |
700 | v6.sin6_port = htons (listen_port); | 703 | v6.sin6_port = htons(listen_port); |
701 | if (GNUNET_OK != | 704 | if (GNUNET_OK != |
702 | GNUNET_NETWORK_socket_bind (listen_socket6, | 705 | GNUNET_NETWORK_socket_bind(listen_socket6, |
703 | (struct sockaddr *) &v6, | 706 | (struct sockaddr *)&v6, |
704 | sizeof (v6))) | 707 | sizeof(v6))) |
708 | { | ||
709 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind"); | ||
710 | GNUNET_NETWORK_socket_close(listen_socket6); | ||
711 | listen_socket6 = NULL; | ||
712 | } | ||
713 | } | ||
714 | if ((NULL == listen_socket4) && | ||
715 | (NULL == listen_socket6)) | ||
705 | { | 716 | { |
706 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 717 | GNUNET_GNS_disconnect(gns); |
707 | GNUNET_NETWORK_socket_close (listen_socket6); | 718 | gns = NULL; |
708 | listen_socket6 = NULL; | 719 | GNUNET_DNSSTUB_stop(dns_stub); |
720 | dns_stub = NULL; | ||
721 | return; | ||
709 | } | 722 | } |
710 | } | ||
711 | if ( (NULL == listen_socket4) && | ||
712 | (NULL == listen_socket6) ) | ||
713 | { | ||
714 | GNUNET_GNS_disconnect (gns); | ||
715 | gns = NULL; | ||
716 | GNUNET_DNSSTUB_stop (dns_stub); | ||
717 | dns_stub = NULL; | ||
718 | return; | ||
719 | } | ||
720 | if (NULL != listen_socket4) | 723 | if (NULL != listen_socket4) |
721 | t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 724 | t4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
722 | listen_socket4, | 725 | listen_socket4, |
723 | &read_dns4, | 726 | &read_dns4, |
724 | listen_socket4); | 727 | listen_socket4); |
725 | if (NULL != listen_socket6) | 728 | if (NULL != listen_socket6) |
726 | t6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 729 | t6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
727 | listen_socket6, | 730 | listen_socket6, |
728 | &read_dns6, | 731 | &read_dns6, |
729 | listen_socket6); | 732 | listen_socket6); |
730 | } | 733 | } |
731 | 734 | ||
732 | 735 | ||
@@ -738,39 +741,39 @@ run (void *cls, | |||
738 | * @return 0 ok, 1 on error | 741 | * @return 0 ok, 1 on error |
739 | */ | 742 | */ |
740 | int | 743 | int |
741 | main (int argc, | 744 | main(int argc, |
742 | char *const *argv) | 745 | char *const *argv) |
743 | { | 746 | { |
744 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 747 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
745 | GNUNET_GETOPT_option_string ('d', | 748 | GNUNET_GETOPT_option_string('d', |
746 | "dns", | 749 | "dns", |
747 | "IP", | 750 | "IP", |
748 | gettext_noop ("IP of recursive DNS resolver to use (required)"), | 751 | gettext_noop("IP of recursive DNS resolver to use (required)"), |
749 | &dns_ip), | 752 | &dns_ip), |
750 | GNUNET_GETOPT_option_uint ('p', | 753 | GNUNET_GETOPT_option_uint('p', |
751 | "port", | 754 | "port", |
752 | "UDPPORT", | 755 | "UDPPORT", |
753 | gettext_noop ("UDP port to listen on for inbound DNS requests; default: 2853"), | 756 | gettext_noop("UDP port to listen on for inbound DNS requests; default: 2853"), |
754 | &listen_port), | 757 | &listen_port), |
755 | GNUNET_GETOPT_OPTION_END | 758 | GNUNET_GETOPT_OPTION_END |
756 | }; | 759 | }; |
757 | int ret; | 760 | int ret; |
758 | 761 | ||
759 | if (GNUNET_OK != | 762 | if (GNUNET_OK != |
760 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 763 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
761 | &argc, &argv)) | 764 | &argc, &argv)) |
762 | return 2; | 765 | return 2; |
763 | GNUNET_log_setup ("gnunet-dns2gns", | 766 | GNUNET_log_setup("gnunet-dns2gns", |
764 | "WARNING", | 767 | "WARNING", |
765 | NULL); | 768 | NULL); |
766 | ret = | 769 | ret = |
767 | (GNUNET_OK == | 770 | (GNUNET_OK == |
768 | GNUNET_PROGRAM_run (argc, argv, | 771 | GNUNET_PROGRAM_run(argc, argv, |
769 | "gnunet-dns2gns", | 772 | "gnunet-dns2gns", |
770 | _("GNUnet DNS-to-GNS proxy (a DNS server)"), | 773 | _("GNUnet DNS-to-GNS proxy (a DNS server)"), |
771 | options, | 774 | options, |
772 | &run, NULL)) ? 0 : 1; | 775 | &run, NULL)) ? 0 : 1; |
773 | GNUNET_free ((void*) argv); | 776 | GNUNET_free((void*)argv); |
774 | return ret; | 777 | return ret; |
775 | } | 778 | } |
776 | 779 | ||
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c index 77066fd3f..b64201f10 100644 --- a/src/gns/gnunet-gns-benchmark.c +++ b/src/gns/gnunet-gns-benchmark.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file src/gns/gnunet-gns-benchmark.c | 21 | * @file src/gns/gnunet-gns-benchmark.c |
22 | * @brief issue many queries to GNS and compute performance statistics | 22 | * @brief issue many queries to GNS and compute performance statistics |
@@ -31,12 +31,12 @@ | |||
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(GNUNET_TIME_UNIT_MILLISECONDS, 1) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * How long do we wait until we consider a request failed by default? | 37 | * How long do we wait until we consider a request failed by default? |
38 | */ | 38 | */ |
39 | #define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | 39 | #define DEF_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
@@ -45,8 +45,7 @@ | |||
45 | * However, this process does not change how it acts | 45 | * However, this process does not change how it acts |
46 | * based on the category. | 46 | * based on the category. |
47 | */ | 47 | */ |
48 | enum RequestCategory | 48 | enum RequestCategory { |
49 | { | ||
50 | RC_SHARED = 0, | 49 | RC_SHARED = 0, |
51 | RC_PRIVATE = 1, | 50 | RC_PRIVATE = 1, |
52 | /** | 51 | /** |
@@ -61,9 +60,7 @@ enum RequestCategory | |||
61 | * thus optimizing it is crucial for the overall memory consumption of | 60 | * thus optimizing it is crucial for the overall memory consumption of |
62 | * the zone importer. | 61 | * the zone importer. |
63 | */ | 62 | */ |
64 | struct Request | 63 | struct Request { |
65 | { | ||
66 | |||
67 | /** | 64 | /** |
68 | * Active requests are kept in a DLL. | 65 | * Active requests are kept in a DLL. |
69 | */ | 66 | */ |
@@ -101,7 +98,6 @@ struct Request | |||
101 | * Category of the request. | 98 | * Category of the request. |
102 | */ | 99 | */ |
103 | enum RequestCategory cat; | 100 | enum RequestCategory cat; |
104 | |||
105 | }; | 101 | }; |
106 | 102 | ||
107 | 103 | ||
@@ -192,11 +188,11 @@ static int g2d; | |||
192 | * @param req request to free | 188 | * @param req request to free |
193 | */ | 189 | */ |
194 | static void | 190 | static void |
195 | free_request (struct Request *req) | 191 | free_request(struct Request *req) |
196 | { | 192 | { |
197 | if (NULL != req->lr) | 193 | if (NULL != req->lr) |
198 | GNUNET_GNS_lookup_with_tld_cancel (req->lr); | 194 | GNUNET_GNS_lookup_with_tld_cancel(req->lr); |
199 | GNUNET_free (req); | 195 | GNUNET_free(req); |
200 | } | 196 | } |
201 | 197 | ||
202 | 198 | ||
@@ -209,32 +205,32 @@ free_request (struct Request *req) | |||
209 | * @param rd the records in reply | 205 | * @param rd the records in reply |
210 | */ | 206 | */ |
211 | static void | 207 | static void |
212 | process_result (void *cls, | 208 | process_result(void *cls, |
213 | int gns_tld, | 209 | int gns_tld, |
214 | uint32_t rd_count, | 210 | uint32_t rd_count, |
215 | const struct GNUNET_GNSRECORD_Data *rd) | 211 | const struct GNUNET_GNSRECORD_Data *rd) |
216 | { | 212 | { |
217 | struct Request *req = cls; | 213 | struct Request *req = cls; |
218 | 214 | ||
219 | (void) gns_tld; | 215 | (void)gns_tld; |
220 | (void) rd_count; | 216 | (void)rd_count; |
221 | (void) rd; | 217 | (void)rd; |
222 | active_cnt--; | 218 | active_cnt--; |
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
224 | "Got response for request `%s'\n", | 220 | "Got response for request `%s'\n", |
225 | req->hostname); | 221 | req->hostname); |
226 | req->lr = NULL; | 222 | req->lr = NULL; |
227 | req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 223 | req->latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); |
228 | GNUNET_CONTAINER_DLL_remove (act_head, | 224 | GNUNET_CONTAINER_DLL_remove(act_head, |
229 | act_tail, | 225 | act_tail, |
230 | req); | 226 | req); |
231 | GNUNET_CONTAINER_DLL_insert (succ_head, | 227 | GNUNET_CONTAINER_DLL_insert(succ_head, |
232 | succ_tail, | 228 | succ_tail, |
233 | req); | 229 | req); |
234 | replies[req->cat]++; | 230 | replies[req->cat]++; |
235 | latency_sum[req->cat] | 231 | latency_sum[req->cat] |
236 | = GNUNET_TIME_relative_add (latency_sum[req->cat], | 232 | = GNUNET_TIME_relative_add(latency_sum[req->cat], |
237 | req->latency); | 233 | req->latency); |
238 | } | 234 | } |
239 | 235 | ||
240 | 236 | ||
@@ -244,69 +240,69 @@ process_result (void *cls, | |||
244 | * @param cls NULL | 240 | * @param cls NULL |
245 | */ | 241 | */ |
246 | static void | 242 | static void |
247 | process_queue (void *cls) | 243 | process_queue(void *cls) |
248 | { | 244 | { |
249 | struct Request *req; | 245 | struct Request *req; |
250 | struct GNUNET_TIME_Relative duration; | 246 | struct GNUNET_TIME_Relative duration; |
251 | 247 | ||
252 | (void) cls; | 248 | (void)cls; |
253 | t = NULL; | 249 | t = NULL; |
254 | /* check for expired requests */ | 250 | /* check for expired requests */ |
255 | while (NULL != (req = act_head)) | 251 | while (NULL != (req = act_head)) |
256 | { | 252 | { |
257 | duration = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 253 | duration = GNUNET_TIME_absolute_get_duration(req->op_start_time); |
258 | if (duration.rel_value_us < timeout.rel_value_us) | 254 | if (duration.rel_value_us < timeout.rel_value_us) |
259 | break; | 255 | break; |
260 | GNUNET_CONTAINER_DLL_remove (act_head, | 256 | GNUNET_CONTAINER_DLL_remove(act_head, |
261 | act_tail, | 257 | act_tail, |
262 | req); | 258 | req); |
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
264 | "Failing request `%s' due to timeout\n", | 260 | "Failing request `%s' due to timeout\n", |
265 | req->hostname); | 261 | req->hostname); |
266 | failures[req->cat]++; | 262 | failures[req->cat]++; |
267 | active_cnt--; | 263 | active_cnt--; |
268 | free_request (req); | 264 | free_request(req); |
269 | } | 265 | } |
270 | if (NULL == (req = todo_head)) | 266 | if (NULL == (req = todo_head)) |
271 | { | ||
272 | struct GNUNET_TIME_Absolute at; | ||
273 | |||
274 | if (NULL == (req = act_head)) | ||
275 | { | 267 | { |
276 | GNUNET_SCHEDULER_shutdown (); | 268 | struct GNUNET_TIME_Absolute at; |
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); | ||
277 | return; | 280 | return; |
278 | } | 281 | } |
279 | at = GNUNET_TIME_absolute_add (req->op_start_time, | 282 | GNUNET_CONTAINER_DLL_remove(todo_head, |
280 | timeout); | 283 | todo_tail, |
281 | t = GNUNET_SCHEDULER_add_at (at, | 284 | req); |
282 | &process_queue, | 285 | GNUNET_CONTAINER_DLL_insert_tail(act_head, |
283 | NULL); | 286 | act_tail, |
284 | return; | 287 | req); |
285 | } | ||
286 | GNUNET_CONTAINER_DLL_remove (todo_head, | ||
287 | todo_tail, | ||
288 | req); | ||
289 | GNUNET_CONTAINER_DLL_insert_tail (act_head, | ||
290 | act_tail, | ||
291 | req); | ||
292 | lookups[req->cat]++; | 288 | lookups[req->cat]++; |
293 | active_cnt++; | 289 | active_cnt++; |
294 | req->op_start_time = GNUNET_TIME_absolute_get (); | 290 | req->op_start_time = GNUNET_TIME_absolute_get(); |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
296 | "Starting request `%s' (%u in parallel)\n", | 292 | "Starting request `%s' (%u in parallel)\n", |
297 | req->hostname, | 293 | req->hostname, |
298 | active_cnt); | 294 | active_cnt); |
299 | req->lr = GNUNET_GNS_lookup_with_tld (gns, | 295 | req->lr = GNUNET_GNS_lookup_with_tld(gns, |
300 | req->hostname, | 296 | req->hostname, |
301 | g2d | 297 | g2d |
302 | ? GNUNET_GNSRECORD_TYPE_GNS2DNS | 298 | ? GNUNET_GNSRECORD_TYPE_GNS2DNS |
303 | : GNUNET_GNSRECORD_TYPE_ANY, | 299 | : GNUNET_GNSRECORD_TYPE_ANY, |
304 | GNUNET_GNS_LO_DEFAULT, | 300 | GNUNET_GNS_LO_DEFAULT, |
305 | &process_result, | 301 | &process_result, |
306 | req); | 302 | req); |
307 | t = GNUNET_SCHEDULER_add_delayed (request_delay, | 303 | t = GNUNET_SCHEDULER_add_delayed(request_delay, |
308 | &process_queue, | 304 | &process_queue, |
309 | NULL); | 305 | NULL); |
310 | } | 306 | } |
311 | 307 | ||
312 | 308 | ||
@@ -318,11 +314,11 @@ process_queue (void *cls) | |||
318 | * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2. | 314 | * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2. |
319 | */ | 315 | */ |
320 | static int | 316 | static int |
321 | compare_req (const void *c1, | 317 | compare_req(const void *c1, |
322 | const void *c2) | 318 | const void *c2) |
323 | { | 319 | { |
324 | const struct Request *r1 = *(void **) c1; | 320 | const struct Request *r1 = *(void **)c1; |
325 | const struct Request *r2 = *(void **) c2; | 321 | const struct Request *r2 = *(void **)c2; |
326 | 322 | ||
327 | if (r1->latency.rel_value_us < r2->latency.rel_value_us) | 323 | if (r1->latency.rel_value_us < r2->latency.rel_value_us) |
328 | return -1; | 324 | return -1; |
@@ -338,101 +334,101 @@ compare_req (const void *c1, | |||
338 | * @param cls NULL | 334 | * @param cls NULL |
339 | */ | 335 | */ |
340 | static void | 336 | static void |
341 | do_shutdown (void *cls) | 337 | do_shutdown(void *cls) |
342 | { | 338 | { |
343 | struct Request *req; | 339 | struct Request *req; |
344 | struct Request **ra[RC_MAX]; | 340 | struct Request **ra[RC_MAX]; |
345 | unsigned int rp[RC_MAX]; | 341 | unsigned int rp[RC_MAX]; |
346 | 342 | ||
347 | (void) cls; | 343 | (void)cls; |
348 | for (enum RequestCategory rc = 0;rc < RC_MAX;rc++) | 344 | for (enum RequestCategory rc = 0; rc < RC_MAX; rc++) |
349 | { | 345 | { |
350 | ra[rc] = GNUNET_new_array (replies[rc], | 346 | ra[rc] = GNUNET_new_array(replies[rc], |
351 | struct Request *); | 347 | struct Request *); |
352 | rp[rc] = 0; | 348 | rp[rc] = 0; |
353 | } | 349 | } |
354 | for (req = succ_head;NULL != req; req = req->next) | 350 | for (req = succ_head; NULL != req; req = req->next) |
355 | { | 351 | { |
356 | GNUNET_assert (rp[req->cat] < replies[req->cat]); | 352 | GNUNET_assert(rp[req->cat] < replies[req->cat]); |
357 | ra[req->cat][rp[req->cat]++] = req; | 353 | ra[req->cat][rp[req->cat]++] = req; |
358 | } | 354 | } |
359 | for (enum RequestCategory rc = 0;rc < RC_MAX;rc++) | 355 | for (enum RequestCategory rc = 0; rc < RC_MAX; rc++) |
360 | { | 356 | { |
361 | unsigned int off; | 357 | unsigned int off; |
362 | 358 | ||
363 | fprintf (stdout, | 359 | fprintf(stdout, |
364 | "Category %u\n", | 360 | "Category %u\n", |
365 | rc); | 361 | rc); |
366 | fprintf (stdout, | 362 | fprintf(stdout, |
367 | "\tlookups: %u replies: %u failures: %u\n", | 363 | "\tlookups: %u replies: %u failures: %u\n", |
368 | lookups[rc], | 364 | lookups[rc], |
369 | replies[rc], | 365 | replies[rc], |
370 | failures[rc]); | 366 | failures[rc]); |
371 | if (0 == rp[rc]) | 367 | if (0 == rp[rc]) |
372 | continue; | 368 | continue; |
373 | qsort (ra[rc], | 369 | qsort(ra[rc], |
374 | rp[rc], | 370 | rp[rc], |
375 | sizeof (struct Request *), | 371 | sizeof(struct Request *), |
376 | &compare_req); | 372 | &compare_req); |
377 | latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc], | 373 | latency_sum[rc] = GNUNET_TIME_relative_divide(latency_sum[rc], |
378 | replies[rc]); | 374 | replies[rc]); |
379 | fprintf (stdout, | 375 | fprintf(stdout, |
380 | "\taverage: %s\n", | 376 | "\taverage: %s\n", |
381 | GNUNET_STRINGS_relative_time_to_string (latency_sum[rc], | 377 | GNUNET_STRINGS_relative_time_to_string(latency_sum[rc], |
382 | GNUNET_YES)); | 378 | GNUNET_YES)); |
383 | off = rp[rc] * 50 / 100; | 379 | off = rp[rc] * 50 / 100; |
384 | fprintf (stdout, | 380 | fprintf(stdout, |
385 | "\tmedian(50): %s\n", | 381 | "\tmedian(50): %s\n", |
386 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 382 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
387 | GNUNET_YES)); | 383 | GNUNET_YES)); |
388 | off = rp[rc] * 75 / 100; | 384 | off = rp[rc] * 75 / 100; |
389 | fprintf (stdout, | 385 | fprintf(stdout, |
390 | "\tquantile(75): %s\n", | 386 | "\tquantile(75): %s\n", |
391 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 387 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
392 | GNUNET_YES)); | 388 | GNUNET_YES)); |
393 | off = rp[rc] * 90 / 100; | 389 | off = rp[rc] * 90 / 100; |
394 | fprintf (stdout, | 390 | fprintf(stdout, |
395 | "\tquantile(90): %s\n", | 391 | "\tquantile(90): %s\n", |
396 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 392 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
397 | GNUNET_YES)); | 393 | GNUNET_YES)); |
398 | off = rp[rc] * 99 / 100; | 394 | off = rp[rc] * 99 / 100; |
399 | fprintf (stdout, | 395 | fprintf(stdout, |
400 | "\tquantile(99): %s\n", | 396 | "\tquantile(99): %s\n", |
401 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 397 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
402 | GNUNET_YES)); | 398 | GNUNET_YES)); |
403 | GNUNET_free (ra[rc]); | 399 | GNUNET_free(ra[rc]); |
404 | } | 400 | } |
405 | if (NULL != t) | 401 | if (NULL != t) |
406 | { | 402 | { |
407 | GNUNET_SCHEDULER_cancel (t); | 403 | GNUNET_SCHEDULER_cancel(t); |
408 | t = NULL; | 404 | t = NULL; |
409 | } | 405 | } |
410 | while (NULL != (req = act_head)) | 406 | while (NULL != (req = act_head)) |
411 | { | 407 | { |
412 | GNUNET_CONTAINER_DLL_remove (act_head, | 408 | GNUNET_CONTAINER_DLL_remove(act_head, |
413 | act_tail, | 409 | act_tail, |
414 | req); | 410 | req); |
415 | free_request (req); | 411 | free_request(req); |
416 | } | 412 | } |
417 | while (NULL != (req = succ_head)) | 413 | while (NULL != (req = succ_head)) |
418 | { | 414 | { |
419 | GNUNET_CONTAINER_DLL_remove (succ_head, | 415 | GNUNET_CONTAINER_DLL_remove(succ_head, |
420 | succ_tail, | 416 | succ_tail, |
421 | req); | 417 | req); |
422 | free_request (req); | 418 | free_request(req); |
423 | } | 419 | } |
424 | while (NULL != (req = todo_head)) | 420 | while (NULL != (req = todo_head)) |
425 | { | 421 | { |
426 | GNUNET_CONTAINER_DLL_remove (todo_head, | 422 | GNUNET_CONTAINER_DLL_remove(todo_head, |
427 | todo_tail, | 423 | todo_tail, |
428 | req); | 424 | req); |
429 | free_request (req); | 425 | free_request(req); |
430 | } | 426 | } |
431 | if (NULL != gns) | 427 | if (NULL != gns) |
432 | { | 428 | { |
433 | GNUNET_GNS_disconnect (gns); | 429 | GNUNET_GNS_disconnect(gns); |
434 | gns = NULL; | 430 | gns = NULL; |
435 | } | 431 | } |
436 | } | 432 | } |
437 | 433 | ||
438 | 434 | ||
@@ -443,32 +439,32 @@ do_shutdown (void *cls) | |||
443 | * @param cat category of the @a hostname | 439 | * @param cat category of the @a hostname |
444 | */ | 440 | */ |
445 | static void | 441 | static void |
446 | queue (const char *hostname, | 442 | queue(const char *hostname, |
447 | enum RequestCategory cat) | 443 | enum RequestCategory cat) |
448 | { | 444 | { |
449 | struct Request *req; | 445 | struct Request *req; |
450 | const char *dot; | 446 | const char *dot; |
451 | size_t hlen; | 447 | size_t hlen; |
452 | 448 | ||
453 | dot = strchr (hostname, | 449 | dot = strchr(hostname, |
454 | (unsigned char) '.'); | 450 | (unsigned char)'.'); |
455 | if (NULL == dot) | 451 | if (NULL == dot) |
456 | { | 452 | { |
457 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 453 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
458 | "Refusing invalid hostname `%s' (lacks '.')\n", | 454 | "Refusing invalid hostname `%s' (lacks '.')\n", |
459 | hostname); | 455 | hostname); |
460 | return; | 456 | return; |
461 | } | 457 | } |
462 | hlen = strlen (hostname) + 1; | 458 | hlen = strlen(hostname) + 1; |
463 | req = GNUNET_malloc (sizeof (struct Request) + hlen); | 459 | req = GNUNET_malloc(sizeof(struct Request) + hlen); |
464 | req->cat = cat; | 460 | req->cat = cat; |
465 | req->hostname = (char *) &req[1]; | 461 | req->hostname = (char *)&req[1]; |
466 | GNUNET_memcpy (&req[1], | 462 | GNUNET_memcpy(&req[1], |
467 | hostname, | 463 | hostname, |
468 | hlen); | 464 | hlen); |
469 | GNUNET_CONTAINER_DLL_insert (todo_head, | 465 | GNUNET_CONTAINER_DLL_insert(todo_head, |
470 | todo_tail, | 466 | todo_tail, |
471 | req); | 467 | req); |
472 | } | 468 | } |
473 | 469 | ||
474 | 470 | ||
@@ -478,7 +474,7 @@ queue (const char *hostname, | |||
478 | * @param cls NULL | 474 | * @param cls NULL |
479 | */ | 475 | */ |
480 | static void | 476 | static void |
481 | process_stdin (void *cls) | 477 | process_stdin(void *cls) |
482 | { | 478 | { |
483 | static struct GNUNET_TIME_Absolute last; | 479 | static struct GNUNET_TIME_Absolute last; |
484 | static uint64_t idot; | 480 | static uint64_t idot; |
@@ -486,48 +482,48 @@ process_stdin (void *cls) | |||
486 | char hn[256]; | 482 | char hn[256]; |
487 | char in[270]; | 483 | char in[270]; |
488 | 484 | ||
489 | (void) cls; | 485 | (void)cls; |
490 | t = NULL; | 486 | t = NULL; |
491 | while (NULL != | 487 | while (NULL != |
492 | fgets (in, | 488 | fgets(in, |
493 | sizeof (in), | 489 | sizeof(in), |
494 | stdin)) | 490 | stdin)) |
495 | { | ||
496 | if (strlen(in) > 0) | ||
497 | hn[strlen(in)-1] = '\0'; /* eat newline */ | ||
498 | if ( (2 != sscanf (in, | ||
499 | "%u %255s", | ||
500 | &cat, | ||
501 | hn)) || | ||
502 | (cat >= RC_MAX) ) | ||
503 | { | ||
504 | fprintf (stderr, | ||
505 | "Malformed input line `%s', skipping\n", | ||
506 | in); | ||
507 | continue; | ||
508 | } | ||
509 | if (0 == idot) | ||
510 | last = GNUNET_TIME_absolute_get (); | ||
511 | idot++; | ||
512 | if (0 == idot % 100000) | ||
513 | { | 491 | { |
514 | struct GNUNET_TIME_Relative delta; | 492 | if (strlen(in) > 0) |
515 | 493 | hn[strlen(in) - 1] = '\0'; /* eat newline */ | |
516 | delta = GNUNET_TIME_absolute_get_duration (last); | 494 | if ((2 != sscanf(in, |
517 | last = GNUNET_TIME_absolute_get (); | 495 | "%u %255s", |
518 | fprintf (stderr, | 496 | &cat, |
519 | "Read 100000 domain names in %s\n", | 497 | hn)) || |
520 | GNUNET_STRINGS_relative_time_to_string (delta, | 498 | (cat >= RC_MAX)) |
521 | GNUNET_YES)); | 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); | ||
522 | } | 521 | } |
523 | queue (hn, | 522 | fprintf(stderr, |
524 | (enum RequestCategory) cat); | 523 | "Done reading %llu domain names\n", |
525 | } | 524 | (unsigned long long)idot); |
526 | fprintf (stderr, | 525 | t = GNUNET_SCHEDULER_add_now(&process_queue, |
527 | "Done reading %llu domain names\n", | 526 | NULL); |
528 | (unsigned long long) idot); | ||
529 | t = GNUNET_SCHEDULER_add_now (&process_queue, | ||
530 | NULL); | ||
531 | } | 527 | } |
532 | 528 | ||
533 | 529 | ||
@@ -541,25 +537,25 @@ process_stdin (void *cls) | |||
541 | * @param cfg configuration | 537 | * @param cfg configuration |
542 | */ | 538 | */ |
543 | static void | 539 | static void |
544 | run (void *cls, | 540 | run(void *cls, |
545 | char *const *args, | 541 | char *const *args, |
546 | const char *cfgfile, | 542 | const char *cfgfile, |
547 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 543 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
548 | { | 544 | { |
549 | (void) cls; | 545 | (void)cls; |
550 | (void) args; | 546 | (void)args; |
551 | (void) cfgfile; | 547 | (void)cfgfile; |
552 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 548 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
553 | NULL); | 549 | NULL); |
554 | gns = GNUNET_GNS_connect (cfg); | 550 | gns = GNUNET_GNS_connect(cfg); |
555 | if (NULL == gns) | 551 | if (NULL == gns) |
556 | { | 552 | { |
557 | GNUNET_break (0); | 553 | GNUNET_break(0); |
558 | GNUNET_SCHEDULER_shutdown (); | 554 | GNUNET_SCHEDULER_shutdown(); |
559 | return; | 555 | return; |
560 | } | 556 | } |
561 | t = GNUNET_SCHEDULER_add_now (&process_stdin, | 557 | t = GNUNET_SCHEDULER_add_now(&process_stdin, |
562 | NULL); | 558 | NULL); |
563 | } | 559 | } |
564 | 560 | ||
565 | 561 | ||
@@ -571,44 +567,44 @@ run (void *cls, | |||
571 | * @return 0 on success | 567 | * @return 0 on success |
572 | */ | 568 | */ |
573 | int | 569 | int |
574 | main (int argc, | 570 | main(int argc, |
575 | char *const*argv) | 571 | char *const*argv) |
576 | { | 572 | { |
577 | int ret = 0; | 573 | int ret = 0; |
578 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 574 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
579 | GNUNET_GETOPT_option_relative_time ('d', | 575 | GNUNET_GETOPT_option_relative_time('d', |
580 | "delay", | 576 | "delay", |
581 | "RELATIVETIME", | 577 | "RELATIVETIME", |
582 | gettext_noop ("how long to wait between queries"), | 578 | gettext_noop("how long to wait between queries"), |
583 | &request_delay), | 579 | &request_delay), |
584 | GNUNET_GETOPT_option_relative_time ('t', | 580 | GNUNET_GETOPT_option_relative_time('t', |
585 | "timeout", | 581 | "timeout", |
586 | "RELATIVETIME", | 582 | "RELATIVETIME", |
587 | gettext_noop ("how long to wait for an answer"), | 583 | gettext_noop("how long to wait for an answer"), |
588 | &timeout), | 584 | &timeout), |
589 | GNUNET_GETOPT_option_flag ('2', | 585 | GNUNET_GETOPT_option_flag('2', |
590 | "g2d", | 586 | "g2d", |
591 | gettext_noop ("look for GNS2DNS records instead of ANY"), | 587 | gettext_noop("look for GNS2DNS records instead of ANY"), |
592 | &g2d), | 588 | &g2d), |
593 | GNUNET_GETOPT_OPTION_END | 589 | GNUNET_GETOPT_OPTION_END |
594 | }; | 590 | }; |
595 | 591 | ||
596 | if (GNUNET_OK != | 592 | if (GNUNET_OK != |
597 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 593 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
598 | &argc, &argv)) | 594 | &argc, &argv)) |
599 | return 2; | 595 | return 2; |
600 | timeout = DEF_TIMEOUT; | 596 | timeout = DEF_TIMEOUT; |
601 | request_delay = DEF_REQUEST_DELAY; | 597 | request_delay = DEF_REQUEST_DELAY; |
602 | if (GNUNET_OK != | 598 | if (GNUNET_OK != |
603 | GNUNET_PROGRAM_run (argc, | 599 | GNUNET_PROGRAM_run(argc, |
604 | argv, | 600 | argv, |
605 | "gnunet-gns-benchmark", | 601 | "gnunet-gns-benchmark", |
606 | "resolve GNS names and measure performance", | 602 | "resolve GNS names and measure performance", |
607 | options, | 603 | options, |
608 | &run, | 604 | &run, |
609 | NULL)) | 605 | NULL)) |
610 | ret = 1; | 606 | ret = 1; |
611 | GNUNET_free ((void*) argv); | 607 | GNUNET_free((void*)argv); |
612 | return ret; | 608 | return ret; |
613 | } | 609 | } |
614 | 610 | ||
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c index 4eb965e24..4c4803556 100644 --- a/src/gns/gnunet-gns-helper-service-w32.c +++ b/src/gns/gnunet-gns-helper-service-w32.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet-gns-helper-service-w32.c | 21 | * @file gnunet-gns-helper-service-w32.c |
22 | * @brief an intermediary service to access distributed GNS | 22 | * @brief an intermediary service to access distributed GNS |
@@ -35,7 +35,7 @@ | |||
35 | #include <nspapi.h> | 35 | #include <nspapi.h> |
36 | #include <unistr.h> | 36 | #include <unistr.h> |
37 | 37 | ||
38 | #define DEFINE_DNS_GUID(a,x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46) | 38 | #define DEFINE_DNS_GUID(a, x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46) |
39 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001); | 39 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001); |
40 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002); | 40 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002); |
41 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005); | 41 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005); |
@@ -49,8 +49,7 @@ DEFINE_GUID(SVCID_HOSTNAME, 0x0002a800, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, | |||
49 | DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); | 49 | DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); |
50 | 50 | ||
51 | 51 | ||
52 | struct request | 52 | struct request { |
53 | { | ||
54 | /** | 53 | /** |
55 | * We keep these in a doubly-linked list (for cleanup). | 54 | * We keep these in a doubly-linked list (for cleanup). |
56 | */ | 55 | */ |
@@ -120,83 +119,83 @@ static int got_egos; | |||
120 | * @param cls unused | 119 | * @param cls unused |
121 | */ | 120 | */ |
122 | static void | 121 | static void |
123 | do_shutdown (void *cls) | 122 | do_shutdown(void *cls) |
124 | { | 123 | { |
125 | struct request *rq; | 124 | struct request *rq; |
126 | 125 | ||
127 | if (NULL != id_op) | 126 | if (NULL != id_op) |
128 | { | 127 | { |
129 | GNUNET_IDENTITY_cancel (id_op); | 128 | GNUNET_IDENTITY_cancel(id_op); |
130 | id_op = NULL; | 129 | id_op = NULL; |
131 | } | 130 | } |
132 | if (NULL != identity) | 131 | if (NULL != identity) |
133 | { | 132 | { |
134 | GNUNET_IDENTITY_disconnect (identity); | 133 | GNUNET_IDENTITY_disconnect(identity); |
135 | identity = NULL; | 134 | identity = NULL; |
136 | } | 135 | } |
137 | while (NULL != (rq = rq_head)) | 136 | while (NULL != (rq = rq_head)) |
138 | { | 137 | { |
139 | if (NULL != rq->lookup_request) | 138 | if (NULL != rq->lookup_request) |
140 | GNUNET_GNS_lookup_cancel (rq->lookup_request); | 139 | GNUNET_GNS_lookup_cancel(rq->lookup_request); |
141 | GNUNET_CONTAINER_DLL_remove (rq_head, | 140 | GNUNET_CONTAINER_DLL_remove(rq_head, |
142 | rq_tail, | 141 | rq_tail, |
143 | rq); | 142 | rq); |
144 | GNUNET_free_non_null (rq->name); | 143 | GNUNET_free_non_null(rq->name); |
145 | if (rq->u8name) | 144 | if (rq->u8name) |
146 | free (rq->u8name); | 145 | free(rq->u8name); |
147 | GNUNET_free (rq); | 146 | GNUNET_free(rq); |
148 | } | 147 | } |
149 | if (NULL != gns) | 148 | if (NULL != gns) |
150 | { | 149 | { |
151 | GNUNET_GNS_disconnect (gns); | 150 | GNUNET_GNS_disconnect(gns); |
152 | gns = NULL; | 151 | gns = NULL; |
153 | } | 152 | } |
154 | } | 153 | } |
155 | 154 | ||
156 | 155 | ||
157 | #define MarshallPtr(ptr, base, type) \ | 156 | #define MarshallPtr(ptr, base, type) \ |
158 | if (ptr) \ | 157 | if (ptr) \ |
159 | ptr = (type *) ((char *) ptr - (char *) base) | 158 | ptr = (type *) ((char *)ptr - (char *)base) |
160 | 159 | ||
161 | 160 | ||
162 | void | 161 | void |
163 | MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc) | 162 | MarshallWSAQUERYSETW(WSAQUERYSETW *qs, GUID *sc) |
164 | { | 163 | { |
165 | MarshallPtr (qs->lpszServiceInstanceName, qs, wchar_t); | 164 | MarshallPtr(qs->lpszServiceInstanceName, qs, wchar_t); |
166 | MarshallPtr (qs->lpServiceClassId, qs, GUID); | 165 | MarshallPtr(qs->lpServiceClassId, qs, GUID); |
167 | MarshallPtr (qs->lpVersion, qs, WSAVERSION); | 166 | MarshallPtr(qs->lpVersion, qs, WSAVERSION); |
168 | MarshallPtr (qs->lpNSProviderId, qs, GUID); | 167 | MarshallPtr(qs->lpNSProviderId, qs, GUID); |
169 | MarshallPtr (qs->lpszContext, qs, wchar_t); | 168 | MarshallPtr(qs->lpszContext, qs, wchar_t); |
170 | MarshallPtr (qs->lpafpProtocols, qs, AFPROTOCOLS); | 169 | MarshallPtr(qs->lpafpProtocols, qs, AFPROTOCOLS); |
171 | MarshallPtr (qs->lpszQueryString, qs, wchar_t); | 170 | MarshallPtr(qs->lpszQueryString, qs, wchar_t); |
172 | for (int i = 0; i < qs->dwNumberOfCsAddrs; i++) | 171 | for (int i = 0; i < qs->dwNumberOfCsAddrs; i++) |
173 | { | 172 | { |
174 | MarshallPtr (qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR); | 173 | MarshallPtr(qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR); |
175 | MarshallPtr (qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR); | 174 | MarshallPtr(qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR); |
176 | } | 175 | } |
177 | MarshallPtr (qs->lpcsaBuffer, qs, CSADDR_INFO); | 176 | MarshallPtr(qs->lpcsaBuffer, qs, CSADDR_INFO); |
178 | if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL) | 177 | if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL) |
179 | { | 178 | { |
180 | struct hostent *he; | 179 | struct hostent *he; |
181 | 180 | ||
182 | he = (struct hostent *) qs->lpBlob->pBlobData; | 181 | he = (struct hostent *)qs->lpBlob->pBlobData; |
183 | for (int i = 0; he->h_aliases[i] != NULL; i++) | 182 | for (int i = 0; he->h_aliases[i] != NULL; i++) |
184 | MarshallPtr (he->h_aliases[i], he, char); | 183 | MarshallPtr(he->h_aliases[i], he, char); |
185 | MarshallPtr (he->h_aliases, he, char *); | 184 | MarshallPtr(he->h_aliases, he, char *); |
186 | MarshallPtr (he->h_name, he, char); | 185 | MarshallPtr(he->h_name, he, char); |
187 | for (int i = 0; he->h_addr_list[i] != NULL; i++) | 186 | for (int i = 0; he->h_addr_list[i] != NULL; i++) |
188 | MarshallPtr (he->h_addr_list[i], he, void); | 187 | MarshallPtr(he->h_addr_list[i], he, void); |
189 | MarshallPtr (he->h_addr_list, he, char *); | 188 | MarshallPtr(he->h_addr_list, he, char *); |
190 | MarshallPtr (qs->lpBlob->pBlobData, qs, void); | 189 | MarshallPtr(qs->lpBlob->pBlobData, qs, void); |
191 | } | 190 | } |
192 | MarshallPtr (qs->lpBlob, qs, BLOB); | 191 | MarshallPtr(qs->lpBlob, qs, BLOB); |
193 | } | 192 | } |
194 | 193 | ||
195 | 194 | ||
196 | static void | 195 | static void |
197 | process_lookup_result (void *cls, | 196 | process_lookup_result(void *cls, |
198 | uint32_t rd_count, | 197 | uint32_t rd_count, |
199 | const struct GNUNET_GNSRECORD_Data *rd) | 198 | const struct GNUNET_GNSRECORD_Data *rd) |
200 | { | 199 | { |
201 | struct request *rq = cls; | 200 | struct request *rq = cls; |
202 | int i, j, csanum; | 201 | int i, j, csanum; |
@@ -211,269 +210,272 @@ process_lookup_result (void *cls, | |||
211 | size_t blobsize = 0; | 210 | size_t blobsize = 0; |
212 | size_t blobaddrcount = 0; | 211 | size_t blobaddrcount = 0; |
213 | 212 | ||
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 213 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
215 | "Got lookup result with count %u for rq %p with client %p\n", | 214 | "Got lookup result with count %u for rq %p with client %p\n", |
216 | rd_count, | 215 | rd_count, |
217 | rq, | 216 | rq, |
218 | rq->client); | 217 | rq->client); |
219 | rq->lookup_request = NULL; | 218 | rq->lookup_request = NULL; |
220 | 219 | ||
221 | if (0 == rd_count) | 220 | if (0 == rd_count) |
222 | { | 221 | { |
223 | msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | 222 | msgend_env = GNUNET_MQ_msg(msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); |
224 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client), | 223 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(rq->client), |
225 | msgend_env); | 224 | msgend_env); |
226 | GNUNET_CONTAINER_DLL_remove (rq_head, | 225 | GNUNET_CONTAINER_DLL_remove(rq_head, |
227 | rq_tail, | 226 | rq_tail, |
228 | rq); | 227 | rq); |
229 | GNUNET_free_non_null (rq->name); | 228 | GNUNET_free_non_null(rq->name); |
230 | if (rq->u8name) | 229 | if (rq->u8name) |
231 | free (rq->u8name); | 230 | free(rq->u8name); |
232 | GNUNET_free (rq); | 231 | GNUNET_free(rq); |
233 | return; | 232 | return; |
234 | } | 233 | } |
235 | 234 | ||
236 | size = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW); | 235 | size = sizeof(struct GNUNET_W32RESOLVER_GetMessage) + sizeof(WSAQUERYSETW); |
237 | size += (wcslen (rq->name) + 1) * sizeof (wchar_t); | 236 | size += (wcslen(rq->name) + 1) * sizeof(wchar_t); |
238 | size += sizeof (GUID); | 237 | size += sizeof(GUID); |
239 | /* lpszComment ? a TXT record? */ | 238 | /* lpszComment ? a TXT record? */ |
240 | size += sizeof (GUID); | 239 | size += sizeof(GUID); |
241 | /* lpszContext ? Not sure what it is */ | 240 | /* lpszContext ? Not sure what it is */ |
242 | csanum = 0; | 241 | csanum = 0; |
243 | for (i = 0; i < rd_count; i++) | 242 | for (i = 0; i < rd_count; i++) |
244 | { | ||
245 | switch (rd[i].record_type) | ||
246 | { | 243 | { |
247 | case GNUNET_DNSPARSER_TYPE_A: | 244 | switch (rd[i].record_type) |
248 | if (rd[i].data_size != sizeof (struct in_addr)) | 245 | { |
249 | continue; | 246 | case GNUNET_DNSPARSER_TYPE_A: |
250 | size += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in) * 2; | 247 | if (rd[i].data_size != sizeof(struct in_addr)) |
251 | csanum++; | 248 | continue; |
252 | break; | 249 | size += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in) * 2; |
253 | case GNUNET_DNSPARSER_TYPE_AAAA: | 250 | csanum++; |
254 | if (rd[i].data_size != sizeof (struct in6_addr)) | 251 | break; |
255 | continue; | 252 | |
256 | size += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in6) * 2; | 253 | case GNUNET_DNSPARSER_TYPE_AAAA: |
257 | csanum++; | 254 | if (rd[i].data_size != sizeof(struct in6_addr)) |
258 | break; | 255 | continue; |
256 | size += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in6) * 2; | ||
257 | csanum++; | ||
258 | break; | ||
259 | } | ||
259 | } | 260 | } |
260 | } | 261 | if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, &rq->sc)) |
261 | if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, &rq->sc)) | ||
262 | { | ||
263 | size += sizeof (BLOB); | ||
264 | blobsize += sizeof (struct hostent); | ||
265 | blobsize += strlen (rq->u8name) + 1; | ||
266 | blobsize += sizeof (void *); /* For aliases */ | ||
267 | blobsize += sizeof (void *); /* For addresses */ | ||
268 | for (i = 0; i < rd_count; i++) | ||
269 | { | 262 | { |
270 | if ((rq->af == AF_INET || rq->af == AF_UNSPEC) && rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | 263 | size += sizeof(BLOB); |
271 | { | 264 | blobsize += sizeof(struct hostent); |
272 | blobsize += sizeof (void *); | 265 | blobsize += strlen(rq->u8name) + 1; |
273 | blobsize += sizeof (struct in_addr); | 266 | blobsize += sizeof(void *); /* For aliases */ |
274 | blobaddrcount++; | 267 | blobsize += sizeof(void *); /* For addresses */ |
275 | } | 268 | for (i = 0; i < rd_count; i++) |
276 | else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA) | 269 | { |
277 | { | 270 | if ((rq->af == AF_INET || rq->af == AF_UNSPEC) && rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) |
278 | blobsize += sizeof (void *); | 271 | { |
279 | blobsize += sizeof (struct in6_addr); | 272 | blobsize += sizeof(void *); |
280 | blobaddrcount++; | 273 | blobsize += sizeof(struct in_addr); |
281 | } | 274 | blobaddrcount++; |
275 | } | ||
276 | else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA) | ||
277 | { | ||
278 | blobsize += sizeof(void *); | ||
279 | blobsize += sizeof(struct in6_addr); | ||
280 | blobaddrcount++; | ||
281 | } | ||
282 | } | ||
283 | size += blobsize; | ||
282 | } | 284 | } |
283 | size += blobsize; | 285 | size_recalc = sizeof(struct GNUNET_W32RESOLVER_GetMessage) + sizeof(WSAQUERYSETW); |
284 | } | 286 | msg_env = GNUNET_MQ_msg_extra(msg, |
285 | size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW); | 287 | size - sizeof(struct GNUNET_MessageHeader), |
286 | msg_env = GNUNET_MQ_msg_extra (msg, | 288 | GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); |
287 | size - sizeof (struct GNUNET_MessageHeader), | 289 | msg->af = htonl(rq->af); |
288 | GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | 290 | msg->sc_data1 = htonl(rq->sc.Data1); |
289 | msg->af = htonl (rq->af); | 291 | msg->sc_data2 = htons(rq->sc.Data2); |
290 | msg->sc_data1 = htonl (rq->sc.Data1); | 292 | msg->sc_data3 = htons(rq->sc.Data3); |
291 | msg->sc_data2 = htons (rq->sc.Data2); | ||
292 | msg->sc_data3 = htons (rq->sc.Data3); | ||
293 | for (i = 0; i < 8; i++) | 293 | for (i = 0; i < 8; i++) |
294 | msg->sc_data4[i] = rq->sc.Data4[i]; | 294 | msg->sc_data4[i] = rq->sc.Data4[i]; |
295 | qs = (WSAQUERYSETW *) &msg[1]; | 295 | qs = (WSAQUERYSETW *)&msg[1]; |
296 | ptr = (char *) &qs[1]; | 296 | ptr = (char *)&qs[1]; |
297 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 297 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
298 | qs->dwSize = sizeof (WSAQUERYSETW); | 298 | qs->dwSize = sizeof(WSAQUERYSETW); |
299 | qs->lpszServiceInstanceName = (wchar_t *) ptr; | 299 | qs->lpszServiceInstanceName = (wchar_t *)ptr; |
300 | ptr += (wcslen (rq->name) + 1) * sizeof (wchar_t); | 300 | ptr += (wcslen(rq->name) + 1) * sizeof(wchar_t); |
301 | size_recalc += (wcslen (rq->name) + 1) * sizeof (wchar_t); | 301 | size_recalc += (wcslen(rq->name) + 1) * sizeof(wchar_t); |
302 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 302 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
303 | wcscpy (qs->lpszServiceInstanceName, rq->name); | 303 | wcscpy(qs->lpszServiceInstanceName, rq->name); |
304 | qs->lpServiceClassId = (GUID *) ptr; | 304 | qs->lpServiceClassId = (GUID *)ptr; |
305 | ptr += sizeof (GUID); | 305 | ptr += sizeof(GUID); |
306 | size_recalc += sizeof (GUID); | 306 | size_recalc += sizeof(GUID); |
307 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 307 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
308 | GNUNET_memcpy (qs->lpServiceClassId, &rq->sc, sizeof (GUID)); | 308 | GNUNET_memcpy(qs->lpServiceClassId, &rq->sc, sizeof(GUID)); |
309 | qs->lpVersion = NULL; | 309 | qs->lpVersion = NULL; |
310 | qs->dwNameSpace = NS_DNS; | 310 | qs->dwNameSpace = NS_DNS; |
311 | qs->lpNSProviderId = (GUID *) ptr; | 311 | qs->lpNSProviderId = (GUID *)ptr; |
312 | ptr += sizeof (GUID); | 312 | ptr += sizeof(GUID); |
313 | size_recalc += sizeof (GUID); | 313 | size_recalc += sizeof(GUID); |
314 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 314 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
315 | GNUNET_memcpy (qs->lpNSProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS, sizeof (GUID)); | 315 | GNUNET_memcpy(qs->lpNSProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS, sizeof(GUID)); |
316 | qs->lpszContext = NULL; | 316 | qs->lpszContext = NULL; |
317 | qs->dwNumberOfProtocols = 0; | 317 | qs->dwNumberOfProtocols = 0; |
318 | qs->lpafpProtocols = NULL; | 318 | qs->lpafpProtocols = NULL; |
319 | /* Don't bother with this... */ | 319 | /* Don't bother with this... */ |
320 | qs->lpszQueryString = NULL; | 320 | qs->lpszQueryString = NULL; |
321 | qs->dwNumberOfCsAddrs = rd_count; | 321 | qs->dwNumberOfCsAddrs = rd_count; |
322 | qs->lpcsaBuffer = (CSADDR_INFO *) ptr; | 322 | qs->lpcsaBuffer = (CSADDR_INFO *)ptr; |
323 | ptr += sizeof (CSADDR_INFO) * csanum; | 323 | ptr += sizeof(CSADDR_INFO) * csanum; |
324 | j = 0; | 324 | j = 0; |
325 | for (i = 0; i < rd_count; i++) | 325 | for (i = 0; i < rd_count; i++) |
326 | { | ||
327 | switch (rd[i].record_type) | ||
328 | { | 326 | { |
329 | case GNUNET_DNSPARSER_TYPE_A: | 327 | switch (rd[i].record_type) |
330 | if (rd[i].data_size != sizeof (struct in_addr)) | 328 | { |
331 | continue; | 329 | case GNUNET_DNSPARSER_TYPE_A: |
332 | qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM; | 330 | if (rd[i].data_size != sizeof(struct in_addr)) |
333 | qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP; | 331 | continue; |
334 | 332 | qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM; | |
335 | qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof (struct sockaddr_in); | 333 | qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP; |
336 | qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *) ptr; | 334 | |
337 | ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength; | 335 | qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof(struct sockaddr_in); |
338 | memset (qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength); | 336 | qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *)ptr; |
339 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin_family = AF_INET; | 337 | ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength; |
340 | 338 | memset(qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength); | |
341 | qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof (struct sockaddr_in); | 339 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin_family = AF_INET; |
342 | qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *) ptr; | 340 | |
343 | ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength; | 341 | qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof(struct sockaddr_in); |
344 | memset (qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength); | 342 | qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *)ptr; |
345 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_family = AF_INET; | 343 | ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength; |
346 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_port = htonl (53); /* Don't ask why it's 53 */ | 344 | memset(qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength); |
347 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_addr = *(struct in_addr *) rd[i].data; | 345 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_family = AF_INET; |
348 | size_recalc += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in) * 2; | 346 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_port = htonl(53); /* Don't ask why it's 53 */ |
349 | j++; | 347 | ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_addr = *(struct in_addr *)rd[i].data; |
350 | break; | 348 | size_recalc += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in) * 2; |
351 | case GNUNET_DNSPARSER_TYPE_AAAA: | 349 | j++; |
352 | if (rd[i].data_size != sizeof (struct in6_addr)) | 350 | break; |
353 | continue; | 351 | |
354 | qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM; | 352 | case GNUNET_DNSPARSER_TYPE_AAAA: |
355 | qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP; | 353 | if (rd[i].data_size != sizeof(struct in6_addr)) |
356 | 354 | continue; | |
357 | qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof (struct sockaddr_in6); | 355 | qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM; |
358 | qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *) ptr; | 356 | qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP; |
359 | ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength; | 357 | |
360 | memset (qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength); | 358 | qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof(struct sockaddr_in6); |
361 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin6_family = AF_INET6; | 359 | qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *)ptr; |
362 | 360 | ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength; | |
363 | qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof (struct sockaddr_in6); | 361 | memset(qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength); |
364 | qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *) ptr; | 362 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin6_family = AF_INET6; |
365 | ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength; | 363 | |
366 | memset (qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength); | 364 | qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof(struct sockaddr_in6); |
367 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_family = AF_INET6; | 365 | qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *)ptr; |
368 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_port = htonl (53); /* Don't ask why it's 53 */ | 366 | ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength; |
369 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_addr = *(struct in6_addr *) rd[i].data; | 367 | memset(qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength); |
370 | size_recalc += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in6) * 2; | 368 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_family = AF_INET6; |
371 | j++; | 369 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_port = htonl(53); /* Don't ask why it's 53 */ |
372 | break; | 370 | ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_addr = *(struct in6_addr *)rd[i].data; |
373 | default: | 371 | size_recalc += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in6) * 2; |
374 | break; | 372 | j++; |
373 | break; | ||
374 | |||
375 | default: | ||
376 | break; | ||
377 | } | ||
375 | } | 378 | } |
376 | } | 379 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
377 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | ||
378 | qs->dwOutputFlags = 0; | 380 | qs->dwOutputFlags = 0; |
379 | if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, &rq->sc)) | 381 | if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, &rq->sc)) |
380 | { | 382 | { |
381 | struct hostent *he; | 383 | struct hostent *he; |
382 | qs->lpBlob = (BLOB *) ptr; | 384 | qs->lpBlob = (BLOB *)ptr; |
383 | ptr += sizeof (BLOB); | 385 | ptr += sizeof(BLOB); |
384 | 386 | ||
385 | size_recalc += sizeof (BLOB); | 387 | size_recalc += sizeof(BLOB); |
386 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 388 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
387 | 389 | ||
388 | qs->lpBlob->cbSize = blobsize; | 390 | qs->lpBlob->cbSize = blobsize; |
389 | qs->lpBlob->pBlobData = (BYTE *) ptr; | 391 | qs->lpBlob->pBlobData = (BYTE *)ptr; |
390 | ptr += sizeof (struct hostent); | 392 | ptr += sizeof(struct hostent); |
391 | 393 | ||
392 | size_recalc += sizeof (struct hostent); | 394 | size_recalc += sizeof(struct hostent); |
393 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 395 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
394 | 396 | ||
395 | he = (struct hostent *) qs->lpBlob->pBlobData; | 397 | he = (struct hostent *)qs->lpBlob->pBlobData; |
396 | he->h_name = (char *) ptr; | 398 | he->h_name = (char *)ptr; |
397 | ptr += strlen (rq->u8name) + 1; | 399 | ptr += strlen(rq->u8name) + 1; |
398 | 400 | ||
399 | size_recalc += strlen (rq->u8name) + 1; | 401 | size_recalc += strlen(rq->u8name) + 1; |
400 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 402 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
401 | 403 | ||
402 | strcpy (he->h_name, rq->u8name); | 404 | strcpy(he->h_name, rq->u8name); |
403 | he->h_aliases = (char **) ptr; | 405 | he->h_aliases = (char **)ptr; |
404 | ptr += sizeof (void *); | 406 | ptr += sizeof(void *); |
405 | 407 | ||
406 | size_recalc += sizeof (void *); /* For aliases */ | 408 | size_recalc += sizeof(void *); /* For aliases */ |
407 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 409 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
408 | 410 | ||
409 | he->h_aliases[0] = NULL; | 411 | he->h_aliases[0] = NULL; |
410 | he->h_addrtype = rq->af; | 412 | he->h_addrtype = rq->af; |
411 | he->h_length = rq->af == AF_INET || rq->af == AF_UNSPEC ? sizeof (struct in_addr) : sizeof (struct in6_addr); | 413 | he->h_length = rq->af == AF_INET || rq->af == AF_UNSPEC ? sizeof(struct in_addr) : sizeof(struct in6_addr); |
412 | he->h_addr_list = (char **) ptr; | 414 | he->h_addr_list = (char **)ptr; |
413 | ptr += sizeof (void *) * (blobaddrcount + 1); | 415 | ptr += sizeof(void *) * (blobaddrcount + 1); |
414 | 416 | ||
415 | size_recalc += sizeof (void *) * (blobaddrcount + 1); /* For addresses */ | 417 | size_recalc += sizeof(void *) * (blobaddrcount + 1); /* For addresses */ |
416 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | 418 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); |
419 | |||
420 | j = 0; | ||
421 | for (i = 0; i < rd_count; i++) | ||
422 | { | ||
423 | if ((rq->af == AF_INET || rq->af == AF_UNSPEC) && | ||
424 | rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | ||
425 | { | ||
426 | he->h_addr_list[j] = (char *)ptr; | ||
427 | ptr += sizeof(struct in_addr); | ||
428 | |||
429 | size_recalc += sizeof(struct in_addr); | ||
430 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); | ||
431 | |||
432 | GNUNET_memcpy(he->h_addr_list[j], rd[i].data, sizeof(struct in_addr)); | ||
433 | j++; | ||
434 | } | ||
435 | else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA) | ||
436 | { | ||
437 | he->h_addr_list[j] = (char *)ptr; | ||
438 | ptr += sizeof(struct in6_addr); | ||
439 | |||
440 | size_recalc += sizeof(struct in6_addr); | ||
441 | GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg)); | ||
442 | |||
443 | GNUNET_memcpy(he->h_addr_list[j], rd[i].data, sizeof(struct in6_addr)); | ||
444 | j++; | ||
445 | } | ||
446 | } | ||
447 | he->h_addr_list[j] = NULL; | ||
448 | } | ||
449 | msgend_env = GNUNET_MQ_msg(msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | ||
417 | 450 | ||
418 | j = 0; | 451 | if ((char *)ptr - (char *)msg != size || size_recalc != size || size_recalc != ((char *)ptr - (char *)msg)) |
419 | for (i = 0; i < rd_count; i++) | ||
420 | { | 452 | { |
421 | if ((rq->af == AF_INET || rq->af == AF_UNSPEC) && | 453 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
422 | rd[i].record_type == GNUNET_DNSPARSER_TYPE_A) | 454 | "Error in WSAQUERYSETW size calc: expected %u, got %lu (recalc %u)\n", |
423 | { | 455 | size, |
424 | he->h_addr_list[j] = (char *) ptr; | 456 | (unsigned long)((char *)ptr - (char *)msg), |
425 | ptr += sizeof (struct in_addr); | 457 | size_recalc); |
426 | |||
427 | size_recalc += sizeof (struct in_addr); | ||
428 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | ||
429 | |||
430 | GNUNET_memcpy (he->h_addr_list[j], rd[i].data, sizeof (struct in_addr)); | ||
431 | j++; | ||
432 | } | ||
433 | else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA) | ||
434 | { | ||
435 | he->h_addr_list[j] = (char *) ptr; | ||
436 | ptr += sizeof (struct in6_addr); | ||
437 | |||
438 | size_recalc += sizeof (struct in6_addr); | ||
439 | GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg)); | ||
440 | |||
441 | GNUNET_memcpy (he->h_addr_list[j], rd[i].data, sizeof (struct in6_addr)); | ||
442 | j++; | ||
443 | } | ||
444 | } | 458 | } |
445 | he->h_addr_list[j] = NULL; | 459 | MarshallWSAQUERYSETW(qs, &rq->sc); |
446 | } | 460 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(rq->client), |
447 | msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | 461 | msg_env); |
448 | 462 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(rq->client), | |
449 | if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg)) | 463 | msgend_env); |
450 | { | 464 | GNUNET_CONTAINER_DLL_remove(rq_head, |
451 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 465 | rq_tail, |
452 | "Error in WSAQUERYSETW size calc: expected %u, got %lu (recalc %u)\n", | 466 | rq); |
453 | size, | 467 | GNUNET_free_non_null(rq->name); |
454 | (unsigned long) ((char *) ptr - (char *) msg), | ||
455 | size_recalc); | ||
456 | } | ||
457 | MarshallWSAQUERYSETW (qs, &rq->sc); | ||
458 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client), | ||
459 | msg_env); | ||
460 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client), | ||
461 | msgend_env); | ||
462 | GNUNET_CONTAINER_DLL_remove (rq_head, | ||
463 | rq_tail, | ||
464 | rq); | ||
465 | GNUNET_free_non_null (rq->name); | ||
466 | if (rq->u8name) | 468 | if (rq->u8name) |
467 | free (rq->u8name); | 469 | free(rq->u8name); |
468 | GNUNET_free (rq); | 470 | GNUNET_free(rq); |
469 | } | 471 | } |
470 | 472 | ||
471 | 473 | ||
472 | static void | 474 | static void |
473 | get_ip_from_hostname (struct GNUNET_SERVICE_Client *client, | 475 | get_ip_from_hostname(struct GNUNET_SERVICE_Client *client, |
474 | const wchar_t *name, | 476 | const wchar_t *name, |
475 | int af, | 477 | int af, |
476 | GUID sc) | 478 | GUID sc) |
477 | { | 479 | { |
478 | struct request *rq; | 480 | struct request *rq; |
479 | char *hostname; | 481 | char *hostname; |
@@ -481,104 +483,104 @@ get_ip_from_hostname (struct GNUNET_SERVICE_Client *client, | |||
481 | size_t namelen; | 483 | size_t namelen; |
482 | uint32_t rtype; | 484 | uint32_t rtype; |
483 | 485 | ||
484 | if (IsEqualGUID (&SVCID_DNS_TYPE_A, &sc)) | 486 | if (IsEqualGUID(&SVCID_DNS_TYPE_A, &sc)) |
485 | rtype = GNUNET_DNSPARSER_TYPE_A; | 487 | rtype = GNUNET_DNSPARSER_TYPE_A; |
486 | else if (IsEqualGUID (&SVCID_DNS_TYPE_NS, &sc)) | 488 | else if (IsEqualGUID(&SVCID_DNS_TYPE_NS, &sc)) |
487 | rtype = GNUNET_DNSPARSER_TYPE_NS; | 489 | rtype = GNUNET_DNSPARSER_TYPE_NS; |
488 | else if (IsEqualGUID (&SVCID_DNS_TYPE_CNAME, &sc)) | 490 | else if (IsEqualGUID(&SVCID_DNS_TYPE_CNAME, &sc)) |
489 | rtype = GNUNET_DNSPARSER_TYPE_CNAME; | 491 | rtype = GNUNET_DNSPARSER_TYPE_CNAME; |
490 | else if (IsEqualGUID (&SVCID_DNS_TYPE_SOA, &sc)) | 492 | else if (IsEqualGUID(&SVCID_DNS_TYPE_SOA, &sc)) |
491 | rtype = GNUNET_DNSPARSER_TYPE_SOA; | 493 | rtype = GNUNET_DNSPARSER_TYPE_SOA; |
492 | else if (IsEqualGUID (&SVCID_DNS_TYPE_PTR, &sc)) | 494 | else if (IsEqualGUID(&SVCID_DNS_TYPE_PTR, &sc)) |
493 | rtype = GNUNET_DNSPARSER_TYPE_PTR; | 495 | rtype = GNUNET_DNSPARSER_TYPE_PTR; |
494 | else if (IsEqualGUID (&SVCID_DNS_TYPE_MX, &sc)) | 496 | else if (IsEqualGUID(&SVCID_DNS_TYPE_MX, &sc)) |
495 | rtype = GNUNET_DNSPARSER_TYPE_MX; | 497 | rtype = GNUNET_DNSPARSER_TYPE_MX; |
496 | else if (IsEqualGUID (&SVCID_DNS_TYPE_TEXT, &sc)) | 498 | else if (IsEqualGUID(&SVCID_DNS_TYPE_TEXT, &sc)) |
497 | rtype = GNUNET_DNSPARSER_TYPE_TXT; | 499 | rtype = GNUNET_DNSPARSER_TYPE_TXT; |
498 | else if (IsEqualGUID (&SVCID_DNS_TYPE_AAAA, &sc)) | 500 | else if (IsEqualGUID(&SVCID_DNS_TYPE_AAAA, &sc)) |
499 | rtype = GNUNET_DNSPARSER_TYPE_AAAA; | 501 | rtype = GNUNET_DNSPARSER_TYPE_AAAA; |
500 | else if (IsEqualGUID (&SVCID_DNS_TYPE_SRV, &sc)) | 502 | else if (IsEqualGUID(&SVCID_DNS_TYPE_SRV, &sc)) |
501 | rtype = GNUNET_DNSPARSER_TYPE_SRV; | 503 | rtype = GNUNET_DNSPARSER_TYPE_SRV; |
502 | else if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, &sc)) | 504 | else if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, &sc)) |
503 | rtype = GNUNET_DNSPARSER_TYPE_A; | 505 | rtype = GNUNET_DNSPARSER_TYPE_A; |
504 | else | 506 | else |
505 | { | 507 | { |
506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 508 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
507 | "Unknown GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", | 509 | "Unknown GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", |
508 | sc.Data1, | 510 | sc.Data1, |
509 | sc.Data2, | 511 | sc.Data2, |
510 | sc.Data3, | 512 | sc.Data3, |
511 | sc.Data4[0], | 513 | sc.Data4[0], |
512 | sc.Data4[1], | 514 | sc.Data4[1], |
513 | sc.Data4[2], | 515 | sc.Data4[2], |
514 | sc.Data4[3], | 516 | sc.Data4[3], |
515 | sc.Data4[4], | 517 | sc.Data4[4], |
516 | sc.Data4[5], | 518 | sc.Data4[5], |
517 | sc.Data4[6], | 519 | sc.Data4[6], |
518 | sc.Data4[7]); | 520 | sc.Data4[7]); |
519 | GNUNET_SERVICE_client_drop (client); | 521 | GNUNET_SERVICE_client_drop(client); |
520 | return; | 522 | return; |
521 | } | 523 | } |
522 | 524 | ||
523 | if (name) | 525 | if (name) |
524 | namelen = wcslen (name); | 526 | namelen = wcslen(name); |
525 | else | 527 | else |
526 | namelen = 0; | 528 | namelen = 0; |
527 | if (namelen > 0) | 529 | if (namelen > 0) |
528 | hostname = (char *) u16_to_u8 (name, namelen + 1, NULL, &strl); | 530 | hostname = (char *)u16_to_u8(name, namelen + 1, NULL, &strl); |
529 | else | 531 | else |
530 | hostname = NULL; | 532 | hostname = NULL; |
531 | 533 | ||
532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
533 | "W32 DNS resolver asked to look up %s for `%s'.\n", | 535 | "W32 DNS resolver asked to look up %s for `%s'.\n", |
534 | af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything", | 536 | af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything", |
535 | hostname); | 537 | hostname); |
536 | 538 | ||
537 | rq = GNUNET_new (struct request); | 539 | rq = GNUNET_new(struct request); |
538 | rq->sc = sc; | 540 | rq->sc = sc; |
539 | rq->client = client; | 541 | rq->client = client; |
540 | rq->af = af; | 542 | rq->af = af; |
541 | if (rq->af != AF_INET && rq->af != AF_INET6) | 543 | if (rq->af != AF_INET && rq->af != AF_INET6) |
542 | rq->af = AF_INET; | 544 | rq->af = AF_INET; |
543 | if (namelen) | 545 | if (namelen) |
544 | { | 546 | { |
545 | rq->name = GNUNET_malloc ((namelen + 1) * sizeof (wchar_t)); | 547 | rq->name = GNUNET_malloc((namelen + 1) * sizeof(wchar_t)); |
546 | GNUNET_memcpy (rq->name, | 548 | GNUNET_memcpy(rq->name, |
547 | name, | 549 | name, |
548 | (namelen + 1) * sizeof (wchar_t)); | 550 | (namelen + 1) * sizeof(wchar_t)); |
549 | rq->u8name = hostname; | 551 | rq->u8name = hostname; |
550 | } | 552 | } |
551 | 553 | ||
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 554 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
553 | "Launching a lookup for client %p with rq %p\n", | 555 | "Launching a lookup for client %p with rq %p\n", |
554 | client, | 556 | client, |
555 | rq); | 557 | rq); |
556 | rq->lookup_request = GNUNET_GNS_lookup (gns, | 558 | rq->lookup_request = GNUNET_GNS_lookup(gns, |
557 | hostname, | 559 | hostname, |
558 | &gns_master_pubkey, | 560 | &gns_master_pubkey, |
559 | rtype, | 561 | rtype, |
560 | GNUNET_NO /* Use DHT */, | 562 | GNUNET_NO /* Use DHT */, |
561 | &process_lookup_result, | 563 | &process_lookup_result, |
562 | rq); | 564 | rq); |
563 | if (NULL != rq->lookup_request) | 565 | if (NULL != rq->lookup_request) |
564 | { | 566 | { |
565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 567 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
566 | "Lookup launched, waiting for a reply\n"); | 568 | "Lookup launched, waiting for a reply\n"); |
567 | GNUNET_SERVICE_client_continue (client); | 569 | GNUNET_SERVICE_client_continue(client); |
568 | GNUNET_CONTAINER_DLL_insert (rq_head, | 570 | GNUNET_CONTAINER_DLL_insert(rq_head, |
569 | rq_tail, | 571 | rq_tail, |
570 | rq); | 572 | rq); |
571 | } | 573 | } |
572 | else | 574 | else |
573 | { | 575 | { |
574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 576 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
575 | "Lookup was not launched, disconnecting the client\n"); | 577 | "Lookup was not launched, disconnecting the client\n"); |
576 | GNUNET_free_non_null (rq->name); | 578 | GNUNET_free_non_null(rq->name); |
577 | if (rq->u8name) | 579 | if (rq->u8name) |
578 | free (rq->u8name); | 580 | free(rq->u8name); |
579 | GNUNET_free (rq); | 581 | GNUNET_free(rq); |
580 | GNUNET_SERVICE_client_drop (client); | 582 | GNUNET_SERVICE_client_drop(client); |
581 | } | 583 | } |
582 | } | 584 | } |
583 | 585 | ||
584 | 586 | ||
@@ -590,25 +592,25 @@ get_ip_from_hostname (struct GNUNET_SERVICE_Client *client, | |||
590 | * @return #GNUNET_OK if @a msg is well-formed | 592 | * @return #GNUNET_OK if @a msg is well-formed |
591 | */ | 593 | */ |
592 | static int | 594 | static int |
593 | check_get (void *cls, | 595 | check_get(void *cls, |
594 | const struct GNUNET_W32RESOLVER_GetMessage *msg) | 596 | const struct GNUNET_W32RESOLVER_GetMessage *msg) |
595 | { | 597 | { |
596 | uint16_t size; | 598 | uint16_t size; |
597 | const wchar_t *hostname; | 599 | const wchar_t *hostname; |
598 | 600 | ||
599 | if (! got_egos) | 601 | if (!got_egos) |
600 | { | 602 | { |
601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 603 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
602 | _("Not ready to process requests, lacking ego data\n")); | 604 | _("Not ready to process requests, lacking ego data\n")); |
603 | return GNUNET_SYSERR; | 605 | return GNUNET_SYSERR; |
604 | } | 606 | } |
605 | size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage); | 607 | size = ntohs(msg->header.size) - sizeof(struct GNUNET_W32RESOLVER_GetMessage); |
606 | hostname = (const wchar_t *) &msg[1]; | 608 | hostname = (const wchar_t *)&msg[1]; |
607 | if (hostname[size / 2 - 1] != L'\0') | 609 | if (hostname[size / 2 - 1] != L'\0') |
608 | { | 610 | { |
609 | GNUNET_break (0); | 611 | GNUNET_break(0); |
610 | return GNUNET_SYSERR; | 612 | return GNUNET_SYSERR; |
611 | } | 613 | } |
612 | return GNUNET_OK; | 614 | return GNUNET_OK; |
613 | } | 615 | } |
614 | 616 | ||
@@ -620,8 +622,8 @@ check_get (void *cls, | |||
620 | * @param msg the actual message | 622 | * @param msg the actual message |
621 | */ | 623 | */ |
622 | static void | 624 | static void |
623 | handle_get (void *cls, | 625 | handle_get(void *cls, |
624 | const struct GNUNET_W32RESOLVER_GetMessage *msg) | 626 | const struct GNUNET_W32RESOLVER_GetMessage *msg) |
625 | { | 627 | { |
626 | struct GNUNET_SERVICE_Client *client = cls; | 628 | struct GNUNET_SERVICE_Client *client = cls; |
627 | GUID sc; | 629 | GUID sc; |
@@ -629,50 +631,50 @@ handle_get (void *cls, | |||
629 | const wchar_t *hostname; | 631 | const wchar_t *hostname; |
630 | int af; | 632 | int af; |
631 | 633 | ||
632 | size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage); | 634 | size = ntohs(msg->header.size) - sizeof(struct GNUNET_W32RESOLVER_GetMessage); |
633 | af = ntohl (msg->af); | 635 | af = ntohl(msg->af); |
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 636 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
635 | "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", | 637 | "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", |
636 | msg->sc_data1, | 638 | msg->sc_data1, |
637 | msg->sc_data2, | 639 | msg->sc_data2, |
638 | msg->sc_data3, | 640 | msg->sc_data3, |
639 | msg->sc_data4[0], | 641 | msg->sc_data4[0], |
640 | msg->sc_data4[1], | 642 | msg->sc_data4[1], |
641 | msg->sc_data4[2], | 643 | msg->sc_data4[2], |
642 | msg->sc_data4[3], | 644 | msg->sc_data4[3], |
643 | msg->sc_data4[4], | 645 | msg->sc_data4[4], |
644 | msg->sc_data4[5], | 646 | msg->sc_data4[5], |
645 | msg->sc_data4[6], | 647 | msg->sc_data4[6], |
646 | msg->sc_data4[7]); | 648 | msg->sc_data4[7]); |
647 | sc.Data1 = ntohl (msg->sc_data1); | 649 | sc.Data1 = ntohl(msg->sc_data1); |
648 | sc.Data2 = ntohs (msg->sc_data2); | 650 | sc.Data2 = ntohs(msg->sc_data2); |
649 | sc.Data3 = ntohs (msg->sc_data3); | 651 | sc.Data3 = ntohs(msg->sc_data3); |
650 | for (int i = 0; i < 8; i++) | 652 | for (int i = 0; i < 8; i++) |
651 | sc.Data4[i] = msg->sc_data4[i]; | 653 | sc.Data4[i] = msg->sc_data4[i]; |
652 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 654 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
653 | "Got GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", | 655 | "Got GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", |
654 | sc.Data1, | 656 | sc.Data1, |
655 | sc.Data2, | 657 | sc.Data2, |
656 | sc.Data3, | 658 | sc.Data3, |
657 | sc.Data4[0], | 659 | sc.Data4[0], |
658 | sc.Data4[1], | 660 | sc.Data4[1], |
659 | sc.Data4[2], | 661 | sc.Data4[2], |
660 | sc.Data4[3], | 662 | sc.Data4[3], |
661 | sc.Data4[4], | 663 | sc.Data4[4], |
662 | sc.Data4[5], | 664 | sc.Data4[5], |
663 | sc.Data4[6], | 665 | sc.Data4[6], |
664 | sc.Data4[7]); | 666 | sc.Data4[7]); |
665 | hostname = (const wchar_t *) &msg[1]; | 667 | hostname = (const wchar_t *)&msg[1]; |
666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 668 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
667 | "Name of %u bytes (last word is 0x%0X): %*S\n", | 669 | "Name of %u bytes (last word is 0x%0X): %*S\n", |
668 | size, | 670 | size, |
669 | hostname[size / 2 - 2], | 671 | hostname[size / 2 - 2], |
670 | size / 2, | 672 | size / 2, |
671 | hostname); | 673 | hostname); |
672 | get_ip_from_hostname (client, | 674 | get_ip_from_hostname(client, |
673 | hostname, | 675 | hostname, |
674 | af, | 676 | af, |
675 | sc); | 677 | sc); |
676 | } | 678 | } |
677 | 679 | ||
678 | 680 | ||
@@ -689,21 +691,21 @@ handle_get (void *cls, | |||
689 | * must thus no longer be used | 691 | * must thus no longer be used |
690 | */ | 692 | */ |
691 | static void | 693 | static void |
692 | identity_master_cb (void *cls, | 694 | identity_master_cb(void *cls, |
693 | struct GNUNET_IDENTITY_Ego *ego, | 695 | struct GNUNET_IDENTITY_Ego *ego, |
694 | void **ctx, | 696 | void **ctx, |
695 | const char *name) | 697 | const char *name) |
696 | { | 698 | { |
697 | id_op = NULL; | 699 | id_op = NULL; |
698 | if (NULL == ego) | 700 | if (NULL == ego) |
699 | { | 701 | { |
700 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 702 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
701 | _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); | 703 | _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); |
702 | GNUNET_SCHEDULER_shutdown (); | 704 | GNUNET_SCHEDULER_shutdown(); |
703 | return; | 705 | return; |
704 | } | 706 | } |
705 | GNUNET_IDENTITY_ego_get_public_key (ego, | 707 | GNUNET_IDENTITY_ego_get_public_key(ego, |
706 | &gns_master_pubkey); | 708 | &gns_master_pubkey); |
707 | got_egos = 1; | 709 | got_egos = 1; |
708 | } | 710 | } |
709 | 711 | ||
@@ -716,35 +718,35 @@ identity_master_cb (void *cls, | |||
716 | * @param service the initialized service | 718 | * @param service the initialized service |
717 | */ | 719 | */ |
718 | static void | 720 | static void |
719 | run (void *cls, | 721 | run(void *cls, |
720 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 722 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
721 | struct GNUNET_SERVICE_Handle *service) | 723 | struct GNUNET_SERVICE_Handle *service) |
722 | { | 724 | { |
723 | gns = GNUNET_GNS_connect (cfg); | 725 | gns = GNUNET_GNS_connect(cfg); |
724 | if (NULL == gns) | 726 | if (NULL == gns) |
725 | { | 727 | { |
726 | fprintf (stderr, | 728 | fprintf(stderr, |
727 | _("Failed to connect to GNS\n")); | 729 | _("Failed to connect to GNS\n")); |
728 | GNUNET_SCHEDULER_shutdown (); | 730 | GNUNET_SCHEDULER_shutdown(); |
729 | return; | 731 | return; |
730 | } | 732 | } |
731 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 733 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
732 | NULL); | 734 | NULL); |
733 | identity = GNUNET_IDENTITY_connect (cfg, | 735 | identity = GNUNET_IDENTITY_connect(cfg, |
734 | NULL, | 736 | NULL, |
735 | NULL); | 737 | NULL); |
736 | if (NULL == identity) | 738 | if (NULL == identity) |
737 | { | 739 | { |
738 | fprintf (stderr, | 740 | fprintf(stderr, |
739 | _("Failed to connect to identity service\n")); | 741 | _("Failed to connect to identity service\n")); |
740 | GNUNET_SCHEDULER_shutdown (); | 742 | GNUNET_SCHEDULER_shutdown(); |
741 | return; | 743 | return; |
742 | } | 744 | } |
743 | id_op = GNUNET_IDENTITY_get (identity, | 745 | id_op = GNUNET_IDENTITY_get(identity, |
744 | "gns-master", | 746 | "gns-master", |
745 | &identity_master_cb, | 747 | &identity_master_cb, |
746 | NULL); | 748 | NULL); |
747 | GNUNET_assert (NULL != id_op); | 749 | GNUNET_assert(NULL != id_op); |
748 | } | 750 | } |
749 | 751 | ||
750 | 752 | ||
@@ -757,9 +759,9 @@ run (void *cls, | |||
757 | * @return @a client | 759 | * @return @a client |
758 | */ | 760 | */ |
759 | static void * | 761 | static void * |
760 | client_connect_cb (void *cls, | 762 | client_connect_cb(void *cls, |
761 | struct GNUNET_SERVICE_Client *client, | 763 | struct GNUNET_SERVICE_Client *client, |
762 | struct GNUNET_MQ_Handle *mq) | 764 | struct GNUNET_MQ_Handle *mq) |
763 | { | 765 | { |
764 | return client; | 766 | return client; |
765 | } | 767 | } |
@@ -773,11 +775,11 @@ client_connect_cb (void *cls, | |||
773 | * @param internal_cls should be equal to @a c | 775 | * @param internal_cls should be equal to @a c |
774 | */ | 776 | */ |
775 | static void | 777 | static void |
776 | client_disconnect_cb (void *cls, | 778 | client_disconnect_cb(void *cls, |
777 | struct GNUNET_SERVICE_Client *client, | 779 | struct GNUNET_SERVICE_Client *client, |
778 | void *internal_cls) | 780 | void *internal_cls) |
779 | { | 781 | { |
780 | GNUNET_assert (internal_cls == client); | 782 | GNUNET_assert(internal_cls == client); |
781 | } | 783 | } |
782 | 784 | ||
783 | 785 | ||
@@ -785,17 +787,17 @@ client_disconnect_cb (void *cls, | |||
785 | * Define "main" method using service macro. | 787 | * Define "main" method using service macro. |
786 | */ | 788 | */ |
787 | GNUNET_SERVICE_MAIN | 789 | GNUNET_SERVICE_MAIN |
788 | ("gns-helper-service-w32", | 790 | ("gns-helper-service-w32", |
789 | GNUNET_SERVICE_OPTION_NONE, | 791 | GNUNET_SERVICE_OPTION_NONE, |
790 | &run, | 792 | &run, |
791 | &client_connect_cb, | 793 | &client_connect_cb, |
792 | &client_disconnect_cb, | 794 | &client_disconnect_cb, |
793 | NULL, | 795 | NULL, |
794 | GNUNET_MQ_hd_var_size (get, | 796 | GNUNET_MQ_hd_var_size(get, |
795 | GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST, | 797 | GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST, |
796 | struct GNUNET_W32RESOLVER_GetMessage, | 798 | struct GNUNET_W32RESOLVER_GetMessage, |
797 | NULL), | 799 | NULL), |
798 | GNUNET_MQ_handler_end()); | 800 | GNUNET_MQ_handler_end()); |
799 | 801 | ||
800 | 802 | ||
801 | /* end of gnunet-gns-helper-service-w32.c */ | 803 | /* end of gnunet-gns-helper-service-w32.c */ |
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c index 5e3560313..82710b803 100644 --- a/src/gns/gnunet-gns-import.c +++ b/src/gns/gnunet-gns-import.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet-gns.c | 21 | * @file gnunet-gns.c |
22 | * @brief binary version of gnunet-gns-import.sh | 22 | * @brief binary version of gnunet-gns-import.sh |
@@ -86,13 +86,13 @@ static int ret; | |||
86 | 86 | ||
87 | 87 | ||
88 | static int | 88 | static int |
89 | run_process_and_wait (int pipe_control, | 89 | run_process_and_wait(int pipe_control, |
90 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 90 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
91 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 91 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
92 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 92 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
93 | enum GNUNET_OS_ProcessStatusType *st, | 93 | enum GNUNET_OS_ProcessStatusType *st, |
94 | unsigned long *code, | 94 | unsigned long *code, |
95 | const char *filename, ...) | 95 | const char *filename, ...) |
96 | { | 96 | { |
97 | static struct GNUNET_OS_Process *p; | 97 | static struct GNUNET_OS_Process *p; |
98 | int arglen; | 98 | int arglen; |
@@ -101,93 +101,96 @@ run_process_and_wait (int pipe_control, | |||
101 | char *argp; | 101 | char *argp; |
102 | va_list ap, apc1, apc2; | 102 | va_list ap, apc1, apc2; |
103 | 103 | ||
104 | va_start (ap, filename); | 104 | va_start(ap, filename); |
105 | va_copy (apc1, ap); | 105 | va_copy(apc1, ap); |
106 | va_copy (apc2, ap); | 106 | va_copy(apc2, ap); |
107 | arglen = 0; | 107 | arglen = 0; |
108 | while (NULL != (arg = va_arg (apc1, char *))) | 108 | while (NULL != (arg = va_arg(apc1, char *))) |
109 | arglen += strlen (arg) + 1; | 109 | arglen += strlen(arg) + 1; |
110 | va_end (apc1); | 110 | va_end(apc1); |
111 | args = argp = GNUNET_malloc (arglen); | 111 | args = argp = GNUNET_malloc(arglen); |
112 | while (NULL != (arg = va_arg (apc2, char *))) | 112 | while (NULL != (arg = va_arg(apc2, char *))) |
113 | { | 113 | { |
114 | strcpy (argp, arg); | 114 | strcpy(argp, arg); |
115 | argp += strlen (arg); | 115 | argp += strlen(arg); |
116 | *argp = ' '; | 116 | *argp = ' '; |
117 | argp += 1; | 117 | argp += 1; |
118 | } | 118 | } |
119 | va_end (apc2); | 119 | va_end(apc2); |
120 | if (arglen > 0) | 120 | if (arglen > 0) |
121 | argp[-1] = '\0'; | 121 | argp[-1] = '\0'; |
122 | p = GNUNET_OS_start_process_va (pipe_control, std_inheritance, | 122 | p = GNUNET_OS_start_process_va(pipe_control, std_inheritance, |
123 | pipe_stdin, | 123 | pipe_stdin, |
124 | pipe_stdout, | 124 | pipe_stdout, |
125 | NULL, | 125 | NULL, |
126 | filename, ap); | 126 | filename, ap); |
127 | va_end (ap); | 127 | va_end(ap); |
128 | if (NULL == p) | 128 | if (NULL == p) |
129 | { | 129 | { |
130 | ret = 3; | 130 | ret = 3; |
131 | fprintf (stderr, "Failed to run `%s'\n", args); | 131 | fprintf(stderr, "Failed to run `%s'\n", args); |
132 | GNUNET_free (args); | 132 | GNUNET_free(args); |
133 | return 1; | 133 | return 1; |
134 | } | 134 | } |
135 | 135 | ||
136 | if (GNUNET_OK != GNUNET_OS_process_wait (p)) | 136 | if (GNUNET_OK != GNUNET_OS_process_wait(p)) |
137 | { | 137 | { |
138 | ret = 4; | 138 | ret = 4; |
139 | fprintf (stderr, "Failed to wait for `%s'\n", args); | 139 | fprintf(stderr, "Failed to wait for `%s'\n", args); |
140 | GNUNET_free (args); | 140 | GNUNET_free(args); |
141 | return 1; | 141 | return 1; |
142 | } | 142 | } |
143 | 143 | ||
144 | switch (GNUNET_OS_process_status (p, st, code)) | 144 | switch (GNUNET_OS_process_status(p, st, code)) |
145 | { | 145 | { |
146 | case GNUNET_OK: | 146 | case GNUNET_OK: |
147 | break; | 147 | break; |
148 | |||
148 | case GNUNET_NO: | 149 | case GNUNET_NO: |
149 | ret = 5; | 150 | ret = 5; |
150 | fprintf (stderr, "`%s' is still running\n", args); | 151 | fprintf(stderr, "`%s' is still running\n", args); |
151 | GNUNET_free (args); | 152 | GNUNET_free(args); |
152 | return 1; | 153 | return 1; |
154 | |||
153 | default: | 155 | default: |
154 | case GNUNET_SYSERR: | 156 | case GNUNET_SYSERR: |
155 | ret = 6; | 157 | ret = 6; |
156 | fprintf (stderr, "Failed to check the status of `%s'\n", args); | 158 | fprintf(stderr, "Failed to check the status of `%s'\n", args); |
157 | GNUNET_free (args); | 159 | GNUNET_free(args); |
158 | return 1; | 160 | return 1; |
159 | } | 161 | } |
160 | #ifdef WINDOWS | 162 | #ifdef WINDOWS |
161 | if (GNUNET_OS_PROCESS_EXITED != *st || 0 != *code) | 163 | if (GNUNET_OS_PROCESS_EXITED != *st || 0 != *code) |
162 | { | 164 | { |
163 | ret = 7; | 165 | ret = 7; |
164 | fprintf (stderr, "`%s' did not end correctly (%d, %d)\n", args, *st, *code); | 166 | fprintf(stderr, "`%s' did not end correctly (%d, %d)\n", args, *st, *code); |
165 | return 1; | 167 | return 1; |
166 | } | 168 | } |
167 | #endif | 169 | #endif |
168 | return 0; | 170 | return 0; |
169 | } | 171 | } |
170 | 172 | ||
171 | static void | 173 | static void |
172 | check_pkey (unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, | 174 | check_pkey(unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, |
173 | char *pk, int *found_rec) | 175 | char *pk, int *found_rec) |
174 | { | 176 | { |
175 | int i; | 177 | int i; |
178 | |||
176 | for (i = 0; i < rd_len; i++) | 179 | for (i = 0; i < rd_len; i++) |
177 | { | 180 | { |
178 | char *s; | 181 | char *s; |
179 | if (GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type || | 182 | if (GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type || |
180 | rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) | 183 | rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) |
181 | continue; | 184 | continue; |
182 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | 185 | s = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, |
183 | rd[i].data, | 186 | rd[i].data, |
184 | rd[i].data_size); | 187 | rd[i].data_size); |
185 | if (NULL == s) | 188 | if (NULL == s) |
186 | continue; | 189 | continue; |
187 | if (0 == strcmp (s, pk)) | 190 | if (0 == strcmp(s, pk)) |
188 | *found_rec = GNUNET_YES; | 191 | *found_rec = GNUNET_YES; |
189 | GNUNET_free (s); | 192 | GNUNET_free(s); |
190 | } | 193 | } |
191 | } | 194 | } |
192 | 195 | ||
193 | /** | 196 | /** |
@@ -200,53 +203,54 @@ check_pkey (unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, | |||
200 | * @param rd array of records with data to store | 203 | * @param rd array of records with data to store |
201 | */ | 204 | */ |
202 | static void | 205 | static void |
203 | zone_iterator (void *cls, | 206 | zone_iterator(void *cls, |
204 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 207 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
205 | const char *rname, unsigned int rd_len, | 208 | const char *rname, unsigned int rd_len, |
206 | const struct GNUNET_GNSRECORD_Data *rd) | 209 | const struct GNUNET_GNSRECORD_Data *rd) |
207 | { | 210 | { |
208 | if (NULL != rname) | 211 | if (NULL != rname) |
209 | { | 212 | { |
210 | if (0 == strcmp (rname, "private")) | 213 | if (0 == strcmp(rname, "private")) |
211 | check_pkey (rd_len, rd, private_zone_pkey, &found_private_rec); | 214 | check_pkey(rd_len, rd, private_zone_pkey, &found_private_rec); |
212 | else if (0 == strcmp (rname, "pin")) | 215 | else if (0 == strcmp(rname, "pin")) |
213 | check_pkey (rd_len, rd, pin_zone_pkey, &found_pin_rec); | 216 | check_pkey(rd_len, rd, pin_zone_pkey, &found_pin_rec); |
214 | } | 217 | } |
215 | GNUNET_NAMESTORE_zone_iterator_next (list_it); | 218 | GNUNET_NAMESTORE_zone_iterator_next(list_it); |
216 | } | 219 | } |
217 | 220 | ||
218 | static void | 221 | static void |
219 | zone_iteration_error (void *cls) | 222 | zone_iteration_error(void *cls) |
220 | { | 223 | { |
221 | enum GNUNET_OS_ProcessStatusType st; | 224 | enum GNUNET_OS_ProcessStatusType st; |
222 | unsigned long code; | 225 | unsigned long code; |
226 | |||
223 | if (!found_private_rec) | 227 | if (!found_private_rec) |
224 | { | ||
225 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | ||
226 | "gnunet-namestore", | ||
227 | "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "private", "-p", "-t", "PKEY", "-V", private_zone_pkey, NULL)) | ||
228 | { | 228 | { |
229 | ret = 8; | 229 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
230 | return; | 230 | "gnunet-namestore", |
231 | "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "private", "-p", "-t", "PKEY", "-V", private_zone_pkey, NULL)) | ||
232 | { | ||
233 | ret = 8; | ||
234 | return; | ||
235 | } | ||
231 | } | 236 | } |
232 | } | ||
233 | if (!found_pin_rec) | 237 | if (!found_pin_rec) |
234 | { | ||
235 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | ||
236 | "gnunet-namestore", | ||
237 | "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "pin", "-p", "-t", "PKEY", "-V", pin_zone_pkey, NULL)) | ||
238 | { | 238 | { |
239 | ret = 10; | 239 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
240 | return; | 240 | "gnunet-namestore", |
241 | "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "pin", "-p", "-t", "PKEY", "-V", pin_zone_pkey, NULL)) | ||
242 | { | ||
243 | ret = 10; | ||
244 | return; | ||
245 | } | ||
241 | } | 246 | } |
242 | } | ||
243 | list_it = NULL; | 247 | list_it = NULL; |
244 | GNUNET_SCHEDULER_shutdown (); | 248 | GNUNET_SCHEDULER_shutdown(); |
245 | } | 249 | } |
246 | 250 | ||
247 | 251 | ||
248 | static void | 252 | static void |
249 | zone_iteration_finished (void *cls) | 253 | zone_iteration_finished(void *cls) |
250 | { | 254 | { |
251 | } | 255 | } |
252 | 256 | ||
@@ -283,43 +287,44 @@ zone_iteration_finished (void *cls) | |||
283 | * @param identifier identifier assigned by the user for this ego, | 287 | * @param identifier identifier assigned by the user for this ego, |
284 | * NULL if the user just deleted the ego and it | 288 | * NULL if the user just deleted the ego and it |
285 | * must thus no longer be used | 289 | * must thus no longer be used |
286 | */ | 290 | */ |
287 | static void | 291 | static void |
288 | get_ego (void *cls, | 292 | get_ego(void *cls, |
289 | struct GNUNET_IDENTITY_Ego *ego, | 293 | struct GNUNET_IDENTITY_Ego *ego, |
290 | void **ctx, | 294 | void **ctx, |
291 | const char *identifier) | 295 | const char *identifier) |
292 | { | 296 | { |
293 | static struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 297 | static struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
298 | |||
294 | if (NULL == ego) | 299 | if (NULL == ego) |
295 | { | ||
296 | if (NULL == master_zone_pkey || | ||
297 | NULL == private_zone_pkey) | ||
298 | { | 300 | { |
299 | ret = 11; | 301 | if (NULL == master_zone_pkey || |
300 | GNUNET_SCHEDULER_shutdown (); | 302 | NULL == private_zone_pkey) |
303 | { | ||
304 | ret = 11; | ||
305 | GNUNET_SCHEDULER_shutdown(); | ||
306 | return; | ||
307 | } | ||
308 | list_it = GNUNET_NAMESTORE_zone_iteration_start(ns, | ||
309 | &master_pk, &zone_iteration_error, NULL, &zone_iterator, NULL, &zone_iteration_finished, NULL); | ||
310 | if (NULL == list_it) | ||
311 | { | ||
312 | ret = 12; | ||
313 | GNUNET_SCHEDULER_shutdown(); | ||
314 | } | ||
301 | return; | 315 | return; |
302 | } | 316 | } |
303 | list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 317 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); |
304 | &master_pk, &zone_iteration_error, NULL, &zone_iterator, NULL, &zone_iteration_finished, NULL); | ||
305 | if (NULL == list_it) | ||
306 | { | ||
307 | ret = 12; | ||
308 | GNUNET_SCHEDULER_shutdown (); | ||
309 | } | ||
310 | return; | ||
311 | } | ||
312 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
313 | if (NULL != identifier) | 318 | if (NULL != identifier) |
314 | { | ||
315 | if (NULL == master_zone_pkey && 0 == strcmp ("master-zone", identifier)) | ||
316 | { | 319 | { |
317 | master_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 320 | if (NULL == master_zone_pkey && 0 == strcmp("master-zone", identifier)) |
318 | master_pk = *GNUNET_IDENTITY_ego_get_private_key (ego); | 321 | { |
322 | master_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); | ||
323 | master_pk = *GNUNET_IDENTITY_ego_get_private_key(ego); | ||
324 | } | ||
325 | else if (NULL == private_zone_pkey && 0 == strcmp("private-zone", identifier)) | ||
326 | private_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); | ||
319 | } | 327 | } |
320 | else if (NULL == private_zone_pkey && 0 == strcmp ("private-zone", identifier)) | ||
321 | private_zone_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
322 | } | ||
323 | } | 328 | } |
324 | 329 | ||
325 | /** | 330 | /** |
@@ -328,27 +333,27 @@ get_ego (void *cls, | |||
328 | * @param cls NULL | 333 | * @param cls NULL |
329 | */ | 334 | */ |
330 | static void | 335 | static void |
331 | shutdown_task (void *cls) | 336 | shutdown_task(void *cls) |
332 | { | 337 | { |
333 | GNUNET_free_non_null (master_zone_pkey); | 338 | GNUNET_free_non_null(master_zone_pkey); |
334 | master_zone_pkey = NULL; | 339 | master_zone_pkey = NULL; |
335 | GNUNET_free_non_null (private_zone_pkey); | 340 | GNUNET_free_non_null(private_zone_pkey); |
336 | private_zone_pkey = NULL; | 341 | private_zone_pkey = NULL; |
337 | if (NULL != list_it) | 342 | if (NULL != list_it) |
338 | { | 343 | { |
339 | GNUNET_NAMESTORE_zone_iteration_stop (list_it); | 344 | GNUNET_NAMESTORE_zone_iteration_stop(list_it); |
340 | list_it = NULL; | 345 | list_it = NULL; |
341 | } | 346 | } |
342 | if (NULL != ns) | 347 | if (NULL != ns) |
343 | { | 348 | { |
344 | GNUNET_NAMESTORE_disconnect (ns); | 349 | GNUNET_NAMESTORE_disconnect(ns); |
345 | ns = NULL; | 350 | ns = NULL; |
346 | } | 351 | } |
347 | if (NULL != sh) | 352 | if (NULL != sh) |
348 | { | 353 | { |
349 | GNUNET_IDENTITY_disconnect (sh); | 354 | GNUNET_IDENTITY_disconnect(sh); |
350 | sh = NULL; | 355 | sh = NULL; |
351 | } | 356 | } |
352 | } | 357 | } |
353 | 358 | ||
354 | /** | 359 | /** |
@@ -360,71 +365,71 @@ shutdown_task (void *cls) | |||
360 | * @param c configuration | 365 | * @param c configuration |
361 | */ | 366 | */ |
362 | static void | 367 | static void |
363 | run (void *cls, char *const *args, const char *cfgfile, | 368 | run(void *cls, char *const *args, const char *cfgfile, |
364 | const struct GNUNET_CONFIGURATION_Handle *c) | 369 | const struct GNUNET_CONFIGURATION_Handle *c) |
365 | { | 370 | { |
366 | enum GNUNET_OS_ProcessStatusType st; | 371 | enum GNUNET_OS_ProcessStatusType st; |
367 | unsigned long code; | 372 | unsigned long code; |
368 | 373 | ||
369 | cfg = c; | 374 | cfg = c; |
370 | 375 | ||
371 | if (0 != run_process_and_wait (GNUNET_NO, 0, NULL, NULL, &st, &code, | 376 | if (0 != run_process_and_wait(GNUNET_NO, 0, NULL, NULL, &st, &code, |
372 | "gnunet-arm", | 377 | "gnunet-arm", |
373 | "gnunet-arm", "-I", NULL)) | 378 | "gnunet-arm", "-I", NULL)) |
374 | { | 379 | { |
375 | if (7 == ret) | 380 | if (7 == ret) |
376 | fprintf (stderr, "GNUnet is not running, please start GNUnet before running import\n"); | 381 | fprintf(stderr, "GNUnet is not running, please start GNUnet before running import\n"); |
377 | return; | 382 | return; |
378 | } | 383 | } |
379 | 384 | ||
380 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 385 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
381 | "gnunet-identity", | 386 | "gnunet-identity", |
382 | "gnunet-identity", "-C", "master-zone", NULL)) | 387 | "gnunet-identity", "-C", "master-zone", NULL)) |
383 | return; | 388 | return; |
384 | 389 | ||
385 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 390 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
386 | "gnunet-identity", | 391 | "gnunet-identity", |
387 | "gnunet-identity", "-C", "private-zone", NULL)) | 392 | "gnunet-identity", "-C", "private-zone", NULL)) |
388 | return; | 393 | return; |
389 | 394 | ||
390 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 395 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
391 | "gnunet-identity", | 396 | "gnunet-identity", |
392 | "gnunet-identity", "-C", "sks-zone", NULL)) | 397 | "gnunet-identity", "-C", "sks-zone", NULL)) |
393 | return; | 398 | return; |
394 | 399 | ||
395 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 400 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
396 | "gnunet-identity", | 401 | "gnunet-identity", |
397 | "gnunet-identity", "-e", "master-zone", "-s", "gns-master", NULL)) | 402 | "gnunet-identity", "-e", "master-zone", "-s", "gns-master", NULL)) |
398 | return; | 403 | return; |
399 | 404 | ||
400 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 405 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
401 | "gnunet-identity", | 406 | "gnunet-identity", |
402 | "gnunet-identity", "-e", "master-zone", "-s", "namestore", NULL)) | 407 | "gnunet-identity", "-e", "master-zone", "-s", "namestore", NULL)) |
403 | return; | 408 | return; |
404 | 409 | ||
405 | 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, NULL, NULL, &st, &code, |
406 | "gnunet-identity", | 411 | "gnunet-identity", |
407 | "gnunet-identity", "-e", "master-zone", "-s", "gns-proxy", NULL)) | 412 | "gnunet-identity", "-e", "master-zone", "-s", "gns-proxy", NULL)) |
408 | return; | 413 | return; |
409 | 414 | ||
410 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 415 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
411 | "gnunet-identity", | 416 | "gnunet-identity", |
412 | "gnunet-identity", "-e", "master-zone", "-s", "gns-intercept", NULL)) | 417 | "gnunet-identity", "-e", "master-zone", "-s", "gns-intercept", NULL)) |
413 | return; | 418 | return; |
414 | 419 | ||
415 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 420 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
416 | "gnunet-identity", | 421 | "gnunet-identity", |
417 | "gnunet-identity", "-e", "private-zone", "-s", "gns-private", NULL)) | 422 | "gnunet-identity", "-e", "private-zone", "-s", "gns-private", NULL)) |
418 | return; | 423 | return; |
419 | 424 | ||
420 | if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, | 425 | if (0 != run_process_and_wait(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, |
421 | "gnunet-identity", | 426 | "gnunet-identity", |
422 | "gnunet-identity", "-e", "sks-zone", "-s", "fs-sks", NULL)) | 427 | "gnunet-identity", "-e", "sks-zone", "-s", "fs-sks", NULL)) |
423 | return; | 428 | return; |
424 | 429 | ||
425 | ns = GNUNET_NAMESTORE_connect (cfg); | 430 | ns = GNUNET_NAMESTORE_connect(cfg); |
426 | sh = GNUNET_IDENTITY_connect (cfg, &get_ego, NULL); | 431 | sh = GNUNET_IDENTITY_connect(cfg, &get_ego, NULL); |
427 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 432 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
428 | } | 433 | } |
429 | 434 | ||
430 | 435 | ||
@@ -436,23 +441,23 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
436 | * @return 0 ok, 1 on error | 441 | * @return 0 ok, 1 on error |
437 | */ | 442 | */ |
438 | int | 443 | int |
439 | main (int argc, char *const *argv) | 444 | main(int argc, char *const *argv) |
440 | { | 445 | { |
441 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 446 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
442 | GNUNET_GETOPT_OPTION_END | 447 | GNUNET_GETOPT_OPTION_END |
443 | }; | 448 | }; |
444 | int r; | 449 | int r; |
445 | 450 | ||
446 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 451 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
447 | return 2; | 452 | return 2; |
448 | 453 | ||
449 | GNUNET_log_setup ("gnunet-gns-import", "WARNING", NULL); | 454 | GNUNET_log_setup("gnunet-gns-import", "WARNING", NULL); |
450 | ret = 0; | 455 | ret = 0; |
451 | r = GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-import", | 456 | r = GNUNET_PROGRAM_run(argc, argv, "gnunet-gns-import", |
452 | _("This program will import some GNS authorities into your GNS namestore."), | 457 | _("This program will import some GNS authorities into your GNS namestore."), |
453 | options, | 458 | options, |
454 | &run, NULL); | 459 | &run, NULL); |
455 | GNUNET_free ((void*) argv); | 460 | GNUNET_free((void*)argv); |
456 | return GNUNET_OK == r ? ret : 1; | 461 | return GNUNET_OK == r ? ret : 1; |
457 | } | 462 | } |
458 | 463 | ||
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index eb8115026..6285a8fcd 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -94,13 +94,13 @@ | |||
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(GNUNET_TIME_UNIT_MINUTES, 5) |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * After how long do we clean up Socks5 handles that failed to show any activity | 100 | * After how long do we clean up Socks5 handles that failed to show any activity |
101 | * with their respective MHD instance? | 101 | * with their respective MHD instance? |
102 | */ | 102 | */ |
103 | #define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 103 | #define HTTP_HANDSHAKE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
104 | 104 | ||
105 | 105 | ||
106 | /** | 106 | /** |
@@ -110,13 +110,13 @@ | |||
110 | * @param fun name of curl_easy-function that gave the error | 110 | * @param fun name of curl_easy-function that gave the error |
111 | * @param rc return code from curl | 111 | * @param rc return code from curl |
112 | */ | 112 | */ |
113 | #define LOG_CURL_EASY(level,fun,rc) \ | 113 | #define LOG_CURL_EASY(level, fun, rc) \ |
114 | GNUNET_log (level, \ | 114 | GNUNET_log(level, \ |
115 | _("%s failed at %s:%d: `%s'\n"), \ | 115 | _("%s failed at %s:%d: `%s'\n"), \ |
116 | fun, \ | 116 | fun, \ |
117 | __FILE__, \ | 117 | __FILE__, \ |
118 | __LINE__, \ | 118 | __LINE__, \ |
119 | curl_easy_strerror (rc)) | 119 | curl_easy_strerror(rc)) |
120 | 120 | ||
121 | 121 | ||
122 | /* *************** Socks protocol definitions (move to TUN?) ****************** */ | 122 | /* *************** Socks protocol definitions (move to TUN?) ****************** */ |
@@ -135,8 +135,7 @@ | |||
135 | /** | 135 | /** |
136 | * Commands in Socks5. | 136 | * Commands in Socks5. |
137 | */ | 137 | */ |
138 | enum Socks5Commands | 138 | enum Socks5Commands { |
139 | { | ||
140 | /** | 139 | /** |
141 | * Establish TCP/IP stream. | 140 | * Establish TCP/IP stream. |
142 | */ | 141 | */ |
@@ -157,8 +156,7 @@ enum Socks5Commands | |||
157 | /** | 156 | /** |
158 | * Address types in Socks5. | 157 | * Address types in Socks5. |
159 | */ | 158 | */ |
160 | enum Socks5AddressType | 159 | enum Socks5AddressType { |
161 | { | ||
162 | /** | 160 | /** |
163 | * IPv4 address. | 161 | * IPv4 address. |
164 | */ | 162 | */ |
@@ -173,15 +171,13 @@ enum Socks5AddressType | |||
173 | * IPv6 address. | 171 | * IPv6 address. |
174 | */ | 172 | */ |
175 | SOCKS5_AT_IPV6 = 4 | 173 | SOCKS5_AT_IPV6 = 4 |
176 | |||
177 | }; | 174 | }; |
178 | 175 | ||
179 | 176 | ||
180 | /** | 177 | /** |
181 | * Status codes in Socks5 response. | 178 | * Status codes in Socks5 response. |
182 | */ | 179 | */ |
183 | enum Socks5StatusCode | 180 | enum Socks5StatusCode { |
184 | { | ||
185 | SOCKS5_STATUS_REQUEST_GRANTED = 0, | 181 | SOCKS5_STATUS_REQUEST_GRANTED = 0, |
186 | SOCKS5_STATUS_GENERAL_FAILURE = 1, | 182 | SOCKS5_STATUS_GENERAL_FAILURE = 1, |
187 | SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE = 2, | 183 | SOCKS5_STATUS_CONNECTION_NOT_ALLOWED_BY_RULE = 2, |
@@ -197,8 +193,7 @@ enum Socks5StatusCode | |||
197 | /** | 193 | /** |
198 | * Client hello in Socks5 protocol. | 194 | * Client hello in Socks5 protocol. |
199 | */ | 195 | */ |
200 | struct Socks5ClientHelloMessage | 196 | struct Socks5ClientHelloMessage { |
201 | { | ||
202 | /** | 197 | /** |
203 | * Should be #SOCKS_VERSION_5. | 198 | * Should be #SOCKS_VERSION_5. |
204 | */ | 199 | */ |
@@ -210,15 +205,13 @@ struct Socks5ClientHelloMessage | |||
210 | uint8_t num_auth_methods; | 205 | uint8_t num_auth_methods; |
211 | 206 | ||
212 | /* followed by supported authentication methods, 1 byte per method */ | 207 | /* followed by supported authentication methods, 1 byte per method */ |
213 | |||
214 | }; | 208 | }; |
215 | 209 | ||
216 | 210 | ||
217 | /** | 211 | /** |
218 | * Server hello in Socks5 protocol. | 212 | * Server hello in Socks5 protocol. |
219 | */ | 213 | */ |
220 | struct Socks5ServerHelloMessage | 214 | struct Socks5ServerHelloMessage { |
221 | { | ||
222 | /** | 215 | /** |
223 | * Should be #SOCKS_VERSION_5. | 216 | * Should be #SOCKS_VERSION_5. |
224 | */ | 217 | */ |
@@ -235,8 +228,7 @@ struct Socks5ServerHelloMessage | |||
235 | /** | 228 | /** |
236 | * Client socks request in Socks5 protocol. | 229 | * Client socks request in Socks5 protocol. |
237 | */ | 230 | */ |
238 | struct Socks5ClientRequestMessage | 231 | struct Socks5ClientRequestMessage { |
239 | { | ||
240 | /** | 232 | /** |
241 | * Should be #SOCKS_VERSION_5. | 233 | * Should be #SOCKS_VERSION_5. |
242 | */ | 234 | */ |
@@ -268,8 +260,7 @@ struct Socks5ClientRequestMessage | |||
268 | /** | 260 | /** |
269 | * Server response to client requests in Socks5 protocol. | 261 | * Server response to client requests in Socks5 protocol. |
270 | */ | 262 | */ |
271 | struct Socks5ServerResponseMessage | 263 | struct Socks5ServerResponseMessage { |
272 | { | ||
273 | /** | 264 | /** |
274 | * Should be #SOCKS_VERSION_5. | 265 | * Should be #SOCKS_VERSION_5. |
275 | */ | 266 | */ |
@@ -295,7 +286,6 @@ struct Socks5ServerResponseMessage | |||
295 | * length field (uint8_t) in front (depending on @e addr_type). | 286 | * length field (uint8_t) in front (depending on @e addr_type). |
296 | * followed by port number in network byte order (uint16_t). | 287 | * followed by port number in network byte order (uint16_t). |
297 | */ | 288 | */ |
298 | |||
299 | }; | 289 | }; |
300 | 290 | ||
301 | 291 | ||
@@ -305,8 +295,7 @@ struct Socks5ServerResponseMessage | |||
305 | /** | 295 | /** |
306 | * A structure for CA cert/key | 296 | * A structure for CA cert/key |
307 | */ | 297 | */ |
308 | struct ProxyCA | 298 | struct ProxyCA { |
309 | { | ||
310 | /** | 299 | /** |
311 | * The certificate | 300 | * The certificate |
312 | */ | 301 | */ |
@@ -322,8 +311,7 @@ struct ProxyCA | |||
322 | /** | 311 | /** |
323 | * Structure for GNS certificates | 312 | * Structure for GNS certificates |
324 | */ | 313 | */ |
325 | struct ProxyGNSCertificate | 314 | struct ProxyGNSCertificate { |
326 | { | ||
327 | /** | 315 | /** |
328 | * The certificate as PEM | 316 | * The certificate as PEM |
329 | */ | 317 | */ |
@@ -340,8 +328,7 @@ struct ProxyGNSCertificate | |||
340 | /** | 328 | /** |
341 | * A structure for all running Httpds | 329 | * A structure for all running Httpds |
342 | */ | 330 | */ |
343 | struct MhdHttpList | 331 | struct MhdHttpList { |
344 | { | ||
345 | /** | 332 | /** |
346 | * DLL for httpds | 333 | * DLL for httpds |
347 | */ | 334 | */ |
@@ -376,7 +363,6 @@ struct MhdHttpList | |||
376 | * is this an ssl daemon? | 363 | * is this an ssl daemon? |
377 | */ | 364 | */ |
378 | int is_ssl; | 365 | int is_ssl; |
379 | |||
380 | }; | 366 | }; |
381 | 367 | ||
382 | 368 | ||
@@ -386,8 +372,7 @@ struct MhdHttpList | |||
386 | /** | 372 | /** |
387 | * The socks phases. | 373 | * The socks phases. |
388 | */ | 374 | */ |
389 | enum SocksPhase | 375 | enum SocksPhase { |
390 | { | ||
391 | /** | 376 | /** |
392 | * We're waiting to get the client hello. | 377 | * We're waiting to get the client hello. |
393 | */ | 378 | */ |
@@ -443,8 +428,7 @@ enum SocksPhase | |||
443 | /** | 428 | /** |
444 | * A header list | 429 | * A header list |
445 | */ | 430 | */ |
446 | struct HttpResponseHeader | 431 | struct HttpResponseHeader { |
447 | { | ||
448 | /** | 432 | /** |
449 | * DLL | 433 | * DLL |
450 | */ | 434 | */ |
@@ -469,9 +453,7 @@ struct HttpResponseHeader | |||
469 | /** | 453 | /** |
470 | * A structure for socks requests | 454 | * A structure for socks requests |
471 | */ | 455 | */ |
472 | struct Socks5Request | 456 | struct Socks5Request { |
473 | { | ||
474 | |||
475 | /** | 457 | /** |
476 | * DLL. | 458 | * DLL. |
477 | */ | 459 | */ |
@@ -769,7 +751,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
769 | * @param hd the daemon to run now. | 751 | * @param hd the daemon to run now. |
770 | */ | 752 | */ |
771 | static void | 753 | static void |
772 | run_mhd_now (struct MhdHttpList *hd); | 754 | run_mhd_now(struct MhdHttpList *hd); |
773 | 755 | ||
774 | 756 | ||
775 | /** | 757 | /** |
@@ -778,79 +760,79 @@ run_mhd_now (struct MhdHttpList *hd); | |||
778 | * @param s5r the handle to destroy | 760 | * @param s5r the handle to destroy |
779 | */ | 761 | */ |
780 | static void | 762 | static void |
781 | cleanup_s5r (struct Socks5Request *s5r) | 763 | cleanup_s5r(struct Socks5Request *s5r) |
782 | { | 764 | { |
783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 765 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
784 | "Cleaning up socks request\n"); | 766 | "Cleaning up socks request\n"); |
785 | if (NULL != s5r->curl) | 767 | if (NULL != s5r->curl) |
786 | { | 768 | { |
787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 769 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
788 | "Cleaning up cURL handle\n"); | 770 | "Cleaning up cURL handle\n"); |
789 | curl_multi_remove_handle (curl_multi, | 771 | curl_multi_remove_handle(curl_multi, |
790 | s5r->curl); | 772 | s5r->curl); |
791 | curl_easy_cleanup (s5r->curl); | 773 | curl_easy_cleanup(s5r->curl); |
792 | s5r->curl = NULL; | 774 | s5r->curl = NULL; |
793 | } | 775 | } |
794 | if (s5r->suspended) | 776 | if (s5r->suspended) |
795 | { | 777 | { |
796 | s5r->suspended = GNUNET_NO; | 778 | s5r->suspended = GNUNET_NO; |
797 | MHD_resume_connection (s5r->con); | 779 | MHD_resume_connection(s5r->con); |
798 | } | 780 | } |
799 | curl_slist_free_all (s5r->headers); | 781 | curl_slist_free_all(s5r->headers); |
800 | if (NULL != s5r->hosts) | 782 | if (NULL != s5r->hosts) |
801 | { | 783 | { |
802 | curl_slist_free_all (s5r->hosts); | 784 | curl_slist_free_all(s5r->hosts); |
803 | } | 785 | } |
804 | if ( (NULL != s5r->response) && | 786 | if ((NULL != s5r->response) && |
805 | (curl_failure_response != s5r->response) ) | 787 | (curl_failure_response != s5r->response)) |
806 | { | 788 | { |
807 | MHD_destroy_response (s5r->response); | 789 | MHD_destroy_response(s5r->response); |
808 | s5r->response = NULL; | 790 | s5r->response = NULL; |
809 | } | 791 | } |
810 | if (NULL != s5r->rtask) | 792 | if (NULL != s5r->rtask) |
811 | { | 793 | { |
812 | GNUNET_SCHEDULER_cancel (s5r->rtask); | 794 | GNUNET_SCHEDULER_cancel(s5r->rtask); |
813 | s5r->rtask = NULL; | 795 | s5r->rtask = NULL; |
814 | } | 796 | } |
815 | if (NULL != s5r->timeout_task) | 797 | if (NULL != s5r->timeout_task) |
816 | { | 798 | { |
817 | GNUNET_SCHEDULER_cancel (s5r->timeout_task); | 799 | GNUNET_SCHEDULER_cancel(s5r->timeout_task); |
818 | s5r->timeout_task = NULL; | 800 | s5r->timeout_task = NULL; |
819 | } | 801 | } |
820 | if (NULL != s5r->wtask) | 802 | if (NULL != s5r->wtask) |
821 | { | 803 | { |
822 | GNUNET_SCHEDULER_cancel (s5r->wtask); | 804 | GNUNET_SCHEDULER_cancel(s5r->wtask); |
823 | s5r->wtask = NULL; | 805 | s5r->wtask = NULL; |
824 | } | 806 | } |
825 | if (NULL != s5r->gns_lookup) | 807 | if (NULL != s5r->gns_lookup) |
826 | { | 808 | { |
827 | GNUNET_GNS_lookup_with_tld_cancel (s5r->gns_lookup); | 809 | GNUNET_GNS_lookup_with_tld_cancel(s5r->gns_lookup); |
828 | s5r->gns_lookup = NULL; | 810 | s5r->gns_lookup = NULL; |
829 | } | 811 | } |
830 | if (NULL != s5r->sock) | 812 | if (NULL != s5r->sock) |
831 | { | 813 | { |
832 | if (SOCKS5_SOCKET_WITH_MHD <= s5r->state) | 814 | if (SOCKS5_SOCKET_WITH_MHD <= s5r->state) |
833 | GNUNET_NETWORK_socket_free_memory_only_ (s5r->sock); | 815 | GNUNET_NETWORK_socket_free_memory_only_(s5r->sock); |
834 | else | 816 | else |
835 | GNUNET_NETWORK_socket_close (s5r->sock); | 817 | GNUNET_NETWORK_socket_close(s5r->sock); |
836 | s5r->sock = NULL; | 818 | s5r->sock = NULL; |
837 | } | 819 | } |
838 | GNUNET_CONTAINER_DLL_remove (s5r_head, | 820 | GNUNET_CONTAINER_DLL_remove(s5r_head, |
839 | s5r_tail, | 821 | s5r_tail, |
840 | s5r); | 822 | s5r); |
841 | GNUNET_free_non_null (s5r->domain); | 823 | GNUNET_free_non_null(s5r->domain); |
842 | GNUNET_free_non_null (s5r->leho); | 824 | GNUNET_free_non_null(s5r->leho); |
843 | GNUNET_free_non_null (s5r->url); | 825 | GNUNET_free_non_null(s5r->url); |
844 | for (unsigned int i=0;i<s5r->num_danes;i++) | 826 | for (unsigned int i = 0; i < s5r->num_danes; i++) |
845 | GNUNET_free (s5r->dane_data[i]); | 827 | GNUNET_free(s5r->dane_data[i]); |
846 | GNUNET_free (s5r); | 828 | GNUNET_free(s5r); |
847 | } | 829 | } |
848 | 830 | ||
849 | 831 | ||
850 | /* ************************* HTTP handling with cURL *********************** */ | 832 | /* ************************* HTTP handling with cURL *********************** */ |
851 | 833 | ||
852 | static void | 834 | static void |
853 | curl_download_prepare (); | 835 | curl_download_prepare(); |
854 | 836 | ||
855 | 837 | ||
856 | /** | 838 | /** |
@@ -865,89 +847,89 @@ curl_download_prepare (); | |||
865 | * @return number of bytes written to @a buf | 847 | * @return number of bytes written to @a buf |
866 | */ | 848 | */ |
867 | static ssize_t | 849 | static ssize_t |
868 | mhd_content_cb (void *cls, | 850 | mhd_content_cb(void *cls, |
869 | uint64_t pos, | 851 | uint64_t pos, |
870 | char* buf, | 852 | char* buf, |
871 | size_t max) | 853 | size_t max) |
872 | { | 854 | { |
873 | struct Socks5Request *s5r = cls; | 855 | struct Socks5Request *s5r = cls; |
874 | size_t bytes_to_copy; | 856 | size_t bytes_to_copy; |
875 | 857 | ||
876 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || | 858 | if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || |
877 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | 859 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) |
878 | { | 860 | { |
879 | /* we're still not done with the upload, do not yet | 861 | /* we're still not done with the upload, do not yet |
880 | start the download, the IO buffer is still full | 862 | start the download, the IO buffer is still full |
881 | with upload data. */ | 863 | with upload data. */ |
882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 864 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
883 | "Pausing MHD download %s%s, not yet ready for download\n", | 865 | "Pausing MHD download %s%s, not yet ready for download\n", |
884 | s5r->domain, | 866 | s5r->domain, |
885 | s5r->url); | 867 | s5r->url); |
886 | return 0; /* not yet ready for data download */ | 868 | return 0; /* not yet ready for data download */ |
887 | } | ||
888 | bytes_to_copy = GNUNET_MIN (max, | ||
889 | s5r->io_len); | ||
890 | if ( (0 == bytes_to_copy) && | ||
891 | (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) ) | ||
892 | { | ||
893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
894 | "Pausing MHD download %s%s, no data available\n", | ||
895 | s5r->domain, | ||
896 | s5r->url); | ||
897 | if (NULL != s5r->curl) | ||
898 | { | ||
899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
900 | "Continuing CURL interaction for %s%s\n", | ||
901 | s5r->domain, | ||
902 | s5r->url); | ||
903 | if (GNUNET_YES == s5r->curl_paused) | ||
904 | { | ||
905 | s5r->curl_paused = GNUNET_NO; | ||
906 | curl_easy_pause (s5r->curl, | ||
907 | CURLPAUSE_CONT); | ||
908 | } | ||
909 | curl_download_prepare (); | ||
910 | } | 869 | } |
911 | if (GNUNET_NO == s5r->suspended) | 870 | bytes_to_copy = GNUNET_MIN(max, |
871 | s5r->io_len); | ||
872 | if ((0 == bytes_to_copy) && | ||
873 | (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state)) | ||
912 | { | 874 | { |
913 | MHD_suspend_connection (s5r->con); | 875 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
914 | s5r->suspended = GNUNET_YES; | 876 | "Pausing MHD download %s%s, no data available\n", |
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 */ | ||
915 | } | 899 | } |
916 | return 0; /* more data later */ | 900 | if ((0 == bytes_to_copy) && |
917 | } | 901 | (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state)) |
918 | if ( (0 == bytes_to_copy) && | 902 | { |
919 | (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) ) | 903 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
920 | { | 904 | "Completed MHD download %s%s\n", |
921 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 905 | s5r->domain, |
922 | "Completed MHD download %s%s\n", | 906 | s5r->url); |
923 | s5r->domain, | 907 | return MHD_CONTENT_READER_END_OF_STREAM; |
924 | s5r->url); | 908 | } |
925 | return MHD_CONTENT_READER_END_OF_STREAM; | 909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
926 | } | 910 | "Writing %llu/%llu bytes to %s%s\n", |
927 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 911 | (unsigned long long)bytes_to_copy, |
928 | "Writing %llu/%llu bytes to %s%s\n", | 912 | (unsigned long long)s5r->io_len, |
929 | (unsigned long long) bytes_to_copy, | 913 | s5r->domain, |
930 | (unsigned long long) s5r->io_len, | 914 | s5r->url); |
931 | s5r->domain, | 915 | GNUNET_memcpy(buf, |
932 | s5r->url); | 916 | s5r->io_buf, |
933 | GNUNET_memcpy (buf, | 917 | bytes_to_copy); |
934 | s5r->io_buf, | 918 | memmove(s5r->io_buf, |
935 | bytes_to_copy); | 919 | &s5r->io_buf[bytes_to_copy], |
936 | memmove (s5r->io_buf, | 920 | s5r->io_len - bytes_to_copy); |
937 | &s5r->io_buf[bytes_to_copy], | ||
938 | s5r->io_len - bytes_to_copy); | ||
939 | s5r->io_len -= bytes_to_copy; | 921 | s5r->io_len -= bytes_to_copy; |
940 | if ( (NULL != s5r->curl) && | 922 | if ((NULL != s5r->curl) && |
941 | (GNUNET_YES == s5r->curl_paused) ) | 923 | (GNUNET_YES == s5r->curl_paused)) |
942 | { | 924 | { |
943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 925 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
944 | "Continuing CURL interaction for %s%s\n", | 926 | "Continuing CURL interaction for %s%s\n", |
945 | s5r->domain, | 927 | s5r->domain, |
946 | s5r->url); | 928 | s5r->url); |
947 | s5r->curl_paused = GNUNET_NO; | 929 | s5r->curl_paused = GNUNET_NO; |
948 | curl_easy_pause (s5r->curl, | 930 | curl_easy_pause(s5r->curl, |
949 | CURLPAUSE_CONT); | 931 | CURLPAUSE_CONT); |
950 | } | 932 | } |
951 | return bytes_to_copy; | 933 | return bytes_to_copy; |
952 | } | 934 | } |
953 | 935 | ||
@@ -961,7 +943,7 @@ mhd_content_cb (void *cls, | |||
961 | * @return #GNUNET_OK if the certificate is valid | 943 | * @return #GNUNET_OK if the certificate is valid |
962 | */ | 944 | */ |
963 | static int | 945 | static int |
964 | check_ssl_certificate (struct Socks5Request *s5r) | 946 | check_ssl_certificate(struct Socks5Request *s5r) |
965 | { | 947 | { |
966 | unsigned int cert_list_size; | 948 | unsigned int cert_list_size; |
967 | const gnutls_datum_t *chainp; | 949 | const gnutls_datum_t *chainp; |
@@ -973,113 +955,113 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
973 | const char *name; | 955 | const char *name; |
974 | 956 | ||
975 | s5r->ssl_checked = GNUNET_YES; | 957 | s5r->ssl_checked = GNUNET_YES; |
976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 958 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
977 | "Checking X.509 certificate\n"); | 959 | "Checking X.509 certificate\n"); |
978 | if (CURLE_OK != | 960 | if (CURLE_OK != |
979 | curl_easy_getinfo (s5r->curl, | 961 | curl_easy_getinfo(s5r->curl, |
980 | CURLINFO_TLS_SESSION, | 962 | CURLINFO_TLS_SESSION, |
981 | &tlsinfo)) | 963 | &tlsinfo)) |
982 | return GNUNET_SYSERR; | 964 | return GNUNET_SYSERR; |
983 | if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend) | 965 | if (CURLSSLBACKEND_GNUTLS != tlsinfo->backend) |
984 | { | 966 | { |
985 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 967 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
986 | _("Unsupported CURL TLS backend %d\n"), | 968 | _("Unsupported CURL TLS backend %d\n"), |
987 | tlsinfo->backend); | 969 | tlsinfo->backend); |
988 | return GNUNET_SYSERR; | 970 | return GNUNET_SYSERR; |
989 | } | 971 | } |
990 | chainp = gnutls_certificate_get_peers (tlsinfo->internals, | 972 | chainp = gnutls_certificate_get_peers(tlsinfo->internals, |
991 | &cert_list_size); | 973 | &cert_list_size); |
992 | if ( (! chainp) || | 974 | if ((!chainp) || |
993 | (0 == cert_list_size) ) | 975 | (0 == cert_list_size)) |
994 | return GNUNET_SYSERR; | 976 | return GNUNET_SYSERR; |
995 | 977 | ||
996 | size = sizeof (certdn); | 978 | size = sizeof(certdn); |
997 | /* initialize an X.509 certificate structure. */ | 979 | /* initialize an X.509 certificate structure. */ |
998 | gnutls_x509_crt_init (&x509_cert); | 980 | gnutls_x509_crt_init(&x509_cert); |
999 | gnutls_x509_crt_import (x509_cert, | 981 | gnutls_x509_crt_import(x509_cert, |
1000 | chainp, | 982 | chainp, |
1001 | GNUTLS_X509_FMT_DER); | 983 | GNUTLS_X509_FMT_DER); |
1002 | 984 | ||
1003 | if (0 != (rc = gnutls_x509_crt_get_dn_by_oid (x509_cert, | 985 | if (0 != (rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, |
1004 | GNUTLS_OID_X520_COMMON_NAME, | 986 | GNUTLS_OID_X520_COMMON_NAME, |
1005 | 0, /* the first and only one */ | 987 | 0, /* the first and only one */ |
1006 | 0 /* no DER encoding */, | 988 | 0 /* no DER encoding */, |
1007 | certdn, | 989 | certdn, |
1008 | &size))) | 990 | &size))) |
1009 | { | 991 | { |
1010 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 992 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1011 | _("Failed to fetch CN from cert: %s\n"), | 993 | _("Failed to fetch CN from cert: %s\n"), |
1012 | gnutls_strerror(rc)); | 994 | gnutls_strerror(rc)); |
1013 | gnutls_x509_crt_deinit (x509_cert); | 995 | gnutls_x509_crt_deinit(x509_cert); |
1014 | return GNUNET_SYSERR; | 996 | return GNUNET_SYSERR; |
1015 | } | 997 | } |
1016 | /* check for TLSA/DANE records */ | 998 | /* check for TLSA/DANE records */ |
1017 | #if HAVE_GNUTLS_DANE | 999 | #if HAVE_GNUTLS_DANE |
1018 | if (0 != s5r->num_danes) | 1000 | if (0 != s5r->num_danes) |
1019 | { | 1001 | { |
1020 | dane_state_t dane_state; | 1002 | dane_state_t dane_state; |
1021 | dane_query_t dane_query; | 1003 | dane_query_t dane_query; |
1022 | unsigned int verify; | 1004 | unsigned int verify; |
1023 | 1005 | ||
1024 | /* FIXME: add flags to gnutls to NOT read UNBOUND_ROOT_KEY_FILE here! */ | 1006 | /* FIXME: add flags to gnutls to NOT read UNBOUND_ROOT_KEY_FILE here! */ |
1025 | if (0 != (rc = dane_state_init (&dane_state, | 1007 | if (0 != (rc = dane_state_init(&dane_state, |
1026 | #ifdef DANE_F_IGNORE_DNSSEC | 1008 | #ifdef DANE_F_IGNORE_DNSSEC |
1027 | DANE_F_IGNORE_DNSSEC | | 1009 | DANE_F_IGNORE_DNSSEC | |
1028 | #endif | 1010 | #endif |
1029 | DANE_F_IGNORE_LOCAL_RESOLVER))) | 1011 | DANE_F_IGNORE_LOCAL_RESOLVER))) |
1030 | { | 1012 | { |
1031 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1013 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1032 | _("Failed to initialize DANE: %s\n"), | 1014 | _("Failed to initialize DANE: %s\n"), |
1033 | dane_strerror(rc)); | 1015 | dane_strerror(rc)); |
1034 | gnutls_x509_crt_deinit (x509_cert); | 1016 | gnutls_x509_crt_deinit(x509_cert); |
1035 | return GNUNET_SYSERR; | 1017 | return GNUNET_SYSERR; |
1036 | } | 1018 | } |
1037 | s5r->dane_data[s5r->num_danes] = NULL; | 1019 | s5r->dane_data[s5r->num_danes] = NULL; |
1038 | s5r->dane_data_len[s5r->num_danes] = 0; | 1020 | s5r->dane_data_len[s5r->num_danes] = 0; |
1039 | if (0 != (rc = dane_raw_tlsa (dane_state, | 1021 | if (0 != (rc = dane_raw_tlsa(dane_state, |
1040 | &dane_query, | 1022 | &dane_query, |
1041 | s5r->dane_data, | 1023 | s5r->dane_data, |
1042 | s5r->dane_data_len, | 1024 | s5r->dane_data_len, |
1043 | GNUNET_YES, | 1025 | GNUNET_YES, |
1044 | GNUNET_NO))) | 1026 | GNUNET_NO))) |
1045 | { | 1027 | { |
1046 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1028 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1047 | _("Failed to parse DANE record: %s\n"), | 1029 | _("Failed to parse DANE record: %s\n"), |
1048 | dane_strerror(rc)); | 1030 | dane_strerror(rc)); |
1049 | dane_state_deinit (dane_state); | 1031 | dane_state_deinit(dane_state); |
1050 | gnutls_x509_crt_deinit (x509_cert); | 1032 | gnutls_x509_crt_deinit(x509_cert); |
1051 | return GNUNET_SYSERR; | 1033 | return GNUNET_SYSERR; |
1052 | } | 1034 | } |
1053 | if (0 != (rc = dane_verify_crt_raw (dane_state, | 1035 | if (0 != (rc = dane_verify_crt_raw(dane_state, |
1054 | chainp, | 1036 | chainp, |
1055 | cert_list_size, | 1037 | cert_list_size, |
1056 | gnutls_certificate_type_get (tlsinfo->internals), | 1038 | gnutls_certificate_type_get(tlsinfo->internals), |
1057 | dane_query, | 1039 | dane_query, |
1058 | 0, 0, | 1040 | 0, 0, |
1059 | &verify))) | 1041 | &verify))) |
1060 | { | 1042 | { |
1061 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1043 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1062 | _("Failed to verify TLS connection using DANE: %s\n"), | 1044 | _("Failed to verify TLS connection using DANE: %s\n"), |
1063 | dane_strerror(rc)); | 1045 | dane_strerror(rc)); |
1064 | dane_query_deinit (dane_query); | 1046 | dane_query_deinit(dane_query); |
1065 | dane_state_deinit (dane_state); | 1047 | dane_state_deinit(dane_state); |
1066 | gnutls_x509_crt_deinit (x509_cert); | 1048 | gnutls_x509_crt_deinit(x509_cert); |
1067 | return GNUNET_SYSERR; | 1049 | return GNUNET_SYSERR; |
1068 | } | 1050 | } |
1069 | if (0 != verify) | 1051 | if (0 != verify) |
1070 | { | 1052 | { |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1053 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1072 | _("Failed DANE verification failed with GnuTLS verify status code: %u\n"), | 1054 | _("Failed DANE verification failed with GnuTLS verify status code: %u\n"), |
1073 | verify); | 1055 | verify); |
1074 | dane_query_deinit (dane_query); | 1056 | dane_query_deinit(dane_query); |
1075 | dane_state_deinit (dane_state); | 1057 | dane_state_deinit(dane_state); |
1076 | gnutls_x509_crt_deinit (x509_cert); | 1058 | gnutls_x509_crt_deinit(x509_cert); |
1077 | return GNUNET_SYSERR; | 1059 | return GNUNET_SYSERR; |
1060 | } | ||
1061 | dane_query_deinit(dane_query); | ||
1062 | dane_state_deinit(dane_state); | ||
1063 | /* success! */ | ||
1078 | } | 1064 | } |
1079 | dane_query_deinit (dane_query); | ||
1080 | dane_state_deinit (dane_state); | ||
1081 | /* success! */ | ||
1082 | } | ||
1083 | else | 1065 | else |
1084 | #endif | 1066 | #endif |
1085 | { | 1067 | { |
@@ -1088,27 +1070,27 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
1088 | if (NULL != s5r->leho) | 1070 | if (NULL != s5r->leho) |
1089 | name = s5r->leho; | 1071 | name = s5r->leho; |
1090 | if (NULL != name) | 1072 | if (NULL != name) |
1091 | { | ||
1092 | if (0 == (rc = gnutls_x509_crt_check_hostname (x509_cert, | ||
1093 | name))) | ||
1094 | { | 1073 | { |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1074 | if (0 == (rc = gnutls_x509_crt_check_hostname(x509_cert, |
1096 | _("TLS certificate subject name (%s) does not match `%s': %d\n"), | 1075 | name))) |
1097 | certdn, | 1076 | { |
1098 | name, | 1077 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1099 | rc); | 1078 | _("TLS certificate subject name (%s) does not match `%s': %d\n"), |
1100 | gnutls_x509_crt_deinit (x509_cert); | 1079 | certdn, |
1101 | return GNUNET_SYSERR; | 1080 | name, |
1081 | rc); | ||
1082 | gnutls_x509_crt_deinit(x509_cert); | ||
1083 | return GNUNET_SYSERR; | ||
1084 | } | ||
1102 | } | 1085 | } |
1103 | } | ||
1104 | else | 1086 | else |
1105 | { | 1087 | { |
1106 | /* we did not even have the domain name!? */ | 1088 | /* we did not even have the domain name!? */ |
1107 | GNUNET_break (0); | 1089 | GNUNET_break(0); |
1108 | return GNUNET_SYSERR; | 1090 | return GNUNET_SYSERR; |
1109 | } | 1091 | } |
1110 | } | 1092 | } |
1111 | gnutls_x509_crt_deinit (x509_cert); | 1093 | gnutls_x509_crt_deinit(x509_cert); |
1112 | return GNUNET_OK; | 1094 | return GNUNET_OK; |
1113 | } | 1095 | } |
1114 | 1096 | ||
@@ -1126,10 +1108,10 @@ check_ssl_certificate (struct Socks5Request *s5r) | |||
1126 | * @return size of processed bytes | 1108 | * @return size of processed bytes |
1127 | */ | 1109 | */ |
1128 | static size_t | 1110 | static size_t |
1129 | curl_check_hdr (void *buffer, | 1111 | curl_check_hdr(void *buffer, |
1130 | size_t size, | 1112 | size_t size, |
1131 | size_t nmemb, | 1113 | size_t nmemb, |
1132 | void *cls) | 1114 | void *cls) |
1133 | { | 1115 | { |
1134 | struct Socks5Request *s5r = cls; | 1116 | struct Socks5Request *s5r = cls; |
1135 | struct HttpResponseHeader *header; | 1117 | struct HttpResponseHeader *header; |
@@ -1145,178 +1127,178 @@ curl_check_hdr (void *buffer, | |||
1145 | int domain_matched; | 1127 | int domain_matched; |
1146 | char *tok; | 1128 | char *tok; |
1147 | 1129 | ||
1148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1149 | "Receiving HTTP response header from CURL\n"); | 1131 | "Receiving HTTP response header from CURL\n"); |
1150 | /* first, check TLS certificate */ | 1132 | /* first, check TLS certificate */ |
1151 | if ( (GNUNET_YES != s5r->ssl_checked) && | 1133 | if ((GNUNET_YES != s5r->ssl_checked) && |
1152 | (GNUNET_YES == s5r->is_tls)) | 1134 | (GNUNET_YES == s5r->is_tls)) |
1153 | //(HTTPS_PORT == s5r->port)) | 1135 | //(HTTPS_PORT == s5r->port)) |
1154 | { | 1136 | { |
1155 | if (GNUNET_OK != check_ssl_certificate (s5r)) | 1137 | if (GNUNET_OK != check_ssl_certificate(s5r)) |
1156 | return 0; | 1138 | return 0; |
1157 | } | 1139 | } |
1158 | ndup = GNUNET_strndup (buffer, | 1140 | ndup = GNUNET_strndup(buffer, |
1159 | bytes); | 1141 | bytes); |
1160 | hdr_type = strtok (ndup, | 1142 | hdr_type = strtok(ndup, |
1161 | ":"); | 1143 | ":"); |
1162 | if (NULL == hdr_type) | 1144 | if (NULL == hdr_type) |
1163 | { | 1145 | { |
1164 | GNUNET_free (ndup); | 1146 | GNUNET_free(ndup); |
1165 | return bytes; | 1147 | return bytes; |
1166 | } | 1148 | } |
1167 | hdr_val = strtok (NULL, | 1149 | hdr_val = strtok(NULL, |
1168 | ""); | 1150 | ""); |
1169 | if (NULL == hdr_val) | 1151 | if (NULL == hdr_val) |
1170 | { | 1152 | { |
1171 | GNUNET_free (ndup); | 1153 | GNUNET_free(ndup); |
1172 | return bytes; | 1154 | return bytes; |
1173 | } | 1155 | } |
1174 | if (' ' == *hdr_val) | 1156 | if (' ' == *hdr_val) |
1175 | hdr_val++; | 1157 | hdr_val++; |
1176 | 1158 | ||
1177 | /* custom logic for certain header types */ | 1159 | /* custom logic for certain header types */ |
1178 | new_cookie_hdr = NULL; | 1160 | new_cookie_hdr = NULL; |
1179 | if ( (NULL != s5r->leho) && | 1161 | if ((NULL != s5r->leho) && |
1180 | (0 == strcasecmp (hdr_type, | 1162 | (0 == strcasecmp(hdr_type, |
1181 | MHD_HTTP_HEADER_SET_COOKIE)) ) | 1163 | MHD_HTTP_HEADER_SET_COOKIE))) |
1182 | 1164 | ||
1183 | { | 1165 | { |
1184 | new_cookie_hdr = GNUNET_malloc (strlen (hdr_val) + | 1166 | new_cookie_hdr = GNUNET_malloc(strlen(hdr_val) + |
1185 | strlen (s5r->domain) + 1); | 1167 | strlen(s5r->domain) + 1); |
1186 | offset = 0; | 1168 | offset = 0; |
1187 | domain_matched = GNUNET_NO; /* make sure we match domain at most once */ | 1169 | domain_matched = GNUNET_NO; /* make sure we match domain at most once */ |
1188 | for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";")) | 1170 | 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)) | ||
1198 | { | 1171 | { |
1199 | delta_cdomain = strlen (s5r->leho) - strlen (cookie_domain); | 1172 | if ((0 == strncasecmp(tok, |
1200 | if (0 == strcasecmp (cookie_domain, | 1173 | " domain", |
1201 | s5r->leho + delta_cdomain)) | 1174 | strlen(" domain"))) && |
1202 | { | 1175 | (GNUNET_NO == domain_matched)) |
1203 | offset += sprintf (new_cookie_hdr + offset, | 1176 | { |
1204 | " domain=%s;", | 1177 | domain_matched = GNUNET_YES; |
1205 | s5r->domain); | 1178 | cookie_domain = tok + strlen(" domain") + 1; |
1206 | continue; | 1179 | if (strlen(cookie_domain) < strlen(s5r->leho)) |
1207 | } | 1180 | { |
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++] = ';'; | ||
1208 | } | 1217 | } |
1209 | else if (0 == strcmp (cookie_domain, | 1218 | hdr_val = new_cookie_hdr; |
1210 | s5r->leho)) | 1219 | } |
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))) | ||
1211 | { | 1241 | { |
1212 | offset += sprintf (new_cookie_hdr + offset, | 1242 | GNUNET_asprintf(&new_location, |
1213 | " domain=%s;", | 1243 | "%s%s%s", |
1214 | s5r->domain); | 1244 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) |
1215 | continue; | 1245 | ? "http://" |
1246 | : "https://", | ||
1247 | s5r->domain, | ||
1248 | hdr_val + strlen(leho_host)); | ||
1249 | hdr_val = new_location; | ||
1216 | } | 1250 | } |
1217 | else if ( ('.' == cookie_domain[0]) && | 1251 | GNUNET_free(leho_host); |
1218 | (0 == strcmp (&cookie_domain[1], | 1252 | } |
1219 | s5r->leho)) ) | 1253 | if (0 == strcasecmp(MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, |
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))) | ||
1220 | { | 1266 | { |
1221 | offset += sprintf (new_cookie_hdr + offset, | 1267 | GNUNET_asprintf(&new_location, |
1222 | " domain=.%s;", | 1268 | "%s%s", |
1223 | s5r->domain); | 1269 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) |
1224 | continue; | 1270 | ? "http://" |
1271 | : "https://", | ||
1272 | s5r->domain); | ||
1273 | hdr_val = new_location; | ||
1225 | } | 1274 | } |
1226 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1275 | GNUNET_free(leho_host); |
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++] = ';'; | ||
1235 | } | 1276 | } |
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 | } | ||
1295 | 1277 | ||
1296 | /* MHD does not allow certain characters in values, remove those */ | 1278 | /* MHD does not allow certain characters in values, remove those */ |
1297 | if (NULL != (tok = strchr (hdr_val, '\n'))) | 1279 | if (NULL != (tok = strchr(hdr_val, '\n'))) |
1298 | *tok = '\0'; | 1280 | *tok = '\0'; |
1299 | if (NULL != (tok = strchr (hdr_val, '\r'))) | 1281 | if (NULL != (tok = strchr(hdr_val, '\r'))) |
1300 | *tok = '\0'; | 1282 | *tok = '\0'; |
1301 | if (NULL != (tok = strchr (hdr_val, '\t'))) | 1283 | if (NULL != (tok = strchr(hdr_val, '\t'))) |
1302 | *tok = '\0'; | 1284 | *tok = '\0'; |
1303 | if (0 != strlen (hdr_val)) /* Rely in MHD to set those */ | 1285 | if (0 != strlen(hdr_val)) /* Rely in MHD to set those */ |
1304 | { | 1286 | { |
1305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1287 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1306 | "Adding header %s: %s to MHD response\n", | 1288 | "Adding header %s: %s to MHD response\n", |
1307 | hdr_type, | 1289 | hdr_type, |
1308 | hdr_val); | 1290 | hdr_val); |
1309 | header = GNUNET_new (struct HttpResponseHeader); | 1291 | header = GNUNET_new(struct HttpResponseHeader); |
1310 | header->type = GNUNET_strdup (hdr_type); | 1292 | header->type = GNUNET_strdup(hdr_type); |
1311 | header->value = GNUNET_strdup (hdr_val); | 1293 | header->value = GNUNET_strdup(hdr_val); |
1312 | GNUNET_CONTAINER_DLL_insert (s5r->header_head, | 1294 | GNUNET_CONTAINER_DLL_insert(s5r->header_head, |
1313 | s5r->header_tail, | 1295 | s5r->header_tail, |
1314 | header); | 1296 | header); |
1315 | } | 1297 | } |
1316 | cleanup: | 1298 | cleanup: |
1317 | GNUNET_free (ndup); | 1299 | GNUNET_free(ndup); |
1318 | GNUNET_free_non_null (new_cookie_hdr); | 1300 | GNUNET_free_non_null(new_cookie_hdr); |
1319 | GNUNET_free_non_null (new_location); | 1301 | GNUNET_free_non_null(new_location); |
1320 | return bytes; | 1302 | return bytes; |
1321 | } | 1303 | } |
1322 | 1304 | ||
@@ -1330,73 +1312,73 @@ curl_check_hdr (void *buffer, | |||
1330 | * already initialized before | 1312 | * already initialized before |
1331 | */ | 1313 | */ |
1332 | static int | 1314 | static int |
1333 | create_mhd_response_from_s5r (struct Socks5Request *s5r) | 1315 | create_mhd_response_from_s5r(struct Socks5Request *s5r) |
1334 | { | 1316 | { |
1335 | long resp_code; | 1317 | long resp_code; |
1336 | double content_length; | 1318 | double content_length; |
1337 | 1319 | ||
1338 | if (NULL != s5r->response) | 1320 | if (NULL != s5r->response) |
1339 | { | 1321 | { |
1340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1322 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1341 | "Response already set!\n"); | 1323 | "Response already set!\n"); |
1342 | return GNUNET_SYSERR; | 1324 | return GNUNET_SYSERR; |
1343 | } | 1325 | } |
1344 | 1326 | ||
1345 | GNUNET_break (CURLE_OK == | 1327 | GNUNET_break(CURLE_OK == |
1346 | curl_easy_getinfo (s5r->curl, | 1328 | curl_easy_getinfo(s5r->curl, |
1347 | CURLINFO_RESPONSE_CODE, | 1329 | CURLINFO_RESPONSE_CODE, |
1348 | &resp_code)); | 1330 | &resp_code)); |
1349 | GNUNET_break (CURLE_OK == | 1331 | GNUNET_break(CURLE_OK == |
1350 | curl_easy_getinfo (s5r->curl, | 1332 | curl_easy_getinfo(s5r->curl, |
1351 | CURLINFO_CONTENT_LENGTH_DOWNLOAD, | 1333 | CURLINFO_CONTENT_LENGTH_DOWNLOAD, |
1352 | &content_length)); | 1334 | &content_length)); |
1353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1354 | "Creating MHD response with code %d and size %d for %s%s\n", | 1336 | "Creating MHD response with code %d and size %d for %s%s\n", |
1355 | (int) resp_code, | 1337 | (int)resp_code, |
1356 | (int) content_length, | 1338 | (int)content_length, |
1357 | s5r->domain, | 1339 | s5r->domain, |
1358 | s5r->url); | 1340 | s5r->url); |
1359 | s5r->response_code = resp_code; | 1341 | s5r->response_code = resp_code; |
1360 | s5r->response = MHD_create_response_from_callback ((-1 == content_length) | 1342 | s5r->response = MHD_create_response_from_callback((-1 == content_length) |
1361 | ? MHD_SIZE_UNKNOWN | 1343 | ? MHD_SIZE_UNKNOWN |
1362 | : content_length, | 1344 | : content_length, |
1363 | IO_BUFFERSIZE, | 1345 | IO_BUFFERSIZE, |
1364 | &mhd_content_cb, | 1346 | &mhd_content_cb, |
1365 | s5r, | 1347 | s5r, |
1366 | NULL); | 1348 | NULL); |
1367 | for (struct HttpResponseHeader *header = s5r->header_head; | 1349 | for (struct HttpResponseHeader *header = s5r->header_head; |
1368 | NULL != header; | 1350 | NULL != header; |
1369 | header = header->next) | 1351 | header = header->next) |
1370 | { | 1352 | { |
1371 | if (0 == strcasecmp (header->type, | 1353 | if (0 == strcasecmp(header->type, |
1372 | MHD_HTTP_HEADER_CONTENT_LENGTH)) | 1354 | MHD_HTTP_HEADER_CONTENT_LENGTH)) |
1373 | continue; /* MHD won't let us mess with those, for good reason */ | 1355 | continue; /* MHD won't let us mess with those, for good reason */ |
1374 | if ( (0 == strcasecmp (header->type, | 1356 | if ((0 == strcasecmp(header->type, |
1375 | MHD_HTTP_HEADER_TRANSFER_ENCODING)) && | 1357 | MHD_HTTP_HEADER_TRANSFER_ENCODING)) && |
1376 | ( (0 == strcasecmp (header->value, | 1358 | ((0 == strcasecmp(header->value, |
1377 | "identity")) || | 1359 | "identity")) || |
1378 | (0 == strcasecmp (header->value, | 1360 | (0 == strcasecmp(header->value, |
1379 | "chunked")) ) ) | 1361 | "chunked")))) |
1380 | continue; /* MHD won't let us mess with those, for good reason */ | 1362 | continue; /* MHD won't let us mess with those, for good reason */ |
1381 | if (MHD_YES != | 1363 | if (MHD_YES != |
1382 | MHD_add_response_header (s5r->response, | 1364 | MHD_add_response_header(s5r->response, |
1383 | header->type, | 1365 | header->type, |
1384 | header->value)) | 1366 | header->value)) |
1385 | { | 1367 | { |
1386 | GNUNET_break (0); | 1368 | GNUNET_break(0); |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1369 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1388 | "Failed to add header `%s:%s'\n", | 1370 | "Failed to add header `%s:%s'\n", |
1389 | header->type, | 1371 | header->type, |
1390 | header->value); | 1372 | header->value); |
1373 | } | ||
1391 | } | 1374 | } |
1392 | } | ||
1393 | /* force connection to be closed after each request, as we | 1375 | /* force connection to be closed after each request, as we |
1394 | do not support HTTP pipelining (yet, FIXME!) */ | 1376 | do not support HTTP pipelining (yet, FIXME!) */ |
1395 | /*GNUNET_break (MHD_YES == | 1377 | /*GNUNET_break (MHD_YES == |
1396 | MHD_add_response_header (s5r->response, | 1378 | MHD_add_response_header (s5r->response, |
1397 | MHD_HTTP_HEADER_CONNECTION, | 1379 | MHD_HTTP_HEADER_CONNECTION, |
1398 | "close"));*/ | 1380 | "close"));*/ |
1399 | MHD_resume_connection (s5r->con); | 1381 | MHD_resume_connection(s5r->con); |
1400 | s5r->suspended = GNUNET_NO; | 1382 | s5r->suspended = GNUNET_NO; |
1401 | return GNUNET_OK; | 1383 | return GNUNET_OK; |
1402 | } | 1384 | } |
@@ -1413,70 +1395,70 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r) | |||
1413 | * @return number of bytes handled | 1395 | * @return number of bytes handled |
1414 | */ | 1396 | */ |
1415 | static size_t | 1397 | static size_t |
1416 | curl_download_cb (void *ptr, | 1398 | curl_download_cb(void *ptr, |
1417 | size_t size, | 1399 | size_t size, |
1418 | size_t nmemb, | 1400 | size_t nmemb, |
1419 | void* ctx) | 1401 | void* ctx) |
1420 | { | 1402 | { |
1421 | struct Socks5Request *s5r = ctx; | 1403 | struct Socks5Request *s5r = ctx; |
1422 | size_t total = size * nmemb; | 1404 | size_t total = size * nmemb; |
1423 | 1405 | ||
1424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1406 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1425 | "Receiving %ux%u bytes for `%s%s' from cURL to download\n", | 1407 | "Receiving %ux%u bytes for `%s%s' from cURL to download\n", |
1426 | (unsigned int) size, | 1408 | (unsigned int)size, |
1427 | (unsigned int) nmemb, | 1409 | (unsigned int)nmemb, |
1428 | s5r->domain, | 1410 | s5r->domain, |
1429 | s5r->url); | 1411 | s5r->url); |
1430 | if (NULL == s5r->response) | 1412 | if (NULL == s5r->response) |
1431 | GNUNET_assert (GNUNET_OK == | 1413 | GNUNET_assert(GNUNET_OK == |
1432 | create_mhd_response_from_s5r (s5r)); | 1414 | create_mhd_response_from_s5r(s5r)); |
1433 | if ( (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) && | 1415 | if ((SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) && |
1434 | (0 == s5r->io_len)) | 1416 | (0 == s5r->io_len)) |
1435 | { | 1417 | { |
1436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1418 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1437 | "Previous upload finished... starting DOWNLOAD.\n"); | 1419 | "Previous upload finished... starting DOWNLOAD.\n"); |
1438 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | 1420 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; |
1439 | } | 1421 | } |
1440 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || | 1422 | if ((SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || |
1441 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | 1423 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) |
1442 | { | 1424 | { |
1443 | /* we're still not done with the upload, do not yet | 1425 | /* we're still not done with the upload, do not yet |
1444 | start the download, the IO buffer is still full | 1426 | start the download, the IO buffer is still full |
1445 | with upload data. */ | 1427 | with upload data. */ |
1446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1428 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1447 | "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n", | 1429 | "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n", |
1448 | s5r->domain, | 1430 | s5r->domain, |
1449 | s5r->url); | 1431 | s5r->url); |
1450 | s5r->curl_paused = GNUNET_YES; | 1432 | s5r->curl_paused = GNUNET_YES; |
1451 | return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ | 1433 | return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ |
1452 | } | 1434 | } |
1453 | if (sizeof (s5r->io_buf) - s5r->io_len < total) | 1435 | if (sizeof(s5r->io_buf) - s5r->io_len < total) |
1454 | { | 1436 | { |
1455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1437 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1456 | "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n", | 1438 | "Pausing CURL `%s%s' download, not enough space %llu %llu %llu\n", |
1457 | s5r->domain, | 1439 | s5r->domain, |
1458 | s5r->url, | 1440 | s5r->url, |
1459 | (unsigned long long) sizeof (s5r->io_buf), | 1441 | (unsigned long long)sizeof(s5r->io_buf), |
1460 | (unsigned long long) s5r->io_len, | 1442 | (unsigned long long)s5r->io_len, |
1461 | (unsigned long long) total); | 1443 | (unsigned long long)total); |
1462 | s5r->curl_paused = GNUNET_YES; | 1444 | s5r->curl_paused = GNUNET_YES; |
1463 | return CURL_WRITEFUNC_PAUSE; /* not enough space */ | 1445 | return CURL_WRITEFUNC_PAUSE; /* not enough space */ |
1464 | } | 1446 | } |
1465 | GNUNET_memcpy (&s5r->io_buf[s5r->io_len], | 1447 | GNUNET_memcpy(&s5r->io_buf[s5r->io_len], |
1466 | ptr, | 1448 | ptr, |
1467 | total); | 1449 | total); |
1468 | s5r->io_len += total; | 1450 | s5r->io_len += total; |
1469 | if (GNUNET_YES == s5r->suspended) | 1451 | if (GNUNET_YES == s5r->suspended) |
1470 | { | 1452 | { |
1471 | MHD_resume_connection (s5r->con); | 1453 | MHD_resume_connection(s5r->con); |
1472 | s5r->suspended = GNUNET_NO; | 1454 | s5r->suspended = GNUNET_NO; |
1473 | } | 1455 | } |
1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1456 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1475 | "Received %llu bytes of payload via cURL from %s\n", | 1457 | "Received %llu bytes of payload via cURL from %s\n", |
1476 | (unsigned long long) total, | 1458 | (unsigned long long)total, |
1477 | s5r->domain); | 1459 | s5r->domain); |
1478 | if (s5r->io_len == total) | 1460 | if (s5r->io_len == total) |
1479 | run_mhd_now (s5r->hd); | 1461 | run_mhd_now(s5r->hd); |
1480 | return total; | 1462 | return total; |
1481 | } | 1463 | } |
1482 | 1464 | ||
@@ -1492,64 +1474,64 @@ curl_download_cb (void *ptr, | |||
1492 | * @return number of bytes copied to @a buf | 1474 | * @return number of bytes copied to @a buf |
1493 | */ | 1475 | */ |
1494 | static size_t | 1476 | static size_t |
1495 | curl_upload_cb (void *buf, | 1477 | curl_upload_cb(void *buf, |
1496 | size_t size, | 1478 | size_t size, |
1497 | size_t nmemb, | 1479 | size_t nmemb, |
1498 | void *cls) | 1480 | void *cls) |
1499 | { | 1481 | { |
1500 | struct Socks5Request *s5r = cls; | 1482 | struct Socks5Request *s5r = cls; |
1501 | size_t len = size * nmemb; | 1483 | size_t len = size * nmemb; |
1502 | size_t to_copy; | 1484 | size_t to_copy; |
1503 | 1485 | ||
1504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1486 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1505 | "Receiving %ux%u bytes for `%s%s' from cURL to upload\n", | 1487 | "Receiving %ux%u bytes for `%s%s' from cURL to upload\n", |
1506 | (unsigned int) size, | 1488 | (unsigned int)size, |
1507 | (unsigned int) nmemb, | 1489 | (unsigned int)nmemb, |
1508 | s5r->domain, | 1490 | s5r->domain, |
1509 | s5r->url); | 1491 | s5r->url); |
1510 | 1492 | ||
1511 | if ( (0 == s5r->io_len) && | 1493 | if ((0 == s5r->io_len) && |
1512 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) | 1494 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state)) |
1513 | { | ||
1514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1515 | "Pausing CURL UPLOAD %s%s, need more data\n", | ||
1516 | s5r->domain, | ||
1517 | s5r->url); | ||
1518 | return CURL_READFUNC_PAUSE; | ||
1519 | } | ||
1520 | if ( (0 == s5r->io_len) && | ||
1521 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) | ||
1522 | { | ||
1523 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
1524 | if (GNUNET_YES == s5r->curl_paused) | ||
1525 | { | 1495 | { |
1526 | s5r->curl_paused = GNUNET_NO; | 1496 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1527 | curl_easy_pause (s5r->curl, | 1497 | "Pausing CURL UPLOAD %s%s, need more data\n", |
1528 | CURLPAUSE_CONT); | 1498 | s5r->domain, |
1529 | } | 1499 | s5r->url); |
1530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1500 | return CURL_READFUNC_PAUSE; |
1531 | "Completed CURL UPLOAD %s%s\n", | 1501 | } |
1532 | s5r->domain, | 1502 | if ((0 == s5r->io_len) && |
1533 | s5r->url); | 1503 | (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state)) |
1534 | return 0; /* upload finished, can now download */ | 1504 | { |
1535 | } | 1505 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; |
1536 | if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && | 1506 | if (GNUNET_YES == s5r->curl_paused) |
1537 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) | 1507 | { |
1538 | { | 1508 | s5r->curl_paused = GNUNET_NO; |
1539 | GNUNET_break (0); | 1509 | curl_easy_pause(s5r->curl, |
1540 | return CURL_READFUNC_ABORT; | 1510 | CURLPAUSE_CONT); |
1541 | } | 1511 | } |
1542 | to_copy = GNUNET_MIN (s5r->io_len, | 1512 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1543 | len); | 1513 | "Completed CURL UPLOAD %s%s\n", |
1544 | GNUNET_memcpy (buf, | 1514 | s5r->domain, |
1545 | s5r->io_buf, | 1515 | s5r->url); |
1546 | to_copy); | 1516 | return 0; /* upload finished, can now download */ |
1547 | memmove (s5r->io_buf, | 1517 | } |
1548 | &s5r->io_buf[to_copy], | 1518 | if ((SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && |
1549 | s5r->io_len - to_copy); | 1519 | (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state)) |
1520 | { | ||
1521 | GNUNET_break(0); | ||
1522 | return CURL_READFUNC_ABORT; | ||
1523 | } | ||
1524 | to_copy = GNUNET_MIN(s5r->io_len, | ||
1525 | len); | ||
1526 | GNUNET_memcpy(buf, | ||
1527 | s5r->io_buf, | ||
1528 | to_copy); | ||
1529 | memmove(s5r->io_buf, | ||
1530 | &s5r->io_buf[to_copy], | ||
1531 | s5r->io_len - to_copy); | ||
1550 | s5r->io_len -= to_copy; | 1532 | s5r->io_len -= to_copy; |
1551 | if (s5r->io_len + to_copy == sizeof (s5r->io_buf)) | 1533 | if (s5r->io_len + to_copy == sizeof(s5r->io_buf)) |
1552 | run_mhd_now (s5r->hd); /* got more space for upload now */ | 1534 | run_mhd_now(s5r->hd); /* got more space for upload now */ |
1553 | return to_copy; | 1535 | return to_copy; |
1554 | } | 1536 | } |
1555 | 1537 | ||
@@ -1564,14 +1546,14 @@ curl_upload_cb (void *buf, | |||
1564 | * @param cls closure | 1546 | * @param cls closure |
1565 | */ | 1547 | */ |
1566 | static void | 1548 | static void |
1567 | curl_task_download (void *cls); | 1549 | curl_task_download(void *cls); |
1568 | 1550 | ||
1569 | 1551 | ||
1570 | /** | 1552 | /** |
1571 | * Ask cURL for the select() sets and schedule cURL operations. | 1553 | * Ask cURL for the select() sets and schedule cURL operations. |
1572 | */ | 1554 | */ |
1573 | static void | 1555 | static void |
1574 | curl_download_prepare () | 1556 | curl_download_prepare() |
1575 | { | 1557 | { |
1576 | CURLMcode mret; | 1558 | CURLMcode mret; |
1577 | fd_set rs; | 1559 | fd_set rs; |
@@ -1583,63 +1565,63 @@ curl_download_prepare () | |||
1583 | long to; | 1565 | long to; |
1584 | struct GNUNET_TIME_Relative rtime; | 1566 | struct GNUNET_TIME_Relative rtime; |
1585 | 1567 | ||
1586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1568 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1587 | "Scheduling CURL interaction\n"); | 1569 | "Scheduling CURL interaction\n"); |
1588 | if (NULL != curl_download_task) | 1570 | if (NULL != curl_download_task) |
1589 | { | 1571 | { |
1590 | GNUNET_SCHEDULER_cancel (curl_download_task); | 1572 | GNUNET_SCHEDULER_cancel(curl_download_task); |
1591 | curl_download_task = NULL; | 1573 | curl_download_task = NULL; |
1592 | } | 1574 | } |
1593 | max = -1; | 1575 | max = -1; |
1594 | FD_ZERO (&rs); | 1576 | FD_ZERO(&rs); |
1595 | FD_ZERO (&ws); | 1577 | FD_ZERO(&ws); |
1596 | FD_ZERO (&es); | 1578 | FD_ZERO(&es); |
1597 | if (CURLM_OK != (mret = curl_multi_fdset (curl_multi, | 1579 | if (CURLM_OK != (mret = curl_multi_fdset(curl_multi, |
1598 | &rs, | 1580 | &rs, |
1599 | &ws, | 1581 | &ws, |
1600 | &es, | 1582 | &es, |
1601 | &max))) | 1583 | &max))) |
1602 | { | 1584 | { |
1603 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1585 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1604 | "%s failed at %s:%d: `%s'\n", | 1586 | "%s failed at %s:%d: `%s'\n", |
1605 | "curl_multi_fdset", __FILE__, __LINE__, | 1587 | "curl_multi_fdset", __FILE__, __LINE__, |
1606 | curl_multi_strerror (mret)); | 1588 | curl_multi_strerror(mret)); |
1607 | return; | 1589 | return; |
1608 | } | 1590 | } |
1609 | to = -1; | 1591 | to = -1; |
1610 | GNUNET_break (CURLM_OK == | 1592 | GNUNET_break(CURLM_OK == |
1611 | curl_multi_timeout (curl_multi, | 1593 | curl_multi_timeout(curl_multi, |
1612 | &to)); | 1594 | &to)); |
1613 | if (-1 == to) | 1595 | if (-1 == to) |
1614 | rtime = GNUNET_TIME_UNIT_FOREVER_REL; | 1596 | rtime = GNUNET_TIME_UNIT_FOREVER_REL; |
1615 | else | 1597 | else |
1616 | rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 1598 | rtime = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
1617 | to); | 1599 | to); |
1618 | if (-1 != max) | 1600 | if (-1 != max) |
1619 | { | 1601 | { |
1620 | grs = GNUNET_NETWORK_fdset_create (); | 1602 | grs = GNUNET_NETWORK_fdset_create(); |
1621 | gws = GNUNET_NETWORK_fdset_create (); | 1603 | gws = GNUNET_NETWORK_fdset_create(); |
1622 | GNUNET_NETWORK_fdset_copy_native (grs, | 1604 | GNUNET_NETWORK_fdset_copy_native(grs, |
1623 | &rs, | 1605 | &rs, |
1624 | max + 1); | 1606 | max + 1); |
1625 | GNUNET_NETWORK_fdset_copy_native (gws, | 1607 | GNUNET_NETWORK_fdset_copy_native(gws, |
1626 | &ws, | 1608 | &ws, |
1627 | max + 1); | 1609 | max + 1); |
1628 | curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1610 | curl_download_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1629 | rtime, | 1611 | rtime, |
1630 | grs, | 1612 | grs, |
1631 | gws, | 1613 | gws, |
1632 | &curl_task_download, | ||
1633 | curl_multi); | ||
1634 | GNUNET_NETWORK_fdset_destroy (gws); | ||
1635 | GNUNET_NETWORK_fdset_destroy (grs); | ||
1636 | } | ||
1637 | else | ||
1638 | { | ||
1639 | curl_download_task = GNUNET_SCHEDULER_add_delayed (rtime, | ||
1640 | &curl_task_download, | 1614 | &curl_task_download, |
1641 | curl_multi); | 1615 | curl_multi); |
1642 | } | 1616 | GNUNET_NETWORK_fdset_destroy(gws); |
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 | } | ||
1643 | } | 1625 | } |
1644 | 1626 | ||
1645 | 1627 | ||
@@ -1649,7 +1631,7 @@ curl_download_prepare () | |||
1649 | * @param cls closure, NULL | 1631 | * @param cls closure, NULL |
1650 | */ | 1632 | */ |
1651 | static void | 1633 | static void |
1652 | curl_task_download (void *cls) | 1634 | curl_task_download(void *cls) |
1653 | { | 1635 | { |
1654 | int running; | 1636 | int running; |
1655 | int msgnum; | 1637 | int msgnum; |
@@ -1658,103 +1640,109 @@ curl_task_download (void *cls) | |||
1658 | struct Socks5Request *s5r; | 1640 | struct Socks5Request *s5r; |
1659 | 1641 | ||
1660 | curl_download_task = NULL; | 1642 | curl_download_task = NULL; |
1661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1643 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1662 | "Running CURL interaction\n"); | 1644 | "Running CURL interaction\n"); |
1663 | do | 1645 | do |
1664 | { | 1646 | { |
1665 | running = 0; | 1647 | running = 0; |
1666 | mret = curl_multi_perform (curl_multi, | 1648 | mret = curl_multi_perform(curl_multi, |
1667 | &running); | 1649 | &running); |
1668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1650 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1669 | "Checking CURL multi status: %d\n", | 1651 | "Checking CURL multi status: %d\n", |
1670 | mret); | 1652 | mret); |
1671 | while (NULL != (msg = curl_multi_info_read (curl_multi, | 1653 | while (NULL != (msg = curl_multi_info_read(curl_multi, |
1672 | &msgnum))) | 1654 | &msgnum))) |
1673 | { | 1655 | { |
1674 | GNUNET_break (CURLE_OK == | 1656 | GNUNET_break(CURLE_OK == |
1675 | curl_easy_getinfo (msg->easy_handle, | 1657 | curl_easy_getinfo(msg->easy_handle, |
1676 | CURLINFO_PRIVATE, | 1658 | CURLINFO_PRIVATE, |
1677 | (char **) &s5r )); | 1659 | (char **)&s5r)); |
1678 | if (NULL == s5r) | 1660 | if (NULL == s5r) |
1679 | { | 1661 | { |
1680 | GNUNET_break (0); | 1662 | GNUNET_break(0); |
1681 | continue; | 1663 | continue; |
1682 | } | 1664 | } |
1683 | switch (msg->msg) | 1665 | switch (msg->msg) |
1684 | { | 1666 | { |
1685 | case CURLMSG_NONE: | 1667 | case CURLMSG_NONE: |
1686 | /* documentation says this is not used */ | 1668 | /* documentation says this is not used */ |
1687 | GNUNET_break (0); | 1669 | GNUNET_break(0); |
1688 | break; | 1670 | break; |
1689 | case CURLMSG_DONE: | 1671 | |
1690 | switch (msg->data.result) | 1672 | case CURLMSG_DONE: |
1691 | { | 1673 | switch (msg->data.result) |
1692 | case CURLE_OK: | 1674 | { |
1693 | case CURLE_GOT_NOTHING: | 1675 | case CURLE_OK: |
1694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1676 | case CURLE_GOT_NOTHING: |
1695 | "CURL download %s%s completed.\n", | 1677 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1696 | s5r->domain, | 1678 | "CURL download %s%s completed.\n", |
1697 | s5r->url); | 1679 | s5r->domain, |
1680 | s5r->url); | ||
1681 | if (NULL == s5r->response) | ||
1682 | { | ||
1683 | GNUNET_assert(GNUNET_OK == | ||
1684 | create_mhd_response_from_s5r(s5r)); | ||
1685 | } | ||
1686 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1687 | if (GNUNET_YES == s5r->suspended) | ||
1688 | { | ||
1689 | MHD_resume_connection(s5r->con); | ||
1690 | s5r->suspended = GNUNET_NO; | ||
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 | } | ||
1698 | if (NULL == s5r->response) | 1711 | if (NULL == s5r->response) |
1699 | { | 1712 | s5r->response = curl_failure_response; |
1700 | GNUNET_assert (GNUNET_OK == | ||
1701 | create_mhd_response_from_s5r (s5r)); | ||
1702 | } | ||
1703 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1704 | if (GNUNET_YES == s5r->suspended) | ||
1705 | { | ||
1706 | MHD_resume_connection (s5r->con); | ||
1707 | s5r->suspended = GNUNET_NO; | ||
1708 | } | ||
1709 | run_mhd_now (s5r->hd); | ||
1710 | break; | 1713 | break; |
1714 | |||
1715 | case CURLMSG_LAST: | ||
1716 | /* documentation says this is not used */ | ||
1717 | GNUNET_break(0); | ||
1718 | break; | ||
1719 | |||
1711 | default: | 1720 | default: |
1712 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1721 | /* unexpected status code */ |
1713 | "Download curl %s%s failed: %s\n", | 1722 | GNUNET_break(0); |
1714 | s5r->domain, | ||
1715 | s5r->url, | ||
1716 | curl_easy_strerror (msg->data.result)); | ||
1717 | /* FIXME: indicate error somehow? close MHD connection badly as well? */ | ||
1718 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; | ||
1719 | if (GNUNET_YES == s5r->suspended) | ||
1720 | { | ||
1721 | MHD_resume_connection (s5r->con); | ||
1722 | s5r->suspended = GNUNET_NO; | ||
1723 | } | ||
1724 | run_mhd_now (s5r->hd); | ||
1725 | break; | 1723 | break; |
1726 | } | 1724 | } |
1727 | if (NULL == s5r->response) | 1725 | } |
1728 | s5r->response = curl_failure_response; | 1726 | ; |
1729 | break; | 1727 | } |
1730 | case CURLMSG_LAST: | 1728 | while (mret == CURLM_CALL_MULTI_PERFORM); |
1731 | /* documentation says this is not used */ | ||
1732 | GNUNET_break (0); | ||
1733 | break; | ||
1734 | default: | ||
1735 | /* unexpected status code */ | ||
1736 | GNUNET_break (0); | ||
1737 | break; | ||
1738 | } | ||
1739 | }; | ||
1740 | } while (mret == CURLM_CALL_MULTI_PERFORM); | ||
1741 | if (CURLM_OK != mret) | 1729 | if (CURLM_OK != mret) |
1742 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1730 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1743 | "%s failed at %s:%d: `%s'\n", | 1731 | "%s failed at %s:%d: `%s'\n", |
1744 | "curl_multi_perform", __FILE__, __LINE__, | 1732 | "curl_multi_perform", __FILE__, __LINE__, |
1745 | curl_multi_strerror (mret)); | 1733 | curl_multi_strerror(mret)); |
1746 | if (0 == running) | 1734 | if (0 == running) |
1747 | { | ||
1748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1749 | "Suspending cURL multi loop, no more events pending\n"); | ||
1750 | if (NULL != curl_download_task) | ||
1751 | { | 1735 | { |
1752 | GNUNET_SCHEDULER_cancel (curl_download_task); | 1736 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1753 | curl_download_task = NULL; | 1737 | "Suspending cURL multi loop, no more events pending\n"); |
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 */ | ||
1754 | } | 1744 | } |
1755 | return; /* nothing more in progress */ | 1745 | curl_download_prepare(); |
1756 | } | ||
1757 | curl_download_prepare (); | ||
1758 | } | 1746 | } |
1759 | 1747 | ||
1760 | 1748 | ||
@@ -1775,28 +1763,28 @@ curl_task_download (void *cls) | |||
1775 | * @return #MHD_YES to continue to iterate | 1763 | * @return #MHD_YES to continue to iterate |
1776 | */ | 1764 | */ |
1777 | static int | 1765 | static int |
1778 | con_val_iter (void *cls, | 1766 | con_val_iter(void *cls, |
1779 | enum MHD_ValueKind kind, | 1767 | enum MHD_ValueKind kind, |
1780 | const char *key, | 1768 | const char *key, |
1781 | const char *value) | 1769 | const char *value) |
1782 | { | 1770 | { |
1783 | struct Socks5Request *s5r = cls; | 1771 | struct Socks5Request *s5r = cls; |
1784 | char *hdr; | 1772 | char *hdr; |
1785 | 1773 | ||
1786 | if ( (0 == strcasecmp (MHD_HTTP_HEADER_HOST, | 1774 | if ((0 == strcasecmp(MHD_HTTP_HEADER_HOST, |
1787 | key)) && | 1775 | key)) && |
1788 | (NULL != s5r->leho) ) | 1776 | (NULL != s5r->leho)) |
1789 | value = s5r->leho; | 1777 | value = s5r->leho; |
1790 | GNUNET_asprintf (&hdr, | 1778 | GNUNET_asprintf(&hdr, |
1791 | "%s: %s", | 1779 | "%s: %s", |
1792 | key, | 1780 | key, |
1793 | value); | 1781 | value); |
1794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1782 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1795 | "Adding HEADER `%s' to HTTP request\n", | 1783 | "Adding HEADER `%s' to HTTP request\n", |
1796 | hdr); | 1784 | hdr); |
1797 | s5r->headers = curl_slist_append (s5r->headers, | 1785 | s5r->headers = curl_slist_append(s5r->headers, |
1798 | hdr); | 1786 | hdr); |
1799 | GNUNET_free (hdr); | 1787 | GNUNET_free(hdr); |
1800 | return MHD_YES; | 1788 | return MHD_YES; |
1801 | } | 1789 | } |
1802 | 1790 | ||
@@ -1825,14 +1813,14 @@ con_val_iter (void *cls, | |||
1825 | * error while handling the request | 1813 | * error while handling the request |
1826 | */ | 1814 | */ |
1827 | static int | 1815 | static int |
1828 | create_response (void *cls, | 1816 | create_response(void *cls, |
1829 | struct MHD_Connection *con, | 1817 | struct MHD_Connection *con, |
1830 | const char *url, | 1818 | const char *url, |
1831 | const char *meth, | 1819 | const char *meth, |
1832 | const char *ver, | 1820 | const char *ver, |
1833 | const char *upload_data, | 1821 | const char *upload_data, |
1834 | size_t *upload_data_size, | 1822 | size_t *upload_data_size, |
1835 | void **con_cls) | 1823 | void **con_cls) |
1836 | { | 1824 | { |
1837 | struct Socks5Request *s5r = *con_cls; | 1825 | struct Socks5Request *s5r = *con_cls; |
1838 | char *curlurl; | 1826 | char *curlurl; |
@@ -1845,412 +1833,415 @@ create_response (void *cls, | |||
1845 | size_t left; | 1833 | size_t left; |
1846 | 1834 | ||
1847 | if (NULL == s5r) | 1835 | if (NULL == s5r) |
1848 | { | 1836 | { |
1849 | GNUNET_break (0); | 1837 | GNUNET_break(0); |
1850 | return MHD_NO; | 1838 | return MHD_NO; |
1851 | } | 1839 | } |
1852 | s5r->con = con; | 1840 | s5r->con = con; |
1853 | /* Fresh connection. */ | 1841 | /* Fresh connection. */ |
1854 | if (SOCKS5_SOCKET_WITH_MHD == s5r->state) | 1842 | if (SOCKS5_SOCKET_WITH_MHD == s5r->state) |
1855 | { | ||
1856 | /* first time here, initialize curl handle */ | ||
1857 | if (s5r->is_gns) | ||
1858 | { | 1843 | { |
1859 | sa = (const struct sockaddr *) &s5r->destination_address; | 1844 | /* first time here, initialize curl handle */ |
1860 | switch (sa->sa_family) | 1845 | if (s5r->is_gns) |
1861 | { | ||
1862 | case AF_INET: | ||
1863 | s4 = (const struct sockaddr_in *) &s5r->destination_address; | ||
1864 | if (NULL == inet_ntop (AF_INET, | ||
1865 | &s4->sin_addr, | ||
1866 | ipstring, | ||
1867 | sizeof (ipstring))) | ||
1868 | { | 1846 | { |
1869 | GNUNET_break (0); | 1847 | sa = (const struct sockaddr *)&s5r->destination_address; |
1870 | return MHD_NO; | 1848 | switch (sa->sa_family) |
1849 | { | ||
1850 | case AF_INET: | ||
1851 | s4 = (const struct sockaddr_in *)&s5r->destination_address; | ||
1852 | if (NULL == inet_ntop(AF_INET, | ||
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 | } | ||
1871 | } | 1888 | } |
1872 | GNUNET_snprintf (ipaddr, | 1889 | else |
1873 | sizeof (ipaddr), | ||
1874 | "%s", | ||
1875 | ipstring); | ||
1876 | port = ntohs (s4->sin_port); | ||
1877 | break; | ||
1878 | case AF_INET6: | ||
1879 | s6 = (const struct sockaddr_in6 *) &s5r->destination_address; | ||
1880 | if (NULL == inet_ntop (AF_INET6, | ||
1881 | &s6->sin6_addr, | ||
1882 | ipstring, | ||
1883 | sizeof (ipstring))) | ||
1884 | { | 1890 | { |
1885 | GNUNET_break (0); | 1891 | port = s5r->port; |
1886 | return MHD_NO; | ||
1887 | } | 1892 | } |
1888 | GNUNET_snprintf (ipaddr, | 1893 | if (NULL == s5r->curl) |
1889 | sizeof (ipaddr), | 1894 | s5r->curl = curl_easy_init(); |
1890 | "%s", | 1895 | if (NULL == s5r->curl) |
1891 | ipstring); | 1896 | return MHD_queue_response(con, |
1892 | port = ntohs (s6->sin6_port); | 1897 | MHD_HTTP_INTERNAL_SERVER_ERROR, |
1893 | break; | 1898 | curl_failure_response); |
1894 | default: | 1899 | curl_easy_setopt(s5r->curl, |
1895 | GNUNET_break (0); | 1900 | CURLOPT_HEADERFUNCTION, |
1896 | return MHD_NO; | 1901 | &curl_check_hdr); |
1897 | } | 1902 | curl_easy_setopt(s5r->curl, |
1898 | } | 1903 | CURLOPT_HEADERDATA, |
1899 | else | 1904 | s5r); |
1900 | { | 1905 | curl_easy_setopt(s5r->curl, |
1901 | port = s5r->port; | 1906 | CURLOPT_FOLLOWLOCATION, |
1902 | } | 1907 | 0); |
1903 | if (NULL == s5r->curl) | 1908 | if (s5r->is_gns) |
1904 | s5r->curl = curl_easy_init (); | 1909 | curl_easy_setopt(s5r->curl, |
1905 | if (NULL == s5r->curl) | 1910 | CURLOPT_IPRESOLVE, |
1906 | return MHD_queue_response (con, | 1911 | CURL_IPRESOLVE_V4); |
1907 | MHD_HTTP_INTERNAL_SERVER_ERROR, | 1912 | curl_easy_setopt(s5r->curl, |
1908 | curl_failure_response); | 1913 | CURLOPT_CONNECTTIMEOUT, |
1909 | curl_easy_setopt (s5r->curl, | 1914 | 600L); |
1910 | CURLOPT_HEADERFUNCTION, | 1915 | curl_easy_setopt(s5r->curl, |
1911 | &curl_check_hdr); | 1916 | CURLOPT_TIMEOUT, |
1912 | curl_easy_setopt (s5r->curl, | 1917 | 600L); |
1913 | CURLOPT_HEADERDATA, | 1918 | curl_easy_setopt(s5r->curl, |
1914 | s5r); | 1919 | CURLOPT_NOSIGNAL, |
1915 | curl_easy_setopt (s5r->curl, | 1920 | 1L); |
1916 | CURLOPT_FOLLOWLOCATION, | 1921 | curl_easy_setopt(s5r->curl, |
1917 | 0); | 1922 | CURLOPT_HTTP_CONTENT_DECODING, |
1918 | if (s5r->is_gns) | 1923 | 0); |
1919 | curl_easy_setopt (s5r->curl, | 1924 | curl_easy_setopt(s5r->curl, |
1920 | CURLOPT_IPRESOLVE, | 1925 | CURLOPT_NOSIGNAL, |
1921 | CURL_IPRESOLVE_V4); | 1926 | 1L); |
1922 | curl_easy_setopt (s5r->curl, | 1927 | curl_easy_setopt(s5r->curl, |
1923 | CURLOPT_CONNECTTIMEOUT, | 1928 | CURLOPT_PRIVATE, |
1924 | 600L); | 1929 | s5r); |
1925 | curl_easy_setopt (s5r->curl, | 1930 | curl_easy_setopt(s5r->curl, |
1926 | CURLOPT_TIMEOUT, | 1931 | CURLOPT_VERBOSE, |
1927 | 600L); | 1932 | 0L); |
1928 | curl_easy_setopt (s5r->curl, | 1933 | /** |
1929 | CURLOPT_NOSIGNAL, | 1934 | * Pre-populate cache to resolve Hostname. |
1930 | 1L); | 1935 | * This is necessary as the DNS name in the CURLOPT_URL is used |
1931 | curl_easy_setopt (s5r->curl, | 1936 | * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication |
1932 | CURLOPT_HTTP_CONTENT_DECODING, | 1937 | */ |
1933 | 0); | 1938 | if (NULL != s5r->leho) |
1934 | curl_easy_setopt (s5r->curl, | ||
1935 | CURLOPT_NOSIGNAL, | ||
1936 | 1L); | ||
1937 | curl_easy_setopt (s5r->curl, | ||
1938 | CURLOPT_PRIVATE, | ||
1939 | s5r); | ||
1940 | curl_easy_setopt (s5r->curl, | ||
1941 | CURLOPT_VERBOSE, | ||
1942 | 0L); | ||
1943 | /** | ||
1944 | * Pre-populate cache to resolve Hostname. | ||
1945 | * This is necessary as the DNS name in the CURLOPT_URL is used | ||
1946 | * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication | ||
1947 | */ | ||
1948 | if (NULL != s5r->leho) | ||
1949 | { | ||
1950 | char *curl_hosts; | ||
1951 | |||
1952 | GNUNET_asprintf (&curl_hosts, | ||
1953 | "%s:%d:%s", | ||
1954 | s5r->leho, | ||
1955 | port, | ||
1956 | ipaddr); | ||
1957 | s5r->hosts = curl_slist_append (NULL, | ||
1958 | curl_hosts); | ||
1959 | curl_easy_setopt (s5r->curl, | ||
1960 | CURLOPT_RESOLVE, | ||
1961 | s5r->hosts); | ||
1962 | GNUNET_free (curl_hosts); | ||
1963 | } | ||
1964 | if (s5r->is_gns) | ||
1965 | { | ||
1966 | GNUNET_asprintf (&curlurl, | ||
1967 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1968 | ? "http://%s:%d%s" | ||
1969 | : "https://%s:%d%s", | ||
1970 | (NULL != s5r->leho) | ||
1971 | ? s5r->leho | ||
1972 | : ipaddr, | ||
1973 | port, | ||
1974 | s5r->url); | ||
1975 | } | ||
1976 | else | ||
1977 | { | ||
1978 | GNUNET_asprintf (&curlurl, | ||
1979 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) | ||
1980 | ? "http://%s:%d%s" | ||
1981 | : "https://%s:%d%s", | ||
1982 | s5r->domain, | ||
1983 | port, | ||
1984 | s5r->url); | ||
1985 | } | ||
1986 | curl_easy_setopt (s5r->curl, | ||
1987 | CURLOPT_URL, | ||
1988 | curlurl); | ||
1989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1990 | "Launching %s CURL interaction, fetching `%s'\n", | ||
1991 | (s5r->is_gns) ? "GNS" : "DNS", | ||
1992 | curlurl); | ||
1993 | GNUNET_free (curlurl); | ||
1994 | if (0 == strcasecmp (meth, | ||
1995 | MHD_HTTP_METHOD_PUT)) | ||
1996 | { | ||
1997 | s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; | ||
1998 | curl_easy_setopt (s5r->curl, | ||
1999 | CURLOPT_UPLOAD, | ||
2000 | 1L); | ||
2001 | curl_easy_setopt (s5r->curl, | ||
2002 | CURLOPT_WRITEFUNCTION, | ||
2003 | &curl_download_cb); | ||
2004 | curl_easy_setopt (s5r->curl, | ||
2005 | CURLOPT_WRITEDATA, | ||
2006 | s5r); | ||
2007 | GNUNET_assert (CURLE_OK == | ||
2008 | curl_easy_setopt (s5r->curl, | ||
2009 | CURLOPT_READFUNCTION, | ||
2010 | &curl_upload_cb)); | ||
2011 | curl_easy_setopt (s5r->curl, | ||
2012 | CURLOPT_READDATA, | ||
2013 | s5r); | ||
2014 | { | ||
2015 | const char *us; | ||
2016 | long upload_size = 0; | ||
2017 | |||
2018 | us = MHD_lookup_connection_value (con, | ||
2019 | MHD_HEADER_KIND, | ||
2020 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
2021 | if ( (1 == sscanf (us, | ||
2022 | "%ld", | ||
2023 | &upload_size)) && | ||
2024 | (upload_size >= 0) ) | ||
2025 | { | 1939 | { |
2026 | curl_easy_setopt (s5r->curl, | 1940 | char *curl_hosts; |
2027 | CURLOPT_INFILESIZE, | 1941 | |
2028 | upload_size); | 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); | ||
2029 | } | 1953 | } |
2030 | } | 1954 | if (s5r->is_gns) |
2031 | } | ||
2032 | else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST)) | ||
2033 | { | ||
2034 | s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; | ||
2035 | curl_easy_setopt (s5r->curl, | ||
2036 | CURLOPT_POST, | ||
2037 | 1L); | ||
2038 | curl_easy_setopt (s5r->curl, | ||
2039 | CURLOPT_WRITEFUNCTION, | ||
2040 | &curl_download_cb); | ||
2041 | curl_easy_setopt (s5r->curl, | ||
2042 | CURLOPT_WRITEDATA, | ||
2043 | s5r); | ||
2044 | curl_easy_setopt (s5r->curl, | ||
2045 | CURLOPT_READFUNCTION, | ||
2046 | &curl_upload_cb); | ||
2047 | curl_easy_setopt (s5r->curl, | ||
2048 | CURLOPT_READDATA, | ||
2049 | s5r); | ||
2050 | { | ||
2051 | const char *us; | ||
2052 | long upload_size; | ||
2053 | |||
2054 | upload_size = 0; | ||
2055 | us = MHD_lookup_connection_value (con, | ||
2056 | MHD_HEADER_KIND, | ||
2057 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
2058 | if ( (NULL != us) && | ||
2059 | (1 == sscanf (us, | ||
2060 | "%ld", | ||
2061 | &upload_size)) && | ||
2062 | (upload_size >= 0) ) | ||
2063 | { | 1955 | { |
2064 | curl_easy_setopt (s5r->curl, | 1956 | GNUNET_asprintf(&curlurl, |
2065 | CURLOPT_INFILESIZE, | 1957 | (GNUNET_YES != s5r->is_tls) //(HTTPS_PORT != s5r->port) |
2066 | upload_size); | 1958 | ? "http://%s:%d%s" |
2067 | } else { | 1959 | : "https://%s:%d%s", |
2068 | curl_easy_setopt (s5r->curl, | 1960 | (NULL != s5r->leho) |
2069 | CURLOPT_INFILESIZE, | 1961 | ? s5r->leho |
2070 | upload_size); | 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 | { | ||
2105 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2106 | curl_easy_setopt(s5r->curl, | ||
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 | } | ||
2116 | else | ||
2117 | { | ||
2118 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2119 | _("Unsupported HTTP method `%s'\n"), | ||
2120 | meth); | ||
2121 | curl_easy_cleanup(s5r->curl); | ||
2122 | s5r->curl = NULL; | ||
2123 | return MHD_NO; | ||
2071 | } | 2124 | } |
2072 | } | ||
2073 | } | ||
2074 | else if (0 == strcasecmp (meth, | ||
2075 | MHD_HTTP_METHOD_HEAD)) | ||
2076 | { | ||
2077 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2078 | curl_easy_setopt (s5r->curl, | ||
2079 | CURLOPT_NOBODY, | ||
2080 | 1L); | ||
2081 | } | ||
2082 | else if (0 == strcasecmp (meth, | ||
2083 | MHD_HTTP_METHOD_OPTIONS)) | ||
2084 | { | ||
2085 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2086 | curl_easy_setopt (s5r->curl, | ||
2087 | CURLOPT_CUSTOMREQUEST, | ||
2088 | "OPTIONS"); | ||
2089 | curl_easy_setopt (s5r->curl, | ||
2090 | CURLOPT_WRITEFUNCTION, | ||
2091 | &curl_download_cb); | ||
2092 | curl_easy_setopt (s5r->curl, | ||
2093 | CURLOPT_WRITEDATA, | ||
2094 | s5r); | ||
2095 | |||
2096 | } | ||
2097 | else if (0 == strcasecmp (meth, | ||
2098 | MHD_HTTP_METHOD_GET)) | ||
2099 | { | ||
2100 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2101 | curl_easy_setopt (s5r->curl, | ||
2102 | CURLOPT_HTTPGET, | ||
2103 | 1L); | ||
2104 | curl_easy_setopt (s5r->curl, | ||
2105 | CURLOPT_WRITEFUNCTION, | ||
2106 | &curl_download_cb); | ||
2107 | curl_easy_setopt (s5r->curl, | ||
2108 | CURLOPT_WRITEDATA, | ||
2109 | s5r); | ||
2110 | } | ||
2111 | else if (0 == strcasecmp (meth, | ||
2112 | MHD_HTTP_METHOD_DELETE)) | ||
2113 | { | ||
2114 | s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; | ||
2115 | curl_easy_setopt (s5r->curl, | ||
2116 | CURLOPT_CUSTOMREQUEST, | ||
2117 | "DELETE"); | ||
2118 | curl_easy_setopt (s5r->curl, | ||
2119 | CURLOPT_WRITEFUNCTION, | ||
2120 | &curl_download_cb); | ||
2121 | curl_easy_setopt (s5r->curl, | ||
2122 | CURLOPT_WRITEDATA, | ||
2123 | s5r); | ||
2124 | } | ||
2125 | else | ||
2126 | { | ||
2127 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2128 | _("Unsupported HTTP method `%s'\n"), | ||
2129 | meth); | ||
2130 | curl_easy_cleanup (s5r->curl); | ||
2131 | s5r->curl = NULL; | ||
2132 | return MHD_NO; | ||
2133 | } | ||
2134 | 2125 | ||
2135 | if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0)) | 2126 | if (0 == strcasecmp(ver, MHD_HTTP_VERSION_1_0)) |
2136 | { | 2127 | { |
2137 | curl_easy_setopt (s5r->curl, | 2128 | curl_easy_setopt(s5r->curl, |
2138 | CURLOPT_HTTP_VERSION, | 2129 | CURLOPT_HTTP_VERSION, |
2139 | CURL_HTTP_VERSION_1_0); | 2130 | CURL_HTTP_VERSION_1_0); |
2140 | } | 2131 | } |
2141 | else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1)) | 2132 | else if (0 == strcasecmp(ver, MHD_HTTP_VERSION_1_1)) |
2142 | { | 2133 | { |
2143 | curl_easy_setopt (s5r->curl, | 2134 | curl_easy_setopt(s5r->curl, |
2144 | CURLOPT_HTTP_VERSION, | 2135 | CURLOPT_HTTP_VERSION, |
2145 | CURL_HTTP_VERSION_1_1); | 2136 | CURL_HTTP_VERSION_1_1); |
2146 | } | 2137 | } |
2147 | else | 2138 | else |
2148 | { | 2139 | { |
2149 | curl_easy_setopt (s5r->curl, | 2140 | curl_easy_setopt(s5r->curl, |
2150 | CURLOPT_HTTP_VERSION, | 2141 | CURLOPT_HTTP_VERSION, |
2151 | CURL_HTTP_VERSION_NONE); | 2142 | CURL_HTTP_VERSION_NONE); |
2152 | } | 2143 | } |
2153 | 2144 | ||
2154 | if (GNUNET_YES == s5r->is_tls) //(HTTPS_PORT == s5r->port) | 2145 | if (GNUNET_YES == s5r->is_tls) //(HTTPS_PORT == s5r->port) |
2155 | { | 2146 | { |
2156 | curl_easy_setopt (s5r->curl, | 2147 | curl_easy_setopt(s5r->curl, |
2157 | CURLOPT_USE_SSL, | 2148 | CURLOPT_USE_SSL, |
2158 | CURLUSESSL_ALL); | 2149 | CURLUSESSL_ALL); |
2159 | if (0 < s5r->num_danes) | 2150 | if (0 < s5r->num_danes) |
2160 | curl_easy_setopt (s5r->curl, | 2151 | curl_easy_setopt(s5r->curl, |
2161 | CURLOPT_SSL_VERIFYPEER, | 2152 | CURLOPT_SSL_VERIFYPEER, |
2162 | 0L); | 2153 | 0L); |
2154 | else | ||
2155 | curl_easy_setopt(s5r->curl, | ||
2156 | CURLOPT_SSL_VERIFYPEER, | ||
2157 | 1L); | ||
2158 | /* Disable cURL checking the hostname, as we will check ourselves | ||
2159 | as only we have the domain name or the LEHO or the DANE record */ | ||
2160 | curl_easy_setopt(s5r->curl, | ||
2161 | CURLOPT_SSL_VERIFYHOST, | ||
2162 | 0L); | ||
2163 | } | ||
2163 | else | 2164 | else |
2164 | curl_easy_setopt (s5r->curl, | 2165 | { |
2165 | CURLOPT_SSL_VERIFYPEER, | 2166 | curl_easy_setopt(s5r->curl, |
2166 | 1L); | 2167 | CURLOPT_USE_SSL, |
2167 | /* Disable cURL checking the hostname, as we will check ourselves | 2168 | CURLUSESSL_NONE); |
2168 | as only we have the domain name or the LEHO or the DANE record */ | 2169 | } |
2169 | curl_easy_setopt (s5r->curl, | ||
2170 | CURLOPT_SSL_VERIFYHOST, | ||
2171 | 0L); | ||
2172 | } | ||
2173 | else | ||
2174 | { | ||
2175 | curl_easy_setopt (s5r->curl, | ||
2176 | CURLOPT_USE_SSL, | ||
2177 | CURLUSESSL_NONE); | ||
2178 | } | ||
2179 | 2170 | ||
2180 | if (CURLM_OK != | 2171 | if (CURLM_OK != |
2181 | curl_multi_add_handle (curl_multi, | 2172 | curl_multi_add_handle(curl_multi, |
2182 | s5r->curl)) | 2173 | s5r->curl)) |
2183 | { | 2174 | { |
2184 | GNUNET_break (0); | 2175 | GNUNET_break(0); |
2185 | curl_easy_cleanup (s5r->curl); | 2176 | curl_easy_cleanup(s5r->curl); |
2186 | s5r->curl = NULL; | 2177 | s5r->curl = NULL; |
2187 | return MHD_NO; | 2178 | 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; | ||
2188 | } | 2189 | } |
2189 | MHD_get_connection_values (con, | ||
2190 | MHD_HEADER_KIND, | ||
2191 | (MHD_KeyValueIterator) &con_val_iter, | ||
2192 | s5r); | ||
2193 | curl_easy_setopt (s5r->curl, | ||
2194 | CURLOPT_HTTPHEADER, | ||
2195 | s5r->headers); | ||
2196 | curl_download_prepare (); | ||
2197 | return MHD_YES; | ||
2198 | } | ||
2199 | 2190 | ||
2200 | /* continuing to process request */ | 2191 | /* continuing to process request */ |
2201 | if (0 != *upload_data_size) | 2192 | if (0 != *upload_data_size) |
2202 | { | ||
2203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2204 | "Processing %u bytes UPLOAD\n", | ||
2205 | (unsigned int) *upload_data_size); | ||
2206 | |||
2207 | /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else | ||
2208 | * upload callback is not called! | ||
2209 | */ | ||
2210 | curl_easy_setopt (s5r->curl, | ||
2211 | CURLOPT_POSTFIELDSIZE, | ||
2212 | *upload_data_size); | ||
2213 | |||
2214 | left = GNUNET_MIN (*upload_data_size, | ||
2215 | sizeof (s5r->io_buf) - s5r->io_len); | ||
2216 | GNUNET_memcpy (&s5r->io_buf[s5r->io_len], | ||
2217 | upload_data, | ||
2218 | left); | ||
2219 | s5r->io_len += left; | ||
2220 | *upload_data_size -= left; | ||
2221 | GNUNET_assert (NULL != s5r->curl); | ||
2222 | if (GNUNET_YES == s5r->curl_paused) | ||
2223 | { | 2193 | { |
2224 | s5r->curl_paused = GNUNET_NO; | 2194 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2225 | curl_easy_pause (s5r->curl, | 2195 | "Processing %u bytes UPLOAD\n", |
2226 | CURLPAUSE_CONT); | 2196 | (unsigned int)*upload_data_size); |
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; | ||
2227 | } | 2220 | } |
2228 | return MHD_YES; | ||
2229 | } | ||
2230 | if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) | 2221 | if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) |
2231 | { | 2222 | { |
2232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2233 | "Finished processing UPLOAD\n"); | 2224 | "Finished processing UPLOAD\n"); |
2234 | s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; | 2225 | s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; |
2235 | } | 2226 | } |
2236 | if (NULL == s5r->response) | 2227 | if (NULL == s5r->response) |
2237 | { | 2228 | { |
2238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2229 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2239 | "Waiting for HTTP response for %s%s...\n", | 2230 | "Waiting for HTTP response for %s%s...\n", |
2240 | s5r->domain, | 2231 | s5r->domain, |
2241 | s5r->url); | 2232 | s5r->url); |
2242 | MHD_suspend_connection (con); | 2233 | MHD_suspend_connection(con); |
2243 | s5r->suspended = GNUNET_YES; | 2234 | s5r->suspended = GNUNET_YES; |
2244 | return MHD_YES; | 2235 | return MHD_YES; |
2245 | } | 2236 | } |
2246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2237 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2247 | "Queueing response for %s%s with MHD\n", | 2238 | "Queueing response for %s%s with MHD\n", |
2248 | s5r->domain, | 2239 | s5r->domain, |
2249 | s5r->url); | 2240 | s5r->url); |
2250 | run_mhd_now (s5r->hd); | 2241 | run_mhd_now(s5r->hd); |
2251 | return MHD_queue_response (con, | 2242 | return MHD_queue_response(con, |
2252 | s5r->response_code, | 2243 | s5r->response_code, |
2253 | s5r->response); | 2244 | s5r->response); |
2254 | } | 2245 | } |
2255 | 2246 | ||
2256 | 2247 | ||
@@ -2267,51 +2258,51 @@ create_response (void *cls, | |||
2267 | * @param toe reason for request termination (ignored) | 2258 | * @param toe reason for request termination (ignored) |
2268 | */ | 2259 | */ |
2269 | static void | 2260 | static void |
2270 | mhd_completed_cb (void *cls, | 2261 | mhd_completed_cb(void *cls, |
2271 | struct MHD_Connection *connection, | 2262 | struct MHD_Connection *connection, |
2272 | void **con_cls, | 2263 | void **con_cls, |
2273 | enum MHD_RequestTerminationCode toe) | 2264 | enum MHD_RequestTerminationCode toe) |
2274 | { | 2265 | { |
2275 | struct Socks5Request *s5r = *con_cls; | 2266 | struct Socks5Request *s5r = *con_cls; |
2276 | 2267 | ||
2277 | if (NULL == s5r) | 2268 | if (NULL == s5r) |
2278 | return; | 2269 | return; |
2279 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) | 2270 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) |
2280 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2271 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2281 | "MHD encountered error handling request: %d\n", | 2272 | "MHD encountered error handling request: %d\n", |
2282 | toe); | 2273 | toe); |
2283 | if (NULL != s5r->curl) | 2274 | if (NULL != s5r->curl) |
2284 | { | 2275 | { |
2285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2286 | "Removing cURL handle (MHD interaction complete)\n"); | 2277 | "Removing cURL handle (MHD interaction complete)\n"); |
2287 | curl_multi_remove_handle (curl_multi, | 2278 | curl_multi_remove_handle(curl_multi, |
2288 | s5r->curl); | 2279 | s5r->curl); |
2289 | curl_slist_free_all (s5r->headers); | 2280 | curl_slist_free_all(s5r->headers); |
2290 | s5r->headers = NULL; | 2281 | s5r->headers = NULL; |
2291 | curl_easy_reset (s5r->curl); | 2282 | curl_easy_reset(s5r->curl); |
2292 | s5r->rbuf_len = 0; | 2283 | s5r->rbuf_len = 0; |
2293 | s5r->wbuf_len = 0; | 2284 | s5r->wbuf_len = 0; |
2294 | s5r->io_len = 0; | 2285 | s5r->io_len = 0; |
2295 | curl_download_prepare (); | 2286 | curl_download_prepare(); |
2296 | } | 2287 | } |
2297 | if ( (NULL != s5r->response) && | 2288 | if ((NULL != s5r->response) && |
2298 | (curl_failure_response != s5r->response) ) | 2289 | (curl_failure_response != s5r->response)) |
2299 | MHD_destroy_response (s5r->response); | 2290 | MHD_destroy_response(s5r->response); |
2300 | for (struct HttpResponseHeader *header = s5r->header_head; | 2291 | for (struct HttpResponseHeader *header = s5r->header_head; |
2301 | NULL != header; | 2292 | NULL != header; |
2302 | header = s5r->header_head) | 2293 | header = s5r->header_head) |
2303 | { | 2294 | { |
2304 | GNUNET_CONTAINER_DLL_remove (s5r->header_head, | 2295 | GNUNET_CONTAINER_DLL_remove(s5r->header_head, |
2305 | s5r->header_tail, | 2296 | s5r->header_tail, |
2306 | header); | 2297 | header); |
2307 | GNUNET_free (header->type); | 2298 | GNUNET_free(header->type); |
2308 | GNUNET_free (header->value); | 2299 | GNUNET_free(header->value); |
2309 | GNUNET_free (header); | 2300 | GNUNET_free(header); |
2310 | } | 2301 | } |
2311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2302 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2312 | "Finished request for %s\n", | 2303 | "Finished request for %s\n", |
2313 | s5r->url); | 2304 | s5r->url); |
2314 | GNUNET_free (s5r->url); | 2305 | GNUNET_free(s5r->url); |
2315 | s5r->state = SOCKS5_SOCKET_WITH_MHD; | 2306 | s5r->state = SOCKS5_SOCKET_WITH_MHD; |
2316 | s5r->url = NULL; | 2307 | s5r->url = NULL; |
2317 | s5r->response = NULL; | 2308 | s5r->response = NULL; |
@@ -2329,56 +2320,58 @@ mhd_completed_cb (void *cls, | |||
2329 | * @param toe connection notification type | 2320 | * @param toe connection notification type |
2330 | */ | 2321 | */ |
2331 | static void | 2322 | static void |
2332 | mhd_connection_cb (void *cls, | 2323 | mhd_connection_cb(void *cls, |
2333 | struct MHD_Connection *connection, | 2324 | struct MHD_Connection *connection, |
2334 | void **con_cls, | 2325 | void **con_cls, |
2335 | enum MHD_ConnectionNotificationCode cnc) | 2326 | enum MHD_ConnectionNotificationCode cnc) |
2336 | { | 2327 | { |
2337 | struct Socks5Request *s5r; | 2328 | struct Socks5Request *s5r; |
2338 | const union MHD_ConnectionInfo *ci; | 2329 | const union MHD_ConnectionInfo *ci; |
2339 | int sock; | 2330 | int sock; |
2340 | 2331 | ||
2341 | switch (cnc) | 2332 | switch (cnc) |
2342 | { | 2333 | { |
2343 | case MHD_CONNECTION_NOTIFY_STARTED: | 2334 | case MHD_CONNECTION_NOTIFY_STARTED: |
2344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection started...\n"); | 2335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connection started...\n"); |
2345 | ci = MHD_get_connection_info (connection, | 2336 | ci = MHD_get_connection_info(connection, |
2346 | MHD_CONNECTION_INFO_CONNECTION_FD); | 2337 | MHD_CONNECTION_INFO_CONNECTION_FD); |
2347 | if (NULL == ci) | 2338 | if (NULL == ci) |
2348 | { | 2339 | { |
2349 | GNUNET_break (0); | 2340 | GNUNET_break(0); |
2350 | return; | 2341 | return; |
2351 | } | 2342 | } |
2352 | sock = ci->connect_fd; | 2343 | sock = ci->connect_fd; |
2353 | for (s5r = s5r_head; NULL != s5r; s5r = s5r->next) | 2344 | for (s5r = s5r_head; NULL != s5r; s5r = s5r->next) |
2354 | { | ||
2355 | if (GNUNET_NETWORK_get_fd (s5r->sock) == sock) | ||
2356 | { | 2345 | { |
2357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2346 | if (GNUNET_NETWORK_get_fd(s5r->sock) == sock) |
2358 | "Context set...\n"); | 2347 | { |
2359 | s5r->ssl_checked = GNUNET_NO; | 2348 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2360 | *con_cls = s5r; | 2349 | "Context set...\n"); |
2361 | break; | 2350 | s5r->ssl_checked = GNUNET_NO; |
2351 | *con_cls = s5r; | ||
2352 | break; | ||
2353 | } | ||
2362 | } | 2354 | } |
2363 | } | ||
2364 | break; | 2355 | break; |
2356 | |||
2365 | case MHD_CONNECTION_NOTIFY_CLOSED: | 2357 | case MHD_CONNECTION_NOTIFY_CLOSED: |
2366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2367 | "Connection closed... cleaning up\n"); | 2359 | "Connection closed... cleaning up\n"); |
2368 | s5r = *con_cls; | 2360 | s5r = *con_cls; |
2369 | if (NULL == s5r) | 2361 | if (NULL == s5r) |
2370 | { | 2362 | { |
2371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2363 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2372 | "Connection stale!\n"); | 2364 | "Connection stale!\n"); |
2373 | return; | 2365 | return; |
2374 | } | 2366 | } |
2375 | cleanup_s5r (s5r); | 2367 | cleanup_s5r(s5r); |
2376 | curl_download_prepare (); | 2368 | curl_download_prepare(); |
2377 | *con_cls = NULL; | 2369 | *con_cls = NULL; |
2378 | break; | 2370 | break; |
2371 | |||
2379 | default: | 2372 | default: |
2380 | GNUNET_break (0); | 2373 | GNUNET_break(0); |
2381 | } | 2374 | } |
2382 | } | 2375 | } |
2383 | 2376 | ||
2384 | /** | 2377 | /** |
@@ -2395,34 +2388,34 @@ mhd_connection_cb (void *cls, | |||
2395 | * @return the `struct Socks5Request` that this @a connection is for | 2388 | * @return the `struct Socks5Request` that this @a connection is for |
2396 | */ | 2389 | */ |
2397 | static void * | 2390 | static void * |
2398 | mhd_log_callback (void *cls, | 2391 | mhd_log_callback(void *cls, |
2399 | const char *url, | 2392 | const char *url, |
2400 | struct MHD_Connection *connection) | 2393 | struct MHD_Connection *connection) |
2401 | { | 2394 | { |
2402 | struct Socks5Request *s5r; | 2395 | struct Socks5Request *s5r; |
2403 | const union MHD_ConnectionInfo *ci; | 2396 | const union MHD_ConnectionInfo *ci; |
2404 | 2397 | ||
2405 | ci = MHD_get_connection_info (connection, | 2398 | ci = MHD_get_connection_info(connection, |
2406 | MHD_CONNECTION_INFO_SOCKET_CONTEXT); | 2399 | MHD_CONNECTION_INFO_SOCKET_CONTEXT); |
2407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing %s\n", url); | 2400 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing %s\n", url); |
2408 | if (NULL == ci) | 2401 | if (NULL == ci) |
2409 | { | 2402 | { |
2410 | GNUNET_break (0); | 2403 | GNUNET_break(0); |
2411 | return NULL; | 2404 | return NULL; |
2412 | } | 2405 | } |
2413 | s5r = ci->socket_context; | 2406 | s5r = ci->socket_context; |
2414 | if (NULL != s5r->url) | 2407 | if (NULL != s5r->url) |
2415 | { | 2408 | { |
2416 | GNUNET_break (0); | 2409 | GNUNET_break(0); |
2417 | return NULL; | 2410 | return NULL; |
2418 | } | 2411 | } |
2419 | s5r->url = GNUNET_strdup (url); | 2412 | s5r->url = GNUNET_strdup(url); |
2420 | if (NULL != s5r->timeout_task) | 2413 | if (NULL != s5r->timeout_task) |
2421 | { | 2414 | { |
2422 | GNUNET_SCHEDULER_cancel (s5r->timeout_task); | 2415 | GNUNET_SCHEDULER_cancel(s5r->timeout_task); |
2423 | s5r->timeout_task = NULL; | 2416 | s5r->timeout_task = NULL; |
2424 | } | 2417 | } |
2425 | GNUNET_assert (s5r->state == SOCKS5_SOCKET_WITH_MHD); | 2418 | GNUNET_assert(s5r->state == SOCKS5_SOCKET_WITH_MHD); |
2426 | return s5r; | 2419 | return s5r; |
2427 | } | 2420 | } |
2428 | 2421 | ||
@@ -2433,22 +2426,22 @@ mhd_log_callback (void *cls, | |||
2433 | * @param hd daemon to stop | 2426 | * @param hd daemon to stop |
2434 | */ | 2427 | */ |
2435 | static void | 2428 | static void |
2436 | kill_httpd (struct MhdHttpList *hd) | 2429 | kill_httpd(struct MhdHttpList *hd) |
2437 | { | 2430 | { |
2438 | GNUNET_CONTAINER_DLL_remove (mhd_httpd_head, | 2431 | GNUNET_CONTAINER_DLL_remove(mhd_httpd_head, |
2439 | mhd_httpd_tail, | 2432 | mhd_httpd_tail, |
2440 | hd); | 2433 | hd); |
2441 | GNUNET_free_non_null (hd->domain); | 2434 | GNUNET_free_non_null(hd->domain); |
2442 | MHD_stop_daemon (hd->daemon); | 2435 | MHD_stop_daemon(hd->daemon); |
2443 | if (NULL != hd->httpd_task) | 2436 | if (NULL != hd->httpd_task) |
2444 | { | 2437 | { |
2445 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 2438 | GNUNET_SCHEDULER_cancel(hd->httpd_task); |
2446 | hd->httpd_task = NULL; | 2439 | hd->httpd_task = NULL; |
2447 | } | 2440 | } |
2448 | GNUNET_free_non_null (hd->proxy_cert); | 2441 | GNUNET_free_non_null(hd->proxy_cert); |
2449 | if (hd == httpd) | 2442 | if (hd == httpd) |
2450 | httpd = NULL; | 2443 | httpd = NULL; |
2451 | GNUNET_free (hd); | 2444 | GNUNET_free(hd); |
2452 | } | 2445 | } |
2453 | 2446 | ||
2454 | 2447 | ||
@@ -2458,12 +2451,12 @@ kill_httpd (struct MhdHttpList *hd) | |||
2458 | * @param cls the `struct MhdHttpList *` | 2451 | * @param cls the `struct MhdHttpList *` |
2459 | */ | 2452 | */ |
2460 | static void | 2453 | static void |
2461 | kill_httpd_task (void *cls) | 2454 | kill_httpd_task(void *cls) |
2462 | { | 2455 | { |
2463 | struct MhdHttpList *hd = cls; | 2456 | struct MhdHttpList *hd = cls; |
2464 | 2457 | ||
2465 | hd->httpd_task = NULL; | 2458 | hd->httpd_task = NULL; |
2466 | kill_httpd (hd); | 2459 | kill_httpd(hd); |
2467 | } | 2460 | } |
2468 | 2461 | ||
2469 | 2462 | ||
@@ -2473,7 +2466,7 @@ kill_httpd_task (void *cls) | |||
2473 | * @param cls the `struct MhdHttpList *` of the daemon that is being run | 2466 | * @param cls the `struct MhdHttpList *` of the daemon that is being run |
2474 | */ | 2467 | */ |
2475 | static void | 2468 | static void |
2476 | do_httpd (void *cls); | 2469 | do_httpd(void *cls); |
2477 | 2470 | ||
2478 | 2471 | ||
2479 | /** | 2472 | /** |
@@ -2484,7 +2477,7 @@ do_httpd (void *cls); | |||
2484 | * @param hd the daemon to schedule | 2477 | * @param hd the daemon to schedule |
2485 | */ | 2478 | */ |
2486 | static void | 2479 | static void |
2487 | schedule_httpd (struct MhdHttpList *hd) | 2480 | schedule_httpd(struct MhdHttpList *hd) |
2488 | { | 2481 | { |
2489 | fd_set rs; | 2482 | fd_set rs; |
2490 | fd_set ws; | 2483 | fd_set ws; |
@@ -2496,63 +2489,63 @@ schedule_httpd (struct MhdHttpList *hd) | |||
2496 | MHD_UNSIGNED_LONG_LONG timeout; | 2489 | MHD_UNSIGNED_LONG_LONG timeout; |
2497 | struct GNUNET_TIME_Relative tv; | 2490 | struct GNUNET_TIME_Relative tv; |
2498 | 2491 | ||
2499 | FD_ZERO (&rs); | 2492 | FD_ZERO(&rs); |
2500 | FD_ZERO (&ws); | 2493 | FD_ZERO(&ws); |
2501 | FD_ZERO (&es); | 2494 | FD_ZERO(&es); |
2502 | max = -1; | 2495 | max = -1; |
2503 | if (MHD_YES != | 2496 | if (MHD_YES != |
2504 | MHD_get_fdset (hd->daemon, | 2497 | MHD_get_fdset(hd->daemon, |
2505 | &rs, | 2498 | &rs, |
2506 | &ws, | 2499 | &ws, |
2507 | &es, | 2500 | &es, |
2508 | &max)) | 2501 | &max)) |
2509 | { | 2502 | { |
2510 | kill_httpd (hd); | 2503 | kill_httpd(hd); |
2511 | return; | 2504 | return; |
2512 | } | 2505 | } |
2513 | haveto = MHD_get_timeout (hd->daemon, | 2506 | haveto = MHD_get_timeout(hd->daemon, |
2514 | &timeout); | 2507 | &timeout); |
2515 | if (MHD_YES == haveto) | 2508 | if (MHD_YES == haveto) |
2516 | tv.rel_value_us = (uint64_t) timeout * 1000LL; | 2509 | tv.rel_value_us = (uint64_t)timeout * 1000LL; |
2517 | else | 2510 | else |
2518 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 2511 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
2519 | if (-1 != max) | 2512 | if (-1 != max) |
2520 | { | 2513 | { |
2521 | wrs = GNUNET_NETWORK_fdset_create (); | 2514 | wrs = GNUNET_NETWORK_fdset_create(); |
2522 | wws = GNUNET_NETWORK_fdset_create (); | 2515 | wws = GNUNET_NETWORK_fdset_create(); |
2523 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | 2516 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); |
2524 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 2517 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); |
2525 | } | 2518 | } |
2526 | else | 2519 | else |
2527 | { | 2520 | { |
2528 | wrs = NULL; | 2521 | wrs = NULL; |
2529 | wws = NULL; | 2522 | wws = NULL; |
2530 | } | 2523 | } |
2531 | if (NULL != hd->httpd_task) | 2524 | if (NULL != hd->httpd_task) |
2532 | { | 2525 | { |
2533 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 2526 | GNUNET_SCHEDULER_cancel(hd->httpd_task); |
2534 | hd->httpd_task = NULL; | 2527 | hd->httpd_task = NULL; |
2535 | } | 2528 | } |
2536 | if ( (MHD_YES != haveto) && | 2529 | if ((MHD_YES != haveto) && |
2537 | (-1 == max) && | 2530 | (-1 == max) && |
2538 | (hd != httpd) ) | 2531 | (hd != httpd)) |
2539 | { | 2532 | { |
2540 | /* daemon is idle, kill after timeout */ | 2533 | /* daemon is idle, kill after timeout */ |
2541 | hd->httpd_task = GNUNET_SCHEDULER_add_delayed (MHD_CACHE_TIMEOUT, | 2534 | hd->httpd_task = GNUNET_SCHEDULER_add_delayed(MHD_CACHE_TIMEOUT, |
2542 | &kill_httpd_task, | 2535 | &kill_httpd_task, |
2543 | hd); | 2536 | hd); |
2544 | } | 2537 | } |
2545 | else | 2538 | else |
2546 | { | 2539 | { |
2547 | hd->httpd_task = | 2540 | hd->httpd_task = |
2548 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 2541 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
2549 | tv, wrs, wws, | 2542 | tv, wrs, wws, |
2550 | &do_httpd, hd); | 2543 | &do_httpd, hd); |
2551 | } | 2544 | } |
2552 | if (NULL != wrs) | 2545 | if (NULL != wrs) |
2553 | GNUNET_NETWORK_fdset_destroy (wrs); | 2546 | GNUNET_NETWORK_fdset_destroy(wrs); |
2554 | if (NULL != wws) | 2547 | if (NULL != wws) |
2555 | GNUNET_NETWORK_fdset_destroy (wws); | 2548 | GNUNET_NETWORK_fdset_destroy(wws); |
2556 | } | 2549 | } |
2557 | 2550 | ||
2558 | 2551 | ||
@@ -2562,13 +2555,13 @@ schedule_httpd (struct MhdHttpList *hd) | |||
2562 | * @param cls the `struct MhdHttpList` of the daemon that is being run | 2555 | * @param cls the `struct MhdHttpList` of the daemon that is being run |
2563 | */ | 2556 | */ |
2564 | static void | 2557 | static void |
2565 | do_httpd (void *cls) | 2558 | do_httpd(void *cls) |
2566 | { | 2559 | { |
2567 | struct MhdHttpList *hd = cls; | 2560 | struct MhdHttpList *hd = cls; |
2568 | 2561 | ||
2569 | hd->httpd_task = NULL; | 2562 | hd->httpd_task = NULL; |
2570 | MHD_run (hd->daemon); | 2563 | MHD_run(hd->daemon); |
2571 | schedule_httpd (hd); | 2564 | schedule_httpd(hd); |
2572 | } | 2565 | } |
2573 | 2566 | ||
2574 | 2567 | ||
@@ -2578,12 +2571,12 @@ do_httpd (void *cls) | |||
2578 | * @param hd the daemon to run now. | 2571 | * @param hd the daemon to run now. |
2579 | */ | 2572 | */ |
2580 | static void | 2573 | static void |
2581 | run_mhd_now (struct MhdHttpList *hd) | 2574 | run_mhd_now(struct MhdHttpList *hd) |
2582 | { | 2575 | { |
2583 | if (NULL != hd->httpd_task) | 2576 | if (NULL != hd->httpd_task) |
2584 | GNUNET_SCHEDULER_cancel (hd->httpd_task); | 2577 | GNUNET_SCHEDULER_cancel(hd->httpd_task); |
2585 | hd->httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, | 2578 | hd->httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, |
2586 | hd); | 2579 | hd); |
2587 | } | 2580 | } |
2588 | 2581 | ||
2589 | 2582 | ||
@@ -2595,30 +2588,30 @@ run_mhd_now (struct MhdHttpList *hd) | |||
2595 | * @return NULL on error | 2588 | * @return NULL on error |
2596 | */ | 2589 | */ |
2597 | static void* | 2590 | static void* |
2598 | load_file (const char* filename, | 2591 | load_file(const char* filename, |
2599 | unsigned int* size) | 2592 | unsigned int* size) |
2600 | { | 2593 | { |
2601 | void *buffer; | 2594 | void *buffer; |
2602 | uint64_t fsize; | 2595 | uint64_t fsize; |
2603 | 2596 | ||
2604 | if (GNUNET_OK != | 2597 | if (GNUNET_OK != |
2605 | GNUNET_DISK_file_size (filename, | 2598 | GNUNET_DISK_file_size(filename, |
2606 | &fsize, | 2599 | &fsize, |
2607 | GNUNET_YES, | 2600 | GNUNET_YES, |
2608 | GNUNET_YES)) | 2601 | GNUNET_YES)) |
2609 | return NULL; | 2602 | return NULL; |
2610 | if (fsize > MAX_PEM_SIZE) | 2603 | if (fsize > MAX_PEM_SIZE) |
2611 | return NULL; | 2604 | return NULL; |
2612 | *size = (unsigned int) fsize; | 2605 | *size = (unsigned int)fsize; |
2613 | buffer = GNUNET_malloc (*size); | 2606 | buffer = GNUNET_malloc(*size); |
2614 | if (fsize != | 2607 | if (fsize != |
2615 | GNUNET_DISK_fn_read (filename, | 2608 | GNUNET_DISK_fn_read(filename, |
2616 | buffer, | 2609 | buffer, |
2617 | (size_t) fsize)) | 2610 | (size_t)fsize)) |
2618 | { | 2611 | { |
2619 | GNUNET_free (buffer); | 2612 | GNUNET_free(buffer); |
2620 | return NULL; | 2613 | return NULL; |
2621 | } | 2614 | } |
2622 | return buffer; | 2615 | return buffer; |
2623 | } | 2616 | } |
2624 | 2617 | ||
@@ -2631,25 +2624,25 @@ load_file (const char* filename, | |||
2631 | * @return #GNUNET_OK on success | 2624 | * @return #GNUNET_OK on success |
2632 | */ | 2625 | */ |
2633 | static int | 2626 | static int |
2634 | load_key_from_file (gnutls_x509_privkey_t key, | 2627 | load_key_from_file(gnutls_x509_privkey_t key, |
2635 | const char* keyfile) | 2628 | const char* keyfile) |
2636 | { | 2629 | { |
2637 | gnutls_datum_t key_data; | 2630 | gnutls_datum_t key_data; |
2638 | int ret; | 2631 | int ret; |
2639 | 2632 | ||
2640 | key_data.data = load_file (keyfile, | 2633 | key_data.data = load_file(keyfile, |
2641 | &key_data.size); | 2634 | &key_data.size); |
2642 | if (NULL == key_data.data) | 2635 | if (NULL == key_data.data) |
2643 | return GNUNET_SYSERR; | 2636 | return GNUNET_SYSERR; |
2644 | ret = gnutls_x509_privkey_import (key, &key_data, | 2637 | ret = gnutls_x509_privkey_import(key, &key_data, |
2645 | GNUTLS_X509_FMT_PEM); | 2638 | GNUTLS_X509_FMT_PEM); |
2646 | if (GNUTLS_E_SUCCESS != ret) | 2639 | if (GNUTLS_E_SUCCESS != ret) |
2647 | { | 2640 | { |
2648 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2641 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2649 | _("Unable to import private key from file `%s'\n"), | 2642 | _("Unable to import private key from file `%s'\n"), |
2650 | keyfile); | 2643 | keyfile); |
2651 | } | 2644 | } |
2652 | GNUNET_free_non_null (key_data.data); | 2645 | GNUNET_free_non_null(key_data.data); |
2653 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 2646 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
2654 | } | 2647 | } |
2655 | 2648 | ||
@@ -2662,26 +2655,26 @@ load_key_from_file (gnutls_x509_privkey_t key, | |||
2662 | * @return #GNUNET_OK on success | 2655 | * @return #GNUNET_OK on success |
2663 | */ | 2656 | */ |
2664 | static int | 2657 | static int |
2665 | load_cert_from_file (gnutls_x509_crt_t crt, | 2658 | load_cert_from_file(gnutls_x509_crt_t crt, |
2666 | const char* certfile) | 2659 | const char* certfile) |
2667 | { | 2660 | { |
2668 | gnutls_datum_t cert_data; | 2661 | gnutls_datum_t cert_data; |
2669 | int ret; | 2662 | int ret; |
2670 | 2663 | ||
2671 | cert_data.data = load_file (certfile, | 2664 | cert_data.data = load_file(certfile, |
2672 | &cert_data.size); | 2665 | &cert_data.size); |
2673 | if (NULL == cert_data.data) | 2666 | if (NULL == cert_data.data) |
2674 | return GNUNET_SYSERR; | 2667 | return GNUNET_SYSERR; |
2675 | ret = gnutls_x509_crt_import (crt, | 2668 | ret = gnutls_x509_crt_import(crt, |
2676 | &cert_data, | 2669 | &cert_data, |
2677 | GNUTLS_X509_FMT_PEM); | 2670 | GNUTLS_X509_FMT_PEM); |
2678 | if (GNUTLS_E_SUCCESS != ret) | 2671 | if (GNUTLS_E_SUCCESS != ret) |
2679 | { | 2672 | { |
2680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2673 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2681 | _("Unable to import certificate from `%s'\n"), | 2674 | _("Unable to import certificate from `%s'\n"), |
2682 | certfile); | 2675 | certfile); |
2683 | } | 2676 | } |
2684 | GNUNET_free_non_null (cert_data.data); | 2677 | GNUNET_free_non_null(cert_data.data); |
2685 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 2678 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
2686 | } | 2679 | } |
2687 | 2680 | ||
@@ -2693,7 +2686,7 @@ load_cert_from_file (gnutls_x509_crt_t crt, | |||
2693 | * @return a struct holding the PEM data, NULL on error | 2686 | * @return a struct holding the PEM data, NULL on error |
2694 | */ | 2687 | */ |
2695 | static struct ProxyGNSCertificate * | 2688 | static struct ProxyGNSCertificate * |
2696 | generate_gns_certificate (const char *name) | 2689 | generate_gns_certificate(const char *name) |
2697 | { | 2690 | { |
2698 | unsigned int serial; | 2691 | unsigned int serial; |
2699 | size_t key_buf_size; | 2692 | size_t key_buf_size; |
@@ -2703,65 +2696,65 @@ generate_gns_certificate (const char *name) | |||
2703 | struct tm *tm_data; | 2696 | struct tm *tm_data; |
2704 | struct ProxyGNSCertificate *pgc; | 2697 | struct ProxyGNSCertificate *pgc; |
2705 | 2698 | ||
2706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2707 | "Generating x.509 certificate for `%s'\n", | 2700 | "Generating x.509 certificate for `%s'\n", |
2708 | name); | 2701 | name); |
2709 | GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_init (&request)); | 2702 | GNUNET_break(GNUTLS_E_SUCCESS == gnutls_x509_crt_init(&request)); |
2710 | GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key (request, proxy_ca.key)); | 2703 | GNUNET_break(GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key(request, proxy_ca.key)); |
2711 | pgc = GNUNET_new (struct ProxyGNSCertificate); | 2704 | pgc = GNUNET_new(struct ProxyGNSCertificate); |
2712 | gnutls_x509_crt_set_dn_by_oid (request, | 2705 | gnutls_x509_crt_set_dn_by_oid(request, |
2713 | GNUTLS_OID_X520_COUNTRY_NAME, | 2706 | GNUTLS_OID_X520_COUNTRY_NAME, |
2714 | 0, | 2707 | 0, |
2715 | "ZZ", | 2708 | "ZZ", |
2716 | strlen ("ZZ")); | 2709 | strlen("ZZ")); |
2717 | gnutls_x509_crt_set_dn_by_oid (request, | 2710 | gnutls_x509_crt_set_dn_by_oid(request, |
2718 | GNUTLS_OID_X520_ORGANIZATION_NAME, | 2711 | GNUTLS_OID_X520_ORGANIZATION_NAME, |
2719 | 0, | 2712 | 0, |
2720 | "GNU Name System", | 2713 | "GNU Name System", |
2721 | strlen ("GNU Name System")); | 2714 | strlen("GNU Name System")); |
2722 | gnutls_x509_crt_set_dn_by_oid (request, | 2715 | gnutls_x509_crt_set_dn_by_oid(request, |
2723 | GNUTLS_OID_X520_COMMON_NAME, | 2716 | GNUTLS_OID_X520_COMMON_NAME, |
2724 | 0, | 2717 | 0, |
2725 | name, | 2718 | name, |
2726 | strlen (name)); | 2719 | strlen(name)); |
2727 | gnutls_x509_crt_set_subject_alternative_name (request, | 2720 | gnutls_x509_crt_set_subject_alternative_name(request, |
2728 | GNUTLS_SAN_DNSNAME, | 2721 | GNUTLS_SAN_DNSNAME, |
2729 | name); | 2722 | name); |
2730 | GNUNET_break (GNUTLS_E_SUCCESS == | 2723 | GNUNET_break(GNUTLS_E_SUCCESS == |
2731 | gnutls_x509_crt_set_version (request, | 2724 | gnutls_x509_crt_set_version(request, |
2732 | 3)); | 2725 | 3)); |
2733 | gnutls_rnd (GNUTLS_RND_NONCE, | 2726 | gnutls_rnd(GNUTLS_RND_NONCE, |
2734 | &serial, | 2727 | &serial, |
2735 | sizeof (serial)); | 2728 | sizeof(serial)); |
2736 | gnutls_x509_crt_set_serial (request, | 2729 | gnutls_x509_crt_set_serial(request, |
2737 | &serial, | 2730 | &serial, |
2738 | sizeof (serial)); | 2731 | sizeof(serial)); |
2739 | etime = time (NULL); | 2732 | etime = time(NULL); |
2740 | tm_data = localtime (&etime); | 2733 | tm_data = localtime(&etime); |
2741 | tm_data->tm_hour--; | 2734 | tm_data->tm_hour--; |
2742 | etime = mktime(tm_data); | 2735 | etime = mktime(tm_data); |
2743 | gnutls_x509_crt_set_activation_time (request, | 2736 | gnutls_x509_crt_set_activation_time(request, |
2744 | etime); | 2737 | etime); |
2745 | tm_data->tm_year++; | 2738 | tm_data->tm_year++; |
2746 | etime = mktime (tm_data); | 2739 | etime = mktime(tm_data); |
2747 | gnutls_x509_crt_set_expiration_time (request, | 2740 | gnutls_x509_crt_set_expiration_time(request, |
2748 | etime); | 2741 | etime); |
2749 | gnutls_x509_crt_sign2 (request, | 2742 | gnutls_x509_crt_sign2(request, |
2750 | proxy_ca.cert, | 2743 | proxy_ca.cert, |
2751 | proxy_ca.key, | 2744 | proxy_ca.key, |
2752 | GNUTLS_DIG_SHA512, | 2745 | GNUTLS_DIG_SHA512, |
2753 | 0); | 2746 | 0); |
2754 | key_buf_size = sizeof (pgc->key); | 2747 | key_buf_size = sizeof(pgc->key); |
2755 | cert_buf_size = sizeof (pgc->cert); | 2748 | cert_buf_size = sizeof(pgc->cert); |
2756 | gnutls_x509_crt_export (request, | 2749 | gnutls_x509_crt_export(request, |
2757 | GNUTLS_X509_FMT_PEM, | 2750 | GNUTLS_X509_FMT_PEM, |
2758 | pgc->cert, | 2751 | pgc->cert, |
2759 | &cert_buf_size); | 2752 | &cert_buf_size); |
2760 | gnutls_x509_privkey_export (proxy_ca.key, | 2753 | gnutls_x509_privkey_export(proxy_ca.key, |
2761 | GNUTLS_X509_FMT_PEM, | 2754 | GNUTLS_X509_FMT_PEM, |
2762 | pgc->key, | 2755 | pgc->key, |
2763 | &key_buf_size); | 2756 | &key_buf_size); |
2764 | gnutls_x509_crt_deinit (request); | 2757 | gnutls_x509_crt_deinit(request); |
2765 | return pgc; | 2758 | return pgc; |
2766 | } | 2759 | } |
2767 | 2760 | ||
@@ -2774,9 +2767,9 @@ generate_gns_certificate (const char *name) | |||
2774 | * @param ap arguments to @a fm | 2767 | * @param ap arguments to @a fm |
2775 | */ | 2768 | */ |
2776 | static void | 2769 | static void |
2777 | mhd_error_log_callback (void *cls, | 2770 | mhd_error_log_callback(void *cls, |
2778 | const char *fm, | 2771 | const char *fm, |
2779 | va_list ap) | 2772 | va_list ap) |
2780 | { | 2773 | { |
2781 | /* do nothing */ | 2774 | /* do nothing */ |
2782 | } | 2775 | } |
@@ -2789,49 +2782,49 @@ mhd_error_log_callback (void *cls, | |||
2789 | * @return NULL on error | 2782 | * @return NULL on error |
2790 | */ | 2783 | */ |
2791 | static struct MhdHttpList * | 2784 | static struct MhdHttpList * |
2792 | lookup_ssl_httpd (const char* domain) | 2785 | lookup_ssl_httpd(const char* domain) |
2793 | { | 2786 | { |
2794 | struct MhdHttpList *hd; | 2787 | struct MhdHttpList *hd; |
2795 | struct ProxyGNSCertificate *pgc; | 2788 | struct ProxyGNSCertificate *pgc; |
2796 | 2789 | ||
2797 | if (NULL == domain) | 2790 | if (NULL == domain) |
2798 | { | 2791 | { |
2799 | GNUNET_break (0); | 2792 | GNUNET_break(0); |
2800 | return NULL; | 2793 | return NULL; |
2801 | } | 2794 | } |
2802 | for (hd = mhd_httpd_head; NULL != hd; hd = hd->next) | 2795 | for (hd = mhd_httpd_head; NULL != hd; hd = hd->next) |
2803 | if ( (NULL != hd->domain) && | 2796 | if ((NULL != hd->domain) && |
2804 | (0 == strcmp (hd->domain, domain)) ) | 2797 | (0 == strcmp(hd->domain, domain))) |
2805 | return hd; | 2798 | return hd; |
2806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2807 | "Starting fresh MHD HTTPS instance for domain `%s'\n", | 2800 | "Starting fresh MHD HTTPS instance for domain `%s'\n", |
2808 | domain); | 2801 | domain); |
2809 | pgc = generate_gns_certificate (domain); | 2802 | pgc = generate_gns_certificate(domain); |
2810 | hd = GNUNET_new (struct MhdHttpList); | 2803 | hd = GNUNET_new(struct MhdHttpList); |
2811 | hd->is_ssl = GNUNET_YES; | 2804 | hd->is_ssl = GNUNET_YES; |
2812 | hd->domain = GNUNET_strdup (domain); | 2805 | hd->domain = GNUNET_strdup(domain); |
2813 | hd->proxy_cert = pgc; | 2806 | hd->proxy_cert = pgc; |
2814 | hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, | 2807 | hd->daemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, |
2815 | 0, | 2808 | 0, |
2816 | NULL, NULL, | 2809 | NULL, NULL, |
2817 | &create_response, hd, | 2810 | &create_response, hd, |
2818 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 2811 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, |
2819 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, | 2812 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, |
2820 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, | 2813 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, |
2821 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, | 2814 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, |
2822 | MHD_OPTION_EXTERNAL_LOGGER, &mhd_error_log_callback, NULL, | 2815 | MHD_OPTION_EXTERNAL_LOGGER, &mhd_error_log_callback, NULL, |
2823 | MHD_OPTION_HTTPS_MEM_KEY, pgc->key, | 2816 | MHD_OPTION_HTTPS_MEM_KEY, pgc->key, |
2824 | MHD_OPTION_HTTPS_MEM_CERT, pgc->cert, | 2817 | MHD_OPTION_HTTPS_MEM_CERT, pgc->cert, |
2825 | MHD_OPTION_END); | 2818 | MHD_OPTION_END); |
2826 | if (NULL == hd->daemon) | 2819 | if (NULL == hd->daemon) |
2827 | { | 2820 | { |
2828 | GNUNET_free (pgc); | 2821 | GNUNET_free(pgc); |
2829 | GNUNET_free (hd); | 2822 | GNUNET_free(hd); |
2830 | return NULL; | 2823 | return NULL; |
2831 | } | 2824 | } |
2832 | GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, | 2825 | GNUNET_CONTAINER_DLL_insert(mhd_httpd_head, |
2833 | mhd_httpd_tail, | 2826 | mhd_httpd_tail, |
2834 | hd); | 2827 | hd); |
2835 | return hd; | 2828 | return hd; |
2836 | } | 2829 | } |
2837 | 2830 | ||
@@ -2844,12 +2837,12 @@ lookup_ssl_httpd (const char* domain) | |||
2844 | * @param cls the `struct Socks5Request *` | 2837 | * @param cls the `struct Socks5Request *` |
2845 | */ | 2838 | */ |
2846 | static void | 2839 | static void |
2847 | timeout_s5r_handshake (void *cls) | 2840 | timeout_s5r_handshake(void *cls) |
2848 | { | 2841 | { |
2849 | struct Socks5Request *s5r = cls; | 2842 | struct Socks5Request *s5r = cls; |
2850 | 2843 | ||
2851 | s5r->timeout_task = NULL; | 2844 | s5r->timeout_task = NULL; |
2852 | cleanup_s5r (s5r); | 2845 | cleanup_s5r(s5r); |
2853 | } | 2846 | } |
2854 | 2847 | ||
2855 | 2848 | ||
@@ -2862,7 +2855,7 @@ timeout_s5r_handshake (void *cls) | |||
2862 | * @param s5r socks request that has reached the final stage | 2855 | * @param s5r socks request that has reached the final stage |
2863 | */ | 2856 | */ |
2864 | static void | 2857 | static void |
2865 | setup_data_transfer (struct Socks5Request *s5r) | 2858 | setup_data_transfer(struct Socks5Request *s5r) |
2866 | { | 2859 | { |
2867 | struct MhdHttpList *hd; | 2860 | struct MhdHttpList *hd; |
2868 | int fd; | 2861 | int fd; |
@@ -2871,47 +2864,49 @@ setup_data_transfer (struct Socks5Request *s5r) | |||
2871 | char *domain; | 2864 | char *domain; |
2872 | 2865 | ||
2873 | if (GNUNET_YES == s5r->is_tls) | 2866 | if (GNUNET_YES == s5r->is_tls) |
2874 | { | 2867 | { |
2875 | GNUNET_asprintf (&domain, | 2868 | GNUNET_asprintf(&domain, |
2876 | "%s", | 2869 | "%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"), | ||
2877 | s5r->domain); | 2876 | s5r->domain); |
2878 | hd = lookup_ssl_httpd (domain); | 2877 | cleanup_s5r(s5r); |
2879 | if (NULL == hd) | 2878 | GNUNET_free(domain); |
2880 | { | 2879 | return; |
2881 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2880 | } |
2882 | _("Failed to start HTTPS server for `%s'\n"), | ||
2883 | s5r->domain); | ||
2884 | cleanup_s5r (s5r); | ||
2885 | GNUNET_free (domain); | ||
2886 | return; | ||
2887 | } | 2881 | } |
2888 | } else { | 2882 | else |
2883 | { | ||
2889 | domain = NULL; | 2884 | domain = NULL; |
2890 | GNUNET_assert (NULL != httpd); | 2885 | GNUNET_assert(NULL != httpd); |
2891 | hd = httpd; | 2886 | hd = httpd; |
2892 | } | 2887 | } |
2893 | fd = GNUNET_NETWORK_get_fd (s5r->sock); | 2888 | fd = GNUNET_NETWORK_get_fd(s5r->sock); |
2894 | addr = GNUNET_NETWORK_get_addr (s5r->sock); | 2889 | addr = GNUNET_NETWORK_get_addr(s5r->sock); |
2895 | len = GNUNET_NETWORK_get_addrlen (s5r->sock); | 2890 | len = GNUNET_NETWORK_get_addrlen(s5r->sock); |
2896 | s5r->state = SOCKS5_SOCKET_WITH_MHD; | 2891 | s5r->state = SOCKS5_SOCKET_WITH_MHD; |
2897 | if (MHD_YES != | 2892 | if (MHD_YES != |
2898 | MHD_add_connection (hd->daemon, | 2893 | MHD_add_connection(hd->daemon, |
2899 | fd, | 2894 | fd, |
2900 | addr, | 2895 | addr, |
2901 | len)) | 2896 | len)) |
2902 | { | 2897 | { |
2903 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2898 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2904 | _("Failed to pass client to MHD\n")); | 2899 | _("Failed to pass client to MHD\n")); |
2905 | cleanup_s5r (s5r); | 2900 | cleanup_s5r(s5r); |
2906 | GNUNET_free_non_null (domain); | 2901 | GNUNET_free_non_null(domain); |
2907 | return; | 2902 | return; |
2908 | } | 2903 | } |
2909 | s5r->hd = hd; | 2904 | s5r->hd = hd; |
2910 | schedule_httpd (hd); | 2905 | schedule_httpd(hd); |
2911 | s5r->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_HANDSHAKE_TIMEOUT, | 2906 | s5r->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_HANDSHAKE_TIMEOUT, |
2912 | &timeout_s5r_handshake, | 2907 | &timeout_s5r_handshake, |
2913 | s5r); | 2908 | s5r); |
2914 | GNUNET_free_non_null (domain); | 2909 | GNUNET_free_non_null(domain); |
2915 | } | 2910 | } |
2916 | 2911 | ||
2917 | 2912 | ||
@@ -2924,57 +2919,61 @@ setup_data_transfer (struct Socks5Request *s5r) | |||
2924 | * @param cls the closure with the `struct Socks5Request` | 2919 | * @param cls the closure with the `struct Socks5Request` |
2925 | */ | 2920 | */ |
2926 | static void | 2921 | static void |
2927 | do_write (void *cls) | 2922 | do_write(void *cls) |
2928 | { | 2923 | { |
2929 | struct Socks5Request *s5r = cls; | 2924 | struct Socks5Request *s5r = cls; |
2930 | ssize_t len; | 2925 | ssize_t len; |
2931 | 2926 | ||
2932 | s5r->wtask = NULL; | 2927 | s5r->wtask = NULL; |
2933 | len = GNUNET_NETWORK_socket_send (s5r->sock, | 2928 | len = GNUNET_NETWORK_socket_send(s5r->sock, |
2934 | s5r->wbuf, | 2929 | s5r->wbuf, |
2935 | s5r->wbuf_len); | 2930 | s5r->wbuf_len); |
2936 | if (len <= 0) | 2931 | if (len <= 0) |
2937 | { | 2932 | { |
2938 | /* write error: connection closed, shutdown, etc.; just clean up */ | 2933 | /* write error: connection closed, shutdown, etc.; just clean up */ |
2939 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2934 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2940 | "Write Error\n"); | 2935 | "Write Error\n"); |
2941 | cleanup_s5r (s5r); | 2936 | cleanup_s5r(s5r); |
2942 | return; | 2937 | return; |
2943 | } | 2938 | } |
2944 | memmove (s5r->wbuf, | 2939 | memmove(s5r->wbuf, |
2945 | &s5r->wbuf[len], | 2940 | &s5r->wbuf[len], |
2946 | s5r->wbuf_len - len); | 2941 | s5r->wbuf_len - len); |
2947 | s5r->wbuf_len -= len; | 2942 | s5r->wbuf_len -= len; |
2948 | if (s5r->wbuf_len > 0) | 2943 | if (s5r->wbuf_len > 0) |
2949 | { | 2944 | { |
2950 | /* not done writing */ | 2945 | /* not done writing */ |
2951 | s5r->wtask = | 2946 | s5r->wtask = |
2952 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2947 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
2953 | s5r->sock, | 2948 | s5r->sock, |
2954 | &do_write, s5r); | 2949 | &do_write, s5r); |
2955 | return; | 2950 | return; |
2956 | } | 2951 | } |
2957 | 2952 | ||
2958 | /* we're done writing, continue with state machine! */ | 2953 | /* we're done writing, continue with state machine! */ |
2959 | 2954 | ||
2960 | switch (s5r->state) | 2955 | switch (s5r->state) |
2961 | { | 2956 | { |
2962 | case SOCKS5_INIT: | 2957 | case SOCKS5_INIT: |
2963 | GNUNET_assert (0); | 2958 | GNUNET_assert(0); |
2964 | break; | 2959 | break; |
2960 | |||
2965 | case SOCKS5_REQUEST: | 2961 | case SOCKS5_REQUEST: |
2966 | GNUNET_assert (NULL != s5r->rtask); | 2962 | GNUNET_assert(NULL != s5r->rtask); |
2967 | break; | 2963 | break; |
2964 | |||
2968 | case SOCKS5_DATA_TRANSFER: | 2965 | case SOCKS5_DATA_TRANSFER: |
2969 | setup_data_transfer (s5r); | 2966 | setup_data_transfer(s5r); |
2970 | return; | 2967 | return; |
2968 | |||
2971 | case SOCKS5_WRITE_THEN_CLEANUP: | 2969 | case SOCKS5_WRITE_THEN_CLEANUP: |
2972 | cleanup_s5r (s5r); | 2970 | cleanup_s5r(s5r); |
2973 | return; | 2971 | return; |
2972 | |||
2974 | default: | 2973 | default: |
2975 | GNUNET_break (0); | 2974 | GNUNET_break(0); |
2976 | break; | 2975 | break; |
2977 | } | 2976 | } |
2978 | } | 2977 | } |
2979 | 2978 | ||
2980 | 2979 | ||
@@ -2985,21 +2984,21 @@ do_write (void *cls) | |||
2985 | * @param sc status code to return | 2984 | * @param sc status code to return |
2986 | */ | 2985 | */ |
2987 | static void | 2986 | static void |
2988 | signal_socks_failure (struct Socks5Request *s5r, | 2987 | signal_socks_failure(struct Socks5Request *s5r, |
2989 | enum Socks5StatusCode sc) | 2988 | enum Socks5StatusCode sc) |
2990 | { | 2989 | { |
2991 | struct Socks5ServerResponseMessage *s_resp; | 2990 | struct Socks5ServerResponseMessage *s_resp; |
2992 | 2991 | ||
2993 | s_resp = (struct Socks5ServerResponseMessage *) &s5r->wbuf[s5r->wbuf_len]; | 2992 | s_resp = (struct Socks5ServerResponseMessage *)&s5r->wbuf[s5r->wbuf_len]; |
2994 | memset (s_resp, 0, sizeof (struct Socks5ServerResponseMessage)); | 2993 | memset(s_resp, 0, sizeof(struct Socks5ServerResponseMessage)); |
2995 | s_resp->version = SOCKS_VERSION_5; | 2994 | s_resp->version = SOCKS_VERSION_5; |
2996 | s_resp->reply = sc; | 2995 | s_resp->reply = sc; |
2997 | s5r->state = SOCKS5_WRITE_THEN_CLEANUP; | 2996 | s5r->state = SOCKS5_WRITE_THEN_CLEANUP; |
2998 | if (NULL != s5r->wtask) | 2997 | if (NULL != s5r->wtask) |
2999 | s5r->wtask = | 2998 | s5r->wtask = |
3000 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2999 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3001 | s5r->sock, | 3000 | s5r->sock, |
3002 | &do_write, s5r); | 3001 | &do_write, s5r); |
3003 | } | 3002 | } |
3004 | 3003 | ||
3005 | 3004 | ||
@@ -3009,26 +3008,26 @@ signal_socks_failure (struct Socks5Request *s5r, | |||
3009 | * @param s5r request to return success status message for | 3008 | * @param s5r request to return success status message for |
3010 | */ | 3009 | */ |
3011 | static void | 3010 | static void |
3012 | signal_socks_success (struct Socks5Request *s5r) | 3011 | signal_socks_success(struct Socks5Request *s5r) |
3013 | { | 3012 | { |
3014 | struct Socks5ServerResponseMessage *s_resp; | 3013 | struct Socks5ServerResponseMessage *s_resp; |
3015 | 3014 | ||
3016 | s_resp = (struct Socks5ServerResponseMessage *) &s5r->wbuf[s5r->wbuf_len]; | 3015 | s_resp = (struct Socks5ServerResponseMessage *)&s5r->wbuf[s5r->wbuf_len]; |
3017 | s_resp->version = SOCKS_VERSION_5; | 3016 | s_resp->version = SOCKS_VERSION_5; |
3018 | s_resp->reply = SOCKS5_STATUS_REQUEST_GRANTED; | 3017 | s_resp->reply = SOCKS5_STATUS_REQUEST_GRANTED; |
3019 | s_resp->reserved = 0; | 3018 | s_resp->reserved = 0; |
3020 | s_resp->addr_type = SOCKS5_AT_IPV4; | 3019 | s_resp->addr_type = SOCKS5_AT_IPV4; |
3021 | /* zero out IPv4 address and port */ | 3020 | /* zero out IPv4 address and port */ |
3022 | memset (&s_resp[1], | 3021 | memset(&s_resp[1], |
3023 | 0, | 3022 | 0, |
3024 | sizeof (struct in_addr) + sizeof (uint16_t)); | 3023 | sizeof(struct in_addr) + sizeof(uint16_t)); |
3025 | s5r->wbuf_len += sizeof (struct Socks5ServerResponseMessage) + | 3024 | s5r->wbuf_len += sizeof(struct Socks5ServerResponseMessage) + |
3026 | sizeof (struct in_addr) + sizeof (uint16_t); | 3025 | sizeof(struct in_addr) + sizeof(uint16_t); |
3027 | if (NULL == s5r->wtask) | 3026 | if (NULL == s5r->wtask) |
3028 | s5r->wtask = | 3027 | s5r->wtask = |
3029 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3028 | GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3030 | s5r->sock, | 3029 | s5r->sock, |
3031 | &do_write, s5r); | 3030 | &do_write, s5r); |
3032 | } | 3031 | } |
3033 | 3032 | ||
3034 | 3033 | ||
@@ -3041,10 +3040,10 @@ signal_socks_success (struct Socks5Request *s5r) | |||
3041 | * @param rd record data | 3040 | * @param rd record data |
3042 | */ | 3041 | */ |
3043 | static void | 3042 | static void |
3044 | handle_gns_result (void *cls, | 3043 | handle_gns_result(void *cls, |
3045 | int tld, | 3044 | int tld, |
3046 | uint32_t rd_count, | 3045 | uint32_t rd_count, |
3047 | const struct GNUNET_GNSRECORD_Data *rd) | 3046 | const struct GNUNET_GNSRECORD_Data *rd) |
3048 | { | 3047 | { |
3049 | struct Socks5Request *s5r = cls; | 3048 | struct Socks5Request *s5r = cls; |
3050 | const struct GNUNET_GNSRECORD_Data *r; | 3049 | const struct GNUNET_GNSRECORD_Data *r; |
@@ -3053,118 +3052,123 @@ handle_gns_result (void *cls, | |||
3053 | s5r->gns_lookup = NULL; | 3052 | s5r->gns_lookup = NULL; |
3054 | s5r->is_gns = tld; | 3053 | s5r->is_gns = tld; |
3055 | got_ip = GNUNET_NO; | 3054 | got_ip = GNUNET_NO; |
3056 | for (uint32_t i=0;i<rd_count;i++) | 3055 | for (uint32_t i = 0; i < rd_count; i++) |
3057 | { | ||
3058 | r = &rd[i]; | ||
3059 | switch (r->record_type) | ||
3060 | { | 3056 | { |
3061 | case GNUNET_DNSPARSER_TYPE_A: | 3057 | r = &rd[i]; |
3058 | switch (r->record_type) | ||
3059 | { | ||
3060 | case GNUNET_DNSPARSER_TYPE_A: | ||
3062 | { | 3061 | { |
3063 | struct sockaddr_in *in; | 3062 | struct sockaddr_in *in; |
3064 | 3063 | ||
3065 | if (sizeof (struct in_addr) != r->data_size) | 3064 | if (sizeof(struct in_addr) != r->data_size) |
3066 | { | 3065 | { |
3067 | GNUNET_break_op (0); | 3066 | GNUNET_break_op(0); |
3068 | break; | 3067 | break; |
3069 | } | 3068 | } |
3070 | if (GNUNET_YES == got_ip) | 3069 | if (GNUNET_YES == got_ip) |
3071 | break; | 3070 | break; |
3072 | if (GNUNET_OK != | 3071 | if (GNUNET_OK != |
3073 | GNUNET_NETWORK_test_pf (PF_INET)) | 3072 | GNUNET_NETWORK_test_pf(PF_INET)) |
3074 | break; | 3073 | break; |
3075 | got_ip = GNUNET_YES; | 3074 | got_ip = GNUNET_YES; |
3076 | in = (struct sockaddr_in *) &s5r->destination_address; | 3075 | in = (struct sockaddr_in *)&s5r->destination_address; |
3077 | in->sin_family = AF_INET; | 3076 | in->sin_family = AF_INET; |
3078 | GNUNET_memcpy (&in->sin_addr, | 3077 | GNUNET_memcpy(&in->sin_addr, |
3079 | r->data, | 3078 | r->data, |
3080 | r->data_size); | 3079 | r->data_size); |
3081 | in->sin_port = htons (s5r->port); | 3080 | in->sin_port = htons(s5r->port); |
3082 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3081 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3083 | in->sin_len = sizeof (*in); | 3082 | in->sin_len = sizeof(*in); |
3084 | #endif | 3083 | #endif |
3085 | } | 3084 | } |
3086 | break; | 3085 | break; |
3087 | case GNUNET_DNSPARSER_TYPE_AAAA: | 3086 | |
3087 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
3088 | { | 3088 | { |
3089 | struct sockaddr_in6 *in; | 3089 | struct sockaddr_in6 *in; |
3090 | 3090 | ||
3091 | if (sizeof (struct in6_addr) != r->data_size) | 3091 | if (sizeof(struct in6_addr) != r->data_size) |
3092 | { | 3092 | { |
3093 | GNUNET_break_op (0); | 3093 | GNUNET_break_op(0); |
3094 | break; | 3094 | break; |
3095 | } | 3095 | } |
3096 | if (GNUNET_YES == got_ip) | 3096 | if (GNUNET_YES == got_ip) |
3097 | break; | 3097 | break; |
3098 | if (GNUNET_YES == disable_v6) | 3098 | if (GNUNET_YES == disable_v6) |
3099 | break; | 3099 | break; |
3100 | if (GNUNET_OK != | 3100 | if (GNUNET_OK != |
3101 | GNUNET_NETWORK_test_pf (PF_INET6)) | 3101 | GNUNET_NETWORK_test_pf(PF_INET6)) |
3102 | break; | 3102 | break; |
3103 | /* FIXME: allow user to disable IPv6 per configuration option... */ | 3103 | /* FIXME: allow user to disable IPv6 per configuration option... */ |
3104 | got_ip = GNUNET_YES; | 3104 | got_ip = GNUNET_YES; |
3105 | in = (struct sockaddr_in6 *) &s5r->destination_address; | 3105 | in = (struct sockaddr_in6 *)&s5r->destination_address; |
3106 | in->sin6_family = AF_INET6; | 3106 | in->sin6_family = AF_INET6; |
3107 | GNUNET_memcpy (&in->sin6_addr, | 3107 | GNUNET_memcpy(&in->sin6_addr, |
3108 | r->data, | 3108 | r->data, |
3109 | r->data_size); | 3109 | r->data_size); |
3110 | in->sin6_port = htons (s5r->port); | 3110 | in->sin6_port = htons(s5r->port); |
3111 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3111 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3112 | in->sin6_len = sizeof (*in); | 3112 | in->sin6_len = sizeof(*in); |
3113 | #endif | 3113 | #endif |
3114 | } | 3114 | } |
3115 | break; | 3115 | break; |
3116 | case GNUNET_GNSRECORD_TYPE_VPN: | 3116 | |
3117 | GNUNET_break (0); /* should have been translated within GNS */ | 3117 | case GNUNET_GNSRECORD_TYPE_VPN: |
3118 | break; | 3118 | GNUNET_break(0); /* should have been translated within GNS */ |
3119 | case GNUNET_GNSRECORD_TYPE_LEHO: | 3119 | break; |
3120 | GNUNET_free_non_null (s5r->leho); | 3120 | |
3121 | s5r->leho = GNUNET_strndup (r->data, | 3121 | case GNUNET_GNSRECORD_TYPE_LEHO: |
3122 | r->data_size); | 3122 | GNUNET_free_non_null(s5r->leho); |
3123 | break; | 3123 | s5r->leho = GNUNET_strndup(r->data, |
3124 | case GNUNET_GNSRECORD_TYPE_BOX: | 3124 | r->data_size); |
3125 | break; | ||
3126 | |||
3127 | case GNUNET_GNSRECORD_TYPE_BOX: | ||
3125 | { | 3128 | { |
3126 | const struct GNUNET_GNSRECORD_BoxRecord *box; | 3129 | const struct GNUNET_GNSRECORD_BoxRecord *box; |
3127 | 3130 | ||
3128 | if (r->data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) | 3131 | if (r->data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord)) |
3129 | { | 3132 | { |
3130 | GNUNET_break_op (0); | 3133 | GNUNET_break_op(0); |
3131 | break; | 3134 | break; |
3132 | } | 3135 | } |
3133 | box = r->data; | 3136 | box = r->data; |
3134 | if ( (ntohl (box->record_type) != GNUNET_DNSPARSER_TYPE_TLSA) || | 3137 | if ((ntohl(box->record_type) != GNUNET_DNSPARSER_TYPE_TLSA) || |
3135 | (ntohs (box->protocol) != IPPROTO_TCP) || | 3138 | (ntohs(box->protocol) != IPPROTO_TCP) || |
3136 | (ntohs (box->service) != s5r->port) ) | 3139 | (ntohs(box->service) != s5r->port)) |
3137 | break; /* BOX record does not apply */ | 3140 | break; /* BOX record does not apply */ |
3138 | if (s5r->num_danes >= MAX_DANES) | 3141 | if (s5r->num_danes >= MAX_DANES) |
3139 | { | 3142 | { |
3140 | GNUNET_break (0); /* MAX_DANES too small */ | 3143 | GNUNET_break(0); /* MAX_DANES too small */ |
3141 | break; | 3144 | break; |
3142 | } | 3145 | } |
3143 | s5r->is_tls = GNUNET_YES; /* This should be TLS */ | 3146 | s5r->is_tls = GNUNET_YES; /* This should be TLS */ |
3144 | s5r->dane_data_len[s5r->num_danes] | 3147 | s5r->dane_data_len[s5r->num_danes] |
3145 | = r->data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord); | 3148 | = r->data_size - sizeof(struct GNUNET_GNSRECORD_BoxRecord); |
3146 | s5r->dane_data[s5r->num_danes] | 3149 | s5r->dane_data[s5r->num_danes] |
3147 | = GNUNET_memdup (&box[1], | 3150 | = GNUNET_memdup(&box[1], |
3148 | s5r->dane_data_len[s5r->num_danes]); | 3151 | s5r->dane_data_len[s5r->num_danes]); |
3149 | s5r->num_danes++; | 3152 | s5r->num_danes++; |
3153 | break; | ||
3154 | } | ||
3155 | |||
3156 | default: | ||
3157 | /* don't care */ | ||
3150 | break; | 3158 | break; |
3151 | } | 3159 | } |
3152 | default: | ||
3153 | /* don't care */ | ||
3154 | break; | ||
3155 | } | 3160 | } |
3156 | } | 3161 | if ((GNUNET_YES != got_ip) && |
3157 | if ( (GNUNET_YES != got_ip) && | 3162 | (GNUNET_YES == tld)) |
3158 | (GNUNET_YES == tld) ) | 3163 | { |
3159 | { | 3164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3165 | "Name resolution failed to yield useful IP address.\n"); |
3161 | "Name resolution failed to yield useful IP address.\n"); | 3166 | signal_socks_failure(s5r, |
3162 | signal_socks_failure (s5r, | 3167 | SOCKS5_STATUS_GENERAL_FAILURE); |
3163 | SOCKS5_STATUS_GENERAL_FAILURE); | 3168 | return; |
3164 | return; | 3169 | } |
3165 | } | ||
3166 | s5r->state = SOCKS5_DATA_TRANSFER; | 3170 | s5r->state = SOCKS5_DATA_TRANSFER; |
3167 | signal_socks_success (s5r); | 3171 | signal_socks_success(s5r); |
3168 | } | 3172 | } |
3169 | 3173 | ||
3170 | 3174 | ||
@@ -3175,13 +3179,13 @@ handle_gns_result (void *cls, | |||
3175 | * @param len number of bytes in read buffer to advance | 3179 | * @param len number of bytes in read buffer to advance |
3176 | */ | 3180 | */ |
3177 | static void | 3181 | static void |
3178 | clear_from_s5r_rbuf (struct Socks5Request *s5r, | 3182 | clear_from_s5r_rbuf(struct Socks5Request *s5r, |
3179 | size_t len) | 3183 | size_t len) |
3180 | { | 3184 | { |
3181 | GNUNET_assert (len <= s5r->rbuf_len); | 3185 | GNUNET_assert(len <= s5r->rbuf_len); |
3182 | memmove (s5r->rbuf, | 3186 | memmove(s5r->rbuf, |
3183 | &s5r->rbuf[len], | 3187 | &s5r->rbuf[len], |
3184 | s5r->rbuf_len - len); | 3188 | s5r->rbuf_len - len); |
3185 | s5r->rbuf_len -= len; | 3189 | s5r->rbuf_len -= len; |
3186 | } | 3190 | } |
3187 | 3191 | ||
@@ -3192,7 +3196,7 @@ clear_from_s5r_rbuf (struct Socks5Request *s5r, | |||
3192 | * @param cls the closure with the `struct Socks5Request` | 3196 | * @param cls the closure with the `struct Socks5Request` |
3193 | */ | 3197 | */ |
3194 | static void | 3198 | static void |
3195 | do_s5r_read (void *cls) | 3199 | do_s5r_read(void *cls) |
3196 | { | 3200 | { |
3197 | struct Socks5Request *s5r = cls; | 3201 | struct Socks5Request *s5r = cls; |
3198 | const struct Socks5ClientHelloMessage *c_hello; | 3202 | const struct Socks5ClientHelloMessage *c_hello; |
@@ -3203,188 +3207,196 @@ do_s5r_read (void *cls) | |||
3203 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 3207 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
3204 | 3208 | ||
3205 | s5r->rtask = NULL; | 3209 | s5r->rtask = NULL; |
3206 | tc = GNUNET_SCHEDULER_get_task_context (); | 3210 | tc = GNUNET_SCHEDULER_get_task_context(); |
3207 | if ( (NULL != tc->read_ready) && | 3211 | if ((NULL != tc->read_ready) && |
3208 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 3212 | (GNUNET_NETWORK_fdset_isset(tc->read_ready, |
3209 | s5r->sock)) ) | 3213 | s5r->sock))) |
3210 | { | 3214 | { |
3211 | rlen = GNUNET_NETWORK_socket_recv (s5r->sock, | 3215 | rlen = GNUNET_NETWORK_socket_recv(s5r->sock, |
3212 | &s5r->rbuf[s5r->rbuf_len], | 3216 | &s5r->rbuf[s5r->rbuf_len], |
3213 | sizeof (s5r->rbuf) - s5r->rbuf_len); | 3217 | sizeof(s5r->rbuf) - s5r->rbuf_len); |
3214 | if (rlen <= 0) | 3218 | if (rlen <= 0) |
3215 | { | 3219 | { |
3216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3220 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3217 | "socks5 client disconnected.\n"); | 3221 | "socks5 client disconnected.\n"); |
3218 | cleanup_s5r (s5r); | 3222 | cleanup_s5r(s5r); |
3219 | return; | 3223 | return; |
3224 | } | ||
3225 | s5r->rbuf_len += rlen; | ||
3220 | } | 3226 | } |
3221 | s5r->rbuf_len += rlen; | 3227 | s5r->rtask = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3222 | } | 3228 | s5r->sock, |
3223 | s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3229 | &do_s5r_read, s5r); |
3224 | s5r->sock, | 3230 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3225 | &do_s5r_read, s5r); | 3231 | "Processing %zu bytes of socks data in state %d\n", |
3226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3232 | s5r->rbuf_len, |
3227 | "Processing %zu bytes of socks data in state %d\n", | 3233 | s5r->state); |
3228 | s5r->rbuf_len, | ||
3229 | s5r->state); | ||
3230 | switch (s5r->state) | 3234 | switch (s5r->state) |
3231 | { | 3235 | { |
3232 | case SOCKS5_INIT: | 3236 | case SOCKS5_INIT: |
3233 | c_hello = (const struct Socks5ClientHelloMessage*) &s5r->rbuf; | 3237 | c_hello = (const struct Socks5ClientHelloMessage*)&s5r->rbuf; |
3234 | if ( (s5r->rbuf_len < sizeof (struct Socks5ClientHelloMessage)) || | 3238 | if ((s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage)) || |
3235 | (s5r->rbuf_len < sizeof (struct Socks5ClientHelloMessage) + c_hello->num_auth_methods) ) | 3239 | (s5r->rbuf_len < sizeof(struct Socks5ClientHelloMessage) + c_hello->num_auth_methods)) |
3236 | return; /* need more data */ | 3240 | return; /* need more data */ |
3237 | if (SOCKS_VERSION_5 != c_hello->version) | 3241 | if (SOCKS_VERSION_5 != c_hello->version) |
3238 | { | 3242 | { |
3239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3243 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3240 | _("Unsupported socks version %d\n"), | 3244 | _("Unsupported socks version %d\n"), |
3241 | (int) c_hello->version); | 3245 | (int)c_hello->version); |
3242 | cleanup_s5r (s5r); | 3246 | cleanup_s5r(s5r); |
3243 | return; | 3247 | return; |
3244 | } | 3248 | } |
3245 | clear_from_s5r_rbuf (s5r, | 3249 | clear_from_s5r_rbuf(s5r, |
3246 | sizeof (struct Socks5ClientHelloMessage) + c_hello->num_auth_methods); | 3250 | sizeof(struct Socks5ClientHelloMessage) + c_hello->num_auth_methods); |
3247 | GNUNET_assert (0 == s5r->wbuf_len); | 3251 | GNUNET_assert(0 == s5r->wbuf_len); |
3248 | s_hello = (struct Socks5ServerHelloMessage *) &s5r->wbuf; | 3252 | s_hello = (struct Socks5ServerHelloMessage *)&s5r->wbuf; |
3249 | s5r->wbuf_len = sizeof (struct Socks5ServerHelloMessage); | 3253 | s5r->wbuf_len = sizeof(struct Socks5ServerHelloMessage); |
3250 | s_hello->version = SOCKS_VERSION_5; | 3254 | s_hello->version = SOCKS_VERSION_5; |
3251 | s_hello->auth_method = SOCKS_AUTH_NONE; | 3255 | s_hello->auth_method = SOCKS_AUTH_NONE; |
3252 | GNUNET_assert (NULL == s5r->wtask); | 3256 | GNUNET_assert(NULL == s5r->wtask); |
3253 | s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3257 | s5r->wtask = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3254 | s5r->sock, | 3258 | s5r->sock, |
3255 | &do_write, s5r); | 3259 | &do_write, s5r); |
3256 | s5r->state = SOCKS5_REQUEST; | 3260 | s5r->state = SOCKS5_REQUEST; |
3257 | return; | 3261 | return; |
3262 | |||
3258 | case SOCKS5_REQUEST: | 3263 | case SOCKS5_REQUEST: |
3259 | c_req = (const struct Socks5ClientRequestMessage *) &s5r->rbuf; | 3264 | c_req = (const struct Socks5ClientRequestMessage *)&s5r->rbuf; |
3260 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage)) | 3265 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage)) |
3261 | return; | 3266 | return; |
3262 | switch (c_req->command) | 3267 | switch (c_req->command) |
3263 | { | 3268 | { |
3264 | case SOCKS5_CMD_TCP_STREAM: | 3269 | case SOCKS5_CMD_TCP_STREAM: |
3265 | /* handled below */ | 3270 | /* handled below */ |
3266 | break; | 3271 | break; |
3272 | |||
3267 | default: | 3273 | default: |
3268 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3274 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3269 | _("Unsupported socks command %d\n"), | 3275 | _("Unsupported socks command %d\n"), |
3270 | (int) c_req->command); | 3276 | (int)c_req->command); |
3271 | signal_socks_failure (s5r, | 3277 | signal_socks_failure(s5r, |
3272 | SOCKS5_STATUS_COMMAND_NOT_SUPPORTED); | 3278 | SOCKS5_STATUS_COMMAND_NOT_SUPPORTED); |
3273 | return; | 3279 | return; |
3274 | } | 3280 | } |
3275 | switch (c_req->addr_type) | 3281 | switch (c_req->addr_type) |
3276 | { | 3282 | { |
3277 | case SOCKS5_AT_IPV4: | 3283 | case SOCKS5_AT_IPV4: |
3278 | { | 3284 | { |
3279 | const struct in_addr *v4 = (const struct in_addr *) &c_req[1]; | 3285 | const struct in_addr *v4 = (const struct in_addr *)&c_req[1]; |
3280 | const uint16_t *port = (const uint16_t *) &v4[1]; | 3286 | const uint16_t *port = (const uint16_t *)&v4[1]; |
3281 | struct sockaddr_in *in; | 3287 | struct sockaddr_in *in; |
3282 | 3288 | ||
3283 | s5r->port = ntohs (*port); | 3289 | s5r->port = ntohs(*port); |
3284 | alen = sizeof (struct in_addr); | 3290 | alen = sizeof(struct in_addr); |
3285 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage) + | 3291 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + |
3286 | alen + sizeof (uint16_t)) | 3292 | alen + sizeof(uint16_t)) |
3287 | return; /* need more data */ | 3293 | return; /* need more data */ |
3288 | in = (struct sockaddr_in *) &s5r->destination_address; | 3294 | in = (struct sockaddr_in *)&s5r->destination_address; |
3289 | in->sin_family = AF_INET; | 3295 | in->sin_family = AF_INET; |
3290 | in->sin_addr = *v4; | 3296 | in->sin_addr = *v4; |
3291 | in->sin_port = *port; | 3297 | in->sin_port = *port; |
3292 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3298 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3293 | in->sin_len = sizeof (*in); | 3299 | in->sin_len = sizeof(*in); |
3294 | #endif | 3300 | #endif |
3295 | s5r->state = SOCKS5_DATA_TRANSFER; | 3301 | s5r->state = SOCKS5_DATA_TRANSFER; |
3296 | } | 3302 | } |
3297 | break; | 3303 | break; |
3304 | |||
3298 | case SOCKS5_AT_IPV6: | 3305 | case SOCKS5_AT_IPV6: |
3299 | { | 3306 | { |
3300 | const struct in6_addr *v6 = (const struct in6_addr *) &c_req[1]; | 3307 | const struct in6_addr *v6 = (const struct in6_addr *)&c_req[1]; |
3301 | const uint16_t *port = (const uint16_t *) &v6[1]; | 3308 | const uint16_t *port = (const uint16_t *)&v6[1]; |
3302 | struct sockaddr_in6 *in; | 3309 | struct sockaddr_in6 *in; |
3303 | 3310 | ||
3304 | s5r->port = ntohs (*port); | 3311 | s5r->port = ntohs(*port); |
3305 | alen = sizeof (struct in6_addr); | 3312 | alen = sizeof(struct in6_addr); |
3306 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage) + | 3313 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + |
3307 | alen + sizeof (uint16_t)) | 3314 | alen + sizeof(uint16_t)) |
3308 | return; /* need more data */ | 3315 | return; /* need more data */ |
3309 | in = (struct sockaddr_in6 *) &s5r->destination_address; | 3316 | in = (struct sockaddr_in6 *)&s5r->destination_address; |
3310 | in->sin6_family = AF_INET6; | 3317 | in->sin6_family = AF_INET6; |
3311 | in->sin6_addr = *v6; | 3318 | in->sin6_addr = *v6; |
3312 | in->sin6_port = *port; | 3319 | in->sin6_port = *port; |
3313 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3320 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3314 | in->sin6_len = sizeof (*in); | 3321 | in->sin6_len = sizeof(*in); |
3315 | #endif | 3322 | #endif |
3316 | s5r->state = SOCKS5_DATA_TRANSFER; | 3323 | s5r->state = SOCKS5_DATA_TRANSFER; |
3317 | } | 3324 | } |
3318 | break; | 3325 | break; |
3326 | |||
3319 | case SOCKS5_AT_DOMAINNAME: | 3327 | case SOCKS5_AT_DOMAINNAME: |
3320 | { | 3328 | { |
3321 | const uint8_t *dom_len; | 3329 | const uint8_t *dom_len; |
3322 | const char *dom_name; | 3330 | const char *dom_name; |
3323 | const uint16_t *port; | 3331 | const uint16_t *port; |
3324 | 3332 | ||
3325 | dom_len = (const uint8_t *) &c_req[1]; | 3333 | dom_len = (const uint8_t *)&c_req[1]; |
3326 | alen = *dom_len + 1; | 3334 | alen = *dom_len + 1; |
3327 | if (s5r->rbuf_len < sizeof (struct Socks5ClientRequestMessage) + | 3335 | if (s5r->rbuf_len < sizeof(struct Socks5ClientRequestMessage) + |
3328 | alen + sizeof (uint16_t)) | 3336 | alen + sizeof(uint16_t)) |
3329 | return; /* need more data */ | 3337 | return; /* need more data */ |
3330 | dom_name = (const char *) &dom_len[1]; | 3338 | dom_name = (const char *)&dom_len[1]; |
3331 | port = (const uint16_t*) &dom_name[*dom_len]; | 3339 | port = (const uint16_t*)&dom_name[*dom_len]; |
3332 | s5r->domain = GNUNET_strndup (dom_name, | 3340 | s5r->domain = GNUNET_strndup(dom_name, |
3333 | *dom_len); | 3341 | *dom_len); |
3334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3342 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3335 | "Requested connection is to %s:%d\n", | 3343 | "Requested connection is to %s:%d\n", |
3336 | //(HTTPS_PORT == s5r->port) ? "s" : "", | 3344 | //(HTTPS_PORT == s5r->port) ? "s" : "", |
3337 | s5r->domain, | 3345 | s5r->domain, |
3338 | ntohs (*port)); | 3346 | ntohs(*port)); |
3339 | s5r->state = SOCKS5_RESOLVING; | 3347 | s5r->state = SOCKS5_RESOLVING; |
3340 | s5r->port = ntohs (*port); | 3348 | s5r->port = ntohs(*port); |
3341 | s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO; | 3349 | s5r->is_tls = (HTTPS_PORT == s5r->port) ? GNUNET_YES : GNUNET_NO; |
3342 | s5r->gns_lookup = GNUNET_GNS_lookup_with_tld (gns_handle, | 3350 | s5r->gns_lookup = GNUNET_GNS_lookup_with_tld(gns_handle, |
3343 | s5r->domain, | 3351 | s5r->domain, |
3344 | GNUNET_DNSPARSER_TYPE_A, | 3352 | GNUNET_DNSPARSER_TYPE_A, |
3345 | GNUNET_NO /* only cached */, | 3353 | GNUNET_NO /* only cached */, |
3346 | &handle_gns_result, | 3354 | &handle_gns_result, |
3347 | s5r); | 3355 | s5r); |
3348 | break; | 3356 | break; |
3349 | } | 3357 | } |
3358 | |||
3350 | default: | 3359 | default: |
3351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3360 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3352 | _("Unsupported socks address type %d\n"), | 3361 | _("Unsupported socks address type %d\n"), |
3353 | (int) c_req->addr_type); | 3362 | (int)c_req->addr_type); |
3354 | signal_socks_failure (s5r, | 3363 | signal_socks_failure(s5r, |
3355 | SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED); | 3364 | SOCKS5_STATUS_ADDRESS_TYPE_NOT_SUPPORTED); |
3356 | return; | 3365 | return; |
3357 | } | 3366 | } |
3358 | clear_from_s5r_rbuf (s5r, | 3367 | clear_from_s5r_rbuf(s5r, |
3359 | sizeof (struct Socks5ClientRequestMessage) + | 3368 | sizeof(struct Socks5ClientRequestMessage) + |
3360 | alen + sizeof (uint16_t)); | 3369 | alen + sizeof(uint16_t)); |
3361 | if (0 != s5r->rbuf_len) | 3370 | if (0 != s5r->rbuf_len) |
3362 | { | 3371 | { |
3363 | /* read more bytes than healthy, why did the client send more!? */ | 3372 | /* read more bytes than healthy, why did the client send more!? */ |
3364 | GNUNET_break_op (0); | 3373 | GNUNET_break_op(0); |
3365 | signal_socks_failure (s5r, | 3374 | signal_socks_failure(s5r, |
3366 | SOCKS5_STATUS_GENERAL_FAILURE); | 3375 | SOCKS5_STATUS_GENERAL_FAILURE); |
3367 | return; | 3376 | return; |
3368 | } | 3377 | } |
3369 | if (SOCKS5_DATA_TRANSFER == s5r->state) | 3378 | if (SOCKS5_DATA_TRANSFER == s5r->state) |
3370 | { | 3379 | { |
3371 | /* if we are not waiting for GNS resolution, signal success */ | 3380 | /* if we are not waiting for GNS resolution, signal success */ |
3372 | signal_socks_success (s5r); | 3381 | signal_socks_success(s5r); |
3373 | } | 3382 | } |
3374 | /* We are done reading right now */ | 3383 | /* We are done reading right now */ |
3375 | GNUNET_SCHEDULER_cancel (s5r->rtask); | 3384 | GNUNET_SCHEDULER_cancel(s5r->rtask); |
3376 | s5r->rtask = NULL; | 3385 | s5r->rtask = NULL; |
3377 | return; | 3386 | return; |
3387 | |||
3378 | case SOCKS5_RESOLVING: | 3388 | case SOCKS5_RESOLVING: |
3379 | GNUNET_assert (0); | 3389 | GNUNET_assert(0); |
3380 | return; | 3390 | return; |
3391 | |||
3381 | case SOCKS5_DATA_TRANSFER: | 3392 | case SOCKS5_DATA_TRANSFER: |
3382 | GNUNET_assert (0); | 3393 | GNUNET_assert(0); |
3383 | return; | 3394 | return; |
3395 | |||
3384 | default: | 3396 | default: |
3385 | GNUNET_assert (0); | 3397 | GNUNET_assert(0); |
3386 | return; | 3398 | return; |
3387 | } | 3399 | } |
3388 | } | 3400 | } |
3389 | 3401 | ||
3390 | 3402 | ||
@@ -3395,46 +3407,46 @@ do_s5r_read (void *cls) | |||
3395 | * @param tc the scheduler context | 3407 | * @param tc the scheduler context |
3396 | */ | 3408 | */ |
3397 | static void | 3409 | static void |
3398 | do_accept (void *cls) | 3410 | do_accept(void *cls) |
3399 | { | 3411 | { |
3400 | struct GNUNET_NETWORK_Handle *lsock = cls; | 3412 | struct GNUNET_NETWORK_Handle *lsock = cls; |
3401 | struct GNUNET_NETWORK_Handle *s; | 3413 | struct GNUNET_NETWORK_Handle *s; |
3402 | struct Socks5Request *s5r; | 3414 | struct Socks5Request *s5r; |
3403 | 3415 | ||
3404 | GNUNET_assert (NULL != lsock); | 3416 | GNUNET_assert(NULL != lsock); |
3405 | if (lsock == lsock4) | 3417 | if (lsock == lsock4) |
3406 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3418 | ltask4 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3407 | lsock, | 3419 | lsock, |
3408 | &do_accept, | 3420 | &do_accept, |
3409 | lsock); | 3421 | lsock); |
3410 | else if (lsock == lsock6) | 3422 | else if (lsock == lsock6) |
3411 | ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3423 | ltask6 = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3412 | lsock, | 3424 | lsock, |
3413 | &do_accept, | 3425 | &do_accept, |
3414 | lsock); | 3426 | lsock); |
3415 | else | 3427 | else |
3416 | GNUNET_assert (0); | 3428 | GNUNET_assert(0); |
3417 | s = GNUNET_NETWORK_socket_accept (lsock, | 3429 | s = GNUNET_NETWORK_socket_accept(lsock, |
3418 | NULL, | 3430 | NULL, |
3419 | NULL); | 3431 | NULL); |
3420 | if (NULL == s) | 3432 | if (NULL == s) |
3421 | { | 3433 | { |
3422 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3434 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
3423 | "accept"); | 3435 | "accept"); |
3424 | return; | 3436 | return; |
3425 | } | 3437 | } |
3426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3438 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3427 | "Got an inbound connection, waiting for data\n"); | 3439 | "Got an inbound connection, waiting for data\n"); |
3428 | s5r = GNUNET_new (struct Socks5Request); | 3440 | s5r = GNUNET_new(struct Socks5Request); |
3429 | GNUNET_CONTAINER_DLL_insert (s5r_head, | 3441 | GNUNET_CONTAINER_DLL_insert(s5r_head, |
3430 | s5r_tail, | 3442 | s5r_tail, |
3431 | s5r); | 3443 | s5r); |
3432 | s5r->sock = s; | 3444 | s5r->sock = s; |
3433 | s5r->state = SOCKS5_INIT; | 3445 | s5r->state = SOCKS5_INIT; |
3434 | s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3446 | s5r->rtask = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
3435 | s5r->sock, | 3447 | s5r->sock, |
3436 | &do_s5r_read, | 3448 | &do_s5r_read, |
3437 | s5r); | 3449 | s5r); |
3438 | } | 3450 | } |
3439 | 3451 | ||
3440 | 3452 | ||
@@ -3447,63 +3459,63 @@ do_accept (void *cls) | |||
3447 | * @param cls closure | 3459 | * @param cls closure |
3448 | */ | 3460 | */ |
3449 | static void | 3461 | static void |
3450 | do_shutdown (void *cls) | 3462 | do_shutdown(void *cls) |
3451 | { | 3463 | { |
3452 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3464 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
3453 | "Shutting down...\n"); | 3465 | "Shutting down...\n"); |
3454 | /* MHD requires resuming before destroying the daemons */ | 3466 | /* MHD requires resuming before destroying the daemons */ |
3455 | for (struct Socks5Request *s5r = s5r_head; | 3467 | for (struct Socks5Request *s5r = s5r_head; |
3456 | NULL != s5r; | 3468 | NULL != s5r; |
3457 | s5r = s5r->next) | 3469 | s5r = s5r->next) |
3458 | { | ||
3459 | if (s5r->suspended) | ||
3460 | { | 3470 | { |
3461 | s5r->suspended = GNUNET_NO; | 3471 | if (s5r->suspended) |
3462 | MHD_resume_connection (s5r->con); | 3472 | { |
3473 | s5r->suspended = GNUNET_NO; | ||
3474 | MHD_resume_connection(s5r->con); | ||
3475 | } | ||
3463 | } | 3476 | } |
3464 | } | ||
3465 | while (NULL != mhd_httpd_head) | 3477 | while (NULL != mhd_httpd_head) |
3466 | kill_httpd (mhd_httpd_head); | 3478 | kill_httpd(mhd_httpd_head); |
3467 | while (NULL != s5r_head) | 3479 | while (NULL != s5r_head) |
3468 | cleanup_s5r (s5r_head); | 3480 | cleanup_s5r(s5r_head); |
3469 | if (NULL != lsock4) | 3481 | if (NULL != lsock4) |
3470 | { | 3482 | { |
3471 | GNUNET_NETWORK_socket_close (lsock4); | 3483 | GNUNET_NETWORK_socket_close(lsock4); |
3472 | lsock4 = NULL; | 3484 | lsock4 = NULL; |
3473 | } | 3485 | } |
3474 | if (NULL != lsock6) | 3486 | if (NULL != lsock6) |
3475 | { | 3487 | { |
3476 | GNUNET_NETWORK_socket_close (lsock6); | 3488 | GNUNET_NETWORK_socket_close(lsock6); |
3477 | lsock6 = NULL; | 3489 | lsock6 = NULL; |
3478 | } | 3490 | } |
3479 | if (NULL != curl_multi) | 3491 | if (NULL != curl_multi) |
3480 | { | 3492 | { |
3481 | curl_multi_cleanup (curl_multi); | 3493 | curl_multi_cleanup(curl_multi); |
3482 | curl_multi = NULL; | 3494 | curl_multi = NULL; |
3483 | } | 3495 | } |
3484 | if (NULL != gns_handle) | 3496 | if (NULL != gns_handle) |
3485 | { | 3497 | { |
3486 | GNUNET_GNS_disconnect (gns_handle); | 3498 | GNUNET_GNS_disconnect(gns_handle); |
3487 | gns_handle = NULL; | 3499 | gns_handle = NULL; |
3488 | } | 3500 | } |
3489 | if (NULL != curl_download_task) | 3501 | if (NULL != curl_download_task) |
3490 | { | 3502 | { |
3491 | GNUNET_SCHEDULER_cancel (curl_download_task); | 3503 | GNUNET_SCHEDULER_cancel(curl_download_task); |
3492 | curl_download_task = NULL; | 3504 | curl_download_task = NULL; |
3493 | } | 3505 | } |
3494 | if (NULL != ltask4) | 3506 | if (NULL != ltask4) |
3495 | { | 3507 | { |
3496 | GNUNET_SCHEDULER_cancel (ltask4); | 3508 | GNUNET_SCHEDULER_cancel(ltask4); |
3497 | ltask4 = NULL; | 3509 | ltask4 = NULL; |
3498 | } | 3510 | } |
3499 | if (NULL != ltask6) | 3511 | if (NULL != ltask6) |
3500 | { | 3512 | { |
3501 | GNUNET_SCHEDULER_cancel (ltask6); | 3513 | GNUNET_SCHEDULER_cancel(ltask6); |
3502 | ltask6 = NULL; | 3514 | ltask6 = NULL; |
3503 | } | 3515 | } |
3504 | gnutls_x509_crt_deinit (proxy_ca.cert); | 3516 | gnutls_x509_crt_deinit(proxy_ca.cert); |
3505 | gnutls_x509_privkey_deinit (proxy_ca.key); | 3517 | gnutls_x509_privkey_deinit(proxy_ca.key); |
3506 | gnutls_global_deinit (); | 3518 | gnutls_global_deinit(); |
3507 | } | 3519 | } |
3508 | 3520 | ||
3509 | 3521 | ||
@@ -3513,34 +3525,34 @@ do_shutdown (void *cls) | |||
3513 | * @return NULL on error | 3525 | * @return NULL on error |
3514 | */ | 3526 | */ |
3515 | static struct GNUNET_NETWORK_Handle * | 3527 | static struct GNUNET_NETWORK_Handle * |
3516 | bind_v4 () | 3528 | bind_v4() |
3517 | { | 3529 | { |
3518 | struct GNUNET_NETWORK_Handle *ls; | 3530 | struct GNUNET_NETWORK_Handle *ls; |
3519 | struct sockaddr_in sa4; | 3531 | struct sockaddr_in sa4; |
3520 | int eno; | 3532 | int eno; |
3521 | 3533 | ||
3522 | memset (&sa4, 0, sizeof (sa4)); | 3534 | memset(&sa4, 0, sizeof(sa4)); |
3523 | sa4.sin_family = AF_INET; | 3535 | sa4.sin_family = AF_INET; |
3524 | sa4.sin_port = htons (port); | 3536 | sa4.sin_port = htons(port); |
3525 | sa4.sin_addr.s_addr = address; | 3537 | sa4.sin_addr.s_addr = address; |
3526 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3538 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3527 | sa4.sin_len = sizeof (sa4); | 3539 | sa4.sin_len = sizeof(sa4); |
3528 | #endif | 3540 | #endif |
3529 | ls = GNUNET_NETWORK_socket_create (AF_INET, | 3541 | ls = GNUNET_NETWORK_socket_create(AF_INET, |
3530 | SOCK_STREAM, | 3542 | SOCK_STREAM, |
3531 | 0); | 3543 | 0); |
3532 | if (NULL == ls) | 3544 | if (NULL == ls) |
3533 | return NULL; | 3545 | return NULL; |
3534 | if (GNUNET_OK != | 3546 | if (GNUNET_OK != |
3535 | GNUNET_NETWORK_socket_bind (ls, | 3547 | GNUNET_NETWORK_socket_bind(ls, |
3536 | (const struct sockaddr *) &sa4, | 3548 | (const struct sockaddr *)&sa4, |
3537 | sizeof (sa4))) | 3549 | sizeof(sa4))) |
3538 | { | 3550 | { |
3539 | eno = errno; | 3551 | eno = errno; |
3540 | GNUNET_NETWORK_socket_close (ls); | 3552 | GNUNET_NETWORK_socket_close(ls); |
3541 | errno = eno; | 3553 | errno = eno; |
3542 | return NULL; | 3554 | return NULL; |
3543 | } | 3555 | } |
3544 | return ls; | 3556 | return ls; |
3545 | } | 3557 | } |
3546 | 3558 | ||
@@ -3551,34 +3563,34 @@ bind_v4 () | |||
3551 | * @return NULL on error | 3563 | * @return NULL on error |
3552 | */ | 3564 | */ |
3553 | static struct GNUNET_NETWORK_Handle * | 3565 | static struct GNUNET_NETWORK_Handle * |
3554 | bind_v6 () | 3566 | bind_v6() |
3555 | { | 3567 | { |
3556 | struct GNUNET_NETWORK_Handle *ls; | 3568 | struct GNUNET_NETWORK_Handle *ls; |
3557 | struct sockaddr_in6 sa6; | 3569 | struct sockaddr_in6 sa6; |
3558 | int eno; | 3570 | int eno; |
3559 | 3571 | ||
3560 | memset (&sa6, 0, sizeof (sa6)); | 3572 | memset(&sa6, 0, sizeof(sa6)); |
3561 | sa6.sin6_family = AF_INET6; | 3573 | sa6.sin6_family = AF_INET6; |
3562 | sa6.sin6_port = htons (port); | 3574 | sa6.sin6_port = htons(port); |
3563 | sa6.sin6_addr = address6; | 3575 | sa6.sin6_addr = address6; |
3564 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3576 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3565 | sa6.sin6_len = sizeof (sa6); | 3577 | sa6.sin6_len = sizeof(sa6); |
3566 | #endif | 3578 | #endif |
3567 | ls = GNUNET_NETWORK_socket_create (AF_INET6, | 3579 | ls = GNUNET_NETWORK_socket_create(AF_INET6, |
3568 | SOCK_STREAM, | 3580 | SOCK_STREAM, |
3569 | 0); | 3581 | 0); |
3570 | if (NULL == ls) | 3582 | if (NULL == ls) |
3571 | return NULL; | 3583 | return NULL; |
3572 | if (GNUNET_OK != | 3584 | if (GNUNET_OK != |
3573 | GNUNET_NETWORK_socket_bind (ls, | 3585 | GNUNET_NETWORK_socket_bind(ls, |
3574 | (const struct sockaddr *) &sa6, | 3586 | (const struct sockaddr *)&sa6, |
3575 | sizeof (sa6))) | 3587 | sizeof(sa6))) |
3576 | { | 3588 | { |
3577 | eno = errno; | 3589 | eno = errno; |
3578 | GNUNET_NETWORK_socket_close (ls); | 3590 | GNUNET_NETWORK_socket_close(ls); |
3579 | errno = eno; | 3591 | errno = eno; |
3580 | return NULL; | 3592 | return NULL; |
3581 | } | 3593 | } |
3582 | return ls; | 3594 | return ls; |
3583 | } | 3595 | } |
3584 | 3596 | ||
@@ -3592,10 +3604,10 @@ bind_v6 () | |||
3592 | * @param c configuration | 3604 | * @param c configuration |
3593 | */ | 3605 | */ |
3594 | static void | 3606 | static void |
3595 | run (void *cls, | 3607 | run(void *cls, |
3596 | char *const *args, | 3608 | char *const *args, |
3597 | const char *cfgfile, | 3609 | const char *cfgfile, |
3598 | const struct GNUNET_CONFIGURATION_Handle *c) | 3610 | const struct GNUNET_CONFIGURATION_Handle *c) |
3599 | { | 3611 | { |
3600 | char* cafile_cfg = NULL; | 3612 | char* cafile_cfg = NULL; |
3601 | char* cafile; | 3613 | char* cafile; |
@@ -3605,198 +3617,198 @@ run (void *cls, | |||
3605 | cfg = c; | 3617 | cfg = c; |
3606 | 3618 | ||
3607 | /* Get address to bind to */ | 3619 | /* Get address to bind to */ |
3608 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy", | 3620 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "gns-proxy", |
3609 | "BIND_TO", | 3621 | "BIND_TO", |
3610 | &addr_str)) | 3622 | &addr_str)) |
3611 | { | 3623 | { |
3612 | //No address specified | 3624 | //No address specified |
3613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3625 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3614 | "Don't know what to bind to...\n"); | 3626 | "Don't know what to bind to...\n"); |
3615 | GNUNET_free (addr_str); | 3627 | GNUNET_free(addr_str); |
3616 | GNUNET_SCHEDULER_shutdown (); | 3628 | GNUNET_SCHEDULER_shutdown(); |
3617 | return; | 3629 | return; |
3618 | } | 3630 | } |
3619 | if (1 != inet_pton (AF_INET, addr_str, &address)) | 3631 | if (1 != inet_pton(AF_INET, addr_str, &address)) |
3620 | { | 3632 | { |
3621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3633 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3622 | "Unable to parse address %s\n", | 3634 | "Unable to parse address %s\n", |
3623 | addr_str); | 3635 | addr_str); |
3624 | GNUNET_free (addr_str); | 3636 | GNUNET_free(addr_str); |
3625 | GNUNET_SCHEDULER_shutdown (); | 3637 | GNUNET_SCHEDULER_shutdown(); |
3626 | return; | 3638 | return; |
3627 | } | 3639 | } |
3628 | GNUNET_free (addr_str); | 3640 | GNUNET_free(addr_str); |
3629 | /* Get address to bind to */ | 3641 | /* Get address to bind to */ |
3630 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy", | 3642 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "gns-proxy", |
3631 | "BIND_TO6", | 3643 | "BIND_TO6", |
3632 | &addr_str)) | 3644 | &addr_str)) |
3633 | { | 3645 | { |
3634 | //No address specified | 3646 | //No address specified |
3635 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3647 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3636 | "Don't know what to bind6 to...\n"); | 3648 | "Don't know what to bind6 to...\n"); |
3637 | GNUNET_free (addr_str); | 3649 | GNUNET_free(addr_str); |
3638 | GNUNET_SCHEDULER_shutdown (); | 3650 | GNUNET_SCHEDULER_shutdown(); |
3639 | return; | 3651 | return; |
3640 | } | 3652 | } |
3641 | if (1 != inet_pton (AF_INET6, addr_str, &address6)) | 3653 | if (1 != inet_pton(AF_INET6, addr_str, &address6)) |
3642 | { | 3654 | { |
3643 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3655 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3644 | "Unable to parse IPv6 address %s\n", | 3656 | "Unable to parse IPv6 address %s\n", |
3645 | addr_str); | 3657 | addr_str); |
3646 | GNUNET_free (addr_str); | 3658 | GNUNET_free(addr_str); |
3647 | GNUNET_SCHEDULER_shutdown (); | 3659 | GNUNET_SCHEDULER_shutdown(); |
3648 | return; | 3660 | return; |
3649 | } | 3661 | } |
3650 | GNUNET_free (addr_str); | 3662 | GNUNET_free(addr_str); |
3651 | 3663 | ||
3652 | if (NULL == (curl_multi = curl_multi_init ())) | 3664 | if (NULL == (curl_multi = curl_multi_init())) |
3653 | { | 3665 | { |
3654 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3666 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3655 | "Failed to create cURL multi handle!\n"); | 3667 | "Failed to create cURL multi handle!\n"); |
3656 | return; | 3668 | return; |
3657 | } | 3669 | } |
3658 | cafile = cafile_opt; | 3670 | cafile = cafile_opt; |
3659 | if (NULL == cafile) | 3671 | if (NULL == cafile) |
3660 | { | 3672 | { |
3661 | if (GNUNET_OK != | 3673 | if (GNUNET_OK != |
3662 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 3674 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
3663 | "gns-proxy", | 3675 | "gns-proxy", |
3664 | "PROXY_CACERT", | 3676 | "PROXY_CACERT", |
3665 | &cafile_cfg)) | 3677 | &cafile_cfg)) |
3666 | { | 3678 | { |
3667 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3679 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3668 | "gns-proxy", | 3680 | "gns-proxy", |
3669 | "PROXY_CACERT"); | 3681 | "PROXY_CACERT"); |
3682 | return; | ||
3683 | } | ||
3684 | cafile = cafile_cfg; | ||
3685 | } | ||
3686 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
3687 | "Using `%s' as CA\n", | ||
3688 | cafile); | ||
3689 | |||
3690 | gnutls_global_init(); | ||
3691 | gnutls_x509_crt_init(&proxy_ca.cert); | ||
3692 | gnutls_x509_privkey_init(&proxy_ca.key); | ||
3693 | |||
3694 | if ((GNUNET_OK != | ||
3695 | load_cert_from_file(proxy_ca.cert, | ||
3696 | cafile)) || | ||
3697 | (GNUNET_OK != | ||
3698 | load_key_from_file(proxy_ca.key, | ||
3699 | cafile))) | ||
3700 | { | ||
3701 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
3702 | _("Failed to load X.509 key and certificate from `%s'\n"), | ||
3703 | cafile); | ||
3704 | gnutls_x509_crt_deinit(proxy_ca.cert); | ||
3705 | gnutls_x509_privkey_deinit(proxy_ca.key); | ||
3706 | gnutls_global_deinit(); | ||
3707 | GNUNET_free_non_null(cafile_cfg); | ||
3670 | return; | 3708 | return; |
3671 | } | 3709 | } |
3672 | cafile = cafile_cfg; | 3710 | GNUNET_free_non_null(cafile_cfg); |
3673 | } | 3711 | if (NULL == (gns_handle = GNUNET_GNS_connect(cfg))) |
3674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3712 | { |
3675 | "Using `%s' as CA\n", | 3713 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3676 | cafile); | 3714 | "Unable to connect to GNS!\n"); |
3677 | 3715 | gnutls_x509_crt_deinit(proxy_ca.cert); | |
3678 | gnutls_global_init (); | 3716 | gnutls_x509_privkey_deinit(proxy_ca.key); |
3679 | gnutls_x509_crt_init (&proxy_ca.cert); | 3717 | gnutls_global_deinit(); |
3680 | gnutls_x509_privkey_init (&proxy_ca.key); | 3718 | return; |
3681 | 3719 | } | |
3682 | if ( (GNUNET_OK != | 3720 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
3683 | load_cert_from_file (proxy_ca.cert, | 3721 | NULL); |
3684 | cafile)) || | ||
3685 | (GNUNET_OK != | ||
3686 | load_key_from_file (proxy_ca.key, | ||
3687 | cafile)) ) | ||
3688 | { | ||
3689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3690 | _("Failed to load X.509 key and certificate from `%s'\n"), | ||
3691 | cafile); | ||
3692 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3693 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3694 | gnutls_global_deinit (); | ||
3695 | GNUNET_free_non_null (cafile_cfg); | ||
3696 | return; | ||
3697 | } | ||
3698 | GNUNET_free_non_null (cafile_cfg); | ||
3699 | if (NULL == (gns_handle = GNUNET_GNS_connect (cfg))) | ||
3700 | { | ||
3701 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3702 | "Unable to connect to GNS!\n"); | ||
3703 | gnutls_x509_crt_deinit (proxy_ca.cert); | ||
3704 | gnutls_x509_privkey_deinit (proxy_ca.key); | ||
3705 | gnutls_global_deinit (); | ||
3706 | return; | ||
3707 | } | ||
3708 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
3709 | NULL); | ||
3710 | 3722 | ||
3711 | /* Open listen socket for socks proxy */ | 3723 | /* Open listen socket for socks proxy */ |
3712 | lsock6 = bind_v6 (); | 3724 | lsock6 = bind_v6(); |
3713 | if (NULL == lsock6) | 3725 | if (NULL == lsock6) |
3714 | { | ||
3715 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
3716 | "bind"); | ||
3717 | } | ||
3718 | else | ||
3719 | { | ||
3720 | if (GNUNET_OK != | ||
3721 | GNUNET_NETWORK_socket_listen (lsock6, | ||
3722 | 5)) | ||
3723 | { | 3726 | { |
3724 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3727 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
3725 | "listen"); | 3728 | "bind"); |
3726 | GNUNET_NETWORK_socket_close (lsock6); | ||
3727 | lsock6 = NULL; | ||
3728 | } | 3729 | } |
3729 | else | 3730 | else |
3730 | { | 3731 | { |
3731 | ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3732 | if (GNUNET_OK != |
3732 | lsock6, | 3733 | GNUNET_NETWORK_socket_listen(lsock6, |
3733 | &do_accept, | 3734 | 5)) |
3734 | lsock6); | 3735 | { |
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 | } | ||
3735 | } | 3748 | } |
3736 | } | 3749 | lsock4 = bind_v4(); |
3737 | lsock4 = bind_v4 (); | ||
3738 | if (NULL == lsock4) | 3750 | if (NULL == lsock4) |
3739 | { | 3751 | { |
3740 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3752 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
3741 | "bind"); | 3753 | "bind"); |
3742 | } | 3754 | } |
3743 | else | 3755 | else |
3744 | { | ||
3745 | if (GNUNET_OK != | ||
3746 | GNUNET_NETWORK_socket_listen (lsock4, | ||
3747 | 5)) | ||
3748 | { | 3756 | { |
3749 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 3757 | if (GNUNET_OK != |
3750 | "listen"); | 3758 | GNUNET_NETWORK_socket_listen(lsock4, |
3751 | GNUNET_NETWORK_socket_close (lsock4); | 3759 | 5)) |
3752 | lsock4 = NULL; | 3760 | { |
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 | } | ||
3753 | } | 3773 | } |
3754 | else | 3774 | if ((NULL == lsock4) && |
3775 | (NULL == lsock6)) | ||
3755 | { | 3776 | { |
3756 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 3777 | GNUNET_SCHEDULER_shutdown(); |
3757 | lsock4, | 3778 | return; |
3758 | &do_accept, | ||
3759 | lsock4); | ||
3760 | } | 3779 | } |
3761 | } | 3780 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
3762 | if ( (NULL == lsock4) && | 3781 | { |
3763 | (NULL == lsock6) ) | 3782 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3764 | { | 3783 | "cURL global init failed!\n"); |
3765 | GNUNET_SCHEDULER_shutdown (); | 3784 | GNUNET_SCHEDULER_shutdown(); |
3766 | return; | 3785 | return; |
3767 | } | 3786 | } |
3768 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 3787 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3769 | { | 3788 | "Proxy listens on port %u\n", |
3770 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3789 | (unsigned int)port); |
3771 | "cURL global init failed!\n"); | ||
3772 | GNUNET_SCHEDULER_shutdown (); | ||
3773 | return; | ||
3774 | } | ||
3775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3776 | "Proxy listens on port %u\n", | ||
3777 | (unsigned int) port); | ||
3778 | 3790 | ||
3779 | /* start MHD daemon for HTTP */ | 3791 | /* start MHD daemon for HTTP */ |
3780 | hd = GNUNET_new (struct MhdHttpList); | 3792 | hd = GNUNET_new(struct MhdHttpList); |
3781 | hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, | 3793 | hd->daemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME, |
3782 | 0, | 3794 | 0, |
3783 | NULL, NULL, | 3795 | NULL, NULL, |
3784 | &create_response, hd, | 3796 | &create_response, hd, |
3785 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 3797 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, |
3786 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, | 3798 | MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL, |
3787 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, | 3799 | MHD_OPTION_NOTIFY_CONNECTION, &mhd_connection_cb, NULL, |
3788 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, | 3800 | MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL, |
3789 | MHD_OPTION_END); | 3801 | MHD_OPTION_END); |
3790 | if (NULL == hd->daemon) | 3802 | if (NULL == hd->daemon) |
3791 | { | 3803 | { |
3792 | GNUNET_free (hd); | 3804 | GNUNET_free(hd); |
3793 | GNUNET_SCHEDULER_shutdown (); | 3805 | GNUNET_SCHEDULER_shutdown(); |
3794 | return; | 3806 | return; |
3795 | } | 3807 | } |
3796 | httpd = hd; | 3808 | httpd = hd; |
3797 | GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, | 3809 | GNUNET_CONTAINER_DLL_insert(mhd_httpd_head, |
3798 | mhd_httpd_tail, | 3810 | mhd_httpd_tail, |
3799 | hd); | 3811 | hd); |
3800 | } | 3812 | } |
3801 | 3813 | ||
3802 | 3814 | ||
@@ -3808,24 +3820,24 @@ run (void *cls, | |||
3808 | * @return 0 ok, 1 on error | 3820 | * @return 0 ok, 1 on error |
3809 | */ | 3821 | */ |
3810 | int | 3822 | int |
3811 | main (int argc, | 3823 | main(int argc, |
3812 | char *const *argv) | 3824 | char *const *argv) |
3813 | { | 3825 | { |
3814 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 3826 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
3815 | GNUNET_GETOPT_option_uint16 ('p', | 3827 | GNUNET_GETOPT_option_uint16('p', |
3816 | "port", | 3828 | "port", |
3817 | NULL, | 3829 | NULL, |
3818 | gettext_noop ("listen on specified port (default: 7777)"), | 3830 | gettext_noop("listen on specified port (default: 7777)"), |
3819 | &port), | 3831 | &port), |
3820 | GNUNET_GETOPT_option_string ('a', | 3832 | GNUNET_GETOPT_option_string('a', |
3821 | "authority", | 3833 | "authority", |
3822 | NULL, | 3834 | NULL, |
3823 | gettext_noop ("pem file to use as CA"), | 3835 | gettext_noop("pem file to use as CA"), |
3824 | &cafile_opt), | 3836 | &cafile_opt), |
3825 | GNUNET_GETOPT_option_flag ('6', | 3837 | GNUNET_GETOPT_option_flag('6', |
3826 | "disable-ivp6", | 3838 | "disable-ivp6", |
3827 | gettext_noop ("disable use of IPv6"), | 3839 | gettext_noop("disable use of IPv6"), |
3828 | &disable_v6), | 3840 | &disable_v6), |
3829 | 3841 | ||
3830 | GNUNET_GETOPT_OPTION_END | 3842 | GNUNET_GETOPT_OPTION_END |
3831 | }; | 3843 | }; |
@@ -3835,26 +3847,26 @@ main (int argc, | |||
3835 | int ret; | 3847 | int ret; |
3836 | 3848 | ||
3837 | if (GNUNET_OK != | 3849 | if (GNUNET_OK != |
3838 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 3850 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
3839 | &argc, &argv)) | 3851 | &argc, &argv)) |
3840 | return 2; | 3852 | return 2; |
3841 | GNUNET_log_setup ("gnunet-gns-proxy", | 3853 | GNUNET_log_setup("gnunet-gns-proxy", |
3842 | "WARNING", | 3854 | "WARNING", |
3843 | NULL); | 3855 | NULL); |
3844 | curl_failure_response | 3856 | curl_failure_response |
3845 | = MHD_create_response_from_buffer (strlen (page), | 3857 | = MHD_create_response_from_buffer(strlen(page), |
3846 | (void *) page, | 3858 | (void *)page, |
3847 | MHD_RESPMEM_PERSISTENT); | 3859 | MHD_RESPMEM_PERSISTENT); |
3848 | 3860 | ||
3849 | ret = | 3861 | ret = |
3850 | (GNUNET_OK == | 3862 | (GNUNET_OK == |
3851 | GNUNET_PROGRAM_run (argc, argv, | 3863 | GNUNET_PROGRAM_run(argc, argv, |
3852 | "gnunet-gns-proxy", | 3864 | "gnunet-gns-proxy", |
3853 | _("GNUnet GNS proxy"), | 3865 | _("GNUnet GNS proxy"), |
3854 | options, | 3866 | options, |
3855 | &run, NULL)) ? 0 : 1; | 3867 | &run, NULL)) ? 0 : 1; |
3856 | MHD_destroy_response (curl_failure_response); | 3868 | MHD_destroy_response(curl_failure_response); |
3857 | GNUNET_free_non_null ((char *) argv); | 3869 | GNUNET_free_non_null((char *)argv); |
3858 | return ret; | 3870 | return ret; |
3859 | } | 3871 | } |
3860 | 3872 | ||
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index d795f89fc..352ccce04 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet-gns.c | 21 | * @file gnunet-gns.c |
22 | * @brief command line tool to access distributed GNS | 22 | * @brief command line tool to access distributed GNS |
@@ -90,24 +90,24 @@ static int global_ret; | |||
90 | * @param cls unused | 90 | * @param cls unused |
91 | */ | 91 | */ |
92 | static void | 92 | static void |
93 | do_shutdown (void *cls) | 93 | do_shutdown(void *cls) |
94 | { | 94 | { |
95 | (void) cls; | 95 | (void)cls; |
96 | if (NULL != to_task) | 96 | if (NULL != to_task) |
97 | { | 97 | { |
98 | GNUNET_SCHEDULER_cancel (to_task); | 98 | GNUNET_SCHEDULER_cancel(to_task); |
99 | to_task = NULL; | 99 | to_task = NULL; |
100 | } | 100 | } |
101 | if (NULL != lr) | 101 | if (NULL != lr) |
102 | { | 102 | { |
103 | GNUNET_GNS_lookup_with_tld_cancel (lr); | 103 | GNUNET_GNS_lookup_with_tld_cancel(lr); |
104 | lr = NULL; | 104 | lr = NULL; |
105 | } | 105 | } |
106 | if (NULL != gns) | 106 | if (NULL != gns) |
107 | { | 107 | { |
108 | GNUNET_GNS_disconnect (gns); | 108 | GNUNET_GNS_disconnect(gns); |
109 | gns = NULL; | 109 | gns = NULL; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | /** | 113 | /** |
@@ -116,11 +116,11 @@ do_shutdown (void *cls) | |||
116 | * @param cls unused | 116 | * @param cls unused |
117 | */ | 117 | */ |
118 | static void | 118 | static void |
119 | do_timeout (void* cls) | 119 | do_timeout(void* cls) |
120 | { | 120 | { |
121 | to_task = NULL; | 121 | to_task = NULL; |
122 | global_ret = 3; //Timeout | 122 | global_ret = 3; //Timeout |
123 | GNUNET_SCHEDULER_shutdown (); | 123 | GNUNET_SCHEDULER_shutdown(); |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
@@ -132,10 +132,10 @@ do_timeout (void* cls) | |||
132 | * @param rd array of @a rd_count records with the results | 132 | * @param rd array of @a rd_count records with the results |
133 | */ | 133 | */ |
134 | static void | 134 | static void |
135 | process_lookup_result (void *cls, | 135 | process_lookup_result(void *cls, |
136 | int was_gns, | 136 | int was_gns, |
137 | uint32_t rd_count, | 137 | uint32_t rd_count, |
138 | const struct GNUNET_GNSRECORD_Data *rd) | 138 | const struct GNUNET_GNSRECORD_Data *rd) |
139 | { | 139 | { |
140 | const char *name = cls; | 140 | const char *name = cls; |
141 | const char *typename; | 141 | const char *typename; |
@@ -143,41 +143,41 @@ process_lookup_result (void *cls, | |||
143 | 143 | ||
144 | lr = NULL; | 144 | lr = NULL; |
145 | if (GNUNET_NO == was_gns) | 145 | if (GNUNET_NO == was_gns) |
146 | { | 146 | { |
147 | global_ret = 4; /* not for GNS */ | 147 | global_ret = 4; /* not for GNS */ |
148 | GNUNET_SCHEDULER_shutdown (); | 148 | GNUNET_SCHEDULER_shutdown(); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | if (! raw) | 151 | if (!raw) |
152 | { | 152 | { |
153 | if (0 == rd_count) | 153 | if (0 == rd_count) |
154 | printf ("No results.\n"); | 154 | printf("No results.\n"); |
155 | else | 155 | else |
156 | printf ("%s:\n", name); | 156 | printf("%s:\n", name); |
157 | } | 157 | } |
158 | for (uint32_t i = 0; i < rd_count; i++) | 158 | for (uint32_t i = 0; i < rd_count; i++) |
159 | { | ||
160 | if ((rd[i].record_type != rtype) && (GNUNET_GNSRECORD_TYPE_ANY != rtype)) | ||
161 | continue; | ||
162 | typename = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
163 | string_val = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
164 | rd[i].data, | ||
165 | rd[i].data_size); | ||
166 | if (NULL == string_val) | ||
167 | { | 159 | { |
168 | fprintf (stderr, | 160 | if ((rd[i].record_type != rtype) && (GNUNET_GNSRECORD_TYPE_ANY != rtype)) |
169 | "Record %u of type %d malformed, skipping\n", | 161 | continue; |
170 | (unsigned int) i, | 162 | typename = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type); |
171 | (int) rd[i].record_type); | 163 | string_val = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, |
172 | continue; | 164 | rd[i].data, |
165 | rd[i].data_size); | ||
166 | if (NULL == string_val) | ||
167 | { | ||
168 | fprintf(stderr, | ||
169 | "Record %u of type %d malformed, skipping\n", | ||
170 | (unsigned int)i, | ||
171 | (int)rd[i].record_type); | ||
172 | continue; | ||
173 | } | ||
174 | if (raw) | ||
175 | printf("%s\n", string_val); | ||
176 | else | ||
177 | printf("Got `%s' record: %s\n", typename, string_val); | ||
178 | GNUNET_free(string_val); | ||
173 | } | 179 | } |
174 | if (raw) | 180 | GNUNET_SCHEDULER_shutdown(); |
175 | printf ("%s\n", string_val); | ||
176 | else | ||
177 | printf ("Got `%s' record: %s\n", typename, string_val); | ||
178 | GNUNET_free (string_val); | ||
179 | } | ||
180 | GNUNET_SCHEDULER_shutdown (); | ||
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
@@ -190,53 +190,53 @@ process_lookup_result (void *cls, | |||
190 | * @param c configuration | 190 | * @param c configuration |
191 | */ | 191 | */ |
192 | static void | 192 | static void |
193 | run (void *cls, | 193 | run(void *cls, |
194 | char *const *args, | 194 | char *const *args, |
195 | const char *cfgfile, | 195 | const char *cfgfile, |
196 | const struct GNUNET_CONFIGURATION_Handle *c) | 196 | const struct GNUNET_CONFIGURATION_Handle *c) |
197 | { | 197 | { |
198 | (void) cls; | 198 | (void)cls; |
199 | (void) args; | 199 | (void)args; |
200 | (void) cfgfile; | 200 | (void)cfgfile; |
201 | 201 | ||
202 | cfg = c; | 202 | cfg = c; |
203 | to_task = NULL; | 203 | to_task = NULL; |
204 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (lookup_name)) | 204 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name(lookup_name)) |
205 | { | 205 | { |
206 | fprintf (stderr, _ ("`%s' is not a valid domain name\n"), lookup_name); | 206 | fprintf(stderr, _("`%s' is not a valid domain name\n"), lookup_name); |
207 | global_ret = 3; | 207 | global_ret = 3; |
208 | return; | 208 | return; |
209 | } | 209 | } |
210 | to_task = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, NULL); | 210 | to_task = GNUNET_SCHEDULER_add_delayed(timeout, &do_timeout, NULL); |
211 | gns = GNUNET_GNS_connect (cfg); | 211 | gns = GNUNET_GNS_connect(cfg); |
212 | if (NULL == gns) | 212 | if (NULL == gns) |
213 | { | 213 | { |
214 | fprintf (stderr, _ ("Failed to connect to GNS\n")); | 214 | fprintf(stderr, _("Failed to connect to GNS\n")); |
215 | global_ret = 2; | 215 | global_ret = 2; |
216 | return; | 216 | return; |
217 | } | 217 | } |
218 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 218 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
219 | if (NULL != lookup_type) | 219 | if (NULL != lookup_type) |
220 | rtype = GNUNET_GNSRECORD_typename_to_number (lookup_type); | 220 | rtype = GNUNET_GNSRECORD_typename_to_number(lookup_type); |
221 | else | 221 | else |
222 | rtype = GNUNET_DNSPARSER_TYPE_A; | 222 | rtype = GNUNET_DNSPARSER_TYPE_A; |
223 | if (UINT32_MAX == rtype) | 223 | if (UINT32_MAX == rtype) |
224 | { | 224 | { |
225 | fprintf (stderr, _ ("Invalid typename specified, assuming `ANY'\n")); | 225 | fprintf(stderr, _("Invalid typename specified, assuming `ANY'\n")); |
226 | rtype = GNUNET_GNSRECORD_TYPE_ANY; | 226 | rtype = GNUNET_GNSRECORD_TYPE_ANY; |
227 | } | 227 | } |
228 | lr = GNUNET_GNS_lookup_with_tld (gns, | 228 | lr = GNUNET_GNS_lookup_with_tld(gns, |
229 | lookup_name, | 229 | lookup_name, |
230 | rtype, | 230 | rtype, |
231 | GNUNET_GNS_LO_DEFAULT, | 231 | GNUNET_GNS_LO_DEFAULT, |
232 | &process_lookup_result, | 232 | &process_lookup_result, |
233 | lookup_name); | 233 | lookup_name); |
234 | if (NULL == lr) | 234 | if (NULL == lr) |
235 | { | 235 | { |
236 | global_ret = 2; | 236 | global_ret = 2; |
237 | GNUNET_SCHEDULER_shutdown (); | 237 | GNUNET_SCHEDULER_shutdown(); |
238 | return; | 238 | return; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
@@ -248,48 +248,48 @@ run (void *cls, | |||
248 | * @return 0 ok, 1 on error | 248 | * @return 0 ok, 1 on error |
249 | */ | 249 | */ |
250 | int | 250 | int |
251 | main (int argc, char *const *argv) | 251 | main(int argc, char *const *argv) |
252 | { | 252 | { |
253 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 253 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
254 | struct GNUNET_GETOPT_CommandLineOption options[] = | 254 | struct GNUNET_GETOPT_CommandLineOption options[] = |
255 | {GNUNET_GETOPT_option_mandatory ( | 255 | { GNUNET_GETOPT_option_mandatory( |
256 | GNUNET_GETOPT_option_string ('u', | 256 | GNUNET_GETOPT_option_string('u', |
257 | "lookup", | 257 | "lookup", |
258 | "NAME", | 258 | "NAME", |
259 | gettext_noop ( | 259 | gettext_noop( |
260 | "Lookup a record for the given name"), | 260 | "Lookup a record for the given name"), |
261 | &lookup_name)), | 261 | &lookup_name)), |
262 | GNUNET_GETOPT_option_string ('t', | 262 | GNUNET_GETOPT_option_string('t', |
263 | "type", | 263 | "type", |
264 | "TYPE", | 264 | "TYPE", |
265 | gettext_noop ( | 265 | gettext_noop( |
266 | "Specify the type of the record to lookup"), | 266 | "Specify the type of the record to lookup"), |
267 | &lookup_type), | 267 | &lookup_type), |
268 | GNUNET_GETOPT_option_relative_time ('T', | 268 | GNUNET_GETOPT_option_relative_time('T', |
269 | "timeout", | 269 | "timeout", |
270 | "TIMEOUT", | 270 | "TIMEOUT", |
271 | gettext_noop ( | 271 | gettext_noop( |
272 | "Specify a timeout for the lookup"), | 272 | "Specify a timeout for the lookup"), |
273 | &timeout), | 273 | &timeout), |
274 | GNUNET_GETOPT_option_flag ('r', | 274 | GNUNET_GETOPT_option_flag('r', |
275 | "raw", | 275 | "raw", |
276 | gettext_noop ("No unneeded output"), | 276 | gettext_noop("No unneeded output"), |
277 | &raw), | 277 | &raw), |
278 | GNUNET_GETOPT_OPTION_END}; | 278 | GNUNET_GETOPT_OPTION_END }; |
279 | int ret; | 279 | int ret; |
280 | 280 | ||
281 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 281 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
282 | return 2; | 282 | return 2; |
283 | 283 | ||
284 | GNUNET_log_setup ("gnunet-gns", "WARNING", NULL); | 284 | GNUNET_log_setup("gnunet-gns", "WARNING", NULL); |
285 | ret = GNUNET_PROGRAM_run (argc, | 285 | ret = GNUNET_PROGRAM_run(argc, |
286 | argv, | 286 | argv, |
287 | "gnunet-gns", | 287 | "gnunet-gns", |
288 | _ ("GNUnet GNS resolver tool"), | 288 | _("GNUnet GNS resolver tool"), |
289 | options, | 289 | options, |
290 | &run, | 290 | &run, |
291 | NULL); | 291 | NULL); |
292 | GNUNET_free ((void *) argv); | 292 | GNUNET_free((void *)argv); |
293 | if (GNUNET_OK != ret) | 293 | if (GNUNET_OK != ret) |
294 | return 1; | 294 | return 1; |
295 | return global_ret; | 295 | return global_ret; |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 65c232f93..5bfaf4859 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gnunet-service-gns.c | 21 | * @file gns/gnunet-service-gns.c |
22 | * @brief GNU Name System (main service) | 22 | * @brief GNU Name System (main service) |
@@ -46,9 +46,7 @@ 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 | */ |
49 | struct ClientLookupHandle | 49 | struct ClientLookupHandle { |
50 | { | ||
51 | |||
52 | /** | 50 | /** |
53 | * We keep these in a DLL. | 51 | * We keep these in a DLL. |
54 | */ | 52 | */ |
@@ -73,15 +71,13 @@ struct ClientLookupHandle | |||
73 | * request id | 71 | * request id |
74 | */ | 72 | */ |
75 | uint32_t request_id; | 73 | uint32_t request_id; |
76 | |||
77 | }; | 74 | }; |
78 | 75 | ||
79 | 76 | ||
80 | /** | 77 | /** |
81 | * Information we track per connected client. | 78 | * Information we track per connected client. |
82 | */ | 79 | */ |
83 | struct GnsClient | 80 | struct GnsClient { |
84 | { | ||
85 | /** | 81 | /** |
86 | * The client | 82 | * The client |
87 | */ | 83 | */ |
@@ -108,9 +104,7 @@ struct GnsClient | |||
108 | * Representation of a TLD, mapping the respective TLD string | 104 | * Representation of a TLD, mapping the respective TLD string |
109 | * (i.e. ".gnu") to the respective public key of the zone. | 105 | * (i.e. ".gnu") to the respective public key of the zone. |
110 | */ | 106 | */ |
111 | struct GNS_TopLevelDomain | 107 | struct GNS_TopLevelDomain { |
112 | { | ||
113 | |||
114 | /** | 108 | /** |
115 | * Kept in a DLL, as there are unlikely enough of these to | 109 | * Kept in a DLL, as there are unlikely enough of these to |
116 | * warrant a hash map. | 110 | * warrant a hash map. |
@@ -132,7 +126,6 @@ struct GNS_TopLevelDomain | |||
132 | * Top-level domain as a string, including leading ".". | 126 | * Top-level domain as a string, including leading ".". |
133 | */ | 127 | */ |
134 | char *tld; | 128 | char *tld; |
135 | |||
136 | }; | 129 | }; |
137 | 130 | ||
138 | 131 | ||
@@ -180,25 +173,25 @@ static struct GNS_TopLevelDomain *tld_tail; | |||
180 | * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not | 173 | * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not |
181 | */ | 174 | */ |
182 | int | 175 | int |
183 | GNS_find_tld (const char *tld_str, | 176 | GNS_find_tld(const char *tld_str, |
184 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 177 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) |
185 | { | 178 | { |
186 | if ('\0' == *tld_str) | 179 | if ('\0' == *tld_str) |
187 | return GNUNET_NO; | 180 | return GNUNET_NO; |
188 | for (struct GNS_TopLevelDomain *tld = tld_head; | 181 | for (struct GNS_TopLevelDomain *tld = tld_head; |
189 | NULL != tld; | 182 | NULL != tld; |
190 | tld = tld->next) | 183 | tld = tld->next) |
191 | { | ||
192 | if (0 == strcasecmp (tld_str, | ||
193 | tld->tld)) | ||
194 | { | 184 | { |
195 | *pkey = tld->pkey; | 185 | if (0 == strcasecmp(tld_str, |
196 | return GNUNET_YES; | 186 | tld->tld)) |
187 | { | ||
188 | *pkey = tld->pkey; | ||
189 | return GNUNET_YES; | ||
190 | } | ||
197 | } | 191 | } |
198 | } | ||
199 | if (GNUNET_OK == | 192 | if (GNUNET_OK == |
200 | GNUNET_GNSRECORD_zkey_to_pkey (tld_str + 1, | 193 | GNUNET_GNSRECORD_zkey_to_pkey(tld_str + 1, |
201 | pkey)) | 194 | pkey)) |
202 | return GNUNET_YES; /* TLD string *was* the public key */ | 195 | return GNUNET_YES; /* TLD string *was* the public key */ |
203 | return GNUNET_NO; | 196 | return GNUNET_NO; |
204 | } | 197 | } |
@@ -212,12 +205,12 @@ GNS_find_tld (const char *tld_str, | |||
212 | * or @a name if @a name does not contain a "." | 205 | * or @a name if @a name does not contain a "." |
213 | */ | 206 | */ |
214 | const char * | 207 | const char * |
215 | GNS_get_tld (const char *name) | 208 | GNS_get_tld(const char *name) |
216 | { | 209 | { |
217 | const char *tld; | 210 | const char *tld; |
218 | 211 | ||
219 | tld = strrchr (name, | 212 | tld = strrchr(name, |
220 | (unsigned char) '.'); | 213 | (unsigned char)'.'); |
221 | if (NULL == tld) | 214 | if (NULL == tld) |
222 | tld = name; | 215 | tld = name; |
223 | else | 216 | else |
@@ -232,39 +225,39 @@ GNS_get_tld (const char *name) | |||
232 | * @param cls unused, NULL | 225 | * @param cls unused, NULL |
233 | */ | 226 | */ |
234 | static void | 227 | static void |
235 | shutdown_task (void *cls) | 228 | shutdown_task(void *cls) |
236 | { | 229 | { |
237 | struct GNS_TopLevelDomain *tld; | 230 | struct GNS_TopLevelDomain *tld; |
238 | 231 | ||
239 | (void) cls; | 232 | (void)cls; |
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 233 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
241 | "Shutting down!\n"); | 234 | "Shutting down!\n"); |
242 | GNS_interceptor_done (); | 235 | GNS_interceptor_done(); |
243 | GNS_resolver_done (); | 236 | GNS_resolver_done(); |
244 | if (NULL != statistics) | 237 | if (NULL != statistics) |
245 | { | 238 | { |
246 | GNUNET_STATISTICS_destroy (statistics, | 239 | GNUNET_STATISTICS_destroy(statistics, |
247 | GNUNET_NO); | 240 | GNUNET_NO); |
248 | statistics = NULL; | 241 | statistics = NULL; |
249 | } | 242 | } |
250 | if (NULL != namecache_handle) | 243 | if (NULL != namecache_handle) |
251 | { | 244 | { |
252 | GNUNET_NAMECACHE_disconnect (namecache_handle); | 245 | GNUNET_NAMECACHE_disconnect(namecache_handle); |
253 | namecache_handle = NULL; | 246 | namecache_handle = NULL; |
254 | } | 247 | } |
255 | if (NULL != dht_handle) | 248 | if (NULL != dht_handle) |
256 | { | 249 | { |
257 | GNUNET_DHT_disconnect (dht_handle); | 250 | GNUNET_DHT_disconnect(dht_handle); |
258 | dht_handle = NULL; | 251 | dht_handle = NULL; |
259 | } | 252 | } |
260 | while (NULL != (tld = tld_head)) | 253 | while (NULL != (tld = tld_head)) |
261 | { | 254 | { |
262 | GNUNET_CONTAINER_DLL_remove (tld_head, | 255 | GNUNET_CONTAINER_DLL_remove(tld_head, |
263 | tld_tail, | 256 | tld_tail, |
264 | tld); | 257 | tld); |
265 | GNUNET_free (tld->tld); | 258 | GNUNET_free(tld->tld); |
266 | GNUNET_free (tld); | 259 | GNUNET_free(tld); |
267 | } | 260 | } |
268 | } | 261 | } |
269 | 262 | ||
270 | 263 | ||
@@ -276,27 +269,27 @@ shutdown_task (void *cls) | |||
276 | * @param app_ctx @a client | 269 | * @param app_ctx @a client |
277 | */ | 270 | */ |
278 | static void | 271 | static void |
279 | client_disconnect_cb (void *cls, | 272 | client_disconnect_cb(void *cls, |
280 | struct GNUNET_SERVICE_Client *client, | 273 | struct GNUNET_SERVICE_Client *client, |
281 | void *app_ctx) | 274 | void *app_ctx) |
282 | { | 275 | { |
283 | struct ClientLookupHandle *clh; | 276 | struct ClientLookupHandle *clh; |
284 | struct GnsClient *gc = app_ctx; | 277 | struct GnsClient *gc = app_ctx; |
285 | 278 | ||
286 | (void) cls; | 279 | (void)cls; |
287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 280 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
288 | "Client %p disconnected\n", | 281 | "Client %p disconnected\n", |
289 | client); | 282 | client); |
290 | while (NULL != (clh = gc->clh_head)) | 283 | while (NULL != (clh = gc->clh_head)) |
291 | { | 284 | { |
292 | if (NULL != clh->lookup) | 285 | if (NULL != clh->lookup) |
293 | GNS_resolver_lookup_cancel (clh->lookup); | 286 | GNS_resolver_lookup_cancel(clh->lookup); |
294 | GNUNET_CONTAINER_DLL_remove (gc->clh_head, | 287 | GNUNET_CONTAINER_DLL_remove(gc->clh_head, |
295 | gc->clh_tail, | 288 | gc->clh_tail, |
296 | clh); | 289 | clh); |
297 | GNUNET_free (clh); | 290 | GNUNET_free(clh); |
298 | } | 291 | } |
299 | GNUNET_free (gc); | 292 | GNUNET_free(gc); |
300 | } | 293 | } |
301 | 294 | ||
302 | 295 | ||
@@ -309,17 +302,17 @@ client_disconnect_cb (void *cls, | |||
309 | * @return internal namestore client structure for this client | 302 | * @return internal namestore client structure for this client |
310 | */ | 303 | */ |
311 | static void * | 304 | static void * |
312 | client_connect_cb (void *cls, | 305 | client_connect_cb(void *cls, |
313 | struct GNUNET_SERVICE_Client *client, | 306 | struct GNUNET_SERVICE_Client *client, |
314 | struct GNUNET_MQ_Handle *mq) | 307 | struct GNUNET_MQ_Handle *mq) |
315 | { | 308 | { |
316 | struct GnsClient *gc; | 309 | struct GnsClient *gc; |
317 | 310 | ||
318 | (void) cls; | 311 | (void)cls; |
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 312 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
320 | "Client %p connected\n", | 313 | "Client %p connected\n", |
321 | client); | 314 | client); |
322 | gc = GNUNET_new (struct GnsClient); | 315 | gc = GNUNET_new(struct GnsClient); |
323 | gc->client = client; | 316 | gc->client = client; |
324 | gc->mq = mq; | 317 | gc->mq = mq; |
325 | return gc; | 318 | return gc; |
@@ -334,9 +327,9 @@ client_connect_cb (void *cls, | |||
334 | * @param rd the record data | 327 | * @param rd the record data |
335 | */ | 328 | */ |
336 | static void | 329 | static void |
337 | send_lookup_response (void *cls, | 330 | send_lookup_response(void *cls, |
338 | uint32_t rd_count, | 331 | uint32_t rd_count, |
339 | const struct GNUNET_GNSRECORD_Data *rd) | 332 | const struct GNUNET_GNSRECORD_Data *rd) |
340 | { | 333 | { |
341 | struct ClientLookupHandle *clh = cls; | 334 | struct ClientLookupHandle *clh = cls; |
342 | struct GnsClient *gc = clh->gc; | 335 | struct GnsClient *gc = clh->gc; |
@@ -344,46 +337,46 @@ send_lookup_response (void *cls, | |||
344 | struct LookupResultMessage *rmsg; | 337 | struct LookupResultMessage *rmsg; |
345 | ssize_t len; | 338 | ssize_t len; |
346 | 339 | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
348 | "Sending LOOKUP_RESULT message with %u results\n", | 341 | "Sending LOOKUP_RESULT message with %u results\n", |
349 | (unsigned int) rd_count); | 342 | (unsigned int)rd_count); |
350 | len = GNUNET_GNSRECORD_records_get_size (rd_count, | 343 | len = GNUNET_GNSRECORD_records_get_size(rd_count, |
351 | rd); | 344 | rd); |
352 | if (len < 0) | 345 | if (len < 0) |
353 | { | 346 | { |
354 | GNUNET_break (0); | 347 | GNUNET_break(0); |
355 | GNUNET_SERVICE_client_drop (gc->client); | 348 | GNUNET_SERVICE_client_drop(gc->client); |
356 | return; | 349 | return; |
357 | } | 350 | } |
358 | if (len > UINT16_MAX - sizeof (*rmsg)) | 351 | if (len > UINT16_MAX - sizeof(*rmsg)) |
359 | { | 352 | { |
360 | GNUNET_break (0); | 353 | GNUNET_break(0); |
361 | GNUNET_SERVICE_client_drop (gc->client); | 354 | GNUNET_SERVICE_client_drop(gc->client); |
362 | return; | 355 | return; |
363 | } | 356 | } |
364 | env = GNUNET_MQ_msg_extra (rmsg, | 357 | env = GNUNET_MQ_msg_extra(rmsg, |
365 | len, | 358 | len, |
366 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); | 359 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); |
367 | rmsg->id = clh->request_id; | 360 | rmsg->id = clh->request_id; |
368 | rmsg->rd_count = htonl (rd_count); | 361 | rmsg->rd_count = htonl(rd_count); |
369 | GNUNET_assert (len == | 362 | GNUNET_assert(len == |
370 | GNUNET_GNSRECORD_records_serialize (rd_count, | 363 | GNUNET_GNSRECORD_records_serialize(rd_count, |
371 | rd, | 364 | rd, |
372 | len, | 365 | len, |
373 | (char*) &rmsg[1])); | 366 | (char*)&rmsg[1])); |
374 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (gc->client), | 367 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(gc->client), |
375 | env); | 368 | env); |
376 | GNUNET_CONTAINER_DLL_remove (gc->clh_head, | 369 | GNUNET_CONTAINER_DLL_remove(gc->clh_head, |
377 | gc->clh_tail, | 370 | gc->clh_tail, |
378 | clh); | 371 | clh); |
379 | GNUNET_free (clh); | 372 | GNUNET_free(clh); |
380 | GNUNET_STATISTICS_update (statistics, | 373 | GNUNET_STATISTICS_update(statistics, |
381 | "Completed lookups", 1, | 374 | "Completed lookups", 1, |
382 | GNUNET_NO); | 375 | GNUNET_NO); |
383 | GNUNET_STATISTICS_update (statistics, | 376 | GNUNET_STATISTICS_update(statistics, |
384 | "Records resolved", | 377 | "Records resolved", |
385 | rd_count, | 378 | rd_count, |
386 | GNUNET_NO); | 379 | GNUNET_NO); |
387 | } | 380 | } |
388 | 381 | ||
389 | 382 | ||
@@ -395,19 +388,19 @@ send_lookup_response (void *cls, | |||
395 | * @return #GNUNET_OK if @a l_msg is well-formed | 388 | * @return #GNUNET_OK if @a l_msg is well-formed |
396 | */ | 389 | */ |
397 | static int | 390 | static int |
398 | check_lookup (void *cls, | 391 | check_lookup(void *cls, |
399 | const struct LookupMessage *l_msg) | 392 | const struct LookupMessage *l_msg) |
400 | { | 393 | { |
401 | size_t nlen; | 394 | size_t nlen; |
402 | 395 | ||
403 | (void) cls; | 396 | (void)cls; |
404 | GNUNET_MQ_check_zero_termination (l_msg); | 397 | GNUNET_MQ_check_zero_termination(l_msg); |
405 | nlen = ntohs (l_msg->header.size) - sizeof (struct LookupMessage); | 398 | nlen = ntohs(l_msg->header.size) - sizeof(struct LookupMessage); |
406 | if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH) | 399 | if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH) |
407 | { | 400 | { |
408 | GNUNET_break (0); | 401 | GNUNET_break(0); |
409 | return GNUNET_SYSERR; | 402 | return GNUNET_SYSERR; |
410 | } | 403 | } |
411 | return GNUNET_OK; | 404 | return GNUNET_OK; |
412 | } | 405 | } |
413 | 406 | ||
@@ -420,8 +413,8 @@ check_lookup (void *cls, | |||
420 | * @param message the message | 413 | * @param message the message |
421 | */ | 414 | */ |
422 | static void | 415 | static void |
423 | handle_lookup (void *cls, | 416 | handle_lookup(void *cls, |
424 | const struct LookupMessage *sh_msg) | 417 | const struct LookupMessage *sh_msg) |
425 | { | 418 | { |
426 | struct GnsClient *gc = cls; | 419 | struct GnsClient *gc = cls; |
427 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1]; | 420 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1]; |
@@ -429,47 +422,47 @@ handle_lookup (void *cls, | |||
429 | char *nameptr = name; | 422 | char *nameptr = name; |
430 | const char *utf_in; | 423 | const char *utf_in; |
431 | 424 | ||
432 | GNUNET_SERVICE_client_continue (gc->client); | 425 | GNUNET_SERVICE_client_continue(gc->client); |
433 | utf_in = (const char *) &sh_msg[1]; | 426 | utf_in = (const char *)&sh_msg[1]; |
434 | GNUNET_STRINGS_utf8_tolower (utf_in, | 427 | GNUNET_STRINGS_utf8_tolower(utf_in, |
435 | nameptr); | 428 | nameptr); |
436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
437 | "Received LOOKUP `%s' message\n", | 430 | "Received LOOKUP `%s' message\n", |
438 | name); | 431 | name); |
439 | clh = GNUNET_new (struct ClientLookupHandle); | 432 | clh = GNUNET_new(struct ClientLookupHandle); |
440 | GNUNET_CONTAINER_DLL_insert (gc->clh_head, | 433 | GNUNET_CONTAINER_DLL_insert(gc->clh_head, |
441 | gc->clh_tail, | 434 | gc->clh_tail, |
442 | clh); | 435 | clh); |
443 | clh->gc = gc; | 436 | clh->gc = gc; |
444 | clh->request_id = sh_msg->id; | 437 | clh->request_id = sh_msg->id; |
445 | if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) && | 438 | if ((GNUNET_DNSPARSER_TYPE_A == ntohl(sh_msg->type)) && |
446 | (GNUNET_OK != v4_enabled) ) | 439 | (GNUNET_OK != v4_enabled)) |
447 | { | 440 | { |
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 441 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
449 | "LOOKUP: Query for A record but AF_INET not supported!"); | 442 | "LOOKUP: Query for A record but AF_INET not supported!"); |
450 | send_lookup_response (clh, | 443 | send_lookup_response(clh, |
451 | 0, | 444 | 0, |
452 | NULL); | 445 | NULL); |
453 | return; | 446 | return; |
454 | } | 447 | } |
455 | if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) && | 448 | if ((GNUNET_DNSPARSER_TYPE_AAAA == ntohl(sh_msg->type)) && |
456 | (GNUNET_OK != v6_enabled) ) | 449 | (GNUNET_OK != v6_enabled)) |
457 | { | 450 | { |
458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
459 | "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); | 452 | "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); |
460 | send_lookup_response (clh, | 453 | send_lookup_response(clh, |
461 | 0, | 454 | 0, |
462 | NULL); | 455 | NULL); |
463 | return; | 456 | return; |
464 | } | 457 | } |
465 | clh->lookup = GNS_resolver_lookup (&sh_msg->zone, | 458 | clh->lookup = GNS_resolver_lookup(&sh_msg->zone, |
466 | ntohl (sh_msg->type), | 459 | ntohl(sh_msg->type), |
467 | name, | 460 | name, |
468 | (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options), | 461 | (enum GNUNET_GNS_LocalOptions)ntohs(sh_msg->options), |
469 | &send_lookup_response, clh); | 462 | &send_lookup_response, clh); |
470 | GNUNET_STATISTICS_update (statistics, | 463 | GNUNET_STATISTICS_update(statistics, |
471 | "Lookup attempts", | 464 | "Lookup attempts", |
472 | 1, GNUNET_NO); | 465 | 1, GNUNET_NO); |
473 | } | 466 | } |
474 | 467 | ||
475 | 468 | ||
@@ -482,36 +475,36 @@ handle_lookup (void *cls, | |||
482 | * @param value value for the option, public key for TLDs | 475 | * @param value value for the option, public key for TLDs |
483 | */ | 476 | */ |
484 | static void | 477 | static void |
485 | read_service_conf (void *cls, | 478 | read_service_conf(void *cls, |
486 | const char *section, | 479 | const char *section, |
487 | const char *option, | 480 | const char *option, |
488 | const char *value) | 481 | const char *value) |
489 | { | 482 | { |
490 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 483 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
491 | struct GNS_TopLevelDomain *tld; | 484 | struct GNS_TopLevelDomain *tld; |
492 | 485 | ||
493 | (void) cls; | 486 | (void)cls; |
494 | (void) section; | 487 | (void)section; |
495 | if (option[0] != '.') | 488 | if (option[0] != '.') |
496 | return; | 489 | return; |
497 | if (GNUNET_OK != | 490 | if (GNUNET_OK != |
498 | GNUNET_STRINGS_string_to_data (value, | 491 | GNUNET_STRINGS_string_to_data(value, |
499 | strlen (value), | 492 | strlen(value), |
500 | &pk, | 493 | &pk, |
501 | sizeof (pk))) | 494 | sizeof(pk))) |
502 | { | 495 | { |
503 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 496 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, |
504 | section, | 497 | section, |
505 | option, | 498 | option, |
506 | _("Properly base32-encoded public key required")); | 499 | _("Properly base32-encoded public key required")); |
507 | return; | 500 | return; |
508 | } | 501 | } |
509 | tld = GNUNET_new (struct GNS_TopLevelDomain); | 502 | tld = GNUNET_new(struct GNS_TopLevelDomain); |
510 | tld->tld = GNUNET_strdup (&option[1]); | 503 | tld->tld = GNUNET_strdup(&option[1]); |
511 | tld->pkey = pk; | 504 | tld->pkey = pk; |
512 | GNUNET_CONTAINER_DLL_insert (tld_head, | 505 | GNUNET_CONTAINER_DLL_insert(tld_head, |
513 | tld_tail, | 506 | tld_tail, |
514 | tld); | 507 | tld); |
515 | } | 508 | } |
516 | 509 | ||
517 | 510 | ||
@@ -523,66 +516,66 @@ read_service_conf (void *cls, | |||
523 | * @param c configuration to use | 516 | * @param c configuration to use |
524 | */ | 517 | */ |
525 | static void | 518 | static void |
526 | run (void *cls, | 519 | run(void *cls, |
527 | const struct GNUNET_CONFIGURATION_Handle *c, | 520 | const struct GNUNET_CONFIGURATION_Handle *c, |
528 | struct GNUNET_SERVICE_Handle *service) | 521 | struct GNUNET_SERVICE_Handle *service) |
529 | { | 522 | { |
530 | unsigned long long max_parallel_bg_queries = 16; | 523 | unsigned long long max_parallel_bg_queries = 16; |
531 | 524 | ||
532 | GNUNET_CONFIGURATION_iterate_section_values (c, | 525 | GNUNET_CONFIGURATION_iterate_section_values(c, |
533 | "gns", | 526 | "gns", |
534 | &read_service_conf, | 527 | &read_service_conf, |
535 | NULL); | 528 | NULL); |
536 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); | 529 | v6_enabled = GNUNET_NETWORK_test_pf(PF_INET6); |
537 | v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); | 530 | v4_enabled = GNUNET_NETWORK_test_pf(PF_INET); |
538 | namecache_handle = GNUNET_NAMECACHE_connect (c); | 531 | namecache_handle = GNUNET_NAMECACHE_connect(c); |
539 | if (NULL == namecache_handle) | 532 | if (NULL == namecache_handle) |
540 | { | 533 | { |
541 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 534 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
542 | _("Failed to connect to the namecache!\n")); | 535 | _("Failed to connect to the namecache!\n")); |
543 | GNUNET_SCHEDULER_shutdown (); | 536 | GNUNET_SCHEDULER_shutdown(); |
544 | return; | 537 | return; |
545 | } | 538 | } |
546 | if (GNUNET_OK == | 539 | if (GNUNET_OK == |
547 | GNUNET_CONFIGURATION_get_value_number (c, | 540 | GNUNET_CONFIGURATION_get_value_number(c, |
548 | "gns", | 541 | "gns", |
549 | "MAX_PARALLEL_BACKGROUND_QUERIES", | 542 | "MAX_PARALLEL_BACKGROUND_QUERIES", |
550 | &max_parallel_bg_queries)) | 543 | &max_parallel_bg_queries)) |
551 | { | 544 | { |
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 545 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
553 | "Number of allowed parallel background queries: %llu\n", | 546 | "Number of allowed parallel background queries: %llu\n", |
554 | max_parallel_bg_queries); | 547 | max_parallel_bg_queries); |
555 | } | 548 | } |
556 | dht_handle = GNUNET_DHT_connect (c, | 549 | dht_handle = GNUNET_DHT_connect(c, |
557 | (unsigned int) max_parallel_bg_queries); | 550 | (unsigned int)max_parallel_bg_queries); |
558 | if (NULL == dht_handle) | 551 | if (NULL == dht_handle) |
559 | { | 552 | { |
560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 553 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
561 | _("Could not connect to DHT!\n")); | 554 | _("Could not connect to DHT!\n")); |
562 | GNUNET_SCHEDULER_add_now (&shutdown_task, | 555 | GNUNET_SCHEDULER_add_now(&shutdown_task, |
563 | NULL); | 556 | NULL); |
564 | return; | 557 | return; |
565 | } | 558 | } |
566 | GNS_resolver_init (namecache_handle, | 559 | GNS_resolver_init(namecache_handle, |
567 | dht_handle, | 560 | dht_handle, |
568 | c, | 561 | c, |
569 | max_parallel_bg_queries); | 562 | max_parallel_bg_queries); |
570 | if ( (GNUNET_YES == | 563 | if ((GNUNET_YES == |
571 | GNUNET_CONFIGURATION_get_value_yesno (c, | 564 | GNUNET_CONFIGURATION_get_value_yesno(c, |
572 | "gns", | 565 | "gns", |
573 | "INTERCEPT_DNS")) && | 566 | "INTERCEPT_DNS")) && |
574 | (GNUNET_SYSERR == | 567 | (GNUNET_SYSERR == |
575 | GNS_interceptor_init (c)) ) | 568 | GNS_interceptor_init(c))) |
576 | { | 569 | { |
577 | GNUNET_break (0); | 570 | GNUNET_break(0); |
578 | GNUNET_SCHEDULER_add_now (&shutdown_task, | 571 | GNUNET_SCHEDULER_add_now(&shutdown_task, |
579 | NULL); | 572 | NULL); |
580 | return; | 573 | return; |
581 | } | 574 | } |
582 | statistics = GNUNET_STATISTICS_create ("gns", | 575 | statistics = GNUNET_STATISTICS_create("gns", |
583 | c); | 576 | c); |
584 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 577 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
585 | NULL); | 578 | NULL); |
586 | } | 579 | } |
587 | 580 | ||
588 | 581 | ||
@@ -590,17 +583,17 @@ run (void *cls, | |||
590 | * Define "main" method using service macro. | 583 | * Define "main" method using service macro. |
591 | */ | 584 | */ |
592 | GNUNET_SERVICE_MAIN | 585 | GNUNET_SERVICE_MAIN |
593 | ("gns", | 586 | ("gns", |
594 | GNUNET_SERVICE_OPTION_NONE, | 587 | GNUNET_SERVICE_OPTION_NONE, |
595 | &run, | 588 | &run, |
596 | &client_connect_cb, | 589 | &client_connect_cb, |
597 | &client_disconnect_cb, | 590 | &client_disconnect_cb, |
598 | NULL, | 591 | NULL, |
599 | GNUNET_MQ_hd_var_size (lookup, | 592 | GNUNET_MQ_hd_var_size(lookup, |
600 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP, | 593 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP, |
601 | struct LookupMessage, | 594 | struct LookupMessage, |
602 | NULL), | 595 | NULL), |
603 | GNUNET_MQ_handler_end()); | 596 | GNUNET_MQ_handler_end()); |
604 | 597 | ||
605 | 598 | ||
606 | /* end of gnunet-service-gns.c */ | 599 | /* end of gnunet-service-gns.c */ |
diff --git a/src/gns/gnunet-service-gns.h b/src/gns/gnunet-service-gns.h index d9309e985..2c17ca72a 100644 --- a/src/gns/gnunet-service-gns.h +++ b/src/gns/gnunet-service-gns.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gnunet-service-gns.h | 21 | * @file gns/gnunet-service-gns.h |
22 | * @brief GNU Name System (main service) | 22 | * @brief GNU Name System (main service) |
@@ -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 | */ |
37 | int | 37 | int |
38 | GNS_find_tld (const char *tld_str, | 38 | GNS_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 | */ |
49 | const char * | 49 | const char * |
50 | GNS_get_tld (const char *name); | 50 | GNS_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 d5a84f6a0..e56aaef47 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gnunet-service-gns_interceptor.c | 21 | * @file gns/gnunet-service-gns_interceptor.c |
22 | * @brief GNUnet GNS interceptor logic | 22 | * @brief GNUnet GNS interceptor logic |
@@ -37,9 +37,7 @@ | |||
37 | * Handle to a DNS intercepted | 37 | * Handle to a DNS intercepted |
38 | * reslution request | 38 | * reslution request |
39 | */ | 39 | */ |
40 | struct InterceptLookupHandle | 40 | struct InterceptLookupHandle { |
41 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * We keep these in a DLL. | 42 | * We keep these in a DLL. |
45 | */ | 43 | */ |
@@ -64,7 +62,6 @@ struct InterceptLookupHandle | |||
64 | * Handle for the lookup operation. | 62 | * Handle for the lookup operation. |
65 | */ | 63 | */ |
66 | struct GNS_ResolverHandle *lookup; | 64 | struct GNS_ResolverHandle *lookup; |
67 | |||
68 | }; | 65 | }; |
69 | 66 | ||
70 | 67 | ||
@@ -92,8 +89,8 @@ static struct InterceptLookupHandle *ilh_tail; | |||
92 | * @param rd the record data | 89 | * @param rd the record data |
93 | */ | 90 | */ |
94 | static void | 91 | static void |
95 | reply_to_dns (void *cls, uint32_t rd_count, | 92 | reply_to_dns(void *cls, uint32_t rd_count, |
96 | const struct GNUNET_GNSRECORD_Data *rd) | 93 | const struct GNUNET_GNSRECORD_Data *rd) |
97 | { | 94 | { |
98 | struct InterceptLookupHandle *ilh = cls; | 95 | struct InterceptLookupHandle *ilh = cls; |
99 | struct GNUNET_DNSPARSER_Packet *packet = ilh->packet; | 96 | struct GNUNET_DNSPARSER_Packet *packet = ilh->packet; |
@@ -109,7 +106,7 @@ reply_to_dns (void *cls, uint32_t rd_count, | |||
109 | 106 | ||
110 | /* Put records in the DNS packet */ | 107 | /* Put records in the DNS packet */ |
111 | num_answers = 0; | 108 | num_answers = 0; |
112 | for (i=0; i < rd_count; i++) | 109 | for (i = 0; i < rd_count; i++) |
113 | if (rd[i].record_type == query->type) | 110 | if (rd[i].record_type == query->type) |
114 | num_answers++; | 111 | num_answers++; |
115 | skip_answers = 0; | 112 | skip_answers = 0; |
@@ -124,123 +121,131 @@ reply_to_dns (void *cls, uint32_t rd_count, | |||
124 | /* FIXME: need to handle #GNUNET_GNSRECORD_RF_SHADOW_RECORD option | 121 | /* FIXME: need to handle #GNUNET_GNSRECORD_RF_SHADOW_RECORD option |
125 | (by ignoring records where this flag is set if there is any | 122 | (by ignoring records where this flag is set if there is any |
126 | other record of that type in the result set) */ | 123 | other record of that type in the result set) */ |
127 | for (i=0; i < rd_count; i++) | 124 | for (i = 0; i < rd_count; i++) |
128 | { | ||
129 | if (rd[i].record_type == query->type) | ||
130 | { | 125 | { |
131 | answer_records[i - skip_answers].name = query->name; | 126 | if (rd[i].record_type == query->type) |
132 | answer_records[i - skip_answers].type = rd[i].record_type; | 127 | { |
133 | switch(rd[i].record_type) | 128 | answer_records[i - skip_answers].name = query->name; |
134 | { | 129 | answer_records[i - skip_answers].type = rd[i].record_type; |
135 | case GNUNET_DNSPARSER_TYPE_NS: | 130 | switch (rd[i].record_type) |
136 | case GNUNET_DNSPARSER_TYPE_CNAME: | 131 | { |
137 | case GNUNET_DNSPARSER_TYPE_PTR: | 132 | case GNUNET_DNSPARSER_TYPE_NS: |
138 | answer_records[i - skip_answers].data.hostname | 133 | case GNUNET_DNSPARSER_TYPE_CNAME: |
139 | = GNUNET_DNSPARSER_parse_name (rd[i].data, | 134 | case GNUNET_DNSPARSER_TYPE_PTR: |
140 | rd[i].data_size, | 135 | answer_records[i - skip_answers].data.hostname |
141 | &off); | 136 | = GNUNET_DNSPARSER_parse_name(rd[i].data, |
142 | if ( (off != rd[i].data_size) || | 137 | rd[i].data_size, |
143 | (NULL == answer_records[i].data.hostname) ) | 138 | &off); |
144 | { | 139 | if ((off != rd[i].data_size) || |
145 | GNUNET_break_op (0); | 140 | (NULL == answer_records[i].data.hostname)) |
146 | skip_answers++; | 141 | { |
147 | } | 142 | GNUNET_break_op(0); |
148 | break; | 143 | skip_answers++; |
149 | case GNUNET_DNSPARSER_TYPE_SOA: | 144 | } |
150 | answer_records[i - skip_answers].data.soa | 145 | break; |
151 | = GNUNET_DNSPARSER_parse_soa (rd[i].data, | 146 | |
152 | rd[i].data_size, | 147 | case GNUNET_DNSPARSER_TYPE_SOA: |
153 | &off); | 148 | answer_records[i - skip_answers].data.soa |
154 | if ( (off != rd[i].data_size) || | 149 | = GNUNET_DNSPARSER_parse_soa(rd[i].data, |
155 | (NULL == answer_records[i].data.soa) ) | 150 | rd[i].data_size, |
156 | { | 151 | &off); |
157 | GNUNET_break_op (0); | 152 | if ((off != rd[i].data_size) || |
158 | skip_answers++; | 153 | (NULL == answer_records[i].data.soa)) |
159 | } | 154 | { |
160 | break; | 155 | GNUNET_break_op(0); |
161 | case GNUNET_DNSPARSER_TYPE_SRV: | 156 | skip_answers++; |
162 | /* FIXME: SRV is not yet supported */ | 157 | } |
163 | skip_answers++; | 158 | break; |
164 | break; | 159 | |
165 | case GNUNET_DNSPARSER_TYPE_MX: | 160 | case GNUNET_DNSPARSER_TYPE_SRV: |
166 | answer_records[i - skip_answers].data.mx | 161 | /* FIXME: SRV is not yet supported */ |
167 | = GNUNET_DNSPARSER_parse_mx (rd[i].data, | 162 | skip_answers++; |
168 | rd[i].data_size, | 163 | break; |
169 | &off); | 164 | |
170 | if ( (off != rd[i].data_size) || | 165 | case GNUNET_DNSPARSER_TYPE_MX: |
171 | (NULL == answer_records[i].data.hostname) ) | 166 | answer_records[i - skip_answers].data.mx |
172 | { | 167 | = GNUNET_DNSPARSER_parse_mx(rd[i].data, |
173 | GNUNET_break_op (0); | 168 | rd[i].data_size, |
174 | skip_answers++; | 169 | &off); |
175 | } | 170 | if ((off != rd[i].data_size) || |
176 | break; | 171 | (NULL == answer_records[i].data.hostname)) |
177 | default: | 172 | { |
178 | answer_records[i - skip_answers].data.raw.data_len = rd[i].data_size; | 173 | GNUNET_break_op(0); |
179 | answer_records[i - skip_answers].data.raw.data = (char*)rd[i].data; | 174 | skip_answers++; |
180 | break; | 175 | } |
181 | } | 176 | break; |
182 | GNUNET_break (0 == (rd[i - skip_answers].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)); | 177 | |
183 | answer_records[i - skip_answers].expiration_time.abs_value_us = rd[i].expiration_time; | 178 | default: |
184 | answer_records[i - skip_answers].dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 179 | answer_records[i - skip_answers].data.raw.data_len = rd[i].data_size; |
185 | } | 180 | answer_records[i - skip_answers].data.raw.data = (char*)rd[i].data; |
186 | else | 181 | break; |
187 | { | 182 | } |
188 | additional_records[i - skip_additional].name = query->name; | 183 | GNUNET_break(0 == (rd[i - skip_answers].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)); |
189 | additional_records[i - skip_additional].type = rd[i].record_type; | 184 | answer_records[i - skip_answers].expiration_time.abs_value_us = rd[i].expiration_time; |
190 | switch(rd[i].record_type) | 185 | answer_records[i - skip_answers].dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
191 | { | 186 | } |
192 | case GNUNET_DNSPARSER_TYPE_NS: | 187 | else |
193 | case GNUNET_DNSPARSER_TYPE_CNAME: | 188 | { |
194 | case GNUNET_DNSPARSER_TYPE_PTR: | 189 | additional_records[i - skip_additional].name = query->name; |
195 | additional_records[i - skip_additional].data.hostname | 190 | additional_records[i - skip_additional].type = rd[i].record_type; |
196 | = GNUNET_DNSPARSER_parse_name (rd[i].data, | 191 | switch (rd[i].record_type) |
197 | rd[i].data_size, | 192 | { |
198 | &off); | 193 | case GNUNET_DNSPARSER_TYPE_NS: |
199 | if ( (off != rd[i].data_size) || | 194 | case GNUNET_DNSPARSER_TYPE_CNAME: |
200 | (NULL == additional_records[i].data.hostname) ) | 195 | case GNUNET_DNSPARSER_TYPE_PTR: |
201 | { | 196 | additional_records[i - skip_additional].data.hostname |
202 | GNUNET_break_op (0); | 197 | = GNUNET_DNSPARSER_parse_name(rd[i].data, |
203 | skip_additional++; | 198 | rd[i].data_size, |
204 | } | 199 | &off); |
205 | break; | 200 | if ((off != rd[i].data_size) || |
206 | case GNUNET_DNSPARSER_TYPE_SOA: | 201 | (NULL == additional_records[i].data.hostname)) |
207 | additional_records[i - skip_additional].data.soa | 202 | { |
208 | = GNUNET_DNSPARSER_parse_soa (rd[i].data, | 203 | GNUNET_break_op(0); |
209 | rd[i].data_size, | 204 | skip_additional++; |
210 | &off); | 205 | } |
211 | if ( (off != rd[i].data_size) || | 206 | break; |
212 | (NULL == additional_records[i].data.hostname) ) | 207 | |
213 | { | 208 | case GNUNET_DNSPARSER_TYPE_SOA: |
214 | GNUNET_break_op (0); | 209 | additional_records[i - skip_additional].data.soa |
215 | skip_additional++; | 210 | = GNUNET_DNSPARSER_parse_soa(rd[i].data, |
216 | } | 211 | rd[i].data_size, |
217 | break; | 212 | &off); |
218 | case GNUNET_DNSPARSER_TYPE_MX: | 213 | if ((off != rd[i].data_size) || |
219 | additional_records[i - skip_additional].data.mx | 214 | (NULL == additional_records[i].data.hostname)) |
220 | = GNUNET_DNSPARSER_parse_mx (rd[i].data, | 215 | { |
221 | rd[i].data_size, | 216 | GNUNET_break_op(0); |
222 | &off); | 217 | skip_additional++; |
223 | if ( (off != rd[i].data_size) || | 218 | } |
224 | (NULL == additional_records[i].data.hostname) ) | 219 | break; |
225 | { | 220 | |
226 | GNUNET_break_op (0); | 221 | case GNUNET_DNSPARSER_TYPE_MX: |
227 | skip_additional++; | 222 | additional_records[i - skip_additional].data.mx |
228 | } | 223 | = GNUNET_DNSPARSER_parse_mx(rd[i].data, |
229 | break; | 224 | rd[i].data_size, |
230 | case GNUNET_DNSPARSER_TYPE_SRV: | 225 | &off); |
231 | /* FIXME: SRV is not yet supported */ | 226 | if ((off != rd[i].data_size) || |
232 | skip_answers++; | 227 | (NULL == additional_records[i].data.hostname)) |
233 | break; | 228 | { |
234 | default: | 229 | GNUNET_break_op(0); |
235 | additional_records[i - skip_additional].data.raw.data_len = rd[i].data_size; | 230 | skip_additional++; |
236 | additional_records[i - skip_additional].data.raw.data = (char*)rd[i].data; | 231 | } |
237 | break; | 232 | break; |
238 | } | 233 | |
239 | GNUNET_break (0 == (rd[i - skip_additional].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)); | 234 | case GNUNET_DNSPARSER_TYPE_SRV: |
240 | additional_records[i - skip_additional].expiration_time.abs_value_us = rd[i].expiration_time; | 235 | /* FIXME: SRV is not yet supported */ |
241 | additional_records[i - skip_additional].dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 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 | } | ||
242 | } | 248 | } |
243 | } | ||
244 | packet->num_answers = num_answers - skip_answers; | 249 | packet->num_answers = num_answers - skip_answers; |
245 | packet->num_additional_records = rd_count - num_answers - skip_additional; | 250 | packet->num_additional_records = rd_count - num_answers - skip_additional; |
246 | packet->flags.authoritative_answer = 1; | 251 | packet->flags.authoritative_answer = 1; |
@@ -249,32 +254,32 @@ reply_to_dns (void *cls, uint32_t rd_count, | |||
249 | else | 254 | else |
250 | packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; | 255 | packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR; |
251 | packet->flags.query_or_response = 1; | 256 | packet->flags.query_or_response = 1; |
252 | ret = GNUNET_DNSPARSER_pack (packet, | 257 | ret = GNUNET_DNSPARSER_pack(packet, |
253 | 1024, /* maximum allowed size for DNS reply */ | 258 | 1024, /* maximum allowed size for DNS reply */ |
254 | &buf, | 259 | &buf, |
255 | &len); | 260 | &len); |
256 | if (GNUNET_OK != ret) | 261 | if (GNUNET_OK != ret) |
257 | { | 262 | { |
258 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 263 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
259 | _("Error converting GNS response to DNS response!\n")); | 264 | _("Error converting GNS response to DNS response!\n")); |
260 | if (GNUNET_NO == ret) | 265 | if (GNUNET_NO == ret) |
261 | GNUNET_free (buf); | 266 | GNUNET_free(buf); |
262 | } | 267 | } |
263 | else | 268 | else |
264 | { | 269 | { |
265 | GNUNET_DNS_request_answer (ilh->request_handle, | 270 | GNUNET_DNS_request_answer(ilh->request_handle, |
266 | len, | 271 | len, |
267 | buf); | 272 | buf); |
268 | GNUNET_free (buf); | 273 | GNUNET_free(buf); |
269 | } | 274 | } |
270 | packet->num_answers = 0; | 275 | packet->num_answers = 0; |
271 | packet->answers = NULL; | 276 | packet->answers = NULL; |
272 | packet->num_additional_records = 0; | 277 | packet->num_additional_records = 0; |
273 | packet->additional_records = NULL; | 278 | packet->additional_records = NULL; |
274 | GNUNET_DNSPARSER_free_packet (packet); | 279 | GNUNET_DNSPARSER_free_packet(packet); |
275 | } | 280 | } |
276 | GNUNET_CONTAINER_DLL_remove (ilh_head, ilh_tail, ilh); | 281 | GNUNET_CONTAINER_DLL_remove(ilh_head, ilh_tail, ilh); |
277 | GNUNET_free (ilh); | 282 | GNUNET_free(ilh); |
278 | } | 283 | } |
279 | 284 | ||
280 | 285 | ||
@@ -287,61 +292,61 @@ reply_to_dns (void *cls, uint32_t rd_count, | |||
287 | * @param request UDP payload of the DNS request | 292 | * @param request UDP payload of the DNS request |
288 | */ | 293 | */ |
289 | static void | 294 | static void |
290 | handle_dns_request (void *cls, | 295 | handle_dns_request(void *cls, |
291 | struct GNUNET_DNS_RequestHandle *rh, | 296 | struct GNUNET_DNS_RequestHandle *rh, |
292 | size_t request_length, | 297 | size_t request_length, |
293 | const char *request) | 298 | const char *request) |
294 | { | 299 | { |
295 | struct GNUNET_DNSPARSER_Packet *p; | 300 | struct GNUNET_DNSPARSER_Packet *p; |
296 | struct InterceptLookupHandle *ilh; | 301 | struct InterceptLookupHandle *ilh; |
297 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 302 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; |
298 | 303 | ||
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 304 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
300 | "Hijacked a DNS request. Processing.\n"); | 305 | "Hijacked a DNS request. Processing.\n"); |
301 | if (NULL == (p = GNUNET_DNSPARSER_parse (request, request_length))) | 306 | if (NULL == (p = GNUNET_DNSPARSER_parse(request, request_length))) |
302 | { | 307 | { |
303 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 308 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
304 | "Received malformed DNS packet, leaving it untouched.\n"); | 309 | "Received malformed DNS packet, leaving it untouched.\n"); |
305 | GNUNET_DNS_request_forward (rh); | 310 | GNUNET_DNS_request_forward(rh); |
306 | GNUNET_DNSPARSER_free_packet (p); | 311 | GNUNET_DNSPARSER_free_packet(p); |
307 | return; | 312 | return; |
308 | } | 313 | } |
309 | 314 | ||
310 | /* Check TLD and decide if we or legacy dns is responsible */ | 315 | /* Check TLD and decide if we or legacy dns is responsible */ |
311 | if (1 != p->num_queries) | 316 | if (1 != p->num_queries) |
312 | { | 317 | { |
313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 318 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
314 | "Not exactly one query in DNS packet. Forwarding untouched.\n"); | 319 | "Not exactly one query in DNS packet. Forwarding untouched.\n"); |
315 | GNUNET_DNS_request_forward (rh); | 320 | GNUNET_DNS_request_forward(rh); |
316 | GNUNET_DNSPARSER_free_packet(p); | 321 | GNUNET_DNSPARSER_free_packet(p); |
317 | return; | 322 | return; |
318 | } | 323 | } |
319 | 324 | ||
320 | /* Check for GNS TLDs. */ | 325 | /* Check for GNS TLDs. */ |
321 | if (GNUNET_YES == | 326 | if (GNUNET_YES == |
322 | GNS_find_tld (GNS_get_tld (p->queries[0].name), | 327 | GNS_find_tld(GNS_get_tld(p->queries[0].name), |
323 | &zone)) | 328 | &zone)) |
324 | { | 329 | { |
325 | /* Start resolution in GNS */ | 330 | /* Start resolution in GNS */ |
326 | ilh = GNUNET_new (struct InterceptLookupHandle); | 331 | ilh = GNUNET_new(struct InterceptLookupHandle); |
327 | GNUNET_CONTAINER_DLL_insert (ilh_head, | 332 | GNUNET_CONTAINER_DLL_insert(ilh_head, |
328 | ilh_tail, | 333 | ilh_tail, |
329 | ilh); | 334 | ilh); |
330 | ilh->packet = p; | 335 | ilh->packet = p; |
331 | ilh->request_handle = rh; | 336 | ilh->request_handle = rh; |
332 | ilh->lookup = GNS_resolver_lookup (&zone, | 337 | ilh->lookup = GNS_resolver_lookup(&zone, |
333 | p->queries[0].type, | 338 | p->queries[0].type, |
334 | p->queries[0].name, | 339 | p->queries[0].name, |
335 | GNUNET_NO, | 340 | GNUNET_NO, |
336 | &reply_to_dns, ilh); | 341 | &reply_to_dns, ilh); |
337 | return; | 342 | return; |
338 | } | 343 | } |
339 | /* This request does not concern us. Forward to real DNS. */ | 344 | /* This request does not concern us. Forward to real DNS. */ |
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 345 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
341 | "Request for `%s' is forwarded to DNS untouched.\n", | 346 | "Request for `%s' is forwarded to DNS untouched.\n", |
342 | p->queries[0].name); | 347 | p->queries[0].name); |
343 | GNUNET_DNS_request_forward (rh); | 348 | GNUNET_DNS_request_forward(rh); |
344 | GNUNET_DNSPARSER_free_packet (p); | 349 | GNUNET_DNSPARSER_free_packet(p); |
345 | } | 350 | } |
346 | 351 | ||
347 | 352 | ||
@@ -352,20 +357,20 @@ handle_dns_request (void *cls, | |||
352 | * @return #GNUNET_OK on success | 357 | * @return #GNUNET_OK on success |
353 | */ | 358 | */ |
354 | int | 359 | int |
355 | GNS_interceptor_init (const struct GNUNET_CONFIGURATION_Handle *c) | 360 | GNS_interceptor_init(const struct GNUNET_CONFIGURATION_Handle *c) |
356 | { | 361 | { |
357 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 362 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
358 | "DNS hijacking enabled. Connecting to DNS service.\n"); | 363 | "DNS hijacking enabled. Connecting to DNS service.\n"); |
359 | dns_handle = GNUNET_DNS_connect (c, | 364 | dns_handle = GNUNET_DNS_connect(c, |
360 | GNUNET_DNS_FLAG_PRE_RESOLUTION, | 365 | GNUNET_DNS_FLAG_PRE_RESOLUTION, |
361 | &handle_dns_request, | 366 | &handle_dns_request, |
362 | NULL); | 367 | NULL); |
363 | if (NULL == dns_handle) | 368 | if (NULL == dns_handle) |
364 | { | 369 | { |
365 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 370 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
366 | _("Failed to connect to the DNS service!\n")); | 371 | _("Failed to connect to the DNS service!\n")); |
367 | return GNUNET_SYSERR; | 372 | return GNUNET_SYSERR; |
368 | } | 373 | } |
369 | return GNUNET_YES; | 374 | return GNUNET_YES; |
370 | } | 375 | } |
371 | 376 | ||
@@ -374,25 +379,25 @@ GNS_interceptor_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
374 | * Disconnect from interceptor | 379 | * Disconnect from interceptor |
375 | */ | 380 | */ |
376 | void | 381 | void |
377 | GNS_interceptor_done () | 382 | GNS_interceptor_done() |
378 | { | 383 | { |
379 | struct InterceptLookupHandle *ilh; | 384 | struct InterceptLookupHandle *ilh; |
380 | 385 | ||
381 | while (NULL != (ilh = ilh_head)) | 386 | while (NULL != (ilh = ilh_head)) |
382 | { | 387 | { |
383 | GNUNET_CONTAINER_DLL_remove (ilh_head, | 388 | GNUNET_CONTAINER_DLL_remove(ilh_head, |
384 | ilh_tail, | 389 | ilh_tail, |
385 | ilh); | 390 | ilh); |
386 | GNS_resolver_lookup_cancel (ilh->lookup); | 391 | GNS_resolver_lookup_cancel(ilh->lookup); |
387 | GNUNET_DNS_request_drop (ilh->request_handle); | 392 | GNUNET_DNS_request_drop(ilh->request_handle); |
388 | GNUNET_DNSPARSER_free_packet (ilh->packet); | 393 | GNUNET_DNSPARSER_free_packet(ilh->packet); |
389 | GNUNET_free (ilh); | 394 | GNUNET_free(ilh); |
390 | } | 395 | } |
391 | if (NULL != dns_handle) | 396 | if (NULL != dns_handle) |
392 | { | 397 | { |
393 | GNUNET_DNS_disconnect (dns_handle); | 398 | GNUNET_DNS_disconnect(dns_handle); |
394 | dns_handle = NULL; | 399 | dns_handle = NULL; |
395 | } | 400 | } |
396 | } | 401 | } |
397 | 402 | ||
398 | /* end of gnunet-service-gns_interceptor.c */ | 403 | /* 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 095448db2..10e1acab6 100644 --- a/src/gns/gnunet-service-gns_interceptor.h +++ b/src/gns/gnunet-service-gns_interceptor.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gnunet-service-gns_interceptor.h | 21 | * @file gns/gnunet-service-gns_interceptor.h |
22 | * @brief GNUnet GNS service | 22 | * @brief GNUnet GNS service |
@@ -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 | */ |
37 | int | 37 | int |
38 | GNS_interceptor_init (const struct GNUNET_CONFIGURATION_Handle *c); | 38 | GNS_interceptor_init(const struct GNUNET_CONFIGURATION_Handle *c); |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Stops the interceptor | 41 | * Stops the interceptor |
42 | */ | 42 | */ |
43 | void | 43 | void |
44 | GNS_interceptor_done (void); | 44 | GNS_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 703a0f652..da54f3dd5 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file gns/gnunet-service-gns_resolver.c | 22 | * @file gns/gnunet-service-gns_resolver.c |
@@ -45,17 +45,17 @@ | |||
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(GNUNET_TIME_UNIT_SECONDS, 60) |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Default timeout for DNS lookups. | 51 | * Default timeout for DNS lookups. |
52 | */ | 52 | */ |
53 | #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 53 | #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Default timeout for VPN redirections. | 56 | * Default timeout for VPN redirections. |
57 | */ | 57 | */ |
58 | #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | 58 | #define VPN_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * DHT replication level | 61 | * DHT replication level |
@@ -80,9 +80,7 @@ struct AuthorityChain; | |||
80 | * responsible DNS server hostname in a GNS2DNS recursive | 80 | * responsible DNS server hostname in a GNS2DNS recursive |
81 | * resolution. | 81 | * resolution. |
82 | */ | 82 | */ |
83 | struct Gns2DnsPending | 83 | struct Gns2DnsPending { |
84 | { | ||
85 | |||
86 | /** | 84 | /** |
87 | * Kept in a DLL. | 85 | * Kept in a DLL. |
88 | */ | 86 | */ |
@@ -128,8 +126,7 @@ struct GNS_ResolverHandle; | |||
128 | * DLL to hold the authority chain we had to pass in the resolution | 126 | * DLL to hold the authority chain we had to pass in the resolution |
129 | * process. | 127 | * process. |
130 | */ | 128 | */ |
131 | struct AuthorityChain | 129 | struct AuthorityChain { |
132 | { | ||
133 | /** | 130 | /** |
134 | * This is a DLL. | 131 | * This is a DLL. |
135 | */ | 132 | */ |
@@ -159,16 +156,13 @@ struct AuthorityChain | |||
159 | /** | 156 | /** |
160 | * Information about the resolver authority for this label. | 157 | * Information about the resolver authority for this label. |
161 | */ | 158 | */ |
162 | union | 159 | union { |
163 | { | ||
164 | |||
165 | /** | 160 | /** |
166 | * The zone of the GNS authority | 161 | * The zone of the GNS authority |
167 | */ | 162 | */ |
168 | struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority; | 163 | struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority; |
169 | 164 | ||
170 | struct | 165 | struct { |
171 | { | ||
172 | /** | 166 | /** |
173 | * Domain of the DNS resolver that is the authority. | 167 | * Domain of the DNS resolver that is the authority. |
174 | * (appended to construct the DNS name to resolve; | 168 | * (appended to construct the DNS name to resolve; |
@@ -203,20 +197,15 @@ struct AuthorityChain | |||
203 | * Did we start the recursive resolution via DNS? | 197 | * Did we start the recursive resolution via DNS? |
204 | */ | 198 | */ |
205 | int launched; | 199 | int launched; |
206 | |||
207 | } dns_authority; | 200 | } dns_authority; |
208 | |||
209 | } authority_info; | 201 | } authority_info; |
210 | |||
211 | }; | 202 | }; |
212 | 203 | ||
213 | 204 | ||
214 | /** | 205 | /** |
215 | * A result we got from DNS. | 206 | * A result we got from DNS. |
216 | */ | 207 | */ |
217 | struct DnsResult | 208 | struct DnsResult { |
218 | { | ||
219 | |||
220 | /** | 209 | /** |
221 | * Kept in DLL. | 210 | * Kept in DLL. |
222 | */ | 211 | */ |
@@ -247,16 +236,13 @@ struct DnsResult | |||
247 | * Type of the GNS/DNS record. | 236 | * Type of the GNS/DNS record. |
248 | */ | 237 | */ |
249 | uint32_t record_type; | 238 | uint32_t record_type; |
250 | |||
251 | }; | 239 | }; |
252 | 240 | ||
253 | 241 | ||
254 | /** | 242 | /** |
255 | * Closure for #vpn_allocation_cb. | 243 | * Closure for #vpn_allocation_cb. |
256 | */ | 244 | */ |
257 | struct VpnContext | 245 | struct VpnContext { |
258 | { | ||
259 | |||
260 | /** | 246 | /** |
261 | * Which resolution process are we processing. | 247 | * Which resolution process are we processing. |
262 | */ | 248 | */ |
@@ -288,9 +274,7 @@ struct VpnContext | |||
288 | * Handle to a currenty pending resolution. On result (positive or | 274 | * Handle to a currenty pending resolution. On result (positive or |
289 | * negative) the #GNS_ResultProcessor is called. | 275 | * negative) the #GNS_ResultProcessor is called. |
290 | */ | 276 | */ |
291 | struct GNS_ResolverHandle | 277 | struct GNS_ResolverHandle { |
292 | { | ||
293 | |||
294 | /** | 278 | /** |
295 | * DLL | 279 | * DLL |
296 | */ | 280 | */ |
@@ -426,16 +410,13 @@ struct GNS_ResolverHandle | |||
426 | * 16 bit random ID we used in the @e dns_request. | 410 | * 16 bit random ID we used in the @e dns_request. |
427 | */ | 411 | */ |
428 | uint16_t original_dns_id; | 412 | uint16_t original_dns_id; |
429 | |||
430 | }; | 413 | }; |
431 | 414 | ||
432 | 415 | ||
433 | /** | 416 | /** |
434 | * Active namestore caching operations. | 417 | * Active namestore caching operations. |
435 | */ | 418 | */ |
436 | struct CacheOps | 419 | struct CacheOps { |
437 | { | ||
438 | |||
439 | /** | 420 | /** |
440 | * Organized in a DLL. | 421 | * Organized in a DLL. |
441 | */ | 422 | */ |
@@ -450,7 +431,6 @@ struct CacheOps | |||
450 | * Pending Namestore caching task. | 431 | * Pending Namestore caching task. |
451 | */ | 432 | */ |
452 | struct GNUNET_NAMECACHE_QueueEntry *namecache_qe_cache; | 433 | struct GNUNET_NAMECACHE_QueueEntry *namecache_qe_cache; |
453 | |||
454 | }; | 434 | }; |
455 | 435 | ||
456 | 436 | ||
@@ -526,19 +506,19 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
526 | * @return #GNUNET_YES if canonical | 506 | * @return #GNUNET_YES if canonical |
527 | */ | 507 | */ |
528 | /* dead, but keep for now */ int | 508 | /* dead, but keep for now */ int |
529 | is_canonical (const char *name) | 509 | is_canonical(const char *name) |
530 | { | 510 | { |
531 | const char *pos; | 511 | const char *pos; |
532 | const char *dot; | 512 | const char *dot; |
533 | 513 | ||
534 | if (NULL == strchr (name, | 514 | if (NULL == strchr(name, |
535 | (unsigned char) '.')) | 515 | (unsigned char)'.')) |
536 | return GNUNET_YES; | 516 | return GNUNET_YES; |
537 | if ('_' != name[0]) | 517 | if ('_' != name[0]) |
538 | return GNUNET_NO; | 518 | return GNUNET_NO; |
539 | pos = &name[1]; | 519 | pos = &name[1]; |
540 | while (NULL != (dot = strchr (pos, | 520 | while (NULL != (dot = strchr(pos, |
541 | (unsigned char) '.'))) | 521 | (unsigned char)'.'))) |
542 | if ('_' != dot[1]) | 522 | if ('_' != dot[1]) |
543 | return GNUNET_NO; | 523 | return GNUNET_NO; |
544 | else | 524 | else |
@@ -556,22 +536,22 @@ is_canonical (const char *name) | |||
556 | * @return updated name | 536 | * @return updated name |
557 | */ | 537 | */ |
558 | static char * | 538 | static char * |
559 | translate_dot_plus (struct GNS_ResolverHandle *rh, | 539 | translate_dot_plus(struct GNS_ResolverHandle *rh, |
560 | char *name) | 540 | char *name) |
561 | { | 541 | { |
562 | char *ret; | 542 | char *ret; |
563 | size_t s_len = strlen (name); | 543 | size_t s_len = strlen(name); |
564 | 544 | ||
565 | if (0 != strcmp (&name[s_len - 2], | 545 | if (0 != strcmp(&name[s_len - 2], |
566 | ".+")) | 546 | ".+")) |
567 | return name; /* did not end in ".+" */ | 547 | return name; /* did not end in ".+" */ |
568 | GNUNET_assert (GNUNET_YES == rh->ac_tail->gns_authority); | 548 | GNUNET_assert(GNUNET_YES == rh->ac_tail->gns_authority); |
569 | GNUNET_asprintf (&ret, | 549 | GNUNET_asprintf(&ret, |
570 | "%.*s.%s", | 550 | "%.*s.%s", |
571 | (int) (s_len - 2), | 551 | (int)(s_len - 2), |
572 | name, | 552 | name, |
573 | GNUNET_GNSRECORD_pkey_to_zkey (&rh->ac_tail->authority_info.gns_authority)); | 553 | GNUNET_GNSRECORD_pkey_to_zkey(&rh->ac_tail->authority_info.gns_authority)); |
574 | GNUNET_free (name); | 554 | GNUNET_free(name); |
575 | return ret; | 555 | return ret; |
576 | } | 556 | } |
577 | 557 | ||
@@ -583,12 +563,12 @@ translate_dot_plus (struct GNS_ResolverHandle *rh, | |||
583 | * @param cls the `struct GNS_ResolverHandle` | 563 | * @param cls the `struct GNS_ResolverHandle` |
584 | */ | 564 | */ |
585 | static void | 565 | static void |
586 | GNS_resolver_lookup_cancel_ (void *cls) | 566 | GNS_resolver_lookup_cancel_(void *cls) |
587 | { | 567 | { |
588 | struct GNS_ResolverHandle *rh = cls; | 568 | struct GNS_ResolverHandle *rh = cls; |
589 | 569 | ||
590 | rh->task_id = NULL; | 570 | rh->task_id = NULL; |
591 | GNS_resolver_lookup_cancel (rh); | 571 | GNS_resolver_lookup_cancel(rh); |
592 | } | 572 | } |
593 | 573 | ||
594 | 574 | ||
@@ -598,14 +578,14 @@ GNS_resolver_lookup_cancel_ (void *cls) | |||
598 | * @param rh the resolution to fail | 578 | * @param rh the resolution to fail |
599 | */ | 579 | */ |
600 | static void | 580 | static void |
601 | fail_resolution (struct GNS_ResolverHandle *rh) | 581 | fail_resolution(struct GNS_ResolverHandle *rh) |
602 | { | 582 | { |
603 | rh->proc (rh->proc_cls, | 583 | rh->proc(rh->proc_cls, |
604 | 0, | 584 | 0, |
605 | NULL); | 585 | NULL); |
606 | GNUNET_assert (NULL == rh->task_id); | 586 | GNUNET_assert(NULL == rh->task_id); |
607 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 587 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
608 | rh); | 588 | rh); |
609 | } | 589 | } |
610 | 590 | ||
611 | 591 | ||
@@ -615,12 +595,12 @@ fail_resolution (struct GNS_ResolverHandle *rh) | |||
615 | * @param cls the `struct GNS_ResolverHandle` | 595 | * @param cls the `struct GNS_ResolverHandle` |
616 | */ | 596 | */ |
617 | static void | 597 | static void |
618 | timeout_resolution (void *cls) | 598 | timeout_resolution(void *cls) |
619 | { | 599 | { |
620 | struct GNS_ResolverHandle *rh = cls; | 600 | struct GNS_ResolverHandle *rh = cls; |
621 | 601 | ||
622 | rh->task_id = NULL; | 602 | rh->task_id = NULL; |
623 | fail_resolution (rh); | 603 | fail_resolution(rh); |
624 | } | 604 | } |
625 | 605 | ||
626 | 606 | ||
@@ -642,7 +622,7 @@ timeout_resolution (void *cls) | |||
642 | * @return NULL if there are no more labels | 622 | * @return NULL if there are no more labels |
643 | */ | 623 | */ |
644 | static char * | 624 | static char * |
645 | resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh) | 625 | resolver_lookup_get_next_label(struct GNS_ResolverHandle *rh) |
646 | { | 626 | { |
647 | const char *rp; | 627 | const char *rp; |
648 | const char *dot; | 628 | const char *dot; |
@@ -655,71 +635,71 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh) | |||
655 | 635 | ||
656 | if (0 == rh->name_resolution_pos) | 636 | if (0 == rh->name_resolution_pos) |
657 | return NULL; | 637 | return NULL; |
658 | dot = memrchr (rh->name, | 638 | dot = memrchr(rh->name, |
659 | (int) '.', | 639 | (int)'.', |
660 | rh->name_resolution_pos); | 640 | rh->name_resolution_pos); |
661 | if (NULL == dot) | 641 | if (NULL == dot) |
662 | { | 642 | { |
663 | /* done, this was the last one */ | 643 | /* done, this was the last one */ |
664 | len = rh->name_resolution_pos; | 644 | len = rh->name_resolution_pos; |
665 | rp = rh->name; | 645 | rp = rh->name; |
666 | rh->name_resolution_pos = 0; | 646 | rh->name_resolution_pos = 0; |
667 | } | 647 | } |
668 | else | 648 | else |
669 | { | 649 | { |
670 | /* advance by one label */ | 650 | /* advance by one label */ |
671 | len = rh->name_resolution_pos - (dot - rh->name) - 1; | 651 | len = rh->name_resolution_pos - (dot - rh->name) - 1; |
672 | rp = dot + 1; | 652 | rp = dot + 1; |
673 | rh->name_resolution_pos = dot - rh->name; | 653 | rh->name_resolution_pos = dot - rh->name; |
674 | } | 654 | } |
675 | rh->protocol = 0; | 655 | rh->protocol = 0; |
676 | rh->service = 0; | 656 | rh->service = 0; |
677 | ret = GNUNET_strndup (rp, len); | 657 | ret = GNUNET_strndup(rp, len); |
678 | /* If we have labels starting with underscore with label on | 658 | /* If we have labels starting with underscore with label on |
679 | * the right (SRV/DANE/BOX case), determine port/protocol; | 659 | * the right (SRV/DANE/BOX case), determine port/protocol; |
680 | * The format of `rh->name` must be "_PORT._PROTOCOL". | 660 | * The format of `rh->name` must be "_PORT._PROTOCOL". |
681 | */ | 661 | */ |
682 | if ( ('_' == rh->name[0]) && | 662 | if (('_' == rh->name[0]) && |
683 | (NULL != (dot = memrchr (rh->name, | 663 | (NULL != (dot = memrchr(rh->name, |
684 | (int) '.', | 664 | (int)'.', |
685 | rh->name_resolution_pos))) && | 665 | rh->name_resolution_pos))) && |
686 | ('_' == dot[1]) && | 666 | ('_' == dot[1]) && |
687 | (NULL == memrchr (rh->name, | 667 | (NULL == memrchr(rh->name, |
688 | (int) '.', | 668 | (int)'.', |
689 | dot - rh->name)) ) | 669 | dot - rh->name))) |
690 | { | ||
691 | srv_name = GNUNET_strndup (&rh->name[1], | ||
692 | (dot - rh->name) - 1); | ||
693 | proto_name = GNUNET_strndup (&dot[2], | ||
694 | rh->name_resolution_pos - (dot - rh->name) - 1); | ||
695 | rh->name_resolution_pos = 0; | ||
696 | pe = getprotobyname (proto_name); | ||
697 | if (NULL == pe) | ||
698 | { | ||
699 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
700 | _("Protocol `%s' unknown, skipping labels.\n"), | ||
701 | proto_name); | ||
702 | GNUNET_free (proto_name); | ||
703 | GNUNET_free (srv_name); | ||
704 | return ret; | ||
705 | } | ||
706 | se = getservbyname (srv_name, | ||
707 | proto_name); | ||
708 | if (NULL == se) | ||
709 | { | 670 | { |
710 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 671 | srv_name = GNUNET_strndup(&rh->name[1], |
711 | _("Service `%s' unknown for protocol `%s', skipping labels.\n"), | 672 | (dot - rh->name) - 1); |
712 | srv_name, | 673 | proto_name = GNUNET_strndup(&dot[2], |
713 | proto_name); | 674 | rh->name_resolution_pos - (dot - rh->name) - 1); |
714 | GNUNET_free (proto_name); | 675 | rh->name_resolution_pos = 0; |
715 | GNUNET_free (srv_name); | 676 | pe = getprotobyname(proto_name); |
716 | return ret; | 677 | if (NULL == pe) |
678 | { | ||
679 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
680 | _("Protocol `%s' unknown, skipping labels.\n"), | ||
681 | proto_name); | ||
682 | GNUNET_free(proto_name); | ||
683 | GNUNET_free(srv_name); | ||
684 | return ret; | ||
685 | } | ||
686 | se = getservbyname(srv_name, | ||
687 | proto_name); | ||
688 | if (NULL == se) | ||
689 | { | ||
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); | ||
717 | } | 702 | } |
718 | rh->protocol = pe->p_proto; | ||
719 | rh->service = se->s_port; | ||
720 | GNUNET_free (proto_name); | ||
721 | GNUNET_free (srv_name); | ||
722 | } | ||
723 | return ret; | 703 | return ret; |
724 | } | 704 | } |
725 | 705 | ||
@@ -730,7 +710,7 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh) | |||
730 | * @param rh resolution process that has culminated in a result | 710 | * @param rh resolution process that has culminated in a result |
731 | */ | 711 | */ |
732 | static void | 712 | static void |
733 | transmit_lookup_dns_result (struct GNS_ResolverHandle *rh) | 713 | transmit_lookup_dns_result(struct GNS_ResolverHandle *rh) |
734 | { | 714 | { |
735 | struct DnsResult *pos; | 715 | struct DnsResult *pos; |
736 | unsigned int n; | 716 | unsigned int n; |
@@ -744,31 +724,31 @@ transmit_lookup_dns_result (struct GNS_ResolverHandle *rh) | |||
744 | 724 | ||
745 | i = 0; | 725 | i = 0; |
746 | for (pos = rh->dns_result_head; NULL != pos; pos = pos->next) | 726 | for (pos = rh->dns_result_head; NULL != pos; pos = pos->next) |
747 | { | ||
748 | rd[i].data = pos->data; | ||
749 | rd[i].data_size = pos->data_size; | ||
750 | rd[i].record_type = pos->record_type; | ||
751 | if (0 == pos->expiration_time) | ||
752 | { | 727 | { |
753 | rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 728 | rd[i].data = pos->data; |
754 | rd[i].expiration_time = 0; | 729 | rd[i].data_size = pos->data_size; |
755 | } | 730 | rd[i].record_type = pos->record_type; |
756 | else | 731 | if (0 == pos->expiration_time) |
757 | { | 732 | { |
758 | rd[i].flags = GNUNET_GNSRECORD_RF_NONE; | 733 | rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
759 | rd[i].expiration_time = pos->expiration_time; | 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++; | ||
760 | } | 742 | } |
761 | i++; | 743 | GNUNET_assert(i == n); |
762 | } | 744 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
763 | GNUNET_assert (i == n); | 745 | "Transmitting standard DNS result with %u records\n", |
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 746 | n); |
765 | "Transmitting standard DNS result with %u records\n", | 747 | rh->proc(rh->proc_cls, |
766 | n); | 748 | n, |
767 | rh->proc (rh->proc_cls, | 749 | rd); |
768 | n, | ||
769 | rd); | ||
770 | } | 750 | } |
771 | GNS_resolver_lookup_cancel (rh); | 751 | GNS_resolver_lookup_cancel(rh); |
772 | } | 752 | } |
773 | 753 | ||
774 | 754 | ||
@@ -782,25 +762,25 @@ transmit_lookup_dns_result (struct GNS_ResolverHandle *rh) | |||
782 | * @param data binary data to return in DNS record | 762 | * @param data binary data to return in DNS record |
783 | */ | 763 | */ |
784 | static void | 764 | static void |
785 | add_dns_result (struct GNS_ResolverHandle *rh, | 765 | add_dns_result(struct GNS_ResolverHandle *rh, |
786 | uint64_t expiration_time, | 766 | uint64_t expiration_time, |
787 | uint32_t record_type, | 767 | uint32_t record_type, |
788 | size_t data_size, | 768 | size_t data_size, |
789 | const void *data) | 769 | const void *data) |
790 | { | 770 | { |
791 | struct DnsResult *res; | 771 | struct DnsResult *res; |
792 | 772 | ||
793 | res = GNUNET_malloc (sizeof (struct DnsResult) + data_size); | 773 | res = GNUNET_malloc(sizeof(struct DnsResult) + data_size); |
794 | res->expiration_time = expiration_time; | 774 | res->expiration_time = expiration_time; |
795 | res->data_size = data_size; | 775 | res->data_size = data_size; |
796 | res->record_type = record_type; | 776 | res->record_type = record_type; |
797 | res->data = &res[1]; | 777 | res->data = &res[1]; |
798 | GNUNET_memcpy (&res[1], | 778 | GNUNET_memcpy(&res[1], |
799 | data, | 779 | data, |
800 | data_size); | 780 | data_size); |
801 | GNUNET_CONTAINER_DLL_insert (rh->dns_result_head, | 781 | GNUNET_CONTAINER_DLL_insert(rh->dns_result_head, |
802 | rh->dns_result_tail, | 782 | rh->dns_result_tail, |
803 | res); | 783 | res); |
804 | } | 784 | } |
805 | 785 | ||
806 | 786 | ||
@@ -813,45 +793,47 @@ add_dns_result (struct GNS_ResolverHandle *rh, | |||
813 | * @param addrlen length of the address | 793 | * @param addrlen length of the address |
814 | */ | 794 | */ |
815 | static void | 795 | static void |
816 | handle_dns_result (void *cls, | 796 | handle_dns_result(void *cls, |
817 | const struct sockaddr *addr, | 797 | const struct sockaddr *addr, |
818 | socklen_t addrlen) | 798 | socklen_t addrlen) |
819 | { | 799 | { |
820 | struct GNS_ResolverHandle *rh = cls; | 800 | struct GNS_ResolverHandle *rh = cls; |
821 | const struct sockaddr_in *sa4; | 801 | const struct sockaddr_in *sa4; |
822 | const struct sockaddr_in6 *sa6; | 802 | const struct sockaddr_in6 *sa6; |
823 | 803 | ||
824 | if (NULL == addr) | 804 | if (NULL == addr) |
825 | { | 805 | { |
826 | rh->std_resolve = NULL; | 806 | rh->std_resolve = NULL; |
827 | transmit_lookup_dns_result (rh); | 807 | transmit_lookup_dns_result(rh); |
828 | return; | 808 | return; |
829 | } | 809 | } |
830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 810 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
831 | "Received %u bytes of DNS IP data\n", | 811 | "Received %u bytes of DNS IP data\n", |
832 | addrlen); | 812 | addrlen); |
833 | switch (addr->sa_family) | 813 | switch (addr->sa_family) |
834 | { | 814 | { |
835 | case AF_INET: | 815 | case AF_INET: |
836 | sa4 = (const struct sockaddr_in *) addr; | 816 | sa4 = (const struct sockaddr_in *)addr; |
837 | add_dns_result (rh, | 817 | add_dns_result(rh, |
838 | 0 /* expiration time is unknown */, | 818 | 0 /* expiration time is unknown */, |
839 | GNUNET_DNSPARSER_TYPE_A, | 819 | GNUNET_DNSPARSER_TYPE_A, |
840 | sizeof (struct in_addr), | 820 | sizeof(struct in_addr), |
841 | &sa4->sin_addr); | 821 | &sa4->sin_addr); |
842 | break; | 822 | break; |
843 | case AF_INET6: | 823 | |
844 | sa6 = (const struct sockaddr_in6 *) addr; | 824 | case AF_INET6: |
845 | add_dns_result (rh, | 825 | sa6 = (const struct sockaddr_in6 *)addr; |
846 | 0 /* expiration time is unknown */, | 826 | add_dns_result(rh, |
847 | GNUNET_DNSPARSER_TYPE_AAAA, | 827 | 0 /* expiration time is unknown */, |
848 | sizeof (struct in6_addr), | 828 | GNUNET_DNSPARSER_TYPE_AAAA, |
849 | &sa6->sin6_addr); | 829 | sizeof(struct in6_addr), |
850 | break; | 830 | &sa6->sin6_addr); |
851 | default: | 831 | break; |
852 | GNUNET_break (0); | 832 | |
853 | break; | 833 | default: |
854 | } | 834 | GNUNET_break(0); |
835 | break; | ||
836 | } | ||
855 | } | 837 | } |
856 | 838 | ||
857 | 839 | ||
@@ -862,7 +844,7 @@ handle_dns_result (void *cls, | |||
862 | * @param tc task context | 844 | * @param tc task context |
863 | */ | 845 | */ |
864 | static void | 846 | static void |
865 | recursive_resolution (void *cls); | 847 | recursive_resolution(void *cls); |
866 | 848 | ||
867 | 849 | ||
868 | /** | 850 | /** |
@@ -872,7 +854,7 @@ recursive_resolution (void *cls); | |||
872 | * @param cls closure with `struct GNS_ResolverHandle *rh` | 854 | * @param cls closure with `struct GNS_ResolverHandle *rh` |
873 | */ | 855 | */ |
874 | static void | 856 | static void |
875 | start_resolver_lookup (void *cls); | 857 | start_resolver_lookup(void *cls); |
876 | 858 | ||
877 | 859 | ||
878 | /** | 860 | /** |
@@ -884,9 +866,9 @@ start_resolver_lookup (void *cls); | |||
884 | * @param dns_len number of bytes in @a dns | 866 | * @param dns_len number of bytes in @a dns |
885 | */ | 867 | */ |
886 | static void | 868 | static void |
887 | dns_result_parser (void *cls, | 869 | dns_result_parser(void *cls, |
888 | const struct GNUNET_TUN_DnsHeader *dns, | 870 | const struct GNUNET_TUN_DnsHeader *dns, |
889 | size_t dns_len) | 871 | size_t dns_len) |
890 | { | 872 | { |
891 | struct GNS_ResolverHandle *rh = cls; | 873 | struct GNS_ResolverHandle *rh = cls; |
892 | struct GNUNET_DNSPARSER_Packet *p; | 874 | struct GNUNET_DNSPARSER_Packet *p; |
@@ -894,80 +876,82 @@ dns_result_parser (void *cls, | |||
894 | unsigned int rd_count; | 876 | unsigned int rd_count; |
895 | 877 | ||
896 | if (NULL == dns) | 878 | if (NULL == dns) |
897 | { | 879 | { |
898 | rh->dns_request = NULL; | 880 | rh->dns_request = NULL; |
899 | GNUNET_SCHEDULER_cancel (rh->task_id); | 881 | GNUNET_SCHEDULER_cancel(rh->task_id); |
900 | rh->task_id = NULL; | 882 | rh->task_id = NULL; |
901 | fail_resolution (rh); | 883 | fail_resolution(rh); |
902 | return; | 884 | return; |
903 | } | 885 | } |
904 | if (rh->original_dns_id != dns->id) | 886 | if (rh->original_dns_id != dns->id) |
905 | { | 887 | { |
906 | /* DNS answer, but for another query */ | 888 | /* DNS answer, but for another query */ |
907 | return; | 889 | return; |
908 | } | 890 | } |
909 | p = GNUNET_DNSPARSER_parse ((const char *) dns, | 891 | p = GNUNET_DNSPARSER_parse((const char *)dns, |
910 | dns_len); | 892 | dns_len); |
911 | if (NULL == p) | 893 | if (NULL == p) |
912 | { | ||
913 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
914 | _("Failed to parse DNS response\n")); | ||
915 | return; | ||
916 | } | ||
917 | |||
918 | /* We got a result from DNS */ | ||
919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
920 | "Received DNS response for `%s' with %u answers\n", | ||
921 | rh->ac_tail->label, | ||
922 | (unsigned int) p->num_answers); | ||
923 | if ( (p->num_answers > 0) && | ||
924 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && | ||
925 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) | ||
926 | { | ||
927 | int af; | ||
928 | |||
929 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
930 | "Got CNAME `%s' from DNS for `%s'\n", | ||
931 | p->answers[0].data.hostname, | ||
932 | rh->name); | ||
933 | if (NULL != rh->std_resolve) | ||
934 | { | 894 | { |
935 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 895 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
936 | "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n", | 896 | _("Failed to parse DNS response\n")); |
937 | rh->name); | 897 | return; |
938 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | ||
939 | } | 898 | } |
940 | GNUNET_free (rh->name); | 899 | |
941 | rh->name = GNUNET_strdup (p->answers[0].data.hostname); | 900 | /* We got a result from DNS */ |
942 | rh->name_resolution_pos = strlen (rh->name); | 901 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
943 | switch (rh->record_type) | 902 | "Received DNS response for `%s' with %u answers\n", |
903 | rh->ac_tail->label, | ||
904 | (unsigned int)p->num_answers); | ||
905 | if ((p->num_answers > 0) && | ||
906 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && | ||
907 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type)) | ||
944 | { | 908 | { |
945 | case GNUNET_DNSPARSER_TYPE_A: | 909 | int af; |
946 | af = AF_INET; | 910 | |
947 | break; | 911 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
948 | case GNUNET_DNSPARSER_TYPE_AAAA: | 912 | "Got CNAME `%s' from DNS for `%s'\n", |
949 | af = AF_INET6; | 913 | p->answers[0].data.hostname, |
950 | break; | 914 | rh->name); |
951 | default: | 915 | if (NULL != rh->std_resolve) |
952 | af = AF_UNSPEC; | 916 | { |
953 | break; | 917 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
918 | "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n", | ||
919 | rh->name); | ||
920 | GNUNET_RESOLVER_request_cancel(rh->std_resolve); | ||
921 | } | ||
922 | GNUNET_free(rh->name); | ||
923 | rh->name = GNUNET_strdup(p->answers[0].data.hostname); | ||
924 | rh->name_resolution_pos = strlen(rh->name); | ||
925 | switch (rh->record_type) | ||
926 | { | ||
927 | case GNUNET_DNSPARSER_TYPE_A: | ||
928 | af = AF_INET; | ||
929 | break; | ||
930 | |||
931 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
932 | af = AF_INET6; | ||
933 | break; | ||
934 | |||
935 | default: | ||
936 | af = AF_UNSPEC; | ||
937 | 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 | } | 954 | } |
955 | if (NULL != rh->leho) | ||
956 | add_dns_result (rh, | ||
957 | GNUNET_TIME_UNIT_HOURS.rel_value_us, | ||
958 | GNUNET_GNSRECORD_TYPE_LEHO, | ||
959 | strlen (rh->leho), | ||
960 | rh->leho); | ||
961 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | ||
962 | af, | ||
963 | DNS_LOOKUP_TIMEOUT, | ||
964 | &handle_dns_result, | ||
965 | rh); | ||
966 | GNUNET_DNSPARSER_free_packet (p); | ||
967 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | ||
968 | rh->dns_request = NULL; | ||
969 | return; | ||
970 | } | ||
971 | 955 | ||
972 | /* convert from (parsed) DNS to (binary) GNS format! */ | 956 | /* convert from (parsed) DNS to (binary) GNS format! */ |
973 | rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; | 957 | rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; |
@@ -980,151 +964,157 @@ dns_result_parser (void *cls, | |||
980 | 964 | ||
981 | buf_off = 0; | 965 | buf_off = 0; |
982 | skip = 0; | 966 | skip = 0; |
983 | memset (rd, | 967 | memset(rd, |
984 | 0, | 968 | 0, |
985 | sizeof (rd)); | 969 | sizeof(rd)); |
986 | for (unsigned int i=0;i<rd_count;i++) | 970 | for (unsigned int i = 0; i < rd_count; i++) |
987 | { | ||
988 | if (i < p->num_answers) | ||
989 | rec = &p->answers[i]; | ||
990 | else if (i < p->num_answers + p->num_authority_records) | ||
991 | rec = &p->authority_records[i - p->num_answers]; | ||
992 | else | ||
993 | rec = &p->additional_records[i - p->num_answers - p->num_authority_records]; | ||
994 | /* As we copied the full DNS name to 'rh->ac_tail->label', this | ||
995 | should be the correct check to see if this record is actually | ||
996 | a record for our label... */ | ||
997 | if (0 != strcmp (rec->name, | ||
998 | rh->ac_tail->label)) | ||
999 | { | 971 | { |
1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 972 | if (i < p->num_answers) |
1001 | "Dropping record `%s', does not match desired name `%s'\n", | 973 | rec = &p->answers[i]; |
1002 | rec->name, | 974 | else if (i < p->num_answers + p->num_authority_records) |
1003 | rh->ac_tail->label); | 975 | rec = &p->authority_records[i - p->num_answers]; |
1004 | skip++; | 976 | else |
1005 | continue; | 977 | rec = &p->additional_records[i - p->num_answers - p->num_authority_records]; |
1006 | } | 978 | /* As we copied the full DNS name to 'rh->ac_tail->label', this |
1007 | rd[i - skip].record_type = rec->type; | 979 | should be the correct check to see if this record is actually |
1008 | rd[i - skip].expiration_time = rec->expiration_time.abs_value_us; | 980 | a record for our label... */ |
1009 | switch (rec->type) | 981 | if (0 != strcmp(rec->name, |
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) | ||
1010 | { | 1092 | { |
1011 | case GNUNET_DNSPARSER_TYPE_A: | 1093 | rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO; |
1012 | if (rec->data.raw.data_len != sizeof (struct in_addr)) | 1094 | rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1013 | { | 1095 | rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; |
1014 | GNUNET_break_op (0); | 1096 | rd[rd_count - skip].data = rh->leho; |
1015 | skip++; | 1097 | rd[rd_count - skip].data_size = strlen(rh->leho); |
1016 | continue; | 1098 | skip--; /* skip one LESS */ |
1017 | } | 1099 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1018 | rd[i - skip].data_size = rec->data.raw.data_len; | 1100 | "Adding LEHO %s\n", |
1019 | rd[i - skip].data = rec->data.raw.data; | 1101 | rh->leho); |
1020 | break; | ||
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 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1032 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
1033 | case GNUNET_DNSPARSER_TYPE_NS: | ||
1034 | buf_start = buf_off; | ||
1035 | if (GNUNET_OK != | ||
1036 | GNUNET_DNSPARSER_builder_add_name (buf, | ||
1037 | sizeof (buf), | ||
1038 | &buf_off, | ||
1039 | rec->data.hostname)) | ||
1040 | { | ||
1041 | GNUNET_break (0); | ||
1042 | skip++; | ||
1043 | continue; | ||
1044 | } | ||
1045 | rd[i - skip].data_size = buf_off - buf_start; | ||
1046 | rd[i - skip].data = &buf[buf_start]; | ||
1047 | break; | ||
1048 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
1049 | buf_start = buf_off; | ||
1050 | if (GNUNET_OK != | ||
1051 | GNUNET_DNSPARSER_builder_add_soa (buf, | ||
1052 | sizeof (buf), | ||
1053 | &buf_off, | ||
1054 | rec->data.soa)) | ||
1055 | { | ||
1056 | GNUNET_break (0); | ||
1057 | skip++; | ||
1058 | continue; | ||
1059 | } | ||
1060 | rd[i - skip].data_size = buf_off - buf_start; | ||
1061 | rd[i - skip].data = &buf[buf_start]; | ||
1062 | break; | ||
1063 | case GNUNET_DNSPARSER_TYPE_MX: | ||
1064 | buf_start = buf_off; | ||
1065 | if (GNUNET_OK != | ||
1066 | GNUNET_DNSPARSER_builder_add_mx (buf, | ||
1067 | sizeof (buf), | ||
1068 | &buf_off, | ||
1069 | rec->data.mx)) | ||
1070 | { | ||
1071 | GNUNET_break (0); | ||
1072 | skip++; | ||
1073 | continue; | ||
1074 | } | ||
1075 | rd[i - skip].data_size = buf_off - buf_start; | ||
1076 | rd[i - skip].data = &buf[buf_start]; | ||
1077 | break; | ||
1078 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
1079 | buf_start = buf_off; | ||
1080 | if (GNUNET_OK != | ||
1081 | GNUNET_DNSPARSER_builder_add_srv (buf, | ||
1082 | sizeof (buf), | ||
1083 | &buf_off, | ||
1084 | rec->data.srv)) | ||
1085 | { | ||
1086 | GNUNET_break (0); | ||
1087 | skip++; | ||
1088 | continue; | ||
1089 | } | ||
1090 | rd[i - skip].data_size = buf_off - buf_start; | ||
1091 | rd[i - skip].data = &buf[buf_start]; | ||
1092 | break; | ||
1093 | default: | ||
1094 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1095 | _("Skipping record of unsupported type %d\n"), | ||
1096 | rec->type); | ||
1097 | skip++; | ||
1098 | continue; | ||
1099 | } | 1102 | } |
1100 | } /* end of for all records in answer */ | 1103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1101 | if (NULL != rh->leho) | 1104 | "Returning DNS response for `%s' with %u answers\n", |
1102 | { | 1105 | rh->ac_tail->label, |
1103 | rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO; | 1106 | (unsigned int)(rd_count - skip)); |
1104 | rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1107 | rh->proc(rh->proc_cls, |
1105 | rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; | 1108 | rd_count - skip, |
1106 | rd[rd_count - skip].data = rh->leho; | 1109 | rd); |
1107 | rd[rd_count - skip].data_size = strlen (rh->leho); | 1110 | GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); |
1108 | skip--; /* skip one LESS */ | ||
1109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1110 | "Adding LEHO %s\n", | ||
1111 | rh->leho); | ||
1112 | } | ||
1113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1114 | "Returning DNS response for `%s' with %u answers\n", | ||
1115 | rh->ac_tail->label, | ||
1116 | (unsigned int) (rd_count - skip)); | ||
1117 | rh->proc (rh->proc_cls, | ||
1118 | rd_count - skip, | ||
1119 | rd); | ||
1120 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | ||
1121 | rh->dns_request = NULL; | 1111 | rh->dns_request = NULL; |
1122 | } | 1112 | } |
1123 | GNUNET_DNSPARSER_free_packet (p); | 1113 | GNUNET_DNSPARSER_free_packet(p); |
1124 | if (NULL != rh->task_id) | 1114 | if (NULL != rh->task_id) |
1125 | GNUNET_SCHEDULER_cancel (rh->task_id); /* should be timeout task */ | 1115 | GNUNET_SCHEDULER_cancel(rh->task_id); /* should be timeout task */ |
1126 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 1116 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
1127 | rh); | 1117 | rh); |
1128 | } | 1118 | } |
1129 | 1119 | ||
1130 | 1120 | ||
@@ -1137,7 +1127,7 @@ dns_result_parser (void *cls, | |||
1137 | * @param rh resolution information | 1127 | * @param rh resolution information |
1138 | */ | 1128 | */ |
1139 | static void | 1129 | static void |
1140 | recursive_dns_resolution (struct GNS_ResolverHandle *rh) | 1130 | recursive_dns_resolution(struct GNS_ResolverHandle *rh) |
1141 | { | 1131 | { |
1142 | struct AuthorityChain *ac; | 1132 | struct AuthorityChain *ac; |
1143 | struct GNUNET_DNSPARSER_Query *query; | 1133 | struct GNUNET_DNSPARSER_Query *query; |
@@ -1147,54 +1137,54 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh) | |||
1147 | int ret; | 1137 | int ret; |
1148 | 1138 | ||
1149 | ac = rh->ac_tail; | 1139 | ac = rh->ac_tail; |
1150 | GNUNET_assert (NULL != ac); | 1140 | GNUNET_assert(NULL != ac); |
1151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1152 | "Starting DNS lookup for `%s'\n", | 1142 | "Starting DNS lookup for `%s'\n", |
1153 | ac->label); | 1143 | ac->label); |
1154 | GNUNET_assert (GNUNET_NO == ac->gns_authority); | 1144 | GNUNET_assert(GNUNET_NO == ac->gns_authority); |
1155 | query = GNUNET_new (struct GNUNET_DNSPARSER_Query); | 1145 | query = GNUNET_new(struct GNUNET_DNSPARSER_Query); |
1156 | query->name = GNUNET_strdup (ac->label); | 1146 | query->name = GNUNET_strdup(ac->label); |
1157 | query->type = rh->record_type; | 1147 | query->type = rh->record_type; |
1158 | query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 1148 | query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
1159 | p = GNUNET_new (struct GNUNET_DNSPARSER_Packet); | 1149 | p = GNUNET_new(struct GNUNET_DNSPARSER_Packet); |
1160 | p->queries = query; | 1150 | p->queries = query; |
1161 | p->num_queries = 1; | 1151 | p->num_queries = 1; |
1162 | p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1152 | p->id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, |
1163 | UINT16_MAX); | 1153 | UINT16_MAX); |
1164 | p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY; | 1154 | p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY; |
1165 | p->flags.recursion_desired = 1; | 1155 | p->flags.recursion_desired = 1; |
1166 | ret = GNUNET_DNSPARSER_pack (p, | 1156 | ret = GNUNET_DNSPARSER_pack(p, |
1167 | 1024, | 1157 | 1024, |
1168 | &dns_request, | 1158 | &dns_request, |
1169 | &dns_request_length); | 1159 | &dns_request_length); |
1170 | if (GNUNET_OK != ret) | 1160 | if (GNUNET_OK != ret) |
1171 | { | 1161 | { |
1172 | GNUNET_break (0); | 1162 | GNUNET_break(0); |
1173 | rh->proc (rh->proc_cls, | 1163 | rh->proc(rh->proc_cls, |
1174 | 0, | 1164 | 0, |
1175 | NULL); | 1165 | NULL); |
1176 | GNUNET_assert (NULL == rh->task_id); | 1166 | GNUNET_assert(NULL == rh->task_id); |
1177 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 1167 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
1178 | rh); | 1168 | rh); |
1179 | } | 1169 | } |
1180 | else | 1170 | else |
1181 | { | 1171 | { |
1182 | rh->original_dns_id = p->id; | 1172 | rh->original_dns_id = p->id; |
1183 | GNUNET_assert (NULL != ac->authority_info.dns_authority.dns_handle); | 1173 | GNUNET_assert(NULL != ac->authority_info.dns_authority.dns_handle); |
1184 | GNUNET_assert (NULL == rh->dns_request); | 1174 | GNUNET_assert(NULL == rh->dns_request); |
1185 | rh->leho = GNUNET_strdup (ac->label); | 1175 | rh->leho = GNUNET_strdup(ac->label); |
1186 | rh->dns_request = GNUNET_DNSSTUB_resolve (ac->authority_info.dns_authority.dns_handle, | 1176 | rh->dns_request = GNUNET_DNSSTUB_resolve(ac->authority_info.dns_authority.dns_handle, |
1187 | dns_request, | 1177 | dns_request, |
1188 | dns_request_length, | 1178 | dns_request_length, |
1189 | &dns_result_parser, | 1179 | &dns_result_parser, |
1190 | rh); | 1180 | rh); |
1191 | rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT, | 1181 | rh->task_id = GNUNET_SCHEDULER_add_delayed(DNS_LOOKUP_TIMEOUT, |
1192 | &timeout_resolution, | 1182 | &timeout_resolution, |
1193 | rh); | 1183 | rh); |
1194 | } | 1184 | } |
1195 | if (GNUNET_SYSERR != ret) | 1185 | if (GNUNET_SYSERR != ret) |
1196 | GNUNET_free (dns_request); | 1186 | GNUNET_free(dns_request); |
1197 | GNUNET_DNSPARSER_free_packet (p); | 1187 | GNUNET_DNSPARSER_free_packet(p); |
1198 | } | 1188 | } |
1199 | 1189 | ||
1200 | 1190 | ||
@@ -1207,85 +1197,87 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh) | |||
1207 | * authority chain tail | 1197 | * authority chain tail |
1208 | */ | 1198 | */ |
1209 | static void | 1199 | static void |
1210 | handle_gns_cname_result (struct GNS_ResolverHandle *rh, | 1200 | handle_gns_cname_result(struct GNS_ResolverHandle *rh, |
1211 | const char *cname) | 1201 | const char *cname) |
1212 | { | 1202 | { |
1213 | size_t nlen; | 1203 | size_t nlen; |
1214 | char *res; | 1204 | char *res; |
1215 | struct AuthorityChain *ac; | 1205 | struct AuthorityChain *ac; |
1216 | int af; | 1206 | int af; |
1217 | 1207 | ||
1218 | nlen = strlen (cname); | 1208 | nlen = strlen(cname); |
1219 | if ( (nlen > 2) && | 1209 | if ((nlen > 2) && |
1220 | (0 == strcmp (".+", | 1210 | (0 == strcmp(".+", |
1221 | &cname[nlen - 2])) ) | 1211 | &cname[nlen - 2]))) |
1222 | { | ||
1223 | /* CNAME resolution continues relative to current domain */ | ||
1224 | if (0 == rh->name_resolution_pos) | ||
1225 | { | 1212 | { |
1226 | res = GNUNET_strndup (cname, nlen - 2); | 1213 | /* CNAME resolution continues relative to current domain */ |
1227 | rh->name_resolution_pos = nlen - 2; | 1214 | if (0 == rh->name_resolution_pos) |
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; | ||
1228 | } | 1243 | } |
1229 | else | 1244 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1245 | "Got CNAME `%s' from GNS for `%s'\n", | ||
1246 | cname, | ||
1247 | rh->name); | ||
1248 | if (NULL != rh->std_resolve) | ||
1230 | { | 1249 | { |
1231 | GNUNET_asprintf (&res, | 1250 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1232 | "%.*s.%.*s", | 1251 | "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n", |
1233 | (int) rh->name_resolution_pos, | 1252 | rh->name); |
1234 | rh->name, | 1253 | GNUNET_RESOLVER_request_cancel(rh->std_resolve); |
1235 | (int) (nlen - 2), | ||
1236 | cname); | ||
1237 | rh->name_resolution_pos = strlen (res); | ||
1238 | } | 1254 | } |
1239 | GNUNET_free (rh->name); | ||
1240 | rh->name = res; | ||
1241 | ac = GNUNET_new (struct AuthorityChain); | ||
1242 | ac->rh = rh; | ||
1243 | ac->gns_authority = GNUNET_YES; | ||
1244 | ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; | ||
1245 | ac->label = resolver_lookup_get_next_label (rh); | ||
1246 | /* add AC to tail */ | ||
1247 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | ||
1248 | rh->ac_tail, | ||
1249 | ac); | ||
1250 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | ||
1251 | rh); | ||
1252 | return; | ||
1253 | } | ||
1254 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1255 | "Got CNAME `%s' from GNS for `%s'\n", | ||
1256 | cname, | ||
1257 | rh->name); | ||
1258 | if (NULL != rh->std_resolve) | ||
1259 | { | ||
1260 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1261 | "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n", | ||
1262 | rh->name); | ||
1263 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | ||
1264 | } | ||
1265 | /* name is absolute, go to DNS */ | 1255 | /* name is absolute, go to DNS */ |
1266 | GNUNET_free (rh->name); | 1256 | GNUNET_free(rh->name); |
1267 | rh->name = GNUNET_strdup (cname); | 1257 | rh->name = GNUNET_strdup(cname); |
1268 | rh->name_resolution_pos = strlen (rh->name); | 1258 | rh->name_resolution_pos = strlen(rh->name); |
1269 | switch (rh->record_type) | 1259 | switch (rh->record_type) |
1270 | { | 1260 | { |
1271 | case GNUNET_DNSPARSER_TYPE_A: | 1261 | case GNUNET_DNSPARSER_TYPE_A: |
1272 | af = AF_INET; | 1262 | af = AF_INET; |
1273 | break; | 1263 | break; |
1274 | case GNUNET_DNSPARSER_TYPE_AAAA: | 1264 | |
1275 | af = AF_INET6; | 1265 | case GNUNET_DNSPARSER_TYPE_AAAA: |
1276 | break; | 1266 | af = AF_INET6; |
1277 | default: | 1267 | break; |
1278 | af = AF_UNSPEC; | 1268 | |
1279 | break; | 1269 | default: |
1280 | } | 1270 | af = AF_UNSPEC; |
1281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1271 | break; |
1282 | "Doing standard DNS lookup for `%s'\n", | 1272 | } |
1283 | rh->name); | 1273 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1284 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | 1274 | "Doing standard DNS lookup for `%s'\n", |
1285 | af, | 1275 | rh->name); |
1286 | DNS_LOOKUP_TIMEOUT, | 1276 | rh->std_resolve = GNUNET_RESOLVER_ip_get(rh->name, |
1287 | &handle_dns_result, | 1277 | af, |
1288 | rh); | 1278 | DNS_LOOKUP_TIMEOUT, |
1279 | &handle_dns_result, | ||
1280 | rh); | ||
1289 | } | 1281 | } |
1290 | 1282 | ||
1291 | 1283 | ||
@@ -1297,9 +1289,9 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1297 | * @param rd array of records with data to store | 1289 | * @param rd array of records with data to store |
1298 | */ | 1290 | */ |
1299 | static void | 1291 | static void |
1300 | handle_gns_resolution_result (void *cls, | 1292 | handle_gns_resolution_result(void *cls, |
1301 | unsigned int rd_count, | 1293 | unsigned int rd_count, |
1302 | const struct GNUNET_GNSRECORD_Data *rd); | 1294 | const struct GNUNET_GNSRECORD_Data *rd); |
1303 | 1295 | ||
1304 | 1296 | ||
1305 | /** | 1297 | /** |
@@ -1317,9 +1309,9 @@ handle_gns_resolution_result (void *cls, | |||
1317 | * specified target peer; NULL on error | 1309 | * specified target peer; NULL on error |
1318 | */ | 1310 | */ |
1319 | static void | 1311 | static void |
1320 | vpn_allocation_cb (void *cls, | 1312 | vpn_allocation_cb(void *cls, |
1321 | int af, | 1313 | int af, |
1322 | const void *address) | 1314 | const void *address) |
1323 | { | 1315 | { |
1324 | struct VpnContext *vpn_ctx = cls; | 1316 | struct VpnContext *vpn_ctx = cls; |
1325 | struct GNS_ResolverHandle *rh = vpn_ctx->rh; | 1317 | struct GNS_ResolverHandle *rh = vpn_ctx->rh; |
@@ -1328,47 +1320,49 @@ vpn_allocation_cb (void *cls, | |||
1328 | 1320 | ||
1329 | vpn_ctx->vpn_request = NULL; | 1321 | vpn_ctx->vpn_request = NULL; |
1330 | rh->vpn_ctx = NULL; | 1322 | rh->vpn_ctx = NULL; |
1331 | GNUNET_assert (GNUNET_OK == | 1323 | GNUNET_assert(GNUNET_OK == |
1332 | GNUNET_GNSRECORD_records_deserialize ((size_t) vpn_ctx->rd_data_size, | 1324 | GNUNET_GNSRECORD_records_deserialize((size_t)vpn_ctx->rd_data_size, |
1333 | vpn_ctx->rd_data, | 1325 | vpn_ctx->rd_data, |
1334 | vpn_ctx->rd_count, | 1326 | vpn_ctx->rd_count, |
1335 | rd)); | 1327 | rd)); |
1336 | for (i=0;i<vpn_ctx->rd_count;i++) | 1328 | for (i = 0; i < vpn_ctx->rd_count; i++) |
1337 | { | ||
1338 | if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) | ||
1339 | { | 1329 | { |
1340 | switch (af) | 1330 | if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) |
1341 | { | 1331 | { |
1342 | case AF_INET: | 1332 | switch (af) |
1343 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; | 1333 | { |
1344 | rd[i].data_size = sizeof (struct in_addr); | 1334 | case AF_INET: |
1345 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us; | 1335 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; |
1346 | rd[i].flags = 0; | 1336 | rd[i].data_size = sizeof(struct in_addr); |
1347 | rd[i].data = address; | 1337 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT).abs_value_us; |
1348 | break; | 1338 | rd[i].flags = 0; |
1349 | case AF_INET6: | 1339 | rd[i].data = address; |
1350 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; | 1340 | break; |
1351 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us; | 1341 | |
1352 | rd[i].flags = 0; | 1342 | case AF_INET6: |
1353 | rd[i].data = address; | 1343 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; |
1354 | rd[i].data_size = sizeof (struct in6_addr); | 1344 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT).abs_value_us; |
1355 | break; | 1345 | rd[i].flags = 0; |
1356 | default: | 1346 | rd[i].data = address; |
1357 | GNUNET_assert (0); | 1347 | rd[i].data_size = sizeof(struct in6_addr); |
1358 | } | 1348 | break; |
1359 | break; | 1349 | |
1350 | default: | ||
1351 | GNUNET_assert(0); | ||
1352 | } | ||
1353 | break; | ||
1354 | } | ||
1360 | } | 1355 | } |
1361 | } | 1356 | GNUNET_assert(i < vpn_ctx->rd_count); |
1362 | GNUNET_assert (i < vpn_ctx->rd_count); | ||
1363 | if (0 == vpn_ctx->rd_count) | 1357 | if (0 == vpn_ctx->rd_count) |
1364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1358 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1365 | _("VPN returned empty result for `%s'\n"), | 1359 | _("VPN returned empty result for `%s'\n"), |
1366 | rh->name); | 1360 | rh->name); |
1367 | handle_gns_resolution_result (rh, | 1361 | handle_gns_resolution_result(rh, |
1368 | vpn_ctx->rd_count, | 1362 | vpn_ctx->rd_count, |
1369 | rd); | 1363 | rd); |
1370 | GNUNET_free (vpn_ctx->rd_data); | 1364 | GNUNET_free(vpn_ctx->rd_data); |
1371 | GNUNET_free (vpn_ctx); | 1365 | GNUNET_free(vpn_ctx); |
1372 | } | 1366 | } |
1373 | 1367 | ||
1374 | 1368 | ||
@@ -1380,32 +1374,31 @@ vpn_allocation_cb (void *cls, | |||
1380 | * @param ac context for GNS2DNS resolution | 1374 | * @param ac context for GNS2DNS resolution |
1381 | */ | 1375 | */ |
1382 | static void | 1376 | static void |
1383 | continue_with_gns2dns (struct AuthorityChain *ac) | 1377 | continue_with_gns2dns(struct AuthorityChain *ac) |
1384 | { | 1378 | { |
1385 | struct GNS_ResolverHandle *rh = ac->rh; | 1379 | struct GNS_ResolverHandle *rh = ac->rh; |
1386 | 1380 | ||
1387 | if ( (NULL != ac->authority_info.dns_authority.gp_head) && | 1381 | if ((NULL != ac->authority_info.dns_authority.gp_head) && |
1388 | (GNUNET_NO == ac->authority_info.dns_authority.found) ) | 1382 | (GNUNET_NO == ac->authority_info.dns_authority.found)) |
1389 | return; /* more pending and none found yet */ | 1383 | return; /* more pending and none found yet */ |
1390 | if (GNUNET_NO == ac->authority_info.dns_authority.found) | 1384 | if (GNUNET_NO == ac->authority_info.dns_authority.found) |
1391 | { | 1385 | { |
1392 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1386 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1393 | "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n", | 1387 | "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n", |
1394 | ac->authority_info.dns_authority.name); | 1388 | ac->authority_info.dns_authority.name); |
1395 | fail_resolution (rh); | 1389 | fail_resolution(rh); |
1396 | return; | 1390 | return; |
1397 | } | 1391 | } |
1398 | if (GNUNET_NO != ac->authority_info.dns_authority.launched) | 1392 | if (GNUNET_NO != ac->authority_info.dns_authority.launched) |
1399 | return; /* already running, do not launch again! */ | 1393 | return; /* already running, do not launch again! */ |
1400 | /* recurse */ | 1394 | /* recurse */ |
1401 | ac->authority_info.dns_authority.launched = GNUNET_YES; | 1395 | ac->authority_info.dns_authority.launched = GNUNET_YES; |
1402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1403 | "Will continue resolution using DNS to resolve `%s'\n", | 1397 | "Will continue resolution using DNS to resolve `%s'\n", |
1404 | ac->label); | 1398 | ac->label); |
1405 | GNUNET_assert (NULL == rh->task_id); | 1399 | GNUNET_assert(NULL == rh->task_id); |
1406 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | 1400 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, |
1407 | rh); | 1401 | rh); |
1408 | |||
1409 | } | 1402 | } |
1410 | 1403 | ||
1411 | 1404 | ||
@@ -1418,93 +1411,95 @@ continue_with_gns2dns (struct AuthorityChain *ac) | |||
1418 | * @param rd addresses for the DNS resolver (presumably) | 1411 | * @param rd addresses for the DNS resolver (presumably) |
1419 | */ | 1412 | */ |
1420 | static void | 1413 | static void |
1421 | handle_gns2dns_result (void *cls, | 1414 | handle_gns2dns_result(void *cls, |
1422 | unsigned int rd_count, | 1415 | unsigned int rd_count, |
1423 | const struct GNUNET_GNSRECORD_Data *rd) | 1416 | const struct GNUNET_GNSRECORD_Data *rd) |
1424 | { | 1417 | { |
1425 | struct Gns2DnsPending *gp = cls; | 1418 | struct Gns2DnsPending *gp = cls; |
1426 | struct AuthorityChain *ac = gp->ac; | 1419 | struct AuthorityChain *ac = gp->ac; |
1427 | 1420 | ||
1428 | GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head, | 1421 | GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, |
1429 | ac->authority_info.dns_authority.gp_tail, | 1422 | ac->authority_info.dns_authority.gp_tail, |
1430 | gp); | 1423 | gp); |
1431 | /* enable cleanup of 'rh' handle that automatically comes after we return, | 1424 | /* enable cleanup of 'rh' handle that automatically comes after we return, |
1432 | and which expects 'rh' to be in the #rlh_head DLL. */ | 1425 | and which expects 'rh' to be in the #rlh_head DLL. */ |
1433 | if (NULL != gp->rh) | 1426 | if (NULL != gp->rh) |
1434 | { | 1427 | { |
1435 | GNUNET_CONTAINER_DLL_insert (rlh_head, | 1428 | GNUNET_CONTAINER_DLL_insert(rlh_head, |
1436 | rlh_tail, | 1429 | rlh_tail, |
1437 | gp->rh); | 1430 | gp->rh); |
1438 | gp->rh = NULL; | 1431 | gp->rh = NULL; |
1439 | } | 1432 | } |
1440 | GNUNET_free (gp); | 1433 | GNUNET_free(gp); |
1441 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1434 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1442 | "Received %u results for IP address of DNS server for GNS2DNS transition\n", | 1435 | "Received %u results for IP address of DNS server for GNS2DNS transition\n", |
1443 | rd_count); | 1436 | rd_count); |
1444 | /* find suitable A/AAAA record */ | 1437 | /* find suitable A/AAAA record */ |
1445 | for (unsigned int j=0;j<rd_count;j++) | 1438 | for (unsigned int j = 0; j < rd_count; j++) |
1446 | { | ||
1447 | switch (rd[j].record_type) | ||
1448 | { | 1439 | { |
1449 | case GNUNET_DNSPARSER_TYPE_A: | 1440 | switch (rd[j].record_type) |
1450 | { | ||
1451 | struct sockaddr_in v4; | ||
1452 | |||
1453 | if (sizeof (struct in_addr) != rd[j].data_size) | ||
1454 | { | 1441 | { |
1455 | GNUNET_break_op (0); | 1442 | case GNUNET_DNSPARSER_TYPE_A: |
1456 | continue; | 1443 | { |
1457 | } | 1444 | struct sockaddr_in v4; |
1458 | memset (&v4, | 1445 | |
1459 | 0, | 1446 | if (sizeof(struct in_addr) != rd[j].data_size) |
1460 | sizeof (v4)); | 1447 | { |
1461 | v4.sin_family = AF_INET; | 1448 | GNUNET_break_op(0); |
1462 | v4.sin_port = htons (53); | 1449 | continue; |
1450 | } | ||
1451 | memset(&v4, | ||
1452 | 0, | ||
1453 | sizeof(v4)); | ||
1454 | v4.sin_family = AF_INET; | ||
1455 | v4.sin_port = htons(53); | ||
1463 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1456 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1464 | v4.sin_len = (u_char) sizeof (v4); | 1457 | v4.sin_len = (u_char)sizeof(v4); |
1465 | #endif | 1458 | #endif |
1466 | GNUNET_memcpy (&v4.sin_addr, | 1459 | GNUNET_memcpy(&v4.sin_addr, |
1467 | rd[j].data, | 1460 | rd[j].data, |
1468 | sizeof (struct in_addr)); | 1461 | sizeof(struct in_addr)); |
1469 | if (GNUNET_OK == | 1462 | if (GNUNET_OK == |
1470 | GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, | 1463 | GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, |
1471 | (const struct sockaddr *) &v4)) | 1464 | (const struct sockaddr *)&v4)) |
1472 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1465 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1473 | break; | 1466 | break; |
1474 | } | 1467 | } |
1475 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
1476 | { | ||
1477 | struct sockaddr_in6 v6; | ||
1478 | 1468 | ||
1479 | if (sizeof (struct in6_addr) != rd[j].data_size) | 1469 | case GNUNET_DNSPARSER_TYPE_AAAA: |
1480 | { | 1470 | { |
1481 | GNUNET_break_op (0); | 1471 | struct sockaddr_in6 v6; |
1482 | continue; | 1472 | |
1483 | } | 1473 | if (sizeof(struct in6_addr) != rd[j].data_size) |
1484 | /* FIXME: might want to check if we support IPv6 here, | 1474 | { |
1485 | and otherwise skip this one and hope we find another */ | 1475 | GNUNET_break_op(0); |
1486 | memset (&v6, | 1476 | continue; |
1487 | 0, | 1477 | } |
1488 | sizeof (v6)); | 1478 | /* FIXME: might want to check if we support IPv6 here, |
1489 | v6.sin6_family = AF_INET6; | 1479 | and otherwise skip this one and hope we find another */ |
1490 | v6.sin6_port = htons (53); | 1480 | memset(&v6, |
1481 | 0, | ||
1482 | sizeof(v6)); | ||
1483 | v6.sin6_family = AF_INET6; | ||
1484 | v6.sin6_port = htons(53); | ||
1491 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1485 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1492 | v6.sin6_len = (u_char) sizeof (v6); | 1486 | v6.sin6_len = (u_char)sizeof(v6); |
1493 | #endif | 1487 | #endif |
1494 | GNUNET_memcpy (&v6.sin6_addr, | 1488 | GNUNET_memcpy(&v6.sin6_addr, |
1495 | rd[j].data, | 1489 | rd[j].data, |
1496 | sizeof (struct in6_addr)); | 1490 | sizeof(struct in6_addr)); |
1497 | if (GNUNET_OK == | 1491 | if (GNUNET_OK == |
1498 | GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, | 1492 | GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, |
1499 | (const struct sockaddr *) &v6)) | 1493 | (const struct sockaddr *)&v6)) |
1500 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1494 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1501 | break; | 1495 | break; |
1502 | } | 1496 | } |
1503 | default: | 1497 | |
1504 | break; | 1498 | default: |
1499 | break; | ||
1500 | } | ||
1505 | } | 1501 | } |
1506 | } | 1502 | continue_with_gns2dns(ac); |
1507 | continue_with_gns2dns (ac); | ||
1508 | } | 1503 | } |
1509 | 1504 | ||
1510 | 1505 | ||
@@ -1516,9 +1511,9 @@ handle_gns2dns_result (void *cls, | |||
1516 | * @param addrlen length of @a addr | 1511 | * @param addrlen length of @a addr |
1517 | */ | 1512 | */ |
1518 | static void | 1513 | static void |
1519 | handle_gns2dns_ip (void *cls, | 1514 | handle_gns2dns_ip(void *cls, |
1520 | const struct sockaddr *addr, | 1515 | const struct sockaddr *addr, |
1521 | socklen_t addrlen) | 1516 | socklen_t addrlen) |
1522 | { | 1517 | { |
1523 | struct Gns2DnsPending *gp = cls; | 1518 | struct Gns2DnsPending *gp = cls; |
1524 | struct AuthorityChain *ac = gp->ac; | 1519 | struct AuthorityChain *ac = gp->ac; |
@@ -1527,42 +1522,44 @@ handle_gns2dns_ip (void *cls, | |||
1527 | struct sockaddr_in6 *v6; | 1522 | struct sockaddr_in6 *v6; |
1528 | 1523 | ||
1529 | if (NULL == addr) | 1524 | if (NULL == addr) |
1530 | { | 1525 | { |
1531 | /* DNS resolution finished */ | 1526 | /* DNS resolution finished */ |
1532 | if (0 == gp->num_results) | 1527 | if (0 == gp->num_results) |
1533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1528 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1534 | "Failed to use DNS to resolve name of DNS resolver\n"); | 1529 | "Failed to use DNS to resolve name of DNS resolver\n"); |
1535 | GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head, | 1530 | GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, |
1536 | ac->authority_info.dns_authority.gp_tail, | 1531 | ac->authority_info.dns_authority.gp_tail, |
1537 | gp); | 1532 | gp); |
1538 | GNUNET_free (gp); | 1533 | GNUNET_free(gp); |
1539 | continue_with_gns2dns (ac); | 1534 | continue_with_gns2dns(ac); |
1540 | return; | 1535 | return; |
1541 | } | 1536 | } |
1542 | GNUNET_memcpy (&ss, | 1537 | GNUNET_memcpy(&ss, |
1543 | addr, | 1538 | addr, |
1544 | addrlen); | 1539 | addrlen); |
1545 | switch (ss.ss_family) | 1540 | switch (ss.ss_family) |
1546 | { | 1541 | { |
1547 | case AF_INET: | 1542 | case AF_INET: |
1548 | v4 = (struct sockaddr_in *) &ss; | 1543 | v4 = (struct sockaddr_in *)&ss; |
1549 | v4->sin_port = htons (53); | 1544 | v4->sin_port = htons(53); |
1550 | gp->num_results++; | 1545 | gp->num_results++; |
1551 | break; | 1546 | break; |
1552 | case AF_INET6: | 1547 | |
1553 | v6 = (struct sockaddr_in6 *) &ss; | 1548 | case AF_INET6: |
1554 | v6->sin6_port = htons (53); | 1549 | v6 = (struct sockaddr_in6 *)&ss; |
1555 | gp->num_results++; | 1550 | v6->sin6_port = htons(53); |
1556 | break; | 1551 | gp->num_results++; |
1557 | default: | 1552 | break; |
1558 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1553 | |
1559 | "Unsupported AF %d\n", | 1554 | default: |
1560 | ss.ss_family); | 1555 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1561 | return; | 1556 | "Unsupported AF %d\n", |
1562 | } | 1557 | ss.ss_family); |
1558 | return; | ||
1559 | } | ||
1563 | if (GNUNET_OK == | 1560 | if (GNUNET_OK == |
1564 | GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, | 1561 | GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, |
1565 | (struct sockaddr *) &ss)) | 1562 | (struct sockaddr *)&ss)) |
1566 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1563 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1567 | } | 1564 | } |
1568 | 1565 | ||
@@ -1574,27 +1571,27 @@ handle_gns2dns_ip (void *cls, | |||
1574 | * @param rd record with CNAME to resolve recursively | 1571 | * @param rd record with CNAME to resolve recursively |
1575 | */ | 1572 | */ |
1576 | static void | 1573 | static void |
1577 | recursive_cname_resolution (struct GNS_ResolverHandle *rh, | 1574 | recursive_cname_resolution(struct GNS_ResolverHandle *rh, |
1578 | const struct GNUNET_GNSRECORD_Data *rd) | 1575 | const struct GNUNET_GNSRECORD_Data *rd) |
1579 | { | 1576 | { |
1580 | char *cname; | 1577 | char *cname; |
1581 | size_t off; | 1578 | size_t off; |
1582 | 1579 | ||
1583 | off = 0; | 1580 | off = 0; |
1584 | cname = GNUNET_DNSPARSER_parse_name (rd->data, | 1581 | cname = GNUNET_DNSPARSER_parse_name(rd->data, |
1585 | rd->data_size, | 1582 | rd->data_size, |
1586 | &off); | 1583 | &off); |
1587 | if ( (NULL == cname) || | 1584 | if ((NULL == cname) || |
1588 | (off != rd->data_size) ) | 1585 | (off != rd->data_size)) |
1589 | { | 1586 | { |
1590 | GNUNET_break_op (0); /* record not well-formed */ | 1587 | GNUNET_break_op(0); /* record not well-formed */ |
1591 | GNUNET_free_non_null (cname); | 1588 | GNUNET_free_non_null(cname); |
1592 | fail_resolution (rh); | 1589 | fail_resolution(rh); |
1593 | return; | 1590 | return; |
1594 | } | 1591 | } |
1595 | handle_gns_cname_result (rh, | 1592 | handle_gns_cname_result(rh, |
1596 | cname); | 1593 | cname); |
1597 | GNUNET_free (cname); | 1594 | GNUNET_free(cname); |
1598 | } | 1595 | } |
1599 | 1596 | ||
1600 | 1597 | ||
@@ -1605,34 +1602,34 @@ recursive_cname_resolution (struct GNS_ResolverHandle *rh, | |||
1605 | * @param rd record with PKEY to resolve recursively | 1602 | * @param rd record with PKEY to resolve recursively |
1606 | */ | 1603 | */ |
1607 | static void | 1604 | static void |
1608 | recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | 1605 | recursive_pkey_resolution(struct GNS_ResolverHandle *rh, |
1609 | const struct GNUNET_GNSRECORD_Data *rd) | 1606 | const struct GNUNET_GNSRECORD_Data *rd) |
1610 | { | 1607 | { |
1611 | struct AuthorityChain *ac; | 1608 | struct AuthorityChain *ac; |
1612 | 1609 | ||
1613 | /* delegation to another zone */ | 1610 | /* delegation to another zone */ |
1614 | if (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) != | 1611 | if (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != |
1615 | rd->data_size) | 1612 | rd->data_size) |
1616 | { | 1613 | { |
1617 | GNUNET_break_op (0); | 1614 | GNUNET_break_op(0); |
1618 | fail_resolution (rh); | 1615 | fail_resolution(rh); |
1619 | return; | 1616 | return; |
1620 | } | 1617 | } |
1621 | /* expand authority chain */ | 1618 | /* expand authority chain */ |
1622 | ac = GNUNET_new (struct AuthorityChain); | 1619 | ac = GNUNET_new(struct AuthorityChain); |
1623 | ac->rh = rh; | 1620 | ac->rh = rh; |
1624 | ac->gns_authority = GNUNET_YES; | 1621 | ac->gns_authority = GNUNET_YES; |
1625 | GNUNET_memcpy (&ac->authority_info.gns_authority, | 1622 | GNUNET_memcpy(&ac->authority_info.gns_authority, |
1626 | rd->data, | 1623 | rd->data, |
1627 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1624 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
1628 | ac->label = resolver_lookup_get_next_label (rh); | 1625 | ac->label = resolver_lookup_get_next_label(rh); |
1629 | /* add AC to tail */ | 1626 | /* add AC to tail */ |
1630 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1627 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, |
1631 | rh->ac_tail, | 1628 | rh->ac_tail, |
1632 | ac); | 1629 | ac); |
1633 | /* recurse */ | 1630 | /* recurse */ |
1634 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | 1631 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, |
1635 | rh); | 1632 | rh); |
1636 | } | 1633 | } |
1637 | 1634 | ||
1638 | 1635 | ||
@@ -1647,9 +1644,9 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | |||
1647 | * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd | 1644 | * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd |
1648 | */ | 1645 | */ |
1649 | static int | 1646 | static int |
1650 | recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | 1647 | recursive_gns2dns_resolution(struct GNS_ResolverHandle *rh, |
1651 | unsigned int rd_count, | 1648 | unsigned int rd_count, |
1652 | const struct GNUNET_GNSRECORD_Data *rd) | 1649 | const struct GNUNET_GNSRECORD_Data *rd) |
1653 | { | 1650 | { |
1654 | struct AuthorityChain *ac; | 1651 | struct AuthorityChain *ac; |
1655 | const char *tld; | 1652 | const char *tld; |
@@ -1657,157 +1654,157 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1657 | 1654 | ||
1658 | ns = NULL; | 1655 | ns = NULL; |
1659 | /* expand authority chain */ | 1656 | /* expand authority chain */ |
1660 | ac = GNUNET_new (struct AuthorityChain); | 1657 | ac = GNUNET_new(struct AuthorityChain); |
1661 | ac->rh = rh; | 1658 | ac->rh = rh; |
1662 | ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start (4); | 1659 | ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start(4); |
1663 | 1660 | ||
1664 | for (unsigned int i=0;i<rd_count;i++) | 1661 | for (unsigned int i = 0; i < rd_count; i++) |
1665 | { | ||
1666 | char *ip; | ||
1667 | char *n; | ||
1668 | size_t off; | ||
1669 | struct Gns2DnsPending *gp; | ||
1670 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | ||
1671 | struct sockaddr_in v4; | ||
1672 | struct sockaddr_in6 v6; | ||
1673 | |||
1674 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) | ||
1675 | continue; | ||
1676 | off = 0; | ||
1677 | n = GNUNET_DNSPARSER_parse_name (rd[i].data, | ||
1678 | rd[i].data_size, | ||
1679 | &off); | ||
1680 | ip = GNUNET_DNSPARSER_parse_name (rd[i].data, | ||
1681 | rd[i].data_size, | ||
1682 | &off); | ||
1683 | if ( (NULL == n) || | ||
1684 | (NULL == ip) || | ||
1685 | (off != rd[i].data_size) ) | ||
1686 | { | 1662 | { |
1687 | GNUNET_break_op (0); | 1663 | char *ip; |
1688 | GNUNET_free_non_null (n); | 1664 | char *n; |
1689 | GNUNET_free_non_null (ip); | 1665 | size_t off; |
1690 | continue; | 1666 | struct Gns2DnsPending *gp; |
1691 | } | 1667 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; |
1692 | /* resolve 'ip' to determine the IP(s) of the DNS | 1668 | struct sockaddr_in v4; |
1693 | resolver to use for lookup of 'ns' */ | 1669 | struct sockaddr_in6 v6; |
1694 | if (NULL != ns) | 1670 | |
1695 | { | 1671 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) |
1696 | if (0 != strcasecmp (ns, | ||
1697 | n)) | ||
1698 | { | ||
1699 | /* NS values must all be the same for all GNS2DNS records, | ||
1700 | anything else leads to insanity */ | ||
1701 | GNUNET_break_op (0); | ||
1702 | GNUNET_free (n); | ||
1703 | GNUNET_free (ip); | ||
1704 | continue; | 1672 | continue; |
1705 | } | 1673 | off = 0; |
1706 | GNUNET_free (n); | 1674 | n = GNUNET_DNSPARSER_parse_name(rd[i].data, |
1707 | } | 1675 | rd[i].data_size, |
1708 | else | 1676 | &off); |
1709 | { | 1677 | ip = GNUNET_DNSPARSER_parse_name(rd[i].data, |
1710 | ns = n; | 1678 | rd[i].data_size, |
1711 | } | 1679 | &off); |
1680 | if ((NULL == n) || | ||
1681 | (NULL == ip) || | ||
1682 | (off != rd[i].data_size)) | ||
1683 | { | ||
1684 | GNUNET_break_op(0); | ||
1685 | GNUNET_free_non_null(n); | ||
1686 | GNUNET_free_non_null(ip); | ||
1687 | continue; | ||
1688 | } | ||
1689 | /* resolve 'ip' to determine the IP(s) of the DNS | ||
1690 | resolver to use for lookup of 'ns' */ | ||
1691 | if (NULL != ns) | ||
1692 | { | ||
1693 | if (0 != strcasecmp(ns, | ||
1694 | n)) | ||
1695 | { | ||
1696 | /* NS values must all be the same for all GNS2DNS records, | ||
1697 | anything else leads to insanity */ | ||
1698 | GNUNET_break_op(0); | ||
1699 | GNUNET_free(n); | ||
1700 | GNUNET_free(ip); | ||
1701 | continue; | ||
1702 | } | ||
1703 | GNUNET_free(n); | ||
1704 | } | ||
1705 | else | ||
1706 | { | ||
1707 | ns = n; | ||
1708 | } | ||
1712 | 1709 | ||
1713 | /* check if 'ip' is already an IPv4/IPv6 address */ | 1710 | /* check if 'ip' is already an IPv4/IPv6 address */ |
1714 | if ( (1 == inet_pton (AF_INET, | 1711 | if ((1 == inet_pton(AF_INET, |
1715 | ip, | 1712 | ip, |
1716 | &v4)) || | 1713 | &v4)) || |
1717 | (1 == inet_pton (AF_INET6, | 1714 | (1 == inet_pton(AF_INET6, |
1718 | ip, | 1715 | ip, |
1719 | &v6)) ) | 1716 | &v6))) |
1720 | { | 1717 | { |
1721 | GNUNET_break (GNUNET_OK == | 1718 | GNUNET_break(GNUNET_OK == |
1722 | GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle, | 1719 | GNUNET_DNSSTUB_add_dns_ip(ac->authority_info.dns_authority.dns_handle, |
1723 | ip)); | 1720 | ip)); |
1724 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1721 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1725 | GNUNET_free (ip); | 1722 | GNUNET_free(ip); |
1726 | continue; | 1723 | continue; |
1727 | } | 1724 | } |
1728 | tld = GNS_get_tld (ip); | 1725 | tld = GNS_get_tld(ip); |
1729 | if (0 != strcmp (tld, | 1726 | if (0 != strcmp(tld, |
1730 | "+")) | 1727 | "+")) |
1731 | { | 1728 | { |
1732 | /* 'ip' is a DNS name */ | 1729 | /* 'ip' is a DNS name */ |
1733 | gp = GNUNET_new (struct Gns2DnsPending); | 1730 | gp = GNUNET_new(struct Gns2DnsPending); |
1731 | gp->ac = ac; | ||
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); | ||
1734 | gp->ac = ac; | 1745 | gp->ac = ac; |
1735 | GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head, | 1746 | GNUNET_CONTAINER_DLL_insert(ac->authority_info.dns_authority.gp_head, |
1736 | ac->authority_info.dns_authority.gp_tail, | 1747 | ac->authority_info.dns_authority.gp_tail, |
1737 | gp); | 1748 | gp); |
1738 | gp->dns_rh = GNUNET_RESOLVER_ip_get (ip, | 1749 | gp->rh = GNUNET_new(struct GNS_ResolverHandle); |
1739 | AF_UNSPEC, | 1750 | ip = translate_dot_plus(rh, |
1740 | GNUNET_TIME_UNIT_FOREVER_REL, | 1751 | ip); |
1741 | &handle_gns2dns_ip, | 1752 | tld = GNS_get_tld(ip); |
1742 | gp); | 1753 | if (GNUNET_OK != |
1743 | GNUNET_free (ip); | 1754 | GNUNET_GNSRECORD_zkey_to_pkey(tld, |
1744 | continue; | 1755 | &zone)) |
1745 | } | 1756 | { |
1746 | /* 'ip' should be a GNS name */ | 1757 | GNUNET_break_op(0); |
1747 | gp = GNUNET_new (struct Gns2DnsPending); | 1758 | GNUNET_free(ip); |
1748 | gp->ac = ac; | 1759 | continue; |
1749 | GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head, | 1760 | } |
1750 | ac->authority_info.dns_authority.gp_tail, | 1761 | gp->rh->authority_zone = zone; |
1751 | gp); | 1762 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1752 | gp->rh = GNUNET_new (struct GNS_ResolverHandle); | 1763 | "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n", |
1753 | ip = translate_dot_plus (rh, | 1764 | ip, |
1754 | ip); | 1765 | ns); |
1755 | tld = GNS_get_tld (ip); | 1766 | gp->rh->name = ip; |
1756 | if (GNUNET_OK != | 1767 | gp->rh->name_resolution_pos = strlen(ip) - strlen(tld) - 1; |
1757 | GNUNET_GNSRECORD_zkey_to_pkey (tld, | 1768 | gp->rh->proc = &handle_gns2dns_result; |
1758 | &zone)) | 1769 | gp->rh->proc_cls = gp; |
1759 | { | 1770 | gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
1760 | GNUNET_break_op (0); | 1771 | gp->rh->options = GNUNET_GNS_LO_DEFAULT; |
1761 | GNUNET_free (ip); | 1772 | gp->rh->loop_limiter = rh->loop_limiter + 1; |
1762 | continue; | 1773 | gp->rh->task_id |
1763 | } | 1774 | = GNUNET_SCHEDULER_add_now(&start_resolver_lookup, |
1764 | gp->rh->authority_zone = zone; | 1775 | gp->rh); |
1765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1776 | } /* end 'for all records' */ |
1766 | "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n", | ||
1767 | ip, | ||
1768 | ns); | ||
1769 | gp->rh->name = ip; | ||
1770 | gp->rh->name_resolution_pos = strlen (ip) - strlen (tld) - 1; | ||
1771 | gp->rh->proc = &handle_gns2dns_result; | ||
1772 | gp->rh->proc_cls = gp; | ||
1773 | gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; | ||
1774 | gp->rh->options = GNUNET_GNS_LO_DEFAULT; | ||
1775 | gp->rh->loop_limiter = rh->loop_limiter + 1; | ||
1776 | gp->rh->task_id | ||
1777 | = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | ||
1778 | gp->rh); | ||
1779 | } /* end 'for all records' */ | ||
1780 | 1777 | ||
1781 | if (NULL == ns) | 1778 | if (NULL == ns) |
1782 | { | 1779 | { |
1783 | /* not a single GNS2DNS record found */ | 1780 | /* not a single GNS2DNS record found */ |
1784 | GNUNET_free (ac); | 1781 | GNUNET_free(ac); |
1785 | return GNUNET_SYSERR; | 1782 | return GNUNET_SYSERR; |
1786 | } | 1783 | } |
1787 | GNUNET_assert (strlen (ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH); | 1784 | GNUNET_assert(strlen(ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH); |
1788 | strcpy (ac->authority_info.dns_authority.name, | 1785 | strcpy(ac->authority_info.dns_authority.name, |
1789 | ns); | 1786 | ns); |
1790 | /* for DNS recursion, the label is the full DNS name, | 1787 | /* for DNS recursion, the label is the full DNS name, |
1791 | created from the remainder of the GNS name and the | 1788 | created from the remainder of the GNS name and the |
1792 | name in the NS record */ | 1789 | name in the NS record */ |
1793 | GNUNET_asprintf (&ac->label, | 1790 | GNUNET_asprintf(&ac->label, |
1794 | "%.*s%s%s", | 1791 | "%.*s%s%s", |
1795 | (int) rh->name_resolution_pos, | 1792 | (int)rh->name_resolution_pos, |
1796 | rh->name, | 1793 | rh->name, |
1797 | (0 != rh->name_resolution_pos) ? "." : "", | 1794 | (0 != rh->name_resolution_pos) ? "." : "", |
1798 | ns); | 1795 | ns); |
1799 | GNUNET_free (ns); | 1796 | GNUNET_free(ns); |
1800 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1797 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, |
1801 | rh->ac_tail, | 1798 | rh->ac_tail, |
1802 | ac); | 1799 | ac); |
1803 | if (strlen (ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) | 1800 | if (strlen(ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) |
1804 | { | 1801 | { |
1805 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1802 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1806 | _("GNS lookup resulted in DNS name that is too long (`%s')\n"), | 1803 | _("GNS lookup resulted in DNS name that is too long (`%s')\n"), |
1807 | ac->label); | 1804 | ac->label); |
1808 | return GNUNET_SYSERR; | 1805 | return GNUNET_SYSERR; |
1809 | } | 1806 | } |
1810 | continue_with_gns2dns (ac); | 1807 | continue_with_gns2dns(ac); |
1811 | return GNUNET_OK; | 1808 | return GNUNET_OK; |
1812 | } | 1809 | } |
1813 | 1810 | ||
@@ -1820,9 +1817,9 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1820 | * @param rd array of records with data to store | 1817 | * @param rd array of records with data to store |
1821 | */ | 1818 | */ |
1822 | static void | 1819 | static void |
1823 | handle_gns_resolution_result (void *cls, | 1820 | handle_gns_resolution_result(void *cls, |
1824 | unsigned int rd_count, | 1821 | unsigned int rd_count, |
1825 | const struct GNUNET_GNSRECORD_Data *rd) | 1822 | const struct GNUNET_GNSRECORD_Data *rd) |
1826 | { | 1823 | { |
1827 | struct GNS_ResolverHandle *rh = cls; | 1824 | struct GNS_ResolverHandle *rh = cls; |
1828 | char *cname; | 1825 | char *cname; |
@@ -1838,431 +1835,442 @@ handle_gns_resolution_result (void *cls, | |||
1838 | struct GNUNET_GNSRECORD_Data rd_new[rd_count]; | 1835 | struct GNUNET_GNSRECORD_Data rd_new[rd_count]; |
1839 | unsigned int rd_off; | 1836 | unsigned int rd_off; |
1840 | 1837 | ||
1841 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1838 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1842 | "Resolution succeeded for `%s' in zone %s, got %u records\n", | 1839 | "Resolution succeeded for `%s' in zone %s, got %u records\n", |
1843 | rh->ac_tail->label, | 1840 | rh->ac_tail->label, |
1844 | GNUNET_GNSRECORD_z2s (&rh->ac_tail->authority_info.gns_authority), | 1841 | GNUNET_GNSRECORD_z2s(&rh->ac_tail->authority_info.gns_authority), |
1845 | rd_count); | 1842 | rd_count); |
1846 | if (0 == rd_count) | 1843 | if (0 == rd_count) |
1847 | { | ||
1848 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1849 | _("GNS lookup failed (zero records found for `%s')\n"), | ||
1850 | rh->name); | ||
1851 | fail_resolution (rh); | ||
1852 | return; | ||
1853 | } | ||
1854 | |||
1855 | if (0 == rh->name_resolution_pos) | ||
1856 | { | ||
1857 | /* top-level match, are we done yet? */ | ||
1858 | if ( (rd_count > 0) && | ||
1859 | (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) && | ||
1860 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) | ||
1861 | { | 1844 | { |
1862 | off = 0; | 1845 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1863 | cname = GNUNET_DNSPARSER_parse_name (rd[0].data, | 1846 | _("GNS lookup failed (zero records found for `%s')\n"), |
1864 | rd[0].data_size, | 1847 | rh->name); |
1865 | &off); | 1848 | fail_resolution(rh); |
1866 | if ( (NULL == cname) || | ||
1867 | (off != rd[0].data_size) ) | ||
1868 | { | ||
1869 | GNUNET_break_op (0); | ||
1870 | GNUNET_free_non_null (cname); | ||
1871 | fail_resolution (rh); | ||
1872 | return; | ||
1873 | } | ||
1874 | handle_gns_cname_result (rh, | ||
1875 | cname); | ||
1876 | GNUNET_free (cname); | ||
1877 | return; | 1849 | return; |
1878 | } | 1850 | } |
1879 | /* If A/AAAA was requested, but we got a VPN | 1851 | |
1880 | record, we convert it to A/AAAA using GNUnet VPN */ | 1852 | if (0 == rh->name_resolution_pos) |
1881 | if ( (GNUNET_DNSPARSER_TYPE_A == rh->record_type) || | ||
1882 | (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type) ) | ||
1883 | { | 1853 | { |
1884 | for (unsigned int i=0;i<rd_count;i++) | 1854 | /* top-level match, are we done yet? */ |
1885 | { | 1855 | if ((rd_count > 0) && |
1886 | switch (rd[i].record_type) | 1856 | (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) && |
1887 | { | 1857 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type)) |
1888 | case GNUNET_GNSRECORD_TYPE_VPN: | 1858 | { |
1889 | { | 1859 | off = 0; |
1890 | af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6; | 1860 | cname = GNUNET_DNSPARSER_parse_name(rd[0].data, |
1891 | if (sizeof (struct GNUNET_TUN_GnsVpnRecord) > | 1861 | rd[0].data_size, |
1892 | rd[i].data_size) | 1862 | &off); |
1893 | { | 1863 | if ((NULL == cname) || |
1894 | GNUNET_break_op (0); | 1864 | (off != rd[0].data_size)) |
1895 | fail_resolution (rh); | ||
1896 | return; | ||
1897 | } | ||
1898 | vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data; | ||
1899 | vname = (const char *) &vpn[1]; | ||
1900 | if ('\0' != vname[rd[i].data_size - 1 - sizeof (struct GNUNET_TUN_GnsVpnRecord)]) | ||
1901 | { | ||
1902 | GNUNET_break_op (0); | ||
1903 | fail_resolution (rh); | ||
1904 | return; | ||
1905 | } | ||
1906 | GNUNET_TUN_service_name_to_hash (vname, | ||
1907 | &vhash); | ||
1908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1909 | "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n", | ||
1910 | GNUNET_i2s (&vpn->peer), | ||
1911 | vname, | ||
1912 | (int) af, | ||
1913 | (int) ntohs (vpn->proto)); | ||
1914 | vpn_ctx = GNUNET_new (struct VpnContext); | ||
1915 | rh->vpn_ctx = vpn_ctx; | ||
1916 | vpn_ctx->rh = rh; | ||
1917 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1918 | rd); | ||
1919 | if (vpn_ctx->rd_data_size < 0) | ||
1920 | { | 1865 | { |
1921 | GNUNET_break_op (0); | 1866 | GNUNET_break_op(0); |
1922 | GNUNET_free (vpn_ctx); | 1867 | GNUNET_free_non_null(cname); |
1923 | fail_resolution (rh); | 1868 | fail_resolution(rh); |
1924 | return; | ||
1925 | } | ||
1926 | vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size); | ||
1927 | vpn_ctx->rd_count = rd_count; | ||
1928 | GNUNET_assert (vpn_ctx->rd_data_size == | ||
1929 | GNUNET_GNSRECORD_records_serialize (rd_count, | ||
1930 | rd, | ||
1931 | (size_t) vpn_ctx->rd_data_size, | ||
1932 | vpn_ctx->rd_data)); | ||
1933 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, | ||
1934 | af, | ||
1935 | ntohs (vpn->proto), | ||
1936 | &vpn->peer, | ||
1937 | &vhash, | ||
1938 | GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT), | ||
1939 | &vpn_allocation_cb, | ||
1940 | vpn_ctx); | ||
1941 | return; | ||
1942 | } | ||
1943 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | ||
1944 | { | ||
1945 | /* delegation to DNS */ | ||
1946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1947 | "Found GNS2DNS record, delegating to DNS!\n"); | ||
1948 | if (GNUNET_OK == | ||
1949 | recursive_gns2dns_resolution (rh, | ||
1950 | rd_count, | ||
1951 | rd)) | ||
1952 | return; | 1869 | return; |
1953 | else | 1870 | } |
1954 | goto fail; | 1871 | handle_gns_cname_result(rh, |
1955 | } | 1872 | cname); |
1956 | default: | 1873 | GNUNET_free(cname); |
1957 | break; | 1874 | return; |
1958 | } /* end: switch */ | ||
1959 | } /* end: for rd */ | ||
1960 | } /* end: name_resolution_pos */ | ||
1961 | /* convert relative names in record values to absolute names, | ||
1962 | using 'scratch' array for memory allocations */ | ||
1963 | scratch_off = 0; | ||
1964 | rd_off = 0; | ||
1965 | for (unsigned int i=0;i<rd_count;i++) | ||
1966 | { | ||
1967 | GNUNET_assert (rd_off <= i); | ||
1968 | if ( (0 != rh->protocol) && | ||
1969 | (0 != rh->service) && | ||
1970 | (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type) ) | ||
1971 | continue; /* we _only_ care about boxed records */ | ||
1972 | |||
1973 | GNUNET_assert (rd_off < rd_count); | ||
1974 | rd_new[rd_off] = rd[i]; | ||
1975 | /* Check if the embedded name(s) end in "+", and if so, | ||
1976 | replace the "+" with the zone at "ac_tail", changing the name | ||
1977 | to a ".ZONEKEY". The name is allocated on the 'scratch' array, | ||
1978 | so we can free it afterwards. */ | ||
1979 | switch (rd[i].record_type) | ||
1980 | { | ||
1981 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1982 | { | ||
1983 | char *cname; | ||
1984 | |||
1985 | off = 0; | ||
1986 | cname = GNUNET_DNSPARSER_parse_name (rd[i].data, | ||
1987 | rd[i].data_size, | ||
1988 | &off); | ||
1989 | if ( (NULL == cname) || | ||
1990 | (off != rd[i].data_size) ) | ||
1991 | { | ||
1992 | GNUNET_break_op (0); /* record not well-formed */ | ||
1993 | } | ||
1994 | else | ||
1995 | { | ||
1996 | cname = translate_dot_plus (rh, cname); | ||
1997 | GNUNET_break (NULL != cname); | ||
1998 | scratch_start = scratch_off; | ||
1999 | if (GNUNET_OK != | ||
2000 | GNUNET_DNSPARSER_builder_add_name (scratch, | ||
2001 | sizeof (scratch), | ||
2002 | &scratch_off, | ||
2003 | cname)) | ||
2004 | { | ||
2005 | GNUNET_break (0); | ||
2006 | } | ||
2007 | else | ||
2008 | { | ||
2009 | GNUNET_assert (rd_off < rd_count); | ||
2010 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2011 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2012 | rd_off++; | ||
2013 | } | ||
2014 | } | ||
2015 | GNUNET_free_non_null (cname); | ||
2016 | } | ||
2017 | break; | ||
2018 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
2019 | { | ||
2020 | struct GNUNET_DNSPARSER_SoaRecord *soa; | ||
2021 | |||
2022 | off = 0; | ||
2023 | soa = GNUNET_DNSPARSER_parse_soa (rd[i].data, | ||
2024 | rd[i].data_size, | ||
2025 | &off); | ||
2026 | if ( (NULL == soa) || | ||
2027 | (off != rd[i].data_size) ) | ||
2028 | { | ||
2029 | GNUNET_break_op (0); /* record not well-formed */ | ||
2030 | } | ||
2031 | else | ||
2032 | { | ||
2033 | soa->mname = translate_dot_plus (rh, soa->mname); | ||
2034 | soa->rname = translate_dot_plus (rh, soa->rname); | ||
2035 | scratch_start = scratch_off; | ||
2036 | if (GNUNET_OK != | ||
2037 | GNUNET_DNSPARSER_builder_add_soa (scratch, | ||
2038 | sizeof (scratch), | ||
2039 | &scratch_off, | ||
2040 | soa)) | ||
2041 | { | ||
2042 | 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 | } | ||
2055 | break; | ||
2056 | case GNUNET_DNSPARSER_TYPE_MX: | ||
2057 | { | ||
2058 | struct GNUNET_DNSPARSER_MxRecord *mx; | ||
2059 | |||
2060 | off = 0; | ||
2061 | mx = GNUNET_DNSPARSER_parse_mx (rd[i].data, | ||
2062 | rd[i].data_size, | ||
2063 | &off); | ||
2064 | if ( (NULL == mx) || | ||
2065 | (off != rd[i].data_size) ) | ||
2066 | { | ||
2067 | GNUNET_break_op (0); /* record not well-formed */ | ||
2068 | } | ||
2069 | else | ||
2070 | { | ||
2071 | mx->mxhost = translate_dot_plus (rh, mx->mxhost); | ||
2072 | scratch_start = scratch_off; | ||
2073 | if (GNUNET_OK != | ||
2074 | GNUNET_DNSPARSER_builder_add_mx (scratch, | ||
2075 | sizeof (scratch), | ||
2076 | &scratch_off, | ||
2077 | mx)) | ||
2078 | { | ||
2079 | GNUNET_break (0); | ||
2080 | } | ||
2081 | else | ||
2082 | { | ||
2083 | GNUNET_assert (rd_off < rd_count); | ||
2084 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2085 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2086 | rd_off++; | ||
2087 | } | ||
2088 | } | ||
2089 | if (NULL != mx) | ||
2090 | GNUNET_DNSPARSER_free_mx (mx); | ||
2091 | } | ||
2092 | break; | ||
2093 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
2094 | { | ||
2095 | struct GNUNET_DNSPARSER_SrvRecord *srv; | ||
2096 | |||
2097 | off = 0; | ||
2098 | srv = GNUNET_DNSPARSER_parse_srv (rd[i].data, | ||
2099 | rd[i].data_size, | ||
2100 | &off); | ||
2101 | if ( (NULL == srv) || | ||
2102 | (off != rd[i].data_size) ) | ||
2103 | { | ||
2104 | GNUNET_break_op (0); /* record not well-formed */ | ||
2105 | } | ||
2106 | else | ||
2107 | { | ||
2108 | srv->target = translate_dot_plus (rh, srv->target); | ||
2109 | scratch_start = scratch_off; | ||
2110 | if (GNUNET_OK != | ||
2111 | GNUNET_DNSPARSER_builder_add_srv (scratch, | ||
2112 | sizeof (scratch), | ||
2113 | &scratch_off, | ||
2114 | srv)) | ||
2115 | { | ||
2116 | GNUNET_break (0); | ||
2117 | } | ||
2118 | else | ||
2119 | { | ||
2120 | GNUNET_assert (rd_off < rd_count); | ||
2121 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2122 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2123 | rd_off++; | ||
2124 | } | ||
2125 | } | ||
2126 | if (NULL != srv) | ||
2127 | GNUNET_DNSPARSER_free_srv (srv); | ||
2128 | } | ||
2129 | break; | ||
2130 | |||
2131 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
2132 | { | ||
2133 | const char *nick; | ||
2134 | |||
2135 | nick = rd[i].data; | ||
2136 | if ((rd[i].data_size > 0) && | ||
2137 | (nick[rd[i].data_size -1] != '\0')) | ||
2138 | { | ||
2139 | GNUNET_break_op (0); | ||
2140 | break; | ||
2141 | } | ||
2142 | break; | ||
2143 | } | ||
2144 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
2145 | { | ||
2146 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
2147 | |||
2148 | if (rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) | ||
2149 | { | ||
2150 | GNUNET_break_op (0); | ||
2151 | break; | ||
2152 | } | ||
2153 | GNUNET_memcpy (&pub, | ||
2154 | rd[i].data, | ||
2155 | rd[i].data_size); | ||
2156 | rd_off++; | ||
2157 | if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type) | ||
2158 | { | ||
2159 | /* try to resolve "@" */ | ||
2160 | struct AuthorityChain *ac; | ||
2161 | |||
2162 | ac = GNUNET_new (struct AuthorityChain); | ||
2163 | ac->rh = rh; | ||
2164 | ac->gns_authority = GNUNET_YES; | ||
2165 | ac->authority_info.gns_authority = pub; | ||
2166 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); | ||
2167 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | ||
2168 | rh->ac_tail, | ||
2169 | ac); | ||
2170 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | ||
2171 | rh); | ||
2172 | return; | ||
2173 | } | ||
2174 | } | 1875 | } |
2175 | break; | 1876 | /* If A/AAAA was requested, but we got a VPN |
2176 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | 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)) | ||
2177 | { | 1880 | { |
2178 | /* delegation to DNS */ | 1881 | for (unsigned int i = 0; i < rd_count; i++) |
2179 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type) | 1882 | { |
2180 | { | 1883 | switch (rd[i].record_type) |
2181 | rd_off++; | 1884 | { |
2182 | break; /* do not follow to DNS, we wanted the GNS2DNS record! */ | 1885 | case GNUNET_GNSRECORD_TYPE_VPN: |
2183 | } | 1886 | { |
2184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1887 | af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6; |
2185 | "Found GNS2DNS record, delegating to DNS!\n"); | 1888 | if (sizeof(struct GNUNET_TUN_GnsVpnRecord) > |
2186 | if (GNUNET_OK == | 1889 | rd[i].data_size) |
2187 | recursive_gns2dns_resolution (rh, | 1890 | { |
2188 | rd_count, | 1891 | GNUNET_break_op(0); |
2189 | rd)) | 1892 | fail_resolution(rh); |
2190 | return; | 1893 | return; |
2191 | else | 1894 | } |
2192 | goto fail; | 1895 | vpn = (const struct GNUNET_TUN_GnsVpnRecord *)rd[i].data; |
2193 | } | 1896 | vname = (const char *)&vpn[1]; |
2194 | case GNUNET_GNSRECORD_TYPE_BOX: | 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++) | ||
2195 | { | 1965 | { |
2196 | /* unbox SRV/TLSA records if a specific one was requested */ | 1966 | GNUNET_assert(rd_off <= i); |
2197 | if ( (0 != rh->protocol) && | 1967 | if ((0 != rh->protocol) && |
2198 | (0 != rh->service) && | 1968 | (0 != rh->service) && |
2199 | (rd[i].data_size >= sizeof (struct GNUNET_GNSRECORD_BoxRecord)) ) | 1969 | (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type)) |
2200 | { | 1970 | continue; /* we _only_ care about boxed records */ |
2201 | const struct GNUNET_GNSRECORD_BoxRecord *box; | 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 | { | ||
1980 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1981 | { | ||
1982 | char *cname; | ||
1983 | |||
1984 | off = 0; | ||
1985 | cname = GNUNET_DNSPARSER_parse_name(rd[i].data, | ||
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 | } | ||
2016 | break; | ||
2017 | |||
2018 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
2019 | { | ||
2020 | struct GNUNET_DNSPARSER_SoaRecord *soa; | ||
2021 | |||
2022 | off = 0; | ||
2023 | soa = GNUNET_DNSPARSER_parse_soa(rd[i].data, | ||
2024 | rd[i].data_size, | ||
2025 | &off); | ||
2026 | if ((NULL == soa) || | ||
2027 | (off != rd[i].data_size)) | ||
2028 | { | ||
2029 | GNUNET_break_op(0); /* record not well-formed */ | ||
2030 | } | ||
2031 | else | ||
2032 | { | ||
2033 | soa->mname = translate_dot_plus(rh, soa->mname); | ||
2034 | soa->rname = translate_dot_plus(rh, soa->rname); | ||
2035 | scratch_start = scratch_off; | ||
2036 | if (GNUNET_OK != | ||
2037 | GNUNET_DNSPARSER_builder_add_soa(scratch, | ||
2038 | sizeof(scratch), | ||
2039 | &scratch_off, | ||
2040 | soa)) | ||
2041 | { | ||
2042 | 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 | } | ||
2055 | break; | ||
2056 | |||
2057 | case GNUNET_DNSPARSER_TYPE_MX: | ||
2058 | { | ||
2059 | struct GNUNET_DNSPARSER_MxRecord *mx; | ||
2060 | |||
2061 | off = 0; | ||
2062 | mx = GNUNET_DNSPARSER_parse_mx(rd[i].data, | ||
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 | } | ||
2093 | break; | ||
2094 | |||
2095 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
2096 | { | ||
2097 | struct GNUNET_DNSPARSER_SrvRecord *srv; | ||
2098 | |||
2099 | off = 0; | ||
2100 | srv = GNUNET_DNSPARSER_parse_srv(rd[i].data, | ||
2101 | rd[i].data_size, | ||
2102 | &off); | ||
2103 | if ((NULL == srv) || | ||
2104 | (off != rd[i].data_size)) | ||
2105 | { | ||
2106 | GNUNET_break_op(0); /* record not well-formed */ | ||
2107 | } | ||
2108 | else | ||
2109 | { | ||
2110 | srv->target = translate_dot_plus(rh, srv->target); | ||
2111 | scratch_start = scratch_off; | ||
2112 | if (GNUNET_OK != | ||
2113 | GNUNET_DNSPARSER_builder_add_srv(scratch, | ||
2114 | sizeof(scratch), | ||
2115 | &scratch_off, | ||
2116 | srv)) | ||
2117 | { | ||
2118 | GNUNET_break(0); | ||
2119 | } | ||
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 | } | ||
2131 | break; | ||
2132 | |||
2133 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
2134 | { | ||
2135 | const char *nick; | ||
2136 | |||
2137 | nick = rd[i].data; | ||
2138 | if ((rd[i].data_size > 0) && | ||
2139 | (nick[rd[i].data_size - 1] != '\0')) | ||
2140 | { | ||
2141 | GNUNET_break_op(0); | ||
2142 | break; | ||
2143 | } | ||
2144 | break; | ||
2145 | } | ||
2202 | 2146 | ||
2203 | box = rd[i].data; | 2147 | case GNUNET_GNSRECORD_TYPE_PKEY: |
2204 | if ( (ntohs (box->protocol) == rh->protocol) && | ||
2205 | (ntohs (box->service) == rh->service) ) | ||
2206 | { | 2148 | { |
2207 | /* Box matches, unbox! */ | 2149 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
2208 | GNUNET_assert (rd_off < rd_count); | 2150 | |
2209 | rd_new[rd_off].record_type = ntohl (box->record_type); | 2151 | if (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) |
2210 | rd_new[rd_off].data_size -= sizeof (struct GNUNET_GNSRECORD_BoxRecord); | 2152 | { |
2211 | rd_new[rd_off].data = &box[1]; | 2153 | GNUNET_break_op(0); |
2154 | break; | ||
2155 | } | ||
2156 | GNUNET_memcpy(&pub, | ||
2157 | rd[i].data, | ||
2158 | rd[i].data_size); | ||
2212 | rd_off++; | 2159 | 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 | } | ||
2213 | } | 2177 | } |
2214 | } | 2178 | break; |
2215 | else | 2179 | |
2216 | { | 2180 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: |
2217 | /* no specific protocol/service specified, preserve all BOX | 2181 | { |
2218 | records (for modern, GNS-enabled applications) */ | 2182 | /* delegation to DNS */ |
2219 | rd_off++; | 2183 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type) |
2220 | } | 2184 | { |
2221 | break; | 2185 | rd_off++; |
2222 | } | 2186 | break; /* do not follow to DNS, we wanted the GNS2DNS record! */ |
2223 | default: | 2187 | } |
2224 | rd_off++; | 2188 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2225 | break; | 2189 | "Found GNS2DNS record, delegating to DNS!\n"); |
2226 | } /* end: switch */ | 2190 | if (GNUNET_OK == |
2227 | } /* end: for rd_count */ | 2191 | recursive_gns2dns_resolution(rh, |
2228 | 2192 | rd_count, | |
2229 | /* yes, we are done, return result */ | 2193 | rd)) |
2230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2194 | return; |
2231 | "Returning GNS response for `%s' with %u answers\n", | 2195 | else |
2232 | rh->ac_tail->label, | 2196 | goto fail; |
2233 | rd_off); | 2197 | } |
2234 | rh->proc (rh->proc_cls, | 2198 | |
2235 | rd_off, | 2199 | case GNUNET_GNSRECORD_TYPE_BOX: |
2236 | rd_new); | 2200 | { |
2237 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 2201 | /* unbox SRV/TLSA records if a specific one was requested */ |
2238 | rh); | 2202 | if ((0 != rh->protocol) && |
2239 | return; | 2203 | (0 != rh->service) && |
2240 | } | 2204 | (rd[i].data_size >= sizeof(struct GNUNET_GNSRECORD_BoxRecord))) |
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 | } | ||
2228 | |||
2229 | default: | ||
2230 | rd_off++; | ||
2231 | break; | ||
2232 | } /* end: switch */ | ||
2233 | } /* end: for rd_count */ | ||
2234 | |||
2235 | /* yes, we are done, return result */ | ||
2236 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2237 | "Returning GNS response for `%s' with %u answers\n", | ||
2238 | rh->ac_tail->label, | ||
2239 | rd_off); | ||
2240 | rh->proc(rh->proc_cls, | ||
2241 | rd_off, | ||
2242 | rd_new); | ||
2243 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, | ||
2244 | rh); | ||
2245 | return; | ||
2246 | } | ||
2241 | 2247 | ||
2242 | switch (rd[0].record_type) | 2248 | switch (rd[0].record_type) |
2243 | { | 2249 | { |
2244 | case GNUNET_DNSPARSER_TYPE_CNAME: | 2250 | case GNUNET_DNSPARSER_TYPE_CNAME: |
2245 | GNUNET_break_op (1 == rd_count); /* CNAME should be unique */ | 2251 | GNUNET_break_op(1 == rd_count); /* CNAME should be unique */ |
2246 | recursive_cname_resolution (rh, | 2252 | recursive_cname_resolution(rh, |
2253 | &rd[0]); | ||
2254 | return; | ||
2255 | |||
2256 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
2257 | GNUNET_break_op(1 == rd_count); /* PKEY should be unique */ | ||
2258 | recursive_pkey_resolution(rh, | ||
2247 | &rd[0]); | 2259 | &rd[0]); |
2248 | return; | ||
2249 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
2250 | GNUNET_break_op (1 == rd_count); /* PKEY should be unique */ | ||
2251 | recursive_pkey_resolution (rh, | ||
2252 | &rd[0]); | ||
2253 | return; | ||
2254 | default: | ||
2255 | if (GNUNET_OK == | ||
2256 | recursive_gns2dns_resolution (rh, | ||
2257 | rd_count, | ||
2258 | rd)) | ||
2259 | return; | 2260 | return; |
2260 | break; | 2261 | |
2261 | } | 2262 | default: |
2262 | fail: | 2263 | if (GNUNET_OK == |
2263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2264 | recursive_gns2dns_resolution(rh, |
2264 | _("GNS lookup recursion failed (no delegation record found)\n")); | 2265 | rd_count, |
2265 | fail_resolution (rh); | 2266 | rd)) |
2267 | return; | ||
2268 | break; | ||
2269 | } | ||
2270 | fail: | ||
2271 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2272 | _("GNS lookup recursion failed (no delegation record found)\n")); | ||
2273 | fail_resolution(rh); | ||
2266 | } | 2274 | } |
2267 | 2275 | ||
2268 | 2276 | ||
@@ -2275,21 +2283,21 @@ handle_gns_resolution_result (void *cls, | |||
2275 | * @param emsg error message | 2283 | * @param emsg error message |
2276 | */ | 2284 | */ |
2277 | static void | 2285 | static void |
2278 | namecache_cache_continuation (void *cls, | 2286 | namecache_cache_continuation(void *cls, |
2279 | int32_t success, | 2287 | int32_t success, |
2280 | const char *emsg) | 2288 | const char *emsg) |
2281 | { | 2289 | { |
2282 | struct CacheOps *co = cls; | 2290 | struct CacheOps *co = cls; |
2283 | 2291 | ||
2284 | co->namecache_qe_cache = NULL; | 2292 | co->namecache_qe_cache = NULL; |
2285 | if (GNUNET_OK != success) | 2293 | if (GNUNET_OK != success) |
2286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2294 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2287 | _("Failed to cache GNS resolution: %s\n"), | 2295 | _("Failed to cache GNS resolution: %s\n"), |
2288 | emsg); | 2296 | emsg); |
2289 | GNUNET_CONTAINER_DLL_remove (co_head, | 2297 | GNUNET_CONTAINER_DLL_remove(co_head, |
2290 | co_tail, | 2298 | co_tail, |
2291 | co); | 2299 | co); |
2292 | GNUNET_free (co); | 2300 | GNUNET_free(co); |
2293 | } | 2301 | } |
2294 | 2302 | ||
2295 | 2303 | ||
@@ -2311,88 +2319,88 @@ namecache_cache_continuation (void *cls, | |||
2311 | * @param data pointer to the result data | 2319 | * @param data pointer to the result data |
2312 | */ | 2320 | */ |
2313 | static void | 2321 | static void |
2314 | handle_dht_response (void *cls, | 2322 | handle_dht_response(void *cls, |
2315 | struct GNUNET_TIME_Absolute exp, | 2323 | struct GNUNET_TIME_Absolute exp, |
2316 | const struct GNUNET_HashCode *key, | 2324 | const struct GNUNET_HashCode *key, |
2317 | const struct GNUNET_PeerIdentity *get_path, | 2325 | const struct GNUNET_PeerIdentity *get_path, |
2318 | unsigned int get_path_length, | 2326 | unsigned int get_path_length, |
2319 | const struct GNUNET_PeerIdentity *put_path, | 2327 | const struct GNUNET_PeerIdentity *put_path, |
2320 | unsigned int put_path_length, | 2328 | unsigned int put_path_length, |
2321 | enum GNUNET_BLOCK_Type type, | 2329 | enum GNUNET_BLOCK_Type type, |
2322 | size_t size, | 2330 | size_t size, |
2323 | const void *data) | 2331 | const void *data) |
2324 | { | 2332 | { |
2325 | struct GNS_ResolverHandle *rh = cls; | 2333 | struct GNS_ResolverHandle *rh = cls; |
2326 | struct AuthorityChain *ac = rh->ac_tail; | 2334 | struct AuthorityChain *ac = rh->ac_tail; |
2327 | const struct GNUNET_GNSRECORD_Block *block; | 2335 | const struct GNUNET_GNSRECORD_Block *block; |
2328 | struct CacheOps *co; | 2336 | struct CacheOps *co; |
2329 | 2337 | ||
2330 | (void) exp; | 2338 | (void)exp; |
2331 | (void) key; | 2339 | (void)key; |
2332 | (void) get_path; | 2340 | (void)get_path; |
2333 | (void) get_path_length; | 2341 | (void)get_path_length; |
2334 | (void) put_path; | 2342 | (void)put_path; |
2335 | (void) put_path_length; | 2343 | (void)put_path_length; |
2336 | (void) type; | 2344 | (void)type; |
2337 | GNUNET_DHT_get_stop (rh->get_handle); | 2345 | GNUNET_DHT_get_stop(rh->get_handle); |
2338 | rh->get_handle = NULL; | 2346 | rh->get_handle = NULL; |
2339 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); | 2347 | GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); |
2340 | rh->dht_heap_node = NULL; | 2348 | rh->dht_heap_node = NULL; |
2341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2349 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2342 | "Handling response from the DHT\n"); | 2350 | "Handling response from the DHT\n"); |
2343 | if (size < sizeof (struct GNUNET_GNSRECORD_Block)) | 2351 | if (size < sizeof(struct GNUNET_GNSRECORD_Block)) |
2344 | { | 2352 | { |
2345 | /* how did this pass DHT block validation!? */ | 2353 | /* how did this pass DHT block validation!? */ |
2346 | GNUNET_break (0); | 2354 | GNUNET_break(0); |
2347 | fail_resolution (rh); | 2355 | fail_resolution(rh); |
2348 | return; | 2356 | return; |
2349 | } | 2357 | } |
2350 | block = data; | 2358 | block = data; |
2351 | if (size != | 2359 | if (size != |
2352 | ntohl (block->purpose.size) + | 2360 | ntohl(block->purpose.size) + |
2353 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | 2361 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + |
2354 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)) | 2362 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) |
2355 | { | 2363 | { |
2356 | /* how did this pass DHT block validation!? */ | 2364 | /* how did this pass DHT block validation!? */ |
2357 | GNUNET_break (0); | 2365 | GNUNET_break(0); |
2358 | fail_resolution (rh); | 2366 | fail_resolution(rh); |
2359 | return; | 2367 | return; |
2360 | } | 2368 | } |
2361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2369 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2362 | "Decrypting DHT block of size %u for `%s', expires %s\n", | 2370 | "Decrypting DHT block of size %u for `%s', expires %s\n", |
2363 | ntohl (block->purpose.size), | 2371 | ntohl(block->purpose.size), |
2364 | rh->name, | 2372 | rh->name, |
2365 | GNUNET_STRINGS_absolute_time_to_string (exp)); | 2373 | GNUNET_STRINGS_absolute_time_to_string(exp)); |
2366 | if (GNUNET_OK != | 2374 | if (GNUNET_OK != |
2367 | GNUNET_GNSRECORD_block_decrypt (block, | 2375 | GNUNET_GNSRECORD_block_decrypt(block, |
2368 | &ac->authority_info.gns_authority, | 2376 | &ac->authority_info.gns_authority, |
2369 | ac->label, | 2377 | ac->label, |
2370 | &handle_gns_resolution_result, | 2378 | &handle_gns_resolution_result, |
2371 | rh)) | 2379 | rh)) |
2372 | { | 2380 | { |
2373 | GNUNET_break_op (0); /* block was ill-formed */ | 2381 | GNUNET_break_op(0); /* block was ill-formed */ |
2374 | fail_resolution (rh); | 2382 | fail_resolution(rh); |
2375 | return; | 2383 | return; |
2376 | } | 2384 | } |
2377 | if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) | 2385 | if (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us) |
2378 | { | 2386 | { |
2379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2380 | "Received expired block from the DHT, will not cache it.\n"); | 2388 | "Received expired block from the DHT, will not cache it.\n"); |
2381 | return; | 2389 | return; |
2382 | } | 2390 | } |
2383 | if (GNUNET_YES == disable_cache) | 2391 | if (GNUNET_YES == disable_cache) |
2384 | return; | 2392 | return; |
2385 | /* Cache well-formed blocks */ | 2393 | /* Cache well-formed blocks */ |
2386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2394 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2387 | "Caching response from the DHT in namecache\n"); | 2395 | "Caching response from the DHT in namecache\n"); |
2388 | co = GNUNET_new (struct CacheOps); | 2396 | co = GNUNET_new(struct CacheOps); |
2389 | co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache (namecache_handle, | 2397 | co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache(namecache_handle, |
2390 | block, | 2398 | block, |
2391 | &namecache_cache_continuation, | 2399 | &namecache_cache_continuation, |
2392 | co); | 2400 | co); |
2393 | GNUNET_CONTAINER_DLL_insert (co_head, | 2401 | GNUNET_CONTAINER_DLL_insert(co_head, |
2394 | co_tail, | 2402 | co_tail, |
2395 | co); | 2403 | co); |
2396 | } | 2404 | } |
2397 | 2405 | ||
2398 | 2406 | ||
@@ -2403,30 +2411,30 @@ handle_dht_response (void *cls, | |||
2403 | * @param query key to use in the DHT lookup | 2411 | * @param query key to use in the DHT lookup |
2404 | */ | 2412 | */ |
2405 | static void | 2413 | static void |
2406 | start_dht_request (struct GNS_ResolverHandle *rh, | 2414 | start_dht_request(struct GNS_ResolverHandle *rh, |
2407 | const struct GNUNET_HashCode *query) | 2415 | const struct GNUNET_HashCode *query) |
2408 | { | 2416 | { |
2409 | struct GNS_ResolverHandle *rx; | 2417 | struct GNS_ResolverHandle *rx; |
2410 | 2418 | ||
2411 | GNUNET_assert (NULL == rh->get_handle); | 2419 | GNUNET_assert(NULL == rh->get_handle); |
2412 | rh->get_handle = GNUNET_DHT_get_start (dht_handle, | 2420 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
2413 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 2421 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
2414 | query, | 2422 | query, |
2415 | DHT_GNS_REPLICATION_LEVEL, | 2423 | DHT_GNS_REPLICATION_LEVEL, |
2416 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 2424 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
2417 | NULL, 0, | 2425 | NULL, 0, |
2418 | &handle_dht_response, rh); | 2426 | &handle_dht_response, rh); |
2419 | rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap, | 2427 | rh->dht_heap_node = GNUNET_CONTAINER_heap_insert(dht_lookup_heap, |
2420 | rh, | 2428 | rh, |
2421 | GNUNET_TIME_absolute_get ().abs_value_us); | 2429 | GNUNET_TIME_absolute_get().abs_value_us); |
2422 | if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) | 2430 | if (GNUNET_CONTAINER_heap_get_size(dht_lookup_heap) > max_allowed_background_queries) |
2423 | { | 2431 | { |
2424 | /* fail longest-standing DHT request */ | 2432 | /* fail longest-standing DHT request */ |
2425 | rx = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); | 2433 | rx = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap); |
2426 | rx->dht_heap_node = NULL; | 2434 | rx->dht_heap_node = NULL; |
2427 | GNUNET_assert (NULL != rx); | 2435 | GNUNET_assert(NULL != rx); |
2428 | fail_resolution (rx); | 2436 | fail_resolution(rx); |
2429 | } | 2437 | } |
2430 | } | 2438 | } |
2431 | 2439 | ||
2432 | 2440 | ||
@@ -2439,19 +2447,19 @@ start_dht_request (struct GNS_ResolverHandle *rh, | |||
2439 | * @param rd array of records with data to store | 2447 | * @param rd array of records with data to store |
2440 | */ | 2448 | */ |
2441 | static void | 2449 | static void |
2442 | handle_gns_namecache_resolution_result (void *cls, | 2450 | handle_gns_namecache_resolution_result(void *cls, |
2443 | unsigned int rd_count, | 2451 | unsigned int rd_count, |
2444 | const struct GNUNET_GNSRECORD_Data *rd) | 2452 | const struct GNUNET_GNSRECORD_Data *rd) |
2445 | { | 2453 | { |
2446 | struct GNS_ResolverHandle *rh = cls; | 2454 | struct GNS_ResolverHandle *rh = cls; |
2447 | 2455 | ||
2448 | if (0 == rd_count) | 2456 | if (0 == rd_count) |
2449 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2457 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2450 | _("GNS namecache returned empty result for `%s'\n"), | 2458 | _("GNS namecache returned empty result for `%s'\n"), |
2451 | rh->name); | 2459 | rh->name); |
2452 | handle_gns_resolution_result (rh, | 2460 | handle_gns_resolution_result(rh, |
2453 | rd_count, | 2461 | rd_count, |
2454 | rd); | 2462 | rd); |
2455 | } | 2463 | } |
2456 | 2464 | ||
2457 | 2465 | ||
@@ -2462,8 +2470,8 @@ handle_gns_namecache_resolution_result (void *cls, | |||
2462 | * @param block block that was stored in the namecache | 2470 | * @param block block that was stored in the namecache |
2463 | */ | 2471 | */ |
2464 | static void | 2472 | static void |
2465 | handle_namecache_block_response (void *cls, | 2473 | handle_namecache_block_response(void *cls, |
2466 | const struct GNUNET_GNSRECORD_Block *block) | 2474 | const struct GNUNET_GNSRECORD_Block *block) |
2467 | { | 2475 | { |
2468 | struct GNS_ResolverHandle *rh = cls; | 2476 | struct GNS_ResolverHandle *rh = cls; |
2469 | struct AuthorityChain *ac = rh->ac_tail; | 2477 | struct AuthorityChain *ac = rh->ac_tail; |
@@ -2471,62 +2479,62 @@ handle_namecache_block_response (void *cls, | |||
2471 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; | 2479 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; |
2472 | struct GNUNET_HashCode query; | 2480 | struct GNUNET_HashCode query; |
2473 | 2481 | ||
2474 | GNUNET_assert (NULL != rh->namecache_qe); | 2482 | GNUNET_assert(NULL != rh->namecache_qe); |
2475 | rh->namecache_qe = NULL; | 2483 | rh->namecache_qe = NULL; |
2476 | if ( ( (GNUNET_GNS_LO_DEFAULT == rh->options) || | 2484 | if (((GNUNET_GNS_LO_DEFAULT == rh->options) || |
2477 | ( (GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && | 2485 | ((GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && |
2478 | (ac != rh->ac_head) ) ) && | 2486 | (ac != rh->ac_head))) && |
2479 | ( (NULL == block) || | 2487 | ((NULL == block) || |
2480 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) ) | 2488 | (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us))) |
2481 | { | 2489 | { |
2482 | /* namecache knows nothing; try DHT lookup */ | 2490 | /* namecache knows nothing; try DHT lookup */ |
2483 | GNUNET_GNSRECORD_query_from_public_key (auth, | 2491 | GNUNET_GNSRECORD_query_from_public_key(auth, |
2484 | label, | 2492 | label, |
2485 | &query); | 2493 | &query); |
2486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2494 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2487 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", | 2495 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", |
2488 | ac->label, | 2496 | ac->label, |
2489 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority), | 2497 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority), |
2490 | GNUNET_h2s (&query)); | 2498 | GNUNET_h2s(&query)); |
2491 | start_dht_request (rh, &query); | 2499 | start_dht_request(rh, &query); |
2492 | return; | 2500 | return; |
2493 | } | 2501 | } |
2494 | 2502 | ||
2495 | if ( (NULL == block) || | 2503 | if ((NULL == block) || |
2496 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) | 2504 | (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us)) |
2497 | { | 2505 | { |
2498 | /* DHT not permitted and no local result, fail */ | 2506 | /* DHT not permitted and no local result, fail */ |
2499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2507 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2500 | "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n", | 2508 | "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n", |
2501 | ac->label, | 2509 | ac->label, |
2502 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2510 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2503 | fail_resolution (rh); | 2511 | fail_resolution(rh); |
2504 | return; | 2512 | return; |
2505 | } | 2513 | } |
2506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2514 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2507 | "Received result from namecache for label `%s'\n", | 2515 | "Received result from namecache for label `%s'\n", |
2508 | ac->label); | 2516 | ac->label); |
2509 | 2517 | ||
2510 | if (GNUNET_OK != | 2518 | if (GNUNET_OK != |
2511 | GNUNET_GNSRECORD_block_decrypt (block, | 2519 | GNUNET_GNSRECORD_block_decrypt(block, |
2512 | auth, | 2520 | auth, |
2513 | label, | 2521 | label, |
2514 | &handle_gns_namecache_resolution_result, | 2522 | &handle_gns_namecache_resolution_result, |
2515 | rh)) | 2523 | rh)) |
2516 | { | 2524 | { |
2517 | GNUNET_break_op (0); /* block was ill-formed */ | 2525 | GNUNET_break_op(0); /* block was ill-formed */ |
2518 | /* try DHT instead */ | 2526 | /* try DHT instead */ |
2519 | GNUNET_GNSRECORD_query_from_public_key (auth, | 2527 | GNUNET_GNSRECORD_query_from_public_key(auth, |
2520 | label, | 2528 | label, |
2521 | &query); | 2529 | &query); |
2522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2530 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2523 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", | 2531 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", |
2524 | ac->label, | 2532 | ac->label, |
2525 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority), | 2533 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority), |
2526 | GNUNET_h2s (&query)); | 2534 | GNUNET_h2s(&query)); |
2527 | start_dht_request (rh, &query); | 2535 | start_dht_request(rh, &query); |
2528 | return; | 2536 | return; |
2529 | } | 2537 | } |
2530 | } | 2538 | } |
2531 | 2539 | ||
2532 | 2540 | ||
@@ -2536,32 +2544,32 @@ handle_namecache_block_response (void *cls, | |||
2536 | * @param rh query we are processing | 2544 | * @param rh query we are processing |
2537 | */ | 2545 | */ |
2538 | static void | 2546 | static void |
2539 | recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh) | 2547 | recursive_gns_resolution_namecache(struct GNS_ResolverHandle *rh) |
2540 | { | 2548 | { |
2541 | struct AuthorityChain *ac = rh->ac_tail; | 2549 | struct AuthorityChain *ac = rh->ac_tail; |
2542 | struct GNUNET_HashCode query; | 2550 | struct GNUNET_HashCode query; |
2543 | 2551 | ||
2544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2552 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2545 | "Starting GNS resolution for `%s' in zone %s\n", | 2553 | "Starting GNS resolution for `%s' in zone %s\n", |
2546 | ac->label, | 2554 | ac->label, |
2547 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2555 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2548 | GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority, | 2556 | GNUNET_GNSRECORD_query_from_public_key(&ac->authority_info.gns_authority, |
2549 | ac->label, | 2557 | ac->label, |
2550 | &query); | 2558 | &query); |
2551 | if (GNUNET_YES != disable_cache) | 2559 | if (GNUNET_YES != disable_cache) |
2552 | { | 2560 | { |
2553 | rh->namecache_qe | 2561 | rh->namecache_qe |
2554 | = GNUNET_NAMECACHE_lookup_block (namecache_handle, | 2562 | = GNUNET_NAMECACHE_lookup_block(namecache_handle, |
2555 | &query, | 2563 | &query, |
2556 | &handle_namecache_block_response, | 2564 | &handle_namecache_block_response, |
2557 | rh); | 2565 | rh); |
2558 | GNUNET_assert (NULL != rh->namecache_qe); | 2566 | GNUNET_assert(NULL != rh->namecache_qe); |
2559 | } | 2567 | } |
2560 | else | 2568 | else |
2561 | { | 2569 | { |
2562 | start_dht_request (rh, | 2570 | start_dht_request(rh, |
2563 | &query); | 2571 | &query); |
2564 | } | 2572 | } |
2565 | } | 2573 | } |
2566 | 2574 | ||
2567 | 2575 | ||
@@ -2572,22 +2580,22 @@ recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh) | |||
2572 | * @param is_valid #GNUNET_YES if the zone was not yet revoked | 2580 | * @param is_valid #GNUNET_YES if the zone was not yet revoked |
2573 | */ | 2581 | */ |
2574 | static void | 2582 | static void |
2575 | handle_revocation_result (void *cls, | 2583 | handle_revocation_result(void *cls, |
2576 | int is_valid) | 2584 | int is_valid) |
2577 | { | 2585 | { |
2578 | struct GNS_ResolverHandle *rh = cls; | 2586 | struct GNS_ResolverHandle *rh = cls; |
2579 | struct AuthorityChain *ac = rh->ac_tail; | 2587 | struct AuthorityChain *ac = rh->ac_tail; |
2580 | 2588 | ||
2581 | rh->rev_check = NULL; | 2589 | rh->rev_check = NULL; |
2582 | if (GNUNET_YES != is_valid) | 2590 | if (GNUNET_YES != is_valid) |
2583 | { | 2591 | { |
2584 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2592 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2585 | _("Zone %s was revoked, resolution fails\n"), | 2593 | _("Zone %s was revoked, resolution fails\n"), |
2586 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2594 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2587 | fail_resolution (rh); | 2595 | fail_resolution(rh); |
2588 | return; | 2596 | return; |
2589 | } | 2597 | } |
2590 | recursive_gns_resolution_namecache (rh); | 2598 | recursive_gns_resolution_namecache(rh); |
2591 | } | 2599 | } |
2592 | 2600 | ||
2593 | 2601 | ||
@@ -2597,18 +2605,18 @@ handle_revocation_result (void *cls, | |||
2597 | * @param rh query we are processing | 2605 | * @param rh query we are processing |
2598 | */ | 2606 | */ |
2599 | static void | 2607 | static void |
2600 | recursive_gns_resolution_revocation (struct GNS_ResolverHandle *rh) | 2608 | recursive_gns_resolution_revocation(struct GNS_ResolverHandle *rh) |
2601 | { | 2609 | { |
2602 | struct AuthorityChain *ac = rh->ac_tail; | 2610 | struct AuthorityChain *ac = rh->ac_tail; |
2603 | 2611 | ||
2604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2612 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2605 | "Starting revocation check for zone %s\n", | 2613 | "Starting revocation check for zone %s\n", |
2606 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2614 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2607 | rh->rev_check = GNUNET_REVOCATION_query (cfg, | 2615 | rh->rev_check = GNUNET_REVOCATION_query(cfg, |
2608 | &ac->authority_info.gns_authority, | 2616 | &ac->authority_info.gns_authority, |
2609 | &handle_revocation_result, | 2617 | &handle_revocation_result, |
2610 | rh); | 2618 | rh); |
2611 | GNUNET_assert (NULL != rh->rev_check); | 2619 | GNUNET_assert(NULL != rh->rev_check); |
2612 | } | 2620 | } |
2613 | 2621 | ||
2614 | 2622 | ||
@@ -2618,23 +2626,23 @@ recursive_gns_resolution_revocation (struct GNS_ResolverHandle *rh) | |||
2618 | * @param cls the `struct GNS_ResolverHandle` of the resolution | 2626 | * @param cls the `struct GNS_ResolverHandle` of the resolution |
2619 | */ | 2627 | */ |
2620 | static void | 2628 | static void |
2621 | recursive_resolution (void *cls) | 2629 | recursive_resolution(void *cls) |
2622 | { | 2630 | { |
2623 | struct GNS_ResolverHandle *rh = cls; | 2631 | struct GNS_ResolverHandle *rh = cls; |
2624 | 2632 | ||
2625 | rh->task_id = NULL; | 2633 | rh->task_id = NULL; |
2626 | if (MAX_RECURSION < rh->loop_limiter++) | 2634 | if (MAX_RECURSION < rh->loop_limiter++) |
2627 | { | 2635 | { |
2628 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2636 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2629 | "Encountered unbounded recursion resolving `%s'\n", | 2637 | "Encountered unbounded recursion resolving `%s'\n", |
2630 | rh->name); | 2638 | rh->name); |
2631 | fail_resolution (rh); | 2639 | fail_resolution(rh); |
2632 | return; | 2640 | return; |
2633 | } | 2641 | } |
2634 | if (GNUNET_YES == rh->ac_tail->gns_authority) | 2642 | if (GNUNET_YES == rh->ac_tail->gns_authority) |
2635 | recursive_gns_resolution_revocation (rh); | 2643 | recursive_gns_resolution_revocation(rh); |
2636 | else | 2644 | else |
2637 | recursive_dns_resolution (rh); | 2645 | recursive_dns_resolution(rh); |
2638 | } | 2646 | } |
2639 | 2647 | ||
2640 | 2648 | ||
@@ -2645,7 +2653,7 @@ recursive_resolution (void *cls) | |||
2645 | * @param cls the `struct GNS_ResolverHandle` | 2653 | * @param cls the `struct GNS_ResolverHandle` |
2646 | */ | 2654 | */ |
2647 | static void | 2655 | static void |
2648 | start_resolver_lookup (void *cls) | 2656 | start_resolver_lookup(void *cls) |
2649 | { | 2657 | { |
2650 | struct GNS_ResolverHandle *rh = cls; | 2658 | struct GNS_ResolverHandle *rh = cls; |
2651 | struct AuthorityChain *ac; | 2659 | struct AuthorityChain *ac; |
@@ -2653,61 +2661,61 @@ start_resolver_lookup (void *cls) | |||
2653 | struct in6_addr v6; | 2661 | struct in6_addr v6; |
2654 | 2662 | ||
2655 | rh->task_id = NULL; | 2663 | rh->task_id = NULL; |
2656 | if (1 == inet_pton (AF_INET, | 2664 | if (1 == inet_pton(AF_INET, |
2657 | rh->name, | 2665 | rh->name, |
2658 | &v4)) | 2666 | &v4)) |
2659 | { | 2667 | { |
2660 | /* name is IPv4 address, pretend it's an A record */ | 2668 | /* name is IPv4 address, pretend it's an A record */ |
2661 | struct GNUNET_GNSRECORD_Data rd; | 2669 | struct GNUNET_GNSRECORD_Data rd; |
2662 | 2670 | ||
2663 | rd.data = &v4; | 2671 | rd.data = &v4; |
2664 | rd.data_size = sizeof (v4); | 2672 | rd.data_size = sizeof(v4); |
2665 | rd.expiration_time = UINT64_MAX; | 2673 | rd.expiration_time = UINT64_MAX; |
2666 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | 2674 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; |
2667 | rd.flags = 0; | 2675 | rd.flags = 0; |
2668 | rh->proc (rh->proc_cls, | 2676 | rh->proc(rh->proc_cls, |
2669 | 1, | 2677 | 1, |
2670 | &rd); | 2678 | &rd); |
2671 | GNUNET_assert (NULL == rh->task_id); | 2679 | GNUNET_assert(NULL == rh->task_id); |
2672 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 2680 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
2673 | rh); | 2681 | rh); |
2674 | return; | 2682 | return; |
2675 | } | 2683 | } |
2676 | if (1 == inet_pton (AF_INET6, | 2684 | if (1 == inet_pton(AF_INET6, |
2677 | rh->name, | 2685 | rh->name, |
2678 | &v6)) | 2686 | &v6)) |
2679 | { | 2687 | { |
2680 | /* name is IPv6 address, pretend it's an AAAA record */ | 2688 | /* name is IPv6 address, pretend it's an AAAA record */ |
2681 | struct GNUNET_GNSRECORD_Data rd; | 2689 | struct GNUNET_GNSRECORD_Data rd; |
2682 | 2690 | ||
2683 | rd.data = &v6; | 2691 | rd.data = &v6; |
2684 | rd.data_size = sizeof (v6); | 2692 | rd.data_size = sizeof(v6); |
2685 | rd.expiration_time = UINT64_MAX; | 2693 | rd.expiration_time = UINT64_MAX; |
2686 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; | 2694 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; |
2687 | rd.flags = 0; | 2695 | rd.flags = 0; |
2688 | rh->proc (rh->proc_cls, | 2696 | rh->proc(rh->proc_cls, |
2689 | 1, | 2697 | 1, |
2690 | &rd); | 2698 | &rd); |
2691 | GNUNET_assert (NULL == rh->task_id); | 2699 | GNUNET_assert(NULL == rh->task_id); |
2692 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 2700 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
2693 | rh); | 2701 | rh); |
2694 | return; | 2702 | return; |
2695 | } | 2703 | } |
2696 | 2704 | ||
2697 | ac = GNUNET_new (struct AuthorityChain); | 2705 | ac = GNUNET_new(struct AuthorityChain); |
2698 | ac->rh = rh; | 2706 | ac->rh = rh; |
2699 | ac->label = resolver_lookup_get_next_label (rh); | 2707 | ac->label = resolver_lookup_get_next_label(rh); |
2700 | if (NULL == ac->label) | 2708 | if (NULL == ac->label) |
2701 | /* name was just the "TLD", so we default to label | 2709 | /* name was just the "TLD", so we default to label |
2702 | #GNUNET_GNS_EMPTY_LABEL_AT */ | 2710 | #GNUNET_GNS_EMPTY_LABEL_AT */ |
2703 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); | 2711 | ac->label = GNUNET_strdup(GNUNET_GNS_EMPTY_LABEL_AT); |
2704 | ac->gns_authority = GNUNET_YES; | 2712 | ac->gns_authority = GNUNET_YES; |
2705 | ac->authority_info.gns_authority = rh->authority_zone; | 2713 | ac->authority_info.gns_authority = rh->authority_zone; |
2706 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 2714 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, |
2707 | rh->ac_tail, | 2715 | rh->ac_tail, |
2708 | ac); | 2716 | ac); |
2709 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | 2717 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, |
2710 | rh); | 2718 | rh); |
2711 | } | 2719 | } |
2712 | 2720 | ||
2713 | 2721 | ||
@@ -2724,31 +2732,31 @@ start_resolver_lookup (void *cls) | |||
2724 | * @return handle to cancel operation | 2732 | * @return handle to cancel operation |
2725 | */ | 2733 | */ |
2726 | struct GNS_ResolverHandle * | 2734 | struct GNS_ResolverHandle * |
2727 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 2735 | GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, |
2728 | uint32_t record_type, | 2736 | uint32_t record_type, |
2729 | const char *name, | 2737 | const char *name, |
2730 | enum GNUNET_GNS_LocalOptions options, | 2738 | enum GNUNET_GNS_LocalOptions options, |
2731 | GNS_ResultProcessor proc, | 2739 | GNS_ResultProcessor proc, |
2732 | void *proc_cls) | 2740 | void *proc_cls) |
2733 | { | 2741 | { |
2734 | struct GNS_ResolverHandle *rh; | 2742 | struct GNS_ResolverHandle *rh; |
2735 | 2743 | ||
2736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2744 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2737 | "Starting lookup for `%s'\n", | 2745 | "Starting lookup for `%s'\n", |
2738 | name); | 2746 | name); |
2739 | rh = GNUNET_new (struct GNS_ResolverHandle); | 2747 | rh = GNUNET_new(struct GNS_ResolverHandle); |
2740 | GNUNET_CONTAINER_DLL_insert (rlh_head, | 2748 | GNUNET_CONTAINER_DLL_insert(rlh_head, |
2741 | rlh_tail, | 2749 | rlh_tail, |
2742 | rh); | 2750 | rh); |
2743 | rh->authority_zone = *zone; | 2751 | rh->authority_zone = *zone; |
2744 | rh->proc = proc; | 2752 | rh->proc = proc; |
2745 | rh->proc_cls = proc_cls; | 2753 | rh->proc_cls = proc_cls; |
2746 | rh->options = options; | 2754 | rh->options = options; |
2747 | rh->record_type = record_type; | 2755 | rh->record_type = record_type; |
2748 | rh->name = GNUNET_strdup (name); | 2756 | rh->name = GNUNET_strdup(name); |
2749 | rh->name_resolution_pos = strlen (name); | 2757 | rh->name_resolution_pos = strlen(name); |
2750 | rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 2758 | rh->task_id = GNUNET_SCHEDULER_add_now(&start_resolver_lookup, |
2751 | rh); | 2759 | rh); |
2752 | return rh; | 2760 | return rh; |
2753 | } | 2761 | } |
2754 | 2762 | ||
@@ -2759,107 +2767,107 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | |||
2759 | * @param rh resolution to abort | 2767 | * @param rh resolution to abort |
2760 | */ | 2768 | */ |
2761 | void | 2769 | void |
2762 | GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | 2770 | GNS_resolver_lookup_cancel(struct GNS_ResolverHandle *rh) |
2763 | { | 2771 | { |
2764 | struct DnsResult *dr; | 2772 | struct DnsResult *dr; |
2765 | struct AuthorityChain *ac; | 2773 | struct AuthorityChain *ac; |
2766 | struct VpnContext *vpn_ctx; | 2774 | struct VpnContext *vpn_ctx; |
2767 | 2775 | ||
2768 | GNUNET_CONTAINER_DLL_remove (rlh_head, | 2776 | GNUNET_CONTAINER_DLL_remove(rlh_head, |
2769 | rlh_tail, | 2777 | rlh_tail, |
2770 | rh); | 2778 | rh); |
2771 | if (NULL != rh->dns_request) | 2779 | if (NULL != rh->dns_request) |
2772 | { | 2780 | { |
2773 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | 2781 | GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); |
2774 | rh->dns_request = NULL; | 2782 | rh->dns_request = NULL; |
2775 | } | 2783 | } |
2776 | while (NULL != (ac = rh->ac_head)) | 2784 | while (NULL != (ac = rh->ac_head)) |
2777 | { | ||
2778 | GNUNET_CONTAINER_DLL_remove (rh->ac_head, | ||
2779 | rh->ac_tail, | ||
2780 | ac); | ||
2781 | if (GNUNET_NO == ac->gns_authority) | ||
2782 | { | 2785 | { |
2783 | struct Gns2DnsPending *gp; | 2786 | GNUNET_CONTAINER_DLL_remove(rh->ac_head, |
2784 | 2787 | rh->ac_tail, | |
2785 | while (NULL != (gp = ac->authority_info.dns_authority.gp_head)) | 2788 | ac); |
2786 | { | 2789 | if (GNUNET_NO == ac->gns_authority) |
2787 | GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head, | ||
2788 | ac->authority_info.dns_authority.gp_tail, | ||
2789 | gp); | ||
2790 | if (NULL != gp->rh) | ||
2791 | { | ||
2792 | /* rh->g2dc->rh is NOT in the DLL yet, so to enable us | ||
2793 | using GNS_resolver_lookup_cancel here, we need to | ||
2794 | add it first... */ | ||
2795 | GNUNET_CONTAINER_DLL_insert (rlh_head, | ||
2796 | rlh_tail, | ||
2797 | gp->rh); | ||
2798 | GNUNET_assert (NULL == gp->rh->task_id); | ||
2799 | gp->rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | ||
2800 | gp->rh); | ||
2801 | gp->rh = NULL; | ||
2802 | } | ||
2803 | if (NULL != gp->dns_rh) | ||
2804 | { | 2790 | { |
2805 | GNUNET_RESOLVER_request_cancel (gp->dns_rh); | 2791 | struct Gns2DnsPending *gp; |
2806 | gp->dns_rh = NULL; | 2792 | |
2793 | while (NULL != (gp = ac->authority_info.dns_authority.gp_head)) | ||
2794 | { | ||
2795 | GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, | ||
2796 | ac->authority_info.dns_authority.gp_tail, | ||
2797 | gp); | ||
2798 | if (NULL != gp->rh) | ||
2799 | { | ||
2800 | /* rh->g2dc->rh is NOT in the DLL yet, so to enable us | ||
2801 | using GNS_resolver_lookup_cancel here, we need to | ||
2802 | add it first... */ | ||
2803 | GNUNET_CONTAINER_DLL_insert(rlh_head, | ||
2804 | rlh_tail, | ||
2805 | gp->rh); | ||
2806 | GNUNET_assert(NULL == gp->rh->task_id); | ||
2807 | gp->rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, | ||
2808 | gp->rh); | ||
2809 | gp->rh = NULL; | ||
2810 | } | ||
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); | ||
2807 | } | 2819 | } |
2808 | GNUNET_free (gp); | 2820 | GNUNET_free(ac->label); |
2809 | } | 2821 | GNUNET_free(ac); |
2810 | GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle); | ||
2811 | } | 2822 | } |
2812 | GNUNET_free (ac->label); | ||
2813 | GNUNET_free (ac); | ||
2814 | } | ||
2815 | if (NULL != rh->task_id) | 2823 | if (NULL != rh->task_id) |
2816 | { | 2824 | { |
2817 | GNUNET_SCHEDULER_cancel (rh->task_id); | 2825 | GNUNET_SCHEDULER_cancel(rh->task_id); |
2818 | rh->task_id = NULL; | 2826 | rh->task_id = NULL; |
2819 | } | 2827 | } |
2820 | if (NULL != rh->get_handle) | 2828 | if (NULL != rh->get_handle) |
2821 | { | 2829 | { |
2822 | GNUNET_DHT_get_stop (rh->get_handle); | 2830 | GNUNET_DHT_get_stop(rh->get_handle); |
2823 | rh->get_handle = NULL; | 2831 | rh->get_handle = NULL; |
2824 | } | 2832 | } |
2825 | if (NULL != rh->dht_heap_node) | 2833 | if (NULL != rh->dht_heap_node) |
2826 | { | 2834 | { |
2827 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); | 2835 | GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); |
2828 | rh->dht_heap_node = NULL; | 2836 | rh->dht_heap_node = NULL; |
2829 | } | 2837 | } |
2830 | if (NULL != (vpn_ctx = rh->vpn_ctx)) | 2838 | if (NULL != (vpn_ctx = rh->vpn_ctx)) |
2831 | { | 2839 | { |
2832 | GNUNET_VPN_cancel_request (vpn_ctx->vpn_request); | 2840 | GNUNET_VPN_cancel_request(vpn_ctx->vpn_request); |
2833 | GNUNET_free (vpn_ctx->rd_data); | 2841 | GNUNET_free(vpn_ctx->rd_data); |
2834 | GNUNET_free (vpn_ctx); | 2842 | GNUNET_free(vpn_ctx); |
2835 | } | 2843 | } |
2836 | if (NULL != rh->namecache_qe) | 2844 | if (NULL != rh->namecache_qe) |
2837 | { | 2845 | { |
2838 | GNUNET_NAMECACHE_cancel (rh->namecache_qe); | 2846 | GNUNET_NAMECACHE_cancel(rh->namecache_qe); |
2839 | rh->namecache_qe = NULL; | 2847 | rh->namecache_qe = NULL; |
2840 | } | 2848 | } |
2841 | if (NULL != rh->rev_check) | 2849 | if (NULL != rh->rev_check) |
2842 | { | 2850 | { |
2843 | GNUNET_REVOCATION_query_cancel (rh->rev_check); | 2851 | GNUNET_REVOCATION_query_cancel(rh->rev_check); |
2844 | rh->rev_check = NULL; | 2852 | rh->rev_check = NULL; |
2845 | } | 2853 | } |
2846 | if (NULL != rh->std_resolve) | 2854 | if (NULL != rh->std_resolve) |
2847 | { | 2855 | { |
2848 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2856 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2849 | "Canceling standard DNS resolution\n"); | 2857 | "Canceling standard DNS resolution\n"); |
2850 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | 2858 | GNUNET_RESOLVER_request_cancel(rh->std_resolve); |
2851 | rh->std_resolve = NULL; | 2859 | rh->std_resolve = NULL; |
2852 | } | 2860 | } |
2853 | while (NULL != (dr = rh->dns_result_head)) | 2861 | while (NULL != (dr = rh->dns_result_head)) |
2854 | { | 2862 | { |
2855 | GNUNET_CONTAINER_DLL_remove (rh->dns_result_head, | 2863 | GNUNET_CONTAINER_DLL_remove(rh->dns_result_head, |
2856 | rh->dns_result_tail, | 2864 | rh->dns_result_tail, |
2857 | dr); | 2865 | dr); |
2858 | GNUNET_free (dr); | 2866 | GNUNET_free(dr); |
2859 | } | 2867 | } |
2860 | GNUNET_free_non_null (rh->leho); | 2868 | GNUNET_free_non_null(rh->leho); |
2861 | GNUNET_free (rh->name); | 2869 | GNUNET_free(rh->name); |
2862 | GNUNET_free (rh); | 2870 | GNUNET_free(rh); |
2863 | } | 2871 | } |
2864 | 2872 | ||
2865 | 2873 | ||
@@ -2875,24 +2883,24 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
2875 | * @param max_bg_queries maximum number of parallel background queries in dht | 2883 | * @param max_bg_queries maximum number of parallel background queries in dht |
2876 | */ | 2884 | */ |
2877 | void | 2885 | void |
2878 | GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | 2886 | GNS_resolver_init(struct GNUNET_NAMECACHE_Handle *nc, |
2879 | struct GNUNET_DHT_Handle *dht, | 2887 | struct GNUNET_DHT_Handle *dht, |
2880 | const struct GNUNET_CONFIGURATION_Handle *c, | 2888 | const struct GNUNET_CONFIGURATION_Handle *c, |
2881 | unsigned long long max_bg_queries) | 2889 | unsigned long long max_bg_queries) |
2882 | { | 2890 | { |
2883 | cfg = c; | 2891 | cfg = c; |
2884 | namecache_handle = nc; | 2892 | namecache_handle = nc; |
2885 | dht_handle = dht; | 2893 | dht_handle = dht; |
2886 | dht_lookup_heap = | 2894 | dht_lookup_heap = |
2887 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2895 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2888 | max_allowed_background_queries = max_bg_queries; | 2896 | max_allowed_background_queries = max_bg_queries; |
2889 | disable_cache = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 2897 | disable_cache = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
2890 | "namecache", | 2898 | "namecache", |
2891 | "DISABLE"); | 2899 | "DISABLE"); |
2892 | if (GNUNET_YES == disable_cache) | 2900 | if (GNUNET_YES == disable_cache) |
2893 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2901 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2894 | "Namecache disabled\n"); | 2902 | "Namecache disabled\n"); |
2895 | vpn_handle = GNUNET_VPN_connect (cfg); | 2903 | vpn_handle = GNUNET_VPN_connect(cfg); |
2896 | } | 2904 | } |
2897 | 2905 | ||
2898 | 2906 | ||
@@ -2900,30 +2908,30 @@ GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | |||
2900 | * Shutdown resolver | 2908 | * Shutdown resolver |
2901 | */ | 2909 | */ |
2902 | void | 2910 | void |
2903 | GNS_resolver_done () | 2911 | GNS_resolver_done() |
2904 | { | 2912 | { |
2905 | struct GNS_ResolverHandle *rh; | 2913 | struct GNS_ResolverHandle *rh; |
2906 | struct CacheOps *co; | 2914 | struct CacheOps *co; |
2907 | 2915 | ||
2908 | /* abort active resolutions */ | 2916 | /* abort active resolutions */ |
2909 | while (NULL != (rh = rlh_head)) | 2917 | while (NULL != (rh = rlh_head)) |
2910 | { | 2918 | { |
2911 | rh->proc (rh->proc_cls, | 2919 | rh->proc(rh->proc_cls, |
2912 | 0, | 2920 | 0, |
2913 | NULL); | 2921 | NULL); |
2914 | GNS_resolver_lookup_cancel (rh); | 2922 | GNS_resolver_lookup_cancel(rh); |
2915 | } | 2923 | } |
2916 | while (NULL != (co = co_head)) | 2924 | while (NULL != (co = co_head)) |
2917 | { | 2925 | { |
2918 | GNUNET_CONTAINER_DLL_remove (co_head, | 2926 | GNUNET_CONTAINER_DLL_remove(co_head, |
2919 | co_tail, | 2927 | co_tail, |
2920 | co); | 2928 | co); |
2921 | GNUNET_NAMECACHE_cancel (co->namecache_qe_cache); | 2929 | GNUNET_NAMECACHE_cancel(co->namecache_qe_cache); |
2922 | GNUNET_free (co); | 2930 | GNUNET_free(co); |
2923 | } | 2931 | } |
2924 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); | 2932 | GNUNET_CONTAINER_heap_destroy(dht_lookup_heap); |
2925 | dht_lookup_heap = NULL; | 2933 | dht_lookup_heap = NULL; |
2926 | GNUNET_VPN_disconnect (vpn_handle); | 2934 | GNUNET_VPN_disconnect(vpn_handle); |
2927 | vpn_handle = NULL; | 2935 | vpn_handle = NULL; |
2928 | dht_handle = NULL; | 2936 | dht_handle = NULL; |
2929 | namecache_handle = NULL; | 2937 | namecache_handle = NULL; |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 240747931..8865f3c95 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/gnunet-service-gns_resolver.h | 21 | * @file gns/gnunet-service-gns_resolver.h |
22 | * @brief GNUnet GNS service | 22 | * @brief GNUnet GNS service |
@@ -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 | */ |
41 | void | 41 | void |
42 | GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | 42 | GNS_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 | */ |
51 | void | 51 | void |
52 | GNS_resolver_done (void); | 52 | GNS_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 | */ |
86 | struct GNS_ResolverHandle * | 86 | struct GNS_ResolverHandle * |
87 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 87 | GNS_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 | */ |
100 | void | 100 | void |
101 | GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh); | 101 | GNS_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 1c17efefe..0316245ff 100644 --- a/src/gns/gnunet_w32nsp_lib.h +++ b/src/gns/gnunet_w32nsp_lib.h | |||
@@ -4,6 +4,6 @@ | |||
4 | #include <basetyps.h> | 4 | #include <basetyps.h> |
5 | 5 | ||
6 | /* E0D24085-622C-4A93-9A0018-034469DE28DA */ | 6 | /* E0D24085-622C-4A93-9A0018-034469DE28DA */ |
7 | DEFINE_GUID (GNUNET_NAMESPACE_PROVIDER_DNS, 0xE0D24085L, 0x622C, 0x4A93, 0x9A, 0x18, 0x03, 0x44, 0x69, 0xDE, 0x28, 0xDA); | 7 | DEFINE_GUID(GNUNET_NAMESPACE_PROVIDER_DNS, 0xE0D24085L, 0x622C, 0x4A93, 0x9A, 0x18, 0x03, 0x44, 0x69, 0xDE, 0x28, 0xDA); |
8 | 8 | ||
9 | #endif /* GNUNET_W32NSP_LIB_H */ | 9 | #endif /* GNUNET_W32NSP_LIB_H */ |
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c index d76eac845..43fc030b9 100644 --- a/src/gns/nss/nss_gns.c +++ b/src/gns/nss/nss_gns.c | |||
@@ -17,7 +17,7 @@ | |||
17 | along with nss-mdns; if not, write to the Free Software | 17 | along with nss-mdns; if not, write to the Free Software |
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 | USA. | 19 | USA. |
20 | ***/ | 20 | ***/ |
21 | 21 | ||
22 | #include <gnunet_config.h> | 22 | #include <gnunet_config.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
@@ -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 | /** |
@@ -75,7 +75,7 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
75 | #ifdef NSS_IPV6_ONLY | 75 | #ifdef NSS_IPV6_ONLY |
76 | af = AF_INET6; | 76 | af = AF_INET6; |
77 | #else | 77 | #else |
78 | af = AF_INET; | 78 | af = AF_INET; |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | #ifdef NSS_IPV4_ONLY | 81 | #ifdef NSS_IPV4_ONLY |
@@ -83,70 +83,70 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
83 | #elif NSS_IPV6_ONLY | 83 | #elif NSS_IPV6_ONLY |
84 | if (af != AF_INET6) | 84 | if (af != AF_INET6) |
85 | #else | 85 | #else |
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) : sizeof(ipv6_address_t); |
97 | if (buflen < | 97 | if (buflen < |
98 | sizeof(char*) + /* alias names */ | 98 | sizeof(char*) + /* alias names */ |
99 | strlen (name) + 1) | 99 | strlen(name) + 1) |
100 | { /* official name */ | 100 | { /* official name */ |
101 | *errnop = ERANGE; | 101 | *errnop = ERANGE; |
102 | *h_errnop = NO_RECOVERY; | 102 | *h_errnop = NO_RECOVERY; |
103 | status = NSS_STATUS_TRYAGAIN; | 103 | status = NSS_STATUS_TRYAGAIN; |
104 | 104 | ||
105 | goto finish; | 105 | goto finish; |
106 | } | 106 | } |
107 | u.count = 0; | 107 | u.count = 0; |
108 | u.data_len = 0; | 108 | u.data_len = 0; |
109 | i = gns_resolve_name (af, | 109 | i = gns_resolve_name(af, |
110 | name, | 110 | name, |
111 | &u); | 111 | &u); |
112 | if (-1 == i) | 112 | if (-1 == i) |
113 | { | 113 | { |
114 | *errnop = errno; | 114 | *errnop = errno; |
115 | status = NSS_STATUS_UNAVAIL; | 115 | status = NSS_STATUS_UNAVAIL; |
116 | *h_errnop = NO_RECOVERY; | 116 | *h_errnop = NO_RECOVERY; |
117 | goto finish; | 117 | goto finish; |
118 | } | 118 | } |
119 | if (-2 == i) | 119 | if (-2 == i) |
120 | { | 120 | { |
121 | *errnop = ENOENT; | 121 | *errnop = ENOENT; |
122 | *h_errnop = NO_RECOVERY; | 122 | *h_errnop = NO_RECOVERY; |
123 | status = NSS_STATUS_UNAVAIL; | 123 | status = NSS_STATUS_UNAVAIL; |
124 | goto finish; | 124 | goto finish; |
125 | } | 125 | } |
126 | if (-3 == i) | 126 | if (-3 == i) |
127 | { | 127 | { |
128 | *errnop = ETIMEDOUT; | 128 | *errnop = ETIMEDOUT; |
129 | *h_errnop = HOST_NOT_FOUND; | 129 | *h_errnop = HOST_NOT_FOUND; |
130 | status = NSS_STATUS_NOTFOUND; | 130 | status = NSS_STATUS_NOTFOUND; |
131 | goto finish; | 131 | goto finish; |
132 | } | 132 | } |
133 | if (0 == u.count) | 133 | if (0 == u.count) |
134 | { | 134 | { |
135 | *errnop = 0; /* success */ | 135 | *errnop = 0; /* success */ |
136 | *h_errnop = NO_DATA; /* success */ | 136 | *h_errnop = NO_DATA; /* success */ |
137 | status = NSS_STATUS_NOTFOUND; | 137 | status = NSS_STATUS_NOTFOUND; |
138 | goto finish; | 138 | goto finish; |
139 | } | 139 | } |
140 | /* Alias names */ | 140 | /* Alias names */ |
141 | *((char**) buffer) = NULL; | 141 | *((char**)buffer) = NULL; |
142 | result->h_aliases = (char**) buffer; | 142 | result->h_aliases = (char**)buffer; |
143 | idx = sizeof(char*); | 143 | idx = sizeof(char*); |
144 | 144 | ||
145 | /* Official name */ | 145 | /* Official name */ |
146 | strcpy (buffer+idx, | 146 | strcpy(buffer + idx, |
147 | name); | 147 | name); |
148 | result->h_name = buffer+idx; | 148 | result->h_name = buffer + idx; |
149 | idx += strlen (name)+1; | 149 | idx += strlen(name) + 1; |
150 | 150 | ||
151 | ALIGN(idx); | 151 | ALIGN(idx); |
152 | 152 | ||
@@ -154,29 +154,29 @@ _nss_gns_gethostbyname2_r(const char *name, | |||
154 | result->h_length = address_length; | 154 | result->h_length = address_length; |
155 | 155 | ||
156 | /* Check if there's enough space for the addresses */ | 156 | /* Check if there's enough space for the addresses */ |
157 | if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)) | 157 | if (buflen < idx + u.data_len + sizeof(char*) * (u.count + 1)) |
158 | { | 158 | { |
159 | *errnop = ERANGE; | 159 | *errnop = ERANGE; |
160 | *h_errnop = NO_RECOVERY; | 160 | *h_errnop = NO_RECOVERY; |
161 | status = NSS_STATUS_TRYAGAIN; | 161 | status = NSS_STATUS_TRYAGAIN; |
162 | goto finish; | 162 | goto finish; |
163 | } | 163 | } |
164 | /* Addresses */ | 164 | /* Addresses */ |
165 | astart = idx; | 165 | astart = idx; |
166 | l = u.count*address_length; | 166 | l = u.count * address_length; |
167 | if (0 != l) | 167 | if (0 != l) |
168 | memcpy (buffer+astart, | 168 | memcpy(buffer + astart, |
169 | &u.data, | 169 | &u.data, |
170 | l); | 170 | l); |
171 | /* address_length is a multiple of 32bits, so idx is still aligned | 171 | /* address_length is a multiple of 32bits, so idx is still aligned |
172 | * correctly */ | 172 | * correctly */ |
173 | idx += l; | 173 | idx += l; |
174 | 174 | ||
175 | /* Address array address_length is always a multiple of 32bits */ | 175 | /* Address array address_length is always a multiple of 32bits */ |
176 | for (i = 0; i < u.count; i++) | 176 | for (i = 0; i < u.count; i++) |
177 | ((char**) (buffer+idx))[i] = buffer+astart+address_length*i; | 177 | ((char**)(buffer + idx))[i] = buffer + astart + address_length * i; |
178 | ((char**) (buffer+idx))[i] = NULL; | 178 | ((char**)(buffer + idx))[i] = NULL; |
179 | result->h_addr_list = (char**) (buffer+idx); | 179 | result->h_addr_list = (char**)(buffer + idx); |
180 | 180 | ||
181 | status = NSS_STATUS_SUCCESS; | 181 | status = NSS_STATUS_SUCCESS; |
182 | 182 | ||
@@ -197,20 +197,20 @@ finish: | |||
197 | * @return a nss_status code | 197 | * @return a nss_status code |
198 | */ | 198 | */ |
199 | enum nss_status | 199 | enum nss_status |
200 | _nss_gns_gethostbyname_r (const char *name, | 200 | _nss_gns_gethostbyname_r(const char *name, |
201 | struct hostent *result, | 201 | struct hostent *result, |
202 | char *buffer, | 202 | char *buffer, |
203 | size_t buflen, | 203 | size_t buflen, |
204 | int *errnop, | 204 | int *errnop, |
205 | int *h_errnop) | 205 | int *h_errnop) |
206 | { | 206 | { |
207 | return _nss_gns_gethostbyname2_r (name, | 207 | return _nss_gns_gethostbyname2_r(name, |
208 | AF_UNSPEC, | 208 | AF_UNSPEC, |
209 | result, | 209 | result, |
210 | buffer, | 210 | buffer, |
211 | buflen, | 211 | buflen, |
212 | errnop, | 212 | errnop, |
213 | h_errnop); | 213 | h_errnop); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
@@ -229,21 +229,21 @@ _nss_gns_gethostbyname_r (const char *name, | |||
229 | * @return NSS_STATUS_UNAVAIL | 229 | * @return NSS_STATUS_UNAVAIL |
230 | */ | 230 | */ |
231 | enum nss_status | 231 | enum nss_status |
232 | _nss_gns_gethostbyaddr_r (const void* addr, | 232 | _nss_gns_gethostbyaddr_r(const void* addr, |
233 | int len, | 233 | int len, |
234 | int af, | 234 | int af, |
235 | struct hostent *result, | 235 | struct hostent *result, |
236 | char *buffer, | 236 | char *buffer, |
237 | size_t buflen, | 237 | size_t buflen, |
238 | int *errnop, | 238 | int *errnop, |
239 | int *h_errnop) | 239 | int *h_errnop) |
240 | { | 240 | { |
241 | (void) addr; | 241 | (void)addr; |
242 | (void) len; | 242 | (void)len; |
243 | (void) af; | 243 | (void)af; |
244 | (void) result; | 244 | (void)result; |
245 | (void) buffer; | 245 | (void)buffer; |
246 | (void) buflen; | 246 | (void)buflen; |
247 | *errnop = EINVAL; | 247 | *errnop = EINVAL; |
248 | *h_errnop = NO_RECOVERY; | 248 | *h_errnop = NO_RECOVERY; |
249 | /* NOTE we allow to leak this into DNS so no NOTFOUND */ | 249 | /* 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 253bb0f02..8af618618 100644 --- a/src/gns/nss/nss_gns_query.c +++ b/src/gns/nss/nss_gns_query.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | #include <string.h> | 20 | #include <string.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
@@ -33,12 +33,12 @@ | |||
33 | #define TIMEOUT "5s" | 33 | #define TIMEOUT "5s" |
34 | 34 | ||
35 | static void | 35 | static void |
36 | kwait (pid_t chld) | 36 | kwait(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 | */ |
57 | int | 57 | int |
58 | gns_resolve_name (int af, const char *name, struct userdata *u) | 58 | gns_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') | ||
102 | { | 93 | { |
103 | line[strlen (line) - 1] = '\0'; | 94 | kwait(pid); |
104 | if (AF_INET == af) | 95 | return -1; |
105 | { | 96 | } |
106 | if (inet_pton (af, line, &u->data.ipv4[u->count])) | 97 | while (NULL != fgets(line, sizeof(line), p)) |
107 | { | 98 | { |
108 | u->count++; | 99 | if (u->count >= MAX_ENTRIES) |
109 | u->data_len += sizeof (ipv4_address_t); | 100 | break; |
110 | } | 101 | if (line[strlen(line) - 1] == '\n') |
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 | { | 102 | { |
128 | (void) fclose (p); | 103 | line[strlen(line) - 1] = '\0'; |
129 | kwait (pid); | 104 | if (AF_INET == af) |
130 | errno = EINVAL; | 105 | { |
131 | return -1; | 106 | if (inet_pton(af, line, &u->data.ipv4[u->count])) |
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 | } | ||
132 | } | 134 | } |
133 | } | ||
134 | } | 135 | } |
135 | } | 136 | (void)fclose(p); |
136 | (void) fclose (p); | 137 | waitpid(pid, &ret, 0); |
137 | waitpid (pid, &ret, 0); | 138 | if (!WIFEXITED(ret)) |
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 30ba76fd9..1901dd6c4 100644 --- a/src/gns/nss/nss_gns_query.h +++ b/src/gns/nss/nss_gns_query.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | #ifndef NSS_GNS_QUERY_H | 20 | #ifndef NSS_GNS_QUERY_H |
21 | #define NSS_GNS_QUERY_H | 21 | #define NSS_GNS_QUERY_H |
22 | 22 | ||
@@ -28,20 +28,17 @@ | |||
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 | ||
31 | typedef struct | 31 | typedef struct { |
32 | { | ||
33 | uint32_t address; | 32 | uint32_t address; |
34 | } ipv4_address_t; | 33 | } ipv4_address_t; |
35 | 34 | ||
36 | 35 | ||
37 | typedef struct | 36 | typedef struct { |
38 | { | ||
39 | uint8_t address[16]; | 37 | uint8_t address[16]; |
40 | } ipv6_address_t; | 38 | } ipv6_address_t; |
41 | 39 | ||
42 | 40 | ||
43 | struct userdata | 41 | struct userdata { |
44 | { | ||
45 | int count; | 42 | int count; |
46 | int data_len; /* only valid when doing reverse lookup */ | 43 | int data_len; /* only valid when doing reverse lookup */ |
47 | union { | 44 | union { |
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 86d45b9fe..71cd78a8e 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file gns/plugin_block_gns.c | 22 | * @file gns/plugin_block_gns.c |
@@ -56,37 +56,37 @@ | |||
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 | */ |
58 | static struct GNUNET_BLOCK_Group * | 58 | static struct GNUNET_BLOCK_Group * |
59 | block_plugin_gns_create_group (void *cls, | 59 | block_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 int), |
73 | BLOOMFILTER_K); | 73 | BLOOMFILTER_K); |
74 | else if (0 == strcmp (guard, | 74 | else if (0 == strcmp(guard, |
75 | "filter-size")) | 75 | "filter-size")) |
76 | bf_size = va_arg (va, unsigned int); | 76 | bf_size = va_arg(va, unsigned int); |
77 | else | 77 | else |
78 | { | 78 | { |
79 | GNUNET_break (0); | 79 | GNUNET_break(0); |
80 | bf_size = GNS_BF_SIZE; | 80 | bf_size = GNS_BF_SIZE; |
81 | } | 81 | } |
82 | GNUNET_break (NULL == va_arg (va, const char *)); | 82 | GNUNET_break(NULL == va_arg(va, const char *)); |
83 | return GNUNET_BLOCK_GROUP_bf_create (cls, | 83 | return GNUNET_BLOCK_GROUP_bf_create(cls, |
84 | bf_size, | 84 | bf_size, |
85 | BLOOMFILTER_K, | 85 | BLOOMFILTER_K, |
86 | type, | 86 | type, |
87 | nonce, | 87 | nonce, |
88 | raw_data, | 88 | raw_data, |
89 | raw_data_size); | 89 | raw_data_size); |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
@@ -110,16 +110,16 @@ block_plugin_gns_create_group (void *cls, | |||
110 | * @return characterization of result | 110 | * @return characterization of result |
111 | */ | 111 | */ |
112 | static enum GNUNET_BLOCK_EvaluationResult | 112 | static enum GNUNET_BLOCK_EvaluationResult |
113 | block_plugin_gns_evaluate (void *cls, | 113 | block_plugin_gns_evaluate(void *cls, |
114 | struct GNUNET_BLOCK_Context *ctx, | 114 | struct GNUNET_BLOCK_Context *ctx, |
115 | enum GNUNET_BLOCK_Type type, | 115 | enum GNUNET_BLOCK_Type type, |
116 | struct GNUNET_BLOCK_Group *bg, | 116 | struct GNUNET_BLOCK_Group *bg, |
117 | enum GNUNET_BLOCK_EvaluationOptions eo, | 117 | enum GNUNET_BLOCK_EvaluationOptions eo, |
118 | const struct GNUNET_HashCode *query, | 118 | const struct GNUNET_HashCode *query, |
119 | const void *xquery, | 119 | const void *xquery, |
120 | size_t xquery_size, | 120 | size_t xquery_size, |
121 | const void *reply_block, | 121 | const void *reply_block, |
122 | size_t reply_block_size) | 122 | size_t reply_block_size) |
123 | { | 123 | { |
124 | const struct GNUNET_GNSRECORD_Block *block; | 124 | const struct GNUNET_GNSRECORD_Block *block; |
125 | struct GNUNET_HashCode h; | 125 | struct GNUNET_HashCode h; |
@@ -128,48 +128,48 @@ block_plugin_gns_evaluate (void *cls, | |||
128 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 128 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
129 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 129 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
130 | if (NULL == reply_block) | 130 | if (NULL == reply_block) |
131 | { | ||
132 | if (0 != xquery_size) | ||
133 | { | 131 | { |
134 | GNUNET_break_op (0); | 132 | if (0 != xquery_size) |
135 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | 133 | { |
134 | GNUNET_break_op(0); | ||
135 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
136 | } | ||
137 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
136 | } | 138 | } |
137 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
138 | } | ||
139 | 139 | ||
140 | /* this is a reply */ | 140 | /* this is a reply */ |
141 | if (reply_block_size < sizeof (struct GNUNET_GNSRECORD_Block)) | 141 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) |
142 | { | 142 | { |
143 | GNUNET_break_op (0); | 143 | GNUNET_break_op(0); |
144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
145 | } | 145 | } |
146 | block = reply_block; | 146 | block = reply_block; |
147 | if (ntohl (block->purpose.size) + sizeof (struct GNUNET_CRYPTO_EcdsaSignature) + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) != | 147 | if (ntohl(block->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != |
148 | reply_block_size) | 148 | reply_block_size) |
149 | { | 149 | { |
150 | GNUNET_break_op (0); | 150 | GNUNET_break_op(0); |
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
152 | } | 152 | } |
153 | GNUNET_CRYPTO_hash (&block->derived_key, | 153 | GNUNET_CRYPTO_hash(&block->derived_key, |
154 | sizeof (block->derived_key), | 154 | sizeof(block->derived_key), |
155 | &h); | 155 | &h); |
156 | if (0 != GNUNET_memcmp (&h, query)) | 156 | if (0 != GNUNET_memcmp(&h, query)) |
157 | { | 157 | { |
158 | GNUNET_break_op (0); | 158 | GNUNET_break_op(0); |
159 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 159 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
160 | } | 160 | } |
161 | if (GNUNET_OK != | 161 | if (GNUNET_OK != |
162 | GNUNET_GNSRECORD_block_verify (block)) | 162 | GNUNET_GNSRECORD_block_verify(block)) |
163 | { | 163 | { |
164 | GNUNET_break_op (0); | 164 | GNUNET_break_op(0); |
165 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 165 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
166 | } | 166 | } |
167 | GNUNET_CRYPTO_hash (reply_block, | 167 | GNUNET_CRYPTO_hash(reply_block, |
168 | reply_block_size, | 168 | reply_block_size, |
169 | &chash); | 169 | &chash); |
170 | if (GNUNET_YES == | 170 | if (GNUNET_YES == |
171 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 171 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, |
172 | &chash)) | 172 | &chash)) |
173 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | 173 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
174 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 174 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
175 | } | 175 | } |
@@ -187,25 +187,25 @@ block_plugin_gns_evaluate (void *cls, | |||
187 | * (or if extracting a key from a block of this type does not work) | 187 | * (or if extracting a key from a block of this type does not work) |
188 | */ | 188 | */ |
189 | static int | 189 | static int |
190 | block_plugin_gns_get_key (void *cls, | 190 | block_plugin_gns_get_key(void *cls, |
191 | enum GNUNET_BLOCK_Type type, | 191 | enum GNUNET_BLOCK_Type type, |
192 | const void *reply_block, | 192 | const void *reply_block, |
193 | size_t reply_block_size, | 193 | size_t reply_block_size, |
194 | struct GNUNET_HashCode *key) | 194 | struct GNUNET_HashCode *key) |
195 | { | 195 | { |
196 | const struct GNUNET_GNSRECORD_Block *block; | 196 | const struct GNUNET_GNSRECORD_Block *block; |
197 | 197 | ||
198 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 198 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
199 | return GNUNET_SYSERR; | 199 | return GNUNET_SYSERR; |
200 | if (reply_block_size < sizeof (struct GNUNET_GNSRECORD_Block)) | 200 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) |
201 | { | 201 | { |
202 | GNUNET_break_op (0); | 202 | GNUNET_break_op(0); |
203 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 203 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
204 | } | 204 | } |
205 | block = reply_block; | 205 | block = reply_block; |
206 | GNUNET_CRYPTO_hash (&block->derived_key, | 206 | GNUNET_CRYPTO_hash(&block->derived_key, |
207 | sizeof (block->derived_key), | 207 | sizeof(block->derived_key), |
208 | key); | 208 | key); |
209 | return GNUNET_OK; | 209 | return GNUNET_OK; |
210 | } | 210 | } |
211 | 211 | ||
@@ -214,7 +214,7 @@ block_plugin_gns_get_key (void *cls, | |||
214 | * Entry point for the plugin. | 214 | * Entry point for the plugin. |
215 | */ | 215 | */ |
216 | void * | 216 | void * |
217 | libgnunet_plugin_block_gns_init (void *cls) | 217 | libgnunet_plugin_block_gns_init(void *cls) |
218 | { | 218 | { |
219 | static enum GNUNET_BLOCK_Type types[] = | 219 | static enum GNUNET_BLOCK_Type types[] = |
220 | { | 220 | { |
@@ -223,7 +223,7 @@ libgnunet_plugin_block_gns_init (void *cls) | |||
223 | }; | 223 | }; |
224 | struct GNUNET_BLOCK_PluginFunctions *api; | 224 | struct GNUNET_BLOCK_PluginFunctions *api; |
225 | 225 | ||
226 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | 226 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); |
227 | api->evaluate = &block_plugin_gns_evaluate; | 227 | api->evaluate = &block_plugin_gns_evaluate; |
228 | api->get_key = &block_plugin_gns_get_key; | 228 | api->get_key = &block_plugin_gns_get_key; |
229 | api->create_group = &block_plugin_gns_create_group; | 229 | api->create_group = &block_plugin_gns_create_group; |
@@ -236,11 +236,11 @@ libgnunet_plugin_block_gns_init (void *cls) | |||
236 | * Exit point from the plugin. | 236 | * Exit point from the plugin. |
237 | */ | 237 | */ |
238 | void * | 238 | void * |
239 | libgnunet_plugin_block_gns_done (void *cls) | 239 | libgnunet_plugin_block_gns_done(void *cls) |
240 | { | 240 | { |
241 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 241 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
242 | 242 | ||
243 | GNUNET_free (api); | 243 | GNUNET_free(api); |
244 | return NULL; | 244 | return NULL; |
245 | } | 245 | } |
246 | 246 | ||
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c index 8cb76cffe..094307ea3 100644 --- a/src/gns/plugin_gnsrecord_gns.c +++ b/src/gns/plugin_gnsrecord_gns.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file gns/plugin_gnsrecord_gns.c | 22 | * @file gns/plugin_gnsrecord_gns.c |
@@ -44,88 +44,94 @@ | |||
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 | */ |
46 | static char * | 46 | static char * |
47 | gns_value_to_string (void *cls, | 47 | gns_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 | { | ||
56 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
57 | if (data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) | ||
58 | return NULL; | ||
59 | return GNUNET_CRYPTO_ecdsa_public_key_to_string (data); | ||
60 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
61 | return GNUNET_strndup (data, data_size); | ||
62 | case GNUNET_GNSRECORD_TYPE_LEHO: | ||
63 | return GNUNET_strndup (data, data_size); | ||
64 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: { | ||
65 | char *ns; | ||
66 | char *ip; | ||
67 | size_t off; | ||
68 | char *nstr; | ||
69 | |||
70 | off = 0; | ||
71 | ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off); | ||
72 | ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off); | ||
73 | if ((NULL == ns) || (NULL == ip) || (off != data_size)) | ||
74 | { | 55 | { |
75 | GNUNET_break_op (0); | 56 | case GNUNET_GNSRECORD_TYPE_PKEY: |
76 | GNUNET_free_non_null (ns); | 57 | if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) |
77 | GNUNET_free_non_null (ip); | 58 | return NULL; |
59 | return GNUNET_CRYPTO_ecdsa_public_key_to_string(data); | ||
60 | |||
61 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
62 | return GNUNET_strndup(data, data_size); | ||
63 | |||
64 | case GNUNET_GNSRECORD_TYPE_LEHO: | ||
65 | return GNUNET_strndup(data, data_size); | ||
66 | |||
67 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: { | ||
68 | char *ns; | ||
69 | char *ip; | ||
70 | size_t off; | ||
71 | char *nstr; | ||
72 | |||
73 | off = 0; | ||
74 | ns = 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)) | ||
77 | { | ||
78 | GNUNET_break_op(0); | ||
79 | GNUNET_free_non_null(ns); | ||
80 | GNUNET_free_non_null(ip); | ||
81 | return NULL; | ||
82 | } | ||
83 | GNUNET_asprintf(&nstr, "%s@%s", ns, ip); | ||
84 | GNUNET_free_non_null(ns); | ||
85 | GNUNET_free_non_null(ip); | ||
86 | return nstr; | ||
87 | } | ||
88 | |||
89 | case GNUNET_GNSRECORD_TYPE_VPN: { | ||
90 | struct GNUNET_TUN_GnsVpnRecord vpn; | ||
91 | char *vpn_str; | ||
92 | |||
93 | cdata = data; | ||
94 | if ((data_size <= sizeof(vpn)) || ('\0' != cdata[data_size - 1])) | ||
95 | return NULL; /* malformed */ | ||
96 | /* need to memcpy for alignment */ | ||
97 | GNUNET_memcpy(&vpn, data, sizeof(vpn)); | ||
98 | GNUNET_asprintf(&vpn_str, | ||
99 | "%u %s %s", | ||
100 | (unsigned int)ntohs(vpn.proto), | ||
101 | (const char *)GNUNET_i2s_full(&vpn.peer), | ||
102 | (const char *)&cdata[sizeof(vpn)]); | ||
103 | return vpn_str; | ||
104 | } | ||
105 | |||
106 | case GNUNET_GNSRECORD_TYPE_BOX: { | ||
107 | struct GNUNET_GNSRECORD_BoxRecord box; | ||
108 | uint32_t rt; | ||
109 | char *box_str; | ||
110 | char *ival; | ||
111 | |||
112 | cdata = data; | ||
113 | if (data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord)) | ||
114 | return NULL; /* malformed */ | ||
115 | GNUNET_memcpy(&box, data, sizeof(box)); | ||
116 | rt = ntohl(box.record_type); | ||
117 | ival = GNUNET_GNSRECORD_value_to_string(rt, | ||
118 | &cdata[sizeof(box)], | ||
119 | data_size - sizeof(box)); | ||
120 | if (NULL == ival) | ||
121 | return NULL; /* malformed */ | ||
122 | GNUNET_asprintf(&box_str, | ||
123 | "%u %u %u %s", | ||
124 | (unsigned int)ntohs(box.protocol), | ||
125 | (unsigned int)ntohs(box.service), | ||
126 | (unsigned int)rt, | ||
127 | ival); | ||
128 | GNUNET_free(ival); | ||
129 | return box_str; | ||
130 | } | ||
131 | |||
132 | default: | ||
78 | return NULL; | 133 | return NULL; |
79 | } | 134 | } |
80 | GNUNET_asprintf (&nstr, "%s@%s", ns, ip); | ||
81 | GNUNET_free_non_null (ns); | ||
82 | GNUNET_free_non_null (ip); | ||
83 | return nstr; | ||
84 | } | ||
85 | case GNUNET_GNSRECORD_TYPE_VPN: { | ||
86 | struct GNUNET_TUN_GnsVpnRecord vpn; | ||
87 | char *vpn_str; | ||
88 | |||
89 | cdata = data; | ||
90 | if ((data_size <= sizeof (vpn)) || ('\0' != cdata[data_size - 1])) | ||
91 | return NULL; /* malformed */ | ||
92 | /* need to memcpy for alignment */ | ||
93 | GNUNET_memcpy (&vpn, data, sizeof (vpn)); | ||
94 | GNUNET_asprintf (&vpn_str, | ||
95 | "%u %s %s", | ||
96 | (unsigned int) ntohs (vpn.proto), | ||
97 | (const char *) GNUNET_i2s_full (&vpn.peer), | ||
98 | (const char *) &cdata[sizeof (vpn)]); | ||
99 | return vpn_str; | ||
100 | } | ||
101 | case GNUNET_GNSRECORD_TYPE_BOX: { | ||
102 | struct GNUNET_GNSRECORD_BoxRecord box; | ||
103 | uint32_t rt; | ||
104 | char *box_str; | ||
105 | char *ival; | ||
106 | |||
107 | cdata = data; | ||
108 | if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) | ||
109 | return NULL; /* malformed */ | ||
110 | GNUNET_memcpy (&box, data, sizeof (box)); | ||
111 | rt = ntohl (box.record_type); | ||
112 | ival = GNUNET_GNSRECORD_value_to_string (rt, | ||
113 | &cdata[sizeof (box)], | ||
114 | data_size - sizeof (box)); | ||
115 | if (NULL == ival) | ||
116 | return NULL; /* malformed */ | ||
117 | GNUNET_asprintf (&box_str, | ||
118 | "%u %u %u %s", | ||
119 | (unsigned int) ntohs (box.protocol), | ||
120 | (unsigned int) ntohs (box.service), | ||
121 | (unsigned int) rt, | ||
122 | ival); | ||
123 | GNUNET_free (ival); | ||
124 | return box_str; | ||
125 | } | ||
126 | default: | ||
127 | return NULL; | ||
128 | } | ||
129 | } | 135 | } |
130 | 136 | ||
131 | 137 | ||
@@ -141,142 +147,146 @@ gns_value_to_string (void *cls, | |||
141 | * @return #GNUNET_OK on success | 147 | * @return #GNUNET_OK on success |
142 | */ | 148 | */ |
143 | static int | 149 | static int |
144 | gns_string_to_value (void *cls, | 150 | gns_string_to_value(void *cls, |
145 | uint32_t type, | 151 | uint32_t type, |
146 | const char *s, | 152 | const char *s, |
147 | void **data, | 153 | void **data, |
148 | size_t *data_size) | 154 | size_t *data_size) |
149 | { | 155 | { |
150 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 156 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
151 | 157 | ||
152 | if (NULL == s) | 158 | if (NULL == s) |
153 | return GNUNET_SYSERR; | 159 | return GNUNET_SYSERR; |
154 | switch (type) | 160 | switch (type) |
155 | { | ||
156 | |||
157 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
158 | if (GNUNET_OK != | ||
159 | GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey)) | ||
160 | { | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
162 | _ ("Unable to parse PKEY record `%s'\n"), | ||
163 | s); | ||
164 | return GNUNET_SYSERR; | ||
165 | } | ||
166 | *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
167 | GNUNET_memcpy (*data, &pkey, sizeof (pkey)); | ||
168 | *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
169 | return GNUNET_OK; | ||
170 | |||
171 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
172 | *data = GNUNET_strdup (s); | ||
173 | *data_size = strlen (s); | ||
174 | return GNUNET_OK; | ||
175 | case GNUNET_GNSRECORD_TYPE_LEHO: | ||
176 | *data = GNUNET_strdup (s); | ||
177 | *data_size = strlen (s); | ||
178 | return GNUNET_OK; | ||
179 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: { | ||
180 | char nsbuf[514]; | ||
181 | char *cpy; | ||
182 | char *at; | ||
183 | size_t off; | ||
184 | |||
185 | cpy = GNUNET_strdup (s); | ||
186 | at = strchr (cpy, '@'); | ||
187 | if (NULL == at) | ||
188 | { | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
190 | _ ("Unable to parse GNS2DNS record `%s'\n"), | ||
191 | s); | ||
192 | GNUNET_free (cpy); | ||
193 | return GNUNET_SYSERR; | ||
194 | } | ||
195 | *at = '\0'; | ||
196 | at++; | ||
197 | |||
198 | off = 0; | ||
199 | if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf, | ||
200 | sizeof (nsbuf), | ||
201 | &off, | ||
202 | cpy)) || | ||
203 | (GNUNET_OK != | ||
204 | GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof (nsbuf), &off, at))) | ||
205 | { | 161 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 162 | case GNUNET_GNSRECORD_TYPE_PKEY: |
207 | _ ("Failed to serialize GNS2DNS record with value `%s'\n"), | 163 | if (GNUNET_OK != |
208 | s); | 164 | GNUNET_CRYPTO_ecdsa_public_key_from_string(s, strlen(s), &pkey)) |
209 | GNUNET_free (cpy); | 165 | { |
210 | return GNUNET_SYSERR; | 166 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
167 | _("Unable to parse PKEY record `%s'\n"), | ||
168 | s); | ||
169 | return GNUNET_SYSERR; | ||
170 | } | ||
171 | *data = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
172 | GNUNET_memcpy(*data, &pkey, sizeof(pkey)); | ||
173 | *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
174 | return GNUNET_OK; | ||
175 | |||
176 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
177 | *data = GNUNET_strdup(s); | ||
178 | *data_size = strlen(s); | ||
179 | return GNUNET_OK; | ||
180 | |||
181 | case GNUNET_GNSRECORD_TYPE_LEHO: | ||
182 | *data = GNUNET_strdup(s); | ||
183 | *data_size = strlen(s); | ||
184 | return GNUNET_OK; | ||
185 | |||
186 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: { | ||
187 | char nsbuf[514]; | ||
188 | char *cpy; | ||
189 | char *at; | ||
190 | size_t off; | ||
191 | |||
192 | cpy = GNUNET_strdup(s); | ||
193 | at = strchr(cpy, '@'); | ||
194 | if (NULL == at) | ||
195 | { | ||
196 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
197 | _("Unable to parse GNS2DNS record `%s'\n"), | ||
198 | s); | ||
199 | GNUNET_free(cpy); | ||
200 | return GNUNET_SYSERR; | ||
201 | } | ||
202 | *at = '\0'; | ||
203 | at++; | ||
204 | |||
205 | off = 0; | ||
206 | if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name(nsbuf, | ||
207 | sizeof(nsbuf), | ||
208 | &off, | ||
209 | cpy)) || | ||
210 | (GNUNET_OK != | ||
211 | GNUNET_DNSPARSER_builder_add_name(nsbuf, sizeof(nsbuf), &off, at))) | ||
212 | { | ||
213 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
214 | _("Failed to serialize GNS2DNS record with value `%s'\n"), | ||
215 | s); | ||
216 | GNUNET_free(cpy); | ||
217 | return GNUNET_SYSERR; | ||
218 | } | ||
219 | GNUNET_free(cpy); | ||
220 | *data_size = off; | ||
221 | *data = GNUNET_malloc(off); | ||
222 | GNUNET_memcpy(*data, nsbuf, off); | ||
223 | return GNUNET_OK; | ||
211 | } | 224 | } |
212 | GNUNET_free (cpy); | 225 | |
213 | *data_size = off; | 226 | case GNUNET_GNSRECORD_TYPE_VPN: { |
214 | *data = GNUNET_malloc (off); | 227 | struct GNUNET_TUN_GnsVpnRecord *vpn; |
215 | GNUNET_memcpy (*data, nsbuf, off); | 228 | char s_peer[103 + 1]; |
216 | return GNUNET_OK; | 229 | char s_serv[253 + 1]; |
217 | } | 230 | unsigned int proto; |
218 | case GNUNET_GNSRECORD_TYPE_VPN: { | 231 | |
219 | struct GNUNET_TUN_GnsVpnRecord *vpn; | 232 | if (3 != sscanf(s, "%u %103s %253s", &proto, s_peer, s_serv)) |
220 | char s_peer[103 + 1]; | 233 | { |
221 | char s_serv[253 + 1]; | 234 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
222 | unsigned int proto; | 235 | _("Unable to parse VPN record string `%s'\n"), |
223 | 236 | s); | |
224 | if (3 != sscanf (s, "%u %103s %253s", &proto, s_peer, s_serv)) | 237 | return GNUNET_SYSERR; |
225 | { | 238 | } |
226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 239 | *data_size = sizeof(struct GNUNET_TUN_GnsVpnRecord) + strlen(s_serv) + 1; |
227 | _ ("Unable to parse VPN record string `%s'\n"), | 240 | *data = vpn = GNUNET_malloc(*data_size); |
228 | s); | 241 | if (GNUNET_OK != |
229 | return GNUNET_SYSERR; | 242 | GNUNET_CRYPTO_eddsa_public_key_from_string((char *)s_peer, |
243 | strlen(s_peer), | ||
244 | &vpn->peer.public_key)) | ||
245 | { | ||
246 | GNUNET_free(vpn); | ||
247 | *data_size = 0; | ||
248 | return GNUNET_SYSERR; | ||
249 | } | ||
250 | vpn->proto = htons((uint16_t)proto); | ||
251 | strcpy((char *)&vpn[1], s_serv); | ||
252 | return GNUNET_OK; | ||
230 | } | 253 | } |
231 | *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1; | 254 | |
232 | *data = vpn = GNUNET_malloc (*data_size); | 255 | case GNUNET_GNSRECORD_TYPE_BOX: { |
233 | if (GNUNET_OK != | 256 | struct GNUNET_GNSRECORD_BoxRecord *box; |
234 | GNUNET_CRYPTO_eddsa_public_key_from_string ((char *) s_peer, | 257 | size_t rest; |
235 | strlen (s_peer), | 258 | unsigned int protocol; |
236 | &vpn->peer.public_key)) | 259 | unsigned int service; |
237 | { | 260 | unsigned int record_type; |
238 | GNUNET_free (vpn); | 261 | void *bval; |
239 | *data_size = 0; | 262 | size_t bval_size; |
240 | return GNUNET_SYSERR; | 263 | |
264 | if (3 != sscanf(s, "%u %u %u ", &protocol, &service, &record_type)) | ||
265 | { | ||
266 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
267 | _("Unable to parse BOX record string `%s'\n"), | ||
268 | s); | ||
269 | return GNUNET_SYSERR; | ||
270 | } | ||
271 | rest = snprintf(NULL, 0, "%u %u %u ", protocol, service, record_type); | ||
272 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value(record_type, | ||
273 | &s[rest], | ||
274 | &bval, | ||
275 | &bval_size)) | ||
276 | return GNUNET_SYSERR; | ||
277 | *data_size = sizeof(struct GNUNET_GNSRECORD_BoxRecord) + bval_size; | ||
278 | *data = box = GNUNET_malloc(*data_size); | ||
279 | box->protocol = htons(protocol); | ||
280 | box->service = htons(service); | ||
281 | box->record_type = htonl(record_type); | ||
282 | GNUNET_memcpy(&box[1], bval, bval_size); | ||
283 | GNUNET_free(bval); | ||
284 | return GNUNET_OK; | ||
241 | } | 285 | } |
242 | vpn->proto = htons ((uint16_t) proto); | 286 | |
243 | strcpy ((char *) &vpn[1], s_serv); | 287 | default: |
244 | return GNUNET_OK; | ||
245 | } | ||
246 | case GNUNET_GNSRECORD_TYPE_BOX: { | ||
247 | struct GNUNET_GNSRECORD_BoxRecord *box; | ||
248 | size_t rest; | ||
249 | unsigned int protocol; | ||
250 | unsigned int service; | ||
251 | unsigned int record_type; | ||
252 | void *bval; | ||
253 | size_t bval_size; | ||
254 | |||
255 | if (3 != sscanf (s, "%u %u %u ", &protocol, &service, &record_type)) | ||
256 | { | ||
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
258 | _ ("Unable to parse BOX record string `%s'\n"), | ||
259 | s); | ||
260 | return GNUNET_SYSERR; | 288 | return GNUNET_SYSERR; |
261 | } | 289 | } |
262 | rest = snprintf (NULL, 0, "%u %u %u ", protocol, service, record_type); | ||
263 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record_type, | ||
264 | &s[rest], | ||
265 | &bval, | ||
266 | &bval_size)) | ||
267 | return GNUNET_SYSERR; | ||
268 | *data_size = sizeof (struct GNUNET_GNSRECORD_BoxRecord) + bval_size; | ||
269 | *data = box = GNUNET_malloc (*data_size); | ||
270 | box->protocol = htons (protocol); | ||
271 | box->service = htons (service); | ||
272 | box->record_type = htonl (record_type); | ||
273 | GNUNET_memcpy (&box[1], bval, bval_size); | ||
274 | GNUNET_free (bval); | ||
275 | return GNUNET_OK; | ||
276 | } | ||
277 | default: | ||
278 | return GNUNET_SYSERR; | ||
279 | } | ||
280 | } | 290 | } |
281 | 291 | ||
282 | 292 | ||
@@ -284,17 +294,16 @@ gns_string_to_value (void *cls, | |||
284 | * Mapping of record type numbers to human-readable | 294 | * Mapping of record type numbers to human-readable |
285 | * record type names. | 295 | * record type names. |
286 | */ | 296 | */ |
287 | static struct | 297 | static struct { |
288 | { | ||
289 | const char *name; | 298 | const char *name; |
290 | uint32_t number; | 299 | uint32_t number; |
291 | } gns_name_map[] = {{"PKEY", GNUNET_GNSRECORD_TYPE_PKEY}, | 300 | } gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, |
292 | {"NICK", GNUNET_GNSRECORD_TYPE_NICK}, | 301 | { "NICK", GNUNET_GNSRECORD_TYPE_NICK }, |
293 | {"LEHO", GNUNET_GNSRECORD_TYPE_LEHO}, | 302 | { "LEHO", GNUNET_GNSRECORD_TYPE_LEHO }, |
294 | {"VPN", GNUNET_GNSRECORD_TYPE_VPN}, | 303 | { "VPN", GNUNET_GNSRECORD_TYPE_VPN }, |
295 | {"GNS2DNS", GNUNET_GNSRECORD_TYPE_GNS2DNS}, | 304 | { "GNS2DNS", GNUNET_GNSRECORD_TYPE_GNS2DNS }, |
296 | {"BOX", GNUNET_GNSRECORD_TYPE_BOX}, | 305 | { "BOX", GNUNET_GNSRECORD_TYPE_BOX }, |
297 | {NULL, UINT32_MAX}}; | 306 | { NULL, UINT32_MAX } }; |
298 | 307 | ||
299 | 308 | ||
300 | /** | 309 | /** |
@@ -305,13 +314,13 @@ static struct | |||
305 | * @return corresponding number, UINT32_MAX on error | 314 | * @return corresponding number, UINT32_MAX on error |
306 | */ | 315 | */ |
307 | static uint32_t | 316 | static uint32_t |
308 | gns_typename_to_number (void *cls, const char *gns_typename) | 317 | gns_typename_to_number(void *cls, const char *gns_typename) |
309 | { | 318 | { |
310 | unsigned int i; | 319 | unsigned int i; |
311 | 320 | ||
312 | i = 0; | 321 | i = 0; |
313 | while ((NULL != gns_name_map[i].name) && | 322 | while ((NULL != gns_name_map[i].name) && |
314 | (0 != strcasecmp (gns_typename, gns_name_map[i].name))) | 323 | (0 != strcasecmp(gns_typename, gns_name_map[i].name))) |
315 | i++; | 324 | i++; |
316 | return gns_name_map[i].number; | 325 | return gns_name_map[i].number; |
317 | } | 326 | } |
@@ -325,7 +334,7 @@ gns_typename_to_number (void *cls, const char *gns_typename) | |||
325 | * @return corresponding typestring, NULL on error | 334 | * @return corresponding typestring, NULL on error |
326 | */ | 335 | */ |
327 | static const char * | 336 | static const char * |
328 | gns_number_to_typename (void *cls, uint32_t type) | 337 | gns_number_to_typename(void *cls, uint32_t type) |
329 | { | 338 | { |
330 | unsigned int i; | 339 | unsigned int i; |
331 | 340 | ||
@@ -343,11 +352,11 @@ gns_number_to_typename (void *cls, uint32_t type) | |||
343 | * @return the exported block API | 352 | * @return the exported block API |
344 | */ | 353 | */ |
345 | void * | 354 | void * |
346 | libgnunet_plugin_gnsrecord_gns_init (void *cls) | 355 | libgnunet_plugin_gnsrecord_gns_init(void *cls) |
347 | { | 356 | { |
348 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 357 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
349 | 358 | ||
350 | api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); | 359 | api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); |
351 | api->value_to_string = &gns_value_to_string; | 360 | api->value_to_string = &gns_value_to_string; |
352 | api->string_to_value = &gns_string_to_value; | 361 | api->string_to_value = &gns_string_to_value; |
353 | api->typename_to_number = &gns_typename_to_number; | 362 | api->typename_to_number = &gns_typename_to_number; |
@@ -363,11 +372,11 @@ libgnunet_plugin_gnsrecord_gns_init (void *cls) | |||
363 | * @return NULL | 372 | * @return NULL |
364 | */ | 373 | */ |
365 | void * | 374 | void * |
366 | libgnunet_plugin_gnsrecord_gns_done (void *cls) | 375 | libgnunet_plugin_gnsrecord_gns_done(void *cls) |
367 | { | 376 | { |
368 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 377 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
369 | 378 | ||
370 | GNUNET_free (api); | 379 | GNUNET_free(api); |
371 | return NULL; | 380 | return NULL; |
372 | } | 381 | } |
373 | 382 | ||
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c index 1ecde12f0..2fc103ef6 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/gns/plugin_rest_gns.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Philippe Buschmann | 21 | * @author Philippe Buschmann |
22 | * @file gns/plugin_rest_gns.c | 22 | * @file gns/plugin_rest_gns.c |
@@ -65,17 +65,14 @@ 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 | */ |
68 | struct Plugin | 68 | struct Plugin { |
69 | { | ||
70 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 69 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
71 | }; | 70 | }; |
72 | 71 | ||
73 | /** | 72 | /** |
74 | * The request handle | 73 | * The request handle |
75 | */ | 74 | */ |
76 | struct RequestHandle | 75 | struct RequestHandle { |
77 | { | ||
78 | |||
79 | /** | 76 | /** |
80 | * Connection to GNS | 77 | * Connection to GNS |
81 | */ | 78 | */ |
@@ -143,35 +140,36 @@ struct RequestHandle | |||
143 | * @param handle Handle to clean up | 140 | * @param handle Handle to clean up |
144 | */ | 141 | */ |
145 | static void | 142 | static void |
146 | cleanup_handle (void *cls) | 143 | cleanup_handle(void *cls) |
147 | { | 144 | { |
148 | struct RequestHandle *handle = cls; | 145 | struct RequestHandle *handle = cls; |
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 146 | |
147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | ||
150 | 148 | ||
151 | if (NULL != handle->gns_lookup) | 149 | if (NULL != handle->gns_lookup) |
152 | { | 150 | { |
153 | GNUNET_GNS_lookup_with_tld_cancel (handle->gns_lookup); | 151 | GNUNET_GNS_lookup_with_tld_cancel(handle->gns_lookup); |
154 | handle->gns_lookup = NULL; | 152 | handle->gns_lookup = NULL; |
155 | } | 153 | } |
156 | if (NULL != handle->gns) | 154 | if (NULL != handle->gns) |
157 | { | 155 | { |
158 | GNUNET_GNS_disconnect (handle->gns); | 156 | GNUNET_GNS_disconnect(handle->gns); |
159 | handle->gns = NULL; | 157 | handle->gns = NULL; |
160 | } | 158 | } |
161 | 159 | ||
162 | if (NULL != handle->timeout_task) | 160 | if (NULL != handle->timeout_task) |
163 | { | 161 | { |
164 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 162 | GNUNET_SCHEDULER_cancel(handle->timeout_task); |
165 | handle->timeout_task = NULL; | 163 | handle->timeout_task = NULL; |
166 | } | 164 | } |
167 | if (NULL != handle->url) | 165 | if (NULL != handle->url) |
168 | GNUNET_free (handle->url); | 166 | GNUNET_free(handle->url); |
169 | if (NULL != handle->name) | 167 | if (NULL != handle->name) |
170 | GNUNET_free (handle->name); | 168 | GNUNET_free(handle->name); |
171 | if (NULL != handle->emsg) | 169 | if (NULL != handle->emsg) |
172 | GNUNET_free (handle->emsg); | 170 | GNUNET_free(handle->emsg); |
173 | 171 | ||
174 | GNUNET_free (handle); | 172 | GNUNET_free(handle); |
175 | } | 173 | } |
176 | 174 | ||
177 | 175 | ||
@@ -181,39 +179,40 @@ cleanup_handle (void *cls) | |||
181 | * @param cls the `struct RequestHandle` | 179 | * @param cls the `struct RequestHandle` |
182 | */ | 180 | */ |
183 | static void | 181 | static void |
184 | do_error (void *cls) | 182 | do_error(void *cls) |
185 | { | 183 | { |
186 | struct RequestHandle *handle = cls; | 184 | struct RequestHandle *handle = cls; |
187 | struct MHD_Response *resp; | 185 | struct MHD_Response *resp; |
188 | json_t *json_error = json_object (); | 186 | json_t *json_error = json_object(); |
189 | char *response; | 187 | char *response; |
190 | 188 | ||
191 | if (NULL != handle->timeout_task) | 189 | if (NULL != handle->timeout_task) |
192 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 190 | GNUNET_SCHEDULER_cancel(handle->timeout_task); |
193 | handle->timeout_task = NULL; | 191 | handle->timeout_task = NULL; |
194 | if (NULL == handle->emsg) | 192 | if (NULL == handle->emsg) |
195 | handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_ERROR_UNKNOWN); | 193 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_ERROR_UNKNOWN); |
196 | 194 | ||
197 | json_object_set_new (json_error, "error", json_string (handle->emsg)); | 195 | json_object_set_new(json_error, "error", json_string(handle->emsg)); |
198 | 196 | ||
199 | if (0 == handle->response_code) | 197 | if (0 == handle->response_code) |
200 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 198 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
201 | response = json_dumps (json_error, 0); | 199 | response = json_dumps(json_error, 0); |
202 | resp = GNUNET_REST_create_response (response); | 200 | resp = GNUNET_REST_create_response(response); |
203 | handle->proc (handle->proc_cls, resp, handle->response_code); | 201 | handle->proc(handle->proc_cls, resp, handle->response_code); |
204 | json_decref (json_error); | 202 | json_decref(json_error); |
205 | GNUNET_free (response); | 203 | GNUNET_free(response); |
206 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 204 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
207 | } | 205 | } |
208 | 206 | ||
209 | 207 | ||
210 | static void | 208 | static void |
211 | do_timeout (void *cls) | 209 | do_timeout(void *cls) |
212 | { | 210 | { |
213 | struct RequestHandle *handle = cls; | 211 | struct RequestHandle *handle = cls; |
212 | |||
214 | handle->timeout_task = NULL; | 213 | handle->timeout_task = NULL; |
215 | handle->response_code = MHD_HTTP_REQUEST_TIMEOUT; | 214 | handle->response_code = MHD_HTTP_REQUEST_TIMEOUT; |
216 | do_error (handle); | 215 | do_error(handle); |
217 | } | 216 | } |
218 | 217 | ||
219 | 218 | ||
@@ -226,10 +225,10 @@ do_timeout (void *cls) | |||
226 | * @param rd the records in reply | 225 | * @param rd the records in reply |
227 | */ | 226 | */ |
228 | static void | 227 | static void |
229 | handle_gns_response (void *cls, | 228 | handle_gns_response(void *cls, |
230 | int was_gns, | 229 | int was_gns, |
231 | uint32_t rd_count, | 230 | uint32_t rd_count, |
232 | const struct GNUNET_GNSRECORD_Data *rd) | 231 | const struct GNUNET_GNSRECORD_Data *rd) |
233 | { | 232 | { |
234 | struct RequestHandle *handle = cls; | 233 | struct RequestHandle *handle = cls; |
235 | struct MHD_Response *resp; | 234 | struct MHD_Response *resp; |
@@ -239,22 +238,22 @@ handle_gns_response (void *cls, | |||
239 | handle->gns_lookup = NULL; | 238 | handle->gns_lookup = NULL; |
240 | 239 | ||
241 | if (GNUNET_NO == was_gns) | 240 | if (GNUNET_NO == was_gns) |
242 | { | 241 | { |
243 | handle->response_code = MHD_HTTP_NOT_FOUND; | 242 | handle->response_code = MHD_HTTP_NOT_FOUND; |
244 | handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_NOT_FOUND); | 243 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); |
245 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 244 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
246 | return; | 245 | return; |
247 | } | 246 | } |
248 | 247 | ||
249 | result_obj = GNUNET_JSON_from_gnsrecord (handle->name, rd, rd_count); | 248 | result_obj = GNUNET_JSON_from_gnsrecord(handle->name, rd, rd_count); |
250 | 249 | ||
251 | result = json_dumps (result_obj, 0); | 250 | result = json_dumps(result_obj, 0); |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); | 251 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); |
253 | resp = GNUNET_REST_create_response (result); | 252 | resp = GNUNET_REST_create_response(result); |
254 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 253 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
255 | GNUNET_free (result); | 254 | GNUNET_free(result); |
256 | json_decref (result_obj); | 255 | json_decref(result_obj); |
257 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 256 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
258 | } | 257 | } |
259 | 258 | ||
260 | 259 | ||
@@ -266,9 +265,9 @@ handle_gns_response (void *cls, | |||
266 | * @param cls the RequestHandle | 265 | * @param cls the RequestHandle |
267 | */ | 266 | */ |
268 | void | 267 | void |
269 | get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, | 268 | get_gns_cont(struct GNUNET_REST_RequestHandle *con_handle, |
270 | const char *url, | 269 | const char *url, |
271 | void *cls) | 270 | void *cls) |
272 | { | 271 | { |
273 | struct RequestHandle *handle = cls; | 272 | struct RequestHandle *handle = cls; |
274 | struct GNUNET_HashCode key; | 273 | struct GNUNET_HashCode key; |
@@ -277,50 +276,50 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
277 | 276 | ||
278 | name = NULL; | 277 | name = NULL; |
279 | handle->name = NULL; | 278 | handle->name = NULL; |
280 | if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url)) | 279 | if (strlen(GNUNET_REST_API_NS_GNS) < strlen(handle->url)) |
281 | { | 280 | { |
282 | name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1]; | 281 | name = &handle->url[strlen(GNUNET_REST_API_NS_GNS) + 1]; |
283 | } | 282 | } |
284 | 283 | ||
285 | if (NULL == name) | 284 | if (NULL == name) |
286 | { | 285 | { |
287 | handle->response_code = MHD_HTTP_NOT_FOUND; | 286 | handle->response_code = MHD_HTTP_NOT_FOUND; |
288 | handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_NOT_FOUND); | 287 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); |
289 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 288 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
290 | return; | 289 | return; |
291 | } | 290 | } |
292 | if (0 >= strlen (name)) | 291 | if (0 >= strlen(name)) |
293 | { | 292 | { |
294 | handle->response_code = MHD_HTTP_NOT_FOUND; | 293 | handle->response_code = MHD_HTTP_NOT_FOUND; |
295 | handle->emsg = GNUNET_strdup (GNUNET_REST_GNS_NOT_FOUND); | 294 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); |
296 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 295 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
297 | return; | 296 | return; |
298 | } | 297 | } |
299 | handle->name = GNUNET_strdup (name); | 298 | handle->name = GNUNET_strdup(name); |
300 | 299 | ||
301 | handle->record_type = UINT32_MAX; | 300 | handle->record_type = UINT32_MAX; |
302 | GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_RECORD_TYPE, | 301 | GNUNET_CRYPTO_hash(GNUNET_REST_GNS_PARAM_RECORD_TYPE, |
303 | strlen (GNUNET_REST_GNS_PARAM_RECORD_TYPE), | 302 | strlen(GNUNET_REST_GNS_PARAM_RECORD_TYPE), |
304 | &key); | 303 | &key); |
305 | if (GNUNET_YES == | 304 | if (GNUNET_YES == |
306 | GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key)) | 305 | GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, &key)) |
307 | { | 306 | { |
308 | record_type = | 307 | record_type = |
309 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); | 308 | GNUNET_CONTAINER_multihashmap_get(con_handle->url_param_map, &key); |
310 | handle->record_type = GNUNET_GNSRECORD_typename_to_number (record_type); | 309 | handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); |
311 | } | 310 | } |
312 | 311 | ||
313 | if (UINT32_MAX == handle->record_type) | 312 | if (UINT32_MAX == handle->record_type) |
314 | { | 313 | { |
315 | handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; | 314 | handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
316 | } | 315 | } |
317 | 316 | ||
318 | handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, | 317 | handle->gns_lookup = GNUNET_GNS_lookup_with_tld(handle->gns, |
319 | handle->name, | 318 | handle->name, |
320 | handle->record_type, | 319 | handle->record_type, |
321 | GNUNET_NO, | 320 | GNUNET_NO, |
322 | &handle_gns_response, | 321 | &handle_gns_response, |
323 | handle); | 322 | handle); |
324 | } | 323 | } |
325 | 324 | ||
326 | 325 | ||
@@ -332,18 +331,18 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
332 | * @param cls the RequestHandle | 331 | * @param cls the RequestHandle |
333 | */ | 332 | */ |
334 | static void | 333 | static void |
335 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | 334 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, |
336 | const char *url, | 335 | const char *url, |
337 | void *cls) | 336 | void *cls) |
338 | { | 337 | { |
339 | struct MHD_Response *resp; | 338 | struct MHD_Response *resp; |
340 | struct RequestHandle *handle = cls; | 339 | struct RequestHandle *handle = cls; |
341 | 340 | ||
342 | //independent of path return all options | 341 | //independent of path return all options |
343 | resp = GNUNET_REST_create_response (NULL); | 342 | resp = GNUNET_REST_create_response(NULL); |
344 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | 343 | MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); |
345 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 344 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
346 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 345 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
347 | return; | 346 | return; |
348 | } | 347 | } |
349 | 348 | ||
@@ -354,20 +353,20 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
354 | * @param handle the request handle | 353 | * @param handle the request handle |
355 | */ | 354 | */ |
356 | static void | 355 | static void |
357 | init_cont (struct RequestHandle *handle) | 356 | init_cont(struct RequestHandle *handle) |
358 | { | 357 | { |
359 | struct GNUNET_REST_RequestHandlerError err; | 358 | struct GNUNET_REST_RequestHandlerError err; |
360 | static const struct GNUNET_REST_RequestHandler handlers[] = | 359 | static const struct GNUNET_REST_RequestHandler handlers[] = |
361 | {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont}, | 360 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont }, |
362 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont}, | 361 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont }, |
363 | GNUNET_REST_HANDLER_END}; | 362 | GNUNET_REST_HANDLER_END }; |
364 | 363 | ||
365 | if (GNUNET_NO == | 364 | if (GNUNET_NO == |
366 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 365 | GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) |
367 | { | 366 | { |
368 | handle->response_code = err.error_code; | 367 | handle->response_code = err.error_code; |
369 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 368 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
370 | } | 369 | } |
371 | } | 370 | } |
372 | 371 | ||
373 | 372 | ||
@@ -383,30 +382,30 @@ init_cont (struct RequestHandle *handle) | |||
383 | * @return GNUNET_OK if request accepted | 382 | * @return GNUNET_OK if request accepted |
384 | */ | 383 | */ |
385 | static void | 384 | static void |
386 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 385 | rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, |
387 | GNUNET_REST_ResultProcessor proc, | 386 | GNUNET_REST_ResultProcessor proc, |
388 | void *proc_cls) | 387 | void *proc_cls) |
389 | { | 388 | { |
390 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 389 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); |
391 | 390 | ||
392 | handle->response_code = 0; | 391 | handle->response_code = 0; |
393 | handle->timeout = | 392 | handle->timeout = |
394 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60); | 393 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60); |
395 | handle->proc_cls = proc_cls; | 394 | handle->proc_cls = proc_cls; |
396 | handle->proc = proc; | 395 | handle->proc = proc; |
397 | handle->rest_handle = rest_handle; | 396 | handle->rest_handle = rest_handle; |
398 | 397 | ||
399 | handle->url = GNUNET_strdup (rest_handle->url); | 398 | handle->url = GNUNET_strdup(rest_handle->url); |
400 | if (handle->url[strlen (handle->url) - 1] == '/') | 399 | if (handle->url[strlen(handle->url) - 1] == '/') |
401 | handle->url[strlen (handle->url) - 1] = '\0'; | 400 | handle->url[strlen(handle->url) - 1] = '\0'; |
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 401 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
403 | handle->gns = GNUNET_GNS_connect (cfg); | 402 | handle->gns = GNUNET_GNS_connect(cfg); |
404 | init_cont (handle); | 403 | init_cont(handle); |
405 | 404 | ||
406 | handle->timeout_task = | 405 | handle->timeout_task = |
407 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | 406 | GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_timeout, handle); |
408 | 407 | ||
409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 408 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
410 | } | 409 | } |
411 | 410 | ||
412 | 411 | ||
@@ -417,7 +416,7 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
417 | * @return NULL on error, otherwise the plugin context | 416 | * @return NULL on error, otherwise the plugin context |
418 | */ | 417 | */ |
419 | void * | 418 | void * |
420 | libgnunet_plugin_rest_gns_init (void *cls) | 419 | libgnunet_plugin_rest_gns_init(void *cls) |
421 | { | 420 | { |
422 | static struct Plugin plugin; | 421 | static struct Plugin plugin; |
423 | struct GNUNET_REST_Plugin *api; | 422 | struct GNUNET_REST_Plugin *api; |
@@ -425,21 +424,21 @@ libgnunet_plugin_rest_gns_init (void *cls) | |||
425 | cfg = cls; | 424 | cfg = cls; |
426 | if (NULL != plugin.cfg) | 425 | if (NULL != plugin.cfg) |
427 | return NULL; /* can only initialize once! */ | 426 | return NULL; /* can only initialize once! */ |
428 | memset (&plugin, 0, sizeof (struct Plugin)); | 427 | memset(&plugin, 0, sizeof(struct Plugin)); |
429 | plugin.cfg = cfg; | 428 | plugin.cfg = cfg; |
430 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 429 | api = GNUNET_new(struct GNUNET_REST_Plugin); |
431 | api->cls = &plugin; | 430 | api->cls = &plugin; |
432 | api->name = GNUNET_REST_API_NS_GNS; | 431 | api->name = GNUNET_REST_API_NS_GNS; |
433 | api->process_request = &rest_process_request; | 432 | api->process_request = &rest_process_request; |
434 | GNUNET_asprintf (&allow_methods, | 433 | GNUNET_asprintf(&allow_methods, |
435 | "%s, %s, %s, %s, %s", | 434 | "%s, %s, %s, %s, %s", |
436 | MHD_HTTP_METHOD_GET, | 435 | MHD_HTTP_METHOD_GET, |
437 | MHD_HTTP_METHOD_POST, | 436 | MHD_HTTP_METHOD_POST, |
438 | MHD_HTTP_METHOD_PUT, | 437 | MHD_HTTP_METHOD_PUT, |
439 | MHD_HTTP_METHOD_DELETE, | 438 | MHD_HTTP_METHOD_DELETE, |
440 | MHD_HTTP_METHOD_OPTIONS); | 439 | MHD_HTTP_METHOD_OPTIONS); |
441 | 440 | ||
442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n")); | 441 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Gns REST API initialized\n")); |
443 | return api; | 442 | return api; |
444 | } | 443 | } |
445 | 444 | ||
@@ -451,15 +450,16 @@ libgnunet_plugin_rest_gns_init (void *cls) | |||
451 | * @return always NULL | 450 | * @return always NULL |
452 | */ | 451 | */ |
453 | void * | 452 | void * |
454 | libgnunet_plugin_rest_gns_done (void *cls) | 453 | libgnunet_plugin_rest_gns_done(void *cls) |
455 | { | 454 | { |
456 | struct GNUNET_REST_Plugin *api = cls; | 455 | struct GNUNET_REST_Plugin *api = cls; |
457 | struct Plugin *plugin = api->cls; | 456 | struct Plugin *plugin = api->cls; |
457 | |||
458 | plugin->cfg = NULL; | 458 | plugin->cfg = NULL; |
459 | 459 | ||
460 | GNUNET_free_non_null (allow_methods); | 460 | GNUNET_free_non_null(allow_methods); |
461 | GNUNET_free (api); | 461 | GNUNET_free(api); |
462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Gns REST plugin is finished\n"); | 462 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Gns REST plugin is finished\n"); |
463 | return NULL; | 463 | return NULL; |
464 | } | 464 | } |
465 | 465 | ||
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c index 053f5f898..2df422731 100644 --- a/src/gns/test_gns_proxy.c +++ b/src/gns/test_gns_proxy.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file test_gns_proxy.c | 22 | * @file 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'. |
@@ -69,8 +69,7 @@ static gnutls_x509_crt_t proxy_cert; | |||
69 | 69 | ||
70 | static gnutls_x509_privkey_t proxy_key; | 70 | static gnutls_x509_privkey_t proxy_key; |
71 | 71 | ||
72 | struct CBC | 72 | struct CBC { |
73 | { | ||
74 | char buf[1024]; | 73 | char buf[1024]; |
75 | size_t pos; | 74 | size_t pos; |
76 | }; | 75 | }; |
@@ -85,30 +84,30 @@ static struct CBC cbc; | |||
85 | * @return NULL on error | 84 | * @return NULL on error |
86 | */ | 85 | */ |
87 | static void* | 86 | static void* |
88 | load_file (const char* filename, | 87 | load_file(const char* filename, |
89 | unsigned int* size) | 88 | unsigned int* size) |
90 | { | 89 | { |
91 | void *buffer; | 90 | void *buffer; |
92 | uint64_t fsize; | 91 | uint64_t fsize; |
93 | 92 | ||
94 | if (GNUNET_OK != | 93 | if (GNUNET_OK != |
95 | GNUNET_DISK_file_size (filename, | 94 | GNUNET_DISK_file_size(filename, |
96 | &fsize, | 95 | &fsize, |
97 | GNUNET_YES, | 96 | GNUNET_YES, |
98 | GNUNET_YES)) | 97 | GNUNET_YES)) |
99 | return NULL; | 98 | return NULL; |
100 | if (fsize > MAX_PEM_SIZE) | 99 | if (fsize > MAX_PEM_SIZE) |
101 | return NULL; | 100 | return NULL; |
102 | *size = (unsigned int) fsize; | 101 | *size = (unsigned int)fsize; |
103 | buffer = GNUNET_malloc (*size); | 102 | buffer = GNUNET_malloc(*size); |
104 | if (fsize != | 103 | if (fsize != |
105 | GNUNET_DISK_fn_read (filename, | 104 | GNUNET_DISK_fn_read(filename, |
106 | buffer, | 105 | buffer, |
107 | (size_t) fsize)) | 106 | (size_t)fsize)) |
108 | { | 107 | { |
109 | GNUNET_free (buffer); | 108 | GNUNET_free(buffer); |
110 | return NULL; | 109 | return NULL; |
111 | } | 110 | } |
112 | return buffer; | 111 | return buffer; |
113 | } | 112 | } |
114 | 113 | ||
@@ -120,25 +119,25 @@ load_file (const char* filename, | |||
120 | * @return #GNUNET_OK on success | 119 | * @return #GNUNET_OK on success |
121 | */ | 120 | */ |
122 | static int | 121 | static int |
123 | load_key_from_file (gnutls_x509_privkey_t key, | 122 | load_key_from_file(gnutls_x509_privkey_t key, |
124 | const char* keyfile) | 123 | const char* keyfile) |
125 | { | 124 | { |
126 | gnutls_datum_t key_data; | 125 | gnutls_datum_t key_data; |
127 | int ret; | 126 | int ret; |
128 | 127 | ||
129 | key_data.data = load_file (keyfile, | 128 | key_data.data = load_file(keyfile, |
130 | &key_data.size); | 129 | &key_data.size); |
131 | if (NULL == key_data.data) | 130 | if (NULL == key_data.data) |
132 | return GNUNET_SYSERR; | 131 | return GNUNET_SYSERR; |
133 | ret = gnutls_x509_privkey_import (key, &key_data, | 132 | ret = gnutls_x509_privkey_import(key, &key_data, |
134 | GNUTLS_X509_FMT_PEM); | 133 | GNUTLS_X509_FMT_PEM); |
135 | if (GNUTLS_E_SUCCESS != ret) | 134 | if (GNUTLS_E_SUCCESS != ret) |
136 | { | 135 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 136 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
138 | _("Unable to import private key from file `%s'\n"), | 137 | _("Unable to import private key from file `%s'\n"), |
139 | keyfile); | 138 | keyfile); |
140 | } | 139 | } |
141 | GNUNET_free_non_null (key_data.data); | 140 | GNUNET_free_non_null(key_data.data); |
142 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 141 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
143 | } | 142 | } |
144 | 143 | ||
@@ -150,107 +149,108 @@ load_key_from_file (gnutls_x509_privkey_t key, | |||
150 | * @return #GNUNET_OK on success | 149 | * @return #GNUNET_OK on success |
151 | */ | 150 | */ |
152 | static int | 151 | static int |
153 | load_cert_from_file (gnutls_x509_crt_t crt, | 152 | load_cert_from_file(gnutls_x509_crt_t crt, |
154 | const char* certfile) | 153 | const char* certfile) |
155 | { | 154 | { |
156 | gnutls_datum_t cert_data; | 155 | gnutls_datum_t cert_data; |
157 | int ret; | 156 | int ret; |
158 | 157 | ||
159 | cert_data.data = load_file (certfile, | 158 | cert_data.data = load_file(certfile, |
160 | &cert_data.size); | 159 | &cert_data.size); |
161 | if (NULL == cert_data.data) | 160 | if (NULL == cert_data.data) |
162 | return GNUNET_SYSERR; | 161 | return GNUNET_SYSERR; |
163 | ret = gnutls_x509_crt_import (crt, | 162 | ret = gnutls_x509_crt_import(crt, |
164 | &cert_data, | 163 | &cert_data, |
165 | GNUTLS_X509_FMT_PEM); | 164 | GNUTLS_X509_FMT_PEM); |
166 | if (GNUTLS_E_SUCCESS != ret) | 165 | if (GNUTLS_E_SUCCESS != ret) |
167 | { | 166 | { |
168 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 167 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
169 | _("Unable to import certificate from `%s'\n"), | 168 | _("Unable to import certificate from `%s'\n"), |
170 | certfile); | 169 | certfile); |
171 | } | 170 | } |
172 | GNUNET_free_non_null (cert_data.data); | 171 | GNUNET_free_non_null(cert_data.data); |
173 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; | 172 | return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; |
174 | } | 173 | } |
175 | 174 | ||
176 | static size_t | 175 | static size_t |
177 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 176 | copy_buffer(void *ptr, size_t size, size_t nmemb, void *ctx) |
178 | { | 177 | { |
179 | struct CBC *cbc = ctx; | 178 | struct CBC *cbc = ctx; |
180 | 179 | ||
181 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) | 180 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) |
182 | return 0; /* overflow */ | 181 | return 0; /* overflow */ |
183 | GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | 182 | GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb); |
184 | cbc->pos += size * nmemb; | 183 | cbc->pos += size * nmemb; |
185 | return size * nmemb; | 184 | return size * nmemb; |
186 | } | 185 | } |
187 | 186 | ||
188 | 187 | ||
189 | static int | 188 | static int |
190 | mhd_ahc (void *cls, | 189 | mhd_ahc(void *cls, |
191 | struct MHD_Connection *connection, | 190 | struct MHD_Connection *connection, |
192 | const char *url, | 191 | const char *url, |
193 | const char *method, | 192 | const char *method, |
194 | const char *version, | 193 | const char *version, |
195 | const char *upload_data, size_t *upload_data_size, | 194 | const char *upload_data, size_t *upload_data_size, |
196 | void **unused) | 195 | void **unused) |
197 | { | 196 | { |
198 | static int ptr; | 197 | static int ptr; |
199 | struct MHD_Response *response; | 198 | struct MHD_Response *response; |
200 | int ret; | 199 | int ret; |
201 | 200 | ||
202 | if (0 != strcmp ("GET", method)) | 201 | if (0 != strcmp("GET", method)) |
203 | return MHD_NO; /* unexpected method */ | 202 | return MHD_NO; /* unexpected method */ |
204 | if (&ptr != *unused) | 203 | if (&ptr != *unused) |
205 | { | 204 | { |
206 | *unused = &ptr; | 205 | *unused = &ptr; |
207 | return MHD_YES; | 206 | return MHD_YES; |
208 | } | 207 | } |
209 | *unused = NULL; | 208 | *unused = NULL; |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); | 209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); |
211 | response = MHD_create_response_from_buffer (strlen (url), | 210 | response = MHD_create_response_from_buffer(strlen(url), |
212 | (void *) url, | 211 | (void *)url, |
213 | MHD_RESPMEM_MUST_COPY); | 212 | MHD_RESPMEM_MUST_COPY); |
214 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 213 | ret = MHD_queue_response(connection, MHD_HTTP_OK, response); |
215 | MHD_destroy_response (response); | 214 | MHD_destroy_response(response); |
216 | if (ret == MHD_NO) { | 215 | if (ret == MHD_NO) |
217 | global_ret = 1; | 216 | { |
218 | abort (); | 217 | global_ret = 1; |
219 | } | 218 | abort(); |
219 | } | ||
220 | global_ret = 0; | 220 | global_ret = 0; |
221 | return ret; | 221 | return ret; |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | static void | 225 | static void |
226 | do_shutdown () | 226 | do_shutdown() |
227 | { | 227 | { |
228 | if (mhd_task_id != NULL) | 228 | if (mhd_task_id != NULL) |
229 | { | 229 | { |
230 | GNUNET_SCHEDULER_cancel (mhd_task_id); | 230 | GNUNET_SCHEDULER_cancel(mhd_task_id); |
231 | mhd_task_id = NULL; | 231 | mhd_task_id = NULL; |
232 | } | 232 | } |
233 | if (curl_task_id != NULL) | 233 | if (curl_task_id != NULL) |
234 | { | 234 | { |
235 | GNUNET_SCHEDULER_cancel (curl_task_id); | 235 | GNUNET_SCHEDULER_cancel(curl_task_id); |
236 | curl_task_id = NULL; | 236 | curl_task_id = NULL; |
237 | } | 237 | } |
238 | if (NULL != mhd) | 238 | if (NULL != mhd) |
239 | { | 239 | { |
240 | MHD_stop_daemon (mhd); | 240 | MHD_stop_daemon(mhd); |
241 | mhd = NULL; | 241 | mhd = NULL; |
242 | } | 242 | } |
243 | GNUNET_free_non_null (url); | 243 | GNUNET_free_non_null(url); |
244 | 244 | ||
245 | if (NULL != proxy_proc) | 245 | if (NULL != proxy_proc) |
246 | { | 246 | { |
247 | (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL); | 247 | (void)GNUNET_OS_process_kill(proxy_proc, SIGKILL); |
248 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proxy_proc)); | 248 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(proxy_proc)); |
249 | GNUNET_OS_process_destroy (proxy_proc); | 249 | GNUNET_OS_process_destroy(proxy_proc); |
250 | proxy_proc = NULL; | 250 | proxy_proc = NULL; |
251 | } | 251 | } |
252 | url = NULL; | 252 | url = NULL; |
253 | GNUNET_SCHEDULER_shutdown (); | 253 | GNUNET_SCHEDULER_shutdown(); |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
@@ -258,19 +258,19 @@ do_shutdown () | |||
258 | * Function to run the HTTP client. | 258 | * Function to run the HTTP client. |
259 | */ | 259 | */ |
260 | static void | 260 | static void |
261 | curl_main (void); | 261 | curl_main(void); |
262 | 262 | ||
263 | 263 | ||
264 | static void | 264 | static void |
265 | curl_task (void *cls) | 265 | curl_task(void *cls) |
266 | { | 266 | { |
267 | curl_task_id = NULL; | 267 | curl_task_id = NULL; |
268 | curl_main (); | 268 | curl_main(); |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | static void | 272 | static void |
273 | curl_main () | 273 | curl_main() |
274 | { | 274 | { |
275 | fd_set rs; | 275 | fd_set rs; |
276 | fd_set ws; | 276 | fd_set ws; |
@@ -284,93 +284,93 @@ curl_main () | |||
284 | struct CURLMsg *msg; | 284 | struct CURLMsg *msg; |
285 | 285 | ||
286 | max = 0; | 286 | max = 0; |
287 | FD_ZERO (&rs); | 287 | FD_ZERO(&rs); |
288 | FD_ZERO (&ws); | 288 | FD_ZERO(&ws); |
289 | FD_ZERO (&es); | 289 | FD_ZERO(&es); |
290 | curl_multi_perform (multi, &running); | 290 | curl_multi_perform(multi, &running); |
291 | if (running == 0) | 291 | if (running == 0) |
292 | { | ||
293 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | ||
294 | if (msg->msg == CURLMSG_DONE) | ||
295 | { | 292 | { |
296 | if (msg->data.result != CURLE_OK) | 293 | GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running))); |
297 | { | 294 | if (msg->msg == CURLMSG_DONE) |
298 | fprintf (stderr, | 295 | { |
299 | "%s failed at %s:%d: `%s'\n", | 296 | if (msg->data.result != CURLE_OK) |
300 | "curl_multi_perform", | 297 | { |
301 | __FILE__, | 298 | fprintf(stderr, |
302 | __LINE__, curl_easy_strerror (msg->data.result)); | 299 | "%s failed at %s:%d: `%s'\n", |
303 | global_ret = 1; | 300 | "curl_multi_perform", |
304 | } | 301 | __FILE__, |
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; | ||
305 | } | 324 | } |
306 | curl_multi_remove_handle (multi, curl); | 325 | GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max)); |
307 | curl_multi_cleanup (multi); | 326 | if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || |
308 | curl_easy_cleanup (curl); | 327 | (-1 == timeout)) |
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 | } | ||
325 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | ||
326 | if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || | ||
327 | (-1 == timeout) ) | ||
328 | delay = GNUNET_TIME_UNIT_SECONDS; | 328 | delay = GNUNET_TIME_UNIT_SECONDS; |
329 | else | 329 | else |
330 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout); | 330 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int)timeout); |
331 | GNUNET_NETWORK_fdset_copy_native (&nrs, | 331 | GNUNET_NETWORK_fdset_copy_native(&nrs, |
332 | &rs, | 332 | &rs, |
333 | max + 1); | 333 | max + 1); |
334 | GNUNET_NETWORK_fdset_copy_native (&nws, | 334 | GNUNET_NETWORK_fdset_copy_native(&nws, |
335 | &ws, | 335 | &ws, |
336 | max + 1); | 336 | max + 1); |
337 | curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 337 | curl_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
338 | delay, | 338 | delay, |
339 | &nrs, | 339 | &nrs, |
340 | &nws, | 340 | &nws, |
341 | &curl_task, | 341 | &curl_task, |
342 | NULL); | 342 | NULL); |
343 | } | 343 | } |
344 | 344 | ||
345 | 345 | ||
346 | static void | 346 | static void |
347 | start_curl (void *cls) | 347 | start_curl(void *cls) |
348 | { | 348 | { |
349 | curl_task_id = NULL; | 349 | curl_task_id = NULL; |
350 | GNUNET_asprintf (&url, | 350 | GNUNET_asprintf(&url, |
351 | "https://%s:%d/hello_world", | 351 | "https://%s:%d/hello_world", |
352 | TEST_DOMAIN, port); | 352 | TEST_DOMAIN, port); |
353 | curl = curl_easy_init (); | 353 | curl = curl_easy_init(); |
354 | curl_easy_setopt (curl, CURLOPT_URL, url); | 354 | curl_easy_setopt(curl, CURLOPT_URL, url); |
355 | //curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world"); | 355 | //curl_easy_setopt (curl, CURLOPT_URL, "https://127.0.0.1:8443/hello_world"); |
356 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | 356 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ©_buffer); |
357 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | 357 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc); |
358 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | 358 | curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); |
359 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | 359 | curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L); |
360 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | 360 | curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15L); |
361 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | 361 | curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
362 | curl_easy_setopt (curl, CURLOPT_CAINFO, cafile_opt); | 362 | curl_easy_setopt(curl, CURLOPT_CAINFO, cafile_opt); |
363 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L); | 363 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L); |
364 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L); | 364 | //curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L); |
365 | curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); | 365 | curl_easy_setopt(curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777"); |
366 | 366 | ||
367 | multi = curl_multi_init (); | 367 | multi = curl_multi_init(); |
368 | GNUNET_assert (multi != NULL); | 368 | GNUNET_assert(multi != NULL); |
369 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | 369 | GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl)); |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 370 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
371 | "Beginning HTTP download from `%s'\n", | 371 | "Beginning HTTP download from `%s'\n", |
372 | url); | 372 | url); |
373 | curl_main (); | 373 | curl_main(); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
@@ -387,12 +387,12 @@ start_curl (void *cls) | |||
387 | * specified target peer; NULL on error | 387 | * specified target peer; NULL on error |
388 | */ | 388 | */ |
389 | static void | 389 | static void |
390 | commence_testing (void *cls) | 390 | commence_testing(void *cls) |
391 | { | 391 | { |
392 | curl_task_id = | 392 | curl_task_id = |
393 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 393 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
394 | &start_curl, | 394 | &start_curl, |
395 | NULL); | 395 | NULL); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
@@ -400,20 +400,20 @@ commence_testing (void *cls) | |||
400 | * Function to keep the HTTP server running. | 400 | * Function to keep the HTTP server running. |
401 | */ | 401 | */ |
402 | static void | 402 | static void |
403 | mhd_main (void); | 403 | mhd_main(void); |
404 | 404 | ||
405 | 405 | ||
406 | static void | 406 | static void |
407 | mhd_task (void *cls) | 407 | mhd_task(void *cls) |
408 | { | 408 | { |
409 | mhd_task_id = NULL; | 409 | mhd_task_id = NULL; |
410 | MHD_run (mhd); | 410 | MHD_run(mhd); |
411 | mhd_main (); | 411 | mhd_main(); |
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | static void | 415 | static void |
416 | mhd_main () | 416 | mhd_main() |
417 | { | 417 | { |
418 | struct GNUNET_NETWORK_FDSet nrs; | 418 | struct GNUNET_NETWORK_FDSet nrs; |
419 | struct GNUNET_NETWORK_FDSet nws; | 419 | struct GNUNET_NETWORK_FDSet nws; |
@@ -424,30 +424,30 @@ mhd_main () | |||
424 | unsigned MHD_LONG_LONG timeout; | 424 | unsigned MHD_LONG_LONG timeout; |
425 | struct GNUNET_TIME_Relative delay; | 425 | struct GNUNET_TIME_Relative delay; |
426 | 426 | ||
427 | GNUNET_assert (NULL == mhd_task_id); | 427 | GNUNET_assert(NULL == mhd_task_id); |
428 | FD_ZERO (&rs); | 428 | FD_ZERO(&rs); |
429 | FD_ZERO (&ws); | 429 | FD_ZERO(&ws); |
430 | FD_ZERO (&es); | 430 | FD_ZERO(&es); |
431 | max_fd = -1; | 431 | max_fd = -1; |
432 | GNUNET_assert (MHD_YES == | 432 | GNUNET_assert(MHD_YES == |
433 | MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); | 433 | MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd)); |
434 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) | 434 | if (MHD_YES == MHD_get_timeout(mhd, &timeout)) |
435 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 435 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
436 | (unsigned int) timeout); | 436 | (unsigned int)timeout); |
437 | else | 437 | else |
438 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 438 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
439 | GNUNET_NETWORK_fdset_copy_native (&nrs, | 439 | GNUNET_NETWORK_fdset_copy_native(&nrs, |
440 | &rs, | 440 | &rs, |
441 | max_fd + 1); | 441 | max_fd + 1); |
442 | GNUNET_NETWORK_fdset_copy_native (&nws, | 442 | GNUNET_NETWORK_fdset_copy_native(&nws, |
443 | &ws, | 443 | &ws, |
444 | max_fd + 1); | 444 | max_fd + 1); |
445 | mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 445 | mhd_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
446 | delay, | 446 | delay, |
447 | &nrs, | 447 | &nrs, |
448 | &nws, | 448 | &nws, |
449 | &mhd_task, | 449 | &mhd_task, |
450 | NULL); | 450 | NULL); |
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
@@ -460,105 +460,105 @@ mhd_main () | |||
460 | * @param c configuration | 460 | * @param c configuration |
461 | */ | 461 | */ |
462 | static void | 462 | static void |
463 | run (void *cls, | 463 | run(void *cls, |
464 | char *const *args, | 464 | char *const *args, |
465 | const char *cfgfile, | 465 | const char *cfgfile, |
466 | const struct GNUNET_CONFIGURATION_Handle *c) | 466 | const struct GNUNET_CONFIGURATION_Handle *c) |
467 | { | 467 | { |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 468 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
469 | "Using `%s' as CA\n", | 469 | "Using `%s' as CA\n", |
470 | cafile_srv); | 470 | cafile_srv); |
471 | char cert[MAX_PEM_SIZE]; | 471 | char cert[MAX_PEM_SIZE]; |
472 | char key[MAX_PEM_SIZE]; | 472 | char key[MAX_PEM_SIZE]; |
473 | size_t key_buf_size; | 473 | size_t key_buf_size; |
474 | size_t cert_buf_size; | 474 | size_t cert_buf_size; |
475 | 475 | ||
476 | gnutls_global_init (); | 476 | gnutls_global_init(); |
477 | gnutls_x509_crt_init (&proxy_cert); | 477 | gnutls_x509_crt_init(&proxy_cert); |
478 | gnutls_x509_privkey_init (&proxy_key); | 478 | gnutls_x509_privkey_init(&proxy_key); |
479 | 479 | ||
480 | if ( (GNUNET_OK != | 480 | if ((GNUNET_OK != |
481 | load_cert_from_file (proxy_cert, | 481 | load_cert_from_file(proxy_cert, |
482 | cafile_srv)) || | 482 | cafile_srv)) || |
483 | (GNUNET_OK != | 483 | (GNUNET_OK != |
484 | load_key_from_file (proxy_key, | 484 | load_key_from_file(proxy_key, |
485 | cafile_srv)) ) | 485 | cafile_srv))) |
486 | { | 486 | { |
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 487 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
488 | _("Failed to load X.509 key and certificate from `%s'\n"), | 488 | _("Failed to load X.509 key and certificate from `%s'\n"), |
489 | cafile_srv); | 489 | cafile_srv); |
490 | gnutls_x509_crt_deinit (proxy_cert); | 490 | gnutls_x509_crt_deinit(proxy_cert); |
491 | gnutls_x509_privkey_deinit (proxy_key); | 491 | gnutls_x509_privkey_deinit(proxy_key); |
492 | gnutls_global_deinit (); | 492 | gnutls_global_deinit(); |
493 | return; | 493 | return; |
494 | } | 494 | } |
495 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 495 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
496 | NULL); | 496 | NULL); |
497 | key_buf_size = sizeof (key); | 497 | key_buf_size = sizeof(key); |
498 | cert_buf_size = sizeof (cert); | 498 | cert_buf_size = sizeof(cert); |
499 | gnutls_x509_crt_export (proxy_cert, | 499 | gnutls_x509_crt_export(proxy_cert, |
500 | GNUTLS_X509_FMT_PEM, | 500 | GNUTLS_X509_FMT_PEM, |
501 | cert, | 501 | cert, |
502 | &cert_buf_size); | 502 | &cert_buf_size); |
503 | gnutls_x509_privkey_export (proxy_key, | 503 | gnutls_x509_privkey_export(proxy_key, |
504 | GNUTLS_X509_FMT_PEM, | 504 | GNUTLS_X509_FMT_PEM, |
505 | key, | 505 | key, |
506 | &key_buf_size); | 506 | &key_buf_size); |
507 | mhd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_ALLOW_SUSPEND_RESUME, port, | 507 | mhd = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SSL | MHD_ALLOW_SUSPEND_RESUME, port, |
508 | NULL, NULL, | 508 | NULL, NULL, |
509 | &mhd_ahc, NULL, | 509 | &mhd_ahc, NULL, |
510 | MHD_OPTION_HTTPS_MEM_KEY, key, | 510 | MHD_OPTION_HTTPS_MEM_KEY, key, |
511 | MHD_OPTION_HTTPS_MEM_CERT, cert, | 511 | MHD_OPTION_HTTPS_MEM_CERT, cert, |
512 | MHD_OPTION_END); | 512 | MHD_OPTION_END); |
513 | GNUNET_assert (NULL != mhd); | 513 | GNUNET_assert(NULL != mhd); |
514 | mhd_main (); | 514 | mhd_main(); |
515 | 515 | ||
516 | GNUNET_SCHEDULER_add_now (&commence_testing, | 516 | GNUNET_SCHEDULER_add_now(&commence_testing, |
517 | NULL); | 517 | NULL); |
518 | } | 518 | } |
519 | 519 | ||
520 | int | 520 | int |
521 | main (int argc, char *const *argv) | 521 | main(int argc, char *const *argv) |
522 | { | 522 | { |
523 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 523 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
524 | GNUNET_GETOPT_option_uint16 ('p', | 524 | GNUNET_GETOPT_option_uint16('p', |
525 | "port", | 525 | "port", |
526 | NULL, | 526 | NULL, |
527 | gettext_noop ("listen on specified port (default: 7777)"), | 527 | gettext_noop("listen on specified port (default: 7777)"), |
528 | &port), | 528 | &port), |
529 | GNUNET_GETOPT_option_string ('A', | 529 | GNUNET_GETOPT_option_string('A', |
530 | "curlcert", | 530 | "curlcert", |
531 | NULL, | 531 | NULL, |
532 | gettext_noop ("pem file to use as CA"), | 532 | gettext_noop("pem file to use as CA"), |
533 | &cafile_opt), | 533 | &cafile_opt), |
534 | GNUNET_GETOPT_option_string ('S', | 534 | GNUNET_GETOPT_option_string('S', |
535 | "servercert", | 535 | "servercert", |
536 | NULL, | 536 | NULL, |
537 | gettext_noop ("pem file to use for the server"), | 537 | gettext_noop("pem file to use for the server"), |
538 | &cafile_srv), | 538 | &cafile_srv), |
539 | 539 | ||
540 | GNUNET_GETOPT_OPTION_END | 540 | GNUNET_GETOPT_OPTION_END |
541 | }; | 541 | }; |
542 | 542 | ||
543 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 543 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
544 | { | 544 | { |
545 | fprintf (stderr, "failed to initialize curl\n"); | 545 | fprintf(stderr, "failed to initialize curl\n"); |
546 | return 2; | 546 | return 2; |
547 | } | 547 | } |
548 | if (GNUNET_OK != | 548 | if (GNUNET_OK != |
549 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 549 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
550 | &argc, &argv)) | 550 | &argc, &argv)) |
551 | return 2; | 551 | return 2; |
552 | GNUNET_log_setup ("gnunet-gns-proxy-test", | 552 | GNUNET_log_setup("gnunet-gns-proxy-test", |
553 | "WARNING", | 553 | "WARNING", |
554 | NULL); | 554 | NULL); |
555 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, | 555 | if (GNUNET_OK != GNUNET_PROGRAM_run(argc, argv, |
556 | "gnunet-gns-proxy-test", | 556 | "gnunet-gns-proxy-test", |
557 | _("GNUnet GNS proxy test"), | 557 | _("GNUnet GNS proxy test"), |
558 | options, | 558 | options, |
559 | &run, NULL)) | 559 | &run, NULL)) |
560 | return 1; | 560 | return 1; |
561 | GNUNET_free_non_null ((char *) argv); | 561 | GNUNET_free_non_null((char *)argv); |
562 | return global_ret; | 562 | return global_ret; |
563 | } | 563 | } |
564 | 564 | ||
diff --git a/src/gns/w32nsp-install.c b/src/gns/w32nsp-install.c index 6c9c44409..2674359fb 100644 --- a/src/gns/w32nsp-install.c +++ b/src/gns/w32nsp-install.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/w32nsp-install.c | 21 | * @file gns/w32nsp-install.c |
22 | * @brief W32 integration installer for GNS | 22 | * @brief W32 integration installer for GNS |
@@ -31,7 +31,7 @@ | |||
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | 32 | ||
33 | int | 33 | int |
34 | main (int argc, char **argv) | 34 | main(int argc, char **argv) |
35 | { | 35 | { |
36 | int ret; | 36 | int ret; |
37 | int r = 1; | 37 | int r = 1; |
@@ -47,97 +47,97 @@ main (int argc, char **argv) | |||
47 | int p_count; | 47 | int p_count; |
48 | int i; | 48 | int i; |
49 | 49 | ||
50 | if (WSAStartup (MAKEWORD (2,2), &wsd) != 0) | 50 | if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0) |
51 | { | 51 | { |
52 | fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ()); | 52 | fprintf(stderr, "WSAStartup () failed: %lu\n", GetLastError()); |
53 | return 5; | 53 | return 5; |
54 | } | 54 | } |
55 | 55 | ||
56 | dwBufferLen = dwInitialBufferLen; | 56 | dwBufferLen = dwInitialBufferLen; |
57 | pi = malloc (dwBufferLen); | 57 | pi = malloc(dwBufferLen); |
58 | if (NULL == pi) | 58 | if (NULL == pi) |
59 | { | 59 | { |
60 | fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); | 60 | fprintf(stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); |
61 | WSACleanup (); | 61 | WSACleanup(); |
62 | return 6; | 62 | return 6; |
63 | } | 63 | } |
64 | p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi); | 64 | p_count = WSAEnumNameSpaceProviders(&dwBufferLen, pi); |
65 | if (SOCKET_ERROR == p_count) | 65 | if (SOCKET_ERROR == p_count) |
66 | { | ||
67 | DWORD err = GetLastError (); | ||
68 | if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen) | ||
69 | { | 66 | { |
70 | free (pi); | 67 | DWORD err = GetLastError(); |
68 | if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen) | ||
69 | { | ||
70 | free(pi); | ||
71 | 71 | ||
72 | pi = malloc (dwBufferLen); | 72 | pi = malloc(dwBufferLen); |
73 | if (pi == NULL) | 73 | if (pi == NULL) |
74 | { | 74 | { |
75 | fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); | 75 | fprintf(stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno); |
76 | WSACleanup (); | 76 | WSACleanup(); |
77 | return 6; | 77 | return 6; |
78 | } | 78 | } |
79 | 79 | ||
80 | p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi); | 80 | p_count = WSAEnumNameSpaceProviders(&dwBufferLen, pi); |
81 | if (SOCKET_ERROR == p_count) | 81 | if (SOCKET_ERROR == p_count) |
82 | { | 82 | { |
83 | fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ()); | 83 | fprintf(stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError()); |
84 | free (pi); | 84 | free(pi); |
85 | WSACleanup (); | 85 | WSACleanup(); |
86 | return 7; | 86 | return 7; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | else | 89 | else |
90 | { | 90 | { |
91 | fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ()); | 91 | fprintf(stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError()); |
92 | free (pi); | 92 | free(pi); |
93 | WSACleanup (); | 93 | WSACleanup(); |
94 | return 8; | 94 | return 8; |
95 | } | ||
95 | } | 96 | } |
96 | } | 97 | for (i = 0; i < p_count; i++) |
97 | for (i= 0; i < p_count; i++) | ||
98 | { | ||
99 | if (IsEqualGUID (&pi[i].NSProviderId, &id)) | ||
100 | { | 98 | { |
101 | fprintf (stderr, "GNUnet DNS provider is already installed\n"); | 99 | if (IsEqualGUID(&pi[i].NSProviderId, &id)) |
102 | free (pi); | 100 | { |
103 | WSACleanup (); | 101 | fprintf(stderr, "GNUnet DNS provider is already installed\n"); |
104 | return 0; | 102 | free(pi); |
103 | WSACleanup(); | ||
104 | return 0; | ||
105 | } | ||
105 | } | 106 | } |
106 | } | 107 | free(pi); |
107 | free (pi); | ||
108 | 108 | ||
109 | cmdl = GetCommandLineW (); | 109 | cmdl = GetCommandLineW(); |
110 | if (cmdl == NULL) | 110 | if (cmdl == NULL) |
111 | { | 111 | { |
112 | WSACleanup (); | 112 | WSACleanup(); |
113 | return 2; | 113 | return 2; |
114 | } | 114 | } |
115 | wargv = CommandLineToArgvW (cmdl, &wargc); | 115 | wargv = CommandLineToArgvW(cmdl, &wargc); |
116 | if (wargv == NULL) | 116 | if (wargv == NULL) |
117 | { | 117 | { |
118 | WSACleanup (); | 118 | WSACleanup(); |
119 | return 3; | 119 | return 3; |
120 | } | 120 | } |
121 | r = 4; | 121 | r = 4; |
122 | 122 | ||
123 | if (wargc == 2) | 123 | if (wargc == 2) |
124 | { | ||
125 | ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id); | ||
126 | if (ret == NO_ERROR) | ||
127 | { | ||
128 | fprintf (stderr, "Installed GNUnet DNS provider\n"); | ||
129 | r = 0; | ||
130 | } | ||
131 | else | ||
132 | { | 124 | { |
133 | r = 1; | 125 | ret = WSCInstallNameSpace(L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id); |
134 | fprintf (stderr, | 126 | if (ret == NO_ERROR) |
135 | "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n", | 127 | { |
136 | wargv[1], NS_DNS, &id, GetLastError ()); | 128 | fprintf(stderr, "Installed GNUnet DNS provider\n"); |
129 | r = 0; | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | r = 1; | ||
134 | fprintf(stderr, | ||
135 | "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n", | ||
136 | wargv[1], NS_DNS, &id, GetLastError()); | ||
137 | } | ||
137 | } | 138 | } |
138 | } | ||
139 | else | 139 | else |
140 | fprintf (stderr, "Usage: %S <path-to-libw32nsp>\n", wargv[0]); | 140 | fprintf(stderr, "Usage: %S <path-to-libw32nsp>\n", wargv[0]); |
141 | WSACleanup (); | 141 | WSACleanup(); |
142 | return r; | 142 | return r; |
143 | } | 143 | } |
diff --git a/src/gns/w32nsp-resolve.c b/src/gns/w32nsp-resolve.c index 841f5b9e6..ad0fd3586 100644 --- a/src/gns/w32nsp-resolve.c +++ b/src/gns/w32nsp-resolve.c | |||
@@ -11,19 +11,19 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/w32nsp-resolve.c | 21 | * @file gns/w32nsp-resolve.c |
22 | * @brief W32 integration for GNS | 22 | * @brief W32 integration for GNS |
23 | * @author LRN | 23 | * @author LRN |
24 | */ | 24 | */ |
25 | /* Instead of including gnunet_common.h */ | 25 | /* Instead of including gnunet_common.h */ |
26 | #define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0) | 26 | #define GNUNET_memcpy(dst, src, n) do { if (0 != n) { (void)memcpy(dst, src, n); } } while (0) |
27 | 27 | ||
28 | #include <ws2tcpip.h> | 28 | #include <ws2tcpip.h> |
29 | #include <windows.h> | 29 | #include <windows.h> |
@@ -34,15 +34,15 @@ | |||
34 | #include "gnunet_w32nsp_lib.h" | 34 | #include "gnunet_w32nsp_lib.h" |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | 36 | ||
37 | typedef int (WSPAPI *LPNSPSTARTUP) (LPGUID lpProviderId, LPNSP_ROUTINE lpnspRoutines); | 37 | typedef int (WSPAPI *LPNSPSTARTUP)(LPGUID lpProviderId, LPNSP_ROUTINE lpnspRoutines); |
38 | 38 | ||
39 | GUID host = {0x0002a800,0,0,{ 0xC0,0,0,0,0,0,0,0x46 }}; | 39 | GUID host = { 0x0002a800, 0, 0, { 0xC0, 0, 0, 0, 0, 0, 0, 0x46 } }; |
40 | GUID ip4 = {0x00090035,0,1,{ 0xc0,0,0,0,0,0,0,0x046}}; | 40 | GUID ip4 = { 0x00090035, 0, 1, { 0xc0, 0, 0, 0, 0, 0, 0, 0x046 } }; |
41 | GUID ip6 = {0x00090035,0,0x001c, { 0xc0,0,0,0,0,0,0,0x046}}; | 41 | GUID ip6 = { 0x00090035, 0, 0x001c, { 0xc0, 0, 0, 0, 0, 0, 0, 0x046 } }; |
42 | 42 | ||
43 | DEFINE_GUID(W32_DNS, 0x22059D40, 0x7E9E, 0x11CF, 0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B); | 43 | DEFINE_GUID(W32_DNS, 0x22059D40, 0x7E9E, 0x11CF, 0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B); |
44 | 44 | ||
45 | #define DEFINE_DNS_GUID(a,x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46) | 45 | #define DEFINE_DNS_GUID(a, x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46) |
46 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001); | 46 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001); |
47 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002); | 47 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002); |
48 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005); | 48 | DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005); |
@@ -63,15 +63,15 @@ DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0 | |||
63 | VOID | 63 | VOID |
64 | FixList(PCHAR ** List, PCHAR Base) | 64 | FixList(PCHAR ** List, PCHAR Base) |
65 | { | 65 | { |
66 | if(*List) | 66 | if (*List) |
67 | { | 67 | { |
68 | PCHAR * Addr; | 68 | PCHAR * Addr; |
69 | 69 | ||
70 | Addr = *List = (PCHAR *)( ((DWORD)*List + Base) ); | 70 | Addr = *List = (PCHAR *)(((DWORD)*List + Base)); |
71 | while(*Addr) | 71 | while (*Addr) |
72 | { | 72 | { |
73 | *Addr = (PCHAR)(((DWORD)*Addr + Base)); | 73 | *Addr = (PCHAR)(((DWORD)*Addr + Base)); |
74 | Addr++; | 74 | Addr++; |
75 | } | 75 | } |
76 | } | 76 | } |
77 | } | 77 | } |
@@ -84,82 +84,92 @@ FixList(PCHAR ** List, PCHAR Base) | |||
84 | VOID | 84 | VOID |
85 | UnpackHostEnt(struct hostent * hostent) | 85 | UnpackHostEnt(struct hostent * hostent) |
86 | { | 86 | { |
87 | PCHAR pch; | 87 | PCHAR pch; |
88 | 88 | ||
89 | pch = (PCHAR)hostent; | 89 | pch = (PCHAR)hostent; |
90 | 90 | ||
91 | if(hostent->h_name) | 91 | if (hostent->h_name) |
92 | { | 92 | { |
93 | hostent->h_name = (PCHAR)((DWORD)hostent->h_name + pch); | 93 | hostent->h_name = (PCHAR)((DWORD)hostent->h_name + pch); |
94 | } | 94 | } |
95 | FixList(&hostent->h_aliases, pch); | 95 | FixList(&hostent->h_aliases, pch); |
96 | FixList(&hostent->h_addr_list, pch); | 96 | FixList(&hostent->h_addr_list, pch); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | static void | 100 | static void |
101 | print_hostent (struct hostent *he) | 101 | print_hostent(struct hostent *he) |
102 | { | 102 | { |
103 | int i; | 103 | int i; |
104 | char **pAlias; | 104 | char **pAlias; |
105 | 105 | ||
106 | printf("\tOfficial name: %s\n", he->h_name); | 106 | printf("\tOfficial name: %s\n", he->h_name); |
107 | for (i=0, pAlias = he->h_aliases; *pAlias != 0; pAlias++) { | 107 | for (i = 0, pAlias = he->h_aliases; *pAlias != 0; pAlias++) |
108 | { | ||
108 | printf("\tAlternate name #%d: %s\n", ++i, *pAlias); | 109 | printf("\tAlternate name #%d: %s\n", ++i, *pAlias); |
109 | } | 110 | } |
110 | printf("\tAddress type: "); | 111 | printf("\tAddress type: "); |
111 | switch (he->h_addrtype) { | 112 | switch (he->h_addrtype) |
112 | case AF_INET: | 113 | { |
114 | case AF_INET: | ||
113 | printf("AF_INET\n"); | 115 | printf("AF_INET\n"); |
114 | break; | 116 | break; |
115 | case AF_INET6: | 117 | |
118 | case AF_INET6: | ||
116 | printf("AF_INET6\n"); | 119 | printf("AF_INET6\n"); |
117 | break; | 120 | break; |
118 | case AF_NETBIOS: | 121 | |
122 | case AF_NETBIOS: | ||
119 | printf("AF_NETBIOS\n"); | 123 | printf("AF_NETBIOS\n"); |
120 | break; | 124 | break; |
121 | default: | 125 | |
126 | default: | ||
122 | printf(" %d\n", he->h_addrtype); | 127 | printf(" %d\n", he->h_addrtype); |
123 | break; | 128 | break; |
124 | } | 129 | } |
125 | printf("\tAddress length: %d\n", he->h_length); | 130 | printf("\tAddress length: %d\n", he->h_length); |
126 | 131 | ||
127 | if (he->h_addrtype == AF_INET) { | 132 | if (he->h_addrtype == AF_INET) |
128 | struct sockaddr_in addr; | 133 | { |
129 | memset (&addr, 0, sizeof (addr)); | 134 | struct sockaddr_in addr; |
130 | addr.sin_family = AF_INET; | 135 | memset(&addr, 0, sizeof(addr)); |
131 | addr.sin_port = 0; | 136 | addr.sin_family = AF_INET; |
132 | i = 0; | 137 | addr.sin_port = 0; |
133 | while (he->h_addr_list[i] != 0) { | 138 | i = 0; |
134 | char buf[1024]; | 139 | while (he->h_addr_list[i] != 0) |
135 | DWORD buflen = 1024; | 140 | { |
136 | addr.sin_addr = *(struct in_addr *) he->h_addr_list[i++]; | 141 | char buf[1024]; |
137 | if (NO_ERROR == WSAAddressToStringA ((LPSOCKADDR) &addr, sizeof (addr), NULL, buf, &buflen)) | 142 | DWORD buflen = 1024; |
138 | printf("\tIPv4 Address #%d: %s\n", i, buf); | 143 | addr.sin_addr = *(struct in_addr *)he->h_addr_list[i++]; |
139 | else | 144 | if (NO_ERROR == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(addr), NULL, buf, &buflen)) |
140 | printf("\tIPv4 Address #%d: Can't convert: %lu\n", i, GetLastError ()); | 145 | printf("\tIPv4 Address #%d: %s\n", i, buf); |
146 | else | ||
147 | printf("\tIPv4 Address #%d: Can't convert: %lu\n", i, GetLastError()); | ||
148 | } | ||
141 | } | 149 | } |
142 | } else if (he->h_addrtype == AF_INET6) { | 150 | else if (he->h_addrtype == AF_INET6) |
143 | struct sockaddr_in6 addr; | 151 | { |
144 | memset (&addr, 0, sizeof (addr)); | 152 | struct sockaddr_in6 addr; |
145 | addr.sin6_family = AF_INET6; | 153 | memset(&addr, 0, sizeof(addr)); |
146 | addr.sin6_port = 0; | 154 | addr.sin6_family = AF_INET6; |
147 | i = 0; | 155 | addr.sin6_port = 0; |
148 | while (he->h_addr_list[i] != 0) { | 156 | i = 0; |
149 | char buf[1024]; | 157 | while (he->h_addr_list[i] != 0) |
150 | DWORD buflen = 1024; | 158 | { |
151 | addr.sin6_addr = *(struct in6_addr *) he->h_addr_list[i++]; | 159 | char buf[1024]; |
152 | if (NO_ERROR == WSAAddressToStringA ((LPSOCKADDR) &addr, sizeof (addr), NULL, buf, &buflen)) | 160 | DWORD buflen = 1024; |
153 | printf("\tIPv6 Address #%d: %s\n", i, buf); | 161 | addr.sin6_addr = *(struct in6_addr *)he->h_addr_list[i++]; |
154 | else | 162 | if (NO_ERROR == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(addr), NULL, buf, &buflen)) |
155 | printf("\tIPv6 Address #%d: Can't convert: %lu\n", i, GetLastError ()); | 163 | printf("\tIPv6 Address #%d: %s\n", i, buf); |
164 | else | ||
165 | printf("\tIPv6 Address #%d: Can't convert: %lu\n", i, GetLastError()); | ||
166 | } | ||
156 | } | 167 | } |
157 | } | ||
158 | } | 168 | } |
159 | 169 | ||
160 | 170 | ||
161 | int | 171 | int |
162 | main (int argc, char **argv) | 172 | main(int argc, char **argv) |
163 | { | 173 | { |
164 | int ret; | 174 | int ret; |
165 | int r = 1; | 175 | int r = 1; |
@@ -170,277 +180,285 @@ main (int argc, char **argv) | |||
170 | int wargc; | 180 | int wargc; |
171 | wchar_t **wargv; | 181 | wchar_t **wargv; |
172 | 182 | ||
173 | if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) | 183 | if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0) |
174 | { | 184 | { |
175 | fprintf (stderr, "WSAStartup() failed: %lu\n", GetLastError()); | 185 | fprintf(stderr, "WSAStartup() failed: %lu\n", GetLastError()); |
176 | return 5; | 186 | return 5; |
177 | } | 187 | } |
178 | 188 | ||
179 | cmdl = GetCommandLineW (); | 189 | cmdl = GetCommandLineW(); |
180 | if (cmdl == NULL) | 190 | if (cmdl == NULL) |
181 | { | 191 | { |
182 | WSACleanup(); | 192 | WSACleanup(); |
183 | return 2; | 193 | return 2; |
184 | } | 194 | } |
185 | wargv = CommandLineToArgvW (cmdl, &wargc); | 195 | wargv = CommandLineToArgvW(cmdl, &wargc); |
186 | if (wargv == NULL) | 196 | if (wargv == NULL) |
187 | { | 197 | { |
188 | WSACleanup(); | 198 | WSACleanup(); |
189 | return 3; | 199 | return 3; |
190 | } | 200 | } |
191 | r = 4; | 201 | r = 4; |
192 | 202 | ||
193 | if (wargc == 5) | 203 | if (wargc == 5) |
194 | { | 204 | { |
195 | if (wcscmp (wargv[1], L"A") == 0) | 205 | if (wcscmp(wargv[1], L"A") == 0) |
196 | sc = SVCID_DNS_TYPE_A; | 206 | sc = SVCID_DNS_TYPE_A; |
197 | else if (wcscmp (wargv[1], L"AAAA") == 0) | 207 | else if (wcscmp(wargv[1], L"AAAA") == 0) |
198 | sc = SVCID_DNS_TYPE_AAAA; | 208 | sc = SVCID_DNS_TYPE_AAAA; |
199 | else if (wcscmp (wargv[1], L"name") == 0) | 209 | else if (wcscmp(wargv[1], L"name") == 0) |
200 | sc = SVCID_HOSTNAME; | 210 | sc = SVCID_HOSTNAME; |
201 | else if (wcscmp (wargv[1], L"addr") == 0) | 211 | else if (wcscmp(wargv[1], L"addr") == 0) |
202 | sc = SVCID_INET_HOSTADDRBYNAME; | 212 | sc = SVCID_INET_HOSTADDRBYNAME; |
203 | else | 213 | else |
204 | wargc -= 1; | 214 | wargc -= 1; |
205 | if (wcscmp (wargv[4], L"mswdns") == 0) | 215 | if (wcscmp(wargv[4], L"mswdns") == 0) |
206 | prov = W32_DNS; | 216 | prov = W32_DNS; |
207 | else if (wcscmp (wargv[4], L"gnunetdns") == 0) | 217 | else if (wcscmp(wargv[4], L"gnunetdns") == 0) |
208 | prov = GNUNET_NAMESPACE_PROVIDER_DNS; | 218 | prov = GNUNET_NAMESPACE_PROVIDER_DNS; |
209 | else | 219 | else |
210 | wargc -= 1; | 220 | wargc -= 1; |
211 | } | 221 | } |
212 | else if (wargc == 3) | 222 | else if (wargc == 3) |
213 | { | 223 | { |
214 | } | 224 | } |
215 | else | 225 | else |
216 | { | ||
217 | fprintf (stderr, "Usage: %S <record type> <service name> <NSP library path> <NSP id>\n" | ||
218 | "record type - one of the following: A | AAAA | name | addr\n" | ||
219 | "service name - a string to resolve; \" \" (a space) means 'blank'\n" | ||
220 | "NSP library path - path to libw32nsp\n" | ||
221 | "NSP id - one of the following: mswdns | gnunetdns\n", | ||
222 | wargv[0]); | ||
223 | } | ||
224 | |||
225 | if (wargc == 5) | ||
226 | { | ||
227 | HMODULE nsp; | ||
228 | |||
229 | nsp = LoadLibraryW (wargv[3]); | ||
230 | if (nsp == NULL) | ||
231 | { | 226 | { |
232 | fprintf (stderr, "Failed to load library `%S'\n", wargv[3]); | 227 | fprintf(stderr, "Usage: %S <record type> <service name> <NSP library path> <NSP id>\n" |
228 | "record type - one of the following: A | AAAA | name | addr\n" | ||
229 | "service name - a string to resolve; \" \" (a space) means 'blank'\n" | ||
230 | "NSP library path - path to libw32nsp\n" | ||
231 | "NSP id - one of the following: mswdns | gnunetdns\n", | ||
232 | wargv[0]); | ||
233 | } | 233 | } |
234 | else | 234 | |
235 | if (wargc == 5) | ||
235 | { | 236 | { |
236 | LPNSPSTARTUP startup = (LPNSPSTARTUP) GetProcAddress (nsp, "NSPStartup"); | 237 | HMODULE nsp; |
237 | if (startup == NULL) | 238 | |
238 | startup = (LPNSPSTARTUP) GetProcAddress (nsp, "NSPStartup@8"); | 239 | nsp = LoadLibraryW(wargv[3]); |
239 | if (startup != NULL) | 240 | if (nsp == NULL) |
240 | { | ||
241 | NSP_ROUTINE api; | ||
242 | api.cbSize = sizeof (api); | ||
243 | ret = startup (&prov, &api); | ||
244 | if (NO_ERROR != ret) | ||
245 | fprintf (stderr, "startup failed: %lu\n", GetLastError ()); | ||
246 | else | ||
247 | { | 241 | { |
248 | HANDLE lookup; | 242 | fprintf(stderr, "Failed to load library `%S'\n", wargv[3]); |
249 | WSAQUERYSETW search; | 243 | } |
250 | char buf[4096]; | 244 | else |
251 | WSAQUERYSETW *result = (WSAQUERYSETW *) buf; | 245 | { |
252 | DWORD resultsize; | 246 | LPNSPSTARTUP startup = (LPNSPSTARTUP)GetProcAddress(nsp, "NSPStartup"); |
253 | DWORD err; | 247 | if (startup == NULL) |
254 | memset (&search, 0, sizeof (search)); | 248 | startup = (LPNSPSTARTUP)GetProcAddress(nsp, "NSPStartup@8"); |
255 | search.dwSize = sizeof (search); | 249 | if (startup != NULL) |
256 | search.lpszServiceInstanceName = (wcscmp (wargv[2], L" ") == 0) ? NULL : wargv[2]; | ||
257 | search.lpServiceClassId = ≻ | ||
258 | search.lpNSProviderId = &prov; | ||
259 | search.dwNameSpace = NS_ALL; | ||
260 | ret = api.NSPLookupServiceBegin (&prov, &search, NULL, LUP_RETURN_ALL, &lookup); | ||
261 | if (ret != NO_ERROR) | ||
262 | { | ||
263 | fprintf (stderr, "lookup start failed\n"); | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | resultsize = 4096; | ||
268 | ret = api.NSPLookupServiceNext (lookup, LUP_RETURN_ALL, &resultsize, result); | ||
269 | err = GetLastError (); | ||
270 | if (ret != NO_ERROR) | ||
271 | { | ||
272 | fprintf (stderr, "lookup next failed: %lu\n", err); | ||
273 | } | ||
274 | else | ||
275 | { | 250 | { |
276 | int i; | 251 | NSP_ROUTINE api; |
277 | printf ("Got result:\n"); | 252 | api.cbSize = sizeof(api); |
278 | printf (" lpszServiceInstanceName: %S\n", result->lpszServiceInstanceName ? result->lpszServiceInstanceName : L"NULL"); | 253 | ret = startup(&prov, &api); |
279 | if (result->lpServiceClassId) | 254 | if (NO_ERROR != ret) |
280 | printf (" lpServiceClassId: { 0x%08lX,0x%04X,0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n", | 255 | fprintf(stderr, "startup failed: %lu\n", GetLastError()); |
281 | result->lpServiceClassId->Data1, result->lpServiceClassId->Data2, result->lpServiceClassId->Data3, result->lpServiceClassId->Data4[0], | ||
282 | result->lpServiceClassId->Data4[1], result->lpServiceClassId->Data4[2], result->lpServiceClassId->Data4[3], result->lpServiceClassId->Data4[4], | ||
283 | result->lpServiceClassId->Data4[5], result->lpServiceClassId->Data4[6], result->lpServiceClassId->Data4[7]); | ||
284 | else | ||
285 | printf (" lpServiceClassId: NULL\n"); | ||
286 | if (result->lpVersion) | ||
287 | printf (" lpVersion: 0x%08lX, %d\n", result->lpVersion->dwVersion, result->lpVersion->ecHow); | ||
288 | else | 256 | else |
289 | printf (" lpVersion: NULL\n"); | ||
290 | printf (" lpszComment: %S\n", result->lpszComment ? result->lpszComment : L"NULL"); | ||
291 | printf (" dwNameSpace: %lu\n", result->dwNameSpace); | ||
292 | if (result->lpNSProviderId) | ||
293 | printf (" lpNSProviderId: { 0x%08lX,0x%04X,0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n", | ||
294 | result->lpNSProviderId->Data1, result->lpNSProviderId->Data2, result->lpNSProviderId->Data3, result->lpNSProviderId->Data4[0], | ||
295 | result->lpNSProviderId->Data4[1], result->lpNSProviderId->Data4[2], result->lpNSProviderId->Data4[3], result->lpNSProviderId->Data4[4], | ||
296 | result->lpNSProviderId->Data4[5], result->lpNSProviderId->Data4[6], result->lpNSProviderId->Data4[7]); | ||
297 | else | ||
298 | printf (" lpNSProviderId: NULL\n"); | ||
299 | printf (" lpszContext: %S\n", result->lpszContext ? result->lpszContext : L"NULL"); | ||
300 | printf (" dwNumberOfProtocols: %lu\n", result->dwNumberOfProtocols); | ||
301 | printf (" lpszQueryString: %S\n", result->lpszQueryString ? result->lpszQueryString : L"NULL"); | ||
302 | printf (" dwNumberOfCsAddrs: %lu\n", result->dwNumberOfCsAddrs); | ||
303 | for (i = 0; i < result->dwNumberOfCsAddrs; i++) | ||
304 | { | ||
305 | switch (result->lpcsaBuffer[i].iSocketType) | ||
306 | { | 257 | { |
307 | case SOCK_STREAM: | 258 | HANDLE lookup; |
308 | printf (" %d: iSocketType = SOCK_STREAM\n", i); | 259 | WSAQUERYSETW search; |
309 | break; | 260 | char buf[4096]; |
310 | case SOCK_DGRAM: | 261 | WSAQUERYSETW *result = (WSAQUERYSETW *)buf; |
311 | printf (" %d: iSocketType = SOCK_DGRAM\n", i); | 262 | DWORD resultsize; |
312 | break; | 263 | DWORD err; |
313 | default: | 264 | memset(&search, 0, sizeof(search)); |
314 | printf (" %d: iSocketType = %d\n", i, result->lpcsaBuffer[i].iSocketType); | 265 | search.dwSize = sizeof(search); |
315 | } | 266 | search.lpszServiceInstanceName = (wcscmp(wargv[2], L" ") == 0) ? NULL : wargv[2]; |
316 | switch (result->lpcsaBuffer[i].iProtocol) | 267 | search.lpServiceClassId = ≻ |
317 | { | 268 | search.lpNSProviderId = &prov; |
318 | case IPPROTO_TCP: | 269 | search.dwNameSpace = NS_ALL; |
319 | printf (" %d: iProtocol = IPPROTO_TCP\n", i); | 270 | ret = api.NSPLookupServiceBegin(&prov, &search, NULL, LUP_RETURN_ALL, &lookup); |
320 | break; | 271 | if (ret != NO_ERROR) |
321 | case IPPROTO_UDP: | 272 | { |
322 | printf (" %d: iProtocol = IPPROTO_UDP\n", i); | 273 | fprintf(stderr, "lookup start failed\n"); |
323 | break; | 274 | } |
324 | default: | 275 | else |
325 | printf (" %d: iProtocol = %d\n", i, result->lpcsaBuffer[i].iProtocol); | 276 | { |
326 | } | 277 | resultsize = 4096; |
327 | switch (result->lpcsaBuffer[i].LocalAddr.lpSockaddr->sa_family) | 278 | ret = api.NSPLookupServiceNext(lookup, LUP_RETURN_ALL, &resultsize, result); |
328 | { | 279 | err = GetLastError(); |
329 | case AF_INET: | 280 | if (ret != NO_ERROR) |
330 | printf (" %d: loc family = AF_INET\n", i); | 281 | { |
331 | break; | 282 | fprintf(stderr, "lookup next failed: %lu\n", err); |
332 | case AF_INET6: | 283 | } |
333 | printf (" %d: loc family = AF_INET6\n", i); | 284 | else |
334 | break; | 285 | { |
335 | default: | 286 | int i; |
336 | printf (" %d: loc family = %hu\n", i, result->lpcsaBuffer[i].LocalAddr.lpSockaddr->sa_family); | 287 | printf("Got result:\n"); |
337 | } | 288 | printf(" lpszServiceInstanceName: %S\n", result->lpszServiceInstanceName ? result->lpszServiceInstanceName : L"NULL"); |
338 | switch (result->lpcsaBuffer[i].RemoteAddr.lpSockaddr->sa_family) | 289 | if (result->lpServiceClassId) |
339 | { | 290 | printf(" lpServiceClassId: { 0x%08lX,0x%04X,0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n", |
340 | case AF_INET: | 291 | result->lpServiceClassId->Data1, result->lpServiceClassId->Data2, result->lpServiceClassId->Data3, result->lpServiceClassId->Data4[0], |
341 | printf (" %d: rem family = AF_INET\n", i); | 292 | result->lpServiceClassId->Data4[1], result->lpServiceClassId->Data4[2], result->lpServiceClassId->Data4[3], result->lpServiceClassId->Data4[4], |
342 | break; | 293 | result->lpServiceClassId->Data4[5], result->lpServiceClassId->Data4[6], result->lpServiceClassId->Data4[7]); |
343 | case AF_INET6: | 294 | else |
344 | printf (" %d: rem family = AF_INET6\n", i); | 295 | printf(" lpServiceClassId: NULL\n"); |
345 | break; | 296 | if (result->lpVersion) |
346 | default: | 297 | printf(" lpVersion: 0x%08lX, %d\n", result->lpVersion->dwVersion, result->lpVersion->ecHow); |
347 | printf (" %d: rem family = %hu\n", i, result->lpcsaBuffer[i].RemoteAddr.lpSockaddr->sa_family); | 298 | else |
348 | } | 299 | printf(" lpVersion: NULL\n"); |
349 | char buf[1024]; | 300 | printf(" lpszComment: %S\n", result->lpszComment ? result->lpszComment : L"NULL"); |
350 | DWORD buflen = 1024; | 301 | printf(" dwNameSpace: %lu\n", result->dwNameSpace); |
351 | if (NO_ERROR == WSAAddressToStringA (result->lpcsaBuffer[i].LocalAddr.lpSockaddr, result->lpcsaBuffer[i].LocalAddr.iSockaddrLength, NULL, buf, &buflen)) | 302 | if (result->lpNSProviderId) |
352 | printf("\tLocal Address #%d: %s\n", i, buf); | 303 | printf(" lpNSProviderId: { 0x%08lX,0x%04X,0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n", |
353 | else | 304 | result->lpNSProviderId->Data1, result->lpNSProviderId->Data2, result->lpNSProviderId->Data3, result->lpNSProviderId->Data4[0], |
354 | printf("\tLocal Address #%d: Can't convert: %lu\n", i, GetLastError ()); | 305 | result->lpNSProviderId->Data4[1], result->lpNSProviderId->Data4[2], result->lpNSProviderId->Data4[3], result->lpNSProviderId->Data4[4], |
355 | buflen = 1024; | 306 | result->lpNSProviderId->Data4[5], result->lpNSProviderId->Data4[6], result->lpNSProviderId->Data4[7]); |
356 | if (NO_ERROR == WSAAddressToStringA (result->lpcsaBuffer[i].RemoteAddr.lpSockaddr, result->lpcsaBuffer[i].RemoteAddr.iSockaddrLength, NULL, buf, &buflen)) | 307 | else |
357 | printf("\tRemote Address #%d: %s\n", i, buf); | 308 | printf(" lpNSProviderId: NULL\n"); |
358 | else | 309 | printf(" lpszContext: %S\n", result->lpszContext ? result->lpszContext : L"NULL"); |
359 | printf("\tRemote Address #%d: Can't convert: %lu\n", i, GetLastError ()); | 310 | printf(" dwNumberOfProtocols: %lu\n", result->dwNumberOfProtocols); |
360 | } | 311 | printf(" lpszQueryString: %S\n", result->lpszQueryString ? result->lpszQueryString : L"NULL"); |
361 | printf (" dwOutputFlags: 0x%08lX\n", result->dwOutputFlags); | 312 | printf(" dwNumberOfCsAddrs: %lu\n", result->dwNumberOfCsAddrs); |
362 | printf (" lpBlob: 0x%p\n", result->lpBlob); | 313 | for (i = 0; i < result->dwNumberOfCsAddrs; i++) |
363 | if (result->lpBlob) | 314 | { |
364 | { | 315 | switch (result->lpcsaBuffer[i].iSocketType) |
365 | struct hostent *he = malloc (result->lpBlob->cbSize); | 316 | { |
366 | if (he != NULL) | 317 | case SOCK_STREAM: |
367 | { | 318 | printf(" %d: iSocketType = SOCK_STREAM\n", i); |
368 | GNUNET_memcpy (he, result->lpBlob->pBlobData, result->lpBlob->cbSize); | 319 | break; |
369 | UnpackHostEnt (he); | 320 | |
370 | print_hostent (he); | 321 | case SOCK_DGRAM: |
371 | free (he); | 322 | printf(" %d: iSocketType = SOCK_DGRAM\n", i); |
323 | break; | ||
324 | |||
325 | default: | ||
326 | printf(" %d: iSocketType = %d\n", i, result->lpcsaBuffer[i].iSocketType); | ||
327 | } | ||
328 | switch (result->lpcsaBuffer[i].iProtocol) | ||
329 | { | ||
330 | case IPPROTO_TCP: | ||
331 | printf(" %d: iProtocol = IPPROTO_TCP\n", i); | ||
332 | break; | ||
333 | |||
334 | case IPPROTO_UDP: | ||
335 | printf(" %d: iProtocol = IPPROTO_UDP\n", i); | ||
336 | break; | ||
337 | |||
338 | default: | ||
339 | printf(" %d: iProtocol = %d\n", i, result->lpcsaBuffer[i].iProtocol); | ||
340 | } | ||
341 | switch (result->lpcsaBuffer[i].LocalAddr.lpSockaddr->sa_family) | ||
342 | { | ||
343 | case AF_INET: | ||
344 | printf(" %d: loc family = AF_INET\n", i); | ||
345 | break; | ||
346 | |||
347 | case AF_INET6: | ||
348 | printf(" %d: loc family = AF_INET6\n", i); | ||
349 | break; | ||
350 | |||
351 | default: | ||
352 | printf(" %d: loc family = %hu\n", i, result->lpcsaBuffer[i].LocalAddr.lpSockaddr->sa_family); | ||
353 | } | ||
354 | switch (result->lpcsaBuffer[i].RemoteAddr.lpSockaddr->sa_family) | ||
355 | { | ||
356 | case AF_INET: | ||
357 | printf(" %d: rem family = AF_INET\n", i); | ||
358 | break; | ||
359 | |||
360 | case AF_INET6: | ||
361 | printf(" %d: rem family = AF_INET6\n", i); | ||
362 | break; | ||
363 | |||
364 | default: | ||
365 | printf(" %d: rem family = %hu\n", i, result->lpcsaBuffer[i].RemoteAddr.lpSockaddr->sa_family); | ||
366 | } | ||
367 | char buf[1024]; | ||
368 | DWORD buflen = 1024; | ||
369 | if (NO_ERROR == WSAAddressToStringA(result->lpcsaBuffer[i].LocalAddr.lpSockaddr, result->lpcsaBuffer[i].LocalAddr.iSockaddrLength, NULL, buf, &buflen)) | ||
370 | printf("\tLocal Address #%d: %s\n", i, buf); | ||
371 | else | ||
372 | printf("\tLocal Address #%d: Can't convert: %lu\n", i, GetLastError()); | ||
373 | buflen = 1024; | ||
374 | if (NO_ERROR == WSAAddressToStringA(result->lpcsaBuffer[i].RemoteAddr.lpSockaddr, result->lpcsaBuffer[i].RemoteAddr.iSockaddrLength, NULL, buf, &buflen)) | ||
375 | printf("\tRemote Address #%d: %s\n", i, buf); | ||
376 | else | ||
377 | printf("\tRemote Address #%d: Can't convert: %lu\n", i, GetLastError()); | ||
378 | } | ||
379 | printf(" dwOutputFlags: 0x%08lX\n", result->dwOutputFlags); | ||
380 | printf(" lpBlob: 0x%p\n", result->lpBlob); | ||
381 | if (result->lpBlob) | ||
382 | { | ||
383 | struct hostent *he = malloc(result->lpBlob->cbSize); | ||
384 | if (he != NULL) | ||
385 | { | ||
386 | GNUNET_memcpy(he, result->lpBlob->pBlobData, result->lpBlob->cbSize); | ||
387 | UnpackHostEnt(he); | ||
388 | print_hostent(he); | ||
389 | free(he); | ||
390 | } | ||
391 | } | ||
392 | } | ||
393 | ret = api.NSPLookupServiceEnd(lookup); | ||
394 | if (ret != NO_ERROR) | ||
395 | printf("NSPLookupServiceEnd() failed: %lu\n", GetLastError()); | ||
396 | } | ||
397 | api.NSPCleanup(&prov); | ||
372 | } | 398 | } |
373 | } | ||
374 | } | 399 | } |
375 | ret = api.NSPLookupServiceEnd (lookup); | 400 | FreeLibrary(nsp); |
376 | if (ret != NO_ERROR) | ||
377 | printf ("NSPLookupServiceEnd() failed: %lu\n", GetLastError ()); | ||
378 | } | ||
379 | api.NSPCleanup (&prov); | ||
380 | } | 401 | } |
381 | } | ||
382 | FreeLibrary (nsp); | ||
383 | } | 402 | } |
384 | } | ||
385 | else if (wargc == 3) | 403 | else if (wargc == 3) |
386 | { | 404 | { |
387 | int s; | 405 | int s; |
388 | ADDRINFOW hints; | 406 | ADDRINFOW hints; |
389 | ADDRINFOW *result; | 407 | ADDRINFOW *result; |
390 | ADDRINFOW *pos; | 408 | ADDRINFOW *pos; |
391 | 409 | ||
392 | memset (&hints, 0, sizeof (struct addrinfo)); | 410 | memset(&hints, 0, sizeof(struct addrinfo)); |
393 | hints.ai_family = AF_UNSPEC; | 411 | hints.ai_family = AF_UNSPEC; |
394 | hints.ai_socktype = SOCK_STREAM; | 412 | hints.ai_socktype = SOCK_STREAM; |
395 | 413 | ||
396 | if (0 != (s = GetAddrInfoW (wargv[2], NULL, &hints, &result))) | 414 | if (0 != (s = GetAddrInfoW(wargv[2], NULL, &hints, &result))) |
397 | { | 415 | { |
398 | fprintf (stderr, "Cound not resolve `%S' using GetAddrInfoW: %lu\n", | 416 | fprintf(stderr, "Cound not resolve `%S' using GetAddrInfoW: %lu\n", |
399 | wargv[2], GetLastError ()); | 417 | wargv[2], GetLastError()); |
400 | } | 418 | } |
401 | else | 419 | else |
402 | { | 420 | { |
403 | for (pos = result; pos != NULL; pos = pos->ai_next) | 421 | for (pos = result; pos != NULL; pos = pos->ai_next) |
404 | { | 422 | { |
405 | wchar_t tmpbuf[1024]; | 423 | wchar_t tmpbuf[1024]; |
406 | DWORD buflen = 1024; | 424 | DWORD buflen = 1024; |
407 | if (0 == WSAAddressToStringW (pos->ai_addr, pos->ai_addrlen, NULL, tmpbuf, &buflen)) | 425 | if (0 == WSAAddressToStringW(pos->ai_addr, pos->ai_addrlen, NULL, tmpbuf, &buflen)) |
408 | fprintf (stderr, "Result:\n" | 426 | fprintf(stderr, "Result:\n" |
409 | " flags: 0x%X\n" | 427 | " flags: 0x%X\n" |
410 | " family: 0x%X\n" | 428 | " family: 0x%X\n" |
411 | " socktype: 0x%X\n" | 429 | " socktype: 0x%X\n" |
412 | " protocol: 0x%X\n" | 430 | " protocol: 0x%X\n" |
413 | " addrlen: %u\n" | 431 | " addrlen: %u\n" |
414 | " addr: %S\n" | 432 | " addr: %S\n" |
415 | " canonname: %S\n", | 433 | " canonname: %S\n", |
416 | pos->ai_flags, | 434 | pos->ai_flags, |
417 | pos->ai_family, | 435 | pos->ai_family, |
418 | pos->ai_socktype, | 436 | pos->ai_socktype, |
419 | pos->ai_protocol, | 437 | pos->ai_protocol, |
420 | pos->ai_addrlen, | 438 | pos->ai_addrlen, |
421 | tmpbuf, | 439 | tmpbuf, |
422 | pos->ai_canonname); | 440 | pos->ai_canonname); |
423 | else | 441 | else |
424 | fprintf (stderr, "Result:\n" | 442 | fprintf(stderr, "Result:\n" |
425 | " flags: 0x%X\n" | 443 | " flags: 0x%X\n" |
426 | " family: 0x%X\n" | 444 | " family: 0x%X\n" |
427 | " socktype: 0x%X\n" | 445 | " socktype: 0x%X\n" |
428 | " protocol: 0x%X\n" | 446 | " protocol: 0x%X\n" |
429 | " addrlen: %u\n" | 447 | " addrlen: %u\n" |
430 | " addr: %S\n" | 448 | " addr: %S\n" |
431 | " canonname: %S\n", | 449 | " canonname: %S\n", |
432 | pos->ai_flags, | 450 | pos->ai_flags, |
433 | pos->ai_family, | 451 | pos->ai_family, |
434 | pos->ai_socktype, | 452 | pos->ai_socktype, |
435 | pos->ai_protocol, | 453 | pos->ai_protocol, |
436 | pos->ai_addrlen, | 454 | pos->ai_addrlen, |
437 | L"<can't stringify>", | 455 | L"<can't stringify>", |
438 | pos->ai_canonname); | 456 | pos->ai_canonname); |
439 | } | 457 | } |
440 | if (NULL != result) | 458 | if (NULL != result) |
441 | FreeAddrInfoW (result); | 459 | FreeAddrInfoW(result); |
460 | } | ||
442 | } | 461 | } |
443 | } | ||
444 | WSACleanup(); | 462 | WSACleanup(); |
445 | return r; | 463 | return r; |
446 | } | 464 | } |
diff --git a/src/gns/w32nsp-uninstall.c b/src/gns/w32nsp-uninstall.c index b2a9b083e..f5031f341 100644 --- a/src/gns/w32nsp-uninstall.c +++ b/src/gns/w32nsp-uninstall.c | |||
@@ -6,26 +6,26 @@ | |||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | 7 | ||
8 | int | 8 | int |
9 | main (int argc, char **argv) | 9 | main(int argc, char **argv) |
10 | { | 10 | { |
11 | int ret; | 11 | int ret; |
12 | GUID id = GNUNET_NAMESPACE_PROVIDER_DNS; | 12 | GUID id = GNUNET_NAMESPACE_PROVIDER_DNS; |
13 | WSADATA wsd; | 13 | WSADATA wsd; |
14 | 14 | ||
15 | if (WSAStartup (MAKEWORD (2,2), &wsd) != 0) | 15 | if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0) |
16 | { | 16 | { |
17 | fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ()); | 17 | fprintf(stderr, "WSAStartup () failed: %lu\n", GetLastError()); |
18 | return 5; | 18 | return 5; |
19 | } | 19 | } |
20 | 20 | ||
21 | ret = WSCUnInstallNameSpace (&id); | 21 | ret = WSCUnInstallNameSpace(&id); |
22 | if (ret == NO_ERROR) | 22 | if (ret == NO_ERROR) |
23 | { | 23 | { |
24 | fprintf (stderr, "Uninstalled GNUnet DNS provider\n"); | 24 | fprintf(stderr, "Uninstalled GNUnet DNS provider\n"); |
25 | WSACleanup (); | 25 | WSACleanup(); |
26 | return 0; | 26 | return 0; |
27 | } | 27 | } |
28 | fprintf (stderr, "WSCUnInstallNameSpace () failed: %lu\n", GetLastError ()); | 28 | fprintf(stderr, "WSCUnInstallNameSpace () failed: %lu\n", GetLastError()); |
29 | WSACleanup (); | 29 | WSACleanup(); |
30 | return 1; | 30 | return 1; |
31 | } \ No newline at end of file | 31 | } \ No newline at end of file |
diff --git a/src/gns/w32nsp.c b/src/gns/w32nsp.c index 56d07a50c..5178cb822 100644 --- a/src/gns/w32nsp.c +++ b/src/gns/w32nsp.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/w32nsp.c | 21 | * @file gns/w32nsp.c |
22 | * @brief W32 integration for GNS | 22 | * @brief W32 integration for GNS |
@@ -32,7 +32,7 @@ | |||
32 | #endif | 32 | #endif |
33 | #if VERBOSE | 33 | #if VERBOSE |
34 | # define __printf__ printf | 34 | # define __printf__ printf |
35 | # define DEBUGLOG(s, ...) printf (s, ##__VA_ARGS__) | 35 | # define DEBUGLOG(s, ...) printf(s, ## __VA_ARGS__) |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <stdint.h> | 38 | #include <stdint.h> |
@@ -80,8 +80,7 @@ | |||
80 | 80 | ||
81 | static CRITICAL_SECTION records_cs; | 81 | static CRITICAL_SECTION records_cs; |
82 | 82 | ||
83 | struct record | 83 | struct record { |
84 | { | ||
85 | SOCKET s; | 84 | SOCKET s; |
86 | DWORD flags; | 85 | DWORD flags; |
87 | uint8_t state; | 86 | uint8_t state; |
@@ -94,58 +93,60 @@ static size_t records_len = 0; | |||
94 | static size_t records_size = 0; | 93 | static size_t records_size = 0; |
95 | 94 | ||
96 | static int | 95 | static int |
97 | resize_records () | 96 | resize_records() |
98 | { | 97 | { |
99 | size_t new_size = records_len > 0 ? records_len * 2 : 5; | 98 | size_t new_size = records_len > 0 ? records_len * 2 : 5; |
100 | struct record *new_records = malloc (new_size * sizeof (struct record)); | 99 | struct record *new_records = malloc(new_size * sizeof(struct record)); |
100 | |||
101 | if (new_records == NULL) | 101 | if (new_records == NULL) |
102 | { | 102 | { |
103 | SetLastError (WSA_NOT_ENOUGH_MEMORY); | 103 | SetLastError(WSA_NOT_ENOUGH_MEMORY); |
104 | return 0; | 104 | return 0; |
105 | } | 105 | } |
106 | GNUNET_memcpy (new_records, records, records_len * sizeof (struct record)); | 106 | GNUNET_memcpy(new_records, records, records_len * sizeof(struct record)); |
107 | memset (&new_records[records_len], 0, sizeof (struct record) * (new_size - records_len)); | 107 | memset(&new_records[records_len], 0, sizeof(struct record) * (new_size - records_len)); |
108 | records_size = new_size; | 108 | records_size = new_size; |
109 | free (records); | 109 | free(records); |
110 | records = new_records; | 110 | records = new_records; |
111 | return 1; | 111 | return 1; |
112 | } | 112 | } |
113 | 113 | ||
114 | static int | 114 | static int |
115 | add_record (SOCKET s, const wchar_t *name, DWORD flags) | 115 | add_record(SOCKET s, const wchar_t *name, DWORD flags) |
116 | { | 116 | { |
117 | int res = 1; | 117 | int res = 1; |
118 | int i; | 118 | int i; |
119 | int empty = -1; | 119 | int empty = -1; |
120 | |||
120 | //EnterCriticalSection (&records_cs); | 121 | //EnterCriticalSection (&records_cs); |
121 | for (i = 0; i < records_len; i++) | 122 | for (i = 0; i < records_len; i++) |
122 | if (records[i].state == 0) | 123 | if (records[i].state == 0) |
123 | break; | 124 | break; |
124 | empty = i; | 125 | empty = i; |
125 | if (i == records_len) | 126 | if (i == records_len) |
126 | { | 127 | { |
127 | res = resize_records (); | 128 | res = resize_records(); |
128 | if (res) | 129 | if (res) |
129 | empty = records_len++; | 130 | empty = records_len++; |
130 | } | 131 | } |
131 | if (res) | 132 | if (res) |
132 | { | 133 | { |
133 | struct record r; | 134 | struct record r; |
134 | r.s = s; | 135 | r.s = s; |
135 | r.flags = flags; | 136 | r.flags = flags; |
136 | r.name = (wchar_t *) name; | 137 | r.name = (wchar_t *)name; |
137 | r.state = 1; | 138 | r.state = 1; |
138 | r.buf = NULL; | 139 | r.buf = NULL; |
139 | if (name) | 140 | if (name) |
140 | r.name = wcsdup (name); | 141 | r.name = wcsdup(name); |
141 | records[empty] = r; | 142 | records[empty] = r; |
142 | } | 143 | } |
143 | //LeaveCriticalSection (&records_cs); | 144 | //LeaveCriticalSection (&records_cs); |
144 | return res; | 145 | return res; |
145 | } | 146 | } |
146 | 147 | ||
147 | /* These are not defined by mingw.org headers at the moment*/ | 148 | /* These are not defined by mingw.org headers at the moment*/ |
148 | typedef INT (WSPAPI *LPNSPIOCTL) (HANDLE,DWORD,LPVOID,DWORD,LPVOID,DWORD,LPDWORD,LPWSACOMPLETION,LPWSATHREADID); | 149 | typedef INT (WSPAPI *LPNSPIOCTL)(HANDLE, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPWSACOMPLETION, LPWSATHREADID); |
149 | typedef struct _NSP_ROUTINE_XP { | 150 | typedef struct _NSP_ROUTINE_XP { |
150 | DWORD cbSize; | 151 | DWORD cbSize; |
151 | DWORD dwMajorVersion; | 152 | DWORD dwMajorVersion; |
@@ -162,39 +163,39 @@ typedef struct _NSP_ROUTINE_XP { | |||
162 | } NSP_ROUTINE_XP; | 163 | } NSP_ROUTINE_XP; |
163 | 164 | ||
164 | static SOCKET | 165 | static SOCKET |
165 | connect_to_dns_resolver () | 166 | connect_to_dns_resolver() |
166 | { | 167 | { |
167 | struct sockaddr_in addr; | 168 | struct sockaddr_in addr; |
168 | SOCKET r; | 169 | SOCKET r; |
169 | int ret; | 170 | int ret; |
170 | 171 | ||
171 | r = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); | 172 | r = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
172 | if (INVALID_SOCKET == r) | 173 | if (INVALID_SOCKET == r) |
173 | { | 174 | { |
174 | SetLastError (16004); | 175 | SetLastError(16004); |
175 | return r; | 176 | return r; |
176 | } | 177 | } |
177 | 178 | ||
178 | addr.sin_family = AF_INET; | 179 | addr.sin_family = AF_INET; |
179 | addr.sin_port = htons (5353); /* TCP 5353 is not registered; UDP 5353 is */ | 180 | addr.sin_port = htons(5353); /* TCP 5353 is not registered; UDP 5353 is */ |
180 | addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); | 181 | addr.sin_addr.s_addr = inet_addr("127.0.0.1"); |
181 | 182 | ||
182 | ret = connect (r, (struct sockaddr *) &addr, sizeof (addr)); | 183 | ret = connect(r, (struct sockaddr *)&addr, sizeof(addr)); |
183 | if (SOCKET_ERROR == ret) | 184 | if (SOCKET_ERROR == ret) |
184 | { | 185 | { |
185 | DWORD err = GetLastError (); | 186 | DWORD err = GetLastError(); |
186 | closesocket (r); | 187 | closesocket(r); |
187 | SetLastError (err); | 188 | SetLastError(err); |
188 | SetLastError (16005); | 189 | SetLastError(16005); |
189 | r = INVALID_SOCKET; | 190 | r = INVALID_SOCKET; |
190 | } | 191 | } |
191 | return r; | 192 | return r; |
192 | } | 193 | } |
193 | 194 | ||
194 | static int | 195 | static int |
195 | send_name_to_ip_request (LPWSAQUERYSETW lpqsRestrictions, | 196 | send_name_to_ip_request(LPWSAQUERYSETW lpqsRestrictions, |
196 | LPWSASERVICECLASSINFOW lpServiceClassInfo, DWORD dwControlFlags, | 197 | LPWSASERVICECLASSINFOW lpServiceClassInfo, DWORD dwControlFlags, |
197 | SOCKET *resolver) | 198 | SOCKET *resolver) |
198 | { | 199 | { |
199 | struct GNUNET_W32RESOLVER_GetMessage *msg; | 200 | struct GNUNET_W32RESOLVER_GetMessage *msg; |
200 | int af4 = 0; | 201 | int af4 = 0; |
@@ -202,91 +203,95 @@ send_name_to_ip_request (LPWSAQUERYSETW lpqsRestrictions, | |||
202 | char *buf; | 203 | char *buf; |
203 | int ret = 1; | 204 | int ret = 1; |
204 | int i; | 205 | int i; |
205 | size_t size = sizeof (struct GNUNET_W32RESOLVER_GetMessage); | 206 | size_t size = sizeof(struct GNUNET_W32RESOLVER_GetMessage); |
206 | size_t namelen = 0; | 207 | size_t namelen = 0; |
208 | |||
207 | if (lpqsRestrictions->lpszServiceInstanceName) | 209 | if (lpqsRestrictions->lpszServiceInstanceName) |
208 | namelen = sizeof (wchar_t) * (wcslen (lpqsRestrictions->lpszServiceInstanceName) + 1); | 210 | namelen = sizeof(wchar_t) * (wcslen(lpqsRestrictions->lpszServiceInstanceName) + 1); |
209 | size += namelen; | 211 | size += namelen; |
210 | buf = malloc (size); | 212 | buf = malloc(size); |
211 | msg = (struct GNUNET_W32RESOLVER_GetMessage *) buf; | 213 | msg = (struct GNUNET_W32RESOLVER_GetMessage *)buf; |
212 | msg->header.size = htons (size); | 214 | msg->header.size = htons(size); |
213 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST); | 215 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST); |
214 | if (lpqsRestrictions->dwNumberOfProtocols > 0) | 216 | if (lpqsRestrictions->dwNumberOfProtocols > 0) |
215 | { | ||
216 | int i; | ||
217 | for (i = 0; i < lpqsRestrictions->dwNumberOfProtocols; i++) | ||
218 | { | 217 | { |
219 | if (lpqsRestrictions->lpafpProtocols[0].iAddressFamily == AF_INET) | 218 | int i; |
220 | af4 = 1; | 219 | for (i = 0; i < lpqsRestrictions->dwNumberOfProtocols; i++) |
221 | if (lpqsRestrictions->lpafpProtocols[0].iAddressFamily == AF_INET6) | 220 | { |
222 | af6 = 1; | 221 | if (lpqsRestrictions->lpafpProtocols[0].iAddressFamily == AF_INET) |
222 | af4 = 1; | ||
223 | if (lpqsRestrictions->lpafpProtocols[0].iAddressFamily == AF_INET6) | ||
224 | af6 = 1; | ||
225 | } | ||
223 | } | 226 | } |
224 | } | ||
225 | if (af4 && !af6) | 227 | if (af4 && !af6) |
226 | msg->af = htonl (AF_INET); | 228 | msg->af = htonl(AF_INET); |
227 | else if (af6 && !af4) | 229 | else if (af6 && !af4) |
228 | msg->af = htonl (AF_INET6); | 230 | msg->af = htonl(AF_INET6); |
229 | else | 231 | else |
230 | msg->af = htonl (AF_UNSPEC); | 232 | msg->af = htonl(AF_UNSPEC); |
231 | if (lpqsRestrictions->lpszServiceInstanceName) | 233 | if (lpqsRestrictions->lpszServiceInstanceName) |
232 | GNUNET_memcpy (&msg[1], lpqsRestrictions->lpszServiceInstanceName, namelen); | 234 | GNUNET_memcpy(&msg[1], lpqsRestrictions->lpszServiceInstanceName, namelen); |
233 | msg->sc_data1 = htonl (lpqsRestrictions->lpServiceClassId->Data1); | 235 | msg->sc_data1 = htonl(lpqsRestrictions->lpServiceClassId->Data1); |
234 | msg->sc_data2 = htons (lpqsRestrictions->lpServiceClassId->Data2); | 236 | msg->sc_data2 = htons(lpqsRestrictions->lpServiceClassId->Data2); |
235 | msg->sc_data3 = htons (lpqsRestrictions->lpServiceClassId->Data3); | 237 | msg->sc_data3 = htons(lpqsRestrictions->lpServiceClassId->Data3); |
236 | for (i = 0; i < 8; i++) | 238 | for (i = 0; i < 8; i++) |
237 | msg->sc_data4[i] = lpqsRestrictions->lpServiceClassId->Data4[i]; | 239 | msg->sc_data4[i] = lpqsRestrictions->lpServiceClassId->Data4[i]; |
238 | *resolver = connect_to_dns_resolver (); | 240 | *resolver = connect_to_dns_resolver(); |
239 | if (*resolver != INVALID_SOCKET) | 241 | if (*resolver != INVALID_SOCKET) |
240 | { | ||
241 | if (size != send (*resolver, buf, size, 0)) | ||
242 | { | 242 | { |
243 | if (size != send(*resolver, buf, size, 0)) | ||
244 | { | ||
243 | #if VERBOSE | 245 | #if VERBOSE |
244 | DWORD err = GetLastError (); | 246 | DWORD err = GetLastError(); |
245 | #endif | 247 | #endif |
246 | closesocket (*resolver); | 248 | closesocket(*resolver); |
247 | *resolver = INVALID_SOCKET; | 249 | *resolver = INVALID_SOCKET; |
248 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: failed to send request: %lu\n", err); | 250 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: failed to send request: %lu\n", err); |
249 | SetLastError (WSATRY_AGAIN); | 251 | SetLastError(WSATRY_AGAIN); |
250 | ret = 0; | 252 | ret = 0; |
253 | } | ||
251 | } | 254 | } |
252 | } | ||
253 | else | 255 | else |
254 | ret = 0; | 256 | ret = 0; |
255 | free (buf); | 257 | free(buf); |
256 | return ret; | 258 | return ret; |
257 | } | 259 | } |
258 | 260 | ||
259 | static int WSPAPI | 261 | static int WSPAPI |
260 | NSPCleanup (LPGUID lpProviderId) | 262 | NSPCleanup(LPGUID lpProviderId) |
261 | { | 263 | { |
262 | DEBUGLOG ("NSPCleanup\n"); | 264 | DEBUGLOG("NSPCleanup\n"); |
263 | if (IsEqualGUID (lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS)) | 265 | if (IsEqualGUID(lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS)) |
264 | { | 266 | { |
265 | return NO_ERROR; | 267 | return NO_ERROR; |
266 | } | 268 | } |
267 | SetLastError (WSAEINVALIDPROVIDER); | 269 | SetLastError(WSAEINVALIDPROVIDER); |
268 | return SOCKET_ERROR; | 270 | return SOCKET_ERROR; |
269 | } | 271 | } |
270 | 272 | ||
271 | BOOL WINAPI | 273 | BOOL WINAPI |
272 | DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | 274 | DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) |
273 | { | 275 | { |
274 | switch (fdwReason) | 276 | switch (fdwReason) |
275 | { | 277 | { |
276 | case DLL_PROCESS_ATTACH: | 278 | case DLL_PROCESS_ATTACH: |
277 | if (!InitializeCriticalSectionAndSpinCount (&records_cs, 0x00000400)) | 279 | if (!InitializeCriticalSectionAndSpinCount(&records_cs, 0x00000400)) |
278 | { | 280 | { |
279 | return FALSE; | 281 | return FALSE; |
280 | } | 282 | } |
281 | break; | 283 | break; |
284 | |||
282 | case DLL_THREAD_ATTACH: | 285 | case DLL_THREAD_ATTACH: |
283 | break; | 286 | break; |
287 | |||
284 | case DLL_THREAD_DETACH: | 288 | case DLL_THREAD_DETACH: |
285 | break; | 289 | break; |
290 | |||
286 | case DLL_PROCESS_DETACH: | 291 | case DLL_PROCESS_DETACH: |
287 | DeleteCriticalSection (&records_cs); | 292 | DeleteCriticalSection(&records_cs); |
288 | break; | 293 | break; |
289 | } | 294 | } |
290 | return TRUE; | 295 | return TRUE; |
291 | } | 296 | } |
292 | 297 | ||
@@ -294,374 +299,375 @@ DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | |||
294 | 299 | ||
295 | 300 | ||
296 | static int WSPAPI | 301 | static int WSPAPI |
297 | GNUNET_W32NSP_LookupServiceBegin (LPGUID lpProviderId, LPWSAQUERYSETW lpqsRestrictions, | 302 | GNUNET_W32NSP_LookupServiceBegin(LPGUID lpProviderId, LPWSAQUERYSETW lpqsRestrictions, |
298 | LPWSASERVICECLASSINFOW lpServiceClassInfo, DWORD dwControlFlags, | 303 | LPWSASERVICECLASSINFOW lpServiceClassInfo, DWORD dwControlFlags, |
299 | LPHANDLE lphLookup) | 304 | LPHANDLE lphLookup) |
300 | { | 305 | { |
301 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin\n"); | 306 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin\n"); |
302 | if (IsEqualGUID (lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS)) | 307 | if (IsEqualGUID(lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS)) |
303 | { | ||
304 | SOCKET s; | ||
305 | if (lpqsRestrictions->dwNameSpace != NS_DNS && lpqsRestrictions->dwNameSpace != NS_ALL) | ||
306 | { | 308 | { |
307 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: wrong namespace\n"); | 309 | SOCKET s; |
308 | SetLastError (WSAEINVAL); | 310 | if (lpqsRestrictions->dwNameSpace != NS_DNS && lpqsRestrictions->dwNameSpace != NS_ALL) |
311 | { | ||
312 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: wrong namespace\n"); | ||
313 | SetLastError(WSAEINVAL); | ||
314 | return SOCKET_ERROR; | ||
315 | } | ||
316 | if (lpqsRestrictions->lpszServiceInstanceName != NULL) | ||
317 | { | ||
318 | wchar_t *s = lpqsRestrictions->lpszServiceInstanceName; | ||
319 | size_t len = wcslen(s); | ||
320 | if (len >= 5 && wcscmp(&s[len - 5], L".zkey") == 0) | ||
321 | { | ||
322 | } | ||
323 | else if (len >= 4 && wcscmp(&s[len - 4], L".gnu") == 0) | ||
324 | { | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: unsupported TLD\n"); | ||
329 | SetLastError(WSAEINVAL); | ||
330 | return SOCKET_ERROR; | ||
331 | } | ||
332 | } | ||
333 | |||
334 | if (send_name_to_ip_request(lpqsRestrictions, | ||
335 | lpServiceClassInfo, dwControlFlags, &s)) | ||
336 | { | ||
337 | if (!(add_record(s, lpqsRestrictions->lpszServiceInstanceName, dwControlFlags))) | ||
338 | { | ||
339 | DWORD err = GetLastError(); | ||
340 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: failed to add a record\n"); | ||
341 | closesocket(s); | ||
342 | SetLastError(err); | ||
343 | return SOCKET_ERROR; | ||
344 | } | ||
345 | *lphLookup = (HANDLE)s; | ||
346 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: OK (%lu)\n", GetLastError()); | ||
347 | return NO_ERROR; | ||
348 | } | ||
309 | return SOCKET_ERROR; | 349 | return SOCKET_ERROR; |
310 | } | 350 | } |
311 | if (lpqsRestrictions->lpszServiceInstanceName != NULL) | 351 | DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: wrong provider\n"); |
312 | { | 352 | SetLastError(WSAEINVALIDPROVIDER); |
313 | wchar_t *s = lpqsRestrictions->lpszServiceInstanceName; | ||
314 | size_t len = wcslen (s); | ||
315 | if (len >= 5 && wcscmp (&s[len - 5], L".zkey") == 0) | ||
316 | { | ||
317 | } | ||
318 | else if (len >= 4 && wcscmp (&s[len - 4], L".gnu") == 0) | ||
319 | { | ||
320 | } | ||
321 | else | ||
322 | { | ||
323 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: unsupported TLD\n"); | ||
324 | SetLastError (WSAEINVAL); | ||
325 | return SOCKET_ERROR; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | if (send_name_to_ip_request (lpqsRestrictions, | ||
330 | lpServiceClassInfo, dwControlFlags, &s)) | ||
331 | { | ||
332 | if (!(add_record (s, lpqsRestrictions->lpszServiceInstanceName, dwControlFlags))) | ||
333 | { | ||
334 | DWORD err = GetLastError (); | ||
335 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: failed to add a record\n"); | ||
336 | closesocket (s); | ||
337 | SetLastError (err); | ||
338 | return SOCKET_ERROR; | ||
339 | } | ||
340 | *lphLookup = (HANDLE) s; | ||
341 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: OK (%lu)\n", GetLastError ()); | ||
342 | return NO_ERROR; | ||
343 | } | ||
344 | return SOCKET_ERROR; | ||
345 | } | ||
346 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceBegin: wrong provider\n"); | ||
347 | SetLastError (WSAEINVALIDPROVIDER); | ||
348 | return SOCKET_ERROR; | 353 | return SOCKET_ERROR; |
349 | } | 354 | } |
350 | 355 | ||
351 | #define UnmarshallPtr(ptr, ptrtype, base) \ | 356 | #define UnmarshallPtr(ptr, ptrtype, base) \ |
352 | if (ptr) \ | 357 | if (ptr) \ |
353 | ptr = (ptrtype *) (base + (uintptr_t) ptr) | 358 | ptr = (ptrtype *) (base + (uintptr_t)ptr) |
354 | 359 | ||
355 | static void | 360 | static void |
356 | UnmarshallWSAQUERYSETW (LPWSAQUERYSETW req) | 361 | UnmarshallWSAQUERYSETW(LPWSAQUERYSETW req) |
357 | { | 362 | { |
358 | int i; | 363 | int i; |
359 | char *base = (char *) req; | 364 | char *base = (char *)req; |
360 | UnmarshallPtr (req->lpszServiceInstanceName, wchar_t, base); | 365 | |
361 | UnmarshallPtr (req->lpServiceClassId, GUID, base); | 366 | UnmarshallPtr(req->lpszServiceInstanceName, wchar_t, base); |
362 | UnmarshallPtr (req->lpVersion, WSAVERSION, base); | 367 | UnmarshallPtr(req->lpServiceClassId, GUID, base); |
363 | UnmarshallPtr (req->lpszComment, wchar_t, base); | 368 | UnmarshallPtr(req->lpVersion, WSAVERSION, base); |
364 | UnmarshallPtr (req->lpNSProviderId, GUID, base); | 369 | UnmarshallPtr(req->lpszComment, wchar_t, base); |
365 | UnmarshallPtr (req->lpszContext, wchar_t, base); | 370 | UnmarshallPtr(req->lpNSProviderId, GUID, base); |
366 | UnmarshallPtr (req->lpafpProtocols, AFPROTOCOLS, base); | 371 | UnmarshallPtr(req->lpszContext, wchar_t, base); |
367 | UnmarshallPtr (req->lpszQueryString, wchar_t, base); | 372 | UnmarshallPtr(req->lpafpProtocols, AFPROTOCOLS, base); |
368 | UnmarshallPtr (req->lpcsaBuffer, CSADDR_INFO, base); | 373 | UnmarshallPtr(req->lpszQueryString, wchar_t, base); |
374 | UnmarshallPtr(req->lpcsaBuffer, CSADDR_INFO, base); | ||
369 | for (i = 0; i < req->dwNumberOfCsAddrs; i++) | 375 | for (i = 0; i < req->dwNumberOfCsAddrs; i++) |
370 | { | 376 | { |
371 | UnmarshallPtr (req->lpcsaBuffer[i].LocalAddr.lpSockaddr, SOCKADDR, base); | 377 | UnmarshallPtr(req->lpcsaBuffer[i].LocalAddr.lpSockaddr, SOCKADDR, base); |
372 | UnmarshallPtr (req->lpcsaBuffer[i].RemoteAddr.lpSockaddr, SOCKADDR, base); | 378 | UnmarshallPtr(req->lpcsaBuffer[i].RemoteAddr.lpSockaddr, SOCKADDR, base); |
373 | } | 379 | } |
374 | UnmarshallPtr (req->lpBlob, BLOB, base); | 380 | UnmarshallPtr(req->lpBlob, BLOB, base); |
375 | if (req->lpBlob) | 381 | if (req->lpBlob) |
376 | UnmarshallPtr (req->lpBlob->pBlobData, BYTE, base); | 382 | UnmarshallPtr(req->lpBlob->pBlobData, BYTE, base); |
377 | } | 383 | } |
378 | 384 | ||
379 | static int WSAAPI | 385 | static int WSAAPI |
380 | GNUNET_W32NSP_LookupServiceNext (HANDLE hLookup, DWORD dwControlFlags, | 386 | GNUNET_W32NSP_LookupServiceNext(HANDLE hLookup, DWORD dwControlFlags, |
381 | LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults) | 387 | LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults) |
382 | { | 388 | { |
383 | /*DWORD effective_flags;*/ | 389 | /*DWORD effective_flags;*/ |
384 | int i; | 390 | int i; |
385 | struct GNUNET_MessageHeader header = {0, 0}; | 391 | struct GNUNET_MessageHeader header = { 0, 0 }; |
386 | int rec = -1; | 392 | int rec = -1; |
387 | int rc; | 393 | int rc; |
388 | int to_receive; | 394 | int to_receive; |
389 | int t; | 395 | int t; |
390 | char *buf; | 396 | char *buf; |
391 | 397 | ||
392 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext\n"); | 398 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext\n"); |
393 | //EnterCriticalSection (&records_cs); | 399 | //EnterCriticalSection (&records_cs); |
394 | for (i = 0; i < records_len; i++) | 400 | for (i = 0; i < records_len; i++) |
395 | { | ||
396 | if (records[i].s == (SOCKET) hLookup) | ||
397 | { | 401 | { |
398 | rec = i; | 402 | if (records[i].s == (SOCKET)hLookup) |
399 | break; | 403 | { |
404 | rec = i; | ||
405 | break; | ||
406 | } | ||
400 | } | 407 | } |
401 | } | ||
402 | if (rec == -1) | 408 | if (rec == -1) |
403 | { | 409 | { |
404 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: invalid handle\n"); | 410 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: invalid handle\n"); |
405 | SetLastError (WSA_INVALID_HANDLE); | 411 | SetLastError(WSA_INVALID_HANDLE); |
406 | //LeaveCriticalSection (&records_cs); | 412 | //LeaveCriticalSection (&records_cs); |
407 | return SOCKET_ERROR; | 413 | return SOCKET_ERROR; |
408 | } | 414 | } |
409 | if (records[rec].state & 4) | 415 | if (records[rec].state & 4) |
410 | { | 416 | { |
411 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: session is closed\n"); | 417 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: session is closed\n"); |
412 | SetLastError (WSA_E_NO_MORE); | 418 | SetLastError(WSA_E_NO_MORE); |
413 | //LeaveCriticalSection (&records_cs); | 419 | //LeaveCriticalSection (&records_cs); |
414 | return SOCKET_ERROR; | 420 | return SOCKET_ERROR; |
415 | } | 421 | } |
416 | /*effective_flags = dwControlFlags & records[rec].flags;*/ | 422 | /*effective_flags = dwControlFlags & records[rec].flags;*/ |
417 | if (records[rec].buf) | 423 | if (records[rec].buf) |
418 | { | ||
419 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: checking buffer\n"); | ||
420 | header = *((struct GNUNET_MessageHeader *) records[rec].buf); | ||
421 | if (*lpdwBufferLength < header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage)) | ||
422 | { | 424 | { |
423 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: client buffer is too small\n"); | 425 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: checking buffer\n"); |
424 | SetLastError (WSAEFAULT); | 426 | header = *((struct GNUNET_MessageHeader *)records[rec].buf); |
427 | if (*lpdwBufferLength < header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage)) | ||
428 | { | ||
429 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: client buffer is too small\n"); | ||
430 | SetLastError(WSAEFAULT); | ||
431 | //LeaveCriticalSection (&records_cs); | ||
432 | return SOCKET_ERROR; | ||
433 | } | ||
434 | GNUNET_memcpy(lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)records[rec].buf)[1], header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage)); | ||
435 | free(records[rec].buf); | ||
436 | records[rec].buf = NULL; | ||
425 | //LeaveCriticalSection (&records_cs); | 437 | //LeaveCriticalSection (&records_cs); |
426 | return SOCKET_ERROR; | 438 | UnmarshallWSAQUERYSETW((LPWSAQUERYSETW)lpqsResults); |
439 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: OK (from buffer)\n"); | ||
440 | return NO_ERROR; | ||
427 | } | 441 | } |
428 | GNUNET_memcpy (lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)records[rec].buf)[1], header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage)); | ||
429 | free (records[rec].buf); | ||
430 | records[rec].buf = NULL; | ||
431 | //LeaveCriticalSection (&records_cs); | ||
432 | UnmarshallWSAQUERYSETW ((LPWSAQUERYSETW) lpqsResults); | ||
433 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: OK (from buffer)\n"); | ||
434 | return NO_ERROR; | ||
435 | } | ||
436 | records[rec].state |= 8; | 442 | records[rec].state |= 8; |
437 | //LeaveCriticalSection (&records_cs); | 443 | //LeaveCriticalSection (&records_cs); |
438 | to_receive = sizeof (header); | 444 | to_receive = sizeof(header); |
439 | rc = 0; | 445 | rc = 0; |
440 | #if VERBOSE | 446 | #if VERBOSE |
441 | { | 447 | { |
442 | unsigned long have; | 448 | unsigned long have; |
443 | int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have); | 449 | int ior = ioctlsocket((SOCKET)hLookup, FIONREAD, &have); |
444 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a header from %p, %lu bytes available\n", to_receive, hLookup, have); | 450 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a header from %p, %lu bytes available\n", to_receive, hLookup, have); |
445 | } | 451 | } |
446 | #endif | 452 | #endif |
447 | while (to_receive > 0) | 453 | while (to_receive > 0) |
448 | { | ||
449 | t = recv ((SOCKET) hLookup, &((char *) &header)[rc], to_receive, 0); | ||
450 | if (t > 0) | ||
451 | { | 454 | { |
452 | rc += t; | 455 | t = recv((SOCKET)hLookup, &((char *)&header)[rc], to_receive, 0); |
453 | to_receive -= t; | 456 | if (t > 0) |
457 | { | ||
458 | rc += t; | ||
459 | to_receive -= t; | ||
460 | } | ||
461 | else | ||
462 | break; | ||
454 | } | 463 | } |
455 | else | ||
456 | break; | ||
457 | } | ||
458 | #if VERBOSE | 464 | #if VERBOSE |
459 | { | 465 | { |
460 | unsigned long have; | 466 | unsigned long have; |
461 | int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have); | 467 | int ior = ioctlsocket((SOCKET)hLookup, FIONREAD, &have); |
462 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a header from %p, %lu bytes available\n", rc, hLookup, have); | 468 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a header from %p, %lu bytes available\n", rc, hLookup, have); |
463 | } | 469 | } |
464 | #endif | 470 | #endif |
465 | //EnterCriticalSection (&records_cs); | 471 | //EnterCriticalSection (&records_cs); |
466 | records[rec].state &= ~8; | 472 | records[rec].state &= ~8; |
467 | if (rc != sizeof (header)) | 473 | if (rc != sizeof(header)) |
468 | { | ||
469 | if (records[rec].state & 2) | ||
470 | { | ||
471 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: call cancelled\n"); | ||
472 | SetLastError (WSA_E_CANCELLED); | ||
473 | } | ||
474 | else | ||
475 | { | 474 | { |
476 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: failed to receive enough data for a header (rc %d != %u, state is 0x%0X)\n", rc, sizeof (header), records[rec].state); | 475 | if (records[rec].state & 2) |
477 | SetLastError (WSA_E_NO_MORE); | 476 | { |
477 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: call cancelled\n"); | ||
478 | SetLastError(WSA_E_CANCELLED); | ||
479 | } | ||
480 | else | ||
481 | { | ||
482 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: failed to receive enough data for a header (rc %d != %u, state is 0x%0X)\n", rc, sizeof(header), records[rec].state); | ||
483 | SetLastError(WSA_E_NO_MORE); | ||
484 | } | ||
485 | records[rec].state |= 4; | ||
486 | //LeaveCriticalSection (&records_cs); | ||
487 | return SOCKET_ERROR; | ||
478 | } | 488 | } |
479 | records[rec].state |= 4; | ||
480 | //LeaveCriticalSection (&records_cs); | ||
481 | return SOCKET_ERROR; | ||
482 | } | ||
483 | records[rec].state &= ~8; | 489 | records[rec].state &= ~8; |
484 | header.type = ntohs (header.type); | 490 | header.type = ntohs(header.type); |
485 | header.size = ntohs (header.size); | 491 | header.size = ntohs(header.size); |
486 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: header type %d, header size %u\n", header.type, header.size); | 492 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: header type %d, header size %u\n", header.type, header.size); |
487 | if (header.type != GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE || | 493 | if (header.type != GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE || |
488 | (header.type == GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE && | 494 | (header.type == GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE && |
489 | header.size == sizeof (header))) | 495 | header.size == sizeof(header))) |
490 | { | 496 | { |
491 | records[rec].state |= 4; | 497 | records[rec].state |= 4; |
492 | if (header.type != GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE) | 498 | if (header.type != GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE) |
493 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: header type is wrong\n"); | 499 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: header type is wrong\n"); |
494 | else | 500 | else |
495 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: empty header - no data\n"); | 501 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: empty header - no data\n"); |
496 | //LeaveCriticalSection (&records_cs); | 502 | //LeaveCriticalSection (&records_cs); |
497 | SetLastError (WSA_E_NO_MORE); | 503 | SetLastError(WSA_E_NO_MORE); |
498 | return SOCKET_ERROR; | 504 | return SOCKET_ERROR; |
499 | } | 505 | } |
500 | buf = malloc (header.size); | 506 | buf = malloc(header.size); |
501 | if (buf == NULL) | 507 | if (buf == NULL) |
502 | { | 508 | { |
503 | records[rec].state |= 4; | 509 | records[rec].state |= 4; |
504 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: malloc() failed\n"); | 510 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: malloc() failed\n"); |
505 | //LeaveCriticalSection (&records_cs); | 511 | //LeaveCriticalSection (&records_cs); |
506 | SetLastError (WSA_E_NO_MORE); | 512 | SetLastError(WSA_E_NO_MORE); |
507 | return SOCKET_ERROR; | 513 | return SOCKET_ERROR; |
508 | } | 514 | } |
509 | records[rec].state |= 8; | 515 | records[rec].state |= 8; |
510 | //LeaveCriticalSection (&records_cs); | 516 | //LeaveCriticalSection (&records_cs); |
511 | GNUNET_memcpy (buf, &header, sizeof (header)); | 517 | GNUNET_memcpy(buf, &header, sizeof(header)); |
512 | to_receive = header.size - sizeof (header); | 518 | to_receive = header.size - sizeof(header); |
513 | rc = 0; | 519 | rc = 0; |
514 | #if VERBOSE | 520 | #if VERBOSE |
515 | { | 521 | { |
516 | unsigned long have; | 522 | unsigned long have; |
517 | int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have); | 523 | int ior = ioctlsocket((SOCKET)hLookup, FIONREAD, &have); |
518 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a body from %p, %lu bytes available\n", to_receive, hLookup, have); | 524 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a body from %p, %lu bytes available\n", to_receive, hLookup, have); |
519 | } | 525 | } |
520 | #endif | 526 | #endif |
521 | while (to_receive > 0) | 527 | while (to_receive > 0) |
522 | { | ||
523 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: recv (%d)\n", to_receive); | ||
524 | t = recv ((SOCKET) hLookup, &((char *) &((struct GNUNET_MessageHeader *) buf)[1])[rc], to_receive, 0); | ||
525 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: recv returned %d\n", t); | ||
526 | if (t > 0) | ||
527 | { | 528 | { |
528 | rc += t; | 529 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: recv (%d)\n", to_receive); |
529 | to_receive -= t; | 530 | t = recv((SOCKET)hLookup, &((char *)&((struct GNUNET_MessageHeader *)buf)[1])[rc], to_receive, 0); |
531 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: recv returned %d\n", t); | ||
532 | if (t > 0) | ||
533 | { | ||
534 | rc += t; | ||
535 | to_receive -= t; | ||
536 | } | ||
537 | else | ||
538 | break; | ||
530 | } | 539 | } |
531 | else | ||
532 | break; | ||
533 | } | ||
534 | #if VERBOSE | 540 | #if VERBOSE |
535 | { | 541 | { |
536 | unsigned long have; | 542 | unsigned long have; |
537 | int ior = ioctlsocket ((SOCKET) hLookup, FIONREAD, &have); | 543 | int ior = ioctlsocket((SOCKET)hLookup, FIONREAD, &have); |
538 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a body from %p, %lu bytes available\n", rc, hLookup, have); | 544 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a body from %p, %lu bytes available\n", rc, hLookup, have); |
539 | } | 545 | } |
540 | #endif | 546 | #endif |
541 | //EnterCriticalSection (&records_cs); | 547 | //EnterCriticalSection (&records_cs); |
542 | records[rec].state &= ~8; | 548 | records[rec].state &= ~8; |
543 | if (rc != header.size - sizeof (header)) | 549 | if (rc != header.size - sizeof(header)) |
544 | { | ||
545 | free (buf); | ||
546 | if (records[rec].state & 2) | ||
547 | { | 550 | { |
548 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: call cancelled\n"); | 551 | free(buf); |
549 | SetLastError (WSA_E_CANCELLED); | 552 | if (records[rec].state & 2) |
553 | { | ||
554 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: call cancelled\n"); | ||
555 | SetLastError(WSA_E_CANCELLED); | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: failed to receive enough data for the rest (rc %d != %d, state is 0x%0X)\n", rc, header.size - sizeof(header), records[rec].state); | ||
560 | SetLastError(WSA_E_NO_MORE); | ||
561 | } | ||
562 | records[rec].state |= 4; | ||
563 | //LeaveCriticalSection (&records_cs); | ||
564 | return SOCKET_ERROR; | ||
550 | } | 565 | } |
551 | else | 566 | if (*lpdwBufferLength < header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage)) |
552 | { | 567 | { |
553 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: failed to receive enough data for the rest (rc %d != %d, state is 0x%0X)\n", rc, header.size - sizeof (header), records[rec].state); | 568 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: client buffer is too small\n"); |
554 | SetLastError (WSA_E_NO_MORE); | 569 | SetLastError(WSAEFAULT); |
570 | records[rec].buf = buf; | ||
571 | //LeaveCriticalSection (&records_cs); | ||
572 | return SOCKET_ERROR; | ||
555 | } | 573 | } |
556 | records[rec].state |= 4; | ||
557 | //LeaveCriticalSection (&records_cs); | ||
558 | return SOCKET_ERROR; | ||
559 | } | ||
560 | if (*lpdwBufferLength < header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage)) | ||
561 | { | ||
562 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: client buffer is too small\n"); | ||
563 | SetLastError (WSAEFAULT); | ||
564 | records[rec].buf = buf; | ||
565 | //LeaveCriticalSection (&records_cs); | ||
566 | return SOCKET_ERROR; | ||
567 | } | ||
568 | //LeaveCriticalSection (&records_cs); | 574 | //LeaveCriticalSection (&records_cs); |
569 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: writing %d bytes into result buffer\n", header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage)); | 575 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: writing %d bytes into result buffer\n", header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage)); |
570 | GNUNET_memcpy (lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)buf)[1], header.size - sizeof (struct GNUNET_W32RESOLVER_GetMessage)); | 576 | GNUNET_memcpy(lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)buf)[1], header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage)); |
571 | free (buf); | 577 | free(buf); |
572 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: OK\n"); | 578 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: OK\n"); |
573 | UnmarshallWSAQUERYSETW ((LPWSAQUERYSETW) lpqsResults); | 579 | UnmarshallWSAQUERYSETW((LPWSAQUERYSETW)lpqsResults); |
574 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceNext: returning (%lu)\n", GetLastError ()); | 580 | DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: returning (%lu)\n", GetLastError()); |
575 | return NO_ERROR; | 581 | return NO_ERROR; |
576 | } | 582 | } |
577 | 583 | ||
578 | static int WSPAPI | 584 | static int WSPAPI |
579 | GNUNET_W32NSP_LookupServiceEnd (HANDLE hLookup) | 585 | GNUNET_W32NSP_LookupServiceEnd(HANDLE hLookup) |
580 | { | 586 | { |
581 | int i; | 587 | int i; |
582 | int rec = -1; | 588 | int rec = -1; |
583 | 589 | ||
584 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceEnd\n"); | 590 | DEBUGLOG("GNUNET_W32NSP_LookupServiceEnd\n"); |
585 | //EnterCriticalSection (&records_cs); | 591 | //EnterCriticalSection (&records_cs); |
586 | for (i = 0; i < records_len; i++) | 592 | for (i = 0; i < records_len; i++) |
587 | { | ||
588 | if (records[i].s == (SOCKET) hLookup) | ||
589 | { | 593 | { |
590 | rec = i; | 594 | if (records[i].s == (SOCKET)hLookup) |
591 | break; | 595 | { |
596 | rec = i; | ||
597 | break; | ||
598 | } | ||
592 | } | 599 | } |
593 | } | ||
594 | if (rec == -1) | 600 | if (rec == -1) |
595 | { | 601 | { |
596 | SetLastError (WSA_INVALID_HANDLE); | 602 | SetLastError(WSA_INVALID_HANDLE); |
597 | //LeaveCriticalSection (&records_cs); | 603 | //LeaveCriticalSection (&records_cs); |
598 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceEnd: invalid handle\n"); | 604 | DEBUGLOG("GNUNET_W32NSP_LookupServiceEnd: invalid handle\n"); |
599 | return SOCKET_ERROR; | 605 | return SOCKET_ERROR; |
600 | } | 606 | } |
601 | records[rec].state |= 2; | 607 | records[rec].state |= 2; |
602 | closesocket (records[rec].s); | 608 | closesocket(records[rec].s); |
603 | while (records[rec].state & 8) | 609 | while (records[rec].state & 8) |
604 | { | 610 | { |
605 | //LeaveCriticalSection (&records_cs); | 611 | //LeaveCriticalSection (&records_cs); |
606 | Sleep (10); | 612 | Sleep(10); |
607 | //EnterCriticalSection (&records_cs); | 613 | //EnterCriticalSection (&records_cs); |
608 | } | 614 | } |
609 | if (records[rec].buf) | 615 | if (records[rec].buf) |
610 | free (records[rec].buf); | 616 | free(records[rec].buf); |
611 | records[rec].buf = NULL; | 617 | records[rec].buf = NULL; |
612 | records[rec].state = 0; | 618 | records[rec].state = 0; |
613 | if (records[rec].name) | 619 | if (records[rec].name) |
614 | free (records[rec].name); | 620 | free(records[rec].name); |
615 | //LeaveCriticalSection (&records_cs); | 621 | //LeaveCriticalSection (&records_cs); |
616 | DEBUGLOG ("GNUNET_W32NSP_LookupServiceEnd: OK\n"); | 622 | DEBUGLOG("GNUNET_W32NSP_LookupServiceEnd: OK\n"); |
617 | return NO_ERROR; | 623 | return NO_ERROR; |
618 | } | 624 | } |
619 | 625 | ||
620 | static int WSAAPI | 626 | static int WSAAPI |
621 | GNUNET_W32NSP_SetService (LPGUID lpProviderId, | 627 | GNUNET_W32NSP_SetService(LPGUID lpProviderId, |
622 | LPWSASERVICECLASSINFOW lpServiceClassInfo, LPWSAQUERYSETW lpqsRegInfo, | 628 | LPWSASERVICECLASSINFOW lpServiceClassInfo, LPWSAQUERYSETW lpqsRegInfo, |
623 | WSAESETSERVICEOP essOperation, DWORD dwControlFlags) | 629 | WSAESETSERVICEOP essOperation, DWORD dwControlFlags) |
624 | { | 630 | { |
625 | DEBUGLOG ("GNUNET_W32NSP_SetService\n"); | 631 | DEBUGLOG("GNUNET_W32NSP_SetService\n"); |
626 | SetLastError (WSAEOPNOTSUPP); | 632 | SetLastError(WSAEOPNOTSUPP); |
627 | return SOCKET_ERROR; | 633 | return SOCKET_ERROR; |
628 | } | 634 | } |
629 | 635 | ||
630 | static int WSAAPI | 636 | static int WSAAPI |
631 | GNUNET_W32NSP_InstallServiceClass (LPGUID lpProviderId, | 637 | GNUNET_W32NSP_InstallServiceClass(LPGUID lpProviderId, |
632 | LPWSASERVICECLASSINFOW lpServiceClassInfo) | 638 | LPWSASERVICECLASSINFOW lpServiceClassInfo) |
633 | { | 639 | { |
634 | DEBUGLOG ("GNUNET_W32NSP_InstallServiceClass\n"); | 640 | DEBUGLOG("GNUNET_W32NSP_InstallServiceClass\n"); |
635 | SetLastError (WSAEOPNOTSUPP); | 641 | SetLastError(WSAEOPNOTSUPP); |
636 | return SOCKET_ERROR; | 642 | return SOCKET_ERROR; |
637 | } | 643 | } |
638 | 644 | ||
639 | 645 | ||
640 | static int WSAAPI | 646 | static int WSAAPI |
641 | GNUNET_W32NSP_RemoveServiceClass (LPGUID lpProviderId, LPGUID lpServiceClassId) | 647 | GNUNET_W32NSP_RemoveServiceClass(LPGUID lpProviderId, LPGUID lpServiceClassId) |
642 | { | 648 | { |
643 | DEBUGLOG ("GNUNET_W32NSP_RemoveServiceClass\n"); | 649 | DEBUGLOG("GNUNET_W32NSP_RemoveServiceClass\n"); |
644 | SetLastError (WSAEOPNOTSUPP); | 650 | SetLastError(WSAEOPNOTSUPP); |
645 | return SOCKET_ERROR; | 651 | return SOCKET_ERROR; |
646 | } | 652 | } |
647 | 653 | ||
648 | static int WSAAPI | 654 | static int WSAAPI |
649 | GNUNET_W32NSP_GetServiceClassInfo (LPGUID lpProviderId, LPDWORD lpdwBufSize, | 655 | GNUNET_W32NSP_GetServiceClassInfo(LPGUID lpProviderId, LPDWORD lpdwBufSize, |
650 | LPWSASERVICECLASSINFOW lpServiceClassInfo) | 656 | LPWSASERVICECLASSINFOW lpServiceClassInfo) |
651 | { | 657 | { |
652 | DEBUGLOG ("GNUNET_W32NSP_GetServiceClassInfo\n"); | 658 | DEBUGLOG("GNUNET_W32NSP_GetServiceClassInfo\n"); |
653 | SetLastError (WSAEOPNOTSUPP); | 659 | SetLastError(WSAEOPNOTSUPP); |
654 | return SOCKET_ERROR; | 660 | return SOCKET_ERROR; |
655 | } | 661 | } |
656 | 662 | ||
657 | static int WSAAPI | 663 | static int WSAAPI |
658 | GNUNET_W32NSP_Ioctl (HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, | 664 | GNUNET_W32NSP_Ioctl(HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, |
659 | DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, | 665 | DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, |
660 | LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion, | 666 | LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion, |
661 | LPWSATHREADID lpThreadId) | 667 | LPWSATHREADID lpThreadId) |
662 | { | 668 | { |
663 | DEBUGLOG ("GNUNET_W32NSP_Ioctl\n"); | 669 | DEBUGLOG("GNUNET_W32NSP_Ioctl\n"); |
664 | SetLastError (WSAEOPNOTSUPP); | 670 | SetLastError(WSAEOPNOTSUPP); |
665 | return SOCKET_ERROR; | 671 | return SOCKET_ERROR; |
666 | } | 672 | } |
667 | 673 | ||
@@ -671,35 +677,35 @@ GNUNET_W32NSP_Ioctl (HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer, | |||
671 | * provider. All other routines are passed as pointers in lpnspRoutines. | 677 | * provider. All other routines are passed as pointers in lpnspRoutines. |
672 | */ | 678 | */ |
673 | int WSAAPI | 679 | int WSAAPI |
674 | GNUNET_W32NSP_NSPStartup (LPGUID lpProviderId, LPNSP_ROUTINE lpnspRoutines) | 680 | GNUNET_W32NSP_NSPStartup(LPGUID lpProviderId, LPNSP_ROUTINE lpnspRoutines) |
675 | { | 681 | { |
676 | if (IsEqualGUID (lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS)) | 682 | if (IsEqualGUID(lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS)) |
677 | { | ||
678 | if (!connect_to_dns_resolver ()) | ||
679 | { | 683 | { |
680 | return SOCKET_ERROR; | 684 | if (!connect_to_dns_resolver()) |
685 | { | ||
686 | return SOCKET_ERROR; | ||
687 | } | ||
688 | /* This assumes that NSP_ROUTINE struct doesn't have a NSPIoctl member. | ||
689 | * If it does, you need to use FIELD_OFFSET() macro to get offset of NSPIoctl | ||
690 | * and use that offset as cbSize. | ||
691 | */ | ||
692 | lpnspRoutines->cbSize = sizeof(NSP_ROUTINE); | ||
693 | |||
694 | lpnspRoutines->dwMajorVersion = NSPAPI_VERSION_MAJOR; | ||
695 | lpnspRoutines->dwMinorVersion = NSPAPI_VERSION_MINOR; | ||
696 | lpnspRoutines->NSPCleanup = NSPCleanup; | ||
697 | lpnspRoutines->NSPLookupServiceBegin = GNUNET_W32NSP_LookupServiceBegin; | ||
698 | lpnspRoutines->NSPLookupServiceNext = GNUNET_W32NSP_LookupServiceNext; | ||
699 | lpnspRoutines->NSPLookupServiceEnd = GNUNET_W32NSP_LookupServiceEnd; | ||
700 | lpnspRoutines->NSPSetService = GNUNET_W32NSP_SetService; | ||
701 | lpnspRoutines->NSPInstallServiceClass = GNUNET_W32NSP_InstallServiceClass; | ||
702 | lpnspRoutines->NSPRemoveServiceClass = GNUNET_W32NSP_RemoveServiceClass; | ||
703 | lpnspRoutines->NSPGetServiceClassInfo = GNUNET_W32NSP_GetServiceClassInfo; | ||
704 | /*((NSP_ROUTINE_XP *) lpnspRoutines)->NSPIoctl = GNUNET_W32NSP_Ioctl;*/ | ||
705 | lpnspRoutines->NSPIoctl = GNUNET_W32NSP_Ioctl; | ||
706 | return NO_ERROR; | ||
681 | } | 707 | } |
682 | /* This assumes that NSP_ROUTINE struct doesn't have a NSPIoctl member. | 708 | SetLastError(WSAEINVALIDPROVIDER); |
683 | * If it does, you need to use FIELD_OFFSET() macro to get offset of NSPIoctl | ||
684 | * and use that offset as cbSize. | ||
685 | */ | ||
686 | lpnspRoutines->cbSize = sizeof(NSP_ROUTINE); | ||
687 | |||
688 | lpnspRoutines->dwMajorVersion = NSPAPI_VERSION_MAJOR; | ||
689 | lpnspRoutines->dwMinorVersion = NSPAPI_VERSION_MINOR; | ||
690 | lpnspRoutines->NSPCleanup = NSPCleanup; | ||
691 | lpnspRoutines->NSPLookupServiceBegin = GNUNET_W32NSP_LookupServiceBegin; | ||
692 | lpnspRoutines->NSPLookupServiceNext = GNUNET_W32NSP_LookupServiceNext; | ||
693 | lpnspRoutines->NSPLookupServiceEnd = GNUNET_W32NSP_LookupServiceEnd; | ||
694 | lpnspRoutines->NSPSetService = GNUNET_W32NSP_SetService; | ||
695 | lpnspRoutines->NSPInstallServiceClass = GNUNET_W32NSP_InstallServiceClass; | ||
696 | lpnspRoutines->NSPRemoveServiceClass = GNUNET_W32NSP_RemoveServiceClass; | ||
697 | lpnspRoutines->NSPGetServiceClassInfo = GNUNET_W32NSP_GetServiceClassInfo; | ||
698 | /*((NSP_ROUTINE_XP *) lpnspRoutines)->NSPIoctl = GNUNET_W32NSP_Ioctl;*/ | ||
699 | lpnspRoutines->NSPIoctl = GNUNET_W32NSP_Ioctl; | ||
700 | return NO_ERROR; | ||
701 | } | ||
702 | SetLastError (WSAEINVALIDPROVIDER); | ||
703 | return SOCKET_ERROR; | 709 | return SOCKET_ERROR; |
704 | } | 710 | } |
705 | 711 | ||
diff --git a/src/gns/w32resolver.h b/src/gns/w32resolver.h index c73559cf0..17521ba50 100644 --- a/src/gns/w32resolver.h +++ b/src/gns/w32resolver.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -50,8 +50,7 @@ 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 | */ |
53 | struct GNUNET_W32RESOLVER_GetMessage | 53 | struct GNUNET_W32RESOLVER_GetMessage { |
54 | { | ||
55 | /** | 54 | /** |
56 | * Type: GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST | 55 | * Type: GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST |
57 | */ | 56 | */ |