GNUnet  0.11.x
Data Structures | Macros | 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 dependency graph for gnunet-bcd.c:

Go to the source code of this file.

Data Structures

struct  Entry
 Entry type to be used in the map to store old latency values. More...
 

Macros

#define INVALID_GNSKEY   "<html><head><title>Error</title><body>Invalid GNS public key given.</body></html>"
 Error page to display if submitted GNS key is invalid. More...
 
#define NOT_FOUND   "<html><head><title>Error</title><body>404 not found</body></html>"
 Error page to display on 404. More...
 

Functions

static int access_handler_callback (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 **con_cls)
 Main request handler. More...
 
static struct GNUNET_SCHEDULER_Taskprepare_daemon (struct MHD_Daemon *daemon_handle)
 Function that queries MHD's select sets and starts the task waiting for them. More...
 
static void run_daemon (void *cls)
 Call MHD to process pending requests and then go back and schedule the next run. More...
 
static int server_start ()
 Start server offering our hostlist. More...
 
static void server_stop (void *cls)
 Stop HTTP server. 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 * daemon_handle
 Handle to the HTTP server as provided by libmicrohttpd. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_SCHEDULER_Taskhttp_task
 Our primary task for the HTTPD. More...
 
static struct MHD_Response * main_response
 Our main website. More...
 
static struct MHD_Response * invalid_gnskey_response
 Error: invalid gns key. More...
 
static struct MHD_Response * not_found_response
 Error: 404. More...
 
static char * resfile
 Absolute name of the 'gns-bcd.tex' file. 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.

Macro Definition Documentation

◆ INVALID_GNSKEY

#define INVALID_GNSKEY   "<html><head><title>Error</title><body>Invalid GNS public key given.</body></html>"

Error page to display if submitted GNS key is invalid.

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

Referenced by run().

◆ NOT_FOUND

#define NOT_FOUND   "<html><head><title>Error</title><body>404 not found</body></html>"

Error page to display on 404.

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

Referenced by run().

Function Documentation

◆ access_handler_callback()

static int access_handler_callback ( 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 **  con_cls 
)
static

Main request handler.

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

References _, daemon_handle, DIR_SEPARATOR_STR, dummy, removetrailingwhitespace::f, Entry::formname, GNUNET_asprintf(), GNUNET_break, GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_DISK_directory_remove(), GNUNET_DISK_mkdtemp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_strdup, GNUNET_strndup, invalid_gnskey_response, main_response, not_found_response, p, prepare_daemon(), resfile, response, ret, and Entry::texname.

Referenced by server_start().

