Showing posts with label Opensips. Show all posts
Showing posts with label Opensips. Show all posts

Monday, 22 June 2015

Opensips Nat Handling

Call fix_nat_sdp for INVITE,RE-Invite.. That's it, This route will take care of everything..


route[fix_nat_sdp] {

        if(has_body("application/sdp"))
 {
                xlog("fix_nat_sdp called\n");
                setbflag(3);
                rtpproxy_offer();       
                t_on_failure("1");
        }

 t_on_reply("1");

        if(nat_uac_test("1")){
                fix_nated_contact(); 
        }
}

onreply_route[1] {
        xlog("onreply_route called\n");
        if(nat_uac_test("1")){
                fix_nated_contact(); 
        }

        if(has_body("application/sdp")){
                rtpproxy_answer();
        }
}

Friday, 6 February 2015

enabling full debug for the specific function.. Here i am enabling full debugging for the m_store() function.

enabling full debug for the specific function.. Here i am enabling full debugging for the m_store() function.

Also , you could enable full debug for the m_dump() function:
    set_debug(4);
    m_dump();
    set_debug();

Tuesday, 3 February 2015

Using SIPSAK command to send m

sipsak -vvvv -c sip:from_number@192.168.1.70 -s sip:to_number@192.168.1.70 -B "hello this is message body"

Thursday, 22 January 2015

RTP Proxy Installation From Source



Basic Steps in RTP Proxy Installation:
This is a rookie guide for people running Ubuntu 9.04, have OpenSIPS 1.5.2 installed on their server, and wanted to implement RTPProxy as media server.

If your already have basic knowledge you can skip the basic steps and proceed to expert installation steps…

Objectives:
1. Package/Dependencies Installation
2. RTPProxy Installation
3. OpenSIPS 1.5.2 Configuration
4. Database MySQL 5.0.51a Configuration

Assumptions:
- OpenSIPS 1.5.2 (latest version) Installed.
– UDP/Media ports* are open on your router.
(Configure Router for the Ports to be used by rtpproxy by opening them first.)

Use dpkg command to list installed software and follow the codes listed bellow:

$ dpkg –get-selections
$ mkdir /backup
$ dpkg –get-selections > /backup/installed-software.log
$ cd /usr/src
$ wget http://b2bua.org/chrome/site/rtpproxy-1.2.0.tar.gz
$ tar -xzvf rtpproxy-1.2.0.tar.gz

Change to the directory and install the program
$ cd rtpproxy-1.2
$ ./configure
$ make
$ make install

Create a system user with no privileges and start the daemon running
$ adduser rtpproxy
$ rtpproxy -u rtpproxy

Now rtpproxy should be running and if you check in /var/run you should see rtpproxy.sockand rtpproxy.pid

Running Manually:
$ rtpproxy -l 192.168.1.109 -s udp:127.0.0.1:50000 -u usrname &
OR
$ rtpproxy -s udp:127.0.0.1:50000 -f -u opensips -l 192.168.1.109 &

Consideration:
Creating the user rtpproxy was not essential, you can run the daemon under whatever user you are logged in as by simply typing rtpproxy at the command but I read that it is safe practice to run the daemon under a non privileged user. (Maybe someone can comment on the linux user I added. I am not 100% on the security of the user added with no password but the way I understand it the user cannot access the system until a password is created.)

Monday, 12 January 2015

OPENSIPS 477 send failed not Entering into Failure Root

Failure Route is not executed on a 477 or IP-Blocked error.
- t_on_failure is set
- failure_route is existing
- t_relay is always positive in an if-construct
- you may catch the 477 error inscript but not as a failure route
- Status code is always send
We expected the same behaviour as on a 408 error.


Actually this case is supposed to work a bit different when you think. By design (on logical reasons), the failure route is triggered only when there is a SIP failure (transaction failed with negative reply).
In your case, you have a different case of failure - you were actually not able to send the INVITE out, so it is a transport error. So failure route is not supposed to be triggered.
What to do here is to use the "0x02" flag with t_relay() - seehttp://www.opensips.org/html/docs/modules/1.9.x/tm.html#id293413 - this will make t_relay() to return failure to script instead of sending the 477 out -> at script level you can handle the failure.

Tuesday, 25 November 2014

opensips fr_timeout and fr_inv_timeout

fr_timeout is the interval between the request and the first provisional reply - shortly, how long to to wait for the first provisional reply.

fr_inv_timeout is the interval between the request and the final reply (2xx or negative) - shortly, how long to wait for completing the transaction.

So you can use different values for these 2 timers for a transaction to get the desired behavior. 

Monday, 10 November 2014

Generating Text messages, INFO messages from OPENSIPS script

Opensips is a SIP Server. I thought it is not capable to generate sip messages from it's script file i.e opensips.cfg. because opensips is basically SIP server, Server always serves request (i.e give response ) to it's UAC and unable to generate request from it. Then i had a requirement i need to send Text Message to my User Agent Client. I actually started searching about it Finally i came to Know that  OPENSIPS is able to Send text messages from it's Script. Today in this Short tutorial we will discuss about "How to Generate Custom Messages from opensips script".


How to generate Text messages from OPENSIPS script :

This can be done by using t_uac_dlg exported MI function of TM module. and im_send.php file used to send Instant messages from OPENSIPS to any User agent client.

I am trying to generate Text message from Opensips.cfg and sending it to desired UAC.

Here is the Details about t_uac_dlg function

t_uac_dlg :

Generates and sends a local SIP request.

Parameters:

  • method - request method
  • RURI - request SIP URI
  • NEXT HOP - next hop SIP URI (OBP); use “.” if no value.
  • socket - local socket to be used for sending the request; use “.” if no value.
  • headers - set of additional headers to be added to the request; at least “From” and “To” headers must be specify)
  • body - (optional, may not be present) request body (if present, requires the “Content-Type” and “Content-length” headers)
we are also using im_send.php file. you can get this file from GITHUB OPENSIPS repositary.
my im_send.php file look like this..

im_send.php file for Sending Custom Text message :

  1. <?php
  2. /* config values */
  3. $web_contact="sip:daemon@mydomain.net";
  4. $fifo="/tmp/opensips_fifo";
  5. $signature="web_im_0.1.0";
  6.  
  7. /* open reply fifo */
  8. $myfilename="webfifo_".rand();
  9. $mypath="/tmp/".$myfilename;
  10. $outbound_proxy=".";
  11.  
  12.  
  13. // store argument 1 in to_user address
  14. if (isset($argv[1])) {
  15.         $sip_address = $argv[1];
  16. }
  17.  
  18. // store argument 2 in $fromNumber variable - this is From DID
  19. if (isset($argv[2])) {
  20.         $fromNumber=$argv[2];
  21. }
  22.  
  23. // store argument 3 is Error Message..
  24. if (isset($argv[3])) {
  25.         $instant_message = $argv[3];
  26. }
  27.  
  28. echo "Initiating your request...<p>";
  29.  
  30. /* open fifo now */
  31. $fifo_handle=fopen( $fifo, "w" );
  32. if (!$fifo_handle) {
  33.     exit ("Sorry -- cannot open fifo: ".$fifo);
  34. }
  35.  
  36. /* construct FIFO command */
  37. $fifo_cmd=":t_uac_dlg:".$myfilename."\n".
  38.     "MESSAGE\n".
  39.     $sip_address."\n".
  40.         $outbound_proxy."\n".
  41.     ".\n".
  42.     "\"From: ".$fromNumber."\r\n".
  43.         "To: ".$sip_address."\r\n".
  44.         "p-version: ".$signature."\r\n".
  45.     "Contact: ".$fromNumber."\r\n".
  46.     "Content-Type: text/plain; charset=UTF-8\r\n".
  47.     "\"\n".
  48.     "\"".$instant_message."\"".
  49.         "\n\n";
  50.  
  51. /* create fifo for replies */
  52. system("mkfifo -m 666 ".$mypath );
  53.  
  54. /* write fifo command */
  55. if (fwrite( $fifo_handle, $fifo_cmd)==-1) {
  56.     unlink($mypath);
  57.     fclose($fifo_handle);
  58.     exit("Sorry -- fifo writing error");
  59. }
  60. fclose($fifo_handle);
  61.  
  62. /* read output now */
  63. if (readfile( $mypath )==-1) {
  64.     unlink($mypath);
  65.         exit("Sorry -- fifo reading error");
  66. }
  67. unlink($mypath);
  68. echo "<p>Thank you for using IM<p>";
  69.  
  70. ?>

