diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-08-07 18:18:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-08-07 18:18:56 +0000 |
commit | 645767a8803ddfee212fc77bc80dd35fe2be1b0a (patch) | |
tree | bcb7c4c1c372e4f09189b681b3c9486a18c8926d | |
parent | b80e650bad570e01b5600aab2a667d177fc17770 (diff) | |
download | gnunet-645767a8803ddfee212fc77bc80dd35fe2be1b0a.tar.gz gnunet-645767a8803ddfee212fc77bc80dd35fe2be1b0a.zip |
hxing
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/fs/fs.h | 3 | ||||
-rw-r--r-- | src/fs/fs_getopt.c | 15 | ||||
-rw-r--r-- | src/fs/fs_uri.c | 1181 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 78 |
5 files changed, 694 insertions, 584 deletions
diff --git a/configure.ac b/configure.ac index 9932e9092..d4f0ab891 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -748,6 +748,7 @@ src/core/Makefile | |||
748 | src/datacache/Makefile | 748 | src/datacache/Makefile |
749 | src/datastore/Makefile | 749 | src/datastore/Makefile |
750 | src/fragmentation/Makefile | 750 | src/fragmentation/Makefile |
751 | src/fs/Makefile | ||
751 | src/hello/Makefile | 752 | src/hello/Makefile |
752 | src/include/Makefile | 753 | src/include/Makefile |
753 | src/include/gnunet_directories.h | 754 | src/include/gnunet_directories.h |
diff --git a/src/fs/fs.h b/src/fs/fs.h index c6d5d38cc..27ac39238 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -73,8 +73,7 @@ struct Location | |||
73 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer; | 73 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Time when the HELLO *and* this location URI | 76 | * Time when this location URI expires. |
77 | * expire (they expire together!). | ||
78 | */ | 77 | */ |
79 | struct GNUNET_TIME_Absolute expirationTime; | 78 | struct GNUNET_TIME_Absolute expirationTime; |
80 | 79 | ||
diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c index 8afe49852..dfcc4fdc4 100644 --- a/src/fs/fs_getopt.c +++ b/src/fs/fs_getopt.c | |||
@@ -24,11 +24,10 @@ | |||
24 | * @author Igor Wronsky, Christian Grothoff | 24 | * @author Igor Wronsky, Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_fs_lib.h" | 27 | #include "gnunet_fs_service.h" |
28 | #include "fs.h" | ||
28 | 29 | ||
29 | 30 | /* ******************** command-line option parsing API ******************** */ | |
30 | |||
31 | /* ******************** command-line option parsing API *********************** */ | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Command-line option parser function that allows the user | 33 | * Command-line option parser function that allows the user |
@@ -43,7 +42,7 @@ | |||
43 | * @return GNUNET_OK on success | 42 | * @return GNUNET_OK on success |
44 | */ | 43 | */ |
45 | int | 44 | int |
46 | GNUNET_FS_getopt_configure_set_keywords (GNUNET_GETOPT_CommandLineProcessorContext* ctx, | 45 | GNUNET_FS_getopt_configure_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, |
47 | void *scls, | 46 | void *scls, |
48 | const char *option, | 47 | const char *option, |
49 | const char *value) | 48 | const char *value) |
@@ -55,7 +54,7 @@ GNUNET_FS_getopt_configure_set_keywords (GNUNET_GETOPT_CommandLineProcessorConte | |||
55 | 54 | ||
56 | if (u == NULL) | 55 | if (u == NULL) |
57 | { | 56 | { |
58 | u = GNUNET_malloc (sizeof (struct GNUNET_ECRS_URI)); | 57 | u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
59 | *uri = u; | 58 | *uri = u; |
60 | u->type = ksk; | 59 | u->type = ksk; |
61 | u->data.ksk.keywordCount = 0; | 60 | u->data.ksk.keywordCount = 0; |
@@ -125,7 +124,7 @@ GNUNET_FS_getopt_configure_set_keywords (GNUNET_GETOPT_CommandLineProcessorConte | |||
125 | * @return GNUNET_OK on success | 124 | * @return GNUNET_OK on success |
126 | */ | 125 | */ |
127 | int | 126 | int |
128 | GNUNET_FS_getopt_configure_set_metadata (GNUNET_GETOPT_CommandLineProcessorContext* ctx, | 127 | GNUNET_FS_getopt_configure_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, |
129 | void *scls, | 128 | void *scls, |
130 | const char *option, | 129 | const char *option, |
131 | const char *value) | 130 | const char *value) |
@@ -145,7 +144,7 @@ GNUNET_FS_getopt_configure_set_metadata (GNUNET_GETOPT_CommandLineProcessorConte | |||
145 | *mm = meta; | 144 | *mm = meta; |
146 | } | 145 | } |
147 | 146 | ||
148 | tmp = GNUNET_STRINGS_to_utf8 (NULL, value, strlen (value), | 147 | tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), |
149 | #if ENABLE_NLS | 148 | #if ENABLE_NLS |
150 | nl_langinfo (CODESET) | 149 | nl_langinfo (CODESET) |
151 | #else | 150 | #else |
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 863ab475d..10ffe1350 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -79,7 +79,7 @@ | |||
79 | * <p> | 79 | * <p> |
80 | */ | 80 | */ |
81 | #include "platform.h" | 81 | #include "platform.h" |
82 | #include "gnunet_fs_lib.h" | 82 | #include "gnunet_fs_service.h" |
83 | #include "fs.h" | 83 | #include "fs.h" |
84 | 84 | ||
85 | 85 | ||
@@ -97,21 +97,21 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
97 | switch (uri->type) | 97 | switch (uri->type) |
98 | { | 98 | { |
99 | case chk: | 99 | case chk: |
100 | *key = uri->data.fi.chk.query; | 100 | *key = uri->data.chk.chk.query; |
101 | return; | 101 | return; |
102 | case sks: | 102 | case sks: |
103 | GNUNET_hash (uri->data.sks.identifier, | 103 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, |
104 | strlen (uri->data.sks.identifier), key); | 104 | strlen (uri->data.sks.identifier), key); |
105 | break; | 105 | break; |
106 | case ksk: | 106 | case ksk: |
107 | if (uri->data.ksk.keywordCount > 0) | 107 | if (uri->data.ksk.keywordCount > 0) |
108 | GNUNET_hash (uri->data.ksk.keywords[0], | 108 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], |
109 | strlen (uri->data.ksk.keywords[0]), key); | 109 | strlen (uri->data.ksk.keywords[0]), key); |
110 | break; | 110 | break; |
111 | case loc: | 111 | case loc: |
112 | GNUNET_hash (&uri->data.loc.fi, | 112 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, |
113 | sizeof (GNUNET_EC_FileIdentifier) + | 113 | sizeof (struct FileIdentifier) + |
114 | sizeof (GNUNET_RSA_PublicKey), key); | 114 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), key); |
115 | break; | 115 | break; |
116 | default: | 116 | default: |
117 | memset (key, 0, sizeof (GNUNET_HashCode)); | 117 | memset (key, 0, sizeof (GNUNET_HashCode)); |
@@ -121,24 +121,400 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
121 | 121 | ||
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Convert a URI to a UTF-8 String. | 124 | * Convert keyword URI to a human readable format |
125 | * (i.e. the search query that was used in the first place) | ||
125 | * | 126 | * |
126 | * @param uri uri to convert to a string | 127 | * @param uri ksk uri to convert to a string |
127 | * @return the UTF-8 string | 128 | * @return string with the keywords |
128 | */ | 129 | */ |
129 | char * | 130 | char * |
130 | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri); | 131 | GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) |
132 | { | ||
133 | size_t n; | ||
134 | char *ret; | ||
135 | unsigned int i; | ||
136 | const char *keyword; | ||
137 | char **keywords; | ||
138 | unsigned int keywordCount; | ||
139 | |||
140 | if ((uri == NULL) || (uri->type != ksk)) | ||
141 | { | ||
142 | GNUNET_break (0); | ||
143 | return NULL; | ||
144 | } | ||
145 | keywords = uri->data.ksk.keywords; | ||
146 | keywordCount = uri->data.ksk.keywordCount; | ||
147 | n = keywordCount + 1; | ||
148 | for (i = 0; i < keywordCount; i++) | ||
149 | { | ||
150 | keyword = keywords[i]; | ||
151 | n += strlen (keyword) - 1; | ||
152 | if (NULL != strstr (&keyword[1], " ")) | ||
153 | n += 2; | ||
154 | if (keyword[0] == '+') | ||
155 | n++; | ||
156 | } | ||
157 | ret = GNUNET_malloc (n); | ||
158 | strcpy (ret, ""); | ||
159 | for (i = 0; i < keywordCount; i++) | ||
160 | { | ||
161 | keyword = keywords[i]; | ||
162 | if (NULL != strstr (&keyword[1], " ")) | ||
163 | { | ||
164 | strcat (ret, "\""); | ||
165 | if (keyword[0] == '+') | ||
166 | strcat (ret, keyword); | ||
167 | else | ||
168 | strcat (ret, &keyword[1]); | ||
169 | strcat (ret, "\""); | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | if (keyword[0] == '+') | ||
174 | strcat (ret, keyword); | ||
175 | else | ||
176 | strcat (ret, &keyword[1]); | ||
177 | } | ||
178 | strcat (ret, " "); | ||
179 | } | ||
180 | return ret; | ||
181 | } | ||
182 | |||
183 | |||
131 | 184 | ||
132 | 185 | ||
133 | /** | 186 | /** |
134 | * Convert keyword URI to a human readable format | 187 | * Given a keyword with %-encoding (and possibly quotes to protect |
135 | * (i.e. the search query that was used in the first place) | 188 | * spaces), return a copy of the keyword without %-encoding and |
189 | * without double-quotes (%22). Also, add a space at the beginning | ||
190 | * if there is not a '+'. | ||
191 | * | ||
192 | * @param in string with %-encoding | ||
193 | * @param emsg where to store the parser error message (if any) | ||
194 | * @return decodded string with leading space (or preserved plus) | ||
195 | */ | ||
196 | static char * | ||
197 | percent_decode_keyword (const char *in, char **emsg) | ||
198 | { | ||
199 | char *out; | ||
200 | char *ret; | ||
201 | unsigned int rpos; | ||
202 | unsigned int wpos; | ||
203 | unsigned int hx; | ||
204 | |||
205 | out = GNUNET_strdup (in); | ||
206 | rpos = 0; | ||
207 | wpos = 0; | ||
208 | while (out[rpos] != '\0') | ||
209 | { | ||
210 | if (out[rpos] == '%') | ||
211 | { | ||
212 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) | ||
213 | { | ||
214 | GNUNET_free (out); | ||
215 | return NULL; | ||
216 | } | ||
217 | rpos += 3; | ||
218 | if (hx == '"') | ||
219 | continue; /* skip double quote */ | ||
220 | out[wpos++] = (char) hx; | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | out[wpos++] = out[rpos++]; | ||
225 | } | ||
226 | } | ||
227 | out[wpos] = '\0'; | ||
228 | if (out[0] == '+') | ||
229 | { | ||
230 | ret = GNUNET_strdup (out); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | /* need to prefix with space */ | ||
235 | ret = GNUNET_malloc (strlen (out) + 2); | ||
236 | strcpy (ret, " "); | ||
237 | strcat (ret, out); | ||
238 | } | ||
239 | GNUNET_free (out); | ||
240 | return ret; | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Parse a KSK URI. | ||
136 | * | 246 | * |
137 | * @param uri ksk uri to convert to a string | 247 | * @param s an uri string |
138 | * @return string with the keywords | 248 | * @param emsg where to store the parser error message (if any) |
249 | * @return NULL on error, otherwise the KSK URI | ||
139 | */ | 250 | */ |
140 | char * | 251 | static struct GNUNET_FS_Uri * |
141 | GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri); | 252 | uri_ksk_parse (const char *s, char **emsg) |
253 | { | ||
254 | struct GNUNET_FS_Uri *ret; | ||
255 | char **keywords; | ||
256 | unsigned int pos; | ||
257 | int max; | ||
258 | int iret; | ||
259 | int i; | ||
260 | size_t slen; | ||
261 | char *dup; | ||
262 | int saw_quote; | ||
263 | |||
264 | GNUNET_assert (s != NULL); | ||
265 | slen = strlen (s); | ||
266 | pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX); | ||
267 | if ( (slen <= pos) || | ||
268 | (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX, | ||
269 | pos) ) || | ||
270 | (s[slen - 1] == '+') || | ||
271 | (s[pos] == '+') ) | ||
272 | return NULL; /* no keywords / malformed */ | ||
273 | |||
274 | max = 1; | ||
275 | saw_quote = 0; | ||
276 | for (i = pos; i < slen; i++) | ||
277 | { | ||
278 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
279 | { | ||
280 | saw_quote = (saw_quote + 1) % 2; | ||
281 | i += 3; | ||
282 | continue; | ||
283 | } | ||
284 | if ((s[i] == '+') && (saw_quote == 0)) | ||
285 | { | ||
286 | max++; | ||
287 | if (s[i - 1] == '+') | ||
288 | return NULL; /* "++" not allowed */ | ||
289 | } | ||
290 | } | ||
291 | if (saw_quote == 1) | ||
292 | return NULL; /* quotes not balanced */ | ||
293 | iret = max; | ||
294 | dup = GNUNET_strdup (s); | ||
295 | keywords = GNUNET_malloc (max * sizeof (char *)); | ||
296 | for (i = slen - 1; i >= pos; i--) | ||
297 | { | ||
298 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | ||
299 | { | ||
300 | saw_quote = (saw_quote + 1) % 2; | ||
301 | i += 3; | ||
302 | continue; | ||
303 | } | ||
304 | if ((dup[i] == '+') && (saw_quote == 0)) | ||
305 | { | ||
306 | keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg); | ||
307 | if (NULL == keywords[max]) | ||
308 | goto CLEANUP; | ||
309 | dup[i] = '\0'; | ||
310 | } | ||
311 | } | ||
312 | keywords[--max] = percent_decode_keyword (&dup[pos], emsg); | ||
313 | if (NULL == keywords[max]) | ||
314 | goto CLEANUP; | ||
315 | GNUNET_assert (max == 0); | ||
316 | GNUNET_free (dup); | ||
317 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | ||
318 | ret->type = ksk; | ||
319 | ret->data.ksk.keywordCount = iret; | ||
320 | ret->data.ksk.keywords = keywords; | ||
321 | return ret; | ||
322 | CLEANUP: | ||
323 | for (i = 0; i < max; i++) | ||
324 | GNUNET_free_non_null (keywords[i]); | ||
325 | GNUNET_free (keywords); | ||
326 | GNUNET_free (dup); | ||
327 | return NULL; | ||
328 | } | ||
329 | |||
330 | |||
331 | /** | ||
332 | * Parse an SKS URI. | ||
333 | * | ||
334 | * @param s an uri string | ||
335 | * @param emsg where to store the parser error message (if any) | ||
336 | * @return NULL on error, SKS URI otherwise | ||
337 | */ | ||
338 | static struct GNUNET_FS_Uri * | ||
339 | uri_sks_parse (const char *s, char **emsg) | ||
340 | { | ||
341 | struct GNUNET_FS_Uri *ret; | ||
342 | GNUNET_HashCode namespace; | ||
343 | char *identifier; | ||
344 | unsigned int pos; | ||
345 | size_t slen; | ||
346 | char enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
347 | |||
348 | GNUNET_assert (s != NULL); | ||
349 | slen = strlen (s); | ||
350 | pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX); | ||
351 | if ( (slen <= pos) || | ||
352 | (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX, | ||
353 | pos) ) || | ||
354 | (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | ||
355 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/') ) | ||
356 | return NULL; | ||
357 | memcpy (enc, &s[pos], sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
358 | enc[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
359 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace)) | ||
360 | return NULL; | ||
361 | identifier = GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]); | ||
362 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | ||
363 | ret->type = sks; | ||
364 | ret->data.sks.namespace = namespace; | ||
365 | ret->data.sks.identifier = identifier; | ||
366 | return ret; | ||
367 | } | ||
368 | |||
369 | |||
370 | /** | ||
371 | * Parse a CHK URI. | ||
372 | * | ||
373 | * @param s an uri string | ||
374 | * @param emsg where to store the parser error message (if any) | ||
375 | * @return NULL on error, CHK URI otherwise | ||
376 | */ | ||
377 | static struct GNUNET_FS_Uri * | ||
378 | uri_chk_parse (const char *s, char **emsg) | ||
379 | { | ||
380 | struct GNUNET_FS_Uri *ret; | ||
381 | struct FileIdentifier fi; | ||
382 | unsigned int pos; | ||
383 | size_t slen; | ||
384 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
385 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
386 | |||
387 | GNUNET_assert (s != NULL); | ||
388 | |||
389 | slen = strlen (s); | ||
390 | pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX); | ||
391 | if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | ||
392 | (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX, | ||
393 | pos) ) || | ||
394 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | ||
395 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.') ) | ||
396 | return NULL; | ||
397 | |||
398 | memcpy (h1, | ||
399 | &s[pos], | ||
400 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
401 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
402 | memcpy (h2, | ||
403 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], | ||
404 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
405 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
406 | |||
407 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, | ||
408 | &fi.chk.key)) || | ||
409 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, | ||
410 | &fi.chk.query)) || | ||
411 | (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | ||
412 | "%llu", | ||
413 | &fi.file_length))) | ||
414 | return NULL; | ||
415 | fi.file_length = GNUNET_htonll (fi.file_length); | ||
416 | |||
417 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | ||
418 | ret->type = chk; | ||
419 | ret->data.chk = fi; | ||
420 | return ret; | ||
421 | } | ||
422 | |||
423 | |||
424 | /** | ||
425 | * Parse a LOC URI. | ||
426 | * Also verifies validity of the location URI. | ||
427 | * | ||
428 | * @param s an uri string | ||
429 | * @param emsg where to store the parser error message (if any) | ||
430 | * @return NULL on error, valid LOC URI otherwise | ||
431 | */ | ||
432 | static struct GNUNET_FS_Uri * | ||
433 | uri_loc_parse (const char *s, char **emsg) | ||
434 | { | ||
435 | struct GNUNET_FS_Uri *ret; | ||
436 | char h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
437 | char h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
438 | unsigned int pos; | ||
439 | unsigned int npos; | ||
440 | unsigned long long exptime; | ||
441 | int ret; | ||
442 | size_t slen; | ||
443 | char *addr; | ||
444 | |||
445 | GNUNET_assert (s != NULL); | ||
446 | slen = strlen (s); | ||
447 | pos = strlen (GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX); | ||
448 | if ( (slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | ||
449 | (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX, | ||
450 | pos) ) || | ||
451 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | ||
452 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.') ) | ||
453 | return NULL; | ||
454 | |||
455 | memcpy (h1, | ||
456 | &s[pos], | ||
457 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
458 | h1[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
459 | memcpy (h2, | ||
460 | &s[pos + sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)], | ||
461 | sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
462 | h2[sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded)-1] = '\0'; | ||
463 | |||
464 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, | ||
465 | &fi.chk.key)) || | ||
466 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, | ||
467 | &fi.chk.query)) | ||
468 | (1 != SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | ||
469 | "%llu", | ||
470 | &fi.file_length)) ) | ||
471 | return NULL; | ||
472 | fi.file_length = GNUNET_htonll (fi.file_length); | ||
473 | |||
474 | npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2; | ||
475 | while ((s[npos] != '\0') && (s[npos] != '.')) | ||
476 | npos++; | ||
477 | if (s[npos] == '\0') | ||
478 | goto ERR; | ||
479 | ret = enc2bin (&s[npos], | ||
480 | &loc->peer, | ||
481 | sizeof (GNUNET_RSA_PublicKey)); | ||
482 | if (ret == -1) | ||
483 | goto ERR; | ||
484 | npos += ret; | ||
485 | if (dup[npos++] != '.') | ||
486 | goto ERR; | ||
487 | ret = enc2bin (&s[npos], | ||
488 | &loc->contentSignature, | ||
489 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
490 | if (ret == -1) | ||
491 | goto ERR; | ||
492 | npos += ret; | ||
493 | if (dup[npos++] != '.') | ||
494 | goto ERR; | ||
495 | if (1 != SSCANF (&dup[npos], "%llu", &exptime)) | ||
496 | goto ERR; | ||
497 | // FIXME: do something to exptime... | ||
498 | /* Finally: verify sigs! */ | ||
499 | if (GNUNET_OK != GNUNET_RSA_verify (&loc->fi, | ||
500 | sizeof (struct FileIdentifier) + | ||
501 | sizeof (GNUNET_PeerIdentity) + | ||
502 | sizeof (GNUNET_Int32Time), | ||
503 | &loc->contentSignature, | ||
504 | &loc->peer)) | ||
505 | goto ERR; | ||
506 | |||
507 | ret = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | ||
508 | ret->type = loc; | ||
509 | ret->data.loc.chk = fi; | ||
510 | ret->data.loc.xx = yy; | ||
511 | |||
512 | return ret; | ||
513 | ERR: | ||
514 | GNUNET_free_non_null (addr); | ||
515 | return NULL; | ||
516 | } | ||
517 | |||
142 | 518 | ||
143 | /** | 519 | /** |
144 | * Convert a UTF-8 String to a URI. | 520 | * Convert a UTF-8 String to a URI. |
@@ -149,7 +525,18 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri); | |||
149 | */ | 525 | */ |
150 | struct GNUNET_FS_Uri * | 526 | struct GNUNET_FS_Uri * |
151 | GNUNET_FS_uri_parse (const char *uri, | 527 | GNUNET_FS_uri_parse (const char *uri, |
152 | char **emsg); | 528 | char **emsg) |
529 | { | ||
530 | struct GNUNET_FS_Uri *ret; | ||
531 | |||
532 | if ( (NULL != (ret = uri_chk_parse (uri, emsg))) || | ||
533 | (NULL != (ret = uri_ksk_parse (uri, emsg))) || | ||
534 | (NULL != (ret = uri_sks_parse (uri, emsg))) || | ||
535 | (NULL != (ret = uri_loc_parse (uri, emsg))) ) | ||
536 | return ret; | ||
537 | return NULL; | ||
538 | } | ||
539 | |||
153 | 540 | ||
154 | /** | 541 | /** |
155 | * Free URI. | 542 | * Free URI. |
@@ -223,7 +610,9 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
223 | keyword = uri->data.ksk.keywords[i]; | 610 | keyword = uri->data.ksk.keywords[i]; |
224 | /* first character of keyword indicates | 611 | /* first character of keyword indicates |
225 | if it is mandatory or not */ | 612 | if it is mandatory or not */ |
226 | if (GNUNET_OK != iterator (&keyword[1], keyword[0] == '+', cls)) | 613 | if (GNUNET_OK != iterator (iterator_cls, |
614 | &keyword[1], | ||
615 | keyword[0] == '+')) | ||
227 | return i; | 616 | return i; |
228 | } | 617 | } |
229 | return i; | 618 | return i; |
@@ -243,8 +632,9 @@ GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, | |||
243 | { | 632 | { |
244 | if (uri->type != loc) | 633 | if (uri->type != loc) |
245 | return GNUNET_SYSERR; | 634 | return GNUNET_SYSERR; |
246 | GNUNET_hash (&uri->data.loc.peer, sizeof (GNUNET_RSA_PublicKey), | 635 | GNUNET_CRYPTO_hash (&uri->data.loc.peer, |
247 | &peer->hashPubKey); | 636 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
637 | &peer->hashPubKey); | ||
248 | return GNUNET_OK; | 638 | return GNUNET_OK; |
249 | } | 639 | } |
250 | 640 | ||
@@ -258,11 +648,11 @@ GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, | |||
258 | struct GNUNET_FS_Uri * | 648 | struct GNUNET_FS_Uri * |
259 | GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) | 649 | GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) |
260 | { | 650 | { |
261 | struct GNUNET_ECRS_Uri *ret; | 651 | struct GNUNET_FS_Uri *ret; |
262 | 652 | ||
263 | if (uri->type != loc) | 653 | if (uri->type != loc) |
264 | return NULL; | 654 | return NULL; |
265 | ret = GNUNET_malloc (sizeof (struct GNUNET_ECRS_Uri)); | 655 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
266 | ret->type = chk; | 656 | ret->type = chk; |
267 | ret->data.chk = uri->data.loc.fi; | 657 | ret->data.chk = uri->data.loc.fi; |
268 | return ret; | 658 | return ret; |
@@ -292,7 +682,11 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
292 | * @return canonicalized version of the URI, NULL on error | 682 | * @return canonicalized version of the URI, NULL on error |
293 | */ | 683 | */ |
294 | struct GNUNET_FS_Uri * | 684 | struct GNUNET_FS_Uri * |
295 | GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri); | 685 | GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri) |
686 | { | ||
687 | /* FIXME: not implemented */ | ||
688 | return NULL; | ||
689 | } | ||
296 | 690 | ||
297 | 691 | ||
298 | /** | 692 | /** |
@@ -306,7 +700,11 @@ GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri); | |||
306 | */ | 700 | */ |
307 | struct GNUNET_FS_Uri * | 701 | struct GNUNET_FS_Uri * |
308 | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | 702 | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, |
309 | const struct GNUNET_FS_Uri *u2); | 703 | const struct GNUNET_FS_Uri *u2) |
704 | { | ||
705 | /* FIXME */ | ||
706 | return NULL; | ||
707 | } | ||
310 | 708 | ||
311 | 709 | ||
312 | /** | 710 | /** |
@@ -318,7 +716,7 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | |||
318 | struct GNUNET_FS_Uri * | 716 | struct GNUNET_FS_Uri * |
319 | GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | 717 | GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) |
320 | { | 718 | { |
321 | struct GNUNET_ECRS_URI *ret; | 719 | struct GNUNET_FS_Uri *ret; |
322 | unsigned int i; | 720 | unsigned int i; |
323 | 721 | ||
324 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 722 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
@@ -366,7 +764,11 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
366 | * if keywords is not legal (i.e. empty). | 764 | * if keywords is not legal (i.e. empty). |
367 | */ | 765 | */ |
368 | struct GNUNET_FS_Uri * | 766 | struct GNUNET_FS_Uri * |
369 | GNUNET_FS_uri_ksk_create (const char *keywords); | 767 | GNUNET_FS_uri_ksk_create (const char *keywords) |
768 | { | ||
769 | /* FIXME */ | ||
770 | return NULL; | ||
771 | } | ||
370 | 772 | ||
371 | 773 | ||
372 | /** | 774 | /** |
@@ -388,7 +790,11 @@ GNUNET_FS_uri_ksk_create (const char *keywords); | |||
388 | */ | 790 | */ |
389 | struct GNUNET_FS_Uri * | 791 | struct GNUNET_FS_Uri * |
390 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | 792 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, |
391 | const char **argv); | 793 | const char **argv) |
794 | { | ||
795 | /* FIXME */ | ||
796 | return NULL; | ||
797 | } | ||
392 | 798 | ||
393 | 799 | ||
394 | /** | 800 | /** |
@@ -406,37 +812,37 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
406 | unsigned int i; | 812 | unsigned int i; |
407 | unsigned int j; | 813 | unsigned int j; |
408 | 814 | ||
409 | GNUNET_assert (uri1 != NULL); | 815 | GNUNET_assert (u1 != NULL); |
410 | GNUNET_assert (uri2 != NULL); | 816 | GNUNET_assert (u2 != NULL); |
411 | if (uri1->type != uri2->type) | 817 | if (u1->type != u2->type) |
412 | return GNUNET_NO; | 818 | return GNUNET_NO; |
413 | switch (uri1->type) | 819 | switch (u1->type) |
414 | { | 820 | { |
415 | case chk: | 821 | case chk: |
416 | if (0 == memcmp (&uri1->data.chk, | 822 | if (0 == memcmp (&u1->data.chk, |
417 | &uri2->data.chk, | 823 | &u2->data.chk, |
418 | sizeof (struct FileIdentifier))) | 824 | sizeof (struct FileIdentifier))) |
419 | return GNUNET_YES; | 825 | return GNUNET_YES; |
420 | return GNUNET_NO; | 826 | return GNUNET_NO; |
421 | case sks: | 827 | case sks: |
422 | if ((0 == memcmp (&uri1->data.sks.namespace, | 828 | if ((0 == memcmp (&u1->data.sks.namespace, |
423 | &uri2->data.sks.namespace, | 829 | &u2->data.sks.namespace, |
424 | sizeof (GNUNET_HashCode))) && | 830 | sizeof (GNUNET_HashCode))) && |
425 | (0 == strcmp (uri1->data.sks.identifier, | 831 | (0 == strcmp (u1->data.sks.identifier, |
426 | uri2->data.sks.identifier))) | 832 | u2->data.sks.identifier))) |
427 | 833 | ||
428 | return GNUNET_YES; | 834 | return GNUNET_YES; |
429 | return GNUNET_NO; | 835 | return GNUNET_NO; |
430 | case ksk: | 836 | case ksk: |
431 | if (uri1->data.ksk.keywordCount != uri2->data.ksk.keywordCount) | 837 | if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount) |
432 | return GNUNET_NO; | 838 | return GNUNET_NO; |
433 | for (i = 0; i < uri1->data.ksk.keywordCount; i++) | 839 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
434 | { | 840 | { |
435 | ret = GNUNET_NO; | 841 | ret = GNUNET_NO; |
436 | for (j = 0; j < uri2->data.ksk.keywordCount; j++) | 842 | for (j = 0; j < u2->data.ksk.keywordCount; j++) |
437 | { | 843 | { |
438 | if (0 == strcmp (uri1->data.ksk.keywords[i], | 844 | if (0 == strcmp (u1->data.ksk.keywords[i], |
439 | uri2->data.ksk.keywords[j])) | 845 | u2->data.ksk.keywords[j])) |
440 | { | 846 | { |
441 | ret = GNUNET_YES; | 847 | ret = GNUNET_YES; |
442 | break; | 848 | break; |
@@ -447,10 +853,10 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
447 | } | 853 | } |
448 | return GNUNET_YES; | 854 | return GNUNET_YES; |
449 | case loc: | 855 | case loc: |
450 | if (memcmp (&uri1->data.loc, | 856 | if (memcmp (&u1->data.loc, |
451 | &uri2->data.loc, | 857 | &u2->data.loc, |
452 | sizeof (struct FileIdentifier) + | 858 | sizeof (struct FileIdentifier) + |
453 | sizeof (GNUNET_RSA_PublicKey) + | 859 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + |
454 | sizeof (struct GNUNET_TIME_Absolute) + | 860 | sizeof (struct GNUNET_TIME_Absolute) + |
455 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) | 861 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) |
456 | return GNUNET_NO; | 862 | return GNUNET_NO; |
@@ -491,7 +897,7 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | |||
491 | GNUNET_break (0); | 897 | GNUNET_break (0); |
492 | return GNUNET_SYSERR; | 898 | return GNUNET_SYSERR; |
493 | } | 899 | } |
494 | *id = uri->data.sks.namespace; | 900 | *nsid = uri->data.sks.namespace; |
495 | return GNUNET_OK; | 901 | return GNUNET_OK; |
496 | } | 902 | } |
497 | 903 | ||
@@ -524,7 +930,11 @@ GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | |||
524 | */ | 930 | */ |
525 | char * | 931 | char * |
526 | GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, | 932 | GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, |
527 | const struct GNUNET_FS_Uri *uri); | 933 | const struct GNUNET_FS_Uri *uri) |
934 | { | ||
935 | /* FIXME */ | ||
936 | return NULL; | ||
937 | } | ||
528 | 938 | ||
529 | 939 | ||
530 | /** | 940 | /** |
@@ -634,7 +1044,7 @@ gather_uri_data (void *cls, | |||
634 | * @deprecated | 1044 | * @deprecated |
635 | */ | 1045 | */ |
636 | struct GNUNET_FS_Uri * | 1046 | struct GNUNET_FS_Uri * |
637 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_MetaData *md) | 1047 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) |
638 | { | 1048 | { |
639 | struct GNUNET_FS_Uri *ret; | 1049 | struct GNUNET_FS_Uri *ret; |
640 | 1050 | ||
@@ -646,17 +1056,12 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_MetaData *md) | |||
646 | ret->data.ksk.keywords = NULL; | 1056 | ret->data.ksk.keywords = NULL; |
647 | ret->data.ksk.keywords | 1057 | ret->data.ksk.keywords |
648 | = GNUNET_malloc (sizeof (char *) * | 1058 | = GNUNET_malloc (sizeof (char *) * |
649 | GNUNET_meta_data_get_contents (md, NULL, NULL)); | 1059 | GNUNET_CONTAINER_meta_data_get_contents (md, NULL, NULL)); |
650 | GNUNET_meta_data_get_contents (md, &gather_uri_data, ret); | 1060 | GNUNET_CONTAINER_meta_data_get_contents (md, &gather_uri_data, ret); |
651 | return ret; | 1061 | return ret; |
652 | 1062 | ||
653 | } | 1063 | } |
654 | 1064 | ||
655 | #if 0 | ||
656 | |||
657 | // old code... | ||
658 | |||
659 | |||
660 | 1065 | ||
661 | /** | 1066 | /** |
662 | * In URI-encoding, does the given character | 1067 | * In URI-encoding, does the given character |
@@ -669,13 +1074,18 @@ needs_percent (char c) | |||
669 | (c == '-') || (c == '_') || (c == '.') || (c == '~'))); | 1074 | (c == '-') || (c == '_') || (c == '.') || (c == '~'))); |
670 | } | 1075 | } |
671 | 1076 | ||
1077 | |||
672 | /** | 1078 | /** |
673 | * Generate a keyword URI. | 1079 | * Convert a KSK URI to a string. |
1080 | * | ||
1081 | * @param uri the URI to convert | ||
674 | * @return NULL on error (i.e. keywordCount == 0) | 1082 | * @return NULL on error (i.e. keywordCount == 0) |
675 | */ | 1083 | */ |
676 | static char * | 1084 | static char * |
677 | createKeywordURI (char **keywords, unsigned int keywordCount) | 1085 | uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) |
678 | { | 1086 | { |
1087 | char ** keywords; | ||
1088 | unsigned int keywordCount; | ||
679 | size_t n; | 1089 | size_t n; |
680 | char *ret; | 1090 | char *ret; |
681 | unsigned int i; | 1091 | unsigned int i; |
@@ -684,9 +1094,13 @@ createKeywordURI (char **keywords, unsigned int keywordCount) | |||
684 | size_t slen; | 1094 | size_t slen; |
685 | const char *keyword; | 1095 | const char *keyword; |
686 | 1096 | ||
1097 | if (uri->type != ksk) | ||
1098 | return NULL; | ||
1099 | keywords = uri->data.ksk.keywords; | ||
1100 | keywordCount = uri->data.ksk.keywordCount; | ||
687 | n = | 1101 | n = |
688 | keywordCount + strlen (GNUNET_ECRS_URI_PREFIX) + | 1102 | keywordCount + strlen (GNUNET_FS_URI_PREFIX) + |
689 | strlen (GNUNET_ECRS_SEARCH_INFIX) + 1; | 1103 | strlen (GNUNET_FS_URI_KSK_INFIX) + 1; |
690 | for (i = 0; i < keywordCount; i++) | 1104 | for (i = 0; i < keywordCount; i++) |
691 | { | 1105 | { |
692 | keyword = keywords[i]; | 1106 | keyword = keywords[i]; |
@@ -704,8 +1118,8 @@ createKeywordURI (char **keywords, unsigned int keywordCount) | |||
704 | } | 1118 | } |
705 | } | 1119 | } |
706 | ret = GNUNET_malloc (n); | 1120 | ret = GNUNET_malloc (n); |
707 | strcpy (ret, GNUNET_ECRS_URI_PREFIX); | 1121 | strcpy (ret, GNUNET_FS_URI_PREFIX); |
708 | strcat (ret, GNUNET_ECRS_SEARCH_INFIX); | 1122 | strcat (ret, GNUNET_FS_URI_KSK_INFIX); |
709 | wpos = strlen (ret); | 1123 | wpos = strlen (ret); |
710 | for (i = 0; i < keywordCount; i++) | 1124 | for (i = 0; i < keywordCount; i++) |
711 | { | 1125 | { |
@@ -731,548 +1145,245 @@ createKeywordURI (char **keywords, unsigned int keywordCount) | |||
731 | return ret; | 1145 | return ret; |
732 | } | 1146 | } |
733 | 1147 | ||
1148 | |||
734 | /** | 1149 | /** |
735 | * Generate a subspace URI. | 1150 | * Convert SKS URI to a string. |
1151 | * | ||
1152 | * @param uri sks uri to convert | ||
1153 | * @return NULL on error | ||
736 | */ | 1154 | */ |
737 | static char * | 1155 | static char * |
738 | createSubspaceURI (const GNUNET_HashCode * namespace, const char *identifier) | 1156 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) |
739 | { | 1157 | { |
740 | size_t n; | 1158 | const GNUNET_HashCode * namespace; |
1159 | const char *identifier; | ||
741 | char *ret; | 1160 | char *ret; |
742 | GNUNET_EncName ns; | 1161 | struct GNUNET_CRYPTO_HashAsciiEncoded ns; |
743 | 1162 | ||
744 | n = | 1163 | if (uri->type != sks) |
745 | sizeof (GNUNET_EncName) + strlen (GNUNET_ECRS_URI_PREFIX) + | 1164 | return NULL; |
746 | strlen (GNUNET_ECRS_SUBSPACE_INFIX) + 1 + strlen (identifier); | 1165 | namespace = &uri->data.sks.namespace; |
747 | ret = GNUNET_malloc (n); | 1166 | identifier = uri->data.sks.identifier; |
748 | GNUNET_hash_to_enc (namespace, &ns); | 1167 | GNUNET_CRYPTO_hash_to_enc (namespace, &ns); |
749 | GNUNET_snprintf (ret, n, | 1168 | GNUNET_asprintf (&ret, |
750 | "%s%s%s/%s", | 1169 | "%s%s%s/%s", |
751 | GNUNET_ECRS_URI_PREFIX, GNUNET_ECRS_SUBSPACE_INFIX, | 1170 | GNUNET_FS_URI_PREFIX, |
1171 | GNUNET_FS_URI_SKS_INFIX, | ||
752 | (const char *) &ns, identifier); | 1172 | (const char *) &ns, identifier); |
753 | return ret; | 1173 | return ret; |
754 | } | 1174 | } |
755 | 1175 | ||
1176 | |||
756 | /** | 1177 | /** |
757 | * Generate a file URI. | 1178 | * Convert a CHK URI to a string. |
1179 | * | ||
1180 | * @param uri chk uri to convert | ||
1181 | * @return NULL on error | ||
758 | */ | 1182 | */ |
759 | static char * | 1183 | static char * |
760 | createFileURI (const GNUNET_EC_FileIdentifier * fi) | 1184 | uri_chk_to_string (const struct GNUNET_FS_Uri *uri) |
761 | { | 1185 | { |
1186 | const struct FileIdentifier * fi; | ||
762 | char *ret; | 1187 | char *ret; |
763 | GNUNET_EncName keyhash; | 1188 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; |
764 | GNUNET_EncName queryhash; | 1189 | struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; |
765 | size_t n; | ||
766 | 1190 | ||
767 | GNUNET_hash_to_enc (&fi->chk.key, &keyhash); | 1191 | if (uri->type != chk) |
768 | GNUNET_hash_to_enc (&fi->chk.query, &queryhash); | 1192 | return NULL; |
1193 | fi = &uri->data.chk; | ||
1194 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); | ||
1195 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); | ||
769 | 1196 | ||
770 | n = | 1197 | GNUNET_asprintf (&ret, |
771 | strlen (GNUNET_ECRS_URI_PREFIX) + 2 * sizeof (GNUNET_EncName) + 8 + 16 + | ||
772 | 32 + strlen (GNUNET_ECRS_FILE_INFIX); | ||
773 | ret = GNUNET_malloc (n); | ||
774 | GNUNET_snprintf (ret, | ||
775 | n, | ||
776 | "%s%s%s.%s.%llu", | 1198 | "%s%s%s.%s.%llu", |
777 | GNUNET_ECRS_URI_PREFIX, | 1199 | GNUNET_FS_URI_PREFIX, |
778 | GNUNET_ECRS_FILE_INFIX, | 1200 | GNUNET_FS_URI_CHK_INFIX, |
779 | (char *) &keyhash, (char *) &queryhash, | 1201 | (const char *) &keyhash, |
1202 | (const char *) &queryhash, | ||
780 | GNUNET_ntohll (fi->file_length)); | 1203 | GNUNET_ntohll (fi->file_length)); |
781 | return ret; | 1204 | return ret; |
782 | } | 1205 | } |
783 | 1206 | ||
784 | #include "bincoder.c" | ||
785 | |||
786 | /** | 1207 | /** |
787 | * Create a (string) location URI from a Location. | 1208 | * Convert binary data to a string. |
1209 | * | ||
1210 | * @return converted data | ||
788 | */ | 1211 | */ |
789 | static char * | 1212 | static char * |
790 | createLocURI (const Location * loc) | 1213 | bin2enc (const void *data, size_t size) |
791 | { | ||
792 | size_t n; | ||
793 | char *ret; | ||
794 | GNUNET_EncName keyhash; | ||
795 | GNUNET_EncName queryhash; | ||
796 | char *peerId; | ||
797 | char *peerSig; | ||
798 | |||
799 | GNUNET_hash_to_enc (&loc->fi.chk.key, &keyhash); | ||
800 | GNUNET_hash_to_enc (&loc->fi.chk.query, &queryhash); | ||
801 | n = 2148; | ||
802 | peerId = bin2enc (&loc->peer, sizeof (GNUNET_RSA_PublicKey)); | ||
803 | peerSig = bin2enc (&loc->contentSignature, sizeof (GNUNET_RSA_Signature)); | ||
804 | ret = GNUNET_malloc (n); | ||
805 | GNUNET_snprintf (ret, | ||
806 | n, | ||
807 | "%s%s%s.%s.%llu.%s.%s.%u", | ||
808 | GNUNET_ECRS_URI_PREFIX, | ||
809 | GNUNET_ECRS_LOCATION_INFIX, | ||
810 | (char *) &keyhash, | ||
811 | (char *) &queryhash, | ||
812 | GNUNET_ntohll (loc->fi.file_length), | ||
813 | peerId, peerSig, loc->expirationTime); | ||
814 | GNUNET_free (peerSig); | ||
815 | GNUNET_free (peerId); | ||
816 | return ret; | ||
817 | } | ||
818 | |||
819 | /** | ||
820 | * Convert a URI to a UTF-8 String. | ||
821 | */ | ||
822 | char * | ||
823 | GNUNET_ECRS_uri_to_string (const struct GNUNET_ECRS_URI *uri) | ||
824 | { | 1214 | { |
825 | if (uri == NULL) | 1215 | /** |
826 | { | 1216 | * 64 characters for encoding, 6 bits per character |
827 | GNUNET_GE_BREAK (NULL, 0); | 1217 | */ |
828 | return NULL; | 1218 | static char *tbl = |
829 | } | 1219 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_="; |
830 | switch (uri->type) | 1220 | |
831 | { | 1221 | size_t len; |
832 | case ksk: | 1222 | size_t pos; |
833 | return createKeywordURI (uri->data.ksk.keywords, | 1223 | unsigned int bits; |
834 | uri->data.ksk.keywordCount); | 1224 | unsigned int hbits; |
835 | case sks: | ||
836 | return createSubspaceURI (&uri->data.sks.namespace, | ||
837 | uri->data.sks.identifier); | ||
838 | case chk: | ||
839 | return createFileURI (&uri->data.fi); | ||
840 | case loc: | ||
841 | return createLocURI (&uri->data.loc); | ||
842 | default: | ||
843 | GNUNET_GE_BREAK (NULL, 0); | ||
844 | return NULL; | ||
845 | } | ||
846 | } | ||
847 | |||
848 | /** | ||
849 | * Convert keyword URI to a human readable format | ||
850 | * (i.e. the search query that was used in the first place) | ||
851 | */ | ||
852 | char * | ||
853 | GNUNET_ECRS_ksk_uri_to_human_readable_string (const struct GNUNET_ECRS_URI | ||
854 | *uri) | ||
855 | { | ||
856 | size_t n; | ||
857 | char *ret; | 1225 | char *ret; |
858 | unsigned int i; | ||
859 | const char *keyword; | ||
860 | char **keywords; | ||
861 | unsigned int keywordCount; | ||
862 | 1226 | ||
863 | if ((uri == NULL) || (uri->type != ksk)) | 1227 | GNUNET_assert (strlen (tbl) == 64); |
1228 | len = size * 8 / 6; | ||
1229 | if (((size * 8) % 6) != 0) | ||
1230 | len++; | ||
1231 | ret = GNUNET_malloc (len + 1); | ||
1232 | ret[len] = '\0'; | ||
1233 | len = 0; | ||
1234 | bits = 0; | ||
1235 | hbits = 0; | ||
1236 | for (pos = 0; pos < size; pos++) | ||
864 | { | 1237 | { |
865 | GNUNET_GE_BREAK (NULL, 0); | 1238 | bits |= ((((const unsigned char *) data)[pos]) << hbits); |
866 | return NULL; | 1239 | hbits += 8; |
867 | } | 1240 | while (hbits >= 6) |
868 | keywords = uri->data.ksk.keywords; | ||
869 | keywordCount = uri->data.ksk.keywordCount; | ||
870 | n = keywordCount + 1; | ||
871 | for (i = 0; i < keywordCount; i++) | ||
872 | { | ||
873 | keyword = keywords[i]; | ||
874 | n += strlen (keyword) - 1; | ||
875 | if (NULL != strstr (&keyword[1], " ")) | ||
876 | n += 2; | ||
877 | if (keyword[0] == '+') | ||
878 | n++; | ||
879 | } | ||
880 | ret = GNUNET_malloc (n); | ||
881 | strcpy (ret, ""); | ||
882 | for (i = 0; i < keywordCount; i++) | ||
883 | { | ||
884 | keyword = keywords[i]; | ||
885 | if (NULL != strstr (&keyword[1], " ")) | ||
886 | { | 1241 | { |
887 | strcat (ret, "\""); | 1242 | ret[len++] = tbl[bits & 63]; |
888 | if (keyword[0] == '+') | 1243 | bits >>= 6; |
889 | strcat (ret, keyword); | 1244 | hbits -= 6; |
890 | else | ||
891 | strcat (ret, &keyword[1]); | ||
892 | strcat (ret, "\""); | ||
893 | } | ||
894 | else | ||
895 | { | ||
896 | if (keyword[0] == '+') | ||
897 | strcat (ret, keyword); | ||
898 | else | ||
899 | strcat (ret, &keyword[1]); | ||
900 | } | 1245 | } |
901 | strcat (ret, " "); | ||
902 | } | 1246 | } |
1247 | if (hbits > 0) | ||
1248 | ret[len++] = tbl[bits & 63]; | ||
903 | return ret; | 1249 | return ret; |
904 | } | 1250 | } |
905 | 1251 | ||
1252 | |||
906 | /** | 1253 | /** |
907 | * Given a keyword with %-encoding (and possibly quotes to protect | 1254 | * Convert a character back to the binary value |
908 | * spaces), return a copy of the keyword without %-encoding and | 1255 | * that it represents (given base64-encoding). |
909 | * without double-quotes (%22). Also, add a space at the beginning | 1256 | * |
910 | * if there is not a '+'. | 1257 | * @param a character to convert |
1258 | * @return offset in the "tbl" array | ||
911 | */ | 1259 | */ |
912 | static char * | 1260 | static unsigned int |
913 | percent_decode_keyword (const char *in) | 1261 | c2v (unsigned char a) |
914 | { | 1262 | { |
915 | char *out; | 1263 | if ((a >= '0') && (a <= '9')) |
916 | char *ret; | 1264 | return a - '0'; |
917 | unsigned int rpos; | 1265 | if ((a >= 'A') && (a <= 'Z')) |
918 | unsigned int wpos; | 1266 | return (a - 'A' + 10); |
919 | unsigned int hx; | 1267 | if ((a >= 'a') && (a <= 'z')) |
920 | 1268 | return (a - 'a' + 36); | |
921 | out = GNUNET_strdup (in); | 1269 | if (a == '_') |
922 | rpos = 0; | 1270 | return 62; |
923 | wpos = 0; | 1271 | if (a == '=') |
924 | while (out[rpos] != '\0') | 1272 | return 63; |
925 | { | 1273 | return -1; |
926 | if (out[rpos] == '%') | ||
927 | { | ||
928 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) | ||
929 | { | ||
930 | GNUNET_free (out); | ||
931 | return NULL; | ||
932 | } | ||
933 | rpos += 3; | ||
934 | if (hx == '"') | ||
935 | continue; /* skip double quote */ | ||
936 | out[wpos++] = (char) hx; | ||
937 | } | ||
938 | else | ||
939 | { | ||
940 | out[wpos++] = out[rpos++]; | ||
941 | } | ||
942 | } | ||
943 | out[wpos] = '\0'; | ||
944 | if (out[0] == '+') | ||
945 | { | ||
946 | ret = GNUNET_strdup (out); | ||
947 | } | ||
948 | else | ||
949 | { | ||
950 | /* need to prefix with space */ | ||
951 | ret = GNUNET_malloc (strlen (out) + 2); | ||
952 | strcpy (ret, " "); | ||
953 | strcat (ret, out); | ||
954 | } | ||
955 | GNUNET_free (out); | ||
956 | return ret; | ||
957 | } | 1274 | } |
958 | 1275 | ||
1276 | |||
959 | /** | 1277 | /** |
960 | * Parses an ECRS search URI. | 1278 | * Convert string back to binary data. |
961 | * | 1279 | * |
962 | * @param uri an uri string | 1280 | * @param input '\0'-terminated string |
963 | * @param keyword will be set to an array with the keywords | 1281 | * @param data where to write binary data |
964 | * @return GNUNET_SYSERR if this is not a search URI, otherwise | 1282 | * @param size how much data should be converted |
965 | * the number of keywords placed in the array | 1283 | * @return number of characters processed from input, |
1284 | * -1 on error | ||
966 | */ | 1285 | */ |
967 | static int | 1286 | static int |
968 | parseKeywordURI (struct GNUNET_GE_Context *ectx, const char *uri, | 1287 | enc2bin (const char *input, void *data, size_t size) |
969 | char ***keywords) | ||
970 | { | 1288 | { |
971 | unsigned int pos; | 1289 | size_t len; |
972 | int ret; | 1290 | size_t pos; |
973 | int iret; | 1291 | unsigned int bits; |
974 | int i; | 1292 | unsigned int hbits; |
975 | size_t slen; | 1293 | |
976 | char *dup; | 1294 | len = size * 8 / 6; |
977 | int saw_quote; | 1295 | if (((size * 8) % 6) != 0) |
978 | 1296 | len++; | |
979 | GNUNET_GE_ASSERT (ectx, uri != NULL); | 1297 | if (strlen (input) < len) |
980 | 1298 | return -1; /* error! */ | |
981 | slen = strlen (uri); | 1299 | bits = 0; |
982 | pos = strlen (GNUNET_ECRS_URI_PREFIX); | 1300 | hbits = 0; |
983 | 1301 | len = 0; | |
984 | if (0 != strncmp (uri, GNUNET_ECRS_URI_PREFIX, pos)) | 1302 | pos = 0; |
985 | return GNUNET_SYSERR; | 1303 | for (pos = 0; pos < size; pos++) |
986 | if (0 != | ||
987 | strncmp (&uri[pos], GNUNET_ECRS_SEARCH_INFIX, | ||
988 | strlen (GNUNET_ECRS_SEARCH_INFIX))) | ||
989 | return GNUNET_SYSERR; | ||
990 | pos += strlen (GNUNET_ECRS_SEARCH_INFIX); | ||
991 | if (slen == pos) | ||
992 | { | ||
993 | /* no keywords */ | ||
994 | (*keywords) = NULL; | ||
995 | return 0; | ||
996 | } | ||
997 | if ((uri[slen - 1] == '+') || (uri[pos] == '+')) | ||
998 | return GNUNET_SYSERR; /* no keywords / malformed */ | ||
999 | |||
1000 | ret = 1; | ||
1001 | saw_quote = 0; | ||
1002 | for (i = pos; i < slen; i++) | ||
1003 | { | ||
1004 | if ((uri[i] == '%') && (&uri[i] == strstr (&uri[i], "%22"))) | ||
1005 | { | ||
1006 | saw_quote = (saw_quote + 1) % 2; | ||
1007 | i += 3; | ||
1008 | continue; | ||
1009 | } | ||
1010 | if ((uri[i] == '+') && (saw_quote == 0)) | ||
1011 | { | ||
1012 | ret++; | ||
1013 | if (uri[i - 1] == '+') | ||
1014 | return GNUNET_SYSERR; /* "++" not allowed */ | ||
1015 | } | ||
1016 | } | ||
1017 | if (saw_quote == 1) | ||
1018 | return GNUNET_SYSERR; /* quotes not balanced */ | ||
1019 | iret = ret; | ||
1020 | dup = GNUNET_strdup (uri); | ||
1021 | (*keywords) = GNUNET_malloc (ret * sizeof (char *)); | ||
1022 | for (i = 0; i < ret; i++) | ||
1023 | (*keywords)[i] = NULL; | ||
1024 | for (i = slen - 1; i >= pos; i--) | ||
1025 | { | 1304 | { |
1026 | if ((uri[i] == '%') && (&uri[i] == strstr (&uri[i], "%22"))) | 1305 | while (hbits < 8) |
1027 | { | 1306 | { |
1028 | saw_quote = (saw_quote + 1) % 2; | 1307 | bits |= (c2v (input[len++]) << hbits); |
1029 | i += 3; | 1308 | hbits += 6; |
1030 | continue; | ||
1031 | } | ||
1032 | if ((dup[i] == '+') && (saw_quote == 0)) | ||
1033 | { | ||
1034 | (*keywords)[--ret] = percent_decode_keyword (&dup[i + 1]); | ||
1035 | if (NULL == (*keywords)[ret]) | ||
1036 | goto CLEANUP; | ||
1037 | dup[i] = '\0'; | ||
1038 | } | 1309 | } |
1310 | (((unsigned char *) data)[pos]) = (unsigned char) bits; | ||
1311 | bits >>= 8; | ||
1312 | hbits -= 8; | ||
1039 | } | 1313 | } |
1040 | (*keywords)[--ret] = percent_decode_keyword (&dup[pos]); | 1314 | return len; |
1041 | if (NULL == (*keywords)[ret]) | ||
1042 | goto CLEANUP; | ||
1043 | GNUNET_GE_ASSERT (ectx, ret == 0); | ||
1044 | GNUNET_free (dup); | ||
1045 | return iret; | ||
1046 | CLEANUP: | ||
1047 | for (i = 0; i < ret; i++) | ||
1048 | GNUNET_free_non_null ((*keywords)[i]); | ||
1049 | GNUNET_free (*keywords); | ||
1050 | *keywords = NULL; | ||
1051 | GNUNET_free (dup); | ||
1052 | return GNUNET_SYSERR; | ||
1053 | } | 1315 | } |
1054 | 1316 | ||
1055 | /** | ||
1056 | * Parses an AFS namespace / subspace identifier URI. | ||
1057 | * | ||
1058 | * @param uri an uri string | ||
1059 | * @param namespace set to the namespace ID | ||
1060 | * @param identifier set to the ID in the namespace | ||
1061 | * @return GNUNET_OK on success, GNUNET_SYSERR if this is not a namespace URI | ||
1062 | */ | ||
1063 | static int | ||
1064 | parseSubspaceURI (struct GNUNET_GE_Context *ectx, | ||
1065 | const char *uri, | ||
1066 | GNUNET_HashCode * namespace, char **identifier) | ||
1067 | { | ||
1068 | unsigned int pos; | ||
1069 | size_t slen; | ||
1070 | char *up; | ||
1071 | |||
1072 | GNUNET_GE_ASSERT (ectx, uri != NULL); | ||
1073 | |||
1074 | slen = strlen (uri); | ||
1075 | pos = strlen (GNUNET_ECRS_URI_PREFIX); | ||
1076 | |||
1077 | if (0 != strncmp (uri, GNUNET_ECRS_URI_PREFIX, pos)) | ||
1078 | return GNUNET_SYSERR; | ||
1079 | if (0 != strncmp (&uri[pos], | ||
1080 | GNUNET_ECRS_SUBSPACE_INFIX, | ||
1081 | strlen (GNUNET_ECRS_SUBSPACE_INFIX))) | ||
1082 | return GNUNET_SYSERR; | ||
1083 | pos += strlen (GNUNET_ECRS_SUBSPACE_INFIX); | ||
1084 | if ((slen < pos + sizeof (GNUNET_EncName) + 1) || | ||
1085 | (!((uri[pos + sizeof (GNUNET_EncName) - 1] == '/') || | ||
1086 | (uri[pos + sizeof (GNUNET_EncName) - 1] == '\\')))) | ||
1087 | return GNUNET_SYSERR; | ||
1088 | |||
1089 | up = GNUNET_strdup (uri); | ||
1090 | up[pos + sizeof (GNUNET_EncName) - 1] = '\0'; | ||
1091 | if ((GNUNET_OK != GNUNET_enc_to_hash (&up[pos], namespace))) | ||
1092 | { | ||
1093 | GNUNET_free (up); | ||
1094 | return GNUNET_SYSERR; | ||
1095 | } | ||
1096 | *identifier = GNUNET_strdup (&up[pos + sizeof (GNUNET_EncName)]); | ||
1097 | GNUNET_free (up); | ||
1098 | return GNUNET_OK; | ||
1099 | } | ||
1100 | 1317 | ||
1101 | /** | 1318 | /** |
1102 | * Parses an URI that identifies a file | 1319 | * Convert a LOC URI to a string. |
1103 | * | 1320 | * |
1104 | * @param uri an uri string | 1321 | * @param uri loc uri to convert |
1105 | * @param fi the file identifier | 1322 | * @return NULL on error |
1106 | * @return GNUNET_OK on success, GNUNET_SYSERR if this is not a file URI | ||
1107 | */ | 1323 | */ |
1108 | static int | 1324 | static char * |
1109 | parseFileURI (struct GNUNET_GE_Context *ectx, const char *uri, | 1325 | uri_loc_to_string (const struct GNUNET_FS_Uri *uri) |
1110 | GNUNET_EC_FileIdentifier * fi) | ||
1111 | { | 1326 | { |
1112 | unsigned int pos; | 1327 | char *ret; |
1113 | size_t slen; | 1328 | struct GNUNET_CRYPTO_HashAsciiEncoded keyhash; |
1114 | char *dup; | 1329 | struct GNUNET_CRYPTO_HashAsciiEncoded queryhash; |
1115 | 1330 | char *peerId; | |
1116 | GNUNET_GE_ASSERT (ectx, uri != NULL); | 1331 | char *peerSig; |
1117 | |||
1118 | slen = strlen (uri); | ||
1119 | pos = strlen (GNUNET_ECRS_URI_PREFIX); | ||
1120 | |||
1121 | if (0 != strncmp (uri, GNUNET_ECRS_URI_PREFIX, pos)) | ||
1122 | return GNUNET_SYSERR; | ||
1123 | if (0 != | ||
1124 | strncmp (&uri[pos], GNUNET_ECRS_FILE_INFIX, | ||
1125 | strlen (GNUNET_ECRS_FILE_INFIX))) | ||
1126 | return GNUNET_SYSERR; | ||
1127 | pos += strlen (GNUNET_ECRS_FILE_INFIX); | ||
1128 | if ((slen < pos + 2 * sizeof (GNUNET_EncName) + 1) || | ||
1129 | (uri[pos + sizeof (GNUNET_EncName) - 1] != '.') || | ||
1130 | (uri[pos + sizeof (GNUNET_EncName) * 2 - 1] != '.')) | ||
1131 | return GNUNET_SYSERR; | ||
1132 | 1332 | ||
1133 | dup = GNUNET_strdup (uri); | 1333 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); |
1134 | dup[pos + sizeof (GNUNET_EncName) - 1] = '\0'; | 1334 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
1135 | dup[pos + sizeof (GNUNET_EncName) * 2 - 1] = '\0'; | 1335 | peerId = bin2enc (&uri->data.loc.peer, |
1136 | if ((GNUNET_OK != GNUNET_enc_to_hash (&dup[pos], | 1336 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
1137 | &fi->chk.key)) || | 1337 | peerSig = bin2enc (&uri->data.loc.contentSignature, |
1138 | (GNUNET_OK != GNUNET_enc_to_hash (&dup[pos + sizeof (GNUNET_EncName)], | 1338 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
1139 | &fi->chk.query)) || | 1339 | GNUNET_asprintf (&ret, |
1140 | (1 != SSCANF (&dup[pos + sizeof (GNUNET_EncName) * 2], | 1340 | "%s%s%s.%s.%llu.%s.%s.%u", // FIXME: expirationTime 64-bit??? |
1141 | "%llu", &fi->file_length))) | 1341 | GNUNET_FS_URI_PREFIX, |
1142 | { | 1342 | GNUNET_FS_URI_LOC_INFIX, |
1143 | GNUNET_free (dup); | 1343 | (const char *) &keyhash, |
1144 | return GNUNET_SYSERR; | 1344 | (const char *) &queryhash, |
1145 | } | 1345 | GNUNET_ntohll (uri->data.loc.fi.file_length), |
1146 | GNUNET_free (dup); | 1346 | peerId, |
1147 | fi->file_length = GNUNET_htonll (fi->file_length); | 1347 | peerSig, |
1148 | return GNUNET_OK; | 1348 | uri->data.loc.expirationTime); |
1349 | GNUNET_free (peerSig); | ||
1350 | GNUNET_free (peerId); | ||
1351 | return ret; | ||
1149 | } | 1352 | } |
1150 | 1353 | ||
1151 | /** | ||
1152 | * Parses an URI that identifies a location (and file). | ||
1153 | * Also verifies validity of the location URI. | ||
1154 | * | ||
1155 | * @param uri an uri string | ||
1156 | * @param loc where to store the location | ||
1157 | * @return GNUNET_OK on success, GNUNET_SYSERR if this is not a file URI | ||
1158 | */ | ||
1159 | static int | ||
1160 | parseLocationURI (struct GNUNET_GE_Context *ectx, const char *uri, | ||
1161 | Location * loc) | ||
1162 | { | ||
1163 | unsigned int pos; | ||
1164 | unsigned int npos; | ||
1165 | int ret; | ||
1166 | size_t slen; | ||
1167 | char *dup; | ||
1168 | char *addr; | ||
1169 | |||
1170 | |||
1171 | GNUNET_GE_ASSERT (ectx, uri != NULL); | ||
1172 | addr = NULL; | ||
1173 | slen = strlen (uri); | ||
1174 | pos = strlen (GNUNET_ECRS_URI_PREFIX); | ||
1175 | |||
1176 | if (0 != strncmp (uri, GNUNET_ECRS_URI_PREFIX, pos)) | ||
1177 | return GNUNET_SYSERR; | ||
1178 | if (0 != strncmp (&uri[pos], | ||
1179 | GNUNET_ECRS_LOCATION_INFIX, | ||
1180 | strlen (GNUNET_ECRS_LOCATION_INFIX))) | ||
1181 | return GNUNET_SYSERR; | ||
1182 | pos += strlen (GNUNET_ECRS_LOCATION_INFIX); | ||
1183 | if ((slen < pos + 2 * sizeof (GNUNET_EncName) + 1) || | ||
1184 | (uri[pos + sizeof (GNUNET_EncName) - 1] != '.') || | ||
1185 | (uri[pos + sizeof (GNUNET_EncName) * 2 - 1] != '.')) | ||
1186 | return GNUNET_SYSERR; | ||
1187 | |||
1188 | dup = GNUNET_strdup (uri); | ||
1189 | dup[pos + sizeof (GNUNET_EncName) - 1] = '\0'; | ||
1190 | dup[pos + sizeof (GNUNET_EncName) * 2 - 1] = '\0'; | ||
1191 | npos = pos + sizeof (GNUNET_EncName) * 2; | ||
1192 | while ((uri[npos] != '\0') && (uri[npos] != '.')) | ||
1193 | npos++; | ||
1194 | if (dup[npos] == '\0') | ||
1195 | goto ERR; | ||
1196 | dup[npos++] = '\0'; | ||
1197 | if ((GNUNET_OK != GNUNET_enc_to_hash (&dup[pos], | ||
1198 | &loc->fi.chk.key)) || | ||
1199 | (GNUNET_OK != GNUNET_enc_to_hash (&dup[pos + sizeof (GNUNET_EncName)], | ||
1200 | &loc->fi.chk.query)) || | ||
1201 | (1 != SSCANF (&dup[pos + sizeof (GNUNET_EncName) * 2], | ||
1202 | "%llu", &loc->fi.file_length))) | ||
1203 | goto ERR; | ||
1204 | loc->fi.file_length = GNUNET_htonll (loc->fi.file_length); | ||
1205 | ret = enc2bin (&dup[npos], &loc->peer, sizeof (GNUNET_RSA_PublicKey)); | ||
1206 | if (ret == -1) | ||
1207 | goto ERR; | ||
1208 | npos += ret; | ||
1209 | if (dup[npos++] != '.') | ||
1210 | goto ERR; | ||
1211 | ret = | ||
1212 | enc2bin (&dup[npos], &loc->contentSignature, | ||
1213 | sizeof (GNUNET_RSA_Signature)); | ||
1214 | if (ret == -1) | ||
1215 | goto ERR; | ||
1216 | npos += ret; | ||
1217 | if (dup[npos++] != '.') | ||
1218 | goto ERR; | ||
1219 | if (1 != SSCANF (&dup[npos], "%u", &loc->expirationTime)) | ||
1220 | goto ERR; | ||
1221 | /* Finally: verify sigs! */ | ||
1222 | if (GNUNET_OK != GNUNET_RSA_verify (&loc->fi, | ||
1223 | sizeof (GNUNET_EC_FileIdentifier) + | ||
1224 | sizeof (GNUNET_PeerIdentity) + | ||
1225 | sizeof (GNUNET_Int32Time), | ||
1226 | &loc->contentSignature, &loc->peer)) | ||
1227 | goto ERR; | ||
1228 | GNUNET_free (dup); | ||
1229 | return GNUNET_OK; | ||
1230 | ERR: | ||
1231 | GNUNET_free (dup); | ||
1232 | GNUNET_free_non_null (addr); | ||
1233 | return GNUNET_SYSERR; | ||
1234 | } | ||
1235 | 1354 | ||
1236 | /** | 1355 | /** |
1237 | * Convert a UTF-8 String to a URI. | 1356 | * Convert a URI to a UTF-8 String. |
1357 | * | ||
1358 | * @param uri uri to convert to a string | ||
1359 | * @return the UTF-8 string | ||
1238 | */ | 1360 | */ |
1239 | URI * | 1361 | char * |
1240 | GNUNET_ECRS_string_to_uri (struct GNUNET_GE_Context * ectx, const char *uri) | 1362 | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) |
1241 | { | 1363 | { |
1242 | URI *ret; | 1364 | if (uri == NULL) |
1243 | int len; | ||
1244 | |||
1245 | ret = GNUNET_malloc (sizeof (URI)); | ||
1246 | if (GNUNET_OK == parseFileURI (ectx, uri, &ret->data.fi)) | ||
1247 | { | ||
1248 | ret->type = chk; | ||
1249 | return ret; | ||
1250 | } | ||
1251 | if (GNUNET_OK == parseSubspaceURI (ectx, | ||
1252 | uri, | ||
1253 | &ret->data.sks.namespace, | ||
1254 | &ret->data.sks.identifier)) | ||
1255 | { | ||
1256 | ret->type = sks; | ||
1257 | return ret; | ||
1258 | } | ||
1259 | if (GNUNET_OK == parseLocationURI (ectx, uri, &ret->data.loc)) | ||
1260 | { | 1365 | { |
1261 | ret->type = loc; | 1366 | GNUNET_break (0); |
1262 | return ret; | 1367 | return NULL; |
1263 | } | 1368 | } |
1264 | len = parseKeywordURI (ectx, uri, &ret->data.ksk.keywords); | 1369 | switch (uri->type) |
1265 | if (len < 0) | ||
1266 | { | 1370 | { |
1267 | GNUNET_free (ret); | 1371 | case ksk: |
1372 | return uri_ksk_to_string (uri); | ||
1373 | case sks: | ||
1374 | return uri_sks_to_string (uri); | ||
1375 | case chk: | ||
1376 | return uri_chk_to_string (uri); | ||
1377 | case loc: | ||
1378 | return uri_loc_to_string (uri); | ||
1379 | default: | ||
1380 | GNUNET_break (0); | ||
1268 | return NULL; | 1381 | return NULL; |
1269 | } | 1382 | } |
1270 | ret->type = ksk; | ||
1271 | ret->data.ksk.keywordCount = len; | ||
1272 | return ret; | ||
1273 | } | 1383 | } |
1274 | 1384 | ||
1275 | 1385 | ||
1386 | #if 0 | ||
1276 | 1387 | ||
1277 | /** | 1388 | /** |
1278 | * Construct a location URI. | 1389 | * Construct a location URI. |
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index e45a46ef4..a5bdae340 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -58,11 +58,11 @@ extern "C" | |||
58 | 58 | ||
59 | /* ******************** URI API *********************** */ | 59 | /* ******************** URI API *********************** */ |
60 | 60 | ||
61 | #define GNUNET_FS_URI_PREFIX "gnunet://fs/" | 61 | #define GNUNET_FS_URI_PREFIX "gnunet://fs/" |
62 | #define GNUNET_FS_SEARCH_INFIX "ksk/" | 62 | #define GNUNET_FS_URI_KSK_INFIX "ksk/" |
63 | #define GNUNET_FS_SUBSPACE_INFIX "sks/" | 63 | #define GNUNET_FS_URI_SKS_INFIX "sks/" |
64 | #define GNUNET_FS_FILE_INFIX "chk/" | 64 | #define GNUNET_FS_URI_CHK_INFIX "chk/" |
65 | #define GNUNET_FS_LOCATION_INFIX "loc/" | 65 | #define GNUNET_FS_URI_LOC_INFIX "loc/" |
66 | 66 | ||
67 | 67 | ||
68 | /** | 68 | /** |
@@ -378,7 +378,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri); | |||
378 | * @deprecated | 378 | * @deprecated |
379 | */ | 379 | */ |
380 | struct GNUNET_FS_Uri * | 380 | struct GNUNET_FS_Uri * |
381 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_MetaData *md); | 381 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md); |
382 | 382 | ||
383 | 383 | ||
384 | /* ******************** command-line option parsing API *********************** */ | 384 | /* ******************** command-line option parsing API *********************** */ |
@@ -396,7 +396,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_MetaData *md); | |||
396 | * @return GNUNET_OK on success | 396 | * @return GNUNET_OK on success |
397 | */ | 397 | */ |
398 | int | 398 | int |
399 | GNUNET_FS_getopt_configure_set_keywords (GNUNET_GETOPT_CommandLineProcessorContext* ctx, | 399 | GNUNET_FS_getopt_configure_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, |
400 | void *scls, | 400 | void *scls, |
401 | const char *option, | 401 | const char *option, |
402 | const char *value); | 402 | const char *value); |
@@ -415,7 +415,7 @@ GNUNET_FS_getopt_configure_set_keywords (GNUNET_GETOPT_CommandLineProcessorConte | |||
415 | * @return GNUNET_OK on success | 415 | * @return GNUNET_OK on success |
416 | */ | 416 | */ |
417 | int | 417 | int |
418 | GNUNET_FS_getopt_configure_set_metadata (GNUNET_GETOPT_CommandLineProcessorContext* ctx, | 418 | GNUNET_FS_getopt_configure_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, |
419 | void *scls, | 419 | void *scls, |
420 | const char *option, | 420 | const char *option, |
421 | const char *value); | 421 | const char *value); |
@@ -630,26 +630,6 @@ enum GNUNET_FS_Status | |||
630 | 630 | ||
631 | 631 | ||
632 | /** | 632 | /** |
633 | * Notification of FS to a client about the progress of an | ||
634 | * operation. Callbacks of this type will be used for uploads, | ||
635 | * downloads and searches. Some of the arguments depend a bit | ||
636 | * in their meaning on the context in which the callback is used. | ||
637 | * | ||
638 | * @param cls closure | ||
639 | * @param info details about the event, specifying the event type | ||
640 | * and various bits about the event | ||
641 | * @return client-context (for the next progress call | ||
642 | * for this operation; should be set to NULL for | ||
643 | * SUSPEND and STOPPED events). The value returned | ||
644 | * will be passed to future callbacks in the respective | ||
645 | * field in the GNUNET_FS_ProgressInfo struct. | ||
646 | */ | ||
647 | typedef int (*GNUNET_FS_ProgressCallback) | ||
648 | (void *cls, | ||
649 | const struct GNUNET_FS_ProgressInfo *info); | ||
650 | |||
651 | |||
652 | /** | ||
653 | * Handle to one of our namespaces. | 633 | * Handle to one of our namespaces. |
654 | */ | 634 | */ |
655 | struct GNUNET_FS_Namespace; | 635 | struct GNUNET_FS_Namespace; |
@@ -1230,7 +1210,7 @@ struct GNUNET_FS_ProgressInfo | |||
1230 | /** | 1210 | /** |
1231 | * Hash-identifier for the namespace. | 1211 | * Hash-identifier for the namespace. |
1232 | */ | 1212 | */ |
1233 | struct GNUNET_HashCode id; | 1213 | GNUNET_HashCode id; |
1234 | 1214 | ||
1235 | } namespace; | 1215 | } namespace; |
1236 | 1216 | ||
@@ -1352,6 +1332,26 @@ struct GNUNET_FS_ProgressInfo | |||
1352 | 1332 | ||
1353 | 1333 | ||
1354 | /** | 1334 | /** |
1335 | * Notification of FS to a client about the progress of an | ||
1336 | * operation. Callbacks of this type will be used for uploads, | ||
1337 | * downloads and searches. Some of the arguments depend a bit | ||
1338 | * in their meaning on the context in which the callback is used. | ||
1339 | * | ||
1340 | * @param cls closure | ||
1341 | * @param info details about the event, specifying the event type | ||
1342 | * and various bits about the event | ||
1343 | * @return client-context (for the next progress call | ||
1344 | * for this operation; should be set to NULL for | ||
1345 | * SUSPEND and STOPPED events). The value returned | ||
1346 | * will be passed to future callbacks in the respective | ||
1347 | * field in the GNUNET_FS_ProgressInfo struct. | ||
1348 | */ | ||
1349 | typedef int (*GNUNET_FS_ProgressCallback) | ||
1350 | (void *cls, | ||
1351 | const struct GNUNET_FS_ProgressInfo *info); | ||
1352 | |||
1353 | |||
1354 | /** | ||
1355 | * Handle to the file-sharing service. | 1355 | * Handle to the file-sharing service. |
1356 | */ | 1356 | */ |
1357 | struct GNUNET_FS_Handle; | 1357 | struct GNUNET_FS_Handle; |
@@ -1527,9 +1527,9 @@ GNUNET_FS_file_information_create_from_reader (void *client_info, | |||
1527 | * @param fi information about the file (should not be | 1527 | * @param fi information about the file (should not be |
1528 | * used henceforth by the caller) | 1528 | * used henceforth by the caller) |
1529 | */ | 1529 | */ |
1530 | typedef void (*GNUNET_FS_FileInformationProcessor)(void *cls, | 1530 | typedef void (*GNUNET_FS_FileProcessor)(void *cls, |
1531 | const char *filename, | 1531 | const char *filename, |
1532 | struct GNUNET_FS_FileInformation *fi); | 1532 | struct GNUNET_FS_FileInformation *fi); |
1533 | 1533 | ||
1534 | 1534 | ||
1535 | /** | 1535 | /** |
@@ -1661,7 +1661,7 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, | |||
1661 | */ | 1661 | */ |
1662 | void | 1662 | void |
1663 | GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, | 1663 | GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, |
1664 | struct GNUNET_FS_FileInformationProcessor proc, | 1664 | GNUNET_FS_FileInformationProcessor proc, |
1665 | void *proc_cls); | 1665 | void *proc_cls); |
1666 | 1666 | ||
1667 | 1667 | ||
@@ -1699,7 +1699,7 @@ struct GNUNET_FS_ShareContext * | |||
1699 | GNUNET_FS_share_start (struct GNUNET_FS_Handle *h, | 1699 | GNUNET_FS_share_start (struct GNUNET_FS_Handle *h, |
1700 | void *ctx, | 1700 | void *ctx, |
1701 | const struct GNUNET_FS_FileInformation *fi, | 1701 | const struct GNUNET_FS_FileInformation *fi, |
1702 | struct GNUNET_FS_Namespace *namespace | 1702 | struct GNUNET_FS_Namespace *namespace, |
1703 | const char *nid, | 1703 | const char *nid, |
1704 | const char *nuid); | 1704 | const char *nuid); |
1705 | 1705 | ||
@@ -1722,8 +1722,8 @@ GNUNET_FS_share_stop (struct GNUNET_FS_ShareContext *sc); | |||
1722 | * @param filename the name of the file | 1722 | * @param filename the name of the file |
1723 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | 1723 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort |
1724 | */ | 1724 | */ |
1725 | typedef int (*GNUNET_FS_FileProcessor) (void *cls, | 1725 | typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, |
1726 | const char *filename); | 1726 | const char *filename); |
1727 | 1727 | ||
1728 | 1728 | ||
1729 | /** | 1729 | /** |
@@ -1735,7 +1735,7 @@ typedef int (*GNUNET_FS_FileProcessor) (void *cls, | |||
1735 | */ | 1735 | */ |
1736 | void | 1736 | void |
1737 | GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, | 1737 | GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, |
1738 | GNUNET_FS_FileProcessor iterator, | 1738 | GNUNET_FS_IndexedFileProcessor iterator, |
1739 | void *iterator_cls); | 1739 | void *iterator_cls); |
1740 | 1740 | ||
1741 | 1741 | ||
@@ -1842,7 +1842,7 @@ typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, | |||
1842 | */ | 1842 | */ |
1843 | int | 1843 | int |
1844 | GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h, | 1844 | GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h, |
1845 | GNUNET_FS_NamespaceProcessor cb, | 1845 | GNUNET_FS_NamespaceInfoProcessor cb, |
1846 | void *cb_cls); | 1846 | void *cb_cls); |
1847 | 1847 | ||
1848 | 1848 | ||
@@ -2074,7 +2074,7 @@ GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md); | |||
2074 | typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls, | 2074 | typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls, |
2075 | const char *filename, | 2075 | const char *filename, |
2076 | const struct GNUNET_FS_Uri *uri, | 2076 | const struct GNUNET_FS_Uri *uri, |
2077 | const struct GNUNET_FS_MetaData *meta, | 2077 | const struct GNUNET_CONTAINER_MetaData *meta, |
2078 | size_t length, | 2078 | size_t length, |
2079 | const void *data); | 2079 | const void *data); |
2080 | 2080 | ||