/
README
212 lines (138 loc) · 4.78 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
app_python3 Module
Maxim Sobolev
Anthony Alba
Edited by
Maxim Sobolev
Copyright © 2010 Maxim Sobolev
__________________________________________________________________
Table of Contents
1. Admin Guide
1. Overview
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
3. Parameters
3.1. load (string)
3.2. script_name (string)
3.3. mod_init_function (string)
3.4. child_init_method (string)
4. Functions
4.1. python_exec(method [, args])
5. RPC Commands
5.1. app_python.reload
5.2. app_python.api_list
List of Examples
1.1. Set load parameter
1.2. Set mod_init_function parameter
1.3. Set child_init_method parameter
1.4. python_exec usage
Chapter 1. Admin Guide
Table of Contents
1. Overview
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
3. Parameters
3.1. load (string)
3.2. script_name (string)
3.3. mod_init_function (string)
3.4. child_init_method (string)
4. Functions
4.1. python_exec(method [, args])
5. RPC Commands
5.1. app_python.reload
5.2. app_python.api_list
1. Overview
This module is a port of the 'app_python' module to Python 3. It is
based on the work of Maxim Sobolev.
This module cannot be loaded together with 'app_python' as global
symbols have not been renamed. To ease transition, the functions, KEMI
exports, and RPC commands have the same names as 'app_python', which
also means the two modules cannot coexist.
This module allows executing Python scripts from the config file,
exporting functions to access the SIP message from Python.
For some basic examples of Python scripts that can be used with this
module, look at the files inside the source tree located at
'modules/app_python3/python_examples/'.
2. Dependencies
2.1. Kamailio Modules
2.2. External Libraries or Applications
2.1. Kamailio Modules
The following modules must be loaded before this module:
* none.
2.2. External Libraries or Applications
The following libraries or applications must be installed before
running Kamailio with this module loaded:
* python3 - Python 3 runtime.
To compile this module the Python 3 development package is needed.
Requirements:
* python3-dev - Python 3 development package.
* python3-config - (part of python3-dev) tool to output C includes
and library paths.
3. Parameters
3.1. load (string)
3.2. script_name (string)
3.3. mod_init_function (string)
3.4. child_init_method (string)
3.1. load (string)
The path to the file with Python code to be executed from configuration
file.
Default value is “/usr/local/etc/kamailio/handler.py”.
Example 1.1. Set load parameter
...
modparam("app_python3", "load", "/usr/local/etc/kamailio/myscript.py")
...
3.2. script_name (string)
This is same as "load" parameter, kept for backward compatibility with
the older versions of the module.
3.3. mod_init_function (string)
The Python function to be executed by this module when it is initialied
by Kamailio.
Default value is “mod_init”.
Example 1.2. Set mod_init_function parameter
...
modparam("app_python3", "mod_init_function", "my_mod_init")
...
3.4. child_init_method (string)
The Python function to be executed by this module when a new worker
process (child) is initialied by Kamailio.
Default value is “child_init”.
Example 1.3. Set child_init_method parameter
...
modparam("app_python3", "child_init_method", "my_child_init")
...
4. Functions
4.1. python_exec(method [, args])
4.1. python_exec(method [, args])
Execute the Python function with the name given by the parameter
'method'. Optionally can be provided a second string with parameters to
be passed to the Python function.
Both parameters can contain pseudo-variables.
Example 1.4. python_exec usage
...
python_exec("my_python_function");
python_exec("my_python_function", "my_params");
python_exec("my_python_function", "$rU");
...
5. RPC Commands
5.1. app_python.reload
5.2. app_python.api_list
5.1. app_python.reload
IMPORTANT: not functional yet (can crash a running instance, use it
only for testing).
Marks the need to reload the Python script. The actual reload is done
by every working process when the next call to KEMI config is executed.
Name: app_python.reload
Parameters: none
Example:
...
kamcmd app_python.reload
...
5.2. app_python.api_list
List the functions available via Kemi framework.
Name: app_python.api_list
Parameters: none
Example:
...
kamcmd app_python.api_list
...