--- /dev/null
+# Copyright (c) Stas Shtin, 2010
+
+# This file is part of IPyPBX.
+
+# IPyPBX is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# IPyPBX is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
+
+from PyQt4 import QtCore, QtNetwork
+
+
+class FreeswitchConfigServer(QtNetwork.QTcpServer):
+ def setSocket(self, host, port):
+ self.host = host
+ self.port = port
+
+ def startServer(self):
+ self.newConnection.connect(self.clientConnecting)
+ self.listen(QtNetwork.QHostAddress(self.host), self.port)
+
+ def stopServer(self):
+ self.close()
+
+ def clientConnecting(self, socket):
+ if self.hasPendingConnections():
+ connectingClient = self.server.nextPendingConnection()
+ connectingClient.readyRead.connect(self.receiveData)
+
+ def receiveData(self, socket):
+ self.
+ while socket.canReadLine():
+ line = socket.readLine().strip()
+
+
+
+class HttpParseError(Exception):
+ pass
+
+
+class HttpRequestParser(object):
+ """
+ A simple state machine for parsing HTTP requests.
+ """
+ HTTP_NONE, HTTP_REQUEST, HTTP_HEADERS, HTTP_EMPTY, HTTP_MESSAGE = range(5)
+ HTTP_STATES = ['NONE', 'REQUEST', 'HEADERS', 'EMPTY', 'MESSAGE']
+
+ def __init__(self):
+ super(HttpParser, self).__init__()
+
+ def reset(self):
+ """
+ Reset parser to initial state.
+ """
+ # Initial values for request data.
+ self.method = None
+ self.request_path = None
+ self.http_version = None
+ self.message = ''
+
+ # Set initial state.
+ self.state = HTTP_NONE
+
+ def handle(self, line):
+ """
+ Dispatch line to current state handler.
+ """
+ for state in HTTP_STATES:
+ if getattr(self, 'HTTP_%s' % state) == self.state:
+ getattr(self, 'handle%s' % state.title()).(line)
+ break
+ else:
+ raise HttpParseError('Unknown HTTP state')
+
+ def handleNone(self, line):
+ """
+ Pass line to next state.
+ """
+ self.state += 1
+ self.handle(line)
+
+ def handleRequest(self, line):
+ """
+ Retrieve HTTP method, request path and HTTP version from request.
+ """
+ self.method, self.request_path, self.http_version = line.split(' ')
+ self.state += 1
+
+ def handleHeaders(self, line):
+ """
+ Parse headers while not found an empty line.
+ """
+ if line:
+ key, value = line.split(': ')
+ self.headers[key] = value
+ else:
+ self.state += 1
+
+ def handleEmpty(self, line):
+ """
+ Empty line separator is found - proceed to next state.
+ """
+ self.state += 1
+
+ def handleMessage(self, line):
+ """
+ Append to message body.
+ """
+ self.message += line
+++ /dev/null
-# Copyright (c) Stas Shtin, 2010
-
-# This file is part of IPyPBX.
-
-# IPyPBX is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# IPyPBX is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
-
-
-from PyQt import QtNetwork
-
-
-class FreeswitchConfigServer(QTcpServer):
- """
- This is a server that gets instantiated for every connection.
- """
- def __init__(self, host, port, parent=None):
- super(FreeswitchConfig, self).__init__(self, parent)
-
- self.newConnection.connect(self, handleClientConnection)
- self.listen(host, port)
-
- def handleClientConnection(self):
- if self.hasPendingConnections():
- connectionClient = self.nextClientConnection()
- connectionClient.readyRead.connect(self.receiveData)
+++ /dev/null
-# Copyright (c) Stas Shtin, 2010
-
-# This file is part of IPyPBX.
-
-# IPyPBX is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# IPyPBX is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-from axiom.store import Store
-from ipypbx import models
-
-
-# Working directory path.
-PREFIX = os.path.expanduser('~/.ipypbx')
-
-# Create it if necessary.
-if not os.path.exists(PREFIX):
- os.mkdir(PREFIX, 0700)
-
-# Initialize sqlite DB file.
-#store = Store(os.path.join(PREFIX, 'ipypbx.db'))
-
-# Program state data.
-sipProfiles = []
-domains = []
-gateways = []
-endpoints = []
-extensions = []
-