File: db_fifo.xml

package info (click to toggle)
kamailio 6.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 70,472 kB
  • sloc: ansic: 859,394; xml: 203,514; makefile: 9,688; sh: 9,105; sql: 8,571; yacc: 4,121; python: 3,086; perl: 2,955; java: 449; cpp: 289; javascript: 270; php: 258; ruby: 248; awk: 27
file content (288 lines) | stat: -rw-r--r-- 8,166 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<section id="db_fifo" xmlns:xi="http://www.w3.org/2001/XInclude">
    <sectioninfo>
	<revhistory>
	    <revision>
		<revnumber>$Revision$</revnumber>
		<date>$Date$</date>
	    </revision>
	</revhistory>
    </sectioninfo>

    <title>Database FIFO interface</title>

    <section id="db_fifo_intro">
	<title>Introduction</title>
	<para>
	<application>SER</application> offers to its module developers a common 
	DataBase(DB) interface, disregarding the database implementation (mysql, 
	dbtext or postgres) that lays beneath it.
	</para>
	<para>
	This feature is now extended and offered also to the 
	<application>SER</application> users/administrators by DataBase
	<acronym>FIFO</acronym> Interface (or DB FIFO interface). So,
	DB FIFO interface is an extension of the internal DB interface through the
	FIFO server. Everybody from outside <application>SER</application> can 
	operate SER's database (for adding/removing users, for manipulating 
	aliases, access control wrights, etc) using the same FIFO commands 
	without caring about the database type that's used by SER.
	</para>
    </section>

    <section id="advantages">
	<title>Advantages</title>
	<para>
	All external applications that need to work with SER's database (like 
	<application>serctl</application> or <application>serweb</application>) 
	can do so via DB FIFO interface without depending of a specific database 
	driver. No modifications will be required when a new type of database 
	will be added to <application>SER</application>.
	</para>
	<para>
	Also, this approach, prevents any kind of confusion between the database
	type used by <application>SER</application> and the one used by these 
	external applications. They will use automatically the same database as 
	<application>SER</application> is configure to use.
	</para>
    </section>
    

    <section id="limitations">
	<title>Limitations</title>
	<para>
	DB FIFO interface is restricted to the limitation of the internal DB
	interface.
	</para>
	<para>
	Also the size (can fit on only one line) and the content (\n or \r
	characters must be escaped) of a BLOB value is restricted.
	</para>
    </section>

    <section id="db_fifo_config">
	<title>Configuration</title>
	<para>
	FIFO server presents is required, so configure in your config file the FIFO
	file to be used by the <application>SER</application> FIFO server:
	<programlisting>
fifo="/tmp/ser_fifo"
	</programlisting>
	To enable the DB FIFO interface, it's required to load at least one 
	database module (available for the moment are mysql, dbtext and postgres).
	</para>
	<para>
	The database module that you want to use and the database configuration are
	configured via parameter <varname>fifo_db_url</varname>:
	<programlisting>
fifo_db_url="mysql:mysql_url"
fifo_db_url="dbtext:dbtext_url"
	</programlisting>
	The format of the database URL depends of the used database implementation
	(see the documentation for each DB type).
	</para>
	<para><emphasis>
	NOTE: be sure to load the module the is specified into fifo_db_url!
	</emphasis></para>
	<para>
	If no fifo_db_url is specified or no appropriate DB module found, the 
	DB FIFO interface will be disabled.
	</para>
    </section>


    <section id="db_fifo_commands">
	<title>DB FIFO commands</title>
	<para>
	From FIFO point of view, all DB FIFO commands are mapped with the 
	same name: <emphasis>DB</emphasis>. The first line of the command must 
	contain the name of the DB command. Available are:
	<itemizedlist>
		<listitem>
			<para>SELECT</para>
		</listitem>
		<listitem>
			<para>UPDATE</para>
		</listitem>
		<listitem>
			<para>INSERT</para>
		</listitem>
		<listitem>
			<para>DELETE</para>
		</listitem>
		<listitem>
			<para>RAW_QUERY</para>
		</listitem>
		<listitem>
			<para>EAW_QUERY_RES</para>
		</listitem>
	</itemizedlist>
	    The grammar used in the commands definition can be found in next
	    section "DB FIFO grammar". The presence of the
	    <varname>reply_fifo_file</varname> in the FIFO command is
	    <emphasis>required</emphasis> for all commands.
	</para>

	<section>
		<title><function>SELECT</function> command</title>
		<para>
		This function implements SELECT DB directive. Its syntax is:
		<programlisting>
