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;
install:
@./install.sh install
+verbose_install:
+ @./install.sh install verbose
+
clean:
@./install.sh clean
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)
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:
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:
@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 $@
#include <stdio.h>
/* 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*);
#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"
-LDLIBS += -lobjson -lopensrf #-lfieldmapper
+LDLIBS += -lopensrf
CFLAGS += -DOSRF_LOG_PARAMS
#all: oils_auth.so oils_fetch.so oils_cstore.so
#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"
#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 <dbi/dbi.h>
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* );
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 );
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(
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
);
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);
sql_buf,
"%s %s %s",
field_transform,
- node->key,
+ key,
value
);
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;
}
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);
growing_buffer* sql_buf = buffer_init(128);
- jsonObjectNode* node = NULL;
+ jsonObject* node = NULL;
int first = 1;
jsonObjectIterator* search_itr = jsonNewObjectIterator( search_hash );
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);
}
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;
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;
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");
}
// 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);
// ... 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 );
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);
if (is_agg->size || (flags & SELECT_DISTINCT)) {
- if (!jsonBoolIsTrue( jsonObjectGetKey( selfield->item, "aggregate" ) )) {
+ if (!jsonBoolIsTrue( jsonObjectGetKey( selfield, "aggregate" ) )) {
if (gfirst) {
gfirst = 0;
} else {
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);
*/
}
}
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);
}
} 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";
}
- } 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) {
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;
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;
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;
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);
}
} 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";
}
} else {
- string = jsonObjectToSimpleString(snode->item);
+ string = jsonObjectToSimpleString(snode);
buffer_add(order_buf, string);
free(string);
break;
}
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 ))) {
char* search_key =
jsonObjectToSimpleString(
jsonObjectGetIndex(
- cur->item,
+ cur,
atoi( osrfHashGet(value_field, "array_position") )
)
);
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(
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) )
);
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 )
);
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));
}
}
jsonObjectSetIndex(
object,
fmIndex,
- jsonNewObject( dbi_result_get_string(result, columnName) )
+ jsonNewObject( (char*) dbi_result_get_string(result, columnName) )
);
break;
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 :
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;
}
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 );
}
}
}
#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"
#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"
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 ),
}
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 ),
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 );
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 ),
}
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 ),
_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 ),
}
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 ),
}
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 ),
}
string_tmp = NULL;
- if( (string_tmp = (char*)xmlGetProp(_f, "name")) ) {
+ if( (string_tmp = (char*)xmlGetProp(_f, BAD_CAST "name")) ) {
osrfHashSet(
_tmp,
strdup( string_tmp ),
_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 ),
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 ),
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 ),
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 );
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 ),
-#include "objson/object.h"
+#include "opensrf/osrf_json.h"
#include "opensrf/log.h"
// XXX replacing this with liboils_idl implementation
-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
OILS_NS_REPORTER='http://open-ils.org/spec/opensrf/IDL/reporter/v1'
OILS_APP_CSTORE='open-ils.cstore'
+OILS_APP_AUTH='open-ils.auth'
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)
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
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
- # Logs string with some meta info
+ # Logs the given string with some meta info
# -------------------------------------------------------------------------
def log(self, func, string):
s = "editor[";
# -------------------------------------------------------------------------
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))
# -------------------------------------------------------------------------
+ # 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 += '<new object: %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
# -------------------------------------------------------------------------
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()):
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
+
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 <bootstrap_config>" ) 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";
+
+
-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;
//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; }
<div>
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/utils.js'> </script>
-
- <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/utils.js'> </script>
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/config.js'> </script>
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/CGI.js'> </script>
<!--
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/slimtree.js'> </script>
- <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/JSON.js'> </script>
+ <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/JSON_wrapper.js'> </script>
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/fmcore.js'> </script>
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/fmgen.js'> </script>
<script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/opac_utils.js'> </script>
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 \
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 \
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
@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
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
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)]"
-LDLIBS += -lobjson -lopensrf
+LDLIBS += -lopensrf
CFLAGS += -DOSRF_LOG_PARAMS
all: osrf_math.so osrf_dbmath.so osrf_version.so
#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"
#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"
#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"
#CFLAGS += -DASSUME_STATELESS -DOSRF_GATEWAY_NASTY_DEBUG
CFLAGS += -DASSUME_STATELESS
-LDLIBS += -lobjson -lopensrf
+LDLIBS += -lopensrf
all: osrf_json_gateway.so copy
/* and the JSON parser, so we can read the response we're XMLizing */
#include <string.h>
#include <stdio.h>
-#include "objson/object.h"
-#include "objson/json_parser.h"
+#include "opensrf/osrf_json.h"
#include "opensrf/utils.h"
char* json_string_to_xml(char*);
#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 <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#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 */
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;
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}
};
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) {
/* 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 */
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, ", ");
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);
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);
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,
-LDLIBS += -lopensrf -lobjson -lxml2
+LDLIBS += -lopensrf -lxml2
CFLAGS += -D_GNU_SOURCE
all: chopchop
# 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 \
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 \
osrf_transgroup.h \
osrf_list.h \
osrf_hash.h \
+ osrf_json.h \
xml_utils.h
all: xml_utils.o $(TARGETS) copy
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
}
cfg->config = xmlDocToJSON(doc);
+
+ /*
+ char* j = jsonObjectToJSON(cfg->config);
+ fprintf(stderr, "JSON:\n%s\n", j);
+ free(j);
+ */
+
xmlFreeDoc(doc);
if(!cfg->config) {
#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;
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);
#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"
#include "osrf_hash.h"
#include "osrf_list.h"
-#include "objson/object.h"
-#include "objson/json_parser.h"
-
#define DEF_RECV_TIMEOUT 6 /* receive timeout */
#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;
#include <dlfcn.h>
#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"
*/
-#include "objson/object.h"
-#include "objson/json_parser.h"
+#include "osrf_json.h"
#include "memcache.h"
#include "log.h"
while( ((msg = msgs[i]) && (i++ < count)) )
jsonObjectPush(wrapper, osrfMessageToJSON( msg ));
+ //jsonObject* enc = jsonObjectEncodeClass(wrapper);
j = jsonObjectToJSON(wrapper);
jsonObjectFree(wrapper);
+ //jsonObjectFree(enc);
return j;
}
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;
}
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,
#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 */
#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"
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
xmlFree(router_class);
}
if(broadcast) {
- if(strcmp(broadcast,"0") )
+ if(strcmp( (char*)broadcast,"0") )
new_msg->broadcast = 1;
xmlFree(broadcast);
}
// ---------------------------------------------------------------------------------
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;
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" ) );
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];
}
// ------------------------------------------------------------------
// 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 ) {
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;
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/((?<!\\)"(?>(?<=\\)"|[^"])*(?<!\\)")/;
# Grab strings...
return eval '$ret = '.$_;
}
+
my $_json_index;
sub ___JSON2perl {
my $class = shift;
return eval $output;
}
-sub perl2JSON {
+
+sub rawPerl2JSON {
my ($class, $perl, $strict) = @_;
my $output = '';
$output = 'null' unless $strict;
} elsif (ref($perl) and ref($perl) =~ /^JSON/) {
$output .= $perl;
- } elsif ( ref($perl) && exists($_class_map{classes}{ref($perl)}) ) {
- $output .= '/*--S '.$_class_map{classes}{ref($perl)}{hint}.'--*/';
- if (lc($_class_map{classes}{ref($perl)}{type}) eq 'hash') {
- my %hash = %$perl;
- $output .= perl2JSON(undef,\%hash, $strict);
- } elsif (lc($_class_map{classes}{ref($perl)}{type}) eq 'array') {
- my @array = @$perl;
- $output .= perl2JSON(undef,\@array, $strict);
- }
- $output .= '/*--E '.$_class_map{classes}{ref($perl)}{hint}.'--*/';
- } elsif (ref($perl) and ref($perl) =~ /HASH/) {
+# } elsif ( ref($perl) && exists($_class_map{classes}{ref($perl)}) ) {
+# $output .= '/*--S '.$_class_map{classes}{ref($perl)}{hint}.'--*/';
+# if (lc($_class_map{classes}{ref($perl)}{type}) eq 'hash') {
+# my %hash = %$perl;
+# $output .= rawPerl2JSON(undef,\%hash, $strict);
+# } elsif (lc($_class_map{classes}{ref($perl)}{type}) eq 'array') {
+# my @array = @$perl;
+# $output .= rawPerl2JSON(undef,\@array, $strict);
+# }
+# $output .= '/*--E '.$_class_map{classes}{ref($perl)}{hint}.'--*/';
+# } elsif (ref($perl) and ref($perl) =~ /HASH/) {
+ } elsif (UNIVERSAL::isa($perl, 'HASH')) {
$output .= '{';
my $c = 0;
for my $key (sort keys %$perl) {
$outkey =~ s/\n/\\n/sgo;
$outkey =~ s/([\x{0080}-\x{fffd}])/sprintf('\u%0.4x',ord($1))/sgoe;
- $output .= '"'.$outkey.'":'. perl2JSON(undef,$$perl{$key}, $strict);
+ $output .= '"'.$outkey.'":'. rawPerl2JSON(undef,$$perl{$key}, $strict);
$c++;
}
$output .= '}';
- } elsif (ref($perl) and ref($perl) =~ /ARRAY/) {
+# } elsif (ref($perl) and ref($perl) =~ /ARRAY/) {
+ } elsif (UNIVERSAL::isa($perl, 'ARRAY')) {
$output .= '[';
my $c = 0;
for my $part (@$perl) {
$output .= ',' if ($c);
- $output .= perl2JSON(undef,$part, $strict);
+ $output .= rawPerl2JSON(undef,$part, $strict);
$c++;
}
$output .= ']';
} elsif (ref($perl) and ref($perl) =~ /CODE/) {
- $output .= perl2JSON(undef,$perl->(), $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;
# -----------------------------------------------------------------------
-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.<hint> 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.<hint> 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
-
+
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'))
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
request <service> <method> [<param1>, <param2>, ...]
- performs an opensrf request
+ eval <command>
+ - evals the requested command within the srfsh environment
+ - special variables:
+ - last_response - last item received from a network call
+
set VAR=<value>
- 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))
# 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)
+
+
+
#MALLOC_CHECK_=1 # XXX debug only
-LDLIBS += -lxml2 -lopensrf -lobjson
+LDLIBS += -lxml2 -lopensrf
CFLAGS += -D_ROUTER
all: opensrf_router
# 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
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");
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"));
print HEADER <<C;
-#include "objson/object.h"
-#include "objson/json_parser.h"
+#include "opensrf/osrf_json.h"
#include "utils.h"
/* Fieldmapper-C. Autogenerated from fieldmapper-c.pl.\n\nNote that object*'s passed in as
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
-//#include <sys/timeb.h>
-
#include "md5.h"
+
+//#define MKCHAR(__c) (char*) __c
+
+
#define OSRF_MALLOC(ptr, size) \
ptr = (void*) malloc( size ); \
if( ptr == NULL ) { \
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];
}
}