GNUnet 0.21.1
gnunet-namestore-zonefile.c File Reference
#include "platform.h"
#include <gnunet_util_lib.h>
#include <gnunet_namestore_plugin.h>
Include dependency graph for gnunet-namestore-zonefile.c:

Go to the source code of this file.

Macros

#define MAX_RECORDS_PER_NAME   50
 
#define MAX_ZONEFILE_LINE_LEN   4096
 Maximum length of a zonefile line. More...
 
#define MAX_ZONEFILE_RECORD_DATA_LEN   2048
 FIXME: Soft limit this? More...
 

Enumerations

enum  ZonefileImportState { ZS_READY , ZS_ORIGIN_SET , ZS_ORIGIN_CHANGED , ZS_NAME_CHANGED }
 

Functions

static void do_shutdown (void *cls)
 Task run on shutdown. More...
 
static void parse (void *cls)
 Main function that will be run. More...
 
static char * trim (char *line)
 
static char * next_token (char *token)
 
static int parse_ttl (char *token, struct GNUNET_TIME_Relative *ttl)
 
static int parse_origin (char *token, char *origin)
 
static void origin_create_cb (void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
 
static void origin_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 
static void add_continuation (void *cls, enum GNUNET_ErrorCode ec)
 
static void identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *_cfg)
 
int main (int argc, char *const *argv)
 The main function for gnunet-namestore-dbtool. More...
 

Variables

static struct GNUNET_GNSRECORD_Data rd [50]
 The record data under a single label. More...
 
static struct GNUNET_TIME_Relative ttl
 Current record $TTL to use. More...
 
static char origin [GNUNET_DNSPARSER_MAX_NAME_LENGTH]
 Current origin. More...
 
static unsigned int rd_count = 0
 Number of records for currently parsed set. More...
 
static int ret = 0
 Return code. More...
 
static char * ego_name = NULL
 Name of the ego. More...
 
static char * res
 Currently read line or NULL on EOF. More...
 
static unsigned int published_sets = 0
 Statistics, how many published record sets. More...
 
static unsigned int published_records = 0
 Statistics, how many records published in aggregate. More...
 
static struct GNUNET_IDENTITY_EgoLookupel
 Handle to identity lookup. More...
 
static struct GNUNET_CRYPTO_PrivateKey zone_pkey
 Private key for the our zone. More...
 
static struct GNUNET_NAMESTORE_QueueEntryns_qe
 Queue entry for the 'add' operation. More...
 
static struct GNUNET_NAMESTORE_Handlens
 Handle to the namestore. More...
 
static struct GNUNET_IDENTITY_Operationid_op
 Origin create operations. More...
 
static struct GNUNET_IDENTITY_Handleid
 Handle to IDENTITY. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Current configurataion. More...
 
static struct GNUNET_SCHEDULER_Taskparse_task
 Scheduled parse task. More...
 
static int state
 The current state of the parser. More...
 

Macro Definition Documentation

◆ MAX_RECORDS_PER_NAME

#define MAX_RECORDS_PER_NAME   50

Definition at line 30 of file gnunet-namestore-zonefile.c.

◆ MAX_ZONEFILE_LINE_LEN

#define MAX_ZONEFILE_LINE_LEN   4096

Maximum length of a zonefile line.

Definition at line 35 of file gnunet-namestore-zonefile.c.

◆ MAX_ZONEFILE_RECORD_DATA_LEN

#define MAX_ZONEFILE_RECORD_DATA_LEN   2048

FIXME: Soft limit this?

Definition at line 40 of file gnunet-namestore-zonefile.c.

Enumeration Type Documentation

◆ ZonefileImportState

Enumerator
ZS_READY 
ZS_ORIGIN_SET 
ZS_ORIGIN_CHANGED 
ZS_NAME_CHANGED 

Definition at line 134 of file gnunet-namestore-zonefile.c.

135{
136
137 /* Uninitialized */
138 ZS_READY,
139
140 /* The initial state */
142
143 /* The $ORIGIN has changed */
145
146 /* The record name/label has changed */
148
149};

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

Definition at line 159 of file gnunet-namestore-zonefile.c.

