Index: pjproject/trunk/pjlib/build/pjlib.dsp
===================================================================
--- pjproject/trunk/pjlib/build/pjlib.dsp	(revision 514)
+++ pjproject/trunk/pjlib/build/pjlib.dsp	(revision 515)
@@ -183,8 +183,4 @@
 # Begin Source File
 
-SOURCE=..\src\pj\equeue_winnt.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\src\pj\errno.c
 # End Source File
@@ -234,11 +230,4 @@
 
 SOURCE=..\src\pj\ioqueue_select.c
-
-!IF  "$(CFG)" == "pjlib - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "pjlib - Win32 Debug"
-
-!ENDIF 
-
 # End Source File
 # Begin Source File
Index: pjproject/trunk/pjlib/src/pj/equeue_winnt.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/equeue_winnt.c	(revision 514)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/* $Id$ */
-/* 
- * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
- */
-#include <pj/equeue.h>
Index: pjproject/trunk/pjsip/build/pjsip_core.dsp
===================================================================
--- pjproject/trunk/pjsip/build/pjsip_core.dsp	(revision 514)
+++ pjproject/trunk/pjsip/build/pjsip_core.dsp	(revision 515)
@@ -320,4 +320,8 @@
 # Begin Source File
 
+SOURCE=..\docs\doxygen.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\include\pjsip.h
 # End Source File
Index: pjproject/trunk/pjsip/docs/doxygen.cfg
===================================================================
--- pjproject/trunk/pjsip/docs/doxygen.cfg	(revision 514)
+++ pjproject/trunk/pjsip/docs/doxygen.cfg	(revision 515)
@@ -135,5 +135,5 @@
 
 #STRIP_FROM_PATH        = "/cygdrive/e/project/bulukucing.org/pjsip/src"
-STRIP_FROM_PATH        = "/c/project/bulukucing.org/pjsip/src"
+STRIP_FROM_PATH        = "/c/project/pjproject/pjsip"
 
 # The INTERNAL_DOCS tag determines if documentation 
@@ -347,5 +347,5 @@
 # with spaces.
 
-INPUT                  =  src/pjsip src/pjsip_mod_ua src/pjsip_simple src
+INPUT                  =  docs include 
 
 # If the value of the INPUT tag contains directories, you can use the 
@@ -475,5 +475,5 @@
 # should be ignored while generating the index headers.
 
-IGNORE_PREFIX          = 
+IGNORE_PREFIX          =  /c/project/pjproject/pjsip
 
 #---------------------------------------------------------------------------
@@ -496,5 +496,5 @@
 # doxygen will generate files with .html extension.
 
-HTML_FILE_EXTENSION    = .html
+HTML_FILE_EXTENSION    = .htm
 
 # The HTML_HEADER tag can be used to specify a personal HTML header for 
@@ -502,5 +502,5 @@
 # standard header.
 
-HTML_HEADER            = 
+HTML_HEADER            =  docs/header.html
 
 # The HTML_FOOTER tag can be used to specify a personal HTML footer for 
@@ -508,5 +508,5 @@
 # standard footer.
 
-HTML_FOOTER            = 
+HTML_FOOTER            =  docs/footer.html
 
 # The HTML_STYLESHEET tag can be used to specify a user defined cascading 
@@ -845,5 +845,4 @@
 
 PREDEFINED             = PJ_DECL(x)=x PJ_DEF(x)=x PJ_IDECL(x)=x \
-
 			 PJ_IDEF(x)=x PJ_INLINE(x)=x
 
@@ -1011,36 +1010,2 @@
 SEARCHENGINE           = NO
 
-# The CGI_NAME tag should be the name of the CGI script that 
-# starts the search engine (doxysearch) with the correct parameters. 
-# A script with this name will be generated by doxygen.
-
-CGI_NAME               = search.cgi
-
-# The CGI_URL tag should be the absolute URL to the directory where the 
-# cgi binaries are located. See the documentation of your http daemon for 
-# details.
-
-CGI_URL                = 
-
-# The DOC_URL tag should be the absolute URL to the directory where the 
-# documentation is located. If left blank the absolute path to the 
-# documentation, with file:// prepended to it, will be used.
-
-DOC_URL                = 
-
-# The DOC_ABSPATH tag should be the absolute path to the directory where the 
-# documentation is located. If left blank the directory on the local machine 
-# will be used.
-
-DOC_ABSPATH            = 
-
-# The BIN_ABSPATH tag must point to the directory where the doxysearch binary 
-# is installed.
-
-BIN_ABSPATH            = /usr/local/bin/
-
-# The EXT_DOC_PATHS tag can be used to specify one or more paths to 
-# documentation generated for other projects. This allows doxysearch to search 
-# the documentation for these projects as well.
-
-EXT_DOC_PATHS          = 
Index: pjproject/trunk/pjsip/docs/doxygen.h
===================================================================
--- pjproject/trunk/pjsip/docs/doxygen.h	(revision 515)
+++ pjproject/trunk/pjsip/docs/doxygen.h	(revision 515)
@@ -0,0 +1,183 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+/**
+ * @file doxygen.h
+ * @brief PJSIP Doxygen's mainpage.
+ */
+
+/*////////////////////////////////////////////////////////////////////////// */
+/*
+	INTRODUCTION PAGE
+ */
+
+/**
+
+  @mainpage PJSIP
+
+  \n
+  \n
+  @section intro_sec Introduction
+
+  PJSIP is an Open Source SIP prototol stack, designed to be very small in 
+  footprint, have high performance, and very flexible.
+
+  @subsection hist_sec History
+
+  PJSIP has been actively developed since 2003, but its history goes well
+  beyond that. The author has been developing SIP stack since 1999 during
+  RFC 2543 era, and after several experimentation with different approaches 
+  in the programming (the first stack actually was in C++!), and also with
+  the evolution of the SIP protocol itself, the current/third generation
+  of PJSIP (the 0.2.9 version is the second generation) can be considered 
+  as pretty stable in term of design, and should
+  incorporate all design considerations (and implementation tricks!) that 
+  have been learned over the years. Of course only time will tell if this 
+  statement can still be held true in the future.
+
+
+
+
+  \n
+  \n
+  @section pjsipgetting_started Getting Started
+
+  PJSIP consists of multiple levels of APIs, which each of them layered on
+  top of another. Because of this, new readers may find it a bit difficult
+  to find the place to start.
+
+  In general, I think perhaps I can recommend two approaches on using PJSIP.
+
+
+  \n
+  @subsection getting_started_high Using PJSUA API
+
+  @ref PJSUA_LIB wraps together all SIP components and media into a high level
+  API, suitable for creating typical SIP user agent applications. It 
+  features easy to use API for:
+  - multiple client registration (accounts),
+  - high level SIP and media session (calls),
+  - buddy list, presence and instant messaging,
+  - powerful and very easy to use media manipulation,
+
+  while maintaining some space for customization (custom SIP
+  transport, custom SIP media, etc.) needed by some types of applications.
+  @ref PJSUA_LIB is also aimed to be able to run on devices such as PDA
+  or mobile phones, by carefully allowing application to set the appropriate
+  threading strategy and memory limits (number of calls, media ports, etc.).
+
+  However, @ref PJSUA_LIB may not be the most suitable API for some types
+  of applications, since it is directed towards an easy to use API. For
+  more more advanced use, you may better implement the application by using
+  PJSIP + PJMEDIA directly, as described below.
+
+
+  \n
+  @subsection getting_started_pjsip_pjmedia Using PJSIP and PJMEDIA Directly
+
+  For the ultimate flexibility and power, using PJSIP and PJMEDIA directly
+  is the way to go. The drawback will be, of course, steeper learning curve. 
+
+  However, the following links may provide some useful information:
+  - <A HREF="/docs.htm">PJSIP Developer's Guide</A> PDF
+    document is the ultimate guide to understand PJSIP design concept.
+  - there are some samples in <A HREF="/cgi-bin/viewcvs.cgi/pjproject/trunk/pjsip-apps/src/samples/">
+   <b>pjsip-apps/src/samples</b></A> directory.
+  - @ref PJSUA_LIB source code may also be useful to see how high level
+    API are implemented with PJSIP/PJMEDIA.
+  - and finally, you can always <b>Use the Source</b>!
+
+
+
+  \n
+  \n
+  @section this_doc About This Document
+
+  This document contains the reference information about PJSIP. For
+  more in-depth guide (and information in general), readers are 
+  encouraged to read the <A HREF="/docs.htm">
+  <b>PJSIP Developer's Guide</b></A> PDF document
+  which can be downloaded from http://www.pjsip.org/docs.htm.
+
+  \n
+  @subsection doc_ver Version
+
+  This document corresponds to PJSIP version 0.5.6.
+
+  \n
+  @subsection doc_how_to_read How to Read This Document
+
+  For main navigation, please go to <A HREF="modules.htm"><b>Modules</b></A>
+  link on top of this page.
+
+  This document was generated with <A HREF="http://www.doxygen.org">Doxygen</A>
+  from PJSIP header files.
+
+
+  \n
+  \n
+  @section pjsip_toc Documentation Contents
+
+  Click on <A HREF="modules.htm"><b>Modules</b></A> link on top of this page 
+  to get the detailed table of contents.
+
+  The following are top level sections in the <A HREF="modules.htm">
+  <b>Modules</b></A>, as laid out in the following diagram:
+
+  \image html pjsip-arch.jpg "Static Library Layout"
+
+  Enumerating the static libraries from the bottom:
+
+  - <A HREF="/pjlib/docs/main.htm">PJLIB</A>, is the platform abstraction
+    and framework library, on which all other libraries depend,
+
+  - PJLIB-UTIL, provides auxiliary functions such as text scanning,
+    XML, and STUN,
+
+  - PJMEDIA is the multimedia framework,
+
+  - PJMEDIA-CODEC is the placeholder for media codecs,
+
+  - @ref PJSIP_CORE (<b>PJSIP-CORE</b>) is the very core of the PJSIP library, 
+    and contains the SIP @ref PJSIP_ENDPT, which is the owner/manager for all
+    SIP objects in the application, messaging elements, parsing, transport 
+    management, module management, and stateless operations, and also
+    contains:
+
+  - The @ref PJSIP_TRANSACT module inside <b>PJSIP-CORE</b> provides 
+    stateful operation, and is the base for higher layer features such as 
+    dialogs,
+
+  - The @ref PJSIP_UA module inside <b>PJSIP-CORE</b> manages dialogs, and supports dialog
+    usages,
+
+  - @ref PJSIP_SIMPLE (<b>PJSIP-SIMPLE</b>) provides the base SIP event framework 
+    (which uses the common/base dialog framework) and implements presence 
+    on top of it, and is also used by call transfer functions,
+
+  - @ref PJSIP_HIGH_UA (<b>PJSIP-UA</b>) is the high level abstraction of INVITE sessions
+    (using the common/base dialog framework). This library also provides
+    SIP client registration and call transfer functionality,
+
+  - and finally, @ref PJSUA_LIB (<b>PJSUA-LIB</b>) is the highest level of abstraction, 
+    which wraps together all above functionalities into high level, easy to
+    use API.
+*/
+
+
Index: pjproject/trunk/pjsip/docs/footer.html
===================================================================
--- pjproject/trunk/pjsip/docs/footer.html	(revision 515)
+++ pjproject/trunk/pjsip/docs/footer.html	(revision 515)
@@ -0,0 +1,4 @@
+	<!--#include virtual="/footer.html" -->
+
+</BODY>
+</HTML>
Index: pjproject/trunk/pjsip/docs/header.html
===================================================================
--- pjproject/trunk/pjsip/docs/header.html	(revision 515)
+++ pjproject/trunk/pjsip/docs/header.html	(revision 515)
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
+<title>PJSIP - Open Source SIP, SIMPLE, Presence, IM Protocol Stack Documentation</title>
+<link href="/style/style.css" rel="stylesheet" type="text/css">
+</head><body>
+	<!--#include virtual="/header.html" -->
+
Index: pjproject/trunk/pjsip/include/pjsip-simple/evsub.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-simple/evsub.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-simple/evsub.h	(revision 515)
@@ -31,4 +31,5 @@
  * @defgroup PJSIP_EVENT_NOT SIP Event Notification (RFC 3265) Module
  * @ingroup PJSIP_SIMPLE