This im_send.php takes three arguments.. 
      1) to_user
      2) form _user -==> Here opensips generating Message so.. opensips itself is From user..
      3) Custom Message 
 ex :  Hello UAC this message Genetated from opensips.cfg

Save this file as *.php and now we have im_send.php file. Need to call this file from opensips script

Calling im_send.php file from opensips Script i.e opensips.cfg:

loadmodule "uac.so"
loadmodule "exec.so"

call above im_send.php file whenever you want to send text message. like this

$avp(message)="Hello UAC this is Custom Text Message";
exec_avp("php /usr/local/sbin/im_send.php '$fu' '$ru' '$avp(message)'","$avp(status)");

Make sure the path of im_send.php file is correct. also check file permissions Opensips running user need to have permissions to access that file.
i recommend 755 for that file.

Congratulations, You're Successfully Configured opensips to generate Custom Messages.



Tuesday, 30 September 2014

Writing New opensips Module

My interest is mostly in writing new Modules for OpenSER at this time. I could not find a lot of information about it, so I started this page set. Please if you find I am going down the wrong path, correct me and these pages. I will try to only include correct information, but I am learning as I go.

Introduction

The code and APIs are based off the current 1.1.x source base.
When starting a new module, there are a few things you must do. Listed below will get you started with the template module structured code example:

Template Module

#include "../../sr_module.h"
 
MODULE_VERSION/*Module */
 
static int mod_init(void);
static void mod_destroy(void);
static int child_init(int);
 
/*
 * Script commands we export.
 */
static cmd_export_t cmds[]={
  {0,0,0,0,0}
};
 
/*
 * Script parameters
 */
static param_export_t mod_params[]={
  { 0,0,0 }
};
 
/*
 * Export the statistics we have
 */
static stat_export_t mod_stats[] = {
  {0,0,0}
};
 
struct module_exports exports= {
  "MyMod", /* module's name */
  cmds,         /* exported functions */
  mod_params,   /* param exports */
  mod_stats,    /* exported statistics */
  modInit,      /* module initialization function */
  0,            /* reply processing function FIXME Not sure when this is used */
  modDestroy,   /* Destroy function */
  childInit     /* per-child init function */
};
 
/**
 * @return 0 to continue to load the OpenSER, -1 to stop the loading
 * and abort OpenSER.
 */
static int modInit(void) {
  return(0);
}
 
/**
 * Called only once when OpenSER is shuting down to clean up module
 * resources.
 */
static void modDestroy() {
  return;
}
 
/**
 * The rank will be o for the main process calling this function,
 * or 1 through n for each listener process. The rank can have a negative
 * value if it is a special process calling the child init function.
 * Other then the listeners, the rank will equal one of these values:
 * PROC_MAIN      0  Main ser process
 * PROC_TIMER    -1  Timer attendant process 
 * PROC_FIFO     -2  FIFO attendant process
 * PROC_TCP_MAIN -4  TCP main process
 * PROC_UNIXSOCK -5  Unix domain socket server processes
 *
 * If this function returns a nonzero value the loading of OpenSER will
 * stop.
 */
