From 6d338860993c612e0e3516437843727e3f566554 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 10 Sep 2009 12:56:14 +0200 Subject: [PATCH] More strict metadata assignment code --- src/pazpar2_config.c | 57 +++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index c937927..b508eed 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #endif #include +#include #include #include @@ -68,21 +69,19 @@ static char *parse_settings(struct conf_config *config, static struct conf_targetprofiles *parse_targetprofiles(NMEM nmem, xmlNode *node); -static -struct conf_metadata * conf_metadata_assign(NMEM nmem, - struct conf_metadata * metadata, - const char *name, - enum conf_metadata_type type, - enum conf_metadata_merge merge, - enum conf_setting_type setting, - int brief, - int termlist, - int rank, - int sortkey_offset, - enum conf_metadata_mergekey mt) +static void conf_metadata_assign(NMEM nmem, + struct conf_metadata * metadata, + const char *name, + enum conf_metadata_type type, + enum conf_metadata_merge merge, + enum conf_setting_type setting, + int brief, + int termlist, + int rank, + int sortkey_offset, + enum conf_metadata_mergekey mt) { - if (!nmem || !metadata || !name) - return 0; + assert(nmem && metadata && name); metadata->name = nmem_strdup(nmem, name); @@ -100,35 +99,28 @@ struct conf_metadata * conf_metadata_assign(NMEM nmem, metadata->rank = rank; metadata->sortkey_offset = sortkey_offset; metadata->mergekey = mt; - return metadata; } -static -struct conf_sortkey * conf_sortkey_assign(NMEM nmem, - struct conf_sortkey * sortkey, - const char *name, - enum conf_sortkey_type type) +static void conf_sortkey_assign(NMEM nmem, + struct conf_sortkey * sortkey, + const char *name, + enum conf_sortkey_type type) { - if (!nmem || !sortkey || !name) - return 0; + assert(nmem && sortkey && name); sortkey->name = nmem_strdup(nmem, name); sortkey->type = type; - - return sortkey; } -struct conf_service * conf_service_create(struct conf_config *config, - int num_metadata, int num_sortkeys, +struct conf_service *conf_service_create(struct conf_config *config, + int num_metadata, int num_sortkeys, const char *service_id) { struct conf_service * service = 0; NMEM nmem = nmem_create(); - //assert(nmem); - service = nmem_malloc(nmem, sizeof(struct conf_service)); service->nmem = nmem; service->next = 0; @@ -172,11 +164,10 @@ struct conf_metadata* conf_service_add_metadata(struct conf_service *service, || field_id < 0 || !(field_id < service->num_metadata)) return 0; - //md = &((service->metadata)[field_id]); md = service->metadata + field_id; - md = conf_metadata_assign(service->nmem, md, name, type, merge, setting, - brief, termlist, rank, sortkey_offset, - mt); + conf_metadata_assign(service->nmem, md, name, type, merge, setting, + brief, termlist, rank, sortkey_offset, + mt); return md; } @@ -194,7 +185,7 @@ struct conf_sortkey * conf_service_add_sortkey(struct conf_service *service, //sk = &((service->sortkeys)[field_id]); sk = service->sortkeys + field_id; - sk = conf_sortkey_assign(service->nmem, sk, name, type); + conf_sortkey_assign(service->nmem, sk, name, type); return sk; } -- 1.7.10.4