From 5d934706763832f44166b083079474a036d6154d Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Fri, 29 Mar 2002 08:46:34 +0000 Subject: [PATCH] updates. --- CHANGES | 6 +++++ apps/silcd/server.c | 19 +++++++++------- apps/silcd/serverconfig.c | 48 ++++++++++++++++++--------------------- apps/silcd/serverconfig.h | 2 +- apps/silcd/silcd.c | 4 +--- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/CHANGES b/CHANGES index e0bf6491..ff8dfd07 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Fri Mar 29 10:41:07 EET 2002 Pekka Riikonen + + * And yet again reverted back the config thing since Johnny + screwed it up. Affected file silcd/serverconfig.[ch], server.c, + and silcd.c. + Fri Mar 29 03:26:12 CET 2002 Johnny Mnemonic * Added preliminary checking during config parsing for a valid diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 6db5a87c..32c2ac81 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -148,6 +148,10 @@ bool silc_server_init(SilcServer server) SILC_LOG_DEBUG(("Initializing server")); + /* Take config object for us */ + silc_server_config_ref(&server->config_ref, server->config, + server->config); + /* Steal public and private key from the config object */ server->public_key = server->config->server_info->public_key; server->private_key = server->config->server_info->private_key; @@ -366,19 +370,18 @@ bool silc_server_rehash(SilcServer server) return FALSE; } - /* Config file parsing went fine, so our old config is gone now. We - unreference the basic pointer and it should be destroyed as soon - as all other references are released. */ + /* Our old config is gone now. We'll unreference our reference made in + silc_server_init and then destroy it since we are destroying it + underneath the application (layer which called silc_server_init). */ silc_server_config_unref(&server->config_ref); + silc_server_config_destroy(server->config); + + /* Take new config context */ server->config = newconfig; silc_server_config_ref(&server->config_ref, server->config, server->config); /* Fix the server_name field */ - if (!strcmp(server->server_name, newconfig->server_info->server_name)) { - /* We don't need any update */ - silc_free(newconfig->server_info->server_name); - newconfig->server_info->server_name = NULL; - } else { + if (strcmp(server->server_name, newconfig->server_info->server_name)) { silc_free(server->server_name); server->server_name = newconfig->server_info->server_name; newconfig->server_info->server_name = NULL; diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index 0d217e7c..b4c264b3 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -884,10 +884,6 @@ SILC_CONFIG_CALLBACK(fetch_server) goto got_err; } } - else if (!strcmp(name, "versionid")) { - CONFIG_IS_DOUBLE(tmp->version); - tmp->version = strdup((char *) val); - } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); tmp->param = my_find_param(config, (char *) val, line); @@ -906,7 +902,6 @@ SILC_CONFIG_CALLBACK(fetch_server) got_err: silc_free(tmp->host); - silc_free(tmp->version); CONFIG_FREE_AUTH(tmp); silc_free(tmp); config->tmp = NULL; @@ -966,10 +961,6 @@ SILC_CONFIG_CALLBACK(fetch_router) goto got_err; } } - else if (!strcmp(name, "versionid")) { - CONFIG_IS_DOUBLE(tmp->version); - tmp->version = strdup((char *) val); - } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); tmp->param = my_find_param(config, (char *) val, line); @@ -1004,7 +995,6 @@ SILC_CONFIG_CALLBACK(fetch_router) got_err: silc_free(tmp->host); - silc_free(tmp->version); silc_free(tmp->backup_replace_ip); CONFIG_FREE_AUTH(tmp); silc_free(tmp); @@ -1144,7 +1134,6 @@ static const SilcConfigTable table_serverconn[] = { { "host", SILC_CONFIG_ARG_STRE, fetch_server, NULL }, { "passphrase", SILC_CONFIG_ARG_STR, fetch_server, NULL }, { "publickey", SILC_CONFIG_ARG_STR, fetch_server, NULL }, - { "versionid", SILC_CONFIG_ARG_STR, fetch_server, NULL }, { "params", SILC_CONFIG_ARG_STR, fetch_server, NULL }, { "backup", SILC_CONFIG_ARG_TOGGLE, fetch_server, NULL }, { 0, 0, 0, 0 } @@ -1155,7 +1144,6 @@ static const SilcConfigTable table_routerconn[] = { { "port", SILC_CONFIG_ARG_INT, fetch_router, NULL }, { "passphrase", SILC_CONFIG_ARG_STR, fetch_router, NULL }, { "publickey", SILC_CONFIG_ARG_STR, fetch_router, NULL }, - { "versionid", SILC_CONFIG_ARG_STR, fetch_router, NULL }, { "params", SILC_CONFIG_ARG_STR, fetch_router, NULL }, { "initiator", SILC_CONFIG_ARG_TOGGLE, fetch_router, NULL }, { "backuphost", SILC_CONFIG_ARG_STRE, fetch_router, NULL }, @@ -1269,6 +1257,7 @@ SilcServerConfig silc_server_config_alloc(const char *filename) /* Set default to configuration parameters */ silc_server_config_set_defaults(config_new); + config_new->refcount = 1; return config_new; } @@ -1291,16 +1280,8 @@ void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config, void silc_server_config_unref(SilcServerConfigRef *ref) { - SilcServerConfig config = ref->config; - - if (ref->ref_ptr) { - config->refcount--; - SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %hu->%hu", config, - config->refcount + 1, config->refcount)); - if (!config->refcount) - silc_server_config_destroy(config); - ref->ref_ptr = NULL; - } + if (ref->ref_ptr) + silc_server_config_destroy(ref->config); } /* Destroy a config object with all his children lists */ @@ -1309,9 +1290,19 @@ void silc_server_config_destroy(SilcServerConfig config) { void *tmp; + config->refcount--; + SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %hu->%hu", config, + config->refcount + 1, config->refcount)); + if (config->refcount > 0) + return; + SILC_LOG_DEBUG(("Freeing config context")); + /* Destroy general config stuff */ silc_free(config->module_path); + silc_free(config->param.version_protocol); + silc_free(config->param.version_software); + silc_free(config->param.version_software_vendor); /* Destroy Logging channels */ if (config->logging_info) @@ -1362,8 +1353,15 @@ void silc_server_config_destroy(SilcServerConfig config) silc_free(di->name); silc_free(di); } - SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient, - config->clients) + SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigConnParams, + config->conn_params) + silc_free(di->name); + silc_free(di->version_protocol); + silc_free(di->version_software); + silc_free(di->version_software_vendor); + silc_free(di); + } + SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient, config->clients) silc_free(di->host); CONFIG_FREE_AUTH(di); silc_free(di); @@ -1383,14 +1381,12 @@ void silc_server_config_destroy(SilcServerConfig config) SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigServer, config->servers) silc_free(di->host); - silc_free(di->version); CONFIG_FREE_AUTH(di); silc_free(di); } SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigRouter, config->routers) silc_free(di->host); - silc_free(di->version); silc_free(di->backup_replace_ip); CONFIG_FREE_AUTH(di); silc_free(di); diff --git a/apps/silcd/serverconfig.h b/apps/silcd/serverconfig.h index a842576b..cd5e2201 100644 --- a/apps/silcd/serverconfig.h +++ b/apps/silcd/serverconfig.h @@ -150,7 +150,7 @@ typedef struct { void *tmp; /* Reference count (when this reaches zero, config object is destroyed) */ - SilcInt16 refcount; + SilcInt32 refcount; /* The General section */ char *module_path; diff --git a/apps/silcd/silcd.c b/apps/silcd/silcd.c index 2ad30724..82d29d7a 100644 --- a/apps/silcd/silcd.c +++ b/apps/silcd/silcd.c @@ -381,9 +381,6 @@ int main(int argc, char **argv) if (silcd->config == NULL) goto fail; silcd->config_file = silcd_config_file; - /* Since silc_server_config_alloc returns an unreferenced config object - we must immediately increment it. */ - silc_server_config_ref(&silcd->config_ref, silcd->config, silcd->config); /* Check for another silcd running */ silc_server_checkpid(silcd); @@ -428,6 +425,7 @@ int main(int argc, char **argv) /* Stop the server and free it. */ silc_server_stop(silcd); silc_server_free(silcd); + silc_server_config_destroy(silcd->config); /* Flush the logging system */ silc_log_flush_all(); -- 2.24.0