From 334be00dd90942ab74426ad21f3eb7d2ebf5e604 Mon Sep 17 00:00:00 2001 From: Stas Shtin Date: Sun, 18 Apr 2010 23:53:51 +0400 Subject: [PATCH] Sofia.conf works with freeswitch --- src/ipypbx/http.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ipypbx/http.py b/src/ipypbx/http.py index 4636866..85b7062 100644 --- a/src/ipypbx/http.py +++ b/src/ipypbx/http.py @@ -106,12 +106,15 @@ Content-Length: %i def receiveData(self): # TODO: read in chunks. for line in str(self.socket.readAll()).split('\r\n'): - print line + print self.httpRequestParser.i, line self.httpRequestParser.handle(line) response = self.httpRequestParser.result or self.configNotFound http_response = self.responseTemplate % (len(response), response) self.socket.write(http_response) + print + print http_response + print self.httpRequestParser.reset() self.socket.close() @@ -131,12 +134,14 @@ class HttpRequestParser(object): def __init__(self, parent): self.parent = parent + self.i = 0 self.reset() def reset(self): """ Reset parser to initial state. """ + self.i += 1 # Initial values for request data. self.method = None self.request_path = None @@ -170,8 +175,11 @@ class HttpRequestParser(object): """ Retrieve HTTP method, request path and HTTP version from request. """ - self.method, self.request_path, self.http_version = line.split(' ') - self.state += 1 + try: + self.method, self.request_path, self.http_version = line.split(' ') + self.state += 1 + except ValueError: + pass def handleHeaders(self, line): """ @@ -228,7 +236,7 @@ class FreeswitchConfigGenerator(object): return True def baseElements(self): - root_elt = etree.Element('document') + root_elt = etree.Element('document', type='freeswitch/xml') section_elt = etree.SubElement( root_elt, 'section', name=self.section_name) return root_elt, section_elt @@ -260,8 +268,7 @@ class SofiaConfGenerator(FreeswitchConfigGenerator): configuration_elt = etree.SubElement( section_elt, 'configuration', name=self.config_name, description='%s config' % self.config_name) - settings_elt = etree.SubElement(configuration_elt, 'settings') - profiles_elt = etree.SubElement(settings_elt, 'profiles') + profiles_elt = etree.SubElement(configuration_elt, 'profiles') database = self.model.controllers['connection'].model.database() @@ -281,12 +288,14 @@ class SofiaConfGenerator(FreeswitchConfigGenerator): # Create domains for current profile. domains_elt = etree.SubElement(profile_elt, 'domains') domains_query = database.exec_( - 'select host_name from ipypbxweb_domain where profile_id = ' + 'select host_name from ipypbxweb_domain where sip_profile_id = ' '%i' % profile_id) while domains_query.next(): domain_elt = etree.SubElement( - domains_elt, 'domain', name=domains_quey.value(0), - alias='true', parse='true') + domains_elt, 'domain', + name=domains_query.value(0).toString(), alias='true', + parse='true') + profile_sip_port, _ok = profiles_query.value(6).toInt() @@ -315,8 +324,9 @@ class SofiaConfGenerator(FreeswitchConfigGenerator): gateways_query = database.exec_( ''' select name, username, realm, from_domain, password, - retry_seconds, expire_seconds, caller_id_in_from, extension - from ipypbxweb_gateway where sipprofile_id = %i + retry_in_seconds, expire_in_seconds, caller_id_in_from_field, + extension + from ipypbxweb_gateway where sip_profile_id = %i ''' % profile_id) while gateways_query.next(): gateway_elt = etree.SubElement( -- 1.7.9.5