mirror of https://github.com/yandex/odyssey.git
odissey: allocate each string parameter separately
This commit is contained in:
parent
9cc6411c04
commit
351b18be92
|
@ -88,6 +88,8 @@ typedef struct
|
|||
od_parser_t parser;
|
||||
od_log_t *log;
|
||||
od_scheme_t *scheme;
|
||||
char *data;
|
||||
int data_size;
|
||||
} od_config_t;
|
||||
|
||||
#define od_keyword(name, token) { token, name, sizeof(name) - 1 }
|
||||
|
@ -148,7 +150,7 @@ static od_keyword_t od_config_keywords[] =
|
|||
};
|
||||
|
||||
static int
|
||||
od_config_read(od_config_t *config, char *config_file)
|
||||
od_config_open(od_config_t *config, char *config_file)
|
||||
{
|
||||
/* read file */
|
||||
struct stat st;
|
||||
|
@ -178,14 +180,19 @@ od_config_read(od_config_t *config, char *config_file)
|
|||
config_file);
|
||||
return -1;
|
||||
}
|
||||
config->scheme->data = config_buf;
|
||||
config->scheme->data_size = st.st_size;
|
||||
config->scheme->config_file = config_file;
|
||||
od_parser_init(&config->parser, config->scheme->data,
|
||||
config->scheme->data_size);
|
||||
config->data = config_buf;
|
||||
config->data_size = st.st_size;
|
||||
od_parser_init(&config->parser, config->data, config->data_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
od_config_close(od_config_t *config)
|
||||
{
|
||||
free(config->data);
|
||||
}
|
||||
|
||||
static void
|
||||
od_config_error(od_config_t *config, od_token_t *token, char *fmt, ...)
|
||||
{
|
||||
|
@ -262,7 +269,17 @@ od_config_next_string(od_config_t *config, char **value)
|
|||
od_config_error(config, &token, "expected 'string'");
|
||||
return false;
|
||||
}
|
||||
*value = token.value.string.pointer;
|
||||
char *copy = malloc(token.value.string.size + 1);
|
||||
if (copy == NULL) {
|
||||
od_parser_push(&config->parser, &token);
|
||||
od_config_error(config, &token, "memory allocation error");
|
||||
return false;
|
||||
}
|
||||
memcpy(copy, token.value.string.pointer, token.value.string.size);
|
||||
copy[token.value.string.size] = 0;
|
||||
if (*value)
|
||||
free(*value);
|
||||
*value = copy;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -822,13 +839,14 @@ od_config_parse(od_config_t *config)
|
|||
int od_config_load(od_scheme_t *scheme, od_log_t *log, char *config_file)
|
||||
{
|
||||
od_config_t config;
|
||||
memset(&config.parser, 0, sizeof(config.parser));
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.log = log;
|
||||
config.scheme = scheme;
|
||||
int rc;
|
||||
rc = od_config_read(&config, config_file);
|
||||
rc = od_config_open(&config, config_file);
|
||||
if (rc == -1)
|
||||
return -1;
|
||||
rc = od_config_parse(&config);
|
||||
od_config_close(&config);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -147,7 +147,6 @@ od_parser_next(od_parser_t *parser, od_token_t *token)
|
|||
}
|
||||
token->value.string.size =
|
||||
parser->pos - token->value.string.pointer;
|
||||
*parser->pos = 0;
|
||||
parser->pos++;
|
||||
return token->type;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
void od_scheme_init(od_scheme_t *scheme)
|
||||
{
|
||||
scheme->config_file = NULL;
|
||||
scheme->data = NULL;
|
||||
scheme->data_size = 0;
|
||||
scheme->daemonize = 0;
|
||||
scheme->log_debug = 0;
|
||||
scheme->log_config = 0;
|
||||
|
@ -76,8 +74,6 @@ void od_scheme_free(od_scheme_t *scheme)
|
|||
storage = od_container_of(i, od_schemestorage_t, link);
|
||||
od_schemestorage_unref(storage);
|
||||
}
|
||||
if (scheme->data)
|
||||
free(scheme->data);
|
||||
}
|
||||
|
||||
od_schemestorage_t*
|
||||
|
@ -113,12 +109,28 @@ void od_schemestorage_ref(od_schemestorage_t *storage)
|
|||
|
||||
void od_schemestorage_unref(od_schemestorage_t *storage)
|
||||
{
|
||||
if (storage->refs == 0) {
|
||||
od_list_unlink(&storage->link);
|
||||
free(storage);
|
||||
if (storage->refs > 0)
|
||||
--storage->refs;
|
||||
if (storage->refs > 0)
|
||||
return;
|
||||
}
|
||||
storage->refs--;
|
||||
if (storage->name)
|
||||
free(storage->name);
|
||||
if (storage->type)
|
||||
free(storage->type);
|
||||
if (storage->host)
|
||||
free(storage->host);
|
||||
if (storage->tls)
|
||||
free(storage->tls);
|
||||
if (storage->tls_ca_file)
|
||||
free(storage->tls_ca_file);
|
||||
if (storage->tls_key_file)
|
||||
free(storage->tls_key_file);
|
||||
if (storage->tls_cert_file)
|
||||
free(storage->tls_cert_file);
|
||||
if (storage->tls_protocols)
|
||||
free(storage->tls_protocols);
|
||||
od_list_unlink(&storage->link);
|
||||
free(storage);
|
||||
}
|
||||
|
||||
od_schemedb_t*
|
||||
|
@ -162,7 +174,6 @@ od_schemeuser_add(od_schemedb_t *db)
|
|||
user->pool_cancel = 1;
|
||||
user->pool_discard = 1;
|
||||
user->pool_rollback = 1;
|
||||
user->pool_sz = "session";
|
||||
user->pool = OD_PSESSION;
|
||||
od_list_init(&user->link);
|
||||
od_list_append(&db->users, &user->link);
|
||||
|
@ -312,7 +323,13 @@ int od_scheme_validate(od_scheme_t *scheme, od_log_t *log)
|
|||
db->name, user->user);
|
||||
return -1;
|
||||
}
|
||||
/* remote pooling mode */
|
||||
|
||||
/* pooling mode */
|
||||
if (! user->pool_sz) {
|
||||
od_error(log, "config", "db '%s' user '%s': pooling mode is not set",
|
||||
db->name, user->user);
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(user->pool_sz, "session") == 0) {
|
||||
user->pool = OD_PSESSION;
|
||||
} else
|
||||
|
|
|
@ -107,8 +107,6 @@ struct od_schemeuser
|
|||
struct od_scheme
|
||||
{
|
||||
char *config_file;
|
||||
char *data;
|
||||
int data_size;
|
||||
/* main */
|
||||
int daemonize;
|
||||
int log_debug;
|
||||
|
|
Loading…
Reference in New Issue