Index: pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp	(revision 4597)
+++ pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp	(revision 4608)
@@ -25,4 +25,5 @@
  */
 #include <pjsua-lib/pjsua.h>
+#include <pjsua2/types.hpp>
 
 /**
@@ -37,4 +38,10 @@
  */
 
+/** PJSUA2 API is inside pj namespace */
+namespace pj
+{
+using std::string;
+using std::vector;
+
 /**
  * Account registration config. This will be specified in AccountConfig.
@@ -49,5 +56,5 @@
      * value is empty, no account registration will be performed.
      */
-    String		registrarUri;
+    string		registrarUri;
 
     /**
@@ -64,5 +71,5 @@
      * request.
      */
-    StringVector	headers;
+    SipHeaderVector	headers;
 
     /**
@@ -102,5 +109,5 @@
      * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
      */
-    unsigned		delayBeforeRefresh;
+    unsigned		delayBeforeRefreshSec;
 
     /**
@@ -122,9 +129,12 @@
 
     /**
-     * Specify whether REGISTER requests will use the proxy settings
-     * of this account. If zero, the REGISTER request will not have any
-     * Route headers.
-     *
-     * Default: 1 (use account proxy)
+     * Specify how the registration uses the outbound and account proxy
+     * settings. This controls if and what Route headers will appear in
+     * the REGISTER request of this account. The value is bitmask combination
+     * of PJSUA_REG_USE_OUTBOUND_PROXY and PJSUA_REG_USE_ACC_PROXY bits.
+     * If the value is set to 0, the REGISTER request will not use any proxy
+     * (i.e. it will not have any Route headers).
+     *
+     * Default: 3 (PJSUA_REG_USE_OUTBOUND_PROXY | PJSUA_REG_USE_ACC_PROXY)
      */
     unsigned		proxyUse;
@@ -241,4 +251,17 @@
      */
     pjsua_sip_timer_use	timerUse;
+
+    /**
+     * Specify minimum Session Timer expiration period, in seconds.
+     * Must not be lower than 90. Default is 90.
+     */
+    unsigned		timerMinSESec;
+
+    /**
+     * Specify Session Timer expiration period, in seconds.
+     * Must not be lower than timerMinSE. Default is 1800.
+     */
+    unsigned		timerSessExpiresSec;
+
 };
 
@@ -252,5 +275,5 @@
      * subscription request.
      */
-    StringVector	subHeaders;
+    SipHeaderVector	headers;
 
     /**
@@ -390,4 +413,14 @@
      */
     bool		iceNoRtcp;
+
+    /**
+     * Always send re-INVITE/UPDATE after ICE negotiation regardless of whether
+     * the default ICE transport address is changed or not. When this is set
+     * to False, re-INVITE/UPDATE will be sent only when the default ICE
+     * transport address is changed.
+     *
+     * Default: yes
+     */
+    bool		iceAlwaysUpdate;
 
     /**
@@ -440,22 +473,15 @@
      * Default: TRUE
      */
-    bool		contactRewriteEnabled;
+    int			contactRewriteUse;
 
     /**
      * Specify how Contact update will be done with the registration, if
-     * contactRewriteEnabled is enabled.
-     *
-     * If set to 1, the Contact update will be done by sending unregistration
-     * to the currently registered Contact, while simultaneously sending new
-     * registration (with different Call-ID) for the updated Contact.
-     *
-     * If set to 2, the Contact update will be done in a single, current
-     * registration session, by removing the current binding (by setting its
-     * Contact's expires parameter to zero) and adding a new Contact binding,
-     * all done in a single request.
-     *
-     * Value 1 is the legacy behavior.
-     *
-     * Default value: PJSUA_CONTACT_REWRITE_METHOD (2)
+     * \a contactRewriteEnabled is enabled. The value is bitmask combination of
+     * \a pjsua_contact_rewrite_method. See also pjsua_contact_rewrite_method.
+     *
+     * Value PJSUA_CONTACT_REWRITE_UNREGISTER(1) is the legacy behavior.
+     *
+     * Default value: PJSUA_CONTACT_REWRITE_METHOD
+     *   (PJSUA_CONTACT_REWRITE_NO_UNREG | PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE)
      */
     int			contactRewriteMethod;
