Browse code

ruxc: added ruxc_http_delete(...) to do HTTP DELETE request

Daniel-Constantin Mierla authored on 26/08/2021 09:03:09
Showing 1 changed files
... ...
@@ -322,6 +322,37 @@ ruxc_http_post("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$
322 322
 switch ($rc) {
323 323
     ...
324 324
 }
325
+...
326
+				</programlisting>
327
+			</example>
328
+		</section>
329
+		<section id="ruxc.f.ruxc_http_delete">
330
+			<title>
331
+				<function moreinfo="none">ruxc_http_delete(url, body, hdrs, respv)</function>
332
+			</title>
333
+			<para>
334
+				Perform a HTTP DELETE request to "url", storing the response body
335
+				in the "respv" variable. The "body" and "hdrs" can be empty strings
336
+				to skip setting them. The first three parameters can contain
337
+				variables that are evaluated at runtime. The "respv" has to be
338
+				the name of a writable variable.
339
+			</para>
340
+			<para>
341
+			The function returns response code of HTTP reply or negative value
342
+			if something went wrong.
343
+			</para>
344
+			<para>
345
+			This function can be used from ANY_ROUTE.
346
+			</para>
347
+			<example>
348
+				<title><function>ruxc_http_delete()</function> usage</title>
349
+				<programlisting format="linespecific">
350
+...
351
+ruxc_http_delete("http://api.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
352
+	   "", "X-Token: abc", "$var(result)");
353
+switch ($rc) {
354
+    ...
355
+}
325 356
 ...
326 357
 				</programlisting>
327 358
 			</example>
Browse code

ruxc: docs for the new timeouts params

Daniel-Constantin Mierla authored on 24/08/2021 08:16:52
Showing 1 changed files
... ...
@@ -62,7 +62,15 @@
62 62
 		<title><varname>http_timeout</varname> (int)</title>
63 63
 		<para>
64 64
 		The interval in miliseconds after which the HTTP GET or POST query
65
-		times out.
65
+		times out. It is the overall timeout, including DNS resolution, connecting
66
+		time, redirects, and reading the response body. Slow DNS resolution
67
+		may cause a request to exceed the timeout, because the DNS request
68
+		cannot be interrupted with the available APIs. It takes precedence over
69
+		http_timeout_read() and http_timeout_write(), but not http_timeout_connect.
70
+		See also the comments in 'https://github.com/algesten/ureq/blob/main/src/agent.rs'.
71
+		</para>
72
+		<para>
73
+		Use 0 to disable setting it in the library.
66 74
 		</para>
67 75
 		<para>
68 76
 		<emphasis>
... ...
@@ -75,6 +83,76 @@
75 83
 ...
76 84
 modparam("ruxc", "http_timeout", 2000)
77 85
 ...
86
+</programlisting>
87
+		</example>
88
+	</section>
89
+	<section id="ruxc.p.http_timeout_connect">
90
+		<title><varname>http_timeout_connect</varname> (int)</title>
91
+		<para>
92
+		The interval in miliseconds after which to give up on connecting to the
93
+		HTTP/S server. If http_timeout is set, this one takes precedence. The
94
+		library beneath has a default 30 seconds connect timeout.
95
+		</para>
96
+		<para>
97
+		Use 0 to disable setting it in the library.
98
+		</para>
99
+		<para>
100
+		<emphasis>
101
+			Default value is 5000 (5 secs).
102
+		</emphasis>
103
+		</para>
104
+		<example>
105
+		<title>Set <varname>http_timeout_connect</varname> parameter</title>
106
+		<programlisting format="linespecific">
107
+...
108
+modparam("ruxc", "http_timeout_connect", 2000)
109
+...
110
+</programlisting>
111
+		</example>
112
+	</section>
113
+	<section id="ruxc.p.http_timeout_read">
114
+		<title><varname>http_timeout_read</varname> (int)</title>
115
+		<para>
116
+		The interval in miliseconds after which the read on HTTP/S connection
117
+		socket timeouts. If http_timeout is set, it takes precedence.
118
+		</para>
119
+		<para>
120
+		Use 0 to disable setting it in the library.
121
+		</para>
122
+		<para>
123
+		<emphasis>
124
+			Default value is 5000 (5 secs).
125
+		</emphasis>
126
+		</para>
127
+		<example>
128
+		<title>Set <varname>http_timeout_read</varname> parameter</title>
129
+		<programlisting format="linespecific">
130
+...
131
+modparam("ruxc", "http_timeout_read", 2000)
132
+...
133
+</programlisting>
134
+		</example>
135
+	</section>
136
+	<section id="ruxc.p.http_timeout_write">
137
+		<title><varname>http_timeout_write</varname> (int)</title>
138
+		<para>
139
+		The interval in miliseconds after which the write on HTTP/S connection
140
+		socket timeouts. If http_timeout is set, it takes precedence.
141
+		</para>
142
+		<para>
143
+		Use 0 to disable setting it in the library.
144
+		</para>
145
+		<para>
146
+		<emphasis>
147
+			Default value is 5000 (5 secs).
148
+		</emphasis>
149
+		</para>
150
+		<example>
151
+		<title>Set <varname>http_timeout_write</varname> parameter</title>
152
+		<programlisting format="linespecific">
153
+...
154
+modparam("ruxc", "http_timeout_write", 2000)
155
+...
78 156
 </programlisting>
79 157
 		</example>
80 158
 	</section>
Browse code

ruxc: added modparams to set libruxc logtype and debug

Daniel-Constantin Mierla authored on 20/08/2021 06:01:25
Showing 1 changed files
... ...
@@ -140,6 +140,45 @@ modparam("ruxc", "http_reuse", 1)
140 140
 ...
141 141
 modparam("ruxc", "http_retry", 2)
142 142
 ...
143
+</programlisting>
144
+		</example>
145
+	</section>
146
+	<section id="ruxc.p.http_logtype">
147
+		<title><varname>http_logtype</varname> (int)</title>
148
+		<para>
149
+		Set the log type for libruxc http functions: 0 - stdout; 1 - syslog.
150
+		</para>
151
+		<para>
152
+		<emphasis>
153
+			Default value is 0.
154
+		</emphasis>
155
+		</para>
156
+		<example>
157
+		<title>Set <varname>http_logtype</varname> parameter</title>
158
+		<programlisting format="linespecific">
159
+...
160
+modparam("ruxc", "http_logtype", 1)
161
+...
162
+</programlisting>
163
+		</example>
164
+	</section>
165
+	<section id="ruxc.p.http_debug">
166
+		<title><varname>http_debug</varname> (int)</title>
167
+		<para>
168
+		Set the debug mode for libruxc http functions: 0 - no debug; 1 - errors;
169
+		2 - debug.
170
+		</para>
171
+		<para>
172
+		<emphasis>
173
+			Default value is 0.
174
+		</emphasis>
175
+		</para>
176
+		<example>
177
+		<title>Set <varname>http_debug</varname> parameter</title>
178
+		<programlisting format="linespecific">
179
+...
180
+modparam("ruxc", "http_debug", 1)
181
+...
143 182
 </programlisting>
144 183
 		</example>
145 184
 	</section>
Browse code

ruxc: added http_retry modparam

Daniel-Constantin Mierla authored on 17/08/2021 19:27:36
Showing 1 changed files
... ...
@@ -121,6 +121,25 @@ modparam("ruxc", "http_tlsmode", 1)
121 121
 ...
122 122
 modparam("ruxc", "http_reuse", 1)
123 123
 ...
124
+</programlisting>
125
+		</example>
126
+	</section>
127
+	<section id="ruxc.p.http_retry">
128
+		<title><varname>http_retry</varname> (int)</title>
129
+		<para>
130
+		How many times to retry if the HTTP request does not get a 200ok response.
131
+		</para>
132
+		<para>
133
+		<emphasis>
134
+			Default value is 0 (no retry).
135
+		</emphasis>
136
+		</para>
137
+		<example>
138
+		<title>Set <varname>http_retry</varname> parameter</title>
139
+		<programlisting format="linespecific">
140
+...
141
+modparam("ruxc", "http_retry", 2)
142
+...
124 143
 </programlisting>
125 144
 		</example>
126 145
 	</section>
Browse code

ruxc: docs for reuse mode 2

Daniel-Constantin Mierla authored on 06/08/2021 06:54:29
Showing 1 changed files
... ...
@@ -106,6 +106,11 @@ modparam("ruxc", "http_tlsmode", 1)
106 106
 		handshake) when all requests are performed against the same HTTP/S server.