+ * @brief Core Event Subscription framework, used by presence, call transfer, etc.
  * @{
  *
@@ -431,5 +432,5 @@
  *
  * @param sub		The event subscription.
- * @param index		The module id.
+ * @param mod_id	The module id.
  * @param data		Arbitrary data.
  */
Index: pjproject/trunk/pjsip/include/pjsip-simple/evsub_msg.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-simple/evsub_msg.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-simple/evsub_msg.h	(revision 515)
@@ -27,4 +27,5 @@
 
 /**
+ * @defgroup PJSIP_EVENT_HDRS Additional Header Fields
  * @ingroup PJSIP_EVENT_NOT
  * @{
@@ -42,5 +43,7 @@
 typedef struct pjsip_event_hdr
 {
+    /** Standard header fields. */
     PJSIP_DECL_HDR_MEMBER(struct pjsip_event_hdr);
+
     pj_str_t	    event_type;	    /**< Event name. */
     pj_str_t	    id_param;	    /**< Optional event ID parameter. */
@@ -67,9 +70,10 @@
  * Create a new Allow-Events header.
  *
- * @param pool.	    The pool.
+ * @param pool	    The pool.
  *
  * @return	    Allow-Events header.
  */
-PJ_DECL(pjsip_allow_events_hdr*) pjsip_allow_events_hdr_create(pj_pool_t *pool);
+PJ_DECL(pjsip_allow_events_hdr*) 
+pjsip_allow_events_hdr_create(pj_pool_t *pool);
 
 
@@ -79,5 +83,7 @@
 typedef struct pjsip_sub_state_hdr
 {
+    /** Standard header fields. */
     PJSIP_DECL_HDR_MEMBER(struct pjsip_sub_state_hdr);
+
     pj_str_t	    sub_state;		/**< Subscription state. */
     pj_str_t	    reason_param;	/**< Optional termination reason. */
Index: pjproject/trunk/pjsip/include/pjsip-simple/iscomposing.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-simple/iscomposing.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-simple/iscomposing.h	(revision 515)
@@ -27,4 +27,13 @@
 #include <pjlib-util/xml.h>
 
+/**
+ * @defgroup PJSIP_ISCOMPOSING Message Composition Indication (RFC 3994)
+ * @ingroup PJSIP_SIMPLE
+ * @brief Support for Indication of Message Composition (RFC 3994)
+ * @{
+ *
+ * This implements message composition indication, as described in
+ * RFC 3994.
+ */
 
 PJ_BEGIN_DECL
@@ -114,4 +123,8 @@
 
 
+/**
+ * @}
+ */
+
 
 PJ_END_DECL
Index: pjproject/trunk/pjsip/include/pjsip-simple/pidf.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-simple/pidf.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-simple/pidf.h	(revision 515)
@@ -33,4 +33,5 @@
  * @defgroup PJSIP_SIMPLE_PIDF PIDF/Presence Information Data Format (RFC 3863)
  * @ingroup PJSIP_SIMPLE
+ * @brief Support for PIDF/Presence Information Data Format (RFC 3863)
  * @{
  *
Index: pjproject/trunk/pjsip/include/pjsip-simple/presence.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-simple/presence.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-simple/presence.h	(revision 515)
@@ -35,4 +35,5 @@
  * @defgroup PJSIP_SIMPLE_PRES SIP Extension for Presence (RFC 3856)
  * @ingroup PJSIP_SIMPLE
+ * @brief Support for SIP Extension for Presence (RFC 3856)
  * @{
  *
@@ -68,4 +69,7 @@
 
 
+/**
+ * Maximum presence status info.
+ */
 #define PJSIP_PRES_STATUS_MAX_INFO  8
 
Index: pjproject/trunk/pjsip/include/pjsip-simple/xpidf.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-simple/xpidf.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-simple/xpidf.h	(revision 515)
@@ -32,4 +32,5 @@
  * @defgroup PJSIP_SIMPLE_XPIDF XPIDF/Presence Information Data Format
  * @ingroup PJSIP_SIMPLE
+ * @brief Support for XPIDF/Presence Information Data Format
  * @{
  *
Index: pjproject/trunk/pjsip/include/pjsip-ua/sip_inv.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-ua/sip_inv.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-ua/sip_inv.h	(revision 515)
@@ -20,19 +20,71 @@
 #define __SIP_INVITE_SESSION_H__
 
+/**
+ * @file sip_inv.h
+ * @brief INVITE sessions
+ */
+
+
 #include <pjsip/sip_dialog.h>
 #include <pjmedia/sdp_neg.h>
 
 
+/**
+ * @defgroup PJSIP_HIGH_UA User Agent Library
+ * @ingroup PJSIP
+ * @brief Mid-level User Agent Library.
+ *
+ * This is the high level user agent library, which consists of:
+ *  - @ref PJSIP_INV, to encapsulate INVITE sessions and SDP
+ *    negotiation in the session,
+ *  - @ref PJSUA_REGC, high level client registration API, and
+ *  - @ref PJSUA_XFER.
+ *
+ * More detailed information is explained in
+ * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
+ * PDF document, and readers are encouraged to read the document to
+ * get the concept behind dialog, dialog usages, and INVITE sessions.
+ *
+ * The User Agent Library is implemented in <b>pjsip-ua</b> static
+ * library.
+ */
+
+/**
+ * @defgroup PJSIP_INV INVITE Session
+ * @ingroup PJSIP_HIGH_UA
+ * @brief Provides INVITE session management.
+ * @{
+ *
+ * The INVITE session uses the @ref PJSIP_DIALOG framework to manage
+ * the underlying dialog, and is one type of usages that can use
+ * a particular dialog instance (other usages are event subscription,
+ * discussed in @ref PJSIP_EVENT_NOT). The INVITE session manages
+ * the life-time of the session, and also manages the SDP negotiation.
+ *
+ * Application must link with  <b>pjsip-ua</b> static library to use this API.
+ *
+ * More detailed information is explained in
+ * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
+ * PDF document, and readers are encouraged to read the document to
+ * get the concept behind dialog, dialog usages, and INVITE sessions.
+ *
+ * The INVITE session does NOT manage media. If application wants to
+ * use API that encapsulates both signaling and media in a very easy
+ * to use API, it can use @ref PJSUA_LIB for this purpose.
+ */
+
 PJ_BEGIN_DECL
 
 
-typedef enum pjsip_inv_state pjsip_inv_state;
+/**
+ * @see pjsip_inv_session
+ */
 typedef struct pjsip_inv_session pjsip_inv_session;
-typedef struct pjsip_inv_callback pjsip_inv_callback;
+
 
 /**
  * This enumeration describes invite session state.
  */
-enum pjsip_inv_state
+typedef enum pjsip_inv_state
 {
     PJSIP_INV_STATE_NULL,	    /**< Before INVITE is sent or received  */
@@ -43,5 +95,5 @@
     PJSIP_INV_STATE_CONFIRMED,	    /**< After ACK is sent/received.	    */
     PJSIP_INV_STATE_DISCONNECTED,   /**< Session is terminated.		    */
-};
+} pjsip_inv_state;
 
 /**
@@ -50,5 +102,5 @@
  * the invite session.
  */
-struct pjsip_inv_callback
+typedef struct pjsip_inv_callback
 {
     /**
@@ -119,5 +171,7 @@
     void (*on_media_update)(pjsip_inv_session *inv_ses, 
 			    pj_status_t status);
-};
+
+} pjsip_inv_callback;
+
 
 
@@ -188,5 +242,5 @@
  *
  * @param endpt		The endpoint instance.
- * @param callback	Callback structure.
+ * @param cb		Callback structure.
  *
  * @return		PJ_SUCCESS on success, or the appropriate error code.
@@ -311,5 +365,5 @@
  *			received request to see if the request contains 
  *			features that it supports.
- * @param sdp		If application has determined its media capability, 
+ * @param local_sdp	If application has determined its media capability, 
  *			it can specify this capability in this argument. 
  *			If SDP is received in the initial INVITE, the UAS 
@@ -564,4 +618,7 @@
 PJ_END_DECL
 
+/**
+ * @}
+ */
 
 
Index: pjproject/trunk/pjsip/include/pjsip-ua/sip_regc.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-ua/sip_regc.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-ua/sip_regc.h	(revision 515)
@@ -27,15 +27,19 @@
 #include <pjsip/sip_types.h>
 #include <pjsip/sip_auth.h>
-//#include <pjsip/sip_ua.h>
+
+
+/**
+ * @defgroup PJSUA_REGC Client Registration
+ * @ingroup PJSIP_HIGH_UA
+ * @brief High Layer API for performing client registration.
+ * @{
+ *
+ * This provides API for performing client registration. Application must
+ * link with  <b>pjsip-ua</b> static library to use this API.
+
+ */
+
 
 PJ_BEGIN_DECL
-
-/**
- * @defgroup PJSUA_REGC SIP Registration Client
- * @ingroup PJSUA
- * @{
- * \brief
- *   API for performing registration for user agent.
- */
 
 /** Typedef for client registration data. */
@@ -57,13 +61,13 @@
 struct pjsip_regc_cbparam
 {
-    pjsip_regc		*regc;
-    void		*token;
-    int			 code;
-    pj_status_t		 status;
-    pj_str_t		 reason;
-    pjsip_rx_data	*rdata;
-    int			 contact_cnt;
-    int			 expiration;
-    pjsip_contact_hdr	*contact[PJSIP_REGC_MAX_CONTACT];
+    pjsip_regc		*regc;	    /**< Client registration structure.	    */
+    void		*token;	    /**< Arbitrary token.		    */
+    pj_status_t		 status;    /**< Error status.			    */
+    int			 code;	    /**< SIP status code received.	    */
+    pj_str_t		 reason;    /**< SIP reason phrase received.	    */
+    pjsip_rx_data	*rdata;	    /**< The complete received response.    */
+    int			 expiration;/**< Next expiration interval.	    */
+    int			 contact_cnt;/**<Number of contacts in response.    */
+    pjsip_contact_hdr	*contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts.    */
 };
 
@@ -150,4 +154,5 @@
  *
  * @param regc	    The client registration structure.
+ * @param srv_url   Server URL.
  * @param from_url  The person performing the registration, must be a SIP URL type.
  * @param to_url    The address of record for which the registration is targetd, must
@@ -260,3 +265,7 @@
 PJ_END_DECL
 
+/**
+ * @}
+ */
+
 #endif	/* __PJSIP_REG_H__ */
Index: pjproject/trunk/pjsip/include/pjsip-ua/sip_xfer.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-ua/sip_xfer.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip-ua/sip_xfer.h	(revision 515)
@@ -29,4 +29,17 @@
 #include <pjsip/sip_msg.h>
 
+/**
+ * @defgroup PJSUA_XFER Call Transfer
+ * @ingroup PJSIP_HIGH_UA
+ * @brief Provides call transfer functionality.
+ * @{
+ *
+ * This implements call transfer functionality to INVITE sessions. The call
+ * transfer functionality uses SIP Event Subscription framework for
+ * managing call transfer status.
+ *
+ * Application must link with <b>pjsip-ua</b> AND <b>pjsip-simple</b> static
+ * libraries to use call transfer functionality.
+ */
 
 
@@ -169,6 +182,9 @@
 
 
+PJ_END_DECL
 
-PJ_END_DECL
+/**
+ * @}
+ */
 
 #endif	/* __PJSIP_XFER_H__ */
Index: pjproject/trunk/pjsip/include/pjsip/sip_auth.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_auth.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_auth.h	(revision 515)
@@ -30,12 +30,18 @@
 PJ_BEGIN_DECL
 
-
-/**
- * @defgroup PJSIP_AUTH_API Authorization API's
+/**
+ * @addtogroup PJSIP_AUTH Authentication Framework
+ * @ingroup PJSIP_CORE
+ * @brief Client and server side authentication framework.
+ */
+
+/**
+ * @defgroup PJSIP_AUTH_API Authentication API's
  * @ingroup PJSIP_AUTH
+ * @brief Structures and functions to perform authentication.
  * @{
  */
 
-/* Length of digest string. */
+/** Length of digest string. */
 #define PJSIP_MD5STRLEN 32
 
@@ -81,4 +87,5 @@
 typedef struct pjsip_cached_auth_hdr
 {
+    /** Standard list member */
     PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr);
 
@@ -101,4 +108,5 @@
 typedef struct pjsip_cached_auth
 {
+    /** Standard list member */
     PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth);
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_auth_msg.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_auth_msg.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_auth_msg.h	(revision 515)
@@ -25,19 +25,21 @@
 
 /**
- * @defgroup PJSIP_MSG_AUTHORIZATION Header Field: Authorization and Proxy-Authorization
- * @brief Authorization and Proxy-Authorization header field.
- * @ingroup PJSIP_MSG
+ * @addtogroup PJSIP_MSG_HDR
  * @{
  */
 
 /**
- * Common credential.
+ * Common credential structure represents common credential fields
+ * present in Authorization/Proxy-Authorization header.
  */
 struct pjsip_common_credential
 {
-    pj_str_t	realm;
-    pjsip_param	other_param;
-};
-
+    pj_str_t	realm;		/**< Credential's realm.    */
+    pjsip_param	other_param;	/**< Other parameters.	    */
+};
+
+/**
+ * @see pjsip_common_credential
+ */
 typedef struct pjsip_common_credential pjsip_common_credential;
 
@@ -49,17 +51,20 @@
 struct pjsip_digest_credential
 {
-    pj_str_t	realm;
-    pjsip_param	other_param;
-    pj_str_t	username;
-    pj_str_t	nonce;
-    pj_str_t	uri;
-    pj_str_t	response;
-    pj_str_t	algorithm;
-    pj_str_t	cnonce;
-    pj_str_t	opaque;
-    pj_str_t	qop;
-    pj_str_t	nc;
-};
-
+    pj_str_t	realm;		/**< Realm of the credential	*/
+    pjsip_param	other_param;	/**< Other parameters.		*/
+    pj_str_t	username;	/**< Username parameter.	*/
+    pj_str_t	nonce;		/**< Nonce parameter.		*/
+    pj_str_t	uri;		/**< URI parameter.		*/ 
+    pj_str_t	response;	/**< Response digest.		*/
+    pj_str_t	algorithm;	/**< Algorithm.			*/
+    pj_str_t	cnonce;		/**< Cnonce.			*/
+    pj_str_t	opaque;		/**< Opaque value.		*/
+    pj_str_t	qop;		/**< Quality of protection.	*/
+    pj_str_t	nc;		/**< Nonce count.		*/
+};
+
+/**
+ * @see pjsip_digest_credential
+ */
 typedef struct pjsip_digest_credential pjsip_digest_credential;
 
@@ -70,12 +75,15 @@
 struct pjsip_pgp_credential
 {
-    pj_str_t	realm;
-    pjsip_param	other_param;
-    pj_str_t	version;
-    pj_str_t	signature;
-    pj_str_t	signed_by;
-    pj_str_t	nonce;
-};
-
+    pj_str_t	realm;		/**< Realm.			*/
+    pjsip_param	other_param;	/**< Other parameters.		*/
+    pj_str_t	version;	/**< Version parameter.		*/
+    pj_str_t	signature;	/**< Signature parameter.	*/
+    pj_str_t	signed_by;	/**< Signed by parameter.	*/
+    pj_str_t	nonce;		/**< Nonce parameter.		*/
+};
+
+/**
+ * @see pjsip_pgp_credential
+ */
 typedef struct pjsip_pgp_credential pjsip_pgp_credential;
 
@@ -86,14 +94,22 @@
 struct pjsip_authorization_hdr
 {
+    /** Standard header fiends. */
     PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr);
+
+    /** Authorization scheme.  */
     pj_str_t scheme;
+
+    /** Type of credentials, depending on the scheme. */
     union
     {
-	pjsip_common_credential common;
-	pjsip_digest_credential digest;
-	pjsip_pgp_credential	pgp;
+	pjsip_common_credential common;	/**< Common fields.	    */
+	pjsip_digest_credential digest;	/**< Digest credentials.    */
+	pjsip_pgp_credential	pgp;	/**< PGP credentials.	    */
     } credential;
 };
 
+/**
+ * @see pjsip_authorization_hdr.
+ */
 typedef struct pjsip_authorization_hdr pjsip_authorization_hdr;
 
@@ -105,34 +121,32 @@
 /**
  * Create SIP Authorization header.
- * @param pool Pool where memory will be allocated from.
- * @return SIP Authorization header.
- */
-PJ_DECL(pjsip_authorization_hdr*) pjsip_authorization_hdr_create(pj_pool_t *pool);
+ * @param pool	    Pool where memory will be allocated from.
+ * @return	    SIP Authorization header.
+ */
+PJ_DECL(pjsip_authorization_hdr*) 
+pjsip_authorization_hdr_create(pj_pool_t *pool);
 
 /**
  * Create SIP Proxy-Authorization header.
- * @param pool Pool where memory will be allocated from.
- * @return SIP Proxy-Authorization header.
- */
-PJ_DECL(pjsip_proxy_authorization_hdr*) pjsip_proxy_authorization_hdr_create(pj_pool_t *pool);
-
-
-/**
- * @}
- */
-
-/**
- * @defgroup PJSIP_WWW_AUTH Header Field: Proxy-Authenticate and WWW-Authenticate
- * @brief Proxy-Authenticate and WWW-Authenticate.
- * @ingroup PJSIP_MSG
- * @{
- */
-
+ * @param pool	    Pool where memory will be allocated from.
+ * @return SIP	    Proxy-Authorization header.
+ */
+PJ_DECL(pjsip_proxy_authorization_hdr*) 
+pjsip_proxy_authorization_hdr_create(pj_pool_t *pool);
+
+
+/**
+ * This structure describes common fields in authentication challenge
+ * headers (WWW-Authenticate and Proxy-Authenticate).
+ */
 struct pjsip_common_challenge
 {
-    pj_str_t	realm;
-    pjsip_param	other_param;
-};
-
+    pj_str_t	realm;		/**< Realm for the challenge.	*/
+    pjsip_param	other_param;	/**< Other parameters.		*/
+};
+
+/**
+ * @see pjsip_common_challenge
+ */
 typedef struct pjsip_common_challenge pjsip_common_challenge;
 
@@ -143,14 +157,17 @@
 struct pjsip_digest_challenge
 {
-    pj_str_t	realm;
-    pjsip_param	other_param;
-    pj_str_t	domain;
-    pj_str_t	nonce;
-    pj_str_t	opaque;
-    int		stale;
-    pj_str_t	algorithm;
-    pj_str_t	qop;
-};
-
+    pj_str_t	realm;		/**< Realm for the challenge.	*/
+    pjsip_param	other_param;	/**< Other parameters.		*/
+    pj_str_t	domain;		/**< Domain.			*/
+    pj_str_t	nonce;		/**< Nonce challenge.		*/
+    pj_str_t	opaque;		/**< Opaque value.		*/
+    int		stale;		/**< Stale parameter.		*/
+    pj_str_t	algorithm;	/**< Algorithm parameter.	*/
+    pj_str_t	qop;		/**< Quality of protection.	*/
+};
+
+/**
+ * @see pjsip_digest_challenge
+ */
 typedef struct pjsip_digest_challenge pjsip_digest_challenge;
 
@@ -161,12 +178,15 @@
 struct pjsip_pgp_challenge
 {
-    pj_str_t	realm;
-    pjsip_param	other_param;
-    pj_str_t	version;
-    pj_str_t	micalgorithm;
-    pj_str_t	pubalgorithm;
-    pj_str_t	nonce;
-};
-
+    pj_str_t	realm;		/**< Realm for the challenge.	*/
+    pjsip_param	other_param;	/**< Other parameters.		*/
+    pj_str_t	version;	/**< PGP version.		*/
+    pj_str_t	micalgorithm;	/**< micalgorithm parameter.	*/
+    pj_str_t	pubalgorithm;	/**< pubalgorithm parameter.	*/ 
+    pj_str_t	nonce;		/**< Nonce challenge.		*/
+};
+
+/**
+ * @see pjsip_pgp_challenge
+ */
 typedef struct pjsip_pgp_challenge pjsip_pgp_challenge;
 
@@ -177,15 +197,29 @@
 struct pjsip_www_authenticate_hdr
 {
+    /** Standard header fields. */
     PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr);
+
+    /** Authentication scheme  */
     pj_str_t	scheme;
+
+    /** This union contains structures that are only relevant
+        depending on the value of the scheme being used.
+     */
     union
     {
-	pjsip_common_challenge	common;
-	pjsip_digest_challenge	digest;
-	pjsip_pgp_challenge	pgp;
+	pjsip_common_challenge	common;	/**< Common fields.	*/
+	pjsip_digest_challenge	digest;	/**< Digest challenge.	*/
+	pjsip_pgp_challenge	pgp;	/**< PGP challenge.	*/
     } challenge;
 };
 
+/**
+ * WWW-Authenticate header.
+ */
 typedef struct pjsip_www_authenticate_hdr pjsip_www_authenticate_hdr;
+
+/**
+ * Proxy-Authenticate header.
+ */
 typedef struct pjsip_www_authenticate_hdr pjsip_proxy_authenticate_hdr;
 
@@ -193,15 +227,19 @@
 /**
  * Create SIP WWW-Authenticate header.
- * @param pool Pool where memory will be allocated from.
- * @return SIP WWW-Authenticate header.
- */
-PJ_DECL(pjsip_www_authenticate_hdr*) pjsip_www_authenticate_hdr_create(pj_pool_t *pool);
+ *
+ * @param pool	    Pool where memory will be allocated from.
+ * @return	    SIP WWW-Authenticate header.
+ */
+PJ_DECL(pjsip_www_authenticate_hdr*) 
+pjsip_www_authenticate_hdr_create(pj_pool_t *pool);
 
 /**
  * Create SIP Proxy-Authenticate header.
- * @param pool Pool where memory will be allocated from.
- * @return SIP Proxy-Authenticate header.
- */
-PJ_DECL(pjsip_proxy_authenticate_hdr*) pjsip_proxy_authenticate_hdr_create(pj_pool_t *pool);
+ *
+ * @param pool	    Pool where memory will be allocated from.
+ * @return	    SIP Proxy-Authenticate header.
+ */
+PJ_DECL(pjsip_proxy_authenticate_hdr*) 
+pjsip_proxy_authenticate_hdr_create(pj_pool_t *pool);
 
 /**
Index: pjproject/trunk/pjsip/include/pjsip/sip_auth_parser.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_auth_parser.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_auth_parser.h	(revision 515)
@@ -30,14 +30,10 @@
 
 /**
- * @defgroup PJSIP_AUTH_PARSER_MODULE Authorization Parser Module
- * @ingroup PJSIP_AUTH
- * @{
- */
-
-/**
  * Initialize and register authorization parser module.
  * This will register parser handler for various Authorization related headers
  * such as Authorization, WWW-Authenticate, Proxy-Authorizization, and 
  * Proxy-Authenticate headers.
+ *
+ * This function is called automatically by the main SIP parser.
  *
  * @return      PJ_SUCCESS or the appropriate status code.
@@ -51,34 +47,23 @@
 
 
-extern const pj_str_t	pjsip_USERNAME_STR,
-			pjsip_REALM_STR,
-			pjsip_NONCE_STR,
-			pjsip_URI_STR,
-			pjsip_RESPONSE_STR,
-			pjsip_ALGORITHM_STR,
-			pjsip_DOMAIN_STR,
-			pjsip_STALE_STR,
-			pjsip_QOP_STR,
-			pjsip_CNONCE_STR,
-			pjsip_OPAQUE_STR,
-			pjsip_NC_STR,
-			pjsip_TRUE_STR,
-			pjsip_FALSE_STR,
-			pjsip_DIGEST_STR,
-			pjsip_PGP_STR,
-			pjsip_MD5_STR,
-			pjsip_AUTH_STR;
-/*
-extern const pj_str_t	pjsip_QUOTED_TRUE_STR,
-			pjsip_QUOTED_FALSE_STR,
-			pjsip_QUOTED_DIGEST_STR,
-			pjsip_QUOTED_PGP_STR,
-			pjsip_QUOTED_MD5_STR,
-			pjsip_QUOTED_AUTH_STR;
-*/
 
