Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 8839b0a2474211d1e41984e51e6c40b7 > files > 42

linphone-devel-3.5.2-5.fc18.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>liblinphone: Basic buddy status notification</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">liblinphone
   &#160;<span id="projectnumber">3.5.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Basic buddy status notification</div>  </div>
<div class="ingroups"><a class="el" href="group__tutorials.html">Tutorials:</a></div></div><!--header-->
<div class="contents">
<p>*This program is a <em>very</em> simple usage example of liblinphone, *demonstrating how to initiate SIP subscriptions and receive notifications from a sip uri identity passed from the command line. <br/>
Argument must be like sip:<a href="#" onclick="location.href='mai'+'lto:'+'jeh'+'an'+'@si'+'p.'+'lin'+'ph'+'one'+'.o'+'rg'; return false;">jehan<span style="display: none;">.nosp@m.</span>@sip<span style="display: none;">.nosp@m.</span>.linp<span style="display: none;">.nosp@m.</span>hone<span style="display: none;">.nosp@m.</span>.org</a> . <br/>
 *ex budy_list sip:<a href="#" onclick="location.href='mai'+'lto:'+'jeh'+'an'+'@si'+'p.'+'lin'+'ph'+'one'+'.o'+'rg'; return false;">jehan<span style="display: none;">.nosp@m.</span>@sip<span style="display: none;">.nosp@m.</span>.linp<span style="display: none;">.nosp@m.</span>hone<span style="display: none;">.nosp@m.</span>.org</a> <br/>
Subscription is cleared on SIGINT <br/>
 </p>
