This shows you the differences between two versions of the page.
— |
embeddedapi:4.3.x:mono [2015/06/03 13:23] (current) miconda created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Mono - C# API for Kamailio 4.3.x Version ====== | ||
+ | |||
+ | Kamailio can execute managed code assemblies via **app_mono** module: | ||
+ | |||
+ | * http:// | ||
+ | |||
+ | The C# API exported by Kamailio to the embedded Mono interpreter is defined in **SR.cs** file located in source tree **modules/ | ||
+ | |||
+ | To compile **SR.cs** to a library, use: | ||
+ | |||
+ | < | ||
+ | gmcs -t:library SR.cs | ||
+ | </ | ||
+ | |||
+ | This will generate the file **SR.dll**. To link your C# file to it, use: | ||
+ | |||
+ | < | ||
+ | $ gmcs -r:SR.dll MyFile.cs | ||
+ | </ | ||
+ | |||
+ | The API is stored in a **namespace**, | ||
+ | |||
+ | ===== Class Core ===== | ||
+ | |||
+ | ==== APIVersion ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static string APIVersion(); | ||
+ | </ | ||
+ | |||
+ | Return API version string. | ||
+ | |||
+ | ==== Log ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static void Log(int level, string text); | ||
+ | </ | ||
+ | |||
+ | Write a message via Kamailio logging system to specified log level. | ||
+ | |||
+ | ==== Err ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static void Err(string text); | ||
+ | </ | ||
+ | |||
+ | Write a message via Kamailio logging system to error log level. | ||
+ | |||
+ | ==== Dbg ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static void Dbg(string text); | ||
+ | </ | ||
+ | |||
+ | Write a message via Kamailio logging system to debug log level. | ||
+ | |||
+ | ==== ModF ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int ModF(string text); | ||
+ | </ | ||
+ | |||
+ | Execute the function named by the value of parameter ' | ||
+ | |||
+ | ===== Class PV ===== | ||
+ | |||
+ | ==== GetS ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static string GetS(string pvn); | ||
+ | </ | ||
+ | |||
+ | Get the string value of a pseudo-variable. | ||
+ | |||
+ | ==== GetI ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int GetI(string pvn); | ||
+ | </ | ||
+ | |||
+ | Get the integer value of a pseudo-variable. | ||
+ | |||
+ | ==== SetS ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int SetS(string pvn, string val); | ||
+ | </ | ||
+ | |||
+ | Set the pseudo-variable to a string value. | ||
+ | |||
+ | ==== SetI ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int SetI(string pvn, int val); | ||
+ | </ | ||
+ | |||
+ | Set the pseudo-variable to an integer value. | ||
+ | |||
+ | ==== Unset ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int Unset(string pvn); | ||
+ | </ | ||
+ | |||
+ | Unset the pseudo-variable (like assigning $null in kamailio.cfg). | ||
+ | |||
+ | ==== IsNull ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int IsNull(string pvn); | ||
+ | </ | ||
+ | |||
+ | Return true if the pseudo-variable is null. | ||
+ | |||
+ | ===== Class HDR ===== | ||
+ | |||
+ | ==== Append ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int Append(string hv); | ||
+ | </ | ||
+ | |||
+ | Add a header to the end of the headers list. The parameter must be full header, including name, body header and ending ' | ||
+ | |||
+ | ==== Remove ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int Remove(string name); | ||
+ | </ | ||
+ | |||
+ | Remove all headers matching the name. | ||
+ | |||
+ | ==== Insert ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int Insert(string hv); | ||
+ | </ | ||
+ | |||
+ | Add a header to the beginning of the headers list. The parameter must be full header, including name, body header and ending ' | ||
+ | |||
+ | ==== AppendToReply ==== | ||
+ | |||
+ | <code c> | ||
+ | public extern static int AppendToReply(string hv); | ||
+ | </ | ||
+ | |||
+ | Add a header to the headers list for local reply. The parameter must be full header, including name, body header and ending ' | ||
+ | |||
+ | ===== Example ===== | ||
+ | |||
+ | A basic example of C# application using SR API: | ||
+ | |||
+ | <code c> | ||
+ | using SR; | ||
+ | |||
+ | namespace MySRTest { | ||
+ | class Test { | ||
+ | static int Main(string[] args) { | ||
+ | SR.Core.Log(1, | ||
+ | if (args.Length == 1) { | ||
+ | SR.Core.Log(1, | ||
+ | + args[0] + " | ||
+ | } | ||
+ | SR.Core.Dbg(" | ||
+ | SR.PV.SetS(" | ||
+ | SR.HDR.AppendToReply(" | ||
+ | SR.Core.ModF(" | ||
+ | return 1; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||