| 1 |
RUXC Module |
| 2 |
|
| 3 |
Daniel-Constantin Mierla |
| 4 |
|
| 5 |
asipto.com |
| 6 |
<[email protected]> |
| 7 |
|
| 8 |
Edited by |
| 9 |
|
| 10 |
Daniel-Constantin Mierla |
| 11 |
|
| 12 |
<[email protected]> |
| 13 |
|
| 14 |
Copyright © 2021 http://www.asipto.com |
| 15 |
__________________________________________________________________ |
| 16 |
|
| 17 |
Table of Contents |
| 18 |
|
| 19 |
1. Admin Guide |
| 20 |
|
| 21 |
1. Overview |
| 22 |
2. Dependencies |
| 23 |
|
| 24 |
2.1. Kamailio Modules |
| 25 |
2.2. External Libraries or Applications |
| 26 |
|
| 27 |
3. Parameters |
| 28 |
|
| 29 |
3.1. http_timeout (int) |
| 30 |
3.2. http_timeout_connect (int) |
| 31 |
3.3. http_timeout_read (int) |
| 32 |
3.4. http_timeout_write (int) |
| 33 |
3.5. http_tlsmode (int) |
| 34 |
3.6. http_reuse (int) |
| 35 |
3.7. http_retry (int) |
| 36 |
3.8. http_logtype (int) |
| 37 |
3.9. http_debug (int) |
| 38 |
|
| 39 |
4. Functions |
| 40 |
|
| 41 |
4.1. ruxc_http_get(url, hdrs, respv) |
| 42 |
4.2. ruxc_http_post(url, body, hdrs, respv) |
| 43 |
4.3. ruxc_http_delete(url, body, hdrs, respv) |
| 44 |
|
| 45 |
5. Installation |
| 46 |
|
| 47 |
List of Examples |
| 48 |
|
| 49 |
1.1. Set http_timeout parameter |
| 50 |
1.2. Set http_timeout_connect parameter |
| 51 |
1.3. Set http_timeout_read parameter |
| 52 |
1.4. Set http_timeout_write parameter |
| 53 |
1.5. Set http_tlsmode parameter |
| 54 |
1.6. Set http_reuse parameter |
| 55 |
1.7. Set http_retry parameter |
| 56 |
1.8. Set http_logtype parameter |
| 57 |
1.9. Set http_debug parameter |
| 58 |
1.10. ruxc_http_get() usage |
| 59 |
1.11. ruxc_http_post() usage |
| 60 |
1.12. ruxc_http_delete() usage |
| 61 |
1.13. Libruxc Usage |
| 62 |
|
| 63 |
Chapter 1. Admin Guide |
| 64 |
|
| 65 |
Table of Contents |
| 66 |
|
| 67 |
1. Overview |
| 68 |
2. Dependencies |
| 69 |
|
| 70 |
2.1. Kamailio Modules |
| 71 |
2.2. External Libraries or Applications |
| 72 |
|
| 73 |
3. Parameters |
| 74 |
|
| 75 |
3.1. http_timeout (int) |
| 76 |
3.2. http_timeout_connect (int) |
| 77 |
3.3. http_timeout_read (int) |
| 78 |
3.4. http_timeout_write (int) |
| 79 |
3.5. http_tlsmode (int) |
| 80 |
3.6. http_reuse (int) |
| 81 |
3.7. http_retry (int) |
| 82 |
3.8. http_logtype (int) |
| 83 |
3.9. http_debug (int) |
| 84 |
|
| 85 |
4. Functions |
| 86 |
|
| 87 |
4.1. ruxc_http_get(url, hdrs, respv) |
| 88 |
4.2. ruxc_http_post(url, body, hdrs, respv) |
| 89 |
4.3. ruxc_http_delete(url, body, hdrs, respv) |
| 90 |
|
| 91 |
5. Installation |
| 92 |
|
| 93 |
1. Overview |
| 94 |
|
| 95 |
The module exports utility functions based on libruxc. |
| 96 |
|
| 97 |
Among them are function to perform HTTP GET and POST queries. |
| 98 |
|
| 99 |
The ruxc project is available at: https://github.com/miconda/ruxc. |
| 100 |
|
| 101 |
2. Dependencies |
| 102 |
|
| 103 |
2.1. Kamailio Modules |
| 104 |
2.2. External Libraries or Applications |
| 105 |
|
| 106 |
2.1. Kamailio Modules |
| 107 |
|
| 108 |
The following modules must be installed (but not loaded) to use this |
| 109 |
module: |
| 110 |
* none. |
| 111 |
|
| 112 |
2.2. External Libraries or Applications |
| 113 |
|
| 114 |
The following libraries or applications must be installed before |
| 115 |
running Kamailio with this module loaded: |
| 116 |
* libruxc. |
| 117 |
|
| 118 |
3. Parameters |
| 119 |
|
| 120 |
3.1. http_timeout (int) |
| 121 |
3.2. http_timeout_connect (int) |
| 122 |
3.3. http_timeout_read (int) |
| 123 |
3.4. http_timeout_write (int) |
| 124 |
3.5. http_tlsmode (int) |
| 125 |
3.6. http_reuse (int) |
| 126 |
3.7. http_retry (int) |
| 127 |
3.8. http_logtype (int) |
| 128 |
3.9. http_debug (int) |
| 129 |
|
| 130 |
3.1. http_timeout (int) |
| 131 |
|
| 132 |
The interval in milliseconds after which the HTTP GET or POST query |
| 133 |
times out. It is the overall timeout, including DNS resolution, |
| 134 |
connecting time, redirects, and reading the response body. Slow DNS |
| 135 |
resolution may cause a request to exceed the timeout, because the DNS |
| 136 |
request cannot be interrupted with the available APIs. It takes |
| 137 |
precedence over http_timeout_read() and http_timeout_write(), but not |
| 138 |
http_timeout_connect. See also the comments in |
| 139 |
'https://github.com/algesten/ureq/blob/main/src/agent.rs'. |
| 140 |
|
| 141 |
Use 0 to disable setting it in the library. |
| 142 |
|
| 143 |
Default value is 5000 (5 secs). |
| 144 |
|
| 145 |
Example 1.1. Set http_timeout parameter |
| 146 |
... |
| 147 |
modparam("ruxc", "http_timeout", 2000) |
| 148 |
... |
| 149 |
|
| 150 |
3.2. http_timeout_connect (int) |
| 151 |
|
| 152 |
The interval in milliseconds after which to give up on connecting to |
| 153 |
the HTTP/S server. If http_timeout is set, this one takes precedence. |
| 154 |
The library beneath has a default 30 seconds connect timeout. |
| 155 |
|
| 156 |
Use 0 to disable setting it in the library. |
| 157 |
|
| 158 |
Default value is 5000 (5 secs). |
| 159 |
|
| 160 |
Example 1.2. Set http_timeout_connect parameter |
| 161 |
... |
| 162 |
modparam("ruxc", "http_timeout_connect", 2000) |
| 163 |
... |
| 164 |
|
| 165 |
3.3. http_timeout_read (int) |
| 166 |
|
| 167 |
The interval in milliseconds after which the read on HTTP/S connection |
| 168 |
socket timeouts. If http_timeout is set, it takes precedence. |
| 169 |
|
| 170 |
Use 0 to disable setting it in the library. |
| 171 |
|
| 172 |
Default value is 5000 (5 secs). |
| 173 |
|
| 174 |
Example 1.3. Set http_timeout_read parameter |
| 175 |
... |
| 176 |
modparam("ruxc", "http_timeout_read", 2000) |
| 177 |
... |
| 178 |
|
| 179 |
3.4. http_timeout_write (int) |
| 180 |
|
| 181 |
The interval in milliseconds after which the write on HTTP/S connection |
| 182 |
socket timeouts. If http_timeout is set, it takes precedence. |
| 183 |
|
| 184 |
Use 0 to disable setting it in the library. |
| 185 |
|
| 186 |
Default value is 5000 (5 secs). |
| 187 |
|
| 188 |
Example 1.4. Set http_timeout_write parameter |
| 189 |
... |
| 190 |
modparam("ruxc", "http_timeout_write", 2000) |
| 191 |
... |
| 192 |
|
| 193 |
3.5. http_tlsmode (int) |
| 194 |
|
| 195 |
The mode to connect over TLS to HTTPS sites: 0 accept all certificates; |
| 196 |
1 - accept trusted certificates. |
| 197 |
|
| 198 |
Default value is 0 (accept all certificates). |
| 199 |
|
| 200 |
Example 1.5. Set http_tlsmode parameter |
| 201 |
... |
| 202 |
modparam("ruxc", "http_tlsmode", 1) |
| 203 |
... |
| 204 |
|
| 205 |
3.6. http_reuse (int) |
| 206 |
|
| 207 |
Set to 1 in order to reuse the connection for all requests (each |
| 208 |
Kamailio process has its own connection). Useful to avoid TCP connect |
| 209 |
(and TLS handshake) when all requests are performed against the same |
| 210 |
HTTP/S server. |
| 211 |
|
| 212 |
Set to 2 in order to keep connections per base URL (scheme://host:port) |
| 213 |
indexed in a hash map. Useful when doing HTTP/S requests to many |
| 214 |
servers. |
| 215 |
|
| 216 |
Default value is 0 (new connection for each request). |
| 217 |
|
| 218 |
Example 1.6. Set http_reuse parameter |
| 219 |
... |
| 220 |
modparam("ruxc", "http_reuse", 1) |
| 221 |
... |
| 222 |
|
| 223 |
3.7. http_retry (int) |
| 224 |
|
| 225 |
How many times to retry if the HTTP request does not get a 200 OK |
| 226 |
response. |
| 227 |
|
| 228 |
Default value is 0 (no retry). |
| 229 |
|
| 230 |
Example 1.7. Set http_retry parameter |
| 231 |
... |
| 232 |
modparam("ruxc", "http_retry", 2) |
| 233 |
... |
| 234 |
|
| 235 |
3.8. http_logtype (int) |
| 236 |
|
| 237 |
Set the log type for libruxc http functions: 0 - stdout; 1 - syslog. |
| 238 |
|
| 239 |
Default value is 0. |
| 240 |
|
| 241 |
Example 1.8. Set http_logtype parameter |
| 242 |
... |
| 243 |
modparam("ruxc", "http_logtype", 1) |
| 244 |
... |
| 245 |
|
| 246 |
3.9. http_debug (int) |
| 247 |
|
| 248 |
Set the debug mode for libruxc http functions: 0 - no debug; 1 - |
| 249 |
errors; 2 - debug. |
| 250 |
|
| 251 |
Default value is 0. |
| 252 |
|
| 253 |
Example 1.9. Set http_debug parameter |
| 254 |
... |
| 255 |
modparam("ruxc", "http_debug", 1) |
| 256 |
... |
| 257 |
|
| 258 |
4. Functions |
| 259 |
|
| 260 |
4.1. ruxc_http_get(url, hdrs, respv) |
| 261 |
4.2. ruxc_http_post(url, body, hdrs, respv) |
| 262 |
4.3. ruxc_http_delete(url, body, hdrs, respv) |
| 263 |
|
| 264 |
4.1. ruxc_http_get(url, hdrs, respv) |
| 265 |
|
| 266 |
Perform a HTTP GET request to "url", storing the response body in the |
| 267 |
"respv" variable. The "hdrs" can be empty string to skip setting them. |
| 268 |
The first two parameters can contain variables that are evaluated at |
| 269 |
runtime. The "respv" has to be the name of a writable variable. |
| 270 |
|
| 271 |
The function returns response code of HTTP reply or negative value if |
| 272 |
something went wrong. |
| 273 |
|
| 274 |
This function can be used from ANY_ROUTE. |
| 275 |
|
| 276 |
Example 1.10. ruxc_http_get() usage |
| 277 |
... |
| 278 |
ruxc_http_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{s |
| 279 |
.escape.param})", |
| 280 |
"", "X-Token: abc", "$var(result)"); |
| 281 |
switch ($rc) { |
| 282 |
... |
| 283 |
} |
| 284 |
... |
| 285 |
|
| 286 |
4.2. ruxc_http_post(url, body, hdrs, respv) |
| 287 |
|
| 288 |
Perform a HTTP POST request to "url", storing the response body in the |
| 289 |
"respv" variable. The "body" and "hdrs" can be empty strings to skip |
| 290 |
setting them. The first three parameters can contain variables that are |
| 291 |
evaluated at runtime. The "respv" has to be the name of a writable |
| 292 |
variable. |
| 293 |
|
| 294 |
The function returns response code of HTTP reply or negative value if |
| 295 |
something went wrong. |
| 296 |
|
| 297 |
This function can be used from ANY_ROUTE. |
| 298 |
|
| 299 |
Example 1.11. ruxc_http_post() usage |
| 300 |
... |
| 301 |
ruxc_http_post("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{ |
| 302 |
s.escape.param})", |
| 303 |
"", "X-Token: abc", "$var(result)"); |
| 304 |
switch ($rc) { |
| 305 |
... |
| 306 |
} |
| 307 |
... |
| 308 |
|
| 309 |
4.3. ruxc_http_delete(url, body, hdrs, respv) |
| 310 |
|
| 311 |
Perform a HTTP DELETE request to "url", storing the response body in |
| 312 |
the "respv" variable. The "body" and "hdrs" can be empty strings to |
| 313 |
skip setting them. The first three parameters can contain variables |
| 314 |
that are evaluated at runtime. The "respv" has to be the name of a |
| 315 |
writable variable. |
| 316 |
|
| 317 |
The function returns response code of HTTP reply or negative value if |
| 318 |
something went wrong. |
| 319 |
|
| 320 |
This function can be used from ANY_ROUTE. |
| 321 |
|
| 322 |
Example 1.12. ruxc_http_delete() usage |
| 323 |
... |
| 324 |
ruxc_http_delete("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(f |
| 325 |
u{s.escape.param})", |
| 326 |
"", "X-Token: abc", "$var(result)"); |
| 327 |
switch ($rc) { |
| 328 |
... |
| 329 |
} |
| 330 |
... |
| 331 |
|
| 332 |
5. Installation |
| 333 |
|
| 334 |
The module needs "libruxc" library, which is provided by "ruxc" project |
| 335 |
from https://github.com/miconda/ruxc/. The library is implemented in |
| 336 |
Rust language, with generated C API and library. Until the libruxc is |
| 337 |
going to be packaged in OS distributions, the ruxc module can be |
| 338 |
compiled by copying ruxc.h and libruxc.a files in the folder of the |
| 339 |
module. |
| 340 |
|
| 341 |
To generate the libruxc.a file, it requires to have Rust language |
| 342 |
installed and its environment configured, then run the following |
| 343 |
commands: |
| 344 |
|
| 345 |
Example 1.13. Libruxc Usage |
| 346 |
... |
| 347 |
git clone https://github.com/miconda/ruxc |
| 348 |
cd ruxc |
| 349 |
cargo build --release |
| 350 |
cp include/ruxc.h target/release/libruxc.a \ |
| 351 |
/path/to/kamailio/src/modules/ruxc/ |
| 352 |
|
| 353 |
cd /path/to/kamailio/ |
| 354 |
make include_modules="ruxc ..." cfg |
| 355 |
make all |
| 356 |
make install |
| 357 |
|
| 358 |
## or compiling individual module for use inside source tree |
| 359 |
# make modules modules=src/modules/ruxc |
| 360 |
... |
| 361 |
|
| 362 |
For more details about compilation and installation of libruxc, see: |
| 363 |
https://github.com/miconda/ruxc. |