107 107
 		</para>
108 108
 		<para>
109
+		Set to 2 in order to keep connections per base URL (scheme://host:port)
110
+		indexed in a hash map. Useful when doing HTTP/S requests to many
111
+		servers.
112
+		</para>
113
+		<para>
109 114
 		<emphasis>
110 115
 			Default value is 0 (new connection for each request).
111 116
 		</emphasis>
Browse code

ruxc: added http_reuse modparam

- enable connection reuse

Daniel-Constantin Mierla authored on 24/07/2021 06:16:49
Showing 1 changed files
... ...
@@ -95,6 +95,27 @@ modparam("ruxc", "http_timeout", 2000)
95 95
 ...
96 96
 modparam("ruxc", "http_tlsmode", 1)
97 97
 ...
98
+</programlisting>
99
+		</example>
100
+	</section>
101
+	<section id="ruxc.p.http_reuse">
102
+		<title><varname>http_reuse</varname> (int)</title>
103
+		<para>
104
+		Set to 1 in order to reuse the connection for all requests (each &kamailio;
105
+		process has its own connection). Useful to avoid TCP connect (and TLS
106
+		handshake) when all requests are performed against the same HTTP/S server.
107
+		</para>
108
+		<para>
109
+		<emphasis>
110
+			Default value is 0 (new connection for each request).
111
+		</emphasis>
112
+		</para>
113
+		<example>
114
+		<title>Set <varname>http_reuse</varname> parameter</title>
115
+		<programlisting format="linespecific">
116
+...
117
+modparam("ruxc", "http_reuse", 1)
118
+...
98 119
 </programlisting>
99 120
 		</example>
100 121
 	</section>
Browse code

ruxc: docs for http_tlsmode parameter

Daniel-Constantin Mierla authored on 21/07/2021 14:52:48
Showing 1 changed files
... ...
@@ -75,6 +75,26 @@
75 75
 ...
76 76
 modparam("ruxc", "http_timeout", 2000)
77 77
 ...
78
+</programlisting>
79
+		</example>
80
+	</section>
81
+	<section id="ruxc.p.http_tlsmode">
82
+		<title><varname>http_tlsmode</varname> (int)</title>
83
+		<para>
84
+		The mode to connect over TLS to HTTPS sites: 0 accept all certificates;
85
+		1 - accept trusted certificates.
86
+		</para>
87
+		<para>
88
+		<emphasis>
89
+			Default value is 0 (accept all certificates).
90
+		</emphasis>
91
+		</para>
92
+		<example>
93
+		<title>Set <varname>http_tlsmode</varname> parameter</title>
94
+		<programlisting format="linespecific">
95
+...
96
+modparam("ruxc", "http_tlsmode", 1)
97
+...
78 98
 </programlisting>
79 99
 		</example>
80 100
 	</section>
Browse code

ruxc: docs - fixed typo in function name

Daniel-Constantin Mierla authored on 19/07/2021 14:35:36
Showing 1 changed files
... ...
@@ -104,7 +104,7 @@ modparam("ruxc", "http_timeout", 2000)
104 104
 				<title><function>ruxc_http_get()</function> usage</title>
105 105
 				<programlisting format="linespecific">
106 106
 ...
107
-http_client_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
107
+ruxc_http_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
108 108
 	   "", "X-Token: abc", "$var(result)");
