From b8f9c3e68104c779296d0d7dfdf6fae08cd22ec3 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 14 Jul 2005 14:16:17 +0000 Subject: [PATCH] fixed some a bug in jserver, added some debug lines git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@392 9efc2488-bf62-4759-914b-345cdb29e865 --- src/Makefile | 11 +++--- src/jserver/jserver-c.c | 43 ++++++++++++++++++----- src/jserver/jserver-c.h | 2 ++ src/objson/json_parser.c | 7 ++++ src/objson/objson_test.c | 89 +++++++++++++++++++++++++++++++----------------- src/router/router.c | 6 ++-- 6 files changed, 111 insertions(+), 47 deletions(-) diff --git a/src/Makefile b/src/Makefile index c0a6986..24836e3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,7 +28,7 @@ test: test install: install-prep transport-install stack-install gateway-install \ router-install srfsh-install jserver-install perl-install \ - libjson-install objson-install utils-install info + libjson-install objson-install utils-install bin-install info prep: mkdir -p $(TMPDIR) @@ -119,6 +119,9 @@ jserver-install: install-prep utils-install perl-install: install-prep cp -r perlmods/* $(PERLDIR)/ +bin-install: install-prep + cp ../bin/opensrf_ctl $(BINDIR) + # -------------------------------------------------------------------------------- # INFO @@ -130,9 +133,9 @@ info: @echo "It may be helpful to set some environment variables if the install " @echo "was set to a non-standard location. These include:" @echo "" - @echo "export LD_LIBRARY_PATH=\$$LD_LIBRARY_PATH:$(LIBDIR)" - @echo "export PERL5LIB=\$$PERL5LIB:$(PERLDIR)" - @echo "export PATH=\$$PATH:$(BINDIR)" + @echo "export LD_LIBRARY_PATH=$(LIBDIR):\$$LD_LIBRARY_PATH" + @echo "export PERL5LIB=$(PERLDIR):\$$PERL5LIB" + @echo "export PATH=$(BINDIR):\$$PATH" @echo "" diff --git a/src/jserver/jserver-c.c b/src/jserver/jserver-c.c index b30ce5a..80e9004 100644 --- a/src/jserver/jserver-c.c +++ b/src/jserver/jserver-c.c @@ -27,7 +27,7 @@ void jserver_free(jserver* js) { jclient_node* node; while(js->client) { node = js->client->next; - _jserver_remove_client(js, js->client->addr); + _jserver_remove_client_id(js, js->client->id); js->client = node; } socket_manager_free(js->mgr); @@ -37,13 +37,8 @@ void jserver_free(jserver* js) { void jserver_socket_closed(void* blob, int sock_id) { jserver* js = (jserver*) blob; if(js == NULL) return; - jclient_node* node = jserver_find_client_id(js, sock_id); - if(node) { - info_handler("Removing client %d - %s remote " - "site closed socket", sock_id, node->addr); - _jserver_remove_client(js, node->addr); - } - + info_handler("Removing client %d - site closed socket",sock_id); + _jserver_remove_client_id(js, sock_id); } /* opens the inet and unix sockets that we're listening on */ @@ -180,6 +175,38 @@ void _jserver_remove_client(jserver* js, char* addr) { } } + +/* removes and frees a client node */ +void _jserver_remove_client_id(jserver* js, int id) { + if(js == NULL || js->client == NULL) return; + + jclient_node* node = js->client; + + if(node->id == id) { + js->client = node->next; + debug_handler("Removing the first jserver client"); + socket_disconnect(js->mgr, node->id); + _free_jclient_node(node); + return; + } + + debug_handler("Searching for jclient to remove"); + jclient_node* tail_node = node; + node = node->next; + + while(node) { + if(node->id == id) { + tail_node->next = node->next; + debug_handler("Removing a jserver client"); + socket_disconnect(js->mgr, node->id); + _free_jclient_node(node); + return; + } + tail_node = node; + node = node->next; + } +} + /* finds a client node by addr */ jclient_node* jserver_find_client(jserver* js, char* addr) { if(js == NULL || addr == NULL) return NULL; diff --git a/src/jserver/jserver-c.h b/src/jserver/jserver-c.h index e292756..67e5695 100644 --- a/src/jserver/jserver-c.h +++ b/src/jserver/jserver-c.h @@ -55,6 +55,8 @@ jclient_node* _jserver_add_client(jserver* js, int id); /* removes and frees a client node */ void _jserver_remove_client(jserver* js, char* addr); +void _jserver_remove_client_id(jserver* js, int id); + /* finds a client node by addr */ jclient_node* jserver_find_client(jserver* js, char* addr); diff --git a/src/objson/json_parser.c b/src/objson/json_parser.c index 28ea4b6..7b4c6bc 100644 --- a/src/objson/json_parser.c +++ b/src/objson/json_parser.c @@ -173,6 +173,7 @@ int json_parse_json_bool(char* string, unsigned long* index, object* obj) { (*index) += 5; obj->bool_value = 0; obj->is_bool = 1; + obj->is_null = 0; return 0; } @@ -183,6 +184,7 @@ int json_parse_json_bool(char* string, unsigned long* index, object* obj) { (*index) += 4; obj->bool_value = 1; obj->is_bool = 1; + obj->is_null = 0; return 0; } @@ -225,12 +227,14 @@ int json_parse_json_number(char* string, unsigned long* index, object* obj) { if(dot_seen) { obj->is_double = 1; + obj->is_null = 0; obj->double_value = strtod(buf->buf, NULL); buffer_free(buf); return 0; } else { obj->is_number = 1; + obj->is_null = 0; obj->num_value = atol(buf->buf); buffer_free(buf); return 0; @@ -246,6 +250,7 @@ int json_parse_json_array(char* string, unsigned long* index, object* obj) { int status; int in_parse = 0; /* true if this array already contains one item */ obj->is_array = 1; + obj->is_null = 0; while(*index < current_strlen) { json_eat_ws(string, index, 1); @@ -284,6 +289,7 @@ int json_parse_json_object(char* string, unsigned long* index, object* obj) { assert(string && obj && index && *index < current_strlen); obj->is_hash = 1; + obj->is_null = 0; int status; int in_parse = 0; /* true if we've already added one item to this object */ @@ -337,6 +343,7 @@ int json_parse_json_object(char* string, unsigned long* index, object* obj) { free_object(key_obj); in_parse = 1; } + return 0; } diff --git a/src/objson/objson_test.c b/src/objson/objson_test.c index 95a8df6..19fe108 100644 --- a/src/objson/objson_test.c +++ b/src/objson/objson_test.c @@ -27,68 +27,94 @@ int main() { /* number, double, and 'null' parsing... */ - object* num = json_parse_string("1"); - printf("\nParsed number: %d\n", num->num_value); - free_object(num); - num = json_parse_string("1.1"); - printf("\nDouble number: %lf\n", num->double_value); - free_object(num); - - object* null = json_parse_string("nUlL"); - char* n = null->to_json(null); - free_object(null); - printf("\nJSON Null: %s\n", n); - free(n); - - object* mix = json_parse_string("[1, .5, null]"); - char* m = mix->to_json(mix); - printf("\nJSON MIX: %s\n", m ); - free(m); - free_object(mix); - + printf("------------------------------------------------------------------\n"); + object* o = json_parse_string("1"); + printf("\nParsed number: %ld\n", o->num_value); + free_object(o); + + printf("------------------------------------------------------------------\n"); + o = json_parse_string("1.1"); + printf("\nDouble number: %lf\n", o->double_value); + free_object(o); + + printf("------------------------------------------------------------------\n"); + o = json_parse_string("nUlL"); + char* s = o->to_json(o); + free_object(o); + + printf("\nJSON Null: %s\n", s); + free(s); + + printf("------------------------------------------------------------------\n"); + o = json_parse_string("[1, .5, null]"); + s = o->to_json(o); + printf("\nJSON MIX: %s\n", s ); + free(s); + free_object(o); + + printf("------------------------------------------------------------------\n"); /* simulate an error.. */ printf("\nShould print error msg: \n"); - object* error = json_parse_string("[1, .5. null]"); - if( error == NULL ) printf("\n"); - - object * t = json_parse_string("[ Null, trUe, falSE, 1, 12.9, \"true\" ]"); - char* ts = t->to_json(t); - printf("More JSON: %s\n", ts); - free(ts); - free_object(t); - - - + o = json_parse_string("[1, .5. null]"); + if( o == NULL ) printf("\n"); + + printf("------------------------------------------------------------------\n"); + o = json_parse_string("[ Null, trUe, falSE, 1, 12.9, \"true\" ]"); + s = o->to_json(o); + printf("More JSON: %s\n", s); + free(s); + free_object(o); + + printf("------------------------------------------------------------------\n"); + o = json_parse_string("[ Null, trUe, falSE, 1, 12.9, \"true\", " + "{\"key\":[0,0.0,1],\"key2\":null},NULL, { }, [] ]"); + s = o->to_json(o); + printf("More JSON: %s\n", s); + free(s); + free_object(o); + + + printf("------------------------------------------------------------------\n"); + o = json_parse_string("\"Pin\\u0303ata\""); + s = o->to_json(o); + printf("UNICODE:: %s\n", o->string_data); + printf("Back to JSON: %s\n", s); + free_object(o); + free(s); /* sample JSON string with some encoded UTF8 */ char* jsons = "/*--S mvr--*/[null,null,null,\"Griswold del Castillo, Richard\",[],null,\"1405676\",null,null,\"1558853243 (alk. paper) :\",\"c2002\",\"Pin\\u0303ata Books\",null,[],[[\"Chavez, Cesar 1927-\",\"Juvenile literature\"],[\"Labor leaders\",\"United States\",\"Biography\",\"Juvenile literature\"],[\"Mexican Americans\",\"Biography\",\"Juvenile literature\"],[\"Agricultural laborers\",\"Labor unions\",\"United States\",\"History\",\"Juvenile literature\"],[\"United Farm Workers\",\"History\",\"Juvenile literature\"],[\"Chavez, Cesar 1927-\"],[\"Labor leaders\"],[\"Mexican Americans\",\"Biography\"],[\"United Farm Workers.\"],[\"Spanish language materials\",\"Bilingual\"],[\"Chavez, Cesar 1927-\",\"Literatura juvenil\"],[\"Li\\u0301deres obreros\",\"Estados Unidos\",\"Biografi\\u0301a\",\"Literatura juvenil\"],[\"Mexicano-americanos\",\"Biografi\\u0301a\",\"Literatura juvenil\"],[\"Sindicatos\",\"Trabajadores agri\\u0301colas\",\"Estados Unidos\",\"Historia\",\"Literatura juvenil\"],[\"Unio\\u0301n de Trabajadores Agri\\u0301colas\",\"Historia\",\"Literatura juvenil\"]],\"ocm48083852 \",\"Ce\\u0301sar Cha\\u0301vez : the struggle for justice = Ce\\u0301sar Cha\\u0301vez : la lucha por la justicia\",[\"text\"], { \"hi\":\"you\"} ]/*--E mvr--*/"; + printf("------------------------------------------------------------------\n"); printf("\nOriginal JSON\n%s\n", jsons); /* parse the JSON string */ object* yuk = json_parse_string(jsons); /* grab the class name from the object */ + printf("------------------------------------------------------------------\n"); printf("\nParsed object with class %s\n", yuk->classname ); /* turn the resulting object back into JSON */ char* ccc = yuk->to_json(yuk); /* extract a sub-object from the object and print its data*/ - object* o = yuk->get_index(yuk, 11); + o = yuk->get_index(yuk, 11); printf("\nRandom unicode string => %s\n", o->string_data); /* parse the new JSON string to build yet another object */ object* yuk2 = json_parse_string(ccc); + printf("------------------------------------------------------------------\n"); /* turn that one back into JSON and print*/ char* cccc = yuk2->to_json(yuk2); printf("\nFinal JSON: \n%s\n", cccc); char* string2 = strdup(jsons); + printf("------------------------------------------------------------------\n"); int x = 0; int count = 3000; printf("\nParsing %d round trips at %f...\n", count, get_timestamp_millis()); @@ -139,6 +165,7 @@ int main() { /* dig our way into the JSON object we parsed, see test.json to get an idea of the object structure */ + printf("------------------------------------------------------------------\n"); object* big = json_parse_string(buf); object* k = big->get_key(big,"web-app"); object* k2 = k->get_key(k,"servlet"); diff --git a/src/router/router.c b/src/router/router.c index f4b1b3c..4b6022e 100644 --- a/src/router/router.c +++ b/src/router/router.c @@ -1142,8 +1142,8 @@ int router_registrar_free( transport_router_registrar* router_registrar ) { transport_router_registrar* router = router_registrar; + /* make this better int i = 0; - while(1) { if( router->trusted_servers[i] == NULL && @@ -1156,11 +1156,9 @@ int router_registrar_free( transport_router_registrar* router_registrar ) { free(router->trusted_clients[i]); i++; } + */ free( router_registrar ); - - - return 1; } -- 2.11.0