From d0391f68b0424cb55912d43c1db80bbd3bd46f7f Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 8 Jul 2005 17:24:42 +0000 Subject: [PATCH] added some debugging, safety measures git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@385 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libtransport/transport_message.c | 5 +- src/objson/Makefile | 3 +- src/objson/json_parser.c | 4 ++ src/objson/object.h | 1 + src/objson/objson_test.c | 8 +++ src/router/router.c | 101 ++++++++++++++++++++--------------- 6 files changed, 78 insertions(+), 44 deletions(-) diff --git a/src/libtransport/transport_message.c b/src/libtransport/transport_message.c index 5a043bb..7af26a0 100644 --- a/src/libtransport/transport_message.c +++ b/src/libtransport/transport_message.c @@ -380,15 +380,18 @@ void jid_get_resource( const char* jid, char buf[]) { } void jid_get_domain( const char* jid, char buf[] ) { + if(jid == NULL) return; + int len = strlen(jid); int i; int index1 = 0; int index2 = 0; + for( i = 0; i!= len; i++ ) { if(jid[i] == 64) /* ascii @ */ index1 = i + 1; - else if(jid[i] == 47) /* ascii / */ + else if(jid[i] == 47 && index1 != 0) /* ascii / */ index2 = i; } if( index1 > 0 && index2 > 0 && index2 > index1 ) diff --git a/src/objson/Makefile b/src/objson/Makefile index 09e7fdf..0d1caaf 100644 --- a/src/objson/Makefile +++ b/src/objson/Makefile @@ -31,6 +31,7 @@ install: lib: $(OBJS) $(CC) -shared -W1 $(OBJS) -o $(TMPDIR)/libobjson.so + $(CC) -shared -W1 $(OBJS) -o libobjson.so mkdir -p $(TMPDIR)/$(DEST_INCLUDE)/ cp *.h $(TMPDIR)/$(DEST_INCLUDE)/ @@ -44,4 +45,4 @@ utils.o: $(UTIL_DIR)/utils.h $(UTIL_DIR)/utils.c $(CC) -c $(CC_OPTS) $(UTIL_DIR)/utils.c -o $@ clean: - /bin/rm -f *.o test + /bin/rm -f *.o *.so test diff --git a/src/objson/json_parser.c b/src/objson/json_parser.c index 79bcafa..28ea4b6 100644 --- a/src/objson/json_parser.c +++ b/src/objson/json_parser.c @@ -171,6 +171,8 @@ int json_parse_json_bool(char* string, unsigned long* index, object* obj) { if(!strncasecmp( string + (*index), "false", 5)) { (*index) += 5; + obj->bool_value = 0; + obj->is_bool = 1; return 0; } @@ -179,6 +181,8 @@ int json_parse_json_bool(char* string, unsigned long* index, object* obj) { if(!strncasecmp( string + (*index), "true", 4)) { (*index) += 4; + obj->bool_value = 1; + obj->is_bool = 1; return 0; } diff --git a/src/objson/object.h b/src/objson/object.h index 4d65544..455f53a 100644 --- a/src/objson/object.h +++ b/src/objson/object.h @@ -85,6 +85,7 @@ struct object_struct { * added serialized object when applicable */ char* comment; + }; typedef struct object_struct object; diff --git a/src/objson/objson_test.c b/src/objson/objson_test.c index 8325fe7..95a8df6 100644 --- a/src/objson/objson_test.c +++ b/src/objson/objson_test.c @@ -49,6 +49,14 @@ int main() { /* 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); + diff --git a/src/router/router.c b/src/router/router.c index 277fdee..f4b1b3c 100644 --- a/src/router/router.c +++ b/src/router/router.c @@ -260,31 +260,41 @@ void listen_loop( transport_router_registrar* router ) { /* We only process a message if we have some trusted servers and the current message came from one of those servers */ - if(router->trusted_servers && router->trusted_servers[0]) { - int i = 0; - int found = 0; + if(cur_msg) { - char server_buf[256]; - memset(server_buf,0,256); - jid_get_domain( cur_msg->sender, server_buf ); - info_handler("Received top level message from %s", server_buf ); + if(router->trusted_servers && router->trusted_servers[0]) { - while(1) { - if(router->trusted_servers[i] == NULL) - break; - if(!strcmp(router->trusted_servers[i], server_buf)) { - found = 1; - break; + int i = 0; + int found = 0; + + if( cur_msg->sender ) { + + int len = strlen(cur_msg->sender) + 1; /* there's no way it could be that big, but... */ + char server_buf[len]; + memset(server_buf,0,len); + jid_get_domain( cur_msg->sender, server_buf ); + info_handler("Received top level message from %s", server_buf ); + + while(1) { + if(router->trusted_servers[i] == NULL) + break; + if(!strcmp(router->trusted_servers[i], server_buf)) { + found = 1; + break; + } + i++; + } } - i++; + + if(found) + router_registrar_handle_msg( router, cur_msg ); + else + warning_handler( "Received top level message from unpriveleged sender %s", cur_msg->sender ); } - if(found) - router_registrar_handle_msg( router, cur_msg ); - else - warning_handler( "Received top level message from unpriveleged sender %s", cur_msg->sender ); + + message_free( cur_msg ); } - message_free( cur_msg ); if( ++num_handled == select_ret ) continue; } @@ -300,32 +310,39 @@ void listen_loop( transport_router_registrar* router ) { FD_CLR(cur_fd,&listen_set); cur_msg = client_recv( cur_node->jabber->t_client, 1 ); - info_handler( "%s received from %s", cur_node->server_class, cur_msg->sender ); - int handle_ret = server_class_handle_msg( router, cur_node, cur_msg ); - - if( handle_ret == -1 ) { - warning_handler( "server_class_handle_msg() returned -1" ); - cur_node = router->server_class_list; /*start over*/ - continue; - - } else if( handle_ret == 0 ) { - /* delete and continue */ - warning_handler( "server_class_handle_msg() returned 0" ); - //server_class_node* tmp_node = cur_node->next; - remove_server_class( router, cur_node ); - debug_handler( "Removed Server Class" ); - cur_node = router->server_class_list; /*start over*/ - //cur_node = tmp_node; - continue; - } - - info_handler( "%s handled message successfully", cur_node->server_class ); - /* dont free message here */ - if( num_handled == select_ret ) - break; + + if(cur_msg) { + + info_handler( "%s received from %s", cur_node->server_class, cur_msg->sender ); + int handle_ret = server_class_handle_msg( router, cur_node, cur_msg ); + + if( handle_ret == -1 ) { + warning_handler( "server_class_handle_msg() returned -1" ); + cur_node = router->server_class_list; /*start over*/ + continue; + + } else if( handle_ret == 0 ) { + /* delete and continue */ + warning_handler( "server_class_handle_msg() returned 0" ); + //server_class_node* tmp_node = cur_node->next; + remove_server_class( router, cur_node ); + debug_handler( "Removed Server Class" ); + cur_node = router->server_class_list; /*start over*/ + //cur_node = tmp_node; + continue; + } + + info_handler( "%s handled message successfully", cur_node->server_class ); + /* dont free message here */ + if( num_handled == select_ret ) + break; + } + } + if( num_handled == select_ret ) break; + cur_node = cur_node->next; } /* cycling through the server_class list */ -- 2.11.0