An example of an exosip-based phone call

Source: Internet
Author: User

An example of an exosip-based phone call

 

From: http://www.coolboysky.com/oblog/more.asp stickers? Name = Tucket & id = 72
Http://blog.csdn.net/wffy
Because there are both.

Exosip extends Osip to UA. Osip does not provide any method to quickly generate request messages and respond to messages, all request messages and response messages must be manually assembled by calling a set of SIP Message APIs. Therefore, the author developed exosip on the basis of Osip, which is very convenient to use exosip to develop soft phones, only a few APIs are required. exosip comes with an example: Josua, but Josua is relatively complicated. The following is a simple example for your reference. Because the example is too simple to be annotated, for the parameters of the API that uses exosip, see the exosip source code. It is very easy to understand this example and study Josua. I am using Osip 2.0.9 + exosip 0.77.

# Include "assert. H"
# Include <conio. h>
# Include <iostream>
# Include <osip2/osip_mt.h>
# Include <exosip/exosip. h>
# Include <exosip/exosip_cfg.h>

Using namespace STD;

Class jcall;

Class jcall {
Public:
Int CID;
Int did;
 
Char reason_phrase [50];
Int status_code;
 
Char textinfo [256];
Char req_uri [256];
Char local_uri [256];
Char remote_uri [256];
Char subject [256];
 
Char remote_sdp_audio_ip [50];
Int remote_sdp_audio_port;
Int payload;
Char payload_name [50];
 
Int state;
 
Jcall (){}
 
Int build (exosip_event_t * Je)
{
Jcall * CA = this;

Ca-> cid = Je-> CID;
Ca-> did = Je-> did;

If (ca-> did <1 & Ca-> CID <1)
{
Assert (0 );
Return-1;/* not enough information for this event ?? */
}

Osip_strncpy (ca-> textinfo, je-> textinfo, 255 );
Osip_strncpy (ca-> req_uri, je-> req_uri, 255 );
Osip_strncpy (ca-> local_uri, je-> local_uri, 255 );
Osip_strncpy (ca-> remote_uri, je-> remote_uri, 255 );
Osip_strncpy (Ca> subject, je-> subject, 255 );

If (ca-> remote_sdp_audio_ip [0] = '/0 ')
{
Osip_strncpy (ca-> remote_sdp_audio_ip, je-> remote_sdp_audio_ip, 49 );
Ca-> remote_sdp_audio_port = Je-> remote_sdp_audio_port;
Ca-> payload = Je-> payload;
Osip_strncpy (ca-> payload_name, je-> payload_name, 49 );

}

If (Je-> reason_phrase [0]! = '/0 ')
{
Osip_strncpy (ca-> reason_phrase, je-> reason_phrase, 49 );
Ca-> status_code = Je-> status_code;
}

Ca-> state = Je-> type;
Return 0;
}
 
};

Jcall call;

Void _ exit (int r)
{
Char line [256];
Gets (line );
Exit (R );
}

Void josua_printf (char * BUF)
{
Printf ("/N ");
}

