[Freeswitch-svn] [commit] r9009 - freeswitch/trunk/scripts/socket/freepy

Freeswitch SVN greenlizard at freeswitch.org
Sun Jul 13 00:10:53 EDT 2008


Author: greenlizard
Date: Sun Jul 13 00:10:52 2008
New Revision: 9009

Modified:
   freeswitch/trunk/scripts/socket/freepy/README
   freeswitch/trunk/scripts/socket/freepy/__init__.py
   freeswitch/trunk/scripts/socket/freepy/bgapirequest.sm
   freeswitch/trunk/scripts/socket/freepy/bgapirequest_sm.py
   freeswitch/trunk/scripts/socket/freepy/globals.py
   freeswitch/trunk/scripts/socket/freepy/request.py

Log:
fixed protocol incompatibility, make more robust and less anal regarding spurious blank lines, debugging instructions added to README.  debug off by default

Modified: freeswitch/trunk/scripts/socket/freepy/README
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/README	(original)
+++ freeswitch/trunk/scripts/socket/freepy/README	Sun Jul 13 00:10:52 2008
@@ -9,8 +9,18 @@
 
 See INSTALL
 
+Debugging
+=========
+
+Set FREEPY_DEBUG_ON = True in globals.py
+
+TODO: pull this from an environment variable or a config file
+
 Rebulding State Machines
 ========================
+
+(you only need to do this if you changed an .sm file)
+
 for each .sm file:
 
 java -jar /usr/src/smc/bin/Smc.jar -python -g THE.sm

Modified: freeswitch/trunk/scripts/socket/freepy/__init__.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/__init__.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/__init__.py	Sun Jul 13 00:10:52 2008
@@ -54,20 +54,20 @@
         self.active_request = None # the current active (de-queued) request
 
     def connectionMade(self):
-        print "Connection made"
+        self.log("Connection made")
         self.conncb(self)
         
     def connectionLost(self, reason):
         if self.discocb:
             self.discocb(reason)        
-        print "connectionLost: %s" % reason
+        self.log("connectionLost: %s" % reason)
 
 
     def log(self, msg):
         """
         print a message to stdout if debug enabled
         """
-        if freepy.globals.DEBUG_ON:
+        if freepy.globals.FREEPY_DEBUG_ON:
             print msg
             
     def login(self, passwd):
@@ -166,7 +166,6 @@
 
                   TODO: add this        
         """
-        print "confdtmf called"        
         if bgapi == True:
             msg = "bgapi conference %s dtmf %s %s" % \
                   (conf_name, member_id, dtmf)
@@ -296,7 +295,7 @@
             msg = "api sofia status profile %s as xml" % (profile_name)
             req = request.ApiRequest()
         self.requestq.put(req)
-        print "sending to fs: %s" % msg
+        self.log("sending to fs: %s" % msg)
         self.transport.write("%s\n\n" % msg)
         return req.getDeferred()
         
@@ -357,9 +356,15 @@
     def lineReceived(self, line):
         self.log("<< %s" % line)                                
         if not self.active_request:
+
+            # if no active request pending, we ignore
+            # blank lines
+            if not line.strip():
+                return
+            
             # if no active request, dequeue a new one
             if self.requestq.empty():
-                # we are receiving data from fs without an
+                # we are receiving non-empty data from fs without an
                 # active request pending.  that means that
                 # there is a bug in the protocol handler
                 # (or possibly in fs)                

Modified: freeswitch/trunk/scripts/socket/freepy/bgapirequest.sm
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/bgapirequest.sm	(original)
+++ freeswitch/trunk/scripts/socket/freepy/bgapirequest.sm	Sun Jul 13 00:10:52 2008
@@ -25,11 +25,16 @@
 GotReplyText
 {
         BlankLine
-		Startup                
+				nil                
                 {
-		setRequestFinished(); callOrErrback();		
+				
                 }
 
+		JobUuid
+				Startup
+				{
+				setRequestFinished(); callOrErrback();			
+				}
 
 }
 
@@ -43,8 +48,7 @@
 		nil			
 		{ 
 		setRequestFinished();
-		errbackDeferred("Protocol failure - was not expecting blank line");		
-		}
+		errbackDeferred("Protocol failure - was not expecting blank line");			   }
 
     	CommandReply		
 		nil			
@@ -64,7 +68,7 @@
 		nil			
 		{ 
 		setRequestFinished();
-		errbackDeferred("Protocol failure - was not expecting line needing to be processed");		
+		errbackDeferred("Protocol failure handling bgapi response - was not expecting line needing to be processed");		
 		}
 
 }

Modified: freeswitch/trunk/scripts/socket/freepy/bgapirequest_sm.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/bgapirequest_sm.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/bgapirequest_sm.py	Sun Jul 13 00:10:52 2008
@@ -19,6 +19,9 @@
     def CommandReply(self, fsm):
         self.Default(fsm)
 
+    def JobUuid(self, fsm):
+        self.Default(fsm)
+
     def ProcessLine(self, fsm, line):
         self.Default(fsm)
 
@@ -82,7 +85,7 @@
         fsm.clearState()
         try:
             ctxt.setRequestFinished()
-            ctxt.errbackDeferred("Protocol failure - was not expecting line needing to be processed")
+            ctxt.errbackDeferred("Protocol failure handling bgapi response - was not expecting line needing to be processed")
         finally:
             fsm.setState(endState)
 
@@ -109,10 +112,15 @@
 class MainMap_GotReplyText(MainMap_Default):
 
     def BlankLine(self, fsm):
-        ctxt = fsm.getOwner()
         if fsm.getDebugFlag() == True:
             fsm.getDebugStream().write("TRANSITION   : MainMap.GotReplyText.BlankLine()\n")
 
+
+    def JobUuid(self, fsm):
+        ctxt = fsm.getOwner()
+        if fsm.getDebugFlag() == True:
+            fsm.getDebugStream().write("TRANSITION   : MainMap.GotReplyText.JobUuid()\n")
+
         fsm.getState().Exit(fsm)
         fsm.clearState()
         try:
@@ -147,6 +155,11 @@
         self.getState().CommandReply(self)
         self._transition = None
 
+    def JobUuid(self):
+        self._transition = 'JobUuid'
+        self.getState().JobUuid(self)
+        self._transition = None
+
     def ProcessLine(self, *arglist):
         self._transition = 'ProcessLine'
         self.getState().ProcessLine(self, *arglist)

Modified: freeswitch/trunk/scripts/socket/freepy/globals.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/globals.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/globals.py	Sun Jul 13 00:10:52 2008
@@ -1,2 +1,10 @@
 
-DEBUG_ON = True
+import os
+
+if os.environ.has_key('FREEPY_DEBUG_ON'):
+    # pull from environment if avail
+    FREEPY_DEBUG_ON = os.environ['FREEPY_DEBUG_ON']
+else:
+    # fall back to hardcoded value
+    FREEPY_DEBUG_ON = False   
+

Modified: freeswitch/trunk/scripts/socket/freepy/request.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/request.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/request.py	Sun Jul 13 00:10:52 2008
@@ -83,7 +83,7 @@
 
         otherwise, if the fs response is incomplete, just buffer the data
         """