static int childInit(int rank) {
  int rtn = 0;
 
  return(rtn);
}
  • The sr_module.h file must be included
  • You must include the MODULE_VERSION macro. This tells OpenSER the module was built for the correct version of the running OpenSER when the module is loaded. If the version number does not match, the load will fail.
  • Declare your local initialization and destructor functions.
  • Fill out the following data structures to export the modules functionality.
    • cmd_export_t - This structure is where you export the script functions. (more on it later)
    • param_export_t structure is used to export the modules parameters that can be set in the script (openser.cfg)
    • stat_export_t If your module wants to track statistics this is where you declare and export them.
    • module_exports - This is where you tie all the exported information together to define your new Module.
      • The module name. A char * that uniquely identifies your module.
      • The pointer to the cmd_export_t (or NULL if none defined)
      • The pointer to the param_export_t (or NULL if none defined)
      • The pointer to the stat_export_t (or NULL if none defined)
      • The module initialization function pointer. FIXME Function prototype needed here. (rw)
      • FIXME Need more information on this function pointer.
      • The module destroy function pointer. FIXME Need prototype here. (rw)
      • FIXME Need the child init function explained and included in the example. (rw)
You should be able to cut and paste the code above into your first module “C” file. To build the module, read the Module Makefile section.

Module export structure

cmd_export_t

struct cmd_export_t {
 char* name;             /* null terminated command name */
 cmd_function function;  /* pointer to the corresponding function */
 int param_no;           /* number of parameters used by the function */
 fixup_function fixup;   /* pointer to the function called to "fix" the
       parameters */
 int flags;              /* Function flags */
};
  • name char * - A null terminated command name.
  • function int (*cmd_function)(struct sip_msg*, char*, char*) - The C function pointer to bind to the named script function.
  • param_no int - The number of parameters to pass to the C function (the function argument count)
  • fixup int (*fixup_function)(void * * param, int param_no); - FIXME Need more information on this function.
  • flags int - Can't have a structure without flags! The flags tell the script when it is legal to call the function. The flag values can be “or'ed” together if the function can be called from more then one routing section of the openser.cfg script. i.e. REQUEST_ROUTE | ONREPLY_ROUTE
    • REQUEST_ROUTE - The function can be called in the request route section of the openser.cfg script.
    • FAILURE_ROUTE - The function can be called in the failure route section of the openser.cfg script.
    • ONREPLY_ROUTE - The function can be called in the reply route section of the openser.cfg script.
    • BRANCH_ROUTE - The function can be called in the branch route section of the openser.cfg script.

Hints & Tips

Because the module is written in “C” you must be carefull about naming your functions. The function field in the cmd_export_t structure can be file scope (static) if you want to define the real handler in the same file as you define the cmd_export_t structure. In most cases you will want to define all your handlers in a separate file like MyMod_handlers.c. In this case, make sure you add your module name to the begining of the function named to ensure there is no namespace collisions. i.e. MyMod_func1().

Licensing of Modules

The relevant part of the GPL concerning distribution of proprietary modules is the bottom of section 2, here quoted:
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a workbased on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 
So, if you are writing a closed module that washes the dog, walks the dishes, and controls the light in your aquarium within the larger context of the openSER framework, without modifying the framework, directing people who wish source code to the openSER web site to obtain the GPL'd portions of a proprietary and commercial VOIP-controlled dog-washing, dish-walking, aquarium-light-controlling appliance is sufficent, although RMS will probably not share his ravs with you should the opportunity arise. Your module's main focus – home automation with regard to dogs,
dishes, and pet fish – is not the main focus of openSER, and although your module plugs into the openSER framework, it could just as well plug into some other framework instead of openSER.
The GPL would not force distribution of your trade secrets involved in your dog/dish/fish component.
Addition of a module does not constitute a modification of openSER, nor does selection of openSER as a product's framework for interfacing with VOIP necessarily make the resulting composite work a derivative work of openSER.
Said home automation system would not be “based on” openSER. Said home automation system would include openSER for VOIP functionality.
Adherence to the provided and documented module API fulfills the “arm's length” requirement discussed at http://www.gnu.org/licenses/gpl-faq.html#TOCGPLInProprietarySystem even though the module and the framework will be linked into a single binary executable file, which is a technical detail.

