From 17e3e74ad5e0cf111555b3f9ded23b7e555ebf63 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 18 Jun 2019 14:49:18 +0200 Subject: [PATCH] All hash_ functions have been prefixed with `clicon_` to avoid name collision with other packages (frr) --- CHANGELOG.md | 1 + apps/cli/cli_common.c | 6 ++--- lib/clixon/clixon_hash.h | 33 ++++++++++++------------ lib/src/clixon_data.c | 52 +++++++++++++++++++------------------- lib/src/clixon_datastore.c | 6 ++--- lib/src/clixon_handle.c | 12 ++++----- lib/src/clixon_hash.c | 46 ++++++++++++++++----------------- lib/src/clixon_options.c | 22 ++++++++-------- 8 files changed, 89 insertions(+), 89 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4ae6f50..4ab298e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ ### API changes on existing features (you may need to change your code) +* All hash_ functions have been prefixed with `clicon_` to avoid name collision with other packages (frr) * Added compiled regexp parameter as part of internal yang type resolution functions * `yang_type_resolve()`, `yang_type_get()` * All internal `ys_populate_*()` functions (except ys_populate()) have switched parameters: `clicon_handle, yang_stmt *)` diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index b871c7a3..0502fd7b 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -107,7 +107,7 @@ cli_notification_register(clicon_handle h, goto done; } snprintf(logname, len, "log_socket_%s", stream); - if ((p = hash_value(cdat, logname, &len)) != NULL) + if ((p = clicon_hash_value(cdat, logname, &len)) != NULL) s_exist = *(int*)p; if (status){ /* start */ @@ -119,14 +119,14 @@ cli_notification_register(clicon_handle h, goto done; if (cligen_regfd(s, fn, arg) < 0) goto done; - if (hash_add(cdat, logname, &s, sizeof(s)) == NULL) + if (clicon_hash_add(cdat, logname, &s, sizeof(s)) == NULL) goto done; } else{ /* stop */ if (s_exist != -1){ cligen_unregfd(s_exist); } - hash_del(cdat, logname); + clicon_hash_del(cdat, logname); #if 0 /* cant turn off */ if (clicon_rpc_create_subscription(h, status, stream, format, filter, NULL) < 0) goto done; diff --git a/lib/clixon/clixon_hash.h b/lib/clixon/clixon_hash.h index 090af542..6fcca465 100644 --- a/lib/clixon/clixon_hash.h +++ b/lib/clixon/clixon_hash.h @@ -44,14 +44,14 @@ struct clicon_hash { }; typedef struct clicon_hash *clicon_hash_t; -clicon_hash_t *hash_init (void); -void hash_free (clicon_hash_t *); -clicon_hash_t hash_lookup (clicon_hash_t *head, const char *key); -void *hash_value (clicon_hash_t *head, const char *key, size_t *vlen); -clicon_hash_t hash_add (clicon_hash_t *head, const char *key, void *val, size_t vlen); -int hash_del (clicon_hash_t *head, const char *key); -int hash_dump(clicon_hash_t *head, FILE *f); -int hash_keys(clicon_hash_t *hash, char ***vector, size_t *nkeys); +clicon_hash_t *clicon_hash_init (void); +void clicon_hash_free (clicon_hash_t *); +clicon_hash_t clicon_hash_lookup (clicon_hash_t *head, const char *key); +void *clicon_hash_value (clicon_hash_t *head, const char *key, size_t *vlen); +clicon_hash_t clicon_hash_add (clicon_hash_t *head, const char *key, void *val, size_t vlen); +int clicon_hash_del (clicon_hash_t *head, const char *key); +int clicon_hash_dump(clicon_hash_t *head, FILE *f); +int clicon_hash_keys(clicon_hash_t *hash, char ***vector, size_t *nkeys); /* * Macros to iterate over hash contents. @@ -59,24 +59,23 @@ int hash_keys(clicon_hash_t *hash, char ***vector, size_t *nkeys); * * Example: * char *k; - * clicon_hash_t *h = hash_init(); + * clicon_hash_t *h = clicon_hash_init(); * - * hash_add(h, "colour", "red", 6); - * hash_add(h, "name", "rudolf" 7); - * hash_add(h, "species", "reindeer" 9); + * clicon_hash_add(h, "colour", "red", 6); + * clicon_hash_add(h, "name", "rudolf" 7); + * clicon_hash_add(h, "species", "reindeer" 9); * - * hash_each(h, k) { - * printf ("%s = %s\n", k, (char *)hash_value(h, k, NULL)); + * clicon_hash_each(h, k) { + * printf ("%s = %s\n", k, (char *)clicon_hash_value(h, k, NULL)); * } hash_each_end(); */ -#define hash_each(__hash__, __key__) \ +#define clicon_hash_each(__hash__, __key__) \ { \ int __i__; \ size_t __n__; \ char **__k__ = hash_keys((__hash__),&__n__); \ if (__k__) { \ for(__i__ = 0; __i__ < __n__ && ((__key__) = __k__[__i__]); __i__++) -#define hash_each_end(__hash__) if (__k__) free(__k__); } } - +#define clicon_hash_each_end(__hash__) if (__k__) free(__k__); } } #endif /* _CLIXON_HASH_H_ */ diff --git a/lib/src/clixon_data.c b/lib/src/clixon_data.c index 56871268..cb38c34d 100644 --- a/lib/src/clixon_data.c +++ b/lib/src/clixon_data.c @@ -83,7 +83,7 @@ clicon_dbspec_yang(clicon_handle h) size_t len; void *p; - if ((p = hash_value(cdat, "dbspec_yang", &len)) != NULL) + if ((p = clicon_hash_value(cdat, "dbspec_yang", &len)) != NULL) return *(yang_stmt **)p; return NULL; } @@ -100,7 +100,7 @@ clicon_dbspec_yang_set(clicon_handle h, /* It is the pointer to ys that should be copied by hash, so we send a ptr to the ptr to indicate what to copy. */ - if (hash_add(cdat, "dbspec_yang", &ys, sizeof(ys)) == NULL) + if (clicon_hash_add(cdat, "dbspec_yang", &ys, sizeof(ys)) == NULL) return -1; return 0; } @@ -118,7 +118,7 @@ clicon_nacm_ext(clicon_handle h) size_t len; void *p; - if ((p = hash_value(cdat, "nacm_xml", &len)) != NULL) + if ((p = clicon_hash_value(cdat, "nacm_xml", &len)) != NULL) return *(cxobj **)p; return NULL; } @@ -141,7 +141,7 @@ clicon_nacm_ext_set(clicon_handle h, /* It is the pointer to xn that should be copied by hash, so we send a ptr to the ptr to indicate what to copy. */ - if (hash_add(cdat, "nacm_xml", &xn, sizeof(xn)) == NULL) + if (clicon_hash_add(cdat, "nacm_xml", &xn, sizeof(xn)) == NULL) return -1; return 0; } @@ -158,7 +158,7 @@ clicon_config_yang(clicon_handle h) size_t len; void *p; - if ((p = hash_value(cdat, "control_yang", &len)) != NULL) + if ((p = clicon_hash_value(cdat, "control_yang", &len)) != NULL) return *(yang_stmt **)p; return NULL; } @@ -175,7 +175,7 @@ clicon_config_yang_set(clicon_handle h, /* It is the pointer to ys that should be copied by hash, so we send a ptr to the ptr to indicate what to copy. */ - if (hash_add(cdat, "control_yang", &ys, sizeof(ys)) == NULL) + if (clicon_hash_add(cdat, "control_yang", &ys, sizeof(ys)) == NULL) return -1; return 0; } @@ -192,7 +192,7 @@ clicon_conf_xml(clicon_handle h) size_t len; void *p; - if ((p = hash_value(cdat, "clixon_conf", &len)) != NULL) + if ((p = clicon_hash_value(cdat, "clixon_conf", &len)) != NULL) return *(cxobj **)p; return NULL; } @@ -209,7 +209,7 @@ clicon_conf_xml_set(clicon_handle h, /* It is the pointer to x that should be copied by hash, * so we send a ptr to the ptr to indicate what to copy. */ - if (hash_add(cdat, "clixon_conf", &x, sizeof(x)) == NULL) + if (clicon_hash_add(cdat, "clixon_conf", &x, sizeof(x)) == NULL) return -1; return 0; } @@ -223,7 +223,7 @@ clicon_username_get(clicon_handle h) { clicon_hash_t *cdat = clicon_data(h); - return (char*)hash_value(cdat, "username", NULL); + return (char*)clicon_hash_value(cdat, "username", NULL); } /*! Set authorized user name @@ -238,8 +238,8 @@ clicon_username_set(clicon_handle h, clicon_hash_t *cdat = clicon_data(h); if (username == NULL) - return hash_del(cdat, "username"); - return hash_add(cdat, "username", username, strlen(username)+1)==NULL?-1:0; + return clicon_hash_del(cdat, "username"); + return clicon_hash_add(cdat, "username", username, strlen(username)+1)==NULL?-1:0; } /*! Get backend daemon startup status @@ -252,7 +252,7 @@ clicon_startup_status_get(clicon_handle h) clicon_hash_t *cdat = clicon_data(h); void *p; - if ((p = hash_value(cdat, "startup_status", NULL)) != NULL) + if ((p = clicon_hash_value(cdat, "startup_status", NULL)) != NULL) return *(enum startup_status *)p; return STARTUP_ERR; } @@ -268,7 +268,7 @@ clicon_startup_status_set(clicon_handle h, enum startup_status status) { clicon_hash_t *cdat = clicon_data(h); - if (hash_add(cdat, "startup_status", &status, sizeof(status))==NULL) + if (clicon_hash_add(cdat, "startup_status", &status, sizeof(status))==NULL) return -1; return 0; } @@ -284,7 +284,7 @@ clicon_socket_get(clicon_handle h) clicon_hash_t *cdat = clicon_data(h); void *p; - if ((p = hash_value(cdat, "socket", NULL)) == NULL) + if ((p = clicon_hash_value(cdat, "socket", NULL)) == NULL) return -1; return *(int*)p; } @@ -302,8 +302,8 @@ clicon_socket_set(clicon_handle h, clicon_hash_t *cdat = clicon_data(h); if (s == -1) - return hash_del(cdat, "socket"); - return hash_add(cdat, "socket", &s, sizeof(int))==NULL?-1:0; + return clicon_hash_del(cdat, "socket"); + return clicon_hash_add(cdat, "socket", &s, sizeof(int))==NULL?-1:0; } /*! Get module state cache @@ -319,7 +319,7 @@ clicon_modst_cache_get(clicon_handle h, clicon_hash_t *cdat = clicon_data(h); void *p; - if ((p = hash_value(cdat, brief?"modst_brief":"modst_full", NULL)) != NULL) + if ((p = clicon_hash_value(cdat, brief?"modst_brief":"modst_full", NULL)) != NULL) return *(cxobj **)p; return NULL; } @@ -346,7 +346,7 @@ clicon_modst_cache_set(clicon_handle h, assert(strcmp(xml_name(xms),"modules-state")==0); if ((x = xml_dup(xms)) == NULL) return -1; - if (hash_add(cdat, brief?"modst_brief":"modst_full", &x, sizeof(x))==NULL) + if (clicon_hash_add(cdat, brief?"modst_brief":"modst_full", &x, sizeof(x))==NULL) return -1; ok: return 0; @@ -363,7 +363,7 @@ clicon_xml_changelog_get(clicon_handle h) clicon_hash_t *cdat = clicon_data(h); void *p; - if ((p = hash_value(cdat, "xml-changelog", NULL)) != NULL) + if ((p = clicon_hash_value(cdat, "xml-changelog", NULL)) != NULL) return *(cxobj **)p; return NULL; } @@ -381,7 +381,7 @@ clicon_xml_changelog_set(clicon_handle h, { clicon_hash_t *cdat = clicon_data(h); - if (hash_add(cdat, "xml-changelog", &xchlog, sizeof(xchlog))==NULL) + if (clicon_hash_add(cdat, "xml-changelog", &xchlog, sizeof(xchlog))==NULL) return -1; return 0; } @@ -403,12 +403,12 @@ clicon_argv_get(clicon_handle h, void *p; if (argc){ - if ((p = hash_value(cdat, "argc", NULL)) == NULL) + if ((p = clicon_hash_value(cdat, "argc", NULL)) == NULL) return -1; *argc = *(int*)p; } if (argv){ - if ((p = hash_value(cdat, "argv", NULL)) == NULL) + if ((p = clicon_hash_value(cdat, "argv", NULL)) == NULL) return -1; *argv = (char**)p; } @@ -444,10 +444,10 @@ clicon_argv_set(clicon_handle h, memcpy(argvv+1, argv, argc*sizeof(char*)); argvv[0] = prgm; /* Note the value is the argv vector (which is copied) */ - if (hash_add(cdat, "argv", argvv, len*sizeof(char*))==NULL) + if (clicon_hash_add(cdat, "argv", argvv, len*sizeof(char*))==NULL) goto done; argc += 1; - if (hash_add(cdat, "argc", &argc, sizeof(argc))==NULL) + if (clicon_hash_add(cdat, "argc", &argc, sizeof(argc))==NULL) goto done; retval = 0; done: @@ -470,7 +470,7 @@ clicon_db_elmnt_get(clicon_handle h, clicon_hash_t *cdat = clicon_db_elmnt(h); void *p; - if ((p = hash_value(cdat, db, NULL)) != NULL) + if ((p = clicon_hash_value(cdat, db, NULL)) != NULL) return (db_elmnt *)p; return NULL; } @@ -491,7 +491,7 @@ clicon_db_elmnt_set(clicon_handle h, { clicon_hash_t *cdat = clicon_db_elmnt(h); - if (hash_add(cdat, db, de, sizeof(*de))==NULL) + if (clicon_hash_add(cdat, db, de, sizeof(*de))==NULL) return -1; return 0; } diff --git a/lib/src/clixon_datastore.c b/lib/src/clixon_datastore.c index b27ce1b4..78e5c300 100644 --- a/lib/src/clixon_datastore.c +++ b/lib/src/clixon_datastore.c @@ -160,10 +160,10 @@ xmldb_disconnect(clicon_handle h) int i; db_elmnt *de; - if (hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0) + if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0) goto done; for(i = 0; i < klen; i++) - if ((de = hash_value(clicon_db_elmnt(h), keys[i], NULL)) != NULL){ + if ((de = clicon_hash_value(clicon_db_elmnt(h), keys[i], NULL)) != NULL){ if (de->de_xml){ xml_free(de->de_xml); de->de_xml = NULL; @@ -310,7 +310,7 @@ xmldb_unlock_all(clicon_handle h, int i; db_elmnt *de; - if (hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0) + if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0) goto done; for (i = 0; i < klen; i++) if ((de = clicon_db_elmnt_get(h, keys[i])) != NULL && diff --git a/lib/src/clixon_handle.c b/lib/src/clixon_handle.c index 5d91c7c8..b4b5a303 100644 --- a/lib/src/clixon_handle.c +++ b/lib/src/clixon_handle.c @@ -111,15 +111,15 @@ clicon_handle_init0(int size) } memset(ch, 0, size); ch->ch_magic = CLICON_MAGIC; - if ((ch->ch_copt = hash_init()) == NULL){ + if ((ch->ch_copt = clicon_hash_init()) == NULL){ clicon_handle_exit((clicon_handle)ch); goto done; } - if ((ch->ch_data = hash_init()) == NULL){ + if ((ch->ch_data = clicon_hash_init()) == NULL){ clicon_handle_exit((clicon_handle)ch); goto done; } - if ((ch->ch_db_elmnt = hash_init()) == NULL){ + if ((ch->ch_db_elmnt = clicon_hash_init()) == NULL){ clicon_handle_exit((clicon_handle)ch); goto done; } @@ -154,12 +154,12 @@ clicon_handle_exit(clicon_handle h) clicon_hash_t *ha; if ((ha = clicon_options(h)) != NULL) - hash_free(ha); + clicon_hash_free(ha); if ((ha = clicon_data(h)) != NULL) - hash_free(ha); + clicon_hash_free(ha); if ((ha = clicon_db_elmnt(h)) != NULL) - hash_free(ha); + clicon_hash_free(ha); stream_delete_all(h, 1); free(ch); retval = 0; diff --git a/lib/src/clixon_hash.c b/lib/src/clixon_hash.c index b14e10ad..f757743b 100644 --- a/lib/src/clixon_hash.c +++ b/lib/src/clixon_hash.c @@ -115,7 +115,7 @@ hash_bucket(const char *str) * @see hash_free For freeing the hash-table */ clicon_hash_t * -hash_init(void) +clicon_hash_init(void) { clicon_hash_t *hash; @@ -133,7 +133,7 @@ hash_init(void) * @retval void */ void -hash_free(clicon_hash_t *hash) +clicon_hash_free(clicon_hash_t *hash) { int i; clicon_hash_t tmp; @@ -157,8 +157,8 @@ hash_free(clicon_hash_t *hash) * @retval NULL Not found */ clicon_hash_t -hash_lookup(clicon_hash_t *hash, - const char *key) +clicon_hash_lookup(clicon_hash_t *hash, + const char *key) { uint32_t bkt; clicon_hash_t h; @@ -183,13 +183,13 @@ hash_lookup(clicon_hash_t *hash, * @retval NULL Key not found or value NULL */ void * -hash_value(clicon_hash_t *hash, - const char *key, - size_t *vlen) +clicon_hash_value(clicon_hash_t *hash, + const char *key, + size_t *vlen) { clicon_hash_t h; - h = hash_lookup(hash, key); + h = clicon_hash_lookup(hash, key); if (h == NULL) return NULL; /* OK, key not found */ @@ -209,10 +209,10 @@ hash_value(clicon_hash_t *hash, * @note special case val is NULL and vlen==0 */ clicon_hash_t -hash_add(clicon_hash_t *hash, - const char *key, - void *val, - size_t vlen) +clicon_hash_add(clicon_hash_t *hash, + const char *key, + void *val, + size_t vlen) { void *newval = NULL; clicon_hash_t h; @@ -225,7 +225,7 @@ hash_add(clicon_hash_t *hash, goto catch; } /* If variable exist, don't allocate a new. just replace value */ - h = hash_lookup(hash, key); + h = clicon_hash_lookup(hash, key); if (h == NULL) { if ((new = (clicon_hash_t)malloc(sizeof(*new))) == NULL){ clicon_err(OE_UNIX, errno, "malloc: %s", strerror(errno)); @@ -283,12 +283,12 @@ catch: * @retval -1 Key not found */ int -hash_del(clicon_hash_t *hash, - const char *key) +clicon_hash_del(clicon_hash_t *hash, + const char *key) { clicon_hash_t h; - h = hash_lookup(hash, key); + h = clicon_hash_lookup(hash, key); if (h == NULL) return -1; @@ -311,9 +311,9 @@ hash_del(clicon_hash_t *hash, * @note: vector needs to be deallocated with free */ int -hash_keys(clicon_hash_t *hash, - char ***vector, - size_t *nkeys) +clicon_hash_keys(clicon_hash_t *hash, + char ***vector, + size_t *nkeys) { int retval = -1; int bkt; @@ -357,8 +357,8 @@ catch: * @retval -1 Error */ int -hash_dump(clicon_hash_t *hash, - FILE *f) +clicon_hash_dump(clicon_hash_t *hash, + FILE *f) { int retval = -1; int i; @@ -369,10 +369,10 @@ hash_dump(clicon_hash_t *hash, if (hash == NULL) goto ok; - if (hash_keys(hash, &keys, &klen) < 0) + if (clicon_hash_keys(hash, &keys, &klen) < 0) goto done; for(i = 0; i < klen; i++) { - val = hash_value(hash, keys[i], &vlen); + val = clicon_hash_value(hash, keys[i], &vlen); printf("%s =\t 0x%p , length %zu\n", keys[i], val, vlen); } diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index d91dc9ee..a3fbbdf1 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -102,10 +102,10 @@ clicon_option_dump(clicon_handle h, size_t klen; size_t vlen; - if (hash_keys(hash, &keys, &klen) < 0) + if (clicon_hash_keys(hash, &keys, &klen) < 0) goto done; for(i = 0; i < klen; i++) { - val = hash_value(hash, keys[i], &vlen); + val = clicon_hash_value(hash, keys[i], &vlen); if (vlen){ if (((char*)val)[vlen-1]=='\0') /* assume string */ clicon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val); @@ -222,7 +222,7 @@ parse_configfile(clicon_handle h, /* Used as an arg to this fn */ if (strcmp(name,"CLICON_CONFIGFILE")==0) continue; - if (hash_add(copt, + if (clicon_hash_add(copt, name, body, strlen(body)+1) == NULL) @@ -267,7 +267,7 @@ clicon_option_add(clicon_handle h, name, value, name) < 0) goto done; } - if (hash_add(copt, + if (clicon_hash_add(copt, name, value, strlen(value)+1) == NULL) @@ -302,10 +302,10 @@ clicon_options_main(clicon_handle h, /* * Set configure file if not set by command-line above */ - if (!hash_lookup(copt, "CLICON_CONFIGFILE")){ + if (!clicon_hash_lookup(copt, "CLICON_CONFIGFILE")){ clicon_option_str_set(h, "CLICON_CONFIGFILE", CLIXON_DEFAULT_CONFIG); } - configfile = hash_value(copt, "CLICON_CONFIGFILE", NULL); + configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL); clicon_debug(1, "CLICON_CONFIGFILE=%s", configfile); /* File must end with .xml */ if ((suffix = rindex(configfile, '.')) != NULL){ @@ -368,7 +368,7 @@ clicon_option_exists(clicon_handle h, { clicon_hash_t *copt = clicon_options(h); - return (hash_lookup(copt, (char*)name) != NULL); + return (clicon_hash_lookup(copt, (char*)name) != NULL); } /*! Get a single string option string via handle @@ -387,9 +387,9 @@ clicon_option_str(clicon_handle h, { clicon_hash_t *copt = clicon_options(h); - if (hash_lookup(copt, (char*)name) == NULL) + if (clicon_hash_lookup(copt, (char*)name) == NULL) return NULL; - return hash_value(copt, (char*)name, NULL); + return clicon_hash_value(copt, (char*)name, NULL); } /*! Set a single string option via handle @@ -406,7 +406,7 @@ clicon_option_str_set(clicon_handle h, { clicon_hash_t *copt = clicon_options(h); - return hash_add(copt, (char*)name, val, strlen(val)+1)==NULL?-1:0; + return clicon_hash_add(copt, (char*)name, val, strlen(val)+1)==NULL?-1:0; } /*! Get options as integer but stored as string @@ -501,7 +501,7 @@ clicon_option_del(clicon_handle h, { clicon_hash_t *copt = clicon_options(h); - return hash_del(copt, (char*)name); + return clicon_hash_del(copt, (char*)name); } /*-----------------------------------------------------------------