160{
161 (void) cls;
162 if (NULL != ego_name)
164 if (NULL != el)
165 {
167 el = NULL;
168 }
169 if (NULL != ns_qe)
171 if (NULL != id_op)
173 if (NULL != ns)
175 if (NULL != id)
177 for (int i = 0; i < rd_count; i++)
178 {
179 void *rd_ptr = (void*) rd[i].data;
180 GNUNET_free (rd_ptr);
181 }
182 if (NULL != parse_task)
184}
static char * data
The data to insert into the dht.
static struct GNUNET_NAMESTORE_QueueEntry * ns_qe
Queue entry for the 'add' operation.
static struct GNUNET_IDENTITY_Operation * id_op
Origin create operations.
static struct GNUNET_SCHEDULER_Task * parse_task
Scheduled parse task.
static struct GNUNET_IDENTITY_EgoLookup * el
Handle to identity lookup.
static char * ego_name
Name of the ego.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:715
void GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
Abort ego lookup attempt.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:732
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981

References data, ego_name, el, GNUNET_free, GNUNET_IDENTITY_cancel(), GNUNET_IDENTITY_disconnect(), GNUNET_IDENTITY_ego_lookup_cancel(), GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_disconnect(), GNUNET_SCHEDULER_cancel(), id_op, ns, ns_qe, parse_task, rd, and rd_count.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse()

static void parse ( void *  cls)
static

Main function that will be run.

TODO:

  • We must assume that names are not repeated later in the zonefile because our _store APIs are replacing. No sure if that is common in zonefiles.
  • We must only actually store a record set when the name to store changes or the end of the file is reached. that way we can group them and add (see above).
  • We need to hope our string formats are compatible, but seems ok.
Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 353 of file gnunet-namestore-zonefile.c.

