diff options
author | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
commit | 6e599264ad13e8fc105493d74d7c11d46f8739ed (patch) | |
tree | 169bef1ecbade5a659831fb169f3ae6943af127f /src/fs/fs_uri.c | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r-- | src/fs/fs_uri.c | 400 |
1 files changed, 208 insertions, 192 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 9097d9884..5a67afbc0 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -91,7 +91,6 @@ | |||
91 | #include <unistdio.h> | 91 | #include <unistdio.h> |
92 | 92 | ||
93 | 93 | ||
94 | |||
95 | /** | 94 | /** |
96 | * Get a unique key from a URI. This is for putting URIs | 95 | * Get a unique key from a URI. This is for putting URIs |
97 | * into HashMaps. The key may change between FS implementations. | 96 | * into HashMaps. The key may change between FS implementations. |
@@ -102,7 +101,7 @@ | |||
102 | */ | 101 | */ |
103 | int | 102 | int |
104 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | 103 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, |
105 | struct GNUNET_HashCode *key) | 104 | struct GNUNET_HashCode *key) |
106 | { | 105 | { |
107 | switch (uri->type) | 106 | switch (uri->type) |
108 | { | 107 | { |
@@ -112,14 +111,14 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
112 | case GNUNET_FS_URI_SKS: | 111 | case GNUNET_FS_URI_SKS: |
113 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, | 112 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, |
114 | strlen (uri->data.sks.identifier), | 113 | strlen (uri->data.sks.identifier), |
115 | key); | 114 | key); |
116 | return GNUNET_OK; | 115 | return GNUNET_OK; |
117 | case GNUNET_FS_URI_KSK: | 116 | case GNUNET_FS_URI_KSK: |
118 | if (uri->data.ksk.keywordCount > 0) | 117 | if (uri->data.ksk.keywordCount > 0) |
119 | { | 118 | { |
120 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], | 119 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], |
121 | strlen (uri->data.ksk.keywords[0]), | 120 | strlen (uri->data.ksk.keywords[0]), |
122 | key); | 121 | key); |
123 | return GNUNET_OK; | 122 | return GNUNET_OK; |
124 | } | 123 | } |
125 | else | 124 | else |
@@ -131,7 +130,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
131 | case GNUNET_FS_URI_LOC: | 130 | case GNUNET_FS_URI_LOC: |
132 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, | 131 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, |
133 | sizeof (struct FileIdentifier) + | 132 | sizeof (struct FileIdentifier) + |
134 | sizeof (struct GNUNET_PeerIdentity), | 133 | sizeof (struct GNUNET_PeerIdentity), |
135 | key); | 134 | key); |
136 | return GNUNET_OK; | 135 | return GNUNET_OK; |
137 | default: | 136 | default: |
@@ -213,8 +212,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) | |||
213 | * @return decodded string with leading space (or preserved plus) | 212 | * @return decodded string with leading space (or preserved plus) |
214 | */ | 213 | */ |
215 | static char * | 214 | static char * |
216 | percent_decode_keyword (const char *in, | 215 | percent_decode_keyword (const char *in, char **emsg) |
217 | char **emsg) | ||
218 | { | 216 | { |
219 | char *out; | 217 | char *out; |
220 | char *ret; | 218 | char *ret; |
@@ -229,16 +227,17 @@ percent_decode_keyword (const char *in, | |||
229 | { | 227 | { |
230 | if (out[rpos] == '%') | 228 | if (out[rpos] == '%') |
231 | { | 229 | { |
232 | if (1 != SSCANF (&out[rpos + 1], "%2X", &hx)) | 230 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) |
233 | { | 231 | { |
234 | GNUNET_free (out); | 232 | GNUNET_free (out); |
235 | *emsg = GNUNET_strdup (_(/* xgettext:no-c-format */ | 233 | *emsg = GNUNET_strdup ( |
236 | "Malformed KSK URI (`%' must be followed by HEX number)")); | 234 | _ (/* xgettext:no-c-format */ |
235 | "Malformed KSK URI (`%' must be followed by HEX number)")); | ||
237 | return NULL; | 236 | return NULL; |
238 | } | 237 | } |
239 | rpos += 3; | 238 | rpos += 3; |
240 | if (hx == '"') | 239 | if (hx == '"') |
241 | continue; /* skip double quote */ | 240 | continue; /* skip double quote */ |
242 | out[wpos++] = (char) hx; | 241 | out[wpos++] = (char) hx; |
243 | } | 242 | } |
244 | else | 243 | else |
@@ -272,8 +271,7 @@ percent_decode_keyword (const char *in, | |||
272 | * @return NULL on error, otherwise the KSK URI | 271 | * @return NULL on error, otherwise the KSK URI |
273 | */ | 272 | */ |
274 | static struct GNUNET_FS_Uri * | 273 | static struct GNUNET_FS_Uri * |
275 | uri_ksk_parse (const char *s, | 274 | uri_ksk_parse (const char *s, char **emsg) |
276 | char **emsg) | ||
277 | { | 275 | { |
278 | struct GNUNET_FS_Uri *ret; | 276 | struct GNUNET_FS_Uri *ret; |
279 | char **keywords; | 277 | char **keywords; |
@@ -288,11 +286,11 @@ uri_ksk_parse (const char *s, | |||
288 | slen = strlen (s); | 286 | slen = strlen (s); |
289 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); | 287 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); |
290 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) | 288 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) |
291 | return NULL; /* not KSK URI */ | 289 | return NULL; /* not KSK URI */ |
292 | if ((s[slen - 1] == '+') || (s[pos] == '+')) | 290 | if ((s[slen - 1] == '+') || (s[pos] == '+')) |
293 | { | 291 | { |
294 | *emsg = | 292 | *emsg = |
295 | GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); | 293 | GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')")); |
296 | return NULL; | 294 | return NULL; |
297 | } | 295 | } |
298 | max = 1; | 296 | max = 1; |
@@ -310,20 +308,19 @@ uri_ksk_parse (const char *s, | |||
310 | max++; | 308 | max++; |
311 | if (s[i - 1] == '+') | 309 | if (s[i - 1] == '+') |
312 | { | 310 | { |
313 | *emsg = GNUNET_strdup (_("Malformed KSK URI (`++' not allowed)")); | 311 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)")); |
314 | return NULL; | 312 | return NULL; |
315 | } | 313 | } |
316 | } | 314 | } |
317 | } | 315 | } |
318 | if (saw_quote == 1) | 316 | if (saw_quote == 1) |
319 | { | 317 | { |
320 | *emsg = GNUNET_strdup (_("Malformed KSK URI (quotes not balanced)")); | 318 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)")); |
321 | return NULL; | 319 | return NULL; |
322 | } | 320 | } |
323 | iret = max; | 321 | iret = max; |
324 | dup = GNUNET_strdup (s); | 322 | dup = GNUNET_strdup (s); |
325 | keywords = GNUNET_new_array (max, | 323 | keywords = GNUNET_new_array (max, char *); |
326 | char *); | ||
327 | for (i = slen - 1; i >= (int) pos; i--) | 324 | for (i = slen - 1; i >= (int) pos; i--) |
328 | { | 325 | { |
329 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | 326 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) |
@@ -368,8 +365,7 @@ CLEANUP: | |||
368 | * @return NULL on error, SKS URI otherwise | 365 | * @return NULL on error, SKS URI otherwise |
369 | */ | 366 | */ |
370 | static struct GNUNET_FS_Uri * | 367 | static struct GNUNET_FS_Uri * |
371 | uri_sks_parse (const char *s, | 368 | uri_sks_parse (const char *s, char **emsg) |
372 | char **emsg) | ||
373 | { | 369 | { |
374 | struct GNUNET_FS_Uri *ret; | 370 | struct GNUNET_FS_Uri *ret; |
375 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; | 371 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; |
@@ -378,16 +374,15 @@ uri_sks_parse (const char *s, | |||
378 | 374 | ||
379 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); | 375 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); |
380 | if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) | 376 | if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) |
381 | return NULL; /* not an SKS URI */ | 377 | return NULL; /* not an SKS URI */ |
382 | end = strchr (&s[pos], '/'); | 378 | end = strchr (&s[pos], '/'); |
383 | if ( (NULL == end) || | 379 | if ((NULL == end) || |
384 | (GNUNET_OK != | 380 | (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos], |
385 | GNUNET_STRINGS_string_to_data (&s[pos], | 381 | end - &s[pos], |
386 | end - &s[pos], | 382 | &ns, |
387 | &ns, | 383 | sizeof (ns)))) |
388 | sizeof (ns))) ) | ||
389 | { | 384 | { |
390 | *emsg = GNUNET_strdup (_("Malformed SKS URI (wrong syntax)")); | 385 | *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)")); |
391 | return NULL; /* malformed */ | 386 | return NULL; /* malformed */ |
392 | } | 387 | } |
393 | end++; /* skip over '/' */ | 388 | end++; /* skip over '/' */ |
@@ -409,8 +404,7 @@ uri_sks_parse (const char *s, | |||
409 | * @return NULL on error, CHK URI otherwise | 404 | * @return NULL on error, CHK URI otherwise |
410 | */ | 405 | */ |
411 | static struct GNUNET_FS_Uri * | 406 | static struct GNUNET_FS_Uri * |
412 | uri_chk_parse (const char *s, | 407 | uri_chk_parse (const char *s, char **emsg) |
413 | char **emsg) | ||
414 | { | 408 | { |
415 | struct GNUNET_FS_Uri *ret; | 409 | struct GNUNET_FS_Uri *ret; |
416 | struct FileIdentifier fi; | 410 | struct FileIdentifier fi; |
@@ -424,26 +418,28 @@ uri_chk_parse (const char *s, | |||
424 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); | 418 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); |
425 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 419 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
426 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) | 420 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) |
427 | return NULL; /* not a CHK URI */ | 421 | return NULL; /* not a CHK URI */ |
428 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 422 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
429 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 423 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
430 | { | 424 | { |
431 | *emsg = GNUNET_strdup (_("Malformed CHK URI (wrong syntax)")); | 425 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)")); |
432 | return NULL; | 426 | return NULL; |
433 | } | 427 | } |
434 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 428 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
435 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 429 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
436 | GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | 430 | GNUNET_memcpy (h2, |
437 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 431 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
432 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
438 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 433 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
439 | 434 | ||
440 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || | 435 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || |
441 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || | 436 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || |
442 | (1 != | 437 | (1 != |
443 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 438 | sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
444 | "%llu", &flen))) | 439 | "%llu", |
440 | &flen))) | ||
445 | { | 441 | { |
446 | *emsg = GNUNET_strdup (_("Malformed CHK URI (failed to decode CHK)")); | 442 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)")); |
447 | return NULL; | 443 | return NULL; |
448 | } | 444 | } |
449 | fi.file_length = GNUNET_htonll (flen); | 445 | fi.file_length = GNUNET_htonll (flen); |
@@ -481,7 +477,6 @@ struct LocUriAssembly | |||
481 | * Peer offering the file. | 477 | * Peer offering the file. |
482 | */ | 478 | */ |
483 | struct GNUNET_PeerIdentity peer; | 479 | struct GNUNET_PeerIdentity peer; |
484 | |||
485 | }; | 480 | }; |
486 | GNUNET_NETWORK_STRUCT_END | 481 | GNUNET_NETWORK_STRUCT_END |
487 | 482 | ||
@@ -499,8 +494,7 @@ GNUNET_NETWORK_STRUCT_END | |||
499 | * @return NULL on error, valid LOC URI otherwise | 494 | * @return NULL on error, valid LOC URI otherwise |
500 | */ | 495 | */ |
501 | static struct GNUNET_FS_Uri * | 496 | static struct GNUNET_FS_Uri * |
502 | uri_loc_parse (const char *s, | 497 | uri_loc_parse (const char *s, char **emsg) |
503 | char **emsg) | ||
504 | { | 498 | { |
505 | struct GNUNET_FS_Uri *uri; | 499 | struct GNUNET_FS_Uri *uri; |
506 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 500 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
@@ -518,26 +512,28 @@ uri_loc_parse (const char *s, | |||
518 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); | 512 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); |
519 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 513 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
520 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) | 514 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) |
521 | return NULL; /* not a LOC URI */ | 515 | return NULL; /* not a LOC URI */ |
522 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 516 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
523 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 517 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
524 | { | 518 | { |
525 | *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax)")); | 519 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)")); |
526 | return NULL; | 520 | return NULL; |
527 | } | 521 | } |
528 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 522 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
529 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 523 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
530 | GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | 524 | GNUNET_memcpy (h2, |
531 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 525 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
526 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
532 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 527 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
533 | 528 | ||
534 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || | 529 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || |
535 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || | 530 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || |
536 | (1 != | 531 | (1 != |
537 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 532 | sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
538 | "%llu", &flen))) | 533 | "%llu", |
534 | &flen))) | ||
539 | { | 535 | { |
540 | *emsg = GNUNET_strdup (_("LOC URI malformed (no CHK)")); | 536 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)")); |
541 | return NULL; | 537 | return NULL; |
542 | } | 538 | } |
543 | ass.fi.file_length = GNUNET_htonll (flen); | 539 | ass.fi.file_length = GNUNET_htonll (flen); |
@@ -547,56 +543,61 @@ uri_loc_parse (const char *s, | |||
547 | npos++; | 543 | npos++; |
548 | if (s[npos] == '\0') | 544 | if (s[npos] == '\0') |
549 | { | 545 | { |
550 | *emsg = GNUNET_strdup (_("LOC URI malformed (missing LOC)")); | 546 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)")); |
551 | goto ERR; | 547 | goto ERR; |
552 | } | 548 | } |
553 | npos++; | 549 | npos++; |
554 | if ( (strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || | 550 | if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || |
555 | ('.' != s[npos+GNUNET_CRYPTO_PKEY_ASCII_LENGTH]) ) | 551 | ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) |
556 | { | 552 | { |
557 | *emsg = | 553 | *emsg = |
558 | GNUNET_strdup (_("LOC URI malformed (wrong syntax for public key)")); | 554 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)")); |
559 | } | 555 | } |
560 | if (GNUNET_OK != | 556 | if ( |
561 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], | 557 | GNUNET_OK != |
562 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, | 558 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], |
563 | &ass.peer.public_key)) | 559 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, |
560 | &ass.peer.public_key)) | ||
564 | { | 561 | { |
565 | *emsg = | 562 | *emsg = |
566 | GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); | 563 | GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)")); |
567 | goto ERR; | 564 | goto ERR; |
568 | } | 565 | } |
569 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; | 566 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; |
570 | if (s[npos++] != '.') | 567 | if (s[npos++] != '.') |
571 | { | 568 | { |
572 | *emsg = GNUNET_strdup (_("LOC URI malformed (could not find signature)")); | 569 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)")); |
573 | goto ERR; | 570 | goto ERR; |
574 | } | 571 | } |
575 | if ( (strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || | 572 | if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || |
576 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH]) ) | 573 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) |
577 | { | 574 | { |
578 | *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for signature)")); | 575 | *emsg = |
576 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)")); | ||
579 | goto ERR; | 577 | goto ERR; |
580 | } | 578 | } |
581 | if (GNUNET_OK != | 579 | if (GNUNET_OK != |
582 | GNUNET_STRINGS_string_to_data (&s[npos], | 580 | GNUNET_STRINGS_string_to_data (&s[npos], |
583 | SIGNATURE_ASCII_LENGTH, | 581 | SIGNATURE_ASCII_LENGTH, |
584 | &sig, | 582 | &sig, |
585 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))) | 583 | sizeof ( |
584 | struct GNUNET_CRYPTO_EddsaSignature))) | ||
586 | { | 585 | { |
587 | *emsg = GNUNET_strdup (_("LOC URI malformed (could not decode signature)")); | 586 | *emsg = |
587 | GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)")); | ||
588 | goto ERR; | 588 | goto ERR; |
589 | } | 589 | } |
590 | npos += SIGNATURE_ASCII_LENGTH; | 590 | npos += SIGNATURE_ASCII_LENGTH; |
591 | if (s[npos++] != '.') | 591 | if (s[npos++] != '.') |
592 | { | 592 | { |
593 | *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for expiration time)")); | 593 | *emsg = GNUNET_strdup ( |
594 | _ ("LOC URI malformed (wrong syntax for expiration time)")); | ||
594 | goto ERR; | 595 | goto ERR; |
595 | } | 596 | } |
596 | if (1 != SSCANF (&s[npos], "%llu", &exptime)) | 597 | if (1 != sscanf (&s[npos], "%llu", &exptime)) |
597 | { | 598 | { |
598 | *emsg = | 599 | *emsg = |
599 | GNUNET_strdup (_("LOC URI malformed (could not parse expiration time)")); | 600 | GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)")); |
600 | goto ERR; | 601 | goto ERR; |
601 | } | 602 | } |
602 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 603 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); |
@@ -605,10 +606,12 @@ uri_loc_parse (const char *s, | |||
605 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 606 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
606 | if (GNUNET_OK != | 607 | if (GNUNET_OK != |
607 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, | 608 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, |
608 | &ass.purpose, &sig, &ass.peer.public_key)) | 609 | &ass.purpose, |
610 | &sig, | ||
611 | &ass.peer.public_key)) | ||
609 | { | 612 | { |
610 | *emsg = | 613 | *emsg = |
611 | GNUNET_strdup (_("LOC URI malformed (signature failed validation)")); | 614 | GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)")); |
612 | goto ERR; | 615 | goto ERR; |
613 | } | 616 | } |
614 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 617 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
@@ -632,8 +635,7 @@ ERR: | |||
632 | * @return NULL on error | 635 | * @return NULL on error |
633 | */ | 636 | */ |
634 | struct GNUNET_FS_Uri * | 637 | struct GNUNET_FS_Uri * |
635 | GNUNET_FS_uri_parse (const char *uri, | 638 | GNUNET_FS_uri_parse (const char *uri, char **emsg) |
636 | char **emsg) | ||
637 | { | 639 | { |
638 | struct GNUNET_FS_Uri *ret; | 640 | struct GNUNET_FS_Uri *ret; |
639 | char *msg; | 641 | char *msg; |
@@ -642,7 +644,7 @@ GNUNET_FS_uri_parse (const char *uri, | |||
642 | { | 644 | { |
643 | GNUNET_break (0); | 645 | GNUNET_break (0); |
644 | if (NULL != emsg) | 646 | if (NULL != emsg) |
645 | *emsg = GNUNET_strdup (_("invalid argument")); | 647 | *emsg = GNUNET_strdup (_ ("invalid argument")); |
646 | return NULL; | 648 | return NULL; |
647 | } | 649 | } |
648 | if (NULL == emsg) | 650 | if (NULL == emsg) |
@@ -654,7 +656,7 @@ GNUNET_FS_uri_parse (const char *uri, | |||
654 | (NULL != (ret = uri_loc_parse (uri, emsg)))) | 656 | (NULL != (ret = uri_loc_parse (uri, emsg)))) |
655 | return ret; | 657 | return ret; |
656 | if (NULL == *emsg) | 658 | if (NULL == *emsg) |
657 | *emsg = GNUNET_strdup (_("Unrecognized URI type")); | 659 | *emsg = GNUNET_strdup (_ ("Unrecognized URI type")); |
658 | if (emsg == &msg) | 660 | if (emsg == &msg) |
659 | GNUNET_free (msg); | 661 | GNUNET_free (msg); |
660 | return NULL; | 662 | return NULL; |
@@ -789,8 +791,9 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, | |||
789 | if (0 == strcmp (&old[1], keyword)) | 791 | if (0 == strcmp (&old[1], keyword)) |
790 | { | 792 | { |
791 | uri->data.ksk.keywords[i] = | 793 | uri->data.ksk.keywords[i] = |
792 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; | 794 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; |
793 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, | 795 | GNUNET_array_grow (uri->data.ksk.keywords, |
796 | uri->data.ksk.keywordCount, | ||
794 | uri->data.ksk.keywordCount - 1); | 797 | uri->data.ksk.keywordCount - 1); |
795 | GNUNET_free (old); | 798 | GNUNET_free (old); |
796 | return; | 799 | return; |
@@ -877,8 +880,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | |||
877 | return NULL; | 880 | return NULL; |
878 | /* we round expiration time to full seconds for SKS URIs */ | 881 | /* we round expiration time to full seconds for SKS URIs */ |
879 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; | 882 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; |
880 | GNUNET_CRYPTO_eddsa_key_get_public (sign_key, | 883 | GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key); |
881 | &my_public_key); | ||
882 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 884 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); |
883 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 885 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
884 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 886 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
@@ -906,7 +908,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | |||
906 | */ | 908 | */ |
907 | struct GNUNET_FS_Uri * | 909 | struct GNUNET_FS_Uri * |
908 | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 910 | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
909 | const char *id) | 911 | const char *id) |
910 | { | 912 | { |
911 | struct GNUNET_FS_Uri *ns_uri; | 913 | struct GNUNET_FS_Uri *ns_uri; |
912 | 914 | ||
@@ -951,8 +953,7 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | |||
951 | return NULL; | 953 | return NULL; |
952 | } | 954 | } |
953 | kc = u1->data.ksk.keywordCount; | 955 | kc = u1->data.ksk.keywordCount; |
954 | kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, | 956 | kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *); |
955 | char *); | ||
956 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 957 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
957 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); | 958 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); |
958 | for (i = 0; i < u2->data.ksk.keywordCount; i++) | 959 | for (i = 0; i < u2->data.ksk.keywordCount; i++) |
@@ -1006,14 +1007,13 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1006 | } | 1007 | } |
1007 | if (ret->data.ksk.keywordCount > 0) | 1008 | if (ret->data.ksk.keywordCount > 0) |
1008 | { | 1009 | { |
1009 | ret->data.ksk.keywords | 1010 | ret->data.ksk.keywords = |
1010 | = GNUNET_new_array (ret->data.ksk.keywordCount, | 1011 | GNUNET_new_array (ret->data.ksk.keywordCount, char *); |
1011 | char *); | ||
1012 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | 1012 | for (i = 0; i < ret->data.ksk.keywordCount; i++) |
1013 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); | 1013 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); |
1014 | } | 1014 | } |
1015 | else | 1015 | else |
1016 | ret->data.ksk.keywords = NULL; /* just to be sure */ | 1016 | ret->data.ksk.keywords = NULL; /* just to be sure */ |
1017 | break; | 1017 | break; |
1018 | case GNUNET_FS_URI_SKS: | 1018 | case GNUNET_FS_URI_SKS: |
1019 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); | 1019 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); |
@@ -1045,8 +1045,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1045 | * if keywords is not legal (i.e. empty). | 1045 | * if keywords is not legal (i.e. empty). |
1046 | */ | 1046 | */ |
1047 | struct GNUNET_FS_Uri * | 1047 | struct GNUNET_FS_Uri * |
1048 | GNUNET_FS_uri_ksk_create (const char *keywords, | 1048 | GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) |
1049 | char **emsg) | ||
1050 | { | 1049 | { |
1051 | char **keywordarr; | 1050 | char **keywordarr; |
1052 | unsigned int num_Words; | 1051 | unsigned int num_Words; |
@@ -1058,7 +1057,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1058 | 1057 | ||
1059 | if (keywords == NULL) | 1058 | if (keywords == NULL) |
1060 | { | 1059 | { |
1061 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | 1060 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); |
1062 | GNUNET_break (0); | 1061 | GNUNET_break (0); |
1063 | return NULL; | 1062 | return NULL; |
1064 | } | 1063 | } |
@@ -1085,17 +1084,16 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1085 | if (num_Words == 0) | 1084 | if (num_Words == 0) |
1086 | { | 1085 | { |
1087 | GNUNET_free (searchString); | 1086 | GNUNET_free (searchString); |
1088 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | 1087 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); |
1089 | return NULL; | 1088 | return NULL; |
1090 | } | 1089 | } |
1091 | if (saw_quote != 0) | 1090 | if (saw_quote != 0) |
1092 | { | 1091 | { |
1093 | GNUNET_free (searchString); | 1092 | GNUNET_free (searchString); |
1094 | *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); | 1093 | *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n")); |
1095 | return NULL; | 1094 | return NULL; |
1096 | } | 1095 | } |
1097 | keywordarr = GNUNET_new_array (num_Words, | 1096 | keywordarr = GNUNET_new_array (num_Words, char *); |
1098 | char *); | ||
1099 | num_Words = 0; | 1097 | num_Words = 0; |
1100 | inWord = 0; | 1098 | inWord = 0; |
1101 | pos = searchString; | 1099 | pos = searchString; |
@@ -1117,8 +1115,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1117 | pos++; | 1115 | pos++; |
1118 | } | 1116 | } |
1119 | uri = | 1117 | uri = |
1120 | GNUNET_FS_uri_ksk_create_from_args (num_Words, | 1118 | GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr); |
1121 | (const char **) keywordarr); | ||
1122 | GNUNET_free (keywordarr); | 1119 | GNUNET_free (keywordarr); |
1123 | GNUNET_free (searchString); | 1120 | GNUNET_free (searchString); |
1124 | return uri; | 1121 | return uri; |
@@ -1143,8 +1140,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1143 | * if keywords is not legal (i.e. empty). | 1140 | * if keywords is not legal (i.e. empty). |
1144 | */ | 1141 | */ |
1145 | struct GNUNET_FS_Uri * | 1142 | struct GNUNET_FS_Uri * |
1146 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | 1143 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) |
1147 | const char **argv) | ||
1148 | { | 1144 | { |
1149 | unsigned int i; | 1145 | unsigned int i; |
1150 | struct GNUNET_FS_Uri *uri; | 1146 | struct GNUNET_FS_Uri *uri; |
@@ -1160,16 +1156,16 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | |||
1160 | * handle accordingly */ | 1156 | * handle accordingly */ |
1161 | emsg = NULL; | 1157 | emsg = NULL; |
1162 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && | 1158 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && |
1163 | (0 == | 1159 | (0 == strncmp (argv[0], |
1164 | strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) | 1160 | GNUNET_FS_URI_PREFIX, |
1165 | && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | 1161 | strlen (GNUNET_FS_URI_PREFIX))) && |
1162 | (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | ||
1166 | return uri; | 1163 | return uri; |
1167 | GNUNET_free_non_null (emsg); | 1164 | GNUNET_free_non_null (emsg); |
1168 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 1165 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
1169 | uri->type = GNUNET_FS_URI_KSK; | 1166 | uri->type = GNUNET_FS_URI_KSK; |
1170 | uri->data.ksk.keywordCount = argc; | 1167 | uri->data.ksk.keywordCount = argc; |
1171 | uri->data.ksk.keywords = GNUNET_new_array (argc, | 1168 | uri->data.ksk.keywords = GNUNET_new_array (argc, char *); |
1172 | char *); | ||
1173 | for (i = 0; i < argc; i++) | 1169 | for (i = 0; i < argc; i++) |
1174 | { | 1170 | { |
1175 | keyword = argv[i]; | 1171 | keyword = argv[i]; |
@@ -1220,9 +1216,9 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1220 | return GNUNET_YES; | 1216 | return GNUNET_YES; |
1221 | return GNUNET_NO; | 1217 | return GNUNET_NO; |
1222 | case GNUNET_FS_URI_SKS: | 1218 | case GNUNET_FS_URI_SKS: |
1223 | if ((0 == | 1219 | if ((0 == memcmp (&u1->data.sks.ns, |
1224 | memcmp (&u1->data.sks.ns, &u2->data.sks.ns, | 1220 | &u2->data.sks.ns, |
1225 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && | 1221 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && |
1226 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) | 1222 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) |
1227 | 1223 | ||
1228 | return GNUNET_YES; | 1224 | return GNUNET_YES; |
@@ -1246,12 +1242,12 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1246 | } | 1242 | } |
1247 | return GNUNET_YES; | 1243 | return GNUNET_YES; |
1248 | case GNUNET_FS_URI_LOC: | 1244 | case GNUNET_FS_URI_LOC: |
1249 | if (memcmp | 1245 | if (memcmp (&u1->data.loc, |
1250 | (&u1->data.loc, &u2->data.loc, | 1246 | &u2->data.loc, |
1251 | sizeof (struct FileIdentifier) + | 1247 | sizeof (struct FileIdentifier) + |
1252 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | 1248 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + |
1253 | sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) + | 1249 | sizeof (struct GNUNET_TIME_Absolute) + |
1254 | sizeof (unsigned short)) != 0) | 1250 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) |
1255 | return GNUNET_NO; | 1251 | return GNUNET_NO; |
1256 | return GNUNET_YES; | 1252 | return GNUNET_YES; |
1257 | default: | 1253 | default: |
@@ -1285,7 +1281,7 @@ int | |||
1285 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | 1281 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, |
1286 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) | 1282 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) |
1287 | { | 1283 | { |
1288 | if (!GNUNET_FS_uri_test_sks (uri)) | 1284 | if (! GNUNET_FS_uri_test_sks (uri)) |
1289 | { | 1285 | { |
1290 | GNUNET_break (0); | 1286 | GNUNET_break (0); |
1291 | return GNUNET_SYSERR; | 1287 | return GNUNET_SYSERR; |
@@ -1304,7 +1300,7 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | |||
1304 | char * | 1300 | char * |
1305 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | 1301 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) |
1306 | { | 1302 | { |
1307 | if (!GNUNET_FS_uri_test_sks (uri)) | 1303 | if (! GNUNET_FS_uri_test_sks (uri)) |
1308 | { | 1304 | { |
1309 | GNUNET_break (0); | 1305 | GNUNET_break (0); |
1310 | return NULL; | 1306 | return NULL; |
@@ -1327,7 +1323,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) | |||
1327 | 1323 | ||
1328 | if (uri->type == GNUNET_FS_URI_KSK) | 1324 | if (uri->type == GNUNET_FS_URI_KSK) |
1329 | { | 1325 | { |
1330 | for (i=0;i < uri->data.ksk.keywordCount; i++) | 1326 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
1331 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); | 1327 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); |
1332 | } | 1328 | } |
1333 | #endif | 1329 | #endif |
@@ -1356,7 +1352,7 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) | |||
1356 | * @return size of the file as specified in the CHK URI | 1352 | * @return size of the file as specified in the CHK URI |
1357 | */ | 1353 | */ |
1358 | uint64_t | 1354 | uint64_t |
1359 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) | 1355 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) |
1360 | { | 1356 | { |
1361 | switch (uri->type) | 1357 | switch (uri->type) |
1362 | { | 1358 | { |
@@ -1367,7 +1363,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) | |||
1367 | default: | 1363 | default: |
1368 | GNUNET_assert (0); | 1364 | GNUNET_assert (0); |
1369 | } | 1365 | } |
1370 | return 0; /* unreachable */ | 1366 | return 0; /* unreachable */ |
1371 | } | 1367 | } |
1372 | 1368 | ||
1373 | 1369 | ||
@@ -1394,9 +1390,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | |||
1394 | * @param index offset where to add the keyword | 1390 | * @param index offset where to add the keyword |
1395 | */ | 1391 | */ |
1396 | static void | 1392 | static void |
1397 | insert_non_mandatory_keyword (const char *s, | 1393 | insert_non_mandatory_keyword (const char *s, char **array, int index) |
1398 | char **array, | ||
1399 | int index) | ||
1400 | { | 1394 | { |
1401 | char *nkword; | 1395 | char *nkword; |
1402 | 1396 | ||
@@ -1417,9 +1411,7 @@ insert_non_mandatory_keyword (const char *s, | |||
1417 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not | 1411 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not |
1418 | */ | 1412 | */ |
1419 | static int | 1413 | static int |
1420 | find_duplicate (const char *s, | 1414 | find_duplicate (const char *s, const char **array, int array_length) |
1421 | const char **array, | ||
1422 | int array_length) | ||
1423 | { | 1415 | { |
1424 | int j; | 1416 | int j; |
1425 | 1417 | ||
@@ -1455,12 +1447,19 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format, | |||
1455 | } | 1447 | } |
1456 | if (format == EXTRACTOR_METAFORMAT_C_STRING) | 1448 | if (format == EXTRACTOR_METAFORMAT_C_STRING) |
1457 | { | 1449 | { |
1458 | free_str = u8_strconv_from_encoding (data, locale_charset (), iconveh_escape_sequence); | 1450 | free_str = u8_strconv_from_encoding (data, |
1451 | locale_charset (), | ||
1452 | iconveh_escape_sequence); | ||
1459 | if (free_str == NULL) | 1453 | if (free_str == NULL) |
1460 | return NULL; | 1454 | return NULL; |
1461 | } | 1455 | } |
1462 | 1456 | ||
1463 | normalized = u8_tolower (str_to_normalize, strlen ((char *) str_to_normalize), NULL, UNINORM_NFD, NULL, &r_len); | 1457 | normalized = u8_tolower (str_to_normalize, |
1458 | strlen ((char *) str_to_normalize), | ||
1459 | NULL, | ||
1460 | UNINORM_NFD, | ||
1461 | NULL, | ||
1462 | &r_len); | ||
1464 | /* free_str is allocated by libunistring internally, use free() */ | 1463 | /* free_str is allocated by libunistring internally, use free() */ |
1465 | if (free_str != NULL) | 1464 | if (free_str != NULL) |
1466 | free (free_str); | 1465 | free (free_str); |
@@ -1512,9 +1511,7 @@ u8_strcount (const uint8_t *s) | |||
1512 | * were duplicates (when extracting). | 1511 | * were duplicates (when extracting). |
1513 | */ | 1512 | */ |
1514 | static int | 1513 | static int |
1515 | get_keywords_from_parens (const char *s, | 1514 | get_keywords_from_parens (const char *s, char **array, int index) |
1516 | char **array, | ||
1517 | int index) | ||
1518 | { | 1515 | { |
1519 | int count = 0; | 1516 | int count = 0; |
1520 | char *open_paren; | 1517 | char *open_paren; |
@@ -1564,28 +1561,33 @@ get_keywords_from_parens (const char *s, | |||
1564 | { | 1561 | { |
1565 | char *normalized; | 1562 | char *normalized; |
1566 | if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], | 1563 | if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], |
1567 | (const char **) array, index + count)) | 1564 | (const char **) array, |
1565 | index + count)) | ||
1568 | { | 1566 | { |
1569 | insert_non_mandatory_keyword ((const char *) &open_paren[1], array, | 1567 | insert_non_mandatory_keyword ((const char *) &open_paren[1], |
1570 | index + count); | 1568 | array, |
1569 | index + count); | ||
1571 | count++; | 1570 | count++; |
1572 | } | 1571 | } |
1573 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, | 1572 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, |
1574 | &open_paren[1], close_paren - &open_paren[1]); | 1573 | &open_paren[1], |
1574 | close_paren - &open_paren[1]); | ||
1575 | if (normalized != NULL) | 1575 | if (normalized != NULL) |
1576 | { | 1576 | { |
1577 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | 1577 | if (GNUNET_NO == find_duplicate ((const char *) normalized, |
1578 | (const char **) array, index + count)) | 1578 | (const char **) array, |
1579 | index + count)) | ||
1579 | { | 1580 | { |
1580 | insert_non_mandatory_keyword ((const char *) normalized, array, | 1581 | insert_non_mandatory_keyword ((const char *) normalized, |
1581 | index + count); | 1582 | array, |
1583 | index + count); | ||
1582 | count++; | 1584 | count++; |
1583 | } | 1585 | } |
1584 | GNUNET_free (normalized); | 1586 | GNUNET_free (normalized); |
1585 | } | 1587 | } |
1586 | } | 1588 | } |
1587 | else | 1589 | else |
1588 | count++; | 1590 | count++; |
1589 | close_paren[0] = tmp; | 1591 | close_paren[0] = tmp; |
1590 | } | 1592 | } |
1591 | } | 1593 | } |
@@ -1614,9 +1616,7 @@ get_keywords_from_parens (const char *s, | |||
1614 | * duplicates (when extracting). | 1616 | * duplicates (when extracting). |
1615 | */ | 1617 | */ |
1616 | static int | 1618 | static int |
1617 | get_keywords_from_tokens (const char *s, | 1619 | get_keywords_from_tokens (const char *s, char **array, int index) |
1618 | char **array, | ||
1619 | int index) | ||
1620 | { | 1620 | { |
1621 | char *p; | 1621 | char *p; |
1622 | char *ss; | 1622 | char *ss; |
@@ -1633,19 +1633,20 @@ get_keywords_from_tokens (const char *s, | |||
1633 | char *normalized; | 1633 | char *normalized; |
1634 | if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) | 1634 | if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) |
1635 | { | 1635 | { |
1636 | insert_non_mandatory_keyword (p, array, | 1636 | insert_non_mandatory_keyword (p, array, index + seps); |
1637 | index + seps); | 1637 | seps++; |
1638 | seps++; | ||
1639 | } | 1638 | } |
1640 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, | 1639 | normalized = |
1641 | p, strlen (p)); | 1640 | normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p)); |
1642 | if (normalized != NULL) | 1641 | if (normalized != NULL) |
1643 | { | 1642 | { |
1644 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | 1643 | if (GNUNET_NO == find_duplicate ((const char *) normalized, |
1645 | (const char **) array, index + seps)) | 1644 | (const char **) array, |
1645 | index + seps)) | ||
1646 | { | 1646 | { |
1647 | insert_non_mandatory_keyword ((const char *) normalized, array, | 1647 | insert_non_mandatory_keyword ((const char *) normalized, |
1648 | index + seps); | 1648 | array, |
1649 | index + seps); | ||
1649 | seps++; | 1650 | seps++; |
1650 | } | 1651 | } |
1651 | GNUNET_free (normalized); | 1652 | GNUNET_free (normalized); |
@@ -1678,7 +1679,8 @@ get_keywords_from_tokens (const char *s, | |||
1678 | * @return 0 (always) | 1679 | * @return 0 (always) |
1679 | */ | 1680 | */ |
1680 | static int | 1681 | static int |
1681 | gather_uri_data (void *cls, const char *plugin_name, | 1682 | gather_uri_data (void *cls, |
1683 | const char *plugin_name, | ||
1682 | enum EXTRACTOR_MetaType type, | 1684 | enum EXTRACTOR_MetaType type, |
1683 | enum EXTRACTOR_MetaFormat format, | 1685 | enum EXTRACTOR_MetaFormat format, |
1684 | const char *data_mime_type, | 1686 | const char *data_mime_type, |
@@ -1699,16 +1701,12 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1699 | */ | 1701 | */ |
1700 | if (u8_strcount ((const uint8_t *) data) <= 2) | 1702 | if (u8_strcount ((const uint8_t *) data) <= 2) |
1701 | return 0; | 1703 | return 0; |
1702 | if ( (EXTRACTOR_METATYPE_MIMETYPE == type) && | 1704 | if ((EXTRACTOR_METATYPE_MIMETYPE == type) && |
1703 | (NULL != (sep = memchr (data, '/', data_len))) && | 1705 | (NULL != (sep = memchr (data, '/', data_len))) && (sep != data)) |
1704 | (sep != data) ) | ||
1705 | { | 1706 | { |
1706 | char *xtra; | 1707 | char *xtra; |
1707 | 1708 | ||
1708 | GNUNET_asprintf (&xtra, | 1709 | GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data); |
1709 | "mimetype:%.*s", | ||
1710 | (int) (sep - data), | ||
1711 | data); | ||
1712 | if (! find_duplicate (xtra, | 1710 | if (! find_duplicate (xtra, |
1713 | (const char **) uri->data.ksk.keywords, | 1711 | (const char **) uri->data.ksk.keywords, |
1714 | uri->data.ksk.keywordCount)) | 1712 | uri->data.ksk.keywordCount)) |
@@ -1727,17 +1725,19 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1727 | uri->data.ksk.keywordCount)) | 1725 | uri->data.ksk.keywordCount)) |
1728 | { | 1726 | { |
1729 | insert_non_mandatory_keyword (data, | 1727 | insert_non_mandatory_keyword (data, |
1730 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); | 1728 | uri->data.ksk.keywords, |
1729 | uri->data.ksk.keywordCount); | ||
1731 | uri->data.ksk.keywordCount++; | 1730 | uri->data.ksk.keywordCount++; |
1732 | } | 1731 | } |
1733 | if (NULL != normalized_data) | 1732 | if (NULL != normalized_data) |
1734 | { | 1733 | { |
1735 | if (! find_duplicate (normalized_data, | 1734 | if (! find_duplicate (normalized_data, |
1736 | (const char **) uri->data.ksk.keywords, | 1735 | (const char **) uri->data.ksk.keywords, |
1737 | uri->data.ksk.keywordCount)) | 1736 | uri->data.ksk.keywordCount)) |
1738 | { | 1737 | { |
1739 | insert_non_mandatory_keyword (normalized_data, | 1738 | insert_non_mandatory_keyword (normalized_data, |
1740 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); | 1739 | uri->data.ksk.keywords, |
1740 | uri->data.ksk.keywordCount); | ||
1741 | uri->data.ksk.keywordCount++; | 1741 | uri->data.ksk.keywordCount++; |
1742 | } | 1742 | } |
1743 | GNUNET_free (normalized_data); | 1743 | GNUNET_free (normalized_data); |
@@ -1755,7 +1755,8 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1755 | * @return NULL on error, otherwise a KSK URI | 1755 | * @return NULL on error, otherwise a KSK URI |
1756 | */ | 1756 | */ |
1757 | struct GNUNET_FS_Uri * | 1757 | struct GNUNET_FS_Uri * |
1758 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) | 1758 | GNUNET_FS_uri_ksk_create_from_meta_data ( |
1759 | const struct GNUNET_CONTAINER_MetaData *md) | ||
1759 | { | 1760 | { |
1760 | struct GNUNET_FS_Uri *ret; | 1761 | struct GNUNET_FS_Uri *ret; |
1761 | char *filename; | 1762 | char *filename; |
@@ -1772,8 +1773,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1772 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); | 1773 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); |
1773 | if (ent > 0) | 1774 | if (ent > 0) |
1774 | { | 1775 | { |
1775 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (md, | 1776 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types ( |
1776 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, -1); | 1777 | md, |
1778 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
1779 | -1); | ||
1777 | if (NULL != full_name) | 1780 | if (NULL != full_name) |
1778 | { | 1781 | { |
1779 | filename = full_name; | 1782 | filename = full_name; |
@@ -1784,19 +1787,20 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1784 | } | 1787 | } |
1785 | /* x3 because there might be a normalized variant of every keyword, | 1788 | /* x3 because there might be a normalized variant of every keyword, |
1786 | plus theoretically one more for mime... */ | 1789 | plus theoretically one more for mime... */ |
1787 | ret->data.ksk.keywords | 1790 | ret->data.ksk.keywords = |
1788 | = GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, | 1791 | GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *); |
1789 | char *); | ||
1790 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); | 1792 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); |
1791 | } | 1793 | } |
1792 | if (tok_keywords > 0) | 1794 | if (tok_keywords > 0) |
1793 | ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, | 1795 | ret->data.ksk.keywordCount += |
1794 | ret->data.ksk.keywords, | 1796 | get_keywords_from_tokens (filename, |
1795 | ret->data.ksk.keywordCount); | 1797 | ret->data.ksk.keywords, |
1798 | ret->data.ksk.keywordCount); | ||
1796 | if (paren_keywords > 0) | 1799 | if (paren_keywords > 0) |
1797 | ret->data.ksk.keywordCount += get_keywords_from_parens (filename, | 1800 | ret->data.ksk.keywordCount += |
1798 | ret->data.ksk.keywords, | 1801 | get_keywords_from_parens (filename, |
1799 | ret->data.ksk.keywordCount); | 1802 | ret->data.ksk.keywords, |
1803 | ret->data.ksk.keywordCount); | ||
1800 | if (ent > 0) | 1804 | if (ent > 0) |
1801 | GNUNET_free_non_null (full_name); | 1805 | GNUNET_free_non_null (full_name); |
1802 | return ret; | 1806 | return ret; |
@@ -1810,9 +1814,8 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1810 | static int | 1814 | static int |
1811 | needs_percent (char c) | 1815 | needs_percent (char c) |
1812 | { | 1816 | { |
1813 | return (! | 1817 | return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || |
1814 | ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || | 1818 | (c == '.') || (c == '~'))); |
1815 | (c == '.') || (c == '~'))); | ||
1816 | } | 1819 | } |
1817 | 1820 | ||
1818 | 1821 | ||
@@ -1851,10 +1854,10 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1851 | if ((j == 0) && (keyword[j] == ' ')) | 1854 | if ((j == 0) && (keyword[j] == ' ')) |
1852 | { | 1855 | { |
1853 | n--; | 1856 | n--; |
1854 | continue; /* skip leading space */ | 1857 | continue; /* skip leading space */ |
1855 | } | 1858 | } |
1856 | if (needs_percent (keyword[j])) | 1859 | if (needs_percent (keyword[j])) |
1857 | n += 2; /* will use %-encoding */ | 1860 | n += 2; /* will use %-encoding */ |
1858 | } | 1861 | } |
1859 | } | 1862 | } |
1860 | ret = GNUNET_malloc (n); | 1863 | ret = GNUNET_malloc (n); |
@@ -1868,7 +1871,7 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1868 | for (j = 0; j < slen; j++) | 1871 | for (j = 0; j < slen; j++) |
1869 | { | 1872 | { |
1870 | if ((j == 0) && (keyword[j] == ' ')) | 1873 | if ((j == 0) && (keyword[j] == ' ')) |
1871 | continue; /* skip leading space */ | 1874 | continue; /* skip leading space */ |
1872 | if (needs_percent (keyword[j])) | 1875 | if (needs_percent (keyword[j])) |
1873 | { | 1876 | { |
1874 | sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); | 1877 | sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); |
@@ -1900,15 +1903,19 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1900 | 1903 | ||
1901 | if (GNUNET_FS_URI_SKS != uri->type) | 1904 | if (GNUNET_FS_URI_SKS != uri->type) |
1902 | return NULL; | 1905 | return NULL; |
1903 | ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, | 1906 | ret = |
1904 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | 1907 | GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, |
1905 | buf, | 1908 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), |
1906 | sizeof (buf)); | 1909 | buf, |
1910 | sizeof (buf)); | ||
1907 | GNUNET_assert (NULL != ret); | 1911 | GNUNET_assert (NULL != ret); |
1908 | ret[0] = '\0'; | 1912 | ret[0] = '\0'; |
1909 | GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, | 1913 | GNUNET_asprintf (&ret, |
1910 | GNUNET_FS_URI_SKS_INFIX, buf, | 1914 | "%s%s%s/%s", |
1911 | uri->data.sks.identifier); | 1915 | GNUNET_FS_URI_PREFIX, |
1916 | GNUNET_FS_URI_SKS_INFIX, | ||
1917 | buf, | ||
1918 | uri->data.sks.identifier); | ||
1912 | return ret; | 1919 | return ret; |
1913 | } | 1920 | } |
1914 | 1921 | ||
@@ -1933,9 +1940,13 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1933 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); | 1940 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); |
1934 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); | 1941 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); |
1935 | 1942 | ||
1936 | GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX, | 1943 | GNUNET_asprintf (&ret, |
1937 | GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash, | 1944 | "%s%s%s.%s.%llu", |
1938 | (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); | 1945 | GNUNET_FS_URI_PREFIX, |
1946 | GNUNET_FS_URI_CHK_INFIX, | ||
1947 | (const char *) &keyhash, | ||
1948 | (const char *) &queryhash, | ||
1949 | GNUNET_ntohll (fi->file_length)); | ||
1939 | return ret; | 1950 | return ret; |
1940 | } | 1951 | } |
1941 | 1952 | ||
@@ -1959,20 +1970,25 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
1959 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); | 1970 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
1960 | peer_id = | 1971 | peer_id = |
1961 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); | 1972 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); |
1962 | GNUNET_assert (NULL != | 1973 | GNUNET_assert ( |
1963 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, | 1974 | NULL != |
1964 | sizeof (struct GNUNET_CRYPTO_EddsaSignature), | 1975 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, |
1965 | peer_sig, | 1976 | sizeof (struct GNUNET_CRYPTO_EddsaSignature), |
1966 | sizeof (peer_sig))); | 1977 | peer_sig, |
1978 | sizeof (peer_sig))); | ||
1967 | GNUNET_asprintf (&ret, | 1979 | GNUNET_asprintf (&ret, |
1968 | "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, | 1980 | "%s%s%s.%s.%llu.%s.%s.%llu", |
1969 | GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, | 1981 | GNUNET_FS_URI_PREFIX, |
1982 | GNUNET_FS_URI_LOC_INFIX, | ||
1983 | (const char *) &keyhash, | ||
1970 | (const char *) &queryhash, | 1984 | (const char *) &queryhash, |
1971 | (unsigned long long) GNUNET_ntohll (uri->data.loc. | 1985 | (unsigned long long) GNUNET_ntohll ( |
1972 | fi.file_length), | 1986 | uri->data.loc.fi.file_length), |
1973 | peer_id, | 1987 | peer_id, |
1974 | peer_sig, | 1988 | peer_sig, |
1975 | (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL); | 1989 | (unsigned long long) |
1990 | uri->data.loc.expirationTime.abs_value_us / | ||
1991 | 1000000LL); | ||
1976 | GNUNET_free (peer_id); | 1992 | GNUNET_free (peer_id); |
1977 | return ret; | 1993 | return ret; |
1978 | } | 1994 | } |