⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nua.docs

📁 Internet Phone, Chat, Conferencing
💻 DOCS
📖 第 1 页 / 共 5 页
字号:
/* -*- text -*- *//**@mainpage Sofia User Agent Library - nua@section nua_meta Module Meta InformationThe @b nua module contains the user-agent library taking care of basicSIP User Agent functions. Its functionality includes call management,messaging and event retrieval.@CONTACT Pekka Pessi <Pekka.Pessi@nokia.com>@STATUS Core library@LICENSE LGPL@par Contributor(s):- Pekka Pessi <Pekka.Pessi@nokia.com>- Pasi Rinne-Rahkola <Pasi.Rinne-Rahkola@nokia.com>- Kai Vehmanen <Kai.Vehmanen@nokia.com>- Martti Mela <Martti.Mela@nokia.com>@section nua_overview OverviewThe NUA API gives the high-level application programmer transparent andfull control to the SIP protocol engine燽elow it. NUA provides the callsemantics on top of existing transaction semantics found in<a href="../nta/index.html"><b>nta</b></a> module.API makes it possible to create different kind of User Agents,like terminals, gateways or MCUs.The @b nua engine hides many low-level signaling and media managementaspects from the application programmer. It is possible to use differentkind of media interfaces - even remote ones - in a fully transparent way.The application and the protocol engine within User Agent library can berun in separate threads. Communications from the protocol engine isconveyed through a callback function. The callback function is calledwithin context of the application, so the application must provideappropriate handle to a #su_root_t object.@section nua_concepts_user Sofia Concepts for NUA User@subsection nua_intro IntroductionThe Sofia software suite is based on certain basic ideas and concepts thatare used in all levels of Sofia software. Many of those are implemented inSofia utility library (<a href="../su/index.html"><b>su</b></a>) providingunified interface to the most important OS services and utilities .The following sections contain descriptions of the concepts that a user ofNUA library must understand to create a working application. The otherutilities (in the SU library and other libraries of Sofia software suite)might also be useful for an application developer but one must be carefulwhen using them because they might change the behavior of the Sofiasoftware suite in a way that causes NUA library to work incorrectly.See [<a href="../su/index.html"><b>su</b></a>] for more detaileddescription of the SU services.@subsection nua_root Event loop - root objectThe NUA uses the reactor pattern (also known as dispatcher pattern andnotifier pattern) for event driven systems (see [Using Design Patternsto Develop Reusable Object-oriented Communication Software, D.C. Schmidt,CACM October '95, 38(10): 65-74]). Sofia uses a task as basic executionunit for the programming model. According to the model, the program canask that the event loop invokes a callback function when a certain eventoccurs. Such events include I/O activity, timers or a asynchronouslydelivered messages from other task.The root object is a handle representing the task in the application.Another way of seeing the same thing is that the root object representsthe main event loop of the task. Through the root object the task codecan access its context information (magic) and thread-synchronizationfeatures like wait objects, timers, and messages.An application using NUA services must create a root object and thecallback routine to handle events. The root object is created withsu_root_create() function and the callback routine is registered withnua_create() function.Root object has type #su_root_t.See documentation of <su_wait.h> and <su_root.c> for more informationof root object.See section #nua_event_e for more information of the callback function.@subsection nua_magic MagicThe magic is a term used for the context pointer that can be boundto various objects in Sofia stack (for example root object and operationhandle) by the application code. This context pointer is passed backto the application code when a registered callback function is called bythe main event loop. The Sofia stack retains the context information betweencalls to the callback function. An application can use the context informationto store any information it needs for processing the events.@subsection nua_memmgmt Memory HandlingThe home-based memory management is useful when a lot of memory blocks areallocated for given task. The allocations are done via the memory home,which keeps a reference to each allocated memory block. When the memoryhome is then freed, it will free all memory blocks to which it hasreference. This simplifies application logic because application code doesnot need to keep track of the allocated memory and free every allocated blockseparately.An application using NUA services can use the memory management servicesprovided by the SU library but it is not mandatory.See documentation of <su_alloc.h> for more information of memory managementservices.@subsection nua_tags TagsTagging is the mechanism used in Sofia software for packing parameters tofunctions. It enables passing a variable number of parameters havingnon-fixed types. For an application programmer the tagging is visible asmacros that are used to encapsulate the passed parameters. When evaluated atagging macro creates a structure that contains a tag (telling what is thetype of a parameter) and a value (pointer to opaque data). By checking thetag the layers of Sofia software check whether they can handle the parameteror should it just be passed to lower layers for processing.There are some tags with special meaning:- TAG_NULL() end of tag list- TAG_END()  end of tag list- TAG_SKIP()  empty tag item- TAG_NEXT() tag item pointing to another tag list- TAG_ANY() filter tag accepting any tag- TAG_IF() conditional inclusion of tag itemThe NUA functions can be called with a list of tagged values if they havefollowing parameters at the end of parameter list:@codetag_type_t   tag,tag_value_t  value,...);@endcodeThe last tagged value on the parameter list must be TAG_NULL()(synonym for TAG_END()).Every tag has two versions: \nNUTAG_<tagname> \nwhich takes a value parameter and \nNUTAG_<tagname>_REF \nwhich takes a reference parameter and is used withtl_gets() function to retrieve tag values from tag list.For some Sofia layers (for example SIP) there exists also additionalversion of tags: \nSIPTAG_<tagname>_STR \nThis tag version takes a C-language character string as parameter.The corresponding tag without _STR suffix takes a parsed value structureas parameter.The following is an example of call to NUA function containing tagged values:@codenua_unregister(op->op_handle,               TAG_IF(use_registrar, NUTAG_REGISTRAR(registrar)),               SIPTAG_CONTACT_STR("*"),               SIPTAG_EXPIRES_STR("0"),               TAG_NULL());@endcodeAn application using NUA services must use tagging for the functionparameter passing.See documentation of <su_tag.h> for more information of tags and themodule-specific documentation of each Sofia module for information oftags specific for that module.@subsection nua_debugandlogging Debugging and LoggingThe modules of Sofia stack contain configurable debugging and loggingfunctionality based on the services defined in <su_log.h>. The debuggingand logging details (for example level of details on output and outputfile name) can be configured by environment variables, directives inconfiguration files and compilation directives in the source files.Examples of useful directives/ environment variables are:- #SOFIA_DEBUG	Default debug level (0..9)- #NUA_DEBUG	NUA debug level (0..9)- #NTA_DEBUG	Transaction engine debug level (0..9)- #TPORT_DEBUG	Transport event debug level (0..9)- #TPORT_LOG	If set, print out all parsed SIP messages on transport layer- #TPORT_DUMP	Filename for dumping unparsed messages from transportThe defined debug output levels are:- 0 fatal errors, panic- 1 critical errors, minimal progress at subsystem level- 2 non-critical errors- 3 warnings, progress messages- 5 signaling protocol actions (incoming packets, ...)- 7 media protocol actions (incoming packets, ...)- 9 entering/exiting functions, very verbatim progressAn application using NUA services can also use the debugging andlogging services provided by the Sofia stack but it is not mandatory.See documentation of <su_log.h> for more information of debugging andlogging services.@section nua_concepts NUA Concepts@subsection nua_stackobject NUA Stack ObjectStack object represents an instance of SIP stack and media engine. Itcontains reference to root object of that stack, user-agent-specificsettings, and reference to the SIP transaction engine, for example.A NUA stack object is created by nua_create() function and deleted bynua_destroy() function. The nua_shutdown() function is used to gracefullyrelease active the sessions by @b nua engine.NUA stack object has type nua_t.@subsection nua_operationhandle NUA Operation HandleOperation handle represents an abstract SIP call/session. It containsinformation of SIP dialog and media session, and state machine thattakes care of the call, high-level SDP offer-answer protocol, registration,subscriptions, publications and simple SIP transactions. An operationhandle may contain list of tags used when SIP messages are created byNUA (e.g. From and To headers).An operation handle is created explicitly by the application using NUAfor sending messages (function nua_handle()) and by stack for incomingcalls/sessions (starting with INVITE or MESSAGE). The handle is destroyedby the application using NUA (function nua_handle_destroy()).Indication and response events are associated with an operation handle.NUA operation handle has type nua_handle_t.@subsection nua_stacktread Stack Thread and Message Passing ConceptsThe stack thread is a separate thread from application that provides thereal-time protocol stack operations so that application thread can forexample block or redraw UI as it likes.The communication between stack thread and application thread is asynchronous.Most of the NUA API functions cause a send of a message to the stack threadfor processing and similarly when something happens in the stack thread itsends a message to the application thread. The messages to the applicationthread are delivered as invokes of the application callback function whenthe application calls su_root_run() or su_root_step() function.@subsection nua_sipmessage SIP Message and Header ManipulationSIP messages are manipulated with typesafe SIPTAG_ tags. There arethree versions of each SIP tag:- SIPTAG_<tagname>() takes a parsed value as parameter.- SIPTAG_<tagname>_STR() takes an unparsed string as parameter.- SIPTAG_<tagname>_REF() takes a reference as parameter, is used        with tl_gets() function to retrieve tag values from tag list.- SIPTAG_<tagname>__STR_REF() takes a reference as parameter, is used        with tl_gets() function to retrieve string tag values from tag list.For example a header named "Example" would have tags names SIPTAG_EXAMPLE(),SIPTAG_EXAMPLE_STR(), and SIPTAG_EXAMPLE_REF().When tags are used in NUA calls the corresponding headers are added tothe message. In case the header can be present only once in a messageand there already exists a value for the header the value given bytag replaces the existing header value. Passing tag value NULL has noeffect on headers. Passing tag value (void *)-1 removes correspondingheaders from the message.For example:- sending a SUBSCRIBE with @b Event: header and two @b Accept: headers:@code	nua_subscribe(nh,                      SIPTAG_EVENT_STR("presence"),                      SIPTAG_ACCEPT(accept1),                      SIPTAG_ACCEPT(accept2),                      TAG_END());@endcode- fetching tag values when processing nua_r_subscribe event:@code           sip_accept_t *ac = NULL;           sip_event_t  *o  = NULL;           tl_gets(tl,                   SIPTAG_EVENT_REF(o),   /* _REF takes a reference! */                   SIPTAG_ACCEPT_REF(ac),                   TAG_END());@endcode@section nua_tutorial SIP/NUA tutorialThis section describes basic usage scenarios of NUA/Sofia stack usingmessage sequence charts.@subsection nua_outgoingcall Outgoing Call@image latex SIP_outgoing_call.eps@image html SIP_outgoing_call.gif@subsection nua_incomingcall Incoming Call@image latex SIP_incoming_call.eps@image html SIP_incoming_call.gif@subsection nua_basicoutgoingoperation Basic Outgoing Operation@image latex SIP_basic_outgoing_operation.eps@image html SIP_basic_outgoing_operation.gif@subsection nua_basicincomingoperation Basic Incoming Operation@image latex SIP_basic_incoming_operation.eps@image html SIP_basic_incoming_operation.gif@subsection nua_outgoingoperationwithauth Outgoing Operation with Authentication@image latex SIP_outgoing_operation_with_auth.eps@image html SIP_outgoing_operation_with_auth.gif@section nua_simpleapplication Simple ApplicationThe following sections will present code examples from a simple applicationthat uses services of NUA. The example is not complete but should presentall relevant details of the basic use of NUA.The source distribution of Sofia stack contains in directory nua an exampleapplication nua_cli.c that can be studied for more complete example.@subsection nua_datastructures Data Structures & DefinesAn application using services of NUA normally defines data areas that areused to store context information (i.e., "magic"). The types of pointers to

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -