From: erickson Date: Mon, 14 May 2007 22:58:03 +0000 (+0000) Subject: Committing massive pile of new-json code. This includes: X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6ed23b5c7d748f74bbf1a5cbcd7ddfed5bf0cf4c;p=Evergreen.git Committing massive pile of new-json code. This includes: the new-json object encoding protocol a new C JSON parser which uses osrfHash and osrfList and is built into libopensrf (but has a standalone makefile) altered osrfHashIterator API some more work on the Python opensrf bindings Lots of small updates to extract objson from header files and makefiles, etc. support for new and legacy JSON encodings in the opensrf JSON gateway git-svn-id: svn://svn.open-ils.org/ILS/branches/new-json@7308 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Evergreen/Makefile b/Evergreen/Makefile index b636fde374..f96a5cd939 100644 --- a/Evergreen/Makefile +++ b/Evergreen/Makefile @@ -42,7 +42,7 @@ iplist-install: web-install: @echo $@ - cp web/opac/images/* $(WEBDIR)/opac/images/ + cp web/opac/images/* $(WEBDIR)/opac/images/ clean: if [ -d local_staff_client ]; then make -C local_staff_client clean; fi; diff --git a/Makefile b/Makefile index 2996d44e15..de5ac928ef 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,9 @@ build: oldconfig install: @./install.sh install +verbose_install: + @./install.sh install verbose + clean: @./install.sh clean diff --git a/Open-ILS/src/Makefile b/Open-ILS/src/Makefile index 8219bc9215..7c32288afc 100644 --- a/Open-ILS/src/Makefile +++ b/Open-ILS/src/Makefile @@ -61,8 +61,6 @@ server-xul: webcore-install: @echo $@ echo "Copying web into $(WEBDIR)" - mkdir -p $(ADMINDIR) - cp -r ../admin/* $(ADMINDIR) mkdir -p $(WEBDIR) mkdir -p $(WEBDIR)/opac/extras/xsl/ cp -r ../web/* $(WEBDIR) @@ -76,7 +74,6 @@ webcore-install: cp ../xsl/*.xsl $(WEBDIR)/opac/extras/xsl/ ln -sf $(ETCDIR)/fm_IDL.xml $(WEBDIR)/reports/ cp ../xul/staff_client/server/admin/adminlib.js $(WEBDIR)/reports/ - mkdir -p $(WEBDIR)/opac/extras/slimpac/ libfieldmapper: @@ -135,12 +132,6 @@ perl-install: reporter-install: @echo $@ -# @echo "Installing Reporter templates to $(REPORTERDIR) and example configs to $(ETCDIR)" -# cp reporter/report_base.example.xml $(ETCDIR)/reporter.example.xml -# cp reporter/tables.example.xml $(ETCDIR) -# cp reporter/widgets.example.xml $(ETCDIR) -# mkdir -p $(REPORTERDIR) -# cp -r reporter/templates/* $(REPORTERDIR) # ----------------------------------------------------------------------------------- offline-install: @@ -188,8 +179,8 @@ xsl-install: @echo "Installing XSL files to $(XSLDIR)" mkdir -p $(XSLDIR) cp ../xsl/*.xsl $(XSLDIR) -# mkdir -p $(WEBDIR)/xsl/ -# cp ../xsl/*.xsl $(WEBDIR)/xsl/ + mkdir -p $(WEBDIR)/xsl/ + cp ../xsl/*.xsl $(WEBDIR)/xsl/ clean: @echo $@ diff --git a/Open-ILS/src/apachemods/json_xml.h b/Open-ILS/src/apachemods/json_xml.h index 2752fd0492..53c7773492 100644 --- a/Open-ILS/src/apachemods/json_xml.h +++ b/Open-ILS/src/apachemods/json_xml.h @@ -3,8 +3,7 @@ #include /* the JSON parser, so we can read the response we're XMLizing */ -#include "objson/object.h" -#include "objson/json_parser.h" +#include "opensrf/osrf_json.h" #include "utils.h" char* json_string_to_xml(char*); diff --git a/Open-ILS/src/apachemods/mod_rest_gateway.h b/Open-ILS/src/apachemods/mod_rest_gateway.h index 571e3d6d16..dcfe9b5691 100644 --- a/Open-ILS/src/apachemods/mod_rest_gateway.h +++ b/Open-ILS/src/apachemods/mod_rest_gateway.h @@ -11,8 +11,7 @@ #include "opensrf/osrf_app_session.h" #include "string_array.h" #include "md5.h" -#include "objson/object.h" -#include "objson/json_parser.h" +#include "opensrf/osrf_json.h" #include "json_xml.h" #define GATEWAY_CONFIG "ILSRestGatewayConfig" diff --git a/Open-ILS/src/c-apps/Makefile b/Open-ILS/src/c-apps/Makefile index 3ecbe0e929..ae6e1f79f7 100644 --- a/Open-ILS/src/c-apps/Makefile +++ b/Open-ILS/src/c-apps/Makefile @@ -1,4 +1,4 @@ -LDLIBS += -lobjson -lopensrf #-lfieldmapper +LDLIBS += -lopensrf CFLAGS += -DOSRF_LOG_PARAMS #all: oils_auth.so oils_fetch.so oils_cstore.so diff --git a/Open-ILS/src/c-apps/oils_auth.c b/Open-ILS/src/c-apps/oils_auth.c index 1b449192f7..f4e5b95eb4 100644 --- a/Open-ILS/src/c-apps/oils_auth.c +++ b/Open-ILS/src/c-apps/oils_auth.c @@ -1,7 +1,7 @@ #include "opensrf/osrf_app_session.h" #include "opensrf/osrf_application.h" #include "opensrf/osrf_settings.h" -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/log.h" #include "oils_utils.h" #include "oils_constants.h" diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index cd10914ea9..a4b1a1903d 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -1,7 +1,7 @@ #include "opensrf/osrf_application.h" #include "opensrf/osrf_settings.h" #include "opensrf/utils.h" -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/log.h" #include "oils_idl.h" #include @@ -45,9 +45,9 @@ jsonObject* oilsMakeJSONFromResult( dbi_result ); char* searchWriteSimplePredicate ( const char*, osrfHash*, const char*, const char*, const char* ); char* searchSimplePredicate ( const char*, const char*, osrfHash*, jsonObject* ); -char* searchFunctionPredicate ( const char*, osrfHash*, jsonObjectNode* ); +char* searchFunctionPredicate ( const char*, osrfHash*, char* key, jsonObject* obj ); char* searchFieldTransform (const char*, osrfHash*, jsonObject*); -char* searchFieldTransformPredicate ( const char*, osrfHash*, jsonObjectNode* ); +char* searchFieldTransformPredicate ( const char*, osrfHash*, char* key, jsonObject* obj ); char* searchBETWEENPredicate ( const char*, osrfHash*, jsonObject* ); char* searchINPredicate ( const char*, osrfHash*, jsonObject*, const char* ); char* searchPredicate ( const char*, osrfHash*, jsonObject* ); @@ -575,10 +575,10 @@ int dispatchCRUDMethod ( osrfMethodContext* ctx ) { obj = doFieldmapperSearch(ctx, class_obj, ctx->params, &err); if(err) return err; - jsonObjectNode* cur; + jsonObject* cur; jsonObjectIterator* itr = jsonNewObjectIterator( obj ); while ((cur = jsonObjectIteratorNext( itr ))) { - osrfAppRespond( ctx, jsonObjectClone(cur->item) ); + osrfAppRespond( ctx, jsonObjectClone(cur) ); } jsonObjectIteratorFree(itr); osrfAppRespondComplete( ctx, NULL ); @@ -605,14 +605,14 @@ int dispatchCRUDMethod ( osrfMethodContext* ctx ) { obj = doFieldmapperSearch(ctx, class_obj, _p, &err); if(err) return err; - jsonObjectNode* cur; + jsonObject* cur; jsonObjectIterator* itr = jsonNewObjectIterator( obj ); while ((cur = jsonObjectIteratorNext( itr ))) { osrfAppRespond( ctx, jsonObjectClone( jsonObjectGetIndex( - cur->item, + cur, atoi( osrfHashGet( osrfHashGet( @@ -1060,17 +1060,17 @@ char* searchValueTransform( jsonObject* array ) { return pred; } -char* searchFunctionPredicate (const char* class, osrfHash* field, jsonObjectNode* node) { +char* searchFunctionPredicate (const char* class, osrfHash* field, char* key, jsonObject* obj) { growing_buffer* sql_buf = buffer_init(32); - char* val = searchValueTransform(node->item); + char* val = searchValueTransform(obj); buffer_fadd( sql_buf, "\"%s\".%s %s %s", class, osrfHashGet(field, "name"), - node->key, + key, val ); @@ -1099,23 +1099,23 @@ char* searchFieldTransform (const char* class, osrfHash* field, jsonObject* node return pred; } -char* searchFieldTransformPredicate (const char* class, osrfHash* field, jsonObjectNode* node) { +char* searchFieldTransformPredicate (const char* class, osrfHash* field, char* key, jsonObject* obj) { growing_buffer* sql_buf = buffer_init(32); - char* field_transform = searchFieldTransform( class, field, node->item ); + char* field_transform = searchFieldTransform( class, field, obj ); char* value = NULL; - if (!jsonObjectGetKey( node->item, "value" )) { - value = searchWHERE( node->item, osrfHashGet( oilsIDL(), class ), 0 ); - } else if (jsonObjectGetKey( node->item, "value" )->type == JSON_ARRAY) { - value = searchValueTransform(jsonObjectGetKey( node->item, "value" )); - } else if (jsonObjectGetKey( node->item, "value" )->type == JSON_HASH) { - value = searchWHERE( jsonObjectGetKey( node->item, "value" ), osrfHashGet( oilsIDL(), class ), 0 ); - } else if (jsonObjectGetKey( node->item, "value" )->type != JSON_NULL) { + if (!jsonObjectGetKey( obj, "value" )) { + value = searchWHERE( obj, osrfHashGet( oilsIDL(), class ), 0 ); + } else if (jsonObjectGetKey( obj, "value" )->type == JSON_ARRAY) { + value = searchValueTransform(jsonObjectGetKey( obj, "value" )); + } else if (jsonObjectGetKey( obj, "value" )->type == JSON_HASH) { + value = searchWHERE( jsonObjectGetKey( obj, "value" ), osrfHashGet( oilsIDL(), class ), 0 ); + } else if (jsonObjectGetKey( obj, "value" )->type != JSON_NULL) { if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) { - value = jsonNumberToDBString( field, jsonObjectGetKey( node->item, "value" ) ); + value = jsonNumberToDBString( field, jsonObjectGetKey( obj, "value" ) ); } else { - value = jsonObjectToSimpleString(jsonObjectGetKey( node->item, "value" )); + value = jsonObjectToSimpleString(jsonObjectGetKey( obj, "value" )); if ( !dbi_conn_quote_string(dbhandle, &value) ) { osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, value); free(value); @@ -1128,7 +1128,7 @@ char* searchFieldTransformPredicate (const char* class, osrfHash* field, jsonObj sql_buf, "%s %s %s", field_transform, - node->key, + key, value ); @@ -1233,19 +1233,19 @@ char* searchPredicate ( const char* class, osrfHash* field, jsonObject* node ) { if (node->type == JSON_ARRAY) { // equality IN search pred = searchINPredicate( class, field, node, NULL ); } else if (node->type == JSON_HASH) { // non-equality search - jsonObjectNode* pred_node; + jsonObject* pred_obj; jsonObjectIterator* pred_itr = jsonNewObjectIterator( node ); - while ( (pred_node = jsonObjectIteratorNext( pred_itr )) ) { - if ( !(strcasecmp( pred_node->key,"between" )) ) - pred = searchBETWEENPredicate( class, field, pred_node->item ); - else if ( !(strcasecmp( pred_node->key,"in" )) || !(strcasecmp( pred_node->key,"not in" )) ) - pred = searchINPredicate( class, field, pred_node->item, pred_node->key ); - else if ( pred_node->item->type == JSON_ARRAY ) - pred = searchFunctionPredicate( class, field, pred_node ); - else if ( pred_node->item->type == JSON_HASH ) - pred = searchFieldTransformPredicate( class, field, pred_node ); + while ( (pred_obj = jsonObjectIteratorNext( pred_itr )) ) { + if ( !(strcasecmp( pred_itr->key,"between" )) ) + pred = searchBETWEENPredicate( class, field, pred_obj ); + else if ( !(strcasecmp( pred_itr->key,"in" )) || !(strcasecmp( pred_itr->key,"not in" )) ) + pred = searchINPredicate( class, field, pred_obj, pred_itr->key ); + else if ( pred_obj->type == JSON_ARRAY ) + pred = searchFunctionPredicate( class, field, pred_itr->key, pred_obj); + else if ( pred_obj->type == JSON_HASH ) + pred = searchFieldTransformPredicate( class, field, pred_itr->key, pred_obj); else - pred = searchSimplePredicate( pred_node->key, class, field, pred_node->item ); + pred = searchSimplePredicate( pred_itr->key, class, field, pred_obj ); break; } @@ -1307,21 +1307,21 @@ char* searchJOIN ( jsonObject* join_hash, osrfHash* leftmeta ) { growing_buffer* join_buf = buffer_init(128); char* leftclass = osrfHashGet(leftmeta, "classname"); - jsonObjectNode* snode = NULL; + jsonObject* sobj = NULL; jsonObjectIterator* search_itr = jsonNewObjectIterator( join_hash ); - while ( (snode = jsonObjectIteratorNext( search_itr )) ) { - osrfHash* idlClass = osrfHashGet( oilsIDL(), snode->key ); + while ( (sobj= jsonObjectIteratorNext( search_itr )) ) { + osrfHash* idlClass = osrfHashGet( oilsIDL(), search_itr->key ); char* class = osrfHashGet(idlClass, "classname"); char* table = osrfHashGet(idlClass, "tablename"); - char* type = jsonObjectToSimpleString( jsonObjectGetKey( snode->item, "type" ) ); - char* filter_op = jsonObjectToSimpleString( jsonObjectGetKey( snode->item, "filter_op" ) ); - char* fkey = jsonObjectToSimpleString( jsonObjectGetKey( snode->item, "fkey" ) ); - char* field = jsonObjectToSimpleString( jsonObjectGetKey( snode->item, "field" ) ); + char* type = jsonObjectToSimpleString( jsonObjectGetKey( sobj, "type" ) ); + char* filter_op = jsonObjectToSimpleString( jsonObjectGetKey( sobj, "filter_op" ) ); + char* fkey = jsonObjectToSimpleString( jsonObjectGetKey( sobj, "fkey" ) ); + char* field = jsonObjectToSimpleString( jsonObjectGetKey( sobj, "field" ) ); - jsonObject* filter = jsonObjectGetKey( snode->item, "filter" ); - jsonObject* join_filter = jsonObjectGetKey( snode->item, "join" ); + jsonObject* filter = jsonObjectGetKey( sobj, "filter" ); + jsonObject* join_filter = jsonObjectGetKey( sobj, "join" ); if (field && !fkey) { fkey = (char*)oilsIDLFindPath("/%s/links/%s/key", class, field); @@ -1462,7 +1462,7 @@ char* searchWHERE ( jsonObject* search_hash, osrfHash* meta, int opjoin_type ) { growing_buffer* sql_buf = buffer_init(128); - jsonObjectNode* node = NULL; + jsonObject* node = NULL; int first = 1; jsonObjectIterator* search_itr = jsonNewObjectIterator( search_hash ); @@ -1475,43 +1475,43 @@ char* searchWHERE ( jsonObject* search_hash, osrfHash* meta, int opjoin_type ) { else buffer_add(sql_buf, " AND "); } - if ( !strncmp("+",node->key,1) ) { - if ( node->item->type == JSON_STRING ) { - char* subpred = jsonObjectToSimpleString( node->item ); - buffer_fadd(sql_buf, " \"%s\".%s ", node->key + 1, subpred); + if ( !strncmp("+",search_itr->key,1) ) { + if ( node->type == JSON_STRING ) { + char* subpred = jsonObjectToSimpleString( node ); + buffer_fadd(sql_buf, " \"%s\".%s ", search_itr->key + 1, subpred); free(subpred); } else { - char* subpred = searchWHERE( node->item, osrfHashGet( oilsIDL(), node->key + 1 ), 0); + char* subpred = searchWHERE( node, osrfHashGet( oilsIDL(), search_itr->key + 1 ), 0); buffer_fadd(sql_buf, "( %s )", subpred); free(subpred); } - } else if ( !strcasecmp("-or",node->key) ) { - char* subpred = searchWHERE( node->item, meta, 1); + } else if ( !strcasecmp("-or",search_itr->key) ) { + char* subpred = searchWHERE( node, meta, 1); buffer_fadd(sql_buf, "( %s )", subpred); free(subpred); - } else if ( !strcasecmp("-and",node->key) ) { - char* subpred = searchWHERE( node->item, meta, 0); + } else if ( !strcasecmp("-and",search_itr->key) ) { + char* subpred = searchWHERE( node, meta, 0); buffer_fadd(sql_buf, "( %s )", subpred); free(subpred); } else { char* class = osrfHashGet(meta, "classname"); osrfHash* fields = osrfHashGet(meta, "fields"); - osrfHash* field = osrfHashGet( fields, node->key ); + osrfHash* field = osrfHashGet( fields, search_itr->key ); if (!field) { osrfLogError( OSRF_LOG_MARK, "%s: Attempt to reference non-existant column %s on table %s", MODULENAME, - node->key, + search_itr->key, osrfHashGet(meta, "tablename") ); buffer_free(sql_buf); return NULL; } - char* subpred = searchPredicate( class, field, node->item ); + char* subpred = searchPredicate( class, field, node ); buffer_add( sql_buf, subpred ); free(subpred); } @@ -1540,11 +1540,11 @@ char* SELECT ( jsonObject* defaultselhash = NULL; // general tmp objects - jsonObject* __tmp = NULL; - jsonObjectNode* selclass = NULL; - jsonObjectNode* selfield = NULL; - jsonObjectNode* snode = NULL; - jsonObjectNode* onode = NULL; + jsonObject* __tmp = NULL; + jsonObject* selclass = NULL; + jsonObject* selfield = NULL; + jsonObject* snode = NULL; + jsonObject* onode = NULL; jsonObject* found = NULL; char* string = NULL; @@ -1581,8 +1581,8 @@ char* SELECT ( jsonObjectIterator* tmp_itr = jsonNewObjectIterator( join_hash ); snode = jsonObjectIteratorNext( tmp_itr ); - core_class = strdup( snode->key ); - join_hash = snode->item; + core_class = strdup( tmp_itr->key ); + join_hash = snode; jsonObjectIteratorFree( tmp_itr ); snode = NULL; @@ -1635,7 +1635,7 @@ char* SELECT ( while ( (selclass = jsonObjectIteratorNext( selclass_itr )) ) { // round trip through the idl, just to be safe - idlClass = osrfHashGet( oilsIDL(), selclass->key ); + idlClass = osrfHashGet( oilsIDL(), selclass_itr->key ); if (!idlClass) continue; char* cname = osrfHashGet(idlClass, "classname"); @@ -1660,17 +1660,17 @@ char* SELECT ( } // stitch together the column list ... - jsonObjectIterator* select_itr = jsonNewObjectIterator( selclass->item ); + jsonObjectIterator* select_itr = jsonNewObjectIterator( selclass ); while ( (selfield = jsonObjectIteratorNext( select_itr )) ) { char* __column = NULL; char* __alias = NULL; // ... if it's a sstring, just toss it on the pile - if (selfield->item->type == JSON_STRING) { + if (selfield->type == JSON_STRING) { // again, just to be safe - char* _requested_col = jsonObjectToSimpleString(selfield->item); + char* _requested_col = jsonObjectToSimpleString(selfield); osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), _requested_col ); free(_requested_col); @@ -1688,7 +1688,7 @@ char* SELECT ( // ... but it could be an object, in which case we check for a Field Transform } else { - __column = jsonObjectToSimpleString( jsonObjectGetKey( selfield->item, "column" ) ); + __column = jsonObjectToSimpleString( jsonObjectGetKey( selfield, "column" ) ); // again, just to be safe osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), __column ); @@ -1701,15 +1701,15 @@ char* SELECT ( buffer_add(select_buf, ","); } - if ((__tmp = jsonObjectGetKey( selfield->item, "alias" ))) { + if ((__tmp = jsonObjectGetKey( selfield, "alias" ))) { __alias = jsonObjectToSimpleString( __tmp ); } else { __alias = strdup(__column); } - if (jsonObjectGetKey( selfield->item, "transform" )) { + if (jsonObjectGetKey( selfield, "transform" )) { free(__column); - __column = searchFieldTransform(cname, field, selfield->item); + __column = searchFieldTransform(cname, field, selfield); buffer_fadd(select_buf, " %s AS \"%s\"", __column, __alias); } else { buffer_fadd(select_buf, " \"%s\".%s AS \"%s\"", cname, fname, __alias); @@ -1718,7 +1718,7 @@ char* SELECT ( if (is_agg->size || (flags & SELECT_DISTINCT)) { - if (!jsonBoolIsTrue( jsonObjectGetKey( selfield->item, "aggregate" ) )) { + if (!jsonBoolIsTrue( jsonObjectGetKey( selfield, "aggregate" ) )) { if (gfirst) { gfirst = 0; } else { @@ -1727,16 +1727,16 @@ char* SELECT ( buffer_fadd(group_buf, " %d", sel_pos); /* - } else if (is_agg = jsonObjectGetKey( selfield->item, "having" )) { + } else if (is_agg = jsonObjectGetKey( selfield, "having" )) { if (gfirst) { gfirst = 0; } else { buffer_add(group_buf, ","); } - __column = searchFieldTransform(cname, field, selfield->item); + __column = searchFieldTransform(cname, field, selfield); buffer_fadd(group_buf, " %s", __column); - __column = searchFieldTransform(cname, field, selfield->item); + __column = searchFieldTransform(cname, field, selfield); */ } } @@ -1791,33 +1791,33 @@ char* SELECT ( jsonObjectIterator* class_itr = jsonNewObjectIterator( order_hash ); while ( (snode = jsonObjectIteratorNext( class_itr )) ) { - if (!jsonObjectGetKey(selhash,snode->key)) + if (!jsonObjectGetKey(selhash,class_itr->key)) continue; - if ( snode->item->type == JSON_HASH ) { + if ( snode->type == JSON_HASH ) { - jsonObjectIterator* order_itr = jsonNewObjectIterator( snode->item ); + jsonObjectIterator* order_itr = jsonNewObjectIterator( snode ); while ( (onode = jsonObjectIteratorNext( order_itr )) ) { - if (!oilsIDLFindPath( "/%s/fields/%s", snode->key, onode->key )) + if (!oilsIDLFindPath( "/%s/fields/%s", class_itr->key, order_itr->key )) continue; char* direction = NULL; - if ( onode->item->type == JSON_HASH ) { - if ( jsonObjectGetKey( onode->item, "transform" ) ) { + if ( onode->type == JSON_HASH ) { + if ( jsonObjectGetKey( onode, "transform" ) ) { string = searchFieldTransform( - snode->key, - oilsIDLFindPath( "/%s/fields/%s", snode->key, onode->key ), - onode->item + class_itr->key, + oilsIDLFindPath( "/%s/fields/%s", class_itr->key, order_itr->key ), + onode ); } else { growing_buffer* field_buf = buffer_init(16); - buffer_fadd(field_buf, "\"%s\".%s", snode->key, onode->key); + buffer_fadd(field_buf, "\"%s\".%s", class_itr->key, order_itr->key); string = buffer_data(field_buf); buffer_free(field_buf); } - if ( (__tmp = jsonObjectGetKey( onode->item, "direction" )) ) { + if ( (__tmp = jsonObjectGetKey( onode, "direction" )) ) { direction = jsonObjectToSimpleString(__tmp); if (!strncasecmp(direction, "d", 1)) { free(direction); @@ -1829,8 +1829,8 @@ char* SELECT ( } } else { - string = strdup(onode->key); - direction = jsonObjectToSimpleString(onode->item); + string = strdup(order_itr->key); + direction = jsonObjectToSimpleString(onode); if (!strncasecmp(direction, "d", 1)) { free(direction); direction = " DESC"; @@ -1855,14 +1855,14 @@ char* SELECT ( } - } else if ( snode->item->type == JSON_ARRAY ) { + } else if ( snode->type == JSON_ARRAY ) { - jsonObjectIterator* order_itr = jsonNewObjectIterator( snode->item ); + jsonObjectIterator* order_itr = jsonNewObjectIterator( snode ); while ( (onode = jsonObjectIteratorNext( order_itr )) ) { - char* _f = jsonObjectToSimpleString( onode->item ); + char* _f = jsonObjectToSimpleString( onode ); - if (!oilsIDLFindPath( "/%s/fields/%s", snode->key, _f)) + if (!oilsIDLFindPath( "/%s/fields/%s", class_itr->key, _f)) continue; if (first) { @@ -1966,9 +1966,9 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m jsonObject* join_hash = jsonObjectGetKey( order_hash, "join" ); - jsonObjectNode* node = NULL; - jsonObjectNode* snode = NULL; - jsonObjectNode* onode = NULL; + jsonObject* node = NULL; + jsonObject* snode = NULL; + jsonObject* onode = NULL; jsonObject* _tmp = NULL; jsonObject* selhash = NULL; jsonObject* defaultselhash = NULL; @@ -2000,14 +2000,14 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m jsonObjectIterator* class_itr = jsonNewObjectIterator( selhash ); while ( (snode = jsonObjectIteratorNext( class_itr )) ) { - osrfHash* idlClass = osrfHashGet( oilsIDL(), snode->key ); + osrfHash* idlClass = osrfHashGet( oilsIDL(), class_itr->key ); if (!idlClass) continue; char* cname = osrfHashGet(idlClass, "classname"); - if (strcmp(core_class,snode->key)) { + if (strcmp(core_class,class_itr->key)) { if (!join_hash) continue; - jsonObject* found = jsonObjectFindPath(join_hash, "//%s", snode->key); + jsonObject* found = jsonObjectFindPath(join_hash, "//%s", class_itr->key); if (!found->size) { jsonObjectFree(found); continue; @@ -2016,9 +2016,9 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m jsonObjectFree(found); } - jsonObjectIterator* select_itr = jsonNewObjectIterator( snode->item ); + jsonObjectIterator* select_itr = jsonNewObjectIterator( snode ); while ( (node = jsonObjectIteratorNext( select_itr )) ) { - osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), jsonObjectToSimpleString(node->item) ); + osrfHash* field = osrfHashGet( osrfHashGet( idlClass, "fields" ), jsonObjectToSimpleString(node) ); char* fname = osrfHashGet(field, "name"); if (!field) continue; @@ -2072,33 +2072,33 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m jsonObjectIterator* class_itr = jsonNewObjectIterator( _tmp ); while ( (snode = jsonObjectIteratorNext( class_itr )) ) { - if (!jsonObjectGetKey(selhash,snode->key)) + if (!jsonObjectGetKey(selhash,class_itr->key)) continue; - if ( snode->item->type == JSON_HASH ) { + if ( snode->type == JSON_HASH ) { - jsonObjectIterator* order_itr = jsonNewObjectIterator( snode->item ); + jsonObjectIterator* order_itr = jsonNewObjectIterator( snode ); while ( (onode = jsonObjectIteratorNext( order_itr )) ) { - if (!oilsIDLFindPath( "/%s/fields/%s", snode->key, onode->key )) + if (!oilsIDLFindPath( "/%s/fields/%s", class_itr->key, order_itr->key )) continue; char* direction = NULL; - if ( onode->item->type == JSON_HASH ) { - if ( jsonObjectGetKey( onode->item, "transform" ) ) { + if ( onode->type == JSON_HASH ) { + if ( jsonObjectGetKey( onode, "transform" ) ) { string = searchFieldTransform( - snode->key, - oilsIDLFindPath( "/%s/fields/%s", snode->key, onode->key ), - onode->item + class_itr->key, + oilsIDLFindPath( "/%s/fields/%s", class_itr->key, order_itr->key ), + onode ); } else { growing_buffer* field_buf = buffer_init(16); - buffer_fadd(field_buf, "\"%s\".%s", snode->key, onode->key); + buffer_fadd(field_buf, "\"%s\".%s", class_itr->key, order_itr->key); string = buffer_data(field_buf); buffer_free(field_buf); } - if ( (_tmp = jsonObjectGetKey( onode->item, "direction" )) ) { + if ( (_tmp = jsonObjectGetKey( onode, "direction" )) ) { direction = jsonObjectToSimpleString(_tmp); if (!strncasecmp(direction, "d", 1)) { free(direction); @@ -2110,8 +2110,8 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m } } else { - string = strdup(onode->key); - direction = jsonObjectToSimpleString(onode->item); + string = strdup(order_itr->key); + direction = jsonObjectToSimpleString(onode); if (!strncasecmp(direction, "d", 1)) { free(direction); direction = " DESC"; @@ -2137,7 +2137,7 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m } } else { - string = jsonObjectToSimpleString(snode->item); + string = jsonObjectToSimpleString(snode); buffer_add(order_buf, string); free(string); break; @@ -2346,16 +2346,16 @@ jsonObject* doFieldmapperSearch ( osrfMethodContext* ctx, osrfHash* meta, jsonOb } if (!link_fields) { - jsonObjectNode* _f; + jsonObject* _f; link_fields = osrfNewStringArray(1); jsonObjectIterator* _i = jsonNewObjectIterator( flesh_fields ); while ((_f = jsonObjectIteratorNext( _i ))) { - osrfStringArrayAdd( link_fields, jsonObjectToSimpleString( _f->item ) ); + osrfStringArrayAdd( link_fields, jsonObjectToSimpleString( _f ) ); } } } - jsonObjectNode* cur; + jsonObject* cur; jsonObjectIterator* itr = jsonNewObjectIterator( res_list ); while ((cur = jsonObjectIteratorNext( itr ))) { @@ -2419,7 +2419,7 @@ jsonObject* doFieldmapperSearch ( osrfMethodContext* ctx, osrfHash* meta, jsonOb char* search_key = jsonObjectToSimpleString( jsonObjectGetIndex( - cur->item, + cur, atoi( osrfHashGet(value_field, "array_position") ) ) ); @@ -2480,14 +2480,14 @@ jsonObject* doFieldmapperSearch ( osrfMethodContext* ctx, osrfHash* meta, jsonOb X = kids; kids = jsonParseString("[]"); - jsonObjectNode* _k_node; + jsonObject* _k_node; jsonObjectIterator* _k = jsonNewObjectIterator( X ); while ((_k_node = jsonObjectIteratorNext( _k ))) { jsonObjectPush( kids, jsonObjectClone( jsonObjectGetIndex( - _k_node->item, + _k_node, (unsigned long)atoi( osrfHashGet( osrfHashGet( @@ -2512,7 +2512,7 @@ jsonObject* doFieldmapperSearch ( osrfMethodContext* ctx, osrfHash* meta, jsonOb if (!(strcmp( osrfHashGet(kid_link, "reltype"), "has_a" )) || !(strcmp( osrfHashGet(kid_link, "reltype"), "might_have" ))) { osrfLogDebug(OSRF_LOG_MARK, "Storing fleshed objects in %s", osrfHashGet(kid_link, "field")); jsonObjectSetIndex( - cur->item, + cur, (unsigned long)atoi( osrfHashGet( field, "array_position" ) ), jsonObjectClone( jsonObjectGetIndex(kids, 0) ) ); @@ -2521,7 +2521,7 @@ jsonObject* doFieldmapperSearch ( osrfMethodContext* ctx, osrfHash* meta, jsonOb if (!(strcmp( osrfHashGet(kid_link, "reltype"), "has_many" ))) { // has_many osrfLogDebug(OSRF_LOG_MARK, "Storing fleshed objects in %s", osrfHashGet(kid_link, "field")); jsonObjectSetIndex( - cur->item, + cur, (unsigned long)atoi( osrfHashGet( field, "array_position" ) ), jsonObjectClone( kids ) ); @@ -2536,7 +2536,7 @@ jsonObject* doFieldmapperSearch ( osrfMethodContext* ctx, osrfHash* meta, jsonOb jsonObjectFree( fake_params ); osrfLogDebug(OSRF_LOG_MARK, "Fleshing of %s complete", osrfHashGet(kid_link, "field")); - osrfLogDebug(OSRF_LOG_MARK, "%s", jsonObjectToJSON(cur->item)); + osrfLogDebug(OSRF_LOG_MARK, "%s", jsonObjectToJSON(cur)); } } @@ -2871,7 +2871,7 @@ jsonObject* oilsMakeFieldmapperFromResult( dbi_result result, osrfHash* meta) { jsonObjectSetIndex( object, fmIndex, - jsonNewObject( dbi_result_get_string(result, columnName) ) + jsonNewObject( (char*) dbi_result_get_string(result, columnName) ) ); break; @@ -2952,7 +2952,7 @@ jsonObject* oilsMakeJSONFromResult( dbi_result result ) { break; case DBI_TYPE_STRING : - jsonObjectSetKey( object, columnName, jsonNewObject(dbi_result_get_string(result, columnName)) ); + jsonObjectSetKey( object, columnName, jsonNewObject( (char*)dbi_result_get_string(result, columnName)) ); break; case DBI_TYPE_DATETIME : diff --git a/Open-ILS/src/c-apps/oils_event.c b/Open-ILS/src/c-apps/oils_event.c index 3b086cead2..a890693bd4 100644 --- a/Open-ILS/src/c-apps/oils_event.c +++ b/Open-ILS/src/c-apps/oils_event.c @@ -122,7 +122,7 @@ void _oilsEventParseEvents() { xmlChar* code = xmlGetProp( child, BAD_CAST "code"); xmlChar* textcode = xmlGetProp( child, BAD_CAST "textcode"); if( code && textcode ) { - osrfHashSet( __oilsEventEvents, code, textcode ); + osrfHashSet( __oilsEventEvents, code, (char*)textcode ); success = 1; } @@ -136,15 +136,15 @@ void _oilsEventParseEvents() { if(lang) { osrfLogDebug(OSRF_LOG_MARK, "Loaded event lang: %s", (char*) lang); osrfHash* langHash = osrfHashGet( - __oilsEventDescriptions, lang); + __oilsEventDescriptions, (char*)lang); if(!langHash) { langHash = osrfNewHash(); - osrfHashSet(__oilsEventDescriptions, langHash, lang); + osrfHashSet(__oilsEventDescriptions, langHash, (char*)lang); } char* content; - if( desc->children && (content = desc->children->content) ) { + if( desc->children && (content = (char*)desc->children->content) ) { osrfLogDebug(OSRF_LOG_MARK, "Loaded event desc: %s", (char*) content); - osrfHashSet( langHash, content, code ); + osrfHashSet( langHash, content, (char*)code ); } } } diff --git a/Open-ILS/src/c-apps/oils_event.h b/Open-ILS/src/c-apps/oils_event.h index 64af3070a1..35c6da9911 100644 --- a/Open-ILS/src/c-apps/oils_event.h +++ b/Open-ILS/src/c-apps/oils_event.h @@ -1,6 +1,6 @@ #ifndef OILS_EVENT_HEADER #define OILS_EVENT_HEADER -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/utils.h" #include "opensrf/log.h" #include "opensrf/osrf_hash.h" diff --git a/Open-ILS/src/c-apps/oils_fetch.c b/Open-ILS/src/c-apps/oils_fetch.c index 34ce92f045..b629d33621 100644 --- a/Open-ILS/src/c-apps/oils_fetch.c +++ b/Open-ILS/src/c-apps/oils_fetch.c @@ -1,7 +1,7 @@ #include "opensrf/osrf_app_session.h" #include "opensrf/osrf_application.h" #include "opensrf/osrf_settings.h" -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/log.h" #include "oils_utils.h" #include "oils_constants.h" diff --git a/Open-ILS/src/c-apps/oils_idl-core.c b/Open-ILS/src/c-apps/oils_idl-core.c index 906c47e3a9..18923b3075 100644 --- a/Open-ILS/src/c-apps/oils_idl-core.c +++ b/Open-ILS/src/c-apps/oils_idl-core.c @@ -44,13 +44,13 @@ osrfHash* oilsIDLInit( char* idl_filename ) { if (!strcmp( (char*)kid->name, "class" )) { usrData = osrfNewHash(); - osrfHashSet( usrData, xmlGetProp(kid, "id"), "classname"); - osrfHashSet( usrData, xmlGetNsProp(kid, "fieldmapper", OBJECT_NS), "fieldmapper"); + osrfHashSet( usrData, xmlGetProp(kid, BAD_CAST "id"), "classname"); + osrfHashSet( usrData, xmlGetNsProp(kid, BAD_CAST "fieldmapper", BAD_CAST OBJECT_NS), "fieldmapper"); osrfHashSet( idlHash, usrData, (char*)osrfHashGet(usrData, "classname") ); string_tmp = NULL; - if ((string_tmp = (char*)xmlGetNsProp(kid, "tablename", PERSIST_NS))) { + if ((string_tmp = (char*)xmlGetNsProp(kid, BAD_CAST "tablename", BAD_CAST PERSIST_NS))) { osrfHashSet( usrData, strdup( string_tmp ), @@ -59,7 +59,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { } string_tmp = NULL; - if ((string_tmp = (char*)xmlGetNsProp(kid, "virtual", PERSIST_NS))) { + if ((string_tmp = (char*)xmlGetNsProp(kid, BAD_CAST "virtual", BAD_CAST PERSIST_NS))) { osrfHashSet( usrData, strdup( string_tmp ), @@ -69,7 +69,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { osrfStringArray* controller = osrfNewStringArray(0); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(kid, "controller") )) { + if( (string_tmp = (char*)xmlGetProp(kid, BAD_CAST "controller") )) { char* controller_list = strdup( string_tmp ); osrfLogInfo(OSRF_LOG_MARK, "Controller list is %s", string_tmp ); @@ -100,7 +100,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { if (!strcmp( (char*)_cur->name, "fields" )) { string_tmp = NULL; - if( (string_tmp = (char*)xmlGetNsProp(_cur, "primary", PERSIST_NS)) ) { + if( (string_tmp = (char*)xmlGetNsProp(_cur, BAD_CAST "primary", BAD_CAST PERSIST_NS)) ) { osrfHashSet( usrData, strdup( string_tmp ), @@ -109,7 +109,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { } string_tmp = NULL; - if( (string_tmp = (char*)xmlGetNsProp(_cur, "sequence", PERSIST_NS)) ) { + if( (string_tmp = (char*)xmlGetNsProp(_cur, BAD_CAST "sequence", BAD_CAST PERSIST_NS)) ) { osrfHashSet( usrData, strdup( string_tmp ), @@ -128,7 +128,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { _tmp = osrfNewHash(); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetNsProp(_f, "array_position", OBJECT_NS)) ) { + if( (string_tmp = (char*)xmlGetNsProp(_f, BAD_CAST "array_position", BAD_CAST OBJECT_NS)) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -137,7 +137,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { } string_tmp = NULL; - if( (string_tmp = (char*)xmlGetNsProp(_f, "virtual", PERSIST_NS)) ) { + if( (string_tmp = (char*)xmlGetNsProp(_f, BAD_CAST "virtual", BAD_CAST PERSIST_NS)) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -146,7 +146,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { } string_tmp = NULL; - if( (string_tmp = (char*)xmlGetNsProp(_f, "primitive", PERSIST_NS)) ) { + if( (string_tmp = (char*)xmlGetNsProp(_f, BAD_CAST "primitive", BAD_CAST PERSIST_NS)) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -155,7 +155,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { } string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(_f, "name")) ) { + if( (string_tmp = (char*)xmlGetProp(_f, BAD_CAST "name")) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -186,7 +186,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { _tmp = osrfNewHash(); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(_l, "reltype")) ) { + if( (string_tmp = (char*)xmlGetProp(_l, BAD_CAST "reltype")) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -196,7 +196,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { osrfLogInfo(OSRF_LOG_MARK, "Adding link with reltype %s", string_tmp ); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(_l, "key")) ) { + if( (string_tmp = (char*)xmlGetProp(_l, BAD_CAST "key")) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -206,7 +206,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { osrfLogInfo(OSRF_LOG_MARK, "Link fkey is %s", string_tmp ); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(_l, "class")) ) { + if( (string_tmp = (char*)xmlGetProp(_l, BAD_CAST "class")) ) { osrfHashSet( _tmp, strdup( string_tmp ), @@ -218,7 +218,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { osrfStringArray* map = osrfNewStringArray(0); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(_l, "map") )) { + if( (string_tmp = (char*)xmlGetProp(_l, BAD_CAST "map") )) { char* map_list = strdup( string_tmp ); osrfLogInfo(OSRF_LOG_MARK, "Link mapping list is %s", string_tmp ); @@ -235,7 +235,7 @@ osrfHash* oilsIDLInit( char* idl_filename ) { osrfHashSet( _tmp, map, "map"); string_tmp = NULL; - if( (string_tmp = (char*)xmlGetProp(_l, "field")) ) { + if( (string_tmp = (char*)xmlGetProp(_l, BAD_CAST "field")) ) { osrfHashSet( _tmp, strdup( string_tmp ), diff --git a/Open-ILS/src/c-apps/oils_utils.h b/Open-ILS/src/c-apps/oils_utils.h index 3e134d5d24..290a21cf59 100644 --- a/Open-ILS/src/c-apps/oils_utils.h +++ b/Open-ILS/src/c-apps/oils_utils.h @@ -1,4 +1,4 @@ -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/log.h" // XXX replacing this with liboils_idl implementation diff --git a/Open-ILS/src/extras/Makefile b/Open-ILS/src/extras/Makefile index aa4d3c791c..5f5a6877b1 100644 --- a/Open-ILS/src/extras/Makefile +++ b/Open-ILS/src/extras/Makefile @@ -1,4 +1,4 @@ -LDLIBS += -lreadline -loils_utils -lopensrf -lobjson -lxml2 -loils_idl +LDLIBS += -lreadline -loils_utils -lopensrf -lxml2 -loils_idl all: oils_requestor oils_requestor: oils_requestor.o diff --git a/Open-ILS/src/python/oils/const.py b/Open-ILS/src/python/oils/const.py index 52ee81f67f..f9d818894d 100644 --- a/Open-ILS/src/python/oils/const.py +++ b/Open-ILS/src/python/oils/const.py @@ -19,4 +19,5 @@ OILS_NS_PERSIST='http://open-ils.org/spec/opensrf/IDL/persistance/v1' OILS_NS_REPORTER='http://open-ils.org/spec/opensrf/IDL/reporter/v1' OILS_APP_CSTORE='open-ils.cstore' +OILS_APP_AUTH='open-ils.auth' diff --git a/Open-ILS/src/python/oils/utils/csedit.py b/Open-ILS/src/python/oils/utils/csedit.py index 8054196243..457a582444 100644 --- a/Open-ILS/src/python/oils/utils/csedit.py +++ b/Open-ILS/src/python/oils/utils/csedit.py @@ -17,13 +17,14 @@ from osrf.log import * from osrf.json import * from oils.utils.utils import replace from oils.utils.idl import oilsGetIDLParser -from osrf.ses import osrfClientSession +from osrf.ses import osrfClientSession, osrfAtomicRequest from oils.const import * import re ACTIONS = ['create', 'retrieve', 'update', 'delete', 'search'] class CSEditor(object): + def __init__(self, **args): self.app = args.get('app', OILS_APP_CSTORE) @@ -31,12 +32,27 @@ class CSEditor(object): self.requestor = args.get('requestor') self.connect = args.get('connect') self.xact = args.get('xact') + self.substream = False; self.__session = None + # ------------------------------------------------------------------------- + # rolls back the existing transaction and returns the last event + # ------------------------------------------------------------------------- def die_event(self): - pass + self.rollback() + return self.event + + # ------------------------------------------------------------------------- + # Verifies the session is valid sets the 'requestor' to the user retrieved + # by the session lookup + # ------------------------------------------------------------------------- def checkauth(self): - pass + usr = osrfAtomicRequest( OILS_APP_AUTH, 'open-ils.auth.session.retrieve', self.authtoken ) + if oilsIsEvent(usr): + self.event = usr + return False + self.requestor = usr + return True # ------------------------------------------------------------------------- @@ -59,7 +75,7 @@ class CSEditor(object): # ------------------------------------------------------------------------- - # Logs string with some meta info + # Logs the given string with some meta info # ------------------------------------------------------------------------- def log(self, func, string): s = "editor["; @@ -104,19 +120,27 @@ class CSEditor(object): # ------------------------------------------------------------------------- def request(self, method, params=[]): - # XXX improve param logging here - - self.log(osrfLogInfo, "request %s %s" % (method, str(params))) - if self.xact and self.session().state != OSRF_APP_SESSION_CONNECTED: self.log(osrfLogErr, "csedit lost it's connection!") - val = None + self.log(osrfLogInfo, "request %s %s" % (method, self.__args_to_str(params))) + val = None try: - req = self.session().request2(method, params) - resp = req.recv() - val = resp.content() + req = self.session().request2(method, params) + + # ------------------------------------------------------------------------- + # substream requests gather the requests as they come in + # ------------------------------------------------------------------------- + if self.substream: + val = [] + while True: + resp = req.recv() + if not resp: + break + val.append(resp.content()) + else: + val = req.recv().content() except Exception, e: self.log(osrfLogErr, "request error: %s" % str(e)) @@ -126,6 +150,22 @@ class CSEditor(object): # ------------------------------------------------------------------------- + # turns an array of parms into a readable argument string for logging + # ------------------------------------------------------------------------- + def __args_to_str(self, arg): + s = '' + for i in range(len(arg)): + obj = arg[i] + if i > 0: s += ', ' + if isinstance(obj, osrfNetworkObject): + if obj.id() != None: + s += str(obj.id()) + else: s += '' % obj.__class__.__name__ + else: s += osrfObjectToJSON(obj) + return s + + + # ------------------------------------------------------------------------- # Returns true if our requestor is allowed to perform the request action # 'org' defaults to the requestors ws_ou # ------------------------------------------------------------------------- @@ -135,14 +175,28 @@ class CSEditor(object): def runMethod(self, action, type, arg, options={}): + # make sure we're in a transaction if performing any writes + if action in ['create', 'update', 'delete'] and not self.xact: + raise oilsCSEditException('attempt to update DB outside of a transaction') + + # clear the previous event + self.event = None + + # construct the method name method = "%s.direct.%s.%s" % (self.app, type, action) + # do we only want a list of IDs? if options.get('idlist'): method = replace(method, 'search', 'id_list') del options['idlist'] - + + # are we streaming or atomic? if action == 'search': - method = replace(method, '$', '.atomic') + if options.get('substream'): + self.substream = True + del options['substream'] + else: + method = replace(method, '$', '.atomic') params = [arg]; if len(options.keys()): diff --git a/Open-ILS/src/python/oils/utils/utils.py b/Open-ILS/src/python/oils/utils/utils.py index 9e03cb91ba..ddd4679da9 100644 --- a/Open-ILS/src/python/oils/utils/utils.py +++ b/Open-ILS/src/python/oils/utils/utils.py @@ -27,6 +27,16 @@ def replace(str, pattern, replace): return re.compile(pattern).sub(replace, str) +def oilsIsEvent(evt): + try: + if evt['ilsevent']: return True + except: return False + +def oilsEventCode(evt): + if oilsIsEvent(evt): + return evt['ilsevent'] + return -1 + diff --git a/Open-ILS/src/support-scripts/test-scripts/simple.pl b/Open-ILS/src/support-scripts/test-scripts/simple.pl index 108445de86..953ada5150 100755 --- a/Open-ILS/src/support-scripts/test-scripts/simple.pl +++ b/Open-ILS/src/support-scripts/test-scripts/simple.pl @@ -7,12 +7,38 @@ require '../oils_header.pl'; use vars qw/ $apputils $memcache $user $authtoken $authtime /; use strict; use warnings; +use JSON; +use Time::HiRes qw/time/; +use OpenILS::Utils::Fieldmapper; my $config = $ARGV[0]; err( "usage: $0 " ) unless $config; osrf_connect($config); -my( $user, $evt ) = simplereq( STORAGE(), 'open-ils.storage.direct.actor.user.retrieve', 1 ); -oils_event_die($evt); # this user was not found / not all methods return events.. -print debug($user); +my $p = Fieldmapper::actor::user->new; +my $sr = Fieldmapper::action::survey_response->new; +$sr->answer_date('now'); +$p->survey_responses( [ $sr ] ); +my $c = $p->clone; +$p->clear_survey_responses; +debug($p); +debug($c); + + +exit; + + +my $s = time; +my( $user, $evt ); +my $str = ''; +#for(0..100) { +for(0..0) { + ( $user, $evt ) = simplereq( STORAGE(), 'open-ils.storage.direct.actor.user.retrieve', 1 ); + oils_event_die($evt); # this user was not found / not all methods return events.. + $str .= JSON->perl2JSON($user); +} +print "\ntime: " . (time - $s) . "\n"; +print length($str) . "\n"; + + diff --git a/Open-ILS/web/opac/common/js/RemoteRequest.js b/Open-ILS/web/opac/common/js/RemoteRequest.js index 53af228d9d..0e045b2f59 100644 --- a/Open-ILS/web/opac/common/js/RemoteRequest.js +++ b/Open-ILS/web/opac/common/js/RemoteRequest.js @@ -1,9 +1,11 @@ -var XML_HTTP_GATEWAY = "gateway"; +//var XML_HTTP_GATEWAY = "gateway2"; +var XML_HTTP_GATEWAY; var XML_HTTP_SERVER = ""; var XML_HTTP_MAX_TRIES = 3; + /* This object is thrown when network failures occur */ function NetworkFailure(stat, url) { this._status = stat; @@ -21,6 +23,11 @@ NetworkFailure.prototype.toString = function() { //var IAMXUL = false; function isXUL() { try { if(IAMXUL) return true;}catch(e){return false;}; } + +if(isXUL()) + XML_HTTP_GATEWAY = "gateway"; +else XML_HTTP_GATEWAY = "gateway2"; + /* some communication exceptions */ function EX(message) { this.init(message); } EX.prototype.init = function(message) { this.message = message; } diff --git a/Open-ILS/web/opac/skin/default/xml/common/js_common.xml b/Open-ILS/web/opac/skin/default/xml/common/js_common.xml index fe8eb1b6b8..f90983eb20 100644 --- a/Open-ILS/web/opac/skin/default/xml/common/js_common.xml +++ b/Open-ILS/web/opac/skin/default/xml/common/js_common.xml @@ -1,7 +1,5 @@
- - /slimtree.js'> - + diff --git a/OpenSRF/src/Makefile b/OpenSRF/src/Makefile index 008679e163..0ad9171caa 100644 --- a/OpenSRF/src/Makefile +++ b/OpenSRF/src/Makefile @@ -32,6 +32,10 @@ OPENSRF_TARGETS = libtransport/transport_session.o \ libstack/osrf_transgroup.o \ libstack/osrf_list.o \ libstack/osrf_hash.o \ + libstack/osrf_json_parser.o \ + libstack/osrf_json_object.o \ + libstack/osrf_json_tools.o \ + libstack/legacy_json.o \ utils/socket_bundle.o \ utils/string_array.o \ utils/utils.o \ @@ -55,6 +59,7 @@ OPENSRF_HEADERS = libtransport/transport_session.h \ libstack/osrf_transgroup.h \ libstack/osrf_list.h \ libstack/osrf_hash.h \ + libstack/osrf_json.h \ utils/socket_bundle.h \ utils/string_array.h \ utils/utils.h \ @@ -67,22 +72,19 @@ all: prep \ libstack/opensrf \ router \ srfsh \ - jserver \ gateway -install: install-prep \ +install: install-prep \ opensrf-install \ gateway-install \ router-install \ srfsh-install \ - jserver-install \ - perl-install \ - objson-install + perl-install prep: mkdir -p $(TMPDIR) -libopensrf.so: objson/libobjson.so +libopensrf.so: @echo utils make -C utils @echo transport @@ -90,30 +92,19 @@ libopensrf.so: objson/libobjson.so @echo stack make -C libstack @echo $@ - $(CC) -shared -W1 $(LDFLAGS) -lxml2 -lmemcache -lobjson $(OPENSRF_TARGETS) -o $(TMPDIR)/$(LIBOPENSRF) + $(CC) -shared -W1 $(LDFLAGS) -lxml2 -lmemcache $(OPENSRF_TARGETS) -o $(TMPDIR)/$(LIBOPENSRF) @echo apps make -C c-apps -opensrf-install: objson-install - @echo $@ - cp $(TMPDIR)/$(LIBOPENSRF) $(LIBDIR)/$(LIBOPENSRF) - cp $(OPENSRF_HEADERS) $(INCLUDEDIR)/opensrf/ - cp libstack/opensrf $(BINDIR)/opensrf-c - make -C c-apps install - - -objson/libobjson.so: prep - @echo $@ - make -C objson - +# # -------------------------------------------------------------------------------- # BINARIES # -------------------------------------------------------------------------------- libstack/opensrf.o: libstack/opensrf.c libopensrf.so libstack/opensrf: libstack/opensrf.o @echo $@ - $(CC) $(CFLAGS) $(LDFLAGS) -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) -lxml2 -lopensrf libstack/opensrf.o -o $@ router: libopensrf.so @@ -146,14 +137,17 @@ install-prep: mkdir -p $(ETCDIR) mkdir -p $(TEMPLATEDIR) -objson-install: install-prep - @echo $@ - make -C objson install - libopensrf-install: install-prep @echo $@ cp $(TMPDIR)/$(LIBOPENSRF) $(LIBDIR) +opensrf-install: + @echo $@ + cp $(TMPDIR)/$(LIBOPENSRF) $(LIBDIR)/$(LIBOPENSRF) + cp $(OPENSRF_HEADERS) $(INCLUDEDIR)/opensrf/ + cp libstack/opensrf $(BINDIR)/opensrf-c + make -C c-apps install + gateway-install: install-prep opensrf-install @echo $@ make -C gateway install @@ -191,7 +185,6 @@ clean: make -C gateway clean make -C jserver clean make -C utils clean - make -C objson clean make -C srfsh clean make -C c-apps clean echo "Removing directory [$(TMPDIR)]" diff --git a/OpenSRF/src/c-apps/Makefile b/OpenSRF/src/c-apps/Makefile index ceda7920ee..14b884ef70 100644 --- a/OpenSRF/src/c-apps/Makefile +++ b/OpenSRF/src/c-apps/Makefile @@ -1,4 +1,4 @@ -LDLIBS += -lobjson -lopensrf +LDLIBS += -lopensrf CFLAGS += -DOSRF_LOG_PARAMS all: osrf_math.so osrf_dbmath.so osrf_version.so diff --git a/OpenSRF/src/c-apps/osrf_dbmath.c b/OpenSRF/src/c-apps/osrf_dbmath.c index 0b930cd54f..ace60a1abb 100644 --- a/OpenSRF/src/c-apps/osrf_dbmath.c +++ b/OpenSRF/src/c-apps/osrf_dbmath.c @@ -1,6 +1,6 @@ #include "opensrf/osrf_app_session.h" #include "opensrf/osrf_application.h" -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/log.h" #define MODULENAME "opensrf.dbmath" diff --git a/OpenSRF/src/c-apps/osrf_math.c b/OpenSRF/src/c-apps/osrf_math.c index 63d168ac11..05d9a1f9eb 100644 --- a/OpenSRF/src/c-apps/osrf_math.c +++ b/OpenSRF/src/c-apps/osrf_math.c @@ -1,6 +1,6 @@ #include "opensrf/osrf_app_session.h" #include "opensrf/osrf_application.h" -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/log.h" #define MODULENAME "opensrf.math" diff --git a/OpenSRF/src/c-apps/osrf_version.c b/OpenSRF/src/c-apps/osrf_version.c index 1affb70914..9d07874222 100644 --- a/OpenSRF/src/c-apps/osrf_version.c +++ b/OpenSRF/src/c-apps/osrf_version.c @@ -1,6 +1,6 @@ #include "opensrf/osrf_app_session.h" #include "opensrf/osrf_application.h" -#include "objson/object.h" +#include "opensrf/osrf_json.h" #include "opensrf/utils.h" #include "opensrf/log.h" diff --git a/OpenSRF/src/gateway/Makefile b/OpenSRF/src/gateway/Makefile index 2120b239cb..8da80b1252 100644 --- a/OpenSRF/src/gateway/Makefile +++ b/OpenSRF/src/gateway/Makefile @@ -1,6 +1,6 @@ #CFLAGS += -DASSUME_STATELESS -DOSRF_GATEWAY_NASTY_DEBUG CFLAGS += -DASSUME_STATELESS -LDLIBS += -lobjson -lopensrf +LDLIBS += -lopensrf all: osrf_json_gateway.so copy diff --git a/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl b/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl index 8f28c91558..5d5555b896 100755 --- a/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl +++ b/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl @@ -42,8 +42,7 @@ print SOURCE < #include -#include "objson/object.h" -#include "objson/json_parser.h" +#include "opensrf/osrf_json.h" #include "opensrf/utils.h" char* json_string_to_xml(char*); diff --git a/OpenSRF/src/gateway/osrf_json_gateway.c b/OpenSRF/src/gateway/osrf_json_gateway.c index a575bd9769..27ce45414a 100644 --- a/OpenSRF/src/gateway/osrf_json_gateway.c +++ b/OpenSRF/src/gateway/osrf_json_gateway.c @@ -2,8 +2,8 @@ #include "opensrf/osrf_app_session.h" #include "opensrf/osrf_system.h" #include "opensrf/osrfConfig.h" -#include "objson/object.h" -#include "objson/json2xml.h" +#include "opensrf/osrf_json.h" +#include "../libstack/legacy_json.h" #include #include #include @@ -11,9 +11,11 @@ #define MODULE_NAME "osrf_json_gateway_module" #define GATEWAY_CONFIG "OSRFGatewayConfig" +#define JSON_PROTOCOL "OSRFGatewayJSONProtocol" #define CONFIG_CONTEXT "gateway" #define GATEWAY_DEFAULT_CONFIG "/openils/conf/opensrf_core.xml" +#define GATEWAY_DEFAULT_PROTOCOL "wrapper" // other option is "classy" /* our config structure */ @@ -21,6 +23,11 @@ typedef struct { char* configfile; /* our bootstrap config file */ } osrf_json_gateway_config; + +typedef struct { + char* JSONProtocol; +} osrf_json_gateway_dir_config; + module AP_MODULE_DECLARE_DATA osrf_json_gateway_module; char* osrf_json_gateway_config_file = NULL; @@ -36,10 +43,18 @@ static const char* osrf_json_gateway_set_config(cmd_parms *parms, void *config, return NULL; } +static const char* osrf_json_gateway_set_json_proto(cmd_parms *parms, void *config, const char *arg) { + osrf_json_gateway_dir_config* cfg = (osrf_json_gateway_dir_config*) config; + cfg->JSONProtocol = (char*) arg; + return NULL; +} + /* tell apache about our commands */ static const command_rec osrf_json_gateway_cmds[] = { AP_INIT_TAKE1( GATEWAY_CONFIG, osrf_json_gateway_set_config, NULL, RSRC_CONF, "osrf json gateway config file"), + AP_INIT_TAKE1( JSON_PROTOCOL, osrf_json_gateway_set_json_proto, + NULL, ACCESS_CONF, "osrf json gateway config file"), {NULL} }; @@ -51,6 +66,13 @@ static void* osrf_json_gateway_create_config( apr_pool_t* p, server_rec* s) { return (void*) cfg; } +static void* osrf_json_gateway_create_dir_config( apr_pool_t* p, char* dir) { + osrf_json_gateway_dir_config* cfg = (osrf_json_gateway_dir_config*) + apr_palloc(p, sizeof(osrf_json_gateway_dir_config)); + cfg->JSONProtocol = GATEWAY_DEFAULT_PROTOCOL; + return (void*) cfg; +} + static void osrf_json_gateway_child_init(apr_pool_t *p, server_rec *s) { @@ -83,6 +105,25 @@ static int osrf_json_gateway_method_handler (request_rec *r) { /* make sure we're needed first thing*/ if (strcmp(r->handler, MODULE_NAME )) return DECLINED; + /* XXX */ + osrf_json_gateway_dir_config* dir_conf = + ap_get_module_config(r->per_dir_config, &osrf_json_gateway_module); + + ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "JSON protocol = %s", dir_conf->JSONProtocol); + + /* provide 2 different JSON parsers and serializers to support legacy JSON */ + jsonObject* (*parseJSONFunc) (char*) = legacy_jsonParseString; + char* (*jsonToStringFunc) (const jsonObject*) = legacy_jsonObjectToJSON; + + if(dir_conf->JSONProtocol && !strcmp(dir_conf->JSONProtocol,"wrapper") ) { + /* if protocol is wrapper, use the new wrapper JSON code */ + ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Using wrapper JSON"); + parseJSONFunc = jsonParseString; + jsonToStringFunc = jsonObjectToJSON; + } + /* XXX */ + + osrfLogDebug(OSRF_LOG_MARK, "osrf gateway: entered request handler"); /* verify we are connected */ @@ -179,7 +220,7 @@ static int osrf_json_gateway_method_handler (request_rec *r) { char* str; int i = 0; while( (str = osrfStringArrayGetString(mparams, i++)) ) { if( i == 1 ) { - OSRF_BUFFER_ADD(act, " "); + OSRF_BUFFER_ADD(act, " "); OSRF_BUFFER_ADD(act, str); } else { OSRF_BUFFER_ADD(act, ", "); @@ -217,7 +258,8 @@ static int osrf_json_gateway_method_handler (request_rec *r) { if (isXML) { output = jsonObjectToXML( res ); } else { - output = jsonObjectToJSON( res ); + //output = jsonObjectToJSON( res ); + output = jsonToStringFunc( res ); if( morethan1 ) ap_rputs(",", r); /* comma between JSON array items */ } ap_rputs(output, r); @@ -263,7 +305,8 @@ static int osrf_json_gateway_method_handler (request_rec *r) { bzero(bb, l); snprintf(bb, l, "%s : %s", statusname, statustext); jsonObject* tmp = jsonNewObject(bb); - char* j = jsonObjectToJSON(tmp); + //char* j = jsonObjectToJSON(tmp); + char* j = jsonToStringFunc(tmp); snprintf( buf, l, ",\"debug\": %s", j); free(j); jsonObjectFree(tmp); @@ -314,7 +357,8 @@ static void osrf_json_gateway_register_hooks (apr_pool_t *p) { module AP_MODULE_DECLARE_DATA osrf_json_gateway_module = { STANDARD20_MODULE_STUFF, - NULL, + osrf_json_gateway_create_dir_config, + /*NULL,*/ NULL, osrf_json_gateway_create_config, NULL, diff --git a/OpenSRF/src/jserver/Makefile b/OpenSRF/src/jserver/Makefile index e21cfe1f53..28a614777d 100644 --- a/OpenSRF/src/jserver/Makefile +++ b/OpenSRF/src/jserver/Makefile @@ -1,4 +1,4 @@ -LDLIBS += -lopensrf -lobjson -lxml2 +LDLIBS += -lopensrf -lxml2 CFLAGS += -D_GNU_SOURCE all: chopchop diff --git a/OpenSRF/src/libstack/Makefile b/OpenSRF/src/libstack/Makefile index 82fae9a345..3dc5dd252f 100644 --- a/OpenSRF/src/libstack/Makefile +++ b/OpenSRF/src/libstack/Makefile @@ -2,8 +2,8 @@ # OSRF_STRICT_PARAMS instructs the app handler to return an error if the number of method arguments # provided to any method is not at least as large as the 'argc' setting for the method -CFLAGS += -DASSUME_STATELESS -DOSRF_LOG_PARAMS -DOSRF_STRICT_PARAMS -rdynamic -fno-strict-aliasing -LDLIBS += -lxml2 -lobjson -ldl -lmemcache +CFLAGS += -DASSUME_STATELESS -DOSRF_LOG_PARAMS -DOSRF_STRICT_PARAMS -rdynamic -fno-strict-aliasing -I. +LDLIBS += -lxml2 -ldl -lmemcache TARGETS = osrf_message.o \ osrf_app_session.o \ @@ -17,7 +17,13 @@ TARGETS = osrf_message.o \ osrf_transgroup.o \ osrf_list.o \ osrf_hash.o \ - xml_utils.o + xml_utils.o \ + osrf_hash.o \ + osrf_json_object.o \ + osrf_json_parser.o \ + osrf_json_tools.o \ + legacy_json.o \ + xml_utils.o HEADERS = osrf_message.h \ osrf_app_session.h \ @@ -31,6 +37,7 @@ HEADERS = osrf_message.h \ osrf_transgroup.h \ osrf_list.h \ osrf_hash.h \ + osrf_json.h \ xml_utils.h all: xml_utils.o $(TARGETS) copy @@ -53,10 +60,11 @@ osrfConfig.o: osrfConfig.c osrfConfig.h xml_utils.o osrf_application.o: osrf_application.c osrf_application.h osrf_cache.o: osrf_cache.c osrf_cache.h osrf_list.o: osrf_list.c osrf_list.h -#osrf_big_list.o: osrf_big_list.c osrf_big_list.h osrf_hash.o: osrf_hash.c osrf_hash.h -#osrf_big_hash.o: osrf_big_hash.c osrf_big_hash.h - +osrf_json_object.o: osrf_json_object.c osrf_json.h osrf_json_utils.h +osrf_json_parser.o: osrf_json_parser.c osrf_json.h osrf_json_utils.h +osrf_json_tools.o: osrf_json_tools.c osrf_json.h osrf_json_utils.h +legacy_json.o: legacy_json.c osrf_json.h osrf_json_utils.h clean: /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c opensrf diff --git a/OpenSRF/src/libstack/osrfConfig.c b/OpenSRF/src/libstack/osrfConfig.c index a172a2b224..c195a19348 100644 --- a/OpenSRF/src/libstack/osrfConfig.c +++ b/OpenSRF/src/libstack/osrfConfig.c @@ -50,6 +50,13 @@ osrfConfig* osrfConfigInit(char* configFile, char* configContext) { } cfg->config = xmlDocToJSON(doc); + + /* + char* j = jsonObjectToJSON(cfg->config); + fprintf(stderr, "JSON:\n%s\n", j); + free(j); + */ + xmlFreeDoc(doc); if(!cfg->config) { diff --git a/OpenSRF/src/libstack/osrfConfig.h b/OpenSRF/src/libstack/osrfConfig.h index c0a6459b42..ff1cbbdad9 100644 --- a/OpenSRF/src/libstack/osrfConfig.h +++ b/OpenSRF/src/libstack/osrfConfig.h @@ -19,7 +19,7 @@ GNU General Public License for more details. #include "xml_utils.h" #include "opensrf/utils.h" #include "opensrf/string_array.h" -#include "objson/object.h" +#include "osrf_json.h" typedef struct { jsonObject* config; @@ -45,11 +45,11 @@ osrfConfig* osrfConfigInit(char* configFile, char* configContext); int osrfConfigHasDefaultConfig(); /** - Replaces the config object's objson object. This is useful + Replaces the config object's json object. This is useful if you have an ojbson object already and not an XML config file to parse. @param cfg The config object to alter - @param obj The objson objet to use when searching values + @param obj The json objet to use when searching values */ void osrfConfigReplaceConfig(osrfConfig* cfg, const jsonObject* obj); diff --git a/OpenSRF/src/libstack/osrf_app_session.h b/OpenSRF/src/libstack/osrf_app_session.h index af35af5e72..733cb28c96 100644 --- a/OpenSRF/src/libstack/osrf_app_session.h +++ b/OpenSRF/src/libstack/osrf_app_session.h @@ -2,7 +2,7 @@ #define _OSRF_APP_SESSION #include "opensrf/transport_client.h" -#include "objson/object.h" +#include "osrf_json.h" #include "osrf_message.h" #include "osrf_system.h" #include "opensrf/string_array.h" @@ -10,9 +10,6 @@ #include "osrf_hash.h" #include "osrf_list.h" -#include "objson/object.h" -#include "objson/json_parser.h" - #define DEF_RECV_TIMEOUT 6 /* receive timeout */ diff --git a/OpenSRF/src/libstack/osrf_application.c b/OpenSRF/src/libstack/osrf_application.c index 1d62642ef9..411078319d 100644 --- a/OpenSRF/src/libstack/osrf_application.c +++ b/OpenSRF/src/libstack/osrf_application.c @@ -1,11 +1,7 @@ #include "osrf_application.h" -#include "objson/object.h" - -//osrfApplication* __osrfAppList = NULL; osrfHash* __osrfAppHash = NULL; - int osrfAppRegisterApplication( char* appName, char* soFile ) { if(!appName || ! soFile) return -1; char* error; diff --git a/OpenSRF/src/libstack/osrf_application.h b/OpenSRF/src/libstack/osrf_application.h index 0980a81606..de6a16731e 100644 --- a/OpenSRF/src/libstack/osrf_application.h +++ b/OpenSRF/src/libstack/osrf_application.h @@ -2,7 +2,7 @@ #include #include "opensrf/utils.h" #include "opensrf/log.h" -#include "objson/object.h" +#include "osrf_json.h" #include "osrf_app_session.h" #include "osrf_hash.h" diff --git a/OpenSRF/src/libstack/osrf_cache.h b/OpenSRF/src/libstack/osrf_cache.h index 317cdd0451..d110b47f41 100644 --- a/OpenSRF/src/libstack/osrf_cache.h +++ b/OpenSRF/src/libstack/osrf_cache.h @@ -14,8 +14,7 @@ GNU General Public License for more details. */ -#include "objson/object.h" -#include "objson/json_parser.h" +#include "osrf_json.h" #include "memcache.h" #include "log.h" diff --git a/OpenSRF/src/libstack/osrf_message.c b/OpenSRF/src/libstack/osrf_message.c index beb52d0299..c650139256 100644 --- a/OpenSRF/src/libstack/osrf_message.c +++ b/OpenSRF/src/libstack/osrf_message.c @@ -119,8 +119,10 @@ char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count ) { while( ((msg = msgs[i]) && (i++ < count)) ) jsonObjectPush(wrapper, osrfMessageToJSON( msg )); + //jsonObject* enc = jsonObjectEncodeClass(wrapper); j = jsonObjectToJSON(wrapper); jsonObjectFree(wrapper); + //jsonObjectFree(enc); return j; } @@ -133,12 +135,14 @@ char* osrf_message_serialize(osrf_message* msg) { jsonObject* json = osrfMessageToJSON( msg ); - if(json) { - jsonObject* wrapper = jsonNewObject(NULL); - jsonObjectPush(wrapper, json); - j = jsonObjectToJSON(wrapper); - jsonObjectFree(wrapper); - } + if(!json) return NULL; + + jsonObject* wrapper = jsonNewObject(NULL); + jsonObjectPush(wrapper, json); + //jsonObject* enc = jsonObjectEncodeClass(wrapper); + j = jsonObjectToJSON(wrapper); + jsonObjectFree(wrapper); + //jsonObjectFree(enc); return j; } @@ -211,7 +215,11 @@ int osrf_message_deserialize(char* string, osrf_message* msgs[], int count) { if(!string || !msgs || count <= 0) return 0; int numparsed = 0; + /** XXX **/ jsonObject* json = jsonParseString(string); + //jsonObject* json2 = jsonObjectDecodeClass(json); + //jsonObjectFree(json); + //json = json2; if(!json) { osrfLogWarning( OSRF_LOG_MARK, diff --git a/OpenSRF/src/libstack/osrf_message.h b/OpenSRF/src/libstack/osrf_message.h index b87a97eb04..e99a60453b 100644 --- a/OpenSRF/src/libstack/osrf_message.h +++ b/OpenSRF/src/libstack/osrf_message.h @@ -1,8 +1,7 @@ #include "opensrf/string_array.h" #include "opensrf/utils.h" #include "opensrf/log.h" -#include "objson/object.h" -#include "objson/json_parser.h" +#include "osrf_json.h" /* libxml stuff for the config reader */ diff --git a/OpenSRF/src/libstack/osrf_settings.h b/OpenSRF/src/libstack/osrf_settings.h index fecfc32453..6313490ac2 100644 --- a/OpenSRF/src/libstack/osrf_settings.h +++ b/OpenSRF/src/libstack/osrf_settings.h @@ -10,8 +10,7 @@ #include "opensrf/log.h" #include "opensrf/utils.h" -#include "objson/object.h" -#include "objson/json_parser.h" +#include "osrf_json.h" #include "osrf_app_session.h" diff --git a/OpenSRF/src/libtransport/Makefile b/OpenSRF/src/libtransport/Makefile index 643e81c54b..103ecc97be 100644 --- a/OpenSRF/src/libtransport/Makefile +++ b/OpenSRF/src/libtransport/Makefile @@ -1,6 +1,7 @@ TARGETS = transport_message.o transport_session.o transport_client.o HEADERS = transport_message.h transport_session.h transport_client.h +CFLAGS += -I ../libstack -I ../utils TARGET = libopensrf_transport.so diff --git a/OpenSRF/src/libtransport/transport_message.c b/OpenSRF/src/libtransport/transport_message.c index f0e63afbd4..44eaa98ff1 100644 --- a/OpenSRF/src/libtransport/transport_message.c +++ b/OpenSRF/src/libtransport/transport_message.c @@ -95,7 +95,7 @@ transport_message* new_message_from_xml( const char* msg_xml ) { xmlFree(router_class); } if(broadcast) { - if(strcmp(broadcast,"0") ) + if(strcmp( (char*)broadcast,"0") ) new_msg->broadcast = 1; xmlFree(broadcast); } @@ -211,9 +211,9 @@ int message_free( transport_message* msg ){ // --------------------------------------------------------------------------------- char* message_to_xml( const transport_message* msg ) { - int bufsize; + //int bufsize; //xmlChar* xmlbuf; - char* encoded_body; + //char* encoded_body; xmlNodePtr message_node; xmlNodePtr body_node; diff --git a/OpenSRF/src/libtransport/transport_session.c b/OpenSRF/src/libtransport/transport_session.c index 43bdcbc984..1db881a17e 100644 --- a/OpenSRF/src/libtransport/transport_session.c +++ b/OpenSRF/src/libtransport/transport_session.c @@ -322,13 +322,14 @@ void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int void startElementHandler( - void *session, const xmlChar *name, const xmlChar **atts) { + void *session, const xmlChar *ename, const xmlChar **atts) { transport_session* ses = (transport_session*) session; if( ! ses ) { return; } - - if( strcmp( name, "message" ) == 0 ) { + char* name = (char*) ename; + + if( strcmp( name, "message" ) == 0 ) { ses->state_machine->in_message = 1; buffer_add( ses->from_buffer, get_xml_attr( atts, "from" ) ); buffer_add( ses->recipient_buffer, get_xml_attr( atts, "to" ) ); @@ -429,7 +430,7 @@ char* get_xml_attr( const xmlChar** atts, char* attr_name ) { int i; if (atts != NULL) { for(i = 0;(atts[i] != NULL);i++) { - if( strcmp( atts[i++], attr_name ) == 0 ) { + if( strcmp( (char*)atts[i++], attr_name ) == 0 ) { if( atts[i] != NULL ) { return (char*) atts[i]; } @@ -443,10 +444,11 @@ char* get_xml_attr( const xmlChar** atts, char* attr_name ) { // ------------------------------------------------------------------ // See which tags are ending // ------------------------------------------------------------------ -void endElementHandler( void *session, const xmlChar *name) { +void endElementHandler( void *session, const xmlChar *ename) { transport_session* ses = (transport_session*) session; if( ! ses ) { return; } + char* name = (char*) ename; if( strcmp( name, "message" ) == 0 ) { diff --git a/OpenSRF/src/perlmods/JSON.pm b/OpenSRF/src/perlmods/JSON.pm index 2128f96630..13f75e8009 100644 --- a/OpenSRF/src/perlmods/JSON.pm +++ b/OpenSRF/src/perlmods/JSON.pm @@ -85,7 +85,78 @@ sub _json_hint_to_class { return $hint; } + +my $JSON_CLASS_KEY = '__c'; +my $JSON_PAYLOAD_KEY = '__p'; + sub JSON2perl { + my( $class, $string ) = @_; + my $perl = $class->rawJSON2perl($string); + use Data::Dumper; + return $class->JSONObject2Perl($perl); +} + +sub perl2JSON { + my( $class, $obj ) = @_; + my $json = $class->perl2JSONObject($obj); + return $class->rawPerl2JSON($json); +} + +sub JSONObject2Perl { + my $class = shift; + my $obj = shift; + my $ref = ref($obj); + if( $ref eq 'HASH' ) { + if( defined($obj->{$JSON_CLASS_KEY})) { + my $cls = $obj->{$JSON_CLASS_KEY}; + if( $obj = $class->JSONObject2Perl($obj->{$JSON_PAYLOAD_KEY}) ) { + $cls = $class->lookup_class($cls) || $cls; + return bless(\$obj, $cls) unless ref($obj); + return bless($obj, $cls); + } + return undef; + } + $obj->{$_} = $class->JSONObject2Perl($obj->{$_}) for (keys %$obj); + } elsif( $ref eq 'ARRAY' ) { + $obj->[$_] = $class->JSONObject2Perl($obj->[$_]) for(0..scalar(@$obj) - 1); + } + return $obj; +} + +sub perl2JSONObject { + my $class = shift; + my $obj = shift; + my $ref = ref($obj); + + return $obj unless $ref; + my $newobj; + + if( $ref eq 'HASH' ) { + $newobj = {}; + $newobj->{$_} = $class->perl2JSONObject( $obj->{$_} ) for (keys %$obj); + } elsif( $ref eq 'ARRAY' ) { + $newobj = []; + $newobj->[$_] = $class->perl2JSONObject( $obj->[$_] ) for(0..scalar(@$obj) - 1 ); + } elsif( $ref ) { + if(UNIVERSAL::isa($obj, 'HASH')) { + $newobj = {}; + $newobj->{$_} = $class->perl2JSONObject( $obj->{$_} ) for (keys %$obj); + bless( $newobj, ref($obj) ); + #bless($obj, 'HASH'); # so our parser won't add the hints + } elsif(UNIVERSAL::isa($obj, 'ARRAY')) { + $newobj = []; + $newobj->[$_] = $class->perl2JSONObject( $obj->[$_] ) for(0..scalar(@$obj) - 1); + bless( $newobj, ref($obj) ); + #bless($obj, 'ARRAY'); # so our parser won't add the hints + } + $ref = $class->lookup_hint($ref) || $ref; + $newobj = { $JSON_CLASS_KEY => $ref, $JSON_PAYLOAD_KEY => $newobj }; + } + return $newobj; +} + + +sub rawJSON2perl { my $class = shift; local $_ = shift; @@ -97,8 +168,8 @@ sub JSON2perl { s/\\u([0-9a-fA-F]{4})/chr(hex($1))/esog; # handle class blessings - s/\/\*--\s*S\w*?\s+\S+\s*--\*\// bless(/sog; - s/(\]|\}|")\s*\/\*--\s*E\w*?\s+(\S+)\s*--\*\//$1 => _json_hint_to_class("$1", "$2")) /sog; +# s/\/\*--\s*S\w*?\s+\S+\s*--\*\// bless(/sog; +# s/(\]|\}|")\s*\/\*--\s*E\w*?\s+(\S+)\s*--\*\//$1 => _json_hint_to_class("$1", "$2")) /sog; my $re = qr/((?(?<=\\)"|[^"])*(?(), $strict); + $output .= rawPerl2JSON(undef,$perl->(), $strict); } elsif (ref($perl) and ("$perl" =~ /^([^=]+)=(\w+)/o)) { my $type = $2; my $name = $1; JSON->register_class_hint(name => $name, hint => $name, type => lc($type)); - $output .= perl2JSON(undef,$perl, $strict); + $output .= rawPerl2JSON(undef,$perl, $strict); } else { $perl = NFC($perl); $perl =~ s{\\}{\\\\}sgo; diff --git a/OpenSRF/src/python/osrf/json.py b/OpenSRF/src/python/osrf/json.py index 615b0fd6f0..826e6b978b 100644 --- a/OpenSRF/src/python/osrf/json.py +++ b/OpenSRF/src/python/osrf/json.py @@ -14,220 +14,228 @@ # ----------------------------------------------------------------------- -import simplejson, types +import simplejson, types, cjson JSON_PAYLOAD_KEY = '__p' JSON_CLASS_KEY = '__c' class osrfNetworkObject(object): - """Base class for serializable network objects.""" - def getData(self): - """Returns a dict of data contained by this object""" - return self.data + """Base class for serializable network objects.""" + def getData(self): + """Returns a dict of data contained by this object""" + return self.data class __unknown(osrfNetworkObject): - """Default class for un-registered network objects.""" - def __init__(self, data=None): - self.data = data + """Default class for un-registered network objects.""" + def __init__(self, data=None): + self.data = data setattr(__unknown,'__keys', []) setattr(osrfNetworkObject,'__unknown', __unknown) def osrfNetworkRegisterHint(hint, keys, type='hash'): - """Register a network hint. - - This creates a new class at osrfNetworkObject. with - methods for accessing/mutating the object's data. - Method names will match the names found in the keys array - - hint - The hint name to encode with the object - type - The data container type. - keys - An array of data keys. If type is an 'array', the order of - the keys will determine how the data is accessed - """ - - estr = "class %s(osrfNetworkObject):\n" % hint - estr += "\tdef __init__(self, data=None):\n" - estr += "\t\tself.data = data\n" - estr += "\t\tif data:\n" - - if type == 'hash': - estr += "\t\t\tpass\n" - else: - # we have to make sure the array is large enough - estr += "\t\t\twhile len(data) < %d:\n" % len(keys) - estr += "\t\t\t\tdata.append(None)\n" - - estr += "\t\telse:\n" - - if type == 'array': - estr += "\t\t\tself.data = []\n" - estr += "\t\t\tfor i in range(%s):\n" % len(keys) - estr += "\t\t\t\tself.data.append(None)\n" - for i in range(len(keys)): - estr += "\tdef %s(self, *args):\n"\ - "\t\tif len(args) != 0:\n"\ - "\t\t\tself.data[%s] = args[0]\n"\ - "\t\treturn self.data[%s]\n" % (keys[i], i, i) - - if type == 'hash': - estr += "\t\t\tself.data = {}\n" - estr += "\t\t\tfor i in %s:\n" % str(keys) - estr += "\t\t\t\tself.data[i] = None\n" - for i in keys: - estr += "\tdef %s(self, *args):\n"\ - "\t\tif len(args) != 0:\n"\ - "\t\t\tself.data['%s'] = args[0]\n"\ - "\t\tval = None\n"\ - "\t\ttry: val = self.data['%s']\n"\ - "\t\texcept: return None\n"\ - "\t\treturn val\n" % (i, i, i) - - estr += "setattr(osrfNetworkObject, '%s', %s)\n" % (hint,hint) - estr += "setattr(osrfNetworkObject.%s, '__keys', keys)" % hint - exec(estr) - - + """Register a network hint. + + This creates a new class at osrfNetworkObject. with + methods for accessing/mutating the object's data. + Method names will match the names found in the keys array + + hint - The hint name to encode with the object + type - The data container type. + keys - An array of data keys. If type is an 'array', the order of + the keys will determine how the data is accessed + """ + + # XXX there must be a cleaner way to do this via the python API + + estr = "class %s(osrfNetworkObject):\n" % hint + estr += "\tdef __init__(self, data=None):\n" + estr += "\t\tself.data = data\n" + estr += "\t\tif data:\n" + + if type == 'hash': + estr += "\t\t\tpass\n" + else: + # we have to make sure the array is large enough + estr += "\t\t\twhile len(data) < %d:\n" % len(keys) + estr += "\t\t\t\tdata.append(None)\n" + + estr += "\t\telse:\n" + + if type == 'array': + estr += "\t\t\tself.data = []\n" + estr += "\t\t\tfor i in range(%s):\n" % len(keys) + estr += "\t\t\t\tself.data.append(None)\n" + for i in range(len(keys)): + estr += "\tdef %s(self, *args):\n"\ + "\t\tif len(args) != 0:\n"\ + "\t\t\tself.data[%s] = args[0]\n"\ + "\t\treturn self.data[%s]\n" % (keys[i], i, i) + + if type == 'hash': + estr += "\t\t\tself.data = {}\n" + estr += "\t\t\tfor i in %s:\n" % str(keys) + estr += "\t\t\t\tself.data[i] = None\n" + for i in keys: + estr += "\tdef %s(self, *args):\n"\ + "\t\tif len(args) != 0:\n"\ + "\t\t\tself.data['%s'] = args[0]\n"\ + "\t\tval = None\n"\ + "\t\ttry: val = self.data['%s']\n"\ + "\t\texcept: return None\n"\ + "\t\treturn val\n" % (i, i, i) + + estr += "setattr(osrfNetworkObject, '%s', %s)\n" % (hint,hint) + estr += "setattr(osrfNetworkObject.%s, '__keys', keys)" % hint + exec(estr) + + # ------------------------------------------------------------------- # Define the custom object parsing behavior # ------------------------------------------------------------------- def __parseNetObject(obj): - hint = None - islist = False - try: - hint = obj[JSON_CLASS_KEY] - obj = obj[JSON_PAYLOAD_KEY] - except: pass - if isinstance(obj,list): - islist = True - for i in range(len(obj)): - obj[i] = __parseNetObject(obj[i]) - else: - if isinstance(obj,dict): - for k,v in obj.iteritems(): - obj[k] = __parseNetObject(v) - - if hint: # Now, "bless" the object into an osrfNetworkObject - estr = 'obj = osrfNetworkObject.%s(obj)' % hint - try: - exec(estr) - except AttributeError: - # this object has not been registered, shove it into the default container - obj = osrfNetworkObject.__unknown(obj) - - return obj; + hint = None + #islist = False + try: + hint = obj[JSON_CLASS_KEY] + obj = obj[JSON_PAYLOAD_KEY] + except: pass + if isinstance(obj,list): + #islist = True + for i in range(len(obj)): + obj[i] = __parseNetObject(obj[i]) + else: + if isinstance(obj,dict): + for k,v in obj.iteritems(): + obj[k] = __parseNetObject(v) + + if hint: # Now, "bless" the object into an osrfNetworkObject + estr = 'obj = osrfNetworkObject.%s(obj)' % hint + try: + exec(estr) + except AttributeError: + # this object has not been registered, shove it into the default container + obj = osrfNetworkObject.__unknown(obj) + + return obj; # ------------------------------------------------------------------- # Define the custom object encoding behavior # ------------------------------------------------------------------- class osrfJSONNetworkEncoder(simplejson.JSONEncoder): - def default(self, obj): - if isinstance(obj, osrfNetworkObject): - return { - JSON_CLASS_KEY: obj.__class__.__name__, - JSON_PAYLOAD_KEY: self.default(obj.getData()) - } - return obj + def default(self, obj): + if isinstance(obj, osrfNetworkObject): + return { + JSON_CLASS_KEY: obj.__class__.__name__, + JSON_PAYLOAD_KEY: self.default(obj.getData()) + } + return obj def osrfObjectToJSON(obj): - """Turns a python object into a wrapped JSON object""" - return simplejson.dumps(obj, cls=osrfJSONNetworkEncoder) + """Turns a python object into a wrapped JSON object""" + return simplejson.dumps(obj, cls=osrfJSONNetworkEncoder) def osrfJSONToObject(json): - """Turns a JSON string into python objects""" - obj = simplejson.loads(json) - return __parseNetObject(obj) + """Turns a JSON string into python objects""" + #obj = simplejson.loads(json) + obj = None + try: + obj = cjson.decode(json) + except Exception: + # cjson is more finicky, if it dies, try simplejson + obj = simplejson.loads(json) + return __parseNetObject(obj) def osrfParseJSONRaw(json): - """Parses JSON the old fashioned way.""" - return simplejson.loads(json) + """Parses JSON the old fashioned way.""" + return simplejson.loads(json) def osrfToJSONRaw(obj): - """Stringifies an object as JSON with no additional logic.""" - return simplejson.dumps(obj) + """Stringifies an object as JSON with no additional logic.""" + return simplejson.dumps(obj) def __tabs(t): - r='' - for i in range(t): r += ' ' - return r + r='' + for i in range(t): r += ' ' + return r -def osrfDebugNetworkObject(obj, t=1): - """Returns a debug string for a given object. +def osrfDebugNetworkObject(obj, t=0): + """Returns a debug string for a given object. - If it's an osrfNetworkObject and has registered keys, key/value p - pairs are returned. Otherwise formatted JSON is returned""" + If it's an osrfNetworkObject and has registered keys, key/value p + pairs are returned. Otherwise formatted JSON is returned""" - s = '' - if isinstance(obj, osrfNetworkObject) and len(obj.__keys): - obj.__keys.sort() + s = '' + if isinstance(obj, osrfNetworkObject) and len(obj.__keys): + obj.__keys.sort() - for k in obj.__keys: + for k in obj.__keys: - key = k - while len(key) < 24: key += '.' # pad the names to make the values line up somewhat - val = getattr(obj, k)() + key = k + while len(key) < 24: key += '.' # pad the names to make the values line up somewhat + val = getattr(obj, k)() - subobj = val and not (isinstance(val,unicode) or \ - isinstance(val, int) or isinstance(val, float) or isinstance(val, long)) + subobj = val and not (isinstance(val,unicode) or isinstance(val,str) or\ + isinstance(val, int) or isinstance(val, float) or isinstance(val, long)) - s += __tabs(t) + key + ' = ' + s += __tabs(t) + key + ' ' - if subobj: - s += '\n' - val = osrfDebugNetworkObject(val, t+1) + if subobj: + s += '\n' + val = osrfDebugNetworkObject(val, t+1) - s += str(val) + s += str(val) - if not subobj: s += '\n' + if not subobj: s += '\n' - else: - s = osrfFormatJSON(osrfObjectToJSON(obj)) - return s + else: + s = osrfFormatJSON(osrfObjectToJSON(obj)) + return s def osrfFormatJSON(json): - """JSON pretty-printer""" - r = '' - t = 0 - instring = False - inescape = False - done = False + """JSON pretty-printer""" + r = '' + t = 0 + instring = False + inescape = False + done = False - for c in json: + for c in json: - done = False - if (c == '{' or c == '[') and not instring: - t += 1 - r += c + '\n' + __tabs(t) - done = True + done = False + if (c == '{' or c == '[') and not instring: + t += 1 + r += c + '\n' + __tabs(t) + done = True - if (c == '}' or c == ']') and not instring: - t -= 1 - r += '\n' + __tabs(t) + c - done = True + if (c == '}' or c == ']') and not instring: + t -= 1 + r += '\n' + __tabs(t) + c + done = True - if c == ',' and not instring: - r += c + '\n' + __tabs(t) - done = True + if c == ',' and not instring: + r += c + '\n' + __tabs(t) + done = True - if c == '"' and not inescape: - instring = not instring + if c == '"' and not inescape: + instring = not instring - if inescape: - inescape = False + if inescape: + inescape = False - if c == '\\': - inescape = True + if c == '\\': + inescape = True - if not done: - r += c + if not done: + r += c - return r + return r - + diff --git a/OpenSRF/src/python/osrf/net.py b/OpenSRF/src/python/osrf/net.py index db0b131f40..5664761f4f 100644 --- a/OpenSRF/src/python/osrf/net.py +++ b/OpenSRF/src/python/osrf/net.py @@ -22,7 +22,7 @@ from osrf.log import * import os, time import logging -# - log jabber activity (for future reference) +# - if you need raw jabber logs #logger=logging.getLogger() #logger.addHandler(logging.StreamHandler()) #logger.addHandler(logging.FileHandler('j.log')) diff --git a/OpenSRF/src/python/srfsh.py b/OpenSRF/src/python/srfsh.py index 4742246052..e3e63c4b9d 100755 --- a/OpenSRF/src/python/srfsh.py +++ b/OpenSRF/src/python/srfsh.py @@ -5,79 +5,94 @@ from osrf.system import osrfConnect from osrf.json import * from osrf.ses import osrfClientSession from osrf.conf import osrfConfigValue +import osrf.ex +prompt = "\033[01;32msrfsh\033[01;34m% \033[00m" +last_response = None +commands = {} + + +def register_command(name, callback): + commands[name] = callback + # ------------------------------------------------------------------- # main listen loop # ------------------------------------------------------------------- +""" def do_loop(): - while True: + while True: + + try: + line = raw_input(prompt+'') + if not len(line): + continue + if lower(line) == 'exit' or lower(line) == 'quit': + break + parts = split(line) - try: - #line = raw_input("srfsh% ") - line = raw_input("\033[01;32msrfsh\033[01;34m% \033[00m") - if not len(line): - continue - if lower(line) == 'exit' or lower(line) == 'quit': - break - parts = split(line) + command = parts.pop(0) + + if command == 'request': + handle_request(parts) + continue - command = parts[0] - - if command == 'request': - parts.pop(0) - handle_request(parts) - continue + if command == 'math_bench': + handle_math_bench(parts) + continue - if command == 'math_bench': - parts.pop(0) - handle_math_bench(parts) - continue + if command == 'help': + handle_help() + continue - if command == 'help': - handle_help() - continue + if command == 'set': + handle_set(parts) - if command == 'set': - parts.pop(0) - handle_set(parts) + if command == 'get': + handle_get(parts) - if command == 'get': - parts.pop(0) - handle_get(parts) + if command == 'eval': + handle_eval(parts) - except KeyboardInterrupt: - print "" + except KeyboardInterrupt: + print "" - except EOFError: - print "exiting..." - sys.exit(0) + except EOFError: + print "exiting..." + sys.exit(0) +""" # ------------------------------------------------------------------- # Set env variables to control behavior # ------------------------------------------------------------------- def handle_set(parts): - m = re.compile('(.*)=(.*)').match(parts[0]) - key = m.group(1) - val = m.group(2) - set_var(key, val) - print "%s = %s" % (key, val) + m = re.compile('(.*)=(.*)').match(parts[0]) + key = m.group(1) + val = m.group(2) + set_var(key, val) + print "%s = %s" % (key, val) def handle_get(parts): - try: - print get_var(parts[0]) - except: - print "" - + try: + print get_var(parts[0]) + except: + print "" + +def handle_eval(parts): + com = ' '.join(parts) + try: + print eval(com) + except Exception, e: + print "EVAL failed: " + str(e) # ------------------------------------------------------------------- # Prints help info # ------------------------------------------------------------------- def handle_help(): - print """ + print """ help - show this menu @@ -87,94 +102,109 @@ def handle_help(): request [, , ...] - performs an opensrf request + eval + - evals the requested command within the srfsh environment + - special variables: + - last_response - last item received from a network call + set VAR= - sets an environment variable Environment variables: SRFSH_OUTPUT = pretty - print pretty JSON and key/value pairs for network objects = raw - print formatted JSON - """ + """ - + # ------------------------------------------------------------------- # performs an opesnrf request # ------------------------------------------------------------------- def handle_request(parts): - service = parts.pop(0) - method = parts.pop(0) - jstr = '[%s]' % join(parts) - params = None + service = parts.pop(0) + method = parts.pop(0) + jstr = '[%s]' % join(parts) + params = None + global last_response - try: - params = osrfJSONToObject(jstr) - except: - print "Error parsing JSON: %s" % jstr - return + try: + params = osrfJSONToObject(jstr) + except: + print "Error parsing JSON: %s" % jstr + return - ses = osrfClientSession(service) + otp = get_var('SRFSH_OUTPUT') - end = None - start = time.time() + ses = osrfClientSession(service) - req = ses.request2(method, tuple(params)) + end = None + start = time.time() + req = ses.request2(method, tuple(params)) - while True: - resp = req.recv(timeout=120) - if not end: - total = time.time() - start - if not resp: break + while True: - otp = get_var('SRFSH_OUTPUT') - if otp == 'pretty': - print osrfDebugNetworkObject(resp.content()) - else: - print osrfFormatJSON(osrfObjectToJSON(resp.content())) + resp = None - req.cleanup() - ses.cleanup() + try: + resp = req.recv(timeout=120) + except Exception, e: + print "\nThere was a problem running your request:\n\n%s\n" % str(e) + return - print '-'*60 - print "Total request time: %f" % total - print '-'*60 + if not end: + total = time.time() - start + if not resp: break + + if otp == 'pretty': + print osrfDebugNetworkObject(resp.content()) + else: + print osrfFormatJSON(osrfObjectToJSON(resp.content())) + last_response = resp.content() + + req.cleanup() + ses.cleanup() + + print '-'*60 + print "Total request time: %f" % total + print '-'*60 def handle_math_bench(parts): - count = int(parts.pop(0)) - ses = osrfClientSession('opensrf.math') - times = [] - - for i in range(100): - if i % 10: sys.stdout.write('.') - else: sys.stdout.write( str( i / 10 ) ) - print ""; - - - for i in range(count): - - starttime = time.time() - req = ses.request('add', 1, 2) - resp = req.recv(timeout=2) - endtime = time.time() - - if resp.content() == 3: - sys.stdout.write("+") - sys.stdout.flush() - times.append( endtime - starttime ) - else: - print "What happened? %s" % str(resp.content()) - - req.cleanup() - if not ( (i+1) % 100): - print ' [%d]' % (i+1) - - ses.cleanup() - total = 0 - for i in times: total += i - print "\naverage time %f" % (total / len(times)) + count = int(parts.pop(0)) + ses = osrfClientSession('opensrf.math') + times = [] + + for i in range(100): + if i % 10: sys.stdout.write('.') + else: sys.stdout.write( str( i / 10 ) ) + print ""; + + + for i in range(count): + + starttime = time.time() + req = ses.request('add', 1, 2) + resp = req.recv(timeout=2) + endtime = time.time() + + if resp.content() == 3: + sys.stdout.write("+") + sys.stdout.flush() + times.append( endtime - starttime ) + else: + print "What happened? %s" % str(resp.content()) + + req.cleanup() + if not ( (i+1) % 100): + print ' [%d]' % (i+1) + + ses.cleanup() + total = 0 + for i in times: total += i + print "\naverage time %f" % (total / len(times)) @@ -183,88 +213,151 @@ def handle_math_bench(parts): # Defines the tab-completion handling and sets up the readline history # ------------------------------------------------------------------- def setup_readline(): - class SrfshCompleter(object): - def __init__(self, words): - self.words = words - self.prefix = None - - def complete(self, prefix, index): - if prefix != self.prefix: - # find all words that start with this prefix - self.matching_words = [ - w for w in self.words if w.startswith(prefix) - ] - self.prefix = prefix - try: - return self.matching_words[index] - except IndexError: - return None - - words = 'request', 'help', 'exit', 'quit', 'opensrf.settings', 'opensrf.math', 'set' - completer = SrfshCompleter(words) - readline.parse_and_bind("tab: complete") - readline.set_completer(completer.complete) - - histfile = os.path.join(get_var('HOME'), ".srfsh_history") - try: - readline.read_history_file(histfile) - except IOError: - pass - atexit.register(readline.write_history_file, histfile) + class SrfshCompleter(object): + def __init__(self, words): + self.words = words + self.prefix = None + + def complete(self, prefix, index): + if prefix != self.prefix: + # find all words that start with this prefix + self.matching_words = [ + w for w in self.words if w.startswith(prefix) + ] + self.prefix = prefix + try: + return self.matching_words[index] + except IndexError: + return None + + words = 'request', 'help', 'exit', 'quit', 'opensrf.settings', 'opensrf.math', 'set' + completer = SrfshCompleter(words) + readline.parse_and_bind("tab: complete") + readline.set_completer(completer.complete) + + histfile = os.path.join(get_var('HOME'), ".srfsh_history") + try: + readline.read_history_file(histfile) + except IOError: + pass + atexit.register(readline.write_history_file, histfile) def do_connect(): - file = os.path.join(get_var('HOME'), ".srfsh.xml") + file = os.path.join(get_var('HOME'), ".srfsh.xml") - print_green("Connecting to opensrf...") - osrfConnect(file) - print_red('OK\n') + print_green("Connecting to opensrf...") + osrfConnect(file) + print_red('OK') + print '' def load_plugins(): - # Load the user defined external plugins - # XXX Make this a real module interface, with tab-complete words, commands, etc. - plugins = osrfConfigValue('plugins') - plugins = osrfConfigValue('plugins.plugin') - if not isinstance(plugins, list): - plugins = [plugins] - - for module in plugins: - name = module['module'] - init = module['init'] - print_green("Loading module %s..." % name) - - try: - str = 'from %s import %s\n%s()' % (name, init, init) - exec(str) - print_red('OK\n') - - except Exception, e: - sys.stderr.write("\nError importing plugin %s, with init symbol %s: \n%s\n" % (name, init, e)) + # Load the user defined external plugins + # XXX Make this a real module interface, with tab-complete words, commands, etc. + plugins = osrfConfigValue('plugins') + plugins = osrfConfigValue('plugins.plugin') + if not isinstance(plugins, list): + plugins = [plugins] + + for module in plugins: + name = module['module'] + init = module['init'] + print_green("Loading module %s..." % name) + + try: + str = 'from %s import %s\n%s()' % (name, init, init) + exec(str) + print_red('OK') + print '' + + except Exception, e: + sys.stderr.write("\nError importing plugin %s, with init symbol %s: \n%s\n" % (name, init, e)) def set_vars(): - if not get_var('SRFSH_OUTPUT'): - set_var('SRFSH_OUTPUT', 'pretty') + if not get_var('SRFSH_OUTPUT'): + set_var('SRFSH_OUTPUT', 'pretty') def set_var(key, val): - os.environ[key] = val + os.environ[key] = val def get_var(key): - try: return os.environ[key] - except: return '' - - + try: return os.environ[key] + except: return '' + + def print_green(str): - sys.stdout.write("\033[01;32m") - sys.stdout.write(str) - sys.stdout.write("\033[00m") - sys.stdout.flush() + sys.stdout.write("\033[01;32m") + sys.stdout.write(str) + sys.stdout.write("\033[00m") + #sys.stdout.flush() def print_red(str): - sys.stdout.write("\033[01;31m") - sys.stdout.write(str) - sys.stdout.write("\033[00m") - sys.stdout.flush() + sys.stdout.write("\033[01;31m") + sys.stdout.write(str) + sys.stdout.write("\033[00m") + #sys.stdout.flush() + +def print_purple(str): + sys.stdout.write("\033[01;34m") + sys.stdout.write(str) + sys.stdout.write("\033[00m") + #sys.stdout.flush() + + + + + + + +# ------------------------------------------------------------------- +# main listen loop +# ------------------------------------------------------------------- +def do_loop(): + while True: + + try: + line = raw_input(prompt+'') + if not len(line): + continue + if lower(line) == 'exit' or lower(line) == 'quit': + break + parts = split(line) + + command = parts.pop(0) + + if command == 'request': + handle_request(parts) + continue + + if command == 'math_bench': + handle_math_bench(parts) + continue + + if command == 'help': + handle_help() + continue + + if command == 'set': + handle_set(parts) + + if command == 'get': + handle_get(parts) + + if command == 'eval': + handle_eval(parts) + + + + except KeyboardInterrupt: + print "" + + except EOFError: + print "exiting..." + sys.exit(0) + + + diff --git a/OpenSRF/src/router/Makefile b/OpenSRF/src/router/Makefile index e156743e77..f545b66158 100644 --- a/OpenSRF/src/router/Makefile +++ b/OpenSRF/src/router/Makefile @@ -1,6 +1,6 @@ #MALLOC_CHECK_=1 # XXX debug only -LDLIBS += -lxml2 -lopensrf -lobjson +LDLIBS += -lxml2 -lopensrf CFLAGS += -D_ROUTER all: opensrf_router diff --git a/OpenSRF/src/srfsh/Makefile b/OpenSRF/src/srfsh/Makefile index 163818e282..17526a0459 100644 --- a/OpenSRF/src/srfsh/Makefile +++ b/OpenSRF/src/srfsh/Makefile @@ -1,6 +1,6 @@ # if EXEC_DEFAULT is defined, then srfsh will send all unknown commands to the shell for execution -LDLIBS += -lobjson -lreadline -lxml2 -lopensrf -lncurses +LDLIBS += -lreadline -lxml2 -lopensrf -lncurses LDFLAGS += -DEXEC_DEFAULT all: srfsh diff --git a/OpenSRF/src/srfsh/srfsh.c b/OpenSRF/src/srfsh/srfsh.c index 98870389d2..a5e1f82cf9 100644 --- a/OpenSRF/src/srfsh/srfsh.c +++ b/OpenSRF/src/srfsh/srfsh.c @@ -514,7 +514,7 @@ int send_request( char* server, jsonObject* params = NULL; if( !relay ) { if( buffer != NULL && buffer->n_used > 0 ) - params = json_parse_string(buffer->buf); + params = jsonParseString(buffer->buf); } else { if(!last_result || ! last_result->_result_content) { printf("We're not going to call 'relay' with no result params\n"); @@ -802,7 +802,7 @@ int do_math( int count, int style ) { osrf_app_session* session = osrf_app_client_session_init( "opensrf.math" ); osrf_app_session_connect(session); - jsonObject* params = json_parse_string("[]"); + jsonObject* params = jsonParseString("[]"); jsonObjectPush(params,jsonNewObject("1")); jsonObjectPush(params,jsonNewObject("2")); diff --git a/OpenSRF/src/utils/fieldmapper-c.pl b/OpenSRF/src/utils/fieldmapper-c.pl index 80a59e53ab..063e6146f7 100755 --- a/OpenSRF/src/utils/fieldmapper-c.pl +++ b/OpenSRF/src/utils/fieldmapper-c.pl @@ -24,8 +24,7 @@ my $map = $Fieldmapper::fieldmap; print HEADER < #include #include -//#include - #include "md5.h" + +//#define MKCHAR(__c) (char*) __c + + #define OSRF_MALLOC(ptr, size) \ ptr = (void*) malloc( size ); \ if( ptr == NULL ) { \ diff --git a/OpenSRF/src/utils/xml_utils.c b/OpenSRF/src/utils/xml_utils.c index 15a350b770..a33c36c350 100644 --- a/OpenSRF/src/utils/xml_utils.c +++ b/OpenSRF/src/utils/xml_utils.c @@ -91,7 +91,7 @@ char* xmlSaxAttr( const xmlChar** atts, char* name ) { if( atts && name ) { int i; for(i = 0; (atts[i] != NULL); i++) { - if(!strcmp(atts[i], name)) { + if(!strcmp( (char*)atts[i], name)) { if(atts[++i]) return (char*) atts[i]; } }