GNUnet  0.11.x
Data Structures | Functions | Variables
gnunet-bcd.c File Reference

HTTP server to create GNS business cards. More...

#include "platform.h"
#include <microhttpd.h>
#include "gnunet_util_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_mhd_compat.h"
Include dependency graph for gnunet-bcd.c:

Go to the source code of this file.

Data Structures

struct  StaticResource
 
struct  ParameterMap
 

Functions

static void do_shutdown (void *cls)
 Task ran at shutdown to clean up everything. More...
 
static void do_httpd (void *cls)
 Called when the HTTP server has some pending operations. More...
 
static void run_httpd (void)
 Schedule a task to run MHD. More...
 
static MHD_RESULT create_response (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr)
 Send a response back to a connected client. More...
 
static struct StaticResourceopen_static_resource (const char *name, const char *basedir)
 Open a file on disk and generate a response for it. 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 struct MHD_Daemon * httpd = NULL
 Handle to the HTTP server as provided by libmicrohttpd. More...
 
static struct GNUNET_SCHEDULER_Taskhttpd_task = NULL
 Our primary task for the HTTPD. More...
 
static struct StaticResourceindex_simple = NULL
 Index file resource (simple result). More...
 
static struct StaticResourceindex_full = NULL
 Index file resource (full result). More...
 
static struct StaticResourcekey_error = NULL
 Error: invalid gns key. More...
 
static struct StaticResourcenotfound_error = NULL
 Error: 404. More...
 
static struct StaticResourceinternal_error = NULL
 Errors after receiving the form data. More...
 
static struct StaticResourceforbidden_error = NULL
 Other errors. More...
 
static char * tex_file_simple = NULL
 Full path to the TeX template file (simple result) More...
 
static char * tex_file_full = NULL
 Full path to the TeX template file (full result) More...
 
static char * tex_file_png = NULL
 Full path to the TeX template file (PNG result) More...
 
static int continue_100 = 100
 Used as a sort of singleton to send exactly one 100 CONTINUE per request. More...
 
static const struct ParameterMap pmap []
 Map of names with TeX definitions, used during PDF generation. More...
 
static uint16_t port = 8888
 Port number. More...
 

Detailed Description

HTTP server to create GNS business cards.

Author
Christian Grothoff

Definition in file gnunet-bcd.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task ran at shutdown to clean up everything.

Parameters
clsunused

Definition at line 155 of file gnunet-bcd.c.

156 {
157  /* We cheat a bit here: the file descriptor is implicitly closed by MHD, so
158  calling `GNUNET_DISK_file_close' would generate a spurious warning message
159  in the log. Since that function does nothing but close the descriptor and
160  free the allocated memory, After destroying the response all that's left to
161  do is call `GNUNET_free'. */
162  if (NULL != index_simple)
163  {
164  MHD_destroy_response (index_simple->response);
167  }
168  if (NULL != index_full)
169  {
170  MHD_destroy_response (index_full->response);
173  }
174  if (NULL != key_error)
175  {
176  MHD_destroy_response (key_error->response);
179  }
180  if (NULL != notfound_error)
181  {
182  MHD_destroy_response (notfound_error->response);
185  }
186  if (NULL != internal_error)
187  {
188  MHD_destroy_response (internal_error->response);
191  }
192  if (NULL != forbidden_error)
193  {
194  MHD_destroy_response (forbidden_error->response);
197  }
198 
199  if (NULL != httpd_task)
200  {
202  }
203  if (NULL != httpd)
204  {
205  MHD_stop_daemon (httpd);
206  }
207 }
static struct StaticResource * key_error
Error: invalid gns key.
Definition: gnunet-bcd.c:87
static struct StaticResource * index_full
Index file resource (full result).
Definition: gnunet-bcd.c:82
static struct MHD_Daemon * httpd
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:67
static struct StaticResource * forbidden_error
Other errors.
Definition: gnunet-bcd.c:102
static struct StaticResource * index_simple
Index file resource (simple result).
Definition: gnunet-bcd.c:77
static struct GNUNET_SCHEDULER_Task * httpd_task
Our primary task for the HTTPD.
Definition: gnunet-bcd.c:72
static struct StaticResource * internal_error
Errors after receiving the form data.
Definition: gnunet-bcd.c:97
static struct StaticResource * notfound_error
Error: 404.
Definition: gnunet-bcd.c:92
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
struct MHD_Response * response
Cached response object to send to clients.
Definition: gnunet-bcd.c:48
struct GNUNET_DISK_FileHandle * handle
Handle to file on disk.
Definition: gnunet-bcd.c:38