103 {
104  static int dummy;
105  static const struct Entry map[] = { { "prefix", "prefix" },
106  { "name", "name" },
107  { "suffix", "suffix" },
108  { "street", "street" },
109  { "city", "city" },
110  { "phone", "phone" },
111  { "fax", "fax" },
112  { "email", "email" },
113  { "homepage", "homepage" },
114  { "orga", "orga" },
115  { "departmenti18n", "departmentde" },
116  { "departmenten", "departmenten" },
117  { "subdepartmenti18n",
118  "subdepartmentde" },
119  { "subdepartmenten", "subdepartmenten" },
120  { "jobtitlei18n", "jobtitlegerman" },
121  { "jobtitleen", "jobtitleenglish" },
122  { "subdepartmenten", "subdepartmenten" },
123  { NULL, NULL } };
124 
125  (void) cls;
126  (void) version;
127  (void) upload_data;
128  (void) upload_data_size;
129  if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
130  {
132  _ ("Refusing `%s' request to HTTP server\n"),
133  method);
134  return MHD_NO;
135  }
136  if (NULL == *con_cls)
137  {
138  (*con_cls) = &dummy;
139  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n");
140  return MHD_YES; /* send 100 continue */
141  }
142  if (0 == strcasecmp (url, "/"))
143  return MHD_queue_response (connection, MHD_HTTP_OK, main_response);
144  if (0 == strcasecmp (url, "/submit.pdf"))
145  {
146  unsigned int i;
147  char *p;
148  char *tmp;
149  char *deffile;
151  size_t slen;
152  FILE *f;
153  struct stat st;
154  struct MHD_Response *response;
155  int fd;
156  int ret;
157 
158  const char *gpg_fp = MHD_lookup_connection_value (connection,
159  MHD_GET_ARGUMENT_KIND,
160  "gpgfingerprint");
161  const char *gns_nick = MHD_lookup_connection_value (connection,
162  MHD_GET_ARGUMENT_KIND,
163  "gnsnick");
164  const char *gnskey =
165  MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "gnskey");
166  if ((NULL == gnskey) ||
167  (GNUNET_OK !=
169  strlen (gnskey),
170  &pub)))
171  {
172  return MHD_queue_response (connection,
173  MHD_HTTP_OK,
175  }
176  tmp = GNUNET_DISK_mkdtemp (gnskey);
177  if (NULL == tmp)
178  {
180  return MHD_NO;
181  }
182  GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex");
183  f = fopen (deffile, "w");
184  if (NULL == f)
185  {
187  GNUNET_free (deffile);
189  GNUNET_free (tmp);
190  return MHD_NO;
191  }
192  for (i = 0; NULL != map[i].formname; i++)
193  {
194  const char *val = MHD_lookup_connection_value (connection,
195  MHD_GET_ARGUMENT_KIND,
196  map[i].formname);
197  if (NULL != val)
198  fprintf (f, "\\def\\%s{%s}\n", map[i].texname, val);
199  else
200  fprintf (f, "\\def\\%s{}\n", map[i].texname);
201  }
202  if (NULL != gpg_fp)
203  {
204  char *gpg1;
205  char *gpg2;
206 
207  slen = strlen (gpg_fp);
208  gpg1 = GNUNET_strndup (gpg_fp, slen / 2);
209  gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]);
210  fprintf (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
211  GNUNET_free (gpg2);
212  GNUNET_free (gpg1);
213  }
214  fprintf (f,
215  "\\def\\gns{%s/%s}\n",
216  gnskey,
217  (NULL == gns_nick) ? "" : gns_nick);
218  fclose (f);
220  &p,
221  "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
222  tmp,
223  resfile);
224  GNUNET_free (deffile);
225  ret = system (p);
226  if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret)))
228  GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "gns-bcd.pdf");
229  fd = open (deffile, O_RDONLY);
230  if (-1 == fd)
231  {
233  GNUNET_free (deffile);
234  GNUNET_free (p);
236  GNUNET_free (tmp);
237  return MHD_NO;
238  }
239  GNUNET_break (0 == stat (deffile, &st));
240  if (NULL ==
241  (response = MHD_create_response_from_fd ((size_t) st.st_size, fd)))
242  {
243  GNUNET_break (0);
244  GNUNET_break (0 == close (fd));
245  GNUNET_free (deffile);
246  GNUNET_free (p);
248  GNUNET_free (tmp);
249  return MHD_NO;
250  }
251  (void) MHD_add_response_header (response,
252  MHD_HTTP_HEADER_CONTENT_TYPE,
253  "application/pdf");
254  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
255  MHD_destroy_response (response);
256  GNUNET_free (deffile);
257  GNUNET_free (p);
259  GNUNET_free (tmp);
260  return ret;
261  }
262  return MHD_queue_response (connection,
263  MHD_HTTP_NOT_FOUND,
265 }
static struct MHD_Response * invalid_gnskey_response
Error: invalid gns key.
Definition: gnunet-bcd.c:66
static struct MHD_Response * not_found_response
Error: 404.
Definition: gnunet-bcd.c:71
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#define DIR_SEPARATOR_STR
Definition: platform.h:168
int GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1029
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:409
const char * formname
Definition: gnunet-bcd.c:86
static struct MHD_Response * main_response
Our main website.
Definition: gnunet-bcd.c:61
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:466
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
static struct MHD_Response * response
Our canonical response.
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static char * resfile
Absolute name of the &#39;gns-bcd.tex&#39; file.
Definition: gnunet-bcd.c:76
Entry type to be used in the map to store old latency values.
Definition: gnunet-bcd.c:84
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_daemon()

static struct GNUNET_SCHEDULER_Task * prepare_daemon ( struct MHD_Daemon *  daemon_handle)
static

Function that queries MHD's select sets and starts the task waiting for them.

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

References 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_UNIT_FOREVER_REL, GNUNET_TIME_Relative::rel_value_us, ret, run_daemon(), and timeout.

Referenced by access_handler_callback(), run_daemon(), and server_start().

297 {
298  struct GNUNET_SCHEDULER_Task *ret;
299  fd_set rs;
300  fd_set ws;
301  fd_set es;
302  struct GNUNET_NETWORK_FDSet *wrs;
303  struct GNUNET_NETWORK_FDSet *wws;
304  int max;
305  MHD_UNSIGNED_LONG_LONG timeout;
306  int haveto;
307  struct GNUNET_TIME_Relative tv;
308 
309  FD_ZERO (&rs);
310  FD_ZERO (&ws);
311  FD_ZERO (&es);
314  max = -1;
315  GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
316  haveto = MHD_get_timeout (daemon_handle, &timeout);
317  if (haveto == MHD_YES)
318  tv.rel_value_us = (uint64_t) timeout * 1000LL;
319  else
321  GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
322  GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
324  tv,
325  wrs,
326  wws,
327  &run_daemon,
328  daemon_handle);
331  return ret;
332 }
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:46
Run with high priority (important requests).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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:1120
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1266
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
collection of IO descriptors
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:1810
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Entry in list of pending tasks.
Definition: scheduler.c:134
static void run_daemon(void *cls)
Call MHD to process pending requests and then go back and schedule the next run.
Definition: gnunet-bcd.c:281
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_daemon()

