GNUnet  0.10.x
Functions | Variables
gnunet-gns.c File Reference

binary version of gnunet-gns-import.sh (for OSes that have no POSIX shell). More...

#include "platform.h"
#include <gnunet_util_lib.h>
#include <gnunet_dnsparser_lib.h>
#include <gnunet_gnsrecord_lib.h>
#include <gnunet_namestore_service.h>
#include <gnunet_gns_service.h>
Include dependency graph for gnunet-gns.c:

Go to the source code of this file.

Functions

static void do_shutdown (void *cls)
 Task run on shutdown. More...
 
static void do_timeout (void *cls)
 Task to run on timeout. More...
 
static void process_lookup_result (void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Function called with the result of a GNS lookup. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function for gnunet-gns. More...
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Configuration we are using. More...
 
static struct GNUNET_GNS_Handlegns
 Handle to GNS service. More...
 
static char * lookup_name
 GNS name to lookup. More...
 
static char * lookup_type
 record type to look up (-t option) More...
 
static int raw
 raw output More...
 
static uint32_t rtype
 Desired record type. More...
 
static struct GNUNET_TIME_Relative timeout
 Timeout for lookup. More...
 
static struct GNUNET_SCHEDULER_Taskto_task
 Timeout task. More...
 
static struct GNUNET_GNS_LookupWithTldRequestlr
 Handle to lookup request. More...
 
static int global_ret
 Global return value. More...
 

Detailed Description

binary version of gnunet-gns-import.sh (for OSes that have no POSIX shell).

command line tool to access distributed GNS

Author
LRN
Christian Grothoff

Definition in file gnunet-gns.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

Definition at line 93 of file gnunet-gns.c.

References GNUNET_GNS_disconnect(), GNUNET_GNS_lookup_with_tld_cancel(), and GNUNET_SCHEDULER_cancel().

Referenced by run().

94 {
95  (void)cls;
96  if (NULL != to_task)
97  {
99  to_task = NULL;
100  }
101  if (NULL != lr)
102  {
104  lr = NULL;
105  }
106  if (NULL != gns)
107  {
109  gns = NULL;
110  }
111 }
static struct GNUNET_GNS_LookupWithTldRequest * lr
Handle to lookup request.
Definition: gnunet-gns.c:75
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:328
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
Definition: gnunet-gns.c:40
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:282
static struct GNUNET_SCHEDULER_Task * to_task
Timeout task.
Definition: gnunet-gns.c:70
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Task to run on timeout.

Parameters
clsunused

Definition at line 119 of file gnunet-gns.c.

References global_ret, and GNUNET_SCHEDULER_shutdown().

Referenced by run().

120 {
121  to_task = NULL;
122  global_ret = 3; //Timeout
124 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
static struct GNUNET_SCHEDULER_Task * to_task
Timeout task.
Definition: gnunet-gns.c:70
static int global_ret
Global return value.
Definition: gnunet-gns.c:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_lookup_result()

static void process_lookup_result ( void *  cls,
int  was_gns,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Function called with the result of a GNS lookup.

Parameters
clsthe 'const char *' name that was resolved
was_gnsGNUNET_NO if TLD did not indicate use of GNS
rd_countnumber of records returned
rdarray of rd_count records with the results

Definition at line 135 of file gnunet-gns.c.

References data, data_size, global_ret, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_value_to_string(), GNUNET_NO, GNUNET_SCHEDULER_shutdown(), name, raw, and rtype.

Referenced by run().

139 {
140  const char *name = cls;
141  const char *typename;
142  char *string_val;
143 
144  lr = NULL;
145  if (GNUNET_NO == was_gns)
146  {
147  global_ret = 4; /* not for GNS */
149  return;
150  }
151  if (!raw)
152  {
153  if (0 == rd_count)
154  printf("No results.\n");
155  else
156  printf("%s:\n", name);
157  }
158  for (uint32_t i = 0; i < rd_count; i++)
159  {
160  if ((rd[i].record_type != rtype) && (GNUNET_GNSRECORD_TYPE_ANY != rtype))
161  continue;
162  typename = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type);
163  string_val = GNUNET_GNSRECORD_value_to_string(rd[i].record_type,
164  rd[i].data,
165  rd[i].data_size);
166  if (NULL == string_val)
167  {
168  fprintf(stderr,
169  "Record %u of type %d malformed, skipping\n",
170  (unsigned int)i,
171  (int)rd[i].record_type);
172  continue;
173  }
174  if (raw)
175  printf("%s\n", string_val);
176  else
177  printf("Got `%s' record: %s\n", typename, string_val);
178  GNUNET_free(string_val);
179  }
181 }
static int raw
raw output
Definition: gnunet-gns.c:55
static struct GNUNET_GNS_LookupWithTldRequest * lr
Handle to lookup request.
Definition: gnunet-gns.c:75
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
const char * name
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:142
static size_t data_size
Number of bytes in data.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number (i.e.
Definition: gnsrecord.c:230
static uint32_t rtype
Desired record type.
Definition: gnunet-gns.c:60
#define GNUNET_free(ptr)
Wrapper around free.
static int global_ret
Global return value.
Definition: gnunet-gns.c:84
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 c 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 193 of file gnunet-gns.c.

References _, do_shutdown(), do_timeout(), global_ret, GNUNET_DNSPARSER_check_name(), GNUNET_DNSPARSER_TYPE_A, GNUNET_GNS_connect(), GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup_with_tld(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), lookup_name, lookup_type, process_lookup_result(), rtype, and timeout.

Referenced by main().

197 {
198  (void)cls;
199  (void)args;
200  (void)cfgfile;
201 
202  cfg = c;
203  to_task = NULL;
205  {
206  fprintf(stderr, _("`%s' is not a valid domain name\n"), lookup_name);
207  global_ret = 3;
208  return;
209  }
212  if (NULL == gns)
213  {
214  fprintf(stderr, _("Failed to connect to GNS\n"));
215  global_ret = 2;
216  return;
217  }
219  if (NULL != lookup_type)
221  else
223  if (UINT32_MAX == rtype)
224  {
225  fprintf(stderr, _("Invalid typename specified, assuming `ANY'\n"));
227  }
229  lookup_name,
230  rtype,
233  lookup_name);
234  if (NULL == lr)
235  {
236  global_ret = 2;
238  return;
239  }
240 }
static struct GNUNET_GNS_LookupWithTldRequest * lr
Handle to lookup request.
Definition: gnunet-gns.c:75
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (i.e.
Definition: gnsrecord.c:203
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
Definition: gns_tld_api.c:240
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1237
static struct GNUNET_TIME_Relative timeout
Timeout for lookup.
Definition: gnunet-gns.c:65
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
Definition: gnunet-gns.c:40
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:260
static struct GNUNET_SCHEDULER_Task * to_task
Timeout task.
Definition: gnunet-gns.c:70
static void do_shutdown(void *cls)
Task run on shutdown.
Definition: gnunet-gns.c:93
static void do_timeout(void *cls)
Task to run on timeout.
Definition: gnunet-gns.c:119
int GNUNET_DNSPARSER_check_name(const char *name)
Check if a hostname in UTF-8 format can be coded into valid IDNA.
Definition: dnsparser.c:79
static char * lookup_name
GNS name to lookup.
Definition: gnunet-gns.c:45
static void process_lookup_result(void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called with the result of a GNS lookup.
Definition: gnunet-gns.c:135
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-gns.c:35
Defaults, look in cache, then in DHT.
static uint32_t rtype
Desired record type.
Definition: gnunet-gns.c:60
#define GNUNET_DNSPARSER_TYPE_A
static char * lookup_type
record type to look up (-t option)
Definition: gnunet-gns.c:50
static int global_ret
Global return value.
Definition: gnunet-gns.c:84
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-gns.

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

Definition at line 251 of file gnunet-gns.c.

References _, gettext_noop, global_ret, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_mandatory(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_TIME_UNIT_FOREVER_REL, lookup_name, lookup_type, raw, ret, run(), and timeout.

252 {
257  "lookup",
258  "NAME",
259  gettext_noop(
260  "Lookup a record for the given name"),
261  &lookup_name)),
263  "type",
264  "TYPE",
265  gettext_noop(
266  "Specify the type of the record to lookup"),
267  &lookup_type),
269  "timeout",
270  "TIMEOUT",
271  gettext_noop(
272  "Specify a timeout for the lookup"),
273  &timeout),
275  "raw",
276  gettext_noop("No unneeded output"),
277  &raw),
279  int ret;
280 
281  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
282  return 2;
283 
284  GNUNET_log_setup("gnunet-gns", "WARNING", NULL);
285  ret = GNUNET_PROGRAM_run(argc,
286  argv,
287  "gnunet-gns",
288  _("GNUnet GNS resolver tool"),
289  options,
290  &run,
291  NULL);
292  GNUNET_free((void *)argv);
293  if (GNUNET_OK != ret)
294  return 1;
295  return global_ret;
296 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time)...
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
Definition: gnunet-gns.c:193
static int raw
raw output
Definition: gnunet-gns.c:55
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_TIME_Relative timeout
Timeout for lookup.
Definition: gnunet-gns.c:65
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
static char * lookup_name
GNS name to lookup.
Definition: gnunet-gns.c:45
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
int 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, parse options).
Definition: program.c:367
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free(ptr)
Wrapper around free.
static char * lookup_type
record type to look up (-t option)
Definition: gnunet-gns.c:50
#define gettext_noop(String)
Definition: gettext.h:69
static int global_ret
Global return value.
Definition: gnunet-gns.c:84
Here is the call graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration we are using.

