GNUnet 0.22.2
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 *pttl)
 
static int parse_origin (char *token, char *porigin)
 
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 158 of file gnunet-namestore-zonefile.c.

159{
160 (void) cls;
161 if (NULL != ego_name)
163 if (NULL != el)
164 {
166 el = NULL;
167 }
168 if (NULL != ns_qe)
170 if (NULL != id_op)
172 if (NULL != ns)
174 if (NULL != id)
176 for (int i = 0; i < rd_count; i++)
177 {
178 void *rd_ptr = (void*) rd[i].data;
179 GNUNET_free (rd_ptr);
180 }
181 if (NULL != parse_task)
183}
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:980

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 358 of file gnunet-namestore-zonefile.c.

359{
360 char buf[MAX_ZONEFILE_LINE_LEN];
362 char *next;
363 char *token;
364 char *payload_pos;
365 static char lastname[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
367 void *data;
368 size_t data_size;
369 int ttl_line = 0;
370 int type;
371 int bracket_unclosed = 0;
372 int quoted = 0;
373 int ln = 0;
374
375 parse_task = NULL;
376 /* use filename provided as 1st argument (stdin by default) */
377 while ((res = fgets (buf, sizeof(buf), stdin))) /* read each line of input */
378 {
379 ln++;
380 ttl_line = 0;
381 token = trim (buf);
383 "Trimmed line (bracket %s): `%s'\n",
384 (bracket_unclosed > 0) ? "unclosed" : "closed",
385 token);
386 if ((0 == strlen (token)) ||
387 ((1 == strlen (token)) && (' ' == *token)))
388 continue; // I guess we can safely ignore blank lines
389 if (bracket_unclosed == 0)
390 {
391 /* Payload is already parsed */
392 payload_pos = payload;
393 /* Find space */
394 next = strchr (token, ' ');
395 if (NULL == next)
396 {
397 fprintf (stderr, "Error at line %u: %s\n", ln, token);
398 ret = 1;
400 return;
401 }
402 next[0] = '\0';
403 next++;
404 if (0 == (strcmp (token, "$ORIGIN")))
405 {
407 token = next_token (next);
408 }
409 else if (0 == (strcmp (token, "$TTL")))
410 {
411 ttl_line = 1;
412 token = next_token (next);
413 }
414 else
415 {
416 if (0 == strcmp (token, "IN")) // Inherit name from before
417 {
419 "Old name: %s\n", lastname);
420 strcpy (newname, lastname);
421 token[strlen (token)] = ' ';
422 }
423 else if (token[strlen (token) - 1] != '.') // no fqdn
424 {
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: %s\n", token);
426 if (GNUNET_DNSPARSER_MAX_LABEL_LENGTH < strlen (token))
427 {
428 fprintf (stderr,
429 _ ("Name `%s' is too long\n"),
430 token);
431 ret = 1;
433 return;
434 }
435 strcpy (newname, token);
436 token = next_token (next);
437 }
438 else if (0 == strcmp (token, origin))
439 {
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: @\n");
441 strcpy (newname, "@");
442 token = next_token (next);
443 }
444 else
445 {
446 if (strlen (token) < strlen (origin))
447 {
448 fprintf (stderr, "Wrong origin: %s (expected %s)\n", token, origin);
449 break; // FIXME error?
450 }
451 if (0 != strcmp (token + (strlen (token) - strlen (origin)), origin))
452 {
453 fprintf (stderr, "Wrong origin: %s (expected %s)\n", token, origin);
454 break;
455 }
456 token[strlen (token) - strlen (origin) - 1] = '\0';
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: %s\n", token);
458 if (GNUNET_DNSPARSER_MAX_LABEL_LENGTH < strlen (token))
459 {
460 fprintf (stderr,
461 _ ("Name `%s' is too long\n"),
462 token);
463 ret = 1;
465 return;
466 }
467 strcpy (newname, token);
468 token = next_token (next);
469 }
470 if (0 != strcmp (newname, lastname) &&
471 (0 < rd_count))
472 {
474 "Name changed %s->%s, storing record set of %u elements\n",
475 lastname, newname,
476 rd_count);
478 }
479 else
480 {
481 strcpy (lastname, newname);
482 }
483 }
484
485 if (ttl_line)
486 {
487 if (GNUNET_SYSERR == parse_ttl (token, &ttl))
488 {
489 fprintf (stderr, _ ("Failed to parse $TTL\n"));
490 ret = 1;
492 return;
493 }
494 continue;
495 }
497 {
498 if (GNUNET_SYSERR == parse_origin (token, origin))
499 {
500 fprintf (stderr, _ ("Failed to parse $ORIGIN from %s\n"), token);
501 ret = 1;
503 return;
504 }
505 break;
506 }
507 if (ZS_READY == state)
508 {
509 fprintf (stderr,
510 _ (
511 "You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n"));
512 ret = 1;
514 return;
515 }
516 // This is a record, let's go
518 {
519 fprintf (stderr,
520 _ ("Only %u records per unique name supported.\n"),
522 ret = 1;
524 return;
525 }
528 next = strchr (token, ' ');
529 if (NULL == next)
530 {
531 fprintf (stderr, "Error, last token: %s\n", token);
532 ret = 1;
534 break;
535 }
536 next[0] = '\0';
537 next++;
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "class is: %s\n", token);
539 while (*next == ' ')
540 next++;
541 token = next;
542 next = strchr (token, ' ');
543 if (NULL == next)
544 {
545 fprintf (stderr, "Error\n");
546 break;
547 }
548 next[0] = '\0';
549 next++;
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "type is: %s\n", token);
553 while (*next == ' ')
554 next++;
555 token = next;
556 }
557 for (int i = 0; i < strlen (token); i++)
558 {
559 if (token[i] == '"')
560 quoted = ! quoted;
561 if ((token[i] == '(') && ! quoted)
562 bracket_unclosed++;
563 if ((token[i] == ')') && ! quoted)
564 bracket_unclosed--;
565 }
566 memcpy (payload_pos, token, strlen (token));
567 payload_pos += strlen (token);
568 if (bracket_unclosed > 0)
569 {
570 *payload_pos = ' ';
571 payload_pos++;
572 continue;
573 }
574 *payload_pos = '\0';
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data is: %s\n\n", payload);
576 if (GNUNET_OK !=
578 &data,
579 &data_size))
580 {
581 fprintf (stderr,
582 _ ("Data `%s' invalid\n"),
583 payload);
584 ret = 1;
586 return;
587 }
588 rd[rd_count].data = data;
590 if (ZS_NAME_CHANGED == state)
591 break;
592 rd_count++;
593 }
594 if (rd_count > 0)
595 {
597 &zone_pkey,
598 lastname,
599 rd_count,
600 rd,
602 NULL);
605 for (int i = 0; i < rd_count; i++)
606 {
607 data = (void*) rd[i].data;
609 }
610 if (ZS_NAME_CHANGED == state)
611 {
612 rd[0] = rd[rd_count]; // recover last rd parsed.
613 rd_count = 1;
614 strcpy (lastname, newname);
616 }
617 else
618 rd_count = 0;
619 return;
620 }
622 {
623 if (NULL != ego_name)
626 if (ego_name[strlen (ego_name) - 1] == '.')
627 ego_name[strlen (ego_name) - 1] = '\0';
629 "Changing origin to %s\n", ego_name);
631 &origin_lookup_cb, NULL);
632 return;
633 }
634 printf ("Published %u records sets with total %u records\n",
637}
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 int parse_origin(char *token, char *porigin)
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 int parse_ttl(char *token, struct GNUNET_TIME_Relative *pttl)
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:192
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:169
@ 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 occurrence 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 225 of file gnunet-namestore-zonefile.c.

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

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 pttl 
)
static

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

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

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

