diff options
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r-- | src/fs/fs_uri.c | 1357 |
1 files changed, 658 insertions, 699 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 4b249d6bf..5d5d24ca8 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -91,33 +91,33 @@ | |||
91 | * @param uri uri to convert to a unique key | 91 | * @param uri uri to convert to a unique key |
92 | * @param key wherer to store the unique key | 92 | * @param key wherer to store the unique key |
93 | */ | 93 | */ |
94 | void | 94 | void |
95 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | 95 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key) |
96 | GNUNET_HashCode * key) | ||
97 | { | 96 | { |
98 | switch (uri->type) | 97 | switch (uri->type) |
99 | { | 98 | { |
100 | case chk: | 99 | case chk: |
101 | *key = uri->data.chk.chk.query; | 100 | *key = uri->data.chk.chk.query; |
102 | return; | 101 | return; |
103 | case sks: | 102 | case sks: |
104 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, | 103 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, |
105 | strlen (uri->data.sks.identifier), key); | 104 | strlen (uri->data.sks.identifier), key); |
106 | break; | 105 | break; |
107 | case ksk: | 106 | case ksk: |
108 | if (uri->data.ksk.keywordCount > 0) | 107 | if (uri->data.ksk.keywordCount > 0) |
109 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], | 108 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], |
110 | strlen (uri->data.ksk.keywords[0]), key); | 109 | strlen (uri->data.ksk.keywords[0]), key); |
111 | break; | 110 | break; |
112 | case loc: | 111 | case loc: |
113 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, | 112 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, |
114 | sizeof (struct FileIdentifier) + | 113 | sizeof (struct FileIdentifier) + |
115 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), key); | 114 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
116 | break; | 115 | key); |
117 | default: | 116 | break; |
118 | memset (key, 0, sizeof (GNUNET_HashCode)); | 117 | default: |
119 | break; | 118 | memset (key, 0, sizeof (GNUNET_HashCode)); |
120 | } | 119 | break; |
120 | } | ||
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
@@ -139,45 +139,45 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) | |||
139 | unsigned int keywordCount; | 139 | unsigned int keywordCount; |
140 | 140 | ||
141 | if ((uri == NULL) || (uri->type != ksk)) | 141 | if ((uri == NULL) || (uri->type != ksk)) |
142 | { | 142 | { |
143 | GNUNET_break (0); | 143 | GNUNET_break (0); |
144 | return NULL; | 144 | return NULL; |
145 | } | 145 | } |
146 | keywords = uri->data.ksk.keywords; | 146 | keywords = uri->data.ksk.keywords; |
147 | keywordCount = uri->data.ksk.keywordCount; | 147 | keywordCount = uri->data.ksk.keywordCount; |
148 | n = keywordCount + 1; | 148 | n = keywordCount + 1; |
149 | for (i = 0; i < keywordCount; i++) | 149 | for (i = 0; i < keywordCount; i++) |
150 | { | 150 | { |
151 | keyword = keywords[i]; | 151 | keyword = keywords[i]; |
152 | n += strlen (keyword) - 1; | 152 | n += strlen (keyword) - 1; |
153 | if (NULL != strstr (&keyword[1], " ")) | 153 | if (NULL != strstr (&keyword[1], " ")) |
154 | n += 2; | 154 | n += 2; |
155 | if (keyword[0] == '+') | 155 | if (keyword[0] == '+') |
156 | n++; | 156 | n++; |
157 | } | 157 | } |
158 | ret = GNUNET_malloc (n); | 158 | ret = GNUNET_malloc (n); |
159 | strcpy (ret, ""); | 159 | strcpy (ret, ""); |
160 | for (i = 0; i < keywordCount; i++) | 160 | for (i = 0; i < keywordCount; i++) |
161 | { | ||
162 | keyword = keywords[i]; | ||
163 | if (NULL != strstr (&keyword[1], " ")) | ||
161 | { | 164 | { |
162 | keyword = keywords[i]; | 165 | strcat (ret, "\""); |
163 | if (NULL != strstr (&keyword[1], " ")) | 166 | if (keyword[0] == '+') |
164 | { | 167 | strcat (ret, keyword); |
165 | strcat (ret, "\""); | ||
166 | if (keyword[0] == '+') | ||
167 | strcat (ret, keyword); | ||
168 | else | ||
169 | strcat (ret, &keyword[1]); | ||
170 | strcat (ret, "\""); | ||
171 | } | ||
172 | else | 168 | else |
173 | { | 169 | strcat (ret, &keyword[1]); |
174 | if (keyword[0] == '+') | 170 | strcat (ret, "\""); |
175 | strcat (ret, keyword); | ||
176 | else | ||
177 | strcat (ret, &keyword[1]); | ||
178 | } | ||
179 | strcat (ret, " "); | ||
180 | } | 171 | } |
172 | else | ||
173 | { | ||
174 | if (keyword[0] == '+') | ||
175 | strcat (ret, keyword); | ||
176 | else | ||
177 | strcat (ret, &keyword[1]); | ||
178 | } | ||
179 | strcat (ret, " "); | ||
180 | } | ||
181 | return ret; | 181 | return ret; |
182 | } | 182 | } |
183 | 183 | ||
@@ -205,37 +205,37 @@ percent_decode_keyword (const char *in, char **emsg) | |||
205 | rpos = 0; | 205 | rpos = 0; |
206 | wpos = 0; | 206 | wpos = 0; |
207 | while (out[rpos] != '\0') | 207 | while (out[rpos] != '\0') |
208 | { | ||
209 | if (out[rpos] == '%') | ||
208 | { | 210 | { |
209 | if (out[rpos] == '%') | 211 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) |
210 | { | 212 | { |
211 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) | 213 | GNUNET_free (out); |
212 | { | 214 | *emsg = GNUNET_strdup (_("`%' must be followed by HEX number")); |
213 | GNUNET_free (out); | 215 | return NULL; |
214 | *emsg = GNUNET_strdup (_("`%' must be followed by HEX number")); | 216 | } |
215 | return NULL; | 217 | rpos += 3; |
216 | } | 218 | if (hx == '"') |
217 | rpos += 3; | 219 | continue; /* skip double quote */ |
218 | if (hx == '"') | 220 | out[wpos++] = (char) hx; |
219 | continue; /* skip double quote */ | ||
220 | out[wpos++] = (char) hx; | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | out[wpos++] = out[rpos++]; | ||
225 | } | ||
226 | } | 221 | } |
227 | out[wpos] = '\0'; | 222 | else |
228 | if (out[0] == '+') | ||
229 | { | 223 | { |
230 | ret = GNUNET_strdup (out); | 224 | out[wpos++] = out[rpos++]; |
231 | } | 225 | } |
226 | } | ||
227 | out[wpos] = '\0'; | ||
228 | if (out[0] == '+') | ||
229 | { | ||
230 | ret = GNUNET_strdup (out); | ||
231 | } | ||
232 | else | 232 | else |
233 | { | 233 | { |
234 | /* need to prefix with space */ | 234 | /* need to prefix with space */ |
235 | ret = GNUNET_malloc (strlen (out) + 2); | 235 | ret = GNUNET_malloc (strlen (out) + 2); |
236 | strcpy (ret, " "); | 236 | strcpy (ret, " "); |
237 | strcat (ret, out); | 237 | strcat (ret, out); |
238 | } | 238 | } |
239 | GNUNET_free (out); | 239 | GNUNET_free (out); |
240 | return ret; | 240 | return ret; |
241 | } | 241 | } |
@@ -265,66 +265,64 @@ uri_ksk_parse (const char *s, char **emsg) | |||
265 | GNUNET_assert (s != NULL); | 265 | GNUNET_assert (s != NULL); |
266 | slen = strlen (s); | 266 | slen = strlen (s); |
267 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); | 267 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); |
268 | if ( (slen <= pos) || | 268 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) |
269 | (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, | 269 | return NULL; /* not KSK URI */ |
270 | pos) ) ) | 270 | if ((s[slen - 1] == '+') || (s[pos] == '+')) |
271 | return NULL; /* not KSK URI */ | 271 | { |
272 | if ( (s[slen - 1] == '+') || | 272 | *emsg = |
273 | (s[pos] == '+') ) | 273 | GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); |
274 | { | 274 | return NULL; |
275 | *emsg = GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); | 275 | } |
276 | return NULL; | ||
277 | } | ||
278 | max = 1; | 276 | max = 1; |
279 | saw_quote = 0; | 277 | saw_quote = 0; |
280 | for (i = pos; i < slen; i++) | 278 | for (i = pos; i < slen; i++) |
279 | { | ||
280 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
281 | { | 281 | { |
282 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | 282 | saw_quote = (saw_quote + 1) % 2; |
283 | { | 283 | i += 3; |
284 | saw_quote = (saw_quote + 1) % 2; | 284 | continue; |
285 | i += 3; | ||
286 | continue; | ||
287 | } | ||
288 | if ((s[i] == '+') && (saw_quote == 0)) | ||
289 | { | ||
290 | max++; | ||
291 | if (s[i - 1] == '+') | ||
292 | { | ||
293 | *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI")); | ||
294 | return NULL; | ||
295 | } | ||
296 | } | ||
297 | } | 285 | } |
298 | if (saw_quote == 1) | 286 | if ((s[i] == '+') && (saw_quote == 0)) |
299 | { | 287 | { |
300 | *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI")); | 288 | max++; |
301 | return NULL; | 289 | if (s[i - 1] == '+') |
290 | { | ||
291 | *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI")); | ||
292 | return NULL; | ||
293 | } | ||
302 | } | 294 | } |
295 | } | ||
296 | if (saw_quote == 1) | ||
297 | { | ||
298 | *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI")); | ||
299 | return NULL; | ||
300 | } | ||
303 | iret = max; | 301 | iret = max; |
304 | dup = GNUNET_strdup (s); | 302 | dup = GNUNET_strdup (s); |
305 | keywords = GNUNET_malloc (max * sizeof (char *)); | 303 | keywords = GNUNET_malloc (max * sizeof (char *)); |
306 | for (i = slen - 1; i >= pos; i--) | 304 | for (i = slen - 1; i >= pos; i--) |
305 | { | ||
306 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
307 | { | 307 | { |
308 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | 308 | saw_quote = (saw_quote + 1) % 2; |
309 | { | 309 | i += 3; |
310 | saw_quote = (saw_quote + 1) % 2; | 310 | continue; |
311 | i += 3; | 311 | } |
312 | continue; | 312 | if ((dup[i] == '+') && (saw_quote == 0)) |
313 | } | 313 | { |
314 | if ((dup[i] == '+') && (saw_quote == 0)) | 314 | keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); |
315 | { | 315 | if (NULL == keywords[max]) |
316 | keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); | 316 | goto CLEANUP; |
317 | if (NULL == keywords[max]) | 317 | dup[i] = '\0'; |
318 | goto CLEANUP; | ||
319 | dup[i] = '\0'; | ||
320 | } | ||
321 | } | 318 | } |
319 | } | ||
322 | keywords[--max] = percent_decode_keyword (&dup[pos], emsg); | 320 | keywords[--max] = percent_decode_keyword (&dup[pos], emsg); |
323 | if (NULL == keywords[max]) | 321 | if (NULL == keywords[max]) |
324 | goto CLEANUP; | 322 | goto CLEANUP; |
325 | GNUNET_assert (max == 0); | 323 | GNUNET_assert (max == 0); |
326 | GNUNET_free (dup); | 324 | GNUNET_free (dup); |
327 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | 325 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
328 | ret->type = ksk; | 326 | ret->type = ksk; |
329 | ret->data.ksk.keywordCount = iret; | 327 | ret->data.ksk.keywordCount = iret; |
330 | ret->data.ksk.keywords = keywords; | 328 | ret->data.ksk.keywords = keywords; |
@@ -355,30 +353,29 @@ uri_sks_parse (const char *s, char **emsg) | |||
355 | char *identifier; | 353 | char *identifier; |
356 | unsigned int pos; | 354 | unsigned int pos; |
357 | size_t slen; | 355 | size_t slen; |
358 | char enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 356 | char enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
359 | 357 | ||
360 | GNUNET_assert (s != NULL); | 358 | GNUNET_assert (s != NULL); |
361 | slen = strlen (s); | 359 | slen = strlen (s); |
362 | pos = strlen ( GNUNET_FS_URI_SKS_PREFIX); | 360 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); |
363 | if ( (slen <= pos) || | 361 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) |
364 | (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, | 362 | return NULL; /* not an SKS URI */ |
365 | pos) ) ) | 363 | if ((slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) || |
366 | return NULL; /* not an SKS URI */ | 364 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/')) |
367 | if ( (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) || | 365 | { |
368 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/') ) | 366 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); |
369 | { | 367 | return NULL; |
370 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); | 368 | } |
371 | return NULL; | 369 | memcpy (enc, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
372 | } | 370 | enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
373 | memcpy (enc, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
374 | enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
375 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace)) | 371 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace)) |
376 | { | 372 | { |
377 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); | 373 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); |
378 | return NULL; | 374 | return NULL; |
379 | } | 375 | } |
380 | identifier = GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]); | 376 | identifier = |
381 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | 377 | GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]); |
378 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | ||
382 | ret->type = sks; | 379 | ret->type = sks; |
383 | ret->data.sks.namespace = namespace; | 380 | ret->data.sks.namespace = namespace; |
384 | ret->data.sks.identifier = identifier; | 381 | ret->data.sks.identifier = identifier; |
@@ -403,46 +400,43 @@ uri_chk_parse (const char *s, char **emsg) | |||
403 | unsigned int pos; | 400 | unsigned int pos; |
404 | unsigned long long flen; | 401 | unsigned long long flen; |
405 | size_t slen; | 402 | size_t slen; |
406 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 403 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
407 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 404 | char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
408 | 405 | ||
409 | if (NULL == s) | 406 | if (NULL == s) |
410 | return NULL; | 407 | return NULL; |
411 | GNUNET_assert (s != NULL); | 408 | GNUNET_assert (s != NULL); |
412 | slen = strlen (s); | 409 | slen = strlen (s); |
413 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); | 410 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); |
414 | if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 411 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
415 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, | 412 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) |
416 | pos) ) ) | 413 | return NULL; /* not a CHK URI */ |
417 | return NULL; /* not a CHK URI */ | 414 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
418 | if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 415 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
419 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.') ) | 416 | { |
420 | { | 417 | *emsg = GNUNET_strdup (_("Malformed CHK URI")); |
421 | *emsg = GNUNET_strdup (_("Malformed CHK URI")); | 418 | return NULL; |
422 | return NULL; | 419 | } |
423 | } | 420 | memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
424 | memcpy (h1, | 421 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
425 | &s[pos], | ||
426 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
427 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
428 | memcpy (h2, | 422 | memcpy (h2, |
429 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], | 423 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
430 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | 424 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
431 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | 425 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
432 | 426 | ||
433 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, | 427 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, |
434 | &fi.chk.key)) || | 428 | &fi.chk.key)) || |
435 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, | 429 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, |
436 | &fi.chk.query)) || | 430 | &fi.chk.query)) || |
437 | (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 431 | (1 != |
438 | "%llu", | 432 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
439 | &flen)) ) | 433 | "%llu", &flen))) |
440 | { | 434 | { |
441 | *emsg = GNUNET_strdup (_("Malformed CHK URI")); | 435 | *emsg = GNUNET_strdup (_("Malformed CHK URI")); |
442 | return NULL; | 436 | return NULL; |
443 | } | 437 | } |
444 | fi.file_length = GNUNET_htonll (flen); | 438 | fi.file_length = GNUNET_htonll (flen); |
445 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | 439 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
446 | ret->type = chk; | 440 | ret->type = chk; |
447 | ret->data.chk = fi; | 441 | ret->data.chk = fi; |
448 | return ret; | 442 | return ret; |
@@ -499,16 +493,16 @@ enc2bin (const char *input, void *data, size_t size) | |||
499 | hbits = 0; | 493 | hbits = 0; |
500 | len = 0; | 494 | len = 0; |
501 | for (pos = 0; pos < size; pos++) | 495 | for (pos = 0; pos < size; pos++) |
496 | { | ||
497 | while (hbits < 8) | ||
502 | { | 498 | { |
503 | while (hbits < 8) | 499 | bits |= (c2v (input[len++]) << hbits); |
504 | { | 500 | hbits += 6; |
505 | bits |= (c2v (input[len++]) << hbits); | ||
506 | hbits += 6; | ||
507 | } | ||
508 | (((unsigned char *) data)[pos]) = (unsigned char) bits; | ||
509 | bits >>= 8; | ||
510 | hbits -= 8; | ||
511 | } | 501 | } |
502 | (((unsigned char *) data)[pos]) = (unsigned char) bits; | ||
503 | bits >>= 8; | ||
504 | hbits -= 8; | ||
505 | } | ||
512 | return len; | 506 | return len; |
513 | } | 507 | } |
514 | 508 | ||
@@ -520,14 +514,14 @@ enc2bin (const char *input, void *data, size_t size) | |||
520 | * verify the signature of a location | 514 | * verify the signature of a location |
521 | * URI. | 515 | * URI. |
522 | */ | 516 | */ |
523 | struct LocUriAssembly | 517 | struct LocUriAssembly |
524 | { | 518 | { |
525 | struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; | 519 | struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; |
526 | 520 | ||
527 | struct GNUNET_TIME_AbsoluteNBO exptime; | 521 | struct GNUNET_TIME_AbsoluteNBO exptime; |
528 | 522 | ||
529 | struct FileIdentifier fi; | 523 | struct FileIdentifier fi; |
530 | 524 | ||
531 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer; | 525 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer; |
532 | 526 | ||
533 | }; | 527 | }; |
@@ -547,8 +541,8 @@ static struct GNUNET_FS_Uri * | |||
547 | uri_loc_parse (const char *s, char **emsg) | 541 | uri_loc_parse (const char *s, char **emsg) |
548 | { | 542 | { |
549 | struct GNUNET_FS_Uri *uri; | 543 | struct GNUNET_FS_Uri *uri; |
550 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 544 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
551 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 545 | char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
552 | unsigned int pos; | 546 | unsigned int pos; |
553 | unsigned int npos; | 547 | unsigned int npos; |
554 | unsigned long long exptime; | 548 | unsigned long long exptime; |
@@ -561,95 +555,92 @@ uri_loc_parse (const char *s, char **emsg) | |||
561 | 555 | ||
562 | GNUNET_assert (s != NULL); | 556 | GNUNET_assert (s != NULL); |
563 | slen = strlen (s); | 557 | slen = strlen (s); |
564 | pos = strlen ( GNUNET_FS_URI_LOC_PREFIX); | 558 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); |
565 | if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 559 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
566 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, | 560 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) |
567 | pos) ) ) | 561 | return NULL; /* not an SKS URI */ |
568 | return NULL; /* not an SKS URI */ | 562 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
569 | if ( (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 563 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
570 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.') ) | 564 | { |
571 | { | 565 | *emsg = GNUNET_strdup (_("SKS URI malformed")); |
572 | *emsg = GNUNET_strdup (_("SKS URI malformed")); | 566 | return NULL; |
573 | return NULL; | 567 | } |
574 | } | 568 | memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
575 | memcpy (h1, | 569 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
576 | &s[pos], | ||
577 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
578 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
579 | memcpy (h2, | 570 | memcpy (h2, |
580 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], | 571 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
581 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | 572 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
582 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | 573 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
583 | 574 | ||
584 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, | 575 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, |
585 | &ass.fi.chk.key)) || | 576 | &ass.fi.chk.key)) || |
586 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, | 577 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, |
587 | &ass.fi.chk.query)) || | 578 | &ass.fi.chk.query)) || |
588 | (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 579 | (1 != |
589 | "%llu", | 580 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
590 | &flen)) ) | 581 | "%llu", &flen))) |
591 | { | 582 | { |
592 | *emsg = GNUNET_strdup (_("SKS URI malformed")); | 583 | *emsg = GNUNET_strdup (_("SKS URI malformed")); |
593 | return NULL; | 584 | return NULL; |
594 | } | 585 | } |
595 | ass.fi.file_length = GNUNET_htonll (flen); | 586 | ass.fi.file_length = GNUNET_htonll (flen); |
596 | 587 | ||
597 | npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; | 588 | npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; |
598 | while ((s[npos] != '\0') && (s[npos] != '.')) | 589 | while ((s[npos] != '\0') && (s[npos] != '.')) |
599 | npos++; | 590 | npos++; |
600 | if (s[npos] == '\0') | 591 | if (s[npos] == '\0') |
601 | { | 592 | { |
602 | *emsg = GNUNET_strdup (_("SKS URI malformed")); | 593 | *emsg = GNUNET_strdup (_("SKS URI malformed")); |
603 | goto ERR; | 594 | goto ERR; |
604 | } | 595 | } |
605 | npos++; | 596 | npos++; |
606 | ret = enc2bin (&s[npos], | 597 | ret = enc2bin (&s[npos], |
607 | &ass.peer, | 598 | &ass.peer, |
608 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 599 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
609 | if (ret == -1) | 600 | if (ret == -1) |
610 | { | 601 | { |
611 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode public key)")); | 602 | *emsg = |
612 | goto ERR; | 603 | GNUNET_strdup (_("SKS URI malformed (could not decode public key)")); |
613 | } | 604 | goto ERR; |
605 | } | ||
614 | npos += ret; | 606 | npos += ret; |
615 | if (s[npos++] != '.') | 607 | if (s[npos++] != '.') |
616 | { | 608 | { |
617 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)")); | 609 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)")); |
618 | goto ERR; | 610 | goto ERR; |
619 | } | 611 | } |
620 | ret = enc2bin (&s[npos], | 612 | ret = enc2bin (&s[npos], &sig, sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
621 | &sig, | ||
622 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
623 | if (ret == -1) | 613 | if (ret == -1) |
624 | { | 614 | { |
625 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)")); | 615 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)")); |
626 | goto ERR; | 616 | goto ERR; |
627 | } | 617 | } |
628 | npos += ret; | 618 | npos += ret; |
629 | if (s[npos++] != '.') | 619 | if (s[npos++] != '.') |
630 | { | 620 | { |
631 | *emsg = GNUNET_strdup (_("SKS URI malformed")); | 621 | *emsg = GNUNET_strdup (_("SKS URI malformed")); |
632 | goto ERR; | 622 | goto ERR; |
633 | } | 623 | } |
634 | if (1 != SSCANF (&s[npos], "%llu", &exptime)) | 624 | if (1 != SSCANF (&s[npos], "%llu", &exptime)) |
635 | { | 625 | { |
636 | *emsg = GNUNET_strdup (_("SKS URI malformed (could not parse expiration time)")); | 626 | *emsg = |
637 | goto ERR; | 627 | GNUNET_strdup (_ |
638 | } | 628 | ("SKS URI malformed (could not parse expiration time)")); |
639 | ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); | 629 | goto ERR; |
640 | ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 630 | } |
631 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | ||
632 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | ||
641 | et.abs_value = exptime; | 633 | et.abs_value = exptime; |
642 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 634 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
643 | if (GNUNET_OK != | 635 | if (GNUNET_OK != |
644 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, | 636 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, |
645 | &ass.purpose, | 637 | &ass.purpose, &sig, &ass.peer)) |
646 | &sig, | 638 | { |
647 | &ass.peer)) | 639 | *emsg = |
648 | { | 640 | GNUNET_strdup (_("SKS URI malformed (signature failed validation)")); |
649 | *emsg = GNUNET_strdup (_("SKS URI malformed (signature failed validation)")); | 641 | goto ERR; |
650 | goto ERR; | 642 | } |
651 | } | 643 | uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
652 | uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | ||
653 | uri->type = loc; | 644 | uri->type = loc; |
654 | uri->data.loc.fi = ass.fi; | 645 | uri->data.loc.fi = ass.fi; |
655 | uri->data.loc.peer = ass.peer; | 646 | uri->data.loc.peer = ass.peer; |
@@ -670,8 +661,7 @@ ERR: | |||
670 | * @return NULL on error | 661 | * @return NULL on error |
671 | */ | 662 | */ |
672 | struct GNUNET_FS_Uri * | 663 | struct GNUNET_FS_Uri * |
673 | GNUNET_FS_uri_parse (const char *uri, | 664 | GNUNET_FS_uri_parse (const char *uri, char **emsg) |
674 | char **emsg) | ||
675 | { | 665 | { |
676 | struct GNUNET_FS_Uri *ret; | 666 | struct GNUNET_FS_Uri *ret; |
677 | char *msg; | 667 | char *msg; |
@@ -679,10 +669,10 @@ GNUNET_FS_uri_parse (const char *uri, | |||
679 | if (NULL == emsg) | 669 | if (NULL == emsg) |
680 | emsg = &msg; | 670 | emsg = &msg; |
681 | *emsg = NULL; | 671 | *emsg = NULL; |
682 | if ( (NULL != (ret = uri_chk_parse (uri, emsg))) || | 672 | if ((NULL != (ret = uri_chk_parse (uri, emsg))) || |
683 | (NULL != (ret = uri_ksk_parse (uri, emsg))) || | 673 | (NULL != (ret = uri_ksk_parse (uri, emsg))) || |
684 | (NULL != (ret = uri_sks_parse (uri, emsg))) || | 674 | (NULL != (ret = uri_sks_parse (uri, emsg))) || |
685 | (NULL != (ret = uri_loc_parse (uri, emsg))) ) | 675 | (NULL != (ret = uri_loc_parse (uri, emsg)))) |
686 | return ret; | 676 | return ret; |
687 | if (NULL == *emsg) | 677 | if (NULL == *emsg) |
688 | *emsg = GNUNET_strdup (_("Unrecognized URI type")); | 678 | *emsg = GNUNET_strdup (_("Unrecognized URI type")); |
@@ -697,29 +687,28 @@ GNUNET_FS_uri_parse (const char *uri, | |||
697 | * | 687 | * |
698 | * @param uri uri to free | 688 | * @param uri uri to free |
699 | */ | 689 | */ |
700 | void | 690 | void |
701 | GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) | 691 | GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) |
702 | { | 692 | { |
703 | unsigned int i; | 693 | unsigned int i; |
704 | 694 | ||
705 | GNUNET_assert (uri != NULL); | 695 | GNUNET_assert (uri != NULL); |
706 | switch (uri->type) | 696 | switch (uri->type) |
707 | { | 697 | { |
708 | case ksk: | 698 | case ksk: |
709 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 699 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
710 | GNUNET_free (uri->data.ksk.keywords[i]); | 700 | GNUNET_free (uri->data.ksk.keywords[i]); |
711 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, | 701 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); |
712 | 0); | 702 | break; |
713 | break; | 703 | case sks: |
714 | case sks: | 704 | GNUNET_free (uri->data.sks.identifier); |
715 | GNUNET_free (uri->data.sks.identifier); | 705 | break; |
716 | break; | 706 | case loc: |
717 | case loc: | 707 | break; |
718 | break; | 708 | default: |
719 | default: | 709 | /* do nothing */ |
720 | /* do nothing */ | 710 | break; |
721 | break; | 711 | } |
722 | } | ||
723 | GNUNET_free (uri); | 712 | GNUNET_free (uri); |
724 | } | 713 | } |
725 | 714 | ||
@@ -729,7 +718,7 @@ GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) | |||
729 | * @param uri ksk uri to get the number of keywords from | 718 | * @param uri ksk uri to get the number of keywords from |
730 | * @return 0 if this is not a keyword URI | 719 | * @return 0 if this is not a keyword URI |
731 | */ | 720 | */ |
732 | unsigned int | 721 | unsigned int |
733 | GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) | 722 | GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) |
734 | { | 723 | { |
735 | if (uri->type != ksk) | 724 | if (uri->type != ksk) |
@@ -747,10 +736,10 @@ GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) | |||
747 | * @return -1 if this is not a keyword URI, otherwise number of | 736 | * @return -1 if this is not a keyword URI, otherwise number of |
748 | * keywords iterated over until iterator aborted | 737 | * keywords iterated over until iterator aborted |
749 | */ | 738 | */ |
750 | int | 739 | int |
751 | GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | 740 | GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, |
752 | GNUNET_FS_KeywordIterator iterator, | 741 | GNUNET_FS_KeywordIterator iterator, |
753 | void *iterator_cls) | 742 | void *iterator_cls) |
754 | { | 743 | { |
755 | unsigned int i; | 744 | unsigned int i; |
756 | char *keyword; | 745 | char *keyword; |
@@ -760,15 +749,13 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
760 | if (iterator == NULL) | 749 | if (iterator == NULL) |
761 | return uri->data.ksk.keywordCount; | 750 | return uri->data.ksk.keywordCount; |
762 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 751 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
763 | { | 752 | { |
764 | keyword = uri->data.ksk.keywords[i]; | 753 | keyword = uri->data.ksk.keywords[i]; |
765 | /* first character of keyword indicates | 754 | /* first character of keyword indicates |
766 | if it is mandatory or not */ | 755 | * if it is mandatory or not */ |
767 | if (GNUNET_OK != iterator (iterator_cls, | 756 | if (GNUNET_OK != iterator (iterator_cls, &keyword[1], keyword[0] == '+')) |
768 | &keyword[1], | 757 | return i; |
769 | keyword[0] == '+')) | 758 | } |
770 | return i; | ||
771 | } | ||
772 | return i; | 759 | return i; |
773 | } | 760 | } |
774 | 761 | ||
@@ -783,8 +770,7 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
783 | */ | 770 | */ |
784 | void | 771 | void |
785 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, | 772 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, |
786 | const char *keyword, | 773 | const char *keyword, int is_mandatory) |
787 | int is_mandatory) | ||
788 | { | 774 | { |
789 | unsigned int i; | 775 | unsigned int i; |
790 | const char *old; | 776 | const char *old; |
@@ -792,17 +778,13 @@ GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, | |||
792 | 778 | ||
793 | GNUNET_assert (uri->type == ksk); | 779 | GNUNET_assert (uri->type == ksk); |
794 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 780 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
795 | { | 781 | { |
796 | old = uri->data.ksk.keywords[i]; | 782 | old = uri->data.ksk.keywords[i]; |
797 | if (0 == strcmp (&old[1], keyword)) | 783 | if (0 == strcmp (&old[1], keyword)) |
798 | return; | 784 | return; |
799 | } | 785 | } |
800 | GNUNET_asprintf (&n, | 786 | GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword); |
801 | is_mandatory ? "+%s" : " %s", | 787 | GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); |
802 | keyword); | ||
803 | GNUNET_array_append (uri->data.ksk.keywords, | ||
804 | uri->data.ksk.keywordCount, | ||
805 | n); | ||
806 | } | 788 | } |
807 | 789 | ||
808 | 790 | ||
@@ -815,25 +797,25 @@ GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, | |||
815 | */ | 797 | */ |
816 | void | 798 | void |
817 | GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, | 799 | GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, |
818 | const char *keyword) | 800 | const char *keyword) |
819 | { | 801 | { |
820 | unsigned int i; | 802 | unsigned int i; |
821 | char *old; | 803 | char *old; |
822 | 804 | ||
823 | GNUNET_assert (uri->type == ksk); | 805 | GNUNET_assert (uri->type == ksk); |
824 | for (i = 0; i < uri->data.ksk.keywordCount; i++) | 806 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
807 | { | ||
808 | old = uri->data.ksk.keywords[i]; | ||
809 | if (0 == strcmp (&old[1], keyword)) | ||
825 | { | 810 | { |
826 | old = uri->data.ksk.keywords[i]; | 811 | uri->data.ksk.keywords[i] = |
827 | if (0 == strcmp (&old[1], keyword)) | 812 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; |
828 | { | 813 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, |
829 | uri->data.ksk.keywords[i] = uri->data.ksk.keywords[uri->data.ksk.keywordCount-1]; | 814 | uri->data.ksk.keywordCount - 1); |
830 | GNUNET_array_grow (uri->data.ksk.keywords, | 815 | GNUNET_free (old); |
831 | uri->data.ksk.keywordCount, | 816 | return; |
832 | uri->data.ksk.keywordCount - 1); | ||
833 | GNUNET_free (old); | ||
834 | return; | ||
835 | } | ||
836 | } | 817 | } |
818 | } | ||
837 | } | 819 | } |
838 | 820 | ||
839 | 821 | ||
@@ -846,13 +828,13 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, | |||
846 | */ | 828 | */ |
847 | int | 829 | int |
848 | GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, | 830 | GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, |
849 | struct GNUNET_PeerIdentity * peer) | 831 | struct GNUNET_PeerIdentity *peer) |
850 | { | 832 | { |
851 | if (uri->type != loc) | 833 | if (uri->type != loc) |
852 | return GNUNET_SYSERR; | 834 | return GNUNET_SYSERR; |
853 | GNUNET_CRYPTO_hash (&uri->data.loc.peer, | 835 | GNUNET_CRYPTO_hash (&uri->data.loc.peer, |
854 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 836 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
855 | &peer->hashPubKey); | 837 | &peer->hashPubKey); |
856 | return GNUNET_OK; | 838 | return GNUNET_OK; |
857 | } | 839 | } |
858 | 840 | ||
@@ -867,7 +849,7 @@ struct GNUNET_TIME_Absolute | |||
867 | GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) | 849 | GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) |
868 | { | 850 | { |
869 | GNUNET_assert (uri->type == loc); | 851 | GNUNET_assert (uri->type == loc); |
870 | return uri->data.loc.expirationTime; | 852 | return uri->data.loc.expirationTime; |
871 | } | 853 | } |
872 | 854 | ||
873 | 855 | ||
@@ -902,11 +884,11 @@ GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) | |||
902 | */ | 884 | */ |
903 | struct GNUNET_FS_Uri * | 885 | struct GNUNET_FS_Uri * |
904 | GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | 886 | GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, |
905 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 887 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
906 | struct GNUNET_TIME_Absolute expiration_time) | 888 | struct GNUNET_TIME_Absolute expiration_time) |
907 | { | 889 | { |
908 | struct GNUNET_FS_Uri *uri; | 890 | struct GNUNET_FS_Uri *uri; |
909 | struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | 891 | struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; |
910 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; | 892 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; |
911 | char *keyfile; | 893 | char *keyfile; |
912 | struct LocUriAssembly ass; | 894 | struct LocUriAssembly ass; |
@@ -915,27 +897,24 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
915 | return NULL; | 897 | return NULL; |
916 | if (GNUNET_OK != | 898 | if (GNUNET_OK != |
917 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 899 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
918 | "GNUNETD", | 900 | "GNUNETD", "HOSTKEY", &keyfile)) |
919 | "HOSTKEY", &keyfile)) | 901 | { |
920 | { | 902 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
921 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 903 | _("Lacking key configuration settings.\n")); |
922 | _ | 904 | return NULL; |
923 | ("Lacking key configuration settings.\n")); | 905 | } |
924 | return NULL; | ||
925 | } | ||
926 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 906 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
927 | if (my_private_key == NULL) | 907 | if (my_private_key == NULL) |
928 | { | 908 | { |
929 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 909 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
930 | _("Could not access hostkey file `%s'.\n"), | 910 | _("Could not access hostkey file `%s'.\n"), keyfile); |
931 | keyfile); | 911 | GNUNET_free (keyfile); |
932 | GNUNET_free (keyfile); | 912 | return NULL; |
933 | return NULL; | 913 | } |
934 | } | ||
935 | GNUNET_free (keyfile); | 914 | GNUNET_free (keyfile); |
936 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | 915 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
937 | ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); | 916 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); |
938 | ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 917 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
939 | ass.exptime = GNUNET_TIME_absolute_hton (expiration_time); | 918 | ass.exptime = GNUNET_TIME_absolute_hton (expiration_time); |
940 | ass.fi = baseUri->data.chk; | 919 | ass.fi = baseUri->data.chk; |
941 | ass.peer = my_public_key; | 920 | ass.peer = my_public_key; |
@@ -945,9 +924,9 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
945 | uri->data.loc.expirationTime = expiration_time; | 924 | uri->data.loc.expirationTime = expiration_time; |
946 | uri->data.loc.peer = my_public_key; | 925 | uri->data.loc.peer = my_public_key; |
947 | GNUNET_assert (GNUNET_OK == | 926 | GNUNET_assert (GNUNET_OK == |
948 | GNUNET_CRYPTO_rsa_sign (my_private_key, | 927 | GNUNET_CRYPTO_rsa_sign (my_private_key, |
949 | &ass.purpose, | 928 | &ass.purpose, |
950 | &uri->data.loc.contentSignature)); | 929 | &uri->data.loc.contentSignature)); |
951 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 930 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
952 | return uri; | 931 | return uri; |
953 | } | 932 | } |
@@ -963,19 +942,15 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
963 | */ | 942 | */ |
964 | struct GNUNET_FS_Uri * | 943 | struct GNUNET_FS_Uri * |
965 | GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, | 944 | GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, |
966 | const char *id, | 945 | const char *id, char **emsg) |
967 | char **emsg) | ||
968 | { | 946 | { |
969 | struct GNUNET_FS_Uri *ns_uri; | 947 | struct GNUNET_FS_Uri *ns_uri; |
970 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; | 948 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; |
971 | 949 | ||
972 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 950 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
973 | ns_uri->type = sks; | 951 | ns_uri->type = sks; |
974 | GNUNET_CRYPTO_rsa_key_get_public (ns->key, | 952 | GNUNET_CRYPTO_rsa_key_get_public (ns->key, &pk); |
975 | &pk); | 953 | GNUNET_CRYPTO_hash (&pk, sizeof (pk), &ns_uri->data.sks.namespace); |
976 | GNUNET_CRYPTO_hash (&pk, | ||
977 | sizeof (pk), | ||
978 | &ns_uri->data.sks.namespace); | ||
979 | ns_uri->data.sks.identifier = GNUNET_strdup (id); | 954 | ns_uri->data.sks.identifier = GNUNET_strdup (id); |
980 | return ns_uri; | 955 | return ns_uri; |
981 | } | 956 | } |
@@ -989,11 +964,10 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, | |||
989 | * @return an FS URI for the given namespace and identifier | 964 | * @return an FS URI for the given namespace and identifier |
990 | */ | 965 | */ |
991 | struct GNUNET_FS_Uri * | 966 | struct GNUNET_FS_Uri * |
992 | GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode *nsid, | 967 | GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id) |
993 | const char *id) | ||
994 | { | 968 | { |
995 | struct GNUNET_FS_Uri *ns_uri; | 969 | struct GNUNET_FS_Uri *ns_uri; |
996 | 970 | ||
997 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 971 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
998 | ns_uri->type = sks; | 972 | ns_uri->type = sks; |
999 | ns_uri->data.sks.namespace = *nsid; | 973 | ns_uri->data.sks.namespace = *nsid; |
@@ -1019,60 +993,60 @@ canonicalize_keyword (const char *in) | |||
1019 | wpos = ret; | 993 | wpos = ret; |
1020 | rpos = in; | 994 | rpos = in; |
1021 | while ('\0' != *rpos) | 995 | while ('\0' != *rpos) |
996 | { | ||
997 | switch (tolower ((unsigned char) *rpos)) | ||
1022 | { | 998 | { |
1023 | switch (tolower( (unsigned char) *rpos)) | 999 | case 'a': |
1024 | { | 1000 | case 'e': |
1025 | case 'a': | 1001 | case 'i': |
1026 | case 'e': | 1002 | case 'o': |
1027 | case 'i': | 1003 | case 'u': |
1028 | case 'o': | 1004 | case ' ': |
1029 | case 'u': | 1005 | case '\t': |
1030 | case ' ': | 1006 | case '\n': |
1031 | case '\t': | 1007 | case '\r': |
1032 | case '\n': | 1008 | /* skip characters listed above */ |
1033 | case '\r': | 1009 | break; |
1034 | /* skip characters listed above */ | 1010 | case 'b': |
1035 | break; | 1011 | case 'c': |
1036 | case 'b': | 1012 | case 'd': |
1037 | case 'c': | 1013 | case 'f': |
1038 | case 'd': | 1014 | case 'g': |
1039 | case 'f': | 1015 | case 'h': |
1040 | case 'g': | 1016 | case 'j': |
1041 | case 'h': | 1017 | case 'k': |
1042 | case 'j': | 1018 | case 'l': |
1043 | case 'k': | 1019 | case 'm': |
1044 | case 'l': | 1020 | case 'n': |
1045 | case 'm': | 1021 | case 'p': |
1046 | case 'n': | 1022 | case 'r': |
1047 | case 'p': | 1023 | case 's': |
1048 | case 'r': | 1024 | case 't': |
1049 | case 's': | 1025 | case 'v': |
1050 | case 't': | 1026 | case 'w': |
1051 | case 'v': | 1027 | case 'x': |
1052 | case 'w': | 1028 | case 'y': |
1053 | case 'x': | 1029 | case 'z': |
1054 | case 'y': | 1030 | /* convert characters listed above to lower case */ |
1055 | case 'z': | 1031 | *wpos = tolower ((unsigned char) *rpos); |
1056 | /* convert characters listed above to lower case */ | 1032 | wpos++; |
1057 | *wpos = tolower( (unsigned char)*rpos); | 1033 | break; |
1058 | wpos++; | 1034 | case '!': |
1059 | break; | 1035 | case '.': |
1060 | case '!': | 1036 | case '?': |
1061 | case '.': | 1037 | case '-': |
1062 | case '?': | 1038 | /* keep characters listed above without changes */ |
1063 | case '-': | 1039 | *wpos = *rpos; |
1064 | /* keep characters listed above without changes */ | 1040 | wpos++; |
1065 | *wpos = *rpos; | 1041 | break; |
1066 | wpos++; | 1042 | default: |
1067 | break; | 1043 | /* replace characters listed above with '_' */ |
1068 | default: | 1044 | *wpos = '_'; |
1069 | /* replace characters listed above with '_' */ | 1045 | wpos++; |
1070 | *wpos = '_'; | 1046 | break; |
1071 | wpos++; | ||
1072 | break; | ||
1073 | } | ||
1074 | rpos++; | ||
1075 | } | 1047 | } |
1048 | rpos++; | ||
1049 | } | ||
1076 | return ret; | 1050 | return ret; |
1077 | } | 1051 | } |
1078 | 1052 | ||
@@ -1094,10 +1068,10 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri) | |||
1094 | char **kl; | 1068 | char **kl; |
1095 | 1069 | ||
1096 | kc = uri->data.ksk.keywordCount; | 1070 | kc = uri->data.ksk.keywordCount; |
1097 | kl = GNUNET_malloc (kc*sizeof(char*)); | 1071 | kl = GNUNET_malloc (kc * sizeof (char *)); |
1098 | for (i=0;i<kc;i++) | 1072 | for (i = 0; i < kc; i++) |
1099 | kl[i] = canonicalize_keyword (uri->data.ksk.keywords[i]); | 1073 | kl[i] = canonicalize_keyword (uri->data.ksk.keywords[i]); |
1100 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | 1074 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
1101 | ret->type = ksk; | 1075 | ret->type = ksk; |
1102 | ret->data.ksk.keywordCount = kc; | 1076 | ret->data.ksk.keywordCount = kc; |
1103 | ret->data.ksk.keywords = kl; | 1077 | ret->data.ksk.keywords = kl; |
@@ -1116,7 +1090,7 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri) | |||
1116 | */ | 1090 | */ |
1117 | struct GNUNET_FS_Uri * | 1091 | struct GNUNET_FS_Uri * |
1118 | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | 1092 | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, |
1119 | const struct GNUNET_FS_Uri *u2) | 1093 | const struct GNUNET_FS_Uri *u2) |
1120 | { | 1094 | { |
1121 | struct GNUNET_FS_Uri *ret; | 1095 | struct GNUNET_FS_Uri *ret; |
1122 | unsigned int kc; | 1096 | unsigned int kc; |
@@ -1126,39 +1100,37 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | |||
1126 | const char *kp; | 1100 | const char *kp; |
1127 | char **kl; | 1101 | char **kl; |
1128 | 1102 | ||
1129 | if ( (u1 == NULL) && (u2 == NULL) ) | 1103 | if ((u1 == NULL) && (u2 == NULL)) |
1130 | return NULL; | 1104 | return NULL; |
1131 | if (u1 == NULL) | 1105 | if (u1 == NULL) |
1132 | return GNUNET_FS_uri_dup (u2); | 1106 | return GNUNET_FS_uri_dup (u2); |
1133 | if (u2 == NULL) | 1107 | if (u2 == NULL) |
1134 | return GNUNET_FS_uri_dup (u1); | 1108 | return GNUNET_FS_uri_dup (u1); |
1135 | if ( (u1->type != ksk) || | 1109 | if ((u1->type != ksk) || (u2->type != ksk)) |
1136 | (u2->type != ksk) ) | 1110 | { |
1137 | { | 1111 | GNUNET_break (0); |
1138 | GNUNET_break (0); | 1112 | return NULL; |
1139 | return NULL; | 1113 | } |
1140 | } | ||
1141 | kc = u1->data.ksk.keywordCount; | 1114 | kc = u1->data.ksk.keywordCount; |
1142 | kl = GNUNET_malloc ((kc+u2->data.ksk.keywordCount)*sizeof(char*)); | 1115 | kl = GNUNET_malloc ((kc + u2->data.ksk.keywordCount) * sizeof (char *)); |
1143 | for (i=0;i<u1->data.ksk.keywordCount;i++) | 1116 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
1144 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); | 1117 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); |
1145 | for (i=0;i<u2->data.ksk.keywordCount;i++) | 1118 | for (i = 0; i < u2->data.ksk.keywordCount; i++) |
1146 | { | 1119 | { |
1147 | kp = u2->data.ksk.keywords[i]; | 1120 | kp = u2->data.ksk.keywords[i]; |
1148 | found = 0; | 1121 | found = 0; |
1149 | for (j=0;j<u1->data.ksk.keywordCount;j++) | 1122 | for (j = 0; j < u1->data.ksk.keywordCount; j++) |
1150 | if (0 == strcmp(kp + 1, | 1123 | if (0 == strcmp (kp + 1, kl[j] + 1)) |
1151 | kl[j]+1)) | 1124 | { |
1152 | { | 1125 | found = 1; |
1153 | found = 1; | 1126 | if (kp[0] == '+') |
1154 | if (kp[0] == '+') | 1127 | kl[j][0] = '+'; |
1155 | kl[j][0] = '+'; | 1128 | break; |
1156 | break; | 1129 | } |
1157 | } | 1130 | if (0 == found) |
1158 | if (0 == found) | 1131 | kl[kc++] = GNUNET_strdup (kp); |
1159 | kl[kc++] = GNUNET_strdup (kp); | 1132 | } |
1160 | } | 1133 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
1161 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | ||
1162 | ret->type = ksk; | 1134 | ret->type = ksk; |
1163 | ret->data.ksk.keywordCount = kc; | 1135 | ret->data.ksk.keywordCount = kc; |
1164 | ret->data.ksk.keywords = kl; | 1136 | ret->data.ksk.keywords = kl; |
@@ -1183,33 +1155,33 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1183 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 1155 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
1184 | memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri)); | 1156 | memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri)); |
1185 | switch (ret->type) | 1157 | switch (ret->type) |
1158 | { | ||
1159 | case ksk: | ||
1160 | if (ret->data.ksk.keywordCount >= | ||
1161 | GNUNET_MAX_MALLOC_CHECKED / sizeof (char *)) | ||
1186 | { | 1162 | { |
1187 | case ksk: | 1163 | GNUNET_break (0); |
1188 | if (ret->data.ksk.keywordCount >= GNUNET_MAX_MALLOC_CHECKED / sizeof (char*)) | 1164 | GNUNET_free (ret); |
1189 | { | 1165 | return NULL; |
1190 | GNUNET_break (0); | ||
1191 | GNUNET_free (ret); | ||
1192 | return NULL; | ||
1193 | } | ||
1194 | if (ret->data.ksk.keywordCount > 0) | ||
1195 | { | ||
1196 | ret->data.ksk.keywords | ||
1197 | = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *)); | ||
1198 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | ||
1199 | ret->data.ksk.keywords[i] = | ||
1200 | GNUNET_strdup (uri->data.ksk.keywords[i]); | ||
1201 | } | ||
1202 | else | ||
1203 | ret->data.ksk.keywords = NULL; /* just to be sure */ | ||
1204 | break; | ||
1205 | case sks: | ||
1206 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); | ||
1207 | break; | ||
1208 | case loc: | ||
1209 | break; | ||
1210 | default: | ||
1211 | break; | ||
1212 | } | 1166 | } |
1167 | if (ret->data.ksk.keywordCount > 0) | ||
1168 | { | ||
1169 | ret->data.ksk.keywords | ||
1170 | = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *)); | ||
1171 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | ||
1172 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); | ||
1173 | } | ||
1174 | else | ||
1175 | ret->data.ksk.keywords = NULL; /* just to be sure */ | ||
1176 | break; | ||
1177 | case sks: | ||
1178 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); | ||
1179 | break; | ||
1180 | case loc: | ||
1181 | break; | ||
1182 | default: | ||
1183 | break; | ||
1184 | } | ||
1213 | return ret; | 1185 | return ret; |
1214 | } | 1186 | } |
1215 | 1187 | ||
@@ -1232,8 +1204,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1232 | * if keywords is not legal (i.e. empty). | 1204 | * if keywords is not legal (i.e. empty). |
1233 | */ | 1205 | */ |
1234 | struct GNUNET_FS_Uri * | 1206 | struct GNUNET_FS_Uri * |
1235 | GNUNET_FS_uri_ksk_create (const char *keywords, | 1207 | GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) |
1236 | char **emsg) | ||
1237 | { | 1208 | { |
1238 | char **keywordarr; | 1209 | char **keywordarr; |
1239 | unsigned int num_Words; | 1210 | unsigned int num_Words; |
@@ -1244,67 +1215,67 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1244 | int saw_quote; | 1215 | int saw_quote; |
1245 | 1216 | ||
1246 | if (keywords == NULL) | 1217 | if (keywords == NULL) |
1247 | { | 1218 | { |
1248 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | 1219 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); |
1249 | GNUNET_break (0); | 1220 | GNUNET_break (0); |
1250 | return NULL; | 1221 | return NULL; |
1251 | } | 1222 | } |
1252 | searchString = GNUNET_strdup (keywords); | 1223 | searchString = GNUNET_strdup (keywords); |
1253 | num_Words = 0; | 1224 | num_Words = 0; |
1254 | inWord = 0; | 1225 | inWord = 0; |
1255 | saw_quote = 0; | 1226 | saw_quote = 0; |
1256 | pos = searchString; | 1227 | pos = searchString; |
1257 | while ('\0' != *pos) | 1228 | while ('\0' != *pos) |
1229 | { | ||
1230 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | ||
1258 | { | 1231 | { |
1259 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | 1232 | inWord = 0; |
1260 | { | ||
1261 | inWord = 0; | ||
1262 | } | ||
1263 | else if (0 == inWord) | ||
1264 | { | ||
1265 | inWord = 1; | ||
1266 | ++num_Words; | ||
1267 | } | ||
1268 | if ('"' == *pos) | ||
1269 | saw_quote = (saw_quote + 1) % 2; | ||
1270 | pos++; | ||
1271 | } | 1233 | } |
1272 | if (num_Words == 0) | 1234 | else if (0 == inWord) |
1273 | { | 1235 | { |
1274 | GNUNET_free (searchString); | 1236 | inWord = 1; |
1275 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | 1237 | ++num_Words; |
1276 | return NULL; | ||
1277 | } | 1238 | } |
1239 | if ('"' == *pos) | ||
1240 | saw_quote = (saw_quote + 1) % 2; | ||
1241 | pos++; | ||
1242 | } | ||
1243 | if (num_Words == 0) | ||
1244 | { | ||
1245 | GNUNET_free (searchString); | ||
1246 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | ||
1247 | return NULL; | ||
1248 | } | ||
1278 | if (saw_quote != 0) | 1249 | if (saw_quote != 0) |
1279 | { | 1250 | { |
1280 | GNUNET_free (searchString); | 1251 | GNUNET_free (searchString); |
1281 | *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); | 1252 | *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); |
1282 | return NULL; | 1253 | return NULL; |
1283 | } | 1254 | } |
1284 | keywordarr = GNUNET_malloc (num_Words * sizeof (char *)); | 1255 | keywordarr = GNUNET_malloc (num_Words * sizeof (char *)); |
1285 | num_Words = 0; | 1256 | num_Words = 0; |
1286 | inWord = 0; | 1257 | inWord = 0; |
1287 | pos = searchString; | 1258 | pos = searchString; |
1288 | while ('\0' != *pos) | 1259 | while ('\0' != *pos) |
1260 | { | ||
1261 | if ((saw_quote == 0) && (isspace ((unsigned char) *pos))) | ||
1289 | { | 1262 | { |
1290 | if ((saw_quote == 0) && (isspace ( (unsigned char) *pos))) | 1263 | inWord = 0; |
1291 | { | 1264 | *pos = '\0'; |
1292 | inWord = 0; | ||
1293 | *pos = '\0'; | ||
1294 | } | ||
1295 | else if (0 == inWord) | ||
1296 | { | ||
1297 | keywordarr[num_Words] = pos; | ||
1298 | inWord = 1; | ||
1299 | ++num_Words; | ||
1300 | } | ||
1301 | if ('"' == *pos) | ||
1302 | saw_quote = (saw_quote + 1) % 2; | ||
1303 | pos++; | ||
1304 | } | 1265 | } |
1266 | else if (0 == inWord) | ||
1267 | { | ||
1268 | keywordarr[num_Words] = pos; | ||
1269 | inWord = 1; | ||
1270 | ++num_Words; | ||
1271 | } | ||
1272 | if ('"' == *pos) | ||
1273 | saw_quote = (saw_quote + 1) % 2; | ||
1274 | pos++; | ||
1275 | } | ||
1305 | uri = | 1276 | uri = |
1306 | GNUNET_FS_uri_ksk_create_from_args (num_Words, | 1277 | GNUNET_FS_uri_ksk_create_from_args (num_Words, |
1307 | (const char **) keywordarr); | 1278 | (const char **) keywordarr); |
1308 | GNUNET_free (keywordarr); | 1279 | GNUNET_free (keywordarr); |
1309 | GNUNET_free (searchString); | 1280 | GNUNET_free (searchString); |
1310 | return uri; | 1281 | return uri; |
@@ -1329,8 +1300,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1329 | * if keywords is not legal (i.e. empty). | 1300 | * if keywords is not legal (i.e. empty). |
1330 | */ | 1301 | */ |
1331 | struct GNUNET_FS_Uri * | 1302 | struct GNUNET_FS_Uri * |
1332 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | 1303 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) |
1333 | const char **argv) | ||
1334 | { | 1304 | { |
1335 | unsigned int i; | 1305 | unsigned int i; |
1336 | struct GNUNET_FS_Uri *uri; | 1306 | struct GNUNET_FS_Uri *uri; |
@@ -1343,12 +1313,13 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | |||
1343 | if (argc == 0) | 1313 | if (argc == 0) |
1344 | return NULL; | 1314 | return NULL; |
1345 | /* allow URI to be given as one and only keyword and | 1315 | /* allow URI to be given as one and only keyword and |
1346 | handle accordingly */ | 1316 | * handle accordingly */ |
1347 | emsg = NULL; | 1317 | emsg = NULL; |
1348 | if ( (argc == 1) && | 1318 | if ((argc == 1) && |
1349 | (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) && | 1319 | (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && |
1350 | (0 == strncmp(argv[0], GNUNET_FS_URI_PREFIX, strlen(GNUNET_FS_URI_PREFIX)) ) && | 1320 | (0 == |
1351 | (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)) ) ) | 1321 | strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) |
1322 | && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | ||
1352 | return uri; | 1323 | return uri; |
1353 | GNUNET_free_non_null (emsg); | 1324 | GNUNET_free_non_null (emsg); |
1354 | uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 1325 | uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
@@ -1356,24 +1327,24 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | |||
1356 | uri->data.ksk.keywordCount = argc; | 1327 | uri->data.ksk.keywordCount = argc; |
1357 | uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *)); | 1328 | uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *)); |
1358 | for (i = 0; i < argc; i++) | 1329 | for (i = 0; i < argc; i++) |
1330 | { | ||
1331 | keyword = argv[i]; | ||
1332 | if (keyword[0] == '+') | ||
1333 | val = GNUNET_strdup (keyword); | ||
1334 | else | ||
1335 | GNUNET_asprintf (&val, " %s", keyword); | ||
1336 | r = val; | ||
1337 | w = val; | ||
1338 | while ('\0' != *r) | ||
1359 | { | 1339 | { |
1360 | keyword = argv[i]; | 1340 | if ('"' == *r) |
1361 | if (keyword[0] == '+') | 1341 | r++; |
1362 | val = GNUNET_strdup (keyword); | ||
1363 | else | 1342 | else |
1364 | GNUNET_asprintf (&val, " %s", keyword); | 1343 | *(w++) = *(r++); |
1365 | r = val; | ||
1366 | w = val; | ||
1367 | while ('\0' != *r) | ||
1368 | { | ||
1369 | if ('"' == *r) | ||
1370 | r++; | ||
1371 | else | ||
1372 | *(w++) = *(r++); | ||
1373 | } | ||
1374 | *w = '\0'; | ||
1375 | uri->data.ksk.keywords[i] = val; | ||
1376 | } | 1344 | } |
1345 | *w = '\0'; | ||
1346 | uri->data.ksk.keywords[i] = val; | ||
1347 | } | ||
1377 | return uri; | 1348 | return uri; |
1378 | } | 1349 | } |
1379 | 1350 | ||
@@ -1385,9 +1356,9 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | |||
1385 | * @param u2 the other URI | 1356 | * @param u2 the other URI |
1386 | * @return GNUNET_YES if the URIs are equal | 1357 | * @return GNUNET_YES if the URIs are equal |
1387 | */ | 1358 | */ |
1388 | int | 1359 | int |
1389 | GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | 1360 | GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, |
1390 | const struct GNUNET_FS_Uri *u2) | 1361 | const struct GNUNET_FS_Uri *u2) |
1391 | { | 1362 | { |
1392 | int ret; | 1363 | int ret; |
1393 | unsigned int i; | 1364 | unsigned int i; |
@@ -1398,53 +1369,50 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1398 | if (u1->type != u2->type) | 1369 | if (u1->type != u2->type) |
1399 | return GNUNET_NO; | 1370 | return GNUNET_NO; |
1400 | switch (u1->type) | 1371 | switch (u1->type) |
1401 | { | 1372 | { |
1402 | case chk: | 1373 | case chk: |
1403 | if (0 == memcmp (&u1->data.chk, | 1374 | if (0 == memcmp (&u1->data.chk, |
1404 | &u2->data.chk, | 1375 | &u2->data.chk, sizeof (struct FileIdentifier))) |
1405 | sizeof (struct FileIdentifier))) | 1376 | return GNUNET_YES; |
1406 | return GNUNET_YES; | 1377 | return GNUNET_NO; |
1407 | return GNUNET_NO; | 1378 | case sks: |
1408 | case sks: | 1379 | if ((0 == memcmp (&u1->data.sks.namespace, |
1409 | if ((0 == memcmp (&u1->data.sks.namespace, | 1380 | &u2->data.sks.namespace, |
1410 | &u2->data.sks.namespace, | 1381 | sizeof (GNUNET_HashCode))) && |
1411 | sizeof (GNUNET_HashCode))) && | 1382 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) |
1412 | (0 == strcmp (u1->data.sks.identifier, | 1383 | |
1413 | u2->data.sks.identifier))) | 1384 | return GNUNET_YES; |
1414 | 1385 | return GNUNET_NO; | |
1415 | return GNUNET_YES; | 1386 | case ksk: |
1387 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) | ||
1416 | return GNUNET_NO; | 1388 | return GNUNET_NO; |
1417 | case ksk: | 1389 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
1418 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) | 1390 | { |
1419 | return GNUNET_NO; | 1391 | ret = GNUNET_NO; |
1420 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 1392 | for (j = 0; j < u2->data.ksk.keywordCount; j++) |
1393 | { | ||
1394 | if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j])) | ||
1421 | { | 1395 | { |
1422 | ret = GNUNET_NO; | 1396 | ret = GNUNET_YES; |
1423 | for (j = 0; j < u2->data.ksk.keywordCount; j++) | 1397 | break; |
1424 | { | ||
1425 | if (0 == strcmp (u1->data.ksk.keywords[i], | ||
1426 | u2->data.ksk.keywords[j])) | ||
1427 | { | ||
1428 | ret = GNUNET_YES; | ||
1429 | break; | ||
1430 | } | ||
1431 | } | ||
1432 | if (ret == GNUNET_NO) | ||
1433 | return GNUNET_NO; | ||
1434 | } | 1398 | } |
1435 | return GNUNET_YES; | 1399 | } |
1436 | case loc: | 1400 | if (ret == GNUNET_NO) |
1437 | if (memcmp (&u1->data.loc, | ||
1438 | &u2->data.loc, | ||
1439 | sizeof (struct FileIdentifier) + | ||
1440 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | ||
1441 | sizeof (struct GNUNET_TIME_Absolute) + | ||
1442 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) | ||
1443 | return GNUNET_NO; | 1401 | return GNUNET_NO; |
1444 | return GNUNET_YES; | ||
1445 | default: | ||
1446 | return GNUNET_NO; | ||
1447 | } | 1402 | } |
1403 | return GNUNET_YES; | ||
1404 | case loc: | ||
1405 | if (memcmp (&u1->data.loc, | ||
1406 | &u2->data.loc, | ||
1407 | sizeof (struct FileIdentifier) + | ||
1408 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | ||
1409 | sizeof (struct GNUNET_TIME_Absolute) + | ||
1410 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) | ||
1411 | return GNUNET_NO; | ||
1412 | return GNUNET_YES; | ||
1413 | default: | ||
1414 | return GNUNET_NO; | ||
1415 | } | ||
1448 | } | 1416 | } |
1449 | 1417 | ||
1450 | 1418 | ||
@@ -1469,15 +1437,15 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) | |||
1469 | * @param nsid where to store the ID of the namespace | 1437 | * @param nsid where to store the ID of the namespace |
1470 | * @return GNUNET_OK on success | 1438 | * @return GNUNET_OK on success |
1471 | */ | 1439 | */ |
1472 | int | 1440 | int |
1473 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | 1441 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, |
1474 | GNUNET_HashCode * nsid) | 1442 | GNUNET_HashCode * nsid) |
1475 | { | 1443 | { |
1476 | if (! GNUNET_FS_uri_test_sks (uri)) | 1444 | if (!GNUNET_FS_uri_test_sks (uri)) |
1477 | { | 1445 | { |
1478 | GNUNET_break (0); | 1446 | GNUNET_break (0); |
1479 | return GNUNET_SYSERR; | 1447 | return GNUNET_SYSERR; |
1480 | } | 1448 | } |
1481 | *nsid = uri->data.sks.namespace; | 1449 | *nsid = uri->data.sks.namespace; |
1482 | return GNUNET_OK; | 1450 | return GNUNET_OK; |
1483 | } | 1451 | } |
@@ -1493,10 +1461,10 @@ char * | |||
1493 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | 1461 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) |
1494 | { | 1462 | { |
1495 | if (!GNUNET_FS_uri_test_sks (uri)) | 1463 | if (!GNUNET_FS_uri_test_sks (uri)) |
1496 | { | 1464 | { |
1497 | GNUNET_break (0); | 1465 | GNUNET_break (0); |
1498 | return NULL; | 1466 | return NULL; |
1499 | } | 1467 | } |
1500 | return GNUNET_strdup (uri->data.sks.identifier); | 1468 | return GNUNET_strdup (uri->data.sks.identifier); |
1501 | } | 1469 | } |
1502 | 1470 | ||
@@ -1511,7 +1479,7 @@ GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | |||
1511 | */ | 1479 | */ |
1512 | char * | 1480 | char * |
1513 | GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, | 1481 | GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, |
1514 | const struct GNUNET_FS_Uri *uri) | 1482 | const struct GNUNET_FS_Uri *uri) |
1515 | { | 1483 | { |
1516 | char *ret; | 1484 | char *ret; |
1517 | char *name; | 1485 | char *name; |
@@ -1521,10 +1489,7 @@ GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1521 | name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace); | 1489 | name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace); |
1522 | if (name == NULL) | 1490 | if (name == NULL) |
1523 | return GNUNET_FS_uri_to_string (uri); | 1491 | return GNUNET_FS_uri_to_string (uri); |
1524 | GNUNET_asprintf (&ret, | 1492 | GNUNET_asprintf (&ret, "%s: %s", name, uri->data.sks.identifier); |
1525 | "%s: %s", | ||
1526 | name, | ||
1527 | uri->data.sks.identifier); | ||
1528 | GNUNET_free (name); | 1493 | GNUNET_free (name); |
1529 | return ret; | 1494 | return ret; |
1530 | } | 1495 | } |
@@ -1536,17 +1501,17 @@ GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1536 | * @param uri the uri | 1501 | * @param uri the uri |
1537 | * @return GNUNET_YES if this is a KSK uri | 1502 | * @return GNUNET_YES if this is a KSK uri |
1538 | */ | 1503 | */ |
1539 | int | 1504 | int |
1540 | GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) | 1505 | GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) |
1541 | { | 1506 | { |
1542 | #if EXTRA_CHECKS | 1507 | #if EXTRA_CHECKS |
1543 | unsigned int i; | 1508 | unsigned int i; |
1544 | 1509 | ||
1545 | if (uri->type == ksk) | 1510 | if (uri->type == ksk) |
1546 | { | 1511 | { |
1547 | for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--) | 1512 | for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--) |
1548 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); | 1513 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); |
1549 | } | 1514 | } |
1550 | #endif | 1515 | #endif |
1551 | return uri->type == ksk; | 1516 | return uri->type == ksk; |
1552 | } | 1517 | } |
@@ -1558,7 +1523,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) | |||
1558 | * @param uri the uri to check | 1523 | * @param uri the uri to check |
1559 | * @return GNUNET_YES if this is a CHK uri | 1524 | * @return GNUNET_YES if this is a CHK uri |
1560 | */ | 1525 | */ |
1561 | int | 1526 | int |
1562 | GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) | 1527 | GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) |
1563 | { | 1528 | { |
1564 | return uri->type == chk; | 1529 | return uri->type == chk; |
@@ -1572,18 +1537,18 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) | |||
1572 | * @param uri the CHK URI to inspect | 1537 | * @param uri the CHK URI to inspect |
1573 | * @return size of the file as specified in the CHK URI | 1538 | * @return size of the file as specified in the CHK URI |
1574 | */ | 1539 | */ |
1575 | uint64_t | 1540 | uint64_t |
1576 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) | 1541 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) |
1577 | { | 1542 | { |
1578 | switch (uri->type) | 1543 | switch (uri->type) |
1579 | { | 1544 | { |
1580 | case chk: | 1545 | case chk: |
1581 | return GNUNET_ntohll (uri->data.chk.file_length); | 1546 | return GNUNET_ntohll (uri->data.chk.file_length); |
1582 | case loc: | 1547 | case loc: |
1583 | return GNUNET_ntohll (uri->data.loc.fi.file_length); | 1548 | return GNUNET_ntohll (uri->data.loc.fi.file_length); |
1584 | default: | 1549 | default: |
1585 | GNUNET_assert (0); | 1550 | GNUNET_assert (0); |
1586 | } | 1551 | } |
1587 | return 0; /* unreachable */ | 1552 | return 0; /* unreachable */ |
1588 | } | 1553 | } |
1589 | 1554 | ||
@@ -1594,7 +1559,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) | |||
1594 | * @param uri the uri to check | 1559 | * @param uri the uri to check |
1595 | * @return GNUNET_YES if this is a LOC uri | 1560 | * @return GNUNET_YES if this is a LOC uri |
1596 | */ | 1561 | */ |
1597 | int | 1562 | int |
1598 | GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | 1563 | GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) |
1599 | { | 1564 | { |
1600 | return uri->type == loc; | 1565 | return uri->type == loc; |
@@ -1620,26 +1585,23 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | |||
1620 | */ | 1585 | */ |
1621 | static int | 1586 | static int |
1622 | gather_uri_data (void *cls, | 1587 | gather_uri_data (void *cls, |
1623 | const char *plugin_name, | 1588 | const char *plugin_name, |
1624 | enum EXTRACTOR_MetaType type, | 1589 | enum EXTRACTOR_MetaType type, |
1625 | enum EXTRACTOR_MetaFormat format, | 1590 | enum EXTRACTOR_MetaFormat format, |
1626 | const char *data_mime_type, | 1591 | const char *data_mime_type, const char *data, size_t data_len) |
1627 | const char *data, | ||
1628 | size_t data_len) | ||
1629 | { | 1592 | { |
1630 | struct GNUNET_FS_Uri *uri = cls; | 1593 | struct GNUNET_FS_Uri *uri = cls; |
1631 | char *nkword; | 1594 | char *nkword; |
1632 | int j; | 1595 | int j; |
1633 | 1596 | ||
1634 | if ( (format != EXTRACTOR_METAFORMAT_UTF8) && | 1597 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && |
1635 | (format != EXTRACTOR_METAFORMAT_C_STRING) ) | 1598 | (format != EXTRACTOR_METAFORMAT_C_STRING)) |
1636 | return 0; | 1599 | return 0; |
1637 | for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--) | 1600 | for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--) |
1638 | if (0 == strcmp (&uri->data.ksk.keywords[j][1], data)) | 1601 | if (0 == strcmp (&uri->data.ksk.keywords[j][1], data)) |
1639 | return GNUNET_OK; | 1602 | return GNUNET_OK; |
1640 | GNUNET_asprintf (&nkword, | 1603 | GNUNET_asprintf (&nkword, " %s", /* space to mark as 'non mandatory' */ |
1641 | " %s", /* space to mark as 'non mandatory' */ | 1604 | data); |
1642 | data); | ||
1643 | uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword; | 1605 | uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword; |
1644 | return 0; | 1606 | return 0; |
1645 | } | 1607 | } |
@@ -1654,7 +1616,8 @@ gather_uri_data (void *cls, | |||
1654 | * @return NULL on error, otherwise a KSK URI | 1616 | * @return NULL on error, otherwise a KSK URI |
1655 | */ | 1617 | */ |
1656 | struct GNUNET_FS_Uri * | 1618 | struct GNUNET_FS_Uri * |
1657 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) | 1619 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData |
1620 | *md) | ||
1658 | { | 1621 | { |
1659 | struct GNUNET_FS_Uri *ret; | 1622 | struct GNUNET_FS_Uri *ret; |
1660 | int ent; | 1623 | int ent; |
@@ -1665,11 +1628,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1665 | ret->type = ksk; | 1628 | ret->type = ksk; |
1666 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); | 1629 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); |
1667 | if (ent > 0) | 1630 | if (ent > 0) |
1668 | { | 1631 | { |
1669 | ret->data.ksk.keywords | 1632 | ret->data.ksk.keywords = GNUNET_malloc (sizeof (char *) * ent); |
1670 | = GNUNET_malloc (sizeof (char *) * ent); | 1633 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); |
1671 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); | 1634 | } |
1672 | } | ||
1673 | return ret; | 1635 | return ret; |
1674 | } | 1636 | } |
1675 | 1637 | ||
@@ -1681,7 +1643,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1681 | static int | 1643 | static int |
1682 | needs_percent (char c) | 1644 | needs_percent (char c) |
1683 | { | 1645 | { |
1684 | return (!((isalnum ( (unsigned char) c)) || | 1646 | return (!((isalnum ((unsigned char) c)) || |
1685 | (c == '-') || (c == '_') || (c == '.') || (c == '~'))); | 1647 | (c == '-') || (c == '_') || (c == '.') || (c == '~'))); |
1686 | } | 1648 | } |
1687 | 1649 | ||
@@ -1695,7 +1657,7 @@ needs_percent (char c) | |||
1695 | static char * | 1657 | static char * |
1696 | uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | 1658 | uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) |
1697 | { | 1659 | { |
1698 | char ** keywords; | 1660 | char **keywords; |
1699 | unsigned int keywordCount; | 1661 | unsigned int keywordCount; |
1700 | size_t n; | 1662 | size_t n; |
1701 | char *ret; | 1663 | char *ret; |
@@ -1709,50 +1671,49 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1709 | return NULL; | 1671 | return NULL; |
1710 | keywords = uri->data.ksk.keywords; | 1672 | keywords = uri->data.ksk.keywords; |
1711 | keywordCount = uri->data.ksk.keywordCount; | 1673 | keywordCount = uri->data.ksk.keywordCount; |
1712 | n = | 1674 | n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) + |
1713 | keywordCount + strlen (GNUNET_FS_URI_PREFIX) + | 1675 | strlen (GNUNET_FS_URI_KSK_INFIX) + 1; |
1714 | strlen (GNUNET_FS_URI_KSK_INFIX) + 1; | ||
1715 | for (i = 0; i < keywordCount; i++) | 1676 | for (i = 0; i < keywordCount; i++) |
1677 | { | ||
1678 | keyword = keywords[i]; | ||
1679 | slen = strlen (keyword); | ||
1680 | n += slen; | ||
1681 | for (j = 0; j < slen; j++) | ||
1716 | { | 1682 | { |
1717 | keyword = keywords[i]; | 1683 | if ((j == 0) && (keyword[j] == ' ')) |
1718 | slen = strlen (keyword); | 1684 | { |
1719 | n += slen; | 1685 | n--; |
1720 | for (j = 0; j < slen; j++) | 1686 | continue; /* skip leading space */ |
1721 | { | 1687 | } |
1722 | if ((j == 0) && (keyword[j] == ' ')) | 1688 | if (needs_percent (keyword[j])) |
1723 | { | 1689 | n += 2; /* will use %-encoding */ |
1724 | n--; | ||
1725 | continue; /* skip leading space */ | ||
1726 | } | ||
1727 | if (needs_percent (keyword[j])) | ||
1728 | n += 2; /* will use %-encoding */ | ||
1729 | } | ||
1730 | } | 1690 | } |
1691 | } | ||
1731 | ret = GNUNET_malloc (n); | 1692 | ret = GNUNET_malloc (n); |
1732 | strcpy (ret, GNUNET_FS_URI_PREFIX); | 1693 | strcpy (ret, GNUNET_FS_URI_PREFIX); |
1733 | strcat (ret, GNUNET_FS_URI_KSK_INFIX); | 1694 | strcat (ret, GNUNET_FS_URI_KSK_INFIX); |
1734 | wpos = strlen (ret); | 1695 | wpos = strlen (ret); |
1735 | for (i = 0; i < keywordCount; i++) | 1696 | for (i = 0; i < keywordCount; i++) |
1697 | { | ||
1698 | keyword = keywords[i]; | ||
1699 | slen = strlen (keyword); | ||
1700 | for (j = 0; j < slen; j++) | ||
1736 | { | 1701 | { |
1737 | keyword = keywords[i]; | 1702 | if ((j == 0) && (keyword[j] == ' ')) |
1738 | slen = strlen (keyword); | 1703 | continue; /* skip leading space */ |
1739 | for (j = 0; j < slen; j++) | 1704 | if (needs_percent (keyword[j])) |
1740 | { | 1705 | { |
1741 | if ((j == 0) && (keyword[j] == ' ')) | 1706 | sprintf (&ret[wpos], "%%%02X", keyword[j]); |
1742 | continue; /* skip leading space */ | 1707 | wpos += 3; |
1743 | if (needs_percent (keyword[j])) | 1708 | } |
1744 | { | 1709 | else |
1745 | sprintf (&ret[wpos], "%%%02X", keyword[j]); | 1710 | { |
1746 | wpos += 3; | 1711 | ret[wpos++] = keyword[j]; |
1747 | } | 1712 | } |
1748 | else | ||
1749 | { | ||
1750 | ret[wpos++] = keyword[j]; | ||
1751 | } | ||
1752 | } | ||
1753 | if (i != keywordCount - 1) | ||
1754 | ret[wpos++] = '+'; | ||
1755 | } | 1713 | } |
1714 | if (i != keywordCount - 1) | ||
1715 | ret[wpos++] = '+'; | ||
1716 | } | ||
1756 | return ret; | 1717 | return ret; |
1757 | } | 1718 | } |
1758 | 1719 | ||
@@ -1766,11 +1727,11 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1766 | static char * | 1727 | static char * |
1767 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | 1728 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) |
1768 | { | 1729 | { |
1769 | const GNUNET_HashCode * namespace; | 1730 | const GNUNET_HashCode *namespace; |
1770 | const char *identifier; | 1731 | const char *identifier; |
1771 | char *ret; | 1732 | char *ret; |
1772 | struct GNUNET_CRYPTO_HashAsciiEncoded ns; | 1733 | struct GNUNET_CRYPTO_HashAsciiEncoded ns; |
1773 | 1734 | ||
1774 | if (uri->type != sks) | 1735 | if (uri->type != sks) |
1775 | return NULL; | 1736 | return NULL; |
1776 | namespace = &uri->data.sks.namespace; | 1737 | namespace = &uri->data.sks.namespace; |
@@ -1778,9 +1739,8 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1778 | GNUNET_CRYPTO_hash_to_enc (namespace, &ns); | 1739 | GNUNET_CRYPTO_hash_to_enc (namespace, &ns); |
1779 | GNUNET_asprintf (&ret, | 1740 | GNUNET_asprintf (&ret, |
1780 | "%s%s%s/%s", | 1741 | "%s%s%s/%s", |
1781 | GNUNET_FS_URI_PREFIX, | 1742 | GNUNET_FS_URI_PREFIX, |
1782 | GNUNET_FS_URI_SKS_INFIX, | 1743 | GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier); |
1783 | (const char *) &ns, identifier); | ||
1784 | return ret; | 1744 | return ret; |
1785 | } | 1745 | } |
1786 | 1746 | ||
@@ -1794,7 +1754,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1794 | static char * | 1754 | static char * |
1795 | uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | 1755 | uri_chk_to_string (const struct GNUNET_FS_Uri *uri) |
1796 | { | 1756 | { |
1797 | const struct FileIdentifier * fi; | 1757 | const struct FileIdentifier *fi; |
1798 | char *ret; | 1758 | char *ret; |
1799 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; | 1759 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; |
1800 | struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; | 1760 | struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; |
@@ -1809,9 +1769,8 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1809 | "%s%s%s.%s.%llu", | 1769 | "%s%s%s.%s.%llu", |
1810 | GNUNET_FS_URI_PREFIX, | 1770 | GNUNET_FS_URI_PREFIX, |
1811 | GNUNET_FS_URI_CHK_INFIX, | 1771 | GNUNET_FS_URI_CHK_INFIX, |
1812 | (const char *) &keyhash, | 1772 | (const char *) &keyhash, |
1813 | (const char *) &queryhash, | 1773 | (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); |
1814 | GNUNET_ntohll (fi->file_length)); | ||
1815 | return ret; | 1774 | return ret; |
1816 | } | 1775 | } |
1817 | 1776 | ||
@@ -1829,8 +1788,8 @@ bin2enc (const void *data, size_t size) | |||
1829 | * 64 characters for encoding, 6 bits per character | 1788 | * 64 characters for encoding, 6 bits per character |
1830 | */ | 1789 | */ |
1831 | static char *tbl = | 1790 | static char *tbl = |
1832 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_="; | 1791 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_="; |
1833 | 1792 | ||
1834 | size_t len; | 1793 | size_t len; |
1835 | size_t pos; | 1794 | size_t pos; |
1836 | unsigned int bits; | 1795 | unsigned int bits; |
@@ -1847,16 +1806,16 @@ bin2enc (const void *data, size_t size) | |||
1847 | bits = 0; | 1806 | bits = 0; |
1848 | hbits = 0; | 1807 | hbits = 0; |
1849 | for (pos = 0; pos < size; pos++) | 1808 | for (pos = 0; pos < size; pos++) |
1809 | { | ||
1810 | bits |= ((((const unsigned char *) data)[pos]) << hbits); | ||
1811 | hbits += 8; | ||
1812 | while (hbits >= 6) | ||
1850 | { | 1813 | { |
1851 | bits |= ((((const unsigned char *) data)[pos]) << hbits); | 1814 | ret[len++] = tbl[bits & 63]; |
1852 | hbits += 8; | 1815 | bits >>= 6; |
1853 | while (hbits >= 6) | 1816 | hbits -= 6; |
1854 | { | ||
1855 | ret[len++] = tbl[bits & 63]; | ||
1856 | bits >>= 6; | ||
1857 | hbits -= 6; | ||
1858 | } | ||
1859 | } | 1817 | } |
1818 | } | ||
1860 | if (hbits > 0) | 1819 | if (hbits > 0) |
1861 | ret[len] = tbl[bits & 63]; | 1820 | ret[len] = tbl[bits & 63]; |
1862 | return ret; | 1821 | return ret; |
@@ -1881,19 +1840,19 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
1881 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); | 1840 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); |
1882 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); | 1841 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
1883 | peerId = bin2enc (&uri->data.loc.peer, | 1842 | peerId = bin2enc (&uri->data.loc.peer, |
1884 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 1843 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
1885 | peerSig = bin2enc (&uri->data.loc.contentSignature, | 1844 | peerSig = bin2enc (&uri->data.loc.contentSignature, |
1886 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 1845 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
1887 | GNUNET_asprintf (&ret, | 1846 | GNUNET_asprintf (&ret, |
1888 | "%s%s%s.%s.%llu.%s.%s.%llu", | 1847 | "%s%s%s.%s.%llu.%s.%s.%llu", |
1889 | GNUNET_FS_URI_PREFIX, | 1848 | GNUNET_FS_URI_PREFIX, |
1890 | GNUNET_FS_URI_LOC_INFIX, | 1849 | GNUNET_FS_URI_LOC_INFIX, |
1891 | (const char *) &keyhash, | 1850 | (const char *) &keyhash, |
1892 | (const char *) &queryhash, | 1851 | (const char *) &queryhash, |
1893 | (unsigned long long) GNUNET_ntohll (uri->data.loc.fi.file_length), | 1852 | (unsigned long long) GNUNET_ntohll (uri->data.loc. |
1894 | peerId, | 1853 | fi.file_length), peerId, |
1895 | peerSig, | 1854 | peerSig, |
1896 | (unsigned long long) uri->data.loc.expirationTime.abs_value); | 1855 | (unsigned long long) uri->data.loc.expirationTime.abs_value); |
1897 | GNUNET_free (peerSig); | 1856 | GNUNET_free (peerSig); |
1898 | GNUNET_free (peerId); | 1857 | GNUNET_free (peerId); |
1899 | return ret; | 1858 | return ret; |
@@ -1910,24 +1869,24 @@ char * | |||
1910 | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) | 1869 | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) |
1911 | { | 1870 | { |
1912 | if (uri == NULL) | 1871 | if (uri == NULL) |
1913 | { | 1872 | { |
1914 | GNUNET_break (0); | 1873 | GNUNET_break (0); |
1915 | return NULL; | 1874 | return NULL; |
1916 | } | 1875 | } |
1917 | switch (uri->type) | 1876 | switch (uri->type) |
1918 | { | 1877 | { |
1919 | case ksk: | 1878 | case ksk: |
1920 | return uri_ksk_to_string (uri); | 1879 | return uri_ksk_to_string (uri); |
1921 | case sks: | 1880 | case sks: |
1922 | return uri_sks_to_string (uri); | 1881 | return uri_sks_to_string (uri); |
1923 | case chk: | 1882 | case chk: |
1924 | return uri_chk_to_string (uri); | 1883 | return uri_chk_to_string (uri); |
1925 | case loc: | 1884 | case loc: |
1926 | return uri_loc_to_string (uri); | 1885 | return uri_loc_to_string (uri); |
1927 | default: | 1886 | default: |
1928 | GNUNET_break (0); | 1887 | GNUNET_break (0); |
1929 | return NULL; | 1888 | return NULL; |
1930 | } | 1889 | } |
1931 | } | 1890 | } |
1932 | 1891 | ||
1933 | /* end of fs_uri.c */ | 1892 | /* end of fs_uri.c */ |