# HG changeset patch # User Thomas Klausner # Date 1360763267 -3600 # Node ID cce5d4bace82ed7cbe3590543ea1079ae386b60d # Parent 5d9229144cacae395abd0c730d79ea4a501b6c58 Make config file parameter const and convert another fprintf to TRACE_DEBUG_ERROR. diff -r 5d9229144cac -r cce5d4bace82 include/freeDiameter/libfdcore.h --- a/include/freeDiameter/libfdcore.h Tue Feb 12 12:38:32 2013 +0100 +++ b/include/freeDiameter/libfdcore.h Wed Feb 13 14:47:47 2013 +0100 @@ -86,7 +86,7 @@ const char *fd_core_version(void); /* Parse the freeDiameter.conf configuration file, load the extensions */ -int fd_core_parseconf(char * conffile); +int fd_core_parseconf(const char * conffile); /* Start the server & client threads */ int fd_core_start(void); @@ -110,7 +110,7 @@ struct fd_config { int cnf_eyec; /* Eye catcher: EYEC_CONFIG */ - char *cnf_file; /* Configuration file to parse, default is DEFAULT_CONF_FILE */ + const char *cnf_file; /* Configuration file to parse, default is DEFAULT_CONF_FILE */ DiamId_t cnf_diamid; /* Diameter Identity of the local peer (FQDN -- ASCII) */ size_t cnf_diamid_len;/* cached length of the previous string */ @@ -349,7 +349,7 @@ * (other standard errors may be returned, too, with their standard meaning. Example: * ENOMEM : Memory allocation for the new object element failed.) */ -int fd_peer_add ( struct peer_info * info, char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data ); +int fd_peer_add ( struct peer_info * info, const char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data ); /* * FUNCTION: fd_peer_getbyid diff -r 5d9229144cac -r cce5d4bace82 libfdcore/config.c --- a/libfdcore/config.c Tue Feb 12 12:38:32 2013 +0100 +++ b/libfdcore/config.c Wed Feb 13 14:47:47 2013 +0100 @@ -229,7 +229,7 @@ int fd_conf_parse() { extern FILE * fddin; - char * orig = NULL; + const char * orig = NULL; /* Attempt to find the configuration file */ if (!fd_g_config->cnf_file) @@ -237,23 +237,18 @@ fddin = fopen(fd_g_config->cnf_file, "r"); if ((fddin == NULL) && (*fd_g_config->cnf_file != '/')) { + char * new_cnf = NULL; /* We got a relative path, attempt to add the default directory prefix */ orig = fd_g_config->cnf_file; - CHECK_MALLOC( fd_g_config->cnf_file = malloc(strlen(orig) + strlen(DEFAULT_CONF_PATH) + 2) ); /* we will not free it, but not important */ - sprintf( fd_g_config->cnf_file, DEFAULT_CONF_PATH "/%s", orig ); + CHECK_MALLOC( new_cnf = malloc(strlen(orig) + strlen(DEFAULT_CONF_PATH) + 2) ); /* we will not free it, but not important */ + sprintf( new_cnf, DEFAULT_CONF_PATH "/%s", orig ); + fd_g_config->cnf_file = new_cnf; fddin = fopen(fd_g_config->cnf_file, "r"); } if (fddin == NULL) { int ret = errno; - if (orig) { - fprintf(stderr, "Unable to open configuration file for reading\n" - "Tried the following locations:\n" - " - %s\n" - " - %s\n" - "Error: %s\n", orig, fd_g_config->cnf_file, strerror(ret)); - } else { - fprintf(stderr, "Unable to open '%s' for reading: %s\n", fd_g_config->cnf_file, strerror(ret)); - } + TRACE_DEBUG_ERROR("Unable to open configuration file for reading; tried the following locations: %s%s%s; Error: %s\n", + orig ?: "", orig? " and " : "", fd_g_config->cnf_file, strerror(ret)); return ret; } diff -r 5d9229144cac -r cce5d4bace82 libfdcore/core.c --- a/libfdcore/core.c Tue Feb 12 12:38:32 2013 +0100 +++ b/libfdcore/core.c Wed Feb 13 14:47:47 2013 +0100 @@ -225,7 +225,7 @@ } /* Parse the freeDiameter.conf configuration file, load the extensions */ -int fd_core_parseconf(char * conffile) +int fd_core_parseconf(const char * conffile) { TRACE_ENTRY("%p", conffile); diff -r 5d9229144cac -r cce5d4bace82 libfdcore/peers.c --- a/libfdcore/peers.c Tue Feb 12 12:38:32 2013 +0100 +++ b/libfdcore/peers.c Wed Feb 13 14:47:47 2013 +0100 @@ -90,7 +90,7 @@ } /* Add a new peer entry */ -int fd_peer_add ( struct peer_info * info, char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data ) +int fd_peer_add ( struct peer_info * info, const char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data ) { struct fd_peer *p = NULL; struct fd_list * li, *li_inf;