summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1704889)
raw | patch | inline | side by side (parent: 1704889)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 13 Dec 2012 12:35:34 +0000 (13:35 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 13 Dec 2012 12:35:34 +0000 (13:35 +0100) |
None of these parameters will be modified, so all to pass in constant strings.
src/core/store.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
diff --git a/src/core/store.c b/src/core/store.c
index 162a3fc2d7c736d97c5bd406e609a130f6ff2228..888fbb973449870ae82b5c2910a386e47a2481f9 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
#include <pthread.h>
+/*
+ * private data types
+ */
+
+/* type used for looking up named objects */
+typedef struct {
+ sc_object_t parent;
+ const char *obj_name;
+} sc_store_lookup_obj_t;
+#define SC_STORE_LOOKUP_OBJ_INIT { SC_OBJECT_INIT, NULL }
+
/*
* private variables
*/
return strcasecmp(h1->name, h2->name);
} /* sc_store_obj_cmp_by_name */
+static int
+sc_cmp_store_obj_with_name(const sc_object_t *a, const sc_object_t *b)
+{
+ const sc_store_obj_t *obj = (const sc_store_obj_t *)a;
+ const sc_store_lookup_obj_t *lookup = (const sc_store_lookup_obj_t *)b;
+
+ assert(obj && lookup);
+ return strcasecmp(obj->name, lookup->obj_name);
+} /* sc_cmp_store_obj_with_name */
+
static int
sc_host_init(sc_object_t *obj, va_list ap)
{
- char *name = va_arg(ap, char *);
+ const char *name = va_arg(ap, const char *);
SC_HOST(obj)->host_name = strdup(name);
if (! SC_HOST(obj)->host_name)
static int
sc_svc_init(sc_object_t *obj, va_list ap)
{
- char *hostname = va_arg(ap, char *);
- char *name = va_arg(ap, char *);
+ const char *hostname = va_arg(ap, const char *);
+ const char *name = va_arg(ap, const char *);
SC_SVC(obj)->hostname = strdup(hostname);
SC_SVC(obj)->svc_name = strdup(name);
*/
sc_host_t *
-sc_host_create(char *name)
+sc_host_create(const char *name)
{
sc_object_t *obj;
int
sc_store_host(const sc_host_t *host)
{
+ sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
sc_time_t last_update;
sc_host_t *old;
}
}
- old = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)host,
- sc_store_obj_cmp_by_name));
+ lookup.obj_name = host->host_name;
+ old = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
+ sc_cmp_store_obj_with_name));
if (old) {
if (old->host_last_update > last_update) {
} /* sc_store_host */
const sc_host_t *
-sc_store_get_host(char *name)
+sc_store_get_host(const char *name)
{
- sc_host_t tmp = SC_HOST_INIT;
+ sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
sc_host_t *host;
if (! name)
return NULL;
- tmp.host_name = name;
- host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&tmp,
- sc_store_obj_cmp_by_name));
+ lookup.obj_name = name;
+ host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
+ sc_cmp_store_obj_with_name));
if (! host)
return NULL;
} /* sc_store_get_host */
sc_service_t *
-sc_service_create(char *hostname, char *name)
+sc_service_create(const char *hostname, const char *name)
{
sc_object_t *obj;
int
sc_store_service(const sc_service_t *svc)
{
- sc_host_t tmp = SC_HOST_INIT;
+ sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
sc_host_t *host;
sc_service_t *old;
pthread_rwlock_wrlock(&host_lock);
- tmp.host_name = svc->hostname;
- host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&tmp,
- sc_store_obj_cmp_by_name));
+ lookup.obj_name = svc->hostname;
+ host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
+ sc_cmp_store_obj_with_name));
if (! host)
return -1;
- old = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)svc,
- sc_store_obj_cmp_by_name));
+ lookup.obj_name = svc->svc_name;
+ old = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&lookup,
+ sc_cmp_store_obj_with_name));
if (old) {
if (old->host_last_update > last_update) {
} /* sc_store_service */
const sc_service_t *
-sc_store_get_service(const sc_host_t *host, char *name)
+sc_store_get_service(const sc_host_t *host, const char *name)
{
- sc_service_t tmp = SC_SVC_INIT;
+ sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
sc_service_t *svc;
if ((! host) || (! name))
return NULL;
- tmp.svc_name = name;
- svc = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&tmp,
- sc_store_obj_cmp_by_name));
+ lookup.obj_name = name;
+ svc = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&lookup,
+ sc_cmp_store_obj_with_name));
if (! svc)
return NULL;
index 5d11c09975277ded9c43d1425a02d3ac387a207a..82507a9d424c2c33865e5f133a6fd753ca32d94c 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
#define SC_HOST(obj) ((sc_host_t *)(obj))
sc_host_t *
-sc_host_create(char *name);
+sc_host_create(const char *name);
sc_host_t *
sc_host_clone(const sc_host_t *host);
sc_store_host(const sc_host_t *host);
const sc_host_t *
-sc_store_get_host(char *name);
+sc_store_get_host(const char *name);
sc_service_t *
-sc_service_create(char *hostname, char *name);
+sc_service_create(const char *hostname, const char *name);
sc_service_t *
sc_service_clone(const sc_service_t *svc);
sc_store_service(const sc_service_t *svc);
const sc_service_t *
-sc_store_get_service(const sc_host_t *host, char *name);
+sc_store_get_service(const sc_host_t *host, const char *name);
int
sc_store_dump(FILE *fh);