GNUnet  0.19.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 tx_end (void *cls, enum GNUNET_ErrorCode ec)
 
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_IDENTITY_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 tx_start (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_IDENTITY_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 }
uint32_t data
The data value.
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:740
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:757
#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:944

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:

◆ tx_end()

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

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

188 {
189  ns_qe = NULL;
190  if (GNUNET_EC_NONE != ec)
191  {
192  fprintf (stderr,
193  _ ("Ego `%s' not known to identity service\n"),
194  ego_name);
196  ret = -1;
197  }
199 }
@ GNUNET_EC_NONE
No error (success).
static int ret
Return code.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:534
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

References _, ego_name, GNUNET_EC_NONE, GNUNET_SCHEDULER_shutdown(), ns_qe, and ret.

Referenced by parse().

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

369 {
372  char *next;
373  char *token;
374  char *payload_pos;
375  static char lastname[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
376  char newname[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
377  void *data;
378  size_t data_size;
379  int ttl_line = 0;
380  int type;
381  int bracket_unclosed = 0;
382  int quoted = 0;
383 
384  parse_task = NULL;
385  /* use filename provided as 1st argument (stdin by default) */
386  int ln = 0;
387  while ((res = fgets (buf, sizeof(buf), stdin))) /* read each line of input */
388  {
389  ln++;
390  ttl_line = 0;
391  token = trim (buf);
393  "Trimmed line (bracket %s): `%s'\n",
394  (bracket_unclosed > 0) ? "unclosed" : "closed",
395  token);
396  if ((0 == strlen (token)) ||
397  ((1 == strlen (token)) && (' ' == *token)))
398  continue; // I guess we can safely ignore blank lines
399  if (bracket_unclosed == 0)
400  {
401  /* Payload is already parsed */
402  payload_pos = payload;
403  /* Find space */
404  next = strchr (token, ' ');
405  if (NULL == next)
406  {
407  fprintf (stderr, "Error at line %u: %s\n", ln, token);
408  ret = 1;
410  return;
411  }
412  next[0] = '\0';
413  next++;
414  if (0 == (strcmp (token, "$ORIGIN")))
415  {
417  token = next_token (next);
418  }
419  else if (0 == (strcmp (token, "$TTL")))
420  {
421  ttl_line = 1;
422  token = next_token (next);
423  }
424  else
425  {
426  if (0 == strcmp (token, "IN")) // Inherit name from before
427  {
429  "Old name: %s\n", lastname);
430  strcpy (newname, lastname);
431  token[strlen (token)] = ' ';
432  }
433  else if (token[strlen (token) - 1] != '.') // no fqdn
434  {
435  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: %s\n", token);
436  if (GNUNET_DNSPARSER_MAX_LABEL_LENGTH < strlen (token))
437  {
438  fprintf (stderr,
439  _ ("Name `%s' is too long\n"),
440  token);
441  ret = 1;
443  return;
444  }
445  strcpy (newname, token);
446  token = next_token (next);
447  }
448  else if (0 == strcmp (token, origin))
449  {
450  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: @\n");
451  strcpy (newname, "@");
452  token = next_token (next);
453  }
454  else
455  {
456  if (strlen (token) < strlen (origin))
457  {
458  fprintf (stderr, "Wrong origin: %s (expected %s)\n", token, origin);
459  break; // FIXME error?
460  }
461  if (0 != strcmp (token + (strlen (token) - strlen (origin)), origin))
462  {
463  fprintf (stderr, "Wrong origin: %s (expected %s)\n", token, origin);
464  break;
465  }
466  token[strlen (token) - strlen (origin) - 1] = '\0';
467  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New name: %s\n", token);
468  if (GNUNET_DNSPARSER_MAX_LABEL_LENGTH < strlen (token))
469  {
470  fprintf (stderr,
471  _ ("Name `%s' is too long\n"),
472  token);
473  ret = 1;
475  return;
476  }
477  strcpy (newname, token);
478  token = next_token (next);
479  }
480  if (0 != strcmp (newname, lastname) &&
481  (0 < rd_count))
482  {
484  "Name changed %s->%s, storing record set of %u elements\n",
485  lastname, newname,
486  rd_count);
488  }
489  else {
490  strcpy (lastname, newname);
491  }
492  }
493 
494  if (ttl_line)
495  {
496  if (GNUNET_SYSERR == parse_ttl (token, &ttl))
497  {
498  fprintf (stderr, _ ("Failed to parse $TTL\n"));
499  ret = 1;
501  return;
502  }
503  continue;
504  }
505  if (ZS_ORIGIN_CHANGED == state)
506  {
507  if (GNUNET_SYSERR == parse_origin (token, origin))
508  {
509  fprintf (stderr, _ ("Failed to parse $ORIGIN from %s\n"), token);
510  ret = 1;
512  return;
513  }
514  break;
515  }
516  if (ZS_READY == state)
517  {
518  fprintf (stderr,
519  _ (
520  "You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n"));
521  ret = 1;
523  return;
524  }
525  // This is a record, let's go
527  {
528  fprintf (stderr,
529  _ ("Only %u records per unique name supported.\n"),
531  ret = 1;
533  return;
534  }
537  next = strchr (token, ' ');
538  if (NULL == next)
539  {
540  fprintf (stderr, "Error, last token: %s\n", token);
541  ret = 1;
543  break;
544  }
545  next[0] = '\0';
546  next++;
547  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "class is: %s\n", token);
548  while (*next == ' ')
549  next++;
550  token = next;
551  next = strchr (token, ' ');
552  if (NULL == next)
553  {
554  fprintf (stderr, "Error\n");
555  break;
556  }
557  next[0] = '\0';
558  next++;
559  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "type is: %s\n", token);
562  while (*next == ' ')
563  next++;
564  token = next;
565  }
566  for (int i = 0; i < strlen (token); i++)
567  {
568  if (token[i] == '"')
569  quoted = ! quoted;
570  if ((token[i] == '(') && ! quoted)
571  bracket_unclosed++;
572  if ((token[i] == ')') && ! quoted)
573  bracket_unclosed--;
574  }
575  memcpy (payload_pos, token, strlen (token));
576  payload_pos += strlen (token);
577  if (bracket_unclosed > 0)
578  {
579  *payload_pos = ' ';
580  payload_pos++;
581  continue;
582  }
583  *payload_pos = '\0';
584  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data is: %s\n\n", payload);
585  if (GNUNET_OK !=
587  &data,
588  &data_size))
589  {
590  fprintf (stderr,
591  _ ("Data `%s' invalid\n"),
592  payload);
593  ret = 1;
595  return;
596  }
597  rd[rd_count].data = data;
599  if (ZS_NAME_CHANGED == state)
600  break;
601  rd_count++;
602  }
603  if (rd_count > 0)
604  {
606  &zone_pkey,
607  lastname,
608  rd_count,
609  rd,
611  NULL);
612  published_sets++;
614  for (int i = 0; i < rd_count; i++)
615  {
616  data = (void*) rd[i].data;
617  GNUNET_free (data);
618  }
619  if (ZS_NAME_CHANGED == state)
620  {
621  rd[0] = rd[rd_count]; // recover last rd parsed.
622  rd_count = 1;
623  strcpy (lastname, newname);
625  }
626  else
627  rd_count = 0;
628  return;
629  }
630  if (ZS_ORIGIN_CHANGED == state)
631  {
632  if (NULL != ego_name)
635  if (ego_name[strlen (ego_name) - 1] == '.')
636  ego_name[strlen (ego_name) - 1] = '\0';
638  "Changing origin to %s\n", ego_name);
640  &origin_lookup_cb, NULL);
641  return;
642  }
643  printf ("Published %u records sets with total %u records\n",
646  &tx_end,
647  NULL);
648 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static int parse_ttl(char *token, struct GNUNET_TIME_Relative *ttl)
static int parse_origin(char *token, char *origin)
static struct GNUNET_IDENTITY_PrivateKey zone_pkey
Private key for the our zone.
static char * next_token(char *token)
static unsigned int published_records
Statistics, how many records published in aggregate.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Current configurataion.
static void tx_end(void *cls, enum GNUNET_ErrorCode ec)
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
#define MAX_RECORDS_PER_NAME
#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 unsigned int published_sets
Statistics, how many published record sets.
static unsigned long long payload
How much data are we currently storing in the database?
static char buf[2048]
#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH
Maximum length of a label in DNS.
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
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
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_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_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.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_commit(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Commit a namestore transaction.
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References _, add_continuation(), buf, cfg, GNUNET_GNSRECORD_Data::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_records_store(), GNUNET_NAMESTORE_transaction_commit(), 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, tx_end(), type, zone_pkey, ZS_NAME_CHANGED, ZS_ORIGIN_CHANGED, ZS_ORIGIN_SET, and ZS_READY.

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

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

206 {
207  char *ltrimmed = line;
208  int ltrimmed_len;
209  int quoted = 0;
210 
211  // Trim all whitespace to the left
212  while (*ltrimmed == ' ')
213  ltrimmed++;
214  ltrimmed_len = strlen (ltrimmed);
215  // Find the first occurence of an unqoted ';', which is our comment
216  for (int i = 0; i < ltrimmed_len; i++)
217  {
218  if (ltrimmed[i] == '"')
219  quoted = ! quoted;
220  if ((ltrimmed[i] != ';') || quoted)
221  continue;
222  ltrimmed[i] = '\0';
223  }
224  ltrimmed_len = strlen (ltrimmed);
225  // Remove trailing whitespace
226  for (int i = ltrimmed_len; i > 0; i--)
227  {
228  if (ltrimmed[i - 1] != ' ')
229  break;
230  ltrimmed[i - 1] = '\0';
231  }
232  ltrimmed_len = strlen (ltrimmed);
233  if (ltrimmed[ltrimmed_len - 1] == '\n')
234  ltrimmed[ltrimmed_len - 1] = ' ';
235  return ltrimmed;
236 }
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 239 of file gnunet-namestore-zonefile.c.

240 {
241  char *next = token;
242  while (*next == ' ')
243  next++;
244  return next;
245 }

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

249 {
250  char *next;
251  unsigned int ttl_tmp;
252 
253  next = strchr (token, ';');
254  if (NULL != next)
255  next[0] = '\0';
256  next = strchr (token, ' ');
257  if (NULL != next)
258  next[0] = '\0';
259  if (1 != sscanf (token, "%u", &ttl_tmp))
260  {
261  fprintf (stderr, "Unable to parse TTL `%s'\n", token);
262  return GNUNET_SYSERR;
263  }
264  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TTL is: %u\n", ttl_tmp);
265  ttl->rel_value_us = ttl_tmp * 1000 * 1000;
266  return GNUNET_OK;
267 }

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

271 {
272  char *next;
273  next = strchr (token, ';');
274  if (NULL != next)
275  next[0] = '\0';
276  next = strchr (token, ' ');
277  if (NULL != next)
278  next[0] = '\0';
279  strcpy (origin, token);
280  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Origin is: %s\n", origin);
281  return GNUNET_OK;
282 }

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_IDENTITY_PrivateKey pk,
enum GNUNET_ErrorCode  ec 
)
static

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