:DB:reply_fifo_file
select
[COLUMN]*
.
TABLE_NAME
[CVP]
.
		</programlisting>
		If no CVP line is present, the whole table.will be returned. If no 
		COLUMN line is given, all table columns will be found in the result.
		</para>
		<para>
		The result of the query will be return via reply_fifo_file  in one 
		raw per line format (only requested columns), the first line being 
		the head of the table. The <emphasis>NULL</emphasis> values will be
		printed as "NULL".
		</para>
	</section>

	<section id="insert">
		<title><function>INSERT</function> command</title>
		<para>
		This function implements INSERT DB directive - inserts one row in 
		a table. Its syntax is:
		<programlisting>
:DB:reply_fifo_file
insert
TABLE_NAME
[EQUAL_CVP]+
.
		</programlisting>
		</para>
		<para>
		Command returns nothing if success or, other way, an error message.
		</para>
	</section>


	<section id="update">
		<title><function>UPDATE</function> command</title>
		<para>
		The function implements UPDATE DB directive - it is possible to 
		modify one or more rows in a table. Its syntax is:
		<programlisting>
:DB:reply_fifo_file
update
[EQUAL_CVP]+
.
TABLE_NAME
[CVP]*
.
		</programlisting>
		</para>
		<para>
		Command returns nothing if success or, other way, an error message.
		</para>
	</section>


	<section id="delete">
		<title><function>DELETE</function> command</title>
		<para>
		This function implements DELETE DB directive - it is possible to 
		delete one or more rows from a table. Its syntax is:
		<programlisting>
:DB:reply_fifo_file
delete
TABLE_NAME
[CVP]*
.
		</programlisting>
		If CVP list contain <emphasis>no lines, all rows will be
		deleted</emphasis> (table will be empty).
		</para>
		<para>
		Command returns nothing if success or, other way, an error message.
		</para>
	</section>


	<section id="raw_query">
		<title><function>RAW_QUERY</function> command</title>
		<para>
		This function sends a raw query directly to the database driver 
		without trying to understand the command. This command <emphasis>MUST
		NOT</emphasis> generate any response. Otherwise, the database driver 
		can block or desynchronize (depending of the driver).
		Its syntax is:
		<programlisting>
:DB:reply_fifo_file
raw_query
(ASCII)+
		</programlisting>
	    </para>
	    <para>
		Command returns nothing if success or, other way, an error message.
	    </para>
	</section>


	<section id="raw_query_res">
	    <title>
		<function>RAW_QUERY_RES</function> command
	    </title>
	    <para>
		This function sends a raw query directly to the database driver without
		trying to understand the command. This command <emphasis>MUST
		</emphasis> generate an response (even if an empty one). Otherwise, 
		the database driver can block or desynchronize (depending of the 
		driver). Its syntax is:
		<programlisting>
:DB:reply_fifo_file
raw_query_res
(ASCII)+
		</programlisting>
	    </para>
	    <para>
		Command's output format is identical with the one from 
		<function>SELECT</function> command.
	    </para>
	</section>
    </section>


    <section id="db_fifo_grammar">
	<title>DB FIFO grammar</title>
	<programlisting>
<![CDATA[
COLUMN=(alfa-numeric|'_')+

GAP=' '|'\t'

DEF_OP='='|'<'|'>'|'>='|'<='
UNDEF_OP=(ASCII)+
CAST_OP="int"|"double"|"string"|"date"|"blob"|"bitmap"

INT_VAL=integer number
DOUBLE_VAL=float number
STRING_VAL='"' ASCII* '"'
DATE_VAL='<' YEAR '-' MONTH '-' DAY ' ' HOUR ':' MINS ':' SECS '>'
BLOB_VAL=STRING_VAL
BITMAP_VAL=INT_VAL
NULL_VAL="null"

VALUE=('['CAST_OP']')?(INT_VAL|DOUBLE_VAL|STRING_VAL|DATE_VAL|
		BLOB_VAL|BITMAP_VAL|NULL_VAL)

CVP(column-value-pair)=
		(COLUMN GAP* DEF_OP GAP* VALUE) | (COLUMN GAP+ UNDEF_OP GAP+ VALUE)
EQUAL-CVP(column-equal-value-pair)=
		(COLUMN GAP* '=' GAP* VALUE)
]]>
	</programlisting>
    </section>
</section>