Implement ticket #336: custom presence status in NOTIFY/PUBLISH, supporting subset of RPID elements

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1424 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsip-simple/errno.h b/pjsip/include/pjsip-simple/errno.h
index ab3d4ec..7097bc6 100644
--- a/pjsip/include/pjsip-simple/errno.h
+++ b/pjsip/include/pjsip-simple/errno.h
@@ -77,6 +77,11 @@
  * Bad XPIDF Message
  */
 #define PJSIP_SIMPLE_EBADXPIDF	    (PJSIP_SIMPLE_ERRNO_START+25)   /*270025*/
+/**
+ * @hideinitializer
+ * Bad RPID Message
+ */
+#define PJSIP_SIMPLE_EBADRPID	    (PJSIP_SIMPLE_ERRNO_START+26)   /*270026*/
 
 
 /************************************************************
diff --git a/pjsip/include/pjsip-simple/presence.h b/pjsip/include/pjsip-simple/presence.h
index fb505fe..e52ec9c 100644
--- a/pjsip/include/pjsip-simple/presence.h
+++ b/pjsip/include/pjsip-simple/presence.h
@@ -26,6 +26,7 @@
 #include <pjsip-simple/evsub.h>
 #include <pjsip-simple/pidf.h>
 #include <pjsip-simple/xpidf.h>
+#include <pjsip-simple/rpid.h>
 
 
 PJ_BEGIN_DECL
@@ -73,6 +74,7 @@
  */
 #define PJSIP_PRES_STATUS_MAX_INFO  8
 
+
 /**
  * This structure describes presence status of a presentity.
  */
