30 #define MAX_RECORDS_PER_NAME 50
35 #define MAX_ZONEFILE_LINE_LEN 4096
40 #define MAX_ZONEFILE_RECORD_DATA_LEN 2048
179 void *rd_ptr = (
void*)
rd[i].
data;
193 _ (
"Ego `%s' not known to identity service\n"),
207 char *ltrimmed =
line;
212 while (*ltrimmed ==
' ')
214 ltrimmed_len = strlen (ltrimmed);
216 for (
int i = 0; i < ltrimmed_len; i++)
218 if (ltrimmed[i] ==
'"')
220 if ((ltrimmed[i] !=
';') || quoted)
224 ltrimmed_len = strlen (ltrimmed);
226 for (
int i = ltrimmed_len; i > 0; i--)
228 if (ltrimmed[i - 1] !=
' ')
230 ltrimmed[i - 1] =
'\0';
232 ltrimmed_len = strlen (ltrimmed);
233 if (ltrimmed[ltrimmed_len - 1] ==
'\n')
234 ltrimmed[ltrimmed_len - 1] =
' ';
251 unsigned int ttl_tmp;
253 next = strchr (token,
';');
256 next = strchr (token,
' ');
259 if (1 != sscanf (token,
"%u", &ttl_tmp))
261 fprintf (stderr,
"Unable to parse TTL `%s'\n", token);
273 next = strchr (token,
';');
276 next = strchr (token,
' ');
310 "$ORIGIN %s does not exist, creating...\n",
ego_name);
329 _ (
"Failed to store records...\n"));
341 "Changing origin to %s\n",
ego_name);
381 int bracket_unclosed = 0;
387 while ((
res = fgets (
buf,
sizeof(
buf), stdin)))
393 "Trimmed line (bracket %s): `%s'\n",
394 (bracket_unclosed > 0) ?
"unclosed" :
"closed",
396 if ((0 == strlen (token)) ||
397 ((1 == strlen (token)) && (
' ' == *token)))
399 if (bracket_unclosed == 0)
404 next = strchr (token,
' ');
407 fprintf (stderr,
"Error at line %u: %s\n", ln, token);
414 if (0 == (strcmp (token,
"$ORIGIN")))
419 else if (0 == (strcmp (token,
"$TTL")))
426 if (0 == strcmp (token,
"IN"))
429 "Old name: %s\n", lastname);
430 strcpy (newname, lastname);
431 token[strlen (token)] =
' ';
433 else if (token[strlen (token) - 1] !=
'.')
439 _ (
"Name `%s' is too long\n"),
445 strcpy (newname, token);
448 else if (0 == strcmp (token,
origin))
451 strcpy (newname,
"@");
456 if (strlen (token) < strlen (
origin))
458 fprintf (stderr,
"Wrong origin: %s (expected %s)\n", token,
origin);
461 if (0 != strcmp (token + (strlen (token) - strlen (
origin)),
origin))
463 fprintf (stderr,
"Wrong origin: %s (expected %s)\n", token,
origin);
466 token[strlen (token) - strlen (
origin) - 1] =
'\0';
471 _ (
"Name `%s' is too long\n"),
477 strcpy (newname, token);
480 if (0 != strcmp (newname, lastname) &&
484 "Name changed %s->%s, storing record set of %u elements\n",
490 strcpy (lastname, newname);
498 fprintf (stderr,
_ (
"Failed to parse $TTL\n"));
509 fprintf (stderr,
_ (
"Failed to parse $ORIGIN from %s\n"), token);
520 "You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n"));
529 _ (
"Only %u records per unique name supported.\n"),
537 next = strchr (token,
' ');
540 fprintf (stderr,
"Error, last token: %s\n", token);
551 next = strchr (token,
' ');
554 fprintf (stderr,
"Error\n");
566 for (
int i = 0; i < strlen (token); i++)
570 if ((token[i] ==
'(') && ! quoted)
572 if ((token[i] ==
')') && ! quoted)
575 memcpy (payload_pos, token, strlen (token));
576 payload_pos += strlen (token);
577 if (bracket_unclosed > 0)
591 _ (
"Data `%s' invalid\n"),
623 strcpy (lastname, newname);
638 "Changing origin to %s\n",
ego_name);
643 printf (
"Published %u records sets with total %u records\n",
657 _ (
"Ego `%s' not known to identity service\n"),
676 _ (
"Ego `%s' not known to identity service\n"),
705 _ (
"Failed to connect to NAMESTORE\n"));
712 _ (
"Failed to connect to IDENTITY\n"));
731 main (
int argc,
char *
const *argv)
738 "name of the ego controlling the zone"),
751 "gnunet-namestore-zonefile",
753 "GNUnet namestore database manipulation tool"),
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
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).
#define gettext_noop(String)
static size_t data_size
Number of bytes in data.
static char * line
Desired phone line (string to be converted to a hash).
uint32_t data
The data value.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_NAMESTORE_QueueEntry * ns_qe
Queue entry for the 'add' operation.
static int parse_ttl(char *token, struct GNUNET_TIME_Relative *ttl)
static struct GNUNET_IDENTITY_Operation * id_op
Origin create operations.
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 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_IDENTITY_PrivateKey *pk, enum GNUNET_ErrorCode ec)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Current configurataion.
static void tx_end(void *cls, enum GNUNET_ErrorCode ec)
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 void tx_start(void *cls, enum GNUNET_ErrorCode ec)
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.
int main(int argc, char *const *argv)
The main function for gnunet-namestore-dbtool.
static char * trim(char *line)
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 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?
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.
@ 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.
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...
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.
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.
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.
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_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
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.
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
#define GNUNET_log(kind,...)
int 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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_begin(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
New API draft.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
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_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_commit(struct GNUNET_NAMESTORE_Handle *h, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Commit a namestore transaction.
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,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
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.
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.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
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.
A private key for an identity as per LSD0001.
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model