-fix generation to match latest code

This commit is contained in:
Christian Grothoff
2024-07-24 12:46:28 +02:00
parent 7d0ef5a5a4
commit c5c276f523
5 changed files with 166 additions and 76 deletions
+36 -3
View File
@@ -37,8 +37,11 @@ Type: struct MHD_DaemonOptionValueLog
Argument1: MHD_LoggingCallback log_cb
Description1: the callback to use for logging,
+ NULL to disable logging
Argument2: void *lob_cb_cls
Argument2: void *log_cb_cls
Description2: the closure for the logging callback
# Note: CG does not exactly like this...
CustomSetter: /* Note: set directly to the daemon */
+ daemon->log_params = option->val.log_callback;
# Listen socket
@@ -69,6 +72,20 @@ Argument1: size_t sa_len
Description1: the size of the socket address pointed by @a sa.
Argument2: const struct sockaddr *sa
Description2: the address to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6) or even a UNIX domain socket (AF_UNIX)
CustomSetter: /* custom setter */
+ if (0 != option->val.bind_sa.v_sa_len)
+ {
+ if (NULL != settings->bind_sa.v_sa)
+ free (settings->bind_sa.v_sa);
+ settings->bind_sa.v_sa = malloc (option->val.bind_sa.v_sa_len);
+ if (NULL == settings->bind_sa.v_sa)
+ return MHD_SC_DAEMON_MALLOC_FAILURE;
+ memcpy (settings->bind_sa.v_sa,
+ option->val.bind_sa.v_sa,
+ option->val.bind_sa.v_sa_len);
+ settings->bind_sa.v_sa_len = option->val.bind_sa.v_sa_len;
+ settings->bind_sa.v_dual = option->val.bind_sa.v_dual;
+ }
Name: listen_socket
Value: 82
@@ -78,7 +95,7 @@ Comment: Accept connections from the given socket. Socket
+ Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA().
+
+ If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
Argument1: MHD_socket listen_fd
Argument1: MHD_Socket listen_fd
Description1: the listen socket to use, ignored if set to #MHD_INVALID_SOCKET
Name: listen_addr_reuse
@@ -276,7 +293,7 @@ Comment: The the maximum FD value.
+ Useful if application uses select() for polling the sockets, system FD_SETSIZE is good value for this option in such case.
+ Does not work with #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION().
+ Does not work on W32 (WinSock sockets).
Argument1: MHD_socket max_fd
Argument1: MHD_Socket max_fd
Description1: FIXME
# MHD optimisations
@@ -360,6 +377,22 @@ Argument1: size_t buf_size
Description1: the size of the buffer
Argument2: const void *buf
Description2: the buffer with strong random data, the content will be copied by MHD
CustomSetter: /* custom setter */
+ if (0 != option->val.random_entropy.v_buf_size)
+ {
+ if (NULL != settings->random_entropy.v_buf)
+ free (settings->random_entropy.v_buf);
+ settings->random_entropy.v_buf
+ = malloc (option->val.random_entropy.v_buf_size);
+ if (NULL == settings->random_entropy.v_buf)
+ return MHD_SC_DAEMON_MALLOC_FAILURE;
+ memcpy (settings->random_entropy.v_buf,
+ option->val.random_entropy.v_buf,
+ option->val.random_entropy.v_buf_size);
+ settings->random_entropy.v_buf_size
+ = option->val.random_entropy.v_buf_size;
+ }
Name: dauth_map_size
Value: 401
@@ -1,5 +1,3 @@
/* EDITED MANUALLY */
/**
* The options (parameters) for MHD daemon
*/
@@ -869,16 +867,16 @@ struct MHD_DaemonOptionAndValue
* Set a callback to use for logging
* @param log_cb the callback to use for logging,
* NULL to disable logging
* @param lob_cb_cls the closure for the logging callback
* @param log_cb_cls the closure for the logging callback
* @return structure with the requested setting
*/
# define MHD_D_OPTION_LOG_CALLBACK(log_cb,lob_cb_cls) \
# define MHD_D_OPTION_LOG_CALLBACK(log_cb,log_cb_cls) \
MHD_NOWARN_COMPOUND_LITERALS_ \
(const struct MHD_DaemonOptionAndValue) \
{ \
.opt = MHD_D_O_LOG_CALLBACK, \
.val.log_callback.v_log_cb = (log_cb), \
.val.log_callback.v_lob_cb_cls = (lob_cb_cls) \
.val.log_callback.v_log_cb_cls = (log_cb_cls) \
} \
MHD_RESTORE_WARN_COMPOUND_LITERALS_
/**
@@ -1522,20 +1520,20 @@ MHD_D_OPTION_POLL_SYSCALL (
* Set a callback to use for logging
* @param log_cb the callback to use for logging,
* NULL to disable logging
* @param lob_cb_cls the closure for the logging callback
* @param log_cb_cls the closure for the logging callback
* @return structure with the requested setting
*/
static MHD_INLINE struct MHD_daemonOptionAndValue
MHD_D_OPTION_LOG_CALLBACK (
MHD_LoggingCallback log_cb,
void *lob_cb_cls
void *log_cb_cls
)
{
struct MHD_DaemonOptionAndValue opt_val;
opt_val.opt = MHD_D_O_LOG_CALLBACK;
opt_val.val.log_callback.v_log_cb = log_cb;
opt_val.val.log_callback.v_lob_cb_cls = lob_cb_cls;
opt_val.val.log_callback.v_log_cb_cls = log_cb_cls;
return opt_val;
}
+104 -37
View File
@@ -38,6 +38,7 @@ struct Option
unsigned int value;
char *type;
char *comment;
char *custom_setter;
unsigned int argc;
char *arguments[MAX_ARGS];
unsigned int desc;
@@ -55,6 +56,7 @@ typedef void
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desc,
@@ -75,6 +77,7 @@ iterate (struct Option *head,
o->comment,
o->type,
o->conditional,
o->custom_setter,
o->argc,
o->arguments,
o->desc,
@@ -89,6 +92,7 @@ check (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desc,
@@ -203,6 +207,7 @@ dump_enum (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desc,
@@ -234,6 +239,7 @@ dump_union_members (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desct,
@@ -271,6 +277,7 @@ dump_union (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desc,
@@ -319,6 +326,7 @@ dump_struct (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desc,
@@ -333,6 +341,7 @@ dump_struct (const char *name,
comment,
type,
conditional,
custom_setter,
argc,
arguments,
desc,
@@ -351,6 +360,7 @@ dump_option_macros (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desct,
@@ -430,6 +440,7 @@ dump_option_static_functions (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desct,
@@ -514,6 +525,7 @@ dump_option_documentation_functions (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desct,
@@ -573,6 +585,7 @@ dump_option_set_switch (const char *name,
const char *comment,
const char *type,
const char *conditional,
const char *custom_setter,
unsigned int argc,
char **arguments,
unsigned int desc,
@@ -583,35 +596,46 @@ dump_option_set_switch (const char *name,
"#ifdef HAVE_%s",
uppercase (conditional));
fprintf (f,
" case MHD_%c_OPTION_%s:\n",
" case MHD_%c_O_%s:\n",
(char) toupper (*category),
uppercase (name));
if (0 == argc)
if (NULL != custom_setter)
{
fprintf (f,
" %s->settings.%s = option->val.%s;\n",
category,
lowercase (name),
lowercase (name));
" %s\n",
indent (" ",
custom_setter));
}
else
for (unsigned int i = 0; i<argc; i++)
{
if (0 == argc)
{
const char *vn = var_name (arguments[i]);
if (1 < argc)
fprintf (f,
" %s->settings.%s.v_%s = option->val.%s.v_%s;\n",
category,
lowercase (name),
vn,
lowercase (name),
vn);
else
fprintf (f,
" %s->settings.%s = option->val.%s;\n",
category,
lowercase (name),
lowercase (name));
fprintf (f,
" settings->%s = option->val.%s;\n",
lowercase (name),
lowercase (name));
}
else
{
for (unsigned int i = 0; i<argc; i++)
{
const char *vn = var_name (arguments[i]);
if (1 < argc)
fprintf (f,
" settings->%s.v_%s = option->val.%s.v_%s;\n",
lowercase (name),
vn,
lowercase (name),
vn);
else
fprintf (f,
" settings->%s = option->val.%s;\n",
lowercase (name),
lowercase (name));
}
}
}
fprintf (f,
" continue;\n");
if (NULL != conditional)
@@ -748,6 +772,10 @@ TOP:
"Conditional: ",
line)))
continue;
if (NULL != (larg = parse (&last->custom_setter,
"CustomSetter: ",
line)))
continue;
if (0 == strncasecmp (line,
"Value: ",
strlen ("Value: ")))
@@ -891,7 +919,8 @@ TOP:
printf (
"#else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */\n");
printf ("MHD_NOWARN_UNUSED_FUNC_");
iterate (head, &dump_option_static_functions);
iterate (head,
&dump_option_static_functions);
printf ("\n/**\n"
" * Terminate the list of the options\n"
" * @return the terminating object of struct MHD_%sOptionAndValue\n"
@@ -959,15 +988,24 @@ TOP:
return 2;
}
fprintf (f,
"/* This is generated code, it is still under LGPLv3+.\n"
"/* This is generated code, it is still under LGPLv2.1+.\n"
" Do not edit directly! */\n"
"/* *INDENT-OFF* */\n"
"/**\n"
"/* @file %s_set_options.c\n"
"/* @author %s-options-generator.c\n"
" */\n\n"
"#include \"microhttpd2.h\"\n"
"#include \"internal.h\"\n\n"
" * @file %s_set_options.c\n"
" * @author %s-options-generator.c\n"
" */\n"
"\n"
"#include \"mhd_sys_options.h\"\n"
"#include \"sys_base_types.h\"\n"
"#include \"sys_malloc.h\"\n"
"#include <string.h>\n"
"#include \"mhd_daemon.h\"\n"
"#include \"mhd_response.h\"\n"
"#include \"%s_options.h\"\n"
"#include \"mhd_public_api.h\"\n"
"\n"
"MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_\n"
"enum MHD_StatusCode\n"
"MHD_%s_set_options (\n"
" struct MHD_%s *%s,\n"
@@ -977,18 +1015,38 @@ TOP:
category,
category,
category,
category,
capitalize (category),
category,
capitalize (category));
fprintf (f,
" for (size_t i=0;i<options_max_num;i++)\n"
" struct %sOptions *const settings = %s->settings;\n"
" size_t i;\n"
"\n"
" if (%s->frozen)\n"
" return MHD_SC_TOO_LATE;\n"
"\n"
" for (i=0;i<options_max_num;i++)\n"
" {\n"
" switch (options[i].opt) {\n");
" const struct MHD_%sOptionAndValue *const option = options + i;\n"
" switch (option->opt) {\n",
capitalize (category),
category,
category,
capitalize (category));
fprintf (f,
" case MHD_%c_O_END:\n"
" return MHD_SC_OK;\n",
(char) toupper (*category));
iterate (head,
&dump_option_set_switch);
fprintf (f,
" case MHD_%c_O_SENTINEL:\n"
" break;\n",
(char) toupper (*category));
fprintf (f,
" }\n"
" return MHD_SC_OPTION_UNSUPPORTED;\n"
" return MHD_SC_OPTION_UNKNOWN;\n"
" }\n"
" return MHD_SC_OK;\n");
fprintf (f,
@@ -1015,23 +1073,32 @@ TOP:
return 2;
}
fprintf (f,
"/* This is generated code, it is still under LGPLv3+.\n"
"/* This is generated code, it is still under LGPLv2.1+.\n"
" Do not edit directly! */\n"
"/* *INDENT-OFF* */\n"
"/**\n"
"/* @file %s_options.h\n"
"/* @author %s-options-generator.c\n"
" */\n\n"
"#include \"microhttpd2.h\"\n"
"#include \"internal.h\"\n\n"
"#ifndef MHD_%s_OPTIONS_H\n"
"#define MHD_%s_OTPIONS_H 1\n"
"\n"
"#include \"mhd_sys_options.h\"\n"
"#include \"mhd_public_api.h\"\n"
"\n"
"struct %sOptions {\n",
category,
category,
uppercase (category),
uppercase (category),
capitalize (category));
iterate (head,
&dump_struct);
fprintf (f,
"};\n");
"};\n"
"\n"
"#endif /* ! MHD_%s_OPTIONS_H */\n",
uppercase (category));
fclose (f);
chmod (do_h, S_IRUSR | S_IRGRP | S_IROTH);
free (do_h);
+3 -7
View File
@@ -2,20 +2,16 @@
Do not edit directly! */
/* *INDENT-OFF* */
/**
* @file daemon_options.h
* @author daemon-options-generator.c
/* @file daemon_options.h
/* @author daemon-options-generator.c
*/
/* EDITED MANUALLY */
#ifndef MHD_DAEMON_OPTIONS_H
#define MHD_DAEMON_OPTIONS_H 1
#define MHD_DAEMON_OTPIONS_H 1
#include "mhd_sys_options.h"
#include "mhd_public_api.h"
struct DaemonOptions {
/**
* Value for #MHD_D_O_WORK_MODE.
+17 -21
View File
@@ -6,26 +6,26 @@
* @author daemon-options-generator.c
*/
/* EDITED MANUALLY */
#include "mhd_sys_options.h"
#include "sys_base_types.h"
#include "sys_malloc.h"
#include <string.h>
#include "mhd_daemon.h"
#include "mhd_response.h"
#include "daemon_options.h"
#include "mhd_public_api.h"
MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_ enum MHD_StatusCode
MHD_daemon_set_options (struct MHD_Daemon *daemon,
const struct MHD_DaemonOptionAndValue *options,
size_t options_max_num)
MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_
enum MHD_StatusCode
MHD_daemon_set_options (
struct MHD_Daemon *daemon,
const struct MHD_DaemonOptionAndValue *options,
size_t options_max_num)
{
struct DaemonOptions *const settings = daemon->settings;
size_t i;
if (mhd_DAEMON_STATE_NOT_STARTED != daemon->state)
if (daemon->frozen)
return MHD_SC_TOO_LATE;
for (i=0;i<options_max_num;i++)
@@ -41,7 +41,7 @@ MHD_daemon_set_options (struct MHD_Daemon *daemon,
settings->poll_syscall = option->val.poll_syscall;
continue;
case MHD_D_O_LOG_CALLBACK:
/* Note: set directly to the daemon! */
/* Note: set directly to the daemon */
daemon->log_params = option->val.log_callback;
continue;
case MHD_D_O_BIND_PORT:
@@ -49,17 +49,16 @@ MHD_daemon_set_options (struct MHD_Daemon *daemon,
settings->bind_port.v_port = option->val.bind_port.v_port;
continue;
case MHD_D_O_BIND_SA:
/* The is not an easy for automatic generations */
/* custom setter */
if (0 != option->val.bind_sa.v_sa_len)
{
if (NULL != settings->bind_sa.v_sa)
free (settings->bind_sa.v_sa);
settings->bind_sa.v_sa = malloc (option->val.bind_sa.v_sa_len);
if (NULL == settings->bind_sa.v_sa)
return MHD_SC_DAEMON_MALLOC_FAILURE;
memcpy (settings->bind_sa.v_sa, option->val.bind_sa.v_sa,
memcpy (settings->bind_sa.v_sa,
option->val.bind_sa.v_sa,
option->val.bind_sa.v_sa_len);
settings->bind_sa.v_sa_len = option->val.bind_sa.v_sa_len;
settings->bind_sa.v_dual = option->val.bind_sa.v_dual;
@@ -166,22 +165,20 @@ MHD_daemon_set_options (struct MHD_Daemon *daemon,
settings->notify_stream.v_cls = option->val.notify_stream.v_cls;
continue;
case MHD_D_O_RANDOM_ENTROPY:
/* The is not an easy for automatic generations */
/* custom setter */
if (0 != option->val.random_entropy.v_buf_size)
{
if (NULL != settings->random_entropy.v_buf)
free (settings->random_entropy.v_buf);
settings->random_entropy.v_buf =
malloc (option->val.random_entropy.v_buf_size);
settings->random_entropy.v_buf
= malloc (option->val.random_entropy.v_buf_size);
if (NULL == settings->random_entropy.v_buf)
return MHD_SC_DAEMON_MALLOC_FAILURE;
memcpy (settings->random_entropy.v_buf,
option->val.random_entropy.v_buf,
option->val.random_entropy.v_buf_size);
settings->random_entropy.v_buf_size =
option->val.random_entropy.v_buf_size;
settings->random_entropy.v_buf_size
= option->val.random_entropy.v_buf_size;
}
continue;
case MHD_D_O_DAUTH_MAP_SIZE:
@@ -197,7 +194,6 @@ MHD_daemon_set_options (struct MHD_Daemon *daemon,
settings->dauth_def_max_nc = option->val.dauth_def_max_nc;
continue;
case MHD_D_O_SENTINEL:
default:
break;
}
return MHD_SC_OPTION_UNKNOWN;