nghttpx: Return std::unique_ptr from parse_config_str_list

This commit is contained in:
Tatsuhiro Tsujikawa 2014-04-08 22:44:30 +09:00
parent f9f6cdc93d
commit 6326aec089
3 changed files with 15 additions and 14 deletions

View File

@ -1168,11 +1168,11 @@ int main(int argc, char **argv)
if(!get_config()->npn_list) {
mod_config()->npn_list = parse_config_str_list(&mod_config()->npn_list_len,
DEFAULT_NPN_LIST);
DEFAULT_NPN_LIST).release();
}
if(!get_config()->tls_proto_list) {
mod_config()->tls_proto_list = parse_config_str_list
(&mod_config()->tls_proto_list_len, DEFAULT_TLS_PROTO_LIST);
(&mod_config()->tls_proto_list_len, DEFAULT_TLS_PROTO_LIST).release();
}
if(!get_config()->subcerts.empty()) {

View File

@ -229,12 +229,12 @@ void set_config_str(char **destp, const char *val)
*destp = strdup(val);
}
char** parse_config_str_list(size_t *outlen, const char *s)
std::unique_ptr<char*[]> parse_config_str_list(size_t *outlen, const char *s)
{
size_t len = 1;
for(const char *first = s, *p = nullptr; (p = strchr(first, ','));
++len, first = p + 1);
auto list = new char*[len];
auto list = util::make_unique<char*[]>(len);
auto first = strdup(s);
len = 0;
for(;;) {
@ -468,11 +468,11 @@ int parse_config(const char *opt, const char *optarg)
} else if(util::strieq(opt, SHRPX_OPT_NPN_LIST)) {
delete [] mod_config()->npn_list;
mod_config()->npn_list = parse_config_str_list(&mod_config()->npn_list_len,
optarg);
optarg).release();
} else if(util::strieq(opt, SHRPX_OPT_TLS_PROTO_LIST)) {
delete [] mod_config()->tls_proto_list;
mod_config()->tls_proto_list = parse_config_str_list
(&mod_config()->tls_proto_list_len, optarg);
(&mod_config()->tls_proto_list_len, optarg).release();
} else if(util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT)) {
mod_config()->verify_client = util::strieq(optarg, "yes");
} else if(util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT_CACERT)) {

View File

@ -34,6 +34,7 @@
#include <arpa/inet.h>
#include <cstdio>
#include <vector>
#include <memory>
#include <event.h>
#include <openssl/ssl.h>
@ -274,15 +275,15 @@ int load_config(const char *filename);
std::string read_passwd_from_file(const char *filename);
// Parses comma delimited strings in |s| and returns the array of
// pointers, each element points to the each substring in |s|. The
// number of elements are stored in |*outlen|. The |s| must be comma
// delimited list of strings. The strings must be delimited by a
// pointers, each element points to the each substring in |s|. The
// number of elements are stored in |*outlen|. The |s| must be comma
// delimited list of strings. The strings must be delimited by a
// single comma and any white spaces around it are treated as a part
// of protocol strings. This function may modify |s| and the caller
// 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);
// of protocol strings. This function may modify |s| and the caller
// must leave it as is after this call. This function copies |s| and
// first element in the return value points to it. It is caller's
// responsibility to deallocate its memory.
std::unique_ptr<char*[]> parse_config_str_list(size_t *outlen, const char *s);
// Copies NULL-terminated string |val| to |*destp|. If |*destp| is not
// NULL, it is freed before copying.