static void run_daemon ( void *  cls)
static

Call MHD to process pending requests and then go back and schedule the next run.

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

References daemon_handle, GNUNET_assert, and prepare_daemon().

Referenced by prepare_daemon().

282 {
283  struct MHD_Daemon *daemon_handle = cls;
284 
285  http_task = NULL;
286  GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
287  http_task = prepare_daemon (daemon_handle);
288 }
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:46
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * http_task
Our primary task for the HTTPD.
Definition: gnunet-bcd.c:56
static struct GNUNET_SCHEDULER_Task * prepare_daemon(struct MHD_Daemon *daemon_handle)
Function that queries MHD&#39;s select sets and starts the task waiting for them.
Definition: gnunet-bcd.c:296
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_start()

static int server_start ( )
static

Start server offering our hostlist.

Returns
GNUNET_OK on success

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

References _, access_handler_callback(), daemon_handle, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, port, and prepare_daemon().

Referenced by run().

342 {
343  if (0 == port)
344  {
346  _ ("Invalid port number %u. Exiting.\n"),
347  port);
348  return GNUNET_SYSERR;
349  }
351  _ ("Businesscard HTTP server starts on %u\n"),
352  port);
353  daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG,
354  port,
355  NULL /* accept_policy_callback */,
356  NULL,
358  NULL,
359  MHD_OPTION_CONNECTION_LIMIT,
360  (unsigned int) 512,
361  MHD_OPTION_PER_IP_CONNECTION_LIMIT,
362  (unsigned int) 2,
363  MHD_OPTION_CONNECTION_TIMEOUT,
364  (unsigned int) 60,
365  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
366  (size_t) (16 * 1024),
367  MHD_OPTION_END);
368  if (NULL == daemon_handle)
369  {
371  _ ("Could not start businesscard HTTP server on port %u\n"),
372  (unsigned int) port);
373  return GNUNET_SYSERR;
374  }
376  return GNUNET_OK;
377 }
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:46
static struct GNUNET_SCHEDULER_Task * http_task
Our primary task for the HTTPD.
Definition: gnunet-bcd.c:56
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static int access_handler_callback(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 **con_cls)
Main request handler.
Definition: gnunet-bcd.c:95
static struct GNUNET_SCHEDULER_Task * prepare_daemon(struct MHD_Daemon *daemon_handle)
Function that queries MHD&#39;s select sets and starts the task waiting for them.
Definition: gnunet-bcd.c:296
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_stop()

static void server_stop ( void *  cls)
static

Stop HTTP server.

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

References daemon_handle, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), invalid_gnskey_response, main_response, not_found_response, and resfile.

Referenced by run().

385 {
386  (void) cls;
387  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n");
388  if (NULL != http_task)
389  {
391  http_task = NULL;
392  }
393  if (NULL != daemon_handle)
394  {
395  MHD_stop_daemon (daemon_handle);
396  daemon_handle = NULL;
397  }
398  if (NULL != main_response)
399  {
400  MHD_destroy_response (main_response);
401  main_response = NULL;
402  }
403  if (NULL != invalid_gnskey_response)
404  {
405  MHD_destroy_response (invalid_gnskey_response);
407  }
408  if (NULL != not_found_response)
409  {
410  MHD_destroy_response (not_found_response);
411  not_found_response = NULL;
412  }
413  if (NULL != resfile)
414  {
416  resfile = NULL;
417  }
418 }
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:46
static struct MHD_Response * invalid_gnskey_response
Error: invalid gns key.
Definition: gnunet-bcd.c:66
static struct MHD_Response * not_found_response
Error: 404.
Definition: gnunet-bcd.c:71
static struct GNUNET_SCHEDULER_Task * http_task
Our primary task for the HTTPD.
Definition: gnunet-bcd.c:56
static struct MHD_Response * main_response
Our main website.
Definition: gnunet-bcd.c:61
#define GNUNET_log(kind,...)
static char * resfile
Absolute name of the &#39;gns-bcd.tex&#39; file.
Definition: gnunet-bcd.c:76
#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:966
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 430 of file gnunet-bcd.c.

