Merge trunk changes to enable building acq and trunk on same box
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 9 Mar 2008 16:41:31 +0000 (16:41 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 9 Mar 2008 16:41:31 +0000 (16:41 +0000)
svn merge -r8456:8457 svn://svn.open-ils.org/ILS/trunk .
svn merge -r8498:8499 svn://svn.open-ils.org/ILS/trunk .
svn merge -r8547:8552 svn://svn.open-ils.org/ILS/trunk .

git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8935 dcc99617-32d9-48b4-a31d-7c20da2025e4

Makefile
Open-ILS/include/openils/oils_event.h
Open-ILS/include/openils/oils_utils.h
Open-ILS/src/c-apps/oils_dataloader.c
Open-ILS/src/c-apps/oils_event.c
Open-ILS/src/c-apps/oils_idl-core.c
Open-ILS/src/c-apps/oils_utils.c

index 57c2c84..a193e39 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,3 @@
-#!/bin/bash
 # vim:noet:ts=4
 # --------------------------------------------------------------------
 # Copyright (C) 2005  Georgia Public Library Service 
@@ -15,6 +14,8 @@
 # GNU General Public License for more details.
 # --------------------------------------------------------------------
 
+SHELL=/bin/bash
+
 all: build
 
 verbose:       oldconfig
index 64af307..e057386 100644 (file)
@@ -20,37 +20,36 @@ typedef struct _oilsEventStruct oilsEvent;
 
 
 /** Creates a new event.  User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent( char* file, int line, char* event );
+oilsEvent* oilsNewEvent( const char* file, int line, const char* event );
 
 /** Creates a new event with payload.  
  * User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent2( char* file, int line, char* event, jsonObject* payload );
+oilsEvent* oilsNewEvent2( const char* file, int line, const char* event,
+               const jsonObject* payload );
 
 /** Creates a new event with permission and permission location.  
  * User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent3( char* file, int line, char* event, char* perm, int permloc );
+oilsEvent* oilsNewEvent3( const char* file, int line, const char* event,
+               const char* perm, int permloc );
 
 /** Creates a new event with permission, permission location, and payload.  
  * User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent4( char* file, int line, 
-               char* event, char* perm, int permloc, jsonObject* payload );
+oilsEvent* oilsNewEvent4( const char* file, int line, const char* event,
+               const char* perm, int permloc, const jsonObject* payload );
 
 /** Sets the permission info for the event */
-void oilsEventSetPermission( oilsEvent* event, char* perm, int permloc );
+void oilsEventSetPermission( oilsEvent* event, const char* perm, int permloc );
 
 /* Sets the payload for the event 
  * This clones the payload, so the user is responsible
  * for handling the payload object's memory
  * */
-void oilsEventSetPayload( oilsEvent* event, jsonObject* payload );
+void oilsEventSetPayload( oilsEvent* event, const jsonObject* payload );
 
 /** Creates the JSON associated with an event.  The JSON should NOT be
  * freed by the user.  It will be freed by oilsEventFree */
 jsonObject* oilsEventToJSON( oilsEvent* event );
 
-/* Parses the events file */
-void _oilsEventParseEvents();
-
 /* Frees an event object */
 void oilsEventFree( oilsEvent* event );
 
index 64a785f..70fc84d 100644 (file)
@@ -17,7 +17,7 @@
   @param idl_filename If not provided, we'll fetch the 
   filename from the settings server
  */
-osrfHash* oilsInitIDL( char* idl_filename );
+osrfHash* oilsInitIDL( const char* idl_filename );
 
 /**
   Returns the string value for field 'field' in the given object.
index 60f844e..3ebe2f9 100644 (file)
 #define CSTORE "open-ils.cstore"
 #define APPNAME "oils_dataloader"
 
-#define ESUCCESS 0
-#define ECOMMITERROR -1
-#define ECOMMANDERROR -2
-#define EROLLBACKERROR -3
+#define E_SUCCESS 0
+#define E_COMMITERROR -1
+#define E_COMMANDERROR -2
+#define E_ROLLBACKERROR -3
 
-int sendCommand ( char* );
-int startTransaction ( );
-int commitTransaction ( );
-int rollbackTransaction ( );
+static int sendCommand ( const char* );
+static int startTransaction ( );
+static int commitTransaction ( );
+static int rollbackTransaction ( );
 
 
-osrfHash* mnames = NULL;
-osrfAppSession* session = NULL;
-char* trans_id = NULL;
+static osrfHash* mnames = NULL;
+static osrfAppSession* session = NULL;
+static char* trans_id = NULL;
 
 int main (int argc, char **argv) {
        if( argc < 4 ) {
@@ -80,12 +80,12 @@ int main (int argc, char **argv) {
                }
                buffer_fadd(_method_name, ".%s", method);
 
-               char* m = buffer_data(_method_name);
+               char* m = buffer_release(_method_name);
                osrfHashSet( mnames, m, classname );
 
                osrfLogDebug(OSRF_LOG_MARK, "Constructed %s method named %s for %s", method, m, classname);
 
-               buffer_free(_method_name);
+               free(_fm);
        }
 
        free(config);
@@ -124,11 +124,11 @@ int main (int argc, char **argv) {
                                        if (!rollbackTransaction()) {
                                                osrfAppSessionFree(session);
                                                osrfLogError(OSRF_LOG_MARK, "An error occured while attempting to complete a transaction");
-                                               return EROLLBACKERROR;
+                                               return E_ROLLBACKERROR;
                                        }
 
                                        osrfAppSessionFree(session);
-                                       return ECOMMANDERROR;
+                                       return E_COMMANDERROR;
                                }
 
                                counter++;
@@ -143,29 +143,30 @@ int main (int argc, char **argv) {
                }
        }
 
+       buffer_free(json);
+
        // clean up, commit, go away
        if (!commitTransaction()) {
                osrfLogError(OSRF_LOG_MARK, "An error occured while attempting to complete a transaction");
                osrfAppSessionFree(session);
-               return ECOMMITERROR;
+               return E_COMMITERROR;
        }
 
        osrfAppSessionFree(session);
        free(method);
 
-       return ESUCCESS;
+       return E_SUCCESS;
 }
 
-int commitTransaction () {
+static int commitTransaction () {
        int ret = 1;
-       jsonObject* data;
+       const jsonObject* data;
        int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.commit", 1, NULL );
        osrf_message* res = osrfAppSessionRequestRecv( session, req_id, 5 );
-       if ( (data = jsonObjectClone(osrfMessageGetResult(res))) ) {
+       if ( (data = osrfMessageGetResult(res)) ) {
                if(!(trans_id = jsonObjectGetString(data))) {
                        ret = 0;
                }
-               jsonObjectFree(data);
        } else {
                ret = 0;
        }
@@ -174,16 +175,15 @@ int commitTransaction () {
        return ret;
 }
 
-int rollbackTransaction () {
+static int rollbackTransaction () {
        int ret = 1;
-       jsonObject* data;
+       const jsonObject* data;
        int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.rollback", 1, NULL );
        osrf_message* res = osrfAppSessionRequestRecv( session, req_id, 5 );
-       if ( (data = jsonObjectClone(osrfMessageGetResult(res))) ) {
+       if ( (data = osrfMessageGetResult(res)) ) {
                if(!(trans_id = jsonObjectGetString(data))) {
                        ret = 0;
                }
-               jsonObjectFree(data);
        } else {
                ret = 0;
        }
@@ -192,7 +192,7 @@ int rollbackTransaction () {
        return ret;
 }
 
-int startTransaction () {
+static int startTransaction () {
        int ret = 1;
        jsonObject* data;
        int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.begin", 1, NULL );
@@ -209,7 +209,7 @@ int startTransaction () {
        return ret;
 }
 
-int sendCommand ( char* json ) {
+static int sendCommand ( const char* json ) {
        int ret = 1;
        jsonObject* item = jsonParseString(json);
 
index 135bd40..bc9b737 100644 (file)
@@ -3,65 +3,82 @@
 #include <libxml/tree.h>
 #include "opensrf/osrf_settings.h"
 
-osrfHash* __oilsEventEvents = NULL;
-osrfHash* __oilsEventDescriptions = NULL;
+static void _oilsEventParseEvents();
 
-oilsEvent* oilsNewEvent( char* file, int line, char* event ) {
+// The following two osrfHashes are created when we
+// create the first osrfEvent, and are never freed.
+
+static osrfHash* _oilsEventEvents = NULL;
+static osrfHash* _oilsEventDescriptions = NULL;
+
+oilsEvent* oilsNewEvent( const char* file, int line, const char* event ) {
        if(!event) return NULL;
        osrfLogInfo(OSRF_LOG_MARK, "Creating new event: %s", event);
-       if(!__oilsEventEvents) _oilsEventParseEvents();
-       oilsEvent* evt =  (oilsEvent*) safe_malloc(sizeof(oilsEvent));
+       if(!_oilsEventEvents) _oilsEventParseEvents();
+       oilsEvent* evt = safe_malloc(sizeof(oilsEvent));
        evt->event = strdup(event);
+       evt->perm = NULL;
        evt->permloc = -1;
+       evt->payload = NULL;
+       evt->json = NULL;
        if(file) evt->file = strdup(file);
+       else evt->file = NULL;
        evt->line = line;
        return evt;
 }
 
-oilsEvent* oilsNewEvent2( char* file, int line, char* event, jsonObject* payload ) {
+oilsEvent* oilsNewEvent2( const char* file, int line, const char* event,
+               const jsonObject* payload ) {
        oilsEvent* evt = oilsNewEvent(file, line, event);
-       oilsEventSetPayload(evt, payload);
+       if(payload) evt->payload = jsonObjectClone(payload);
        return evt;
 }
 
-oilsEvent* oilsNewEvent3( char* file, int line, char* event, char* perm, int permloc ) {
+oilsEvent* oilsNewEvent3( const char* file, int line, const char* event,
+               const char* perm, int permloc ) {
        oilsEvent* evt = oilsNewEvent(file, line, event);
-       oilsEventSetPermission( evt, perm, permloc );
+       if(perm) {
+               evt->perm = strdup(perm);
+               evt->permloc = permloc;
+       }
        return evt;
 }
 
-oilsEvent* oilsNewEvent4( char* file, int line, 
-                       char* event, char* perm, int permloc, jsonObject* payload ) {
+oilsEvent* oilsNewEvent4( const char* file, int line, const char* event,
+               const char* perm, int permloc, const jsonObject* payload ) {
        oilsEvent* evt = oilsNewEvent3( file, line, event, perm, permloc );
-       if(evt) oilsEventSetPayload( evt, payload );
+       if(payload) evt->payload = jsonObjectClone(payload);
        return evt;
 }
 
-void oilsEventSetPermission( oilsEvent* event, char* perm, int permloc ) {
+void oilsEventSetPermission( oilsEvent* event, const char* perm, int permloc ) {
        if(!(event && perm)) return;
+       if(event->perm) free(event->perm);
        event->perm = strdup(perm);
        event->permloc = permloc;
 }
 
-void oilsEventSetPayload( oilsEvent* event, jsonObject* payload ) {
+void oilsEventSetPayload( oilsEvent* event, const jsonObject* payload ) {
        if(!(event && payload)) return;
+       if(event->payload) jsonObjectFree(event->payload);
        event->payload = jsonObjectClone(payload);
 }
 
 
 void oilsEventFree( oilsEvent* event ) {
        if(!event) return;
+       free(event->event);
        free(event->perm);
        free(event->file);
        if(event->json) jsonObjectFree(event->json);
-       else jsonObjectFree(event->payload);
+       if(event->payload) jsonObjectFree(event->payload);
        free(event);
 }
 
 
 jsonObject* oilsEventToJSON( oilsEvent* event ) {
        if(!event) return NULL;
-       char* code = osrfHashGet( __oilsEventEvents, event->event );
+       char* code = osrfHashGet( _oilsEventEvents, event->event );
 
        if(!code) {
                osrfLogError(OSRF_LOG_MARK,  "No such event name: %s", event->event );
@@ -71,7 +88,7 @@ jsonObject* oilsEventToJSON( oilsEvent* event ) {
 
        char* lang = "en-US"; /* assume this for now */
        char* desc = NULL;
-       osrfHash* h = osrfHashGet(__oilsEventDescriptions, lang);
+       osrfHash* h = osrfHashGet(_oilsEventDescriptions, lang);
        if(h) {
                osrfLogDebug(OSRF_LOG_MARK, "Loaded event lang hash for %s",lang);
                desc = osrfHashGet(h, code);
@@ -93,12 +110,14 @@ jsonObject* oilsEventToJSON( oilsEvent* event ) {
        if(event->perm) jsonObjectSetKey( json, "ilsperm", jsonNewObject(event->perm) );
        if(event->permloc != -1) jsonObjectSetKey( json, "ilspermloc", jsonNewNumberObject(event->permloc) );
        if(event->payload) jsonObjectSetKey( json, "payload", event->payload );
+       
+       if(event->json) jsonObjectFree(event->json);
        event->json = json;
        return json;
 }
 
-
-void _oilsEventParseEvents() {
+/* Parses the events file */
+static void _oilsEventParseEvents() {
        
        char* xml = osrf_settings_host_value("/ils_events");
 
@@ -110,8 +129,8 @@ void _oilsEventParseEvents() {
        xmlDocPtr doc = xmlParseFile(xml);
        free(xml);
        int success = 0;
-       __oilsEventEvents = osrfNewHash();
-       __oilsEventDescriptions = osrfNewHash();
+       _oilsEventEvents = osrfNewHash();
+       _oilsEventDescriptions = osrfNewHash();
 
        if( doc ) {
                xmlNodePtr root = xmlDocGetRootElement(doc);
@@ -122,7 +141,7 @@ void _oilsEventParseEvents() {
                                        xmlChar* code = xmlGetProp( child, BAD_CAST "code");
                                        xmlChar* textcode = xmlGetProp( child, BAD_CAST "textcode");
                                        if( code && textcode ) {
-                                               osrfHashSet( __oilsEventEvents, code, (char*) textcode );
+                                               osrfHashSet( _oilsEventEvents, code, (char*) textcode );
                                                success = 1;
                                        }
 
@@ -136,10 +155,10 @@ void _oilsEventParseEvents() {
                                                        if(lang) {
                                                                osrfLogDebug(OSRF_LOG_MARK, "Loaded event lang: %s", (char*) lang);
                                                                osrfHash* langHash = osrfHashGet(
-                                                                       __oilsEventDescriptions, (char*) lang);
+                                                                       _oilsEventDescriptions, (char*) lang);
                                                                if(!langHash) {
                                                                        langHash = osrfNewHash();
-                                                                       osrfHashSet(__oilsEventDescriptions, langHash, (char*) lang);
+                                                                       osrfHashSet(_oilsEventDescriptions, langHash, (char*) lang);
                                                                }
                                                                char* content;
                                                                if( desc->children && (content = (char*) desc->children->content) ) {
index 5994e13..8b8184d 100644 (file)
@@ -87,6 +87,7 @@ osrfHash* oilsIDLInit( const char* idl_filename ) {
                                                osrfStringArrayAdd(controller, strdup(_controller_class));
                                        }
                                }
+                               free(controller_list);
                        }
                        osrfHashSet( usrData, controller, "controller");
 
@@ -245,6 +246,7 @@ osrfHash* oilsIDLInit( const char* idl_filename ) {
                                                                        osrfStringArrayAdd(map, strdup(_map_class));
                                                                }
                                                        }
+                                                       free(map_list);
                                                }
                                                osrfHashSet( _tmp, map, "map");
 
@@ -283,11 +285,11 @@ osrfHash* oilsIDLInit( const char* idl_filename ) {
                                }
 
                                _cur = _cur->next;
-                       }
+                       } // end while
                }
 
                kid = kid->next;
-       }
+       } // end while
 
        osrfLogInfo(OSRF_LOG_MARK, "...IDL XML parsed");
 
