[OpenSRF-GIT] OpenSRF branch master updated. 37606bf64f2829258cc612e730782e081e2ac6bb

Evergreen Git git at git.evergreen-ils.org
Wed Mar 7 14:46:13 EST 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".

The branch, master has been updated
       via  37606bf64f2829258cc612e730782e081e2ac6bb (commit)
       via  26c31a9d5728adbd884a1369034caff41471130b (commit)
       via  7ec92808fea116ead923e475ad5242a54b688798 (commit)
       via  b12de37f9480c68b1c8b033da18c3cc0d0ebc8f0 (commit)
      from  67d4d5de8656128f32b20f4c04dbf81a1028e929 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 37606bf64f2829258cc612e730782e081e2ac6bb
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Jan 13 10:57:59 2012 -0500

    Python libs for OpenSRF ingress tracking
    
    osrf.ses.Session.ingress(ingress)
    
    This also set the "srfsh" ingress value for srfsh.py.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/src/python/osrf/ses.py b/src/python/osrf/ses.py
index 15e1f10..6fd2d24 100644
--- a/src/python/osrf/ses.py
+++ b/src/python/osrf/ses.py
@@ -25,7 +25,7 @@ import random, os, time, threading
 # -----------------------------------------------------------------------
 # Go ahead and register the common network objects
 # -----------------------------------------------------------------------
-osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload'], 'hash')
+osrf.net_obj.register_hint('osrfMessage', ['threadTrace', 'locale', 'type', 'payload', 'ingress'], 'hash')
 osrf.net_obj.register_hint('osrfMethod', ['method', 'params'], 'hash')
 osrf.net_obj.register_hint('osrfResult', ['status', 'statusCode', 'content'], 'hash')
 osrf.net_obj.register_hint('osrfConnectStatus', ['status', 'statusCode'], 'hash')
@@ -37,6 +37,7 @@ class Session(object):
 
     ''' Global cache of in-service sessions '''
     session_cache = {}
+    current_ingress = 'opensrf';
 
     def __init__(self):
         # by default, we're connected to no one
@@ -52,6 +53,12 @@ class Session(object):
             return Session.session_cache[thread]
         return ServerSession(thread)
 
+    @staticmethod
+    def ingress(ingress):
+        if ingress:
+            Session.current_ingress = ingress
+        return Session.current_ingress
+
     def set_remote_id(self, remoteid):
         self.remote_id = remoteid
         osrf.log.log_internal("Setting request remote ID to %s" % self.remote_id)
@@ -66,6 +73,9 @@ class Session(object):
         """Sends an OpenSRF message"""
         if not isinstance(omessages, list):
             omessages = [omessages]
