Browse Source

Fix bug introduced by dealing with invalid numbers.

Cleanup file copyrights as suggested by Eric Caudal.
get_caller_name.py should handle Unicode results properly.
pull/96/head
Trever L. Adams 8 years ago
parent
commit
b29862a45c
  1. 9
      freeswitch_click2dial/freeswitch_click2dial.py
  2. 29
      freeswitch_click2dial/scripts/get_caller_name.py

9
freeswitch_click2dial/freeswitch_click2dial.py

@ -176,13 +176,13 @@ class FreeSWITCHServer(models.Model):
else:
resource = user.resource
request = "channels like /" + re.sub(r'/', r':', resource) + \
(("/" if user.freeswitch_chan_type == "FreeTDM" else "@")
if not is_fq_res else "") + " as json"
("/" if user.freeswitch_chan_type == "FreeTDM" else "@") + \
" as json"
ret = fs_manager.api('show', str(request))
f = json.load(StringIO.StringIO(ret.getBody()))
if int(f['row_count']) > 0:
for x in range(0, int(f['row_count'])):
if (is_fq_res and f['rows'][x]['presence_id'] !=
if (is_fq_res > 0 and f['rows'][x]['presence_id'] !=
user.resource):
continue
if (f['rows'][x]['cid_num'] == user.internal_number or
@ -204,7 +204,7 @@ class FreeSWITCHServer(models.Model):
fs_manager.disconnect()
_logger.debug("Calling party number: '%s'", calling_party_number)
if isinstance(calling_party_number, int):
if calling_party_number and calling_party_number.isdigit():
return calling_party_number
else:
return False
@ -397,7 +397,6 @@ class PhoneCommon(models.AbstractModel):
channel + ' ' + fs_number + ' ' + fs_server.context + ' ' + \
'\'' + self.get_name_from_phone_number(fs_number) + '\' ' + \
fs_number
# raise orm.except_orm(_('Error :'), dial_string)
fs_manager.api('originate', dial_string.encode('utf-8'))
except Exception, e:
_logger.error(

29
freeswitch_click2dial/scripts/get_caller_name.py

@ -1,5 +1,8 @@
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# (c) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com>
# (c) 2014-2016 Trever L. Adams <trever.adams@gmail.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
"""
Name lookup in OpenERP for incoming and outgoing calls with an
FreeSWITCH system
@ -54,25 +57,9 @@
"""
__author__ = "Trever Adams <trever.adams@gmail.com>"
__date__ = "May 2016"
__date__ = "August 2016"
__version__ = "0.5"
# Copyright (C) 2014-2015 Trever L. Adams <trever.adams@gmail.com>
# Copyright (C) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
sys.path.append('.')
import xmlrpclib
@ -228,7 +215,7 @@ def main(name, phone_number, options):
# All SIP phones should support UTF-8...
# but in case you have analog phones over TDM
# or buggy phones, you should use the command line option --ascii
# or buggy phones, you should set options["ascii"] to True below
if options["ascii"]:
res = convert_to_ascii(res)
@ -249,7 +236,7 @@ def application(environ, start_response):
options["country"] = "US"
options["lang"] = "en"
options["ssl"] = False
options["ascii"] = True
options["ascii"] = False
options["max_size"] = 40
parameters = parse_qs(environ.get('QUERY_STRING', ''))
if 'number' in parameters:
@ -275,8 +262,10 @@ def application(environ, start_response):
except:
output = name
output = output.encode('utf-8')
status = '200 OK'
response_headers = [('Content-type', 'text/plain'),
response_headers = [('Content-type', 'text/plain; charset=utf-8'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Loading…
Cancel
Save