index db25e42..6743b52 100644 (file)
@@ -1,27 +1,32 @@
 #include "openils/oils_utils.h"
 #include "openils/oils_idl.h"
 
-osrfHash* oilsInitIDL(char* idl_filename) {
+osrfHash* oilsInitIDL(const char* idl_filename) {
 
-    int freeme = 0;
-    if(!idl_filename) {
-           idl_filename = osrf_settings_host_value("/IDL");
-        freeme = 1;
-    }
+       char* freeable_filename = NULL;
+       const char* filename;
 
-       if (!idl_filename) {
+       if(idl_filename)
+               filename = idl_filename;
+       else {
+               freeable_filename = osrf_settings_host_value("/IDL");
+               filename = freeable_filename;
+       }
+
+       if (!filename) {
                osrfLogError(OSRF_LOG_MARK, "No settings config for '/IDL'");
                return NULL;
        }
 
-    osrfLogInfo(OSRF_LOG_MARK, "Parsing IDL %s", idl_filename);
+       osrfLogInfo(OSRF_LOG_MARK, "Parsing IDL %s", filename);
 
-       if (!oilsIDLInit( idl_filename )) {
-               osrfLogError(OSRF_LOG_MARK, "Problem loading IDL file [%s]!", idl_filename);
+       if (!oilsIDLInit( filename )) {
+               osrfLogError(OSRF_LOG_MARK, "Problem loading IDL file [%s]!", filename);
+               if(freeable_filename) free(freeable_filename);
                return NULL;
        }
 
-    if(freeme) free(idl_filename);
+       if(freeable_filename) free(freeable_filename);
        return oilsIDL();
 }
 
@@ -143,6 +148,7 @@ jsonObject* oilsUtilsFetchUserByBarcode(const char* barcode) {
        if(!card) { jsonObjectFree(params); return NULL; }
 
        char* usr = oilsFMGetString(card, "usr");
+       jsonObjectFree(card);
        if(!usr) return NULL;
        double iusr = strtod(usr, NULL);
        free(usr);