The list of sender subcommands (add, delete, allow, deny, on, off)
is defined as an enumeration in send.h. This list is duplicated in
check_sender_args() of command.c which contains the six subcommands
as C-strings to be matched against the first word of the sender
command line.
For the code to work properly it is essential that the two subcommand
lists are identical, which is a bad design that is quite error
prone. Fortunately it is easy to avoid the duplication with a little
preprocessor fu.
Since the subcommands are spelled in lower case and there is no
toupper function in CPP, we need to change the subcommand part of the
enumeration constants to lower case. The bulk of the patch consists
in trivial changes of all the users of these constants.
static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd)
{
int i;
static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd)
{
int i;
- /* this has to match sender.h */
- const char *subcmds[] = {"add", "delete", "allow", "deny", "on", "off", NULL};
+ const char *subcmds[] = {SENDER_SUBCOMMANDS NULL};
scd->sender_num = -1;
if (argc < 3)
return -E_COMMAND_SYNTAX;
scd->sender_num = -1;
if (argc < 3)
return -E_COMMAND_SYNTAX;
if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
return -E_SENDER_CMD;
switch (scd->cmd_num) {
if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
return -E_SENDER_CMD;
switch (scd->cmd_num) {
- case SENDER_ON:
- case SENDER_OFF:
+ case SENDER_on:
+ case SENDER_off:
if (argc != 3)
return -E_COMMAND_SYNTAX;
break;
if (argc != 3)
return -E_COMMAND_SYNTAX;
break;
- case SENDER_DENY:
- case SENDER_ALLOW:
+ case SENDER_deny:
+ case SENDER_allow:
if (argc != 4 || parse_cidr(argv[3], scd->host,
sizeof(scd->host), &scd->netmask) == NULL)
return -E_COMMAND_SYNTAX;
break;
if (argc != 4 || parse_cidr(argv[3], scd->host,
sizeof(scd->host), &scd->netmask) == NULL)
return -E_COMMAND_SYNTAX;
break;
- case SENDER_ADD:
- case SENDER_DELETE:
+ case SENDER_add:
+ case SENDER_delete:
if (argc != 4)
return -E_COMMAND_SYNTAX;
return parse_fec_url(argv[3], scd);
if (argc != 4)
return -E_COMMAND_SYNTAX;
return parse_fec_url(argv[3], scd);
- case SENDER_ADD:
- case SENDER_DELETE:
+ case SENDER_add:
+ case SENDER_delete:
assert(senders[scd.sender_num].resolve_target);
ret = senders[scd.sender_num].resolve_target(cc->argv[3], &scd);
if (ret < 0)
assert(senders[scd.sender_num].resolve_target);
ret = senders[scd.sender_num].resolve_target(cc->argv[3], &scd);
if (ret < 0)
s->shutdown_clients = dccp_shutdown_clients;
s->resolve_target = NULL;
s->help = generic_sender_help;
s->shutdown_clients = dccp_shutdown_clients;
s->resolve_target = NULL;
s->help = generic_sender_help;
- s->client_cmds[SENDER_ON] = dccp_com_on;
- s->client_cmds[SENDER_OFF] = dccp_com_off;
- s->client_cmds[SENDER_DENY] = dccp_com_deny;
- s->client_cmds[SENDER_ALLOW] = dccp_com_allow;
- s->client_cmds[SENDER_ADD] = NULL;
- s->client_cmds[SENDER_DELETE] = NULL;
+ s->client_cmds[SENDER_on] = dccp_com_on;
+ s->client_cmds[SENDER_off] = dccp_com_off;
+ s->client_cmds[SENDER_deny] = dccp_com_deny;
+ s->client_cmds[SENDER_allow] = dccp_com_allow;
+ s->client_cmds[SENDER_add] = NULL;
+ s->client_cmds[SENDER_delete] = NULL;
k = conf.dccp_data_slices_per_group_arg;
n = conf.dccp_slices_per_group_arg;
k = conf.dccp_data_slices_per_group_arg;
n = conf.dccp_slices_per_group_arg;
s->shutdown_clients = http_shutdown_clients;
s->resolve_target = NULL;
s->help = generic_sender_help;
s->shutdown_clients = http_shutdown_clients;
s->resolve_target = NULL;
s->help = generic_sender_help;
- s->client_cmds[SENDER_ON] = http_com_on;
- s->client_cmds[SENDER_OFF] = http_com_off;
- s->client_cmds[SENDER_DENY] = http_com_deny;
- s->client_cmds[SENDER_ALLOW] = http_com_allow;
- s->client_cmds[SENDER_ADD] = NULL;
- s->client_cmds[SENDER_DELETE] = NULL;
+ s->client_cmds[SENDER_on] = http_com_on;
+ s->client_cmds[SENDER_off] = http_com_off;
+ s->client_cmds[SENDER_deny] = http_com_deny;
+ s->client_cmds[SENDER_allow] = http_com_allow;
+ s->client_cmds[SENDER_add] = NULL;
+ s->client_cmds[SENDER_delete] = NULL;
init_sender_status(hss, conf.http_access_arg, conf.http_access_given,
conf.http_port_arg, conf.http_max_clients_arg,
init_sender_status(hss, conf.http_access_arg, conf.http_access_given,
conf.http_port_arg, conf.http_max_clients_arg,
/** \file send.h Sender-related defines and structures. */
/** \file send.h Sender-related defines and structures. */
-/** The sender subcommands. */
+#define SENDER_SUBCOMMANDS \
+ SENDER_SUBCOMMAND(add) /**< Add a target (udp only). */ \
+ SENDER_SUBCOMMAND(delete) /**< Delete a target (udp only). */ \
+ SENDER_SUBCOMMAND(allow) /**< Allow connections from given IP address(es). */ \
+ SENDER_SUBCOMMAND(deny) /**< Deny connections from given IP address(es). */ \
+ SENDER_SUBCOMMAND(on) /**< Activate the sender. */ \
+ SENDER_SUBCOMMAND(off) /**< Deactivate the sender. */ \
+
+#define SENDER_SUBCOMMAND(_name) SENDER_ ## _name,
- SENDER_ADD, /**< Add a target (udp only). */
- SENDER_DELETE, /**< Delete a target (udp only). */
- SENDER_ALLOW, /**< Allow connections from given IP address(es). */
- SENDER_DENY, /**< Deny connections from given IP address(es). */
- SENDER_ON, /**< Activate the sender. */
- SENDER_OFF, /**< Deactivate the sender. */
NUM_SENDER_CMDS /**< Used as array size in struct \ref sender. */
};
NUM_SENDER_CMDS /**< Used as array size in struct \ref sender. */
};
+#undef SENDER_SUBCOMMAND
+#define SENDER_SUBCOMMAND(_name) #_name,
/**
* Describes one supported sender of para_server.
/**
* Describes one supported sender of para_server.
static int udp_com_on(__a_unused struct sender_command_data *scd)
{
static int udp_com_on(__a_unused struct sender_command_data *scd)
{
- sender_status = SENDER_ON;
+ sender_status = SENDER_on;
return 1;
}
static int udp_com_off(__a_unused struct sender_command_data *scd)
{
udp_shutdown_targets();
return 1;
}
static int udp_com_off(__a_unused struct sender_command_data *scd)
{
udp_shutdown_targets();
- sender_status = SENDER_OFF;
+ sender_status = SENDER_off;
- if (sender_status == SENDER_OFF)
+ if (sender_status == SENDER_off)
return;
if (len == 0)
return;
return;
if (len == 0)
return;
"status: %s\n"
"port: %s\n"
"targets: %s\n",
"status: %s\n"
"port: %s\n"
"targets: %s\n",
- (sender_status == SENDER_ON)? "on" : "off",
+ (sender_status == SENDER_on)? "on" : "off",
stringify_port(conf.udp_default_port_arg, "udp"),
tgts? tgts : "(none)"
);
stringify_port(conf.udp_default_port_arg, "udp"),
tgts? tgts : "(none)"
);
s->post_select = NULL;
s->shutdown_clients = udp_shutdown_targets;
s->resolve_target = udp_resolve_target;
s->post_select = NULL;
s->shutdown_clients = udp_shutdown_targets;
s->resolve_target = udp_resolve_target;
- s->client_cmds[SENDER_ON] = udp_com_on;
- s->client_cmds[SENDER_OFF] = udp_com_off;
- s->client_cmds[SENDER_DENY] = NULL;
- s->client_cmds[SENDER_ALLOW] = NULL;
- s->client_cmds[SENDER_ADD] = udp_com_add;
- s->client_cmds[SENDER_DELETE] = udp_com_delete;
- sender_status = SENDER_OFF;
+ s->client_cmds[SENDER_on] = udp_com_on;
+ s->client_cmds[SENDER_off] = udp_com_off;
+ s->client_cmds[SENDER_deny] = NULL;
+ s->client_cmds[SENDER_allow] = NULL;
+ s->client_cmds[SENDER_add] = udp_com_add;
+ s->client_cmds[SENDER_delete] = udp_com_delete;
+ sender_status = SENDER_off;
udp_init_target_list();
if (!conf.udp_no_autostart_given)
udp_init_target_list();
if (!conf.udp_no_autostart_given)
- sender_status = SENDER_ON;
+ sender_status = SENDER_on;
PARA_DEBUG_LOG("udp sender init complete\n");
}
PARA_DEBUG_LOG("udp sender init complete\n");
}