-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
338 lines (213 loc) · 7.08 KB
/
README
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
siplua Module
Eric Gouyer / Arnaud Chong
Edited by
Eric Gouyer / Arnaud Chong
Copyright © 2006-20011
__________________________________________________________
Table of Contents
1. Admin Guide
1.1. Overview
1.2. Installing the module
1.3. Using the module
1.4. Dependencies
1.4.1. OpenSIPS Modules
1.4.2. External Libraries or Applications
1.5. Exported Parameters
1.5.1. luafilename (string)
1.5.2. lua_user_debug (int)
1.5.3. warn_missing_free_fixup (int)
1.5.4. lua_allocator (string)
1.6. Exported Functions
1.6.1. lua_exec(func, [param])
1.6.2. lua_meminfo()
2. OpenSIPS Lua API
2.1. Available Functions
2.1.1. xdbg(message)
2.1.2. xlog(level,message)
2.1.3. setUserDebug
2.1.4. WarnMissingFreeFixup
2.1.5. getpid
2.1.6. getmem
2.1.7 getmeminfo
2.1.8. gethostname
2.1.9. getType
2.1.10. getURI_User
2.1.11. getExpires
2.1.12. getHeader
2.1.13. getContact
2.1.14. moduleFunc
2.1.15. getStatus
2.1.16. getMethod
2.1.17. getSrcIp
2.1.18. getDstIp
2.1.19. AVP_get
2.1.20. AVP_set
2.1.21. AVP_destroy
2.1.22. pseudoVar
2.1.23. add_lump_rpl
2.2. MySQL
2.3. memcache
3. Lua samples
3.1. sample directory
3.1.1. Script descriptions
4. Frequently Asked Questions
List of Examples
Chapter 1. Admin Guide
1.1. Overview
The time needed when writing a new OpenSIPS module
unfortunately is quite high, while the options provided by the
configuration file are limited to the features implemented in
the modules.
With this Lua module, you can easily implement your own
OpenSIPS extensions in Lua.
1.2. Installing the module
This Lua module is loaded in opensips.cfg (just like all the
other modules) with loadmodule("/path/to/siplua.so");.
For the Lua module to compile, you need a recent version of
Lua (tested with 5.1) linked dynamically. The default version
of your favorite Linux distribution should work fine.
1.3. Using the module
With the Lua module, you can access to lua function on the
OpenSIPS side. You need to define a file to load and call
a function from it. Write a function "mongo_alias" and then
write in your opensips.cfg
...
if (lua_exec("mongo_alias")) {
...
}
...
On the Lua side, you have access to opensips functions and
variables (AVP, pseudoVar, ...). Read the documentation below
for further informations.
1.4. Dependencies
1.4.1. OpenSIPS Modules
None ;-)
1.4.2. External Libraries or Applications
The following libraries or applications must be installed
before running OpenSIPS with this module loaded:
* Lua 5.1.x or later
* memcache
This module has been developed and tested with Lua 5.1.?, but
should work with any 5.1.x release. Earlier versions do not work.
On current Debian systems, at least the following packages
should be installed:
* lua5.1
* liblua5.1-0-dev
* libmemcache-dev
* libmysqlclient-dev
It was reported that other Debian-style distributions (such as
Ubuntu) need the same packages.
On OpenBSD systems, at least the following packages should be
installed:
* Lua
1.5. Exported Parameters
1.5.1. filename (string)
This is the file name of your script. This may be set once
only, but it may include an arbitary number of functions and
"use" as many Lua module as necessary.
The default value is "/etc/opensips/opensips.lua"
Example 1.1. Set filename parameter
...
modparam("siplua", "filename", "/etc/opensips/opensips.lua")
...
1.5.2. lua_auto_reload (int)
Define this value to 1 if you want to reload automatically
the lua script.
Disabled by default.
1.5.3. warn_missing_free_fixup (int)
When you call a function via moduleFunc() you could have a memleak.
Enable this warns you when you're doing it.
Enabled by default.
1.5.4. lua_allocator (string)
Change the default memory allocator for the lua module.
Possible values are :
* opensips (default)
* malloc
1.5.5. lua_user_debug (int)
Disabled by default.
1.6. Exported Functions
1.6.1. lua_exec(func, [param])
Calls a Lua function with passing it the current SIP message.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
ONREPLY_ROUTE and BRANCH_ROUTE.
Example 1.1. lua_exec() usage
...
if (lua_exec("mongo_alias")) {
...
}
...
1.6.2. lua_meminfo()
Logs informations about memory.
Chapter 2. OpenSIPS Lua API
2.1. Available functions
This module provides access to a limited number of OpenSIPS
core functions.
2.1.1. xdbg(message)
An alias for xlog(DBG, message)
2.1.2. xlog([level],message)
Logs the message with OpenSIPS's logging facility. The logging
level is one of the following:
* ALERT
* CRIT
* ERR
* WARN
* NOTICE
* INFO
* DBG
2.1.3. setUserDebug
Enable or disable the xlog feature.
Disabled, the xlog function has no effect.
2.1.4. WarnMissingFreeFixup
Dynamically change the variable warn_missing_free_fixup.
2.1.5. getpid
Returns the current pid.
2.1.6. getmem
Returns a table with the size of allocated memory and the fragmentation.
2.1.7 getmeminfo
Returns a table with memory infos.
2.1.8. gethostname
Returns the value of the current hostname.
2.1.9. getType(msg)
Returns "SIP_REQUEST" or "SIP_REPLY".
2.1.10. getURI_User(msg)
Returns the user of the To URI.
2.1.11. getExpires(msg)
Returns the expires header of the current message.
2.1.12. getHeader(header)
Returns the value of the specified header.
2.1.13. getContact(msg)
Returns a table with the contact header.
2.1.14. moduleFunc(msg, function, args1, args2)
Calls an opensips function (could be a function form a loaded module).
You can pass arguments to this function.
2.1.15. getStatus(msg)
Returns the current status if the SIP message is a SIP_REPLY.
2.1.16. getMethod(msg)
Returns the current method.
2.1.17. getSrcIp(msg)
Returns the IP address of the source.
2.1.18. getDstIp(msg)
Returns the IP address of the destination.
2.1.19. AVP_get(msg, name)
Returns an AVP variable.
2.1.20. AVP_set(msg, name, value)
Defines an AVP variable.
2.1.21. AVP_destroy(msg, name)
Destroys an AVP variable.
2.1.22. pseudoVar(msg, variable)
Returns a pseudoVar.
2.1.23. add_lump_rpl
Add header to the reply.
Chapter 3. Lua samples
3.1. sample directory
There are a number of example scripts in the "samples/".
Chapter 4. Frequently Asked Questions
4.1.
Not now !
4.2.
Where can I find more about OpenSIPS?
Take a look at http://www.opensips.org/.
4.3.
Where can I report a bug about this module ?
See the github issues:
* https://github.com/achamo/siplua/issues