mirror of https://github.com/omar-polo/gmid.git
move parse_portno to gmid.c
it's used only to parse the -p flag. While there add check_port_num to check the range for the port.
This commit is contained in:
parent
e3b2a0f8de
commit
391825e360
12
gmid.c
12
gmid.c
|
@ -532,6 +532,18 @@ setup_configless(int argc, char **argv, const char *cgi)
|
||||||
imsg_flush(&logibuf);
|
imsg_flush(&logibuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
parse_portno(const char *p)
|
||||||
|
{
|
||||||
|
const char *errstr;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = strtonum(p, 0, UINT16_MAX, &errstr);
|
||||||
|
if (errstr != NULL)
|
||||||
|
yyerror("port number is %s: %s", errstr, p);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
1
gmid.h
1
gmid.h
|
@ -317,7 +317,6 @@ void free_config(void);
|
||||||
void drop_priv(void);
|
void drop_priv(void);
|
||||||
|
|
||||||
void yyerror(const char*, ...);
|
void yyerror(const char*, ...);
|
||||||
int parse_portno(const char*);
|
|
||||||
void parse_conf(const char*);
|
void parse_conf(const char*);
|
||||||
int cmdline_symset(char *);
|
int cmdline_symset(char *);
|
||||||
|
|
||||||
|
|
26
parse.y
26
parse.y
|
@ -78,11 +78,11 @@ char *symget(const char *);
|
||||||
|
|
||||||
struct vhost *new_vhost(void);
|
struct vhost *new_vhost(void);
|
||||||
struct location *new_location(void);
|
struct location *new_location(void);
|
||||||
int parse_portno(const char*);
|
|
||||||
char *ensure_absolute_path(char*);
|
char *ensure_absolute_path(char*);
|
||||||
int check_block_code(int);
|
int check_block_code(int);
|
||||||
char *check_block_fmt(char*);
|
char *check_block_fmt(char*);
|
||||||
int check_strip_no(int);
|
int check_strip_no(int);
|
||||||
|
int check_port_num(int);
|
||||||
int check_prefork_num(int);
|
int check_prefork_num(int);
|
||||||
void advance_loc(void);
|
void advance_loc(void);
|
||||||
void only_once(const void*, const char*);
|
void only_once(const void*, const char*);
|
||||||
|
@ -190,7 +190,7 @@ option : TCHROOT string { conf.chroot = $2; }
|
||||||
add_mime(&conf.mime, $2, $3);
|
add_mime(&conf.mime, $2, $3);
|
||||||
}
|
}
|
||||||
| TMAP string TTOEXT string { add_mime(&conf.mime, $2, $4); }
|
| TMAP string TTOEXT string { add_mime(&conf.mime, $2, $4); }
|
||||||
| TPORT NUM { conf.port = $2; }
|
| TPORT NUM { conf.port = check_port_num($2); }
|
||||||
| TPREFORK NUM { conf.prefork = check_prefork_num($2); }
|
| TPREFORK NUM { conf.prefork = check_prefork_num($2); }
|
||||||
| TPROTOCOLS string {
|
| TPROTOCOLS string {
|
||||||
if (tls_config_parse_protocols(&conf.protos, $2) == -1)
|
if (tls_config_parse_protocols(&conf.protos, $2) == -1)
|
||||||
|
@ -864,18 +864,6 @@ new_location(void)
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
parse_portno(const char *p)
|
|
||||||
{
|
|
||||||
const char *errstr;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = strtonum(p, 0, UINT16_MAX, &errstr);
|
|
||||||
if (errstr != NULL)
|
|
||||||
yyerror("port number is %s: %s", errstr, p);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
ensure_absolute_path(char *path)
|
ensure_absolute_path(char *path)
|
||||||
{
|
{
|
||||||
|
@ -923,6 +911,16 @@ check_strip_no(int n)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
check_port_num(int n)
|
||||||
|
{
|
||||||
|
if (n <= 0 || n >= UINT16_MAX)
|
||||||
|
yyerror("port number is %s: %d",
|
||||||
|
n <= 0 ? "too small" : "too large",
|
||||||
|
n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
check_prefork_num(int n)
|
check_prefork_num(int n)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue