{"id":338,"date":"2010-11-22T09:27:49","date_gmt":"2010-11-22T08:27:49","guid":{"rendered":""},"modified":"2018-11-01T11:08:02","modified_gmt":"2018-11-01T10:08:02","slug":"configuring-im-and-presence-kamailio-31-howto","status":"publish","type":"post","link":"https:\/\/nil.uniza.sk\/en\/configuring-im-and-presence-kamailio-31-howto\/","title":{"rendered":"Configuring IM and presence on Kamailio 3.1 &#8211; Howto"},"content":{"rendered":"<p>This article continue on series of articles about the Kamailio 3.1.x SIP&nbsp;proxy deployed on debian lenny and its features. In previous articles we have:<\/p>\n<p>1) <a href=\"https:\/\/nil.uniza.sk\/en\/installing-kamailio-31-debian-lenny\/\">installed clear Kamailio 3.1.x server <\/a><\/p>\n<p>2) <a href=\"https:\/\/nil.uniza.sk\/en\/sip\/kamailio\/adding-mysql-support-kamailio-31-debian-lenny\/\">added Mysql support <\/a>for persistance location storage<\/p>\n<p>3) <a href=\"https:\/\/nil.uniza.sk\/en\/sip\/kamailio\/installing-siremis-20-kamailio-web-management-interface-debian-lenny-how\/\">SIREMIS web management interface for our kamailio server<\/a>.<\/p>\n<p>and now, we will configure the IM\/presence support.<\/p>\n<h2>Prerequsities<\/h2>\n<div class=\"level2\">\n<ul>\n<li class=\"level1\">\n<div class=\"li\"><a rel=\"nofollow\" class=\"urlextern\" title=\"http:\/\/www.kamailio.org\" href=\"http:\/\/www.kamailio.org\/\">Kamailio (OpenSER) 3.1.0<\/a> installed and configured for Mysql usage<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Mysql Server installed<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<p>To support presence, Kamailio requires special DB tables for presence. So when you installing Mysql support for Kamailio, you have to uncomment in etc\/kamailio\/kamctlrc file following lines<\/p>\n<pre>\r\n# If to install tables for the modules in the EXTRA_MODULES variable.\r\nINSTALL_EXTRA_TABLES=ask\r\n\r\n# If to install presence related tables.\r\nINSTALL_PRESENCE_TABLES=ask&nbsp;\r\n<\/pre>\n<p>and then run<\/p>\n<pre><span>kamdbctl crea<\/span>te\r\n<\/pre>\n<p>If you are further in your configuration and Mysql is already configured, the <em><strong>kamdbctl <\/strong><\/em>command has a presence options regarding to adding presence tables.<\/p>\n<pre>\r\npstest:\/home\/palo# <span><strong>kamdbctl<\/strong> <\/span>database engine 'mysql' loaded\r\n\/usr\/sbin\/kamdbctl $Revision$\r\n\r\nusage: kamdbctl create &lt;db name or db_path, optional&gt; .....(creates a new database)\r\n       kamdbctl drop &lt;db name or db_path, optional&gt; .......(!entirely deletes tables!)\r\n       kamdbctl reinit &lt;db name or db_path, optional&gt; .....(!entirely deletes and than re-creates tables!)\r\n       kamdbctl backup &lt;file&gt; .................................(dumps current database to file)\r\n       kamdbctl restore &lt;file&gt; ................................(restores tables from a file)\r\n       kamdbctl copy &lt;new_db&gt; .................................(creates a new db from an existing one)\r\n       kamdbctl migrate &lt;old_db&gt; &lt;new_db&gt; .....................(migrates DB from 1.2 to 1.3, not implemented yet!)\r\n       <span>kamdbctl presence <\/span>......................................(adds the presence related tables)\r\n       kamdbctl extra .........................................(adds the extra tables)\r\n\r\n<\/pre>\n<p>So you may run kamdbctl presence, and required tables will be added.<\/p>\n<p>Do not run  kamdbctl presence, if you already have <strong>installed <\/strong>presence tables using   kamdbctl create during initial DB&nbsp;initialisation. Running&nbsp;  kamdbctl presence will do change in kamailio database and it causing problem to run presence correctly. Precisely, the version table of the kamailio database is modyfied such way, that there are added new indexes pointing to a duplicated tables regarding to the presence service with different version indexes.<\/p>\n<h2>Dependencies<\/h2>\n<p>The following modules must be loaded before this module:&nbsp;<\/p>\n<ul>\n<li>a database module.<\/li>\n<li>&nbsp;sl.<\/li>\n<li>&nbsp;tm.<\/li>\n<\/ul>\n<p>External Libraries or Applications have to be already installed<\/p>\n<ul>\n<li>libxml.<br \/>\n    &nbsp;<\/li>\n<\/ul>\n<h2>Installing the kamailio presence module<\/h2>\n<pre>\r\napt-get install kamailio-presence-modules\r\n<\/pre>\n<p>and do not forget restart kamailio server \/etc\/init.d\/kamailio restart<\/p>\n<h2>Configuration of the Kamailio for Instant Messaging and Presence (SIMPLE)<\/h2>\n<p>The Presence and instant messaging RFC&nbsp;standards are quite complex and wide. For this kind of service over Kamailio we will use presence and xcap modules.<\/p>\n<p>Kamailio 3.1.x<\/p>\n<ul>\n<li><a href=\"http:\/\/www.kamailio.org\/docs\/modules\/3.1.x\/modules_k\/presence.html\">Presence module documentation<\/a><\/li>\n<li><a href=\"http:\/\/www.kamailio.org\/docs\/modules\/3.1.x\/modules_k\/presence_xml.html\">Presence XML&nbsp;module for XCAP<\/a><\/li>\n<\/ul>\n<h3>Loading required modules<\/h3>\n<p>Open <em>\/etc\/kamailio\/kamailio.cfg<\/em> and we go through, line by line.<\/p>\n<p>At the top of the cfg file, in define zone blocks, we have prepared<\/p>\n<pre>\r\n# *** To enable presence server execute:\r\n#     - enable mysql\r\n#     - define WITH_PRESENCE\r\n<\/pre>\n<p>so we will define presence support<\/p>\n<pre>\r\n#!define WITH_PRESENCE\r\n<\/pre>\n<p>and for the basic Presence configuration <strong>it is all<\/strong>. All other lines are included inside of the kamailio.cfg as directive blocks.<\/p>\n<p>&nbsp;<\/p>\n<p>Anyway, we may look through.<\/p>\n<p>In module section (starting with <strong>####### Modules Section ########<\/strong>) we will find<\/p>\n<pre>\r\n#!ifdef WITH_PRESENCE\r\nloadmodule &quot;presence.so&quot;\r\nloadmodule &quot;presence_xml.so&quot;\r\n#!endif\r\n<\/pre>\n<p>What mean, that if we have defined presence directive (and we have), the modules will be loaded.<\/p>\n<h3>Setting up module parameters<\/h3>\n<p>Now we are going to setting module parameters, and in config file we are moving behind<\/p>\n<pre>\r\n# ----------------- setting module-specific parameters ---------------\r\n<\/pre>\n<p>so we are in and going through we find prepared lines.<\/p>\n<pre>\r\n#!ifdef WITH_PRESENCE\r\n# ----- presence params -----\r\nmodparam(&quot;presence&quot;, &quot;db_url&quot;, DBURL)\r\n\r\n# ----- presence_xml params -----\r\nmodparam(&quot;presence_xml&quot;, &quot;db_url&quot;, DBURL)\r\nmodparam(&quot;presence_xml&quot;, &quot;force_active&quot;, 1)\r\n#!endif\r\n<\/pre>\n<p>The first and the second modparam (<em>modparam(&quot;presence&quot;, &quot;db_url&quot;, DBURL), 9modparam(&quot;presence_xml&quot;, &quot;db_url&quot;, DBURL)<\/em>)<em> <\/em>is pointing to the database defined in the upper part of the kamailio.cfg. And if we have correctly configured Mysql support, we do not need to deal with.<\/p>\n<pre>\r\n####### Defined Values #########\r\n\r\n# *** Value defines - IDs used later in config\r\n#!ifdef WITH_MYSQL\r\n# - database URL - used to connect to database server by modules such\r\n#       as: auth_db, acc, usrloc, a.s.o.\r\n#!define DBURL &quot;mysql:\/\/openser:openserrw@localhost\/kamailio&quot;\r\n#!endif\r\n<\/pre>\n<p>The last modparam (<a href=\"http:\/\/www.kamailio.org\/docs\/modules\/3.1.x\/modules_k\/presence_xml.html#id2897378\">modparam(&quot;presence_xml&quot;, &quot;force_active&quot;, 1<\/a>)) deals about subscription permissions. The parameters has value 1 if we use XCAP server, otherwise should be 0.<\/p>\n<h2>Modifying route logic for using IP\/Presence<\/h2>\n<p>Inside of the main routing logic, starting woth lines<\/p>\n<pre>\r\n# Main SIP request routing logic\r\n# - processing of any incoming SIP request starts with this route\r\nroute {\r\n<\/pre>\n<p>we may find preconfigured route calling to handle Presence (<strong><em>route(PRESENCE)<\/em><\/strong>)<\/p>\n<pre>\r\n# handle presence related requests\r\n        route(PRESENCE);\r\n<\/pre>\n<p>where the route(PRESENCE) contain lines<\/p>\n<pre>\r\nroute[PRESENCE] {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!is_method(&quot;PUBLISH|SUBSCRIBE&quot;))\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;\r\n\r\n#!ifdef WITH_PRESENCE\r\n&nbsp;&nbsp;&nbsp;&nbsp;&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&nbsp;&nbsp;&nbsp; t_release();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit;\r\n#!endif\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # if presence enabled, this part will not be executed\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (is_method(&quot;PUBLISH&quot;) || $rU==$null)\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sl_send_reply(&quot;404&quot;, &quot;Not here&quot;);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;\r\n}\r\n<\/pre>\n<p>So the default behaviour should be fulfilled and the service should work.<\/p>\n<h2>Testing<\/h2>\n<p>Using Bria and SipCommuicator with Presence agent settings (not peer to peer) work nice. Transfer of the buddy lists do not work yet.<\/p>\n<p>Using wireshark at both client sides, or ngrep on the server, we should observe message diagram looking something like<\/p>\n<pre>\r\nPUA                     PA                      WATCHER\r\n                           \r\n  |                       |                      |\r\n  |                       | &lt;----- SUBSCRIBE --- |\r\n  |                       |                      |\r\n  |                       | ------ 200 OK -----&gt; |\r\n  |                       |                      |\r\n  |                       | -----  NOTIFY -----&gt; |\r\n  |                       |                      |\r\n  |                       | &lt;----  200 OK ------ |\r\n  |                       |                      |\r\n  |                       |                      |\r\n  | -------  PUBLISH ---&gt; |                      |\r\n  |                       |                      |\r\n  | &lt;------  200 OK ----  |                      |\r\n  |                       |                      |\r\n  |                       | -----  NOTIFY -----&gt; |\r\n  |                       |                      |\r\n  |                       | &lt;----  200 OK ------ |\r\n  |                       |                      |  <\/pre>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>This article continue on series of articles about the Kamailio 3.1.x SIP&nbsp;proxy deployed on debian lenny and its features. In previous articles we have:<\/p>\n<p>1) <a href=\"https:\/\/nil-test.kis.fri.uniza.sk\/installing-kamailio-31-debian-lenny\">installed clear Kamailio 3.1.x server <\/a><\/p>\n<p>2) <a href=\"https:\/\/nil-test.kis.fri.uniza.sk\/sip\/kamailio\/adding-mysql-support-kamailio-31-debian-lenny\">added Mysql support <\/a>for persistance location storage<\/p>","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[781,795,661],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-kamailio-en","category-services-en","category-instant_messaging-simple-en"],"taxonomy_info":{"category":[{"value":781,"label":"Kamailio"},{"value":795,"label":"Services"},{"value":661,"label":"SIMPLE"}]},"featured_image_src_large":false,"author_info":{"display_name":"admin","author_link":"https:\/\/nil.uniza.sk\/en\/author\/admin\/"},"comment_info":9,"category_info":[{"term_id":781,"name":"Kamailio","slug":"kamailio-en","term_group":0,"term_taxonomy_id":779,"taxonomy":"category","description":"","parent":771,"count":29,"filter":"raw","cat_ID":781,"category_count":29,"category_description":"","cat_name":"Kamailio","category_nicename":"kamailio-en","category_parent":771},{"term_id":795,"name":"Services","slug":"services-en","term_group":0,"term_taxonomy_id":793,"taxonomy":"category","description":"","parent":771,"count":3,"filter":"raw","cat_ID":795,"category_count":3,"category_description":"","cat_name":"Services","category_nicename":"services-en","category_parent":771},{"term_id":661,"name":"SIMPLE","slug":"instant_messaging-simple-en","term_group":0,"term_taxonomy_id":659,"taxonomy":"category","description":"","parent":659,"count":2,"filter":"raw","cat_ID":661,"category_count":2,"category_description":"","cat_name":"SIMPLE","category_nicename":"instant_messaging-simple-en","category_parent":659}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":0,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"wp:attachment":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}