From f5b7653f06443643c8bdc8d0da977f65eb8107d2 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/ILS/trunk@2299 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/apachemods/mod_rest_gateway.c | 8 +- Open-ILS/src/extras/fieldmapper.pl | 6 +- .../src/perlmods/OpenILS/Application/Actor.pm | 9 +- Open-ILS/web/opac/common/js/config.js | 1 + Open-ILS/web/opac/common/js/opac_utils.js | 7 +- Open-ILS/web/opac/locale/en-US/lang.dtd | 8 +- Open-ILS/web/opac/skin/default/js/holds.js | 80 ++++++++---- .../web/opac/skin/default/xml/altcanvas.xml | 1 + Open-ILS/web/opac/skin/default/xml/holds.xml | 115 +++++++++++------- .../web/opac/skin/default/xml/ilsevents.xml | 1 + OpenSRF/src/gateway/mod_ils_gateway.c | 71 ++++++----- OpenSRF/src/libstack/osrf_system.c | 2 +- OpenSRF/src/objson/json_parser.c | 1 + OpenSRF/src/utils/log.c | 8 +- 14 files changed, 199 insertions(+), 119 deletions(-) diff --git a/Open-ILS/src/apachemods/mod_rest_gateway.c b/Open-ILS/src/apachemods/mod_rest_gateway.c index 9fd4beb72f..8231ea17ed 100644 --- a/Open-ILS/src/apachemods/mod_rest_gateway.c +++ b/Open-ILS/src/apachemods/mod_rest_gateway.c @@ -1,4 +1,5 @@ #include "mod_rest_gateway.h" +#include "http_log.h" char* ils_rest_gateway_config_file; @@ -35,7 +36,6 @@ static void mod_ils_gateway_child_init(apr_pool_t *p, server_rec *s) { osrfLogError("Unable to load gateway config file..."); return; } - osrfLogSetAppname("oils_rest_gw"); fprintf(stderr, "Bootstrapping %d\n", getpid() ); fflush(stderr); } @@ -46,6 +46,8 @@ static int mod_ils_gateway_method_handler (request_rec *r) { if (strcmp(r->handler, MODULE_NAME )) return DECLINED; + osrfLogSetAppname("oils_rest_gw"); + apr_pool_t *p = r->pool; /* memory pool */ char* arg = r->args; /* url query string */ @@ -73,7 +75,6 @@ static int mod_ils_gateway_method_handler (request_rec *r) { } - /* gather the post args and append them to the url query string */ if( !strcmp(r->method,"POST") ) { @@ -88,7 +89,6 @@ static int mod_ils_gateway_method_handler (request_rec *r) { buffer = buffer_init(1025); while(ap_get_client_block(r, body, 1024)) { - osrfLogDebug("Apache read POST block data: %s\n", body); buffer_add( buffer, body ); memset(body,0,1025); } @@ -106,7 +106,7 @@ static int mod_ils_gateway_method_handler (request_rec *r) { } - osrfLogDebug("params args are %s", arg); + ap_log_rerror( APLOG_MARK, APLOG_DEBUG, 0, r, "URL: %s", arg ); if( ! arg || !arg[0] ) { /* we received no request */ diff --git a/Open-ILS/src/extras/fieldmapper.pl b/Open-ILS/src/extras/fieldmapper.pl index 9dd2ed0d74..23c719efcc 100755 --- a/Open-ILS/src/extras/fieldmapper.pl +++ b/Open-ILS/src/extras/fieldmapper.pl @@ -11,10 +11,10 @@ if(!$web) { $web = ""; } # List of classes needed by the opac my @web_hints = qw/asv asva asvr asvq - circ acp acpl acn ccs ahn aua ac - actscecm crcd crmf crrf mbts aoc aus mous/; + circ acp acpl acn ccs ahn + crcd crmf crrf mbts aoc aus mous/; -my @web_core = qw/ aou au perm_ex ex aout mvr ccs ahr /; +my @web_core = qw/ aou au perm_ex ex aout mvr ccs ahr aua ac actscecm /; my @reports = qw/ perm_ex ex ao aou aout /; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index d58fb1db50..94c5d5d736 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -14,6 +14,8 @@ use OpenILS::Application::AppUtils; use OpenILS::Utils::Fieldmapper; use OpenILS::Application::Search::Actor; use OpenILS::Utils::ModsParser; +use OpenSRF::Utils::Logger; +my $logger = "OpenSRF::Utils::Logger"; use OpenSRF::Utils::Cache; @@ -684,8 +686,11 @@ __PACKAGE__->register_method( sub user_retrieve_by_barcode { my($self, $client, $user_session, $barcode) = @_; - warn "Searching for user with barcode $barcode\n"; - my $user_obj = $apputils->check_user_session( $user_session ); + + $logger->debug("Searching for user with barcode $barcode"); + #my $user_obj = $apputils->check_user_session( $user_session ); + my ($user_obj, $evt) = $apputils->check_ses($user_session); + return $evt if $evt; my $session = OpenSRF::AppSession->create("open-ils.storage"); diff --git a/Open-ILS/web/opac/common/js/config.js b/Open-ILS/web/opac/common/js/config.js index e3ee5cbada..e7cce811a3 100644 --- a/Open-ILS/web/opac/common/js/config.js +++ b/Open-ILS/web/opac/common/js/config.js @@ -209,6 +209,7 @@ var CHECK_SPELL = "open-ils.search:open-ils.search.spell_check"; var FETCH_REVIEWS = "open-ils.search:open-ils.search.added_content.review.retrieve.all"; var FETCH_TOC = "open-ils.search:open-ils.search.added_content.toc.retrieve"; var FETCH_ACONT_SUMMARY = "open-ils.search:open-ils.search.added_content.summary.retrieve"; +var FETCH_USER_BYBARCODE = "open-ils.actor:open-ils.actor.user.fleshed.retrieve_by_barcode"; /* ---------------------------------------------------------------------------- */ diff --git a/Open-ILS/web/opac/common/js/opac_utils.js b/Open-ILS/web/opac/common/js/opac_utils.js index 3c929ec9f5..494e0b6afd 100644 --- a/Open-ILS/web/opac/common/js/opac_utils.js +++ b/Open-ILS/web/opac/common/js/opac_utils.js @@ -279,7 +279,6 @@ function grabUser(ses, force) { //new AuthTimer(20).run(); return G.user; - } @@ -643,3 +642,9 @@ function _authTimerAlert() { } +function grabUserByBarcode( authtoken, barcode ) { + var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode ); + req.send(true); + return req.result(); +} + diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 793e0b3fe0..f6ec32b893 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -22,6 +22,8 @@ + + @@ -117,7 +119,9 @@ - + + + diff --git a/Open-ILS/web/opac/skin/default/js/holds.js b/Open-ILS/web/opac/skin/default/js/holds.js index 5ff95d19b3..142e897bc7 100644 --- a/Open-ILS/web/opac/skin/default/js/holds.js +++ b/Open-ILS/web/opac/skin/default/js/holds.js @@ -2,16 +2,50 @@ var currentHoldRecord; var currentHoldRecordObj; var holdsOrgSelectorBuilt = false; +var holdRecipient; +var holdRequestor +var holdEmail; +var holdPhone; + + +function holdsHandleStaff() { + swapCanvas($('xulholds_box')); + $('xul_recipient_barcode').focus(); + $('xul_recipient_barcode').onkeypress = function(evt) + {if(userPressedEnter(evt)) { _holdsHandleStaff(); } }; + $('xul_recipient_barcode_submit').onclick = _holdsHandleStaff; +} + +function _holdsHandleStaff() { + var barcode = $('xul_recipient_barcode').value; + var user = grabUserByBarcode( G.user.session, barcode ); + if(!user) { + alert( '(' + barcode + ') => ' + $('user_not_found').innerHTML ); + showCanvas(); + return; + } + holdRecipient = user; + holdsDrawWindow( currentHoldRecord, null ); +} function holdsDrawWindow(recid, type) { if(recid == null) { recid = currentHoldRecord; if(recid == null) return; - } + } currentHoldRecord = recid; + + //if(isXUL() && holdRecipient == null ) { + if(holdRecipient == null ) { + holdsHandleStaff(); + return; + } + + if( holdRecipient == null ) holdRecipient = G.user; + if( holdRequestor == null ) holdRequestor = G.user; - if(!(G.user && G.user.session)) { + if(!(holdRequestor && holdRequestor.session)) { detachAllEvt('common','locationChanged'); attachEvt('common','loggedIn', holdsDrawWindow) @@ -28,15 +62,13 @@ function holdsDrawWindow(recid, type) { holdsOrgSelectorBuilt = true; } - removeChildren($('holds_title')); - removeChildren($('holds_author')); - removeChildren($('holds_format')); - removeChildren($('holds_email')); - removeChildren($('holds_email')); - - $('holds_title').appendChild(text(rec.title())); - $('holds_author').appendChild(text(rec.author())); + appendClear($('holds_recipient'), text( + holdRecipient.family_name() + ', ' + + holdRecipient.first_given_name())); + appendClear($('holds_title'), text(rec.title())); + appendClear($('holds_author'), text(rec.author())); + //removeChildren($('holds_format')); for( var i in rec.types_of_resource() ) { var res = rec.types_of_resource()[i]; var img = elem("img"); @@ -46,8 +78,8 @@ function holdsDrawWindow(recid, type) { $('holds_format').appendChild(text(' ')); } - $('holds_phone').appendChild(text(G.user.day_phone())); - $('holds_email').appendChild(text(G.user.email())); + appendClear( $('holds_phone'), text(holdRecipient.day_phone())); + appendClear( $('holds_email'), text(holdRecipient.email())); $('holds_cancel').onclick = showCanvas; $('holds_submit').onclick = holdsPlaceHold; } @@ -81,7 +113,7 @@ function holdsBuildOrgSelector(node, depth) { selector.options[index] = select; } - if( node.id() == G.user.home_ou() ) { + if( node.id() == holdRecipient.home_ou() ) { selector.selectedIndex = index; selector.options[index].selected = true; } @@ -95,33 +127,35 @@ function holdsBuildOrgSelector(node, depth) { } function holdsPlaceHold() { - //alert("placing hold for " + currentHoldRecord ); - var org = $('holds_org_selector').options[$('holds_org_selector').selectedIndex].value; + var org = $('holds_org_selector').options[ + $('holds_org_selector').selectedIndex].value; var hold = new ahr(); hold.pickup_lib(org); hold.request_lib(org); - hold.requestor(G.user.id()); - hold.usr(G.user.id()); + hold.requestor(holdRequestor.id()); + hold.usr(holdRecipient.id()); hold.hold_type('T'); - hold.email_notify(G.user.email()); - hold.phone_notify(G.user.day_phone()); + hold.email_notify(holdRecipient.email()); + hold.phone_notify(holdRecipient.day_phone()); hold.target(currentHoldRecord); - var req = new Request( CREATE_HOLD, G.user.session, hold ); + var req = new Request( CREATE_HOLD, holdRequestor.session, hold ); req.send(true); var res = req.result(); - /* XMLize me XXX */ if( res == '1' ) alert($('holds_success').innerHTML); else alert($('holds_failure').innerHTML); showCanvas(); + holdRecipient = null; + holdRequestor = null; } -function holdsCancel(holdid) { - var req = new Request(CANCEL_HOLD, G.user.session, holdid); +function holdsCancel(holdid, user) { + if(!user) user = G.user; + var req = new Request(CANCEL_HOLD, user.session, holdid); req.send(true); return req.result(); } diff --git a/Open-ILS/web/opac/skin/default/xml/altcanvas.xml b/Open-ILS/web/opac/skin/default/xml/altcanvas.xml index 2cc0292604..448ede5a2b 100644 --- a/Open-ILS/web/opac/skin/default/xml/altcanvas.xml +++ b/Open-ILS/web/opac/skin/default/xml/altcanvas.xml @@ -17,6 +17,7 @@ config.ids.altcanvas.login = config.ids.login.box; config.ids.altcanvas.org_tree = config.ids.common.org_container; config.ids.altcanvas.holds = 'holds_box'; + config.ids.altcanvas.xulholds = 'xulholds_box'; config.ids.altcanvas.loading = 'loading_alt'; diff --git a/Open-ILS/web/opac/skin/default/xml/holds.xml b/Open-ILS/web/opac/skin/default/xml/holds.xml index 939786db27..f2ebdbb001 100644 --- a/Open-ILS/web/opac/skin/default/xml/holds.xml +++ b/Open-ILS/web/opac/skin/default/xml/holds.xml @@ -1,51 +1,72 @@ -
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
&opac.holds.placeHold;
&common.title;:
&common.author;:
&common.format;:
&opac.holds.contactPhone;:
&opac.holds.concactEmail;:
&opac.holds.pickupLocation; - -
- - - -
- -
&opac.holds.success;
-
&opac.holds.failure;
+
+
+
+ + + + + + + + +
&opac.holds.xulRecipient;:
+
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
&opac.holds.placeHold;
&opac.holds.recipient;:
&common.title;:
&common.author;:
&common.format;:
&opac.holds.contactPhone;:
&opac.holds.concactEmail;:
&opac.holds.pickupLocation; + +
+ + + +
+ +
&opac.holds.success;
+
&opac.holds.failure;
+ +
diff --git a/Open-ILS/web/opac/skin/default/xml/ilsevents.xml b/Open-ILS/web/opac/skin/default/xml/ilsevents.xml index 6db5f476f6..3279ca4a92 100644 --- a/Open-ILS/web/opac/skin/default/xml/ilsevents.xml +++ b/Open-ILS/web/opac/skin/default/xml/ilsevents.xml @@ -6,5 +6,6 @@ &opac.session_expiring; &opac.session_expired; + &common.user_not_found; diff --git a/OpenSRF/src/gateway/mod_ils_gateway.c b/OpenSRF/src/gateway/mod_ils_gateway.c index 21067ec98d..82a9a3c43f 100644 --- a/OpenSRF/src/gateway/mod_ils_gateway.c +++ b/OpenSRF/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/OpenSRF/src/libstack/osrf_system.c b/OpenSRF/src/libstack/osrf_system.c index ac698f74cc..794a1f5be5 100644 --- a/OpenSRF/src/libstack/osrf_system.c +++ b/OpenSRF/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/OpenSRF/src/objson/json_parser.c b/OpenSRF/src/objson/json_parser.c index 63ba6b3718..159eca1ed8 100644 --- a/OpenSRF/src/objson/json_parser.c +++ b/OpenSRF/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/OpenSRF/src/utils/log.c b/OpenSRF/src/utils/log.c index 40ec051cd6..03c8809ce4 100644 --- a/OpenSRF/src/utils/log.c +++ b/OpenSRF/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.43.2