GNUnet 0.22.2
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_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 154 of file gnunet-bcd.c.

155{
156 /* We cheat a bit here: the file descriptor is implicitly closed by MHD, so
157 calling `GNUNET_DISK_file_close' would generate a spurious warning message
158 in the log. Since that function does nothing but close the descriptor and
159 free the allocated memory, After destroying the response all that's left to
160 do is call `GNUNET_free'. */
161 if (NULL != index_simple)
162 {
163 MHD_destroy_response (index_simple->response);
166 }
167 if (NULL != index_full)
168 {
169 MHD_destroy_response (index_full->response);
172 }
173 if (NULL != key_error)
174 {
175 MHD_destroy_response (key_error->response);
178 }
179 if (NULL != notfound_error)
180 {
181 MHD_destroy_response (notfound_error->response);
184 }
185 if (NULL != internal_error)
186 {
187 MHD_destroy_response (internal_error->response);
190 }
191 if (NULL != forbidden_error)
192 {
193 MHD_destroy_response (forbidden_error->response);
196 }
197
198 if (NULL != httpd_task)
199 {
201 }
202 if (NULL != httpd)
203 {
204 MHD_stop_daemon (httpd);
205 }
206}
static struct StaticResource * key_error
Error: invalid gns key.
Definition: gnunet-bcd.c:86
static struct StaticResource * index_full
Index file resource (full result).
Definition: gnunet-bcd.c:81
static struct MHD_Daemon * httpd
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:66
static struct StaticResource * forbidden_error
Other errors.
Definition: gnunet-bcd.c:101
static struct StaticResource * index_simple
Index file resource (simple result).
Definition: gnunet-bcd.c:76
static struct GNUNET_SCHEDULER_Task * httpd_task
Our primary task for the HTTPD.
Definition: gnunet-bcd.c:71
static struct StaticResource * internal_error
Errors after receiving the form data.
Definition: gnunet-bcd.c:96
static struct StaticResource * notfound_error
Error: 404.
Definition: gnunet-bcd.c:91
#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:980
struct MHD_Response * response
Cached response object to send to clients.
Definition: gnunet-bcd.c:47
struct GNUNET_DISK_FileHandle * handle
Handle to file on disk.
Definition: gnunet-bcd.c:37

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

269{
270 httpd_task = NULL;
271 MHD_run (httpd);
272 run_httpd ();
273}
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 int max = -1;
227 unsigned MHD_LONG_LONG timeout = 0;
229
233
234 FD_ZERO (&rs);
235 FD_ZERO (&ws);
236 FD_ZERO (&es);
237
238 GNUNET_assert (MHD_YES == MHD_get_fdset (httpd, &rs, &ws, &es, &max));
239
240 if (MHD_YES == MHD_get_timeout (httpd, &timeout))
241 {
243 timeout);
244 }
245
249
251 gtime,
252 grs,
253 gws,
254 &do_httpd,
255 NULL);
259}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static void do_httpd(void *cls)
Called when the HTTP server has some pending operations.
Definition: gnunet-bcd.c:268
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1185
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:1041
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1169
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:1835
#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:486
#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 290 of file gnunet-bcd.c.