Int josua_event_get ()
{
Int counter = 0;
/* Use events to print some info */
Exosip_event_t * Je;
For (;;)
{
Char Buf [100];
Je = exosip_event_wait (0, 50 );
If (JE = NULL)
Break;
Counter ++;
If (Je-> type = exosip_call_new)
{
Printf ("<-(% I) invite from: % s ",
Je-> CID, je-> did,
Je-> remote_uri );
Josua_printf (BUF );

Call. Build (JE );
}
Else if (Je-> type = exosip_call_answered)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_proceeding)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_ringing)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_redirected)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_requestfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_serverfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_globalfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_closed)
{
Printf ("<-(% I) Bye from: % s ",
Je-> CID, je-> did, je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_hold)
{
Printf ("<-(% I) Invite (on hold) from: % s ",
Je-> CID, je-> did, je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_call_offhold)
{
Printf ("<-(% I) Invite (off hold) from: % s ",
Je-> CID, je-> did, je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_registration_success)
{
Printf ("<-(% I) [% I % s] % s for register % s ",
Je-> RID,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri,
Je-> req_uri );
Josua_printf (BUF );

}
Else if (Je-> type = exosip_registration_failure)
{
Printf ("<-(% I) [% I % s] % s for register % s ",
Je-> RID,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri,
Je-> req_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_options_new)
{
Printf ("<-(% I) options from: % s ",
Je-> CID, je-> did,
Je-> remote_uri );
Josua_printf (BUF );

}
Else if (Je-> type = exosip_options_answered)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_options_proceeding)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );

}
Else if (Je-> type = exosip_options_redirected)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_options_requestfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_options_serverfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_options_globalfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_new)
{
Printf ("<-(% I) info from: % s ",
Je-> CID, je-> did,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_answered)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_proceeding)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_redirected)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_requestfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_serverfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_info_globalfailure)
{
Printf ("<-(% I) [% I % s] % s ",
Je-> CID, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}

Else if (Je-> type = exosip_subscription_answered)
{
Printf ("<-(% I) [% I % s] % s for subscribe ",
Je-> Sid, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );

Printf ("<-(% I) Online = % I [Status: % I reason: % I]",
Je-> Sid, je-> did,
Je-> online_status,
Je-> ss_status,
Je-> ss_reason );
Josua_printf (BUF );

}
Else if (Je-> type = exosip_subscription_proceeding)
{
Printf ("<-(% I) [% I % s] % s for subscribe ",
Je-> Sid, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );

}
Else if (Je-> type = exosip_subscription_redirected)
{
Printf ("<-(% I) [% I % s] % s for subscribe ",
Je-> Sid, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_subscription_requestfailure)
{
Printf ("<-(% I) [% I % s] % s for subscribe ",
Je-> Sid, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_subscription_serverfailure)
{
Printf ("<-(% I) [% I % s] % s for subscribe ",
Je-> Sid, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_subscription_globalfailure)
{
Printf ("<-(% I) [% I % s] % s for subscribe ",
Je-> Sid, je-> did,
Je-> status_code,
Je-> reason_phrase,
Je-> remote_uri );
Josua_printf (BUF );
}
Else if (Je-> type = exosip_subscription_policy)
{
Printf ("<-(% I) using Y from: % s ",
Je-> Sid, je-> did,
Je-> remote_uri );
Josua_printf (BUF );

Printf ("<-(% I) Online = % I [Status: % I reason: % I]",
Je-> Sid, je-> did,
Je-> online_status,
Je-> ss_status,
Je-> ss_reason );
Josua_printf (BUF );

}
Else if (Je-> type = exosip_in_subscription_new)
{
Printf ("<-(% I) subscribe from: % s ",
Je-> NID, je-> did,
Je-> remote_uri );
Josua_printf (BUF );

/* Search for the user to see if he has been
Previusly accepted or not! */

Exosip_policy (Je-> did, exosip_subcrstate_pending, exosip_policy_away );
}
Else if (Je-> textinfo [0]! = '/0 ')
{
Printf ("(% I) % s", je-> CID, je-> Sid, je-> NID, je-> did, je-> textinfo );
Josua_printf (BUF );
}


Exosip_event_free (JE );
}
If (counter> 0)
Return 0;
Return-1;
}

Int main (INT argc, char * argv [])
{
Int I;
Memset (& call, 0, sizeof (CALL ));
 
Cout <"Usage:" <Endl;
Cout <"a-answering call" <Endl;
Cout <"H-hangup" <Endl;
Cout <"R-ringing" <Endl;
Cout <"c-call" <Endl;
Cout <"Q-Quit" <Endl;
 
File * logfile = fopen ("logfile.txt", "W ");
// Osip_trace_initialize (_ trace_level) 0, logfile );
// Osip_trace_initialize (_ trace_level) 8, stdout );
I = exosip_init (stdin, stdout, 5060 );
If (I! = 0)
{
Fprintf (stderr, "test: cocould not initialize exosip/N ");
_ Exit (0 );

}
 
 
Exosip_sdp_negotiation_remove_audio_payloads ();
Exosip_sdp_negotiation_add_codec (osip_strdup ("0 "),
Null,
Osip_strdup ("RTP/AVP "),
Null, null, null,
Null, null,
Osip_strdup ("0 PCMU/8000 "));
 
Exosip_sdp_negotiation_add_codec (osip_strdup ("8 "),
Null,
Osip_strdup ("RTP/AVP "),
Null, null, null,
Null, null,
Osip_strdup ("8 PCMA/8000 "));

/* Register callbacks? */
Exosip_set_mode (event_mode );
 
Osip_message_t * invite;
I = exosip_build_initial_invite (& invite,
"SIP: 192.168.197.5: 5060", // called to IP Address
"SIP: 192.168.197.254: 5060", // ip address of the user
Null,
"Osip phone ");
If (I! = 0)
{
Fprintf (stderr, "exosip_build_initial_invite failed/N ");
_ Exit (0 );
}
 
 
Cout <"Osip> ";
Bool run = true;
While (run)
{
Josua_event_get ();

If (_ kbhit ())
{
Switch (_ getch ())
{
Case 'A ':
Cout <"Answer" <Endl;
Exosip_lock ();
Exosip_answer_call (call. Did, 200, 0 );
Exosip_unlock ();
Break;

Case 'H ':
Cout <"hangup" <Endl;
Exosip_lock ();
Exosip_terminate_call (call. CID, call. Did );
Exosip_unlock ();
Break;

Case 'r ':
Cout <"Ringing" <Endl;
Exosip_lock ();
Exosip_answer_call (call. Did, 180, 0 );
Exosip_unlock ();
Break;

Case 'C ':
Cout <"call" <Endl;
Exosip_lock ();
Exosip_initiate_call (invite, null, null, "10500 ");
Exosip_unlock ();
Break;

Case 'q ':
Cout <"quit" <Endl;
Run = false;
Break;

Default:
Cout <"/nosip> ";
}
}
}
 
 
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.