opensips数据库

#include “../../db/db.h”

static int mod_init(void)
{
    LM_INFO("initializing...\n");
    init_db_url( db_url , 0 /*cannot be null*/);
    user_column.len = strlen(user_column.s);
    domain_column.len = strlen(domain_column.s);
    alias_domain_column.len = strlen(alias_domain_column.s);
    alias_user_column.len = strlen(alias_user_column.s);
    if (domain_prefix.s)
        domain_prefix.len = strlen(domain_prefix.s);

    /* Find a database module */
    if (db_bind_mod(&db_url, &adbf)) {
        LM_ERR("unable to bind database module\n");
        return -1;
    }
    if (!DB_CAPABILITY(adbf, DB_CAP_QUERY)) {
        LM_CRIT("database modules does not "
            "provide all functions needed by alias_db module\n");
        return -1;
    }

    return 0;
}

http://www.opensips.org/html/docs/modules/1.6.x/alias_db.html

ALIAS_DB Module

Daniel-Constantin Mierla

<team@voice-system.ro>
Elena-Ramona Modroiu

<team@voice-system.ro>
Edited by

Daniel-Constantin Mierla

<team@voice-system.ro>
Copyright © 2005-2009 voice-system.ro

Table of Contents

1. Admin Guide
1.1. Overview
1.2. Dependencies
1.2.1. OpenSIPS Modules
1.2.2. External Libraries or Applications
1.3. Exported Parameters
1.3.1. db_url (str)
1.3.2. user_column (str)
1.3.3. domain_column (str)
1.3.4. alias_user_column (str)
1.3.5. alias_domain_column (str)
1.3.6. domain_prefix (str)
1.3.7. append_branches (int)
1.4. Exported Functions
1.4.1. alias_db_lookup( table_name [,flags] )
1.4.2. alias_db_find( table_name , input, output [,flags] )
2. Frequently Asked Questions
List of Examples

1.1. Set db_url parameter
1.2. Set user_column parameter
1.3. Set domain_column parameter
1.4. Set alias_user_column parameter
1.5. Set alias_domain_column parameter
1.6. Set domain_prefix parameter
1.7. Set append_branches parameter
1.8. alias_db_lookup() usage
1.9. alias_db_find() usage
Chapter 1. Admin Guide

1.1. Overview

ALIAS_DB module can be used as an alternative for user aliases via usrloc. The main feature is that it does not store all adjacent data as for user location and always uses database for search (no memory caching).

Having no memory caching, search speed might decrease but provisioning is easier. With very fast databases like MySQL, speed penalty can be lowered. Also, search can be performed on different tables in the same script.

1.2. Dependencies

1.2.1. OpenSIPS Modules

The following modules must be loaded before this module:

database module (mysql, dbtext, ...).

1.2.2. External Libraries or Applications

The following libraries or applications must be installed before running OpenSIPS with this module loaded:

None.

1.3. Exported Parameters

1.3.1. db_url (str)

Database URL.

Default value is “mysql://opensipsro:opensipsro@localhost/opensips”.

Example 1.1. Set db_url parameter

...
modparam("alias_db", "db_url", "dbdriver://username:password@dbhost/dbname")
...

1.3.2. user_column (str)

Name of the column storing username.

Default value is “username”.

Example 1.2. Set user_column parameter

...
modparam("alias_db", "user_column", "susername")
...

1.3.3. domain_column (str)

Name of the column storing user's domain.

Default value is “domain”.

Example 1.3. Set domain_column parameter

...
modparam("alias_db", "domain_column", "sdomain")
...

1.3.4. alias_user_column (str)

Name of the column storing alias username.

Default value is “alias_username”.

Example 1.4. Set alias_user_column parameter

...
modparam("alias_db", "alias_user_column", "auser")
...

1.3.5. alias_domain_column (str)

Name of the column storing alias domain.

Default value is “alias_domain”.

Example 1.5. Set alias_domain_column parameter

...
modparam("alias_db", "alias_domain_column", "adomain")
...

1.3.6. domain_prefix (str)

Specifies the prefix to be stripped from the domain in R-URI before doing the search.

Default value isNULL”.

Example 1.6. Set domain_prefix parameter

...
modparam("alias_db", "domain_prefix", "sip.")
...

1.3.7. append_branches (int)

If the alias resolves to many SIP IDs, the first is replacing the R-URI, the rest are added as branches.

Default value is0” (0 - don't add branches; 1 - add branches).

Example 1.7. Set append_branches parameter

...
modparam("alias_db", "append_branches", 1)
...

1.4. Exported Functions

1.4.1.  alias_db_lookup( table_name [,flags] )

The function takes the R-URI and search to see whether it is an alias or not. If it is an alias for a local user, the R-URI is replaced with user's SIP uri.

The function returns TRUE if R-URI is alias and it was replaced by user's SIP uri.

Meaning of the parameters is as follows:

table_name - the name of the table where to search for alias. It can include pseudo-variables.

flags (optional) - set of flags (char based flags) to control the alias lookup process:

d - do not use domain URI part in the alias lookup query (use only a username-based lookup). By default, both username and domain are used.

r - do revers alias lookup - lookup for the alias mapped to the current URI (URI 2 alias translation); normally, the function looks up for the URI mapped to the alias (alias 2 URI translation).

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.

Example 1.8. alias_db_lookup() usage

...
alias_db_lookup("dbaliases" , "rd");
alias_db_lookup("dba_$(rU{s.substr,0,1})");
...

1.4.2.  alias_db_find( table_name , input, output [,flags] )

The function is very similar to alias_db_lookup(), but instead of using fixed input (RURI) and output (RURI) is able to get the input SIP URI from a pseudo-variable and place the result back also in a pseudo-variable.

The function is useful as the alias lookup does not affect the request itself (no RURI changes), can be used in a reply context (as it does not work with RURI only) and can be used for others URI than the RURI (To URI, From URI, custom URI).

The function returns TRUE if any alias mapping was found and returned.

Meaning of the parameters is as follows:

table_name - the name of the table where to search for alias. It can include pseudo-variables.

input - any PV (pseudo-variable) carrying the SIP URI that needs to be looked up.

ouput - PV (AVP or script VAR) where to place the SIP URI resulting from the alias lookup.

flags (optional) - set of flags (char based flags) to control the alias lookup process:

d - do not use domain URI part in the alias lookup query (use only a username-based lookup). By default, both username and domain are used.

r - do revers alias lookup - lookup for the alias mapped to the current URI (URI 2 alias translation); normally, the function looks up for the URI mapped to the alias (alias 2 URI translation).

This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, LOCAL_ROUTE, FAILURE_ROUTE and ONREPLY_ROUTE.

Example 1.9. alias_db_find() usage

...
# do revers alias lookup and find the alias for the FROM URI
alias_db_find("dbaliases" , "$fu", "$avp(s:from_alias)", "r");
...

Chapter 2. Frequently Asked Questions

2.1.

What happened with old use_domain parameter

The global parameter (affecting the entire module) was replaced with a per lookup parameter (affecting only current lookup). See the "d" (do not used domain part) flag in the db_alias_lookup() and db_alias_find() functions.

2.2.

How can I report a bug?

Please follow the guidelines provided at: https://github.com/OpenSIPS/opensips/issues.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值