From f9323e11c9416db39637df680202ff70a627858a Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 22 Jun 2009 05:28:34 +0000 Subject: [PATCH 1/1] Fix a bug whereby, if there was only one entry for the public router in opensrf_core.xml, the service would fail to register. Root cause: The code was expecting to see a list of services in a JSON_ARRAY. But if there's only one service, it's represented as a JSON_STRING. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1724 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/osrf_prefork.c | 42 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/libopensrf/osrf_prefork.c b/src/libopensrf/osrf_prefork.c index 95ca398..ce19e35 100644 --- a/src/libopensrf/osrf_prefork.c +++ b/src/libopensrf/osrf_prefork.c @@ -158,23 +158,31 @@ static void osrf_prefork_send_router_registration(const char* appname, const cha /** parses a single "complex" router configuration chunk */ static void osrf_prefork_parse_router_chunk(const char* appname, jsonObject* routerChunk) { - char* routerName = jsonObjectGetString(jsonObjectGetKey(routerChunk, "name")); - char* domain = jsonObjectGetString(jsonObjectGetKey(routerChunk, "domain")); - jsonObject* services = jsonObjectGetKey(routerChunk, "services"); - osrfLogDebug(OSRF_LOG_MARK, "found router config with domain %s and name %s", routerName, domain); - - if(services && services->type == JSON_HASH) { - osrfLogDebug(OSRF_LOG_MARK, "investigating router information..."); - services = jsonObjectGetKey(services, "service"); - int j; - for(j = 0; j < services->size; j++ ) { - char* service = jsonObjectGetString(jsonObjectGetIndex(services, j)); - if(!strcmp(appname, service)) - osrf_prefork_send_router_registration(appname, routerName, domain); - } - } else { - osrf_prefork_send_router_registration(appname, routerName, domain); - } + char* routerName = jsonObjectGetString(jsonObjectGetKey(routerChunk, "name")); + char* domain = jsonObjectGetString(jsonObjectGetKey(routerChunk, "domain")); + jsonObject* services = jsonObjectGetKey(routerChunk, "services"); + osrfLogDebug(OSRF_LOG_MARK, "found router config with domain %s and name %s", routerName, domain); + + if( services && services->type == JSON_HASH ) { + osrfLogDebug(OSRF_LOG_MARK, "investigating router information..."); + jsonObject* service_obj = jsonObjectGetKey(services, "service"); + if( !service_obj ) + ; // do nothing (shouldn't happen) + else if( JSON_ARRAY == service_obj->type ) { + int j; + for(j = 0; j < service_obj->size; j++ ) { + const char* service = jsonObjectGetString(jsonObjectGetIndex(service_obj, j)); + if( service && !strcmp( appname, service )) + osrf_prefork_send_router_registration(appname, routerName, domain); + } + } + else if( JSON_STRING == service_obj->type ) { + if( !strcmp(appname, jsonObjectGetString( service_obj )) ) + osrf_prefork_send_router_registration(appname, routerName, domain); + } + } else { + osrf_prefork_send_router_registration(appname, routerName, domain); + } } static void osrf_prefork_register_routers( const char* appname ) { -- 2.43.2