
exosip开发手册.pdf
49页exexoSoSipip 开发者手册开发者手册 exoSip 开发者手册 ——本手册指导开发者利用exoSip 栈开发用户代理 原文标题:exoSIP User Manual 原文作者: 联系方法: 版权保护:GNU Free Documentation License 项目网站: 制作作者:周芒芝 联系方法:xing_1314@ 1 The eXtented eXosip stack.4 1.1How- To initialize libeXosip24 1.2How- To initiate, modify or terminate calls.5 1.2.1Initiate a call6 1.2.2Answer a call.7 1.2.3Sending other request8 1.3How- To send or update registrations. .9 1.3.1Initiate a registration .9 1.3.2Update a registration.9 1.3.3Closing the registration.10 2General purposeAPI.11 2.1eXosip2 configurationAPI11 2.1.1 Functions11 2.1.2Function Documentation.11 2.2eXosip2 networkAPI14 2.2.2Functions.14 2.2.3Function Documentation.14 2.3 eXosip2 eventAPI 16 2.3.1 Data Structures.16 2.3.2 Enumerations .16 2.3.3 Functions17 2.3.4 Enumeration Type Documentation.17 2.3.5 Function Documentation19 3SIP messages and call controlAPI21 3.1eXosip2 INVITE and Call Management.21 3.1.1Functions.21 3.1.2Function Documentation.22 3.2eXosip2 request outside of dialog.29 3.2.1Functions.29 3.2.2Function Documentation.29 3.3eXosip2 OPTIONS and UAcapabilities Management .31 3.3.1Functions.31 3.3.2Function Documentation.31 3.4eXosip2 Publication Management 33 3.4.1Functions.33 3.4.2Function Documentation.33 3.5eXosip2 REFER and blind tranfer Management outside of calls35 3.5.1Functions.35 3.5.2Function Documentation.35 3.6eXosip2 REGISTER and Registration Management 37 3.6.1Functions.37 3.6.2Function Documentation.37 3.7eXosip2 SUBSCRIBE and outgoing subscriptions.39 3.7.1Enumerations.39 3.7.2Functions.39 3.7.3Enumeration Type Documentation40 3.7.4Function Documentation.41 3.8eXosip2 SUBSCRIBE and incoming subscriptions43 3.8.1Functions.43 3.8.2Function Documentation.43 3.9eXosip2 authenticationAPI.46 3.9.1Functions.46 3.9.2Function Documentation.46 3.10Xosip2 SDP helperAPI.48 3.10.1Functions.48 3.10.2Function Documentation.48 1 The eXtented eXosip stack 1.1 How- To initialize libeXosip2. When using eXosip, your first task is to initialize both eXosip context and libosip library (parser and state machines). This must be done prior to any use of libeXosip2. include int i; TRACE_INITIALIZE (6, stdout); i=eXosip_init(); if (i!=0) return -1; i = eXosip_listen_addr (IPPROTO_UDP, NULL, port, AF_INET, 0); if (i!=0) { eXosip_quit()eXosip_quit(); fprintf (stderr, “could not initialize transport layer\n“); return -1; } . then you have to send messages and wait for eXosip events. In the previous code, you've learned how to: Initialize the osip trace (compile this code with - DENABLE_TRACE) Initialize eXosip (and osip) stack Open a socket for signalling (only UDP with initial eXosip2 version) Now you have to handle eXosip events. Here is some code to get eXosip_event from the eXosip2 stack. eXosip_event_t *je; for (;;) { je = eXosip_event_wait (0, 50); eXosip_lock()eXosip_lock(); eXosip_automatic_action (); eXosip_unlock()eXosip_unlock(); if (je == NULL) break; if (je-type == EXOSIP_CALL_NEW) { } else if (je-type == EXOSIP_CALL_ACK) { } else if (je-type == EXOSIP_CALL_ANSWERED) { } else . eXosip_event_free(je); } You will receive one event for each SIP message sent. Each event contains the original request of the affected transaction and the last response that triggers the event when available. You can access all headers from those messages and store them in your own context for other actions or graphic displays. For example, when you receive a REFER request for a call transfer, you'll typically retreive the “refer- To“ header: osip_header_t *referto_head = NULL; i = osip_message_header_get_byname (evt-sip, “refer-to“, 0, if (referto_head == NULL || referto_head-hvalue == NULL) The eXosip_event also contains identifiers for calls, registrations, incoming subscriptions or outgoing subscriptions when applicable. Those identifiers are used in API to control calls, registrations, incoming or outgoing subscriptions. These API will build default messages with usual SIP headers (From, To, Call- ID, CSeq, Route, Record- Route, Max- Forward.) and send thoses messages for you. 1.2 How- To initiate, modify or terminate calls. eXosip2 offers a flexible API to help you controling calls. 1.2.1 Initiate a call To start an outgoing call, you typically need a few headers which will be used by eXosip2 to build a default SIP INVITE request. The code below is used to start a call: osip_message_t *invite; int i; i = eXosip_call_build_initial_invite ( if (i != 0) { return -1; } osip_message_set_supported (invite, “100rel“); { char tmp[4096]; char localip[128]; eXosip_guess_localip (AF_INET, localip, 128); snprintf (tmp, 4096, “v=0\r\n“ “o=josua 0 0 IN IP4 %s\r\n“ “s=conversation\r\n“ “c=IN IP4 %s\r\n“ “t=0 0\r\n“ “m=audio %s RTP/AVP 0 8 101\r\n“ “a=rtpmap:0 PCMU/8000\r\n“ “a=rtpmap:8 PCMA/8000\r\n“ “a=rtpmap:101 telephone-event/8000\r\n“ “a=fmtp:101 0-11\r\n“, localip, localip, port); osip_message_set_body (invite, tmp, strlen (tmp)); osip_message_set_content_type (invite, “a。