Monday, 29 September 2014

Make File Structure of opensips Module | opensips module makefile structure

Module Makefiles and Building

The Makefile in each module subdirectory is small and simple to use. If you do not have any extra libraries or make definitions required to build your module, you can take the template below and just drop it into the top level directory of your new module.

Module directory structure

All OpenSER modules are kept in the sip-server/modules directory of the source code. To add your module to the build, just add a subdirectory with the same name as the module to the sip-server/modules directory and run make modules. The top level makefile will find the new code and include it into the build process.

Template Makefile

The following template is the minimum requirements to build your module. There are a few additional things you can include into the Makefile to customize it.
include ../../Makefile.defs
auto_gen=
NAME=MyMod.so
LIBS= 

include ../../Makefile.modules
The one and only required item is the NAME variable in the Makefile. You must set it to the final target name of the modules shared object.

Additional Makefile variables

There are few other makefile variables that you can override or append to in the Makefile to pass additional information to your build.
  • LIBS - Add any linker options you require to build the module. This would include the -llibrary and the -Lpath_to_library options if your module requires external libraries.
  • DEFS - Append any additional definitions you want to pass to the compiler when building your module. You can do this with the ”+=” makefile operator. DEFS+=-DMY_NEW_DEFINE -I../../../external/includes

Wednesday, 24 September 2014

CDRTool virtual host Configuration | how to enable Virtual host on 8080 post


This post is written by a newbie linux user .

We know that apache2 is runnig on 80 port. I also tried to add the new virtual host for CDRTool in 80 port but it is not wotking. So i decided to run CDRTool virtual host on 8080 port.

Here is the configuration

step 1 :

cp setup/apache2/sites-available/cdrtool.example.com /etc/apache2/sites-enabled
step 2 :

rename it to your website name
mv cdrtool.example.com mysite.com

step 3 :
edit mysite.com file to suit your Environment here is my file

Listen 8080

NameVirtualHost mysite.com:8080

<VirtualHost mysite.com:8080>

ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/
CustomLog /var/log/apache2/cdrtool-access.log combined
ErrorLog /var/log/apache2/cdrtool-errors.log
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

<Directory /var/www/CDRTool>
Options FollowSymLinks
AllowOverride All
</Directory>

</VirtualHost>

save the file
step 4 :
now move this file to /etc/apache2/sites-available/ folder.
Mv /etc/apache2/sites-enable/mysite.com /etc/apache2/sites-available/

step 5 :
now use a2ensite command on mysite.com file like this
a2ensite mysite.com

step 6 :
Now restart the apache2 like this
/etc/init.d/apache2 relaod
That's it. You are successfully configured one New Virtual host

step 7:
open your browser. Now type like this

mysite.com:8080/CDRTool

ohhhh you can see CDRTool Login page now..


Thursday, 18 September 2014

opensips.cfg file example with use_media_proxy and end_media_session.