@@ -82,6 +84,8 @@
     struct {
 
 	pj_bool_t	basic_open;	/**< Basic status/availability.	    */
+	pjrpid_element	rpid;		/**< Optional RPID info.	    */
+
 	pj_str_t	id;		/**< Tuple id.			    */
 	pj_str_t	contact;	/**< Optional contact address.	    */
 
diff --git a/pjsip/include/pjsip-simple/rpid.h b/pjsip/include/pjsip-simple/rpid.h
new file mode 100644
index 0000000..2f090a9
--- /dev/null
+++ b/pjsip/include/pjsip-simple/rpid.h
@@ -0,0 +1,148 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2003-2007 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 
+ */
+#ifndef __PJSIP_SIMPLE_RPID_H__
+#define __PJSIP_SIMPLE_RPID_H__
+
+/**
+ * @file rpid.h
+ * @brief RPID: Rich Presence Extensions to the PIDF (RFC 4480)
+ */
+#include <pjsip-simple/types.h>
+#include <pjsip-simple/pidf.h>
+
+PJ_BEGIN_DECL
+
+
+/**
+ * @defgroup PJSIP_SIMPLE_RPID RPID/Rich Presence Extensions to PIDF (RFC 4480)
+ * @ingroup PJSIP_SIMPLE
+ * @brief RPID/Rich Presence Extensions to PIDF (RFC 4480)
+ * @{
+ *
+ * This file provides tools for managing subset of RPID elements into
+ * PIDF document.
+ */
+
+/**
+ * This enumeration describes subset of standard activities as 
+ * described by RFC 4880, RPID: Rich Presence Extensions to the 
+ * Presence Information Data Format (PIDF). 
+ */
+typedef enum pjrpid_activity
+{
+    /** Activity is unknown. The activity would then be conceived
+     *  in the "note" field.
+     */
+    PJRPID_ACTIVITY_UNKNOWN,
+
+    /** The person is away */
+    PJRPID_ACTIVITY_AWAY,
+
+    /** The person is busy */
+    PJRPID_ACTIVITY_BUSY
+
+} pjrpid_activity;
+
+
+/**
+ * This enumeration describes types of RPID element.
+ */
+typedef enum pjrpid_element_type
+{
+    /** RPID <person> element */
+    PJRPID_ELEMENT_TYPE_PERSON
+
+} pjrpid_element_type;
+
+
+/**
+ * This structure describes person information in RPID document.
+ */
+typedef struct pjrpid_element
+{
+    /** Element type. */
+    pjrpid_element_type	    type;
+
+    /** Optional id to set on the element. */
+    pj_str_t		    id;
+
+    /** Activity type. */
+    pjrpid_activity	    activity;
+
+    /** Optional text describing the person/element. */
+    pj_str_t		    note;
+
+} pjrpid_element;
+
+
+/**
+ * Duplicate RPID element.
+ *
+ * @param pool	    Pool.
+ * @param dst	    Destination structure.
+ * @param src	    Source structure.
+ */
+PJ_DECL(void) pjrpid_element_dup(pj_pool_t *pool, pjrpid_element *dst,
+				 const pjrpid_element *src);
+
+
+/**
+ * Add RPID element information into existing PIDF document. This will also
+ * add the appropriate XML namespace attributes into the presence's XML
+ * node, if the attributes are not already present, and also a <note> element
+ * to the first <tuple> element of the PIDF document.
+ *
+ * @param pres	    The PIDF presence document.
+ * @param pool	    Pool.
+ * @param options   Currently unused, and must be zero.
+ * @param elem	    RPID element information to be added into the PIDF
+ *		    document.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjrpid_add_element(pjpidf_pres *pres,
+				        pj_pool_t *pool,
+					unsigned options,
+				        const pjrpid_element *elem);
+
+/**
+ * Get RPID element information from PIDF document, if any.
+ *
+ * @param pres	    The PIDF document containing RPID elements.
+ * @param pool	    Pool to duplicate the information.
+ * @param elem	    Structure to receive the element information.
+ *
+ * @return PJ_SUCCESS	if the document does contain RPID element
+ *			and the information has been parsed successfully.
+ */
+PJ_DECL(pj_status_t) pjrpid_get_element(const pjpidf_pres *pres,
+				        pj_pool_t *pool,
+				        pjrpid_element *elem);
+
+
+/**
+ * @}
+ */
+
+
+PJ_END_DECL
+
+
+#endif	/* __PJSIP_SIMPLE_RPID_H__ */
+
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index d6af018..ad89a03 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -1918,6 +1918,16 @@
     pj_bool_t		online_status;
 
     /**
+     * Presence online status text.
+     */
+    pj_str_t		online_status_text;
+
+    /**
+     * Extended RPID online status information.
+     */
+    pjrpid_element	rpid;
+
+    /**
      * Buffer that is used internally to store the status text.
      */
     char		buf_[PJ_ERR_MSG_SIZE];
@@ -2080,7 +2090,10 @@
 /**
  * Modify account's presence 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.
+ * if there are server side presence subscription for this account, and/or
+ * outgoing PUBLISH if presence publication is enabled for this account.
+ *
+ * @see pjsua_acc_set_online_status2()
  *
  * @param acc_id	The account ID.
  * @param is_online	True of false.
@@ -2095,6 +2108,24 @@
 PJ_DECL(pj_status_t) pjsua_acc_set_online_status(pjsua_acc_id acc_id,
 						 pj_bool_t is_online);
 
+/**
+ * Modify account's presence 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.
+ *
+ * @see pjsua_acc_set_online_status()
+ *
+ * @param acc_id	The account ID.
+ * @param is_online	True of false.
+ * @param pr		Extended information in subset of RPID format
+ *			which allows setting custom presence text.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_acc_set_online_status2(pjsua_acc_id acc_id,
+						  pj_bool_t is_online,
+						  const pjrpid_element *pr);
 
 /**
  * Update registration or perform unregistration. If registration is
@@ -2988,9 +3019,14 @@
     pj_bool_t		monitor_pres;
 
     /**
+     * Extended RPID information about the person.
+     */
+    pjrpid_element	rpid;
+
+    /**
      * Internal buffer.
      */
-    char		buf_[256];
+    char		buf_[512];
 
 } pjsua_buddy_info;
 
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h
index ca9ea65..de6be5d 100644
--- a/pjsip/include/pjsua-lib/pjsua_internal.h
+++ b/pjsip/include/pjsua-lib/pjsua_internal.h
@@ -95,6 +95,7 @@
     pjsip_cred_info  cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds.	*/
 
     pj_bool_t	     online_status; /**< Our online status.		*/
+    pjrpid_element   rpid;	    /**< RPID element information.	*/
     pjsua_srv_pres   pres_srv_list; /**< Server subscription list.	*/
     pjsip_publishc  *publish_sess;  /**< Client publication session.	*/
     pj_bool_t	     publish_state; /**< Last published online status	*/
@@ -320,6 +321,11 @@
 void pjsua_pres_refresh(void);
 
 /*
+ * Update server subscription (e.g. when our online status has changed)
+ */
+void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
+
+/*
  * Shutdown presence.
  */
 void pjsua_pres_shutdown(void);