Browse Source

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.
pull/96/head
Trever L. Adams 8 years ago
parent
commit
1aa4a57970
  1. 35
      freeswitch_click2dial/freeswitch_click2dial.py
  2. 9
      freeswitch_click2dial/scripts/get_caller_name.py

35
freeswitch_click2dial/freeswitch_click2dial.py

@ -175,22 +175,27 @@ class FreeSWITCHServer(models.Model):
calling_party_number = False calling_party_number = False
try: try:
is_fq_res = user.resource.rfind('@') 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 user.freeswitch_chan_type == "FreeTDM" else "@")
if not is_fq_res else "") + " as json" if not is_fq_res else "") + " as json"
ret = fs_manager.api('show', str(request)) ret = fs_manager.api('show', str(request))
f = json.load(StringIO.StringIO(ret.getBody())) f = json.load(StringIO.StringIO(ret.getBody()))
if int(f['row_count']) > 0: 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: except Exception, e:
_logger.error( _logger.error(
"Error in the Status request to FreeSWITCH server %s", "Error in the Status request to FreeSWITCH server %s",
@ -205,7 +210,10 @@ class FreeSWITCHServer(models.Model):
fs_manager.disconnect() fs_manager.disconnect()
_logger.debug("Calling party number: '%s'", calling_party_number) _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 @api.model
def get_record_from_my_channel(self): def get_record_from_my_channel(self):
@ -374,7 +382,8 @@ class PhoneCommon(models.AbstractModel):
if caller_number: if caller_number:
if len(variable): if len(variable):
variable += ',' variable += ','
variable += 'effective_caller_id_number=\'' + caller_number + '\''
variable += 'effective_caller_id_number=\'' + \
caller_number + '\''
if fs_server.wait_time != 60: if fs_server.wait_time != 60:
if len(variable): if len(variable):
variable += ',' variable += ','

9
freeswitch_click2dial/scripts/get_caller_name.py

@ -83,6 +83,8 @@ import unicodedata
# Name that will be displayed if there is no match # Name that will be displayed if there is no match
# and no geolocalisation # and no geolocalisation
not_found_name = "Not in OpenERP" not_found_name = "Not in OpenERP"
# Name used if name and number are both empty
unknown_name = "unknown"
# Set to 1 for debugging output # Set to 1 for debugging output
verbose = 0 verbose = 0
@ -256,6 +258,8 @@ def application(environ, start_response):
number = escape(parameters['number'][0]) number = escape(parameters['number'][0])
if 'name' in parameters: if 'name' in parameters:
name = escape(parameters['name'][0]) name = escape(parameters['name'][0])
else:
name = unknown_name
if 'notify' in parameters: if 'notify' in parameters:
options["notify"] = [] options["notify"] = []
for item in parameters['notify'][0].split(','): for item in parameters['notify'][0].split(','):
@ -268,7 +272,10 @@ def application(environ, start_response):
options["geoloc"] = True options["geoloc"] = True
else: else:
options["geoloc"] = False 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' status = '200 OK'
response_headers = [('Content-type', 'text/plain'), response_headers = [('Content-type', 'text/plain'),

Loading…
Cancel
Save