287 {
288  id_op = NULL;
289  if (GNUNET_EC_NONE != ec)
290  {
291  fprintf (stderr, "Error: %s\n", GNUNET_ErrorCode_get_hint (ec));
292  ret = 1;
294  return;
295  }
297  zone_pkey = *pk;
299 }
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
struct GNUNET_IDENTITY_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:1268

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

303 {
304 
305  el = NULL;
306 
307  if (NULL == ego)
308  {
310  "$ORIGIN %s does not exist, creating...\n", ego_name);
312  GNUNET_IDENTITY_TYPE_ECDSA, // FIXME make configurable
314  NULL);
315  return;
316  }
320 }
static void origin_create_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, enum GNUNET_ErrorCode ec)
const struct GNUNET_IDENTITY_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:560
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_IDENTITY_PrivateKey *privkey, enum GNUNET_IDENTITY_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:586
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.

References ego_name, el, GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_create(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_log, 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 323 of file gnunet-namestore-zonefile.c.

324 {
325  ns_qe = NULL;
326  if (GNUNET_EC_NONE != ec)
327  {
328  fprintf (stderr,
329  _ ("Failed to store records...\n"));
331  ret = -1;
332  }
333  if (ZS_ORIGIN_CHANGED == state)
334  {
335  if (NULL != ego_name)
338  if (ego_name[strlen (ego_name) - 1] == '.')
339  ego_name[strlen (ego_name) - 1] = '\0';
341  "Changing origin to %s\n", ego_name);
343  &origin_lookup_cb, NULL);
344  return;
345  }
347 }

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:

