From 5515806ef87e408918a349c6544daead6dd1cd85 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 8 Dec 2005 23:18:00 +0000 Subject: [PATCH] started work on xul-based requestor/recipient holds avoided (but not fixed) bug in the gateway modules where you cannot send escaped URL params to vsnprintf. This will need to be fixed. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@606 9efc2488-bf62-4759-914b-345cdb29e865 --- src/gateway/mod_ils_gateway.c | 71 ++++++++++++++++++++++++------------------- src/libstack/osrf_system.c | 2 +- src/objson/json_parser.c | 1 + src/utils/log.c | 8 ++--- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/gateway/mod_ils_gateway.c b/src/gateway/mod_ils_gateway.c index 21067ec..82a9a3c 100644 --- a/src/gateway/mod_ils_gateway.c +++ b/src/gateway/mod_ils_gateway.c @@ -1,7 +1,8 @@ #include "mod_ils_gateway.h" +#include "http_log.h" -char* ils_gateway_config_file; -char* ils_rest_gateway_config_file; +char* ils_gateway_config_file = NULL; +char* ils_rest_gateway_config_file = NULL; static const char* ils_gateway_set_config(cmd_parms *parms, void *config, const char *arg) { ils_gateway_config *cfg; @@ -29,10 +30,9 @@ static void mod_ils_gateway_child_init(apr_pool_t *p, server_rec *s) { char* cfg = ils_gateway_config_file; if( ! osrf_system_bootstrap_client( cfg, CONFIG_CONTEXT) ) { - osrfLogError("Unable to load gateway config file..."); + osrfLogError("Unable to bootstrap client in gateway..."); return; } - osrfLogSetAppname("osrf_json_gw"); fprintf(stderr, "Bootstrapping %d\n", getpid() ); fflush(stderr); } @@ -42,6 +42,8 @@ static int mod_ils_gateway_method_handler (request_rec *r) { /* make sure we're needed first thing*/ if (strcmp(r->handler, MODULE_NAME )) return DECLINED; + + osrfLogSetAppname("osrf_json_gw"); apr_pool_t *p = r->pool; /* memory pool */ char* arg = r->args; /* url query string */ @@ -49,8 +51,6 @@ static int mod_ils_gateway_method_handler (request_rec *r) { char* service = NULL; /* service to connect to */ char* method = NULL; /* method to perform */ - //json* exception = NULL; /* returned in error conditions */ - //jsonObject* exception = NULL; /* returned in error conditions */ string_array* sarray = init_string_array(12); /* method parameters */ growing_buffer* buffer = NULL; /* POST data */ @@ -59,20 +59,18 @@ static int mod_ils_gateway_method_handler (request_rec *r) { char* key = NULL; /* query item name */ char* val = NULL; /* query item value */ - jsonObject* response = jsonParseString("{\"status\":0,\"debug\":\"\"}"); - jsonObject* payload = jsonParseString("[]"); + jsonObject* response = jsonParseString("{ }"); + jsonObject* payload = jsonParseString("[ ]"); jsonObjectSetKey(response, "payload", payload ); - - /* verify we are connected */ if(!osrf_system_get_transport_client()) { osrfLogError("Bootstrap Failed, no transport client"); return HTTP_INTERNAL_SERVER_ERROR; } - ap_set_content_type(r, "text/plain"); + osrfLogDebug("Apache request method: %s", r->method ); /* gather the post args and append them to the url query string */ if( !strcmp(r->method,"POST") ) { @@ -81,20 +79,28 @@ static int mod_ils_gateway_method_handler (request_rec *r) { if(! ap_should_client_block(r)) { osrfLogWarning("No Post Body"); + ap_rputs("null", r); + return OK; } - char body[1025]; - memset(body,0,1025); - buffer = buffer_init(1025); + int BUFL = 1024; + char body[BUFL]; + bzero(body, BUFL); + buffer = buffer_init(BUFL); - while(ap_get_client_block(r, body, 1024)) { - osrfLogDebug("Apache read POST block data: %s\n", body); + while(ap_get_client_block(r, body, BUFL - 1 )) { buffer_add( buffer, body ); - memset(body,0,1025); + bzero(body, BUFL); + } + + if( buffer->n_used < 1 ) { + osrfLogWarning("No Post Body"); + ap_rputs("null", r); + return OK; } - if(arg && arg[0]) { - tmp_buf = buffer_init(1024); + if(arg && strlen(arg) > 0 ) { + tmp_buf = buffer_init(BUFL); buffer_add(tmp_buf,arg); buffer_add(tmp_buf,buffer->buf); arg = (char*) apr_pstrdup(p, tmp_buf->buf); @@ -106,17 +112,16 @@ static int mod_ils_gateway_method_handler (request_rec *r) { } - osrfLogDebug("params args are %s", arg); - - - if( ! arg || !arg[0] ) { /* we received no request */ + if( ! arg || strlen(arg) == 0 ) { /* we received no request */ osrfLogWarning("No Args"); + ap_rputs("null", r); return OK; } + ap_log_rerror( APLOG_MARK, APLOG_DEBUG, 0, r, "URL: %s", arg ); + r->allowed |= (AP_METHOD_BIT << M_GET); r->allowed |= (AP_METHOD_BIT << M_POST); - while( arg && (val = ap_getword(p, (const char**) &arg, '&'))) { @@ -138,7 +143,7 @@ static int mod_ils_gateway_method_handler (request_rec *r) { } - osrfLogInfo("\nPerforming(%d): service %s " + osrfLogInfo("\r\nPerforming(%d): service %s " "| method %s |", getpid(), service, method ); int k; @@ -148,7 +153,7 @@ static int mod_ils_gateway_method_handler (request_rec *r) { osrf_app_session* session = osrf_app_client_session_init(service); - osrfLogDebug("MOD session service: %s", session->remote_service ); + osrfLogDebug("session service: %s", session->remote_service ); int req_id = osrf_app_session_make_req( session, NULL, method, 1, sarray ); string_array_destroy(sarray); @@ -164,12 +169,14 @@ static int mod_ils_gateway_method_handler (request_rec *r) { } else { - char* s = omsg->status_name ? omsg->status_name : "Unknown Error"; - char* t = omsg->status_text ? omsg->status_text : "No Error Message"; - jsonObjectSetKey(response, "debug", jsonNewObject("\n\n%s:\n%s\n", s, t)); - osrfLogError( "Gateway received error: %s", - jsonObjectGetString(jsonObjectGetKey(response, "debug"))); - break; + if( omsg->status_code > 299 ) { + char* s = omsg->status_name ? omsg->status_name : "Unknown Error"; + char* t = omsg->status_text ? omsg->status_text : "No Error Message"; + jsonObjectSetKey(response, "debug", jsonNewObject("\n\n%s:\n%s\n", s, t)); + osrfLogError( "Gateway received error: %s", + jsonObjectGetString(jsonObjectGetKey(response, "debug"))); + break; + } } osrf_message_free(omsg); diff --git a/src/libstack/osrf_system.c b/src/libstack/osrf_system.c index ac698f7..794a1f5 100644 --- a/src/libstack/osrf_system.c +++ b/src/libstack/osrf_system.c @@ -5,7 +5,7 @@ void __osrfSystemSignalHandler( int sig ); -transport_client* __osrfGlobalTransportClient; +transport_client* __osrfGlobalTransportClient = NULL; transport_client* osrfSystemGetTransportClient() { return __osrfGlobalTransportClient; diff --git a/src/objson/json_parser.c b/src/objson/json_parser.c index 63ba6b3..159eca1 100644 --- a/src/objson/json_parser.c +++ b/src/objson/json_parser.c @@ -718,6 +718,7 @@ int json_handle_error(char* string, unsigned long* index, char* err_msg) { "\nError parsing json string at charracter %c " "(code %d) and index %ld\nMsg:\t%s\nNear:\t%s\n\n", string[*index], string[*index], *index, err_msg, buf ); + return -1; } diff --git a/src/utils/log.c b/src/utils/log.c index 40ec051..03c8809 100644 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -78,9 +78,9 @@ void osrfLogDetail( int level, char* filename, int line, char* func, char* msg, if(!filename) filename = ""; if(!func) func = ""; - char lb[8]; - bzero(lb,8); - if(line >= 0) snprintf(lb,8,"%d", line); + char lb[12]; + bzero(lb,12); + if(line >= 0) snprintf(lb,12,"%d", line); char* l = "INFO"; /* level name */ int lvl = LOG_INFO; /* syslog level */ @@ -126,6 +126,7 @@ void osrfLogDetail( int level, char* filename, int line, char* func, char* msg, else if( __osrfLogType == OSRF_LOG_TYPE_FILE ) _osrfLogToFile("[%s:%d:%s:%s:%s] %s", l, getpid(), filename, lb, func, VA_BUF ); + } @@ -140,7 +141,6 @@ void _osrfLogToFile( char* msg, ... ) { char buf[l]; bzero(buf,l); - char datebuf[36]; bzero(datebuf,36); time_t t = time(NULL); -- 2.11.0