298{
300 bool isget = (0 == strcmp (method, MHD_HTTP_METHOD_GET));
301 bool ishead = (0 == strcmp (method, MHD_HTTP_METHOD_HEAD));
302 bool isfull = (0 == strcmp ("/submit/full", url));
303 bool issimple = (0 == strcmp ("/submit/simple", url));
304 char *tmpd;
305 char *defpath = NULL;
306 const char *gpgfp = MHD_lookup_connection_value (connection,
307 MHD_GET_ARGUMENT_KIND,
308 "gpgfingerprint");
309 const char *gnsnick = MHD_lookup_connection_value (connection,
310 MHD_GET_ARGUMENT_KIND,
311 "gnsnick");
312 const char *gnskey = MHD_lookup_connection_value (connection,
313 MHD_GET_ARGUMENT_KIND,
314 "gnskey");
315 const char *qrpng = MHD_lookup_connection_value (connection,
316 MHD_GET_ARGUMENT_KIND,
317 "gnspng");
318
319 (void) cls;
320 (void) version;
321 (void) upload_data;
322 (void) upload_data_size;
323
324 if (! isget && ! ishead)
325 {
326 return MHD_queue_response (connection,
327 MHD_HTTP_NOT_IMPLEMENTED,
329 }
330
331 if (ishead)
332 {
333 /* Dedicated branch in case we want to provide a different result for some
334 reason (e.g. a non-web browser application using the web UI) */
335 return MHD_queue_response (connection,
336 MHD_HTTP_OK,
338 }
339
340 /* Send a 100 CONTINUE response to tell clients that the result of the
341 request might take some time */
342 if (NULL == *ptr)
343 {
344 *ptr = &continue_100;
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE\n");
346 return MHD_YES;
347 }
348
349 if (0 == strcmp ("/", url))
350 {
351 return MHD_queue_response (connection,
352 MHD_HTTP_OK,
354 }
355
356 if (0 == strcmp ("/full", url))
357 {
358 return MHD_queue_response (connection,
359 MHD_HTTP_OK,
361 }
362
363
364 if (! isfull && ! issimple)
365 {
366 return MHD_queue_response (connection,
367 MHD_HTTP_NOT_FOUND,
369 }
370
371
372 if (NULL == gnskey
374 {
375 return MHD_queue_response (connection,
376 MHD_HTTP_BAD_REQUEST,
378 }
379
380 tmpd = GNUNET_DISK_mkdtemp (gnskey);
381 if (NULL == tmpd)
382 {
384 return MHD_queue_response (connection,
385 MHD_HTTP_INTERNAL_SERVER_ERROR,
387 }
388
389 GNUNET_asprintf (&defpath, "%s%s%s", tmpd, DIR_SEPARATOR_STR, "def.tex");
390
391 {
392 FILE *deffile = fopen (defpath, "w");
393 if (NULL == deffile)
394 {
396 GNUNET_free (defpath);
398 GNUNET_free (tmpd);
399 return MHD_queue_response (connection,
400 MHD_HTTP_INTERNAL_SERVER_ERROR,
402 }
403
404 GNUNET_free (defpath);
405
406 for (size_t i = 0; NULL!=pmap[i].name; ++i)
407 {
408 const char *value = MHD_lookup_connection_value (connection,
409 MHD_GET_ARGUMENT_KIND,
410 pmap[i].name);
411 fprintf (deffile,
412 "\\def\\%s{%s}\n",
413 pmap[i].definition,
414 (NULL == value) ? "" : value);
415 }
416
417 if (NULL != gpgfp)
418 {
419 size_t len = strlen (gpgfp);
420 char *line1 = GNUNET_strndup (gpgfp, len / 2);
421 char *line2 = GNUNET_strdup (&gpgfp[len / 2]);
422 fprintf (deffile,
423 "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n",
424 line1,
425 line2);
426 GNUNET_free (line1);
427 GNUNET_free (line2);
428 }
429
430 fprintf (deffile,
431 "\\def\\gns{%s/%s}\n",
432 gnskey,
433 (NULL == gnsnick) ? "" : gnsnick);
434
435 fclose (deffile);
436 }
437 {
438 char *command = NULL;
439 int ret;
440 GNUNET_asprintf (&command,
441 "cd %s; cp %s gns-bcd.tex; "
442 "pdflatex %s gns-bcd.tex >/dev/null 2>&1",
443 tmpd,
444 (isfull) ? tex_file_full :
445 ((NULL == qrpng) ? tex_file_simple : tex_file_png),
446 (NULL == qrpng) ? "" : "-shell-escape");
447
448 ret = system (command);
449
450 if (WIFSIGNALED (ret) || 0 != WEXITSTATUS (ret))
451 {
453 }
454
455 GNUNET_free (command);
456 }
457 GNUNET_asprintf (&defpath,
458 "%s%s%s",
459 tmpd,
461 (NULL == qrpng) ? "gns-bcd.pdf" : "gns-bcd.png");
462 {
463 MHD_RESULT r;
464 struct MHD_Response *pdfrs;
465 struct stat statret;
466 int pdf = open (defpath, O_RDONLY);
467 if (-1 == pdf)
468 {
470 GNUNET_free (defpath);
472 GNUNET_free (tmpd);
473 return MHD_queue_response (connection,
474 MHD_HTTP_INTERNAL_SERVER_ERROR,
476 }
477
478 GNUNET_break (0 == stat (defpath, &statret));
479
480 GNUNET_free (defpath);
481
482 pdfrs = MHD_create_response_from_fd ((size_t) statret.st_size, pdf);
483 if (NULL == pdfrs)
484 {
485 GNUNET_break (0);
486 GNUNET_break (0 == close (pdf));
488 GNUNET_free (tmpd);
489 return MHD_queue_response (connection,
490 MHD_HTTP_INTERNAL_SERVER_ERROR,
492 }
493
494 GNUNET_assert (MHD_NO != MHD_add_response_header (pdfrs,
495 MHD_HTTP_HEADER_CONTENT_TYPE,
496 (NULL == qrpng) ?
497 "application/pdf" :
498 "image/png"));
499 GNUNET_assert (MHD_NO !=
500 MHD_add_response_header (pdfrs,
501 MHD_HTTP_HEADER_CONTENT_DISPOSITION,
502 (NULL == qrpng) ?
503 "attachment; filename=\"gns-business-card.pdf\""
504 :
505 "attachment; filename=\"gns-qr-code.png\""));
506 r = MHD_queue_response (connection, MHD_HTTP_OK, pdfrs);
507
508 MHD_destroy_response (pdfrs);
510 GNUNET_free (tmpd);
511 return r;
512 }
513}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static char * tex_file_full
Full path to the TeX template file (full result)
Definition: gnunet-bcd.c:111
static int continue_100
Used as a sort of singleton to send exactly one 100 CONTINUE per request.
Definition: gnunet-bcd.c:121
static const struct ParameterMap pmap[]
Map of names with TeX definitions, used during PDF generation.
Definition: gnunet-bcd.c:126
static char * tex_file_png
Full path to the TeX template file (PNG result)
Definition: gnunet-bcd.c:116
static char * tex_file_simple
Full path to the TeX template file (simple result)
Definition: gnunet-bcd.c:106
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
#define MHD_RESULT
Data type to use for functions return an "MHD result".
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
Definition: disk.c:340
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1080
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:399
@ GNUNET_OK
#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:167
An identity key as per LSD0001.
const char * name
Name of the parameter from the request.
Definition: gnunet-bcd.c:55

References continue_100, DIR_SEPARATOR_STR, forbidden_error, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_public_key_from_string(), GNUNET_DISK_directory_remove(), GNUNET_DISK_mkdtemp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_strdup, GNUNET_strndup, index_full, index_simple, internal_error, key_error, 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 524 of file gnunet-bcd.c.

525{
526 char *fullname = NULL;
527 off_t size = 0;
529 struct MHD_Response *response;
530 struct StaticResource *res;
531 GNUNET_asprintf (&fullname, "%s%s%s", basedir, DIR_SEPARATOR_STR, name);
532
533 f = GNUNET_DISK_file_open (fullname,
536
537 GNUNET_free (fullname);
538
539 if (NULL == f)
540 {
541 return NULL;
542 }
543
545 {
547 return NULL;
548 }
549
550 response = MHD_create_response_from_fd64 (size, f->fd);
551
552 if (NULL == response)
553 {
555 return NULL;
556 }
557
558 res = GNUNET_new (struct StaticResource);
559 res->handle = f;
560 res->size = (uint64_t) size;
561 res->response = response;
562
563 return res;
564}
static struct MHD_Response * response
Our canonical response.
static char * res
Currently read line or NULL on EOF.
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:1234
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
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.
@ GNUNET_SYSERR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int size
Size of the "table".
Definition: peer.c:68
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 576 of file gnunet-bcd.c.

580{
581 char *datadir;
582 (void) cls;
583 (void) args;
584 (void) cfgfile;
585
586 if (0 == port)
587 {
589 _ ("Invalid port number %u\n"),
590 port);
592 return;
593 }
594
596
599 GNUNET_assert (NULL != datadir);
600
602 "%s%s%s",
603 datadir,
605 "gns-bcd.tex");
607 "%s%s%s",
608 datadir,
610 "gns-bcd-simple.tex");
612 "%s%s%s",
613 datadir,
615 "gns-bcd-png.tex");
616
617 index_simple = open_static_resource ("gns-bcd-simple.html", datadir);
618 index_full = open_static_resource ("gns-bcd.html", datadir);
619 key_error = open_static_resource ("gns-bcd-invalid-key.html", datadir);
620 notfound_error = open_static_resource ("gns-bcd-not-found.html", datadir);
621 internal_error = open_static_resource ("gns-bcd-internal-error.html", datadir)
622 ;
623 forbidden_error = open_static_resource ("gns-bcd-forbidden.html", datadir);
624
625 GNUNET_free (datadir);
626
627 if ((NULL == index_simple) || (NULL == index_full)
628 || (NULL == key_error) || (NULL == notfound_error)
629 || (NULL == internal_error) || (NULL == forbidden_error))
630 {
632 _ ("Unable to set up the daemon\n"));
634 return;
635 }
636
637 {
638 int flags = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
639 do
640 {
641 httpd = MHD_start_daemon (flags,
642 port,
643 NULL, NULL,
644 &create_response, NULL,
645 MHD_OPTION_CONNECTION_LIMIT, 512,
646 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 2,
647 MHD_OPTION_CONNECTION_TIMEOUT, 60,
648 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 16 * 1024,
649 MHD_OPTION_END);
650 flags = MHD_USE_DEBUG;
651 } while (NULL == httpd && flags != MHD_USE_DEBUG);
652 }
653 if (NULL == httpd)
654 {
656 _ ("Failed to start HTTP server\n"));
658 return;
659 }
660
661 run_httpd ();
662}
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:290
static void do_shutdown(void *cls)
Task ran at shutdown to clean up everything.
Definition: gnunet-bcd.c:154
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
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:524
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, 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:567
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:1339
#define _(String)
GNU gettext support macro.
Definition: platform.h:179

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_OS_project_data_gnunet(), 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 673 of file gnunet-bcd.c.

674{
677 'p',
678 "port",
679 "PORT",
680 gettext_noop ("Run HTTP server on port PORT (default is 8888)"),
681 &port),
683 };
684
685 return ((GNUNET_OK ==
687 argc,
688 argv,
689 "gnunet-bcd",
690 _ ("GNUnet HTTP server to create business cards")
691 ,
692 options,
693 &run,
694 NULL))
695 ? 0
696 : 1);
697}
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:74
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:576
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(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,...
Definition: program.c:407
Definition of a command line option.

References _, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_uint16(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), 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 66 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 71 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 76 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 81 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 86 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 91 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 96 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 101 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 106 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 111 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 116 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 121 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 126 of file gnunet-bcd.c.

Referenced by create_response(), and run().

◆ port