added pid and basic stacktrace to the C event handler
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 May 2006 12:57:33 +0000 (12:57 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 May 2006 12:57:33 +0000 (12:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4063 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/c-apps/oils_auth.c
Open-ILS/src/c-apps/oils_event.c
Open-ILS/src/c-apps/oils_event.h
Open-ILS/src/c-apps/oils_utils.c
Open-ILS/src/extras/ils_events.xml

index 63bf82b..a9c8d25 100644 (file)
@@ -285,7 +285,7 @@ oilsEvent* oilsAuthHandleLoginOK(
        jsonObject* payload = jsonParseString(
                "{ \"authtoken\": \"%s\", \"authtime\": %lf }", authToken, timeout );
 
-       response = oilsNewEvent2( OILS_EVENT_SUCCESS, payload );
+       response = oilsNewEvent2( OSRF_LOG_MARK, OILS_EVENT_SUCCESS, payload );
        free(string); free(authToken); free(authKey);
        jsonObjectFree(payload);
 
@@ -296,7 +296,7 @@ oilsEvent* oilsAuthVerifyWorkstation(
                osrfMethodContext* ctx, jsonObject* userObj, char* ws ) {
        osrfLogInfo(OSRF_LOG_MARK, "Attaching workstation to user at login: %s", ws);
        jsonObject* workstation = oilsUtilsFetchWorkstationByName(ws);
-       if(!workstation) return oilsNewEvent("WORKSTATION_NOT_FOUND");
+       if(!workstation) return oilsNewEvent(OSRF_LOG_MARK, "WORKSTATION_NOT_FOUND");
        long wsid = oilsFMGetObjectId(workstation);
        LONG_TO_STRING(wsid);
        char* orgid = oilsFMGetString(workstation, "owning_lib");
@@ -336,7 +336,7 @@ int oilsAuthComplete( osrfMethodContext* ctx ) {
        else if(barcode) userObj = oilsUtilsFetchUserByBarcode( barcode );
        
        if(!userObj) { 
-               response = oilsNewEvent( OILS_EVENT_AUTH_FAILED );
+               response = oilsNewEvent( OSRF_LOG_MARK, OILS_EVENT_AUTH_FAILED );
                osrfAppRespondComplete( ctx, oilsEventToJSON(response) ); 
                oilsEventFree(response);
                free(barcode);
@@ -384,7 +384,7 @@ int oilsAuthComplete( osrfMethodContext* ctx ) {
                response = oilsAuthHandleLoginOK( userObj, uname, type, orgloc );
 
        } else {
-               response = oilsNewEvent( OILS_EVENT_AUTH_FAILED );
+               response = oilsNewEvent( OSRF_LOG_MARK, OILS_EVENT_AUTH_FAILED );
                osrfLogInfo(OSRF_LOG_MARK,  "Login failed for for %s", uname );
        }
 
@@ -432,14 +432,14 @@ oilsEvent*  _oilsAuthResetTimeout( char* authToken ) {
 
        if(!cacheObj) {
                osrfLogError(OSRF_LOG_MARK, "No user in the cache exists with key %s", key);
-               evt = oilsNewEvent(OILS_EVENT_NO_SESSION);
+               evt = oilsNewEvent(OSRF_LOG_MARK, OILS_EVENT_NO_SESSION);
 
        } else {
 
                timeout = jsonObjectGetNumber( jsonObjectGetKey( cacheObj, "authtime"));
                osrfCacheSetExpire( timeout, key );
                jsonObject* payload = jsonNewNumberObject(timeout);
-               evt = oilsNewEvent2(OILS_EVENT_SUCCESS, payload);
+               evt = oilsNewEvent2(OSRF_LOG_MARK, OILS_EVENT_SUCCESS, payload);
                jsonObjectFree(payload);
                jsonObjectFree(cacheObj);
        }
@@ -482,7 +482,7 @@ int oilsAuthSessionRetrieve( osrfMethodContext* ctx ) {
                                osrfAppRespondComplete( ctx, jsonObjectGetKey( cacheObj, "userobj"));
                                jsonObjectFree(cacheObj);
                        } else {
-                               oilsEvent* evt = oilsNewEvent(OILS_EVENT_NO_SESSION);
+                               oilsEvent* evt = oilsNewEvent(OSRF_LOG_MARK, OILS_EVENT_NO_SESSION);
                                osrfAppRespondComplete( ctx, oilsEventToJSON(evt) ); /* should be event.. */
                                oilsEventFree(evt);
                        }
@@ -491,7 +491,7 @@ int oilsAuthSessionRetrieve( osrfMethodContext* ctx ) {
 
        } else {
 
-               evt = oilsNewEvent(OILS_EVENT_NO_SESSION);
+               evt = oilsNewEvent(OSRF_LOG_MARK, OILS_EVENT_NO_SESSION);
                osrfAppRespondComplete( ctx, oilsEventToJSON(evt) );
                oilsEventFree(evt);
        }
index 86e1acd..3b086ce 100644 (file)
@@ -6,30 +6,33 @@
 osrfHash* __oilsEventEvents = NULL;
 osrfHash* __oilsEventDescriptions = NULL;
 
-oilsEvent* oilsNewEvent( char* event ) {
+oilsEvent* oilsNewEvent( char* file, int line, 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));
        evt->event = strdup(event);
        evt->permloc = -1;
+       if(file) evt->file = strdup(file);
+       evt->line = line;
        return evt;
 }
 
-oilsEvent* oilsNewEvent2( char* event, jsonObject* payload ) {
-       oilsEvent* evt = oilsNewEvent(event);
+oilsEvent* oilsNewEvent2( char* file, int line, char* event, jsonObject* payload ) {
+       oilsEvent* evt = oilsNewEvent(file, line, event);
        oilsEventSetPayload(evt, payload);
        return evt;
 }
 
-oilsEvent* oilsNewEvent3( char* event, char* perm, int permloc ) {
-       oilsEvent* evt = oilsNewEvent(event);
+oilsEvent* oilsNewEvent3( char* file, int line, char* event, char* perm, int permloc ) {
+       oilsEvent* evt = oilsNewEvent(file, line, event);
        oilsEventSetPermission( evt, perm, permloc );
        return evt;
 }
 
-oilsEvent* oilsNewEvent4( char* event, char* perm, int permloc, jsonObject* payload ) {
-       oilsEvent* evt = oilsNewEvent3( event, perm, permloc );
+oilsEvent* oilsNewEvent4( char* file, int line, 
+                       char* event, char* perm, int permloc, jsonObject* payload ) {
+       oilsEvent* evt = oilsNewEvent3( file, line, event, perm, permloc );
        if(evt) oilsEventSetPayload( evt, payload );
        return evt;
 }
@@ -49,6 +52,7 @@ void oilsEventSetPayload( oilsEvent* event, jsonObject* payload ) {
 void oilsEventFree( oilsEvent* event ) {
        if(!event) return;
        free(event->perm);
+       free(event->file);
        if(event->json) jsonObjectFree(event->json);
        else jsonObjectFree(event->payload);
        free(event);
@@ -79,6 +83,12 @@ jsonObject* oilsEventToJSON( oilsEvent* event ) {
        jsonObjectSetKey( json, "ilsevent", jsonNewNumberObject(atoi(code)) );
        jsonObjectSetKey( json, "textcode", jsonNewObject(event->event) );
        jsonObjectSetKey( json, "desc", jsonNewObject(desc) );
+       jsonObjectSetKey( json, "pid", jsonNewNumberObject(getpid()) );
+
+       char buf[256];
+       memset(buf,0, 256);
+       snprintf(buf, 256, "%s:%d", event->file, event->line);
+       jsonObjectSetKey( json, "stacktrace", jsonNewObject(buf) );
 
        if(event->perm) jsonObjectSetKey( json, "ilsperm", jsonNewObject(event->perm) );
        if(event->permloc != -1) jsonObjectSetKey( json, "ilspermloc", jsonNewNumberObject(event->permloc) );
index 0ed9f7d..64af307 100644 (file)
@@ -13,24 +13,27 @@ struct _oilsEventStruct {
        int permloc;                    /* the permission location id */
        jsonObject* payload;    /* the payload */
        jsonObject* json;               /* the event as a jsonObject */
+       char* file;
+       int line;
 };
 typedef struct _oilsEventStruct oilsEvent;
 
 
 /** Creates a new event.  User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent( char* event );
+oilsEvent* oilsNewEvent( char* file, int line, char* event );
 
 /** Creates a new event with payload.  
  * User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent2( char* event, jsonObject* payload );
+oilsEvent* oilsNewEvent2( char* file, int line, char* event, jsonObject* payload );
 
 /** Creates a new event with permission and permission location.  
  * User is responsible for freeing event with oilsEventFree */
-oilsEvent* oilsNewEvent3( char* event, char* perm, int permloc );
+oilsEvent* oilsNewEvent3( char* file, int line, char* event, 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* event, char* perm, int permloc, jsonObject* payload );
+oilsEvent* oilsNewEvent4( char* file, int line, 
+               char* event, char* perm, int permloc, jsonObject* payload );
 
 /** Sets the permission info for the event */
 void oilsEventSetPermission( oilsEvent* event, char* perm, int permloc );
index b356348..a56c87d 100644 (file)
@@ -53,7 +53,7 @@ oilsEvent* oilsUtilsCheckPerms( int userid, int orgid, char* permissions[], int
                char* r = jsonObjectToSimpleString(o);
 
                if(r && !strcmp(r, "0")) 
-                       evt = oilsNewEvent3( OILS_EVENT_PERM_FAILURE, perm, orgid );
+                       evt = oilsNewEvent3( OSRF_LOG_MARK, OILS_EVENT_PERM_FAILURE, perm, orgid );
 
                jsonObjectFree(params);
                jsonObjectFree(o);
index 7f0fa55..bb25cd3 100644 (file)
@@ -11,7 +11,7 @@
        </notes>
 
        <event code='0' textcode='SUCCESS'>
-               <desc xml:lang="en-US">No errors or unexpected events occurred</desc>
+               <desc xml:lang="en-US"> </desc>
        </event>
        <event code='1' textcode='UNKNOWN'>
                <desc xml:lang="en-US">Placeholder event.  Used for development only</desc>