-/**
- * @}
- */
+extern const pj_str_t	pjsip_USERNAME_STR, /**< "username" string const.   */
+			pjsip_REALM_STR,    /**< "realm" string const.	    */
+			pjsip_NONCE_STR,    /**< "nonce" string const.	    */
+			pjsip_URI_STR,	    /**< "uri" string const.	    */
+			pjsip_RESPONSE_STR, /**< "response" string const.   */
+			pjsip_ALGORITHM_STR,/**< "algorithm" string const.  */
+			pjsip_DOMAIN_STR,   /**< "domain" string const.	    */
+			pjsip_STALE_STR,    /**< "stale" string const.	    */
+			pjsip_QOP_STR,	    /**< "qop" string const.	    */
+			pjsip_CNONCE_STR,   /**< "cnonce" string const.	    */
+			pjsip_OPAQUE_STR,   /**< "opaque" string const.	    */
+			pjsip_NC_STR,	    /**< "nc" string const.	    */
+			pjsip_TRUE_STR,	    /**< "true" string const.	    */
+			pjsip_FALSE_STR,    /**< "false" string const.	    */
+			pjsip_DIGEST_STR,   /**< "digest" string const.	    */
+			pjsip_PGP_STR,	    /**< "pgp" string const.	    */
+			pjsip_MD5_STR,	    /**< "md5" string const.	    */
+			pjsip_AUTH_STR;	    /**< "auth" string const.	    */
 
 PJ_END_DECL
Index: pjproject/trunk/pjsip/include/pjsip/sip_config.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 515)
@@ -20,5 +20,40 @@
 #define __PJSIP_SIP_CONFIG_H__
 
+/**
+ * @file sip_config.h
+ * @brief Compile time configuration.
+ */
 #include <pj/config.h>
+
+/**
+ * @defgroup PJSIP PJSIP Library Collection
+ */
+
+/**
+ * @defgroup PJSIP_CORE Core SIP Library
+ * @ingroup PJSIP
+ * @brief The core framework from which all other SIP components depends on.
+ * 
+ * The PJSIP Core library only provides transport framework, event
+ * dispatching/module framework, and SIP message representation and
+ * parsing. It doesn't do anything usefull in itself!
+ *
+ * If application wants the stack to do anything usefull at all,
+ * it must registers @ref PJSIP_MOD to the core library. Examples
+ * of modules are @ref PJSIP_TRANSACT and @ref PJSUA_UA.
+ */
+
+/**
+ * @defgroup PJSIP_BASE Base Types
+ * @ingroup PJSIP_CORE
+ * @brief Basic PJSIP types and configurations.
+ */
+
+/**
+ * @defgroup PJSIP_CONFIG Compile Time Configuration
+ * @ingroup PJSIP_BASE
+ * @brief PJSIP compile time configurations.
+ * @{
+ */
 
 /**
@@ -74,4 +109,12 @@
 #ifndef PJSIP_MAX_MODULE
 #   define PJSIP_MAX_MODULE		16
+#endif
+
+
+/**
+ * Maximum packet length.
+ */
+#ifndef PJSIP_MAX_PKT_LEN
+#   define PJSIP_MAX_PKT_LEN		1500
 #endif
 
@@ -85,5 +128,4 @@
 /* Transport related constants. */
 
-#define PJSIP_MAX_PKT_LEN		1500
 #define PJSIP_POOL_RDATA_LEN		4000
 #define PJSIP_POOL_RDATA_INC		4000
@@ -142,20 +184,20 @@
 //#define PJSIP_T2_TIMEOUT	60000
 
-/* T1 timeout value. */
+/** Transaction T1 timeout value. */
 #if !defined(PJSIP_T1_TIMEOUT)
 #  define PJSIP_T1_TIMEOUT	500
 #endif
 
-/* T2 timeout value. */
+/** Transaction T2 timeout value. */
 #if !defined(PJSIP_T2_TIMEOUT)
 #  define PJSIP_T2_TIMEOUT	4000
 #endif
 
-/* Completed timer for non-INVITE */
+/** Transaction completed timer for non-INVITE */
 #if !defined(PJSIP_T4_TIMEOUT)
 #  define PJSIP_T4_TIMEOUT	5000
 #endif
 
-/* Completed timer for INVITE */
+/** Transaction completed timer for INVITE */
 #if !defined(PJSIP_TD_TIMEOUT)
 #  define PJSIP_TD_TIMEOUT	32000
@@ -167,5 +209,5 @@
  */
 
-/*
+/**
  * If this flag is set, the stack will keep the Authorization/Proxy-Authorization
  * headers that are sent in a cache. Future requests with the same realm and
@@ -183,5 +225,5 @@
 #endif
 
-/*
+/**
  * If this flag is set, the stack will proactively send Authorization/Proxy-
  * Authorization header for next requests. If next request has the same method
@@ -204,5 +246,5 @@
 #endif
 
-/*
+/**
  * Support qop="auth" directive.
  * This option also requires client to cache the last challenge offered by
@@ -216,4 +258,8 @@
 
 
+/**
+ * @}
+ */
+
 #include <pj/config.h>
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_dialog.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_dialog.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_dialog.h	(revision 515)
@@ -31,4 +31,28 @@
 #include <pj/sock.h>
 #include <pj/assert.h>
+
+
+/**
+ * @defgroup PJSIP_DIALOG Base Dialog
+ * @ingroup PJSIP_UA
+ * @brief The base dialog framework to support dialog usages.
+ * @{
+ *
+ * The base dialog framework provides management for base dialog
+ * properties such as <b>From</b> header, <b>To</b> header, <b>CSeq</b>
+ * sequencing, <b>Call-ID</b> header, <b>Contact</b> header management, 
+ * dialog <b>route-set</b> management, and common <b>authentication</b>. 
+ * This basic dialog functionality will be shared by all <b>dialog
+ * usages</b> of a particular dialog.
+ *
+ * More detailed information is explained in
+ * <A HREF="/docs.htm">PJSIP Developer's Guide</A>
+ * PDF document, and readers are encouraged to read the document to
+ * get the concept behind dialog, dialog usages, and INVITE sessions.
+ *
+ * Application MUST initialize the user agent layer module by calling
+ * #pjsip_ua_init_module() before using any of the dialog API, and link
+ * the application with with <b>pjsip-core</b> library.
+ */
 
 PJ_BEGIN_DECL
@@ -55,5 +79,8 @@
 enum pjsip_dialog_state
 {
+    /** Dialog is not established. */
     PJSIP_DIALOG_STATE_NULL,
+
+    /** Dialog has been established (probably early) */
     PJSIP_DIALOG_STATE_ESTABLISHED,
 };
@@ -87,5 +114,5 @@
     pjsip_endpoint     *endpt;	    /**< Endpoint instance.		    */
 
-    /* The dialog set. */
+    /** The dialog set which this dialog belongs (opaque type). */
     void	       *dlg_set;
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_endpoint.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_endpoint.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_endpoint.h	(revision 515)
@@ -28,16 +28,16 @@
 #include <pjsip/sip_resolve.h>
 
+/**
+ * @defgroup PJSIP_CORE_CORE At the Very Core
+ * @ingroup PJSIP_CORE
+ * @brief The very core of PJSIP.
+ */
+
 PJ_BEGIN_DECL
 
 /**
- * @defgroup PJSIP SIP Stack Core
- * Implementation of core SIP protocol stack processing.
- */
-
-/**
- * @defgroup PJSIP_ENDPT SIP Endpoint
- * @ingroup PJSIP
- * @brief
- * Representation of SIP node instance.
+ * @defgroup PJSIP_ENDPT Endpoint
+ * @ingroup PJSIP_CORE_CORE
+ * @brief The master, owner of all objects
  *
  * SIP Endpoint instance (pjsip_endpoint) can be viewed as the master/owner of
@@ -287,5 +287,5 @@
  * Note: at the moment we don't have implementation of RFC 3263 yet!
  *
- * @param resolver  The resolver engine.
+ * @param endpt	    The endpoint instance.
  * @param pool	    The pool to allocate resolver job.
  * @param target    The target specification to be resolved.
@@ -420,4 +420,9 @@
 
 /**
+ * @}
+ */
+
+
+/**
  * Log an error.
  */
@@ -437,8 +442,4 @@
             } while (0)
 
-/**
- * @}
- */
-
 /*
  * Internal functions.
Index: pjproject/trunk/pjsip/include/pjsip/sip_errno.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_errno.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_errno.h	(revision 515)
@@ -20,7 +20,19 @@
 #define __PJSIP_SIP_ERRNO_H__
 
+/**
+ * @file sip_errno.h
+ * @brief PJSIP Specific Error Code
+ */
+
 #include <pj/errno.h>
 
 PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJSIP_CORE_ERRNO PJSIP Specific Error Code
+ * @ingroup PJSIP_BASE
+ * @brief PJSIP specific error constants.
+ * @{
+ */
 
 /*
@@ -383,3 +395,8 @@
 PJ_END_DECL
 
+
+/**
+ * @}
+ */
+
 #endif	/* __PJSIP_SIP_ERRNO_H__ */
Index: pjproject/trunk/pjsip/include/pjsip/sip_event.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_event.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_event.h	(revision 515)
@@ -28,6 +28,7 @@
 
 /**
- * @defgroup PJSIP_EVENT SIP Event
- * @ingroup PJSIP
+ * @defgroup PJSIP_EVENT Event
+ * @ingroup PJSIP_CORE_CORE
+ * @brief Representation of events as they are distributed among modules.
  * @{
  */
@@ -65,6 +66,5 @@
 
 /**
- * \struct
- * \brief Event descriptor to fully identify a SIP event.
+ * This structure describe event descriptor to fully identify a SIP event.
  *
  * Events are the only way for a lower layer object to inform something
@@ -86,6 +86,6 @@
     pjsip_event_id_e type;
 
-    /*
-     * The event body.
+    /**
+     * The event body as union, which fields depends on the event type.
      * By convention, the first member of each struct in the union must be
      * the pointer which is relevant to the event.
@@ -217,5 +217,5 @@
  * Get the event string from the event ID.
  * @param e the event ID.
- * @notes defined in sip_util.c
+ * @note defined in sip_util.c
  */
 PJ_DEF(const char *) pjsip_event_str(pjsip_event_id_e e);
Index: pjproject/trunk/pjsip/include/pjsip/sip_module.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_module.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_module.h	(revision 515)
@@ -30,14 +30,24 @@
 
 /**
- * @defgroup PJSIP_MOD SIP Modules
- * @ingroup PJSIP
+ * @defgroup PJSIP_MOD Modules
+ * @ingroup PJSIP_CORE_CORE
+ * @brief Modules are the primary means to extend PJSIP!
  * @{
- */
-
-/**
- * Module registration structure, which is passed by the module to the
- * endpoint during the module registration process. This structure enables
- * the endpoint to query the module capability and to further communicate
- * with the module.
+ * Modules are the primary means to extend PJSIP. Without modules, PJSIP
+ * would not know how to handle messages, and will simply discard all
+ * incoming messages.
+ *
+ * Modules are registered by creating and initializing #pjsip_module 
+ * structure, and register the structure to PJSIP with 
+ * #pjsip_endpt_register_module().
+ *
+ * The <A HREF="/docs.htm">PJSIP Developer's Guide</A>
+ * has a thorough discussion on this subject, and readers are encouraged
+ * to read the document for more information.
+ */
+
+/**
+ * The declaration for SIP module. This structure would be passed to
+ * #pjsip_endpt_register_module() to register the module to PJSIP.
  */
 struct pjsip_module
@@ -47,10 +57,14 @@
 
     /**
-     * Module name.
+     * Module name to identify the module.
+     *
+     * This field MUST be initialized before registering the module.
      */
     pj_str_t name;
 
     /**
-     * Module ID.
+     * Module ID. Application must initialize this field with -1 before
+     * registering the module to PJSIP. After the module is registered,
+     * this field will contain a unique ID to identify the module.
      */
     int id;
@@ -60,9 +74,13 @@
      * regard to other modules. Higher number will make the module gets
      * initialized later.
+     *
+     * This field MUST be initialized before registering the module.
      */
     int priority;
 
     /**
-     * Pointer to function to be called to initialize the module.
+     * Optional function to be called to initialize the module. This function
+     * will be called by endpoint during module registration. If the value
+     * is NULL, then it's equal to returning PJ_SUCCESS.
      *
      * @param endpt	The endpoint instance.
@@ -72,5 +90,7 @@
 
     /**
-     * Pointer to function to be called to start the module.
+     * Optional function to be called to start the module. This function
+     * will be called by endpoint during module registration. If the value
+     * is NULL, then it's equal to returning PJ_SUCCESS.
      *
      * @return		Module should return zero to indicate success.
@@ -79,6 +99,8 @@
 
     /**
-     * Pointer to function to be called to deinitialize the module before
-     * it is unloaded.
+     * Optional function to be called to deinitialize the module before
+     * it is unloaded. This function will be called by endpoint during 
+     * module unregistration. If the value is NULL, then it's equal to 
+     * returning PJ_SUCCESS.
      *
      * @return		Module should return PJ_SUCCESS to indicate success.
@@ -87,6 +109,8 @@
 
     /**
-     * Pointer to function to be called to deinitialize the module before
-     * it is unloaded.
+     * Optional function to be called to deinitialize the module before
+     * it is unloaded. This function will be called by endpoint during 
+     * module unregistration. If the value is NULL, then it's equal to 
+     * returning PJ_SUCCESS.
      *
      * @param mod	The module.
@@ -97,5 +121,5 @@
 
     /**
-     * Called to process incoming request.
+     * Optional function to be called to process incoming request message.
      *
      * @param rdata	The incoming message.
@@ -108,5 +132,5 @@
 
     /**
-     * Called to processed incoming response.
+     * Optional function to be called to process incoming response message.
      *
      * @param rdata	The incoming message.
@@ -119,5 +143,6 @@
 
     /**
-     * Called to process outgoing request.
+     * Optional function to be called when transport layer is about to
+     * transmit outgoing request message.
      *
      * @param tdata	The outgoing request message.
@@ -130,5 +155,6 @@
 
     /**
-     * Called to process outgoing response message.
+     * Optional function to be called when transport layer is about to
+     * transmit outgoing response message.
      *
      * @param tdata	The outgoing response message.
@@ -141,6 +167,7 @@
 
     /**
-     * Called when this module is acting as transaction user for the specified
-     * transaction, when the transaction's state has changed.
+     * Optional function to be called when this module is acting as 
+     * transaction user for the specified transaction, when the 
+     * transaction's state has changed.
      *
      * @param tsx	The transaction.
@@ -158,8 +185,27 @@
 enum pjsip_module_priority
 {
+    /** 
+     * This is the priority used by transport layer.
+     */
     PJSIP_MOD_PRIORITY_TRANSPORT_LAYER	= 8,
+
+    /**
+     * This is the priority used by transaction layer.
+     */
     PJSIP_MOD_PRIORITY_TSX_LAYER	= 16,
+
+    /**
+     * This is the priority used by the user agent and proxy layer.
+     */
     PJSIP_MOD_PRIORITY_UA_PROXY_LAYER	= 32,
+
+    /**
+     * This is the priority used by the dialog usages.
+     */
     PJSIP_MOD_PRIORITY_DIALOG_USAGE	= 48,
+
+    /**
+     * This is the recommended priority to be used by applications.
+     */
     PJSIP_MOD_PRIORITY_APPLICATION	= 64,
 };
Index: pjproject/trunk/pjsip/include/pjsip/sip_msg.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_msg.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_msg.h	(revision 515)
@@ -21,5 +21,5 @@
 
 /**
- * @file sip_msg.h
+ * @file pjsip/sip_msg.h
  * @brief SIP Message Structure.
  */
@@ -32,6 +32,7 @@
 
 /**
- * @defgroup PJSIP_MSG SIP Message Structure
- * @ingroup PJSIP
+ * @defgroup PJSIP_MSG Messaging Elements
+ * @ingroup PJSIP_CORE
+ * @brief Various SIP message elements such as methods, headers, URIs, etc.
  * @{
  */
@@ -155,6 +156,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 /** 
- * @defgroup PJSIP_MSG_HDR Header Fields General Structure.
- * @brief General Header Fields Structure.
+ * @defgroup PJSIP_MSG_HDR Header Fields
+ * @brief Declarations for various SIP header fields.
  * @ingroup PJSIP_MSG
  * @{
@@ -462,6 +463,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 /**
- * @addtogroup PJSIP_MSG_MEDIA Media Type
- * @brief Media type definitions and manipulations.
+ * @addtogroup PJSIP_MSG_MEDIA Media/MIME Type
+ * @brief Media/MIME type declaration and manipulations.
  * @ingroup PJSIP_MSG
  * @{
@@ -655,5 +656,5 @@
 /**
  * @defgroup PJSIP_MSG_MSG Message Structure
- * @brief Message structure and operations.
+ * @brief SIP message (request and response) structure and operations.
  * @ingroup PJSIP_MSG
  * @{
@@ -846,7 +847,5 @@
 ///////////////////////////////////////////////////////////////////////////////
 /**
- * @addtogroup PJSIP_MSG_HDR_GEN Header Field: Generic
- * @brief Generic header field which contains header name and value.
- * @ingroup PJSIP_MSG
+ * @addtogroup PJSIP_MSG_HDR
  * @{
  */
@@ -905,15 +904,6 @@
 
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @addtogroup PJSIP_MSG_HDR_GEN_INT Header Field: Generic Integer
- * @brief Generic header field which contains header name and value.
- * @ingroup PJSIP_MSG
- * @{
- */
+
+///////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -965,24 +955,23 @@
 							    int value );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_GENERIC_LIST Header Field: Generic string list.
- * @brief Header with list of strings separated with comma
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 
 /** Maximum elements in the header array. */
 #define PJSIP_GENERIC_ARRAY_MAX_COUNT	32
 
+/**
+ * Generic array of string header.
+ */
 typedef struct pjsip_generic_array_hdr
 {
+    /** Standard header fields. */
     PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr);
-    unsigned	count;					/**< Number of elements. */
-    pj_str_t	values[PJSIP_GENERIC_ARRAY_MAX_COUNT];	/**< Elements.		 */
+
+    /** Number of tags/elements. */
+    unsigned	count;
+
+    /**< Tags/elements. */
+    pj_str_t	values[PJSIP_GENERIC_ARRAY_MAX_COUNT];
+
 } pjsip_generic_array_hdr;
 
@@ -1019,15 +1008,6 @@
 
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_ACCEPT Header Field: Accept
- * @brief Accept header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
+
 /** Accept header. */
 typedef pjsip_generic_array_hdr pjsip_accept_hdr;
@@ -1062,14 +1042,9 @@
 						  void *mem );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_ALLOW Header Field: Allow
- * @brief Allow header field.
- * @ingroup PJSIP_MSG
- * @{
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Allow header.
  */
 typedef pjsip_generic_array_hdr pjsip_allow_hdr;
@@ -1103,15 +1078,6 @@
 						void *mem );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_CID Header Field: Call-ID