354{
355 char buf[MAX_ZONEFILE_LINE_LEN];
357 char *next;
358 char *token;
359 char *payload_pos;
360 static char lastname[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
362 void *data;
363 size_t data_size;
364 int ttl_line = 0;
365 int type;
366 int bracket_unclosed = 0;
367 int quoted = 0;
368
369 parse_task = NULL;
370 /* use filename provided as 1st argument (stdin by default) */
371 int ln = 0;
372 while ((res = fgets (buf, sizeof(buf), stdin))) /* read each line of input */
373 {
374 ln++;
375 ttl_line = 0;
376 token = trim (buf);
378 "Trimmed line (bracket %s): `%s'\n",
379 (bracket_unclosed > 0) ? "unclosed" : "closed",
380 token);
381 if ((0 == strlen (token)) ||
382 ((1 == strlen (token)) && (' ' == *token)))
383 continue; // I guess we can safely ignore blank lines
384 if (bracket_unclosed == 0)
385 {
386 /* Payload is already parsed */
387 payload_pos = payload;
388 /* Find space */
389 next = strchr (token, ' ');
390 if (NULL == next)
391 {
392 fprintf (stderr, "Error at line %u: %s\n", ln, token);
393 ret = 1;
395 return;
396 }
397 next[0] = '\0';
398 next++;
399 if (0 == (strcmp (token, "$ORIGIN")))
400 {
402 token = next_token (next);
403 }
404 else if (0 == (strcmp (token, "$TTL")))
405 {
406 ttl_line = 1;
407 token = next_token (next);
408 }
409 else
410 {
411 if (0 == strcmp (token, "IN")) // Inherit name from before
412 {
414 "Old name: %s\n", lastname);
415 strcpy (newname, lastname);
416 token[strlen (token)] = ' ';
417 }
418 else if (token[strlen (token) - 1] != '.') // no fqdn
419 {
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: %s\n", token);
421 if (GNUNET_DNSPARSER_MAX_LABEL_LENGTH < strlen (token))
422 {
423 fprintf (stderr,
424 _ ("Name `%s' is too long\n"),
425 token);
426 ret = 1;
428 return;
429 }
430 strcpy (newname, token);
431 token = next_token (next);
432 }
433 else if (0 == strcmp (token, origin))
434 {
435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: @\n");
436 strcpy (newname, "@");
437 token = next_token (next);
438 }
439 else
440 {
441 if (strlen (token) < strlen (origin))
442 {
443 fprintf (stderr, "Wrong origin: %s (expected %s)\n", token, origin);
444 break; // FIXME error?
445 }
446 if (0 != strcmp (token + (strlen (token) - strlen (origin)), origin))
447 {
448 fprintf (stderr, "Wrong origin: %s (expected %s)\n", token, origin);
449 break;
450 }
451 token[strlen (token) - strlen (origin) - 1] = '\0';
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: %s\n", token);
453 if (GNUNET_DNSPARSER_MAX_LABEL_LENGTH < strlen (token))
454 {
455 fprintf (stderr,
456 _ ("Name `%s' is too long\n"),
457 token);
458 ret = 1;
460 return;
461 }
462 strcpy (newname, token);
463 token = next_token (next);
464 }
465 if (0 != strcmp (newname, lastname) &&
466 (0 < rd_count))
467 {
469 "Name changed %s->%s, storing record set of %u elements\n",
470 lastname, newname,
471 rd_count);
473 }
474 else {
475 strcpy (lastname, newname);
476 }
477 }
478
479 if (ttl_line)
480 {
481 if (GNUNET_SYSERR == parse_ttl (token, &ttl))
482 {
483 fprintf (stderr, _ ("Failed to parse $TTL\n"));
484 ret = 1;
486 return;
487 }
488 continue;
489 }
491 {
492 if (GNUNET_SYSERR == parse_origin (token, origin))
493 {
494 fprintf (stderr, _ ("Failed to parse $ORIGIN from %s\n"), token);
495 ret = 1;
497 return;
498 }
499 break;
500 }
501 if (ZS_READY == state)
502 {
503 fprintf (stderr,
504 _ (
505 "You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n"));
506 ret = 1;
508 return;
509 }
510 // This is a record, let's go
512 {
513 fprintf (stderr,
514 _ ("Only %u records per unique name supported.\n"),
516 ret = 1;
518 return;
519 }
522 next = strchr (token, ' ');
523 if (NULL == next)
524 {
525 fprintf (stderr, "Error, last token: %s\n", token);
526 ret = 1;
528 break;
529 }
530 next[0] = '\0';
531 next++;
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "class is: %s\n", token);
533 while (*next == ' ')
534 next++;
535 token = next;
536 next = strchr (token, ' ');
537 if (NULL == next)
538 {
539 fprintf (stderr, "Error\n");
540 break;
541 }
542 next[0] = '\0';
543 next++;
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "type is: %s\n", token);
547 while (*next == ' ')
548 next++;
549 token = next;
550 }
551 for (int i = 0; i < strlen (token); i++)
552 {
553 if (token[i] == '"')
554 quoted = ! quoted;
555 if ((token[i] == '(') && ! quoted)
556 bracket_unclosed++;
557 if ((token[i] == ')') && ! quoted)
558 bracket_unclosed--;
559 }
560 memcpy (payload_pos, token, strlen (token));
561 payload_pos += strlen (token);
562 if (bracket_unclosed > 0)
563 {
564 *payload_pos = ' ';
565 payload_pos++;
566 continue;
567 }
568 *payload_pos = '\0';
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data is: %s\n\n", payload);
570 if (GNUNET_OK !=
572 &data,
573 &data_size))
574 {
575 fprintf (stderr,
576 _ ("Data `%s' invalid\n"),
577 payload);
578 ret = 1;
580 return;
581 }
582 rd[rd_count].data = data;
584 if (ZS_NAME_CHANGED == state)
585 break;
586 rd_count++;
587 }
588 if (rd_count > 0)
589 {
591 &zone_pkey,
592 lastname,
593 rd_count,
594 rd,
596 NULL);
599 for (int i = 0; i < rd_count; i++)
600 {
601 data = (void*) rd[i].data;
603 }
604 if (ZS_NAME_CHANGED == state)
605 {
606 rd[0] = rd[rd_count]; // recover last rd parsed.
607 rd_count = 1;
608 strcpy (lastname, newname);
610 }
611 else
612 rd_count = 0;
613 return;
614 }
616 {
617 if (NULL != ego_name)
620 if (ego_name[strlen (ego_name) - 1] == '.')
621 ego_name[strlen (ego_name) - 1] = '\0';
623 "Changing origin to %s\n", ego_name);
625 &origin_lookup_cb, NULL);
626 return;
627 }
628 printf ("Published %u records sets with total %u records\n",
631}
static int parse_ttl(char *token, struct GNUNET_TIME_Relative *ttl)
static int parse_origin(char *token, char *origin)
static struct GNUNET_CRYPTO_PrivateKey zone_pkey
Private key for the our zone.
static unsigned int published_records
Statistics, how many records published in aggregate.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Current configurataion.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
#define MAX_RECORDS_PER_NAME
static int ret
Return code.
#define MAX_ZONEFILE_LINE_LEN
Maximum length of a zonefile line.
static char origin[GNUNET_DNSPARSER_MAX_NAME_LENGTH]
Current origin.
#define MAX_ZONEFILE_RECORD_DATA_LEN
FIXME: Soft limit this?
static int state
The current state of the parser.
static void add_continuation(void *cls, enum GNUNET_ErrorCode ec)
static char * res
Currently read line or NULL on EOF.
static char * trim(char *line)
static void origin_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
static char * next_token(char *token)
static unsigned int published_sets
Statistics, how many published record sets.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static unsigned long long payload
How much data are we currently storing in the database?
#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH
Maximum length of a label in DNS.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
Definition: gnsrecord.c:200
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of the value s of a record of type type to the respective binary repre...
Definition: gnsrecord.c:177
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
uint64_t rel_value_us
The actual value.

