diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/util | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/util')
87 files changed, 10509 insertions, 10612 deletions
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index 6f25abfd5..d138ffba1 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c | |||
@@ -42,8 +42,8 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second) | |||
42 | 42 | ||
43 | #if DEBUG_BANDWIDTH | 43 | #if DEBUG_BANDWIDTH |
44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
45 | "Initializing bandwidth of %u Bps\n", | 45 | "Initializing bandwidth of %u Bps\n", |
46 | (unsigned int) bytes_per_second); | 46 | (unsigned int) bytes_per_second); |
47 | #endif | 47 | #endif |
48 | ret.value__ = htonl (bytes_per_second); | 48 | ret.value__ = htonl (bytes_per_second); |
49 | return ret; | 49 | return ret; |
@@ -59,10 +59,10 @@ GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second) | |||
59 | */ | 59 | */ |
60 | struct GNUNET_BANDWIDTH_Value32NBO | 60 | struct GNUNET_BANDWIDTH_Value32NBO |
61 | GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, | 61 | GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, |
62 | struct GNUNET_BANDWIDTH_Value32NBO b2) | 62 | struct GNUNET_BANDWIDTH_Value32NBO b2) |
63 | { | 63 | { |
64 | return GNUNET_BANDWIDTH_value_init (GNUNET_MIN (ntohl (b1.value__), | 64 | return GNUNET_BANDWIDTH_value_init (GNUNET_MIN (ntohl (b1.value__), |
65 | ntohl (b2.value__))); | 65 | ntohl (b2.value__))); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
@@ -74,18 +74,20 @@ GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, | |||
74 | * @param deadline when is the deadline | 74 | * @param deadline when is the deadline |
75 | * @return number of bytes available at bps until deadline | 75 | * @return number of bytes available at bps until deadline |
76 | */ | 76 | */ |
77 | uint64_t | 77 | uint64_t |
78 | GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO bps, | 78 | GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO |
79 | struct GNUNET_TIME_Relative deadline) | 79 | bps, |
80 | struct GNUNET_TIME_Relative | ||
81 | deadline) | ||
80 | { | 82 | { |
81 | uint64_t b; | 83 | uint64_t b; |
82 | 84 | ||
83 | b = ntohl (bps.value__); | 85 | b = ntohl (bps.value__); |
84 | #if DEBUG_BANDWIDTH | 86 | #if DEBUG_BANDWIDTH |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Bandwidth has %llu bytes available until deadline in %llums\n", | 88 | "Bandwidth has %llu bytes available until deadline in %llums\n", |
87 | (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL), | 89 | (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL), |
88 | deadline.rel_value); | 90 | deadline.rel_value); |
89 | #endif | 91 | #endif |
90 | return (b * deadline.rel_value + 500LL) / 1000LL; | 92 | return (b * deadline.rel_value + 500LL) / 1000LL; |
91 | } | 93 | } |
@@ -101,26 +103,25 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO b | |||
101 | */ | 103 | */ |
102 | struct GNUNET_TIME_Relative | 104 | struct GNUNET_TIME_Relative |
103 | GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, | 105 | GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, |
104 | uint64_t size) | 106 | uint64_t size) |
105 | { | 107 | { |
106 | uint64_t b; | 108 | uint64_t b; |
107 | struct GNUNET_TIME_Relative ret; | 109 | struct GNUNET_TIME_Relative ret; |
108 | 110 | ||
109 | b = ntohl (bps.value__); | 111 | b = ntohl (bps.value__); |
110 | if (b == 0) | 112 | if (b == 0) |
111 | { | 113 | { |
112 | #if DEBUG_BANDWIDTH | 114 | #if DEBUG_BANDWIDTH |
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
114 | "Bandwidth suggests delay of infinity (zero bandwidth)\n"); | 116 | "Bandwidth suggests delay of infinity (zero bandwidth)\n"); |
115 | #endif | 117 | #endif |
116 | return GNUNET_TIME_UNIT_FOREVER_REL; | 118 | return GNUNET_TIME_UNIT_FOREVER_REL; |
117 | } | 119 | } |
118 | ret.rel_value = size * 1000LL / b; | 120 | ret.rel_value = size * 1000LL / b; |
119 | #if DEBUG_BANDWIDTH | 121 | #if DEBUG_BANDWIDTH |
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
121 | "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n", | 123 | "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n", |
122 | (unsigned long long) ret.rel_value, | 124 | (unsigned long long) ret.rel_value, (unsigned long long) size); |
123 | (unsigned long long) size); | ||
124 | #endif | 125 | #endif |
125 | return ret; | 126 | return ret; |
126 | } | 127 | } |
@@ -142,8 +143,8 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, | |||
142 | */ | 143 | */ |
143 | void | 144 | void |
144 | GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, | 145 | GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, |
145 | struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, | 146 | struct GNUNET_BANDWIDTH_Value32NBO |
146 | uint32_t max_carry_s) | 147 | bytes_per_second_limit, uint32_t max_carry_s) |
147 | { | 148 | { |
148 | av->consumption_since_last_update__ = 0; | 149 | av->consumption_since_last_update__ = 0; |
149 | av->last_update__ = GNUNET_TIME_absolute_get (); | 150 | av->last_update__ = GNUNET_TIME_absolute_get (); |
@@ -151,10 +152,10 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, | |||
151 | av->max_carry_s__ = max_carry_s; | 152 | av->max_carry_s__ = max_carry_s; |
152 | #if DEBUG_BANDWIDTH | 153 | #if DEBUG_BANDWIDTH |
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "Tracker %p initialized with %u Bps and max carry %u\n", | 155 | "Tracker %p initialized with %u Bps and max carry %u\n", |
155 | av, | 156 | av, |
156 | (unsigned int) av->available_bytes_per_s__, | 157 | (unsigned int) av->available_bytes_per_s__, |
157 | (unsigned int) max_carry_s); | 158 | (unsigned int) max_carry_s); |
158 | #endif | 159 | #endif |
159 | } | 160 | } |
160 | 161 | ||
@@ -176,26 +177,28 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) | |||
176 | 177 | ||
177 | now = GNUNET_TIME_absolute_get (); | 178 | now = GNUNET_TIME_absolute_get (); |
178 | delta_time = now.abs_value - av->last_update__.abs_value; | 179 | delta_time = now.abs_value - av->last_update__.abs_value; |
179 | delta_avail = (delta_time * ((unsigned long long) av->available_bytes_per_s__) + 500LL) / 1000LL; | 180 | delta_avail = |
181 | (delta_time * ((unsigned long long) av->available_bytes_per_s__) + | ||
182 | 500LL) / 1000LL; | ||
180 | av->consumption_since_last_update__ -= delta_avail; | 183 | av->consumption_since_last_update__ -= delta_avail; |
181 | av->last_update__ = now; | 184 | av->last_update__ = now; |
182 | if (av->consumption_since_last_update__ < 0) | 185 | if (av->consumption_since_last_update__ < 0) |
183 | { | 186 | { |
184 | left_bytes = - av->consumption_since_last_update__; | 187 | left_bytes = -av->consumption_since_last_update__; |
185 | max_carry = av->available_bytes_per_s__ * av->max_carry_s__; | 188 | max_carry = av->available_bytes_per_s__ * av->max_carry_s__; |
186 | if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE) | 189 | if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE) |
187 | max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE; | 190 | max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE; |
188 | if (max_carry > left_bytes) | 191 | if (max_carry > left_bytes) |
189 | av->consumption_since_last_update__ = -left_bytes; | 192 | av->consumption_since_last_update__ = -left_bytes; |
190 | else | 193 | else |
191 | av->consumption_since_last_update__ = -max_carry; | 194 | av->consumption_since_last_update__ = -max_carry; |
192 | } | 195 | } |
193 | #if DEBUG_BANDWIDTH | 196 | #if DEBUG_BANDWIDTH |
194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
195 | "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", | 198 | "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", |
196 | av, | 199 | av, |
197 | (unsigned int) av->available_bytes_per_s__, | 200 | (unsigned int) av->available_bytes_per_s__, |
198 | (unsigned long long) delta_time); | 201 | (unsigned long long) delta_time); |
199 | #endif | 202 | #endif |
200 | 203 | ||
201 | } | 204 | } |
@@ -214,41 +217,38 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) | |||
214 | */ | 217 | */ |
215 | int | 218 | int |
216 | GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, | 219 | GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, |
217 | ssize_t size) | 220 | ssize_t size) |
218 | { | 221 | { |
219 | int64_t nc; | 222 | int64_t nc; |
220 | 223 | ||
221 | #if DEBUG_BANDWIDTH | 224 | #if DEBUG_BANDWIDTH |
222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
223 | "Tracker %p consumes %d bytes\n", | 226 | "Tracker %p consumes %d bytes\n", av, (int) size); |
224 | av, | ||
225 | (int) size); | ||
226 | #endif | 227 | #endif |
227 | if (size > 0) | 228 | if (size > 0) |
229 | { | ||
230 | nc = av->consumption_since_last_update__ + size; | ||
231 | if (nc < av->consumption_since_last_update__) | ||
232 | { | ||
233 | GNUNET_break (0); | ||
234 | return GNUNET_SYSERR; | ||
235 | } | ||
236 | av->consumption_since_last_update__ = nc; | ||
237 | update_tracker (av); | ||
238 | if (av->consumption_since_last_update__ > 0) | ||
228 | { | 239 | { |
229 | nc = av->consumption_since_last_update__ + size; | ||
230 | if (nc < av->consumption_since_last_update__) | ||
231 | { | ||
232 | GNUNET_break (0); | ||
233 | return GNUNET_SYSERR; | ||
234 | } | ||
235 | av->consumption_since_last_update__ = nc; | ||
236 | update_tracker (av); | ||
237 | if (av->consumption_since_last_update__ > 0) | ||
238 | { | ||
239 | #if DEBUG_BANDWIDTH | 240 | #if DEBUG_BANDWIDTH |
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
241 | "Tracker %p consumption %llu bytes above limit\n", | 242 | "Tracker %p consumption %llu bytes above limit\n", |
242 | av, | 243 | av, (unsigned long long) av->consumption_since_last_update__); |
243 | (unsigned long long) av->consumption_since_last_update__); | ||
244 | #endif | 244 | #endif |
245 | return GNUNET_YES; | 245 | return GNUNET_YES; |
246 | } | ||
247 | } | 246 | } |
247 | } | ||
248 | else | 248 | else |
249 | { | 249 | { |
250 | av->consumption_since_last_update__ += size; | 250 | av->consumption_since_last_update__ += size; |
251 | } | 251 | } |
252 | return GNUNET_NO; | 252 | return GNUNET_NO; |
253 | } | 253 | } |
254 | 254 | ||
@@ -264,39 +264,35 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, | |||
264 | */ | 264 | */ |
265 | struct GNUNET_TIME_Relative | 265 | struct GNUNET_TIME_Relative |
266 | GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, | 266 | GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, |
267 | size_t size) | 267 | size_t size) |
268 | { | 268 | { |
269 | struct GNUNET_TIME_Relative ret; | 269 | struct GNUNET_TIME_Relative ret; |
270 | int64_t bytes_needed; | 270 | int64_t bytes_needed; |
271 | 271 | ||
272 | if (av->available_bytes_per_s__ == 0) | 272 | if (av->available_bytes_per_s__ == 0) |
273 | { | 273 | { |
274 | #if DEBUG_BANDWIDTH | 274 | #if DEBUG_BANDWIDTH |
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av); |
276 | "Tracker %p delay is infinity\n", | ||
277 | av); | ||
278 | #endif | 276 | #endif |
279 | return GNUNET_TIME_UNIT_FOREVER_REL; | 277 | return GNUNET_TIME_UNIT_FOREVER_REL; |
280 | } | 278 | } |
281 | update_tracker (av); | 279 | update_tracker (av); |
282 | bytes_needed = size + av->consumption_since_last_update__; | 280 | bytes_needed = size + av->consumption_since_last_update__; |
283 | if (bytes_needed <= 0) | 281 | if (bytes_needed <= 0) |
284 | { | 282 | { |
285 | #if DEBUG_BANDWIDTH | 283 | #if DEBUG_BANDWIDTH |
286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
287 | "Tracker %p delay for %u bytes is zero\n", | 285 | "Tracker %p delay for %u bytes is zero\n", |
288 | av, | 286 | av, (unsigned int) size); |
289 | (unsigned int) size); | ||
290 | #endif | 287 | #endif |
291 | return GNUNET_TIME_UNIT_ZERO; | 288 | return GNUNET_TIME_UNIT_ZERO; |
292 | } | 289 | } |
293 | ret.rel_value = 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__; | 290 | ret.rel_value = |
291 | 1000LL * bytes_needed / (unsigned long long) av->available_bytes_per_s__; | ||
294 | #if DEBUG_BANDWIDTH | 292 | #if DEBUG_BANDWIDTH |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Tracker %p delay for %u bytes is %llu ms\n", | 294 | "Tracker %p delay for %u bytes is %llu ms\n", |
297 | av, | 295 | av, (unsigned int) size, (unsigned long long) ret.rel_value); |
298 | (unsigned int) size, | ||
299 | (unsigned long long) ret.rel_value); | ||
300 | #endif | 296 | #endif |
301 | return ret; | 297 | return ret; |
302 | } | 298 | } |
@@ -309,8 +305,8 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, | |||
309 | * @param av tracker to query | 305 | * @param av tracker to query |
310 | * @return number of bytes available for consumption right now | 306 | * @return number of bytes available for consumption right now |
311 | */ | 307 | */ |
312 | int64_t | 308 | int64_t |
313 | GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av) | 309 | GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av) |
314 | { | 310 | { |
315 | struct GNUNET_BANDWIDTH_Value32NBO bps; | 311 | struct GNUNET_BANDWIDTH_Value32NBO bps; |
316 | uint64_t avail; | 312 | uint64_t avail; |
@@ -319,13 +315,13 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av) | |||
319 | update_tracker (av); | 315 | update_tracker (av); |
320 | bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__); | 316 | bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__); |
321 | avail = GNUNET_BANDWIDTH_value_get_available_until (bps, | 317 | avail = GNUNET_BANDWIDTH_value_get_available_until (bps, |
322 | GNUNET_TIME_absolute_get_duration (av->last_update__)); | 318 | GNUNET_TIME_absolute_get_duration |
319 | (av->last_update__)); | ||
323 | used = av->consumption_since_last_update__; | 320 | used = av->consumption_since_last_update__; |
324 | #if DEBUG_BANDWIDTH | 321 | #if DEBUG_BANDWIDTH |
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
326 | "Tracker %p available bandwidth is %lld bytes\n", | 323 | "Tracker %p available bandwidth is %lld bytes\n", |
327 | av, | 324 | av, (long long) (int64_t) (avail - used)); |
328 | (long long) (int64_t) (avail - used)); | ||
329 | #endif | 325 | #endif |
330 | return (int64_t) (avail - used); | 326 | return (int64_t) (avail - used); |
331 | } | 327 | } |
@@ -339,7 +335,8 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av) | |||
339 | */ | 335 | */ |
340 | void | 336 | void |
341 | GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, | 337 | GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, |
342 | struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit) | 338 | struct GNUNET_BANDWIDTH_Value32NBO |
339 | bytes_per_second_limit) | ||
343 | { | 340 | { |
344 | uint32_t old_limit; | 341 | uint32_t old_limit; |
345 | uint32_t new_limit; | 342 | uint32_t new_limit; |
@@ -347,15 +344,14 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, | |||
347 | new_limit = ntohl (bytes_per_second_limit.value__); | 344 | new_limit = ntohl (bytes_per_second_limit.value__); |
348 | #if DEBUG_BANDWIDTH | 345 | #if DEBUG_BANDWIDTH |
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
350 | "Tracker %p bandwidth changed to %u Bps\n", | 347 | "Tracker %p bandwidth changed to %u Bps\n", |
351 | av, | 348 | av, (unsigned int) new_limit); |
352 | (unsigned int) new_limit); | ||
353 | #endif | 349 | #endif |
354 | update_tracker (av); | 350 | update_tracker (av); |
355 | old_limit = av->available_bytes_per_s__; | 351 | old_limit = av->available_bytes_per_s__; |
356 | av->available_bytes_per_s__ = new_limit; | 352 | av->available_bytes_per_s__ = new_limit; |
357 | if (old_limit > new_limit) | 353 | if (old_limit > new_limit) |
358 | update_tracker (av); /* maximum excess might be less now */ | 354 | update_tracker (av); /* maximum excess might be less now */ |
359 | } | 355 | } |
360 | 356 | ||
361 | 357 | ||
diff --git a/src/util/bio.c b/src/util/bio.c index 3fc7d05e6..b29d75eb9 100644 --- a/src/util/bio.c +++ b/src/util/bio.c | |||
@@ -56,8 +56,7 @@ GNUNET_BIO_read_open (const char *fn) | |||
56 | struct GNUNET_DISK_FileHandle *fd; | 56 | struct GNUNET_DISK_FileHandle *fd; |
57 | struct GNUNET_BIO_ReadHandle *h; | 57 | struct GNUNET_BIO_ReadHandle *h; |
58 | 58 | ||
59 | fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, | 59 | fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); |
60 | GNUNET_DISK_PERM_NONE); | ||
61 | if (NULL == fd) | 60 | if (NULL == fd) |
62 | return NULL; | 61 | return NULL; |
63 | h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); | 62 | h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); |
@@ -114,39 +113,37 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | |||
114 | return GNUNET_SYSERR; | 113 | return GNUNET_SYSERR; |
115 | pos = 0; | 114 | pos = 0; |
116 | do | 115 | do |
116 | { | ||
117 | /* first, use buffer */ | ||
118 | min = h->have - h->pos; | ||
119 | if (min > 0) | ||
117 | { | 120 | { |
118 | /* first, use buffer */ | 121 | if (min > len - pos) |
119 | min = h->have - h->pos; | 122 | min = len - pos; |
120 | if (min > 0) | 123 | memcpy (&dst[pos], &h->buffer[h->pos], min); |
121 | { | 124 | h->pos += min; |
122 | if (min > len - pos) | 125 | pos += min; |
123 | min = len - pos; | 126 | } |
124 | memcpy (&dst[pos], &h->buffer[h->pos], min); | 127 | if (pos == len) |
125 | h->pos += min; | 128 | return GNUNET_OK; /* done! */ |
126 | pos += min; | 129 | GNUNET_assert (h->have == h->pos); |
127 | } | 130 | /* fill buffer */ |
128 | if (pos == len) | 131 | ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); |
129 | return GNUNET_OK; /* done! */ | 132 | if (ret == -1) |
130 | GNUNET_assert (h->have == h->pos); | 133 | { |
131 | /* fill buffer */ | 134 | GNUNET_asprintf (&h->emsg, |
132 | ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); | 135 | _("Error reading `%s': %s"), what, STRERROR (errno)); |
133 | if (ret == -1) | 136 | return GNUNET_SYSERR; |
134 | { | 137 | } |
135 | GNUNET_asprintf (&h->emsg, | 138 | if (ret == 0) |
136 | _("Error reading `%s': %s"), | 139 | { |
137 | what, STRERROR (errno)); | 140 | GNUNET_asprintf (&h->emsg, |
138 | return GNUNET_SYSERR; | 141 | _("Error reading `%s': %s"), what, _("End of file")); |
139 | } | 142 | return GNUNET_SYSERR; |
140 | if (ret == 0) | ||
141 | { | ||
142 | GNUNET_asprintf (&h->emsg, | ||
143 | _("Error reading `%s': %s"), | ||
144 | what, _("End of file")); | ||
145 | return GNUNET_SYSERR; | ||
146 | } | ||
147 | h->pos = 0; | ||
148 | h->have = ret; | ||
149 | } | 143 | } |
144 | h->pos = 0; | ||
145 | h->have = ret; | ||
146 | } | ||
150 | while (pos < len); /* should always be true */ | 147 | while (pos < len); /* should always be true */ |
151 | return GNUNET_OK; | 148 | return GNUNET_OK; |
152 | } | 149 | } |
@@ -162,16 +159,13 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | |||
162 | * @param len the number of bytes to read | 159 | * @param len the number of bytes to read |
163 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 160 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure |
164 | */ | 161 | */ |
165 | int GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, | 162 | int |
166 | const char *file, int line, | 163 | GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, |
167 | void *result, | 164 | const char *file, int line, void *result, size_t len) |
168 | size_t len) | ||
169 | { | 165 | { |
170 | char what[1024]; | 166 | char what[1024]; |
171 | GNUNET_snprintf (what, | 167 | |
172 | sizeof(what), | 168 | GNUNET_snprintf (what, sizeof (what), "%s:%d", file, line); |
173 | "%s:%d", | ||
174 | file, line); | ||
175 | return GNUNET_BIO_read (h, what, result, len); | 169 | return GNUNET_BIO_read (h, what, result, len); |
176 | } | 170 | } |
177 | 171 | ||
@@ -194,36 +188,34 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, | |||
194 | uint32_t big; | 188 | uint32_t big; |
195 | 189 | ||
196 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big)) | 190 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big)) |
197 | { | 191 | { |
198 | GNUNET_free_non_null (h->emsg); | 192 | GNUNET_free_non_null (h->emsg); |
199 | GNUNET_asprintf (&h->emsg, | 193 | GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what); |
200 | _("Error reading length of string `%s'"), | 194 | return GNUNET_SYSERR; |
201 | what); | 195 | } |
202 | return GNUNET_SYSERR; | ||
203 | } | ||
204 | if (big == 0) | 196 | if (big == 0) |
205 | { | 197 | { |
206 | *result = NULL; | 198 | *result = NULL; |
207 | return GNUNET_OK; | 199 | return GNUNET_OK; |
208 | } | 200 | } |
209 | if (big > maxLen) | 201 | if (big > maxLen) |
210 | { | 202 | { |
211 | GNUNET_asprintf (&h->emsg, | 203 | GNUNET_asprintf (&h->emsg, |
212 | _("String `%s' longer than allowed (%u > %u)"), | 204 | _("String `%s' longer than allowed (%u > %u)"), |
213 | what, big, maxLen); | 205 | what, big, maxLen); |
214 | return GNUNET_SYSERR; | 206 | return GNUNET_SYSERR; |
215 | } | 207 | } |
216 | buf = GNUNET_malloc (big); | 208 | buf = GNUNET_malloc (big); |
217 | *result = buf; | 209 | *result = buf; |
218 | buf[--big] = '\0'; | 210 | buf[--big] = '\0'; |
219 | if (big == 0) | 211 | if (big == 0) |
220 | return GNUNET_OK; | 212 | return GNUNET_OK; |
221 | if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) | 213 | if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) |
222 | { | 214 | { |
223 | GNUNET_free (buf); | 215 | GNUNET_free (buf); |
224 | *result = NULL; | 216 | *result = NULL; |
225 | return GNUNET_SYSERR; | 217 | return GNUNET_SYSERR; |
226 | } | 218 | } |
227 | return GNUNET_OK; | 219 | return GNUNET_OK; |
228 | } | 220 | } |
229 | 221 | ||
@@ -245,34 +237,33 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
245 | char *buf; | 237 | char *buf; |
246 | struct GNUNET_CONTAINER_MetaData *meta; | 238 | struct GNUNET_CONTAINER_MetaData *meta; |
247 | 239 | ||
248 | if (GNUNET_BIO_read_int32 (h, (int32_t *) &size) != GNUNET_OK) | 240 | if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK) |
249 | return GNUNET_SYSERR; | 241 | return GNUNET_SYSERR; |
250 | if (size == 0) | 242 | if (size == 0) |
251 | { | 243 | { |
252 | *result = NULL; | 244 | *result = NULL; |
253 | return GNUNET_OK; | 245 | return GNUNET_OK; |
254 | } | 246 | } |
255 | if (size > MAX_META_DATA) | 247 | if (size > MAX_META_DATA) |
256 | { | 248 | { |
257 | GNUNET_asprintf (&h->emsg, | 249 | GNUNET_asprintf (&h->emsg, |
258 | _("Serialized metadata `%s' larger than allowed (%u>%u)"), | 250 | _("Serialized metadata `%s' larger than allowed (%u>%u)"), |
259 | what, size, MAX_META_DATA); | 251 | what, size, MAX_META_DATA); |
260 | return GNUNET_SYSERR; | 252 | return GNUNET_SYSERR; |
261 | } | 253 | } |
262 | buf = GNUNET_malloc (size); | 254 | buf = GNUNET_malloc (size); |
263 | if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) | 255 | if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) |
264 | { | 256 | { |
265 | GNUNET_free (buf); | 257 | GNUNET_free (buf); |
266 | return GNUNET_SYSERR; | 258 | return GNUNET_SYSERR; |
267 | } | 259 | } |
268 | meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size); | 260 | meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size); |
269 | if (meta == NULL) | 261 | if (meta == NULL) |
270 | { | 262 | { |
271 | GNUNET_free (buf); | 263 | GNUNET_free (buf); |
272 | GNUNET_asprintf (&h->emsg, | 264 | GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what); |
273 | _("Metadata `%s' failed to deserialize"), what); | 265 | return GNUNET_SYSERR; |
274 | return GNUNET_SYSERR; | 266 | } |
275 | } | ||
276 | GNUNET_free (buf); | 267 | GNUNET_free (buf); |
277 | *result = meta; | 268 | *result = meta; |
278 | return GNUNET_OK; | 269 | return GNUNET_OK; |
@@ -290,9 +281,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
290 | */ | 281 | */ |
291 | int | 282 | int |
292 | GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, | 283 | GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, |
293 | const char *file, | 284 | const char *file, int line, int32_t * i) |
294 | int line, | ||
295 | int32_t * i) | ||
296 | { | 285 | { |
297 | int32_t big; | 286 | int32_t big; |
298 | 287 | ||
@@ -314,9 +303,7 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, | |||
314 | */ | 303 | */ |
315 | int | 304 | int |
316 | GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, | 305 | GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, |
317 | const char *file, | 306 | const char *file, int line, int64_t * i) |
318 | int line, | ||
319 | int64_t * i) | ||
320 | { | 307 | { |
321 | int64_t big; | 308 | int64_t big; |
322 | 309 | ||
@@ -359,8 +346,7 @@ GNUNET_BIO_write_open (const char *fn) | |||
359 | GNUNET_DISK_PERM_USER_WRITE); | 346 | GNUNET_DISK_PERM_USER_WRITE); |
360 | if (NULL == fd) | 347 | if (NULL == fd) |
361 | return NULL; | 348 | return NULL; |
362 | h = | 349 | h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); |
363 | GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); | ||
364 | h->buffer = (char *) &h[1]; | 350 | h->buffer = (char *) &h[1]; |
365 | h->size = BIO_BUFFER_SIZE; | 351 | h->size = BIO_BUFFER_SIZE; |
366 | h->fd = fd; | 352 | h->fd = fd; |
@@ -382,18 +368,18 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) | |||
382 | int ret; | 368 | int ret; |
383 | 369 | ||
384 | if (NULL == h->fd) | 370 | if (NULL == h->fd) |
385 | { | 371 | { |
386 | ret = GNUNET_SYSERR; | 372 | ret = GNUNET_SYSERR; |
387 | } | 373 | } |
388 | else | 374 | else |
389 | { | 375 | { |
390 | wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); | 376 | wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); |
391 | if (wrt == h->have) | 377 | if (wrt == h->have) |
392 | ret = GNUNET_OK; | 378 | ret = GNUNET_OK; |
393 | else | 379 | else |
394 | ret = GNUNET_SYSERR; | 380 | ret = GNUNET_SYSERR; |
395 | GNUNET_DISK_file_close (h->fd); | 381 | GNUNET_DISK_file_close (h->fd); |
396 | } | 382 | } |
397 | GNUNET_free (h); | 383 | GNUNET_free (h); |
398 | return ret; | 384 | return ret; |
399 | } | 385 | } |
@@ -420,26 +406,26 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, | |||
420 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |
421 | pos = 0; | 407 | pos = 0; |
422 | do | 408 | do |
409 | { | ||
410 | /* first, just use buffer */ | ||
411 | min = h->size - h->have; | ||
412 | if (min > n - pos) | ||
413 | min = n - pos; | ||
414 | memcpy (&h->buffer[h->have], &src[pos], min); | ||
415 | pos += min; | ||
416 | h->have += min; | ||
417 | if (pos == n) | ||
418 | return GNUNET_OK; /* done */ | ||
419 | GNUNET_assert (h->have == h->size); | ||
420 | ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size); | ||
421 | if (ret != h->size) | ||
423 | { | 422 | { |
424 | /* first, just use buffer */ | 423 | GNUNET_DISK_file_close (h->fd); |
425 | min = h->size - h->have; | 424 | h->fd = NULL; |
426 | if (min > n - pos) | 425 | return GNUNET_SYSERR; /* error */ |
427 | min = n - pos; | ||
428 | memcpy (&h->buffer[h->have], &src[pos], min); | ||
429 | pos += min; | ||
430 | h->have += min; | ||
431 | if (pos == n) | ||
432 | return GNUNET_OK; /* done */ | ||
433 | GNUNET_assert (h->have == h->size); | ||
434 | ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size); | ||
435 | if (ret != h->size) | ||
436 | { | ||
437 | GNUNET_DISK_file_close (h->fd); | ||
438 | h->fd = NULL; | ||
439 | return GNUNET_SYSERR; /* error */ | ||
440 | } | ||
441 | h->have = 0; | ||
442 | } | 426 | } |
427 | h->have = 0; | ||
428 | } | ||
443 | while (pos < n); /* should always be true */ | 429 | while (pos < n); /* should always be true */ |
444 | GNUNET_break (0); | 430 | GNUNET_break (0); |
445 | return GNUNET_OK; | 431 | return GNUNET_OK; |
@@ -480,25 +466,25 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, | |||
480 | { | 466 | { |
481 | ssize_t size; | 467 | ssize_t size; |
482 | char *buf; | 468 | char *buf; |
483 | 469 | ||
484 | if (m == NULL) | 470 | if (m == NULL) |
485 | return GNUNET_BIO_write_int32 (h, 0); | 471 | return GNUNET_BIO_write_int32 (h, 0); |
486 | buf = NULL; | 472 | buf = NULL; |
487 | size = GNUNET_CONTAINER_meta_data_serialize (m, | 473 | size = GNUNET_CONTAINER_meta_data_serialize (m, |
488 | &buf, | 474 | &buf, |
489 | MAX_META_DATA, | 475 | MAX_META_DATA, |
490 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 476 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
491 | if (size == -1) | 477 | if (size == -1) |
492 | { | 478 | { |
493 | GNUNET_free (buf); | 479 | GNUNET_free (buf); |
494 | return GNUNET_SYSERR; | 480 | return GNUNET_SYSERR; |
495 | } | 481 | } |
496 | if ( (GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) || | 482 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) || |
497 | (GNUNET_OK != GNUNET_BIO_write (h, buf, size)) ) | 483 | (GNUNET_OK != GNUNET_BIO_write (h, buf, size))) |
498 | { | 484 | { |
499 | GNUNET_free (buf); | 485 | GNUNET_free (buf); |
500 | return GNUNET_SYSERR; | 486 | return GNUNET_SYSERR; |
501 | } | 487 | } |
502 | GNUNET_free (buf); | 488 | GNUNET_free (buf); |
503 | return GNUNET_OK; | 489 | return GNUNET_OK; |
504 | } | 490 | } |
@@ -515,6 +501,7 @@ int | |||
515 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i) | 501 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i) |
516 | { | 502 | { |
517 | int32_t big; | 503 | int32_t big; |
504 | |||
518 | big = htonl (i); | 505 | big = htonl (i); |
519 | return GNUNET_BIO_write (h, &big, sizeof (int32_t)); | 506 | return GNUNET_BIO_write (h, &big, sizeof (int32_t)); |
520 | } | 507 | } |
@@ -531,6 +518,7 @@ int | |||
531 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i) | 518 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i) |
532 | { | 519 | { |
533 | int64_t big; | 520 | int64_t big; |
521 | |||
534 | big = GNUNET_htonll (i); | 522 | big = GNUNET_htonll (i); |
535 | return GNUNET_BIO_write (h, &big, sizeof (int64_t)); | 523 | return GNUNET_BIO_write (h, &big, sizeof (int64_t)); |
536 | } | 524 | } |
diff --git a/src/util/client.c b/src/util/client.c index db53ab6f2..032a6c5e4 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -243,7 +243,7 @@ struct GNUNET_CLIENT_Connection | |||
243 | * Are we ignoring shutdown signals? | 243 | * Are we ignoring shutdown signals? |
244 | */ | 244 | */ |
245 | int ignore_shutdown; | 245 | int ignore_shutdown; |
246 | 246 | ||
247 | /** | 247 | /** |
248 | * How often have we tried to connect? | 248 | * How often have we tried to connect? |
249 | */ | 249 | */ |
@@ -262,8 +262,7 @@ struct GNUNET_CLIENT_Connection | |||
262 | */ | 262 | */ |
263 | static struct GNUNET_CONNECTION_Handle * | 263 | static struct GNUNET_CONNECTION_Handle * |
264 | do_connect (const char *service_name, | 264 | do_connect (const char *service_name, |
265 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 265 | const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int attempt) |
266 | unsigned int attempt) | ||
267 | { | 266 | { |
268 | struct GNUNET_CONNECTION_Handle *sock; | 267 | struct GNUNET_CONNECTION_Handle *sock; |
269 | char *hostname; | 268 | char *hostname; |
@@ -273,27 +272,24 @@ do_connect (const char *service_name, | |||
273 | sock = NULL; | 272 | sock = NULL; |
274 | #if AF_UNIX | 273 | #if AF_UNIX |
275 | if (0 == (attempt % 2)) | 274 | if (0 == (attempt % 2)) |
275 | { | ||
276 | /* on even rounds, try UNIX */ | ||
277 | unixpath = NULL; | ||
278 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ | ||
276 | { | 279 | { |
277 | /* on even rounds, try UNIX */ | 280 | sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath); |
278 | unixpath = NULL; | 281 | if (sock != NULL) |
279 | if ( (GNUNET_OK == | 282 | { |
280 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
281 | service_name, | ||
282 | "UNIXPATH", &unixpath)) && | ||
283 | (0 < strlen (unixpath)) ) /* We have a non-NULL unixpath, does that mean it's valid? */ | ||
284 | { | ||
285 | sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath); | ||
286 | if (sock != NULL) | ||
287 | { | ||
288 | #if DEBUG_CLIENT | 283 | #if DEBUG_CLIENT |
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n", unixpath); | 284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n", |
285 | unixpath); | ||
290 | #endif | 286 | #endif |
291 | GNUNET_free(unixpath); | 287 | GNUNET_free (unixpath); |
292 | return sock; | 288 | return sock; |
293 | } | 289 | } |
294 | } | ||
295 | GNUNET_free_non_null (unixpath); | ||
296 | } | 290 | } |
291 | GNUNET_free_non_null (unixpath); | ||
292 | } | ||
297 | #endif | 293 | #endif |
298 | 294 | ||
299 | if ((GNUNET_OK != | 295 | if ((GNUNET_OK != |
@@ -306,57 +302,56 @@ do_connect (const char *service_name, | |||
306 | GNUNET_CONFIGURATION_get_value_string (cfg, | 302 | GNUNET_CONFIGURATION_get_value_string (cfg, |
307 | service_name, | 303 | service_name, |
308 | "HOSTNAME", &hostname))) | 304 | "HOSTNAME", &hostname))) |
309 | { | 305 | { |
310 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 306 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
311 | _("Could not determine valid hostname and port for service `%s' from configuration.\n"), | 307 | _ |
312 | service_name); | 308 | ("Could not determine valid hostname and port for service `%s' from configuration.\n"), |
313 | return NULL; | 309 | service_name); |
314 | } | 310 | return NULL; |
311 | } | ||
315 | if (0 == strlen (hostname)) | 312 | if (0 == strlen (hostname)) |
316 | { | 313 | { |
317 | GNUNET_free (hostname); | 314 | GNUNET_free (hostname); |
318 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 315 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
319 | _("Need a non-empty hostname for service `%s'.\n"), | 316 | _("Need a non-empty hostname for service `%s'.\n"), |
320 | service_name); | 317 | service_name); |
321 | return NULL; | 318 | return NULL; |
322 | } | 319 | } |
323 | if (port == 0) | 320 | if (port == 0) |
324 | { | 321 | { |
325 | #if AF_UNIX | 322 | #if AF_UNIX |
326 | if (0 != (attempt % 2)) | 323 | if (0 != (attempt % 2)) |
327 | { | 324 | { |
328 | /* try UNIX */ | 325 | /* try UNIX */ |
329 | unixpath = NULL; | 326 | unixpath = NULL; |
330 | if ( (GNUNET_OK == | 327 | if ((GNUNET_OK == |
331 | GNUNET_CONFIGURATION_get_value_string (cfg, | 328 | GNUNET_CONFIGURATION_get_value_string (cfg, |
332 | service_name, | 329 | service_name, |
333 | "UNIXPATH", &unixpath)) && | 330 | "UNIXPATH", &unixpath)) && |
334 | (0 < strlen (unixpath))) | 331 | (0 < strlen (unixpath))) |
335 | { | 332 | { |
336 | sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, | 333 | sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, |
337 | unixpath); | 334 | unixpath); |
338 | if (sock != NULL) | 335 | if (sock != NULL) |
339 | { | 336 | { |
340 | GNUNET_free (unixpath); | 337 | GNUNET_free (unixpath); |
341 | GNUNET_free (hostname); | 338 | GNUNET_free (hostname); |
342 | return sock; | 339 | return sock; |
343 | } | 340 | } |
344 | } | 341 | } |
345 | GNUNET_free_non_null (unixpath); | 342 | GNUNET_free_non_null (unixpath); |
346 | } | 343 | } |
347 | #endif | 344 | #endif |
348 | #if DEBUG_CLIENT | 345 | #if DEBUG_CLIENT |
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
350 | "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n", | 347 | "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n", |
351 | service_name); | 348 | service_name); |
352 | #endif | 349 | #endif |
353 | GNUNET_free (hostname); | 350 | GNUNET_free (hostname); |
354 | return NULL; | 351 | return NULL; |
355 | } | 352 | } |
356 | 353 | ||
357 | sock = GNUNET_CONNECTION_create_from_connect (cfg, | 354 | sock = GNUNET_CONNECTION_create_from_connect (cfg, hostname, port); |
358 | hostname, | ||
359 | port); | ||
360 | GNUNET_free (hostname); | 355 | GNUNET_free (hostname); |
361 | return sock; | 356 | return sock; |
362 | } | 357 | } |
@@ -376,8 +371,7 @@ GNUNET_CLIENT_connect (const char *service_name, | |||
376 | struct GNUNET_CLIENT_Connection *ret; | 371 | struct GNUNET_CLIENT_Connection *ret; |
377 | struct GNUNET_CONNECTION_Handle *sock; | 372 | struct GNUNET_CONNECTION_Handle *sock; |
378 | 373 | ||
379 | sock = do_connect (service_name, | 374 | sock = do_connect (service_name, cfg, 0); |
380 | cfg, 0); | ||
381 | ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection)); | 375 | ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection)); |
382 | ret->attempts = 1; | 376 | ret->attempts = 1; |
383 | ret->sock = sock; | 377 | ret->sock = sock; |
@@ -396,12 +390,11 @@ GNUNET_CLIENT_connect (const char *service_name, | |||
396 | */ | 390 | */ |
397 | void | 391 | void |
398 | GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h, | 392 | GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h, |
399 | int do_ignore) | 393 | int do_ignore) |
400 | { | 394 | { |
401 | h->ignore_shutdown = do_ignore; | 395 | h->ignore_shutdown = do_ignore; |
402 | if (h->sock != NULL) | 396 | if (h->sock != NULL) |
403 | GNUNET_CONNECTION_ignore_shutdown (h->sock, | 397 | GNUNET_CONNECTION_ignore_shutdown (h->sock, do_ignore); |
404 | do_ignore); | ||
405 | } | 398 | } |
406 | 399 | ||
407 | 400 | ||
@@ -422,33 +415,33 @@ GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h, | |||
422 | */ | 415 | */ |
423 | void | 416 | void |
424 | GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock, | 417 | GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock, |
425 | int finish_pending_write) | 418 | int finish_pending_write) |
426 | { | 419 | { |
427 | if (sock->in_receive == GNUNET_YES) | 420 | if (sock->in_receive == GNUNET_YES) |
428 | { | 421 | { |
429 | GNUNET_CONNECTION_receive_cancel (sock->sock); | 422 | GNUNET_CONNECTION_receive_cancel (sock->sock); |
430 | sock->in_receive = GNUNET_NO; | 423 | sock->in_receive = GNUNET_NO; |
431 | } | 424 | } |
432 | if (sock->th != NULL) | 425 | if (sock->th != NULL) |
433 | { | 426 | { |
434 | GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); | 427 | GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); |
435 | sock->th = NULL; | 428 | sock->th = NULL; |
436 | } | 429 | } |
437 | if (NULL != sock->sock) | 430 | if (NULL != sock->sock) |
438 | { | 431 | { |
439 | GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write); | 432 | GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write); |
440 | sock->sock = NULL; | 433 | sock->sock = NULL; |
441 | } | 434 | } |
442 | if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK) | 435 | if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK) |
443 | { | 436 | { |
444 | GNUNET_SCHEDULER_cancel (sock->receive_task); | 437 | GNUNET_SCHEDULER_cancel (sock->receive_task); |
445 | sock->receive_task = GNUNET_SCHEDULER_NO_TASK; | 438 | sock->receive_task = GNUNET_SCHEDULER_NO_TASK; |
446 | } | 439 | } |
447 | if (sock->tag != NULL) | 440 | if (sock->tag != NULL) |
448 | { | 441 | { |
449 | GNUNET_free (sock->tag); | 442 | GNUNET_free (sock->tag); |
450 | sock->tag = NULL; | 443 | sock->tag = NULL; |
451 | } | 444 | } |
452 | sock->receiver_handler = NULL; | 445 | sock->receiver_handler = NULL; |
453 | GNUNET_array_grow (sock->received_buf, sock->received_size, 0); | 446 | GNUNET_array_grow (sock->received_buf, sock->received_size, 0); |
454 | GNUNET_free (sock->service_name); | 447 | GNUNET_free (sock->service_name); |
@@ -496,26 +489,25 @@ receive_helper (void *cls, | |||
496 | GNUNET_assert (conn->msg_complete == GNUNET_NO); | 489 | GNUNET_assert (conn->msg_complete == GNUNET_NO); |
497 | conn->in_receive = GNUNET_NO; | 490 | conn->in_receive = GNUNET_NO; |
498 | if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) | 491 | if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) |
499 | { | 492 | { |
500 | /* signal timeout! */ | 493 | /* signal timeout! */ |
501 | #if DEBUG_CLIENT | 494 | #if DEBUG_CLIENT |
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
503 | "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n", | 496 | "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n", |
504 | (unsigned int) available, | 497 | (unsigned int) available, |
505 | conn->sock == NULL ? "NULL" : "non-NULL", | 498 | conn->sock == NULL ? "NULL" : "non-NULL", STRERROR (errCode)); |
506 | STRERROR (errCode)); | ||
507 | #endif | 499 | #endif |
508 | if (NULL != (receive_handler = conn->receiver_handler)) | 500 | if (NULL != (receive_handler = conn->receiver_handler)) |
509 | { | 501 | { |
510 | receive_handler_cls = conn->receiver_handler_cls; | 502 | receive_handler_cls = conn->receiver_handler_cls; |
511 | conn->receiver_handler = NULL; | 503 | conn->receiver_handler = NULL; |
512 | receive_handler (receive_handler_cls, NULL); | 504 | receive_handler (receive_handler_cls, NULL); |
513 | } | ||
514 | return; | ||
515 | } | 505 | } |
506 | return; | ||
507 | } | ||
516 | 508 | ||
517 | /* FIXME: optimize for common fast case where buf contains the | 509 | /* FIXME: optimize for common fast case where buf contains the |
518 | entire message and we need no copying... */ | 510 | * entire message and we need no copying... */ |
519 | 511 | ||
520 | 512 | ||
521 | /* slow path: append to array */ | 513 | /* slow path: append to array */ |
@@ -528,12 +520,12 @@ receive_helper (void *cls, | |||
528 | /* check for timeout */ | 520 | /* check for timeout */ |
529 | remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout); | 521 | remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout); |
530 | if (remaining.rel_value == 0) | 522 | if (remaining.rel_value == 0) |
531 | { | 523 | { |
532 | /* signal timeout! */ | 524 | /* signal timeout! */ |
533 | if (NULL != conn->receiver_handler) | 525 | if (NULL != conn->receiver_handler) |
534 | conn->receiver_handler (conn->receiver_handler_cls, NULL); | 526 | conn->receiver_handler (conn->receiver_handler_cls, NULL); |
535 | return; | 527 | return; |
536 | } | 528 | } |
537 | /* back to receive -- either for more data or to call callback! */ | 529 | /* back to receive -- either for more data or to call callback! */ |
538 | GNUNET_CLIENT_receive (conn, | 530 | GNUNET_CLIENT_receive (conn, |
539 | conn->receiver_handler, | 531 | conn->receiver_handler, |
@@ -553,7 +545,7 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
553 | struct GNUNET_CLIENT_Connection *sock = cls; | 545 | struct GNUNET_CLIENT_Connection *sock = cls; |
554 | GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; | 546 | GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; |
555 | const struct GNUNET_MessageHeader *cmsg = | 547 | const struct GNUNET_MessageHeader *cmsg = |
556 | (const struct GNUNET_MessageHeader *) sock->received_buf; | 548 | (const struct GNUNET_MessageHeader *) sock->received_buf; |
557 | void *handler_cls = sock->receiver_handler_cls; | 549 | void *handler_cls = sock->receiver_handler_cls; |
558 | uint16_t msize = ntohs (cmsg->size); | 550 | uint16_t msize = ntohs (cmsg->size); |
559 | char mbuf[msize]; | 551 | char mbuf[msize]; |
@@ -561,9 +553,8 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
561 | 553 | ||
562 | #if DEBUG_CLIENT | 554 | #if DEBUG_CLIENT |
563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
564 | "Received message of type %u and size %u\n", | 556 | "Received message of type %u and size %u\n", |
565 | ntohs (cmsg->type), | 557 | ntohs (cmsg->type), msize); |
566 | msize); | ||
567 | #endif | 558 | #endif |
568 | sock->receive_task = GNUNET_SCHEDULER_NO_TASK; | 559 | sock->receive_task = GNUNET_SCHEDULER_NO_TASK; |
569 | GNUNET_assert (GNUNET_YES == sock->msg_complete); | 560 | GNUNET_assert (GNUNET_YES == sock->msg_complete); |
@@ -594,32 +585,32 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, | |||
594 | void *handler_cls, struct GNUNET_TIME_Relative timeout) | 585 | void *handler_cls, struct GNUNET_TIME_Relative timeout) |
595 | { | 586 | { |
596 | if (sock->sock == NULL) | 587 | if (sock->sock == NULL) |
597 | { | 588 | { |
598 | /* already disconnected, fail instantly! */ | 589 | /* already disconnected, fail instantly! */ |
599 | GNUNET_break (0); /* this should not happen in well-written code! */ | 590 | GNUNET_break (0); /* this should not happen in well-written code! */ |
600 | if (NULL != handler) | 591 | if (NULL != handler) |
601 | handler (handler_cls, NULL); | 592 | handler (handler_cls, NULL); |
602 | return; | 593 | return; |
603 | } | 594 | } |
604 | sock->receiver_handler = handler; | 595 | sock->receiver_handler = handler; |
605 | sock->receiver_handler_cls = handler_cls; | 596 | sock->receiver_handler_cls = handler_cls; |
606 | sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 597 | sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
607 | if (GNUNET_YES == sock->msg_complete) | 598 | if (GNUNET_YES == sock->msg_complete) |
608 | { | 599 | { |
609 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task); | 600 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->receive_task); |
610 | sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock); | 601 | sock->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, sock); |
611 | } | 602 | } |
612 | else | 603 | else |
613 | { | 604 | { |
614 | GNUNET_assert (sock->in_receive == GNUNET_NO); | 605 | GNUNET_assert (sock->in_receive == GNUNET_NO); |
615 | sock->in_receive = GNUNET_YES; | 606 | sock->in_receive = GNUNET_YES; |
616 | #if DEBUG_CLIENT | 607 | #if DEBUG_CLIENT |
617 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); | 608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n"); |
618 | #endif | 609 | #endif |
619 | GNUNET_CONNECTION_receive (sock->sock, | 610 | GNUNET_CONNECTION_receive (sock->sock, |
620 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 611 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
621 | timeout, &receive_helper, sock); | 612 | timeout, &receive_helper, sock); |
622 | } | 613 | } |
623 | } | 614 | } |
624 | 615 | ||
625 | 616 | ||
@@ -630,8 +621,7 @@ static void | |||
630 | service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls) | 621 | service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls) |
631 | { | 622 | { |
632 | GNUNET_SCHEDULER_add_continuation (task, | 623 | GNUNET_SCHEDULER_add_continuation (task, |
633 | task_cls, | 624 | task_cls, GNUNET_SCHEDULER_REASON_TIMEOUT); |
634 | GNUNET_SCHEDULER_REASON_TIMEOUT); | ||
635 | } | 625 | } |
636 | 626 | ||
637 | 627 | ||
@@ -645,23 +635,24 @@ static void | |||
645 | confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) | 635 | confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
646 | { | 636 | { |
647 | struct GNUNET_CLIENT_Connection *conn = cls; | 637 | struct GNUNET_CLIENT_Connection *conn = cls; |
638 | |||
648 | /* We may want to consider looking at the reply in more | 639 | /* We may want to consider looking at the reply in more |
649 | detail in the future, for example, is this the | 640 | * detail in the future, for example, is this the |
650 | correct service? FIXME! */ | 641 | * correct service? FIXME! */ |
651 | if (msg != NULL) | 642 | if (msg != NULL) |
652 | { | 643 | { |
653 | #if DEBUG_CLIENT | 644 | #if DEBUG_CLIENT |
654 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 645 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
655 | "Received confirmation that service is running.\n"); | 646 | "Received confirmation that service is running.\n"); |
656 | #endif | 647 | #endif |
657 | GNUNET_SCHEDULER_add_continuation (conn->test_cb, | 648 | GNUNET_SCHEDULER_add_continuation (conn->test_cb, |
658 | conn->test_cb_cls, | 649 | conn->test_cb_cls, |
659 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 650 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
660 | } | 651 | } |
661 | else | 652 | else |
662 | { | 653 | { |
663 | service_test_error (conn->test_cb, conn->test_cb_cls); | 654 | service_test_error (conn->test_cb, conn->test_cb_cls); |
664 | } | 655 | } |
665 | GNUNET_CLIENT_disconnect (conn, GNUNET_NO); | 656 | GNUNET_CLIENT_disconnect (conn, GNUNET_NO); |
666 | } | 657 | } |
667 | 658 | ||
@@ -682,26 +673,26 @@ write_test (void *cls, size_t size, void *buf) | |||
682 | struct GNUNET_MessageHeader *msg; | 673 | struct GNUNET_MessageHeader *msg; |
683 | 674 | ||
684 | if (size < sizeof (struct GNUNET_MessageHeader)) | 675 | if (size < sizeof (struct GNUNET_MessageHeader)) |
685 | { | 676 | { |
686 | #if DEBUG_CLIENT | 677 | #if DEBUG_CLIENT |
687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
688 | _("Failure to transmit TEST request.\n")); | 679 | _("Failure to transmit TEST request.\n")); |
689 | #endif | 680 | #endif |
690 | service_test_error (conn->test_cb, conn->test_cb_cls); | 681 | service_test_error (conn->test_cb, conn->test_cb_cls); |
691 | GNUNET_CLIENT_disconnect (conn, GNUNET_NO); | 682 | GNUNET_CLIENT_disconnect (conn, GNUNET_NO); |
692 | return 0; /* client disconnected */ | 683 | return 0; /* client disconnected */ |
693 | } | 684 | } |
694 | #if DEBUG_CLIENT | 685 | #if DEBUG_CLIENT |
695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST"); |
696 | "Transmitting `%s' request.\n", "TEST"); | ||
697 | #endif | 687 | #endif |
698 | msg = (struct GNUNET_MessageHeader *) buf; | 688 | msg = (struct GNUNET_MessageHeader *) buf; |
699 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); | 689 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); |
700 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 690 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
701 | GNUNET_CLIENT_receive (conn, | 691 | GNUNET_CLIENT_receive (conn, |
702 | &confirm_handler, | 692 | &confirm_handler, |
703 | conn, | 693 | conn, |
704 | GNUNET_TIME_absolute_get_remaining (conn->test_deadline)); | 694 | GNUNET_TIME_absolute_get_remaining |
695 | (conn->test_deadline)); | ||
705 | return sizeof (struct GNUNET_MessageHeader); | 696 | return sizeof (struct GNUNET_MessageHeader); |
706 | } | 697 | } |
707 | 698 | ||
@@ -740,60 +731,53 @@ GNUNET_CLIENT_service_test (const char *service, | |||
740 | struct sockaddr_un s_un; | 731 | struct sockaddr_un s_un; |
741 | size_t slen; | 732 | size_t slen; |
742 | char *unixpath; | 733 | char *unixpath; |
743 | 734 | ||
744 | unixpath = NULL; | 735 | unixpath = NULL; |
745 | if ( (GNUNET_OK == | 736 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ |
746 | GNUNET_CONFIGURATION_get_value_string (cfg, | 737 | { |
747 | service, | 738 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) |
748 | "UNIXPATH", &unixpath)) && | ||
749 | (0 < strlen (unixpath)) ) /* We have a non-NULL unixpath, does that mean it's valid? */ | ||
750 | { | 739 | { |
751 | if (strlen(unixpath) >= sizeof(s_un.sun_path)) | 740 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
752 | { | 741 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), |
753 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 742 | unixpath, sizeof (s_un.sun_path)); |
754 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), | 743 | } |
755 | unixpath, | 744 | else |
756 | sizeof(s_un.sun_path)); | 745 | { |
757 | } | 746 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); |
758 | else | 747 | if (sock != NULL) |
759 | { | 748 | { |
760 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); | 749 | memset (&s_un, 0, sizeof (s_un)); |
761 | if (sock != NULL) | 750 | s_un.sun_family = AF_UNIX; |
762 | { | 751 | slen = strlen (unixpath) + 1; |
763 | memset (&s_un, 0, sizeof (s_un)); | 752 | if (slen >= sizeof (s_un.sun_path)) |
764 | s_un.sun_family = AF_UNIX; | 753 | slen = sizeof (s_un.sun_path) - 1; |
765 | slen = strlen (unixpath) + 1; | 754 | memcpy (s_un.sun_path, unixpath, slen); |
766 | if (slen >= sizeof (s_un.sun_path)) | 755 | s_un.sun_path[slen] = '\0'; |
767 | slen = sizeof (s_un.sun_path) - 1; | 756 | slen = sizeof (struct sockaddr_un); |
768 | memcpy (s_un.sun_path, | ||
769 | unixpath, | ||
770 | slen); | ||
771 | s_un.sun_path[slen] = '\0'; | ||
772 | slen = sizeof (struct sockaddr_un); | ||
773 | #if LINUX | 757 | #if LINUX |
774 | s_un.sun_path[0] = '\0'; | 758 | s_un.sun_path[0] = '\0'; |
775 | #endif | 759 | #endif |
776 | #if HAVE_SOCKADDR_IN_SIN_LEN | 760 | #if HAVE_SOCKADDR_IN_SIN_LEN |
777 | s_un.sun_len = (u_char) slen; | 761 | s_un.sun_len = (u_char) slen; |
778 | #endif | 762 | #endif |
779 | if (GNUNET_OK != | 763 | if (GNUNET_OK != |
780 | GNUNET_NETWORK_socket_bind (sock, | 764 | GNUNET_NETWORK_socket_bind (sock, |
781 | (const struct sockaddr*) &s_un, | 765 | (const struct sockaddr *) &s_un, |
782 | slen)) | 766 | slen)) |
783 | { | 767 | { |
784 | /* failed to bind => service must be running */ | 768 | /* failed to bind => service must be running */ |
785 | GNUNET_free (unixpath); | 769 | GNUNET_free (unixpath); |
786 | (void) GNUNET_NETWORK_socket_close (sock); | 770 | (void) GNUNET_NETWORK_socket_close (sock); |
787 | GNUNET_SCHEDULER_add_continuation (task, | 771 | GNUNET_SCHEDULER_add_continuation (task, |
788 | task_cls, | 772 | task_cls, |
789 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 773 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
790 | return; | 774 | return; |
791 | } | 775 | } |
792 | (void) GNUNET_NETWORK_socket_close (sock); | 776 | (void) GNUNET_NETWORK_socket_close (sock); |
793 | } | 777 | } |
794 | /* let's try IP */ | 778 | /* let's try IP */ |
795 | } | ||
796 | } | 779 | } |
780 | } | ||
797 | GNUNET_free_non_null (unixpath); | 781 | GNUNET_free_non_null (unixpath); |
798 | } | 782 | } |
799 | #endif | 783 | #endif |
@@ -807,128 +791,126 @@ GNUNET_CLIENT_service_test (const char *service, | |||
807 | (port > 65535) || | 791 | (port > 65535) || |
808 | (GNUNET_OK != | 792 | (GNUNET_OK != |
809 | GNUNET_CONFIGURATION_get_value_string (cfg, | 793 | GNUNET_CONFIGURATION_get_value_string (cfg, |
810 | service, | 794 | service, "HOSTNAME", &hostname))) |
811 | "HOSTNAME", &hostname))) | 795 | { |
812 | { | 796 | /* UNIXPATH failed (if possible) AND IP failed => error */ |
813 | /* UNIXPATH failed (if possible) AND IP failed => error */ | 797 | service_test_error (task, task_cls); |
814 | service_test_error (task, task_cls); | 798 | return; |
815 | return; | 799 | } |
816 | } | 800 | |
817 | |||
818 | if (0 == strcmp ("localhost", hostname) | 801 | if (0 == strcmp ("localhost", hostname) |
819 | #if WINDOWS | 802 | #if WINDOWS |
820 | && 0 | 803 | && 0 |
821 | #endif | 804 | #endif |
822 | ) | 805 | ) |
823 | { | 806 | { |
824 | /* can test using 'bind' */ | 807 | /* can test using 'bind' */ |
825 | struct sockaddr_in s_in; | 808 | struct sockaddr_in s_in; |
826 | 809 | ||
827 | memset (&s_in, 0, sizeof (s_in)); | 810 | memset (&s_in, 0, sizeof (s_in)); |
828 | #if HAVE_SOCKADDR_IN_SIN_LEN | 811 | #if HAVE_SOCKADDR_IN_SIN_LEN |
829 | s_in.sin_len = saddrlens[1]; | 812 | s_in.sin_len = saddrlens[1]; |
830 | #endif | 813 | #endif |
831 | s_in.sin_family = AF_INET; | 814 | s_in.sin_family = AF_INET; |
832 | s_in.sin_port = htons (port); | 815 | s_in.sin_port = htons (port); |
833 | 816 | ||
834 | sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); | 817 | sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); |
835 | if (sock != NULL) | 818 | if (sock != NULL) |
836 | { | 819 | { |
837 | if (GNUNET_OK != | 820 | if (GNUNET_OK != |
838 | GNUNET_NETWORK_socket_bind (sock, | 821 | GNUNET_NETWORK_socket_bind (sock, |
839 | (const struct sockaddr*) &s_in, | 822 | (const struct sockaddr *) &s_in, |
840 | sizeof (s_in))) | 823 | sizeof (s_in))) |
841 | { | 824 | { |
842 | /* failed to bind => service must be running */ | 825 | /* failed to bind => service must be running */ |
843 | GNUNET_free (hostname); | 826 | GNUNET_free (hostname); |
844 | (void) GNUNET_NETWORK_socket_close (sock); | 827 | (void) GNUNET_NETWORK_socket_close (sock); |
845 | GNUNET_SCHEDULER_add_continuation (task, | 828 | GNUNET_SCHEDULER_add_continuation (task, |
846 | task_cls, | 829 | task_cls, |
847 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 830 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
848 | return; | 831 | return; |
849 | } | 832 | } |
850 | (void) GNUNET_NETWORK_socket_close (sock); | 833 | (void) GNUNET_NETWORK_socket_close (sock); |
851 | } | ||
852 | } | 834 | } |
835 | } | ||
853 | 836 | ||
854 | if (0 == strcmp ("ip6-localhost", hostname) | 837 | if (0 == strcmp ("ip6-localhost", hostname) |
855 | #if WINDOWS | 838 | #if WINDOWS |
856 | && 0 | 839 | && 0 |
857 | #endif | 840 | #endif |
858 | ) | 841 | ) |
859 | { | 842 | { |
860 | /* can test using 'bind' */ | 843 | /* can test using 'bind' */ |
861 | struct sockaddr_in6 s_in6; | 844 | struct sockaddr_in6 s_in6; |
862 | 845 | ||
863 | memset (&s_in6, 0, sizeof (s_in6)); | 846 | memset (&s_in6, 0, sizeof (s_in6)); |
864 | #if HAVE_SOCKADDR_IN_SIN_LEN | 847 | #if HAVE_SOCKADDR_IN_SIN_LEN |
865 | s_in6.sin6_len = saddrlens[1]; | 848 | s_in6.sin6_len = saddrlens[1]; |
866 | #endif | 849 | #endif |
867 | s_in6.sin6_family = AF_INET6; | 850 | s_in6.sin6_family = AF_INET6; |
868 | s_in6.sin6_port = htons (port); | 851 | s_in6.sin6_port = htons (port); |
869 | 852 | ||
870 | sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0); | 853 | sock = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_STREAM, 0); |
871 | if (sock != NULL) | 854 | if (sock != NULL) |
872 | { | 855 | { |
873 | if (GNUNET_OK != | 856 | if (GNUNET_OK != |
874 | GNUNET_NETWORK_socket_bind (sock, | 857 | GNUNET_NETWORK_socket_bind (sock, |
875 | (const struct sockaddr*) &s_in6, | 858 | (const struct sockaddr *) &s_in6, |
876 | sizeof (s_in6))) | 859 | sizeof (s_in6))) |
877 | { | 860 | { |
878 | /* failed to bind => service must be running */ | 861 | /* failed to bind => service must be running */ |
879 | GNUNET_free (hostname); | 862 | GNUNET_free (hostname); |
880 | (void) GNUNET_NETWORK_socket_close (sock); | 863 | (void) GNUNET_NETWORK_socket_close (sock); |
881 | GNUNET_SCHEDULER_add_continuation (task, | 864 | GNUNET_SCHEDULER_add_continuation (task, |
882 | task_cls, | 865 | task_cls, |
883 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 866 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
884 | return; | 867 | return; |
885 | } | 868 | } |
886 | (void) GNUNET_NETWORK_socket_close (sock); | 869 | (void) GNUNET_NETWORK_socket_close (sock); |
887 | } | ||
888 | } | 870 | } |
871 | } | ||
889 | 872 | ||
890 | if (( (0 == strcmp ("localhost", hostname)) || | 873 | if (((0 == strcmp ("localhost", hostname)) || |
891 | (0 == strcmp ("ip6-localhost", hostname))) | 874 | (0 == strcmp ("ip6-localhost", hostname))) |
892 | #if WINDOWS | 875 | #if WINDOWS |
893 | && 0 | 876 | && 0 |
894 | #endif | 877 | #endif |
895 | ) | 878 | ) |
896 | { | 879 | { |
897 | /* all binds succeeded => claim service not running right now */ | 880 | /* all binds succeeded => claim service not running right now */ |
898 | GNUNET_free_non_null (hostname); | 881 | GNUNET_free_non_null (hostname); |
899 | service_test_error (task, task_cls); | 882 | service_test_error (task, task_cls); |
900 | return; | 883 | return; |
901 | } | 884 | } |
902 | GNUNET_free_non_null (hostname); | 885 | GNUNET_free_non_null (hostname); |
903 | 886 | ||
904 | /* non-localhost, try 'connect' method */ | 887 | /* non-localhost, try 'connect' method */ |
905 | conn = GNUNET_CLIENT_connect (service, cfg); | 888 | conn = GNUNET_CLIENT_connect (service, cfg); |
906 | if (conn == NULL) | 889 | if (conn == NULL) |
907 | { | 890 | { |
908 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 891 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
909 | _ | 892 | _ |
910 | ("Could not connect to service `%s', must not be running.\n"), | 893 | ("Could not connect to service `%s', must not be running.\n"), |
911 | service); | 894 | service); |
912 | service_test_error (task, task_cls); | 895 | service_test_error (task, task_cls); |
913 | return; | 896 | return; |
914 | } | 897 | } |
915 | conn->test_cb = task; | 898 | conn->test_cb = task; |
916 | conn->test_cb_cls = task_cls; | 899 | conn->test_cb_cls = task_cls; |
917 | conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); | 900 | conn->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); |
918 | 901 | ||
919 | if (NULL == GNUNET_CLIENT_notify_transmit_ready (conn, | 902 | if (NULL == GNUNET_CLIENT_notify_transmit_ready (conn, |
920 | sizeof (struct GNUNET_MessageHeader), | 903 | sizeof (struct |
921 | timeout, | 904 | GNUNET_MessageHeader), |
922 | GNUNET_YES, | 905 | timeout, GNUNET_YES, |
923 | &write_test, conn)) | 906 | &write_test, conn)) |
924 | { | 907 | { |
925 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 908 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
926 | _("Failure to transmit request to service `%s'\n"), | 909 | _("Failure to transmit request to service `%s'\n"), service); |
927 | service); | 910 | service_test_error (task, task_cls); |
928 | service_test_error (task, task_cls); | 911 | GNUNET_CLIENT_disconnect (conn, GNUNET_NO); |
929 | GNUNET_CLIENT_disconnect (conn, GNUNET_NO); | 912 | return; |
930 | return; | 913 | } |
931 | } | ||
932 | } | 914 | } |
933 | 915 | ||
934 | 916 | ||
@@ -953,61 +935,60 @@ static size_t client_notify (void *cls, size_t size, void *buf); | |||
953 | * @param tc unused | 935 | * @param tc unused |
954 | */ | 936 | */ |
955 | static void | 937 | static void |
956 | client_delayed_retry (void *cls, | 938 | client_delayed_retry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
957 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
958 | { | 939 | { |
959 | struct GNUNET_CLIENT_TransmitHandle *th = cls; | 940 | struct GNUNET_CLIENT_TransmitHandle *th = cls; |
960 | struct GNUNET_TIME_Relative delay; | 941 | struct GNUNET_TIME_Relative delay; |
961 | 942 | ||
962 | th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 943 | th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
963 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 944 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
964 | { | 945 | { |
965 | #if DEBUG_CLIENT | 946 | #if DEBUG_CLIENT |
966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 947 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
967 | "Transmission failed due to shutdown.\n"); | 948 | "Transmission failed due to shutdown.\n"); |
968 | #endif | 949 | #endif |
969 | th->sock->th = NULL; | 950 | th->sock->th = NULL; |
970 | th->notify (th->notify_cls, 0, NULL); | 951 | th->notify (th->notify_cls, 0, NULL); |
971 | GNUNET_free (th); | 952 | GNUNET_free (th); |
972 | return; | 953 | return; |
973 | } | 954 | } |
974 | th->sock->sock = do_connect (th->sock->service_name, | 955 | th->sock->sock = do_connect (th->sock->service_name, |
975 | th->sock->cfg, | 956 | th->sock->cfg, th->sock->attempts++); |
976 | th->sock->attempts++); | ||
977 | if (NULL == th->sock->sock) | 957 | if (NULL == th->sock->sock) |
978 | { | 958 | { |
979 | /* could happen if we're out of sockets */ | 959 | /* could happen if we're out of sockets */ |
980 | delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (th->timeout), | 960 | delay = |
981 | th->sock->back_off); | 961 | GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining |
982 | th->sock->back_off | 962 | (th->timeout), th->sock->back_off); |
983 | = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (th->sock->back_off, 2), | 963 | th->sock->back_off = |
984 | GNUNET_TIME_UNIT_SECONDS); | 964 | GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply |
965 | (th->sock->back_off, 2), | ||
966 | GNUNET_TIME_UNIT_SECONDS); | ||
985 | #if DEBUG_CLIENT | 967 | #if DEBUG_CLIENT |
986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 968 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
987 | "Transmission failed %u times, trying again in %llums.\n", | 969 | "Transmission failed %u times, trying again in %llums.\n", |
988 | MAX_ATTEMPTS - th->attempts_left, | 970 | MAX_ATTEMPTS - th->attempts_left, |
989 | (unsigned long long) delay.rel_value); | 971 | (unsigned long long) delay.rel_value); |
990 | #endif | 972 | #endif |
991 | th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, | 973 | th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, |
992 | &client_delayed_retry, | 974 | &client_delayed_retry, |
993 | th); | 975 | th); |
994 | return; | 976 | return; |
995 | } | 977 | } |
996 | GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, | 978 | GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, th->sock->ignore_shutdown); |
997 | th->sock->ignore_shutdown); | ||
998 | th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, | 979 | th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, |
999 | th->size, | 980 | th->size, |
1000 | GNUNET_TIME_absolute_get_remaining | 981 | GNUNET_TIME_absolute_get_remaining |
1001 | (th->timeout), | 982 | (th->timeout), |
1002 | &client_notify, th); | 983 | &client_notify, th); |
1003 | if (th->th == NULL) | 984 | if (th->th == NULL) |
1004 | { | 985 | { |
1005 | GNUNET_break (0); | 986 | GNUNET_break (0); |
1006 | th->sock->th = NULL; | 987 | th->sock->th = NULL; |
1007 | th->notify (th->notify_cls, 0, NULL); | 988 | th->notify (th->notify_cls, 0, NULL); |
1008 | GNUNET_free (th); | 989 | GNUNET_free (th); |
1009 | return; | 990 | return; |
1010 | } | 991 | } |
1011 | } | 992 | } |
1012 | 993 | ||
1013 | 994 | ||
@@ -1030,47 +1011,49 @@ client_notify (void *cls, size_t size, void *buf) | |||
1030 | th->th = NULL; | 1011 | th->th = NULL; |
1031 | th->sock->th = NULL; | 1012 | th->sock->th = NULL; |
1032 | if (buf == NULL) | 1013 | if (buf == NULL) |
1014 | { | ||
1015 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); | ||
1016 | delay.rel_value /= 2; | ||
1017 | if ((0 != | ||
1018 | (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) || | ||
1019 | (GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) || | ||
1020 | (delay.rel_value < 1)) | ||
1033 | { | 1021 | { |
1034 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); | ||
1035 | delay.rel_value /= 2; | ||
1036 | if ( (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ())) || | ||
1037 | (GNUNET_YES != th->auto_retry) || | ||
1038 | (0 == --th->attempts_left) || | ||
1039 | (delay.rel_value < 1) ) | ||
1040 | { | ||
1041 | #if DEBUG_CLIENT | 1022 | #if DEBUG_CLIENT |
1042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1043 | "Transmission failed %u times, giving up.\n", | 1024 | "Transmission failed %u times, giving up.\n", |
1044 | MAX_ATTEMPTS - th->attempts_left); | 1025 | MAX_ATTEMPTS - th->attempts_left); |
1045 | #endif | 1026 | #endif |
1046 | GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); | 1027 | GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); |
1047 | GNUNET_free (th); | 1028 | GNUNET_free (th); |
1048 | return 0; | 1029 | return 0; |
1049 | } | 1030 | } |
1050 | /* auto-retry */ | 1031 | /* auto-retry */ |
1051 | #if DEBUG_CLIENT | 1032 | #if DEBUG_CLIENT |
1052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1053 | "Failed to connect to `%s', automatically trying again.\n", | 1034 | "Failed to connect to `%s', automatically trying again.\n", |
1054 | th->sock->service_name); | 1035 | th->sock->service_name); |
1055 | #endif | 1036 | #endif |
1056 | GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); | 1037 | GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); |
1057 | th->sock->sock = NULL; | 1038 | th->sock->sock = NULL; |
1058 | delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); | 1039 | delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); |
1059 | th->sock->back_off | 1040 | th->sock->back_off |
1060 | = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (th->sock->back_off, 2), | 1041 | = |
1061 | GNUNET_TIME_UNIT_SECONDS); | 1042 | GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply |
1043 | (th->sock->back_off, 2), | ||
1044 | GNUNET_TIME_UNIT_SECONDS); | ||
1062 | #if DEBUG_CLIENT | 1045 | #if DEBUG_CLIENT |
1063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1064 | "Transmission failed %u times, trying again in %llums.\n", | 1047 | "Transmission failed %u times, trying again in %llums.\n", |
1065 | MAX_ATTEMPTS - th->attempts_left, | 1048 | MAX_ATTEMPTS - th->attempts_left, |
1066 | (unsigned long long) delay.rel_value); | 1049 | (unsigned long long) delay.rel_value); |
1067 | #endif | 1050 | #endif |
1068 | th->sock->th = th; | 1051 | th->sock->th = th; |
1069 | th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, | 1052 | th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, |
1070 | &client_delayed_retry, | 1053 | &client_delayed_retry, |
1071 | th); | 1054 | th); |
1072 | return 0; | 1055 | return 0; |
1073 | } | 1056 | } |
1074 | GNUNET_assert (size >= th->size); | 1057 | GNUNET_assert (size >= th->size); |
1075 | ret = th->notify (th->notify_cls, size, buf); | 1058 | ret = th->notify (th->notify_cls, size, buf); |
1076 | GNUNET_free (th); | 1059 | GNUNET_free (th); |
@@ -1108,12 +1091,12 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, | |||
1108 | struct GNUNET_CLIENT_TransmitHandle *th; | 1091 | struct GNUNET_CLIENT_TransmitHandle *th; |
1109 | 1092 | ||
1110 | if (NULL != sock->th) | 1093 | if (NULL != sock->th) |
1111 | { | 1094 | { |
1112 | /* If this breaks, you most likley called this function twice without waiting | 1095 | /* If this breaks, you most likley called this function twice without waiting |
1113 | * for completion or canceling the request */ | 1096 | * for completion or canceling the request */ |
1114 | GNUNET_break (0); | 1097 | GNUNET_break (0); |
1115 | return NULL; | 1098 | return NULL; |
1116 | } | 1099 | } |
1117 | th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle)); | 1100 | th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle)); |
1118 | th->sock = sock; | 1101 | th->sock = sock; |
1119 | th->size = size; | 1102 | th->size = size; |
@@ -1124,26 +1107,26 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, | |||
1124 | th->attempts_left = MAX_ATTEMPTS; | 1107 | th->attempts_left = MAX_ATTEMPTS; |
1125 | sock->th = th; | 1108 | sock->th = th; |
1126 | if (sock->sock == NULL) | 1109 | if (sock->sock == NULL) |
1127 | { | 1110 | { |
1128 | th->reconnect_task = GNUNET_SCHEDULER_add_delayed (sock->back_off, | 1111 | th->reconnect_task = GNUNET_SCHEDULER_add_delayed (sock->back_off, |
1129 | &client_delayed_retry, | 1112 | &client_delayed_retry, |
1130 | th); | 1113 | th); |
1131 | 1114 | ||
1132 | } | 1115 | } |
1133 | else | 1116 | else |
1117 | { | ||
1118 | th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock, | ||
1119 | size, | ||
1120 | timeout, | ||
1121 | &client_notify, th); | ||
1122 | if (NULL == th->th) | ||
1134 | { | 1123 | { |
1135 | th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock, | 1124 | GNUNET_break (0); |
1136 | size, | 1125 | GNUNET_free (th); |
1137 | timeout, | 1126 | sock->th = NULL; |
1138 | &client_notify, th); | 1127 | return NULL; |
1139 | if (NULL == th->th) | ||
1140 | { | ||
1141 | GNUNET_break (0); | ||
1142 | GNUNET_free (th); | ||
1143 | sock->th = NULL; | ||
1144 | return NULL; | ||
1145 | } | ||
1146 | } | 1128 | } |
1129 | } | ||
1147 | return th; | 1130 | return th; |
1148 | } | 1131 | } |
1149 | 1132 | ||
@@ -1158,16 +1141,16 @@ GNUNET_CLIENT_notify_transmit_ready_cancel (struct | |||
1158 | GNUNET_CLIENT_TransmitHandle *th) | 1141 | GNUNET_CLIENT_TransmitHandle *th) |
1159 | { | 1142 | { |
1160 | if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | 1143 | if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK) |
1161 | { | 1144 | { |
1162 | GNUNET_assert (NULL == th->th); | 1145 | GNUNET_assert (NULL == th->th); |
1163 | GNUNET_SCHEDULER_cancel (th->reconnect_task); | 1146 | GNUNET_SCHEDULER_cancel (th->reconnect_task); |
1164 | th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1147 | th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
1165 | } | 1148 | } |
1166 | else | 1149 | else |
1167 | { | 1150 | { |
1168 | GNUNET_assert (NULL != th->th); | 1151 | GNUNET_assert (NULL != th->th); |
1169 | GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th); | 1152 | GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th); |
1170 | } | 1153 | } |
1171 | th->sock->th = NULL; | 1154 | th->sock->th = NULL; |
1172 | GNUNET_free (th); | 1155 | GNUNET_free (th); |
1173 | } | 1156 | } |
@@ -1193,16 +1176,17 @@ transmit_for_response (void *cls, size_t size, void *buf) | |||
1193 | tc->sock->tag = NULL; | 1176 | tc->sock->tag = NULL; |
1194 | msize = ntohs (tc->hdr->size); | 1177 | msize = ntohs (tc->hdr->size); |
1195 | if (NULL == buf) | 1178 | if (NULL == buf) |
1196 | { | 1179 | { |
1197 | #if DEBUG_CLIENT | 1180 | #if DEBUG_CLIENT |
1198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1199 | _("Could not submit request, not expecting to receive a response.\n")); | 1182 | _ |
1183 | ("Could not submit request, not expecting to receive a response.\n")); | ||
1200 | #endif | 1184 | #endif |
1201 | if (NULL != tc->rn) | 1185 | if (NULL != tc->rn) |
1202 | tc->rn (tc->rn_cls, NULL); | 1186 | tc->rn (tc->rn_cls, NULL); |
1203 | GNUNET_free (tc); | 1187 | GNUNET_free (tc); |
1204 | return 0; | 1188 | return 0; |
1205 | } | 1189 | } |
1206 | GNUNET_assert (size >= msize); | 1190 | GNUNET_assert (size >= msize); |
1207 | memcpy (buf, tc->hdr, msize); | 1191 | memcpy (buf, tc->hdr, msize); |
1208 | GNUNET_CLIENT_receive (tc->sock, | 1192 | GNUNET_CLIENT_receive (tc->sock, |
@@ -1263,13 +1247,12 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection | |||
1263 | msize, | 1247 | msize, |
1264 | timeout, | 1248 | timeout, |
1265 | auto_retry, | 1249 | auto_retry, |
1266 | &transmit_for_response, | 1250 | &transmit_for_response, tc)) |
1267 | tc)) | 1251 | { |
1268 | { | 1252 | GNUNET_break (0); |
1269 | GNUNET_break (0); | 1253 | GNUNET_free (tc); |
1270 | GNUNET_free (tc); | 1254 | return GNUNET_SYSERR; |
1271 | return GNUNET_SYSERR; | 1255 | } |
1272 | } | ||
1273 | sock->tag = tc; | 1256 | sock->tag = tc; |
1274 | return GNUNET_OK; | 1257 | return GNUNET_OK; |
1275 | } | 1258 | } |
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 40ffe8c61..6f01e8230 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c | |||
@@ -55,15 +55,16 @@ void * | |||
55 | GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) | 55 | GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) |
56 | { | 56 | { |
57 | void *ret; | 57 | void *ret; |
58 | |||
58 | /* As a security precaution, we generally do not allow very large | 59 | /* As a security precaution, we generally do not allow very large |
59 | allocations using the default 'GNUNET_malloc' macro */ | 60 | * allocations using the default 'GNUNET_malloc' macro */ |
60 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); | 61 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); |
61 | ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); | 62 | ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); |
62 | if (ret == NULL) | 63 | if (ret == NULL) |
63 | { | 64 | { |
64 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 65 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
65 | abort (); | 66 | abort (); |
66 | } | 67 | } |
67 | return ret; | 68 | return ret; |
68 | } | 69 | } |
69 | 70 | ||
@@ -79,11 +80,14 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) | |||
79 | * @param linenumber line where this call is being made (for debugging) | 80 | * @param linenumber line where this call is being made (for debugging) |
80 | * @return allocated memory, never NULL | 81 | * @return allocated memory, never NULL |
81 | */ | 82 | */ |
82 | void *GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int linenumber) | 83 | void * |
84 | GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, | ||
85 | int linenumber) | ||
83 | { | 86 | { |
84 | void *ret; | 87 | void *ret; |
88 | |||
85 | /* As a security precaution, we generally do not allow very large | 89 | /* As a security precaution, we generally do not allow very large |
86 | allocations here */ | 90 | * allocations here */ |
87 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); | 91 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); |
88 | #ifdef W32_MEM_LIMIT | 92 | #ifdef W32_MEM_LIMIT |
89 | size += sizeof (size_t); | 93 | size += sizeof (size_t); |
@@ -93,10 +97,10 @@ void *GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int l | |||
93 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); | 97 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); |
94 | ret = malloc (size); | 98 | ret = malloc (size); |
95 | if (ret == NULL) | 99 | if (ret == NULL) |
96 | { | 100 | { |
97 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 101 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
98 | abort (); | 102 | abort (); |
99 | } | 103 | } |
100 | #ifdef W32_MEM_LIMIT | 104 | #ifdef W32_MEM_LIMIT |
101 | *((size_t *) ret) = size; | 105 | *((size_t *) ret) = size; |
102 | ret = &((size_t *) ret)[1]; | 106 | ret = &((size_t *) ret)[1]; |
@@ -155,9 +159,7 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) | |||
155 | * @return pointer to size bytes of memory | 159 | * @return pointer to size bytes of memory |
156 | */ | 160 | */ |
157 | void * | 161 | void * |
158 | GNUNET_xrealloc_ (void *ptr, | 162 | GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) |
159 | size_t n, | ||
160 | const char *filename, int linenumber) | ||
161 | { | 163 | { |
162 | #ifdef W32_MEM_LIMIT | 164 | #ifdef W32_MEM_LIMIT |
163 | n += sizeof (size_t); | 165 | n += sizeof (size_t); |
@@ -165,11 +167,11 @@ GNUNET_xrealloc_ (void *ptr, | |||
165 | mem_used = mem_used - *((size_t *) ptr) + n; | 167 | mem_used = mem_used - *((size_t *) ptr) + n; |
166 | #endif | 168 | #endif |
167 | ptr = realloc (ptr, n); | 169 | ptr = realloc (ptr, n); |
168 | if ( (NULL == ptr) && (n > 0) ) | 170 | if ((NULL == ptr) && (n > 0)) |
169 | { | 171 | { |
170 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "realloc"); | 172 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "realloc"); |
171 | abort (); | 173 | abort (); |
172 | } | 174 | } |
173 | #ifdef W32_MEM_LIMIT | 175 | #ifdef W32_MEM_LIMIT |
174 | ptr = &((size_t *) ptr)[1]; | 176 | ptr = &((size_t *) ptr)[1]; |
175 | #endif | 177 | #endif |
@@ -226,12 +228,13 @@ GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber) | |||
226 | * @return strndup(str,len) | 228 | * @return strndup(str,len) |
227 | */ | 229 | */ |
228 | char * | 230 | char * |
229 | GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int linenumber) | 231 | GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, |
232 | int linenumber) | ||
230 | { | 233 | { |
231 | char *res; | 234 | char *res; |
232 | 235 | ||
233 | GNUNET_assert_at (str != NULL, filename, linenumber); | 236 | GNUNET_assert_at (str != NULL, filename, linenumber); |
234 | len = GNUNET_MIN(len,strlen(str)); | 237 | len = GNUNET_MIN (len, strlen (str)); |
235 | res = GNUNET_xmalloc_ (len + 1, filename, linenumber); | 238 | res = GNUNET_xmalloc_ (len + 1, filename, linenumber); |
236 | memcpy (res, str, len); | 239 | memcpy (res, str, len); |
237 | res[len] = '\0'; | 240 | res[len] = '\0'; |
@@ -263,22 +266,22 @@ GNUNET_xgrow_ (void **old, | |||
263 | GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); | 266 | GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); |
264 | size = newCount * elementSize; | 267 | size = newCount * elementSize; |
265 | if (size == 0) | 268 | if (size == 0) |
266 | { | 269 | { |
267 | tmp = NULL; | 270 | tmp = NULL; |
268 | } | 271 | } |
269 | else | 272 | else |
270 | { | 273 | { |
271 | tmp = GNUNET_xmalloc_ (size, filename, linenumber); | 274 | tmp = GNUNET_xmalloc_ (size, filename, linenumber); |
272 | memset (tmp, 0, size); /* client code should not rely on this, though... */ | 275 | memset (tmp, 0, size); /* client code should not rely on this, though... */ |
273 | if (*oldCount > newCount) | 276 | if (*oldCount > newCount) |
274 | *oldCount = newCount; /* shrink is also allowed! */ | 277 | *oldCount = newCount; /* shrink is also allowed! */ |
275 | memcpy (tmp, *old, elementSize * (*oldCount)); | 278 | memcpy (tmp, *old, elementSize * (*oldCount)); |
276 | } | 279 | } |
277 | 280 | ||
278 | if (*old != NULL) | 281 | if (*old != NULL) |
279 | { | 282 | { |
280 | GNUNET_xfree_ (*old, filename, linenumber); | 283 | GNUNET_xfree_ (*old, filename, linenumber); |
281 | } | 284 | } |
282 | *old = tmp; | 285 | *old = tmp; |
283 | *oldCount = newCount; | 286 | *oldCount = newCount; |
284 | } | 287 | } |
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 463936741..37f630854 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -107,7 +107,7 @@ static unsigned int last_bulk_repeat; | |||
107 | /** | 107 | /** |
108 | * Component when the last bulk was logged. Will be 0-terminated. | 108 | * Component when the last bulk was logged. Will be 0-terminated. |
109 | */ | 109 | */ |
110 | static char last_bulk_comp[COMP_TRACK_SIZE+1]; | 110 | static char last_bulk_comp[COMP_TRACK_SIZE + 1]; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Running component. | 113 | * Running component. |
@@ -187,10 +187,7 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) | |||
187 | QueryPerformanceFrequency (&performance_frequency); | 187 | QueryPerformanceFrequency (&performance_frequency); |
188 | #endif | 188 | #endif |
189 | GNUNET_free_non_null (component); | 189 | GNUNET_free_non_null (component); |
190 | GNUNET_asprintf (&component, | 190 | GNUNET_asprintf (&component, "%s-%d", comp, getpid ()); |
191 | "%s-%d", | ||
192 | comp, | ||
193 | getpid()); | ||
194 | env_loglevel = getenv ("GNUNET_LOGLEVEL"); | 191 | env_loglevel = getenv ("GNUNET_LOGLEVEL"); |
195 | if (env_loglevel != NULL) | 192 | if (env_loglevel != NULL) |
196 | env_minlevel = get_type (env_loglevel); | 193 | env_minlevel = get_type (env_loglevel); |
@@ -205,20 +202,20 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) | |||
205 | if (logfile == NULL) | 202 | if (logfile == NULL) |
206 | return GNUNET_OK; | 203 | return GNUNET_OK; |
207 | fn = GNUNET_STRINGS_filename_expand (logfile); | 204 | fn = GNUNET_STRINGS_filename_expand (logfile); |
208 | if (NULL == fn) | 205 | if (NULL == fn) |
209 | return GNUNET_SYSERR; | 206 | return GNUNET_SYSERR; |
210 | dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); | 207 | dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); |
211 | altlog = FOPEN (fn, "a"); | 208 | altlog = FOPEN (fn, "a"); |
212 | if (altlog == NULL) | 209 | if (altlog == NULL) |
213 | { | 210 | { |
214 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); | 211 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); |
215 | if (dirwarn) | 212 | if (dirwarn) |
216 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 213 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
217 | _("Failed to create or access directory for log file `%s'\n"), | 214 | _("Failed to create or access directory for log file `%s'\n"), |
218 | fn); | 215 | fn); |
219 | GNUNET_free (fn); | 216 | GNUNET_free (fn); |
220 | return GNUNET_SYSERR; | 217 | return GNUNET_SYSERR; |
221 | } | 218 | } |
222 | GNUNET_free (fn); | 219 | GNUNET_free (fn); |
223 | if (GNUNET_stderr != NULL) | 220 | if (GNUNET_stderr != NULL) |
224 | fclose (GNUNET_stderr); | 221 | fclose (GNUNET_stderr); |
@@ -260,10 +257,10 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) | |||
260 | pos = loggers; | 257 | pos = loggers; |
261 | while ((pos != NULL) && | 258 | while ((pos != NULL) && |
262 | ((pos->logger != logger) || (pos->logger_cls != logger_cls))) | 259 | ((pos->logger != logger) || (pos->logger_cls != logger_cls))) |
263 | { | 260 | { |
264 | prev = pos; | 261 | prev = pos; |
265 | pos = pos->next; | 262 | pos = pos->next; |
266 | } | 263 | } |
267 | GNUNET_assert (pos != NULL); | 264 | GNUNET_assert (pos != NULL); |
268 | if (prev == NULL) | 265 | if (prev == NULL) |
269 | loggers = pos->next; | 266 | loggers = pos->next; |
@@ -286,18 +283,19 @@ output_message (enum GNUNET_ErrorType kind, | |||
286 | const char *comp, const char *datestr, const char *msg) | 283 | const char *comp, const char *datestr, const char *msg) |
287 | { | 284 | { |
288 | struct CustomLogger *pos; | 285 | struct CustomLogger *pos; |
286 | |||
289 | if (GNUNET_stderr != NULL) | 287 | if (GNUNET_stderr != NULL) |
290 | { | 288 | { |
291 | fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp, | 289 | fprintf (GNUNET_stderr, "%s %s %s %s", datestr, comp, |
292 | GNUNET_error_type_to_string (kind), msg); | 290 | GNUNET_error_type_to_string (kind), msg); |
293 | fflush (GNUNET_stderr); | 291 | fflush (GNUNET_stderr); |
294 | } | 292 | } |
295 | pos = loggers; | 293 | pos = loggers; |
296 | while (pos != NULL) | 294 | while (pos != NULL) |
297 | { | 295 | { |
298 | pos->logger (pos->logger_cls, kind, comp, datestr, msg); | 296 | pos->logger (pos->logger_cls, kind, comp, datestr, msg); |
299 | pos = pos->next; | 297 | pos = pos->next; |
300 | } | 298 | } |
301 | } | 299 | } |
302 | 300 | ||
303 | 301 | ||
@@ -323,13 +321,12 @@ flush_bulk (const char *datestr) | |||
323 | else if (last != last_bulk) | 321 | else if (last != last_bulk) |
324 | last--; | 322 | last--; |
325 | if (last[0] == '\n') | 323 | if (last[0] == '\n') |
326 | { | 324 | { |
327 | rev = 1; | 325 | rev = 1; |
328 | last[0] = '\0'; | 326 | last[0] = '\0'; |
329 | } | 327 | } |
330 | ft = | 328 | ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration |
331 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration | 329 | (last_bulk_time)); |
332 | (last_bulk_time)); | ||
333 | snprintf (msg, sizeof (msg), | 330 | snprintf (msg, sizeof (msg), |
334 | _("Message `%.*s' repeated %u times in the last %s\n"), | 331 | _("Message `%.*s' repeated %u times in the last %s\n"), |
335 | BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); | 332 | BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); |
@@ -352,14 +349,14 @@ void | |||
352 | GNUNET_log_skip (unsigned int n, int check_reset) | 349 | GNUNET_log_skip (unsigned int n, int check_reset) |
353 | { | 350 | { |
354 | if (n == 0) | 351 | if (n == 0) |
355 | { | 352 | { |
356 | int ok; | 353 | int ok; |
357 | 354 | ||
358 | ok = (0 == skip_log); | 355 | ok = (0 == skip_log); |
359 | skip_log = 0; | 356 | skip_log = 0; |
360 | if (check_reset) | 357 | if (check_reset) |
361 | GNUNET_assert (ok); | 358 | GNUNET_assert (ok); |
362 | } | 359 | } |
363 | else | 360 | else |
364 | skip_log += n; | 361 | skip_log += n; |
365 | } | 362 | } |
@@ -387,10 +384,10 @@ mylog (enum GNUNET_ErrorType kind, | |||
387 | va_list vacp; | 384 | va_list vacp; |
388 | 385 | ||
389 | if (skip_log > 0) | 386 | if (skip_log > 0) |
390 | { | 387 | { |
391 | skip_log--; | 388 | skip_log--; |
392 | return; | 389 | return; |
393 | } | 390 | } |
394 | if ((kind & (~GNUNET_ERROR_TYPE_BULK)) > min_level) | 391 | if ((kind & (~GNUNET_ERROR_TYPE_BULK)) > min_level) |
395 | return; | 392 | return; |
396 | va_copy (vacp, va); | 393 | va_copy (vacp, va); |
@@ -403,15 +400,18 @@ mylog (enum GNUNET_ErrorType kind, | |||
403 | time (&timetmp); | 400 | time (&timetmp); |
404 | memset (date, 0, DATE_STR_SIZE); | 401 | memset (date, 0, DATE_STR_SIZE); |
405 | tmptr = localtime (&timetmp); | 402 | tmptr = localtime (&timetmp); |
406 | gettimeofday(&timeofday, NULL); | 403 | gettimeofday (&timeofday, NULL); |
407 | if (NULL != tmptr) | 404 | if (NULL != tmptr) |
408 | { | 405 | { |
409 | #ifdef WINDOWS | 406 | #ifdef WINDOWS |
410 | LARGE_INTEGER pc; | 407 | LARGE_INTEGER pc; |
408 | |||
411 | pc.QuadPart = 0; | 409 | pc.QuadPart = 0; |
412 | QueryPerformanceCounter (&pc); | 410 | QueryPerformanceCounter (&pc); |
413 | strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr); | 411 | strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr); |
414 | snprintf (date, sizeof (date), date2, (long long) (pc.QuadPart / (performance_frequency.QuadPart / 1000))); | 412 | snprintf (date, sizeof (date), date2, |
413 | (long long) (pc.QuadPart / | ||
414 | (performance_frequency.QuadPart / 1000))); | ||
415 | #else | 415 | #else |
416 | strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr); | 416 | strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr); |
417 | snprintf (date, sizeof (date), date2, timeofday.tv_usec); | 417 | snprintf (date, sizeof (date), date2, timeofday.tv_usec); |
@@ -422,15 +422,14 @@ mylog (enum GNUNET_ErrorType kind, | |||
422 | if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && | 422 | if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && |
423 | (last_bulk_time.abs_value != 0) && | 423 | (last_bulk_time.abs_value != 0) && |
424 | (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) | 424 | (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) |
425 | { | 425 | { |
426 | last_bulk_repeat++; | 426 | last_bulk_repeat++; |
427 | if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value > | 427 | if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value > |
428 | BULK_DELAY_THRESHOLD) | 428 | BULK_DELAY_THRESHOLD) || (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) |
429 | || (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) | 429 | flush_bulk (date); |
430 | flush_bulk (date); | 430 | free (buf); |
431 | free (buf); | 431 | return; |
432 | return; | 432 | } |
433 | } | ||
434 | flush_bulk (date); | 433 | flush_bulk (date); |
435 | strncpy (last_bulk, buf, sizeof (last_bulk)); | 434 | strncpy (last_bulk, buf, sizeof (last_bulk)); |
436 | last_bulk_repeat = 0; | 435 | last_bulk_repeat = 0; |
@@ -453,6 +452,7 @@ void | |||
453 | GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...) | 452 | GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...) |
454 | { | 453 | { |
455 | va_list va; | 454 | va_list va; |
455 | |||
456 | va_start (va, message); | 456 | va_start (va, message); |
457 | mylog (kind, component, message, va); | 457 | mylog (kind, component, message, va); |
458 | va_end (va); | 458 | va_end (va); |
@@ -476,11 +476,7 @@ GNUNET_log_from (enum GNUNET_ErrorType kind, | |||
476 | char comp_w_pid[128]; | 476 | char comp_w_pid[128]; |
477 | 477 | ||
478 | va_start (va, message); | 478 | va_start (va, message); |
479 | GNUNET_snprintf (comp_w_pid, | 479 | GNUNET_snprintf (comp_w_pid, sizeof (comp_w_pid), "%s-%d", comp, getpid ()); |
480 | sizeof (comp_w_pid), | ||
481 | "%s-%d", | ||
482 | comp, | ||
483 | getpid()); | ||
484 | mylog (kind, comp_w_pid, message, va); | 480 | mylog (kind, comp_w_pid, message, va); |
485 | va_end (va); | 481 | va_end (va); |
486 | } | 482 | } |
@@ -539,7 +535,7 @@ GNUNET_h2s_full (const GNUNET_HashCode * hc) | |||
539 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 535 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
540 | 536 | ||
541 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); | 537 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); |
542 | ret.encoding[sizeof(ret)-1] = '\0'; | 538 | ret.encoding[sizeof (ret) - 1] = '\0'; |
543 | return (const char *) ret.encoding; | 539 | return (const char *) ret.encoding; |
544 | } | 540 | } |
545 | 541 | ||
@@ -587,46 +583,47 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) | |||
587 | if (addr == NULL) | 583 | if (addr == NULL) |
588 | return _("unknown address"); | 584 | return _("unknown address"); |
589 | switch (addr->sa_family) | 585 | switch (addr->sa_family) |
590 | { | 586 | { |
591 | case AF_INET: | 587 | case AF_INET: |
592 | if (addrlen != sizeof (struct sockaddr_in)) | 588 | if (addrlen != sizeof (struct sockaddr_in)) |
593 | return "<invalid v4 address>"; | 589 | return "<invalid v4 address>"; |
594 | v4 = (const struct sockaddr_in *) addr; | 590 | v4 = (const struct sockaddr_in *) addr; |
595 | inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); | 591 | inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); |
596 | if (0 == ntohs (v4->sin_port)) | 592 | if (0 == ntohs (v4->sin_port)) |
597 | return buf; | ||
598 | strcat (buf, ":"); | ||
599 | GNUNET_snprintf (b2, sizeof(b2), "%u", ntohs (v4->sin_port)); | ||
600 | strcat (buf, b2); | ||
601 | return buf; | ||
602 | case AF_INET6: | ||
603 | if (addrlen != sizeof (struct sockaddr_in6)) | ||
604 | return "<invalid v4 address>"; | ||
605 | v6 = (const struct sockaddr_in6 *) addr; | ||
606 | buf[0] = '['; | ||
607 | inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); | ||
608 | if (0 == ntohs (v6->sin6_port)) | ||
609 | return &buf[1]; | ||
610 | strcat (buf, "]:"); | ||
611 | GNUNET_snprintf (b2, sizeof(b2), "%u", ntohs (v6->sin6_port)); | ||
612 | strcat (buf, b2); | ||
613 | return buf; | ||
614 | case AF_UNIX: | ||
615 | if (addrlen <= sizeof (sa_family_t)) | ||
616 | return "<unbound UNIX client>"; | ||
617 | un = (const struct sockaddr_un*) addr; | ||
618 | off = 0; | ||
619 | if (un->sun_path[0] == '\0') off++; | ||
620 | snprintf (buf, | ||
621 | sizeof (buf), | ||
622 | "%s%.*s", | ||
623 | (off == 1) ? "@" : "", | ||
624 | (int) (addrlen - sizeof (sa_family_t) - 1 - off), | ||
625 | &un->sun_path[off]); | ||
626 | return buf; | 593 | return buf; |
627 | default: | 594 | strcat (buf, ":"); |
628 | return _("invalid address"); | 595 | GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port)); |
629 | } | 596 | strcat (buf, b2); |
597 | return buf; | ||
598 | case AF_INET6: | ||
599 | if (addrlen != sizeof (struct sockaddr_in6)) | ||
600 | return "<invalid v4 address>"; | ||
601 | v6 = (const struct sockaddr_in6 *) addr; | ||
602 | buf[0] = '['; | ||
603 | inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); | ||
604 | if (0 == ntohs (v6->sin6_port)) | ||
605 | return &buf[1]; | ||
606 | strcat (buf, "]:"); | ||
607 | GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port)); | ||
608 | strcat (buf, b2); | ||
609 | return buf; | ||
610 | case AF_UNIX: | ||
611 | if (addrlen <= sizeof (sa_family_t)) | ||
612 | return "<unbound UNIX client>"; | ||
613 | un = (const struct sockaddr_un *) addr; | ||
614 | off = 0; | ||
615 | if (un->sun_path[0] == '\0') | ||
616 | off++; | ||
617 | snprintf (buf, | ||
618 | sizeof (buf), | ||
619 | "%s%.*s", | ||
620 | (off == 1) ? "@" : "", | ||
621 | (int) (addrlen - sizeof (sa_family_t) - 1 - off), | ||
622 | &un->sun_path[off]); | ||
623 | return buf; | ||
624 | default: | ||
625 | return _("invalid address"); | ||
626 | } | ||
630 | } | 627 | } |
631 | 628 | ||
632 | 629 | ||
diff --git a/src/util/configuration.c b/src/util/configuration.c index 88bde1c38..b3b9d5ea8 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -168,90 +168,89 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
168 | return GNUNET_SYSERR; | 168 | return GNUNET_SYSERR; |
169 | dirty = cfg->dirty; /* back up value! */ | 169 | dirty = cfg->dirty; /* back up value! */ |
170 | if (NULL == (fp = FOPEN (fn, "r"))) | 170 | if (NULL == (fp = FOPEN (fn, "r"))) |
171 | { | 171 | { |
172 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); | 172 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); |
173 | GNUNET_free (fn); | 173 | GNUNET_free (fn); |
174 | return GNUNET_SYSERR; | 174 | return GNUNET_SYSERR; |
175 | } | 175 | } |
176 | GNUNET_free (fn); | 176 | GNUNET_free (fn); |
177 | ret = GNUNET_OK; | 177 | ret = GNUNET_OK; |
178 | section = GNUNET_strdup (""); | 178 | section = GNUNET_strdup (""); |
179 | memset (line, 0, 256); | 179 | memset (line, 0, 256); |
180 | nr = 0; | 180 | nr = 0; |
181 | while (NULL != fgets (line, 255, fp)) | 181 | while (NULL != fgets (line, 255, fp)) |
182 | { | ||
183 | nr++; | ||
184 | for (i = 0; i < 255; i++) | ||
185 | if (line[i] == '\t') | ||
186 | line[i] = ' '; | ||
187 | if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || line[0] == '\r') | ||
188 | continue; | ||
189 | emptyline = 1; | ||
190 | for (i = 0; (i < 255 && line[i] != 0); i++) | ||
191 | if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') | ||
192 | emptyline = 0; | ||
193 | if (emptyline == 1) | ||
194 | continue; | ||
195 | /* remove tailing whitespace */ | ||
196 | for (i = strlen (line) - 1; (i >= 0) && (isspace ((unsigned char) line[i])); | ||
197 | i--) | ||
198 | line[i] = '\0'; | ||
199 | if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) | ||
182 | { | 200 | { |
183 | nr++; | 201 | /* @INLINE@ value */ |
184 | for (i = 0; i < 255; i++) | 202 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) |
185 | if (line[i] == '\t') | 203 | ret = GNUNET_SYSERR; /* failed to parse included config */ |
186 | line[i] = ' '; | 204 | } |
187 | if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || | 205 | else if (1 == sscanf (line, "[%99[^]]]", value)) |
188 | line[0] == '\r') | 206 | { |
189 | continue; | 207 | /* [value] */ |
190 | emptyline = 1; | 208 | GNUNET_free (section); |
191 | for (i = 0; (i < 255 && line[i] != 0); i++) | 209 | section = GNUNET_strdup (value); |
192 | if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') | 210 | } |
193 | emptyline = 0; | 211 | else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) |
194 | if (emptyline == 1) | 212 | { |
195 | continue; | 213 | /* tag = value */ |
196 | /* remove tailing whitespace */ | 214 | /* Strip LF */ |
197 | for (i = strlen (line) - 1; (i >= 0) && (isspace ( (unsigned char) line[i])); i--) | 215 | i = strlen (value) - 1; |
198 | line[i] = '\0'; | 216 | while ((i >= 0) && (isspace ((unsigned char) value[i]))) |
199 | if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) | 217 | value[i--] = '\0'; |
200 | { | 218 | /* remove quotes */ |
201 | /* @INLINE@ value */ | 219 | i = 0; |
202 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) | 220 | if (value[0] == '"') |
203 | ret = GNUNET_SYSERR; /* failed to parse included config */ | 221 | { |
204 | } | 222 | i = 1; |
205 | else if (1 == sscanf (line, "[%99[^]]]", value)) | 223 | while ((value[i] != '\0') && (value[i] != '"')) |
224 | i++; | ||
225 | if (value[i] == '"') | ||
206 | { | 226 | { |
207 | /* [value] */ | 227 | value[i] = '\0'; |
208 | GNUNET_free (section); | 228 | i = 1; |
209 | section = GNUNET_strdup (value); | ||
210 | } | 229 | } |
211 | else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) | 230 | else |
212 | { | ||
213 | /* tag = value */ | ||
214 | /* Strip LF */ | ||
215 | i = strlen (value) - 1; | ||
216 | while ((i >= 0) && (isspace ( (unsigned char) value[i]))) | ||
217 | value[i--] = '\0'; | ||
218 | /* remove quotes */ | ||
219 | i = 0; | 231 | i = 0; |
220 | if (value[0] == '"') | 232 | } |
221 | { | 233 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]); |
222 | i = 1; | 234 | } |
223 | while ((value[i] != '\0') && (value[i] != '"')) | 235 | else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag)) |
224 | i++; | 236 | { |
225 | if (value[i] == '"') | 237 | /* tag = */ |
226 | { | 238 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, ""); |
227 | value[i] = '\0'; | 239 | } |
228 | i = 1; | 240 | else |
229 | } | 241 | { |
230 | else | 242 | /* parse error */ |
231 | i = 0; | 243 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
232 | } | 244 | _ |
233 | GNUNET_CONFIGURATION_set_value_string (cfg, | 245 | ("Syntax error in configuration file `%s' at line %u.\n"), |
234 | section, tag, &value[i]); | 246 | filename, nr); |
235 | } | 247 | ret = GNUNET_SYSERR; |
236 | else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag)) | 248 | break; |
237 | { | ||
238 | /* tag = */ | ||
239 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, ""); | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | /* parse error */ | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
245 | _ | ||
246 | ("Syntax error in configuration file `%s' at line %u.\n"), | ||
247 | filename, nr); | ||
248 | ret = GNUNET_SYSERR; | ||
249 | break; | ||
250 | } | ||
251 | } | 249 | } |
250 | } | ||
252 | GNUNET_assert (0 == fclose (fp)); | 251 | GNUNET_assert (0 == fclose (fp)); |
253 | /* restore dirty flag - anything we set in the meantime | 252 | /* restore dirty flag - anything we set in the meantime |
254 | came from disk */ | 253 | * came from disk */ |
255 | cfg->dirty = dirty; | 254 | cfg->dirty = dirty; |
256 | GNUNET_free (section); | 255 | GNUNET_free (section); |
257 | return ret; | 256 | return ret; |
@@ -295,66 +294,66 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
295 | if (fn == NULL) | 294 | if (fn == NULL) |
296 | return GNUNET_SYSERR; | 295 | return GNUNET_SYSERR; |
297 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) | 296 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) |
298 | { | 297 | { |
299 | GNUNET_free (fn); | 298 | GNUNET_free (fn); |
300 | return GNUNET_SYSERR; | 299 | return GNUNET_SYSERR; |
301 | } | 300 | } |
302 | if (NULL == (fp = FOPEN (fn, "w"))) | 301 | if (NULL == (fp = FOPEN (fn, "w"))) |
303 | { | 302 | { |
304 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); | 303 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); |
305 | GNUNET_free (fn); | 304 | GNUNET_free (fn); |
306 | return GNUNET_SYSERR; | 305 | return GNUNET_SYSERR; |
307 | } | 306 | } |
308 | GNUNET_free (fn); | 307 | GNUNET_free (fn); |
309 | error = 0; | 308 | error = 0; |
310 | sec = cfg->sections; | 309 | sec = cfg->sections; |
311 | while (sec != NULL) | 310 | while (sec != NULL) |
311 | { | ||
312 | if (0 > fprintf (fp, "[%s]\n", sec->name)) | ||
312 | { | 313 | { |
313 | if (0 > fprintf (fp, "[%s]\n", sec->name)) | 314 | error = 1; |
314 | { | 315 | break; |
315 | error = 1; | 316 | } |
316 | break; | 317 | ent = sec->entries; |
317 | } | 318 | while (ent != NULL) |
318 | ent = sec->entries; | 319 | { |
319 | while (ent != NULL) | 320 | if (ent->val != NULL) |
321 | { | ||
322 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); | ||
323 | strcpy (val, ent->val); | ||
324 | while (NULL != (pos = strstr (val, "\n"))) | ||
320 | { | 325 | { |
321 | if (ent->val != NULL) | 326 | memmove (&pos[2], &pos[1], strlen (&pos[1])); |
322 | { | 327 | pos[0] = '\\'; |
323 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); | 328 | pos[1] = 'n'; |
324 | strcpy (val, ent->val); | ||
325 | while (NULL != (pos = strstr (val, "\n"))) | ||
326 | { | ||
327 | memmove (&pos[2], &pos[1], strlen (&pos[1])); | ||
328 | pos[0] = '\\'; | ||
329 | pos[1] = 'n'; | ||
330 | } | ||
331 | if (0 > fprintf (fp, "%s = %s\n", ent->key, val)) | ||
332 | { | ||
333 | error = 1; | ||
334 | GNUNET_free (val); | ||
335 | break; | ||
336 | } | ||
337 | GNUNET_free (val); | ||
338 | } | ||
339 | ent = ent->next; | ||
340 | } | 329 | } |
341 | if (error != 0) | 330 | if (0 > fprintf (fp, "%s = %s\n", ent->key, val)) |
342 | break; | ||
343 | if (0 > fprintf (fp, "\n")) | ||
344 | { | 331 | { |
345 | error = 1; | 332 | error = 1; |
333 | GNUNET_free (val); | ||
346 | break; | 334 | break; |
347 | } | 335 | } |
348 | sec = sec->next; | 336 | GNUNET_free (val); |
337 | } | ||
338 | ent = ent->next; | ||
339 | } | ||
340 | if (error != 0) | ||
341 | break; | ||
342 | if (0 > fprintf (fp, "\n")) | ||
343 | { | ||
344 | error = 1; | ||
345 | break; | ||
349 | } | 346 | } |
347 | sec = sec->next; | ||
348 | } | ||
350 | if (error != 0) | 349 | if (error != 0) |
351 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename); | 350 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename); |
352 | GNUNET_assert (0 == fclose (fp)); | 351 | GNUNET_assert (0 == fclose (fp)); |
353 | if (error != 0) | 352 | if (error != 0) |
354 | { | 353 | { |
355 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ | 354 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ |
356 | return GNUNET_SYSERR; | 355 | return GNUNET_SYSERR; |
357 | } | 356 | } |
358 | cfg->dirty = GNUNET_NO; /* last write succeeded */ | 357 | cfg->dirty = GNUNET_NO; /* last write succeeded */ |
359 | return GNUNET_OK; | 358 | return GNUNET_OK; |
360 | } | 359 | } |
@@ -377,15 +376,15 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
377 | 376 | ||
378 | spos = cfg->sections; | 377 | spos = cfg->sections; |
379 | while (spos != NULL) | 378 | while (spos != NULL) |
379 | { | ||
380 | epos = spos->entries; | ||
381 | while (epos != NULL) | ||
380 | { | 382 | { |
381 | epos = spos->entries; | 383 | iter (iter_cls, spos->name, epos->key, epos->val); |
382 | while (epos != NULL) | 384 | epos = epos->next; |
383 | { | ||
384 | iter (iter_cls, spos->name, epos->key, epos->val); | ||
385 | epos = epos->next; | ||
386 | } | ||
387 | spos = spos->next; | ||
388 | } | 385 | } |
386 | spos = spos->next; | ||
387 | } | ||
389 | } | 388 | } |
390 | 389 | ||
391 | 390 | ||
@@ -398,10 +397,11 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
398 | * @param iter_cls closure for iter | 397 | * @param iter_cls closure for iter |
399 | */ | 398 | */ |
400 | void | 399 | void |
401 | GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg, | 400 | GNUNET_CONFIGURATION_iterate_section_values (const struct |
402 | const char *section, | 401 | GNUNET_CONFIGURATION_Handle *cfg, |
403 | GNUNET_CONFIGURATION_Iterator iter, | 402 | const char *section, |
404 | void *iter_cls) | 403 | GNUNET_CONFIGURATION_Iterator iter, |
404 | void *iter_cls) | ||
405 | { | 405 | { |
406 | struct ConfigSection *spos; | 406 | struct ConfigSection *spos; |
407 | struct ConfigEntry *epos; | 407 | struct ConfigEntry *epos; |
@@ -415,10 +415,10 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_H | |||
415 | 415 | ||
416 | epos = spos->entries; | 416 | epos = spos->entries; |
417 | while (epos != NULL) | 417 | while (epos != NULL) |
418 | { | 418 | { |
419 | iter (iter_cls, spos->name, epos->key, epos->val); | 419 | iter (iter_cls, spos->name, epos->key, epos->val); |
420 | epos = epos->next; | 420 | epos = epos->next; |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | 424 | ||
@@ -430,20 +430,21 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_H | |||
430 | * @param iter_cls closure for iter | 430 | * @param iter_cls closure for iter |
431 | */ | 431 | */ |
432 | void | 432 | void |
433 | GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg, | 433 | GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle |
434 | GNUNET_CONFIGURATION_Section_Iterator iter, | 434 | *cfg, |
435 | void *iter_cls) | 435 | GNUNET_CONFIGURATION_Section_Iterator |
436 | iter, void *iter_cls) | ||
436 | { | 437 | { |
437 | struct ConfigSection *spos; | 438 | struct ConfigSection *spos; |
438 | struct ConfigSection *next; | 439 | struct ConfigSection *next; |
439 | 440 | ||
440 | next = cfg->sections; | 441 | next = cfg->sections; |
441 | while (next != NULL) | 442 | while (next != NULL) |
442 | { | 443 | { |
443 | spos = next; | 444 | spos = next; |
444 | next = spos->next; | 445 | next = spos->next; |
445 | iter (iter_cls, spos->name); | 446 | iter (iter_cls, spos->name); |
446 | } | 447 | } |
447 | } | 448 | } |
448 | 449 | ||
449 | /** | 450 | /** |
@@ -452,39 +453,39 @@ GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle | |||
452 | * @param cfg configuration to inspect | 453 | * @param cfg configuration to inspect |
453 | * @param section name of the section to remove | 454 | * @param section name of the section to remove |
454 | */ | 455 | */ |
455 | void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | 456 | void |
456 | const char *section) | 457 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, |
458 | const char *section) | ||
457 | { | 459 | { |
458 | struct ConfigSection *spos; | 460 | struct ConfigSection *spos; |
459 | struct ConfigSection *prev; | 461 | struct ConfigSection *prev; |
460 | struct ConfigEntry *ent; | 462 | struct ConfigEntry *ent; |
461 | 463 | ||
462 | prev = NULL; | 464 | prev = NULL; |
463 | spos = cfg->sections; | 465 | spos = cfg->sections; |
464 | while (spos != NULL) | 466 | while (spos != NULL) |
467 | { | ||
468 | if (0 == strcmp (section, spos->name)) | ||
465 | { | 469 | { |
466 | if (0 == strcmp (section, | 470 | if (prev == NULL) |
467 | spos->name)) | 471 | cfg->sections = spos->next; |
468 | { | 472 | else |
469 | if (prev == NULL) | 473 | prev->next = spos->next; |
470 | cfg->sections = spos->next; | 474 | while (NULL != (ent = spos->entries)) |
471 | else | 475 | { |
472 | prev->next = spos->next; | 476 | spos->entries = ent->next; |
473 | while (NULL != (ent = spos->entries)) | 477 | GNUNET_free (ent->key); |
474 | { | 478 | GNUNET_free_non_null (ent->val); |
475 | spos->entries = ent->next; | 479 | GNUNET_free (ent); |
476 | GNUNET_free (ent->key); | 480 | cfg->dirty = GNUNET_YES; |
477 | GNUNET_free_non_null (ent->val); | 481 | } |
478 | GNUNET_free (ent); | 482 | GNUNET_free (spos->name); |
479 | cfg->dirty = GNUNET_YES; | 483 | GNUNET_free (spos); |
480 | } | 484 | return; |
481 | GNUNET_free (spos->name); | ||
482 | GNUNET_free (spos); | ||
483 | return; | ||
484 | } | ||
485 | prev = spos; | ||
486 | spos = spos->next; | ||
487 | } | 485 | } |
486 | prev = spos; | ||
487 | spos = spos->next; | ||
488 | } | ||
488 | } | 489 | } |
489 | 490 | ||
490 | 491 | ||
@@ -502,6 +503,7 @@ copy_entry (void *cls, | |||
502 | const char *section, const char *option, const char *value) | 503 | const char *section, const char *option, const char *value) |
503 | { | 504 | { |
504 | struct GNUNET_CONFIGURATION_Handle *dst = cls; | 505 | struct GNUNET_CONFIGURATION_Handle *dst = cls; |
506 | |||
505 | GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); | 507 | GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); |
506 | } | 508 | } |
507 | 509 | ||
@@ -531,8 +533,7 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
531 | * @return matching entry, NULL if not found | 533 | * @return matching entry, NULL if not found |
532 | */ | 534 | */ |
533 | static struct ConfigSection * | 535 | static struct ConfigSection * |
534 | findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, | 536 | findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) |
535 | const char *section) | ||
536 | { | 537 | { |
537 | struct ConfigSection *pos; | 538 | struct ConfigSection *pos; |
538 | 539 | ||
@@ -584,15 +585,11 @@ compareEntries (void *cls, | |||
584 | { | 585 | { |
585 | struct DiffHandle *dh = cls; | 586 | struct DiffHandle *dh = cls; |
586 | struct ConfigEntry *entNew; | 587 | struct ConfigEntry *entNew; |
587 | 588 | ||
588 | entNew = findEntry (dh->cfgDefault, section, option); | 589 | entNew = findEntry (dh->cfgDefault, section, option); |
589 | if ( (entNew != NULL) && | 590 | if ((entNew != NULL) && (strcmp (entNew->val, value) == 0)) |
590 | (strcmp (entNew->val, value) == 0) ) | ||
591 | return; | 591 | return; |
592 | GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, | 592 | GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value); |
593 | section, | ||
594 | option, | ||
595 | value); | ||
596 | } | 593 | } |
597 | 594 | ||
598 | 595 | ||
@@ -606,8 +603,8 @@ compareEntries (void *cls, | |||
606 | int | 603 | int |
607 | GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle | 604 | GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle |
608 | *cfgDefault, | 605 | *cfgDefault, |
609 | const struct GNUNET_CONFIGURATION_Handle *cfgNew, | 606 | const struct GNUNET_CONFIGURATION_Handle |
610 | const char *filename) | 607 | *cfgNew, const char *filename) |
611 | { | 608 | { |
612 | int ret; | 609 | int ret; |
613 | struct DiffHandle diffHandle; | 610 | struct DiffHandle diffHandle; |
@@ -640,19 +637,19 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle | |||
640 | 637 | ||
641 | e = findEntry (cfg, section, option); | 638 | e = findEntry (cfg, section, option); |
642 | if (e != NULL) | 639 | if (e != NULL) |
643 | { | 640 | { |
644 | GNUNET_free_non_null (e->val); | 641 | GNUNET_free_non_null (e->val); |
645 | e->val = GNUNET_strdup (value); | 642 | e->val = GNUNET_strdup (value); |
646 | return; | 643 | return; |
647 | } | 644 | } |
648 | sec = findSection (cfg, section); | 645 | sec = findSection (cfg, section); |
649 | if (sec == NULL) | 646 | if (sec == NULL) |
650 | { | 647 | { |
651 | sec = GNUNET_malloc (sizeof (struct ConfigSection)); | 648 | sec = GNUNET_malloc (sizeof (struct ConfigSection)); |
652 | sec->name = GNUNET_strdup (section); | 649 | sec->name = GNUNET_strdup (section); |
653 | sec->next = cfg->sections; | 650 | sec->next = cfg->sections; |
654 | cfg->sections = sec; | 651 | cfg->sections = sec; |
655 | } | 652 | } |
656 | e = GNUNET_malloc (sizeof (struct ConfigEntry)); | 653 | e = GNUNET_malloc (sizeof (struct ConfigEntry)); |
657 | e->key = GNUNET_strdup (option); | 654 | e->key = GNUNET_strdup (option); |
658 | e->val = GNUNET_strdup (value); | 655 | e->val = GNUNET_strdup (value); |
@@ -676,6 +673,7 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle | |||
676 | unsigned long long number) | 673 | unsigned long long number) |
677 | { | 674 | { |
678 | char s[64]; | 675 | char s[64]; |
676 | |||
679 | GNUNET_snprintf (s, 64, "%llu", number); | 677 | GNUNET_snprintf (s, 64, "%llu", number); |
680 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); | 678 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); |
681 | } | 679 | } |
@@ -729,12 +727,12 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | |||
729 | e = findEntry (cfg, section, option); | 727 | e = findEntry (cfg, section, option); |
730 | if (e == NULL) | 728 | if (e == NULL) |
731 | return GNUNET_SYSERR; | 729 | return GNUNET_SYSERR; |
732 | if ( (0 == strcasecmp (e->val, "infinity")) || | 730 | if ((0 == strcasecmp (e->val, "infinity")) || |
733 | (0 == strcasecmp (e->val, "forever")) ) | 731 | (0 == strcasecmp (e->val, "forever"))) |
734 | { | 732 | { |
735 | *time = GNUNET_TIME_UNIT_FOREVER_REL; | 733 | *time = GNUNET_TIME_UNIT_FOREVER_REL; |
736 | return GNUNET_OK; | 734 | return GNUNET_OK; |
737 | } | 735 | } |
738 | if (1 != SSCANF (e->val, "%llu", &num)) | 736 | if (1 != SSCANF (e->val, "%llu", &num)) |
739 | return GNUNET_SYSERR; | 737 | return GNUNET_SYSERR; |
740 | time->rel_value = (uint64_t) num; | 738 | time->rel_value = (uint64_t) num; |
@@ -762,10 +760,10 @@ GNUNET_CONFIGURATION_get_value_string (const struct | |||
762 | 760 | ||
763 | e = findEntry (cfg, section, option); | 761 | e = findEntry (cfg, section, option); |
764 | if ((e == NULL) || (e->val == NULL)) | 762 | if ((e == NULL) || (e->val == NULL)) |
765 | { | 763 | { |
766 | *value = NULL; | 764 | *value = NULL; |
767 | return GNUNET_SYSERR; | 765 | return GNUNET_SYSERR; |
768 | } | 766 | } |
769 | *value = GNUNET_strdup (e->val); | 767 | *value = GNUNET_strdup (e->val); |
770 | return GNUNET_OK; | 768 | return GNUNET_OK; |
771 | } | 769 | } |
@@ -788,8 +786,7 @@ GNUNET_CONFIGURATION_get_value_choice (const struct | |||
788 | GNUNET_CONFIGURATION_Handle *cfg, | 786 | GNUNET_CONFIGURATION_Handle *cfg, |
789 | const char *section, | 787 | const char *section, |
790 | const char *option, | 788 | const char *option, |
791 | const char **choices, | 789 | const char **choices, const char **value) |
792 | const char **value) | ||
793 | { | 790 | { |
794 | struct ConfigEntry *e; | 791 | struct ConfigEntry *e; |
795 | int i; | 792 | int i; |
@@ -799,19 +796,19 @@ GNUNET_CONFIGURATION_get_value_choice (const struct | |||
799 | return GNUNET_SYSERR; | 796 | return GNUNET_SYSERR; |
800 | i = 0; | 797 | i = 0; |
801 | while (choices[i] != NULL) | 798 | while (choices[i] != NULL) |
802 | { | 799 | { |
803 | if (0 == strcasecmp (choices[i], e->val)) | 800 | if (0 == strcasecmp (choices[i], e->val)) |
804 | break; | 801 | break; |
805 | i++; | 802 | i++; |
806 | } | 803 | } |
807 | if (choices[i] == NULL) | 804 | if (choices[i] == NULL) |
808 | { | 805 | { |
809 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 806 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
810 | _("Configuration value '%s' for '%s'" | 807 | _("Configuration value '%s' for '%s'" |
811 | " in section '%s' is not in set of legal choices\n"), | 808 | " in section '%s' is not in set of legal choices\n"), |
812 | e->val, option, section); | 809 | e->val, option, section); |
813 | return GNUNET_SYSERR; | 810 | return GNUNET_SYSERR; |
814 | } | 811 | } |
815 | *value = choices[i]; | 812 | *value = choices[i]; |
816 | return GNUNET_OK; | 813 | return GNUNET_OK; |
817 | } | 814 | } |
@@ -826,10 +823,10 @@ GNUNET_CONFIGURATION_get_value_choice (const struct | |||
826 | */ | 823 | */ |
827 | int | 824 | int |
828 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle | 825 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle |
829 | *cfg, const char *section, | 826 | *cfg, const char *section, const char *option) |
830 | const char *option) | ||
831 | { | 827 | { |
832 | struct ConfigEntry *e; | 828 | struct ConfigEntry *e; |
829 | |||
833 | if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL)) | 830 | if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL)) |
834 | return GNUNET_NO; | 831 | return GNUNET_NO; |
835 | return GNUNET_YES; | 832 | return GNUNET_YES; |
@@ -861,25 +858,25 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle | |||
861 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0')) | 858 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0')) |
862 | i++; | 859 | i++; |
863 | if (orig[i] == '\0') | 860 | if (orig[i] == '\0') |
864 | { | 861 | { |
865 | post = ""; | 862 | post = ""; |
866 | } | 863 | } |
867 | else | 864 | else |
868 | { | 865 | { |
869 | orig[i] = '\0'; | 866 | orig[i] = '\0'; |
870 | post = &orig[i + 1]; | 867 | post = &orig[i + 1]; |
871 | } | 868 | } |
872 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 869 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
873 | "PATHS", | 870 | "PATHS", |
874 | &orig[1], &prefix)) | 871 | &orig[1], &prefix)) |
872 | { | ||
873 | if (NULL == (env = getenv (&orig[1]))) | ||
875 | { | 874 | { |
876 | if (NULL == (env = getenv (&orig[1]))) | 875 | orig[i] = DIR_SEPARATOR; |
877 | { | 876 | return orig; |
878 | orig[i] = DIR_SEPARATOR; | ||
879 | return orig; | ||
880 | } | ||
881 | prefix = GNUNET_strdup (env); | ||
882 | } | 877 | } |
878 | prefix = GNUNET_strdup (env); | ||
879 | } | ||
883 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); | 880 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); |
884 | strcpy (result, prefix); | 881 | strcpy (result, prefix); |
885 | if ((strlen (prefix) == 0) || | 882 | if ((strlen (prefix) == 0) || |
@@ -912,10 +909,10 @@ GNUNET_CONFIGURATION_get_value_filename (const struct | |||
912 | 909 | ||
913 | if (GNUNET_OK != | 910 | if (GNUNET_OK != |
914 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) | 911 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) |
915 | { | 912 | { |
916 | *value = NULL; | 913 | *value = NULL; |
917 | return GNUNET_SYSERR; | 914 | return GNUNET_SYSERR; |
918 | } | 915 | } |
919 | tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); | 916 | tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); |
920 | *value = GNUNET_STRINGS_filename_expand (tmp); | 917 | *value = GNUNET_STRINGS_filename_expand (tmp); |
921 | GNUNET_free (tmp); | 918 | GNUNET_free (tmp); |
@@ -984,46 +981,46 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct | |||
984 | ret = 0; | 981 | ret = 0; |
985 | pos = list; | 982 | pos = list; |
986 | while (1) | 983 | while (1) |
984 | { | ||
985 | while (pos[0] == ' ') | ||
986 | pos++; | ||
987 | if (strlen (pos) == 0) | ||
988 | break; | ||
989 | end = pos + 1; | ||
990 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
987 | { | 991 | { |
988 | while (pos[0] == ' ') | 992 | if (end[0] == '\\') |
989 | pos++; | 993 | { |
990 | if (strlen (pos) == 0) | 994 | switch (end[1]) |
991 | break; | ||
992 | end = pos + 1; | ||
993 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
994 | { | 995 | { |
995 | if (end[0] == '\\') | 996 | case '\\': |
996 | { | 997 | case ' ': |
997 | switch (end[1]) | 998 | memmove (end, &end[1], strlen (&end[1]) + 1); |
998 | { | 999 | case '\0': |
999 | case '\\': | 1000 | /* illegal, but just keep it */ |
1000 | case ' ': | 1001 | break; |
1001 | memmove (end, &end[1], strlen (&end[1]) + 1); | 1002 | default: |
1002 | case '\0': | 1003 | /* illegal, but just ignore that there was a '/' */ |
1003 | /* illegal, but just keep it */ | 1004 | break; |
1004 | break; | ||
1005 | default: | ||
1006 | /* illegal, but just ignore that there was a '/' */ | ||
1007 | break; | ||
1008 | } | ||
1009 | } | ||
1010 | end++; | ||
1011 | } | ||
1012 | old = end[0]; | ||
1013 | end[0] = '\0'; | ||
1014 | if (strlen (pos) > 0) | ||
1015 | { | ||
1016 | ret++; | ||
1017 | if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) | ||
1018 | { | ||
1019 | ret = GNUNET_SYSERR; | ||
1020 | break; | ||
1021 | } | ||
1022 | } | 1005 | } |
1023 | if (old == '\0') | 1006 | } |
1007 | end++; | ||
1008 | } | ||
1009 | old = end[0]; | ||
1010 | end[0] = '\0'; | ||
1011 | if (strlen (pos) > 0) | ||
1012 | { | ||
1013 | ret++; | ||
1014 | if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) | ||
1015 | { | ||
1016 | ret = GNUNET_SYSERR; | ||
1024 | break; | 1017 | break; |
1025 | pos = end + 1; | 1018 | } |
1026 | } | 1019 | } |
1020 | if (old == '\0') | ||
1021 | break; | ||
1022 | pos = end + 1; | ||
1023 | } | ||
1027 | GNUNET_free (list); | 1024 | GNUNET_free (list); |
1028 | return ret; | 1025 | return ret; |
1029 | } | 1026 | } |
@@ -1047,21 +1044,21 @@ escape_name (const char *value) | |||
1047 | rpos = value; | 1044 | rpos = value; |
1048 | wpos = escaped; | 1045 | wpos = escaped; |
1049 | while (rpos[0] != '\0') | 1046 | while (rpos[0] != '\0') |
1047 | { | ||
1048 | switch (rpos[0]) | ||
1050 | { | 1049 | { |
1051 | switch (rpos[0]) | 1050 | case '\\': |
1052 | { | 1051 | case ' ': |
1053 | case '\\': | 1052 | wpos[0] = '\\'; |
1054 | case ' ': | 1053 | wpos[1] = rpos[0]; |
1055 | wpos[0] = '\\'; | 1054 | wpos += 2; |
1056 | wpos[1] = rpos[0]; | 1055 | break; |
1057 | wpos += 2; | 1056 | default: |
1058 | break; | 1057 | wpos[0] = rpos[0]; |
1059 | default: | 1058 | wpos++; |
1060 | wpos[0] = rpos[0]; | ||
1061 | wpos++; | ||
1062 | } | ||
1063 | rpos++; | ||
1064 | } | 1059 | } |
1060 | rpos++; | ||
1061 | } | ||
1065 | return escaped; | 1062 | return escaped; |
1066 | } | 1063 | } |
1067 | 1064 | ||
@@ -1077,6 +1074,7 @@ static int | |||
1077 | test_match (void *cls, const char *fn) | 1074 | test_match (void *cls, const char *fn) |
1078 | { | 1075 | { |
1079 | const char *of = cls; | 1076 | const char *of = cls; |
1077 | |||
1080 | return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK; | 1078 | return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK; |
1081 | } | 1079 | } |
1082 | 1080 | ||
@@ -1159,56 +1157,55 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1159 | match = escape_name (value); | 1157 | match = escape_name (value); |
1160 | pos = list; | 1158 | pos = list; |
1161 | while (1) | 1159 | while (1) |
1160 | { | ||
1161 | while (pos[0] == ' ') | ||
1162 | pos++; | ||
1163 | if (strlen (pos) == 0) | ||
1164 | break; | ||
1165 | end = pos + 1; | ||
1166 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1162 | { | 1167 | { |
1163 | while (pos[0] == ' ') | 1168 | if (end[0] == '\\') |
1164 | pos++; | 1169 | { |
1165 | if (strlen (pos) == 0) | 1170 | switch (end[1]) |
1166 | break; | ||
1167 | end = pos + 1; | ||
1168 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1169 | { | 1171 | { |
1170 | if (end[0] == '\\') | 1172 | case '\\': |
1171 | { | 1173 | case ' ': |
1172 | switch (end[1]) | ||
1173 | { | ||
1174 | case '\\': | ||
1175 | case ' ': | ||
1176 | end++; | ||
1177 | break; | ||
1178 | case '\0': | ||
1179 | /* illegal, but just keep it */ | ||
1180 | break; | ||
1181 | default: | ||
1182 | /* illegal, but just ignore that there was a '/' */ | ||
1183 | break; | ||
1184 | } | ||
1185 | } | ||
1186 | end++; | 1174 | end++; |
1175 | break; | ||
1176 | case '\0': | ||
1177 | /* illegal, but just keep it */ | ||
1178 | break; | ||
1179 | default: | ||
1180 | /* illegal, but just ignore that there was a '/' */ | ||
1181 | break; | ||
1187 | } | 1182 | } |
1188 | old = end[0]; | 1183 | } |
1189 | end[0] = '\0'; | 1184 | end++; |
1190 | if (0 == strcmp (pos, match)) | ||
1191 | { | ||
1192 | if (old != '\0') | ||
1193 | memmove (pos, &end[1], strlen (&end[1]) + 1); | ||
1194 | else | ||
1195 | { | ||
1196 | if (pos != list) | ||
1197 | pos[-1] = '\0'; | ||
1198 | else | ||
1199 | pos[0] = '\0'; | ||
1200 | } | ||
1201 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
1202 | section, option, list); | ||
1203 | GNUNET_free (list); | ||
1204 | GNUNET_free (match); | ||
1205 | return GNUNET_OK; | ||
1206 | } | ||
1207 | if (old == '\0') | ||
1208 | break; | ||
1209 | end[0] = old; | ||
1210 | pos = end + 1; | ||
1211 | } | 1185 | } |
1186 | old = end[0]; | ||
1187 | end[0] = '\0'; | ||
1188 | if (0 == strcmp (pos, match)) | ||
1189 | { | ||
1190 | if (old != '\0') | ||
1191 | memmove (pos, &end[1], strlen (&end[1]) + 1); | ||
1192 | else | ||
1193 | { | ||
1194 | if (pos != list) | ||
1195 | pos[-1] = '\0'; | ||
1196 | else | ||
1197 | pos[0] = '\0'; | ||
1198 | } | ||
1199 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); | ||
1200 | GNUNET_free (list); | ||
1201 | GNUNET_free (match); | ||
1202 | return GNUNET_OK; | ||
1203 | } | ||
1204 | if (old == '\0') | ||
1205 | break; | ||
1206 | end[0] = old; | ||
1207 | pos = end + 1; | ||
1208 | } | ||
1212 | GNUNET_free (list); | 1209 | GNUNET_free (list); |
1213 | GNUNET_free (match); | 1210 | GNUNET_free (match); |
1214 | return GNUNET_NO; | 1211 | return GNUNET_NO; |
@@ -1241,19 +1238,17 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1241 | GNUNET_CONFIGURATION_parse (cfg, baseconfig)) || | 1238 | GNUNET_CONFIGURATION_parse (cfg, baseconfig)) || |
1242 | (!((filename == NULL) || | 1239 | (!((filename == NULL) || |
1243 | (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename))))) | 1240 | (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename))))) |
1244 | { | 1241 | { |
1245 | GNUNET_free (baseconfig); | 1242 | GNUNET_free (baseconfig); |
1246 | return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR; | 1243 | return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR; |
1247 | } | 1244 | } |
1248 | GNUNET_free (baseconfig); | 1245 | GNUNET_free (baseconfig); |
1249 | if ( ((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, | 1246 | if (((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, |
1250 | "PATHS", | 1247 | "PATHS", |
1251 | "DEFAULTCONFIG"))) && | 1248 | "DEFAULTCONFIG"))) && |
1252 | (filename != NULL) ) | 1249 | (filename != NULL)) |
1253 | GNUNET_CONFIGURATION_set_value_string (cfg, | 1250 | GNUNET_CONFIGURATION_set_value_string (cfg, |
1254 | "PATHS", | 1251 | "PATHS", "DEFAULTCONFIG", filename); |
1255 | "DEFAULTCONFIG", | ||
1256 | filename); | ||
1257 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, | 1252 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, |
1258 | "TESTING", | 1253 | "TESTING", |
1259 | "WEAKRANDOM")) && | 1254 | "WEAKRANDOM")) && |
diff --git a/src/util/connection.c b/src/util/connection.c index f26130a06..1ac1b2304 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -296,7 +296,8 @@ struct GNUNET_CONNECTION_Handle | |||
296 | * | 296 | * |
297 | * @param sock the connection to set persistent | 297 | * @param sock the connection to set persistent |
298 | */ | 298 | */ |
299 | void GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *sock) | 299 | void |
300 | GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock) | ||
300 | { | 301 | { |
301 | sock->persist = GNUNET_YES; | 302 | sock->persist = GNUNET_YES; |
302 | } | 303 | } |
@@ -313,7 +314,8 @@ void GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *sock) | |||
313 | * @param sock the connection to make flushing and blocking | 314 | * @param sock the connection to make flushing and blocking |
314 | * @return GNUNET_OK on success | 315 | * @return GNUNET_OK on success |
315 | */ | 316 | */ |
316 | int GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock) | 317 | int |
318 | GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock) | ||
317 | { | 319 | { |
318 | return GNUNET_NETWORK_socket_disable_corking (sock->sock); | 320 | return GNUNET_NETWORK_socket_disable_corking (sock->sock); |
319 | } | 321 | } |
@@ -327,13 +329,13 @@ int GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock) | |||
327 | * @return the boxed socket handle | 329 | * @return the boxed socket handle |
328 | */ | 330 | */ |
329 | struct GNUNET_CONNECTION_Handle * | 331 | struct GNUNET_CONNECTION_Handle * |
330 | GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle | 332 | GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket) |
331 | *osSocket) | ||
332 | { | 333 | { |
333 | struct GNUNET_CONNECTION_Handle *ret; | 334 | struct GNUNET_CONNECTION_Handle *ret; |
335 | |||
334 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); | 336 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); |
335 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; | 337 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; |
336 | ret->write_buffer = GNUNET_malloc(ret->write_buffer_size); | 338 | ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); |
337 | ret->sock = osSocket; | 339 | ret->sock = osSocket; |
338 | return ret; | 340 | return ret; |
339 | } | 341 | } |
@@ -362,8 +364,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, | |||
362 | struct sockaddr_in6 *v6; | 364 | struct sockaddr_in6 *v6; |
363 | struct sockaddr *sa; | 365 | struct sockaddr *sa; |
364 | void *uaddr; | 366 | void *uaddr; |
365 | struct GNUNET_CONNECTION_Credentials *gcp; | 367 | struct GNUNET_CONNECTION_Credentials *gcp; |
366 | struct GNUNET_CONNECTION_Credentials gc; | 368 | struct GNUNET_CONNECTION_Credentials gc; |
369 | |||
367 | #ifdef SO_PEERCRED | 370 | #ifdef SO_PEERCRED |
368 | struct ucred uc; | 371 | struct ucred uc; |
369 | socklen_t olen; | 372 | socklen_t olen; |
@@ -371,102 +374,98 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, | |||
371 | 374 | ||
372 | addrlen = sizeof (addr); | 375 | addrlen = sizeof (addr); |
373 | sock = | 376 | sock = |
374 | GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); | 377 | GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); |
375 | if (NULL == sock) | 378 | if (NULL == sock) |
376 | { | 379 | { |
377 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); | 380 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); |
378 | return NULL; | 381 | return NULL; |
379 | } | 382 | } |
380 | if ( (addrlen > sizeof (addr)) || | 383 | if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t))) |
381 | (addrlen < sizeof (sa_family_t)) ) | 384 | { |
382 | { | 385 | GNUNET_break (0); |
383 | GNUNET_break (0); | 386 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
384 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 387 | return NULL; |
385 | return NULL; | 388 | } |
386 | } | ||
387 | 389 | ||
388 | sa = (struct sockaddr *) addr; | 390 | sa = (struct sockaddr *) addr; |
389 | v6 = (struct sockaddr_in6 *) addr; | 391 | v6 = (struct sockaddr_in6 *) addr; |
390 | if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) | 392 | if ((sa->sa_family == AF_INET6) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) |
391 | { | 393 | { |
392 | /* convert to V4 address */ | 394 | /* convert to V4 address */ |
393 | v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); | 395 | v4 = GNUNET_malloc (sizeof (struct sockaddr_in)); |
394 | memset (v4, 0, sizeof (struct sockaddr_in)); | 396 | memset (v4, 0, sizeof (struct sockaddr_in)); |
395 | v4->sin_family = AF_INET; | 397 | v4->sin_family = AF_INET; |
396 | #if HAVE_SOCKADDR_IN_SIN_LEN | 398 | #if HAVE_SOCKADDR_IN_SIN_LEN |
397 | v4->sin_len = (u_char) sizeof (struct sockaddr_in); | 399 | v4->sin_len = (u_char) sizeof (struct sockaddr_in); |
398 | #endif | 400 | #endif |
399 | memcpy (&v4->sin_addr, | 401 | memcpy (&v4->sin_addr, |
400 | &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - | 402 | &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - |
401 | sizeof (struct in_addr)], | 403 | sizeof (struct in_addr)], |
402 | sizeof (struct in_addr)); | 404 | sizeof (struct in_addr)); |
403 | v4->sin_port = v6->sin6_port; | 405 | v4->sin_port = v6->sin6_port; |
404 | uaddr = v4; | 406 | uaddr = v4; |
405 | addrlen = sizeof (struct sockaddr_in); | 407 | addrlen = sizeof (struct sockaddr_in); |
406 | } | 408 | } |
407 | else | 409 | else |
408 | { | 410 | { |
409 | uaddr = GNUNET_malloc (addrlen); | 411 | uaddr = GNUNET_malloc (addrlen); |
410 | memcpy (uaddr, addr, addrlen); | 412 | memcpy (uaddr, addr, addrlen); |
411 | } | 413 | } |
412 | gcp = NULL; | 414 | gcp = NULL; |
413 | gc.uid = 0; | 415 | gc.uid = 0; |
414 | gc.gid = 0; | 416 | gc.gid = 0; |
415 | if (sa->sa_family == AF_UNIX) | 417 | if (sa->sa_family == AF_UNIX) |
416 | { | 418 | { |
417 | #if HAVE_GETPEEREID | 419 | #if HAVE_GETPEEREID |
418 | /* most BSDs */ | 420 | /* most BSDs */ |
419 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), | 421 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) |
420 | &gc.uid, | 422 | gcp = &gc; |
421 | &gc.gid)) | ||
422 | gcp = &gc; | ||
423 | #else | 423 | #else |
424 | #ifdef SO_PEERCRED | 424 | #ifdef SO_PEERCRED |
425 | /* largely traditional GNU/Linux */ | 425 | /* largely traditional GNU/Linux */ |
426 | olen = sizeof (uc); | 426 | olen = sizeof (uc); |
427 | if ( (0 == | 427 | if ((0 == |
428 | getsockopt (GNUNET_NETWORK_get_fd (sock), | 428 | getsockopt (GNUNET_NETWORK_get_fd (sock), |
429 | SOL_SOCKET, SO_PEERCRED, &uc, &olen)) && | 429 | SOL_SOCKET, SO_PEERCRED, &uc, &olen)) && |
430 | (olen == sizeof (uc)) ) | 430 | (olen == sizeof (uc))) |
431 | { | 431 | { |
432 | gc.uid = uc.uid; | 432 | gc.uid = uc.uid; |
433 | gc.gid = uc.gid; | 433 | gc.gid = uc.gid; |
434 | gcp = &gc; | 434 | gcp = &gc; |
435 | } | 435 | } |
436 | #else | 436 | #else |
437 | #if HAVE_GETPEERUCRED | 437 | #if HAVE_GETPEERUCRED |
438 | /* this is for Solaris 10 */ | 438 | /* this is for Solaris 10 */ |
439 | ucred_t *uc; | 439 | ucred_t *uc; |
440 | 440 | ||
441 | uc = NULL; | 441 | uc = NULL; |
442 | if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) | 442 | if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) |
443 | { | 443 | { |
444 | gc.uid = ucred_geteuid (uc); | 444 | gc.uid = ucred_geteuid (uc); |
445 | gc.gid = ucred_getegid (uc); | 445 | gc.gid = ucred_getegid (uc); |
446 | gcp = &gc; | 446 | gcp = &gc; |
447 | } | 447 | } |
448 | ucred_free (uc); | 448 | ucred_free (uc); |
449 | #endif | 449 | #endif |
450 | #endif | 450 | #endif |
451 | #endif | 451 | #endif |
452 | } | 452 | } |
453 | 453 | ||
454 | if ((access != NULL) && | 454 | if ((access != NULL) && |
455 | (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen)))) | 455 | (GNUNET_YES != (aret = access (access_cls, gcp, uaddr, addrlen)))) |
456 | { | 456 | { |
457 | if (aret == GNUNET_NO) | 457 | if (aret == GNUNET_NO) |
458 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 458 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
459 | _("Access denied to `%s'\n"), | 459 | _("Access denied to `%s'\n"), GNUNET_a2s (uaddr, addrlen)); |
460 | GNUNET_a2s (uaddr, addrlen)); | 460 | GNUNET_break (GNUNET_OK == |
461 | GNUNET_break (GNUNET_OK == | 461 | GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); |
462 | GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); | 462 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
463 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 463 | GNUNET_free (uaddr); |
464 | GNUNET_free (uaddr); | 464 | return NULL; |
465 | return NULL; | 465 | } |
466 | } | ||
467 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); | 466 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); |
468 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; | 467 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; |
469 | ret->write_buffer = GNUNET_malloc(ret->write_buffer_size); | 468 | ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); |
470 | ret->addr = uaddr; | 469 | ret->addr = uaddr; |
471 | ret->addrlen = addrlen; | 470 | ret->addrlen = addrlen; |
472 | ret->sock = sock; | 471 | ret->sock = sock; |
@@ -521,8 +520,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
521 | * @param tc unused | 520 | * @param tc unused |
522 | */ | 521 | */ |
523 | static void | 522 | static void |
524 | destroy_continuation (void *cls, | 523 | destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
525 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
526 | { | 524 | { |
527 | struct GNUNET_CONNECTION_Handle *sock = cls; | 525 | struct GNUNET_CONNECTION_Handle *sock = cls; |
528 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 526 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
@@ -531,80 +529,77 @@ destroy_continuation (void *cls, | |||
531 | sock->destroy_task = GNUNET_SCHEDULER_NO_TASK; | 529 | sock->destroy_task = GNUNET_SCHEDULER_NO_TASK; |
532 | GNUNET_assert (sock->dns_active == NULL); | 530 | GNUNET_assert (sock->dns_active == NULL); |
533 | if (0 != (sock->ccs & COCO_TRANSMIT_READY)) | 531 | if (0 != (sock->ccs & COCO_TRANSMIT_READY)) |
534 | { | 532 | { |
535 | #if DEBUG_CONNECTION | 533 | #if DEBUG_CONNECTION |
536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
537 | "Destroy waits for CCS-TR to be done (%p)\n", sock); | 535 | "Destroy waits for CCS-TR to be done (%p)\n", sock); |
538 | #endif | 536 | #endif |
539 | sock->ccs |= COCO_DESTROY_CONTINUATION; | 537 | sock->ccs |= COCO_DESTROY_CONTINUATION; |
540 | return; | 538 | return; |
541 | } | 539 | } |
542 | if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) | 540 | if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) |
543 | { | 541 | { |
544 | #if DEBUG_CONNECTION | 542 | #if DEBUG_CONNECTION |
545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
546 | "Destroy waits for write_task to be done (%p)\n", sock); | 544 | "Destroy waits for write_task to be done (%p)\n", sock); |
547 | #endif | 545 | #endif |
548 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); | 546 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); |
549 | sock->destroy_task | 547 | sock->destroy_task |
550 | = GNUNET_SCHEDULER_add_after (sock->write_task, | 548 | = GNUNET_SCHEDULER_add_after (sock->write_task, |
551 | &destroy_continuation, sock); | 549 | &destroy_continuation, sock); |
552 | return; | 550 | return; |
553 | } | 551 | } |
554 | if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) | 552 | if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) |
555 | { | 553 | { |
556 | sock->ccs |= COCO_DESTROY_CONTINUATION; | 554 | sock->ccs |= COCO_DESTROY_CONTINUATION; |
557 | return; | 555 | return; |
558 | } | 556 | } |
559 | if (sock->sock != NULL) | 557 | if (sock->sock != NULL) |
560 | { | 558 | { |
561 | #if DEBUG_CONNECTION | 559 | #if DEBUG_CONNECTION |
562 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); |
563 | "Shutting down socket (%p)\n", sock); | ||
564 | #endif | 561 | #endif |
565 | if (sock->persist != GNUNET_YES) | 562 | if (sock->persist != GNUNET_YES) |
566 | { | ||
567 | if ( (GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) && | ||
568 | (errno != ENOTCONN) && | ||
569 | (errno != ECONNRESET) ) | ||
570 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "shutdown"); | ||
571 | } | ||
572 | } | ||
573 | if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) | ||
574 | { | 563 | { |
575 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); | 564 | if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) |
576 | sock->destroy_task | 565 | && (errno != ENOTCONN) && (errno != ECONNRESET)) |
577 | = GNUNET_SCHEDULER_add_after (sock->read_task, | 566 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "shutdown"); |
578 | &destroy_continuation, sock); | ||
579 | return; | ||
580 | } | 567 | } |
568 | } | ||
569 | if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) | ||
570 | { | ||
571 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); | ||
572 | sock->destroy_task | ||
573 | = GNUNET_SCHEDULER_add_after (sock->read_task, | ||
574 | &destroy_continuation, sock); | ||
575 | return; | ||
576 | } | ||
581 | #if DEBUG_CONNECTION | 577 | #if DEBUG_CONNECTION |
582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 578 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); |
583 | "Destroy actually runs (%p)!\n", sock); | ||
584 | #endif | 579 | #endif |
585 | while (NULL != (pos = sock->ap_head)) | 580 | while (NULL != (pos = sock->ap_head)) |
586 | { | 581 | { |
587 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 582 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
588 | GNUNET_SCHEDULER_cancel (pos->task); | 583 | GNUNET_SCHEDULER_cancel (pos->task); |
589 | GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); | 584 | GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); |
590 | GNUNET_free (pos); | 585 | GNUNET_free (pos); |
591 | } | 586 | } |
592 | GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); | 587 | GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); |
593 | GNUNET_assert (sock->ccs == COCO_NONE); | 588 | GNUNET_assert (sock->ccs == COCO_NONE); |
594 | if (NULL != (notify = sock->nth.notify_ready)) | 589 | if (NULL != (notify = sock->nth.notify_ready)) |
595 | { | 590 | { |
596 | sock->nth.notify_ready = NULL; | 591 | sock->nth.notify_ready = NULL; |
597 | notify (sock->nth.notify_ready_cls, 0, NULL); | 592 | notify (sock->nth.notify_ready_cls, 0, NULL); |
598 | } | 593 | } |
599 | 594 | ||
600 | if (sock->sock != NULL) | 595 | if (sock->sock != NULL) |
601 | { | 596 | { |
602 | if (sock->persist != GNUNET_YES) | 597 | if (sock->persist != GNUNET_YES) |
603 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); | 598 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); |
604 | else | 599 | else |
605 | GNUNET_free (sock->sock); /* at least no memory leak (we deliberately | 600 | GNUNET_free (sock->sock); /* at least no memory leak (we deliberately |
606 | leak the socket in this special case) ... */ | 601 | * leak the socket in this special case) ... */ |
607 | } | 602 | } |
608 | GNUNET_free_non_null (sock->addr); | 603 | GNUNET_free_non_null (sock->addr); |
609 | GNUNET_free_non_null (sock->hostname); | 604 | GNUNET_free_non_null (sock->hostname); |
610 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); | 605 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); |
@@ -639,12 +634,13 @@ static void | |||
639 | connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) | 634 | connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) |
640 | { | 635 | { |
641 | #if DEBUG_CONNECTION | 636 | #if DEBUG_CONNECTION |
642 | GNUNET_log ((0 != strncmp (h->hostname, | 637 | GNUNET_log ((0 != strncmp (h->hostname, |
643 | "localhost:", | 638 | "localhost:", |
644 | 10)) | 639 | 10)) |
645 | ? GNUNET_ERROR_TYPE_INFO | 640 | ? GNUNET_ERROR_TYPE_INFO |
646 | : GNUNET_ERROR_TYPE_WARNING, | 641 | : GNUNET_ERROR_TYPE_WARNING, |
647 | _("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), | 642 | _ |
643 | ("Failed to establish TCP connection to `%s:%u', no further addresses to try.\n"), | ||
648 | h->hostname, h->port); | 644 | h->hostname, h->port); |
649 | #endif | 645 | #endif |
650 | /* connect failed / timed out */ | 646 | /* connect failed / timed out */ |
@@ -655,43 +651,40 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) | |||
655 | 651 | ||
656 | /* trigger jobs that used to wait on "connect_task" */ | 652 | /* trigger jobs that used to wait on "connect_task" */ |
657 | if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) | 653 | if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) |
658 | { | 654 | { |
659 | #if DEBUG_CONNECTION | 655 | #if DEBUG_CONNECTION |
660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
661 | "connect_fail_continuation triggers receive_again (%p)\n", | 657 | "connect_fail_continuation triggers receive_again (%p)\n", h); |
662 | h); | ||
663 | #endif | 658 | #endif |
664 | h->ccs -= COCO_RECEIVE_AGAIN; | 659 | h->ccs -= COCO_RECEIVE_AGAIN; |
665 | h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); | 660 | h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); |
666 | } | 661 | } |
667 | if (0 != (h->ccs & COCO_TRANSMIT_READY)) | 662 | if (0 != (h->ccs & COCO_TRANSMIT_READY)) |
668 | { | 663 | { |
669 | #if DEBUG_CONNECTION | 664 | #if DEBUG_CONNECTION |
670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 665 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
671 | "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", | 666 | "connect_fail_continuation cancels timeout_task, triggers transmit_ready (%p)\n", |
672 | h); | 667 | h); |
673 | #endif | 668 | #endif |
674 | GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); | 669 | GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); |
675 | GNUNET_SCHEDULER_cancel (h->nth.timeout_task); | 670 | GNUNET_SCHEDULER_cancel (h->nth.timeout_task); |
676 | h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; | 671 | h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; |
677 | h->ccs -= COCO_TRANSMIT_READY; | 672 | h->ccs -= COCO_TRANSMIT_READY; |
678 | GNUNET_assert (h->nth.notify_ready != NULL); | 673 | GNUNET_assert (h->nth.notify_ready != NULL); |
679 | GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); | 674 | GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); |
680 | h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); | 675 | h->write_task = GNUNET_SCHEDULER_add_now (&transmit_ready, h); |
681 | } | 676 | } |
682 | if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) | 677 | if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) |
683 | { | 678 | { |
684 | #if DEBUG_CONNECTION | 679 | #if DEBUG_CONNECTION |
685 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 680 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
686 | "connect_fail_continuation runs destroy_continuation (%p)\n", | 681 | "connect_fail_continuation runs destroy_continuation (%p)\n", |
687 | h); | 682 | h); |
688 | #endif | 683 | #endif |
689 | h->ccs -= COCO_DESTROY_CONTINUATION; | 684 | h->ccs -= COCO_DESTROY_CONTINUATION; |
690 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); | 685 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); |
691 | h->destroy_task | 686 | h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); |
692 | = GNUNET_SCHEDULER_add_now (&destroy_continuation, | 687 | } |
693 | h); | ||
694 | } | ||
695 | } | 688 | } |
696 | 689 | ||
697 | 690 | ||
@@ -710,46 +703,43 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) | |||
710 | #endif | 703 | #endif |
711 | /* trigger jobs that waited for the connection */ | 704 | /* trigger jobs that waited for the connection */ |
712 | if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) | 705 | if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) |
713 | { | 706 | { |
714 | #if DEBUG_CONNECTION | 707 | #if DEBUG_CONNECTION |
715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
716 | "connect_success_continuation runs receive_again (%p)\n", | 709 | "connect_success_continuation runs receive_again (%p)\n", h); |
717 | h); | ||
718 | #endif | 710 | #endif |
719 | h->ccs -= COCO_RECEIVE_AGAIN; | 711 | h->ccs -= COCO_RECEIVE_AGAIN; |
720 | h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); | 712 | h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); |
721 | } | 713 | } |
722 | if (0 != (h->ccs & COCO_TRANSMIT_READY)) | 714 | if (0 != (h->ccs & COCO_TRANSMIT_READY)) |
723 | { | 715 | { |
724 | #if DEBUG_CONNECTION | 716 | #if DEBUG_CONNECTION |
725 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
726 | "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", | 718 | "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", |
727 | h); | 719 | h); |
728 | #endif | 720 | #endif |
729 | GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); | 721 | GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); |
730 | GNUNET_SCHEDULER_cancel (h->nth.timeout_task); | 722 | GNUNET_SCHEDULER_cancel (h->nth.timeout_task); |
731 | h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; | 723 | h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; |
732 | h->ccs -= COCO_TRANSMIT_READY; | 724 | h->ccs -= COCO_TRANSMIT_READY; |
733 | GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); | 725 | GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); |
734 | GNUNET_assert (h->nth.notify_ready != NULL); | 726 | GNUNET_assert (h->nth.notify_ready != NULL); |
735 | h->write_task = | 727 | h->write_task = |
736 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 728 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining |
737 | (h->nth.transmit_timeout), h->sock, | 729 | (h->nth.transmit_timeout), h->sock, |
738 | &transmit_ready, h); | 730 | &transmit_ready, h); |
739 | } | 731 | } |
740 | if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) | 732 | if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) |
741 | { | 733 | { |
742 | #if DEBUG_CONNECTION | 734 | #if DEBUG_CONNECTION |
743 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
744 | "connect_success_continuation runs destroy_continuation (%p)\n", | 736 | "connect_success_continuation runs destroy_continuation (%p)\n", |
745 | h); | 737 | h); |
746 | #endif | 738 | #endif |
747 | h->ccs -= COCO_DESTROY_CONTINUATION; | 739 | h->ccs -= COCO_DESTROY_CONTINUATION; |
748 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); | 740 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); |
749 | h->destroy_task | 741 | h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); |
750 | = GNUNET_SCHEDULER_add_now (&destroy_continuation, | 742 | } |
751 | h); | ||
752 | } | ||
753 | } | 743 | } |
754 | 744 | ||
755 | 745 | ||
@@ -775,18 +765,17 @@ connect_probe_continuation (void *cls, | |||
775 | len = sizeof (error); | 765 | len = sizeof (error); |
776 | errno = 0; | 766 | errno = 0; |
777 | error = 0; | 767 | error = 0; |
778 | if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || | 768 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || |
779 | (GNUNET_OK != | 769 | (GNUNET_OK != |
780 | GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, | 770 | GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, |
781 | &error, &len)) || | 771 | &error, &len)) || (error != 0)) |
782 | (error != 0) ) | 772 | { |
783 | { | 773 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); |
784 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); | 774 | GNUNET_free (ap); |
785 | GNUNET_free (ap); | 775 | if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) |
786 | if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) | 776 | connect_fail_continuation (h); |
787 | connect_fail_continuation (h); | 777 | return; |
788 | return; | 778 | } |
789 | } | ||
790 | GNUNET_assert (h->sock == NULL); | 779 | GNUNET_assert (h->sock == NULL); |
791 | h->sock = ap->sock; | 780 | h->sock = ap->sock; |
792 | GNUNET_assert (h->addr == NULL); | 781 | GNUNET_assert (h->addr == NULL); |
@@ -796,12 +785,12 @@ connect_probe_continuation (void *cls, | |||
796 | GNUNET_free (ap); | 785 | GNUNET_free (ap); |
797 | /* cancel all other attempts */ | 786 | /* cancel all other attempts */ |
798 | while (NULL != (pos = h->ap_head)) | 787 | while (NULL != (pos = h->ap_head)) |
799 | { | 788 | { |
800 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 789 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
801 | GNUNET_SCHEDULER_cancel (pos->task); | 790 | GNUNET_SCHEDULER_cancel (pos->task); |
802 | GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); | 791 | GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); |
803 | GNUNET_free (pos); | 792 | GNUNET_free (pos); |
804 | } | 793 | } |
805 | connect_success_continuation (h); | 794 | connect_success_continuation (h); |
806 | } | 795 | } |
807 | 796 | ||
@@ -823,12 +812,12 @@ try_connect_using_address (void *cls, | |||
823 | struct GNUNET_TIME_Relative delay; | 812 | struct GNUNET_TIME_Relative delay; |
824 | 813 | ||
825 | if (addr == NULL) | 814 | if (addr == NULL) |
826 | { | 815 | { |
827 | h->dns_active = NULL; | 816 | h->dns_active = NULL; |
828 | if (NULL == h->ap_head) | 817 | if (NULL == h->ap_head) |
829 | connect_fail_continuation (h); | 818 | connect_fail_continuation (h); |
830 | return; | 819 | return; |
831 | } | 820 | } |
832 | if (h->sock != NULL) | 821 | if (h->sock != NULL) |
833 | return; /* already connected */ | 822 | return; /* already connected */ |
834 | GNUNET_assert (h->addr == NULL); | 823 | GNUNET_assert (h->addr == NULL); |
@@ -845,25 +834,24 @@ try_connect_using_address (void *cls, | |||
845 | ap->h = h; | 834 | ap->h = h; |
846 | 835 | ||
847 | switch (ap->addr->sa_family) | 836 | switch (ap->addr->sa_family) |
848 | { | 837 | { |
849 | case AF_INET: | 838 | case AF_INET: |
850 | ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); | 839 | ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); |
851 | break; | 840 | break; |
852 | case AF_INET6: | 841 | case AF_INET6: |
853 | ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); | 842 | ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); |
854 | break; | 843 | break; |
855 | default: | 844 | default: |
856 | GNUNET_break (0); | 845 | GNUNET_break (0); |
857 | GNUNET_free (ap); | 846 | GNUNET_free (ap); |
858 | return; /* not supported by us */ | 847 | return; /* not supported by us */ |
859 | } | 848 | } |
860 | ap->sock = | 849 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); |
861 | GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); | ||
862 | if (ap->sock == NULL) | 850 | if (ap->sock == NULL) |
863 | { | 851 | { |
864 | GNUNET_free (ap); | 852 | GNUNET_free (ap); |
865 | return; /* not supported by OS */ | 853 | return; /* not supported by OS */ |
866 | } | 854 | } |
867 | #if DEBUG_CONNECTION | 855 | #if DEBUG_CONNECTION |
868 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 856 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
869 | _("Trying to connect to `%s' (%p)\n"), | 857 | _("Trying to connect to `%s' (%p)\n"), |
@@ -873,13 +861,13 @@ try_connect_using_address (void *cls, | |||
873 | ap->addr, | 861 | ap->addr, |
874 | ap->addrlen)) && | 862 | ap->addrlen)) && |
875 | (errno != EINPROGRESS)) | 863 | (errno != EINPROGRESS)) |
876 | { | 864 | { |
877 | /* maybe refused / unsupported address, try next */ | 865 | /* maybe refused / unsupported address, try next */ |
878 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); | 866 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); |
879 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); | 867 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); |
880 | GNUNET_free (ap); | 868 | GNUNET_free (ap); |
881 | return; | 869 | return; |
882 | } | 870 | } |
883 | GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); | 871 | GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); |
884 | delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; | 872 | delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; |
885 | if (h->nth.notify_ready != NULL) | 873 | if (h->nth.notify_ready != NULL) |
@@ -891,8 +879,8 @@ try_connect_using_address (void *cls, | |||
891 | GNUNET_TIME_absolute_get_remaining | 879 | GNUNET_TIME_absolute_get_remaining |
892 | (h->receive_timeout)); | 880 | (h->receive_timeout)); |
893 | ap->task = | 881 | ap->task = |
894 | GNUNET_SCHEDULER_add_write_net (delay, ap->sock, | 882 | GNUNET_SCHEDULER_add_write_net (delay, ap->sock, |
895 | &connect_probe_continuation, ap); | 883 | &connect_probe_continuation, ap); |
896 | } | 884 | } |
897 | 885 | ||
898 | 886 | ||
@@ -917,7 +905,7 @@ GNUNET_CONNECTION_create_from_connect (const struct | |||
917 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); | 905 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); |
918 | ret->cfg = cfg; | 906 | ret->cfg = cfg; |
919 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; | 907 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; |
920 | ret->write_buffer = GNUNET_malloc(ret->write_buffer_size); | 908 | ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); |
921 | ret->port = port; | 909 | ret->port = port; |
922 | ret->hostname = GNUNET_strdup (hostname); | 910 | ret->hostname = GNUNET_strdup (hostname); |
923 | ret->dns_active = GNUNET_RESOLVER_ip_get (ret->hostname, | 911 | ret->dns_active = GNUNET_RESOLVER_ip_get (ret->hostname, |
@@ -939,8 +927,8 @@ GNUNET_CONNECTION_create_from_connect (const struct | |||
939 | */ | 927 | */ |
940 | struct GNUNET_CONNECTION_Handle * | 928 | struct GNUNET_CONNECTION_Handle * |
941 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | 929 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct |
942 | GNUNET_CONFIGURATION_Handle *cfg, | 930 | GNUNET_CONFIGURATION_Handle |
943 | const char *unixpath) | 931 | *cfg, const char *unixpath) |
944 | { | 932 | { |
945 | #ifdef AF_UNIX | 933 | #ifdef AF_UNIX |
946 | struct GNUNET_CONNECTION_Handle *ret; | 934 | struct GNUNET_CONNECTION_Handle *ret; |
@@ -953,9 +941,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
953 | slen = strlen (unixpath); | 941 | slen = strlen (unixpath); |
954 | if (slen >= sizeof (un->sun_path)) | 942 | if (slen >= sizeof (un->sun_path)) |
955 | slen = sizeof (un->sun_path) - 1; | 943 | slen = sizeof (un->sun_path) - 1; |
956 | memcpy (un->sun_path, | 944 | memcpy (un->sun_path, unixpath, slen); |
957 | unixpath, | ||
958 | slen); | ||
959 | un->sun_path[slen] = '\0'; | 945 | un->sun_path[slen] = '\0'; |
960 | slen = sizeof (struct sockaddr_un); | 946 | slen = sizeof (struct sockaddr_un); |
961 | #if HAVE_SOCKADDR_IN_SIN_LEN | 947 | #if HAVE_SOCKADDR_IN_SIN_LEN |
@@ -967,28 +953,27 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
967 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); | 953 | ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); |
968 | ret->cfg = cfg; | 954 | ret->cfg = cfg; |
969 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; | 955 | ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; |
970 | ret->write_buffer = GNUNET_malloc(ret->write_buffer_size); | 956 | ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); |
971 | ret->port = 0; | 957 | ret->port = 0; |
972 | ret->hostname = NULL; | 958 | ret->hostname = NULL; |
973 | ret->addr = (struct sockaddr*) un; | 959 | ret->addr = (struct sockaddr *) un; |
974 | ret->addrlen = slen; | 960 | ret->addrlen = slen; |
975 | ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 961 | ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
976 | if (NULL == ret->sock) | 962 | if (NULL == ret->sock) |
977 | { | 963 | { |
978 | GNUNET_free (ret->addr); | 964 | GNUNET_free (ret->addr); |
979 | GNUNET_free (ret->write_buffer); | 965 | GNUNET_free (ret->write_buffer); |
980 | GNUNET_free (ret); | 966 | GNUNET_free (ret); |
981 | return NULL; | 967 | return NULL; |
982 | } | 968 | } |
983 | if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock, | 969 | if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock, |
984 | ret->addr, | 970 | ret->addr, ret->addrlen)) |
985 | ret->addrlen)) | 971 | { |
986 | { | 972 | /* Just return; we expect everything to work eventually so don't fail HARD */ |
987 | /* Just return; we expect everything to work eventually so don't fail HARD */ | 973 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); |
988 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); | 974 | ret->sock = NULL; |
989 | ret->sock = NULL; | 975 | return ret; |
990 | return ret; | 976 | } |
991 | } | ||
992 | connect_success_continuation (ret); | 977 | connect_success_continuation (ret); |
993 | return ret; | 978 | return ret; |
994 | #else | 979 | #else |
@@ -1018,22 +1003,22 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
1018 | 1003 | ||
1019 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); | 1004 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); |
1020 | if (s == NULL) | 1005 | if (s == NULL) |
1021 | { | 1006 | { |
1022 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | | 1007 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | |
1023 | GNUNET_ERROR_TYPE_BULK, "socket"); | 1008 | GNUNET_ERROR_TYPE_BULK, "socket"); |
1024 | return NULL; | 1009 | return NULL; |
1025 | } | 1010 | } |
1026 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) | 1011 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) |
1027 | && (errno != EINPROGRESS)) | 1012 | && (errno != EINPROGRESS)) |
1028 | { | 1013 | { |
1029 | /* maybe refused / unsupported address, try next */ | 1014 | /* maybe refused / unsupported address, try next */ |
1030 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); | 1015 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); |
1031 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1016 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1032 | _("Attempt to connect to `%s' failed\n"), | 1017 | _("Attempt to connect to `%s' failed\n"), |
1033 | GNUNET_a2s (serv_addr, addrlen)); | 1018 | GNUNET_a2s (serv_addr, addrlen)); |
1034 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); | 1019 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
1035 | return NULL; | 1020 | return NULL; |
1036 | } | 1021 | } |
1037 | ret = GNUNET_CONNECTION_create_from_existing (s); | 1022 | ret = GNUNET_CONNECTION_create_from_existing (s); |
1038 | ret->addr = GNUNET_malloc (addrlen); | 1023 | ret->addr = GNUNET_malloc (addrlen); |
1039 | memcpy (ret->addr, serv_addr, addrlen); | 1024 | memcpy (ret->addr, serv_addr, addrlen); |
@@ -1079,27 +1064,26 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) | |||
1079 | */ | 1064 | */ |
1080 | void | 1065 | void |
1081 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, | 1066 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, |
1082 | int finish_pending_write) | 1067 | int finish_pending_write) |
1083 | { | 1068 | { |
1084 | if (GNUNET_NO == finish_pending_write) | 1069 | if (GNUNET_NO == finish_pending_write) |
1070 | { | ||
1071 | if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) | ||
1085 | { | 1072 | { |
1086 | if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) | 1073 | GNUNET_SCHEDULER_cancel (sock->write_task); |
1087 | { | 1074 | sock->write_task = GNUNET_SCHEDULER_NO_TASK; |
1088 | GNUNET_SCHEDULER_cancel (sock->write_task); | 1075 | sock->write_buffer_off = 0; |
1089 | sock->write_task = GNUNET_SCHEDULER_NO_TASK; | ||
1090 | sock->write_buffer_off = 0; | ||
1091 | } | ||
1092 | sock->nth.notify_ready = NULL; | ||
1093 | } | 1076 | } |
1077 | sock->nth.notify_ready = NULL; | ||
1078 | } | ||
1094 | if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) | 1079 | if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) |
1095 | { | 1080 | { |
1096 | GNUNET_RESOLVER_request_cancel (sock->dns_active); | 1081 | GNUNET_RESOLVER_request_cancel (sock->dns_active); |
1097 | sock->dns_active = NULL; | 1082 | sock->dns_active = NULL; |
1098 | } | 1083 | } |
1099 | 1084 | ||
1100 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); | 1085 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); |
1101 | sock->destroy_task | 1086 | sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock); |
1102 | = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock); | ||
1103 | } | 1087 | } |
1104 | 1088 | ||
1105 | 1089 | ||
@@ -1128,6 +1112,7 @@ static void | |||
1128 | signal_error (struct GNUNET_CONNECTION_Handle *sh, int errcode) | 1112 | signal_error (struct GNUNET_CONNECTION_Handle *sh, int errcode) |
1129 | { | 1113 | { |
1130 | GNUNET_CONNECTION_Receiver receiver; | 1114 | GNUNET_CONNECTION_Receiver receiver; |
1115 | |||
1131 | GNUNET_assert (NULL != (receiver = sh->receiver)); | 1116 | GNUNET_assert (NULL != (receiver = sh->receiver)); |
1132 | sh->receiver = NULL; | 1117 | sh->receiver = NULL; |
1133 | receiver (sh->receiver_cls, NULL, 0, sh->addr, sh->addrlen, errcode); | 1118 | receiver (sh->receiver_cls, NULL, 0, sh->addr, sh->addrlen, errcode); |
@@ -1148,60 +1133,60 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1148 | GNUNET_CONNECTION_Receiver receiver; | 1133 | GNUNET_CONNECTION_Receiver receiver; |
1149 | 1134 | ||
1150 | sh->read_task = GNUNET_SCHEDULER_NO_TASK; | 1135 | sh->read_task = GNUNET_SCHEDULER_NO_TASK; |
1151 | if ( (GNUNET_YES == sh->ignore_shutdown) && | 1136 | if ((GNUNET_YES == sh->ignore_shutdown) && |
1152 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | 1137 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) |
1153 | { | 1138 | { |
1154 | /* ignore shutdown request, go again immediately */ | 1139 | /* ignore shutdown request, go again immediately */ |
1155 | #if DEBUG_CONNECTION | 1140 | #if DEBUG_CONNECTION |
1156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1157 | "Ignoring shutdown signal per configuration\n"); | 1142 | "Ignoring shutdown signal per configuration\n"); |
1158 | #endif | 1143 | #endif |
1159 | sh->read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 1144 | sh->read_task = |
1160 | (sh->receive_timeout), | 1145 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining |
1161 | sh->sock, | 1146 | (sh->receive_timeout), sh->sock, |
1162 | &receive_ready, sh); | 1147 | &receive_ready, sh); |
1163 | return; | 1148 | return; |
1164 | } | 1149 | } |
1165 | now = GNUNET_TIME_absolute_get (); | 1150 | now = GNUNET_TIME_absolute_get (); |
1166 | if ((now.abs_value > sh->receive_timeout.abs_value) || | 1151 | if ((now.abs_value > sh->receive_timeout.abs_value) || |
1167 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || | 1152 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || |
1168 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | 1153 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) |
1169 | { | 1154 | { |
1170 | #if DEBUG_CONNECTION | 1155 | #if DEBUG_CONNECTION |
1171 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1156 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1173 | "Receive from `%s' encounters error: time out by %llums... (%p)\n", | 1158 | "Receive from `%s' encounters error: time out by %llums... (%p)\n", |
1174 | GNUNET_a2s (sh->addr, sh->addrlen), | 1159 | GNUNET_a2s (sh->addr, sh->addrlen), |
1175 | GNUNET_TIME_absolute_get_duration (sh->receive_timeout). | 1160 | GNUNET_TIME_absolute_get_duration (sh->receive_timeout). |
1176 | rel_value, sh); | 1161 | rel_value, sh); |
1177 | #endif | 1162 | #endif |
1178 | signal_timeout (sh); | 1163 | signal_timeout (sh); |
1179 | return; | 1164 | return; |
1180 | } | 1165 | } |
1181 | if (sh->sock == NULL) | 1166 | if (sh->sock == NULL) |
1182 | { | 1167 | { |
1183 | /* connect failed for good */ | 1168 | /* connect failed for good */ |
1184 | #if DEBUG_CONNECTION | 1169 | #if DEBUG_CONNECTION |
1185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1186 | "Receive encounters error, socket closed... (%p)\n", sh); | 1171 | "Receive encounters error, socket closed... (%p)\n", sh); |
1187 | #endif | 1172 | #endif |
1188 | signal_error (sh, ECONNREFUSED); | 1173 | signal_error (sh, ECONNREFUSED); |
1189 | return; | 1174 | return; |
1190 | } | 1175 | } |
1191 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock)); | 1176 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock)); |
1192 | RETRY: | 1177 | RETRY: |
1193 | ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max); | 1178 | ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max); |
1194 | if (ret == -1) | 1179 | if (ret == -1) |
1195 | { | 1180 | { |
1196 | if (errno == EINTR) | 1181 | if (errno == EINTR) |
1197 | goto RETRY; | 1182 | goto RETRY; |
1198 | #if DEBUG_CONNECTION | 1183 | #if DEBUG_CONNECTION |
1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1200 | "Error receiving: %s\n", STRERROR (errno)); | 1185 | "Error receiving: %s\n", STRERROR (errno)); |
1201 | #endif | 1186 | #endif |
1202 | signal_error (sh, errno); | 1187 | signal_error (sh, errno); |
1203 | return; | 1188 | return; |
1204 | } | 1189 | } |
1205 | #if DEBUG_CONNECTION | 1190 | #if DEBUG_CONNECTION |
1206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1207 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", | 1192 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", |
@@ -1232,32 +1217,32 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1232 | 1217 | ||
1233 | sh->read_task = GNUNET_SCHEDULER_NO_TASK; | 1218 | sh->read_task = GNUNET_SCHEDULER_NO_TASK; |
1234 | if (sh->sock == NULL) | 1219 | if (sh->sock == NULL) |
1235 | { | 1220 | { |
1236 | /* not connected and no longer trying */ | 1221 | /* not connected and no longer trying */ |
1237 | #if DEBUG_CONNECTION | 1222 | #if DEBUG_CONNECTION |
1238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1239 | "Receive encounters error, socket closed (%p)...\n", sh); | 1224 | "Receive encounters error, socket closed (%p)...\n", sh); |
1240 | #endif | 1225 | #endif |
1241 | signal_error (sh, ECONNREFUSED); | 1226 | signal_error (sh, ECONNREFUSED); |
1242 | return; | 1227 | return; |
1243 | } | 1228 | } |
1244 | now = GNUNET_TIME_absolute_get (); | 1229 | now = GNUNET_TIME_absolute_get (); |
1245 | if ((now.abs_value > sh->receive_timeout.abs_value) || | 1230 | if ((now.abs_value > sh->receive_timeout.abs_value) || |
1246 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | 1231 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) |
1247 | { | 1232 | { |
1248 | #if DEBUG_CONNECTION | 1233 | #if DEBUG_CONNECTION |
1249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1250 | "Receive encounters error: time out (%p)...\n", sh); | 1235 | "Receive encounters error: time out (%p)...\n", sh); |
1251 | #endif | 1236 | #endif |
1252 | signal_timeout (sh); | 1237 | signal_timeout (sh); |
1253 | return; | 1238 | return; |
1254 | } | 1239 | } |
1255 | GNUNET_assert (sh->sock != NULL); | 1240 | GNUNET_assert (sh->sock != NULL); |
1256 | /* connect succeeded, wait for data! */ | 1241 | /* connect succeeded, wait for data! */ |
1257 | sh->read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 1242 | sh->read_task = |
1258 | (sh->receive_timeout), | 1243 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining |
1259 | sh->sock, | 1244 | (sh->receive_timeout), sh->sock, |
1260 | &receive_ready, sh); | 1245 | &receive_ready, sh); |
1261 | } | 1246 | } |
1262 | 1247 | ||
1263 | 1248 | ||
@@ -1291,17 +1276,17 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, | |||
1291 | sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1276 | sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1292 | sock->max = max; | 1277 | sock->max = max; |
1293 | if (sock->sock != NULL) | 1278 | if (sock->sock != NULL) |
1294 | { | 1279 | { |
1295 | memset (&tc, 0, sizeof (tc)); | 1280 | memset (&tc, 0, sizeof (tc)); |
1296 | tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; | 1281 | tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; |
1297 | receive_again (sock, &tc); | 1282 | receive_again (sock, &tc); |
1298 | return; | 1283 | return; |
1299 | } | 1284 | } |
1300 | if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) | 1285 | if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) |
1301 | { | 1286 | { |
1302 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); | 1287 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); |
1303 | return; | 1288 | return; |
1304 | } | 1289 | } |
1305 | sock->ccs += COCO_RECEIVE_AGAIN; | 1290 | sock->ccs += COCO_RECEIVE_AGAIN; |
1306 | } | 1291 | } |
1307 | 1292 | ||
@@ -1314,7 +1299,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, | |||
1314 | */ | 1299 | */ |
1315 | void | 1300 | void |
1316 | GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, | 1301 | GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, |
1317 | int do_ignore) | 1302 | int do_ignore) |
1318 | { | 1303 | { |
1319 | sock->ignore_shutdown = do_ignore; | 1304 | sock->ignore_shutdown = do_ignore; |
1320 | } | 1305 | } |
@@ -1332,15 +1317,15 @@ void * | |||
1332 | GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) | 1317 | GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) |
1333 | { | 1318 | { |
1334 | if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) | 1319 | if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) |
1335 | { | 1320 | { |
1336 | GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); | 1321 | GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); |
1337 | sock->read_task = GNUNET_SCHEDULER_NO_TASK; | 1322 | sock->read_task = GNUNET_SCHEDULER_NO_TASK; |
1338 | } | 1323 | } |
1339 | else | 1324 | else |
1340 | { | 1325 | { |
1341 | GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); | 1326 | GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); |
1342 | sock->ccs -= COCO_RECEIVE_AGAIN; | 1327 | sock->ccs -= COCO_RECEIVE_AGAIN; |
1343 | } | 1328 | } |
1344 | sock->receiver = NULL; | 1329 | sock->receiver = NULL; |
1345 | return sock->receiver_cls; | 1330 | return sock->receiver_cls; |
1346 | } | 1331 | } |
@@ -1371,18 +1356,17 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) | |||
1371 | return GNUNET_NO; | 1356 | return GNUNET_NO; |
1372 | sock->nth.notify_ready = NULL; | 1357 | sock->nth.notify_ready = NULL; |
1373 | if (sock->write_buffer_size - sock->write_buffer_off < size) | 1358 | if (sock->write_buffer_size - sock->write_buffer_off < size) |
1374 | { | 1359 | { |
1375 | /* need to compact */ | 1360 | /* need to compact */ |
1376 | memmove (sock->write_buffer, | 1361 | memmove (sock->write_buffer, |
1377 | &sock->write_buffer[sock->write_buffer_pos], used); | 1362 | &sock->write_buffer[sock->write_buffer_pos], used); |
1378 | sock->write_buffer_off -= sock->write_buffer_pos; | 1363 | sock->write_buffer_off -= sock->write_buffer_pos; |
1379 | sock->write_buffer_pos = 0; | 1364 | sock->write_buffer_pos = 0; |
1380 | } | 1365 | } |
1381 | avail = sock->write_buffer_size - sock->write_buffer_off; | 1366 | avail = sock->write_buffer_size - sock->write_buffer_off; |
1382 | GNUNET_assert (avail >= size); | 1367 | GNUNET_assert (avail >= size); |
1383 | size = notify (sock->nth.notify_ready_cls, | 1368 | size = notify (sock->nth.notify_ready_cls, |
1384 | avail, | 1369 | avail, &sock->write_buffer[sock->write_buffer_off]); |
1385 | &sock->write_buffer[sock->write_buffer_off]); | ||
1386 | GNUNET_assert (size <= avail); | 1370 | GNUNET_assert (size <= avail); |
1387 | sock->write_buffer_off += size; | 1371 | sock->write_buffer_off += size; |
1388 | return GNUNET_YES; | 1372 | return GNUNET_YES; |
@@ -1401,15 +1385,13 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) | |||
1401 | * @param tc scheduler context | 1385 | * @param tc scheduler context |
1402 | */ | 1386 | */ |
1403 | static void | 1387 | static void |
1404 | transmit_timeout (void *cls, | 1388 | transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1405 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1406 | { | 1389 | { |
1407 | struct GNUNET_CONNECTION_Handle *sock = cls; | 1390 | struct GNUNET_CONNECTION_Handle *sock = cls; |
1408 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1391 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1409 | 1392 | ||
1410 | #if DEBUG_CONNECTION | 1393 | #if DEBUG_CONNECTION |
1411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transmit_timeout running (%p)\n", sock); |
1412 | "transmit_timeout running (%p)\n", sock); | ||
1413 | #endif | 1395 | #endif |
1414 | sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1396 | sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1415 | #if DEBUG_CONNECTION | 1397 | #if DEBUG_CONNECTION |
@@ -1436,8 +1418,7 @@ transmit_timeout (void *cls, | |||
1436 | * @param tc scheduler context | 1418 | * @param tc scheduler context |
1437 | */ | 1419 | */ |
1438 | static void | 1420 | static void |
1439 | connect_error (void *cls, | 1421 | connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1440 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1441 | { | 1422 | { |
1442 | struct GNUNET_CONNECTION_Handle *sock = cls; | 1423 | struct GNUNET_CONNECTION_Handle *sock = cls; |
1443 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1424 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
@@ -1445,10 +1426,7 @@ connect_error (void *cls, | |||
1445 | #if DEBUG_CONNECTION | 1426 | #if DEBUG_CONNECTION |
1446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1447 | "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", | 1428 | "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", |
1448 | sock->nth.notify_size, | 1429 | sock->nth.notify_size, sock->hostname, sock->port, sock); |
1449 | sock->hostname, | ||
1450 | sock->port, | ||
1451 | sock); | ||
1452 | #endif | 1430 | #endif |
1453 | sock->write_task = GNUNET_SCHEDULER_NO_TASK; | 1431 | sock->write_task = GNUNET_SCHEDULER_NO_TASK; |
1454 | notify = sock->nth.notify_ready; | 1432 | notify = sock->nth.notify_ready; |
@@ -1468,19 +1446,18 @@ transmit_error (struct GNUNET_CONNECTION_Handle *sock) | |||
1468 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1446 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1469 | 1447 | ||
1470 | if (NULL != sock->sock) | 1448 | if (NULL != sock->sock) |
1471 | { | 1449 | { |
1472 | GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); | 1450 | GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); |
1473 | GNUNET_break (GNUNET_OK == | 1451 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); |
1474 | GNUNET_NETWORK_socket_close (sock->sock)); | 1452 | sock->sock = NULL; |
1475 | sock->sock = NULL; | 1453 | } |
1476 | } | ||
1477 | if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) | 1454 | if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) |
1478 | { | 1455 | { |
1479 | GNUNET_SCHEDULER_cancel (sock->read_task); | 1456 | GNUNET_SCHEDULER_cancel (sock->read_task); |
1480 | sock->read_task = GNUNET_SCHEDULER_NO_TASK; | 1457 | sock->read_task = GNUNET_SCHEDULER_NO_TASK; |
1481 | signal_timeout (sock); | 1458 | signal_timeout (sock); |
1482 | return; | 1459 | return; |
1483 | } | 1460 | } |
1484 | if (sock->nth.notify_ready == NULL) | 1461 | if (sock->nth.notify_ready == NULL) |
1485 | return; /* nobody to tell about it */ | 1462 | return; /* nobody to tell about it */ |
1486 | notify = sock->nth.notify_ready; | 1463 | notify = sock->nth.notify_ready; |
@@ -1506,102 +1483,99 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1506 | size_t have; | 1483 | size_t have; |
1507 | 1484 | ||
1508 | #if DEBUG_CONNECTION | 1485 | #if DEBUG_CONNECTION |
1509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", sock); |
1510 | "transmit_ready running (%p).\n", sock); | ||
1511 | #endif | 1487 | #endif |
1512 | GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK); | 1488 | GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK); |
1513 | sock->write_task = GNUNET_SCHEDULER_NO_TASK; | 1489 | sock->write_task = GNUNET_SCHEDULER_NO_TASK; |
1514 | GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); | 1490 | GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); |
1515 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1491 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1516 | { | 1492 | { |
1517 | if (sock->ignore_shutdown == GNUNET_YES) | 1493 | if (sock->ignore_shutdown == GNUNET_YES) |
1518 | goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ | 1494 | goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ |
1519 | #if DEBUG_CONNECTION | 1495 | #if DEBUG_CONNECTION |
1520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1521 | "Transmit to `%s' fails, shutdown happened (%p).\n", | 1497 | "Transmit to `%s' fails, shutdown happened (%p).\n", |
1522 | GNUNET_a2s (sock->addr, sock->addrlen), sock); | 1498 | GNUNET_a2s (sock->addr, sock->addrlen), sock); |
1523 | #endif | 1499 | #endif |
1524 | notify = sock->nth.notify_ready; | 1500 | notify = sock->nth.notify_ready; |
1525 | if (NULL != notify) | 1501 | if (NULL != notify) |
1526 | { | ||
1527 | sock->nth.notify_ready = NULL; | ||
1528 | notify (sock->nth.notify_ready_cls, 0, NULL); | ||
1529 | } | ||
1530 | return; | ||
1531 | } | ||
1532 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | ||
1533 | { | 1502 | { |
1534 | #if DEBUG_CONNECTION | ||
1535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1536 | "Transmit to `%s' fails, time out reached (%p).\n", | ||
1537 | GNUNET_a2s (sock->addr, sock->addrlen), sock); | ||
1538 | #endif | ||
1539 | notify = sock->nth.notify_ready; | ||
1540 | GNUNET_assert (NULL != notify); | ||
1541 | sock->nth.notify_ready = NULL; | 1503 | sock->nth.notify_ready = NULL; |
1542 | notify (sock->nth.notify_ready_cls, 0, NULL); | 1504 | notify (sock->nth.notify_ready_cls, 0, NULL); |
1543 | return; | ||
1544 | } | 1505 | } |
1506 | return; | ||
1507 | } | ||
1508 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | ||
1509 | { | ||
1510 | #if DEBUG_CONNECTION | ||
1511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1512 | "Transmit to `%s' fails, time out reached (%p).\n", | ||
1513 | GNUNET_a2s (sock->addr, sock->addrlen), sock); | ||
1514 | #endif | ||
1515 | notify = sock->nth.notify_ready; | ||
1516 | GNUNET_assert (NULL != notify); | ||
1517 | sock->nth.notify_ready = NULL; | ||
1518 | notify (sock->nth.notify_ready_cls, 0, NULL); | ||
1519 | return; | ||
1520 | } | ||
1545 | GNUNET_assert (NULL != sock->sock); | 1521 | GNUNET_assert (NULL != sock->sock); |
1546 | if (tc->write_ready == NULL) | 1522 | if (tc->write_ready == NULL) |
1547 | { | 1523 | { |
1548 | /* special circumstances (in particular, | 1524 | /* special circumstances (in particular, |
1549 | PREREQ_DONE after connect): not yet ready to write, | 1525 | * PREREQ_DONE after connect): not yet ready to write, |
1550 | but no "fatal" error either. Hence retry. */ | 1526 | * but no "fatal" error either. Hence retry. */ |
1551 | goto SCHEDULE_WRITE; | 1527 | goto SCHEDULE_WRITE; |
1552 | } | 1528 | } |
1553 | if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) | 1529 | if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) |
1554 | { | 1530 | { |
1555 | #if DEBUG_CONNECTION | 1531 | #if DEBUG_CONNECTION |
1556 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1532 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1557 | _ | 1533 | _ |
1558 | ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), | 1534 | ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), |
1559 | sock); | 1535 | sock); |
1560 | #endif | 1536 | #endif |
1561 | transmit_error (sock); | 1537 | transmit_error (sock); |
1562 | return; /* connect failed for good, we're finished */ | 1538 | return; /* connect failed for good, we're finished */ |
1563 | } | 1539 | } |
1564 | GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos); | 1540 | GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos); |
1565 | if ( (sock->nth.notify_ready != NULL) && | 1541 | if ((sock->nth.notify_ready != NULL) && |
1566 | (sock->write_buffer_size < sock->nth.notify_size) ) | 1542 | (sock->write_buffer_size < sock->nth.notify_size)) |
1567 | { | 1543 | { |
1568 | sock->write_buffer = GNUNET_realloc(sock->write_buffer, | 1544 | sock->write_buffer = GNUNET_realloc (sock->write_buffer, |
1569 | sock->nth.notify_size); | 1545 | sock->nth.notify_size); |
1570 | sock->write_buffer_size = sock->nth.notify_size; | 1546 | sock->write_buffer_size = sock->nth.notify_size; |
1571 | } | 1547 | } |
1572 | process_notify (sock); | 1548 | process_notify (sock); |
1573 | have = sock->write_buffer_off - sock->write_buffer_pos; | 1549 | have = sock->write_buffer_off - sock->write_buffer_pos; |
1574 | if (have == 0) | 1550 | if (have == 0) |
1575 | { | 1551 | { |
1576 | /* no data ready for writing, terminate write loop */ | 1552 | /* no data ready for writing, terminate write loop */ |
1577 | return; | 1553 | return; |
1578 | } | 1554 | } |
1579 | GNUNET_assert (have <= sock->write_buffer_size); | 1555 | GNUNET_assert (have <= sock->write_buffer_size); |
1580 | GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); | 1556 | GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); |
1581 | GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); | 1557 | GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); |
1582 | RETRY: | 1558 | RETRY: |
1583 | ret = GNUNET_NETWORK_socket_send (sock->sock, | 1559 | ret = GNUNET_NETWORK_socket_send (sock->sock, |
1584 | &sock->write_buffer[sock-> | 1560 | &sock->write_buffer[sock->write_buffer_pos], |
1585 | write_buffer_pos], | ||
1586 | have); | 1561 | have); |
1587 | if (ret == -1) | 1562 | if (ret == -1) |
1588 | { | 1563 | { |
1589 | if (errno == EINTR) | 1564 | if (errno == EINTR) |
1590 | goto RETRY; | 1565 | goto RETRY; |
1591 | #if 0 | 1566 | #if 0 |
1592 | int en = errno; | 1567 | int en = errno; |
1593 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1568 | |
1594 | _("Failed to send to `%s': %s\n"), | 1569 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1595 | GNUNET_a2s (sock->addr, | 1570 | _("Failed to send to `%s': %s\n"), |
1596 | sock->addrlen), | 1571 | GNUNET_a2s (sock->addr, sock->addrlen), STRERROR (en)); |
1597 | STRERROR (en)); | ||
1598 | #endif | 1572 | #endif |
1599 | #if DEBUG_CONNECTION | 1573 | #if DEBUG_CONNECTION |
1600 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); | 1574 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send"); |
1601 | #endif | 1575 | #endif |
1602 | transmit_error (sock); | 1576 | transmit_error (sock); |
1603 | return; | 1577 | return; |
1604 | } | 1578 | } |
1605 | #if DEBUG_CONNECTION | 1579 | #if DEBUG_CONNECTION |
1606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1607 | "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", | 1581 | "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", |
@@ -1610,11 +1584,11 @@ RETRY: | |||
1610 | #endif | 1584 | #endif |
1611 | sock->write_buffer_pos += ret; | 1585 | sock->write_buffer_pos += ret; |
1612 | if (sock->write_buffer_pos == sock->write_buffer_off) | 1586 | if (sock->write_buffer_pos == sock->write_buffer_off) |
1613 | { | 1587 | { |
1614 | /* transmitted all pending data */ | 1588 | /* transmitted all pending data */ |
1615 | sock->write_buffer_pos = 0; | 1589 | sock->write_buffer_pos = 0; |
1616 | sock->write_buffer_off = 0; | 1590 | sock->write_buffer_off = 0; |
1617 | } | 1591 | } |
1618 | if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) | 1592 | if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) |
1619 | return; /* all data sent! */ | 1593 | return; /* all data sent! */ |
1620 | /* not done writing, schedule more */ | 1594 | /* not done writing, schedule more */ |
@@ -1624,14 +1598,15 @@ SCHEDULE_WRITE: | |||
1624 | "Re-scheduling transmit_ready (more to do) (%p).\n", sock); | 1598 | "Re-scheduling transmit_ready (more to do) (%p).\n", sock); |
1625 | #endif | 1599 | #endif |
1626 | have = sock->write_buffer_off - sock->write_buffer_pos; | 1600 | have = sock->write_buffer_off - sock->write_buffer_pos; |
1627 | GNUNET_assert ( (sock->nth.notify_ready != NULL) || (have > 0) ); | 1601 | GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0)); |
1628 | if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) | 1602 | if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) |
1629 | sock->write_task = | 1603 | sock->write_task = |
1630 | GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == NULL) | 1604 | GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == NULL) |
1631 | ? GNUNET_TIME_UNIT_FOREVER_REL | 1605 | ? GNUNET_TIME_UNIT_FOREVER_REL |
1632 | : GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), | 1606 | : |
1633 | sock->sock, | 1607 | GNUNET_TIME_absolute_get_remaining |
1634 | &transmit_ready, sock); | 1608 | (sock->nth.transmit_timeout), |
1609 | sock->sock, &transmit_ready, sock); | ||
1635 | } | 1610 | } |
1636 | 1611 | ||
1637 | 1612 | ||
@@ -1657,10 +1632,10 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle | |||
1657 | notify, void *notify_cls) | 1632 | notify, void *notify_cls) |
1658 | { | 1633 | { |
1659 | if (sock->nth.notify_ready != NULL) | 1634 | if (sock->nth.notify_ready != NULL) |
1660 | { | 1635 | { |
1661 | GNUNET_assert (0); | 1636 | GNUNET_assert (0); |
1662 | return NULL; | 1637 | return NULL; |
1663 | } | 1638 | } |
1664 | GNUNET_assert (notify != NULL); | 1639 | GNUNET_assert (notify != NULL); |
1665 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 1640 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
1666 | GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); | 1641 | GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); |
@@ -1674,39 +1649,37 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle | |||
1674 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); | 1649 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); |
1675 | if ((sock->sock == NULL) && | 1650 | if ((sock->sock == NULL) && |
1676 | (sock->ap_head == NULL) && (sock->dns_active == NULL)) | 1651 | (sock->ap_head == NULL) && (sock->dns_active == NULL)) |
1677 | { | 1652 | { |
1678 | if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) | 1653 | if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) |
1679 | GNUNET_SCHEDULER_cancel (sock->write_task); | 1654 | GNUNET_SCHEDULER_cancel (sock->write_task); |
1680 | sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); | 1655 | sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); |
1681 | return &sock->nth; | 1656 | return &sock->nth; |
1682 | } | 1657 | } |
1683 | if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) | 1658 | if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) |
1684 | return &sock->nth; | 1659 | return &sock->nth; |
1685 | if (sock->sock != NULL) | 1660 | if (sock->sock != NULL) |
1686 | { | 1661 | { |
1687 | #if DEBUG_CONNECTION | 1662 | #if DEBUG_CONNECTION |
1688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1689 | "Scheduling transmit_ready (%p).\n", sock); | 1664 | "Scheduling transmit_ready (%p).\n", sock); |
1690 | #endif | 1665 | #endif |
1691 | sock->write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 1666 | sock->write_task = |
1692 | (sock->nth. | 1667 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining |
1693 | transmit_timeout), | 1668 | (sock->nth.transmit_timeout), |
1694 | sock->sock, | 1669 | sock->sock, &transmit_ready, sock); |
1695 | &transmit_ready, | 1670 | } |
1696 | sock); | ||
1697 | } | ||
1698 | else | 1671 | else |
1699 | { | 1672 | { |
1700 | #if DEBUG_CONNECTION | 1673 | #if DEBUG_CONNECTION |
1701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1702 | "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", | 1675 | "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", |
1703 | sock); | 1676 | sock); |
1704 | #endif | 1677 | #endif |
1705 | sock->ccs |= COCO_TRANSMIT_READY; | 1678 | sock->ccs |= COCO_TRANSMIT_READY; |
1706 | sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 1679 | sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, |
1707 | &transmit_timeout, | 1680 | &transmit_timeout, |
1708 | sock); | 1681 | sock); |
1709 | } | 1682 | } |
1710 | return &sock->nth; | 1683 | return &sock->nth; |
1711 | } | 1684 | } |
1712 | 1685 | ||
@@ -1723,24 +1696,23 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct | |||
1723 | { | 1696 | { |
1724 | GNUNET_assert (h->notify_ready != NULL); | 1697 | GNUNET_assert (h->notify_ready != NULL); |
1725 | if (0 != (h->sh->ccs & COCO_TRANSMIT_READY)) | 1698 | if (0 != (h->sh->ccs & COCO_TRANSMIT_READY)) |
1726 | { | 1699 | { |
1727 | #if DEBUG_CONNECTION | 1700 | #if DEBUG_CONNECTION |
1728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1729 | "notify_transmit_ready_cancel cancels timeout_task (%p)\n", | 1702 | "notify_transmit_ready_cancel cancels timeout_task (%p)\n", h); |
1730 | h); | ||
1731 | #endif | 1703 | #endif |
1732 | GNUNET_SCHEDULER_cancel (h->timeout_task); | 1704 | GNUNET_SCHEDULER_cancel (h->timeout_task); |
1733 | h->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1705 | h->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1734 | h->sh->ccs -= COCO_TRANSMIT_READY; | 1706 | h->sh->ccs -= COCO_TRANSMIT_READY; |
1735 | } | 1707 | } |
1736 | else | 1708 | else |
1709 | { | ||
1710 | if (h->sh->write_task != GNUNET_SCHEDULER_NO_TASK) | ||
1737 | { | 1711 | { |
1738 | if (h->sh->write_task != GNUNET_SCHEDULER_NO_TASK) | 1712 | GNUNET_SCHEDULER_cancel (h->sh->write_task); |
1739 | { | 1713 | h->sh->write_task = GNUNET_SCHEDULER_NO_TASK; |
1740 | GNUNET_SCHEDULER_cancel (h->sh->write_task); | ||
1741 | h->sh->write_task = GNUNET_SCHEDULER_NO_TASK; | ||
1742 | } | ||
1743 | } | 1714 | } |
1715 | } | ||
1744 | h->notify_ready = NULL; | 1716 | h->notify_ready = NULL; |
1745 | } | 1717 | } |
1746 | 1718 | ||
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index b4c3ad08d..a0749a18a 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -82,9 +82,9 @@ struct GNUNET_CONTAINER_BloomFilter | |||
82 | * @param bf the filter | 82 | * @param bf the filter |
83 | * @return number of bytes used for the data of the bloom filter | 83 | * @return number of bytes used for the data of the bloom filter |
84 | */ | 84 | */ |
85 | size_t | 85 | size_t |
86 | GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter | 86 | GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter |
87 | *bf) | 87 | *bf) |
88 | { | 88 | { |
89 | if (bf == NULL) | 89 | if (bf == NULL) |
90 | return 0; | 90 | return 0; |
@@ -99,11 +99,12 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter | |||
99 | * @return copy of the bf | 99 | * @return copy of the bf |
100 | */ | 100 | */ |
101 | struct GNUNET_CONTAINER_BloomFilter * | 101 | struct GNUNET_CONTAINER_BloomFilter * |
102 | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf) | 102 | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter |
103 | *bf) | ||
103 | { | 104 | { |
104 | return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, | 105 | return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, |
105 | bf->bitArraySize, | 106 | bf->bitArraySize, |
106 | bf->addressesPerElement); | 107 | bf->addressesPerElement); |
107 | } | 108 | } |
108 | 109 | ||
109 | 110 | ||
@@ -198,15 +199,15 @@ incrementBit (char *bitArray, unsigned int bitIdx, | |||
198 | high = (value & (~0xF)) >> 4; | 199 | high = (value & (~0xF)) >> 4; |
199 | 200 | ||
200 | if (targetLoc == 0) | 201 | if (targetLoc == 0) |
201 | { | 202 | { |
202 | if (low < 0xF) | 203 | if (low < 0xF) |
203 | low++; | 204 | low++; |
204 | } | 205 | } |
205 | else | 206 | else |
206 | { | 207 | { |
207 | if (high < 0xF) | 208 | if (high < 0xF) |
208 | high++; | 209 | high++; |
209 | } | 210 | } |
210 | value = ((high << 4) | low); | 211 | value = ((high << 4) | low); |
211 | GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, | 212 | GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, |
212 | fileSlot, | 213 | fileSlot, |
@@ -245,23 +246,23 @@ decrementBit (char *bitArray, unsigned int bitIdx, | |||
245 | 246 | ||
246 | /* decrement, but once we have reached the max, never go back! */ | 247 | /* decrement, but once we have reached the max, never go back! */ |
247 | if (targetLoc == 0) | 248 | if (targetLoc == 0) |
249 | { | ||
250 | if ((low > 0) && (low < 0xF)) | ||
251 | low--; | ||
252 | if (low == 0) | ||
248 | { | 253 | { |
249 | if ((low > 0) && (low < 0xF)) | 254 | clearBit (bitArray, bitIdx); |
250 | low--; | ||
251 | if (low == 0) | ||
252 | { | ||
253 | clearBit (bitArray, bitIdx); | ||
254 | } | ||
255 | } | 255 | } |
256 | } | ||
256 | else | 257 | else |
258 | { | ||
259 | if ((high > 0) && (high < 0xF)) | ||
260 | high--; | ||
261 | if (high == 0) | ||
257 | { | 262 | { |
258 | if ((high > 0) && (high < 0xF)) | 263 | clearBit (bitArray, bitIdx); |
259 | high--; | ||
260 | if (high == 0) | ||
261 | { | ||
262 | clearBit (bitArray, bitIdx); | ||
263 | } | ||
264 | } | 264 | } |
265 | } | ||
265 | value = ((high << 4) | low); | 266 | value = ((high << 4) | low); |
266 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); | 267 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); |
267 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); | 268 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); |
@@ -290,19 +291,19 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) | |||
290 | GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); | 291 | GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); |
291 | 292 | ||
292 | while (bytesleft > 0) | 293 | while (bytesleft > 0) |
294 | { | ||
295 | if (bytesleft > BUFFSIZE) | ||
293 | { | 296 | { |
294 | if (bytesleft > BUFFSIZE) | 297 | res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); |
295 | { | 298 | bytesleft -= BUFFSIZE; |
296 | res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); | ||
297 | bytesleft -= BUFFSIZE; | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | res = GNUNET_DISK_file_write (fh, buffer, bytesleft); | ||
302 | bytesleft = 0; | ||
303 | } | ||
304 | GNUNET_assert (res != GNUNET_SYSERR); | ||
305 | } | 299 | } |
300 | else | ||
301 | { | ||
302 | res = GNUNET_DISK_file_write (fh, buffer, bytesleft); | ||
303 | bytesleft = 0; | ||
304 | } | ||
305 | GNUNET_assert (res != GNUNET_SYSERR); | ||
306 | } | ||
306 | GNUNET_free (buffer); | 307 | GNUNET_free (buffer); |
307 | return GNUNET_OK; | 308 | return GNUNET_OK; |
308 | } | 309 | } |
@@ -319,7 +320,7 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) | |||
319 | * @param bit the current bit | 320 | * @param bit the current bit |
320 | */ | 321 | */ |
321 | typedef void (*BitIterator) (void *cls, | 322 | typedef void (*BitIterator) (void *cls, |
322 | const struct GNUNET_CONTAINER_BloomFilter *bf, | 323 | const struct GNUNET_CONTAINER_BloomFilter * bf, |
323 | unsigned int bit); | 324 | unsigned int bit); |
324 | 325 | ||
325 | /** | 326 | /** |
@@ -333,7 +334,7 @@ typedef void (*BitIterator) (void *cls, | |||
333 | */ | 334 | */ |
334 | static void | 335 | static void |
335 | iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | 336 | iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, |
336 | BitIterator callback, void *arg, const GNUNET_HashCode *key) | 337 | BitIterator callback, void *arg, const GNUNET_HashCode * key) |
337 | { | 338 | { |
338 | GNUNET_HashCode tmp[2]; | 339 | GNUNET_HashCode tmp[2]; |
339 | int bitCount; | 340 | int bitCount; |
@@ -344,26 +345,26 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
344 | memcpy (&tmp[0], key, sizeof (GNUNET_HashCode)); | 345 | memcpy (&tmp[0], key, sizeof (GNUNET_HashCode)); |
345 | round = 0; | 346 | round = 0; |
346 | while (bitCount > 0) | 347 | while (bitCount > 0) |
348 | { | ||
349 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | ||
347 | { | 350 | { |
348 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | 351 | callback (arg, |
349 | { | 352 | bf, |
350 | callback (arg, | 353 | (((uint32_t *) & tmp[round & 1])[slot]) & |
351 | bf, | 354 | ((bf->bitArraySize * 8) - 1)); |
352 | (((uint32_t *) &tmp[round & 1])[slot]) & | 355 | slot++; |
353 | ((bf->bitArraySize * 8) - 1)); | 356 | bitCount--; |
354 | slot++; | 357 | if (bitCount == 0) |
355 | bitCount--; | 358 | break; |
356 | if (bitCount == 0) | ||
357 | break; | ||
358 | } | ||
359 | if (bitCount > 0) | ||
360 | { | ||
361 | GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), | ||
362 | &tmp[(round + 1) & 1]); | ||
363 | round++; | ||
364 | slot = 0; | ||
365 | } | ||
366 | } | 359 | } |
360 | if (bitCount > 0) | ||
361 | { | ||
362 | GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), | ||
363 | &tmp[(round + 1) & 1]); | ||
364 | round++; | ||
365 | slot = 0; | ||
366 | } | ||
367 | } | ||
367 | } | 368 | } |
368 | 369 | ||
369 | /** | 370 | /** |
@@ -379,6 +380,7 @@ incrementBitCallback (void *cls, | |||
379 | unsigned int bit) | 380 | unsigned int bit) |
380 | { | 381 | { |
381 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 382 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
383 | |||
382 | incrementBit (b->bitArray, bit, bf->fh); | 384 | incrementBit (b->bitArray, bit, bf->fh); |
383 | } | 385 | } |
384 | 386 | ||
@@ -395,6 +397,7 @@ decrementBitCallback (void *cls, | |||
395 | unsigned int bit) | 397 | unsigned int bit) |
396 | { | 398 | { |
397 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 399 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
400 | |||
398 | decrementBit (b->bitArray, bit, bf->fh); | 401 | decrementBit (b->bitArray, bit, bf->fh); |
399 | } | 402 | } |
400 | 403 | ||
@@ -408,9 +411,10 @@ decrementBitCallback (void *cls, | |||
408 | static void | 411 | static void |
409 | testBitCallback (void *cls, | 412 | testBitCallback (void *cls, |
410 | const struct GNUNET_CONTAINER_BloomFilter *bf, | 413 | const struct GNUNET_CONTAINER_BloomFilter *bf, |
411 | unsigned int bit) | 414 | unsigned int bit) |
412 | { | 415 | { |
413 | int *arg = cls; | 416 | int *arg = cls; |
417 | |||
414 | if (GNUNET_NO == testBit (bf->bitArray, bit)) | 418 | if (GNUNET_NO == testBit (bf->bitArray, bit)) |
415 | *arg = GNUNET_NO; | 419 | *arg = GNUNET_NO; |
416 | } | 420 | } |
@@ -450,25 +454,25 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, | |||
450 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); | 454 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); |
451 | /* Try to open a bloomfilter file */ | 455 | /* Try to open a bloomfilter file */ |
452 | bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE | 456 | bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE |
453 | | GNUNET_DISK_OPEN_CREATE, | 457 | | GNUNET_DISK_OPEN_CREATE, |
454 | GNUNET_DISK_PERM_USER_READ | | 458 | GNUNET_DISK_PERM_USER_READ | |
455 | GNUNET_DISK_PERM_USER_WRITE); | 459 | GNUNET_DISK_PERM_USER_WRITE); |
456 | if (NULL == bf->fh) | 460 | if (NULL == bf->fh) |
457 | { | 461 | { |
458 | GNUNET_free (bf); | 462 | GNUNET_free (bf); |
459 | return NULL; | 463 | return NULL; |
460 | } | 464 | } |
461 | bf->filename = GNUNET_strdup (filename); | 465 | bf->filename = GNUNET_strdup (filename); |
462 | /* Alloc block */ | 466 | /* Alloc block */ |
463 | bf->bitArray = GNUNET_malloc_large (size); | 467 | bf->bitArray = GNUNET_malloc_large (size); |
464 | if (bf->bitArray == NULL) | 468 | if (bf->bitArray == NULL) |
465 | { | 469 | { |
466 | if (bf->fh != NULL) | 470 | if (bf->fh != NULL) |
467 | GNUNET_DISK_file_close (bf->fh); | 471 | GNUNET_DISK_file_close (bf->fh); |
468 | GNUNET_free (bf->filename); | 472 | GNUNET_free (bf->filename); |
469 | GNUNET_free (bf); | 473 | GNUNET_free (bf); |
470 | return NULL; | 474 | return NULL; |
471 | } | 475 | } |
472 | bf->bitArraySize = size; | 476 | bf->bitArraySize = size; |
473 | bf->addressesPerElement = k; | 477 | bf->addressesPerElement = k; |
474 | memset (bf->bitArray, 0, bf->bitArraySize); | 478 | memset (bf->bitArray, 0, bf->bitArraySize); |
@@ -477,28 +481,28 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, | |||
477 | rbuff = GNUNET_malloc (BUFFSIZE); | 481 | rbuff = GNUNET_malloc (BUFFSIZE); |
478 | pos = 0; | 482 | pos = 0; |
479 | while (pos < size * 8) | 483 | while (pos < size * 8) |
484 | { | ||
485 | int res; | ||
486 | |||
487 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | ||
488 | if (res == -1) | ||
489 | { | ||
490 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
491 | "read", bf->filename); | ||
492 | } | ||
493 | if (res == 0) | ||
494 | break; /* is ok! we just did not use that many bits yet */ | ||
495 | for (i = 0; i < res; i++) | ||
480 | { | 496 | { |
481 | int res; | 497 | if ((rbuff[i] & 0x0F) != 0) |
482 | 498 | setBit (bf->bitArray, pos + i * 2); | |
483 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | 499 | if ((rbuff[i] & 0xF0) != 0) |
484 | if (res == -1) | 500 | setBit (bf->bitArray, pos + i * 2 + 1); |
485 | { | ||
486 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
487 | "read", bf->filename); | ||
488 | } | ||
489 | if (res == 0) | ||
490 | break; /* is ok! we just did not use that many bits yet */ | ||
491 | for (i = 0; i < res; i++) | ||
492 | { | ||
493 | if ((rbuff[i] & 0x0F) != 0) | ||
494 | setBit (bf->bitArray, pos + i * 2); | ||
495 | if ((rbuff[i] & 0xF0) != 0) | ||
496 | setBit (bf->bitArray, pos + i * 2 + 1); | ||
497 | } | ||
498 | if (res < BUFFSIZE) | ||
499 | break; | ||
500 | pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ | ||
501 | } | 501 | } |
502 | if (res < BUFFSIZE) | ||
503 | break; | ||
504 | pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ | ||
505 | } | ||
502 | GNUNET_free (rbuff); | 506 | GNUNET_free (rbuff); |
503 | return bf; | 507 | return bf; |
504 | } | 508 | } |
@@ -530,19 +534,19 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, | |||
530 | while (ui < size) | 534 | while (ui < size) |
531 | ui *= 2; | 535 | ui *= 2; |
532 | if (size != ui) | 536 | if (size != ui) |
533 | { | 537 | { |
534 | GNUNET_break (0); | 538 | GNUNET_break (0); |
535 | return NULL; | 539 | return NULL; |
536 | } | 540 | } |
537 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); | 541 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); |
538 | bf->filename = NULL; | 542 | bf->filename = NULL; |
539 | bf->fh = NULL; | 543 | bf->fh = NULL; |
540 | bf->bitArray = GNUNET_malloc_large (size); | 544 | bf->bitArray = GNUNET_malloc_large (size); |
541 | if (bf->bitArray == NULL) | 545 | if (bf->bitArray == NULL) |
542 | { | 546 | { |
543 | GNUNET_free (bf); | 547 | GNUNET_free (bf); |
544 | return NULL; | 548 | return NULL; |
545 | } | 549 | } |
546 | bf->bitArraySize = size; | 550 | bf->bitArraySize = size; |
547 | bf->addressesPerElement = k; | 551 | bf->addressesPerElement = k; |
548 | if (data != NULL) | 552 | if (data != NULL) |
@@ -563,8 +567,9 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, | |||
563 | * @return GNUNET_SYSERR if the data array is not big enough | 567 | * @return GNUNET_SYSERR if the data array is not big enough |
564 | */ | 568 | */ |
565 | int | 569 | int |
566 | GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFilter | 570 | GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct |
567 | *bf, char *data, size_t size) | 571 | GNUNET_CONTAINER_BloomFilter *bf, |
572 | char *data, size_t size) | ||
568 | { | 573 | { |
569 | if (NULL == bf) | 574 | if (NULL == bf) |
570 | return GNUNET_SYSERR; | 575 | return GNUNET_SYSERR; |
@@ -618,8 +623,8 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf) | |||
618 | * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not | 623 | * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not |
619 | */ | 624 | */ |
620 | int | 625 | int |
621 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, | 626 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter |
622 | const GNUNET_HashCode * e) | 627 | *bf, const GNUNET_HashCode * e) |
623 | { | 628 | { |
624 | int res; | 629 | int res; |
625 | 630 | ||
@@ -663,20 +668,20 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
663 | { | 668 | { |
664 | unsigned int i; | 669 | unsigned int i; |
665 | unsigned int n; | 670 | unsigned int n; |
666 | unsigned long long* fc; | 671 | unsigned long long *fc; |
667 | const unsigned long long* dc; | 672 | const unsigned long long *dc; |
668 | 673 | ||
669 | if (NULL == bf) | 674 | if (NULL == bf) |
670 | return GNUNET_YES; | 675 | return GNUNET_YES; |
671 | if (bf->bitArraySize != size) | 676 | if (bf->bitArraySize != size) |
672 | return GNUNET_SYSERR; | 677 | return GNUNET_SYSERR; |
673 | fc = (unsigned long long*) bf->bitArray; | 678 | fc = (unsigned long long *) bf->bitArray; |
674 | dc = (const unsigned long long*) data; | 679 | dc = (const unsigned long long *) data; |
675 | n = size / sizeof (unsigned long long); | 680 | n = size / sizeof (unsigned long long); |
676 | 681 | ||
677 | for (i = 0; i < n; i++) | 682 | for (i = 0; i < n; i++) |
678 | fc[i] |= dc[i]; | 683 | fc[i] |= dc[i]; |
679 | for (i = n * sizeof(unsigned long long); i < size; i++) | 684 | for (i = n * sizeof (unsigned long long); i < size; i++) |
680 | bf->bitArray[i] |= data[i]; | 685 | bf->bitArray[i] |= data[i]; |
681 | return GNUNET_OK; | 686 | return GNUNET_OK; |
682 | } | 687 | } |
@@ -693,25 +698,25 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
693 | */ | 698 | */ |
694 | int | 699 | int |
695 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | 700 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, |
696 | const struct GNUNET_CONTAINER_BloomFilter *to_or, | 701 | const struct GNUNET_CONTAINER_BloomFilter |
697 | size_t size) | 702 | *to_or, size_t size) |
698 | { | 703 | { |
699 | unsigned int i; | 704 | unsigned int i; |
700 | unsigned int n; | 705 | unsigned int n; |
701 | unsigned long long* fc; | 706 | unsigned long long *fc; |
702 | const unsigned long long* dc; | 707 | const unsigned long long *dc; |
703 | 708 | ||
704 | if (NULL == bf) | 709 | if (NULL == bf) |
705 | return GNUNET_YES; | 710 | return GNUNET_YES; |
706 | if (bf->bitArraySize != size) | 711 | if (bf->bitArraySize != size) |
707 | return GNUNET_SYSERR; | 712 | return GNUNET_SYSERR; |
708 | fc = (unsigned long long*) bf->bitArray; | 713 | fc = (unsigned long long *) bf->bitArray; |
709 | dc = (const unsigned long long*) to_or->bitArray; | 714 | dc = (const unsigned long long *) to_or->bitArray; |
710 | n = size / sizeof (unsigned long long); | 715 | n = size / sizeof (unsigned long long); |
711 | 716 | ||
712 | for (i = 0; i < n; i++) | 717 | for (i = 0; i < n; i++) |
713 | fc[i] |= dc[i]; | 718 | fc[i] |= dc[i]; |
714 | for (i = n * sizeof(unsigned long long); i < size; i++) | 719 | for (i = n * sizeof (unsigned long long); i < size; i++) |
715 | bf->bitArray[i] |= to_or->bitArray[i]; | 720 | bf->bitArray[i] |= to_or->bitArray[i]; |
716 | return GNUNET_OK; | 721 | return GNUNET_OK; |
717 | } | 722 | } |
diff --git a/src/util/container_heap.c b/src/util/container_heap.c index a7e79cc7e..c1d478e06 100644 --- a/src/util/container_heap.c +++ b/src/util/container_heap.c | |||
@@ -94,7 +94,7 @@ struct GNUNET_CONTAINER_Heap | |||
94 | * Number of elements in the heap. | 94 | * Number of elements in the heap. |
95 | */ | 95 | */ |
96 | unsigned int size; | 96 | unsigned int size; |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * How is the heap sorted? | 99 | * How is the heap sorted? |
100 | */ | 100 | */ |
@@ -108,15 +108,17 @@ struct GNUNET_CONTAINER_Heap | |||
108 | * Check if internal invariants hold for the given node. | 108 | * Check if internal invariants hold for the given node. |
109 | * | 109 | * |
110 | * @param node subtree to check | 110 | * @param node subtree to check |
111 | */ | 111 | */ |
112 | static void | 112 | static void |
113 | check (const struct GNUNET_CONTAINER_HeapNode *node) | 113 | check (const struct GNUNET_CONTAINER_HeapNode *node) |
114 | { | 114 | { |
115 | if (NULL == node) | 115 | if (NULL == node) |
116 | return; | 116 | return; |
117 | GNUNET_assert (node->tree_size == | 117 | GNUNET_assert (node->tree_size == |
118 | ( (node->left_child == NULL) ? 0 : 1 + node->left_child->tree_size) + | 118 | ((node->left_child == |
119 | ( (node->right_child == NULL) ? 0 : 1 + node->right_child->tree_size) ); | 119 | NULL) ? 0 : 1 + node->left_child->tree_size) + |
120 | ((node->right_child == | ||
121 | NULL) ? 0 : 1 + node->right_child->tree_size)); | ||
120 | check (node->left_child); | 122 | check (node->left_child); |
121 | check (node->right_child); | 123 | check (node->right_child); |
122 | } | 124 | } |
@@ -194,7 +196,8 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap) | |||
194 | * @return cost of the node | 196 | * @return cost of the node |
195 | */ | 197 | */ |
196 | GNUNET_CONTAINER_HeapCostType | 198 | GNUNET_CONTAINER_HeapCostType |
197 | GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node) | 199 | GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode |
200 | *node) | ||
198 | { | 201 | { |
199 | return node->cost; | 202 | return node->cost; |
200 | } | 203 | } |
@@ -210,26 +213,18 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *nod | |||
210 | */ | 213 | */ |
211 | static int | 214 | static int |
212 | node_iterator (const struct GNUNET_CONTAINER_Heap *heap, | 215 | node_iterator (const struct GNUNET_CONTAINER_Heap *heap, |
213 | struct GNUNET_CONTAINER_HeapNode *node, | 216 | struct GNUNET_CONTAINER_HeapNode *node, |
214 | GNUNET_CONTAINER_HeapIterator iterator, | 217 | GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls) |
215 | void *iterator_cls) | ||
216 | { | 218 | { |
217 | if (node == NULL) | 219 | if (node == NULL) |
218 | return GNUNET_YES; | 220 | return GNUNET_YES; |
219 | if (GNUNET_YES != node_iterator (heap, | 221 | if (GNUNET_YES != node_iterator (heap, |
220 | node->left_child, | 222 | node->left_child, iterator, iterator_cls)) |
221 | iterator, | ||
222 | iterator_cls)) | ||
223 | return GNUNET_NO; | 223 | return GNUNET_NO; |
224 | if (GNUNET_YES != node_iterator (heap, | 224 | if (GNUNET_YES != node_iterator (heap, |
225 | node->right_child, | 225 | node->right_child, iterator, iterator_cls)) |
226 | iterator, | ||
227 | iterator_cls)) | ||
228 | return GNUNET_NO; | 226 | return GNUNET_NO; |
229 | return iterator (iterator_cls, | 227 | return iterator (iterator_cls, node, node->element, node->cost); |
230 | node, | ||
231 | node->element, | ||
232 | node->cost); | ||
233 | } | 228 | } |
234 | 229 | ||
235 | 230 | ||
@@ -269,13 +264,12 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap) | |||
269 | if (heap->root == NULL) | 264 | if (heap->root == NULL) |
270 | return NULL; | 265 | return NULL; |
271 | pos = heap->walk_pos; | 266 | pos = heap->walk_pos; |
272 | if (pos == NULL) | 267 | if (pos == NULL) |
273 | pos = heap->root; | 268 | pos = heap->root; |
274 | element = pos->element; | 269 | element = pos->element; |
275 | heap->walk_pos | 270 | heap->walk_pos |
276 | = (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) | 271 | = (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) |
277 | ? pos->right_child | 272 | ? pos->right_child : pos->left_child; |
278 | : pos->left_child; | ||
279 | return element; | 273 | return element; |
280 | } | 274 | } |
281 | 275 | ||
@@ -290,51 +284,50 @@ GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap) | |||
290 | */ | 284 | */ |
291 | static void | 285 | static void |
292 | insert_node (struct GNUNET_CONTAINER_Heap *heap, | 286 | insert_node (struct GNUNET_CONTAINER_Heap *heap, |
293 | struct GNUNET_CONTAINER_HeapNode *pos, | 287 | struct GNUNET_CONTAINER_HeapNode *pos, |
294 | struct GNUNET_CONTAINER_HeapNode *node) | 288 | struct GNUNET_CONTAINER_HeapNode *node) |
295 | { | 289 | { |
296 | struct GNUNET_CONTAINER_HeapNode *parent; | 290 | struct GNUNET_CONTAINER_HeapNode *parent; |
297 | 291 | ||
298 | GNUNET_assert (node->parent == NULL); | 292 | GNUNET_assert (node->parent == NULL); |
299 | while ( (heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) | 293 | while ((heap->order == GNUNET_CONTAINER_HEAP_ORDER_MAX) |
300 | ? (pos->cost >= node->cost) | 294 | ? (pos->cost >= node->cost) : (pos->cost <= node->cost)) |
301 | : (pos->cost <= node->cost) ) | 295 | { |
296 | /* node is descendent of pos */ | ||
297 | pos->tree_size += (1 + node->tree_size); | ||
298 | if (pos->left_child == NULL) | ||
302 | { | 299 | { |
303 | /* node is descendent of pos */ | 300 | pos->left_child = node; |
304 | pos->tree_size += (1 + node->tree_size); | 301 | node->parent = pos; |
305 | if (pos->left_child == NULL) | 302 | return; |
306 | { | ||
307 | pos->left_child = node; | ||
308 | node->parent = pos; | ||
309 | return; | ||
310 | } | ||
311 | if (pos->right_child == NULL) | ||
312 | { | ||
313 | pos->right_child = node; | ||
314 | node->parent = pos; | ||
315 | return; | ||
316 | } | ||
317 | /* keep it balanced by descending into smaller subtree */ | ||
318 | if (pos->left_child->tree_size < pos->right_child->tree_size) | ||
319 | pos = pos->left_child; | ||
320 | else | ||
321 | pos = pos->right_child; | ||
322 | } | 303 | } |
304 | if (pos->right_child == NULL) | ||
305 | { | ||
306 | pos->right_child = node; | ||
307 | node->parent = pos; | ||
308 | return; | ||
309 | } | ||
310 | /* keep it balanced by descending into smaller subtree */ | ||
311 | if (pos->left_child->tree_size < pos->right_child->tree_size) | ||
312 | pos = pos->left_child; | ||
313 | else | ||
314 | pos = pos->right_child; | ||
315 | } | ||
323 | /* make 'node' parent of 'pos' */ | 316 | /* make 'node' parent of 'pos' */ |
324 | parent = pos->parent; | 317 | parent = pos->parent; |
325 | pos->parent = NULL; | 318 | pos->parent = NULL; |
326 | node->parent = parent; | 319 | node->parent = parent; |
327 | if (NULL == parent) | 320 | if (NULL == parent) |
328 | { | 321 | { |
329 | heap->root = node; | 322 | heap->root = node; |
330 | } | 323 | } |
331 | else | 324 | else |
332 | { | 325 | { |
333 | if (parent->left_child == pos) | 326 | if (parent->left_child == pos) |
334 | parent->left_child = node; | 327 | parent->left_child = node; |
335 | else | 328 | else |
336 | parent->right_child = node; | 329 | parent->right_child = node; |
337 | } | 330 | } |
338 | /* insert 'pos' below 'node' */ | 331 | /* insert 'pos' below 'node' */ |
339 | insert_node (heap, node, pos); | 332 | insert_node (heap, node, pos); |
340 | CHECK (pos); | 333 | CHECK (pos); |
@@ -351,8 +344,7 @@ insert_node (struct GNUNET_CONTAINER_Heap *heap, | |||
351 | */ | 344 | */ |
352 | struct GNUNET_CONTAINER_HeapNode * | 345 | struct GNUNET_CONTAINER_HeapNode * |
353 | GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, | 346 | GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, |
354 | void *element, | 347 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
355 | GNUNET_CONTAINER_HeapCostType cost) | ||
356 | { | 348 | { |
357 | struct GNUNET_CONTAINER_HeapNode *node; | 349 | struct GNUNET_CONTAINER_HeapNode *node; |
358 | 350 | ||
@@ -388,28 +380,28 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap) | |||
388 | heap->size--; | 380 | heap->size--; |
389 | ret = root->element; | 381 | ret = root->element; |
390 | if (root->left_child == NULL) | 382 | if (root->left_child == NULL) |
391 | { | 383 | { |
392 | heap->root = root->right_child; | 384 | heap->root = root->right_child; |
393 | if (root->right_child != NULL) | 385 | if (root->right_child != NULL) |
394 | root->right_child->parent = NULL; | 386 | root->right_child->parent = NULL; |
395 | } | 387 | } |
396 | else if (root->right_child == NULL) | 388 | else if (root->right_child == NULL) |
397 | { | 389 | { |
398 | heap->root = root->left_child; | 390 | heap->root = root->left_child; |
399 | root->left_child->parent = NULL; | 391 | root->left_child->parent = NULL; |
400 | } | 392 | } |
401 | else | 393 | else |
402 | { | 394 | { |
403 | root->left_child->parent = NULL; | 395 | root->left_child->parent = NULL; |
404 | root->right_child->parent = NULL; | 396 | root->right_child->parent = NULL; |
405 | heap->root = root->left_child; | 397 | heap->root = root->left_child; |
406 | insert_node (heap, heap->root, root->right_child); | 398 | insert_node (heap, heap->root, root->right_child); |
407 | } | 399 | } |
408 | GNUNET_free (root); | 400 | GNUNET_free (root); |
409 | #if DEBUG | 401 | #if DEBUG |
410 | GNUNET_assert (( (heap->size == 0) && | 402 | GNUNET_assert (((heap->size == 0) && |
411 | (heap->root == NULL) ) || | 403 | (heap->root == NULL)) || |
412 | (heap->size == heap->root->tree_size + 1) ); | 404 | (heap->size == heap->root->tree_size + 1)); |
413 | CHECK (heap->root); | 405 | CHECK (heap->root); |
414 | #endif | 406 | #endif |
415 | return ret; | 407 | return ret; |
@@ -430,7 +422,7 @@ remove_node (struct GNUNET_CONTAINER_HeapNode *node) | |||
430 | 422 | ||
431 | /* update 'size' of the ancestors */ | 423 | /* update 'size' of the ancestors */ |
432 | ancestor = node; | 424 | ancestor = node; |
433 | while (NULL != (ancestor = ancestor->parent)) | 425 | while (NULL != (ancestor = ancestor->parent)) |
434 | ancestor->tree_size--; | 426 | ancestor->tree_size--; |
435 | 427 | ||
436 | /* update 'size' of node itself */ | 428 | /* update 'size' of node itself */ |
@@ -441,43 +433,43 @@ remove_node (struct GNUNET_CONTAINER_HeapNode *node) | |||
441 | 433 | ||
442 | /* unlink 'node' itself and insert children in its place */ | 434 | /* unlink 'node' itself and insert children in its place */ |
443 | if (node->parent == NULL) | 435 | if (node->parent == NULL) |
436 | { | ||
437 | if (node->left_child != NULL) | ||
444 | { | 438 | { |
445 | if (node->left_child != NULL) | 439 | heap->root = node->left_child; |
446 | { | 440 | node->left_child->parent = NULL; |
447 | heap->root = node->left_child; | 441 | if (node->right_child != NULL) |
448 | node->left_child->parent = NULL; | 442 | { |
449 | if (node->right_child != NULL) | 443 | node->right_child->parent = NULL; |
450 | { | 444 | insert_node (heap, heap->root, node->right_child); |
451 | node->right_child->parent = NULL; | 445 | } |
452 | insert_node (heap, heap->root, node->right_child); | ||
453 | } | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | heap->root = node->right_child; | ||
458 | if (node->right_child != NULL) | ||
459 | node->right_child->parent = NULL; | ||
460 | } | ||
461 | } | 446 | } |
462 | else | 447 | else |
463 | { | 448 | { |
464 | if (node->parent->left_child == node) | 449 | heap->root = node->right_child; |
465 | node->parent->left_child = NULL; | ||
466 | else | ||
467 | node->parent->right_child = NULL; | ||
468 | if (node->left_child != NULL) | ||
469 | { | ||
470 | node->left_child->parent = NULL; | ||
471 | node->parent->tree_size -= (1 + node->left_child->tree_size); | ||
472 | insert_node (heap, node->parent, node->left_child); | ||
473 | } | ||
474 | if (node->right_child != NULL) | 450 | if (node->right_child != NULL) |
475 | { | 451 | node->right_child->parent = NULL; |
476 | node->right_child->parent = NULL; | 452 | } |
477 | node->parent->tree_size -= (1 + node->right_child->tree_size); | 453 | } |
478 | insert_node (heap, node->parent, node->right_child); | 454 | else |
479 | } | 455 | { |
456 | if (node->parent->left_child == node) | ||
457 | node->parent->left_child = NULL; | ||
458 | else | ||
459 | node->parent->right_child = NULL; | ||
460 | if (node->left_child != NULL) | ||
461 | { | ||
462 | node->left_child->parent = NULL; | ||
463 | node->parent->tree_size -= (1 + node->left_child->tree_size); | ||
464 | insert_node (heap, node->parent, node->left_child); | ||
465 | } | ||
466 | if (node->right_child != NULL) | ||
467 | { | ||
468 | node->right_child->parent = NULL; | ||
469 | node->parent->tree_size -= (1 + node->right_child->tree_size); | ||
470 | insert_node (heap, node->parent, node->right_child); | ||
480 | } | 471 | } |
472 | } | ||
481 | node->parent = NULL; | 473 | node->parent = NULL; |
482 | node->left_child = NULL; | 474 | node->left_child = NULL; |
483 | node->right_child = NULL; | 475 | node->right_child = NULL; |
@@ -498,7 +490,7 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) | |||
498 | void *ret; | 490 | void *ret; |
499 | struct GNUNET_CONTAINER_Heap *heap; | 491 | struct GNUNET_CONTAINER_Heap *heap; |
500 | 492 | ||
501 | heap = node->heap; | 493 | heap = node->heap; |
502 | CHECK (heap->root); | 494 | CHECK (heap->root); |
503 | if (heap->walk_pos == node) | 495 | if (heap->walk_pos == node) |
504 | (void) GNUNET_CONTAINER_heap_walk_get_next (heap); | 496 | (void) GNUNET_CONTAINER_heap_walk_get_next (heap); |
@@ -510,9 +502,9 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) | |||
510 | GNUNET_free (node); | 502 | GNUNET_free (node); |
511 | #if DEBUG | 503 | #if DEBUG |
512 | CHECK (heap->root); | 504 | CHECK (heap->root); |
513 | GNUNET_assert (( (heap->size == 0) && | 505 | GNUNET_assert (((heap->size == 0) && |
514 | (heap->root == NULL) ) || | 506 | (heap->root == NULL)) || |
515 | (heap->size == heap->root->tree_size + 1) ); | 507 | (heap->size == heap->root->tree_size + 1)); |
516 | #endif | 508 | #endif |
517 | return ret; | 509 | return ret; |
518 | } | 510 | } |
@@ -527,21 +519,21 @@ GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) | |||
527 | */ | 519 | */ |
528 | void | 520 | void |
529 | GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, | 521 | GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, |
530 | struct GNUNET_CONTAINER_HeapNode *node, | 522 | struct GNUNET_CONTAINER_HeapNode *node, |
531 | GNUNET_CONTAINER_HeapCostType new_cost) | 523 | GNUNET_CONTAINER_HeapCostType new_cost) |
532 | { | 524 | { |
533 | #if DEBUG | 525 | #if DEBUG |
534 | GNUNET_assert ( ( (heap->size == 0) && | 526 | GNUNET_assert (((heap->size == 0) && |
535 | (heap->root == NULL) ) || | 527 | (heap->root == NULL)) || |
536 | (heap->size == heap->root->tree_size + 1) ); | 528 | (heap->size == heap->root->tree_size + 1)); |
537 | CHECK (heap->root); | 529 | CHECK (heap->root); |
538 | #endif | 530 | #endif |
539 | remove_node (node); | 531 | remove_node (node); |
540 | #if DEBUG | 532 | #if DEBUG |
541 | CHECK (heap->root); | 533 | CHECK (heap->root); |
542 | GNUNET_assert ( ( (heap->size == 1) && | 534 | GNUNET_assert (((heap->size == 1) && |
543 | (heap->root == NULL) ) || | 535 | (heap->root == NULL)) || |
544 | (heap->size == heap->root->tree_size + 2) ); | 536 | (heap->size == heap->root->tree_size + 2)); |
545 | #endif | 537 | #endif |
546 | node->cost = new_cost; | 538 | node->cost = new_cost; |
547 | if (heap->root == NULL) | 539 | if (heap->root == NULL) |
@@ -550,9 +542,9 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, | |||
550 | insert_node (heap, heap->root, node); | 542 | insert_node (heap, heap->root, node); |
551 | #if DEBUG | 543 | #if DEBUG |
552 | CHECK (heap->root); | 544 | CHECK (heap->root); |
553 | GNUNET_assert ( ( (heap->size == 0) && | 545 | GNUNET_assert (((heap->size == 0) && |
554 | (heap->root == NULL) ) || | 546 | (heap->root == NULL)) || |
555 | (heap->size == heap->root->tree_size + 1) ); | 547 | (heap->size == heap->root->tree_size + 1)); |
556 | #endif | 548 | #endif |
557 | } | 549 | } |
558 | 550 | ||
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index 9d20f8dc5..64a58e133 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c | |||
@@ -39,7 +39,7 @@ struct MetaItem | |||
39 | { | 39 | { |
40 | /** | 40 | /** |
41 | * This is a linked list. | 41 | * This is a linked list. |
42 | */ | 42 | */ |
43 | struct MetaItem *next; | 43 | struct MetaItem *next; |
44 | 44 | ||
45 | /** | 45 | /** |
@@ -160,10 +160,10 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md) | |||
160 | if (md == NULL) | 160 | if (md == NULL) |
161 | return; | 161 | return; |
162 | while (NULL != (item = md->items)) | 162 | while (NULL != (item = md->items)) |
163 | { | 163 | { |
164 | md->items = item->next; | 164 | md->items = item->next; |
165 | meta_item_free (item); | 165 | meta_item_free (item); |
166 | } | 166 | } |
167 | GNUNET_free_non_null (md->sbuf); | 167 | GNUNET_free_non_null (md->sbuf); |
168 | GNUNET_free (md); | 168 | GNUNET_free (md); |
169 | } | 169 | } |
@@ -174,7 +174,7 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md) | |||
174 | * | 174 | * |
175 | * @param md metadata to manipulate | 175 | * @param md metadata to manipulate |
176 | */ | 176 | */ |
177 | void | 177 | void |
178 | GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md) | 178 | GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md) |
179 | { | 179 | { |
180 | struct MetaItem *item; | 180 | struct MetaItem *item; |
@@ -182,10 +182,10 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md) | |||
182 | if (md == NULL) | 182 | if (md == NULL) |
183 | return; | 183 | return; |
184 | while (NULL != (item = md->items)) | 184 | while (NULL != (item = md->items)) |
185 | { | 185 | { |
186 | md->items = item->next; | 186 | md->items = item->next; |
187 | meta_item_free (item); | 187 | meta_item_free (item); |
188 | } | 188 | } |
189 | GNUNET_free_non_null (md->sbuf); | 189 | GNUNET_free_non_null (md->sbuf); |
190 | memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData)); | 190 | memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData)); |
191 | } | 191 | } |
@@ -219,27 +219,25 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData | |||
219 | 219 | ||
220 | i = md1->items; | 220 | i = md1->items; |
221 | while (NULL != i) | 221 | while (NULL != i) |
222 | { | ||
223 | found = GNUNET_NO; | ||
224 | j = md2->items; | ||
225 | while (NULL != j) | ||
222 | { | 226 | { |
223 | found = GNUNET_NO; | 227 | if ((i->type == j->type) && |
224 | j = md2->items; | 228 | (i->format == j->format) && |
225 | while (NULL != j) | 229 | (i->data_size == j->data_size) && |
226 | { | 230 | (0 == memcmp (i->data, j->data, i->data_size))) |
227 | if ( (i->type == j->type) && | 231 | { |
228 | (i->format == j->format) && | 232 | found = GNUNET_YES; |
229 | (i->data_size == j->data_size) && | 233 | break; |
230 | (0 == memcmp (i->data, | 234 | } |
231 | j->data, | 235 | j = j->next; |
232 | i->data_size))) | ||
233 | { | ||
234 | found = GNUNET_YES; | ||
235 | break; | ||
236 | } | ||
237 | j = j->next; | ||
238 | } | ||
239 | if (found == GNUNET_NO) | ||
240 | return GNUNET_NO; | ||
241 | i = i->next; | ||
242 | } | 236 | } |
237 | if (found == GNUNET_NO) | ||
238 | return GNUNET_NO; | ||
239 | i = i->next; | ||
240 | } | ||
243 | return GNUNET_YES; | 241 | return GNUNET_YES; |
244 | } | 242 | } |
245 | 243 | ||
@@ -264,12 +262,11 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData | |||
264 | */ | 262 | */ |
265 | int | 263 | int |
266 | GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | 264 | GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, |
267 | const char *plugin_name, | 265 | const char *plugin_name, |
268 | enum EXTRACTOR_MetaType type, | 266 | enum EXTRACTOR_MetaType type, |
269 | enum EXTRACTOR_MetaFormat format, | 267 | enum EXTRACTOR_MetaFormat format, |
270 | const char *data_mime_type, | 268 | const char *data_mime_type, |
271 | const char *data, | 269 | const char *data, size_t data_len) |
272 | size_t data_len) | ||
273 | { | 270 | { |
274 | struct MetaItem *prev; | 271 | struct MetaItem *prev; |
275 | struct MetaItem *pos; | 272 | struct MetaItem *pos; |
@@ -279,32 +276,29 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
279 | prev = NULL; | 276 | prev = NULL; |
280 | pos = md->items; | 277 | pos = md->items; |
281 | while (NULL != pos) | 278 | while (NULL != pos) |
279 | { | ||
280 | if (pos->data_size < data_len) | ||
281 | break; | ||
282 | if ((pos->type == type) && | ||
283 | (pos->data_size == data_len) && | ||
284 | (0 == memcmp (pos->data, data, data_len))) | ||
282 | { | 285 | { |
283 | if (pos->data_size < data_len) | 286 | if ((pos->mime_type == NULL) && (data_mime_type != NULL)) |
284 | break; | 287 | { |
285 | if ( (pos->type == type) && | 288 | pos->mime_type = GNUNET_strdup (data_mime_type); |
286 | (pos->data_size == data_len) && | 289 | invalidate_sbuf (md); |
287 | (0 == memcmp (pos->data, | 290 | } |
288 | data, | 291 | if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) && |
289 | data_len))) | 292 | (format == EXTRACTOR_METAFORMAT_UTF8)) |
290 | { | 293 | { |
291 | if ( (pos->mime_type == NULL) && | 294 | pos->format = EXTRACTOR_METAFORMAT_UTF8; |
292 | (data_mime_type != NULL) ) | 295 | invalidate_sbuf (md); |
293 | { | 296 | } |
294 | pos->mime_type = GNUNET_strdup (data_mime_type); | 297 | return GNUNET_SYSERR; |
295 | invalidate_sbuf (md); | ||
296 | } | ||
297 | if ( (pos->format == EXTRACTOR_METAFORMAT_C_STRING) && | ||
298 | (format == EXTRACTOR_METAFORMAT_UTF8) ) | ||
299 | { | ||
300 | pos->format = EXTRACTOR_METAFORMAT_UTF8; | ||
301 | invalidate_sbuf (md); | ||
302 | } | ||
303 | return GNUNET_SYSERR; | ||
304 | } | ||
305 | prev = pos; | ||
306 | pos = pos->next; | ||
307 | } | 298 | } |
299 | prev = pos; | ||
300 | pos = pos->next; | ||
301 | } | ||
308 | md->item_count++; | 302 | md->item_count++; |
309 | i = GNUNET_malloc (sizeof (struct MetaItem)); | 303 | i = GNUNET_malloc (sizeof (struct MetaItem)); |
310 | i->type = type; | 304 | i->type = type; |
@@ -315,24 +309,24 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
315 | md->items = i; | 309 | md->items = i; |
316 | else | 310 | else |
317 | prev->next = i; | 311 | prev->next = i; |
318 | i->mime_type = (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type); | 312 | i->mime_type = |
313 | (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type); | ||
319 | i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name); | 314 | i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name); |
320 | i->data = GNUNET_malloc (data_len); | 315 | i->data = GNUNET_malloc (data_len); |
321 | memcpy (i->data, data, data_len); | 316 | memcpy (i->data, data, data_len); |
322 | /* change OS native dir separators to unix '/' and others to '_' */ | 317 | /* change OS native dir separators to unix '/' and others to '_' */ |
323 | if (type == EXTRACTOR_METATYPE_FILENAME) | 318 | if (type == EXTRACTOR_METATYPE_FILENAME) |
319 | { | ||
320 | p = i->data; | ||
321 | while ((*p != '\0') && (p < i->data + data_len)) | ||
324 | { | 322 | { |
325 | p = i->data; | 323 | if (*p == DIR_SEPARATOR) |
326 | while ( (*p != '\0') && | 324 | *p = '/'; |
327 | (p < i->data + data_len) ) | 325 | else if (*p == '\\') |
328 | { | 326 | *p = '_'; |
329 | if (*p == DIR_SEPARATOR) | 327 | p++; |
330 | *p = '/'; | ||
331 | else if (*p == '\\') | ||
332 | *p = '_'; | ||
333 | p++; | ||
334 | } | ||
335 | } | 328 | } |
329 | } | ||
336 | invalidate_sbuf (md); | 330 | invalidate_sbuf (md); |
337 | return GNUNET_OK; | 331 | return GNUNET_OK; |
338 | } | 332 | } |
@@ -353,20 +347,19 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
353 | * @param data actual meta-data found | 347 | * @param data actual meta-data found |
354 | * @param data_len number of bytes in data | 348 | * @param data_len number of bytes in data |
355 | * @return 0 (to continue) | 349 | * @return 0 (to continue) |
356 | */ | 350 | */ |
357 | static int | 351 | static int |
358 | merge_helper(void *cls, | 352 | merge_helper (void *cls, |
359 | const char *plugin_name, | 353 | const char *plugin_name, |
360 | enum EXTRACTOR_MetaType type, | 354 | enum EXTRACTOR_MetaType type, |
361 | enum EXTRACTOR_MetaFormat format, | 355 | enum EXTRACTOR_MetaFormat format, |
362 | const char *data_mime_type, | 356 | const char *data_mime_type, const char *data, size_t data_len) |
363 | const char *data, | ||
364 | size_t data_len) | ||
365 | { | 357 | { |
366 | struct GNUNET_CONTAINER_MetaData *md = cls; | 358 | struct GNUNET_CONTAINER_MetaData *md = cls; |
359 | |||
367 | (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, | 360 | (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, |
368 | type, format, | 361 | type, format, |
369 | data_mime_type, data, data_len); | 362 | data_mime_type, data, data_len); |
370 | return 0; | 363 | return 0; |
371 | } | 364 | } |
372 | 365 | ||
@@ -378,9 +371,9 @@ merge_helper(void *cls, | |||
378 | * @param md metadata to extend | 371 | * @param md metadata to extend |
379 | * @param in metadata to merge | 372 | * @param in metadata to merge |
380 | */ | 373 | */ |
381 | void | 374 | void |
382 | GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, | 375 | GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, |
383 | const struct GNUNET_CONTAINER_MetaData *in) | 376 | const struct GNUNET_CONTAINER_MetaData *in) |
384 | { | 377 | { |
385 | GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md); | 378 | GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md); |
386 | } | 379 | } |
@@ -398,9 +391,8 @@ GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, | |||
398 | */ | 391 | */ |
399 | int | 392 | int |
400 | GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, | 393 | GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, |
401 | enum EXTRACTOR_MetaType type, | 394 | enum EXTRACTOR_MetaType type, |
402 | const char *data, | 395 | const char *data, size_t data_len) |
403 | size_t data_len) | ||
404 | { | 396 | { |
405 | struct MetaItem *pos; | 397 | struct MetaItem *pos; |
406 | struct MetaItem *prev; | 398 | struct MetaItem *prev; |
@@ -408,26 +400,24 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, | |||
408 | prev = NULL; | 400 | prev = NULL; |
409 | pos = md->items; | 401 | pos = md->items; |
410 | while (NULL != pos) | 402 | while (NULL != pos) |
403 | { | ||
404 | if ((pos->type == type) && | ||
405 | ((data == NULL) || | ||
406 | ((pos->data_size == data_len) && | ||
407 | (0 == memcmp (pos->data, data, data_len))))) | ||
411 | { | 408 | { |
412 | if ( (pos->type == type) && | 409 | if (prev == NULL) |
413 | ( (data == NULL) || | 410 | md->items = pos->next; |
414 | ( (pos->data_size == data_len) && | 411 | else |
415 | (0 == memcmp (pos->data, | 412 | prev->next = pos->next; |
416 | data, | 413 | meta_item_free (pos); |
417 | data_len))) ) ) | 414 | md->item_count--; |
418 | { | 415 | invalidate_sbuf (md); |
419 | if (prev == NULL) | 416 | return GNUNET_OK; |
420 | md->items = pos->next; | ||
421 | else | ||
422 | prev->next = pos->next; | ||
423 | meta_item_free (pos); | ||
424 | md->item_count--; | ||
425 | invalidate_sbuf (md); | ||
426 | return GNUNET_OK; | ||
427 | } | ||
428 | prev = pos; | ||
429 | pos = pos->next; | ||
430 | } | 417 | } |
418 | prev = pos; | ||
419 | pos = pos->next; | ||
420 | } | ||
431 | return GNUNET_SYSERR; | 421 | return GNUNET_SYSERR; |
432 | } | 422 | } |
433 | 423 | ||
@@ -440,25 +430,21 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, | |||
440 | */ | 430 | */ |
441 | void | 431 | void |
442 | GNUNET_CONTAINER_meta_data_add_publication_date (struct | 432 | GNUNET_CONTAINER_meta_data_add_publication_date (struct |
443 | GNUNET_CONTAINER_MetaData | 433 | GNUNET_CONTAINER_MetaData *md) |
444 | *md) | ||
445 | { | 434 | { |
446 | char *dat; | 435 | char *dat; |
447 | struct GNUNET_TIME_Absolute t; | 436 | struct GNUNET_TIME_Absolute t; |
448 | 437 | ||
449 | t = GNUNET_TIME_absolute_get (); | 438 | t = GNUNET_TIME_absolute_get (); |
450 | GNUNET_CONTAINER_meta_data_delete (md, | 439 | GNUNET_CONTAINER_meta_data_delete (md, |
451 | EXTRACTOR_METATYPE_PUBLICATION_DATE, | 440 | EXTRACTOR_METATYPE_PUBLICATION_DATE, |
452 | NULL, | 441 | NULL, 0); |
453 | 0); | ||
454 | dat = GNUNET_STRINGS_absolute_time_to_string (t); | 442 | dat = GNUNET_STRINGS_absolute_time_to_string (t); |
455 | GNUNET_CONTAINER_meta_data_insert (md, | 443 | GNUNET_CONTAINER_meta_data_insert (md, |
456 | "<gnunet>", | 444 | "<gnunet>", |
457 | EXTRACTOR_METATYPE_PUBLICATION_DATE, | 445 | EXTRACTOR_METATYPE_PUBLICATION_DATE, |
458 | EXTRACTOR_METAFORMAT_UTF8, | 446 | EXTRACTOR_METAFORMAT_UTF8, |
459 | "text/plain", | 447 | "text/plain", dat, strlen (dat) + 1); |
460 | dat, | ||
461 | strlen(dat)+1); | ||
462 | GNUNET_free (dat); | 448 | GNUNET_free (dat); |
463 | } | 449 | } |
464 | 450 | ||
@@ -473,9 +459,9 @@ GNUNET_CONTAINER_meta_data_add_publication_date (struct | |||
473 | */ | 459 | */ |
474 | int | 460 | int |
475 | GNUNET_CONTAINER_meta_data_iterate (const struct | 461 | GNUNET_CONTAINER_meta_data_iterate (const struct |
476 | GNUNET_CONTAINER_MetaData *md, | 462 | GNUNET_CONTAINER_MetaData *md, |
477 | EXTRACTOR_MetaDataProcessor | 463 | EXTRACTOR_MetaDataProcessor |
478 | iter, void *iter_cls) | 464 | iter, void *iter_cls) |
479 | { | 465 | { |
480 | struct MetaItem *pos; | 466 | struct MetaItem *pos; |
481 | 467 | ||
@@ -485,17 +471,14 @@ GNUNET_CONTAINER_meta_data_iterate (const struct | |||
485 | return md->item_count; | 471 | return md->item_count; |
486 | pos = md->items; | 472 | pos = md->items; |
487 | while (NULL != pos) | 473 | while (NULL != pos) |
488 | { | 474 | { |
489 | if (0 != iter (iter_cls, | 475 | if (0 != iter (iter_cls, |
490 | pos->plugin_name, | 476 | pos->plugin_name, |
491 | pos->type, | 477 | pos->type, |
492 | pos->format, | 478 | pos->format, pos->mime_type, pos->data, pos->data_size)) |
493 | pos->mime_type, | 479 | return md->item_count; |
494 | pos->data, | 480 | pos = pos->next; |
495 | pos->data_size)) | 481 | } |
496 | return md->item_count; | ||
497 | pos = pos->next; | ||
498 | } | ||
499 | return md->item_count; | 482 | return md->item_count; |
500 | } | 483 | } |
501 | 484 | ||
@@ -520,13 +503,13 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData | |||
520 | return NULL; | 503 | return NULL; |
521 | pos = md->items; | 504 | pos = md->items; |
522 | while (NULL != pos) | 505 | while (NULL != pos) |
523 | { | 506 | { |
524 | if ( (type == pos->type) && | 507 | if ((type == pos->type) && |
525 | ( (pos->format == EXTRACTOR_METAFORMAT_UTF8) || | 508 | ((pos->format == EXTRACTOR_METAFORMAT_UTF8) || |
526 | (pos->format == EXTRACTOR_METAFORMAT_C_STRING) ) ) | 509 | (pos->format == EXTRACTOR_METAFORMAT_C_STRING))) |
527 | return GNUNET_strdup (pos->data); | 510 | return GNUNET_strdup (pos->data); |
528 | pos = pos->next; | 511 | pos = pos->next; |
529 | } | 512 | } |
530 | return NULL; | 513 | return NULL; |
531 | } | 514 | } |
532 | 515 | ||
@@ -556,14 +539,15 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct | |||
556 | ret = NULL; | 539 | ret = NULL; |
557 | va_start (args, md); | 540 | va_start (args, md); |
558 | while (1) | 541 | while (1) |
559 | { | 542 | { |
560 | type = va_arg (args, enum EXTRACTOR_MetaType); | 543 | type = va_arg (args, enum EXTRACTOR_MetaType); |
561 | if (type == -1) | 544 | |
562 | break; | 545 | if (type == -1) |
563 | ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type); | 546 | break; |
564 | if (ret != NULL) | 547 | ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type); |
565 | break; | 548 | if (ret != NULL) |
566 | } | 549 | break; |
550 | } | ||
567 | va_end (args); | 551 | va_end (args); |
568 | return ret; | 552 | return ret; |
569 | } | 553 | } |
@@ -590,22 +574,21 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct | |||
590 | match = NULL; | 574 | match = NULL; |
591 | pos = md->items; | 575 | pos = md->items; |
592 | while (NULL != pos) | 576 | while (NULL != pos) |
593 | { | 577 | { |
594 | if ( (NULL != pos->mime_type) && | 578 | if ((NULL != pos->mime_type) && |
595 | (0 == strncasecmp ("image/", pos->mime_type, | 579 | (0 == strncasecmp ("image/", pos->mime_type, |
596 | strlen("image/"))) && | 580 | strlen ("image/"))) && |
597 | (pos->format == EXTRACTOR_METAFORMAT_BINARY) ) | 581 | (pos->format == EXTRACTOR_METAFORMAT_BINARY)) |
598 | { | 582 | { |
599 | if (match == NULL) | 583 | if (match == NULL) |
600 | match = pos; | 584 | match = pos; |
601 | else if ( (match->type != EXTRACTOR_METATYPE_THUMBNAIL) && | 585 | else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) && |
602 | (pos->type == EXTRACTOR_METATYPE_THUMBNAIL) ) | 586 | (pos->type == EXTRACTOR_METATYPE_THUMBNAIL)) |
603 | match = pos; | 587 | match = pos; |
604 | } | ||
605 | pos = pos->next; | ||
606 | } | 588 | } |
607 | if ( (match == NULL) || | 589 | pos = pos->next; |
608 | (match->data_size == 0) ) | 590 | } |
591 | if ((match == NULL) || (match->data_size == 0)) | ||
609 | return 0; | 592 | return 0; |
610 | *thumb = GNUNET_malloc (match->data_size); | 593 | *thumb = GNUNET_malloc (match->data_size); |
611 | memcpy (*thumb, match->data, match->data_size); | 594 | memcpy (*thumb, match->data, match->data_size); |
@@ -631,16 +614,15 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData | |||
631 | ret = GNUNET_CONTAINER_meta_data_create (); | 614 | ret = GNUNET_CONTAINER_meta_data_create (); |
632 | pos = md->items; | 615 | pos = md->items; |
633 | while (NULL != pos) | 616 | while (NULL != pos) |
634 | { | 617 | { |
635 | GNUNET_CONTAINER_meta_data_insert (ret, | 618 | GNUNET_CONTAINER_meta_data_insert (ret, |
636 | pos->plugin_name, | 619 | pos->plugin_name, |
637 | pos->type, | 620 | pos->type, |
638 | pos->format, | 621 | pos->format, |
639 | pos->mime_type, | 622 | pos->mime_type, |
640 | pos->data, | 623 | pos->data, pos->data_size); |
641 | pos->data_size); | 624 | pos = pos->next; |
642 | pos = pos->next; | 625 | } |
643 | } | ||
644 | return ret; | 626 | return ret; |
645 | } | 627 | } |
646 | 628 | ||
@@ -660,10 +642,8 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData | |||
660 | * GNUNET_NO if compression did not help | 642 | * GNUNET_NO if compression did not help |
661 | */ | 643 | */ |
662 | static int | 644 | static int |
663 | try_compression (const char *data, | 645 | try_compression (const char *data, |
664 | size_t oldSize, | 646 | size_t oldSize, char **result, size_t * newSize) |
665 | char **result, | ||
666 | size_t *newSize) | ||
667 | { | 647 | { |
668 | char *tmp; | 648 | char *tmp; |
669 | uLongf dlen; | 649 | uLongf dlen; |
@@ -673,19 +653,19 @@ try_compression (const char *data, | |||
673 | #else | 653 | #else |
674 | dlen = oldSize + (oldSize / 100) + 20; | 654 | dlen = oldSize + (oldSize / 100) + 20; |
675 | /* documentation says 100.1% oldSize + 12 bytes, but we | 655 | /* documentation says 100.1% oldSize + 12 bytes, but we |
676 | should be able to overshoot by more to be safe */ | 656 | * should be able to overshoot by more to be safe */ |
677 | #endif | 657 | #endif |
678 | tmp = GNUNET_malloc (dlen); | 658 | tmp = GNUNET_malloc (dlen); |
679 | if (Z_OK == compress2 ((Bytef *) tmp, | 659 | if (Z_OK == compress2 ((Bytef *) tmp, |
680 | &dlen, (const Bytef *) data, oldSize, 9)) | 660 | &dlen, (const Bytef *) data, oldSize, 9)) |
661 | { | ||
662 | if (dlen < oldSize) | ||
681 | { | 663 | { |
682 | if (dlen < oldSize) | 664 | *result = tmp; |
683 | { | 665 | *newSize = dlen; |
684 | *result = tmp; | 666 | return GNUNET_YES; |
685 | *newSize = dlen; | ||
686 | return GNUNET_YES; | ||
687 | } | ||
688 | } | 667 | } |
668 | } | ||
689 | GNUNET_free (tmp); | 669 | GNUNET_free (tmp); |
690 | return GNUNET_NO; | 670 | return GNUNET_NO; |
691 | } | 671 | } |
@@ -744,7 +724,7 @@ struct MetaDataEntry | |||
744 | { | 724 | { |
745 | /** | 725 | /** |
746 | * Meta data type. Corresponds to an 'enum EXTRACTOR_MetaType' | 726 | * Meta data type. Corresponds to an 'enum EXTRACTOR_MetaType' |
747 | */ | 727 | */ |
748 | uint32_t type; | 728 | uint32_t type; |
749 | 729 | ||
750 | /** | 730 | /** |
@@ -793,8 +773,8 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
793 | { | 773 | { |
794 | struct GNUNET_CONTAINER_MetaData *vmd; | 774 | struct GNUNET_CONTAINER_MetaData *vmd; |
795 | struct MetaItem *pos; | 775 | struct MetaItem *pos; |
796 | struct MetaDataHeader ihdr; | 776 | struct MetaDataHeader ihdr; |
797 | struct MetaDataHeader *hdr; | 777 | struct MetaDataHeader *hdr; |
798 | struct MetaDataEntry *ent; | 778 | struct MetaDataEntry *ent; |
799 | char *dst; | 779 | char *dst; |
800 | unsigned int i; | 780 | unsigned int i; |
@@ -814,78 +794,76 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
814 | return GNUNET_SYSERR; /* far too small */ | 794 | return GNUNET_SYSERR; /* far too small */ |
815 | if (md == NULL) | 795 | if (md == NULL) |
816 | return 0; | 796 | return 0; |
817 | 797 | ||
818 | if (md->sbuf != NULL) | 798 | if (md->sbuf != NULL) |
799 | { | ||
800 | /* try to use serialization cache */ | ||
801 | if (md->sbuf_size <= max) | ||
819 | { | 802 | { |
820 | /* try to use serialization cache */ | 803 | if (NULL == *target) |
821 | if (md->sbuf_size <= max) | 804 | *target = GNUNET_malloc (md->sbuf_size); |
822 | { | 805 | memcpy (*target, md->sbuf, md->sbuf_size); |
823 | if (NULL == *target) | 806 | return md->sbuf_size; |
824 | *target = GNUNET_malloc (md->sbuf_size); | ||
825 | memcpy (*target, | ||
826 | md->sbuf, | ||
827 | md->sbuf_size); | ||
828 | return md->sbuf_size; | ||
829 | } | ||
830 | if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) | ||
831 | return GNUNET_SYSERR; /* can say that this will fail */ | ||
832 | /* need to compute a partial serialization, sbuf useless ... */ | ||
833 | } | 807 | } |
834 | dst = NULL; | 808 | if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) |
809 | return GNUNET_SYSERR; /* can say that this will fail */ | ||
810 | /* need to compute a partial serialization, sbuf useless ... */ | ||
811 | } | ||
812 | dst = NULL; | ||
835 | msize = 0; | 813 | msize = 0; |
836 | pos = md->items; | 814 | pos = md->items; |
837 | while (NULL != pos) | 815 | while (NULL != pos) |
838 | { | 816 | { |
839 | msize += sizeof (struct MetaDataEntry); | 817 | msize += sizeof (struct MetaDataEntry); |
840 | msize += pos->data_size; | 818 | msize += pos->data_size; |
841 | if (pos->plugin_name != NULL) | 819 | if (pos->plugin_name != NULL) |
842 | msize += strlen (pos->plugin_name) + 1; | 820 | msize += strlen (pos->plugin_name) + 1; |
843 | if (pos->mime_type != NULL) | 821 | if (pos->mime_type != NULL) |
844 | msize += strlen (pos->mime_type) + 1; | 822 | msize += strlen (pos->mime_type) + 1; |
845 | pos = pos->next; | 823 | pos = pos->next; |
846 | } | 824 | } |
847 | size = (size_t) msize; | 825 | size = (size_t) msize; |
848 | if (size != msize) | 826 | if (size != msize) |
849 | { | 827 | { |
850 | GNUNET_break (0); /* integer overflow */ | 828 | GNUNET_break (0); /* integer overflow */ |
851 | return GNUNET_SYSERR; | 829 | return GNUNET_SYSERR; |
852 | } | 830 | } |
853 | if (size >= GNUNET_MAX_MALLOC_CHECKED) | 831 | if (size >= GNUNET_MAX_MALLOC_CHECKED) |
854 | { | 832 | { |
855 | /* too large to be processed */ | 833 | /* too large to be processed */ |
856 | return GNUNET_SYSERR; | 834 | return GNUNET_SYSERR; |
857 | } | 835 | } |
858 | ent = GNUNET_malloc (size); | 836 | ent = GNUNET_malloc (size); |
859 | mdata = (char *) &ent[md->item_count]; | 837 | mdata = (char *) &ent[md->item_count]; |
860 | off = size - (md->item_count * sizeof(struct MetaDataEntry)); | 838 | off = size - (md->item_count * sizeof (struct MetaDataEntry)); |
861 | i = 0; | 839 | i = 0; |
862 | pos = md->items; | 840 | pos = md->items; |
863 | while (NULL != pos) | 841 | while (NULL != pos) |
864 | { | 842 | { |
865 | ent[i].type = htonl ((uint32_t) pos->type); | 843 | ent[i].type = htonl ((uint32_t) pos->type); |
866 | ent[i].format = htonl ((uint32_t) pos->format); | 844 | ent[i].format = htonl ((uint32_t) pos->format); |
867 | ent[i].data_size = htonl ((uint32_t) pos->data_size); | 845 | ent[i].data_size = htonl ((uint32_t) pos->data_size); |
868 | if (pos->plugin_name == NULL) | 846 | if (pos->plugin_name == NULL) |
869 | plen = 0; | 847 | plen = 0; |
870 | else | 848 | else |
871 | plen = strlen (pos->plugin_name) + 1; | 849 | plen = strlen (pos->plugin_name) + 1; |
872 | ent[i].plugin_name_len = htonl ( (uint32_t) plen); | 850 | ent[i].plugin_name_len = htonl ((uint32_t) plen); |
873 | if (pos->mime_type == NULL) | 851 | if (pos->mime_type == NULL) |
874 | mlen = 0; | 852 | mlen = 0; |
875 | else | 853 | else |
876 | mlen = strlen (pos->mime_type) + 1; | 854 | mlen = strlen (pos->mime_type) + 1; |
877 | ent[i].mime_type_len = htonl ((uint32_t) mlen); | 855 | ent[i].mime_type_len = htonl ((uint32_t) mlen); |
878 | off -= pos->data_size; | 856 | off -= pos->data_size; |
879 | memcpy (&mdata[off], pos->data, pos->data_size); | 857 | memcpy (&mdata[off], pos->data, pos->data_size); |
880 | off -= plen; | 858 | off -= plen; |
881 | if (pos->plugin_name != NULL) | 859 | if (pos->plugin_name != NULL) |
882 | memcpy (&mdata[off], pos->plugin_name, plen); | 860 | memcpy (&mdata[off], pos->plugin_name, plen); |
883 | off -= mlen; | 861 | off -= mlen; |
884 | if (pos->mime_type != NULL) | 862 | if (pos->mime_type != NULL) |
885 | memcpy (&mdata[off], pos->mime_type, mlen); | 863 | memcpy (&mdata[off], pos->mime_type, mlen); |
886 | i++; | 864 | i++; |
887 | pos = pos->next; | 865 | pos = pos->next; |
888 | } | 866 | } |
889 | GNUNET_assert (off == 0); | 867 | GNUNET_assert (off == 0); |
890 | 868 | ||
891 | clen = 0; | 869 | clen = 0; |
@@ -894,115 +872,102 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
894 | i = 0; | 872 | i = 0; |
895 | pos = md->items; | 873 | pos = md->items; |
896 | while (pos != NULL) | 874 | while (pos != NULL) |
897 | { | 875 | { |
898 | comp = GNUNET_NO; | 876 | comp = GNUNET_NO; |
899 | if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS)) | 877 | if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS)) |
900 | comp = try_compression ((const char*) &ent[i], | 878 | comp = try_compression ((const char *) &ent[i], left, &cdata, &clen); |
901 | left, | 879 | |
902 | &cdata, | 880 | if ((md->sbuf == NULL) && (i == 0)) |
903 | &clen); | 881 | { |
904 | 882 | /* fill 'sbuf'; this "modifies" md, but since this is only | |
905 | if ( (md->sbuf == NULL) && | 883 | * an internal cache we will cast away the 'const' instead |
906 | (i == 0) ) | 884 | * of making the API look strange. */ |
907 | { | 885 | vmd = (struct GNUNET_CONTAINER_MetaData *) md; |
908 | /* fill 'sbuf'; this "modifies" md, but since this is only | 886 | hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); |
909 | an internal cache we will cast away the 'const' instead | 887 | hdr->size = htonl (left); |
910 | of making the API look strange. */ | 888 | hdr->entries = htonl (md->item_count); |
911 | vmd = (struct GNUNET_CONTAINER_MetaData*) md; | 889 | if (GNUNET_YES == comp) |
912 | hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); | 890 | { |
913 | hdr->size = htonl (left); | 891 | GNUNET_assert (clen < left); |
914 | hdr->entries = htonl (md->item_count); | 892 | hdr->version = htonl (2 | HEADER_COMPRESSED); |
915 | if (GNUNET_YES == comp) | 893 | memcpy (&hdr[1], cdata, clen); |
916 | { | 894 | vmd->sbuf_size = clen + sizeof (struct MetaDataHeader); |
917 | GNUNET_assert (clen < left); | 895 | } |
918 | hdr->version = htonl (2 | HEADER_COMPRESSED); | 896 | else |
919 | memcpy (&hdr[1], | 897 | { |
920 | cdata, | 898 | hdr->version = htonl (2); |
921 | clen); | 899 | memcpy (&hdr[1], &ent[0], left); |
922 | vmd->sbuf_size = clen + sizeof (struct MetaDataHeader); | 900 | vmd->sbuf_size = left + sizeof (struct MetaDataHeader); |
923 | } | 901 | } |
924 | else | 902 | vmd->sbuf = (char *) hdr; |
925 | { | 903 | } |
926 | hdr->version = htonl (2); | 904 | |
927 | memcpy (&hdr[1], | 905 | if (((left + sizeof (struct MetaDataHeader)) <= max) || |
928 | &ent[0], | 906 | ((comp == GNUNET_YES) && (clen <= max))) |
929 | left); | 907 | { |
930 | vmd->sbuf_size = left + sizeof (struct MetaDataHeader); | 908 | /* success, this now fits! */ |
931 | } | 909 | if (GNUNET_YES == comp) |
932 | vmd->sbuf = (char*) hdr; | 910 | { |
933 | } | 911 | if (dst == NULL) |
934 | 912 | dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader)); | |
935 | if ( ( (left + sizeof (struct MetaDataHeader)) <= max) || | 913 | hdr = (struct MetaDataHeader *) dst; |
936 | ( (comp == GNUNET_YES) && | 914 | hdr->version = htonl (2 | HEADER_COMPRESSED); |
937 | (clen <= max)) ) | 915 | hdr->size = htonl (left); |
938 | { | 916 | hdr->entries = htonl (md->item_count - i); |
939 | /* success, this now fits! */ | 917 | memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen); |
940 | if (GNUNET_YES == comp) | 918 | GNUNET_free (cdata); |
941 | { | 919 | GNUNET_free (ent); |
942 | if (dst == NULL) | 920 | rlen = clen + sizeof (struct MetaDataHeader); |
943 | dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader)); | 921 | } |
944 | hdr = (struct MetaDataHeader*) dst; | 922 | else |
945 | hdr->version = htonl (2 | HEADER_COMPRESSED); | 923 | { |
946 | hdr->size = htonl (left); | 924 | if (dst == NULL) |
947 | hdr->entries = htonl (md->item_count - i); | 925 | dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); |
948 | memcpy (&dst[sizeof(struct MetaDataHeader)], | 926 | hdr = (struct MetaDataHeader *) dst; |
949 | cdata, | 927 | hdr->version = htonl (2); |
950 | clen); | 928 | hdr->entries = htonl (md->item_count - i); |
951 | GNUNET_free (cdata); | 929 | hdr->size = htonl (left); |
952 | GNUNET_free (ent); | 930 | memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left); |
953 | rlen = clen + sizeof (struct MetaDataHeader); | 931 | GNUNET_free (ent); |
954 | } | 932 | rlen = left + sizeof (struct MetaDataHeader); |
955 | else | 933 | } |
956 | { | 934 | if (NULL != *target) |
957 | if (dst == NULL) | 935 | { |
958 | dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader)); | 936 | memcpy (*target, dst, clen + sizeof (struct MetaDataHeader)); |
959 | hdr = (struct MetaDataHeader*) dst; | 937 | GNUNET_free (dst); |
960 | hdr->version = htonl (2); | 938 | } |
961 | hdr->entries = htonl (md->item_count - i); | 939 | else |
962 | hdr->size = htonl (left); | 940 | { |
963 | memcpy (&dst[sizeof(struct MetaDataHeader)], | 941 | *target = dst; |
964 | &ent[i], | 942 | } |
965 | left); | 943 | return rlen; |
966 | GNUNET_free (ent); | 944 | } |
967 | rlen = left + sizeof (struct MetaDataHeader); | 945 | |
968 | } | 946 | if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) |
969 | if (NULL != *target) | 947 | { |
970 | { | 948 | /* does not fit! */ |
971 | memcpy (*target, dst, clen + sizeof (struct MetaDataHeader)); | 949 | GNUNET_free (ent); |
972 | GNUNET_free (dst); | 950 | return GNUNET_SYSERR; |
973 | } | ||
974 | else | ||
975 | { | ||
976 | *target = dst; | ||
977 | } | ||
978 | return rlen; | ||
979 | } | ||
980 | |||
981 | if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART)) | ||
982 | { | ||
983 | /* does not fit! */ | ||
984 | GNUNET_free (ent); | ||
985 | return GNUNET_SYSERR; | ||
986 | } | ||
987 | |||
988 | /* next iteration: ignore the corresponding meta data at the | ||
989 | end and try again without it */ | ||
990 | left -= sizeof (struct MetaDataEntry); | ||
991 | left -= pos->data_size; | ||
992 | if (pos->plugin_name != NULL) | ||
993 | left -= strlen (pos->plugin_name) + 1; | ||
994 | if (pos->mime_type != NULL) | ||
995 | left -= strlen (pos->mime_type) + 1; | ||
996 | pos = pos->next; | ||
997 | i++; | ||
998 | } | 951 | } |
952 | |||
953 | /* next iteration: ignore the corresponding meta data at the | ||
954 | * end and try again without it */ | ||
955 | left -= sizeof (struct MetaDataEntry); | ||
956 | left -= pos->data_size; | ||
957 | if (pos->plugin_name != NULL) | ||
958 | left -= strlen (pos->plugin_name) + 1; | ||
959 | if (pos->mime_type != NULL) | ||
960 | left -= strlen (pos->mime_type) + 1; | ||
961 | pos = pos->next; | ||
962 | i++; | ||
963 | } | ||
999 | GNUNET_free (ent); | 964 | GNUNET_free (ent); |
1000 | 965 | ||
1001 | /* nothing fit, only write header! */ | 966 | /* nothing fit, only write header! */ |
1002 | ihdr.version = htonl (2); | 967 | ihdr.version = htonl (2); |
1003 | ihdr.entries = htonl (0); | 968 | ihdr.entries = htonl (0); |
1004 | ihdr.size = htonl (0); | 969 | ihdr.size = htonl (0); |
1005 | if (*target == NULL) | 970 | if (*target == NULL) |
1006 | *target = GNUNET_malloc (sizeof (struct MetaDataHeader)); | 971 | *target = GNUNET_malloc (sizeof (struct MetaDataHeader)); |
1007 | memcpy (*target, &ihdr, sizeof (struct MetaDataHeader)); | 972 | memcpy (*target, &ihdr, sizeof (struct MetaDataHeader)); |
1008 | return sizeof (struct MetaDataHeader); | 973 | return sizeof (struct MetaDataHeader); |
@@ -1016,18 +981,19 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
1016 | * @return number of bytes needed for serialization, -1 on error | 981 | * @return number of bytes needed for serialization, -1 on error |
1017 | */ | 982 | */ |
1018 | ssize_t | 983 | ssize_t |
1019 | GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_MetaData *md) | 984 | GNUNET_CONTAINER_meta_data_get_serialized_size (const struct |
985 | GNUNET_CONTAINER_MetaData *md) | ||
1020 | { | 986 | { |
1021 | ssize_t ret; | 987 | ssize_t ret; |
1022 | char *ptr; | 988 | char *ptr; |
1023 | 989 | ||
1024 | if (md->sbuf != NULL) | 990 | if (md->sbuf != NULL) |
1025 | return md->sbuf_size; | 991 | return md->sbuf_size; |
1026 | ptr = NULL; | 992 | ptr = NULL; |
1027 | ret = GNUNET_CONTAINER_meta_data_serialize (md, | 993 | ret = GNUNET_CONTAINER_meta_data_serialize (md, |
1028 | &ptr, | 994 | &ptr, |
1029 | GNUNET_MAX_MALLOC_CHECKED, | 995 | GNUNET_MAX_MALLOC_CHECKED, |
1030 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); | 996 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); |
1031 | if (ret != -1) | 997 | if (ret != -1) |
1032 | GNUNET_free (ptr); | 998 | GNUNET_free (ptr); |
1033 | return ret; | 999 | return ret; |
@@ -1045,9 +1011,7 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_Me | |||
1045 | * @return NULL on error | 1011 | * @return NULL on error |
1046 | */ | 1012 | */ |
1047 | static char * | 1013 | static char * |
1048 | decompress (const char *input, | 1014 | decompress (const char *input, size_t inputSize, size_t outputSize) |
1049 | size_t inputSize, | ||
1050 | size_t outputSize) | ||
1051 | { | 1015 | { |
1052 | char *output; | 1016 | char *output; |
1053 | uLongf olen; | 1017 | uLongf olen; |
@@ -1056,14 +1020,14 @@ decompress (const char *input, | |||
1056 | output = GNUNET_malloc (olen); | 1020 | output = GNUNET_malloc (olen); |
1057 | if (Z_OK == uncompress ((Bytef *) output, | 1021 | if (Z_OK == uncompress ((Bytef *) output, |
1058 | &olen, (const Bytef *) input, inputSize)) | 1022 | &olen, (const Bytef *) input, inputSize)) |
1059 | { | 1023 | { |
1060 | return output; | 1024 | return output; |
1061 | } | 1025 | } |
1062 | else | 1026 | else |
1063 | { | 1027 | { |
1064 | GNUNET_free (output); | 1028 | GNUNET_free (output); |
1065 | return NULL; | 1029 | return NULL; |
1066 | } | 1030 | } |
1067 | } | 1031 | } |
1068 | 1032 | ||
1069 | 1033 | ||
@@ -1100,136 +1064,129 @@ GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size) | |||
1100 | 1064 | ||
1101 | if (size < sizeof (struct MetaDataHeader)) | 1065 | if (size < sizeof (struct MetaDataHeader)) |
1102 | return NULL; | 1066 | return NULL; |
1103 | memcpy (&hdr, | 1067 | memcpy (&hdr, input, sizeof (struct MetaDataHeader)); |
1104 | input, | ||
1105 | sizeof (struct MetaDataHeader)); | ||
1106 | version = ntohl (hdr.version) & HEADER_VERSION_MASK; | 1068 | version = ntohl (hdr.version) & HEADER_VERSION_MASK; |
1107 | compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0; | 1069 | compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0; |
1108 | 1070 | ||
1109 | if (version == 1) | 1071 | if (version == 1) |
1110 | return NULL; /* null pointer */ | 1072 | return NULL; /* null pointer */ |
1111 | if (version != 2) | 1073 | if (version != 2) |
1112 | { | 1074 | { |
1113 | GNUNET_break_op (0); /* unsupported version */ | 1075 | GNUNET_break_op (0); /* unsupported version */ |
1114 | return NULL; | 1076 | return NULL; |
1115 | } | 1077 | } |
1116 | 1078 | ||
1117 | ic = ntohl (hdr.entries); | 1079 | ic = ntohl (hdr.entries); |
1118 | dataSize = ntohl (hdr.size); | 1080 | dataSize = ntohl (hdr.size); |
1119 | if ((sizeof (struct MetaDataEntry) * ic) > dataSize) | 1081 | if ((sizeof (struct MetaDataEntry) * ic) > dataSize) |
1120 | { | 1082 | { |
1121 | GNUNET_break_op (0); | 1083 | GNUNET_break_op (0); |
1122 | return NULL; | 1084 | return NULL; |
1123 | } | 1085 | } |
1124 | 1086 | ||
1125 | if (compressed) | 1087 | if (compressed) |
1088 | { | ||
1089 | if (dataSize >= GNUNET_MAX_MALLOC_CHECKED) | ||
1126 | { | 1090 | { |
1127 | if (dataSize >= GNUNET_MAX_MALLOC_CHECKED) | 1091 | /* make sure we don't blow our memory limit because of a mal-formed |
1128 | { | 1092 | * message... */ |
1129 | /* make sure we don't blow our memory limit because of a mal-formed | 1093 | GNUNET_break_op (0); |
1130 | message... */ | 1094 | return NULL; |
1131 | GNUNET_break_op (0); | 1095 | } |
1132 | return NULL; | 1096 | data = |
1133 | } | ||
1134 | data = | ||
1135 | decompress ((const char *) &input[sizeof (struct MetaDataHeader)], | 1097 | decompress ((const char *) &input[sizeof (struct MetaDataHeader)], |
1136 | size - sizeof (struct MetaDataHeader), dataSize); | 1098 | size - sizeof (struct MetaDataHeader), dataSize); |
1137 | if (data == NULL) | 1099 | if (data == NULL) |
1138 | { | 1100 | { |
1139 | GNUNET_break_op (0); | 1101 | GNUNET_break_op (0); |
1140 | return NULL; | 1102 | return NULL; |
1141 | } | ||
1142 | cdata = data; | ||
1143 | } | 1103 | } |
1104 | cdata = data; | ||
1105 | } | ||
1144 | else | 1106 | else |
1107 | { | ||
1108 | data = NULL; | ||
1109 | cdata = (const char *) &input[sizeof (struct MetaDataHeader)]; | ||
1110 | if (dataSize != size - sizeof (struct MetaDataHeader)) | ||
1145 | { | 1111 | { |
1146 | data = NULL; | 1112 | GNUNET_break_op (0); |
1147 | cdata = (const char *) &input[sizeof (struct MetaDataHeader)]; | 1113 | return NULL; |
1148 | if (dataSize != size - sizeof (struct MetaDataHeader)) | ||
1149 | { | ||
1150 | GNUNET_break_op (0); | ||
1151 | return NULL; | ||
1152 | } | ||
1153 | } | 1114 | } |
1115 | } | ||
1154 | 1116 | ||
1155 | md = GNUNET_CONTAINER_meta_data_create (); | 1117 | md = GNUNET_CONTAINER_meta_data_create (); |
1156 | left = dataSize - ic * sizeof (struct MetaDataEntry); | 1118 | left = dataSize - ic * sizeof (struct MetaDataEntry); |
1157 | mdata = &cdata[ic * sizeof (struct MetaDataEntry)]; | 1119 | mdata = &cdata[ic * sizeof (struct MetaDataEntry)]; |
1158 | for (i=0;i<ic;i++) | 1120 | for (i = 0; i < ic; i++) |
1121 | { | ||
1122 | memcpy (&ent, | ||
1123 | &cdata[i * sizeof (struct MetaDataEntry)], | ||
1124 | sizeof (struct MetaDataEntry)); | ||
1125 | format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format); | ||
1126 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && | ||
1127 | (format != EXTRACTOR_METAFORMAT_C_STRING) && | ||
1128 | (format != EXTRACTOR_METAFORMAT_BINARY)) | ||
1159 | { | 1129 | { |
1160 | memcpy (&ent, | 1130 | GNUNET_break_op (0); |
1161 | &cdata[i * sizeof(struct MetaDataEntry)], | 1131 | break; |
1162 | sizeof (struct MetaDataEntry)); | 1132 | } |
1163 | format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format); | 1133 | dlen = ntohl (ent.data_size); |
1164 | if ( (format != EXTRACTOR_METAFORMAT_UTF8) && | 1134 | plen = ntohl (ent.plugin_name_len); |
1165 | (format != EXTRACTOR_METAFORMAT_C_STRING) && | 1135 | mlen = ntohl (ent.mime_type_len); |
1166 | (format != EXTRACTOR_METAFORMAT_BINARY) ) | 1136 | if (dlen > left) |
1167 | { | 1137 | { |
1168 | GNUNET_break_op (0); | 1138 | GNUNET_break_op (0); |
1169 | break; | 1139 | break; |
1170 | } | 1140 | } |
1171 | dlen = ntohl (ent.data_size); | 1141 | left -= dlen; |
1172 | plen = ntohl (ent.plugin_name_len); | 1142 | meta_data = &mdata[left]; |
1173 | mlen = ntohl (ent.mime_type_len); | 1143 | if ((format == EXTRACTOR_METAFORMAT_UTF8) || |
1174 | if (dlen > left) | 1144 | (format == EXTRACTOR_METAFORMAT_C_STRING)) |
1175 | { | 1145 | { |
1176 | GNUNET_break_op (0); | 1146 | if ((dlen == 0) || (mdata[left + dlen - 1] != '\0')) |
1177 | break; | 1147 | { |
1178 | } | 1148 | GNUNET_break_op (0); |
1179 | left -= dlen; | 1149 | break; |
1180 | meta_data = &mdata[left]; | 1150 | } |
1181 | if ( (format == EXTRACTOR_METAFORMAT_UTF8) || | 1151 | } |
1182 | (format == EXTRACTOR_METAFORMAT_C_STRING) ) | 1152 | if (plen > left) |
1183 | { | 1153 | { |
1184 | if ( (dlen == 0) || | 1154 | GNUNET_break_op (0); |
1185 | (mdata[left + dlen - 1] != '\0') ) | 1155 | break; |
1186 | { | 1156 | } |
1187 | GNUNET_break_op (0); | 1157 | left -= plen; |
1188 | break; | 1158 | if ((plen > 0) && (mdata[left + plen - 1] != '\0')) |
1189 | } | 1159 | { |
1190 | } | 1160 | GNUNET_break_op (0); |
1191 | if (plen > left) | 1161 | break; |
1192 | { | 1162 | } |
1193 | GNUNET_break_op (0); | 1163 | if (plen == 0) |
1194 | break; | 1164 | plugin_name = NULL; |
1195 | } | 1165 | else |
1196 | left -= plen; | 1166 | plugin_name = &mdata[left]; |
1197 | if ( (plen > 0) && | 1167 | |
1198 | (mdata[left + plen - 1] != '\0') ) | 1168 | if (mlen > left) |
1199 | { | 1169 | { |
1200 | GNUNET_break_op (0); | 1170 | GNUNET_break_op (0); |
1201 | break; | 1171 | break; |
1202 | } | 1172 | } |
1203 | if (plen == 0) | 1173 | left -= mlen; |
1204 | plugin_name = NULL; | 1174 | if ((mlen > 0) && (mdata[left + mlen - 1] != '\0')) |
1205 | else | 1175 | { |
1206 | plugin_name = &mdata[left]; | 1176 | GNUNET_break_op (0); |
1207 | 1177 | break; | |
1208 | if (mlen > left) | ||
1209 | { | ||
1210 | GNUNET_break_op (0); | ||
1211 | break; | ||
1212 | } | ||
1213 | left -= mlen; | ||
1214 | if ( (mlen > 0) && | ||
1215 | (mdata[left + mlen - 1] != '\0') ) | ||
1216 | { | ||
1217 | GNUNET_break_op (0); | ||
1218 | break; | ||
1219 | } | ||
1220 | if (mlen == 0) | ||
1221 | mime_type = NULL; | ||
1222 | else | ||
1223 | mime_type = &mdata[left]; | ||
1224 | GNUNET_CONTAINER_meta_data_insert (md, | ||
1225 | plugin_name, | ||
1226 | (enum EXTRACTOR_MetaType) ntohl (ent.type), | ||
1227 | format, | ||
1228 | mime_type, | ||
1229 | meta_data, | ||
1230 | dlen); | ||
1231 | } | 1178 | } |
1232 | GNUNET_free_non_null (data); | 1179 | if (mlen == 0) |
1180 | mime_type = NULL; | ||
1181 | else | ||
1182 | mime_type = &mdata[left]; | ||
1183 | GNUNET_CONTAINER_meta_data_insert (md, | ||
1184 | plugin_name, | ||
1185 | (enum EXTRACTOR_MetaType) | ||
1186 | ntohl (ent.type), format, mime_type, | ||
1187 | meta_data, dlen); | ||
1188 | } | ||
1189 | GNUNET_free_non_null (data); | ||
1233 | return md; | 1190 | return md; |
1234 | } | 1191 | } |
1235 | 1192 | ||
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index 579573bdb..9635af17d 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c | |||
@@ -107,13 +107,13 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap | |||
107 | struct MapEntry *e; | 107 | struct MapEntry *e; |
108 | 108 | ||
109 | for (i = 0; i < map->map_length; i++) | 109 | for (i = 0; i < map->map_length; i++) |
110 | { | ||
111 | while (NULL != (e = map->map[i])) | ||
110 | { | 112 | { |
111 | while (NULL != (e = map->map[i])) | 113 | map->map[i] = e->next; |
112 | { | 114 | GNUNET_free (e); |
113 | map->map[i] = e->next; | ||
114 | GNUNET_free (e); | ||
115 | } | ||
116 | } | 115 | } |
116 | } | ||
117 | GNUNET_free (map->map); | 117 | GNUNET_free (map->map); |
118 | GNUNET_free (map); | 118 | GNUNET_free (map); |
119 | } | 119 | } |
@@ -130,7 +130,7 @@ static unsigned int | |||
130 | idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, | 130 | idx_of (const struct GNUNET_CONTAINER_MultiHashMap *m, |
131 | const GNUNET_HashCode * key) | 131 | const GNUNET_HashCode * key) |
132 | { | 132 | { |
133 | GNUNET_assert (m!=NULL); | 133 | GNUNET_assert (m != NULL); |
134 | return (*(unsigned int *) key) % m->map_length; | 134 | return (*(unsigned int *) key) % m->map_length; |
135 | } | 135 | } |
136 | 136 | ||
@@ -167,11 +167,11 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap | |||
167 | 167 | ||
168 | e = map->map[idx_of (map, key)]; | 168 | e = map->map[idx_of (map, key)]; |
169 | while (e != NULL) | 169 | while (e != NULL) |
170 | { | 170 | { |
171 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 171 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
172 | return e->value; | 172 | return e->value; |
173 | e = e->next; | 173 | e = e->next; |
174 | } | 174 | } |
175 | return NULL; | 175 | return NULL; |
176 | } | 176 | } |
177 | 177 | ||
@@ -198,22 +198,22 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct | |||
198 | GNUNET_HashCode kc; | 198 | GNUNET_HashCode kc; |
199 | 199 | ||
200 | count = 0; | 200 | count = 0; |
201 | GNUNET_assert(map != NULL); | 201 | GNUNET_assert (map != NULL); |
202 | for (i = 0; i < map->map_length; i++) | 202 | for (i = 0; i < map->map_length; i++) |
203 | { | ||
204 | n = map->map[i]; | ||
205 | while (NULL != (e = n)) | ||
203 | { | 206 | { |
204 | n = map->map[i]; | 207 | n = e->next; |
205 | while (NULL != (e = n)) | 208 | if (NULL != it) |
206 | { | 209 | { |
207 | n = e->next; | 210 | kc = e->key; |
208 | if (NULL != it) | 211 | if (GNUNET_OK != it (it_cls, &kc, e->value)) |
209 | { | 212 | return GNUNET_SYSERR; |
210 | kc = e->key; | 213 | } |
211 | if (GNUNET_OK != it (it_cls, &kc, e->value)) | 214 | count++; |
212 | return GNUNET_SYSERR; | ||
213 | } | ||
214 | count++; | ||
215 | } | ||
216 | } | 215 | } |
216 | } | ||
217 | return count; | 217 | return count; |
218 | } | 218 | } |
219 | 219 | ||
@@ -242,21 +242,21 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap | |||
242 | p = NULL; | 242 | p = NULL; |
243 | e = map->map[i]; | 243 | e = map->map[i]; |
244 | while (e != NULL) | 244 | while (e != NULL) |
245 | { | ||
246 | if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && | ||
247 | (value == e->value)) | ||
245 | { | 248 | { |
246 | if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && | 249 | if (p == NULL) |
247 | (value == e->value)) | 250 | map->map[i] = e->next; |
248 | { | 251 | else |
249 | if (p == NULL) | 252 | p->next = e->next; |
250 | map->map[i] = e->next; | 253 | GNUNET_free (e); |
251 | else | 254 | map->size--; |
252 | p->next = e->next; | 255 | return GNUNET_YES; |
253 | GNUNET_free (e); | ||
254 | map->size--; | ||
255 | return GNUNET_YES; | ||
256 | } | ||
257 | p = e; | ||
258 | e = e->next; | ||
259 | } | 256 | } |
257 | p = e; | ||
258 | e = e->next; | ||
259 | } | ||
260 | return GNUNET_NO; | 260 | return GNUNET_NO; |
261 | } | 261 | } |
262 | 262 | ||
@@ -283,27 +283,27 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap | |||
283 | p = NULL; | 283 | p = NULL; |
284 | e = map->map[i]; | 284 | e = map->map[i]; |
285 | while (e != NULL) | 285 | while (e != NULL) |
286 | { | ||
287 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | ||
286 | { | 288 | { |
287 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 289 | if (p == NULL) |
288 | { | 290 | map->map[i] = e->next; |
289 | if (p == NULL) | ||
290 | map->map[i] = e->next; | ||
291 | else | ||
292 | p->next = e->next; | ||
293 | GNUNET_free (e); | ||
294 | map->size--; | ||
295 | if (p == NULL) | ||
296 | e = map->map[i]; | ||
297 | else | ||
298 | e = p->next; | ||
299 | ret++; | ||
300 | } | ||
301 | else | 291 | else |
302 | { | 292 | p->next = e->next; |
303 | p = e; | 293 | GNUNET_free (e); |
304 | e = e->next; | 294 | map->size--; |
305 | } | 295 | if (p == NULL) |
296 | e = map->map[i]; | ||
297 | else | ||
298 | e = p->next; | ||
299 | ret++; | ||
300 | } | ||
301 | else | ||
302 | { | ||
303 | p = e; | ||
304 | e = e->next; | ||
306 | } | 305 | } |
306 | } | ||
307 | return ret; | 307 | return ret; |
308 | } | 308 | } |
309 | 309 | ||
@@ -326,11 +326,11 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
326 | 326 | ||
327 | e = map->map[idx_of (map, key)]; | 327 | e = map->map[idx_of (map, key)]; |
328 | while (e != NULL) | 328 | while (e != NULL) |
329 | { | 329 | { |
330 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 330 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
331 | return GNUNET_YES; | 331 | return GNUNET_YES; |
332 | e = e->next; | 332 | e = e->next; |
333 | } | 333 | } |
334 | return GNUNET_NO; | 334 | return GNUNET_NO; |
335 | } | 335 | } |
336 | 336 | ||
@@ -345,22 +345,23 @@ GNUNET_CONTAINER_multihashmap_contains (const struct | |||
345 | * @return GNUNET_YES if such a value exists, | 345 | * @return GNUNET_YES if such a value exists, |
346 | * GNUNET_NO if not | 346 | * GNUNET_NO if not |
347 | */ | 347 | */ |
348 | int GNUNET_CONTAINER_multihashmap_contains_value (const struct | 348 | int |
349 | GNUNET_CONTAINER_MultiHashMap | 349 | GNUNET_CONTAINER_multihashmap_contains_value (const struct |
350 | *map, | 350 | GNUNET_CONTAINER_MultiHashMap |
351 | const GNUNET_HashCode * key, | 351 | *map, |
352 | const void *value) | 352 | const GNUNET_HashCode * key, |
353 | const void *value) | ||
353 | { | 354 | { |
354 | struct MapEntry *e; | 355 | struct MapEntry *e; |
355 | 356 | ||
356 | e = map->map[idx_of (map, key)]; | 357 | e = map->map[idx_of (map, key)]; |
357 | while (e != NULL) | 358 | while (e != NULL) |
358 | { | 359 | { |
359 | if ( (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && | 360 | if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && |
360 | (e->value == value) ) | 361 | (e->value == value)) |
361 | return GNUNET_YES; | 362 | return GNUNET_YES; |
362 | e = e->next; | 363 | e = e->next; |
363 | } | 364 | } |
364 | return GNUNET_NO; | 365 | return GNUNET_NO; |
365 | } | 366 | } |
366 | 367 | ||
@@ -388,15 +389,15 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map) | |||
388 | map->map_length = new_len; | 389 | map->map_length = new_len; |
389 | map->map = new_map; | 390 | map->map = new_map; |
390 | for (i = 0; i < old_len; i++) | 391 | for (i = 0; i < old_len; i++) |
392 | { | ||
393 | while (NULL != (e = old_map[i])) | ||
391 | { | 394 | { |
392 | while (NULL != (e = old_map[i])) | 395 | old_map[i] = e->next; |
393 | { | 396 | idx = idx_of (map, &e->key); |
394 | old_map[i] = e->next; | 397 | e->next = new_map[idx]; |
395 | idx = idx_of (map, &e->key); | 398 | new_map[idx] = e; |
396 | e->next = new_map[idx]; | ||
397 | new_map[idx] = e; | ||
398 | } | ||
399 | } | 399 | } |
400 | } | ||
400 | GNUNET_free (old_map); | 401 | GNUNET_free (old_map); |
401 | } | 402 | } |
402 | 403 | ||
@@ -417,8 +418,7 @@ int | |||
417 | GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | 418 | GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, |
418 | const GNUNET_HashCode * key, | 419 | const GNUNET_HashCode * key, |
419 | void *value, | 420 | void *value, |
420 | enum GNUNET_CONTAINER_MultiHashMapOption | 421 | enum GNUNET_CONTAINER_MultiHashMapOption opt) |
421 | opt) | ||
422 | { | 422 | { |
423 | struct MapEntry *e; | 423 | struct MapEntry *e; |
424 | unsigned int i; | 424 | unsigned int i; |
@@ -426,25 +426,25 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, | |||
426 | i = idx_of (map, key); | 426 | i = idx_of (map, key); |
427 | if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && | 427 | if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && |
428 | (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 428 | (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
429 | { | ||
430 | e = map->map[i]; | ||
431 | while (e != NULL) | ||
429 | { | 432 | { |
430 | e = map->map[i]; | 433 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
431 | while (e != NULL) | 434 | { |
432 | { | 435 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) |
433 | if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 436 | return GNUNET_SYSERR; |
434 | { | 437 | e->value = value; |
435 | if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) | 438 | return GNUNET_NO; |
436 | return GNUNET_SYSERR; | 439 | } |
437 | e->value = value; | 440 | e = e->next; |
438 | return GNUNET_NO; | ||
439 | } | ||
440 | e = e->next; | ||
441 | } | ||
442 | } | 441 | } |
442 | } | ||
443 | if (map->size / 3 >= map->map_length / 4) | 443 | if (map->size / 3 >= map->map_length / 4) |
444 | { | 444 | { |
445 | grow (map); | 445 | grow (map); |
446 | i = idx_of (map, key); | 446 | i = idx_of (map, key); |
447 | } | 447 | } |
448 | e = GNUNET_malloc (sizeof (struct MapEntry)); | 448 | e = GNUNET_malloc (sizeof (struct MapEntry)); |
449 | e->key = *key; | 449 | e->key = *key; |
450 | e->value = value; | 450 | e->value = value; |
@@ -479,14 +479,14 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct | |||
479 | count = 0; | 479 | count = 0; |
480 | n = map->map[idx_of (map, key)]; | 480 | n = map->map[idx_of (map, key)]; |
481 | while (NULL != (e = n)) | 481 | while (NULL != (e = n)) |
482 | { | 482 | { |
483 | n = e->next; | 483 | n = e->next; |
484 | if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) | 484 | if (0 != memcmp (key, &e->key, sizeof (GNUNET_HashCode))) |
485 | continue; | 485 | continue; |
486 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) | 486 | if ((it != NULL) && (GNUNET_OK != it (it_cls, key, e->value))) |
487 | return GNUNET_SYSERR; | 487 | return GNUNET_SYSERR; |
488 | count++; | 488 | count++; |
489 | } | 489 | } |
490 | return count; | 490 | return count; |
491 | } | 491 | } |
492 | 492 | ||
diff --git a/src/util/container_slist.c b/src/util/container_slist.c index cecc74ce2..c06d70e91 100644 --- a/src/util/container_slist.c +++ b/src/util/container_slist.c | |||
@@ -113,16 +113,16 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp, | |||
113 | struct GNUNET_CONTAINER_SList_Elem *e; | 113 | struct GNUNET_CONTAINER_SList_Elem *e; |
114 | 114 | ||
115 | if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT) | 115 | if (disp == GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT) |
116 | { | 116 | { |
117 | e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); | 117 | e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); |
118 | memcpy (&e[1], buf, len); | 118 | memcpy (&e[1], buf, len); |
119 | e->elem = (void *) &e[1]; | 119 | e->elem = (void *) &e[1]; |
120 | } | 120 | } |
121 | else | 121 | else |
122 | { | 122 | { |
123 | e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); | 123 | e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); |
124 | e->elem = (void *) buf; | 124 | e->elem = (void *) buf; |
125 | } | 125 | } |
126 | e->disp = disp; | 126 | e->disp = disp; |
127 | e->len = len; | 127 | e->len = len; |
128 | return e; | 128 | return e; |
@@ -146,7 +146,8 @@ GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, | |||
146 | e = create_elem (disp, buf, len); | 146 | e = create_elem (disp, buf, len); |
147 | e->next = l->head; | 147 | e->next = l->head; |
148 | l->head = e; | 148 | l->head = e; |
149 | if (l->tail == NULL) l->tail = e; | 149 | if (l->tail == NULL) |
150 | l->tail = e; | ||
150 | l->length++; | 151 | l->length++; |
151 | } | 152 | } |
152 | 153 | ||
@@ -159,8 +160,8 @@ GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, | |||
159 | */ | 160 | */ |
160 | void | 161 | void |
161 | GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, | 162 | GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, |
162 | enum GNUNET_CONTAINER_SListDisposition disp, | 163 | enum GNUNET_CONTAINER_SListDisposition disp, |
163 | const void *buf, size_t len) | 164 | const void *buf, size_t len) |
164 | { | 165 | { |
165 | struct GNUNET_CONTAINER_SList_Elem *e; | 166 | struct GNUNET_CONTAINER_SList_Elem *e; |
166 | 167 | ||
@@ -180,19 +181,22 @@ GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, | |||
180 | * @param src source | 181 | * @param src source |
181 | */ | 182 | */ |
182 | void | 183 | void |
183 | GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, struct GNUNET_CONTAINER_SList *src) | 184 | GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, |
185 | struct GNUNET_CONTAINER_SList *src) | ||
184 | { | 186 | { |
185 | struct GNUNET_CONTAINER_SList_Iterator *i; | 187 | struct GNUNET_CONTAINER_SList_Iterator *i; |
186 | 188 | ||
187 | for (i = GNUNET_CONTAINER_slist_begin (src); GNUNET_CONTAINER_slist_end (i) != | 189 | for (i = GNUNET_CONTAINER_slist_begin (src); GNUNET_CONTAINER_slist_end (i) != |
188 | GNUNET_YES; GNUNET_CONTAINER_slist_next (i)) | 190 | GNUNET_YES; GNUNET_CONTAINER_slist_next (i)) |
189 | 191 | ||
190 | { | 192 | { |
191 | GNUNET_CONTAINER_slist_add (dst, | 193 | GNUNET_CONTAINER_slist_add (dst, |
192 | (i->elem->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) ? GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC | 194 | (i->elem->disp == |
193 | : GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, i->elem->elem, | 195 | GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC) ? |
194 | i->elem->len); | 196 | GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC : |
195 | } | 197 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
198 | i->elem->elem, i->elem->len); | ||
199 | } | ||
196 | GNUNET_CONTAINER_slist_iter_destroy (i); | 200 | GNUNET_CONTAINER_slist_iter_destroy (i); |
197 | } | 201 | } |
198 | 202 | ||
@@ -249,13 +253,13 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l) | |||
249 | 253 | ||
250 | e = l->head; | 254 | e = l->head; |
251 | while (e != NULL) | 255 | while (e != NULL) |
252 | { | 256 | { |
253 | n = e->next; | 257 | n = e->next; |
254 | if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) | 258 | if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) |
255 | GNUNET_free (e->elem); | 259 | GNUNET_free (e->elem); |
256 | GNUNET_free (e); | 260 | GNUNET_free (e); |
257 | e = n; | 261 | e = n; |
258 | } | 262 | } |
259 | l->head = NULL; | 263 | l->head = NULL; |
260 | l->tail = NULL; | 264 | l->tail = NULL; |
261 | l->length = 0; | 265 | l->length = 0; |
@@ -394,8 +398,7 @@ GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, | |||
394 | * @param i iterator | 398 | * @param i iterator |
395 | */ | 399 | */ |
396 | void | 400 | void |
397 | GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator | 401 | GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i) |
398 | *i) | ||
399 | { | 402 | { |
400 | GNUNET_free (i); | 403 | GNUNET_free (i); |
401 | } | 404 | } |
diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c index e26b59abe..200c367c1 100644 --- a/src/util/crypto_aes.c +++ b/src/util/crypto_aes.c | |||
@@ -39,7 +39,7 @@ GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key) | |||
39 | gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH, | 39 | gcry_randomize (&key->key[0], GNUNET_CRYPTO_AES_KEY_LENGTH, |
40 | GCRY_STRONG_RANDOM); | 40 | GCRY_STRONG_RANDOM); |
41 | key->crc32 = | 41 | key->crc32 = |
42 | htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH)); | 42 | htonl (GNUNET_CRYPTO_crc32_n (key, GNUNET_CRYPTO_AES_KEY_LENGTH)); |
43 | } | 43 | } |
44 | 44 | ||
45 | /** | 45 | /** |
@@ -84,20 +84,19 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, | |||
84 | int rc; | 84 | int rc; |
85 | 85 | ||
86 | if (sessionkey->crc32 != | 86 | if (sessionkey->crc32 != |
87 | htonl (GNUNET_CRYPTO_crc32_n | 87 | htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) |
88 | (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) | 88 | { |
89 | { | 89 | GNUNET_break (0); |
90 | GNUNET_break (0); | 90 | return -1; |
91 | return -1; | 91 | } |
92 | } | ||
93 | GNUNET_assert (0 == gcry_cipher_open (&handle, | 92 | GNUNET_assert (0 == gcry_cipher_open (&handle, |
94 | GCRY_CIPHER_AES256, | 93 | GCRY_CIPHER_AES256, |
95 | GCRY_CIPHER_MODE_CFB, 0)); | 94 | GCRY_CIPHER_MODE_CFB, 0)); |
96 | rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); | 95 | rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); |
97 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 96 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); |
98 | rc = | 97 | rc = gcry_cipher_setiv (handle, iv, |
99 | gcry_cipher_setiv (handle, iv, | 98 | sizeof (struct |
100 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 99 | GNUNET_CRYPTO_AesInitializationVector)); |
101 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 100 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); |
102 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, block, len)); | 101 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, block, len)); |
103 | gcry_cipher_close (handle); | 102 | gcry_cipher_close (handle); |
@@ -127,23 +126,21 @@ GNUNET_CRYPTO_aes_decrypt (const void *block, | |||
127 | int rc; | 126 | int rc; |
128 | 127 | ||
129 | if (sessionkey->crc32 != | 128 | if (sessionkey->crc32 != |
130 | htonl (GNUNET_CRYPTO_crc32_n | 129 | htonl (GNUNET_CRYPTO_crc32_n (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) |
131 | (sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH))) | 130 | { |
132 | { | 131 | GNUNET_break (0); |
133 | GNUNET_break (0); | 132 | return -1; |
134 | return -1; | 133 | } |
135 | } | ||
136 | GNUNET_assert (0 == gcry_cipher_open (&handle, | 134 | GNUNET_assert (0 == gcry_cipher_open (&handle, |
137 | GCRY_CIPHER_AES256, | 135 | GCRY_CIPHER_AES256, |
138 | GCRY_CIPHER_MODE_CFB, 0)); | 136 | GCRY_CIPHER_MODE_CFB, 0)); |
139 | rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); | 137 | rc = gcry_cipher_setkey (handle, sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); |
140 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 138 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); |
141 | rc = | 139 | rc = gcry_cipher_setiv (handle, iv, |
142 | gcry_cipher_setiv (handle, iv, | 140 | sizeof (struct |
143 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 141 | GNUNET_CRYPTO_AesInitializationVector)); |
144 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | 142 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); |
145 | GNUNET_assert (0 == | 143 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, result, size, block, size)); |
146 | gcry_cipher_decrypt (handle, result, size, block, size)); | ||
147 | gcry_cipher_close (handle); | 144 | gcry_cipher_close (handle); |
148 | return size; | 145 | return size; |
149 | } | 146 | } |
@@ -158,9 +155,8 @@ GNUNET_CRYPTO_aes_decrypt (const void *block, | |||
158 | */ | 155 | */ |
159 | void | 156 | void |
160 | GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | 157 | GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
161 | const struct GNUNET_CRYPTO_AesSessionKey *skey, | 158 | const struct GNUNET_CRYPTO_AesSessionKey *skey, |
162 | const void *salt, size_t salt_len, | 159 | const void *salt, size_t salt_len, ...) |
163 | ...) | ||
164 | { | 160 | { |
165 | va_list argp; | 161 | va_list argp; |
166 | 162 | ||
@@ -179,12 +175,11 @@ GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | |||
179 | */ | 175 | */ |
180 | void | 176 | void |
181 | GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, | 177 | GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
182 | const struct GNUNET_CRYPTO_AesSessionKey *skey, | 178 | const struct GNUNET_CRYPTO_AesSessionKey *skey, |
183 | const void *salt, size_t salt_len, | 179 | const void *salt, size_t salt_len, va_list argp) |
184 | va_list argp) | ||
185 | { | 180 | { |
186 | GNUNET_CRYPTO_kdf_v (iv->iv, sizeof(iv->iv), salt, salt_len, skey->key, | 181 | GNUNET_CRYPTO_kdf_v (iv->iv, sizeof (iv->iv), salt, salt_len, skey->key, |
187 | sizeof(skey->key), argp); | 182 | sizeof (skey->key), argp); |
188 | } | 183 | } |
189 | 184 | ||
190 | /* end of crypto_aes.c */ | 185 | /* end of crypto_aes.c */ |
diff --git a/src/util/crypto_crc.c b/src/util/crypto_crc.c index 8f5cfc800..543bc4c65 100644 --- a/src/util/crypto_crc.c +++ b/src/util/crypto_crc.c | |||
@@ -52,7 +52,7 @@ static uLong crc_table[256]; | |||
52 | * with the ccorrect final value. Thus, it is safe to call | 52 | * with the ccorrect final value. Thus, it is safe to call |
53 | * even on a table that someone else is using concurrently. | 53 | * even on a table that someone else is using concurrently. |
54 | */ | 54 | */ |
55 | static void | 55 | static void |
56 | crc_init () | 56 | crc_init () |
57 | { | 57 | { |
58 | static int once; | 58 | static int once; |
@@ -64,12 +64,12 @@ crc_init () | |||
64 | once = 1; | 64 | once = 1; |
65 | crc_table[0] = 0; | 65 | crc_table[0] = 0; |
66 | for (i = 128; i; i >>= 1) | 66 | for (i = 128; i; i >>= 1) |
67 | { | 67 | { |
68 | h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0); | 68 | h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0); |
69 | /* h is now crc_table[i] */ | 69 | /* h is now crc_table[i] */ |
70 | for (j = 0; j < 256; j += 2 * i) | 70 | for (j = 0; j < 256; j += 2 * i) |
71 | crc_table[i + j] = crc_table[j] ^ h; | 71 | crc_table[i + j] = crc_table[j] ^ h; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | /* | 75 | /* |
@@ -105,6 +105,7 @@ int32_t | |||
105 | GNUNET_CRYPTO_crc32_n (const void *buf, size_t len) | 105 | GNUNET_CRYPTO_crc32_n (const void *buf, size_t len) |
106 | { | 106 | { |
107 | uLong crc; | 107 | uLong crc; |
108 | |||
108 | crc = crc32 (0L, Z_NULL, 0); | 109 | crc = crc32 (0L, Z_NULL, 0); |
109 | crc = crc32 (crc, (char *) buf, len); | 110 | crc = crc32 (crc, (char *) buf, len); |
110 | return crc; | 111 | return crc; |
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 670f5e73a..c693ed081 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -115,8 +115,8 @@ struct GNUNET_CRYPTO_FileHashContext | |||
115 | * and free associated resources. | 115 | * and free associated resources. |
116 | */ | 116 | */ |
117 | static void | 117 | static void |
118 | file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, | 118 | file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, |
119 | const GNUNET_HashCode * res) | 119 | const GNUNET_HashCode * res) |
120 | { | 120 | { |
121 | fhc->callback (fhc->callback_cls, res); | 121 | fhc->callback (fhc->callback_cls, res); |
122 | GNUNET_free (fhc->filename); | 122 | GNUNET_free (fhc->filename); |
@@ -146,22 +146,20 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
146 | if (fhc->fsize - fhc->offset < delta) | 146 | if (fhc->fsize - fhc->offset < delta) |
147 | delta = fhc->fsize - fhc->offset; | 147 | delta = fhc->fsize - fhc->offset; |
148 | if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) | 148 | if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) |
149 | { | 149 | { |
150 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 150 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); |
151 | "read", fhc->filename); | 151 | file_hash_finish (fhc, NULL); |
152 | file_hash_finish (fhc, NULL); | 152 | return; |
153 | return; | 153 | } |
154 | } | ||
155 | gcry_md_write (fhc->md, fhc->buffer, delta); | 154 | gcry_md_write (fhc->md, fhc->buffer, delta); |
156 | fhc->offset += delta; | 155 | fhc->offset += delta; |
157 | if (fhc->offset == fhc->fsize) | 156 | if (fhc->offset == fhc->fsize) |
158 | { | 157 | { |
159 | res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); | 158 | res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); |
160 | file_hash_finish (fhc, res); | 159 | file_hash_finish (fhc, res); |
161 | return; | 160 | return; |
162 | } | 161 | } |
163 | fhc->task | 162 | fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc); |
164 | = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc); | ||
165 | } | 163 | } |
166 | 164 | ||
167 | 165 | ||
@@ -185,36 +183,36 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, | |||
185 | struct GNUNET_CRYPTO_FileHashContext *fhc; | 183 | struct GNUNET_CRYPTO_FileHashContext *fhc; |
186 | 184 | ||
187 | GNUNET_assert (blocksize > 0); | 185 | GNUNET_assert (blocksize > 0); |
188 | fhc = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize); | 186 | fhc = |
187 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_FileHashContext) + blocksize); | ||
189 | fhc->callback = callback; | 188 | fhc->callback = callback; |
190 | fhc->callback_cls = callback_cls; | 189 | fhc->callback_cls = callback_cls; |
191 | fhc->buffer = (unsigned char *) &fhc[1]; | 190 | fhc->buffer = (unsigned char *) &fhc[1]; |
192 | fhc->filename = GNUNET_strdup (filename); | 191 | fhc->filename = GNUNET_strdup (filename); |
193 | if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0)) | 192 | if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->md, GCRY_MD_SHA512, 0)) |
194 | { | 193 | { |
195 | GNUNET_break (0); | 194 | GNUNET_break (0); |
196 | GNUNET_free (fhc); | 195 | GNUNET_free (fhc); |
197 | return NULL; | 196 | return NULL; |
198 | } | 197 | } |
199 | fhc->bsize = blocksize; | 198 | fhc->bsize = blocksize; |
200 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) | 199 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO)) |
201 | { | 200 | { |
202 | GNUNET_free (fhc->filename); | 201 | GNUNET_free (fhc->filename); |
203 | GNUNET_free (fhc); | 202 | GNUNET_free (fhc); |
204 | return NULL; | 203 | return NULL; |
205 | } | 204 | } |
206 | fhc->fh = GNUNET_DISK_file_open (filename, | 205 | fhc->fh = GNUNET_DISK_file_open (filename, |
207 | GNUNET_DISK_OPEN_READ, | 206 | GNUNET_DISK_OPEN_READ, |
208 | GNUNET_DISK_PERM_NONE); | 207 | GNUNET_DISK_PERM_NONE); |
209 | if (!fhc->fh) | 208 | if (!fhc->fh) |
210 | { | 209 | { |
211 | GNUNET_free (fhc->filename); | 210 | GNUNET_free (fhc->filename); |
212 | GNUNET_free (fhc); | 211 | GNUNET_free (fhc); |
213 | return NULL; | 212 | return NULL; |
214 | } | 213 | } |
215 | fhc->task | 214 | fhc->task |
216 | = GNUNET_SCHEDULER_add_with_priority (priority, | 215 | = GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); |
217 | &file_hash_task, fhc); | ||
218 | return fhc; | 216 | return fhc; |
219 | } | 217 | } |
220 | 218 | ||
@@ -278,23 +276,22 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | |||
278 | rpos = 0; | 276 | rpos = 0; |
279 | bits = 0; | 277 | bits = 0; |
280 | while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0)) | 278 | while ((rpos < sizeof (GNUNET_HashCode)) || (vbit > 0)) |
279 | { | ||
280 | if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5)) | ||
281 | { | ||
282 | bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */ | ||
283 | vbit += 8; | ||
284 | } | ||
285 | if (vbit < 5) | ||
281 | { | 286 | { |
282 | if ((rpos < sizeof (GNUNET_HashCode)) && (vbit < 5)) | 287 | bits <<= (5 - vbit); /* zero-padding */ |
283 | { | 288 | GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */ |
284 | bits = (bits << 8) | ((unsigned char *) block)[rpos++]; /* eat 8 more bits */ | 289 | vbit = 5; |
285 | vbit += 8; | ||
286 | } | ||
287 | if (vbit < 5) | ||
288 | { | ||
289 | bits <<= (5 - vbit); /* zero-padding */ | ||
290 | GNUNET_assert (vbit == 2); /* padding by 3: 512+3 mod 5 == 0 */ | ||
291 | vbit = 5; | ||
292 | } | ||
293 | GNUNET_assert (wpos < | ||
294 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); | ||
295 | result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31]; | ||
296 | vbit -= 5; | ||
297 | } | 290 | } |
291 | GNUNET_assert (wpos < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); | ||
292 | result->encoding[wpos++] = encTable__[(bits >> (vbit - 5)) & 31]; | ||
293 | vbit -= 5; | ||
294 | } | ||
298 | GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); | 295 | GNUNET_assert (wpos == sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); |
299 | GNUNET_assert (vbit == 0); | 296 | GNUNET_assert (vbit == 0); |
300 | result->encoding[wpos] = '\0'; | 297 | result->encoding[wpos] = '\0'; |
@@ -323,17 +320,17 @@ GNUNET_CRYPTO_hash_from_string (const char *enc, GNUNET_HashCode * result) | |||
323 | rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; | 320 | rpos = sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1; |
324 | bits = getValue__ (enc[--rpos]) >> 3; | 321 | bits = getValue__ (enc[--rpos]) >> 3; |
325 | while (wpos > 0) | 322 | while (wpos > 0) |
323 | { | ||
324 | GNUNET_assert (rpos > 0); | ||
325 | bits = (getValue__ (enc[--rpos]) << vbit) | bits; | ||
326 | vbit += 5; | ||
327 | if (vbit >= 8) | ||
326 | { | 328 | { |
327 | GNUNET_assert (rpos > 0); | 329 | ((unsigned char *) result)[--wpos] = (unsigned char) bits; |
328 | bits = (getValue__ (enc[--rpos]) << vbit) | bits; | 330 | bits >>= 8; |
329 | vbit += 5; | 331 | vbit -= 8; |
330 | if (vbit >= 8) | ||
331 | { | ||
332 | ((unsigned char *) result)[--wpos] = (unsigned char) bits; | ||
333 | bits >>= 8; | ||
334 | vbit -= 8; | ||
335 | } | ||
336 | } | 332 | } |
333 | } | ||
337 | GNUNET_assert (rpos == 0); | 334 | GNUNET_assert (rpos == 0); |
338 | GNUNET_assert (vbit == 0); | 335 | GNUNET_assert (vbit == 0); |
339 | return GNUNET_OK; | 336 | return GNUNET_OK; |
@@ -356,6 +353,7 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | |||
356 | { | 353 | { |
357 | unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; | 354 | unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; |
358 | unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; | 355 | unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; |
356 | |||
359 | return (x1 * x2); | 357 | return (x1 * x2); |
360 | } | 358 | } |
361 | 359 | ||
@@ -364,6 +362,7 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, | |||
364 | GNUNET_HashCode * result) | 362 | GNUNET_HashCode * result) |
365 | { | 363 | { |
366 | int i; | 364 | int i; |
365 | |||
367 | for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--) | 366 | for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--) |
368 | result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX); | 367 | result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX); |
369 | } | 368 | } |
@@ -374,31 +373,29 @@ GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | |||
374 | GNUNET_HashCode * result) | 373 | GNUNET_HashCode * result) |
375 | { | 374 | { |
376 | int i; | 375 | int i; |
377 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 376 | |
378 | i--) | 377 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
379 | result->bits[i] = b->bits[i] - a->bits[i]; | 378 | result->bits[i] = b->bits[i] - a->bits[i]; |
380 | } | 379 | } |
381 | 380 | ||
382 | void | 381 | void |
383 | GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | 382 | GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, |
384 | const GNUNET_HashCode * delta, | 383 | const GNUNET_HashCode * delta, GNUNET_HashCode * result) |
385 | GNUNET_HashCode * result) | ||
386 | { | 384 | { |
387 | int i; | 385 | int i; |
388 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 386 | |
389 | i--) | 387 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
390 | result->bits[i] = delta->bits[i] + a->bits[i]; | 388 | result->bits[i] = delta->bits[i] + a->bits[i]; |
391 | } | 389 | } |
392 | 390 | ||
393 | 391 | ||
394 | void | 392 | void |
395 | GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | 393 | GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, |
396 | const GNUNET_HashCode * b, | 394 | const GNUNET_HashCode * b, GNUNET_HashCode * result) |
397 | GNUNET_HashCode * result) | ||
398 | { | 395 | { |
399 | int i; | 396 | int i; |
400 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 397 | |
401 | i--) | 398 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
402 | result->bits[i] = a->bits[i] ^ b->bits[i]; | 399 | result->bits[i] = a->bits[i] ^ b->bits[i]; |
403 | } | 400 | } |
404 | 401 | ||
@@ -409,15 +406,14 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, | |||
409 | void | 406 | void |
410 | GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | 407 | GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, |
411 | struct GNUNET_CRYPTO_AesSessionKey *skey, | 408 | struct GNUNET_CRYPTO_AesSessionKey *skey, |
412 | struct GNUNET_CRYPTO_AesInitializationVector | 409 | struct GNUNET_CRYPTO_AesInitializationVector *iv) |
413 | *iv) | ||
414 | { | 410 | { |
415 | GNUNET_assert (sizeof (GNUNET_HashCode) >= | 411 | GNUNET_assert (sizeof (GNUNET_HashCode) >= |
416 | GNUNET_CRYPTO_AES_KEY_LENGTH + | 412 | GNUNET_CRYPTO_AES_KEY_LENGTH + |
417 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 413 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); |
418 | memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); | 414 | memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); |
419 | skey->crc32 = | 415 | skey->crc32 = |
420 | htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); | 416 | htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); |
421 | memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], | 417 | memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], |
422 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 418 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); |
423 | } | 419 | } |
@@ -430,8 +426,7 @@ GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | |||
430 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 426 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
431 | */ | 427 | */ |
432 | int | 428 | int |
433 | GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, | 429 | GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) |
434 | unsigned int bit) | ||
435 | { | 430 | { |
436 | GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode)); | 431 | GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode)); |
437 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; | 432 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; |
@@ -449,14 +444,15 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, | |||
449 | * | 444 | * |
450 | * @return the number of bits that match | 445 | * @return the number of bits that match |
451 | */ | 446 | */ |
452 | unsigned int | 447 | unsigned int |
453 | GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, | 448 | GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, |
454 | const GNUNET_HashCode *second) | 449 | const GNUNET_HashCode * second) |
455 | { | 450 | { |
456 | unsigned int i; | 451 | unsigned int i; |
457 | 452 | ||
458 | for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) | 453 | for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) |
459 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != GNUNET_CRYPTO_hash_get_bit (second, i)) | 454 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != |
455 | GNUNET_CRYPTO_hash_get_bit (second, i)) | ||
460 | return i; | 456 | return i; |
461 | return sizeof (GNUNET_HashCode) * 8; | 457 | return sizeof (GNUNET_HashCode) * 8; |
462 | } | 458 | } |
@@ -468,8 +464,7 @@ GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, | |||
468 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | 464 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. |
469 | */ | 465 | */ |
470 | int | 466 | int |
471 | GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | 467 | GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2) |
472 | const GNUNET_HashCode * h2) | ||
473 | { | 468 | { |
474 | unsigned int *i1; | 469 | unsigned int *i1; |
475 | unsigned int *i2; | 470 | unsigned int *i2; |
@@ -477,14 +472,13 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, | |||
477 | 472 | ||
478 | i1 = (unsigned int *) h1; | 473 | i1 = (unsigned int *) h1; |
479 | i2 = (unsigned int *) h2; | 474 | i2 = (unsigned int *) h2; |
480 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; | 475 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
481 | i--) | 476 | { |
482 | { | 477 | if (i1[i] > i2[i]) |
483 | if (i1[i] > i2[i]) | 478 | return 1; |
484 | return 1; | 479 | if (i1[i] < i2[i]) |
485 | if (i1[i] < i2[i]) | 480 | return -1; |
486 | return -1; | 481 | } |
487 | } | ||
488 | return 0; | 482 | return 0; |
489 | } | 483 | } |
490 | 484 | ||
@@ -504,14 +498,14 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | |||
504 | unsigned int d2; | 498 | unsigned int d2; |
505 | 499 | ||
506 | for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) | 500 | for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) |
507 | { | 501 | { |
508 | d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; | 502 | d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; |
509 | d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; | 503 | d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; |
510 | if (d1 > d2) | 504 | if (d1 > d2) |
511 | return 1; | 505 | return 1; |
512 | else if (d1 < d2) | 506 | else if (d1 < d2) |
513 | return -1; | 507 | return -1; |
514 | } | 508 | } |
515 | return 0; | 509 | return 0; |
516 | } | 510 | } |
517 | 511 | ||
@@ -525,11 +519,9 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | |||
525 | * @param ... pair of void * & size_t for context chunks, terminated by NULL | 519 | * @param ... pair of void * & size_t for context chunks, terminated by NULL |
526 | */ | 520 | */ |
527 | void | 521 | void |
528 | GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, | 522 | GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, |
529 | const struct GNUNET_CRYPTO_AesSessionKey *rkey, | 523 | const struct GNUNET_CRYPTO_AesSessionKey *rkey, |
530 | const void *salt, | 524 | const void *salt, size_t salt_len, ...) |
531 | size_t salt_len, | ||
532 | ...) | ||
533 | { | 525 | { |
534 | va_list argp; | 526 | va_list argp; |
535 | 527 | ||
@@ -548,18 +540,14 @@ GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, | |||
548 | * @param argp pair of void * & size_t for context chunks, terminated by NULL | 540 | * @param argp pair of void * & size_t for context chunks, terminated by NULL |
549 | */ | 541 | */ |
550 | void | 542 | void |
551 | GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key, | 543 | GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, |
552 | const struct GNUNET_CRYPTO_AesSessionKey *rkey, | 544 | const struct GNUNET_CRYPTO_AesSessionKey *rkey, |
553 | const void *salt, | 545 | const void *salt, |
554 | size_t salt_len, | 546 | size_t salt_len, va_list argp) |
555 | va_list argp) | ||
556 | { | 547 | { |
557 | GNUNET_CRYPTO_kdf_v (key->key, | 548 | GNUNET_CRYPTO_kdf_v (key->key, |
558 | sizeof(key->key), | 549 | sizeof (key->key), |
559 | salt, salt_len, | 550 | salt, salt_len, rkey->key, sizeof (rkey->key), argp); |
560 | rkey->key, | ||
561 | sizeof(rkey->key), | ||
562 | argp); | ||
563 | } | 551 | } |
564 | 552 | ||
565 | 553 | ||
@@ -571,23 +559,22 @@ GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key, | |||
571 | * @param plaintext_len length of plaintext | 559 | * @param plaintext_len length of plaintext |
572 | * @param hmac where to store the hmac | 560 | * @param hmac where to store the hmac |
573 | */ | 561 | */ |
574 | void | 562 | void |
575 | GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, | 563 | GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, |
576 | const void *plaintext, | 564 | const void *plaintext, |
577 | size_t plaintext_len, | 565 | size_t plaintext_len, GNUNET_HashCode * hmac) |
578 | GNUNET_HashCode *hmac) | ||
579 | { | 566 | { |
580 | gcry_md_hd_t md; | 567 | gcry_md_hd_t md; |
581 | const unsigned char *mc; | 568 | const unsigned char *mc; |
582 | 569 | ||
583 | GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md, | 570 | GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md, |
584 | GCRY_MD_SHA512, | 571 | GCRY_MD_SHA512, |
585 | GCRY_MD_FLAG_HMAC)); | 572 | GCRY_MD_FLAG_HMAC)); |
586 | gcry_md_setkey (md, key->key, sizeof(key->key)); | 573 | gcry_md_setkey (md, key->key, sizeof (key->key)); |
587 | gcry_md_write (md, plaintext, plaintext_len); | 574 | gcry_md_write (md, plaintext, plaintext_len); |
588 | mc = gcry_md_read (md, GCRY_MD_SHA512); | 575 | mc = gcry_md_read (md, GCRY_MD_SHA512); |
589 | if (mc != NULL) | 576 | if (mc != NULL) |
590 | memcpy (hmac->bits, mc, sizeof(hmac->bits)); | 577 | memcpy (hmac->bits, mc, sizeof (hmac->bits)); |
591 | gcry_md_close (md); | 578 | gcry_md_close (md); |
592 | } | 579 | } |
593 | 580 | ||
diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c index 494f3d0ab..d97f516fe 100644 --- a/src/util/crypto_hkdf.c +++ b/src/util/crypto_hkdf.c | |||
@@ -71,9 +71,8 @@ | |||
71 | * @return HMAC, freed by caller via gcry_md_close/_reset | 71 | * @return HMAC, freed by caller via gcry_md_close/_reset |
72 | */ | 72 | */ |
73 | static const void * | 73 | static const void * |
74 | doHMAC (gcry_md_hd_t mac, | 74 | doHMAC (gcry_md_hd_t mac, |
75 | const void *key, size_t key_len, | 75 | const void *key, size_t key_len, const void *buf, size_t buf_len) |
76 | const void *buf, size_t buf_len) | ||
77 | { | 76 | { |
78 | gcry_md_setkey (mac, key, key_len); | 77 | gcry_md_setkey (mac, key, key_len); |
79 | gcry_md_write (mac, buf, buf_len); | 78 | gcry_md_write (mac, buf, buf_len); |
@@ -92,38 +91,33 @@ doHMAC (gcry_md_hd_t mac, | |||
92 | * @return GNUNET_YES on success | 91 | * @return GNUNET_YES on success |
93 | */ | 92 | */ |
94 | static int | 93 | static int |
95 | getPRK (gcry_md_hd_t mac, | 94 | getPRK (gcry_md_hd_t mac, |
96 | const void *xts, size_t xts_len, | 95 | const void *xts, size_t xts_len, |
97 | const void *skm, size_t skm_len, | 96 | const void *skm, size_t skm_len, void *prk) |
98 | void *prk) | ||
99 | { | 97 | { |
100 | const void *ret; | 98 | const void *ret; |
101 | 99 | ||
102 | ret = doHMAC (mac, xts, xts_len, skm, skm_len); | 100 | ret = doHMAC (mac, xts, xts_len, skm, skm_len); |
103 | if (ret == NULL) | 101 | if (ret == NULL) |
104 | return GNUNET_SYSERR; | 102 | return GNUNET_SYSERR; |
105 | memcpy (prk, | 103 | memcpy (prk, ret, gcry_md_get_algo_dlen (gcry_md_get_algo (mac))); |
106 | ret, | ||
107 | gcry_md_get_algo_dlen (gcry_md_get_algo (mac))); | ||
108 | 104 | ||
109 | return GNUNET_YES; | 105 | return GNUNET_YES; |
110 | } | 106 | } |
111 | 107 | ||
112 | 108 | ||
113 | #if DEBUG_HKDF | 109 | #if DEBUG_HKDF |
114 | static void | 110 | static void |
115 | dump(const char *src, | 111 | dump (const char *src, const void *p, unsigned int l) |
116 | const void *p, | ||
117 | unsigned int l) | ||
118 | { | 112 | { |
119 | unsigned int i; | 113 | unsigned int i; |
120 | 114 | ||
121 | printf("\n%s: ", src); | 115 | printf ("\n%s: ", src); |
122 | for (i = 0; i < l; i++) | 116 | for (i = 0; i < l; i++) |
123 | { | 117 | { |
124 | printf("%2x", (int) ((const unsigned char *) p)[i]); | 118 | printf ("%2x", (int) ((const unsigned char *) p)[i]); |
125 | } | 119 | } |
126 | printf("\n"); | 120 | printf ("\n"); |
127 | } | 121 | } |
128 | #endif | 122 | #endif |
129 | 123 | ||
@@ -143,10 +137,9 @@ dump(const char *src, | |||
143 | */ | 137 | */ |
144 | int | 138 | int |
145 | GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, | 139 | GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, |
146 | int xtr_algo, int prf_algo, | 140 | int xtr_algo, int prf_algo, |
147 | const void *xts, size_t xts_len, | 141 | const void *xts, size_t xts_len, |
148 | const void *skm, size_t skm_len, | 142 | const void *skm, size_t skm_len, va_list argp) |
149 | va_list argp) | ||
150 | { | 143 | { |
151 | const void *hc; | 144 | const void *hc; |
152 | unsigned long i, t, d; | 145 | unsigned long i, t, d; |
@@ -161,10 +154,10 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, | |||
161 | if (k == 0) | 154 | if (k == 0) |
162 | return GNUNET_SYSERR; | 155 | return GNUNET_SYSERR; |
163 | 156 | ||
164 | if (gcry_md_open(&xtr, xtr_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR) | 157 | if (gcry_md_open (&xtr, xtr_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR) |
165 | return GNUNET_SYSERR; | 158 | return GNUNET_SYSERR; |
166 | 159 | ||
167 | if (gcry_md_open(&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR) | 160 | if (gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR) |
168 | { | 161 | { |
169 | gcry_md_close (xtr); | 162 | gcry_md_close (xtr); |
170 | return GNUNET_SYSERR; | 163 | return GNUNET_SYSERR; |
@@ -174,15 +167,15 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, | |||
174 | 167 | ||
175 | ctx_len = 0; | 168 | ctx_len = 0; |
176 | while (NULL != va_arg (args, void *)) | 169 | while (NULL != va_arg (args, void *)) |
177 | ctx_len += va_arg (args, size_t); | 170 | ctx_len += va_arg (args, size_t); |
178 | va_end(args); | 171 | |
172 | va_end (args); | ||
179 | 173 | ||
180 | memset (result, 0, out_len); | 174 | memset (result, 0, out_len); |
181 | if (getPRK (xtr, xts, xts_len, skm, skm_len, prk) | 175 | if (getPRK (xtr, xts, xts_len, skm, skm_len, prk) != GNUNET_YES) |
182 | != GNUNET_YES) | ||
183 | goto hkdf_error; | 176 | goto hkdf_error; |
184 | #if DEBUG_HKDF | 177 | #if DEBUG_HKDF |
185 | dump("PRK", prk, xtr_len); | 178 | dump ("PRK", prk, xtr_len); |
186 | #endif | 179 | #endif |
187 | 180 | ||
188 | t = out_len / k; | 181 | t = out_len / k; |
@@ -190,46 +183,44 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, | |||
190 | 183 | ||
191 | /* K(1) */ | 184 | /* K(1) */ |
192 | { | 185 | { |
193 | size_t plain_len = k + ctx_len + 1; | 186 | size_t plain_len = k + ctx_len + 1; |
194 | char plain[plain_len]; | 187 | char plain[plain_len]; |
195 | const void *ctx; | 188 | const void *ctx; |
196 | char *dst; | 189 | char *dst; |
197 | 190 | ||
198 | dst = plain + k; | 191 | dst = plain + k; |
199 | va_copy (args, argp); | 192 | va_copy (args, argp); |
200 | while ((ctx = va_arg (args, void *))) | 193 | while ((ctx = va_arg (args, void *))) |
201 | { | 194 | { |
202 | size_t len; | 195 | size_t len; |
203 | 196 | ||
204 | len = va_arg (args, size_t); | 197 | len = va_arg (args, size_t); |
205 | memcpy (dst, ctx, len); | 198 | memcpy (dst, ctx, len); |
206 | dst += len; | 199 | dst += len; |
207 | } | 200 | } |
208 | va_end (args); | 201 | va_end (args); |
209 | 202 | ||
210 | if (t > 0) | 203 | if (t > 0) |
211 | { | 204 | { |
212 | memset (plain + k + ctx_len, 1, 1); | 205 | memset (plain + k + ctx_len, 1, 1); |
213 | #if DEBUG_HKDF | 206 | #if DEBUG_HKDF |
214 | dump("K(1)", plain, plain_len); | 207 | dump ("K(1)", plain, plain_len); |
215 | #endif | 208 | #endif |
216 | hc = doHMAC (prf, | 209 | hc = doHMAC (prf, prk, xtr_len, &plain[k], ctx_len + 1); |
217 | prk, | ||
218 | xtr_len, &plain[k], ctx_len + 1); | ||
219 | if (hc == NULL) | 210 | if (hc == NULL) |
220 | goto hkdf_error; | 211 | goto hkdf_error; |
221 | memcpy (result, hc, k); | 212 | memcpy (result, hc, k); |
222 | result += k; | 213 | result += k; |
223 | } | 214 | } |
224 | 215 | ||
225 | /* K(i+1) */ | 216 | /* K(i+1) */ |
226 | for (i = 1; i < t; i++) | 217 | for (i = 1; i < t; i++) |
227 | { | 218 | { |
228 | memcpy (plain, result - k, k); | 219 | memcpy (plain, result - k, k); |
229 | memset (plain + k + ctx_len, i + 1, 1); | 220 | memset (plain + k + ctx_len, i + 1, 1); |
230 | gcry_md_reset (prf); | 221 | gcry_md_reset (prf); |
231 | #if DEBUG_HKDF | 222 | #if DEBUG_HKDF |
232 | dump("K(i+1)", plain, plain_len); | 223 | dump ("K(i+1)", plain, plain_len); |
233 | #endif | 224 | #endif |
234 | hc = doHMAC (prf, prk, xtr_len, plain, plain_len); | 225 | hc = doHMAC (prf, prk, xtr_len, plain, plain_len); |
235 | if (hc == NULL) | 226 | if (hc == NULL) |
@@ -238,18 +229,18 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, | |||
238 | result += k; | 229 | result += k; |
239 | } | 230 | } |
240 | 231 | ||
241 | /* K(t):d */ | 232 | /* K(t):d */ |
242 | if (d > 0) | 233 | if (d > 0) |
243 | { | 234 | { |
244 | if (t > 0) | 235 | if (t > 0) |
245 | { | 236 | { |
246 | memcpy (plain, result - k, k); | 237 | memcpy (plain, result - k, k); |
247 | i++; | 238 | i++; |
248 | } | 239 | } |
249 | memset (plain + k + ctx_len, i, 1); | 240 | memset (plain + k + ctx_len, i, 1); |
250 | gcry_md_reset (prf); | 241 | gcry_md_reset (prf); |
251 | #if DEBUG_HKDF | 242 | #if DEBUG_HKDF |
252 | dump("K(t):d", plain, plain_len); | 243 | dump ("K(t):d", plain, plain_len); |
253 | #endif | 244 | #endif |
254 | if (t > 0) | 245 | if (t > 0) |
255 | hc = doHMAC (prf, prk, xtr_len, plain, plain_len); | 246 | hc = doHMAC (prf, prk, xtr_len, plain, plain_len); |
@@ -260,11 +251,11 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, | |||
260 | memcpy (result, hc, d); | 251 | memcpy (result, hc, d); |
261 | } | 252 | } |
262 | #if DEBUG_HKDF | 253 | #if DEBUG_HKDF |
263 | dump("result", result - k, out_len); | 254 | dump ("result", result - k, out_len); |
264 | #endif | 255 | #endif |
265 | 256 | ||
266 | ret = GNUNET_YES; | 257 | ret = GNUNET_YES; |
267 | goto hkdf_ok; | 258 | goto hkdf_ok; |
268 | } | 259 | } |
269 | hkdf_error: | 260 | hkdf_error: |
270 | ret = GNUNET_SYSERR; | 261 | ret = GNUNET_SYSERR; |
@@ -290,18 +281,17 @@ hkdf_ok: | |||
290 | */ | 281 | */ |
291 | int | 282 | int |
292 | GNUNET_CRYPTO_hkdf (void *result, size_t out_len, | 283 | GNUNET_CRYPTO_hkdf (void *result, size_t out_len, |
293 | int xtr_algo, int prf_algo, | 284 | int xtr_algo, int prf_algo, |
294 | const void *xts, size_t xts_len, | 285 | const void *xts, size_t xts_len, |
295 | const void *skm, size_t skm_len, | 286 | const void *skm, size_t skm_len, ...) |
296 | ...) | ||
297 | { | 287 | { |
298 | va_list argp; | 288 | va_list argp; |
299 | int ret; | 289 | int ret; |
300 | 290 | ||
301 | va_start(argp, skm_len); | 291 | va_start (argp, skm_len); |
302 | ret = GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, | 292 | ret = GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, |
303 | xts_len, skm, skm_len, argp); | 293 | xts_len, skm, skm_len, argp); |
304 | va_end(argp); | 294 | va_end (argp); |
305 | 295 | ||
306 | return ret; | 296 | return ret; |
307 | } | 297 | } |
diff --git a/src/util/crypto_kdf.c b/src/util/crypto_kdf.c index cd42a63bf..dc2e667af 100644 --- a/src/util/crypto_kdf.c +++ b/src/util/crypto_kdf.c | |||
@@ -42,23 +42,23 @@ | |||
42 | */ | 42 | */ |
43 | int | 43 | int |
44 | GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, | 44 | GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, |
45 | const void *xts, size_t xts_len, const void *skm, | 45 | const void *xts, size_t xts_len, const void *skm, |
46 | size_t skm_len, va_list argp) | 46 | size_t skm_len, va_list argp) |
47 | { | 47 | { |
48 | /* | 48 | /* |
49 | "Finally, we point out to a particularly advantageous instantiation using | 49 | * "Finally, we point out to a particularly advantageous instantiation using |
50 | HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from SHA-512 is | 50 | * HMAC-SHA512 as XTR and HMAC-SHA256 in PRF* (in which case the output from SHA-512 is |
51 | truncated to 256 bits). This makes sense in two ways: First, the extraction part is where we need a | 51 | * truncated to 256 bits). This makes sense in two ways: First, the extraction part is where we need a |
52 | stronger hash function due to the unconventional demand from the hash function in the extraction | 52 | * stronger hash function due to the unconventional demand from the hash function in the extraction |
53 | setting. Second, as shown in Section 6, using HMAC with a truncated output as an extractor | 53 | * setting. Second, as shown in Section 6, using HMAC with a truncated output as an extractor |
54 | allows to prove the security of HKDF under considerably weaker assumptions on the underlying | 54 | * allows to prove the security of HKDF under considerably weaker assumptions on the underlying |
55 | hash function." | 55 | * hash function." |
56 | 56 | * | |
57 | http://eprint.iacr.org/2010/264 | 57 | * http://eprint.iacr.org/2010/264 |
58 | */ | 58 | */ |
59 | 59 | ||
60 | return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, GCRY_MD_SHA256, | 60 | return GNUNET_CRYPTO_hkdf_v (result, out_len, GCRY_MD_SHA512, GCRY_MD_SHA256, |
61 | xts, xts_len, skm, skm_len, argp); | 61 | xts, xts_len, skm, skm_len, argp); |
62 | } | 62 | } |
63 | 63 | ||
64 | /** | 64 | /** |
@@ -74,15 +74,15 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, | |||
74 | */ | 74 | */ |
75 | int | 75 | int |
76 | GNUNET_CRYPTO_kdf (void *result, size_t out_len, | 76 | GNUNET_CRYPTO_kdf (void *result, size_t out_len, |
77 | const void *xts, size_t xts_len, const void *skm, | 77 | const void *xts, size_t xts_len, const void *skm, |
78 | size_t skm_len, ...) | 78 | size_t skm_len, ...) |
79 | { | 79 | { |
80 | va_list argp; | 80 | va_list argp; |
81 | int ret; | 81 | int ret; |
82 | 82 | ||
83 | va_start(argp, skm_len); | 83 | va_start (argp, skm_len); |
84 | ret = GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp); | 84 | ret = GNUNET_CRYPTO_kdf_v (result, out_len, xts, xts_len, skm, skm_len, argp); |
85 | va_end(argp); | 85 | va_end (argp); |
86 | 86 | ||
87 | return ret; | 87 | return ret; |
88 | } | 88 | } |
diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c index 7a0b4410a..7c23fc1e0 100644 --- a/src/util/crypto_ksk.c +++ b/src/util/crypto_ksk.c | |||
@@ -49,12 +49,12 @@ | |||
49 | 49 | ||
50 | typedef struct | 50 | typedef struct |
51 | { | 51 | { |
52 | gcry_mpi_t n; /* public modulus */ | 52 | gcry_mpi_t n; /* public modulus */ |
53 | gcry_mpi_t e; /* public exponent */ | 53 | gcry_mpi_t e; /* public exponent */ |
54 | gcry_mpi_t d; /* exponent */ | 54 | gcry_mpi_t d; /* exponent */ |
55 | gcry_mpi_t p; /* prime p. */ | 55 | gcry_mpi_t p; /* prime p. */ |
56 | gcry_mpi_t q; /* prime q. */ | 56 | gcry_mpi_t q; /* prime q. */ |
57 | gcry_mpi_t u; /* inverse of p mod q. */ | 57 | gcry_mpi_t u; /* inverse of p mod q. */ |
58 | } KBlock_secret_key; | 58 | } KBlock_secret_key; |
59 | 59 | ||
60 | /** | 60 | /** |
@@ -82,23 +82,23 @@ mpz_randomize (gcry_mpi_t n, unsigned int nbits, GNUNET_HashCode * rnd) | |||
82 | 82 | ||
83 | tmp = *rnd; | 83 | tmp = *rnd; |
84 | for (i = 0; i < cnt; i++) | 84 | for (i = 0; i < cnt; i++) |
85 | { | ||
86 | int j; | ||
87 | |||
88 | if (i > 0) | ||
89 | GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp); | ||
90 | for (j = 0; j < sizeof (GNUNET_HashCode) / sizeof (uint32_t); j++) | ||
85 | { | 91 | { |
86 | int j; | 92 | #if HAVE_GCRY_MPI_LSHIFT |
87 | 93 | gcry_mpi_lshift (n, n, sizeof (uint32_t) * 8); | |
88 | if (i > 0) | ||
89 | GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), &tmp); | ||
90 | for (j=0;j<sizeof(GNUNET_HashCode) / sizeof(uint32_t); j++) | ||
91 | { | ||
92 | #if HAVE_GCRY_MPI_LSHIFT | ||
93 | gcry_mpi_lshift (n, n, sizeof(uint32_t)*8); | ||
94 | #else | 94 | #else |
95 | gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4)); | 95 | gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); |
96 | gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4)); | 96 | gcry_mpi_mul_ui (n, n, 1 << (sizeof (uint32_t) * 4)); |
97 | #endif | 97 | #endif |
98 | gcry_mpi_add_ui(n, n, ntohl (((uint32_t *) &tmp)[j])); | 98 | gcry_mpi_add_ui (n, n, ntohl (((uint32_t *) & tmp)[j])); |
99 | } | ||
100 | hc = tmp; | ||
101 | } | 99 | } |
100 | hc = tmp; | ||
101 | } | ||
102 | GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), rnd); | 102 | GNUNET_CRYPTO_hash (&hc, sizeof (GNUNET_HashCode), rnd); |
103 | i = gcry_mpi_get_nbits (n); | 103 | i = gcry_mpi_get_nbits (n); |
104 | while (i > nbits) | 104 | while (i > nbits) |
@@ -110,12 +110,12 @@ mpz_trailing_zeroes (gcry_mpi_t n) | |||
110 | { | 110 | { |
111 | unsigned int idx, cnt; | 111 | unsigned int idx, cnt; |
112 | 112 | ||
113 | cnt = gcry_mpi_get_nbits(n); | 113 | cnt = gcry_mpi_get_nbits (n); |
114 | for (idx = 0; idx < cnt; idx++) | 114 | for (idx = 0; idx < cnt; idx++) |
115 | { | 115 | { |
116 | if (gcry_mpi_test_bit(n, idx) == 0) | 116 | if (gcry_mpi_test_bit (n, idx) == 0) |
117 | return idx; | 117 | return idx; |
118 | } | 118 | } |
119 | 119 | ||
120 | return ULONG_MAX; | 120 | return ULONG_MAX; |
121 | } | 121 | } |
@@ -154,7 +154,7 @@ is_prime (gcry_mpi_t n, int steps, GNUNET_HashCode * hc) | |||
154 | a2 = gcry_mpi_set_ui (NULL, 2); | 154 | a2 = gcry_mpi_set_ui (NULL, 2); |
155 | 155 | ||
156 | nbits = gcry_mpi_get_nbits (n); | 156 | nbits = gcry_mpi_get_nbits (n); |
157 | gcry_mpi_sub_ui(nminus1, n, 1); | 157 | gcry_mpi_sub_ui (nminus1, n, 1); |
158 | 158 | ||
159 | /* Find q and k, so that n = 1 + 2^k * q . */ | 159 | /* Find q and k, so that n = 1 + 2^k * q . */ |
160 | q = gcry_mpi_set (NULL, nminus1); | 160 | q = gcry_mpi_set (NULL, nminus1); |
@@ -162,30 +162,30 @@ is_prime (gcry_mpi_t n, int steps, GNUNET_HashCode * hc) | |||
162 | mpz_tdiv_q_2exp (q, q, k); | 162 | mpz_tdiv_q_2exp (q, q, k); |
163 | 163 | ||
164 | for (i = 0; i < steps; i++) | 164 | for (i = 0; i < steps; i++) |
165 | { | ||
166 | if (!i) | ||
167 | { | ||
168 | gcry_mpi_set_ui (x, 2); | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | mpz_randomize (x, nbits - 1, hc); | ||
173 | GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0); | ||
174 | GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0); | ||
175 | } | ||
176 | gcry_mpi_powm (y, x, q, n); | ||
177 | if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1)) | ||
165 | { | 178 | { |
166 | if (!i) | 179 | for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++) |
167 | { | 180 | { |
168 | gcry_mpi_set_ui (x, 2); | 181 | gcry_mpi_powm (y, y, a2, n); |
169 | } | 182 | if (!gcry_mpi_cmp_ui (y, 1)) |
170 | else | 183 | goto leave; /* Not a prime. */ |
171 | { | 184 | } |
172 | mpz_randomize (x, nbits - 1, hc); | 185 | if (gcry_mpi_cmp (y, nminus1)) |
173 | GNUNET_assert (gcry_mpi_cmp (x, nminus1) < 0); | 186 | goto leave; /* Not a prime. */ |
174 | GNUNET_assert (gcry_mpi_cmp_ui (x, 1) > 0); | ||
175 | } | ||
176 | gcry_mpi_powm (y, x, q, n); | ||
177 | if (gcry_mpi_cmp_ui (y, 1) && gcry_mpi_cmp (y, nminus1)) | ||
178 | { | ||
179 | for (j = 1; j < k && gcry_mpi_cmp (y, nminus1); j++) | ||
180 | { | ||
181 | gcry_mpi_powm (y, y, a2, n); | ||
182 | if (!gcry_mpi_cmp_ui (y, 1)) | ||
183 | goto leave; /* Not a prime. */ | ||
184 | } | ||
185 | if (gcry_mpi_cmp (y, nminus1)) | ||
186 | goto leave; /* Not a prime. */ | ||
187 | } | ||
188 | } | 187 | } |
188 | } | ||
189 | rc = 1; /* May be a prime. */ | 189 | rc = 1; /* May be a prime. */ |
190 | 190 | ||
191 | leave: | 191 | leave: |
@@ -208,18 +208,18 @@ static void | |||
208 | adjust (unsigned char *buf, size_t size, size_t target) | 208 | adjust (unsigned char *buf, size_t size, size_t target) |
209 | { | 209 | { |
210 | if (size < target) | 210 | if (size < target) |
211 | { | 211 | { |
212 | memmove (&buf[target - size], buf, size); | 212 | memmove (&buf[target - size], buf, size); |
213 | memset (buf, 0, target - size); | 213 | memset (buf, 0, target - size); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | static void | 218 | static void |
219 | gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc) | 219 | gen_prime (gcry_mpi_t * ptest, unsigned int nbits, GNUNET_HashCode * hc) |
220 | { | 220 | { |
221 | /* Note: 2 is not included because it can be tested more easily by | 221 | /* Note: 2 is not included because it can be tested more easily by |
222 | looking at bit 0. The last entry in this list is marked by a zero */ | 222 | * looking at bit 0. The last entry in this list is marked by a zero */ |
223 | static const uint16_t small_prime_numbers[] = { | 223 | static const uint16_t small_prime_numbers[] = { |
224 | 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, | 224 | 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, |
225 | 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, | 225 | 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, |
@@ -317,76 +317,77 @@ gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc) | |||
317 | /* Make nbits fit into mpz_t implementation. */ | 317 | /* Make nbits fit into mpz_t implementation. */ |
318 | val_2 = gcry_mpi_set_ui (NULL, 2); | 318 | val_2 = gcry_mpi_set_ui (NULL, 2); |
319 | val_3 = gcry_mpi_set_ui (NULL, 3); | 319 | val_3 = gcry_mpi_set_ui (NULL, 3); |
320 | prime = gcry_mpi_snew(0); | 320 | prime = gcry_mpi_snew (0); |
321 | result = gcry_mpi_new(0); | 321 | result = gcry_mpi_new (0); |
322 | pminus1 = gcry_mpi_new(0); | 322 | pminus1 = gcry_mpi_new (0); |
323 | *ptest = gcry_mpi_new(0); | 323 | *ptest = gcry_mpi_new (0); |
324 | tmp = gcry_mpi_new (0); | 324 | tmp = gcry_mpi_new (0); |
325 | sp = gcry_mpi_new (0); | 325 | sp = gcry_mpi_new (0); |
326 | while (1) | 326 | while (1) |
327 | { | ||
328 | /* generate a random number */ | ||
329 | mpz_randomize (prime, nbits, hc); | ||
330 | /* Set high order bit to 1, set low order bit to 1. If we are | ||
331 | * generating a secret prime we are most probably doing that | ||
332 | * for RSA, to make sure that the modulus does have the | ||
333 | * requested key size we set the 2 high order bits. */ | ||
334 | gcry_mpi_set_bit (prime, nbits - 1); | ||
335 | gcry_mpi_set_bit (prime, nbits - 2); | ||
336 | gcry_mpi_set_bit (prime, 0); | ||
337 | |||
338 | /* Calculate all remainders. */ | ||
339 | for (i = 0; i < no_of_small_prime_numbers; i++) | ||
340 | { | ||
341 | size_t written; | ||
342 | |||
343 | gcry_mpi_set_ui (sp, small_prime_numbers[i]); | ||
344 | gcry_mpi_div (NULL, tmp, prime, sp, -1); | ||
345 | mods[i] = 0; | ||
346 | written = sizeof (unsigned int); | ||
347 | GNUNET_assert (0 == | ||
348 | gcry_mpi_print (GCRYMPI_FMT_USG, | ||
349 | (unsigned char *) &mods[i], written, | ||
350 | &written, tmp)); | ||
351 | adjust ((unsigned char *) &mods[i], written, sizeof (unsigned int)); | ||
352 | mods[i] = ntohl (mods[i]); | ||
353 | } | ||
354 | /* Now try some primes starting with prime. */ | ||
355 | for (step = 0; step < 20000; step += 2) | ||
327 | { | 356 | { |
328 | /* generate a random number */ | 357 | /* Check against all the small primes we have in mods. */ |
329 | mpz_randomize (prime, nbits, hc); | ||
330 | /* Set high order bit to 1, set low order bit to 1. If we are | ||
331 | generating a secret prime we are most probably doing that | ||
332 | for RSA, to make sure that the modulus does have the | ||
333 | requested key size we set the 2 high order bits. */ | ||
334 | gcry_mpi_set_bit (prime, nbits - 1); | ||
335 | gcry_mpi_set_bit (prime, nbits - 2); | ||
336 | gcry_mpi_set_bit (prime, 0); | ||
337 | |||
338 | /* Calculate all remainders. */ | ||
339 | for (i = 0; i < no_of_small_prime_numbers; i++) | 358 | for (i = 0; i < no_of_small_prime_numbers; i++) |
340 | { | 359 | { |
341 | size_t written; | 360 | uint16_t x = small_prime_numbers[i]; |
342 | 361 | ||
343 | gcry_mpi_set_ui(sp, small_prime_numbers[i]); | 362 | while (mods[i] + step >= x) |
344 | gcry_mpi_div (NULL, tmp, prime, sp, -1); | 363 | mods[i] -= x; |
345 | mods[i] = 0; | 364 | if (!(mods[i] + step)) |
346 | written = sizeof (unsigned int); | 365 | break; |
347 | GNUNET_assert (0 == | 366 | } |
348 | gcry_mpi_print (GCRYMPI_FMT_USG, | 367 | if (i < no_of_small_prime_numbers) |
349 | (unsigned char*) &mods[i], written, &written, | 368 | continue; /* Found a multiple of an already known prime. */ |
350 | tmp)); | 369 | |
351 | adjust ( (unsigned char*) &mods[i], written, sizeof (unsigned int)); | 370 | gcry_mpi_add_ui (*ptest, prime, step); |
352 | mods[i] = ntohl (mods[i]); | 371 | if (!gcry_mpi_test_bit (*ptest, nbits - 2)) |
353 | } | 372 | break; |
354 | /* Now try some primes starting with prime. */ | 373 | |
355 | for (step = 0; step < 20000; step += 2) | 374 | /* Do a fast Fermat test now. */ |
356 | { | 375 | gcry_mpi_sub_ui (pminus1, *ptest, 1); |
357 | /* Check against all the small primes we have in mods. */ | 376 | gcry_mpi_powm (result, val_2, pminus1, *ptest); |
358 | for (i = 0; i < no_of_small_prime_numbers; i++) | 377 | if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc))) |
359 | { | 378 | { |
360 | uint16_t x = small_prime_numbers[i]; | 379 | /* Got it. */ |
361 | while (mods[i] + step >= x) | 380 | gcry_mpi_release (sp); |
362 | mods[i] -= x; | 381 | gcry_mpi_release (tmp); |
363 | if (!(mods[i] + step)) | 382 | gcry_mpi_release (val_2); |
364 | break; | 383 | gcry_mpi_release (val_3); |
365 | } | 384 | gcry_mpi_release (result); |
366 | if (i < no_of_small_prime_numbers) | 385 | gcry_mpi_release (pminus1); |
367 | continue; /* Found a multiple of an already known prime. */ | 386 | gcry_mpi_release (prime); |
368 | 387 | return; | |
369 | gcry_mpi_add_ui (*ptest, prime, step); | 388 | } |
370 | if (!gcry_mpi_test_bit (*ptest, nbits - 2)) | ||
371 | break; | ||
372 | |||
373 | /* Do a fast Fermat test now. */ | ||
374 | gcry_mpi_sub_ui (pminus1, *ptest, 1); | ||
375 | gcry_mpi_powm (result, val_2, pminus1, *ptest); | ||
376 | if ((!gcry_mpi_cmp_ui (result, 1)) && (is_prime (*ptest, 5, hc))) | ||
377 | { | ||
378 | /* Got it. */ | ||
379 | gcry_mpi_release (sp); | ||
380 | gcry_mpi_release (tmp); | ||
381 | gcry_mpi_release (val_2); | ||
382 | gcry_mpi_release (val_3); | ||
383 | gcry_mpi_release (result); | ||
384 | gcry_mpi_release (pminus1); | ||
385 | gcry_mpi_release (prime); | ||
386 | return; | ||
387 | } | ||
388 | } | ||
389 | } | 389 | } |
390 | } | ||
390 | } | 391 | } |
391 | 392 | ||
392 | /** | 393 | /** |
@@ -396,11 +397,11 @@ gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc) | |||
396 | * @param hc the HC to use for PRNG (modified!) | 397 | * @param hc the HC to use for PRNG (modified!) |
397 | */ | 398 | */ |
398 | static void | 399 | static void |
399 | generate_kblock_key (KBlock_secret_key * sk, | 400 | generate_kblock_key (KBlock_secret_key *sk, |
400 | unsigned int nbits, GNUNET_HashCode * hc) | 401 | unsigned int nbits, GNUNET_HashCode * hc) |
401 | { | 402 | { |
402 | gcry_mpi_t t1, t2; | 403 | gcry_mpi_t t1, t2; |
403 | gcry_mpi_t phi; /* helper: (p-1)(q-1) */ | 404 | gcry_mpi_t phi; /* helper: (p-1)(q-1) */ |
404 | gcry_mpi_t g; | 405 | gcry_mpi_t g; |
405 | gcry_mpi_t f; | 406 | gcry_mpi_t f; |
406 | 407 | ||
@@ -409,47 +410,47 @@ generate_kblock_key (KBlock_secret_key * sk, | |||
409 | nbits++; | 410 | nbits++; |
410 | 411 | ||
411 | sk->e = gcry_mpi_set_ui (NULL, 257); | 412 | sk->e = gcry_mpi_set_ui (NULL, 257); |
412 | sk->n = gcry_mpi_new(0); | 413 | sk->n = gcry_mpi_new (0); |
413 | sk->p = gcry_mpi_new(0); | 414 | sk->p = gcry_mpi_new (0); |
414 | sk->q = gcry_mpi_new(0); | 415 | sk->q = gcry_mpi_new (0); |
415 | sk->d = gcry_mpi_new(0); | 416 | sk->d = gcry_mpi_new (0); |
416 | sk->u = gcry_mpi_new(0); | 417 | sk->u = gcry_mpi_new (0); |
417 | 418 | ||
418 | t1 = gcry_mpi_new(0); | 419 | t1 = gcry_mpi_new (0); |
419 | t2 = gcry_mpi_new(0); | 420 | t2 = gcry_mpi_new (0); |
420 | phi = gcry_mpi_new(0); | 421 | phi = gcry_mpi_new (0); |
421 | g = gcry_mpi_new(0); | 422 | g = gcry_mpi_new (0); |
422 | f = gcry_mpi_new(0); | 423 | f = gcry_mpi_new (0); |
423 | 424 | ||
424 | do | 425 | do |
426 | { | ||
427 | do | ||
425 | { | 428 | { |
426 | do | 429 | gcry_mpi_release (sk->p); |
427 | { | 430 | gcry_mpi_release (sk->q); |
428 | gcry_mpi_release (sk->p); | 431 | gen_prime (&sk->p, nbits / 2, hc); |
429 | gcry_mpi_release (sk->q); | 432 | gen_prime (&sk->q, nbits / 2, hc); |
430 | gen_prime (&sk->p, nbits / 2, hc); | 433 | |
431 | gen_prime (&sk->q, nbits / 2, hc); | 434 | if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */ |
432 | 435 | gcry_mpi_swap (sk->p, sk->q); | |
433 | if (gcry_mpi_cmp (sk->p, sk->q) > 0) /* p shall be smaller than q (for calc of u) */ | 436 | /* calculate the modulus */ |
434 | gcry_mpi_swap (sk->p, sk->q); | 437 | gcry_mpi_mul (sk->n, sk->p, sk->q); |
435 | /* calculate the modulus */ | 438 | } |
436 | gcry_mpi_mul (sk->n, sk->p, sk->q); | 439 | while (gcry_mpi_get_nbits (sk->n) != nbits); |
437 | } | 440 | |
438 | while (gcry_mpi_get_nbits (sk->n) != nbits); | 441 | /* calculate Euler totient: phi = (p-1)(q-1) */ |
439 | 442 | gcry_mpi_sub_ui (t1, sk->p, 1); | |
440 | /* calculate Euler totient: phi = (p-1)(q-1) */ | 443 | gcry_mpi_sub_ui (t2, sk->q, 1); |
441 | gcry_mpi_sub_ui (t1, sk->p, 1); | 444 | gcry_mpi_mul (phi, t1, t2); |
442 | gcry_mpi_sub_ui (t2, sk->q, 1); | 445 | gcry_mpi_gcd (g, t1, t2); |
443 | gcry_mpi_mul (phi, t1, t2); | 446 | gcry_mpi_div (f, NULL, phi, g, 0); |
444 | gcry_mpi_gcd (g, t1, t2); | 447 | while (0 == gcry_mpi_gcd (t1, sk->e, phi)) |
445 | gcry_mpi_div (f, NULL, phi, g, 0); | 448 | { /* (while gcd is not 1) */ |
446 | while (0 == gcry_mpi_gcd (t1, sk->e, phi)) | 449 | gcry_mpi_add_ui (sk->e, sk->e, 2); |
447 | { /* (while gcd is not 1) */ | ||
448 | gcry_mpi_add_ui (sk->e, sk->e, 2); | ||
449 | } | ||
450 | |||
451 | /* calculate the secret key d = e^1 mod phi */ | ||
452 | } | 450 | } |
451 | |||
452 | /* calculate the secret key d = e^1 mod phi */ | ||
453 | } | ||
453 | while ((0 == gcry_mpi_invm (sk->d, sk->e, f)) || | 454 | while ((0 == gcry_mpi_invm (sk->d, sk->e, f)) || |
454 | (0 == gcry_mpi_invm (sk->u, sk->p, sk->q))); | 455 | (0 == gcry_mpi_invm (sk->u, sk->p, sk->q))); |
455 | 456 | ||
@@ -499,14 +500,14 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc) | |||
499 | 500 | ||
500 | hx = *hc; | 501 | hx = *hc; |
501 | generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits | 502 | generate_kblock_key (&sk, 1024, /* at least 10x as fast than 2048 bits |
502 | -- we simply cannot afford 2048 bits | 503 | * -- we simply cannot afford 2048 bits |
503 | even on modern hardware, and especially | 504 | * even on modern hardware, and especially |
504 | not since clearly a dictionary attack | 505 | * not since clearly a dictionary attack |
505 | will still be much cheaper | 506 | * will still be much cheaper |
506 | than breaking a 1024 bit RSA key. | 507 | * than breaking a 1024 bit RSA key. |
507 | If an adversary can spend the time to | 508 | * If an adversary can spend the time to |
508 | break a 1024 bit RSA key just to forge | 509 | * break a 1024 bit RSA key just to forge |
509 | a signature -- SO BE IT. [ CG, 6/2005 ] */ | 510 | * a signature -- SO BE IT. [ CG, 6/2005 ] */ |
510 | &hx); | 511 | &hx); |
511 | pkv[0] = &sk.n; | 512 | pkv[0] = &sk.n; |
512 | pkv[1] = &sk.e; | 513 | pkv[1] = &sk.e; |
@@ -516,10 +517,10 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc) | |||
516 | pkv[5] = &sk.u; | 517 | pkv[5] = &sk.u; |
517 | size = sizeof (struct KskRsaPrivateKeyBinaryEncoded); | 518 | size = sizeof (struct KskRsaPrivateKeyBinaryEncoded); |
518 | for (i = 0; i < 6; i++) | 519 | for (i = 0; i < 6; i++) |
519 | { | 520 | { |
520 | gcry_mpi_aprint(GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]); | 521 | gcry_mpi_aprint (GCRYMPI_FMT_STD, &pbu[i], &sizes[i], *pkv[i]); |
521 | size += sizes[i]; | 522 | size += sizes[i]; |
522 | } | 523 | } |
523 | GNUNET_assert (size < 65536); | 524 | GNUNET_assert (size < 65536); |
524 | retval = GNUNET_malloc (size); | 525 | retval = GNUNET_malloc (size); |
525 | retval->len = htons (size); | 526 | retval->len = htons (size); |
@@ -544,10 +545,10 @@ makeKblockKeyInternal (const GNUNET_HashCode * hc) | |||
544 | retval->sizedmq1 = htons (0); | 545 | retval->sizedmq1 = htons (0); |
545 | memcpy (&((char *) &retval[1])[i], pbu[5], sizes[5]); | 546 | memcpy (&((char *) &retval[1])[i], pbu[5], sizes[5]); |
546 | for (i = 0; i < 6; i++) | 547 | for (i = 0; i < 6; i++) |
547 | { | 548 | { |
548 | gcry_mpi_release (*pkv[i]); | 549 | gcry_mpi_release (*pkv[i]); |
549 | free (pbu[i]); | 550 | free (pbu[i]); |
550 | } | 551 | } |
551 | return retval; | 552 | return retval; |
552 | } | 553 | } |
553 | 554 | ||
@@ -574,10 +575,10 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding) | |||
574 | size, &size); | 575 | size, &size); |
575 | pos += ntohs (encoding->sizen); | 576 | pos += ntohs (encoding->sizen); |
576 | if (rc) | 577 | if (rc) |
577 | { | 578 | { |
578 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 579 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
579 | return NULL; | 580 | return NULL; |
580 | } | 581 | } |
581 | size = ntohs (encoding->sizee); | 582 | size = ntohs (encoding->sizee); |
582 | rc = gcry_mpi_scan (&e, | 583 | rc = gcry_mpi_scan (&e, |
583 | GCRYMPI_FMT_USG, | 584 | GCRYMPI_FMT_USG, |
@@ -585,11 +586,11 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding) | |||
585 | size, &size); | 586 | size, &size); |
586 | pos += ntohs (encoding->sizee); | 587 | pos += ntohs (encoding->sizee); |
587 | if (rc) | 588 | if (rc) |
588 | { | 589 | { |
589 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 590 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
590 | gcry_mpi_release (n); | 591 | gcry_mpi_release (n); |
591 | return NULL; | 592 | return NULL; |
592 | } | 593 | } |
593 | size = ntohs (encoding->sized); | 594 | size = ntohs (encoding->sized); |
594 | rc = gcry_mpi_scan (&d, | 595 | rc = gcry_mpi_scan (&d, |
595 | GCRYMPI_FMT_USG, | 596 | GCRYMPI_FMT_USG, |
@@ -597,101 +598,100 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding) | |||
597 | size, &size); | 598 | size, &size); |
598 | pos += ntohs (encoding->sized); | 599 | pos += ntohs (encoding->sized); |
599 | if (rc) | 600 | if (rc) |
601 | { | ||
602 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | ||
603 | gcry_mpi_release (n); | ||
604 | gcry_mpi_release (e); | ||
605 | return NULL; | ||
606 | } | ||
607 | /* swap p and q! */ | ||
608 | size = ntohs (encoding->sizep); | ||
609 | if (size > 0) | ||
610 | { | ||
611 | rc = gcry_mpi_scan (&q, | ||
612 | GCRYMPI_FMT_USG, | ||
613 | &((const unsigned char *) (&encoding[1]))[pos], | ||
614 | size, &size); | ||
615 | pos += ntohs (encoding->sizep); | ||
616 | if (rc) | ||
600 | { | 617 | { |
601 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 618 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
602 | gcry_mpi_release (n); | 619 | gcry_mpi_release (n); |
603 | gcry_mpi_release (e); | 620 | gcry_mpi_release (e); |
621 | gcry_mpi_release (d); | ||
604 | return NULL; | 622 | return NULL; |
605 | } | 623 | } |
606 | /* swap p and q! */ | 624 | } |
607 | size = ntohs (encoding->sizep); | ||
608 | if (size > 0) | ||
609 | { | ||
610 | rc = gcry_mpi_scan (&q, | ||
611 | GCRYMPI_FMT_USG, | ||
612 | &((const unsigned char *) (&encoding[1]))[pos], | ||
613 | size, &size); | ||
614 | pos += ntohs (encoding->sizep); | ||
615 | if (rc) | ||
616 | { | ||
617 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | ||
618 | gcry_mpi_release (n); | ||
619 | gcry_mpi_release (e); | ||
620 | gcry_mpi_release (d); | ||
621 | return NULL; | ||
622 | } | ||
623 | } | ||
624 | else | 625 | else |
625 | q = NULL; | 626 | q = NULL; |
626 | size = ntohs (encoding->sizeq); | 627 | size = ntohs (encoding->sizeq); |
627 | if (size > 0) | 628 | if (size > 0) |
629 | { | ||
630 | rc = gcry_mpi_scan (&p, | ||
631 | GCRYMPI_FMT_USG, | ||
632 | &((const unsigned char *) (&encoding[1]))[pos], | ||
633 | size, &size); | ||
634 | pos += ntohs (encoding->sizeq); | ||
635 | if (rc) | ||
628 | { | 636 | { |
629 | rc = gcry_mpi_scan (&p, | 637 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
630 | GCRYMPI_FMT_USG, | 638 | gcry_mpi_release (n); |
631 | &((const unsigned char *) (&encoding[1]))[pos], | 639 | gcry_mpi_release (e); |
632 | size, &size); | 640 | gcry_mpi_release (d); |
633 | pos += ntohs (encoding->sizeq); | 641 | if (q != NULL) |
634 | if (rc) | 642 | gcry_mpi_release (q); |
635 | { | 643 | return NULL; |
636 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | ||
637 | gcry_mpi_release (n); | ||
638 | gcry_mpi_release (e); | ||
639 | gcry_mpi_release (d); | ||
640 | if (q != NULL) | ||
641 | gcry_mpi_release (q); | ||
642 | return NULL; | ||
643 | } | ||
644 | } | 644 | } |
645 | } | ||
645 | else | 646 | else |
646 | p = NULL; | 647 | p = NULL; |
647 | pos += ntohs (encoding->sizedmp1); | 648 | pos += ntohs (encoding->sizedmp1); |
648 | pos += ntohs (encoding->sizedmq1); | 649 | pos += ntohs (encoding->sizedmq1); |
649 | size = | 650 | size = |
650 | ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) - | 651 | ntohs (encoding->len) - sizeof (struct KskRsaPrivateKeyBinaryEncoded) - |
651 | pos; | 652 | pos; |
652 | if (size > 0) | 653 | if (size > 0) |
654 | { | ||
655 | rc = gcry_mpi_scan (&u, | ||
656 | GCRYMPI_FMT_USG, | ||
657 | &((const unsigned char *) (&encoding[1]))[pos], | ||
658 | size, &size); | ||
659 | if (rc) | ||
653 | { | 660 | { |
654 | rc = gcry_mpi_scan (&u, | 661 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
655 | GCRYMPI_FMT_USG, | 662 | gcry_mpi_release (n); |
656 | &((const unsigned char *) (&encoding[1]))[pos], | 663 | gcry_mpi_release (e); |
657 | size, &size); | 664 | gcry_mpi_release (d); |
658 | if (rc) | 665 | if (p != NULL) |
659 | { | 666 | gcry_mpi_release (p); |
660 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 667 | if (q != NULL) |
661 | gcry_mpi_release (n); | 668 | gcry_mpi_release (q); |
662 | gcry_mpi_release (e); | 669 | return NULL; |
663 | gcry_mpi_release (d); | ||
664 | if (p != NULL) | ||
665 | gcry_mpi_release (p); | ||
666 | if (q != NULL) | ||
667 | gcry_mpi_release (q); | ||
668 | return NULL; | ||
669 | } | ||
670 | } | 670 | } |
671 | } | ||
671 | else | 672 | else |
672 | u = NULL; | 673 | u = NULL; |
673 | 674 | ||
674 | if ((p != NULL) && (q != NULL) && (u != NULL)) | 675 | if ((p != NULL) && (q != NULL) && (u != NULL)) |
676 | { | ||
677 | rc = gcry_sexp_build (&res, &size, /* erroff */ | ||
678 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", | ||
679 | n, e, d, p, q, u); | ||
680 | } | ||
681 | else | ||
682 | { | ||
683 | if ((p != NULL) && (q != NULL)) | ||
675 | { | 684 | { |
676 | rc = gcry_sexp_build (&res, &size, /* erroff */ | 685 | rc = gcry_sexp_build (&res, &size, /* erroff */ |
677 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", | 686 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", |
678 | n, e, d, p, q, u); | 687 | n, e, d, p, q); |
679 | } | 688 | } |
680 | else | 689 | else |
681 | { | 690 | { |
682 | if ((p != NULL) && (q != NULL)) | 691 | rc = gcry_sexp_build (&res, &size, /* erroff */ |
683 | { | 692 | "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d); |
684 | rc = gcry_sexp_build (&res, &size, /* erroff */ | ||
685 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", | ||
686 | n, e, d, p, q); | ||
687 | } | ||
688 | else | ||
689 | { | ||
690 | rc = gcry_sexp_build (&res, &size, /* erroff */ | ||
691 | "(private-key(rsa(n %m)(e %m)(d %m)))", | ||
692 | n, e, d); | ||
693 | } | ||
694 | } | 693 | } |
694 | } | ||
695 | gcry_mpi_release (n); | 695 | gcry_mpi_release (n); |
696 | gcry_mpi_release (e); | 696 | gcry_mpi_release (e); |
697 | gcry_mpi_release (d); | 697 | gcry_mpi_release (d); |
@@ -706,10 +706,10 @@ ksk_decode_key (const struct KskRsaPrivateKeyBinaryEncoded *encoding) | |||
706 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); | 706 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); |
707 | #if EXTRA_CHECKS | 707 | #if EXTRA_CHECKS |
708 | if (gcry_pk_testkey (res)) | 708 | if (gcry_pk_testkey (res)) |
709 | { | 709 | { |
710 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); | 710 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); |
711 | return NULL; | 711 | return NULL; |
712 | } | 712 | } |
713 | #endif | 713 | #endif |
714 | ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); | 714 | ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); |
715 | ret->sexp = res; | 715 | ret->sexp = res; |
@@ -739,13 +739,13 @@ GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc) | |||
739 | unsigned int i; | 739 | unsigned int i; |
740 | 740 | ||
741 | for (i = 0; i < cacheSize; i++) | 741 | for (i = 0; i < cacheSize; i++) |
742 | { | ||
743 | if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode))) | ||
742 | { | 744 | { |
743 | if (0 == memcmp (hc, &cache[i]->hc, sizeof (GNUNET_HashCode))) | 745 | ret = ksk_decode_key (cache[i]->pke); |
744 | { | 746 | return ret; |
745 | ret = ksk_decode_key (cache[i]->pke); | ||
746 | return ret; | ||
747 | } | ||
748 | } | 747 | } |
748 | } | ||
749 | 749 | ||
750 | line = GNUNET_malloc (sizeof (struct KBlockKeyCacheLine)); | 750 | line = GNUNET_malloc (sizeof (struct KBlockKeyCacheLine)); |
751 | line->hc = *hc; | 751 | line->hc = *hc; |
@@ -761,10 +761,10 @@ void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini () | |||
761 | unsigned int i; | 761 | unsigned int i; |
762 | 762 | ||
763 | for (i = 0; i < cacheSize; i++) | 763 | for (i = 0; i < cacheSize; i++) |
764 | { | 764 | { |
765 | GNUNET_free (cache[i]->pke); | 765 | GNUNET_free (cache[i]->pke); |
766 | GNUNET_free (cache[i]); | 766 | GNUNET_free (cache[i]); |
767 | } | 767 | } |
768 | GNUNET_array_grow (cache, cacheSize, 0); | 768 | GNUNET_array_grow (cache, cacheSize, 0); |
769 | } | 769 | } |
770 | 770 | ||
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 5928b96ea..03f6c0e98 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c | |||
@@ -61,37 +61,37 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) | |||
61 | GNUNET_assert (i > 0); | 61 | GNUNET_assert (i > 0); |
62 | 62 | ||
63 | switch (mode) | 63 | switch (mode) |
64 | { | 64 | { |
65 | case GNUNET_CRYPTO_QUALITY_STRONG: | 65 | case GNUNET_CRYPTO_QUALITY_STRONG: |
66 | /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ | 66 | /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ |
67 | #ifdef gcry_fast_random_poll | 67 | #ifdef gcry_fast_random_poll |
68 | if ((invokeCount++ % 256) == 0) | 68 | if ((invokeCount++ % 256) == 0) |
69 | gcry_fast_random_poll (); | 69 | gcry_fast_random_poll (); |
70 | #endif | 70 | #endif |
71 | ul = UINT32_MAX - (UINT32_MAX % i); | 71 | ul = UINT32_MAX - (UINT32_MAX % i); |
72 | do | 72 | do |
73 | { | 73 | { |
74 | gcry_randomize ((unsigned char *) &ret, | 74 | gcry_randomize ((unsigned char *) &ret, |
75 | sizeof (uint32_t), GCRY_STRONG_RANDOM); | 75 | sizeof (uint32_t), GCRY_STRONG_RANDOM); |
76 | } | 76 | } |
77 | while (ret >= ul); | 77 | while (ret >= ul); |
78 | return ret % i; | 78 | return ret % i; |
79 | case GNUNET_CRYPTO_QUALITY_NONCE: | 79 | case GNUNET_CRYPTO_QUALITY_NONCE: |
80 | ul = UINT32_MAX - (UINT32_MAX % i); | 80 | ul = UINT32_MAX - (UINT32_MAX % i); |
81 | do | 81 | do |
82 | { | 82 | { |
83 | gcry_create_nonce(&ret, sizeof(ret)); | 83 | gcry_create_nonce (&ret, sizeof (ret)); |
84 | } | ||
85 | while (ret >= ul); | ||
86 | return ret % i; | ||
87 | case GNUNET_CRYPTO_QUALITY_WEAK: | ||
88 | ret = i * weak_random (); | ||
89 | if (ret >= i) | ||
90 | ret = i - 1; | ||
91 | return ret; | ||
92 | default: | ||
93 | GNUNET_assert (0); | ||
94 | } | 84 | } |
85 | while (ret >= ul); | ||
86 | return ret % i; | ||
87 | case GNUNET_CRYPTO_QUALITY_WEAK: | ||
88 | ret = i * weak_random (); | ||
89 | if (ret >= i) | ||
90 | ret = i - 1; | ||
91 | return ret; | ||
92 | default: | ||
93 | GNUNET_assert (0); | ||
94 | } | ||
95 | return 0; | 95 | return 0; |
96 | } | 96 | } |
97 | 97 | ||
@@ -117,12 +117,12 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) | |||
117 | for (i = 0; i < n; i++) | 117 | for (i = 0; i < n; i++) |
118 | ret[i] = i; | 118 | ret[i] = i; |
119 | for (i = n - 1; i > 0; i--) | 119 | for (i = n - 1; i > 0; i--) |
120 | { | 120 | { |
121 | x = GNUNET_CRYPTO_random_u32 (mode, i+1); | 121 | x = GNUNET_CRYPTO_random_u32 (mode, i + 1); |
122 | tmp = ret[x]; | 122 | tmp = ret[x]; |
123 | ret[x] = ret[i]; | 123 | ret[x] = ret[i]; |
124 | ret[i] = tmp; | 124 | ret[i] = tmp; |
125 | } | 125 | } |
126 | return ret; | 126 | return ret; |
127 | } | 127 | } |
128 | 128 | ||
@@ -142,33 +142,33 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) | |||
142 | 142 | ||
143 | GNUNET_assert (max > 0); | 143 | GNUNET_assert (max > 0); |
144 | switch (mode) | 144 | switch (mode) |
145 | { | ||
146 | case GNUNET_CRYPTO_QUALITY_STRONG: | ||
147 | ul = UINT64_MAX - (UINT64_MAX % max); | ||
148 | do | ||
145 | { | 149 | { |
146 | case GNUNET_CRYPTO_QUALITY_STRONG: | 150 | gcry_randomize ((unsigned char *) &ret, |
147 | ul = UINT64_MAX - (UINT64_MAX % max); | 151 | sizeof (uint64_t), GCRY_STRONG_RANDOM); |
148 | do | ||
149 | { | ||
150 | gcry_randomize ((unsigned char *) &ret, | ||
151 | sizeof (uint64_t), GCRY_STRONG_RANDOM); | ||
152 | } | ||
153 | while (ret >= ul); | ||
154 | return ret % max; | ||
155 | case GNUNET_CRYPTO_QUALITY_NONCE: | ||
156 | ul = UINT64_MAX - (UINT64_MAX % max); | ||
157 | do | ||
158 | { | ||
159 | gcry_create_nonce(&ret, sizeof(ret)); | ||
160 | } | ||
161 | while (ret >= ul); | ||
162 | |||
163 | return ret % max; | ||
164 | case GNUNET_CRYPTO_QUALITY_WEAK: | ||
165 | ret = max * weak_random (); | ||
166 | if (ret >= max) | ||
167 | ret = max - 1; | ||
168 | return ret; | ||
169 | default: | ||
170 | GNUNET_assert (0); | ||
171 | } | 152 | } |
153 | while (ret >= ul); | ||
154 | return ret % max; | ||
155 | case GNUNET_CRYPTO_QUALITY_NONCE: | ||
156 | ul = UINT64_MAX - (UINT64_MAX % max); | ||
157 | do | ||
158 | { | ||
159 | gcry_create_nonce (&ret, sizeof (ret)); | ||
160 | } | ||
161 | while (ret >= ul); | ||
162 | |||
163 | return ret % max; | ||
164 | case GNUNET_CRYPTO_QUALITY_WEAK: | ||
165 | ret = max * weak_random (); | ||
166 | if (ret >= max) | ||
167 | ret = max - 1; | ||
168 | return ret; | ||
169 | default: | ||
170 | GNUNET_assert (0); | ||
171 | } | ||
172 | return 0; | 172 | return 0; |
173 | } | 173 | } |
174 | 174 | ||
@@ -205,33 +205,33 @@ entropy_generator (void *cls, | |||
205 | if (0 != strcmp (what, "need_entropy")) | 205 | if (0 != strcmp (what, "need_entropy")) |
206 | return; | 206 | return; |
207 | if (current == total) | 207 | if (current == total) |
208 | { | ||
209 | if (genproc != NULL) | ||
208 | { | 210 | { |
209 | if (genproc != NULL) | ||
210 | { | ||
211 | if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) | ||
212 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); | ||
213 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); | ||
214 | GNUNET_OS_process_close (genproc); | ||
215 | genproc = NULL; | ||
216 | } | ||
217 | return; | ||
218 | } | ||
219 | if (genproc != NULL) | ||
220 | { | ||
221 | ret = GNUNET_OS_process_status (genproc, &type, &code); | ||
222 | if (ret == GNUNET_NO) | ||
223 | return; /* still running */ | ||
224 | if (ret == GNUNET_SYSERR) | ||
225 | { | ||
226 | GNUNET_break (0); | ||
227 | return; | ||
228 | } | ||
229 | if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) | 211 | if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) |
230 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); | 212 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); |
231 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); | 213 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); |
232 | GNUNET_OS_process_close (genproc); | 214 | GNUNET_OS_process_close (genproc); |
233 | genproc = NULL; | 215 | genproc = NULL; |
234 | } | 216 | } |
217 | return; | ||
218 | } | ||
219 | if (genproc != NULL) | ||
220 | { | ||
221 | ret = GNUNET_OS_process_status (genproc, &type, &code); | ||
222 | if (ret == GNUNET_NO) | ||
223 | return; /* still running */ | ||
224 | if (ret == GNUNET_SYSERR) | ||
225 | { | ||
226 | GNUNET_break (0); | ||
227 | return; | ||
228 | } | ||
229 | if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) | ||
230 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); | ||
231 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); | ||
232 | GNUNET_OS_process_close (genproc); | ||
233 | genproc = NULL; | ||
234 | } | ||
235 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 235 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
236 | _("Starting `%s' process to generate entropy\n"), "find"); | 236 | _("Starting `%s' process to generate entropy\n"), "find"); |
237 | genproc = GNUNET_OS_start_process (NULL, NULL, "sh", | 237 | genproc = GNUNET_OS_start_process (NULL, NULL, "sh", |
@@ -246,11 +246,11 @@ static void | |||
246 | killfind () | 246 | killfind () |
247 | { | 247 | { |
248 | if (genproc != NULL) | 248 | if (genproc != NULL) |
249 | { | 249 | { |
250 | GNUNET_OS_process_kill (genproc, SIGKILL); | 250 | GNUNET_OS_process_kill (genproc, SIGKILL); |
251 | GNUNET_OS_process_close (genproc); | 251 | GNUNET_OS_process_close (genproc); |
252 | genproc = NULL; | 252 | genproc = NULL; |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
@@ -258,19 +258,20 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () | |||
258 | { | 258 | { |
259 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); | 259 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); |
260 | if (!gcry_check_version (GCRYPT_VERSION)) | 260 | if (!gcry_check_version (GCRYPT_VERSION)) |
261 | { | 261 | { |
262 | fprintf (stderr, | 262 | fprintf (stderr, |
263 | _ | 263 | _ |
264 | ("libgcrypt has not the expected version (version %s is required).\n"), | 264 | ("libgcrypt has not the expected version (version %s is required).\n"), |
265 | GCRYPT_VERSION); | 265 | GCRYPT_VERSION); |
266 | abort (); | 266 | abort (); |
267 | } | 267 | } |
268 | #ifdef gcry_fast_random_poll | 268 | #ifdef gcry_fast_random_poll |
269 | gcry_fast_random_poll (); | 269 | gcry_fast_random_poll (); |
270 | #endif | 270 | #endif |
271 | gcry_set_progress_handler (&entropy_generator, NULL); | 271 | gcry_set_progress_handler (&entropy_generator, NULL); |
272 | atexit (&killfind); | 272 | atexit (&killfind); |
273 | SRANDOM (time (NULL) ^ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 273 | SRANDOM (time (NULL) ^ |
274 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | ||
274 | } | 275 | } |
275 | 276 | ||
276 | 277 | ||
@@ -282,4 +283,3 @@ void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini () | |||
282 | 283 | ||
283 | 284 | ||
284 | /* end of crypto_random.c */ | 285 | /* end of crypto_random.c */ |
285 | |||
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index e0f56dea0..6be2f53c0 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -92,10 +92,10 @@ static void | |||
92 | adjust (unsigned char *buf, size_t size, size_t target) | 92 | adjust (unsigned char *buf, size_t size, size_t target) |
93 | { | 93 | { |
94 | if (size < target) | 94 | if (size < target) |
95 | { | 95 | { |
96 | memmove (&buf[target - size], buf, size); | 96 | memmove (&buf[target - size], buf, size); |
97 | memset (buf, 0, target - size); | 97 | memset (buf, 0, target - size); |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
@@ -142,44 +142,44 @@ key_from_sexp (gcry_mpi_t * array, | |||
142 | 142 | ||
143 | list = gcry_sexp_find_token (sexp, topname, 0); | 143 | list = gcry_sexp_find_token (sexp, topname, 0); |
144 | if (!list) | 144 | if (!list) |
145 | { | 145 | { |
146 | return 1; | 146 | return 1; |
147 | } | 147 | } |
148 | l2 = gcry_sexp_cadr (list); | 148 | l2 = gcry_sexp_cadr (list); |
149 | gcry_sexp_release (list); | 149 | gcry_sexp_release (list); |
150 | list = l2; | 150 | list = l2; |
151 | if (!list) | 151 | if (!list) |
152 | { | 152 | { |
153 | return 2; | 153 | return 2; |
154 | } | 154 | } |
155 | 155 | ||
156 | idx = 0; | 156 | idx = 0; |
157 | for (s = elems; *s; s++, idx++) | 157 | for (s = elems; *s; s++, idx++) |
158 | { | ||
159 | l2 = gcry_sexp_find_token (list, s, 1); | ||
160 | if (!l2) | ||
158 | { | 161 | { |
159 | l2 = gcry_sexp_find_token (list, s, 1); | 162 | for (i = 0; i < idx; i++) |
160 | if (!l2) | 163 | { |
161 | { | 164 | gcry_free (array[i]); |
162 | for (i = 0; i < idx; i++) | 165 | array[i] = NULL; |
163 | { | 166 | } |
164 | gcry_free (array[i]); | 167 | gcry_sexp_release (list); |
165 | array[i] = NULL; | 168 | return 3; /* required parameter not found */ |
166 | } | 169 | } |
167 | gcry_sexp_release (list); | 170 | array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG); |
168 | return 3; /* required parameter not found */ | 171 | gcry_sexp_release (l2); |
169 | } | 172 | if (!array[idx]) |
170 | array[idx] = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG); | 173 | { |
171 | gcry_sexp_release (l2); | 174 | for (i = 0; i < idx; i++) |
172 | if (!array[idx]) | 175 | { |
173 | { | 176 | gcry_free (array[i]); |
174 | for (i = 0; i < idx; i++) | 177 | array[i] = NULL; |
175 | { | 178 | } |
176 | gcry_free (array[i]); | 179 | gcry_sexp_release (list); |
177 | array[i] = NULL; | 180 | return 4; /* required parameter is invalid */ |
178 | } | ||
179 | gcry_sexp_release (list); | ||
180 | return 4; /* required parameter is invalid */ | ||
181 | } | ||
182 | } | 181 | } |
182 | } | ||
183 | gcry_sexp_release (list); | 183 | gcry_sexp_release (list); |
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
@@ -193,8 +193,7 @@ void | |||
193 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | 193 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey |
194 | *priv, | 194 | *priv, |
195 | struct | 195 | struct |
196 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 196 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub) |
197 | *pub) | ||
198 | { | 197 | { |
199 | gcry_mpi_t skey[2]; | 198 | gcry_mpi_t skey[2]; |
200 | size_t size; | 199 | size_t size; |
@@ -207,16 +206,15 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | |||
207 | rc = key_from_sexp (skey, priv->sexp, "rsa", "ne"); | 206 | rc = key_from_sexp (skey, priv->sexp, "rsa", "ne"); |
208 | GNUNET_assert (0 == rc); | 207 | GNUNET_assert (0 == rc); |
209 | pub->len = | 208 | pub->len = |
210 | htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - | 209 | htons (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - |
211 | sizeof (pub->padding)); | 210 | sizeof (pub->padding)); |
212 | pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); | 211 | pub->sizen = htons (GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); |
213 | pub->padding = 0; | 212 | pub->padding = 0; |
214 | size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; | 213 | size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; |
215 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | 214 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, |
216 | &pub->key[0], size, &size, skey[0])); | 215 | &pub->key[0], size, &size, skey[0])); |
217 | adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); | 216 | adjust (&pub->key[0], size, GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH); |
218 | size = | 217 | size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; |
219 | GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; | ||
220 | GNUNET_assert (0 == | 218 | GNUNET_assert (0 == |
221 | gcry_mpi_print (GCRYMPI_FMT_USG, | 219 | gcry_mpi_print (GCRYMPI_FMT_USG, |
222 | &pub->key | 220 | &pub->key |
@@ -252,38 +250,36 @@ public2PrivateKey (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | |||
252 | (ntohs (publicKey->len) != | 250 | (ntohs (publicKey->len) != |
253 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - | 251 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) - |
254 | sizeof (publicKey->padding))) | 252 | sizeof (publicKey->padding))) |
255 | { | 253 | { |
256 | GNUNET_break (0); | 254 | GNUNET_break (0); |
257 | return NULL; | 255 | return NULL; |
258 | } | 256 | } |
259 | size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; | 257 | size = GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; |
260 | rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, &publicKey->key[0], size, &size); | 258 | rc = gcry_mpi_scan (&n, GCRYMPI_FMT_USG, &publicKey->key[0], size, &size); |
261 | if (rc) | 259 | if (rc) |
262 | { | 260 | { |
263 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 261 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
264 | return NULL; | 262 | return NULL; |
265 | } | 263 | } |
266 | size = | 264 | size = GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; |
267 | GNUNET_CRYPTO_RSA_KEY_LENGTH - GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH; | 265 | rc = gcry_mpi_scan (&e, GCRYMPI_FMT_USG, |
268 | rc = | 266 | &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], |
269 | gcry_mpi_scan (&e, GCRYMPI_FMT_USG, | 267 | size, &size); |
270 | &publicKey->key[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH], | ||
271 | size, &size); | ||
272 | if (rc) | 268 | if (rc) |
273 | { | 269 | { |
274 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 270 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
275 | gcry_mpi_release (n); | 271 | gcry_mpi_release (n); |
276 | return NULL; | 272 | return NULL; |
277 | } | 273 | } |
278 | rc = gcry_sexp_build (&result, | 274 | rc = gcry_sexp_build (&result, |
279 | &erroff, "(public-key(rsa(n %m)(e %m)))", n, e); | 275 | &erroff, "(public-key(rsa(n %m)(e %m)))", n, e); |
280 | gcry_mpi_release (n); | 276 | gcry_mpi_release (n); |
281 | gcry_mpi_release (e); | 277 | gcry_mpi_release (e); |
282 | if (rc) | 278 | if (rc) |
283 | { | 279 | { |
284 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */ | 280 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */ |
285 | return NULL; | 281 | return NULL; |
286 | } | 282 | } |
287 | ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); | 283 | ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); |
288 | ret->sexp = result; | 284 | ret->sexp = result; |
289 | return ret; | 285 | return ret; |
@@ -309,10 +305,10 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
309 | 305 | ||
310 | #if EXTRA_CHECKS | 306 | #if EXTRA_CHECKS |
311 | if (gcry_pk_testkey (hostkey->sexp)) | 307 | if (gcry_pk_testkey (hostkey->sexp)) |
312 | { | 308 | { |
313 | GNUNET_break (0); | 309 | GNUNET_break (0); |
314 | return NULL; | 310 | return NULL; |
315 | } | 311 | } |
316 | #endif | 312 | #endif |
317 | 313 | ||
318 | memset (pkv, 0, sizeof (gcry_mpi_t) * 6); | 314 | memset (pkv, 0, sizeof (gcry_mpi_t) * 6); |
@@ -330,20 +326,20 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
330 | GNUNET_assert (0 == rc); | 326 | GNUNET_assert (0 == rc); |
331 | size = sizeof (struct RsaPrivateKeyBinaryEncoded); | 327 | size = sizeof (struct RsaPrivateKeyBinaryEncoded); |
332 | for (i = 0; i < 6; i++) | 328 | for (i = 0; i < 6; i++) |
329 | { | ||
330 | if (pkv[i] != NULL) | ||
333 | { | 331 | { |
334 | if (pkv[i] != NULL) | 332 | GNUNET_assert (0 == gcry_mpi_aprint (GCRYMPI_FMT_USG, |
335 | { | 333 | (unsigned char **) &pbu[i], |
336 | GNUNET_assert (0 == gcry_mpi_aprint (GCRYMPI_FMT_USG, | 334 | &sizes[i], pkv[i])); |
337 | (unsigned char **) &pbu[i], | 335 | size += sizes[i]; |
338 | &sizes[i], pkv[i])); | ||
339 | size += sizes[i]; | ||
340 | } | ||
341 | else | ||
342 | { | ||
343 | pbu[i] = NULL; | ||
344 | sizes[i] = 0; | ||
345 | } | ||
346 | } | 336 | } |
337 | else | ||
338 | { | ||
339 | pbu[i] = NULL; | ||
340 | sizes[i] = 0; | ||
341 | } | ||
342 | } | ||
347 | GNUNET_assert (size < 65536); | 343 | GNUNET_assert (size < 65536); |
348 | retval = GNUNET_malloc (size); | 344 | retval = GNUNET_malloc (size); |
349 | retval->len = htons (size); | 345 | retval->len = htons (size); |
@@ -368,12 +364,12 @@ rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
368 | retval->sizedmq1 = htons (0); | 364 | retval->sizedmq1 = htons (0); |
369 | memcpy (&((char *) (&retval[1]))[i], pbu[5], sizes[5]); | 365 | memcpy (&((char *) (&retval[1]))[i], pbu[5], sizes[5]); |
370 | for (i = 0; i < 6; i++) | 366 | for (i = 0; i < 6; i++) |
371 | { | 367 | { |
372 | if (pkv[i] != NULL) | 368 | if (pkv[i] != NULL) |
373 | gcry_mpi_release (pkv[i]); | 369 | gcry_mpi_release (pkv[i]); |
374 | if (pbu[i] != NULL) | 370 | if (pbu[i] != NULL) |
375 | free (pbu[i]); | 371 | free (pbu[i]); |
376 | } | 372 | } |
377 | return retval; | 373 | return retval; |
378 | } | 374 | } |
379 | 375 | ||
@@ -388,7 +384,8 @@ struct GNUNET_CRYPTO_RsaPrivateKey * | |||
388 | GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | 384 | GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) |
389 | { | 385 | { |
390 | struct GNUNET_CRYPTO_RsaPrivateKey *ret; | 386 | struct GNUNET_CRYPTO_RsaPrivateKey *ret; |
391 | const struct RsaPrivateKeyBinaryEncoded *encoding = (const struct RsaPrivateKeyBinaryEncoded *)buf; | 387 | const struct RsaPrivateKeyBinaryEncoded *encoding = |
388 | (const struct RsaPrivateKeyBinaryEncoded *) buf; | ||
392 | gcry_sexp_t res; | 389 | gcry_sexp_t res; |
393 | gcry_mpi_t n, e, d, p, q, u; | 390 | gcry_mpi_t n, e, d, p, q, u; |
394 | int rc; | 391 | int rc; |
@@ -396,7 +393,7 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
396 | int pos; | 393 | int pos; |
397 | uint16_t enc_len; | 394 | uint16_t enc_len; |
398 | 395 | ||
399 | enc_len = ntohs(encoding->len); | 396 | enc_len = ntohs (encoding->len); |
400 | if (len != enc_len) | 397 | if (len != enc_len) |
401 | return NULL; | 398 | return NULL; |
402 | 399 | ||
@@ -408,10 +405,10 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
408 | size, &size); | 405 | size, &size); |
409 | pos += ntohs (encoding->sizen); | 406 | pos += ntohs (encoding->sizen); |
410 | if (rc) | 407 | if (rc) |
411 | { | 408 | { |
412 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 409 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
413 | return NULL; | 410 | return NULL; |
414 | } | 411 | } |
415 | size = ntohs (encoding->sizee); | 412 | size = ntohs (encoding->sizee); |
416 | rc = gcry_mpi_scan (&e, | 413 | rc = gcry_mpi_scan (&e, |
417 | GCRYMPI_FMT_USG, | 414 | GCRYMPI_FMT_USG, |
@@ -419,11 +416,11 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
419 | size, &size); | 416 | size, &size); |
420 | pos += ntohs (encoding->sizee); | 417 | pos += ntohs (encoding->sizee); |
421 | if (rc) | 418 | if (rc) |
422 | { | 419 | { |
423 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 420 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
424 | gcry_mpi_release (n); | 421 | gcry_mpi_release (n); |
425 | return NULL; | 422 | return NULL; |
426 | } | 423 | } |
427 | size = ntohs (encoding->sized); | 424 | size = ntohs (encoding->sized); |
428 | rc = gcry_mpi_scan (&d, | 425 | rc = gcry_mpi_scan (&d, |
429 | GCRYMPI_FMT_USG, | 426 | GCRYMPI_FMT_USG, |
@@ -431,100 +428,99 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
431 | size, &size); | 428 | size, &size); |
432 | pos += ntohs (encoding->sized); | 429 | pos += ntohs (encoding->sized); |
433 | if (rc) | 430 | if (rc) |
431 | { | ||
432 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | ||
433 | gcry_mpi_release (n); | ||
434 | gcry_mpi_release (e); | ||
435 | return NULL; | ||
436 | } | ||
437 | /* swap p and q! */ | ||
438 | size = ntohs (encoding->sizep); | ||
439 | if (size > 0) | ||
440 | { | ||
441 | rc = gcry_mpi_scan (&q, | ||
442 | GCRYMPI_FMT_USG, | ||
443 | &((const unsigned char *) (&encoding[1]))[pos], | ||
444 | size, &size); | ||
445 | pos += ntohs (encoding->sizep); | ||
446 | if (rc) | ||
434 | { | 447 | { |
435 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 448 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
436 | gcry_mpi_release (n); | 449 | gcry_mpi_release (n); |
437 | gcry_mpi_release (e); | 450 | gcry_mpi_release (e); |
451 | gcry_mpi_release (d); | ||
438 | return NULL; | 452 | return NULL; |
439 | } | 453 | } |
440 | /* swap p and q! */ | 454 | } |
441 | size = ntohs (encoding->sizep); | ||
442 | if (size > 0) | ||
443 | { | ||
444 | rc = gcry_mpi_scan (&q, | ||
445 | GCRYMPI_FMT_USG, | ||
446 | &((const unsigned char *) (&encoding[1]))[pos], | ||
447 | size, &size); | ||
448 | pos += ntohs (encoding->sizep); | ||
449 | if (rc) | ||
450 | { | ||
451 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | ||
452 | gcry_mpi_release (n); | ||
453 | gcry_mpi_release (e); | ||
454 | gcry_mpi_release (d); | ||
455 | return NULL; | ||
456 | } | ||
457 | } | ||
458 | else | 455 | else |
459 | q = NULL; | 456 | q = NULL; |
460 | size = ntohs (encoding->sizeq); | 457 | size = ntohs (encoding->sizeq); |
461 | if (size > 0) | 458 | if (size > 0) |
459 | { | ||
460 | rc = gcry_mpi_scan (&p, | ||
461 | GCRYMPI_FMT_USG, | ||
462 | &((const unsigned char *) (&encoding[1]))[pos], | ||
463 | size, &size); | ||
464 | pos += ntohs (encoding->sizeq); | ||
465 | if (rc) | ||
462 | { | 466 | { |
463 | rc = gcry_mpi_scan (&p, | 467 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
464 | GCRYMPI_FMT_USG, | 468 | gcry_mpi_release (n); |
465 | &((const unsigned char *) (&encoding[1]))[pos], | 469 | gcry_mpi_release (e); |
466 | size, &size); | 470 | gcry_mpi_release (d); |
467 | pos += ntohs (encoding->sizeq); | 471 | if (q != NULL) |
468 | if (rc) | 472 | gcry_mpi_release (q); |
469 | { | 473 | return NULL; |
470 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | ||
471 | gcry_mpi_release (n); | ||
472 | gcry_mpi_release (e); | ||
473 | gcry_mpi_release (d); | ||
474 | if (q != NULL) | ||
475 | gcry_mpi_release (q); | ||
476 | return NULL; | ||
477 | } | ||
478 | } | 474 | } |
475 | } | ||
479 | else | 476 | else |
480 | p = NULL; | 477 | p = NULL; |
481 | pos += ntohs (encoding->sizedmp1); | 478 | pos += ntohs (encoding->sizedmp1); |
482 | pos += ntohs (encoding->sizedmq1); | 479 | pos += ntohs (encoding->sizedmq1); |
483 | size = | 480 | size = |
484 | ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; | 481 | ntohs (encoding->len) - sizeof (struct RsaPrivateKeyBinaryEncoded) - pos; |
485 | if (size > 0) | 482 | if (size > 0) |
483 | { | ||
484 | rc = gcry_mpi_scan (&u, | ||
485 | GCRYMPI_FMT_USG, | ||
486 | &((const unsigned char *) (&encoding[1]))[pos], | ||
487 | size, &size); | ||
488 | if (rc) | ||
486 | { | 489 | { |
487 | rc = gcry_mpi_scan (&u, | 490 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
488 | GCRYMPI_FMT_USG, | 491 | gcry_mpi_release (n); |
489 | &((const unsigned char *) (&encoding[1]))[pos], | 492 | gcry_mpi_release (e); |
490 | size, &size); | 493 | gcry_mpi_release (d); |
491 | if (rc) | 494 | if (p != NULL) |
492 | { | 495 | gcry_mpi_release (p); |
493 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 496 | if (q != NULL) |
494 | gcry_mpi_release (n); | 497 | gcry_mpi_release (q); |
495 | gcry_mpi_release (e); | 498 | return NULL; |
496 | gcry_mpi_release (d); | ||
497 | if (p != NULL) | ||
498 | gcry_mpi_release (p); | ||
499 | if (q != NULL) | ||
500 | gcry_mpi_release (q); | ||
501 | return NULL; | ||
502 | } | ||
503 | } | 499 | } |
500 | } | ||
504 | else | 501 | else |
505 | u = NULL; | 502 | u = NULL; |
506 | 503 | ||
507 | if ((p != NULL) && (q != NULL) && (u != NULL)) | 504 | if ((p != NULL) && (q != NULL) && (u != NULL)) |
505 | { | ||
506 | rc = gcry_sexp_build (&res, &size, /* erroff */ | ||
507 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", | ||
508 | n, e, d, p, q, u); | ||
509 | } | ||
510 | else | ||
511 | { | ||
512 | if ((p != NULL) && (q != NULL)) | ||
508 | { | 513 | { |
509 | rc = gcry_sexp_build (&res, &size, /* erroff */ | 514 | rc = gcry_sexp_build (&res, &size, /* erroff */ |
510 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)(u %m)))", | 515 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", |
511 | n, e, d, p, q, u); | 516 | n, e, d, p, q); |
512 | } | 517 | } |
513 | else | 518 | else |
514 | { | 519 | { |
515 | if ((p != NULL) && (q != NULL)) | 520 | rc = gcry_sexp_build (&res, &size, /* erroff */ |
516 | { | 521 | "(private-key(rsa(n %m)(e %m)(d %m)))", n, e, d); |
517 | rc = gcry_sexp_build (&res, &size, /* erroff */ | ||
518 | "(private-key(rsa(n %m)(e %m)(d %m)(p %m)(q %m)))", | ||
519 | n, e, d, p, q); | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | rc = gcry_sexp_build (&res, &size, /* erroff */ | ||
524 | "(private-key(rsa(n %m)(e %m)(d %m)))", | ||
525 | n, e, d); | ||
526 | } | ||
527 | } | 522 | } |
523 | } | ||
528 | gcry_mpi_release (n); | 524 | gcry_mpi_release (n); |
529 | gcry_mpi_release (e); | 525 | gcry_mpi_release (e); |
530 | gcry_mpi_release (d); | 526 | gcry_mpi_release (d); |
@@ -539,10 +535,10 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len) | |||
539 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); | 535 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); |
540 | #if EXTRA_CHECKS | 536 | #if EXTRA_CHECKS |
541 | if (gcry_pk_testkey (res)) | 537 | if (gcry_pk_testkey (res)) |
542 | { | 538 | { |
543 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); | 539 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); |
544 | return NULL; | 540 | return NULL; |
545 | } | 541 | } |
546 | #endif | 542 | #endif |
547 | ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); | 543 | ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); |
548 | ret->sexp = res; | 544 | ret->sexp = res; |
@@ -579,167 +575,156 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
579 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) | 575 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) |
580 | return NULL; | 576 | return NULL; |
581 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 577 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
578 | { | ||
579 | fd = GNUNET_DISK_file_open (filename, | ||
580 | GNUNET_DISK_OPEN_WRITE | | ||
581 | GNUNET_DISK_OPEN_CREATE | | ||
582 | GNUNET_DISK_OPEN_FAILIFEXISTS, | ||
583 | GNUNET_DISK_PERM_USER_READ | | ||
584 | GNUNET_DISK_PERM_USER_WRITE); | ||
585 | if (NULL == fd) | ||
582 | { | 586 | { |
583 | fd = GNUNET_DISK_file_open (filename, | 587 | if (errno == EEXIST) |
584 | GNUNET_DISK_OPEN_WRITE | | 588 | { |
585 | GNUNET_DISK_OPEN_CREATE | | 589 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
586 | GNUNET_DISK_OPEN_FAILIFEXISTS, | ||
587 | GNUNET_DISK_PERM_USER_READ | | ||
588 | GNUNET_DISK_PERM_USER_WRITE); | ||
589 | if (NULL == fd) | ||
590 | { | 590 | { |
591 | if (errno == EEXIST) | 591 | /* must exist but not be accessible, fail for good! */ |
592 | { | 592 | if (0 != ACCESS (filename, R_OK)) |
593 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 593 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
594 | { | 594 | "access", filename); |
595 | /* must exist but not be accessible, fail for good! */ | 595 | else |
596 | if (0 != ACCESS (filename, R_OK)) | 596 | GNUNET_break (0); /* what is going on!? */ |
597 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
598 | "access", filename); | ||
599 | else | ||
600 | GNUNET_break (0); /* what is going on!? */ | ||
601 | return NULL; | ||
602 | } | ||
603 | continue; | ||
604 | } | ||
605 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
606 | "open", filename); | ||
607 | return NULL; | 597 | return NULL; |
608 | } | 598 | } |
609 | cnt = 0; | 599 | continue; |
600 | } | ||
601 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); | ||
602 | return NULL; | ||
603 | } | ||
604 | cnt = 0; | ||
610 | 605 | ||
611 | while (GNUNET_YES != | 606 | while (GNUNET_YES != |
612 | GNUNET_DISK_file_lock (fd, 0, | 607 | GNUNET_DISK_file_lock (fd, 0, |
613 | sizeof (struct | 608 | sizeof (struct |
614 | RsaPrivateKeyBinaryEncoded), | 609 | RsaPrivateKeyBinaryEncoded), |
615 | GNUNET_YES)) | 610 | GNUNET_YES)) |
616 | { | 611 | { |
617 | sleep (1); | 612 | sleep (1); |
618 | if (0 == ++cnt % 10) | 613 | if (0 == ++cnt % 10) |
619 | { | 614 | { |
620 | ec = errno; | 615 | ec = errno; |
621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 616 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
622 | _ | 617 | _ |
623 | ("Could not aquire lock on file `%s': %s...\n"), | 618 | ("Could not aquire lock on file `%s': %s...\n"), |
624 | filename, STRERROR (ec)); | 619 | filename, STRERROR (ec)); |
625 | } | 620 | } |
626 | } | ||
627 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
628 | _("Creating a new private key. This may take a while.\n")); | ||
629 | ret = GNUNET_CRYPTO_rsa_key_create (); | ||
630 | GNUNET_assert (ret != NULL); | ||
631 | enc = rsa_encode_key (ret); | ||
632 | GNUNET_assert (enc != NULL); | ||
633 | GNUNET_assert (ntohs (enc->len) == | ||
634 | GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); | ||
635 | GNUNET_free (enc); | ||
636 | |||
637 | GNUNET_DISK_file_sync (fd); | ||
638 | if (GNUNET_YES != | ||
639 | GNUNET_DISK_file_unlock (fd, 0, | ||
640 | sizeof (struct | ||
641 | RsaPrivateKeyBinaryEncoded))) | ||
642 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", | ||
643 | filename); | ||
644 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | ||
645 | GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); | ||
646 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); | ||
647 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
648 | _("I am host `%s'. Stored new private key in `%s'.\n"), | ||
649 | GNUNET_i2s (&pid), | ||
650 | filename); | ||
651 | return ret; | ||
652 | } | 621 | } |
622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
623 | _("Creating a new private key. This may take a while.\n")); | ||
624 | ret = GNUNET_CRYPTO_rsa_key_create (); | ||
625 | GNUNET_assert (ret != NULL); | ||
626 | enc = rsa_encode_key (ret); | ||
627 | GNUNET_assert (enc != NULL); | ||
628 | GNUNET_assert (ntohs (enc->len) == | ||
629 | GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); | ||
630 | GNUNET_free (enc); | ||
631 | |||
632 | GNUNET_DISK_file_sync (fd); | ||
633 | if (GNUNET_YES != | ||
634 | GNUNET_DISK_file_unlock (fd, 0, | ||
635 | sizeof (struct RsaPrivateKeyBinaryEncoded))) | ||
636 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | ||
637 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | ||
638 | GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); | ||
639 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); | ||
640 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
641 | _("I am host `%s'. Stored new private key in `%s'.\n"), | ||
642 | GNUNET_i2s (&pid), filename); | ||
643 | return ret; | ||
644 | } | ||
653 | /* hostkey file exists already, read it! */ | 645 | /* hostkey file exists already, read it! */ |
654 | fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, | 646 | fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, |
655 | GNUNET_DISK_PERM_NONE); | 647 | GNUNET_DISK_PERM_NONE); |
656 | if (NULL == fd) | 648 | if (NULL == fd) |
657 | { | 649 | { |
658 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); | 650 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); |
659 | return NULL; | 651 | return NULL; |
660 | } | 652 | } |
661 | cnt = 0; | 653 | cnt = 0; |
662 | while (1) | 654 | while (1) |
655 | { | ||
656 | if (GNUNET_YES != | ||
657 | GNUNET_DISK_file_lock (fd, 0, | ||
658 | sizeof (struct RsaPrivateKeyBinaryEncoded), | ||
659 | GNUNET_NO)) | ||
663 | { | 660 | { |
661 | if (0 == ++cnt % 60) | ||
662 | { | ||
663 | ec = errno; | ||
664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
665 | _("Could not aquire lock on file `%s': %s...\n"), | ||
666 | filename, STRERROR (ec)); | ||
667 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
668 | _ | ||
669 | ("This may be ok if someone is currently generating a hostkey.\n")); | ||
670 | } | ||
671 | sleep (1); | ||
672 | continue; | ||
673 | } | ||
674 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
675 | { | ||
676 | /* eh, what!? File we opened is now gone!? */ | ||
677 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | ||
664 | if (GNUNET_YES != | 678 | if (GNUNET_YES != |
665 | GNUNET_DISK_file_lock (fd, 0, | 679 | GNUNET_DISK_file_unlock (fd, 0, |
666 | sizeof (struct RsaPrivateKeyBinaryEncoded), | 680 | sizeof (struct RsaPrivateKeyBinaryEncoded))) |
667 | GNUNET_NO)) | 681 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
668 | { | 682 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); |
669 | if (0 == ++cnt % 60) | ||
670 | { | ||
671 | ec = errno; | ||
672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
673 | _("Could not aquire lock on file `%s': %s...\n"), | ||
674 | filename, STRERROR (ec)); | ||
675 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
676 | _ | ||
677 | ("This may be ok if someone is currently generating a hostkey.\n")); | ||
678 | } | ||
679 | sleep (1); | ||
680 | continue; | ||
681 | } | ||
682 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
683 | { | ||
684 | /* eh, what!? File we opened is now gone!? */ | ||
685 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
686 | "stat", filename); | ||
687 | if (GNUNET_YES != | ||
688 | GNUNET_DISK_file_unlock (fd, 0, | ||
689 | sizeof (struct | ||
690 | RsaPrivateKeyBinaryEncoded))) | ||
691 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", | ||
692 | filename); | ||
693 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
694 | 683 | ||
695 | return NULL; | 684 | return NULL; |
696 | } | 685 | } |
697 | if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES)) | 686 | if (GNUNET_YES != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES)) |
698 | fs = 0; | 687 | fs = 0; |
699 | if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded)) | 688 | if (fs < sizeof (struct RsaPrivateKeyBinaryEncoded)) |
700 | { | 689 | { |
701 | /* maybe we got the read lock before the hostkey generating | 690 | /* maybe we got the read lock before the hostkey generating |
702 | process had a chance to get the write lock; give it up! */ | 691 | * process had a chance to get the write lock; give it up! */ |
703 | if (GNUNET_YES != | 692 | if (GNUNET_YES != |
704 | GNUNET_DISK_file_unlock (fd, 0, | 693 | GNUNET_DISK_file_unlock (fd, 0, |
705 | sizeof (struct | 694 | sizeof (struct RsaPrivateKeyBinaryEncoded))) |
706 | RsaPrivateKeyBinaryEncoded))) | 695 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
707 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", | 696 | if (0 == ++cnt % 10) |
708 | filename); | 697 | { |
709 | if (0 == ++cnt % 10) | 698 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
710 | { | 699 | _ |
711 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 700 | ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"), |
712 | _ | 701 | filename, (unsigned int) fs, |
713 | ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"), | 702 | (unsigned int) sizeof (struct RsaPrivateKeyBinaryEncoded)); |
714 | filename, (unsigned int) fs, | 703 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
715 | (unsigned int) sizeof (struct | 704 | _ |
716 | RsaPrivateKeyBinaryEncoded)); | 705 | ("This may be ok if someone is currently generating a hostkey.\n")); |
717 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 706 | } |
718 | _ | 707 | sleep (2); /* wait a bit longer! */ |
719 | ("This may be ok if someone is currently generating a hostkey.\n")); | 708 | continue; |
720 | } | ||
721 | sleep (2); /* wait a bit longer! */ | ||
722 | continue; | ||
723 | } | ||
724 | break; | ||
725 | } | 709 | } |
710 | break; | ||
711 | } | ||
726 | enc = GNUNET_malloc (fs); | 712 | enc = GNUNET_malloc (fs); |
727 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs)); | 713 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, enc, fs)); |
728 | len = ntohs (enc->len); | 714 | len = ntohs (enc->len); |
729 | ret = NULL; | 715 | ret = NULL; |
730 | if ((len != fs) || (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *)enc, len)))) | 716 | if ((len != fs) || |
717 | (NULL == (ret = GNUNET_CRYPTO_rsa_decode_key ((char *) enc, len)))) | ||
718 | { | ||
719 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
720 | _ | ||
721 | ("File `%s' does not contain a valid private key. Deleting it.\n"), | ||
722 | filename); | ||
723 | if (0 != UNLINK (filename)) | ||
731 | { | 724 | { |
732 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 725 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
733 | _ | ||
734 | ("File `%s' does not contain a valid private key. Deleting it.\n"), | ||
735 | filename); | ||
736 | if (0 != UNLINK (filename)) | ||
737 | { | ||
738 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
739 | "unlink", | ||
740 | filename); | ||
741 | } | ||
742 | } | 726 | } |
727 | } | ||
743 | GNUNET_free (enc); | 728 | GNUNET_free (enc); |
744 | if (GNUNET_YES != | 729 | if (GNUNET_YES != |
745 | GNUNET_DISK_file_unlock (fd, 0, | 730 | GNUNET_DISK_file_unlock (fd, 0, |
@@ -747,14 +732,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
747 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 732 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
748 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 733 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
749 | if (ret != NULL) | 734 | if (ret != NULL) |
750 | { | 735 | { |
751 | GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); | 736 | GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); |
752 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); | 737 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); |
753 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 738 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
754 | _("I am host `%s'. Read private key from `%s'.\n"), | 739 | _("I am host `%s'. Read private key from `%s'.\n"), |
755 | GNUNET_i2s (&pid), | 740 | GNUNET_i2s (&pid), filename); |
756 | filename); | 741 | } |
757 | } | ||
758 | return ret; | 742 | return ret; |
759 | } | 743 | } |
760 | 744 | ||
@@ -853,8 +837,7 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key, | |||
853 | gcry_sexp_release (resultsexp); | 837 | gcry_sexp_release (resultsexp); |
854 | tmp = GNUNET_malloc (max + HOSTKEY_LEN / 8); | 838 | tmp = GNUNET_malloc (max + HOSTKEY_LEN / 8); |
855 | size = max + HOSTKEY_LEN / 8; | 839 | size = max + HOSTKEY_LEN / 8; |
856 | GNUNET_assert (0 == | 840 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val)); |
857 | gcry_mpi_print (GCRYMPI_FMT_USG, tmp, size, &size, val)); | ||
858 | gcry_mpi_release (val); | 841 | gcry_mpi_release (val); |
859 | endp = tmp; | 842 | endp = tmp; |
860 | endp += (size - max); | 843 | endp += (size - max); |
@@ -946,8 +929,7 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | |||
946 | size = sizeof (struct GNUNET_CRYPTO_RsaSignature); | 929 | size = sizeof (struct GNUNET_CRYPTO_RsaSignature); |
947 | GNUNET_assert (0 == gcry_mpi_scan (&val, | 930 | GNUNET_assert (0 == gcry_mpi_scan (&val, |
948 | GCRYMPI_FMT_USG, | 931 | GCRYMPI_FMT_USG, |
949 | (const unsigned char *) sig, size, | 932 | (const unsigned char *) sig, size, &size)); |
950 | &size)); | ||
951 | GNUNET_assert (0 == | 933 | GNUNET_assert (0 == |
952 | gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", | 934 | gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))", |
953 | val)); | 935 | val)); |
@@ -963,22 +945,22 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, | |||
963 | GNUNET_free (buff); | 945 | GNUNET_free (buff); |
964 | hostkey = public2PrivateKey (publicKey); | 946 | hostkey = public2PrivateKey (publicKey); |
965 | if (hostkey == NULL) | 947 | if (hostkey == NULL) |
966 | { | 948 | { |
967 | gcry_sexp_release (data); | 949 | gcry_sexp_release (data); |
968 | gcry_sexp_release (sigdata); | 950 | gcry_sexp_release (sigdata); |
969 | return GNUNET_SYSERR; | 951 | return GNUNET_SYSERR; |
970 | } | 952 | } |
971 | rc = gcry_pk_verify (sigdata, data, hostkey->sexp); | 953 | rc = gcry_pk_verify (sigdata, data, hostkey->sexp); |
972 | GNUNET_CRYPTO_rsa_key_free (hostkey); | 954 | GNUNET_CRYPTO_rsa_key_free (hostkey); |
973 | gcry_sexp_release (data); | 955 | gcry_sexp_release (data); |
974 | gcry_sexp_release (sigdata); | 956 | gcry_sexp_release (sigdata); |
975 | if (rc) | 957 | if (rc) |
976 | { | 958 | { |
977 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 959 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
978 | _("RSA signature verification failed at %s:%d: %s\n"), | 960 | _("RSA signature verification failed at %s:%d: %s\n"), |
979 | __FILE__, __LINE__, gcry_strerror (rc)); | 961 | __FILE__, __LINE__, gcry_strerror (rc)); |
980 | return GNUNET_SYSERR; | 962 | return GNUNET_SYSERR; |
981 | } | 963 | } |
982 | return GNUNET_OK; | 964 | return GNUNET_OK; |
983 | } | 965 | } |
984 | 966 | ||
diff --git a/src/util/disk.c b/src/util/disk.c index 31b610fe8..dd7db7d73 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -109,7 +109,8 @@ struct GetFileSizeData | |||
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | int translate_unix_perms(enum GNUNET_DISK_AccessPermissions perm) | 112 | int |
113 | translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm) | ||
113 | { | 114 | { |
114 | int mode; | 115 | int mode; |
115 | 116 | ||
@@ -149,6 +150,7 @@ static int | |||
149 | getSizeRec (void *cls, const char *fn) | 150 | getSizeRec (void *cls, const char *fn) |
150 | { | 151 | { |
151 | struct GetFileSizeData *gfsd = cls; | 152 | struct GetFileSizeData *gfsd = cls; |
153 | |||
152 | #ifdef HAVE_STAT64 | 154 | #ifdef HAVE_STAT64 |
153 | struct stat64 buf; | 155 | struct stat64 buf; |
154 | #else | 156 | #else |
@@ -157,26 +159,26 @@ getSizeRec (void *cls, const char *fn) | |||
157 | 159 | ||
158 | #ifdef HAVE_STAT64 | 160 | #ifdef HAVE_STAT64 |
159 | if (0 != STAT64 (fn, &buf)) | 161 | if (0 != STAT64 (fn, &buf)) |
160 | { | 162 | { |
161 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat64", fn); | 163 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat64", fn); |
162 | return GNUNET_SYSERR; | 164 | return GNUNET_SYSERR; |
163 | } | 165 | } |
164 | #else | 166 | #else |
165 | if (0 != STAT (fn, &buf)) | 167 | if (0 != STAT (fn, &buf)) |
166 | { | 168 | { |
167 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", fn); | 169 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", fn); |
168 | return GNUNET_SYSERR; | 170 | return GNUNET_SYSERR; |
169 | } | 171 | } |
170 | #endif | 172 | #endif |
171 | if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) | 173 | if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)) |
172 | gfsd->total += buf.st_size; | 174 | gfsd->total += buf.st_size; |
173 | if ((S_ISDIR (buf.st_mode)) && | 175 | if ((S_ISDIR (buf.st_mode)) && |
174 | (0 == ACCESS (fn, X_OK)) && | 176 | (0 == ACCESS (fn, X_OK)) && |
175 | ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) | 177 | ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) |
176 | { | 178 | { |
177 | if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) | 179 | if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) |
178 | return GNUNET_SYSERR; | 180 | return GNUNET_SYSERR; |
179 | } | 181 | } |
180 | return GNUNET_OK; | 182 | return GNUNET_OK; |
181 | } | 183 | } |
182 | 184 | ||
@@ -211,23 +213,24 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, | |||
211 | enum GNUNET_DISK_Seek whence) | 213 | enum GNUNET_DISK_Seek whence) |
212 | { | 214 | { |
213 | if (h == NULL) | 215 | if (h == NULL) |
214 | { | 216 | { |
215 | errno = EINVAL; | 217 | errno = EINVAL; |
216 | return GNUNET_SYSERR; | 218 | return GNUNET_SYSERR; |
217 | } | 219 | } |
218 | 220 | ||
219 | #ifdef MINGW | 221 | #ifdef MINGW |
220 | DWORD ret; | 222 | DWORD ret; |
223 | |||
221 | static DWORD t[] = {[GNUNET_DISK_SEEK_SET] = FILE_BEGIN, | 224 | static DWORD t[] = {[GNUNET_DISK_SEEK_SET] = FILE_BEGIN, |
222 | [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT,[GNUNET_DISK_SEEK_END] = FILE_END | 225 | [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT,[GNUNET_DISK_SEEK_END] = FILE_END |
223 | }; | 226 | }; |
224 | 227 | ||
225 | ret = SetFilePointer (h->h, offset, NULL, t[whence]); | 228 | ret = SetFilePointer (h->h, offset, NULL, t[whence]); |
226 | if (ret == INVALID_SET_FILE_POINTER) | 229 | if (ret == INVALID_SET_FILE_POINTER) |
227 | { | 230 | { |
228 | SetErrnoFromWinError (GetLastError ()); | 231 | SetErrnoFromWinError (GetLastError ()); |
229 | return GNUNET_SYSERR; | 232 | return GNUNET_SYSERR; |
230 | } | 233 | } |
231 | return ret; | 234 | return ret; |
232 | #else | 235 | #else |
233 | static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET, | 236 | static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET, |
@@ -291,39 +294,39 @@ GNUNET_DISK_file_get_identifiers (const char *filename, | |||
291 | struct statvfs fbuf; | 294 | struct statvfs fbuf; |
292 | 295 | ||
293 | if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf))) | 296 | if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf))) |
294 | { | 297 | { |
295 | *dev = (uint64_t) fbuf.f_fsid; | 298 | *dev = (uint64_t) fbuf.f_fsid; |
296 | *ino = (uint64_t) sbuf.st_ino; | 299 | *ino = (uint64_t) sbuf.st_ino; |
297 | return GNUNET_OK; | 300 | return GNUNET_OK; |
298 | } | 301 | } |
299 | #elif SOMEBSD | 302 | #elif SOMEBSD |
300 | struct stat sbuf; | 303 | struct stat sbuf; |
301 | struct statfs fbuf; | 304 | struct statfs fbuf; |
302 | 305 | ||
303 | if ( (0 == stat (filename, &sbuf)) && | 306 | if ((0 == stat (filename, &sbuf)) && (0 == statfs (filename, &fbuf))) |
304 | (0 == statfs (filename, &fbuf) ) ) | 307 | { |
305 | { | 308 | *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || |
306 | *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]); | 309 | ((uint64_t) fbuf.f_fsid.val[1]); |
307 | *ino = (uint64_t) sbuf.st_ino; | 310 | *ino = (uint64_t) sbuf.st_ino; |
308 | return GNUNET_OK; | 311 | return GNUNET_OK; |
309 | } | 312 | } |
310 | #elif WINDOWS | 313 | #elif WINDOWS |
311 | // FIXME NILS: test this | 314 | // FIXME NILS: test this |
312 | struct GNUNET_DISK_FileHandle *fh; | 315 | struct GNUNET_DISK_FileHandle *fh; |
313 | BY_HANDLE_FILE_INFORMATION info; | 316 | BY_HANDLE_FILE_INFORMATION info; |
314 | int succ; | 317 | int succ; |
315 | 318 | ||
316 | fh = GNUNET_DISK_file_open(filename, GNUNET_DISK_OPEN_READ, 0); | 319 | fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 0); |
317 | if (fh == NULL) | 320 | if (fh == NULL) |
318 | return GNUNET_SYSERR; | 321 | return GNUNET_SYSERR; |
319 | succ = GetFileInformationByHandle(fh->h, &info); | 322 | succ = GetFileInformationByHandle (fh->h, &info); |
320 | GNUNET_DISK_file_close(fh); | 323 | GNUNET_DISK_file_close (fh); |
321 | if (succ) | 324 | if (succ) |
322 | { | 325 | { |
323 | *dev = info.dwVolumeSerialNumber; | 326 | *dev = info.dwVolumeSerialNumber; |
324 | *ino = ((info.nFileIndexHigh << sizeof(DWORD)) | info.nFileIndexLow); | 327 | *ino = ((info.nFileIndexHigh << sizeof (DWORD)) | info.nFileIndexLow); |
325 | return GNUNET_OK; | 328 | return GNUNET_OK; |
326 | } | 329 | } |
327 | else | 330 | else |
328 | return GNUNET_SYSERR; | 331 | return GNUNET_SYSERR; |
329 | 332 | ||
@@ -351,40 +354,39 @@ GNUNET_DISK_mktemp (const char *t) | |||
351 | char *tmpl; | 354 | char *tmpl; |
352 | char *fn; | 355 | char *fn; |
353 | 356 | ||
354 | if ( (t[0] != '/') && | 357 | if ((t[0] != '/') && (t[0] != '\\') |
355 | (t[0] != '\\') | ||
356 | #if WINDOWS | 358 | #if WINDOWS |
357 | && ! (isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':')) | 359 | && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':')) |
358 | #endif | 360 | #endif |
359 | ) | 361 | ) |
360 | { | 362 | { |
361 | tmpdir = getenv ("TMPDIR"); | 363 | tmpdir = getenv ("TMPDIR"); |
362 | tmpdir = tmpdir ? tmpdir : "/tmp"; | 364 | tmpdir = tmpdir ? tmpdir : "/tmp"; |
363 | GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX"); | 365 | GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX"); |
364 | } | 366 | } |
365 | else | 367 | else |
366 | { | 368 | { |
367 | GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX"); | 369 | GNUNET_asprintf (&tmpl, "%s%s", t, "XXXXXX"); |
368 | } | 370 | } |
369 | #ifdef MINGW | 371 | #ifdef MINGW |
370 | fn = (char *) GNUNET_malloc (MAX_PATH + 1); | 372 | fn = (char *) GNUNET_malloc (MAX_PATH + 1); |
371 | if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn)) | 373 | if (ERROR_SUCCESS != plibc_conv_to_win_path (tmpl, fn)) |
372 | { | 374 | { |
373 | GNUNET_free (fn); | 375 | GNUNET_free (fn); |
374 | GNUNET_free (tmpl); | 376 | GNUNET_free (tmpl); |
375 | return NULL; | 377 | return NULL; |
376 | } | 378 | } |
377 | GNUNET_free (tmpl); | 379 | GNUNET_free (tmpl); |
378 | #else | 380 | #else |
379 | fn = tmpl; | 381 | fn = tmpl; |
380 | #endif | 382 | #endif |
381 | fd = mkstemp (fn); | 383 | fd = mkstemp (fn); |
382 | if (fd == -1) | 384 | if (fd == -1) |
383 | { | 385 | { |
384 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn); | 386 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn); |
385 | GNUNET_free (fn); | 387 | GNUNET_free (fn); |
386 | return NULL; | 388 | return NULL; |
387 | } | 389 | } |
388 | if (0 != CLOSE (fd)) | 390 | if (0 != CLOSE (fd)) |
389 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 391 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); |
390 | return fn; | 392 | return fn; |
@@ -405,10 +407,10 @@ GNUNET_DISK_get_blocks_available (const char *part) | |||
405 | struct statvfs buf; | 407 | struct statvfs buf; |
406 | 408 | ||
407 | if (0 != statvfs (part, &buf)) | 409 | if (0 != statvfs (part, &buf)) |
408 | { | 410 | { |
409 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part); | 411 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part); |
410 | return -1; | 412 | return -1; |
411 | } | 413 | } |
412 | return buf.f_bavail; | 414 | return buf.f_bavail; |
413 | #elif MINGW | 415 | #elif MINGW |
414 | DWORD dwDummy; | 416 | DWORD dwDummy; |
@@ -423,21 +425,22 @@ GNUNET_DISK_get_blocks_available (const char *part) | |||
423 | GNUNET_free (path); | 425 | GNUNET_free (path); |
424 | szDrive[3] = 0; | 426 | szDrive[3] = 0; |
425 | if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) | 427 | if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) |
426 | { | 428 | { |
427 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 429 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
428 | _("`%s' failed for drive `%s': %u\n"), | 430 | _("`%s' failed for drive `%s': %u\n"), |
429 | "GetDiskFreeSpace", szDrive, GetLastError ()); | 431 | "GetDiskFreeSpace", szDrive, GetLastError ()); |
430 | 432 | ||
431 | return -1; | 433 | return -1; |
432 | } | 434 | } |
433 | return dwBlocks; | 435 | return dwBlocks; |
434 | #else | 436 | #else |
435 | struct statfs s; | 437 | struct statfs s; |
438 | |||
436 | if (0 != statfs (part, &s)) | 439 | if (0 != statfs (part, &s)) |
437 | { | 440 | { |
438 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part); | 441 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "statfs", part); |
439 | return -1; | 442 | return -1; |
440 | } | 443 | } |
441 | return s.f_bavail; | 444 | return s.f_bavail; |
442 | #endif | 445 | #endif |
443 | } | 446 | } |
@@ -461,21 +464,21 @@ GNUNET_DISK_directory_test (const char *fil) | |||
461 | 464 | ||
462 | ret = STAT (fil, &filestat); | 465 | ret = STAT (fil, &filestat); |
463 | if (ret != 0) | 466 | if (ret != 0) |
467 | { | ||
468 | if (errno != ENOENT) | ||
464 | { | 469 | { |
465 | if (errno != ENOENT) | 470 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", fil); |
466 | { | 471 | return GNUNET_SYSERR; |
467 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", fil); | ||
468 | return GNUNET_SYSERR; | ||
469 | } | ||
470 | return GNUNET_NO; | ||
471 | } | 472 | } |
473 | return GNUNET_NO; | ||
474 | } | ||
472 | if (!S_ISDIR (filestat.st_mode)) | 475 | if (!S_ISDIR (filestat.st_mode)) |
473 | return GNUNET_NO; | 476 | return GNUNET_NO; |
474 | if (ACCESS (fil, R_OK | X_OK) < 0) | 477 | if (ACCESS (fil, R_OK | X_OK) < 0) |
475 | { | 478 | { |
476 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", fil); | 479 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", fil); |
477 | return GNUNET_SYSERR; | 480 | return GNUNET_SYSERR; |
478 | } | 481 | } |
479 | return GNUNET_YES; | 482 | return GNUNET_YES; |
480 | } | 483 | } |
481 | 484 | ||
@@ -500,27 +503,27 @@ GNUNET_DISK_file_test (const char *fil) | |||
500 | 503 | ||
501 | ret = STAT (rdir, &filestat); | 504 | ret = STAT (rdir, &filestat); |
502 | if (ret != 0) | 505 | if (ret != 0) |
506 | { | ||
507 | if (errno != ENOENT) | ||
503 | { | 508 | { |
504 | if (errno != ENOENT) | 509 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", rdir); |
505 | { | ||
506 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", rdir); | ||
507 | GNUNET_free (rdir); | ||
508 | return GNUNET_SYSERR; | ||
509 | } | ||
510 | GNUNET_free (rdir); | 510 | GNUNET_free (rdir); |
511 | return GNUNET_NO; | 511 | return GNUNET_SYSERR; |
512 | } | 512 | } |
513 | GNUNET_free (rdir); | ||
514 | return GNUNET_NO; | ||
515 | } | ||
513 | if (!S_ISREG (filestat.st_mode)) | 516 | if (!S_ISREG (filestat.st_mode)) |
514 | { | 517 | { |
515 | GNUNET_free (rdir); | 518 | GNUNET_free (rdir); |
516 | return GNUNET_NO; | 519 | return GNUNET_NO; |
517 | } | 520 | } |
518 | if (ACCESS (rdir, R_OK) < 0) | 521 | if (ACCESS (rdir, R_OK) < 0) |
519 | { | 522 | { |
520 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", rdir); | 523 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "access", rdir); |
521 | GNUNET_free (rdir); | 524 | GNUNET_free (rdir); |
522 | return GNUNET_SYSERR; | 525 | return GNUNET_SYSERR; |
523 | } | 526 | } |
524 | GNUNET_free (rdir); | 527 | GNUNET_free (rdir); |
525 | return GNUNET_YES; | 528 | return GNUNET_YES; |
526 | } | 529 | } |
@@ -549,53 +552,52 @@ GNUNET_DISK_directory_create (const char *dir) | |||
549 | #else | 552 | #else |
550 | /* Local or Network path? */ | 553 | /* Local or Network path? */ |
551 | if (strncmp (rdir, "\\\\", 2) == 0) | 554 | if (strncmp (rdir, "\\\\", 2) == 0) |
555 | { | ||
556 | pos = 2; | ||
557 | while (rdir[pos]) | ||
552 | { | 558 | { |
553 | pos = 2; | 559 | if (rdir[pos] == '\\') |
554 | while (rdir[pos]) | 560 | { |
555 | { | 561 | pos++; |
556 | if (rdir[pos] == '\\') | 562 | break; |
557 | { | 563 | } |
558 | pos++; | 564 | pos++; |
559 | break; | ||
560 | } | ||
561 | pos++; | ||
562 | } | ||
563 | } | 565 | } |
566 | } | ||
564 | else | 567 | else |
565 | { | 568 | { |
566 | pos = 3; /* strlen("C:\\") */ | 569 | pos = 3; /* strlen("C:\\") */ |
567 | } | 570 | } |
568 | #endif | 571 | #endif |
569 | while (pos <= len) | 572 | while (pos <= len) |
573 | { | ||
574 | if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) | ||
570 | { | 575 | { |
571 | if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) | 576 | rdir[pos] = '\0'; |
572 | { | 577 | ret = GNUNET_DISK_directory_test (rdir); |
573 | rdir[pos] = '\0'; | 578 | if (ret == GNUNET_SYSERR) |
574 | ret = GNUNET_DISK_directory_test (rdir); | 579 | { |
575 | if (ret == GNUNET_SYSERR) | 580 | GNUNET_free (rdir); |
576 | { | 581 | return GNUNET_SYSERR; |
577 | GNUNET_free (rdir); | 582 | } |
578 | return GNUNET_SYSERR; | 583 | if (ret == GNUNET_NO) |
579 | } | 584 | { |
580 | if (ret == GNUNET_NO) | ||
581 | { | ||
582 | #ifndef MINGW | 585 | #ifndef MINGW |
583 | ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ | 586 | ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ |
584 | #else | 587 | #else |
585 | ret = mkdir (rdir); | 588 | ret = mkdir (rdir); |
586 | #endif | 589 | #endif |
587 | if ((ret != 0) && (errno != EEXIST)) | 590 | if ((ret != 0) && (errno != EEXIST)) |
588 | { | 591 | { |
589 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", | 592 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir); |
590 | rdir); | 593 | GNUNET_free (rdir); |
591 | GNUNET_free (rdir); | 594 | return GNUNET_SYSERR; |
592 | return GNUNET_SYSERR; | ||
593 | } | ||
594 | } | ||
595 | rdir[pos] = DIR_SEPARATOR; | ||
596 | } | 595 | } |
597 | pos++; | 596 | } |
597 | rdir[pos] = DIR_SEPARATOR; | ||
598 | } | 598 | } |
599 | pos++; | ||
600 | } | ||
599 | GNUNET_free (rdir); | 601 | GNUNET_free (rdir); |
600 | return GNUNET_OK; | 602 | return GNUNET_OK; |
601 | } | 603 | } |
@@ -645,15 +647,15 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, | |||
645 | size_t len) | 647 | size_t len) |
646 | { | 648 | { |
647 | if (h == NULL) | 649 | if (h == NULL) |
648 | { | 650 | { |
649 | errno = EINVAL; | 651 | errno = EINVAL; |
650 | return GNUNET_SYSERR; | 652 | return GNUNET_SYSERR; |
651 | } | 653 | } |
652 | 654 | ||
653 | #ifdef MINGW | 655 | #ifdef MINGW |
654 | DWORD bytesRead; | 656 | DWORD bytesRead; |
655 | 657 | ||
656 | if(h->type != GNUNET_PIPE) | 658 | if (h->type != GNUNET_PIPE) |
657 | { | 659 | { |
658 | if (!ReadFile (h->h, result, len, &bytesRead, NULL)) | 660 | if (!ReadFile (h->h, result, len, &bytesRead, NULL)) |
659 | { | 661 | { |
@@ -665,13 +667,13 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, | |||
665 | { | 667 | { |
666 | if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead)) | 668 | if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead)) |
667 | { | 669 | { |
668 | if(GetLastError () != ERROR_IO_PENDING ) | 670 | if (GetLastError () != ERROR_IO_PENDING) |
669 | { | 671 | { |
670 | SetErrnoFromWinError (GetLastError ()); | 672 | SetErrnoFromWinError (GetLastError ()); |
671 | return GNUNET_SYSERR; | 673 | return GNUNET_SYSERR; |
672 | } | 674 | } |
673 | } | 675 | } |
674 | GetOverlappedResult(h->h, h->oOverlapRead, &bytesRead, TRUE); | 676 | GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); |
675 | } | 677 | } |
676 | return bytesRead; | 678 | return bytesRead; |
677 | #else | 679 | #else |
@@ -694,8 +696,7 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) | |||
694 | struct GNUNET_DISK_FileHandle *fh; | 696 | struct GNUNET_DISK_FileHandle *fh; |
695 | ssize_t ret; | 697 | ssize_t ret; |
696 | 698 | ||
697 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, | 699 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); |
698 | GNUNET_DISK_PERM_NONE); | ||
699 | if (!fh) | 700 | if (!fh) |
700 | return GNUNET_SYSERR; | 701 | return GNUNET_SYSERR; |
701 | ret = GNUNET_DISK_file_read (fh, result, len); | 702 | ret = GNUNET_DISK_file_read (fh, result, len); |
@@ -717,15 +718,15 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, | |||
717 | const void *buffer, size_t n) | 718 | const void *buffer, size_t n) |
718 | { | 719 | { |
719 | if (h == NULL) | 720 | if (h == NULL) |
720 | { | 721 | { |
721 | errno = EINVAL; | 722 | errno = EINVAL; |
722 | return GNUNET_SYSERR; | 723 | return GNUNET_SYSERR; |
723 | } | 724 | } |
724 | 725 | ||
725 | #ifdef MINGW | 726 | #ifdef MINGW |
726 | DWORD bytesWritten; | 727 | DWORD bytesWritten; |
727 | 728 | ||
728 | if(h->type != GNUNET_PIPE) | 729 | if (h->type != GNUNET_PIPE) |
729 | { | 730 | { |
730 | if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) | 731 | if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) |
731 | { | 732 | { |
@@ -740,19 +741,19 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, | |||
740 | #endif | 741 | #endif |
741 | if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite)) | 742 | if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite)) |
742 | { | 743 | { |
743 | if(GetLastError () != ERROR_IO_PENDING ) | 744 | if (GetLastError () != ERROR_IO_PENDING) |
744 | { | 745 | { |
745 | SetErrnoFromWinError (GetLastError ()); | 746 | SetErrnoFromWinError (GetLastError ()); |
746 | #if DEBUG_PIPE | 747 | #if DEBUG_PIPE |
747 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n"); | 748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n"); |
748 | #endif | 749 | #endif |
749 | return GNUNET_SYSERR; | 750 | return GNUNET_SYSERR; |
750 | } | 751 | } |
751 | } | 752 | } |
752 | #if DEBUG_PIPE | 753 | #if DEBUG_PIPE |
753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); | 754 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); |
754 | #endif | 755 | #endif |
755 | GetOverlappedResult(h->h, h->oOverlapWrite, &bytesWritten, TRUE); | 756 | GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE); |
756 | } | 757 | } |
757 | return bytesWritten; | 758 | return bytesWritten; |
758 | #else | 759 | #else |
@@ -819,64 +820,64 @@ GNUNET_DISK_directory_scan (const char *dirName, | |||
819 | while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR)) | 820 | while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR)) |
820 | dname[strlen (dname) - 1] = '\0'; | 821 | dname[strlen (dname) - 1] = '\0'; |
821 | if (0 != STAT (dname, &istat)) | 822 | if (0 != STAT (dname, &istat)) |
822 | { | 823 | { |
823 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", dname); | 824 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", dname); |
824 | GNUNET_free (dname); | 825 | GNUNET_free (dname); |
825 | return GNUNET_SYSERR; | 826 | return GNUNET_SYSERR; |
826 | } | 827 | } |
827 | if (!S_ISDIR (istat.st_mode)) | 828 | if (!S_ISDIR (istat.st_mode)) |
828 | { | 829 | { |
829 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 830 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
830 | _("Expected `%s' to be a directory!\n"), dirName); | 831 | _("Expected `%s' to be a directory!\n"), dirName); |
831 | GNUNET_free (dname); | 832 | GNUNET_free (dname); |
832 | return GNUNET_SYSERR; | 833 | return GNUNET_SYSERR; |
833 | } | 834 | } |
834 | errno = 0; | 835 | errno = 0; |
835 | dinfo = OPENDIR (dname); | 836 | dinfo = OPENDIR (dname); |
836 | if ((errno == EACCES) || (dinfo == NULL)) | 837 | if ((errno == EACCES) || (dinfo == NULL)) |
837 | { | 838 | { |
838 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); | 839 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); |
839 | if (dinfo != NULL) | 840 | if (dinfo != NULL) |
840 | closedir (dinfo); | 841 | closedir (dinfo); |
841 | GNUNET_free (dname); | 842 | GNUNET_free (dname); |
842 | return GNUNET_SYSERR; | 843 | return GNUNET_SYSERR; |
843 | } | 844 | } |
844 | name_len = 256; | 845 | name_len = 256; |
845 | n_size = strlen (dname) + name_len + 2; | 846 | n_size = strlen (dname) + name_len + 2; |
846 | name = GNUNET_malloc (n_size); | 847 | name = GNUNET_malloc (n_size); |
847 | while ((finfo = readdir (dinfo)) != NULL) | 848 | while ((finfo = readdir (dinfo)) != NULL) |
849 | { | ||
850 | if ((0 == strcmp (finfo->d_name, ".")) || | ||
851 | (0 == strcmp (finfo->d_name, ".."))) | ||
852 | continue; | ||
853 | if (callback != NULL) | ||
848 | { | 854 | { |
849 | if ((0 == strcmp (finfo->d_name, ".")) || | 855 | if (name_len < strlen (finfo->d_name)) |
850 | (0 == strcmp (finfo->d_name, ".."))) | 856 | { |
851 | continue; | 857 | GNUNET_free (name); |
852 | if (callback != NULL) | 858 | name_len = strlen (finfo->d_name); |
853 | { | 859 | n_size = strlen (dname) + name_len + 2; |
854 | if (name_len < strlen (finfo->d_name)) | 860 | name = GNUNET_malloc (n_size); |
855 | { | 861 | } |
856 | GNUNET_free (name); | 862 | /* dname can end in "/" only if dname == "/"; |
857 | name_len = strlen (finfo->d_name); | 863 | * if dname does not end in "/", we need to add |
858 | n_size = strlen (dname) + name_len + 2; | 864 | * a "/" (otherwise, we must not!) */ |
859 | name = GNUNET_malloc (n_size); | 865 | GNUNET_snprintf (name, |
860 | } | 866 | n_size, |
861 | /* dname can end in "/" only if dname == "/"; | 867 | "%s%s%s", |
862 | if dname does not end in "/", we need to add | 868 | dname, |
863 | a "/" (otherwise, we must not!) */ | 869 | (strcmp (dname, DIR_SEPARATOR_STR) == |
864 | GNUNET_snprintf (name, | 870 | 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); |
865 | n_size, | 871 | if (GNUNET_OK != callback (callback_cls, name)) |
866 | "%s%s%s", | 872 | { |
867 | dname, | 873 | closedir (dinfo); |
868 | (strcmp (dname, DIR_SEPARATOR_STR) == | 874 | GNUNET_free (name); |
869 | 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); | 875 | GNUNET_free (dname); |
870 | if (GNUNET_OK != callback (callback_cls, name)) | 876 | return GNUNET_SYSERR; |
871 | { | 877 | } |
872 | closedir (dinfo); | ||
873 | GNUNET_free (name); | ||
874 | GNUNET_free (dname); | ||
875 | return GNUNET_SYSERR; | ||
876 | } | ||
877 | } | ||
878 | count++; | ||
879 | } | 878 | } |
879 | count++; | ||
880 | } | ||
880 | closedir (dinfo); | 881 | closedir (dinfo); |
881 | GNUNET_free (name); | 882 | GNUNET_free (name); |
882 | GNUNET_free (dname); | 883 | GNUNET_free (dname); |
@@ -960,27 +961,26 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator | |||
960 | 961 | ||
961 | GNUNET_assert (iter->next_name == NULL); | 962 | GNUNET_assert (iter->next_name == NULL); |
962 | if (can == GNUNET_YES) | 963 | if (can == GNUNET_YES) |
963 | { | 964 | { |
964 | closedir (iter->directory); | 965 | closedir (iter->directory); |
965 | GNUNET_free (iter->dirname); | 966 | GNUNET_free (iter->dirname); |
966 | GNUNET_free (iter); | 967 | GNUNET_free (iter); |
967 | return GNUNET_SYSERR; | 968 | return GNUNET_SYSERR; |
968 | } | 969 | } |
969 | while (NULL != (finfo = readdir (iter->directory))) | 970 | while (NULL != (finfo = readdir (iter->directory))) |
970 | { | 971 | { |
971 | if ((0 == strcmp (finfo->d_name, ".")) || | 972 | if ((0 == strcmp (finfo->d_name, ".")) || |
972 | (0 == strcmp (finfo->d_name, ".."))) | 973 | (0 == strcmp (finfo->d_name, ".."))) |
973 | continue; | 974 | continue; |
974 | GNUNET_asprintf (&iter->next_name, | 975 | GNUNET_asprintf (&iter->next_name, |
975 | "%s%s%s", | 976 | "%s%s%s", iter->dirname, DIR_SEPARATOR_STR, finfo->d_name); |
976 | iter->dirname, DIR_SEPARATOR_STR, finfo->d_name); | 977 | break; |
977 | break; | 978 | } |
978 | } | ||
979 | if (finfo == NULL) | 979 | if (finfo == NULL) |
980 | { | 980 | { |
981 | GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); | 981 | GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); |
982 | return GNUNET_NO; | 982 | return GNUNET_NO; |
983 | } | 983 | } |
984 | GNUNET_SCHEDULER_add_with_priority (iter->priority, | 984 | GNUNET_SCHEDULER_add_with_priority (iter->priority, |
985 | &directory_iterator_task, iter); | 985 | &directory_iterator_task, iter); |
986 | return GNUNET_YES; | 986 | return GNUNET_YES; |
@@ -1011,11 +1011,11 @@ GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, | |||
1011 | di->callback_cls = callback_cls; | 1011 | di->callback_cls = callback_cls; |
1012 | di->directory = OPENDIR (dirName); | 1012 | di->directory = OPENDIR (dirName); |
1013 | if (di->directory == NULL) | 1013 | if (di->directory == NULL) |
1014 | { | 1014 | { |
1015 | GNUNET_free (di); | 1015 | GNUNET_free (di); |
1016 | callback (callback_cls, NULL, NULL, NULL); | 1016 | callback (callback_cls, NULL, NULL, NULL); |
1017 | return; | 1017 | return; |
1018 | } | 1018 | } |
1019 | di->dirname = GNUNET_strdup (dirName); | 1019 | di->dirname = GNUNET_strdup (dirName); |
1020 | di->priority = prio; | 1020 | di->priority = prio; |
1021 | GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); | 1021 | GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); |
@@ -1058,21 +1058,21 @@ GNUNET_DISK_directory_remove (const char *fileName) | |||
1058 | return GNUNET_OK; | 1058 | return GNUNET_OK; |
1059 | if ((errno != EISDIR) && | 1059 | if ((errno != EISDIR) && |
1060 | /* EISDIR is not sufficient in all cases, e.g. | 1060 | /* EISDIR is not sufficient in all cases, e.g. |
1061 | sticky /tmp directory may result in EPERM on BSD. | 1061 | * sticky /tmp directory may result in EPERM on BSD. |
1062 | So we also explicitly check "isDirectory" */ | 1062 | * So we also explicitly check "isDirectory" */ |
1063 | (GNUNET_YES != GNUNET_DISK_directory_test (fileName))) | 1063 | (GNUNET_YES != GNUNET_DISK_directory_test (fileName))) |
1064 | { | 1064 | { |
1065 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); | 1065 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); |
1066 | return GNUNET_SYSERR; | 1066 | return GNUNET_SYSERR; |
1067 | } | 1067 | } |
1068 | if (GNUNET_SYSERR == | 1068 | if (GNUNET_SYSERR == |
1069 | GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL)) | 1069 | GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL)) |
1070 | return GNUNET_SYSERR; | 1070 | return GNUNET_SYSERR; |
1071 | if (0 != RMDIR (fileName)) | 1071 | if (0 != RMDIR (fileName)) |
1072 | { | 1072 | { |
1073 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); | 1073 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", fileName); |
1074 | return GNUNET_SYSERR; | 1074 | return GNUNET_SYSERR; |
1075 | } | 1075 | } |
1076 | return GNUNET_OK; | 1076 | return GNUNET_OK; |
1077 | } | 1077 | } |
1078 | 1078 | ||
@@ -1109,22 +1109,22 @@ GNUNET_DISK_file_copy (const char *src, const char *dst) | |||
1109 | GNUNET_DISK_PERM_GROUP_READ | | 1109 | GNUNET_DISK_PERM_GROUP_READ | |
1110 | GNUNET_DISK_PERM_GROUP_WRITE); | 1110 | GNUNET_DISK_PERM_GROUP_WRITE); |
1111 | if (!out) | 1111 | if (!out) |
1112 | { | 1112 | { |
1113 | GNUNET_DISK_file_close (in); | 1113 | GNUNET_DISK_file_close (in); |
1114 | return GNUNET_SYSERR; | 1114 | return GNUNET_SYSERR; |
1115 | } | 1115 | } |
1116 | buf = GNUNET_malloc (COPY_BLK_SIZE); | 1116 | buf = GNUNET_malloc (COPY_BLK_SIZE); |
1117 | while (pos < size) | 1117 | while (pos < size) |
1118 | { | 1118 | { |
1119 | len = COPY_BLK_SIZE; | 1119 | len = COPY_BLK_SIZE; |
1120 | if (len > size - pos) | 1120 | if (len > size - pos) |
1121 | len = size - pos; | 1121 | len = size - pos; |
1122 | if (len != GNUNET_DISK_file_read (in, buf, len)) | 1122 | if (len != GNUNET_DISK_file_read (in, buf, len)) |
1123 | goto FAIL; | 1123 | goto FAIL; |
1124 | if (len != GNUNET_DISK_file_write (out, buf, len)) | 1124 | if (len != GNUNET_DISK_file_write (out, buf, len)) |
1125 | goto FAIL; | 1125 | goto FAIL; |
1126 | pos += len; | 1126 | pos += len; |
1127 | } | 1127 | } |
1128 | GNUNET_free (buf); | 1128 | GNUNET_free (buf); |
1129 | GNUNET_DISK_file_close (in); | 1129 | GNUNET_DISK_file_close (in); |
1130 | GNUNET_DISK_file_close (out); | 1130 | GNUNET_DISK_file_close (out); |
@@ -1149,17 +1149,17 @@ GNUNET_DISK_filename_canonicalize (char *fn) | |||
1149 | 1149 | ||
1150 | idx = fn; | 1150 | idx = fn; |
1151 | while (*idx) | 1151 | while (*idx) |
1152 | { | 1152 | { |
1153 | c = *idx; | 1153 | c = *idx; |
1154 | |||
1155 | if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || | ||
1156 | c == '"' || c == '<' || c == '>' || c == '|') | ||
1157 | { | ||
1158 | *idx = '_'; | ||
1159 | } | ||
1160 | 1154 | ||
1161 | idx++; | 1155 | if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || |
1156 | c == '"' || c == '<' || c == '>' || c == '|') | ||
1157 | { | ||
1158 | *idx = '_'; | ||
1162 | } | 1159 | } |
1160 | |||
1161 | idx++; | ||
1162 | } | ||
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | 1165 | ||
@@ -1179,12 +1179,12 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) | |||
1179 | 1179 | ||
1180 | pws = getpwnam (user); | 1180 | pws = getpwnam (user); |
1181 | if (pws == NULL) | 1181 | if (pws == NULL) |
1182 | { | 1182 | { |
1183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1184 | _("Cannot obtain information about user `%s': %s\n"), | 1184 | _("Cannot obtain information about user `%s': %s\n"), |
1185 | user, STRERROR (errno)); | 1185 | user, STRERROR (errno)); |
1186 | return GNUNET_SYSERR; | 1186 | return GNUNET_SYSERR; |
1187 | } | 1187 | } |
1188 | if (0 != chown (filename, pws->pw_uid, pws->pw_gid)) | 1188 | if (0 != chown (filename, pws->pw_uid, pws->pw_gid)) |
1189 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "chown", filename); | 1189 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "chown", filename); |
1190 | #endif | 1190 | #endif |
@@ -1205,10 +1205,10 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, | |||
1205 | off_t lockEnd, int excl) | 1205 | off_t lockEnd, int excl) |
1206 | { | 1206 | { |
1207 | if (fh == NULL) | 1207 | if (fh == NULL) |
1208 | { | 1208 | { |
1209 | errno = EINVAL; | 1209 | errno = EINVAL; |
1210 | return GNUNET_SYSERR; | 1210 | return GNUNET_SYSERR; |
1211 | } | 1211 | } |
1212 | 1212 | ||
1213 | #ifndef MINGW | 1213 | #ifndef MINGW |
1214 | struct flock fl; | 1214 | struct flock fl; |
@@ -1227,12 +1227,11 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, | |||
1227 | o.Offset = lockStart; | 1227 | o.Offset = lockStart; |
1228 | 1228 | ||
1229 | if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | 1229 | if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) |
1230 | | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, | 1230 | | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, &o)) |
1231 | &o)) | 1231 | { |
1232 | { | 1232 | SetErrnoFromWinError (GetLastError ()); |
1233 | SetErrnoFromWinError (GetLastError ()); | 1233 | return GNUNET_SYSERR; |
1234 | return GNUNET_SYSERR; | 1234 | } |
1235 | } | ||
1236 | 1235 | ||
1237 | return GNUNET_OK; | 1236 | return GNUNET_OK; |
1238 | #endif | 1237 | #endif |
@@ -1251,10 +1250,10 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, | |||
1251 | off_t unlockEnd) | 1250 | off_t unlockEnd) |
1252 | { | 1251 | { |
1253 | if (fh == NULL) | 1252 | if (fh == NULL) |
1254 | { | 1253 | { |
1255 | errno = EINVAL; | 1254 | errno = EINVAL; |
1256 | return GNUNET_SYSERR; | 1255 | return GNUNET_SYSERR; |
1257 | } | 1256 | } |
1258 | 1257 | ||
1259 | #ifndef MINGW | 1258 | #ifndef MINGW |
1260 | struct flock fl; | 1259 | struct flock fl; |
@@ -1273,10 +1272,10 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, | |||
1273 | o.Offset = unlockStart; | 1272 | o.Offset = unlockStart; |
1274 | 1273 | ||
1275 | if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o)) | 1274 | if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o)) |
1276 | { | 1275 | { |
1277 | SetErrnoFromWinError (GetLastError ()); | 1276 | SetErrnoFromWinError (GetLastError ()); |
1278 | return GNUNET_SYSERR; | 1277 | return GNUNET_SYSERR; |
1279 | } | 1278 | } |
1280 | 1279 | ||
1281 | return GNUNET_OK; | 1280 | return GNUNET_OK; |
1282 | #endif | 1281 | #endif |
@@ -1302,6 +1301,7 @@ GNUNET_DISK_file_open (const char *fn, | |||
1302 | { | 1301 | { |
1303 | char *expfn; | 1302 | char *expfn; |
1304 | struct GNUNET_DISK_FileHandle *ret; | 1303 | struct GNUNET_DISK_FileHandle *ret; |
1304 | |||
1305 | #ifdef MINGW | 1305 | #ifdef MINGW |
1306 | DWORD access; | 1306 | DWORD access; |
1307 | DWORD disp; | 1307 | DWORD disp; |
@@ -1324,11 +1324,11 @@ GNUNET_DISK_file_open (const char *fn, | |||
1324 | else if (flags & GNUNET_DISK_OPEN_WRITE) | 1324 | else if (flags & GNUNET_DISK_OPEN_WRITE) |
1325 | oflags = O_WRONLY; | 1325 | oflags = O_WRONLY; |
1326 | else | 1326 | else |
1327 | { | 1327 | { |
1328 | GNUNET_break (0); | 1328 | GNUNET_break (0); |
1329 | GNUNET_free (expfn); | 1329 | GNUNET_free (expfn); |
1330 | return NULL; | 1330 | return NULL; |
1331 | } | 1331 | } |
1332 | if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) | 1332 | if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) |
1333 | oflags |= (O_CREAT | O_EXCL); | 1333 | oflags |= (O_CREAT | O_EXCL); |
1334 | if (flags & GNUNET_DISK_OPEN_TRUNCATE) | 1334 | if (flags & GNUNET_DISK_OPEN_TRUNCATE) |
@@ -1336,22 +1336,22 @@ GNUNET_DISK_file_open (const char *fn, | |||
1336 | if (flags & GNUNET_DISK_OPEN_APPEND) | 1336 | if (flags & GNUNET_DISK_OPEN_APPEND) |
1337 | oflags |= O_APPEND; | 1337 | oflags |= O_APPEND; |
1338 | if (flags & GNUNET_DISK_OPEN_CREATE) | 1338 | if (flags & GNUNET_DISK_OPEN_CREATE) |
1339 | { | 1339 | { |
1340 | (void) GNUNET_DISK_directory_create_for_file (expfn); | 1340 | (void) GNUNET_DISK_directory_create_for_file (expfn); |
1341 | oflags |= O_CREAT; | 1341 | oflags |= O_CREAT; |
1342 | mode = translate_unix_perms(perm); | 1342 | mode = translate_unix_perms (perm); |
1343 | } | 1343 | } |
1344 | 1344 | ||
1345 | fd = open (expfn, oflags | O_LARGEFILE, mode); | 1345 | fd = open (expfn, oflags | O_LARGEFILE, mode); |
1346 | if (fd == -1) | 1346 | if (fd == -1) |
1347 | { | 1347 | { |
1348 | if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) | 1348 | if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) |
1349 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); | 1349 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); |
1350 | else | 1350 | else |
1351 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_DEBUG, "open", expfn); | 1351 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_DEBUG, "open", expfn); |
1352 | GNUNET_free (expfn); | 1352 | GNUNET_free (expfn); |
1353 | return NULL; | 1353 | return NULL; |
1354 | } | 1354 | } |
1355 | #else | 1355 | #else |
1356 | access = 0; | 1356 | access = 0; |
1357 | disp = OPEN_ALWAYS; | 1357 | disp = OPEN_ALWAYS; |
@@ -1364,48 +1364,47 @@ GNUNET_DISK_file_open (const char *fn, | |||
1364 | access = FILE_WRITE_DATA; | 1364 | access = FILE_WRITE_DATA; |
1365 | 1365 | ||
1366 | if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) | 1366 | if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) |
1367 | { | 1367 | { |
1368 | disp = CREATE_NEW; | 1368 | disp = CREATE_NEW; |
1369 | } | 1369 | } |
1370 | else if (flags & GNUNET_DISK_OPEN_CREATE) | 1370 | else if (flags & GNUNET_DISK_OPEN_CREATE) |
1371 | { | 1371 | { |
1372 | (void) GNUNET_DISK_directory_create_for_file (expfn); | 1372 | (void) GNUNET_DISK_directory_create_for_file (expfn); |
1373 | if (flags & GNUNET_DISK_OPEN_TRUNCATE) | 1373 | if (flags & GNUNET_DISK_OPEN_TRUNCATE) |
1374 | disp = CREATE_ALWAYS; | 1374 | disp = CREATE_ALWAYS; |
1375 | else | 1375 | else |
1376 | disp = OPEN_ALWAYS; | 1376 | disp = OPEN_ALWAYS; |
1377 | } | 1377 | } |
1378 | else if (flags & GNUNET_DISK_OPEN_TRUNCATE) | 1378 | else if (flags & GNUNET_DISK_OPEN_TRUNCATE) |
1379 | { | 1379 | { |
1380 | disp = TRUNCATE_EXISTING; | 1380 | disp = TRUNCATE_EXISTING; |
1381 | } | 1381 | } |
1382 | else | 1382 | else |
1383 | { | 1383 | { |
1384 | disp = OPEN_EXISTING; | 1384 | disp = OPEN_EXISTING; |
1385 | } | 1385 | } |
1386 | 1386 | ||
1387 | /* TODO: access priviledges? */ | 1387 | /* TODO: access priviledges? */ |
1388 | h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ | 1388 | h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ |
1389 | | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, | 1389 | | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); |
1390 | NULL); | ||
1391 | if (h == INVALID_HANDLE_VALUE) | 1390 | if (h == INVALID_HANDLE_VALUE) |
1391 | { | ||
1392 | SetErrnoFromWinError (GetLastError ()); | ||
1393 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); | ||
1394 | GNUNET_free (expfn); | ||
1395 | return NULL; | ||
1396 | } | ||
1397 | |||
1398 | if (flags & GNUNET_DISK_OPEN_APPEND) | ||
1399 | if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) | ||
1392 | { | 1400 | { |
1393 | SetErrnoFromWinError (GetLastError ()); | 1401 | SetErrnoFromWinError (GetLastError ()); |
1394 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); | 1402 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", |
1403 | expfn); | ||
1404 | CloseHandle (h); | ||
1395 | GNUNET_free (expfn); | 1405 | GNUNET_free (expfn); |
1396 | return NULL; | 1406 | return NULL; |
1397 | } | 1407 | } |
1398 | |||
1399 | if (flags & GNUNET_DISK_OPEN_APPEND) | ||
1400 | if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER) | ||
1401 | { | ||
1402 | SetErrnoFromWinError (GetLastError ()); | ||
1403 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", | ||
1404 | expfn); | ||
1405 | CloseHandle (h); | ||
1406 | GNUNET_free (expfn); | ||
1407 | return NULL; | ||
1408 | } | ||
1409 | #endif | 1408 | #endif |
1410 | 1409 | ||
1411 | ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); | 1410 | ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); |
@@ -1429,28 +1428,28 @@ int | |||
1429 | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) | 1428 | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) |
1430 | { | 1429 | { |
1431 | if (h == NULL) | 1430 | if (h == NULL) |
1432 | { | 1431 | { |
1433 | errno = EINVAL; | 1432 | errno = EINVAL; |
1434 | return GNUNET_SYSERR; | 1433 | return GNUNET_SYSERR; |
1435 | } | 1434 | } |
1436 | 1435 | ||
1437 | #if MINGW | 1436 | #if MINGW |
1438 | if (!CloseHandle (h->h)) | 1437 | if (!CloseHandle (h->h)) |
1439 | { | 1438 | { |
1440 | SetErrnoFromWinError (GetLastError ()); | 1439 | SetErrnoFromWinError (GetLastError ()); |
1441 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); | 1440 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); |
1442 | GNUNET_free (h->oOverlapRead); | 1441 | GNUNET_free (h->oOverlapRead); |
1443 | GNUNET_free (h->oOverlapWrite); | 1442 | GNUNET_free (h->oOverlapWrite); |
1444 | GNUNET_free (h); | 1443 | GNUNET_free (h); |
1445 | return GNUNET_SYSERR; | 1444 | return GNUNET_SYSERR; |
1446 | } | 1445 | } |
1447 | #else | 1446 | #else |
1448 | if (close (h->fd) != 0) | 1447 | if (close (h->fd) != 0) |
1449 | { | 1448 | { |
1450 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); | 1449 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); |
1451 | GNUNET_free (h); | 1450 | GNUNET_free (h); |
1452 | return GNUNET_SYSERR; | 1451 | return GNUNET_SYSERR; |
1453 | } | 1452 | } |
1454 | #endif | 1453 | #endif |
1455 | GNUNET_free (h); | 1454 | GNUNET_free (h); |
1456 | return GNUNET_OK; | 1455 | return GNUNET_OK; |
@@ -1482,43 +1481,44 @@ GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1482 | unsigned int needed; | 1481 | unsigned int needed; |
1483 | 1482 | ||
1484 | if (GNUNET_OK != | 1483 | if (GNUNET_OK != |
1485 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1484 | GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", &pfx)) |
1486 | serviceName, "HOME", &pfx)) | ||
1487 | return NULL; | 1485 | return NULL; |
1488 | if (pfx == NULL) | 1486 | if (pfx == NULL) |
1489 | { | 1487 | { |
1490 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1488 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1491 | _("No `%s' specified for service `%s' in configuration.\n"), | 1489 | _("No `%s' specified for service `%s' in configuration.\n"), |
1492 | "HOME", serviceName); | 1490 | "HOME", serviceName); |
1493 | return NULL; | 1491 | return NULL; |
1494 | } | 1492 | } |
1495 | needed = strlen (pfx) + 2; | 1493 | needed = strlen (pfx) + 2; |
1496 | if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\')) | 1494 | if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\')) |
1497 | needed++; | 1495 | needed++; |
1498 | va_start (ap, serviceName); | 1496 | va_start (ap, serviceName); |
1499 | while (1) | 1497 | while (1) |
1500 | { | 1498 | { |
1501 | c = va_arg (ap, const char *); | 1499 | c = va_arg (ap, const char *); |
1502 | if (c == NULL) | 1500 | |
1503 | break; | 1501 | if (c == NULL) |
1504 | needed += strlen (c); | 1502 | break; |
1505 | if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) | 1503 | needed += strlen (c); |
1506 | needed++; | 1504 | if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) |
1507 | } | 1505 | needed++; |
1506 | } | ||
1508 | va_end (ap); | 1507 | va_end (ap); |
1509 | ret = GNUNET_malloc (needed); | 1508 | ret = GNUNET_malloc (needed); |
1510 | strcpy (ret, pfx); | 1509 | strcpy (ret, pfx); |
1511 | GNUNET_free (pfx); | 1510 | GNUNET_free (pfx); |
1512 | va_start (ap, serviceName); | 1511 | va_start (ap, serviceName); |
1513 | while (1) | 1512 | while (1) |
1514 | { | 1513 | { |
1515 | c = va_arg (ap, const char *); | 1514 | c = va_arg (ap, const char *); |
1516 | if (c == NULL) | 1515 | |
1517 | break; | 1516 | if (c == NULL) |
1518 | if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) | 1517 | break; |
1519 | strcat (ret, DIR_SEPARATOR_STR); | 1518 | if ((c[strlen (c) - 1] != '/') && (c[strlen (c) - 1] != '\\')) |
1520 | strcat (ret, c); | 1519 | strcat (ret, DIR_SEPARATOR_STR); |
1521 | } | 1520 | strcat (ret, c); |
1521 | } | ||
1522 | va_end (ap); | 1522 | va_end (ap); |
1523 | if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\')) | 1523 | if ((ret[strlen (ret) - 1] != '/') && (ret[strlen (ret) - 1] != '\\')) |
1524 | (void) GNUNET_DISK_directory_create_for_file (ret); | 1524 | (void) GNUNET_DISK_directory_create_for_file (ret); |
@@ -1571,52 +1571,52 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, | |||
1571 | enum GNUNET_DISK_MapType access, size_t len) | 1571 | enum GNUNET_DISK_MapType access, size_t len) |
1572 | { | 1572 | { |
1573 | if (h == NULL) | 1573 | if (h == NULL) |
1574 | { | 1574 | { |
1575 | errno = EINVAL; | 1575 | errno = EINVAL; |
1576 | return NULL; | 1576 | return NULL; |
1577 | } | 1577 | } |
1578 | 1578 | ||
1579 | #ifdef MINGW | 1579 | #ifdef MINGW |
1580 | DWORD mapAccess, protect; | 1580 | DWORD mapAccess, protect; |
1581 | 1581 | ||
1582 | if ((access & GNUNET_DISK_MAP_TYPE_READ) && | 1582 | if ((access & GNUNET_DISK_MAP_TYPE_READ) && |
1583 | (access & GNUNET_DISK_MAP_TYPE_WRITE)) | 1583 | (access & GNUNET_DISK_MAP_TYPE_WRITE)) |
1584 | { | 1584 | { |
1585 | protect = PAGE_READWRITE; | 1585 | protect = PAGE_READWRITE; |
1586 | mapAccess = FILE_MAP_ALL_ACCESS; | 1586 | mapAccess = FILE_MAP_ALL_ACCESS; |
1587 | } | 1587 | } |
1588 | else if (access & GNUNET_DISK_MAP_TYPE_READ) | 1588 | else if (access & GNUNET_DISK_MAP_TYPE_READ) |
1589 | { | 1589 | { |
1590 | protect = PAGE_READONLY; | 1590 | protect = PAGE_READONLY; |
1591 | mapAccess = FILE_MAP_READ; | 1591 | mapAccess = FILE_MAP_READ; |
1592 | } | 1592 | } |
1593 | else if (access & GNUNET_DISK_MAP_TYPE_WRITE) | 1593 | else if (access & GNUNET_DISK_MAP_TYPE_WRITE) |
1594 | { | 1594 | { |
1595 | protect = PAGE_READWRITE; | 1595 | protect = PAGE_READWRITE; |
1596 | mapAccess = FILE_MAP_WRITE; | 1596 | mapAccess = FILE_MAP_WRITE; |
1597 | } | 1597 | } |
1598 | else | 1598 | else |
1599 | { | 1599 | { |
1600 | GNUNET_break (0); | 1600 | GNUNET_break (0); |
1601 | return NULL; | 1601 | return NULL; |
1602 | } | 1602 | } |
1603 | 1603 | ||
1604 | *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle)); | 1604 | *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle)); |
1605 | (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL); | 1605 | (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL); |
1606 | if ((*m)->h == INVALID_HANDLE_VALUE) | 1606 | if ((*m)->h == INVALID_HANDLE_VALUE) |
1607 | { | 1607 | { |
1608 | SetErrnoFromWinError (GetLastError ()); | 1608 | SetErrnoFromWinError (GetLastError ()); |
1609 | GNUNET_free (*m); | 1609 | GNUNET_free (*m); |
1610 | return NULL; | 1610 | return NULL; |
1611 | } | 1611 | } |
1612 | 1612 | ||
1613 | (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len); | 1613 | (*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len); |
1614 | if (!(*m)->addr) | 1614 | if (!(*m)->addr) |
1615 | { | 1615 | { |
1616 | SetErrnoFromWinError (GetLastError ()); | 1616 | SetErrnoFromWinError (GetLastError ()); |
1617 | CloseHandle ((*m)->h); | 1617 | CloseHandle ((*m)->h); |
1618 | GNUNET_free (*m); | 1618 | GNUNET_free (*m); |
1619 | } | 1619 | } |
1620 | 1620 | ||
1621 | return (*m)->addr; | 1621 | return (*m)->addr; |
1622 | #else | 1622 | #else |
@@ -1631,10 +1631,10 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, | |||
1631 | (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0); | 1631 | (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0); |
1632 | GNUNET_assert (NULL != (*m)->addr); | 1632 | GNUNET_assert (NULL != (*m)->addr); |
1633 | if (MAP_FAILED == (*m)->addr) | 1633 | if (MAP_FAILED == (*m)->addr) |
1634 | { | 1634 | { |
1635 | GNUNET_free (*m); | 1635 | GNUNET_free (*m); |
1636 | return NULL; | 1636 | return NULL; |
1637 | } | 1637 | } |
1638 | (*m)->len = len; | 1638 | (*m)->len = len; |
1639 | return (*m)->addr; | 1639 | return (*m)->addr; |
1640 | #endif | 1640 | #endif |
@@ -1649,21 +1649,22 @@ int | |||
1649 | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) | 1649 | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) |
1650 | { | 1650 | { |
1651 | int ret; | 1651 | int ret; |
1652 | |||
1652 | if (h == NULL) | 1653 | if (h == NULL) |
1653 | { | 1654 | { |
1654 | errno = EINVAL; | 1655 | errno = EINVAL; |
1655 | return GNUNET_SYSERR; | 1656 | return GNUNET_SYSERR; |
1656 | } | 1657 | } |
1657 | 1658 | ||
1658 | #ifdef MINGW | 1659 | #ifdef MINGW |
1659 | ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR; | 1660 | ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR; |
1660 | if (ret != GNUNET_OK) | 1661 | if (ret != GNUNET_OK) |
1661 | SetErrnoFromWinError (GetLastError ()); | 1662 | SetErrnoFromWinError (GetLastError ()); |
1662 | if (!CloseHandle (h->h) && (ret == GNUNET_OK)) | 1663 | if (!CloseHandle (h->h) && (ret == GNUNET_OK)) |
1663 | { | 1664 | { |
1664 | ret = GNUNET_SYSERR; | 1665 | ret = GNUNET_SYSERR; |
1665 | SetErrnoFromWinError (GetLastError ()); | 1666 | SetErrnoFromWinError (GetLastError ()); |
1666 | } | 1667 | } |
1667 | #else | 1668 | #else |
1668 | ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; | 1669 | ret = munmap (h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; |
1669 | #endif | 1670 | #endif |
@@ -1681,10 +1682,10 @@ int | |||
1681 | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) | 1682 | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) |
1682 | { | 1683 | { |
1683 | if (h == NULL) | 1684 | if (h == NULL) |
1684 | { | 1685 | { |
1685 | errno = EINVAL; | 1686 | errno = EINVAL; |
1686 | return GNUNET_SYSERR; | 1687 | return GNUNET_SYSERR; |
1687 | } | 1688 | } |
1688 | 1689 | ||
1689 | #ifdef MINGW | 1690 | #ifdef MINGW |
1690 | int ret; | 1691 | int ret; |
@@ -1715,9 +1716,7 @@ static int | |||
1715 | create_selectable_pipe (PHANDLE read_pipe_ptr, | 1716 | create_selectable_pipe (PHANDLE read_pipe_ptr, |
1716 | PHANDLE write_pipe_ptr, | 1717 | PHANDLE write_pipe_ptr, |
1717 | LPSECURITY_ATTRIBUTES sa_ptr, | 1718 | LPSECURITY_ATTRIBUTES sa_ptr, |
1718 | DWORD psize, | 1719 | DWORD psize, DWORD dwReadMode, DWORD dwWriteMode) |
1719 | DWORD dwReadMode, | ||
1720 | DWORD dwWriteMode) | ||
1721 | { | 1720 | { |
1722 | /* Default to error. */ | 1721 | /* Default to error. */ |
1723 | *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; | 1722 | *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; |
@@ -1731,108 +1730,107 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, | |||
1731 | char pipename[MAX_PATH]; | 1730 | char pipename[MAX_PATH]; |
1732 | 1731 | ||
1733 | /* Retry CreateNamedPipe as long as the pipe name is in use. | 1732 | /* Retry CreateNamedPipe as long as the pipe name is in use. |
1734 | Retrying will probably never be necessary, but we want | 1733 | * Retrying will probably never be necessary, but we want |
1735 | to be as robust as possible. */ | 1734 | * to be as robust as possible. */ |
1736 | while (1) | 1735 | while (1) |
1737 | { | 1736 | { |
1738 | static volatile LONG pipe_unique_id; | 1737 | static volatile LONG pipe_unique_id; |
1739 | 1738 | ||
1740 | snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", | 1739 | snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", |
1741 | getpid (), InterlockedIncrement ((LONG *)&pipe_unique_id)); | 1740 | getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); |
1742 | #if DEBUG_PIPE | 1741 | #if DEBUG_PIPE |
1743 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n", pipename, psize); | 1742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1743 | "CreateNamedPipe: name = %s, size = %lu\n", pipename, psize); | ||
1744 | #endif | 1744 | #endif |
1745 | /* Use CreateNamedPipe instead of CreatePipe, because the latter | 1745 | /* Use CreateNamedPipe instead of CreatePipe, because the latter |
1746 | returns a write handle that does not permit FILE_READ_ATTRIBUTES | 1746 | * returns a write handle that does not permit FILE_READ_ATTRIBUTES |
1747 | access, on versions of win32 earlier than WinXP SP2. | 1747 | * access, on versions of win32 earlier than WinXP SP2. |
1748 | CreatePipe also stupidly creates a full duplex pipe, which is | 1748 | * CreatePipe also stupidly creates a full duplex pipe, which is |
1749 | a waste, since only a single direction is actually used. | 1749 | * a waste, since only a single direction is actually used. |
1750 | It's important to only allow a single instance, to ensure that | 1750 | * It's important to only allow a single instance, to ensure that |
1751 | the pipe was not created earlier by some other process, even if | 1751 | * the pipe was not created earlier by some other process, even if |
1752 | the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE | 1752 | * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE |
1753 | because that is only available for Win2k SP2 and WinXP. */ | 1753 | * because that is only available for Win2k SP2 and WinXP. */ |
1754 | read_pipe = CreateNamedPipeA (pipename, | 1754 | read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ |
1755 | PIPE_ACCESS_INBOUND | dwReadMode, | 1755 | psize, /* output buffer size */ |
1756 | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, | 1756 | psize, /* input buffer size */ |
1757 | 1, /* max instances */ | 1757 | NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); |
1758 | psize, /* output buffer size */ | 1758 | |
1759 | psize, /* input buffer size */ | 1759 | if (read_pipe != INVALID_HANDLE_VALUE) |
1760 | NMPWAIT_USE_DEFAULT_WAIT, | 1760 | { |
1761 | sa_ptr); | ||
1762 | |||
1763 | if (read_pipe != INVALID_HANDLE_VALUE) | ||
1764 | { | ||
1765 | #if DEBUG_PIPE | 1761 | #if DEBUG_PIPE |
1766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); | 1762 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", |
1763 | read_pipe); | ||
1767 | #endif | 1764 | #endif |
1768 | break; | 1765 | break; |
1769 | } | 1766 | } |
1770 | 1767 | ||
1771 | DWORD err = GetLastError (); | 1768 | DWORD err = GetLastError (); |
1772 | switch (err) | 1769 | |
1773 | { | 1770 | switch (err) |
1774 | case ERROR_PIPE_BUSY: | 1771 | { |
1775 | /* The pipe is already open with compatible parameters. | 1772 | case ERROR_PIPE_BUSY: |
1776 | Pick a new name and retry. */ | 1773 | /* The pipe is already open with compatible parameters. |
1774 | * Pick a new name and retry. */ | ||
1777 | #if DEBUG_PIPE | 1775 | #if DEBUG_PIPE |
1778 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); | 1776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); |
1779 | #endif | 1777 | #endif |
1780 | continue; | 1778 | continue; |
1781 | case ERROR_ACCESS_DENIED: | 1779 | case ERROR_ACCESS_DENIED: |
1782 | /* The pipe is already open with incompatible parameters. | 1780 | /* The pipe is already open with incompatible parameters. |
1783 | Pick a new name and retry. */ | 1781 | * Pick a new name and retry. */ |
1784 | #if DEBUG_PIPE | 1782 | #if DEBUG_PIPE |
1785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); | 1783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); |
1786 | #endif | 1784 | #endif |
1787 | continue; | 1785 | continue; |
1788 | case ERROR_CALL_NOT_IMPLEMENTED: | 1786 | case ERROR_CALL_NOT_IMPLEMENTED: |
1789 | /* We are on an older Win9x platform without named pipes. | 1787 | /* We are on an older Win9x platform without named pipes. |
1790 | Return an anonymous pipe as the best approximation. */ | 1788 | * Return an anonymous pipe as the best approximation. */ |
1791 | #if DEBUG_PIPE | 1789 | #if DEBUG_PIPE |
1792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe not implemented, resorting to " | 1790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1793 | "CreatePipe: size = %lu\n", psize); | 1791 | "CreateNamedPipe not implemented, resorting to " |
1792 | "CreatePipe: size = %lu\n", psize); | ||
1794 | #endif | 1793 | #endif |
1795 | if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) | 1794 | if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) |
1796 | { | 1795 | { |
1797 | #if DEBUG_PIPE | 1796 | #if DEBUG_PIPE |
1798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", *read_pipe_ptr); | 1797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", |
1799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", *write_pipe_ptr); | 1798 | *read_pipe_ptr); |
1799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", | ||
1800 | *write_pipe_ptr); | ||
1800 | #endif | 1801 | #endif |
1801 | return GNUNET_OK; | 1802 | return GNUNET_OK; |
1802 | } | 1803 | } |
1803 | err = GetLastError (); | 1804 | err = GetLastError (); |
1804 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err); | 1805 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err); |
1805 | return err; | 1806 | return err; |
1806 | default: | 1807 | default: |
1807 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err); | 1808 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err); |
1808 | return err; | 1809 | return err; |
1809 | } | ||
1810 | /* NOTREACHED */ | ||
1811 | } | 1810 | } |
1811 | /* NOTREACHED */ | ||
1812 | } | ||
1812 | #if DEBUG_PIPE | 1813 | #if DEBUG_PIPE |
1813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); | 1814 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); |
1814 | #endif | 1815 | #endif |
1815 | 1816 | ||
1816 | /* Open the named pipe for writing. | 1817 | /* Open the named pipe for writing. |
1817 | Be sure to permit FILE_READ_ATTRIBUTES access. */ | 1818 | * Be sure to permit FILE_READ_ATTRIBUTES access. */ |
1818 | write_pipe = CreateFileA (pipename, | 1819 | write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */ |
1819 | GENERIC_WRITE | FILE_READ_ATTRIBUTES, | 1820 | sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */ |
1820 | 0, /* share mode */ | 1821 | 0); /* handle to template file */ |
1821 | sa_ptr, | ||
1822 | OPEN_EXISTING, | ||
1823 | dwWriteMode, /* flags and attributes */ | ||
1824 | 0); /* handle to template file */ | ||
1825 | 1822 | ||
1826 | if (write_pipe == INVALID_HANDLE_VALUE) | 1823 | if (write_pipe == INVALID_HANDLE_VALUE) |
1827 | { | 1824 | { |
1828 | /* Failure. */ | 1825 | /* Failure. */ |
1829 | DWORD err = GetLastError (); | 1826 | DWORD err = GetLastError (); |
1827 | |||
1830 | #if DEBUG_PIPE | 1828 | #if DEBUG_PIPE |
1831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); | 1829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); |
1832 | #endif | 1830 | #endif |
1833 | CloseHandle (read_pipe); | 1831 | CloseHandle (read_pipe); |
1834 | return err; | 1832 | return err; |
1835 | } | 1833 | } |
1836 | #if DEBUG_PIPE | 1834 | #if DEBUG_PIPE |
1837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); | 1835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); |
1838 | #endif | 1836 | #endif |
@@ -1858,9 +1856,8 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) | |||
1858 | struct GNUNET_DISK_PipeHandle *p; | 1856 | struct GNUNET_DISK_PipeHandle *p; |
1859 | struct GNUNET_DISK_FileHandle *fds; | 1857 | struct GNUNET_DISK_FileHandle *fds; |
1860 | 1858 | ||
1861 | p = | 1859 | p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + |
1862 | GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + | 1860 | 2 * sizeof (struct GNUNET_DISK_FileHandle)); |
1863 | 2 * sizeof (struct GNUNET_DISK_FileHandle)); | ||
1864 | fds = (struct GNUNET_DISK_FileHandle *) &p[1]; | 1861 | fds = (struct GNUNET_DISK_FileHandle *) &p[1]; |
1865 | p->fd[0] = &fds[0]; | 1862 | p->fd[0] = &fds[0]; |
1866 | p->fd[1] = &fds[1]; | 1863 | p->fd[1] = &fds[1]; |
@@ -1872,13 +1869,13 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) | |||
1872 | 1869 | ||
1873 | ret = pipe (fd); | 1870 | ret = pipe (fd); |
1874 | if (ret == -1) | 1871 | if (ret == -1) |
1875 | { | 1872 | { |
1876 | eno = errno; | 1873 | eno = errno; |
1877 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 1874 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); |
1878 | GNUNET_free (p); | 1875 | GNUNET_free (p); |
1879 | errno = eno; | 1876 | errno = eno; |
1880 | return NULL; | 1877 | return NULL; |
1881 | } | 1878 | } |
1882 | p->fd[0]->fd = fd[0]; | 1879 | p->fd[0]->fd = fd[0]; |
1883 | p->fd[1]->fd = fd[1]; | 1880 | p->fd[1]->fd = fd[1]; |
1884 | ret = 0; | 1881 | ret = 0; |
@@ -1902,60 +1899,64 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) | |||
1902 | if (0 > fcntl (fd[1], F_SETFD, flags)) | 1899 | if (0 > fcntl (fd[1], F_SETFD, flags)) |
1903 | ret = -1; | 1900 | ret = -1; |
1904 | if (ret == -1) | 1901 | if (ret == -1) |
1905 | { | 1902 | { |
1906 | eno = errno; | 1903 | eno = errno; |
1907 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fcntl"); | 1904 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fcntl"); |
1908 | GNUNET_break (0 == close (p->fd[0]->fd)); | 1905 | GNUNET_break (0 == close (p->fd[0]->fd)); |
1909 | GNUNET_break (0 == close (p->fd[1]->fd)); | 1906 | GNUNET_break (0 == close (p->fd[1]->fd)); |
1910 | GNUNET_free (p); | 1907 | GNUNET_free (p); |
1911 | errno = eno; | 1908 | errno = eno; |
1912 | return NULL; | 1909 | return NULL; |
1913 | } | 1910 | } |
1914 | #else | 1911 | #else |
1915 | BOOL ret; | 1912 | BOOL ret; |
1916 | HANDLE tmp_handle; | 1913 | HANDLE tmp_handle; |
1917 | 1914 | ||
1918 | ret = create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0, FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED); | 1915 | ret = |
1916 | create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0, | ||
1917 | FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED); | ||
1919 | if (!ret) | 1918 | if (!ret) |
1920 | { | 1919 | { |
1921 | GNUNET_free (p); | 1920 | GNUNET_free (p); |
1922 | SetErrnoFromWinError (GetLastError ()); | 1921 | SetErrnoFromWinError (GetLastError ()); |
1923 | return NULL; | 1922 | return NULL; |
1924 | } | 1923 | } |
1925 | if (!DuplicateHandle (GetCurrentProcess (), p->fd[0]->h, | 1924 | if (!DuplicateHandle (GetCurrentProcess (), p->fd[0]->h, |
1926 | GetCurrentProcess (), &tmp_handle, 0, inherit_read == GNUNET_YES ? TRUE : FALSE, | 1925 | GetCurrentProcess (), &tmp_handle, 0, |
1927 | DUPLICATE_SAME_ACCESS)) | 1926 | inherit_read == GNUNET_YES ? TRUE : FALSE, |
1928 | { | 1927 | DUPLICATE_SAME_ACCESS)) |
1929 | SetErrnoFromWinError (GetLastError ()); | 1928 | { |
1930 | CloseHandle (p->fd[0]->h); | 1929 | SetErrnoFromWinError (GetLastError ()); |
1931 | CloseHandle (p->fd[1]->h); | 1930 | CloseHandle (p->fd[0]->h); |
1932 | GNUNET_free (p); | 1931 | CloseHandle (p->fd[1]->h); |
1933 | return NULL; | 1932 | GNUNET_free (p); |
1934 | } | 1933 | return NULL; |
1935 | CloseHandle (p->fd[0]->h); | 1934 | } |
1936 | p->fd[0]->h = tmp_handle; | 1935 | CloseHandle (p->fd[0]->h); |
1937 | 1936 | p->fd[0]->h = tmp_handle; | |
1938 | if (!DuplicateHandle (GetCurrentProcess (), p->fd[1]->h, | 1937 | |
1939 | GetCurrentProcess (), &tmp_handle, 0, inherit_write == GNUNET_YES ? TRUE : FALSE, | 1938 | if (!DuplicateHandle (GetCurrentProcess (), p->fd[1]->h, |
1940 | DUPLICATE_SAME_ACCESS)) | 1939 | GetCurrentProcess (), &tmp_handle, 0, |
1941 | { | 1940 | inherit_write == GNUNET_YES ? TRUE : FALSE, |
1942 | SetErrnoFromWinError (GetLastError ()); | 1941 | DUPLICATE_SAME_ACCESS)) |
1943 | CloseHandle (p->fd[0]->h); | 1942 | { |
1944 | CloseHandle (p->fd[1]->h); | 1943 | SetErrnoFromWinError (GetLastError ()); |
1945 | GNUNET_free (p); | 1944 | CloseHandle (p->fd[0]->h); |
1946 | return NULL; | 1945 | CloseHandle (p->fd[1]->h); |
1947 | } | 1946 | GNUNET_free (p); |
1947 | return NULL; | ||
1948 | } | ||
1948 | CloseHandle (p->fd[1]->h); | 1949 | CloseHandle (p->fd[1]->h); |
1949 | p->fd[1]->h = tmp_handle; | 1950 | p->fd[1]->h = tmp_handle; |
1950 | if (!blocking) | 1951 | if (!blocking) |
1951 | { | 1952 | { |
1952 | DWORD mode; | 1953 | DWORD mode; |
1953 | 1954 | ||
1954 | mode = PIPE_NOWAIT; | 1955 | mode = PIPE_NOWAIT; |
1955 | SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); | 1956 | SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); |
1956 | SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); | 1957 | SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); |
1957 | /* this always fails on Windows 95, so we don't care about error handling */ | 1958 | /* this always fails on Windows 95, so we don't care about error handling */ |
1958 | } | 1959 | } |
1959 | p->fd[0]->type = GNUNET_PIPE; | 1960 | p->fd[0]->type = GNUNET_PIPE; |
1960 | p->fd[1]->type = GNUNET_PIPE; | 1961 | p->fd[1]->type = GNUNET_PIPE; |
1961 | 1962 | ||
@@ -1984,51 +1985,51 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write) | |||
1984 | */ | 1985 | */ |
1985 | int | 1986 | int |
1986 | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, | 1987 | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, |
1987 | enum GNUNET_DISK_PipeEnd end) | 1988 | enum GNUNET_DISK_PipeEnd end) |
1988 | { | 1989 | { |
1989 | int ret = GNUNET_OK; | 1990 | int ret = GNUNET_OK; |
1990 | int save; | 1991 | int save; |
1991 | 1992 | ||
1992 | #ifdef MINGW | 1993 | #ifdef MINGW |
1993 | if (end == GNUNET_DISK_PIPE_END_READ) | 1994 | if (end == GNUNET_DISK_PIPE_END_READ) |
1995 | { | ||
1996 | if (!CloseHandle (p->fd[0]->h)) | ||
1994 | { | 1997 | { |
1995 | if (!CloseHandle (p->fd[0]->h)) | 1998 | SetErrnoFromWinError (GetLastError ()); |
1996 | { | 1999 | ret = GNUNET_SYSERR; |
1997 | SetErrnoFromWinError (GetLastError ()); | ||
1998 | ret = GNUNET_SYSERR; | ||
1999 | } | ||
2000 | p->fd[0]->h = INVALID_HANDLE_VALUE; | ||
2001 | } | 2000 | } |
2001 | p->fd[0]->h = INVALID_HANDLE_VALUE; | ||
2002 | } | ||
2002 | else if (end == GNUNET_DISK_PIPE_END_WRITE) | 2003 | else if (end == GNUNET_DISK_PIPE_END_WRITE) |
2004 | { | ||
2005 | if (!CloseHandle (p->fd[1]->h)) | ||
2003 | { | 2006 | { |
2004 | if (!CloseHandle (p->fd[1]->h)) | 2007 | SetErrnoFromWinError (GetLastError ()); |
2005 | { | 2008 | ret = GNUNET_SYSERR; |
2006 | SetErrnoFromWinError (GetLastError ()); | ||
2007 | ret = GNUNET_SYSERR; | ||
2008 | } | ||
2009 | p->fd[1]->h = INVALID_HANDLE_VALUE; | ||
2010 | } | 2009 | } |
2010 | p->fd[1]->h = INVALID_HANDLE_VALUE; | ||
2011 | } | ||
2011 | save = errno; | 2012 | save = errno; |
2012 | #else | 2013 | #else |
2013 | save = 0; | 2014 | save = 0; |
2014 | if (end == GNUNET_DISK_PIPE_END_READ) | 2015 | if (end == GNUNET_DISK_PIPE_END_READ) |
2016 | { | ||
2017 | if (0 != close (p->fd[0]->fd)) | ||
2015 | { | 2018 | { |
2016 | if (0 != close (p->fd[0]->fd)) | 2019 | ret = GNUNET_SYSERR; |
2017 | { | 2020 | save = errno; |
2018 | ret = GNUNET_SYSERR; | ||
2019 | save = errno; | ||
2020 | } | ||
2021 | p->fd[0]->fd = -1; | ||
2022 | } | 2021 | } |
2022 | p->fd[0]->fd = -1; | ||
2023 | } | ||
2023 | else if (end == GNUNET_DISK_PIPE_END_WRITE) | 2024 | else if (end == GNUNET_DISK_PIPE_END_WRITE) |
2025 | { | ||
2026 | if (0 != close (p->fd[1]->fd)) | ||
2024 | { | 2027 | { |
2025 | if (0 != close (p->fd[1]->fd)) | 2028 | ret = GNUNET_SYSERR; |
2026 | { | 2029 | save = errno; |
2027 | ret = GNUNET_SYSERR; | ||
2028 | save = errno; | ||
2029 | } | ||
2030 | p->fd[1]->fd = -1; | ||
2031 | } | 2030 | } |
2031 | p->fd[1]->fd = -1; | ||
2032 | } | ||
2032 | #endif | 2033 | #endif |
2033 | errno = save; | 2034 | errno = save; |
2034 | return ret; | 2035 | return ret; |
@@ -2048,35 +2049,35 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) | |||
2048 | 2049 | ||
2049 | #ifdef MINGW | 2050 | #ifdef MINGW |
2050 | if (!CloseHandle (p->fd[0]->h)) | 2051 | if (!CloseHandle (p->fd[0]->h)) |
2051 | { | 2052 | { |
2052 | SetErrnoFromWinError (GetLastError ()); | 2053 | SetErrnoFromWinError (GetLastError ()); |
2053 | ret = GNUNET_SYSERR; | 2054 | ret = GNUNET_SYSERR; |
2054 | } | 2055 | } |
2055 | if (!CloseHandle (p->fd[1]->h)) | 2056 | if (!CloseHandle (p->fd[1]->h)) |
2056 | { | 2057 | { |
2057 | SetErrnoFromWinError (GetLastError ()); | 2058 | SetErrnoFromWinError (GetLastError ()); |
2058 | ret = GNUNET_SYSERR; | 2059 | ret = GNUNET_SYSERR; |
2059 | } | 2060 | } |
2060 | save = errno; | 2061 | save = errno; |
2061 | #else | 2062 | #else |
2062 | save = 0; | 2063 | save = 0; |
2063 | if (p->fd[0]->fd != -1) | 2064 | if (p->fd[0]->fd != -1) |
2065 | { | ||
2066 | if (0 != close (p->fd[0]->fd)) | ||
2064 | { | 2067 | { |
2065 | if (0 != close (p->fd[0]->fd)) | 2068 | ret = GNUNET_SYSERR; |
2066 | { | 2069 | save = errno; |
2067 | ret = GNUNET_SYSERR; | ||
2068 | save = errno; | ||
2069 | } | ||
2070 | } | 2070 | } |
2071 | } | ||
2071 | 2072 | ||
2072 | if (p->fd[1]->fd != -1) | 2073 | if (p->fd[1]->fd != -1) |
2074 | { | ||
2075 | if (0 != close (p->fd[1]->fd)) | ||
2073 | { | 2076 | { |
2074 | if (0 != close (p->fd[1]->fd)) | 2077 | ret = GNUNET_SYSERR; |
2075 | { | 2078 | save = errno; |
2076 | ret = GNUNET_SYSERR; | ||
2077 | save = errno; | ||
2078 | } | ||
2079 | } | 2079 | } |
2080 | } | ||
2080 | #endif | 2081 | #endif |
2081 | GNUNET_free (p); | 2082 | GNUNET_free (p); |
2082 | errno = save; | 2083 | errno = save; |
@@ -2114,93 +2115,104 @@ GNUNET_DISK_npipe_create (char **fn, | |||
2114 | openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; | 2115 | openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; |
2115 | 2116 | ||
2116 | while (h == NULL) | 2117 | while (h == NULL) |
2118 | { | ||
2119 | DWORD error_code; | ||
2120 | |||
2121 | name = NULL; | ||
2122 | if (*fn != NULL) | ||
2117 | { | 2123 | { |
2118 | DWORD error_code; | 2124 | GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn); |
2119 | name = NULL; | ||
2120 | if (*fn != NULL) | ||
2121 | { | ||
2122 | GNUNET_asprintf(&name, "\\\\.\\pipe\\%.246s", fn); | ||
2123 | #if DEBUG_NPIPE | 2125 | #if DEBUG_NPIPE |
2124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to create an instance of named pipe `%s'\n", name); | 2126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2127 | "Trying to create an instance of named pipe `%s'\n", name); | ||
2125 | #endif | 2128 | #endif |
2126 | h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, | 2129 | h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, |
2127 | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, NULL); | 2130 | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, |
2128 | } | 2131 | NULL); |
2129 | else | 2132 | } |
2130 | { | 2133 | else |
2131 | GNUNET_asprintf(fn, "\\\\.\\pipe\\gnunet-%llu", | 2134 | { |
2132 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX)); | 2135 | GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu", |
2136 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
2137 | UINT64_MAX)); | ||
2133 | #if DEBUG_NPIPE | 2138 | #if DEBUG_NPIPE |
2134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named pipe `%s'\n", *fn); | 2139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2140 | "Trying to create unique named pipe `%s'\n", *fn); | ||
2135 | #endif | 2141 | #endif |
2136 | h = CreateNamedPipe (*fn, openMode | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, | 2142 | h = CreateNamedPipe (*fn, |
2137 | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, NULL); | 2143 | openMode | FILE_FLAG_OVERLAPPED | |
2138 | } | 2144 | FILE_FLAG_FIRST_PIPE_INSTANCE, |
2139 | error_code = GetLastError (); | 2145 | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, |
2140 | if (name) | 2146 | NULL); |
2141 | GNUNET_free(name); | 2147 | } |
2142 | /* don't re-set name to NULL yet */ | 2148 | error_code = GetLastError (); |
2143 | if (h == INVALID_HANDLE_VALUE) | 2149 | if (name) |
2144 | { | 2150 | GNUNET_free (name); |
2145 | SetErrnoFromWinError(error_code); | 2151 | /* don't re-set name to NULL yet */ |
2152 | if (h == INVALID_HANDLE_VALUE) | ||
2153 | { | ||
2154 | SetErrnoFromWinError (error_code); | ||
2146 | #if DEBUG_NPIPE | 2155 | #if DEBUG_NPIPE |
2147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pipe creation have failed because of %d, errno is %d\n", error_code, errno); | 2156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2157 | "Pipe creation have failed because of %d, errno is %d\n", | ||
2158 | error_code, errno); | ||
2148 | #endif | 2159 | #endif |
2149 | if (name == NULL) | 2160 | if (name == NULL) |
2150 | { | 2161 | { |
2151 | #if DEBUG_NPIPE | 2162 | #if DEBUG_NPIPE |
2152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pipe was to be unique, considering re-creation\n"); | 2163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2164 | "Pipe was to be unique, considering re-creation\n"); | ||
2153 | #endif | 2165 | #endif |
2154 | GNUNET_free (*fn); | 2166 | GNUNET_free (*fn); |
2155 | *fn = NULL; | 2167 | *fn = NULL; |
2156 | if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY) | 2168 | if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY) |
2157 | { | 2169 | { |
2158 | return NULL; | 2170 | return NULL; |
2159 | } | 2171 | } |
2160 | #if DEBUG_NPIPE | 2172 | #if DEBUG_NPIPE |
2161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Pipe name was not unique, trying again\n"); | 2173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2174 | "Pipe name was not unique, trying again\n"); | ||
2162 | #endif | 2175 | #endif |
2163 | h = NULL; | 2176 | h = NULL; |
2164 | } | 2177 | } |
2165 | else | 2178 | else |
2166 | return NULL; | 2179 | return NULL; |
2167 | } | ||
2168 | } | 2180 | } |
2181 | } | ||
2169 | errno = 0; | 2182 | errno = 0; |
2170 | 2183 | ||
2171 | ret = GNUNET_malloc(sizeof(*ret)); | 2184 | ret = GNUNET_malloc (sizeof (*ret)); |
2172 | ret->h = h; | 2185 | ret->h = h; |
2173 | ret->type = GNUNET_PIPE; | 2186 | ret->type = GNUNET_PIPE; |
2174 | 2187 | ||
2175 | ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); | 2188 | ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); |
2176 | ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED)); | 2189 | ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED)); |
2177 | 2190 | ||
2178 | ret->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | 2191 | ret->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); |
2179 | ret->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | 2192 | ret->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); |
2180 | 2193 | ||
2181 | return ret; | 2194 | return ret; |
2182 | #else | 2195 | #else |
2183 | if (*fn == NULL) | 2196 | if (*fn == NULL) |
2184 | { | 2197 | { |
2185 | char dir[] = "/tmp/gnunet-pipe-XXXXXX"; | 2198 | char dir[] = "/tmp/gnunet-pipe-XXXXXX"; |
2186 | |||
2187 | if (mkdtemp(dir) == NULL) | ||
2188 | { | ||
2189 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "mkdtemp"); | ||
2190 | return NULL; | ||
2191 | } | ||
2192 | GNUNET_asprintf(fn, "%s/child-control", dir); | ||
2193 | } | ||
2194 | 2199 | ||
2195 | if (mkfifo(*fn, translate_unix_perms(perm)) == -1) | 2200 | if (mkdtemp (dir) == NULL) |
2196 | { | 2201 | { |
2197 | if ( (errno != EEXIST) || | 2202 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "mkdtemp"); |
2198 | (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) ) | 2203 | return NULL; |
2199 | return NULL; | ||
2200 | } | 2204 | } |
2205 | GNUNET_asprintf (fn, "%s/child-control", dir); | ||
2206 | } | ||
2207 | |||
2208 | if (mkfifo (*fn, translate_unix_perms (perm)) == -1) | ||
2209 | { | ||
2210 | if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))) | ||
2211 | return NULL; | ||
2212 | } | ||
2201 | 2213 | ||
2202 | flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); | 2214 | flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); |
2203 | return GNUNET_DISK_file_open(*fn, flags, perm); | 2215 | return GNUNET_DISK_file_open (*fn, flags, perm); |
2204 | #endif | 2216 | #endif |
2205 | } | 2217 | } |
2206 | 2218 | ||
@@ -2232,14 +2244,14 @@ GNUNET_DISK_npipe_open (const char *fn, | |||
2232 | openMode = GENERIC_WRITE; | 2244 | openMode = GENERIC_WRITE; |
2233 | 2245 | ||
2234 | h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING, | 2246 | h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING, |
2235 | FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); | 2247 | FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); |
2236 | if (h == INVALID_HANDLE_VALUE) | 2248 | if (h == INVALID_HANDLE_VALUE) |
2237 | { | 2249 | { |
2238 | SetErrnoFromWinError(GetLastError()); | 2250 | SetErrnoFromWinError (GetLastError ()); |
2239 | return NULL; | 2251 | return NULL; |
2240 | } | 2252 | } |
2241 | 2253 | ||
2242 | ret = GNUNET_malloc(sizeof(*ret)); | 2254 | ret = GNUNET_malloc (sizeof (*ret)); |
2243 | ret->h = h; | 2255 | ret->h = h; |
2244 | ret->type = GNUNET_PIPE; | 2256 | ret->type = GNUNET_PIPE; |
2245 | ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); | 2257 | ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); |
@@ -2250,7 +2262,7 @@ GNUNET_DISK_npipe_open (const char *fn, | |||
2250 | return ret; | 2262 | return ret; |
2251 | #else | 2263 | #else |
2252 | flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); | 2264 | flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); |
2253 | return GNUNET_DISK_file_open(fn, flags, perm); | 2265 | return GNUNET_DISK_file_open (fn, flags, perm); |
2254 | #endif | 2266 | #endif |
2255 | } | 2267 | } |
2256 | 2268 | ||
@@ -2263,16 +2275,16 @@ int | |||
2263 | GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe) | 2275 | GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe) |
2264 | { | 2276 | { |
2265 | #ifndef MINGW | 2277 | #ifndef MINGW |
2266 | return close(pipe->fd) == 0 ? GNUNET_OK : GNUNET_SYSERR; | 2278 | return close (pipe->fd) == 0 ? GNUNET_OK : GNUNET_SYSERR; |
2267 | #else | 2279 | #else |
2268 | BOOL ret; | 2280 | BOOL ret; |
2269 | 2281 | ||
2270 | ret = CloseHandle(pipe->h); | 2282 | ret = CloseHandle (pipe->h); |
2271 | if (!ret) | 2283 | if (!ret) |
2272 | { | 2284 | { |
2273 | SetErrnoFromWinError(GetLastError()); | 2285 | SetErrnoFromWinError (GetLastError ()); |
2274 | return GNUNET_SYSERR; | 2286 | return GNUNET_SYSERR; |
2275 | } | 2287 | } |
2276 | else | 2288 | else |
2277 | return GNUNET_OK; | 2289 | return GNUNET_OK; |
2278 | #endif | 2290 | #endif |
@@ -2291,14 +2303,14 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, | |||
2291 | enum GNUNET_DISK_PipeEnd n) | 2303 | enum GNUNET_DISK_PipeEnd n) |
2292 | { | 2304 | { |
2293 | switch (n) | 2305 | switch (n) |
2294 | { | 2306 | { |
2295 | case GNUNET_DISK_PIPE_END_READ: | 2307 | case GNUNET_DISK_PIPE_END_READ: |
2296 | case GNUNET_DISK_PIPE_END_WRITE: | 2308 | case GNUNET_DISK_PIPE_END_WRITE: |
2297 | return p->fd[n]; | 2309 | return p->fd[n]; |
2298 | default: | 2310 | default: |
2299 | GNUNET_break (0); | 2311 | GNUNET_break (0); |
2300 | return NULL; | 2312 | return NULL; |
2301 | } | 2313 | } |
2302 | } | 2314 | } |
2303 | 2315 | ||
2304 | 2316 | ||
diff --git a/src/util/disk.h b/src/util/disk.h index 0f094e289..8c48b85ca 100644 --- a/src/util/disk.h +++ b/src/util/disk.h | |||
@@ -16,8 +16,8 @@ | |||
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file util/disk.h | 22 | * @file util/disk.h |
23 | * @brief Internal DISK related helper functions | 23 | * @brief Internal DISK related helper functions |
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #ifndef GNUNET_DISK_H_ | 26 | #ifndef GNUNET_DISK_H_ |
27 | #define GNUNET_DISK_H_ | 27 | #define GNUNET_DISK_H_ |
28 | 28 | ||
29 | #include "gnunet_disk_lib.h" | 29 | #include "gnunet_disk_lib.h" |
30 | 30 | ||
31 | /** | 31 | /** |
@@ -36,10 +36,8 @@ | |||
36 | * @param dst destination buffer | 36 | * @param dst destination buffer |
37 | * @param dst_len length of dst | 37 | * @param dst_len length of dst |
38 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 38 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise |
39 | */ | 39 | */ |
40 | int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle | 40 | int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle |
41 | *fh, | 41 | *fh, void *dst, size_t dst_len); |
42 | void *dst, | ||
43 | size_t dst_len); | ||
44 | 42 | ||
45 | #endif /* GNUNET_DISK_H_ */ | 43 | #endif /* GNUNET_DISK_H_ */ |
diff --git a/src/util/getopt.c b/src/util/getopt.c index b8a295fae..2a35ab278 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c | |||
@@ -43,27 +43,27 @@ Copyright (C) 2006 Christian Grothoff | |||
43 | #include "gnunet_getopt_lib.h" | 43 | #include "gnunet_getopt_lib.h" |
44 | 44 | ||
45 | #ifdef VMS | 45 | #ifdef VMS |
46 | # include <unixlib.h> | 46 | #include <unixlib.h> |
47 | # if HAVE_STRING_H - 0 | 47 | #if HAVE_STRING_H - 0 |
48 | # include <string.h> | 48 | #include <string.h> |
49 | # endif | 49 | #endif |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #if defined (WIN32) && !defined (__CYGWIN32__) | 52 | #if defined (WIN32) && !defined (__CYGWIN32__) |
53 | /* It's not Unix, really. See? Capital letters. */ | 53 | /* It's not Unix, really. See? Capital letters. */ |
54 | # include <windows.h> | 54 | #include <windows.h> |
55 | # define getpid() GetCurrentProcessId() | 55 | #define getpid() GetCurrentProcessId() |
56 | #endif | 56 | #endif |
57 | 57 | ||
58 | #ifndef _ | 58 | #ifndef _ |
59 | /* This is for other GNU distributions with internationalized messages. | 59 | /* This is for other GNU distributions with internationalized messages. |
60 | When compiling libc, the _ macro is predefined. */ | 60 | When compiling libc, the _ macro is predefined. */ |
61 | # ifdef HAVE_LIBINTL_H | 61 | #ifdef HAVE_LIBINTL_H |
62 | # include <libintl.h> | 62 | #include <libintl.h> |
63 | # define _(msgid) gettext (msgid) | 63 | #define _(msgid) gettext (msgid) |
64 | # else | 64 | #else |
65 | # define _(msgid) (msgid) | 65 | #define _(msgid) (msgid) |
66 | # endif | 66 | #endif |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | /* Describe the long-named options requested by the application. | 69 | /* Describe the long-named options requested by the application. |
@@ -91,7 +91,7 @@ struct GNoption | |||
91 | { | 91 | { |
92 | const char *name; | 92 | const char *name; |
93 | /* has_arg can't be an enum because some compilers complain about | 93 | /* has_arg can't be an enum because some compilers complain about |
94 | type mismatches in all the code that assumes it is an int. */ | 94 | * type mismatches in all the code that assumes it is an int. */ |
95 | int has_arg; | 95 | int has_arg; |
96 | int *flag; | 96 | int *flag; |
97 | int val; | 97 | int val; |
@@ -198,15 +198,15 @@ char *getenv (); | |||
198 | 198 | ||
199 | static char * | 199 | static char * |
200 | my_index (str, chr) | 200 | my_index (str, chr) |
201 | const char *str; | 201 | const char *str; |
202 | int chr; | 202 | int chr; |
203 | { | 203 | { |
204 | while (*str) | 204 | while (*str) |
205 | { | 205 | { |
206 | if (*str == chr) | 206 | if (*str == chr) |
207 | return (char *) str; | 207 | return (char *) str; |
208 | str++; | 208 | str++; |
209 | } | 209 | } |
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
@@ -252,17 +252,17 @@ extern pid_t __libc_pid; | |||
252 | is valid for the getopt call we must make sure that the ARGV passed | 252 | is valid for the getopt call we must make sure that the ARGV passed |
253 | to getopt is that one passed to the process. */ | 253 | to getopt is that one passed to the process. */ |
254 | static void | 254 | static void |
255 | __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) | 255 | __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) |
256 | { | 256 | { |
257 | /* XXX This is no good solution. We should rather copy the args so | 257 | /* XXX This is no good solution. We should rather copy the args so |
258 | that we can compare them later. But we must not use malloc(3). */ | 258 | * that we can compare them later. But we must not use malloc(3). */ |
259 | original_argc = argc; | 259 | original_argc = argc; |
260 | original_argv = argv; | 260 | original_argv = argv; |
261 | } | 261 | } |
262 | 262 | ||
263 | text_set_element (__libc_subinit, store_args_and_env); | 263 | text_set_element (__libc_subinit, store_args_and_env); |
264 | 264 | ||
265 | # define SWAP_FLAGS(ch1, ch2) \ | 265 | #define SWAP_FLAGS(ch1, ch2) \ |
266 | if (nonoption_flags_len > 0) \ | 266 | if (nonoption_flags_len > 0) \ |
267 | { \ | 267 | { \ |
268 | char __tmp = __getopt_nonoption_flags[ch1]; \ | 268 | char __tmp = __getopt_nonoption_flags[ch1]; \ |
@@ -270,7 +270,7 @@ text_set_element (__libc_subinit, store_args_and_env); | |||
270 | __getopt_nonoption_flags[ch2] = __tmp; \ | 270 | __getopt_nonoption_flags[ch2] = __tmp; \ |
271 | } | 271 | } |
272 | #else /* !_LIBC */ | 272 | #else /* !_LIBC */ |
273 | # define SWAP_FLAGS(ch1, ch2) | 273 | #define SWAP_FLAGS(ch1, ch2) |
274 | #endif /* _LIBC */ | 274 | #endif /* _LIBC */ |
275 | 275 | ||
276 | /* Exchange two adjacent subsequences of ARGV. | 276 | /* Exchange two adjacent subsequences of ARGV. |
@@ -288,7 +288,7 @@ static void exchange (char **); | |||
288 | 288 | ||
289 | static void | 289 | static void |
290 | exchange (argv) | 290 | exchange (argv) |
291 | char **argv; | 291 | char **argv; |
292 | { | 292 | { |
293 | int bottom = first_nonopt; | 293 | int bottom = first_nonopt; |
294 | int middle = last_nonopt; | 294 | int middle = last_nonopt; |
@@ -296,69 +296,70 @@ exchange (argv) | |||
296 | char *tem; | 296 | char *tem; |
297 | 297 | ||
298 | /* Exchange the shorter segment with the far end of the longer segment. | 298 | /* Exchange the shorter segment with the far end of the longer segment. |
299 | That puts the shorter segment into the right place. | 299 | * That puts the shorter segment into the right place. |
300 | It leaves the longer segment in the right place overall, | 300 | * It leaves the longer segment in the right place overall, |
301 | but it consists of two parts that need to be swapped next. */ | 301 | * but it consists of two parts that need to be swapped next. */ |
302 | 302 | ||
303 | #ifdef _LIBC | 303 | #ifdef _LIBC |
304 | /* First make sure the handling of the `__getopt_nonoption_flags' | 304 | /* First make sure the handling of the `__getopt_nonoption_flags' |
305 | string can work normally. Our top argument must be in the range | 305 | * string can work normally. Our top argument must be in the range |
306 | of the string. */ | 306 | * of the string. */ |
307 | if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) | 307 | if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) |
308 | { | ||
309 | /* We must extend the array. The user plays games with us and | ||
310 | * presents new arguments. */ | ||
311 | char *new_str = malloc (top + 1); | ||
312 | |||
313 | if (new_str == NULL) | ||
314 | nonoption_flags_len = nonoption_flags_max_len = 0; | ||
315 | else | ||
308 | { | 316 | { |
309 | /* We must extend the array. The user plays games with us and | 317 | memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len); |
310 | presents new arguments. */ | 318 | memset (&new_str[nonoption_flags_max_len], '\0', |
311 | char *new_str = malloc (top + 1); | 319 | top + 1 - nonoption_flags_max_len); |
312 | if (new_str == NULL) | 320 | nonoption_flags_max_len = top + 1; |
313 | nonoption_flags_len = nonoption_flags_max_len = 0; | 321 | __getopt_nonoption_flags = new_str; |
314 | else | ||
315 | { | ||
316 | memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len); | ||
317 | memset (&new_str[nonoption_flags_max_len], '\0', | ||
318 | top + 1 - nonoption_flags_max_len); | ||
319 | nonoption_flags_max_len = top + 1; | ||
320 | __getopt_nonoption_flags = new_str; | ||
321 | } | ||
322 | } | 322 | } |
323 | } | ||
323 | #endif | 324 | #endif |
324 | 325 | ||
325 | while (top > middle && middle > bottom) | 326 | while (top > middle && middle > bottom) |
327 | { | ||
328 | if (top - middle > middle - bottom) | ||
326 | { | 329 | { |
327 | if (top - middle > middle - bottom) | 330 | /* Bottom segment is the short one. */ |
328 | { | 331 | int len = middle - bottom; |
329 | /* Bottom segment is the short one. */ | 332 | register int i; |
330 | int len = middle - bottom; | ||
331 | register int i; | ||
332 | 333 | ||
333 | /* Swap it with the top part of the top segment. */ | 334 | /* Swap it with the top part of the top segment. */ |
334 | for (i = 0; i < len; i++) | 335 | for (i = 0; i < len; i++) |
335 | { | 336 | { |
336 | tem = argv[bottom + i]; | 337 | tem = argv[bottom + i]; |
337 | argv[bottom + i] = argv[top - (middle - bottom) + i]; | 338 | argv[bottom + i] = argv[top - (middle - bottom) + i]; |
338 | argv[top - (middle - bottom) + i] = tem; | 339 | argv[top - (middle - bottom) + i] = tem; |
339 | SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); | 340 | SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); |
340 | } | 341 | } |
341 | /* Exclude the moved bottom segment from further swapping. */ | 342 | /* Exclude the moved bottom segment from further swapping. */ |
342 | top -= len; | 343 | top -= len; |
343 | } | 344 | } |
344 | else | 345 | else |
345 | { | 346 | { |
346 | /* Top segment is the short one. */ | 347 | /* Top segment is the short one. */ |
347 | int len = top - middle; | 348 | int len = top - middle; |
348 | register int i; | 349 | register int i; |
349 | 350 | ||
350 | /* Swap it with the bottom part of the bottom segment. */ | 351 | /* Swap it with the bottom part of the bottom segment. */ |
351 | for (i = 0; i < len; i++) | 352 | for (i = 0; i < len; i++) |
352 | { | 353 | { |
353 | tem = argv[bottom + i]; | 354 | tem = argv[bottom + i]; |
354 | argv[bottom + i] = argv[middle + i]; | 355 | argv[bottom + i] = argv[middle + i]; |
355 | argv[middle + i] = tem; | 356 | argv[middle + i] = tem; |
356 | SWAP_FLAGS (bottom + i, middle + i); | 357 | SWAP_FLAGS (bottom + i, middle + i); |
357 | } | 358 | } |
358 | /* Exclude the moved top segment from further swapping. */ | 359 | /* Exclude the moved top segment from further swapping. */ |
359 | bottom += len; | 360 | bottom += len; |
360 | } | ||
361 | } | 361 | } |
362 | } | ||
362 | 363 | ||
363 | /* Update records for the slots the non-options now occupy. */ | 364 | /* Update records for the slots the non-options now occupy. */ |
364 | 365 | ||
@@ -373,13 +374,13 @@ static const char *_getopt_initialize (int, char *const *, const char *); | |||
373 | #endif | 374 | #endif |
374 | static const char * | 375 | static const char * |
375 | _getopt_initialize (argc, argv, optstring) | 376 | _getopt_initialize (argc, argv, optstring) |
376 | int argc; | 377 | int argc; |
377 | char *const *argv; | 378 | char *const *argv; |
378 | const char *optstring; | 379 | const char *optstring; |
379 | { | 380 | { |
380 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 | 381 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 |
381 | is the program name); the sequence of previously skipped | 382 | * is the program name); the sequence of previously skipped |
382 | non-option ARGV-elements is empty. */ | 383 | * non-option ARGV-elements is empty. */ |
383 | 384 | ||
384 | first_nonopt = last_nonopt = GNoptind; | 385 | first_nonopt = last_nonopt = GNoptind; |
385 | 386 | ||
@@ -390,49 +391,48 @@ _getopt_initialize (argc, argv, optstring) | |||
390 | /* Determine how to handle the ordering of options and nonoptions. */ | 391 | /* Determine how to handle the ordering of options and nonoptions. */ |
391 | 392 | ||
392 | if (optstring[0] == '-') | 393 | if (optstring[0] == '-') |
393 | { | 394 | { |
394 | ordering = RETURN_IN_ORDER; | 395 | ordering = RETURN_IN_ORDER; |
395 | ++optstring; | 396 | ++optstring; |
396 | } | 397 | } |
397 | else if (optstring[0] == '+') | 398 | else if (optstring[0] == '+') |
398 | { | 399 | { |
399 | ordering = REQUIRE_ORDER; | 400 | ordering = REQUIRE_ORDER; |
400 | ++optstring; | 401 | ++optstring; |
401 | } | 402 | } |
402 | else if (posixly_correct != NULL) | 403 | else if (posixly_correct != NULL) |
403 | ordering = REQUIRE_ORDER; | 404 | ordering = REQUIRE_ORDER; |
404 | else | 405 | else |
405 | ordering = PERMUTE; | 406 | ordering = PERMUTE; |
406 | 407 | ||
407 | #ifdef _LIBC | 408 | #ifdef _LIBC |
408 | if (posixly_correct == NULL | 409 | if (posixly_correct == NULL && argc == original_argc && argv == original_argv) |
409 | && argc == original_argc && argv == original_argv) | 410 | { |
411 | if (nonoption_flags_max_len == 0) | ||
410 | { | 412 | { |
411 | if (nonoption_flags_max_len == 0) | 413 | if (__getopt_nonoption_flags == NULL |
414 | || __getopt_nonoption_flags[0] == '\0') | ||
415 | nonoption_flags_max_len = -1; | ||
416 | else | ||
417 | { | ||
418 | const char *orig_str = __getopt_nonoption_flags; | ||
419 | int len = nonoption_flags_max_len = strlen (orig_str); | ||
420 | |||
421 | if (nonoption_flags_max_len < argc) | ||
422 | nonoption_flags_max_len = argc; | ||
423 | __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len); | ||
424 | if (__getopt_nonoption_flags == NULL) | ||
425 | nonoption_flags_max_len = -1; | ||
426 | else | ||
412 | { | 427 | { |
413 | if (__getopt_nonoption_flags == NULL | 428 | memcpy (__getopt_nonoption_flags, orig_str, len); |
414 | || __getopt_nonoption_flags[0] == '\0') | 429 | memset (&__getopt_nonoption_flags[len], '\0', |
415 | nonoption_flags_max_len = -1; | 430 | nonoption_flags_max_len - len); |
416 | else | ||
417 | { | ||
418 | const char *orig_str = __getopt_nonoption_flags; | ||
419 | int len = nonoption_flags_max_len = strlen (orig_str); | ||
420 | if (nonoption_flags_max_len < argc) | ||
421 | nonoption_flags_max_len = argc; | ||
422 | __getopt_nonoption_flags = | ||
423 | (char *) malloc (nonoption_flags_max_len); | ||
424 | if (__getopt_nonoption_flags == NULL) | ||
425 | nonoption_flags_max_len = -1; | ||
426 | else | ||
427 | { | ||
428 | memcpy (__getopt_nonoption_flags, orig_str, len); | ||
429 | memset (&__getopt_nonoption_flags[len], '\0', | ||
430 | nonoption_flags_max_len - len); | ||
431 | } | ||
432 | } | ||
433 | } | 431 | } |
434 | nonoption_flags_len = nonoption_flags_max_len; | 432 | } |
435 | } | 433 | } |
434 | nonoption_flags_len = nonoption_flags_max_len; | ||
435 | } | ||
436 | else | 436 | else |
437 | nonoption_flags_len = 0; | 437 | nonoption_flags_len = 0; |
438 | #endif | 438 | #endif |
@@ -498,11 +498,10 @@ _getopt_initialize (argc, argv, optstring) | |||
498 | 498 | ||
499 | static int | 499 | static int |
500 | GN_getopt_internal (int argc, | 500 | GN_getopt_internal (int argc, |
501 | char *const *argv, | 501 | char *const *argv, |
502 | const char *optstring, | 502 | const char *optstring, |
503 | const struct GNoption *longopts, | 503 | const struct GNoption *longopts, |
504 | int *longind, | 504 | int *longind, int long_only) |
505 | int long_only) | ||
506 | { | 505 | { |
507 | static int __getopt_initialized = 0; | 506 | static int __getopt_initialized = 0; |
508 | static int GNopterr = 1; | 507 | static int GNopterr = 1; |
@@ -510,17 +509,17 @@ GN_getopt_internal (int argc, | |||
510 | GNoptarg = NULL; | 509 | GNoptarg = NULL; |
511 | 510 | ||
512 | if (GNoptind == 0 || !__getopt_initialized) | 511 | if (GNoptind == 0 || !__getopt_initialized) |
513 | { | 512 | { |
514 | if (GNoptind == 0) | 513 | if (GNoptind == 0) |
515 | GNoptind = 1; /* Don't scan ARGV[0], the program name. */ | 514 | GNoptind = 1; /* Don't scan ARGV[0], the program name. */ |
516 | optstring = _getopt_initialize (argc, argv, optstring); | 515 | optstring = _getopt_initialize (argc, argv, optstring); |
517 | __getopt_initialized = 1; | 516 | __getopt_initialized = 1; |
518 | } | 517 | } |
519 | 518 | ||
520 | /* Test whether ARGV[GNoptind] points to a non-option argument. | 519 | /* Test whether ARGV[GNoptind] points to a non-option argument. |
521 | Either it does not have option syntax, or there is an environment flag | 520 | * Either it does not have option syntax, or there is an environment flag |
522 | from the shell indicating it is not an option. The later information | 521 | * from the shell indicating it is not an option. The later information |
523 | is only used when the used in the GNU libc. */ | 522 | * is only used when the used in the GNU libc. */ |
524 | #ifdef _LIBC | 523 | #ifdef _LIBC |
525 | #define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0' \ | 524 | #define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0' \ |
526 | || (GNoptind < nonoption_flags_len \ | 525 | || (GNoptind < nonoption_flags_len \ |
@@ -530,233 +529,232 @@ GN_getopt_internal (int argc, | |||
530 | #endif | 529 | #endif |
531 | 530 | ||
532 | if (nextchar == NULL || *nextchar == '\0') | 531 | if (nextchar == NULL || *nextchar == '\0') |
533 | { | 532 | { |
534 | /* Advance to the next ARGV-element. */ | 533 | /* Advance to the next ARGV-element. */ |
535 | 534 | ||
536 | /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been | 535 | /* Give FIRST_NONOPT & LAST_NONOPT rational values if GNoptind has been |
537 | moved back by the user (who may also have changed the arguments). */ | 536 | * moved back by the user (who may also have changed the arguments). */ |
538 | if (last_nonopt > GNoptind) | 537 | if (last_nonopt > GNoptind) |
539 | last_nonopt = GNoptind; | 538 | last_nonopt = GNoptind; |
540 | if (first_nonopt > GNoptind) | 539 | if (first_nonopt > GNoptind) |
541 | first_nonopt = GNoptind; | 540 | first_nonopt = GNoptind; |
542 | 541 | ||
543 | if (ordering == PERMUTE) | 542 | if (ordering == PERMUTE) |
544 | { | 543 | { |
545 | /* If we have just processed some options following some non-options, | 544 | /* If we have just processed some options following some non-options, |
546 | exchange them so that the options come first. */ | 545 | * exchange them so that the options come first. */ |
547 | 546 | ||
548 | if (first_nonopt != last_nonopt && last_nonopt != GNoptind) | 547 | if (first_nonopt != last_nonopt && last_nonopt != GNoptind) |
549 | exchange ((char **) argv); | 548 | exchange ((char **) argv); |
550 | else if (last_nonopt != GNoptind) | 549 | else if (last_nonopt != GNoptind) |
551 | first_nonopt = GNoptind; | 550 | first_nonopt = GNoptind; |
552 | 551 | ||
553 | /* Skip any additional non-options | 552 | /* Skip any additional non-options |
554 | and extend the range of non-options previously skipped. */ | 553 | * and extend the range of non-options previously skipped. */ |
555 | 554 | ||
556 | while (GNoptind < argc && NONOPTION_P) | 555 | while (GNoptind < argc && NONOPTION_P) |
557 | GNoptind++; | 556 | GNoptind++; |
558 | last_nonopt = GNoptind; | 557 | last_nonopt = GNoptind; |
559 | } | 558 | } |
560 | 559 | ||
561 | /* The special ARGV-element `--' means premature end of options. | 560 | /* The special ARGV-element `--' means premature end of options. |
562 | Skip it like a null option, | 561 | * Skip it like a null option, |
563 | then exchange with previous non-options as if it were an option, | 562 | * then exchange with previous non-options as if it were an option, |
564 | then skip everything else like a non-option. */ | 563 | * then skip everything else like a non-option. */ |
565 | if (GNoptind != argc && !strcmp (argv[GNoptind], "--")) | 564 | if (GNoptind != argc && !strcmp (argv[GNoptind], "--")) |
566 | { | 565 | { |
567 | GNoptind++; | 566 | GNoptind++; |
568 | 567 | ||
569 | if (first_nonopt != last_nonopt && last_nonopt != GNoptind) | 568 | if (first_nonopt != last_nonopt && last_nonopt != GNoptind) |
570 | exchange ((char **) argv); | 569 | exchange ((char **) argv); |
571 | else if (first_nonopt == last_nonopt) | 570 | else if (first_nonopt == last_nonopt) |
572 | first_nonopt = GNoptind; | 571 | first_nonopt = GNoptind; |
573 | last_nonopt = argc; | 572 | last_nonopt = argc; |
574 | 573 | ||
575 | GNoptind = argc; | 574 | GNoptind = argc; |
576 | } | 575 | } |
577 | 576 | ||
578 | /* If we have done all the ARGV-elements, stop the scan | 577 | /* If we have done all the ARGV-elements, stop the scan |
579 | and back over any non-options that we skipped and permuted. */ | 578 | * and back over any non-options that we skipped and permuted. */ |
580 | 579 | ||
581 | if (GNoptind == argc) | 580 | if (GNoptind == argc) |
582 | { | 581 | { |
583 | /* Set the next-arg-index to point at the non-options | 582 | /* Set the next-arg-index to point at the non-options |
584 | that we previously skipped, so the caller will digest them. */ | 583 | * that we previously skipped, so the caller will digest them. */ |
585 | if (first_nonopt != last_nonopt) | 584 | if (first_nonopt != last_nonopt) |
586 | GNoptind = first_nonopt; | 585 | GNoptind = first_nonopt; |
587 | return -1; | 586 | return -1; |
588 | } | 587 | } |
589 | 588 | ||
590 | /* If we have come to a non-option and did not permute it, | 589 | /* If we have come to a non-option and did not permute it, |
591 | either stop the scan or describe it to the caller and pass it by. */ | 590 | * either stop the scan or describe it to the caller and pass it by. */ |
592 | 591 | ||
593 | if (NONOPTION_P) | 592 | if (NONOPTION_P) |
594 | { | 593 | { |
595 | if (ordering == REQUIRE_ORDER) | 594 | if (ordering == REQUIRE_ORDER) |
596 | return -1; | 595 | return -1; |
597 | GNoptarg = argv[GNoptind++]; | 596 | GNoptarg = argv[GNoptind++]; |
598 | return 1; | 597 | return 1; |
599 | } | 598 | } |
600 | 599 | ||
601 | /* We have found another option-ARGV-element. | 600 | /* We have found another option-ARGV-element. |
602 | Skip the initial punctuation. */ | 601 | * Skip the initial punctuation. */ |
603 | 602 | ||
604 | nextchar = (argv[GNoptind] + 1 | 603 | nextchar = (argv[GNoptind] + 1 |
605 | + (longopts != NULL && argv[GNoptind][1] == '-')); | 604 | + (longopts != NULL && argv[GNoptind][1] == '-')); |
606 | } | 605 | } |
607 | 606 | ||
608 | /* Decode the current option-ARGV-element. */ | 607 | /* Decode the current option-ARGV-element. */ |
609 | 608 | ||
610 | /* Check whether the ARGV-element is a long option. | 609 | /* Check whether the ARGV-element is a long option. |
611 | 610 | * | |
612 | If long_only and the ARGV-element has the form "-f", where f is | 611 | * If long_only and the ARGV-element has the form "-f", where f is |
613 | a valid short option, don't consider it an abbreviated form of | 612 | * a valid short option, don't consider it an abbreviated form of |
614 | a long option that starts with f. Otherwise there would be no | 613 | * a long option that starts with f. Otherwise there would be no |
615 | way to give the -f short option. | 614 | * way to give the -f short option. |
616 | 615 | * | |
617 | On the other hand, if there's a long option "fubar" and | 616 | * On the other hand, if there's a long option "fubar" and |
618 | the ARGV-element is "-fu", do consider that an abbreviation of | 617 | * the ARGV-element is "-fu", do consider that an abbreviation of |
619 | the long option, just like "--fu", and not "-f" with arg "u". | 618 | * the long option, just like "--fu", and not "-f" with arg "u". |
620 | 619 | * | |
621 | This distinction seems to be the most useful approach. */ | 620 | * This distinction seems to be the most useful approach. */ |
622 | 621 | ||
623 | if (longopts != NULL | 622 | if (longopts != NULL |
624 | && (argv[GNoptind][1] == '-' | 623 | && (argv[GNoptind][1] == '-' |
625 | || (long_only | 624 | || (long_only |
626 | && (argv[GNoptind][2] | 625 | && (argv[GNoptind][2] |
627 | || !my_index (optstring, argv[GNoptind][1]))))) | 626 | || !my_index (optstring, argv[GNoptind][1]))))) |
628 | { | 627 | { |
629 | char *nameend; | 628 | char *nameend; |
630 | const struct GNoption *p; | 629 | const struct GNoption *p; |
631 | const struct GNoption *pfound = NULL; | 630 | const struct GNoption *pfound = NULL; |
632 | int exact = 0; | 631 | int exact = 0; |
633 | int ambig = 0; | 632 | int ambig = 0; |
634 | int indfound = -1; | 633 | int indfound = -1; |
635 | int option_index; | 634 | int option_index; |
635 | |||
636 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++) | ||
637 | /* Do nothing. */ ; | ||
638 | |||
639 | /* Test all long options for either exact match | ||
640 | * or abbreviated matches. */ | ||
641 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | ||
642 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | ||
643 | { | ||
644 | if ((unsigned int) (nameend - nextchar) | ||
645 | == (unsigned int) strlen (p->name)) | ||
646 | { | ||
647 | /* Exact match found. */ | ||
648 | pfound = p; | ||
649 | indfound = option_index; | ||
650 | exact = 1; | ||
651 | break; | ||
652 | } | ||
653 | else if (pfound == NULL) | ||
654 | { | ||
655 | /* First nonexact match found. */ | ||
656 | pfound = p; | ||
657 | indfound = option_index; | ||
658 | } | ||
659 | else | ||
660 | /* Second or later nonexact match found. */ | ||
661 | ambig = 1; | ||
662 | } | ||
636 | 663 | ||
637 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++) | 664 | if (ambig && !exact) |
638 | /* Do nothing. */ ; | 665 | { |
666 | if (GNopterr) | ||
667 | fprintf (stderr, _("%s: option `%s' is ambiguous\n"), | ||
668 | argv[0], argv[GNoptind]); | ||
669 | nextchar += strlen (nextchar); | ||
670 | GNoptind++; | ||
671 | return '?'; | ||
672 | } | ||
639 | 673 | ||
640 | /* Test all long options for either exact match | 674 | if (pfound != NULL) |
641 | or abbreviated matches. */ | 675 | { |
642 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | 676 | option_index = indfound; |
643 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | 677 | GNoptind++; |
678 | if (*nameend) | ||
679 | { | ||
680 | /* Don't test has_arg with >, because some C compilers don't | ||
681 | * allow it to be used on enums. */ | ||
682 | if (pfound->has_arg) | ||
683 | GNoptarg = nameend + 1; | ||
684 | else | ||
685 | { | ||
686 | if (GNopterr) | ||
644 | { | 687 | { |
645 | if ((unsigned int) (nameend - nextchar) | 688 | if (argv[GNoptind - 1][1] == '-') |
646 | == (unsigned int) strlen (p->name)) | 689 | /* --option */ |
647 | { | 690 | fprintf (stderr, |
648 | /* Exact match found. */ | 691 | _ |
649 | pfound = p; | 692 | ("%s: option `--%s' does not allow an argument\n"), |
650 | indfound = option_index; | 693 | argv[0], pfound->name); |
651 | exact = 1; | ||
652 | break; | ||
653 | } | ||
654 | else if (pfound == NULL) | ||
655 | { | ||
656 | /* First nonexact match found. */ | ||
657 | pfound = p; | ||
658 | indfound = option_index; | ||
659 | } | ||
660 | else | 694 | else |
661 | /* Second or later nonexact match found. */ | 695 | /* +option or -option */ |
662 | ambig = 1; | 696 | fprintf (stderr, |
697 | _ | ||
698 | ("%s: option `%c%s' does not allow an argument\n"), | ||
699 | argv[0], argv[GNoptind - 1][0], pfound->name); | ||
663 | } | 700 | } |
664 | |||
665 | if (ambig && !exact) | ||
666 | { | ||
667 | if (GNopterr) | ||
668 | fprintf (stderr, _("%s: option `%s' is ambiguous\n"), | ||
669 | argv[0], argv[GNoptind]); | ||
670 | nextchar += strlen (nextchar); | 701 | nextchar += strlen (nextchar); |
671 | GNoptind++; | ||
672 | return '?'; | 702 | return '?'; |
673 | } | 703 | } |
674 | 704 | } | |
675 | if (pfound != NULL) | 705 | else if (pfound->has_arg == 1) |
706 | { | ||
707 | if (GNoptind < argc) | ||
676 | { | 708 | { |
677 | option_index = indfound; | 709 | GNoptarg = argv[GNoptind++]; |
678 | GNoptind++; | ||
679 | if (*nameend) | ||
680 | { | ||
681 | /* Don't test has_arg with >, because some C compilers don't | ||
682 | allow it to be used on enums. */ | ||
683 | if (pfound->has_arg) | ||
684 | GNoptarg = nameend + 1; | ||
685 | else | ||
686 | { | ||
687 | if (GNopterr) | ||
688 | { | ||
689 | if (argv[GNoptind - 1][1] == '-') | ||
690 | /* --option */ | ||
691 | fprintf (stderr, | ||
692 | _ | ||
693 | ("%s: option `--%s' does not allow an argument\n"), | ||
694 | argv[0], pfound->name); | ||
695 | else | ||
696 | /* +option or -option */ | ||
697 | fprintf (stderr, | ||
698 | _ | ||
699 | ("%s: option `%c%s' does not allow an argument\n"), | ||
700 | argv[0], argv[GNoptind - 1][0], | ||
701 | pfound->name); | ||
702 | } | ||
703 | nextchar += strlen (nextchar); | ||
704 | return '?'; | ||
705 | } | ||
706 | } | ||
707 | else if (pfound->has_arg == 1) | ||
708 | { | ||
709 | if (GNoptind < argc) | ||
710 | { | ||
711 | GNoptarg = argv[GNoptind++]; | ||
712 | } | ||
713 | else | ||
714 | { | ||
715 | if (GNopterr) | ||
716 | { | ||
717 | fprintf (stderr, | ||
718 | _("%s: option `%s' requires an argument\n"), | ||
719 | argv[0], argv[GNoptind - 1]); | ||
720 | } | ||
721 | nextchar += strlen (nextchar); | ||
722 | return (optstring[0] == ':') ? ':' : '?'; | ||
723 | } | ||
724 | } | ||
725 | nextchar += strlen (nextchar); | ||
726 | if (longind != NULL) | ||
727 | *longind = option_index; | ||
728 | if (pfound->flag) | ||
729 | { | ||
730 | *(pfound->flag) = pfound->val; | ||
731 | return 0; | ||
732 | } | ||
733 | return pfound->val; | ||
734 | } | 710 | } |
735 | 711 | else | |
736 | /* Can't find it as a long option. If this is not getopt_long_only, | ||
737 | or the option starts with '--' or is not a valid short | ||
738 | option, then it's an error. | ||
739 | Otherwise interpret it as a short option. */ | ||
740 | if (!long_only || argv[GNoptind][1] == '-' | ||
741 | || my_index (optstring, *nextchar) == NULL) | ||
742 | { | 712 | { |
743 | if (GNopterr) | 713 | if (GNopterr) |
744 | { | 714 | { |
745 | if (argv[GNoptind][1] == '-') | 715 | fprintf (stderr, |
746 | /* --option */ | 716 | _("%s: option `%s' requires an argument\n"), |
747 | fprintf (stderr, _("%s: unrecognized option `--%s'\n"), | 717 | argv[0], argv[GNoptind - 1]); |
748 | argv[0], nextchar); | 718 | } |
749 | else | 719 | nextchar += strlen (nextchar); |
750 | /* +option or -option */ | 720 | return (optstring[0] == ':') ? ':' : '?'; |
751 | fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), | ||
752 | argv[0], argv[GNoptind][0], nextchar); | ||
753 | } | ||
754 | nextchar = (char *) ""; | ||
755 | GNoptind++; | ||
756 | return '?'; | ||
757 | } | 721 | } |
722 | } | ||
723 | nextchar += strlen (nextchar); | ||
724 | if (longind != NULL) | ||
725 | *longind = option_index; | ||
726 | if (pfound->flag) | ||
727 | { | ||
728 | *(pfound->flag) = pfound->val; | ||
729 | return 0; | ||
730 | } | ||
731 | return pfound->val; | ||
758 | } | 732 | } |
759 | 733 | ||
734 | /* Can't find it as a long option. If this is not getopt_long_only, | ||
735 | * or the option starts with '--' or is not a valid short | ||
736 | * option, then it's an error. | ||
737 | * Otherwise interpret it as a short option. */ | ||
738 | if (!long_only || argv[GNoptind][1] == '-' | ||
739 | || my_index (optstring, *nextchar) == NULL) | ||
740 | { | ||
741 | if (GNopterr) | ||
742 | { | ||
743 | if (argv[GNoptind][1] == '-') | ||
744 | /* --option */ | ||
745 | fprintf (stderr, _("%s: unrecognized option `--%s'\n"), | ||
746 | argv[0], nextchar); | ||
747 | else | ||
748 | /* +option or -option */ | ||
749 | fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), | ||
750 | argv[0], argv[GNoptind][0], nextchar); | ||
751 | } | ||
752 | nextchar = (char *) ""; | ||
753 | GNoptind++; | ||
754 | return '?'; | ||
755 | } | ||
756 | } | ||
757 | |||
760 | /* Look at and handle the next short option-character. */ | 758 | /* Look at and handle the next short option-character. */ |
761 | 759 | ||
762 | { | 760 | { |
@@ -768,186 +766,185 @@ GN_getopt_internal (int argc, | |||
768 | ++GNoptind; | 766 | ++GNoptind; |
769 | 767 | ||
770 | if (temp == NULL || c == ':') | 768 | if (temp == NULL || c == ':') |
769 | { | ||
770 | if (GNopterr) | ||
771 | { | 771 | { |
772 | if (GNopterr) | 772 | if (posixly_correct) |
773 | { | 773 | /* 1003.2 specifies the format of this message. */ |
774 | if (posixly_correct) | 774 | fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); |
775 | /* 1003.2 specifies the format of this message. */ | 775 | else |
776 | fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); | 776 | fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); |
777 | else | ||
778 | fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); | ||
779 | } | ||
780 | return '?'; | ||
781 | } | 777 | } |
778 | return '?'; | ||
779 | } | ||
782 | /* Convenience. Treat POSIX -W foo same as long option --foo */ | 780 | /* Convenience. Treat POSIX -W foo same as long option --foo */ |
783 | if (temp[0] == 'W' && temp[1] == ';') | 781 | if (temp[0] == 'W' && temp[1] == ';') |
784 | { | 782 | { |
785 | char *nameend; | 783 | char *nameend; |
786 | const struct GNoption *p; | 784 | const struct GNoption *p; |
787 | const struct GNoption *pfound = NULL; | 785 | const struct GNoption *pfound = NULL; |
788 | int exact = 0; | 786 | int exact = 0; |
789 | int ambig = 0; | 787 | int ambig = 0; |
790 | int indfound = 0; | 788 | int indfound = 0; |
791 | int option_index; | 789 | int option_index; |
792 | 790 | ||
793 | /* This is an option that requires an argument. */ | 791 | /* This is an option that requires an argument. */ |
794 | if (*nextchar != '\0') | 792 | if (*nextchar != '\0') |
795 | { | 793 | { |
796 | GNoptarg = nextchar; | 794 | GNoptarg = nextchar; |
797 | /* If we end this ARGV-element by taking the rest as an arg, | 795 | /* If we end this ARGV-element by taking the rest as an arg, |
798 | we must advance to the next element now. */ | 796 | * we must advance to the next element now. */ |
799 | GNoptind++; | 797 | GNoptind++; |
800 | } | 798 | } |
801 | else if (GNoptind == argc) | 799 | else if (GNoptind == argc) |
802 | { | 800 | { |
803 | if (GNopterr) | 801 | if (GNopterr) |
804 | { | 802 | { |
805 | /* 1003.2 specifies the format of this message. */ | 803 | /* 1003.2 specifies the format of this message. */ |
806 | fprintf (stderr, _("%s: option requires an argument -- %c\n"), | 804 | fprintf (stderr, _("%s: option requires an argument -- %c\n"), |
807 | argv[0], c); | 805 | argv[0], c); |
808 | } | 806 | } |
809 | if (optstring[0] == ':') | 807 | if (optstring[0] == ':') |
810 | c = ':'; | 808 | c = ':'; |
811 | else | ||
812 | c = '?'; | ||
813 | return c; | ||
814 | } | ||
815 | else | 809 | else |
816 | /* We already incremented `GNoptind' once; | 810 | c = '?'; |
817 | increment it again when taking next ARGV-elt as argument. */ | 811 | return c; |
818 | GNoptarg = argv[GNoptind++]; | 812 | } |
813 | else | ||
814 | /* We already incremented `GNoptind' once; | ||
815 | * increment it again when taking next ARGV-elt as argument. */ | ||
816 | GNoptarg = argv[GNoptind++]; | ||
819 | 817 | ||
820 | /* GNoptarg is now the argument, see if it's in the | 818 | /* GNoptarg is now the argument, see if it's in the |
821 | table of longopts. */ | 819 | * table of longopts. */ |
822 | 820 | ||
823 | for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; | 821 | for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; |
824 | nameend++) | 822 | nameend++) |
825 | /* Do nothing. */ ; | 823 | /* Do nothing. */ ; |
826 | 824 | ||
827 | /* Test all long options for either exact match | 825 | /* Test all long options for either exact match |
828 | or abbreviated matches. */ | 826 | * or abbreviated matches. */ |
829 | if (longopts != NULL) | 827 | if (longopts != NULL) |
830 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | 828 | for (p = longopts, option_index = 0; p->name; p++, option_index++) |
831 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | 829 | if (!strncmp (p->name, nextchar, nameend - nextchar)) |
830 | { | ||
831 | if ((unsigned int) (nameend - nextchar) == strlen (p->name)) | ||
832 | { | ||
833 | /* Exact match found. */ | ||
834 | pfound = p; | ||
835 | indfound = option_index; | ||
836 | exact = 1; | ||
837 | break; | ||
838 | } | ||
839 | else if (pfound == NULL) | ||
832 | { | 840 | { |
833 | if ((unsigned int) (nameend - nextchar) == strlen (p->name)) | 841 | /* First nonexact match found. */ |
834 | { | 842 | pfound = p; |
835 | /* Exact match found. */ | 843 | indfound = option_index; |
836 | pfound = p; | ||
837 | indfound = option_index; | ||
838 | exact = 1; | ||
839 | break; | ||
840 | } | ||
841 | else if (pfound == NULL) | ||
842 | { | ||
843 | /* First nonexact match found. */ | ||
844 | pfound = p; | ||
845 | indfound = option_index; | ||
846 | } | ||
847 | else | ||
848 | /* Second or later nonexact match found. */ | ||
849 | ambig = 1; | ||
850 | } | 844 | } |
851 | if (ambig && !exact) | 845 | else |
846 | /* Second or later nonexact match found. */ | ||
847 | ambig = 1; | ||
848 | } | ||
849 | if (ambig && !exact) | ||
850 | { | ||
851 | if (GNopterr) | ||
852 | fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), | ||
853 | argv[0], argv[GNoptind]); | ||
854 | nextchar += strlen (nextchar); | ||
855 | GNoptind++; | ||
856 | return '?'; | ||
857 | } | ||
858 | if (pfound != NULL) | ||
859 | { | ||
860 | option_index = indfound; | ||
861 | if (*nameend) | ||
862 | { | ||
863 | /* Don't test has_arg with >, because some C compilers don't | ||
864 | * allow it to be used on enums. */ | ||
865 | if (pfound->has_arg) | ||
866 | GNoptarg = nameend + 1; | ||
867 | else | ||
852 | { | 868 | { |
853 | if (GNopterr) | 869 | if (GNopterr) |
854 | fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), | 870 | fprintf (stderr, _("\ |
855 | argv[0], argv[GNoptind]); | 871 | %s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name); |
872 | |||
856 | nextchar += strlen (nextchar); | 873 | nextchar += strlen (nextchar); |
857 | GNoptind++; | ||
858 | return '?'; | 874 | return '?'; |
859 | } | 875 | } |
860 | if (pfound != NULL) | 876 | } |
877 | else if (pfound->has_arg == 1) | ||
878 | { | ||
879 | if (GNoptind < argc) | ||
880 | GNoptarg = argv[GNoptind++]; | ||
881 | else | ||
861 | { | 882 | { |
862 | option_index = indfound; | 883 | if (GNopterr) |
863 | if (*nameend) | 884 | fprintf (stderr, |
864 | { | 885 | _("%s: option `%s' requires an argument\n"), |
865 | /* Don't test has_arg with >, because some C compilers don't | 886 | argv[0], argv[GNoptind - 1]); |
866 | allow it to be used on enums. */ | ||
867 | if (pfound->has_arg) | ||
868 | GNoptarg = nameend + 1; | ||
869 | else | ||
870 | { | ||
871 | if (GNopterr) | ||
872 | fprintf (stderr, _("\ | ||
873 | %s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name); | ||
874 | |||
875 | nextchar += strlen (nextchar); | ||
876 | return '?'; | ||
877 | } | ||
878 | } | ||
879 | else if (pfound->has_arg == 1) | ||
880 | { | ||
881 | if (GNoptind < argc) | ||
882 | GNoptarg = argv[GNoptind++]; | ||
883 | else | ||
884 | { | ||
885 | if (GNopterr) | ||
886 | fprintf (stderr, | ||
887 | _("%s: option `%s' requires an argument\n"), | ||
888 | argv[0], argv[GNoptind - 1]); | ||
889 | nextchar += strlen (nextchar); | ||
890 | return optstring[0] == ':' ? ':' : '?'; | ||
891 | } | ||
892 | } | ||
893 | nextchar += strlen (nextchar); | 887 | nextchar += strlen (nextchar); |
894 | if (longind != NULL) | 888 | return optstring[0] == ':' ? ':' : '?'; |
895 | *longind = option_index; | ||
896 | if (pfound->flag) | ||
897 | { | ||
898 | *(pfound->flag) = pfound->val; | ||
899 | return 0; | ||
900 | } | ||
901 | return pfound->val; | ||
902 | } | 889 | } |
903 | nextchar = NULL; | 890 | } |
904 | return 'W'; /* Let the application handle it. */ | 891 | nextchar += strlen (nextchar); |
892 | if (longind != NULL) | ||
893 | *longind = option_index; | ||
894 | if (pfound->flag) | ||
895 | { | ||
896 | *(pfound->flag) = pfound->val; | ||
897 | return 0; | ||
898 | } | ||
899 | return pfound->val; | ||
905 | } | 900 | } |
901 | nextchar = NULL; | ||
902 | return 'W'; /* Let the application handle it. */ | ||
903 | } | ||
906 | if (temp[1] == ':') | 904 | if (temp[1] == ':') |
905 | { | ||
906 | if (temp[2] == ':') | ||
907 | { | 907 | { |
908 | if (temp[2] == ':') | 908 | /* This is an option that accepts an argument optionally. */ |
909 | { | 909 | if (*nextchar != '\0') |
910 | /* This is an option that accepts an argument optionally. */ | 910 | { |
911 | if (*nextchar != '\0') | 911 | GNoptarg = nextchar; |
912 | { | 912 | GNoptind++; |
913 | GNoptarg = nextchar; | 913 | } |
914 | GNoptind++; | ||
915 | } | ||
916 | else | ||
917 | GNoptarg = NULL; | ||
918 | nextchar = NULL; | ||
919 | } | ||
920 | else | 914 | else |
915 | GNoptarg = NULL; | ||
916 | nextchar = NULL; | ||
917 | } | ||
918 | else | ||
919 | { | ||
920 | /* This is an option that requires an argument. */ | ||
921 | if (*nextchar != '\0') | ||
922 | { | ||
923 | GNoptarg = nextchar; | ||
924 | /* If we end this ARGV-element by taking the rest as an arg, | ||
925 | * we must advance to the next element now. */ | ||
926 | GNoptind++; | ||
927 | } | ||
928 | else if (GNoptind == argc) | ||
929 | { | ||
930 | if (GNopterr) | ||
921 | { | 931 | { |
922 | /* This is an option that requires an argument. */ | 932 | /* 1003.2 specifies the format of this message. */ |
923 | if (*nextchar != '\0') | 933 | fprintf (stderr, |
924 | { | 934 | _("%s: option requires an argument -- %c\n"), argv[0], c); |
925 | GNoptarg = nextchar; | ||
926 | /* If we end this ARGV-element by taking the rest as an arg, | ||
927 | we must advance to the next element now. */ | ||
928 | GNoptind++; | ||
929 | } | ||
930 | else if (GNoptind == argc) | ||
931 | { | ||
932 | if (GNopterr) | ||
933 | { | ||
934 | /* 1003.2 specifies the format of this message. */ | ||
935 | fprintf (stderr, | ||
936 | _("%s: option requires an argument -- %c\n"), | ||
937 | argv[0], c); | ||
938 | } | ||
939 | if (optstring[0] == ':') | ||
940 | c = ':'; | ||
941 | else | ||
942 | c = '?'; | ||
943 | } | ||
944 | else | ||
945 | /* We already incremented `GNoptind' once; | ||
946 | increment it again when taking next ARGV-elt as argument. */ | ||
947 | GNoptarg = argv[GNoptind++]; | ||
948 | nextchar = NULL; | ||
949 | } | 935 | } |
936 | if (optstring[0] == ':') | ||
937 | c = ':'; | ||
938 | else | ||
939 | c = '?'; | ||
940 | } | ||
941 | else | ||
942 | /* We already incremented `GNoptind' once; | ||
943 | * increment it again when taking next ARGV-elt as argument. */ | ||
944 | GNoptarg = argv[GNoptind++]; | ||
945 | nextchar = NULL; | ||
950 | } | 946 | } |
947 | } | ||
951 | return c; | 948 | return c; |
952 | } | 949 | } |
953 | } | 950 | } |
@@ -1001,15 +998,15 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
1001 | shorts = GNUNET_malloc (count * 2 + 1); | 998 | shorts = GNUNET_malloc (count * 2 + 1); |
1002 | spos = 0; | 999 | spos = 0; |
1003 | for (i = 0; i < count; i++) | 1000 | for (i = 0; i < count; i++) |
1004 | { | 1001 | { |
1005 | long_options[i].name = allOptions[i].name; | 1002 | long_options[i].name = allOptions[i].name; |
1006 | long_options[i].has_arg = allOptions[i].require_argument; | 1003 | long_options[i].has_arg = allOptions[i].require_argument; |
1007 | long_options[i].flag = NULL; | 1004 | long_options[i].flag = NULL; |
1008 | long_options[i].val = allOptions[i].shortName; | 1005 | long_options[i].val = allOptions[i].shortName; |
1009 | shorts[spos++] = allOptions[i].shortName; | 1006 | shorts[spos++] = allOptions[i].shortName; |
1010 | if (allOptions[i].require_argument != 0) | 1007 | if (allOptions[i].require_argument != 0) |
1011 | shorts[spos++] = ':'; | 1008 | shorts[spos++] = ':'; |
1012 | } | 1009 | } |
1013 | long_options[count].name = NULL; | 1010 | long_options[count].name = NULL; |
1014 | long_options[count].has_arg = 0; | 1011 | long_options[count].has_arg = 0; |
1015 | long_options[count].flag = NULL; | 1012 | long_options[count].flag = NULL; |
@@ -1018,30 +1015,31 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
1018 | cont = GNUNET_OK; | 1015 | cont = GNUNET_OK; |
1019 | /* main getopt loop */ | 1016 | /* main getopt loop */ |
1020 | while (cont == GNUNET_OK) | 1017 | while (cont == GNUNET_OK) |
1021 | { | 1018 | { |
1022 | int option_index = 0; | 1019 | int option_index = 0; |
1023 | c = GNgetopt_long (argc, argv, shorts, long_options, &option_index); | ||
1024 | 1020 | ||
1025 | if (c == GNUNET_SYSERR) | 1021 | c = GNgetopt_long (argc, argv, shorts, long_options, &option_index); |
1026 | break; /* No more flags to process */ | ||
1027 | 1022 | ||
1028 | for (i = 0; i < count; i++) | 1023 | if (c == GNUNET_SYSERR) |
1029 | { | 1024 | break; /* No more flags to process */ |
1030 | clpc.currentArgument = GNoptind - 1; | 1025 | |
1031 | if ((char) c == allOptions[i].shortName) | 1026 | for (i = 0; i < count; i++) |
1032 | { | 1027 | { |
1033 | cont = allOptions[i].processor (&clpc, | 1028 | clpc.currentArgument = GNoptind - 1; |
1034 | allOptions[i].scls, | 1029 | if ((char) c == allOptions[i].shortName) |
1035 | allOptions[i].name, GNoptarg); | 1030 | { |
1036 | break; | 1031 | cont = allOptions[i].processor (&clpc, |
1037 | } | 1032 | allOptions[i].scls, |
1038 | } | 1033 | allOptions[i].name, GNoptarg); |
1039 | if (i == count) | 1034 | break; |
1040 | { | 1035 | } |
1041 | fprintf (stderr, _("Use --help to get a list of options.\n")); | 1036 | } |
1042 | cont = GNUNET_SYSERR; | 1037 | if (i == count) |
1043 | } | 1038 | { |
1039 | fprintf (stderr, _("Use --help to get a list of options.\n")); | ||
1040 | cont = GNUNET_SYSERR; | ||
1044 | } | 1041 | } |
1042 | } | ||
1045 | 1043 | ||
1046 | GNUNET_free (shorts); | 1044 | GNUNET_free (shorts); |
1047 | GNUNET_free (long_options); | 1045 | GNUNET_free (long_options); |
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index c0646c302..aa85bf536 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -83,67 +83,67 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
83 | i = 0; | 83 | i = 0; |
84 | opt = ctx->allOptions; | 84 | opt = ctx->allOptions; |
85 | while (opt[i].description != NULL) | 85 | while (opt[i].description != NULL) |
86 | { | ||
87 | if (opt[i].shortName == '\0') | ||
88 | printf (" "); | ||
89 | else | ||
90 | printf (" -%c, ", opt[i].shortName); | ||
91 | printf ("--%s", opt[i].name); | ||
92 | slen = 8 + strlen (opt[i].name); | ||
93 | if (opt[i].argumentHelp != NULL) | ||
86 | { | 94 | { |
87 | if (opt[i].shortName == '\0') | 95 | printf ("=%s", opt[i].argumentHelp); |
88 | printf (" "); | 96 | slen += 1 + strlen (opt[i].argumentHelp); |
89 | else | 97 | } |
90 | printf (" -%c, ", opt[i].shortName); | 98 | if (slen > BORDER) |
91 | printf ("--%s", opt[i].name); | 99 | { |
92 | slen = 8 + strlen (opt[i].name); | 100 | printf ("\n%*s", BORDER, ""); |
93 | if (opt[i].argumentHelp != NULL) | 101 | slen = BORDER; |
94 | { | 102 | } |
95 | printf ("=%s", opt[i].argumentHelp); | 103 | if (slen < BORDER) |
96 | slen += 1 + strlen (opt[i].argumentHelp); | 104 | { |
97 | } | 105 | printf ("%*s", (int) (BORDER - slen), ""); |
98 | if (slen > BORDER) | 106 | slen = BORDER; |
99 | { | 107 | } |
100 | printf ("\n%*s", BORDER, ""); | 108 | if (0 < strlen (opt[i].description)) |
101 | slen = BORDER; | 109 | trans = gettext (opt[i].description); |
102 | } | 110 | else |
103 | if (slen < BORDER) | 111 | trans = ""; |
104 | { | 112 | ml = strlen (trans); |
105 | printf ("%*s", (int) (BORDER - slen), ""); | 113 | p = 0; |
106 | slen = BORDER; | 114 | OUTER: |
107 | } | 115 | while (ml - p > 78 - slen) |
108 | if (0 < strlen (opt[i].description)) | 116 | { |
109 | trans = gettext (opt[i].description); | 117 | for (j = p + 78 - slen; j > p; j--) |
110 | else | 118 | { |
111 | trans = ""; | 119 | if (isspace ((unsigned char) trans[j])) |
112 | ml = strlen (trans); | ||
113 | p = 0; | ||
114 | OUTER: | ||
115 | while (ml - p > 78 - slen) | ||
116 | { | 120 | { |
117 | for (j = p + 78 - slen; j > p; j--) | 121 | scp = GNUNET_malloc (j - p + 1); |
118 | { | 122 | memcpy (scp, &trans[p], j - p); |
119 | if (isspace ( (unsigned char) trans[j])) | 123 | scp[j - p] = '\0'; |
120 | { | ||
121 | scp = GNUNET_malloc (j - p + 1); | ||
122 | memcpy (scp, &trans[p], j - p); | ||
123 | scp[j - p] = '\0'; | ||
124 | printf ("%s\n%*s", scp, BORDER + 2, ""); | ||
125 | GNUNET_free (scp); | ||
126 | p = j + 1; | ||
127 | slen = BORDER + 2; | ||
128 | goto OUTER; | ||
129 | } | ||
130 | } | ||
131 | /* could not find space to break line */ | ||
132 | scp = GNUNET_malloc (78 - slen + 1); | ||
133 | memcpy (scp, &trans[p], 78 - slen); | ||
134 | scp[78 - slen] = '\0'; | ||
135 | printf ("%s\n%*s", scp, BORDER + 2, ""); | 124 | printf ("%s\n%*s", scp, BORDER + 2, ""); |
136 | GNUNET_free (scp); | 125 | GNUNET_free (scp); |
126 | p = j + 1; | ||
137 | slen = BORDER + 2; | 127 | slen = BORDER + 2; |
138 | p = p + 78 - slen; | 128 | goto OUTER; |
139 | } | 129 | } |
140 | /* print rest */ | 130 | } |
141 | if (p < ml) | 131 | /* could not find space to break line */ |
142 | printf ("%s\n", &trans[p]); | 132 | scp = GNUNET_malloc (78 - slen + 1); |
143 | if (strlen (trans) == 0) | 133 | memcpy (scp, &trans[p], 78 - slen); |
144 | printf ("\n"); | 134 | scp[78 - slen] = '\0'; |
145 | i++; | 135 | printf ("%s\n%*s", scp, BORDER + 2, ""); |
136 | GNUNET_free (scp); | ||
137 | slen = BORDER + 2; | ||
138 | p = p + 78 - slen; | ||
146 | } | 139 | } |
140 | /* print rest */ | ||
141 | if (p < ml) | ||
142 | printf ("%s\n", &trans[p]); | ||
143 | if (strlen (trans) == 0) | ||
144 | printf ("\n"); | ||
145 | i++; | ||
146 | } | ||
147 | printf ("Report bugs to gnunet-developers@gnu.org.\n" | 147 | printf ("Report bugs to gnunet-developers@gnu.org.\n" |
148 | "GNUnet home page: http://www.gnu.org/software/gnunet/\n" | 148 | "GNUnet home page: http://www.gnu.org/software/gnunet/\n" |
149 | "General help using GNU software: http://www.gnu.org/gethelp/\n"); | 149 | "General help using GNU software: http://www.gnu.org/gethelp/\n"); |
@@ -172,6 +172,7 @@ GNUNET_GETOPT_increment_value (struct | |||
172 | const char *value) | 172 | const char *value) |
173 | { | 173 | { |
174 | int *val = scls; | 174 | int *val = scls; |
175 | |||
175 | (*val)++; | 176 | (*val)++; |
176 | return GNUNET_OK; | 177 | return GNUNET_OK; |
177 | } | 178 | } |
@@ -196,6 +197,7 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
196 | void *scls, const char *option, const char *value) | 197 | void *scls, const char *option, const char *value) |
197 | { | 198 | { |
198 | int *val = scls; | 199 | int *val = scls; |
200 | |||
199 | *val = 1; | 201 | *val = 1; |
200 | return GNUNET_OK; | 202 | return GNUNET_OK; |
201 | } | 203 | } |
@@ -249,12 +251,12 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext | |||
249 | const char *value) | 251 | const char *value) |
250 | { | 252 | { |
251 | unsigned long long *val = scls; | 253 | unsigned long long *val = scls; |
254 | |||
252 | if (1 != SSCANF (value, "%llu", val)) | 255 | if (1 != SSCANF (value, "%llu", val)) |
253 | { | 256 | { |
254 | fprintf (stderr, | 257 | fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option); |
255 | _("You must pass a number to the `%s' option.\n"), option); | 258 | return GNUNET_SYSERR; |
256 | return GNUNET_SYSERR; | 259 | } |
257 | } | ||
258 | return GNUNET_OK; | 260 | return GNUNET_OK; |
259 | } | 261 | } |
260 | 262 | ||
@@ -279,11 +281,10 @@ GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
279 | unsigned int *val = scls; | 281 | unsigned int *val = scls; |
280 | 282 | ||
281 | if (1 != SSCANF (value, "%u", val)) | 283 | if (1 != SSCANF (value, "%u", val)) |
282 | { | 284 | { |
283 | fprintf (stderr, | 285 | fprintf (stderr, _("You must pass a number to the `%s' option.\n"), option); |
284 | _("You must pass a number to the `%s' option.\n"), option); | 286 | return GNUNET_SYSERR; |
285 | return GNUNET_SYSERR; | 287 | } |
286 | } | ||
287 | return GNUNET_OK; | 288 | return GNUNET_OK; |
288 | } | 289 | } |
289 | 290 | ||
diff --git a/src/util/gnunet-config-diff.c b/src/util/gnunet-config-diff.c index 3c0af8f24..02ffa77a1 100644 --- a/src/util/gnunet-config-diff.c +++ b/src/util/gnunet-config-diff.c | |||
@@ -1,28 +1,24 @@ | |||
1 | #include "platform.h" | 1 | #include "platform.h" |
2 | #include <gnunet_util_lib.h> | 2 | #include <gnunet_util_lib.h> |
3 | 3 | ||
4 | int main(int argc, | 4 | int |
5 | char **argv) | 5 | main (int argc, char **argv) |
6 | { | 6 | { |
7 | struct GNUNET_CONFIGURATION_Handle *i1; | 7 | struct GNUNET_CONFIGURATION_Handle *i1; |
8 | struct GNUNET_CONFIGURATION_Handle *i2; | 8 | struct GNUNET_CONFIGURATION_Handle *i2; |
9 | 9 | ||
10 | if (argc != 3) | 10 | if (argc != 3) |
11 | { | 11 | { |
12 | fprintf (stderr, | 12 | fprintf (stderr, "Invoke using `%s DEFAULTS-IN DIFFS'\n", argv[0]); |
13 | "Invoke using `%s DEFAULTS-IN DIFFS'\n", | 13 | return 1; |
14 | argv[0]); | 14 | } |
15 | return 1; | ||
16 | } | ||
17 | i1 = GNUNET_CONFIGURATION_create (); | 15 | i1 = GNUNET_CONFIGURATION_create (); |
18 | i2 = GNUNET_CONFIGURATION_create (); | 16 | i2 = GNUNET_CONFIGURATION_create (); |
19 | if ( (GNUNET_OK != | 17 | if ((GNUNET_OK != |
20 | GNUNET_CONFIGURATION_load (i1, argv[1])) || | 18 | GNUNET_CONFIGURATION_load (i1, argv[1])) || |
21 | (GNUNET_OK != | 19 | (GNUNET_OK != GNUNET_CONFIGURATION_load (i2, argv[2]))) |
22 | GNUNET_CONFIGURATION_load (i2, argv[2])) ) | ||
23 | return 1; | 20 | return 1; |
24 | if (GNUNET_OK != | 21 | if (GNUNET_OK != GNUNET_CONFIGURATION_write_diffs (i1, i2, argv[2])) |
25 | GNUNET_CONFIGURATION_write_diffs (i1, i2, argv[2])) | ||
26 | return 2; | 22 | return 2; |
27 | return 0; | 23 | return 0; |
28 | } | 24 | } |
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c index 85aedcacf..125d6665f 100644 --- a/src/util/gnunet-resolver.c +++ b/src/util/gnunet-resolver.c | |||
@@ -33,15 +33,11 @@ | |||
33 | * Callback function to display address. | 33 | * Callback function to display address. |
34 | */ | 34 | */ |
35 | static void | 35 | static void |
36 | printer (void *cls, | 36 | printer (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
37 | const struct sockaddr * addr, | ||
38 | socklen_t addrlen) | ||
39 | { | 37 | { |
40 | if (addr == NULL) | 38 | if (addr == NULL) |
41 | return; | 39 | return; |
42 | FPRINTF (stdout, | 40 | FPRINTF (stdout, "%s\n", GNUNET_a2s (addr, addrlen)); |
43 | "%s\n", | ||
44 | GNUNET_a2s (addr, addrlen)); | ||
45 | } | 41 | } |
46 | 42 | ||
47 | 43 | ||
@@ -56,16 +52,11 @@ printer (void *cls, | |||
56 | static void | 52 | static void |
57 | run (void *cls, | 53 | run (void *cls, |
58 | char *const *args, | 54 | char *const *args, |
59 | const char *cfgfile, | 55 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
60 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
61 | { | 56 | { |
62 | if (args[0] == NULL) | 57 | if (args[0] == NULL) |
63 | return; | 58 | return; |
64 | GNUNET_RESOLVER_ip_get (args[0], | 59 | GNUNET_RESOLVER_ip_get (args[0], AF_UNSPEC, GET_TIMEOUT, &printer, NULL); |
65 | AF_UNSPEC, | ||
66 | GET_TIMEOUT, | ||
67 | &printer, | ||
68 | NULL); | ||
69 | } | 60 | } |
70 | 61 | ||
71 | /** | 62 | /** |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 39f31745f..f49ec3882 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -88,8 +88,7 @@ getnameinfo_resolve (struct IPCache *cache) | |||
88 | char hostname[256]; | 88 | char hostname[256]; |
89 | 89 | ||
90 | if (0 == getnameinfo (cache->sa, | 90 | if (0 == getnameinfo (cache->sa, |
91 | cache->salen, | 91 | cache->salen, hostname, sizeof (hostname), NULL, 0, 0)) |
92 | hostname, sizeof (hostname), NULL, 0, 0)) | ||
93 | cache->addr = GNUNET_strdup (hostname); | 92 | cache->addr = GNUNET_strdup (hostname); |
94 | } | 93 | } |
95 | #endif | 94 | #endif |
@@ -107,18 +106,18 @@ gethostbyaddr_resolve (struct IPCache *cache) | |||
107 | struct hostent *ent; | 106 | struct hostent *ent; |
108 | 107 | ||
109 | switch (cache->sa->sa_family) | 108 | switch (cache->sa->sa_family) |
110 | { | 109 | { |
111 | case AF_INET: | 110 | case AF_INET: |
112 | ent = gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, | 111 | ent = gethostbyaddr (&((struct sockaddr_in *) cache->sa)->sin_addr, |
113 | sizeof (struct in_addr), AF_INET); | 112 | sizeof (struct in_addr), AF_INET); |
114 | break; | 113 | break; |
115 | case AF_INET6: | 114 | case AF_INET6: |
116 | ent = gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, | 115 | ent = gethostbyaddr (&((struct sockaddr_in6 *) cache->sa)->sin6_addr, |
117 | sizeof (struct in6_addr), AF_INET6); | 116 | sizeof (struct in6_addr), AF_INET6); |
118 | break; | 117 | break; |
119 | default: | 118 | default: |
120 | ent = NULL; | 119 | ent = NULL; |
121 | } | 120 | } |
122 | if (ent != NULL) | 121 | if (ent != NULL) |
123 | cache->addr = GNUNET_strdup (ent->h_name); | 122 | cache->addr = GNUNET_strdup (ent->h_name); |
124 | } | 123 | } |
@@ -164,74 +163,74 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
164 | struct GNUNET_SERVER_TransmitContext *tc; | 163 | struct GNUNET_SERVER_TransmitContext *tc; |
165 | 164 | ||
166 | if (salen < sizeof (struct sockaddr)) | 165 | if (salen < sizeof (struct sockaddr)) |
167 | { | 166 | { |
168 | GNUNET_break (0); | 167 | GNUNET_break (0); |
169 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 168 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
170 | return; | 169 | return; |
171 | } | 170 | } |
172 | now = GNUNET_TIME_absolute_get (); | 171 | now = GNUNET_TIME_absolute_get (); |
173 | cache = head; | 172 | cache = head; |
174 | prev = NULL; | 173 | prev = NULL; |
175 | while ((cache != NULL) && | 174 | while ((cache != NULL) && |
176 | ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) | 175 | ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) |
176 | { | ||
177 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | ||
178 | 60 * 60 * 1000) | ||
177 | { | 179 | { |
178 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | 180 | if (prev != NULL) |
179 | 60 * 60 * 1000) | 181 | { |
180 | { | 182 | prev->next = cache->next; |
181 | if (prev != NULL) | 183 | GNUNET_free_non_null (cache->addr); |
182 | { | 184 | GNUNET_free (cache->sa); |
183 | prev->next = cache->next; | 185 | GNUNET_free (cache); |
184 | GNUNET_free_non_null (cache->addr); | 186 | cache = prev->next; |
185 | GNUNET_free (cache->sa); | 187 | } |
186 | GNUNET_free (cache); | 188 | else |
187 | cache = prev->next; | 189 | { |
188 | } | 190 | head = cache->next; |
189 | else | 191 | GNUNET_free_non_null (cache->addr); |
190 | { | 192 | GNUNET_free (cache->sa); |
191 | head = cache->next; | 193 | GNUNET_free (cache); |
192 | GNUNET_free_non_null (cache->addr); | 194 | cache = head; |
193 | GNUNET_free (cache->sa); | 195 | } |
194 | GNUNET_free (cache); | 196 | continue; |
195 | cache = head; | ||
196 | } | ||
197 | continue; | ||
198 | } | ||
199 | prev = cache; | ||
200 | cache = cache->next; | ||
201 | } | 197 | } |
198 | prev = cache; | ||
199 | cache = cache->next; | ||
200 | } | ||
202 | if (cache != NULL) | 201 | if (cache != NULL) |
202 | { | ||
203 | cache->last_request = now; | ||
204 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | ||
205 | 60 * 60 * 1000) | ||
203 | { | 206 | { |
204 | cache->last_request = now; | 207 | GNUNET_free_non_null (cache->addr); |
205 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).rel_value < | ||
206 | 60 * 60 * 1000) | ||
207 | { | ||
208 | GNUNET_free_non_null (cache->addr); | ||
209 | cache->addr = NULL; | ||
210 | cache->salen = 0; | ||
211 | cache_resolve (cache); | ||
212 | } | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | cache = GNUNET_malloc (sizeof (struct IPCache)); | ||
217 | cache->next = head; | ||
218 | cache->salen = salen; | ||
219 | cache->sa = GNUNET_malloc (salen); | ||
220 | memcpy (cache->sa, sa, salen); | ||
221 | cache->last_request = GNUNET_TIME_absolute_get (); | ||
222 | cache->last_refresh = GNUNET_TIME_absolute_get (); | ||
223 | cache->addr = NULL; | 208 | cache->addr = NULL; |
209 | cache->salen = 0; | ||
224 | cache_resolve (cache); | 210 | cache_resolve (cache); |
225 | head = cache; | ||
226 | } | 211 | } |
212 | } | ||
213 | else | ||
214 | { | ||
215 | cache = GNUNET_malloc (sizeof (struct IPCache)); | ||
216 | cache->next = head; | ||
217 | cache->salen = salen; | ||
218 | cache->sa = GNUNET_malloc (salen); | ||
219 | memcpy (cache->sa, sa, salen); | ||
220 | cache->last_request = GNUNET_TIME_absolute_get (); | ||
221 | cache->last_refresh = GNUNET_TIME_absolute_get (); | ||
222 | cache->addr = NULL; | ||
223 | cache_resolve (cache); | ||
224 | head = cache; | ||
225 | } | ||
227 | tc = GNUNET_SERVER_transmit_context_create (client); | 226 | tc = GNUNET_SERVER_transmit_context_create (client); |
228 | if (cache->addr != NULL) | 227 | if (cache->addr != NULL) |
229 | GNUNET_SERVER_transmit_context_append_data (tc, | 228 | GNUNET_SERVER_transmit_context_append_data (tc, |
230 | cache->addr, | 229 | cache->addr, |
231 | strlen (cache->addr) + 1, | 230 | strlen (cache->addr) + 1, |
232 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 231 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
233 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 232 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
234 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 233 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
235 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 234 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
236 | } | 235 | } |
237 | 236 | ||
@@ -256,35 +255,35 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
256 | hints.ai_socktype = SOCK_STREAM; /* go for TCP */ | 255 | hints.ai_socktype = SOCK_STREAM; /* go for TCP */ |
257 | 256 | ||
258 | if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) | 257 | if (0 != (s = getaddrinfo (hostname, NULL, &hints, &result))) |
259 | { | 258 | { |
260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
261 | _("Could not resolve `%s' (%s): %s\n"), hostname, | 260 | _("Could not resolve `%s' (%s): %s\n"), hostname, |
262 | (domain == | 261 | (domain == |
263 | AF_INET) ? "IPv4" : ((domain == | 262 | AF_INET) ? "IPv4" : ((domain == |
264 | AF_INET6) ? "IPv6" : "any"), | 263 | AF_INET6) ? "IPv6" : "any"), |
265 | gai_strerror (s)); | 264 | gai_strerror (s)); |
266 | if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) | 265 | if ((s == EAI_BADFLAGS) || (s == EAI_MEMORY) |
267 | #ifndef MINGW | 266 | #ifndef MINGW |
268 | || (s == EAI_SYSTEM) | 267 | || (s == EAI_SYSTEM) |
269 | #else | 268 | #else |
270 | // FIXME NILS | 269 | // FIXME NILS |
271 | || 1 | 270 | || 1 |
272 | #endif | 271 | #endif |
273 | ) | 272 | ) |
274 | return GNUNET_NO; /* other function may still succeed */ | 273 | return GNUNET_NO; /* other function may still succeed */ |
275 | return GNUNET_SYSERR; | 274 | return GNUNET_SYSERR; |
276 | } | 275 | } |
277 | if (result == NULL) | 276 | if (result == NULL) |
278 | return GNUNET_SYSERR; | 277 | return GNUNET_SYSERR; |
279 | pos = result; | 278 | pos = result; |
280 | while (pos != NULL) | 279 | while (pos != NULL) |
281 | { | 280 | { |
282 | GNUNET_SERVER_transmit_context_append_data (tc, | 281 | GNUNET_SERVER_transmit_context_append_data (tc, |
283 | pos->ai_addr, | 282 | pos->ai_addr, |
284 | pos->ai_addrlen, | 283 | pos->ai_addrlen, |
285 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 284 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
286 | pos = pos->ai_next; | 285 | pos = pos->ai_next; |
287 | } | 286 | } |
288 | freeaddrinfo (result); | 287 | freeaddrinfo (result); |
289 | return GNUNET_OK; | 288 | return GNUNET_OK; |
290 | } | 289 | } |
@@ -302,52 +301,52 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
302 | int ret2; | 301 | int ret2; |
303 | 302 | ||
304 | if (domain == AF_UNSPEC) | 303 | if (domain == AF_UNSPEC) |
305 | { | 304 | { |
306 | ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); | 305 | ret1 = gethostbyname2_resolve (tc, hostname, AF_INET); |
307 | ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); | 306 | ret2 = gethostbyname2_resolve (tc, hostname, AF_INET6); |
308 | if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) | 307 | if ((ret1 == GNUNET_OK) || (ret2 == GNUNET_OK)) |
309 | return GNUNET_OK; | 308 | return GNUNET_OK; |
310 | if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) | 309 | if ((ret1 == GNUNET_SYSERR) || (ret2 == GNUNET_SYSERR)) |
311 | return GNUNET_SYSERR; | 310 | return GNUNET_SYSERR; |
312 | return GNUNET_NO; | 311 | return GNUNET_NO; |
313 | } | 312 | } |
314 | hp = gethostbyname2 (hostname, domain); | 313 | hp = gethostbyname2 (hostname, domain); |
315 | if (hp == NULL) | 314 | if (hp == NULL) |
316 | { | 315 | { |
317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 316 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
318 | _("Could not find IP of host `%s': %s\n"), | 317 | _("Could not find IP of host `%s': %s\n"), |
319 | hostname, hstrerror (h_errno)); | 318 | hostname, hstrerror (h_errno)); |
320 | return GNUNET_SYSERR; | 319 | return GNUNET_SYSERR; |
321 | } | 320 | } |
322 | GNUNET_assert (hp->h_addrtype == domain); | 321 | GNUNET_assert (hp->h_addrtype == domain); |
323 | if (domain == AF_INET) | 322 | if (domain == AF_INET) |
324 | { | 323 | { |
325 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); | 324 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); |
326 | memset (&a4, 0, sizeof (a4)); | 325 | memset (&a4, 0, sizeof (a4)); |
327 | a4.sin_family = AF_INET; | 326 | a4.sin_family = AF_INET; |
328 | #if HAVE_SOCKADDR_IN_SIN_LEN | 327 | #if HAVE_SOCKADDR_IN_SIN_LEN |
329 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); | 328 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); |
330 | #endif | 329 | #endif |
331 | memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); | 330 | memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); |
332 | GNUNET_SERVER_transmit_context_append_data (tc, | 331 | GNUNET_SERVER_transmit_context_append_data (tc, |
333 | &a4, | 332 | &a4, |
334 | sizeof (a4), | 333 | sizeof (a4), |
335 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 334 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
336 | } | 335 | } |
337 | else | 336 | else |
338 | { | 337 | { |
339 | GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); | 338 | GNUNET_assert (hp->h_length == sizeof (struct in6_addr)); |
340 | memset (&a6, 0, sizeof (a6)); | 339 | memset (&a6, 0, sizeof (a6)); |
341 | a6.sin6_family = AF_INET6; | 340 | a6.sin6_family = AF_INET6; |
342 | #if HAVE_SOCKADDR_IN_SIN_LEN | 341 | #if HAVE_SOCKADDR_IN_SIN_LEN |
343 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 342 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); |
344 | #endif | 343 | #endif |
345 | memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); | 344 | memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); |
346 | GNUNET_SERVER_transmit_context_append_data (tc, | 345 | GNUNET_SERVER_transmit_context_append_data (tc, |
347 | &a6, | 346 | &a6, |
348 | sizeof (a6), | 347 | sizeof (a6), |
349 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 348 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
350 | } | 349 | } |
351 | return GNUNET_OK; | 350 | return GNUNET_OK; |
352 | } | 351 | } |
353 | #endif | 352 | #endif |
@@ -362,17 +361,17 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
362 | 361 | ||
363 | hp = GETHOSTBYNAME (hostname); | 362 | hp = GETHOSTBYNAME (hostname); |
364 | if (hp == NULL) | 363 | if (hp == NULL) |
365 | { | 364 | { |
366 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 365 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
367 | _("Could not find IP of host `%s': %s\n"), | 366 | _("Could not find IP of host `%s': %s\n"), |
368 | hostname, hstrerror (h_errno)); | 367 | hostname, hstrerror (h_errno)); |
369 | return GNUNET_SYSERR; | 368 | return GNUNET_SYSERR; |
370 | } | 369 | } |
371 | if (hp->h_addrtype != AF_INET) | 370 | if (hp->h_addrtype != AF_INET) |
372 | { | 371 | { |
373 | GNUNET_break (0); | 372 | GNUNET_break (0); |
374 | return GNUNET_SYSERR; | 373 | return GNUNET_SYSERR; |
375 | } | 374 | } |
376 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); | 375 | GNUNET_assert (hp->h_length == sizeof (struct in_addr)); |
377 | memset (&addr, 0, sizeof (addr)); | 376 | memset (&addr, 0, sizeof (addr)); |
378 | addr.sin_family = AF_INET; | 377 | addr.sin_family = AF_INET; |
@@ -381,9 +380,9 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
381 | #endif | 380 | #endif |
382 | memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); | 381 | memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); |
383 | GNUNET_SERVER_transmit_context_append_data (tc, | 382 | GNUNET_SERVER_transmit_context_append_data (tc, |
384 | &addr, | 383 | &addr, |
385 | sizeof (addr), | 384 | sizeof (addr), |
386 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 385 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
387 | return GNUNET_OK; | 386 | return GNUNET_OK; |
388 | } | 387 | } |
389 | #endif | 388 | #endif |
@@ -418,7 +417,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, | |||
418 | gethostbyname_resolve (tc, hostname); | 417 | gethostbyname_resolve (tc, hostname); |
419 | #endif | 418 | #endif |
420 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 419 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
421 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 420 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
422 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 421 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
423 | } | 422 | } |
424 | 423 | ||
@@ -445,79 +444,78 @@ handle_get (void *cls, | |||
445 | 444 | ||
446 | msize = ntohs (message->size); | 445 | msize = ntohs (message->size); |
447 | if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) | 446 | if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) |
448 | { | 447 | { |
449 | GNUNET_break (0); | 448 | GNUNET_break (0); |
450 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 449 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
451 | return; | 450 | return; |
452 | } | 451 | } |
453 | msg = (const struct GNUNET_RESOLVER_GetMessage *) message; | 452 | msg = (const struct GNUNET_RESOLVER_GetMessage *) message; |
454 | size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); | 453 | size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); |
455 | direction = ntohl (msg->direction); | 454 | direction = ntohl (msg->direction); |
456 | domain = ntohl (msg->domain); | 455 | domain = ntohl (msg->domain); |
457 | if (direction == GNUNET_NO) | 456 | if (direction == GNUNET_NO) |
457 | { | ||
458 | /* IP from hostname */ | ||
459 | hostname = (const char *) &msg[1]; | ||
460 | if (hostname[size - 1] != '\0') | ||
458 | { | 461 | { |
459 | /* IP from hostname */ | 462 | GNUNET_break (0); |
460 | hostname = (const char *) &msg[1]; | 463 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
461 | if (hostname[size - 1] != '\0') | 464 | return; |
462 | { | 465 | } |
463 | GNUNET_break (0); | ||
464 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
465 | return; | ||
466 | } | ||
467 | #if DEBUG_RESOLVER | 466 | #if DEBUG_RESOLVER |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
469 | _("Resolver asked to look up `%s'.\n"), hostname); | 468 | _("Resolver asked to look up `%s'.\n"), hostname); |
470 | #endif | 469 | #endif |
471 | get_ip_from_hostname (client, hostname, domain); | 470 | get_ip_from_hostname (client, hostname, domain); |
472 | } | 471 | } |
473 | else | 472 | else |
474 | { | 473 | { |
475 | #if DEBUG_RESOLVER | 474 | #if DEBUG_RESOLVER |
476 | char buf[INET6_ADDRSTRLEN]; | 475 | char buf[INET6_ADDRSTRLEN]; |
477 | #endif | ||
478 | if (size < sizeof (struct sockaddr)) | ||
479 | { | ||
480 | GNUNET_break (0); | ||
481 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
482 | return; | ||
483 | } | ||
484 | sa = (const struct sockaddr*) &msg[1]; | ||
485 | switch (sa->sa_family) | ||
486 | { | ||
487 | case AF_INET: | ||
488 | if (size != sizeof (struct sockaddr_in)) | ||
489 | { | ||
490 | GNUNET_break (0); | ||
491 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
492 | return; | ||
493 | } | ||
494 | #if DEBUG_RESOLVER | ||
495 | inet_ntop (AF_INET, sa, buf, size); | ||
496 | #endif | 476 | #endif |
497 | break; | 477 | if (size < sizeof (struct sockaddr)) |
498 | case AF_INET6: | 478 | { |
499 | if (size != sizeof (struct sockaddr_in6)) | 479 | GNUNET_break (0); |
500 | { | 480 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
501 | GNUNET_break (0); | 481 | return; |
502 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 482 | } |
503 | return; | 483 | sa = (const struct sockaddr *) &msg[1]; |
504 | } | 484 | switch (sa->sa_family) |
505 | #if DEBUG_RESOLVER | 485 | { |
506 | inet_ntop (AF_INET6, sa, buf, size); | 486 | case AF_INET: |
487 | if (size != sizeof (struct sockaddr_in)) | ||
488 | { | ||
489 | GNUNET_break (0); | ||
490 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
491 | return; | ||
492 | } | ||
493 | #if DEBUG_RESOLVER | ||
494 | inet_ntop (AF_INET, sa, buf, size); | ||
507 | #endif | 495 | #endif |
508 | break; | 496 | break; |
509 | default: | 497 | case AF_INET6: |
510 | GNUNET_break (0); | 498 | if (size != sizeof (struct sockaddr_in6)) |
511 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 499 | { |
512 | return; | 500 | GNUNET_break (0); |
513 | } | 501 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
514 | #if DEBUG_RESOLVER | 502 | return; |
515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | } |
516 | _("Resolver asked to look up IP address `%s'.\n"), | 504 | #if DEBUG_RESOLVER |
517 | buf); | 505 | inet_ntop (AF_INET6, sa, buf, size); |
518 | #endif | 506 | #endif |
519 | get_ip_as_string (client, sa, size); | 507 | break; |
508 | default: | ||
509 | GNUNET_break (0); | ||
510 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
511 | return; | ||
520 | } | 512 | } |
513 | #if DEBUG_RESOLVER | ||
514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
515 | _("Resolver asked to look up IP address `%s'.\n"), buf); | ||
516 | #endif | ||
517 | get_ip_as_string (client, sa, size); | ||
518 | } | ||
521 | } | 519 | } |
522 | 520 | ||
523 | 521 | ||
@@ -561,13 +559,13 @@ main (int argc, char *const *argv) | |||
561 | &run, NULL)) ? 0 : 1; | 559 | &run, NULL)) ? 0 : 1; |
562 | 560 | ||
563 | while (head != NULL) | 561 | while (head != NULL) |
564 | { | 562 | { |
565 | pos = head->next; | 563 | pos = head->next; |
566 | GNUNET_free_non_null (head->addr); | 564 | GNUNET_free_non_null (head->addr); |
567 | GNUNET_free (head->sa); | 565 | GNUNET_free (head->sa); |
568 | GNUNET_free (head); | 566 | GNUNET_free (head); |
569 | head = pos; | 567 | head = pos; |
570 | } | 568 | } |
571 | return ret; | 569 | return ret; |
572 | } | 570 | } |
573 | 571 | ||
diff --git a/src/util/load.c b/src/util/load.c index 9bbea6c14..c7ef07295 100644 --- a/src/util/load.c +++ b/src/util/load.c | |||
@@ -31,7 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * Values we track for load calculations. | 32 | * Values we track for load calculations. |
33 | */ | 33 | */ |
34 | struct GNUNET_LOAD_Value | 34 | struct GNUNET_LOAD_Value |
35 | { | 35 | { |
36 | 36 | ||
37 | /** | 37 | /** |
@@ -41,7 +41,7 @@ struct GNUNET_LOAD_Value | |||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Last time this load value was updated by an event. | 43 | * Last time this load value was updated by an event. |
44 | */ | 44 | */ |
45 | struct GNUNET_TIME_Absolute last_update; | 45 | struct GNUNET_TIME_Absolute last_update; |
46 | 46 | ||
47 | /** | 47 | /** |
@@ -50,19 +50,19 @@ struct GNUNET_LOAD_Value | |||
50 | * first 4 billion requests). | 50 | * first 4 billion requests). |
51 | */ | 51 | */ |
52 | uint64_t cummulative_delay; | 52 | uint64_t cummulative_delay; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Sum of squares of all datastore delays ever observed (in ms). Note that | 55 | * Sum of squares of all datastore delays ever observed (in ms). Note that |
56 | * delays above 64k ms are excluded (to avoid overflow within | 56 | * delays above 64k ms are excluded (to avoid overflow within |
57 | * first 4 billion requests). | 57 | * first 4 billion requests). |
58 | */ | 58 | */ |
59 | uint64_t cummulative_squared_delay; | 59 | uint64_t cummulative_squared_delay; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Total number of requests included in the cummulative datastore delay values. | 62 | * Total number of requests included in the cummulative datastore delay values. |
63 | */ | 63 | */ |
64 | uint64_t cummulative_request_count; | 64 | uint64_t cummulative_request_count; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Current running average datastore delay. Its relation to the | 67 | * Current running average datastore delay. Its relation to the |
68 | * average datastore delay and it std. dev. (as calcualted from the | 68 | * average datastore delay and it std. dev. (as calcualted from the |
@@ -92,23 +92,23 @@ internal_update (struct GNUNET_LOAD_Value *load) | |||
92 | if (delta.rel_value < load->autodecline.rel_value) | 92 | if (delta.rel_value < load->autodecline.rel_value) |
93 | return; | 93 | return; |
94 | if (load->autodecline.rel_value == 0) | 94 | if (load->autodecline.rel_value == 0) |
95 | { | 95 | { |
96 | load->runavg_delay = 0.0; | 96 | load->runavg_delay = 0.0; |
97 | load->load = 0; | 97 | load->load = 0; |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | n = delta.rel_value / load->autodecline.rel_value; | 100 | n = delta.rel_value / load->autodecline.rel_value; |
101 | if (n > 16) | 101 | if (n > 16) |
102 | { | 102 | { |
103 | load->runavg_delay = 0.0; | 103 | load->runavg_delay = 0.0; |
104 | load->load = 0; | 104 | load->load = 0; |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | while (n > 0) | 107 | while (n > 0) |
108 | { | 108 | { |
109 | n--; | 109 | n--; |
110 | load->runavg_delay = (load->runavg_delay * 7.0) / 8.0; | 110 | load->runavg_delay = (load->runavg_delay * 7.0) / 8.0; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
@@ -140,10 +140,10 @@ GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline) | |||
140 | */ | 140 | */ |
141 | void | 141 | void |
142 | GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load, | 142 | GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load, |
143 | struct GNUNET_TIME_Relative autodecline) | 143 | struct GNUNET_TIME_Relative autodecline) |
144 | { | 144 | { |
145 | internal_update (load); | 145 | internal_update (load); |
146 | load->autodecline = autodecline; | 146 | load->autodecline = autodecline; |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
@@ -164,25 +164,27 @@ calculate_load (struct GNUNET_LOAD_Value *load) | |||
164 | if (load->cummulative_request_count <= 1) | 164 | if (load->cummulative_request_count <= 1) |
165 | return; | 165 | return; |
166 | /* calcuate std dev of latency; we have for n values of "i" that: | 166 | /* calcuate std dev of latency; we have for n values of "i" that: |
167 | 167 | * | |
168 | avg = (sum val_i) / n | 168 | * avg = (sum val_i) / n |
169 | stddev = (sum (val_i - avg)^2) / (n-1) | 169 | * stddev = (sum (val_i - avg)^2) / (n-1) |
170 | = (sum (val_i^2 - 2 avg val_i + avg^2) / (n-1) | 170 | * = (sum (val_i^2 - 2 avg val_i + avg^2) / (n-1) |
171 | = (sum (val_i^2) - 2 avg sum (val_i) + n * avg^2) / (n-1) | 171 | * = (sum (val_i^2) - 2 avg sum (val_i) + n * avg^2) / (n-1) |
172 | */ | 172 | */ |
173 | sum_val_i = (double) load->cummulative_delay; | 173 | sum_val_i = (double) load->cummulative_delay; |
174 | n = ((double) load->cummulative_request_count); | 174 | n = ((double) load->cummulative_request_count); |
175 | nm1 = n - 1.0; | 175 | nm1 = n - 1.0; |
176 | avgdel = sum_val_i / n; | 176 | avgdel = sum_val_i / n; |
177 | stddev = (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i + n * avgdel * avgdel) / nm1; | 177 | stddev = |
178 | (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i + | ||
179 | n * avgdel * avgdel) / nm1; | ||
178 | if (stddev <= 0) | 180 | if (stddev <= 0) |
179 | stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */ | 181 | stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */ |
180 | /* now calculate load based on how far out we are from | 182 | /* now calculate load based on how far out we are from |
181 | std dev; or if we are below average, simply assume load zero */ | 183 | * std dev; or if we are below average, simply assume load zero */ |
182 | if (load->runavg_delay < avgdel) | 184 | if (load->runavg_delay < avgdel) |
183 | load->load = 0.0; | 185 | load->load = 0.0; |
184 | else | 186 | else |
185 | load->load = (load->runavg_delay - avgdel) / stddev; | 187 | load->load = (load->runavg_delay - avgdel) / stddev; |
186 | } | 188 | } |
187 | 189 | ||
188 | 190 | ||
@@ -232,22 +234,21 @@ GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load) | |||
232 | * @param data latest measurement value (for example, delay) | 234 | * @param data latest measurement value (for example, delay) |
233 | */ | 235 | */ |
234 | void | 236 | void |
235 | GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, | 237 | GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data) |
236 | uint64_t data) | ||
237 | { | 238 | { |
238 | uint32_t dv; | 239 | uint32_t dv; |
239 | 240 | ||
240 | internal_update (load); | 241 | internal_update (load); |
241 | load->last_update = GNUNET_TIME_absolute_get (); | 242 | load->last_update = GNUNET_TIME_absolute_get (); |
242 | if (data > 64 * 1024) | 243 | if (data > 64 * 1024) |
243 | { | 244 | { |
244 | /* very large */ | 245 | /* very large */ |
245 | load->load = 100.0; | 246 | load->load = 100.0; |
246 | return; | 247 | return; |
247 | } | 248 | } |
248 | dv = (uint32_t) data; | 249 | dv = (uint32_t) data; |
249 | load->cummulative_delay += dv; | 250 | load->cummulative_delay += dv; |
250 | load->cummulative_squared_delay += dv * dv; | 251 | load->cummulative_squared_delay += dv * dv; |
251 | load->cummulative_request_count++; | 252 | load->cummulative_request_count++; |
252 | load->runavg_delay = ((load->runavg_delay * 7.0) + dv) / 8.0; | 253 | load->runavg_delay = ((load->runavg_delay * 7.0) + dv) / 8.0; |
253 | } | 254 | } |
diff --git a/src/util/network.c b/src/util/network.c index 6ce3df1c2..b533ce183 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -82,25 +82,27 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) | |||
82 | 82 | ||
83 | #if MINGW | 83 | #if MINGW |
84 | u_long mode; | 84 | u_long mode; |
85 | |||
85 | mode = !doBlock; | 86 | mode = !doBlock; |
86 | if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) | 87 | if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) |
87 | 88 | ||
88 | { | 89 | { |
89 | SetErrnoFromWinsockError (WSAGetLastError ()); | 90 | SetErrnoFromWinsockError (WSAGetLastError ()); |
90 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); | 91 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); |
91 | return GNUNET_SYSERR; | 92 | return GNUNET_SYSERR; |
92 | } | 93 | } |
93 | return GNUNET_OK; | 94 | return GNUNET_OK; |
94 | 95 | ||
95 | #else | 96 | #else |
96 | /* not MINGW */ | 97 | /* not MINGW */ |
97 | int flags = fcntl (fd->fd, F_GETFL); | 98 | int flags = fcntl (fd->fd, F_GETFL); |
99 | |||
98 | if (flags == -1) | 100 | if (flags == -1) |
99 | 101 | ||
100 | { | 102 | { |
101 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); | 103 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); |
102 | return GNUNET_SYSERR; | 104 | return GNUNET_SYSERR; |
103 | } | 105 | } |
104 | if (doBlock) | 106 | if (doBlock) |
105 | flags &= ~O_NONBLOCK; | 107 | flags &= ~O_NONBLOCK; |
106 | 108 | ||
@@ -108,10 +110,10 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock) | |||
108 | flags |= O_NONBLOCK; | 110 | flags |= O_NONBLOCK; |
109 | if (0 != fcntl (fd->fd, F_SETFL, flags)) | 111 | if (0 != fcntl (fd->fd, F_SETFL, flags)) |
110 | 112 | ||
111 | { | 113 | { |
112 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); | 114 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); |
113 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
114 | } | 116 | } |
115 | return GNUNET_OK; | 117 | return GNUNET_OK; |
116 | #endif | 118 | #endif |
117 | } | 119 | } |
@@ -130,7 +132,7 @@ socket_set_inheritable (const struct GNUNET_NETWORK_Handle *h) | |||
130 | { | 132 | { |
131 | int i; | 133 | int i; |
132 | 134 | ||
133 | i = fcntl (h->fd, F_GETFD); | 135 | i = fcntl (h->fd, F_GETFD); |
134 | if (i < 0) | 136 | if (i < 0) |
135 | return GNUNET_SYSERR; | 137 | return GNUNET_SYSERR; |
136 | if (i == (i | FD_CLOEXEC)) | 138 | if (i == (i | FD_CLOEXEC)) |
@@ -153,8 +155,10 @@ static void | |||
153 | socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) | 155 | socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) |
154 | { | 156 | { |
155 | int abs_value = 1; | 157 | int abs_value = 1; |
158 | |||
156 | if (0 != | 159 | if (0 != |
157 | setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, sizeof (abs_value))) | 160 | setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, |
161 | sizeof (abs_value))) | ||
158 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 162 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
159 | } | 163 | } |
160 | #endif | 164 | #endif |
@@ -170,15 +174,19 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h) | |||
170 | static void | 174 | static void |
171 | socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) | 175 | socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) |
172 | { | 176 | { |
173 | #ifndef WINDOWS | 177 | #ifndef WINDOWS |
174 | int value = 1; | 178 | int value = 1; |
179 | |||
175 | if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) | 180 | if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value))) |
176 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 181 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
177 | #else | 182 | #else |
178 | const char * abs_value = "1"; | 183 | const char *abs_value = "1"; |
179 | if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, sizeof (abs_value))) | 184 | |
185 | if (0 != | ||
186 | setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, | ||
187 | sizeof (abs_value))) | ||
180 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 188 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
181 | #endif | 189 | #endif |
182 | } | 190 | } |
183 | 191 | ||
184 | 192 | ||
@@ -192,8 +200,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h) | |||
192 | */ | 200 | */ |
193 | struct GNUNET_NETWORK_Handle * | 201 | struct GNUNET_NETWORK_Handle * |
194 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | 202 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, |
195 | struct sockaddr *address, | 203 | struct sockaddr *address, socklen_t * address_len) |
196 | socklen_t * address_len) | ||
197 | { | 204 | { |
198 | struct GNUNET_NETWORK_Handle *ret; | 205 | struct GNUNET_NETWORK_Handle *ret; |
199 | 206 | ||
@@ -203,10 +210,11 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
203 | struct sockaddr name; | 210 | struct sockaddr name; |
204 | int namelen = sizeof (name); | 211 | int namelen = sizeof (name); |
205 | int gsn = getsockname (desc->fd, &name, &namelen); | 212 | int gsn = getsockname (desc->fd, &name, &namelen); |
213 | |||
206 | if (gsn == 0) | 214 | if (gsn == 0) |
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
208 | "Accepting connection on `%s'\n", | 216 | "Accepting connection on `%s'\n", |
209 | GNUNET_a2s (&name, namelen)); | 217 | GNUNET_a2s (&name, namelen)); |
210 | } | 218 | } |
211 | #endif | 219 | #endif |
212 | ret->fd = accept (desc->fd, address, address_len); | 220 | ret->fd = accept (desc->fd, address, address_len); |
@@ -215,31 +223,31 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
215 | else | 223 | else |
216 | ret->af = desc->af; | 224 | ret->af = desc->af; |
217 | if (ret->fd == INVALID_SOCKET) | 225 | if (ret->fd == INVALID_SOCKET) |
218 | { | 226 | { |
219 | #ifdef MINGW | 227 | #ifdef MINGW |
220 | SetErrnoFromWinsockError (WSAGetLastError ()); | 228 | SetErrnoFromWinsockError (WSAGetLastError ()); |
221 | #endif | 229 | #endif |
222 | GNUNET_free (ret); | 230 | GNUNET_free (ret); |
223 | return NULL; | 231 | return NULL; |
224 | } | 232 | } |
225 | #ifndef MINGW | 233 | #ifndef MINGW |
226 | if (ret->fd >= FD_SETSIZE) | 234 | if (ret->fd >= FD_SETSIZE) |
227 | { | 235 | { |
228 | GNUNET_break (0 == close (ret->fd)); | 236 | GNUNET_break (0 == close (ret->fd)); |
229 | GNUNET_free (ret); | 237 | GNUNET_free (ret); |
230 | errno = EMFILE; | 238 | errno = EMFILE; |
231 | return NULL; | 239 | return NULL; |
232 | } | 240 | } |
233 | #endif | 241 | #endif |
234 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) | 242 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) |
235 | 243 | ||
236 | { | 244 | { |
237 | 245 | ||
238 | /* we might want to treat this one as fatal... */ | 246 | /* we might want to treat this one as fatal... */ |
239 | GNUNET_break (0); | 247 | GNUNET_break (0); |
240 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); | 248 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); |
241 | return NULL; | 249 | return NULL; |
242 | } | 250 | } |
243 | 251 | ||
244 | #ifndef MINGW | 252 | #ifndef MINGW |
245 | if (GNUNET_OK != socket_set_inheritable (ret)) | 253 | if (GNUNET_OK != socket_set_inheritable (ret)) |
@@ -270,10 +278,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
270 | socklen_t address_len) | 278 | socklen_t address_len) |
271 | { | 279 | { |
272 | int ret; | 280 | int ret; |
273 | 281 | ||
274 | #ifdef IPV6_V6ONLY | 282 | #ifdef IPV6_V6ONLY |
275 | #ifdef IPPROTO_IPV6 | 283 | #ifdef IPPROTO_IPV6 |
276 | const int on = 1; | 284 | const int on = 1; |
285 | |||
277 | if (desc->af == AF_INET6) | 286 | if (desc->af == AF_INET6) |
278 | if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) | 287 | if (0 != setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) |
279 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); | 288 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); |
@@ -287,10 +296,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
287 | #ifndef LINUX | 296 | #ifndef LINUX |
288 | #ifndef MINGW | 297 | #ifndef MINGW |
289 | if (address->sa_family == AF_UNIX) | 298 | if (address->sa_family == AF_UNIX) |
290 | { | 299 | { |
291 | const struct sockaddr_un *un = (const struct sockaddr_un*) address; | 300 | const struct sockaddr_un *un = (const struct sockaddr_un *) address; |
292 | (void) unlink (un->sun_path); | 301 | |
293 | } | 302 | (void) unlink (un->sun_path); |
303 | } | ||
294 | #endif | 304 | #endif |
295 | #endif | 305 | #endif |
296 | ret = bind (desc->fd, address, address_len); | 306 | ret = bind (desc->fd, address, address_len); |
@@ -323,29 +333,33 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
323 | 333 | ||
324 | #ifdef MINGW | 334 | #ifdef MINGW |
325 | DWORD error = 0; | 335 | DWORD error = 0; |
336 | |||
326 | #if DEBUG_NETWORK | 337 | #if DEBUG_NETWORK |
327 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closing 0x%x\n", desc->fd); | 338 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", |
339 | "Closing 0x%x\n", desc->fd); | ||
328 | #endif | 340 | #endif |
329 | SetLastError (0); | 341 | SetLastError (0); |
330 | ret = closesocket (desc->fd); | 342 | ret = closesocket (desc->fd); |
331 | error = WSAGetLastError (); | 343 | error = WSAGetLastError (); |
332 | SetErrnoFromWinsockError (error); | 344 | SetErrnoFromWinsockError (error); |
333 | #if DEBUG_NETWORK | 345 | #if DEBUG_NETWORK |
334 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", "Closed 0x%x, closesocket() returned %d, GLE is %u\n", desc->fd, ret, error); | 346 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_NETWORK_socket_close", |
347 | "Closed 0x%x, closesocket() returned %d, GLE is %u\n", | ||
348 | desc->fd, ret, error); | ||
335 | #endif | 349 | #endif |
336 | #else | 350 | #else |
337 | ret = close (desc->fd); | 351 | ret = close (desc->fd); |
338 | #endif | 352 | #endif |
339 | #ifndef LINUX | 353 | #ifndef LINUX |
340 | #ifndef MINGW | 354 | #ifndef MINGW |
341 | if ( (desc->af == AF_UNIX) && (NULL != desc->addr) ) | 355 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) |
342 | { | 356 | { |
343 | const struct sockaddr_un *un = (const struct sockaddr_un*) desc->addr; | 357 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; |
344 | if (0 != unlink (un->sun_path)) | 358 | |
345 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 359 | if (0 != unlink (un->sun_path)) |
346 | "unlink", | 360 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
347 | un->sun_path); | 361 | "unlink", un->sun_path); |
348 | } | 362 | } |
349 | #endif | 363 | #endif |
350 | #endif | 364 | #endif |
351 | GNUNET_free_non_null (desc->addr); | 365 | GNUNET_free_non_null (desc->addr); |
@@ -369,8 +383,8 @@ GNUNET_NETWORK_socket_box_native (int fd) | |||
369 | struct GNUNET_NETWORK_Handle *ret; | 383 | struct GNUNET_NETWORK_Handle *ret; |
370 | 384 | ||
371 | if (fcntl (fd, F_GETFD) < 0) | 385 | if (fcntl (fd, F_GETFD) < 0) |
372 | return NULL; /* invalid FD */ | 386 | return NULL; /* invalid FD */ |
373 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); | 387 | ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); |
374 | ret->fd = fd; | 388 | ret->fd = fd; |
375 | ret->af = AF_UNSPEC; | 389 | ret->af = AF_UNSPEC; |
376 | return ret; | 390 | return ret; |
@@ -391,15 +405,16 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | |||
391 | socklen_t address_len) | 405 | socklen_t address_len) |
392 | { | 406 | { |
393 | int ret; | 407 | int ret; |
408 | |||
394 | ret = connect (desc->fd, address, address_len); | 409 | ret = connect (desc->fd, address, address_len); |
395 | 410 | ||
396 | #ifdef MINGW | 411 | #ifdef MINGW |
397 | if (SOCKET_ERROR == ret) | 412 | if (SOCKET_ERROR == ret) |
398 | { | 413 | { |
399 | SetErrnoFromWinsockError (WSAGetLastError ()); | 414 | SetErrnoFromWinsockError (WSAGetLastError ()); |
400 | if (errno == EWOULDBLOCK) | 415 | if (errno == EWOULDBLOCK) |
401 | errno = EINPROGRESS; | 416 | errno = EINPROGRESS; |
402 | } | 417 | } |
403 | #endif | 418 | #endif |
404 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; | 419 | return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; |
405 | } | 420 | } |
@@ -421,6 +436,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | |||
421 | socklen_t * optlen) | 436 | socklen_t * optlen) |
422 | { | 437 | { |
423 | int ret; | 438 | int ret; |
439 | |||
424 | ret = getsockopt (desc->fd, level, optname, optval, optlen); | 440 | ret = getsockopt (desc->fd, level, optname, optval, optlen); |
425 | 441 | ||
426 | #ifdef MINGW | 442 | #ifdef MINGW |
@@ -445,6 +461,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | |||
445 | int backlog) | 461 | int backlog) |
446 | { | 462 | { |
447 | int ret; | 463 | int ret; |
464 | |||
448 | ret = listen (desc->fd, backlog); | 465 | ret = listen (desc->fd, backlog); |
449 | 466 | ||
450 | #ifdef MINGW | 467 | #ifdef MINGW |
@@ -464,17 +481,19 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | |||
464 | */ | 481 | */ |
465 | ssize_t | 482 | ssize_t |
466 | GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle | 483 | GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle |
467 | *desc) | 484 | * desc) |
468 | { | 485 | { |
469 | int error; | 486 | int error; |
470 | 487 | ||
471 | /* How much is there to be read? */ | 488 | /* How much is there to be read? */ |
472 | #ifndef WINDOWS | 489 | #ifndef WINDOWS |
473 | int pending; | 490 | int pending; |
491 | |||
474 | error = ioctl (desc->fd, FIONREAD, &pending); | 492 | error = ioctl (desc->fd, FIONREAD, &pending); |
475 | if (error == 0) | 493 | if (error == 0) |
476 | #else | 494 | #else |
477 | u_long pending; | 495 | u_long pending; |
496 | |||
478 | error = ioctlsocket (desc->fd, FIONREAD, &pending); | 497 | error = ioctlsocket (desc->fd, FIONREAD, &pending); |
479 | if (error != SOCKET_ERROR) | 498 | if (error != SOCKET_ERROR) |
480 | #endif | 499 | #endif |
@@ -496,11 +515,11 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle | |||
496 | ssize_t | 515 | ssize_t |
497 | GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, | 516 | GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, |
498 | void *buffer, size_t length, | 517 | void *buffer, size_t length, |
499 | struct sockaddr * src_addr, | 518 | struct sockaddr * src_addr, socklen_t * addrlen) |
500 | socklen_t * addrlen) | ||
501 | { | 519 | { |
502 | int ret; | 520 | int ret; |
503 | int flags; | 521 | int flags; |
522 | |||
504 | flags = 0; | 523 | flags = 0; |
505 | 524 | ||
506 | #ifdef MSG_DONTWAIT | 525 | #ifdef MSG_DONTWAIT |
@@ -511,7 +530,7 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, | |||
511 | #ifdef MINGW | 530 | #ifdef MINGW |
512 | if (SOCKET_ERROR == ret) | 531 | if (SOCKET_ERROR == ret) |
513 | SetErrnoFromWinsockError (WSAGetLastError ()); | 532 | SetErrnoFromWinsockError (WSAGetLastError ()); |
514 | #endif | 533 | #endif |
515 | return ret; | 534 | return ret; |
516 | } | 535 | } |
517 | 536 | ||
@@ -528,6 +547,7 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, | |||
528 | { | 547 | { |
529 | int ret; | 548 | int ret; |
530 | int flags; | 549 | int flags; |
550 | |||
531 | flags = 0; | 551 | flags = 0; |
532 | 552 | ||
533 | #ifdef MSG_DONTWAIT | 553 | #ifdef MSG_DONTWAIT |
@@ -556,6 +576,7 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, | |||
556 | { | 576 | { |
557 | int ret; | 577 | int ret; |
558 | int flags; | 578 | int flags; |
579 | |||
559 | flags = 0; | 580 | flags = 0; |
560 | 581 | ||
561 | #ifdef MSG_DONTWAIT | 582 | #ifdef MSG_DONTWAIT |
@@ -596,6 +617,7 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, | |||
596 | { | 617 | { |
597 | int ret; | 618 | int ret; |
598 | int flags; | 619 | int flags; |
620 | |||
599 | flags = 0; | 621 | flags = 0; |
600 | 622 | ||
601 | #ifdef MSG_DONTWAIT | 623 | #ifdef MSG_DONTWAIT |
@@ -658,31 +680,31 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) | |||
658 | ret->af = domain; | 680 | ret->af = domain; |
659 | ret->fd = socket (domain, type, protocol); | 681 | ret->fd = socket (domain, type, protocol); |
660 | if (INVALID_SOCKET == ret->fd) | 682 | if (INVALID_SOCKET == ret->fd) |
661 | { | 683 | { |
662 | #ifdef MINGW | 684 | #ifdef MINGW |
663 | SetErrnoFromWinsockError (WSAGetLastError ()); | 685 | SetErrnoFromWinsockError (WSAGetLastError ()); |
664 | #endif | 686 | #endif |
665 | GNUNET_free (ret); | 687 | GNUNET_free (ret); |
666 | return NULL; | 688 | return NULL; |
667 | } | 689 | } |
668 | 690 | ||
669 | #ifndef MINGW | 691 | #ifndef MINGW |
670 | if (ret->fd >= FD_SETSIZE) | 692 | if (ret->fd >= FD_SETSIZE) |
671 | { | 693 | { |
672 | GNUNET_break (0 == close (ret->fd)); | 694 | GNUNET_break (0 == close (ret->fd)); |
673 | GNUNET_free (ret); | 695 | GNUNET_free (ret); |
674 | errno = EMFILE; | 696 | errno = EMFILE; |
675 | return NULL; | 697 | return NULL; |
676 | } | 698 | } |
677 | 699 | ||
678 | #endif | 700 | #endif |
679 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) | 701 | if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) |
680 | { | 702 | { |
681 | /* we might want to treat this one as fatal... */ | 703 | /* we might want to treat this one as fatal... */ |
682 | GNUNET_break (0); | 704 | GNUNET_break (0); |
683 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); | 705 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); |
684 | return NULL; | 706 | return NULL; |
685 | } | 707 | } |
686 | 708 | ||
687 | #ifndef MINGW | 709 | #ifndef MINGW |
688 | if (GNUNET_OK != socket_set_inheritable (ret)) | 710 | if (GNUNET_OK != socket_set_inheritable (ret)) |
@@ -692,11 +714,11 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) | |||
692 | #ifdef DARWIN | 714 | #ifdef DARWIN |
693 | socket_set_nosigpipe (ret); | 715 | socket_set_nosigpipe (ret); |
694 | #endif | 716 | #endif |
695 | if ( (type == SOCK_STREAM) | 717 | if ((type == SOCK_STREAM) |
696 | #ifdef AF_UNIX | 718 | #ifdef AF_UNIX |
697 | && (domain != AF_UNIX) | 719 | && (domain != AF_UNIX) |
698 | #endif | 720 | #endif |
699 | ) | 721 | ) |
700 | socket_set_nodelay (ret); | 722 | socket_set_nodelay (ret); |
701 | return ret; | 723 | return ret; |
702 | } | 724 | } |
@@ -736,15 +758,26 @@ GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc) | |||
736 | { | 758 | { |
737 | int value = 0; | 759 | int value = 0; |
738 | int ret = 0; | 760 | int ret = 0; |
761 | |||
739 | #if WINDOWS | 762 | #if WINDOWS |
740 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, sizeof (value)))) | 763 | if (0 != |
764 | (ret = | ||
765 | setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, (char *) &value, | ||
766 | sizeof (value)))) | ||
741 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 767 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
742 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, sizeof (value)))) | 768 | if (0 != |
769 | (ret = | ||
770 | setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, | ||
771 | sizeof (value)))) | ||
743 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 772 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
744 | #else | 773 | #else |
745 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof (value)))) | 774 | if (0 != |
775 | (ret = | ||
776 | setsockopt (desc->fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof (value)))) | ||
746 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 777 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
747 | if (0 != (ret = setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof (value)))) | 778 | if (0 != |
779 | (ret = | ||
780 | setsockopt (desc->fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof (value)))) | ||
748 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 781 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
749 | #endif | 782 | #endif |
750 | 783 | ||
@@ -805,14 +838,15 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, | |||
805 | const struct GNUNET_NETWORK_FDSet *src) | 838 | const struct GNUNET_NETWORK_FDSet *src) |
806 | { | 839 | { |
807 | int nfds; | 840 | int nfds; |
841 | |||
808 | for (nfds = src->nsds; nfds > 0; nfds--) | 842 | for (nfds = src->nsds; nfds > 0; nfds--) |
809 | if (FD_ISSET (nfds, &src->sds)) | 843 | if (FD_ISSET (nfds, &src->sds)) |
810 | 844 | ||
811 | { | 845 | { |
812 | FD_SET (nfds, &dst->sds); | 846 | FD_SET (nfds, &dst->sds); |
813 | if (nfds + 1 > dst->nsds) | 847 | if (nfds + 1 > dst->nsds) |
814 | dst->nsds = nfds + 1; | 848 | dst->nsds = nfds + 1; |
815 | } | 849 | } |
816 | #ifdef MINGW | 850 | #ifdef MINGW |
817 | GNUNET_CONTAINER_slist_append (dst->handles, src->handles); | 851 | GNUNET_CONTAINER_slist_append (dst->handles, src->handles); |
818 | #endif | 852 | #endif |
@@ -874,10 +908,10 @@ GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, | |||
874 | * @param to destination | 908 | * @param to destination |
875 | * @param nfd native FD to set | 909 | * @param nfd native FD to set |
876 | */ | 910 | */ |
877 | void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, | 911 | void |
878 | int nfd) | 912 | GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd) |
879 | { | 913 | { |
880 | GNUNET_assert((nfd >= 0) && (nfd < FD_SETSIZE)); | 914 | GNUNET_assert ((nfd >= 0) && (nfd < FD_SETSIZE)); |
881 | FD_SET (nfd, &to->sds); | 915 | FD_SET (nfd, &to->sds); |
882 | to->nsds = GNUNET_MAX (nfd + 1, to->nsds); | 916 | to->nsds = GNUNET_MAX (nfd + 1, to->nsds); |
883 | } | 917 | } |
@@ -890,11 +924,11 @@ void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, | |||
890 | * @param nfd native FD to test, or -1 for none | 924 | * @param nfd native FD to test, or -1 for none |
891 | * @return GNUNET_YES if FD is set in the set | 925 | * @return GNUNET_YES if FD is set in the set |
892 | */ | 926 | */ |
893 | int | 927 | int |
894 | GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, | 928 | GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, |
895 | int nfd) | 929 | int nfd) |
896 | { | 930 | { |
897 | if ( (nfd == -1) || (to == NULL) ) | 931 | if ((nfd == -1) || (to == NULL)) |
898 | return GNUNET_NO; | 932 | return GNUNET_NO; |
899 | return FD_ISSET (nfd, &to->sds) ? GNUNET_YES : GNUNET_NO; | 933 | return FD_ISSET (nfd, &to->sds) ? GNUNET_YES : GNUNET_NO; |
900 | } | 934 | } |
@@ -916,6 +950,7 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | |||
916 | 950 | ||
917 | #else | 951 | #else |
918 | int fd; | 952 | int fd; |
953 | |||
919 | GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); | 954 | GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); |
920 | FD_SET (fd, &fds->sds); | 955 | FD_SET (fd, &fds->sds); |
921 | if (fd + 1 > fds->nsds) | 956 | if (fd + 1 > fds->nsds) |
@@ -938,7 +973,8 @@ GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, | |||
938 | 973 | ||
939 | #ifdef MINGW | 974 | #ifdef MINGW |
940 | return GNUNET_CONTAINER_slist_contains (fds->handles, h, | 975 | return GNUNET_CONTAINER_slist_contains (fds->handles, h, |
941 | sizeof (struct GNUNET_DISK_FileHandle)); | 976 | sizeof (struct |
977 | GNUNET_DISK_FileHandle)); | ||
942 | #else | 978 | #else |
943 | return FD_ISSET (h->fd, &fds->sds); | 979 | return FD_ISSET (h->fd, &fds->sds); |
944 | #endif | 980 | #endif |
@@ -962,11 +998,11 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
962 | if (nfds > fds2->nsds) | 998 | if (nfds > fds2->nsds) |
963 | nfds = fds2->nsds; | 999 | nfds = fds2->nsds; |
964 | while (nfds > 0) | 1000 | while (nfds > 0) |
965 | { | 1001 | { |
966 | nfds--; | 1002 | nfds--; |
967 | if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) | 1003 | if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) |
968 | return GNUNET_YES; | 1004 | return GNUNET_YES; |
969 | } | 1005 | } |
970 | #else | 1006 | #else |
971 | struct GNUNET_CONTAINER_SList_Iterator *it; | 1007 | struct GNUNET_CONTAINER_SList_Iterator *it; |
972 | struct GNUNET_DISK_FileHandle *h; | 1008 | struct GNUNET_DISK_FileHandle *h; |
@@ -974,7 +1010,7 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
974 | int j; | 1010 | int j; |
975 | 1011 | ||
976 | /*This code is somewhat hacky, we are not supposed to know what's | 1012 | /*This code is somewhat hacky, we are not supposed to know what's |
977 | inside of fd_set; also the O(n^2) is really bad... */ | 1013 | * inside of fd_set; also the O(n^2) is really bad... */ |
978 | 1014 | ||
979 | for (i = 0; i < fds1->sds.fd_count; i++) | 1015 | for (i = 0; i < fds1->sds.fd_count; i++) |
980 | { | 1016 | { |
@@ -986,33 +1022,36 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, | |||
986 | } | 1022 | } |
987 | it = GNUNET_CONTAINER_slist_begin (fds1->handles); | 1023 | it = GNUNET_CONTAINER_slist_begin (fds1->handles); |
988 | while (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES) | 1024 | while (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES) |
989 | { | 1025 | { |
990 | #if DEBUG_NETWORK | 1026 | #if DEBUG_NETWORK |
991 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1027 | struct GNUNET_CONTAINER_SList_Iterator *t; |
992 | #endif | 1028 | #endif |
993 | h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (it, NULL); | 1029 | h = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (it, NULL); |
994 | #if DEBUG_NETWORK | 1030 | #if DEBUG_NETWORK |
995 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking that FD 0x%x is in another set:\n", h->h); | 1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
996 | for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); | 1032 | "Checking that FD 0x%x is in another set:\n", h->h); |
997 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1033 | for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); |
998 | GNUNET_CONTAINER_slist_next (t)) | 1034 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
999 | { | 1035 | GNUNET_CONTAINER_slist_next (t)) |
1000 | struct GNUNET_DISK_FileHandle *fh; | 1036 | { |
1001 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 1037 | struct GNUNET_DISK_FileHandle *fh; |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); | 1038 | |
1003 | } | 1039 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, |
1040 | NULL); | ||
1041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); | ||
1042 | } | ||
1004 | #endif | 1043 | #endif |
1005 | if (GNUNET_CONTAINER_slist_contains | 1044 | if (GNUNET_CONTAINER_slist_contains |
1006 | (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) | 1045 | (fds2->handles, h, sizeof (struct GNUNET_DISK_FileHandle))) |
1007 | { | 1046 | { |
1008 | #if DEBUG_NETWORK | 1047 | #if DEBUG_NETWORK |
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); |
1010 | #endif | 1049 | #endif |
1011 | GNUNET_CONTAINER_slist_iter_destroy (it); | 1050 | GNUNET_CONTAINER_slist_iter_destroy (it); |
1012 | return GNUNET_YES; | 1051 | return GNUNET_YES; |
1013 | } | ||
1014 | GNUNET_CONTAINER_slist_next (it); | ||
1015 | } | 1052 | } |
1053 | GNUNET_CONTAINER_slist_next (it); | ||
1054 | } | ||
1016 | GNUNET_CONTAINER_slist_iter_destroy (it); | 1055 | GNUNET_CONTAINER_slist_iter_destroy (it); |
1017 | #endif | 1056 | #endif |
1018 | return GNUNET_NO; | 1057 | return GNUNET_NO; |
@@ -1027,6 +1066,7 @@ struct GNUNET_NETWORK_FDSet * | |||
1027 | GNUNET_NETWORK_fdset_create () | 1066 | GNUNET_NETWORK_fdset_create () |
1028 | { | 1067 | { |
1029 | struct GNUNET_NETWORK_FDSet *fds; | 1068 | struct GNUNET_NETWORK_FDSet *fds; |
1069 | |||
1030 | fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); | 1070 | fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); |
1031 | #ifdef MINGW | 1071 | #ifdef MINGW |
1032 | fds->handles = GNUNET_CONTAINER_slist_create (); | 1072 | fds->handles = GNUNET_CONTAINER_slist_create (); |
@@ -1064,6 +1104,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1064 | const struct GNUNET_TIME_Relative timeout) | 1104 | const struct GNUNET_TIME_Relative timeout) |
1065 | { | 1105 | { |
1066 | int nfds = 0; | 1106 | int nfds = 0; |
1107 | |||
1067 | #ifdef MINGW | 1108 | #ifdef MINGW |
1068 | int handles = 0; | 1109 | int handles = 0; |
1069 | int ex_handles = 0; | 1110 | int ex_handles = 0; |
@@ -1093,6 +1134,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1093 | struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except; | 1134 | struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except; |
1094 | 1135 | ||
1095 | fd_set aread, awrite, aexcept; | 1136 | fd_set aread, awrite, aexcept; |
1137 | |||
1096 | #if DEBUG_NETWORK | 1138 | #if DEBUG_NETWORK |
1097 | fd_set bread, bwrite, bexcept; | 1139 | fd_set bread, bwrite, bexcept; |
1098 | #endif | 1140 | #endif |
@@ -1103,62 +1145,67 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1103 | struct timeval tv; | 1145 | struct timeval tv; |
1104 | #endif | 1146 | #endif |
1105 | if (NULL != rfds) | 1147 | if (NULL != rfds) |
1106 | { | 1148 | { |
1107 | nfds = rfds->nsds; | 1149 | nfds = rfds->nsds; |
1108 | #ifdef MINGW | 1150 | #ifdef MINGW |
1109 | handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); | 1151 | handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); |
1110 | #if DEBUG_NETWORK | 1152 | #if DEBUG_NETWORK |
1153 | { | ||
1154 | struct GNUNET_CONTAINER_SList_Iterator *t; | ||
1155 | |||
1156 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | ||
1157 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | ||
1158 | GNUNET_CONTAINER_slist_next (t)) | ||
1111 | { | 1159 | { |
1112 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1160 | struct GNUNET_DISK_FileHandle *fh; |
1113 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1161 | |
1114 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1162 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, |
1115 | GNUNET_CONTAINER_slist_next (t)) | 1163 | NULL); |
1116 | { | 1164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", |
1117 | struct GNUNET_DISK_FileHandle *fh; | 1165 | fh->h, fh); |
1118 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | ||
1119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", fh->h, fh); | ||
1120 | } | ||
1121 | } | 1166 | } |
1167 | } | ||
1122 | #endif | 1168 | #endif |
1123 | #endif | 1169 | #endif |
1124 | } | 1170 | } |
1125 | if (NULL != wfds) | 1171 | if (NULL != wfds) |
1126 | { | 1172 | { |
1127 | nfds = GNUNET_MAX (nfds, wfds->nsds); | 1173 | nfds = GNUNET_MAX (nfds, wfds->nsds); |
1128 | #ifdef MINGW | 1174 | #ifdef MINGW |
1129 | handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); | 1175 | handles += write_handles = GNUNET_CONTAINER_slist_count (wfds->handles); |
1130 | #endif | 1176 | #endif |
1131 | } | 1177 | } |
1132 | if (NULL != efds) | 1178 | if (NULL != efds) |
1133 | { | 1179 | { |
1134 | nfds = GNUNET_MAX (nfds, efds->nsds); | 1180 | nfds = GNUNET_MAX (nfds, efds->nsds); |
1135 | #ifdef MINGW | 1181 | #ifdef MINGW |
1136 | handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); | 1182 | handles += ex_handles = GNUNET_CONTAINER_slist_count (efds->handles); |
1137 | #endif | 1183 | #endif |
1138 | } | 1184 | } |
1139 | 1185 | ||
1140 | if ((nfds == 0) && (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 1186 | if ((nfds == 0) && |
1187 | (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | ||
1141 | #ifdef MINGW | 1188 | #ifdef MINGW |
1142 | && handles == 0 | 1189 | && handles == 0 |
1143 | #endif | 1190 | #endif |
1144 | ) | 1191 | ) |
1145 | { | 1192 | { |
1146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1147 | _ | 1194 | _ |
1148 | ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), | 1195 | ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), |
1149 | "select"); | 1196 | "select"); |
1150 | GNUNET_break (0); | 1197 | GNUNET_break (0); |
1151 | } | 1198 | } |
1152 | #ifndef MINGW | 1199 | #ifndef MINGW |
1153 | tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; | 1200 | tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value; |
1154 | tv.tv_usec = | 1201 | tv.tv_usec = |
1155 | 1000 * (timeout.rel_value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); | 1202 | 1000 * (timeout.rel_value - |
1156 | return select (nfds, | 1203 | (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value)); |
1157 | (rfds != NULL) ? &rfds->sds : NULL, | 1204 | return select (nfds, (rfds != NULL) ? &rfds->sds : NULL, |
1158 | (wfds != NULL) ? &wfds->sds : NULL, | 1205 | (wfds != NULL) ? &wfds->sds : NULL, |
1159 | (efds != NULL) ? &efds->sds : NULL, | 1206 | (efds != NULL) ? &efds->sds : NULL, |
1160 | (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 1207 | (timeout.rel_value == |
1161 | ? NULL : &tv); | 1208 | GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ? NULL : &tv); |
1162 | 1209 | ||
1163 | #else | 1210 | #else |
1164 | #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) | 1211 | #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) |
@@ -1169,10 +1216,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1169 | ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; | 1216 | ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value; |
1170 | /* select() may be used as a portable way to sleep */ | 1217 | /* select() may be used as a portable way to sleep */ |
1171 | if (!(rfds || wfds || efds)) | 1218 | if (!(rfds || wfds || efds)) |
1172 | { | 1219 | { |
1173 | Sleep (ms_total); | 1220 | Sleep (ms_total); |
1174 | return 0; | 1221 | return 0; |
1175 | } | 1222 | } |
1176 | 1223 | ||
1177 | /* Events for sockets */ | 1224 | /* Events for sockets */ |
1178 | if (!hEventRead) | 1225 | if (!hEventRead) |
@@ -1195,7 +1242,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1195 | hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL); | 1242 | hEventPipeWrite = CreateEvent (NULL, TRUE, TRUE, NULL); |
1196 | readPipes = 0; | 1243 | readPipes = 0; |
1197 | writePipePos = -1; | 1244 | writePipePos = -1; |
1198 | 1245 | ||
1199 | handles_read = GNUNET_CONTAINER_slist_create (); | 1246 | handles_read = GNUNET_CONTAINER_slist_create (); |
1200 | handles_write = GNUNET_CONTAINER_slist_create (); | 1247 | handles_write = GNUNET_CONTAINER_slist_create (); |
1201 | handles_except = GNUNET_CONTAINER_slist_create (); | 1248 | handles_except = GNUNET_CONTAINER_slist_create (); |
@@ -1233,40 +1280,49 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1233 | if (rfds && read_handles) | 1280 | if (rfds && read_handles) |
1234 | { | 1281 | { |
1235 | struct GNUNET_CONTAINER_SList_Iterator *i; | 1282 | struct GNUNET_CONTAINER_SList_Iterator *i; |
1283 | |||
1236 | for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1284 | for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1237 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; | 1285 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; |
1238 | GNUNET_CONTAINER_slist_next (i)) | 1286 | GNUNET_CONTAINER_slist_next (i)) |
1239 | { | 1287 | { |
1240 | struct GNUNET_DISK_FileHandle *fh; | 1288 | struct GNUNET_DISK_FileHandle *fh; |
1241 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, NULL); | 1289 | |
1290 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, | ||
1291 | NULL); | ||
1242 | if (fh->type == GNUNET_PIPE) | 1292 | if (fh->type == GNUNET_PIPE) |
1243 | { | 1293 | { |
1244 | /* Read zero bytes to check the status of the pipe */ | 1294 | /* Read zero bytes to check the status of the pipe */ |
1245 | #if DEBUG_NETWORK | 1295 | #if DEBUG_NETWORK |
1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reading 0 bytes from the pipe 0x%x\n", fh->h); | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1297 | "Reading 0 bytes from the pipe 0x%x\n", fh->h); | ||
1247 | #endif | 1298 | #endif |
1248 | if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) | 1299 | if (!ReadFile (fh->h, NULL, 0, NULL, fh->oOverlapRead)) |
1249 | { | 1300 | { |
1250 | DWORD error_code = GetLastError(); | 1301 | DWORD error_code = GetLastError (); |
1302 | |||
1251 | if (error_code == ERROR_IO_PENDING) | 1303 | if (error_code == ERROR_IO_PENDING) |
1252 | { | 1304 | { |
1253 | #if DEBUG_NETWORK | 1305 | #if DEBUG_NETWORK |
1254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the pipe's 0x%x overlapped event to the array as %d\n", fh->h, nhandles); | 1306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1307 | "Adding the pipe's 0x%x overlapped event to the array as %d\n", | ||
1308 | fh->h, nhandles); | ||
1255 | #endif | 1309 | #endif |
1256 | handle_array[nhandles++] = fh->oOverlapRead->hEvent; | 1310 | handle_array[nhandles++] = fh->oOverlapRead->hEvent; |
1257 | readArray[readPipes++] = fh; | 1311 | readArray[readPipes++] = fh; |
1258 | } | 1312 | } |
1259 | /* | 1313 | /* |
1260 | else | 1314 | * else |
1261 | { | 1315 | * { |
1262 | SetErrnoFromWinError (error_code); | 1316 | * SetErrnoFromWinError (error_code); |
1263 | } | 1317 | * } |
1264 | */ | 1318 | */ |
1265 | } | 1319 | } |
1266 | else | 1320 | else |
1267 | { | 1321 | { |
1268 | #if DEBUG_NETWORK | 1322 | #if DEBUG_NETWORK |
1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the read ready event to the array as %d\n", nhandles); | 1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1324 | "Adding the read ready event to the array as %d\n", | ||
1325 | nhandles); | ||
1270 | #endif | 1326 | #endif |
1271 | handle_array[nhandles++] = hEventReadReady; | 1327 | handle_array[nhandles++] = hEventReadReady; |
1272 | readArray[readPipes++] = fh; | 1328 | readArray[readPipes++] = fh; |
@@ -1275,8 +1331,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1275 | else | 1331 | else |
1276 | { | 1332 | { |
1277 | GNUNET_CONTAINER_slist_add (handles_read, | 1333 | GNUNET_CONTAINER_slist_add (handles_read, |
1278 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1334 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1279 | fh, sizeof (struct GNUNET_DISK_FileHandle)); | 1335 | fh, sizeof (struct GNUNET_DISK_FileHandle)); |
1280 | } | 1336 | } |
1281 | } | 1337 | } |
1282 | GNUNET_CONTAINER_slist_iter_destroy (i); | 1338 | GNUNET_CONTAINER_slist_iter_destroy (i); |
@@ -1284,7 +1340,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1284 | if (wfds && write_handles) | 1340 | if (wfds && write_handles) |
1285 | { | 1341 | { |
1286 | #if DEBUG_NETWORK | 1342 | #if DEBUG_NETWORK |
1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the write ready event to the array as %d\n", nhandles); | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1344 | "Adding the write ready event to the array as %d\n", nhandles); | ||
1288 | #endif | 1345 | #endif |
1289 | handle_array[nhandles++] = hEventPipeWrite; | 1346 | handle_array[nhandles++] = hEventPipeWrite; |
1290 | writePipePos = nhandles; | 1347 | writePipePos = nhandles; |
@@ -1292,21 +1349,24 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1292 | if (efds && ex_handles) | 1349 | if (efds && ex_handles) |
1293 | { | 1350 | { |
1294 | struct GNUNET_CONTAINER_SList_Iterator *i; | 1351 | struct GNUNET_CONTAINER_SList_Iterator *i; |
1352 | |||
1295 | for (i = GNUNET_CONTAINER_slist_begin (efds->handles); | 1353 | for (i = GNUNET_CONTAINER_slist_begin (efds->handles); |
1296 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; | 1354 | GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; |
1297 | GNUNET_CONTAINER_slist_next (i)) | 1355 | GNUNET_CONTAINER_slist_next (i)) |
1298 | { | 1356 | { |
1299 | struct GNUNET_DISK_FileHandle *fh; | 1357 | struct GNUNET_DISK_FileHandle *fh; |
1300 | DWORD dwBytes; | 1358 | DWORD dwBytes; |
1301 | 1359 | ||
1302 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, NULL); | 1360 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, |
1361 | NULL); | ||
1303 | if (fh->type == GNUNET_PIPE) | 1362 | if (fh->type == GNUNET_PIPE) |
1304 | { | 1363 | { |
1305 | if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) | 1364 | if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL)) |
1306 | { | 1365 | { |
1307 | GNUNET_CONTAINER_slist_add (handles_except, | 1366 | GNUNET_CONTAINER_slist_add (handles_except, |
1308 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1367 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1309 | fh, sizeof (struct GNUNET_DISK_FileHandle)); | 1368 | fh, |
1369 | sizeof (struct GNUNET_DISK_FileHandle)); | ||
1310 | newretcode++; | 1370 | newretcode++; |
1311 | } | 1371 | } |
1312 | } | 1372 | } |
@@ -1318,21 +1378,27 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1318 | if (rfds) | 1378 | if (rfds) |
1319 | { | 1379 | { |
1320 | #if DEBUG_NETWORK | 1380 | #if DEBUG_NETWORK |
1321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket read event to the array as %d\n", nhandles); | 1381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1382 | "Adding the socket read event to the array as %d\n", | ||
1383 | nhandles); | ||
1322 | #endif | 1384 | #endif |
1323 | handle_array[nhandles++] = hEventRead; | 1385 | handle_array[nhandles++] = hEventRead; |
1324 | nSockEvents++; | 1386 | nSockEvents++; |
1325 | for (i = 0; i < rfds->sds.fd_count; i++) | 1387 | for (i = 0; i < rfds->sds.fd_count; i++) |
1326 | { | 1388 | { |
1327 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, FD_ACCEPT | FD_READ | FD_CLOSE); | 1389 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, |
1390 | FD_ACCEPT | FD_READ | FD_CLOSE); | ||
1328 | nsock++; | 1391 | nsock++; |
1329 | } | 1392 | } |
1330 | } | 1393 | } |
1331 | if (wfds) | 1394 | if (wfds) |
1332 | { | 1395 | { |
1333 | int wakeup = 0; | 1396 | int wakeup = 0; |
1397 | |||
1334 | #if DEBUG_NETWORK | 1398 | #if DEBUG_NETWORK |
1335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket write event to the array as %d\n", nhandles); | 1399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1400 | "Adding the socket write event to the array as %d\n", | ||
1401 | nhandles); | ||
1336 | #endif | 1402 | #endif |
1337 | handle_array[nhandles++] = hEventWrite; | 1403 | handle_array[nhandles++] = hEventWrite; |
1338 | nSockEvents++; | 1404 | nSockEvents++; |
@@ -1340,14 +1406,18 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1340 | { | 1406 | { |
1341 | DWORD error; | 1407 | DWORD error; |
1342 | int status; | 1408 | int status; |
1409 | |||
1343 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | 1410 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); |
1344 | error = GetLastError (); | 1411 | error = GetLastError (); |
1345 | #if DEBUG_NETWORK | 1412 | #if DEBUG_NETWORK |
1346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-send to the socket %d returned %d (%u)\n", i, status, error); | 1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1414 | "pre-send to the socket %d returned %d (%u)\n", i, status, | ||
1415 | error); | ||
1347 | #endif | 1416 | #endif |
1348 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) | 1417 | if (status == 0 || (error != WSAEWOULDBLOCK && error != WSAENOTCONN)) |
1349 | wakeup = 1; | 1418 | wakeup = 1; |
1350 | WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, FD_WRITE | FD_CONNECT | FD_CLOSE); | 1419 | WSAEventSelect (wfds->sds.fd_array[i], hEventWrite, |
1420 | FD_WRITE | FD_CONNECT | FD_CLOSE); | ||
1351 | nsock++; | 1421 | nsock++; |
1352 | } | 1422 | } |
1353 | if (wakeup) | 1423 | if (wakeup) |
@@ -1356,13 +1426,16 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1356 | if (efds) | 1426 | if (efds) |
1357 | { | 1427 | { |
1358 | #if DEBUG_NETWORK | 1428 | #if DEBUG_NETWORK |
1359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding the socket error event to the array as %d\n", nhandles); | 1429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1430 | "Adding the socket error event to the array as %d\n", | ||
1431 | nhandles); | ||
1360 | #endif | 1432 | #endif |
1361 | handle_array[nhandles++] = hEventException; | 1433 | handle_array[nhandles++] = hEventException; |
1362 | nSockEvents++; | 1434 | nSockEvents++; |
1363 | for (i = 0; i < efds->sds.fd_count; i++) | 1435 | for (i = 0; i < efds->sds.fd_count; i++) |
1364 | { | 1436 | { |
1365 | WSAEventSelect (efds->sds.fd_array[i], hEventException, FD_OOB | FD_CLOSE); | 1437 | WSAEventSelect (efds->sds.fd_array[i], hEventException, |
1438 | FD_OOB | FD_CLOSE); | ||
1366 | nsock++; | 1439 | nsock++; |
1367 | } | 1440 | } |
1368 | } | 1441 | } |
@@ -1378,11 +1451,13 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1378 | #endif | 1451 | #endif |
1379 | 1452 | ||
1380 | if (nhandles) | 1453 | if (nhandles) |
1381 | returncode = WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); | 1454 | returncode = |
1455 | WaitForMultipleObjects (nhandles, handle_array, FALSE, ms_total); | ||
1382 | #if DEBUG_NETWORK | 1456 | #if DEBUG_NETWORK |
1383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", returncode); | 1457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WaitForMultipleObjects Returned : %d\n", |
1458 | returncode); | ||
1384 | #endif | 1459 | #endif |
1385 | 1460 | ||
1386 | returnedpos = returncode - WAIT_OBJECT_0; | 1461 | returnedpos = returncode - WAIT_OBJECT_0; |
1387 | #if DEBUG_NETWORK | 1462 | #if DEBUG_NETWORK |
1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos); | 1463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return pos is : %d\n", returnedpos); |
@@ -1390,16 +1465,18 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1390 | 1465 | ||
1391 | /* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that fired the events, not all ! */ | 1466 | /* FIXME: THIS LINE IS WRONG !! We should add to handles only handles that fired the events, not all ! */ |
1392 | /* | 1467 | /* |
1393 | if(rfds) | 1468 | * if(rfds) |
1394 | GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); | 1469 | * GNUNET_CONTAINER_slist_append (handles_read, rfds->handles); |
1395 | */ | 1470 | */ |
1396 | if (nhandles && (returnedpos < nhandles)) | 1471 | if (nhandles && (returnedpos < nhandles)) |
1397 | { | 1472 | { |
1398 | DWORD waitstatus; | 1473 | DWORD waitstatus; |
1474 | |||
1399 | /* Do the select */ | 1475 | /* Do the select */ |
1400 | if (nfds) | 1476 | if (nfds) |
1401 | { | 1477 | { |
1402 | struct timeval tvslice; | 1478 | struct timeval tvslice; |
1479 | |||
1403 | tvslice.tv_sec = 0; | 1480 | tvslice.tv_sec = 0; |
1404 | tvslice.tv_usec = 10; | 1481 | tvslice.tv_usec = 10; |
1405 | retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); | 1482 | retcode = select (nfds, &aread, &awrite, &aexcept, &tvslice); |
@@ -1423,48 +1500,55 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1423 | #endif | 1500 | #endif |
1424 | /* We have some pipes ready for read. */ | 1501 | /* We have some pipes ready for read. */ |
1425 | /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ | 1502 | /* FIXME: it is supposed to work !! Only choose the Pipes who fired the event, but it is not working */ |
1426 | 1503 | ||
1427 | if (returnedpos < readPipes) | 1504 | if (returnedpos < readPipes) |
1428 | { | 1505 | { |
1429 | /* | 1506 | /* |
1430 | for (i = 0; i < readPipes; i++) | 1507 | * for (i = 0; i < readPipes; i++) |
1431 | { | 1508 | * { |
1432 | waitstatus = WaitForSingleObject (handle_array[i], 0); | 1509 | * waitstatus = WaitForSingleObject (handle_array[i], 0); |
1433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); | 1510 | * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read pipe %d wait status is : %d\n", i, waitstatus); |
1434 | if (waitstatus != WAIT_OBJECT_0) | 1511 | * if (waitstatus != WAIT_OBJECT_0) |
1435 | continue; | 1512 | * continue; |
1436 | GNUNET_CONTAINER_slist_add (handles_read, | 1513 | * GNUNET_CONTAINER_slist_add (handles_read, |
1437 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1514 | * GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1438 | readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); | 1515 | * readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); |
1439 | retcode++; | 1516 | * retcode++; |
1440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); | 1517 | * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe\n"); |
1441 | } | 1518 | * } |
1442 | */ | 1519 | */ |
1443 | for (i = 0; i < readPipes; i++) | 1520 | for (i = 0; i < readPipes; i++) |
1444 | { | 1521 | { |
1445 | DWORD error; | 1522 | DWORD error; |
1446 | BOOL bret; | 1523 | BOOL bret; |
1524 | |||
1447 | SetLastError (0); | 1525 | SetLastError (0); |
1448 | waitstatus = 0; | 1526 | waitstatus = 0; |
1449 | bret = PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL); | 1527 | bret = |
1528 | PeekNamedPipe (readArray[i]->h, NULL, 0, NULL, &waitstatus, NULL); | ||
1450 | error = GetLastError (); | 1529 | error = GetLastError (); |
1451 | #if DEBUG_NETWORK | 1530 | #if DEBUG_NETWORK |
1452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", i, readArray[i]->h, bret, waitstatus, error); | 1531 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1532 | "Peek at read pipe %d (0x%x) returned %d (%d bytes available) GLE %u\n", | ||
1533 | i, readArray[i]->h, bret, waitstatus, error); | ||
1453 | #endif | 1534 | #endif |
1454 | if (bret == 0 || waitstatus <= 0) | 1535 | if (bret == 0 || waitstatus <= 0) |
1455 | continue; | 1536 | continue; |
1456 | GNUNET_CONTAINER_slist_add (handles_read, | 1537 | GNUNET_CONTAINER_slist_add (handles_read, |
1457 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 1538 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
1458 | readArray[i], sizeof (struct GNUNET_DISK_FileHandle)); | 1539 | readArray[i], |
1540 | sizeof (struct GNUNET_DISK_FileHandle)); | ||
1459 | retcode++; | 1541 | retcode++; |
1460 | #if DEBUG_NETWORK | 1542 | #if DEBUG_NETWORK |
1461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", readArray[i], readArray[i]->h); | 1543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added read Pipe 0x%x (0x%x)\n", |
1544 | readArray[i], readArray[i]->h); | ||
1462 | #endif | 1545 | #endif |
1463 | } | 1546 | } |
1464 | } | 1547 | } |
1465 | waitstatus = WaitForSingleObject (hEventWrite, 0); | 1548 | waitstatus = WaitForSingleObject (hEventWrite, 0); |
1466 | #if DEBUG_NETWORK | 1549 | #if DEBUG_NETWORK |
1467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wait for the write event returned %d\n", waitstatus); | 1550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1551 | "Wait for the write event returned %d\n", waitstatus); | ||
1468 | #endif | 1552 | #endif |
1469 | if (waitstatus == WAIT_OBJECT_0) | 1553 | if (waitstatus == WAIT_OBJECT_0) |
1470 | { | 1554 | { |
@@ -1474,15 +1558,21 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1474 | int status; | 1558 | int status; |
1475 | int so_error = 0; | 1559 | int so_error = 0; |
1476 | int sizeof_so_error = sizeof (so_error); | 1560 | int sizeof_so_error = sizeof (so_error); |
1477 | int gso_result = getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, (char *) &so_error, &sizeof_so_error); | 1561 | int gso_result = |
1562 | getsockopt (wfds->sds.fd_array[i], SOL_SOCKET, SO_ERROR, | ||
1563 | (char *) &so_error, &sizeof_so_error); | ||
1564 | |||
1478 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); | 1565 | status = send (wfds->sds.fd_array[i], NULL, 0, 0); |
1479 | error = GetLastError (); | 1566 | error = GetLastError (); |
1480 | #if DEBUG_NETWORK | 1567 | #if DEBUG_NETWORK |
1481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send to the socket %d returned %d (%u)\n", i, status, error); | 1568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1569 | "send to the socket %d returned %d (%u)\n", i, status, | ||
1570 | error); | ||
1482 | #endif | 1571 | #endif |
1483 | if (status == 0 | 1572 | if (status == 0 |
1484 | || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) | 1573 | || (error != WSAEWOULDBLOCK && error != WSAENOTCONN) |
1485 | || (status == -1 && gso_result == 0 && error == WSAENOTCONN && so_error == WSAECONNREFUSED)) | 1574 | || (status == -1 && gso_result == 0 && error == WSAENOTCONN && |
1575 | so_error == WSAECONNREFUSED)) | ||
1486 | { | 1576 | { |
1487 | FD_SET (wfds->sds.fd_array[i], &awrite); | 1577 | FD_SET (wfds->sds.fd_array[i], &awrite); |
1488 | retcode += 1; | 1578 | retcode += 1; |
@@ -1492,22 +1582,26 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1492 | } | 1582 | } |
1493 | #if DEBUG_NETWORK | 1583 | #if DEBUG_NETWORK |
1494 | if (!nhandles || (returnedpos >= nhandles)) | 1584 | if (!nhandles || (returnedpos >= nhandles)) |
1495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning from _select() with nothing!\n"); | 1585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1586 | "Returning from _select() with nothing!\n"); | ||
1496 | #endif | 1587 | #endif |
1497 | if (rfds) | 1588 | if (rfds) |
1498 | { | 1589 | { |
1499 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1590 | struct GNUNET_CONTAINER_SList_Iterator *t; |
1591 | |||
1500 | for (i = 0; i < rfds->sds.fd_count; i++) | 1592 | for (i = 0; i < rfds->sds.fd_count; i++) |
1501 | { | 1593 | { |
1502 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); | 1594 | WSAEventSelect (rfds->sds.fd_array[i], hEventRead, 0); |
1503 | nsock++; | 1595 | nsock++; |
1504 | } | 1596 | } |
1505 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1597 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1506 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1598 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
1507 | GNUNET_CONTAINER_slist_next (t)) | 1599 | GNUNET_CONTAINER_slist_next (t)) |
1508 | { | 1600 | { |
1509 | struct GNUNET_DISK_FileHandle *fh; | 1601 | struct GNUNET_DISK_FileHandle *fh; |
1510 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 1602 | |
1603 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, | ||
1604 | NULL); | ||
1511 | if (fh->type == GNUNET_PIPE) | 1605 | if (fh->type == GNUNET_PIPE) |
1512 | { | 1606 | { |
1513 | CancelIo (fh->h); | 1607 | CancelIo (fh->h); |
@@ -1559,17 +1653,23 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1559 | if (rfds) | 1653 | if (rfds) |
1560 | { | 1654 | { |
1561 | struct GNUNET_CONTAINER_SList_Iterator *t; | 1655 | struct GNUNET_CONTAINER_SList_Iterator *t; |
1656 | |||
1562 | for (i = 0; i < bread.fd_count; i++) | 1657 | for (i = 0; i < bread.fd_count; i++) |
1563 | { | 1658 | { |
1564 | if (bread.fd_array[i] != 0) | 1659 | if (bread.fd_array[i] != 0) |
1565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", bread.fd_array[i], (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : "NOT SET"); | 1660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in rfds\n", |
1661 | bread.fd_array[i], | ||
1662 | (SAFE_FD_ISSET (bread.fd_array[i], rfds)) ? "SET" : | ||
1663 | "NOT SET"); | ||
1566 | } | 1664 | } |
1567 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); | 1665 | for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); |
1568 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; | 1666 | GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; |
1569 | GNUNET_CONTAINER_slist_next (t)) | 1667 | GNUNET_CONTAINER_slist_next (t)) |
1570 | { | 1668 | { |
1571 | struct GNUNET_DISK_FileHandle *fh; | 1669 | struct GNUNET_DISK_FileHandle *fh; |
1572 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, NULL); | 1670 | |
1671 | fh = (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, | ||
1672 | NULL); | ||
1573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); | 1673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); |
1574 | } | 1674 | } |
1575 | } | 1675 | } |
@@ -1578,7 +1678,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1578 | for (i = 0; i < bwrite.fd_count; i++) | 1678 | for (i = 0; i < bwrite.fd_count; i++) |
1579 | { | 1679 | { |
1580 | if (bwrite.fd_array[i] != 0) | 1680 | if (bwrite.fd_array[i] != 0) |
1581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", bwrite.fd_array[i], (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : "NOT SET"); | 1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in wfds\n", |
1682 | bwrite.fd_array[i], | ||
1683 | (SAFE_FD_ISSET (bwrite.fd_array[i], rfds)) ? "SET" : | ||
1684 | "NOT SET"); | ||
1582 | } | 1685 | } |
1583 | } | 1686 | } |
1584 | if (efds) | 1687 | if (efds) |
@@ -1586,7 +1689,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1586 | for (i = 0; i < bexcept.fd_count; i++) | 1689 | for (i = 0; i < bexcept.fd_count; i++) |
1587 | { | 1690 | { |
1588 | if (bexcept.fd_array[i] != 0) | 1691 | if (bexcept.fd_array[i] != 0) |
1589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", bexcept.fd_array[i], (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : "NOT SET"); | 1692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is %s in efds\n", |
1693 | bexcept.fd_array[i], | ||
1694 | (SAFE_FD_ISSET (bexcept.fd_array[i], rfds)) ? "SET" : | ||
1695 | "NOT SET"); | ||
1590 | } | 1696 | } |
1591 | } | 1697 | } |
1592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); | 1698 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning %d or 0\n", retcode); |
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 36627a8d8..188401abb 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -51,25 +51,21 @@ get_path_from_proc_maps () | |||
51 | FILE *f; | 51 | FILE *f; |
52 | char *lgu; | 52 | char *lgu; |
53 | 53 | ||
54 | GNUNET_snprintf (fn, | 54 | GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ()); |
55 | sizeof(fn), | ||
56 | "/proc/%u/maps", | ||
57 | getpid ()); | ||
58 | f = fopen (fn, "r"); | 55 | f = fopen (fn, "r"); |
59 | if (f == NULL) | 56 | if (f == NULL) |
60 | return NULL; | 57 | return NULL; |
61 | while (NULL != fgets (line, sizeof(line), f)) | 58 | while (NULL != fgets (line, sizeof (line), f)) |
59 | { | ||
60 | if ((1 == sscanf (line, | ||
61 | "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", | ||
62 | dir)) && (NULL != (lgu = strstr (dir, "libgnunetutil")))) | ||
62 | { | 63 | { |
63 | if ((1 == sscanf (line, | 64 | lgu[0] = '\0'; |
64 | "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", | 65 | fclose (f); |
65 | dir)) && | 66 | return GNUNET_strdup (dir); |
66 | (NULL != (lgu = strstr (dir, "libgnunetutil")))) | ||
67 | { | ||
68 | lgu[0] = '\0'; | ||
69 | fclose (f); | ||
70 | return GNUNET_strdup (dir); | ||
71 | } | ||
72 | } | 67 | } |
68 | } | ||
73 | fclose (f); | 69 | fclose (f); |
74 | return NULL; | 70 | return NULL; |
75 | } | 71 | } |
@@ -84,23 +80,22 @@ get_path_from_proc_exe () | |||
84 | char lnk[1024]; | 80 | char lnk[1024]; |
85 | ssize_t size; | 81 | ssize_t size; |
86 | 82 | ||
87 | GNUNET_snprintf (fn, | 83 | GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); |
88 | sizeof(fn), "/proc/%u/exe", getpid ()); | 84 | size = readlink (fn, lnk, sizeof (lnk) - 1); |
89 | size = readlink (fn, lnk, sizeof (lnk)-1); | ||
90 | if (size <= 0) | 85 | if (size <= 0) |
91 | { | 86 | { |
92 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); | 87 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); |
93 | return NULL; | 88 | return NULL; |
94 | } | 89 | } |
95 | GNUNET_assert (size < sizeof (lnk)); | 90 | GNUNET_assert (size < sizeof (lnk)); |
96 | lnk[size] = '\0'; | 91 | lnk[size] = '\0'; |
97 | while ((lnk[size] != '/') && (size > 0)) | 92 | while ((lnk[size] != '/') && (size > 0)) |
98 | size--; | 93 | size--; |
99 | if ((size < 4) || (lnk[size - 4] != '/')) | 94 | if ((size < 4) || (lnk[size - 4] != '/')) |
100 | { | 95 | { |
101 | /* not installed in "/bin/" -- binary path probably useless */ | 96 | /* not installed in "/bin/" -- binary path probably useless */ |
102 | return NULL; | 97 | return NULL; |
103 | } | 98 | } |
104 | lnk[size] = '\0'; | 99 | lnk[size] = '\0'; |
105 | return GNUNET_strdup (lnk); | 100 | return GNUNET_strdup (lnk); |
106 | } | 101 | } |
@@ -116,7 +111,7 @@ get_path_from_module_filename () | |||
116 | char path[4097]; | 111 | char path[4097]; |
117 | char *idx; | 112 | char *idx; |
118 | 113 | ||
119 | GetModuleFileName (NULL, path, sizeof(path)-1); | 114 | GetModuleFileName (NULL, path, sizeof (path) - 1); |
120 | idx = path + strlen (path); | 115 | idx = path + strlen (path); |
121 | while ((idx > path) && (*idx != '\\') && (*idx != '/')) | 116 | while ((idx > path) && (*idx != '\\') && (*idx != '/')) |
122 | idx--; | 117 | idx--; |
@@ -139,7 +134,7 @@ get_path_from_NSGetExecutablePath () | |||
139 | 134 | ||
140 | path = NULL; | 135 | path = NULL; |
141 | func = | 136 | func = |
142 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); | 137 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); |
143 | if (!func) | 138 | if (!func) |
144 | return NULL; | 139 | return NULL; |
145 | path = &zero; | 140 | path = &zero; |
@@ -151,10 +146,10 @@ get_path_from_NSGetExecutablePath () | |||
151 | path = GNUNET_malloc (len); | 146 | path = GNUNET_malloc (len); |
152 | ret = func (path, &len); | 147 | ret = func (path, &len); |
153 | if (ret != 0) | 148 | if (ret != 0) |
154 | { | 149 | { |
155 | GNUNET_free (path); | 150 | GNUNET_free (path); |
156 | return NULL; | 151 | return NULL; |
157 | } | 152 | } |
158 | len = strlen (path); | 153 | len = strlen (path); |
159 | while ((path[len] != '/') && (len > 0)) | 154 | while ((path[len] != '/') && (len > 0)) |
160 | len--; | 155 | len--; |
@@ -173,22 +168,22 @@ get_path_from_dyld_image () | |||
173 | p = NULL; | 168 | p = NULL; |
174 | c = _dyld_image_count (); | 169 | c = _dyld_image_count (); |
175 | for (i = 0; i < c; i++) | 170 | for (i = 0; i < c; i++) |
171 | { | ||
172 | if (_dyld_get_image_header (i) == &_mh_dylib_header) | ||
176 | { | 173 | { |
177 | if (_dyld_get_image_header (i) == &_mh_dylib_header) | 174 | path = _dyld_get_image_name (i); |
178 | { | 175 | if (path != NULL && strlen (path) > 0) |
179 | path = _dyld_get_image_name (i); | 176 | { |
180 | if (path != NULL && strlen (path) > 0) | 177 | p = strdup (path); |
181 | { | 178 | s = p + strlen (p); |
182 | p = strdup (path); | 179 | while ((s > p) && (*s != '/')) |
183 | s = p + strlen (p); | 180 | s--; |
184 | while ((s > p) && (*s != '/')) | 181 | s++; |
185 | s--; | 182 | *s = '\0'; |
186 | s++; | 183 | } |
187 | *s = '\0'; | 184 | break; |
188 | } | ||
189 | break; | ||
190 | } | ||
191 | } | 185 | } |
186 | } | ||
192 | return p; | 187 | return p; |
193 | } | 188 | } |
194 | #endif | 189 | #endif |
@@ -214,28 +209,28 @@ get_path_from_PATH (const char *binary) | |||
214 | return NULL; | 209 | return NULL; |
215 | path = GNUNET_strdup (p); /* because we write on it */ | 210 | path = GNUNET_strdup (p); /* because we write on it */ |
216 | buf = GNUNET_malloc (strlen (path) + 20); | 211 | buf = GNUNET_malloc (strlen (path) + 20); |
217 | pos = path; | 212 | pos = path; |
218 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) | 213 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) |
219 | { | 214 | { |
220 | *end = '\0'; | 215 | *end = '\0'; |
221 | sprintf (buf, "%s/%s", pos, binary); | 216 | sprintf (buf, "%s/%s", pos, binary); |
222 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | 217 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) |
223 | { | ||
224 | pos = GNUNET_strdup (pos); | ||
225 | GNUNET_free (buf); | ||
226 | GNUNET_free (path); | ||
227 | return pos; | ||
228 | } | ||
229 | pos = end + 1; | ||
230 | } | ||
231 | sprintf (buf, "%s/%s", pos, binary); | ||
232 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
233 | { | 218 | { |
234 | pos = GNUNET_strdup (pos); | 219 | pos = GNUNET_strdup (pos); |
235 | GNUNET_free (buf); | 220 | GNUNET_free (buf); |
236 | GNUNET_free (path); | 221 | GNUNET_free (path); |
237 | return pos; | 222 | return pos; |
238 | } | 223 | } |
224 | pos = end + 1; | ||
225 | } | ||
226 | sprintf (buf, "%s/%s", pos, binary); | ||
227 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
228 | { | ||
229 | pos = GNUNET_strdup (pos); | ||
230 | GNUNET_free (buf); | ||
231 | GNUNET_free (path); | ||
232 | return pos; | ||
233 | } | ||
239 | GNUNET_free (buf); | 234 | GNUNET_free (buf); |
240 | GNUNET_free (path); | 235 | GNUNET_free (path); |
241 | return NULL; | 236 | return NULL; |
@@ -294,8 +289,7 @@ os_get_gnunet_path () | |||
294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 289 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
295 | _ | 290 | _ |
296 | ("Could not determine installation path for %s. Set `%s' environment variable.\n"), | 291 | ("Could not determine installation path for %s. Set `%s' environment variable.\n"), |
297 | "GNUnet", | 292 | "GNUnet", "GNUNET_PREFIX"); |
298 | "GNUNET_PREFIX"); | ||
299 | return NULL; | 293 | return NULL; |
300 | } | 294 | } |
301 | 295 | ||
@@ -361,11 +355,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
361 | 355 | ||
362 | n = strlen (execpath); | 356 | n = strlen (execpath); |
363 | if (n == 0) | 357 | if (n == 0) |
364 | { | 358 | { |
365 | /* should never happen, but better safe than sorry */ | 359 | /* should never happen, but better safe than sorry */ |
366 | GNUNET_free (execpath); | 360 | GNUNET_free (execpath); |
367 | return NULL; | 361 | return NULL; |
368 | } | 362 | } |
369 | /* remove filename itself */ | 363 | /* remove filename itself */ |
370 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 364 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
371 | execpath[--n] = '\0'; | 365 | execpath[--n] = '\0'; |
@@ -374,62 +368,59 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
374 | if ((n > 5) && | 368 | if ((n > 5) && |
375 | ((0 == strcasecmp (&execpath[n - 5], "lib32")) || | 369 | ((0 == strcasecmp (&execpath[n - 5], "lib32")) || |
376 | (0 == strcasecmp (&execpath[n - 5], "lib64")))) | 370 | (0 == strcasecmp (&execpath[n - 5], "lib64")))) |
371 | { | ||
372 | if (dirkind != GNUNET_OS_IPK_LIBDIR) | ||
377 | { | 373 | { |
378 | if (dirkind != GNUNET_OS_IPK_LIBDIR) | 374 | /* strip '/lib32' or '/lib64' */ |
379 | { | 375 | execpath[n - 5] = '\0'; |
380 | /* strip '/lib32' or '/lib64' */ | 376 | n -= 5; |
381 | execpath[n - 5] = '\0'; | ||
382 | n -= 5; | ||
383 | } | ||
384 | else | ||
385 | isbasedir = 0; | ||
386 | } | 377 | } |
378 | else | ||
379 | isbasedir = 0; | ||
380 | } | ||
387 | else if ((n > 3) && | 381 | else if ((n > 3) && |
388 | ((0 == strcasecmp (&execpath[n - 3], "bin")) || | 382 | ((0 == strcasecmp (&execpath[n - 3], "bin")) || |
389 | (0 == strcasecmp (&execpath[n - 3], "lib")))) | 383 | (0 == strcasecmp (&execpath[n - 3], "lib")))) |
390 | { | 384 | { |
391 | /* strip '/bin' or '/lib' */ | 385 | /* strip '/bin' or '/lib' */ |
392 | execpath[n - 3] = '\0'; | 386 | execpath[n - 3] = '\0'; |
393 | n -= 3; | 387 | n -= 3; |
394 | } | 388 | } |
395 | /* in case this was a directory named foo-bin, remove "foo-" */ | 389 | /* in case this was a directory named foo-bin, remove "foo-" */ |
396 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 390 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
397 | execpath[--n] = '\0'; | 391 | execpath[--n] = '\0'; |
398 | switch (dirkind) | 392 | switch (dirkind) |
399 | { | 393 | { |
400 | case GNUNET_OS_IPK_PREFIX: | 394 | case GNUNET_OS_IPK_PREFIX: |
401 | case GNUNET_OS_IPK_SELF_PREFIX: | 395 | case GNUNET_OS_IPK_SELF_PREFIX: |
402 | dirname = DIR_SEPARATOR_STR; | 396 | dirname = DIR_SEPARATOR_STR; |
403 | break; | 397 | break; |
404 | case GNUNET_OS_IPK_BINDIR: | 398 | case GNUNET_OS_IPK_BINDIR: |
405 | dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; | 399 | dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; |
406 | break; | 400 | break; |
407 | case GNUNET_OS_IPK_LIBDIR: | 401 | case GNUNET_OS_IPK_LIBDIR: |
408 | if (isbasedir) | 402 | if (isbasedir) |
409 | dirname = | ||
410 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" | ||
411 | DIR_SEPARATOR_STR; | ||
412 | else | ||
413 | dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
414 | break; | ||
415 | case GNUNET_OS_IPK_DATADIR: | ||
416 | dirname = | ||
417 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" | ||
418 | DIR_SEPARATOR_STR; | ||
419 | break; | ||
420 | case GNUNET_OS_IPK_LOCALEDIR: | ||
421 | dirname = | ||
422 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" | ||
423 | DIR_SEPARATOR_STR; | ||
424 | break; | ||
425 | case GNUNET_OS_IPK_ICONDIR: | ||
426 | dirname = | 403 | dirname = |
404 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
405 | else | ||
406 | dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
407 | break; | ||
408 | case GNUNET_OS_IPK_DATADIR: | ||
409 | dirname = | ||
410 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
411 | break; | ||
412 | case GNUNET_OS_IPK_LOCALEDIR: | ||
413 | dirname = | ||
414 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR; | ||
415 | break; | ||
416 | case GNUNET_OS_IPK_ICONDIR: | ||
417 | dirname = | ||
427 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; | 418 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; |
428 | break; | 419 | break; |
429 | default: | 420 | default: |
430 | GNUNET_free (execpath); | 421 | GNUNET_free (execpath); |
431 | return NULL; | 422 | return NULL; |
432 | } | 423 | } |
433 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 424 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); |
434 | sprintf (tmp, "%s%s", execpath, dirname); | 425 | sprintf (tmp, "%s%s", execpath, dirname); |
435 | GNUNET_free (execpath); | 426 | GNUNET_free (execpath); |
@@ -454,6 +445,7 @@ GNUNET_OS_check_helper_binary (const char *binary) | |||
454 | struct stat statbuf; | 445 | struct stat statbuf; |
455 | char *p; | 446 | char *p; |
456 | char *pf; | 447 | char *pf; |
448 | |||
457 | #ifdef MINGW | 449 | #ifdef MINGW |
458 | SOCKET rawsock; | 450 | SOCKET rawsock; |
459 | char *binaryexe; | 451 | char *binaryexe; |
@@ -461,61 +453,59 @@ GNUNET_OS_check_helper_binary (const char *binary) | |||
461 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); | 453 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); |
462 | p = get_path_from_PATH (binaryexe); | 454 | p = get_path_from_PATH (binaryexe); |
463 | if (p != NULL) | 455 | if (p != NULL) |
464 | { | 456 | { |
465 | GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); | 457 | GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); |
466 | GNUNET_free (p); | 458 | GNUNET_free (p); |
467 | p = pf; | 459 | p = pf; |
468 | } | 460 | } |
469 | free (binaryexe); | 461 | free (binaryexe); |
470 | #else | 462 | #else |
471 | p = get_path_from_PATH (binary); | 463 | p = get_path_from_PATH (binary); |
472 | if (p != NULL) | 464 | if (p != NULL) |
473 | { | 465 | { |
474 | GNUNET_asprintf (&pf, "%s/%s", p, binary); | 466 | GNUNET_asprintf (&pf, "%s/%s", p, binary); |
475 | GNUNET_free (p); | 467 | GNUNET_free (p); |
476 | p = pf; | 468 | p = pf; |
477 | } | 469 | } |
478 | #endif | 470 | #endif |
479 | if (p == NULL) | 471 | if (p == NULL) |
480 | { | 472 | { |
481 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 473 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
482 | _("Could not find binary `%s' in PATH!\n"), | 474 | _("Could not find binary `%s' in PATH!\n"), binary); |
483 | binary); | 475 | return GNUNET_SYSERR; |
484 | return GNUNET_SYSERR; | 476 | } |
485 | } | ||
486 | if (0 != STAT (p, &statbuf)) | 477 | if (0 != STAT (p, &statbuf)) |
487 | { | 478 | { |
488 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 479 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
489 | _("stat (%s) failed: %s\n"), | 480 | _("stat (%s) failed: %s\n"), p, STRERROR (errno)); |
490 | p, | 481 | GNUNET_free (p); |
491 | STRERROR (errno)); | 482 | return GNUNET_SYSERR; |
492 | GNUNET_free (p); | 483 | } |
493 | return GNUNET_SYSERR; | ||
494 | } | ||
495 | #ifndef MINGW | 484 | #ifndef MINGW |
496 | if ( (0 != (statbuf.st_mode & S_ISUID)) && | 485 | if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) |
497 | (statbuf.st_uid == 0) ) | 486 | { |
498 | { | 487 | GNUNET_free (p); |
499 | GNUNET_free (p); | 488 | return GNUNET_YES; |
500 | return GNUNET_YES; | 489 | } |
501 | } | ||
502 | if (0 == ACCESS (p, X_OK)) | 490 | if (0 == ACCESS (p, X_OK)) |
503 | { | 491 | { |
504 | GNUNET_free (p); | 492 | GNUNET_free (p); |
505 | return GNUNET_NO; | 493 | return GNUNET_NO; |
506 | } | 494 | } |
507 | GNUNET_free (p); | 495 | GNUNET_free (p); |
508 | return GNUNET_SYSERR; | 496 | return GNUNET_SYSERR; |
509 | #else | 497 | #else |
510 | GNUNET_free (p); | 498 | GNUNET_free (p); |
511 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); | 499 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); |
512 | if (INVALID_SOCKET == rawsock) | 500 | if (INVALID_SOCKET == rawsock) |
513 | { | 501 | { |
514 | DWORD err = GetLastError (); | 502 | DWORD err = GetLastError (); |
515 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 503 | |
516 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); | 504 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
517 | return GNUNET_NO; /* not running as administrator */ | 505 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", |
518 | } | 506 | err); |
507 | return GNUNET_NO; /* not running as administrator */ | ||
508 | } | ||
519 | closesocket (rawsock); | 509 | closesocket (rawsock); |
520 | return GNUNET_YES; | 510 | return GNUNET_YES; |
521 | #endif | 511 | #endif |
diff --git a/src/util/os_network.c b/src/util/os_network.c index ccf326c05..af8046814 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c | |||
@@ -51,120 +51,118 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
51 | theIP = inet_addr ("192.0.34.166"); /* www.example.com */ | 51 | theIP = inet_addr ("192.0.34.166"); /* www.example.com */ |
52 | if ((!GNGetBestInterface) || | 52 | if ((!GNGetBestInterface) || |
53 | (GNGetBestInterface (theIP, &dwExternalNIC) != NO_ERROR)) | 53 | (GNGetBestInterface (theIP, &dwExternalNIC) != NO_ERROR)) |
54 | { | 54 | { |
55 | dwExternalNIC = 0; | 55 | dwExternalNIC = 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | /* Enumerate NICs */ | 58 | /* Enumerate NICs */ |
59 | EnumNICs (&pTable, &pAddrTable); | 59 | EnumNICs (&pTable, &pAddrTable); |
60 | 60 | ||
61 | if (pTable) | 61 | if (pTable) |
62 | { | ||
63 | for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++) | ||
62 | { | 64 | { |
63 | for (dwIfIdx = 0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++) | 65 | char szEntry[1001]; |
64 | { | 66 | DWORD dwIP = 0; |
65 | char szEntry[1001]; | 67 | PIP_ADAPTER_INFO pAdapterInfo; |
66 | DWORD dwIP = 0; | 68 | PIP_ADAPTER_INFO pAdapter = NULL; |
67 | PIP_ADAPTER_INFO pAdapterInfo; | 69 | DWORD dwRetVal = 0; |
68 | PIP_ADAPTER_INFO pAdapter = NULL; | ||
69 | DWORD dwRetVal = 0; | ||
70 | 70 | ||
71 | /* Get IP-Address */ | 71 | /* Get IP-Address */ |
72 | int i; | 72 | int i; |
73 | for (i = 0; i < pAddrTable->dwNumEntries; i++) | ||
74 | { | ||
75 | if (pAddrTable->table[i].dwIndex == | ||
76 | pTable->table[dwIfIdx].dwIndex) | ||
77 | { | ||
78 | dwIP = pAddrTable->table[i].dwAddr; | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | 73 | ||
83 | if (dwIP) | 74 | for (i = 0; i < pAddrTable->dwNumEntries; i++) |
84 | { | 75 | { |
85 | BYTE bPhysAddr[MAXLEN_PHYSADDR]; | 76 | if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex) |
86 | char *pszIfName = NULL; | 77 | { |
87 | char dst[INET_ADDRSTRLEN]; | 78 | dwIP = pAddrTable->table[i].dwAddr; |
88 | struct sockaddr_in sa; | 79 | break; |
80 | } | ||
81 | } | ||
89 | 82 | ||
90 | /* Get friendly interface name */ | 83 | if (dwIP) |
91 | pAdapterInfo = | 84 | { |
92 | (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO)); | 85 | BYTE bPhysAddr[MAXLEN_PHYSADDR]; |
93 | ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); | 86 | char *pszIfName = NULL; |
87 | char dst[INET_ADDRSTRLEN]; | ||
88 | struct sockaddr_in sa; | ||
94 | 89 | ||
95 | /* Make an initial call to GetAdaptersInfo to get | 90 | /* Get friendly interface name */ |
96 | the necessary size into the ulOutBufLen variable */ | 91 | pAdapterInfo = (IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO)); |
97 | if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) == | 92 | ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); |
98 | ERROR_BUFFER_OVERFLOW) | ||
99 | { | ||
100 | free (pAdapterInfo); | ||
101 | pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); | ||
102 | } | ||
103 | 93 | ||
104 | if ((dwRetVal = | 94 | /* Make an initial call to GetAdaptersInfo to get |
105 | GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR) | 95 | * the necessary size into the ulOutBufLen variable */ |
106 | { | 96 | if (GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen) == |
107 | pAdapter = pAdapterInfo; | 97 | ERROR_BUFFER_OVERFLOW) |
108 | while (pAdapter) | 98 | { |
109 | { | 99 | free (pAdapterInfo); |
110 | if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index) | 100 | pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); |
111 | { | 101 | } |
112 | char szKey[251]; | ||
113 | long lLen = 250; | ||
114 | 102 | ||
115 | sprintf (szKey, | 103 | if ((dwRetVal = |
116 | "SYSTEM\\CurrentControlSet\\Control\\Network\\" | 104 | GGetAdaptersInfo (pAdapterInfo, &ulOutBufLen)) == NO_ERROR) |
117 | "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", | 105 | { |
118 | pAdapter->AdapterName); | 106 | pAdapter = pAdapterInfo; |
119 | pszIfName = (char *) malloc (251); | 107 | while (pAdapter) |
120 | if (QueryRegistry | 108 | { |
121 | (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName, | 109 | if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index) |
122 | &lLen) != ERROR_SUCCESS) | 110 | { |
123 | { | 111 | char szKey[251]; |
124 | free (pszIfName); | 112 | long lLen = 250; |
125 | pszIfName = NULL; | ||
126 | } | ||
127 | } | ||
128 | pAdapter = pAdapter->Next; | ||
129 | } | ||
130 | } | ||
131 | free (pAdapterInfo); | ||
132 | 113 | ||
133 | /* Set entry */ | 114 | sprintf (szKey, |
134 | memset (bPhysAddr, 0, MAXLEN_PHYSADDR); | 115 | "SYSTEM\\CurrentControlSet\\Control\\Network\\" |
135 | memcpy (bPhysAddr, | 116 | "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", |
136 | pTable->table[dwIfIdx].bPhysAddr, | 117 | pAdapter->AdapterName); |
137 | pTable->table[dwIfIdx].dwPhysAddrLen); | 118 | pszIfName = (char *) malloc (251); |
119 | if (QueryRegistry | ||
120 | (HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName, | ||
121 | &lLen) != ERROR_SUCCESS) | ||
122 | { | ||
123 | free (pszIfName); | ||
124 | pszIfName = NULL; | ||
125 | } | ||
126 | } | ||
127 | pAdapter = pAdapter->Next; | ||
128 | } | ||
129 | } | ||
130 | free (pAdapterInfo); | ||
138 | 131 | ||
139 | snprintf (szEntry, 1000, "%s (%s - %I64u)", | 132 | /* Set entry */ |
140 | pszIfName ? pszIfName : (char *) | 133 | memset (bPhysAddr, 0, MAXLEN_PHYSADDR); |
141 | pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET, | 134 | memcpy (bPhysAddr, |
142 | &dwIP, dst, | 135 | pTable->table[dwIfIdx].bPhysAddr, |
143 | INET_ADDRSTRLEN), | 136 | pTable->table[dwIfIdx].dwPhysAddrLen); |
144 | *((unsigned long long *) bPhysAddr)); | ||
145 | szEntry[1000] = 0; | ||
146 | 137 | ||
147 | if (pszIfName) | 138 | snprintf (szEntry, 1000, "%s (%s - %I64u)", |
148 | free (pszIfName); | 139 | pszIfName ? pszIfName : (char *) |
140 | pTable->table[dwIfIdx].bDescr, inet_ntop (AF_INET, | ||
141 | &dwIP, dst, | ||
142 | INET_ADDRSTRLEN), | ||
143 | *((unsigned long long *) bPhysAddr)); | ||
144 | szEntry[1000] = 0; | ||
149 | 145 | ||
150 | sa.sin_family = AF_INET; | 146 | if (pszIfName) |
147 | free (pszIfName); | ||
148 | |||
149 | sa.sin_family = AF_INET; | ||
151 | #if HAVE_SOCKADDR_IN_SIN_LEN | 150 | #if HAVE_SOCKADDR_IN_SIN_LEN |
152 | sa.sin_len = (u_char) sizeof (struct sockaddr_in); | 151 | sa.sin_len = (u_char) sizeof (struct sockaddr_in); |
153 | #endif | 152 | #endif |
154 | sa.sin_addr.S_un.S_addr = dwIP; | 153 | sa.sin_addr.S_un.S_addr = dwIP; |
155 | 154 | ||
156 | if (GNUNET_OK != | 155 | if (GNUNET_OK != |
157 | proc (proc_cls, | 156 | proc (proc_cls, |
158 | szEntry, | 157 | szEntry, |
159 | pTable->table[dwIfIdx].dwIndex == dwExternalNIC, | 158 | pTable->table[dwIfIdx].dwIndex == dwExternalNIC, |
160 | (const struct sockaddr *) &sa, | 159 | (const struct sockaddr *) &sa, sizeof (sa))) |
161 | sizeof (sa))) | 160 | break; |
162 | break; | 161 | } |
163 | } | ||
164 | } | ||
165 | GlobalFree (pAddrTable); | ||
166 | GlobalFree (pTable); | ||
167 | } | 162 | } |
163 | GlobalFree (pAddrTable); | ||
164 | GlobalFree (pTable); | ||
165 | } | ||
168 | 166 | ||
169 | return; | 167 | return; |
170 | 168 | ||
@@ -175,29 +173,29 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
175 | socklen_t alen; | 173 | socklen_t alen; |
176 | 174 | ||
177 | if (getifaddrs (&ifa_first) == 0) | 175 | if (getifaddrs (&ifa_first) == 0) |
176 | { | ||
177 | for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) | ||
178 | { | 178 | { |
179 | for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next) | 179 | if (ifa_ptr->ifa_name != NULL && |
180 | { | 180 | ifa_ptr->ifa_addr != NULL && (ifa_ptr->ifa_flags & IFF_UP) != 0) |
181 | if (ifa_ptr->ifa_name != NULL && | 181 | { |
182 | ifa_ptr->ifa_addr != NULL && (ifa_ptr->ifa_flags & IFF_UP) != 0) | 182 | if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && |
183 | { | 183 | (ifa_ptr->ifa_addr->sa_family != AF_INET6)) |
184 | if ((ifa_ptr->ifa_addr->sa_family != AF_INET) && | 184 | continue; |
185 | (ifa_ptr->ifa_addr->sa_family != AF_INET6)) | 185 | if (ifa_ptr->ifa_addr->sa_family == AF_INET) |
186 | continue; | 186 | alen = sizeof (struct sockaddr_in); |
187 | if (ifa_ptr->ifa_addr->sa_family == AF_INET) | 187 | else |
188 | alen = sizeof (struct sockaddr_in); | 188 | alen = sizeof (struct sockaddr_in6); |
189 | else | 189 | if (GNUNET_OK != proc (proc_cls, |
190 | alen = sizeof (struct sockaddr_in6); | 190 | ifa_ptr->ifa_name, |
191 | if (GNUNET_OK != proc (proc_cls, | 191 | 0 == strcmp (ifa_ptr->ifa_name, |
192 | ifa_ptr->ifa_name, | 192 | GNUNET_DEFAULT_INTERFACE), |
193 | 0 == strcmp (ifa_ptr->ifa_name, | 193 | ifa_ptr->ifa_addr, alen)) |
194 | GNUNET_DEFAULT_INTERFACE), | 194 | break; |
195 | ifa_ptr->ifa_addr, alen)) | 195 | } |
196 | break; | ||
197 | } | ||
198 | } | ||
199 | freeifaddrs (ifa_first); | ||
200 | } | 196 | } |
197 | freeifaddrs (ifa_first); | ||
198 | } | ||
201 | #else | 199 | #else |
202 | char line[1024]; | 200 | char line[1024]; |
203 | const char *start; | 201 | const char *start; |
@@ -218,78 +216,77 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
218 | else | 216 | else |
219 | f = popen ("ifconfig -a 2> /dev/null", "r"); | 217 | f = popen ("ifconfig -a 2> /dev/null", "r"); |
220 | if (!f) | 218 | if (!f) |
221 | { | 219 | { |
222 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 220 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
223 | GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig"); | 221 | GNUNET_ERROR_TYPE_BULK, "popen", "ifconfig"); |
224 | return; | 222 | return; |
225 | } | 223 | } |
226 | 224 | ||
227 | have_ifc = GNUNET_NO; | 225 | have_ifc = GNUNET_NO; |
228 | ifc[11] = '\0'; | 226 | ifc[11] = '\0'; |
229 | while (NULL != fgets (line, sizeof (line), f)) | 227 | while (NULL != fgets (line, sizeof (line), f)) |
228 | { | ||
229 | if (strlen (line) == 0) | ||
230 | { | 230 | { |
231 | if (strlen (line) == 0) | 231 | have_ifc = GNUNET_NO; |
232 | { | 232 | continue; |
233 | have_ifc = GNUNET_NO; | 233 | } |
234 | continue; | 234 | if (!isspace (line[0])) |
235 | } | 235 | { |
236 | if (!isspace (line[0])) | 236 | have_ifc = (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO; |
237 | { | 237 | /* would end with ':' on OSX, fix it! */ |
238 | have_ifc = | 238 | if (ifc[strlen (ifc) - 1] == ':') |
239 | (1 == SSCANF (line, "%11s", ifc)) ? GNUNET_YES : GNUNET_NO; | 239 | ifc[strlen (ifc) - 1] = '\0'; |
240 | /* would end with ':' on OSX, fix it! */ | 240 | continue; |
241 | if (ifc[strlen (ifc) - 1] == ':') | 241 | } |
242 | ifc[strlen (ifc) - 1] = '\0'; | 242 | if (!have_ifc) |
243 | continue; | 243 | continue; /* strange input, hope for the best */ |
244 | } | 244 | start = line; |
245 | if (!have_ifc) | 245 | while (('\0' != *start) && (isspace (*start))) |
246 | continue; /* strange input, hope for the best */ | 246 | start++; |
247 | start = line; | 247 | if ( /* Linux */ |
248 | while (('\0' != *start) && (isspace (*start))) | 248 | (1 == SSCANF (start, "inet addr:%127s", addrstr)) || |
249 | start++; | 249 | (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) || |
250 | if ( /* Linux */ | 250 | /* Solaris, OS X */ |
251 | (1 == SSCANF (start, "inet addr:%127s", addrstr)) || | 251 | (1 == SSCANF (start, "inet %127s", addrstr)) || |
252 | (1 == SSCANF (start, "inet6 addr:%127s", addrstr)) || | 252 | (1 == SSCANF (start, "inet6 %127s", addrstr))) |
253 | /* Solaris, OS X */ | 253 | { |
254 | (1 == SSCANF (start, "inet %127s", addrstr)) || | 254 | /* IPv4 */ |
255 | (1 == SSCANF (start, "inet6 %127s", addrstr))) | 255 | if (1 == inet_pton (AF_INET, addrstr, &v4)) |
256 | { | 256 | { |
257 | /* IPv4 */ | 257 | memset (&a4, 0, sizeof (a4)); |
258 | if (1 == inet_pton (AF_INET, addrstr, &v4)) | 258 | a4.sin_family = AF_INET; |
259 | { | ||
260 | memset (&a4, 0, sizeof (a4)); | ||
261 | a4.sin_family = AF_INET; | ||
262 | #if HAVE_SOCKADDR_IN_SIN_LEN | 259 | #if HAVE_SOCKADDR_IN_SIN_LEN |
263 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); | 260 | a4.sin_len = (u_char) sizeof (struct sockaddr_in); |
264 | #endif | 261 | #endif |
265 | a4.sin_addr = v4; | 262 | a4.sin_addr = v4; |
266 | if (GNUNET_OK != | 263 | if (GNUNET_OK != |
267 | proc (proc_cls, | 264 | proc (proc_cls, |
268 | ifc, | 265 | ifc, |
269 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), | 266 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), |
270 | (const struct sockaddr *) &a4, sizeof (a4))) | 267 | (const struct sockaddr *) &a4, sizeof (a4))) |
271 | break; | 268 | break; |
272 | continue; | 269 | continue; |
273 | } | 270 | } |
274 | /* IPv6 */ | 271 | /* IPv6 */ |
275 | if (1 == inet_pton (AF_INET6, addrstr, &v6)) | 272 | if (1 == inet_pton (AF_INET6, addrstr, &v6)) |
276 | { | 273 | { |
277 | memset (&a6, 0, sizeof (a6)); | 274 | memset (&a6, 0, sizeof (a6)); |
278 | a6.sin6_family = AF_INET6; | 275 | a6.sin6_family = AF_INET6; |
279 | #if HAVE_SOCKADDR_IN_SIN_LEN | 276 | #if HAVE_SOCKADDR_IN_SIN_LEN |
280 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); | 277 | a6.sin6_len = (u_char) sizeof (struct sockaddr_in6); |
281 | #endif | 278 | #endif |
282 | a6.sin6_addr = v6; | 279 | a6.sin6_addr = v6; |
283 | if (GNUNET_OK != | 280 | if (GNUNET_OK != |
284 | proc (proc_cls, | 281 | proc (proc_cls, |
285 | ifc, | 282 | ifc, |
286 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), | 283 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), |
287 | (const struct sockaddr *) &a6, sizeof (a6))) | 284 | (const struct sockaddr *) &a6, sizeof (a6))) |
288 | break; | 285 | break; |
289 | continue; | 286 | continue; |
290 | } | 287 | } |
291 | } | ||
292 | } | 288 | } |
289 | } | ||
293 | pclose (f); | 290 | pclose (f); |
294 | #endif | 291 | #endif |
295 | } | 292 | } |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index f2e3f3c38..bccde8d46 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -53,44 +53,42 @@ static struct GNUNET_OS_Process current_process; | |||
53 | */ | 53 | */ |
54 | static void | 54 | static void |
55 | parent_control_handler (void *cls, | 55 | parent_control_handler (void *cls, |
56 | const struct | 56 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
57 | GNUNET_SCHEDULER_TaskContext * tc) | ||
58 | { | 57 | { |
59 | struct GNUNET_DISK_FileHandle *control_pipe = (struct GNUNET_DISK_FileHandle *) cls; | 58 | struct GNUNET_DISK_FileHandle *control_pipe = |
59 | (struct GNUNET_DISK_FileHandle *) cls; | ||
60 | int sig; | 60 | int sig; |
61 | 61 | ||
62 | #if DEBUG_OS | 62 | #if DEBUG_OS |
63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
64 | "`%s' invoked because of %d\n", | 64 | "`%s' invoked because of %d\n", __FUNCTION__, tc->reason); |
65 | __FUNCTION__, | ||
66 | tc->reason); | ||
67 | #endif | 65 | #endif |
68 | if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT | GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 66 | if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | |
67 | GNUNET_SCHEDULER_REASON_TIMEOUT | | ||
68 | GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | ||
69 | { | ||
70 | GNUNET_DISK_npipe_close (control_pipe); | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | if (GNUNET_DISK_file_read (control_pipe, | ||
75 | &sig, sizeof (sig)) != sizeof (sig)) | ||
69 | { | 76 | { |
77 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); | ||
70 | GNUNET_DISK_npipe_close (control_pipe); | 78 | GNUNET_DISK_npipe_close (control_pipe); |
71 | } | 79 | } |
72 | else | 80 | else |
73 | { | 81 | { |
74 | if (GNUNET_DISK_file_read (control_pipe, | ||
75 | &sig, | ||
76 | sizeof (sig)) != sizeof (sig)) | ||
77 | { | ||
78 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
79 | "GNUNET_DISK_file_read"); | ||
80 | GNUNET_DISK_npipe_close (control_pipe); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | #if DEBUG_OS | 82 | #if DEBUG_OS |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Got control code %d from parent\n", sig); | 84 | "Got control code %d from parent\n", sig); |
87 | #endif | 85 | #endif |
88 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 86 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
89 | control_pipe, | 87 | control_pipe, |
90 | &parent_control_handler, control_pipe); | 88 | &parent_control_handler, control_pipe); |
91 | raise (sig); | 89 | raise (sig); |
92 | } | ||
93 | } | 90 | } |
91 | } | ||
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
@@ -100,39 +98,36 @@ parent_control_handler (void *cls, | |||
100 | void | 98 | void |
101 | GNUNET_OS_install_parent_control_handler (void *cls, | 99 | GNUNET_OS_install_parent_control_handler (void *cls, |
102 | const struct | 100 | const struct |
103 | GNUNET_SCHEDULER_TaskContext * tc) | 101 | GNUNET_SCHEDULER_TaskContext *tc) |
104 | { | 102 | { |
105 | const char *env_buf; | 103 | const char *env_buf; |
106 | struct GNUNET_DISK_FileHandle *control_pipe; | 104 | struct GNUNET_DISK_FileHandle *control_pipe; |
107 | 105 | ||
108 | env_buf = getenv (GNUNET_OS_CONTROL_PIPE); | 106 | env_buf = getenv (GNUNET_OS_CONTROL_PIPE); |
109 | if ( (env_buf == NULL) || (strlen (env_buf) <= 0) ) | 107 | if ((env_buf == NULL) || (strlen (env_buf) <= 0)) |
110 | { | 108 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
112 | _("Not installing a handler because $%s=%s\n"), | 110 | _("Not installing a handler because $%s=%s\n"), |
113 | GNUNET_OS_CONTROL_PIPE, | 111 | GNUNET_OS_CONTROL_PIPE, env_buf); |
114 | env_buf); | 112 | return; |
115 | return; | 113 | } |
116 | } | ||
117 | control_pipe = GNUNET_DISK_npipe_open (env_buf, | 114 | control_pipe = GNUNET_DISK_npipe_open (env_buf, |
118 | GNUNET_DISK_OPEN_READ, | 115 | GNUNET_DISK_OPEN_READ, |
119 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 116 | GNUNET_DISK_PERM_USER_READ | |
117 | GNUNET_DISK_PERM_USER_WRITE); | ||
120 | if (control_pipe == NULL) | 118 | if (control_pipe == NULL) |
121 | { | 119 | { |
122 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 120 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); |
123 | "open", | 121 | return; |
124 | env_buf); | 122 | } |
125 | return; | ||
126 | } | ||
127 | #if DEBUG_OS | 123 | #if DEBUG_OS |
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
129 | "Adding parent control handler pipe `%s' to the scheduler\n", | 125 | "Adding parent control handler pipe `%s' to the scheduler\n", |
130 | env_buf); | 126 | env_buf); |
131 | #endif | 127 | #endif |
132 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 128 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
133 | control_pipe, | 129 | control_pipe, |
134 | &parent_control_handler, | 130 | &parent_control_handler, control_pipe); |
135 | control_pipe); | ||
136 | } | 131 | } |
137 | 132 | ||
138 | 133 | ||
@@ -164,27 +159,27 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
164 | int res = 0; | 159 | int res = 0; |
165 | int ret = 0; | 160 | int ret = 0; |
166 | 161 | ||
167 | ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof(sig)); | 162 | ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig)); |
168 | if (ret != sizeof(sig)) | 163 | if (ret != sizeof (sig)) |
169 | { | 164 | { |
170 | if (errno == ECOMM) | 165 | if (errno == ECOMM) |
171 | { | 166 | { |
172 | /* Child process is not controllable via pipe */ | 167 | /* Child process is not controllable via pipe */ |
173 | #if DEBUG_OS | 168 | #if DEBUG_OS |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Child process is not controllable, will kill it directly\n"); | 170 | "Child process is not controllable, will kill it directly\n"); |
176 | #endif | 171 | #endif |
177 | } | 172 | } |
178 | else if (errno == EPIPE) | 173 | else if (errno == EPIPE) |
179 | { | 174 | { |
180 | #if DEBUG_OS | 175 | #if DEBUG_OS |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
182 | "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n"); | 177 | "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n"); |
183 | #endif | 178 | #endif |
184 | } | 179 | } |
185 | else | 180 | else |
186 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
187 | "Failed to write into control pipe , errno is %d\n", errno); | 182 | "Failed to write into control pipe , errno is %d\n", errno); |
188 | #if WINDOWS && !defined(__CYGWIN__) | 183 | #if WINDOWS && !defined(__CYGWIN__) |
189 | TerminateProcess (proc->handle, 0); | 184 | TerminateProcess (proc->handle, 0); |
190 | #else | 185 | #else |
@@ -195,7 +190,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
195 | { | 190 | { |
196 | #if DEBUG_OS | 191 | #if DEBUG_OS |
197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
198 | "Wrote control code into control pipe, now waiting\n"); | 193 | "Wrote control code into control pipe, now waiting\n"); |
199 | #endif | 194 | #endif |
200 | 195 | ||
201 | #if WINDOWS | 196 | #if WINDOWS |
@@ -225,27 +220,28 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
225 | while (1) | 220 | while (1) |
226 | { | 221 | { |
227 | ret = GNUNET_NETWORK_socket_select (rfds, NULL, efds, | 222 | ret = GNUNET_NETWORK_socket_select (rfds, NULL, efds, |
228 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_unit (), | 223 | GNUNET_TIME_relative_multiply |
229 | 5000)); | 224 | (GNUNET_TIME_relative_get_unit (), |
225 | 5000)); | ||
230 | 226 | ||
231 | if (ret < 1 || GNUNET_NETWORK_fdset_handle_isset (efds, | 227 | if (ret < 1 || GNUNET_NETWORK_fdset_handle_isset (efds, |
232 | proc->control_pipe)) | 228 | proc->control_pipe)) |
233 | { | 229 | { |
234 | /* Just to be sure */ | 230 | /* Just to be sure */ |
235 | PLIBC_KILL (proc->pid, sig); | 231 | PLIBC_KILL (proc->pid, sig); |
236 | res = 0; | 232 | res = 0; |
237 | break; | 233 | break; |
238 | } | 234 | } |
239 | else | 235 | else |
240 | { | 236 | { |
241 | if (GNUNET_DISK_file_read (proc->control_pipe, &ret, | 237 | if (GNUNET_DISK_file_read (proc->control_pipe, &ret, |
242 | sizeof(ret)) != GNUNET_OK) | 238 | sizeof (ret)) != GNUNET_OK) |
243 | res = PLIBC_KILL (proc->pid, sig); | 239 | res = PLIBC_KILL (proc->pid, sig); |
244 | 240 | ||
245 | /* Child signaled shutdown is in progress */ | 241 | /* Child signaled shutdown is in progress */ |
246 | continue; | 242 | continue; |
247 | } | 243 | } |
248 | } | 244 | } |
249 | #endif | 245 | #endif |
250 | } | 246 | } |
251 | 247 | ||
@@ -263,7 +259,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
263 | * @return the current process id | 259 | * @return the current process id |
264 | */ | 260 | */ |
265 | pid_t | 261 | pid_t |
266 | GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc) | 262 | GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc) |
267 | { | 263 | { |
268 | return proc->pid; | 264 | return proc->pid; |
269 | } | 265 | } |
@@ -303,6 +299,7 @@ static DWORD_WINAPI | |||
303 | ChildWaitThread (void *arg) | 299 | ChildWaitThread (void *arg) |
304 | { | 300 | { |
305 | struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *) arg; | 301 | struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *) arg; |
302 | |||
306 | WaitForSingleObject (proc->handle, INFINITE); | 303 | WaitForSingleObject (proc->handle, INFINITE); |
307 | 304 | ||
308 | if (w32_sigchld_handler) | 305 | if (w32_sigchld_handler) |
@@ -331,91 +328,90 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, | |||
331 | 328 | ||
332 | /* convert to MINGW/Unix values */ | 329 | /* convert to MINGW/Unix values */ |
333 | switch (prio) | 330 | switch (prio) |
334 | { | 331 | { |
335 | case GNUNET_SCHEDULER_PRIORITY_UI: | 332 | case GNUNET_SCHEDULER_PRIORITY_UI: |
336 | case GNUNET_SCHEDULER_PRIORITY_URGENT: | 333 | case GNUNET_SCHEDULER_PRIORITY_URGENT: |
337 | #ifdef MINGW | 334 | #ifdef MINGW |
338 | rprio = HIGH_PRIORITY_CLASS; | 335 | rprio = HIGH_PRIORITY_CLASS; |
339 | #else | 336 | #else |
340 | rprio = 0; | 337 | rprio = 0; |
341 | #endif | 338 | #endif |
342 | break; | 339 | break; |
343 | 340 | ||
344 | case GNUNET_SCHEDULER_PRIORITY_HIGH: | 341 | case GNUNET_SCHEDULER_PRIORITY_HIGH: |
345 | #ifdef MINGW | 342 | #ifdef MINGW |
346 | rprio = ABOVE_NORMAL_PRIORITY_CLASS; | 343 | rprio = ABOVE_NORMAL_PRIORITY_CLASS; |
347 | #else | 344 | #else |
348 | rprio = 5; | 345 | rprio = 5; |
349 | #endif | 346 | #endif |
350 | break; | 347 | break; |
351 | 348 | ||
352 | case GNUNET_SCHEDULER_PRIORITY_DEFAULT: | 349 | case GNUNET_SCHEDULER_PRIORITY_DEFAULT: |
353 | #ifdef MINGW | 350 | #ifdef MINGW |
354 | rprio = NORMAL_PRIORITY_CLASS; | 351 | rprio = NORMAL_PRIORITY_CLASS; |
355 | #else | 352 | #else |
356 | rprio = 7; | 353 | rprio = 7; |
357 | #endif | 354 | #endif |
358 | break; | 355 | break; |
359 | 356 | ||
360 | case GNUNET_SCHEDULER_PRIORITY_BACKGROUND: | 357 | case GNUNET_SCHEDULER_PRIORITY_BACKGROUND: |
361 | #ifdef MINGW | 358 | #ifdef MINGW |
362 | rprio = BELOW_NORMAL_PRIORITY_CLASS; | 359 | rprio = BELOW_NORMAL_PRIORITY_CLASS; |
363 | #else | 360 | #else |
364 | rprio = 10; | 361 | rprio = 10; |
365 | #endif | 362 | #endif |
366 | break; | 363 | break; |
367 | 364 | ||
368 | case GNUNET_SCHEDULER_PRIORITY_IDLE: | 365 | case GNUNET_SCHEDULER_PRIORITY_IDLE: |
369 | #ifdef MINGW | 366 | #ifdef MINGW |
370 | rprio = IDLE_PRIORITY_CLASS; | 367 | rprio = IDLE_PRIORITY_CLASS; |
371 | #else | 368 | #else |
372 | rprio = 19; | 369 | rprio = 19; |
373 | #endif | 370 | #endif |
374 | break; | 371 | break; |
375 | default: | 372 | default: |
376 | GNUNET_assert (0); | 373 | GNUNET_assert (0); |
377 | return GNUNET_SYSERR; | 374 | return GNUNET_SYSERR; |
378 | } | 375 | } |
379 | 376 | ||
380 | /* Set process priority */ | 377 | /* Set process priority */ |
381 | #ifdef MINGW | 378 | #ifdef MINGW |
382 | { | 379 | { |
383 | HANDLE h = proc->handle; | 380 | HANDLE h = proc->handle; |
381 | |||
384 | GNUNET_assert (h != NULL); | 382 | GNUNET_assert (h != NULL); |
385 | SetPriorityClass (h, rprio); | 383 | SetPriorityClass (h, rprio); |
386 | } | 384 | } |
387 | #elif LINUX | 385 | #elif LINUX |
388 | pid_t pid; | 386 | pid_t pid; |
389 | 387 | ||
390 | pid = proc->pid; | 388 | pid = proc->pid; |
391 | if ( (0 == pid) || | 389 | if ((0 == pid) || (pid == getpid ())) |
392 | (pid == getpid () ) ) | 390 | { |
391 | int have = nice (0); | ||
392 | int delta = rprio - have; | ||
393 | |||
394 | errno = 0; | ||
395 | if ((delta != 0) && (rprio == nice (delta)) && (errno != 0)) | ||
393 | { | 396 | { |
394 | int have = nice (0); | 397 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | |
395 | int delta = rprio - have; | 398 | GNUNET_ERROR_TYPE_BULK, "nice"); |
396 | errno = 0; | 399 | return GNUNET_SYSERR; |
397 | if ( (delta != 0) && | ||
398 | (rprio == nice (delta)) && | ||
399 | (errno != 0) ) | ||
400 | { | ||
401 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | | ||
402 | GNUNET_ERROR_TYPE_BULK, "nice"); | ||
403 | return GNUNET_SYSERR; | ||
404 | } | ||
405 | } | 400 | } |
401 | } | ||
406 | else | 402 | else |
403 | { | ||
404 | if (0 != setpriority (PRIO_PROCESS, pid, rprio)) | ||
407 | { | 405 | { |
408 | if (0 != setpriority (PRIO_PROCESS, pid, rprio)) | 406 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | |
409 | { | 407 | GNUNET_ERROR_TYPE_BULK, "setpriority"); |
410 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | | 408 | return GNUNET_SYSERR; |
411 | GNUNET_ERROR_TYPE_BULK, "setpriority"); | ||
412 | return GNUNET_SYSERR; | ||
413 | } | ||
414 | } | 409 | } |
410 | } | ||
415 | #else | 411 | #else |
416 | #if DEBUG_OS | 412 | #if DEBUG_OS |
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
418 | "Priority management not availabe for this platform\n"); | 414 | "Priority management not availabe for this platform\n"); |
419 | #endif | 415 | #endif |
420 | #endif | 416 | #endif |
421 | return GNUNET_OK; | 417 | return GNUNET_OK; |
@@ -434,10 +430,11 @@ CreateCustomEnvTable (char **vars) | |||
434 | size_t var_len; | 430 | size_t var_len; |
435 | char *var; | 431 | char *var; |
436 | char *val; | 432 | char *val; |
433 | |||
437 | win32_env_table = GetEnvironmentStringsA (); | 434 | win32_env_table = GetEnvironmentStringsA (); |
438 | if (win32_env_table == NULL) | 435 | if (win32_env_table == NULL) |
439 | return NULL; | 436 | return NULL; |
440 | for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++); | 437 | for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ; |
441 | n_var = c; | 438 | n_var = c; |
442 | index = GNUNET_malloc (sizeof (char *) * n_var); | 439 | index = GNUNET_malloc (sizeof (char *) * n_var); |
443 | for (c = 0; c < n_var; c++) | 440 | for (c = 0; c < n_var; c++) |
@@ -446,6 +443,7 @@ CreateCustomEnvTable (char **vars) | |||
446 | { | 443 | { |
447 | size_t len = strlen (ptr); | 444 | size_t len = strlen (ptr); |
448 | int found = 0; | 445 | int found = 0; |
446 | |||
449 | for (var_ptr = vars; *var_ptr; var_ptr++) | 447 | for (var_ptr = vars; *var_ptr; var_ptr++) |
450 | { | 448 | { |
451 | var = *var_ptr++; | 449 | var = *var_ptr++; |
@@ -461,7 +459,7 @@ CreateCustomEnvTable (char **vars) | |||
461 | } | 459 | } |
462 | if (!found) | 460 | if (!found) |
463 | tablesize += len + 1; | 461 | tablesize += len + 1; |
464 | ptr += len + 1; | 462 | ptr += len + 1; |
465 | } | 463 | } |
466 | for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) | 464 | for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) |
467 | { | 465 | { |
@@ -475,6 +473,7 @@ CreateCustomEnvTable (char **vars) | |||
475 | { | 473 | { |
476 | size_t len = strlen (ptr); | 474 | size_t len = strlen (ptr); |
477 | int found = 0; | 475 | int found = 0; |
476 | |||
478 | for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) | 477 | for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) |
479 | { | 478 | { |
480 | var = *var_ptr++; | 479 | var = *var_ptr++; |
@@ -531,12 +530,12 @@ CreateCustomEnvTable (char **vars) | |||
531 | * @return pointer to process structure of the new process, NULL on error | 530 | * @return pointer to process structure of the new process, NULL on error |
532 | */ | 531 | */ |
533 | struct GNUNET_OS_Process * | 532 | struct GNUNET_OS_Process * |
534 | GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | 533 | GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, |
535 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 534 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
536 | const char *filename, | 535 | const char *filename, va_list va) |
537 | va_list va) | ||
538 | { | 536 | { |
539 | va_list ap; | 537 | va_list ap; |
538 | |||
540 | #if ENABLE_WINDOWS_WORKAROUNDS | 539 | #if ENABLE_WINDOWS_WORKAROUNDS |
541 | char *childpipename = NULL; | 540 | char *childpipename = NULL; |
542 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; | 541 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; |
@@ -554,8 +553,9 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
554 | 553 | ||
555 | #if ENABLE_WINDOWS_WORKAROUNDS | 554 | #if ENABLE_WINDOWS_WORKAROUNDS |
556 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, | 555 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, |
557 | GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ | | 556 | GNUNET_DISK_OPEN_WRITE, |
558 | GNUNET_DISK_PERM_USER_WRITE); | 557 | GNUNET_DISK_PERM_USER_READ | |
558 | GNUNET_DISK_PERM_USER_WRITE); | ||
559 | if (control_pipe == NULL) | 559 | if (control_pipe == NULL) |
560 | return NULL; | 560 | return NULL; |
561 | #endif | 561 | #endif |
@@ -563,24 +563,35 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
563 | argc = 0; | 563 | argc = 0; |
564 | va_copy (ap, va); | 564 | va_copy (ap, va); |
565 | while (NULL != va_arg (ap, char *)) | 565 | while (NULL != va_arg (ap, char *)) |
566 | argc++; | 566 | argc++; |
567 | |||
567 | va_end (ap); | 568 | va_end (ap); |
568 | argv = GNUNET_malloc (sizeof (char *) * (argc + 1)); | 569 | argv = GNUNET_malloc (sizeof (char *) * (argc + 1)); |
569 | argc = 0; | 570 | argc = 0; |
570 | va_copy (ap, va); | 571 | va_copy (ap, va); |
571 | while (NULL != (argv[argc] = va_arg (ap, char *))) | 572 | while (NULL != (argv[argc] = va_arg (ap, char *))) |
572 | argc++; | 573 | argc++; |
574 | |||
573 | va_end (ap); | 575 | va_end (ap); |
574 | if (pipe_stdout != NULL) | 576 | if (pipe_stdout != NULL) |
575 | { | 577 | { |
576 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &fd_stdout_write, sizeof (int)); | 578 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle |
577 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_READ), &fd_stdout_read, sizeof (int)); | 579 | (pipe_stdout, |
578 | } | 580 | GNUNET_DISK_PIPE_END_WRITE), |
581 | &fd_stdout_write, sizeof (int)); | ||
582 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle | ||
583 | (pipe_stdout, GNUNET_DISK_PIPE_END_READ), | ||
584 | &fd_stdout_read, sizeof (int)); | ||
585 | } | ||
579 | if (pipe_stdin != NULL) | 586 | if (pipe_stdin != NULL) |
580 | { | 587 | { |
581 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdin, GNUNET_DISK_PIPE_END_READ), &fd_stdin_read, sizeof (int)); | 588 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle |
582 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), &fd_stdin_write, sizeof (int)); | 589 | (pipe_stdin, GNUNET_DISK_PIPE_END_READ), |
583 | } | 590 | &fd_stdin_read, sizeof (int)); |
591 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle | ||
592 | (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), | ||
593 | &fd_stdin_write, sizeof (int)); | ||
594 | } | ||
584 | 595 | ||
585 | #if HAVE_WORKING_VFORK | 596 | #if HAVE_WORKING_VFORK |
586 | ret = vfork (); | 597 | ret = vfork (); |
@@ -588,44 +599,44 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
588 | ret = fork (); | 599 | ret = fork (); |
589 | #endif | 600 | #endif |
590 | if (ret != 0) | 601 | if (ret != 0) |
602 | { | ||
603 | if (ret == -1) | ||
591 | { | 604 | { |
592 | if (ret == -1) | 605 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); |
593 | { | ||
594 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); | ||
595 | #if ENABLE_WINDOWS_WORKAROUNDS | 606 | #if ENABLE_WINDOWS_WORKAROUNDS |
596 | GNUNET_DISK_npipe_close (control_pipe); | 607 | GNUNET_DISK_npipe_close (control_pipe); |
597 | #endif | 608 | #endif |
598 | } | 609 | } |
599 | else | 610 | else |
600 | { | 611 | { |
601 | 612 | ||
602 | #if HAVE_WORKING_VFORK | 613 | #if HAVE_WORKING_VFORK |
603 | /* let's hope vfork actually works; for some extreme cases (including | 614 | /* let's hope vfork actually works; for some extreme cases (including |
604 | a testcase) we need 'execvp' to have run before we return, since | 615 | * a testcase) we need 'execvp' to have run before we return, since |
605 | we may send a signal to the process next and we don't want it | 616 | * we may send a signal to the process next and we don't want it |
606 | to be caught by OUR signal handler (but either by the default | 617 | * to be caught by OUR signal handler (but either by the default |
607 | handler or the actual handler as installed by the process itself). */ | 618 | * handler or the actual handler as installed by the process itself). */ |
608 | #else | 619 | #else |
609 | /* let's give the child process a chance to run execvp, 1s should | 620 | /* let's give the child process a chance to run execvp, 1s should |
610 | be plenty in practice */ | 621 | * be plenty in practice */ |
611 | if (pipe_stdout != NULL) | 622 | if (pipe_stdout != NULL) |
612 | GNUNET_DISK_pipe_close_end(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | 623 | GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); |
613 | if (pipe_stdin != NULL) | 624 | if (pipe_stdin != NULL) |
614 | GNUNET_DISK_pipe_close_end(pipe_stdin, GNUNET_DISK_PIPE_END_READ); | 625 | GNUNET_DISK_pipe_close_end (pipe_stdin, GNUNET_DISK_PIPE_END_READ); |
615 | sleep (1); | 626 | sleep (1); |
616 | #endif | 627 | #endif |
617 | gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); | 628 | gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); |
618 | gnunet_proc->pid = ret; | 629 | gnunet_proc->pid = ret; |
619 | #if ENABLE_WINDOWS_WORKAROUNDS | 630 | #if ENABLE_WINDOWS_WORKAROUNDS |
620 | gnunet_proc->control_pipe = control_pipe; | 631 | gnunet_proc->control_pipe = control_pipe; |
621 | #endif | 632 | #endif |
622 | } | 633 | } |
623 | GNUNET_free (argv); | 634 | GNUNET_free (argv); |
624 | #if ENABLE_WINDOWS_WORKAROUNDS | 635 | #if ENABLE_WINDOWS_WORKAROUNDS |
625 | GNUNET_free (childpipename); | 636 | GNUNET_free (childpipename); |
626 | #endif | 637 | #endif |
627 | return gnunet_proc; | 638 | return gnunet_proc; |
628 | } | 639 | } |
629 | 640 | ||
630 | #if ENABLE_WINDOWS_WORKAROUNDS | 641 | #if ENABLE_WINDOWS_WORKAROUNDS |
631 | setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); | 642 | setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); |
@@ -633,21 +644,21 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
633 | #endif | 644 | #endif |
634 | 645 | ||
635 | if (pipe_stdout != NULL) | 646 | if (pipe_stdout != NULL) |
636 | { | 647 | { |
637 | GNUNET_break (0 == close (fd_stdout_read)); | 648 | GNUNET_break (0 == close (fd_stdout_read)); |
638 | if (-1 == dup2(fd_stdout_write, 1)) | 649 | if (-1 == dup2 (fd_stdout_write, 1)) |
639 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2"); | 650 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2"); |
640 | GNUNET_break (0 == close (fd_stdout_write)); | 651 | GNUNET_break (0 == close (fd_stdout_write)); |
641 | } | 652 | } |
642 | 653 | ||
643 | if (pipe_stdin != NULL) | 654 | if (pipe_stdin != NULL) |
644 | { | 655 | { |
645 | 656 | ||
646 | GNUNET_break (0 == close (fd_stdin_write)); | 657 | GNUNET_break (0 == close (fd_stdin_write)); |
647 | if (-1 == dup2(fd_stdin_read, 0)) | 658 | if (-1 == dup2 (fd_stdin_read, 0)) |
648 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2"); | 659 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2"); |
649 | GNUNET_break (0 == close (fd_stdin_read)); | 660 | GNUNET_break (0 == close (fd_stdin_read)); |
650 | } | 661 | } |
651 | execvp (filename, argv); | 662 | execvp (filename, argv); |
652 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); | 663 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); |
653 | _exit (1); | 664 | _exit (1); |
@@ -682,7 +693,9 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
682 | 693 | ||
683 | pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); | 694 | pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); |
684 | 695 | ||
685 | alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + strlen (libdir); | 696 | alloc_len = |
697 | pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + | ||
698 | strlen (libdir); | ||
686 | 699 | ||
687 | pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); | 700 | pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); |
688 | 701 | ||
@@ -704,36 +717,39 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
704 | /* Check that this is the full path. If it isn't, search. */ | 717 | /* Check that this is the full path. If it isn't, search. */ |
705 | if (non_const_filename[1] == ':') | 718 | if (non_const_filename[1] == ':') |
706 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); | 719 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); |
707 | else if (!SearchPathA (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), path, NULL)) | 720 | else if (!SearchPathA |
708 | { | 721 | (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), |
709 | SetErrnoFromWinError (GetLastError ()); | 722 | path, NULL)) |
710 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath", non_const_filename); | 723 | { |
711 | GNUNET_free (non_const_filename); | 724 | SetErrnoFromWinError (GetLastError ()); |
712 | GNUNET_free (pathbuf); | 725 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath", |
713 | return NULL; | 726 | non_const_filename); |
714 | } | 727 | GNUNET_free (non_const_filename); |
728 | GNUNET_free (pathbuf); | ||
729 | return NULL; | ||
730 | } | ||
715 | GNUNET_free (pathbuf); | 731 | GNUNET_free (pathbuf); |
716 | GNUNET_free (non_const_filename); | 732 | GNUNET_free (non_const_filename); |
717 | 733 | ||
718 | cmdlen = 0; | 734 | cmdlen = 0; |
719 | va_copy (ap, va); | 735 | va_copy (ap, va); |
720 | while (NULL != (arg = va_arg (ap, char *))) | 736 | while (NULL != (arg = va_arg (ap, char *))) |
721 | { | 737 | { |
722 | if (cmdlen == 0) | 738 | if (cmdlen == 0) |
723 | cmdlen = cmdlen + strlen (path) + 3; | 739 | cmdlen = cmdlen + strlen (path) + 3; |
724 | else | 740 | else |
725 | cmdlen = cmdlen + strlen (arg) + 3; | 741 | cmdlen = cmdlen + strlen (arg) + 3; |
726 | } | 742 | } |
727 | va_end (ap); | 743 | va_end (ap); |
728 | 744 | ||
729 | cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1)); | 745 | cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1)); |
730 | va_copy (ap, va); | 746 | va_copy (ap, va); |
731 | while (NULL != (arg = va_arg (ap, char *))) | 747 | while (NULL != (arg = va_arg (ap, char *))) |
732 | { | 748 | { |
733 | if (idx == cmd) | 749 | if (idx == cmd) |
734 | idx += sprintf (idx, "\"%s\" ", path); | 750 | idx += sprintf (idx, "\"%s\" ", path); |
735 | else | 751 | else |
736 | idx += sprintf (idx, "\"%s\" ", arg); | 752 | idx += sprintf (idx, "\"%s\" ", arg); |
737 | } | 753 | } |
738 | va_end (ap); | 754 | va_end (ap); |
739 | 755 | ||
@@ -744,20 +760,26 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
744 | start.dwFlags |= STARTF_USESTDHANDLES; | 760 | start.dwFlags |= STARTF_USESTDHANDLES; |
745 | 761 | ||
746 | if (pipe_stdin != NULL) | 762 | if (pipe_stdin != NULL) |
747 | { | 763 | { |
748 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdin, GNUNET_DISK_PIPE_END_READ), &stdin_handle, sizeof (HANDLE)); | 764 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle |
749 | start.hStdInput = stdin_handle; | 765 | (pipe_stdin, GNUNET_DISK_PIPE_END_READ), |
750 | } | 766 | &stdin_handle, sizeof (HANDLE)); |
767 | start.hStdInput = stdin_handle; | ||
768 | } | ||
751 | 769 | ||
752 | if (pipe_stdout != NULL) | 770 | if (pipe_stdout != NULL) |
753 | { | 771 | { |
754 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &stdout_handle, sizeof (HANDLE)); | 772 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle |
755 | start.hStdOutput = stdout_handle; | 773 | (pipe_stdout, |
756 | } | 774 | GNUNET_DISK_PIPE_END_WRITE), |
775 | &stdout_handle, sizeof (HANDLE)); | ||
776 | start.hStdOutput = stdout_handle; | ||
777 | } | ||
757 | 778 | ||
758 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, | 779 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, |
759 | GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ | | 780 | GNUNET_DISK_OPEN_WRITE, |
760 | GNUNET_DISK_PERM_USER_WRITE); | 781 | GNUNET_DISK_PERM_USER_READ | |
782 | GNUNET_DISK_PERM_USER_WRITE); | ||
761 | if (control_pipe == NULL) | 783 | if (control_pipe == NULL) |
762 | { | 784 | { |
763 | GNUNET_free (cmd); | 785 | GNUNET_free (cmd); |
@@ -766,9 +788,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
766 | } | 788 | } |
767 | 789 | ||
768 | #if DEBUG_OS | 790 | #if DEBUG_OS |
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
770 | "Opened the parent end of the pipe `%s'\n", | 792 | "Opened the parent end of the pipe `%s'\n", childpipename); |
771 | childpipename); | ||
772 | #endif | 793 | #endif |
773 | 794 | ||
774 | GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); | 795 | GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); |
@@ -781,13 +802,13 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
781 | if (!CreateProcessA | 802 | if (!CreateProcessA |
782 | (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, | 803 | (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, |
783 | env_block, NULL, &start, &proc)) | 804 | env_block, NULL, &start, &proc)) |
784 | { | 805 | { |
785 | SetErrnoFromWinError (GetLastError ()); | 806 | SetErrnoFromWinError (GetLastError ()); |
786 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); | 807 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); |
787 | GNUNET_free (env_block); | 808 | GNUNET_free (env_block); |
788 | GNUNET_free (cmd); | 809 | GNUNET_free (cmd); |
789 | return NULL; | 810 | return NULL; |
790 | } | 811 | } |
791 | 812 | ||
792 | GNUNET_free (env_block); | 813 | GNUNET_free (env_block); |
793 | 814 | ||
@@ -820,18 +841,15 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
820 | * | 841 | * |
821 | */ | 842 | */ |
822 | struct GNUNET_OS_Process * | 843 | struct GNUNET_OS_Process * |
823 | GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, | 844 | GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, |
824 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 845 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
825 | const char *filename, ...) | 846 | const char *filename, ...) |
826 | { | 847 | { |
827 | struct GNUNET_OS_Process *ret; | 848 | struct GNUNET_OS_Process *ret; |
828 | va_list ap; | 849 | va_list ap; |
829 | 850 | ||
830 | va_start (ap, filename); | 851 | va_start (ap, filename); |
831 | ret = GNUNET_OS_start_process_va (pipe_stdin, | 852 | ret = GNUNET_OS_start_process_va (pipe_stdin, pipe_stdout, filename, ap); |
832 | pipe_stdout, | ||
833 | filename, | ||
834 | ap); | ||
835 | va_end (ap); | 853 | va_end (ap); |
836 | return ret; | 854 | return ret; |
837 | } | 855 | } |
@@ -848,7 +866,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
848 | */ | 866 | */ |
849 | struct GNUNET_OS_Process * | 867 | struct GNUNET_OS_Process * |
850 | GNUNET_OS_start_process_v (const int *lsocks, | 868 | GNUNET_OS_start_process_v (const int *lsocks, |
851 | const char *filename, char *const argv[]) | 869 | const char *filename, char *const argv[]) |
852 | { | 870 | { |
853 | #if ENABLE_WINDOWS_WORKAROUNDS | 871 | #if ENABLE_WINDOWS_WORKAROUNDS |
854 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; | 872 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; |
@@ -866,12 +884,13 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
866 | int tgt; | 884 | int tgt; |
867 | int flags; | 885 | int flags; |
868 | int *lscp; | 886 | int *lscp; |
869 | unsigned int ls; | 887 | unsigned int ls; |
870 | 888 | ||
871 | #if ENABLE_WINDOWS_WORKAROUNDS | 889 | #if ENABLE_WINDOWS_WORKAROUNDS |
872 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, | 890 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, |
873 | GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ | | 891 | GNUNET_DISK_OPEN_WRITE, |
874 | GNUNET_DISK_PERM_USER_WRITE); | 892 | GNUNET_DISK_PERM_USER_READ | |
893 | GNUNET_DISK_PERM_USER_WRITE); | ||
875 | if (control_pipe == NULL) | 894 | if (control_pipe == NULL) |
876 | return NULL; | 895 | return NULL; |
877 | #endif | 896 | #endif |
@@ -879,100 +898,100 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
879 | lscp = NULL; | 898 | lscp = NULL; |
880 | ls = 0; | 899 | ls = 0; |
881 | if (lsocks != NULL) | 900 | if (lsocks != NULL) |
882 | { | 901 | { |
883 | i = 0; | 902 | i = 0; |
884 | while (-1 != (k = lsocks[i++])) | 903 | while (-1 != (k = lsocks[i++])) |
885 | GNUNET_array_append (lscp, ls, k); | 904 | GNUNET_array_append (lscp, ls, k); |
886 | GNUNET_array_append (lscp, ls, -1); | 905 | GNUNET_array_append (lscp, ls, -1); |
887 | } | 906 | } |
888 | #if HAVE_WORKING_VFORK | 907 | #if HAVE_WORKING_VFORK |
889 | ret = vfork (); | 908 | ret = vfork (); |
890 | #else | 909 | #else |
891 | ret = fork (); | 910 | ret = fork (); |
892 | #endif | 911 | #endif |
893 | if (ret != 0) | 912 | if (ret != 0) |
913 | { | ||
914 | if (ret == -1) | ||
894 | { | 915 | { |
895 | if (ret == -1) | 916 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); |
896 | { | ||
897 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); | ||
898 | #if ENABLE_WINDOWS_WORKAROUNDS | 917 | #if ENABLE_WINDOWS_WORKAROUNDS |
899 | GNUNET_DISK_npipe_close (control_pipe); | 918 | GNUNET_DISK_npipe_close (control_pipe); |
900 | #endif | 919 | #endif |
901 | } | 920 | } |
902 | else | 921 | else |
903 | { | 922 | { |
904 | #if HAVE_WORKING_VFORK | 923 | #if HAVE_WORKING_VFORK |
905 | /* let's hope vfork actually works; for some extreme cases (including | 924 | /* let's hope vfork actually works; for some extreme cases (including |
906 | a testcase) we need 'execvp' to have run before we return, since | 925 | * a testcase) we need 'execvp' to have run before we return, since |
907 | we may send a signal to the process next and we don't want it | 926 | * we may send a signal to the process next and we don't want it |
908 | to be caught by OUR signal handler (but either by the default | 927 | * to be caught by OUR signal handler (but either by the default |
909 | handler or the actual handler as installed by the process itself). */ | 928 | * handler or the actual handler as installed by the process itself). */ |
910 | #else | 929 | #else |
911 | /* let's give the child process a chance to run execvp, 1s should | 930 | /* let's give the child process a chance to run execvp, 1s should |
912 | be plenty in practice */ | 931 | * be plenty in practice */ |
913 | sleep (1); | 932 | sleep (1); |
914 | #endif | 933 | #endif |
915 | gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); | 934 | gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); |
916 | gnunet_proc->pid = ret; | 935 | gnunet_proc->pid = ret; |
917 | #if ENABLE_WINDOWS_WORKAROUNDS | 936 | #if ENABLE_WINDOWS_WORKAROUNDS |
918 | gnunet_proc->control_pipe = control_pipe; | 937 | gnunet_proc->control_pipe = control_pipe; |
919 | 938 | ||
920 | #endif | 939 | #endif |
921 | } | 940 | } |
922 | GNUNET_array_grow (lscp, ls, 0); | 941 | GNUNET_array_grow (lscp, ls, 0); |
923 | #if ENABLE_WINDOWS_WORKAROUNDS | 942 | #if ENABLE_WINDOWS_WORKAROUNDS |
924 | GNUNET_free (childpipename); | 943 | GNUNET_free (childpipename); |
925 | #endif | 944 | #endif |
926 | return gnunet_proc; | 945 | return gnunet_proc; |
927 | } | 946 | } |
928 | 947 | ||
929 | #if ENABLE_WINDOWS_WORKAROUNDS | 948 | #if ENABLE_WINDOWS_WORKAROUNDS |
930 | setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); | 949 | setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); |
931 | GNUNET_free (childpipename); | 950 | GNUNET_free (childpipename); |
932 | #endif | 951 | #endif |
933 | 952 | ||
934 | if (lscp != NULL) | 953 | if (lscp != NULL) |
954 | { | ||
955 | /* read systemd documentation... */ | ||
956 | GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ()); | ||
957 | setenv ("LISTEN_PID", lpid, 1); | ||
958 | i = 0; | ||
959 | tgt = 3; | ||
960 | while (-1 != lscp[i]) | ||
935 | { | 961 | { |
936 | /* read systemd documentation... */ | 962 | j = i + 1; |
937 | GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid()); | 963 | while (-1 != lscp[j]) |
938 | setenv ("LISTEN_PID", lpid, 1); | 964 | { |
939 | i = 0; | 965 | if (lscp[j] == tgt) |
940 | tgt = 3; | 966 | { |
941 | while (-1 != lscp[i]) | 967 | /* dup away */ |
942 | { | 968 | k = dup (lscp[j]); |
943 | j = i + 1; | 969 | GNUNET_assert (-1 != k); |
944 | while (-1 != lscp[j]) | 970 | GNUNET_assert (0 == close (lscp[j])); |
945 | { | 971 | lscp[j] = k; |
946 | if (lscp[j] == tgt) | 972 | break; |
947 | { | 973 | } |
948 | /* dup away */ | 974 | j++; |
949 | k = dup (lscp[j]); | 975 | } |
950 | GNUNET_assert (-1 != k); | 976 | if (lscp[i] != tgt) |
951 | GNUNET_assert (0 == close (lscp[j])); | 977 | { |
952 | lscp[j] = k; | 978 | /* Bury any existing FD, no matter what; they should all be closed |
953 | break; | 979 | * on exec anyway and the important onces have been dup'ed away */ |
954 | } | 980 | (void) close (tgt); |
955 | j++; | 981 | GNUNET_assert (-1 != dup2 (lscp[i], tgt)); |
956 | } | 982 | } |
957 | if (lscp[i] != tgt) | 983 | /* unset close-on-exec flag */ |
958 | { | 984 | flags = fcntl (tgt, F_GETFD); |
959 | /* Bury any existing FD, no matter what; they should all be closed | 985 | GNUNET_assert (flags >= 0); |
960 | on exec anyway and the important onces have been dup'ed away */ | 986 | flags &= ~FD_CLOEXEC; |
961 | (void) close (tgt); | 987 | fflush (stderr); |
962 | GNUNET_assert (-1 != dup2 (lscp[i], tgt)); | 988 | (void) fcntl (tgt, F_SETFD, flags); |
963 | } | 989 | tgt++; |
964 | /* unset close-on-exec flag */ | 990 | i++; |
965 | flags = fcntl (tgt, F_GETFD); | ||
966 | GNUNET_assert (flags >= 0); | ||
967 | flags &= ~FD_CLOEXEC; | ||
968 | fflush (stderr); | ||
969 | (void) fcntl (tgt, F_SETFD, flags); | ||
970 | tgt++; | ||
971 | i++; | ||
972 | } | ||
973 | GNUNET_snprintf (fds, sizeof (fds), "%u", i); | ||
974 | setenv ("LISTEN_FDS", fds, 1); | ||
975 | } | 991 | } |
992 | GNUNET_snprintf (fds, sizeof (fds), "%u", i); | ||
993 | setenv ("LISTEN_FDS", fds, 1); | ||
994 | } | ||
976 | GNUNET_array_grow (lscp, ls, 0); | 995 | GNUNET_array_grow (lscp, ls, 0); |
977 | execvp (filename, argv); | 996 | execvp (filename, argv); |
978 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); | 997 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); |
@@ -1009,7 +1028,9 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1009 | 1028 | ||
1010 | pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); | 1029 | pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0); |
1011 | 1030 | ||
1012 | alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + strlen (libdir); | 1031 | alloc_len = |
1032 | pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 + | ||
1033 | strlen (libdir); | ||
1013 | 1034 | ||
1014 | pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); | 1035 | pathbuf = GNUNET_malloc (alloc_len * sizeof (char)); |
1015 | 1036 | ||
@@ -1023,7 +1044,7 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1023 | if (alloc_len != pathbuf_len - 1) | 1044 | if (alloc_len != pathbuf_len - 1) |
1024 | { | 1045 | { |
1025 | GNUNET_free (pathbuf); | 1046 | GNUNET_free (pathbuf); |
1026 | errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */ | 1047 | errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */ |
1027 | return NULL; | 1048 | return NULL; |
1028 | } | 1049 | } |
1029 | 1050 | ||
@@ -1036,24 +1057,27 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1036 | /* Check that this is the full path. If it isn't, search. */ | 1057 | /* Check that this is the full path. If it isn't, search. */ |
1037 | if (non_const_filename[1] == ':') | 1058 | if (non_const_filename[1] == ':') |
1038 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); | 1059 | snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename); |
1039 | else if (!SearchPathA (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), path, NULL)) | 1060 | else if (!SearchPathA |
1040 | { | 1061 | (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char), |
1041 | SetErrnoFromWinError (GetLastError ()); | 1062 | path, NULL)) |
1042 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath", non_const_filename); | 1063 | { |
1043 | GNUNET_free (non_const_filename); | 1064 | SetErrnoFromWinError (GetLastError ()); |
1044 | GNUNET_free (pathbuf); | 1065 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath", |
1045 | return NULL; | 1066 | non_const_filename); |
1046 | } | 1067 | GNUNET_free (non_const_filename); |
1068 | GNUNET_free (pathbuf); | ||
1069 | return NULL; | ||
1070 | } | ||
1047 | GNUNET_free (pathbuf); | 1071 | GNUNET_free (pathbuf); |
1048 | GNUNET_free (non_const_filename); | 1072 | GNUNET_free (non_const_filename); |
1049 | 1073 | ||
1050 | /* Count the number of arguments */ | 1074 | /* Count the number of arguments */ |
1051 | arg = (char **) argv; | 1075 | arg = (char **) argv; |
1052 | while (*arg) | 1076 | while (*arg) |
1053 | { | 1077 | { |
1054 | arg++; | 1078 | arg++; |
1055 | argcount++; | 1079 | argcount++; |
1056 | } | 1080 | } |
1057 | 1081 | ||
1058 | /* Allocate a copy argv */ | 1082 | /* Allocate a copy argv */ |
1059 | non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1)); | 1083 | non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1)); |
@@ -1062,33 +1086,33 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1062 | argcount = 0; | 1086 | argcount = 0; |
1063 | arg = (char **) argv; | 1087 | arg = (char **) argv; |
1064 | while (*arg) | 1088 | while (*arg) |
1065 | { | 1089 | { |
1066 | if (arg == argv) | 1090 | if (arg == argv) |
1067 | non_const_argv[argcount] = GNUNET_strdup (path); | 1091 | non_const_argv[argcount] = GNUNET_strdup (path); |
1068 | else | 1092 | else |
1069 | non_const_argv[argcount] = GNUNET_strdup (*arg); | 1093 | non_const_argv[argcount] = GNUNET_strdup (*arg); |
1070 | arg++; | 1094 | arg++; |
1071 | argcount++; | 1095 | argcount++; |
1072 | } | 1096 | } |
1073 | non_const_argv[argcount] = NULL; | 1097 | non_const_argv[argcount] = NULL; |
1074 | 1098 | ||
1075 | /* Count cmd len */ | 1099 | /* Count cmd len */ |
1076 | cmdlen = 1; | 1100 | cmdlen = 1; |
1077 | arg = non_const_argv; | 1101 | arg = non_const_argv; |
1078 | while (*arg) | 1102 | while (*arg) |
1079 | { | 1103 | { |
1080 | cmdlen = cmdlen + strlen (*arg) + 3; | 1104 | cmdlen = cmdlen + strlen (*arg) + 3; |
1081 | arg++; | 1105 | arg++; |
1082 | } | 1106 | } |
1083 | 1107 | ||
1084 | /* Allocate and create cmd */ | 1108 | /* Allocate and create cmd */ |
1085 | cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); | 1109 | cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); |
1086 | arg = non_const_argv; | 1110 | arg = non_const_argv; |
1087 | while (*arg) | 1111 | while (*arg) |
1088 | { | 1112 | { |
1089 | idx += sprintf (idx, "\"%s\" ", *arg); | 1113 | idx += sprintf (idx, "\"%s\" ", *arg); |
1090 | arg++; | 1114 | arg++; |
1091 | } | 1115 | } |
1092 | 1116 | ||
1093 | while (argcount > 0) | 1117 | while (argcount > 0) |
1094 | GNUNET_free (non_const_argv[--argcount]); | 1118 | GNUNET_free (non_const_argv[--argcount]); |
@@ -1098,8 +1122,9 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1098 | start.cb = sizeof (start); | 1122 | start.cb = sizeof (start); |
1099 | 1123 | ||
1100 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, | 1124 | control_pipe = GNUNET_DISK_npipe_create (&childpipename, |
1101 | GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ | | 1125 | GNUNET_DISK_OPEN_WRITE, |
1102 | GNUNET_DISK_PERM_USER_WRITE); | 1126 | GNUNET_DISK_PERM_USER_READ | |
1127 | GNUNET_DISK_PERM_USER_WRITE); | ||
1103 | if (control_pipe == NULL) | 1128 | if (control_pipe == NULL) |
1104 | { | 1129 | { |
1105 | GNUNET_free (cmd); | 1130 | GNUNET_free (cmd); |
@@ -1108,7 +1133,8 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1108 | } | 1133 | } |
1109 | 1134 | ||
1110 | #if DEBUG_OS | 1135 | #if DEBUG_OS |
1111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", childpipename); | 1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1137 | "Opened the parent end of the pipe `%s'\n", childpipename); | ||
1112 | #endif | 1138 | #endif |
1113 | 1139 | ||
1114 | GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); | 1140 | GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); |
@@ -1121,13 +1147,13 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1121 | if (!CreateProcess | 1147 | if (!CreateProcess |
1122 | (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED, | 1148 | (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS | CREATE_SUSPENDED, |
1123 | env_block, NULL, &start, &proc)) | 1149 | env_block, NULL, &start, &proc)) |
1124 | { | 1150 | { |
1125 | SetErrnoFromWinError (GetLastError ()); | 1151 | SetErrnoFromWinError (GetLastError ()); |
1126 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); | 1152 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); |
1127 | GNUNET_free (env_block); | 1153 | GNUNET_free (env_block); |
1128 | GNUNET_free (cmd); | 1154 | GNUNET_free (cmd); |
1129 | return NULL; | 1155 | return NULL; |
1130 | } | 1156 | } |
1131 | 1157 | ||
1132 | GNUNET_free (env_block); | 1158 | GNUNET_free (env_block); |
1133 | 1159 | ||
@@ -1155,8 +1181,8 @@ GNUNET_OS_start_process_v (const int *lsocks, | |||
1155 | * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise | 1181 | * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise |
1156 | */ | 1182 | */ |
1157 | int | 1183 | int |
1158 | GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, | 1184 | GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, |
1159 | enum GNUNET_OS_ProcessStatusType *type, | 1185 | enum GNUNET_OS_ProcessStatusType *type, |
1160 | unsigned long *code) | 1186 | unsigned long *code) |
1161 | { | 1187 | { |
1162 | #ifndef MINGW | 1188 | #ifndef MINGW |
@@ -1166,48 +1192,48 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, | |||
1166 | GNUNET_assert (0 != proc); | 1192 | GNUNET_assert (0 != proc); |
1167 | ret = waitpid (proc->pid, &status, WNOHANG); | 1193 | ret = waitpid (proc->pid, &status, WNOHANG); |
1168 | if (ret < 0) | 1194 | if (ret < 0) |
1169 | { | 1195 | { |
1170 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 1196 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
1171 | return GNUNET_SYSERR; | 1197 | return GNUNET_SYSERR; |
1172 | } | 1198 | } |
1173 | if (0 == ret) | 1199 | if (0 == ret) |
1174 | { | 1200 | { |
1175 | *type = GNUNET_OS_PROCESS_RUNNING; | 1201 | *type = GNUNET_OS_PROCESS_RUNNING; |
1176 | *code = 0; | 1202 | *code = 0; |
1177 | return GNUNET_NO; | 1203 | return GNUNET_NO; |
1178 | } | 1204 | } |
1179 | if (proc->pid != ret) | 1205 | if (proc->pid != ret) |
1180 | { | 1206 | { |
1181 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 1207 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
1182 | return GNUNET_SYSERR; | 1208 | return GNUNET_SYSERR; |
1183 | } | 1209 | } |
1184 | if (WIFEXITED (status)) | 1210 | if (WIFEXITED (status)) |
1185 | { | 1211 | { |
1186 | *type = GNUNET_OS_PROCESS_EXITED; | 1212 | *type = GNUNET_OS_PROCESS_EXITED; |
1187 | *code = WEXITSTATUS (status); | 1213 | *code = WEXITSTATUS (status); |
1188 | } | 1214 | } |
1189 | else if (WIFSIGNALED (status)) | 1215 | else if (WIFSIGNALED (status)) |
1190 | { | 1216 | { |
1191 | *type = GNUNET_OS_PROCESS_SIGNALED; | 1217 | *type = GNUNET_OS_PROCESS_SIGNALED; |
1192 | *code = WTERMSIG (status); | 1218 | *code = WTERMSIG (status); |
1193 | } | 1219 | } |
1194 | else if (WIFSTOPPED (status)) | 1220 | else if (WIFSTOPPED (status)) |
1195 | { | 1221 | { |
1196 | *type = GNUNET_OS_PROCESS_SIGNALED; | 1222 | *type = GNUNET_OS_PROCESS_SIGNALED; |
1197 | *code = WSTOPSIG (status); | 1223 | *code = WSTOPSIG (status); |
1198 | } | 1224 | } |
1199 | #ifdef WIFCONTINUED | 1225 | #ifdef WIFCONTINUED |
1200 | else if (WIFCONTINUED (status)) | 1226 | else if (WIFCONTINUED (status)) |
1201 | { | 1227 | { |
1202 | *type = GNUNET_OS_PROCESS_RUNNING; | 1228 | *type = GNUNET_OS_PROCESS_RUNNING; |
1203 | *code = 0; | 1229 | *code = 0; |
1204 | } | 1230 | } |
1205 | #endif | 1231 | #endif |
1206 | else | 1232 | else |
1207 | { | 1233 | { |
1208 | *type = GNUNET_OS_PROCESS_UNKNOWN; | 1234 | *type = GNUNET_OS_PROCESS_UNKNOWN; |
1209 | *code = 0; | 1235 | *code = 0; |
1210 | } | 1236 | } |
1211 | #else | 1237 | #else |
1212 | HANDLE h; | 1238 | HANDLE h; |
1213 | DWORD c, error_code, ret; | 1239 | DWORD c, error_code, ret; |
@@ -1215,10 +1241,11 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, | |||
1215 | h = proc->handle; | 1241 | h = proc->handle; |
1216 | ret = proc->pid; | 1242 | ret = proc->pid; |
1217 | if (h == NULL || ret == 0) | 1243 | if (h == NULL || ret == 0) |
1218 | { | 1244 | { |
1219 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", ret, h); | 1245 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1220 | return GNUNET_SYSERR; | 1246 | "Invalid process information {%d, %08X}\n", ret, h); |
1221 | } | 1247 | return GNUNET_SYSERR; |
1248 | } | ||
1222 | if (h == NULL) | 1249 | if (h == NULL) |
1223 | h = GetCurrentProcess (); | 1250 | h = GetCurrentProcess (); |
1224 | 1251 | ||
@@ -1227,16 +1254,16 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, | |||
1227 | error_code = GetLastError (); | 1254 | error_code = GetLastError (); |
1228 | if (ret == 0 || error_code != NO_ERROR) | 1255 | if (ret == 0 || error_code != NO_ERROR) |
1229 | { | 1256 | { |
1230 | SetErrnoFromWinError (error_code); | 1257 | SetErrnoFromWinError (error_code); |
1231 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess"); | 1258 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess"); |
1232 | return GNUNET_SYSERR; | 1259 | return GNUNET_SYSERR; |
1233 | } | 1260 | } |
1234 | if (STILL_ACTIVE == c) | 1261 | if (STILL_ACTIVE == c) |
1235 | { | 1262 | { |
1236 | *type = GNUNET_OS_PROCESS_RUNNING; | 1263 | *type = GNUNET_OS_PROCESS_RUNNING; |
1237 | *code = 0; | 1264 | *code = 0; |
1238 | return GNUNET_NO; | 1265 | return GNUNET_NO; |
1239 | } | 1266 | } |
1240 | *type = GNUNET_OS_PROCESS_EXITED; | 1267 | *type = GNUNET_OS_PROCESS_EXITED; |
1241 | *code = c; | 1268 | *code = c; |
1242 | #endif | 1269 | #endif |
@@ -1256,6 +1283,7 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) | |||
1256 | 1283 | ||
1257 | #ifndef MINGW | 1284 | #ifndef MINGW |
1258 | pid_t pid = proc->pid; | 1285 | pid_t pid = proc->pid; |
1286 | |||
1259 | if (pid != waitpid (pid, NULL, 0)) | 1287 | if (pid != waitpid (pid, NULL, 0)) |
1260 | return GNUNET_SYSERR; | 1288 | return GNUNET_SYSERR; |
1261 | return GNUNET_OK; | 1289 | return GNUNET_OK; |
@@ -1265,21 +1293,19 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) | |||
1265 | 1293 | ||
1266 | h = proc->handle; | 1294 | h = proc->handle; |
1267 | if (NULL == h) | 1295 | if (NULL == h) |
1268 | { | 1296 | { |
1269 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1297 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1270 | "Invalid process information {%d, %08X}\n", | 1298 | "Invalid process information {%d, %08X}\n", proc->pid, h); |
1271 | proc->pid, | 1299 | return GNUNET_SYSERR; |
1272 | h); | 1300 | } |
1273 | return GNUNET_SYSERR; | ||
1274 | } | ||
1275 | if (h == NULL) | 1301 | if (h == NULL) |
1276 | h = GetCurrentProcess (); | 1302 | h = GetCurrentProcess (); |
1277 | 1303 | ||
1278 | if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) | 1304 | if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) |
1279 | { | 1305 | { |
1280 | SetErrnoFromWinError (GetLastError ()); | 1306 | SetErrnoFromWinError (GetLastError ()); |
1281 | ret = GNUNET_SYSERR; | 1307 | ret = GNUNET_SYSERR; |
1282 | } | 1308 | } |
1283 | else | 1309 | else |
1284 | ret = GNUNET_OK; | 1310 | ret = GNUNET_OK; |
1285 | 1311 | ||
@@ -1303,7 +1329,7 @@ struct GNUNET_OS_CommandHandle | |||
1303 | * Handle to the output pipe. | 1329 | * Handle to the output pipe. |
1304 | */ | 1330 | */ |
1305 | struct GNUNET_DISK_PipeHandle *opipe; | 1331 | struct GNUNET_DISK_PipeHandle *opipe; |
1306 | 1332 | ||
1307 | /** | 1333 | /** |
1308 | * Read-end of output pipe. | 1334 | * Read-end of output pipe. |
1309 | */ | 1335 | */ |
@@ -1318,12 +1344,12 @@ struct GNUNET_OS_CommandHandle | |||
1318 | * Closure for 'proc'. | 1344 | * Closure for 'proc'. |
1319 | */ | 1345 | */ |
1320 | void *proc_cls; | 1346 | void *proc_cls; |
1321 | 1347 | ||
1322 | /** | 1348 | /** |
1323 | * Buffer for the output. | 1349 | * Buffer for the output. |
1324 | */ | 1350 | */ |
1325 | char buf[1024]; | 1351 | char buf[1024]; |
1326 | 1352 | ||
1327 | /** | 1353 | /** |
1328 | * Task reading from pipe. | 1354 | * Task reading from pipe. |
1329 | */ | 1355 | */ |
@@ -1353,13 +1379,12 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd) | |||
1353 | { | 1379 | { |
1354 | 1380 | ||
1355 | if (cmd->proc != NULL) | 1381 | if (cmd->proc != NULL) |
1356 | { | 1382 | { |
1357 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); | 1383 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); |
1358 | GNUNET_SCHEDULER_cancel (cmd->rtask); | 1384 | GNUNET_SCHEDULER_cancel (cmd->rtask); |
1359 | } | 1385 | } |
1360 | (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL); | 1386 | (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL); |
1361 | GNUNET_break (GNUNET_OK == | 1387 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip)); |
1362 | GNUNET_OS_process_wait (cmd->eip)); | ||
1363 | GNUNET_OS_process_close (cmd->eip); | 1388 | GNUNET_OS_process_close (cmd->eip); |
1364 | GNUNET_DISK_pipe_close (cmd->opipe); | 1389 | GNUNET_DISK_pipe_close (cmd->opipe); |
1365 | GNUNET_free (cmd); | 1390 | GNUNET_free (cmd); |
@@ -1373,8 +1398,7 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd) | |||
1373 | * @param tc scheduler context | 1398 | * @param tc scheduler context |
1374 | */ | 1399 | */ |
1375 | static void | 1400 | static void |
1376 | cmd_read (void *cls, | 1401 | cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1377 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1378 | { | 1402 | { |
1379 | struct GNUNET_OS_CommandHandle *cmd = cls; | 1403 | struct GNUNET_OS_CommandHandle *cmd = cls; |
1380 | GNUNET_OS_LineProcessor proc; | 1404 | GNUNET_OS_LineProcessor proc; |
@@ -1382,47 +1406,42 @@ cmd_read (void *cls, | |||
1382 | ssize_t ret; | 1406 | ssize_t ret; |
1383 | 1407 | ||
1384 | cmd->rtask = GNUNET_SCHEDULER_NO_TASK; | 1408 | cmd->rtask = GNUNET_SCHEDULER_NO_TASK; |
1385 | if (GNUNET_YES != | 1409 | if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) |
1386 | GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, | 1410 | { |
1387 | cmd->r)) | 1411 | /* timeout, shutdown, etc. */ |
1388 | { | 1412 | proc = cmd->proc; |
1389 | /* timeout, shutdown, etc. */ | 1413 | cmd->proc = NULL; |
1390 | proc = cmd->proc; | 1414 | proc (cmd->proc_cls, NULL); |
1391 | cmd->proc = NULL; | 1415 | return; |
1392 | proc (cmd->proc_cls, NULL); | 1416 | } |
1393 | return; | ||
1394 | } | ||
1395 | ret = GNUNET_DISK_file_read (cmd->r, | 1417 | ret = GNUNET_DISK_file_read (cmd->r, |
1396 | &cmd->buf[cmd->off], | 1418 | &cmd->buf[cmd->off], |
1397 | sizeof (cmd->buf)-cmd->off); | 1419 | sizeof (cmd->buf) - cmd->off); |
1398 | if (ret <= 0) | 1420 | if (ret <= 0) |
1421 | { | ||
1422 | if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) | ||
1399 | { | 1423 | { |
1400 | if ( (cmd->off > 0) && (cmd->off < sizeof (cmd->buf)) ) | 1424 | cmd->buf[cmd->off] = '\0'; |
1401 | { | 1425 | cmd->proc (cmd->proc_cls, cmd->buf); |
1402 | cmd->buf[cmd->off] = '\0'; | 1426 | } |
1403 | cmd->proc (cmd->proc_cls, cmd->buf); | 1427 | proc = cmd->proc; |
1404 | } | 1428 | cmd->proc = NULL; |
1405 | proc = cmd->proc; | 1429 | proc (cmd->proc_cls, NULL); |
1406 | cmd->proc = NULL; | 1430 | return; |
1407 | proc (cmd->proc_cls, NULL); | 1431 | } |
1408 | return; | ||
1409 | } | ||
1410 | end = memchr (&cmd->buf[cmd->off], '\n', ret); | 1432 | end = memchr (&cmd->buf[cmd->off], '\n', ret); |
1411 | cmd->off += ret; | 1433 | cmd->off += ret; |
1412 | while (end != NULL) | 1434 | while (end != NULL) |
1413 | { | 1435 | { |
1414 | *end = '\0'; | 1436 | *end = '\0'; |
1415 | cmd->proc (cmd->proc_cls, cmd->buf); | 1437 | cmd->proc (cmd->proc_cls, cmd->buf); |
1416 | memmove (cmd->buf, | 1438 | memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf)); |
1417 | end + 1, | 1439 | cmd->off -= (end + 1 - cmd->buf); |
1418 | cmd->off - (end + 1 - cmd->buf)); | 1440 | end = memchr (cmd->buf, '\n', cmd->off); |
1419 | cmd->off -= (end + 1 - cmd->buf); | 1441 | } |
1420 | end = memchr (cmd->buf, '\n', cmd->off); | 1442 | cmd->rtask = |
1421 | } | 1443 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
1422 | cmd->rtask = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining (cmd->timeout), | 1444 | (cmd->timeout), cmd->r, &cmd_read, cmd); |
1423 | cmd->r, | ||
1424 | &cmd_read, | ||
1425 | cmd); | ||
1426 | } | 1445 | } |
1427 | 1446 | ||
1428 | 1447 | ||
@@ -1439,30 +1458,26 @@ cmd_read (void *cls, | |||
1439 | */ | 1458 | */ |
1440 | struct GNUNET_OS_CommandHandle * | 1459 | struct GNUNET_OS_CommandHandle * |
1441 | GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, | 1460 | GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, |
1442 | void *proc_cls, | 1461 | void *proc_cls, |
1443 | struct GNUNET_TIME_Relative timeout, | 1462 | struct GNUNET_TIME_Relative timeout, |
1444 | const char *binary, | 1463 | const char *binary, ...) |
1445 | ...) | ||
1446 | { | 1464 | { |
1447 | struct GNUNET_OS_CommandHandle *cmd; | 1465 | struct GNUNET_OS_CommandHandle *cmd; |
1448 | struct GNUNET_OS_Process *eip; | 1466 | struct GNUNET_OS_Process *eip; |
1449 | struct GNUNET_DISK_PipeHandle *opipe; | 1467 | struct GNUNET_DISK_PipeHandle *opipe; |
1450 | va_list ap; | 1468 | va_list ap; |
1451 | 1469 | ||
1452 | opipe = GNUNET_DISK_pipe (GNUNET_YES, | 1470 | opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); |
1453 | GNUNET_NO, | ||
1454 | GNUNET_YES); | ||
1455 | if (NULL == opipe) | 1471 | if (NULL == opipe) |
1456 | return NULL; | 1472 | return NULL; |
1457 | va_start (ap, binary); | 1473 | va_start (ap, binary); |
1458 | eip = GNUNET_OS_start_process_va (NULL, opipe, | 1474 | eip = GNUNET_OS_start_process_va (NULL, opipe, binary, ap); |
1459 | binary, ap); | ||
1460 | va_end (ap); | 1475 | va_end (ap); |
1461 | if (NULL == eip) | 1476 | if (NULL == eip) |
1462 | { | 1477 | { |
1463 | GNUNET_DISK_pipe_close (opipe); | 1478 | GNUNET_DISK_pipe_close (opipe); |
1464 | return NULL; | 1479 | return NULL; |
1465 | } | 1480 | } |
1466 | GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE); | 1481 | GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE); |
1467 | cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle)); | 1482 | cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle)); |
1468 | cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1483 | cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -1470,12 +1485,8 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, | |||
1470 | cmd->opipe = opipe; | 1485 | cmd->opipe = opipe; |
1471 | cmd->proc = proc; | 1486 | cmd->proc = proc; |
1472 | cmd->proc_cls = proc_cls; | 1487 | cmd->proc_cls = proc_cls; |
1473 | cmd->r = GNUNET_DISK_pipe_handle (opipe, | 1488 | cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ); |
1474 | GNUNET_DISK_PIPE_END_READ); | 1489 | cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd); |
1475 | cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, | ||
1476 | cmd->r, | ||
1477 | &cmd_read, | ||
1478 | cmd); | ||
1479 | return cmd; | 1490 | return cmd; |
1480 | } | 1491 | } |
1481 | 1492 | ||
diff --git a/src/util/peer.c b/src/util/peer.c index 96ac271c0..91a706040 100644 --- a/src/util/peer.c +++ b/src/util/peer.c | |||
@@ -91,14 +91,14 @@ GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid) | |||
91 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); | 91 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); |
92 | e = (off == 0) ? NULL : &table[off]; | 92 | e = (off == 0) ? NULL : &table[off]; |
93 | if (e != NULL) | 93 | if (e != NULL) |
94 | { | 94 | { |
95 | GNUNET_assert (e->rc > 0); | 95 | GNUNET_assert (e->rc > 0); |
96 | return e->pid; | 96 | return e->pid; |
97 | } | 97 | } |
98 | else | 98 | else |
99 | { | 99 | { |
100 | return 0; | 100 | return 0; |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
104 | /** | 104 | /** |
@@ -123,24 +123,24 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
123 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); | 123 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); |
124 | e = (off == 0) ? NULL : &table[off]; | 124 | e = (off == 0) ? NULL : &table[off]; |
125 | if (e != NULL) | 125 | if (e != NULL) |
126 | { | 126 | { |
127 | GNUNET_assert (e->rc > 0); | 127 | GNUNET_assert (e->rc > 0); |
128 | e->rc++; | 128 | e->rc++; |
129 | return e->pid; | 129 | return e->pid; |
130 | } | 130 | } |
131 | ret = free_list_start; | 131 | ret = free_list_start; |
132 | if (ret == size) | 132 | if (ret == size) |
133 | { | 133 | { |
134 | GNUNET_array_grow (table, size, size + 16); | 134 | GNUNET_array_grow (table, size, size + 16); |
135 | for (i = ret; i < size; i++) | 135 | for (i = ret; i < size; i++) |
136 | table[i].pid = i + 1; | 136 | table[i].pid = i + 1; |
137 | } | 137 | } |
138 | if (ret == 0) | 138 | if (ret == 0) |
139 | { | 139 | { |
140 | table[0].pid = 0; | 140 | table[0].pid = 0; |
141 | table[0].rc = 1; | 141 | table[0].rc = 1; |
142 | ret = 1; | 142 | ret = 1; |
143 | } | 143 | } |
144 | GNUNET_assert (ret < size); | 144 | GNUNET_assert (ret < size); |
145 | GNUNET_assert (table[ret].rc == 0); | 145 | GNUNET_assert (table[ret].rc == 0); |
146 | free_list_start = table[ret].pid; | 146 | free_list_start = table[ret].pid; |
@@ -148,10 +148,10 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
148 | table[ret].rc = 1; | 148 | table[ret].rc = 1; |
149 | table[ret].pid = ret; | 149 | table[ret].pid = ret; |
150 | GNUNET_break (GNUNET_OK == | 150 | GNUNET_break (GNUNET_OK == |
151 | GNUNET_CONTAINER_multihashmap_put (map, | 151 | GNUNET_CONTAINER_multihashmap_put (map, |
152 | &pid->hashPubKey, | 152 | &pid->hashPubKey, |
153 | (void *) (long) ret, | 153 | (void *) (long) ret, |
154 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 154 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
155 | return ret; | 155 | return ret; |
156 | } | 156 | } |
157 | 157 | ||
@@ -163,7 +163,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
163 | * @param count size of the ids array | 163 | * @param count size of the ids array |
164 | */ | 164 | */ |
165 | void | 165 | void |
166 | GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) | 166 | GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count) |
167 | { | 167 | { |
168 | int i; | 168 | int i; |
169 | GNUNET_PEER_Id id; | 169 | GNUNET_PEER_Id id; |
@@ -171,23 +171,24 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) | |||
171 | if (count == 0) | 171 | if (count == 0) |
172 | return; | 172 | return; |
173 | for (i = count - 1; i >= 0; i--) | 173 | for (i = count - 1; i >= 0; i--) |
174 | { | ||
175 | id = ids[i]; | ||
176 | if (id == 0) | ||
177 | continue; | ||
178 | GNUNET_assert (id < size); | ||
179 | GNUNET_assert (table[id].rc > 0); | ||
180 | table[id].rc--; | ||
181 | if (table[id].rc == 0) | ||
174 | { | 182 | { |
175 | id = ids[i]; | 183 | GNUNET_break (GNUNET_OK == |
176 | if (id == 0) | 184 | GNUNET_CONTAINER_multihashmap_remove (map, |
177 | continue; | 185 | &table[id]. |
178 | GNUNET_assert (id < size); | 186 | id.hashPubKey, |
179 | GNUNET_assert (table[id].rc > 0); | 187 | (void *) (long) id)); |
180 | table[id].rc--; | 188 | table[id].pid = free_list_start; |
181 | if (table[id].rc == 0) | 189 | free_list_start = id; |
182 | { | ||
183 | GNUNET_break (GNUNET_OK == | ||
184 | GNUNET_CONTAINER_multihashmap_remove (map, | ||
185 | &table[id].id.hashPubKey, | ||
186 | (void*) (long) id)); | ||
187 | table[id].pid = free_list_start; | ||
188 | free_list_start = id; | ||
189 | } | ||
190 | } | 190 | } |
191 | } | ||
191 | } | 192 | } |
192 | 193 | ||
193 | 194 | ||
@@ -207,14 +208,15 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta) | |||
207 | GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); | 208 | GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); |
208 | table[id].rc += delta; | 209 | table[id].rc += delta; |
209 | if (table[id].rc == 0) | 210 | if (table[id].rc == 0) |
210 | { | 211 | { |
211 | GNUNET_break (GNUNET_OK == | 212 | GNUNET_break (GNUNET_OK == |
212 | GNUNET_CONTAINER_multihashmap_remove (map, | 213 | GNUNET_CONTAINER_multihashmap_remove (map, |
213 | &table[id].id.hashPubKey, | 214 | &table[id]. |
214 | (void*) (long) id)); | 215 | id.hashPubKey, |
215 | table[id].pid = free_list_start; | 216 | (void *) (long) id)); |
216 | free_list_start = id; | 217 | table[id].pid = free_list_start; |
217 | } | 218 | free_list_start = id; |
219 | } | ||
218 | } | 220 | } |
219 | 221 | ||
220 | 222 | ||
@@ -228,11 +230,11 @@ void | |||
228 | GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) | 230 | GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) |
229 | { | 231 | { |
230 | if (id == 0) | 232 | if (id == 0) |
231 | { | 233 | { |
232 | memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); | 234 | memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); |
233 | GNUNET_break (0); | 235 | GNUNET_break (0); |
234 | return; | 236 | return; |
235 | } | 237 | } |
236 | GNUNET_assert (id < size); | 238 | GNUNET_assert (id < size); |
237 | GNUNET_assert (table[id].rc > 0); | 239 | GNUNET_assert (table[id].rc > 0); |
238 | *pid = table[id].id; | 240 | *pid = table[id].id; |
diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c index 0b4067b15..d883776b4 100644 --- a/src/util/perf_crypto_hash.c +++ b/src/util/perf_crypto_hash.c | |||
@@ -42,11 +42,11 @@ perfHash () | |||
42 | memset (buf, 1, 1024 * 64); | 42 | memset (buf, 1, 1024 * 64); |
43 | GNUNET_CRYPTO_hash ("foo", 3, &hc1); | 43 | GNUNET_CRYPTO_hash ("foo", 3, &hc1); |
44 | for (i = 0; i < 1024; i++) | 44 | for (i = 0; i < 1024; i++) |
45 | { | 45 | { |
46 | GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2); | 46 | GNUNET_CRYPTO_hash (&hc1, sizeof (GNUNET_HashCode), &hc2); |
47 | GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1); | 47 | GNUNET_CRYPTO_hash (&hc2, sizeof (GNUNET_HashCode), &hc1); |
48 | GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3); | 48 | GNUNET_CRYPTO_hash (buf, 1024 * 64, &hc3); |
49 | } | 49 | } |
50 | GNUNET_free (buf); | 50 | GNUNET_free (buf); |
51 | } | 51 | } |
52 | 52 | ||
@@ -60,7 +60,10 @@ main (int argc, char *argv[]) | |||
60 | printf ("Hash perf took %llu ms\n", | 60 | printf ("Hash perf took %llu ms\n", |
61 | (unsigned long long) | 61 | (unsigned long long) |
62 | GNUNET_TIME_absolute_get_duration (start).rel_value); | 62 | GNUNET_TIME_absolute_get_duration (start).rel_value); |
63 | GAUGER ("UTIL", "Cryptographic hashing", 1024 * 64 * 1024 / (1+GNUNET_TIME_absolute_get_duration (start).rel_value), "kb/s"); | 63 | GAUGER ("UTIL", "Cryptographic hashing", |
64 | 1024 * 64 * 1024 / (1 + | ||
65 | GNUNET_TIME_absolute_get_duration | ||
66 | (start).rel_value), "kb/s"); | ||
64 | return 0; | 67 | return 0; |
65 | } | 68 | } |
66 | 69 | ||
diff --git a/src/util/plugin.c b/src/util/plugin.c index 4e960b4fe..b1c979dff 100644 --- a/src/util/plugin.c +++ b/src/util/plugin.c | |||
@@ -73,7 +73,7 @@ static struct PluginList *plugins; | |||
73 | /** | 73 | /** |
74 | * Setup libtool paths. | 74 | * Setup libtool paths. |
75 | */ | 75 | */ |
76 | static void | 76 | static void |
77 | plugin_init () | 77 | plugin_init () |
78 | { | 78 | { |
79 | int err; | 79 | int err; |
@@ -83,34 +83,31 @@ plugin_init () | |||
83 | 83 | ||
84 | err = lt_dlinit (); | 84 | err = lt_dlinit (); |
85 | if (err > 0) | 85 | if (err > 0) |
86 | { | 86 | { |
87 | fprintf (stderr, | 87 | fprintf (stderr, |
88 | _("Initialization of plugin mechanism failed: %s!\n"), | 88 | _("Initialization of plugin mechanism failed: %s!\n"), |
89 | lt_dlerror ()); | 89 | lt_dlerror ()); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | opath = lt_dlgetsearchpath (); | 92 | opath = lt_dlgetsearchpath (); |
93 | if (opath != NULL) | 93 | if (opath != NULL) |
94 | old_dlsearchpath = GNUNET_strdup (opath); | 94 | old_dlsearchpath = GNUNET_strdup (opath); |
95 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); | 95 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); |
96 | if (path != NULL) | 96 | if (path != NULL) |
97 | { | ||
98 | if (opath != NULL) | ||
97 | { | 99 | { |
98 | if (opath != NULL) | 100 | GNUNET_asprintf (&cpath, "%s:%s", opath, path); |
99 | { | 101 | lt_dlsetsearchpath (cpath); |
100 | GNUNET_asprintf (&cpath, | 102 | GNUNET_free (path); |
101 | "%s:%s", | 103 | GNUNET_free (cpath); |
102 | opath, | ||
103 | path); | ||
104 | lt_dlsetsearchpath (cpath); | ||
105 | GNUNET_free (path); | ||
106 | GNUNET_free (cpath); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | lt_dlsetsearchpath (path); | ||
111 | GNUNET_free (path); | ||
112 | } | ||
113 | } | 104 | } |
105 | else | ||
106 | { | ||
107 | lt_dlsetsearchpath (path); | ||
108 | GNUNET_free (path); | ||
109 | } | ||
110 | } | ||
114 | } | 111 | } |
115 | 112 | ||
116 | 113 | ||
@@ -122,10 +119,10 @@ plugin_fini () | |||
122 | { | 119 | { |
123 | lt_dlsetsearchpath (old_dlsearchpath); | 120 | lt_dlsetsearchpath (old_dlsearchpath); |
124 | if (old_dlsearchpath != NULL) | 121 | if (old_dlsearchpath != NULL) |
125 | { | 122 | { |
126 | GNUNET_free (old_dlsearchpath); | 123 | GNUNET_free (old_dlsearchpath); |
127 | old_dlsearchpath = NULL; | 124 | old_dlsearchpath = NULL; |
128 | } | 125 | } |
129 | lt_dlexit (); | 126 | lt_dlexit (); |
130 | } | 127 | } |
131 | 128 | ||
@@ -167,23 +164,23 @@ GNUNET_PLUGIN_test (const char *library_name) | |||
167 | GNUNET_PLUGIN_Callback init; | 164 | GNUNET_PLUGIN_Callback init; |
168 | struct PluginList plug; | 165 | struct PluginList plug; |
169 | 166 | ||
170 | if (! initialized) | 167 | if (!initialized) |
171 | { | 168 | { |
172 | initialized = GNUNET_YES; | 169 | initialized = GNUNET_YES; |
173 | plugin_init (); | 170 | plugin_init (); |
174 | } | 171 | } |
175 | libhandle = lt_dlopenext (library_name); | 172 | libhandle = lt_dlopenext (library_name); |
176 | if (libhandle == NULL) | 173 | if (libhandle == NULL) |
177 | return GNUNET_NO; | 174 | return GNUNET_NO; |
178 | plug.handle = libhandle; | 175 | plug.handle = libhandle; |
179 | plug.name = (char*) library_name; | 176 | plug.name = (char *) library_name; |
180 | init = resolve_function (&plug, "init"); | 177 | init = resolve_function (&plug, "init"); |
181 | if (init == NULL) | 178 | if (init == NULL) |
182 | { | 179 | { |
183 | GNUNET_break (0); | 180 | GNUNET_break (0); |
184 | lt_dlclose (libhandle); | 181 | lt_dlclose (libhandle); |
185 | return GNUNET_NO; | 182 | return GNUNET_NO; |
186 | } | 183 | } |
187 | lt_dlclose (libhandle); | 184 | lt_dlclose (libhandle); |
188 | return GNUNET_YES; | 185 | return GNUNET_YES; |
189 | } | 186 | } |
@@ -209,19 +206,19 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) | |||
209 | GNUNET_PLUGIN_Callback init; | 206 | GNUNET_PLUGIN_Callback init; |
210 | void *ret; | 207 | void *ret; |
211 | 208 | ||
212 | if (! initialized) | 209 | if (!initialized) |
213 | { | 210 | { |
214 | initialized = GNUNET_YES; | 211 | initialized = GNUNET_YES; |
215 | plugin_init (); | 212 | plugin_init (); |
216 | } | 213 | } |
217 | libhandle = lt_dlopenext (library_name); | 214 | libhandle = lt_dlopenext (library_name); |
218 | if (libhandle == NULL) | 215 | if (libhandle == NULL) |
219 | { | 216 | { |
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
221 | _("`%s' failed for library `%s' with error: %s\n"), | 218 | _("`%s' failed for library `%s' with error: %s\n"), |
222 | "lt_dlopenext", library_name, lt_dlerror ()); | 219 | "lt_dlopenext", library_name, lt_dlerror ()); |
223 | return NULL; | 220 | return NULL; |
224 | } | 221 | } |
225 | plug = GNUNET_malloc (sizeof (struct PluginList)); | 222 | plug = GNUNET_malloc (sizeof (struct PluginList)); |
226 | plug->handle = libhandle; | 223 | plug->handle = libhandle; |
227 | plug->name = GNUNET_strdup (library_name); | 224 | plug->name = GNUNET_strdup (library_name); |
@@ -229,13 +226,13 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) | |||
229 | plugins = plug; | 226 | plugins = plug; |
230 | init = resolve_function (plug, "init"); | 227 | init = resolve_function (plug, "init"); |
231 | if ((init == NULL) || (NULL == (ret = init (arg)))) | 228 | if ((init == NULL) || (NULL == (ret = init (arg)))) |
232 | { | 229 | { |
233 | lt_dlclose (libhandle); | 230 | lt_dlclose (libhandle); |
234 | GNUNET_free (plug->name); | 231 | GNUNET_free (plug->name); |
235 | plugins = plug->next; | 232 | plugins = plug->next; |
236 | GNUNET_free (plug); | 233 | GNUNET_free (plug); |
237 | return NULL; | 234 | return NULL; |
238 | } | 235 | } |
239 | return ret; | 236 | return ret; |
240 | } | 237 | } |
241 | 238 | ||
@@ -259,10 +256,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg) | |||
259 | prev = NULL; | 256 | prev = NULL; |
260 | pos = plugins; | 257 | pos = plugins; |
261 | while ((pos != NULL) && (0 != strcmp (pos->name, library_name))) | 258 | while ((pos != NULL) && (0 != strcmp (pos->name, library_name))) |
262 | { | 259 | { |
263 | prev = pos; | 260 | prev = pos; |
264 | pos = pos->next; | 261 | pos = pos->next; |
265 | } | 262 | } |
266 | if (pos == NULL) | 263 | if (pos == NULL) |
267 | return NULL; | 264 | return NULL; |
268 | 265 | ||
@@ -278,10 +275,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg) | |||
278 | GNUNET_free (pos->name); | 275 | GNUNET_free (pos->name); |
279 | GNUNET_free (pos); | 276 | GNUNET_free (pos); |
280 | if (plugins == NULL) | 277 | if (plugins == NULL) |
281 | { | 278 | { |
282 | plugin_fini(); | 279 | plugin_fini (); |
283 | initialized = GNUNET_NO; | 280 | initialized = GNUNET_NO; |
284 | } | 281 | } |
285 | return ret; | 282 | return ret; |
286 | } | 283 | } |
287 | 284 | ||
diff --git a/src/util/program.c b/src/util/program.c index b91d0f59e..cccb7db73 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -95,9 +95,12 @@ cmd_sorter (__const void *a1, __const void *a2) | |||
95 | { | 95 | { |
96 | __const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; | 96 | __const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; |
97 | __const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; | 97 | __const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; |
98 | if (toupper ( (unsigned char) c1->shortName) > toupper ( (unsigned char) c2->shortName)) | 98 | |
99 | if (toupper ((unsigned char) c1->shortName) > | ||
100 | toupper ((unsigned char) c2->shortName)) | ||
99 | return 1; | 101 | return 1; |
100 | if (toupper ( (unsigned char) c1->shortName) < toupper ( (unsigned char) c2->shortName)) | 102 | if (toupper ((unsigned char) c1->shortName) < |
103 | toupper ((unsigned char) c2->shortName)) | ||
101 | return -1; | 104 | return -1; |
102 | if (c1->shortName > c2->shortName) | 105 | if (c1->shortName > c2->shortName) |
103 | return 1; | 106 | return 1; |
@@ -138,6 +141,7 @@ GNUNET_PROGRAM_run (int argc, | |||
138 | unsigned long long skew_variance; | 141 | unsigned long long skew_variance; |
139 | long long clock_offset; | 142 | long long clock_offset; |
140 | struct GNUNET_CONFIGURATION_Handle *cfg; | 143 | struct GNUNET_CONFIGURATION_Handle *cfg; |
144 | |||
141 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { | 145 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { |
142 | GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), | 146 | GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), |
143 | GNUNET_GETOPT_OPTION_HELP (binaryHelp), | 147 | GNUNET_GETOPT_OPTION_HELP (binaryHelp), |
@@ -153,29 +157,29 @@ GNUNET_PROGRAM_run (int argc, | |||
153 | logfile = NULL; | 157 | logfile = NULL; |
154 | gargs = getenv ("GNUNET_ARGS"); | 158 | gargs = getenv ("GNUNET_ARGS"); |
155 | if (gargs != NULL) | 159 | if (gargs != NULL) |
160 | { | ||
161 | char **gargv; | ||
162 | unsigned int gargc; | ||
163 | int i; | ||
164 | char *tok; | ||
165 | char *cargs; | ||
166 | |||
167 | gargv = NULL; | ||
168 | gargc = 0; | ||
169 | for (i = 0; i < argc; i++) | ||
170 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); | ||
171 | cargs = GNUNET_strdup (gargs); | ||
172 | tok = strtok (cargs, " "); | ||
173 | while (NULL != tok) | ||
156 | { | 174 | { |
157 | char **gargv; | 175 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); |
158 | unsigned int gargc; | 176 | tok = strtok (NULL, " "); |
159 | int i; | ||
160 | char *tok; | ||
161 | char *cargs; | ||
162 | |||
163 | gargv = NULL; | ||
164 | gargc = 0; | ||
165 | for (i=0;i<argc;i++) | ||
166 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); | ||
167 | cargs = GNUNET_strdup (gargs); | ||
168 | tok = strtok (cargs, " "); | ||
169 | while (NULL != tok) | ||
170 | { | ||
171 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); | ||
172 | tok = strtok (NULL, " "); | ||
173 | } | ||
174 | GNUNET_free (cargs); | ||
175 | GNUNET_array_append (gargv, gargc, NULL); | ||
176 | argv = (char *const *) gargv; | ||
177 | argc = gargc - 1; | ||
178 | } | 177 | } |
178 | GNUNET_free (cargs); | ||
179 | GNUNET_array_append (gargv, gargc, NULL); | ||
180 | argv = (char *const *) gargv; | ||
181 | argc = gargc - 1; | ||
182 | } | ||
179 | memset (&cc, 0, sizeof (cc)); | 183 | memset (&cc, 0, sizeof (cc)); |
180 | loglev = NULL; | 184 | loglev = NULL; |
181 | cc.task = task; | 185 | cc.task = task; |
@@ -187,26 +191,25 @@ GNUNET_PROGRAM_run (int argc, | |||
187 | setlocale (LC_ALL, ""); | 191 | setlocale (LC_ALL, ""); |
188 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); | 192 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
189 | if (path != NULL) | 193 | if (path != NULL) |
190 | { | 194 | { |
191 | BINDTEXTDOMAIN ("GNUnet", path); | 195 | BINDTEXTDOMAIN ("GNUnet", path); |
192 | GNUNET_free (path); | 196 | GNUNET_free (path); |
193 | } | 197 | } |
194 | textdomain ("GNUnet"); | 198 | textdomain ("GNUnet"); |
195 | #endif | 199 | #endif |
196 | cnt = 0; | 200 | cnt = 0; |
197 | while (options[cnt].name != NULL) | 201 | while (options[cnt].name != NULL) |
198 | cnt++; | 202 | cnt++; |
199 | allopts = | 203 | allopts = |
200 | GNUNET_malloc ((cnt + | 204 | GNUNET_malloc ((cnt + |
201 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + | 205 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + |
202 | sizeof (defoptions)); | 206 | sizeof (defoptions)); |
203 | memcpy (allopts, defoptions, sizeof (defoptions)); | 207 | memcpy (allopts, defoptions, sizeof (defoptions)); |
204 | memcpy (&allopts | 208 | memcpy (&allopts |
205 | [sizeof (defoptions) / | 209 | [sizeof (defoptions) / |
206 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, | 210 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, |
207 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); | 211 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); |
208 | cnt += | 212 | cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); |
209 | sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); | ||
210 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), | 213 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), |
211 | &cmd_sorter); | 214 | &cmd_sorter); |
212 | loglev = GNUNET_strdup ("WARNING"); | 215 | loglev = GNUNET_strdup ("WARNING"); |
@@ -222,22 +225,26 @@ GNUNET_PROGRAM_run (int argc, | |||
222 | loglev, | 225 | loglev, |
223 | logfile)) || | 226 | logfile)) || |
224 | (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)))) | 227 | (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)))) |
225 | { | 228 | { |
226 | GNUNET_CONFIGURATION_destroy (cfg); | 229 | GNUNET_CONFIGURATION_destroy (cfg); |
227 | GNUNET_free_non_null (cc.cfgfile); | 230 | GNUNET_free_non_null (cc.cfgfile); |
228 | GNUNET_free (loglev); | 231 | GNUNET_free (loglev); |
229 | GNUNET_free (allopts); | 232 | GNUNET_free (allopts); |
230 | GNUNET_free (lpfx); | 233 | GNUNET_free (lpfx); |
231 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
232 | } | 235 | } |
233 | GNUNET_free (allopts); | 236 | GNUNET_free (allopts); |
234 | GNUNET_free (lpfx); | 237 | GNUNET_free (lpfx); |
235 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_offset", &skew_offset) && | 238 | if (GNUNET_OK == |
236 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cc.cfg, "testing", "skew_variance", &skew_variance))) | 239 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", |
237 | { | 240 | &skew_offset) && |
238 | clock_offset = skew_offset - skew_variance; | 241 | (GNUNET_OK == |
239 | GNUNET_TIME_set_offset(clock_offset); | 242 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", |
240 | } | 243 | "skew_variance", &skew_variance))) |
244 | { | ||
245 | clock_offset = skew_offset - skew_variance; | ||
246 | GNUNET_TIME_set_offset (clock_offset); | ||
247 | } | ||
241 | /* run */ | 248 | /* run */ |
242 | cc.args = &argv[ret]; | 249 | cc.args = &argv[ret]; |
243 | GNUNET_SCHEDULER_run (&program_main, &cc); | 250 | GNUNET_SCHEDULER_run (&program_main, &cc); |
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index 3f0305e87..254decb76 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c | |||
@@ -84,10 +84,10 @@ internal_notify (const GNUNET_HashCode * id, | |||
84 | 84 | ||
85 | pos = head; | 85 | pos = head; |
86 | while (pos != NULL) | 86 | while (pos != NULL) |
87 | { | 87 | { |
88 | pos->callback (pos->closure, id, md, rating); | 88 | pos->callback (pos->closure, id, md, rating); |
89 | pos = pos->next; | 89 | pos = pos->next; |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | /** | 93 | /** |
@@ -131,10 +131,10 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator | |||
131 | pos = head; | 131 | pos = head; |
132 | while ((pos != NULL) && | 132 | while ((pos != NULL) && |
133 | ((pos->callback != iterator) || (pos->closure != closure))) | 133 | ((pos->callback != iterator) || (pos->closure != closure))) |
134 | { | 134 | { |
135 | prev = pos; | 135 | prev = pos; |
136 | pos = pos->next; | 136 | pos = pos->next; |
137 | } | 137 | } |
138 | if (pos == NULL) | 138 | if (pos == NULL) |
139 | return GNUNET_SYSERR; | 139 | return GNUNET_SYSERR; |
140 | if (prev == NULL) | 140 | if (prev == NULL) |
@@ -190,29 +190,29 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
190 | 190 | ||
191 | fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); | 191 | fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); |
192 | GNUNET_assert (fn != NULL); | 192 | GNUNET_assert (fn != NULL); |
193 | fileW = GNUNET_BIO_write_open(fn); | 193 | fileW = GNUNET_BIO_write_open (fn); |
194 | if (NULL != fileW) | 194 | if (NULL != fileW) |
195 | { | ||
196 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (fileW, ranking)) || | ||
197 | (GNUNET_OK != GNUNET_BIO_write_string (fileW, ns_name)) || | ||
198 | (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, meta))) | ||
195 | { | 199 | { |
196 | if ( (GNUNET_OK != GNUNET_BIO_write_int32(fileW, ranking)) || | 200 | (void) GNUNET_BIO_write_close (fileW); |
197 | (GNUNET_OK != GNUNET_BIO_write_string(fileW, ns_name)) || | 201 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); |
198 | (GNUNET_OK != GNUNET_BIO_write_meta_data(fileW, meta)) ) | 202 | GNUNET_free (fn); |
199 | { | 203 | return; |
200 | (void) GNUNET_BIO_write_close(fileW); | ||
201 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
202 | GNUNET_free (fn); | ||
203 | return; | ||
204 | } | ||
205 | if (GNUNET_OK != GNUNET_BIO_write_close(fileW)) | ||
206 | { | ||
207 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
208 | GNUNET_free (fn); | ||
209 | return; | ||
210 | } | ||
211 | } | 204 | } |
205 | if (GNUNET_OK != GNUNET_BIO_write_close (fileW)) | ||
206 | { | ||
207 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
208 | GNUNET_free (fn); | ||
209 | return; | ||
210 | } | ||
211 | } | ||
212 | GNUNET_free (fn); | 212 | GNUNET_free (fn); |
213 | /* create entry for pseudonym name in names */ | 213 | /* create entry for pseudonym name in names */ |
214 | /* FIXME: 90% of what this call does is not needed | 214 | /* FIXME: 90% of what this call does is not needed |
215 | here => refactor code to only create the entry! */ | 215 | * here => refactor code to only create the entry! */ |
216 | GNUNET_free_non_null (GNUNET_PSEUDONYM_id_to_name (cfg, nsid)); | 216 | GNUNET_free_non_null (GNUNET_PSEUDONYM_id_to_name (cfg, nsid)); |
217 | } | 217 | } |
218 | 218 | ||
@@ -237,41 +237,43 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
237 | 237 | ||
238 | fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); | 238 | fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); |
239 | GNUNET_assert (fn != NULL); | 239 | GNUNET_assert (fn != NULL); |
240 | fileR = GNUNET_BIO_read_open(fn); | 240 | fileR = GNUNET_BIO_read_open (fn); |
241 | if (fileR == NULL) | 241 | if (fileR == NULL) |
242 | { | 242 | { |
243 | GNUNET_free (fn); | 243 | GNUNET_free (fn); |
244 | return GNUNET_SYSERR; | 244 | return GNUNET_SYSERR; |
245 | } | 245 | } |
246 | emsg = NULL; | 246 | emsg = NULL; |
247 | *ns_name = NULL; | 247 | *ns_name = NULL; |
248 | if ( (GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) || | 248 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) || |
249 | (GNUNET_OK != GNUNET_BIO_read_string(fileR, "Read string error!", ns_name, 200)) || | 249 | (GNUNET_OK != |
250 | (GNUNET_OK != GNUNET_BIO_read_meta_data(fileR, "Read meta data error!", meta)) ) | 250 | GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) || |
251 | { | 251 | (GNUNET_OK != |
252 | (void) GNUNET_BIO_read_close(fileR, &emsg); | 252 | GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta))) |
253 | GNUNET_free_non_null (emsg); | 253 | { |
254 | GNUNET_free_non_null (*ns_name); | 254 | (void) GNUNET_BIO_read_close (fileR, &emsg); |
255 | *ns_name = NULL; | 255 | GNUNET_free_non_null (emsg); |
256 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | 256 | GNUNET_free_non_null (*ns_name); |
257 | GNUNET_free (fn); | 257 | *ns_name = NULL; |
258 | return GNUNET_SYSERR; | 258 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); |
259 | } | 259 | GNUNET_free (fn); |
260 | if (GNUNET_OK != GNUNET_BIO_read_close(fileR, &emsg)) | 260 | return GNUNET_SYSERR; |
261 | { | 261 | } |
262 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 262 | if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg)) |
263 | _("Failed to parse metadata about pseudonym from file `%s': %s\n"), | 263 | { |
264 | fn, | 264 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
265 | emsg); | 265 | _ |
266 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | 266 | ("Failed to parse metadata about pseudonym from file `%s': %s\n"), |
267 | GNUNET_CONTAINER_meta_data_destroy (*meta); | 267 | fn, emsg); |
268 | *meta = NULL; | 268 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); |
269 | GNUNET_free_non_null (*ns_name); | 269 | GNUNET_CONTAINER_meta_data_destroy (*meta); |
270 | *ns_name = NULL; | 270 | *meta = NULL; |
271 | GNUNET_free_non_null (emsg); | 271 | GNUNET_free_non_null (*ns_name); |
272 | GNUNET_free (fn); | 272 | *ns_name = NULL; |
273 | return GNUNET_SYSERR; | 273 | GNUNET_free_non_null (emsg); |
274 | } | 274 | GNUNET_free (fn); |
275 | return GNUNET_SYSERR; | ||
276 | } | ||
275 | GNUNET_free (fn); | 277 | GNUNET_free (fn); |
276 | return GNUNET_OK; | 278 | return GNUNET_OK; |
277 | } | 279 | } |
@@ -305,24 +307,24 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
305 | meta = NULL; | 307 | meta = NULL; |
306 | name = NULL; | 308 | name = NULL; |
307 | if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name)) | 309 | if (GNUNET_OK == read_info (cfg, nsid, &meta, rank, &name)) |
310 | { | ||
311 | if ((meta != NULL) && (name == NULL)) | ||
312 | name = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, | ||
313 | EXTRACTOR_METATYPE_TITLE, | ||
314 | EXTRACTOR_METATYPE_FILENAME, | ||
315 | EXTRACTOR_METATYPE_DESCRIPTION, | ||
316 | EXTRACTOR_METATYPE_SUBJECT, | ||
317 | EXTRACTOR_METATYPE_PUBLISHER, | ||
318 | EXTRACTOR_METATYPE_AUTHOR_NAME, | ||
319 | EXTRACTOR_METATYPE_COMMENT, | ||
320 | EXTRACTOR_METATYPE_SUMMARY, | ||
321 | -1); | ||
322 | if (meta != NULL) | ||
308 | { | 323 | { |
309 | if ((meta != NULL) && (name == NULL)) | 324 | GNUNET_CONTAINER_meta_data_destroy (meta); |
310 | name = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, | 325 | meta = NULL; |
311 | EXTRACTOR_METATYPE_TITLE, | ||
312 | EXTRACTOR_METATYPE_FILENAME, | ||
313 | EXTRACTOR_METATYPE_DESCRIPTION, | ||
314 | EXTRACTOR_METATYPE_SUBJECT, | ||
315 | EXTRACTOR_METATYPE_PUBLISHER, | ||
316 | EXTRACTOR_METATYPE_AUTHOR_NAME, | ||
317 | EXTRACTOR_METATYPE_COMMENT, | ||
318 | EXTRACTOR_METATYPE_SUMMARY, | ||
319 | -1); | ||
320 | if (meta != NULL) | ||
321 | { | ||
322 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
323 | meta = NULL; | ||
324 | } | ||
325 | } | 326 | } |
327 | } | ||
326 | if (name == NULL) | 328 | if (name == NULL) |
327 | name = GNUNET_strdup (_("no-name")); | 329 | name = GNUNET_strdup (_("no-name")); |
328 | GNUNET_CRYPTO_hash (name, strlen (name), &nh); | 330 | GNUNET_CRYPTO_hash (name, strlen (name), &nh); |
@@ -341,22 +343,22 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
341 | while ((len >= sizeof (GNUNET_HashCode)) && | 343 | while ((len >= sizeof (GNUNET_HashCode)) && |
342 | (sizeof (GNUNET_HashCode) | 344 | (sizeof (GNUNET_HashCode) |
343 | == GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode)))) | 345 | == GNUNET_DISK_file_read (fh, &nh, sizeof (GNUNET_HashCode)))) |
344 | { | 346 | { |
345 | if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode))) | 347 | if (0 == memcmp (&nh, nsid, sizeof (GNUNET_HashCode))) |
346 | { | ||
347 | idx = i; | ||
348 | break; | ||
349 | } | ||
350 | i++; | ||
351 | len -= sizeof (GNUNET_HashCode); | ||
352 | } | ||
353 | if (idx == -1) | ||
354 | { | 348 | { |
355 | idx = i; | 349 | idx = i; |
356 | if (sizeof (GNUNET_HashCode) != | 350 | break; |
357 | GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode))) | ||
358 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
359 | } | 351 | } |
352 | i++; | ||
353 | len -= sizeof (GNUNET_HashCode); | ||
354 | } | ||
355 | if (idx == -1) | ||
356 | { | ||
357 | idx = i; | ||
358 | if (sizeof (GNUNET_HashCode) != | ||
359 | GNUNET_DISK_file_write (fh, nsid, sizeof (GNUNET_HashCode))) | ||
360 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
361 | } | ||
360 | GNUNET_DISK_file_close (fh); | 362 | GNUNET_DISK_file_close (fh); |
361 | ret = GNUNET_malloc (strlen (name) + 32); | 363 | ret = GNUNET_malloc (strlen (name) + 32); |
362 | GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx); | 364 | GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx); |
@@ -401,10 +403,10 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
401 | if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || | 403 | if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || |
402 | (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) || | 404 | (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES))) || |
403 | ((idx + 1) * sizeof (GNUNET_HashCode) > len)) | 405 | ((idx + 1) * sizeof (GNUNET_HashCode) > len)) |
404 | { | 406 | { |
405 | GNUNET_free (fn); | 407 | GNUNET_free (fn); |
406 | return GNUNET_SYSERR; | 408 | return GNUNET_SYSERR; |
407 | } | 409 | } |
408 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE | 410 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE |
409 | | GNUNET_DISK_OPEN_READWRITE, | 411 | | GNUNET_DISK_OPEN_READWRITE, |
410 | GNUNET_DISK_PERM_USER_READ | | 412 | GNUNET_DISK_PERM_USER_READ | |
@@ -414,10 +416,10 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
414 | GNUNET_DISK_SEEK_SET); | 416 | GNUNET_DISK_SEEK_SET); |
415 | if (sizeof (GNUNET_HashCode) != | 417 | if (sizeof (GNUNET_HashCode) != |
416 | GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) | 418 | GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) |
417 | { | 419 | { |
418 | GNUNET_DISK_file_close (fh); | 420 | GNUNET_DISK_file_close (fh); |
419 | return GNUNET_SYSERR; | 421 | return GNUNET_SYSERR; |
420 | } | 422 | } |
421 | GNUNET_DISK_file_close (fh); | 423 | GNUNET_DISK_file_close (fh); |
422 | return GNUNET_OK; | 424 | return GNUNET_OK; |
423 | } | 425 | } |
@@ -466,9 +468,8 @@ list_pseudonym_helper (void *cls, const char *fullname) | |||
466 | 468 | ||
467 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) | 469 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) |
468 | return GNUNET_OK; | 470 | return GNUNET_OK; |
469 | fn = | 471 | fn = &fullname[strlen (fullname) + 1 - |
470 | &fullname[strlen (fullname) + 1 - | 472 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
471 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
472 | if (fn[-1] != DIR_SEPARATOR) | 473 | if (fn[-1] != DIR_SEPARATOR) |
473 | return GNUNET_OK; | 474 | return GNUNET_OK; |
474 | ret = GNUNET_OK; | 475 | ret = GNUNET_OK; |
@@ -534,10 +535,10 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
534 | name = NULL; | 535 | name = NULL; |
535 | ret = read_info (cfg, nsid, &meta, &ranking, &name); | 536 | ret = read_info (cfg, nsid, &meta, &ranking, &name); |
536 | if (ret == GNUNET_SYSERR) | 537 | if (ret == GNUNET_SYSERR) |
537 | { | 538 | { |
538 | ranking = 0; | 539 | ranking = 0; |
539 | meta = GNUNET_CONTAINER_meta_data_create (); | 540 | meta = GNUNET_CONTAINER_meta_data_create (); |
540 | } | 541 | } |
541 | ranking += delta; | 542 | ranking += delta; |
542 | write_pseudonym_info (cfg, nsid, meta, ranking, name); | 543 | write_pseudonym_info (cfg, nsid, meta, ranking, name); |
543 | GNUNET_CONTAINER_meta_data_destroy (meta); | 544 | GNUNET_CONTAINER_meta_data_destroy (meta); |
@@ -572,16 +573,16 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
572 | 573 | ||
573 | if ((0 == STAT (fn, &sbuf)) && | 574 | if ((0 == STAT (fn, &sbuf)) && |
574 | (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) | 575 | (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) |
575 | { | 576 | { |
576 | GNUNET_CONTAINER_meta_data_merge (old, meta); | 577 | GNUNET_CONTAINER_meta_data_merge (old, meta); |
577 | write_pseudonym_info (cfg, id, old, ranking, name); | 578 | write_pseudonym_info (cfg, id, old, ranking, name); |
578 | GNUNET_CONTAINER_meta_data_destroy (old); | 579 | GNUNET_CONTAINER_meta_data_destroy (old); |
579 | GNUNET_free_non_null (name); | 580 | GNUNET_free_non_null (name); |
580 | } | 581 | } |
581 | else | 582 | else |
582 | { | 583 | { |
583 | write_pseudonym_info (cfg, id, meta, ranking, NULL); | 584 | write_pseudonym_info (cfg, id, meta, ranking, NULL); |
584 | } | 585 | } |
585 | GNUNET_free (fn); | 586 | GNUNET_free (fn); |
586 | internal_notify (id, meta, ranking); | 587 | internal_notify (id, meta, ranking); |
587 | } | 588 | } |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 3ff005263..ef48faf59 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -53,7 +53,7 @@ static const char *loopback[] = { | |||
53 | * Configuration. | 53 | * Configuration. |
54 | */ | 54 | */ |
55 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 55 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Our connection to the resolver service, created on-demand, but then | 58 | * Our connection to the resolver service, created on-demand, but then |
59 | * persists until error or shutdown. | 59 | * persists until error or shutdown. |
@@ -69,7 +69,7 @@ static struct GNUNET_RESOLVER_RequestHandle *req_head; | |||
69 | * Tail of DLL of requests. | 69 | * Tail of DLL of requests. |
70 | */ | 70 | */ |
71 | static struct GNUNET_RESOLVER_RequestHandle *req_tail; | 71 | static struct GNUNET_RESOLVER_RequestHandle *req_tail; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * How long should we wait to reconnect? | 74 | * How long should we wait to reconnect? |
75 | */ | 75 | */ |
@@ -192,28 +192,27 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
192 | #endif | 192 | #endif |
193 | if (GNUNET_OK != | 193 | if (GNUNET_OK != |
194 | GNUNET_CONFIGURATION_get_value_string (cfg, | 194 | GNUNET_CONFIGURATION_get_value_string (cfg, |
195 | "resolver", | 195 | "resolver", "HOSTNAME", &hostname)) |
196 | "HOSTNAME", &hostname)) | 196 | { |
197 | { | 197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 198 | _("Must specify `%s' for `%s' in configuration!\n"), |
199 | _("Must specify `%s' for `%s' in configuration!\n"), | 199 | "HOSTNAME", "resolver"); |
200 | "HOSTNAME", "resolver"); | 200 | GNUNET_assert (0); |
201 | GNUNET_assert (0); | 201 | } |
202 | } | ||
203 | if ((1 != inet_pton (AF_INET, | 202 | if ((1 != inet_pton (AF_INET, |
204 | hostname, | 203 | hostname, |
205 | &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6))) | 204 | &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6))) |
205 | { | ||
206 | GNUNET_free (hostname); | ||
207 | return; | ||
208 | } | ||
209 | i = 0; | ||
210 | while (loopback[i] != NULL) | ||
211 | if (0 == strcasecmp (loopback[i++], hostname)) | ||
206 | { | 212 | { |
207 | GNUNET_free (hostname); | 213 | GNUNET_free (hostname); |
208 | return; | 214 | return; |
209 | } | 215 | } |
210 | i = 0; | ||
211 | while (loopback[i] != NULL) | ||
212 | if (0 == strcasecmp (loopback[i++], hostname)) | ||
213 | { | ||
214 | GNUNET_free (hostname); | ||
215 | return; | ||
216 | } | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
218 | _ | 217 | _ |
219 | ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), | 218 | ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), |
@@ -247,24 +246,23 @@ GNUNET_RESOLVER_disconnect () | |||
247 | GNUNET_assert (NULL == req_head); | 246 | GNUNET_assert (NULL == req_head); |
248 | GNUNET_assert (NULL == req_tail); | 247 | GNUNET_assert (NULL == req_tail); |
249 | if (NULL != client) | 248 | if (NULL != client) |
250 | { | 249 | { |
251 | #if DEBUG_RESOLVER | 250 | #if DEBUG_RESOLVER |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n"); |
253 | "Disconnecting from DNS service\n"); | ||
254 | #endif | 252 | #endif |
255 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | 253 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); |
256 | client = NULL; | 254 | client = NULL; |
257 | } | 255 | } |
258 | if (r_task != GNUNET_SCHEDULER_NO_TASK) | 256 | if (r_task != GNUNET_SCHEDULER_NO_TASK) |
259 | { | 257 | { |
260 | GNUNET_SCHEDULER_cancel (r_task); | 258 | GNUNET_SCHEDULER_cancel (r_task); |
261 | r_task = GNUNET_SCHEDULER_NO_TASK; | 259 | r_task = GNUNET_SCHEDULER_NO_TASK; |
262 | } | 260 | } |
263 | if (s_task != GNUNET_SCHEDULER_NO_TASK) | 261 | if (s_task != GNUNET_SCHEDULER_NO_TASK) |
264 | { | 262 | { |
265 | GNUNET_SCHEDULER_cancel (s_task); | 263 | GNUNET_SCHEDULER_cancel (s_task); |
266 | s_task = GNUNET_SCHEDULER_NO_TASK; | 264 | s_task = GNUNET_SCHEDULER_NO_TASK; |
267 | } | 265 | } |
268 | } | 266 | } |
269 | 267 | ||
270 | 268 | ||
@@ -285,37 +283,37 @@ no_resolve (const struct sockaddr *sa, socklen_t salen) | |||
285 | if (salen < sizeof (struct sockaddr)) | 283 | if (salen < sizeof (struct sockaddr)) |
286 | return NULL; | 284 | return NULL; |
287 | switch (sa->sa_family) | 285 | switch (sa->sa_family) |
286 | { | ||
287 | case AF_INET: | ||
288 | if (salen != sizeof (struct sockaddr_in)) | ||
289 | return NULL; | ||
290 | if (NULL == | ||
291 | inet_ntop (AF_INET, | ||
292 | &((struct sockaddr_in *) sa)->sin_addr, | ||
293 | inet4, INET_ADDRSTRLEN)) | ||
288 | { | 294 | { |
289 | case AF_INET: | 295 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
290 | if (salen != sizeof (struct sockaddr_in)) | 296 | return NULL; |
291 | return NULL; | ||
292 | if (NULL == | ||
293 | inet_ntop (AF_INET, | ||
294 | &((struct sockaddr_in *) sa)->sin_addr, | ||
295 | inet4, INET_ADDRSTRLEN)) | ||
296 | { | ||
297 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | ||
298 | return NULL; | ||
299 | } | ||
300 | ret = GNUNET_strdup (inet4); | ||
301 | break; | ||
302 | case AF_INET6: | ||
303 | if (salen != sizeof (struct sockaddr_in6)) | ||
304 | return NULL; | ||
305 | if (NULL == | ||
306 | inet_ntop (AF_INET6, | ||
307 | &((struct sockaddr_in6 *) sa)->sin6_addr, | ||
308 | inet6, INET6_ADDRSTRLEN)) | ||
309 | { | ||
310 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | ||
311 | return NULL; | ||
312 | } | ||
313 | ret = GNUNET_strdup (inet6); | ||
314 | break; | ||
315 | default: | ||
316 | ret = NULL; | ||
317 | break; | ||
318 | } | 297 | } |
298 | ret = GNUNET_strdup (inet4); | ||
299 | break; | ||
300 | case AF_INET6: | ||
301 | if (salen != sizeof (struct sockaddr_in6)) | ||
302 | return NULL; | ||
303 | if (NULL == | ||
304 | inet_ntop (AF_INET6, | ||
305 | &((struct sockaddr_in6 *) sa)->sin6_addr, | ||
306 | inet6, INET6_ADDRSTRLEN)) | ||
307 | { | ||
308 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | ||
309 | return NULL; | ||
310 | } | ||
311 | ret = GNUNET_strdup (inet6); | ||
312 | break; | ||
313 | default: | ||
314 | ret = NULL; | ||
315 | break; | ||
316 | } | ||
319 | return ret; | 317 | return ret; |
320 | } | 318 | } |
321 | 319 | ||
@@ -323,8 +321,7 @@ no_resolve (const struct sockaddr *sa, socklen_t salen) | |||
323 | /** | 321 | /** |
324 | * Adjust exponential back-off and reconnect to the service. | 322 | * Adjust exponential back-off and reconnect to the service. |
325 | */ | 323 | */ |
326 | static void | 324 | static void reconnect (); |
327 | reconnect (); | ||
328 | 325 | ||
329 | 326 | ||
330 | /** | 327 | /** |
@@ -332,8 +329,7 @@ reconnect (); | |||
332 | * | 329 | * |
333 | * @param h handle to the resolver | 330 | * @param h handle to the resolver |
334 | */ | 331 | */ |
335 | static void | 332 | static void process_requests (); |
336 | process_requests (); | ||
337 | 333 | ||
338 | 334 | ||
339 | /** | 335 | /** |
@@ -343,8 +339,7 @@ process_requests (); | |||
343 | * @param msg message with the hostname, NULL on error | 339 | * @param msg message with the hostname, NULL on error |
344 | */ | 340 | */ |
345 | static void | 341 | static void |
346 | handle_response (void *cls, | 342 | handle_response (void *cls, const struct GNUNET_MessageHeader *msg) |
347 | const struct GNUNET_MessageHeader *msg) | ||
348 | { | 343 | { |
349 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 344 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
350 | uint16_t size; | 345 | uint16_t size; |
@@ -353,138 +348,129 @@ handle_response (void *cls, | |||
353 | socklen_t salen; | 348 | socklen_t salen; |
354 | 349 | ||
355 | #if DEBUG_RESOLVER | 350 | #if DEBUG_RESOLVER |
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n"); |
357 | "Receiving response from DNS service\n"); | ||
358 | #endif | 352 | #endif |
359 | if (msg == NULL) | 353 | if (msg == NULL) |
354 | { | ||
355 | if (NULL != rh->name_callback) | ||
356 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
357 | _("Timeout trying to resolve IP address `%s'.\n"), | ||
358 | GNUNET_a2s ((const void *) &rh[1], rh->data_len)); | ||
359 | else | ||
360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
361 | _("Timeout trying to resolve hostname `%s'.\n"), | ||
362 | (const char *) &rh[1]); | ||
363 | /* check if request was canceled */ | ||
364 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
360 | { | 365 | { |
361 | if (NULL != rh->name_callback) | 366 | if (NULL != rh->name_callback) |
362 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 367 | { |
363 | _("Timeout trying to resolve IP address `%s'.\n"), | 368 | /* no reverse lookup was successful, return ip as string */ |
364 | GNUNET_a2s ((const void*) &rh[1], rh->data_len)); | 369 | if (rh->received_response == GNUNET_NO) |
365 | else | 370 | rh->name_callback (rh->cls, |
366 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 371 | no_resolve ((const struct sockaddr *) &rh[1], |
367 | _("Timeout trying to resolve hostname `%s'.\n"), | 372 | rh->data_len)); |
368 | (const char *) &rh[1]); | 373 | /* at least one reverse lookup was successful */ |
369 | /* check if request was canceled */ | 374 | else |
370 | if (rh->was_transmitted != GNUNET_SYSERR) | 375 | rh->name_callback (rh->cls, NULL); |
371 | { | 376 | } |
372 | if (NULL != rh->name_callback) | 377 | if (NULL != rh->addr_callback) |
373 | { | 378 | rh->addr_callback (rh->cls, NULL, 0); |
374 | /* no reverse lookup was successful, return ip as string */ | ||
375 | if (rh->received_response == GNUNET_NO) | ||
376 | rh->name_callback (rh->cls, | ||
377 | no_resolve ((const struct sockaddr *) &rh[1], rh->data_len)); | ||
378 | /* at least one reverse lookup was successful */ | ||
379 | else | ||
380 | rh->name_callback (rh->cls, NULL); | ||
381 | } | ||
382 | if (NULL != rh->addr_callback) | ||
383 | rh->addr_callback (rh->cls, NULL, 0); | ||
384 | } | ||
385 | GNUNET_CONTAINER_DLL_remove (req_head, | ||
386 | req_tail, | ||
387 | rh); | ||
388 | GNUNET_free (rh); | ||
389 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | ||
390 | client = NULL; | ||
391 | reconnect (); | ||
392 | return; | ||
393 | } | 379 | } |
380 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); | ||
381 | GNUNET_free (rh); | ||
382 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | ||
383 | client = NULL; | ||
384 | reconnect (); | ||
385 | return; | ||
386 | } | ||
394 | if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type)) | 387 | if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type)) |
388 | { | ||
389 | GNUNET_break (0); | ||
390 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | ||
391 | client = NULL; | ||
392 | reconnect (); | ||
393 | return; | ||
394 | } | ||
395 | size = ntohs (msg->size); | ||
396 | /* message contains not data, just header */ | ||
397 | if (size == sizeof (struct GNUNET_MessageHeader)) | ||
398 | { | ||
399 | /* check if request was canceled */ | ||
400 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
401 | { | ||
402 | if (NULL != rh->name_callback) | ||
403 | rh->name_callback (rh->cls, NULL); | ||
404 | if (NULL != rh->addr_callback) | ||
405 | rh->addr_callback (rh->cls, NULL, 0); | ||
406 | } | ||
407 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); | ||
408 | GNUNET_free (rh); | ||
409 | process_requests (); | ||
410 | return; | ||
411 | } | ||
412 | /* return reverse lookup results to caller */ | ||
413 | if (NULL != rh->name_callback) | ||
414 | { | ||
415 | hostname = (const char *) &msg[1]; | ||
416 | if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | ||
395 | { | 417 | { |
396 | GNUNET_break (0); | 418 | GNUNET_break (0); |
419 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
420 | rh->name_callback (rh->cls, NULL); | ||
421 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); | ||
422 | GNUNET_free (rh); | ||
397 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | 423 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); |
398 | client = NULL; | 424 | client = NULL; |
399 | reconnect (); | 425 | reconnect (); |
400 | return; | 426 | return; |
401 | } | 427 | } |
402 | size = ntohs (msg->size); | 428 | #if DEBUG_RESOLVER |
403 | /* message contains not data, just header */ | 429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
404 | if (size == sizeof (struct GNUNET_MessageHeader)) | 430 | _("Resolver returns `%s' for IP `%s'.\n"), |
431 | hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); | ||
432 | #endif | ||
433 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
434 | rh->name_callback (rh->cls, hostname); | ||
435 | rh->received_response = GNUNET_YES; | ||
436 | GNUNET_CLIENT_receive (client, | ||
437 | &handle_response, | ||
438 | rh, | ||
439 | GNUNET_TIME_absolute_get_remaining (rh->timeout)); | ||
440 | } | ||
441 | /* return lookup results to caller */ | ||
442 | if (NULL != rh->addr_callback) | ||
443 | { | ||
444 | sa = (const struct sockaddr *) &msg[1]; | ||
445 | salen = size - sizeof (struct GNUNET_MessageHeader); | ||
446 | if (salen < sizeof (struct sockaddr)) | ||
405 | { | 447 | { |
406 | /* check if request was canceled */ | 448 | GNUNET_break (0); |
407 | if (rh->was_transmitted != GNUNET_SYSERR) | 449 | if (rh->was_transmitted != GNUNET_SYSERR) |
408 | { | 450 | rh->addr_callback (rh->cls, NULL, 0); |
409 | if (NULL != rh->name_callback) | 451 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); |
410 | rh->name_callback (rh->cls, NULL); | ||
411 | if (NULL != rh->addr_callback) | ||
412 | rh->addr_callback (rh->cls, NULL, 0); | ||
413 | } | ||
414 | GNUNET_CONTAINER_DLL_remove (req_head, | ||
415 | req_tail, | ||
416 | rh); | ||
417 | GNUNET_free (rh); | 452 | GNUNET_free (rh); |
418 | process_requests (); | 453 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); |
454 | client = NULL; | ||
455 | reconnect (); | ||
419 | return; | 456 | return; |
420 | } | 457 | } |
421 | /* return reverse lookup results to caller */ | ||
422 | if (NULL != rh->name_callback) | ||
423 | { | ||
424 | hostname = (const char *) &msg[1]; | ||
425 | if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | ||
426 | { | ||
427 | GNUNET_break (0); | ||
428 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
429 | rh->name_callback (rh->cls, NULL); | ||
430 | GNUNET_CONTAINER_DLL_remove (req_head, | ||
431 | req_tail, | ||
432 | rh); | ||
433 | GNUNET_free (rh); | ||
434 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | ||
435 | client = NULL; | ||
436 | reconnect (); | ||
437 | return; | ||
438 | } | ||
439 | #if DEBUG_RESOLVER | 458 | #if DEBUG_RESOLVER |
459 | { | ||
460 | char *ips = no_resolve (sa, salen); | ||
461 | |||
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
441 | _("Resolver returns `%s' for IP `%s'.\n"), | 463 | "Resolver returns `%s' for `%s'.\n", |
442 | hostname, | 464 | ips, (const char *) &rh[1]); |
443 | GNUNET_a2s ((const void*) &rh[1], rh->data_len)); | 465 | GNUNET_free (ips); |
444 | #endif | ||
445 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
446 | rh->name_callback (rh->cls, hostname); | ||
447 | rh->received_response = GNUNET_YES; | ||
448 | GNUNET_CLIENT_receive (client, | ||
449 | &handle_response, | ||
450 | rh, | ||
451 | GNUNET_TIME_absolute_get_remaining (rh->timeout)); | ||
452 | } | 466 | } |
453 | /* return lookup results to caller */ | ||
454 | if (NULL != rh->addr_callback) | ||
455 | { | ||
456 | sa = (const struct sockaddr *) &msg[1]; | ||
457 | salen = size - sizeof (struct GNUNET_MessageHeader); | ||
458 | if (salen < sizeof (struct sockaddr)) | ||
459 | { | ||
460 | GNUNET_break (0); | ||
461 | if (rh->was_transmitted != GNUNET_SYSERR) | ||
462 | rh->addr_callback (rh->cls, NULL, 0); | ||
463 | GNUNET_CONTAINER_DLL_remove (req_head, | ||
464 | req_tail, | ||
465 | rh); | ||
466 | GNUNET_free (rh); | ||
467 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | ||
468 | client = NULL; | ||
469 | reconnect (); | ||
470 | return; | ||
471 | } | ||
472 | #if DEBUG_RESOLVER | ||
473 | { | ||
474 | char *ips = no_resolve (sa, salen); | ||
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
476 | "Resolver returns `%s' for `%s'.\n", | ||
477 | ips, | ||
478 | (const char*) &rh[1]); | ||
479 | GNUNET_free (ips); | ||
480 | } | ||
481 | #endif | 467 | #endif |
482 | rh->addr_callback (rh->cls, sa, salen); | 468 | rh->addr_callback (rh->cls, sa, salen); |
483 | GNUNET_CLIENT_receive (client, | 469 | GNUNET_CLIENT_receive (client, |
484 | &handle_response, | 470 | &handle_response, |
485 | rh, | 471 | rh, |
486 | GNUNET_TIME_absolute_get_remaining (rh->timeout)); | 472 | GNUNET_TIME_absolute_get_remaining (rh->timeout)); |
487 | } | 473 | } |
488 | } | 474 | } |
489 | 475 | ||
490 | 476 | ||
@@ -514,30 +500,29 @@ numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
514 | #if HAVE_SOCKADDR_IN_SIN_LEN | 500 | #if HAVE_SOCKADDR_IN_SIN_LEN |
515 | v6.sin6_len = sizeof (v6); | 501 | v6.sin6_len = sizeof (v6); |
516 | #endif | 502 | #endif |
517 | hostname = (const char*) &rh[1]; | 503 | hostname = (const char *) &rh[1]; |
518 | if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) && | 504 | if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) && |
519 | (1 == inet_pton (AF_INET, hostname, &v4.sin_addr))) | 505 | (1 == inet_pton (AF_INET, hostname, &v4.sin_addr))) |
506 | { | ||
507 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); | ||
508 | if ((rh->domain == AF_UNSPEC) && | ||
509 | (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) | ||
520 | { | 510 | { |
521 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); | 511 | /* this can happen on some systems IF "hostname" is "localhost" */ |
522 | if ((rh->domain == AF_UNSPEC) && | 512 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); |
523 | (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) | ||
524 | { | ||
525 | /* this can happen on some systems IF "hostname" is "localhost" */ | ||
526 | rh->addr_callback (rh->cls, | ||
527 | (const struct sockaddr *) &v6, sizeof (v6)); | ||
528 | } | ||
529 | rh->addr_callback (rh->cls, NULL, 0); | ||
530 | GNUNET_free (rh); | ||
531 | return; | ||
532 | } | 513 | } |
514 | rh->addr_callback (rh->cls, NULL, 0); | ||
515 | GNUNET_free (rh); | ||
516 | return; | ||
517 | } | ||
533 | if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) && | 518 | if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) && |
534 | (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) | 519 | (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) |
535 | { | 520 | { |
536 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); | 521 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); |
537 | rh->addr_callback (rh->cls, NULL, 0); | 522 | rh->addr_callback (rh->cls, NULL, 0); |
538 | GNUNET_free (rh); | 523 | GNUNET_free (rh); |
539 | return; | 524 | return; |
540 | } | 525 | } |
541 | /* why are we here? this task should not have been scheduled! */ | 526 | /* why are we here? this task should not have been scheduled! */ |
542 | GNUNET_assert (0); | 527 | GNUNET_assert (0); |
543 | GNUNET_free (rh); | 528 | GNUNET_free (rh); |
@@ -572,21 +557,21 @@ loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
572 | #endif | 557 | #endif |
573 | v6.sin6_addr = in6addr_loopback; | 558 | v6.sin6_addr = in6addr_loopback; |
574 | switch (rh->domain) | 559 | switch (rh->domain) |
575 | { | 560 | { |
576 | case AF_INET: | 561 | case AF_INET: |
577 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); | 562 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); |
578 | break; | 563 | break; |
579 | case AF_INET6: | 564 | case AF_INET6: |
580 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); | 565 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); |
581 | break; | 566 | break; |
582 | case AF_UNSPEC: | 567 | case AF_UNSPEC: |
583 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); | 568 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6)); |
584 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); | 569 | rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4)); |
585 | break; | 570 | break; |
586 | default: | 571 | default: |
587 | GNUNET_break (0); | 572 | GNUNET_break (0); |
588 | break; | 573 | break; |
589 | } | 574 | } |
590 | rh->addr_callback (rh->cls, NULL, 0); | 575 | rh->addr_callback (rh->cls, NULL, 0); |
591 | GNUNET_free (rh); | 576 | GNUNET_free (rh); |
592 | } | 577 | } |
@@ -614,46 +599,46 @@ process_requests () | |||
614 | struct GNUNET_RESOLVER_GetMessage *msg; | 599 | struct GNUNET_RESOLVER_GetMessage *msg; |
615 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 600 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
616 | struct GNUNET_RESOLVER_RequestHandle *rh; | 601 | struct GNUNET_RESOLVER_RequestHandle *rh; |
617 | 602 | ||
618 | if (NULL == client) | 603 | if (NULL == client) |
619 | { | 604 | { |
620 | reconnect (); | 605 | reconnect (); |
621 | return; | 606 | return; |
622 | } | 607 | } |
623 | rh = req_head; | 608 | rh = req_head; |
624 | if (NULL == rh) | 609 | if (NULL == rh) |
625 | { | 610 | { |
626 | /* nothing to do, release socket really soon if there is nothing | 611 | /* nothing to do, release socket really soon if there is nothing |
627 | else happening... */ | 612 | * else happening... */ |
628 | s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | 613 | s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, |
629 | &shutdown_task, NULL); | 614 | &shutdown_task, NULL); |
630 | return; | 615 | return; |
631 | } | 616 | } |
632 | if (GNUNET_YES == rh->was_transmitted) | 617 | if (GNUNET_YES == rh->was_transmitted) |
633 | return; /* waiting for reply */ | 618 | return; /* waiting for reply */ |
634 | msg = (struct GNUNET_RESOLVER_GetMessage *) buf; | 619 | msg = (struct GNUNET_RESOLVER_GetMessage *) buf; |
635 | msg->header.size = | 620 | msg->header.size = |
636 | htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len); | 621 | htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len); |
637 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); | 622 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); |
638 | msg->direction = htonl (rh->direction); | 623 | msg->direction = htonl (rh->direction); |
639 | msg->domain = htonl (rh->domain); | 624 | msg->domain = htonl (rh->domain); |
640 | memcpy (&msg[1], &rh[1], rh->data_len); | 625 | memcpy (&msg[1], &rh[1], rh->data_len); |
641 | #if DEBUG_RESOLVER | 626 | #if DEBUG_RESOLVER |
642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
643 | "Transmitting DNS resolution request to DNS service\n"); | 628 | "Transmitting DNS resolution request to DNS service\n"); |
644 | #endif | 629 | #endif |
645 | if (GNUNET_OK != | 630 | if (GNUNET_OK != |
646 | GNUNET_CLIENT_transmit_and_get_response (client, | 631 | GNUNET_CLIENT_transmit_and_get_response (client, |
647 | &msg->header, | 632 | &msg->header, |
648 | GNUNET_TIME_absolute_get_remaining (rh->timeout), | 633 | GNUNET_TIME_absolute_get_remaining |
649 | GNUNET_YES, | 634 | (rh->timeout), GNUNET_YES, |
650 | &handle_response, rh)) | 635 | &handle_response, rh)) |
651 | { | 636 | { |
652 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); | 637 | GNUNET_CLIENT_disconnect (client, GNUNET_NO); |
653 | client = NULL; | 638 | client = NULL; |
654 | reconnect (); | 639 | reconnect (); |
655 | return; | 640 | return; |
656 | } | 641 | } |
657 | rh->was_transmitted = GNUNET_YES; | 642 | rh->was_transmitted = GNUNET_YES; |
658 | } | 643 | } |
659 | 644 | ||
@@ -665,26 +650,24 @@ process_requests () | |||
665 | * @param tc scheduler context | 650 | * @param tc scheduler context |
666 | */ | 651 | */ |
667 | static void | 652 | static void |
668 | reconnect_task (void *cls, | 653 | reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
669 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
670 | { | 654 | { |
671 | r_task = GNUNET_SCHEDULER_NO_TASK; | 655 | r_task = GNUNET_SCHEDULER_NO_TASK; |
672 | if (NULL == req_head) | 656 | if (NULL == req_head) |
673 | return; /* no work pending */ | 657 | return; /* no work pending */ |
674 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 658 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
675 | return; | 659 | return; |
676 | #if DEBUG_RESOLVER | 660 | #if DEBUG_RESOLVER |
677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to DNS service\n"); |
678 | "Trying to connect to DNS service\n"); | ||
679 | #endif | 662 | #endif |
680 | client = GNUNET_CLIENT_connect ("resolver", cfg); | 663 | client = GNUNET_CLIENT_connect ("resolver", cfg); |
681 | if (NULL == client) | 664 | if (NULL == client) |
682 | { | 665 | { |
683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
684 | "Failed to connect, will try again later\n"); | 667 | "Failed to connect, will try again later\n"); |
685 | reconnect (); | 668 | reconnect (); |
686 | return; | 669 | return; |
687 | } | 670 | } |
688 | process_requests (); | 671 | process_requests (); |
689 | } | 672 | } |
690 | 673 | ||
@@ -701,37 +684,33 @@ reconnect () | |||
701 | return; | 684 | return; |
702 | GNUNET_assert (NULL == client); | 685 | GNUNET_assert (NULL == client); |
703 | if (NULL != (rh = req_head)) | 686 | if (NULL != (rh = req_head)) |
687 | { | ||
688 | switch (rh->was_transmitted) | ||
704 | { | 689 | { |
705 | switch (rh->was_transmitted) | 690 | case GNUNET_NO: |
706 | { | 691 | /* nothing more to do */ |
707 | case GNUNET_NO: | 692 | break; |
708 | /* nothing more to do */ | 693 | case GNUNET_YES: |
709 | break; | 694 | /* disconnected, transmit again! */ |
710 | case GNUNET_YES: | 695 | rh->was_transmitted = GNUNET_NO; |
711 | /* disconnected, transmit again! */ | 696 | break; |
712 | rh->was_transmitted = GNUNET_NO; | 697 | case GNUNET_SYSERR: |
713 | break; | 698 | /* request was cancelled, remove entirely */ |
714 | case GNUNET_SYSERR: | 699 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); |
715 | /* request was cancelled, remove entirely */ | 700 | GNUNET_free (rh); |
716 | GNUNET_CONTAINER_DLL_remove (req_head, | 701 | break; |
717 | req_tail, | 702 | default: |
718 | rh); | 703 | GNUNET_assert (0); |
719 | GNUNET_free (rh); | 704 | break; |
720 | break; | ||
721 | default: | ||
722 | GNUNET_assert (0); | ||
723 | break; | ||
724 | } | ||
725 | } | 705 | } |
706 | } | ||
726 | #if DEBUG_RESOLVER | 707 | #if DEBUG_RESOLVER |
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
728 | "Will try to connect to DNS service in %llu ms\n", | 709 | "Will try to connect to DNS service in %llu ms\n", |
729 | (unsigned long long) backoff.rel_value); | 710 | (unsigned long long) backoff.rel_value); |
730 | #endif | 711 | #endif |
731 | GNUNET_assert (NULL != cfg); | 712 | GNUNET_assert (NULL != cfg); |
732 | r_task = GNUNET_SCHEDULER_add_delayed (backoff, | 713 | r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL); |
733 | &reconnect_task, | ||
734 | NULL); | ||
735 | backoff = GNUNET_TIME_relative_multiply (backoff, 2); | 714 | backoff = GNUNET_TIME_relative_multiply (backoff, 2); |
736 | } | 715 | } |
737 | 716 | ||
@@ -760,11 +739,12 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
760 | struct in6_addr v6; | 739 | struct in6_addr v6; |
761 | 740 | ||
762 | slen = strlen (hostname) + 1; | 741 | slen = strlen (hostname) + 1; |
763 | if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 742 | if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= |
764 | { | 743 | GNUNET_SERVER_MAX_MESSAGE_SIZE) |
765 | GNUNET_break (0); | 744 | { |
766 | return NULL; | 745 | GNUNET_break (0); |
767 | } | 746 | return NULL; |
747 | } | ||
768 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); | 748 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); |
769 | rh->domain = domain; | 749 | rh->domain = domain; |
770 | rh->addr_callback = callback; | 750 | rh->addr_callback = callback; |
@@ -782,27 +762,25 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
782 | hostname, | 762 | hostname, |
783 | &v6)) && | 763 | &v6)) && |
784 | ((domain == AF_INET6) || (domain == AF_UNSPEC)))) | 764 | ((domain == AF_INET6) || (domain == AF_UNSPEC)))) |
785 | { | 765 | { |
786 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); | 766 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); |
787 | return rh; | 767 | return rh; |
788 | } | 768 | } |
789 | /* then, check if this is a loopback address */ | 769 | /* then, check if this is a loopback address */ |
790 | i = 0; | 770 | i = 0; |
791 | while (loopback[i] != NULL) | 771 | while (loopback[i] != NULL) |
792 | if (0 == strcasecmp (loopback[i++], hostname)) | 772 | if (0 == strcasecmp (loopback[i++], hostname)) |
793 | { | ||
794 | rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh); | ||
795 | return rh; | ||
796 | } | ||
797 | GNUNET_CONTAINER_DLL_insert_tail (req_head, | ||
798 | req_tail, | ||
799 | rh); | ||
800 | rh->was_queued = GNUNET_YES; | ||
801 | if (s_task != GNUNET_SCHEDULER_NO_TASK) | ||
802 | { | 773 | { |
803 | GNUNET_SCHEDULER_cancel (s_task); | 774 | rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh); |
804 | s_task = GNUNET_SCHEDULER_NO_TASK; | 775 | return rh; |
805 | } | 776 | } |
777 | GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); | ||
778 | rh->was_queued = GNUNET_YES; | ||
779 | if (s_task != GNUNET_SCHEDULER_NO_TASK) | ||
780 | { | ||
781 | GNUNET_SCHEDULER_cancel (s_task); | ||
782 | s_task = GNUNET_SCHEDULER_NO_TASK; | ||
783 | } | ||
806 | process_requests (); | 784 | process_requests (); |
807 | return rh; | 785 | return rh; |
808 | } | 786 | } |
@@ -816,8 +794,7 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
816 | * @param tc unused scheduler context | 794 | * @param tc unused scheduler context |
817 | */ | 795 | */ |
818 | static void | 796 | static void |
819 | numeric_reverse (void *cls, | 797 | numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
820 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
821 | { | 798 | { |
822 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; | 799 | struct GNUNET_RESOLVER_RequestHandle *rh = cls; |
823 | char *result; | 800 | char *result; |
@@ -827,10 +804,10 @@ numeric_reverse (void *cls, | |||
827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result); | 804 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result); |
828 | #endif | 805 | #endif |
829 | if (result != NULL) | 806 | if (result != NULL) |
830 | { | 807 | { |
831 | rh->name_callback (rh->cls, result); | 808 | rh->name_callback (rh->cls, result); |
832 | GNUNET_free (result); | 809 | GNUNET_free (result); |
833 | } | 810 | } |
834 | rh->name_callback (rh->cls, NULL); | 811 | rh->name_callback (rh->cls, NULL); |
835 | GNUNET_free (rh); | 812 | GNUNET_free (rh); |
836 | } | 813 | } |
@@ -868,25 +845,24 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, | |||
868 | rh->direction = GNUNET_YES; | 845 | rh->direction = GNUNET_YES; |
869 | rh->received_response = GNUNET_NO; | 846 | rh->received_response = GNUNET_NO; |
870 | if (GNUNET_NO == do_resolve) | 847 | if (GNUNET_NO == do_resolve) |
871 | { | 848 | { |
872 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); | 849 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); |
873 | return rh; | 850 | return rh; |
874 | } | 851 | } |
875 | if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 852 | if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= |
876 | { | 853 | GNUNET_SERVER_MAX_MESSAGE_SIZE) |
877 | GNUNET_break (0); | 854 | { |
878 | GNUNET_free (rh); | 855 | GNUNET_break (0); |
879 | return NULL; | 856 | GNUNET_free (rh); |
880 | } | 857 | return NULL; |
881 | GNUNET_CONTAINER_DLL_insert_tail (req_head, | 858 | } |
882 | req_tail, | 859 | GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); |
883 | rh); | ||
884 | rh->was_queued = GNUNET_YES; | 860 | rh->was_queued = GNUNET_YES; |
885 | if (s_task != GNUNET_SCHEDULER_NO_TASK) | 861 | if (s_task != GNUNET_SCHEDULER_NO_TASK) |
886 | { | 862 | { |
887 | GNUNET_SCHEDULER_cancel (s_task); | 863 | GNUNET_SCHEDULER_cancel (s_task); |
888 | s_task = GNUNET_SCHEDULER_NO_TASK; | 864 | s_task = GNUNET_SCHEDULER_NO_TASK; |
889 | } | 865 | } |
890 | process_requests (); | 866 | process_requests (); |
891 | return rh; | 867 | return rh; |
892 | } | 868 | } |
@@ -901,26 +877,25 @@ char * | |||
901 | GNUNET_RESOLVER_local_fqdn_get () | 877 | GNUNET_RESOLVER_local_fqdn_get () |
902 | { | 878 | { |
903 | struct hostent *host; | 879 | struct hostent *host; |
904 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 880 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
905 | 881 | ||
906 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 882 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |
907 | { | 883 | { |
908 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | 884 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | |
909 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | 885 | GNUNET_ERROR_TYPE_BULK, "gethostname"); |
910 | return NULL; | 886 | return NULL; |
911 | } | 887 | } |
912 | #if DEBUG_RESOLVER | 888 | #if DEBUG_RESOLVER |
913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
914 | _("Resolving our FQDN `%s'\n"), hostname); | 890 | _("Resolving our FQDN `%s'\n"), hostname); |
915 | #endif | 891 | #endif |
916 | host = gethostbyname (hostname); | 892 | host = gethostbyname (hostname); |
917 | if (NULL == host) | 893 | if (NULL == host) |
918 | { | 894 | { |
919 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 895 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
920 | _("Could not resolve our FQDN : %s\n"), | 896 | _("Could not resolve our FQDN : %s\n"), hstrerror (h_errno)); |
921 | hstrerror (h_errno)); | 897 | return NULL; |
922 | return NULL; | 898 | } |
923 | } | ||
924 | return GNUNET_strdup (host->h_name); | 899 | return GNUNET_strdup (host->h_name); |
925 | } | 900 | } |
926 | 901 | ||
@@ -940,22 +915,19 @@ GNUNET_RESOLVER_hostname_resolve (int domain, | |||
940 | GNUNET_RESOLVER_AddressCallback callback, | 915 | GNUNET_RESOLVER_AddressCallback callback, |
941 | void *cls) | 916 | void *cls) |
942 | { | 917 | { |
943 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 918 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
944 | 919 | ||
945 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 920 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |
946 | { | 921 | { |
947 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | 922 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | |
948 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | 923 | GNUNET_ERROR_TYPE_BULK, "gethostname"); |
949 | return NULL; | 924 | return NULL; |
950 | } | 925 | } |
951 | #if DEBUG_RESOLVER | 926 | #if DEBUG_RESOLVER |
952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 927 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
953 | _("Resolving our hostname `%s'\n"), hostname); | 928 | _("Resolving our hostname `%s'\n"), hostname); |
954 | #endif | 929 | #endif |
955 | return GNUNET_RESOLVER_ip_get (hostname, | 930 | return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls); |
956 | domain, | ||
957 | timeout, | ||
958 | callback, cls); | ||
959 | } | 931 | } |
960 | 932 | ||
961 | 933 | ||
@@ -971,21 +943,19 @@ void | |||
971 | GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) | 943 | GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) |
972 | { | 944 | { |
973 | if (rh->task != GNUNET_SCHEDULER_NO_TASK) | 945 | if (rh->task != GNUNET_SCHEDULER_NO_TASK) |
974 | { | 946 | { |
975 | GNUNET_SCHEDULER_cancel (rh->task); | 947 | GNUNET_SCHEDULER_cancel (rh->task); |
976 | rh->task = GNUNET_SCHEDULER_NO_TASK; | 948 | rh->task = GNUNET_SCHEDULER_NO_TASK; |
977 | } | 949 | } |
978 | if (rh->was_transmitted == GNUNET_NO) | 950 | if (rh->was_transmitted == GNUNET_NO) |
979 | { | 951 | { |
980 | if (rh->was_queued == GNUNET_YES) | 952 | if (rh->was_queued == GNUNET_YES) |
981 | GNUNET_CONTAINER_DLL_remove (req_head, | 953 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); |
982 | req_tail, | 954 | GNUNET_free (rh); |
983 | rh); | 955 | return; |
984 | GNUNET_free (rh); | 956 | } |
985 | return; | ||
986 | } | ||
987 | GNUNET_assert (rh->was_transmitted == GNUNET_YES); | 957 | GNUNET_assert (rh->was_transmitted == GNUNET_YES); |
988 | rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ | 958 | rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */ |
989 | } | 959 | } |
990 | 960 | ||
991 | 961 | ||
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index e4a31c388..9412457f6 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -149,7 +149,7 @@ struct Task | |||
149 | * Set if we only wait for writing to a single FD, otherwise -1. | 149 | * Set if we only wait for writing to a single FD, otherwise -1. |
150 | */ | 150 | */ |
151 | int write_fd; | 151 | int write_fd; |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * Should the existence of this task in the queue be counted as | 154 | * Should the existence of this task in the queue be counted as |
155 | * reason to not shutdown the scheduler? | 155 | * reason to not shutdown the scheduler? |
@@ -264,7 +264,7 @@ static void *scheduler_select_cls; | |||
264 | */ | 264 | */ |
265 | void | 265 | void |
266 | GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, | 266 | GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, |
267 | void *new_select_cls) | 267 | void *new_select_cls) |
268 | { | 268 | { |
269 | scheduler_select = new_select; | 269 | scheduler_select = new_select; |
270 | scheduler_select_cls = new_select_cls; | 270 | scheduler_select_cls = new_select_cls; |
@@ -308,15 +308,26 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id) | |||
308 | min = -1; /* maximum value */ | 308 | min = -1; /* maximum value */ |
309 | pos = pending; | 309 | pos = pending; |
310 | while (pos != NULL) | 310 | while (pos != NULL) |
311 | { | 311 | { |
312 | if (pos->id == id) | 312 | if (pos->id == id) |
313 | return GNUNET_YES; | 313 | return GNUNET_YES; |
314 | if (pos->id < min) | 314 | if (pos->id < min) |
315 | min = pos->id; | 315 | min = pos->id; |
316 | pos = pos->next; | 316 | pos = pos->next; |
317 | } | 317 | } |
318 | pos = pending_timeout; | 318 | pos = pending_timeout; |
319 | while (pos != NULL) | 319 | while (pos != NULL) |
320 | { | ||
321 | if (pos->id == id) | ||
322 | return GNUNET_YES; | ||
323 | if (pos->id < min) | ||
324 | min = pos->id; | ||
325 | pos = pos->next; | ||
326 | } | ||
327 | for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) | ||
328 | { | ||
329 | pos = ready[p]; | ||
330 | while (pos != NULL) | ||
320 | { | 331 | { |
321 | if (pos->id == id) | 332 | if (pos->id == id) |
322 | return GNUNET_YES; | 333 | return GNUNET_YES; |
@@ -324,18 +335,7 @@ is_pending (GNUNET_SCHEDULER_TaskIdentifier id) | |||
324 | min = pos->id; | 335 | min = pos->id; |
325 | pos = pos->next; | 336 | pos = pos->next; |
326 | } | 337 | } |
327 | for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++) | 338 | } |
328 | { | ||
329 | pos = ready[p]; | ||
330 | while (pos != NULL) | ||
331 | { | ||
332 | if (pos->id == id) | ||
333 | return GNUNET_YES; | ||
334 | if (pos->id < min) | ||
335 | min = pos->id; | ||
336 | pos = pos->next; | ||
337 | } | ||
338 | } | ||
339 | lowest_pending_id = min; | 339 | lowest_pending_id = min; |
340 | return GNUNET_NO; | 340 | return GNUNET_NO; |
341 | } | 341 | } |
@@ -359,41 +359,41 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, | |||
359 | 359 | ||
360 | now = GNUNET_TIME_absolute_get (); | 360 | now = GNUNET_TIME_absolute_get (); |
361 | pos = pending_timeout; | 361 | pos = pending_timeout; |
362 | if (pos != NULL) | 362 | if (pos != NULL) |
363 | { | 363 | { |
364 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | 364 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); |
365 | if (timeout->rel_value > to.rel_value) | 365 | if (timeout->rel_value > to.rel_value) |
366 | *timeout = to; | 366 | *timeout = to; |
367 | if (pos->reason != 0) | 367 | if (pos->reason != 0) |
368 | *timeout = GNUNET_TIME_UNIT_ZERO; | 368 | *timeout = GNUNET_TIME_UNIT_ZERO; |
369 | } | 369 | } |
370 | pos = pending; | 370 | pos = pending; |
371 | while (pos != NULL) | 371 | while (pos != NULL) |
372 | { | ||
373 | if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) && | ||
374 | (GNUNET_YES == is_pending (pos->prereq_id))) | ||
372 | { | 375 | { |
373 | if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) && | ||
374 | (GNUNET_YES == is_pending (pos->prereq_id))) | ||
375 | { | ||
376 | pos = pos->next; | ||
377 | continue; | ||
378 | } | ||
379 | if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
380 | { | ||
381 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | ||
382 | if (timeout->rel_value > to.rel_value) | ||
383 | *timeout = to; | ||
384 | } | ||
385 | if (pos->read_fd != -1) | ||
386 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); | ||
387 | if (pos->write_fd != -1) | ||
388 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); | ||
389 | if (pos->read_set != NULL) | ||
390 | GNUNET_NETWORK_fdset_add (rs, pos->read_set); | ||
391 | if (pos->write_set != NULL) | ||
392 | GNUNET_NETWORK_fdset_add (ws, pos->write_set); | ||
393 | if (pos->reason != 0) | ||
394 | *timeout = GNUNET_TIME_UNIT_ZERO; | ||
395 | pos = pos->next; | 376 | pos = pos->next; |
377 | continue; | ||
378 | } | ||
379 | if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
380 | { | ||
381 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | ||
382 | if (timeout->rel_value > to.rel_value) | ||
383 | *timeout = to; | ||
396 | } | 384 | } |
385 | if (pos->read_fd != -1) | ||
386 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); | ||
387 | if (pos->write_fd != -1) | ||
388 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); | ||
389 | if (pos->read_set != NULL) | ||
390 | GNUNET_NETWORK_fdset_add (rs, pos->read_set); | ||
391 | if (pos->write_set != NULL) | ||
392 | GNUNET_NETWORK_fdset_add (ws, pos->write_set); | ||
393 | if (pos->reason != 0) | ||
394 | *timeout = GNUNET_TIME_UNIT_ZERO; | ||
395 | pos = pos->next; | ||
396 | } | ||
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
@@ -410,15 +410,15 @@ static int | |||
410 | set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, | 410 | set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, |
411 | struct GNUNET_NETWORK_FDSet *want) | 411 | struct GNUNET_NETWORK_FDSet *want) |
412 | { | 412 | { |
413 | if ( (NULL == want) || (NULL == ready) ) | 413 | if ((NULL == want) || (NULL == ready)) |
414 | return GNUNET_NO; | 414 | return GNUNET_NO; |
415 | if (GNUNET_NETWORK_fdset_overlap (ready, want)) | 415 | if (GNUNET_NETWORK_fdset_overlap (ready, want)) |
416 | { | 416 | { |
417 | /* copy all over (yes, there maybe unrelated bits, | 417 | /* copy all over (yes, there maybe unrelated bits, |
418 | but this should not hurt well-written clients) */ | 418 | * but this should not hurt well-written clients) */ |
419 | GNUNET_NETWORK_fdset_copy (want, ready); | 419 | GNUNET_NETWORK_fdset_copy (want, ready); |
420 | return GNUNET_YES; | 420 | return GNUNET_YES; |
421 | } | 421 | } |
422 | return GNUNET_NO; | 422 | return GNUNET_NO; |
423 | } | 423 | } |
424 | 424 | ||
@@ -444,27 +444,27 @@ is_ready (struct Task *task, | |||
444 | reason = task->reason; | 444 | reason = task->reason; |
445 | if (now.abs_value >= task->timeout.abs_value) | 445 | if (now.abs_value >= task->timeout.abs_value) |
446 | reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; | 446 | reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; |
447 | if ( (0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && | 447 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && |
448 | ( ( (task->read_fd != -1) && | 448 | (((task->read_fd != -1) && |
449 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd)) ) || | 449 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) || |
450 | (set_overlaps (rs, task->read_set) ) ) ) | 450 | (set_overlaps (rs, task->read_set)))) |
451 | reason |= GNUNET_SCHEDULER_REASON_READ_READY; | 451 | reason |= GNUNET_SCHEDULER_REASON_READ_READY; |
452 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && | 452 | if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && |
453 | ( ( (task->write_fd != -1) && | 453 | (((task->write_fd != -1) && |
454 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd)) ) || | 454 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) |
455 | (set_overlaps (ws, task->write_set) ) ) ) | 455 | || (set_overlaps (ws, task->write_set)))) |
456 | reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; | 456 | reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; |
457 | if (reason == 0) | 457 | if (reason == 0) |
458 | return GNUNET_NO; /* not ready */ | 458 | return GNUNET_NO; /* not ready */ |
459 | if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK) | 459 | if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK) |
460 | { | ||
461 | if (GNUNET_YES == is_pending (task->prereq_id)) | ||
460 | { | 462 | { |
461 | if (GNUNET_YES == is_pending (task->prereq_id)) | 463 | task->reason = reason; |
462 | { | 464 | return GNUNET_NO; /* prereq waiting */ |
463 | task->reason = reason; | ||
464 | return GNUNET_NO; /* prereq waiting */ | ||
465 | } | ||
466 | reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; | ||
467 | } | 465 | } |
466 | reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; | ||
467 | } | ||
468 | task->reason = reason; | 468 | task->reason = reason; |
469 | return GNUNET_YES; | 469 | return GNUNET_YES; |
470 | } | 470 | } |
@@ -479,6 +479,7 @@ static void | |||
479 | queue_ready_task (struct Task *task) | 479 | queue_ready_task (struct Task *task) |
480 | { | 480 | { |
481 | enum GNUNET_SCHEDULER_Priority p = task->priority; | 481 | enum GNUNET_SCHEDULER_Priority p = task->priority; |
482 | |||
482 | if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 483 | if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
483 | p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN; | 484 | p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN; |
484 | task->next = ready[check_priority (p)]; | 485 | task->next = ready[check_priority (p)]; |
@@ -507,40 +508,40 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, | |||
507 | prev = NULL; | 508 | prev = NULL; |
508 | pos = pending_timeout; | 509 | pos = pending_timeout; |
509 | while (pos != NULL) | 510 | while (pos != NULL) |
510 | { | 511 | { |
511 | next = pos->next; | 512 | next = pos->next; |
512 | if (now.abs_value >= pos->timeout.abs_value) | 513 | if (now.abs_value >= pos->timeout.abs_value) |
513 | pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; | 514 | pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; |
514 | if (0 == pos->reason) | 515 | if (0 == pos->reason) |
515 | break; | 516 | break; |
516 | pending_timeout = next; | 517 | pending_timeout = next; |
517 | if (pending_timeout_last == pos) | 518 | if (pending_timeout_last == pos) |
518 | pending_timeout_last = NULL; | 519 | pending_timeout_last = NULL; |
519 | queue_ready_task (pos); | 520 | queue_ready_task (pos); |
520 | pos = next; | 521 | pos = next; |
521 | } | 522 | } |
522 | pos = pending; | 523 | pos = pending; |
523 | while (pos != NULL) | 524 | while (pos != NULL) |
524 | { | 525 | { |
525 | #if DEBUG_TASKS | 526 | #if DEBUG_TASKS |
526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
527 | "Checking readiness of task: %llu / %p\n", | 528 | "Checking readiness of task: %llu / %p\n", |
528 | pos->id, pos->callback_cls); | 529 | pos->id, pos->callback_cls); |
529 | #endif | 530 | #endif |
530 | next = pos->next; | 531 | next = pos->next; |
531 | if (GNUNET_YES == is_ready (pos, now, rs, ws)) | 532 | if (GNUNET_YES == is_ready (pos, now, rs, ws)) |
532 | { | 533 | { |
533 | if (prev == NULL) | 534 | if (prev == NULL) |
534 | pending = next; | 535 | pending = next; |
535 | else | 536 | else |
536 | prev->next = next; | 537 | prev->next = next; |
537 | queue_ready_task (pos); | 538 | queue_ready_task (pos); |
538 | pos = next; | ||
539 | continue; | ||
540 | } | ||
541 | prev = pos; | ||
542 | pos = next; | 539 | pos = next; |
540 | continue; | ||
543 | } | 541 | } |
542 | prev = pos; | ||
543 | pos = next; | ||
544 | } | ||
544 | } | 545 | } |
545 | 546 | ||
546 | 547 | ||
@@ -559,34 +560,34 @@ GNUNET_SCHEDULER_shutdown () | |||
559 | 560 | ||
560 | pos = pending_timeout; | 561 | pos = pending_timeout; |
561 | while (pos != NULL) | 562 | while (pos != NULL) |
562 | { | 563 | { |
563 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 564 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
564 | /* we don't move the task into the ready queue yet; check_ready | 565 | /* we don't move the task into the ready queue yet; check_ready |
565 | will do that later, possibly adding additional | 566 | * will do that later, possibly adding additional |
566 | readiness-factors */ | 567 | * readiness-factors */ |
567 | pos = pos->next; | 568 | pos = pos->next; |
568 | } | 569 | } |
569 | pos = pending; | 570 | pos = pending; |
570 | while (pos != NULL) | 571 | while (pos != NULL) |
572 | { | ||
573 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | ||
574 | /* we don't move the task into the ready queue yet; check_ready | ||
575 | * will do that later, possibly adding additional | ||
576 | * readiness-factors */ | ||
577 | pos = pos->next; | ||
578 | } | ||
579 | for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) | ||
580 | { | ||
581 | pos = ready[i]; | ||
582 | while (pos != NULL) | ||
571 | { | 583 | { |
572 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 584 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
573 | /* we don't move the task into the ready queue yet; check_ready | 585 | /* we don't move the task into the ready queue yet; check_ready |
574 | will do that later, possibly adding additional | 586 | * will do that later, possibly adding additional |
575 | readiness-factors */ | 587 | * readiness-factors */ |
576 | pos = pos->next; | 588 | pos = pos->next; |
577 | } | 589 | } |
578 | for (i=0;i<GNUNET_SCHEDULER_PRIORITY_COUNT;i++) | 590 | } |
579 | { | ||
580 | pos = ready[i]; | ||
581 | while (pos != NULL) | ||
582 | { | ||
583 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | ||
584 | /* we don't move the task into the ready queue yet; check_ready | ||
585 | will do that later, possibly adding additional | ||
586 | readiness-factors */ | ||
587 | pos = pos->next; | ||
588 | } | ||
589 | } | ||
590 | } | 591 | } |
591 | 592 | ||
592 | 593 | ||
@@ -620,8 +621,7 @@ destroy_task (struct Task *t) | |||
620 | * @param ws FDs ready for writing | 621 | * @param ws FDs ready for writing |
621 | */ | 622 | */ |
622 | static void | 623 | static void |
623 | run_ready (struct GNUNET_NETWORK_FDSet *rs, | 624 | run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) |
624 | struct GNUNET_NETWORK_FDSet *ws) | ||
625 | { | 625 | { |
626 | enum GNUNET_SCHEDULER_Priority p; | 626 | enum GNUNET_SCHEDULER_Priority p; |
627 | struct Task *pos; | 627 | struct Task *pos; |
@@ -629,74 +629,72 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, | |||
629 | 629 | ||
630 | max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; | 630 | max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; |
631 | do | 631 | do |
632 | { | ||
633 | if (ready_count == 0) | ||
634 | return; | ||
635 | GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); | ||
636 | /* yes, p>0 is correct, 0 is "KEEP" which should | ||
637 | * always be an empty queue (see assertion)! */ | ||
638 | for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) | ||
639 | { | ||
640 | pos = ready[p]; | ||
641 | if (pos != NULL) | ||
642 | break; | ||
643 | } | ||
644 | GNUNET_assert (pos != NULL); /* ready_count wrong? */ | ||
645 | ready[p] = pos->next; | ||
646 | ready_count--; | ||
647 | if (current_priority != pos->priority) | ||
632 | { | 648 | { |
633 | if (ready_count == 0) | 649 | current_priority = pos->priority; |
634 | return; | 650 | (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), |
635 | GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); | 651 | pos->priority); |
636 | /* yes, p>0 is correct, 0 is "KEEP" which should | 652 | } |
637 | always be an empty queue (see assertion)! */ | 653 | current_lifeness = pos->lifeness; |
638 | for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) | 654 | active_task = pos; |
639 | { | ||
640 | pos = ready[p]; | ||
641 | if (pos != NULL) | ||
642 | break; | ||
643 | } | ||
644 | GNUNET_assert (pos != NULL); /* ready_count wrong? */ | ||
645 | ready[p] = pos->next; | ||
646 | ready_count--; | ||
647 | if (current_priority != pos->priority) | ||
648 | { | ||
649 | current_priority = pos->priority; | ||
650 | (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), | ||
651 | pos->priority); | ||
652 | } | ||
653 | current_lifeness = pos->lifeness; | ||
654 | active_task = pos; | ||
655 | #if PROFILE_DELAYS | 655 | #if PROFILE_DELAYS |
656 | if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > | 656 | if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > |
657 | DELAY_THRESHOLD.rel_value) | 657 | DELAY_THRESHOLD.rel_value) |
658 | { | 658 | { |
659 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 659 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
660 | "Task %llu took %llums to be scheduled\n", | 660 | "Task %llu took %llums to be scheduled\n", |
661 | pos->id, | 661 | pos->id, |
662 | (unsigned long long) GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value); | 662 | (unsigned long long) |
663 | } | 663 | GNUNET_TIME_absolute_get_duration |
664 | (pos->start_time).rel_value); | ||
665 | } | ||
664 | #endif | 666 | #endif |
665 | tc.reason = pos->reason; | 667 | tc.reason = pos->reason; |
666 | tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; | 668 | tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; |
667 | if ( (pos->read_fd != -1) && | 669 | if ((pos->read_fd != -1) && |
668 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)) ) | 670 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) |
669 | GNUNET_NETWORK_fdset_set_native (rs, | 671 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); |
670 | pos->read_fd); | 672 | tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; |
671 | tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; | 673 | if ((pos->write_fd != -1) && |
672 | if ( (pos->write_fd != -1) && | 674 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) |
673 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ) | 675 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); |
674 | GNUNET_NETWORK_fdset_set_native (ws, | 676 | if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && |
675 | pos->write_fd); | 677 | (pos->write_fd != -1) && |
676 | if ( ( (tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && | 678 | (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) |
677 | (pos->write_fd != -1) && | 679 | abort (); // added to ready in previous select loop! |
678 | (! GNUNET_NETWORK_fdset_test_native (ws, | ||
679 | pos->write_fd))) | ||
680 | abort (); // added to ready in previous select loop! | ||
681 | #if DEBUG_TASKS | 680 | #if DEBUG_TASKS |
682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
683 | "Running task: %llu / %p\n", pos->id, pos->callback_cls); | 682 | "Running task: %llu / %p\n", pos->id, pos->callback_cls); |
684 | #endif | 683 | #endif |
685 | pos->callback (pos->callback_cls, &tc); | 684 | pos->callback (pos->callback_cls, &tc); |
686 | #if EXECINFO | 685 | #if EXECINFO |
687 | int i; | 686 | int i; |
688 | for (i=0;i<pos->num_backtrace_strings;i++) | 687 | |
689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 688 | for (i = 0; i < pos->num_backtrace_strings; i++) |
690 | "Task %llu trace %d: %s\n", | 689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
691 | pos->id, | 690 | "Task %llu trace %d: %s\n", |
692 | i, | 691 | pos->id, i, pos->backtrace_strings[i]); |
693 | pos->backtrace_strings[i]); | ||
694 | #endif | 692 | #endif |
695 | active_task = NULL; | 693 | active_task = NULL; |
696 | destroy_task (pos); | 694 | destroy_task (pos); |
697 | tasks_run++; | 695 | tasks_run++; |
698 | } | 696 | } |
699 | while ( (pending == NULL) || (p >= max_priority_added) ); | 697 | while ((pending == NULL) || (p >= max_priority_added)); |
700 | } | 698 | } |
701 | 699 | ||
702 | /** | 700 | /** |
@@ -721,11 +719,11 @@ static void | |||
721 | sighandler_shutdown () | 719 | sighandler_shutdown () |
722 | { | 720 | { |
723 | static char c; | 721 | static char c; |
724 | int old_errno = errno; /* backup errno */ | 722 | int old_errno = errno; /* backup errno */ |
725 | 723 | ||
726 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 724 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle |
727 | (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), &c, | 725 | (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_WRITE), |
728 | sizeof (c)); | 726 | &c, sizeof (c)); |
729 | errno = old_errno; | 727 | errno = old_errno; |
730 | } | 728 | } |
731 | 729 | ||
@@ -738,9 +736,10 @@ sighandler_shutdown () | |||
738 | * GNUNET_NO to exit | 736 | * GNUNET_NO to exit |
739 | */ | 737 | */ |
740 | static int | 738 | static int |
741 | check_lifeness() | 739 | check_lifeness () |
742 | { | 740 | { |
743 | struct Task *t; | 741 | struct Task *t; |
742 | |||
744 | if (ready_count > 0) | 743 | if (ready_count > 0) |
745 | return GNUNET_OK; | 744 | return GNUNET_OK; |
746 | for (t = pending; NULL != t; t = t->next) | 745 | for (t = pending; NULL != t; t = t->next) |
@@ -748,12 +747,12 @@ check_lifeness() | |||
748 | return GNUNET_OK; | 747 | return GNUNET_OK; |
749 | for (t = pending_timeout; NULL != t; t = t->next) | 748 | for (t = pending_timeout; NULL != t; t = t->next) |
750 | if (t->lifeness == GNUNET_YES) | 749 | if (t->lifeness == GNUNET_YES) |
751 | return GNUNET_OK; | ||
752 | if ( (NULL != pending) || (NULL != pending_timeout) ) | ||
753 | { | ||
754 | GNUNET_SCHEDULER_shutdown (); | ||
755 | return GNUNET_OK; | 750 | return GNUNET_OK; |
756 | } | 751 | if ((NULL != pending) || (NULL != pending_timeout)) |
752 | { | ||
753 | GNUNET_SCHEDULER_shutdown (); | ||
754 | return GNUNET_OK; | ||
755 | } | ||
757 | return GNUNET_NO; | 756 | return GNUNET_NO; |
758 | } | 757 | } |
759 | 758 | ||
@@ -781,6 +780,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
781 | int ret; | 780 | int ret; |
782 | struct GNUNET_SIGNAL_Context *shc_int; | 781 | struct GNUNET_SIGNAL_Context *shc_int; |
783 | struct GNUNET_SIGNAL_Context *shc_term; | 782 | struct GNUNET_SIGNAL_Context *shc_term; |
783 | |||
784 | #ifndef MINGW | 784 | #ifndef MINGW |
785 | struct GNUNET_SIGNAL_Context *shc_quit; | 785 | struct GNUNET_SIGNAL_Context *shc_quit; |
786 | struct GNUNET_SIGNAL_Context *shc_hup; | 786 | struct GNUNET_SIGNAL_Context *shc_hup; |
@@ -795,9 +795,10 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
795 | rs = GNUNET_NETWORK_fdset_create (); | 795 | rs = GNUNET_NETWORK_fdset_create (); |
796 | ws = GNUNET_NETWORK_fdset_create (); | 796 | ws = GNUNET_NETWORK_fdset_create (); |
797 | GNUNET_assert (shutdown_pipe_handle == NULL); | 797 | GNUNET_assert (shutdown_pipe_handle == NULL); |
798 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); | 798 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); |
799 | GNUNET_assert (shutdown_pipe_handle != NULL); | 799 | GNUNET_assert (shutdown_pipe_handle != NULL); |
800 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, GNUNET_DISK_PIPE_END_READ); | 800 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, |
801 | GNUNET_DISK_PIPE_END_READ); | ||
801 | GNUNET_assert (pr != NULL); | 802 | GNUNET_assert (pr != NULL); |
802 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); | 803 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); |
803 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); | 804 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); |
@@ -809,79 +810,77 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
809 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; | 810 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; |
810 | current_lifeness = GNUNET_YES; | 811 | current_lifeness = GNUNET_YES; |
811 | GNUNET_SCHEDULER_add_continuation (task, | 812 | GNUNET_SCHEDULER_add_continuation (task, |
812 | task_cls, | 813 | task_cls, GNUNET_SCHEDULER_REASON_STARTUP); |
813 | GNUNET_SCHEDULER_REASON_STARTUP); | ||
814 | #if ENABLE_WINDOWS_WORKAROUNDS | 814 | #if ENABLE_WINDOWS_WORKAROUNDS |
815 | active_task = (void*) (long) -1; /* force passing of sanity check */ | 815 | active_task = (void *) (long) -1; /* force passing of sanity check */ |
816 | GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, | 816 | GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, |
817 | &GNUNET_OS_install_parent_control_handler, | 817 | &GNUNET_OS_install_parent_control_handler, |
818 | NULL); | 818 | NULL); |
819 | active_task = NULL; | 819 | active_task = NULL; |
820 | #endif | 820 | #endif |
821 | last_tr = 0; | 821 | last_tr = 0; |
822 | busy_wait_warning = 0; | 822 | busy_wait_warning = 0; |
823 | while (GNUNET_OK == check_lifeness ()) | 823 | while (GNUNET_OK == check_lifeness ()) |
824 | { | ||
825 | GNUNET_NETWORK_fdset_zero (rs); | ||
826 | GNUNET_NETWORK_fdset_zero (ws); | ||
827 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
828 | update_sets (rs, ws, &timeout); | ||
829 | GNUNET_NETWORK_fdset_handle_set (rs, pr); | ||
830 | if (ready_count > 0) | ||
824 | { | 831 | { |
825 | GNUNET_NETWORK_fdset_zero (rs); | 832 | /* no blocking, more work already ready! */ |
826 | GNUNET_NETWORK_fdset_zero (ws); | 833 | timeout = GNUNET_TIME_UNIT_ZERO; |
827 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 834 | } |
828 | update_sets (rs, ws, &timeout); | 835 | if (NULL == scheduler_select) |
829 | GNUNET_NETWORK_fdset_handle_set (rs, pr); | 836 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); |
830 | if (ready_count > 0) | 837 | else |
831 | { | 838 | ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout); |
832 | /* no blocking, more work already ready! */ | 839 | if (ret == GNUNET_SYSERR) |
833 | timeout = GNUNET_TIME_UNIT_ZERO; | 840 | { |
834 | } | 841 | if (errno == EINTR) |
835 | if (NULL == scheduler_select) | 842 | continue; |
836 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); | 843 | |
837 | else | 844 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); |
838 | ret = scheduler_select (scheduler_select_cls, | ||
839 | rs, ws, NULL, | ||
840 | timeout); | ||
841 | if (ret == GNUNET_SYSERR) | ||
842 | { | ||
843 | if (errno == EINTR) | ||
844 | continue; | ||
845 | |||
846 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); | ||
847 | #ifndef MINGW | 845 | #ifndef MINGW |
848 | #if USE_LSOF | 846 | #if USE_LSOF |
849 | char lsof[512]; | 847 | char lsof[512]; |
850 | snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid()); | 848 | |
851 | (void) close (1); | 849 | snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ()); |
852 | (void) dup2 (2, 1); | 850 | (void) close (1); |
853 | if (0 != system (lsof)) | 851 | (void) dup2 (2, 1); |
854 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "system"); | 852 | if (0 != system (lsof)) |
853 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "system"); | ||
855 | #endif | 854 | #endif |
856 | #endif | 855 | #endif |
857 | abort (); | 856 | abort (); |
858 | break; | 857 | break; |
859 | } | 858 | } |
860 | if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) | 859 | if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) |
861 | { | 860 | { |
862 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 861 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
863 | _("Looks like we're busy waiting...\n")); | 862 | _("Looks like we're busy waiting...\n")); |
864 | sleep (1); /* mitigate */ | 863 | sleep (1); /* mitigate */ |
865 | } | ||
866 | check_ready (rs, ws); | ||
867 | run_ready (rs, ws); | ||
868 | if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) | ||
869 | { | ||
870 | /* consume the signal */ | ||
871 | GNUNET_DISK_file_read (pr, &c, sizeof (c)); | ||
872 | /* mark all active tasks as ready due to shutdown */ | ||
873 | GNUNET_SCHEDULER_shutdown (); | ||
874 | } | ||
875 | if (last_tr == tasks_run) | ||
876 | { | ||
877 | busy_wait_warning++; | ||
878 | } | ||
879 | else | ||
880 | { | ||
881 | last_tr = tasks_run; | ||
882 | busy_wait_warning = 0; | ||
883 | } | ||
884 | } | 864 | } |
865 | check_ready (rs, ws); | ||
866 | run_ready (rs, ws); | ||
867 | if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) | ||
868 | { | ||
869 | /* consume the signal */ | ||
870 | GNUNET_DISK_file_read (pr, &c, sizeof (c)); | ||
871 | /* mark all active tasks as ready due to shutdown */ | ||
872 | GNUNET_SCHEDULER_shutdown (); | ||
873 | } | ||
874 | if (last_tr == tasks_run) | ||
875 | { | ||
876 | busy_wait_warning++; | ||
877 | } | ||
878 | else | ||
879 | { | ||
880 | last_tr = tasks_run; | ||
881 | busy_wait_warning = 0; | ||
882 | } | ||
883 | } | ||
885 | GNUNET_SIGNAL_handler_uninstall (shc_int); | 884 | GNUNET_SIGNAL_handler_uninstall (shc_int); |
886 | GNUNET_SIGNAL_handler_uninstall (shc_term); | 885 | GNUNET_SIGNAL_handler_uninstall (shc_term); |
887 | #ifndef MINGW | 886 | #ifndef MINGW |
@@ -934,10 +933,10 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p) | |||
934 | ret = 0; | 933 | ret = 0; |
935 | pos = ready[check_priority (p)]; | 934 | pos = ready[check_priority (p)]; |
936 | while (pos != NULL) | 935 | while (pos != NULL) |
937 | { | 936 | { |
938 | pos = pos->next; | 937 | pos = pos->next; |
939 | ret++; | 938 | ret++; |
940 | } | 939 | } |
941 | return ret; | 940 | return ret; |
942 | } | 941 | } |
943 | 942 | ||
@@ -963,73 +962,73 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
963 | prev = NULL; | 962 | prev = NULL; |
964 | t = pending; | 963 | t = pending; |
965 | while (t != NULL) | 964 | while (t != NULL) |
965 | { | ||
966 | if (t->id == task) | ||
967 | break; | ||
968 | prev = t; | ||
969 | t = t->next; | ||
970 | } | ||
971 | if (t == NULL) | ||
972 | { | ||
973 | prev = NULL; | ||
974 | to = 1; | ||
975 | t = pending_timeout; | ||
976 | while (t != NULL) | ||
966 | { | 977 | { |
967 | if (t->id == task) | 978 | if (t->id == task) |
968 | break; | 979 | break; |
969 | prev = t; | 980 | prev = t; |
970 | t = t->next; | 981 | t = t->next; |
971 | } | 982 | } |
972 | if (t == NULL) | 983 | if (pending_timeout_last == t) |
973 | { | 984 | pending_timeout_last = NULL; |
974 | prev = NULL; | 985 | } |
975 | to = 1; | ||
976 | t = pending_timeout; | ||
977 | while (t != NULL) | ||
978 | { | ||
979 | if (t->id == task) | ||
980 | break; | ||
981 | prev = t; | ||
982 | t = t->next; | ||
983 | } | ||
984 | if (pending_timeout_last == t) | ||
985 | pending_timeout_last = NULL; | ||
986 | } | ||
987 | p = 0; | 986 | p = 0; |
988 | while (t == NULL) | 987 | while (t == NULL) |
988 | { | ||
989 | p++; | ||
990 | if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) | ||
989 | { | 991 | { |
990 | p++; | 992 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
991 | if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) | 993 | _("Attempt to cancel dead task %llu!\n"), |
992 | { | 994 | (unsigned long long) task); |
993 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 995 | GNUNET_assert (0); |
994 | _("Attempt to cancel dead task %llu!\n"), | ||
995 | (unsigned long long) task); | ||
996 | GNUNET_assert (0); | ||
997 | } | ||
998 | prev = NULL; | ||
999 | t = ready[p]; | ||
1000 | while (t != NULL) | ||
1001 | { | ||
1002 | if (t->id == task) | ||
1003 | { | ||
1004 | ready_count--; | ||
1005 | break; | ||
1006 | } | ||
1007 | prev = t; | ||
1008 | t = t->next; | ||
1009 | } | ||
1010 | } | 996 | } |
997 | prev = NULL; | ||
998 | t = ready[p]; | ||
999 | while (t != NULL) | ||
1000 | { | ||
1001 | if (t->id == task) | ||
1002 | { | ||
1003 | ready_count--; | ||
1004 | break; | ||
1005 | } | ||
1006 | prev = t; | ||
1007 | t = t->next; | ||
1008 | } | ||
1009 | } | ||
1011 | if (prev == NULL) | 1010 | if (prev == NULL) |
1011 | { | ||
1012 | if (p == 0) | ||
1012 | { | 1013 | { |
1013 | if (p == 0) | 1014 | if (to == 0) |
1014 | { | 1015 | { |
1015 | if (to == 0) | 1016 | pending = t->next; |
1016 | { | 1017 | } |
1017 | pending = t->next; | ||
1018 | } | ||
1019 | else | ||
1020 | { | ||
1021 | pending_timeout = t->next; | ||
1022 | } | ||
1023 | } | ||
1024 | else | 1018 | else |
1025 | { | 1019 | { |
1026 | ready[p] = t->next; | 1020 | pending_timeout = t->next; |
1027 | } | 1021 | } |
1028 | } | 1022 | } |
1029 | else | 1023 | else |
1030 | { | 1024 | { |
1031 | prev->next = t->next; | 1025 | ready[p] = t->next; |
1032 | } | 1026 | } |
1027 | } | ||
1028 | else | ||
1029 | { | ||
1030 | prev->next = t->next; | ||
1031 | } | ||
1033 | ret = t->callback_cls; | 1032 | ret = t->callback_cls; |
1034 | #if DEBUG_TASKS | 1033 | #if DEBUG_TASKS |
1035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1055,17 +1054,19 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, | |||
1055 | enum GNUNET_SCHEDULER_Reason reason) | 1054 | enum GNUNET_SCHEDULER_Reason reason) |
1056 | { | 1055 | { |
1057 | struct Task *t; | 1056 | struct Task *t; |
1057 | |||
1058 | #if EXECINFO | 1058 | #if EXECINFO |
1059 | void *backtrace_array[50]; | 1059 | void *backtrace_array[50]; |
1060 | #endif | 1060 | #endif |
1061 | 1061 | ||
1062 | GNUNET_assert (NULL != task); | 1062 | GNUNET_assert (NULL != task); |
1063 | GNUNET_assert ( (active_task != NULL) || | 1063 | GNUNET_assert ((active_task != NULL) || |
1064 | (reason == GNUNET_SCHEDULER_REASON_STARTUP) ); | 1064 | (reason == GNUNET_SCHEDULER_REASON_STARTUP)); |
1065 | t = GNUNET_malloc (sizeof (struct Task)); | 1065 | t = GNUNET_malloc (sizeof (struct Task)); |
1066 | #if EXECINFO | 1066 | #if EXECINFO |
1067 | t->num_backtrace_strings = backtrace(backtrace_array, 50); | 1067 | t->num_backtrace_strings = backtrace (backtrace_array, 50); |
1068 | t->backtrace_strings = backtrace_symbols(backtrace_array, t->num_backtrace_strings); | 1068 | t->backtrace_strings = |
1069 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1069 | #endif | 1070 | #endif |
1070 | t->read_fd = -1; | 1071 | t->read_fd = -1; |
1071 | t->write_fd = -1; | 1072 | t->write_fd = -1; |
@@ -1080,8 +1081,7 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, | |||
1080 | t->lifeness = current_lifeness; | 1081 | t->lifeness = current_lifeness; |
1081 | #if DEBUG_TASKS | 1082 | #if DEBUG_TASKS |
1082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1083 | "Adding continuation task: %llu / %p\n", | 1084 | "Adding continuation task: %llu / %p\n", t->id, t->callback_cls); |
1084 | t->id, t->callback_cls); | ||
1085 | #endif | 1085 | #endif |
1086 | queue_ready_task (t); | 1086 | queue_ready_task (t); |
1087 | } | 1087 | } |
@@ -1126,8 +1126,7 @@ GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | |||
1126 | */ | 1126 | */ |
1127 | GNUNET_SCHEDULER_TaskIdentifier | 1127 | GNUNET_SCHEDULER_TaskIdentifier |
1128 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | 1128 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, |
1129 | GNUNET_SCHEDULER_Task task, | 1129 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1130 | void *task_cls) | ||
1131 | { | 1130 | { |
1132 | return GNUNET_SCHEDULER_add_select (prio, | 1131 | return GNUNET_SCHEDULER_add_select (prio, |
1133 | GNUNET_SCHEDULER_NO_TASK, | 1132 | GNUNET_SCHEDULER_NO_TASK, |
@@ -1158,6 +1157,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1158 | struct Task *t; | 1157 | struct Task *t; |
1159 | struct Task *pos; | 1158 | struct Task *pos; |
1160 | struct Task *prev; | 1159 | struct Task *prev; |
1160 | |||
1161 | #if EXECINFO | 1161 | #if EXECINFO |
1162 | void *backtrace_array[MAX_TRACE_DEPTH]; | 1162 | void *backtrace_array[MAX_TRACE_DEPTH]; |
1163 | #endif | 1163 | #endif |
@@ -1168,8 +1168,9 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1168 | t->callback = task; | 1168 | t->callback = task; |
1169 | t->callback_cls = task_cls; | 1169 | t->callback_cls = task_cls; |
1170 | #if EXECINFO | 1170 | #if EXECINFO |
1171 | t->num_backtrace_strings = backtrace(backtrace_array, MAX_TRACE_DEPTH); | 1171 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); |
1172 | t->backtrace_strings = backtrace_symbols(backtrace_array, t->num_backtrace_strings); | 1172 | t->backtrace_strings = |
1173 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1173 | #endif | 1174 | #endif |
1174 | t->read_fd = -1; | 1175 | t->read_fd = -1; |
1175 | t->write_fd = -1; | 1176 | t->write_fd = -1; |
@@ -1181,27 +1182,27 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1181 | t->priority = current_priority; | 1182 | t->priority = current_priority; |
1182 | t->lifeness = current_lifeness; | 1183 | t->lifeness = current_lifeness; |
1183 | /* try tail first (optimization in case we are | 1184 | /* try tail first (optimization in case we are |
1184 | appending to a long list of tasks with timeouts) */ | 1185 | * appending to a long list of tasks with timeouts) */ |
1185 | prev = pending_timeout_last; | 1186 | prev = pending_timeout_last; |
1186 | if (prev != NULL) | 1187 | if (prev != NULL) |
1187 | { | 1188 | { |
1188 | if (prev->timeout.abs_value > t->timeout.abs_value) | 1189 | if (prev->timeout.abs_value > t->timeout.abs_value) |
1189 | prev = NULL; | 1190 | prev = NULL; |
1190 | else | 1191 | else |
1191 | pos = prev->next; /* heuristic success! */ | 1192 | pos = prev->next; /* heuristic success! */ |
1192 | } | 1193 | } |
1193 | if (prev == NULL) | 1194 | if (prev == NULL) |
1194 | { | 1195 | { |
1195 | /* heuristic failed, do traversal of timeout list */ | 1196 | /* heuristic failed, do traversal of timeout list */ |
1196 | pos = pending_timeout; | 1197 | pos = pending_timeout; |
1197 | } | 1198 | } |
1198 | while ( (pos != NULL) && | 1199 | while ((pos != NULL) && |
1199 | ( (pos->timeout.abs_value <= t->timeout.abs_value) || | 1200 | ((pos->timeout.abs_value <= t->timeout.abs_value) || |
1200 | (pos->reason != 0) ) ) | 1201 | (pos->reason != 0))) |
1201 | { | 1202 | { |
1202 | prev = pos; | 1203 | prev = pos; |
1203 | pos = pos->next; | 1204 | pos = pos->next; |
1204 | } | 1205 | } |
1205 | if (prev == NULL) | 1206 | if (prev == NULL) |
1206 | pending_timeout = t; | 1207 | pending_timeout = t; |
1207 | else | 1208 | else |
@@ -1217,12 +1218,9 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1217 | #if EXECINFO | 1218 | #if EXECINFO |
1218 | int i; | 1219 | int i; |
1219 | 1220 | ||
1220 | for (i=0;i<t->num_backtrace_strings;i++) | 1221 | for (i = 0; i < t->num_backtrace_strings; i++) |
1221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1222 | "Task %llu trace %d: %s\n", | 1223 | "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); |
1223 | t->id, | ||
1224 | i, | ||
1225 | t->backtrace_strings[i]); | ||
1226 | #endif | 1224 | #endif |
1227 | return t->id; | 1225 | return t->id; |
1228 | 1226 | ||
@@ -1246,12 +1244,11 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1246 | * only valid until "task" is started! | 1244 | * only valid until "task" is started! |
1247 | */ | 1245 | */ |
1248 | GNUNET_SCHEDULER_TaskIdentifier | 1246 | GNUNET_SCHEDULER_TaskIdentifier |
1249 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, | 1247 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) |
1250 | void *task_cls) | ||
1251 | { | 1248 | { |
1252 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, | 1249 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, |
1253 | GNUNET_SCHEDULER_NO_TASK, | 1250 | GNUNET_SCHEDULER_NO_TASK, |
1254 | GNUNET_TIME_UNIT_ZERO, | 1251 | GNUNET_TIME_UNIT_ZERO, |
1255 | NULL, NULL, task, task_cls); | 1252 | NULL, NULL, task, task_cls); |
1256 | } | 1253 | } |
1257 | 1254 | ||
@@ -1272,15 +1269,15 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, | |||
1272 | */ | 1269 | */ |
1273 | GNUNET_SCHEDULER_TaskIdentifier | 1270 | GNUNET_SCHEDULER_TaskIdentifier |
1274 | GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | 1271 | GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, |
1275 | GNUNET_SCHEDULER_Task task, | 1272 | GNUNET_SCHEDULER_Task task, |
1276 | void *task_cls) | 1273 | void *task_cls) |
1277 | { | 1274 | { |
1278 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1275 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1279 | 1276 | ||
1280 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, | 1277 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, |
1281 | GNUNET_SCHEDULER_NO_TASK, | 1278 | GNUNET_SCHEDULER_NO_TASK, |
1282 | GNUNET_TIME_UNIT_ZERO, | 1279 | GNUNET_TIME_UNIT_ZERO, |
1283 | NULL, NULL, task, task_cls); | 1280 | NULL, NULL, task, task_cls); |
1284 | GNUNET_assert (pending->id == ret); | 1281 | GNUNET_assert (pending->id == ret); |
1285 | pending->lifeness = lifeness; | 1282 | pending->lifeness = lifeness; |
1286 | return ret; | 1283 | return ret; |
@@ -1318,11 +1315,10 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | |||
1318 | #ifndef MINGW | 1315 | #ifndef MINGW |
1319 | GNUNET_SCHEDULER_TaskIdentifier | 1316 | GNUNET_SCHEDULER_TaskIdentifier |
1320 | add_without_sets (struct GNUNET_TIME_Relative delay, | 1317 | add_without_sets (struct GNUNET_TIME_Relative delay, |
1321 | int rfd, | 1318 | int rfd, int wfd, GNUNET_SCHEDULER_Task task, void *task_cls) |
1322 | int wfd, | ||
1323 | GNUNET_SCHEDULER_Task task, void *task_cls) | ||
1324 | { | 1319 | { |
1325 | struct Task *t; | 1320 | struct Task *t; |
1321 | |||
1326 | #if EXECINFO | 1322 | #if EXECINFO |
1327 | void *backtrace_array[MAX_TRACE_DEPTH]; | 1323 | void *backtrace_array[MAX_TRACE_DEPTH]; |
1328 | #endif | 1324 | #endif |
@@ -1333,47 +1329,50 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1333 | t->callback = task; | 1329 | t->callback = task; |
1334 | t->callback_cls = task_cls; | 1330 | t->callback_cls = task_cls; |
1335 | #if EXECINFO | 1331 | #if EXECINFO |
1336 | t->num_backtrace_strings = backtrace(backtrace_array, MAX_TRACE_DEPTH); | 1332 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); |
1337 | t->backtrace_strings = backtrace_symbols(backtrace_array, t->num_backtrace_strings); | 1333 | t->backtrace_strings = |
1334 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1338 | #endif | 1335 | #endif |
1339 | #if DEBUG_FDS | 1336 | #if DEBUG_FDS |
1340 | if (-1 != rfd) | 1337 | if (-1 != rfd) |
1338 | { | ||
1339 | int flags = fcntl (rfd, F_GETFD); | ||
1340 | |||
1341 | if (flags == -1 && errno == EBADF) | ||
1341 | { | 1342 | { |
1342 | int flags = fcntl(rfd, F_GETFD); | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", |
1343 | if (flags == -1 && errno == EBADF) | 1344 | rfd); |
1344 | { | ||
1345 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", rfd); | ||
1346 | #if EXECINFO | 1345 | #if EXECINFO |
1347 | int i; | 1346 | int i; |
1348 | 1347 | ||
1349 | for (i=0;i<t->num_backtrace_strings;i++) | 1348 | for (i = 0; i < t->num_backtrace_strings; i++) |
1350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1351 | "Trace: %s\n", | 1350 | "Trace: %s\n", t->backtrace_strings[i]); |
1352 | t->backtrace_strings[i]); | ||
1353 | #endif | 1351 | #endif |
1354 | GNUNET_assert(0); | 1352 | GNUNET_assert (0); |
1355 | } | ||
1356 | } | 1353 | } |
1354 | } | ||
1357 | if (-1 != wfd) | 1355 | if (-1 != wfd) |
1356 | { | ||
1357 | int flags = fcntl (wfd, F_GETFD); | ||
1358 | |||
1359 | if (flags == -1 && errno == EBADF) | ||
1358 | { | 1360 | { |
1359 | int flags = fcntl(wfd, F_GETFD); | 1361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", |
1360 | if (flags == -1 && errno == EBADF) | 1362 | wfd); |
1361 | { | ||
1362 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", wfd); | ||
1363 | #if EXECINFO | 1363 | #if EXECINFO |
1364 | int i; | 1364 | int i; |
1365 | 1365 | ||
1366 | for (i=0;i<t->num_backtrace_strings;i++) | 1366 | for (i = 0; i < t->num_backtrace_strings; i++) |
1367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1368 | "Trace: %s\n", | 1368 | "Trace: %s\n", t->backtrace_strings[i]); |
1369 | t->backtrace_strings[i]); | ||
1370 | #endif | 1369 | #endif |
1371 | GNUNET_assert(0); | 1370 | GNUNET_assert (0); |
1372 | } | ||
1373 | } | 1371 | } |
1372 | } | ||
1374 | #endif | 1373 | #endif |
1375 | t->read_fd = rfd; | 1374 | t->read_fd = rfd; |
1376 | GNUNET_assert(wfd >= -1); | 1375 | GNUNET_assert (wfd >= -1); |
1377 | t->write_fd = wfd; | 1376 | t->write_fd = wfd; |
1378 | t->id = ++last_id; | 1377 | t->id = ++last_id; |
1379 | #if PROFILE_DELAYS | 1378 | #if PROFILE_DELAYS |
@@ -1385,8 +1384,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1385 | t->lifeness = current_lifeness; | 1384 | t->lifeness = current_lifeness; |
1386 | t->next = pending; | 1385 | t->next = pending; |
1387 | pending = t; | 1386 | pending = t; |
1388 | max_priority_added = GNUNET_MAX (max_priority_added, | 1387 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); |
1389 | t->priority); | ||
1390 | #if DEBUG_TASKS | 1388 | #if DEBUG_TASKS |
1391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1392 | "Adding task: %llu / %p\n", t->id, t->callback_cls); | 1390 | "Adding task: %llu / %p\n", t->id, t->callback_cls); |
@@ -1394,12 +1392,9 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1394 | #if EXECINFO | 1392 | #if EXECINFO |
1395 | int i; | 1393 | int i; |
1396 | 1394 | ||
1397 | for (i=0;i<t->num_backtrace_strings;i++) | 1395 | for (i = 0; i < t->num_backtrace_strings; i++) |
1398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1399 | "Task %llu trace %d: %s\n", | 1397 | "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); |
1400 | t->id, | ||
1401 | i, | ||
1402 | t->backtrace_strings[i]); | ||
1403 | #endif | 1398 | #endif |
1404 | return t->id; | 1399 | return t->id; |
1405 | } | 1400 | } |
@@ -1425,7 +1420,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1425 | */ | 1420 | */ |
1426 | GNUNET_SCHEDULER_TaskIdentifier | 1421 | GNUNET_SCHEDULER_TaskIdentifier |
1427 | GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | 1422 | GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, |
1428 | struct GNUNET_NETWORK_Handle * rfd, | 1423 | struct GNUNET_NETWORK_Handle *rfd, |
1429 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1424 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1430 | { | 1425 | { |
1431 | #if MINGW | 1426 | #if MINGW |
@@ -1442,10 +1437,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1442 | return ret; | 1437 | return ret; |
1443 | #else | 1438 | #else |
1444 | return add_without_sets (delay, | 1439 | return add_without_sets (delay, |
1445 | GNUNET_NETWORK_get_fd (rfd), | 1440 | GNUNET_NETWORK_get_fd (rfd), -1, task, task_cls); |
1446 | -1, | ||
1447 | task, | ||
1448 | task_cls); | ||
1449 | #endif | 1441 | #endif |
1450 | } | 1442 | } |
1451 | 1443 | ||
@@ -1468,7 +1460,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1468 | */ | 1460 | */ |
1469 | GNUNET_SCHEDULER_TaskIdentifier | 1461 | GNUNET_SCHEDULER_TaskIdentifier |
1470 | GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | 1462 | GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, |
1471 | struct GNUNET_NETWORK_Handle * wfd, | 1463 | struct GNUNET_NETWORK_Handle *wfd, |
1472 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1464 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1473 | { | 1465 | { |
1474 | #if MINGW | 1466 | #if MINGW |
@@ -1484,12 +1476,9 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1484 | GNUNET_NETWORK_fdset_destroy (ws); | 1476 | GNUNET_NETWORK_fdset_destroy (ws); |
1485 | return ret; | 1477 | return ret; |
1486 | #else | 1478 | #else |
1487 | GNUNET_assert(GNUNET_NETWORK_get_fd(wfd) >= 0); | 1479 | GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); |
1488 | return add_without_sets (delay, | 1480 | return add_without_sets (delay, |
1489 | -1, | 1481 | -1, GNUNET_NETWORK_get_fd (wfd), task, task_cls); |
1490 | GNUNET_NETWORK_get_fd (wfd), | ||
1491 | task, | ||
1492 | task_cls); | ||
1493 | #endif | 1482 | #endif |
1494 | } | 1483 | } |
1495 | 1484 | ||
@@ -1512,7 +1501,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1512 | */ | 1501 | */ |
1513 | GNUNET_SCHEDULER_TaskIdentifier | 1502 | GNUNET_SCHEDULER_TaskIdentifier |
1514 | GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | 1503 | GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, |
1515 | const struct GNUNET_DISK_FileHandle * rfd, | 1504 | const struct GNUNET_DISK_FileHandle *rfd, |
1516 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1505 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1517 | { | 1506 | { |
1518 | #if MINGW | 1507 | #if MINGW |
@@ -1531,11 +1520,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1531 | int fd; | 1520 | int fd; |
1532 | 1521 | ||
1533 | GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int)); | 1522 | GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int)); |
1534 | return add_without_sets (delay, | 1523 | return add_without_sets (delay, fd, -1, task, task_cls); |
1535 | fd, | ||
1536 | -1, | ||
1537 | task, | ||
1538 | task_cls); | ||
1539 | 1524 | ||
1540 | #endif | 1525 | #endif |
1541 | } | 1526 | } |
@@ -1559,7 +1544,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1559 | */ | 1544 | */ |
1560 | GNUNET_SCHEDULER_TaskIdentifier | 1545 | GNUNET_SCHEDULER_TaskIdentifier |
1561 | GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | 1546 | GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, |
1562 | const struct GNUNET_DISK_FileHandle * wfd, | 1547 | const struct GNUNET_DISK_FileHandle *wfd, |
1563 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1548 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1564 | { | 1549 | { |
1565 | #if MINGW | 1550 | #if MINGW |
@@ -1578,12 +1563,8 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1578 | int fd; | 1563 | int fd; |
1579 | 1564 | ||
1580 | GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int)); | 1565 | GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int)); |
1581 | GNUNET_assert(fd >= 0); | 1566 | GNUNET_assert (fd >= 0); |
1582 | return add_without_sets (delay, | 1567 | return add_without_sets (delay, -1, fd, task, task_cls); |
1583 | -1, | ||
1584 | fd, | ||
1585 | task, | ||
1586 | task_cls); | ||
1587 | 1568 | ||
1588 | #endif | 1569 | #endif |
1589 | } | 1570 | } |
@@ -1627,11 +1608,12 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1627 | GNUNET_SCHEDULER_TaskIdentifier | 1608 | GNUNET_SCHEDULER_TaskIdentifier |
1628 | prerequisite_task, | 1609 | prerequisite_task, |
1629 | struct GNUNET_TIME_Relative delay, | 1610 | struct GNUNET_TIME_Relative delay, |
1630 | const struct GNUNET_NETWORK_FDSet * rs, | 1611 | const struct GNUNET_NETWORK_FDSet *rs, |
1631 | const struct GNUNET_NETWORK_FDSet * ws, | 1612 | const struct GNUNET_NETWORK_FDSet *ws, |
1632 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1613 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1633 | { | 1614 | { |
1634 | struct Task *t; | 1615 | struct Task *t; |
1616 | |||
1635 | #if EXECINFO | 1617 | #if EXECINFO |
1636 | void *backtrace_array[MAX_TRACE_DEPTH]; | 1618 | void *backtrace_array[MAX_TRACE_DEPTH]; |
1637 | #endif | 1619 | #endif |
@@ -1642,21 +1624,22 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1642 | t->callback = task; | 1624 | t->callback = task; |
1643 | t->callback_cls = task_cls; | 1625 | t->callback_cls = task_cls; |
1644 | #if EXECINFO | 1626 | #if EXECINFO |
1645 | t->num_backtrace_strings = backtrace(backtrace_array, MAX_TRACE_DEPTH); | 1627 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); |
1646 | t->backtrace_strings = backtrace_symbols(backtrace_array, t->num_backtrace_strings); | 1628 | t->backtrace_strings = |
1629 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1647 | #endif | 1630 | #endif |
1648 | t->read_fd = -1; | 1631 | t->read_fd = -1; |
1649 | t->write_fd = -1; | 1632 | t->write_fd = -1; |
1650 | if (rs != NULL) | 1633 | if (rs != NULL) |
1651 | { | 1634 | { |
1652 | t->read_set = GNUNET_NETWORK_fdset_create (); | 1635 | t->read_set = GNUNET_NETWORK_fdset_create (); |
1653 | GNUNET_NETWORK_fdset_copy (t->read_set, rs); | 1636 | GNUNET_NETWORK_fdset_copy (t->read_set, rs); |
1654 | } | 1637 | } |
1655 | if (ws != NULL) | 1638 | if (ws != NULL) |
1656 | { | 1639 | { |
1657 | t->write_set = GNUNET_NETWORK_fdset_create (); | 1640 | t->write_set = GNUNET_NETWORK_fdset_create (); |
1658 | GNUNET_NETWORK_fdset_copy (t->write_set, ws); | 1641 | GNUNET_NETWORK_fdset_copy (t->write_set, ws); |
1659 | } | 1642 | } |
1660 | t->id = ++last_id; | 1643 | t->id = ++last_id; |
1661 | #if PROFILE_DELAYS | 1644 | #if PROFILE_DELAYS |
1662 | t->start_time = GNUNET_TIME_absolute_get (); | 1645 | t->start_time = GNUNET_TIME_absolute_get (); |
@@ -1664,14 +1647,13 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1664 | t->prereq_id = prerequisite_task; | 1647 | t->prereq_id = prerequisite_task; |
1665 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); | 1648 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); |
1666 | t->priority = | 1649 | t->priority = |
1667 | check_priority ((prio == | 1650 | check_priority ((prio == |
1668 | GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority | 1651 | GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority |
1669 | : prio); | 1652 | : prio); |
1670 | t->lifeness = current_lifeness; | 1653 | t->lifeness = current_lifeness; |
1671 | t->next = pending; | 1654 | t->next = pending; |
1672 | pending = t; | 1655 | pending = t; |
1673 | max_priority_added = GNUNET_MAX (max_priority_added, | 1656 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); |
1674 | t->priority); | ||
1675 | #if DEBUG_TASKS | 1657 | #if DEBUG_TASKS |
1676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1677 | "Adding task: %llu / %p\n", t->id, t->callback_cls); | 1659 | "Adding task: %llu / %p\n", t->id, t->callback_cls); |
@@ -1679,12 +1661,9 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1679 | #if EXECINFO | 1661 | #if EXECINFO |
1680 | int i; | 1662 | int i; |
1681 | 1663 | ||
1682 | for (i=0;i<t->num_backtrace_strings;i++) | 1664 | for (i = 0; i < t->num_backtrace_strings; i++) |
1683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1665 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1684 | "Task %llu trace %d: %s\n", | 1666 | "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]); |
1685 | t->id, | ||
1686 | i, | ||
1687 | t->backtrace_strings[i]); | ||
1688 | #endif | 1667 | #endif |
1689 | return t->id; | 1668 | return t->id; |
1690 | } | 1669 | } |
diff --git a/src/util/server.c b/src/util/server.c index 6e2dc32cf..935cf04f8 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -242,7 +242,7 @@ struct GNUNET_SERVER_Client | |||
242 | * be used in special cases! | 242 | * be used in special cases! |
243 | */ | 243 | */ |
244 | int persist; | 244 | int persist; |
245 | 245 | ||
246 | /** | 246 | /** |
247 | * Type of last message processed (for warn_no_receive_done). | 247 | * Type of last message processed (for warn_no_receive_done). |
248 | */ | 248 | */ |
@@ -258,8 +258,7 @@ struct GNUNET_SERVER_Client | |||
258 | * @param tc reason why we are running right now | 258 | * @param tc reason why we are running right now |
259 | */ | 259 | */ |
260 | static void | 260 | static void |
261 | process_listen_socket (void *cls, | 261 | process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
262 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
263 | { | 262 | { |
264 | struct GNUNET_SERVER_Handle *server = cls; | 263 | struct GNUNET_SERVER_Handle *server = cls; |
265 | struct GNUNET_CONNECTION_Handle *sock; | 264 | struct GNUNET_CONNECTION_Handle *sock; |
@@ -273,49 +272,46 @@ process_listen_socket (void *cls, | |||
273 | while (NULL != server->listen_sockets[i]) | 272 | while (NULL != server->listen_sockets[i]) |
274 | GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); | 273 | GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); |
275 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 274 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
276 | { | 275 | { |
277 | /* ignore shutdown, someone else will take care of it! */ | 276 | /* ignore shutdown, someone else will take care of it! */ |
278 | server->listen_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 277 | server->listen_task = |
279 | GNUNET_SCHEDULER_NO_TASK, | 278 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
280 | GNUNET_TIME_UNIT_FOREVER_REL, | 279 | GNUNET_SCHEDULER_NO_TASK, |
281 | r, NULL, | 280 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
282 | &process_listen_socket, | 281 | &process_listen_socket, server); |
283 | server); | 282 | GNUNET_NETWORK_fdset_destroy (r); |
284 | GNUNET_NETWORK_fdset_destroy (r); | 283 | return; |
285 | return; | 284 | } |
286 | } | ||
287 | i = 0; | 285 | i = 0; |
288 | while (NULL != server->listen_sockets[i]) | 286 | while (NULL != server->listen_sockets[i]) |
287 | { | ||
288 | if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i])) | ||
289 | { | 289 | { |
290 | if (GNUNET_NETWORK_fdset_isset | 290 | sock = |
291 | (tc->read_ready, server->listen_sockets[i])) | 291 | GNUNET_CONNECTION_create_from_accept (server->access, |
292 | { | 292 | server->access_cls, |
293 | sock = | 293 | server->listen_sockets[i]); |
294 | GNUNET_CONNECTION_create_from_accept (server->access, | 294 | if (sock != NULL) |
295 | server->access_cls, | 295 | { |
296 | server->listen_sockets[i]); | ||
297 | if (sock != NULL) | ||
298 | { | ||
299 | #if DEBUG_SERVER | 296 | #if DEBUG_SERVER |
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
301 | "Server accepted incoming connection.\n"); | 298 | "Server accepted incoming connection.\n"); |
302 | #endif | 299 | #endif |
303 | client = GNUNET_SERVER_connect_socket (server, sock); | 300 | client = GNUNET_SERVER_connect_socket (server, sock); |
304 | GNUNET_CONNECTION_ignore_shutdown (sock, | 301 | GNUNET_CONNECTION_ignore_shutdown (sock, |
305 | server->clients_ignore_shutdown); | 302 | server->clients_ignore_shutdown); |
306 | /* decrement reference count, we don't keep "client" alive */ | 303 | /* decrement reference count, we don't keep "client" alive */ |
307 | GNUNET_SERVER_client_drop (client); | 304 | GNUNET_SERVER_client_drop (client); |
308 | } | 305 | } |
309 | } | ||
310 | i++; | ||
311 | } | 306 | } |
307 | i++; | ||
308 | } | ||
312 | /* listen for more! */ | 309 | /* listen for more! */ |
313 | server->listen_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 310 | server->listen_task = |
314 | GNUNET_SCHEDULER_NO_TASK, | 311 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
315 | GNUNET_TIME_UNIT_FOREVER_REL, | 312 | GNUNET_SCHEDULER_NO_TASK, |
316 | r, NULL, | 313 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
317 | &process_listen_socket, | 314 | &process_listen_socket, server); |
318 | server); | ||
319 | GNUNET_NETWORK_fdset_destroy (r); | 315 | GNUNET_NETWORK_fdset_destroy (r); |
320 | } | 316 | } |
321 | 317 | ||
@@ -336,88 +332,88 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
336 | int eno; | 332 | int eno; |
337 | 333 | ||
338 | switch (serverAddr->sa_family) | 334 | switch (serverAddr->sa_family) |
339 | { | 335 | { |
340 | case AF_INET: | 336 | case AF_INET: |
341 | port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port); | 337 | port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port); |
342 | break; | 338 | break; |
343 | case AF_INET6: | 339 | case AF_INET6: |
344 | port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port); | 340 | port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port); |
345 | break; | 341 | break; |
346 | case AF_UNIX: | 342 | case AF_UNIX: |
347 | port = 0; | 343 | port = 0; |
348 | break; | 344 | break; |
349 | default: | 345 | default: |
350 | GNUNET_break (0); | 346 | GNUNET_break (0); |
351 | port = 0; | 347 | port = 0; |
352 | break; | 348 | break; |
353 | } | 349 | } |
354 | sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0); | 350 | sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0); |
355 | if (NULL == sock) | 351 | if (NULL == sock) |
356 | { | 352 | { |
357 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 353 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
358 | errno = 0; | 354 | errno = 0; |
359 | return NULL; | 355 | return NULL; |
360 | } | 356 | } |
361 | if (port != 0) | 357 | if (port != 0) |
362 | { | 358 | { |
363 | if (GNUNET_NETWORK_socket_setsockopt | 359 | if (GNUNET_NETWORK_socket_setsockopt |
364 | (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 360 | (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
365 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 361 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
366 | "setsockopt"); | 362 | "setsockopt"); |
367 | #ifdef IPV6_V6ONLY | 363 | #ifdef IPV6_V6ONLY |
368 | if ( (serverAddr->sa_family == AF_INET6) && | 364 | if ((serverAddr->sa_family == AF_INET6) && |
369 | (GNUNET_NETWORK_socket_setsockopt | 365 | (GNUNET_NETWORK_socket_setsockopt |
370 | (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK) ) | 366 | (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK)) |
371 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 367 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
372 | "setsockopt"); | 368 | "setsockopt"); |
373 | #endif | 369 | #endif |
374 | } | 370 | } |
375 | /* bind the socket */ | 371 | /* bind the socket */ |
376 | if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) | 372 | if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) |
373 | { | ||
374 | eno = errno; | ||
375 | if (errno != EADDRINUSE) | ||
377 | { | 376 | { |
378 | eno = errno; | 377 | /* we don't log 'EADDRINUSE' here since an IPv4 bind may |
379 | if (errno != EADDRINUSE) | 378 | * fail if we already took the port on IPv6; if both IPv4 and |
380 | { | 379 | * IPv6 binds fail, then our caller will log using the |
381 | /* we don't log 'EADDRINUSE' here since an IPv4 bind may | 380 | * errno preserved in 'eno' */ |
382 | fail if we already took the port on IPv6; if both IPv4 and | 381 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
383 | IPv6 binds fail, then our caller will log using the | 382 | if (port != 0) |
384 | errno preserved in 'eno' */ | 383 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
385 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 384 | _ |
386 | if (port != 0) | 385 | ("`%s' failed for port %d (%s).\n"), |
387 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 386 | "bind", port, |
388 | _ | 387 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); |
389 | ("`%s' failed for port %d (%s).\n"), | 388 | eno = 0; |
390 | "bind", port, | ||
391 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); | ||
392 | eno = 0; | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | if (port != 0) | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
398 | _ | ||
399 | ("`%s' failed for port %d (%s): address already in use\n"), | ||
400 | "bind", port, | ||
401 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); | ||
402 | else if (serverAddr->sa_family == AF_UNIX) | ||
403 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
404 | _ | ||
405 | ("`%s' failed for `%s': address already in use\n"), | ||
406 | "bind", | ||
407 | ((const struct sockaddr_un*) serverAddr)->sun_path); | ||
408 | |||
409 | } | ||
410 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | ||
411 | errno = eno; | ||
412 | return NULL; | ||
413 | } | 389 | } |
414 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) | 390 | else |
415 | { | 391 | { |
416 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); | 392 | if (port != 0) |
417 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 393 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
418 | errno = 0; | 394 | _ |
419 | return NULL; | 395 | ("`%s' failed for port %d (%s): address already in use\n"), |
396 | "bind", port, | ||
397 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); | ||
398 | else if (serverAddr->sa_family == AF_UNIX) | ||
399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
400 | _ | ||
401 | ("`%s' failed for `%s': address already in use\n"), | ||
402 | "bind", | ||
403 | ((const struct sockaddr_un *) serverAddr)->sun_path); | ||
404 | |||
420 | } | 405 | } |
406 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | ||
407 | errno = eno; | ||
408 | return NULL; | ||
409 | } | ||
410 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) | ||
411 | { | ||
412 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); | ||
413 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | ||
414 | errno = 0; | ||
415 | return NULL; | ||
416 | } | ||
421 | #if DEBUG_SERVER | 417 | #if DEBUG_SERVER |
422 | if (port != 0) | 418 | if (port != 0) |
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -440,11 +436,11 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
440 | * (typically, "port" already in use) | 436 | * (typically, "port" already in use) |
441 | */ | 437 | */ |
442 | struct GNUNET_SERVER_Handle * | 438 | struct GNUNET_SERVER_Handle * |
443 | GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, void *access_cls, | 439 | GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, |
444 | struct GNUNET_NETWORK_Handle **lsocks, | 440 | void *access_cls, |
445 | struct GNUNET_TIME_Relative | 441 | struct GNUNET_NETWORK_Handle **lsocks, |
446 | idle_timeout, | 442 | struct GNUNET_TIME_Relative idle_timeout, |
447 | int require_found) | 443 | int require_found) |
448 | { | 444 | { |
449 | struct GNUNET_SERVER_Handle *ret; | 445 | struct GNUNET_SERVER_Handle *ret; |
450 | struct GNUNET_NETWORK_FDSet *r; | 446 | struct GNUNET_NETWORK_FDSet *r; |
@@ -457,19 +453,18 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, void *a | |||
457 | ret->access_cls = access_cls; | 453 | ret->access_cls = access_cls; |
458 | ret->require_found = require_found; | 454 | ret->require_found = require_found; |
459 | if (lsocks != NULL) | 455 | if (lsocks != NULL) |
460 | { | 456 | { |
461 | r = GNUNET_NETWORK_fdset_create (); | 457 | r = GNUNET_NETWORK_fdset_create (); |
462 | i = 0; | 458 | i = 0; |
463 | while (NULL != ret->listen_sockets[i]) | 459 | while (NULL != ret->listen_sockets[i]) |
464 | GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); | 460 | GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); |
465 | ret->listen_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 461 | ret->listen_task = |
466 | GNUNET_SCHEDULER_NO_TASK, | 462 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
467 | GNUNET_TIME_UNIT_FOREVER_REL, | 463 | GNUNET_SCHEDULER_NO_TASK, |
468 | r, NULL, | 464 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
469 | &process_listen_socket, | 465 | &process_listen_socket, ret); |
470 | ret); | 466 | GNUNET_NETWORK_fdset_destroy (r); |
471 | GNUNET_NETWORK_fdset_destroy (r); | 467 | } |
472 | } | ||
473 | return ret; | 468 | return ret; |
474 | } | 469 | } |
475 | 470 | ||
@@ -503,34 +498,32 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, | |||
503 | while (serverAddr[i] != NULL) | 498 | while (serverAddr[i] != NULL) |
504 | i++; | 499 | i++; |
505 | if (i > 0) | 500 | if (i > 0) |
501 | { | ||
502 | lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1)); | ||
503 | i = 0; | ||
504 | j = 0; | ||
505 | while (serverAddr[i] != NULL) | ||
506 | { | 506 | { |
507 | lsocks = | 507 | lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]); |
508 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1)); | 508 | if (lsocks[j] != NULL) |
509 | i = 0; | 509 | j++; |
510 | j = 0; | 510 | i++; |
511 | while (serverAddr[i] != NULL) | ||
512 | { | ||
513 | lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]); | ||
514 | if (lsocks[j] != NULL) | ||
515 | j++; | ||
516 | i++; | ||
517 | } | ||
518 | if (j == 0) | ||
519 | { | ||
520 | if (errno != 0) | ||
521 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | ||
522 | GNUNET_free (lsocks); | ||
523 | lsocks = NULL; | ||
524 | } | ||
525 | } | 511 | } |
526 | else | 512 | if (j == 0) |
527 | { | 513 | { |
514 | if (errno != 0) | ||
515 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | ||
516 | GNUNET_free (lsocks); | ||
528 | lsocks = NULL; | 517 | lsocks = NULL; |
529 | } | 518 | } |
519 | } | ||
520 | else | ||
521 | { | ||
522 | lsocks = NULL; | ||
523 | } | ||
530 | return GNUNET_SERVER_create_with_sockets (access, access_cls, | 524 | return GNUNET_SERVER_create_with_sockets (access, access_cls, |
531 | lsocks, | 525 | lsocks, |
532 | idle_timeout, | 526 | idle_timeout, require_found); |
533 | require_found); | ||
534 | } | 527 | } |
535 | 528 | ||
536 | 529 | ||
@@ -550,32 +543,32 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) | |||
550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); | 543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); |
551 | #endif | 544 | #endif |
552 | if (GNUNET_SCHEDULER_NO_TASK != s->listen_task) | 545 | if (GNUNET_SCHEDULER_NO_TASK != s->listen_task) |
553 | { | 546 | { |
554 | GNUNET_SCHEDULER_cancel (s->listen_task); | 547 | GNUNET_SCHEDULER_cancel (s->listen_task); |
555 | s->listen_task = GNUNET_SCHEDULER_NO_TASK; | 548 | s->listen_task = GNUNET_SCHEDULER_NO_TASK; |
556 | } | 549 | } |
557 | if (s->listen_sockets != NULL) | 550 | if (s->listen_sockets != NULL) |
558 | { | 551 | { |
559 | i = 0; | 552 | i = 0; |
560 | while (s->listen_sockets[i] != NULL) | 553 | while (s->listen_sockets[i] != NULL) |
561 | GNUNET_break (GNUNET_OK == | 554 | GNUNET_break (GNUNET_OK == |
562 | GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); | 555 | GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); |
563 | GNUNET_free (s->listen_sockets); | 556 | GNUNET_free (s->listen_sockets); |
564 | s->listen_sockets = NULL; | 557 | s->listen_sockets = NULL; |
565 | } | 558 | } |
566 | while (s->clients != NULL) | 559 | while (s->clients != NULL) |
567 | GNUNET_SERVER_client_disconnect (s->clients); | 560 | GNUNET_SERVER_client_disconnect (s->clients); |
568 | while (NULL != (hpos = s->handlers)) | 561 | while (NULL != (hpos = s->handlers)) |
569 | { | 562 | { |
570 | s->handlers = hpos->next; | 563 | s->handlers = hpos->next; |
571 | GNUNET_free (hpos); | 564 | GNUNET_free (hpos); |
572 | } | 565 | } |
573 | while (NULL != (npos = s->disconnect_notify_list)) | 566 | while (NULL != (npos = s->disconnect_notify_list)) |
574 | { | 567 | { |
575 | npos->callback (npos->callback_cls, NULL); | 568 | npos->callback (npos->callback_cls, NULL); |
576 | s->disconnect_notify_list = npos->next; | 569 | s->disconnect_notify_list = npos->next; |
577 | GNUNET_free (npos); | 570 | GNUNET_free (npos); |
578 | } | 571 | } |
579 | GNUNET_free (s); | 572 | GNUNET_free (s); |
580 | } | 573 | } |
581 | 574 | ||
@@ -595,8 +588,7 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) | |||
595 | */ | 588 | */ |
596 | void | 589 | void |
597 | GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, | 590 | GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, |
598 | const struct GNUNET_SERVER_MessageHandler | 591 | const struct GNUNET_SERVER_MessageHandler *handlers) |
599 | *handlers) | ||
600 | { | 592 | { |
601 | struct HandlerList *p; | 593 | struct HandlerList *p; |
602 | 594 | ||
@@ -614,19 +606,21 @@ GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, | |||
614 | * @param tc scheduler context (unused) | 606 | * @param tc scheduler context (unused) |
615 | */ | 607 | */ |
616 | static void | 608 | static void |
617 | warn_no_receive_done (void *cls, | 609 | warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
618 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
619 | { | 610 | { |
620 | struct GNUNET_SERVER_Client *client = cls; | 611 | struct GNUNET_SERVER_Client *client = cls; |
621 | 612 | ||
622 | client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 613 | client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
623 | &warn_no_receive_done, | 614 | &warn_no_receive_done, |
624 | client); | 615 | client); |
625 | if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 616 | if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
626 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
627 | _("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), | 618 | _ |
628 | (unsigned int) client->warn_type, | 619 | ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), |
629 | (unsigned long long) GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value); | 620 | (unsigned int) client->warn_type, |
621 | (unsigned long long) | ||
622 | GNUNET_TIME_absolute_get_duration | ||
623 | (client->warn_start).rel_value); | ||
630 | } | 624 | } |
631 | 625 | ||
632 | 626 | ||
@@ -641,10 +635,10 @@ void | |||
641 | GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) | 635 | GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) |
642 | { | 636 | { |
643 | if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) | 637 | if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) |
644 | { | 638 | { |
645 | GNUNET_SCHEDULER_cancel (client->warn_task); | 639 | GNUNET_SCHEDULER_cancel (client->warn_task); |
646 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; | 640 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; |
647 | } | 641 | } |
648 | } | 642 | } |
649 | 643 | ||
650 | 644 | ||
@@ -686,53 +680,49 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, | |||
686 | pos = server->handlers; | 680 | pos = server->handlers; |
687 | found = GNUNET_NO; | 681 | found = GNUNET_NO; |
688 | while (pos != NULL) | 682 | while (pos != NULL) |
683 | { | ||
684 | i = 0; | ||
685 | while (pos->handlers[i].callback != NULL) | ||
689 | { | 686 | { |
690 | i = 0; | 687 | mh = &pos->handlers[i]; |
691 | while (pos->handlers[i].callback != NULL) | 688 | if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) |
689 | { | ||
690 | if ((mh->expected_size != 0) && (mh->expected_size != size)) | ||
692 | { | 691 | { |
693 | mh = &pos->handlers[i]; | ||
694 | if ( (mh->type == type) || | ||
695 | (mh->type == GNUNET_MESSAGE_TYPE_ALL) ) | ||
696 | { | ||
697 | if ((mh->expected_size != 0) && (mh->expected_size != size)) | ||
698 | { | ||
699 | #if GNUNET8_NETWORK_IS_DEAD | 692 | #if GNUNET8_NETWORK_IS_DEAD |
700 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 693 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
701 | "Expected %u bytes for message of type %u, got %u\n", | 694 | "Expected %u bytes for message of type %u, got %u\n", |
702 | mh->expected_size, | 695 | mh->expected_size, mh->type, size); |
703 | mh->type, | 696 | GNUNET_break_op (0); |
704 | size); | ||
705 | GNUNET_break_op (0); | ||
706 | #endif | 697 | #endif |
707 | return GNUNET_SYSERR; | 698 | return GNUNET_SYSERR; |
708 | } | ||
709 | if (sender != NULL) | ||
710 | { | ||
711 | if (0 == sender->suspended) | ||
712 | { | ||
713 | sender->warn_start = GNUNET_TIME_absolute_get (); | ||
714 | sender->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
715 | &warn_no_receive_done, | ||
716 | sender); | ||
717 | sender->warn_type = type; | ||
718 | } | ||
719 | sender->suspended++; | ||
720 | } | ||
721 | mh->callback (mh->callback_cls, sender, message); | ||
722 | found = GNUNET_YES; | ||
723 | } | ||
724 | i++; | ||
725 | } | 699 | } |
726 | pos = pos->next; | 700 | if (sender != NULL) |
701 | { | ||
702 | if (0 == sender->suspended) | ||
703 | { | ||
704 | sender->warn_start = GNUNET_TIME_absolute_get (); | ||
705 | sender->warn_task = | ||
706 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
707 | &warn_no_receive_done, sender); | ||
708 | sender->warn_type = type; | ||
709 | } | ||
710 | sender->suspended++; | ||
711 | } | ||
712 | mh->callback (mh->callback_cls, sender, message); | ||
713 | found = GNUNET_YES; | ||
714 | } | ||
715 | i++; | ||
727 | } | 716 | } |
717 | pos = pos->next; | ||
718 | } | ||
728 | if (found == GNUNET_NO) | 719 | if (found == GNUNET_NO) |
729 | { | 720 | { |
730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
731 | "Received message of unknown type %d\n", | 722 | "Received message of unknown type %d\n", type); |
732 | type); | 723 | if (server->require_found == GNUNET_YES) |
733 | if (server->require_found == GNUNET_YES) | 724 | return GNUNET_SYSERR; |
734 | return GNUNET_SYSERR; | 725 | } |
735 | } | ||
736 | return GNUNET_OK; | 726 | return GNUNET_OK; |
737 | } | 727 | } |
738 | 728 | ||
@@ -751,8 +741,7 @@ static void | |||
751 | process_incoming (void *cls, | 741 | process_incoming (void *cls, |
752 | const void *buf, | 742 | const void *buf, |
753 | size_t available, | 743 | size_t available, |
754 | const struct sockaddr *addr, | 744 | const struct sockaddr *addr, socklen_t addrlen, int errCode); |
755 | socklen_t addrlen, int errCode); | ||
756 | 745 | ||
757 | 746 | ||
758 | /** | 747 | /** |
@@ -769,51 +758,49 @@ process_incoming (void *cls, | |||
769 | * GNUNET_SYSERR if we should instantly abort due to error in a previous step | 758 | * GNUNET_SYSERR if we should instantly abort due to error in a previous step |
770 | */ | 759 | */ |
771 | static void | 760 | static void |
772 | process_mst (struct GNUNET_SERVER_Client *client, | 761 | process_mst (struct GNUNET_SERVER_Client *client, int ret) |
773 | int ret) | ||
774 | { | 762 | { |
775 | while ( (ret != GNUNET_SYSERR) && | 763 | while ((ret != GNUNET_SYSERR) && |
776 | (client->server != NULL) && | 764 | (client->server != NULL) && |
777 | (GNUNET_YES != client->shutdown_now) && | 765 | (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) |
778 | (0 == client->suspended) ) | 766 | { |
767 | if (ret == GNUNET_OK) | ||
779 | { | 768 | { |
780 | if (ret == GNUNET_OK) | 769 | client->receive_pending = GNUNET_YES; |
781 | { | ||
782 | client->receive_pending = GNUNET_YES; | ||
783 | #if DEBUG_SERVER | 770 | #if DEBUG_SERVER |
784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
785 | "Server re-enters receive loop, timeout: %llu.\n", client->idle_timeout.rel_value); | 772 | "Server re-enters receive loop, timeout: %llu.\n", |
773 | client->idle_timeout.rel_value); | ||
786 | #endif | 774 | #endif |
787 | GNUNET_CONNECTION_receive (client->connection, | 775 | GNUNET_CONNECTION_receive (client->connection, |
788 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 776 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
789 | client->idle_timeout, | 777 | client->idle_timeout, |
790 | &process_incoming, client); | 778 | &process_incoming, client); |
791 | break; | 779 | break; |
792 | } | 780 | } |
793 | #if DEBUG_SERVER | 781 | #if DEBUG_SERVER |
794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server processes additional messages instantly.\n"); | 782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
783 | "Server processes additional messages instantly.\n"); | ||
795 | #endif | 784 | #endif |
796 | ret = GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, GNUNET_YES); | 785 | ret = |
797 | } | 786 | GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO, |
787 | GNUNET_YES); | ||
788 | } | ||
798 | #if DEBUG_SERVER | 789 | #if DEBUG_SERVER |
799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
800 | "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", | 791 | "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", |
801 | ret, | 792 | ret, client->server, client->shutdown_now, client->suspended); |
802 | client->server, | ||
803 | client->shutdown_now, | ||
804 | client->suspended); | ||
805 | #endif | 793 | #endif |
806 | 794 | ||
807 | if (ret == GNUNET_NO) | 795 | if (ret == GNUNET_NO) |
808 | { | 796 | { |
809 | #if DEBUG_SERVER | 797 | #if DEBUG_SERVER |
810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
811 | "Server has more data pending but is suspended.\n"); | 799 | "Server has more data pending but is suspended.\n"); |
812 | #endif | 800 | #endif |
813 | client->receive_pending = GNUNET_SYSERR; /* data pending */ | 801 | client->receive_pending = GNUNET_SYSERR; /* data pending */ |
814 | } | 802 | } |
815 | if ( (ret == GNUNET_SYSERR) || | 803 | if ((ret == GNUNET_SYSERR) || (GNUNET_YES == client->shutdown_now)) |
816 | (GNUNET_YES == client->shutdown_now) ) | ||
817 | GNUNET_SERVER_client_disconnect (client); | 804 | GNUNET_SERVER_client_disconnect (client); |
818 | GNUNET_SERVER_client_drop (client); | 805 | GNUNET_SERVER_client_drop (client); |
819 | } | 806 | } |
@@ -833,8 +820,7 @@ static void | |||
833 | process_incoming (void *cls, | 820 | process_incoming (void *cls, |
834 | const void *buf, | 821 | const void *buf, |
835 | size_t available, | 822 | size_t available, |
836 | const struct sockaddr *addr, | 823 | const struct sockaddr *addr, socklen_t addrlen, int errCode) |
837 | socklen_t addrlen, int errCode) | ||
838 | { | 824 | { |
839 | struct GNUNET_SERVER_Client *client = cls; | 825 | struct GNUNET_SERVER_Client *client = cls; |
840 | struct GNUNET_SERVER_Handle *server = client->server; | 826 | struct GNUNET_SERVER_Handle *server = client->server; |
@@ -845,48 +831,48 @@ process_incoming (void *cls, | |||
845 | GNUNET_assert (client->receive_pending == GNUNET_YES); | 831 | GNUNET_assert (client->receive_pending == GNUNET_YES); |
846 | client->receive_pending = GNUNET_NO; | 832 | client->receive_pending = GNUNET_NO; |
847 | now = GNUNET_TIME_absolute_get (); | 833 | now = GNUNET_TIME_absolute_get (); |
848 | end = GNUNET_TIME_absolute_add (client->last_activity, | 834 | end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); |
849 | client->idle_timeout); | 835 | |
850 | 836 | if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && | |
851 | if ( (buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && | 837 | (client->shutdown_now != GNUNET_YES) && |
852 | (client->shutdown_now != GNUNET_YES) && | 838 | (server != NULL) && |
853 | (server != NULL) && | 839 | (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && |
854 | (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && | 840 | (end.abs_value > now.abs_value)) |
855 | (end.abs_value > now.abs_value) ) | 841 | { |
856 | { | 842 | /* wait longer, timeout changed (i.e. due to us sending) */ |
857 | /* wait longer, timeout changed (i.e. due to us sending) */ | ||
858 | #if DEBUG_SERVER | 843 | #if DEBUG_SERVER |
859 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
860 | "Receive time out, but no disconnect due to sending (%p)\n", | 845 | "Receive time out, but no disconnect due to sending (%p)\n", |
861 | GNUNET_a2s (addr, addrlen)); | 846 | GNUNET_a2s (addr, addrlen)); |
862 | #endif | 847 | #endif |
863 | client->receive_pending = GNUNET_YES; | 848 | client->receive_pending = GNUNET_YES; |
864 | GNUNET_CONNECTION_receive (client->connection, | 849 | GNUNET_CONNECTION_receive (client->connection, |
865 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 850 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
866 | GNUNET_TIME_absolute_get_remaining (end), | 851 | GNUNET_TIME_absolute_get_remaining (end), |
867 | &process_incoming, client); | 852 | &process_incoming, client); |
868 | return; | 853 | return; |
869 | } | 854 | } |
870 | if ((buf == NULL) || | 855 | if ((buf == NULL) || |
871 | (available == 0) || | 856 | (available == 0) || |
872 | (errCode != 0) || | 857 | (errCode != 0) || |
873 | (server == NULL) || | 858 | (server == NULL) || |
874 | (client->shutdown_now == GNUNET_YES) || | 859 | (client->shutdown_now == GNUNET_YES) || |
875 | (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) | 860 | (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) |
876 | { | 861 | { |
877 | /* other side closed connection, error connecting, etc. */ | 862 | /* other side closed connection, error connecting, etc. */ |
878 | GNUNET_SERVER_client_disconnect (client); | 863 | GNUNET_SERVER_client_disconnect (client); |
879 | return; | 864 | return; |
880 | } | 865 | } |
881 | #if DEBUG_SERVER | 866 | #if DEBUG_SERVER |
882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
883 | "Server receives %u bytes from `%s'.\n", | 868 | "Server receives %u bytes from `%s'.\n", |
884 | (unsigned int) available, | 869 | (unsigned int) available, GNUNET_a2s (addr, addrlen)); |
885 | GNUNET_a2s (addr, addrlen)); | ||
886 | #endif | 870 | #endif |
887 | GNUNET_SERVER_client_keep (client); | 871 | GNUNET_SERVER_client_keep (client); |
888 | client->last_activity = now; | 872 | client->last_activity = now; |
889 | ret = GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, GNUNET_YES); | 873 | ret = |
874 | GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO, | ||
875 | GNUNET_YES); | ||
890 | process_mst (client, ret); | 876 | process_mst (client, ret); |
891 | } | 877 | } |
892 | 878 | ||
@@ -899,34 +885,33 @@ process_incoming (void *cls, | |||
899 | * @param tc scheduler context (unused) | 885 | * @param tc scheduler context (unused) |
900 | */ | 886 | */ |
901 | static void | 887 | static void |
902 | restart_processing (void *cls, | 888 | restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
903 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
904 | { | 889 | { |
905 | struct GNUNET_SERVER_Client *client = cls; | 890 | struct GNUNET_SERVER_Client *client = cls; |
906 | struct GNUNET_SERVER_Handle *server = client->server; | 891 | struct GNUNET_SERVER_Handle *server = client->server; |
907 | 892 | ||
908 | client->restart_task = GNUNET_SCHEDULER_NO_TASK; | 893 | client->restart_task = GNUNET_SCHEDULER_NO_TASK; |
909 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && | 894 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && |
910 | (GNUNET_NO == server->clients_ignore_shutdown) ) | 895 | (GNUNET_NO == server->clients_ignore_shutdown)) |
911 | { | 896 | { |
912 | GNUNET_SERVER_client_disconnect (client); | 897 | GNUNET_SERVER_client_disconnect (client); |
913 | return; | 898 | return; |
914 | } | 899 | } |
915 | if (client->receive_pending == GNUNET_NO) | 900 | if (client->receive_pending == GNUNET_NO) |
916 | { | 901 | { |
917 | #if DEBUG_SERVER | 902 | #if DEBUG_SERVER |
918 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
919 | "Server begins to read again from client.\n"); | 904 | "Server begins to read again from client.\n"); |
920 | #endif | 905 | #endif |
921 | client->receive_pending = GNUNET_YES; | 906 | client->receive_pending = GNUNET_YES; |
922 | GNUNET_CONNECTION_receive (client->connection, | 907 | GNUNET_CONNECTION_receive (client->connection, |
923 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 908 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
924 | client->idle_timeout, &process_incoming, client); | 909 | client->idle_timeout, &process_incoming, client); |
925 | return; | 910 | return; |
926 | } | 911 | } |
927 | #if DEBUG_SERVER | 912 | #if DEBUG_SERVER |
928 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
929 | "Server continues processing messages still in the buffer.\n"); | 914 | "Server continues processing messages still in the buffer.\n"); |
930 | #endif | 915 | #endif |
931 | GNUNET_SERVER_client_keep (client); | 916 | GNUNET_SERVER_client_keep (client); |
932 | client->receive_pending = GNUNET_NO; | 917 | client->receive_pending = GNUNET_NO; |
@@ -944,8 +929,8 @@ restart_processing (void *cls, | |||
944 | */ | 929 | */ |
945 | static void | 930 | static void |
946 | client_message_tokenizer_callback (void *cls, | 931 | client_message_tokenizer_callback (void *cls, |
947 | void *client, | 932 | void *client, |
948 | const struct GNUNET_MessageHeader *message) | 933 | const struct GNUNET_MessageHeader *message) |
949 | { | 934 | { |
950 | struct GNUNET_SERVER_Handle *server = cls; | 935 | struct GNUNET_SERVER_Handle *server = cls; |
951 | struct GNUNET_SERVER_Client *sender = client; | 936 | struct GNUNET_SERVER_Client *sender = client; |
@@ -954,14 +939,14 @@ client_message_tokenizer_callback (void *cls, | |||
954 | #if DEBUG_SERVER | 939 | #if DEBUG_SERVER |
955 | 940 | ||
956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 941 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
957 | "Tokenizer gives server message of type %u from client\n", | 942 | "Tokenizer gives server message of type %u from client\n", |
958 | ntohs (message->type)); | 943 | ntohs (message->type)); |
959 | #endif | 944 | #endif |
960 | sender->in_process_client_buffer = GNUNET_YES; | 945 | sender->in_process_client_buffer = GNUNET_YES; |
961 | ret = GNUNET_SERVER_inject (server, sender, message); | 946 | ret = GNUNET_SERVER_inject (server, sender, message); |
962 | sender->in_process_client_buffer = GNUNET_NO; | 947 | sender->in_process_client_buffer = GNUNET_NO; |
963 | if (GNUNET_OK != ret) | 948 | if (GNUNET_OK != ret) |
964 | GNUNET_SERVER_client_disconnect (sender); | 949 | GNUNET_SERVER_client_disconnect (sender); |
965 | } | 950 | } |
966 | 951 | ||
967 | 952 | ||
@@ -988,7 +973,7 @@ GNUNET_SERVER_connect_socket (struct | |||
988 | client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); | 973 | client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); |
989 | client->connection = connection; | 974 | client->connection = connection; |
990 | client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, | 975 | client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, |
991 | server); | 976 | server); |
992 | client->reference_count = 1; | 977 | client->reference_count = 1; |
993 | client->server = server; | 978 | client->server = server; |
994 | client->last_activity = GNUNET_TIME_absolute_get (); | 979 | client->last_activity = GNUNET_TIME_absolute_get (); |
@@ -999,8 +984,8 @@ GNUNET_SERVER_connect_socket (struct | |||
999 | client->callback = NULL; | 984 | client->callback = NULL; |
1000 | client->callback_cls = NULL; | 985 | client->callback_cls = NULL; |
1001 | GNUNET_CONNECTION_receive (client->connection, | 986 | GNUNET_CONNECTION_receive (client->connection, |
1002 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 987 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
1003 | client->idle_timeout, &process_incoming, client); | 988 | client->idle_timeout, &process_incoming, client); |
1004 | return client; | 989 | return client; |
1005 | } | 990 | } |
1006 | 991 | ||
@@ -1014,8 +999,8 @@ GNUNET_SERVER_connect_socket (struct | |||
1014 | * @param timeout new timeout for activities on the socket | 999 | * @param timeout new timeout for activities on the socket |
1015 | */ | 1000 | */ |
1016 | void | 1001 | void |
1017 | GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, | 1002 | GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, |
1018 | struct GNUNET_TIME_Relative timeout) | 1003 | struct GNUNET_TIME_Relative timeout) |
1019 | { | 1004 | { |
1020 | client->idle_timeout = timeout; | 1005 | client->idle_timeout = timeout; |
1021 | } | 1006 | } |
@@ -1048,8 +1033,7 @@ GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client) | |||
1048 | { | 1033 | { |
1049 | GNUNET_assert (client->reference_count > 0); | 1034 | GNUNET_assert (client->reference_count > 0); |
1050 | client->reference_count--; | 1035 | client->reference_count--; |
1051 | if ( (client->shutdown_now == GNUNET_YES) && | 1036 | if ((client->shutdown_now == GNUNET_YES) && (client->reference_count == 0)) |
1052 | (client->reference_count == 0) ) | ||
1053 | GNUNET_SERVER_client_disconnect (client); | 1037 | GNUNET_SERVER_client_disconnect (client); |
1054 | } | 1038 | } |
1055 | 1039 | ||
@@ -1066,8 +1050,7 @@ int | |||
1066 | GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, | 1050 | GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, |
1067 | void **addr, size_t * addrlen) | 1051 | void **addr, size_t * addrlen) |
1068 | { | 1052 | { |
1069 | return GNUNET_CONNECTION_get_address (client->connection, | 1053 | return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen); |
1070 | addr, addrlen); | ||
1071 | } | 1054 | } |
1072 | 1055 | ||
1073 | 1056 | ||
@@ -1105,8 +1088,8 @@ GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, | |||
1105 | */ | 1088 | */ |
1106 | void | 1089 | void |
1107 | GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, | 1090 | GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, |
1108 | GNUNET_SERVER_DisconnectCallback callback, | 1091 | GNUNET_SERVER_DisconnectCallback |
1109 | void *callback_cls) | 1092 | callback, void *callback_cls) |
1110 | { | 1093 | { |
1111 | struct NotifyList *pos; | 1094 | struct NotifyList *pos; |
1112 | struct NotifyList *prev; | 1095 | struct NotifyList *prev; |
@@ -1114,18 +1097,17 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, | |||
1114 | prev = NULL; | 1097 | prev = NULL; |
1115 | pos = server->disconnect_notify_list; | 1098 | pos = server->disconnect_notify_list; |
1116 | while (pos != NULL) | 1099 | while (pos != NULL) |
1117 | { | 1100 | { |
1118 | if ( (pos->callback == callback) && | 1101 | if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) |
1119 | (pos->callback_cls == callback_cls ) ) | 1102 | break; |
1120 | break; | 1103 | prev = pos; |
1121 | prev = pos; | 1104 | pos = pos->next; |
1122 | pos = pos->next; | 1105 | } |
1123 | } | ||
1124 | if (pos == NULL) | 1106 | if (pos == NULL) |
1125 | { | 1107 | { |
1126 | GNUNET_break (0); | 1108 | GNUNET_break (0); |
1127 | return; | 1109 | return; |
1128 | } | 1110 | } |
1129 | if (prev == NULL) | 1111 | if (prev == NULL) |
1130 | server->disconnect_notify_list = pos->next; | 1112 | server->disconnect_notify_list = pos->next; |
1131 | else | 1113 | else |
@@ -1153,81 +1135,81 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client) | |||
1153 | 1135 | ||
1154 | #if DEBUG_SERVER | 1136 | #if DEBUG_SERVER |
1155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1156 | "Client is being disconnected from the server.\n"); | 1138 | "Client is being disconnected from the server.\n"); |
1157 | #endif | 1139 | #endif |
1158 | if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) | 1140 | if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) |
1141 | { | ||
1142 | GNUNET_SCHEDULER_cancel (client->restart_task); | ||
1143 | client->restart_task = GNUNET_SCHEDULER_NO_TASK; | ||
1144 | } | ||
1145 | if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) | ||
1146 | { | ||
1147 | GNUNET_SCHEDULER_cancel (client->warn_task); | ||
1148 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; | ||
1149 | } | ||
1150 | if (GNUNET_YES == client->receive_pending) | ||
1151 | { | ||
1152 | GNUNET_CONNECTION_receive_cancel (client->connection); | ||
1153 | client->receive_pending = GNUNET_NO; | ||
1154 | } | ||
1155 | |||
1156 | rc = client->reference_count; | ||
1157 | if (client->server != NULL) | ||
1158 | { | ||
1159 | server = client->server; | ||
1160 | client->server = NULL; | ||
1161 | client->shutdown_now = GNUNET_YES; | ||
1162 | prev = NULL; | ||
1163 | pos = server->clients; | ||
1164 | while ((pos != NULL) && (pos != client)) | ||
1165 | { | ||
1166 | prev = pos; | ||
1167 | pos = pos->next; | ||
1168 | } | ||
1169 | GNUNET_assert (pos != NULL); | ||
1170 | if (prev == NULL) | ||
1171 | server->clients = pos->next; | ||
1172 | else | ||
1173 | prev->next = pos->next; | ||
1174 | if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) | ||
1159 | { | 1175 | { |
1160 | GNUNET_SCHEDULER_cancel (client->restart_task); | 1176 | GNUNET_SCHEDULER_cancel (client->restart_task); |
1161 | client->restart_task = GNUNET_SCHEDULER_NO_TASK; | 1177 | client->restart_task = GNUNET_SCHEDULER_NO_TASK; |
1162 | } | 1178 | } |
1163 | if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) | 1179 | if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) |
1164 | { | 1180 | { |
1165 | GNUNET_SCHEDULER_cancel (client->warn_task); | 1181 | GNUNET_SCHEDULER_cancel (client->warn_task); |
1166 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; | 1182 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; |
1167 | } | 1183 | } |
1168 | if (GNUNET_YES == client->receive_pending) | 1184 | n = server->disconnect_notify_list; |
1185 | while (n != NULL) | ||
1169 | { | 1186 | { |
1170 | GNUNET_CONNECTION_receive_cancel (client->connection); | 1187 | n->callback (n->callback_cls, client); |
1171 | client->receive_pending = GNUNET_NO; | 1188 | n = n->next; |
1172 | } | ||
1173 | |||
1174 | rc = client->reference_count; | ||
1175 | if (client->server != NULL) | ||
1176 | { | ||
1177 | server = client->server; | ||
1178 | client->server = NULL; | ||
1179 | client->shutdown_now = GNUNET_YES; | ||
1180 | prev = NULL; | ||
1181 | pos = server->clients; | ||
1182 | while ((pos != NULL) && (pos != client)) | ||
1183 | { | ||
1184 | prev = pos; | ||
1185 | pos = pos->next; | ||
1186 | } | ||
1187 | GNUNET_assert (pos != NULL); | ||
1188 | if (prev == NULL) | ||
1189 | server->clients = pos->next; | ||
1190 | else | ||
1191 | prev->next = pos->next; | ||
1192 | if (client->restart_task != GNUNET_SCHEDULER_NO_TASK) | ||
1193 | { | ||
1194 | GNUNET_SCHEDULER_cancel (client->restart_task); | ||
1195 | client->restart_task = GNUNET_SCHEDULER_NO_TASK; | ||
1196 | } | ||
1197 | if (client->warn_task != GNUNET_SCHEDULER_NO_TASK) | ||
1198 | { | ||
1199 | GNUNET_SCHEDULER_cancel (client->warn_task); | ||
1200 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; | ||
1201 | } | ||
1202 | n = server->disconnect_notify_list; | ||
1203 | while (n != NULL) | ||
1204 | { | ||
1205 | n->callback (n->callback_cls, client); | ||
1206 | n = n->next; | ||
1207 | } | ||
1208 | } | 1189 | } |
1190 | } | ||
1209 | if (rc > 0) | 1191 | if (rc > 0) |
1210 | { | 1192 | { |
1211 | #if DEBUG_SERVER | 1193 | #if DEBUG_SERVER |
1212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1213 | "RC still positive, not destroying everything.\n"); | 1195 | "RC still positive, not destroying everything.\n"); |
1214 | #endif | 1196 | #endif |
1215 | return; | 1197 | return; |
1216 | } | 1198 | } |
1217 | if (client->in_process_client_buffer == GNUNET_YES) | 1199 | if (client->in_process_client_buffer == GNUNET_YES) |
1218 | { | 1200 | { |
1219 | #if DEBUG_SERVER | 1201 | #if DEBUG_SERVER |
1220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1221 | "Still processing inputs, not destroying everything.\n"); | 1203 | "Still processing inputs, not destroying everything.\n"); |
1222 | #endif | 1204 | #endif |
1223 | return; | 1205 | return; |
1224 | } | 1206 | } |
1225 | 1207 | ||
1226 | if (client->persist == GNUNET_YES) | 1208 | if (client->persist == GNUNET_YES) |
1227 | GNUNET_CONNECTION_persist_ (client->connection); | 1209 | GNUNET_CONNECTION_persist_ (client->connection); |
1228 | GNUNET_CONNECTION_destroy (client->connection, GNUNET_NO); | 1210 | GNUNET_CONNECTION_destroy (client->connection, GNUNET_NO); |
1229 | GNUNET_SERVER_mst_destroy (client->mst); | 1211 | GNUNET_SERVER_mst_destroy (client->mst); |
1230 | GNUNET_free (client); | 1212 | GNUNET_free (client); |
1231 | } | 1213 | } |
1232 | 1214 | ||
1233 | 1215 | ||
@@ -1255,7 +1237,7 @@ GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client) | |||
1255 | * @param buf where to copy the message | 1237 | * @param buf where to copy the message |
1256 | * @return number of bytes actually transmitted | 1238 | * @return number of bytes actually transmitted |
1257 | */ | 1239 | */ |
1258 | static size_t | 1240 | static size_t |
1259 | transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) | 1241 | transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) |
1260 | { | 1242 | { |
1261 | struct GNUNET_SERVER_Client *client = cls; | 1243 | struct GNUNET_SERVER_Client *client = cls; |
@@ -1263,7 +1245,7 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) | |||
1263 | 1245 | ||
1264 | ret = client->callback (client->callback_cls, size, buf); | 1246 | ret = client->callback (client->callback_cls, size, buf); |
1265 | if (ret > 0) | 1247 | if (ret > 0) |
1266 | client->last_activity = GNUNET_TIME_absolute_get(); | 1248 | client->last_activity = GNUNET_TIME_absolute_get (); |
1267 | return ret; | 1249 | return ret; |
1268 | } | 1250 | } |
1269 | 1251 | ||
@@ -1293,9 +1275,10 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | |||
1293 | client->callback_cls = callback_cls; | 1275 | client->callback_cls = callback_cls; |
1294 | client->callback = callback; | 1276 | client->callback = callback; |
1295 | return GNUNET_CONNECTION_notify_transmit_ready (client->connection, | 1277 | return GNUNET_CONNECTION_notify_transmit_ready (client->connection, |
1296 | size, | 1278 | size, |
1297 | timeout, | 1279 | timeout, |
1298 | &transmit_ready_callback_wrapper, client); | 1280 | &transmit_ready_callback_wrapper, |
1281 | client); | ||
1299 | } | 1282 | } |
1300 | 1283 | ||
1301 | 1284 | ||
@@ -1332,47 +1315,46 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success) | |||
1332 | GNUNET_assert (client->suspended > 0); | 1315 | GNUNET_assert (client->suspended > 0); |
1333 | client->suspended--; | 1316 | client->suspended--; |
1334 | if (success != GNUNET_OK) | 1317 | if (success != GNUNET_OK) |
1335 | { | 1318 | { |
1336 | #if DEBUG_SERVER | 1319 | #if DEBUG_SERVER |
1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1338 | "GNUNET_SERVER_receive_done called with failure indication\n"); | 1321 | "GNUNET_SERVER_receive_done called with failure indication\n"); |
1339 | #endif | 1322 | #endif |
1340 | GNUNET_SERVER_client_disconnect (client); | 1323 | GNUNET_SERVER_client_disconnect (client); |
1341 | return; | 1324 | return; |
1342 | } | 1325 | } |
1343 | if (client->suspended > 0) | 1326 | if (client->suspended > 0) |
1344 | { | 1327 | { |
1345 | #if DEBUG_SERVER | 1328 | #if DEBUG_SERVER |
1346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1347 | "GNUNET_SERVER_receive_done called, but more clients pending\n"); | 1330 | "GNUNET_SERVER_receive_done called, but more clients pending\n"); |
1348 | #endif | 1331 | #endif |
1349 | return; | 1332 | return; |
1350 | } | 1333 | } |
1351 | if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) | 1334 | if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) |
1352 | { | 1335 | { |
1353 | GNUNET_SCHEDULER_cancel (client->warn_task); | 1336 | GNUNET_SCHEDULER_cancel (client->warn_task); |
1354 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; | 1337 | client->warn_task = GNUNET_SCHEDULER_NO_TASK; |
1355 | } | 1338 | } |
1356 | if (client->in_process_client_buffer == GNUNET_YES) | 1339 | if (client->in_process_client_buffer == GNUNET_YES) |
1357 | { | 1340 | { |
1358 | #if DEBUG_SERVER | 1341 | #if DEBUG_SERVER |
1359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1360 | "GNUNET_SERVER_receive_done called while still in processing loop\n"); | 1343 | "GNUNET_SERVER_receive_done called while still in processing loop\n"); |
1361 | #endif | 1344 | #endif |
1362 | return; | 1345 | return; |
1363 | } | 1346 | } |
1364 | if (client->server == NULL) | 1347 | if (client->server == NULL) |
1365 | { | 1348 | { |
1366 | GNUNET_SERVER_client_disconnect (client); | 1349 | GNUNET_SERVER_client_disconnect (client); |
1367 | return; | 1350 | return; |
1368 | } | 1351 | } |
1369 | #if DEBUG_SERVER | 1352 | #if DEBUG_SERVER |
1370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1371 | "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); | 1354 | "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); |
1372 | #endif | 1355 | #endif |
1373 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task); | 1356 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task); |
1374 | client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, | 1357 | client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client); |
1375 | client); | ||
1376 | } | 1358 | } |
1377 | 1359 | ||
1378 | 1360 | ||
diff --git a/src/util/server_mst.c b/src/util/server_mst.c index 835d8eeba..f48ef5475 100644 --- a/src/util/server_mst.c +++ b/src/util/server_mst.c | |||
@@ -50,7 +50,7 @@ struct GNUNET_SERVER_MessageStreamTokenizer | |||
50 | * Function to call on completed messages. | 50 | * Function to call on completed messages. |
51 | */ | 51 | */ |
52 | GNUNET_SERVER_MessageTokenizerCallback cb; | 52 | GNUNET_SERVER_MessageTokenizerCallback cb; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Closure for cb. | 55 | * Closure for cb. |
56 | */ | 56 | */ |
@@ -89,12 +89,12 @@ struct GNUNET_SERVER_MessageStreamTokenizer | |||
89 | */ | 89 | */ |
90 | struct GNUNET_SERVER_MessageStreamTokenizer * | 90 | struct GNUNET_SERVER_MessageStreamTokenizer * |
91 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | 91 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, |
92 | void *cb_cls) | 92 | void *cb_cls) |
93 | { | 93 | { |
94 | struct GNUNET_SERVER_MessageStreamTokenizer *ret; | 94 | struct GNUNET_SERVER_MessageStreamTokenizer *ret; |
95 | 95 | ||
96 | ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_MessageStreamTokenizer)); | 96 | ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_MessageStreamTokenizer)); |
97 | ret->hdr = GNUNET_malloc(GNUNET_SERVER_MIN_BUFFER_SIZE); | 97 | ret->hdr = GNUNET_malloc (GNUNET_SERVER_MIN_BUFFER_SIZE); |
98 | ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE; | 98 | ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE; |
99 | ret->cb = cb; | 99 | ret->cb = cb; |
100 | ret->cb_cls = cb_cls; | 100 | ret->cb_cls = cb_cls; |
@@ -119,11 +119,9 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | |||
119 | */ | 119 | */ |
120 | int | 120 | int |
121 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | 121 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, |
122 | void *client_identity, | 122 | void *client_identity, |
123 | const char *buf, | 123 | const char *buf, |
124 | size_t size, | 124 | size_t size, int purge, int one_shot) |
125 | int purge, | ||
126 | int one_shot) | ||
127 | { | 125 | { |
128 | const struct GNUNET_MessageHeader *hdr; | 126 | const struct GNUNET_MessageHeader *hdr; |
129 | size_t delta; | 127 | size_t delta; |
@@ -135,169 +133,160 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | |||
135 | 133 | ||
136 | #if DEBUG_SERVER_MST | 134 | #if DEBUG_SERVER_MST |
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
138 | "Server-mst receives %u bytes with %u bytes already in private buffer\n", | 136 | "Server-mst receives %u bytes with %u bytes already in private buffer\n", |
139 | (unsigned int) size, | 137 | (unsigned int) size, (unsigned int) (mst->pos - mst->off)); |
140 | (unsigned int) (mst->pos - mst->off)); | ||
141 | #endif | 138 | #endif |
142 | ret = GNUNET_OK; | 139 | ret = GNUNET_OK; |
143 | ibuf = (char*)mst->hdr; | 140 | ibuf = (char *) mst->hdr; |
144 | while (mst->pos > 0) | 141 | while (mst->pos > 0) |
142 | { | ||
143 | do_align: | ||
144 | if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || | ||
145 | (0 != (mst->off % ALIGN_FACTOR))) | ||
146 | { | ||
147 | /* need to align or need more space */ | ||
148 | mst->pos -= mst->off; | ||
149 | memmove (ibuf, &ibuf[mst->off], mst->pos); | ||
150 | mst->off = 0; | ||
151 | } | ||
152 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | ||
153 | { | ||
154 | delta = | ||
155 | GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - | ||
156 | (mst->pos - mst->off), size); | ||
157 | memcpy (&ibuf[mst->pos], buf, delta); | ||
158 | mst->pos += delta; | ||
159 | buf += delta; | ||
160 | size -= delta; | ||
161 | } | ||
162 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | ||
163 | { | ||
164 | if (purge) | ||
165 | { | ||
166 | mst->off = 0; | ||
167 | mst->pos = 0; | ||
168 | } | ||
169 | return GNUNET_OK; | ||
170 | } | ||
171 | hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; | ||
172 | want = ntohs (hdr->size); | ||
173 | if (want < sizeof (struct GNUNET_MessageHeader)) | ||
145 | { | 174 | { |
146 | do_align: | 175 | GNUNET_break_op (0); |
147 | if ( (mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || | 176 | return GNUNET_SYSERR; |
148 | (0 != (mst->off % ALIGN_FACTOR)) ) | 177 | } |
149 | { | 178 | if (mst->curr_buf - mst->off < want) |
150 | /* need to align or need more space */ | 179 | { |
151 | mst->pos -= mst->off; | 180 | /* need more space */ |
152 | memmove (ibuf, | 181 | mst->pos -= mst->off; |
153 | &ibuf[mst->off], | 182 | memmove (ibuf, &ibuf[mst->off], mst->pos); |
154 | mst->pos); | 183 | mst->off = 0; |
155 | mst->off = 0; | 184 | } |
156 | } | 185 | if (want > mst->curr_buf) |
157 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | 186 | { |
158 | { | 187 | mst->hdr = GNUNET_realloc (mst->hdr, want); |
159 | delta = GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - (mst->pos - mst->off), | 188 | ibuf = (char *) mst->hdr; |
160 | size); | 189 | mst->curr_buf = want; |
161 | memcpy (&ibuf[mst->pos], | 190 | } |
162 | buf, | 191 | hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; |
163 | delta); | 192 | if (mst->pos - mst->off < want) |
164 | mst->pos += delta; | 193 | { |
165 | buf += delta; | 194 | delta = GNUNET_MIN (want - (mst->pos - mst->off), size); |
166 | size -= delta; | 195 | memcpy (&ibuf[mst->pos], buf, delta); |
167 | } | 196 | mst->pos += delta; |
168 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | 197 | buf += delta; |
169 | { | 198 | size -= delta; |
170 | if (purge) | 199 | } |
171 | { | 200 | if (mst->pos - mst->off < want) |
172 | mst->off = 0; | 201 | { |
173 | mst->pos = 0; | 202 | if (purge) |
174 | } | 203 | { |
175 | return GNUNET_OK; | 204 | mst->off = 0; |
176 | } | 205 | mst->pos = 0; |
177 | hdr = (const struct GNUNET_MessageHeader*) &ibuf[mst->off]; | 206 | } |
207 | return GNUNET_OK; | ||
208 | } | ||
209 | if (one_shot == GNUNET_SYSERR) | ||
210 | { | ||
211 | /* cannot call callback again, but return value saying that | ||
212 | * we have another full message in the buffer */ | ||
213 | ret = GNUNET_NO; | ||
214 | goto copy; | ||
215 | } | ||
216 | if (one_shot == GNUNET_YES) | ||
217 | one_shot = GNUNET_SYSERR; | ||
218 | mst->cb (mst->cb_cls, client_identity, hdr); | ||
219 | mst->off += want; | ||
220 | if (mst->off == mst->pos) | ||
221 | { | ||
222 | /* reset to beginning of buffer, it's free right now! */ | ||
223 | mst->off = 0; | ||
224 | mst->pos = 0; | ||
225 | } | ||
226 | } | ||
227 | while (size > 0) | ||
228 | { | ||
229 | #if DEBUG_SERVER_MST | ||
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
231 | "Server-mst has %u bytes left in inbound buffer\n", | ||
232 | (unsigned int) size); | ||
233 | #endif | ||
234 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
235 | break; | ||
236 | offset = (unsigned long) buf; | ||
237 | need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; | ||
238 | if (GNUNET_NO == need_align) | ||
239 | { | ||
240 | /* can try to do zero-copy and process directly from original buffer */ | ||
241 | hdr = (const struct GNUNET_MessageHeader *) buf; | ||
178 | want = ntohs (hdr->size); | 242 | want = ntohs (hdr->size); |
179 | if (want < sizeof (struct GNUNET_MessageHeader)) | 243 | if (want < sizeof (struct GNUNET_MessageHeader)) |
180 | { | 244 | { |
181 | GNUNET_break_op (0); | 245 | GNUNET_break_op (0); |
182 | return GNUNET_SYSERR; | 246 | mst->off = 0; |
183 | } | 247 | return GNUNET_SYSERR; |
184 | if (mst->curr_buf - mst->off < want) | 248 | } |
185 | { | 249 | if (size < want) |
186 | /* need more space */ | 250 | break; /* or not, buffer incomplete, so copy to private buffer... */ |
187 | mst->pos -= mst->off; | ||
188 | memmove (ibuf, | ||
189 | &ibuf[mst->off], | ||
190 | mst->pos); | ||
191 | mst->off = 0; | ||
192 | } | ||
193 | if (want > mst->curr_buf) | ||
194 | { | ||
195 | mst->hdr = GNUNET_realloc(mst->hdr, want); | ||
196 | ibuf = (char*)mst->hdr; | ||
197 | mst->curr_buf = want; | ||
198 | } | ||
199 | hdr = (const struct GNUNET_MessageHeader*) &ibuf[mst->off]; | ||
200 | if (mst->pos - mst->off < want) | ||
201 | { | ||
202 | delta = GNUNET_MIN (want - (mst->pos - mst->off), | ||
203 | size); | ||
204 | memcpy (&ibuf[mst->pos], | ||
205 | buf, | ||
206 | delta); | ||
207 | mst->pos += delta; | ||
208 | buf += delta; | ||
209 | size -= delta; | ||
210 | } | ||
211 | if (mst->pos - mst->off < want) | ||
212 | { | ||
213 | if (purge) | ||
214 | { | ||
215 | mst->off = 0; | ||
216 | mst->pos = 0; | ||
217 | } | ||
218 | return GNUNET_OK; | ||
219 | } | ||
220 | if (one_shot == GNUNET_SYSERR) | 251 | if (one_shot == GNUNET_SYSERR) |
221 | { | 252 | { |
222 | /* cannot call callback again, but return value saying that | 253 | /* cannot call callback again, but return value saying that |
223 | we have another full message in the buffer */ | 254 | * we have another full message in the buffer */ |
224 | ret = GNUNET_NO; | 255 | ret = GNUNET_NO; |
225 | goto copy; | 256 | goto copy; |
226 | } | 257 | } |
227 | if (one_shot == GNUNET_YES) | 258 | if (one_shot == GNUNET_YES) |
228 | one_shot = GNUNET_SYSERR; | 259 | one_shot = GNUNET_SYSERR; |
229 | mst->cb (mst->cb_cls, client_identity, hdr); | 260 | mst->cb (mst->cb_cls, client_identity, hdr); |
230 | mst->off += want; | 261 | buf += want; |
231 | if (mst->off == mst->pos) | 262 | size -= want; |
232 | { | ||
233 | /* reset to beginning of buffer, it's free right now! */ | ||
234 | mst->off = 0; | ||
235 | mst->pos = 0; | ||
236 | } | ||
237 | } | 263 | } |
238 | while (size > 0) | 264 | else |
239 | { | 265 | { |
240 | #if DEBUG_SERVER_MST | 266 | /* need to copy to private buffer to align; |
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 267 | * yes, we go a bit more spagetti than usual here */ |
242 | "Server-mst has %u bytes left in inbound buffer\n", | 268 | goto do_align; |
243 | (unsigned int) size); | ||
244 | #endif | ||
245 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
246 | break; | ||
247 | offset = (unsigned long) buf; | ||
248 | need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; | ||
249 | if (GNUNET_NO == need_align) | ||
250 | { | ||
251 | /* can try to do zero-copy and process directly from original buffer */ | ||
252 | hdr = (const struct GNUNET_MessageHeader *) buf; | ||
253 | want = ntohs (hdr->size); | ||
254 | if (want < sizeof (struct GNUNET_MessageHeader)) | ||
255 | { | ||
256 | GNUNET_break_op (0); | ||
257 | mst->off = 0; | ||
258 | return GNUNET_SYSERR; | ||
259 | } | ||
260 | if (size < want) | ||
261 | break; /* or not, buffer incomplete, so copy to private buffer... */ | ||
262 | if (one_shot == GNUNET_SYSERR) | ||
263 | { | ||
264 | /* cannot call callback again, but return value saying that | ||
265 | we have another full message in the buffer */ | ||
266 | ret = GNUNET_NO; | ||
267 | goto copy; | ||
268 | } | ||
269 | if (one_shot == GNUNET_YES) | ||
270 | one_shot = GNUNET_SYSERR; | ||
271 | mst->cb (mst->cb_cls, client_identity, hdr); | ||
272 | buf += want; | ||
273 | size -= want; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | /* need to copy to private buffer to align; | ||
278 | yes, we go a bit more spagetti than usual here */ | ||
279 | goto do_align; | ||
280 | } | ||
281 | } | 269 | } |
282 | copy: | 270 | } |
283 | if ( (size > 0) && (! purge) ) | 271 | copy: |
272 | if ((size > 0) && (!purge)) | ||
273 | { | ||
274 | if (size + mst->pos > mst->curr_buf) | ||
284 | { | 275 | { |
285 | if (size + mst->pos > mst->curr_buf) | 276 | mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); |
286 | { | 277 | ibuf = (char *) mst->hdr; |
287 | mst->hdr = GNUNET_realloc(mst->hdr, size + mst->pos); | 278 | mst->curr_buf = size + mst->pos; |
288 | ibuf = (char*)mst->hdr; | ||
289 | mst->curr_buf = size + mst->pos; | ||
290 | } | ||
291 | GNUNET_assert (mst->pos + size <= mst->curr_buf); | ||
292 | memcpy (&ibuf[mst->pos], buf, size); | ||
293 | mst->pos += size; | ||
294 | } | 279 | } |
280 | GNUNET_assert (mst->pos + size <= mst->curr_buf); | ||
281 | memcpy (&ibuf[mst->pos], buf, size); | ||
282 | mst->pos += size; | ||
283 | } | ||
295 | if (purge) | 284 | if (purge) |
296 | mst->off = 0; | 285 | mst->off = 0; |
297 | #if DEBUG_SERVER_MST | 286 | #if DEBUG_SERVER_MST |
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
299 | "Server-mst leaves %u bytes in private buffer\n", | 288 | "Server-mst leaves %u bytes in private buffer\n", |
300 | (unsigned int) (mst->pos - mst->off)); | 289 | (unsigned int) (mst->pos - mst->off)); |
301 | #endif | 290 | #endif |
302 | return ret; | 291 | return ret; |
303 | } | 292 | } |
diff --git a/src/util/server_nc.c b/src/util/server_nc.c index 56d79c18e..f8e300029 100644 --- a/src/util/server_nc.c +++ b/src/util/server_nc.c | |||
@@ -44,12 +44,12 @@ struct PendingMessageList | |||
44 | 44 | ||
45 | /** | 45 | /** |
46 | * This is a doubly-linked list. | 46 | * This is a doubly-linked list. |
47 | */ | 47 | */ |
48 | struct PendingMessageList *next; | 48 | struct PendingMessageList *next; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * This is a doubly-linked list. | 51 | * This is a doubly-linked list. |
52 | */ | 52 | */ |
53 | struct PendingMessageList *prev; | 53 | struct PendingMessageList *prev; |
54 | 54 | ||
55 | /** | 55 | /** |
@@ -60,7 +60,7 @@ struct PendingMessageList | |||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Can this message be dropped? | 62 | * Can this message be dropped? |
63 | */ | 63 | */ |
64 | int can_drop; | 64 | int can_drop; |
65 | 65 | ||
66 | }; | 66 | }; |
@@ -74,7 +74,7 @@ struct ClientList | |||
74 | 74 | ||
75 | /** | 75 | /** |
76 | * This is a linked list. | 76 | * This is a linked list. |
77 | */ | 77 | */ |
78 | struct ClientList *next; | 78 | struct ClientList *next; |
79 | 79 | ||
80 | /** | 80 | /** |
@@ -94,12 +94,12 @@ struct ClientList | |||
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Head of linked list of requests queued for transmission. | 96 | * Head of linked list of requests queued for transmission. |
97 | */ | 97 | */ |
98 | struct PendingMessageList *pending_head; | 98 | struct PendingMessageList *pending_head; |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Tail of linked list of requests queued for transmission. | 101 | * Tail of linked list of requests queued for transmission. |
102 | */ | 102 | */ |
103 | struct PendingMessageList *pending_tail; | 103 | struct PendingMessageList *pending_tail; |
104 | 104 | ||
105 | /** | 105 | /** |
@@ -146,8 +146,7 @@ struct GNUNET_SERVER_NotificationContext | |||
146 | * @param client handle of client that disconnected | 146 | * @param client handle of client that disconnected |
147 | */ | 147 | */ |
148 | static void | 148 | static void |
149 | handle_client_disconnect (void *cls, | 149 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
150 | struct GNUNET_SERVER_Client *client) | ||
151 | { | 150 | { |
152 | struct GNUNET_SERVER_NotificationContext *nc = cls; | 151 | struct GNUNET_SERVER_NotificationContext *nc = cls; |
153 | struct ClientList *pos; | 152 | struct ClientList *pos; |
@@ -155,42 +154,40 @@ handle_client_disconnect (void *cls, | |||
155 | struct PendingMessageList *pml; | 154 | struct PendingMessageList *pml; |
156 | 155 | ||
157 | if (client == NULL) | 156 | if (client == NULL) |
158 | { | 157 | { |
159 | nc->server = NULL; | 158 | nc->server = NULL; |
160 | return; | 159 | return; |
161 | } | 160 | } |
162 | prev = NULL; | 161 | prev = NULL; |
163 | pos = nc->clients; | 162 | pos = nc->clients; |
164 | while (NULL != pos) | 163 | while (NULL != pos) |
165 | { | 164 | { |
166 | if (pos->client == client) | 165 | if (pos->client == client) |
167 | break; | 166 | break; |
168 | prev = pos; | 167 | prev = pos; |
169 | pos = pos->next; | 168 | pos = pos->next; |
170 | } | 169 | } |
171 | if (pos == NULL) | 170 | if (pos == NULL) |
172 | return; | 171 | return; |
173 | #if DEBUG_SERVER_NC | 172 | #if DEBUG_SERVER_NC |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Client disconnected, cleaning up %u messages in NC queue\n", | 174 | "Client disconnected, cleaning up %u messages in NC queue\n", |
176 | pos->num_pending); | 175 | pos->num_pending); |
177 | #endif | 176 | #endif |
178 | if (prev == NULL) | 177 | if (prev == NULL) |
179 | nc->clients = pos->next; | 178 | nc->clients = pos->next; |
180 | else | 179 | else |
181 | prev->next = pos->next; | 180 | prev->next = pos->next; |
182 | while (NULL != (pml = pos->pending_head)) | 181 | while (NULL != (pml = pos->pending_head)) |
183 | { | 182 | { |
184 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, | 183 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); |
185 | pos->pending_tail, | 184 | GNUNET_free (pml); |
186 | pml); | 185 | } |
187 | GNUNET_free (pml); | ||
188 | } | ||
189 | if (pos->th != NULL) | 186 | if (pos->th != NULL) |
190 | { | 187 | { |
191 | GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); | 188 | GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); |
192 | pos->th = NULL; | 189 | pos->th = NULL; |
193 | } | 190 | } |
194 | GNUNET_SERVER_client_drop (client); | 191 | GNUNET_SERVER_client_drop (client); |
195 | GNUNET_free (pos); | 192 | GNUNET_free (pos); |
196 | } | 193 | } |
@@ -207,16 +204,14 @@ handle_client_disconnect (void *cls, | |||
207 | */ | 204 | */ |
208 | struct GNUNET_SERVER_NotificationContext * | 205 | struct GNUNET_SERVER_NotificationContext * |
209 | GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, | 206 | GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, |
210 | unsigned int queue_length) | 207 | unsigned int queue_length) |
211 | { | 208 | { |
212 | struct GNUNET_SERVER_NotificationContext *ret; | 209 | struct GNUNET_SERVER_NotificationContext *ret; |
213 | 210 | ||
214 | ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_NotificationContext)); | 211 | ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_NotificationContext)); |
215 | ret->server = server; | 212 | ret->server = server; |
216 | ret->queue_length = queue_length; | 213 | ret->queue_length = queue_length; |
217 | GNUNET_SERVER_disconnect_notify (server, | 214 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, ret); |
218 | &handle_client_disconnect, | ||
219 | ret); | ||
220 | return ret; | 215 | return ret; |
221 | } | 216 | } |
222 | 217 | ||
@@ -227,28 +222,27 @@ GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, | |||
227 | * @param nc context to destroy. | 222 | * @param nc context to destroy. |
228 | */ | 223 | */ |
229 | void | 224 | void |
230 | GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationContext *nc) | 225 | GNUNET_SERVER_notification_context_destroy (struct |
226 | GNUNET_SERVER_NotificationContext | ||
227 | *nc) | ||
231 | { | 228 | { |
232 | struct ClientList *pos; | 229 | struct ClientList *pos; |
233 | struct PendingMessageList *pml; | 230 | struct PendingMessageList *pml; |
234 | 231 | ||
235 | while (NULL != (pos = nc->clients)) | 232 | while (NULL != (pos = nc->clients)) |
233 | { | ||
234 | nc->clients = pos->next; | ||
235 | GNUNET_SERVER_client_drop (pos->client); | ||
236 | while (NULL != (pml = pos->pending_head)) | ||
236 | { | 237 | { |
237 | nc->clients = pos->next; | 238 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); |
238 | GNUNET_SERVER_client_drop (pos->client); | 239 | GNUNET_free (pml); |
239 | while (NULL != (pml = pos->pending_head)) | ||
240 | { | ||
241 | GNUNET_CONTAINER_DLL_remove (pos->pending_head, | ||
242 | pos->pending_tail, | ||
243 | pml); | ||
244 | GNUNET_free (pml); | ||
245 | } | ||
246 | GNUNET_free (pos); | ||
247 | } | 240 | } |
241 | GNUNET_free (pos); | ||
242 | } | ||
248 | if (nc->server != NULL) | 243 | if (nc->server != NULL) |
249 | GNUNET_SERVER_disconnect_notify_cancel (nc->server, | 244 | GNUNET_SERVER_disconnect_notify_cancel (nc->server, |
250 | &handle_client_disconnect, | 245 | &handle_client_disconnect, nc); |
251 | nc); | ||
252 | GNUNET_free (nc); | 246 | GNUNET_free (nc); |
253 | } | 247 | } |
254 | 248 | ||
@@ -260,8 +254,9 @@ GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationCon | |||
260 | * @param client client to add | 254 | * @param client client to add |
261 | */ | 255 | */ |
262 | void | 256 | void |
263 | GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext *nc, | 257 | GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext |
264 | struct GNUNET_SERVER_Client *client) | 258 | *nc, |
259 | struct GNUNET_SERVER_Client *client) | ||
265 | { | 260 | { |
266 | struct ClientList *cl; | 261 | struct ClientList *cl; |
267 | 262 | ||
@@ -285,9 +280,7 @@ GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext | |||
285 | * @return number of bytes written to buf | 280 | * @return number of bytes written to buf |
286 | */ | 281 | */ |
287 | static size_t | 282 | static size_t |
288 | transmit_message (void *cls, | 283 | transmit_message (void *cls, size_t size, void *buf) |
289 | size_t size, | ||
290 | void *buf) | ||
291 | { | 284 | { |
292 | struct ClientList *cl = cls; | 285 | struct ClientList *cl = cls; |
293 | char *cbuf = buf; | 286 | char *cbuf = buf; |
@@ -297,48 +290,44 @@ transmit_message (void *cls, | |||
297 | 290 | ||
298 | cl->th = NULL; | 291 | cl->th = NULL; |
299 | if (buf == NULL) | 292 | if (buf == NULL) |
300 | { | 293 | { |
301 | /* 'cl' should be freed via disconnect notification shortly */ | 294 | /* 'cl' should be freed via disconnect notification shortly */ |
302 | #if DEBUG_SERVER_NC | 295 | #if DEBUG_SERVER_NC |
303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
304 | "Failed to transmit message from NC queue to client\n"); | 297 | "Failed to transmit message from NC queue to client\n"); |
305 | #endif | 298 | #endif |
306 | return 0; | 299 | return 0; |
307 | } | 300 | } |
308 | ret = 0; | 301 | ret = 0; |
309 | while (NULL != (pml = cl->pending_head) ) | 302 | while (NULL != (pml = cl->pending_head)) |
310 | { | 303 | { |
311 | msize = ntohs (pml->msg->size); | 304 | msize = ntohs (pml->msg->size); |
312 | if (size < msize) | 305 | if (size < msize) |
313 | break; | 306 | break; |
314 | GNUNET_CONTAINER_DLL_remove (cl->pending_head, | 307 | GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml); |
315 | cl->pending_tail, | ||
316 | pml); | ||
317 | #if DEBUG_SERVER_NC | 308 | #if DEBUG_SERVER_NC |
318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
319 | "Copying message of type %u and size %u from pending queue to transmission buffer\n", | 310 | "Copying message of type %u and size %u from pending queue to transmission buffer\n", |
320 | ntohs (pml->msg->type), | 311 | ntohs (pml->msg->type), msize); |
321 | msize); | ||
322 | #endif | 312 | #endif |
323 | memcpy (&cbuf[ret], pml->msg, msize); | 313 | memcpy (&cbuf[ret], pml->msg, msize); |
324 | ret += msize; | 314 | ret += msize; |
325 | size -= msize; | 315 | size -= msize; |
326 | GNUNET_free (pml); | 316 | GNUNET_free (pml); |
327 | cl->num_pending--; | 317 | cl->num_pending--; |
328 | } | 318 | } |
329 | if (pml != NULL) | 319 | if (pml != NULL) |
330 | { | 320 | { |
331 | #if DEBUG_SERVER_NC | 321 | #if DEBUG_SERVER_NC |
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
333 | "Have %u messages left in NC queue, will try transmission again\n", | 323 | "Have %u messages left in NC queue, will try transmission again\n", |
334 | cl->num_pending); | 324 | cl->num_pending); |
335 | #endif | 325 | #endif |
336 | cl->th = GNUNET_SERVER_notify_transmit_ready (cl->client, | 326 | cl->th = GNUNET_SERVER_notify_transmit_ready (cl->client, |
337 | ntohs (pml->msg->size), | 327 | ntohs (pml->msg->size), |
338 | GNUNET_TIME_UNIT_FOREVER_REL, | 328 | GNUNET_TIME_UNIT_FOREVER_REL, |
339 | &transmit_message, | 329 | &transmit_message, cl); |
340 | cl); | 330 | } |
341 | } | ||
342 | else | 331 | else |
343 | GNUNET_assert (cl->num_pending == 0); | 332 | GNUNET_assert (cl->num_pending == 0); |
344 | return ret; | 333 | return ret; |
@@ -355,52 +344,49 @@ transmit_message (void *cls, | |||
355 | */ | 344 | */ |
356 | static void | 345 | static void |
357 | do_unicast (struct GNUNET_SERVER_NotificationContext *nc, | 346 | do_unicast (struct GNUNET_SERVER_NotificationContext *nc, |
358 | struct ClientList *client, | 347 | struct ClientList *client, |
359 | const struct GNUNET_MessageHeader *msg, | 348 | const struct GNUNET_MessageHeader *msg, int can_drop) |
360 | int can_drop) | ||
361 | { | 349 | { |
362 | struct PendingMessageList *pml; | 350 | struct PendingMessageList *pml; |
363 | uint16_t size; | 351 | uint16_t size; |
364 | 352 | ||
365 | if ( (client->num_pending > nc->queue_length) && | 353 | if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop)) |
366 | (GNUNET_YES == can_drop) ) | 354 | { |
367 | { | 355 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
368 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 356 | "Dropping message of type %u and size %u due to full queue (%u entries)\n", |
369 | "Dropping message of type %u and size %u due to full queue (%u entries)\n", | 357 | ntohs (msg->type), |
370 | ntohs (msg->type), | 358 | ntohs (msg->size), (unsigned int) nc->queue_length); |
371 | ntohs (msg->size), | 359 | return; /* drop! */ |
372 | (unsigned int) nc->queue_length); | 360 | } |
373 | return; /* drop! */ | ||
374 | } | ||
375 | if (client->num_pending > nc->queue_length) | 361 | if (client->num_pending > nc->queue_length) |
376 | { | 362 | { |
377 | /* FIXME: consider checking for other messages in the | 363 | /* FIXME: consider checking for other messages in the |
378 | queue that are 'droppable' */ | 364 | * queue that are 'droppable' */ |
379 | } | 365 | } |
380 | client->num_pending++; | 366 | client->num_pending++; |
381 | size = ntohs (msg->size); | 367 | size = ntohs (msg->size); |
382 | pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size); | 368 | pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size); |
383 | pml->msg = (const struct GNUNET_MessageHeader*) &pml[1]; | 369 | pml->msg = (const struct GNUNET_MessageHeader *) &pml[1]; |
384 | pml->can_drop = can_drop; | 370 | pml->can_drop = can_drop; |
385 | #if DEBUG_SERVER_NC | 371 | #if DEBUG_SERVER_NC |
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
387 | "Adding message of type %u and size %u to pending queue (which has %u entries)\n", | 373 | "Adding message of type %u and size %u to pending queue (which has %u entries)\n", |
388 | ntohs (msg->type), | 374 | ntohs (msg->type), |
389 | ntohs (msg->size), | 375 | ntohs (msg->size), (unsigned int) nc->queue_length); |
390 | (unsigned int) nc->queue_length); | ||
391 | #endif | 376 | #endif |
392 | memcpy (&pml[1], msg, size); | 377 | memcpy (&pml[1], msg, size); |
393 | /* append */ | 378 | /* append */ |
394 | GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, | 379 | GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, |
395 | client->pending_tail, | 380 | client->pending_tail, pml); |
396 | pml); | ||
397 | if (client->th == NULL) | 381 | if (client->th == NULL) |
398 | client->th = GNUNET_SERVER_notify_transmit_ready (client->client, | 382 | client->th = GNUNET_SERVER_notify_transmit_ready (client->client, |
399 | ntohs (client->pending_head->msg->size), | 383 | ntohs |
400 | GNUNET_TIME_UNIT_FOREVER_REL, | 384 | (client->pending_head-> |
401 | &transmit_message, | 385 | msg->size), |
402 | client); | 386 | GNUNET_TIME_UNIT_FOREVER_REL, |
403 | } | 387 | &transmit_message, |
388 | client); | ||
389 | } | ||
404 | 390 | ||
405 | 391 | ||
406 | /** | 392 | /** |
@@ -413,22 +399,24 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc, | |||
413 | * @param can_drop can this message be dropped due to queue length limitations | 399 | * @param can_drop can this message be dropped due to queue length limitations |
414 | */ | 400 | */ |
415 | void | 401 | void |
416 | GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationContext *nc, | 402 | GNUNET_SERVER_notification_context_unicast (struct |
417 | struct GNUNET_SERVER_Client *client, | 403 | GNUNET_SERVER_NotificationContext |
418 | const struct GNUNET_MessageHeader *msg, | 404 | *nc, |
419 | int can_drop) | 405 | struct GNUNET_SERVER_Client *client, |
406 | const struct GNUNET_MessageHeader | ||
407 | *msg, int can_drop) | ||
420 | { | 408 | { |
421 | struct ClientList *pos; | 409 | struct ClientList *pos; |
422 | 410 | ||
423 | pos = nc->clients; | 411 | pos = nc->clients; |
424 | while (NULL != pos) | 412 | while (NULL != pos) |
425 | { | 413 | { |
426 | if (pos->client == client) | 414 | if (pos->client == client) |
427 | break; | 415 | break; |
428 | pos = pos->next; | 416 | pos = pos->next; |
429 | } | 417 | } |
430 | GNUNET_assert (pos != NULL); | 418 | GNUNET_assert (pos != NULL); |
431 | do_unicast (nc, pos, msg, can_drop); | 419 | do_unicast (nc, pos, msg, can_drop); |
432 | } | 420 | } |
433 | 421 | ||
434 | 422 | ||
@@ -440,18 +428,20 @@ GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationCon | |||
440 | * @param can_drop can this message be dropped due to queue length limitations | 428 | * @param can_drop can this message be dropped due to queue length limitations |
441 | */ | 429 | */ |
442 | void | 430 | void |
443 | GNUNET_SERVER_notification_context_broadcast (struct GNUNET_SERVER_NotificationContext *nc, | 431 | GNUNET_SERVER_notification_context_broadcast (struct |
444 | const struct GNUNET_MessageHeader *msg, | 432 | GNUNET_SERVER_NotificationContext |
445 | int can_drop) | 433 | *nc, |
434 | const struct GNUNET_MessageHeader | ||
435 | *msg, int can_drop) | ||
446 | { | 436 | { |
447 | struct ClientList *pos; | 437 | struct ClientList *pos; |
448 | 438 | ||
449 | pos = nc->clients; | 439 | pos = nc->clients; |
450 | while (NULL != pos) | 440 | while (NULL != pos) |
451 | { | 441 | { |
452 | do_unicast (nc, pos, msg, can_drop); | 442 | do_unicast (nc, pos, msg, can_drop); |
453 | pos = pos->next; | 443 | pos = pos->next; |
454 | } | 444 | } |
455 | } | 445 | } |
456 | 446 | ||
457 | 447 | ||
diff --git a/src/util/server_tc.c b/src/util/server_tc.c index b7158dadb..eda82e50f 100644 --- a/src/util/server_tc.c +++ b/src/util/server_tc.c | |||
@@ -79,14 +79,15 @@ transmit_response (void *cls, size_t size, void *buf) | |||
79 | { | 79 | { |
80 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 80 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
81 | size_t msize; | 81 | size_t msize; |
82 | |||
82 | if (buf == NULL) | 83 | if (buf == NULL) |
83 | { | 84 | { |
84 | GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); | 85 | GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); |
85 | GNUNET_SERVER_client_drop (tc->client); | 86 | GNUNET_SERVER_client_drop (tc->client); |
86 | GNUNET_free_non_null (tc->buf); | 87 | GNUNET_free_non_null (tc->buf); |
87 | GNUNET_free (tc); | 88 | GNUNET_free (tc); |
88 | return 0; | 89 | return 0; |
89 | } | 90 | } |
90 | if (tc->total - tc->off > size) | 91 | if (tc->total - tc->off > size) |
91 | msize = size; | 92 | msize = size; |
92 | else | 93 | else |
@@ -94,30 +95,29 @@ transmit_response (void *cls, size_t size, void *buf) | |||
94 | memcpy (buf, &tc->buf[tc->off], msize); | 95 | memcpy (buf, &tc->buf[tc->off], msize); |
95 | tc->off += msize; | 96 | tc->off += msize; |
96 | if (tc->total == tc->off) | 97 | if (tc->total == tc->off) |
98 | { | ||
99 | GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); | ||
100 | GNUNET_SERVER_client_drop (tc->client); | ||
101 | GNUNET_free_non_null (tc->buf); | ||
102 | GNUNET_free (tc); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | if (NULL == GNUNET_SERVER_notify_transmit_ready (tc->client, | ||
107 | GNUNET_MIN | ||
108 | (MIN_BLOCK_SIZE, | ||
109 | tc->total - tc->off), | ||
110 | GNUNET_TIME_absolute_get_remaining | ||
111 | (tc->timeout), | ||
112 | &transmit_response, tc)) | ||
97 | { | 113 | { |
98 | GNUNET_SERVER_receive_done (tc->client, GNUNET_OK); | 114 | GNUNET_break (0); |
115 | GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); | ||
99 | GNUNET_SERVER_client_drop (tc->client); | 116 | GNUNET_SERVER_client_drop (tc->client); |
100 | GNUNET_free_non_null (tc->buf); | 117 | GNUNET_free_non_null (tc->buf); |
101 | GNUNET_free (tc); | 118 | GNUNET_free (tc); |
102 | } | 119 | } |
103 | else | 120 | } |
104 | { | ||
105 | if (NULL == GNUNET_SERVER_notify_transmit_ready (tc->client, | ||
106 | GNUNET_MIN | ||
107 | (MIN_BLOCK_SIZE, | ||
108 | tc->total - tc->off), | ||
109 | GNUNET_TIME_absolute_get_remaining | ||
110 | (tc->timeout), | ||
111 | &transmit_response, | ||
112 | tc)) | ||
113 | { | ||
114 | GNUNET_break (0); | ||
115 | GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); | ||
116 | GNUNET_SERVER_client_drop (tc->client); | ||
117 | GNUNET_free_non_null (tc->buf); | ||
118 | GNUNET_free (tc); | ||
119 | } | ||
120 | } | ||
121 | return msize; | 121 | return msize; |
122 | } | 122 | } |
123 | 123 | ||
@@ -154,8 +154,8 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client) | |||
154 | */ | 154 | */ |
155 | void | 155 | void |
156 | GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext | 156 | GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext |
157 | *tc, const void *data, size_t length, | 157 | *tc, const void *data, |
158 | uint16_t type) | 158 | size_t length, uint16_t type) |
159 | { | 159 | { |
160 | struct GNUNET_MessageHeader *msg; | 160 | struct GNUNET_MessageHeader *msg; |
161 | size_t size; | 161 | size_t size; |
@@ -181,8 +181,11 @@ GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext | |||
181 | * @param msg message to append | 181 | * @param msg message to append |
182 | */ | 182 | */ |
183 | void | 183 | void |
184 | GNUNET_SERVER_transmit_context_append_message(struct GNUNET_SERVER_TransmitContext | 184 | GNUNET_SERVER_transmit_context_append_message (struct |
185 | *tc, const struct GNUNET_MessageHeader *msg) | 185 | GNUNET_SERVER_TransmitContext |
186 | *tc, | ||
187 | const struct GNUNET_MessageHeader | ||
188 | *msg) | ||
186 | { | 189 | { |
187 | struct GNUNET_MessageHeader *m; | 190 | struct GNUNET_MessageHeader *m; |
188 | uint16_t size; | 191 | uint16_t size; |
@@ -214,13 +217,13 @@ GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, | |||
214 | GNUNET_MIN (MIN_BLOCK_SIZE, | 217 | GNUNET_MIN (MIN_BLOCK_SIZE, |
215 | tc->total), timeout, | 218 | tc->total), timeout, |
216 | &transmit_response, tc)) | 219 | &transmit_response, tc)) |
217 | { | 220 | { |
218 | GNUNET_break (0); | 221 | GNUNET_break (0); |
219 | GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); | 222 | GNUNET_SERVER_receive_done (tc->client, GNUNET_SYSERR); |
220 | GNUNET_SERVER_client_drop (tc->client); | 223 | GNUNET_SERVER_client_drop (tc->client); |
221 | GNUNET_free_non_null (tc->buf); | 224 | GNUNET_free_non_null (tc->buf); |
222 | GNUNET_free (tc); | 225 | GNUNET_free (tc); |
223 | } | 226 | } |
224 | } | 227 | } |
225 | 228 | ||
226 | /* end of server_tc.c */ | 229 | /* end of server_tc.c */ |
diff --git a/src/util/service.c b/src/util/service.c index ac5ce8d80..308267bd6 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -98,128 +98,123 @@ parse_ipv4_specification (const char *routeList) | |||
98 | i = 0; | 98 | i = 0; |
99 | pos = 0; | 99 | pos = 0; |
100 | while (i < count) | 100 | while (i < count) |
101 | { | ||
102 | cnt = sscanf (&routeList[pos], | ||
103 | "%u.%u.%u.%u/%u.%u.%u.%u;", | ||
104 | &temps[0], | ||
105 | &temps[1], | ||
106 | &temps[2], | ||
107 | &temps[3], &temps[4], &temps[5], &temps[6], &temps[7]); | ||
108 | if (cnt == 8) | ||
101 | { | 109 | { |
102 | cnt = sscanf (&routeList[pos], | 110 | for (j = 0; j < 8; j++) |
103 | "%u.%u.%u.%u/%u.%u.%u.%u;", | 111 | if (temps[j] > 0xFF) |
104 | &temps[0], | ||
105 | &temps[1], | ||
106 | &temps[2], | ||
107 | &temps[3], &temps[4], &temps[5], &temps[6], &temps[7]); | ||
108 | if (cnt == 8) | ||
109 | { | 112 | { |
110 | for (j = 0; j < 8; j++) | 113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
111 | if (temps[j] > 0xFF) | 114 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); |
112 | { | 115 | GNUNET_free (result); |
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 116 | return NULL; |
114 | _("Invalid format for IP: `%s'\n"), | ||
115 | &routeList[pos]); | ||
116 | GNUNET_free (result); | ||
117 | return NULL; | ||
118 | } | ||
119 | result[i].network.s_addr | ||
120 | = | ||
121 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | ||
122 | temps[3]); | ||
123 | result[i].netmask.s_addr = | ||
124 | htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + | ||
125 | temps[7]); | ||
126 | while (routeList[pos] != ';') | ||
127 | pos++; | ||
128 | pos++; | ||
129 | i++; | ||
130 | continue; | ||
131 | } | 117 | } |
132 | /* try second notation */ | 118 | result[i].network.s_addr |
133 | cnt = sscanf (&routeList[pos], | 119 | = |
134 | "%u.%u.%u.%u/%u;", | 120 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + |
135 | &temps[0], &temps[1], &temps[2], &temps[3], &slash); | 121 | temps[3]); |
136 | if (cnt == 5) | 122 | result[i].netmask.s_addr = |
123 | htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) + | ||
124 | temps[7]); | ||
125 | while (routeList[pos] != ';') | ||
126 | pos++; | ||
127 | pos++; | ||
128 | i++; | ||
129 | continue; | ||
130 | } | ||
131 | /* try second notation */ | ||
132 | cnt = sscanf (&routeList[pos], | ||
133 | "%u.%u.%u.%u/%u;", | ||
134 | &temps[0], &temps[1], &temps[2], &temps[3], &slash); | ||
135 | if (cnt == 5) | ||
136 | { | ||
137 | for (j = 0; j < 4; j++) | ||
138 | if (temps[j] > 0xFF) | ||
137 | { | 139 | { |
138 | for (j = 0; j < 4; j++) | 140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
139 | if (temps[j] > 0xFF) | 141 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); |
140 | { | 142 | GNUNET_free (result); |
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 143 | return NULL; |
142 | _("Invalid format for IP: `%s'\n"), | ||
143 | &routeList[pos]); | ||
144 | GNUNET_free (result); | ||
145 | return NULL; | ||
146 | } | ||
147 | result[i].network.s_addr | ||
148 | = | ||
149 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | ||
150 | temps[3]); | ||
151 | if ((slash <= 32) && (slash >= 0)) | ||
152 | { | ||
153 | result[i].netmask.s_addr = 0; | ||
154 | while (slash > 0) | ||
155 | { | ||
156 | result[i].netmask.s_addr | ||
157 | = (result[i].netmask.s_addr >> 1) + 0x80000000; | ||
158 | slash--; | ||
159 | } | ||
160 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); | ||
161 | while (routeList[pos] != ';') | ||
162 | pos++; | ||
163 | pos++; | ||
164 | i++; | ||
165 | continue; | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
170 | _ | ||
171 | ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), | ||
172 | slash); | ||
173 | GNUNET_free (result); | ||
174 | return NULL; /* error */ | ||
175 | } | ||
176 | } | 144 | } |
177 | /* try third notation */ | 145 | result[i].network.s_addr |
178 | slash = 32; | 146 | = |
179 | cnt = sscanf (&routeList[pos], | 147 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + |
180 | "%u.%u.%u.%u;", | 148 | temps[3]); |
181 | &temps[0], &temps[1], &temps[2], &temps[3]); | 149 | if ((slash <= 32) && (slash >= 0)) |
182 | if (cnt == 4) | 150 | { |
151 | result[i].netmask.s_addr = 0; | ||
152 | while (slash > 0) | ||
183 | { | 153 | { |
184 | for (j = 0; j < 4; j++) | 154 | result[i].netmask.s_addr |
185 | if (temps[j] > 0xFF) | 155 | = (result[i].netmask.s_addr >> 1) + 0x80000000; |
186 | { | 156 | slash--; |
187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
188 | _("Invalid format for IP: `%s'\n"), | ||
189 | &routeList[pos]); | ||
190 | GNUNET_free (result); | ||
191 | return NULL; | ||
192 | } | ||
193 | result[i].network.s_addr | ||
194 | = | ||
195 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | ||
196 | temps[3]); | ||
197 | result[i].netmask.s_addr = 0; | ||
198 | while (slash > 0) | ||
199 | { | ||
200 | result[i].netmask.s_addr | ||
201 | = (result[i].netmask.s_addr >> 1) + 0x80000000; | ||
202 | slash--; | ||
203 | } | ||
204 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); | ||
205 | while (routeList[pos] != ';') | ||
206 | pos++; | ||
207 | pos++; | ||
208 | i++; | ||
209 | continue; | ||
210 | } | 157 | } |
211 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 158 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); |
212 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | 159 | while (routeList[pos] != ';') |
213 | GNUNET_free (result); | 160 | pos++; |
214 | return NULL; /* error */ | 161 | pos++; |
162 | i++; | ||
163 | continue; | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
168 | _ | ||
169 | ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."), | ||
170 | slash); | ||
171 | GNUNET_free (result); | ||
172 | return NULL; /* error */ | ||
173 | } | ||
215 | } | 174 | } |
216 | if (pos < strlen (routeList)) | 175 | /* try third notation */ |
176 | slash = 32; | ||
177 | cnt = sscanf (&routeList[pos], | ||
178 | "%u.%u.%u.%u;", &temps[0], &temps[1], &temps[2], &temps[3]); | ||
179 | if (cnt == 4) | ||
217 | { | 180 | { |
218 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 181 | for (j = 0; j < 4; j++) |
219 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | 182 | if (temps[j] > 0xFF) |
220 | GNUNET_free (result); | 183 | { |
221 | return NULL; /* oops */ | 184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | ||
186 | GNUNET_free (result); | ||
187 | return NULL; | ||
188 | } | ||
189 | result[i].network.s_addr | ||
190 | = | ||
191 | htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + | ||
192 | temps[3]); | ||
193 | result[i].netmask.s_addr = 0; | ||
194 | while (slash > 0) | ||
195 | { | ||
196 | result[i].netmask.s_addr = (result[i].netmask.s_addr >> 1) + 0x80000000; | ||
197 | slash--; | ||
198 | } | ||
199 | result[i].netmask.s_addr = htonl (result[i].netmask.s_addr); | ||
200 | while (routeList[pos] != ';') | ||
201 | pos++; | ||
202 | pos++; | ||
203 | i++; | ||
204 | continue; | ||
222 | } | 205 | } |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
207 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | ||
208 | GNUNET_free (result); | ||
209 | return NULL; /* error */ | ||
210 | } | ||
211 | if (pos < strlen (routeList)) | ||
212 | { | ||
213 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
214 | _("Invalid format for IP: `%s'\n"), &routeList[pos]); | ||
215 | GNUNET_free (result); | ||
216 | return NULL; /* oops */ | ||
217 | } | ||
223 | return result; /* ok */ | 218 | return result; /* ok */ |
224 | } | 219 | } |
225 | 220 | ||
@@ -262,88 +257,85 @@ parse_ipv6_specification (const char *routeListX) | |||
262 | if (routeList[i] == ';') | 257 | if (routeList[i] == ';') |
263 | count++; | 258 | count++; |
264 | if (routeList[len - 1] != ';') | 259 | if (routeList[len - 1] != ';') |
265 | { | 260 | { |
266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 261 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
267 | _ | 262 | _ |
268 | ("Invalid network notation (does not end with ';': `%s')\n"), | 263 | ("Invalid network notation (does not end with ';': `%s')\n"), |
269 | routeList); | 264 | routeList); |
270 | GNUNET_free (routeList); | 265 | GNUNET_free (routeList); |
271 | return NULL; | 266 | return NULL; |
272 | } | 267 | } |
273 | 268 | ||
274 | result = GNUNET_malloc (sizeof (struct IPv6NetworkSet) * (count + 1)); | 269 | result = GNUNET_malloc (sizeof (struct IPv6NetworkSet) * (count + 1)); |
275 | memset (result, 0, sizeof (struct IPv6NetworkSet) * (count + 1)); | 270 | memset (result, 0, sizeof (struct IPv6NetworkSet) * (count + 1)); |
276 | i = 0; | 271 | i = 0; |
277 | pos = 0; | 272 | pos = 0; |
278 | while (i < count) | 273 | while (i < count) |
274 | { | ||
275 | start = pos; | ||
276 | while (routeList[pos] != ';') | ||
277 | pos++; | ||
278 | slash = pos; | ||
279 | while ((slash >= start) && (routeList[slash] != '/')) | ||
280 | slash--; | ||
281 | if (slash < start) | ||
279 | { | 282 | { |
280 | start = pos; | 283 | memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr)); |
281 | while (routeList[pos] != ';') | ||
282 | pos++; | ||
283 | slash = pos; | 284 | slash = pos; |
284 | while ((slash >= start) && (routeList[slash] != '/')) | 285 | } |
285 | slash--; | 286 | else |
286 | if (slash < start) | 287 | { |
287 | { | 288 | routeList[pos] = '\0'; |
288 | memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr)); | 289 | ret = inet_pton (AF_INET6, &routeList[slash + 1], &result[i].netmask); |
289 | slash = pos; | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | routeList[pos] = '\0'; | ||
294 | ret = inet_pton (AF_INET6, | ||
295 | &routeList[slash + 1], &result[i].netmask); | ||
296 | if (ret <= 0) | ||
297 | { | ||
298 | save = errno; | ||
299 | if ((1 != SSCANF (&routeList[slash + 1], | ||
300 | "%u", &bits)) || (bits >= 128)) | ||
301 | { | ||
302 | if (ret == 0) | ||
303 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
304 | _("Wrong format `%s' for netmask\n"), | ||
305 | &routeList[slash + 1]); | ||
306 | else | ||
307 | { | ||
308 | errno = save; | ||
309 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
310 | "inet_pton"); | ||
311 | } | ||
312 | GNUNET_free (result); | ||
313 | GNUNET_free (routeList); | ||
314 | return NULL; | ||
315 | } | ||
316 | off = 0; | ||
317 | while (bits > 8) | ||
318 | { | ||
319 | result[i].netmask.s6_addr[off++] = 0xFF; | ||
320 | bits -= 8; | ||
321 | } | ||
322 | while (bits > 0) | ||
323 | { | ||
324 | result[i].netmask.s6_addr[off] | ||
325 | = (result[i].netmask.s6_addr[off] >> 1) + 0x80; | ||
326 | bits--; | ||
327 | } | ||
328 | } | ||
329 | } | ||
330 | routeList[slash] = '\0'; | ||
331 | ret = inet_pton (AF_INET6, &routeList[start], &result[i].network); | ||
332 | if (ret <= 0) | 290 | if (ret <= 0) |
291 | { | ||
292 | save = errno; | ||
293 | if ((1 != SSCANF (&routeList[slash + 1], "%u", &bits)) || (bits >= 128)) | ||
333 | { | 294 | { |
334 | if (ret == 0) | 295 | if (ret == 0) |
335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 296 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
336 | _("Wrong format `%s' for network\n"), | 297 | _("Wrong format `%s' for netmask\n"), |
337 | &routeList[slash + 1]); | 298 | &routeList[slash + 1]); |
338 | else | 299 | else |
339 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "inet_pton"); | 300 | { |
301 | errno = save; | ||
302 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); | ||
303 | } | ||
340 | GNUNET_free (result); | 304 | GNUNET_free (result); |
341 | GNUNET_free (routeList); | 305 | GNUNET_free (routeList); |
342 | return NULL; | 306 | return NULL; |
343 | } | 307 | } |
344 | pos++; | 308 | off = 0; |
345 | i++; | 309 | while (bits > 8) |
310 | { | ||
311 | result[i].netmask.s6_addr[off++] = 0xFF; | ||
312 | bits -= 8; | ||
313 | } | ||
314 | while (bits > 0) | ||
315 | { | ||
316 | result[i].netmask.s6_addr[off] | ||
317 | = (result[i].netmask.s6_addr[off] >> 1) + 0x80; | ||
318 | bits--; | ||
319 | } | ||
320 | } | ||
321 | } | ||
322 | routeList[slash] = '\0'; | ||
323 | ret = inet_pton (AF_INET6, &routeList[start], &result[i].network); | ||
324 | if (ret <= 0) | ||
325 | { | ||
326 | if (ret == 0) | ||
327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
328 | _("Wrong format `%s' for network\n"), | ||
329 | &routeList[slash + 1]); | ||
330 | else | ||
331 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "inet_pton"); | ||
332 | GNUNET_free (result); | ||
333 | GNUNET_free (routeList); | ||
334 | return NULL; | ||
346 | } | 335 | } |
336 | pos++; | ||
337 | i++; | ||
338 | } | ||
347 | GNUNET_free (routeList); | 339 | GNUNET_free (routeList); |
348 | return result; | 340 | return result; |
349 | } | 341 | } |
@@ -357,8 +349,7 @@ parse_ipv6_specification (const char *routeListX) | |||
357 | * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is | 349 | * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is |
358 | */ | 350 | */ |
359 | static int | 351 | static int |
360 | check_ipv4_listed (const struct IPv4NetworkSet *list, | 352 | check_ipv4_listed (const struct IPv4NetworkSet *list, const struct in_addr *add) |
361 | const struct in_addr *add) | ||
362 | { | 353 | { |
363 | int i; | 354 | int i; |
364 | 355 | ||
@@ -367,12 +358,12 @@ check_ipv4_listed (const struct IPv4NetworkSet *list, | |||
367 | return GNUNET_NO; | 358 | return GNUNET_NO; |
368 | 359 | ||
369 | while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) | 360 | while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0)) |
370 | { | 361 | { |
371 | if ((add->s_addr & list[i].netmask.s_addr) == | 362 | if ((add->s_addr & list[i].netmask.s_addr) == |
372 | (list[i].network.s_addr & list[i].netmask.s_addr)) | 363 | (list[i].network.s_addr & list[i].netmask.s_addr)) |
373 | return GNUNET_YES; | 364 | return GNUNET_YES; |
374 | i++; | 365 | i++; |
375 | } | 366 | } |
376 | return GNUNET_NO; | 367 | return GNUNET_NO; |
377 | } | 368 | } |
378 | 369 | ||
@@ -384,8 +375,7 @@ check_ipv4_listed (const struct IPv4NetworkSet *list, | |||
384 | * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is | 375 | * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is |
385 | */ | 376 | */ |
386 | static int | 377 | static int |
387 | check_ipv6_listed (const struct IPv6NetworkSet *list, | 378 | check_ipv6_listed (const struct IPv6NetworkSet *list, const struct in6_addr *ip) |
388 | const struct in6_addr *ip) | ||
389 | { | 379 | { |
390 | unsigned int i; | 380 | unsigned int i; |
391 | unsigned int j; | 381 | unsigned int j; |
@@ -398,16 +388,16 @@ check_ipv6_listed (const struct IPv6NetworkSet *list, | |||
398 | i = 0; | 388 | i = 0; |
399 | NEXT: | 389 | NEXT: |
400 | while (memcmp (&zero, &list[i].network, sizeof (struct in6_addr)) != 0) | 390 | while (memcmp (&zero, &list[i].network, sizeof (struct in6_addr)) != 0) |
401 | { | 391 | { |
402 | for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) | 392 | for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) |
403 | if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != | 393 | if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != |
404 | (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) | 394 | (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) |
405 | { | 395 | { |
406 | i++; | 396 | i++; |
407 | goto NEXT; | 397 | goto NEXT; |
408 | } | 398 | } |
409 | return GNUNET_YES; | 399 | return GNUNET_YES; |
410 | } | 400 | } |
411 | return GNUNET_NO; | 401 | return GNUNET_NO; |
412 | } | 402 | } |
413 | 403 | ||
@@ -482,7 +472,7 @@ struct GNUNET_SERVICE_Context | |||
482 | /** | 472 | /** |
483 | * Array of the lengths of the entries in addrs. | 473 | * Array of the lengths of the entries in addrs. |
484 | */ | 474 | */ |
485 | socklen_t * addrlens; | 475 | socklen_t *addrlens; |
486 | 476 | ||
487 | /** | 477 | /** |
488 | * NULL-terminated array of listen sockets we should take over. | 478 | * NULL-terminated array of listen sockets we should take over. |
@@ -541,10 +531,10 @@ write_test (void *cls, size_t size, void *buf) | |||
541 | struct GNUNET_MessageHeader *msg; | 531 | struct GNUNET_MessageHeader *msg; |
542 | 532 | ||
543 | if (size < sizeof (struct GNUNET_MessageHeader)) | 533 | if (size < sizeof (struct GNUNET_MessageHeader)) |
544 | { | 534 | { |
545 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 535 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
546 | return 0; /* client disconnected */ | 536 | return 0; /* client disconnected */ |
547 | } | 537 | } |
548 | msg = (struct GNUNET_MessageHeader *) buf; | 538 | msg = (struct GNUNET_MessageHeader *) buf; |
549 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); | 539 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); |
550 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 540 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -601,9 +591,9 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { | |||
601 | * for unknown address family (will be denied). | 591 | * for unknown address family (will be denied). |
602 | */ | 592 | */ |
603 | static int | 593 | static int |
604 | check_access (void *cls, | 594 | check_access (void *cls, |
605 | const struct GNUNET_CONNECTION_Credentials *uc, | 595 | const struct GNUNET_CONNECTION_Credentials *uc, |
606 | const struct sockaddr *addr, socklen_t addrlen) | 596 | const struct sockaddr *addr, socklen_t addrlen) |
607 | { | 597 | { |
608 | struct GNUNET_SERVICE_Context *sctx = cls; | 598 | struct GNUNET_SERVICE_Context *sctx = cls; |
609 | const struct sockaddr_in *i4; | 599 | const struct sockaddr_in *i4; |
@@ -611,57 +601,54 @@ check_access (void *cls, | |||
611 | int ret; | 601 | int ret; |
612 | 602 | ||
613 | switch (addr->sa_family) | 603 | switch (addr->sa_family) |
614 | { | 604 | { |
615 | case AF_INET: | 605 | case AF_INET: |
616 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 606 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); |
617 | i4 = (const struct sockaddr_in *) addr; | 607 | i4 = (const struct sockaddr_in *) addr; |
618 | ret = ((sctx->v4_allowed == NULL) || | 608 | ret = ((sctx->v4_allowed == NULL) || |
619 | (check_ipv4_listed (sctx->v4_allowed, | 609 | (check_ipv4_listed (sctx->v4_allowed, |
620 | &i4->sin_addr))) | 610 | &i4->sin_addr))) |
621 | && ((sctx->v4_denied == NULL) || | 611 | && ((sctx->v4_denied == NULL) || |
622 | (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); | 612 | (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); |
623 | break; | 613 | break; |
624 | case AF_INET6: | 614 | case AF_INET6: |
625 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 615 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
626 | i6 = (const struct sockaddr_in6 *) addr; | 616 | i6 = (const struct sockaddr_in6 *) addr; |
627 | ret = ((sctx->v6_allowed == NULL) || | 617 | ret = ((sctx->v6_allowed == NULL) || |
628 | (check_ipv6_listed (sctx->v6_allowed, | 618 | (check_ipv6_listed (sctx->v6_allowed, |
629 | &i6->sin6_addr))) | 619 | &i6->sin6_addr))) |
630 | && ((sctx->v6_denied == NULL) || | 620 | && ((sctx->v6_denied == NULL) || |
631 | (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); | 621 | (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); |
632 | break; | 622 | break; |
633 | #ifndef WINDOWS | 623 | #ifndef WINDOWS |
634 | case AF_UNIX: | 624 | case AF_UNIX: |
635 | ret = GNUNET_OK; /* always OK for now */ | 625 | ret = GNUNET_OK; /* always OK for now */ |
636 | if ( (sctx->match_uid == GNUNET_YES) || | 626 | if ((sctx->match_uid == GNUNET_YES) || (sctx->match_gid == GNUNET_YES)) |
637 | (sctx->match_gid == GNUNET_YES) ) | 627 | ret = GNUNET_NO; |
638 | ret = GNUNET_NO; | 628 | if ((uc != NULL) && |
639 | if ( (uc != NULL) && | 629 | ((sctx->match_uid != GNUNET_YES) || |
640 | ( (sctx->match_uid != GNUNET_YES) || | 630 | (uc->uid == geteuid ()) || |
641 | (uc->uid == geteuid()) || | 631 | (uc->uid == getuid ())) && |
642 | (uc->uid == getuid()) ) && | 632 | ((sctx->match_gid != GNUNET_YES) || |
643 | ( (sctx->match_gid != GNUNET_YES) || | 633 | (uc->gid == getegid ()) || (uc->gid == getgid ()))) |
644 | (uc->gid == getegid()) || | 634 | ret = GNUNET_YES; |
645 | (uc->gid == getgid())) ) | 635 | else |
646 | ret = GNUNET_YES; | ||
647 | else | ||
648 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
649 | _("Access denied to UID %d / GID %d\n"), | ||
650 | (uc == NULL) ? -1 : uc->uid, | ||
651 | (uc == NULL) ? -1 : uc->gid); | ||
652 | break; | ||
653 | #endif | ||
654 | default: | ||
655 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 636 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
656 | _("Unknown address family %d\n"), addr->sa_family); | 637 | _("Access denied to UID %d / GID %d\n"), |
657 | return GNUNET_SYSERR; | 638 | (uc == NULL) ? -1 : uc->uid, (uc == NULL) ? -1 : uc->gid); |
658 | } | 639 | break; |
640 | #endif | ||
641 | default: | ||
642 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
643 | _("Unknown address family %d\n"), addr->sa_family); | ||
644 | return GNUNET_SYSERR; | ||
645 | } | ||
659 | if (ret != GNUNET_OK) | 646 | if (ret != GNUNET_OK) |
660 | { | 647 | { |
661 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 648 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
662 | _("Access from `%s' denied to service `%s'\n"), | 649 | _("Access from `%s' denied to service `%s'\n"), |
663 | GNUNET_a2s (addr, addrlen), sctx->serviceName); | 650 | GNUNET_a2s (addr, addrlen), sctx->serviceName); |
664 | } | 651 | } |
665 | return ret; | 652 | return ret; |
666 | } | 653 | } |
667 | 654 | ||
@@ -701,14 +688,14 @@ process_acl4 (struct IPv4NetworkSet **ret, | |||
701 | sctx->serviceName, | 688 | sctx->serviceName, |
702 | option, &opt)); | 689 | option, &opt)); |
703 | if (NULL == (*ret = parse_ipv4_specification (opt))) | 690 | if (NULL == (*ret = parse_ipv4_specification (opt))) |
704 | { | 691 | { |
705 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 692 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
706 | _ | 693 | _ |
707 | ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), | 694 | ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), |
708 | opt, sctx->serviceName, option); | 695 | opt, sctx->serviceName, option); |
709 | GNUNET_free (opt); | 696 | GNUNET_free (opt); |
710 | return GNUNET_SYSERR; | 697 | return GNUNET_SYSERR; |
711 | } | 698 | } |
712 | GNUNET_free (opt); | 699 | GNUNET_free (opt); |
713 | return GNUNET_OK; | 700 | return GNUNET_OK; |
714 | } | 701 | } |
@@ -722,6 +709,7 @@ process_acl6 (struct IPv6NetworkSet **ret, | |||
722 | struct GNUNET_SERVICE_Context *sctx, const char *option) | 709 | struct GNUNET_SERVICE_Context *sctx, const char *option) |
723 | { | 710 | { |
724 | char *opt; | 711 | char *opt; |
712 | |||
725 | if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option)) | 713 | if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, option)) |
726 | return GNUNET_OK; | 714 | return GNUNET_OK; |
727 | GNUNET_break (GNUNET_OK == | 715 | GNUNET_break (GNUNET_OK == |
@@ -729,14 +717,14 @@ process_acl6 (struct IPv6NetworkSet **ret, | |||
729 | sctx->serviceName, | 717 | sctx->serviceName, |
730 | option, &opt)); | 718 | option, &opt)); |
731 | if (NULL == (*ret = parse_ipv6_specification (opt))) | 719 | if (NULL == (*ret = parse_ipv6_specification (opt))) |
732 | { | 720 | { |
733 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 721 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
734 | _ | 722 | _ |
735 | ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), | 723 | ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), |
736 | opt, sctx->serviceName, option); | 724 | opt, sctx->serviceName, option); |
737 | GNUNET_free (opt); | 725 | GNUNET_free (opt); |
738 | return GNUNET_SYSERR; | 726 | return GNUNET_SYSERR; |
739 | } | 727 | } |
740 | GNUNET_free (opt); | 728 | GNUNET_free (opt); |
741 | return GNUNET_OK; | 729 | return GNUNET_OK; |
742 | } | 730 | } |
@@ -751,10 +739,9 @@ process_acl6 (struct IPv6NetworkSet **ret, | |||
751 | */ | 739 | */ |
752 | static void | 740 | static void |
753 | add_unixpath (struct sockaddr **saddrs, | 741 | add_unixpath (struct sockaddr **saddrs, |
754 | socklen_t *saddrlens, | 742 | socklen_t * saddrlens, const char *unixpath) |
755 | const char *unixpath) | ||
756 | { | 743 | { |
757 | #ifdef AF_UNIX | 744 | #ifdef AF_UNIX |
758 | struct sockaddr_un *un; | 745 | struct sockaddr_un *un; |
759 | size_t slen; | 746 | size_t slen; |
760 | 747 | ||
@@ -763,9 +750,7 @@ add_unixpath (struct sockaddr **saddrs, | |||
763 | slen = strlen (unixpath) + 1; | 750 | slen = strlen (unixpath) + 1; |
764 | if (slen >= sizeof (un->sun_path)) | 751 | if (slen >= sizeof (un->sun_path)) |
765 | slen = sizeof (un->sun_path) - 1; | 752 | slen = sizeof (un->sun_path) - 1; |
766 | memcpy (un->sun_path, | 753 | memcpy (un->sun_path, unixpath, slen); |
767 | unixpath, | ||
768 | slen); | ||
769 | un->sun_path[slen] = '\0'; | 754 | un->sun_path[slen] = '\0'; |
770 | slen = sizeof (struct sockaddr_un); | 755 | slen = sizeof (struct sockaddr_un); |
771 | #if LINUX | 756 | #if LINUX |
@@ -774,11 +759,11 @@ add_unixpath (struct sockaddr **saddrs, | |||
774 | #if HAVE_SOCKADDR_IN_SIN_LEN | 759 | #if HAVE_SOCKADDR_IN_SIN_LEN |
775 | un->sun_len = (u_char) slen; | 760 | un->sun_len = (u_char) slen; |
776 | #endif | 761 | #endif |
777 | *saddrs = (struct sockaddr*) un; | 762 | *saddrs = (struct sockaddr *) un; |
778 | *saddrlens = slen; | 763 | *saddrlens = slen; |
779 | #else | 764 | #else |
780 | /* this function should never be called | 765 | /* this function should never be called |
781 | unless AF_UNIX is defined! */ | 766 | * unless AF_UNIX is defined! */ |
782 | GNUNET_assert (0); | 767 | GNUNET_assert (0); |
783 | #endif | 768 | #endif |
784 | } | 769 | } |
@@ -806,9 +791,9 @@ add_unixpath (struct sockaddr **saddrs, | |||
806 | */ | 791 | */ |
807 | int | 792 | int |
808 | GNUNET_SERVICE_get_server_addresses (const char *serviceName, | 793 | GNUNET_SERVICE_get_server_addresses (const char *serviceName, |
809 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 794 | const struct GNUNET_CONFIGURATION_Handle |
810 | struct sockaddr ***addrs, | 795 | *cfg, struct sockaddr ***addrs, |
811 | socklen_t **addr_lens) | 796 | socklen_t ** addr_lens) |
812 | { | 797 | { |
813 | int disablev6; | 798 | int disablev6; |
814 | struct GNUNET_NETWORK_Handle *desc; | 799 | struct GNUNET_NETWORK_Handle *desc; |
@@ -828,292 +813,282 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName, | |||
828 | *addrs = NULL; | 813 | *addrs = NULL; |
829 | *addr_lens = NULL; | 814 | *addr_lens = NULL; |
830 | desc = NULL; | 815 | desc = NULL; |
831 | if (GNUNET_CONFIGURATION_have_value (cfg, | 816 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "DISABLEV6")) |
832 | serviceName, "DISABLEV6")) | 817 | { |
833 | { | 818 | if (GNUNET_SYSERR == |
834 | if (GNUNET_SYSERR == | 819 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
835 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 820 | serviceName, |
836 | serviceName, | 821 | "DISABLEV6"))) |
837 | "DISABLEV6"))) | 822 | return GNUNET_SYSERR; |
838 | return GNUNET_SYSERR; | 823 | } |
839 | } | ||
840 | else | 824 | else |
841 | disablev6 = GNUNET_NO; | 825 | disablev6 = GNUNET_NO; |
842 | 826 | ||
843 | if (!disablev6) | 827 | if (!disablev6) |
828 | { | ||
829 | /* probe IPv6 support */ | ||
830 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | ||
831 | if (NULL == desc) | ||
844 | { | 832 | { |
845 | /* probe IPv6 support */ | 833 | if ((errno == ENOBUFS) || |
846 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | 834 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) |
847 | if (NULL == desc) | 835 | { |
848 | { | 836 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
849 | if ((errno == ENOBUFS) || | 837 | return GNUNET_SYSERR; |
850 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | 838 | } |
851 | { | 839 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
852 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 840 | _ |
853 | return GNUNET_SYSERR; | 841 | ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), |
854 | } | 842 | serviceName, STRERROR (errno)); |
855 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 843 | disablev6 = GNUNET_YES; |
856 | _ | ||
857 | ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
858 | serviceName, STRERROR (errno)); | ||
859 | disablev6 = GNUNET_YES; | ||
860 | } | ||
861 | else | ||
862 | { | ||
863 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | ||
864 | desc = NULL; | ||
865 | } | ||
866 | } | 844 | } |
867 | 845 | else | |
868 | port = 0; | ||
869 | if (GNUNET_CONFIGURATION_have_value (cfg, | ||
870 | serviceName, "PORT")) | ||
871 | { | 846 | { |
872 | GNUNET_break (GNUNET_OK == | 847 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); |
873 | GNUNET_CONFIGURATION_get_value_number (cfg, | 848 | desc = NULL; |
874 | serviceName, | ||
875 | "PORT", | ||
876 | &port)); | ||
877 | if (port > 65535) | ||
878 | { | ||
879 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
880 | _ | ||
881 | ("Require valid port number for service `%s' in configuration!\n"), | ||
882 | serviceName); | ||
883 | return GNUNET_SYSERR; | ||
884 | } | ||
885 | } | 849 | } |
850 | } | ||
886 | 851 | ||
887 | if (GNUNET_CONFIGURATION_have_value (cfg, | 852 | port = 0; |
888 | serviceName, "BINDTO")) | 853 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT")) |
854 | { | ||
855 | GNUNET_break (GNUNET_OK == | ||
856 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
857 | serviceName, | ||
858 | "PORT", &port)); | ||
859 | if (port > 65535) | ||
889 | { | 860 | { |
890 | GNUNET_break (GNUNET_OK == | 861 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
891 | GNUNET_CONFIGURATION_get_value_string (cfg, | 862 | _ |
892 | serviceName, | 863 | ("Require valid port number for service `%s' in configuration!\n"), |
893 | "BINDTO", | 864 | serviceName); |
894 | &hostname)); | 865 | return GNUNET_SYSERR; |
895 | } | 866 | } |
867 | } | ||
868 | |||
869 | if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO")) | ||
870 | { | ||
871 | GNUNET_break (GNUNET_OK == | ||
872 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
873 | serviceName, | ||
874 | "BINDTO", &hostname)); | ||
875 | } | ||
896 | else | 876 | else |
897 | hostname = NULL; | 877 | hostname = NULL; |
898 | 878 | ||
899 | unixpath = NULL; | 879 | unixpath = NULL; |
900 | #ifdef AF_UNIX | 880 | #ifdef AF_UNIX |
901 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, | 881 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, |
902 | serviceName, "UNIXPATH")) && | 882 | serviceName, "UNIXPATH")) |
903 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | 883 | && (GNUNET_OK == |
904 | serviceName, | 884 | GNUNET_CONFIGURATION_get_value_string (cfg, serviceName, "UNIXPATH", |
905 | "UNIXPATH", | 885 | &unixpath)) && |
906 | &unixpath)) && | 886 | (0 < strlen (unixpath))) |
907 | (0 < strlen(unixpath))) | 887 | { |
888 | /* probe UNIX support */ | ||
889 | struct sockaddr_un s_un; | ||
890 | |||
891 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) | ||
908 | { | 892 | { |
909 | /* probe UNIX support */ | 893 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
910 | struct sockaddr_un s_un; | 894 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), |
911 | 895 | unixpath, sizeof (s_un.sun_path)); | |
912 | if (strlen(unixpath) >= sizeof(s_un.sun_path)) | 896 | GNUNET_free_non_null (hostname); |
913 | { | 897 | GNUNET_free (unixpath); |
914 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 898 | return GNUNET_SYSERR; |
915 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), | ||
916 | unixpath, | ||
917 | sizeof(s_un.sun_path)); | ||
918 | GNUNET_free_non_null (hostname); | ||
919 | GNUNET_free (unixpath); | ||
920 | return GNUNET_SYSERR; | ||
921 | } | ||
922 | |||
923 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | ||
924 | if (NULL == desc) | ||
925 | { | ||
926 | if ( (errno == ENOBUFS) || | ||
927 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | ||
928 | { | ||
929 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
930 | GNUNET_free_non_null (hostname); | ||
931 | GNUNET_free (unixpath); | ||
932 | return GNUNET_SYSERR; | ||
933 | } | ||
934 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
935 | _ | ||
936 | ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
937 | serviceName, STRERROR (errno)); | ||
938 | GNUNET_free (unixpath); | ||
939 | unixpath = NULL; | ||
940 | } | ||
941 | else | ||
942 | { | ||
943 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | ||
944 | desc = NULL; | ||
945 | } | ||
946 | } | 899 | } |
900 | |||
901 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | ||
902 | if (NULL == desc) | ||
903 | { | ||
904 | if ((errno == ENOBUFS) || | ||
905 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | ||
906 | { | ||
907 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
908 | GNUNET_free_non_null (hostname); | ||
909 | GNUNET_free (unixpath); | ||
910 | return GNUNET_SYSERR; | ||
911 | } | ||
912 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
913 | _ | ||
914 | ("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
915 | serviceName, STRERROR (errno)); | ||
916 | GNUNET_free (unixpath); | ||
917 | unixpath = NULL; | ||
918 | } | ||
919 | else | ||
920 | { | ||
921 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | ||
922 | desc = NULL; | ||
923 | } | ||
924 | } | ||
947 | #endif | 925 | #endif |
948 | 926 | ||
949 | if ( (port == 0) && | 927 | if ((port == 0) && (unixpath == NULL)) |
950 | (unixpath == NULL) ) | 928 | { |
929 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
930 | _ | ||
931 | ("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | ||
932 | serviceName); | ||
933 | GNUNET_free_non_null (hostname); | ||
934 | return GNUNET_SYSERR; | ||
935 | } | ||
936 | if (port == 0) | ||
937 | { | ||
938 | saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); | ||
939 | saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); | ||
940 | add_unixpath (saddrs, saddrlens, unixpath); | ||
941 | GNUNET_free_non_null (unixpath); | ||
942 | GNUNET_free_non_null (hostname); | ||
943 | *addrs = saddrs; | ||
944 | *addr_lens = saddrlens; | ||
945 | return 1; | ||
946 | } | ||
947 | |||
948 | if (hostname != NULL) | ||
949 | { | ||
950 | #if DEBUG_SERVICE | ||
951 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
952 | "Resolving `%s' since that is where `%s' will bind to.\n", | ||
953 | hostname, serviceName); | ||
954 | #endif | ||
955 | memset (&hints, 0, sizeof (struct addrinfo)); | ||
956 | if (disablev6) | ||
957 | hints.ai_family = AF_INET; | ||
958 | if ((0 != (ret = getaddrinfo (hostname, | ||
959 | NULL, &hints, &res))) || (res == NULL)) | ||
951 | { | 960 | { |
952 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 961 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
953 | _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | 962 | _("Failed to resolve `%s': %s\n"), |
954 | serviceName); | 963 | hostname, gai_strerror (ret)); |
955 | GNUNET_free_non_null(hostname); | 964 | GNUNET_free (hostname); |
965 | GNUNET_free_non_null (unixpath); | ||
956 | return GNUNET_SYSERR; | 966 | return GNUNET_SYSERR; |
957 | } | 967 | } |
958 | if (port == 0) | 968 | next = res; |
969 | i = 0; | ||
970 | while (NULL != (pos = next)) | ||
959 | { | 971 | { |
960 | saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr*)); | 972 | next = pos->ai_next; |
961 | saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); | 973 | if ((disablev6) && (pos->ai_family == AF_INET6)) |
962 | add_unixpath (saddrs, saddrlens, unixpath); | 974 | continue; |
975 | i++; | ||
976 | } | ||
977 | if (0 == i) | ||
978 | { | ||
979 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
980 | _("Failed to find %saddress for `%s'.\n"), | ||
981 | disablev6 ? "IPv4 " : "", hostname); | ||
982 | freeaddrinfo (res); | ||
983 | GNUNET_free (hostname); | ||
963 | GNUNET_free_non_null (unixpath); | 984 | GNUNET_free_non_null (unixpath); |
964 | GNUNET_free_non_null (hostname); | 985 | return GNUNET_SYSERR; |
965 | *addrs = saddrs; | ||
966 | *addr_lens = saddrlens; | ||
967 | return 1; | ||
968 | } | 986 | } |
969 | 987 | resi = i; | |
970 | if (hostname != NULL) | 988 | if (NULL != unixpath) |
989 | resi++; | ||
990 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | ||
991 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | ||
992 | i = 0; | ||
993 | if (NULL != unixpath) | ||
994 | { | ||
995 | add_unixpath (saddrs, saddrlens, unixpath); | ||
996 | i++; | ||
997 | } | ||
998 | next = res; | ||
999 | while (NULL != (pos = next)) | ||
971 | { | 1000 | { |
1001 | next = pos->ai_next; | ||
1002 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
1003 | continue; | ||
1004 | if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0)) | ||
1005 | continue; /* not TCP */ | ||
1006 | if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0)) | ||
1007 | continue; /* huh? */ | ||
972 | #if DEBUG_SERVICE | 1008 | #if DEBUG_SERVICE |
973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
974 | "Resolving `%s' since that is where `%s' will bind to.\n", | 1010 | "Service `%s' will bind to `%s'\n", |
975 | hostname, | 1011 | serviceName, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); |
976 | serviceName); | ||
977 | #endif | 1012 | #endif |
978 | memset (&hints, 0, sizeof (struct addrinfo)); | 1013 | if (pos->ai_family == AF_INET) |
979 | if (disablev6) | 1014 | { |
980 | hints.ai_family = AF_INET; | 1015 | GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); |
981 | if ((0 != (ret = getaddrinfo (hostname, | 1016 | saddrlens[i] = pos->ai_addrlen; |
982 | NULL, &hints, &res))) || (res == NULL)) | 1017 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
983 | { | 1018 | memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); |
984 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1019 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); |
985 | _("Failed to resolve `%s': %s\n"), | 1020 | } |
986 | hostname, gai_strerror (ret)); | 1021 | else |
987 | GNUNET_free (hostname); | 1022 | { |
988 | GNUNET_free_non_null (unixpath); | 1023 | GNUNET_assert (pos->ai_family == AF_INET6); |
989 | return GNUNET_SYSERR; | 1024 | GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); |
990 | } | 1025 | saddrlens[i] = pos->ai_addrlen; |
991 | next = res; | 1026 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
992 | i = 0; | 1027 | memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); |
993 | while (NULL != (pos = next)) | 1028 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); |
994 | { | 1029 | } |
995 | next = pos->ai_next; | 1030 | i++; |
996 | if ( (disablev6) && (pos->ai_family == AF_INET6)) | 1031 | } |
997 | continue; | 1032 | GNUNET_free (hostname); |
998 | i++; | 1033 | freeaddrinfo (res); |
999 | } | 1034 | resi = i; |
1000 | if (0 == i) | 1035 | } |
1001 | { | 1036 | else |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1037 | { |
1003 | _("Failed to find %saddress for `%s'.\n"), | 1038 | /* will bind against everything, just set port */ |
1004 | disablev6 ? "IPv4 " : "", hostname); | 1039 | if (disablev6) |
1005 | freeaddrinfo (res); | 1040 | { |
1006 | GNUNET_free (hostname); | 1041 | /* V4-only */ |
1007 | GNUNET_free_non_null (unixpath); | 1042 | resi = 1; |
1008 | return GNUNET_SYSERR; | ||
1009 | } | ||
1010 | resi = i; | ||
1011 | if (NULL != unixpath) | 1043 | if (NULL != unixpath) |
1012 | resi++; | 1044 | resi++; |
1013 | saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*)); | ||
1014 | saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t)); | ||
1015 | i = 0; | 1045 | i = 0; |
1046 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | ||
1047 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | ||
1016 | if (NULL != unixpath) | 1048 | if (NULL != unixpath) |
1017 | { | 1049 | { |
1018 | add_unixpath (saddrs, saddrlens, unixpath); | 1050 | add_unixpath (saddrs, saddrlens, unixpath); |
1019 | i++; | 1051 | i++; |
1020 | } | 1052 | } |
1021 | next = res; | 1053 | saddrlens[i] = sizeof (struct sockaddr_in); |
1022 | while (NULL != (pos = next)) | 1054 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1023 | { | 1055 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1024 | next = pos->ai_next; | 1056 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; |
1025 | if ( (disablev6) && (pos->ai_family == AF_INET6)) | ||
1026 | continue; | ||
1027 | if ( (pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0) ) | ||
1028 | continue; /* not TCP */ | ||
1029 | if ( (pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0) ) | ||
1030 | continue; /* huh? */ | ||
1031 | #if DEBUG_SERVICE | ||
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1033 | "Service `%s' will bind to `%s'\n", | ||
1034 | serviceName, | ||
1035 | GNUNET_a2s (pos->ai_addr, | ||
1036 | pos->ai_addrlen)); | ||
1037 | #endif | 1057 | #endif |
1038 | if (pos->ai_family == AF_INET) | 1058 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; |
1039 | { | 1059 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); |
1040 | GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); | ||
1041 | saddrlens[i] = pos->ai_addrlen; | ||
1042 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
1043 | memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
1044 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | ||
1045 | } | ||
1046 | else | ||
1047 | { | ||
1048 | GNUNET_assert (pos->ai_family == AF_INET6); | ||
1049 | GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); | ||
1050 | saddrlens[i] = pos->ai_addrlen; | ||
1051 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
1052 | memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
1053 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | ||
1054 | } | ||
1055 | i++; | ||
1056 | } | ||
1057 | GNUNET_free (hostname); | ||
1058 | freeaddrinfo (res); | ||
1059 | resi = i; | ||
1060 | } | 1060 | } |
1061 | else | 1061 | else |
1062 | { | 1062 | { |
1063 | /* will bind against everything, just set port */ | 1063 | /* dual stack */ |
1064 | if (disablev6) | 1064 | resi = 2; |
1065 | { | 1065 | if (NULL != unixpath) |
1066 | /* V4-only */ | 1066 | resi++; |
1067 | resi = 1; | 1067 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); |
1068 | if (NULL != unixpath) | 1068 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); |
1069 | resi++; | 1069 | i = 0; |
1070 | i = 0; | 1070 | if (NULL != unixpath) |
1071 | saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*)); | 1071 | { |
1072 | saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t)); | 1072 | add_unixpath (saddrs, saddrlens, unixpath); |
1073 | if (NULL != unixpath) | 1073 | i++; |
1074 | { | 1074 | } |
1075 | add_unixpath (saddrs, saddrlens, unixpath); | 1075 | saddrlens[i] = sizeof (struct sockaddr_in6); |
1076 | i++; | 1076 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1077 | } | ||
1078 | saddrlens[i] = sizeof (struct sockaddr_in); | ||
1079 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
1080 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1081 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; | ||
1082 | #endif | ||
1083 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | ||
1084 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | ||
1085 | } | ||
1086 | else | ||
1087 | { | ||
1088 | /* dual stack */ | ||
1089 | resi = 2; | ||
1090 | if (NULL != unixpath) | ||
1091 | resi++; | ||
1092 | saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*)); | ||
1093 | saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t)); | ||
1094 | i = 0; | ||
1095 | if (NULL != unixpath) | ||
1096 | { | ||
1097 | add_unixpath (saddrs, saddrlens, unixpath); | ||
1098 | i++; | ||
1099 | } | ||
1100 | saddrlens[i] = sizeof (struct sockaddr_in6); | ||
1101 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
1102 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1077 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1103 | ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; | 1078 | ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; |
1104 | #endif | 1079 | #endif |
1105 | ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; | 1080 | ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; |
1106 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | 1081 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); |
1107 | i++; | 1082 | i++; |
1108 | saddrlens[i] = sizeof (struct sockaddr_in); | 1083 | saddrlens[i] = sizeof (struct sockaddr_in); |
1109 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 1084 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1110 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1085 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1111 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; | 1086 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; |
1112 | #endif | 1087 | #endif |
1113 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 1088 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; |
1114 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 1089 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); |
1115 | } | ||
1116 | } | 1090 | } |
1091 | } | ||
1117 | GNUNET_free_non_null (unixpath); | 1092 | GNUNET_free_non_null (unixpath); |
1118 | *addrs = saddrs; | 1093 | *addrs = saddrs; |
1119 | *addr_lens = saddrlens; | 1094 | *addr_lens = saddrlens; |
@@ -1143,6 +1118,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
1143 | { | 1118 | { |
1144 | struct GNUNET_TIME_Relative idleout; | 1119 | struct GNUNET_TIME_Relative idleout; |
1145 | int tolerant; | 1120 | int tolerant; |
1121 | |||
1146 | #ifndef MINGW | 1122 | #ifndef MINGW |
1147 | const char *lpid; | 1123 | const char *lpid; |
1148 | unsigned int pid; | 1124 | unsigned int pid; |
@@ -1151,92 +1127,89 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) | |||
1151 | int flags; | 1127 | int flags; |
1152 | #endif | 1128 | #endif |
1153 | 1129 | ||
1154 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, | 1130 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TIMEOUT")) |
1155 | sctx->serviceName, "TIMEOUT")) | 1131 | { |
1132 | if (GNUNET_OK != | ||
1133 | GNUNET_CONFIGURATION_get_value_time (sctx->cfg, | ||
1134 | sctx->serviceName, | ||
1135 | "TIMEOUT", &idleout)) | ||
1156 | { | 1136 | { |
1157 | if (GNUNET_OK != | 1137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1158 | GNUNET_CONFIGURATION_get_value_time (sctx->cfg, | 1138 | _("Specified value for `%s' of service `%s' is invalid\n"), |
1159 | sctx->serviceName, | 1139 | "TIMEOUT", sctx->serviceName); |
1160 | "TIMEOUT", &idleout)) | 1140 | return GNUNET_SYSERR; |
1161 | { | ||
1162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1163 | _("Specified value for `%s' of service `%s' is invalid\n"), | ||
1164 | "TIMEOUT", | ||
1165 | sctx->serviceName); | ||
1166 | return GNUNET_SYSERR; | ||
1167 | } | ||
1168 | sctx->timeout = idleout; | ||
1169 | } | 1141 | } |
1142 | sctx->timeout = idleout; | ||
1143 | } | ||
1170 | else | 1144 | else |
1171 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1145 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1172 | 1146 | ||
1173 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, | 1147 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, |
1174 | sctx->serviceName, "TOLERANT")) | 1148 | sctx->serviceName, "TOLERANT")) |
1149 | { | ||
1150 | if (GNUNET_SYSERR == | ||
1151 | (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | ||
1152 | sctx->serviceName, | ||
1153 | "TOLERANT"))) | ||
1175 | { | 1154 | { |
1176 | if (GNUNET_SYSERR == | 1155 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1177 | (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1156 | _("Specified value for `%s' of service `%s' is invalid\n"), |
1178 | sctx->serviceName, | 1157 | "TOLERANT", sctx->serviceName); |
1179 | "TOLERANT"))) | 1158 | return GNUNET_SYSERR; |
1180 | { | ||
1181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1182 | _("Specified value for `%s' of service `%s' is invalid\n"), | ||
1183 | "TOLERANT", | ||
1184 | sctx->serviceName); | ||
1185 | return GNUNET_SYSERR; | ||
1186 | } | ||
1187 | } | 1159 | } |
1160 | } | ||
1188 | else | 1161 | else |
1189 | tolerant = GNUNET_NO; | 1162 | tolerant = GNUNET_NO; |
1190 | 1163 | ||
1191 | #ifndef MINGW | 1164 | #ifndef MINGW |
1192 | errno = 0; | 1165 | errno = 0; |
1193 | if ( (NULL != (lpid = getenv ("LISTEN_PID"))) && | 1166 | if ((NULL != (lpid = getenv ("LISTEN_PID"))) && |
1194 | (1 == sscanf (lpid, "%u", &pid)) && | 1167 | (1 == sscanf (lpid, "%u", &pid)) && |
1195 | (getpid () == (pid_t) pid) && | 1168 | (getpid () == (pid_t) pid) && |
1196 | (NULL != (nfds = getenv ("LISTEN_FDS"))) && | 1169 | (NULL != (nfds = getenv ("LISTEN_FDS"))) && |
1197 | (1 == sscanf (nfds, "%u", &cnt)) && | 1170 | (1 == sscanf (nfds, "%u", &cnt)) && |
1198 | (cnt > 0) && | 1171 | (cnt > 0) && (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) |
1199 | (cnt < FD_SETSIZE) && | 1172 | { |
1200 | (cnt + 4 < FD_SETSIZE) ) | 1173 | sctx->lsocks = |
1174 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); | ||
1175 | while (0 < cnt--) | ||
1201 | { | 1176 | { |
1202 | sctx->lsocks = GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle*) * (cnt+1)); | 1177 | flags = fcntl (3 + cnt, F_GETFD); |
1203 | while (0 < cnt--) | 1178 | if ((flags < 0) || |
1204 | { | 1179 | (0 != (flags & FD_CLOEXEC)) || |
1205 | flags = fcntl (3 + cnt, F_GETFD); | 1180 | (NULL == |
1206 | if ( (flags < 0) || | 1181 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) |
1207 | (0 != (flags & FD_CLOEXEC)) || | 1182 | { |
1208 | (NULL == (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))) ) | 1183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1209 | { | 1184 | _ |
1210 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1185 | ("Could not access pre-bound socket %u, will try to bind myself\n"), |
1211 | _("Could not access pre-bound socket %u, will try to bind myself\n"), | 1186 | (unsigned int) 3 + cnt); |
1212 | (unsigned int) 3 +cnt); | 1187 | cnt++; |
1213 | cnt++; | 1188 | while (sctx->lsocks[cnt] != NULL) |
1214 | while (sctx->lsocks[cnt] != NULL) | 1189 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++])); |
1215 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++])); | 1190 | GNUNET_free (sctx->lsocks); |
1216 | GNUNET_free (sctx->lsocks); | 1191 | sctx->lsocks = NULL; |
1217 | sctx->lsocks = NULL; | 1192 | break; |
1218 | break; | 1193 | } |
1219 | } | ||
1220 | } | ||
1221 | unsetenv ("LISTEN_PID"); | ||
1222 | unsetenv ("LISTEN_FDS"); | ||
1223 | } | 1194 | } |
1195 | unsetenv ("LISTEN_PID"); | ||
1196 | unsetenv ("LISTEN_FDS"); | ||
1197 | } | ||
1224 | #endif | 1198 | #endif |
1225 | 1199 | ||
1226 | if ( (sctx->lsocks == NULL) && | 1200 | if ((sctx->lsocks == NULL) && |
1227 | (GNUNET_SYSERR == | 1201 | (GNUNET_SYSERR == |
1228 | GNUNET_SERVICE_get_server_addresses (sctx->serviceName, | 1202 | GNUNET_SERVICE_get_server_addresses (sctx->serviceName, |
1229 | sctx->cfg, | 1203 | sctx->cfg, |
1230 | &sctx->addrs, | 1204 | &sctx->addrs, &sctx->addrlens))) |
1231 | &sctx->addrlens)) ) | ||
1232 | return GNUNET_SYSERR; | 1205 | return GNUNET_SYSERR; |
1233 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; | 1206 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; |
1234 | sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1207 | sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, |
1235 | sctx->serviceName, | 1208 | sctx->serviceName, |
1236 | "UNIX_MATCH_UID"); | 1209 | "UNIX_MATCH_UID"); |
1237 | sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, | 1210 | sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, |
1238 | sctx->serviceName, | 1211 | sctx->serviceName, |
1239 | "UNIX_MATCH_GID"); | 1212 | "UNIX_MATCH_GID"); |
1240 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); | 1213 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); |
1241 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); | 1214 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); |
1242 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); | 1215 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); |
@@ -1285,30 +1258,30 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid) | |||
1285 | len--; | 1258 | len--; |
1286 | rdir[len] = '\0'; | 1259 | rdir[len] = '\0'; |
1287 | if (0 != ACCESS (rdir, F_OK)) | 1260 | if (0 != ACCESS (rdir, F_OK)) |
1288 | { | 1261 | { |
1289 | /* we get to create a directory -- and claim it | 1262 | /* we get to create a directory -- and claim it |
1290 | as ours! */ | 1263 | * as ours! */ |
1291 | GNUNET_DISK_directory_create (rdir); | 1264 | GNUNET_DISK_directory_create (rdir); |
1292 | if ((user != NULL) && (0 < strlen (user))) | 1265 | if ((user != NULL) && (0 < strlen (user))) |
1293 | GNUNET_DISK_file_change_owner (rdir, user); | 1266 | GNUNET_DISK_file_change_owner (rdir, user); |
1294 | } | 1267 | } |
1295 | if (0 != ACCESS (rdir, W_OK | X_OK)) | 1268 | if (0 != ACCESS (rdir, W_OK | X_OK)) |
1296 | { | 1269 | { |
1297 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", rdir); | 1270 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access", rdir); |
1298 | GNUNET_free (rdir); | 1271 | GNUNET_free (rdir); |
1299 | GNUNET_free_non_null (user); | 1272 | GNUNET_free_non_null (user); |
1300 | GNUNET_free (pif); | 1273 | GNUNET_free (pif); |
1301 | return GNUNET_SYSERR; | 1274 | return GNUNET_SYSERR; |
1302 | } | 1275 | } |
1303 | GNUNET_free (rdir); | 1276 | GNUNET_free (rdir); |
1304 | pidfd = FOPEN (pif, "w"); | 1277 | pidfd = FOPEN (pif, "w"); |
1305 | if (pidfd == NULL) | 1278 | if (pidfd == NULL) |
1306 | { | 1279 | { |
1307 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); | 1280 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); |
1308 | GNUNET_free (pif); | 1281 | GNUNET_free (pif); |
1309 | GNUNET_free_non_null (user); | 1282 | GNUNET_free_non_null (user); |
1310 | return GNUNET_SYSERR; | 1283 | return GNUNET_SYSERR; |
1311 | } | 1284 | } |
1312 | if (0 > FPRINTF (pidfd, "%u", pid)) | 1285 | if (0 > FPRINTF (pidfd, "%u", pid)) |
1313 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); | 1286 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); |
1314 | GNUNET_break (0 == fclose (pidfd)); | 1287 | GNUNET_break (0 == fclose (pidfd)); |
@@ -1347,39 +1320,40 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1347 | GNUNET_RESOLVER_connect (sctx->cfg); | 1320 | GNUNET_RESOLVER_connect (sctx->cfg); |
1348 | if (sctx->lsocks != NULL) | 1321 | if (sctx->lsocks != NULL) |
1349 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, | 1322 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, |
1350 | sctx, | 1323 | sctx, |
1351 | sctx->lsocks, | 1324 | sctx->lsocks, |
1352 | sctx->timeout, sctx->require_found); | 1325 | sctx->timeout, |
1326 | sctx->require_found); | ||
1353 | else | 1327 | else |
1354 | sctx->server = GNUNET_SERVER_create (&check_access, | 1328 | sctx->server = GNUNET_SERVER_create (&check_access, |
1355 | sctx, | 1329 | sctx, |
1356 | sctx->addrs, | 1330 | sctx->addrs, |
1357 | sctx->addrlens, | 1331 | sctx->addrlens, |
1358 | sctx->timeout, sctx->require_found); | 1332 | sctx->timeout, sctx->require_found); |
1359 | if (sctx->server == NULL) | 1333 | if (sctx->server == NULL) |
1334 | { | ||
1335 | if (sctx->addrs != NULL) | ||
1360 | { | 1336 | { |
1361 | if (sctx->addrs != NULL) | 1337 | i = 0; |
1362 | { | 1338 | while (sctx->addrs[i] != NULL) |
1363 | i = 0; | 1339 | { |
1364 | while (sctx->addrs[i] != NULL) | 1340 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1365 | { | 1341 | _("Failed to start `%s' at `%s'\n"), |
1366 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1342 | sctx->serviceName, |
1367 | _("Failed to start `%s' at `%s'\n"), | 1343 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); |
1368 | sctx->serviceName, | 1344 | i++; |
1369 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | 1345 | } |
1370 | i++; | ||
1371 | } | ||
1372 | } | ||
1373 | sctx->ret = GNUNET_SYSERR; | ||
1374 | return; | ||
1375 | } | 1346 | } |
1347 | sctx->ret = GNUNET_SYSERR; | ||
1348 | return; | ||
1349 | } | ||
1376 | if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN)) | 1350 | if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN)) |
1377 | { | 1351 | { |
1378 | /* install a task that will kill the server | 1352 | /* install a task that will kill the server |
1379 | process if the scheduler ever gets a shutdown signal */ | 1353 | * process if the scheduler ever gets a shutdown signal */ |
1380 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1354 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
1381 | &shutdown_task, sctx->server); | 1355 | &shutdown_task, sctx->server); |
1382 | } | 1356 | } |
1383 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1357 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); |
1384 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1358 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); |
1385 | i = 0; | 1359 | i = 0; |
@@ -1387,24 +1361,24 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1387 | sctx->my_handlers[i++].callback_cls = sctx; | 1361 | sctx->my_handlers[i++].callback_cls = sctx; |
1388 | GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); | 1362 | GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); |
1389 | if (sctx->ready_confirm_fd != -1) | 1363 | if (sctx->ready_confirm_fd != -1) |
1390 | { | 1364 | { |
1391 | GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); | 1365 | GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); |
1392 | GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); | 1366 | GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); |
1393 | sctx->ready_confirm_fd = -1; | 1367 | sctx->ready_confirm_fd = -1; |
1394 | write_pid_file (sctx, getpid ()); | 1368 | write_pid_file (sctx, getpid ()); |
1395 | } | 1369 | } |
1396 | if (sctx->addrs != NULL) | 1370 | if (sctx->addrs != NULL) |
1371 | { | ||
1372 | i = 0; | ||
1373 | while (sctx->addrs[i] != NULL) | ||
1397 | { | 1374 | { |
1398 | i = 0; | 1375 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1399 | while (sctx->addrs[i] != NULL) | 1376 | _("Service `%s' runs at %s\n"), |
1400 | { | 1377 | sctx->serviceName, |
1401 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1378 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); |
1402 | _("Service `%s' runs at %s\n"), | 1379 | i++; |
1403 | sctx->serviceName, | ||
1404 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | ||
1405 | i++; | ||
1406 | } | ||
1407 | } | 1380 | } |
1381 | } | ||
1408 | sctx->task (sctx->task_cls, sctx->server, sctx->cfg); | 1382 | sctx->task (sctx->task_cls, sctx->server, sctx->cfg); |
1409 | } | 1383 | } |
1410 | 1384 | ||
@@ -1421,46 +1395,45 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx) | |||
1421 | int filedes[2]; | 1395 | int filedes[2]; |
1422 | 1396 | ||
1423 | if (0 != PIPE (filedes)) | 1397 | if (0 != PIPE (filedes)) |
1424 | { | 1398 | { |
1425 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 1399 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); |
1426 | return GNUNET_SYSERR; | 1400 | return GNUNET_SYSERR; |
1427 | } | 1401 | } |
1428 | pid = fork (); | 1402 | pid = fork (); |
1429 | if (pid < 0) | 1403 | if (pid < 0) |
1430 | { | 1404 | { |
1431 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); | 1405 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); |
1432 | return GNUNET_SYSERR; | 1406 | return GNUNET_SYSERR; |
1433 | } | 1407 | } |
1434 | if (pid != 0) | 1408 | if (pid != 0) |
1409 | { | ||
1410 | /* Parent */ | ||
1411 | char c; | ||
1412 | |||
1413 | GNUNET_break (0 == CLOSE (filedes[1])); | ||
1414 | c = 'X'; | ||
1415 | if (1 != READ (filedes[0], &c, sizeof (char))) | ||
1416 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "read"); | ||
1417 | fflush (stdout); | ||
1418 | switch (c) | ||
1435 | { | 1419 | { |
1436 | /* Parent */ | 1420 | case '.': |
1437 | char c; | 1421 | exit (0); |
1438 | 1422 | case 'I': | |
1439 | GNUNET_break (0 == CLOSE (filedes[1])); | 1423 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1440 | c = 'X'; | 1424 | _("Service process failed to initialize\n")); |
1441 | if (1 != READ (filedes[0], &c, sizeof (char))) | 1425 | break; |
1442 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "read"); | 1426 | case 'S': |
1443 | fflush (stdout); | 1427 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1444 | switch (c) | 1428 | _("Service process could not initialize server function\n")); |
1445 | { | 1429 | break; |
1446 | case '.': | 1430 | case 'X': |
1447 | exit (0); | 1431 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1448 | case 'I': | 1432 | _("Service process failed to report status\n")); |
1449 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1433 | break; |
1450 | _("Service process failed to initialize\n")); | ||
1451 | break; | ||
1452 | case 'S': | ||
1453 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1454 | _ | ||
1455 | ("Service process could not initialize server function\n")); | ||
1456 | break; | ||
1457 | case 'X': | ||
1458 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1459 | _("Service process failed to report status\n")); | ||
1460 | break; | ||
1461 | } | ||
1462 | exit (1); /* child reported error */ | ||
1463 | } | 1434 | } |
1435 | exit (1); /* child reported error */ | ||
1436 | } | ||
1464 | GNUNET_break (0 == CLOSE (0)); | 1437 | GNUNET_break (0 == CLOSE (0)); |
1465 | GNUNET_break (0 == CLOSE (1)); | 1438 | GNUNET_break (0 == CLOSE (1)); |
1466 | GNUNET_break (0 == CLOSE (filedes[0])); | 1439 | GNUNET_break (0 == CLOSE (filedes[0])); |
@@ -1469,11 +1442,11 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx) | |||
1469 | return GNUNET_SYSERR; | 1442 | return GNUNET_SYSERR; |
1470 | /* set stdin/stdout to /dev/null */ | 1443 | /* set stdin/stdout to /dev/null */ |
1471 | if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) | 1444 | if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) |
1472 | { | 1445 | { |
1473 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2"); | 1446 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2"); |
1474 | (void) CLOSE (nullfd); | 1447 | (void) CLOSE (nullfd); |
1475 | return GNUNET_SYSERR; | 1448 | return GNUNET_SYSERR; |
1476 | } | 1449 | } |
1477 | (void) CLOSE (nullfd); | 1450 | (void) CLOSE (nullfd); |
1478 | /* Detach from controlling terminal */ | 1451 | /* Detach from controlling terminal */ |
1479 | pid = setsid (); | 1452 | pid = setsid (); |
@@ -1482,7 +1455,7 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx) | |||
1482 | sctx->ready_confirm_fd = filedes[1]; | 1455 | sctx->ready_confirm_fd = filedes[1]; |
1483 | #else | 1456 | #else |
1484 | /* FIXME: we probably need to do something else | 1457 | /* FIXME: we probably need to do something else |
1485 | elsewhere in order to fork the process itself... */ | 1458 | * elsewhere in order to fork the process itself... */ |
1486 | FreeConsole (); | 1459 | FreeConsole (); |
1487 | #endif | 1460 | #endif |
1488 | return GNUNET_OK; | 1461 | return GNUNET_OK; |
@@ -1505,29 +1478,29 @@ set_user_id (struct GNUNET_SERVICE_Context *sctx) | |||
1505 | errno = 0; | 1478 | errno = 0; |
1506 | pws = getpwnam (user); | 1479 | pws = getpwnam (user); |
1507 | if (pws == NULL) | 1480 | if (pws == NULL) |
1508 | { | 1481 | { |
1509 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1510 | _("Cannot obtain information about user `%s': %s\n"), | 1483 | _("Cannot obtain information about user `%s': %s\n"), |
1511 | user, errno == 0 ? _("No such user") : STRERROR (errno)); | 1484 | user, errno == 0 ? _("No such user") : STRERROR (errno)); |
1512 | GNUNET_free (user); | 1485 | GNUNET_free (user); |
1513 | return GNUNET_SYSERR; | 1486 | return GNUNET_SYSERR; |
1514 | } | 1487 | } |
1515 | if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || | 1488 | if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || |
1516 | #if HAVE_INITGROUPS | 1489 | #if HAVE_INITGROUPS |
1517 | (0 != initgroups (user, pws->pw_gid)) || | 1490 | (0 != initgroups (user, pws->pw_gid)) || |
1518 | #endif | 1491 | #endif |
1519 | (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) | 1492 | (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) |
1493 | { | ||
1494 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || | ||
1495 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) | ||
1520 | { | 1496 | { |
1521 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || | 1497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1522 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) | 1498 | _("Cannot change user/group to `%s': %s\n"), user, |
1523 | { | 1499 | STRERROR (errno)); |
1524 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1500 | GNUNET_free (user); |
1525 | _("Cannot change user/group to `%s': %s\n"), user, | 1501 | return GNUNET_SYSERR; |
1526 | STRERROR (errno)); | ||
1527 | GNUNET_free (user); | ||
1528 | return GNUNET_SYSERR; | ||
1529 | } | ||
1530 | } | 1502 | } |
1503 | } | ||
1531 | #endif | 1504 | #endif |
1532 | GNUNET_free (user); | 1505 | GNUNET_free (user); |
1533 | return GNUNET_OK; | 1506 | return GNUNET_OK; |
@@ -1541,6 +1514,7 @@ static void | |||
1541 | pid_file_delete (struct GNUNET_SERVICE_Context *sctx) | 1514 | pid_file_delete (struct GNUNET_SERVICE_Context *sctx) |
1542 | { | 1515 | { |
1543 | char *pif = get_pid_file_name (sctx); | 1516 | char *pif = get_pid_file_name (sctx); |
1517 | |||
1544 | if (pif == NULL) | 1518 | if (pif == NULL) |
1545 | return; /* no PID file */ | 1519 | return; /* no PID file */ |
1546 | if (0 != UNLINK (pif)) | 1520 | if (0 != UNLINK (pif)) |
@@ -1582,6 +1556,7 @@ GNUNET_SERVICE_run (int argc, | |||
1582 | long long clock_offset; | 1556 | long long clock_offset; |
1583 | struct GNUNET_SERVICE_Context sctx; | 1557 | struct GNUNET_SERVICE_Context sctx; |
1584 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1558 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1559 | |||
1585 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 1560 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
1586 | GNUNET_GETOPT_OPTION_CFG_FILE (&cfg_fn), | 1561 | GNUNET_GETOPT_OPTION_CFG_FILE (&cfg_fn), |
1587 | {'d', "daemonize", NULL, | 1562 | {'d', "daemonize", NULL, |
@@ -1609,7 +1584,7 @@ GNUNET_SERVICE_run (int argc, | |||
1609 | sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); | 1584 | sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); |
1610 | /* setup subsystems */ | 1585 | /* setup subsystems */ |
1611 | if (GNUNET_SYSERR == GNUNET_GETOPT_run (serviceName, service_options, argc, | 1586 | if (GNUNET_SYSERR == GNUNET_GETOPT_run (serviceName, service_options, argc, |
1612 | argv)) | 1587 | argv)) |
1613 | goto shutdown; | 1588 | goto shutdown; |
1614 | if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile)) | 1589 | if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile)) |
1615 | HANDLE_ERROR; | 1590 | HANDLE_ERROR; |
@@ -1617,7 +1592,7 @@ GNUNET_SERVICE_run (int argc, | |||
1617 | goto shutdown; | 1592 | goto shutdown; |
1618 | if (GNUNET_OK != setup_service (&sctx)) | 1593 | if (GNUNET_OK != setup_service (&sctx)) |
1619 | goto shutdown; | 1594 | goto shutdown; |
1620 | if ( (do_daemonize == 1) && (GNUNET_OK != detach_terminal (&sctx))) | 1595 | if ((do_daemonize == 1) && (GNUNET_OK != detach_terminal (&sctx))) |
1621 | HANDLE_ERROR; | 1596 | HANDLE_ERROR; |
1622 | if (GNUNET_OK != set_user_id (&sctx)) | 1597 | if (GNUNET_OK != set_user_id (&sctx)) |
1623 | goto shutdown; | 1598 | goto shutdown; |
@@ -1626,15 +1601,20 @@ GNUNET_SERVICE_run (int argc, | |||
1626 | "Service `%s' runs with configuration from `%s'\n", | 1601 | "Service `%s' runs with configuration from `%s'\n", |
1627 | serviceName, cfg_fn); | 1602 | serviceName, cfg_fn); |
1628 | #endif | 1603 | #endif |
1629 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, "testing", "skew_offset", &skew_offset) && | 1604 | if (GNUNET_OK == |
1630 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg, "testing", "skew_variance", &skew_variance))) | 1605 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", "skew_offset", |
1631 | { | 1606 | &skew_offset) && |
1632 | clock_offset = skew_offset - skew_variance; | 1607 | (GNUNET_OK == |
1633 | GNUNET_TIME_set_offset(clock_offset); | 1608 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "testing", |
1609 | "skew_variance", &skew_variance))) | ||
1610 | { | ||
1611 | clock_offset = skew_offset - skew_variance; | ||
1612 | GNUNET_TIME_set_offset (clock_offset); | ||
1634 | #if DEBUG_SERVICE | 1613 | #if DEBUG_SERVICE |
1635 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", clock_offset); | 1614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll\n", |
1615 | clock_offset); | ||
1636 | #endif | 1616 | #endif |
1637 | } | 1617 | } |
1638 | /* actually run service */ | 1618 | /* actually run service */ |
1639 | GNUNET_SCHEDULER_run (&service_task, &sctx); | 1619 | GNUNET_SCHEDULER_run (&service_task, &sctx); |
1640 | 1620 | ||
@@ -1645,17 +1625,17 @@ GNUNET_SERVICE_run (int argc, | |||
1645 | 1625 | ||
1646 | shutdown: | 1626 | shutdown: |
1647 | if (sctx.ready_confirm_fd != -1) | 1627 | if (sctx.ready_confirm_fd != -1) |
1648 | { | 1628 | { |
1649 | if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) | 1629 | if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) |
1650 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write"); | 1630 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write"); |
1651 | GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); | 1631 | GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); |
1652 | } | 1632 | } |
1653 | 1633 | ||
1654 | GNUNET_CONFIGURATION_destroy (cfg); | 1634 | GNUNET_CONFIGURATION_destroy (cfg); |
1655 | i = 0; | 1635 | i = 0; |
1656 | if (sctx.addrs != NULL) | 1636 | if (sctx.addrs != NULL) |
1657 | while (sctx.addrs[i] != NULL) | 1637 | while (sctx.addrs[i] != NULL) |
1658 | GNUNET_free (sctx.addrs[i++]); | 1638 | GNUNET_free (sctx.addrs[i++]); |
1659 | GNUNET_free_non_null (sctx.addrs); | 1639 | GNUNET_free_non_null (sctx.addrs); |
1660 | GNUNET_free_non_null (sctx.addrlens); | 1640 | GNUNET_free_non_null (sctx.addrlens); |
1661 | GNUNET_free_non_null (logfile); | 1641 | GNUNET_free_non_null (logfile); |
@@ -1694,28 +1674,28 @@ GNUNET_SERVICE_start (const char *serviceName, | |||
1694 | 1674 | ||
1695 | /* setup subsystems */ | 1675 | /* setup subsystems */ |
1696 | if (GNUNET_OK != setup_service (sctx)) | 1676 | if (GNUNET_OK != setup_service (sctx)) |
1697 | { | 1677 | { |
1698 | GNUNET_SERVICE_stop (sctx); | 1678 | GNUNET_SERVICE_stop (sctx); |
1699 | return NULL; | 1679 | return NULL; |
1700 | } | 1680 | } |
1701 | if (sctx->lsocks != NULL) | 1681 | if (sctx->lsocks != NULL) |
1702 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, | 1682 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, |
1703 | sctx, | 1683 | sctx, |
1704 | sctx->lsocks, | 1684 | sctx->lsocks, |
1705 | sctx->timeout, sctx->require_found); | 1685 | sctx->timeout, |
1686 | sctx->require_found); | ||
1706 | else | 1687 | else |
1707 | sctx->server = GNUNET_SERVER_create (&check_access, | 1688 | sctx->server = GNUNET_SERVER_create (&check_access, |
1708 | sctx, | 1689 | sctx, |
1709 | sctx->addrs, | 1690 | sctx->addrs, |
1710 | sctx->addrlens, | 1691 | sctx->addrlens, |
1711 | sctx->timeout, | 1692 | sctx->timeout, sctx->require_found); |
1712 | sctx->require_found); | 1693 | |
1713 | |||
1714 | if (NULL == sctx->server) | 1694 | if (NULL == sctx->server) |
1715 | { | 1695 | { |
1716 | GNUNET_SERVICE_stop (sctx); | 1696 | GNUNET_SERVICE_stop (sctx); |
1717 | return NULL; | 1697 | return NULL; |
1718 | } | 1698 | } |
1719 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1699 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); |
1720 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1700 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); |
1721 | i = 0; | 1701 | i = 0; |
@@ -1748,16 +1728,17 @@ void | |||
1748 | GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx) | 1728 | GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx) |
1749 | { | 1729 | { |
1750 | unsigned int i; | 1730 | unsigned int i; |
1731 | |||
1751 | if (NULL != sctx->server) | 1732 | if (NULL != sctx->server) |
1752 | GNUNET_SERVER_destroy (sctx->server); | 1733 | GNUNET_SERVER_destroy (sctx->server); |
1753 | GNUNET_free_non_null (sctx->my_handlers); | 1734 | GNUNET_free_non_null (sctx->my_handlers); |
1754 | if (sctx->addrs != NULL) | 1735 | if (sctx->addrs != NULL) |
1755 | { | 1736 | { |
1756 | i = 0; | 1737 | i = 0; |
1757 | while (sctx->addrs[i] != NULL) | 1738 | while (sctx->addrs[i] != NULL) |
1758 | GNUNET_free (sctx->addrs[i++]); | 1739 | GNUNET_free (sctx->addrs[i++]); |
1759 | GNUNET_free (sctx->addrs); | 1740 | GNUNET_free (sctx->addrs); |
1760 | } | 1741 | } |
1761 | GNUNET_free_non_null (sctx->addrlens); | 1742 | GNUNET_free_non_null (sctx->addrlens); |
1762 | GNUNET_free_non_null (sctx->v4_denied); | 1743 | GNUNET_free_non_null (sctx->v4_denied); |
1763 | GNUNET_free_non_null (sctx->v6_denied); | 1744 | GNUNET_free_non_null (sctx->v6_denied); |
diff --git a/src/util/signal.c b/src/util/signal.c index 2ace3911f..395e8e517 100644 --- a/src/util/signal.c +++ b/src/util/signal.c | |||
@@ -47,6 +47,7 @@ struct GNUNET_SIGNAL_Context * | |||
47 | GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) | 47 | GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) |
48 | { | 48 | { |
49 | struct GNUNET_SIGNAL_Context *ret; | 49 | struct GNUNET_SIGNAL_Context *ret; |
50 | |||
50 | #ifndef MINGW | 51 | #ifndef MINGW |
51 | struct sigaction sig; | 52 | struct sigaction sig; |
52 | #endif | 53 | #endif |
@@ -68,16 +69,15 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) | |||
68 | if (signum == GNUNET_SIGCHLD) | 69 | if (signum == GNUNET_SIGCHLD) |
69 | w32_sigchld_handler = handler; | 70 | w32_sigchld_handler = handler; |
70 | else | 71 | else |
72 | { | ||
73 | __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler); | ||
74 | |||
75 | if (sigret == SIG_ERR) | ||
71 | { | 76 | { |
72 | __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler); | 77 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
73 | if (sigret == SIG_ERR) | 78 | _("signal (%d, %p) returned %d.\n"), signum, handler, sigret); |
74 | { | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
76 | _ | ||
77 | ("signal (%d, %p) returned %d.\n"), | ||
78 | signum, handler, sigret); | ||
79 | } | ||
80 | } | 79 | } |
80 | } | ||
81 | #endif | 81 | #endif |
82 | return ret; | 82 | return ret; |
83 | } | 83 | } |
diff --git a/src/util/strings.c b/src/util/strings.c index fa445f694..a95981690 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -55,8 +55,7 @@ | |||
55 | * (or number of bytes that would have been written) | 55 | * (or number of bytes that would have been written) |
56 | */ | 56 | */ |
57 | size_t | 57 | size_t |
58 | GNUNET_STRINGS_buffer_fill (char *buffer, | 58 | GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...) |
59 | size_t size, unsigned int count, ...) | ||
60 | { | 59 | { |
61 | size_t needed; | 60 | size_t needed; |
62 | size_t slen; | 61 | size_t slen; |
@@ -66,17 +65,18 @@ GNUNET_STRINGS_buffer_fill (char *buffer, | |||
66 | needed = 0; | 65 | needed = 0; |
67 | va_start (ap, count); | 66 | va_start (ap, count); |
68 | while (count > 0) | 67 | while (count > 0) |
68 | { | ||
69 | s = va_arg (ap, const char *); | ||
70 | |||
71 | slen = strlen (s) + 1; | ||
72 | if (buffer != NULL) | ||
69 | { | 73 | { |
70 | s = va_arg (ap, const char *); | 74 | GNUNET_assert (needed + slen <= size); |
71 | slen = strlen (s) + 1; | 75 | memcpy (&buffer[needed], s, slen); |
72 | if (buffer != NULL) | ||
73 | { | ||
74 | GNUNET_assert (needed + slen <= size); | ||
75 | memcpy (&buffer[needed], s, slen); | ||
76 | } | ||
77 | needed += slen; | ||
78 | count--; | ||
79 | } | 76 | } |
77 | needed += slen; | ||
78 | count--; | ||
79 | } | ||
80 | va_end (ap); | 80 | va_end (ap); |
81 | return needed; | 81 | return needed; |
82 | } | 82 | } |
@@ -107,20 +107,21 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, | |||
107 | needed = 0; | 107 | needed = 0; |
108 | va_start (ap, count); | 108 | va_start (ap, count); |
109 | while (count > 0) | 109 | while (count > 0) |
110 | { | ||
111 | r = va_arg (ap, const char **); | ||
112 | |||
113 | start = needed; | ||
114 | while ((needed < size) && (buffer[needed] != '\0')) | ||
115 | needed++; | ||
116 | if (needed == size) | ||
110 | { | 117 | { |
111 | r = va_arg (ap, const char **); | 118 | va_end (ap); |
112 | start = needed; | 119 | return 0; /* error */ |
113 | while ((needed < size) && (buffer[needed] != '\0')) | ||
114 | needed++; | ||
115 | if (needed == size) | ||
116 | { | ||
117 | va_end (ap); | ||
118 | return 0; /* error */ | ||
119 | } | ||
120 | *r = &buffer[start]; | ||
121 | needed++; /* skip 0-termination */ | ||
122 | count--; | ||
123 | } | 120 | } |
121 | *r = &buffer[start]; | ||
122 | needed++; /* skip 0-termination */ | ||
123 | count--; | ||
124 | } | ||
124 | va_end (ap); | 125 | va_end (ap); |
125 | return needed; | 126 | return needed; |
126 | } | 127 | } |
@@ -139,25 +140,25 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size) | |||
139 | char *ret; | 140 | char *ret; |
140 | 141 | ||
141 | if (size > 5 * 1024) | 142 | if (size > 5 * 1024) |
143 | { | ||
144 | size = size / 1024; | ||
145 | unit = _( /* size unit */ "KiB"); | ||
146 | if (size > 5 * 1024) | ||
142 | { | 147 | { |
143 | size = size / 1024; | 148 | size = size / 1024; |
144 | unit = _( /* size unit */ "KiB"); | 149 | unit = _( /* size unit */ "MiB"); |
145 | if (size > 5 * 1024) | 150 | if (size > 5 * 1024) |
151 | { | ||
152 | size = size / 1024; | ||
153 | unit = _( /* size unit */ "GiB"); | ||
154 | if (size > 5 * 1024) | ||
146 | { | 155 | { |
147 | size = size / 1024; | 156 | size = size / 1024; |
148 | unit = _( /* size unit */ "MiB"); | 157 | unit = _( /* size unit */ "TiB"); |
149 | if (size > 5 * 1024) | ||
150 | { | ||
151 | size = size / 1024; | ||
152 | unit = _( /* size unit */ "GiB"); | ||
153 | if (size > 5 * 1024) | ||
154 | { | ||
155 | size = size / 1024; | ||
156 | unit = _( /* size unit */ "TiB"); | ||
157 | } | ||
158 | } | ||
159 | } | 158 | } |
159 | } | ||
160 | } | 160 | } |
161 | } | ||
161 | ret = GNUNET_malloc (32); | 162 | ret = GNUNET_malloc (32); |
162 | GNUNET_snprintf (ret, 32, "%llu %s", size, unit); | 163 | GNUNET_snprintf (ret, 32, "%llu %s", size, unit); |
163 | return ret; | 164 | return ret; |
@@ -176,6 +177,7 @@ char * | |||
176 | GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) | 177 | GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) |
177 | { | 178 | { |
178 | char *ret; | 179 | char *ret; |
180 | |||
179 | #if ENABLE_NLS && HAVE_ICONV | 181 | #if ENABLE_NLS && HAVE_ICONV |
180 | size_t tmpSize; | 182 | size_t tmpSize; |
181 | size_t finSize; | 183 | size_t finSize; |
@@ -185,15 +187,15 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) | |||
185 | 187 | ||
186 | cd = iconv_open ("UTF-8", charset); | 188 | cd = iconv_open ("UTF-8", charset); |
187 | if (cd == (iconv_t) - 1) | 189 | if (cd == (iconv_t) - 1) |
188 | { | 190 | { |
189 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv_open"); | 191 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv_open"); |
190 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 192 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
191 | _("Character set requested was `%s'\n"), charset); | 193 | _("Character set requested was `%s'\n"), charset); |
192 | ret = GNUNET_malloc (len + 1); | 194 | ret = GNUNET_malloc (len + 1); |
193 | memcpy (ret, input, len); | 195 | memcpy (ret, input, len); |
194 | ret[len] = '\0'; | 196 | ret[len] = '\0'; |
195 | return ret; | 197 | return ret; |
196 | } | 198 | } |
197 | tmpSize = 3 * len + 4; | 199 | tmpSize = 3 * len + 4; |
198 | tmp = GNUNET_malloc (tmpSize); | 200 | tmp = GNUNET_malloc (tmpSize); |
199 | itmp = tmp; | 201 | itmp = tmp; |
@@ -205,15 +207,15 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset) | |||
205 | (char **) &input, | 207 | (char **) &input, |
206 | #endif | 208 | #endif |
207 | &len, &itmp, &finSize) == SIZE_MAX) | 209 | &len, &itmp, &finSize) == SIZE_MAX) |
208 | { | 210 | { |
209 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv"); | 211 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv"); |
210 | iconv_close (cd); | 212 | iconv_close (cd); |
211 | GNUNET_free (tmp); | 213 | GNUNET_free (tmp); |
212 | ret = GNUNET_malloc (len + 1); | 214 | ret = GNUNET_malloc (len + 1); |
213 | memcpy (ret, input, len); | 215 | memcpy (ret, input, len); |
214 | ret[len] = '\0'; | 216 | ret[len] = '\0'; |
215 | return ret; | 217 | return ret; |
216 | } | 218 | } |
217 | ret = GNUNET_malloc (tmpSize - finSize + 1); | 219 | ret = GNUNET_malloc (tmpSize - finSize + 1); |
218 | memcpy (ret, tmp, tmpSize - finSize); | 220 | memcpy (ret, tmp, tmpSize - finSize); |
219 | ret[tmpSize - finSize] = '\0'; | 221 | ret[tmpSize - finSize] = '\0'; |
@@ -241,6 +243,7 @@ char * | |||
241 | GNUNET_STRINGS_filename_expand (const char *fil) | 243 | GNUNET_STRINGS_filename_expand (const char *fil) |
242 | { | 244 | { |
243 | char *buffer; | 245 | char *buffer; |
246 | |||
244 | #ifndef MINGW | 247 | #ifndef MINGW |
245 | size_t len; | 248 | size_t len; |
246 | size_t n; | 249 | size_t n; |
@@ -259,56 +262,56 @@ GNUNET_STRINGS_filename_expand (const char *fil) | |||
259 | /* absolute path, just copy */ | 262 | /* absolute path, just copy */ |
260 | return GNUNET_strdup (fil); | 263 | return GNUNET_strdup (fil); |
261 | if (fil[0] == '~') | 264 | if (fil[0] == '~') |
265 | { | ||
266 | fm = getenv ("HOME"); | ||
267 | if (fm == NULL) | ||
262 | { | 268 | { |
263 | fm = getenv ("HOME"); | 269 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
264 | if (fm == NULL) | 270 | _ |
265 | { | 271 | ("Failed to expand `$HOME': environment variable `HOME' not set")); |
266 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 272 | return NULL; |
267 | _ | ||
268 | ("Failed to expand `$HOME': environment variable `HOME' not set")); | ||
269 | return NULL; | ||
270 | } | ||
271 | fm = GNUNET_strdup (fm); | ||
272 | /* do not copy '~' */ | ||
273 | fil_ptr = fil + 1; | ||
274 | |||
275 | /* skip over dir seperator to be consistent */ | ||
276 | if (fil_ptr[0] == DIR_SEPARATOR) | ||
277 | fil_ptr++; | ||
278 | } | 273 | } |
274 | fm = GNUNET_strdup (fm); | ||
275 | /* do not copy '~' */ | ||
276 | fil_ptr = fil + 1; | ||
277 | |||
278 | /* skip over dir seperator to be consistent */ | ||
279 | if (fil_ptr[0] == DIR_SEPARATOR) | ||
280 | fil_ptr++; | ||
281 | } | ||
279 | else | 282 | else |
283 | { | ||
284 | /* relative path */ | ||
285 | fil_ptr = fil; | ||
286 | len = 512; | ||
287 | fm = NULL; | ||
288 | while (1) | ||
280 | { | 289 | { |
281 | /* relative path */ | 290 | buffer = GNUNET_malloc (len); |
282 | fil_ptr = fil; | 291 | if (getcwd (buffer, len) != NULL) |
283 | len = 512; | 292 | { |
284 | fm = NULL; | 293 | fm = buffer; |
285 | while (1) | 294 | break; |
286 | { | 295 | } |
287 | buffer = GNUNET_malloc (len); | 296 | if ((errno == ERANGE) && (len < 1024 * 1024 * 4)) |
288 | if (getcwd (buffer, len) != NULL) | 297 | { |
289 | { | 298 | len *= 2; |
290 | fm = buffer; | 299 | GNUNET_free (buffer); |
291 | break; | 300 | continue; |
292 | } | 301 | } |
293 | if ((errno == ERANGE) && (len < 1024 * 1024 * 4)) | 302 | GNUNET_free (buffer); |
294 | { | 303 | break; |
295 | len *= 2; | 304 | } |
296 | GNUNET_free (buffer); | 305 | if (fm == NULL) |
297 | continue; | 306 | { |
298 | } | 307 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getcwd"); |
299 | GNUNET_free (buffer); | 308 | buffer = getenv ("PWD"); /* alternative */ |
300 | break; | 309 | if (buffer != NULL) |
301 | } | 310 | fm = GNUNET_strdup (buffer); |
302 | if (fm == NULL) | ||
303 | { | ||
304 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getcwd"); | ||
305 | buffer = getenv ("PWD"); /* alternative */ | ||
306 | if (buffer != NULL) | ||
307 | fm = GNUNET_strdup (buffer); | ||
308 | } | ||
309 | if (fm == NULL) | ||
310 | fm = GNUNET_strdup ("./"); /* give up */ | ||
311 | } | 311 | } |
312 | if (fm == NULL) | ||
313 | fm = GNUNET_strdup ("./"); /* give up */ | ||
314 | } | ||
312 | n = strlen (fm) + 1 + strlen (fil_ptr) + 1; | 315 | n = strlen (fm) + 1 + strlen (fil_ptr) + 1; |
313 | buffer = GNUNET_malloc (n); | 316 | buffer = GNUNET_malloc (n); |
314 | GNUNET_snprintf (buffer, n, "%s%s%s", | 317 | GNUNET_snprintf (buffer, n, "%s%s%s", |
@@ -321,29 +324,28 @@ GNUNET_STRINGS_filename_expand (const char *fil) | |||
321 | fn = GNUNET_malloc (MAX_PATH + 1); | 324 | fn = GNUNET_malloc (MAX_PATH + 1); |
322 | 325 | ||
323 | if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS) | 326 | if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS) |
324 | { | 327 | { |
325 | SetErrnoFromWinError (lRet); | 328 | SetErrnoFromWinError (lRet); |
326 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 329 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path"); |
327 | "plibc_conv_to_win_path"); | 330 | return NULL; |
328 | return NULL; | 331 | } |
329 | } | ||
330 | /* is the path relative? */ | 332 | /* is the path relative? */ |
331 | if ((strncmp (fn + 1, ":\\", 2) != 0) && (strncmp (fn, "\\\\", 2) != 0)) | 333 | if ((strncmp (fn + 1, ":\\", 2) != 0) && (strncmp (fn, "\\\\", 2) != 0)) |
334 | { | ||
335 | char szCurDir[MAX_PATH + 1]; | ||
336 | |||
337 | lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir); | ||
338 | if (lRet + strlen (fn) + 1 > (MAX_PATH + 1)) | ||
332 | { | 339 | { |
333 | char szCurDir[MAX_PATH + 1]; | 340 | SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW); |
334 | lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir); | 341 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory"); |
335 | if (lRet + strlen (fn) + 1 > (MAX_PATH + 1)) | 342 | return NULL; |
336 | { | ||
337 | SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW); | ||
338 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
339 | "GetCurrentDirectory"); | ||
340 | return NULL; | ||
341 | } | ||
342 | buffer = GNUNET_malloc (MAX_PATH + 1); | ||
343 | GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn); | ||
344 | GNUNET_free (fn); | ||
345 | fn = buffer; | ||
346 | } | 343 | } |
344 | buffer = GNUNET_malloc (MAX_PATH + 1); | ||
345 | GNUNET_snprintf (buffer, MAX_PATH + 1, "%s\\%s", szCurDir, fn); | ||
346 | GNUNET_free (fn); | ||
347 | fn = buffer; | ||
348 | } | ||
347 | 349 | ||
348 | return fn; | 350 | return fn; |
349 | #endif | 351 | #endif |
@@ -366,25 +368,25 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta) | |||
366 | if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 368 | if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
367 | return GNUNET_strdup (_("eternity")); | 369 | return GNUNET_strdup (_("eternity")); |
368 | if (dval > 5 * 1000) | 370 | if (dval > 5 * 1000) |
371 | { | ||
372 | dval = dval / 1000; | ||
373 | unit = _( /* time unit */ "s"); | ||
374 | if (dval > 5 * 60) | ||
369 | { | 375 | { |
370 | dval = dval / 1000; | 376 | dval = dval / 60; |
371 | unit = _( /* time unit */ "s"); | 377 | unit = _( /* time unit */ "m"); |
372 | if (dval > 5 * 60) | 378 | if (dval > 5 * 60) |
379 | { | ||
380 | dval = dval / 60; | ||
381 | unit = _( /* time unit */ "h"); | ||
382 | if (dval > 5 * 24) | ||
373 | { | 383 | { |
374 | dval = dval / 60; | 384 | dval = dval / 24; |
375 | unit = _( /* time unit */ "m"); | 385 | unit = _( /* time unit */ " days"); |
376 | if (dval > 5 * 60) | ||
377 | { | ||
378 | dval = dval / 60; | ||
379 | unit = _( /* time unit */ "h"); | ||
380 | if (dval > 5 * 24) | ||
381 | { | ||
382 | dval = dval / 24; | ||
383 | unit = _( /* time unit */ " days"); | ||
384 | } | ||
385 | } | ||
386 | } | 386 | } |
387 | } | ||
387 | } | 388 | } |
389 | } | ||
388 | GNUNET_asprintf (&ret, "%llu %s", dval, unit); | 390 | GNUNET_asprintf (&ret, "%llu %s", dval, unit); |
389 | return ret; | 391 | return ret; |
390 | } | 392 | } |
diff --git a/src/util/test_bio.c b/src/util/test_bio.c index bd74baf52..df4becdd1 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c | |||
@@ -41,6 +41,7 @@ test_normal_rw () | |||
41 | struct GNUNET_BIO_ReadHandle *fileR; | 41 | struct GNUNET_BIO_ReadHandle *fileR; |
42 | struct GNUNET_CONTAINER_MetaData *metaDataW; | 42 | struct GNUNET_CONTAINER_MetaData *metaDataW; |
43 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 43 | struct GNUNET_CONTAINER_MetaData *metaDataR; |
44 | |||
44 | metaDataW = GNUNET_CONTAINER_meta_data_create (); | 45 | metaDataW = GNUNET_CONTAINER_meta_data_create (); |
45 | metaDataR = NULL; | 46 | metaDataR = NULL; |
46 | GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); | 47 | GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); |
@@ -65,8 +66,7 @@ test_normal_rw () | |||
65 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 66 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", |
66 | &metaDataR)); | 67 | &metaDataR)); |
67 | GNUNET_assert (GNUNET_YES == | 68 | GNUNET_assert (GNUNET_YES == |
68 | GNUNET_CONTAINER_meta_data_test_equal (metaDataR, | 69 | GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW)); |
69 | metaDataW)); | ||
70 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); | 70 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); |
71 | GNUNET_BIO_read_close (fileR, &msg); | 71 | GNUNET_BIO_read_close (fileR, &msg); |
72 | GNUNET_CONTAINER_meta_data_destroy (metaDataW); | 72 | GNUNET_CONTAINER_meta_data_destroy (metaDataW); |
@@ -173,8 +173,8 @@ test_bigmeta_rw () | |||
173 | meta[sizeof (meta) - 1] = '\0'; | 173 | meta[sizeof (meta) - 1] = '\0'; |
174 | fileW = GNUNET_BIO_write_open (fileName); | 174 | fileW = GNUNET_BIO_write_open (fileName); |
175 | GNUNET_assert (NULL != fileW); | 175 | GNUNET_assert (NULL != fileW); |
176 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof(meta))); | 176 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof (meta))); |
177 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof(meta))); | 177 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof (meta))); |
178 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 178 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); |
179 | 179 | ||
180 | fileR = GNUNET_BIO_read_open (fileName); | 180 | fileR = GNUNET_BIO_read_open (fileName); |
@@ -203,7 +203,8 @@ test_directory_r () | |||
203 | fileR = GNUNET_BIO_read_open ("/dev"); | 203 | fileR = GNUNET_BIO_read_open ("/dev"); |
204 | GNUNET_assert (NULL != fileR); | 204 | GNUNET_assert (NULL != fileR); |
205 | GNUNET_assert (GNUNET_SYSERR == | 205 | GNUNET_assert (GNUNET_SYSERR == |
206 | GNUNET_BIO_read (fileR, "Read error", readResult, sizeof(readResult))); | 206 | GNUNET_BIO_read (fileR, "Read error", readResult, |
207 | sizeof (readResult))); | ||
207 | msg = NULL; | 208 | msg = NULL; |
208 | GNUNET_BIO_read_close (fileR, &msg); | 209 | GNUNET_BIO_read_close (fileR, &msg); |
209 | GNUNET_free (msg); | 210 | GNUNET_free (msg); |
@@ -215,12 +216,12 @@ static int | |||
215 | test_nullfile_rw () | 216 | test_nullfile_rw () |
216 | { | 217 | { |
217 | static char fileNameNO[102401]; | 218 | static char fileNameNO[102401]; |
218 | struct GNUNET_BIO_WriteHandle *fileWNO; | 219 | struct GNUNET_BIO_WriteHandle *fileWNO; |
219 | struct GNUNET_BIO_ReadHandle *fileRNO; | 220 | struct GNUNET_BIO_ReadHandle *fileRNO; |
220 | 221 | ||
221 | memset (fileNameNO, 'a', sizeof (fileNameNO)); | 222 | memset (fileNameNO, 'a', sizeof (fileNameNO)); |
222 | fileNameNO[sizeof (fileNameNO) - 1] = '\0'; | 223 | fileNameNO[sizeof (fileNameNO) - 1] = '\0'; |
223 | 224 | ||
224 | GNUNET_log_skip (1, GNUNET_NO); | 225 | GNUNET_log_skip (1, GNUNET_NO); |
225 | fileWNO = GNUNET_BIO_write_open (fileNameNO); | 226 | fileWNO = GNUNET_BIO_write_open (fileNameNO); |
226 | GNUNET_log_skip (0, GNUNET_YES); | 227 | GNUNET_log_skip (0, GNUNET_YES); |
@@ -237,7 +238,7 @@ test_nullfile_rw () | |||
237 | static int | 238 | static int |
238 | test_fullfile_rw () | 239 | test_fullfile_rw () |
239 | { | 240 | { |
240 | #ifdef LINUX | 241 | #ifdef LINUX |
241 | /* /dev/full only seems to exist on Linux */ | 242 | /* /dev/full only seems to exist on Linux */ |
242 | char *msg; | 243 | char *msg; |
243 | int64_t testNum; | 244 | int64_t testNum; |
@@ -266,7 +267,8 @@ test_fullfile_rw () | |||
266 | fileR = GNUNET_BIO_read_open ("/dev/null"); | 267 | fileR = GNUNET_BIO_read_open ("/dev/null"); |
267 | GNUNET_assert (NULL != fileR); | 268 | GNUNET_assert (NULL != fileR); |
268 | GNUNET_assert (GNUNET_SYSERR == | 269 | GNUNET_assert (GNUNET_SYSERR == |
269 | GNUNET_BIO_read (fileR, "Read error", readResult, sizeof(readResult))); | 270 | GNUNET_BIO_read (fileR, "Read error", readResult, |
271 | sizeof (readResult))); | ||
270 | readResultString = NULL; | 272 | readResultString = NULL; |
271 | GNUNET_assert (GNUNET_SYSERR == | 273 | GNUNET_assert (GNUNET_SYSERR == |
272 | GNUNET_BIO_read_string (fileR, "Read string error", | 274 | GNUNET_BIO_read_string (fileR, "Read string error", |
diff --git a/src/util/test_client.c b/src/util/test_client.c index 3851744c2..9c2abb016 100644 --- a/src/util/test_client.c +++ b/src/util/test_client.c | |||
@@ -79,8 +79,7 @@ echo_cb (void *cls, | |||
79 | 79 | ||
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
81 | "Receiving message from client, bouncing back\n"); | 81 | "Receiving message from client, bouncing back\n"); |
82 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == | 82 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); |
83 | ntohs (message->size)); | ||
84 | cc = GNUNET_malloc (sizeof (struct CopyContext)); | 83 | cc = GNUNET_malloc (sizeof (struct CopyContext)); |
85 | cc->client = client; | 84 | cc->client = client; |
86 | cpy = GNUNET_malloc (ntohs (message->size)); | 85 | cpy = GNUNET_malloc (ntohs (message->size)); |
@@ -107,12 +106,10 @@ recv_bounce (void *cls, const struct GNUNET_MessageHeader *got) | |||
107 | struct GNUNET_MessageHeader msg; | 106 | struct GNUNET_MessageHeader msg; |
108 | 107 | ||
109 | GNUNET_assert (got != NULL); /* timeout */ | 108 | GNUNET_assert (got != NULL); /* timeout */ |
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving bounce, checking content\n"); |
111 | "Receiving bounce, checking content\n"); | ||
112 | msg.type = htons (MY_TYPE); | 110 | msg.type = htons (MY_TYPE); |
113 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 111 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
114 | GNUNET_assert (0 == | 112 | GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); |
115 | memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); | ||
116 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); | 113 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); |
117 | client = NULL; | 114 | client = NULL; |
118 | GNUNET_SERVER_destroy (server); | 115 | GNUNET_SERVER_destroy (server); |
@@ -125,6 +122,7 @@ static size_t | |||
125 | make_msg (void *cls, size_t size, void *buf) | 122 | make_msg (void *cls, size_t size, void *buf) |
126 | { | 123 | { |
127 | struct GNUNET_MessageHeader *msg = buf; | 124 | struct GNUNET_MessageHeader *msg = buf; |
125 | |||
128 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 126 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
129 | msg->type = htons (MY_TYPE); | 127 | msg->type = htons (MY_TYPE); |
130 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 128 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -137,10 +135,10 @@ static void | |||
137 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 135 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
138 | { | 136 | { |
139 | struct sockaddr_in sa; | 137 | struct sockaddr_in sa; |
140 | struct sockaddr * sap[2]; | 138 | struct sockaddr *sap[2]; |
141 | socklen_t slens[2]; | 139 | socklen_t slens[2]; |
142 | 140 | ||
143 | sap[0] = (struct sockaddr*) &sa; | 141 | sap[0] = (struct sockaddr *) &sa; |
144 | slens[0] = sizeof (sa); | 142 | slens[0] = sizeof (sa); |
145 | sap[1] = NULL; | 143 | sap[1] = NULL; |
146 | slens[1] = 0; | 144 | slens[1] = 0; |
@@ -153,7 +151,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
153 | server = GNUNET_SERVER_create (NULL, | 151 | server = GNUNET_SERVER_create (NULL, |
154 | NULL, | 152 | NULL, |
155 | sap, | 153 | sap, |
156 | slens, | 154 | slens, |
157 | GNUNET_TIME_relative_multiply | 155 | GNUNET_TIME_relative_multiply |
158 | (GNUNET_TIME_UNIT_MILLISECONDS, 10000), | 156 | (GNUNET_TIME_UNIT_MILLISECONDS, 10000), |
159 | GNUNET_NO); | 157 | GNUNET_NO); |
@@ -187,8 +185,7 @@ check () | |||
187 | 185 | ||
188 | cfg = GNUNET_CONFIGURATION_create (); | 186 | cfg = GNUNET_CONFIGURATION_create (); |
189 | GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); | 187 | GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); |
190 | GNUNET_CONFIGURATION_set_value_string (cfg, | 188 | GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost"); |
191 | MYNAME, "HOSTNAME", "localhost"); | ||
192 | GNUNET_CONFIGURATION_set_value_string (cfg, | 189 | GNUNET_CONFIGURATION_set_value_string (cfg, |
193 | "resolver", "HOSTNAME", "localhost"); | 190 | "resolver", "HOSTNAME", "localhost"); |
194 | ok = 1; | 191 | ok = 1; |
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c index ed01e8a6a..950f0cedb 100644 --- a/src/util/test_common_allocation.c +++ b/src/util/test_common_allocation.c | |||
@@ -38,19 +38,19 @@ check () | |||
38 | /* GNUNET_malloc/GNUNET_free test */ | 38 | /* GNUNET_malloc/GNUNET_free test */ |
39 | k = 352; /* random start value */ | 39 | k = 352; /* random start value */ |
40 | for (i = 1; i < MAX_TESTVAL; i++) | 40 | for (i = 1; i < MAX_TESTVAL; i++) |
41 | { | 41 | { |
42 | ptrs[i] = GNUNET_malloc (i); | 42 | ptrs[i] = GNUNET_malloc (i); |
43 | for (j = 0; j < i; j++) | 43 | for (j = 0; j < i; j++) |
44 | ptrs[i][j] = k++; | 44 | ptrs[i][j] = k++; |
45 | } | 45 | } |
46 | 46 | ||
47 | for (i = MAX_TESTVAL - 1; i >= 1; i--) | 47 | for (i = MAX_TESTVAL - 1; i >= 1; i--) |
48 | { | 48 | { |
49 | for (j = i - 1; j >= 0; j--) | 49 | for (j = i - 1; j >= 0; j--) |
50 | if (ptrs[i][j] != (char) --k) | 50 | if (ptrs[i][j] != (char) --k) |
51 | return 1; | 51 | return 1; |
52 | GNUNET_free (ptrs[i]); | 52 | GNUNET_free (ptrs[i]); |
53 | } | 53 | } |
54 | 54 | ||
55 | /* GNUNET_free_non_null test */ | 55 | /* GNUNET_free_non_null test */ |
56 | GNUNET_free_non_null (NULL); | 56 | GNUNET_free_non_null (NULL); |
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c index 0d038c911..da200d62a 100644 --- a/src/util/test_common_logging.c +++ b/src/util/test_common_logging.c | |||
@@ -31,6 +31,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, | |||
31 | const char *component, const char *date, const char *msg) | 31 | const char *component, const char *date, const char *msg) |
32 | { | 32 | { |
33 | unsigned int *c = ctx; | 33 | unsigned int *c = ctx; |
34 | |||
34 | (*c)++; | 35 | (*c)++; |
35 | } | 36 | } |
36 | 37 | ||
@@ -56,26 +57,23 @@ main (int argc, char *argv[]) | |||
56 | /* the last 6 calls should be merged (repated bulk messages!) */ | 57 | /* the last 6 calls should be merged (repated bulk messages!) */ |
57 | GNUNET_logger_remove (&my_log, &logs); | 58 | GNUNET_logger_remove (&my_log, &logs); |
58 | if (logs != 4) | 59 | if (logs != 4) |
59 | { | 60 | { |
60 | fprintf (stdout, "Expected 4 log calls, got %u\n", logs); | 61 | fprintf (stdout, "Expected 4 log calls, got %u\n", logs); |
61 | failureCount++; | 62 | failureCount++; |
62 | } | 63 | } |
63 | GNUNET_break (0 == | 64 | GNUNET_break (0 == |
64 | strcmp (_("ERROR"), | 65 | strcmp (_("ERROR"), |
65 | GNUNET_error_type_to_string | 66 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_ERROR))); |
66 | (GNUNET_ERROR_TYPE_ERROR))); | ||
67 | GNUNET_break (0 == | 67 | GNUNET_break (0 == |
68 | strcmp (_("WARNING"), | 68 | strcmp (_("WARNING"), |
69 | GNUNET_error_type_to_string | 69 | GNUNET_error_type_to_string |
70 | (GNUNET_ERROR_TYPE_WARNING))); | 70 | (GNUNET_ERROR_TYPE_WARNING))); |
71 | GNUNET_break (0 == | 71 | GNUNET_break (0 == |
72 | strcmp (_("INFO"), | 72 | strcmp (_("INFO"), |
73 | GNUNET_error_type_to_string | 73 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_INFO))); |
74 | (GNUNET_ERROR_TYPE_INFO))); | ||
75 | GNUNET_break (0 == | 74 | GNUNET_break (0 == |
76 | strcmp (_("DEBUG"), | 75 | strcmp (_("DEBUG"), |
77 | GNUNET_error_type_to_string | 76 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG))); |
78 | (GNUNET_ERROR_TYPE_DEBUG))); | ||
79 | GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null"); | 77 | GNUNET_log_setup ("test_common_logging", "WARNING", "/dev/null"); |
80 | logs = 0; | 78 | logs = 0; |
81 | GNUNET_logger_add (&my_log, &logs); | 79 | GNUNET_logger_add (&my_log, &logs); |
@@ -83,16 +81,16 @@ main (int argc, char *argv[]) | |||
83 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n"); | 81 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Drop me...\n"); |
84 | GNUNET_logger_remove (&my_log, &logs); | 82 | GNUNET_logger_remove (&my_log, &logs); |
85 | if (logs != 1) | 83 | if (logs != 1) |
86 | { | 84 | { |
87 | fprintf (stdout, "Expected 1 log call, got %u\n", logs); | 85 | fprintf (stdout, "Expected 1 log call, got %u\n", logs); |
88 | failureCount++; | 86 | failureCount++; |
89 | } | 87 | } |
90 | 88 | ||
91 | if (failureCount != 0) | 89 | if (failureCount != 0) |
92 | { | 90 | { |
93 | fprintf (stdout, "%u TESTS FAILED!\n", failureCount); | 91 | fprintf (stdout, "%u TESTS FAILED!\n", failureCount); |
94 | return -1; | 92 | return -1; |
95 | } | 93 | } |
96 | return 0; | 94 | return 0; |
97 | } /* end of main */ | 95 | } /* end of main */ |
98 | 96 | ||
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 365161e34..8bad5b5d4 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c | |||
@@ -42,7 +42,7 @@ enum | |||
42 | REMOVE_ENTRY, | 42 | REMOVE_ENTRY, |
43 | COMPARE | 43 | COMPARE |
44 | #if DEBUG | 44 | #if DEBUG |
45 | 45 | ||
46 | #endif | 46 | #endif |
47 | }; | 47 | }; |
48 | 48 | ||
@@ -76,79 +76,80 @@ initDiffsCBData (struct DiffsCBData *cbData) | |||
76 | */ | 76 | */ |
77 | static void | 77 | static void |
78 | diffsCallBack (void *cls, | 78 | diffsCallBack (void *cls, |
79 | const char *section, const char *option, const char *value) | 79 | const char *section, const char *option, const char *value) |
80 | { | 80 | { |
81 | struct DiffsCBData *cbData = cls; | 81 | struct DiffsCBData *cbData = cls; |
82 | int cbOption = cbData->callBackOption; | 82 | int cbOption = cbData->callBackOption; |
83 | 83 | ||
84 | switch (cbOption) | 84 | switch (cbOption) |
85 | { | ||
86 | case EDIT_SECTION: | ||
87 | if (NULL == cbData->section) | ||
88 | cbData->section = section; | ||
89 | if (strcmp (cbData->section, section) == 0) | ||
85 | { | 90 | { |
86 | case EDIT_SECTION: | ||
87 | if (NULL == cbData->section) | ||
88 | cbData->section = section; | ||
89 | if (strcmp (cbData->section, section) == 0) | ||
90 | { | ||
91 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, | ||
92 | "new-value"); | ||
93 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, | ||
94 | option, "new-value"); | ||
95 | } | ||
96 | break; | ||
97 | case EDIT_ALL: | ||
98 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, | 91 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, |
99 | "new-value"); | 92 | "new-value"); |
100 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, | 93 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, |
101 | option, "new-value"); | 94 | option, "new-value"); |
102 | break; | 95 | } |
103 | case ADD_NEW_ENTRY: | 96 | break; |
104 | { | 97 | case EDIT_ALL: |
105 | static int hit = 0; | 98 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, |
106 | if (hit == 0) | 99 | "new-value"); |
107 | { | 100 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, |
108 | hit = 1; | 101 | option, "new-value"); |
109 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, | 102 | break; |
110 | "new-key", "new-value"); | 103 | case ADD_NEW_ENTRY: |
111 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, | 104 | { |
112 | "new-key", "new-value"); | 105 | static int hit = 0; |
113 | } | 106 | |
114 | break; | 107 | if (hit == 0) |
115 | } | 108 | { |
116 | case COMPARE: | 109 | hit = 1; |
117 | { | 110 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, |
118 | int ret; | 111 | "new-key", "new-value"); |
119 | char *diffValue; | 112 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, |
120 | 113 | "new-key", "new-value"); | |
121 | diffValue = NULL; | 114 | } |
122 | ret = | 115 | break; |
123 | GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section, | 116 | } |
124 | option, &diffValue); | 117 | case COMPARE: |
125 | if (NULL != diffValue) | 118 | { |
126 | { | 119 | int ret; |
127 | if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0) | 120 | char *diffValue; |
128 | cbData->status = 1; | 121 | |
129 | } | 122 | diffValue = NULL; |
130 | else | 123 | ret = |
131 | cbData->status = 1; | 124 | GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section, |
132 | GNUNET_free_non_null (diffValue); | 125 | option, &diffValue); |
133 | break; | 126 | if (NULL != diffValue) |
134 | } | 127 | { |
128 | if (ret == GNUNET_SYSERR || strcmp (diffValue, value) != 0) | ||
129 | cbData->status = 1; | ||
130 | } | ||
131 | else | ||
132 | cbData->status = 1; | ||
133 | GNUNET_free_non_null (diffValue); | ||
134 | break; | ||
135 | } | ||
135 | #if DEBUG | 136 | #if DEBUG |
136 | case PRINT: | 137 | case PRINT: |
137 | if (NULL == cbData->section) | 138 | if (NULL == cbData->section) |
138 | { | 139 | { |
139 | cbData->section = section; | 140 | cbData->section = section; |
140 | printf ("\nSection: %s\n", section); | 141 | printf ("\nSection: %s\n", section); |
141 | } | 142 | } |
142 | else if (strcmp (cbData->section, section) != 0) | 143 | else if (strcmp (cbData->section, section) != 0) |
143 | { | 144 | { |
144 | cbData->section = section; | 145 | cbData->section = section; |
145 | printf ("\nSection: %s\n", section); | 146 | printf ("\nSection: %s\n", section); |
146 | } | ||
147 | printf ("%s = %s\n", option, value); | ||
148 | #endif | ||
149 | default: | ||
150 | break; | ||
151 | } | 147 | } |
148 | printf ("%s = %s\n", option, value); | ||
149 | #endif | ||
150 | default: | ||
151 | break; | ||
152 | } | ||
152 | } | 153 | } |
153 | 154 | ||
154 | 155 | ||
@@ -156,44 +157,45 @@ static struct GNUNET_CONFIGURATION_Handle * | |||
156 | editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option) | 157 | editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option) |
157 | { | 158 | { |
158 | struct DiffsCBData diffsCB; | 159 | struct DiffsCBData diffsCB; |
160 | |||
159 | initDiffsCBData (&diffsCB); | 161 | initDiffsCBData (&diffsCB); |
160 | diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create (); | 162 | diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create (); |
161 | 163 | ||
162 | switch (option) | 164 | switch (option) |
165 | { | ||
166 | case EDIT_SECTION: | ||
167 | case EDIT_ALL: | ||
168 | case ADD_NEW_ENTRY: | ||
169 | diffsCB.callBackOption = option; | ||
170 | diffsCB.cfg = cfg; | ||
171 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB); | ||
172 | break; | ||
173 | case EDIT_NOTHING: | ||
174 | /* Do nothing */ | ||
175 | break; | ||
176 | case ADD_NEW_SECTION: | ||
177 | { | ||
178 | int i; | ||
179 | char *key; | ||
180 | |||
181 | for (i = 0; i < 5; i++) | ||
163 | { | 182 | { |
164 | case EDIT_SECTION: | 183 | GNUNET_asprintf (&key, "key%d", i); |
165 | case EDIT_ALL: | 184 | GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, |
166 | case ADD_NEW_ENTRY: | 185 | "new-value"); |
167 | diffsCB.callBackOption = option; | 186 | GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, |
168 | diffsCB.cfg = cfg; | 187 | "new-section", key, "new-value"); |
169 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB); | 188 | GNUNET_free (key); |
170 | break; | ||
171 | case EDIT_NOTHING: | ||
172 | /* Do nothing */ | ||
173 | break; | ||
174 | case ADD_NEW_SECTION: | ||
175 | { | ||
176 | int i; | ||
177 | char *key; | ||
178 | for (i = 0; i < 5; i++) | ||
179 | { | ||
180 | GNUNET_asprintf (&key, "key%d", i); | ||
181 | GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, | ||
182 | "new-value"); | ||
183 | GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, | ||
184 | "new-section", key, | ||
185 | "new-value"); | ||
186 | GNUNET_free (key); | ||
187 | } | ||
188 | break; | ||
189 | } | ||
190 | case REMOVE_SECTION: | ||
191 | break; | ||
192 | case REMOVE_ENTRY: | ||
193 | break; | ||
194 | default: | ||
195 | break; | ||
196 | } | 189 | } |
190 | break; | ||
191 | } | ||
192 | case REMOVE_SECTION: | ||
193 | break; | ||
194 | case REMOVE_ENTRY: | ||
195 | break; | ||
196 | default: | ||
197 | break; | ||
198 | } | ||
197 | 199 | ||
198 | return diffsCB.cfgDiffs; | 200 | return diffsCB.cfgDiffs; |
199 | } | 201 | } |
@@ -218,15 +220,14 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option) | |||
218 | 220 | ||
219 | /* Modify configuration and save it */ | 221 | /* Modify configuration and save it */ |
220 | cfgDiffs = editConfiguration (cfg, option); | 222 | cfgDiffs = editConfiguration (cfg, option); |
221 | diffsFileName = | 223 | diffsFileName = GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf"); |
222 | GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf"); | ||
223 | if (diffsFileName == NULL) | 224 | if (diffsFileName == NULL) |
224 | { | 225 | { |
225 | GNUNET_break (0); | 226 | GNUNET_break (0); |
226 | GNUNET_CONFIGURATION_destroy (cfg); | 227 | GNUNET_CONFIGURATION_destroy (cfg); |
227 | GNUNET_CONFIGURATION_destroy (cfgDiffs); | 228 | GNUNET_CONFIGURATION_destroy (cfgDiffs); |
228 | return 1; | 229 | return 1; |
229 | } | 230 | } |
230 | GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName); | 231 | GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName); |
231 | GNUNET_CONFIGURATION_destroy (cfg); | 232 | GNUNET_CONFIGURATION_destroy (cfg); |
232 | 233 | ||
@@ -238,16 +239,16 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option) | |||
238 | cbData.cfgDiffs = cfgDiffs; | 239 | cbData.cfgDiffs = cfgDiffs; |
239 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); | 240 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); |
240 | if (1 == (ret = cbData.status)) | 241 | if (1 == (ret = cbData.status)) |
241 | { | 242 | { |
242 | fprintf (stderr, | 243 | fprintf (stderr, |
243 | "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); | 244 | "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); |
244 | goto housekeeping; | 245 | goto housekeeping; |
245 | } | 246 | } |
246 | cbData.cfgDiffs = cfg; | 247 | cbData.cfgDiffs = cfg; |
247 | GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); | 248 | GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); |
248 | if ((ret = cbData.status) == 1) | 249 | if ((ret = cbData.status) == 1) |
249 | fprintf (stderr, | 250 | fprintf (stderr, |
250 | "Incorrect Configuration Diffs: Data may be missing in diffs\n"); | 251 | "Incorrect Configuration Diffs: Data may be missing in diffs\n"); |
251 | 252 | ||
252 | housekeeping: | 253 | housekeeping: |
253 | #if DEBUG | 254 | #if DEBUG |
@@ -272,65 +273,64 @@ testConfig () | |||
272 | char *c; | 273 | char *c; |
273 | unsigned long long l; | 274 | unsigned long long l; |
274 | 275 | ||
275 | if (GNUNET_OK != | 276 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c)) |
276 | GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c)) | ||
277 | return 1; | 277 | return 1; |
278 | if (0 != strcmp ("b", c)) | 278 | if (0 != strcmp ("b", c)) |
279 | { | 279 | { |
280 | fprintf (stderr, "Got `%s'\n", c); | 280 | fprintf (stderr, "Got `%s'\n", c); |
281 | GNUNET_free (c); | 281 | GNUNET_free (c); |
282 | return 2; | 282 | return 2; |
283 | } | 283 | } |
284 | GNUNET_free (c); | 284 | GNUNET_free (c); |
285 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | 285 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
286 | "test", "five", &l)) | 286 | "test", "five", &l)) |
287 | { | 287 | { |
288 | GNUNET_break (0); | 288 | GNUNET_break (0); |
289 | return 3; | 289 | return 3; |
290 | } | 290 | } |
291 | if (5 != l) | 291 | if (5 != l) |
292 | { | 292 | { |
293 | GNUNET_break (0); | 293 | GNUNET_break (0); |
294 | return 4; | 294 | return 4; |
295 | } | 295 | } |
296 | GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES"); | 296 | GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES"); |
297 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c")) | 297 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c")) |
298 | { | 298 | { |
299 | GNUNET_break (0); | 299 | GNUNET_break (0); |
300 | return 5; | 300 | return 5; |
301 | } | 301 | } |
302 | GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10); | 302 | GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10); |
303 | if (GNUNET_OK != | 303 | if (GNUNET_OK != |
304 | GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c)) | 304 | GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c)) |
305 | { | 305 | { |
306 | GNUNET_break (0); | 306 | GNUNET_break (0); |
307 | return 6; | 307 | return 6; |
308 | } | 308 | } |
309 | if (0 != strcmp (c, "10")) | 309 | if (0 != strcmp (c, "10")) |
310 | { | 310 | { |
311 | GNUNET_free (c); | 311 | GNUNET_free (c); |
312 | GNUNET_break (0); | 312 | GNUNET_break (0); |
313 | return 7; | 313 | return 7; |
314 | } | 314 | } |
315 | GNUNET_free (c); | 315 | GNUNET_free (c); |
316 | 316 | ||
317 | if (GNUNET_OK != | 317 | if (GNUNET_OK != |
318 | GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c)) | 318 | GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c)) |
319 | { | 319 | { |
320 | GNUNET_break (0); | 320 | GNUNET_break (0); |
321 | return 8; | 321 | return 8; |
322 | } | 322 | } |
323 | #ifndef MINGW | 323 | #ifndef MINGW |
324 | if (0 != strcmp (c, "/hello/world")) | 324 | if (0 != strcmp (c, "/hello/world")) |
325 | #else | 325 | #else |
326 | #define HI "\\hello\\world" | 326 | #define HI "\\hello\\world" |
327 | if (strstr (c, HI) != c + strlen (c) - strlen (HI)) | 327 | if (strstr (c, HI) != c + strlen (c) - strlen (HI)) |
328 | #endif | 328 | #endif |
329 | { | 329 | { |
330 | GNUNET_break (0); | 330 | GNUNET_break (0); |
331 | GNUNET_free (c); | 331 | GNUNET_free (c); |
332 | return 9; | 332 | return 9; |
333 | } | 333 | } |
334 | GNUNET_free (c); | 334 | GNUNET_free (c); |
335 | 335 | ||
336 | return 0; | 336 | return 0; |
@@ -350,10 +350,10 @@ check (void *data, const char *fn) | |||
350 | int *idx = data; | 350 | int *idx = data; |
351 | 351 | ||
352 | if (0 == strcmp (want[*idx], fn)) | 352 | if (0 == strcmp (want[*idx], fn)) |
353 | { | 353 | { |
354 | (*idx)++; | 354 | (*idx)++; |
355 | return GNUNET_OK; | 355 | return GNUNET_OK; |
356 | } | 356 | } |
357 | GNUNET_break (0); | 357 | GNUNET_break (0); |
358 | return GNUNET_SYSERR; | 358 | return GNUNET_SYSERR; |
359 | } | 359 | } |
@@ -365,93 +365,90 @@ testConfigFilenames () | |||
365 | 365 | ||
366 | idx = 0; | 366 | idx = 0; |
367 | if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, | 367 | if (3 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, |
368 | "FILENAMES", | 368 | "FILENAMES", |
369 | "test", | 369 | "test", &check, &idx)) |
370 | &check, &idx)) | 370 | { |
371 | { | 371 | GNUNET_break (0); |
372 | GNUNET_break (0); | 372 | return 8; |
373 | return 8; | 373 | } |
374 | } | ||
375 | if (idx != 3) | 374 | if (idx != 3) |
376 | return 16; | 375 | return 16; |
377 | if (GNUNET_OK != | 376 | if (GNUNET_OK != |
378 | GNUNET_CONFIGURATION_remove_value_filename (cfg, | 377 | GNUNET_CONFIGURATION_remove_value_filename (cfg, |
379 | "FILENAMES", | 378 | "FILENAMES", |
380 | "test", "/File Name")) | 379 | "test", "/File Name")) |
381 | { | 380 | { |
382 | GNUNET_break (0); | 381 | GNUNET_break (0); |
383 | return 24; | 382 | return 24; |
384 | } | 383 | } |
385 | 384 | ||
386 | if (GNUNET_NO != | 385 | if (GNUNET_NO != |
387 | GNUNET_CONFIGURATION_remove_value_filename (cfg, | 386 | GNUNET_CONFIGURATION_remove_value_filename (cfg, |
388 | "FILENAMES", | 387 | "FILENAMES", |
389 | "test", "/File Name")) | 388 | "test", "/File Name")) |
390 | { | 389 | { |
391 | GNUNET_break (0); | 390 | GNUNET_break (0); |
392 | return 32; | 391 | return 32; |
393 | } | 392 | } |
394 | if (GNUNET_NO != | 393 | if (GNUNET_NO != |
395 | GNUNET_CONFIGURATION_remove_value_filename (cfg, | 394 | GNUNET_CONFIGURATION_remove_value_filename (cfg, |
396 | "FILENAMES", | 395 | "FILENAMES", "test", "Stuff")) |
397 | "test", "Stuff")) | 396 | { |
398 | { | 397 | GNUNET_break (0); |
399 | GNUNET_break (0); | 398 | return 40; |
400 | return 40; | 399 | } |
401 | } | ||
402 | 400 | ||
403 | if (GNUNET_NO != | 401 | if (GNUNET_NO != |
404 | GNUNET_CONFIGURATION_append_value_filename (cfg, | 402 | GNUNET_CONFIGURATION_append_value_filename (cfg, |
405 | "FILENAMES", | 403 | "FILENAMES", |
406 | "test", "/Hello")) | 404 | "test", "/Hello")) |
407 | { | 405 | { |
408 | GNUNET_break (0); | 406 | GNUNET_break (0); |
409 | return 48; | 407 | return 48; |
410 | } | 408 | } |
411 | if (GNUNET_NO != | 409 | if (GNUNET_NO != |
412 | GNUNET_CONFIGURATION_append_value_filename (cfg, | 410 | GNUNET_CONFIGURATION_append_value_filename (cfg, |
413 | "FILENAMES", | 411 | "FILENAMES", |
414 | "test", "/World")) | 412 | "test", "/World")) |
415 | { | 413 | { |
416 | GNUNET_break (0); | 414 | GNUNET_break (0); |
417 | return 56; | 415 | return 56; |
418 | } | 416 | } |
419 | 417 | ||
420 | if (GNUNET_YES != | 418 | if (GNUNET_YES != |
421 | GNUNET_CONFIGURATION_append_value_filename (cfg, | 419 | GNUNET_CONFIGURATION_append_value_filename (cfg, |
422 | "FILENAMES", | 420 | "FILENAMES", |
423 | "test", "/File 1")) | 421 | "test", "/File 1")) |
424 | { | 422 | { |
425 | GNUNET_break (0); | 423 | GNUNET_break (0); |
426 | return 64; | 424 | return 64; |
427 | } | 425 | } |
428 | 426 | ||
429 | if (GNUNET_YES != | 427 | if (GNUNET_YES != |
430 | GNUNET_CONFIGURATION_append_value_filename (cfg, | 428 | GNUNET_CONFIGURATION_append_value_filename (cfg, |
431 | "FILENAMES", | 429 | "FILENAMES", |
432 | "test", "/File 2")) | 430 | "test", "/File 2")) |
433 | { | 431 | { |
434 | GNUNET_break (0); | 432 | GNUNET_break (0); |
435 | return 72; | 433 | return 72; |
436 | } | 434 | } |
437 | 435 | ||
438 | idx = 0; | 436 | idx = 0; |
439 | want[1] = "/World"; | 437 | want[1] = "/World"; |
440 | want[2] = "/File 1"; | 438 | want[2] = "/File 1"; |
441 | want[3] = "/File 2"; | 439 | want[3] = "/File 2"; |
442 | if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, | 440 | if (4 != GNUNET_CONFIGURATION_iterate_value_filenames (cfg, |
443 | "FILENAMES", | 441 | "FILENAMES", |
444 | "test", | 442 | "test", &check, &idx)) |
445 | &check, &idx)) | 443 | { |
446 | { | 444 | GNUNET_break (0); |
447 | GNUNET_break (0); | 445 | return 80; |
448 | return 80; | 446 | } |
449 | } | ||
450 | if (idx != 4) | 447 | if (idx != 4) |
451 | { | 448 | { |
452 | GNUNET_break (0); | 449 | GNUNET_break (0); |
453 | return 88; | 450 | return 88; |
454 | } | 451 | } |
455 | return 0; | 452 | return 0; |
456 | } | 453 | } |
457 | 454 | ||
@@ -467,11 +464,11 @@ main (int argc, char *argv[]) | |||
467 | GNUNET_assert (cfg != NULL); | 464 | GNUNET_assert (cfg != NULL); |
468 | if (GNUNET_OK != | 465 | if (GNUNET_OK != |
469 | GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) | 466 | GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) |
470 | { | 467 | { |
471 | fprintf (stderr, "Failed to parse configuration file\n"); | 468 | fprintf (stderr, "Failed to parse configuration file\n"); |
472 | GNUNET_CONFIGURATION_destroy (cfg); | 469 | GNUNET_CONFIGURATION_destroy (cfg); |
473 | return 1; | 470 | return 1; |
474 | } | 471 | } |
475 | failureCount += testConfig (); | 472 | failureCount += testConfig (); |
476 | if (failureCount > 0) | 473 | if (failureCount > 0) |
477 | goto error; | 474 | goto error; |
@@ -481,37 +478,36 @@ main (int argc, char *argv[]) | |||
481 | goto error; | 478 | goto error; |
482 | 479 | ||
483 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) | 480 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) |
484 | { | 481 | { |
485 | fprintf (stderr, "Failed to write configuration file\n"); | 482 | fprintf (stderr, "Failed to write configuration file\n"); |
486 | GNUNET_CONFIGURATION_destroy (cfg); | 483 | GNUNET_CONFIGURATION_destroy (cfg); |
487 | return 1; | 484 | return 1; |
488 | } | 485 | } |
489 | GNUNET_CONFIGURATION_destroy (cfg); | 486 | GNUNET_CONFIGURATION_destroy (cfg); |
490 | GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); | 487 | GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); |
491 | 488 | ||
492 | cfg = GNUNET_CONFIGURATION_create (); | 489 | cfg = GNUNET_CONFIGURATION_create (); |
493 | if (GNUNET_OK != | 490 | if (GNUNET_OK != |
494 | GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) | 491 | GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) |
495 | { | 492 | { |
496 | GNUNET_break (0); | 493 | GNUNET_break (0); |
497 | GNUNET_CONFIGURATION_destroy (cfg); | 494 | GNUNET_CONFIGURATION_destroy (cfg); |
498 | return 1; | 495 | return 1; |
499 | } | 496 | } |
500 | if (GNUNET_OK != | 497 | if (GNUNET_OK != |
501 | GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", | 498 | GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c)) |
502 | &c)) | 499 | { |
503 | { | 500 | GNUNET_break (0); |
504 | GNUNET_break (0); | 501 | GNUNET_CONFIGURATION_destroy (cfg); |
505 | GNUNET_CONFIGURATION_destroy (cfg); | 502 | return 1; |
506 | return 1; | 503 | } |
507 | } | ||
508 | if (0 != strcmp (c, "YES")) | 504 | if (0 != strcmp (c, "YES")) |
509 | { | 505 | { |
510 | GNUNET_break (0); | 506 | GNUNET_break (0); |
511 | GNUNET_free (c); | 507 | GNUNET_free (c); |
512 | GNUNET_CONFIGURATION_destroy (cfg); | 508 | GNUNET_CONFIGURATION_destroy (cfg); |
513 | return 1; | 509 | return 1; |
514 | } | 510 | } |
515 | 511 | ||
516 | GNUNET_free (c); | 512 | GNUNET_free (c); |
517 | GNUNET_CONFIGURATION_destroy (cfg); | 513 | GNUNET_CONFIGURATION_destroy (cfg); |
@@ -519,11 +515,11 @@ main (int argc, char *argv[]) | |||
519 | /* Testing configuration diffs */ | 515 | /* Testing configuration diffs */ |
520 | cfgDefault = GNUNET_CONFIGURATION_create (); | 516 | cfgDefault = GNUNET_CONFIGURATION_create (); |
521 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL)) | 517 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL)) |
522 | { | 518 | { |
523 | GNUNET_break (0); | 519 | GNUNET_break (0); |
524 | GNUNET_CONFIGURATION_destroy (cfgDefault); | 520 | GNUNET_CONFIGURATION_destroy (cfgDefault); |
525 | return 1; | 521 | return 1; |
526 | } | 522 | } |
527 | 523 | ||
528 | /* Nothing changed in the new configuration */ | 524 | /* Nothing changed in the new configuration */ |
529 | failureCount += checkDiffs (cfgDefault, EDIT_NOTHING); | 525 | failureCount += checkDiffs (cfgDefault, EDIT_NOTHING); |
@@ -544,9 +540,9 @@ main (int argc, char *argv[]) | |||
544 | 540 | ||
545 | error: | 541 | error: |
546 | if (failureCount != 0) | 542 | if (failureCount != 0) |
547 | { | 543 | { |
548 | fprintf (stderr, "Test failed: %u\n", failureCount); | 544 | fprintf (stderr, "Test failed: %u\n", failureCount); |
549 | return 1; | 545 | return 1; |
550 | } | 546 | } |
551 | return 0; | 547 | return 0; |
552 | } | 548 | } |
diff --git a/src/util/test_connection.c b/src/util/test_connection.c index 71b37c8ac..3519522ef 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c | |||
@@ -66,8 +66,7 @@ open_listen_socket () | |||
66 | GNUNET_assert (desc != NULL); | 66 | GNUNET_assert (desc != NULL); |
67 | if (GNUNET_NETWORK_socket_setsockopt | 67 | if (GNUNET_NETWORK_socket_setsockopt |
68 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 68 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
70 | "setsockopt"); | ||
71 | GNUNET_assert (GNUNET_NETWORK_socket_bind | 70 | GNUNET_assert (GNUNET_NETWORK_socket_bind |
72 | (desc, (const struct sockaddr *) &sa, | 71 | (desc, (const struct sockaddr *) &sa, |
73 | sizeof (sa)) == GNUNET_OK); | 72 | sizeof (sa)) == GNUNET_OK); |
@@ -90,25 +89,24 @@ receive_check (void *cls, | |||
90 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) | 89 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) |
91 | sofar += available; | 90 | sofar += available; |
92 | if (sofar < 12) | 91 | if (sofar < 12) |
93 | { | 92 | { |
94 | #if VERBOSE | 93 | #if VERBOSE |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); |
96 | #endif | 95 | #endif |
97 | GNUNET_CONNECTION_receive (asock, | 96 | GNUNET_CONNECTION_receive (asock, |
98 | 1024, | 97 | 1024, |
99 | GNUNET_TIME_relative_multiply | 98 | GNUNET_TIME_relative_multiply |
100 | (GNUNET_TIME_UNIT_SECONDS, 5), | 99 | (GNUNET_TIME_UNIT_SECONDS, 5), |
101 | &receive_check, cls); | 100 | &receive_check, cls); |
102 | } | 101 | } |
103 | else | 102 | else |
104 | { | 103 | { |
105 | #if VERBOSE | 104 | #if VERBOSE |
106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive closes accepted socket\n"); |
107 | "Receive closes accepted socket\n"); | ||
108 | #endif | 106 | #endif |
109 | *ok = 0; | 107 | *ok = 0; |
110 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); | 108 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); |
111 | } | 109 | } |
112 | } | 110 | } |
113 | 111 | ||
114 | 112 | ||
@@ -158,8 +156,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
158 | ls = open_listen_socket (); | 156 | ls = open_listen_socket (); |
159 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | 157 | lsock = GNUNET_CONNECTION_create_from_existing (ls); |
160 | GNUNET_assert (lsock != NULL); | 158 | GNUNET_assert (lsock != NULL); |
161 | csock = GNUNET_CONNECTION_create_from_connect (cfg, | 159 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); |
162 | "localhost", PORT); | ||
163 | GNUNET_assert (csock != NULL); | 160 | GNUNET_assert (csock != NULL); |
164 | #if VERBOSE | 161 | #if VERBOSE |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); |
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index f5328be92..111894a36 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c | |||
@@ -66,15 +66,15 @@ open_listen_socket () | |||
66 | GNUNET_assert (desc != 0); | 66 | GNUNET_assert (desc != 0); |
67 | if (GNUNET_NETWORK_socket_setsockopt | 67 | if (GNUNET_NETWORK_socket_setsockopt |
68 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 68 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
70 | "setsockopt"); | ||
71 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (desc, | 70 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (desc, |
72 | (const struct sockaddr *) &sa, sizeof(sa))) | 71 | (const struct sockaddr *) &sa, |
73 | { | 72 | sizeof (sa))) |
74 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 73 | { |
75 | "bind"); | 74 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
76 | GNUNET_assert (0); | 75 | "bind"); |
77 | } | 76 | GNUNET_assert (0); |
77 | } | ||
78 | GNUNET_NETWORK_socket_listen (desc, 5); | 78 | GNUNET_NETWORK_socket_listen (desc, 5); |
79 | return desc; | 79 | return desc; |
80 | } | 80 | } |
@@ -92,18 +92,18 @@ receive_check (void *cls, | |||
92 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) | 92 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) |
93 | sofar += available; | 93 | sofar += available; |
94 | if (sofar < 12) | 94 | if (sofar < 12) |
95 | { | 95 | { |
96 | GNUNET_CONNECTION_receive (asock, | 96 | GNUNET_CONNECTION_receive (asock, |
97 | 1024, | 97 | 1024, |
98 | GNUNET_TIME_relative_multiply | 98 | GNUNET_TIME_relative_multiply |
99 | (GNUNET_TIME_UNIT_SECONDS, 5), | 99 | (GNUNET_TIME_UNIT_SECONDS, 5), |
100 | &receive_check, cls); | 100 | &receive_check, cls); |
101 | } | 101 | } |
102 | else | 102 | else |
103 | { | 103 | { |
104 | *ok = 0; | 104 | *ok = 0; |
105 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); | 105 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
@@ -151,6 +151,7 @@ static void | |||
151 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 151 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
152 | { | 152 | { |
153 | struct sockaddr_in v4; | 153 | struct sockaddr_in v4; |
154 | |||
154 | ls = open_listen_socket (); | 155 | ls = open_listen_socket (); |
155 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | 156 | lsock = GNUNET_CONNECTION_create_from_existing (ls); |
156 | GNUNET_assert (lsock != NULL); | 157 | GNUNET_assert (lsock != NULL); |
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index 1e6720235..d635f5742 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c | |||
@@ -65,8 +65,7 @@ open_listen_socket () | |||
65 | GNUNET_assert (desc != NULL); | 65 | GNUNET_assert (desc != NULL); |
66 | if (GNUNET_NETWORK_socket_setsockopt | 66 | if (GNUNET_NETWORK_socket_setsockopt |
67 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 67 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
68 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 68 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
69 | "setsockopt"); | ||
70 | GNUNET_assert (GNUNET_NETWORK_socket_bind | 69 | GNUNET_assert (GNUNET_NETWORK_socket_bind |
71 | (desc, (const struct sockaddr *) &sa, | 70 | (desc, (const struct sockaddr *) &sa, |
72 | sizeof (sa)) == GNUNET_OK); | 71 | sizeof (sa)) == GNUNET_OK); |
@@ -97,8 +96,7 @@ run_accept_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
97 | GNUNET_CONNECTION_receive (asock, | 96 | GNUNET_CONNECTION_receive (asock, |
98 | 1024, | 97 | 1024, |
99 | GNUNET_TIME_relative_multiply | 98 | GNUNET_TIME_relative_multiply |
100 | (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, | 99 | (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls); |
101 | cls); | ||
102 | } | 100 | } |
103 | 101 | ||
104 | 102 | ||
@@ -106,6 +104,7 @@ static void | |||
106 | receive_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 104 | receive_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
107 | { | 105 | { |
108 | int *ok = cls; | 106 | int *ok = cls; |
107 | |||
109 | GNUNET_CONNECTION_receive_cancel (asock); | 108 | GNUNET_CONNECTION_receive_cancel (asock); |
110 | GNUNET_CONNECTION_destroy (csock, GNUNET_YES); | 109 | GNUNET_CONNECTION_destroy (csock, GNUNET_YES); |
111 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); | 110 | GNUNET_CONNECTION_destroy (asock, GNUNET_YES); |
@@ -120,8 +119,7 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
120 | ls = open_listen_socket (); | 119 | ls = open_listen_socket (); |
121 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | 120 | lsock = GNUNET_CONNECTION_create_from_existing (ls); |
122 | GNUNET_assert (lsock != NULL); | 121 | GNUNET_assert (lsock != NULL); |
123 | csock = GNUNET_CONNECTION_create_from_connect (cfg, | 122 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); |
124 | "localhost", PORT); | ||
125 | GNUNET_assert (csock != NULL); | 123 | GNUNET_assert (csock != NULL); |
126 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 124 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
127 | ls, &run_accept_cancel, cls); | 125 | ls, &run_accept_cancel, cls); |
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 0e2190e41..3989d654a 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c | |||
@@ -62,8 +62,7 @@ open_listen_socket () | |||
62 | GNUNET_assert (desc != NULL); | 62 | GNUNET_assert (desc != NULL); |
63 | if (GNUNET_NETWORK_socket_setsockopt | 63 | if (GNUNET_NETWORK_socket_setsockopt |
64 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 64 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
66 | "setsockopt"); | ||
67 | GNUNET_assert (GNUNET_NETWORK_socket_bind | 66 | GNUNET_assert (GNUNET_NETWORK_socket_bind |
68 | (desc, (const struct sockaddr *) &sa, | 67 | (desc, (const struct sockaddr *) &sa, |
69 | sizeof (sa)) == GNUNET_OK); | 68 | sizeof (sa)) == GNUNET_OK); |
@@ -76,17 +75,18 @@ static size_t | |||
76 | send_kilo (void *cls, size_t size, void *buf) | 75 | send_kilo (void *cls, size_t size, void *buf) |
77 | { | 76 | { |
78 | int *ok = cls; | 77 | int *ok = cls; |
78 | |||
79 | if (size == 0) | 79 | if (size == 0) |
80 | { | 80 | { |
81 | #if VERBOSE | 81 | #if VERBOSE |
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n"); | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n"); |
83 | #endif | 83 | #endif |
84 | GNUNET_assert (buf == NULL); | 84 | GNUNET_assert (buf == NULL); |
85 | *ok = 0; | 85 | *ok = 0; |
86 | GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); | 86 | GNUNET_CONNECTION_destroy (lsock, GNUNET_YES); |
87 | GNUNET_CONNECTION_destroy (csock, GNUNET_YES); | 87 | GNUNET_CONNECTION_destroy (csock, GNUNET_YES); |
88 | return 0; | 88 | return 0; |
89 | } | 89 | } |
90 | #if VERBOSE | 90 | #if VERBOSE |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n"); | 91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n"); |
92 | #endif | 92 | #endif |
@@ -109,8 +109,7 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
109 | ls = open_listen_socket (); | 109 | ls = open_listen_socket (); |
110 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | 110 | lsock = GNUNET_CONNECTION_create_from_existing (ls); |
111 | GNUNET_assert (lsock != NULL); | 111 | GNUNET_assert (lsock != NULL); |
112 | csock = GNUNET_CONNECTION_create_from_connect (cfg, | 112 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); |
113 | "localhost", PORT); | ||
114 | GNUNET_assert (csock != NULL); | 113 | GNUNET_assert (csock != NULL); |
115 | GNUNET_assert (NULL != | 114 | GNUNET_assert (NULL != |
116 | GNUNET_CONNECTION_notify_transmit_ready (csock, | 115 | GNUNET_CONNECTION_notify_transmit_ready (csock, |
diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c index 3519f197b..ea4a32412 100644 --- a/src/util/test_connection_timeout_no_connect.c +++ b/src/util/test_connection_timeout_no_connect.c | |||
@@ -39,6 +39,7 @@ static size_t | |||
39 | handle_timeout (void *cls, size_t size, void *buf) | 39 | handle_timeout (void *cls, size_t size, void *buf) |
40 | { | 40 | { |
41 | int *ok = cls; | 41 | int *ok = cls; |
42 | |||
42 | #if VERBOSE | 43 | #if VERBOSE |
43 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received timeout signal.\n"); | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received timeout signal.\n"); |
44 | #endif | 45 | #endif |
@@ -53,8 +54,7 @@ handle_timeout (void *cls, size_t size, void *buf) | |||
53 | static void | 54 | static void |
54 | task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 55 | task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
55 | { | 56 | { |
56 | csock = GNUNET_CONNECTION_create_from_connect (cfg, | 57 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); |
57 | "localhost", PORT); | ||
58 | GNUNET_assert (csock != NULL); | 58 | GNUNET_assert (csock != NULL); |
59 | GNUNET_assert (NULL != | 59 | GNUNET_assert (NULL != |
60 | GNUNET_CONNECTION_notify_transmit_ready (csock, | 60 | GNUNET_CONNECTION_notify_transmit_ready (csock, |
diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c index 72e27243b..4280edf1d 100644 --- a/src/util/test_connection_transmit_cancel.c +++ b/src/util/test_connection_transmit_cancel.c | |||
@@ -43,15 +43,13 @@ not_run (void *cls, size_t size, void *buf) | |||
43 | 43 | ||
44 | 44 | ||
45 | static void | 45 | static void |
46 | task_transmit_cancel (void *cls, | 46 | task_transmit_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
47 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
48 | { | 47 | { |
49 | int *ok = cls; | 48 | int *ok = cls; |
50 | struct GNUNET_CONNECTION_TransmitHandle *th; | 49 | struct GNUNET_CONNECTION_TransmitHandle *th; |
51 | struct GNUNET_CONNECTION_Handle *csock; | 50 | struct GNUNET_CONNECTION_Handle *csock; |
52 | 51 | ||
53 | csock = GNUNET_CONNECTION_create_from_connect (cfg, | 52 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); |
54 | "localhost", PORT); | ||
55 | GNUNET_assert (csock != NULL); | 53 | GNUNET_assert (csock != NULL); |
56 | th = GNUNET_CONNECTION_notify_transmit_ready (csock, | 54 | th = GNUNET_CONNECTION_notify_transmit_ready (csock, |
57 | 12, | 55 | 12, |
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c index 7d5de66b1..49cddac7c 100644 --- a/src/util/test_container_bloomfilter.c +++ b/src/util/test_container_bloomfilter.c | |||
@@ -75,30 +75,29 @@ main (int argc, char *argv[]) | |||
75 | bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K); | 75 | bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K); |
76 | 76 | ||
77 | for (i = 0; i < 200; i++) | 77 | for (i = 0; i < 200; i++) |
78 | { | 78 | { |
79 | nextHC (&tmp); | 79 | nextHC (&tmp); |
80 | GNUNET_CONTAINER_bloomfilter_add (bf, &tmp); | 80 | GNUNET_CONTAINER_bloomfilter_add (bf, &tmp); |
81 | } | 81 | } |
82 | SRANDOM (1); | 82 | SRANDOM (1); |
83 | ok1 = 0; | 83 | ok1 = 0; |
84 | for (i = 0; i < 200; i++) | 84 | for (i = 0; i < 200; i++) |
85 | { | 85 | { |
86 | nextHC (&tmp); | 86 | nextHC (&tmp); |
87 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) | 87 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) |
88 | ok1++; | 88 | ok1++; |
89 | } | 89 | } |
90 | if (ok1 != 200) | 90 | if (ok1 != 200) |
91 | { | 91 | { |
92 | printf ("Got %d elements out of" | 92 | printf ("Got %d elements out of" "200 expected after insertion.\n", ok1); |
93 | "200 expected after insertion.\n", ok1); | 93 | GNUNET_CONTAINER_bloomfilter_free (bf); |
94 | GNUNET_CONTAINER_bloomfilter_free (bf); | 94 | return -1; |
95 | return -1; | 95 | } |
96 | } | ||
97 | if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, buf, SIZE)) | 96 | if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, buf, SIZE)) |
98 | { | 97 | { |
99 | GNUNET_CONTAINER_bloomfilter_free (bf); | 98 | GNUNET_CONTAINER_bloomfilter_free (bf); |
100 | return -1; | 99 | return -1; |
101 | } | 100 | } |
102 | 101 | ||
103 | GNUNET_CONTAINER_bloomfilter_free (bf); | 102 | GNUNET_CONTAINER_bloomfilter_free (bf); |
104 | 103 | ||
@@ -111,94 +110,93 @@ main (int argc, char *argv[]) | |||
111 | ok1 = 0; | 110 | ok1 = 0; |
112 | ok2 = 0; | 111 | ok2 = 0; |
113 | for (i = 0; i < 200; i++) | 112 | for (i = 0; i < 200; i++) |
114 | { | 113 | { |
115 | nextHC (&tmp); | 114 | nextHC (&tmp); |
116 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) | 115 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) |
117 | ok1++; | 116 | ok1++; |
118 | if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) | 117 | if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) |
119 | ok2++; | 118 | ok2++; |
120 | } | 119 | } |
121 | if (ok1 != 200) | 120 | if (ok1 != 200) |
122 | { | 121 | { |
123 | printf ("Got %d elements out of 200 " | 122 | printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1); |
124 | "expected after reloading.\n", ok1); | 123 | GNUNET_CONTAINER_bloomfilter_free (bf); |
125 | GNUNET_CONTAINER_bloomfilter_free (bf); | 124 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
126 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 125 | return -1; |
127 | return -1; | 126 | } |
128 | } | ||
129 | 127 | ||
130 | if (ok2 != 200) | 128 | if (ok2 != 200) |
131 | { | 129 | { |
132 | printf ("Got %d elements out of 200 " | 130 | printf ("Got %d elements out of 200 " |
133 | "expected after initialization.\n", ok2); | 131 | "expected after initialization.\n", ok2); |
134 | GNUNET_CONTAINER_bloomfilter_free (bf); | 132 | GNUNET_CONTAINER_bloomfilter_free (bf); |
135 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 133 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
136 | return -1; | 134 | return -1; |
137 | } | 135 | } |
138 | 136 | ||
139 | SRANDOM (1); | 137 | SRANDOM (1); |
140 | for (i = 0; i < 100; i++) | 138 | for (i = 0; i < 100; i++) |
141 | { | 139 | { |
142 | nextHC (&tmp); | 140 | nextHC (&tmp); |
143 | GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp); | 141 | GNUNET_CONTAINER_bloomfilter_remove (bf, &tmp); |
144 | GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp); | 142 | GNUNET_CONTAINER_bloomfilter_remove (bfi, &tmp); |
145 | } | 143 | } |
146 | 144 | ||
147 | SRANDOM (1); | 145 | SRANDOM (1); |
148 | 146 | ||
149 | ok1 = 0; | 147 | ok1 = 0; |
150 | ok2 = 0; | 148 | ok2 = 0; |
151 | for (i = 0; i < 200; i++) | 149 | for (i = 0; i < 200; i++) |
152 | { | 150 | { |
153 | nextHC (&tmp); | 151 | nextHC (&tmp); |
154 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) | 152 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) |
155 | ok1++; | 153 | ok1++; |
156 | if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) | 154 | if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) |
157 | ok2++; | 155 | ok2++; |
158 | } | 156 | } |
159 | 157 | ||
160 | if (ok1 != 100) | 158 | if (ok1 != 100) |
161 | { | 159 | { |
162 | printf ("Expected 100 elements in loaded filter" | 160 | printf ("Expected 100 elements in loaded filter" |
163 | " after adding 200 and deleting 100, got %d\n", ok1); | 161 | " after adding 200 and deleting 100, got %d\n", ok1); |
164 | GNUNET_CONTAINER_bloomfilter_free (bf); | 162 | GNUNET_CONTAINER_bloomfilter_free (bf); |
165 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 163 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
166 | return -1; | 164 | return -1; |
167 | } | 165 | } |
168 | if (ok2 != 200) | 166 | if (ok2 != 200) |
169 | { | 167 | { |
170 | printf ("Expected 200 elements in initialized filter" | 168 | printf ("Expected 200 elements in initialized filter" |
171 | " after adding 200 and deleting 100 " | 169 | " after adding 200 and deleting 100 " |
172 | "(which should do nothing for a filter not backed by a file), got %d\n", | 170 | "(which should do nothing for a filter not backed by a file), got %d\n", |
173 | ok2); | 171 | ok2); |
174 | GNUNET_CONTAINER_bloomfilter_free (bf); | 172 | GNUNET_CONTAINER_bloomfilter_free (bf); |
175 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 173 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
176 | return -1; | 174 | return -1; |
177 | } | 175 | } |
178 | 176 | ||
179 | SRANDOM (3); | 177 | SRANDOM (3); |
180 | 178 | ||
181 | GNUNET_CONTAINER_bloomfilter_clear (bf); | 179 | GNUNET_CONTAINER_bloomfilter_clear (bf); |
182 | falseok = 0; | 180 | falseok = 0; |
183 | for (i = 0; i < 1000; i++) | 181 | for (i = 0; i < 1000; i++) |
184 | { | 182 | { |
185 | nextHC (&tmp); | 183 | nextHC (&tmp); |
186 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) | 184 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) |
187 | falseok++; | 185 | falseok++; |
188 | } | 186 | } |
189 | if (falseok > 0) | 187 | if (falseok > 0) |
190 | { | 188 | { |
191 | GNUNET_CONTAINER_bloomfilter_free (bf); | 189 | GNUNET_CONTAINER_bloomfilter_free (bf); |
192 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 190 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
193 | return -1; | 191 | return -1; |
194 | } | 192 | } |
195 | 193 | ||
196 | if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_or (bf, buf, SIZE)) | 194 | if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_or (bf, buf, SIZE)) |
197 | { | 195 | { |
198 | GNUNET_CONTAINER_bloomfilter_free (bf); | 196 | GNUNET_CONTAINER_bloomfilter_free (bf); |
199 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 197 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
200 | return -1; | 198 | return -1; |
201 | } | 199 | } |
202 | 200 | ||
203 | SRANDOM (2); | 201 | SRANDOM (2); |
204 | i = 20; | 202 | i = 20; |
@@ -212,30 +210,30 @@ main (int argc, char *argv[]) | |||
212 | ok1 = 0; | 210 | ok1 = 0; |
213 | ok2 = 0; | 211 | ok2 = 0; |
214 | for (i = 0; i < 20; i++) | 212 | for (i = 0; i < 20; i++) |
215 | { | 213 | { |
216 | nextHC (&tmp); | 214 | nextHC (&tmp); |
217 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) | 215 | if (GNUNET_CONTAINER_bloomfilter_test (bf, &tmp) == GNUNET_YES) |
218 | ok1++; | 216 | ok1++; |
219 | if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) | 217 | if (GNUNET_CONTAINER_bloomfilter_test (bfi, &tmp) == GNUNET_YES) |
220 | ok2++; | 218 | ok2++; |
221 | } | 219 | } |
222 | 220 | ||
223 | if (ok1 != 20) | 221 | if (ok1 != 20) |
224 | { | 222 | { |
225 | printf ("Expected 20 elements in resized file-backed filter" | 223 | printf ("Expected 20 elements in resized file-backed filter" |
226 | " after adding 20, got %d\n", ok1); | 224 | " after adding 20, got %d\n", ok1); |
227 | GNUNET_CONTAINER_bloomfilter_free (bf); | 225 | GNUNET_CONTAINER_bloomfilter_free (bf); |
228 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 226 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
229 | return -1; | 227 | return -1; |
230 | } | 228 | } |
231 | if (ok2 != 20) | 229 | if (ok2 != 20) |
232 | { | 230 | { |
233 | printf ("Expected 20 elements in resized filter" | 231 | printf ("Expected 20 elements in resized filter" |
234 | " after adding 20, got %d\n", ok2); | 232 | " after adding 20, got %d\n", ok2); |
235 | GNUNET_CONTAINER_bloomfilter_free (bf); | 233 | GNUNET_CONTAINER_bloomfilter_free (bf); |
236 | GNUNET_CONTAINER_bloomfilter_free (bfi); | 234 | GNUNET_CONTAINER_bloomfilter_free (bfi); |
237 | return -1; | 235 | return -1; |
238 | } | 236 | } |
239 | 237 | ||
240 | 238 | ||
241 | GNUNET_CONTAINER_bloomfilter_free (bf); | 239 | GNUNET_CONTAINER_bloomfilter_free (bf); |
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c index 6a0d5d68d..7b352241c 100644 --- a/src/util/test_container_heap.c +++ b/src/util/test_container_heap.c | |||
@@ -30,20 +30,18 @@ | |||
30 | 30 | ||
31 | static int | 31 | static int |
32 | iterator_callback (void *cls, | 32 | iterator_callback (void *cls, |
33 | struct GNUNET_CONTAINER_HeapNode *node, | 33 | struct GNUNET_CONTAINER_HeapNode *node, |
34 | void *element, | 34 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
35 | GNUNET_CONTAINER_HeapCostType cost) | ||
36 | { | 35 | { |
37 | return GNUNET_OK; | 36 | return GNUNET_OK; |
38 | } | 37 | } |
39 | 38 | ||
40 | static int | 39 | static int |
41 | nstrcmp (const char *a, | 40 | nstrcmp (const char *a, const char *b) |
42 | const char *b) | ||
43 | { | 41 | { |
44 | GNUNET_assert (a != NULL); | 42 | GNUNET_assert (a != NULL); |
45 | GNUNET_assert (b != NULL); | 43 | GNUNET_assert (b != NULL); |
46 | return strcmp (a,b); | 44 | return strcmp (a, b); |
47 | } | 45 | } |
48 | 46 | ||
49 | static int | 47 | static int |
@@ -61,47 +59,46 @@ check () | |||
61 | const char *r; | 59 | const char *r; |
62 | 60 | ||
63 | myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 61 | myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
64 | 62 | ||
65 | // GNUNET_CONTAINER_heap_remove_root heap empty, taking if-branch | 63 | // GNUNET_CONTAINER_heap_remove_root heap empty, taking if-branch |
66 | n1 = GNUNET_CONTAINER_heap_remove_root (myHeap); | 64 | n1 = GNUNET_CONTAINER_heap_remove_root (myHeap); |
67 | GNUNET_assert (NULL == n1); | 65 | GNUNET_assert (NULL == n1); |
68 | 66 | ||
69 | // GNUNET_CONTAINER_heap_peek heap empty, taking if-branch | 67 | // GNUNET_CONTAINER_heap_peek heap empty, taking if-branch |
70 | n1 = GNUNET_CONTAINER_heap_peek (myHeap); | 68 | n1 = GNUNET_CONTAINER_heap_peek (myHeap); |
71 | GNUNET_assert (NULL == n1); | 69 | GNUNET_assert (NULL == n1); |
72 | 70 | ||
73 | // GNUNET_CONTAINER_heap_walk_get_next: heap empty, taking if-branch | 71 | // GNUNET_CONTAINER_heap_walk_get_next: heap empty, taking if-branch |
74 | n1 = GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 72 | n1 = GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
75 | GNUNET_assert (NULL == n1); | 73 | GNUNET_assert (NULL == n1); |
76 | 74 | ||
77 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "11", 11); | 75 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "11", 11); |
78 | GNUNET_assert (NULL != n1); | 76 | GNUNET_assert (NULL != n1); |
79 | 77 | ||
80 | 78 | ||
81 | // GNUNET_CONTAINER_heap_peek not empty, taking if-branch | 79 | // GNUNET_CONTAINER_heap_peek not empty, taking if-branch |
82 | n2 = NULL; | 80 | n2 = NULL; |
83 | n2 = GNUNET_CONTAINER_heap_peek (myHeap); | 81 | n2 = GNUNET_CONTAINER_heap_peek (myHeap); |
84 | GNUNET_assert (NULL != n2); | 82 | GNUNET_assert (NULL != n2); |
85 | 83 | ||
86 | // GNUNET_CONTAINER_heap_walk_get_next: 1 element | 84 | // GNUNET_CONTAINER_heap_walk_get_next: 1 element |
87 | n1 = NULL; | 85 | n1 = NULL; |
88 | n1 = GNUNET_CONTAINER_heap_walk_get_next(myHeap); | 86 | n1 = GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
89 | GNUNET_assert (NULL != n1); | 87 | GNUNET_assert (NULL != n1); |
90 | 88 | ||
91 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); | 89 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
92 | GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 90 | GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
93 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "78", 78); | 91 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "78", 78); |
94 | GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 92 | GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
95 | GNUNET_assert (0 == strcmp ("78", | 93 | GNUNET_assert (0 == strcmp ("78", GNUNET_CONTAINER_heap_remove_node (n2))); |
96 | GNUNET_CONTAINER_heap_remove_node (n2))); | ||
97 | GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 94 | GNUNET_assert (1 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
98 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); | 95 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
99 | 96 | ||
100 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "15", 5); | 97 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "15", 5); |
101 | GNUNET_CONTAINER_heap_update_cost (myHeap, n3, 15); | 98 | GNUNET_CONTAINER_heap_update_cost (myHeap, n3, 15); |
102 | GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 99 | GNUNET_assert (2 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
103 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); | 100 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
104 | 101 | ||
105 | n4 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); | 102 | n4 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); |
106 | GNUNET_CONTAINER_heap_update_cost (myHeap, n4, 50); | 103 | GNUNET_CONTAINER_heap_update_cost (myHeap, n4, 50); |
107 | GNUNET_assert (3 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 104 | GNUNET_assert (3 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
@@ -111,36 +108,34 @@ check () | |||
111 | n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30); | 108 | n6 = GNUNET_CONTAINER_heap_insert (myHeap, "30/200", 30); |
112 | GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 109 | GNUNET_assert (5 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
113 | GNUNET_CONTAINER_heap_remove_node (n5); | 110 | GNUNET_CONTAINER_heap_remove_node (n5); |
114 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ | 111 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n1 */ |
115 | GNUNET_assert (NULL != r); | 112 | GNUNET_assert (NULL != r); |
116 | GNUNET_assert (0 == strcmp ("11", | 113 | GNUNET_assert (0 == strcmp ("11", r)); |
117 | r)); | ||
118 | GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200); | 114 | GNUNET_CONTAINER_heap_update_cost (myHeap, n6, 200); |
119 | GNUNET_CONTAINER_heap_remove_node (n3); | 115 | GNUNET_CONTAINER_heap_remove_node (n3); |
120 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ | 116 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n4 */ |
121 | GNUNET_assert (NULL != r); | 117 | GNUNET_assert (NULL != r); |
122 | GNUNET_assert (0 == strcmp ("50", | 118 | GNUNET_assert (0 == strcmp ("50", r)); |
123 | r)); | 119 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */ |
124 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); /* n6 */ | ||
125 | GNUNET_assert (NULL != r); | 120 | GNUNET_assert (NULL != r); |
126 | GNUNET_assert (0 == strcmp ("30/200", r)); | 121 | GNUNET_assert (0 == strcmp ("30/200", r)); |
127 | GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (myHeap)); | 122 | GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (myHeap)); |
128 | 123 | ||
129 | GNUNET_CONTAINER_heap_destroy (myHeap); | 124 | GNUNET_CONTAINER_heap_destroy (myHeap); |
130 | 125 | ||
131 | // My additions to a complete testcase | 126 | // My additions to a complete testcase |
132 | // Testing a GNUNET_CONTAINER_HEAP_ORDER_MIN | 127 | // Testing a GNUNET_CONTAINER_HEAP_ORDER_MIN |
133 | // Testing remove_node | 128 | // Testing remove_node |
134 | 129 | ||
135 | myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 130 | myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
136 | 131 | ||
137 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 132 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
138 | GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); | 133 | GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); |
139 | 134 | ||
140 | r = GNUNET_CONTAINER_heap_remove_node (n1); | 135 | r = GNUNET_CONTAINER_heap_remove_node (n1); |
141 | GNUNET_assert (NULL != r); | 136 | GNUNET_assert (NULL != r); |
142 | GNUNET_assert (0 == strcmp ("10", r)); | 137 | GNUNET_assert (0 == strcmp ("10", r)); |
143 | 138 | ||
144 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 139 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
145 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); | 140 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); |
146 | 141 | ||
@@ -151,134 +146,137 @@ check () | |||
151 | r = GNUNET_CONTAINER_heap_remove_node (n1); | 146 | r = GNUNET_CONTAINER_heap_remove_node (n1); |
152 | GNUNET_assert (NULL != r); | 147 | GNUNET_assert (NULL != r); |
153 | GNUNET_assert (0 == strcmp ("10", r)); | 148 | GNUNET_assert (0 == strcmp ("10", r)); |
154 | 149 | ||
155 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 150 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
156 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); | 151 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); |
157 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); | 152 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); |
158 | 153 | ||
159 | GNUNET_CONTAINER_heap_remove_node (n2); | 154 | GNUNET_CONTAINER_heap_remove_node (n2); |
160 | GNUNET_CONTAINER_heap_remove_node (n1); | 155 | GNUNET_CONTAINER_heap_remove_node (n1); |
161 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); | 156 | r = GNUNET_CONTAINER_heap_remove_root (myHeap); |
162 | GNUNET_assert (NULL != r); | 157 | GNUNET_assert (NULL != r); |
163 | GNUNET_assert (0 == strcmp ("30", r)); | 158 | GNUNET_assert (0 == strcmp ("30", r)); |
164 | 159 | ||
165 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 160 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
166 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); | 161 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); |
167 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); | 162 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); |
168 | 163 | ||
169 | GNUNET_CONTAINER_heap_remove_node (n2); | 164 | GNUNET_CONTAINER_heap_remove_node (n2); |
170 | GNUNET_CONTAINER_heap_remove_node (n1); | 165 | GNUNET_CONTAINER_heap_remove_node (n1); |
171 | r = GNUNET_CONTAINER_heap_remove_node ( n3); | 166 | r = GNUNET_CONTAINER_heap_remove_node (n3); |
172 | GNUNET_assert (NULL != r); | 167 | GNUNET_assert (NULL != r); |
173 | GNUNET_assert (0 == strcmp ("30", r)); | 168 | GNUNET_assert (0 == strcmp ("30", r)); |
174 | 169 | ||
175 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 170 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
176 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); | 171 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); |
177 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); | 172 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); |
178 | 173 | ||
179 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); | 174 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); |
180 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap))); | 175 | GNUNET_assert (0 == |
181 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); | 176 | nstrcmp ("10", GNUNET_CONTAINER_heap_remove_root (myHeap))); |
182 | 177 | GNUNET_assert (0 == | |
178 | nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); | ||
179 | |||
183 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 180 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
184 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); | 181 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); |
185 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); | 182 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); |
186 | n4 = GNUNET_CONTAINER_heap_insert (myHeap, "40", 40); | 183 | n4 = GNUNET_CONTAINER_heap_insert (myHeap, "40", 40); |
187 | n5 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); | 184 | n5 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); |
188 | n6 = GNUNET_CONTAINER_heap_insert (myHeap, "60", 60); | 185 | n6 = GNUNET_CONTAINER_heap_insert (myHeap, "60", 60); |
189 | 186 | ||
190 | // Inserting nodes deeper in the tree with lower costs | 187 | // Inserting nodes deeper in the tree with lower costs |
191 | n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10); | 188 | n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10); |
192 | n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10); | 189 | n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10); |
193 | 190 | ||
194 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); | 191 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); |
195 | 192 | ||
196 | // Cleaning up... | 193 | // Cleaning up... |
197 | GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6))); | 194 | GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6))); |
198 | GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5))); | 195 | GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5))); |
199 | 196 | ||
200 | // Testing heap_walk_get_next | 197 | // Testing heap_walk_get_next |
201 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 198 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
202 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 199 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
203 | GNUNET_CONTAINER_heap_walk_get_next (myHeap);; | 200 | GNUNET_CONTAINER_heap_walk_get_next (myHeap);; |
201 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | ||
204 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 202 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
205 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 203 | |
206 | |||
207 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); | 204 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); |
208 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); | 205 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); |
209 | GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4))); | 206 | GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4))); |
210 | GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7))); | 207 | GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7))); |
211 | GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8))); | 208 | GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8))); |
212 | 209 | ||
213 | // End Testing remove_node | 210 | // End Testing remove_node |
214 | 211 | ||
215 | // Testing a GNUNET_CONTAINER_HEAP_ORDER_MAX | 212 | // Testing a GNUNET_CONTAINER_HEAP_ORDER_MAX |
216 | GNUNET_CONTAINER_heap_destroy (myHeap); | 213 | GNUNET_CONTAINER_heap_destroy (myHeap); |
217 | 214 | ||
218 | myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); | 215 | myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); |
219 | 216 | ||
220 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 217 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
221 | GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); | 218 | GNUNET_CONTAINER_heap_update_cost (myHeap, n1, 15); |
222 | 219 | ||
223 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); | 220 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); |
224 | 221 | ||
225 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 222 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
226 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); | 223 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); |
227 | 224 | ||
228 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 225 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
229 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); | 226 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); |
230 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); | 227 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); |
231 | 228 | ||
232 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 229 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
233 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); | 230 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); |
234 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); | 231 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); |
235 | 232 | ||
236 | GNUNET_CONTAINER_heap_remove_node (n2); | 233 | GNUNET_CONTAINER_heap_remove_node (n2); |
237 | GNUNET_CONTAINER_heap_remove_node (n1); | 234 | GNUNET_CONTAINER_heap_remove_node (n1); |
238 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); | 235 | GNUNET_assert (0 == |
239 | 236 | nstrcmp ("30", GNUNET_CONTAINER_heap_remove_root (myHeap))); | |
237 | |||
240 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 238 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
241 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); | 239 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 10); |
242 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); | 240 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 10); |
243 | 241 | ||
244 | GNUNET_CONTAINER_heap_remove_node (n2); | 242 | GNUNET_CONTAINER_heap_remove_node (n2); |
245 | GNUNET_CONTAINER_heap_remove_node (n1); | 243 | GNUNET_CONTAINER_heap_remove_node (n1); |
246 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); | 244 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); |
247 | 245 | ||
248 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); | 246 | n1 = GNUNET_CONTAINER_heap_insert (myHeap, "10", 10); |
249 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); | 247 | n2 = GNUNET_CONTAINER_heap_insert (myHeap, "20", 20); |
250 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); | 248 | n3 = GNUNET_CONTAINER_heap_insert (myHeap, "30", 30); |
251 | n4 = GNUNET_CONTAINER_heap_insert (myHeap, "40", 40); | 249 | n4 = GNUNET_CONTAINER_heap_insert (myHeap, "40", 40); |
252 | n5 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); | 250 | n5 = GNUNET_CONTAINER_heap_insert (myHeap, "50", 50); |
253 | n6 = GNUNET_CONTAINER_heap_insert (myHeap, "60", 60); | 251 | n6 = GNUNET_CONTAINER_heap_insert (myHeap, "60", 60); |
254 | 252 | ||
255 | // Inserting nodes deeper in the tree with lower costs | 253 | // Inserting nodes deeper in the tree with lower costs |
256 | n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10); | 254 | n7 = GNUNET_CONTAINER_heap_insert (myHeap, "70", 10); |
257 | n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10); | 255 | n8 = GNUNET_CONTAINER_heap_insert (myHeap, "80", 10); |
258 | 256 | ||
259 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); | 257 | GNUNET_assert (0 == nstrcmp ("30", GNUNET_CONTAINER_heap_remove_node (n3))); |
260 | 258 | ||
261 | // Cleaning up... | 259 | // Cleaning up... |
262 | GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6))); | 260 | GNUNET_assert (0 == nstrcmp ("60", GNUNET_CONTAINER_heap_remove_node (n6))); |
263 | GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5))); | 261 | GNUNET_assert (0 == nstrcmp ("50", GNUNET_CONTAINER_heap_remove_node (n5))); |
264 | 262 | ||
265 | // Testing heap_walk_get_next | 263 | // Testing heap_walk_get_next |
266 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 264 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
267 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 265 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
268 | GNUNET_CONTAINER_heap_walk_get_next (myHeap);; | 266 | GNUNET_CONTAINER_heap_walk_get_next (myHeap);; |
269 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 267 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
270 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); | 268 | GNUNET_CONTAINER_heap_walk_get_next (myHeap); |
271 | 269 | ||
272 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); | 270 | GNUNET_assert (0 == nstrcmp ("10", GNUNET_CONTAINER_heap_remove_node (n1))); |
273 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); | 271 | GNUNET_assert (0 == nstrcmp ("20", GNUNET_CONTAINER_heap_remove_node (n2))); |
274 | GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4))); | 272 | GNUNET_assert (0 == nstrcmp ("40", GNUNET_CONTAINER_heap_remove_node (n4))); |
275 | GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7))); | 273 | GNUNET_assert (0 == nstrcmp ("70", GNUNET_CONTAINER_heap_remove_node (n7))); |
276 | GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8))); | 274 | GNUNET_assert (0 == nstrcmp ("80", GNUNET_CONTAINER_heap_remove_node (n8))); |
277 | 275 | ||
278 | // End Testing remove_node | 276 | // End Testing remove_node |
279 | 277 | ||
280 | GNUNET_CONTAINER_heap_destroy (myHeap); | 278 | GNUNET_CONTAINER_heap_destroy (myHeap); |
281 | 279 | ||
282 | return 0; | 280 | return 0; |
283 | } | 281 | } |
284 | 282 | ||
@@ -287,7 +285,7 @@ int | |||
287 | main (int argc, char **argv) | 285 | main (int argc, char **argv) |
288 | { | 286 | { |
289 | GNUNET_log_setup ("test-container-heap", "WARNING", NULL); | 287 | GNUNET_log_setup ("test-container-heap", "WARNING", NULL); |
290 | return check(); | 288 | return check (); |
291 | } | 289 | } |
292 | 290 | ||
293 | /* end of test_container_heap.c */ | 291 | /* end of test_container_heap.c */ |
diff --git a/src/util/test_container_meta_data.c b/src/util/test_container_meta_data.c index 9148e73b0..cee550f96 100644 --- a/src/util/test_container_meta_data.c +++ b/src/util/test_container_meta_data.c | |||
@@ -42,116 +42,89 @@ testMeta (int i) | |||
42 | m = GNUNET_CONTAINER_meta_data_create (); | 42 | m = GNUNET_CONTAINER_meta_data_create (); |
43 | if (GNUNET_OK != | 43 | if (GNUNET_OK != |
44 | GNUNET_CONTAINER_meta_data_insert (m, | 44 | GNUNET_CONTAINER_meta_data_insert (m, |
45 | "<test>", | 45 | "<test>", |
46 | EXTRACTOR_METATYPE_TITLE, | 46 | EXTRACTOR_METATYPE_TITLE, |
47 | EXTRACTOR_METAFORMAT_UTF8, | 47 | EXTRACTOR_METAFORMAT_UTF8, |
48 | "text/plain", | 48 | "text/plain", |
49 | "TestTitle", | 49 | "TestTitle", strlen ("TestTitle") + 1)) |
50 | strlen("TestTitle")+1)) | ||
51 | ABORT (m); | 50 | ABORT (m); |
52 | if (GNUNET_OK != | 51 | if (GNUNET_OK != |
53 | GNUNET_CONTAINER_meta_data_insert (m, | 52 | GNUNET_CONTAINER_meta_data_insert (m, |
54 | "<test>", | 53 | "<test>", |
55 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 54 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
56 | EXTRACTOR_METAFORMAT_UTF8, | 55 | EXTRACTOR_METAFORMAT_UTF8, |
57 | "text/plain", | 56 | "text/plain", |
58 | "TestTitle", | 57 | "TestTitle", strlen ("TestTitle") + 1)) |
59 | strlen ("TestTitle")+1)) | ||
60 | ABORT (m); | 58 | ABORT (m); |
61 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, | 59 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ |
62 | "<test>", | ||
63 | EXTRACTOR_METATYPE_TITLE, | ||
64 | EXTRACTOR_METAFORMAT_UTF8, | ||
65 | "text/plain", | ||
66 | "TestTitle", | ||
67 | strlen ("TestTitle")+1)) /* dup! */ | ||
68 | ABORT (m); | 60 | ABORT (m); |
69 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, | 61 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (m, "<test>", EXTRACTOR_METATYPE_AUTHOR_NAME, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "TestTitle", strlen ("TestTitle") + 1)) /* dup! */ |
70 | "<test>", | ||
71 | EXTRACTOR_METATYPE_AUTHOR_NAME, | ||
72 | EXTRACTOR_METAFORMAT_UTF8, | ||
73 | "text/plain", | ||
74 | "TestTitle", | ||
75 | strlen ("TestTitle")+1)) /* dup! */ | ||
76 | ABORT (m); | 62 | ABORT (m); |
77 | if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) | 63 | if (2 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) |
78 | ABORT (m); | 64 | ABORT (m); |
79 | if (GNUNET_OK != | 65 | if (GNUNET_OK != |
80 | GNUNET_CONTAINER_meta_data_delete (m, | 66 | GNUNET_CONTAINER_meta_data_delete (m, |
81 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 67 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
82 | "TestTitle", | 68 | "TestTitle", strlen ("TestTitle") + 1)) |
83 | strlen("TestTitle")+1)) | ||
84 | ABORT (m); | 69 | ABORT (m); |
85 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, | 70 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_AUTHOR_NAME, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ |
86 | EXTRACTOR_METATYPE_AUTHOR_NAME, | ||
87 | "TestTitle", | ||
88 | strlen ("TestTitle")+1)) /* already gone */ | ||
89 | ABORT (m); | 71 | ABORT (m); |
90 | if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) | 72 | if (1 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) |
91 | ABORT (m); | 73 | ABORT (m); |
92 | if (GNUNET_OK != | 74 | if (GNUNET_OK != |
93 | GNUNET_CONTAINER_meta_data_delete (m, | 75 | GNUNET_CONTAINER_meta_data_delete (m, |
94 | EXTRACTOR_METATYPE_TITLE, | 76 | EXTRACTOR_METATYPE_TITLE, |
95 | "TestTitle", | 77 | "TestTitle", strlen ("TestTitle") + 1)) |
96 | strlen ("TestTitle")+1)) | ||
97 | ABORT (m); | 78 | ABORT (m); |
98 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, | 79 | if (GNUNET_OK == GNUNET_CONTAINER_meta_data_delete (m, EXTRACTOR_METATYPE_TITLE, "TestTitle", strlen ("TestTitle") + 1)) /* already gone */ |
99 | EXTRACTOR_METATYPE_TITLE, | ||
100 | "TestTitle", | ||
101 | strlen ("TestTitle")+1)) /* already gone */ | ||
102 | ABORT (m); | 80 | ABORT (m); |
103 | if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) | 81 | if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) |
104 | ABORT (m); | 82 | ABORT (m); |
105 | for (j = 0; j < i; j++) | 83 | for (j = 0; j < i; j++) |
106 | { | 84 | { |
107 | GNUNET_snprintf (val, | 85 | GNUNET_snprintf (val, |
108 | sizeof(val), | 86 | sizeof (val), |
109 | "%s.%d", | 87 | "%s.%d", "A teststring that should compress well.", j); |
110 | "A teststring that should compress well.", j); | 88 | if (GNUNET_OK != |
111 | if (GNUNET_OK != | 89 | GNUNET_CONTAINER_meta_data_insert (m, |
112 | GNUNET_CONTAINER_meta_data_insert (m, | 90 | "<test>", |
113 | "<test>", | 91 | EXTRACTOR_METATYPE_UNKNOWN, |
114 | EXTRACTOR_METATYPE_UNKNOWN, | 92 | EXTRACTOR_METAFORMAT_UTF8, |
115 | EXTRACTOR_METAFORMAT_UTF8, | 93 | "text/plain", val, strlen (val) + 1)) |
116 | "text/plain", | 94 | ABORT (m); |
117 | val, | 95 | } |
118 | strlen(val)+1)) | ||
119 | ABORT (m); | ||
120 | } | ||
121 | if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) | 96 | if (i != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) |
122 | ABORT (m); | 97 | ABORT (m); |
123 | 98 | ||
124 | size = | 99 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (m); |
125 | GNUNET_CONTAINER_meta_data_get_serialized_size (m); | ||
126 | sval = NULL; | 100 | sval = NULL; |
127 | if (size != GNUNET_CONTAINER_meta_data_serialize (m, | 101 | if (size != GNUNET_CONTAINER_meta_data_serialize (m, |
128 | &sval, size, | 102 | &sval, size, |
129 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) | 103 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) |
130 | { | 104 | { |
131 | GNUNET_free_non_null (sval); | 105 | GNUNET_free_non_null (sval); |
132 | ABORT (m); | 106 | ABORT (m); |
133 | } | 107 | } |
134 | GNUNET_CONTAINER_meta_data_destroy (m); | 108 | GNUNET_CONTAINER_meta_data_destroy (m); |
135 | m = GNUNET_CONTAINER_meta_data_deserialize (sval, size); | 109 | m = GNUNET_CONTAINER_meta_data_deserialize (sval, size); |
136 | GNUNET_free (sval); | 110 | GNUNET_free (sval); |
137 | if (m == NULL) | 111 | if (m == NULL) |
138 | ABORT (m); | 112 | ABORT (m); |
139 | for (j = 0; j < i; j++) | 113 | for (j = 0; j < i; j++) |
114 | { | ||
115 | GNUNET_snprintf (val, | ||
116 | sizeof (val), "%s.%d", | ||
117 | "A teststring that should compress well.", j); | ||
118 | if (GNUNET_OK != | ||
119 | GNUNET_CONTAINER_meta_data_delete (m, | ||
120 | EXTRACTOR_METATYPE_UNKNOWN, | ||
121 | val, strlen (val) + 1)) | ||
140 | { | 122 | { |
141 | GNUNET_snprintf (val, | 123 | ABORT (m); |
142 | sizeof(val), "%s.%d", | ||
143 | "A teststring that should compress well.", j); | ||
144 | if (GNUNET_OK != | ||
145 | GNUNET_CONTAINER_meta_data_delete (m, | ||
146 | EXTRACTOR_METATYPE_UNKNOWN, | ||
147 | val, | ||
148 | strlen(val)+1)) | ||
149 | { | ||
150 | ABORT (m); | ||
151 | } | ||
152 | } | 124 | } |
125 | } | ||
153 | if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) | 126 | if (0 != GNUNET_CONTAINER_meta_data_iterate (m, NULL, NULL)) |
154 | ABORT (m); | 127 | ABORT (m); |
155 | GNUNET_CONTAINER_meta_data_destroy (m); | 128 | GNUNET_CONTAINER_meta_data_destroy (m); |
156 | return 0; | 129 | return 0; |
157 | } | 130 | } |
@@ -167,26 +140,23 @@ testMetaMore (int i) | |||
167 | 140 | ||
168 | meta = GNUNET_CONTAINER_meta_data_create (); | 141 | meta = GNUNET_CONTAINER_meta_data_create (); |
169 | for (q = 0; q <= i; q++) | 142 | for (q = 0; q <= i; q++) |
170 | { | 143 | { |
171 | GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); | 144 | GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); |
172 | GNUNET_CONTAINER_meta_data_insert (meta, | 145 | GNUNET_CONTAINER_meta_data_insert (meta, |
173 | "<test>", | 146 | "<test>", |
174 | q % EXTRACTOR_metatype_get_max(), | 147 | q % EXTRACTOR_metatype_get_max (), |
175 | EXTRACTOR_METAFORMAT_UTF8, | 148 | EXTRACTOR_METAFORMAT_UTF8, |
176 | "text/plain", | 149 | "text/plain", txt, strlen (txt) + 1); |
177 | txt, | 150 | } |
178 | strlen (txt)+1); | 151 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); |
179 | } | ||
180 | size = | ||
181 | GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | ||
182 | data = GNUNET_malloc (size * 4); | 152 | data = GNUNET_malloc (size * 4); |
183 | if (size != GNUNET_CONTAINER_meta_data_serialize (meta, | 153 | if (size != GNUNET_CONTAINER_meta_data_serialize (meta, |
184 | &data, size * 4, | 154 | &data, size * 4, |
185 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) | 155 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)) |
186 | { | 156 | { |
187 | GNUNET_free (data); | 157 | GNUNET_free (data); |
188 | ABORT (meta); | 158 | ABORT (meta); |
189 | } | 159 | } |
190 | GNUNET_CONTAINER_meta_data_destroy (meta); | 160 | GNUNET_CONTAINER_meta_data_destroy (meta); |
191 | GNUNET_free (data); | 161 | GNUNET_free (data); |
192 | return 0; | 162 | return 0; |
@@ -201,26 +171,25 @@ testMetaLink () | |||
201 | 171 | ||
202 | m = GNUNET_CONTAINER_meta_data_create (); | 172 | m = GNUNET_CONTAINER_meta_data_create (); |
203 | if (GNUNET_OK != | 173 | if (GNUNET_OK != |
204 | GNUNET_CONTAINER_meta_data_insert (m, | 174 | GNUNET_CONTAINER_meta_data_insert (m, |
205 | "<test>", | 175 | "<test>", |
206 | EXTRACTOR_METATYPE_UNKNOWN, | 176 | EXTRACTOR_METATYPE_UNKNOWN, |
207 | EXTRACTOR_METAFORMAT_UTF8, | 177 | EXTRACTOR_METAFORMAT_UTF8, |
208 | "text/plain", | 178 | "text/plain", |
209 | "link", | 179 | "link", strlen ("link") + 1)) |
210 | strlen("link")+1)) | ||
211 | ABORT (m); | 180 | ABORT (m); |
212 | if (GNUNET_OK != | 181 | if (GNUNET_OK != |
213 | GNUNET_CONTAINER_meta_data_insert (m, | 182 | GNUNET_CONTAINER_meta_data_insert (m, |
214 | "<test>", | 183 | "<test>", |
215 | EXTRACTOR_METATYPE_FILENAME, | 184 | EXTRACTOR_METATYPE_FILENAME, |
216 | EXTRACTOR_METAFORMAT_UTF8, | 185 | EXTRACTOR_METAFORMAT_UTF8, |
217 | "text/plain", | 186 | "text/plain", |
218 | "lib-link.m4", | 187 | "lib-link.m4", |
219 | strlen ("lib-link.m4")+1)) | 188 | strlen ("lib-link.m4") + 1)) |
220 | ABORT (m); | 189 | ABORT (m); |
221 | val = NULL; | 190 | val = NULL; |
222 | size = GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) -1, | 191 | size = GNUNET_CONTAINER_meta_data_serialize (m, &val, (size_t) - 1, |
223 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); | 192 | GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); |
224 | GNUNET_CONTAINER_meta_data_destroy (m); | 193 | GNUNET_CONTAINER_meta_data_destroy (m); |
225 | m = GNUNET_CONTAINER_meta_data_deserialize (val, size); | 194 | m = GNUNET_CONTAINER_meta_data_deserialize (val, size); |
226 | GNUNET_free (val); | 195 | GNUNET_free (val); |
@@ -231,7 +200,7 @@ testMetaLink () | |||
231 | } | 200 | } |
232 | 201 | ||
233 | int | 202 | int |
234 | check() | 203 | check () |
235 | { | 204 | { |
236 | struct GNUNET_CONTAINER_MetaData *meta; | 205 | struct GNUNET_CONTAINER_MetaData *meta; |
237 | struct GNUNET_CONTAINER_MetaData *meta2; | 206 | struct GNUNET_CONTAINER_MetaData *meta2; |
@@ -239,126 +208,131 @@ check() | |||
239 | int i = 100; | 208 | int i = 100; |
240 | char txt[128]; | 209 | char txt[128]; |
241 | char *str; | 210 | char *str; |
242 | unsigned char* thumb; | 211 | unsigned char *thumb; |
243 | 212 | ||
244 | meta = GNUNET_CONTAINER_meta_data_create (); | 213 | meta = GNUNET_CONTAINER_meta_data_create (); |
245 | meta2 = GNUNET_CONTAINER_meta_data_create (); | 214 | meta2 = GNUNET_CONTAINER_meta_data_create (); |
246 | for (q = 0; q <= i; q++) | 215 | for (q = 0; q <= i; q++) |
247 | { | 216 | { |
248 | GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); | 217 | GNUNET_snprintf (txt, 128, "%u -- %u\n", i, q); |
249 | GNUNET_CONTAINER_meta_data_insert (meta, | 218 | GNUNET_CONTAINER_meta_data_insert (meta, |
250 | "<test>", | 219 | "<test>", |
251 | EXTRACTOR_METATYPE_UNKNOWN, | 220 | EXTRACTOR_METATYPE_UNKNOWN, |
252 | EXTRACTOR_METAFORMAT_UTF8, | 221 | EXTRACTOR_METAFORMAT_UTF8, |
253 | "text/plain", | 222 | "text/plain", |
254 | "TestTitle", | 223 | "TestTitle", strlen ("TestTitle") + 1); |
255 | strlen ("TestTitle")+1); | 224 | GNUNET_CONTAINER_meta_data_insert (meta2, |
256 | GNUNET_CONTAINER_meta_data_insert (meta2, | 225 | "<test>", |
257 | "<test>", | 226 | EXTRACTOR_METATYPE_UNKNOWN, |
258 | EXTRACTOR_METATYPE_UNKNOWN, | 227 | EXTRACTOR_METAFORMAT_UTF8, |
259 | EXTRACTOR_METAFORMAT_UTF8, | 228 | "text/plain", |
260 | "text/plain", | 229 | "TestTitle", strlen ("TestTitle") + 1); |
261 | "TestTitle", | 230 | } |
262 | strlen ("TestTitle")+1); | 231 | |
263 | } | ||
264 | |||
265 | //check meta_data_test_equal | 232 | //check meta_data_test_equal |
266 | if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal(meta, meta2)) | 233 | if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2)) |
267 | { | 234 | { |
268 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 235 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
269 | ABORT(meta); | 236 | ABORT (meta); |
270 | } | 237 | } |
271 | 238 | ||
272 | //check meta_data_clear | 239 | //check meta_data_clear |
273 | GNUNET_CONTAINER_meta_data_clear(meta2); | 240 | GNUNET_CONTAINER_meta_data_clear (meta2); |
274 | if (0 != GNUNET_CONTAINER_meta_data_iterate(meta2,NULL,NULL)) | 241 | if (0 != GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) |
275 | { | 242 | { |
276 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 243 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
277 | ABORT(meta); | 244 | ABORT (meta); |
278 | } | 245 | } |
279 | // check equal branch in meta_data_test_equal | 246 | // check equal branch in meta_data_test_equal |
280 | if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal(meta,meta)) | 247 | if (GNUNET_YES != GNUNET_CONTAINER_meta_data_test_equal (meta, meta)) |
281 | { | 248 | { |
282 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 249 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
283 | ABORT(meta); | 250 | ABORT (meta); |
284 | } | 251 | } |
285 | // check "count" branch in meta_data_test_equal | 252 | // check "count" branch in meta_data_test_equal |
286 | if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal(meta,meta2)) | 253 | if (GNUNET_NO != GNUNET_CONTAINER_meta_data_test_equal (meta, meta2)) |
287 | { | 254 | { |
288 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 255 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
289 | ABORT(meta); | 256 | ABORT (meta); |
290 | } | 257 | } |
291 | 258 | ||
292 | // check meta_data_add_publication_date | 259 | // check meta_data_add_publication_date |
293 | GNUNET_CONTAINER_meta_data_add_publication_date(meta2); | 260 | GNUNET_CONTAINER_meta_data_add_publication_date (meta2); |
294 | 261 | ||
295 | // check meta_data_merge | 262 | // check meta_data_merge |
296 | GNUNET_CONTAINER_meta_data_clear(meta2); | 263 | GNUNET_CONTAINER_meta_data_clear (meta2); |
297 | GNUNET_CONTAINER_meta_data_merge(meta2,meta); | 264 | GNUNET_CONTAINER_meta_data_merge (meta2, meta); |
298 | if (100 == GNUNET_CONTAINER_meta_data_iterate(meta2,NULL,NULL)) | 265 | if (100 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) |
299 | { | 266 | { |
300 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 267 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
301 | ABORT(meta); | 268 | ABORT (meta); |
302 | } | 269 | } |
303 | 270 | ||
304 | // check meta_data_get_by_type | 271 | // check meta_data_get_by_type |
305 | GNUNET_CONTAINER_meta_data_clear(meta2); | 272 | GNUNET_CONTAINER_meta_data_clear (meta2); |
306 | if (NULL != (str = GNUNET_CONTAINER_meta_data_get_by_type (meta2, EXTRACTOR_METATYPE_UNKNOWN))) | 273 | if (NULL != |
307 | { | 274 | (str = |
308 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 275 | GNUNET_CONTAINER_meta_data_get_by_type (meta2, |
309 | GNUNET_free (str); | 276 | EXTRACTOR_METATYPE_UNKNOWN))) |
310 | ABORT(meta); | 277 | { |
311 | } | 278 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
312 | 279 | GNUNET_free (str); | |
313 | str = GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN); | 280 | ABORT (meta); |
281 | } | ||
282 | |||
283 | str = | ||
284 | GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_UNKNOWN); | ||
314 | GNUNET_assert (NULL != str); | 285 | GNUNET_assert (NULL != str); |
315 | if (str[0] != 'T') | 286 | if (str[0] != 'T') |
316 | { | 287 | { |
317 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 288 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
318 | GNUNET_free (str); | 289 | GNUNET_free (str); |
319 | ABORT(meta); | 290 | ABORT (meta); |
320 | } | 291 | } |
321 | GNUNET_free (str); | 292 | GNUNET_free (str); |
322 | 293 | ||
323 | // check branch | 294 | // check branch |
324 | if (NULL != (str = GNUNET_CONTAINER_meta_data_get_by_type (meta, EXTRACTOR_METATYPE_PUBLICATION_DATE))) | 295 | if (NULL != |
325 | { | 296 | (str = |
326 | GNUNET_free (str); | 297 | GNUNET_CONTAINER_meta_data_get_by_type (meta, |
327 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 298 | EXTRACTOR_METATYPE_PUBLICATION_DATE))) |
328 | ABORT(meta); | 299 | { |
329 | } | 300 | GNUNET_free (str); |
301 | GNUNET_CONTAINER_meta_data_destroy (meta2); | ||
302 | ABORT (meta); | ||
303 | } | ||
330 | 304 | ||
331 | //check meta_data_get_first_by_types | 305 | //check meta_data_get_first_by_types |
332 | str = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, | 306 | str = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, |
333 | EXTRACTOR_METATYPE_UNKNOWN, | 307 | EXTRACTOR_METATYPE_UNKNOWN, |
334 | -1); | 308 | -1); |
335 | GNUNET_assert (NULL != str); | 309 | GNUNET_assert (NULL != str); |
336 | if (str[0] != 'T') | 310 | if (str[0] != 'T') |
337 | { | 311 | { |
338 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 312 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
339 | GNUNET_free (str); | 313 | GNUNET_free (str); |
340 | ABORT(meta); | 314 | ABORT (meta); |
341 | } | 315 | } |
342 | GNUNET_free (str); | 316 | GNUNET_free (str); |
343 | 317 | ||
344 | //check meta_data_get_thumbnail | 318 | //check meta_data_get_thumbnail |
345 | if (GNUNET_CONTAINER_meta_data_get_thumbnail(meta, &thumb) != 0) | 319 | if (GNUNET_CONTAINER_meta_data_get_thumbnail (meta, &thumb) != 0) |
346 | { | 320 | { |
347 | GNUNET_free (thumb); | 321 | GNUNET_free (thumb); |
348 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 322 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
349 | ABORT(meta); | 323 | ABORT (meta); |
350 | } | 324 | } |
351 | GNUNET_CONTAINER_meta_data_destroy (meta2); | 325 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
352 | //check meta_data_duplicate | 326 | //check meta_data_duplicate |
353 | meta2 = GNUNET_CONTAINER_meta_data_duplicate(meta); | 327 | meta2 = GNUNET_CONTAINER_meta_data_duplicate (meta); |
354 | if (200 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) | 328 | if (200 == GNUNET_CONTAINER_meta_data_iterate (meta2, NULL, NULL)) |
355 | { | 329 | { |
356 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 330 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
357 | ABORT(meta); | 331 | ABORT (meta); |
358 | } | 332 | } |
359 | GNUNET_CONTAINER_meta_data_destroy(meta2); | 333 | GNUNET_CONTAINER_meta_data_destroy (meta2); |
360 | GNUNET_CONTAINER_meta_data_destroy(meta); | 334 | GNUNET_CONTAINER_meta_data_destroy (meta); |
361 | return 0; | 335 | return 0; |
362 | } | 336 | } |
363 | 337 | ||
364 | 338 | ||
@@ -375,8 +349,9 @@ main (int argc, char *argv[]) | |||
375 | failureCount += testMetaMore (i); | 349 | failureCount += testMetaMore (i); |
376 | failureCount += testMetaLink (); | 350 | failureCount += testMetaLink (); |
377 | 351 | ||
378 | int ret = check(); | 352 | int ret = check (); |
379 | if ( ret == 1) | 353 | |
354 | if (ret == 1) | ||
380 | return 1; | 355 | return 1; |
381 | 356 | ||
382 | if (failureCount != 0) | 357 | if (failureCount != 0) |
diff --git a/src/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c index 931a52fec..c16b2df22 100644 --- a/src/util/test_container_multihashmap.c +++ b/src/util/test_container_multihashmap.c | |||
@@ -52,8 +52,7 @@ testMap (int i) | |||
52 | CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); | 52 | CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); |
53 | CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m)); | 53 | CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m)); |
54 | CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); | 54 | CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); |
55 | CHECK (0 == | 55 | CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); |
56 | GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); | ||
57 | 56 | ||
58 | CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, | 57 | CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m, |
59 | &k1, | 58 | &k1, |
@@ -81,10 +80,8 @@ testMap (int i) | |||
81 | CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m)); | 80 | CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m)); |
82 | CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1)); | 81 | CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1)); |
83 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2)); | 82 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2)); |
84 | CHECK (2 == | 83 | CHECK (2 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); |
85 | GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL)); | 84 | CHECK (0 == GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL)); |
86 | CHECK (0 == | ||
87 | GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL)); | ||
88 | CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); | 85 | CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL)); |
89 | CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); | 86 | CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1)); |
90 | for (j = 0; j < 1024; j++) | 87 | for (j = 0; j < 1024; j++) |
diff --git a/src/util/test_container_slist.c b/src/util/test_container_slist.c index c0a832073..13c12bc5a 100644 --- a/src/util/test_container_slist.c +++ b/src/util/test_container_slist.c | |||
@@ -54,21 +54,19 @@ main (int argc, char *argv[]) | |||
54 | for (it = GNUNET_CONTAINER_slist_begin (l), i = 99; | 54 | for (it = GNUNET_CONTAINER_slist_begin (l), i = 99; |
55 | GNUNET_CONTAINER_slist_end (it) != GNUNET_YES; | 55 | GNUNET_CONTAINER_slist_end (it) != GNUNET_YES; |
56 | GNUNET_CONTAINER_slist_next (it), i--) | 56 | GNUNET_CONTAINER_slist_next (it), i--) |
57 | { | ||
58 | p = GNUNET_CONTAINER_slist_get (it, &s); | ||
59 | |||
60 | if ((p == NULL) || (i != (j = *(int *) p)) || (s != sizeof (i))) | ||
57 | { | 61 | { |
58 | p = GNUNET_CONTAINER_slist_get (it, &s); | 62 | GNUNET_CONTAINER_slist_iter_destroy (it); |
59 | 63 | GNUNET_assert (0); | |
60 | if ( (p == NULL) || | ||
61 | (i != (j = *(int *) p)) || | ||
62 | (s != sizeof (i)) ) | ||
63 | { | ||
64 | GNUNET_CONTAINER_slist_iter_destroy (it); | ||
65 | GNUNET_assert (0); | ||
66 | } | ||
67 | j *= 2; | ||
68 | GNUNET_CONTAINER_slist_insert (it, | ||
69 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | ||
70 | &j, sizeof (j)); | ||
71 | } | 64 | } |
65 | j *= 2; | ||
66 | GNUNET_CONTAINER_slist_insert (it, | ||
67 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | ||
68 | &j, sizeof (j)); | ||
69 | } | ||
72 | GNUNET_CONTAINER_slist_iter_destroy (it); | 70 | GNUNET_CONTAINER_slist_iter_destroy (it); |
73 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); | 71 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); |
74 | i = 198; | 72 | i = 198; |
@@ -76,30 +74,32 @@ main (int argc, char *argv[]) | |||
76 | 74 | ||
77 | for (it = GNUNET_CONTAINER_slist_begin (l); | 75 | for (it = GNUNET_CONTAINER_slist_begin (l); |
78 | GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;) | 76 | GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;) |
79 | { | 77 | { |
80 | p = GNUNET_CONTAINER_slist_get (it, &s); | 78 | p = GNUNET_CONTAINER_slist_get (it, &s); |
81 | GNUNET_assert (p != NULL); | 79 | GNUNET_assert (p != NULL); |
82 | GNUNET_assert (s == sizeof (i)); | 80 | GNUNET_assert (s == sizeof (i)); |
83 | i = *(int *) p; | 81 | i = *(int *) p; |
84 | 82 | ||
85 | GNUNET_assert (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES); | 83 | GNUNET_assert (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES); |
86 | GNUNET_assert (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES); | 84 | GNUNET_assert (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES); |
87 | 85 | ||
88 | p = GNUNET_CONTAINER_slist_get (it, &s); | 86 | p = GNUNET_CONTAINER_slist_get (it, &s); |
89 | GNUNET_assert (p != NULL); | 87 | GNUNET_assert (p != NULL); |
90 | GNUNET_assert (s == sizeof (j)); | 88 | GNUNET_assert (s == sizeof (j)); |
91 | j = *(int *) p; | 89 | j = *(int *) p; |
92 | 90 | ||
93 | GNUNET_assert (j * 2 == i); | 91 | GNUNET_assert (j * 2 == i); |
94 | 92 | ||
95 | GNUNET_CONTAINER_slist_erase (it); | 93 | GNUNET_CONTAINER_slist_erase (it); |
96 | } | 94 | } |
97 | GNUNET_CONTAINER_slist_iter_destroy (it); | 95 | GNUNET_CONTAINER_slist_iter_destroy (it); |
98 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); | 96 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); |
99 | i = 99; | 97 | i = 99; |
100 | GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == GNUNET_NO); | 98 | GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == |
99 | GNUNET_NO); | ||
101 | i = 198; | 100 | i = 198; |
102 | GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == GNUNET_YES); | 101 | GNUNET_assert (GNUNET_CONTAINER_slist_contains (l, &i, sizeof (i)) == |
102 | GNUNET_YES); | ||
103 | 103 | ||
104 | GNUNET_CONTAINER_slist_clear (l); | 104 | GNUNET_CONTAINER_slist_clear (l); |
105 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); | 105 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); |
@@ -108,18 +108,18 @@ main (int argc, char *argv[]) | |||
108 | GNUNET_CONTAINER_slist_add (l, | 108 | GNUNET_CONTAINER_slist_add (l, |
109 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 109 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
110 | &i, sizeof (i)); | 110 | &i, sizeof (i)); |
111 | /*check slist_append*/ | 111 | /*check slist_append */ |
112 | GNUNET_CONTAINER_slist_append(l,l); | 112 | GNUNET_CONTAINER_slist_append (l, l); |
113 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); | 113 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 200); |
114 | 114 | ||
115 | GNUNET_CONTAINER_slist_destroy (l); | 115 | GNUNET_CONTAINER_slist_destroy (l); |
116 | 116 | ||
117 | /*check slist_add_end*/ | 117 | /*check slist_add_end */ |
118 | l = GNUNET_CONTAINER_slist_create (); | 118 | l = GNUNET_CONTAINER_slist_create (); |
119 | for (i = 0; i < 100; i++) | 119 | for (i = 0; i < 100; i++) |
120 | GNUNET_CONTAINER_slist_add_end (l, | 120 | GNUNET_CONTAINER_slist_add_end (l, |
121 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, | 121 | GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, |
122 | &i, sizeof (i)); | 122 | &i, sizeof (i)); |
123 | 123 | ||
124 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); | 124 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 100); |
125 | 125 | ||
@@ -129,9 +129,7 @@ main (int argc, char *argv[]) | |||
129 | { | 129 | { |
130 | p = GNUNET_CONTAINER_slist_get (it, &s); | 130 | p = GNUNET_CONTAINER_slist_get (it, &s); |
131 | 131 | ||
132 | if ((p == NULL) || | 132 | if ((p == NULL) || (i != *(int *) p) || (s != sizeof (i))) |
133 | (i != *(int *) p) || | ||
134 | (s != sizeof (i))) | ||
135 | { | 133 | { |
136 | GNUNET_CONTAINER_slist_iter_destroy (it); | 134 | GNUNET_CONTAINER_slist_iter_destroy (it); |
137 | GNUNET_assert (0); | 135 | GNUNET_assert (0); |
@@ -140,28 +138,28 @@ main (int argc, char *argv[]) | |||
140 | GNUNET_CONTAINER_slist_iter_destroy (it); | 138 | GNUNET_CONTAINER_slist_iter_destroy (it); |
141 | GNUNET_CONTAINER_slist_destroy (l); | 139 | GNUNET_CONTAINER_slist_destroy (l); |
142 | 140 | ||
143 | /*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC*/ | 141 | /*check if disp = GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC */ |
144 | l = GNUNET_CONTAINER_slist_create (); | 142 | l = GNUNET_CONTAINER_slist_create (); |
145 | 143 | ||
146 | for (i = 0; i < 100; i++) | 144 | for (i = 0; i < 100; i++) |
147 | { | 145 | { |
148 | ip = GNUNET_malloc (sizeof (int)); | 146 | ip = GNUNET_malloc (sizeof (int)); |
149 | *ip = i; | 147 | *ip = i; |
150 | GNUNET_CONTAINER_slist_add (l, | 148 | GNUNET_CONTAINER_slist_add (l, |
151 | GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, | 149 | GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, |
152 | ip, sizeof (int)); | 150 | ip, sizeof (int)); |
153 | } | 151 | } |
154 | //creat_add | 152 | //creat_add |
155 | it = GNUNET_CONTAINER_slist_begin (l); | 153 | it = GNUNET_CONTAINER_slist_begin (l); |
156 | p = GNUNET_CONTAINER_slist_get (it, &s); | 154 | p = GNUNET_CONTAINER_slist_get (it, &s); |
157 | GNUNET_assert (p != NULL); | 155 | GNUNET_assert (p != NULL); |
158 | //slist_erase | 156 | //slist_erase |
159 | GNUNET_assert (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES); | 157 | GNUNET_assert (GNUNET_CONTAINER_slist_next (it) == GNUNET_YES); |
160 | GNUNET_CONTAINER_slist_erase (it); | 158 | GNUNET_CONTAINER_slist_erase (it); |
161 | GNUNET_CONTAINER_slist_iter_destroy (it); | 159 | GNUNET_CONTAINER_slist_iter_destroy (it); |
162 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 99); | 160 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 99); |
163 | //slist_clear | 161 | //slist_clear |
164 | GNUNET_CONTAINER_slist_clear(l); | 162 | GNUNET_CONTAINER_slist_clear (l); |
165 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); | 163 | GNUNET_assert (GNUNET_CONTAINER_slist_count (l) == 0); |
166 | GNUNET_CONTAINER_slist_destroy (l); | 164 | GNUNET_CONTAINER_slist_destroy (l); |
167 | 165 | ||
diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c index 8dfaef732..968c7f40f 100644 --- a/src/util/test_crypto_aes.c +++ b/src/util/test_crypto_aes.c | |||
@@ -46,25 +46,25 @@ testSymcipher () | |||
46 | GNUNET_CRYPTO_AesInitializationVector *) | 46 | GNUNET_CRYPTO_AesInitializationVector *) |
47 | INITVALUE, result); | 47 | INITVALUE, result); |
48 | if (size == -1) | 48 | if (size == -1) |
49 | { | 49 | { |
50 | printf ("symciphertest failed: encryptBlock returned %d\n", size); | 50 | printf ("symciphertest failed: encryptBlock returned %d\n", size); |
51 | return 1; | 51 | return 1; |
52 | } | 52 | } |
53 | size = GNUNET_CRYPTO_aes_decrypt (result, size, | 53 | size = GNUNET_CRYPTO_aes_decrypt (result, size, |
54 | &key, | 54 | &key, |
55 | (const struct | 55 | (const struct |
56 | GNUNET_CRYPTO_AesInitializationVector *) | 56 | GNUNET_CRYPTO_AesInitializationVector *) |
57 | INITVALUE, res); | 57 | INITVALUE, res); |
58 | if (strlen (TESTSTRING) + 1 != size) | 58 | if (strlen (TESTSTRING) + 1 != size) |
59 | { | 59 | { |
60 | printf ("symciphertest failed: decryptBlock returned %d\n", size); | 60 | printf ("symciphertest failed: decryptBlock returned %d\n", size); |
61 | return 1; | 61 | return 1; |
62 | } | 62 | } |
63 | if (0 != strcmp (res, TESTSTRING)) | 63 | if (0 != strcmp (res, TESTSTRING)) |
64 | { | 64 | { |
65 | printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); | 65 | printf ("symciphertest failed: %s != %s\n", res, TESTSTRING); |
66 | return 1; | 66 | return 1; |
67 | } | 67 | } |
68 | else | 68 | else |
69 | return 0; | 69 | return 0; |
70 | } | 70 | } |
@@ -78,16 +78,16 @@ verifyCrypto () | |||
78 | int ret; | 78 | int ret; |
79 | 79 | ||
80 | unsigned char plain[] = | 80 | unsigned char plain[] = |
81 | { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249, | 81 | { 29, 128, 192, 253, 74, 171, 38, 187, 84, 219, 76, 76, 209, 118, 33, 249, |
82 | 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164 | 82 | 172, 124, 96, 9, 157, 110, 8, 215, 200, 63, 69, 230, 157, 104, 247, 164 |
83 | }; | 83 | }; |
84 | unsigned char raw_key[] = | 84 | unsigned char raw_key[] = |
85 | { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25, | 85 | { 106, 74, 209, 88, 145, 55, 189, 135, 125, 180, 225, 108, 183, 54, 25, |
86 | 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184, | 86 | 169, 129, 188, 131, 75, 227, 245, 105, 10, 225, 15, 115, 159, 148, 184, |
87 | 34, 191 | 87 | 34, 191 |
88 | }; | 88 | }; |
89 | unsigned char encrresult[] = | 89 | unsigned char encrresult[] = |
90 | { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75, | 90 | { 167, 102, 230, 233, 127, 195, 176, 107, 17, 91, 199, 127, 96, 113, 75, |
91 | 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25, | 91 | 195, 245, 217, 61, 236, 159, 165, 103, 121, 203, 99, 202, 41, 23, 222, 25, |
92 | 102 | 92 | 102 |
93 | }; | 93 | }; |
@@ -97,16 +97,16 @@ verifyCrypto () | |||
97 | 97 | ||
98 | memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH); | 98 | memcpy (key.key, raw_key, GNUNET_CRYPTO_AES_KEY_LENGTH); |
99 | key.crc32 = | 99 | key.crc32 = |
100 | htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH)); | 100 | htonl (GNUNET_CRYPTO_crc32_n (&key, GNUNET_CRYPTO_AES_KEY_LENGTH)); |
101 | 101 | ||
102 | if (ntohl (key.crc32) != (unsigned int) 38125195LL) | 102 | if (ntohl (key.crc32) != (unsigned int) 38125195LL) |
103 | { | 103 | { |
104 | printf ("Static key has different CRC: %u - %u\n", | 104 | printf ("Static key has different CRC: %u - %u\n", |
105 | ntohl (key.crc32), key.crc32); | 105 | ntohl (key.crc32), key.crc32); |
106 | 106 | ||
107 | ret = 1; | 107 | ret = 1; |
108 | goto error; | 108 | goto error; |
109 | } | 109 | } |
110 | 110 | ||
111 | if (GNUNET_CRYPTO_AES_KEY_LENGTH != | 111 | if (GNUNET_CRYPTO_AES_KEY_LENGTH != |
112 | GNUNET_CRYPTO_aes_encrypt (plain, | 112 | GNUNET_CRYPTO_aes_encrypt (plain, |
@@ -115,18 +115,18 @@ verifyCrypto () | |||
115 | (const struct | 115 | (const struct |
116 | GNUNET_CRYPTO_AesInitializationVector *) | 116 | GNUNET_CRYPTO_AesInitializationVector *) |
117 | "testtesttesttest", result)) | 117 | "testtesttesttest", result)) |
118 | { | 118 | { |
119 | printf ("Wrong return value from encrypt block.\n"); | 119 | printf ("Wrong return value from encrypt block.\n"); |
120 | ret = 1; | 120 | ret = 1; |
121 | goto error; | 121 | goto error; |
122 | } | 122 | } |
123 | 123 | ||
124 | if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) | 124 | if (memcmp (encrresult, result, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) |
125 | { | 125 | { |
126 | printf ("Encrypted result wrong.\n"); | 126 | printf ("Encrypted result wrong.\n"); |
127 | ret = 1; | 127 | ret = 1; |
128 | goto error; | 128 | goto error; |
129 | } | 129 | } |
130 | 130 | ||
131 | res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); | 131 | res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); |
132 | 132 | ||
@@ -137,18 +137,18 @@ verifyCrypto () | |||
137 | (const struct | 137 | (const struct |
138 | GNUNET_CRYPTO_AesInitializationVector *) | 138 | GNUNET_CRYPTO_AesInitializationVector *) |
139 | "testtesttesttest", res)) | 139 | "testtesttesttest", res)) |
140 | { | 140 | { |
141 | printf ("Wrong return value from decrypt block.\n"); | 141 | printf ("Wrong return value from decrypt block.\n"); |
142 | ret = 1; | 142 | ret = 1; |
143 | goto error; | 143 | goto error; |
144 | } | 144 | } |
145 | 145 | ||
146 | if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) | 146 | if (memcmp (res, plain, GNUNET_CRYPTO_AES_KEY_LENGTH) != 0) |
147 | { | 147 | { |
148 | printf ("Decrypted result does not match input.\n"); | 148 | printf ("Decrypted result does not match input.\n"); |
149 | 149 | ||
150 | ret = 1; | 150 | ret = 1; |
151 | } | 151 | } |
152 | 152 | ||
153 | error: | 153 | error: |
154 | 154 | ||
@@ -170,10 +170,10 @@ main (int argc, char *argv[]) | |||
170 | failureCount += verifyCrypto (); | 170 | failureCount += verifyCrypto (); |
171 | 171 | ||
172 | if (failureCount != 0) | 172 | if (failureCount != 0) |
173 | { | 173 | { |
174 | printf ("%d TESTS FAILED!\n", failureCount); | 174 | printf ("%d TESTS FAILED!\n", failureCount); |
175 | return -1; | 175 | return -1; |
176 | } | 176 | } |
177 | return 0; | 177 | return 0; |
178 | } | 178 | } |
179 | 179 | ||
diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c index 73e52ba01..f54835b3d 100644 --- a/src/util/test_crypto_aes_weak.c +++ b/src/util/test_crypto_aes_weak.c | |||
@@ -38,10 +38,11 @@ static void | |||
38 | printWeakKey (struct GNUNET_CRYPTO_AesSessionKey *key) | 38 | printWeakKey (struct GNUNET_CRYPTO_AesSessionKey *key) |
39 | { | 39 | { |
40 | int i; | 40 | int i; |
41 | |||
41 | for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++) | 42 | for (i = 0; i < GNUNET_CRYPTO_AES_KEY_LENGTH; i++) |
42 | { | 43 | { |
43 | printf ("%x ", (int) (key->key[i])); | 44 | printf ("%x ", (int) (key->key[i])); |
44 | } | 45 | } |
45 | } | 46 | } |
46 | 47 | ||
47 | static int | 48 | static int |
@@ -56,7 +57,7 @@ testWeakKey () | |||
56 | memset (&INITVALUE, 42, | 57 | memset (&INITVALUE, 42, |
57 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 58 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); |
58 | /* sorry, this is not a weak key -- I don't have | 59 | /* sorry, this is not a weak key -- I don't have |
59 | any at the moment! */ | 60 | * any at the moment! */ |
60 | weak_key.key[0] = (char) (0x4c); | 61 | weak_key.key[0] = (char) (0x4c); |
61 | weak_key.key[1] = (char) (0x31); | 62 | weak_key.key[1] = (char) (0x31); |
62 | weak_key.key[2] = (char) (0xc6); | 63 | weak_key.key[2] = (char) (0xc6); |
@@ -91,30 +92,30 @@ testWeakKey () | |||
91 | weak_key.key[31] = (char) (0xaa); | 92 | weak_key.key[31] = (char) (0xaa); |
92 | /* memset(&weak_key, 0, 32); */ | 93 | /* memset(&weak_key, 0, 32); */ |
93 | weak_key.crc32 = | 94 | weak_key.crc32 = |
94 | htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH)); | 95 | htonl (GNUNET_CRYPTO_crc32_n (&weak_key, GNUNET_CRYPTO_AES_KEY_LENGTH)); |
95 | 96 | ||
96 | size = GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, | 97 | size = GNUNET_CRYPTO_aes_encrypt (WEAK_KEY_TESTSTRING, |
97 | strlen (WEAK_KEY_TESTSTRING) + 1, | 98 | strlen (WEAK_KEY_TESTSTRING) + 1, |
98 | &weak_key, &INITVALUE, result); | 99 | &weak_key, &INITVALUE, result); |
99 | 100 | ||
100 | if (size == -1) | 101 | if (size == -1) |
101 | { | 102 | { |
102 | GNUNET_break (0); | 103 | GNUNET_break (0); |
103 | return 1; | 104 | return 1; |
104 | } | 105 | } |
105 | 106 | ||
106 | size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res); | 107 | size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res); |
107 | 108 | ||
108 | if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size) | 109 | if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size) |
109 | { | 110 | { |
110 | GNUNET_break (0); | 111 | GNUNET_break (0); |
111 | return 1; | 112 | return 1; |
112 | } | 113 | } |
113 | if (0 != strcmp (res, WEAK_KEY_TESTSTRING)) | 114 | if (0 != strcmp (res, WEAK_KEY_TESTSTRING)) |
114 | { | 115 | { |
115 | GNUNET_break (0); | 116 | GNUNET_break (0); |
116 | return 1; | 117 | return 1; |
117 | } | 118 | } |
118 | else | 119 | else |
119 | return 0; | 120 | return 0; |
120 | } | 121 | } |
@@ -131,44 +132,42 @@ getWeakKeys () | |||
131 | 132 | ||
132 | for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS; | 133 | for (number_of_runs = 0; number_of_runs < MAX_WEAK_KEY_TRIALS; |
133 | number_of_runs++) | 134 | number_of_runs++) |
135 | { | ||
136 | |||
137 | if (number_of_runs % 1000 == 0) | ||
138 | fprintf (stderr, "."); | ||
139 | /*printf("Got to run number %d.\n", number_of_runs); */ | ||
140 | GNUNET_CRYPTO_aes_create_session_key (&sessionkey); | ||
141 | |||
142 | rc = gcry_cipher_open (&handle, | ||
143 | GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, 0); | ||
144 | |||
145 | if (rc) | ||
134 | { | 146 | { |
147 | printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", | ||
148 | number_of_runs, gcry_strerror (rc)); | ||
149 | continue; | ||
150 | } | ||
135 | 151 | ||
136 | if (number_of_runs % 1000 == 0) | 152 | rc = gcry_cipher_setkey (handle, &sessionkey, GNUNET_CRYPTO_AES_KEY_LENGTH); |
137 | fprintf (stderr, "."); | ||
138 | /*printf("Got to run number %d.\n", number_of_runs); */ | ||
139 | GNUNET_CRYPTO_aes_create_session_key (&sessionkey); | ||
140 | |||
141 | rc = gcry_cipher_open (&handle, | ||
142 | GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB, 0); | ||
143 | |||
144 | if (rc) | ||
145 | { | ||
146 | printf ("testweakkey: gcry_cipher_open failed on trial %d. %s\n", | ||
147 | number_of_runs, gcry_strerror (rc)); | ||
148 | continue; | ||
149 | } | ||
150 | |||
151 | rc = | ||
152 | gcry_cipher_setkey (handle, &sessionkey, | ||
153 | GNUNET_CRYPTO_AES_KEY_LENGTH); | ||
154 | |||
155 | if ((char) rc == GPG_ERR_WEAK_KEY) | ||
156 | { | ||
157 | printf ("\nWeak key (in hex): "); | ||
158 | printWeakKey (&sessionkey); | ||
159 | printf ("\n"); | ||
160 | number_of_weak_keys++; | ||
161 | } | ||
162 | else if (rc) | ||
163 | { | ||
164 | printf ("\nUnexpected error generating keys. Error is %s\n", | ||
165 | gcry_strerror (rc)); | ||
166 | } | ||
167 | |||
168 | gcry_cipher_close (handle); | ||
169 | 153 | ||
154 | if ((char) rc == GPG_ERR_WEAK_KEY) | ||
155 | { | ||
156 | printf ("\nWeak key (in hex): "); | ||
157 | printWeakKey (&sessionkey); | ||
158 | printf ("\n"); | ||
159 | number_of_weak_keys++; | ||
160 | } | ||
161 | else if (rc) | ||
162 | { | ||
163 | printf ("\nUnexpected error generating keys. Error is %s\n", | ||
164 | gcry_strerror (rc)); | ||
170 | } | 165 | } |
171 | 166 | ||
167 | gcry_cipher_close (handle); | ||
168 | |||
169 | } | ||
170 | |||
172 | return number_of_weak_keys; | 171 | return number_of_weak_keys; |
173 | } | 172 | } |
174 | 173 | ||
@@ -180,19 +179,19 @@ main (int argc, char *argv[]) | |||
180 | GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL); | 179 | GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL); |
181 | GNUNET_CRYPTO_random_disable_entropy_gathering (); | 180 | GNUNET_CRYPTO_random_disable_entropy_gathering (); |
182 | if (GENERATE_WEAK_KEYS) | 181 | if (GENERATE_WEAK_KEYS) |
182 | { | ||
183 | weak_keys = getWeakKeys (); | ||
184 | |||
185 | if (weak_keys == 0) | ||
186 | { | ||
187 | printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS); | ||
188 | } | ||
189 | else | ||
183 | { | 190 | { |
184 | weak_keys = getWeakKeys (); | 191 | printf ("\n%d weak keys found in %d runs.\n", |
185 | 192 | weak_keys, MAX_WEAK_KEY_TRIALS); | |
186 | if (weak_keys == 0) | ||
187 | { | ||
188 | printf ("\nNo weak keys found in %d runs.\n", MAX_WEAK_KEY_TRIALS); | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | printf ("\n%d weak keys found in %d runs.\n", | ||
193 | weak_keys, MAX_WEAK_KEY_TRIALS); | ||
194 | } | ||
195 | } | 193 | } |
194 | } | ||
196 | 195 | ||
197 | if (testWeakKey () != 0) | 196 | if (testWeakKey () != 0) |
198 | return -1; | 197 | return -1; |
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index 85de9fbbb..b0fa4f332 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c | |||
@@ -42,10 +42,10 @@ test (int number) | |||
42 | memset (&h1, number, sizeof (GNUNET_HashCode)); | 42 | memset (&h1, number, sizeof (GNUNET_HashCode)); |
43 | GNUNET_CRYPTO_hash_to_enc (&h1, &enc); | 43 | GNUNET_CRYPTO_hash_to_enc (&h1, &enc); |
44 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2)) | 44 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &h2)) |
45 | { | 45 | { |
46 | printf ("enc2hash failed!\n"); | 46 | printf ("enc2hash failed!\n"); |
47 | return 1; | 47 | return 1; |
48 | } | 48 | } |
49 | if (0 != memcmp (&h1, &h2, sizeof (GNUNET_HashCode))) | 49 | if (0 != memcmp (&h1, &h2, sizeof (GNUNET_HashCode))) |
50 | return 1; | 50 | return 1; |
51 | return 0; | 51 | return 0; |
@@ -55,6 +55,7 @@ static int | |||
55 | testEncoding () | 55 | testEncoding () |
56 | { | 56 | { |
57 | int i; | 57 | int i; |
58 | |||
58 | for (i = 0; i < 255; i++) | 59 | for (i = 0; i < 255; i++) |
59 | if (0 != test (i)) | 60 | if (0 != test (i)) |
60 | return 1; | 61 | return 1; |
@@ -123,9 +124,8 @@ static void | |||
123 | file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 124 | file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
124 | { | 125 | { |
125 | GNUNET_assert (NULL != | 126 | GNUNET_assert (NULL != |
126 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 127 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
127 | FILENAME, 1024, | 128 | FILENAME, 1024, &finished_task, cls)); |
128 | &finished_task, cls)); | ||
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
diff --git a/src/util/test_crypto_hkdf.c b/src/util/test_crypto_hkdf.c index 80523454e..a9b742922 100644 --- a/src/util/test_crypto_hkdf.c +++ b/src/util/test_crypto_hkdf.c | |||
@@ -35,239 +35,299 @@ | |||
35 | void | 35 | void |
36 | tc1 () | 36 | tc1 () |
37 | { | 37 | { |
38 | unsigned char ikm[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | 38 | unsigned char ikm[22] = |
39 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; | 39 | { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
40 | unsigned char salt[13] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | 40 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b |
41 | 0x0a, 0x0b, 0x0c }; | 41 | }; |
42 | unsigned char salt[13] = | ||
43 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | ||
44 | 0x0a, 0x0b, 0x0c | ||
45 | }; | ||
42 | unsigned char | 46 | unsigned char |
43 | info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; | 47 | info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; |
44 | unsigned char okm[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, | 48 | unsigned char okm[42] = |
45 | 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, | 49 | { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, |
46 | 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, | 50 | 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, |
47 | 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65 }; | 51 | 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, |
52 | 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65 | ||
53 | }; | ||
48 | unsigned char result[44]; | 54 | unsigned char result[44]; |
49 | int l = 42; | 55 | int l = 42; |
50 | 56 | ||
51 | memset (result, 0, sizeof(result)); | 57 | memset (result, 0, sizeof (result)); |
52 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, sizeof(salt), ikm, sizeof(ikm), info, sizeof(info), | 58 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
53 | NULL) == GNUNET_YES); | 59 | (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, |
54 | GNUNET_assert (memcmp(result, okm, l) == 0); | 60 | sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), |
55 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 61 | NULL) == GNUNET_YES); |
62 | GNUNET_assert (memcmp (result, okm, l) == 0); | ||
63 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
56 | } | 64 | } |
57 | 65 | ||
58 | void | 66 | void |
59 | tc2 () | 67 | tc2 () |
60 | { | 68 | { |
61 | unsigned char ikm[80] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | 69 | unsigned char ikm[80] = |
62 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, | 70 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, |
63 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | 71 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, |
64 | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, | 72 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, |
65 | 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, | 73 | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, |
66 | 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, | 74 | 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
67 | 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }; | 75 | 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, |
68 | unsigned char salt[80] = { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, | 76 | 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f |
69 | 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, | 77 | }; |
70 | 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, | 78 | unsigned char salt[80] = |
71 | 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, | 79 | { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
72 | 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, | 80 | 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, |
73 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, | 81 | 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, |
74 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; | 82 | 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, |
75 | unsigned char info[80] = { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, | 83 | 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, |
76 | 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, | 84 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, |
77 | 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, | 85 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf |
78 | 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, | 86 | }; |
79 | 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, | 87 | unsigned char info[80] = |
80 | 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, | 88 | { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, |
81 | 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; | 89 | 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, |
82 | unsigned char okm[82] = { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, | 90 | 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, |
83 | 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, | 91 | 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, |
84 | 0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04, | 92 | 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, |
85 | 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, | 93 | 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, |
86 | 0x0e, 0x09, 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77, | 94 | 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff |
87 | 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, | 95 | }; |
88 | 0x3e, 0x87, 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x1d, 0x87 }; | 96 | unsigned char okm[82] = |
97 | { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, | ||
98 | 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, | ||
99 | 0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04, | ||
100 | 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, | ||
101 | 0x0e, 0x09, 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77, | ||
102 | 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, | ||
103 | 0x3e, 0x87, 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x1d, 0x87 | ||
104 | }; | ||
89 | char result[84]; | 105 | char result[84]; |
90 | int l = 82; | 106 | int l = 82; |
91 | 107 | ||
92 | memset (result, 0, sizeof(result)); | 108 | memset (result, 0, sizeof (result)); |
93 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, sizeof(salt), ikm, sizeof(ikm), info, sizeof(info), | 109 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
94 | NULL) == GNUNET_YES); | 110 | (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, salt, |
95 | GNUNET_assert (memcmp(result, okm, l) == 0); | 111 | sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), |
96 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 112 | NULL) == GNUNET_YES); |
113 | GNUNET_assert (memcmp (result, okm, l) == 0); | ||
114 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
97 | } | 115 | } |
98 | 116 | ||
99 | void | 117 | void |
100 | tc3 () | 118 | tc3 () |
101 | { | 119 | { |
102 | unsigned char ikm[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | 120 | unsigned char ikm[22] = |
103 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; | 121 | { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
104 | unsigned char okm[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, | 122 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b |
105 | 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, | 123 | }; |
106 | 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20, | 124 | unsigned char okm[42] = |
107 | 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8 }; | 125 | { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, |
126 | 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, | ||
127 | 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20, | ||
128 | 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8 | ||
129 | }; | ||
108 | unsigned char result[44]; | 130 | unsigned char result[44]; |
109 | int l = 42; | 131 | int l = 42; |
110 | 132 | ||
111 | memset (result, 0, sizeof(result)); | 133 | memset (result, 0, sizeof (result)); |
112 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm, sizeof(ikm), NULL, 0, | 134 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
113 | NULL) == GNUNET_YES); | 135 | (result, l, GCRY_MD_SHA256, GCRY_MD_SHA256, NULL, 0, ikm, |
114 | GNUNET_assert (memcmp(result, okm, l) == 0); | 136 | sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); |
115 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 137 | GNUNET_assert (memcmp (result, okm, l) == 0); |
138 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
116 | } | 139 | } |
117 | 140 | ||
118 | void | 141 | void |
119 | tc4 () | 142 | tc4 () |
120 | { | 143 | { |
121 | unsigned char ikm[11] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | 144 | unsigned char ikm[11] = |
122 | 0x0b }; | 145 | { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
123 | unsigned char salt[13] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | 146 | 0x0b |
124 | 0x0a, 0x0b, 0x0c }; | 147 | }; |
148 | unsigned char salt[13] = | ||
149 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | ||
150 | 0x0a, 0x0b, 0x0c | ||
151 | }; | ||
125 | unsigned char | 152 | unsigned char |
126 | info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; | 153 | info[10] = { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; |
127 | unsigned char okm[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06, | 154 | unsigned char okm[42] = |
128 | 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, | 155 | { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06, |
129 | 0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e, | 156 | 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, |
130 | 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96 }; | 157 | 0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e, |
158 | 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96 | ||
159 | }; | ||
131 | char result[84]; | 160 | char result[84]; |
132 | int l = 42; | 161 | int l = 42; |
133 | 162 | ||
134 | memset (result, 0, sizeof(result)); | 163 | memset (result, 0, sizeof (result)); |
135 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof(salt), ikm, sizeof(ikm), info, sizeof(info), | 164 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
136 | NULL) == GNUNET_YES); | 165 | (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), |
137 | GNUNET_assert (memcmp(result, okm, l) == 0); | 166 | ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES); |
138 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 167 | GNUNET_assert (memcmp (result, okm, l) == 0); |
168 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
139 | } | 169 | } |
140 | 170 | ||
141 | void | 171 | void |
142 | tc5 () | 172 | tc5 () |
143 | { | 173 | { |
144 | unsigned char ikm[80] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | 174 | unsigned char ikm[80] = |
145 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, | 175 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, |
146 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | 176 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, |
147 | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, | 177 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, |
148 | 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, | 178 | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, |
149 | 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, | 179 | 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
150 | 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }; | 180 | 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, |
151 | unsigned char salt[80] = { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, | 181 | 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f |
152 | 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, | 182 | }; |
153 | 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, | 183 | unsigned char salt[80] = |
154 | 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, | 184 | { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
155 | 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, | 185 | 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, |
156 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, | 186 | 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, |
157 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; | 187 | 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, |
158 | unsigned char info[80] = { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, | 188 | 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, |
159 | 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, | 189 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, |
160 | 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, | 190 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf |
161 | 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, | 191 | }; |
162 | 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, | 192 | unsigned char info[80] = |
163 | 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, | 193 | { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, |
164 | 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; | 194 | 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, |
165 | unsigned char okm[82] = { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, | 195 | 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, |
166 | 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, | 196 | 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, |
167 | 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, | 197 | 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, |
168 | 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, | 198 | 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, |
169 | 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c, | 199 | 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff |
170 | 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f, | 200 | }; |
171 | 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 }; | 201 | unsigned char okm[82] = |
202 | { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, | ||
203 | 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, | ||
204 | 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, | ||
205 | 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, | ||
206 | 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c, | ||
207 | 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f, | ||
208 | 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 | ||
209 | }; | ||
172 | char result[84]; | 210 | char result[84]; |
173 | int l = 82; | 211 | int l = 82; |
174 | 212 | ||
175 | memset (result, 0, sizeof(result)); | 213 | memset (result, 0, sizeof (result)); |
176 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof(salt), ikm, sizeof(ikm), info, sizeof(info), | 214 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
177 | NULL) == GNUNET_YES); | 215 | (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), |
178 | GNUNET_assert (memcmp(result, okm, l) == 0); | 216 | ikm, sizeof (ikm), info, sizeof (info), NULL) == GNUNET_YES); |
179 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 217 | GNUNET_assert (memcmp (result, okm, l) == 0); |
218 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
180 | } | 219 | } |
181 | 220 | ||
182 | void | 221 | void |
183 | tc6 () | 222 | tc6 () |
184 | { | 223 | { |
185 | unsigned char ikm[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | 224 | unsigned char ikm[22] = |
186 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; | 225 | { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
187 | unsigned char okm[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5, | 226 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b |
188 | 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, | 227 | }; |
189 | 0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00, | 228 | unsigned char okm[42] = |
190 | 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18 }; | 229 | { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5, |
230 | 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, | ||
231 | 0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00, | ||
232 | 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18 | ||
233 | }; | ||
191 | char result[44]; | 234 | char result[44]; |
192 | int l = 42; | 235 | int l = 42; |
193 | 236 | ||
194 | memset (result, 0, sizeof(result)); | 237 | memset (result, 0, sizeof (result)); |
195 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm, sizeof(ikm), NULL, 0, | 238 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
196 | NULL) == GNUNET_YES); | 239 | (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, NULL, 0, ikm, |
197 | GNUNET_assert (memcmp(result, okm, l) == 0); | 240 | sizeof (ikm), NULL, 0, NULL) == GNUNET_YES); |
198 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 241 | GNUNET_assert (memcmp (result, okm, l) == 0); |
242 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
199 | } | 243 | } |
200 | 244 | ||
201 | void | 245 | void |
202 | tc7 () | 246 | tc7 () |
203 | { | 247 | { |
204 | unsigned char ikm[80] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, | 248 | unsigned char ikm[80] = |
205 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, | 249 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, |
206 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | 250 | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, |
207 | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, | 251 | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, |
208 | 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, | 252 | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, |
209 | 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, | 253 | 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
210 | 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }; | 254 | 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, |
211 | unsigned char salt[80] = { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, | 255 | 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f |
212 | 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, | 256 | }; |
213 | 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, | 257 | unsigned char salt[80] = |
214 | 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, | 258 | { 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
215 | 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, | 259 | 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, |
216 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, | 260 | 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, |
217 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf }; | 261 | 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, |
262 | 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, | ||
263 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, | ||
264 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf | ||
265 | }; | ||
218 | unsigned char info1[34] = { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, | 266 | unsigned char info1[34] = { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, |
219 | 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, | 267 | 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, |
220 | 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, | 268 | 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, |
221 | 0xd0, 0xd1 }; | 269 | 0xd0, 0xd1 |
270 | }; | ||
222 | unsigned char info2[46] = { 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, | 271 | unsigned char info2[46] = { 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, |
223 | 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, | 272 | 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, |
224 | 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, | 273 | 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, |
225 | 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, | 274 | 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, |
226 | 0xfe, 0xff }; | 275 | 0xfe, 0xff |
227 | unsigned char okm[82] = { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, | 276 | }; |
228 | 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, | 277 | unsigned char okm[82] = |
229 | 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, | 278 | { 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, |
230 | 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, | 279 | 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, |
231 | 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c, | 280 | 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, |
232 | 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f, | 281 | 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, |
233 | 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 }; | 282 | 0x17, 0x3c, 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c, |
283 | 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f, | ||
284 | 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 | ||
285 | }; | ||
234 | char result[84]; | 286 | char result[84]; |
235 | int l = 82; | 287 | int l = 82; |
236 | 288 | ||
237 | memset (result, 0, sizeof(result)); | 289 | memset (result, 0, sizeof (result)); |
238 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, | 290 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
239 | sizeof(salt), ikm, sizeof(ikm), info1, sizeof(info1), info2, sizeof(info2), | 291 | (result, l, GCRY_MD_SHA1, GCRY_MD_SHA1, salt, sizeof (salt), |
240 | NULL) == GNUNET_YES); | 292 | ikm, sizeof (ikm), info1, sizeof (info1), info2, |
241 | GNUNET_assert (memcmp(result, okm, l) == 0); | 293 | sizeof (info2), NULL) == GNUNET_YES); |
242 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 294 | GNUNET_assert (memcmp (result, okm, l) == 0); |
295 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
243 | } | 296 | } |
244 | 297 | ||
245 | void | 298 | void |
246 | tc8 () | 299 | tc8 () |
247 | { | 300 | { |
248 | unsigned char ikm[32] = { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72, | 301 | unsigned char ikm[32] = |
249 | 0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81, 0xbe, | 302 | { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3, 0x93, 0xa7, 0x72, |
250 | 0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde }; | 303 | 0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81, 0xbe, |
304 | 0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde | ||
305 | }; | ||
251 | unsigned char salt[4] = { 0xfc, 0x62, 0x76, 0x35 }; | 306 | unsigned char salt[4] = { 0xfc, 0x62, 0x76, 0x35 }; |
252 | unsigned char info[86] = { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b, | 307 | unsigned char info[86] = |
253 | 0x1d, 0x33, 0x15, 0x3e, 0x52, 0x0b, 0xb0, 0x77, 0xff, 0x7d, 0xc3, 0xc7, | 308 | { 0x8c, 0x0d, 0xcf, 0xb3, 0x25, 0x6e, 0x88, 0x0d, 0xc1, 0x0b, |
254 | 0xef, 0xe5, 0x8e, 0x3c, 0xc4, 0x4e, 0x8b, 0x41, 0x46, 0x1f, 0x02, 0x94, | 309 | 0x1d, 0x33, 0x15, 0x3e, 0x52, 0x0b, 0xb0, 0x77, 0xff, 0x7d, 0xc3, 0xc7, |
255 | 0x82, 0x35, 0xc5, 0xa6, 0x5e, 0x91, 0xd8, 0xa2, 0x90, 0xfd, 0x6f, 0xb4, | 310 | 0xef, 0xe5, 0x8e, 0x3c, 0xc4, 0x4e, 0x8b, 0x41, 0x46, 0x1f, 0x02, 0x94, |
256 | 0x07, 0xc9, 0xed, 0x6b, 0x18, 0x90, 0x31, 0xab, 0x0f, 0xb5, 0x6b, 0xec, | 311 | 0x82, 0x35, 0xc5, 0xa6, 0x5e, 0x91, 0xd8, 0xa2, 0x90, 0xfd, 0x6f, 0xb4, |
257 | 0x9e, 0x45, 0xa2, 0x83, 0x65, 0x41, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, | 312 | 0x07, 0xc9, 0xed, 0x6b, 0x18, 0x90, 0x31, 0xab, 0x0f, 0xb5, 0x6b, 0xec, |
258 | 0x6c, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x76, 0x65, 0x63, | 313 | 0x9e, 0x45, 0xa2, 0x83, 0x65, 0x41, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, |
259 | 0x74, 0x6f, 0x72, 0x00 }; | 314 | 0x6c, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x76, 0x65, 0x63, |
260 | unsigned char okm[16] = { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92, | 315 | 0x74, 0x6f, 0x72, 0x00 |
261 | 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0 }; | 316 | }; |
317 | unsigned char okm[16] = | ||
318 | { 0xd6, 0x90, 0xec, 0x9e, 0x62, 0xdf, 0xb9, 0x41, 0xff, 0x92, | ||
319 | 0x4f, 0xd2, 0xf6, 0x1d, 0x67, 0xe0 | ||
320 | }; | ||
262 | char result[18]; | 321 | char result[18]; |
263 | int l = 16; | 322 | int l = 16; |
264 | 323 | ||
265 | memset (result, 0, sizeof(result)); | 324 | memset (result, 0, sizeof (result)); |
266 | GNUNET_assert (GNUNET_CRYPTO_hkdf(result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt, | 325 | GNUNET_assert (GNUNET_CRYPTO_hkdf |
267 | sizeof(salt), ikm, sizeof(ikm), info, sizeof(info), | 326 | (result, l, GCRY_MD_SHA512, GCRY_MD_SHA256, salt, |
268 | NULL) == GNUNET_YES); | 327 | sizeof (salt), ikm, sizeof (ikm), info, sizeof (info), |
269 | GNUNET_assert (memcmp(result, okm, l) == 0); | 328 | NULL) == GNUNET_YES); |
270 | GNUNET_assert (memcmp(result + l, "\0", 2) == 0); | 329 | GNUNET_assert (memcmp (result, okm, l) == 0); |
330 | GNUNET_assert (memcmp (result + l, "\0", 2) == 0); | ||
271 | } | 331 | } |
272 | 332 | ||
273 | int | 333 | int |
@@ -276,16 +336,16 @@ main () | |||
276 | GNUNET_log_setup ("test-crypto-hkdf", "WARNING", NULL); | 336 | GNUNET_log_setup ("test-crypto-hkdf", "WARNING", NULL); |
277 | 337 | ||
278 | /* Official test vectors */ | 338 | /* Official test vectors */ |
279 | tc1(); | 339 | tc1 (); |
280 | tc2(); | 340 | tc2 (); |
281 | tc3(); | 341 | tc3 (); |
282 | tc4(); | 342 | tc4 (); |
283 | tc5(); | 343 | tc5 (); |
284 | tc6(); | 344 | tc6 (); |
285 | 345 | ||
286 | /* Additional tests */ | 346 | /* Additional tests */ |
287 | tc7(); | 347 | tc7 (); |
288 | tc8(); | 348 | tc8 (); |
289 | 349 | ||
290 | return 0; | 350 | return 0; |
291 | } | 351 | } |
diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c index 74f88d5bf..184f9f137 100644 --- a/src/util/test_crypto_ksk.c +++ b/src/util/test_crypto_ksk.c | |||
@@ -38,7 +38,8 @@ | |||
38 | static int | 38 | static int |
39 | testCorrectKey () | 39 | testCorrectKey () |
40 | { | 40 | { |
41 | const char *want = "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000"; | 41 | const char *want = |
42 | "010601000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b73c215f7a5e6b09bec55713c901786c09324a150980e014bdb0d04426934929c3b4971a9711af5455536cd6eeb8bfa004ee904972a737455f53c752987d8c82b755bc02882b44950c4acdc1672ba74c3b94d81a4c1ea3d74e7700ae5594c3a4f3c559e4bff2df6844fac302e4b66175e14dc8bad3ce44281d2fec1a1abef06301010000"; | ||
42 | GNUNET_HashCode in; | 43 | GNUNET_HashCode in; |
43 | struct GNUNET_CRYPTO_RsaPrivateKey *hostkey; | 44 | struct GNUNET_CRYPTO_RsaPrivateKey *hostkey; |
44 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | 45 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; |
@@ -49,29 +50,28 @@ testCorrectKey () | |||
49 | GNUNET_CRYPTO_hash ("X", strlen ("X"), &in); | 50 | GNUNET_CRYPTO_hash ("X", strlen ("X"), &in); |
50 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); | 51 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); |
51 | if (hostkey == NULL) | 52 | if (hostkey == NULL) |
52 | { | 53 | { |
53 | GNUNET_break (0); | 54 | GNUNET_break (0); |
54 | return GNUNET_SYSERR; | 55 | return GNUNET_SYSERR; |
55 | } | 56 | } |
56 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); | 57 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); |
57 | GNUNET_CRYPTO_rsa_key_free (hostkey); | 58 | GNUNET_CRYPTO_rsa_key_free (hostkey); |
58 | #if 0 | 59 | #if 0 |
59 | for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++) | 60 | for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++) |
60 | printf("%02x", ((unsigned char*) &pkey)[i]); | 61 | printf ("%02x", ((unsigned char *) &pkey)[i]); |
61 | printf ("\n"); | 62 | printf ("\n"); |
62 | #endif | 63 | #endif |
63 | for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++) | 64 | for (i = 0; i < sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded); i++) |
65 | { | ||
66 | snprintf (out, sizeof (out), "%02x", ((unsigned char *) &pkey)[i]); | ||
67 | if (0 != strncmp (out, &want[i * 2], 2)) | ||
64 | { | 68 | { |
65 | snprintf(out, sizeof (out), "%02x", ((unsigned char*) &pkey)[i]); | 69 | fprintf (stderr, |
66 | if (0 != strncmp (out, &want[i*2], 2)) | 70 | " Failed! Wanted %.2s but got %2s at %d\n", |
67 | { | 71 | &want[i * 2], out, i); |
68 | fprintf (stderr, | 72 | return GNUNET_SYSERR; |
69 | " Failed! Wanted %.2s but got %2s at %d\n", | ||
70 | &want[i*2], | ||
71 | out, i); | ||
72 | return GNUNET_SYSERR; | ||
73 | } | ||
74 | } | 73 | } |
74 | } | ||
75 | fprintf (stderr, " OK\n"); | 75 | fprintf (stderr, " OK\n"); |
76 | return GNUNET_OK; | 76 | return GNUNET_OK; |
77 | } | 77 | } |
@@ -90,37 +90,37 @@ testMultiKey (const char *word) | |||
90 | GNUNET_CRYPTO_hash (word, strlen (word), &in); | 90 | GNUNET_CRYPTO_hash (word, strlen (word), &in); |
91 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); | 91 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); |
92 | if (hostkey == NULL) | 92 | if (hostkey == NULL) |
93 | { | 93 | { |
94 | GNUNET_break (0); | 94 | GNUNET_break (0); |
95 | return GNUNET_SYSERR; | 95 | return GNUNET_SYSERR; |
96 | } | 96 | } |
97 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); | 97 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); |
98 | /* | 98 | /* |
99 | for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++) | 99 | * for (i=0;i<sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);i++) |
100 | printf("%02x", ((unsigned char*) &pkey)[i]); | 100 | * printf("%02x", ((unsigned char*) &pkey)[i]); |
101 | printf("\n"); */ | 101 | * printf("\n"); */ |
102 | GNUNET_CRYPTO_rsa_key_free (hostkey); | 102 | GNUNET_CRYPTO_rsa_key_free (hostkey); |
103 | for (i = 0; i < UNIQUE_ITER; i++) | 103 | for (i = 0; i < UNIQUE_ITER; i++) |
104 | { | ||
105 | fprintf (stderr, "."); | ||
106 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); | ||
107 | if (hostkey == NULL) | ||
104 | { | 108 | { |
105 | fprintf (stderr, "."); | 109 | GNUNET_break (0); |
106 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); | 110 | fprintf (stderr, " ERROR\n"); |
107 | if (hostkey == NULL) | 111 | return GNUNET_SYSERR; |
108 | { | ||
109 | GNUNET_break (0); | ||
110 | fprintf (stderr, " ERROR\n"); | ||
111 | return GNUNET_SYSERR; | ||
112 | } | ||
113 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1); | ||
114 | GNUNET_CRYPTO_rsa_key_free (hostkey); | ||
115 | if (0 != | ||
116 | memcmp (&pkey, &pkey1, | ||
117 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | ||
118 | { | ||
119 | GNUNET_break (0); | ||
120 | fprintf (stderr, " ERROR\n"); | ||
121 | return GNUNET_SYSERR; | ||
122 | } | ||
123 | } | 112 | } |
113 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey1); | ||
114 | GNUNET_CRYPTO_rsa_key_free (hostkey); | ||
115 | if (0 != | ||
116 | memcmp (&pkey, &pkey1, | ||
117 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | ||
118 | { | ||
119 | GNUNET_break (0); | ||
120 | fprintf (stderr, " ERROR\n"); | ||
121 | return GNUNET_SYSERR; | ||
122 | } | ||
123 | } | ||
124 | fprintf (stderr, " OK\n"); | 124 | fprintf (stderr, " OK\n"); |
125 | return GNUNET_OK; | 125 | return GNUNET_OK; |
126 | } | 126 | } |
@@ -142,32 +142,32 @@ testEncryptDecrypt (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
142 | ok = 0; | 142 | ok = 0; |
143 | start = GNUNET_TIME_absolute_get (); | 143 | start = GNUNET_TIME_absolute_get (); |
144 | for (i = 0; i < ITER; i++) | 144 | for (i = 0; i < ITER; i++) |
145 | { | ||
146 | fprintf (stderr, "."); | ||
147 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, | ||
148 | strlen (TESTSTRING) + 1, | ||
149 | &pkey, &target)) | ||
150 | { | ||
151 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); | ||
152 | ok++; | ||
153 | continue; | ||
154 | } | ||
155 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, | ||
156 | &target, result, | ||
157 | strlen (TESTSTRING) + 1)) | ||
145 | { | 158 | { |
146 | fprintf (stderr, "."); | 159 | fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); |
147 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, | 160 | ok++; |
148 | strlen (TESTSTRING) + 1, | 161 | continue; |
149 | &pkey, &target)) | ||
150 | { | ||
151 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); | ||
152 | ok++; | ||
153 | continue; | ||
154 | } | ||
155 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, | ||
156 | &target, result, | ||
157 | strlen (TESTSTRING) + 1)) | ||
158 | { | ||
159 | fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); | ||
160 | ok++; | ||
161 | continue; | ||
162 | } | ||
163 | if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) | ||
164 | { | ||
165 | printf ("%s != %.*s - testEncryptDecrypt failed!\n", | ||
166 | TESTSTRING, MAX_TESTVAL, result); | ||
167 | ok++; | ||
168 | continue; | ||
169 | } | ||
170 | } | 162 | } |
163 | if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) | ||
164 | { | ||
165 | printf ("%s != %.*s - testEncryptDecrypt failed!\n", | ||
166 | TESTSTRING, MAX_TESTVAL, result); | ||
167 | ok++; | ||
168 | continue; | ||
169 | } | ||
170 | } | ||
171 | printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", | 171 | printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", |
172 | ITER, | 172 | ITER, |
173 | (unsigned long long) | 173 | (unsigned long long) |
@@ -194,31 +194,31 @@ testSignVerify (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey) | |||
194 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)); | 194 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)); |
195 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 195 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
196 | for (i = 0; i < ITER; i++) | 196 | for (i = 0; i < ITER; i++) |
197 | { | ||
198 | fprintf (stderr, "."); | ||
199 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) | ||
200 | { | ||
201 | fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); | ||
202 | ok = GNUNET_SYSERR; | ||
203 | continue; | ||
204 | } | ||
205 | if (GNUNET_SYSERR == | ||
206 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, | ||
207 | &purp, &sig, &pkey)) | ||
208 | { | ||
209 | printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); | ||
210 | ok = GNUNET_SYSERR; | ||
211 | continue; | ||
212 | } | ||
213 | if (GNUNET_SYSERR != | ||
214 | GNUNET_CRYPTO_rsa_verify | ||
215 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) | ||
197 | { | 216 | { |
198 | fprintf (stderr, "."); | 217 | printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); |
199 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) | 218 | ok = GNUNET_SYSERR; |
200 | { | 219 | continue; |
201 | fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); | ||
202 | ok = GNUNET_SYSERR; | ||
203 | continue; | ||
204 | } | ||
205 | if (GNUNET_SYSERR == | ||
206 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, | ||
207 | &purp, &sig, &pkey)) | ||
208 | { | ||
209 | printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); | ||
210 | ok = GNUNET_SYSERR; | ||
211 | continue; | ||
212 | } | ||
213 | if (GNUNET_SYSERR != | ||
214 | GNUNET_CRYPTO_rsa_verify | ||
215 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) | ||
216 | { | ||
217 | printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); | ||
218 | ok = GNUNET_SYSERR; | ||
219 | continue; | ||
220 | } | ||
221 | } | 220 | } |
221 | } | ||
222 | printf ("%d RSA sign/verify operations %llums\n", | 222 | printf ("%d RSA sign/verify operations %llums\n", |
223 | ITER, | 223 | ITER, |
224 | (unsigned long long) | 224 | (unsigned long long) |
@@ -240,10 +240,10 @@ main (int argc, char *argv[]) | |||
240 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in); | 240 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &in); |
241 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); | 241 | hostkey = GNUNET_CRYPTO_rsa_key_create_from_hash (&in); |
242 | if (hostkey == NULL) | 242 | if (hostkey == NULL) |
243 | { | 243 | { |
244 | printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n"); | 244 | printf ("\nGNUNET_CRYPTO_rsa_key_create_from_hash failed!\n"); |
245 | return 1; | 245 | return 1; |
246 | } | 246 | } |
247 | if (GNUNET_OK != testMultiKey ("foo")) | 247 | if (GNUNET_OK != testMultiKey ("foo")) |
248 | failureCount++; | 248 | failureCount++; |
249 | if (GNUNET_OK != testMultiKey ("bar")) | 249 | if (GNUNET_OK != testMultiKey ("bar")) |
@@ -255,9 +255,9 @@ main (int argc, char *argv[]) | |||
255 | GNUNET_CRYPTO_rsa_key_free (hostkey); | 255 | GNUNET_CRYPTO_rsa_key_free (hostkey); |
256 | 256 | ||
257 | if (failureCount != 0) | 257 | if (failureCount != 0) |
258 | { | 258 | { |
259 | printf ("\n\n%d TESTS FAILED!\n\n", failureCount); | 259 | printf ("\n\n%d TESTS FAILED!\n\n", failureCount); |
260 | return -1; | 260 | return -1; |
261 | } | 261 | } |
262 | return 0; | 262 | return 0; |
263 | } | 263 | } |
diff --git a/src/util/test_crypto_random.c b/src/util/test_crypto_random.c index 76230410d..46d3ed0aa 100644 --- a/src/util/test_crypto_random.c +++ b/src/util/test_crypto_random.c | |||
@@ -39,17 +39,17 @@ test (enum GNUNET_CRYPTO_Quality mode) | |||
39 | for (i = 0; i < 1024; i++) | 39 | for (i = 0; i < 1024; i++) |
40 | GNUNET_break (1024 > (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024))); | 40 | GNUNET_break (1024 > (buf[i] = GNUNET_CRYPTO_random_u32 (mode, 1024))); |
41 | for (i = 0; i < 10; i++) | 41 | for (i = 0; i < 10; i++) |
42 | { | ||
43 | b2 = GNUNET_CRYPTO_random_permute (mode, 1024); | ||
44 | if (0 == memcmp (b2, buf, sizeof (buf))) | ||
42 | { | 45 | { |
43 | b2 = GNUNET_CRYPTO_random_permute (mode, 1024); | 46 | fprintf (stderr, "!"); |
44 | if (0 == memcmp (b2, buf, sizeof (buf))) | ||
45 | { | ||
46 | fprintf (stderr, "!"); | ||
47 | GNUNET_free (b2); | ||
48 | continue; | ||
49 | } | ||
50 | GNUNET_free (b2); | 47 | GNUNET_free (b2); |
51 | break; | 48 | continue; |
52 | } | 49 | } |
50 | GNUNET_free (b2); | ||
51 | break; | ||
52 | } | ||
53 | if (i == 10) | 53 | if (i == 10) |
54 | return 1; /* virtually impossible... */ | 54 | return 1; /* virtually impossible... */ |
55 | 55 | ||
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index 396294a48..d7c23731e 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c | |||
@@ -54,33 +54,33 @@ testEncryptDecrypt () | |||
54 | ok = 0; | 54 | ok = 0; |
55 | start = GNUNET_TIME_absolute_get (); | 55 | start = GNUNET_TIME_absolute_get (); |
56 | for (i = 0; i < ITER; i++) | 56 | for (i = 0; i < ITER; i++) |
57 | { | ||
58 | fprintf (stderr, "."); | ||
59 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, | ||
60 | strlen (TESTSTRING) + 1, | ||
61 | &pkey, &target)) | ||
57 | { | 62 | { |
58 | fprintf (stderr, "."); | 63 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); |
59 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, | 64 | ok++; |
60 | strlen (TESTSTRING) + 1, | 65 | continue; |
61 | &pkey, &target)) | 66 | } |
62 | { | 67 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, |
63 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); | 68 | &target, result, |
64 | ok++; | 69 | strlen (TESTSTRING) + 1)) |
65 | continue; | 70 | { |
66 | } | 71 | fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); |
67 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, | 72 | ok++; |
68 | &target, result, | 73 | continue; |
69 | strlen (TESTSTRING) + 1)) | ||
70 | { | ||
71 | fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); | ||
72 | ok++; | ||
73 | continue; | ||
74 | 74 | ||
75 | } | ||
76 | if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) | ||
77 | { | ||
78 | printf ("%s != %.*s - testEncryptDecrypt failed!\n", | ||
79 | TESTSTRING, (int) MAX_TESTVAL, result); | ||
80 | ok++; | ||
81 | continue; | ||
82 | } | ||
83 | } | 75 | } |
76 | if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) | ||
77 | { | ||
78 | printf ("%s != %.*s - testEncryptDecrypt failed!\n", | ||
79 | TESTSTRING, (int) MAX_TESTVAL, result); | ||
80 | ok++; | ||
81 | continue; | ||
82 | } | ||
83 | } | ||
84 | printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", | 84 | printf ("%d RSA encrypt/decrypt operations %llums (%d failures)\n", |
85 | ITER, | 85 | ITER, |
86 | (unsigned long long) | 86 | (unsigned long long) |
@@ -110,17 +110,17 @@ testEncryptPerformance () | |||
110 | ok = 0; | 110 | ok = 0; |
111 | start = GNUNET_TIME_absolute_get (); | 111 | start = GNUNET_TIME_absolute_get (); |
112 | for (i = 0; i < ITER; i++) | 112 | for (i = 0; i < ITER; i++) |
113 | { | ||
114 | fprintf (stderr, "."); | ||
115 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, | ||
116 | strlen (TESTSTRING) + 1, | ||
117 | &pkey, &target)) | ||
113 | { | 118 | { |
114 | fprintf (stderr, "."); | 119 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); |
115 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (TESTSTRING, | 120 | ok++; |
116 | strlen (TESTSTRING) + 1, | 121 | continue; |
117 | &pkey, &target)) | ||
118 | { | ||
119 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); | ||
120 | ok++; | ||
121 | continue; | ||
122 | } | ||
123 | } | 122 | } |
123 | } | ||
124 | printf ("%d RSA encrypt operations %llu ms (%d failures)\n", | 124 | printf ("%d RSA encrypt operations %llu ms (%d failures)\n", |
125 | ITER, | 125 | ITER, |
126 | (unsigned long long) | 126 | (unsigned long long) |
@@ -151,35 +151,35 @@ testEncryptDecryptSK () | |||
151 | ok = 0; | 151 | ok = 0; |
152 | start = GNUNET_TIME_absolute_get (); | 152 | start = GNUNET_TIME_absolute_get (); |
153 | for (i = 0; i < ITER; i++) | 153 | for (i = 0; i < ITER; i++) |
154 | { | ||
155 | fprintf (stderr, "."); | ||
156 | GNUNET_CRYPTO_aes_create_session_key (&insk); | ||
157 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&insk, | ||
158 | sizeof (struct | ||
159 | GNUNET_CRYPTO_AesSessionKey), | ||
160 | &pkey, &target)) | ||
161 | { | ||
162 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); | ||
163 | ok++; | ||
164 | continue; | ||
165 | } | ||
166 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, | ||
167 | &target, &outsk, | ||
168 | sizeof (struct | ||
169 | GNUNET_CRYPTO_AesSessionKey))) | ||
170 | { | ||
171 | fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); | ||
172 | ok++; | ||
173 | continue; | ||
174 | } | ||
175 | if (0 != | ||
176 | memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey))) | ||
154 | { | 177 | { |
155 | fprintf (stderr, "."); | 178 | printf ("testEncryptDecryptSK failed!\n"); |
156 | GNUNET_CRYPTO_aes_create_session_key (&insk); | 179 | ok++; |
157 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&insk, | 180 | continue; |
158 | sizeof (struct | ||
159 | GNUNET_CRYPTO_AesSessionKey), | ||
160 | &pkey, &target)) | ||
161 | { | ||
162 | fprintf (stderr, "GNUNET_CRYPTO_rsa_encrypt returned SYSERR\n"); | ||
163 | ok++; | ||
164 | continue; | ||
165 | } | ||
166 | if (-1 == GNUNET_CRYPTO_rsa_decrypt (hostkey, | ||
167 | &target, &outsk, | ||
168 | sizeof (struct | ||
169 | GNUNET_CRYPTO_AesSessionKey))) | ||
170 | { | ||
171 | fprintf (stderr, "GNUNET_CRYPTO_rsa_decrypt returned SYSERR\n"); | ||
172 | ok++; | ||
173 | continue; | ||
174 | } | ||
175 | if (0 != | ||
176 | memcmp (&insk, &outsk, sizeof (struct GNUNET_CRYPTO_AesSessionKey))) | ||
177 | { | ||
178 | printf ("testEncryptDecryptSK failed!\n"); | ||
179 | ok++; | ||
180 | continue; | ||
181 | } | ||
182 | } | 181 | } |
182 | } | ||
183 | printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", | 183 | printf ("%d RSA encrypt/decrypt SK operations %llums (%d failures)\n", |
184 | ITER, | 184 | ITER, |
185 | (unsigned long long) | 185 | (unsigned long long) |
@@ -210,31 +210,31 @@ testSignVerify () | |||
210 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 210 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
211 | 211 | ||
212 | for (i = 0; i < ITER; i++) | 212 | for (i = 0; i < ITER; i++) |
213 | { | ||
214 | fprintf (stderr, "."); | ||
215 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) | ||
213 | { | 216 | { |
214 | fprintf (stderr, "."); | 217 | fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); |
215 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) | 218 | ok = GNUNET_SYSERR; |
216 | { | 219 | continue; |
217 | fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); | ||
218 | ok = GNUNET_SYSERR; | ||
219 | continue; | ||
220 | } | ||
221 | if (GNUNET_SYSERR == | ||
222 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, | ||
223 | &purp, &sig, &pkey)) | ||
224 | { | ||
225 | printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); | ||
226 | ok = GNUNET_SYSERR; | ||
227 | continue; | ||
228 | } | ||
229 | if (GNUNET_SYSERR != | ||
230 | GNUNET_CRYPTO_rsa_verify | ||
231 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) | ||
232 | { | ||
233 | printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); | ||
234 | ok = GNUNET_SYSERR; | ||
235 | continue; | ||
236 | } | ||
237 | } | 220 | } |
221 | if (GNUNET_SYSERR == | ||
222 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, | ||
223 | &purp, &sig, &pkey)) | ||
224 | { | ||
225 | printf ("GNUNET_CRYPTO_rsa_verify failed!\n"); | ||
226 | ok = GNUNET_SYSERR; | ||
227 | continue; | ||
228 | } | ||
229 | if (GNUNET_SYSERR != | ||
230 | GNUNET_CRYPTO_rsa_verify | ||
231 | (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey)) | ||
232 | { | ||
233 | printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); | ||
234 | ok = GNUNET_SYSERR; | ||
235 | continue; | ||
236 | } | ||
237 | } | ||
238 | printf ("%d RSA sign/verify operations %llums\n", | 238 | printf ("%d RSA sign/verify operations %llums\n", |
239 | ITER, | 239 | ITER, |
240 | (unsigned long long) | 240 | (unsigned long long) |
@@ -263,15 +263,15 @@ testSignPerformance () | |||
263 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); | 263 | GNUNET_CRYPTO_rsa_key_get_public (hostkey, &pkey); |
264 | start = GNUNET_TIME_absolute_get (); | 264 | start = GNUNET_TIME_absolute_get (); |
265 | for (i = 0; i < ITER; i++) | 265 | for (i = 0; i < ITER; i++) |
266 | { | ||
267 | fprintf (stderr, "."); | ||
268 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) | ||
266 | { | 269 | { |
267 | fprintf (stderr, "."); | 270 | fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); |
268 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_sign (hostkey, &purp, &sig)) | 271 | ok = GNUNET_SYSERR; |
269 | { | 272 | continue; |
270 | fprintf (stderr, "GNUNET_CRYPTO_rsa_sign returned SYSERR\n"); | ||
271 | ok = GNUNET_SYSERR; | ||
272 | continue; | ||
273 | } | ||
274 | } | 273 | } |
274 | } | ||
275 | printf ("%d RSA sign operations %llu ms\n", ITER, | 275 | printf ("%d RSA sign operations %llu ms\n", ITER, |
276 | (unsigned long long) | 276 | (unsigned long long) |
277 | GNUNET_TIME_absolute_get_duration (start).rel_value); | 277 | GNUNET_TIME_absolute_get_duration (start).rel_value); |
@@ -292,7 +292,7 @@ testCreateFromFile () | |||
292 | GNUNET_assert (NULL != key); | 292 | GNUNET_assert (NULL != key); |
293 | GNUNET_CRYPTO_rsa_key_get_public (key, &p1); | 293 | GNUNET_CRYPTO_rsa_key_get_public (key, &p1); |
294 | GNUNET_CRYPTO_rsa_key_free (key); | 294 | GNUNET_CRYPTO_rsa_key_free (key); |
295 | key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE); | 295 | key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE); |
296 | GNUNET_assert (NULL != key); | 296 | GNUNET_assert (NULL != key); |
297 | GNUNET_CRYPTO_rsa_key_get_public (key, &p2); | 297 | GNUNET_CRYPTO_rsa_key_get_public (key, &p2); |
298 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1))); | 298 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1))); |
@@ -331,9 +331,9 @@ main (int argc, char *argv[]) | |||
331 | failureCount++; | 331 | failureCount++; |
332 | 332 | ||
333 | if (failureCount != 0) | 333 | if (failureCount != 0) |
334 | { | 334 | { |
335 | printf ("\n\n%d TESTS FAILED!\n\n", failureCount); | 335 | printf ("\n\n%d TESTS FAILED!\n\n", failureCount); |
336 | return -1; | 336 | return -1; |
337 | } | 337 | } |
338 | return 0; | 338 | return 0; |
339 | } /* end of main */ | 339 | } /* end of main */ |
diff --git a/src/util/test_disk.c b/src/util/test_disk.c index fb79e7cd8..d8d8021e5 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c | |||
@@ -46,36 +46,35 @@ testReadWrite () | |||
46 | return 1; | 46 | return 1; |
47 | ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); | 47 | ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1); |
48 | if (ret < 0) | 48 | if (ret < 0) |
49 | { | 49 | { |
50 | fprintf (stderr, | 50 | fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile"); |
51 | "Error reading file `%s' in testReadWrite\n", ".testfile"); | 51 | return 1; |
52 | return 1; | 52 | } |
53 | } | ||
54 | tmp[ret] = '\0'; | 53 | tmp[ret] = '\0'; |
55 | if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) | 54 | if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) |
56 | { | 55 | { |
57 | fprintf (stderr, | 56 | fprintf (stderr, |
58 | "Error in testReadWrite: *%s* != *%s* for file %s\n", | 57 | "Error in testReadWrite: *%s* != *%s* for file %s\n", |
59 | tmp, TESTSTRING, ".testfile"); | 58 | tmp, TESTSTRING, ".testfile"); |
60 | return 1; | 59 | return 1; |
61 | } | 60 | } |
62 | GNUNET_DISK_file_copy (".testfile", ".testfile2"); | 61 | GNUNET_DISK_file_copy (".testfile", ".testfile2"); |
63 | memset (tmp, 0, sizeof (tmp)); | 62 | memset (tmp, 0, sizeof (tmp)); |
64 | ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); | 63 | ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1); |
65 | if (ret < 0) | 64 | if (ret < 0) |
66 | { | 65 | { |
67 | fprintf (stderr, | 66 | fprintf (stderr, |
68 | "Error reading file `%s' in testReadWrite\n", ".testfile2"); | 67 | "Error reading file `%s' in testReadWrite\n", ".testfile2"); |
69 | return 1; | 68 | return 1; |
70 | } | 69 | } |
71 | tmp[ret] = '\0'; | 70 | tmp[ret] = '\0'; |
72 | if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) | 71 | if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1)) |
73 | { | 72 | { |
74 | fprintf (stderr, | 73 | fprintf (stderr, |
75 | "Error in testReadWrite: *%s* != *%s* for file %s\n", | 74 | "Error in testReadWrite: *%s* != *%s* for file %s\n", |
76 | tmp, TESTSTRING, ".testfile2"); | 75 | tmp, TESTSTRING, ".testfile2"); |
77 | return 1; | 76 | return 1; |
78 | } | 77 | } |
79 | 78 | ||
80 | GNUNET_break (0 == UNLINK (".testfile")); | 79 | GNUNET_break (0 == UNLINK (".testfile")); |
81 | GNUNET_break (0 == UNLINK (".testfile2")); | 80 | GNUNET_break (0 == UNLINK (".testfile2")); |
@@ -117,11 +116,11 @@ testOpenClose () | |||
117 | while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && | 116 | while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && |
118 | (avail != -1)) | 117 | (avail != -1)) |
119 | if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16)) | 118 | if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16)) |
120 | { | 119 | { |
121 | GNUNET_DISK_file_close (fh); | 120 | GNUNET_DISK_file_close (fh); |
122 | GNUNET_break (0 == UNLINK (".testfile")); | 121 | GNUNET_break (0 == UNLINK (".testfile")); |
123 | return 1; | 122 | return 1; |
124 | } | 123 | } |
125 | GNUNET_DISK_file_close (fh); | 124 | GNUNET_DISK_file_close (fh); |
126 | GNUNET_break (0 == UNLINK (".testfile")); | 125 | GNUNET_break (0 == UNLINK (".testfile")); |
127 | 126 | ||
@@ -162,6 +161,7 @@ iter_callback (void *cls, | |||
162 | const char *filename, const char *dirname) | 161 | const char *filename, const char *dirname) |
163 | { | 162 | { |
164 | int *i = cls; | 163 | int *i = cls; |
164 | |||
165 | (*i)++; | 165 | (*i)++; |
166 | GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); | 166 | GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); |
167 | } | 167 | } |
@@ -210,7 +210,8 @@ testGetHome () | |||
210 | GNUNET_CONFIGURATION_destroy (cfg); | 210 | GNUNET_CONFIGURATION_destroy (cfg); |
211 | ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn); | 211 | ret = strcmp ("/tmp/test-gnunet-disk-a/b/c/d/e", fn); |
212 | GNUNET_free (fn); | 212 | GNUNET_free (fn); |
213 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a")); | 213 | GNUNET_break (GNUNET_OK == |
214 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-disk-a")); | ||
214 | return ret; | 215 | return ret; |
215 | } | 216 | } |
216 | 217 | ||
@@ -218,12 +219,13 @@ static int | |||
218 | testCanonicalize () | 219 | testCanonicalize () |
219 | { | 220 | { |
220 | char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\""); | 221 | char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\""); |
222 | |||
221 | GNUNET_DISK_filename_canonicalize (fn); | 223 | GNUNET_DISK_filename_canonicalize (fn); |
222 | if (0 != strcmp (fn, "ab____cd_ef__g_")) | 224 | if (0 != strcmp (fn, "ab____cd_ef__g_")) |
223 | { | 225 | { |
224 | GNUNET_free (fn); | 226 | GNUNET_free (fn); |
225 | return 1; | 227 | return 1; |
226 | } | 228 | } |
227 | GNUNET_free (fn); | 229 | GNUNET_free (fn); |
228 | return 0; | 230 | return 0; |
229 | } | 231 | } |
@@ -275,9 +277,9 @@ main (int argc, char *argv[]) | |||
275 | failureCount += testChangeOwner (); | 277 | failureCount += testChangeOwner (); |
276 | failureCount += testDirMani (); | 278 | failureCount += testDirMani (); |
277 | if (failureCount != 0) | 279 | if (failureCount != 0) |
278 | { | 280 | { |
279 | fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount); | 281 | fprintf (stderr, "\n%u TESTS FAILED!\n", failureCount); |
280 | return -1; | 282 | return -1; |
281 | } | 283 | } |
282 | return 0; | 284 | return 0; |
283 | } /* end of main */ | 285 | } /* end of main */ |
diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c index 88a425545..a517887bf 100644 --- a/src/util/test_getopt.c +++ b/src/util/test_getopt.c | |||
@@ -56,21 +56,22 @@ testVerbose () | |||
56 | NULL | 56 | NULL |
57 | }; | 57 | }; |
58 | unsigned int vflags = 0; | 58 | unsigned int vflags = 0; |
59 | |||
59 | const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = { | 60 | const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = { |
60 | GNUNET_GETOPT_OPTION_VERBOSE (&vflags), | 61 | GNUNET_GETOPT_OPTION_VERBOSE (&vflags), |
61 | GNUNET_GETOPT_OPTION_END | 62 | GNUNET_GETOPT_OPTION_END |
62 | }; | 63 | }; |
63 | 64 | ||
64 | if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv)) | 65 | if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv)) |
65 | { | 66 | { |
66 | GNUNET_break (0); | 67 | GNUNET_break (0); |
67 | return 1; | 68 | return 1; |
68 | } | 69 | } |
69 | if (vflags != 2) | 70 | if (vflags != 2) |
70 | { | 71 | { |
71 | GNUNET_break (0); | 72 | GNUNET_break (0); |
72 | return 1; | 73 | return 1; |
73 | } | 74 | } |
74 | return 0; | 75 | return 0; |
75 | } | 76 | } |
76 | 77 | ||
@@ -88,10 +89,10 @@ testVersion () | |||
88 | }; | 89 | }; |
89 | 90 | ||
90 | if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv)) | 91 | if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv)) |
91 | { | 92 | { |
92 | GNUNET_break (0); | 93 | GNUNET_break (0); |
93 | return 1; | 94 | return 1; |
94 | } | 95 | } |
95 | return 0; | 96 | return 0; |
96 | } | 97 | } |
97 | 98 | ||
@@ -109,10 +110,10 @@ testAbout () | |||
109 | }; | 110 | }; |
110 | 111 | ||
111 | if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv)) | 112 | if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv)) |
112 | { | 113 | { |
113 | GNUNET_break (0); | 114 | GNUNET_break (0); |
114 | return 1; | 115 | return 1; |
115 | } | 116 | } |
116 | return 0; | 117 | return 0; |
117 | } | 118 | } |
118 | 119 | ||
@@ -127,6 +128,7 @@ testLogOpts () | |||
127 | }; | 128 | }; |
128 | char *level = GNUNET_strdup ("stuff"); | 129 | char *level = GNUNET_strdup ("stuff"); |
129 | char *fn = NULL; | 130 | char *fn = NULL; |
131 | |||
130 | const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = { | 132 | const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = { |
131 | GNUNET_GETOPT_OPTION_LOGFILE (&fn), | 133 | GNUNET_GETOPT_OPTION_LOGFILE (&fn), |
132 | GNUNET_GETOPT_OPTION_LOGLEVEL (&level), | 134 | GNUNET_GETOPT_OPTION_LOGLEVEL (&level), |
@@ -134,18 +136,18 @@ testLogOpts () | |||
134 | }; | 136 | }; |
135 | 137 | ||
136 | if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv)) | 138 | if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv)) |
137 | { | 139 | { |
138 | GNUNET_break (0); | 140 | GNUNET_break (0); |
139 | return 1; | 141 | return 1; |
140 | } | 142 | } |
141 | GNUNET_assert (fn != NULL); | 143 | GNUNET_assert (fn != NULL); |
142 | if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename"))) | 144 | if ((0 != strcmp (level, "WARNING")) || (0 != strcmp (fn, "filename"))) |
143 | { | 145 | { |
144 | GNUNET_break (0); | 146 | GNUNET_break (0); |
145 | GNUNET_free (level); | 147 | GNUNET_free (level); |
146 | GNUNET_free (fn); | 148 | GNUNET_free (fn); |
147 | return 1; | 149 | return 1; |
148 | } | 150 | } |
149 | GNUNET_free (level); | 151 | GNUNET_free (level); |
150 | GNUNET_free (fn); | 152 | GNUNET_free (fn); |
151 | return 0; | 153 | return 0; |
@@ -164,6 +166,7 @@ testFlagNum () | |||
164 | int flag = 0; | 166 | int flag = 0; |
165 | unsigned int num = 0; | 167 | unsigned int num = 0; |
166 | unsigned long long lnum = 0; | 168 | unsigned long long lnum = 0; |
169 | |||
167 | const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = { | 170 | const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = { |
168 | {'f', "--flag", NULL, "helptext", 0, &GNUNET_GETOPT_set_one, | 171 | {'f', "--flag", NULL, "helptext", 0, &GNUNET_GETOPT_set_one, |
169 | (void *) &flag}, | 172 | (void *) &flag}, |
@@ -175,15 +178,15 @@ testFlagNum () | |||
175 | }; | 178 | }; |
176 | 179 | ||
177 | if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv)) | 180 | if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv)) |
178 | { | 181 | { |
179 | GNUNET_break (0); | 182 | GNUNET_break (0); |
180 | return 1; | 183 | return 1; |
181 | } | 184 | } |
182 | if ((1 != flag) || (42 != num) || (42 != lnum)) | 185 | if ((1 != flag) || (42 != num) || (42 != lnum)) |
183 | { | 186 | { |
184 | GNUNET_break (0); | 187 | GNUNET_break (0); |
185 | return 1; | 188 | return 1; |
186 | } | 189 | } |
187 | return 0; | 190 | return 0; |
188 | } | 191 | } |
189 | 192 | ||
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index f82860e83..4137118fa 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -39,8 +39,10 @@ static char *test_phrase = "HELLO WORLD"; | |||
39 | static int ok; | 39 | static int ok; |
40 | 40 | ||
41 | static struct GNUNET_OS_Process *proc; | 41 | static struct GNUNET_OS_Process *proc; |
42 | |||
42 | /* Pipe to write to started processes stdin (on write end) */ | 43 | /* Pipe to write to started processes stdin (on write end) */ |
43 | static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin; | 44 | static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin; |
45 | |||
44 | /* Pipe to read from started processes stdout (on read end) */ | 46 | /* Pipe to read from started processes stdout (on read end) */ |
45 | static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; | 47 | static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; |
46 | 48 | ||
@@ -51,14 +53,14 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
51 | { | 53 | { |
52 | 54 | ||
53 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 55 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
54 | { | 56 | { |
55 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 57 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
56 | } | 58 | } |
57 | GNUNET_OS_process_wait (proc); | 59 | GNUNET_OS_process_wait (proc); |
58 | GNUNET_OS_process_close (proc); | 60 | GNUNET_OS_process_close (proc); |
59 | proc = NULL; | 61 | proc = NULL; |
60 | GNUNET_DISK_pipe_close(hello_pipe_stdout); | 62 | GNUNET_DISK_pipe_close (hello_pipe_stdout); |
61 | GNUNET_DISK_pipe_close(hello_pipe_stdin); | 63 | GNUNET_DISK_pipe_close (hello_pipe_stdin); |
62 | } | 64 | } |
63 | 65 | ||
64 | static void | 66 | static void |
@@ -66,36 +68,39 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
66 | { | 68 | { |
67 | struct GNUNET_DISK_FileHandle *stdout_read_handle = cls; | 69 | struct GNUNET_DISK_FileHandle *stdout_read_handle = cls; |
68 | char buf[16]; | 70 | char buf[16]; |
69 | memset(&buf, 0, sizeof(buf)); | 71 | |
72 | memset (&buf, 0, sizeof (buf)); | ||
70 | int bytes; | 73 | int bytes; |
71 | bytes = GNUNET_DISK_file_read(stdout_read_handle, &buf, sizeof(buf)); | 74 | |
75 | bytes = GNUNET_DISK_file_read (stdout_read_handle, &buf, sizeof (buf)); | ||
72 | 76 | ||
73 | #if VERBOSE | 77 | #if VERBOSE |
74 | fprintf(stderr, "bytes is %d\n", bytes); | 78 | fprintf (stderr, "bytes is %d\n", bytes); |
75 | #endif | 79 | #endif |
76 | 80 | ||
77 | if (bytes < 1) | 81 | if (bytes < 1) |
78 | { | 82 | { |
79 | GNUNET_break (0); | 83 | GNUNET_break (0); |
80 | ok = 1; | 84 | ok = 1; |
81 | GNUNET_SCHEDULER_cancel(die_task); | 85 | GNUNET_SCHEDULER_cancel (die_task); |
82 | GNUNET_SCHEDULER_add_now(&end_task, NULL); | 86 | GNUNET_SCHEDULER_add_now (&end_task, NULL); |
83 | return; | 87 | return; |
84 | } | 88 | } |
85 | 89 | ||
86 | ok = strncmp(&buf[0], test_phrase, strlen(test_phrase)); | 90 | ok = strncmp (&buf[0], test_phrase, strlen (test_phrase)); |
87 | #if VERBOSE | 91 | #if VERBOSE |
88 | fprintf(stderr, "read %s\n", &buf[0]); | 92 | fprintf (stderr, "read %s\n", &buf[0]); |
89 | #endif | 93 | #endif |
90 | if (ok == 0) | 94 | if (ok == 0) |
91 | { | 95 | { |
92 | GNUNET_SCHEDULER_cancel(die_task); | 96 | GNUNET_SCHEDULER_cancel (die_task); |
93 | GNUNET_SCHEDULER_add_now(&end_task, NULL); | 97 | GNUNET_SCHEDULER_add_now (&end_task, NULL); |
94 | return; | 98 | return; |
95 | } | 99 | } |
96 | 100 | ||
97 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 101 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
98 | stdout_read_handle, &read_call, stdout_read_handle); | 102 | stdout_read_handle, &read_call, |
103 | stdout_read_handle); | ||
99 | 104 | ||
100 | } | 105 | } |
101 | 106 | ||
@@ -107,47 +112,53 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
107 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 112 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
108 | const struct GNUNET_DISK_FileHandle *wh; | 113 | const struct GNUNET_DISK_FileHandle *wh; |
109 | 114 | ||
110 | GNUNET_asprintf(&fn, "cat"); | 115 | GNUNET_asprintf (&fn, "cat"); |
111 | 116 | ||
112 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); | 117 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); |
113 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); | 118 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); |
114 | 119 | ||
115 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 120 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
116 | { | 121 | { |
117 | GNUNET_break (0); | 122 | GNUNET_break (0); |
118 | ok = 1; | 123 | ok = 1; |
119 | GNUNET_free (fn); | 124 | GNUNET_free (fn); |
120 | return; | 125 | return; |
121 | } | 126 | } |
122 | 127 | ||
123 | proc = GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, | 128 | proc = GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, |
124 | "test_gnunet_echo_hello", "-", NULL); | 129 | "test_gnunet_echo_hello", "-", NULL); |
125 | GNUNET_free (fn); | 130 | GNUNET_free (fn); |
126 | 131 | ||
127 | /* Close the write end of the read pipe */ | 132 | /* Close the write end of the read pipe */ |
128 | GNUNET_DISK_pipe_close_end(hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | 133 | GNUNET_DISK_pipe_close_end (hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); |
129 | /* Close the read end of the write pipe */ | 134 | /* Close the read end of the write pipe */ |
130 | GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ); | 135 | GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ); |
131 | 136 | ||
132 | wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); | 137 | wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); |
133 | 138 | ||
134 | /* Write the test_phrase to the cat process */ | 139 | /* Write the test_phrase to the cat process */ |
135 | if (GNUNET_DISK_file_write(wh, test_phrase, strlen(test_phrase) + 1) != strlen(test_phrase) + 1) | 140 | if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) != |
136 | { | 141 | strlen (test_phrase) + 1) |
137 | GNUNET_break (0); | 142 | { |
138 | ok = 1; | 143 | GNUNET_break (0); |
139 | return; | 144 | ok = 1; |
140 | } | 145 | return; |
146 | } | ||
141 | 147 | ||
142 | /* Close the write end to end the cycle! */ | 148 | /* Close the write end to end the cycle! */ |
143 | GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); | 149 | GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); |
144 | 150 | ||
145 | stdout_read_handle = GNUNET_DISK_pipe_handle(hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); | 151 | stdout_read_handle = |
152 | GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); | ||
146 | 153 | ||
147 | die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1), &end_task, NULL); | 154 | die_task = |
155 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
156 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, | ||
157 | NULL); | ||
148 | 158 | ||
149 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 159 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
150 | stdout_read_handle, &read_call, (void *)stdout_read_handle); | 160 | stdout_read_handle, &read_call, |
161 | (void *) stdout_read_handle); | ||
151 | 162 | ||
152 | } | 163 | } |
153 | 164 | ||
diff --git a/src/util/test_peer.c b/src/util/test_peer.c index 8dacbd765..395d40712 100644 --- a/src/util/test_peer.c +++ b/src/util/test_peer.c | |||
@@ -43,13 +43,13 @@ generatePeerIdList () | |||
43 | int i; | 43 | int i; |
44 | 44 | ||
45 | for (i = 0; i < NUMBER_OF_PEERS; i++) | 45 | for (i = 0; i < NUMBER_OF_PEERS; i++) |
46 | { | 46 | { |
47 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, | 47 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, |
48 | &pidArr[i].hashPubKey); | 48 | &pidArr[i].hashPubKey); |
49 | #if DEBUG | 49 | #if DEBUG |
50 | printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); | 50 | printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); |
51 | #endif | 51 | #endif |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
@@ -65,27 +65,25 @@ check () | |||
65 | GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); | 65 | GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); |
66 | /* Insert Peers into PeerEntry table and hashmap */ | 66 | /* Insert Peers into PeerEntry table and hashmap */ |
67 | for (i = 0; i < NUMBER_OF_PEERS; i++) | 67 | for (i = 0; i < NUMBER_OF_PEERS; i++) |
68 | { | ||
69 | pid = GNUNET_PEER_intern (&pidArr[i]); | ||
70 | if (pid != (i + 1)) | ||
68 | { | 71 | { |
69 | pid = GNUNET_PEER_intern (&pidArr[i]); | 72 | fprintf (stderr, "Unexpected Peer ID returned by intern function\n"); |
70 | if (pid != (i + 1)) | 73 | return 1; |
71 | { | ||
72 | fprintf (stderr, | ||
73 | "Unexpected Peer ID returned by intern function\n"); | ||
74 | return 1; | ||
75 | } | ||
76 | } | 74 | } |
75 | } | ||
77 | 76 | ||
78 | /* Referencing the first 3 peers once again */ | 77 | /* Referencing the first 3 peers once again */ |
79 | for (i = 0; i < 3; i++) | 78 | for (i = 0; i < 3; i++) |
79 | { | ||
80 | pid = GNUNET_PEER_intern (&pidArr[i]); | ||
81 | if (pid != (i + 1)) | ||
80 | { | 82 | { |
81 | pid = GNUNET_PEER_intern (&pidArr[i]); | 83 | fprintf (stderr, "Unexpected Peer ID returned by intern function\n"); |
82 | if (pid != (i + 1)) | 84 | return 1; |
83 | { | ||
84 | fprintf (stderr, | ||
85 | "Unexpected Peer ID returned by intern function\n"); | ||
86 | return 1; | ||
87 | } | ||
88 | } | 85 | } |
86 | } | ||
89 | 87 | ||
90 | /* Dereferencing the first 3 peers once [decrementing their reference count] */ | 88 | /* Dereferencing the first 3 peers once [decrementing their reference count] */ |
91 | GNUNET_PEER_decrement_rcs (ids, 3); | 89 | GNUNET_PEER_decrement_rcs (ids, 3); |
@@ -127,13 +125,14 @@ int | |||
127 | main () | 125 | main () |
128 | { | 126 | { |
129 | int i; | 127 | int i; |
128 | |||
130 | GNUNET_log_setup ("test-peer", "ERROR", NULL); | 129 | GNUNET_log_setup ("test-peer", "ERROR", NULL); |
131 | for (i = 0; i < 1; i++) | 130 | for (i = 0; i < 1; i++) |
132 | { | 131 | { |
133 | generatePeerIdList (); | 132 | generatePeerIdList (); |
134 | if (0 != check ()) | 133 | if (0 != check ()) |
135 | return 1; | 134 | return 1; |
136 | } | 135 | } |
137 | return 0; | 136 | return 0; |
138 | } | 137 | } |
139 | 138 | ||
diff --git a/src/util/test_program.c b/src/util/test_program.c index 33a6b50ea..9ea5b1510 100644 --- a/src/util/test_program.c +++ b/src/util/test_program.c | |||
@@ -62,6 +62,7 @@ runner (void *cls, | |||
62 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 62 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
63 | { | 63 | { |
64 | int *ok = cls; | 64 | int *ok = cls; |
65 | |||
65 | GNUNET_assert (setme1 == 1); | 66 | GNUNET_assert (setme1 == 1); |
66 | GNUNET_assert (0 == strcmp (args[0], "extra")); | 67 | GNUNET_assert (0 == strcmp (args[0], "extra")); |
67 | GNUNET_assert (args[1] == NULL); | 68 | GNUNET_assert (args[1] == NULL); |
@@ -78,6 +79,7 @@ static int | |||
78 | check () | 79 | check () |
79 | { | 80 | { |
80 | int ok = 1; | 81 | int ok = 1; |
82 | |||
81 | char *const argv[] = { | 83 | char *const argv[] = { |
82 | "test_program", | 84 | "test_program", |
83 | "-c", | 85 | "-c", |
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index 0f68f9f05..dfdcbb1bb 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c | |||
@@ -48,10 +48,10 @@ iter (void *cls, | |||
48 | &id1, | 48 | &id1, |
49 | sizeof (GNUNET_HashCode))) && | 49 | sizeof (GNUNET_HashCode))) && |
50 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) | 50 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) |
51 | { | 51 | { |
52 | *ok = GNUNET_NO; | 52 | *ok = GNUNET_NO; |
53 | GNUNET_break (0); | 53 | GNUNET_break (0); |
54 | } | 54 | } |
55 | return GNUNET_OK; | 55 | return GNUNET_OK; |
56 | } | 56 | } |
57 | 57 | ||
@@ -62,25 +62,27 @@ noti_callback (void *cls, | |||
62 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 62 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
63 | { | 63 | { |
64 | int *ret = cls; | 64 | int *ret = cls; |
65 | |||
65 | (*ret)++; | 66 | (*ret)++; |
66 | return GNUNET_OK; | 67 | return GNUNET_OK; |
67 | } | 68 | } |
68 | 69 | ||
69 | static int | 70 | static int |
70 | fake_noti_callback (void *cls, | 71 | fake_noti_callback (void *cls, |
71 | const GNUNET_HashCode * | 72 | const GNUNET_HashCode * |
72 | pseudonym, | 73 | pseudonym, |
73 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 74 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
74 | { | 75 | { |
75 | int *ret = cls; | 76 | int *ret = cls; |
76 | (*ret)++; | 77 | |
77 | return GNUNET_OK; | 78 | (*ret)++; |
79 | return GNUNET_OK; | ||
78 | } | 80 | } |
79 | 81 | ||
80 | static int | 82 | static int |
81 | false_callback (void *cls, | 83 | false_callback (void *cls, |
82 | const GNUNET_HashCode *pseudonym, | 84 | const GNUNET_HashCode * pseudonym, |
83 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 85 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
84 | { | 86 | { |
85 | return GNUNET_OK; | 87 | return GNUNET_OK; |
86 | } | 88 | } |
@@ -102,11 +104,12 @@ main (int argc, char *argv[]) | |||
102 | char *name2; | 104 | char *name2; |
103 | char *name3; | 105 | char *name3; |
104 | char *noname; | 106 | char *noname; |
105 | int notiCount,fakenotiCount; | 107 | int notiCount, fakenotiCount; |
106 | int count; | 108 | int count; |
107 | static char m[1024 * 1024 * 10]; | 109 | static char m[1024 * 1024 * 10]; |
108 | memset (m, 'b', sizeof (m)); | 110 | |
109 | m[sizeof (m) - 1] = '\0'; | 111 | memset (m, 'b', sizeof (m)); |
112 | m[sizeof (m) - 1] = '\0'; | ||
110 | 113 | ||
111 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); | 114 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); |
112 | ok = GNUNET_YES; | 115 | ok = GNUNET_YES; |
@@ -114,31 +117,31 @@ main (int argc, char *argv[]) | |||
114 | (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); | 117 | (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); |
115 | cfg = GNUNET_CONFIGURATION_create (); | 118 | cfg = GNUNET_CONFIGURATION_create (); |
116 | if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) | 119 | if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) |
117 | { | 120 | { |
118 | GNUNET_CONFIGURATION_destroy (cfg); | 121 | GNUNET_CONFIGURATION_destroy (cfg); |
119 | GNUNET_break (0); | 122 | GNUNET_break (0); |
120 | return -1; | 123 | return -1; |
121 | } | 124 | } |
122 | notiCount = 0; | 125 | notiCount = 0; |
123 | fakenotiCount = 0; | 126 | fakenotiCount = 0; |
124 | count = 0; | 127 | count = 0; |
125 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, | 128 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, |
126 | &fake_noti_callback, &fakenotiCount); | 129 | &fake_noti_callback, |
127 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, | 130 | &fakenotiCount); |
128 | ¬i_callback, ¬iCount); | 131 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, |
132 | ¬iCount); | ||
129 | GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); | 133 | GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); |
130 | GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, &fakenotiCount); | 134 | GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, |
135 | &fakenotiCount); | ||
131 | 136 | ||
132 | /* ACTUAL TEST CODE */ | 137 | /* ACTUAL TEST CODE */ |
133 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); | 138 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); |
134 | meta = GNUNET_CONTAINER_meta_data_create (); | 139 | meta = GNUNET_CONTAINER_meta_data_create (); |
135 | GNUNET_CONTAINER_meta_data_insert (meta, | 140 | GNUNET_CONTAINER_meta_data_insert (meta, |
136 | "<test>", | 141 | "<test>", |
137 | EXTRACTOR_METATYPE_TITLE, | 142 | EXTRACTOR_METATYPE_TITLE, |
138 | EXTRACTOR_METAFORMAT_UTF8, | 143 | EXTRACTOR_METAFORMAT_UTF8, |
139 | "text/plain", | 144 | "text/plain", "test", strlen ("test") + 1); |
140 | "test", | ||
141 | strlen("test")+1); | ||
142 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); | 145 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); |
143 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); | 146 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); |
144 | CHECK (notiCount == 1); | 147 | CHECK (notiCount == 1); |
@@ -152,13 +155,14 @@ main (int argc, char *argv[]) | |||
152 | CHECK (notiCount == 3); | 155 | CHECK (notiCount == 3); |
153 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); | 156 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); |
154 | CHECK (old < newVal); | 157 | CHECK (old < newVal); |
155 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, | 158 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, |
156 | "<test>", | 159 | "<test>", |
157 | EXTRACTOR_METATYPE_COMMENT, | 160 | EXTRACTOR_METATYPE_COMMENT, |
158 | EXTRACTOR_METAFORMAT_UTF8, | 161 | EXTRACTOR_METAFORMAT_UTF8, |
159 | "text/plain", | 162 | "text/plain", |
160 | m, | 163 | m, |
161 | strlen(m)+1)); | 164 | strlen (m) + |
165 | 1)); | ||
162 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); | 166 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); |
163 | GNUNET_PSEUDONYM_add (cfg, &id3, meta); | 167 | GNUNET_PSEUDONYM_add (cfg, &id3, meta); |
164 | name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); | 168 | name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); |
@@ -167,7 +171,7 @@ main (int argc, char *argv[]) | |||
167 | name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1); | 171 | name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1); |
168 | CHECK (name1 != NULL); | 172 | CHECK (name1 != NULL); |
169 | CHECK (0 != strcmp (name1, name2)); | 173 | CHECK (0 != strcmp (name1, name2)); |
170 | CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); | 174 | CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); |
171 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); | 175 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); |
172 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); | 176 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); |
173 | CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode))); | 177 | CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode))); |
@@ -192,7 +196,8 @@ FAILURE: | |||
192 | GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); | 196 | GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); |
193 | GNUNET_CONTAINER_meta_data_destroy (meta); | 197 | GNUNET_CONTAINER_meta_data_destroy (meta); |
194 | GNUNET_CONFIGURATION_destroy (cfg); | 198 | GNUNET_CONFIGURATION_destroy (cfg); |
195 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); | 199 | GNUNET_break (GNUNET_OK == |
200 | GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); | ||
196 | return (ok == GNUNET_YES) ? 0 : 1; | 201 | return (ok == GNUNET_YES) ? 0 : 1; |
197 | } | 202 | } |
198 | 203 | ||
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 39cfa43fc..8058fa287 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -41,112 +41,114 @@ | |||
41 | #define ROOTSERVER_IP "198.41.0.4" | 41 | #define ROOTSERVER_IP "198.41.0.4" |
42 | 42 | ||
43 | static void | 43 | static void |
44 | check_hostname(void *cls, const struct sockaddr *sa, socklen_t salen) | 44 | check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen) |
45 | { | 45 | { |
46 | int *ok = cls; | 46 | int *ok = cls; |
47 | 47 | ||
48 | if (salen == 0) | 48 | if (salen == 0) |
49 | { | 49 | { |
50 | (*ok) &= ~8; | 50 | (*ok) &= ~8; |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"), | 53 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Got IP address `%s' for our host.\n"), |
54 | GNUNET_a2s(sa, salen)); | 54 | GNUNET_a2s (sa, salen)); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | static void | 58 | static void |
59 | check_localhost_num(void *cls, const char *hostname) | 59 | check_localhost_num (void *cls, const char *hostname) |
60 | { | 60 | { |
61 | int *ok = cls; | 61 | int *ok = cls; |
62 | |||
62 | if (hostname == NULL) | 63 | if (hostname == NULL) |
63 | return; | 64 | return; |
64 | if (0 == strcmp(hostname, "127.0.0.1")) | 65 | if (0 == strcmp (hostname, "127.0.0.1")) |
65 | { | 66 | { |
66 | #if DEBUG_RESOLVER | 67 | #if DEBUG_RESOLVER |
67 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 68 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
68 | "Received correct hostname `%s'.\n", hostname); | 69 | "Received correct hostname `%s'.\n", hostname); |
69 | #endif | 70 | #endif |
70 | (*ok) &= ~4; | 71 | (*ok) &= ~4; |
71 | } | 72 | } |
72 | else | 73 | else |
73 | { | 74 | { |
74 | #if DEBUG_RESOLVER | 75 | #if DEBUG_RESOLVER |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
76 | "Received invalid hostname `%s'.\n", hostname); | 77 | "Received invalid hostname `%s'.\n", hostname); |
77 | #endif | 78 | #endif |
78 | GNUNET_break(0); | 79 | GNUNET_break (0); |
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
82 | 83 | ||
83 | static void | 84 | static void |
84 | check_localhost(void *cls, const char *hostname) | 85 | check_localhost (void *cls, const char *hostname) |
85 | { | 86 | { |
86 | int *ok = cls; | 87 | int *ok = cls; |
88 | |||
87 | if (hostname == NULL) | 89 | if (hostname == NULL) |
88 | return; | 90 | return; |
89 | if (0 == strcmp(hostname, "localhost")) | 91 | if (0 == strcmp (hostname, "localhost")) |
90 | { | 92 | { |
91 | #if DEBUG_RESOLVER | 93 | #if DEBUG_RESOLVER |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
93 | "Received correct hostname `%s'.\n", hostname); | 95 | "Received correct hostname `%s'.\n", hostname); |
94 | #endif | 96 | #endif |
95 | (*ok) &= ~2; | 97 | (*ok) &= ~2; |
96 | } | 98 | } |
97 | else | 99 | else |
98 | { | 100 | { |
99 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
100 | "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", | 102 | "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", |
101 | hostname); | 103 | hostname); |
102 | } | 104 | } |
103 | } | 105 | } |
104 | 106 | ||
105 | static void | 107 | static void |
106 | check_127(void *cls, const struct sockaddr *sa, socklen_t salen) | 108 | check_127 (void *cls, const struct sockaddr *sa, socklen_t salen) |
107 | { | 109 | { |
108 | int *ok = cls; | 110 | int *ok = cls; |
109 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; | 111 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; |
110 | 112 | ||
111 | if (sa == NULL) | 113 | if (sa == NULL) |
112 | return; | 114 | return; |
113 | GNUNET_assert(sizeof(struct sockaddr_in) == salen); | 115 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
114 | if (sai->sin_addr.s_addr == htonl(INADDR_LOOPBACK)) | 116 | if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK)) |
115 | { | 117 | { |
116 | #if DEBUG_RESOLVER | 118 | #if DEBUG_RESOLVER |
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct address.\n"); |
118 | #endif | 120 | #endif |
119 | (*ok) &= ~1; | 121 | (*ok) &= ~1; |
120 | } | 122 | } |
121 | else | 123 | else |
122 | { | 124 | { |
123 | #if DEBUG_RESOLVER | 125 | #if DEBUG_RESOLVER |
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect address.\n"); |
125 | #endif | 127 | #endif |
126 | GNUNET_break(0); | 128 | GNUNET_break (0); |
127 | } | 129 | } |
128 | } | 130 | } |
129 | 131 | ||
130 | static void | 132 | static void |
131 | check_local_fqdn(void *cls, const char *gnunet_fqdn) | 133 | check_local_fqdn (void *cls, const char *gnunet_fqdn) |
132 | { | 134 | { |
133 | int result = 0; | 135 | int result = 0; |
134 | 136 | ||
135 | struct hostent *host; | 137 | struct hostent *host; |
136 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 138 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
137 | 139 | ||
138 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 140 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |
139 | { | 141 | { |
140 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | 142 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | |
141 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | 143 | GNUNET_ERROR_TYPE_BULK, "gethostname"); |
142 | return; | 144 | return; |
143 | } | 145 | } |
144 | #if DEBUG_RESOLVER | 146 | #if DEBUG_RESOLVER |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
146 | _("Resolving our FQDN `%s'\n"), hostname); | 148 | _("Resolving our FQDN `%s'\n"), hostname); |
147 | #endif | 149 | #endif |
148 | host = gethostbyname ( hostname ); | 150 | host = gethostbyname (hostname); |
149 | if ( NULL == host) | 151 | if (NULL == host) |
150 | { | 152 | { |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
152 | _("Could not resolve our FQDN : %s %u\n"), | 154 | _("Could not resolve our FQDN : %s %u\n"), |
@@ -154,144 +156,150 @@ check_local_fqdn(void *cls, const char *gnunet_fqdn) | |||
154 | return; | 156 | return; |
155 | } | 157 | } |
156 | 158 | ||
157 | GNUNET_assert( 0 != host); | 159 | GNUNET_assert (0 != host); |
158 | 160 | ||
159 | result = strcmp(host->h_name, gnunet_fqdn); | 161 | result = strcmp (host->h_name, gnunet_fqdn); |
160 | if ( 0 != result ) | 162 | if (0 != result) |
161 | { | 163 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
163 | "Local resolved and resolver resolved fqdns are not equal\n"); | 165 | "Local resolved and resolver resolved fqdns are not equal\n"); |
164 | } | 166 | } |
165 | GNUNET_assert( 0 == result); | 167 | GNUNET_assert (0 == result); |
166 | } | 168 | } |
167 | 169 | ||
168 | 170 | ||
169 | 171 | ||
170 | static void | 172 | static void |
171 | check_rootserver_ip(void *cls, const struct sockaddr *sa, socklen_t salen) | 173 | check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen) |
172 | { | 174 | { |
173 | int *ok = cls; | 175 | int *ok = cls; |
174 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; | 176 | const struct sockaddr_in *sai = (const struct sockaddr_in *) sa; |
175 | 177 | ||
176 | if (sa == NULL) | 178 | if (sa == NULL) |
177 | return; | 179 | return; |
178 | GNUNET_assert(sizeof(struct sockaddr_in) == salen); | 180 | GNUNET_assert (sizeof (struct sockaddr_in) == salen); |
179 | 181 | ||
180 | if (0 == strcmp(inet_ntoa(sai->sin_addr), ROOTSERVER_IP)) | 182 | if (0 == strcmp (inet_ntoa (sai->sin_addr), ROOTSERVER_IP)) |
181 | { | 183 | { |
182 | #if DEBUG_RESOLVER | 184 | #if DEBUG_RESOLVER |
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct rootserver ip address.\n"); | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
186 | "Received correct rootserver ip address.\n"); | ||
184 | #endif | 187 | #endif |
185 | (*ok) &= ~1; | 188 | (*ok) &= ~1; |
186 | } | 189 | } |
187 | else | 190 | else |
188 | { | 191 | { |
189 | #if DEBUG_RESOLVER | 192 | #if DEBUG_RESOLVER |
190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received incorrect rootserver ip address.\n"); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Received incorrect rootserver ip address.\n"); | ||
191 | #endif | 195 | #endif |
192 | GNUNET_break(0); | 196 | GNUNET_break (0); |
193 | } | 197 | } |
194 | } | 198 | } |
195 | 199 | ||
196 | static void | 200 | static void |
197 | check_rootserver_name(void *cls, const char *hostname) | 201 | check_rootserver_name (void *cls, const char *hostname) |
198 | { | 202 | { |
199 | int *ok = cls; | 203 | int *ok = cls; |
204 | |||
200 | if (hostname == NULL) | 205 | if (hostname == NULL) |
201 | return; | 206 | return; |
202 | 207 | ||
203 | if (0 == strcmp(hostname, ROOTSERVER_NAME)) | 208 | if (0 == strcmp (hostname, ROOTSERVER_NAME)) |
204 | { | 209 | { |
205 | #if DEBUG_RESOLVER | 210 | #if DEBUG_RESOLVER |
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
207 | "Received correct rootserver hostname `%s'.\n", hostname); | 212 | "Received correct rootserver hostname `%s'.\n", hostname); |
208 | #endif | 213 | #endif |
209 | (*ok) &= ~2; | 214 | (*ok) &= ~2; |
210 | } | 215 | } |
211 | else | 216 | else |
212 | { | 217 | { |
213 | #if DEBUG_RESOLVER | 218 | #if DEBUG_RESOLVER |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "Received invalid rootserver hostname `%s'.\n", hostname); | 220 | "Received invalid rootserver hostname `%s'.\n", hostname); |
216 | #endif | 221 | #endif |
217 | GNUNET_break(0); | 222 | GNUNET_break (0); |
218 | } | 223 | } |
219 | } | 224 | } |
220 | 225 | ||
221 | static void | 226 | static void |
222 | run(void *cls, char * const *args, | 227 | run (void *cls, char *const *args, |
223 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 228 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
224 | { | 229 | { |
225 | int *ok = cls; | 230 | int *ok = cls; |
226 | struct sockaddr_in sa; | 231 | struct sockaddr_in sa; |
227 | struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply( | 232 | struct GNUNET_TIME_Relative timeout = |
228 | GNUNET_TIME_UNIT_SECONDS, 30); | 233 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
229 | int count_ips = 0; | 234 | int count_ips = 0; |
230 | char * own_fqdn; | 235 | char *own_fqdn; |
231 | 236 | ||
232 | memset(&sa, 0, sizeof(sa)); | 237 | memset (&sa, 0, sizeof (sa)); |
233 | sa.sin_family = AF_INET; | 238 | sa.sin_family = AF_INET; |
234 | #if HAVE_SOCKADDR_IN_SIN_LEN | 239 | #if HAVE_SOCKADDR_IN_SIN_LEN |
235 | sa.sin_len = (u_char) sizeof (sa); | 240 | sa.sin_len = (u_char) sizeof (sa); |
236 | #endif | 241 | #endif |
237 | sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 242 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
238 | 243 | ||
239 | /* | 244 | /* |
240 | * Looking up our own fqdn | 245 | * Looking up our own fqdn |
241 | */ | 246 | */ |
242 | own_fqdn = GNUNET_RESOLVER_local_fqdn_get(); | 247 | own_fqdn = GNUNET_RESOLVER_local_fqdn_get (); |
243 | check_local_fqdn( NULL, own_fqdn); | 248 | check_local_fqdn (NULL, own_fqdn); |
244 | GNUNET_free_non_null (own_fqdn); | 249 | GNUNET_free_non_null (own_fqdn); |
245 | 250 | ||
246 | /* | 251 | /* |
247 | * Testing non-local DNS resolution | 252 | * Testing non-local DNS resolution |
248 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 | 253 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 |
249 | */ | 254 | */ |
250 | const char * rootserver_name = ROOTSERVER_NAME; | 255 | const char *rootserver_name = ROOTSERVER_NAME; |
251 | struct hostent *rootserver; | 256 | struct hostent *rootserver; |
252 | 257 | ||
253 | rootserver = gethostbyname(rootserver_name); | 258 | rootserver = gethostbyname (rootserver_name); |
254 | if (rootserver == NULL) | 259 | if (rootserver == NULL) |
255 | { | 260 | { |
256 | /* Error: resolving ip addresses does not work */ | 261 | /* Error: resolving ip addresses does not work */ |
257 | #if DEBUG_RESOLVER | 262 | #if DEBUG_RESOLVER |
258 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
259 | _("gethostbyname() could not lookup IP address: %s\n"), | 264 | _("gethostbyname() could not lookup IP address: %s\n"), |
260 | hstrerror (h_errno)); | 265 | hstrerror (h_errno)); |
261 | #endif | 266 | #endif |
262 | fprintf (stderr, | 267 | fprintf (stderr, |
263 | "System seems to be off-line, will not run all DNS tests\n"); | 268 | "System seems to be off-line, will not run all DNS tests\n"); |
264 | *ok = 0; /* mark test as passing anyway */ | 269 | *ok = 0; /* mark test as passing anyway */ |
265 | return; | 270 | return; |
266 | } | 271 | } |
267 | 272 | ||
268 | /* Counting returned IP addresses */ | 273 | /* Counting returned IP addresses */ |
269 | while (rootserver->h_addr_list[count_ips] != NULL) | 274 | while (rootserver->h_addr_list[count_ips] != NULL) |
270 | count_ips++; | 275 | count_ips++; |
271 | if (count_ips > 1) | 276 | if (count_ips > 1) |
272 | { | 277 | { |
273 | #if DEBUG_RESOLVER | 278 | #if DEBUG_RESOLVER |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received range for root name server, but a root name server has only 1 IP\n"); | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
280 | "IP received range for root name server, but a root name server has only 1 IP\n"); | ||
275 | #endif | 281 | #endif |
276 | GNUNET_break(0); | 282 | GNUNET_break (0); |
277 | } | 283 | } |
278 | 284 | ||
279 | /* Comparing to resolved address to the address the root name server should have */ | 285 | /* Comparing to resolved address to the address the root name server should have */ |
280 | if (strcmp(inet_ntoa(*(struct in_addr *) rootserver->h_addr_list[0]), | 286 | if (strcmp (inet_ntoa (*(struct in_addr *) rootserver->h_addr_list[0]), |
281 | ROOTSERVER_IP) != 0) | 287 | ROOTSERVER_IP) != 0) |
282 | { | 288 | { |
283 | #if DEBUG_RESOLVER | 289 | #if DEBUG_RESOLVER |
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received and IP for root name server differ\n"); | 290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "IP received and IP for root name server differ\n"); | ||
285 | #endif | 292 | #endif |
286 | GNUNET_break(0); | 293 | GNUNET_break (0); |
287 | } | 294 | } |
288 | #if DEBUG_RESOLVER | 295 | #if DEBUG_RESOLVER |
289 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own forward name resolution is working\n"); | 296 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
297 | "System's own forward name resolution is working\n"); | ||
290 | #endif | 298 | #endif |
291 | 299 | ||
292 | /* Resolve the same using GNUNET */ | 300 | /* Resolve the same using GNUNET */ |
293 | GNUNET_RESOLVER_ip_get(ROOTSERVER_NAME, AF_INET, timeout, | 301 | GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, |
294 | &check_rootserver_ip, cls); | 302 | &check_rootserver_ip, cls); |
295 | 303 | ||
296 | /* | 304 | /* |
297 | * Success: forward lookups work as expected | 305 | * Success: forward lookups work as expected |
@@ -299,129 +307,137 @@ run(void *cls, char * const *args, | |||
299 | */ | 307 | */ |
300 | 308 | ||
301 | struct in_addr rootserver_addr; | 309 | struct in_addr rootserver_addr; |
310 | |||
302 | rootserver->h_name = ""; | 311 | rootserver->h_name = ""; |
303 | if (1 != inet_pton(AF_INET, ROOTSERVER_IP, &rootserver_addr)) | 312 | if (1 != inet_pton (AF_INET, ROOTSERVER_IP, &rootserver_addr)) |
304 | { | 313 | { |
305 | #if DEBUG_RESOLVER | 314 | #if DEBUG_RESOLVER |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transform root name server IP address\n"); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
316 | "Could not transform root name server IP address\n"); | ||
307 | #endif | 317 | #endif |
308 | GNUNET_break(0); | 318 | GNUNET_break (0); |
309 | } | 319 | } |
310 | 320 | ||
311 | rootserver | 321 | rootserver |
312 | = gethostbyaddr(&rootserver_addr, sizeof(rootserver_addr), AF_INET); | 322 | = gethostbyaddr (&rootserver_addr, sizeof (rootserver_addr), AF_INET); |
313 | if (rootserver == NULL) | 323 | if (rootserver == NULL) |
314 | { | 324 | { |
315 | /* Error: resolving IP addresses does not work */ | 325 | /* Error: resolving IP addresses does not work */ |
316 | #if DEBUG_RESOLVER | 326 | #if DEBUG_RESOLVER |
317 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
318 | _("gethostbyaddr() could not lookup hostname: %s\n"), | 328 | _("gethostbyaddr() could not lookup hostname: %s\n"), |
319 | hstrerror (h_errno)); | 329 | hstrerror (h_errno)); |
320 | #endif | 330 | #endif |
321 | GNUNET_break(0); | 331 | GNUNET_break (0); |
322 | } | 332 | } |
323 | else | 333 | else |
324 | { | 334 | { |
325 | if (0 != strcmp(rootserver->h_name, ROOTSERVER_NAME)) | 335 | if (0 != strcmp (rootserver->h_name, ROOTSERVER_NAME)) |
326 | { | 336 | { |
327 | #if DEBUG_RESOLVER | 337 | #if DEBUG_RESOLVER |
328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received hostname and hostname for root name server differ\n"); | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
339 | "Received hostname and hostname for root name server differ\n"); | ||
329 | #endif | 340 | #endif |
330 | GNUNET_break(0); | 341 | GNUNET_break (0); |
331 | } | 342 | } |
332 | } | 343 | } |
333 | 344 | ||
334 | #if DEBUG_RESOLVER | 345 | #if DEBUG_RESOLVER |
335 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
336 | "System's own reverse name resolution is working\n"); | 347 | "System's own reverse name resolution is working\n"); |
337 | #endif | 348 | #endif |
338 | 349 | ||
339 | /* Resolve the same using GNUNET */ | 350 | /* Resolve the same using GNUNET */ |
340 | memset(&sa, 0, sizeof(sa)); | 351 | memset (&sa, 0, sizeof (sa)); |
341 | sa.sin_family = AF_INET; | 352 | sa.sin_family = AF_INET; |
342 | #if HAVE_SOCKADDR_IN_SIN_LEN | 353 | #if HAVE_SOCKADDR_IN_SIN_LEN |
343 | sa.sin_len = (u_char) sizeof (sa); | 354 | sa.sin_len = (u_char) sizeof (sa); |
344 | #endif | 355 | #endif |
345 | #ifndef MINGW | 356 | #ifndef MINGW |
346 | inet_aton(ROOTSERVER_IP, &sa.sin_addr); | 357 | inet_aton (ROOTSERVER_IP, &sa.sin_addr); |
347 | #else | 358 | #else |
348 | sa.sin_addr.S_un.S_addr = inet_addr(ROOTSERVER_IP); | 359 | sa.sin_addr.S_un.S_addr = inet_addr (ROOTSERVER_IP); |
349 | #endif | 360 | #endif |
350 | GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, | 361 | GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, |
351 | sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls); | 362 | sizeof (struct sockaddr), GNUNET_YES, timeout, |
363 | &check_rootserver_name, cls); | ||
352 | 364 | ||
353 | memset(&sa, 0, sizeof(sa)); | 365 | memset (&sa, 0, sizeof (sa)); |
354 | sa.sin_family = AF_INET; | 366 | sa.sin_family = AF_INET; |
355 | #if HAVE_SOCKADDR_IN_SIN_LEN | 367 | #if HAVE_SOCKADDR_IN_SIN_LEN |
356 | sa.sin_len = (u_char) sizeof (sa); | 368 | sa.sin_len = (u_char) sizeof (sa); |
357 | #endif | 369 | #endif |
358 | sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 370 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
359 | 371 | ||
360 | GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127, | 372 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, timeout, &check_127, cls); |
361 | cls); | 373 | GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, |
362 | GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, | 374 | sizeof (struct sockaddr), GNUNET_YES, timeout, |
363 | sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls); | 375 | &check_localhost, cls); |
364 | 376 | ||
365 | GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, | 377 | GNUNET_RESOLVER_hostname_get ((const struct sockaddr *) &sa, |
366 | sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls); | 378 | sizeof (struct sockaddr), GNUNET_NO, timeout, |
367 | GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout, | 379 | &check_localhost_num, cls); |
368 | &check_hostname, cls); | 380 | GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, timeout, &check_hostname, cls); |
369 | 381 | ||
370 | } | 382 | } |
371 | 383 | ||
372 | static int | 384 | static int |
373 | check() | 385 | check () |
374 | { | 386 | { |
375 | int ok = 1 + 2 + 4 + 8; | 387 | int ok = 1 + 2 + 4 + 8; |
376 | char *fn; | 388 | char *fn; |
377 | char *pfx; | 389 | char *pfx; |
378 | struct GNUNET_OS_Process *proc; | 390 | struct GNUNET_OS_Process *proc; |
379 | char * const argv[] = | 391 | |
380 | { "test-resolver-api", "-c", "test_resolver_api_data.conf", | 392 | char *const argv[] = |
393 | { "test-resolver-api", "-c", "test_resolver_api_data.conf", | ||
381 | #if VERBOSE | 394 | #if VERBOSE |
382 | "-L", "DEBUG", | 395 | "-L", "DEBUG", |
383 | #endif | 396 | #endif |
384 | NULL }; | 397 | NULL |
398 | }; | ||
385 | struct GNUNET_GETOPT_CommandLineOption options[] = | 399 | struct GNUNET_GETOPT_CommandLineOption options[] = |
386 | { GNUNET_GETOPT_OPTION_END }; | 400 | { GNUNET_GETOPT_OPTION_END }; |
387 | pfx = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_BINDIR); | 401 | pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); |
388 | GNUNET_asprintf(&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); | 402 | GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); |
389 | GNUNET_free(pfx); | 403 | GNUNET_free (pfx); |
390 | proc = GNUNET_OS_start_process(NULL, NULL, fn, "gnunet-service-resolver", | 404 | proc = GNUNET_OS_start_process (NULL, NULL, fn, "gnunet-service-resolver", |
391 | #if VERBOSE | 405 | #if VERBOSE |
392 | "-L", "DEBUG", | 406 | "-L", "DEBUG", |
393 | #endif | 407 | #endif |
394 | "-c", "test_resolver_api_data.conf", NULL); | 408 | "-c", "test_resolver_api_data.conf", NULL); |
395 | GNUNET_assert (NULL != proc); | 409 | GNUNET_assert (NULL != proc); |
396 | GNUNET_free(fn); | 410 | GNUNET_free (fn); |
397 | GNUNET_assert(GNUNET_OK == GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) | 411 | GNUNET_assert (GNUNET_OK == |
398 | - 1, argv, "test-resolver-api", "nohelp", options, &run, &ok)); | 412 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
413 | argv, "test-resolver-api", "nohelp", | ||
414 | options, &run, &ok)); | ||
399 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 415 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
400 | { | 416 | { |
401 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 417 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
402 | ok = 1; | 418 | ok = 1; |
403 | } | 419 | } |
404 | GNUNET_OS_process_wait (proc); | 420 | GNUNET_OS_process_wait (proc); |
405 | GNUNET_OS_process_close (proc); | 421 | GNUNET_OS_process_close (proc); |
406 | proc = NULL; | 422 | proc = NULL; |
407 | if (ok != 0) | 423 | if (ok != 0) |
408 | fprintf(stderr, "Missed some resolutions: %u\n", ok); | 424 | fprintf (stderr, "Missed some resolutions: %u\n", ok); |
409 | return ok; | 425 | return ok; |
410 | } | 426 | } |
411 | 427 | ||
412 | int | 428 | int |
413 | main(int argc, char *argv[]) | 429 | main (int argc, char *argv[]) |
414 | { | 430 | { |
415 | int ret; | 431 | int ret; |
416 | 432 | ||
417 | GNUNET_log_setup("test-resolver-api", | 433 | GNUNET_log_setup ("test-resolver-api", |
418 | #if VERBOSE | 434 | #if VERBOSE |
419 | "DEBUG", | 435 | "DEBUG", |
420 | #else | 436 | #else |
421 | "WARNING", | 437 | "WARNING", |
422 | #endif | 438 | #endif |
423 | NULL); | 439 | NULL); |
424 | ret = check(); | 440 | ret = check (); |
425 | 441 | ||
426 | return ret; | 442 | return ret; |
427 | } | 443 | } |
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index f0c908d7d..d5a701692 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c | |||
@@ -33,8 +33,10 @@ static void | |||
33 | task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 33 | task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
34 | { | 34 | { |
35 | int *ok = cls; | 35 | int *ok = cls; |
36 | |||
36 | /* t4 should be ready (albeit with lower priority) */ | 37 | /* t4 should be ready (albeit with lower priority) */ |
37 | GNUNET_assert (1 == GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); | 38 | GNUNET_assert (1 == |
39 | GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); | ||
38 | GNUNET_assert (3 == *ok); | 40 | GNUNET_assert (3 == *ok); |
39 | (*ok) = 4; | 41 | (*ok) = 4; |
40 | } | 42 | } |
@@ -44,6 +46,7 @@ static void | |||
44 | task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 46 | task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
45 | { | 47 | { |
46 | int *ok = cls; | 48 | int *ok = cls; |
49 | |||
47 | GNUNET_assert (2 == *ok); | 50 | GNUNET_assert (2 == *ok); |
48 | (*ok) = 3; | 51 | (*ok) = 3; |
49 | /* t3 will go before t4: higher priority */ | 52 | /* t3 will go before t4: higher priority */ |
@@ -55,6 +58,7 @@ static void | |||
55 | task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 58 | task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
56 | { | 59 | { |
57 | int *ok = cls; | 60 | int *ok = cls; |
61 | |||
58 | GNUNET_assert (4 == *ok); | 62 | GNUNET_assert (4 == *ok); |
59 | (*ok) = 5; | 63 | (*ok) = 5; |
60 | } | 64 | } |
@@ -68,6 +72,7 @@ taskWrt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
68 | { | 72 | { |
69 | static char c; | 73 | static char c; |
70 | int *ok = cls; | 74 | int *ok = cls; |
75 | |||
71 | GNUNET_assert (6 == *ok); | 76 | GNUNET_assert (6 == *ok); |
72 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1])); | 77 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1])); |
73 | (*ok) = 7; | 78 | (*ok) = 7; |
@@ -85,6 +90,7 @@ static void | |||
85 | taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 90 | taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
86 | { | 91 | { |
87 | int *ok = cls; | 92 | int *ok = cls; |
93 | |||
88 | /* t4 should be ready (albeit with lower priority) */ | 94 | /* t4 should be ready (albeit with lower priority) */ |
89 | GNUNET_assert (8 == *ok); | 95 | GNUNET_assert (8 == *ok); |
90 | (*ok) = 0; | 96 | (*ok) = 0; |
@@ -95,6 +101,7 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
95 | { | 101 | { |
96 | static char c; | 102 | static char c; |
97 | int *ok = cls; | 103 | int *ok = cls; |
104 | |||
98 | GNUNET_assert (7 == *ok); | 105 | GNUNET_assert (7 == *ok); |
99 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); | 106 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); |
100 | GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); | 107 | GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); |
@@ -109,6 +116,7 @@ static void | |||
109 | task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 116 | task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
110 | { | 117 | { |
111 | int *ok = cls; | 118 | int *ok = cls; |
119 | |||
112 | GNUNET_assert (5 == *ok); | 120 | GNUNET_assert (5 == *ok); |
113 | (*ok) = 6; | 121 | (*ok) = 6; |
114 | p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); | 122 | p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); |
@@ -160,6 +168,7 @@ static void | |||
160 | taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 168 | taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
161 | { | 169 | { |
162 | int *ok = cls; | 170 | int *ok = cls; |
171 | |||
163 | GNUNET_assert (1 == *ok); | 172 | GNUNET_assert (1 == *ok); |
164 | *ok = 8; | 173 | *ok = 8; |
165 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); | 174 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); |
@@ -186,6 +195,7 @@ static void | |||
186 | taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 195 | taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
187 | { | 196 | { |
188 | int *ok = cls; | 197 | int *ok = cls; |
198 | |||
189 | GNUNET_assert (1 == *ok); | 199 | GNUNET_assert (1 == *ok); |
190 | *ok = 8; | 200 | *ok = 8; |
191 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); | 201 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); |
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c index 1f60ca9fd..b98e76eeb 100644 --- a/src/util/test_scheduler_delay.c +++ b/src/util/test_scheduler_delay.c | |||
@@ -57,14 +57,14 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
57 | else | 57 | else |
58 | cumDelta += (target.abs_value - now.abs_value); | 58 | cumDelta += (target.abs_value - now.abs_value); |
59 | target = | 59 | target = |
60 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply | 60 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply |
61 | (GNUNET_TIME_UNIT_MILLISECONDS, i)); | 61 | (GNUNET_TIME_UNIT_MILLISECONDS, i)); |
62 | fprintf (stderr, "."); | 62 | fprintf (stderr, "."); |
63 | if (i > MAXV) | 63 | if (i > MAXV) |
64 | { | 64 | { |
65 | fprintf (stderr, "\n"); | 65 | fprintf (stderr, "\n"); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 68 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
69 | (GNUNET_TIME_UNIT_MILLISECONDS, i), | 69 | (GNUNET_TIME_UNIT_MILLISECONDS, i), |
70 | &test_task, NULL); | 70 | &test_task, NULL); |
diff --git a/src/util/test_server.c b/src/util/test_server.c index 00d4352f8..577a841ff 100644 --- a/src/util/test_server.c +++ b/src/util/test_server.c | |||
@@ -49,8 +49,7 @@ static int ok; | |||
49 | 49 | ||
50 | 50 | ||
51 | static void | 51 | static void |
52 | finish_up (void *cls, | 52 | finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
53 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
54 | { | 53 | { |
55 | GNUNET_assert (ok == 6); | 54 | GNUNET_assert (ok == 6); |
56 | ok = 0; | 55 | ok = 0; |
@@ -68,14 +67,12 @@ recv_fin_cb (void *cls, | |||
68 | GNUNET_assert (ok == 5); | 67 | GNUNET_assert (ok == 5); |
69 | ok = 6; | 68 | ok = 6; |
70 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 69 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
71 | GNUNET_SCHEDULER_add_now (&finish_up, | 70 | GNUNET_SCHEDULER_add_now (&finish_up, NULL); |
72 | NULL); | ||
73 | } | 71 | } |
74 | 72 | ||
75 | 73 | ||
76 | static void | 74 | static void |
77 | first_reply_handler (void *cls, | 75 | first_reply_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
78 | const struct GNUNET_MessageHeader *msg) | ||
79 | { | 76 | { |
80 | GNUNET_assert (ok == 4); | 77 | GNUNET_assert (ok == 4); |
81 | ok = 5; | 78 | ok = 5; |
@@ -109,8 +106,7 @@ recv_cb (void *cls, | |||
109 | ok = 3; | 106 | ok = 3; |
110 | argclient = client; | 107 | argclient = client; |
111 | GNUNET_SERVER_client_keep (argclient); | 108 | GNUNET_SERVER_client_keep (argclient); |
112 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == | 109 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); |
113 | ntohs (message->size)); | ||
114 | GNUNET_assert (MY_TYPE == ntohs (message->type)); | 110 | GNUNET_assert (MY_TYPE == ntohs (message->type)); |
115 | GNUNET_assert (NULL != | 111 | GNUNET_assert (NULL != |
116 | GNUNET_SERVER_notify_transmit_ready (client, | 112 | GNUNET_SERVER_notify_transmit_ready (client, |
@@ -128,9 +124,7 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
128 | 124 | ||
129 | 125 | ||
130 | static size_t | 126 | static size_t |
131 | transmit_second_message (void *cls, | 127 | transmit_second_message (void *cls, size_t size, void *buf) |
132 | size_t size, | ||
133 | void *buf) | ||
134 | { | 128 | { |
135 | struct GNUNET_MessageHeader msg; | 129 | struct GNUNET_MessageHeader msg; |
136 | 130 | ||
@@ -143,10 +137,8 @@ transmit_second_message (void *cls, | |||
143 | 137 | ||
144 | 138 | ||
145 | static size_t | 139 | static size_t |
146 | transmit_initial_message (void *cls, | 140 | transmit_initial_message (void *cls, size_t size, void *buf) |
147 | size_t size, | 141 | { |
148 | void *buf) | ||
149 | { | ||
150 | struct GNUNET_MessageHeader msg; | 142 | struct GNUNET_MessageHeader msg; |
151 | 143 | ||
152 | GNUNET_assert (ok == 1); | 144 | GNUNET_assert (ok == 1); |
@@ -156,12 +148,12 @@ transmit_initial_message (void *cls, | |||
156 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 148 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
157 | memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); | 149 | memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); |
158 | GNUNET_assert (NULL != | 150 | GNUNET_assert (NULL != |
159 | GNUNET_CLIENT_notify_transmit_ready (cc, | 151 | GNUNET_CLIENT_notify_transmit_ready (cc, |
160 | sizeof (struct GNUNET_MessageHeader), | 152 | sizeof (struct |
161 | TIMEOUT, | 153 | GNUNET_MessageHeader), |
162 | GNUNET_YES, | 154 | TIMEOUT, GNUNET_YES, |
163 | &transmit_second_message, | 155 | &transmit_second_message, |
164 | NULL)); | 156 | NULL)); |
165 | GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT); | 157 | GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT); |
166 | return sizeof (struct GNUNET_MessageHeader); | 158 | return sizeof (struct GNUNET_MessageHeader); |
167 | } | 159 | } |
@@ -171,10 +163,10 @@ static void | |||
171 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 163 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
172 | { | 164 | { |
173 | struct sockaddr_in sa; | 165 | struct sockaddr_in sa; |
174 | struct sockaddr * sap[2]; | 166 | struct sockaddr *sap[2]; |
175 | socklen_t slens[2]; | 167 | socklen_t slens[2]; |
176 | 168 | ||
177 | sap[0] = (struct sockaddr*) &sa; | 169 | sap[0] = (struct sockaddr *) &sa; |
178 | slens[0] = sizeof (sa); | 170 | slens[0] = sizeof (sa); |
179 | sap[1] = NULL; | 171 | sap[1] = NULL; |
180 | slens[1] = 0; | 172 | slens[1] = 0; |
@@ -184,28 +176,24 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
184 | #endif | 176 | #endif |
185 | sa.sin_family = AF_INET; | 177 | sa.sin_family = AF_INET; |
186 | sa.sin_port = htons (PORT); | 178 | sa.sin_port = htons (PORT); |
187 | server = GNUNET_SERVER_create (NULL, | 179 | server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO); |
188 | NULL, | ||
189 | sap, | ||
190 | slens, | ||
191 | TIMEOUT, | ||
192 | GNUNET_NO); | ||
193 | GNUNET_assert (server != NULL); | 180 | GNUNET_assert (server != NULL); |
194 | GNUNET_SERVER_add_handlers (server, handlers); | 181 | GNUNET_SERVER_add_handlers (server, handlers); |
195 | cfg = GNUNET_CONFIGURATION_create (); | 182 | cfg = GNUNET_CONFIGURATION_create (); |
196 | GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); | 183 | GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); |
197 | GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", "localhost"); | 184 | GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", |
198 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); | 185 | "localhost"); |
199 | cc = GNUNET_CLIENT_connect ("test-server", | 186 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", |
200 | cfg); | 187 | "localhost"); |
188 | cc = GNUNET_CLIENT_connect ("test-server", cfg); | ||
201 | GNUNET_assert (cc != NULL); | 189 | GNUNET_assert (cc != NULL); |
202 | GNUNET_assert (NULL != | 190 | GNUNET_assert (NULL != |
203 | GNUNET_CLIENT_notify_transmit_ready (cc, | 191 | GNUNET_CLIENT_notify_transmit_ready (cc, |
204 | sizeof (struct GNUNET_MessageHeader), | 192 | sizeof (struct |
205 | TIMEOUT, | 193 | GNUNET_MessageHeader), |
206 | GNUNET_YES, | 194 | TIMEOUT, GNUNET_YES, |
207 | &transmit_initial_message, | 195 | &transmit_initial_message, |
208 | NULL)); | 196 | NULL)); |
209 | } | 197 | } |
210 | 198 | ||
211 | 199 | ||
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index 8ab8ef35b..03d57a222 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c | |||
@@ -46,8 +46,7 @@ static int ok; | |||
46 | 46 | ||
47 | 47 | ||
48 | static void | 48 | static void |
49 | finish_up (void *cls, | 49 | finish_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
50 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
51 | { | 50 | { |
52 | GNUNET_assert (ok == 5); | 51 | GNUNET_assert (ok == 5); |
53 | ok = 0; | 52 | ok = 0; |
@@ -64,8 +63,7 @@ notify_disconnect (void *cls, struct GNUNET_SERVER_Client *clientarg) | |||
64 | return; | 63 | return; |
65 | GNUNET_assert (ok == 4); | 64 | GNUNET_assert (ok == 4); |
66 | ok = 5; | 65 | ok = 5; |
67 | GNUNET_SCHEDULER_add_now (&finish_up, | 66 | GNUNET_SCHEDULER_add_now (&finish_up, NULL); |
68 | NULL); | ||
69 | } | 67 | } |
70 | 68 | ||
71 | 69 | ||
@@ -73,6 +71,7 @@ static void | |||
73 | server_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 71 | server_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
74 | { | 72 | { |
75 | struct GNUNET_SERVER_Client *argclient = cls; | 73 | struct GNUNET_SERVER_Client *argclient = cls; |
74 | |||
76 | GNUNET_assert (ok == 3); | 75 | GNUNET_assert (ok == 3); |
77 | ok = 4; | 76 | ok = 4; |
78 | GNUNET_SERVER_client_disconnect (argclient); | 77 | GNUNET_SERVER_client_disconnect (argclient); |
@@ -89,8 +88,7 @@ recv_cb (void *cls, | |||
89 | ok = 3; | 88 | ok = 3; |
90 | GNUNET_SERVER_client_keep (client); | 89 | GNUNET_SERVER_client_keep (client); |
91 | GNUNET_SCHEDULER_add_now (&server_disconnect, client); | 90 | GNUNET_SCHEDULER_add_now (&server_disconnect, client); |
92 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == | 91 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); |
93 | ntohs (message->size)); | ||
94 | GNUNET_assert (MY_TYPE == ntohs (message->type)); | 92 | GNUNET_assert (MY_TYPE == ntohs (message->type)); |
95 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 93 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
96 | } | 94 | } |
@@ -103,10 +101,8 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
103 | 101 | ||
104 | 102 | ||
105 | static size_t | 103 | static size_t |
106 | transmit_initial_message (void *cls, | 104 | transmit_initial_message (void *cls, size_t size, void *buf) |
107 | size_t size, | 105 | { |
108 | void *buf) | ||
109 | { | ||
110 | struct GNUNET_MessageHeader msg; | 106 | struct GNUNET_MessageHeader msg; |
111 | 107 | ||
112 | GNUNET_assert (ok == 1); | 108 | GNUNET_assert (ok == 1); |
@@ -123,10 +119,10 @@ static void | |||
123 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 119 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
124 | { | 120 | { |
125 | struct sockaddr_in sa; | 121 | struct sockaddr_in sa; |
126 | struct sockaddr * sap[2]; | 122 | struct sockaddr *sap[2]; |
127 | socklen_t slens[2]; | 123 | socklen_t slens[2]; |
128 | 124 | ||
129 | sap[0] = (struct sockaddr*) &sa; | 125 | sap[0] = (struct sockaddr *) &sa; |
130 | slens[0] = sizeof (sa); | 126 | slens[0] = sizeof (sa); |
131 | sap[1] = NULL; | 127 | sap[1] = NULL; |
132 | slens[1] = 0; | 128 | slens[1] = 0; |
@@ -136,29 +132,25 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
136 | #endif | 132 | #endif |
137 | sa.sin_family = AF_INET; | 133 | sa.sin_family = AF_INET; |
138 | sa.sin_port = htons (PORT); | 134 | sa.sin_port = htons (PORT); |
139 | server = GNUNET_SERVER_create (NULL, | 135 | server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO); |
140 | NULL, | ||
141 | sap, | ||
142 | slens, | ||
143 | TIMEOUT, | ||
144 | GNUNET_NO); | ||
145 | GNUNET_assert (server != NULL); | 136 | GNUNET_assert (server != NULL); |
146 | GNUNET_SERVER_add_handlers (server, handlers); | 137 | GNUNET_SERVER_add_handlers (server, handlers); |
147 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, NULL); | 138 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, NULL); |
148 | cfg = GNUNET_CONFIGURATION_create (); | 139 | cfg = GNUNET_CONFIGURATION_create (); |
149 | GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); | 140 | GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); |
150 | GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", "localhost"); | 141 | GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", |
151 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); | 142 | "localhost"); |
152 | cc = GNUNET_CLIENT_connect ("test-server", | 143 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", |
153 | cfg); | 144 | "localhost"); |
145 | cc = GNUNET_CLIENT_connect ("test-server", cfg); | ||
154 | GNUNET_assert (cc != NULL); | 146 | GNUNET_assert (cc != NULL); |
155 | GNUNET_assert (NULL != | 147 | GNUNET_assert (NULL != |
156 | GNUNET_CLIENT_notify_transmit_ready (cc, | 148 | GNUNET_CLIENT_notify_transmit_ready (cc, |
157 | sizeof (struct GNUNET_MessageHeader), | 149 | sizeof (struct |
158 | TIMEOUT, | 150 | GNUNET_MessageHeader), |
159 | GNUNET_YES, | 151 | TIMEOUT, GNUNET_YES, |
160 | &transmit_initial_message, | 152 | &transmit_initial_message, |
161 | NULL)); | 153 | NULL)); |
162 | } | 154 | } |
163 | 155 | ||
164 | 156 | ||
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c index 5c36b7b03..4b9d84059 100644 --- a/src/util/test_server_with_client.c +++ b/src/util/test_server_with_client.c | |||
@@ -49,6 +49,7 @@ static void | |||
49 | send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 49 | send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
50 | { | 50 | { |
51 | struct GNUNET_SERVER_Client *argclient = cls; | 51 | struct GNUNET_SERVER_Client *argclient = cls; |
52 | |||
52 | GNUNET_assert (ok == 3); | 53 | GNUNET_assert (ok == 3); |
53 | ok++; | 54 | ok++; |
54 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | 55 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); |
@@ -66,8 +67,7 @@ recv_cb (void *cls, | |||
66 | struct sockaddr_in *have; | 67 | struct sockaddr_in *have; |
67 | 68 | ||
68 | GNUNET_assert (GNUNET_OK == | 69 | GNUNET_assert (GNUNET_OK == |
69 | GNUNET_SERVER_client_get_address (argclient, | 70 | GNUNET_SERVER_client_get_address (argclient, &addr, &addrlen)); |
70 | &addr, &addrlen)); | ||
71 | 71 | ||
72 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 72 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); |
73 | have = addr; | 73 | have = addr; |
@@ -81,21 +81,21 @@ recv_cb (void *cls, | |||
81 | GNUNET_assert (0 == memcmp (&sa, addr, addrlen)); | 81 | GNUNET_assert (0 == memcmp (&sa, addr, addrlen)); |
82 | GNUNET_free (addr); | 82 | GNUNET_free (addr); |
83 | switch (ok) | 83 | switch (ok) |
84 | { | 84 | { |
85 | case 2: | 85 | case 2: |
86 | ok++; | 86 | ok++; |
87 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 87 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
88 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), | 88 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), |
89 | &send_done, argclient); | 89 | &send_done, argclient); |
90 | break; | 90 | break; |
91 | case 4: | 91 | case 4: |
92 | ok++; | 92 | ok++; |
93 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); | 93 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); |
94 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | 94 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); |
95 | break; | 95 | break; |
96 | default: | 96 | default: |
97 | GNUNET_assert (0); | 97 | GNUNET_assert (0); |
98 | } | 98 | } |
99 | 99 | ||
100 | } | 100 | } |
101 | 101 | ||
@@ -156,10 +156,10 @@ static void | |||
156 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 156 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
157 | { | 157 | { |
158 | struct sockaddr_in sa; | 158 | struct sockaddr_in sa; |
159 | struct sockaddr * sap[2]; | 159 | struct sockaddr *sap[2]; |
160 | socklen_t slens[2]; | 160 | socklen_t slens[2]; |
161 | 161 | ||
162 | sap[0] = (struct sockaddr*) &sa; | 162 | sap[0] = (struct sockaddr *) &sa; |
163 | slens[0] = sizeof (sa); | 163 | slens[0] = sizeof (sa); |
164 | sap[1] = NULL; | 164 | sap[1] = NULL; |
165 | slens[1] = 0; | 165 | slens[1] = 0; |
@@ -172,7 +172,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
172 | server = GNUNET_SERVER_create (NULL, | 172 | server = GNUNET_SERVER_create (NULL, |
173 | NULL, | 173 | NULL, |
174 | sap, | 174 | sap, |
175 | slens, | 175 | slens, |
176 | GNUNET_TIME_relative_multiply | 176 | GNUNET_TIME_relative_multiply |
177 | (GNUNET_TIME_UNIT_MILLISECONDS, 250), | 177 | (GNUNET_TIME_UNIT_MILLISECONDS, 250), |
178 | GNUNET_NO); | 178 | GNUNET_NO); |
@@ -182,8 +182,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
182 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); | 182 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); |
183 | cfg = GNUNET_CONFIGURATION_create (); | 183 | cfg = GNUNET_CONFIGURATION_create (); |
184 | GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); | 184 | GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); |
185 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", | 185 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); |
186 | "localhost"); | ||
187 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | 186 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", |
188 | "localhost"); | 187 | "localhost"); |
189 | client = GNUNET_CLIENT_connect ("test", cfg); | 188 | client = GNUNET_CLIENT_connect ("test", cfg); |
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c index 8e994095d..00df21129 100644 --- a/src/util/test_server_with_client_unix.c +++ b/src/util/test_server_with_client_unix.c | |||
@@ -47,6 +47,7 @@ static void | |||
47 | send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 47 | send_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
48 | { | 48 | { |
49 | struct GNUNET_SERVER_Client *argclient = cls; | 49 | struct GNUNET_SERVER_Client *argclient = cls; |
50 | |||
50 | GNUNET_assert (ok == 3); | 51 | GNUNET_assert (ok == 3); |
51 | ok++; | 52 | ok++; |
52 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | 53 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); |
@@ -59,21 +60,21 @@ recv_cb (void *cls, | |||
59 | const struct GNUNET_MessageHeader *message) | 60 | const struct GNUNET_MessageHeader *message) |
60 | { | 61 | { |
61 | switch (ok) | 62 | switch (ok) |
62 | { | 63 | { |
63 | case 2: | 64 | case 2: |
64 | ok++; | 65 | ok++; |
65 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 66 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
66 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), | 67 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), |
67 | &send_done, argclient); | 68 | &send_done, argclient); |
68 | break; | 69 | break; |
69 | case 4: | 70 | case 4: |
70 | ok++; | 71 | ok++; |
71 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); | 72 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); |
72 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | 73 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); |
73 | break; | 74 | break; |
74 | default: | 75 | default: |
75 | GNUNET_assert (0); | 76 | GNUNET_assert (0); |
76 | } | 77 | } |
77 | 78 | ||
78 | } | 79 | } |
79 | 80 | ||
@@ -134,12 +135,12 @@ static void | |||
134 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 135 | task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
135 | { | 136 | { |
136 | struct sockaddr_un un; | 137 | struct sockaddr_un un; |
137 | const char * unixpath = "/tmp/testsock"; | 138 | const char *unixpath = "/tmp/testsock"; |
138 | size_t slen = strlen (unixpath); | 139 | size_t slen = strlen (unixpath); |
139 | struct sockaddr * sap[2]; | 140 | struct sockaddr *sap[2]; |
140 | socklen_t slens[2]; | 141 | socklen_t slens[2]; |
141 | 142 | ||
142 | memset(&un, 0, sizeof(un)); | 143 | memset (&un, 0, sizeof (un)); |
143 | un.sun_family = AF_UNIX; | 144 | un.sun_family = AF_UNIX; |
144 | memcpy (un.sun_path, unixpath, slen); | 145 | memcpy (un.sun_path, unixpath, slen); |
145 | un.sun_path[slen] = '\0'; | 146 | un.sun_path[slen] = '\0'; |
@@ -151,7 +152,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
151 | #endif | 152 | #endif |
152 | 153 | ||
153 | 154 | ||
154 | sap[0] = (struct sockaddr*) &un; | 155 | sap[0] = (struct sockaddr *) &un; |
155 | slens[0] = sizeof (un); | 156 | slens[0] = sizeof (un); |
156 | sap[1] = NULL; | 157 | sap[1] = NULL; |
157 | slens[1] = 0; | 158 | slens[1] = 0; |
@@ -168,8 +169,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
168 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); | 169 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); |
169 | cfg = GNUNET_CONFIGURATION_create (); | 170 | cfg = GNUNET_CONFIGURATION_create (); |
170 | 171 | ||
171 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", | 172 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath); |
172 | unixpath); | ||
173 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | 173 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", |
174 | "localhost"); | 174 | "localhost"); |
175 | 175 | ||
diff --git a/src/util/test_service.c b/src/util/test_service.c index 9bd58352b..daafa6cd3 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -76,8 +76,7 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
76 | } | 76 | } |
77 | 77 | ||
78 | static void | 78 | static void |
79 | do_stop (void *cls, | 79 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
80 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
81 | { | 80 | { |
82 | GNUNET_SERVICE_stop (sctx); | 81 | GNUNET_SERVICE_stop (sctx); |
83 | } | 82 | } |
@@ -143,8 +142,7 @@ check () | |||
143 | GNUNET_SERVICE_run (5, | 142 | GNUNET_SERVICE_run (5, |
144 | argv, | 143 | argv, |
145 | "test_service", | 144 | "test_service", |
146 | GNUNET_SERVICE_OPTION_NONE, | 145 | GNUNET_SERVICE_OPTION_NONE, &runner, &ok)); |
147 | &runner, &ok)); | ||
148 | GNUNET_assert (0 == ok); | 146 | GNUNET_assert (0 == ok); |
149 | return ok; | 147 | return ok; |
150 | } | 148 | } |
@@ -217,8 +215,8 @@ start_stop_main (void *cls, | |||
217 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 215 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
218 | { | 216 | { |
219 | int *ret = cls; | 217 | int *ret = cls; |
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 218 | |
221 | "Starting service using start method\n"); | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting service using start method\n"); |
222 | sctx = GNUNET_SERVICE_start ("test_service", cfg); | 220 | sctx = GNUNET_SERVICE_start ("test_service", cfg); |
223 | GNUNET_assert (NULL != sctx); | 221 | GNUNET_assert (NULL != sctx); |
224 | runner (cls, GNUNET_SERVICE_get_server (sctx), cfg); | 222 | runner (cls, GNUNET_SERVICE_get_server (sctx), cfg); |
@@ -245,6 +243,7 @@ check_start_stop () | |||
245 | GNUNET_GETOPT_OPTION_END | 243 | GNUNET_GETOPT_OPTION_END |
246 | }; | 244 | }; |
247 | int ret = 1; | 245 | int ret = 1; |
246 | |||
248 | GNUNET_assert (GNUNET_OK == | 247 | GNUNET_assert (GNUNET_OK == |
249 | GNUNET_PROGRAM_run (5, | 248 | GNUNET_PROGRAM_run (5, |
250 | argv, | 249 | argv, |
@@ -278,22 +277,22 @@ main (int argc, char *argv[]) | |||
278 | s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | 277 | s = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); |
279 | #endif | 278 | #endif |
280 | if (NULL == s) | 279 | if (NULL == s) |
280 | { | ||
281 | if ((errno == ENOBUFS) || | ||
282 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | ||
281 | { | 283 | { |
282 | if ((errno == ENOBUFS) || | 284 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
283 | (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES)) | 285 | return 1; |
284 | { | ||
285 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
286 | return 1; | ||
287 | } | ||
288 | fprintf (stderr, | ||
289 | "IPv6 support seems to not be available (%s), not testing it!\n", | ||
290 | strerror (errno)); | ||
291 | } | 286 | } |
287 | fprintf (stderr, | ||
288 | "IPv6 support seems to not be available (%s), not testing it!\n", | ||
289 | strerror (errno)); | ||
290 | } | ||
292 | else | 291 | else |
293 | { | 292 | { |
294 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); | 293 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
295 | ret += check6 (); | 294 | ret += check6 (); |
296 | } | 295 | } |
297 | ret += check_start_stop (); | 296 | ret += check_start_stop (); |
298 | 297 | ||
299 | return ret; | 298 | return ret; |
diff --git a/src/util/test_strings.c b/src/util/test_strings.c index a1614b487..97b0f4105 100644 --- a/src/util/test_strings.c +++ b/src/util/test_strings.c | |||
@@ -49,33 +49,26 @@ check () | |||
49 | b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL); | 49 | b = GNUNET_STRINGS_byte_size_fancy (10240LL * 1024LL * 1024LL * 1024LL); |
50 | WANT (buf, b); | 50 | WANT (buf, b); |
51 | sprintf (buf, "4 %s", _( /* time unit */ "ms")); | 51 | sprintf (buf, "4 %s", _( /* time unit */ "ms")); |
52 | b = | 52 | b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply |
53 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply | 53 | (GNUNET_TIME_UNIT_MILLISECONDS, |
54 | (GNUNET_TIME_UNIT_MILLISECONDS, | 54 | 4)); |
55 | 4)); | ||
56 | WANT (buf, b); | 55 | WANT (buf, b); |
57 | sprintf (buf, "7 %s", _( /* time unit */ "s")); | 56 | sprintf (buf, "7 %s", _( /* time unit */ "s")); |
58 | b = | 57 | b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply |
59 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply | 58 | (GNUNET_TIME_UNIT_MILLISECONDS, |
60 | (GNUNET_TIME_UNIT_MILLISECONDS, | 59 | 7 * 1000)); |
61 | 7 * 1000)); | ||
62 | WANT (buf, b); | 60 | WANT (buf, b); |
63 | sprintf (buf, "7 %s", _( /* time unit */ "h")); | 61 | sprintf (buf, "7 %s", _( /* time unit */ "h")); |
64 | b = | 62 | b = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply |
65 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_relative_multiply | 63 | (GNUNET_TIME_UNIT_MILLISECONDS, |
66 | (GNUNET_TIME_UNIT_MILLISECONDS, | 64 | 7 * 60 * 60 * 1000)); |
67 | 7 * 60 * 60 * 1000)); | ||
68 | WANT (buf, b); | 65 | WANT (buf, b); |
69 | #ifndef MINGW | 66 | #ifndef MINGW |
70 | hdir = getenv ("HOME"); | 67 | hdir = getenv ("HOME"); |
71 | #else | 68 | #else |
72 | hdir = getenv ("USERPROFILE"); | 69 | hdir = getenv ("USERPROFILE"); |
73 | #endif | 70 | #endif |
74 | GNUNET_snprintf (buf, | 71 | GNUNET_snprintf (buf, sizeof (buf), "%s%s", hdir, DIR_SEPARATOR_STR); |
75 | sizeof (buf), | ||
76 | "%s%s", | ||
77 | hdir, | ||
78 | DIR_SEPARATOR_STR); | ||
79 | b = GNUNET_STRINGS_filename_expand ("~"); | 72 | b = GNUNET_STRINGS_filename_expand ("~"); |
80 | GNUNET_assert (b != NULL); | 73 | GNUNET_assert (b != NULL); |
81 | WANT (buf, b); | 74 | WANT (buf, b); |
@@ -92,15 +85,15 @@ check () | |||
92 | at.abs_value = 5000; | 85 | at.abs_value = 5000; |
93 | r = GNUNET_STRINGS_absolute_time_to_string (at); | 86 | r = GNUNET_STRINGS_absolute_time_to_string (at); |
94 | /* r should be something like "Wed Dec 31 17:00:05 1969" | 87 | /* r should be something like "Wed Dec 31 17:00:05 1969" |
95 | where the details of the day and hour depend on the timezone; | 88 | * where the details of the day and hour depend on the timezone; |
96 | however, the "0:05 19" should always be there; hence: */ | 89 | * however, the "0:05 19" should always be there; hence: */ |
97 | if (NULL == strstr (r, "0:05 19")) | 90 | if (NULL == strstr (r, "0:05 19")) |
98 | { | 91 | { |
99 | fprintf (stderr, "Got %s\n", r); | 92 | fprintf (stderr, "Got %s\n", r); |
100 | GNUNET_break (0); | 93 | GNUNET_break (0); |
101 | GNUNET_free (r); | 94 | GNUNET_free (r); |
102 | return 1; | 95 | return 1; |
103 | } | 96 | } |
104 | GNUNET_free (r); | 97 | GNUNET_free (r); |
105 | b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); | 98 | b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); |
106 | WANT ("TEST", b); | 99 | WANT ("TEST", b); |
diff --git a/src/util/test_time.c b/src/util/test_time.c index 13f5e58a0..788884fcc 100644 --- a/src/util/test_time.c +++ b/src/util/test_time.c | |||
@@ -42,6 +42,7 @@ check () | |||
42 | struct GNUNET_TIME_Relative relUnit; | 42 | struct GNUNET_TIME_Relative relUnit; |
43 | struct GNUNET_TIME_RelativeNBO reln; | 43 | struct GNUNET_TIME_RelativeNBO reln; |
44 | unsigned int i; | 44 | unsigned int i; |
45 | |||
45 | forever = GNUNET_TIME_absolute_get_forever (); | 46 | forever = GNUNET_TIME_absolute_get_forever (); |
46 | relForever = GNUNET_TIME_relative_get_forever (); | 47 | relForever = GNUNET_TIME_relative_get_forever (); |
47 | relUnit = GNUNET_TIME_relative_get_unit (); | 48 | relUnit = GNUNET_TIME_relative_get_unit (); |
@@ -59,9 +60,10 @@ check () | |||
59 | rel = GNUNET_TIME_relative_multiply (rel, 2); | 60 | rel = GNUNET_TIME_relative_multiply (rel, 2); |
60 | GNUNET_log_skip (0, GNUNET_NO); | 61 | GNUNET_log_skip (0, GNUNET_NO); |
61 | GNUNET_assert (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value); | 62 | GNUNET_assert (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value); |
62 | /*check zero*/ | 63 | /*check zero */ |
63 | rel.rel_value = (UINT64_MAX) - 1024; | 64 | rel.rel_value = (UINT64_MAX) - 1024; |
64 | GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == GNUNET_TIME_relative_multiply (rel,0).rel_value); | 65 | GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == |
66 | GNUNET_TIME_relative_multiply (rel, 0).rel_value); | ||
65 | 67 | ||
66 | /* test infinity-check for relative to absolute */ | 68 | /* test infinity-check for relative to absolute */ |
67 | GNUNET_log_skip (1, GNUNET_NO); | 69 | GNUNET_log_skip (1, GNUNET_NO); |
@@ -69,14 +71,14 @@ check () | |||
69 | GNUNET_assert (last.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value); | 71 | GNUNET_assert (last.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value); |
70 | GNUNET_log_skip (0, GNUNET_YES); | 72 | GNUNET_log_skip (0, GNUNET_YES); |
71 | 73 | ||
72 | /*check relative to absolute*/ | 74 | /*check relative to absolute */ |
73 | rel.rel_value = 0; | 75 | rel.rel_value = 0; |
74 | GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value == | 76 | GNUNET_assert (GNUNET_TIME_absolute_get ().abs_value == |
75 | GNUNET_TIME_relative_to_absolute(rel).abs_value); | 77 | GNUNET_TIME_relative_to_absolute (rel).abs_value); |
76 | /*check forever*/ | 78 | /*check forever */ |
77 | rel.rel_value = UINT64_MAX; | 79 | rel.rel_value = UINT64_MAX; |
78 | GNUNET_assert (GNUNET_TIME_absolute_get_forever ().abs_value == | 80 | GNUNET_assert (GNUNET_TIME_absolute_get_forever ().abs_value == |
79 | GNUNET_TIME_relative_to_absolute(rel).abs_value); | 81 | GNUNET_TIME_relative_to_absolute (rel).abs_value); |
80 | /* check overflow for r2a */ | 82 | /* check overflow for r2a */ |
81 | rel.rel_value = (UINT64_MAX) - 1024; | 83 | rel.rel_value = (UINT64_MAX) - 1024; |
82 | GNUNET_log_skip (1, GNUNET_NO); | 84 | GNUNET_log_skip (1, GNUNET_NO); |
@@ -106,8 +108,8 @@ check () | |||
106 | GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value == | 108 | GNUNET_assert (GNUNET_TIME_absolute_get_difference (future, now).rel_value == |
107 | 0); | 109 | 0); |
108 | 110 | ||
109 | GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).rel_value == | 111 | GNUNET_assert (GNUNET_TIME_absolute_get_difference (zero, forever).rel_value |
110 | forever.abs_value); | 112 | == forever.abs_value); |
111 | 113 | ||
112 | past.abs_value = now.abs_value - 1000000; | 114 | past.abs_value = now.abs_value - 1000000; |
113 | rel = GNUNET_TIME_absolute_get_duration (future); | 115 | rel = GNUNET_TIME_absolute_get_duration (future); |
@@ -125,7 +127,7 @@ check () | |||
125 | GNUNET_assert (rel.rel_value <= 1000000); | 127 | GNUNET_assert (rel.rel_value <= 1000000); |
126 | forever = GNUNET_TIME_absolute_get_forever (); | 128 | forever = GNUNET_TIME_absolute_get_forever (); |
127 | GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == | 129 | GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == |
128 | GNUNET_TIME_absolute_get_remaining (forever).rel_value); | 130 | GNUNET_TIME_absolute_get_remaining (forever).rel_value); |
129 | 131 | ||
130 | /* check endianess */ | 132 | /* check endianess */ |
131 | reln = GNUNET_TIME_relative_hton (rel); | 133 | reln = GNUNET_TIME_relative_hton (rel); |
@@ -150,77 +152,80 @@ check () | |||
150 | GNUNET_assert (future.abs_value == now.abs_value); | 152 | GNUNET_assert (future.abs_value == now.abs_value); |
151 | 153 | ||
152 | GNUNET_assert (forever.abs_value == | 154 | GNUNET_assert (forever.abs_value == |
153 | GNUNET_TIME_absolute_subtract (forever, | 155 | GNUNET_TIME_absolute_subtract (forever, |
154 | GNUNET_TIME_UNIT_MINUTES).abs_value); | 156 | GNUNET_TIME_UNIT_MINUTES).abs_value); |
155 | /*check absolute subtract*/ | 157 | /*check absolute subtract */ |
156 | now.abs_value= 50000; | 158 | now.abs_value = 50000; |
157 | rel.rel_value = 100000; | 159 | rel.rel_value = 100000; |
158 | GNUNET_assert (GNUNET_TIME_UNIT_ZERO_ABS.abs_value == | 160 | GNUNET_assert (GNUNET_TIME_UNIT_ZERO_ABS.abs_value == |
159 | (GNUNET_TIME_absolute_subtract(now,rel)).abs_value); | 161 | (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); |
160 | rel.rel_value = 10000; | 162 | rel.rel_value = 10000; |
161 | GNUNET_assert (40000 == | 163 | GNUNET_assert (40000 == (GNUNET_TIME_absolute_subtract (now, rel)).abs_value); |
162 | (GNUNET_TIME_absolute_subtract(now,rel)).abs_value); | 164 | |
165 | /*check relative divide */ | ||
166 | GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == | ||
167 | (GNUNET_TIME_relative_divide (rel, 0)).rel_value); | ||
163 | 168 | ||
164 | /*check relative divide*/ | ||
165 | GNUNET_assert(GNUNET_TIME_UNIT_FOREVER_REL.rel_value == | ||
166 | (GNUNET_TIME_relative_divide (rel,0)).rel_value); | ||
167 | |||
168 | rel = GNUNET_TIME_UNIT_FOREVER_REL; | 169 | rel = GNUNET_TIME_UNIT_FOREVER_REL; |
169 | GNUNET_assert(GNUNET_TIME_UNIT_FOREVER_REL.rel_value == | 170 | GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == |
170 | (GNUNET_TIME_relative_divide (rel,2)).rel_value); | 171 | (GNUNET_TIME_relative_divide (rel, 2)).rel_value); |
171 | 172 | ||
172 | rel = GNUNET_TIME_relative_divide (relUnit,2); | 173 | rel = GNUNET_TIME_relative_divide (relUnit, 2); |
173 | GNUNET_assert(rel.rel_value == relUnit.rel_value / 2); | 174 | GNUNET_assert (rel.rel_value == relUnit.rel_value / 2); |
174 | 175 | ||
175 | 176 | ||
176 | /* check Return absolute time of 0ms*/ | 177 | /* check Return absolute time of 0ms */ |
177 | zero = GNUNET_TIME_absolute_get_zero (); | 178 | zero = GNUNET_TIME_absolute_get_zero (); |
178 | 179 | ||
179 | /* check GNUNET_TIME_calculate_eta */ | 180 | /* check GNUNET_TIME_calculate_eta */ |
180 | last.abs_value = GNUNET_TIME_absolute_get ().abs_value - 1024; | 181 | last.abs_value = GNUNET_TIME_absolute_get ().abs_value - 1024; |
181 | forever = GNUNET_TIME_absolute_get_forever (); | 182 | forever = GNUNET_TIME_absolute_get_forever (); |
182 | forever.abs_value = forever.abs_value - 1024; | 183 | forever.abs_value = forever.abs_value - 1024; |
183 | GNUNET_assert(GNUNET_TIME_absolute_get_zero ().abs_value == | 184 | GNUNET_assert (GNUNET_TIME_absolute_get_zero ().abs_value == |
184 | GNUNET_TIME_calculate_eta (forever, 50000, 100000).rel_value); | 185 | GNUNET_TIME_calculate_eta (forever, 50000, 100000).rel_value); |
185 | /* check zero */ | 186 | /* check zero */ |
186 | GNUNET_log_skip (1, GNUNET_NO); | 187 | GNUNET_log_skip (1, GNUNET_NO); |
187 | GNUNET_assert(GNUNET_TIME_UNIT_ZERO.rel_value == | 188 | GNUNET_assert (GNUNET_TIME_UNIT_ZERO.rel_value == |
188 | (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value); | 189 | (GNUNET_TIME_calculate_eta (last, 60000, 50000)).rel_value); |
189 | GNUNET_log_skip (0, GNUNET_YES); | 190 | GNUNET_log_skip (0, GNUNET_YES); |
190 | /*check forever*/ | 191 | /*check forever */ |
191 | GNUNET_assert(GNUNET_TIME_UNIT_FOREVER_REL.rel_value == | 192 | GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == |
192 | (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value); | 193 | (GNUNET_TIME_calculate_eta (last, 0, 50000)).rel_value); |
193 | 194 | ||
194 | /*check relative subtract*/ | 195 | /*check relative subtract */ |
195 | now = GNUNET_TIME_absolute_get (); | 196 | now = GNUNET_TIME_absolute_get (); |
196 | rel.rel_value = now.abs_value; | 197 | rel.rel_value = now.abs_value; |
197 | relForever.rel_value = rel.rel_value + 1024; | 198 | relForever.rel_value = rel.rel_value + 1024; |
198 | GNUNET_assert(1024 == | 199 | GNUNET_assert (1024 == |
199 | GNUNET_TIME_relative_subtract(relForever,rel).rel_value); | 200 | GNUNET_TIME_relative_subtract (relForever, rel).rel_value); |
200 | /*check zero*/ | 201 | /*check zero */ |
201 | GNUNET_assert(GNUNET_TIME_relative_get_zero ().rel_value == | 202 | GNUNET_assert (GNUNET_TIME_relative_get_zero ().rel_value == |
202 | GNUNET_TIME_relative_subtract(rel,relForever).rel_value); | 203 | GNUNET_TIME_relative_subtract (rel, relForever).rel_value); |
203 | /*check forever*/ | 204 | /*check forever */ |
204 | rel.rel_value = UINT64_MAX; | 205 | rel.rel_value = UINT64_MAX; |
205 | GNUNET_assert(GNUNET_TIME_relative_get_forever ().rel_value == | 206 | GNUNET_assert (GNUNET_TIME_relative_get_forever ().rel_value == |
206 | GNUNET_TIME_relative_subtract(rel,relForever).rel_value); | 207 | GNUNET_TIME_relative_subtract (rel, relForever).rel_value); |
207 | 208 | ||
208 | /*check GNUNET_TIME_relative_min*/ | 209 | /*check GNUNET_TIME_relative_min */ |
209 | now = GNUNET_TIME_absolute_get (); | 210 | now = GNUNET_TIME_absolute_get (); |
210 | rel.rel_value = now.abs_value; | 211 | rel.rel_value = now.abs_value; |
211 | relForever.rel_value = rel.rel_value - 1024; | 212 | relForever.rel_value = rel.rel_value - 1024; |
212 | GNUNET_assert(relForever.rel_value == GNUNET_TIME_relative_min(rel,relForever).rel_value); | 213 | GNUNET_assert (relForever.rel_value == |
214 | GNUNET_TIME_relative_min (rel, relForever).rel_value); | ||
213 | 215 | ||
214 | /*check GNUNET_TIME_relative_max */ | 216 | /*check GNUNET_TIME_relative_max */ |
215 | GNUNET_assert(rel.rel_value == GNUNET_TIME_relative_max(rel,relForever).rel_value); | 217 | GNUNET_assert (rel.rel_value == |
216 | 218 | GNUNET_TIME_relative_max (rel, relForever).rel_value); | |
217 | /*check GNUNET_TIME_absolute_min*/ | 219 | |
220 | /*check GNUNET_TIME_absolute_min */ | ||
218 | now = GNUNET_TIME_absolute_get (); | 221 | now = GNUNET_TIME_absolute_get (); |
219 | last.abs_value = now.abs_value - 1024; | 222 | last.abs_value = now.abs_value - 1024; |
220 | GNUNET_assert(last.abs_value == GNUNET_TIME_absolute_min(now,last).abs_value); | 223 | GNUNET_assert (last.abs_value == |
224 | GNUNET_TIME_absolute_min (now, last).abs_value); | ||
221 | 225 | ||
222 | /*check GNUNET_TIME_absolute_max*/ | 226 | /*check GNUNET_TIME_absolute_max */ |
223 | GNUNET_assert(now.abs_value == GNUNET_TIME_absolute_max(now,last).abs_value); | 227 | GNUNET_assert (now.abs_value == |
228 | GNUNET_TIME_absolute_max (now, last).abs_value); | ||
224 | 229 | ||
225 | return 0; | 230 | return 0; |
226 | } | 231 | } |
diff --git a/src/util/time.c b/src/util/time.c index 3dc2ef03a..f4d4c4070 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -34,7 +34,7 @@ static long long timestamp_offset; | |||
34 | * @param offset the offset to skew the locale time by | 34 | * @param offset the offset to skew the locale time by |
35 | */ | 35 | */ |
36 | void | 36 | void |
37 | GNUNET_TIME_set_offset(long long offset) | 37 | GNUNET_TIME_set_offset (long long offset) |
38 | { | 38 | { |
39 | timestamp_offset = offset; | 39 | timestamp_offset = offset; |
40 | } | 40 | } |
@@ -53,8 +53,8 @@ GNUNET_TIME_absolute_get () | |||
53 | 53 | ||
54 | GETTIMEOFDAY (&tv, NULL); | 54 | GETTIMEOFDAY (&tv, NULL); |
55 | ret.abs_value = | 55 | ret.abs_value = |
56 | (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + | 56 | (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + |
57 | ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; | 57 | ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; |
58 | return ret; | 58 | return ret; |
59 | } | 59 | } |
60 | 60 | ||
@@ -66,6 +66,7 @@ struct GNUNET_TIME_Relative | |||
66 | GNUNET_TIME_relative_get_zero () | 66 | GNUNET_TIME_relative_get_zero () |
67 | { | 67 | { |
68 | static struct GNUNET_TIME_Relative zero; | 68 | static struct GNUNET_TIME_Relative zero; |
69 | |||
69 | return zero; | 70 | return zero; |
70 | } | 71 | } |
71 | 72 | ||
@@ -77,6 +78,7 @@ struct GNUNET_TIME_Absolute | |||
77 | GNUNET_TIME_absolute_get_zero () | 78 | GNUNET_TIME_absolute_get_zero () |
78 | { | 79 | { |
79 | static struct GNUNET_TIME_Absolute zero; | 80 | static struct GNUNET_TIME_Absolute zero; |
81 | |||
80 | return zero; | 82 | return zero; |
81 | } | 83 | } |
82 | 84 | ||
@@ -120,14 +122,16 @@ struct GNUNET_TIME_Absolute | |||
120 | GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) | 122 | GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) |
121 | { | 123 | { |
122 | struct GNUNET_TIME_Absolute ret; | 124 | struct GNUNET_TIME_Absolute ret; |
125 | |||
123 | if (rel.rel_value == UINT64_MAX) | 126 | if (rel.rel_value == UINT64_MAX) |
124 | return GNUNET_TIME_absolute_get_forever (); | 127 | return GNUNET_TIME_absolute_get_forever (); |
125 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 128 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
129 | |||
126 | if (rel.rel_value + now.abs_value < rel.rel_value) | 130 | if (rel.rel_value + now.abs_value < rel.rel_value) |
127 | { | 131 | { |
128 | GNUNET_break (0); /* overflow... */ | 132 | GNUNET_break (0); /* overflow... */ |
129 | return GNUNET_TIME_absolute_get_forever (); | 133 | return GNUNET_TIME_absolute_get_forever (); |
130 | } | 134 | } |
131 | ret.abs_value = rel.rel_value + now.abs_value; | 135 | ret.abs_value = rel.rel_value + now.abs_value; |
132 | return ret; | 136 | return ret; |
133 | } | 137 | } |
@@ -208,9 +212,11 @@ struct GNUNET_TIME_Relative | |||
208 | GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) | 212 | GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) |
209 | { | 213 | { |
210 | struct GNUNET_TIME_Relative ret; | 214 | struct GNUNET_TIME_Relative ret; |
215 | |||
211 | if (future.abs_value == UINT64_MAX) | 216 | if (future.abs_value == UINT64_MAX) |
212 | return GNUNET_TIME_relative_get_forever (); | 217 | return GNUNET_TIME_relative_get_forever (); |
213 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 218 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
219 | |||
214 | if (now.abs_value > future.abs_value) | 220 | if (now.abs_value > future.abs_value) |
215 | return GNUNET_TIME_relative_get_zero (); | 221 | return GNUNET_TIME_relative_get_zero (); |
216 | ret.rel_value = future.abs_value - now.abs_value; | 222 | ret.rel_value = future.abs_value - now.abs_value; |
@@ -229,6 +235,7 @@ GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, | |||
229 | struct GNUNET_TIME_Absolute end) | 235 | struct GNUNET_TIME_Absolute end) |
230 | { | 236 | { |
231 | struct GNUNET_TIME_Relative ret; | 237 | struct GNUNET_TIME_Relative ret; |
238 | |||
232 | if (end.abs_value == UINT64_MAX) | 239 | if (end.abs_value == UINT64_MAX) |
233 | return GNUNET_TIME_relative_get_forever (); | 240 | return GNUNET_TIME_relative_get_forever (); |
234 | if (end.abs_value < start.abs_value) | 241 | if (end.abs_value < start.abs_value) |
@@ -270,14 +277,13 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, | |||
270 | { | 277 | { |
271 | struct GNUNET_TIME_Absolute ret; | 278 | struct GNUNET_TIME_Absolute ret; |
272 | 279 | ||
273 | if ((start.abs_value == UINT64_MAX) || | 280 | if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX)) |
274 | (duration.rel_value == UINT64_MAX)) | ||
275 | return GNUNET_TIME_absolute_get_forever (); | 281 | return GNUNET_TIME_absolute_get_forever (); |
276 | if (start.abs_value + duration.rel_value < start.abs_value) | 282 | if (start.abs_value + duration.rel_value < start.abs_value) |
277 | { | 283 | { |
278 | GNUNET_break (0); | 284 | GNUNET_break (0); |
279 | return GNUNET_TIME_absolute_get_forever (); | 285 | return GNUNET_TIME_absolute_get_forever (); |
280 | } | 286 | } |
281 | ret.abs_value = start.abs_value + duration.rel_value; | 287 | ret.abs_value = start.abs_value + duration.rel_value; |
282 | return ret; | 288 | return ret; |
283 | } | 289 | } |
@@ -291,15 +297,13 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, | |||
291 | * @param duration some relative time to subtract | 297 | * @param duration some relative time to subtract |
292 | * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise | 298 | * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise |
293 | */ | 299 | */ |
294 | struct GNUNET_TIME_Absolute | 300 | struct GNUNET_TIME_Absolute |
295 | GNUNET_TIME_absolute_subtract (struct | 301 | GNUNET_TIME_absolute_subtract (struct |
296 | GNUNET_TIME_Absolute | 302 | GNUNET_TIME_Absolute |
297 | start, | 303 | start, struct GNUNET_TIME_Relative duration) |
298 | struct | ||
299 | GNUNET_TIME_Relative | ||
300 | duration) | ||
301 | { | 304 | { |
302 | struct GNUNET_TIME_Absolute ret; | 305 | struct GNUNET_TIME_Absolute ret; |
306 | |||
303 | if (start.abs_value <= duration.rel_value) | 307 | if (start.abs_value <= duration.rel_value) |
304 | return GNUNET_TIME_UNIT_ZERO_ABS; | 308 | return GNUNET_TIME_UNIT_ZERO_ABS; |
305 | if (start.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | 309 | if (start.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) |
@@ -319,14 +323,15 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
319 | unsigned int factor) | 323 | unsigned int factor) |
320 | { | 324 | { |
321 | struct GNUNET_TIME_Relative ret; | 325 | struct GNUNET_TIME_Relative ret; |
326 | |||
322 | if (factor == 0) | 327 | if (factor == 0) |
323 | return GNUNET_TIME_relative_get_zero (); | 328 | return GNUNET_TIME_relative_get_zero (); |
324 | ret.rel_value = rel.rel_value * (unsigned long long) factor; | 329 | ret.rel_value = rel.rel_value * (unsigned long long) factor; |
325 | if (ret.rel_value / factor != rel.rel_value) | 330 | if (ret.rel_value / factor != rel.rel_value) |
326 | { | 331 | { |
327 | GNUNET_break (0); | 332 | GNUNET_break (0); |
328 | return GNUNET_TIME_relative_get_forever (); | 333 | return GNUNET_TIME_relative_get_forever (); |
329 | } | 334 | } |
330 | return ret; | 335 | return ret; |
331 | } | 336 | } |
332 | 337 | ||
@@ -340,11 +345,12 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
340 | */ | 345 | */ |
341 | struct GNUNET_TIME_Relative | 346 | struct GNUNET_TIME_Relative |
342 | GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, | 347 | GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, |
343 | unsigned int factor) | 348 | unsigned int factor) |
344 | { | 349 | { |
345 | struct GNUNET_TIME_Relative ret; | 350 | struct GNUNET_TIME_Relative ret; |
346 | if ( (factor == 0) || | 351 | |
347 | (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value) ) | 352 | if ((factor == 0) || |
353 | (rel.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)) | ||
348 | return GNUNET_TIME_UNIT_FOREVER_REL; | 354 | return GNUNET_TIME_UNIT_FOREVER_REL; |
349 | ret.rel_value = rel.rel_value / (unsigned long long) factor; | 355 | ret.rel_value = rel.rel_value / (unsigned long long) factor; |
350 | return ret; | 356 | return ret; |
@@ -397,10 +403,10 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, | |||
397 | if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX)) | 403 | if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX)) |
398 | return GNUNET_TIME_relative_get_forever (); | 404 | return GNUNET_TIME_relative_get_forever (); |
399 | if (a1.rel_value + a2.rel_value < a1.rel_value) | 405 | if (a1.rel_value + a2.rel_value < a1.rel_value) |
400 | { | 406 | { |
401 | GNUNET_break (0); | 407 | GNUNET_break (0); |
402 | return GNUNET_TIME_relative_get_forever (); | 408 | return GNUNET_TIME_relative_get_forever (); |
403 | } | 409 | } |
404 | ret.rel_value = a1.rel_value + a2.rel_value; | 410 | ret.rel_value = a1.rel_value + a2.rel_value; |
405 | return ret; | 411 | return ret; |
406 | } | 412 | } |
@@ -415,13 +421,13 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, | |||
415 | */ | 421 | */ |
416 | struct GNUNET_TIME_Relative | 422 | struct GNUNET_TIME_Relative |
417 | GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, | 423 | GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, |
418 | struct GNUNET_TIME_Relative a2) | 424 | struct GNUNET_TIME_Relative a2) |
419 | { | 425 | { |
420 | struct GNUNET_TIME_Relative ret; | 426 | struct GNUNET_TIME_Relative ret; |
421 | 427 | ||
422 | if (a2.rel_value >= a1.rel_value) | 428 | if (a2.rel_value >= a1.rel_value) |
423 | return GNUNET_TIME_relative_get_zero (); | 429 | return GNUNET_TIME_relative_get_zero (); |
424 | if (a1.rel_value == UINT64_MAX) | 430 | if (a1.rel_value == UINT64_MAX) |
425 | return GNUNET_TIME_relative_get_forever (); | 431 | return GNUNET_TIME_relative_get_forever (); |
426 | ret.rel_value = a1.rel_value - a2.rel_value; | 432 | ret.rel_value = a1.rel_value - a2.rel_value; |
427 | return ret; | 433 | return ret; |
@@ -438,6 +444,7 @@ struct GNUNET_TIME_RelativeNBO | |||
438 | GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a) | 444 | GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a) |
439 | { | 445 | { |
440 | struct GNUNET_TIME_RelativeNBO ret; | 446 | struct GNUNET_TIME_RelativeNBO ret; |
447 | |||
441 | ret.rel_value__ = GNUNET_htonll (a.rel_value); | 448 | ret.rel_value__ = GNUNET_htonll (a.rel_value); |
442 | return ret; | 449 | return ret; |
443 | } | 450 | } |
@@ -452,6 +459,7 @@ struct GNUNET_TIME_Relative | |||
452 | GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a) | 459 | GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a) |
453 | { | 460 | { |
454 | struct GNUNET_TIME_Relative ret; | 461 | struct GNUNET_TIME_Relative ret; |
462 | |||
455 | ret.rel_value = GNUNET_ntohll (a.rel_value__); | 463 | ret.rel_value = GNUNET_ntohll (a.rel_value__); |
456 | return ret; | 464 | return ret; |
457 | 465 | ||
@@ -467,6 +475,7 @@ struct GNUNET_TIME_AbsoluteNBO | |||
467 | GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a) | 475 | GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a) |
468 | { | 476 | { |
469 | struct GNUNET_TIME_AbsoluteNBO ret; | 477 | struct GNUNET_TIME_AbsoluteNBO ret; |
478 | |||
470 | ret.abs_value__ = GNUNET_htonll (a.abs_value); | 479 | ret.abs_value__ = GNUNET_htonll (a.abs_value); |
471 | return ret; | 480 | return ret; |
472 | } | 481 | } |
@@ -481,6 +490,7 @@ struct GNUNET_TIME_Absolute | |||
481 | GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a) | 490 | GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a) |
482 | { | 491 | { |
483 | struct GNUNET_TIME_Absolute ret; | 492 | struct GNUNET_TIME_Absolute ret; |
493 | |||
484 | ret.abs_value = GNUNET_ntohll (a.abs_value__); | 494 | ret.abs_value = GNUNET_ntohll (a.abs_value__); |
485 | return ret; | 495 | return ret; |
486 | 496 | ||
@@ -499,9 +509,10 @@ const char * | |||
499 | GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time) | 509 | GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time) |
500 | { | 510 | { |
501 | static char time_string[21]; | 511 | static char time_string[21]; |
502 | memset(time_string, 0, sizeof(time_string)); | ||
503 | 512 | ||
504 | sprintf(time_string, "%llu", (unsigned long long) time.rel_value); | 513 | memset (time_string, 0, sizeof (time_string)); |
514 | |||
515 | sprintf (time_string, "%llu", (unsigned long long) time.rel_value); | ||
505 | return (const char *) time_string; | 516 | return (const char *) time_string; |
506 | } | 517 | } |
507 | 518 | ||
diff --git a/src/util/winproc.c b/src/util/winproc.c index 2df638362..4fa3ab484 100644 --- a/src/util/winproc.c +++ b/src/util/winproc.c | |||
@@ -99,130 +99,130 @@ GNInitWinEnv () | |||
99 | 99 | ||
100 | /* Function to get CPU usage under Win NT */ | 100 | /* Function to get CPU usage under Win NT */ |
101 | if (hNTDLL) | 101 | if (hNTDLL) |
102 | { | 102 | { |
103 | GNNtQuerySystemInformation = (TNtQuerySystemInformation) | 103 | GNNtQuerySystemInformation = (TNtQuerySystemInformation) |
104 | GetProcAddress (hNTDLL, "NtQuerySystemInformation"); | 104 | GetProcAddress (hNTDLL, "NtQuerySystemInformation"); |
105 | } | 105 | } |
106 | else | 106 | else |
107 | { | 107 | { |
108 | GNNtQuerySystemInformation = NULL; | 108 | GNNtQuerySystemInformation = NULL; |
109 | } | 109 | } |
110 | 110 | ||
111 | /* Functions to get information about a network adapter */ | 111 | /* Functions to get information about a network adapter */ |
112 | hIphlpapi = LoadLibrary ("iphlpapi.dll"); | 112 | hIphlpapi = LoadLibrary ("iphlpapi.dll"); |
113 | if (hIphlpapi) | 113 | if (hIphlpapi) |
114 | { | 114 | { |
115 | GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); | 115 | GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); |
116 | GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi, | 116 | GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi, |
117 | "GetIpAddrTable"); | 117 | "GetIpAddrTable"); |
118 | GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); | 118 | GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); |
119 | GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi, | 119 | GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi, |
120 | "GetBestInterface"); | 120 | "GetBestInterface"); |
121 | GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi, | 121 | GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi, |
122 | "GetAdaptersInfo"); | 122 | "GetAdaptersInfo"); |
123 | } | 123 | } |
124 | else | 124 | else |
125 | { | 125 | { |
126 | GNGetIfEntry = NULL; | 126 | GNGetIfEntry = NULL; |
127 | GNGetIpAddrTable = NULL; | 127 | GNGetIpAddrTable = NULL; |
128 | GNGetIfTable = NULL; | 128 | GNGetIfTable = NULL; |
129 | GNGetBestInterface = NULL; | 129 | GNGetBestInterface = NULL; |
130 | GGetAdaptersInfo = NULL; | 130 | GGetAdaptersInfo = NULL; |
131 | } | 131 | } |
132 | 132 | ||
133 | /* Service & Account functions */ | 133 | /* Service & Account functions */ |
134 | hAdvapi = LoadLibrary ("advapi32.dll"); | 134 | hAdvapi = LoadLibrary ("advapi32.dll"); |
135 | if (hAdvapi) | 135 | if (hAdvapi) |
136 | { | 136 | { |
137 | GNOpenSCManager = (TOpenSCManager) | 137 | GNOpenSCManager = (TOpenSCManager) |
138 | GetProcAddress (hAdvapi, "OpenSCManagerA"); | 138 | GetProcAddress (hAdvapi, "OpenSCManagerA"); |
139 | GNCreateService = (TCreateService) | 139 | GNCreateService = (TCreateService) |
140 | GetProcAddress (hAdvapi, "CreateServiceA"); | 140 | GetProcAddress (hAdvapi, "CreateServiceA"); |
141 | GNCloseServiceHandle = (TCloseServiceHandle) | 141 | GNCloseServiceHandle = (TCloseServiceHandle) |
142 | GetProcAddress (hAdvapi, "CloseServiceHandle"); | 142 | GetProcAddress (hAdvapi, "CloseServiceHandle"); |
143 | GNDeleteService = (TDeleteService) | 143 | GNDeleteService = (TDeleteService) |
144 | GetProcAddress (hAdvapi, "DeleteService"); | 144 | GetProcAddress (hAdvapi, "DeleteService"); |
145 | GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler) | 145 | GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler) |
146 | GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA"); | 146 | GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA"); |
147 | GNSetServiceStatus = (TSetServiceStatus) | 147 | GNSetServiceStatus = (TSetServiceStatus) |
148 | GetProcAddress (hAdvapi, "SetServiceStatus"); | 148 | GetProcAddress (hAdvapi, "SetServiceStatus"); |
149 | GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher) | 149 | GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher) |
150 | GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA"); | 150 | GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA"); |
151 | GNControlService = (TControlService) | 151 | GNControlService = (TControlService) |
152 | GetProcAddress (hAdvapi, "ControlService"); | 152 | GetProcAddress (hAdvapi, "ControlService"); |
153 | GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); | 153 | GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); |
154 | 154 | ||
155 | GNLsaOpenPolicy = (TLsaOpenPolicy) | 155 | GNLsaOpenPolicy = (TLsaOpenPolicy) |
156 | GetProcAddress (hAdvapi, "LsaOpenPolicy"); | 156 | GetProcAddress (hAdvapi, "LsaOpenPolicy"); |
157 | GNLsaAddAccountRights = (TLsaAddAccountRights) | 157 | GNLsaAddAccountRights = (TLsaAddAccountRights) |
158 | GetProcAddress (hAdvapi, "LsaAddAccountRights"); | 158 | GetProcAddress (hAdvapi, "LsaAddAccountRights"); |
159 | GNLsaRemoveAccountRights = (TLsaRemoveAccountRights) | 159 | GNLsaRemoveAccountRights = (TLsaRemoveAccountRights) |
160 | GetProcAddress (hAdvapi, "LsaRemoveAccountRights"); | 160 | GetProcAddress (hAdvapi, "LsaRemoveAccountRights"); |
161 | GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); | 161 | GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); |
162 | GNLookupAccountName = (TLookupAccountName) | 162 | GNLookupAccountName = (TLookupAccountName) |
163 | GetProcAddress (hAdvapi, "LookupAccountNameA"); | 163 | GetProcAddress (hAdvapi, "LookupAccountNameA"); |
164 | 164 | ||
165 | GNGetFileSecurity = (TGetFileSecurity) | 165 | GNGetFileSecurity = (TGetFileSecurity) |
166 | GetProcAddress (hAdvapi, "GetFileSecurityA"); | 166 | GetProcAddress (hAdvapi, "GetFileSecurityA"); |
167 | GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor) | 167 | GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor) |
168 | GetProcAddress (hAdvapi, "InitializeSecurityDescriptor"); | 168 | GetProcAddress (hAdvapi, "InitializeSecurityDescriptor"); |
169 | GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl) | 169 | GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl) |
170 | GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl"); | 170 | GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl"); |
171 | GNGetAclInformation = (TGetAclInformation) | 171 | GNGetAclInformation = (TGetAclInformation) |
172 | GetProcAddress (hAdvapi, "GetAclInformation"); | 172 | GetProcAddress (hAdvapi, "GetAclInformation"); |
173 | GNInitializeAcl = (TInitializeAcl) | 173 | GNInitializeAcl = (TInitializeAcl) |
174 | GetProcAddress (hAdvapi, "InitializeAcl"); | 174 | GetProcAddress (hAdvapi, "InitializeAcl"); |
175 | GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); | 175 | GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); |
176 | GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); | 176 | GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); |
177 | GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); | 177 | GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); |
178 | GNAddAccessAllowedAce = (TAddAccessAllowedAce) | 178 | GNAddAccessAllowedAce = (TAddAccessAllowedAce) |
179 | GetProcAddress (hAdvapi, "AddAccessAllowedAce"); | 179 | GetProcAddress (hAdvapi, "AddAccessAllowedAce"); |
180 | GNSetNamedSecurityInfo = (TSetNamedSecurityInfo) | 180 | GNSetNamedSecurityInfo = (TSetNamedSecurityInfo) |
181 | GetProcAddress (hAdvapi, "SetNamedSecurityInfoA"); | 181 | GetProcAddress (hAdvapi, "SetNamedSecurityInfoA"); |
182 | } | 182 | } |
183 | else | 183 | else |
184 | { | 184 | { |
185 | GNOpenSCManager = NULL; | 185 | GNOpenSCManager = NULL; |
186 | GNCreateService = NULL; | 186 | GNCreateService = NULL; |
187 | GNCloseServiceHandle = NULL; | 187 | GNCloseServiceHandle = NULL; |
188 | GNDeleteService = NULL; | 188 | GNDeleteService = NULL; |
189 | GNRegisterServiceCtrlHandler = NULL; | 189 | GNRegisterServiceCtrlHandler = NULL; |
190 | GNSetServiceStatus = NULL; | 190 | GNSetServiceStatus = NULL; |
191 | GNStartServiceCtrlDispatcher = NULL; | 191 | GNStartServiceCtrlDispatcher = NULL; |
192 | GNControlService = NULL; | 192 | GNControlService = NULL; |
193 | GNOpenService = NULL; | 193 | GNOpenService = NULL; |
194 | 194 | ||
195 | GNLsaOpenPolicy = NULL; | 195 | GNLsaOpenPolicy = NULL; |
196 | GNLsaAddAccountRights = NULL; | 196 | GNLsaAddAccountRights = NULL; |
197 | GNLsaRemoveAccountRights = NULL; | 197 | GNLsaRemoveAccountRights = NULL; |
198 | GNLsaClose = NULL; | 198 | GNLsaClose = NULL; |
199 | GNLookupAccountName = NULL; | 199 | GNLookupAccountName = NULL; |
200 | 200 | ||
201 | GNGetFileSecurity = NULL; | 201 | GNGetFileSecurity = NULL; |
202 | GNInitializeSecurityDescriptor = NULL; | 202 | GNInitializeSecurityDescriptor = NULL; |
203 | GNGetSecurityDescriptorDacl = NULL; | 203 | GNGetSecurityDescriptorDacl = NULL; |
204 | GNGetAclInformation = NULL; | 204 | GNGetAclInformation = NULL; |
205 | GNInitializeAcl = NULL; | 205 | GNInitializeAcl = NULL; |
206 | GNGetAce = NULL; | 206 | GNGetAce = NULL; |
207 | GNEqualSid = NULL; | 207 | GNEqualSid = NULL; |
208 | GNAddAce = NULL; | 208 | GNAddAce = NULL; |
209 | GNAddAccessAllowedAce = NULL; | 209 | GNAddAccessAllowedAce = NULL; |
210 | GNSetNamedSecurityInfo = NULL; | 210 | GNSetNamedSecurityInfo = NULL; |
211 | } | 211 | } |
212 | 212 | ||
213 | /* Account function */ | 213 | /* Account function */ |
214 | hNetapi = LoadLibrary ("netapi32.dll"); | 214 | hNetapi = LoadLibrary ("netapi32.dll"); |
215 | if (hNetapi) | 215 | if (hNetapi) |
216 | { | 216 | { |
217 | GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); | 217 | GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); |
218 | GNNetUserSetInfo = (TNetUserSetInfo) | 218 | GNNetUserSetInfo = (TNetUserSetInfo) |
219 | GetProcAddress (hNetapi, "NetUserSetInfo"); | 219 | GetProcAddress (hNetapi, "NetUserSetInfo"); |
220 | } | 220 | } |
221 | else | 221 | else |
222 | { | 222 | { |
223 | GNNetUserAdd = NULL; | 223 | GNNetUserAdd = NULL; |
224 | GNNetUserSetInfo = NULL; | 224 | GNNetUserSetInfo = NULL; |
225 | } | 225 | } |
226 | 226 | ||
227 | return ret; | 227 | return ret; |
228 | } | 228 | } |