JSERVER="1";
ROUTER="1";
OPENSRF="1";
+OPENSRFC="1";
JSERVERSOCK="$PREFIX/var/sock/jserver.sock"; # jabber server socket file
JSERVERLOG="$LOGDIR/jserver.log" # jabber server log
}
function startOpenSRF {
- "$BINDIR/opensrf_ctl" start "$BOOTSTRAP";
-}
+ "$BINDIR/opensrf_ctl" start "$BOOTSTRAP";
+
+ if [ ! -z "$OPENSRFC" ]; then
+ echo "Starting OpenSRF-C...";
+ # localhost will need to be changed...
+ "$BINDIR/opensrf-c" localhost "$ETCDIR//opensrf_core.xml" "opensrf"
+ echo "OpenSRF-C started OK";
+ fi
+}
function makeMeGo {
startOpenSRF;
echo "OpenSRF started OK";
fi
+
return 0;
-
}
echo "Stopping OpenSRF...";
"$BINDIR/opensrf_ctl" stop;
+ killall -9 opensrf-c;
sleep 1;
echo "Stopping The Router...";
@echo $@
cp $(TMPDIR)/$(LIBOPENSRF) $(LIBDIR)/$(LIBOPENSRF)
cp $(OPENSRF_HEADERS) $(INCLUDEDIR)/opensrf/
+ cp libstack/opensrf $(BINDIR)/opensrf-c
make -C c-apps install
# --------------------------------------------------------------------------------
libstack/opensrf.o: libstack/opensrf.c
libstack/opensrf: libstack/opensrf.o
- $(CC) $(CFLAGS) $(LDFLAGS) -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) -lJudy -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@
router: libopensrf.so
MODULENAME,
"add",
"osrfMathRun",
- "Addss two numbers",
- "[ num1, num2 ]", 2, 0 );
+ "Addss two numbers", 2, 0 );
osrfAppRegisterMethod(
MODULENAME,
"sub",
"osrfMathRun",
- "Subtracts two numbers",
- "[ num1, num2 ]", 2, 0 );
+ "Subtracts two numbers", 2, 0 );
osrfAppRegisterMethod(
MODULENAME,
"mult",
"osrfMathRun",
- "Multiplies two numbers",
- "[ num1, num2 ]", 2, 0 );
+ "Multiplies two numbers", 2, 0 );
osrfAppRegisterMethod(
MODULENAME,
"div",
"osrfMathRun",
- "Divides two numbers",
- "[ num1, num2 ]", 2, 0 );
+ "Divides two numbers", 2, 0 );
return 0;
}
"add", /* the name of the method */
"osrfMathRun", /* the symbol that runs the method */
"Adds two numbers", /* description of the method */
- "( num1, num2 )", /* description of the method params */
2, /* the minimum number of params required to run the method */
- 0 ); /* streaming method? yes / no */
+ 0 ); /* method options, 0 for not special options */
osrfAppRegisterMethod(
MODULENAME,
"sub",
"osrfMathRun",
- "Subtracts two numbers",
- "( num1, num2 )", 2, 0 );
+ "Subtracts two numbers", 2, 0 );
osrfAppRegisterMethod(
MODULENAME,
"mult",
"osrfMathRun",
- "Multiplies two numbers",
- "( num1, num2 )", 2, 0 );
+ "Multiplies two numbers", 2, 0 );
osrfAppRegisterMethod(
MODULENAME,
"div",
"osrfMathRun",
- "Divides two numbers",
- "( num1, num2 )", 2, 0 );
+ "Divides two numbers", 2, 0 );
return 0;
}
"osrfVersion",
"The data for a service/method/params combination will be retrieved "
"from the necessary server and the MD5 sum of the total values received "
- "will be returned",
- "( serviceName, methodName, [param1, ...] )", 2, 0 );
+ "will be returned. PARAMS( serviceName, methodName, [param1, ...] )",
+ 2, 0 );
return 0;
}
clean:
- /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c
+ /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c opensrf
#include "osrf_hash.h"
#include "osrf_list.h"
-//static void _free(void* i) { free(i); }
-//static void _hfree(char* c, void* i) { free(i); }
-
int main( int argc, char* argv[] ) {
- /*
- osrfHash* list = osrfNewHash();
- list->freeItem = _hfree;
-
- char* x = strdup("X");
- char* y = strdup("Y");
- char* z = strdup("Z");
- osrfHashSet( list, x, "test1" );
- osrfHashSet( list, y, "test2" );
- osrfHashSet( list, z, "test3" );
-
- char* q = (char*) osrfHashGet( list, "test1" );
- printf( "%s\n", q );
-
- q = (char*) osrfHashGet( list, "test2" );
- printf( "%s\n", q );
-
- q = (char*) osrfHashGet( list, "test3" );
- printf( "%s\n", q );
-
- osrfHashIterator* itr = osrfNewHashIterator(list);
- char* val;
-
- while( (val = osrfHashIteratorNext(itr)) )
- printf("Iterated item: %s\n", val );
-
- osrfHashIteratorReset(itr);
- while( (val = osrfHashIteratorNext(itr)) )
- printf("Iterated item: %s\n", val );
-
- printf( "Count: %lu\n", osrfHashGetCount(list));
-
- osrfHashIteratorFree(itr);
-
- osrfHashFree(list);
-
- exit(1);
-
- osrfList* list = osrfNewList();
- list->freeItem = _free;
-
- char* x = strdup("X");
- char* y = strdup("Y");
- char* z = strdup("Z");
- osrfListSet( list, x, 0 );
- osrfListSet( list, y, 2 );
- osrfListSet( list, z, 4 );
-
- char* q = (char*) osrfListGetIndex( list, 4 );
- printf( "%s\n", q );
-
- osrfListIterator* itr = osrfNewListIterator( list );
- char* val;
-
- while( (val = osrfListIteratorNext(itr)) )
- printf("Found val: %s\n", val );
-
- osrfListIteratorReset(itr);
- printf("\n");
- while( (val = osrfListIteratorNext(itr)) )
- printf("Found val: %s\n", val );
-
- osrfListIteratorFree(itr);
-
- printf( "Count: %lu\n", osrfListGetCount(list));
-
- osrfListFree(list);
-
- exit(1);
- */
-
-
-
if( argc < 4 ) {
fprintf(stderr, "Usage: %s <host> <bootstrap_config> <config_context>\n", argv[0]);
return 1;
fprintf(stderr, "Loading OpenSRF host %s with bootstrap config %s "
"and config context %s\n", argv[1], argv[2], argv[3] );
- char* host = strdup( argv[1] );
- char* config = strdup( argv[2] );
- char* context = strdup( argv[3] );
+ /* these must be strdup'ed because init_proc_title / set_proc_title
+ are evil and overwrite the argv memory */
+ char* host = strdup( argv[1] );
+ char* config = strdup( argv[2] );
+ char* context = strdup( argv[3] );
init_proc_title( argc, argv );
set_proc_title( "OpenSRF System" );
int osrfAppRegisterMethod( char* appName, char* methodName,
- char* symbolName, char* notes, char* params, int argc, int streaming ) {
-
- return _osrfAppRegisterMethod(appName, methodName,
- symbolName, notes, params, argc, streaming, 0 );
-}
-
-int _osrfAppRegisterMethod( char* appName, char* methodName,
- char* symbolName, char* notes, char* params, int argc, int streaming, int system ) {
+ char* symbolName, char* notes, int argc, int options ) {
if( !appName || ! methodName ) return -1;
debug_handler("Registering method %s for app %s", methodName, appName );
osrfMethod* method = _osrfAppBuildMethod(
- methodName, symbolName, notes, params, argc, system, 0 );
- method->streaming = streaming;
+ methodName, symbolName, notes, argc, options );
+ method->options = options;
/* plug the method into the list of methods */
osrfHashSet( app->methods, method, method->name );
- if( streaming ) { /* build the atomic counterpart */
+ if( options & OSRF_METHOD_STREAMING ) { /* build the atomic counterpart */
+ int newops = options | OSRF_METHOD_ATOMIC;
osrfMethod* atomicMethod = _osrfAppBuildMethod(
- methodName, symbolName, notes, params, argc, system, 1 );
+ methodName, symbolName, notes, argc, newops );
osrfHashSet( app->methods, atomicMethod, atomicMethod->name );
}
osrfMethod* _osrfAppBuildMethod( char* methodName,
- char* symbolName, char* notes, char* params, int argc, int sysmethod, int atomic ) {
+ char* symbolName, char* notes, int argc, int options ) {
osrfMethod* method = safe_malloc(sizeof(osrfMethod));
if(methodName) method->name = strdup(methodName);
if(symbolName) method->symbol = strdup(symbolName);
if(notes) method->notes = strdup(notes);
- if(params) method->paramNotes = strdup(params);
method->argc = argc;
- method->sysmethod = sysmethod;
- method->atomic = atomic;
- method->cachable = 0;
+ method->options = options;
- if(atomic) { /* add ".atomic" to the end of the name */
+ if(options & OSRF_METHOD_ATOMIC) { /* add ".atomic" to the end of the name */
char mb[strlen(method->name) + 8];
sprintf(mb, "%s.atomic", method->name);
free(method->name);
method->name = strdup(mb);
- method->streaming = 1;
+ method->options |= OSRF_METHOD_STREAMING;
}
- debug_handler("Built method %s", method->name );
-
return method;
}
int __osrfAppRegisterSysMethods( char* app ) {
- _osrfAppRegisterMethod(
+ osrfAppRegisterMethod(
app, OSRF_SYSMETHOD_INTROSPECT, NULL,
"Return a list of methods whose names have the same initial "
- "substring as that of the provided method name",
- "( methodNameSubstring )", 1, 1 , 1);
+ "substring as that of the provided method name PARAMS( methodNameSubstring )",
+ 1, OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING );
- _osrfAppRegisterMethod(
+ osrfAppRegisterMethod(
app, OSRF_SYSMETHOD_INTROSPECT_ALL, NULL,
- "Returns a complete list of methods", "()", 0, 1, 1 );
+ "Returns a complete list of methods. PARAMS()", 0,
+ OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING );
- _osrfAppRegisterMethod(
+ osrfAppRegisterMethod(
app, OSRF_SYSMETHOD_ECHO, NULL,
- "Echos all data sent to the server back to the client",
- "([a, b, ...])", 0, 1, 1);
+ "Echos all data sent to the server back to the client. PARAMS([a, b, ...])", 0,
+ OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING );
return 0;
}
int retcode = 0;
- if( method->sysmethod ) {
+ if( method->options & OSRF_METHOD_SYSTEM ) {
retcode = __osrfAppRunSystemMethod(&context);
} else {
int _osrfAppRespond( osrfMethodContext* ctx, jsonObject* data, int complete ) {
if(!(ctx && ctx->method)) return -1;
- if( ctx->method->atomic ) {
+ if( ctx->method->options & OSRF_METHOD_ATOMIC ) {
osrfLog( OSRF_DEBUG,
"Adding responses to stash for atomic method %s", ctx->method );
}
- if( !ctx->method->atomic && ! ctx->method->cachable ) {
+ if( !(ctx->method->options & OSRF_METHOD_ATOMIC) &&
+ !(ctx->method->options & OSRF_METHOD_CACHABLE) ) {
+
if(complete)
osrfAppRequestRespondComplete( ctx->session, ctx->request, data );
else
osrfLog( OSRF_DEBUG, "Postprocessing method %s with retcode %d",
ctx->method->name, retcode );
- if(ctx->responses) { /* we have cached responses to return */
+ if(ctx->responses) { /* we have cached responses to return (no responses have been sent) */
osrfAppRequestRespondComplete( ctx->session, ctx->request, ctx->responses );
jsonObjectFree(ctx->responses);
static void __osrfAppSetIntrospectMethod( osrfMethodContext* ctx, osrfMethod* method, jsonObject* resp ) {
if(!(ctx && resp)) return;
+
jsonObjectSetKey(resp, "api_name", jsonNewObject(method->name));
jsonObjectSetKey(resp, "method", jsonNewObject(method->symbol));
jsonObjectSetKey(resp, "service", jsonNewObject(ctx->session->remote_service));
jsonObjectSetKey(resp, "notes", jsonNewObject(method->notes));
jsonObjectSetKey(resp, "argc", jsonNewNumberObject(method->argc));
- jsonObjectSetKey(resp, "params", jsonNewObject(method->paramNotes) );
- jsonObjectSetKey(resp, "sysmethod", jsonNewNumberObject(method->sysmethod) );
- jsonObjectSetKey(resp, "atomic", jsonNewNumberObject(method->atomic) );
- jsonObjectSetKey(resp, "cachable", jsonNewNumberObject(method->cachable) );
+
+ jsonObjectSetKey(resp, "sysmethod",
+ jsonNewNumberObject( (method->options & OSRF_METHOD_SYSTEM) ? 1 : 0 ));
+ jsonObjectSetKey(resp, "atomic",
+ jsonNewNumberObject( (method->options & OSRF_METHOD_ATOMIC) ? 1 : 0 ));
+ jsonObjectSetKey(resp, "cachable",
+ jsonNewNumberObject( (method->options & OSRF_METHOD_CACHABLE) ? 1 : 0 ));
+
jsonObjectSetClass(resp, "method");
}
#define OSRF_SYSMETHOD_ECHO "opensrf.system.echo"
#define OSRF_SYSMETHOD_ECHO_ATOMIC "opensrf.system.echo.atomic"
-//#define OSRF_METHOD_ATOMIC 1
-//#define OSRF_METHOD_CACHABLE 2
+#define OSRF_METHOD_SYSTEM 1
+#define OSRF_METHOD_STREAMING 2
+#define OSRF_METHOD_ATOMIC 4
+#define OSRF_METHOD_CACHABLE 8
struct _osrfApplicationStruct {
- //char* name; /* the name of our application */
void* handle; /* the lib handle */
osrfHash* methods;
- //struct _osrfMethodStruct* methods; /* list of methods */
-// struct _osrfApplicationStruct* next; /* next application */
};
typedef struct _osrfApplicationStruct osrfApplication;
char* symbol; /* the symbol name (function) */
char* notes; /* public method documentation */
int argc; /* how many args this method expects */
- char* paramNotes; /* Description of the params expected for this method */
-// struct _osrfMethodStruct* next; /* nest method in the list */
- int sysmethod; /* true if this is a system method */
- int streaming; /* true if this is a streamable method */
- int atomic; /* true if the method is an atomic method */
- int cachable; /* true if the method is cachable */
+ //char* paramNotes; /* Description of the params expected for this method */
+ int options; /* describes the various options for this method */
+
+ /*
+ int sysmethod;
+ int streaming;
+ int atomic;
+ int cachable;
+ */
};
typedef struct _osrfMethodStruct osrfMethod;
/**
Register a method
+ Any method with the OSRF_METHOD_STREAMING option set will have a ".atomic"
+ version of the method registered automatically
@param appName The name of the application that implements the method
@param methodName The fully qualified name of the method
@param symbolName The symbol name (function) that implements the method
@param notes Public documentation for this method.
- @params params String description description of the params expected
@params argc The number of arguments this method expects
@param streaming True if this is a streaming method that requires an atomic version
@return 0 on success, -1 on error
*/
int osrfAppRegisterMethod( char* appName, char* methodName,
- char* symbolName, char* notes, char* params, int argc, int streaming );
+ char* symbolName, char* notes, int argc, int options );
-int _osrfAppRegisterMethod( char* appName, char* methodName,
- char* symbolName, char* notes, char* params, int argc, int streaming, int system );
osrfMethod* _osrfAppBuildMethod( char* methodName,
- char* symbolName, char* notes, char* params, int argc, int sysmethod, int streaming );
-
-/**
- Registher a method
- @param appName The name of the application that implements the method
- @params desc The method description
- @return 0 on success, -1 on error
- */
-/*
-int osrfAppRegisterMethod( char* appName, osrfMethodDescription* desc );
-*/
+ char* symbolName, char* notes, int argc, int options );
/**
Finds the given app in the list of apps
} else {
+ fprintf(stderr, " * Running application %s\n", appname);
if( osrfAppRegisterApplication( appname, libfile ) == 0 )
osrf_prefork_run(appname);
/** daemonize me **/
- /* let our children do their thing */
+ /* background and let our children do their thing */
+ daemonize();
while(1) {
signal(SIGCHLD, __osrfSystemSignalHandler);
sleep(10000);
/** relaunch the server **/
}
+
+