References _, add_continuation(), cfg, data, GNUNET_GNSRECORD_Data::data, data_size, GNUNET_GNSRECORD_Data::data_size, ego_name, el, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_DNSPARSER_MAX_LABEL_LENGTH, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_string_to_value(), GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_ego_lookup(), GNUNET_log, GNUNET_NAMESTORE_record_set_store(), GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_strdup, GNUNET_SYSERR, MAX_RECORDS_PER_NAME, MAX_ZONEFILE_LINE_LEN, MAX_ZONEFILE_RECORD_DATA_LEN, GNUNET_SCHEDULER_Task::next, next_token(), ns, ns_qe, origin, origin_lookup_cb(), parse_origin(), parse_task, parse_ttl(), payload, published_records, published_sets, rd, rd_count, GNUNET_GNSRECORD_Data::record_type, GNUNET_TIME_Relative::rel_value_us, res, ret, state, trim(), ttl, type, zone_pkey, ZS_NAME_CHANGED, ZS_ORIGIN_CHANGED, ZS_ORIGIN_SET, and ZS_READY.

Referenced by add_continuation(), identity_cb(), origin_create_cb(), origin_lookup_cb(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trim()

static char * trim ( char *  line)
static

Definition at line 190 of file gnunet-namestore-zonefile.c.

191{
192 char *ltrimmed = line;
193 int ltrimmed_len;
194 int quoted = 0;
195
196 // Trim all whitespace to the left
197 while (*ltrimmed == ' ')
198 ltrimmed++;
199 ltrimmed_len = strlen (ltrimmed);
200 // Find the first occurence of an unqoted ';', which is our comment
201 for (int i = 0; i < ltrimmed_len; i++)
202 {
203 if (ltrimmed[i] == '"')
204 quoted = ! quoted;
205 if ((ltrimmed[i] != ';') || quoted)
206 continue;
207 ltrimmed[i] = '\0';
208 }
209 ltrimmed_len = strlen (ltrimmed);
210 // Remove trailing whitespace
211 for (int i = ltrimmed_len; i > 0; i--)
212 {
213 if (ltrimmed[i - 1] != ' ')
214 break;
215 ltrimmed[i - 1] = '\0';
216 }
217 ltrimmed_len = strlen (ltrimmed);
218 if (ltrimmed[ltrimmed_len - 1] == '\n')
219 ltrimmed[ltrimmed_len - 1] = ' ';
220 return ltrimmed;
221}
static char * line
Desired phone line (string to be converted to a hash).

References line.

Referenced by parse().

Here is the caller graph for this function:

◆ next_token()

static char * next_token ( char *  token)
static

Definition at line 224 of file gnunet-namestore-zonefile.c.

225{
226 char *next = token;
227 while (*next == ' ')
228 next++;
229 return next;
230}

References GNUNET_SCHEDULER_Task::next.

Referenced by parse().

Here is the caller graph for this function:

◆ parse_ttl()

static int parse_ttl ( char *  token,
struct GNUNET_TIME_Relative ttl 
)
static

Definition at line 233 of file gnunet-namestore-zonefile.c.

234{
235 char *next;
236 unsigned int ttl_tmp;
237
238 next = strchr (token, ';');
239 if (NULL != next)
240 next[0] = '\0';
241 next = strchr (token, ' ');
242 if (NULL != next)
243 next[0] = '\0';
244 if (1 != sscanf (token, "%u", &ttl_tmp))
245 {
246 fprintf (stderr, "Unable to parse TTL `%s'\n", token);
247 return GNUNET_SYSERR;
248 }
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TTL is: %u\n", ttl_tmp);
250 ttl->rel_value_us = ttl_tmp * 1000 * 1000;
251 return GNUNET_OK;
252}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_SCHEDULER_Task::next, GNUNET_TIME_Relative::rel_value_us, and ttl.

Referenced by parse().

Here is the caller graph for this function:

◆ parse_origin()

static int parse_origin ( char *  token,
char *  origin 
)
static

Definition at line 255 of file gnunet-namestore-zonefile.c.

256{
257 char *next;
258 next = strchr (token, ';');
259 if (NULL != next)
260 next[0] = '\0';
261 next = strchr (token, ' ');
262 if (NULL != next)
263 next[0] = '\0';
264 strcpy (origin, token);
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Origin is: %s\n", origin);
266 return GNUNET_OK;
267}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_Task::next, and origin.

Referenced by parse().

Here is the caller graph for this function:

◆ origin_create_cb()

static void origin_create_cb ( void *  cls,
const struct GNUNET_CRYPTO_PrivateKey pk,
enum GNUNET_ErrorCode  ec 
)
static

Definition at line 270 of file gnunet-namestore-zonefile.c.

272{
273 id_op = NULL;
274 if (GNUNET_EC_NONE != ec)
275 {
276 fprintf (stderr, "Error: %s\n", GNUNET_ErrorCode_get_hint (ec));
277 ret = 1;
279 return;
280 }
282 zone_pkey = *pk;
284}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static void parse(void *cls)
Main function that will be run.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
@ GNUNET_EC_NONE
No error (success).

References GNUNET_EC_NONE, GNUNET_ErrorCode_get_hint(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), id_op, parse(), parse_task, pk, ret, state, zone_pkey, and ZS_ORIGIN_SET.

Referenced by origin_lookup_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ origin_lookup_cb()

static void origin_lookup_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Definition at line 287 of file gnunet-namestore-zonefile.c.

288{
289
290 el = NULL;
291
292 if (NULL == ego)
293 {
295 "$ORIGIN %s does not exist, creating...\n", ego_name);
297 GNUNET_PUBLIC_KEY_TYPE_ECDSA, // FIXME make configurable
299 NULL);
300 return;
301 }
305}
static void origin_create_cb(void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *id, const char *name, const struct GNUNET_CRYPTO_PrivateKey *privkey, enum GNUNET_CRYPTO_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:561
const struct GNUNET_CRYPTO_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:517
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.

References ego_name, el, GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_create(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_SCHEDULER_add_now(), id_op, origin_create_cb(), parse(), parse_task, state, zone_pkey, and ZS_ORIGIN_SET.

Referenced by add_continuation(), and parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_continuation()

static void add_continuation ( void *  cls,
enum GNUNET_ErrorCode  ec 
)
static

Definition at line 308 of file gnunet-namestore-zonefile.c.

309{
310 ns_qe = NULL;
311 if (GNUNET_EC_NONE != ec)
312 {
313 fprintf (stderr,
314 _ ("Failed to store records...\n"));
316 ret = -1;
317 }
319 {
320 if (NULL != ego_name)
323 if (ego_name[strlen (ego_name) - 1] == '.')
324 ego_name[strlen (ego_name) - 1] = '\0';
326 "Changing origin to %s\n", ego_name);
328 &origin_lookup_cb, NULL);
329 return;
330 }
332}

