| 1 |
unixodbc Module |
| 2 |
|
| 3 |
Marco Lorrai |
| 4 |
|
| 5 |
abbeynet.it |
| 6 |
|
| 7 |
Edited by |
| 8 |
|
| 9 |
Marco Lorrai |
| 10 |
|
| 11 |
Copyright © 2005, 2006 Marco Lorrai |
| 12 |
__________________________________________________________________ |
| 13 |
|
| 14 |
Table of Contents |
| 15 |
|
| 16 |
1. Admin Guide |
| 17 |
|
| 18 |
1. Overview |
| 19 |
2. Dependencies |
| 20 |
|
| 21 |
2.1. Kamailio Modules |
| 22 |
2.2. External Libraries or Applications |
| 23 |
|
| 24 |
3. Parameters |
| 25 |
|
| 26 |
3.1. ping_interval (int) |
| 27 |
3.2. auto_reconnect (int) |
| 28 |
3.3. use_escape_common (int) |
| 29 |
3.4. replace_query (int) |
| 30 |
3.5. quote_char (str) |
| 31 |
|
| 32 |
4. Functions |
| 33 |
5. Installation and Running |
| 34 |
|
| 35 |
5.1. Installing |
| 36 |
5.2. Configuring and Running |
| 37 |
|
| 38 |
2. Developer Guide |
| 39 |
|
| 40 |
List of Examples |
| 41 |
|
| 42 |
1.1. Set the “ping_interval” parameter |
| 43 |
1.2. Set the “auto_reconnect” parameter |
| 44 |
1.3. Set the “use_escape_common” parameter |
| 45 |
1.4. Set the “replace_query” parameter |
| 46 |
1.5. Set the “quote_char” parameter |
| 47 |
|
| 48 |
Chapter 1. Admin Guide |
| 49 |
|
| 50 |
Table of Contents |
| 51 |
|
| 52 |
1. Overview |
| 53 |
2. Dependencies |
| 54 |
|
| 55 |
2.1. Kamailio Modules |
| 56 |
2.2. External Libraries or Applications |
| 57 |
|
| 58 |
3. Parameters |
| 59 |
|
| 60 |
3.1. ping_interval (int) |
| 61 |
3.2. auto_reconnect (int) |
| 62 |
3.3. use_escape_common (int) |
| 63 |
3.4. replace_query (int) |
| 64 |
3.5. quote_char (str) |
| 65 |
|
| 66 |
4. Functions |
| 67 |
5. Installation and Running |
| 68 |
|
| 69 |
5.1. Installing |
| 70 |
5.2. Configuring and Running |
| 71 |
|
| 72 |
1. Overview |
| 73 |
|
| 74 |
This module allows to use the unixodbc package with Kamailio. It have |
| 75 |
been tested with mysql and the odbc connector, but it should work also |
| 76 |
with other database. The auth_db module works. |
| 77 |
|
| 78 |
For more information, see the http://www.unixodbc.org/ project web |
| 79 |
page. |
| 80 |
|
| 81 |
To see what DB engines can be used via unixodbc, look at |
| 82 |
http://www.unixodbc.org/drivers.html. |
| 83 |
|
| 84 |
2. Dependencies |
| 85 |
|
| 86 |
2.1. Kamailio Modules |
| 87 |
2.2. External Libraries or Applications |
| 88 |
|
| 89 |
2.1. Kamailio Modules |
| 90 |
|
| 91 |
The following modules must be loaded before this module: |
| 92 |
* No dependencies on other Kamailio modules. |
| 93 |
|
| 94 |
2.2. External Libraries or Applications |
| 95 |
|
| 96 |
The following libraries or applications must be installed before |
| 97 |
running Kamailio with this module loaded: |
| 98 |
* None. |
| 99 |
|
| 100 |
3. Parameters |
| 101 |
|
| 102 |
3.1. ping_interval (int) |
| 103 |
3.2. auto_reconnect (int) |
| 104 |
3.3. use_escape_common (int) |
| 105 |
3.4. replace_query (int) |
| 106 |
3.5. quote_char (str) |
| 107 |
|
| 108 |
3.1. ping_interval (int) |
| 109 |
|
| 110 |
Sets the ping time interval. |
| 111 |
|
| 112 |
Default value is “300” seconds. |
| 113 |
|
| 114 |
Example 1.1. Set the “ping_interval” parameter |
| 115 |
... |
| 116 |
modparam("db_unixodbc", "ping_interval", 600) |
| 117 |
... |
| 118 |
|
| 119 |
3.2. auto_reconnect (int) |
| 120 |
|
| 121 |
Turns on or off the auto_reconnect mode. |
| 122 |
|
| 123 |
Default value is “1”, this means it is enabled. |
| 124 |
|
| 125 |
Example 1.2. Set the “auto_reconnect” parameter |
| 126 |
... |
| 127 |
modparam("db_unixodbc", "auto_reconnect", 0) |
| 128 |
... |
| 129 |
|
| 130 |
3.3. use_escape_common (int) |
| 131 |
|
| 132 |
Escape values in query using internal escape_common() function. It |
| 133 |
escapes single quote ''', double quote '"', backslash '\', and NULL |
| 134 |
characters. |
| 135 |
|
| 136 |
You should enable this parameter if you know that the ODBC driver |
| 137 |
considers the above characters as special (for marking begin and end of |
| 138 |
a value, escape other characters ...). It prevents against SQL |
| 139 |
injection. |
| 140 |
|
| 141 |
Default value is “0” (0 = disabled; 1 = enabled). |
| 142 |
|
| 143 |
Example 1.3. Set the “use_escape_common” parameter |
| 144 |
... |
| 145 |
modparam("db_unixodbc", "use_escape_common", 1) |
| 146 |
... |
| 147 |
|
| 148 |
3.4. replace_query (int) |
| 149 |
|
| 150 |
Tells if the ODBC replace query is supported by the DB odbc driver. |
| 151 |
|
| 152 |
Default value is “1” seconds. |
| 153 |
|
| 154 |
Example 1.4. Set the “replace_query” parameter |
| 155 |
... |
| 156 |
modparam("db_unixodbc", "replace_query", 0) |
| 157 |
... |
| 158 |
|
| 159 |
3.5. quote_char (str) |
| 160 |
|
| 161 |
The character to be used for quoting the table and column names in |
| 162 |
database queries. |
| 163 |
|
| 164 |
Default value: “not set” (no quoting). |
| 165 |
|
| 166 |
Example 1.5. Set the “quote_char” parameter |
| 167 |
... |
| 168 |
modparam("db_unixodbc", "quote_char", "`") |
| 169 |
... |
| 170 |
|
| 171 |
4. Functions |
| 172 |
|
| 173 |
NONE |
| 174 |
|
| 175 |
5. Installation and Running |
| 176 |
|
| 177 |
5.1. Installing |
| 178 |
5.2. Configuring and Running |
| 179 |
|
| 180 |
5.1. Installing |
| 181 |
|
| 182 |
Prerequirement: you should first install unixodbc (or another program |
| 183 |
that implements the odbc standard, such iodbc), your database, and the |
| 184 |
right connector. Set the DSN in the odbc.ini file and the connector |
| 185 |
drivers in the odbcinst.ini file. |
| 186 |
|
| 187 |
5.2. Configuring and Running |
| 188 |
|
| 189 |
In the kamailio.cfg file, add the line: |
| 190 |
.... |
| 191 |
loadmodule "/usr/local/lib/kamailio/modules/db_unixodbc.so" |
| 192 |
.... |
| 193 |
|
| 194 |
You should also uncomment this: |
| 195 |
.... |
| 196 |
loadmodule "/usr/local/lib/kamailio/modules/auth.so" |
| 197 |
loadmodule "/usr/local/lib/kamailio/modules/auth_db.so" |
| 198 |
modparam("usrloc", "db_mode", 2) |
| 199 |
modparam("auth_db", "calculate_ha1", yes) |
| 200 |
modparam("auth_db", "password_column", "password") |
| 201 |
.... |
| 202 |
|
| 203 |
and setting the DSN specified in the odbc.ini, inserting this with the |
| 204 |
url adding this line: |
| 205 |
.... |
| 206 |
modparam("usrloc|auth_db", "db_url", |
| 207 |
"unixodbc://kamailio:kamailiorw@localhost/my_dsn") |
| 208 |
.... |
| 209 |
|
| 210 |
replacing my_dsn with the correct value. |
| 211 |
|
| 212 |
HINT: if unixodbc don't want to connect to mysql server, try restarting |
| 213 |
mysql server with: |
| 214 |
shell>safe_mysqld --user=mysql --socket=/var/lib/mysql/mysql.sock |
| 215 |
|
| 216 |
The connector search the socket in /var/lib/mysql/mysql.sock and not in |
| 217 |
/tmp/mysql.sock |
| 218 |
|
| 219 |
REMARK: Oracle ODBC driver doesn't support ODBC query. To disable its |
| 220 |
usage and replace the replace query by an update or insert query, use |
| 221 |
the parameter: |
| 222 |
.... |
| 223 |
modparam("db_unixodbc", "replace_query", 0) |
| 224 |
.... |
| 225 |
|
| 226 |
Chapter 2. Developer Guide |
| 227 |
|
| 228 |
The module implements the Kamailio DB API, in order to be used by other |
| 229 |
modules. |