예제 #1
0
    def lineReceived(self, line):
        debug("<< %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 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)                
                raise Exception("Received line: %s w/ no pending requests" % line)
            self.active_request = self.requestq.get()

        # tell the request to process the line, and tell us
        # if its finished or not.  if its finished, we remove it
        # as the active request so that a new active request will
        # be de-queued.
        finished = self.active_request.process(line)
        if finished == True:
            self.active_request = None
예제 #2
0
    def lineReceived(self, line):
        debug("<< %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 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)                
                raise Exception("Received line: %s w/ no pending requests" % line)
            self.active_request = self.requestq.get()

        # tell the request to process the line, and tell us
        # if its finished or not.  if its finished, we remove it
        # as the active request so that a new active request will
        # be de-queued.
        finished = self.active_request.process(line)
        if finished == True:
            self.active_request = None
예제 #3
0
 def login(self, passwd):
     """
     send login request
     """
     msg = "auth %s" % passwd
     req = request.LoginRequest()
     self.requestq.put(req)
     self.transport.write("%s\n\n" % msg)
     debug(">> %s" % msg)
     return req.getDeferred()
예제 #4
0
 def login(self, passwd):
     """
     send login request
     """
     msg = "auth %s" % passwd
     req = request.LoginRequest()
     self.requestq.put(req)
     self.transport.write("%s\n\n" % msg)
     debug(">> %s" % msg)
     return req.getDeferred()
예제 #5
0
 def _sendCommand(self, command, bgapi):
     """
     there is a lot of duplication in this object, and as many
     methods as possible should be changed to use this method
     rather than repeating the code
     """
     command = ("bgapi %s" if bgapi else "api %s") % command
     req = (request.BgDialoutRequest if bgapi else request.DialoutRequest)()
     self.requestq.put(req)
     self.transport.write("%s\n\n" % command)
     debug(">> %s" % command)
     return req.getDeferred()
예제 #6
0
    def originate(self, party2dial, dest_ext_app, bgapi=True):

        if bgapi == True:
            msg = "bgapi originate %s %s" % (party2dial, dest_ext_app)
            req = request.BgDialoutRequest()
        else:
            msg = "api originate %s %s" % (party2dial, dest_ext_app)
            req = request.DialoutRequest()
        self.requestq.put(req)
        self.transport.write("%s\n\n" % msg)
        debug(">> %s" % msg)
        return req.getDeferred()
예제 #7
0
 def listconf(self, conf_name):
     """
     List users in a conf
     @param conf_name - the name of the conference (arbitrary)
     @return - a deferred that will be called back with an array
               of models.ConfMember instances
     """
     msg = "api conference %s list" % (conf_name)
     req = request.ListConfRequest()
     self.requestq.put(req)
     self.transport.write("%s\n\n" % msg)
     debug(">> %s" % msg)                        
     return req.getDeferred()
예제 #8
0
 def listconf(self, conf_name):
     """
     List users in a conf
     @param conf_name - the name of the conference (arbitrary)
     @return - a deferred that will be called back with an array
               of models.ConfMember instances
     """
     msg = "api conference %s list" % (conf_name)
     req = request.ListConfRequest()
     self.requestq.put(req)
     self.transport.write("%s\n\n" % msg)
     debug(">> %s" % msg)                        
     return req.getDeferred()
예제 #9
0
 def _sendCommand(self, command, bgapi):
     """
     there is a lot of duplication in this object, and as many
     methods as possible should be changed to use this method
     rather than repeating the code
     """
     command = ("bgapi %s" if bgapi else "api %s") % command
     req = (request.BgDialoutRequest if bgapi else
            request.DialoutRequest)()
     self.requestq.put(req)
     self.transport.write("%s\n\n" % command)
     debug(">> %s" % command)
     return req.getDeferred()
예제 #10
0
    def originate(self, party2dial, dest_ext_app, bgapi=True):

        if bgapi == True:
            msg = "bgapi originate %s %s" % (party2dial,
                                             dest_ext_app)
            req = request.BgDialoutRequest()            
        else:
            msg = "api originate %s %s" % (party2dial,
                                           dest_ext_app)
            req = request.DialoutRequest()
        self.requestq.put(req)
        self.transport.write("%s\n\n" % msg)
        debug(">> %s" % msg)                
        return req.getDeferred()
예제 #11
0
    def confkick(self, member_id, conf_name, bgapi=False):
        """
        Kick member_id from conf
        conf_name - name of conf
        member_id - member id of user to kick, eg, "7"
        returns - a deferred that will be called back with a result
                  like:

                  TODO: add this        
        """
        if bgapi == True:
            msg = "bgapi conference %s kick %s" % (conf_name, member_id)
            req = request.BgConfKickRequest()
        else:
            msg = "api conference %s kick %s" % (conf_name, member_id)
            req = request.ConfKickRequest()
        self.requestq.put(req)
        self.transport.write("%s\n\n" % msg)
        debug(">> %s" % msg)                        
        return req.getDeferred()
예제 #12
0
    def confdialout(self, conf_name, sofia_url, bgapi=True):
        """
        Instruct conference to join a particular user via dialout
        @param conf_name - the name of the conference (arbitrary)
        @param party2dial - a freeswitch sofia url, eg, sofia/mydomain.com/[email protected]
        @return - a deferred that will be called back with a string like:
                  Reply-Text: +OK Job-UUID: 4d410a8e-2409-11dc-99bf-a5e17fab9c65


        """
        if bgapi == True:
            msg = "bgapi conference %s dial %s" % (conf_name, sofia_url)
            req = request.BgDialoutRequest()
        else:
            msg = "api conference %s dial %s" % (conf_name, sofia_url)
            req = request.DialoutRequest()
        self.requestq.put(req)
        self.transport.write("%s\n\n" % msg)
        debug(">> %s" % msg)
        return req.getDeferred()
예제 #13
0
    def confkick(self, member_id, conf_name, bgapi=False):
        """
        Kick member_id from conf
        conf_name - name of conf
        member_id - member id of user to kick, eg, "7"
        returns - a deferred that will be called back with a result
                  like:

                  TODO: add this        
        """
        if bgapi == True:
            msg = "bgapi conference %s kick %s" % (conf_name, member_id)
            req = request.BgConfKickRequest()
        else:
            msg = "api conference %s kick %s" % (conf_name, member_id)
            req = request.ConfKickRequest()
        self.requestq.put(req)
        self.transport.write("%s\n\n" % msg)
        debug(">> %s" % msg)                        
        return req.getDeferred()
예제 #14
0
    def confdialout(self, conf_name, sofia_url, bgapi=True):
        """
        Instruct conference to join a particular user via dialout
        @param conf_name - the name of the conference (arbitrary)
        @param party2dial - a freeswitch sofia url, eg, sofia/mydomain.com/[email protected]
        @return - a deferred that will be called back with a string like:
                  Reply-Text: +OK Job-UUID: 4d410a8e-2409-11dc-99bf-a5e17fab9c65


        """
        if bgapi == True:
            msg = "bgapi conference %s dial %s" % (conf_name,
                                                   sofia_url)
            req = request.BgDialoutRequest()            
        else:
            msg = "api conference %s dial %s" % (conf_name,
                                                 sofia_url)
            req = request.DialoutRequest()
        self.requestq.put(req)
        self.transport.write("%s\n\n" % msg)
        debug(">> %s" % msg)        
        return req.getDeferred()
예제 #15
0
    def process(self, line):
        """
        processs a line from the fs response.  if the fs response has been
        detected to be finished, then:

        * create an appropriate response based on request type
        * callback deferred with response
        * rturn True to indicate we are finished

        otherwise, if the fs response is incomplete, just buffer the data
        """
        if not line.strip() or len(line.strip()) == 0:
            self._fsm.BlankLine()
            return self.isRequestFinished()

        matchstr = re.compile("auth/request", re.I)
        result = matchstr.search(line)
        if (result != None):
            self._fsm.AuthRequest()
            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):
            debug("FREEPY: got Reply-Text")
            fields = line.split(
                ":")  # eg, ['Reply-Text','+OK Job-UUID', '882']
            endfields = fields[1:]
            self.response_content = "".join(endfields)
            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)
        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()
