Sophie

Sophie

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

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 registration</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 registration</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. *Desmonstrating how to initiate a SIP registration from a sip uri identity passed from the command line. *first 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> , second must be password . <br/>
 *ex registration 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> secret <br/>
Registration 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">linphone</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> 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>* 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">                identity=argv[1];</div>
<div class="line">        }</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;2){</div>
<div class="line">                password=argv[2];</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        signal(SIGINT,stop);</div>
<div class="line"></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 registration_state_changed callbacks</span></div>
<div class="line"><span class="comment">         in order to get notifications about the progress of the registration.</span></div>
<div class="line"><span class="comment">         */</span></div>
<div class="line">        vtable.<a class="code" href="struct__LinphoneVTable.html#a0f6a6182f6b98b2eef7e0dc9507f7647">registration_state_changed</a>=registration_state_changed;</div>
<div class="line"></div>
<div class="line">        <span class="comment">/*</span></div>
<div class="line"><span class="comment">         Instanciate 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"></div>
<div class="line">        <a class="code" href="group__proxies.html#ga1879a0d59e068457b688138da97f2d0b">LinphoneProxyConfig</a>* proxy_cfg;</div>
<div class="line">        <span class="comment">/*create proxy config*/</span></div>
<div class="line">        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">                <span class="keyword">const</span> <span class="keywordtype">char</span>* server_addr = <a class="code" href="group__linphone__address.html#ga95a356f26c67ed4ee88db878b617c65f">linphone_address_get_domain</a>(from); <span class="comment">/*extract domain address from identity*/</span></div>
<div class="line">                <a class="code" href="group__proxies.html#ga147377ddae32abf4d3b3777cf0120aed">linphone_proxy_config_set_server_addr</a>(proxy_cfg,server_addr); <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__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">/* main loop for receiving notifications and doing background linphonecore 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 registration */</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__proxies.html#gac77d836d546848289f16716cb2db12f6">linphone_core_get_default_proxy</a>(lc,&amp;proxy_cfg); <span class="comment">/* get default proxy config*/</span></div>
<div class="line">        <a class="code" href="group__proxies.html#ga37cac414aba9e8e4135c1f208c0175f8">linphone_proxy_config_edit</a>(proxy_cfg); <span class="comment">/*start editing proxy configuration*/</span></div>
<div class="line">        <a class="code" href="group__proxies.html#gadca1a0fe47bceff0e58d7057672519b6">linphone_proxy_config_enable_register</a>(proxy_cfg,FALSE); <span class="comment">/*de-activate registration for this proxy config*/</span></div>
<div class="line">        <a class="code" href="group__proxies.html#ga9b59d963af64ee243dfa4643a85c0cdc">linphone_proxy_config_done</a>(proxy_cfg); <span class="comment">/*initiate REGISTER with expire = 0*/</span></div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">while</span>(linphone_proxy_config_get_state(proxy_cfg) !=  <a class="code" href="group__proxies.html#ggaea1b64a739b1faf0b490fe0f52cfe65eaf08a66584f81f4bbc9bfd1e3166c348d">LinphoneRegistrationCleared</a>){</div>
<div class="line">                <a class="code" href="group__initializing.html#ga7bdac8ac386483fc4e0876e4c5d13755">linphone_core_iterate</a>(lc); <span class="comment">/*to make sure we receive call backs before shutting down*/</span></div>
<div class="line">                ms_usleep(50000);</div>
<div class="line">        }</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>