-        if not line or len(line) == 0:
+        if not line.strip() or len(line.strip()) == 0:
             self._fsm.BlankLine()
             return self.isRequestFinished()
         
@@ -110,6 +110,16 @@
             self._fsm.ReplyText()
             return self.isRequestFinished()
 
+        matchstr = re.compile("Job-UUID", re.I)
+        result = matchstr.search(line)
+        if (result != None):
+            fields = line.split(":") # eg, ['Job-UUID','c9eee07e-508-..']
+            endfields = fields[1:]
+            # ignore job uuid given on this line, take the one sent
+            # in Reply-Text response line
+            # self.response_content = "".join(endfields)
+            self._fsm.JobUuid()
+            return self.isRequestFinished()
 
         matchstr = re.compile("api/response", re.I)
         result = matchstr.search(line)
@@ -125,7 +135,6 @@
             self._fsm.ContentLength()
             return self.isRequestFinished()
 
-
         self._fsm.ProcessLine(line)
         return self.isRequestFinished()
 
@@ -194,37 +203,12 @@
     linereceived: 
 
     """
-    
     def __init__(self):
         super(BgApiRequest, self).__init__()
         import bgapirequest_sm
         self._fsm = bgapirequest_sm.BgApiRequest_sm(self)
 
 
-    def processOLD(self, line):
-
-        if not line or len(line) == 0:
-            self._fsm.BlankLine()
-            return self.isRequestFinished()
-        
-        matchstr = re.compile("command/reply", re.I)
-        result = matchstr.search(line)
-        if (result != None):
-            self._fsm.CommandReply()
-            return self.isRequestFinished()
-
-        matchstr = re.compile("Reply-Text", re.I)
-        result = matchstr.search(line)
-        if (result != None):
-            self.response_content = line.split(":")[1]
-            self._fsm.ReplyText()
-            return self.isRequestFinished()
-
-        self._fsm.ProcessLine(line)
-        return self.isRequestFinished()
-
-
-
     def getResponse(self):
 
         # subclasses may want to parse this into a meaningful
@@ -252,28 +236,6 @@
         self._fsm = apirequest_sm.ApiRequest_sm(self)
         self.response_content = ""
 
-    def processOLD(self, line):
-
-        if not line or len(line) == 0:
-            self._fsm.BlankLine()
-            return self.isRequestFinished()
-        
-        matchstr = re.compile("api/response", re.I)
-        result = matchstr.search(line)
-        if (result != None):
-            self._fsm.ApiResponse()
-            return self.isRequestFinished()
-
-        matchstr = re.compile("Content-Length", re.I)
-        result = matchstr.search(line)
-        if (result != None):
-            # line: Content-Length: 34
-            self.content_length = int(line.split(":")[1].strip())
-            self._fsm.ContentLength()
-            return self.isRequestFinished()
-
-        self._fsm.ProcessLine(line)
-        return self.isRequestFinished()
 
     def doNothing(self):
         # weird smc issue workaround attempt



More information about the Freeswitch-svn mailing list