• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..15-Apr-2021-

doc/H15-Apr-2021-697641

MakefileH A D15-Apr-2021553 2813

READMEH A D15-Apr-202114.8 KiB528391

db_text.cH A D15-Apr-20216.9 KiB249175

db_text.hH A D15-Apr-20212.2 KiB10122

dbt_api.cH A D15-Apr-20216.9 KiB320218

dbt_api.hH A D15-Apr-20211.3 KiB4612

dbt_base.cH A D15-Apr-202117.2 KiB868598

dbt_file.cH A D15-Apr-202117.4 KiB693589

dbt_lib.cH A D15-Apr-202110.2 KiB520395

dbt_lib.hH A D15-Apr-20214 KiB154100

dbt_raw_query.cH A D15-Apr-202112.7 KiB552425

dbt_raw_query.hH A D15-Apr-20211.2 KiB419

dbt_raw_util.cH A D15-Apr-20216.2 KiB279199

dbt_raw_util.hH A D15-Apr-20211.2 KiB4111

dbt_res.cH A D15-Apr-202121.8 KiB995798

dbt_res.hH A D15-Apr-20212.5 KiB7839

dbt_tb.cH A D15-Apr-20219.8 KiB494358

dbt_util.cH A D15-Apr-20211.2 KiB5018

dbt_util.hH A D15-Apr-2021949 345

README

