How to decode SIP methods stored by openSIPs?

posted by Peter on 2009-10-14 08:04:07

Well behaved SIP phone should present a list of supported methods (INVITE, MESSAGE, REFER etc.) in "Allow" header when registering with the proxy. This is saved in "methods" column in "location" table by openSIPs. Unfortunately this value is a bitmas so it is not so friendly to look at. The definition of each method (corresponding bit in the mask) can be found in parser/msg_parser.h around line 67.

For example 7999 represents 4096 + 2048 + 1024 + 512 + 256 + 32 + 16 + 8 + 4 +2 +1 which translates to the following methods: REFER, PRACK, NOTIFY, SUBSCRIBE, MESSAGE, OPTIONS, INFO, BYE , ACK, CANCEL, INVITE.

However you might need (as we did) to decode methods supported by registered phone with a PHP code. Below is a sniped which allows for just that:

<?php
$mask = 7999;

$methods = array (
 "0" => "UNDEF",           /* 0 - --- */
 "1" => "INVITE",          /* 1 - 2^0 */
 "2" => "CANCEL",          /* 2 - 2^1 */
 "4" => "ACK",             /* 3 - 2^2 */
 "8" => "BYE",             /* 4 - 2^3 */
 "16" => "INFO",           /* 5 - 2^4 */
 "32" => "OPTIONS",        /* 6 - 2^5 */
 "64" => "UPDATE",         /* 7 - 2^6 */
 "128" => "REGISTER",      /* 8 - 2^7 */
 "256" => "MESSAGE",       /* 9 - 2^8 */
 "512" => "SUBSCRIBE",     /* 10 - 2^9 */
 "1024" => "NOTIFY",       /* 11 - 2^10 */
 "2048" => "PRACK",        /* 12 - 2^11 */
 "4096" => "REFER",        /* 13 - 2^12 */
 "8192" => "PUBLISH",      /* 14 - 2^13 */
 "16384" => "OTHER"        /* 15 - 2^14 */
);

$supported = '';

foreach ($methods as $id => $method)
{
 if ($id & $mask)
 {
   $supported.= $method.", ";
 }
}

echo "Supported methods: $supported";

?>


Hope it might help someone when integrating openSIPs with a web application.




Leave Your Comment

Your name: *
Your Email: *   Will not be published
Your comment: *
Captcha image
To help us prevent automated abuse of this service
please enter the text displayed in the image above: *



All submitted reviews/comments become the licensed property of Level 7 Systems Ltd.

Categories

Enter your email address:

Delivered by FeedBurner

RSS Feed Subscribe with in your feed reader