Example #1
0
def check_result2(params, consoleMsg=True):
    """just like check_result() above, except the result can be non-digits.
    or even empty.
    """
    params = params.rstrip()
    if re.search('^200',params):
        result = re.search('result=(.*)',params)
        if result:
            return result.group(1)
        return ''
    else:
        if consoleMsg:
            info = "dsh_agi.check_result: " + \
                   "FAIL (unexpected result '%s')" % params
            dsh_utils.give_bad_news2(info, logging.error)
        return None
Example #2
0
def read_env(consoleMsg=True):
    """reads AGI environment variables at the beginning of a call."""
    env = {}
    while 1:
        line = sys.stdin.readline().strip()
        if line == '':
            break

        
        #
        # ryw:
        # bad format. not splittable.
        # this is because I found a line that looks like this:
        # agi_channel: IAX2/127.0.0.1:35456-14868
        #
        #key,data = line.split(':')
        success,key,data = split_line(line)
        if not success:
            info = 'dsh_agi.read_env: bad line: ' + line
            dsh_utils.give_bad_news2(info, logging.warning)
            continue
            
        if key[:4] <> 'agi_':
            #skip input that doesn't begin with agi_
            info = 'dsh_agi.read_env: invalid key: ' + key[:4]
            dsh_utils.give_bad_news2(info, logging.warning)
            continue
        key = key.strip()
        data = data.strip()
        if key <> '':
            env[key] = data

    keys2skip = ['agi_rdnis', 'agi_uniqueid', 'agi_language', 'agi_callington',
                 'agi_callingtns', 'agi_accountcode', 
                 'agi_enhanced', 'agi_callingpres', 'agi_callingani2',
                 'agi_dnid', 'agi_rdnis', 'agi_priority']
                 
    if consoleMsg:
        info = "dsh_agi.read_env: AGI Environment Dump:"
        dsh_utils.give_news(info, logging.info)
        for key in env.keys():
            if key in keys2skip:
                continue
            info = " -- %s = %s" % (key, env[key])
            dsh_utils.give_news(info, logging.info)

    return env
Example #3
0
def check_result(params, consoleMsg=True):
    params = params.rstrip()
    if re.search('^200',params):
        result = re.search('result=(\d+)',params)
        if (not result):
            if consoleMsg:
                info = "dsh_agi.check_result: FAIL ('%s')" % params
                dsh_utils.give_bad_news2(info, logging.error)
            return -1
        else:
            result = result.group(1)
            if consoleMsg:
                info = "dsh_agi.check_result: PASS (%s)" % result
                dsh_utils.give_good_news(info, logging.info)
            return result
    else:
        if consoleMsg:
            info = "dsh_agi.check_result: " + \
                   "FAIL (unexpected result '%s')" % params
            dsh_utils.give_bad_news2(info, logging.error)
        return -2
Example #4
0
def check_result(params, consoleMsg=True):
    """copied from the star fish book.  looking for number results.
    the Asterisk response looks like '200 result=1'.
    """
    params = params.rstrip()
    if re.search('^200',params):
        result = re.search('result=(\d+)',params)
        if (not result):
            if consoleMsg:
                info = "dsh_agi.check_result: FAIL ('%s')" % params
                dsh_utils.give_bad_news2(info, logging.error)
            return -1
        else:
            result = result.group(1)
            if consoleMsg:
                info = "dsh_agi.check_result: PASS (%s)" % result
                dsh_utils.give_good_news(info, logging.info)
            return result
    else:
        if consoleMsg:
            info = "dsh_agi.check_result: " + \
                   "FAIL (unexpected result '%s')" % params
            dsh_utils.give_bad_news2(info, logging.error)
        return -2