diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-19 22:56:22 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-19 22:56:22 +0900 |
commit | 3683f556df1324b1ce575dd5932d174d75512f7a (patch) | |
tree | 8920396a04fed596c9532f941839499106a3df7d /src/namestore | |
parent | cfdf9ea8c1246979f48174628872e79cfb1657a2 (diff) | |
download | gnunet-3683f556df1324b1ce575dd5932d174d75512f7a.tar.gz gnunet-3683f556df1324b1ce575dd5932d174d75512f7a.zip |
GNS: Make string formats more comaptible with DNS zonefiles
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore-zonefile.c | 163 |
1 files changed, 156 insertions, 7 deletions
diff --git a/src/namestore/gnunet-namestore-zonefile.c b/src/namestore/gnunet-namestore-zonefile.c index a55e3a0aa..d8ac7c234 100644 --- a/src/namestore/gnunet-namestore-zonefile.c +++ b/src/namestore/gnunet-namestore-zonefile.c | |||
@@ -33,6 +33,32 @@ | |||
33 | static int ret = 0; | 33 | static int ret = 0; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Name of the ego | ||
37 | */ | ||
38 | static char *ego_name = NULL; | ||
39 | |||
40 | /** | ||
41 | * Handle to identity lookup. | ||
42 | */ | ||
43 | static struct GNUNET_IDENTITY_EgoLookup *el; | ||
44 | |||
45 | /** | ||
46 | * Private key for the our zone. | ||
47 | */ | ||
48 | static struct GNUNET_IDENTITY_PrivateKey zone_pkey; | ||
49 | |||
50 | /** | ||
51 | * Queue entry for the 'add' operation. | ||
52 | */ | ||
53 | static struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | ||
54 | |||
55 | /** | ||
56 | * Handle to the namestore. | ||
57 | */ | ||
58 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
59 | |||
60 | |||
61 | /** | ||
36 | * Task run on shutdown. Cleans up everything. | 62 | * Task run on shutdown. Cleans up everything. |
37 | * | 63 | * |
38 | * @param cls unused | 64 | * @param cls unused |
@@ -41,8 +67,36 @@ static void | |||
41 | do_shutdown (void *cls) | 67 | do_shutdown (void *cls) |
42 | { | 68 | { |
43 | (void) cls; | 69 | (void) cls; |
70 | if (NULL != ego_name) | ||
71 | GNUNET_free (ego_name); | ||
72 | if (NULL != el) | ||
73 | { | ||
74 | GNUNET_IDENTITY_ego_lookup_cancel (el); | ||
75 | el = NULL; | ||
76 | } | ||
77 | if (NULL != ns_qe) | ||
78 | GNUNET_NAMESTORE_cancel (ns_qe); | ||
79 | if (NULL != ns) | ||
80 | GNUNET_NAMESTORE_disconnect (ns); | ||
81 | |||
82 | } | ||
83 | |||
84 | static void | ||
85 | tx_end (void *cls, int32_t success, const char *emsg) | ||
86 | { | ||
87 | ns_qe = NULL; | ||
88 | if (GNUNET_SYSERR == success) | ||
89 | { | ||
90 | fprintf (stderr, | ||
91 | _ ("Ego `%s' not known to identity service\n"), | ||
92 | ego_name); | ||
93 | GNUNET_SCHEDULER_shutdown (); | ||
94 | ret = -1; | ||
95 | } | ||
96 | GNUNET_SCHEDULER_shutdown (); | ||
44 | } | 97 | } |
45 | 98 | ||
99 | |||
46 | /** | 100 | /** |
47 | * Main function that will be run. | 101 | * Main function that will be run. |
48 | * | 102 | * |
@@ -64,22 +118,25 @@ do_shutdown (void *cls) | |||
64 | * @param cfg configuration | 118 | * @param cfg configuration |
65 | */ | 119 | */ |
66 | static void | 120 | static void |
67 | run (void *cls, | 121 | parse (void *cls) |
68 | char *const *args, | ||
69 | const char *cfgfile, | ||
70 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
71 | { | 122 | { |
123 | struct GNUNET_GNSRECORD_Data rd[50]; // Let's hope we do not need more | ||
124 | struct GNUNET_GNSRECORD_Data *cur_rd = rd; | ||
72 | char buf[5000]; /* buffer to hold entire line (adjust MAXC as needed) */ | 125 | char buf[5000]; /* buffer to hold entire line (adjust MAXC as needed) */ |
73 | char *next; | 126 | char *next; |
74 | char *token; | 127 | char *token; |
75 | char origin[255]; | 128 | char origin[255]; |
76 | char lastname[255]; | 129 | char lastname[255]; |
130 | void *data; | ||
131 | size_t data_size; | ||
77 | struct GNUNET_TIME_Relative ttl; | 132 | struct GNUNET_TIME_Relative ttl; |
78 | int origin_line = 0; | 133 | int origin_line = 0; |
79 | int ttl_line = 0; | 134 | int ttl_line = 0; |
135 | int type; | ||
136 | unsigned int rd_count = 0; | ||
80 | uint32_t ttl_tmp; | 137 | uint32_t ttl_tmp; |
81 | 138 | ||
82 | /* use filename provided as 1st argument (stdin by default) */ | 139 | /* use filename provided as 1st argument (stdin by default) */ |
83 | int i = 0; | 140 | int i = 0; |
84 | while (fgets (buf, 5000, stdin)) /* read each line of input */ | 141 | while (fgets (buf, 5000, stdin)) /* read each line of input */ |
85 | { | 142 | { |
@@ -167,6 +224,9 @@ run (void *cls, | |||
167 | printf ("Origin is: %s\n", origin); | 224 | printf ("Origin is: %s\n", origin); |
168 | continue; | 225 | continue; |
169 | } | 226 | } |
227 | // This is a record, let's go | ||
228 | cur_rd->flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
229 | cur_rd->expiration_time = ttl.rel_value_us; | ||
170 | next = strchr (token, ' '); | 230 | next = strchr (token, ' '); |
171 | if (NULL == next) | 231 | if (NULL == next) |
172 | { | 232 | { |
@@ -188,16 +248,99 @@ run (void *cls, | |||
188 | next[0] = '\0'; | 248 | next[0] = '\0'; |
189 | next++; | 249 | next++; |
190 | printf ("type is: %s\n", token); | 250 | printf ("type is: %s\n", token); |
251 | type = GNUNET_GNSRECORD_typename_to_number (token); | ||
252 | cur_rd->record_type = type; | ||
191 | while (*next == ' ') | 253 | while (*next == ' ') |
192 | next++; | 254 | next++; |
193 | token = next; | 255 | token = next; |
194 | next = strchr (token, ';'); | 256 | next = strchr (token, ';'); |
195 | if (NULL != next) | 257 | if (NULL != next) |
196 | next[0] = '\0'; | 258 | next[0] = '\0'; |
259 | while (token[strlen (token) - 1] == ' ') | ||
260 | token[strlen (token) - 1] = '\0'; | ||
197 | printf ("data is: %s\n\n", token); | 261 | printf ("data is: %s\n\n", token); |
262 | if (GNUNET_OK != | ||
263 | GNUNET_GNSRECORD_string_to_value (type, token, | ||
264 | &data, | ||
265 | &data_size)) | ||
266 | { | ||
267 | fprintf (stderr, | ||
268 | _ ("Data `%s' invalid\n"), | ||
269 | token); | ||
270 | ret = 1; | ||
271 | GNUNET_SCHEDULER_shutdown (); | ||
272 | return; | ||
273 | } | ||
198 | } | 274 | } |
275 | ns_qe = GNUNET_NAMESTORE_transaction_commit (ns, | ||
276 | &tx_end, | ||
277 | NULL); | ||
278 | } | ||
279 | |||
280 | static void | ||
281 | tx_start (void *cls, int32_t success, const char *emsg) | ||
282 | { | ||
283 | ns_qe = NULL; | ||
284 | if (GNUNET_SYSERR == success) | ||
285 | { | ||
286 | fprintf (stderr, | ||
287 | _ ("Ego `%s' not known to identity service\n"), | ||
288 | ego_name); | ||
289 | GNUNET_SCHEDULER_shutdown (); | ||
290 | ret = -1; | ||
291 | return; | ||
292 | } | ||
293 | GNUNET_SCHEDULER_add_now (&parse, NULL); | ||
294 | } | ||
295 | |||
296 | static void | ||
297 | identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | ||
298 | { | ||
299 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
300 | |||
301 | el = NULL; | ||
302 | |||
303 | if (NULL == ego) | ||
304 | { | ||
305 | if (NULL != ego_name) | ||
306 | { | ||
307 | fprintf (stderr, | ||
308 | _ ("Ego `%s' not known to identity service\n"), | ||
309 | ego_name); | ||
310 | } | ||
311 | GNUNET_SCHEDULER_shutdown (); | ||
312 | ret = -1; | ||
313 | return; | ||
314 | } | ||
315 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
316 | ns_qe = GNUNET_NAMESTORE_transaction_begin (ns, | ||
317 | &tx_start, | ||
318 | NULL); | ||
319 | } | ||
320 | |||
321 | |||
322 | static void | ||
323 | run (void *cls, | ||
324 | char *const *args, | ||
325 | const char *cfgfile, | ||
326 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
327 | { | ||
328 | ns = GNUNET_NAMESTORE_connect (cfg); | ||
329 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); | ||
330 | if (NULL == ns) | ||
331 | { | ||
332 | fprintf (stderr, | ||
333 | _ ("Failed to connect to namestore\n")); | ||
334 | return; | ||
335 | } | ||
336 | if (NULL == ego_name) | ||
337 | { | ||
338 | fprintf (stderr, _ ("You must provide a zone ego to use\n")); | ||
339 | GNUNET_SCHEDULER_shutdown (); | ||
340 | return; | ||
341 | } | ||
342 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); | ||
199 | 343 | ||
200 | GNUNET_SCHEDULER_shutdown (); | ||
201 | } | 344 | } |
202 | 345 | ||
203 | 346 | ||
@@ -212,6 +355,12 @@ int | |||
212 | main (int argc, char *const *argv) | 355 | main (int argc, char *const *argv) |
213 | { | 356 | { |
214 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 357 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
358 | GNUNET_GETOPT_option_string ('z', | ||
359 | "zone", | ||
360 | "EGO", | ||
361 | gettext_noop ( | ||
362 | "name of the ego controlling the zone"), | ||
363 | &ego_name), | ||
215 | GNUNET_GETOPT_OPTION_END | 364 | GNUNET_GETOPT_OPTION_END |
216 | }; | 365 | }; |
217 | int lret; | 366 | int lret; |
@@ -223,7 +372,7 @@ main (int argc, char *const *argv) | |||
223 | if (GNUNET_OK != | 372 | if (GNUNET_OK != |
224 | (lret = GNUNET_PROGRAM_run (argc, | 373 | (lret = GNUNET_PROGRAM_run (argc, |
225 | argv, | 374 | argv, |
226 | "gnunet-namestore-dbtool", | 375 | "gnunet-namestore-zonefile", |
227 | _ ( | 376 | _ ( |
228 | "GNUnet namestore database manipulation tool"), | 377 | "GNUnet namestore database manipulation tool"), |
229 | options, | 378 | options, |