References forbidden_error, GNUNET_free, GNUNET_SCHEDULER_cancel(), StaticResource::handle, httpd, httpd_task, index_full, index_simple, internal_error, key_error, notfound_error, and StaticResource::response.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_httpd()

static void do_httpd ( void *  cls)
static

Called when the HTTP server has some pending operations.

Parameters
clsunused

Definition at line 267 of file gnunet-bcd.c.

268 {
269  httpd_task = NULL;
270  MHD_run (httpd);
271  run_httpd ();
272 }
static void run_httpd(void)
Schedule a task to run MHD.
Definition: gnunet-bcd.c:221

References httpd, httpd_task, and run_httpd().

Referenced by run_httpd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_httpd()

static void run_httpd ( void  )
static

Schedule a task to run MHD.

Definition at line 221 of file gnunet-bcd.c.

222 {
223  fd_set rs;
224  fd_set ws;
225  fd_set es;
226 
230 
231  FD_ZERO (&rs);
232  FD_ZERO (&ws);
233  FD_ZERO (&es);
234 
235  int max = -1;
236  GNUNET_assert (MHD_YES == MHD_get_fdset (httpd, &rs, &ws, &es, &max));
237 
238  unsigned MHD_LONG_LONG timeout = 0;
240  if (MHD_YES == MHD_get_timeout (httpd, &timeout))
241  {
243  timeout);
244  }
245 
246  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
247  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
248  GNUNET_NETWORK_fdset_copy_native (ges, &es, max + 1);
249 
251  gtime,
252  grs,
253  gws,
254  &do_httpd,
255  NULL);
259 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static void do_httpd(void *cls)
Called when the HTTP server has some pending operations.
Definition: gnunet-bcd.c:267
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1192
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1208
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1062
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1841
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:453
#define max(x, y)
collection of IO descriptors
Time for relative time used by GNUnet, in microseconds.

References do_httpd(), GNUNET_assert, GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_MILLISECONDS, httpd, httpd_task, max, and timeout.