@@ -469,5 +495,17 @@
      * Default: TRUE
      */
-    bool		viaRewriteEnabled;
+    int			viaRewriteUse;
+
+    /**
+     * This option controls whether the IP address in SDP should be replaced
+     * with the IP address found in Via header of the REGISTER response, ONLY
+     * when STUN and ICE are not used. If the value is FALSE (the original
+     * behavior), then the local IP address will be used. If TRUE, and when
+     * STUN and ICE are disabled, then the IP address found in registration
+     * response will be used.
+     *
+     * Default: PJ_FALSE (no)
+     */
+    int			sdpNatRewriteUse;
 
     /**
@@ -484,5 +522,5 @@
      * Default: TRUE
      */
-    bool		sipOutboundEnabled;
+    int			sipOutboundUse;
 
     /**
@@ -531,5 +569,5 @@
 {
     /**
-     * Media transport configuration.
+     * Media transport (RTP) configuration.
      */
     TransportConfig	transportConfig;
@@ -574,35 +612,9 @@
      */
     int			srtpSecureSignaling;
-};
-
-/**
- * Video stream rate control config. This will be specified in
- * AccountVideoConfig.
- */
-struct VidRateControlConfig
-{
-    /**
-     * Rate control method.
-     *
-     * Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING.
-     */
-    pjmedia_vid_stream_rc_method    method;
-
-    /**
-     * Upstream/outgoing bandwidth. If this is set to zero, the video stream
-     * will use codec maximum bitrate setting.
-     *
-     * Default: 0 (follow codec maximum bitrate).
-     */
-    unsigned			    bandwidth;
-
-    /** Default constructor */
-    VidRateControlConfig();
-
-    /** Convert to pj */
-    pjmedia_vid_stream_rc_config toPj() const;
-
-    /** Convert from pj */
-    void fromPj(const pjmedia_vid_stream_rc_config &prm);
+
+    /**
+     * Specify whether IPv6 should be used on media. Default is not used.
+     */
+    pjsua_ipv6_use	ipv6Use;
 };
 
@@ -626,5 +638,5 @@
      * Default: False
      */
-    bool		autoShowIncoming;
+    bool			autoShowIncoming;
 
     /**
@@ -641,5 +653,5 @@
      * Default: False
      */
-    bool		autoTransmitOutgoing;
+    bool			autoTransmitOutgoing;
 
     /**
@@ -649,5 +661,5 @@
      * Default: 0
      */
-    unsigned		windowFlags;
+    unsigned			windowFlags;
 
     /**
@@ -658,5 +670,5 @@
      * Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV
      */
-    pjmedia_vid_dev_index defaultCaptureDevice;
+    pjmedia_vid_dev_index 	defaultCaptureDevice;
 
     /**
@@ -665,10 +677,20 @@
      * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV
      */
-    pjmedia_vid_dev_index defaultRenderDevice;
-
-    /**
-     * Specify the send rate control for video stream.
-     */
-    VidRateControlConfig  rateControlConfig;
+    pjmedia_vid_dev_index 	defaultRenderDevice;
+
+    /**
+     * Rate control method.
+     *
+     * Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING.
+     */
+    pjmedia_vid_stream_rc_method rateControlMethod;
+
+    /**
+     * Upstream/outgoing bandwidth. If this is set to zero, the video stream
+     * will use codec maximum bitrate setting.
+     *
+     * Default: 0 (follow codec maximum bitrate).
+     */
+    unsigned			rateControlBandwidth;
 };
 
@@ -692,5 +714,5 @@
      * This field is mandatory.
      */