Referenced by parse().

Here is the caller graph for this function:

◆ parse_origin()

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

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

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

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

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 274 of file gnunet-namestore-zonefile.c.

276{
277 id_op = NULL;
278 if (GNUNET_EC_NONE != ec)
279 {
280 fprintf (stderr, "Error: %s\n", GNUNET_ErrorCode_get_hint (ec));
281 ret = 1;
283 return;
284 }
286 zone_pkey = *pk;
288}
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:1304
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 292 of file gnunet-namestore-zonefile.c.

293{
294
295 el = NULL;
296
297 if (NULL == ego)
298 {
300 "$ORIGIN %s does not exist, creating...\n", ego_name);
302 GNUNET_PUBLIC_KEY_TYPE_ECDSA, // FIXME make configurable
304 NULL);
305 return;
306 }
310}
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 314 of file gnunet-namestore-zonefile.c.

315{
316 ns_qe = NULL;
317 if (GNUNET_EC_NONE != ec)
318 {
319 fprintf (stderr,
320 _ ("Failed to store records...\n"));
322 ret = -1;
323 }
325 {
326 if (NULL != ego_name)
329 if (ego_name[strlen (ego_name) - 1] == '.')
330 ego_name[strlen (ego_name) - 1] = '\0';
332 "Changing origin to %s\n", ego_name);
334 &origin_lookup_cb, NULL);
335 return;
336 }
338}

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 641 of file gnunet-namestore-zonefile.c.

642{
643
644 el = NULL;
645 if (NULL == ego)
646 {
647 if (NULL != ego_name)
648 {
649 fprintf (stderr,
650 _ ("Ego `%s' not known to identity service\n"),
651 ego_name);
652
653 }
655 ret = -1;
656 return;
657 }
659 sprintf (origin, "%s.", ego_name);
662}

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 666 of file gnunet-namestore-zonefile.c.

670{
671 cfg = _cfg;
674 if (NULL == ns)
675 {
676 fprintf (stderr,
677 _ ("Failed to connect to NAMESTORE\n"));
678 return;
679 }
680 id = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
681 if (NULL == id)
682 {
683 fprintf (stderr,
684 _ ("Failed to connect to IDENTITY\n"));
685 return;
686 }
687 if (NULL != ego_name)
689 else
691 state = ZS_READY;
692}
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:1339

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 703 of file gnunet-namestore-zonefile.c.

704{
707 "zone",
708 "EGO",
710 "name of the ego controlling the zone"),
711 &ego_name),
713 };
714 int lret;
715
716 GNUNET_log_setup ("gnunet-namestore-dbtool", "WARNING", NULL);
717 if (GNUNET_OK !=
719 argc,
720 argv,
721 "gnunet-namestore-zonefile",
722 _ (
723 "GNUnet namestore database manipulation tool"),
724 options,
725 &run,
726 NULL)))
727 {
728 return lret;
729 }
730 return ret;
731}
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:74
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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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:407
Definition of a command line option.

References _, ego_name, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), 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_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_command_stdin(), 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_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_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_blinded_sig(), 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_query_param_unblinded_sig(), 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(), prepare_check_patch(), prepare_get_oid_by_name(), 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().