◆ tx_start()

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

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

652 {
653  ns_qe = NULL;
654  if (GNUNET_EC_NONE != ec)
655  {
656  fprintf (stderr,
657  _ ("Ego `%s' not known to identity service\n"),
658  ego_name);
660  ret = -1;
661  return;
662  }
664 }

References _, ego_name, GNUNET_EC_NONE, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), ns_qe, parse(), parse_task, and ret.

Referenced by identity_cb().

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

668 {
669 
670  el = NULL;
671  if (NULL == ego)
672  {
673  if (NULL != ego_name)
674  {
675  fprintf (stderr,
676  _ ("Ego `%s' not known to identity service\n"),
677  ego_name);
678 
679  }
681  ret = -1;
682  return;
683  }
685  sprintf (origin, "%s.", ego_name);
688  &tx_start,
689  NULL);
690 }
static void tx_start(void *cls, enum GNUNET_ErrorCode ec)
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_begin(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
New API draft.

References _, ego_name, el, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_transaction_begin(), GNUNET_SCHEDULER_shutdown(), ns, ns_qe, origin, ret, state, tx_start(), 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 694 of file gnunet-namestore-zonefile.c.

698 {
699  cfg = _cfg;
702  if (NULL == ns)
703  {
704  fprintf (stderr,
705  _ ("Failed to connect to NAMESTORE\n"));
706  return;
707  }
708  id = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
709  if (NULL == id)
710  {
711  fprintf (stderr,
712  _ ("Failed to connect to IDENTITY\n"));
713  return;
714  }
715  if (NULL != ego_name)
717  else
719  state = ZS_READY;
720 }
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:531
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:1303

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

732 {
735  "zone",
736  "EGO",
737  gettext_noop (
738  "name of the ego controlling the zone"),
739  &ego_name),
741  };
742  int lret;
743 
744  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
745  return 2;
746 
747  GNUNET_log_setup ("gnunet-namestore-dbtool", "WARNING", NULL);
748  if (GNUNET_OK !=
749  (lret = GNUNET_PROGRAM_run (argc,
750  argv,
751  "gnunet-namestore-zonefile",
752  _ (
753  "GNUnet namestore database manipulation tool"),
754  options,
755  &run,
756  NULL)))
757  {
758  GNUNET_free_nz ((void *) argv);
759  return lret;
760  }
761  GNUNET_free_nz ((void *) argv);
762  return ret;
763 }
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.
int 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:1222
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 1 of file gnunet-namestore-zonefile.c.

