From 1aa4a579705b48782d545c18e9c84d75a938078e Mon Sep 17 00:00:00 2001 From: "Trever L. Adams" Date: Thu, 25 Aug 2016 21:26:52 -0600 Subject: [PATCH] Thank you to Alexandr Usov and Stanislav Sinyagin for testing and ideas. * Fix originate to handle Unicode via UTF-8. * Fix Open Caller to handle more situations and channel types. * get_caller_name.py and pop-up functionality now handle invalid numbers properly. * Other fixes that were already committed. --- .../freeswitch_click2dial.py | 35 ++++++++++++------- .../scripts/get_caller_name.py | 9 ++++- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/freeswitch_click2dial/freeswitch_click2dial.py b/freeswitch_click2dial/freeswitch_click2dial.py index cebd744..41f513f 100644 --- a/freeswitch_click2dial/freeswitch_click2dial.py +++ b/freeswitch_click2dial/freeswitch_click2dial.py @@ -175,22 +175,27 @@ class FreeSWITCHServer(models.Model): calling_party_number = False try: is_fq_res = user.resource.rfind('@') - if is_fq_res: - if len(user.resource) != is_fq_res: - is_fq_res = True - else: - is_fq_res = False - request = "channels like /" + re.sub(r'/', r':', user.resource) + \ + if is_fq_res > 0: + resource = user.resource[0:is_fq_res] + _logger.error("is_fq_res: %d, resource is %s\n", + is_fq_res, resource) + 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" ret = fs_manager.api('show', str(request)) f = json.load(StringIO.StringIO(ret.getBody())) if int(f['row_count']) > 0: - if (f['rows'][0]['cid_num'] == user.internal_number or - len(f['rows'][0]['cid_num']) < 3): - calling_party_number = f['rows'][0]['dest'] - else: - calling_party_number = f['rows'][0]['cid_num'] + for x in range(0, int(f['row_count'])): + if (is_fq_res and f['rows'][x]['presence_id'] != + user.resource): + continue + if (f['rows'][x]['cid_num'] == user.internal_number or + len(f['rows'][x]['cid_num']) < 3): + calling_party_number = f['rows'][x]['dest'] + else: + calling_party_number = f['rows'][x]['cid_num'] except Exception, e: _logger.error( "Error in the Status request to FreeSWITCH server %s", @@ -205,7 +210,10 @@ class FreeSWITCHServer(models.Model): fs_manager.disconnect() _logger.debug("Calling party number: '%s'", calling_party_number) - return calling_party_number + if isinstance(calling_party_number, int): + return calling_party_number + else: + return False @api.model def get_record_from_my_channel(self): @@ -374,7 +382,8 @@ class PhoneCommon(models.AbstractModel): if caller_number: if len(variable): variable += ',' - variable += 'effective_caller_id_number=\'' + caller_number + '\'' + variable += 'effective_caller_id_number=\'' + \ + caller_number + '\'' if fs_server.wait_time != 60: if len(variable): variable += ',' diff --git a/freeswitch_click2dial/scripts/get_caller_name.py b/freeswitch_click2dial/scripts/get_caller_name.py index aee7325..00a652f 100644 --- a/freeswitch_click2dial/scripts/get_caller_name.py +++ b/freeswitch_click2dial/scripts/get_caller_name.py @@ -83,6 +83,8 @@ import unicodedata # Name that will be displayed if there is no match # and no geolocalisation not_found_name = "Not in OpenERP" +# Name used if name and number are both empty +unknown_name = "unknown" # Set to 1 for debugging output verbose = 0 @@ -256,6 +258,8 @@ def application(environ, start_response): number = escape(parameters['number'][0]) if 'name' in parameters: name = escape(parameters['name'][0]) + else: + name = unknown_name if 'notify' in parameters: options["notify"] = [] for item in parameters['notify'][0].split(','): @@ -268,7 +272,10 @@ def application(environ, start_response): options["geoloc"] = True else: options["geoloc"] = False - output += main(name if name else False, number, options) + try: + output = main(name if name else False, number, options) + except: + output = name status = '200 OK' response_headers = [('Content-type', 'text/plain'),