Rename cf_opt_port() to cf_opt_uint16_nonzero()

Improves the usefulness of the 'config schema' output.
This commit is contained in:
Andrew Bettison 2012-12-07 11:14:05 +10:30
parent b4f6aa5ea2
commit ecdf32fbe2
3 changed files with 24 additions and 14 deletions

3
conf.h
View File

@ -540,12 +540,13 @@ int cf_opt_rhizome_peer_from_uri(struct config_rhizome_peer *, const char *uri);
int cf_opt_str(char *str, size_t len, const char *text);
int cf_opt_str_nonempty(char *str, size_t len, const char *text);
int cf_opt_int(int *intp, const char *text);
int cf_opt_uint16(uint16_t *intp, const char *text);
int cf_opt_uint16_nonzero(uint16_t *intp, const char *text);
int cf_opt_int32_nonneg(int32_t *intp, const char *text);
int cf_opt_uint32_nonzero(uint32_t *intp, const char *text);
int cf_opt_uint64_scaled(uint64_t *intp, const char *text);
int cf_opt_protocol(char *str, size_t len, const char *text);
int cf_opt_in_addr(struct in_addr *addrp, const char *text);
int cf_opt_port(unsigned short *portp, const char *text);
int cf_opt_sid(sid_t *sidp, const char *text);
int cf_opt_rhizome_bk(rhizome_bk_t *bkp, const char *text);
int cf_opt_interface_type(short *typep, const char *text);

View File

@ -297,19 +297,28 @@ int cf_opt_in_addr(struct in_addr *addrp, const char *text)
return CFOK;
}
int cf_opt_port(unsigned short *portp, const char *text)
int cf_opt_uint16(uint16_t *intp, const char *text)
{
unsigned short port = 0;
unsigned short ui = 0;
const char *p;
for (p = text; isdigit(*p); ++p) {
unsigned oport = port;
port = port * 10 + *p - '0';
if (port / 10 != oport)
unsigned oui = ui;
ui = ui * 10 + *p - '0';
if (ui / 10 != oui)
break;
}
if (*p || port == 0)
if (*p)
return CFINVALID;
*portp = port;
*intp = ui;
return CFOK;
}
int cf_opt_uint16_nonzero(uint16_t *intp, const char *text)
{
uint16_t ui;
if (cf_opt_uint16_nonzero(&ui, text) != CFOK || ui == 0)
return CFINVALID;
*intp = ui;
return CFOK;
}
@ -463,7 +472,7 @@ static int cf_opt_network_interface_legacy(struct config_network_interface *nifp
if (len) {
char buf[len + 1];
strncpy(buf, port, len)[len] = '\0';
int result = cf_opt_port(&nif.port, buf);
int result = cf_opt_uint16_nonzero(&nif.port, buf);
switch (result) {
case CFERROR: return CFERROR;
case CFOK: break;

View File

@ -216,8 +216,8 @@ END_STRUCT
STRUCT(olsr)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, OLSR is used for mesh routing")
ATOM(uint16_t, remote_port,4130, cf_opt_port,, "Remote port number")
ATOM(uint16_t, local_port, 4131, cf_opt_port,, "Local port number")
ATOM(uint16_t, remote_port,4130, cf_opt_uint16_nonzero,, "Remote port number")
ATOM(uint16_t, local_port, 4131, cf_opt_uint16_nonzero,, "Local port number")
END_STRUCT
ARRAY(argv, SORTED NO_DUPLICATES, vld_argv)
@ -237,7 +237,7 @@ END_STRUCT
STRUCT(rhizome_peer)
STRING(25, protocol, "http", cf_opt_protocol,, "Protocol name")
STRING(256, host, "", cf_opt_str_nonempty, MANDATORY, "Host name or IP address")
ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_port,, "Port number")
ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_uint16_nonzero,, "Port number")
END_STRUCT
ARRAY(peerlist,)
@ -277,7 +277,7 @@ END_STRUCT
STRUCT(host)
STRING(INTERFACE_NAME_STRLEN, interface, "", cf_opt_str_nonempty, MANDATORY, "Interface name")
ATOM(struct in_addr, address, (struct in_addr){htonl(INADDR_NONE)}, cf_opt_in_addr, MANDATORY, "Host IP address")
ATOM(uint16_t, port, PORT_DNA, cf_opt_port,, "Port number")
ATOM(uint16_t, port, PORT_DNA, cf_opt_uint16_nonzero,, "Port number")
END_STRUCT
ARRAY(host_list, NO_DUPLICATES)
@ -290,7 +290,7 @@ ATOM(int, exclude, 0, cf_opt_boolean,, "If true, do not use
ATOM(struct pattern_list, match, PATTERN_LIST_EMPTY, cf_opt_pattern_list,, "Names that match network interface")
STRING(256, dummy, "", cf_opt_str_nonempty,, "Path of dummy file, absolute or relative to server.dummy_interface_dir")
ATOM(short, type, OVERLAY_INTERFACE_WIFI, cf_opt_interface_type,, "Type of network interface")
ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_port,, "Port number for network interface")
ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_uint16_nonzero,, "Port number for network interface")
ATOM(uint64_t, speed, 1000000, cf_opt_uint64_scaled,, "Speed in bits per second")
ATOM(int, mdp_tick_ms, -1, cf_opt_int32_nonneg,, "Override MDP tick interval for this interface")
END_STRUCT