Referenced by attr_iter_cb(), attr_store_task(), backward_resolution(), block_create2(), block_create_ecdsa(), block_create_eddsa(), bulk_tx_start(), check_credential_iteration_start(), check_monitor_start(), check_pkey(), check_rd(), check_result(), check_zone_to_name(), clean_rsa_public_key(), clean_rsa_signature(), clean_string(), clean_varsize_blob(), collect_tickets_cb(), completed_cb(), consistency_iter(), continue_store_activity(), create_response(), del_monitor(), DID_resolve(), 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(), GNUNET_CONVERSATION_phone_get_record(), GNUNET_GNSRECORD_is_expired(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_NAMESTORE_records_store(), GNUNET_NAMESTORE_records_store2(), handle_delegate_collection_cb(), 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_response(), iterate_do_cb(), iterate_done_cb(), iterate_error_cb(), lookup_authz_cb(), lookup_it(), lookup_nick_it(), lookup_records(), lookup_redirect_uri_result(), namestore_flat_store_records(), namestore_list_iteration(), ns_get_lookup_cb(), ns_lookup_cb(), ns_lookup_result_cb(), parse(), parse_record(), 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(), register_do_cb(), register_done_cb(), register_error_cb(), reply_to_dns(), result_processor(), revoke_attrs_cb(), run(), run_edkey(), run_pkey(), run_with_zone_pkey(), rvk_move_attr_cb(), rvk_ticket_update(), search_done_cb(), search_error_cb(), send_lookup_response(), send_lookup_response_with_filter(), start_phone(), start_resolver_lookup(), 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(), check_credential_iteration_start(), check_monitor_start(), check_rd(), check_result(), check_zone_to_name(), collect_tickets_cb(), consistency_iter(), continue_store_activity(), del_monitor(), DID_create(), DID_resolve(), dispatch_job(), dispatch_job_monitor(), dns_result_parser(), do_shutdown(), filter_tickets_cb(), forward_resolution(), get_existing_rd_exp(), get_existing_record(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_deserialize_get_size(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_NAMESTORE_records_store(), GNUNET_NAMESTORE_records_store2(), handle_delegate_collection_cb(), 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_response(), lookup_authz_cb(), lookup_it(), lookup_nick_it(), lookup_redirect_uri_result(), namestore_flat_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(), 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(), parse(), tx_end(), and tx_start().

◆ ego_name

char* ego_name = NULL
static

◆ res

char* res
static

Currently read line or NULL on EOF.

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

Referenced by parse().

◆ 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

struct GNUNET_IDENTITY_EgoLookup* el
static

Handle to identity lookup.

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

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

◆ zone_pkey

struct GNUNET_IDENTITY_PrivateKey zone_pkey
static

Private key for the our zone.

Definition at line 92 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(), identity_cb(), parse(), tx_end(), and tx_start().

◆ 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(), identity_cb(), 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

struct GNUNET_IDENTITY_Handle* id
static

Handle to IDENTITY.

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

◆ 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().