- * @brief Call-ID header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
+
 /**
  * Call-ID header.
@@ -1152,15 +1118,6 @@
 
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_CLEN Header Field: Content-Length
- * @brief Content-Length header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+
+///////////////////////////////////////////////////////////////////////////////
 /**
  * Content-Length header.
@@ -1198,15 +1155,5 @@
 
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_CSEQ Header Field: CSeq
- * @brief CSeq header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 /**
  * CSeq header.
@@ -1244,15 +1191,5 @@
 					      void *mem );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_CONTACT Header Field: Contact
- * @brief Contact header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 /**
  * Contact header.
@@ -1297,15 +1234,6 @@
 						    void *mem );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_CTYPE Header Field: Content-Type
- * @brief Content-Type header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+
+///////////////////////////////////////////////////////////////////////////////
 /**
  * Content-Type.
@@ -1343,15 +1271,5 @@
 						void *mem );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_EXPIRES Header Field: Expires
- * @brief Expires header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 /** Expires header. */
 typedef pjsip_generic_int_hdr pjsip_expires_hdr;
@@ -1388,15 +1306,6 @@
 
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_FROMTO Header Field: From/To
- * @brief From and To header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+
+///////////////////////////////////////////////////////////////////////////////
 /**
  * To or From header.
@@ -1469,6 +1378,6 @@
  * Convert the header to a From header.
  *
- * @param pool	The pool.
- * @return	"From" header.
+ * @param hdr	    The generic from/to header.
+ * @return	    "From" header.
  */
 PJ_DECL(pjsip_from_hdr*) pjsip_fromto_hdr_set_from( pjsip_fromto_hdr *hdr );
@@ -1477,20 +1386,13 @@
  * Convert the header to a To header.
  *
- * @param pool	The pool.
- * @return	"To" header.
+ * @param hdr	    The generic from/to header.
+ * @return	    "To" header.
  */
 PJ_DECL(pjsip_to_hdr*)   pjsip_fromto_hdr_set_to( pjsip_fromto_hdr *hdr );
 
-/**
- * @}
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_MAX_FORWARDS Header Field: Max-Forwards
- * @brief Max-Forwards header field.
- * @ingroup PJSIP_MSG
- * @{
+
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Max-Forwards header.
  */
 typedef pjsip_generic_int_hdr pjsip_max_fwd_hdr;
@@ -1526,15 +1428,8 @@
 pjsip_max_fwd_hdr_init( pj_pool_t *pool, void *mem, int value );
 
-/**
- * @}
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_MIN_EXPIRES Header Field: Min-Expires
- * @brief Min-Expires header field.
- * @ingroup PJSIP_MSG
- * @{
+
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Min-Expires header.
  */
 typedef pjsip_generic_int_hdr pjsip_min_expires_hdr;
@@ -1571,16 +1466,6 @@
 							    int value );
 
-/**
- * @}
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_ROUTING Header Field: Record-Route/Route
- * @brief Record-Route and Route header fields.
- * @ingroup PJSIP_MSG
- * @{
- */
+
+///////////////////////////////////////////////////////////////////////////////
 /**
  * Record-Route and Route headers.
@@ -1590,5 +1475,5 @@
     PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr);  /**< Generic header fields. */
     pjsip_name_addr  name_addr;	  /**< The URL in the Route/Record-Route header. */
-    pjsip_param	     other_param; /** Other parameter. */
+    pjsip_param	     other_param; /**< Other parameter. */
 } pjsip_routing_hdr;
 
@@ -1666,14 +1551,7 @@
 PJ_DECL(pjsip_route_hdr*)   pjsip_routing_hdr_set_route( pjsip_routing_hdr *r );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_REQUIRE Header Field: Require
- * @brief Require header field.
- * @ingroup PJSIP_MSG
- * @{
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Require header.
  */
 typedef pjsip_generic_array_hdr pjsip_require_hdr;
@@ -1705,15 +1583,8 @@
 						    void *mem );
 
-/**
- * @}
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_RETRY_AFTER Header Field: Retry-After
- * @brief Retry-After header field.
- * @ingroup PJSIP_MSG
- * @{
+
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Retry-After header.
  */
 typedef pjsip_generic_int_hdr pjsip_retry_after_hdr;
@@ -1745,14 +1616,7 @@
 
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_SUPPORTED Header Field: Supported
- * @brief Supported header field.
- * @ingroup PJSIP_MSG
- * @{
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Supported header.
  */
 typedef pjsip_generic_array_hdr pjsip_supported_hdr;
@@ -1779,14 +1643,7 @@
 							void *mem );
 
-/**
- * @}
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_UNSUPPORTED Header Field: Unsupported
- * @brief Unsupported header field.
- * @ingroup PJSIP_MSG
- * @{
+///////////////////////////////////////////////////////////////////////////////
+/**
+ * Unsupported header.
  */
 typedef pjsip_generic_array_hdr pjsip_unsupported_hdr;
@@ -1813,16 +1670,5 @@
 							    void *mem );
 
-/**
- * @}
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_VIA Header Field: Via
- * @brief Via header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 /**
  * SIP Via header.
@@ -1866,16 +1712,5 @@
 					    void *mem );
 
-/**
- * @}
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_WARNING Header Field: Warning
- * @brief Warning header field.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 /**
  * SIP Warning header.
@@ -1918,23 +1753,5 @@
 				      pj_status_t status);
 
-/**
- * @}
- */
-
-/**
- * @bug Once a header is put in the message, the header CAN NOT be put in
- *      other list. Solution:
- *	- always clone header in the message.
- *	- create a list node for each header in the message.
- */
-
-
-///////////////////////////////////////////////////////////////////////////////
-/**
- * @defgroup PJSIP_MSG_HDR_UNIMP Unimplemented Header Fields
- * @brief Unimplemented header fields.
- * @ingroup PJSIP_MSG
- * @{
- */
+///////////////////////////////////////////////////////////////////////////////
 /** Accept-Encoding header. */
 typedef pjsip_generic_string_hdr pjsip_accept_encoding_hdr;
Index: pjproject/trunk/pjsip/include/pjsip/sip_parser.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_parser.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_parser.h	(revision 515)
@@ -32,6 +32,7 @@
 
 /**
- * @defgroup PJSIP_PARSER SIP Message Parser
- * @ingroup PJSIP
+ * @defgroup PJSIP_PARSER Parser
+ * @ingroup PJSIP_MSG
+ * @brief Message and message elements parsing.
  * @{
  */
@@ -67,4 +68,5 @@
 typedef struct pjsip_parser_err_report
 {
+    /** Standard header fields. */
     PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report);
     int		except_code;	/**< Error exception (e.g. PJSIP_SYN_ERR_EXCEPTION) */
@@ -135,4 +137,5 @@
  * @param hname		The header name registered.
  * @param hshortname	The short header name registered, or NULL.
+ * @param fptr		Previously registered function to parse the header.
  *
  * @return		zero if unregistration was successfull.
@@ -186,5 +189,5 @@
 PJ_DECL(pjsip_uri*) pjsip_parse_uri( pj_pool_t *pool, 
 				     char *buf, pj_size_t size,
-				     unsigned option);
+				     unsigned options);
 
 /**
@@ -238,4 +241,5 @@
  * @param buf		The input buffer, which must be NULL terminated.
  * @param size		The buffer size.
+ * @param is_datagram	Put non-zero if transport is datagram oriented.
  * @param msg_size	[out] If message is valid, this parameter will contain
  *			the size of the SIP message (including body, if any).
@@ -279,15 +283,22 @@
  * however is optional for the last header.
  *
- * @param pool the pool.
- * @param buf the input text to parse.
- * @param size the text length.
- * @param hlist the header list to store the parsed headers. This list must
- *              have been initialized before calling this function.
- * @return zero if successfull, or -1 if error is encountered. Upon error,
- *              the \a hlist argument MAY contain successfully parsed headers.
+ * @param pool		the pool.
+ * @param input		the input text to parse.
+ * @param size		the text length.
+ * @param hlist		the header list to store the parsed headers. 
+ *			This list must have been initialized before calling 
+ *			this function.
+ * @return		zero if successfull, or -1 if error is encountered. 
+ *			Upon error, the \a hlist argument MAY contain 
+ *			successfully parsed headers.
  */
 PJ_DECL(pj_status_t) pjsip_parse_headers( pj_pool_t *pool,
 					  char *input, pj_size_t size,
 					  pj_list *hlist );
+
+
+/**
+ * @}
+ */
 
 
@@ -317,18 +328,20 @@
  * Various string constants.
  */
-extern const pj_str_t pjsip_USER_STR,
-		      pjsip_METHOD_STR,
-		      pjsip_TRANSPORT_STR,
-		      pjsip_MADDR_STR,
-		      pjsip_LR_STR,
-		      pjsip_SIP_STR,
-		      pjsip_SIPS_STR,
-		      pjsip_TEL_STR,
-		      pjsip_BRANCH_STR,
-		      pjsip_TTL_STR,
-		      pjsip_PNAME_STR,
-		      pjsip_Q_STR,
-		      pjsip_EXPIRES_STR,
-		      pjsip_TAG_STR;
+extern const pj_str_t pjsip_USER_STR,	    /**< "user" string constant.    */
+		      pjsip_METHOD_STR,	    /**< "method" string constant   */
+		      pjsip_TRANSPORT_STR,  /**< "transport" string const.  */
+		      pjsip_MADDR_STR,	    /**< "maddr" string const.	    */
+		      pjsip_LR_STR,	    /**< "lr" string const.	    */
+		      pjsip_SIP_STR,	    /**< "sip" string constant.	    */
+		      pjsip_SIPS_STR,	    /**< "sips" string constant.    */
+		      pjsip_TEL_STR,	    /**< "tel" string constant.	    */
+		      pjsip_BRANCH_STR,	    /**< "branch" string constant.  */
+		      pjsip_TTL_STR,	    /**< "ttl" string constant.	    */
+		      pjsip_RECEIVED_STR,   /**< "received" string const.   */
+		      pjsip_Q_STR,	    /**< "q" string constant.	    */
+		      pjsip_EXPIRES_STR,    /**< "expires" string constant. */
+		      pjsip_TAG_STR,	    /**< "tag" string constant.	    */
+		      pjsip_RPORT_STR;	    /**< "rport" string const.	    */
+
 
 /*
@@ -347,8 +360,4 @@
 void pjsip_parse_end_hdr_imp ( pj_scanner *scanner );
 
-/**
- * @}
- */
-
 PJ_END_DECL
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_private.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_private.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_private.h	(revision 515)
@@ -27,19 +27,4 @@
 #include <pjsip/sip_types.h>
 
-PJ_BEGIN_DECL
-
-/**
- * @defgroup PJSIP_PRIVATE Private structures and functions (PJSIP internals)
- * @ingroup PJSIP
- * @{
- */
-
-
-
-/** 
- * @}
- */
-
-PJ_END_DECL
 
 #endif /* __PJSIP_PRIVATE_I_H__ */
Index: pjproject/trunk/pjsip/include/pjsip/sip_resolve.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_resolve.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_resolve.h	(revision 515)
@@ -33,7 +33,12 @@
 
 /**
- * @defgroup PJSIP_RESOLVE SIP Server Resolver
- * @ingroup PJSIP
+ * @defgroup PJSIP_RESOLVE Server Resolution
+ * @ingroup PJSIP_TRANSPORT
+ * @brief Framework to resolve SIP servers based on RFC 3263.
  * @{
+ * This is the server resolution framework, which is modelled after 
+ * RFC 3263 - Locating SIP Servers document. The server resolution
+ * framework is asynchronous; callback will be called once the server 
+ * address has been resolved (successfully or with errors).
  */
 
@@ -43,10 +48,8 @@
 #define PJSIP_MAX_RESOLVED_ADDRESSES	8
 
-typedef struct pjsip_server_addresses pjsip_server_addresses;
-
 /**
  * The server addresses returned by the resolver.
  */
-struct pjsip_server_addresses
+typedef struct pjsip_server_addresses
 {
     /** Number of address records. */
@@ -67,5 +70,6 @@
     } entry[PJSIP_MAX_RESOLVED_ADDRESSES];
 
-};
+} pjsip_server_addresses;
+
 
 /**
Index: pjproject/trunk/pjsip/include/pjsip/sip_tel_uri.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_tel_uri.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_tel_uri.h	(revision 515)
@@ -26,4 +26,11 @@
 
 #include <pjsip/sip_uri.h>
+
+/**
+ * @addtogroup PJSIP_TEL_URI tel URI Scheme
+ * @ingroup PJSIP_URI
+ * @brief Support for "tel:" URI scheme.
+ * @{
+ */
 
 
@@ -69,3 +76,8 @@
 
 
+/**
+ * @}
+ */
+
+
 #endif	/* __PJSIP_TEL_URI_H__ */
Index: pjproject/trunk/pjsip/include/pjsip/sip_transaction.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_transaction.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_transaction.h	(revision 515)
@@ -32,7 +32,26 @@
 
 /**
- * @defgroup PJSIP_TRANSACT SIP Transaction
+ * @defgroup PJSIP_TRANSACT Transaction Layer
  * @ingroup PJSIP
+ * @brief Provides statefull message processing.
+ *
+ * This module provides stateful processing to incoming or outgoing SIP
+ * messages. 
+ * Before performing any stateful operations, application must register the
+ * transaction layer module by calling #pjsip_tsx_layer_init_module().
+ *
+ * Application should link with <b>pjsip-core</b> library to
+ * use the transaction layer.
+ */
+
+/**
+ * @defgroup PJSIP_TRANSACT_TRANSACTION Transaction
+ * @ingroup PJSIP_TRANSACT
+ * @brief Transaction instance for all types of SIP transactions.
  * @{
+ * The pjsip_transaction describes SIP transaction, and is used for
+ * both INVITE and non-INVITE, UAC or UAS. Application must register the
+ * transaction layer module with #pjsip_tsx_layer_init_module() before
+ * performing any stateful operations.
  */
 
@@ -258,5 +277,5 @@
  */
 PJ_DECL(pj_status_t) pjsip_tsx_terminate( pjsip_transaction *tsx,
-					  int st_code );
+					  int code );
 
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_transport.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_transport.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_transport.h	(revision 515)
@@ -35,10 +35,15 @@
 
 /**
- * @defgroup PJSIP_TRANSPORT SIP Transport
- * @ingroup PJSIP
- *
- * This is the low-level transport layer. Application normally won't need to 
- * use this function, but instead can use transaction or higher layer API to
- * send and receive messages.
+ * @defgroup PJSIP_TRANSPORT Transport
+ * @ingroup PJSIP_CORE
+ * @brief This is the transport framework.
+ *
+ * The transport framework is fully extensible. Please see
+ * <A HREF="/docs.htm">PJSIP Developer's Guide</A> PDF
+ * document for more information.
+ *
+ * Application MUST register at least one transport to PJSIP before any
+ * messages can be sent or received. Please see @ref PJSIP_TRANSPORT_UDP
+ * on how to create/register UDP transport to the transport framework.
  *
  * @{
@@ -138,6 +143,6 @@
 typedef struct pjsip_rx_data_op_key
 {
-    pj_ioqueue_op_key_t		op_key;
-    pjsip_rx_data	       *rdata;
+    pj_ioqueue_op_key_t		op_key;	/**< ioqueue op_key.		*/
+    pjsip_rx_data	       *rdata;	/**< rdata associated with this */
 } pjsip_rx_data_op_key;
 
@@ -304,7 +309,16 @@
 typedef struct pjsip_tx_data_op_key
 {
+    /** ioqueue pending operation key. */
     pj_ioqueue_op_key_t	    key;
+
+    /** Transmit data associated with this key. */
     pjsip_tx_data	   *tdata;
+
+    /** Arbitrary token (attached by transport) */
     void		   *token;
+
+    /** Callback to be called when pending transmit operation has
+        completed.
+     */
     void		  (*callback)(pjsip_transport*,void*,pj_ssize_t);
 } pjsip_tx_data_op_key;
@@ -377,4 +391,6 @@
     /** Transport manager internal. */
     void		*token;
+
+    /** Callback to be called when this tx_data has been transmitted.	*/
     void	       (*cb)(void*, pjsip_tx_data*, pj_ssize_t);
 
