30#define MAX_RECORDS_PER_NAME 50
35#define MAX_ZONEFILE_LINE_LEN 4096
40#define MAX_ZONEFILE_RECORD_DATA_LEN 2048
178 void *rd_ptr = (
void*)
rd[i].
data;
192 char *ltrimmed =
line;
197 while (*ltrimmed ==
' ')
199 ltrimmed_len = strlen (ltrimmed);
201 for (
int i = 0; i < ltrimmed_len; i++)
203 if (ltrimmed[i] ==
'"')
205 if ((ltrimmed[i] !=
';') || quoted)
209 ltrimmed_len = strlen (ltrimmed);
211 for (
int i = ltrimmed_len; i > 0; i--)
213 if (ltrimmed[i - 1] !=
' ')
215 ltrimmed[i - 1] =
'\0';
217 ltrimmed_len = strlen (ltrimmed);
218 if (ltrimmed[ltrimmed_len - 1] ==
'\n')
219 ltrimmed[ltrimmed_len - 1] =
' ';
238 unsigned int ttl_tmp;
240 next = strchr (token,
';');
243 next = strchr (token,
' ');
246 if (1 != sscanf (token,
"%u", &ttl_tmp))
248 fprintf (stderr,
"Unable to parse TTL `%s'\n", token);
261 next = strchr (token,
';');
264 next = strchr (token,
' ');
267 strcpy (porigin, token);
300 "$ORIGIN %s does not exist, creating...\n",
ego_name);
320 _ (
"Failed to store records...\n"));
332 "Changing origin to %s\n",
ego_name);
371 int bracket_unclosed = 0;
377 while ((
res = fgets (buf,
sizeof(buf), stdin)))
383 "Trimmed line (bracket %s): `%s'\n",
384 (bracket_unclosed > 0) ?
"unclosed" :
"closed",
386 if ((0 == strlen (token)) ||
387 ((1 == strlen (token)) && (
' ' == *token)))
389 if (bracket_unclosed == 0)
394 next = strchr (token,
' ');
397 fprintf (stderr,
"Error at line %u: %s\n", ln, token);
404 if (0 == (strcmp (token,
"$ORIGIN")))
409 else if (0 == (strcmp (token,
"$TTL")))
416 if (0 == strcmp (token,
"IN"))
419 "Old name: %s\n", lastname);
420 strcpy (newname, lastname);
421 token[strlen (token)] =
' ';
423 else if (token[strlen (token) - 1] !=
'.')
429 _ (
"Name `%s' is too long\n"),
435 strcpy (newname, token);
438 else if (0 == strcmp (token,
origin))
441 strcpy (newname,
"@");
446 if (strlen (token) < strlen (
origin))
448 fprintf (stderr,
"Wrong origin: %s (expected %s)\n", token,
origin);
451 if (0 != strcmp (token + (strlen (token) - strlen (
origin)),
origin))
453 fprintf (stderr,
"Wrong origin: %s (expected %s)\n", token,
origin);
456 token[strlen (token) - strlen (
origin) - 1] =
'\0';
461 _ (
"Name `%s' is too long\n"),
467 strcpy (newname, token);
470 if (0 != strcmp (newname, lastname) &&
474 "Name changed %s->%s, storing record set of %u elements\n",
481 strcpy (lastname, newname);
489 fprintf (stderr,
_ (
"Failed to parse $TTL\n"));
500 fprintf (stderr,
_ (
"Failed to parse $ORIGIN from %s\n"), token);
511 "You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n"));
520 _ (
"Only %u records per unique name supported.\n"),
528 next = strchr (token,
' ');
531 fprintf (stderr,
"Error, last token: %s\n", token);
542 next = strchr (token,
' ');
545 fprintf (stderr,
"Error\n");
557 for (
int i = 0; i < strlen (token); i++)
561 if ((token[i] ==
'(') && ! quoted)
563 if ((token[i] ==
')') && ! quoted)
566 memcpy (payload_pos, token, strlen (token));
567 payload_pos += strlen (token);
568 if (bracket_unclosed > 0)
582 _ (
"Data `%s' invalid\n"),
614 strcpy (lastname, newname);
629 "Changing origin to %s\n",
ego_name);
634 printf (
"Published %u records sets with total %u records\n",
650 _ (
"Ego `%s' not known to identity service\n"),
677 _ (
"Failed to connect to NAMESTORE\n"));
684 _ (
"Failed to connect to IDENTITY\n"));
703main (
int argc,
char *
const *argv)
710 "name of the ego controlling the zone"),
721 "gnunet-namestore-zonefile",
723 "GNUnet namestore database manipulation tool"),
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static char * line
Desired phone line (string to be converted to a hash).
static char * data
The data to insert into the dht.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
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_CRYPTO_PrivateKey zone_pkey
Private key for the our zone.
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
static void parse(void *cls)
Main function that will be run.
static unsigned int published_records
Statistics, how many records published in aggregate.
static void origin_create_cb(void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Current configurataion.
static struct GNUNET_SCHEDULER_Task * parse_task
Scheduled parse task.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
#define MAX_RECORDS_PER_NAME
static int ret
Return code.
static void do_shutdown(void *cls)
Task run on shutdown.
static struct GNUNET_IDENTITY_EgoLookup * el
Handle to identity lookup.
static char * ego_name
Name of the ego.
#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 unsigned int rd_count
Number of records for currently parsed set.
static int parse_origin(char *token, char *porigin)
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *_cfg)
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static char * trim(char *line)
int main(int argc, char *const *argv)
The main function for gnunet-namestore-dbtool.
static void origin_lookup_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
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?
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NONE
No error (success).
Plugin API for the namestore database backend.
#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH
Maximum length of a label in DNS.
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
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.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
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...
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
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.
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.
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.
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.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
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.
#define GNUNET_log(kind,...)
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_free(ptr)
Wrapper around free.
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_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.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
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,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
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,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
A private key for an identity as per LSD0001.
Definition of a command line option.
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.
Handle for an operation with the identity service.
Connection to the NAMESTORE service.
An QueueEntry used to store information for a pending NAMESTORE record operation.
Entry in list of pending tasks.
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.