References dir, DIR_SEPARATOR_STR, fn, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_SCHEDULER_add_shutdown(), INVALID_GNSKEY, invalid_gnskey_response, main_response, NOT_FOUND, not_found_response, resfile, server_start(), and server_stop().

Referenced by main().

434 {
435  struct stat st;
436  char *dir;
437  char *fn;
438  int fd;
439 
440  (void) cls;
441  (void) args;
442  (void) cfgfile;
443  cfg = c;
445  GNUNET_assert (NULL != dir);
446  GNUNET_asprintf (&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html");
447  GNUNET_asprintf (&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex");
448  GNUNET_free (dir);
449  fd = open (fn, O_RDONLY);
450  if (-1 == fd)
451  {
453  GNUNET_free (fn);
454  return;
455  }
456  if (0 != stat (fn, &st))
457  {
459  GNUNET_free (fn);
460  GNUNET_break (0 == close (fd));
461  return;
462  }
463  GNUNET_free (fn);
464  if (NULL ==
465  (main_response = MHD_create_response_from_fd ((size_t) st.st_size, fd)))
466  {
467  GNUNET_break (0);
468  GNUNET_break (0 == close (fd));
469  return;
470  }
471  (void) MHD_add_response_header (main_response,
472  MHD_HTTP_HEADER_CONTENT_TYPE,
473  "text/html");
475  MHD_create_response_from_buffer (strlen (INVALID_GNSKEY),
477  MHD_RESPMEM_PERSISTENT);
478  (void) MHD_add_response_header (invalid_gnskey_response,
479  MHD_HTTP_HEADER_CONTENT_TYPE,
480  "text/html");
481  not_found_response = MHD_create_response_from_buffer (strlen (NOT_FOUND),
482  NOT_FOUND,
483  MHD_RESPMEM_PERSISTENT);
484  (void) MHD_add_response_header (not_found_response,
485  MHD_HTTP_HEADER_CONTENT_TYPE,
486  "text/html");
487  if (GNUNET_OK != server_start ())
488  return;
490 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-bcd.c:51
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
static struct MHD_Response * invalid_gnskey_response
Error: invalid gns key.
Definition: gnunet-bcd.c:66
#define NOT_FOUND
Error page to display on 404.
Definition: gnunet-bcd.c:40
static struct MHD_Response * not_found_response
Error: 404.
Definition: gnunet-bcd.c:71
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:1300
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int server_start()
Start server offering our hostlist.
Definition: gnunet-bcd.c:341
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
#define DIR_SEPARATOR_STR
Definition: platform.h:168
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, the current running apps installation directory.
static struct MHD_Response * main_response
Our main website.
Definition: gnunet-bcd.c:61
static void server_stop(void *cls)
Stop HTTP server.
Definition: gnunet-bcd.c:384
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static char * resfile
Absolute name of the &#39;gns-bcd.tex&#39; file.
Definition: gnunet-bcd.c:76
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
#define INVALID_GNSKEY
Error page to display if submitted GNS key is invalid.
Definition: gnunet-bcd.c:34
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 501 of file gnunet-bcd.c.

References _, gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_uint16(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), port, ret, and run().

502 {
505  "port",
506  "PORT",
507  gettext_noop (
508  "Run HTTP serve on port PORT (default is 8888)"),
509  &port),
511  };
512  int ret;
513 
514  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
515  return 2;
516  GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL);
517  ret = (GNUNET_OK ==
518  GNUNET_PROGRAM_run (argc,
519  argv,
520  "gnunet-bcd",
521  _ ("GNUnet HTTP server to create business cards"),
522  options,
523  &run,
524  NULL))
525  ? 0
526  : 1;
527  GNUNET_free ((void *) argv);
528  return ret;
529 }
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:430
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:1438
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
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.
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.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ daemon_handle

struct MHD_Daemon* daemon_handle
static

Handle to the HTTP server as provided by libmicrohttpd.

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

Referenced by access_handler_callback(), process_notify(), run_daemon(), server_start(), and server_stop().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

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

◆ http_task

struct GNUNET_SCHEDULER_Task* http_task
static

Our primary task for the HTTPD.

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

◆ main_response

struct MHD_Response* main_response
static

Our main website.

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

Referenced by access_handler_callback(), run(), and server_stop().

◆ invalid_gnskey_response

struct MHD_Response* invalid_gnskey_response
static

Error: invalid gns key.

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

Referenced by access_handler_callback(), run(), and server_stop().

◆ not_found_response

struct MHD_Response* not_found_response
static

Error: 404.

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

Referenced by access_handler_callback(), run(), and server_stop().

◆ resfile

char* resfile
static

Absolute name of the 'gns-bcd.tex' file.

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

Referenced by access_handler_callback(), run(), and server_stop().

◆ port

uint16_t port = 8888
static