@@ -593,16 +609,16 @@
 struct pjsip_tpfactory
 {
-    /* This list is managed by transport manager. */
+    /** This list is managed by transport manager. */
     PJ_DECL_LIST_MEMBER(struct pjsip_tpfactory);
 
-    pj_pool_t		   *pool;
-    pj_lock_t		   *lock;
-
-    pjsip_transport_type_e  type;
-    char		    type_name[8];
-    unsigned		    flag;
-
-    pj_sockaddr		    local_addr;
-    pjsip_host_port	    addr_name;
+    pj_pool_t		   *pool;	    /**< Owned memory pool.	*/
+    pj_lock_t		   *lock;	    /**< Lock object.		*/
+
+    pjsip_transport_type_e  type;	    /**< Transport type.	*/
+    char		    type_name[8];   /**< Type string name.	*/
+    unsigned		    flag;	    /**< Transport flag.	*/
+
+    pj_sockaddr		    local_addr;	    /**< Bound address.		*/
+    pjsip_host_port	    addr_name;	    /**< Published name.	*/
 
     /**
@@ -629,5 +645,5 @@
  *
  * @param mgr		The transport manager.
- * @param factory	Transport factory.
+ * @param tpf		Transport factory.
  *
  * @return		PJ_SUCCESS if listener was successfully created.
@@ -638,4 +654,9 @@
 /**
  * Unregister factory.
+ *
+ * @param mgr		The transport manager.
+ * @param tpf		Transport factory.
+ *
+ * @return		PJ_SUCCESS is sucessfully unregistered.
  */
 PJ_DECL(pj_status_t) pjsip_tpmgr_unregister_tpfactory(pjsip_tpmgr *mgr,
Index: pjproject/trunk/pjsip/include/pjsip/sip_transport_loop.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_transport_loop.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_transport_loop.h	(revision 515)
@@ -20,5 +20,23 @@
 #define __PJSIP_TRANSPORT_LOOP_H__
 
+
+/**
+ * @file sip_transport_loop.h
+ * @brief 
+ * Loopback transport (for debugging)
+ */
+
+
 #include <pjsip/sip_transport.h>
+
+/**
+ * @defgroup PJSIP_TRANSPORT_LOOP Loop Transport
+ * @ingroup PJSIP_TRANSPORT
+ * @brief Loopback transport (for testing purposes).
+ * @{
+ * The loopback transport simply bounce back outgoing messages as
+ * incoming messages. This feature is used mostly during automated
+ * testing, to provide controlled behavior.
+ */
 
 PJ_BEGIN_DECL
@@ -121,4 +139,7 @@
 PJ_END_DECL
 
+/**
+ * @}
+ */
 
 #endif	/* __PJSIP_TRANSPORT_LOOP_H__ */
Index: pjproject/trunk/pjsip/include/pjsip/sip_transport_udp.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_transport_udp.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_transport_udp.h	(revision 515)
@@ -1,3 +1,3 @@
-/* $Id: $ */
+/* $Id$ */
 /* 
  * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
@@ -20,7 +20,21 @@
 #define __PJSIP_TRANSPORT_UDP_H__
 
+/**
+ * @file sip_transport_udp.h
+ * @brief SIP UDP Transport.
+ */
+
 #include <pjsip/sip_transport.h>
 
 PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJSIP_TRANSPORT_UDP UDP transport
+ * @ingroup PJSIP_TRANSPORT
+ * @brief API to create and register UDP transport.
+ * @{
+ * The functions below are used to create UDP transport and register 
+ * the transport to the framework.
+ */
 
 /**
@@ -68,4 +82,7 @@
 PJ_END_DECL
 
+/**
+ * @}
+ */
 
 #endif	/* __PJSIP_TRANSPORT_UDP_H__ */
Index: pjproject/trunk/pjsip/include/pjsip/sip_types.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_types.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_types.h	(revision 515)
@@ -20,14 +20,37 @@
 #define __PJSIP_SIP_TYPES_H__
 
+
+/*
+ * My note: Doxygen PJSIP and PJSIP_CORE group is declared in
+ *          sip_config.h
+ */
+
+/**
+ * @file sip_types.h
+ * @brief Basic PJSIP types.
+ */
+
 #include <pjsip/sip_config.h>
 #include <pj/types.h>
 
 /**
- * Opaque data structure for transports (sip_transport.h).
+ * @addtogroup PJSIP_BASE
+ */
+
+/* @defgroup PJSIP_TYPES Basic Data Types
+ * @ingroup PJSIP_BASE
+ * @brief Basic data types.
+ * @{
+ */
+
+
+
+/**
+ * Forward declaration for SIP transport.
  */
 typedef struct pjsip_transport pjsip_transport;
 
 /**
- * Opaque data type for transport manager (sip_transport.h).
+ * Forward declaration for transport manager.
  */
 typedef struct pjsip_tpmgr pjsip_tpmgr;
@@ -218,4 +241,9 @@
 #define PJSIP_THROW_SPEC(list)
 
+
+/**
+ * @}
+ */
+
 #endif	/* __PJSIP_SIP_TYPES_H__ */
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_ua_layer.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_ua_layer.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_ua_layer.h	(revision 515)
@@ -30,13 +30,24 @@
 
 /**
- * @defgroup PJSUA SIP User Agent Stack
+ * @defgroup PJSIP_UA Base User Agent Layer/Common Dialog Layer
+ * @ingroup PJSIP
+ * @brief Dialog management.
+ *
+ * This module provides basic dialog management, which is used by higher
+ * layer dialog usages such as INVITE sessions and SIP Event Subscription
+ * framework (RFC 3265). Application should link  with <b>pjsip-core</b> 
+ * library to use this base UA layer. The base UA layer module is initialized
+ * with #pjsip_ua_init_module().
  */
 
 /**
  * @defgroup PJSUA_UA SIP User Agent Module
- * @ingroup PJSUA
+ * @ingroup PJSIP_UA
+ * @brief Provides dialog management.
  * @{
- * \brief
- *   User Agent manages the interactions between application and SIP dialogs.
+ *
+ * Application MUST initialize the user agent layer module by calling
+ * #pjsip_ua_init_module() before using any of the dialog API, and link
+ * the application with with <b>pjsip-core</b> library.
  */
 
@@ -44,4 +55,7 @@
 typedef struct pjsip_ua_init_param
 {
+    /** Callback to be called when the UA layer detects that outgoing
+     *  dialog has forked.
+     */
     pjsip_dialog* (*on_dlg_forked)(pjsip_dialog *first_set, pjsip_rx_data *res);
 } pjsip_ua_init_param;
@@ -91,4 +105,9 @@
 
 
+/**
+ * @}
+ */
+
+
 /*
  * Internal (called by sip_dialog.c).
@@ -101,8 +120,4 @@
 
 
-/**
- * @}
- */
-
 PJ_END_DECL
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_uri.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_uri.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_uri.h	(revision 515)
@@ -34,7 +34,13 @@
 
 /**
- * @defgroup PJSIP_URL URL Structures
- * @brief SIP Url, tel: Url, and generic URI.
+ * @defgroup PJSIP_URI URI
+ * @brief URI types and manipulations.
  * @ingroup PJSIP_MSG
+ */
+
+/**
+ * @addtogroup PJSIP_URI_PARAM URI Parameter Container
+ * @ingroup PJSIP_URI
+ * @brief Generic parameter elements container.
  * @{
  */
@@ -118,4 +124,15 @@
 					 const pj_cis_t *pvalue_unres,
 					 int sep);
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup PJSIP_URI_GENERIC Generic URI
+ * @ingroup PJSIP_URI
+ * @brief Generic representation for all types of URI.
+ * @{
+ */
 
 /**
@@ -220,4 +237,83 @@
 #define PJSIP_URI_SCHEME_IS_TEL(url)	\
     (pj_strnicmp2(pjsip_uri_get_scheme(url), "tel", 3)==0)
+
+
+/**
+ * Generic function to get the URI scheme.
+ * @param uri	    the URI object.
+ * @return	    the URI scheme.
+ */
+PJ_INLINE(const pj_str_t*) pjsip_uri_get_scheme(const void *uri)
+{
+    return (*((pjsip_uri*)uri)->vptr->p_get_scheme)(uri);
+}
+
+/**
+ * Generic function to get the URI object contained by this URI, or the URI 
+ * itself if it doesn't contain another URI.
+ *
+ * @param uri	    the URI.
+ * @return	    the URI.
+ */
+PJ_INLINE(void*) pjsip_uri_get_uri(void *uri)
+{
+    return (*((pjsip_uri*)uri)->vptr->p_get_uri)(uri);
+}
+
+/**
+ * Generic function to compare two URIs.
+ *
+ * @param context   Comparison context.
+ * @param uri1	    The first URI.
+ * @param uri2	    The second URI.
+ * @return	    PJ_SUCCESS if equal, or otherwise the error status which
+ *		    should point to the mismatch part.
+ */
+PJ_INLINE(pj_status_t) pjsip_uri_cmp(pjsip_uri_context_e context, 
+				     const void *uri1, const void *uri2)
+{
+    return (*((const pjsip_uri*)uri1)->vptr->p_compare)(context, uri1, uri2);
+}
+
+/**
+ * Generic function to print an URI object.
+ *
+ * @param context   Print context.
+ * @param uri	    The URI to print.
+ * @param buf	    The buffer.
+ * @param size	    Size of the buffer.
+ * @return	    Length printed.
+ */
+PJ_INLINE(int) pjsip_uri_print(pjsip_uri_context_e context,
+			       const void *uri,
+			       char *buf, pj_size_t size)
+{
+    return (*((const pjsip_uri*)uri)->vptr->p_print)(context, uri, buf, size);
+}
+
+/**
+ * Generic function to clone an URI object.
+ *
+ * @param pool	    Pool.
+ * @param uri	    URI to clone.
+ * @return	    New URI.
+ */
+PJ_INLINE(void*) pjsip_uri_clone( pj_pool_t *pool, const void *uri )
+{
+    return (*((const pjsip_uri*)uri)->vptr->p_clone)(pool, uri);
+}
+
+
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup PJSIP_SIP_URI SIP URI Scheme and Name address
+ * @ingroup PJSIP_URI
+ * @brief SIP URL structure ("sip:" and "sips:")
+ * @{
+ */
 
 
@@ -262,70 +358,4 @@
 
 /**
- * Generic function to get the URI scheme.
- * @param uri	    the URI object.
- * @return	    the URI scheme.
- */
-PJ_INLINE(const pj_str_t*) pjsip_uri_get_scheme(const void *uri)
-{
-    return (*((pjsip_uri*)uri)->vptr->p_get_scheme)(uri);
-}
-
-/**
- * Generic function to get the URI object contained by this URI, or the URI 
- * itself if it doesn't contain another URI.
- *
- * @param uri	    the URI.
- * @return	    the URI.
- */
-PJ_INLINE(void*) pjsip_uri_get_uri(void *uri)
-{
-    return (*((pjsip_uri*)uri)->vptr->p_get_uri)(uri);
-}
-
-/**
- * Generic function to compare two URIs.
- *
- * @param context   Comparison context.
- * @param uri1	    The first URI.
- * @param uri2	    The second URI.
- * @return	    PJ_SUCCESS if equal, or otherwise the error status which
- *		    should point to the mismatch part.
- */
-PJ_INLINE(pj_status_t) pjsip_uri_cmp(pjsip_uri_context_e context, 
-				     const void *uri1, const void *uri2)
-{
-    return (*((const pjsip_uri*)uri1)->vptr->p_compare)(context, uri1, uri2);
-}
-
-/**
- * Generic function to print an URI object.
- *
- * @param context   Print context.
- * @param uri	    The URI to print.
- * @param buf	    The buffer.
- * @param size	    Size of the buffer.
- * @return	    Length printed.
- */
-PJ_INLINE(int) pjsip_uri_print(pjsip_uri_context_e context,
-			       const void *uri,
-			       char *buf, pj_size_t size)
-{
-    return (*((const pjsip_uri*)uri)->vptr->p_print)(context, uri, buf, size);
-}
-
-/**
- * Generic function to clone an URI object.
- *
- * @param pool	    Pool.
- * @param uri	    URI to clone.
- * @return	    New URI.
- */
-PJ_INLINE(void*) pjsip_uri_clone( pj_pool_t *pool, const void *uri )
-{
-    return (*((const pjsip_uri*)uri)->vptr->p_clone)(pool, uri);
-}
-
-
-/**
  * Create new SIP URL and initialize all fields with zero or NULL.
  * @param pool	    The pool.
@@ -345,4 +375,5 @@
  * Initialize SIP URL (all fields are set to NULL or zero).
  * @param url	    The URL.
+ * @param secure    Create sips URI?
  */
 PJ_DECL(void)  pjsip_sip_uri_init(pjsip_sip_uri *url, int secure);
Index: pjproject/trunk/pjsip/include/pjsip/sip_util.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_util.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip/sip_util.h	(revision 515)
@@ -26,6 +26,7 @@
 
 /**
- * @defgroup PJSIP_ENDPT SIP Endpoint
- * @ingroup PJSIP
+ * @defgroup PJSIP_ENDPT_STATELESS Message Creation and Stateless Operations
+ * @ingroup PJSIP_CORE_CORE
+ * @brief Utilities to create various messages and base function to send messages.
  * @{
  */
@@ -239,4 +240,8 @@
  * @param endpt	    The endpoint instance.
  * @param tdata	    The transmit data to be sent.
+ * @param token	    Arbitrary token to be given back on the callback.
+ * @param cb	    Optional callback to notify transmission status (also
+ *		    gives chance for application to discontinue retrying
+ *		    sending to alternate address).
  *
  * @return	    PJ_SUCCESS, or the appropriate error code.
@@ -350,4 +355,14 @@
 						   const pjsip_msg_body *body);
 						    
+/**
+ * @}
+ */
+
+/**
+ * @defgroup PJSIP_TRANSACT_UTIL Stateful Operations
+ * @ingroup PJSIP_TRANSACT
+ * @brief Utility function to send requests/responses statefully.
+ * @{
+ */
 
 /**
Index: pjproject/trunk/pjsip/include/pjsip_simple.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip_simple.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsip_simple.h	(revision 515)
@@ -19,5 +19,6 @@
 
 /**
- * @defgroup PJSIP_SIMPLE SIP Event, Instant Messaging and Presence Extension (SIMPLE)
+ * @defgroup PJSIP_SIMPLE Event and Presence Framework
+ * @ingroup PJSIP
  */
 
Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 514)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 515)
@@ -20,4 +20,10 @@
 #define __PJSUA_H__
 
+/**
+ * @file pjsua.h
+ * @brief PJSUA API.
+ */
+
+
 /* Include all PJSIP core headers. */
 #include <pjsip.h>
@@ -42,37 +48,149 @@
 
 
+/**
+ * @defgroup PJSUA_LIB PJSUA API
+ * @ingroup PJSIP
+ * @brief Very high level API for constructing SIP UA applications.
+ * @{
+ *
+ * PJSUA API is very high level API for constructing SIP user agent
+ * applications. It wraps together the signaling and media functionalities
+ * into an easy to use call API, provides account management, buddy
+ * management, presence, instant messaging, along with multimedia
+ * features such as conferencing, file streaming, local playback,
+ * voice recording, and so on.
+ *
+ * Application must link with <b>pjsua-lib</b> to use this API. In addition,
+ * this library depends on the following libraries:
+ *  - <b>pjsip-ua</b>, 
+ *  - <b>pjsip-simple</b>, 
+ *  - <b>pjsip-core</b>, 
+ *  - <b>pjmedia</b>,
+ *  - <b>pjmedia-codec</b>, 
+ *  - <b>pjlib-util</b>, and
+ *  - <b>pjlib</b>, 
+ *
+ * so application must also link with these libraries as well.
+ *
+ * @section root_using_pjsua_lib Using PJSUA API
+ *
+ * Please refer to @ref using_pjsua_lib on how to use PJSUA API.
+ */ 
+
 PJ_BEGIN_DECL
 
 
-/**
- * Max buddies in buddy list.
- */
-#ifndef PJSUA_MAX_BUDDIES
-#   define PJSUA_MAX_BUDDIES	    256
-#endif
-
-
-/**
- * Max simultaneous calls.
- */
-#ifndef PJSUA_MAX_CALLS
-#   define PJSUA_MAX_CALLS	    32
-#endif
-
-
-/**
- * Max ports in the conference bridge.
- */
-#ifndef PJSUA_MAX_CONF_PORTS
-#   define PJSUA_MAX_CONF_PORTS	    254
-#endif
-
-
-/**
- * Maximum accounts.
- */
-#ifndef PJSUA_MAX_ACC
-#   define PJSUA_MAX_ACC	    8
-#endif
+/** Forward declaration */
+typedef struct pjsua_media_config pjsua_media_config;
+
+
+/*****************************************************************************
+ * BASE API
+ */
+
+/**
+ * @defgroup PJSUA_LIB_BASE Base API
+ * @ingroup PJSUA_LIB
+ * @brief Basic application creation/initialization, logging configuration, etc.
+ * @{
+ *
+ * The base PJSUA API controls PJSUA creation, initialization, and startup, and
+ * also provides various auxiliary functions.
+ *
+ * @section using_pjsua_lib Using PJSUA Library
+ *
+ * @subsection creating_pjsua_lib Creating PJSUA
+ *
+ * Before anything else, application must create PJSUA by calling #pjsua_create().
+ * This, among other things, will initialize PJLIB, which is crucial before 
+ * any PJLIB functions can be called.
+ *
+ * @subsection init_pjsua_lib Initializing PJSUA
+ *
+ * After PJSUA is created, application can initialize PJSUA by calling
+ * #pjsua_init(). This function takes several configuration settings in the
+ * argument, so application normally would want to set these configuration
+ * before passing them to #pjsua_init().
+ *
+ * Sample code to initialize PJSUA:
+ \code
+
+    pjsua_config	 ua_cfg;
+    pjsua_logging_config log_cfg;
+    pjsua_media_config   media_cfg;
+
+    // Initialize configs with default settings.
+    pjsua_config_default(&ua_cfg);
+    pjsua_logging_config_default(&log_cfg);
+    pjsua_media_config_default(&media_cfg);
+
+    // At the very least, application would want to override
+    // the call callbacks in pjsua_config:
+    ua_cfg.cb.on_incoming_call = ...
+    ua_cfg.cb.on_call_state = ..
+    ...
+
+    // Customize other settings (or initialize them from application specific
+    // configuration file):
+    ...
+
+    // Initialize pjsua
+    status = pjsua_init(&ua_cfg, &log_cfg, &media_cfg);
+    if (status != PJ_SUCCESS) {
+          pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
+	  return status;
+    }
+    ..
+
+ \endcode
+ *
+ * @subsection other_init_pjsua_lib Other Initialization
+ *
+ * After PJSUA is initialized with #pjsua_init(), application will normally
+ * need/want to perform the following tasks:
+ *
+ *  - create SIP transport with #pjsua_transport_create(). Please see
+ *    @ref PJSUA_LIB_TRANSPORT section for more info.
+ *  - create one or more SIP accounts with #pjsua_acc_add() or
+ *    #pjsua_acc_add_local(). Please see @ref PJSUA_LIB_ACC for more info.
+ *  - add one or more buddies with #pjsua_buddy_add(). Please see
+ *    @ref PJSUA_LIB_BUDDY section for more info.
+ *  - optionally configure the sound device, codec settings, and other
+ *    media settings. Please see @ref PJSUA_LIB_MEDIA for more info.
+ *
+ *
+ * @subsection starting_pjsua_lib Starting PJSUA
+ *
+ * After all initializations have been done, application must call
+ * #pjsua_start() to start PJSUA. This function will check that all settings
+ * are properly configured, and apply default settings when it's not, or
+ * report error status when it is unable to recover from missing setting.
+ *
+ * Most settings can be changed during run-time. For example, application
+ * may add, modify, or delete accounts, buddies, or change media settings
+ * during run-time.
+ */
+
+/** Constant to identify invalid ID for all sorts of IDs. */
+#define PJSUA_INVALID_ID	    (-1)
+
+/** Call identification */
+typedef int pjsua_call_id;
+
+/** Account identification */
+typedef int pjsua_acc_id;
+
+/** Buddy identification */
+typedef int pjsua_buddy_id;
+
+/** File player identification */
+typedef int pjsua_player_id;
+
+/** File recorder identification */
+typedef int pjsua_recorder_id;
+
+/** Conference port identification */
+typedef int pjsua_conf_port_id;
+
 
 
@@ -83,429 +201,4 @@
 #   define PJSUA_ACC_MAX_PROXIES    8
 #endif
-
-/**
- * Default registration interval.
- */
-#ifndef PJSUA_REG_INTERVAL
-#   define PJSUA_REG_INTERVAL	    55
-#endif
-
-
-/** Account identification */
-typedef int pjsua_acc_id;
-
-/** Call identification */
-typedef int pjsua_call_id;
-
-/** SIP transport identification */
-typedef int pjsua_transport_id;
-
-/** Buddy identification */
-typedef int pjsua_buddy_id;
-
-/** File player identification */
-typedef int pjsua_player_id;
-
-/** File recorder identification */
-typedef int pjsua_recorder_id;
-
-/** Conference port identification */
-typedef int pjsua_conf_port_id;
-
-
-/** Constant to identify invalid ID for all sorts of IDs. */
-#define PJSUA_INVALID_ID	    (-1)
-
-
-
-/**
- * Account configuration.
- */
-typedef struct pjsua_acc_config
-{
-    /** 
-     * The full SIP URL for the account. The value can take name address or 
-     * URL format, and will look something like "sip:account@serviceprovider".
-     *
-     * This field is mandatory.
-     */
-    pj_str_t	    id;
-
-    /** 
-     * This is the URL to be put in the request URI for the registration,
-     * and will look something like "sip:serviceprovider".
-     *
-     * This field should be specified if registration is desired. If the
-     * value is empty, no account registration will be performed.
-     */
-    pj_str_t	    reg_uri;
-
-    /** 
-     * Optional URI to be put as Contact for this account. It is recommended
-     * that this field is left empty, so that the value will be calculated
-     * automatically based on the transport address.
-     */
-    pj_str_t	    contact;
-
-    /**
-     * Number of proxies in the proxy array below.
-     */
-    unsigned	    proxy_cnt;
-
-    /** 
-     * Optional URI of the proxies to be visited for all outgoing requests 
-     * that are using this account (REGISTER, INVITE, etc). Application need 
-     * to specify these proxies if the service provider requires that requests
-     * destined towards its network should go through certain proxies first
-     * (for example, border controllers).
-     *
-     * These proxies will be put in the route set for this account, with 
-     * maintaining the orders (the first proxy in the array will be visited
-     * first).
-     */
-    pj_str_t	    proxy[PJSUA_ACC_MAX_PROXIES];
-
-    /** 
-     * Optional interval for registration, in seconds. If the value is zero, 
-     * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds).
-     */
-    unsigned	    reg_timeout;
-
-    /** 
-     * Number of credentials in the credential array.
-     */
-    unsigned	    cred_count;
-
-    /** 
-     * Array of credentials. If registration is desired, normally there should
-     * be at least one credential specified, to successfully authenticate
-     * against the service provider. More credentials can be specified, for
-     * example when the requests are expected to be challenged by the
-     * proxies in the route set.
-     */
-    pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
-
-} pjsua_acc_config;
-
-
-/**
- * Call this function to initialize account config with default values.
- *
- * @param cfg	    The account config to be initialized.
- */
-PJ_INLINE(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
-{
-    pj_memset(cfg, 0, sizeof(*cfg));
-
-    cfg->reg_timeout = PJSUA_REG_INTERVAL;
-}
-
-
-
-/**
- * Account info. Application can query account info by calling 
- * #pjsua_acc_get_info().
- */
-typedef struct pjsua_acc_info
-{
-    /** 
-     * The account ID. 
-     */
-    pjsua_acc_id	id;
-
-    /**
-     * Flag to indicate whether this is the default account.
-     */
-    pj_bool_t		is_default;
-
-    /** 
-     * Account URI 
-     */
-    pj_str_t		acc_uri;
-
-    /** 
-     * Flag to tell whether this account has registration setting
-     * (reg_uri is not empty).
-     */
-    pj_bool_t		has_registration;
-
-    /**
-     * An up to date expiration interval for account registration session.
-     */
-    int			expires;
-
-    /**
-     * Last registration status code. If status code is zero, the account
-     * is currently not registered. Any other value indicates the SIP
-     * status code of the registration.
-     */
-    pjsip_status_code	status;
-
-    /**
-     * String describing the registration status.
-     */
-    pj_str_t		status_text;
-
-    /**
-     * Presence online status for this account.
-     */
-    pj_bool_t		online_status;
-
-    /**
-     * Buffer that is used internally to store the status text.
-     */
-    char		buf_[PJ_ERR_MSG_SIZE];
-
-} pjsua_acc_info;
-
-
-
-/**
- * STUN configuration.
- */
-typedef struct pjsua_stun_config
-{
-    /**
-     * The first STUN server IP address or hostname.
-     */
-    pj_str_t	stun_srv1;
-
-    /**
-     * Port number of the first STUN server.
-     * If zero, default STUN port will be used.
-     */
-    unsigned	stun_port1;
-    
-    /**
-     * Optional second STUN server IP address or hostname, for which the
-     * result of the mapping request will be compared to. If the value
-     * is empty, only one STUN server will be used.
-     */
-    pj_str_t	stun_srv2;
-
-    /**
-     * Port number of the second STUN server.
-     * If zero, default STUN port will be used.
-     */
-    unsigned	stun_port2;
-
-} pjsua_stun_config;
-
-
-
-/**
- * Call this function to initialize STUN config with default values.
- *
- * @param cfg	    The STUN config to be initialized.
- */
-PJ_INLINE(void) pjsua_stun_config_default(pjsua_stun_config *cfg)
-{
-    pj_memset(cfg, 0, sizeof(*cfg));
-}
-
-
-/**
- * Transport configuration for creating UDP transports for both SIP
- * and media.
- */
-typedef struct pjsua_transport_config
-{
-    /**
-     * UDP port number to bind locally. This setting MUST be specified
-     * even when default port is desired. If the value is zero, the
-     * transport will be bound to any available port, and application
-     * can query the port by querying the transport info.
-     */
-    unsigned		port;
-
-    /**
-     * Optional address where the socket should be bound.
-     */
-    pj_in_addr		ip_addr;
-
-    /**
-     * Flag to indicate whether STUN should be used.
-     */
-    pj_bool_t		use_stun;
-
-    /**
-     * STUN configuration, must be specified when STUN is used.
-     */
-    pjsua_stun_config	stun_config;
-
-} pjsua_transport_config;
-
-
-/**
- * Call this function to initialize UDP config with default values.
- *
- * @param cfg	    The UDP config to be initialized.
- */
-PJ_INLINE(void) pjsua_transport_config_default(pjsua_transport_config *cfg)
-{
-    pj_memset(cfg, 0, sizeof(*cfg));
-}
-
-
-/**
- * Normalize STUN config.
- */
-PJ_INLINE(void) pjsua_normalize_stun_config( pjsua_stun_config *cfg )
-{
-    if (cfg->stun_srv1.slen) {
-
-	if (cfg->stun_port1 == 0)
-	    cfg->stun_port1 = 3478;
-
-	if (cfg->stun_srv2.slen == 0) {
-	    cfg->stun_srv2 = cfg->stun_srv1;
-	    cfg->stun_port2 = cfg->stun_port1;
-	} else {
-	    if (cfg->stun_port2 == 0)
-		cfg->stun_port2 = 3478;
-	}
-
-    } else {
-	cfg->stun_port1 = 0;
-	cfg->stun_srv2.slen = 0;
-	cfg->stun_port2 = 0;
-    }
-}
-
-
-/**
- * Duplicate transport config.
- */
-PJ_INLINE(void) pjsua_transport_config_dup(pj_pool_t *pool,
-					   pjsua_transport_config *dst,
-					   const pjsua_transport_config *src)
-{
-    pj_memcpy(dst, src, sizeof(*src));
-
-    if (src->stun_config.stun_srv1.slen) {
-	pj_strdup_with_null(pool, &dst->stun_config.stun_srv1,
-			    &src->stun_config.stun_srv1);
-    }
-
-    if (src->stun_config.stun_srv2.slen) {
-	pj_strdup_with_null(pool, &dst->stun_config.stun_srv2,
-			    &src->stun_config.stun_srv2);
-    }
-
-    pjsua_normalize_stun_config(&dst->stun_config);
-}
-
-
-
-/**
- * Transport info.
- */
-typedef struct pjsua_transport_info
-{
-    /**
-     * PJSUA transport identification.
-     */
-    pjsua_transport_id	    id;
-
-    /**
-     * Transport type.
-     */
-    pjsip_transport_type_e  type;
-
-    /**
-     * Transport type name.
-     */
-    pj_str_t		    type_name;
-
-    /**
-     * Transport string info/description.
-     */
-    pj_str_t		    info;
-
-    /**
-     * Transport flag (see ##pjsip_transport_flags_e).
-     */
-    unsigned		    flag;
-
-    /**
-     * Local address length.
-     */
-    unsigned		    addr_len;
-
-    /**
-     * Local/bound address.
-     */
-    pj_sockaddr		    local_addr;
-
-    /**
-     * Published address (or transport address name).
-     */
-    pjsip_host_port	    local_name;
-
-    /**
-     * Current number of objects currently referencing this transport.
-     */
-    unsigned		    usage_count;
-
-
-} pjsua_transport_info;
-
-
-/**
- * Media configuration.
- */
-typedef struct pjsua_media_config
-{
-    /**
-     * Clock rate to be applied to the conference bridge.
-     * If value is zero, default clock rate will be used (16KHz).
-     */
-    unsigned		clock_rate;
-
-    /**
-     * Specify maximum number of media ports to be created in the
-     * conference bridge. Since all media terminate in the bridge
-     * (calls, file player, file recorder, etc), the value must be
-     * large enough to support all of them. However, the larger
-     * the value, the more computations are performed.
-     */
-    unsigned		max_media_ports;
-
-    /**
-     * Specify whether the media manager should manage its own
-     * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
-     * and at least one worker thread will be created too. If no,
-     * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
-     * and no worker thread is needed.
-     *
-     * Normally application would say yes here, unless it wants to
-     * run everything from a single thread.
-     */
-    pj_bool_t		has_ioqueue;
-
-    /**
-     * Specify the number of worker threads to handle incoming RTP
-     * packets. A value of one is recommended for most applications.
-     */
-    unsigned		thread_cnt;
-
-
-} pjsua_media_config;
-
-
-/**
- * Use this function to initialize media config.
- *
- * @param cfg	The media config to be initialized.
- */
-PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
-{
-    pj_memset(cfg, 0, sizeof(*cfg));
-
-    cfg->clock_rate = 16000;
-    cfg->max_media_ports = 32;
-    cfg->has_ioqueue = PJ_TRUE;
-    cfg->thread_cnt = 1;
-}
 
 
@@ -583,114 +276,4 @@
 }
 
-
-/**
- * Buddy configuration.
- */
-typedef struct pjsua_buddy_config
-{
-    /**
-     * Buddy URL or name address.
-     */
-    pj_str_t	uri;
-
-    /**
-     * Specify whether presence subscription should start immediately.
-     */
-    pj_bool_t	subscribe;
-
-} pjsua_buddy_config;
-
-
-/**
- * Buddy's online status.
- */
-typedef enum pjsua_buddy_status
-{
-    /**
-     * Online status is unknown (possibly because no presence subscription
-     * has been established).
-     */
-    PJSUA_BUDDY_STATUS_UNKNOWN,
-
-    /**
-     * Buddy is known to be offline.
-     */
-    PJSUA_BUDDY_STATUS_ONLINE,
-
-    /**
-     * Buddy is offline.
-     */
-    PJSUA_BUDDY_STATUS_OFFLINE,
-
-} pjsua_buddy_status;
-
-
-
-/**
- * Buddy info.
- */
-typedef struct pjsua_buddy_info
-{
-    /**
-     * The buddy ID.
-     */
-    pjsua_buddy_id	id;
-
-    /**
-     * The full URI of the buddy, as specified in the configuration.
-     */
-    pj_str_t		uri;
-
-    /**
-     * Buddy's Contact, only available when presence subscription has
-     * been established to the buddy.
-     */
-    pj_str_t		contact;
-
-    /**
-     * Buddy's online status.
-     */
-    pjsua_buddy_status	status;
-
-    /**
-     * Text to describe buddy's online status.
-     */
-    pj_str_t		status_text;
-
-    /**
-     * Flag to indicate that we should monitor the presence information for
-     * this buddy (normally yes, unless explicitly disabled).
-     */
-    pj_bool_t		monitor_pres;
-
-    /**
-     * Internal buffer.
-     */
-    char		buf_[256];
-
-} pjsua_buddy_info;
-
-
-/**
- * Codec config.
- */
-typedef struct pjsua_codec_info
-{
-    /**
-     * Codec unique identification.
-     */
-    pj_str_t		codec_id;
-
-    /**
-     * Codec priority (integer 0-255).
-     */
-    pj_uint8_t		priority;
-
-    /**
-     * Internal buffer.
-     */
-    char		buf_[32];
-
-} pjsua_codec_info;
 
 
@@ -889,4 +472,863 @@
 
 
+
+/**
+ * This structure describes additional information to be sent with
+ * outgoing SIP message.
+ */
+typedef struct pjsua_msg_data
+{
+    /**
+     * Additional message headers as linked list.
+     */
+    pjsip_hdr	hdr_list;
+
+    /**
+     * MIME type of optional message body. 
+     */
+    pj_str_t	content_type;
+
+    /**
+     * Optional message body.
+     */
+    pj_str_t	msg_body;
+
+} pjsua_msg_data;
+
+
+/**
+ * Initialize message data.
+ *
+ * @param msg_data  Message data to be initialized.
+ */
+PJ_INLINE(void) pjsua_msg_data_init(pjsua_msg_data *msg_data)
+{
+    pj_memset(msg_data, 0, sizeof(*msg_data));
+    pj_list_init(&msg_data->hdr_list);
+}
+
+
+
+/**
+ * Instantiate pjsua application. Application must call this function before
+ * calling any other functions, to make sure that the underlying libraries
+ * are properly initialized. Once this function has returned success,
+ * application must call pjsua_destroy() before quitting.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_create(void);
+
+
+/**
+ * Initialize pjsua with the specified settings. All the settings are 
+ * optional, and the default values will be used when the config is not
+ * specified.
+ *
+ * @param ua_cfg	User agent configuration.
+ * @param log_cfg	Optional logging configuration.
+ * @param media_cfg	Optional media configuration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
+				const pjsua_logging_config *log_cfg,
+				const pjsua_media_config *media_cfg);
+
+
+/**
+ * Application is recommended to call this function after all initialization
+ * is done, so that the library can do additional checking set up
+ * additional 
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_start(void);
+
+
+/**
+ * Destroy pjsua. This function must be called once PJSUA is created. To
+ * make it easier for application, application may call this function
+ * several times with no danger.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_destroy(void);
+
+
+/**
+ * Poll pjsua for events, and if necessary block the caller thread for
+ * the specified maximum interval (in miliseconds).
+ *
+ * @param msec_timeout	Maximum time to wait, in miliseconds.
+ *
+ * @return  The number of events that have been handled during the
+ *	    poll. Negative value indicates error, and application
+ *	    can retrieve the error as (err = -return_value).
+ */
+PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
+
+
+/**
+ * Create memory pool.
+ *
+ * @param name		Optional pool name.
+ * @param init_size	Initial size of the pool.
+ * @param increment	Increment size.
+ *
+ * @return		The pool, or NULL when there's no memory.
+ */
+PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
+				      pj_size_t increment);
+
+
+/**
+ * Application can call this function at any time (after pjsua_create(), of
+ * course) to change logging settings.
+ *
+ * @param c		Logging configuration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
+
+
+/**
+ * Internal function to get SIP endpoint instance of pjsua, which is
+ * needed for example to register module, create transports, etc.
+ * Probably is only valid after #pjsua_init() is called.
+ * 
+ * @return		SIP endpoint instance.
+ */
+PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
+
+/**
+ * Internal function to get media endpoint instance.
+ * Only valid after #pjsua_init() is called.
+ *
+ * @return		Media endpoint instance.
+ */
+PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
+
+
+/*****************************************************************************
+ * Utilities.
+ *
+ */
+
+/**
+ * Verify that valid SIP url is given.
+ *
+ * @param c_url		The URL, as NULL terminated string.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *c_url);
+
+
+/**
+ * Display error message for the specified error code.
+ *
+ * @param sender	The log sender field.
+ * @param title		Message title for the error.
+ * @param status	Status code.
+ */
+PJ_DECL(void) pjsua_perror(const char *sender, const char *title, 
+			   pj_status_t status);
+
+
+
+
+/**
+ * @}
+ */
+
+
+
+/*****************************************************************************
+ * TRANSPORT API
+ */
+
+/**
+ * @defgroup PJSUA_LIB_TRANSPORT Signaling Transport
+ * @ingroup PJSUA_LIB
+ * @brief API for managing SIP transports
+ * @{
+ * SIP transport must be created before adding an account. SIP transport is
+ * created by calling #pjsua_transport_create() function.
+ */
+
+
+/** SIP transport identification */
+typedef int pjsua_transport_id;
+
+
+/**
+ * STUN configuration.
+ */
+typedef struct pjsua_stun_config
+{
+    /**
+     * The first STUN server IP address or hostname.
+     */
+    pj_str_t	stun_srv1;
+
+    /**
+     * Port number of the first STUN server.
+     * If zero, default STUN port will be used.
+     */
+    unsigned	stun_port1;
+    
+    /**
+     * Optional second STUN server IP address or hostname, for which the
+     * result of the mapping request will be compared to. If the value
+     * is empty, only one STUN server will be used.
+     */
+    pj_str_t	stun_srv2;
+
+    /**
+     * Port number of the second STUN server.
+     * If zero, default STUN port will be used.
+     */
+    unsigned	stun_port2;
+
+} pjsua_stun_config;
+
+
+
+/**
+ * Call this function to initialize STUN config with default values.
+ *
+ * @param cfg	    The STUN config to be initialized.
+ */
+PJ_INLINE(void) pjsua_stun_config_default(pjsua_stun_config *cfg)
+{
+    pj_memset(cfg, 0, sizeof(*cfg));
+}
+
+
+/**
+ * Transport configuration for creating UDP transports for both SIP
+ * and media.
+ */
+typedef struct pjsua_transport_config
+{
+    /**
+     * UDP port number to bind locally. This setting MUST be specified
+     * even when default port is desired. If the value is zero, the
+     * transport will be bound to any available port, and application
+     * can query the port by querying the transport info.
+     */
+    unsigned		port;
+
+    /**
+     * Optional address where the socket should be bound.
+     */
+    pj_in_addr		ip_addr;
+
+    /**
+     * Flag to indicate whether STUN should be used.
+     */
+    pj_bool_t		use_stun;
+
+    /**
+     * STUN configuration, must be specified when STUN is used.
+     */
+    pjsua_stun_config	stun_config;
+
+} pjsua_transport_config;
+
+
+/**
+ * Call this function to initialize UDP config with default values.
+ *
+ * @param cfg	    The UDP config to be initialized.
+ */
+PJ_INLINE(void) pjsua_transport_config_default(pjsua_transport_config *cfg)
+{
+    pj_memset(cfg, 0, sizeof(*cfg));
+}
+
+
+/**
+ * Normalize STUN config.
+ */
+PJ_INLINE(void) pjsua_normalize_stun_config( pjsua_stun_config *cfg )
+{
+    if (cfg->stun_srv1.slen) {
+
+	if (cfg->stun_port1 == 0)
+	    cfg->stun_port1 = 3478;
+
+	if (cfg->stun_srv2.slen == 0) {
+	    cfg->stun_srv2 = cfg->stun_srv1;
+	    cfg->stun_port2 = cfg->stun_port1;
+	} else {
+	    if (cfg->stun_port2 == 0)
+		cfg->stun_port2 = 3478;
+	}
+
+    } else {
+	cfg->stun_port1 = 0;
+	cfg->stun_srv2.slen = 0;
+	cfg->stun_port2 = 0;
+    }
+}
+
+
+/**
+ * Duplicate transport config.
+ */
+PJ_INLINE(void) pjsua_transport_config_dup(pj_pool_t *pool,
+					   pjsua_transport_config *dst,
+					   const pjsua_transport_config *src)
+{
+    pj_memcpy(dst, src, sizeof(*src));
+
+    if (src->stun_config.stun_srv1.slen) {
+	pj_strdup_with_null(pool, &dst->stun_config.stun_srv1,
+			    &src->stun_config.stun_srv1);
+    }
+
+    if (src->stun_config.stun_srv2.slen) {
+	pj_strdup_with_null(pool, &dst->stun_config.stun_srv2,
+			    &src->stun_config.stun_srv2);
+    }
+
+    pjsua_normalize_stun_config(&dst->stun_config);
+}
+
+
+
+/**
+ * Transport info.
+ */
+typedef struct pjsua_transport_info
+{
+    /**
+     * PJSUA transport identification.
+     */
+    pjsua_transport_id	    id;
+
+    /**
+     * Transport type.
+     */
+    pjsip_transport_type_e  type;
+
+    /**
+     * Transport type name.
+     */
+    pj_str_t		    type_name;
+
+    /**
+     * Transport string info/description.
+     */
+    pj_str_t		    info;
+
+    /**
+     * Transport flag (see ##pjsip_transport_flags_e).
+     */
+    unsigned		    flag;
+
+    /**
+     * Local address length.
+     */
+    unsigned		    addr_len;
+
+    /**
+     * Local/bound address.
+     */
+    pj_sockaddr		    local_addr;
+
+    /**
+     * Published address (or transport address name).
+     */
+    pjsip_host_port	    local_name;
+
+    /**
+     * Current number of objects currently referencing this transport.
+     */
+    unsigned		    usage_count;
+
+
+} pjsua_transport_info;
+
+
+/**
+ * Create SIP transport.
+ *
+ * @param type		Transport type.
+ * @param cfg		Transport configuration.
+ * @param p_id		Optional pointer to receive transport ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
+					    const pjsua_transport_config *cfg,
+					    pjsua_transport_id *p_id);
+
+/**
+ * Register transport that has been created by application.
+ *
+ * @param tp		Transport instance.
+ * @param p_id		Optional pointer to receive transport ID.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
+					      pjsua_transport_id *p_id);
+
+
+/**
+ * Enumerate all transports currently created in the system.
+ *
+ * @param id		Array to receive transport ids.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
+					    unsigned *count );
+
+
+/**
+ * Get information about transports.
+ *
+ * @param id		Transport ID.
+ * @param info		Pointer to receive transport info.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
+					      pjsua_transport_info *info);
+
+
+/**
+ * Disable a transport or re-enable it. By default transport is always 
+ * enabled after it is created. Disabling a transport does not necessarily
+ * close the socket, it will only discard incoming messages and prevent
+ * the transport from being used to send outgoing messages.
+ *
+ * @param id		Transport ID.
+ * @param enabled	Non-zero to enable, zero to disable.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
+						pj_bool_t enabled);
+
+
+/**
+ * Close the transport. If transport is forcefully closed, it will be
+ * immediately closed, and any pending transactions that are using the
+ * transport may not terminate properly. Otherwise, the system will wait
+ * until all transactions are closed while preventing new users from
+ * using the transport, and will close the transport when it is safe to
+ * do so.
+ *
+ * @param id		Transport ID.
+ * @param force		Non-zero to immediately close the transport. This
+ *			is not recommended!
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
+					    pj_bool_t force );
+
+/**
+ * @}
+ */
+
+
+
+
+/*****************************************************************************
+ * ACCOUNT API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_ACC Account Management
+ * @ingroup PJSUA_LIB
+ * @brief PJSUA supports multiple accounts..
+ * @{
+ * PJSUA accounts provide identity (or identities) of the user who is currently
+ * using the application. More than one account maybe created with PJSUA.
+ *
+ * Account may or may not have client registration associated with it.
+ * An account is also associated with <b>route set</b> and some <b>authentication
+ * credentials</b>, which are used when sending SIP request messages using the
+ * account. An account also has presence's <b>online status</b>, which
+ * will be reported to remote peer when the subscribe to the account's
+ * presence.
+ *
+ * At least one account MUST be created in the application. If no user
+ * association is required, application can create a userless account by
+ * calling #pjsua_acc_add_local(). A userless account identifies local endpoint
+ * instead of a particular user.
+ *
+ * Also one account must be set as the <b>default account</b>, which is used as
+ * the account to use when PJSUA fails to match a request with any other
+ * accounts.
+ *
+ * When sending outgoing SIP requests (such as making calls or sending
+ * instant messages), normally PJSUA requires the application to specify
+ * which account to use for the request. If no account is specified,
+ * PJSUA may be able to select the account by matching the destination
+ * domain name, and fall back to default account when no match is found.
+ */
+
+/**
+ * Maximum accounts.
+ */
+#ifndef PJSUA_MAX_ACC
+#   define PJSUA_MAX_ACC	    8
+#endif
+
+
+/**
+ * Default registration interval.
+ */
+#ifndef PJSUA_REG_INTERVAL
+#   define PJSUA_REG_INTERVAL	    55
+#endif
+
+
+/**
+ * Account configuration.
+ */
+typedef struct pjsua_acc_config
+{
+    /** 
+     * The full SIP URL for the account. The value can take name address or 
+     * URL format, and will look something like "sip:account@serviceprovider".
+     *
+     * This field is mandatory.
+     */
+    pj_str_t	    id;
+
+    /** 
+     * This is the URL to be put in the request URI for the registration,
+     * and will look something like "sip:serviceprovider".
+     *
+     * This field should be specified if registration is desired. If the
+     * value is empty, no account registration will be performed.
+     */
+    pj_str_t	    reg_uri;
+
+    /** 
+     * Optional URI to be put as Contact for this account. It is recommended
+     * that this field is left empty, so that the value will be calculated
+     * automatically based on the transport address.
+     */
+    pj_str_t	    contact;
+
+    /**
+     * Number of proxies in the proxy array below.
+     */
+    unsigned	    proxy_cnt;
+
+    /** 
+     * Optional URI of the proxies to be visited for all outgoing requests 
+     * that are using this account (REGISTER, INVITE, etc). Application need 
+     * to specify these proxies if the service provider requires that requests
+     * destined towards its network should go through certain proxies first
+     * (for example, border controllers).
+     *
+     * These proxies will be put in the route set for this account, with 
+     * maintaining the orders (the first proxy in the array will be visited
+     * first).
+     */
+    pj_str_t	    proxy[PJSUA_ACC_MAX_PROXIES];
+
+    /** 
+     * Optional interval for registration, in seconds. If the value is zero, 
+     * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds).
+     */
+    unsigned	    reg_timeout;
+
+    /** 
+     * Number of credentials in the credential array.
+     */
+    unsigned	    cred_count;
+
+    /** 
+     * Array of credentials. If registration is desired, normally there should
+     * be at least one credential specified, to successfully authenticate
+     * against the service provider. More credentials can be specified, for
+     * example when the requests are expected to be challenged by the
+     * proxies in the route set.
+     */
+    pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
+
+} pjsua_acc_config;
+
+
+/**
+ * Call this function to initialize account config with default values.
+ *
+ * @param cfg	    The account config to be initialized.
+ */
+PJ_INLINE(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
+{
+    pj_memset(cfg, 0, sizeof(*cfg));
+
+    cfg->reg_timeout = PJSUA_REG_INTERVAL;
+}
+
+
+
+/**
+ * Account info. Application can query account info by calling 
+ * #pjsua_acc_get_info().
+ */
+typedef struct pjsua_acc_info
+{
+    /** 
+     * The account ID. 
+     */
+    pjsua_acc_id	id;
+
+    /**
+     * Flag to indicate whether this is the default account.
+     */
+    pj_bool_t		is_default;
+
+    /** 
+     * Account URI 
+     */
+    pj_str_t		acc_uri;
+
+    /** 
+     * Flag to tell whether this account has registration setting
+     * (reg_uri is not empty).
+     */
+    pj_bool_t		has_registration;
+
+    /**
+     * An up to date expiration interval for account registration session.
+     */
+    int			expires;
+
+    /**
+     * Last registration status code. If status code is zero, the account
+     * is currently not registered. Any other value indicates the SIP
+     * status code of the registration.
+     */
+    pjsip_status_code	status;
+
+    /**
+     * String describing the registration status.
+     */
+    pj_str_t		status_text;
+
+    /**
+     * Presence online status for this account.
+     */
+    pj_bool_t		online_status;
+
+    /**
+     * Buffer that is used internally to store the status text.
+     */
+    char		buf_[PJ_ERR_MSG_SIZE];
+
+} pjsua_acc_info;
+
+
+
+/**
+ * Get number of current accounts.
+ *
+ * @return		Current number of accounts.
+ */
+PJ_DECL(unsigned) pjsua_acc_get_count(void);
+
+
+/**
+ * Check if the specified account ID is valid.
+ *
+ * @param acc_id	Account ID to check.
+ *
+ * @return		Non-zero if account ID is valid.
+ */
+PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
+
+
+/**
+ * Add a new account to pjsua. PJSUA must have been initialized (with
+ * #pjsua_init()) before calling this function.
+ *
+ * @param cfg		Account configuration.
+ * @param is_default	If non-zero, this account will be set as the default
+ *			account. The default account will be used when sending
+ *			outgoing requests (e.g. making call) when no account is
+ *			specified, and when receiving incoming requests when the
+ *			request does not match any accounts. It is recommended
+ *			that default account is set to local/LAN account.
+ * @param p_acc_id	Pointer to receive account ID of the new account.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *cfg,
+				   pj_bool_t is_default,
+				   pjsua_acc_id *p_acc_id);
+
+
+/**
+ * Add a local account. A local account is used to identify local endpoint
+ * instead of a specific user, and for this reason, a transport ID is needed
+ * to obtain the local address information.
+ *
+ * @param tid		Transport ID to generate account address.
+ * @param is_default	If non-zero, this account will be set as the default
+ *			account. The default account will be used when sending
+ *			outgoing requests (e.g. making call) when no account is
+ *			specified, and when receiving incoming requests when the
+ *			request does not match any accounts. It is recommended
+ *			that default account is set to local/LAN account.
+ * @param p_acc_id	Pointer to receive account ID of the new account.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
+					 pj_bool_t is_default,
+					 pjsua_acc_id *p_acc_id);
+
+/**
+ * Delete account.
+ *
+ * @param acc_id	Id of the account to be deleted.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
+
+
+/**
+ * Modify account information.
+ *
+ * @param acc_id	Id of the account to be modified.
+ * @param cfg		New account configuration.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
+				      const pjsua_acc_config *cfg);
+
+
+/**
+ * Modify account's presence status to be advertised to remote/presence
+ * subscribers.
+ *
+ * @param acc_id	The account ID.
+ * @param is_online	True of false.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
+						 pj_bool_t is_online);
+
+
+/**
+ * Update registration or perform unregistration. 
+ *
+ * @param acc_id	The account ID.
+ * @param renew		If renew argument is zero, this will start 
+ *			unregistration process.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id, 
+						pj_bool_t renew);
+
+
+/**
+ * Get account information.
+ *
+ * @param acc_id	Account identification.
+ * @param info		Pointer to receive account information.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
+					pjsua_acc_info *info);
+
+
+/**
+ * Enum accounts all account ids.
+ *
+ * @param ids		Array of account IDs to be initialized.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
+				     unsigned *count );
+
+
+/**
+ * Enum accounts info.
+ *
+ * @param info		Array of account infos to be initialized.
+ * @param count		In input, specifies the maximum number of elements.
+ *			On return, it contains the actual number of elements.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
+					  unsigned *count );
+
+
+/**
+ * This is an internal function to find the most appropriate account to
+ * used to reach to the specified URL.
+ *
+ * @param url		The remote URL to reach.
+ *
+ * @return		Account id.
+ */
+PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
+
+
+/**
+ * This is an internal function to find the most appropriate account to be
+ * used to handle incoming calls.
+ *
+ * @param rdata		The incoming request message.
+ *
+ * @return		Account id.
+ */
+PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
+
+
+
+/**
+ * @}
+ */
+
+
+/*****************************************************************************
+ * CALLS API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_CALL Calls
+ * @ingroup PJSUA_LIB
+ * @brief Call manipulation.
+ * @{
+ */
+
+/**
+ * Max simultaneous calls.
+ */
+#ifndef PJSUA_MAX_CALLS
+#   define PJSUA_MAX_CALLS	    32
+#endif
+
+
+
 /**
  * Call media status.
@@ -970,331 +1412,4 @@
 
 
-
-/**
- * Conference port info.
- */
-typedef struct pjsua_conf_port_info
-{
-    /** Conference port number. */
-    pjsua_conf_port_id	slot_id;
-
-    /** Port name. */
-    pj_str_t		name;
-
-    /** Clock rate. */
-    unsigned		clock_rate;
-
-    /** Number of channels. */
-    unsigned		channel_count;
-
-    /** Samples per frame */
-    unsigned		samples_per_frame;
-
-    /** Bits per sample */
-    unsigned		bits_per_sample;
-
-    /** Number of listeners in the array. */
-    unsigned		listener_cnt;
-
-    /** Array of listeners (in other words, ports where this port is 
-     *  transmitting to.
-     */
-    pjsua_conf_port_id	listeners[PJSUA_MAX_CONF_PORTS];
-
-} pjsua_conf_port_info;
-
-
-/**
- * This structure holds information about custom media transport to
- * be registered to pjsua.
- */
-typedef struct pjsua_media_transport
-{
-    /**
-     * Media socket information containing the address information
-     * of the RTP and RTCP socket.
-     */
-    pjmedia_sock_info	 skinfo;
-
-    /**
-     * The media transport instance.
-     */
-    pjmedia_transport	*transport;
-
-} pjsua_media_transport;
-
-
-/**
- * This structure describes additional information to be sent with
- * outgoing SIP message.
- */
-typedef struct pjsua_msg_data
-{
-    /**
-     * Additional message headers as linked list.
-     */
-    pjsip_hdr	hdr_list;
-
-    /**
-     * MIME type of optional message body. 
-     */
-    pj_str_t	content_type;
-
-    /**
-     * Optional message body.
-     */
-    pj_str_t	msg_body;
-
-} pjsua_msg_data;
-
-
-/**
- * Initialize message data.
- *
- * @param msg_data  Message data to be initialized.
- */
-PJ_INLINE(void) pjsua_msg_data_init(pjsua_msg_data *msg_data)
-{
-    pj_memset(msg_data, 0, sizeof(*msg_data));
-    pj_list_init(&msg_data->hdr_list);
-}
-
-
-/*****************************************************************************
- * PJSUA Core API
- */
-
-
-/**
- * Instantiate pjsua application. Application must call this function before
- * calling any other functions, to make sure that the underlying libraries
- * are properly initialized. Once this function has returned success,
- * application must call pjsua_destroy() before quitting.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_create(void);
-
-
-/**
- * Initialize pjsua with the specified settings. All the settings are 
- * optional, and the default values will be used when the config is not
- * specified.
- *
- * @param ua_cfg	User agent configuration.
- * @param log_cfg	Optional logging configuration.
- * @param media_cfg	Optional media configuration.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_init(const pjsua_config *ua_cfg,
-				const pjsua_logging_config *log_cfg,
-				const pjsua_media_config *media_cfg);
-
-
-/**
- * Application is recommended to call this function after all initialization
- * is done, so that the library can do additional checking set up
- * additional 
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_start(void);
-
-
-/**
- * Destroy pjsua. This function must be called once PJSUA is created. To
- * make it easier for application, application may call this function
- * several times with no danger.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_destroy(void);
-
-
-/**
- * Poll pjsua for events, and if necessary block the caller thread for
- * the specified maximum interval (in miliseconds).
- *
- * @param msec_timeout	Maximum time to wait, in miliseconds.
- *
- * @return  The number of events that have been handled during the
- *	    poll. Negative value indicates error, and application
- *	    can retrieve the error as (err = -return_value).
- */
-PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout);
-
-
-/**
- * Create memory pool.
- *
- * @param name		Optional pool name.
- * @param size		Initial size of the pool.
- * @param increment	Increment size.
- *
- * @return		The pool, or NULL when there's no memory.
- */
-PJ_DECL(pj_pool_t*) pjsua_pool_create(const char *name, pj_size_t init_size,
-				      pj_size_t increment);
-
-
-/**
- * Application can call this function at any time (after pjsua_create(), of
- * course) to change logging settings.
- *
- * @param c		Logging configuration.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_reconfigure_logging(const pjsua_logging_config *c);
-
-
-/**
- * Internal function to get SIP endpoint instance of pjsua, which is
- * needed for example to register module, create transports, etc.
- * Probably is only valid after #pjsua_init() is called.
- * 
- * @return		SIP endpoint instance.
- */
-PJ_DECL(pjsip_endpoint*) pjsua_get_pjsip_endpt(void);
-
-/**
- * Internal function to get media endpoint instance.
- * Only valid after #pjsua_init() is called.
- *
- * @return		Media endpoint instance.
- */
-PJ_DECL(pjmedia_endpt*) pjsua_get_pjmedia_endpt(void);
-
-
-/*****************************************************************************
- * PJSUA SIP Transport API.
- */
-
-/**
- * Create SIP transport.
- *
- * @param type		Transport type.
- * @param cfg		Transport configuration.
- * @param p_id		Optional pointer to receive transport ID.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_transport_create(pjsip_transport_type_e type,
-					    const pjsua_transport_config *cfg,
-					    pjsua_transport_id *p_id);
-
-/**
- * Register transport that has been created by application.
- *
- * @param tp		Transport instance.
- * @param p_id		Optional pointer to receive transport ID.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_transport_register(pjsip_transport *tp,
-					      pjsua_transport_id *p_id);
-
-
-/**
- * Enumerate all transports currently created in the system.
- *
- * @param id		Array to receive transport ids.
- * @param count		In input, specifies the maximum number of elements.
- *			On return, it contains the actual number of elements.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_enum_transports( pjsua_transport_id id[],
-					    unsigned *count );
-
-
-/**
- * Get information about transports.
- *
- * @param id		Transport ID.
- * @param info		Pointer to receive transport info.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_transport_get_info(pjsua_transport_id id,
-					      pjsua_transport_info *info);
-
-
-/**
- * Disable a transport or re-enable it. By default transport is always 
- * enabled after it is created. Disabling a transport does not necessarily
- * close the socket, it will only discard incoming messages and prevent
- * the transport from being used to send outgoing messages.
- *
- * @param id		Transport ID.
- * @param enabled	Non-zero to enable, zero to disable.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_transport_set_enable(pjsua_transport_id id,
-						pj_bool_t enabled);
-
-
-/**
- * Close the transport. If transport is forcefully closed, it will be
- * immediately closed, and any pending transactions that are using the
- * transport may not terminate properly. Otherwise, the system will wait
- * until all transactions are closed while preventing new users from
- * using the transport, and will close the transport when it is safe to
- * do so.
- *
- * @param id		Transport ID.
- * @param force		Non-zero to immediately close the transport. This
- *			is not recommended!
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id,
-					    pj_bool_t force );
-
-
-/*****************************************************************************
- * PJSUA Media Transport.
- */
-
-/**
- * Create UDP media transports for all the calls. This function creates
- * one UDP media transport for each call.
- *
- * @param cfg		Media transport configuration. The "port" field in the
- *			configuration is used as the start port to bind the
- *			sockets.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) 
-pjsua_media_transports_create(const pjsua_transport_config *cfg);
-
-
-/**
- * Register custom media transports to be used by calls. There must
- * enough media transports for all calls.
- *
- * @param tp		The media transport array.
- * @param count		Number of elements in the array. This number MUST
- *			match the number of maximum calls configured when
- *			pjsua is created.
- * @param auto_delete	Flag to indicate whether the transports should be
- *			destroyed when pjsua is shutdown.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) 
-pjsua_media_transports_attach( pjsua_media_transport tp[],
-			       unsigned count,
-			       pj_bool_t auto_delete);
-
-
-
-/*****************************************************************************
- * PJSUA Call API.
- */
-
 /**
  * Get maximum number of calls configured in pjsua.
@@ -1328,5 +1443,4 @@
  *
  * @param acc_id	The account to be used.
- * @param target	URI to be put in the request URI.
  * @param dst_uri	URI to be put in the To header (normally is the same
  *			as the target URI).
@@ -1565,180 +1679,116 @@
 				     const char *indent);
 
+/**
+ * @}
+ */
+
 
 /*****************************************************************************
- * PJSUA Account and Client Registration API.
- */
-
-
-/**
- * Get number of current accounts.
- *
- * @return		Current number of accounts.
- */
-PJ_DECL(unsigned) pjsua_acc_get_count(void);
-
-
-/**
- * Check if the specified account ID is valid.
- *
- * @param acc_id	Account ID to check.
- *
- * @return		Non-zero if account ID is valid.
- */
-PJ_DECL(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id);
-
-
-/**
- * Add a new account to pjsua. PJSUA must have been initialized (with
- * #pjsua_init()) before calling this function.
- *
- * @param cfg		Account configuration.
- * @param is_default	If non-zero, this account will be set as the default
- *			account. The default account will be used when sending
- *			outgoing requests (e.g. making call) when no account is
- *			specified, and when receiving incoming requests when the
- *			request does not match any accounts. It is recommended
- *			that default account is set to local/LAN account.
- * @param p_acc_id	Pointer to receive account ID of the new account.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_add(const pjsua_acc_config *cfg,
-				   pj_bool_t is_default,
-				   pjsua_acc_id *p_acc_id);
-
-
-/**
- * Add a local account. A local account is used to identify local endpoint
- * instead of a specific user, and for this reason, a transport ID is needed
- * to obtain the local address information.
- *
- * @param tid		Transport ID to generate account address.
- * @param is_default	If non-zero, this account will be set as the default
- *			account. The default account will be used when sending
- *			outgoing requests (e.g. making call) when no account is
- *			specified, and when receiving incoming requests when the
- *			request does not match any accounts. It is recommended
- *			that default account is set to local/LAN account.
- * @param p_acc_id	Pointer to receive account ID of the new account.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_add_local(pjsua_transport_id tid,
-					 pj_bool_t is_default,
-					 pjsua_acc_id *p_acc_id);
-
-/**
- * Delete account.
- *
- * @param acc_id	Id of the account to be deleted.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id);
-
-
-/**
- * Modify account information.
- *
- * @param acc_id	Id of the account to be modified.
- * @param cfg		New account configuration.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
-				      const pjsua_acc_config *cfg);
-
-
-/**
- * Modify account's presence status to be advertised to remote/presence
- * subscribers.
- *
- * @param acc_id	The account ID.
- * @param is_online	True of false.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
-						 pj_bool_t is_online);
-
-
-/**
- * Update registration or perform unregistration. 
- *
- * @param acc_id	The account ID.
- * @param renew		If renew argument is zero, this will start 
- *			unregistration process.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_set_registration(pjsua_acc_id acc_id, 
-						pj_bool_t renew);
-
-
-/**
- * Get account information.
- *
- * @param acc_id	Account identification.
- * @param info		Pointer to receive account information.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_get_info(pjsua_acc_id acc_id,
-					pjsua_acc_info *info);
-
-
-/**
- * Enum accounts all account ids.
- *
- * @param ids		Array of account IDs to be initialized.
- * @param count		In input, specifies the maximum number of elements.
- *			On return, it contains the actual number of elements.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
-				     unsigned *count );
-
-
-/**
- * Enum accounts info.
- *
- * @param info		Array of account infos to be initialized.
- * @param count		In input, specifies the maximum number of elements.
- *			On return, it contains the actual number of elements.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
-					  unsigned *count );
-
-
-/**
- * This is an internal function to find the most appropriate account to
- * used to reach to the specified URL.
- *
- * @param url		The remote URL to reach.
- *
- * @return		Account id.
- */
-PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url);
-
-
-/**
- * This is an internal function to find the most appropriate account to be
- * used to handle incoming calls.
- *
- * @param rdata		The incoming request message.
- *
- * @return		Account id.
- */
-PJ_DECL(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata);
-
-
-
-/*****************************************************************************
- * PJSUA Presence (pjsua_pres.c)
- */
+ * BUDDY API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_BUDDY Buddy, Presence, and Instant Messaging
+ * @ingroup PJSUA_LIB
+ * @brief Buddy management, buddy's presence, and instant messaging.
+ * @{
+ */
+
+/**
+ * Max buddies in buddy list.
+ */
+#ifndef PJSUA_MAX_BUDDIES
+#   define PJSUA_MAX_BUDDIES	    256
+#endif
+
+
+/**
+ * Buddy configuration.
+ */
+typedef struct pjsua_buddy_config
+{
+    /**
+     * Buddy URL or name address.
+     */
+    pj_str_t	uri;
+
+    /**
+     * Specify whether presence subscription should start immediately.
+     */
+    pj_bool_t	subscribe;
+
+} pjsua_buddy_config;
+
+
+/**
+ * Buddy's online status.
+ */
+typedef enum pjsua_buddy_status
+{
+    /**
+     * Online status is unknown (possibly because no presence subscription
+     * has been established).
+     */
+    PJSUA_BUDDY_STATUS_UNKNOWN,
+
+    /**
+     * Buddy is known to be offline.
+     */
+    PJSUA_BUDDY_STATUS_ONLINE,
+
+    /**
+     * Buddy is offline.
+     */
+    PJSUA_BUDDY_STATUS_OFFLINE,
+
+} pjsua_buddy_status;
+
+
+
+/**
+ * Buddy info.
+ */
+typedef struct pjsua_buddy_info
+{
+    /**
+     * The buddy ID.
+     */
+    pjsua_buddy_id	id;
+
+    /**
+     * The full URI of the buddy, as specified in the configuration.
+     */
+    pj_str_t		uri;
+
+    /**
+     * Buddy's Contact, only available when presence subscription has
+     * been established to the buddy.
+     */
+    pj_str_t		contact;
+
+    /**
+     * Buddy's online status.
+     */
+    pjsua_buddy_status	status;
+
+    /**
+     * Text to describe buddy's online status.
+     */
+    pj_str_t		status_text;
+
+    /**
+     * Flag to indicate that we should monitor the presence information for
+     * this buddy (normally yes, unless explicitly disabled).
+     */
+    pj_bool_t		monitor_pres;
+
+    /**
+     * Internal buffer.
+     */
+    char		buf_[256];
+
+} pjsua_buddy_info;
+
 
 /**
@@ -1826,8 +1876,4 @@
 PJ_DECL(void) pjsua_pres_dump(pj_bool_t verbose);
 
-
-/*****************************************************************************
- * PJSUA Instant Messaging (pjsua_im.c)
- */
 
 /**
@@ -1882,7 +1928,213 @@
 
 
+/**
+ * @}
+ */
+
+
 /*****************************************************************************
- * Conference bridge manipulation.
- */
+ * MEDIA API
+ */
+
+
+/**
+ * @defgroup PJSUA_LIB_MEDIA Media
+ * @ingroup PJSUA_LIB
+ * @brief Media manipulation.
+ * @{
+ *
+ * PJSUA has rather powerful media features, which are built around the
+ * PJMEDIA conference bridge. Basically, all media termination (such as
+ * calls, file players, file recorders, sound device, tone generators, etc)
+ * are terminated in the conference bridge, and application can manipulate
+ * the interconnection between these terminations freely. If more than
+ * one media terminations are terminated in the same slot, the conference
+ * bridge will mix the signal automatically.
+ *
+ * Application connects one media termination/slot to another by calling
+ * #pjsua_conf_connect() function. This will establish <b>unidirectional</b>
+ * media flow from the source termination to the sink termination. For
+ * example, to stream a WAV file to remote call, application may use
+ * the following steps:
+ *
+ \code
+  
+  pj_status_t stream_to_call( pjsua_call_id call_id )
+  {
+     pjsua_player_id player_id;
+     
+     status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);
+     if (status != PJ_SUCCESS)
+        return status;
+
+     status = pjsua_conf_connect( pjsua_player_get_conf_port(),
+				  pjsua_call_get_conf_port() );
+  }
+ \endcode
+ *
+ *
+ * Other features of PJSUA media:
+ *  - efficient N to M interconnections between media terminations.
+ *  - media termination can be connected to itself to create loopback
+ *    media.
+ *  - the media termination may have different clock rates, and resampling
+ *    will be done automatically by conference bridge.
+ *  - media terminations may also have different frame time; the
+ *    conference bridge will perform the necessary bufferring to adjust
+ *    the difference between terminations.
+ *  - interconnections are removed automatically when media termination
+ *    is removed from the bridge.
+ *  - sound device may be changed even when there are active media 
+ *    interconnections.
+ *  - correctly report call's media quality (in #pjsua_call_dump()) from
+ *    RTCP packet exchange.
+ */
+
+/**
+ * Max ports in the conference bridge.
+ */
+#ifndef PJSUA_MAX_CONF_PORTS
+#   define PJSUA_MAX_CONF_PORTS	    254
+#endif
+
+
+
+/**
+ * Media configuration.
+ */
+struct pjsua_media_config
+{
+    /**
+     * Clock rate to be applied to the conference bridge.
+     * If value is zero, default clock rate will be used (16KHz).
+     */
+    unsigned		clock_rate;
+
+    /**
+     * Specify maximum number of media ports to be created in the
+     * conference bridge. Since all media terminate in the bridge
+     * (calls, file player, file recorder, etc), the value must be
+     * large enough to support all of them. However, the larger
+     * the value, the more computations are performed.
+     */
+    unsigned		max_media_ports;
+
+    /**
+     * Specify whether the media manager should manage its own
+     * ioqueue for the RTP/RTCP sockets. If yes, ioqueue will be created
+     * and at least one worker thread will be created too. If no,
+     * the RTP/RTCP sockets will share the same ioqueue as SIP sockets,
+     * and no worker thread is needed.
+     *
+     * Normally application would say yes here, unless it wants to
+     * run everything from a single thread.
+     */
+    pj_bool_t		has_ioqueue;
+
+    /**
+     * Specify the number of worker threads to handle incoming RTP
+     * packets. A value of one is recommended for most applications.
+     */
+    unsigned		thread_cnt;
+
+
+};
+
+
+/**
+ * Use this function to initialize media config.
+ *
+ * @param cfg	The media config to be initialized.
+ */
+PJ_INLINE(void) pjsua_media_config_default(pjsua_media_config *cfg)
+{
+    pj_memset(cfg, 0, sizeof(*cfg));
+
+    cfg->clock_rate = 16000;
+    cfg->max_media_ports = 32;
+    cfg->has_ioqueue = PJ_TRUE;
+    cfg->thread_cnt = 1;
+}
+
+
+
+/**
+ * Codec config.
+ */
+typedef struct pjsua_codec_info
+{
+    /**
+     * Codec unique identification.
+     */
+    pj_str_t		codec_id;
+
+    /**
+     * Codec priority (integer 0-255).
+     */
+    pj_uint8_t		priority;
+
+    /**
+     * Internal buffer.
+     */
+    char		buf_[32];
+
+} pjsua_codec_info;
+
+
+/**
+ * Conference port info.
+ */
+typedef struct pjsua_conf_port_info
+{
+    /** Conference port number. */
+    pjsua_conf_port_id	slot_id;
+
+    /** Port name. */
+    pj_str_t		name;
+
+    /** Clock rate. */
+    unsigned		clock_rate;
+
+    /** Number of channels. */
+    unsigned		channel_count;
+
+    /** Samples per frame */
+    unsigned		samples_per_frame;
+
+    /** Bits per sample */
+    unsigned		bits_per_sample;
+
+    /** Number of listeners in the array. */
+    unsigned		listener_cnt;
+
+    /** Array of listeners (in other words, ports where this port is 
+     *  transmitting to.
+     */
+    pjsua_conf_port_id	listeners[PJSUA_MAX_CONF_PORTS];
+
+} pjsua_conf_port_info;
+
+
+/**
+ * This structure holds information about custom media transport to
+ * be registered to pjsua.
+ */
+typedef struct pjsua_media_transport
+{
+    /**
+     * Media socket information containing the address information
+     * of the RTP and RTCP socket.
+     */
+    pjmedia_sock_info	 skinfo;
+
+    /**
+     * The media transport instance.
+     */
+    pjmedia_transport	*transport;
+
+} pjsua_media_transport;
+
+
+
 
 /**
@@ -1969,5 +2221,7 @@
  *
  * @param filename	The filename to be played. Currently only
- *			WAV files are supported.
+ *			WAV files are supported, and the WAV file MUST be
+ *			formatted as 16bit PCM mono/single channel (any
+ *			clock rate is supported).
  * @param options	Options (currently zero).
  * @param user_data	Arbitrary user data to be associated with the player.
@@ -2166,30 +2420,40 @@
 
 
-
-/*****************************************************************************
- * Utilities.
- *
- */
-
-/*
- * Verify that valid SIP url is given.
- *
- * @param c_url		The URL, as NULL terminated string.
- *
- * @return		PJ_SUCCESS on success, or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsua_verify_sip_url(const char *c_url);
-
-
-/**
- * Display error message for the specified error code.
- *
- * @param sender	The log sender field.
- * @param title		Message title for the error.
- * @param status	Status code.
- */
-PJ_DECL(void) pjsua_perror(const char *sender, const char *title, 
-			   pj_status_t status);
-
+/**
+ * Create UDP media transports for all the calls. This function creates
+ * one UDP media transport for each call.
+ *
+ * @param cfg		Media transport configuration. The "port" field in the
+ *			configuration is used as the start port to bind the
+ *			sockets.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) 
+pjsua_media_transports_create(const pjsua_transport_config *cfg);
+
+
+/**
+ * Register custom media transports to be used by calls. There must
+ * enough media transports for all calls.
+ *
+ * @param tp		The media transport array.
+ * @param count		Number of elements in the array. This number MUST
+ *			match the number of maximum calls configured when
+ *			pjsua is created.
+ * @param auto_delete	Flag to indicate whether the transports should be
+ *			destroyed when pjsua is shutdown.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) 
+pjsua_media_transports_attach( pjsua_media_transport tp[],
+			       unsigned count,
+			       pj_bool_t auto_delete);
+
+
+/**
+ * @}
+ */
 
 
@@ -2198,3 +2462,8 @@
 
 
+/**
+ * @}
+ */
+
+
 #endif	/* __PJSUA_H__ */
Index: pjproject/trunk/pjsip/src/pjsip/sip_parser.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_parser.c	(revision 514)
+++ pjproject/trunk/pjsip/src/pjsip/sip_parser.c	(revision 515)
@@ -98,5 +98,5 @@
 const pj_str_t  pjsip_BRANCH_STR    = { "branch", 6 };
 const pj_str_t  pjsip_TTL_STR       = { "ttl", 3 };
-const pj_str_t  pjsip_PNAME_STR     = { "received", 8 };
+const pj_str_t  pjsip_RECEIVED_STR  = { "received", 8 };
 const pj_str_t  pjsip_Q_STR         = { "q", 1 };
 const pj_str_t  pjsip_EXPIRES_STR   = { "expires", 7 };
@@ -1657,5 +1657,5 @@
 	    hdr->maddr_param = pvalue;
 
-	} else if (!parser_stricmp(pname, pjsip_PNAME_STR) && pvalue.slen) {
+	} else if (!parser_stricmp(pname, pjsip_RECEIVED_STR) && pvalue.slen) {
 	    hdr->recvd_param = pvalue;
 
