Index: pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
===================================================================
--- pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h	(revision 1021)
+++ pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h	(revision 1037)
@@ -511,5 +511,5 @@
    \endverbatim
  */
-typedef struct pj_stun_generic_ip_addr_attr
+typedef struct pj_stun_ip_addr_attr
 {
     /**
@@ -527,5 +527,5 @@
     } addr;
 
-} pj_stun_generic_ip_addr_attr;
+} pj_stun_ip_addr_attr;
 
 
@@ -549,5 +549,5 @@
  * NONCE attributes, the text MUST be quoted with.
  */
-typedef struct pj_stun_generic_string_attr
+typedef struct pj_stun_string_attr
 {
     /**
@@ -561,5 +561,5 @@
     pj_str_t		value;
 
-} pj_stun_generic_string_attr;
+} pj_stun_string_attr;
 
 
@@ -568,5 +568,5 @@
  * integer value, such as STUN FINGERPRINT and REFRESH-INTERVAL attributes.
  */
-typedef struct pj_stun_generic_uint_attr
+typedef struct pj_stun_uint_attr
 {
     /**
@@ -580,5 +580,5 @@
     pj_uint32_t		value;
 
-} pj_stun_generic_uint_attr;
+} pj_stun_uint_attr;
 
 
@@ -614,5 +614,5 @@
  * bytes.
  */
-typedef struct pj_stun_msg_integrity_attr
+typedef struct pj_stun_msgint_attr
 {
     /**
@@ -626,5 +626,5 @@
     pj_uint8_t		hmac[20];
 
-} pj_stun_msg_integrity_attr;
+} pj_stun_msgint_attr;
 
 
@@ -635,5 +635,5 @@
  * attribute itself, xor-d with the 32 bit value 0x5354554e
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_fingerprint_attr;
+typedef struct pj_stun_uint_attr pj_stun_fingerprint_attr;
 
 
@@ -656,5 +656,5 @@
  \endverbatim
  */
-typedef struct pj_stun_error_code_attr
+typedef struct pj_stun_errcode_attr
 {
     /**
@@ -683,5 +683,5 @@
     pj_str_t		reason;
 
-} pj_stun_error_code_attr;
+} pj_stun_errcode_attr;
 
 
@@ -693,5 +693,5 @@
  * quotes).
  */
-typedef struct pj_stun_generic_string_attr pj_stun_realm_attr;
+typedef struct pj_stun_string_attr pj_stun_realm_attr;
 
 
@@ -703,5 +703,5 @@
  * values in a server.
  */
-typedef struct pj_stun_generic_string_attr pj_stun_nonce_attr;
+typedef struct pj_stun_string_attr pj_stun_nonce_attr;
 
 
@@ -740,5 +740,5 @@
  * The MAPPED-ADDRESS attribute indicates the mapped transport address.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_mapped_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_mapped_addr_attr;
 
 
@@ -752,5 +752,5 @@
  * through NATs which would otherwise interfere with STUN.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_xor_mapped_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_xor_mapped_addr_attr;
 
 
@@ -763,5 +763,5 @@
  * SERVER is variable length.
  */
-typedef struct pj_stun_generic_string_attr pj_stun_server_attr;
+typedef struct pj_stun_string_attr pj_stun_server_attr;
 
 
@@ -772,5 +772,5 @@
  * MAPPED-ADDRESS.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_alt_server_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_alt_server_attr;
 
 
@@ -781,5 +781,5 @@
  * bindings between the client and server.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_refresh_interval_attr;
+typedef struct pj_stun_uint_attr pj_stun_refresh_interval_attr;
 
 
@@ -793,5 +793,5 @@
  * RFC 3489-bis standard.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_response_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_response_addr_attr;
 
 
@@ -808,5 +808,5 @@
  * RFC 3489-bis standard.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_changed_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_changed_addr_attr;
 
 
@@ -828,5 +828,5 @@
  * RFC 3489-bis standard.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_change_request_attr;
+typedef struct pj_stun_uint_attr pj_stun_change_request_attr;
 
 /**
@@ -840,5 +840,5 @@
  * RFC 3489-bis standard.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_src_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_src_addr_attr;
 
 
@@ -852,5 +852,5 @@
  * denial-of-service attacks.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_reflected_from_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_reflected_from_attr;
 
 
@@ -862,5 +862,5 @@
  * MESSAGE-INTEGRITY attribute.
  */
-typedef struct pj_stun_generic_string_attr pj_stun_username_attr;
+typedef struct pj_stun_string_attr pj_stun_username_attr;
 
 
@@ -870,5 +870,5 @@
  * PASSWORD attribute.
  */
-typedef struct pj_stun_generic_string_attr pj_stun_password_attr;
+typedef struct pj_stun_string_attr pj_stun_password_attr;
 
 
@@ -880,5 +880,5 @@
  * of seconds remaining until expiration.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_lifetime_attr;
+typedef struct pj_stun_uint_attr pj_stun_lifetime_attr;
 
 
@@ -889,5 +889,5 @@
  * value represents the sum in the receive and send directions.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_bandwidth_attr;
+typedef struct pj_stun_uint_attr pj_stun_bandwidth_attr;
 
 
@@ -897,5 +897,5 @@
  * from the STUN relay server.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_remote_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_remote_addr_attr;
 
 
@@ -915,5 +915,5 @@
  * address and port that the server allocated to the client.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_relay_addr_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_relay_addr_attr;
 
 
@@ -934,5 +934,5 @@
  \endverbatim
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_requested_addr_type;
+typedef struct pj_stun_uint_attr pj_stun_requested_addr_type;
 
 /**
@@ -954,5 +954,5 @@
  \endverbatim  
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_requested_port_props_attr;
+typedef struct pj_stun_uint_attr pj_stun_requested_port_props_attr;
 
 
@@ -963,5 +963,5 @@
  * unsigned integer.  Its values are: 0x0000 for UDP and 0x0000 for TCP.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_requested_transport_attr;
+typedef struct pj_stun_uint_attr pj_stun_requested_transport_attr;
 
 
@@ -971,5 +971,5 @@
  * specific IP address be allocated to it.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_requested_ip_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_requested_ip_attr;
 
 /**
@@ -983,5 +983,5 @@
  * to XOR-MAPPED-ADDRESS.
  */
-typedef struct pj_stun_generic_ip_addr_attr pj_stun_xor_reflected_from_attr;
+typedef struct pj_stun_ip_addr_attr pj_stun_xor_reflected_from_attr;
 
 /**
@@ -992,5 +992,5 @@
  * type of 0x0024.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_priority_attr;
+typedef struct pj_stun_uint_attr pj_stun_priority_attr;
 
 /**
@@ -1011,5 +1011,5 @@
  * the STUN-aware NATs along the path.
  */
-typedef pj_stun_generic_ip_addr_attr pj_stun_xor_internal_addr_attr;
+typedef pj_stun_ip_addr_attr pj_stun_xor_internal_addr_attr;
 
 /**
@@ -1019,5 +1019,5 @@
  * client, the value of the timer used in the server state machine.
  */
-typedef struct pj_stun_generic_uint_attr pj_stun_timer_val_attr;
+typedef struct pj_stun_uint_attr pj_stun_timer_val_attr;
 
 
@@ -1048,5 +1048,5 @@
 
 /** STUN decoding options */
-enum pj_stun_options
+enum pj_stun_decode_options
 {
     /** 
@@ -1063,4 +1063,5 @@
     PJ_STUN_CHECK_PACKET    = 2
 };
+
 
 /**
@@ -1208,13 +1209,13 @@
  * @param pdu_len	The length of the packet buffer.
  * @param options	Additional options to be applied in the checking,
- *			which can be taken from pj_stun_options. One of the
- *			useful option is PJ_STUN_IS_DATAGRAM which means that
- *			the pdu represents a whole STUN packet.
+ *			which can be taken from pj_stun_decode_options. One 
+ *			of the useful option is PJ_STUN_IS_DATAGRAM which 
+ *			means that the pdu represents a whole STUN packet.
  *
  * @return		PJ_SUCCESS if the PDU is a potentially valid STUN
  *			message.
  */
-PJ_DECL(pj_status_t) pj_stun_msg_check(const pj_uint8_t *pdu, unsigned pdu_len,
-				       unsigned options);
+PJ_DECL(pj_status_t) pj_stun_msg_check(const pj_uint8_t *pdu, 
+				       unsigned pdu_len, unsigned options);
 
 
@@ -1225,5 +1226,5 @@
  * @param pdu		The incoming packet to be parsed.
  * @param pdu_len	The length of the incoming packet.
- * @param options	Parsing flags, according to pj_stun_options.
+ * @param options	Parsing flags, according to pj_stun_decode_options.
  * @param p_msg		Pointer to receive the parsed message.
  * @param p_parsed_len	Optional pointer to receive how many bytes have
@@ -1248,136 +1249,4 @@
 				        pj_stun_msg **p_response);
 
-typedef enum pj_stun_auth_policy_type
-{
-    PJ_STUN_POLICY_NONE,
-    PJ_STUN_POLICY_STATIC_SHORT_TERM,
-    PJ_STUN_POLICY_STATIC_LONG_TERM,
-    PJ_STUN_POLICY_DYNAMIC
-} pj_stun_auth_policy_type;
-
-typedef struct pj_stun_auth_policy
-{
-    pj_stun_auth_policy_type	type;
-    void		       *user_data;
-
-    union 
-    {
-	struct
-	{
-	    pj_str_t	  username;
-	    pj_str_t	  password;
-	    pj_str_t	  nonce;
-	} static_short_term;
-
-	struct
-	{
-	    pj_str_t	  realm;
-	    pj_str_t	  username;
-	    pj_str_t	  password;
-	    pj_str_t	  nonce;
-	} static_long_term;
-
-	struct
-	{
-	    /**
-	     * This callback is called by pj_stun_verify_credential() when
-	     * server needs to challenge the request with 401 response.
-	     *
-	     * @param user_data	The user data as specified in the policy.
-	     * @param pool	Pool to allocate memory.
-	     * @param realm	On return, the function should fill in with
-	     *			realm if application wants to use long term
-	     *			credential. Otherwise application should set
-	     *			empty string for the realm.
-	     * @param nonce	On return, if application wants to use long
-	     *			term credential, it MUST fill in the nonce
-	     *			with some value. Otherwise  if short term 
-	     *			credential is wanted, it MAY set this value.
-	     *			If short term credential is wanted and the
-	     *			application doesn't want to include NONCE,
-	     *			then it must set this to empty string.
-	     *
-	     * @return		The callback should return PJ_SUCCESS, or
-	     *			otherwise response message will not be 
-	     *			created.
-	     */
-	    pj_status_t (*get_auth)(void *user_data,
-				    pj_pool_t *pool,
-				    pj_str_t *realm,
-				    pj_str_t *nonce);
-
-	    /**
-	     * Get the password for the specified username. This function 
-	     * is also used to check whether the username is valid.
-	     *
-	     * @param user_data	The user data as specified in the policy.
-	     * @param realm	The realm as specified in the message.
-	     * @param username	The username as specified in the message.
-	     * @param pool	Pool to allocate memory when necessary.
-	     * @param password	On return, application should fill up this
-	     *			argument with the password.
-	     *
-	     * @return		The callback should return PJ_SUCCESS if
-	     *			username has been successfully verified
-	     *			and password was obtained. If non-PJ_SUCCESS
-	     *			is returned, it is assumed that the
-	     *			username is not valid.
-	     */
-	    pj_status_t	(*get_password)(void *user_data, 
-				        const pj_str_t *realm,
-				        const pj_str_t *username,
-					pj_pool_t *pool,
-					pj_str_t *password);
-	    pj_bool_t	(*require_nonce)(void *user_data,
-					 const pj_str_t *realm,
-					 const pj_str_t *username);
-	    pj_bool_t	(*verify_nonce)(void *data,
-					const pj_str_t *realm,
-					const pj_str_t *username,
-					const pj_str_t *nonce);
-	    pj_status_t	(*make_nonce)(void *user_data,
-				      const pj_str_t *realm,
-				      const pj_str_t *username,
-				      pj_pool_t *pool,
-				      pj_str_t *nonce);
-	} dynamic;
-
-    } data;
-
-} pj_stun_auth_policy;
-
-
-/**
- * Verify credential in the STUN message. Note that before calling this
- * function, application must have checked that the message contains
- * PJ_STUN_ATTR_MESSAGE_INTEGRITY attribute by calling pj_stun_msg_find_attr()
- * function, because this function will reject the message with 401 error
- * if it doesn't contain PJ_STUN_ATTR_MESSAGE_INTEGRITY attribute.
- *
- * @param pkt		The original packet which has been parsed into
- *			the message. This packet MUST NOT have been modified
- *			after the parsing.
- * @param pkt_len	The length of the packet.
- * @param msg		The parsed message to be verified.
- * @param policy	Pointer to authentication policy.
- * @param pool		If response is to be created, then memory will
- *			be allocated from this pool.
- * @param p_response	Optional pointer to receive the response message
- *			then the credential in the request fails to
- *			authenticate.
- *
- * @return		PJ_SUCCESS if credential is verified successfully.
- *			If the verification fails and \a p_response is not
- *			NULL, an appropriate response will be returned in
- *			\a p_response.
- */
-PJ_DECL(pj_status_t) pj_stun_verify_credential(const pj_uint8_t *pkt,
-					       unsigned pkt_len,
-					       const pj_stun_msg *msg,
-					       pj_stun_auth_policy *policy,
-					       pj_pool_t *pool,
-					       pj_stun_msg **p_response);
-
-
 /**
  * Dump STUN message to a printable string output.
@@ -1431,11 +1300,10 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_generic_ip_addr_attr_create(pj_pool_t *pool,
-				    int attr_type, 
-				    pj_bool_t xor_ed,
-				    const pj_sockaddr_t *addr,
-				    unsigned addr_len,
-				    pj_stun_generic_ip_addr_attr **p_attr);
+PJ_DECL(pj_status_t) pj_stun_ip_addr_attr_create(pj_pool_t *pool,
+						int attr_type, 
+						pj_bool_t xor_ed,
+						const pj_sockaddr_t *addr,
+						unsigned addr_len,
+						pj_stun_ip_addr_attr **p_attr);
 
 
@@ -1455,11 +1323,10 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_msg_add_generic_ip_addr_attr(pj_pool_t *pool,
-				     pj_stun_msg *msg,
-				     int attr_type, 
-				     pj_bool_t xor_ed,
-				     const pj_sockaddr_t *addr,
-				     unsigned addr_len);
+PJ_DECL(pj_status_t) pj_stun_msg_add_ip_addr_attr(pj_pool_t *pool,
+						  pj_stun_msg *msg,
+						  int attr_type, 
+						  pj_bool_t xor_ed,
+						  const pj_sockaddr_t *addr,
+						  unsigned addr_len);
 
 /**
@@ -1473,9 +1340,8 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_generic_string_attr_create(pj_pool_t *pool,
-				   int attr_type,
-				   const pj_str_t *value,
-				   pj_stun_generic_string_attr **p_attr);
+PJ_DECL(pj_status_t) pj_stun_string_attr_create(pj_pool_t *pool,
+					        int attr_type,
+					        const pj_str_t *value,
+					        pj_stun_string_attr **p_attr);
 
 /**
@@ -1489,9 +1355,8 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_msg_add_generic_string_attr(pj_pool_t *pool,
-				    pj_stun_msg *msg,
-				    int attr_type,
-				    const pj_str_t *value);
+PJ_DECL(pj_status_t) pj_stun_msg_add_string_attr(pj_pool_t *pool,
+						 pj_stun_msg *msg,
+						 int attr_type,
+						 const pj_str_t *value);
 
 /**
@@ -1505,9 +1370,8 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_generic_uint_attr_create(pj_pool_t *pool,
-				 int attr_type,
-				 pj_uint32_t value,
-				 pj_stun_generic_uint_attr **p_attr);
+PJ_DECL(pj_status_t) pj_stun_uint_attr_create(pj_pool_t *pool,
+					      int attr_type,
+					      pj_uint32_t value,
+					      pj_stun_uint_attr **p_attr);
 
 /**
@@ -1521,9 +1385,8 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_msg_add_generic_uint_attr(pj_pool_t *pool,
-				  pj_stun_msg *msg,
-				  int attr_type,
-				  pj_uint32_t value);
+PJ_DECL(pj_status_t) pj_stun_msg_add_uint_attr(pj_pool_t *pool,
+					       pj_stun_msg *msg,
+					       int attr_type,
+					       pj_uint32_t value);
 
 
@@ -1536,7 +1399,17 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_msg_integrity_attr_create(pj_pool_t *pool,
-				  pj_stun_msg_integrity_attr **p_attr);
+PJ_DECL(pj_status_t) pj_stun_msgint_attr_create(pj_pool_t *pool,
+						pj_stun_msgint_attr **p_attr);
+
+/** 
+ * Create and add STUN MESSAGE-INTEGRITY attribute.
+ *
+ * @param pool		The pool to allocate memory from.
+ * @param msg		The STUN message
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_msg_add_msgint_attr(pj_pool_t *pool,
+						 pj_stun_msg *msg);
 
 /**
@@ -1551,10 +1424,25 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_error_code_attr_create(pj_pool_t *pool,
-			       int err_code,
-			       const pj_str_t *err_reason,
-			       pj_stun_error_code_attr **p_attr);
-
+PJ_DECL(pj_status_t) pj_stun_errcode_attr_create(pj_pool_t *pool,
+						int err_code,
+						const pj_str_t *err_reason,
+						pj_stun_errcode_attr **p_attr);
+
+
+/**
+ * Create and add STUN ERROR-CODE attribute to the message.
+ *
+ * @param pool		The pool to allocate memory from.
+ * @param msg		The STUN mesage.
+ * @param err_code	STUN error code.
+ * @param err_reason	Optional STUN error reason. If NULL is given, the
+ *			standard error reason will be given.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_stun_msg_add_errcode_attr(pj_pool_t *pool,
+						  pj_stun_msg *msg,
+						  int err_code,
+						  const pj_str_t *err_reason);
 
 /**
@@ -1569,9 +1457,8 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_unknown_attr_create(pj_pool_t *pool,
-			    unsigned attr_cnt,
-			    const pj_uint16_t attr[],
-			    pj_stun_unknown_attr **p_attr);
+PJ_DECL(pj_status_t) pj_stun_unknown_attr_create(pj_pool_t *pool,
+						unsigned attr_cnt,
+						const pj_uint16_t attr[],
+						pj_stun_unknown_attr **p_attr);
 
 /**
@@ -1585,9 +1472,8 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t) 
-pj_stun_msg_add_unknown_attr(pj_pool_t *pool,
-			     pj_stun_msg *msg,
-			     unsigned attr_cnt,
-			     const pj_uint16_t attr[]);
+PJ_DECL(pj_status_t) pj_stun_msg_add_unknown_attr(pj_pool_t *pool,
+						  pj_stun_msg *msg,
+						  unsigned attr_cnt,
+						  const pj_uint16_t attr[]);
 
 /**
@@ -1604,10 +1490,9 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t)
-pj_stun_binary_attr_create(pj_pool_t *pool,
-			   int attr_type,
-			   const pj_uint8_t *data,
-			   unsigned length,
-			   pj_stun_binary_attr **p_attr);
+PJ_DECL(pj_status_t) pj_stun_binary_attr_create(pj_pool_t *pool,
+					        int attr_type,
+					        const pj_uint8_t *data,
+					        unsigned length,
+					        pj_stun_binary_attr **p_attr);
 
 /**
@@ -1625,10 +1510,9 @@
  * @return		PJ_SUCCESS on success or the appropriate error code.
  */
-PJ_DECL(pj_status_t)
-pj_stun_msg_add_binary_attr(pj_pool_t *pool,
-			    pj_stun_msg *msg,
-			    int attr_type,
-			    const pj_uint8_t *data,
-			    unsigned length);
+PJ_DECL(pj_status_t) pj_stun_msg_add_binary_attr(pj_pool_t *pool,
+						 pj_stun_msg *msg,
+						 int attr_type,
+						 const pj_uint8_t *data,
+						 unsigned length);
 
 
