From 2cbd53dbf230b370c2e18ad7c4988f5c67be5cab Mon Sep 17 00:00:00 2001 From: Stas Shtin Date: Thu, 15 Apr 2010 21:07:16 +0400 Subject: [PATCH] Config generator initialization fixed --- src/ipypbx/controllers.py | 2 +- src/ipypbx/create.sql | 2 +- src/ipypbx/http.py | 14 ++++++++------ src/ipypbxweb/models.py | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ipypbx/controllers.py b/src/ipypbx/controllers.py index 19680d3..43d7322 100644 --- a/src/ipypbx/controllers.py +++ b/src/ipypbx/controllers.py @@ -221,7 +221,7 @@ class ConnectionController(BaseController): for row in range(self.model.rowCount()): # Get local IP address and port from the table for each row. - server = http.FreeswitchConfigServer() + server = http.FreeswitchConfigServer(self) server.setSocketData(*self.getSocketData(row)) server.startServer() self.servers.append(server) diff --git a/src/ipypbx/create.sql b/src/ipypbx/create.sql index 3d43168..3a573f8 100644 --- a/src/ipypbx/create.sql +++ b/src/ipypbx/create.sql @@ -2,7 +2,7 @@ CREATE TABLE "ipypbxweb_connection" ( "id" integer NOT NULL PRIMARY KEY, "name" varchar(100) NOT NULL, "local_ip_address" char(15) NOT NULL, - "local_port" integer unsigned NOT NULL, + "local_port" integer unsigned NOT NULL UNIQUE, "freeswitch_ip_address" char(15) NOT NULL, "freeswitch_port" integer unsigned NOT NULL ) diff --git a/src/ipypbx/http.py b/src/ipypbx/http.py index f168c53..3be3b8f 100644 --- a/src/ipypbx/http.py +++ b/src/ipypbx/http.py @@ -23,14 +23,17 @@ class FreeswitchConfigServer(QtNetwork.QTcpServer): """ TCP server that receives config requests from freeswitch. """ - def __init__(self, parent=None): + def __init__(self, parent): super(FreeswitchConfigServer, self).__init__(parent) self.host = None self.port = None self.is_running = False + self.generators = [ + GenClass(self.parent().model) for GenClass in ( + SofiaConfGenerator,)] - self.httpRequestParser = HttpRequestParser() + self.httpRequestParser = HttpRequestParser(self) def setSocketData(self, host, port): """ @@ -47,7 +50,6 @@ class FreeswitchConfigServer(QtNetwork.QTcpServer): # Restart server if necessary. if needs_restart: - print 'restartin', self.host, self.port self.restartServer() def startServer(self): @@ -103,8 +105,8 @@ class HttpRequestParser(object): HTTP_DONE = range(6) HTTP_STATES = ['NONE', 'REQUEST', 'HEADERS', 'EMPTY', 'MESSAGE', 'DONE'] - def __init__(self): - super(HttpRequestParser, self).__init__() + def __init__(self, parent): + self.parent = parent self.reset() def reset(self): @@ -173,7 +175,7 @@ class HttpRequestParser(object): print k, '=>', v print - for generator in self.generators: + for generator in self.parent.generators: if generator.canHandle(self.headers): self.state += 1 return generator.generateConfig(self.headers) diff --git a/src/ipypbxweb/models.py b/src/ipypbxweb/models.py index f2c754b..203e0af 100644 --- a/src/ipypbxweb/models.py +++ b/src/ipypbxweb/models.py @@ -24,7 +24,7 @@ class Connection(models.Model): """ name = models.CharField(max_length=100) local_ip_address = models.IPAddressField() - local_port = models.PositiveIntegerField() + local_port = models.PositiveIntegerField(unique=True) freeswitch_ip_address = models.IPAddressField() freeswitch_port = models.PositiveIntegerField() -- 1.7.9.5