Skip to content

Commit

Permalink
ruxc: new module with utility functions from libruxc
Browse files Browse the repository at this point in the history
- first target is to provide http get/post functions that do not depend
on libcurl+libssl
  • Loading branch information
miconda committed Jul 19, 2021
1 parent 851a8c0 commit 81de787
Show file tree
Hide file tree
Showing 6 changed files with 871 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/modules/ruxc/Makefile
@@ -0,0 +1,32 @@
#
# secsipid module makefile
#
# WARNING: do not run this directly, it should be run by the main Makefile

include ../../Makefile.defs
auto_gen=
NAME=ruxc.so

ifeq ($(CROSS_COMPILE),)
BUILDER = $(shell which pkg-config)
ifneq ($(BUILDER),)
PKGLIBRUXC = $(shell $(BUILDER) --exists libruxc > /dev/null 2>&1 ; echo $$? )
ifneq ($(PKGLIBRUXC),0)
BUILDER =
endif
endif
endif

ifeq ($(BUILDER),)
DEFS+= -I.
LIBS = -L. -lruxc
else
DEFS+= $(shell pkg-config --cflags libruxc)
LIBS = $(shell pkg-config --libs libruxc)
endif

ifeq ($(OS), darwin)
LIBS+= -framework CoreFoundation -framework Security
endif

include ../../Makefile.modules
188 changes: 188 additions & 0 deletions src/modules/ruxc/README
@@ -0,0 +1,188 @@
RUXC Module

Daniel-Constantin Mierla

asipto.com
<miconda@gmail.com>

Edited by

Daniel-Constantin Mierla

<miconda@gmail.com>

Copyright � 2021 http://www.asipto.com
__________________________________________________________________

Table of Contents

1. Admin Guide

1. Overview
2. Dependencies

2.1. Kamailio Modules
2.2. External Libraries or Applications

3. Parameters

3.1. http_timeout (int)

4. Functions

4.1. ruxc_http_get(url, hdrs, respv)
4.2. ruxc_http_post(url, body, hdrs, respv)

5. Installation

List of Examples

1.1. Set http_timeout parameter
1.2. ruxc_http_get() usage
1.3. ruxc_http_post() usage
1.4. Libruxc 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. http_timeout (int)

4. Functions

4.1. ruxc_http_get(url, hdrs, respv)
4.2. ruxc_http_post(url, body, hdrs, respv)

5. Installation

1. Overview

The module exports utility functions based on libruxc.

Among them are function to perform HTTP GET and POST queries.

The ruxc project is available at: https://github.com/miconda/ruxc.

2. Dependencies

2.1. Kamailio Modules
2.2. External Libraries or Applications

2.1. Kamailio Modules

The following modules must be installed (but not loaded) to use this
module:
* none.

2.2. External Libraries or Applications

The following libraries or applications must be installed before
running Kamailio with this module loaded:
* libruxc.

3. Parameters

3.1. http_timeout (int)

3.1. http_timeout (int)

The interval in miliseconds after which the HTTP GET or POST query
times out.

Default value is 5000 (5 secs).

Example 1.1. Set http_timeout parameter
...
modparam("ruxc", "http_timeout", 2000)
...

4. Functions

4.1. ruxc_http_get(url, hdrs, respv)
4.2. ruxc_http_post(url, body, hdrs, respv)

4.1. ruxc_http_get(url, hdrs, respv)

Perform a HTTP GET request to "url", storing the response body in the
"respv" variable. The "hdrs" can be empty string to skip setting them.
The first two parameters can contain variables that are evaluated at
runtime. The "respv" has to be the name of a writable variable.

The function returns response code of HTTP reply or negative value if
something went wrong.

This function can be used from ANY_ROUTE.

Example 1.2. ruxc_http_get() usage
...
http_client_get("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu
{s.escape.param})",
"", "X-Token: abc", "$var(result)");
switch ($rc) {
...
}
...

4.2. ruxc_http_post(url, body, hdrs, respv)

Perform a HTTP POST request to "url", storing the response body in the
"respv" variable. The "body" and "hdrs" can be empty strings to skip
setting them. The first three parameters can contain variables that are
evaluated at runtime. The "respv" has to be the name of a writable
variable.

The function returns response code of HTTP reply or negative value if
something went wrong.

This function can be used from ANY_ROUTE.

Example 1.3. ruxc_http_post() usage
...
ruxc_http_post("http://api.com/index.php?r_uri=$(ru{s.escape.param})&f_uri=$(fu{
s.escape.param})",
"", "X-Token: abc", "$var(result)");
switch ($rc) {
...
}
...

5. Installation

The module needs "libruxc" library, which is provided by "ruxc" project
from https://github.com/miconda/ruxc/. The library is implemented in
Rust language, with generated C API and library. Until the libruxc is
going to be packaged in OS distributions, the ruxc module can be
compiled by copying ruxc.h and libruxc.a files in the folder of the
module.

To generate the libruxc.a file, it requires to have Rust language
installed and its environment configured, then run the following
commands:

Example 1.4. Libruxc Usage
...
git clone https://github.com/miconda/ruxc
cd ruxc
cargo build --release
cp include/ruxc.h target/release/libruxc.a \
/path/to/kamailio/src/modules/ruxc/

cd /path/to/kamailio/
make include_modules="ruxc ..." cfg
make all
make install

## or compiling individual module for use inside source tree
# make modules modules=src/modules/ruxc
...

For more details about compilation and installation of libruxc, see:
https://github.com/miconda/ruxc.
4 changes: 4 additions & 0 deletions src/modules/ruxc/doc/Makefile
@@ -0,0 +1,4 @@
docs = ruxc.xml

docbook_dir = ../../../../doc/docbook
include $(docbook_dir)/Makefile.module
42 changes: 42 additions & 0 deletions src/modules/ruxc/doc/ruxc.xml
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
%docentities;

]>

<book xmlns:xi="http://www.w3.org/2001/XInclude">
<bookinfo>
<title>RUXC Module</title>
<productname class="trade">&kamailioname;</productname>
<authorgroup>
<author>
<firstname>Daniel-Constantin</firstname>
<surname>Mierla</surname>
<affiliation><orgname>asipto.com</orgname></affiliation>
<email>miconda@gmail.com</email>
<address>
<otheraddr>
<ulink url="http://www.asipto.com">http://www.asipto.com</ulink>
</otheraddr>
</address>
</author>
<editor>
<firstname>Daniel-Constantin</firstname>
<surname>Mierla</surname>
<email>miconda@gmail.com</email>
</editor>
</authorgroup>
<copyright>
<year>2021</year>
<holder>http://www.asipto.com</holder>
</copyright>
</bookinfo>
<toc></toc>

<xi:include href="ruxc_admin.xml"/>

</book>

0 comments on commit 81de787

Please sign in to comment.