-    String		uri;
+    string		idUri;
 
     /**
@@ -734,4 +756,5 @@
     AccountVideoConfig	videoConfig;
 
+public:
     /**
      * Default constructor will initialize with default values.
@@ -740,5 +763,9 @@
 
     /**
-     * Convert to pjsip.
+     * This will return a temporary pjsua_acc_config instance, which contents
+     * are only valid as long as this AccountConfig structure remains valid
+     * AND no modifications are done to it AND no further toPj() function call
+     * is made. Any call to toPj() function will invalidate the content of
+     * temporary pjsua_acc_config that was returned by the previous call.
      */
     pjsua_acc_config toPj() const;
@@ -747,5 +774,27 @@
      * Initialize from pjsip.
      */
-    void fromPj(const pjsua_acc_config &prm);
+    void fromPj(const pjsua_acc_config &prm, const pjsua_media_config *mcfg);
+
+};
+
+/**
+ * This describes account presence status.
+ */
+struct AccountPresenceStatus
+{
+    /** Basic status. */
+    bool		isOnline;
+
+    /** Activity type. */
+    pjrpid_activity	activity;
+
+    /** Optional text describing the person/element. */
+    string		note;
+
+    /** Optional RPID ID string. */
+    string		rpidId;
+
+public:
+    AccountPresenceStatus();
 };
 
