Exemplo n.º 1
0
def provide_route(method, request_uri, headers, transport_type, body, cookies, new_headers):
    '''Process a request URI and return the target URI(s)'''
    resip.log_debug('request_uri = ' + request_uri)

    _request_uri = urlparse(request_uri)

    routes = list()
    
    # Basic LDAP server parameters:
    server_uri = 'ldaps://ldap.example.org'
    base_dn = "dc=example,dc=org"

    # this domain will be appended to the phone numbers when creating
    # the target URI:
    phone_domain = 'pbx.example.org'

    # urlparse is not great for "sip:" URIs,
    # the user@host portion is in the 'path' element:
    filter = "(&(objectClass=inetOrgPerson)(mail=%s))" % _request_uri.path

    resip.log_debug("Using filter: %s" % filter)

    try:
        con = ldap.initialize(server_uri)

        scope = ldap.SCOPE_SUBTREE
        retrieve_attributes = None
        result_id = con.search(base_dn, scope, filter, retrieve_attributes)
        result_set = []
        while 1:
            timeout = 1
            result_type, result_data = con.result(result_id, 0, None)
            if (result_data == []):
                break
            else:
                if result_type == ldap.RES_SEARCH_ENTRY:
                    result_set.append(result_data)

        if len(result_set) == 0:
            resip.log_debug("No Results.")
            return routes
        for i in range(len(result_set)):
            for entry in result_set[i]:
                if entry[1].has_key('telephoneNumber'):
                    phone = entry[1]['telephoneNumber'][0]
                    routes.append('sip:' + phone + '@' + phone_domain)

    except ldap.LDAPError as e:
        errno, error_message = e.args
        resip.log_err("Couldn't Connect. %s " % error_message)
        return (500)

    return routes
Exemplo n.º 2
0
def provide_route(method, request_uri, headers, transport_type, body, cookies, new_headers):
    '''Process a request URI and return the target URI(s)'''
    resip.log_debug('request_uri = ' + request_uri)

    _request_uri = urlparse(request_uri)

    routes = list()
    
    # Basic LDAP server parameters:
    server_uri = 'ldaps://ldap.example.org'
    base_dn = "dc=example,dc=org"

    # this domain will be appended to the phone numbers when creating
    # the target URI:
    phone_domain = 'pbx.example.org'

    # urlparse is not great for "sip:" URIs,
    # the user@host portion is in the 'path' element:
    filter = "(&(objectClass=inetOrgPerson)(mail=%s))" % _request_uri.path

    resip.log_debug("Using filter: %s" % filter)

    try:
        con = ldap.initialize(server_uri)

        scope = ldap.SCOPE_SUBTREE
        retrieve_attributes = None
        result_id = con.search(base_dn, scope, filter, retrieve_attributes)
        result_set = []
        while 1:
            timeout = 1
            result_type, result_data = con.result(result_id, 0, None)
            if (result_data == []):
                break
            else:
                if result_type == ldap.RES_SEARCH_ENTRY:
                    result_set.append(result_data)

        if len(result_set) == 0:
            resip.log_debug("No Results.")
            return routes
        for i in range(len(result_set)):
            for entry in result_set[i]:
                if entry[1].has_key('telephoneNumber'):
                    phone = entry[1]['telephoneNumber'][0]
                    routes.append('sip:' + phone + '@' + phone_domain)

    except ldap.LDAPError, error_message:
        resip.log_err("Couldn't Connect. %s " % error_message)
        return (500)
Exemplo n.º 3
0
def on_load():
    '''Do initialisation when module loads'''
    resip.log_debug('on_load invoked')
Exemplo n.º 4
0
def on_load():
    '''Do initialisation when module loads'''
    resip.log_debug('on_load invoked')
Exemplo n.º 5
0
def provide_route(method, request_uri, headers, transport_type, body, cookies, new_headers):
    '''Process a request URI and return the target URI(s)'''

    resip.log_debug('method = ' + method)
    resip.log_debug('request_uri = ' + request_uri)
    resip.log_debug('From = ' + headers["From"])
    resip.log_debug('To = ' + headers["To"])
    resip.log_debug('transport_type = ' + transport_type)
    resip.log_debug('body = ' + body)
    resip.log_debug('len(cookies) = %d' % len(cookies))
    if 'WSSessionInfo' in cookies:
        resip.log_debug('found cookie WSSessionInfo = ' + cookies['WSSessionInfo'])

    # This is how we can signal an error to the caller:
    if method == 'MESSAGE':
        return (500, 'No MESSAGE for me')

    routes = list()
    routes.append('sip:[email protected]')
    routes.append('sip:[email protected]')

    new_headers['To'] = 'sip:[email protected]';
    new_headers['X-Foo'] = 'Bar';

    return routes