28 #include <microhttpd.h> 35 #define INVALID_GNSKEY \ 36 "<html><head><title>Error</title><body>Invalid GNS public key given.</body></html>" 42 "<html><head><title>Error</title><body>404 not found</body></html>" 82 static uint16_t
port = 8888;
97 struct MHD_Connection *connection,
101 const char *upload_data,
102 size_t *upload_data_size,
106 static const struct Entry map[] = { {
"prefix",
"prefix" },
108 {
"suffix",
"suffix" },
109 {
"street",
"street" },
111 {
"phone",
"phone" },
113 {
"email",
"email" },
114 {
"homepage",
"homepage" },
116 {
"departmenti18n",
"departmentde" },
117 {
"departmenten",
"departmenten" },
118 {
"subdepartmenti18n",
120 {
"subdepartmenten",
"subdepartmenten" },
121 {
"jobtitlei18n",
"jobtitlegerman" },
122 {
"jobtitleen",
"jobtitleenglish" },
123 {
"subdepartmenten",
"subdepartmenten" },
129 (void) upload_data_size;
130 if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
133 _ (
"Refusing `%s' request to HTTP server\n"),
137 if (NULL == *con_cls)
143 if (0 == strcasecmp (url,
"/"))
144 return MHD_queue_response (connection, MHD_HTTP_OK,
main_response);
145 if (0 == strcasecmp (url,
"/submit.pdf"))
159 const char *gpg_fp = MHD_lookup_connection_value (connection,
160 MHD_GET_ARGUMENT_KIND,
162 const char *gns_nick = MHD_lookup_connection_value (connection,
163 MHD_GET_ARGUMENT_KIND,
166 MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND,
"gnskey");
167 if ((NULL == gnskey) ||
173 return MHD_queue_response (connection,
184 f = fopen (deffile,
"w");
193 for (i = 0; NULL != map[i].
formname; i++)
195 const char *val = MHD_lookup_connection_value (connection,
196 MHD_GET_ARGUMENT_KIND,
199 fprintf (f,
"\\def\\%s{%s}\n", map[i].
texname, val);
201 fprintf (f,
"\\def\\%s{}\n", map[i].texname);
208 slen = strlen (gpg_fp);
211 fprintf (f,
"\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
216 "\\def\\gns{%s/%s}\n",
218 (NULL == gns_nick) ?
"" : gns_nick);
222 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
227 if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret)))
230 fd = open (deffile, O_RDONLY);
242 (response = MHD_create_response_from_fd ((
size_t) st.st_size, fd)))
252 (void) MHD_add_response_header (response,
253 MHD_HTTP_HEADER_CONTENT_TYPE,
255 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
256 MHD_destroy_response (response);
263 return MHD_queue_response (connection,
306 MHD_UNSIGNED_LONG_LONG
timeout;
316 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
317 haveto = MHD_get_timeout (daemon_handle, &timeout);
318 if (haveto == MHD_YES)
347 _ (
"Invalid port number %u. Exiting.\n"),
352 _ (
"Businesscard HTTP server starts on %u\n"),
354 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG,
360 MHD_OPTION_CONNECTION_LIMIT,
362 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
364 MHD_OPTION_CONNECTION_TIMEOUT,
366 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
367 (
size_t) (16 * 1024),
372 _ (
"Could not start businesscard HTTP server on port %u\n"),
373 (
unsigned int)
port);
389 if (NULL != http_task)
450 fd = open (fn, O_RDONLY);
457 if (0 != stat (fn, &st))
466 (
main_response = MHD_create_response_from_fd ((
size_t) st.st_size, fd)))
473 MHD_HTTP_HEADER_CONTENT_TYPE,
478 MHD_RESPMEM_PERSISTENT);
480 MHD_HTTP_HEADER_CONTENT_TYPE,
484 MHD_RESPMEM_PERSISTENT);
486 MHD_HTTP_HEADER_CONTENT_TYPE,
502 main (
int argc,
char *
const *argv)
509 "Run HTTP serve on port PORT (default is 8888)"),
522 _ (
"GNUnet HTTP server to create business cards"),
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
static char * dir
Set to the directory where runtime files are stored.
static struct MHD_Response * invalid_gnskey_response
Error: invalid gns key.
Run with high priority (important requests).
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, parse options).
uint64_t rel_value_us
The actual value.
int main(int argc, char *const *argv)
The main function for gnunet-gns.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
#define NOT_FOUND
Error page to display on 404.
static struct MHD_Response * not_found_response
Error: 404.
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.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
#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.
static int ret
Return value of the commandline.
static int server_start()
Start server offering our hostlist.
Definition of a command line option.
#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...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
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.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
static struct GNUNET_OS_Process * p
Helper process we started.
#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...
static char * fn
Filename of the unique file.
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.
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...
static MHD_RESULT 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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free_nz(ptr)
Wrapper around free.
char * GNUNET_DISK_mkdtemp(const char *t)
Create an (empty) temporary directory on disk.
#define MHD_RESULT
Data type to use for functions return an "MHD result".
static struct GNUNET_SCHEDULER_Task * prepare_daemon(struct MHD_Daemon *daemon_handle)
Function that queries MHD's select sets and starts the task waiting for them.
static struct MHD_Response * main_response
Our main website.
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_.
enum GNUNET_GenericReturnValue 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.
static uint16_t port
Port number.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
static struct MHD_Response * response
Our canonical response.
static void server_stop(void *cls)
Stop HTTP server.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static char * resfile
Absolute name of the 'gns-bcd.tex' file.
Entry type to be used in the map to store old latency values.
static void run_daemon(void *cls)
Call MHD to process pending requests and then go back and schedule the next run.
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
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)
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
#define INVALID_GNSKEY
Error page to display if submitted GNS key is invalid.