Referenced by do_httpd(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_response()

static MHD_RESULT create_response ( void *  cls,
struct MHD_Connection *  connection,
const char *  url,
const char *  method,
const char *  version,
const char *  upload_data,
size_t *  upload_data_size,
void **  ptr 
)
static

Send a response back to a connected client.

Parameters
clsunused
connectionthe connection with the client
urlthe requested address
methodthe HTTP method used
versionthe protocol version (including the "HTTP/" part)
upload_datadata sent with a POST request
upload_data_sizelength in bytes of the POST data
ptrused to pass data between request handling phases
Returns
MHD_NO on error

Definition at line 288 of file gnunet-bcd.c.

296 {
297  (void) cls;
298  (void) version;
299  (void) upload_data;
300  (void) upload_data_size;
301 
302  bool isget = (0 == strcmp (method, MHD_HTTP_METHOD_GET));
303  bool ishead = (0 == strcmp (method, MHD_HTTP_METHOD_HEAD));
304 
305  if (!isget && !ishead)
306  {
307  return MHD_queue_response (connection,
308  MHD_HTTP_NOT_IMPLEMENTED,
310  }
311 
312  if (ishead)
313  {
314  /* Dedicated branch in case we want to provide a different result for some
315  reason (e.g. a non-web browser application using the web UI) */
316  return MHD_queue_response (connection,
317  MHD_HTTP_OK,
319  }
320 
321  /* Send a 100 CONTINUE response to tell clients that the result of the
322  request might take some time */
323  if (NULL == *ptr)
324  {
325  *ptr = &continue_100;
326  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE\n");
327  return MHD_YES;
328  }
329 
330  if (0 == strcmp ("/", url))
331  {
332  return MHD_queue_response (connection,
333  MHD_HTTP_OK,
335  }
336 
337  if (0 == strcmp ("/full", url))
338  {
339  return MHD_queue_response (connection,
340  MHD_HTTP_OK,
342  }
343 
344  bool isfull = (0 == strcmp ("/submit/full", url));
345  bool issimple = (0 == strcmp ("/submit/simple", url));
346 
347  if (!isfull && !issimple)
348  {
349  return MHD_queue_response (connection,
350  MHD_HTTP_NOT_FOUND,
352  }
353 
354  const char *gpgfp = MHD_lookup_connection_value (connection,
355  MHD_GET_ARGUMENT_KIND,
356  "gpgfingerprint");
357  const char *gnsnick = MHD_lookup_connection_value (connection,
358  MHD_GET_ARGUMENT_KIND,
359  "gnsnick");
360  const char *gnskey = MHD_lookup_connection_value (connection,
361  MHD_GET_ARGUMENT_KIND,
362  "gnskey");
363  const char *qrpng = MHD_lookup_connection_value (connection,
364  MHD_GET_ARGUMENT_KIND,
365  "gnspng");
366 
368  if (NULL == gnskey
370  {
371  return MHD_queue_response (connection,
372  MHD_HTTP_BAD_REQUEST,
374  }
375 
376  char *tmpd = GNUNET_DISK_mkdtemp (gnskey);
377  if (NULL == tmpd)
378  {
380  return MHD_queue_response (connection,
381  MHD_HTTP_INTERNAL_SERVER_ERROR,
383  }
384 
385  char *defpath = NULL;
386  GNUNET_asprintf (&defpath, "%s%s%s", tmpd, DIR_SEPARATOR_STR, "def.tex");
387 
388  FILE *deffile = fopen (defpath, "w");
389  if (NULL == deffile)
390  {
392  GNUNET_free (defpath);
394  GNUNET_free (tmpd);
395  return MHD_queue_response (connection,
396  MHD_HTTP_INTERNAL_SERVER_ERROR,
398  }
399 
400  GNUNET_free (defpath);
401 
402  for (size_t i=0; NULL!=pmap[i].name; ++i)
403  {
404  const char *value = MHD_lookup_connection_value (connection,
405  MHD_GET_ARGUMENT_KIND,
406  pmap[i].name);
407  fprintf (deffile,
408  "\\def\\%s{%s}\n",
409  pmap[i].definition,
410  (NULL == value) ? "" : value);
411  }
412 
413  if (NULL != gpgfp)
414  {
415  size_t len = strlen (gpgfp);
416  char *line1 = GNUNET_strndup (gpgfp, len/2);
417  char *line2 = GNUNET_strdup (&gpgfp[len/2]);
418  fprintf (deffile,
419  "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n",
420  line1,
421  line2);
422  }
423 
424  fprintf (deffile,
425  "\\def\\gns{%s/%s}\n",
426  gnskey,
427  (NULL == gnsnick) ? "" : gnsnick);
428 
429  fclose (deffile);
430 
431  char *command = NULL;
432  GNUNET_asprintf (&command,
433  "cd %s; cp %s gns-bcd.tex; "
434  "pdflatex %s gns-bcd.tex >/dev/null 2>&1",
435  tmpd,
436  (isfull) ? tex_file_full :
437  ((NULL == qrpng) ? tex_file_simple : tex_file_png),
438  (NULL == qrpng) ? "" : "-shell-escape");
439 
440  int ret = system (command);
441 
442  GNUNET_free (command);
443 
444  if (WIFSIGNALED (ret) || 0 != WEXITSTATUS (ret))
445  {
447  }
448 
449  GNUNET_asprintf (&defpath,
450  "%s%s%s",
451  tmpd,
453  (NULL == qrpng) ? "gns-bcd.pdf" : "gns-bcd.png");
454 
455  int pdf = open (defpath, O_RDONLY);
456  if (-1 == pdf)
457  {
459  GNUNET_free (defpath);
461  GNUNET_free (tmpd);
462  return MHD_queue_response (connection,
463  MHD_HTTP_INTERNAL_SERVER_ERROR,
465  }
466 
467  struct stat statret;
468  GNUNET_break (0 == stat (defpath, &statret));
469 
470  GNUNET_free (defpath);
471 
472  struct MHD_Response *pdfrs =
473  MHD_create_response_from_fd ((size_t) statret.st_size, pdf);
474  if (NULL == pdfrs)
475  {
476  GNUNET_break (0);
477  GNUNET_break (0 == close (pdf));
479  GNUNET_free (tmpd);
480  return MHD_queue_response (connection,
481  MHD_HTTP_INTERNAL_SERVER_ERROR,
483  }
484 
485  MHD_add_response_header (pdfrs,
486  MHD_HTTP_HEADER_CONTENT_TYPE,
487  (NULL == qrpng) ? "application/pdf" : "image/png");
488  MHD_add_response_header (pdfrs,
489  MHD_HTTP_HEADER_CONTENT_DISPOSITION,
490  (NULL == qrpng) ?
491  "attachment; filename=\"gns-business-card.pdf\"" :
492  "attachment; filename=\"gns-qr-code.png\"");
493  MHD_RESULT r = MHD_queue_response (connection, MHD_HTTP_OK, pdfrs);
494 
495  MHD_destroy_response (pdfrs);
497  GNUNET_free (tmpd);
498 
499  return r;
500 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * tex_file_full
Full path to the TeX template file (full result)
Definition: gnunet-bcd.c:112
static int continue_100
Used as a sort of singleton to send exactly one 100 CONTINUE per request.
Definition: gnunet-bcd.c:122
static const struct ParameterMap pmap[]
Map of names with TeX definitions, used during PDF generation.
Definition: gnunet-bcd.c:127
static char * tex_file_png
Full path to the TeX template file (PNG result)
Definition: gnunet-bcd.c:117
static char * tex_file_simple
Full path to the TeX template file (simple result)
Definition: gnunet-bcd.c:107
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static char * value
Value of the record to add/remove.
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
#define MHD_RESULT
Data type to use for functions return an "MHD result".
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1085
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:340
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define DIR_SEPARATOR_STR
Definition: platform.h:165
const char * name
An identity key as per LSD0001.
char * name
Name of the parameter from the request.
Definition: gnunet-bcd.c:56

References continue_100, DIR_SEPARATOR_STR, forbidden_error, GNUNET_asprintf(), GNUNET_break, GNUNET_DISK_directory_remove(), GNUNET_DISK_mkdtemp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_IDENTITY_public_key_from_string(), GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_strdup, GNUNET_strndup, index_full, index_simple, internal_error, key_error, len, MHD_RESULT, name, ParameterMap::name, notfound_error, pk, pmap, StaticResource::response, ret, tex_file_full, tex_file_png, tex_file_simple, and value.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_static_resource()

static struct StaticResource* open_static_resource ( const char *  name,
const char *  basedir 
)
static

Open a file on disk and generate a response for it.

Parameters
namename of the file to open
basedirdirectory where the file is located
Returns
NULL on error

Definition at line 510 of file gnunet-bcd.c.

511 {
512  char *fullname = NULL;
513  GNUNET_asprintf (&fullname, "%s%s%s", basedir, DIR_SEPARATOR_STR, name);
514 
515  struct GNUNET_DISK_FileHandle *f =
516  GNUNET_DISK_file_open (fullname,
519 
520  GNUNET_free (fullname);
521 
522  if (NULL == f)
523  {
524  return NULL;
525  }
526 
527  off_t size = 0;
529  {
531  return NULL;
532  }
533 
534  struct MHD_Response *response = MHD_create_response_from_fd64 (size, f->fd);
535 
536  if (NULL == response)
537  {
539  return NULL;
540  }
541 
542  struct StaticResource *res = GNUNET_new (struct StaticResource);
543  res->handle = f;
544  res->size = (uint64_t) size;
545  res->response = response;
546 
547  return res;
548 }
static int res
static struct MHD_Response * response
Our canonical response.
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1235
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:193
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle used to access files (and pipes).

References DIR_SEPARATOR_STR, removetrailingwhitespace::f, GNUNET_asprintf(), GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_free, GNUNET_new, GNUNET_SYSERR, name, res, response, and size.

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 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 559 of file gnunet-bcd.c.

563 {
564  (void) cls;
565  (void) args;
566  (void) cfgfile;
567 
568  if (0 == port)
569  {
571  _ ("Invalid port number %u\n"),
572  port);
574  return;
575  }
576 
578 
580  GNUNET_assert (NULL != datadir);
581 
583  "%s%s%s",
584  datadir,
586  "gns-bcd.tex");
588  "%s%s%s",
589  datadir,
591  "gns-bcd-simple.tex");
593  "%s%s%s",
594  datadir,
596  "gns-bcd-png.tex");
597 
598  index_simple = open_static_resource ("gns-bcd-simple.html", datadir);
599  index_full = open_static_resource ("gns-bcd.html", datadir);
600  key_error = open_static_resource ("gns-bcd-invalid-key.html", datadir);
601  notfound_error = open_static_resource ("gns-bcd-not-found.html", datadir);
602  internal_error = open_static_resource ("gns-bcd-internal-error.html", datadir);
603  forbidden_error = open_static_resource ("gns-bcd-forbidden.html", datadir);
604 
605  GNUNET_free (datadir);
606 
607  if ((NULL == index_simple) || (NULL == index_full)
608  || (NULL == key_error) || (NULL == notfound_error)
609  || (NULL == internal_error) || (NULL == forbidden_error))
610  {
612  _ ("Unable to set up the daemon\n"));
614  return;
615  }
616 
617  int flags = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
618  do
619  {
620  httpd = MHD_start_daemon (flags,
621  port,
622  NULL, NULL,
623  &create_response, NULL,
624  MHD_OPTION_CONNECTION_LIMIT, 512,
625  MHD_OPTION_PER_IP_CONNECTION_LIMIT, 2,
626  MHD_OPTION_CONNECTION_TIMEOUT, 60,
627  MHD_OPTION_CONNECTION_MEMORY_LIMIT, 16 * 1024,
628  MHD_OPTION_END);
629  flags = MHD_USE_DEBUG;
630  } while (NULL == httpd && flags != MHD_USE_DEBUG);
631 
632  if (NULL == httpd)
633  {
635  _ ("Failed to start HTTP server\n"));
637  return;
638  }
639 
640  run_httpd ();
641 }
static MHD_RESULT create_response(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr)
Send a response back to a connected client.
Definition: gnunet-bcd.c:288
static void do_shutdown(void *cls)
Task ran at shutdown to clean up everything.
Definition: gnunet-bcd.c:155
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static struct StaticResource * open_static_resource(const char *name, const char *basedir)
Open a file on disk and generate a response for it.
Definition: gnunet-bcd.c:510
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
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:1331
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

References _, consensus-simulation::args, create_response(), DIR_SEPARATOR_STR, do_shutdown(), forbidden_error, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), httpd, index_full, index_simple, internal_error, key_error, notfound_error, open_static_resource(), port, run_httpd(), tex_file_full, tex_file_png, and tex_file_simple.

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-gns.

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

Definition at line 651 of file gnunet-bcd.c.

652 {
655  'p',
656  "port",
657  "PORT",
658  gettext_noop ("Run HTTP server on port PORT (default is 8888)"),
659  &port),
661  };
662 
663  return ((GNUNET_OK ==
664  GNUNET_PROGRAM_run (argc,
665  argv,
666  "gnunet-bcd",
667  _ ("GNUnet HTTP server to create business cards"),
668  options,
669  &run,
670  NULL))
671  ? 0
672  : 1);
673 }
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:69
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-bcd.c:559
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint16(char shortName, const char *name, const char *argumentHelp, const char *description, uint16_t *val)
Allow user to specify an uint16_t.
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:399
Definition of a command line option.

References _, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_uint16(), GNUNET_OK, GNUNET_PROGRAM_run(), options, port, and run().

Here is the call graph for this function:

Variable Documentation

◆ httpd

struct MHD_Daemon* httpd = NULL
static

Handle to the HTTP server as provided by libmicrohttpd.

Definition at line 67 of file gnunet-bcd.c.

Referenced by do_httpd(), do_shutdown(), run(), and run_httpd().

◆ httpd_task

struct GNUNET_SCHEDULER_Task* httpd_task = NULL
static

Our primary task for the HTTPD.

Definition at line 72 of file gnunet-bcd.c.

Referenced by do_httpd(), do_shutdown(), and run_httpd().

◆ index_simple

struct StaticResource* index_simple = NULL
static

Index file resource (simple result).

Definition at line 77 of file gnunet-bcd.c.

Referenced by create_response(), do_shutdown(), and run().

◆ index_full

struct StaticResource* index_full = NULL
static

Index file resource (full result).

Definition at line 82 of file gnunet-bcd.c.

Referenced by create_response(), do_shutdown(), and run().

◆ key_error

struct StaticResource* key_error = NULL
static

Error: invalid gns key.

Definition at line 87 of file gnunet-bcd.c.

Referenced by create_response(), do_shutdown(), and run().

◆ notfound_error

struct StaticResource* notfound_error = NULL
static

Error: 404.

Definition at line 92 of file gnunet-bcd.c.

Referenced by create_response(), do_shutdown(), and run().

◆ internal_error

struct StaticResource* internal_error = NULL
static

Errors after receiving the form data.

Definition at line 97 of file gnunet-bcd.c.

Referenced by create_response(), do_shutdown(), and run().

◆ forbidden_error

struct StaticResource* forbidden_error = NULL
static

Other errors.

Definition at line 102 of file gnunet-bcd.c.

Referenced by create_response(), do_shutdown(), and run().

◆ tex_file_simple

char* tex_file_simple = NULL
static

Full path to the TeX template file (simple result)

Definition at line 107 of file gnunet-bcd.c.

Referenced by create_response(), and run().

◆ tex_file_full

char* tex_file_full = NULL
static

Full path to the TeX template file (full result)

Definition at line 112 of file gnunet-bcd.c.

Referenced by create_response(), and run().

◆ tex_file_png

char* tex_file_png = NULL
static

Full path to the TeX template file (PNG result)

Definition at line 117 of file gnunet-bcd.c.

Referenced by create_response(), and run().

◆ continue_100

int continue_100 = 100
static

Used as a sort of singleton to send exactly one 100 CONTINUE per request.

Definition at line 122 of file gnunet-bcd.c.

Referenced by create_response().

◆ pmap

const struct ParameterMap pmap[]
static
Initial value:
= {
{"prefix", "prefix"},
{"name", "name"},
{"suffix", "suffix"},
{"street", "street"},
{"city", "city"},
{"phone", "phone"},
{"fax", "fax"},
{"email", "email"},
{"homepage", "homepage"},
{"org", "organization"},
{"department", "department"},
{"subdepartment", "subdepartment"},
{"jobtitle", "jobtitle"},
{NULL, NULL},
}

Map of names with TeX definitions, used during PDF generation.

Definition at line 122 of file gnunet-bcd.c.

Referenced by create_response(), and run().

◆ port

uint16_t port = 8888
static

Port number.

Definition at line 147 of file gnunet-bcd.c.

Referenced by advertise_dns_exit(), associate_shared_service(), client_release_ports(), connect_tunnel(), convert_messenger_key_to_port(), create_channel(), destroy_port_cb(), dns_string_to_value(), extract_port(), GC_u2h(), GCCH_bind(), GCCH_channel_local_new(), GCCH_get_id(), GCCH_handle_channel_open_ack(), gen_rsh_args(), get_cadet(), get_server_addresses(), GNUNET_CADET_channel_create(), GNUNET_CADET_open_port(), GNUNET_CLIENT_test(), GNUNET_CONNECTION_create_from_connect(), GNUNET_HOSTLIST_server_start(), GNUNET_NAT_mini_map_start(), GNUNET_NAT_stun_make_request(), GNUNET_NETWORK_test_port_free(), GNUNET_SOCKS_set_handshake_destination(), GNUNET_TESTBED_controller_start(), GNUNET_TESTBED_host_create(), GNUNET_TESTBED_host_create_with_id(), GNUNET_TESTBED_hosts_load_from_file(), GNUNET_TESTBED_is_host_habitable(), GNUNET_TESTING_release_port(), GNUNET_TUN_ipv4toregexsearch(), GNUNET_TUN_ipv6toregexsearch(), GSF_cadet_start_server(), handle_channel_created(), handle_regex_result(), handle_register(), ip_try_connect(), LEGACY_SERVICE_get_server_addresses(), libgnunet_plugin_dhtu_ip_init(), libgnunet_plugin_transport_udp_init(), lookup_hole_external(), main(), nat_server_read(), open_listen_socket(), open_port_cb(), open_room(), process_icmp_response(), process_map_output(), reset_cadet(), run(), server_configure_plugin(), server_get_addresses(), tcp_address_to_sockaddr(), tcp_address_to_sockaddr_numeric_v4(), tcp_address_to_sockaddr_numeric_v6(), tcp_address_to_sockaddr_port_only(), tcp_plugin_address_pretty_printer(), tcp_plugin_address_to_string(), test_service_configuration(), try_open_exit(), udp_address_to_sockaddr(), udp_address_to_string(), and udp_plugin_address_pretty_printer().