+
+        for msg in omessages:
+            msg.ingress(Session.current_ingress);
             
         net_msg = osrf.net.NetworkMessage(
             recipient      = self.remote_id,
diff --git a/src/python/osrf/stack.py b/src/python/osrf/stack.py
index cc5a4dc..ddecf69 100644
--- a/src/python/osrf/stack.py
+++ b/src/python/osrf/stack.py
@@ -43,6 +43,8 @@ def handle_message(session, message):
     osrf.log.log_internal("handle_message(): processing message of "
         "type %s" % message.type())
 
+    osrf.ses.Session.ingress(message.ingress())
+
     if isinstance(session, osrf.ses.ClientSession):
         handle_client(session, message)
     else:
diff --git a/src/python/srfsh.py b/src/python/srfsh.py
index ba90c7a..5dfc8ee 100755
--- a/src/python/srfsh.py
+++ b/src/python/srfsh.py
@@ -410,6 +410,7 @@ class Srfsh(object):
     def do_connect(self):
         ''' Connects this instance to the OpenSRF network. '''
 
+        osrf.ses.Session.ingress('srfsh')
         file = os.path.join(self.get_var('HOME'), ".srfsh.xml")
         osrf.system.System.connect(config_file=file, config_context='srfsh')
 

commit 26c31a9d5728adbd884a1369034caff41471130b
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Jan 13 09:35:18 2012 -0500

    Set OpenSRF ingress value for srfsh/gateways
    
    Sets the "srfsh", "gateway-v1", and "translator-v1" ingress values
    accordingly.
    
    For the translater, it's necessary to stamp the unpacked messages with
    the updated ingress, then re-serialize before sending the messages along.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/src/gateway/osrf_http_translator.c b/src/gateway/osrf_http_translator.c
index 77189cc..e945689 100644
--- a/src/gateway/osrf_http_translator.c
+++ b/src/gateway/osrf_http_translator.c
@@ -23,6 +23,7 @@
 #define JSON_CONTENT_TYPE "text/plain"
 #define MAX_MSGS_PER_PACKET 256
 #define CACHE_TIME 300
+#define TRANSLATOR_INGRESS "translator-v1"
 
 #define OSRF_HTTP_HEADER_TO "X-OpenSRF-to"
 #define OSRF_HTTP_HEADER_XID "X-OpenSRF-xid"
@@ -240,35 +241,24 @@ static int osrfHttpTranslatorSetTo(osrfHttpTranslator* trans) {
 }
 
 /**
- * Parses the request body and logs any REQUEST messages to the activity log
+ * Parses the request body, logs any REQUEST messages to the activity log, 
+ * stamps the translator ingress on each message, and returns the updated 
+ * messages as a JSON string.
  */
-static int osrfHttpTranslatorParseRequest(osrfHttpTranslator* trans) {
-    const osrfMessage* msg;
+static char* osrfHttpTranslatorParseRequest(osrfHttpTranslator* trans) {
+    osrfMessage* msg;
     osrfMessage* msgList[MAX_MSGS_PER_PACKET];
     int numMsgs = osrf_message_deserialize(trans->body, msgList, MAX_MSGS_PER_PACKET);
     osrfLogDebug(OSRF_LOG_MARK, "parsed %d opensrf messages in this packet", numMsgs);
 
     if(numMsgs == 0)
-        return 0;
-
-    if(numMsgs == 1) {
-        msg = msgList[0];
-        if(msg->m_type == CONNECT) {
-            trans->connectOnly = 1;
-            trans->connecting = 1;
-            return 1;
-        }
-        if(msg->m_type == DISCONNECT) {
-            trans->disconnectOnly = 1;
-            trans->disconnecting = 1;
-            return 1;
-        }
-    }
+        return NULL;
 
     // log request messages to the activity log
     int i;
     for(i = 0; i < numMsgs; i++) {
         msg = msgList[i];
+        osrfMessageSetIngress(msg, TRANSLATOR_INGRESS);
 
         switch(msg->m_type) {
 
@@ -297,10 +287,14 @@ static int osrfHttpTranslatorParseRequest(osrfHttpTranslator* trans) {
 
             case CONNECT:
                 trans->connecting = 1;
+                if (numMsgs == 1) 
+                    trans->connectOnly = 1;
                 break;
 
             case DISCONNECT:
                 trans->disconnecting = 1;
+                if (numMsgs == 1) 
+                    trans->disconnectOnly = 1;
                 break;
 
             case RESULT:
@@ -318,7 +312,7 @@ static int osrfHttpTranslatorParseRequest(osrfHttpTranslator* trans) {
         }
     }
 
-    return 1;
+    return osrfMessageSerializeBatch(msgList, numMsgs);
 }
 
 static int osrfHttpTranslatorCheckStatus(osrfHttpTranslator* trans, transport_message* msg) {
@@ -395,7 +389,8 @@ static int osrfHttpTranslatorProcess(osrfHttpTranslator* trans) {
     if(!osrfHttpTranslatorSetTo(trans))
         return HTTP_BAD_REQUEST;
 
-    if(!osrfHttpTranslatorParseRequest(trans))
+    char* jsonBody = osrfHttpTranslatorParseRequest(trans);
+    if (NULL == jsonBody)
         return HTTP_BAD_REQUEST;
 
     while(client_recv(trans->handle, 0))
@@ -403,10 +398,11 @@ static int osrfHttpTranslatorProcess(osrfHttpTranslator* trans) {
 
     // send the message to the recipient
     transport_message* tmsg = message_init(
-        trans->body, NULL, trans->thread, trans->recipient, NULL);
+        jsonBody, NULL, trans->thread, trans->recipient, NULL);
     message_set_osrf_xid(tmsg, osrfLogGetXid());
     client_send_message(trans->handle, tmsg);
     message_free(tmsg); 
+    free(jsonBody);
 
     if(trans->disconnectOnly) {
         osrfLogDebug(OSRF_LOG_MARK, "exiting early on disconnect");
@@ -523,6 +519,7 @@ static int handler(request_rec *r) {
 	r->allowed |= (AP_METHOD_BIT << M_POST);
 
 	osrfLogSetAppname("osrf_http_translator");
+	osrfAppSessionSetIngress(TRANSLATOR_INGRESS);
     testConnection(r);
 
 	osrfLogMkXid();
diff --git a/src/gateway/osrf_json_gateway.c b/src/gateway/osrf_json_gateway.c
index e2f2124..5282972 100644
--- a/src/gateway/osrf_json_gateway.c
+++ b/src/gateway/osrf_json_gateway.c
@@ -129,6 +129,7 @@ static int osrf_json_gateway_method_handler (request_rec *r) {
 	}
 
 	osrfLogSetAppname("osrf_json_gw");
+	osrfAppSessionSetIngress("gateway-v1");
 
 	char* osrf_locale   = NULL;
 	char* param_locale  = NULL;  /* locale for this call */
diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c
index 0b1fdf8..956d62a 100644
--- a/src/srfsh/srfsh.c
+++ b/src/srfsh/srfsh.c
@@ -140,6 +140,7 @@ int main( int argc, char* argv[] ) {
 	load_history();
 
 	client = osrfSystemGetTransportClient();
+	osrfAppSessionSetIngress("srfsh");
 	
 	// Disable special treatment for tabs by readline
 	// (by default they invoke command completion, which

commit 7ec92808fea116ead923e475ad5242a54b688798
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Jan 13 09:15:05 2012 -0500

    C libs for OpenSRF ingress tracking
    
    osrfAppSessionSetIngress(<ingress>);
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/include/opensrf/osrf_app_session.h b/include/opensrf/osrf_app_session.h
index c8ad2f0..f0e2586 100644
--- a/include/opensrf/osrf_app_session.h
+++ b/include/opensrf/osrf_app_session.h
@@ -105,6 +105,11 @@ osrfAppSession* osrf_app_server_session_init(
 
 char* osrf_app_session_set_locale( osrfAppSession*, const char* );
 
+/* ingress used by all sessions until replaced */
+char* osrfAppSessionSetIngress( const char* );
+
+const char* osrfAppSessionGetIngress();
+
 osrfAppSession* osrf_app_session_find_session( const char* session_id );
 
 /* DEPRECATED; use osrfAppSessionSendRequest() instead. */
diff --git a/include/opensrf/osrf_message.h b/include/opensrf/osrf_message.h
index 592c039..76091d0 100644
--- a/include/opensrf/osrf_message.h
+++ b/include/opensrf/osrf_message.h
@@ -92,11 +92,16 @@ struct osrf_message_struct {
 
 	/** Magical LOCALE hint. */
 	char* sender_locale;
+
+	/** Magical ingress hint. */
+	char* sender_ingress;
 };
 typedef struct osrf_message_struct osrfMessage;
 
 const char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
 
+const char* osrfMessageSetIngress( osrfMessage* msg, const char* ingress );
+
 const char* osrf_message_set_default_locale( const char* locale );
 
 const char* osrf_message_get_last_locale(void);
diff --git a/src/libopensrf/osrf_app_session.c b/src/libopensrf/osrf_app_session.c
index 890108a..8a14d2a 100644
--- a/src/libopensrf/osrf_app_session.c
+++ b/src/libopensrf/osrf_app_session.c
@@ -7,6 +7,8 @@
 #include "opensrf/osrf_app_session.h"
 #include "opensrf/osrf_stack.h"
 
+static char* current_ingress = NULL;
+
 struct osrf_app_request_struct {
 	/** The controlling session. */
 	struct osrf_app_session_struct* session;
@@ -370,6 +372,26 @@ char* osrf_app_session_set_locale( osrfAppSession* session, const char* locale )
 }
 
 /**
+	@brief Install a copy of a ingress string as the new default.
+	@param session Pointer to the new strdup'ed default_ingress
+	@param ingress The ingress string to be copied and installed.
+*/
+char* osrfAppSessionSetIngress(const char* ingress) {
+	if (!ingress) return NULL;
+    if(current_ingress) 
+        free(current_ingress);
+    return current_ingress = strdup(ingress);
+}
+
+/**
+    @brief Returns the current ingress value
+    @return A pointer to the installed copy of the ingress string 
+*/
+const char* osrfAppSessionGetIngress() {
+    return current_ingress;
+}
+
+/**
 	@brief Find the osrfAppSession for a given session id.
 	@param session_id The session id to look for.
 	@return Pointer to the corresponding osrfAppSession if found, or NULL if not.
@@ -689,6 +711,10 @@ static int osrfAppSessionMakeLocaleRequest(
 		osrf_message_set_locale(req_msg, session->session_locale);
 	}
 
+	if (!current_ingress)
+		osrfAppSessionSetIngress("opensrf");
+	osrfMessageSetIngress(req_msg, current_ingress);
+
 	if(params) {
 		osrf_message_set_params(req_msg, params);
 
diff --git a/src/libopensrf/osrf_message.c b/src/libopensrf/osrf_message.c
index f6e2b62..364c875 100644
--- a/src/libopensrf/osrf_message.c
+++ b/src/libopensrf/osrf_message.c
@@ -42,6 +42,7 @@ osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol
 	msg->_result_content        = NULL;
 	msg->method_name            = NULL;
 	msg->sender_locale          = NULL;
+	msg->sender_ingress         = NULL;
 
 	return msg;
 }
@@ -83,6 +84,25 @@ const char* osrf_message_set_locale( osrfMessage* msg, const char* locale ) {
 }
 
 /**
+	@brief Set the ingress for a specified osrfMessage.
+	@param msg Pointer to the osrfMessage.
+	@param ingress Pointer to the ingress string to be installed in the osrfMessage.
+	@return Pointer to the new ingress string for the osrfMessage, or NULL if either
+		parameter is NULL.
+
+	If no ingress is specified for an osrfMessage, we use the default ingress.
+
+	Used for a REQUEST message.
+*/
+const char* osrfMessageSetIngress( osrfMessage* msg, const char* ingress ) {
+	if( msg == NULL || ingress == NULL )
+		return NULL;
+	if( msg->sender_ingress )
+		free( msg->sender_ingress );
+	return msg->sender_ingress = strdup( ingress );
+}
+
+/**
 	@brief Change the default locale.
 	@param locale The new default locale.
 	@return A pointer to the new default locale if successful, or NULL if not.
@@ -287,6 +307,9 @@ void osrfMessageFree( osrfMessage* msg ) {
 	if( msg->sender_locale != NULL )
 		free(msg->sender_locale);
 
+	if( msg->sender_ingress != NULL )
+		free(msg->sender_ingress);
+
 	if( msg->_params != NULL )
 		jsonObjectFree(msg->_params);
 
@@ -361,6 +384,7 @@ char* osrf_message_serialize(const osrfMessage* msg) {
 	The resulting jsonObject is a JSON_HASH with a classname of "osrfMessage", and the following keys:
 	- "threadTrace"
 	- "locale"
+	- "ingress"
 	- "type"
 	- "payload" (only for STATUS, REQUEST, and RESULT messages)
 
@@ -398,6 +422,9 @@ jsonObject* osrfMessageToJSON( const osrfMessage* msg ) {
 		jsonObjectSetKey(json, "locale", jsonNewObject(default_locale));
 	}
 
+	if (msg->sender_ingress != NULL) 
+		jsonObjectSetKey(json, "ingress", jsonNewObject(msg->sender_ingress));
+
 	switch(msg->m_type) {
 
 		case CONNECT:
@@ -622,6 +649,11 @@ static osrfMessage* deserialize_one_message( const jsonObject* obj ) {
 		}
 	}
 
+	tmp = jsonObjectGetKeyConst(obj, "ingress");
+	if (tmp) {
+		osrfMessageSetIngress(msg, jsonObjectGetString(tmp));
+	}
+
 	tmp = jsonObjectGetKeyConst( obj, "payload" );
 	if(tmp) {
 		// Get method name and parameters for a REQUEST
diff --git a/src/libopensrf/osrf_stack.c b/src/libopensrf/osrf_stack.c
index 186c2a8..73793f8 100644
--- a/src/libopensrf/osrf_stack.c
+++ b/src/libopensrf/osrf_stack.c
@@ -149,6 +149,10 @@ struct osrf_app_session_struct* osrf_stack_transport_handler( transport_message*
 			}
 		}
 
+		// grab the ingress value from the first message.
+		// they will all be the same
+		if (i == 0) osrfAppSessionSetIngress(arr[i]->sender_ingress);
+
 		if( session->type == OSRF_SESSION_CLIENT )
 			_do_client( session, arr[i] );
 		else

commit b12de37f9480c68b1c8b033da18c3cc0d0ebc8f0
Author: Bill Erickson <berick at esilibrary.com>
Date:   Thu Jan 12 16:36:16 2012 -0500

    Perl libs for OpenSRF ingress tracking
    
    Ingress is a free-form text value which represents the entry point for
    the client into the opensrf network.  The value is passed within opensrf
    messages, similar to "locale".  Clients should specify the ingress
    before any opensrf communication occurs.
    
    OpenSRF::AppSession->ingress($ingress);
    
    Stock values include the following:
    
    opensrf (default)
    srfsh
    translator-v1
    gateway-v1
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/src/perl/lib/OpenSRF/AppSession.pm b/src/perl/lib/OpenSRF/AppSession.pm
index c8ee269..d19085f 100644
--- a/src/perl/lib/OpenSRF/AppSession.pm
+++ b/src/perl/lib/OpenSRF/AppSession.pm
@@ -22,6 +22,13 @@ our %EXPORT_TAGS = ( state => [ qw/CONNECTING INIT_CONNECTED CONNECTED DISCONNEC
 
 my $logger = "OpenSRF::Utils::Logger";
 my $_last_locale = 'en-US';
+our $current_ingress = 'opensrf';
+
+sub ingress {
+    my ($class, $ingress) = @_;
+    $current_ingress = $ingress if $ingress;
+    return $current_ingress;
+}
 
 our %_CACHE;
 our @_RESEND_QUEUE;
@@ -499,6 +506,8 @@ sub send {
 
         my $locale = $self->session_locale;
 		$msg->sender_locale($locale) if ($locale);
+
+		$msg->sender_ingress($current_ingress);
 	
 		push @doc, $msg;
 
diff --git a/src/perl/lib/OpenSRF/DomainObject/oilsMessage.pm b/src/perl/lib/OpenSRF/DomainObject/oilsMessage.pm
index 44eafc2..54c5963 100644
--- a/src/perl/lib/OpenSRF/DomainObject/oilsMessage.pm
+++ b/src/perl/lib/OpenSRF/DomainObject/oilsMessage.pm
@@ -102,6 +102,24 @@ sub sender_locale {
 	return $self->{locale};
 }
 
+=head2 OpenSRF::DomainObject::oilsMessage->sender_ingress( [$ingress] );
+
+=over 4
+
+Sets or gets the current message ingress.  Useful for telling the
+server how you entered the opensrf network.
+
+=back
+
+=cut
+
+sub sender_ingress {
+	my $self = shift;
+	my $val = shift;
+	$self->{ingress} = $val if $val;
+	return $self->{ingress};
+}
+
 =head2 OpenSRF::DomainObject::oilsMessage->threadTrace( [$new_threadTrace] );
 
 =over 4
@@ -180,10 +198,11 @@ sub handler {
 
 	my $mtype = $self->type;
 	my $locale = $self->sender_locale || '';
+	my $ingress = $self->sender_ingress || '';
 	my $api_level = $self->api_level || 1;
 	my $tT = $self->threadTrace;
 
-    $log->debug("Message locale is $locale", DEBUG);
+    $log->debug("Message locale is $locale; ingress = $ingress", DEBUG);
 
 	$session->last_message_type($mtype);
 	$session->last_message_api_level($api_level);
diff --git a/src/perl/lib/OpenSRF/Transport.pm b/src/perl/lib/OpenSRF/Transport.pm
index cfb7ba9..c295acd 100644
--- a/src/perl/lib/OpenSRF/Transport.pm
+++ b/src/perl/lib/OpenSRF/Transport.pm
@@ -153,6 +153,8 @@ sub handler {
 
 		next unless (	$msg && UNIVERSAL::isa($msg => 'OpenSRF::DomainObject::oilsMessage'));
 
+		OpenSRF::AppSession->ingress($msg->sender_ingress);
+
 		if( $app_session->endpoint == $app_session->SERVER() ) {
 
 			try {  

-----------------------------------------------------------------------

Summary of changes:
 include/opensrf/osrf_app_session.h               |    5 +++
 include/opensrf/osrf_message.h                   |    5 +++
 src/gateway/osrf_http_translator.c               |   39 ++++++++++------------
 src/gateway/osrf_json_gateway.c                  |    1 +
 src/libopensrf/osrf_app_session.c                |   26 ++++++++++++++
 src/libopensrf/osrf_message.c                    |   32 ++++++++++++++++++
 src/libopensrf/osrf_stack.c                      |    4 ++
 src/perl/lib/OpenSRF/AppSession.pm               |    9 +++++
 src/perl/lib/OpenSRF/DomainObject/oilsMessage.pm |   21 +++++++++++-
 src/perl/lib/OpenSRF/Transport.pm                |    2 +
 src/python/osrf/ses.py                           |   12 ++++++-
 src/python/osrf/stack.py                         |    2 +
 src/python/srfsh.py                              |    1 +
 src/srfsh/srfsh.c                                |    1 +
 14 files changed, 137 insertions(+), 23 deletions(-)


hooks/post-receive
-- 
OpenSRF


More information about the opensrf-commits mailing list