@@ -821,17 +870,59 @@
 
 /**
- * This structure contains parameters for onIncomingCall() callback.
- */
-struct IncomingCallParam
-{
-    // rdata
-};
-
-/**
- * This structure contains parameters for onRegState() callback.
- */
-struct RegStateParam
-{
-    // reginfo
+ * This structure contains parameters for onIncomingCall() account callback.
+ */
+struct OnIncomingCallParam
+{
+    /**
+     * The library call index allocated for the new call.
+     */
+    int			callIndex;
+
+    /**
+     * The incoming INVITE request.
+     */
+    SipRxData		rdata;
+};
+
+/**
+ * This structure contains parameters for onRegStarted() account callback.
+ */
+struct OnRegStartedParam
+{
+    /**
+     * True for registration and False for unregistration.
+     */
+    bool renew;
+};
+
+/**
+ * This structure contains parameters for onRegState() account callback.
+ */
+struct OnRegStateParam
+{
+    /**
+     * Registration operation status.
+     */
+    pj_status_t		status;
+
+    /**
+     * SIP status code received.
+     */
+    int			code;
+
+    /**
+     * SIP reason phrase received.
+     */
+    pj_str_t		reason;
+
+    /**
+     * The incoming message.
+     */
+    SipRxData		rdata;
+
+    /**
+     * Next expiration interval.
+     */
+    int			expiration;
 };
 
@@ -839,32 +930,15 @@
  * This structure contains parameters for onIncomingSubscribe() callback.
  */
-struct IncomingSubscribeParam
-{
-    /*
-    * @param srv_pres	    Server presence subscription instance. If
-    *			    application delays the acceptance of the request,
-    *			    it will need to specify this object when calling
-    *			    #pjsua_pres_notify().
-    * @param acc_id	    Account ID most appropriate for this request.
-    * @param buddy_id	    ID of the buddy matching the sender of the
-    *			    request, if any, or PJSUA_INVALID_ID if no
-    *			    matching buddy is found.
-    * @param from	    The From URI of the request.
-    * @param rdata	    The incoming request.
-    * @param code	    The status code to respond to the request. The
-    *			    default value is 200. Application may set this
-    *			    to other final status code to accept or reject
-    *			    the request.
-    * @param reason	    The reason phrase to respond to the request.
-    * @param msg_data	    If the application wants to send additional
-    *			    headers in the response, it can put it in this
-    *			    parameter.
-    */
-
-    //pjsua_srv_pres *srv_pres,
-    // pjsua_buddy_id buddy_id,
-    // const pj_str_t *from,
-    // pjsip_rx_data *rdata,
-    // pjsua_msg_data *msg_data
+struct OnIncomingSubscribeParam
+{
+    /**
+     *  Sender URI.
+     */
+    string		fromUri;
+
+    /**
+     * The incoming message.
+     */
+    SipRxData		rdata;
 
     /**
@@ -873,10 +947,137 @@
      * reject the request.
      */
-    pjsip_status_code code;
+    pjsip_status_code	code;
 
     /**
      * The reason phrase to respond to the request.
      */
-    string reason;
+    string		reason;
+
+    /**
+     * Additional data to be sent with the response, if any.
+     */
+    SipTxOption		txOption;
+};
+
+/**
+ * Parameters for onInstantMessage() account callback.
+ */
+struct OnInstantMessageParam
+{
+    /**
+     * Sender From URI.
+     */
+    string		fromUri;
+
+    /**
+     * To URI of the request.
+     */
+    string		toUri;
+
+    /**
+     * Contact URI of the sender.
+     */
+    string		contactUri;
+
+    /**
+     * MIME type of the message body.
+     */
+    string		contentType;
+
+    /**
+     * The message body.
+     */
+    string		msgBody;
+
+    /**
+     * The whole message.
+     */
+    SipRxData		rdata;
+};
+
+/**
+ * Parameters for onInstantMessageStatus() account callback.
+ */
+struct OnInstantMessageStatusParam
+{
+    /**
+     * Token or a user data that was associated with the pager
+     * transmission.
+     */
+    Token		userData;
+
+    /**
+     * Destination URI.
+     */
+    string		toUri;
+
+    /**
+     * The message body.
+     */
+    string		msgBody;
+
+    /**
+     * The SIP status code of the transaction.
+     */
+    pjsip_status_code	status;
+
+    /**
+     * The reason phrase of the transaction.
+     */
+    string		reason;
+
+    /**
+     * The incoming response that causes this callback to be called.
+     * If the transaction fails because of time out or transport error,
+     * the content will be empty.
+     */
+    SipRxData		rdata;
+};
+
+/**
+ * Parameters for onTypingIndication() account callback.
+ */
+struct OnTypingIndicationParam
+{
+    /**
+     * Sender/From URI.
+     */
+    string		fromUri;
+
+    /**
+     * To URI.
+     */
+    string		toUri;
+
+    /**
+     * The Contact URI.
+     */
+    string		contactUri;
+
+    /**
+     * Boolean to indicate if sender is typing.
+     */
+    bool		isTyping;
+
+    /**
+     * The whole message buffer.
+     */
+    SipRxData		rdata;
+};
+
+/**
+ * Parameters for onMwiInfo() account callback.
+ */
+struct OnMwiInfoParam
+{
+    /**
+     * MWI subscription state.
+     */
+    pjsip_evsub_state	state;
+
+    /**
+     * The whole message buffer.
+     */
+    SipRxData		rdata;
 };
 
@@ -895,5 +1096,16 @@
      * @param prm	Callback parameter.
      */
-    virtual void onIncomingCall(IncomingCallParam &prm)
+    virtual void onIncomingCall(OnIncomingCallParam &prm)
+    {}
+
+    /**
+     * Notify application when registration or unregistration has been
+     * initiated. Note that this only notifies the initial registration
+     * and unregistration. Once registration session is active, subsequent
+     * refresh will not cause this callback to be called.
+     *
+     * @param prm	    Callback parameter.
+     */
+    virtual void onRegStarted(OnRegStartedParam &prm)
     {}
 
@@ -903,7 +1115,7 @@
      * registration details.
      *
-     * @param acc_id	    The account ID.
-     */
-    virtual void onRegState(RegStateParam &prm)
+     * @param prm	    Callback parameter.
+     */
+    virtual void onRegState(OnRegStateParam &prm)
     {}
 
@@ -937,8 +1149,46 @@
      * Application MUST return from this callback immediately (e.g. it must
      * not block in this callback while waiting for user confirmation).
-     */
-    virtual void onIncomingSubscribe(IncomingSubscribeParam &prm)
+     *
+     * @param prm	    Callback parameter.
+     */
+    virtual void onIncomingSubscribe(OnIncomingSubscribeParam &prm)
     {}
 
+    /**
+     * Notify application on incoming instant message or pager (i.e. MESSAGE
+     * request) that was received outside call context.
+     *
+     * @param prm	    Callback parameter.
+     */
+    virtual void onInstantMessage(OnInstantMessageParam &prm)
+    {}
+
+    /**
+     * Notify application about the delivery status of outgoing pager/instant
+     * message (i.e. MESSAGE) request.
+     *
+     * @param prm	    Callback parameter.
+     */
+    virtual void onInstantMessageStatus(OnInstantMessageStatusParam &prm)
+    {}
+
+    /**
+     * Notify application about typing indication.
+     *
+     * @param prm	    Callback parameter.
+     */
+    virtual void onTypingIndication(OnTypingIndicationParam &prm)
+    {}
+
+    /**
+     * Notification about MWI (Message Waiting Indication) status change.
+     * This callback can be called upon the status change of the
+     * SUBSCRIBE request (for example, 202/Accepted to SUBSCRIBE is received)
+     * or when a NOTIFY reqeust is received.
+     *
+     * @param prm	    Callback parameter.
+     */
+    virtual void onMwiInfo(OnMwiInfoParam &prm)
+    {}
 };
 
@@ -960,5 +1210,101 @@
 {
 public:
-    void setTransport();
+    /**
+     * Check if this account is still valid.
+     *
+     * @return			True if it is.
+     */
+    bool isValid() const;
+
+    /**
+     * Set this as default account to be used when incoming and outgoing
+     * requests don't match any accounts.
+     *
+     * @return			PJ_SUCCESS on success.
+     */
+    void setDefault() throw(Error);
+
+    /**
+     * Check if this account is the default account. Default account will be
+     * used for incoming and outgoing requests that don't match any other
+     * accounts.
+     *
+     * @return			True if this is the default account.
+     */
+    bool isDefault() const;
+
+    /**
+     * Get PJSUA-LIB account ID or index associated with this account.
+     *
+     * @return			Integer greater than or equal to zero.
+     */
+    int getIndex() const;
+
+    /**
+     * Set arbitrary data to be associated with the account.
+     *
+     * @param user_data		User/application data.
+     */
+    void setUserData(Token user_data);
+
+    /**
+     * Get the user data that was associated with the account.
+     *
+     * @return			The user data.
+     */
+    Token getUserData() const;
+
+    /**
+     * Get account info.
+     *
+     * @return			Account info.
+     */
+    AccountInfo getInfo() const;
+
+    /**
+     * Modify the account to use the specified account configuration.
+     * Depending on the changes, this may cause unregistration or
+     * reregistration on the account.
+     *
+     * @param cfg 		New account config to be applied to the account.
+     */
+    void modify(const AccountConfig &acc) throw(Error);
+
+    /**
+     * Update registration or perform unregistration. Application normally
+     * only needs to call this function if it wants to manually update the
+     * registration or to unregister from the server.
+     *
+     * @param renew		If False, this will start unregistration
+     * 				process.
+     */
+    void setRegistration(bool renew) throw(Error);
+
+    /**
+     * Set or modify account's presence online status to be advertised to
+     * remote/presence subscribers. This would trigger the sending of
+     * outgoing NOTIFY request if there are server side presence subscription
+     * for this account, and/or outgoing PUBLISH if presence publication is
+     * enabled for this account.
+     *
+     * @param pres_st		Presence online status.
+     */
+    void setOnlineStatus(const AccountPresenceStatus &pres_st) throw(Error);
+
+    /**
+     * Lock/bind this account to a specific transport/listener. Normally
+     * application shouldn't need to do this, as transports will be selected
+     * automatically by the library according to the destination.
+     *
+     * When account is locked/bound to a specific transport, all outgoing
+     * requests from this account will use the specified transport (this
+     * includes SIP registration, dialog (call and event subscription), and
+     * out-of-dialog requests such as MESSAGE).
+     *
+     * Note that transport id may be specified in AccountConfig too.
+     *
+     * @param tp_id		The transport ID.
+     */
+    void setTransport(TransportId tp_id) throw(Error);
 
 protected:
@@ -968,4 +1314,6 @@
 };
 
+} // namespace pj
+
 /**
  * @}  // PJSUA2_ACC