References _, cfg, ego_name, el, GNUNET_EC_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_lookup(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), GNUNET_strdup, ns_qe, origin, origin_lookup_cb(), parse(), parse_task, ret, state, and ZS_ORIGIN_CHANGED.

Referenced by parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ identity_cb()

static void identity_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego 
)
static

Definition at line 635 of file gnunet-namestore-zonefile.c.

636{
637
638 el = NULL;
639 if (NULL == ego)
640 {
641 if (NULL != ego_name)
642 {
643 fprintf (stderr,
644 _ ("Ego `%s' not known to identity service\n"),
645 ego_name);
646
647 }
649 ret = -1;
650 return;
651 }
653 sprintf (origin, "%s.", ego_name);
656}

References _, ego_name, el, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), origin, parse(), parse_task, ret, state, zone_pkey, and ZS_ORIGIN_SET.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle _cfg 
)
static

Definition at line 660 of file gnunet-namestore-zonefile.c.

664{
665 cfg = _cfg;
668 if (NULL == ns)
669 {
670 fprintf (stderr,
671 _ ("Failed to connect to NAMESTORE\n"));
672 return;
673 }
674 id = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
675 if (NULL == id)
676 {
677 fprintf (stderr,
678 _ ("Failed to connect to IDENTITY\n"));
679 return;
680 }
681 if (NULL != ego_name)
683 else
685 state = ZS_READY;
686}
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
static void do_shutdown(void *cls)
Task run on shutdown.
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:487
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1340

References _, cfg, do_shutdown(), ego_name, el, GNUNET_IDENTITY_connect(), GNUNET_IDENTITY_ego_lookup(), GNUNET_NAMESTORE_connect(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), identity_cb(), ns, parse(), parse_task, state, and ZS_READY.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for gnunet-namestore-dbtool.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 697 of file gnunet-namestore-zonefile.c.