Definition at line 35 of file gnunet-gns.c.

◆ gns

struct GNUNET_GNS_Handle* gns
static

Handle to GNS service.

Definition at line 40 of file gnunet-gns.c.

◆ lookup_name

char* lookup_name
static

GNS name to lookup.

(-u option)

Definition at line 45 of file gnunet-gns.c.

Referenced by main(), and run().

◆ lookup_type

char* lookup_type
static

record type to look up (-t option)

Definition at line 50 of file gnunet-gns.c.

Referenced by main(), and run().

◆ raw

int raw
static

◆ rtype

uint32_t rtype
static

Desired record type.

Definition at line 60 of file gnunet-gns.c.

Referenced by process_lookup_result(), and run().

◆ timeout

struct GNUNET_TIME_Relative timeout
static

Timeout for lookup.

Definition at line 65 of file gnunet-gns.c.

Referenced by main(), and run().

◆ to_task

struct GNUNET_SCHEDULER_Task* to_task
static

Timeout task.

Definition at line 70 of file gnunet-gns.c.

◆ lr

Handle to lookup request.

Definition at line 75 of file gnunet-gns.c.

Referenced by db_read_whitelist(), GNUNET_GNS_lookup(), and handle_result().

◆ global_ret

int global_ret
static

Global return value.

0 on success (default), 1 on internal failures 2 on launch failure, 4 if the name is not a GNS-supported TLD,

Definition at line 84 of file gnunet-gns.c.

Referenced by do_timeout(), main(), process_lookup_result(), and run().