aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r--src/fs/fs_uri.c1739
1 files changed, 870 insertions, 869 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index c9ce19114..7eb9f86b0 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -100,47 +100,47 @@
100 * @return #GNUNET_OK on success 100 * @return #GNUNET_OK on success
101 */ 101 */
102int 102int
103GNUNET_FS_uri_to_key(const struct GNUNET_FS_Uri *uri, 103GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
104 struct GNUNET_HashCode *key) 104 struct GNUNET_HashCode *key)
105{ 105{
106 switch (uri->type) 106 switch (uri->type)
107 {
108 case GNUNET_FS_URI_CHK:
109 *key = uri->data.chk.chk.query;
110 return GNUNET_OK;
111
112 case GNUNET_FS_URI_SKS:
113 GNUNET_CRYPTO_hash (uri->data.sks.identifier,
114 strlen (uri->data.sks.identifier),
115 key);
116 return GNUNET_OK;
117
118 case GNUNET_FS_URI_KSK:
119 if (uri->data.ksk.keywordCount > 0)
107 { 120 {
108 case GNUNET_FS_URI_CHK: 121 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
109 *key = uri->data.chk.chk.query; 122 strlen (uri->data.ksk.keywords[0]),
123 key);
110 return GNUNET_OK; 124 return GNUNET_OK;
111 125 }
112 case GNUNET_FS_URI_SKS: 126 else
113 GNUNET_CRYPTO_hash(uri->data.sks.identifier, 127 {
114 strlen(uri->data.sks.identifier), 128 memset (key, 0, sizeof(struct GNUNET_HashCode));
115 key);
116 return GNUNET_OK;
117
118 case GNUNET_FS_URI_KSK:
119 if (uri->data.ksk.keywordCount > 0)
120 {
121 GNUNET_CRYPTO_hash(uri->data.ksk.keywords[0],
122 strlen(uri->data.ksk.keywords[0]),
123 key);
124 return GNUNET_OK;
125 }
126 else
127 {
128 memset(key, 0, sizeof(struct GNUNET_HashCode));
129 return GNUNET_SYSERR;
130 }
131 break;
132
133 case GNUNET_FS_URI_LOC:
134 GNUNET_CRYPTO_hash(&uri->data.loc.fi,
135 sizeof(struct FileIdentifier) +
136 sizeof(struct GNUNET_PeerIdentity),
137 key);
138 return GNUNET_OK;
139
140 default:
141 memset(key, 0, sizeof(struct GNUNET_HashCode));
142 return GNUNET_SYSERR; 129 return GNUNET_SYSERR;
143 } 130 }
131 break;
132
133 case GNUNET_FS_URI_LOC:
134 GNUNET_CRYPTO_hash (&uri->data.loc.fi,
135 sizeof(struct FileIdentifier)
136 + sizeof(struct GNUNET_PeerIdentity),
137 key);
138 return GNUNET_OK;
139
140 default:
141 memset (key, 0, sizeof(struct GNUNET_HashCode));
142 return GNUNET_SYSERR;
143 }
144} 144}
145 145
146 146
@@ -152,7 +152,7 @@ GNUNET_FS_uri_to_key(const struct GNUNET_FS_Uri *uri,
152 * @return string with the keywords 152 * @return string with the keywords
153 */ 153 */
154char * 154char *
155GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri) 155GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri)
156{ 156{
157 size_t n; 157 size_t n;
158 char *ret; 158 char *ret;
@@ -162,45 +162,45 @@ GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri)
162 unsigned int keywordCount; 162 unsigned int keywordCount;
163 163
164 if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type)) 164 if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type))
165 { 165 {
166 GNUNET_break(0); 166 GNUNET_break (0);
167 return NULL; 167 return NULL;
168 } 168 }
169 keywords = uri->data.ksk.keywords; 169 keywords = uri->data.ksk.keywords;
170 keywordCount = uri->data.ksk.keywordCount; 170 keywordCount = uri->data.ksk.keywordCount;
171 n = keywordCount + 1; 171 n = keywordCount + 1;
172 for (i = 0; i < keywordCount; i++) 172 for (i = 0; i < keywordCount; i++)
173 {
174 keyword = keywords[i];
175 n += strlen (keyword) - 1;
176 if (NULL != strstr (&keyword[1], " "))
177 n += 2;
178 if (keyword[0] == '+')
179 n++;
180 }
181 ret = GNUNET_malloc (n);
182 strcpy (ret, "");
183 for (i = 0; i < keywordCount; i++)
184 {
185 keyword = keywords[i];
186 if (NULL != strstr (&keyword[1], " "))
173 { 187 {
174 keyword = keywords[i]; 188 strcat (ret, "\"");
175 n += strlen(keyword) - 1;
176 if (NULL != strstr(&keyword[1], " "))
177 n += 2;
178 if (keyword[0] == '+') 189 if (keyword[0] == '+')
179 n++; 190 strcat (ret, keyword);
191 else
192 strcat (ret, &keyword[1]);
193 strcat (ret, "\"");
180 } 194 }
181 ret = GNUNET_malloc(n); 195 else
182 strcpy(ret, "");
183 for (i = 0; i < keywordCount; i++)
184 { 196 {
185 keyword = keywords[i]; 197 if (keyword[0] == '+')
186 if (NULL != strstr(&keyword[1], " ")) 198 strcat (ret, keyword);
187 {
188 strcat(ret, "\"");
189 if (keyword[0] == '+')
190 strcat(ret, keyword);
191 else
192 strcat(ret, &keyword[1]);
193 strcat(ret, "\"");
194 }
195 else 199 else
196 { 200 strcat (ret, &keyword[1]);
197 if (keyword[0] == '+')
198 strcat(ret, keyword);
199 else
200 strcat(ret, &keyword[1]);
201 }
202 strcat(ret, " ");
203 } 201 }
202 strcat (ret, " ");
203 }
204 return ret; 204 return ret;
205} 205}
206 206
@@ -216,7 +216,7 @@ GNUNET_FS_uri_ksk_to_string_fancy(const struct GNUNET_FS_Uri *uri)
216 * @return decodded string with leading space (or preserved plus) 216 * @return decodded string with leading space (or preserved plus)
217 */ 217 */
218static char * 218static char *
219percent_decode_keyword(const char *in, char **emsg) 219percent_decode_keyword (const char *in, char **emsg)
220{ 220{
221 char *out; 221 char *out;
222 char *ret; 222 char *ret;
@@ -224,44 +224,44 @@ percent_decode_keyword(const char *in, char **emsg)
224 unsigned int wpos; 224 unsigned int wpos;
225 unsigned int hx; 225 unsigned int hx;
226 226
227 out = GNUNET_strdup(in); 227 out = GNUNET_strdup (in);
228 rpos = 0; 228 rpos = 0;
229 wpos = 0; 229 wpos = 0;
230 while (out[rpos] != '\0') 230 while (out[rpos] != '\0')
231 {
232 if (out[rpos] == '%')
231 { 233 {
232 if (out[rpos] == '%') 234 if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
233 { 235 {
234 if (1 != sscanf(&out[rpos + 1], "%2X", &hx)) 236 GNUNET_free (out);
235 { 237 *emsg = GNUNET_strdup (
236 GNUNET_free(out); 238 _ ( /* xgettext:no-c-format */
237 *emsg = GNUNET_strdup( 239 "Malformed KSK URI (`%' must be followed by HEX number)"));
238 _(/* xgettext:no-c-format */ 240 return NULL;
239 "Malformed KSK URI (`%' must be followed by HEX number)")); 241 }
240 return NULL; 242 rpos += 3;
241 } 243 if (hx == '"')
242 rpos += 3; 244 continue; /* skip double quote */
243 if (hx == '"') 245 out[wpos++] = (char) hx;
244 continue; /* skip double quote */
245 out[wpos++] = (char)hx;
246 }
247 else
248 {
249 out[wpos++] = out[rpos++];
250 }
251 } 246 }
252 out[wpos] = '\0'; 247 else
253 if (out[0] == '+')
254 { 248 {
255 ret = GNUNET_strdup(out); 249 out[wpos++] = out[rpos++];
256 } 250 }
251 }
252 out[wpos] = '\0';
253 if (out[0] == '+')
254 {
255 ret = GNUNET_strdup (out);
256 }
257 else 257 else
258 { 258 {
259 /* need to prefix with space */ 259 /* need to prefix with space */
260 ret = GNUNET_malloc(strlen(out) + 2); 260 ret = GNUNET_malloc (strlen (out) + 2);
261 strcpy(ret, " "); 261 strcpy (ret, " ");
262 strcat(ret, out); 262 strcat (ret, out);
263 } 263 }
264 GNUNET_free(out); 264 GNUNET_free (out);
265 return ret; 265 return ret;
266} 266}
267 267
@@ -275,7 +275,7 @@ percent_decode_keyword(const char *in, char **emsg)
275 * @return NULL on error, otherwise the KSK URI 275 * @return NULL on error, otherwise the KSK URI
276 */ 276 */
277static struct GNUNET_FS_Uri * 277static struct GNUNET_FS_Uri *
278uri_ksk_parse(const char *s, char **emsg) 278uri_ksk_parse (const char *s, char **emsg)
279{ 279{
280 struct GNUNET_FS_Uri *ret; 280 struct GNUNET_FS_Uri *ret;
281 char **keywords; 281 char **keywords;
@@ -287,74 +287,74 @@ uri_ksk_parse(const char *s, char **emsg)
287 char *dup; 287 char *dup;
288 int saw_quote; 288 int saw_quote;
289 289
290 slen = strlen(s); 290 slen = strlen (s);
291 pos = strlen(GNUNET_FS_URI_KSK_PREFIX); 291 pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
292 if ((slen <= pos) || (0 != strncmp(s, GNUNET_FS_URI_KSK_PREFIX, pos))) 292 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
293 return NULL; /* not KSK URI */ 293 return NULL; /* not KSK URI */
294 if ((s[slen - 1] == '+') || (s[pos] == '+')) 294 if ((s[slen - 1] == '+') || (s[pos] == '+'))
295 { 295 {
296 *emsg = 296 *emsg =
297 GNUNET_strdup(_("Malformed KSK URI (must not begin or end with `+')")); 297 GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')"));
298 return NULL; 298 return NULL;
299 } 299 }
300 max = 1; 300 max = 1;
301 saw_quote = 0; 301 saw_quote = 0;
302 for (i = pos; i < slen; i++) 302 for (i = pos; i < slen; i++)
303 {
304 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
303 { 305 {
304 if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) 306 saw_quote = (saw_quote + 1) % 2;
305 { 307 i += 3;
306 saw_quote = (saw_quote + 1) % 2; 308 continue;
307 i += 3;
308 continue;
309 }
310 if ((s[i] == '+') && (saw_quote == 0))
311 {
312 max++;
313 if (s[i - 1] == '+')
314 {
315 *emsg = GNUNET_strdup(_("Malformed KSK URI (`++' not allowed)"));
316 return NULL;
317 }
318 }
319 } 309 }
320 if (saw_quote == 1) 310 if ((s[i] == '+') && (saw_quote == 0))
321 { 311 {
322 *emsg = GNUNET_strdup(_("Malformed KSK URI (quotes not balanced)")); 312 max++;
323 return NULL; 313 if (s[i - 1] == '+')
314 {
315 *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)"));
316 return NULL;
317 }
324 } 318 }
319 }
320 if (saw_quote == 1)
321 {
322 *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)"));
323 return NULL;
324 }
325 iret = max; 325 iret = max;
326 dup = GNUNET_strdup(s); 326 dup = GNUNET_strdup (s);
327 keywords = GNUNET_new_array(max, char *); 327 keywords = GNUNET_new_array (max, char *);
328 for (i = slen - 1; i >= (int)pos; i--) 328 for (i = slen - 1; i >= (int) pos; i--)
329 {
330 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
329 { 331 {
330 if ((s[i] == '%') && (&s[i] == strstr(&s[i], "%22"))) 332 saw_quote = (saw_quote + 1) % 2;
331 { 333 continue;
332 saw_quote = (saw_quote + 1) % 2;
333 continue;
334 }
335 if ((dup[i] == '+') && (saw_quote == 0))
336 {
337 keywords[--max] = percent_decode_keyword(&dup[i + 1], emsg);
338 if (NULL == keywords[max])
339 goto CLEANUP;
340 dup[i] = '\0';
341 }
342 } 334 }
343 keywords[--max] = percent_decode_keyword(&dup[pos], emsg); 335 if ((dup[i] == '+') && (saw_quote == 0))
336 {
337 keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg);
338 if (NULL == keywords[max])
339 goto CLEANUP;
340 dup[i] = '\0';
341 }
342 }
343 keywords[--max] = percent_decode_keyword (&dup[pos], emsg);
344 if (NULL == keywords[max]) 344 if (NULL == keywords[max])
345 goto CLEANUP; 345 goto CLEANUP;
346 GNUNET_assert(0 == max); 346 GNUNET_assert (0 == max);
347 GNUNET_free(dup); 347 GNUNET_free (dup);
348 ret = GNUNET_new(struct GNUNET_FS_Uri); 348 ret = GNUNET_new (struct GNUNET_FS_Uri);
349 ret->type = GNUNET_FS_URI_KSK; 349 ret->type = GNUNET_FS_URI_KSK;
350 ret->data.ksk.keywordCount = iret; 350 ret->data.ksk.keywordCount = iret;
351 ret->data.ksk.keywords = keywords; 351 ret->data.ksk.keywords = keywords;
352 return ret; 352 return ret;
353CLEANUP: 353CLEANUP:
354 for (i = 0; i < max; i++) 354 for (i = 0; i < max; i++)
355 GNUNET_free_non_null(keywords[i]); 355 GNUNET_free_non_null (keywords[i]);
356 GNUNET_free(keywords); 356 GNUNET_free (keywords);
357 GNUNET_free(dup); 357 GNUNET_free (dup);
358 return NULL; 358 return NULL;
359} 359}
360 360
@@ -369,31 +369,31 @@ CLEANUP:
369 * @return NULL on error, SKS URI otherwise 369 * @return NULL on error, SKS URI otherwise
370 */ 370 */
371static struct GNUNET_FS_Uri * 371static struct GNUNET_FS_Uri *
372uri_sks_parse(const char *s, char **emsg) 372uri_sks_parse (const char *s, char **emsg)
373{ 373{
374 struct GNUNET_FS_Uri *ret; 374 struct GNUNET_FS_Uri *ret;
375 struct GNUNET_CRYPTO_EcdsaPublicKey ns; 375 struct GNUNET_CRYPTO_EcdsaPublicKey ns;
376 size_t pos; 376 size_t pos;
377 char *end; 377 char *end;
378 378
379 pos = strlen(GNUNET_FS_URI_SKS_PREFIX); 379 pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
380 if ((strlen(s) <= pos) || (0 != strncmp(s, GNUNET_FS_URI_SKS_PREFIX, pos))) 380 if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
381 return NULL; /* not an SKS URI */ 381 return NULL; /* not an SKS URI */
382 end = strchr(&s[pos], '/'); 382 end = strchr (&s[pos], '/');
383 if ((NULL == end) || 383 if ((NULL == end) ||
384 (GNUNET_OK != GNUNET_STRINGS_string_to_data(&s[pos], 384 (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos],
385 end - &s[pos], 385 end - &s[pos],
386 &ns, 386 &ns,
387 sizeof(ns)))) 387 sizeof(ns))))
388 { 388 {
389 *emsg = GNUNET_strdup(_("Malformed SKS URI (wrong syntax)")); 389 *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)"));
390 return NULL; /* malformed */ 390 return NULL; /* malformed */
391 } 391 }
392 end++; /* skip over '/' */ 392 end++; /* skip over '/' */
393 ret = GNUNET_new(struct GNUNET_FS_Uri); 393 ret = GNUNET_new (struct GNUNET_FS_Uri);
394 ret->type = GNUNET_FS_URI_SKS; 394 ret->type = GNUNET_FS_URI_SKS;
395 ret->data.sks.ns = ns; 395 ret->data.sks.ns = ns;
396 ret->data.sks.identifier = GNUNET_strdup(end); 396 ret->data.sks.identifier = GNUNET_strdup (end);
397 return ret; 397 return ret;
398} 398}
399 399
@@ -408,7 +408,7 @@ uri_sks_parse(const char *s, char **emsg)
408 * @return NULL on error, CHK URI otherwise 408 * @return NULL on error, CHK URI otherwise
409 */ 409 */
410static struct GNUNET_FS_Uri * 410static struct GNUNET_FS_Uri *
411uri_chk_parse(const char *s, char **emsg) 411uri_chk_parse (const char *s, char **emsg)
412{ 412{
413 struct GNUNET_FS_Uri *ret; 413 struct GNUNET_FS_Uri *ret;
414 struct FileIdentifier fi; 414 struct FileIdentifier fi;
@@ -418,36 +418,36 @@ uri_chk_parse(const char *s, char **emsg)
418 char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 418 char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
419 char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 419 char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
420 420
421 slen = strlen(s); 421 slen = strlen (s);
422 pos = strlen(GNUNET_FS_URI_CHK_PREFIX); 422 pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
423 if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || 423 if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
424 (0 != strncmp(s, GNUNET_FS_URI_CHK_PREFIX, pos))) 424 (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos)))
425 return NULL; /* not a CHK URI */ 425 return NULL; /* not a CHK URI */
426 if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || 426 if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
427 (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) 427 (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
428 { 428 {
429 *emsg = GNUNET_strdup(_("Malformed CHK URI (wrong syntax)")); 429 *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)"));
430 return NULL; 430 return NULL;
431 } 431 }
432 GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); 432 GNUNET_memcpy (h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
433 h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 433 h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
434 GNUNET_memcpy(h2, 434 GNUNET_memcpy (h2,
435 &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], 435 &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)],
436 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); 436 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
437 h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 437 h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
438 438
439 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &fi.chk.key)) || 439 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) ||
440 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &fi.chk.query)) || 440 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) ||
441 (1 != 441 (1 !=
442 sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 442 sscanf (&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
443 "%llu", 443 "%llu",
444 &flen))) 444 &flen)))
445 { 445 {
446 *emsg = GNUNET_strdup(_("Malformed CHK URI (failed to decode CHK)")); 446 *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)"));
447 return NULL; 447 return NULL;
448 } 448 }
449 fi.file_length = GNUNET_htonll(flen); 449 fi.file_length = GNUNET_htonll (flen);
450 ret = GNUNET_new(struct GNUNET_FS_Uri); 450 ret = GNUNET_new (struct GNUNET_FS_Uri);
451 ret->type = GNUNET_FS_URI_CHK; 451 ret->type = GNUNET_FS_URI_CHK;
452 ret->data.chk = fi; 452 ret->data.chk = fi;
453 return ret; 453 return ret;
@@ -460,7 +460,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
460 * assembled in memory to create or verify the signature of a location 460 * assembled in memory to create or verify the signature of a location
461 * URI. 461 * URI.
462 */ 462 */
463struct LocUriAssembly { 463struct LocUriAssembly
464{
464 /** 465 /**
465 * What is being signed (rest of this struct). 466 * What is being signed (rest of this struct).
466 */ 467 */
@@ -497,7 +498,7 @@ GNUNET_NETWORK_STRUCT_END
497 * @return NULL on error, valid LOC URI otherwise 498 * @return NULL on error, valid LOC URI otherwise
498 */ 499 */
499static struct GNUNET_FS_Uri * 500static struct GNUNET_FS_Uri *
500uri_loc_parse(const char *s, char **emsg) 501uri_loc_parse (const char *s, char **emsg)
501{ 502{
502 struct GNUNET_FS_Uri *uri; 503 struct GNUNET_FS_Uri *uri;
503 char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; 504 char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)];
@@ -511,113 +512,113 @@ uri_loc_parse(const char *s, char **emsg)
511 struct LocUriAssembly ass; 512 struct LocUriAssembly ass;
512 size_t slen; 513 size_t slen;
513 514
514 slen = strlen(s); 515 slen = strlen (s);
515 pos = strlen(GNUNET_FS_URI_LOC_PREFIX); 516 pos = strlen (GNUNET_FS_URI_LOC_PREFIX);
516 if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || 517 if ((slen < pos + 2 * sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
517 (0 != strncmp(s, GNUNET_FS_URI_LOC_PREFIX, pos))) 518 (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos)))
518 return NULL; /* not a LOC URI */ 519 return NULL; /* not a LOC URI */
519 if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || 520 if ((s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
520 (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) 521 (s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
521 { 522 {
522 *emsg = GNUNET_strdup(_("LOC URI malformed (wrong syntax)")); 523 *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)"));
523 return NULL; 524 return NULL;
524 } 525 }
525 GNUNET_memcpy(h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); 526 GNUNET_memcpy (h1, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
526 h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 527 h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
527 GNUNET_memcpy(h2, 528 GNUNET_memcpy (h2,
528 &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], 529 &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)],
529 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); 530 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded));
530 h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; 531 h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
531 532
532 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h1, &ass.fi.chk.key)) || 533 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) ||
533 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(h2, &ass.fi.chk.query)) || 534 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) ||
534 (1 != 535 (1 !=
535 sscanf(&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], 536 sscanf (&s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
536 "%llu", 537 "%llu",
537 &flen))) 538 &flen)))
538 { 539 {
539 *emsg = GNUNET_strdup(_("LOC URI malformed (no CHK)")); 540 *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)"));
540 return NULL; 541 return NULL;
541 } 542 }
542 ass.fi.file_length = GNUNET_htonll(flen); 543 ass.fi.file_length = GNUNET_htonll (flen);
543 544
544 npos = pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; 545 npos = pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) * 2;
545 while ((s[npos] != '\0') && (s[npos] != '.')) 546 while ((s[npos] != '\0') && (s[npos] != '.'))
546 npos++; 547 npos++;
547 if (s[npos] == '\0') 548 if (s[npos] == '\0')
548 { 549 {
549 *emsg = GNUNET_strdup(_("LOC URI malformed (missing LOC)")); 550 *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)"));
550 goto ERR; 551 goto ERR;
551 } 552 }
552 npos++; 553 npos++;
553 if ((strlen(&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || 554 if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) ||
554 ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) 555 ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH]))
555 { 556 {
556 *emsg = 557 *emsg =
557 GNUNET_strdup(_("LOC URI malformed (wrong syntax for public key)")); 558 GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)"));
558 } 559 }
559 if ( 560 if (
560 GNUNET_OK != 561 GNUNET_OK !=
561 GNUNET_CRYPTO_eddsa_public_key_from_string(&s[npos], 562 GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos],
562 GNUNET_CRYPTO_PKEY_ASCII_LENGTH, 563 GNUNET_CRYPTO_PKEY_ASCII_LENGTH,
563 &ass.peer.public_key)) 564 &ass.peer.public_key))
564 { 565 {
565 *emsg = 566 *emsg =
566 GNUNET_strdup(_("LOC URI malformed (could not decode public key)")); 567 GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)"));
567 goto ERR; 568 goto ERR;
568 } 569 }
569 npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; 570 npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH;
570 if (s[npos++] != '.') 571 if (s[npos++] != '.')
571 { 572 {
572 *emsg = GNUNET_strdup(_("LOC URI malformed (could not find signature)")); 573 *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)"));
573 goto ERR; 574 goto ERR;
574 } 575 }
575 if ((strlen(&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || 576 if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) ||
576 ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) 577 ('.' != s[npos + SIGNATURE_ASCII_LENGTH]))
577 { 578 {
578 *emsg = 579 *emsg =
579 GNUNET_strdup(_("LOC URI malformed (wrong syntax for signature)")); 580 GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)"));
580 goto ERR; 581 goto ERR;
581 } 582 }
582 if (GNUNET_OK != 583 if (GNUNET_OK !=
583 GNUNET_STRINGS_string_to_data(&s[npos], 584 GNUNET_STRINGS_string_to_data (&s[npos],
584 SIGNATURE_ASCII_LENGTH, 585 SIGNATURE_ASCII_LENGTH,
585 &sig, 586 &sig,
586 sizeof( 587 sizeof(
587 struct GNUNET_CRYPTO_EddsaSignature))) 588 struct GNUNET_CRYPTO_EddsaSignature)))
588 { 589 {
589 *emsg = 590 *emsg =
590 GNUNET_strdup(_("LOC URI malformed (could not decode signature)")); 591 GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)"));
591 goto ERR; 592 goto ERR;
592 } 593 }
593 npos += SIGNATURE_ASCII_LENGTH; 594 npos += SIGNATURE_ASCII_LENGTH;
594 if (s[npos++] != '.') 595 if (s[npos++] != '.')
595 { 596 {
596 *emsg = GNUNET_strdup( 597 *emsg = GNUNET_strdup (
597 _("LOC URI malformed (wrong syntax for expiration time)")); 598 _ ("LOC URI malformed (wrong syntax for expiration time)"));
598 goto ERR; 599 goto ERR;
599 } 600 }
600 if (1 != sscanf(&s[npos], "%llu", &exptime)) 601 if (1 != sscanf (&s[npos], "%llu", &exptime))
601 { 602 {
602 *emsg = 603 *emsg =
603 GNUNET_strdup(_("LOC URI malformed (could not parse expiration time)")); 604 GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)"));
604 goto ERR; 605 goto ERR;
605 } 606 }
606 ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); 607 ass.purpose.size = htonl (sizeof(struct LocUriAssembly));
607 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 608 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
608 et.abs_value_us = exptime * 1000LL * 1000LL; 609 et.abs_value_us = exptime * 1000LL * 1000LL;
609 ass.exptime = GNUNET_TIME_absolute_hton(et); 610 ass.exptime = GNUNET_TIME_absolute_hton (et);
610 if (GNUNET_OK != 611 if (GNUNET_OK !=
611 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, 612 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
612 &ass.purpose, 613 &ass.purpose,
613 &sig, 614 &sig,
614 &ass.peer.public_key)) 615 &ass.peer.public_key))
615 { 616 {
616 *emsg = 617 *emsg =
617 GNUNET_strdup(_("LOC URI malformed (signature failed validation)")); 618 GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)"));
618 goto ERR; 619 goto ERR;
619 } 620 }
620 uri = GNUNET_new(struct GNUNET_FS_Uri); 621 uri = GNUNET_new (struct GNUNET_FS_Uri);
621 uri->type = GNUNET_FS_URI_LOC; 622 uri->type = GNUNET_FS_URI_LOC;
622 uri->data.loc.fi = ass.fi; 623 uri->data.loc.fi = ass.fi;
623 uri->data.loc.peer = ass.peer; 624 uri->data.loc.peer = ass.peer;
@@ -638,30 +639,30 @@ ERR:
638 * @return NULL on error 639 * @return NULL on error
639 */ 640 */
640struct GNUNET_FS_Uri * 641struct GNUNET_FS_Uri *
641GNUNET_FS_uri_parse(const char *uri, char **emsg) 642GNUNET_FS_uri_parse (const char *uri, char **emsg)
642{ 643{
643 struct GNUNET_FS_Uri *ret; 644 struct GNUNET_FS_Uri *ret;
644 char *msg; 645 char *msg;
645 646
646 if (NULL == uri) 647 if (NULL == uri)
647 { 648 {
648 GNUNET_break(0); 649 GNUNET_break (0);
649 if (NULL != emsg) 650 if (NULL != emsg)
650 *emsg = GNUNET_strdup(_("invalid argument")); 651 *emsg = GNUNET_strdup (_ ("invalid argument"));
651 return NULL; 652 return NULL;
652 } 653 }
653 if (NULL == emsg) 654 if (NULL == emsg)
654 emsg = &msg; 655 emsg = &msg;
655 *emsg = NULL; 656 *emsg = NULL;
656 if ((NULL != (ret = uri_chk_parse(uri, emsg))) || 657 if ((NULL != (ret = uri_chk_parse (uri, emsg))) ||
657 (NULL != (ret = uri_ksk_parse(uri, emsg))) || 658 (NULL != (ret = uri_ksk_parse (uri, emsg))) ||
658 (NULL != (ret = uri_sks_parse(uri, emsg))) || 659 (NULL != (ret = uri_sks_parse (uri, emsg))) ||
659 (NULL != (ret = uri_loc_parse(uri, emsg)))) 660 (NULL != (ret = uri_loc_parse (uri, emsg))))
660 return ret; 661 return ret;
661 if (NULL == *emsg) 662 if (NULL == *emsg)
662 *emsg = GNUNET_strdup(_("Unrecognized URI type")); 663 *emsg = GNUNET_strdup (_ ("Unrecognized URI type"));
663 if (emsg == &msg) 664 if (emsg == &msg)
664 GNUNET_free(msg); 665 GNUNET_free (msg);
665 return NULL; 666 return NULL;
666} 667}
667 668
@@ -672,30 +673,30 @@ GNUNET_FS_uri_parse(const char *uri, char **emsg)
672 * @param uri uri to free 673 * @param uri uri to free
673 */ 674 */
674void 675void
675GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri) 676GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri)
676{ 677{
677 unsigned int i; 678 unsigned int i;
678 679
679 switch (uri->type) 680 switch (uri->type)
680 { 681 {
681 case GNUNET_FS_URI_KSK: 682 case GNUNET_FS_URI_KSK:
682 for (i = 0; i < uri->data.ksk.keywordCount; i++) 683 for (i = 0; i < uri->data.ksk.keywordCount; i++)
683 GNUNET_free(uri->data.ksk.keywords[i]); 684 GNUNET_free (uri->data.ksk.keywords[i]);
684 GNUNET_array_grow(uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0); 685 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0);
685 break; 686 break;
686 687
687 case GNUNET_FS_URI_SKS: 688 case GNUNET_FS_URI_SKS:
688 GNUNET_free(uri->data.sks.identifier); 689 GNUNET_free (uri->data.sks.identifier);
689 break; 690 break;
690 691
691 case GNUNET_FS_URI_LOC: 692 case GNUNET_FS_URI_LOC:
692 break; 693 break;
693 694
694 default: 695 default:
695 /* do nothing */ 696 /* do nothing */
696 break; 697 break;
697 } 698 }
698 GNUNET_free(uri); 699 GNUNET_free (uri);
699} 700}
700 701
701 702
@@ -706,7 +707,7 @@ GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
706 * @return 0 if this is not a keyword URI 707 * @return 0 if this is not a keyword URI
707 */ 708 */
708unsigned int 709unsigned int
709GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri) 710GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri)
710{ 711{
711 if (uri->type != GNUNET_FS_URI_KSK) 712 if (uri->type != GNUNET_FS_URI_KSK)
712 return 0; 713 return 0;
@@ -724,9 +725,9 @@ GNUNET_FS_uri_ksk_get_keyword_count(const struct GNUNET_FS_Uri *uri)
724 * keywords iterated over until iterator aborted 725 * keywords iterated over until iterator aborted
725 */ 726 */
726int 727int
727GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri, 728GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
728 GNUNET_FS_KeywordIterator iterator, 729 GNUNET_FS_KeywordIterator iterator,
729 void *iterator_cls) 730 void *iterator_cls)
730{ 731{
731 unsigned int i; 732 unsigned int i;
732 char *keyword; 733 char *keyword;
@@ -736,13 +737,13 @@ GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri,
736 if (NULL == iterator) 737 if (NULL == iterator)
737 return uri->data.ksk.keywordCount; 738 return uri->data.ksk.keywordCount;
738 for (i = 0; i < uri->data.ksk.keywordCount; i++) 739 for (i = 0; i < uri->data.ksk.keywordCount; i++)
739 { 740 {
740 keyword = uri->data.ksk.keywords[i]; 741 keyword = uri->data.ksk.keywords[i];
741 /* first character of keyword indicates 742 /* first character of keyword indicates
742 * if it is mandatory or not */ 743 * if it is mandatory or not */
743 if (GNUNET_OK != iterator(iterator_cls, &keyword[1], keyword[0] == '+')) 744 if (GNUNET_OK != iterator (iterator_cls, &keyword[1],(keyword[0] == '+') ))
744 return i; 745 return i;
745 } 746 }
746 return i; 747 return i;
747} 748}
748 749
@@ -756,23 +757,23 @@ GNUNET_FS_uri_ksk_get_keywords(const struct GNUNET_FS_Uri *uri,
756 * @param is_mandatory is this keyword mandatory? 757 * @param is_mandatory is this keyword mandatory?
757 */ 758 */
758void 759void
759GNUNET_FS_uri_ksk_add_keyword(struct GNUNET_FS_Uri *uri, 760GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
760 const char *keyword, 761 const char *keyword,
761 int is_mandatory) 762 int is_mandatory)
762{ 763{
763 unsigned int i; 764 unsigned int i;
764 const char *old; 765 const char *old;
765 char *n; 766 char *n;
766 767
767 GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); 768 GNUNET_assert (uri->type == GNUNET_FS_URI_KSK);
768 for (i = 0; i < uri->data.ksk.keywordCount; i++) 769 for (i = 0; i < uri->data.ksk.keywordCount; i++)
769 { 770 {
770 old = uri->data.ksk.keywords[i]; 771 old = uri->data.ksk.keywords[i];
771 if (0 == strcmp(&old[1], keyword)) 772 if (0 == strcmp (&old[1], keyword))
772 return; 773 return;
773 } 774 }
774 GNUNET_asprintf(&n, is_mandatory ? "+%s" : " %s", keyword); 775 GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword);
775 GNUNET_array_append(uri->data.ksk.keywords, uri->data.ksk.keywordCount, n); 776 GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n);
776} 777}
777 778
778 779
@@ -784,27 +785,27 @@ GNUNET_FS_uri_ksk_add_keyword(struct GNUNET_FS_Uri *uri,
784 * @param keyword keyword to add 785 * @param keyword keyword to add
785 */ 786 */
786void 787void
787GNUNET_FS_uri_ksk_remove_keyword(struct GNUNET_FS_Uri *uri, 788GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
788 const char *keyword) 789 const char *keyword)
789{ 790{
790 unsigned int i; 791 unsigned int i;
791 char *old; 792 char *old;
792 793
793 GNUNET_assert(uri->type == GNUNET_FS_URI_KSK); 794 GNUNET_assert (uri->type == GNUNET_FS_URI_KSK);
794 for (i = 0; i < uri->data.ksk.keywordCount; i++) 795 for (i = 0; i < uri->data.ksk.keywordCount; i++)
796 {
797 old = uri->data.ksk.keywords[i];
798 if (0 == strcmp (&old[1], keyword))
795 { 799 {
796 old = uri->data.ksk.keywords[i]; 800 uri->data.ksk.keywords[i] =
797 if (0 == strcmp(&old[1], keyword)) 801 uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
798 { 802 GNUNET_array_grow (uri->data.ksk.keywords,
799 uri->data.ksk.keywords[i] = 803 uri->data.ksk.keywordCount,
800 uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; 804 uri->data.ksk.keywordCount - 1);
801 GNUNET_array_grow(uri->data.ksk.keywords, 805 GNUNET_free (old);
802 uri->data.ksk.keywordCount, 806 return;
803 uri->data.ksk.keywordCount - 1);
804 GNUNET_free(old);
805 return;
806 }
807 } 807 }
808 }
808} 809}
809 810
810 811
@@ -816,8 +817,8 @@ GNUNET_FS_uri_ksk_remove_keyword(struct GNUNET_FS_Uri *uri,
816 * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK 817 * @return #GNUNET_SYSERR if this is not a location URI, otherwise #GNUNET_OK
817 */ 818 */
818int 819int
819GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri, 820GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
820 struct GNUNET_PeerIdentity *peer) 821 struct GNUNET_PeerIdentity *peer)
821{ 822{
822 if (uri->type != GNUNET_FS_URI_LOC) 823 if (uri->type != GNUNET_FS_URI_LOC)
823 return GNUNET_SYSERR; 824 return GNUNET_SYSERR;
@@ -833,9 +834,9 @@ GNUNET_FS_uri_loc_get_peer_identity(const struct GNUNET_FS_Uri *uri,
833 * @return expiration time of the URI 834 * @return expiration time of the URI
834 */ 835 */
835struct GNUNET_TIME_Absolute 836struct GNUNET_TIME_Absolute
836GNUNET_FS_uri_loc_get_expiration(const struct GNUNET_FS_Uri *uri) 837GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri)
837{ 838{
838 GNUNET_assert(uri->type == GNUNET_FS_URI_LOC); 839 GNUNET_assert (uri->type == GNUNET_FS_URI_LOC);
839 return uri->data.loc.expirationTime; 840 return uri->data.loc.expirationTime;
840} 841}
841 842
@@ -847,13 +848,13 @@ GNUNET_FS_uri_loc_get_expiration(const struct GNUNET_FS_Uri *uri)
847 * @return NULL if argument is not a location URI 848 * @return NULL if argument is not a location URI
848 */ 849 */
849struct GNUNET_FS_Uri * 850struct GNUNET_FS_Uri *
850GNUNET_FS_uri_loc_get_uri(const struct GNUNET_FS_Uri *uri) 851GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri)
851{ 852{
852 struct GNUNET_FS_Uri *ret; 853 struct GNUNET_FS_Uri *ret;
853 854
854 if (uri->type != GNUNET_FS_URI_LOC) 855 if (uri->type != GNUNET_FS_URI_LOC)
855 return NULL; 856 return NULL;
856 ret = GNUNET_new(struct GNUNET_FS_Uri); 857 ret = GNUNET_new (struct GNUNET_FS_Uri);
857 ret->type = GNUNET_FS_URI_CHK; 858 ret->type = GNUNET_FS_URI_CHK;
858 ret->data.chk = uri->data.loc.fi; 859 ret->data.chk = uri->data.loc.fi;
859 return ret; 860 return ret;
@@ -873,9 +874,9 @@ GNUNET_FS_uri_loc_get_uri(const struct GNUNET_FS_Uri *uri)
873 * @return the location URI, NULL on error 874 * @return the location URI, NULL on error
874 */ 875 */
875struct GNUNET_FS_Uri * 876struct GNUNET_FS_Uri *
876GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri, 877GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri,
877 const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, 878 const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key,
878 struct GNUNET_TIME_Absolute expiration_time) 879 struct GNUNET_TIME_Absolute expiration_time)
879{ 880{
880 struct GNUNET_FS_Uri *uri; 881 struct GNUNET_FS_Uri *uri;
881 struct GNUNET_CRYPTO_EddsaPublicKey my_public_key; 882 struct GNUNET_CRYPTO_EddsaPublicKey my_public_key;
@@ -886,21 +887,21 @@ GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri,
886 return NULL; 887 return NULL;
887 /* we round expiration time to full seconds for SKS URIs */ 888 /* we round expiration time to full seconds for SKS URIs */
888 et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; 889 et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL;
889 GNUNET_CRYPTO_eddsa_key_get_public(sign_key, &my_public_key); 890 GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key);
890 ass.purpose.size = htonl(sizeof(struct LocUriAssembly)); 891 ass.purpose.size = htonl (sizeof(struct LocUriAssembly));
891 ass.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 892 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
892 ass.exptime = GNUNET_TIME_absolute_hton(et); 893 ass.exptime = GNUNET_TIME_absolute_hton (et);
893 ass.fi = base_uri->data.chk; 894 ass.fi = base_uri->data.chk;
894 ass.peer.public_key = my_public_key; 895 ass.peer.public_key = my_public_key;
895 uri = GNUNET_new(struct GNUNET_FS_Uri); 896 uri = GNUNET_new (struct GNUNET_FS_Uri);
896 uri->type = GNUNET_FS_URI_LOC; 897 uri->type = GNUNET_FS_URI_LOC;
897 uri->data.loc.fi = base_uri->data.chk; 898 uri->data.loc.fi = base_uri->data.chk;
898 uri->data.loc.expirationTime = et; 899 uri->data.loc.expirationTime = et;
899 uri->data.loc.peer.public_key = my_public_key; 900 uri->data.loc.peer.public_key = my_public_key;
900 GNUNET_assert(GNUNET_OK == 901 GNUNET_assert (GNUNET_OK ==
901 GNUNET_CRYPTO_eddsa_sign(sign_key, 902 GNUNET_CRYPTO_eddsa_sign (sign_key,
902 &ass.purpose, 903 &ass.purpose,
903 &uri->data.loc.contentSignature)); 904 &uri->data.loc.contentSignature));
904 return uri; 905 return uri;
905} 906}
906 907
@@ -913,15 +914,15 @@ GNUNET_FS_uri_loc_create(const struct GNUNET_FS_Uri *base_uri,
913 * @return an FS URI for the given namespace and identifier 914 * @return an FS URI for the given namespace and identifier
914 */ 915 */
915struct GNUNET_FS_Uri * 916struct GNUNET_FS_Uri *
916GNUNET_FS_uri_sks_create(const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, 917GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
917 const char *id) 918 const char *id)
918{ 919{
919 struct GNUNET_FS_Uri *ns_uri; 920 struct GNUNET_FS_Uri *ns_uri;
920 921
921 ns_uri = GNUNET_new(struct GNUNET_FS_Uri); 922 ns_uri = GNUNET_new (struct GNUNET_FS_Uri);
922 ns_uri->type = GNUNET_FS_URI_SKS; 923 ns_uri->type = GNUNET_FS_URI_SKS;
923 ns_uri->data.sks.ns = *ns; 924 ns_uri->data.sks.ns = *ns;
924 ns_uri->data.sks.identifier = GNUNET_strdup(id); 925 ns_uri->data.sks.identifier = GNUNET_strdup (id);
925 return ns_uri; 926 return ns_uri;
926} 927}
927 928
@@ -936,8 +937,8 @@ GNUNET_FS_uri_sks_create(const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
936 * @return merged URI, NULL on error 937 * @return merged URI, NULL on error
937 */ 938 */
938struct GNUNET_FS_Uri * 939struct GNUNET_FS_Uri *
939GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1, 940GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
940 const struct GNUNET_FS_Uri *u2) 941 const struct GNUNET_FS_Uri *u2)
941{ 942{
942 struct GNUNET_FS_Uri *ret; 943 struct GNUNET_FS_Uri *ret;
943 unsigned int kc; 944 unsigned int kc;
@@ -950,34 +951,34 @@ GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1,
950 if ((u1 == NULL) && (u2 == NULL)) 951 if ((u1 == NULL) && (u2 == NULL))
951 return NULL; 952 return NULL;
952 if (u1 == NULL) 953 if (u1 == NULL)
953 return GNUNET_FS_uri_dup(u2); 954 return GNUNET_FS_uri_dup (u2);
954 if (u2 == NULL) 955 if (u2 == NULL)
955 return GNUNET_FS_uri_dup(u1); 956 return GNUNET_FS_uri_dup (u1);
956 if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK)) 957 if ((u1->type != GNUNET_FS_URI_KSK) || (u2->type != GNUNET_FS_URI_KSK))
957 { 958 {
958 GNUNET_break(0); 959 GNUNET_break (0);
959 return NULL; 960 return NULL;
960 } 961 }
961 kc = u1->data.ksk.keywordCount; 962 kc = u1->data.ksk.keywordCount;
962 kl = GNUNET_new_array(kc + u2->data.ksk.keywordCount, char *); 963 kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *);
963 for (i = 0; i < u1->data.ksk.keywordCount; i++) 964 for (i = 0; i < u1->data.ksk.keywordCount; i++)
964 kl[i] = GNUNET_strdup(u1->data.ksk.keywords[i]); 965 kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
965 for (i = 0; i < u2->data.ksk.keywordCount; i++) 966 for (i = 0; i < u2->data.ksk.keywordCount; i++)
966 { 967 {
967 kp = u2->data.ksk.keywords[i]; 968 kp = u2->data.ksk.keywords[i];
968 found = 0; 969 found = 0;
969 for (j = 0; j < u1->data.ksk.keywordCount; j++) 970 for (j = 0; j < u1->data.ksk.keywordCount; j++)
970 if (0 == strcmp(kp + 1, kl[j] + 1)) 971 if (0 == strcmp (kp + 1, kl[j] + 1))
971 { 972 {
972 found = 1; 973 found = 1;
973 if (kp[0] == '+') 974 if (kp[0] == '+')
974 kl[j][0] = '+'; 975 kl[j][0] = '+';
975 break; 976 break;
976 } 977 }
977 if (0 == found) 978 if (0 == found)
978 kl[kc++] = GNUNET_strdup(kp); 979 kl[kc++] = GNUNET_strdup (kp);
979 } 980 }
980 ret = GNUNET_new(struct GNUNET_FS_Uri); 981 ret = GNUNET_new (struct GNUNET_FS_Uri);
981 ret->type = GNUNET_FS_URI_KSK; 982 ret->type = GNUNET_FS_URI_KSK;
982 ret->data.ksk.keywordCount = kc; 983 ret->data.ksk.keywordCount = kc;
983 ret->data.ksk.keywords = kl; 984 ret->data.ksk.keywords = kl;
@@ -992,46 +993,46 @@ GNUNET_FS_uri_ksk_merge(const struct GNUNET_FS_Uri *u1,
992 * @return copy of the URI 993 * @return copy of the URI
993 */ 994 */
994struct GNUNET_FS_Uri * 995struct GNUNET_FS_Uri *
995GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri) 996GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
996{ 997{
997 struct GNUNET_FS_Uri *ret; 998 struct GNUNET_FS_Uri *ret;
998 unsigned int i; 999 unsigned int i;
999 1000
1000 if (uri == NULL) 1001 if (uri == NULL)
1001 return NULL; 1002 return NULL;
1002 ret = GNUNET_new(struct GNUNET_FS_Uri); 1003 ret = GNUNET_new (struct GNUNET_FS_Uri);
1003 GNUNET_memcpy(ret, uri, sizeof(struct GNUNET_FS_Uri)); 1004 GNUNET_memcpy (ret, uri, sizeof(struct GNUNET_FS_Uri));
1004 switch (ret->type) 1005 switch (ret->type)
1006 {
1007 case GNUNET_FS_URI_KSK:
1008 if (ret->data.ksk.keywordCount >=
1009 GNUNET_MAX_MALLOC_CHECKED / sizeof(char *))
1005 { 1010 {
1006 case GNUNET_FS_URI_KSK: 1011 GNUNET_break (0);
1007 if (ret->data.ksk.keywordCount >= 1012 GNUNET_free (ret);
1008 GNUNET_MAX_MALLOC_CHECKED / sizeof(char *)) 1013 return NULL;
1009 { 1014 }
1010 GNUNET_break(0); 1015 if (ret->data.ksk.keywordCount > 0)
1011 GNUNET_free(ret); 1016 {
1012 return NULL; 1017 ret->data.ksk.keywords =
1013 } 1018 GNUNET_new_array (ret->data.ksk.keywordCount, char *);
1014 if (ret->data.ksk.keywordCount > 0) 1019 for (i = 0; i < ret->data.ksk.keywordCount; i++)
1015 { 1020 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
1016 ret->data.ksk.keywords = 1021 }
1017 GNUNET_new_array(ret->data.ksk.keywordCount, char *); 1022 else
1018 for (i = 0; i < ret->data.ksk.keywordCount; i++) 1023 ret->data.ksk.keywords = NULL; /* just to be sure */
1019 ret->data.ksk.keywords[i] = GNUNET_strdup(uri->data.ksk.keywords[i]); 1024 break;
1020 }
1021 else
1022 ret->data.ksk.keywords = NULL; /* just to be sure */
1023 break;
1024 1025
1025 case GNUNET_FS_URI_SKS: 1026 case GNUNET_FS_URI_SKS:
1026 ret->data.sks.identifier = GNUNET_strdup(uri->data.sks.identifier); 1027 ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
1027 break; 1028 break;
1028 1029
1029 case GNUNET_FS_URI_LOC: 1030 case GNUNET_FS_URI_LOC:
1030 break; 1031 break;
1031 1032
1032 default: 1033 default:
1033 break; 1034 break;
1034 } 1035 }
1035 return ret; 1036 return ret;
1036} 1037}
1037 1038
@@ -1054,7 +1055,7 @@ GNUNET_FS_uri_dup(const struct GNUNET_FS_Uri *uri)
1054 * if keywords is not legal (i.e. empty). 1055 * if keywords is not legal (i.e. empty).
1055 */ 1056 */
1056struct GNUNET_FS_Uri * 1057struct GNUNET_FS_Uri *
1057GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg) 1058GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg)
1058{ 1059{
1059 char **keywordarr; 1060 char **keywordarr;
1060 unsigned int num_Words; 1061 unsigned int num_Words;
@@ -1065,68 +1066,68 @@ GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg)
1065 int saw_quote; 1066 int saw_quote;
1066 1067
1067 if (keywords == NULL) 1068 if (keywords == NULL)
1068 { 1069 {
1069 *emsg = GNUNET_strdup(_("No keywords specified!\n")); 1070 *emsg = GNUNET_strdup (_ ("No keywords specified!\n"));
1070 GNUNET_break(0); 1071 GNUNET_break (0);
1071 return NULL; 1072 return NULL;
1072 } 1073 }
1073 searchString = GNUNET_strdup(keywords); 1074 searchString = GNUNET_strdup (keywords);
1074 num_Words = 0; 1075 num_Words = 0;
1075 inWord = 0; 1076 inWord = 0;
1076 saw_quote = 0; 1077 saw_quote = 0;
1077 pos = searchString; 1078 pos = searchString;
1078 while ('\0' != *pos) 1079 while ('\0' != *pos)
1080 {
1081 if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
1079 { 1082 {
1080 if ((saw_quote == 0) && (isspace((unsigned char)*pos))) 1083 inWord = 0;
1081 {
1082 inWord = 0;
1083 }
1084 else if (0 == inWord)
1085 {
1086 inWord = 1;
1087 ++num_Words;
1088 }
1089 if ('"' == *pos)
1090 saw_quote = (saw_quote + 1) % 2;
1091 pos++;
1092 } 1084 }
1093 if (num_Words == 0) 1085 else if (0 == inWord)
1094 { 1086 {
1095 GNUNET_free(searchString); 1087 inWord = 1;
1096 *emsg = GNUNET_strdup(_("No keywords specified!\n")); 1088 ++num_Words;
1097 return NULL;
1098 } 1089 }
1090 if ('"' == *pos)
1091 saw_quote = (saw_quote + 1) % 2;
1092 pos++;
1093 }
1094 if (num_Words == 0)
1095 {
1096 GNUNET_free (searchString);
1097 *emsg = GNUNET_strdup (_ ("No keywords specified!\n"));
1098 return NULL;
1099 }
1099 if (saw_quote != 0) 1100 if (saw_quote != 0)
1100 { 1101 {
1101 GNUNET_free(searchString); 1102 GNUNET_free (searchString);
1102 *emsg = GNUNET_strdup(_("Number of double-quotes not balanced!\n")); 1103 *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n"));
1103 return NULL; 1104 return NULL;
1104 } 1105 }
1105 keywordarr = GNUNET_new_array(num_Words, char *); 1106 keywordarr = GNUNET_new_array (num_Words, char *);
1106 num_Words = 0; 1107 num_Words = 0;
1107 inWord = 0; 1108 inWord = 0;
1108 pos = searchString; 1109 pos = searchString;
1109 while ('\0' != *pos) 1110 while ('\0' != *pos)
1111 {
1112 if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
1110 { 1113 {
1111 if ((saw_quote == 0) && (isspace((unsigned char)*pos))) 1114 inWord = 0;
1112 { 1115 *pos = '\0';
1113 inWord = 0;
1114 *pos = '\0';
1115 }
1116 else if (0 == inWord)
1117 {
1118 keywordarr[num_Words] = pos;
1119 inWord = 1;
1120 ++num_Words;
1121 }
1122 if ('"' == *pos)
1123 saw_quote = (saw_quote + 1) % 2;
1124 pos++;
1125 } 1116 }
1117 else if (0 == inWord)
1118 {
1119 keywordarr[num_Words] = pos;
1120 inWord = 1;
1121 ++num_Words;
1122 }
1123 if ('"' == *pos)
1124 saw_quote = (saw_quote + 1) % 2;
1125 pos++;
1126 }
1126 uri = 1127 uri =
1127 GNUNET_FS_uri_ksk_create_from_args(num_Words, (const char **)keywordarr); 1128 GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr);
1128 GNUNET_free(keywordarr); 1129 GNUNET_free (keywordarr);
1129 GNUNET_free(searchString); 1130 GNUNET_free (searchString);
1130 return uri; 1131 return uri;
1131} 1132}
1132 1133
@@ -1149,7 +1150,7 @@ GNUNET_FS_uri_ksk_create(const char *keywords, char **emsg)
1149 * if keywords is not legal (i.e. empty). 1150 * if keywords is not legal (i.e. empty).
1150 */ 1151 */
1151struct GNUNET_FS_Uri * 1152struct GNUNET_FS_Uri *
1152GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv) 1153GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
1153{ 1154{
1154 unsigned int i; 1155 unsigned int i;
1155 struct GNUNET_FS_Uri *uri; 1156 struct GNUNET_FS_Uri *uri;
@@ -1164,36 +1165,36 @@ GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv)
1164 /* allow URI to be given as one and only keyword and 1165 /* allow URI to be given as one and only keyword and
1165 * handle accordingly */ 1166 * handle accordingly */
1166 emsg = NULL; 1167 emsg = NULL;
1167 if ((argc == 1) && (strlen(argv[0]) > strlen(GNUNET_FS_URI_PREFIX)) && 1168 if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
1168 (0 == strncmp(argv[0], 1169 (0 == strncmp (argv[0],
1169 GNUNET_FS_URI_PREFIX, 1170 GNUNET_FS_URI_PREFIX,
1170 strlen(GNUNET_FS_URI_PREFIX))) && 1171 strlen (GNUNET_FS_URI_PREFIX))) &&
1171 (NULL != (uri = GNUNET_FS_uri_parse(argv[0], &emsg)))) 1172 (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
1172 return uri; 1173 return uri;
1173 GNUNET_free_non_null(emsg); 1174 GNUNET_free_non_null (emsg);
1174 uri = GNUNET_new(struct GNUNET_FS_Uri); 1175 uri = GNUNET_new (struct GNUNET_FS_Uri);
1175 uri->type = GNUNET_FS_URI_KSK; 1176 uri->type = GNUNET_FS_URI_KSK;
1176 uri->data.ksk.keywordCount = argc; 1177 uri->data.ksk.keywordCount = argc;
1177 uri->data.ksk.keywords = GNUNET_new_array(argc, char *); 1178 uri->data.ksk.keywords = GNUNET_new_array (argc, char *);
1178 for (i = 0; i < argc; i++) 1179 for (i = 0; i < argc; i++)
1180 {
1181 keyword = argv[i];
1182 if (keyword[0] == '+')
1183 val = GNUNET_strdup (keyword);
1184 else
1185 GNUNET_asprintf (&val, " %s", keyword);
1186 r = val;
1187 w = val;
1188 while ('\0' != *r)
1179 { 1189 {
1180 keyword = argv[i]; 1190 if ('"' == *r)
1181 if (keyword[0] == '+') 1191 r++;
1182 val = GNUNET_strdup(keyword);
1183 else 1192 else
1184 GNUNET_asprintf(&val, " %s", keyword); 1193 *(w++) = *(r++);
1185 r = val;
1186 w = val;
1187 while ('\0' != *r)
1188 {
1189 if ('"' == *r)
1190 r++;
1191 else
1192 *(w++) = *(r++);
1193 }
1194 *w = '\0';
1195 uri->data.ksk.keywords[i] = val;
1196 } 1194 }
1195 *w = '\0';
1196 uri->data.ksk.keywords[i] = val;
1197 }
1197 return uri; 1198 return uri;
1198} 1199}
1199 1200
@@ -1206,66 +1207,66 @@ GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv)
1206 * @return #GNUNET_YES if the URIs are equal 1207 * @return #GNUNET_YES if the URIs are equal
1207 */ 1208 */
1208int 1209int
1209GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1, 1210GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1210 const struct GNUNET_FS_Uri *u2) 1211 const struct GNUNET_FS_Uri *u2)
1211{ 1212{
1212 int ret; 1213 int ret;
1213 unsigned int i; 1214 unsigned int i;
1214 unsigned int j; 1215 unsigned int j;
1215 1216
1216 GNUNET_assert(u1 != NULL); 1217 GNUNET_assert (u1 != NULL);
1217 GNUNET_assert(u2 != NULL); 1218 GNUNET_assert (u2 != NULL);
1218 if (u1->type != u2->type) 1219 if (u1->type != u2->type)
1219 return GNUNET_NO; 1220 return GNUNET_NO;
1220 switch (u1->type) 1221 switch (u1->type)
1221 { 1222 {
1222 case GNUNET_FS_URI_CHK: 1223 case GNUNET_FS_URI_CHK:
1223 if (0 == 1224 if (0 ==
1224 memcmp(&u1->data.chk, &u2->data.chk, sizeof(struct FileIdentifier))) 1225 memcmp (&u1->data.chk, &u2->data.chk, sizeof(struct FileIdentifier)))
1225 return GNUNET_YES; 1226 return GNUNET_YES;
1226 return GNUNET_NO; 1227 return GNUNET_NO;
1227 1228
1228 case GNUNET_FS_URI_SKS: 1229 case GNUNET_FS_URI_SKS:
1229 if ((0 == memcmp(&u1->data.sks.ns, 1230 if ((0 == memcmp (&u1->data.sks.ns,
1230 &u2->data.sks.ns, 1231 &u2->data.sks.ns,
1231 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) && 1232 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) &&
1232 (0 == strcmp(u1->data.sks.identifier, u2->data.sks.identifier))) 1233 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
1233 1234
1234 return GNUNET_YES; 1235 return GNUNET_YES;
1235 return GNUNET_NO; 1236 return GNUNET_NO;
1236 1237
1237 case GNUNET_FS_URI_KSK: 1238 case GNUNET_FS_URI_KSK:
1238 if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) 1239 if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount)
1239 return GNUNET_NO; 1240 return GNUNET_NO;
1240 for (i = 0; i < u1->data.ksk.keywordCount; i++) 1241 for (i = 0; i < u1->data.ksk.keywordCount; i++)
1242 {
1243 ret = GNUNET_NO;
1244 for (j = 0; j < u2->data.ksk.keywordCount; j++)
1245 {
1246 if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j]))
1241 { 1247 {
1242 ret = GNUNET_NO; 1248 ret = GNUNET_YES;
1243 for (j = 0; j < u2->data.ksk.keywordCount; j++) 1249 break;
1244 {
1245 if (0 == strcmp(u1->data.ksk.keywords[i], u2->data.ksk.keywords[j]))
1246 {
1247 ret = GNUNET_YES;
1248 break;
1249 }
1250 }
1251 if (ret == GNUNET_NO)
1252 return GNUNET_NO;
1253 } 1250 }
1254 return GNUNET_YES; 1251 }
1255 1252 if (ret == GNUNET_NO)
1256 case GNUNET_FS_URI_LOC:
1257 if (memcmp(&u1->data.loc,
1258 &u2->data.loc,
1259 sizeof(struct FileIdentifier) +
1260 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) +
1261 sizeof(struct GNUNET_TIME_Absolute) +
1262 sizeof(unsigned short) + sizeof(unsigned short)) != 0)
1263 return GNUNET_NO; 1253 return GNUNET_NO;
1264 return GNUNET_YES;
1265
1266 default:
1267 return GNUNET_NO;
1268 } 1254 }
1255 return GNUNET_YES;
1256
1257 case GNUNET_FS_URI_LOC:
1258 if (memcmp (&u1->data.loc,
1259 &u2->data.loc,
1260 sizeof(struct FileIdentifier)
1261 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
1262 + sizeof(struct GNUNET_TIME_Absolute)
1263 + sizeof(unsigned short) + sizeof(unsigned short)) != 0)
1264 return GNUNET_NO;
1265 return GNUNET_YES;
1266
1267 default:
1268 return GNUNET_NO;
1269 }
1269} 1270}
1270 1271
1271 1272
@@ -1276,7 +1277,7 @@ GNUNET_FS_uri_test_equal(const struct GNUNET_FS_Uri *u1,
1276 * @return #GNUNET_YES if this is an SKS uri 1277 * @return #GNUNET_YES if this is an SKS uri
1277 */ 1278 */
1278int 1279int
1279GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri) 1280GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri)
1280{ 1281{
1281 return uri->type == GNUNET_FS_URI_SKS; 1282 return uri->type == GNUNET_FS_URI_SKS;
1282} 1283}
@@ -1291,14 +1292,14 @@ GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
1291 * @return #GNUNET_OK on success 1292 * @return #GNUNET_OK on success
1292 */ 1293 */
1293int 1294int
1294GNUNET_FS_uri_sks_get_namespace(const struct GNUNET_FS_Uri *uri, 1295GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1295 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) 1296 struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym)
1296{ 1297{
1297 if (!GNUNET_FS_uri_test_sks(uri)) 1298 if (! GNUNET_FS_uri_test_sks (uri))
1298 { 1299 {
1299 GNUNET_break(0); 1300 GNUNET_break (0);
1300 return GNUNET_SYSERR; 1301 return GNUNET_SYSERR;
1301 } 1302 }
1302 *pseudonym = uri->data.sks.ns; 1303 *pseudonym = uri->data.sks.ns;
1303 return GNUNET_OK; 1304 return GNUNET_OK;
1304} 1305}
@@ -1311,14 +1312,14 @@ GNUNET_FS_uri_sks_get_namespace(const struct GNUNET_FS_Uri *uri,
1311 * @return NULL on error (not a valid SKS URI) 1312 * @return NULL on error (not a valid SKS URI)
1312 */ 1313 */
1313char * 1314char *
1314GNUNET_FS_uri_sks_get_content_id(const struct GNUNET_FS_Uri *uri) 1315GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
1315{ 1316{
1316 if (!GNUNET_FS_uri_test_sks(uri)) 1317 if (! GNUNET_FS_uri_test_sks (uri))
1317 { 1318 {
1318 GNUNET_break(0); 1319 GNUNET_break (0);
1319 return NULL; 1320 return NULL;
1320 } 1321 }
1321 return GNUNET_strdup(uri->data.sks.identifier); 1322 return GNUNET_strdup (uri->data.sks.identifier);
1322} 1323}
1323 1324
1324 1325
@@ -1329,16 +1330,16 @@ GNUNET_FS_uri_sks_get_content_id(const struct GNUNET_FS_Uri *uri)
1329 * @return #GNUNET_YES if this is a KSK uri 1330 * @return #GNUNET_YES if this is a KSK uri
1330 */ 1331 */
1331int 1332int
1332GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri) 1333GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
1333{ 1334{
1334#if EXTRA_CHECKS 1335#if EXTRA_CHECKS
1335 unsigned int i; 1336 unsigned int i;
1336 1337
1337 if (uri->type == GNUNET_FS_URI_KSK) 1338 if (uri->type == GNUNET_FS_URI_KSK)
1338 { 1339 {
1339 for (i = 0; i < uri->data.ksk.keywordCount; i++) 1340 for (i = 0; i < uri->data.ksk.keywordCount; i++)
1340 GNUNET_assert(uri->data.ksk.keywords[i] != NULL); 1341 GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
1341 } 1342 }
1342#endif 1343#endif
1343 return uri->type == GNUNET_FS_URI_KSK; 1344 return uri->type == GNUNET_FS_URI_KSK;
1344} 1345}
@@ -1351,7 +1352,7 @@ GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
1351 * @return #GNUNET_YES if this is a CHK uri 1352 * @return #GNUNET_YES if this is a CHK uri
1352 */ 1353 */
1353int 1354int
1354GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri) 1355GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri)
1355{ 1356{
1356 return uri->type == GNUNET_FS_URI_CHK; 1357 return uri->type == GNUNET_FS_URI_CHK;
1357} 1358}
@@ -1365,19 +1366,19 @@ GNUNET_FS_uri_test_chk(const struct GNUNET_FS_Uri *uri)
1365 * @return size of the file as specified in the CHK URI 1366 * @return size of the file as specified in the CHK URI
1366 */ 1367 */
1367uint64_t 1368uint64_t
1368GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri) 1369GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri)
1369{ 1370{
1370 switch (uri->type) 1371 switch (uri->type)
1371 { 1372 {
1372 case GNUNET_FS_URI_CHK: 1373 case GNUNET_FS_URI_CHK:
1373 return GNUNET_ntohll(uri->data.chk.file_length); 1374 return GNUNET_ntohll (uri->data.chk.file_length);
1374 1375
1375 case GNUNET_FS_URI_LOC: 1376 case GNUNET_FS_URI_LOC:
1376 return GNUNET_ntohll(uri->data.loc.fi.file_length); 1377 return GNUNET_ntohll (uri->data.loc.fi.file_length);
1377 1378
1378 default: 1379 default:
1379 GNUNET_assert(0); 1380 GNUNET_assert (0);
1380 } 1381 }
1381 return 0; /* unreachable */ 1382 return 0; /* unreachable */
1382} 1383}
1383 1384
@@ -1389,7 +1390,7 @@ GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri)
1389 * @return #GNUNET_YES if this is a LOC uri 1390 * @return #GNUNET_YES if this is a LOC uri
1390 */ 1391 */
1391int 1392int
1392GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri) 1393GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
1393{ 1394{
1394 return uri->type == GNUNET_FS_URI_LOC; 1395 return uri->type == GNUNET_FS_URI_LOC;
1395} 1396}
@@ -1405,13 +1406,13 @@ GNUNET_FS_uri_test_loc(const struct GNUNET_FS_Uri *uri)
1405 * @param index offset where to add the keyword 1406 * @param index offset where to add the keyword
1406 */ 1407 */
1407static void 1408static void
1408insert_non_mandatory_keyword(const char *s, char **array, int index) 1409insert_non_mandatory_keyword (const char *s, char **array, int index)
1409{ 1410{
1410 char *nkword; 1411 char *nkword;
1411 1412
1412 GNUNET_asprintf(&nkword, 1413 GNUNET_asprintf (&nkword,
1413 " %s", /* space to mark as 'non mandatory' */ 1414 " %s", /* space to mark as 'non mandatory' */
1414 s); 1415 s);
1415 array[index] = nkword; 1416 array[index] = nkword;
1416} 1417}
1417 1418
@@ -1426,12 +1427,12 @@ insert_non_mandatory_keyword(const char *s, char **array, int index)
1426 * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not 1427 * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not
1427 */ 1428 */
1428static int 1429static int
1429find_duplicate(const char *s, const char **array, int array_length) 1430find_duplicate (const char *s, const char **array, int array_length)
1430{ 1431{
1431 int j; 1432 int j;
1432 1433
1433 for (j = array_length - 1; j >= 0; j--) 1434 for (j = array_length - 1; j >= 0; j--)
1434 if (0 == strcmp(&array[j][1], s)) 1435 if (0 == strcmp (&array[j][1], s))
1435 return GNUNET_YES; 1436 return GNUNET_YES;
1436 return GNUNET_NO; 1437 return GNUNET_NO;
1437} 1438}
@@ -1441,12 +1442,12 @@ find_duplicate(const char *s, const char **array, int array_length)
1441 * FIXME: comment 1442 * FIXME: comment
1442 */ 1443 */
1443static char * 1444static char *
1444normalize_metadata(enum EXTRACTOR_MetaFormat format, 1445normalize_metadata (enum EXTRACTOR_MetaFormat format,
1445 const char *data, 1446 const char *data,
1446 size_t data_len) 1447 size_t data_len)
1447{ 1448{
1448 uint8_t *free_str = NULL; 1449 uint8_t *free_str = NULL;
1449 uint8_t *str_to_normalize = (uint8_t *)data; 1450 uint8_t *str_to_normalize = (uint8_t *) data;
1450 uint8_t *normalized; 1451 uint8_t *normalized;
1451 size_t r_len; 1452 size_t r_len;
1452 1453
@@ -1454,41 +1455,41 @@ normalize_metadata(enum EXTRACTOR_MetaFormat format,
1454 return NULL; 1455 return NULL;
1455 /* Don't trust libextractor */ 1456 /* Don't trust libextractor */
1456 if (format == EXTRACTOR_METAFORMAT_UTF8) 1457 if (format == EXTRACTOR_METAFORMAT_UTF8)
1457 { 1458 {
1458 free_str = (uint8_t *)u8_check((const uint8_t *)data, data_len); 1459 free_str = (uint8_t *) u8_check ((const uint8_t *) data, data_len);
1459 if (free_str == NULL) 1460 if (free_str == NULL)
1460 free_str = NULL; 1461 free_str = NULL;
1461 else 1462 else
1462 format = EXTRACTOR_METAFORMAT_C_STRING; 1463 format = EXTRACTOR_METAFORMAT_C_STRING;
1463 } 1464 }
1464 if (format == EXTRACTOR_METAFORMAT_C_STRING) 1465 if (format == EXTRACTOR_METAFORMAT_C_STRING)
1465 { 1466 {
1466 free_str = u8_strconv_from_encoding(data, 1467 free_str = u8_strconv_from_encoding (data,
1467 locale_charset(), 1468 locale_charset (),
1468 iconveh_escape_sequence); 1469 iconveh_escape_sequence);
1469 if (free_str == NULL) 1470 if (free_str == NULL)
1470 return NULL; 1471 return NULL;
1471 } 1472 }
1472 1473
1473 normalized = u8_tolower(str_to_normalize, 1474 normalized = u8_tolower (str_to_normalize,
1474 strlen((char *)str_to_normalize), 1475 strlen ((char *) str_to_normalize),
1475 NULL, 1476 NULL,
1476 UNINORM_NFD, 1477 UNINORM_NFD,
1477 NULL, 1478 NULL,
1478 &r_len); 1479 &r_len);
1479 /* free_str is allocated by libunistring internally, use free() */ 1480 /* free_str is allocated by libunistring internally, use free() */
1480 if (free_str != NULL) 1481 if (free_str != NULL)
1481 free(free_str); 1482 free (free_str);
1482 if (normalized != NULL) 1483 if (normalized != NULL)
1483 { 1484 {
1484 /* u8_tolower allocates a non-NULL-terminated string! */ 1485 /* u8_tolower allocates a non-NULL-terminated string! */
1485 free_str = GNUNET_malloc(r_len + 1); 1486 free_str = GNUNET_malloc (r_len + 1);
1486 GNUNET_memcpy(free_str, normalized, r_len); 1487 GNUNET_memcpy (free_str, normalized, r_len);
1487 free_str[r_len] = '\0'; 1488 free_str[r_len] = '\0';
1488 free(normalized); 1489 free (normalized);
1489 normalized = free_str; 1490 normalized = free_str;
1490 } 1491 }
1491 return (char *)normalized; 1492 return (char *) normalized;
1492} 1493}
1493 1494
1494 1495
@@ -1497,16 +1498,16 @@ normalize_metadata(enum EXTRACTOR_MetaFormat format,
1497 * returns that count. 1498 * returns that count.
1498 */ 1499 */
1499static size_t 1500static size_t
1500u8_strcount(const uint8_t *s) 1501u8_strcount (const uint8_t *s)
1501{ 1502{
1502 size_t count; 1503 size_t count;
1503 ucs4_t c; 1504 ucs4_t c;
1504 1505
1505 GNUNET_assert(s != NULL); 1506 GNUNET_assert (s != NULL);
1506 if (s[0] == 0) 1507 if (s[0] == 0)
1507 return 0; 1508 return 0;
1508 for (count = 0; s != NULL; count++) 1509 for (count = 0; s != NULL; count++)
1509 s = u8_next(&c, s); 1510 s = u8_next (&c, s);
1510 return count - 1; 1511 return count - 1;
1511} 1512}
1512 1513
@@ -1528,7 +1529,7 @@ u8_strcount(const uint8_t *s)
1528 * were duplicates (when extracting). 1529 * were duplicates (when extracting).
1529 */ 1530 */
1530static int 1531static int
1531get_keywords_from_parens(const char *s, char **array, int index) 1532get_keywords_from_parens (const char *s, char **array, int index)
1532{ 1533{
1533 int count = 0; 1534 int count = 0;
1534 char *open_paren; 1535 char *open_paren;
@@ -1538,80 +1539,80 @@ get_keywords_from_parens(const char *s, char **array, int index)
1538 1539
1539 if (NULL == s) 1540 if (NULL == s)
1540 return 0; 1541 return 0;
1541 ss = GNUNET_strdup(s); 1542 ss = GNUNET_strdup (s);
1542 open_paren = ss - 1; 1543 open_paren = ss - 1;
1543 while (NULL != (open_paren = strpbrk(open_paren + 1, "[{("))) 1544 while (NULL != (open_paren = strpbrk (open_paren + 1, "[{(")))
1545 {
1546 int match = 0;
1547
1548 close_paren = strpbrk (open_paren + 1, "]})");
1549 if (NULL == close_paren)
1550 continue;
1551 switch (open_paren[0])
1544 { 1552 {
1545 int match = 0; 1553 case '[':
1546 1554 if (']' == close_paren[0])
1547 close_paren = strpbrk(open_paren + 1, "]})"); 1555 match = 1;
1548 if (NULL == close_paren) 1556 break;
1549 continue;
1550 switch (open_paren[0])
1551 {
1552 case '[':
1553 if (']' == close_paren[0])
1554 match = 1;
1555 break;
1556 1557
1557 case '{': 1558 case '{':
1558 if ('}' == close_paren[0]) 1559 if ('}' == close_paren[0])
1559 match = 1; 1560 match = 1;
1560 break; 1561 break;
1561 1562
1562 case '(': 1563 case '(':
1563 if (')' == close_paren[0]) 1564 if (')' == close_paren[0])
1564 match = 1; 1565 match = 1;
1565 break; 1566 break;
1566 1567
1567 default: 1568 default:
1568 break; 1569 break;
1570 }
1571 if (match && (close_paren - open_paren > 1))
1572 {
1573 tmp = close_paren[0];
1574 close_paren[0] = '\0';
1575 /* Keywords must be at least 3 characters long */
1576 if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2)
1577 {
1578 close_paren[0] = tmp;
1579 continue;
1580 }
1581 if (NULL != array)
1582 {
1583 char *normalized;
1584 if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1],
1585 (const char **) array,
1586 index + count))
1587 {
1588 insert_non_mandatory_keyword ((const char *) &open_paren[1],
1589 array,
1590 index + count);
1591 count++;
1569 } 1592 }
1570 if (match && (close_paren - open_paren > 1)) 1593 normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8,
1594 &open_paren[1],
1595 close_paren - &open_paren[1]);
1596 if (normalized != NULL)
1571 { 1597 {
1572 tmp = close_paren[0]; 1598 if (GNUNET_NO == find_duplicate ((const char *) normalized,
1573 close_paren[0] = '\0'; 1599 (const char **) array,
1574 /* Keywords must be at least 3 characters long */ 1600 index + count))
1575 if (u8_strcount((const uint8_t *)&open_paren[1]) <= 2) 1601 {
1576 { 1602 insert_non_mandatory_keyword ((const char *) normalized,
1577 close_paren[0] = tmp; 1603 array,
1578 continue; 1604 index + count);
1579 }
1580 if (NULL != array)
1581 {
1582 char *normalized;
1583 if (GNUNET_NO == find_duplicate((const char *)&open_paren[1],
1584 (const char **)array,
1585 index + count))
1586 {
1587 insert_non_mandatory_keyword((const char *)&open_paren[1],
1588 array,
1589 index + count);
1590 count++;
1591 }
1592 normalized = normalize_metadata(EXTRACTOR_METAFORMAT_UTF8,
1593 &open_paren[1],
1594 close_paren - &open_paren[1]);
1595 if (normalized != NULL)
1596 {
1597 if (GNUNET_NO == find_duplicate((const char *)normalized,
1598 (const char **)array,
1599 index + count))
1600 {
1601 insert_non_mandatory_keyword((const char *)normalized,
1602 array,
1603 index + count);
1604 count++;
1605 }
1606 GNUNET_free(normalized);
1607 }
1608 }
1609 else
1610 count++; 1605 count++;
1611 close_paren[0] = tmp; 1606 }
1607 GNUNET_free (normalized);
1612 } 1608 }
1609 }
1610 else
1611 count++;
1612 close_paren[0] = tmp;
1613 } 1613 }
1614 GNUNET_free(ss); 1614 }
1615 GNUNET_free (ss);
1615 return count; 1616 return count;
1616} 1617}
1617 1618
@@ -1636,46 +1637,46 @@ get_keywords_from_parens(const char *s, char **array, int index)
1636 * duplicates (when extracting). 1637 * duplicates (when extracting).
1637 */ 1638 */
1638static int 1639static int
1639get_keywords_from_tokens(const char *s, char **array, int index) 1640get_keywords_from_tokens (const char *s, char **array, int index)
1640{ 1641{
1641 char *p; 1642 char *p;
1642 char *ss; 1643 char *ss;
1643 int seps = 0; 1644 int seps = 0;
1644 1645
1645 ss = GNUNET_strdup(s); 1646 ss = GNUNET_strdup (s);
1646 for (p = strtok(ss, TOKENS); p != NULL; p = strtok(NULL, TOKENS)) 1647 for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS))
1648 {
1649 /* Keywords must be at least 3 characters long */
1650 if (u8_strcount ((const uint8_t *) p) <= 2)
1651 continue;
1652 if (NULL != array)
1647 { 1653 {
1648 /* Keywords must be at least 3 characters long */ 1654 char *normalized;
1649 if (u8_strcount((const uint8_t *)p) <= 2) 1655 if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps))
1650 continue; 1656 {
1651 if (NULL != array) 1657 insert_non_mandatory_keyword (p, array, index + seps);
1658 seps++;
1659 }
1660 normalized =
1661 normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p));
1662 if (normalized != NULL)
1663 {
1664 if (GNUNET_NO == find_duplicate ((const char *) normalized,
1665 (const char **) array,
1666 index + seps))
1652 { 1667 {
1653 char *normalized; 1668 insert_non_mandatory_keyword ((const char *) normalized,
1654 if (GNUNET_NO == find_duplicate(p, (const char **)array, index + seps)) 1669 array,
1655 { 1670 index + seps);
1656 insert_non_mandatory_keyword(p, array, index + seps); 1671 seps++;
1657 seps++;
1658 }
1659 normalized =
1660 normalize_metadata(EXTRACTOR_METAFORMAT_UTF8, p, strlen(p));
1661 if (normalized != NULL)
1662 {
1663 if (GNUNET_NO == find_duplicate((const char *)normalized,
1664 (const char **)array,
1665 index + seps))
1666 {
1667 insert_non_mandatory_keyword((const char *)normalized,
1668 array,
1669 index + seps);
1670 seps++;
1671 }
1672 GNUNET_free(normalized);
1673 }
1674 } 1672 }
1675 else 1673 GNUNET_free (normalized);
1676 seps++; 1674 }
1677 } 1675 }
1678 GNUNET_free(ss); 1676 else
1677 seps++;
1678 }
1679 GNUNET_free (ss);
1679 return seps; 1680 return seps;
1680} 1681}
1681#undef TOKENS 1682#undef TOKENS
@@ -1699,13 +1700,13 @@ get_keywords_from_tokens(const char *s, char **array, int index)
1699 * @return 0 (always) 1700 * @return 0 (always)
1700 */ 1701 */
1701static int 1702static int
1702gather_uri_data(void *cls, 1703gather_uri_data (void *cls,
1703 const char *plugin_name, 1704 const char *plugin_name,
1704 enum EXTRACTOR_MetaType type, 1705 enum EXTRACTOR_MetaType type,
1705 enum EXTRACTOR_MetaFormat format, 1706 enum EXTRACTOR_MetaFormat format,
1706 const char *data_mime_type, 1707 const char *data_mime_type,
1707 const char *data, 1708 const char *data,
1708 size_t data_len) 1709 size_t data_len)
1709{ 1710{
1710 struct GNUNET_FS_Uri *uri = cls; 1711 struct GNUNET_FS_Uri *uri = cls;
1711 char *normalized_data; 1712 char *normalized_data;
@@ -1719,49 +1720,49 @@ gather_uri_data(void *cls,
1719 * and will return the length of its valid part, skipping the keyword. 1720 * and will return the length of its valid part, skipping the keyword.
1720 * If it does - fix the extractor, not this check! 1721 * If it does - fix the extractor, not this check!
1721 */ 1722 */
1722 if (u8_strcount((const uint8_t *)data) <= 2) 1723 if (u8_strcount ((const uint8_t *) data) <= 2)
1723 return 0; 1724 return 0;
1724 if ((EXTRACTOR_METATYPE_MIMETYPE == type) && 1725 if ((EXTRACTOR_METATYPE_MIMETYPE == type) &&
1725 (NULL != (sep = memchr(data, '/', data_len))) && (sep != data)) 1726 (NULL != (sep = memchr (data, '/', data_len))) && (sep != data))
1726 { 1727 {
1727 char *xtra; 1728 char *xtra;
1728 1729
1729 GNUNET_asprintf(&xtra, "mimetype:%.*s", (int)(sep - data), data); 1730 GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data);
1730 if (!find_duplicate(xtra, 1731 if (! find_duplicate (xtra,
1731 (const char **)uri->data.ksk.keywords, 1732 (const char **) uri->data.ksk.keywords,
1732 uri->data.ksk.keywordCount)) 1733 uri->data.ksk.keywordCount))
1733 {
1734 insert_non_mandatory_keyword(xtra,
1735 uri->data.ksk.keywords,
1736 uri->data.ksk.keywordCount);
1737 uri->data.ksk.keywordCount++;
1738 }
1739 GNUNET_free(xtra);
1740 }
1741
1742 normalized_data = normalize_metadata(format, data, data_len);
1743 if (!find_duplicate(data,
1744 (const char **)uri->data.ksk.keywords,
1745 uri->data.ksk.keywordCount))
1746 { 1734 {
1747 insert_non_mandatory_keyword(data, 1735 insert_non_mandatory_keyword (xtra,
1748 uri->data.ksk.keywords, 1736 uri->data.ksk.keywords,
1749 uri->data.ksk.keywordCount); 1737 uri->data.ksk.keywordCount);
1750 uri->data.ksk.keywordCount++; 1738 uri->data.ksk.keywordCount++;
1751 } 1739 }
1740 GNUNET_free (xtra);
1741 }
1742
1743 normalized_data = normalize_metadata (format, data, data_len);
1744 if (! find_duplicate (data,
1745 (const char **) uri->data.ksk.keywords,
1746 uri->data.ksk.keywordCount))
1747 {
1748 insert_non_mandatory_keyword (data,
1749 uri->data.ksk.keywords,
1750 uri->data.ksk.keywordCount);
1751 uri->data.ksk.keywordCount++;
1752 }
1752 if (NULL != normalized_data) 1753 if (NULL != normalized_data)
1753 { 1754 {
1754 if (!find_duplicate(normalized_data, 1755 if (! find_duplicate (normalized_data,
1755 (const char **)uri->data.ksk.keywords, 1756 (const char **) uri->data.ksk.keywords,
1756 uri->data.ksk.keywordCount)) 1757 uri->data.ksk.keywordCount))
1757 { 1758 {
1758 insert_non_mandatory_keyword(normalized_data, 1759 insert_non_mandatory_keyword (normalized_data,
1759 uri->data.ksk.keywords, 1760 uri->data.ksk.keywords,
1760 uri->data.ksk.keywordCount); 1761 uri->data.ksk.keywordCount);
1761 uri->data.ksk.keywordCount++; 1762 uri->data.ksk.keywordCount++;
1762 }
1763 GNUNET_free(normalized_data);
1764 } 1763 }
1764 GNUNET_free (normalized_data);
1765 }
1765 return 0; 1766 return 0;
1766} 1767}
1767 1768
@@ -1775,7 +1776,7 @@ gather_uri_data(void *cls,
1775 * @return NULL on error, otherwise a KSK URI 1776 * @return NULL on error, otherwise a KSK URI
1776 */ 1777 */
1777struct GNUNET_FS_Uri * 1778struct GNUNET_FS_Uri *
1778GNUNET_FS_uri_ksk_create_from_meta_data( 1779GNUNET_FS_uri_ksk_create_from_meta_data (
1779 const struct GNUNET_CONTAINER_MetaData *md) 1780 const struct GNUNET_CONTAINER_MetaData *md)
1780{ 1781{
1781 struct GNUNET_FS_Uri *ret; 1782 struct GNUNET_FS_Uri *ret;
@@ -1788,41 +1789,41 @@ GNUNET_FS_uri_ksk_create_from_meta_data(
1788 1789
1789 if (NULL == md) 1790 if (NULL == md)
1790 return NULL; 1791 return NULL;
1791 ret = GNUNET_new(struct GNUNET_FS_Uri); 1792 ret = GNUNET_new (struct GNUNET_FS_Uri);
1792 ret->type = GNUNET_FS_URI_KSK; 1793 ret->type = GNUNET_FS_URI_KSK;
1793 ent = GNUNET_CONTAINER_meta_data_iterate(md, NULL, NULL); 1794 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
1794 if (ent > 0) 1795 if (ent > 0)
1796 {
1797 full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (
1798 md,
1799 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
1800 -1);
1801 if (NULL != full_name)
1795 { 1802 {
1796 full_name = GNUNET_CONTAINER_meta_data_get_first_by_types( 1803 filename = full_name;
1797 md, 1804 while (NULL != (ss = strstr (filename, DIR_SEPARATOR_STR)))
1798 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 1805 filename = ss + 1;
1799 -1); 1806 tok_keywords = get_keywords_from_tokens (filename, NULL, 0);
1800 if (NULL != full_name) 1807 paren_keywords = get_keywords_from_parens (filename, NULL, 0);
1801 {
1802 filename = full_name;
1803 while (NULL != (ss = strstr(filename, DIR_SEPARATOR_STR)))
1804 filename = ss + 1;
1805 tok_keywords = get_keywords_from_tokens(filename, NULL, 0);
1806 paren_keywords = get_keywords_from_parens(filename, NULL, 0);
1807 }
1808 /* x3 because there might be a normalized variant of every keyword,
1809 plus theoretically one more for mime... */
1810 ret->data.ksk.keywords =
1811 GNUNET_new_array((ent + tok_keywords + paren_keywords) * 3, char *);
1812 GNUNET_CONTAINER_meta_data_iterate(md, &gather_uri_data, ret);
1813 } 1808 }
1809 /* x3 because there might be a normalized variant of every keyword,
1810 plus theoretically one more for mime... */
1811 ret->data.ksk.keywords =
1812 GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *);
1813 GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
1814 }
1814 if (tok_keywords > 0) 1815 if (tok_keywords > 0)
1815 ret->data.ksk.keywordCount += 1816 ret->data.ksk.keywordCount +=
1816 get_keywords_from_tokens(filename, 1817 get_keywords_from_tokens (filename,
1817 ret->data.ksk.keywords, 1818 ret->data.ksk.keywords,
1818 ret->data.ksk.keywordCount); 1819 ret->data.ksk.keywordCount);
1819 if (paren_keywords > 0) 1820 if (paren_keywords > 0)
1820 ret->data.ksk.keywordCount += 1821 ret->data.ksk.keywordCount +=
1821 get_keywords_from_parens(filename, 1822 get_keywords_from_parens (filename,
1822 ret->data.ksk.keywords, 1823 ret->data.ksk.keywords,
1823 ret->data.ksk.keywordCount); 1824 ret->data.ksk.keywordCount);
1824 if (ent > 0) 1825 if (ent > 0)
1825 GNUNET_free_non_null(full_name); 1826 GNUNET_free_non_null (full_name);
1826 return ret; 1827 return ret;
1827} 1828}
1828 1829
@@ -1832,10 +1833,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data(
1832 * need to be encoded using %-encoding? 1833 * need to be encoded using %-encoding?
1833 */ 1834 */
1834static int 1835static int
1835needs_percent(char c) 1836needs_percent (char c)
1836{ 1837{
1837 return(!((isalnum((unsigned char)c)) || (c == '-') || (c == '_') || 1838 return(! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') ||
1838 (c == '.') || (c == '~'))); 1839 (c == '.') || (c == '~')));
1839} 1840}
1840 1841
1841 1842
@@ -1846,7 +1847,7 @@ needs_percent(char c)
1846 * @return NULL on error (i.e. keywordCount == 0) 1847 * @return NULL on error (i.e. keywordCount == 0)
1847 */ 1848 */
1848static char * 1849static char *
1849uri_ksk_to_string(const struct GNUNET_FS_Uri *uri) 1850uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1850{ 1851{
1851 char **keywords; 1852 char **keywords;
1852 unsigned int keywordCount; 1853 unsigned int keywordCount;
@@ -1862,49 +1863,49 @@ uri_ksk_to_string(const struct GNUNET_FS_Uri *uri)
1862 return NULL; 1863 return NULL;
1863 keywords = uri->data.ksk.keywords; 1864 keywords = uri->data.ksk.keywords;
1864 keywordCount = uri->data.ksk.keywordCount; 1865 keywordCount = uri->data.ksk.keywordCount;
1865 n = keywordCount + strlen(GNUNET_FS_URI_PREFIX) + 1866 n = keywordCount + strlen (GNUNET_FS_URI_PREFIX)
1866 strlen(GNUNET_FS_URI_KSK_INFIX) + 1; 1867 + strlen (GNUNET_FS_URI_KSK_INFIX) + 1;
1867 for (i = 0; i < keywordCount; i++) 1868 for (i = 0; i < keywordCount; i++)
1869 {
1870 keyword = keywords[i];
1871 slen = strlen (keyword);
1872 n += slen;
1873 for (j = 0; j < slen; j++)
1868 { 1874 {
1869 keyword = keywords[i]; 1875 if ((j == 0) && (keyword[j] == ' '))
1870 slen = strlen(keyword); 1876 {
1871 n += slen; 1877 n--;
1872 for (j = 0; j < slen; j++) 1878 continue; /* skip leading space */
1873 { 1879 }
1874 if ((j == 0) && (keyword[j] == ' ')) 1880 if (needs_percent (keyword[j]))
1875 { 1881 n += 2; /* will use %-encoding */
1876 n--;
1877 continue; /* skip leading space */
1878 }
1879 if (needs_percent(keyword[j]))
1880 n += 2; /* will use %-encoding */
1881 }
1882 } 1882 }
1883 ret = GNUNET_malloc(n); 1883 }
1884 strcpy(ret, GNUNET_FS_URI_PREFIX); 1884 ret = GNUNET_malloc (n);
1885 strcat(ret, GNUNET_FS_URI_KSK_INFIX); 1885 strcpy (ret, GNUNET_FS_URI_PREFIX);
1886 wpos = strlen(ret); 1886 strcat (ret, GNUNET_FS_URI_KSK_INFIX);
1887 wpos = strlen (ret);
1887 for (i = 0; i < keywordCount; i++) 1888 for (i = 0; i < keywordCount; i++)
1889 {
1890 keyword = keywords[i];
1891 slen = strlen (keyword);
1892 for (j = 0; j < slen; j++)
1888 { 1893 {
1889 keyword = keywords[i]; 1894 if ((j == 0) && (keyword[j] == ' '))
1890 slen = strlen(keyword); 1895 continue; /* skip leading space */
1891 for (j = 0; j < slen; j++) 1896 if (needs_percent (keyword[j]))
1892 { 1897 {
1893 if ((j == 0) && (keyword[j] == ' ')) 1898 sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]);
1894 continue; /* skip leading space */ 1899 wpos += 3;
1895 if (needs_percent(keyword[j])) 1900 }
1896 { 1901 else
1897 sprintf(&ret[wpos], "%%%02X", (unsigned char)keyword[j]); 1902 {
1898 wpos += 3; 1903 ret[wpos++] = keyword[j];
1899 } 1904 }
1900 else
1901 {
1902 ret[wpos++] = keyword[j];
1903 }
1904 }
1905 if (i != keywordCount - 1)
1906 ret[wpos++] = '+';
1907 } 1905 }
1906 if (i != keywordCount - 1)
1907 ret[wpos++] = '+';
1908 }
1908 return ret; 1909 return ret;
1909} 1910}
1910 1911
@@ -1916,7 +1917,7 @@ uri_ksk_to_string(const struct GNUNET_FS_Uri *uri)
1916 * @return NULL on error 1917 * @return NULL on error
1917 */ 1918 */
1918static char * 1919static char *
1919uri_sks_to_string(const struct GNUNET_FS_Uri *uri) 1920uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1920{ 1921{
1921 char *ret; 1922 char *ret;
1922 char buf[1024]; 1923 char buf[1024];
@@ -1924,18 +1925,18 @@ uri_sks_to_string(const struct GNUNET_FS_Uri *uri)
1924 if (GNUNET_FS_URI_SKS != uri->type) 1925 if (GNUNET_FS_URI_SKS != uri->type)
1925 return NULL; 1926 return NULL;
1926 ret = 1927 ret =
1927 GNUNET_STRINGS_data_to_string(&uri->data.sks.ns, 1928 GNUNET_STRINGS_data_to_string (&uri->data.sks.ns,
1928 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), 1929 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
1929 buf, 1930 buf,
1930 sizeof(buf)); 1931 sizeof(buf));
1931 GNUNET_assert(NULL != ret); 1932 GNUNET_assert (NULL != ret);
1932 ret[0] = '\0'; 1933 ret[0] = '\0';
1933 GNUNET_asprintf(&ret, 1934 GNUNET_asprintf (&ret,
1934 "%s%s%s/%s", 1935 "%s%s%s/%s",
1935 GNUNET_FS_URI_PREFIX, 1936 GNUNET_FS_URI_PREFIX,
1936 GNUNET_FS_URI_SKS_INFIX, 1937 GNUNET_FS_URI_SKS_INFIX,
1937 buf, 1938 buf,
1938 uri->data.sks.identifier); 1939 uri->data.sks.identifier);
1939 return ret; 1940 return ret;
1940} 1941}
1941 1942
@@ -1947,7 +1948,7 @@ uri_sks_to_string(const struct GNUNET_FS_Uri *uri)
1947 * @return NULL on error 1948 * @return NULL on error
1948 */ 1949 */
1949static char * 1950static char *
1950uri_chk_to_string(const struct GNUNET_FS_Uri *uri) 1951uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
1951{ 1952{
1952 const struct FileIdentifier *fi; 1953 const struct FileIdentifier *fi;
1953 char *ret; 1954 char *ret;
@@ -1957,16 +1958,16 @@ uri_chk_to_string(const struct GNUNET_FS_Uri *uri)
1957 if (uri->type != GNUNET_FS_URI_CHK) 1958 if (uri->type != GNUNET_FS_URI_CHK)
1958 return NULL; 1959 return NULL;
1959 fi = &uri->data.chk; 1960 fi = &uri->data.chk;
1960 GNUNET_CRYPTO_hash_to_enc(&fi->chk.key, &keyhash); 1961 GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash);
1961 GNUNET_CRYPTO_hash_to_enc(&fi->chk.query, &queryhash); 1962 GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash);
1962 1963
1963 GNUNET_asprintf(&ret, 1964 GNUNET_asprintf (&ret,
1964 "%s%s%s.%s.%llu", 1965 "%s%s%s.%s.%llu",
1965 GNUNET_FS_URI_PREFIX, 1966 GNUNET_FS_URI_PREFIX,
1966 GNUNET_FS_URI_CHK_INFIX, 1967 GNUNET_FS_URI_CHK_INFIX,
1967 (const char *)&keyhash, 1968 (const char *) &keyhash,
1968 (const char *)&queryhash, 1969 (const char *) &queryhash,
1969 GNUNET_ntohll(fi->file_length)); 1970 GNUNET_ntohll (fi->file_length));
1970 return ret; 1971 return ret;
1971} 1972}
1972 1973
@@ -1978,7 +1979,7 @@ uri_chk_to_string(const struct GNUNET_FS_Uri *uri)
1978 * @return NULL on error 1979 * @return NULL on error
1979 */ 1980 */
1980static char * 1981static char *
1981uri_loc_to_string(const struct GNUNET_FS_Uri *uri) 1982uri_loc_to_string (const struct GNUNET_FS_Uri *uri)
1982{ 1983{
1983 char *ret; 1984 char *ret;
1984 struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; 1985 struct GNUNET_CRYPTO_HashAsciiEncoded keyhash;
@@ -1986,30 +1987,30 @@ uri_loc_to_string(const struct GNUNET_FS_Uri *uri)
1986 char *peer_id; 1987 char *peer_id;
1987 char peer_sig[SIGNATURE_ASCII_LENGTH + 1]; 1988 char peer_sig[SIGNATURE_ASCII_LENGTH + 1];
1988 1989
1989 GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.key, &keyhash); 1990 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash);
1990 GNUNET_CRYPTO_hash_to_enc(&uri->data.loc.fi.chk.query, &queryhash); 1991 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
1991 peer_id = 1992 peer_id =
1992 GNUNET_CRYPTO_eddsa_public_key_to_string(&uri->data.loc.peer.public_key); 1993 GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key);
1993 GNUNET_assert( 1994 GNUNET_assert (
1994 NULL != 1995 NULL !=
1995 GNUNET_STRINGS_data_to_string(&uri->data.loc.contentSignature, 1996 GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature,
1996 sizeof(struct GNUNET_CRYPTO_EddsaSignature), 1997 sizeof(struct GNUNET_CRYPTO_EddsaSignature),
1997 peer_sig, 1998 peer_sig,
1998 sizeof(peer_sig))); 1999 sizeof(peer_sig)));
1999 GNUNET_asprintf(&ret, 2000 GNUNET_asprintf (&ret,
2000 "%s%s%s.%s.%llu.%s.%s.%llu", 2001 "%s%s%s.%s.%llu.%s.%s.%llu",
2001 GNUNET_FS_URI_PREFIX, 2002 GNUNET_FS_URI_PREFIX,
2002 GNUNET_FS_URI_LOC_INFIX, 2003 GNUNET_FS_URI_LOC_INFIX,
2003 (const char *)&keyhash, 2004 (const char *) &keyhash,
2004 (const char *)&queryhash, 2005 (const char *) &queryhash,
2005 (unsigned long long)GNUNET_ntohll( 2006 (unsigned long long) GNUNET_ntohll (
2006 uri->data.loc.fi.file_length), 2007 uri->data.loc.fi.file_length),
2007 peer_id, 2008 peer_id,
2008 peer_sig, 2009 peer_sig,
2009 (unsigned long long) 2010 (unsigned long long)
2010 uri->data.loc.expirationTime.abs_value_us / 2011 uri->data.loc.expirationTime.abs_value_us
2011 1000000LL); 2012 / 1000000LL);
2012 GNUNET_free(peer_id); 2013 GNUNET_free (peer_id);
2013 return ret; 2014 return ret;
2014} 2015}
2015 2016
@@ -2021,31 +2022,31 @@ uri_loc_to_string(const struct GNUNET_FS_Uri *uri)
2021 * @return the UTF-8 string 2022 * @return the UTF-8 string
2022 */ 2023 */
2023char * 2024char *
2024GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri) 2025GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri)
2025{ 2026{
2026 if (uri == NULL) 2027 if (uri == NULL)
2027 { 2028 {
2028 GNUNET_break(0); 2029 GNUNET_break (0);
2029 return NULL; 2030 return NULL;
2030 } 2031 }
2031 switch (uri->type) 2032 switch (uri->type)
2032 { 2033 {
2033 case GNUNET_FS_URI_KSK: 2034 case GNUNET_FS_URI_KSK:
2034 return uri_ksk_to_string(uri); 2035 return uri_ksk_to_string (uri);
2035 2036
2036 case GNUNET_FS_URI_SKS: 2037 case GNUNET_FS_URI_SKS:
2037 return uri_sks_to_string(uri); 2038 return uri_sks_to_string (uri);
2038 2039
2039 case GNUNET_FS_URI_CHK: 2040 case GNUNET_FS_URI_CHK:
2040 return uri_chk_to_string(uri); 2041 return uri_chk_to_string (uri);
2041 2042
2042 case GNUNET_FS_URI_LOC: 2043 case GNUNET_FS_URI_LOC:
2043 return uri_loc_to_string(uri); 2044 return uri_loc_to_string (uri);
2044 2045
2045 default: 2046 default:
2046 GNUNET_break(0); 2047 GNUNET_break (0);
2047 return NULL; 2048 return NULL;
2048 } 2049 }
2049} 2050}
2050 2051
2051/* end of fs_uri.c */ 2052/* end of fs_uri.c */