opensips.cfg file with use_media_proxy() and end_media_session()  :
  1. # log levels:
  2. # 1 warn
  3. # 2 notice
  4. # 3 info
  5. # 4 debug (default)
  6.                                    # globals
  7. listen=udp:sip.example.com:5060
  8. fifo="/tmp/openser_fifo"
  9.  
  10.                                  # load modules
  11. loadmodule "/usr/lib/openser/modules/sl.so"
  12. loadmodule "/usr/lib/openser/modules/tm.so"
  13. loadmodule "/usr/lib/openser/modules/rr.so"
  14. loadmodule "/usr/lib/openser/modules/maxfwd.so"
  15. loadmodule "/usr/lib/openser/modules/usrloc.so"
  16. loadmodule "/usr/lib/openser/modules/registrar.so"
  17. loadmodule "/usr/lib/openser/modules/textops.so"
  18. loadmodule "/usr/lib/openser/modules/auth.so"
  19. loadmodule "/usr/lib/openser/modules/domain.so"
  20. loadmodule "/usr/lib/openser/modules/mediaproxy.so"
  21. loadmodule "/usr/lib/openser/modules/acc.so"
  22. loadmodule "/usr/lib/openser/modules/exec.so"
  23. loadmodule "/usr/lib/openser/modules/xlog.so"
  24.  
  25.  
  26.                                 # module params
  27. # rr
  28. # add value to ;lr param to make some broken UAs happy
  29. modparam("rr""enable_full_lr"1)
  30.  
  31. # mediaproxy
  32. #modparam("mediaproxy", "mediaproxy_socket", "/var/run/proxydispatcher.sock")
  33. #modparam("mediaproxy", "natping_interval", 60)
  34. modparam("registrar""nat_flag"2)
  35.  
  36.                            # request routing logic
  37. alias="example.com"
  38. alias="voip.example.com"
  39. route
  40. {
  41.     # sanity checks
  42.     if (!mf_process_maxfwd_header("10"))
  43.     {
  44.         sl_send_reply("483","Too Many Hops");
  45.         exit;
  46.     }
  47.     if (msg:len >= max_len)
  48.     {
  49.         sl_send_reply("513""Message too big");
  50.         exit;
  51.     }
  52.  
  53.     # apply loose (normal) routing rules
  54.     loose_route();
  55.  
  56.     # NAT test
  57.     if (client_nat_test("3") && !search("^Route:"))
  58.     {
  59.         setflag(2)# flag for NAT
  60.         force_rport();
  61.         fix_contact();
  62.         append_hf("P-hint: NAT\r\n");
  63.     }
  64.  
  65.     # outbound routing if not for me
  66.     lookup("aliases");
  67.     if (uri != myself)
  68.     {
  69.         route(1);
  70.         exit;
  71.     }
  72.  
  73.     # Registration
  74.     if (method == "REGISTER")
  75.     {
  76.         save("location")# simple no-auth registration
  77.         exit;
  78.     }
  79.  
  80.     if (method == "INVITE")
  81.     {
  82.         # enable Record-Route
  83.         record_route();
  84.  
  85.         # Is this to one of our numbers
  86.         if (lookup("location"))
  87.         {
  88.             append_hf("P-hint: userloc applied\r\n");
  89.         }
  90.         else
  91.         {
  92.             sl_send_reply("404","Not found");
  93.         }
  94.     }
  95.     route(1);
  96. }
  97.  
  98.  
  99. route[1]
  100. {
  101.     if (isflagset(2))
  102.     {
  103.         if (method == "INVITE")
  104.         {
  105.             t_on_reply("1");
  106.             t_on_failure("1");
  107.             use_media_proxy();
  108.         }
  109.         else if (method == "BYE" || method == "CANCEL")
  110.         {
  111.             end_media_session();
  112.         }
  113.     }
  114.  
  115.     # send it out now; use stateful forwarding as it works reliably
  116.     # even for UDP2TCP
  117.     if (!t_relay())
  118.     {
  119.         sl_reply_error();
  120.     }
  121.     exit;
  122. }
  123.  
  124. onreply_route[1]
  125. {
  126.     if (status =~ "(183)|(2[0-9][0-9])")
  127.     {
  128.         if (client_nat_test("1"))
  129.         {
  130.             fix_contact();
  131.         }
  132.         use_media_proxy();
  133.     }
  134. }
  135.  
  136. failure_route[1]
  137. {
  138.     end_media_session();
  139. }
  140.  
  141. # The perl filetype works pretty well for this
  142. # vim: filetype=perl







E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

© 2014 VOIP4Learn. WP themonic converted by Bloggertheme9. Powered by Blogger.
TOP