nghttpx: Make parse_config_npn_list generic
This commit is contained in:
parent
74d82aac56
commit
3e21bed4f9
|
@ -1088,7 +1088,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!get_config()->npn_list) {
|
if(!get_config()->npn_list) {
|
||||||
parse_config_npn_list(DEFAULT_NPN_LIST);
|
mod_config()->npn_list = parse_config_str_list(&mod_config()->npn_list_len,
|
||||||
|
DEFAULT_NPN_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!get_config()->subcerts.empty()) {
|
if(!get_config()->subcerts.empty()) {
|
||||||
|
|
|
@ -221,15 +221,13 @@ void set_config_str(char **destp, const char *val)
|
||||||
*destp = strdup(val);
|
*destp = strdup(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_config_npn_list(const char *s)
|
char** parse_config_str_list(size_t *outlen, const char *s)
|
||||||
{
|
{
|
||||||
delete [] mod_config()->npn_list;
|
|
||||||
size_t len = 1;
|
size_t len = 1;
|
||||||
for(const char *first = s, *p = nullptr; (p = strchr(first, ','));
|
for(const char *first = s, *p = nullptr; (p = strchr(first, ','));
|
||||||
++len, first = p + 1);
|
++len, first = p + 1);
|
||||||
auto list = new char*[len];
|
auto list = new char*[len];
|
||||||
auto t = strdup(s);
|
auto first = strdup(s);
|
||||||
auto first = t;
|
|
||||||
len = 0;
|
len = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
auto p = strchr(first, ',');
|
auto p = strchr(first, ',');
|
||||||
|
@ -241,9 +239,8 @@ int parse_config_npn_list(const char *s)
|
||||||
first = p + 1;
|
first = p + 1;
|
||||||
}
|
}
|
||||||
list[len++] = first;
|
list[len++] = first;
|
||||||
mod_config()->npn_list = list;
|
*outlen = len;
|
||||||
mod_config()->npn_list_len = len;
|
return list;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_config(const char *opt, const char *optarg)
|
int parse_config(const char *opt, const char *optarg)
|
||||||
|
@ -453,7 +450,9 @@ int parse_config(const char *opt, const char *optarg)
|
||||||
} else if(util::strieq(opt, SHRPX_OPT_WRITE_BURST)) {
|
} else if(util::strieq(opt, SHRPX_OPT_WRITE_BURST)) {
|
||||||
mod_config()->write_burst = strtoul(optarg, nullptr, 10);
|
mod_config()->write_burst = strtoul(optarg, nullptr, 10);
|
||||||
} else if(util::strieq(opt, SHRPX_OPT_NPN_LIST)) {
|
} else if(util::strieq(opt, SHRPX_OPT_NPN_LIST)) {
|
||||||
parse_config_npn_list(optarg);
|
delete [] mod_config()->npn_list;
|
||||||
|
mod_config()->npn_list = parse_config_str_list(&mod_config()->npn_list_len,
|
||||||
|
optarg);
|
||||||
} else if(util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT)) {
|
} else if(util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT)) {
|
||||||
mod_config()->verify_client = util::strieq(optarg, "yes");
|
mod_config()->verify_client = util::strieq(optarg, "yes");
|
||||||
} else if(util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT_CACERT)) {
|
} else if(util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT_CACERT)) {
|
||||||
|
|
|
@ -226,13 +226,16 @@ int load_config(const char *filename);
|
||||||
// Read passwd from |filename|
|
// Read passwd from |filename|
|
||||||
std::string read_passwd_from_file(const char *filename);
|
std::string read_passwd_from_file(const char *filename);
|
||||||
|
|
||||||
// Parses NPN protocol strings in |s| and stores the protocols list in
|
// Parses comma delimited strings in |s| and returns the array of
|
||||||
// mod_config()->npn_list and assigns the number of elements in
|
// pointers, each element points to the each substring in |s|. The
|
||||||
// mod_config()->npn_list_len. The |s| must be comma delimited list of
|
// number of elements are stored in |*outlen|. The |s| must be comma
|
||||||
// protocol strings. The strings must be delimited by a single command
|
// delimited list of strings. The strings must be delimited by a
|
||||||
// and any white spaces around it are treated as a part of protocol
|
// single comma and any white spaces around it are treated as a part
|
||||||
// strings. This function always succeeds and returns 0.
|
// of protocol strings. This function may modify |s| and the caller
|
||||||
int parse_config_npn_list(const char *s);
|
// must leave it as is after this call. This function allocates memory
|
||||||
|
// to store the parsed strings and it is caller's responsibility to
|
||||||
|
// deallocate the memory.
|
||||||
|
char** parse_config_str_list(size_t *outlen, const char *s);
|
||||||
|
|
||||||
// Copies NULL-terminated string |val| to |*destp|. If |*destp| is not
|
// Copies NULL-terminated string |val| to |*destp|. If |*destp| is not
|
||||||
// NULL, it is freed before copying.
|
// NULL, it is freed before copying.
|
||||||
|
|
Loading…
Reference in New Issue