Make all 'config' tests pass

Change a test case: configuration options are now case sensitive.

Fix config file load and parse logic in conf.c, always copy 'debug' flags
from config.debug.

The config schema 'interfaces' option is no longer MANDATORY.

Introduce new CLIFLAG_PERMISSIVE_CONFIG to supress bad-config ERROR messages
from the 'config set' and 'config get' commands.

Refactor cli_execute() into cli_parse() and cli_invoke().  Use *const* struct
command_line_option everywhere.
This commit is contained in:
Andrew Bettison 2012-12-04 16:52:49 +10:30
parent caa209fc1d
commit 71ed78e058
14 changed files with 177 additions and 110 deletions

17
cli.c
View File

@ -5,7 +5,7 @@
#include "serval.h"
#include "rhizome.h"
int cli_usage(struct command_line_option *options) {
int cli_usage(const struct command_line_option *options) {
printf("Usage:\n");
int i,j;
for(i=0;options[i].function;i++) {
@ -16,7 +16,8 @@ int cli_usage(struct command_line_option *options) {
return 0;
}
int cli_execute(const char *argv0, int argc, const char *const *args, struct command_line_option *options, void *context){
int cli_parse(const int argc, const char *const *args, const struct command_line_option *options)
{
int ambiguous=0;
int cli_call=-1;
int i;
@ -82,12 +83,16 @@ int cli_execute(const char *argv0, int argc, const char *const *args, struct com
INFO("Use \"help\" command to see a list of valid commands");
return -1;
}
/* Otherwise, make call */
return options[cli_call].function(argc, args, &options[cli_call], context);
return cli_call;
}
int cli_arg(int argc, const char *const *argv, struct command_line_option *o, char *argname, const char **dst, int (*validator)(const char *arg), char *defaultvalue)
int cli_invoke(const struct command_line_option *option, const int argc, const char *const *args, void *context)
{
return option->function(argc, args, option, context);
}
int cli_arg(int argc, const char *const *argv, const struct command_line_option *o, char *argname, const char **dst, int (*validator)(const char *arg), char *defaultvalue)
{
int arglen = strlen(argname);
int i;

16
cli.h
View File

@ -2,18 +2,20 @@
#define __SERVALD_CLI_H
typedef struct command_line_option {
int (*function)(int argc, const char *const *argv, struct command_line_option *o, void *context);
int (*function)(int argc, const char *const *argv, const struct command_line_option *o, void *context);
const char *words[32]; // 32 words should be plenty!
unsigned long long flags;
#define CLIFLAG_NONOVERLAY (1<<0) /* Uses a legacy IPv4 DNA call instead of overlay mnetwork */
#define CLIFLAG_STANDALONE (1<<1) /* Cannot be issued to a running instance */
#define CLIFLAG_NONOVERLAY (1<<0) /* Uses a legacy IPv4 DNA call instead of overlay mnetwork */
#define CLIFLAG_STANDALONE (1<<1) /* Cannot be issued to a running instance */
#define CLIFLAG_PERMISSIVE_CONFIG (1<<2) /* No error on bad configuration file */
const char *description; // describe this invocation
} command_line_option;
int cli_usage(command_line_option *options);
int cli_execute(const char *argv0, int argc, const char *const *args, command_line_option *options, void *context);
int cli_arg(int argc, const char *const *argv, command_line_option *o, char *argname, const char **dst, int (*validator)(const char *arg), char *defaultvalue);
int cli_usage(const command_line_option *options);
int cli_parse(const int argc, const char *const *args, const struct command_line_option *options);
int cli_invoke(const struct command_line_option *option, const int argc, const char *const *args, void *context);
int cli_arg(int argc, const char *const *argv, const command_line_option *o, char *argname, const char **dst, int (*validator)(const char *arg), char *defaultvalue);
int cli_lookup_did(const char *text);
int cli_absolute_path(const char *arg);
@ -27,4 +29,4 @@ int cli_optional_did(const char *text);
#endif
#endif

View File

@ -44,7 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
extern struct command_line_option command_line_options[];
int commandline_usage(int argc, const char *const *argv, struct command_line_option *o, void *context){
int commandline_usage(int argc, const char *const *argv, const struct command_line_option *o, void *context){
printf("Serval Mesh version <version>.\n");
return cli_usage(command_line_options);
}
@ -189,9 +189,19 @@ int parseCommandLine(const char *argv0, int argc, const char *const *args)
{
fd_clearstats();
IN();
cf_reload();
int result = cli_execute(argv0, argc, args, command_line_options, NULL);
int result = cli_parse(argc, args, command_line_options);
if (result != -1) {
const struct command_line_option *option = &command_line_options[result];
if (option->flags & CLIFLAG_PERMISSIVE_CONFIG)
cf_reload_permissive();
else
cf_reload();
result = cli_invoke(option, argc, args, NULL);
} else {
cf_reload();
}
/* clean up after ourselves */
overlay_mdp_client_done();
rhizome_close_db();
@ -322,7 +332,7 @@ void cli_flush()
fflush(stdout);
}
int app_echo(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_echo(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
int i = 1;
@ -385,7 +395,7 @@ void lookup_send_request(unsigned char *srcsid, int srcport, unsigned char *dsts
}
}
int app_dna_lookup(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_dna_lookup(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
@ -502,7 +512,7 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
return 0;
}
int app_server_start(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_server_start(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
/* Process optional arguments */
@ -678,7 +688,7 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti
return ret;
}
int app_server_stop(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_server_stop(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
int pid, tries, running;
@ -739,7 +749,7 @@ int app_server_stop(int argc, const char *const *argv, struct command_line_optio
return 0;
}
int app_server_status(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_server_status(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
int pid;
@ -766,7 +776,7 @@ int app_server_status(int argc, const char *const *argv, struct command_line_opt
return pid > 0 ? 0 : 1;
}
int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_mdp_ping(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *sid, *count;
@ -913,7 +923,7 @@ int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *
return ret;
}
int app_config_set(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_config_set(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *var, *val;
@ -935,12 +945,13 @@ int app_config_set(int argc, const char *const *argv, struct command_line_option
// Bingo, the old version of servald.conf is what remains. This kludge intervenes in step 4, by
// reading the new servald.conf into the memory buffer before applying the "rhizome.enable" set
// value and overwriting.
struct cf_om_node *root = cf_om_reload();
if (cf_om_reload() == -1)
return -1;
// </kludge>
return root == NULL ? -1 : cf_om_set(&root, var, val) == -1 ? -1 : cf_om_save(root);
return cf_om_set(&cf_om_root, var, val) == -1 ? -1 : cf_om_save();
}
int app_config_del(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_config_del(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *var;
@ -949,12 +960,13 @@ int app_config_del(int argc, const char *const *argv, struct command_line_option
if (create_serval_instance_dir() == -1)
return -1;
// <kludge> See app_config_set()
struct cf_om_node *root = cf_om_reload();
if (cf_om_reload() == -1)
return -1;
// </kludge>
return root == NULL ? -1 : cf_om_set(&root, var, NULL) == -1 ? -1 : cf_om_save(root);
return cf_om_set(&cf_om_root, var, NULL) == -1 ? -1 : cf_om_save();
}
int app_config_get(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_config_get(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *var;
@ -962,9 +974,10 @@ int app_config_get(int argc, const char *const *argv, struct command_line_option
return -1;
if (create_serval_instance_dir() == -1)
return -1;
struct cf_om_node *root = cf_om_reload();
if (cf_om_reload() == -1)
return -1;
if (var) {
const char *value = cf_om_get(root, var);
const char *value = cf_om_get(cf_om_root, var);
if (value) {
cli_puts(var);
cli_delim("=");
@ -973,7 +986,7 @@ int app_config_get(int argc, const char *const *argv, struct command_line_option
}
} else {
struct cf_om_iterator it;
for (cf_om_iter_start(&it, root); it.node; cf_om_iter_next(&it)) {
for (cf_om_iter_start(&it, cf_om_root); it.node; cf_om_iter_next(&it)) {
if (it.node->text) {
cli_puts(it.node->fullkey);
cli_delim("=");
@ -985,7 +998,7 @@ int app_config_get(int argc, const char *const *argv, struct command_line_option
return 0;
}
int app_rhizome_hash_file(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_hash_file(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
/* compute hash of file. We do this without a manifest, so it will necessarily
@ -1000,7 +1013,7 @@ int app_rhizome_hash_file(int argc, const char *const *argv, struct command_line
return 0;
}
int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_add_file(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *filepath, *manifestpath, *authorSidHex, *pin, *bskhex;
@ -1240,7 +1253,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_
return ret;
}
int app_rhizome_import_bundle(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_import_bundle(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *filepath, *manifestpath;
@ -1252,7 +1265,7 @@ int app_rhizome_import_bundle(int argc, const char *const *argv, struct command_
return status;
}
int app_rhizome_extract_manifest(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_extract_manifest(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *pins, *manifestid, *manifestpath;
@ -1296,7 +1309,7 @@ int app_rhizome_extract_manifest(int argc, const char *const *argv, struct comma
return ret;
}
int app_rhizome_extract_file(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_extract_file(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *fileid, *filepath, *keyhex;
@ -1326,7 +1339,7 @@ int app_rhizome_extract_file(int argc, const char *const *argv, struct command_l
return ret;
}
int app_rhizome_list(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_list(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *pins, *service, *sender_sid, *recipient_sid, *offset, *limit;
@ -1346,7 +1359,7 @@ int app_rhizome_list(int argc, const char *const *argv, struct command_line_opti
return rhizome_list_manifests(service, sender_sid, recipient_sid, atoi(offset), atoi(limit));
}
int app_keyring_create(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_keyring_create(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *pin;
@ -1356,7 +1369,7 @@ int app_keyring_create(int argc, const char *const *argv, struct command_line_op
return 0;
}
int app_keyring_list(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_keyring_list(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *pins;
@ -1383,7 +1396,7 @@ int app_keyring_list(int argc, const char *const *argv, struct command_line_opti
return 0;
}
int app_keyring_add(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_keyring_add(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *pin;
@ -1428,7 +1441,7 @@ int app_keyring_add(int argc, const char *const *argv, struct command_line_optio
return 0;
}
int app_keyring_set_did(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_keyring_set_did(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *sid, *did, *pin, *name;
@ -1457,7 +1470,7 @@ int app_keyring_set_did(int argc, const char *const *argv, struct command_line_o
return 0;
}
int app_id_self(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_id_self(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
/* List my own identities */
@ -1504,7 +1517,8 @@ int app_id_self(int argc, const char *const *argv, struct command_line_option *o
return 0;
}
int app_count_peers(int argc, const char *const *argv, struct command_line_option *o, void *context){
int app_count_peers(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
overlay_mdp_frame a;
bzero(&a, sizeof(overlay_mdp_frame));
a.packetTypeAndFlags=MDP_GETADDRS;
@ -1520,7 +1534,7 @@ int app_count_peers(int argc, const char *const *argv, struct command_line_optio
return 0;
}
int app_test_rfs(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_test_rfs(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
printf("Testing that RFS coder works properly.\n");
@ -1536,7 +1550,7 @@ int app_test_rfs(int argc, const char *const *argv, struct command_line_option *
return 0;
}
int app_crypt_test(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_crypt_test(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
unsigned char nonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES];
@ -1699,7 +1713,7 @@ int app_crypt_test(int argc, const char *const *argv, struct command_line_option
return 0;
}
int app_node_info(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_node_info(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
const char *sid;
@ -1746,7 +1760,7 @@ int app_node_info(int argc, const char *const *argv, struct command_line_option
return 0;
}
int app_reverse_lookup(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_reverse_lookup(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
const char *sid, *delay;
@ -1886,11 +1900,11 @@ struct command_line_option command_line_options[]={
"Display information about any running Serval Mesh node."},
{app_mdp_ping,{"mdp","ping","<SID|broadcast>","[<count>]",NULL},CLIFLAG_STANDALONE,
"Attempts to ping specified node via Mesh Datagram Protocol (MDP)."},
{app_config_set,{"config","set","<variable>","<value>",NULL},CLIFLAG_STANDALONE,
{app_config_set,{"config","set","<variable>","<value>",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG,
"Set specified configuration variable."},
{app_config_del,{"config","del","<variable>",NULL},CLIFLAG_STANDALONE,
{app_config_del,{"config","del","<variable>",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG,
"Set specified configuration variable."},
{app_config_get,{"config","get","[<variable>]",NULL},CLIFLAG_STANDALONE,
{app_config_get,{"config","get","[<variable>]",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG,
"Get specified configuration variable."},
{app_vomp_console,{"console",NULL},0,
"Test phone call life-cycle from the console"},

67
conf.c
View File

@ -32,8 +32,8 @@ struct file_meta {
off_t size;
};
struct cf_om_node *cf_om_root = NULL;
static struct file_meta conffile_meta = { .mtime = -1, .size = -1 };
static struct cf_om_node *cf_om_root = NULL;
int cf_limbo = 1;
struct config_main config;
@ -119,12 +119,9 @@ static int has_changed(const struct file_meta *metap)
return metap->size != meta.size || metap->mtime != meta.mtime;
}
struct cf_om_node *cf_om_load()
int cf_om_load()
{
int result = load();
if (result == CFERROR)
return NULL;
return cf_om_root;
return load() == CFERROR ? -1 : 0;
}
/* Check if the config file has changed since we last read it, and if so, invalidate the buffer so
@ -136,17 +133,16 @@ struct cf_om_node *cf_om_load()
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
struct cf_om_node *cf_om_reload()
int cf_om_reload()
{
if (cf_om_root) {
if (!has_changed(&conffile_meta))
return cf_om_root;
if (!has_changed(&conffile_meta))
return CFOK;
if (conffile_meta.mtime != -1)
INFOF("config file %s -- detected new version", conffile_path());
}
return cf_om_load();
}
int cf_om_save(const struct cf_om_node *root)
int cf_om_save()
{
if (cf_om_root) {
const char *path = conffile_path();
@ -157,7 +153,7 @@ int cf_om_save(const struct cf_om_node *root)
if ((outf = fopen(tempfile, "w")) == NULL)
return WHYF_perror("fopen(%s, \"w\")", tempfile);
struct cf_om_iterator it;
for (cf_om_iter_start(&it, root); it.node; cf_om_iter_next(&it))
for (cf_om_iter_start(&it, cf_om_root); it.node; cf_om_iter_next(&it))
if (it.node->text)
fprintf(outf, "%s=%s\n", it.node->fullkey, it.node->text);
if (fclose(outf) == EOF)
@ -179,28 +175,33 @@ int cf_om_save(const struct cf_om_node *root)
int cf_init()
{
cf_limbo = 1;
return cf_dfl_config_main(&config) == CFERROR ? -1 : 0;
if (cf_dfl_config_main(&config) == CFERROR)
return -1;
debug = config.debug;
return 0;
}
int cf_load()
static int load_and_parse(int permissive)
{
int result = CFOK;
if (cf_limbo)
result = cf_dfl_config_main(&config);
if (result == CFOK) {
result = load();
if (result == CFOK) {
if (result == CFOK || result == CFEMPTY) {
result = CFOK;
struct config_main new_config;
memset(&new_config, 0, sizeof new_config);
result = cf_dfl_config_main(&new_config);
if (result == CFOK) {
result = cf_om_root ? cf_opt_config_main(&new_config, cf_om_root) : CFEMPTY;
if (result == CFOK || result == CFEMPTY) {
result = CFOK;
config = new_config;
config_meta = conffile_meta;
cf_limbo = 0;
return 0;
} else if (result != CFERROR) {
result &= ~CFEMPTY;
config = new_config;
cf_limbo = 0;
WARN("limping along with incomplete configuration");
@ -208,18 +209,44 @@ int cf_load()
}
}
}
debug = config.debug;
if (result == CFOK)
return 0;
cf_limbo = 0; // let log messages out
strbuf b = strbuf_alloca(180);
strbuf_cf_flag_reason(b, result);
return WHYF("config file %s not loaded -- %s", conffile_path(), strbuf_str(b));
if (!permissive)
return WHYF("config file %s not loaded -- %s", conffile_path(), strbuf_str(b));
WARNF("config file %s loaded despite problems -- %s", conffile_path(), strbuf_str(b));
return 0;
}
int cf_reload()
static int reload_and_parse(int permissive)
{
if (!cf_limbo && cf_om_root) {
if (!has_changed(&config_meta))
return 0;
INFOF("config file %s reloading", conffile_path());
}
return cf_load();
return load_and_parse(permissive);
}
int cf_load()
{
return load_and_parse(0);
}
int cf_load_permissive()
{
return load_and_parse(1);
}
int cf_reload()
{
return reload_and_parse(0);
}
int cf_reload_permissive()
{
return reload_and_parse(1);
}

9
conf.h
View File

@ -250,9 +250,10 @@ struct cf_om_iterator {
void cf_om_iter_start(struct cf_om_iterator *, const struct cf_om_node *);
int cf_om_iter_next(struct cf_om_iterator *);
struct cf_om_node *cf_om_load();
struct cf_om_node *cf_om_reload();
int cf_om_save(const struct cf_om_node *root);
struct cf_om_node *cf_om_root;
int cf_om_load();
int cf_om_reload();
int cf_om_save();
/* Diagnostic functions for use in config schema parsing functions, cf_opt_xxx(). */
@ -550,6 +551,8 @@ extern struct config_main config;
int cf_init();
int cf_load();
int cf_load_permissive();
int cf_reload();
int cf_reload_permissive();
#endif //__SERVALDNA_CONFIG_H

View File

@ -67,7 +67,7 @@ int is_configvarname(const char *text)
const char *const textend = text + strlen(text);
const char *key = text;
const char *keyend = NULL;
while (key < textend && (keyend = cf_find_keyend(key, textend)) != NULL)
while (key <= textend && (keyend = cf_find_keyend(key, textend)) != NULL)
key = keyend + 1;
return keyend != NULL;
}
@ -240,6 +240,8 @@ void cf_om_dump_node(const struct cf_om_node *node, int indent)
const char *cf_om_get(const struct cf_om_node *node, const char *fullkey)
{
if (node == NULL)
return NULL;
const char *fullkeyend = fullkey + strlen(fullkey);
const char *key = fullkey;
const char *keyend = NULL;
@ -333,9 +335,11 @@ void _cf_warn_nodev(struct __sourceloc __whence, const struct cf_om_node *node,
if (node->source && node->line_number)
strbuf_sprintf(b, "%s:%u: ", node->source, node->line_number);
strbuf_puts(b, "configuration option \"");
strbuf_puts(b, node->fullkey);
if (node->fullkey && node->fullkey[0])
strbuf_puts(b, node->fullkey);
if (key && key[0]) {
strbuf_putc(b, '.');
if (node->fullkey && node->fullkey[0])
strbuf_putc(b, '.');
strbuf_puts(b, key);
}
strbuf_puts(b, "\" ");

View File

@ -302,7 +302,7 @@ END_ARRAY(10)
// The top level.
STRUCT(main)
NODE_STRUCT(interface_list, interfaces, cf_opt_interface_list, MANDATORY)
NODE_STRUCT(interface_list, interfaces, cf_opt_interface_list,)
SUB_STRUCT(log, log,)
SUB_STRUCT(server, server,)
SUB_STRUCT(monitor, monitor,)

View File

@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <fcntl.h>
#include "serval.h"
#include "conf.h"
#include "cli.h"
#include "monitor-client.h"
@ -45,7 +46,7 @@ struct monitor_command_handler monitor_handlers[]={
{.command="", .handler=remote_print},
};
int app_monitor_cli(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_monitor_cli(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
struct pollfd fds[2];
struct monitor_state *state;

View File

@ -382,7 +382,7 @@ void monitor_get_all_supported_codecs(unsigned char *codecs){
}
}
static int monitor_set(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_set(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct monitor_context *c=context;
if (strcase_startswith((char *)argv[1],"vomp",NULL)){
c->flags|=MONITOR_VOMP;
@ -410,7 +410,7 @@ static int monitor_set(int argc, const char *const *argv, struct command_line_op
return 0;
}
static int monitor_clear(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_clear(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct monitor_context *c=context;
if (strcase_startswith((char *)argv[1],"vomp",NULL))
c->flags&=~MONITOR_VOMP;
@ -430,7 +430,7 @@ static int monitor_clear(int argc, const char *const *argv, struct command_line_
return 0;
}
static int monitor_lookup_match(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_lookup_match(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct monitor_context *c=context;
const char *sid=argv[2];
const char *ext=argv[4];
@ -453,7 +453,7 @@ static int monitor_lookup_match(int argc, const char *const *argv, struct comman
return 0;
}
static int monitor_call(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_call(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct monitor_context *c=context;
unsigned char sid[SID_SIZE];
if (stowSid(sid, 0, argv[1]) == -1)
@ -466,7 +466,7 @@ static int monitor_call(int argc, const char *const *argv, struct command_line_o
return 0;
}
static int monitor_call_ring(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_call_ring(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct vomp_call_state *call=vomp_find_call_by_session(strtol(argv[1],NULL,16));
if (!call)
monitor_tell_formatted(MONITOR_VOMP, "\nHANGUP:%s\n", argv[1]);
@ -475,7 +475,7 @@ static int monitor_call_ring(int argc, const char *const *argv, struct command_l
return 0;
}
static int monitor_call_pickup(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_call_pickup(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct vomp_call_state *call=vomp_find_call_by_session(strtol(argv[1],NULL,16));
if (!call)
monitor_tell_formatted(MONITOR_VOMP, "\nHANGUP:%s\n", argv[1]);
@ -484,7 +484,7 @@ static int monitor_call_pickup(int argc, const char *const *argv, struct command
return 0;
}
static int monitor_call_audio(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_call_audio(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct monitor_context *c=context;
struct vomp_call_state *call=vomp_find_call_by_session(strtol(argv[1],NULL,16));
if (!call)
@ -494,7 +494,7 @@ static int monitor_call_audio(int argc, const char *const *argv, struct command_
return 0;
}
static int monitor_call_hangup(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_call_hangup(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct vomp_call_state *call=vomp_find_call_by_session(strtol(argv[1],NULL,16));
if (!call)
monitor_tell_formatted(MONITOR_VOMP, "\nHANGUP:%s\n", argv[1]);
@ -503,7 +503,7 @@ static int monitor_call_hangup(int argc, const char *const *argv, struct command
return 0;
}
static int monitor_call_dtmf(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int monitor_call_dtmf(int argc, const char *const *argv, const struct command_line_option *o, void *context){
struct monitor_context *c=context;
struct vomp_call_state *call=vomp_find_call_by_session(strtol(argv[1],NULL,16));
if (!call)
@ -545,7 +545,8 @@ int monitor_process_command(struct monitor_context *c)
char *argv[16]={NULL,};
int argc = parse_argv(c->line, ' ', argv, 16);
if (cli_execute(NULL, argc, (const char *const*)argv, monitor_options, c))
int res = cli_parse(argc, (const char *const*)argv, monitor_options);
if (res == -1 || cli_invoke(&monitor_options[res], argc, (const char *const*)argv, c))
return monitor_write_error(c, "Invalid command");
return 0;
}

View File

@ -58,7 +58,8 @@ static PaCtx *pa_phone_setup(void);
/* Declarations */
int
app_pa_phone(int argc, const char *const *argv, struct command_line_option *o) {
app_pa_phone(int argc, const char *const *argv, const struct command_line_option *o)
{
PaCtx *ctx;
if ((ctx = pa_phone_setup()) == NULL)

View File

@ -513,7 +513,7 @@ static int rhizome_sync_with_peers(int mode, int peer_count, const struct config
return 0;
}
int app_rhizome_direct_sync(int argc, const char *const *argv, struct command_line_option *o, void *context)
int app_rhizome_direct_sync(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
/* Attempt to connect with a remote Rhizome Direct instance,
and negotiate which BARs to synchronise. */

View File

@ -642,12 +642,12 @@ int directory_registration();
int directory_service_init();
struct command_line_option;
int app_rhizome_direct_sync(int argc, const char *const *argv, struct command_line_option *o, void *context);
int app_rhizome_direct_sync(int argc, const char *const *argv, const struct command_line_option *o, void *context);
#ifdef HAVE_VOIPTEST
int app_pa_phone(int argc, const char *const *argv, struct command_line_option *o, void *context);
int app_pa_phone(int argc, const char *const *argv, const struct command_line_option *o, void *context);
#endif
int app_monitor_cli(int argc, const char *const *argv, struct command_line_option *o, void *context);
int app_vomp_console(int argc, const char *const *argv, struct command_line_option *o, void *context);
int app_monitor_cli(int argc, const char *const *argv, const struct command_line_option *o, void *context);
int app_vomp_console(int argc, const char *const *argv, const struct command_line_option *o, void *context);
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);

View File

@ -100,19 +100,23 @@ test_Del() {
assertStdoutLineCount '==' 0
}
doc_CaseInsensitive="Config item names are case insensitive"
test_CaseInsensitive() {
doc_CaseSensitive="Config item names are case sensitive"
test_CaseSensitive() {
executeOk_servald config set foo bar
executeOk_servald config set Foo xxx
executeOk_servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
executeOk_servald config get Foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^Foo=bar$'
assertStdoutGrep --stdout --stderr --matches=1 '^Foo=xxx$'
executeOk_servald config set FOO wah
executeOk_servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=wah$'
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
executeOk_servald config get FOO
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^FOO=wah$'
}
doc_DotsInNames="Config item names can have internal dots"
@ -122,14 +126,14 @@ test_DotsInNames() {
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.bar=yes$'
execute $servald config set foo. yes
assertExitStatus '!=' 0
assertExitStatus --stderr '!=' 0
execute $servald config set .foo yes
assertExitStatus '!=' 0
assertExitStatus --stderr '!=' 0
execute $servald config set foo..bar yes
assertExitStatus '!=' 0
assertExitStatus --stderr '!=' 0
executeOk_servald config set foo.x.bar yes
executeOk_servald config get foo.x.bar
assertStdoutLineCount '==' 1
assertStdoutLineCount --stderr '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.x\.bar=yes$'
}

View File

@ -25,6 +25,7 @@
#include <fcntl.h>
#include "serval.h"
#include "conf.h"
#include "cli.h"
#include "monitor-client.h"
#include "str.h"
@ -186,7 +187,7 @@ struct monitor_command_handler console_handlers[]={
{.command="MONITORSTATUS", .handler=remote_noop},
};
static int console_dial(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int console_dial(int argc, const char *const *argv, const struct command_line_option *o, void *context){
if (call_token!=-1){
printf("Already in a call\n");
return 0;
@ -198,7 +199,7 @@ static int console_dial(int argc, const char *const *argv, struct command_line_o
return 0;
}
static int console_answer(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int console_answer(int argc, const char *const *argv, const struct command_line_option *o, void *context){
if (call_token==-1){
printf("No active call to answer\n");
fflush(stdout);
@ -207,7 +208,7 @@ static int console_answer(int argc, const char *const *argv, struct command_line
return 0;
}
static int console_hangup(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int console_hangup(int argc, const char *const *argv, const struct command_line_option *o, void *context){
if (call_token==-1){
printf("No call to hangup\n");
fflush(stdout);
@ -216,7 +217,7 @@ static int console_hangup(int argc, const char *const *argv, struct command_line
return 0;
}
static int console_usage(int argc, const char *const *argv, struct command_line_option *o, void *context);
static int console_usage(int argc, const char *const *argv, const struct command_line_option *o, void *context);
struct command_line_option console_commands[]={
{console_answer,{"answer",NULL},0,"Answer an incoming phone call"},
@ -226,7 +227,7 @@ struct command_line_option console_commands[]={
{NULL},
};
static int console_usage(int argc, const char *const *argv, struct command_line_option *o, void *context){
static int console_usage(int argc, const char *const *argv, const struct command_line_option *o, void *context){
cli_usage(console_commands);
fflush(stdout);
return 0;
@ -236,9 +237,12 @@ static void console_command(char *line){
char *argv[16];
int argc = parse_argv(line, ' ', argv, 16);
if (cli_execute(NULL, argc, (const char *const*)argv, console_commands, NULL)){
int ret = cli_parse(argc, (const char *const*)argv, console_commands);
if (ret == -1) {
printf("Unknown command, try help\n");
fflush(stdout);
} else {
cli_invoke(&console_commands[ret], argc, (const char *const*)argv, NULL);
}
}
@ -279,7 +283,8 @@ static void monitor_read(struct sched_ent *alarm){
}
}
int app_vomp_console(int argc, const char *const *argv, struct command_line_option *o, void *context){
int app_vomp_console(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{
static struct profile_total stdin_profile={
.name="read_lines",
};