Mono - C# API for Kamailio 4.2.x Version
Kamailio can execute managed code assemblies via app_mono module:
The C# API exported by Kamailio to the embedded Mono interpreter is defined in SR.cs file located in source tree modules/app_mono/lib/SR.cs.
To compile SR.cs to a library, use:
This will generate the file SR.dll. To link your C# file to it, use:
The API is stored in a namespace, named SR. The several classes offer access to internal Kamailio functionalities via public static functions.
Class Core
APIVersion
Return API version string.
Log
Write a message via Kamailio logging system to specified log level.
Err
Write a message via Kamailio logging system to error log level.
Dbg
Write a message via Kamailio logging system to debug log level.
ModF
Execute the function named by the value of parameter 'text' exported by a Kamailio module. It has to be a function with no parameters.
Class PV
GetS
Get the string value of a pseudo-variable.
GetI
Get the integer value of a pseudo-variable.
SetS
Set the pseudo-variable to a string value.
SetI
Set the pseudo-variable to an integer value.
Unset
Unset the pseudo-variable (like assigning $null in kamailio.cfg).
IsNull
Return true if the pseudo-variable is null.
Class HDR
Append
Add a header to the end of the headers list. The parameter must be full header, including name, body header and ending '\r\n'.
Remove
Remove all headers matching the name.
Insert
Add a header to the beginning of the headers list. The parameter must be full header, including name, body header and ending '\r\n'.
AppendToReply
Add a header to the headers list for local reply. The parameter must be full header, including name, body header and ending '\r\n'.
Example
A basic example of C# application using SR API:
using SR;
namespace MySRTest {
class Test {
static int Main(string[] args) {
SR.Core.Log(1, "Kamailio API Version: " + SR.Core.APIVersion() + "\n");
if (args.Length == 1) {
SR.Core.Log(1, "Parameter from Kamailio config:"
+ args[0] + "\n");
}
SR.Core.Dbg("Request URI is: " + SR.PV.GetS("$ru") + "\n");
SR.PV.SetS("$rU", "123");
SR.HDR.AppendToReply("My-Mono-Hdr: ok\r\n");
SR.Core.ModF("sl_reply_error");
return 1;
}
}
}