1DBTEXT Module
2
3Daniel-Constantin Mierla
4
5   <miconda@gmail.com>
6
7Edited by
8
9Ovidiu Sas
10
11   <osas@voipembedded.com>
12
13Daniel-Constantin Mierla
14
15   <miconda@gmail.com>
16
17Olle E. Johansson
18
19   <oej@edvina.net>
20
21   Copyright © 2003, 2004 FhG FOKUS
22     __________________________________________________________________
23
24   Table of Contents
25
26   1. Admin Guide
27
28        1. Overview
29
30              1.1. Design of dbtext engine
31              1.2. Internal format of a dbtext table
32
33        2. Known limitations
34        3. Dependencies
35
36              3.1. Kamailio modules
37              3.2. External libraries or applications
38
39        4. Parameters
40
41              4.1. db_mode (integer)
42              4.2. db_delim (string)
43              4.3. default_connection (string)
44              4.4. emptystring (integer)
45              4.5. file_buffer_size (integer)
46              4.6. max_result_rows (integer)
47
48        5. Exported RPC Functions
49
50              5.1. db_text.dump
51              5.2. db_text.query
52
53        6. Installation and Running
54
55              6.1. Using db_text with a basic Kamailio configuration
56
57   2. Developer Guide
58
59   List of Examples
60
61   1.1. Sample of a dbtext table
62   1.2. Minimal Kamailio location dbtext table definition
63   1.3. Minimal Kamailio subscriber dbtext table example
64   1.4. Set db_mode parameter
65   1.5. Set db_mode parameter
66   1.6. Set default_connection parameter
67   1.7. Set emptystring parameter
68   1.8. Set file_buffer_size parameter
69   1.9. Set max_result_rows parameter
70   1.10. Load the dbtext module
71   1.11. Definition of 'subscriber' table (one line)
72   1.12. Definition of 'location' and 'aliases' tables (one line)
73   1.13. Definition of 'version' table and sample records
74   1.14. Configuration file
75
76Chapter 1. Admin Guide
77
78   Table of Contents
79
80   1. Overview
81
82        1.1. Design of dbtext engine
83        1.2. Internal format of a dbtext table
84
85   2. Known limitations
86   3. Dependencies
87
88        3.1. Kamailio modules
89        3.2. External libraries or applications
90
91   4. Parameters
92
93        4.1. db_mode (integer)
94        4.2. db_delim (string)
95        4.3. default_connection (string)
96        4.4. emptystring (integer)
97        4.5. file_buffer_size (integer)
98        4.6. max_result_rows (integer)
99
100   5. Exported RPC Functions
101
102        5.1. db_text.dump
103        5.2. db_text.query
104
105   6. Installation and Running
106
107        6.1. Using db_text with a basic Kamailio configuration
108
1091. Overview
110
111   1.1. Design of dbtext engine
112   1.2. Internal format of a dbtext table
113
114   The module implements a simplified database engine based on text files.
115   It can be used by Kamailio DB interface instead of other database
116   module (like MySQL).
117
118   The module is meant for use in demos or small devices that do not
119   support other DB modules. It keeps everything in memory and if you deal
120   with large amount of data you may run out of memory quickly. Also, it
121   does not implement all standard database facilities (like order by), it
122   includes minimal functionality to work properly (who knows ?!?) with
123   Kamailio.
124
125   NOTE: the timestamp is printed in an integer value from time_t
126   structure. If you use it in a system that cannot do this conversion, it
127   will fail (support for such situation is in to-do list).
128
129   NOTE: even when db_text is in non-caching mode, the module does not
130   write back to hard drive after changes. In this mode, the module checks
131   if the corresponding file on disk has changed, and reloads it. The
132   write to disk happens at Kamailio shut down. If db_text is in caching
133   mode, many "reload" functions in various modules will not work.
134
1351.1. Design of dbtext engine
136
137   The dbtext database system architecture:
138     * A database is represented by a directory in the local file system.
139       NOTE: when you use dbtext in Kamailio, the database URL for modules
140       must be the path to the directory where the table-files are
141       located, prefixed by “text://”, e.g., “text:///var/dbtext/ser”. If
142       there is no “/” after “text://” then “CFG_DIR/” is inserted at the
143       beginning of the database path. So, either you provide an absolute
144       path to database directory or a relative one to “CFG_DIR”
145       directory.
146       Do not forget that all databases in Kamailio needs the “version”
147       table.
148     * A table is represented by a text file inside database directory.
149
1501.2. Internal format of a dbtext table
151
152   The first line is the definition of the columns. Each column must be
153   declared in the following format:
154     * the name of column must not include white spaces.
155     * the format of a column definition is: name(type,attr).
156     * between two column definitions must be a white space, e.g.,
157       “first_name(str) last_name(str)”.
158     * the type of a column can be:
159          + int - integer numbers.
160          + double - real numbers with two decimals.
161          + str - strings with maximum size of 4KB.
162     * a column can have one of the attributes:
163          + auto - only for 'int' columns, the maximum value in that
164            column is incremented and stored in this field if it is not
165            provided in queries.
166          + null - accept null values in column fields.
167          + if no attribute is set, the fields of the column cannot have
168            null value.
169     * each other line is a row with data. The line ends with “\n”.
170     * the fields are separated by “:”.
171     * no value between two ':' (or between ':' and start/end of a row)
172       means “null” value. If the parameter "emptystring" is enabled,
173       db_text sets a NULL string to an empty string value.
174     * next characters must be escaped in strings: “\n”, “\r”, “\t”, “:”.
175     * 0 -- the zero value must be escaped too.
176
177   Example 1.1. Sample of a dbtext table
178...
179id(int,auto) name(str) flag(double) desc(str,null)
1801:nick:0.34:a\tgood\: friend
1812:cole:-3.75:colleague
1823:bob:2.50:
183...
184
185   Example 1.2. Minimal Kamailio location dbtext table definition
186...
187username(str) contact(str) expires(int) q(double) callid(str) cseq(int)
188...
189
190   Example 1.3. Minimal Kamailio subscriber dbtext table example
191...
192username(str) password(str) ha1(str) domain(str) ha1b(str)
193suser:supasswd:xxx:alpha.org:xxx
194...
195
1962. Known limitations
197
198   This database interface does not support data insertion with default
199   values. All such values specified in the database template are ignored.
200   So its advisable to specify all data for a column at insertion
201   operations.
202
2033. Dependencies
204
205   3.1. Kamailio modules
206   3.2. External libraries or applications
207
2083.1. Kamailio modules
209
210   These modules must be loaded before this module:
211     * none.
212
2133.2. External libraries or applications
214
215   These libraries or applications must be installed before running
216   Kamailio with this module:
217     * none.
218
2194. Parameters
220
221   4.1. db_mode (integer)
222   4.2. db_delim (string)
223   4.3. default_connection (string)
224   4.4. emptystring (integer)
225   4.5. file_buffer_size (integer)
226   4.6. max_result_rows (integer)
227
2284.1. db_mode (integer)
229
230   Set caching mode (0) or non-caching mode (1). In caching mode, data is
231   loaded at startup. In non-caching mode, the module check every time a
232   table is requested whether the corresponding file on disk has changed,
233   and if yes, will re-load the table from file.
234
235   Default value is “0”.
236
237   Example 1.4. Set db_mode parameter
238...
239modparam("db_text", "db_mode", 1)
240...
241
2424.2. db_delim (string)
243
244   Set the delimiter inside the db_text file.
245
246   Default value is “:”.
247
248   Example 1.5. Set db_mode parameter
249...
250modparam("db_text", "db_delim", "|")
251...
252
2534.3. default_connection (string)
254
255   connection for use with rpc query command.
256
257   Default value is “none” (off).
258
259   Example 1.6. Set default_connection parameter
260                    ...
261                    modparam("db_text", "default_connection", "text:///var/db/ka
262mailio/dbtext")
263                    ...
264
2654.4. emptystring (integer)
266
267   db_text by default handles an empty string as a NULL value. Some
268   modules, like the dialplan module, does not accept NULL strings. If you
269   enable emptystring an empty string will not be NULL, but an empty
270   string.
271
272   Default value is “0” (off).
273
274   Example 1.7. Set emptystring parameter
275...
276modparam("db_text", "emptystring", 1)
277...
278
2794.5. file_buffer_size (integer)
280
281   size of the buffer used to read the text file. Some presence tables
282   have columns with large content.
283
284   Default value is “16384”.
285
286   Example 1.8. Set file_buffer_size parameter
287...
288modparam("db_text", "file_buffer_size", 8192)
289...
290
2914.6. max_result_rows (integer)
292
293   number of rows to read from the text file.
294
295   Default value is “100000”.
296
297   Example 1.9. Set max_result_rows parameter
298...
299modparam("db_text", "max_result_rows", 1000000)
300...
301
3025. Exported RPC Functions
303
304   5.1. db_text.dump
305   5.2. db_text.query
306
3075.1.  db_text.dump
308
309   Write back to hard drive all modified tables.
310
311   Name: db_text.dump
312
313   Parameters: none
314
315   RPC Command Format:
316        kamcmd db_text.dump
317
3185.2.  db_text.query
319
320   run sql command
321
322   Name: db_text.query
323
324   Parameters: sqlcmd
325
326   RPC Command Format:
327            kamcmd db_text.query 'select * from location where username="xxx"'
328
3296. Installation and Running
330
331   6.1. Using db_text with a basic Kamailio configuration
332
333   Compile the module and load it instead of mysql or other DB modules.
334
335   REMINDER: when you use text in Kamailio, the database URL for modules
336   must be the path to the directory where the table-files are located,
337   prefixed by “text://”, e.g., “text:///var/dbtext/ser”. If there is no
338   “/” after “text://” then “CFG_DIR/” is inserted at the beginning of the
339   database path. So, either you provide an absolute path to database
340   directory or a relative one to “CFG_DIR” directory.
341
342   Example 1.10. Load the dbtext module
343...
344loadmodule "/path/to/kamailio/modules_k/db_text.so"
345...
346modparam("module_name", "db_url", "text:///path/to/dbtext/database")
347...
348
3496.1. Using db_text with a basic Kamailio configuration
350
351   Here are definitions for the most important tables as well as a basic
352   configuration file to use db_text with Kamailio. The table structures
353   may change in time and you will have to adjust these examples. Check
354   the source code directory “utils/kamctl/dbtext/kamailio” for current
355   definitions.
356
357   You have to populate the table 'subscriber' by hand with user profiles
358   in order to have authentication. To use with the given configuration
359   file, the table files must be placed in the '/tmp/serdb' directory.
360
361   Example 1.11. Definition of 'subscriber' table (one line)
362...
363username(str) domain(str) password(str) first_name(str) last_name(str) phone(str
364) email_address(str) datetime_created(int) datetime_modified(int) confirmation(s
365tr) flag(str) sendnotification(str) greeting(str) ha1(str) ha1b(str) perms(str)
366allow_find(str) timezone(str,null) rpid(str,null)
367...
368
369   Example 1.12. Definition of 'location' and 'aliases' tables (one line)
370...
371username(str) domain(str,null) contact(str,null) received(str) expires(int,null)
372 q(double,null) callid(str,null) cseq(int,null) last_modified(str) flags(int) us
373er_agent(str) socket(str)
374...
375
376   Example 1.13. Definition of 'version' table and sample records
377...
378table_name(str) table_version(int)
379subscriber:3
380location:6
381aliases:6
382...
383
384   Example 1.14. Configuration file
385...
386#
387#
388# simple quick-start config script with dbtext
389#
390
391# ----------- global configuration parameters ------------------------
392
393#debug=3         # debug level (cmd line: -ddd)
394#fork=yes
395#log_stderror=no        # (cmd line: -E)
396
397check_via=no    # (cmd. line: -v)
398dns=no          # (cmd. line: -r)
399rev_dns=no      # (cmd. line: -R)
400children=4
401
402listen=10.100.100.1
403port=5060
404
405# ------------------ module loading ----------------------------------
406
407# use dbtext database
408loadmodule "modules/dbtext/dbtext.so"
409
410loadmodule "modules/sl/sl.so"
411loadmodule "modules/tm/tm.so"
412loadmodule "modules/rr/rr.so"
413loadmodule "modules/maxfwd/maxfwd.so"
414loadmodule "modules/usrloc/usrloc.so"
415loadmodule "modules/registrar/registrar.so"
416loadmodule "modules/textops/textops.so"
417loadmodule "modules/jonrpcs/jsonrpcs.so"
418
419# modules for digest authentication
420loadmodule "modules/auth/auth.so"
421loadmodule "modules/auth_db/auth_db.so"
422
423# ----------------- setting module-specific parameters ---------------
424
425# -- usrloc params --
426
427# use dbtext database for persistent storage
428modparam("usrloc", "db_mode", 2)
429modparam("usrloc|auth_db", "db_url", "db_text:///tmp/kamailiodb")
430
431# -- auth params --
432#
433modparam("auth_db", "calculate_ha1", 1)
434modparam("auth_db", "password_column", "password")
435modparam("auth_db", "user_column", "username")
436modparam("auth_db", "domain_column", "domain")
437
438# -- rr params --
439# add value to ;lr param to make some broken UAs happy
440modparam("rr", "enable_full_lr", 1)
441
442# -------------------------  request routing logic -------------------
443
444# main routing logic
445
446route{
447    # initial sanity checks -- messages with
448    # max_forwards==0, or excessively long requests
449    if (!mf_process_maxfwd_header("10")) {
450        sl_send_reply("483","Too Many Hops");
451        exit;
452    };
453    if (msg:len >=  max_len ) {
454        sl_send_reply("513", "Message too big");
455        exit;
456    };
457
458    # we record-route all messages -- to make sure that
459    # subsequent messages will go through our proxy; that's
460    # particularly good if upstream and downstream entities
461    # use different transport protocol
462    if (!method=="REGISTER") record_route();
463
464    # subsequent messages withing a dialog should take the
465    # path determined by record-routing
466    if (loose_route()) {
467        # mark routing logic in request
468        append_hf("P-hint: rr-enforced\r\n");
469        route(1);
470        exit;
471    };
472
473    if (!uri==myself) {
474        # mark routing logic in request
475        append_hf("P-hint: outbound\r\n");
476        route(1);
477        exit;
478    };
479
480    # if the request is for other domain use UsrLoc
481    # (in case, it does not work, use the following command
482    # with proper names and addresses in it)
483    if (uri==myself) {
484        if (method=="REGISTER") {
485            # digest authentication
486            if (!www_authorize("", "subscriber")) {
487                www_challenge("", "0");
488                exit;
489            };
490
491            save("location");
492            exit;
493        };
494
495        lookup("aliases");
496        if (!uri==myself) {
497            append_hf("P-hint: outbound alias\r\n");
498            route(1);
499            exit;
500        };
501
502        # native SIP destinations are handled using our USRLOC DB
503        if (!lookup("location")) {
504            sl_send_reply("404", "Not Found");
505            exit;
506        };
507    };
508    append_hf("P-hint: usrloc applied\r\n");
509    route(1);
510}
511
512route[1]
513{
514    # send it out now; use stateful forwarding as it works reliably
515    # even for UDP2TCP
516    if (!t_relay()) {
517        sl_reply_error();
518    };
519}
520
521
522...
523
524Chapter 2. Developer Guide
525
526   Once you have the module loaded, you can use the API specified by
527   Kamailio DB interface.
528