698{
701 "zone",
702 "EGO",
704 "name of the ego controlling the zone"),
705 &ego_name),
707 };
708 int lret;
709
710 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
711 return 2;
712
713 GNUNET_log_setup ("gnunet-namestore-dbtool", "WARNING", NULL);
714 if (GNUNET_OK !=
715 (lret = GNUNET_PROGRAM_run (argc,
716 argv,
717 "gnunet-namestore-zonefile",
718 _ (
719 "GNUnet namestore database manipulation tool"),
720 options,
721 &run,
722 NULL)))
723 {
724 GNUNET_free_nz ((void *) argv);
725 return lret;
726 }
727 GNUNET_free_nz ((void *) argv);
728 return ret;
729}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *_cfg)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
Definition of a command line option.

References _, ego_name, gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ rd

struct GNUNET_GNSRECORD_Data rd[50]
static

The record data under a single label.

Reused. Hard limit.

Definition at line 46 of file gnunet-namestore-zonefile.c.

Referenced by array_cleanup(), attr_iter_cb(), attr_store_task(), backward_resolution(), block_create2(), block_create_ecdsa(), block_create_eddsa(), block_decrypt_ecdsa(), block_decrypt_eddsa(), block_get_size_ecdsa(), block_get_size_eddsa(), bulk_tx_start(), check_pkey(), check_rd(), check_result(), clean_blind_sign_priv(), clean_blind_sign_pub(), clean_rsa_public_key(), clean_rsa_signature(), clean_string(), clean_varsize_blob(), collect_tickets_cb(), consistency_iter(), continue_store_activity(), cred_iter_cb(), del_monitor(), DID_resolve_gns_lookup_cb(), dispatch_job(), dispatch_job_monitor(), display_record(), display_record_iterator(), display_record_lookup(), display_record_monitor(), display_records_from_block(), dns_result_parser(), do_shutdown(), filter_tickets_cb(), forward_resolution(), get_existing_rd_exp(), get_existing_record(), get_records_and_call_iterator(), GNUNET_CONVERSATION_phone_get_record(), GNUNET_GNSRECORD_block_calculate_size(), GNUNET_GNSRECORD_block_create(), GNUNET_GNSRECORD_block_create2(), GNUNET_GNSRECORD_block_create_unsigned(), GNUNET_GNSRECORD_is_expired(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_JSON_spec_gnsrecord(), GNUNET_GNSRECORD_normalize_record_set(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_GNSRECORD_record_to_identity_key(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_NAMESTORE_record_set_store(), GNUNET_NAMESTORE_records_store(), handle_delegate_collection_cb(), handle_edit_record_set_response(), handle_gns2dns_result(), handle_gns_namecache_resolution_result(), handle_gns_resolution_result(), handle_gns_response(), handle_gns_result(), handle_lookup_result(), handle_monitor_event(), handle_record(), handle_record_result(), handle_result(), handle_reverse_lookup(), handle_zone_to_name_it(), handle_zone_to_name_response(), lookup_authz_cb(), lookup_it(), lookup_nick_it(), lookup_redirect_uri_result(), monitor_iterate_cb(), namestore_flat_store_records(), namestore_list_iteration(), namestore_postgres_store_records(), namestore_sqlite_store_records(), ns_get_lookup_cb(), ns_lookup_cb(), ns_lookup_result_cb(), parse(), parse_record(), parse_result_call_iterator(), print_record(), process_lookup_result(), process_parallel_lookup_result(), process_result(), process_tickets(), purge_orphans_iterator(), purge_zone_iterator(), recursive_cname_resolution(), recursive_gns2dns_resolution(), recursive_pkey_resolution(), recursive_redirect_resolution(), reply_to_dns(), result_processor(), revoke_attrs_cb(), run(), run_edkey(), run_pkey(), run_with_zone_pkey(), rvk_move_attr_cb(), rvk_ticket_update(), send_lookup_response(), send_lookup_response_with_filter(), start_phone(), start_resolver_lookup(), store_record_set(), transmit_lookup_dns_result(), update_tickets(), vpn_allocation_cb(), zone_iterate_proc(), and zone_iterator().

◆ ttl

◆ origin

◆ rd_count

unsigned int rd_count = 0
static

Number of records for currently parsed set.

Definition at line 61 of file gnunet-namestore-zonefile.c.

Referenced by attr_iter_cb(), backward_resolution(), block_create2(), block_create_ecdsa(), block_create_eddsa(), block_decrypt_ecdsa(), block_decrypt_eddsa(), block_get_size_ecdsa(), block_get_size_eddsa(), check_rd(), check_result(), collect_tickets_cb(), consistency_iter(), continue_store_activity(), cred_iter_cb(), del_monitor(), DID_create_namestore_lookup_cb(), DID_resolve_gns_lookup_cb(), dispatch_job(), dispatch_job_monitor(), dns_result_parser(), do_shutdown(), filter_tickets_cb(), forward_resolution(), get_existing_rd_exp(), get_existing_record(), GNUNET_GNSRECORD_block_calculate_size(), GNUNET_GNSRECORD_block_create(), GNUNET_GNSRECORD_block_create2(), GNUNET_GNSRECORD_block_create_unsigned(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_JSON_spec_gnsrecord(), GNUNET_GNSRECORD_normalize_record_set(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_deserialize_get_size(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_NAMESTORE_record_set_store(), GNUNET_NAMESTORE_records_store(), handle_delegate_collection_cb(), handle_edit_record_set_response(), handle_gns2dns_result(), handle_gns_namecache_resolution_result(), handle_gns_resolution_result(), handle_gns_response(), handle_gns_result(), handle_lookup_result(), handle_monitor_event(), handle_record(), handle_record_result(), handle_result(), handle_reverse_lookup(), handle_zone_to_name_it(), handle_zone_to_name_response(), lookup_authz_cb(), lookup_it(), lookup_nick_it(), lookup_redirect_uri_result(), monitor_iterate_cb(), namestore_flat_store_records(), namestore_postgres_store_records(), namestore_sqlite_store_records(), ns_lookup_cb(), ns_lookup_result_cb(), parse(), process_lookup_result(), process_parallel_lookup_result(), process_result(), process_tickets(), recursive_gns2dns_resolution(), reply_to_dns(), result_processor(), revoke_attrs_cb(), run_edkey(), run_pkey(), run_with_zone_pkey(), rvk_move_attr_cb(), rvk_ticket_update(), send_lookup_response(), send_lookup_response_with_filter(), store_record_set(), update_tickets(), vpn_allocation_cb(), and zone_iterate_proc().

◆ ret

int ret = 0
static

Return code.

Definition at line 66 of file gnunet-namestore-zonefile.c.

Referenced by add_continuation(), identity_cb(), main(), origin_create_cb(), and parse().

◆ ego_name

char* ego_name = NULL
static

Name of the ego.

Definition at line 71 of file gnunet-namestore-zonefile.c.

Referenced by add_continuation(), do_shutdown(), identity_cb(), main(), origin_lookup_cb(), parse(), and run().

◆ res

char* res
static

Currently read line or NULL on EOF.

Definition at line 76 of file gnunet-namestore-zonefile.c.

Referenced by add_dns_result(), add_services(), block_create2(), client_disconnect_cb(), decode_and_send(), delete_old_block(), extract_abs_time(), extract_address(), extract_blind_sign_priv(), extract_blind_sign_pub(), extract_bool(), extract_filename(), extract_fixed_blob(), extract_int64(), extract_rel_time(), extract_rsa_public_key(), extract_rsa_signature(), extract_string(), extract_timestamp(), extract_uint16(), extract_uint32(), extract_uint64(), extract_varsize_blob(), file_hash_finish(), file_hash_task(), get_iv_key(), get_nick_record(), get_server_addresses(), get_url_parameter_copy(), GNUNET_buffer_reap(), GNUNET_buffer_reap_str(), GNUNET_buffer_write_vfstr(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_ecc_dlog(), GNUNET_CRYPTO_ecdsa_sign_derived(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_CRYPTO_eddsa_sign_raw(), GNUNET_CRYPTO_eddsa_verify_(), GNUNET_CRYPTO_edx25519_verify_(), GNUNET_CRYPTO_hash_context_finish(), GNUNET_DISK_directory_create_for_file(), GNUNET_GNSRECORD_block_calculate_size(), GNUNET_GNSRECORD_block_create(), GNUNET_GNSRECORD_block_decrypt(), GNUNET_GNSRECORD_block_sign(), GNUNET_GNSRECORD_block_verify(), GNUNET_hton_double(), GNUNET_NT_scanner_get_type(), GNUNET_ntoh_double(), GNUNET_PQ_exec_prepared(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_blind_sign_priv(), GNUNET_PQ_query_param_blind_sign_pub(), GNUNET_PQ_query_param_fixed_size(), GNUNET_PQ_query_param_int64(), GNUNET_PQ_query_param_null(), GNUNET_PQ_query_param_relative_time(), GNUNET_PQ_query_param_rsa_public_key(), GNUNET_PQ_query_param_rsa_signature(), GNUNET_PQ_query_param_uint16(), GNUNET_PQ_query_param_uint32(), GNUNET_PQ_query_param_uint64(), GNUNET_PQ_reconnect(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_absolute_time_nbo(), GNUNET_PQ_result_spec_array_abs_time(), GNUNET_PQ_result_spec_array_bool(), GNUNET_PQ_result_spec_array_fixed_size(), GNUNET_PQ_result_spec_array_rel_time(), GNUNET_PQ_result_spec_array_string(), GNUNET_PQ_result_spec_array_timestamp(), GNUNET_PQ_result_spec_array_uint16(), GNUNET_PQ_result_spec_array_uint32(), GNUNET_PQ_result_spec_array_uint64(), GNUNET_PQ_result_spec_array_variable_size(), GNUNET_PQ_result_spec_blind_sign_priv(), GNUNET_PQ_result_spec_blind_sign_pub(), GNUNET_PQ_result_spec_bool(), GNUNET_PQ_result_spec_fixed_size(), GNUNET_PQ_result_spec_int64(), GNUNET_PQ_result_spec_relative_time(), GNUNET_PQ_result_spec_rsa_public_key(), GNUNET_PQ_result_spec_rsa_signature(), GNUNET_PQ_result_spec_string(), GNUNET_PQ_result_spec_timestamp(), GNUNET_PQ_result_spec_timestamp_nbo(), GNUNET_PQ_result_spec_uint16(), GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_uint64(), GNUNET_PQ_result_spec_variable_size(), GNUNET_SECRETSHARING_plaintext_generate_i(), GNUNET_STRINGS_string_to_data_alloc(), GNUNET_xstrdup_(), GNUNET_xstrndup_(), handle_arm_result(), handle_auto_result(), handle_block_cache(), handle_block_cache_response(), handle_edit_record_set(), handle_edit_record_set_cancel(), handle_generic_response(), handle_gns_redirect_result(), handle_monitor_notify(), handle_query_message(), handle_record_lookup(), handle_record_store(), handle_success_response(), handle_zone_to_name_response(), hash_for_index_cb(), hash_for_index_val(), list_count(), lookup_nick_it(), main(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), namecache_postgres_lookup_block(), namestore_postgres_clear_editor_hint(), namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_store_records(), namestore_postgres_zone_to_name(), open_static_resource(), pabc_get_issuer(), parse(), parse_result_call_iterator(), parse_rsa_signature(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_key(), postgres_plugin_get_replication(), postgres_plugin_get_zero_anonymity(), pq_notice_receiver_cb(), process_peer_string(), process_result(), query_param_array_generic(), REGEX_BLOCK_check(), return_agpl(), route_control_message_without_fc(), run(), send_client_reply(), send_lookup_response_with_filter(), send_remaining_elements(), sign_cb(), store_record_set(), try_old_ax_keys(), and verify_fair().

◆ published_sets

unsigned int published_sets = 0
static

Statistics, how many published record sets.

Definition at line 81 of file gnunet-namestore-zonefile.c.

Referenced by parse().

◆ published_records

unsigned int published_records = 0
static

Statistics, how many records published in aggregate.

Definition at line 86 of file gnunet-namestore-zonefile.c.

Referenced by parse().

◆ el

◆ zone_pkey

struct GNUNET_CRYPTO_PrivateKey zone_pkey
static

Private key for the our zone.

Definition at line 97 of file gnunet-namestore-zonefile.c.

Referenced by identity_cb(), origin_create_cb(), origin_lookup_cb(), and parse().

◆ ns_qe

struct GNUNET_NAMESTORE_QueueEntry* ns_qe
static

Queue entry for the 'add' operation.

Definition at line 102 of file gnunet-namestore-zonefile.c.

Referenced by add_continuation(), do_shutdown(), and parse().

◆ ns

struct GNUNET_NAMESTORE_Handle* ns
static

Handle to the namestore.

Definition at line 107 of file gnunet-namestore-zonefile.c.

Referenced by do_shutdown(), parse(), and run().

◆ id_op

struct GNUNET_IDENTITY_Operation* id_op
static

Origin create operations.

Definition at line 112 of file gnunet-namestore-zonefile.c.

Referenced by do_shutdown(), origin_create_cb(), and origin_lookup_cb().

◆ id

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Current configurataion.

Definition at line 122 of file gnunet-namestore-zonefile.c.

Referenced by add_continuation(), parse(), and run().

◆ parse_task

struct GNUNET_SCHEDULER_Task* parse_task
static

◆ state

int state
static

The current state of the parser.

Definition at line 132 of file gnunet-namestore-zonefile.c.

Referenced by add_continuation(), identity_cb(), origin_create_cb(), origin_lookup_cb(), parse(), and run().