예제 #16
0
 def setRequestFinished(self):
     debug("setRequestFinished called.  response_content: %s " %
           self.response_content)
     self.finished = True
예제 #17
0
파일: request.py 프로젝트: bodji/freeswitch
 def setRequestFinished(self):
     debug("setRequestFinished called.  response_content: %s " % self.response_content)
     self.finished = True
예제 #18
0
 def connectionLost(self, reason):
     if self.discocb:
         self.discocb(reason)        
     debug("connectionLost: %s" % reason)
예제 #19
0
 def connectionMade(self):
     debug("FREEPY: Connection made")
     self.conncb(self)
예제 #20
0
파일: request.py 프로젝트: bodji/freeswitch
    def process(self, line):
        """
        processs a line from the fs response.  if the fs response has been
        detected to be finished, then:

        * create an appropriate response based on request type
        * callback deferred with response
        * rturn True to indicate we are finished

        otherwise, if the fs response is incomplete, just buffer the data
        """
        if not line.strip() or len(line.strip()) == 0:
            self._fsm.BlankLine()
            return self.isRequestFinished()

        matchstr = re.compile("auth/request", re.I)
        result = matchstr.search(line)
        if result != None:
            self._fsm.AuthRequest()
            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:
            debug("FREEPY: got Reply-Text")
            fields = line.split(":")  # eg, ['Reply-Text','+OK Job-UUID', '882']
            endfields = fields[1:]
            self.response_content = "".join(endfields)
            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)
        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()
예제 #21
0
 def connectionMade(self):
     debug("FREEPY: Connection made")
     self.conncb(self)
예제 #22
0
 def connectionLost(self, reason):
     if self.discocb:
         self.discocb(reason)        
     debug("connectionLost: %s" % reason)