109 109
 switch ($rc) {
110 110
     ...
Browse code

ruxc: new module with utility functions from libruxc

- first target is to provide http get/post functions that do not depend
on libcurl+libssl

Daniel-Constantin Mierla authored on 19/07/2021 06:32:48
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,189 @@
1
+<?xml version="1.0" encoding='ISO-8859-1'?>
2
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4
+
5
+<!-- Include general documentation entities -->
6
+<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
7
+%docentities;
8
+
9
+]>
10
+<!-- Module User's Guide -->
11
+
12
+<chapter>
13
+
14
+	<title>&adminguide;</title>
15
+
16
+	<section>
17
+	<title>Overview</title>
18
+	<para>
19
+		The module exports utility functions based on libruxc.
20
+	</para>
21
+	<para>
22
+		Among them are function to perform HTTP GET and POST queries.
23
+	</para>
24
+	<para>
25
+		The ruxc project is available at:
26
+		<ulink url="https://github.com/miconda/ruxc">https://github.com/miconda/ruxc</ulink>.
27
+	</para>
28
+	</section>
29
+	<section>
30
+	<title>Dependencies</title>
31
+	<section>
32
+		<title>&kamailio; Modules</title>
33
+		<para>
34
+		The following modules must be installed (but not loaded) to use this module:
35
+			<itemizedlist>
36
+			<listitem>
37
+			<para>
38
+				<emphasis>none</emphasis>.
39
+			</para>
40
+			</listitem>
41
+			</itemizedlist>
42
+		</para>
43
+	</section>
44
+	<section>
45
+		<title>External Libraries or Applications</title>
46
+		<para>
47
+		The following libraries or applications must be installed before running
48
+		&kamailio; with this module loaded:
49
+			<itemizedlist>
50
+			<listitem>
51
+			<para>
52
+				<emphasis>libruxc</emphasis>.
53
+			</para>
54
+			</listitem>
55
+			</itemizedlist>
56
+		</para>
57
+	</section>
58
+	</section>
59
+	<section>
60
+	<title>Parameters</title>
61
+	<section id="ruxc.p.http_timeout">
62
+		<title><varname>http_timeout</varname> (int)</title>
63
+		<para>
64
+		The interval in miliseconds after which the HTTP GET or POST query
65
+		times out.
66
+		</para>
67
+		<para>
68
+		<emphasis>
69
+			Default value is 5000 (5 secs).
70
+		</emphasis>
71
+		</para>
72
+		<example>
73
+		<title>Set <varname>http_timeout</varname> parameter</title>
74
+		<programlisting format="linespecific">
75
+...
76
+modparam("ruxc", "http_timeout", 2000)
77
+...
78
+</programlisting>
79
+		</example>
80
+	</section>
81
+	</section>
82
+
83
+	<section>
84
+	<title>Functions</title>
85
+		<section id="ruxc.f.ruxc_http_get">
86
+			<title>
87
+				<function moreinfo="none">ruxc_http_get(url, hdrs, respv)</function>
88
+			</title>
89
+			<para>
90
+				Perform a HTTP GET request to "url", storing the response body
91
+				in the "respv" variable. The "hdrs" can be empty string
92
+				to skip setting them. The first two parameters can contain
93
+				variables that are evaluated at runtime. The "respv" has to be
94
+				the name of a writable variable.
95
+			</para>
96
+			<para>
97
+			The function returns response code of HTTP reply or negative value
98
+			if something went wrong.
99
+			</para>
100
+			<para>
101
+			This function can be used from ANY_ROUTE.
102
+			</para>
103
+			<example>
104
+				<title><function>ruxc_http_get()</function> usage</title>
105
+				<programlisting format="linespecific">
106
+...
107
+http_client_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
108
+	   "", "X-Token: abc", "$var(result)");
109
+switch ($rc) {
110
+    ...
111
+}
112
+...
113
+				</programlisting>
114
+			</example>
115
+		</section>
116
+		<section id="ruxc.f.ruxc_http_post">
117
+			<title>
118
+				<function moreinfo="none">ruxc_http_post(url, body, hdrs, respv)</function>
119
+			</title>
120
+			<para>
121
+				Perform a HTTP POST request to "url", storing the response body
122
+				in the "respv" variable. The "body" and "hdrs" can be empty strings
123
+				to skip setting them. The first three parameters can contain
124
+				variables that are evaluated at runtime. The "respv" has to be
125
+				the name of a writable variable.
126
+			</para>
127
+			<para>
128
+			The function returns response code of HTTP reply or negative value
129
+			if something went wrong.
130
+			</para>
131
+			<para>
132
+			This function can be used from ANY_ROUTE.
133
+			</para>
134
+			<example>
135
+				<title><function>ruxc_http_post()</function> usage</title>
136
+				<programlisting format="linespecific">
137
+...
138
+ruxc_http_post("http://api.com/index.php?r_uri=$(ru{s.escape.param})&amp;f_uri=$(fu{s.escape.param})",
139
+	   "", "X-Token: abc", "$var(result)");
140
+switch ($rc) {
141
+    ...
142
+}
143
+...
144
+				</programlisting>
145
+			</example>
146
+		</section>
147
+	</section>
148
+	<section id="ruxc.s.installation">
149
+	<title>Installation</title>
150
+	<para>
151
+		The module needs "libruxc" library, which is provided by "ruxc" project
152
+		from https://github.com/miconda/ruxc/. The library is
153
+		implemented in Rust language, with generated C API and library. Until the
154
+		libruxc is going to be packaged in OS distributions, the ruxc
155
+		module can be compiled by copying ruxc.h and libruxc.a
156
+		files in the folder of the module.
157
+	</para>
158
+	<para>
159
+		To generate the libruxc.a file, it requires to have Rust language
160
+		installed and its environment configured, then run the following commands:
161
+	</para>
162
+		<example>
163
+		<title>Libruxc Usage</title>
164
+		<programlisting format="linespecific">
165
+...
166
+git clone https://github.com/miconda/ruxc
167
+cd ruxc
168
+cargo build --release
169
+cp include/ruxc.h target/release/libruxc.a \
170
+    /path/to/kamailio/src/modules/ruxc/
171
+
172
+cd /path/to/kamailio/
173
+make include_modules="ruxc ..." cfg
174
+make all
175
+make install
176
+
177
+## or compiling individual module for use inside source tree
178
+# make modules modules=src/modules/ruxc
179
+...
180
+</programlisting>
181
+		</example>
182
+	<para>
183
+		For more details about compilation and installation of libruxc, see:
184
+		<ulink url="https://github.com/miconda/ruxc">https://github.com/miconda/ruxc</ulink>.
185
+	</para>
186
+	</section>
187
+
188
+</chapter>
189
+