<div class="fragment"><div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment">buddy_status</span></div>
<div class="line"><span class="comment">Copyright (C) 2010  Belledonne Communications SARL </span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">This program is free software; you can redistribute it and/or</span></div>
<div class="line"><span class="comment">modify it under the terms of the GNU General Public License</span></div>
<div class="line"><span class="comment">as published by the Free Software Foundation; either version 2</span></div>
<div class="line"><span class="comment">of the License, or (at your option) any later version.</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">This program is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment">but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><span class="comment">GNU General Public License for more details.</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment">along with this program; if not, write to the Free Software</span></div>
<div class="line"><span class="comment">Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#ifdef IN_LINPHONE</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &quot;linphonecore.h&quot;</span></div>
<div class="line"><span class="preprocessor">#else</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &quot;linphone/linphonecore.h&quot;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#include &lt;signal.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> bool_t running=TRUE;</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> stop(<span class="keywordtype">int</span> signum){</div>
<div class="line">        running=FALSE;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> notify_presence_recv_updated (<a class="code" href="group__initializing.html#gaa5cf635b82dd338e7ee2dd3599d05f0a">LinphoneCore</a> *lc,  <a class="code" href="group__buddy__list.html#ga2f0508bab6d8ded431ce8b1a679a1522">LinphoneFriend</a> *<span class="keyword">friend</span>) {</div>
<div class="line">        <span class="keyword">const</span> <a class="code" href="group__linphone__address.html#gaa017e66840f5ee578168bd469b6c3e91">LinphoneAddress</a>* friend_address = <a class="code" href="group__buddy__list.html#ga1bbbe1f2b3760587681b8392d87efffa">linphone_friend_get_address</a>(<span class="keyword">friend</span>);</div>
<div class="line">        printf(<span class="stringliteral">&quot;New state state [%s] for user id [%s] \n&quot;</span></div>
<div class="line">                                ,<a class="code" href="group__buddy__list.html#gac691ff2fc71a0b9e91049dd1d0ad59f0">linphone_online_status_to_string</a>(<a class="code" href="group__buddy__list.html#ga77f0463c9fb52d98fd74a90a3c55028a">linphone_friend_get_status</a>(<span class="keyword">friend</span>))</div>
<div class="line">                                ,<a class="code" href="group__linphone__address.html#ga24c1a16f49f8b72f2bab65cc5d8a51af">linphone_address_as_string</a> (friend_address));</div>
<div class="line">}</div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> new_subscription_request (<a class="code" href="group__initializing.html#gaa5cf635b82dd338e7ee2dd3599d05f0a">LinphoneCore</a> *lc,  <a class="code" href="group__buddy__list.html#ga2f0508bab6d8ded431ce8b1a679a1522">LinphoneFriend</a> *<span class="keyword">friend</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* url) {</div>
<div class="line">        <span class="keyword">const</span> <a class="code" href="group__linphone__address.html#gaa017e66840f5ee578168bd469b6c3e91">LinphoneAddress</a>* friend_address = <a class="code" href="group__buddy__list.html#ga1bbbe1f2b3760587681b8392d87efffa">linphone_friend_get_address</a>(<span class="keyword">friend</span>);</div>
<div class="line">        printf(<span class="stringliteral">&quot; [%s] wants to see your status, accepting\n&quot;</span></div>
<div class="line">                                ,<a class="code" href="group__linphone__address.html#ga24c1a16f49f8b72f2bab65cc5d8a51af">linphone_address_as_string</a> (friend_address));</div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga254b01923c79947a5d23981d47639f40">linphone_friend_edit</a>(<span class="keyword">friend</span>); <span class="comment">/* start editing friend */</span></div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga9ab0c9222edcc0a8e25fb068aee88bc0">linphone_friend_set_inc_subscribe_policy</a>(<span class="keyword">friend</span>,<a class="code" href="group__buddy__list.html#gga542840b0e4c60ba1c700dcc75c8b3156a876507f111b9ea7c5fb4eac01bac22dd">LinphoneSPAccept</a>); <span class="comment">/* Accept incoming subscription request for this friend*/</span></div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga6e28513bba28f948ee61341384a36958">linphone_friend_done</a>(<span class="keyword">friend</span>); <span class="comment">/*commit change*/</span></div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga3a8e9184320402082bf35226ae8d25b8">linphone_core_add_friend</a>(lc,<span class="keyword">friend</span>); <span class="comment">/* add this new friend to the buddy list*/</span></div>
<div class="line"></div>
<div class="line">}</div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> registration_state_changed(<span class="keyword">struct</span> _LinphoneCore *lc, <a class="code" href="group__proxies.html#ga1879a0d59e068457b688138da97f2d0b">LinphoneProxyConfig</a> *cfg, <a class="code" href="group__proxies.html#ga698cb4228fac724b9e7c3cc5f499f7a8">LinphoneRegistrationState</a> cstate, <span class="keyword">const</span> <span class="keywordtype">char</span> *message){</div>
<div class="line">                printf(<span class="stringliteral">&quot;New registration state %s for user id [%s] at proxy [%s]\n&quot;</span></div>
<div class="line">                                ,<a class="code" href="group__proxies.html#gae79c79371d71750ee987757d59785ed7">linphone_registration_state_to_string</a>(cstate)</div>
<div class="line">                                ,<a class="code" href="group__proxies.html#gafebbeb5de42c1cfac8f134714111f10e">linphone_proxy_config_get_identity</a>(cfg)</div>
<div class="line">                                ,<a class="code" href="group__proxies.html#ga5e1459a6d25b45345525b4eca12d9252">linphone_proxy_config_get_addr</a>(cfg));</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><a class="code" href="group__initializing.html#gaa5cf635b82dd338e7ee2dd3599d05f0a">LinphoneCore</a> *lc;</div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]){</div>
<div class="line">        <a class="code" href="struct__LinphoneVTable.html">LinphoneCoreVTable</a> vtable={0};</div>
<div class="line"></div>
<div class="line">        <span class="keywordtype">char</span>* dest_friend=NULL;</div>
<div class="line">        <span class="keywordtype">char</span>* identity=NULL;</div>
<div class="line">        <span class="keywordtype">char</span>* password=NULL;</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* takes   sip uri  identity from the command line arguments */</span></div>
<div class="line">        <span class="keywordflow">if</span> (argc&gt;1){</div>
<div class="line">                dest_friend=argv[1];</div>
<div class="line">        }</div>
<div class="line">        <span class="comment">/* takes   sip uri  identity from the command line arguments */</span></div>
<div class="line">        <span class="keywordflow">if</span> (argc&gt;2){</div>
<div class="line">                identity=argv[2];</div>
<div class="line">        }</div>
<div class="line">        <span class="comment">/* takes   password from the command line arguments */</span></div>
<div class="line">        <span class="keywordflow">if</span> (argc&gt;3){</div>
<div class="line">                password=argv[3];</div>
<div class="line">        }</div>
<div class="line">        signal(SIGINT,stop);</div>
<div class="line"><span class="comment">//#define DEBUG</span></div>
<div class="line"><span class="preprocessor">#ifdef DEBUG</span></div>
<div class="line"><span class="preprocessor"></span>        <a class="code" href="group__misc.html#gad70dc5268366c829238b458547fe5277">linphone_core_enable_logs</a>(NULL); <span class="comment">/*enable liblinphone logs.*/</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span>        <span class="comment">/* </span></div>
<div class="line"><span class="comment">         Fill the LinphoneCoreVTable with application callbacks.</span></div>
<div class="line"><span class="comment">         All are optional. Here we only use the both notify_presence_recv and new_subscription_request callbacks</span></div>
<div class="line"><span class="comment">         in order to get notifications about friend status.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">        vtable.<a class="code" href="struct__LinphoneVTable.html#afedfc364c5b5193f10473cd47524400f">notify_presence_recv</a>=notify_presence_recv_updated;</div>
<div class="line">        vtable.<a class="code" href="struct__LinphoneVTable.html#ae66dffa2d5e6b3be881552cab3024ec2">new_subscription_request</a>=new_subscription_request;</div>
<div class="line">        vtable.<a class="code" href="struct__LinphoneVTable.html#a0f6a6182f6b98b2eef7e0dc9507f7647">registration_state_changed</a>=registration_state_changed; <span class="comment">/*just in case sip proxy is used*/</span></div>
<div class="line"></div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         Instantiate a LinphoneCore object given the LinphoneCoreVTable</span></div>
<div class="line"><span class="comment">        */</span></div>
<div class="line">        lc=<a class="code" href="group__initializing.html#gac93ed982ae84a5a282a703c8433ca42f">linphone_core_new</a>(&amp;vtable,NULL,NULL,NULL);</div>
<div class="line">        <span class="comment">/*sip proxy might be requested*/</span></div>
<div class="line">        <span class="keywordflow">if</span> (identity != NULL)  {</div>
<div class="line">                <span class="comment">/*create proxy config*/</span></div>
<div class="line">                <a class="code" href="group__proxies.html#ga1879a0d59e068457b688138da97f2d0b">LinphoneProxyConfig</a>* proxy_cfg = <a class="code" href="group__proxies.html#gaaedcf1a592cedba55ad05167abd2d7ce">linphone_proxy_config_new</a>();</div>
<div class="line">                <span class="comment">/*parse identity*/</span></div>
<div class="line">                <a class="code" href="group__linphone__address.html#gaa017e66840f5ee578168bd469b6c3e91">LinphoneAddress</a> *from = <a class="code" href="group__linphone__address.html#ga301c9884c0bc8b1050fe790d424e0b49">linphone_address_new</a>(identity);</div>
<div class="line">                <span class="keywordflow">if</span> (from==NULL){</div>
<div class="line">                        printf(<span class="stringliteral">&quot;%s not a valid sip uri, must be like sip:toto@sip.linphone.org \n&quot;</span>,identity);</div>
<div class="line">                        <span class="keywordflow">goto</span> end;</div>
<div class="line">                }</div>
<div class="line">                <a class="code" href="group__authentication.html#ga0f8289c1aab407992864a68869107f4f">LinphoneAuthInfo</a> *info;</div>
<div class="line">                <span class="keywordflow">if</span> (password!=NULL){</div>
<div class="line">                        info=<a class="code" href="group__authentication.html#gada5caa494ea0c9320b42be28a69bea1b">linphone_auth_info_new</a>(<a class="code" href="group__linphone__address.html#ga4fa5a4927c1d2f3a6b7c6824e35a87bf">linphone_address_get_username</a>(from),NULL,password,NULL,NULL); <span class="comment">/*create authentication structure from identity*/</span></div>
<div class="line">                        <a class="code" href="group__authentication.html#ga62ac5bb34f0342f7edc733c42473b7aa">linphone_core_add_auth_info</a>(lc,info); <span class="comment">/*add authentication info to LinphoneCore*/</span></div>
<div class="line">                }</div>
<div class="line"></div>
<div class="line">                <span class="comment">// configure proxy entries</span></div>
<div class="line">                <a class="code" href="group__proxies.html#gaf18076ceb04bc4e779c6e1096e2ef412">linphone_proxy_config_set_identity</a>(proxy_cfg,identity); <span class="comment">/*set identity with user name and domain*/</span></div>
<div class="line">                <a class="code" href="group__proxies.html#ga147377ddae32abf4d3b3777cf0120aed">linphone_proxy_config_set_server_addr</a>(proxy_cfg,<a class="code" href="group__linphone__address.html#ga95a356f26c67ed4ee88db878b617c65f">linphone_address_get_domain</a>(from)); <span class="comment">/* we assume domain = proxy server address*/</span></div>
<div class="line">                <a class="code" href="group__proxies.html#gadca1a0fe47bceff0e58d7057672519b6">linphone_proxy_config_enable_register</a>(proxy_cfg,TRUE); <span class="comment">/*activate registration for this proxy config*/</span></div>
<div class="line">                <a class="code" href="group__proxies.html#ga111a1c43aa8aac3b2b95274b5a02be64">linphone_proxy_config_enable_publish</a>(proxy_cfg,TRUE); <span class="comment">/* enable presence satus publication for this proxy*/</span></div>
<div class="line">                <a class="code" href="group__linphone__address.html#ga5777f2976c71a48cf2b3f03c61818f13">linphone_address_destroy</a>(from); <span class="comment">/*release resource*/</span></div>
<div class="line"></div>
<div class="line">                <a class="code" href="group__proxies.html#gaccdcbca377b771625aeea9c251b597c7">linphone_core_add_proxy_config</a>(lc,proxy_cfg); <span class="comment">/*add proxy config to linphone core*/</span></div>
<div class="line">                <a class="code" href="group__proxies.html#ga466cfc7b5f7a63e1efb77732ac3b6de2">linphone_core_set_default_proxy</a>(lc,proxy_cfg); <span class="comment">/*set to default proxy*/</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line">                <span class="comment">/* Loop until registration status is available */</span></div>
<div class="line">                <span class="keywordflow">do</span> {</div>
<div class="line">                        <a class="code" href="group__initializing.html#ga7bdac8ac386483fc4e0876e4c5d13755">linphone_core_iterate</a>(lc); <span class="comment">/* first iterate initiates registration */</span></div>
<div class="line">                        ms_usleep(100000);</div>
<div class="line">                }</div>
<div class="line">                <span class="keywordflow">while</span>(  running &amp;&amp; linphone_proxy_config_get_state(proxy_cfg) == <a class="code" href="group__proxies.html#ggaea1b64a739b1faf0b490fe0f52cfe65eae20dab1677f285ef32006cc86f8ea630">LinphoneRegistrationProgress</a>);</div>
<div class="line"></div>
<div class="line">        }</div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga2f0508bab6d8ded431ce8b1a679a1522">LinphoneFriend</a>* my_friend=NULL;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">if</span> (dest_friend) {</div>
<div class="line">                my_friend = <a class="code" href="group__buddy__list.html#gac4076f5a4af3fc923b8d818f9480131b">linphone_friend_new_with_addr</a>(dest_friend); <span class="comment">/*creates friend object from dest*/</span></div>
<div class="line">                <span class="keywordflow">if</span> (my_friend == NULL) {</div>
<div class="line">                        printf(<span class="stringliteral">&quot;bad destination uri for friend [%s]\n&quot;</span>,dest_friend);</div>
<div class="line">                        <span class="keywordflow">goto</span> end;</div>
<div class="line">                }</div>
<div class="line"></div>
<div class="line">                <a class="code" href="group__buddy__list.html#ga832ec207f77f722ddc596303e7a68a47">linphone_friend_enable_subscribes</a>(my_friend,TRUE); <span class="comment">/*configure this friend to emit SUBSCRIBE message after being added to LinphoneCore*/</span></div>
<div class="line">                <a class="code" href="group__buddy__list.html#ga9ab0c9222edcc0a8e25fb068aee88bc0">linphone_friend_set_inc_subscribe_policy</a>(my_friend,<a class="code" href="group__buddy__list.html#gga542840b0e4c60ba1c700dcc75c8b3156a876507f111b9ea7c5fb4eac01bac22dd">LinphoneSPAccept</a>); <span class="comment">/* Accept incoming subscription request for this friend*/</span></div>
<div class="line">                <a class="code" href="group__buddy__list.html#ga3a8e9184320402082bf35226ae8d25b8">linphone_core_add_friend</a>(lc,my_friend); <span class="comment">/* add my friend to the buddy list, initiate SUBSCRIBE message*/</span></div>
<div class="line"></div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <a class="code" href="group__buddy__list.html#gadae69527e9b36e0f29bd80c30275874f">linphone_core_set_presence_info</a>(lc,0,NULL,<a class="code" href="group__buddy__list.html#gga1fe5b01157185e761475b82058697a34ae254d925323f861f5752aa55abab5ecf">LinphoneStatusOnline</a>); <span class="comment">/*set my status to online*/</span></div>
<div class="line"></div>
<div class="line">        <span class="comment">/* main loop for receiving notifications and doing background linphone core work: */</span></div>
<div class="line">        <span class="keywordflow">while</span>(running){</div>
<div class="line">                <a class="code" href="group__initializing.html#ga7bdac8ac386483fc4e0876e4c5d13755">linphone_core_iterate</a>(lc); <span class="comment">/* first iterate initiates subscription */</span></div>
<div class="line">                ms_usleep(50000);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <a class="code" href="group__buddy__list.html#gadae69527e9b36e0f29bd80c30275874f">linphone_core_set_presence_info</a>(lc,0,NULL,<a class="code" href="group__buddy__list.html#gga1fe5b01157185e761475b82058697a34af5aff8e160716b480e4f9f54a1892bb8">LinphoneStatusOffline</a>); <span class="comment">/* change my presence status to offline*/</span></div>
<div class="line">        <a class="code" href="group__initializing.html#ga7bdac8ac386483fc4e0876e4c5d13755">linphone_core_iterate</a>(lc); <span class="comment">/* just to make sure new status is initiate message is issued */</span></div>
<div class="line"></div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga254b01923c79947a5d23981d47639f40">linphone_friend_edit</a>(my_friend); <span class="comment">/* start editing friend */</span></div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga832ec207f77f722ddc596303e7a68a47">linphone_friend_enable_subscribes</a>(my_friend,FALSE); <span class="comment">/*disable subscription for this friend*/</span></div>
<div class="line">        <a class="code" href="group__buddy__list.html#ga6e28513bba28f948ee61341384a36958">linphone_friend_done</a>(my_friend); <span class="comment">/*commit changes triggering an UNSUBSCRIBE message*/</span></div>
<div class="line"></div>
<div class="line">        <a class="code" href="group__initializing.html#ga7bdac8ac386483fc4e0876e4c5d13755">linphone_core_iterate</a>(lc); <span class="comment">/* just to make sure unsubscribe message is issued */</span></div>
<div class="line"></div>
<div class="line">end:</div>
<div class="line">        printf(<span class="stringliteral">&quot;Shutting down...\n&quot;</span>);</div>
<div class="line">        <a class="code" href="group__initializing.html#ga5e3f2f87c8d8262caa1fa90bbd504008">linphone_core_destroy</a>(lc);</div>
<div class="line">        printf(<span class="stringliteral">&quot;Exited\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"></div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>