From: erickson Date: Thu, 4 May 2006 20:43:48 +0000 (+0000) Subject: adding cookie parsing - disabled in gateway for now X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=218af206896711b73aec1118b5073a5577c54afc;p=opensrf%2Fbjwebb.git adding cookie parsing - disabled in gateway for now git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@710 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/gateway/apachetools.c b/src/gateway/apachetools.c index 39a3d75..f975d62 100644 --- a/src/gateway/apachetools.c +++ b/src/gateway/apachetools.c @@ -175,3 +175,30 @@ int apacheError( char* msg, ... ) { } +/* taken more or less directly from O'Reillly - Writing Apache Modules in Perl and C */ +apr_table_t* apacheParseCookies(request_rec *r) { + + const char *data = ap_table_get(r->headers_in, "Cookie"); + osrfLogDebug(OSRF_LOG_MARK, "Loaded cookies: %s", data); + + apr_table_t* cookies; + const char *pair; + if(!data) return NULL; + + cookies = ap_make_table(r->pool, 4); + while(*data && (pair = ap_getword(r->pool, &data, ';'))) { + const char *name, *value; + if(*data == ' ') ++data; + name = ap_getword(r->pool, &pair, '='); + while(*pair && (value = ap_getword(r->pool, &pair, '&'))) { + ap_unescape_url((char *)value); + ap_table_add(cookies, name, value); + } + } + + return cookies; +} + + + + diff --git a/src/gateway/apachetools.h b/src/gateway/apachetools.h index cc4987f..d034b40 100644 --- a/src/gateway/apachetools.h +++ b/src/gateway/apachetools.h @@ -46,5 +46,10 @@ int apacheDebug( char* msg, ... ); */ int apacheError( char* msg, ... ); +/* + * Creates an apache table* of cookie name / value pairs + */ +apr_table_t* apacheParseCookies(request_rec *r); + #endif diff --git a/src/gateway/osrf_json_gateway.c b/src/gateway/osrf_json_gateway.c index 440c1ae..e927462 100644 --- a/src/gateway/osrf_json_gateway.c +++ b/src/gateway/osrf_json_gateway.c @@ -108,6 +108,7 @@ static int osrf_json_gateway_method_handler (request_rec *r) { char* a_l = NULL; /* request api level */ int isXML = 0; int api_level = 1; + apr_table_t* cookies = NULL; r->allowed |= (AP_METHOD_BIT << M_GET); r->allowed |= (AP_METHOD_BIT << M_POST); @@ -142,6 +143,12 @@ static int osrf_json_gateway_method_handler (request_rec *r) { } else { + if( 0 && (cookies = apacheParseCookies(r)) ) { + const char* authtoken = apr_table_get(cookies, "ses"); + osrfLogInfo(OSRF_LOG_MARK, "SESSION = %s", authtoken); + } + + osrfLogInfo( OSRF_LOG_MARK, "service=%s, method=%s", service, method ); osrfAppSession* session = osrf_app_client_session_init(service); int req_id = osrf_app_session_make_req( session, NULL, method, api_level, mparams );