-CC_OPTS += -DASSUME_STATELESS
-EXE_LD_OPTS += -lxml2 -lopensrf_transport -lopensrf_stack -lobjson -lc_utils
+CC_OPTS += -DASSUME_STATELESS
+LD_OPTS += -lxml2 -lopensrf_transport -lopensrf_stack -lobjson -lc_utils
-SOURCES = osrf_message.c osrf_app_session.c osrf_stack.c osrf_system.c osrf_config.c
-TARGETS = osrf_message.o osrf_app_session.o osrf_stack.o osrf_system.o osrf_config.o
-HEADERS = osrf_message.h osrf_app_session.h osrf_stack.h osrf_system.h osrf_config.h
+SOURCES = osrf_message.c osrf_app_session.c osrf_stack.c osrf_system.c osrf_config.c osrf_settings.c
+TARGETS = osrf_message.o osrf_app_session.o osrf_stack.o osrf_system.o osrf_config.o osrf_settings.o
+HEADERS = osrf_message.h osrf_app_session.h osrf_stack.h osrf_system.h osrf_config.h osrf_settings.h
-all: msg libopensrf_stack.so
+all: msg libopensrf_stack.so test
msg:
echo "-> $$(pwd)"
+test: test.o
+ echo $@
+ $(CC) $(LD_OPTS) test.o xml_utils.o -o $@
+
+test.o: test.c xml_utils.o
+ echo $@
+ $(CC) -c $(CC_OPTS) test.c -o $@
+
+xml_utils.o:
+ echo $@
+ cp ../utils/xml_utils.h .
+ cp ../utils/xml_utils.c .
+ $(CC) -c $(CC_OPTS) xml_utils.c -o $@
+
+# -------------------------------------------------------------
+
+
libopensrf_stack.so: $(TARGETS)
echo $@
$(CC) -shared -W1 $(TARGETS) -o libopensrf_stack.so
osrf_config.o: osrf_config.c osrf_config.h
echo $@; $(CC) -c $(CC_OPTS) osrf_config.c -o $@
+osrf_settings.o: osrf_settings.c osrf_settings.h
+ echo $@; $(CC) -c $(CC_OPTS) osrf_settings.c -o $@
+
install:
echo installing libopensrf_stack.so
cp $(HEADERS) $(INCLUDEDIR)/$(OPENSRF)
cp $(TMPDIR)/libopensrf_stack.so $(LIBDIR)/
clean:
- /bin/rm -f *.o libopensrf_stack.so
+ /bin/rm -f *.o libopensrf_stack.so test
#include "osrf_config.h"
-//object* config_object = NULL;
-
-/*
-char* osrf_config_value(char* path) {
-}
-
-
-void _osrf_config_grab_config() {
- if(config_object) return;
-}
-*/
-
-
void config_reader_init( char* name, char* config_file ) {
if( name == NULL || config_file == NULL || strlen(config_file) == 0 ) {
#include "osrf_system.h"
transport_client* global_client;
+char* system_config = NULL;
transport_client* osrf_system_get_transport_client() {
return global_client;
int osrf_system_bootstrap_client( char* config_file, char* contextnode ) {
- if( config_file == NULL )
+ if( !config_file || !contextnode )
fatal_handler("No Config File Specified\n" );
+ free(system_config);
+ free(osrf_config_context);
+ system_config = strdup(config_file);
+ osrf_config_context = strdup(contextnode);
+
config_reader_init( "opensrf.bootstrap", config_file );
-
- osrf_config_context = contextnode;
char* log_file = config_value( "opensrf.bootstrap", "//%s/logfile", contextnode );
char* log_level = config_value( "opensrf.bootstrap", "//%s/loglevel", contextnode );
return 0;
}
-int osrf_system_shutdown() {
- config_reader_free();
- log_free();
+int osrf_system_disconnect_client() {
client_disconnect( global_client );
client_free( global_client );
global_client = NULL;
+ return 0;
+}
+
+int osrf_system_shutdown() {
+ config_reader_free();
+ osrf_system_disconnect_client();
+ free(system_config);
+ free(osrf_config_context);
+ osrf_settings_free_host_config(NULL);
+ log_free();
return 1;
}
#include "utils.h"
#include "logging.h"
#include "osrf_config.h"
+//#include "osrf_settings.h"
#ifndef OSRF_SYSTEM_H
#define OSRF_SYSTEM_H
int osrf_system_bootstrap_client( char* config_file, char* contextnode );
transport_client* osrf_system_get_transport_client();
+/* disconnects and destroys the current client connection */
+int osrf_system_disconnect_client();
int osrf_system_shutdown();
session->parser_ctxt = xmlCreatePushParserCtxt(SAXHandler, session, "", 0, NULL);
/* initialize the transport_socket structure */
- //session->sock_obj = (transport_socket*) safe_malloc( sizeof(transport_socket) );
session->sock_mgr = (socket_manager*) safe_malloc( sizeof(socket_manager) );
- //int serv_size = strlen( server );
-/*
- session->sock_obj->server = server;
- session->sock_obj->port = port;
- session->sock_obj->data_received_callback = &grab_incoming;
-*/
-
session->sock_mgr->data_received = &grab_incoming;
session->sock_mgr->blob = session;
session->port = port;
session->server = strdup(server);
- if(unix_path)
+ if(unix_path)
session->unix_path = strdup(unix_path);
- session->unix_path = NULL;
+ else session->unix_path = NULL;
session->sock_id = 0;
- /* this will be handed back to us in callbacks */
- //session->sock_obj->user_data = session;
-
return session;
}
int session_free( transport_session* session ) {
if( ! session ) { return 0; }
- //if( session->sock_obj )
- // free( session->sock_obj );
-
if(session->sock_mgr)
socket_manager_free(session->sock_mgr);
if( session->state_machine ) free( session->state_machine );
if( session->parser_ctxt) {
- xmlCleanupCharEncodingHandlers();
xmlFreeDoc( session->parser_ctxt->myDoc );
xmlFreeParserCtxt(session->parser_ctxt);
}
+
+ xmlCleanupCharEncodingHandlers();
+ xmlDictCleanup();
xmlCleanupParser();
buffer_free(session->body_buffer);
char* t = buf;
char* tt = tokbuf;
+ /* copy the path before strtok_r destroys it */
char* pathcopy = strdup(buf);
/* grab the root of the path */
token = strtok_r(t, "/", &tt);
- t = NULL;
if(!token) return NULL;
/* special case where path starts with // (start anywhere) */
free(pathcopy);
+ t = NULL;
do {
obj = obj->get_key(obj, token);
} while( (token = strtok_r(NULL, "/", &tt)) && obj);
object* _object_find_path_recurse(object* obj, char* root, char* path) {
if(!obj || ! root) return NULL;
+
+ /* collect all of the potential objects */
object* arr = __object_find_path_recurse(obj, root);
- object* newarr = json_parse_string("[]");
+ /* container for fully matching objects */
+ object* newarr = json_parse_string("[]");
int i;
/* path is just /root or /root/ */
if( strlen(root) + 2 >= strlen(path) ) {
return arr;
+
} else {
+ /* gather all of the sub-objects that match the full path */
for( i = 0; i < arr->size; i++ ) {
- /*
- fprintf(stderr, "Searching root %s and path %s and size %ld\n", root, path + strlen(root) + 1, arr->size);
- */
object* a = arr->get_index(arr, i);
object* thing = object_find_path(a , path + strlen(root) + 1);
if(thing) newarr->push(newarr, thing);
object* arr = json_parse_string("[]");
if(!obj) return arr;
+
+ int i;
+
+ /* if the current object has a node that matches, add it */
object* o = obj->get_key(obj, root);
if(o) arr->push(arr, object_clone(o));
object* childarr;
object_iterator* itr = new_iterator(obj);
+ /* recurse through the children and find all potential nodes */
while( (tmp = itr->next(itr)) ) {
childarr = __object_find_path_recurse(tmp->item, root);
if(childarr && childarr->size > 0) {
- int i;
for( i = 0; i!= childarr->size; i++ ) {
arr->push(arr, object_clone(childarr->get_index(childarr, i)));
}
}
-
free_object(childarr);
}
object* object_clone(object* o);
+/* ------------------------------------------------------------------------ */
+/* XPATH */
+
/* provide an XPATH style path (e.g. /some/node/here) and this will
return the object at that location if one exists. Naturally,
every element in the path must be a proper object ("hash" / {}).
object* object_find_path(object* obj, char* format, ...);
-/* returns an object array of matches */
+/* Utility method. finds any object in the tree that matches the path.
+ Use this for finding paths that start with '//' */
object* _object_find_path_recurse(object* obj, char* root, char* path);
+
+/* returns a list of object whose key is 'root'. These are used as
+ potential objects when doing a // search */
object* __object_find_path_recurse(object* obj, char* root);
+/* ------------------------------------------------------------------------ */
#endif
# ------------------------------------------------------------------------
-LD_OPTS += -lc_utils
-CC_OPTS -= -Wall
-
UTIL_SOURCES = logging.c utils.c socket_bundle.c md5.c sha.c string_array.c
UTIL_HEADERS = logging.h utils.h socket_bundle.h md5.h sha.h string_array.h
UTIL_OBJECTS = logging.o utils.o socket_bundle.o md5.o sha.o string_array.o
-all: msg libc_utils.so
+all: msg libc_utils.so
msg:
echo "-> $$(pwd)"
+
install:
echo installing libc_utils.so
cp $(UTIL_HEADERS) $(INCLUDEDIR)/
@echo $@
$(CC) -c $(CC_OPTS) string_array.c -o $@
+
clean:
- /bin/rm -f *.o socket_test libc_utils.so
+ /bin/rm -f *.o socket_test libc_utils.so test