diff --git a/.gitignore b/.gitignore index d4cffaa..1f04ef1 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,4 @@ cov-int/ getversion.mak configure.out pjsip-libs +compile_commands.json diff --git a/pjsip/include/pjsip/sip_auth.h b/pjsip/include/pjsip/sip_auth.h index 5e11664..5b50ec0 100644 --- a/pjsip/include/pjsip/sip_auth.h +++ b/pjsip/include/pjsip/sip_auth.h @@ -24,8 +24,8 @@ * @brief SIP Authorization Module. */ -#include #include +#include PJ_BEGIN_DECL @@ -46,19 +46,19 @@ PJ_BEGIN_DECL * Length of digest MD5 string. * \deprecated Use #pjsip_auth_algorithm::digest_str_length instead. */ -#define PJSIP_MD5STRLEN 32 +#define PJSIP_MD5STRLEN 32 /** * Length of digest SHA256 string. * \deprecated Use #pjsip_auth_algorithm::digest_str_length instead. */ -#define PJSIP_SHA256STRLEN 64 +#define PJSIP_SHA256STRLEN 64 /** * The length of the buffer needed to contain the largest * supported algorithm's digest. */ -#define PJSIP_AUTH_MAX_DIGEST_BUFFER_LENGTH 64 +#define PJSIP_AUTH_MAX_DIGEST_BUFFER_LENGTH 64 /** * Digest Algorithm Types. @@ -70,18 +70,16 @@ PJ_BEGIN_DECL * The AKA algorithms are described in RFC 3310 and RFC 4169 * and 3GPP TS 33.203. */ -typedef enum pjsip_auth_algorithm_type -{ - PJSIP_AUTH_ALGORITHM_NOT_SET = 0, /**< Algorithm not set. */ - PJSIP_AUTH_ALGORITHM_MD5, /**< MD5 algorithm. */ - PJSIP_AUTH_ALGORITHM_SHA256, /**< SHA-256 algorithm. */ - PJSIP_AUTH_ALGORITHM_SHA512_256, /**< SHA-512/256 algorithm */ - PJSIP_AUTH_ALGORITHM_AKAV1_MD5, /**< AKA v1 with MD5 algorithm. */ - PJSIP_AUTH_ALGORITHM_AKAV2_MD5, /**< AKA v2 with MD5 algorithm. */ - PJSIP_AUTH_ALGORITHM_COUNT, /**< Number of algorithms. */ +typedef enum pjsip_auth_algorithm_type { + PJSIP_AUTH_ALGORITHM_NOT_SET = 0, /**< Algorithm not set. */ + PJSIP_AUTH_ALGORITHM_MD5, /**< MD5 algorithm. */ + PJSIP_AUTH_ALGORITHM_SHA256, /**< SHA-256 algorithm. */ + PJSIP_AUTH_ALGORITHM_SHA512_256, /**< SHA-512/256 algorithm */ + PJSIP_AUTH_ALGORITHM_AKAV1_MD5, /**< AKA v1 with MD5 algorithm. */ + PJSIP_AUTH_ALGORITHM_AKAV2_MD5, /**< AKA v2 with MD5 algorithm. */ + PJSIP_AUTH_ALGORITHM_COUNT, /**< Number of algorithms. */ } pjsip_auth_algorithm_type; - /** * Authentication Digest Algorithm * @@ -89,8 +87,7 @@ typedef enum pjsip_auth_algorithm_type * SIP authentication. * */ -typedef struct pjsip_auth_algorithm -{ +typedef struct pjsip_auth_algorithm { pjsip_auth_algorithm_type algorithm_type; /**< Digest algorithm type */ pj_str_t iana_name; /**< IANA/RFC name used in SIP headers */ @@ -102,34 +99,33 @@ typedef struct pjsip_auth_algorithm representation */ } pjsip_auth_algorithm; - /** Type of data in the credential information in #pjsip_cred_info. */ -typedef enum pjsip_cred_data_type -{ - PJSIP_CRED_DATA_PLAIN_PASSWD=0, /**< Plain text password. */ - PJSIP_CRED_DATA_DIGEST =1, /**< Hashed digest. */ +typedef enum pjsip_cred_data_type { + PJSIP_CRED_DATA_PLAIN_PASSWD = 0, /**< Plain text password. */ + PJSIP_CRED_DATA_DIGEST = 1, /**< Hashed digest. */ - PJSIP_CRED_DATA_EXT_AKA =16 /**< Extended AKA info is available */ + PJSIP_CRED_DATA_EXT_AKA = 16, /**< Extended AKA info is available */ + PJSIP_CRED_DATA_GB = 32 /** GB35114 AUth */ } pjsip_cred_data_type; -#define PJSIP_CRED_DATA_PASSWD_MASK 0x000F -#define PJSIP_CRED_DATA_EXT_MASK 0x00F0 +#define PJSIP_CRED_DATA_PASSWD_MASK 0x000F +#define PJSIP_CRED_DATA_EXT_MASK 0x00F0 #define PJSIP_CRED_DATA_IS_AKA(cred) (((cred)->data_type & PJSIP_CRED_DATA_EXT_MASK) == PJSIP_CRED_DATA_EXT_AKA) -#define PJSIP_CRED_DATA_IS_PASSWD(cred) (((cred)->data_type & PJSIP_CRED_DATA_PASSWD_MASK) == PJSIP_CRED_DATA_PLAIN_PASSWD) +#define PJSIP_CRED_DATA_IS_PASSWD(cred) \ + (((cred)->data_type & PJSIP_CRED_DATA_PASSWD_MASK) == PJSIP_CRED_DATA_PLAIN_PASSWD) #define PJSIP_CRED_DATA_IS_DIGEST(cred) (((cred)->data_type & PJSIP_CRED_DATA_PASSWD_MASK) == PJSIP_CRED_DATA_DIGEST) +#define PJSIP_CRED_DATA_IS_GB(cred) (((cred)->data_type & PJSIP_CRED_DATA_GB) == PJSIP_CRED_DATA_GB) /** Authentication's quality of protection (qop) type. */ -typedef enum pjsip_auth_qop_type -{ - PJSIP_AUTH_QOP_NONE, /**< No quality of protection. */ - PJSIP_AUTH_QOP_AUTH, /**< Authentication. */ - PJSIP_AUTH_QOP_AUTH_INT, /**< Authentication with integrity protection. */ - PJSIP_AUTH_QOP_UNKNOWN /**< Unknown protection. */ +typedef enum pjsip_auth_qop_type { + PJSIP_AUTH_QOP_NONE, /**< No quality of protection. */ + PJSIP_AUTH_QOP_AUTH, /**< Authentication. */ + PJSIP_AUTH_QOP_AUTH_INT, /**< Authentication with integrity protection. */ + PJSIP_AUTH_QOP_UNKNOWN /**< Unknown protection. */ } pjsip_auth_qop_type; - /** * Type of callback function to create authentication response. * Application can specify this callback in \a cb field of the credential info @@ -153,12 +149,16 @@ typedef enum pjsip_auth_qop_type * framework will return failure to the original function * that requested authentication. */ -typedef pj_status_t (*pjsip_cred_cb)(pj_pool_t *pool, +typedef pj_status_t (*pjsip_cred_digest_cb)(pj_pool_t *pool, const pjsip_digest_challenge *chal, const pjsip_cred_info *cred, const pj_str_t *method, pjsip_digest_credential *auth); - +typedef pj_status_t (*pjsip_cred_gb_cb)(pj_pool_t *pool, + const pjsip_gb_challenge* chal, + const pjsip_cred_info* cred, + const pj_str_t *method, + pjsip_gb_credential* auth); /** * This structure describes credential information. @@ -172,22 +172,21 @@ typedef pj_status_t (*pjsip_cred_cb)(pj_pool_t *pool, * You should always fill this structure with zeros using PJ_POOL_ZALLOC_T() * or pj_bzero() before setting any fields. */ -struct pjsip_cred_info -{ - pj_str_t realm; /**< Realm. Use "*" to make a credential that +struct pjsip_cred_info { + pj_str_t realm; /**< Realm. Use "*" to make a credential that can be used to authenticate against any challenges. */ - pj_str_t scheme; /**< Scheme (e.g. "digest"). */ - pj_str_t username; /**< User name. */ - int data_type; /**< Type of data \ref pjsip_cred_data_type */ - pj_str_t data; /**< The data, which can be a plaintext + pj_str_t scheme; /**< Scheme (e.g. "digest"). */ + pj_str_t username; /**< User name. */ + int data_type; /**< Type of data \ref pjsip_cred_data_type */ + pj_str_t data; /**< The data, which can be a plaintext password or a hashed digest. */ /** * If the data_type is #PJSIP_CRED_DATA_DIGEST and the digest algorithm * used is not MD5 (the default), then this field MUST be set to the * appropriate digest algorithm type. */ - pjsip_auth_algorithm_type algorithm_type; /**< Digest algorithm type */ + pjsip_auth_algorithm_type algorithm_type; /**< Digest algorithm type */ /** Extended data */ union { @@ -197,13 +196,19 @@ struct pjsip_cred_info * Please see \ref PJSIP_AUTH_AKA_API for more information. */ struct { - pj_str_t k; /**< Permanent subscriber key. */ - pj_str_t op; /**< Operator variant key. */ - pj_str_t amf; /**< Authentication Management Field */ - pjsip_cred_cb cb; /**< Callback to create AKA digest. */ + pj_str_t k; /**< Permanent subscriber key. */ + pj_str_t op; /**< Operator variant key. */ + pj_str_t amf; /**< Authentication Management Field */ + pjsip_cred_digest_cb cb; /**< Callback to create AKA digest. */ } aka; } ext; + + struct { + pj_str_t algorithm; + pj_str_t keyversion; + pjsip_cred_gb_cb cb; /**< Callback to create gb35114 auth */ + } gb; }; /** @@ -212,17 +217,15 @@ struct pjsip_cred_info * of this structure and will resend the same header to the same server * as long as the method, uri, and nonce stays the same. */ -typedef struct pjsip_cached_auth_hdr -{ +typedef struct pjsip_cached_auth_hdr { /** Standard list member */ PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr); - pjsip_method method; /**< To quickly see the method. */ - pjsip_authorization_hdr *hdr; /**< The cached header. */ + pjsip_method method; /**< To quickly see the method. */ + pjsip_authorization_hdr *hdr; /**< The cached header. */ } pjsip_cached_auth_hdr; - /** * This structure describes authentication information for the specified * realm. Each instance of this structure describes authentication "session" @@ -233,52 +236,48 @@ typedef struct pjsip_cached_auth_hdr * Other than that, this structure also keeps the last authorization headers * that have been sent in the cache list. */ -typedef struct pjsip_cached_auth -{ +typedef struct pjsip_cached_auth { /** Standard list member */ PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth); - pj_pool_t *pool; /**< Pool for cached auth */ - pj_str_t realm; /**< Realm. */ - pj_bool_t is_proxy; /**< Server type (401/407) */ - pjsip_auth_qop_type qop_value; /**< qop required by server. */ - unsigned stale_cnt; /**< Number of stale retry. */ + pj_pool_t *pool; /**< Pool for cached auth */ + pj_str_t realm; /**< Realm. */ + pj_bool_t is_proxy; /**< Server type (401/407) */ + pjsip_auth_qop_type qop_value; /**< qop required by server. */ + unsigned stale_cnt; /**< Number of stale retry. */ #if PJSIP_AUTH_QOP_SUPPORT - pj_uint32_t nc; /**< Nonce count. */ - pj_str_t cnonce; /**< Cnonce value. */ + pj_uint32_t nc; /**< Nonce count. */ + pj_str_t cnonce; /**< Cnonce value. */ #endif - pjsip_www_authenticate_hdr *last_chal; /**< Last challenge seen. */ + pjsip_www_authenticate_hdr *last_chal; /**< Last challenge seen. */ #if PJSIP_AUTH_HEADER_CACHING - pjsip_cached_auth_hdr cached_hdr;/**< List of cached header for + pjsip_cached_auth_hdr cached_hdr; /**< List of cached header for each method. */ #endif - pjsip_auth_algorithm_type challenge_algorithm_type; /**< Challenge + pjsip_auth_algorithm_type challenge_algorithm_type; /**< Challenge algorithm */ } pjsip_cached_auth; - /** * This structure describes client authentication session preference. * The preference can be set by calling #pjsip_auth_clt_set_prefs(). */ -typedef struct pjsip_auth_clt_pref -{ +typedef struct pjsip_auth_clt_pref { /** * If this flag is set, the authentication client framework will * send an empty Authorization header in each initial request. * Default is no. */ - pj_bool_t initial_auth; + pj_bool_t initial_auth; /** * Specify the algorithm to use when empty Authorization header * is to be sent for each initial request (see above) */ - pj_str_t algorithm; + pj_str_t algorithm; } pjsip_auth_clt_pref; - /** * Get a pjsip_auth_algorithm structure by type. * @@ -287,9 +286,7 @@ typedef struct pjsip_auth_clt_pref * @return A pointer to a pjsip_auth_algorithm structure * or NULL if not found. */ -PJ_DECL(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_type( - pjsip_auth_algorithm_type algorithm_type); - +PJ_DECL(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_type(pjsip_auth_algorithm_type algorithm_type); /** * Get a pjsip_auth_algorithm by IANA name. @@ -299,9 +296,7 @@ PJ_DECL(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_type( * @return A pointer to a pjsip_auth_algorithm structure * or NULL if not found. */ -PJ_DECL(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_iana_name( - const pj_str_t *iana_name); - +PJ_DECL(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_iana_name(const pj_str_t *iana_name); /** * Check if a digest algorithm is supported. @@ -314,9 +309,7 @@ PJ_DECL(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_iana_name( * @return PJ_TRUE if the algorithm is supported, * PJ_FALSE otherwise. */ -PJ_DECL(pj_bool_t) pjsip_auth_is_algorithm_supported( - pjsip_auth_algorithm_type algorithm_type); - +PJ_DECL(pj_bool_t) pjsip_auth_is_algorithm_supported(pjsip_auth_algorithm_type algorithm_type); /** * Duplicate a client authentication preference setting. @@ -325,28 +318,23 @@ PJ_DECL(pj_bool_t) pjsip_auth_is_algorithm_supported( * @param dst Destination client authentication preference. * @param src Source client authentication preference. */ -PJ_DECL(void) pjsip_auth_clt_pref_dup(pj_pool_t *pool, - pjsip_auth_clt_pref *dst, - const pjsip_auth_clt_pref *src); - +PJ_DECL(void) pjsip_auth_clt_pref_dup(pj_pool_t *pool, pjsip_auth_clt_pref *dst, const pjsip_auth_clt_pref *src); /** * This structure describes client authentication sessions. It keeps * all the information needed to authorize the client against all downstream * servers. */ -typedef struct pjsip_auth_clt_sess -{ - pj_pool_t *pool; /**< Pool to use. */ - pjsip_endpoint *endpt; /**< Endpoint where this belongs. */ - pjsip_auth_clt_pref pref; /**< Preference/options. */ - unsigned cred_cnt; /**< Number of credentials. */ - pjsip_cred_info *cred_info; /**< Array of credential information*/ - pjsip_cached_auth cached_auth; /**< Cached authorization info. */ +typedef struct pjsip_auth_clt_sess { + pj_pool_t *pool; /**< Pool to use. */ + pjsip_endpoint *endpt; /**< Endpoint where this belongs. */ + pjsip_auth_clt_pref pref; /**< Preference/options. */ + unsigned cred_cnt; /**< Number of credentials. */ + pjsip_cred_info *cred_info; /**< Array of credential information*/ + pjsip_cached_auth cached_auth; /**< Cached authorization info. */ } pjsip_auth_clt_sess; - /** * Duplicate a credential info. * @@ -354,9 +342,7 @@ typedef struct pjsip_auth_clt_sess * @param dst Destination credential. * @param src Source credential. */ -PJ_DECL(void) pjsip_cred_info_dup(pj_pool_t *pool, - pjsip_cred_info *dst, - const pjsip_cred_info *src); +PJ_DECL(void) pjsip_cred_info_dup(pj_pool_t *pool, pjsip_cred_info *dst, const pjsip_cred_info *src); /** * Compare two credential infos. @@ -366,9 +352,7 @@ PJ_DECL(void) pjsip_cred_info_dup(pj_pool_t *pool, * * @return 0 if both credentials are equal. */ -PJ_DECL(int) pjsip_cred_info_cmp(const pjsip_cred_info *cred1, - const pjsip_cred_info *cred2); - +PJ_DECL(int) pjsip_cred_info_cmp(const pjsip_cred_info *cred1, const pjsip_cred_info *cred2); /** * Type of function to lookup credential for the specified name. @@ -387,26 +371,21 @@ PJ_DECL(int) pjsip_cred_info_cmp(const pjsip_cred_info *cred1, * realm. Otherwise it may return PJSIP_EAUTHACCNOTFOUND * or PJSIP_EAUTHACCDISABLED. */ -typedef pj_status_t pjsip_auth_lookup_cred( pj_pool_t *pool, - const pj_str_t *realm, - const pj_str_t *acc_name, - pjsip_cred_info *cred_info ); - +typedef pj_status_t +pjsip_auth_lookup_cred(pj_pool_t *pool, const pj_str_t *realm, const pj_str_t *acc_name, pjsip_cred_info *cred_info); /** * This structure describes input param for credential lookup. */ -typedef struct pjsip_auth_lookup_cred_param -{ - pj_str_t realm; /**< Realm to find the account. */ - pj_str_t acc_name; /**< Account name to look for. */ - pjsip_rx_data *rdata; /**< Incoming request to be +typedef struct pjsip_auth_lookup_cred_param { + pj_str_t realm; /**< Realm to find the account. */ + pj_str_t acc_name; /**< Account name to look for. */ + pjsip_rx_data *rdata; /**< Incoming request to be authenticated. */ - pjsip_authorization_hdr *auth_hdr; /**< Authorization header to be + pjsip_authorization_hdr *auth_hdr; /**< Authorization header to be authenticated. */ } pjsip_auth_lookup_cred_param; - /** * Type of function to lookup credential for the specified name. * @@ -423,28 +402,23 @@ typedef struct pjsip_auth_lookup_cred_param * realm. Otherwise it may return PJSIP_EAUTHACCNOTFOUND * or PJSIP_EAUTHACCDISABLED. */ -typedef pj_status_t pjsip_auth_lookup_cred2( - pj_pool_t *pool, - const pjsip_auth_lookup_cred_param *param, - pjsip_cred_info *cred_info ); - +typedef pj_status_t +pjsip_auth_lookup_cred2(pj_pool_t *pool, const pjsip_auth_lookup_cred_param *param, pjsip_cred_info *cred_info); /** Flag to specify that server is a proxy. */ -#define PJSIP_AUTH_SRV_IS_PROXY 1 +#define PJSIP_AUTH_SRV_IS_PROXY 1 /** * This structure describes server authentication information. */ -typedef struct pjsip_auth_srv -{ - pj_str_t realm; /**< Realm to serve. */ - pj_bool_t is_proxy; /**< Will issue 407 instead of 401 */ - pjsip_auth_lookup_cred *lookup; /**< Lookup function. */ - pjsip_auth_lookup_cred2 *lookup2; /**< Lookup function with additional +typedef struct pjsip_auth_srv { + pj_str_t realm; /**< Realm to serve. */ + pj_bool_t is_proxy; /**< Will issue 407 instead of 401 */ + pjsip_auth_lookup_cred *lookup; /**< Lookup function. */ + pjsip_auth_lookup_cred2 *lookup2; /**< Lookup function with additional info in its input param. */ } pjsip_auth_srv; - /** * Initialize client authentication session data structure, and set the * session to use pool for its subsequent memory allocation. The argument @@ -457,11 +431,8 @@ typedef struct pjsip_auth_srv * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_init( pjsip_auth_clt_sess *sess, - pjsip_endpoint *endpt, - pj_pool_t *pool, - unsigned options); - +PJ_DECL(pj_status_t) +pjsip_auth_clt_init(pjsip_auth_clt_sess *sess, pjsip_endpoint *endpt, pj_pool_t *pool, unsigned options); /** * Deinitialize client authentication session data structure. @@ -470,8 +441,7 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_init( pjsip_auth_clt_sess *sess, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_deinit( pjsip_auth_clt_sess *sess); - +PJ_DECL(pj_status_t) pjsip_auth_clt_deinit(pjsip_auth_clt_sess *sess); /** * Clone client initialization session. @@ -482,9 +452,7 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_deinit( pjsip_auth_clt_sess *sess); * * @return PJ_SUCCESS on success; */ -PJ_DECL(pj_status_t) pjsip_auth_clt_clone( pj_pool_t *pool, - pjsip_auth_clt_sess *sess, - const pjsip_auth_clt_sess *rhs); +PJ_DECL(pj_status_t) pjsip_auth_clt_clone(pj_pool_t *pool, pjsip_auth_clt_sess *sess, const pjsip_auth_clt_sess *rhs); /** * Set the credentials to be used during the session. This will duplicate @@ -500,10 +468,7 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_clone( pj_pool_t *pool, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_set_credentials( pjsip_auth_clt_sess *sess, - int cred_cnt, - const pjsip_cred_info *c); - +PJ_DECL(pj_status_t) pjsip_auth_clt_set_credentials(pjsip_auth_clt_sess *sess, int cred_cnt, const pjsip_cred_info *c); /** * Set the preference for the client authentication session. @@ -513,9 +478,7 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_set_credentials( pjsip_auth_clt_sess *sess, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, - const pjsip_auth_clt_pref *p); - +PJ_DECL(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, const pjsip_auth_clt_pref *p); /** * Get the preference for the client authentication session. @@ -525,8 +488,7 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, - pjsip_auth_clt_pref *p); +PJ_DECL(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, pjsip_auth_clt_pref *p); /** * Initialize new request message with authorization headers. @@ -549,9 +511,7 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, * * @return PJ_SUCCESS if successfull. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, - pjsip_tx_data *tdata ); - +PJ_DECL(pj_status_t) pjsip_auth_clt_init_req(pjsip_auth_clt_sess *sess, pjsip_tx_data *tdata); /** * Call this function when a transaction failed with 401 or 407 response. @@ -573,10 +533,11 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, * created to respond all the authentication * challenges. */ -PJ_DECL(pj_status_t) pjsip_auth_clt_reinit_req( pjsip_auth_clt_sess *sess, - const pjsip_rx_data *rdata, - pjsip_tx_data *old_request, - pjsip_tx_data **new_request ); +PJ_DECL(pj_status_t) +pjsip_auth_clt_reinit_req(pjsip_auth_clt_sess *sess, + const pjsip_rx_data *rdata, + pjsip_tx_data *old_request, + pjsip_tx_data **new_request); /** * Initialize server authorization session data structure to serve the @@ -595,28 +556,27 @@ PJ_DECL(pj_status_t) pjsip_auth_clt_reinit_req( pjsip_auth_clt_sess *sess, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_srv_init( pj_pool_t *pool, - pjsip_auth_srv *auth_srv, - const pj_str_t *realm, - pjsip_auth_lookup_cred *lookup, - unsigned options ); - +PJ_DECL(pj_status_t) +pjsip_auth_srv_init(pj_pool_t *pool, + pjsip_auth_srv *auth_srv, + const pj_str_t *realm, + pjsip_auth_lookup_cred *lookup, + unsigned options); /** * This structure describes initialization settings of server authorization * session. */ -typedef struct pjsip_auth_srv_init_param -{ +typedef struct pjsip_auth_srv_init_param { /** * Realm to be served by the server. */ - const pj_str_t *realm; + const pj_str_t *realm; /** * Account lookup function. */ - pjsip_auth_lookup_cred2 *lookup2; + pjsip_auth_lookup_cred2 *lookup2; /** * Options, bitmask of: @@ -624,11 +584,10 @@ typedef struct pjsip_auth_srv_init_param * clients as a proxy server (instead of as UAS), which means that * Proxy-Authenticate will be used instead of WWW-Authenticate. */ - unsigned options; + unsigned options; } pjsip_auth_srv_init_param; - /** * Initialize server authorization session data structure to serve the * specified realm and to use lookup_func function to look for the credential @@ -640,10 +599,8 @@ typedef struct pjsip_auth_srv_init_param * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_srv_init2( - pj_pool_t *pool, - pjsip_auth_srv *auth_srv, - const pjsip_auth_srv_init_param *param); +PJ_DECL(pj_status_t) +pjsip_auth_srv_init2(pj_pool_t *pool, pjsip_auth_srv *auth_srv, const pjsip_auth_srv_init_param *param); /** * Request the authorization server framework to verify the authorization @@ -664,10 +621,7 @@ PJ_DECL(pj_status_t) pjsip_auth_srv_init2( * - PJSIP_EAUTHINVALIDREALM * - PJSIP_EAUTHINVALIDDIGEST */ -PJ_DECL(pj_status_t) pjsip_auth_srv_verify( pjsip_auth_srv *auth_srv, - pjsip_rx_data *rdata, - int *status_code ); - +PJ_DECL(pj_status_t) pjsip_auth_srv_verify(pjsip_auth_srv *auth_srv, pjsip_rx_data *rdata, int *status_code); /** * Add authentication challenge headers to the outgoing response in tdata. @@ -686,12 +640,13 @@ PJ_DECL(pj_status_t) pjsip_auth_srv_verify( pjsip_auth_srv *auth_srv, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_srv_challenge( pjsip_auth_srv *auth_srv, - const pj_str_t *qop, - const pj_str_t *nonce, - const pj_str_t *opaque, - pj_bool_t stale, - pjsip_tx_data *tdata); +PJ_DECL(pj_status_t) +pjsip_auth_srv_challenge(pjsip_auth_srv *auth_srv, + const pj_str_t *qop, + const pj_str_t *nonce, + const pj_str_t *opaque, + pj_bool_t stale, + pjsip_tx_data *tdata); /** * Add authentication challenge headers to the outgoing response in tdata. @@ -711,13 +666,14 @@ PJ_DECL(pj_status_t) pjsip_auth_srv_challenge( pjsip_auth_srv *auth_srv, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_srv_challenge2(pjsip_auth_srv *auth_srv, - const pj_str_t *qop, - const pj_str_t *nonce, - const pj_str_t *opaque, - pj_bool_t stale, - pjsip_tx_data *tdata, - const pjsip_auth_algorithm_type algorithm_type); +PJ_DECL(pj_status_t) +pjsip_auth_srv_challenge2(pjsip_auth_srv *auth_srv, + const pj_str_t *qop, + const pj_str_t *nonce, + const pj_str_t *opaque, + pj_bool_t stale, + pjsip_tx_data *tdata, + const pjsip_auth_algorithm_type algorithm_type); /** * Helper function to create a digest out of the specified @@ -752,15 +708,17 @@ PJ_DECL(pj_status_t) pjsip_auth_srv_challenge2(pjsip_auth_srv *auth_srv, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_create_digest(pj_str_t *result, - const pj_str_t *nonce, - const pj_str_t *nc, - const pj_str_t *cnonce, - const pj_str_t *qop, - const pj_str_t *uri, - const pj_str_t *realm, - const pjsip_cred_info *cred_info, - const pj_str_t *method); +PJ_DECL(pj_status_t) +pjsip_auth_create_digest( + pj_str_t *result, + const pj_str_t *nonce, + const pj_str_t *nc, + const pj_str_t *cnonce, + const pj_str_t *qop, + const pj_str_t *uri, + const pj_str_t *realm, + const pjsip_cred_info *cred_info, + const pj_str_t *method); /** * Helper function to create SHA-256 digest out of the specified @@ -795,15 +753,17 @@ PJ_DECL(pj_status_t) pjsip_auth_create_digest(pj_str_t *result, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_create_digestSHA256(pj_str_t* result, - const pj_str_t* nonce, - const pj_str_t* nc, - const pj_str_t* cnonce, - const pj_str_t* qop, - const pj_str_t* uri, - const pj_str_t* realm, - const pjsip_cred_info* cred_info, - const pj_str_t* method); +PJ_DECL(pj_status_t) +pjsip_auth_create_digestSHA256( + pj_str_t *result, + const pj_str_t *nonce, + const pj_str_t *nc, + const pj_str_t *cnonce, + const pj_str_t *qop, + const pj_str_t *uri, + const pj_str_t *realm, + const pjsip_cred_info *cred_info, + const pj_str_t *method); /** * Helper function to create a digest out of the specified @@ -841,25 +801,23 @@ PJ_DECL(pj_status_t) pjsip_auth_create_digestSHA256(pj_str_t* result, * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjsip_auth_create_digest2(pj_str_t *result, - const pj_str_t *nonce, - const pj_str_t *nc, - const pj_str_t *cnonce, - const pj_str_t *qop, - const pj_str_t *uri, - const pj_str_t *realm, - const pjsip_cred_info *cred_info, - const pj_str_t *method, - const pjsip_auth_algorithm_type algorithm_type); +PJ_DECL(pj_status_t) +pjsip_auth_create_digest2( + pj_str_t *result, + const pj_str_t *nonce, + const pj_str_t *nc, + const pj_str_t *cnonce, + const pj_str_t *qop, + const pj_str_t *uri, + const pj_str_t *realm, + const pjsip_cred_info *cred_info, + const pj_str_t *method, + const pjsip_auth_algorithm_type algorithm_type); /** * @} */ - - PJ_END_DECL - -#endif /* __PJSIP_AUTH_SIP_AUTH_H__ */ - +#endif /* __PJSIP_AUTH_SIP_AUTH_H__ */ diff --git a/pjsip/include/pjsip/sip_auth_msg.h b/pjsip/include/pjsip/sip_auth_msg.h index 6eb933f..2213828 100644 --- a/pjsip/include/pjsip/sip_auth_msg.h +++ b/pjsip/include/pjsip/sip_auth_msg.h @@ -68,6 +68,26 @@ struct pjsip_digest_credential */ typedef struct pjsip_digest_credential pjsip_digest_credential; +struct pjsip_gb_credential { + pj_str_t realm; /**< Realm for the challenge. */ + pjsip_param other_param; /**< Other parameters. */ + pj_str_t algorithm; + pj_str_t keyversion; + pj_str_t random1; + pj_str_t random2; + pj_str_t deviceid; + pj_str_t serverid; + pj_str_t sign1; + pj_str_t sign2; + pj_str_t cryptkey; + pj_str_t cryptkey1; + pj_str_t cryptkey2; + pj_str_t certificate; +}; +typedef struct pjsip_gb_credential pjsip_gb_credential; +typedef struct pjsip_gb_credential pjsip_gb_challenge; +void pjsip_gb_credential_clone(pj_pool_t* pool, pjsip_gb_credential* cred, const pjsip_gb_credential* rhs); + /** * This structure describe credential used in Authorization and * Proxy-Authorization header for PGP authentication scheme. @@ -123,6 +143,7 @@ struct pjsip_authorization_hdr pjsip_digest_credential digest; /**< Digest credentials. */ pjsip_pgp_credential pgp; /**< PGP credentials. */ pjsip_oauth_credential oauth; /**< OAuth credentials. */ + pjsip_gb_credential gb; /**< GB35114 credential */ } credential; }; @@ -228,6 +249,7 @@ struct pjsip_www_authenticate_hdr pjsip_common_challenge common; /**< Common fields. */ pjsip_digest_challenge digest; /**< Digest challenge. */ pjsip_pgp_challenge pgp; /**< PGP challenge. */ + pjsip_gb_credential gb; } challenge; }; @@ -260,6 +282,20 @@ pjsip_www_authenticate_hdr_create(pj_pool_t *pool); PJ_DECL(pjsip_proxy_authenticate_hdr*) pjsip_proxy_authenticate_hdr_create(pj_pool_t *pool); +struct pjsip_security_info_hdr { + /** Standard header fiends. */ + PJSIP_DECL_HDR_MEMBER(struct pjsip_security_info_hdr); + + /** Authorization scheme. */ + pj_str_t scheme; + + pjsip_gb_credential gb; +}; + +typedef struct pjsip_security_info_hdr pjsip_security_info_hdr; + +PJ_DECL(pjsip_security_info_hdr*) pjsip_security_info_hdr_create(pj_pool_t* pool); + /** * @} */ diff --git a/pjsip/include/pjsip/sip_auth_parser.h b/pjsip/include/pjsip/sip_auth_parser.h index f7faefb..ada2b25 100644 --- a/pjsip/include/pjsip/sip_auth_parser.h +++ b/pjsip/include/pjsip/sip_auth_parser.h @@ -53,6 +53,17 @@ extern const pj_str_t pjsip_USERNAME_STR, /**< "username" string const. */ pjsip_URI_STR, /**< "uri" string const. */ pjsip_RESPONSE_STR, /**< "response" string const. */ pjsip_ALGORITHM_STR,/**< "algorithm" string const. */ + pjsip_RANDOM1_STR, + pjsip_RANDOM2_STR, + pjsip_KEYVERSION_STR, + pjsip_DEVICEID_STR, + pjsip_SERVERID_STR, + pjsip_SIGN1_STR, + pjsip_SIGN2_STR, + pjsip_CRYPTOKEY_STR, + pjsip_CRYPTOKEY1_STR, + pjsip_CRYPTOKEY2_STR, + pjsip_CERTIFICATE_STR, pjsip_DOMAIN_STR, /**< "domain" string const. */ pjsip_STALE_STR, /**< "stale" string const. */ pjsip_QOP_STR, /**< "qop" string const. */ @@ -62,11 +73,16 @@ extern const pj_str_t pjsip_USERNAME_STR, /**< "username" string const. */ pjsip_TRUE_STR, /**< "true" string const. */ pjsip_FALSE_STR, /**< "false" string const. */ pjsip_DIGEST_STR, /**< "digest" string const. */ + pjsip_CAPABILITY_STR, + pjsip_QUATED_CAPABILITY_STR, + pjsip_UNIDIRECTION_STR, + pjsip_BIDIRECTION_STR, pjsip_PGP_STR, /**< "pgp" string const. */ pjsip_BEARER_STR, /**< "bearer" string const. */ pjsip_MD5_STR, /**< "MD5" string const. */ pjsip_SHA256_STR, /**< "SHA-256" string const. */ pjsip_AUTH_STR; /**< "auth" string const. */ + ; PJ_END_DECL diff --git a/pjsip/include/pjsip/sip_errno.h b/pjsip/include/pjsip/sip_errno.h index 5053bb0..4140ce4 100644 --- a/pjsip/include/pjsip/sip_errno.h +++ b/pjsip/include/pjsip/sip_errno.h @@ -44,14 +44,14 @@ PJ_BEGIN_DECL /** * Start of error code relative to PJ_ERRNO_START_USER. */ -#define PJSIP_ERRNO_START (PJ_ERRNO_START_USER) +#define PJSIP_ERRNO_START (PJ_ERRNO_START_USER) /** * Create error value from SIP status code. * @param code SIP status code. * @return Error code in pj_status_t namespace. */ -#define PJSIP_ERRNO_FROM_SIP_STATUS(code) (PJSIP_ERRNO_START+code) +#define PJSIP_ERRNO_FROM_SIP_STATUS(code) (PJSIP_ERRNO_START + code) /** * Get SIP status code from error value. @@ -61,16 +61,15 @@ PJ_BEGIN_DECL * @param status Error code in pj_status_t namespace. * @return SIP status code. */ -#define PJSIP_ERRNO_TO_SIP_STATUS(status) \ - ((status>=PJSIP_ERRNO_FROM_SIP_STATUS(100) && \ - status= PJSIP_ERRNO_FROM_SIP_STATUS(100) && status < PJSIP_ERRNO_FROM_SIP_STATUS(800)) \ + ? status - PJSIP_ERRNO_FROM_SIP_STATUS(0) \ + : 599) /** * Start of PJSIP generated error code values. */ -#define PJSIP_ERRNO_START_PJSIP (PJSIP_ERRNO_START + 1000) +#define PJSIP_ERRNO_START_PJSIP (PJSIP_ERRNO_START + 1000) /************************************************************ * GENERIC/GENERAL SIP ERRORS @@ -79,28 +78,27 @@ PJ_BEGIN_DECL * @hideinitializer * SIP object is busy. */ -#define PJSIP_EBUSY (PJSIP_ERRNO_START_PJSIP + 1) /* 171001 */ +#define PJSIP_EBUSY (PJSIP_ERRNO_START_PJSIP + 1) /* 171001 */ /** * @hideinitializer * SIP object with the same type already exists. */ -#define PJSIP_ETYPEEXISTS (PJSIP_ERRNO_START_PJSIP + 2) /* 171002 */ +#define PJSIP_ETYPEEXISTS (PJSIP_ERRNO_START_PJSIP + 2) /* 171002 */ /** * @hideinitializer * SIP stack is shutting down. */ -#define PJSIP_ESHUTDOWN (PJSIP_ERRNO_START_PJSIP + 3) /* 171003 */ +#define PJSIP_ESHUTDOWN (PJSIP_ERRNO_START_PJSIP + 3) /* 171003 */ /** * @hideinitializer * SIP object is not initialized. */ -#define PJSIP_ENOTINITIALIZED (PJSIP_ERRNO_START_PJSIP + 4) /* 171004 */ +#define PJSIP_ENOTINITIALIZED (PJSIP_ERRNO_START_PJSIP + 4) /* 171004 */ /** * @hideinitializer * Missing route set (for tel: URI) */ -#define PJSIP_ENOROUTESET (PJSIP_ERRNO_START_PJSIP + 5) /* 171005 */ - +#define PJSIP_ENOROUTESET (PJSIP_ERRNO_START_PJSIP + 5) /* 171005 */ /************************************************************ * MESSAGING ERRORS @@ -109,91 +107,90 @@ PJ_BEGIN_DECL * @hideinitializer * General invalid message error (e.g. syntax error) */ -#define PJSIP_EINVALIDMSG (PJSIP_ERRNO_START_PJSIP + 20) /* 171020 */ +#define PJSIP_EINVALIDMSG (PJSIP_ERRNO_START_PJSIP + 20) /* 171020 */ /** * @hideinitializer * Expecting request message. */ -#define PJSIP_ENOTREQUESTMSG (PJSIP_ERRNO_START_PJSIP + 21) /* 171021 */ +#define PJSIP_ENOTREQUESTMSG (PJSIP_ERRNO_START_PJSIP + 21) /* 171021 */ /** * @hideinitializer * Expecting response message. */ -#define PJSIP_ENOTRESPONSEMSG (PJSIP_ERRNO_START_PJSIP + 22) /* 171022 */ +#define PJSIP_ENOTRESPONSEMSG (PJSIP_ERRNO_START_PJSIP + 22) /* 171022 */ /** * @hideinitializer * Message too long. See also PJSIP_ERXOVERFLOW. */ -#define PJSIP_EMSGTOOLONG (PJSIP_ERRNO_START_PJSIP + 23) /* 171023 */ +#define PJSIP_EMSGTOOLONG (PJSIP_ERRNO_START_PJSIP + 23) /* 171023 */ /** * @hideinitializer * Message not completely received. */ -#define PJSIP_EPARTIALMSG (PJSIP_ERRNO_START_PJSIP + 24) /* 171024 */ +#define PJSIP_EPARTIALMSG (PJSIP_ERRNO_START_PJSIP + 24) /* 171024 */ /** * @hideinitializer * Status code is invalid. */ -#define PJSIP_EINVALIDSTATUS (PJSIP_ERRNO_START_PJSIP + 30) /* 171030 */ +#define PJSIP_EINVALIDSTATUS (PJSIP_ERRNO_START_PJSIP + 30) /* 171030 */ /** * @hideinitializer * General Invalid URI error. */ -#define PJSIP_EINVALIDURI (PJSIP_ERRNO_START_PJSIP + 39) /* 171039 */ +#define PJSIP_EINVALIDURI (PJSIP_ERRNO_START_PJSIP + 39) /* 171039 */ /** * @hideinitializer * Unsupported URL scheme. */ -#define PJSIP_EINVALIDSCHEME (PJSIP_ERRNO_START_PJSIP + 40) /* 171040 */ +#define PJSIP_EINVALIDSCHEME (PJSIP_ERRNO_START_PJSIP + 40) /* 171040 */ /** * @hideinitializer * Missing Request-URI. */ -#define PJSIP_EMISSINGREQURI (PJSIP_ERRNO_START_PJSIP + 41) /* 171041 */ +#define PJSIP_EMISSINGREQURI (PJSIP_ERRNO_START_PJSIP + 41) /* 171041 */ /** * @hideinitializer * Invalid request URI. */ -#define PJSIP_EINVALIDREQURI (PJSIP_ERRNO_START_PJSIP + 42) /* 171042 */ +#define PJSIP_EINVALIDREQURI (PJSIP_ERRNO_START_PJSIP + 42) /* 171042 */ /** * @hideinitializer * URI is too long. */ -#define PJSIP_EURITOOLONG (PJSIP_ERRNO_START_PJSIP + 43) /* 171043 */ +#define PJSIP_EURITOOLONG (PJSIP_ERRNO_START_PJSIP + 43) /* 171043 */ /** * @hideinitializer * Missing required header(s). */ -#define PJSIP_EMISSINGHDR (PJSIP_ERRNO_START_PJSIP + 50) /* 171050 */ +#define PJSIP_EMISSINGHDR (PJSIP_ERRNO_START_PJSIP + 50) /* 171050 */ /** * @hideinitializer * Invalid header field. */ -#define PJSIP_EINVALIDHDR (PJSIP_ERRNO_START_PJSIP + 51) /* 171051 */ +#define PJSIP_EINVALIDHDR (PJSIP_ERRNO_START_PJSIP + 51) /* 171051 */ /** * @hideinitializer * Invalid Via header in response (sent-by, etc). */ -#define PJSIP_EINVALIDVIA (PJSIP_ERRNO_START_PJSIP + 52) /* 171052 */ +#define PJSIP_EINVALIDVIA (PJSIP_ERRNO_START_PJSIP + 52) /* 171052 */ /** * @hideinitializer * Multiple Via headers in response. */ -#define PJSIP_EMULTIPLEVIA (PJSIP_ERRNO_START_PJSIP + 53) /* 171053 */ +#define PJSIP_EMULTIPLEVIA (PJSIP_ERRNO_START_PJSIP + 53) /* 171053 */ /** * @hideinitializer * Missing message body. */ -#define PJSIP_EMISSINGBODY (PJSIP_ERRNO_START_PJSIP + 54) /* 171054 */ +#define PJSIP_EMISSINGBODY (PJSIP_ERRNO_START_PJSIP + 54) /* 171054 */ /** * @hideinitializer * Invalid/unexpected method. */ -#define PJSIP_EINVALIDMETHOD (PJSIP_ERRNO_START_PJSIP + 55) /* 171055 */ - +#define PJSIP_EINVALIDMETHOD (PJSIP_ERRNO_START_PJSIP + 55) /* 171055 */ /************************************************************ * TRANSPORT ERRORS @@ -202,23 +199,23 @@ PJ_BEGIN_DECL * @hideinitializer * Unsupported transport type. */ -#define PJSIP_EUNSUPTRANSPORT (PJSIP_ERRNO_START_PJSIP + 60) /* 171060 */ +#define PJSIP_EUNSUPTRANSPORT (PJSIP_ERRNO_START_PJSIP + 60) /* 171060 */ /** * @hideinitializer * Buffer is being sent, operation still pending. */ -#define PJSIP_EPENDINGTX (PJSIP_ERRNO_START_PJSIP + 61) /* 171061 */ +#define PJSIP_EPENDINGTX (PJSIP_ERRNO_START_PJSIP + 61) /* 171061 */ /** * @hideinitializer * Rx buffer overflow. See also PJSIP_EMSGTOOLONG. */ -#define PJSIP_ERXOVERFLOW (PJSIP_ERRNO_START_PJSIP + 62) /* 171062 */ +#define PJSIP_ERXOVERFLOW (PJSIP_ERRNO_START_PJSIP + 62) /* 171062 */ /** * @hideinitializer * This is not really an error, it just informs application that * transmit data has been deleted on return of pjsip_tx_data_dec_ref(). */ -#define PJSIP_EBUFDESTROYED (PJSIP_ERRNO_START_PJSIP + 63) /* 171063 */ +#define PJSIP_EBUFDESTROYED (PJSIP_ERRNO_START_PJSIP + 63) /* 171063 */ /** * @hideinitializer * Unsuitable transport selected. This error occurs when application @@ -226,14 +223,14 @@ PJ_BEGIN_DECL * but the selected transport is not suitable to send request to * the specified destination. */ -#define PJSIP_ETPNOTSUITABLE (PJSIP_ERRNO_START_PJSIP + 64) /* 171064 */ +#define PJSIP_ETPNOTSUITABLE (PJSIP_ERRNO_START_PJSIP + 64) /* 171064 */ /** * @hideinitializer * Transport not available. This error occurs for example when the SIP stack * is trying to use a SIP transport while the transport is being paused by * application. */ -#define PJSIP_ETPNOTAVAIL (PJSIP_ERRNO_START_PJSIP + 65) /* 171065 */ +#define PJSIP_ETPNOTAVAIL (PJSIP_ERRNO_START_PJSIP + 65) /* 171065 */ /************************************************************ * TRANSACTION ERRORS @@ -242,13 +239,12 @@ PJ_BEGIN_DECL * @hideinitializer * Transaction has just been destroyed. */ -#define PJSIP_ETSXDESTROYED (PJSIP_ERRNO_START_PJSIP + 70) /* 171070 */ +#define PJSIP_ETSXDESTROYED (PJSIP_ERRNO_START_PJSIP + 70) /* 171070 */ /** * @hideinitializer * No transaction. */ -#define PJSIP_ENOTSX (PJSIP_ERRNO_START_PJSIP + 71) /* 171071 */ - +#define PJSIP_ENOTSX (PJSIP_ERRNO_START_PJSIP + 71) /* 171071 */ /************************************************************ * URI COMPARISON RESULTS @@ -257,63 +253,62 @@ PJ_BEGIN_DECL * @hideinitializer * Scheme mismatch. */ -#define PJSIP_ECMPSCHEME (PJSIP_ERRNO_START_PJSIP + 80) /* 171080 */ +#define PJSIP_ECMPSCHEME (PJSIP_ERRNO_START_PJSIP + 80) /* 171080 */ /** * @hideinitializer * User part mismatch. */ -#define PJSIP_ECMPUSER (PJSIP_ERRNO_START_PJSIP + 81) /* 171081 */ +#define PJSIP_ECMPUSER (PJSIP_ERRNO_START_PJSIP + 81) /* 171081 */ /** * @hideinitializer * Password part mismatch. */ -#define PJSIP_ECMPPASSWD (PJSIP_ERRNO_START_PJSIP + 82) /* 171082 */ +#define PJSIP_ECMPPASSWD (PJSIP_ERRNO_START_PJSIP + 82) /* 171082 */ /** * @hideinitializer * Host part mismatch. */ -#define PJSIP_ECMPHOST (PJSIP_ERRNO_START_PJSIP + 83) /* 171083 */ +#define PJSIP_ECMPHOST (PJSIP_ERRNO_START_PJSIP + 83) /* 171083 */ /** * @hideinitializer * Port part mismatch. */ -#define PJSIP_ECMPPORT (PJSIP_ERRNO_START_PJSIP + 84) /* 171084 */ +#define PJSIP_ECMPPORT (PJSIP_ERRNO_START_PJSIP + 84) /* 171084 */ /** * @hideinitializer * Transport parameter part mismatch. */ -#define PJSIP_ECMPTRANSPORTPRM (PJSIP_ERRNO_START_PJSIP + 85) /* 171085 */ +#define PJSIP_ECMPTRANSPORTPRM (PJSIP_ERRNO_START_PJSIP + 85) /* 171085 */ /** * @hideinitializer * TTL parameter part mismatch. */ -#define PJSIP_ECMPTTLPARAM (PJSIP_ERRNO_START_PJSIP + 86) /* 171086 */ +#define PJSIP_ECMPTTLPARAM (PJSIP_ERRNO_START_PJSIP + 86) /* 171086 */ /** * @hideinitializer * User parameter part mismatch. */ -#define PJSIP_ECMPUSERPARAM (PJSIP_ERRNO_START_PJSIP + 87) /* 171087 */ +#define PJSIP_ECMPUSERPARAM (PJSIP_ERRNO_START_PJSIP + 87) /* 171087 */ /** * @hideinitializer * Method parameter part mismatch. */ -#define PJSIP_ECMPMETHODPARAM (PJSIP_ERRNO_START_PJSIP + 88) /* 171088 */ +#define PJSIP_ECMPMETHODPARAM (PJSIP_ERRNO_START_PJSIP + 88) /* 171088 */ /** * @hideinitializer * Maddr parameter part mismatch. */ -#define PJSIP_ECMPMADDRPARAM (PJSIP_ERRNO_START_PJSIP + 89) /* 171089 */ +#define PJSIP_ECMPMADDRPARAM (PJSIP_ERRNO_START_PJSIP + 89) /* 171089 */ /** * @hideinitializer * Parameter part in other_param mismatch. */ -#define PJSIP_ECMPOTHERPARAM (PJSIP_ERRNO_START_PJSIP + 90) /* 171090 */ +#define PJSIP_ECMPOTHERPARAM (PJSIP_ERRNO_START_PJSIP + 90) /* 171090 */ /** * @hideinitializer * Parameter part in header_param mismatch. */ -#define PJSIP_ECMPHEADERPARAM (PJSIP_ERRNO_START_PJSIP + 91) /* 171091 */ - +#define PJSIP_ECMPHEADERPARAM (PJSIP_ERRNO_START_PJSIP + 91) /* 171091 */ /************************************************************ * AUTHENTICATION FRAMEWORK @@ -326,7 +321,7 @@ PJ_BEGIN_DECL * (either with no stale parameter or with "stale=false" parameter). In most * cases, this indicates that the username/password combination is incorrect. */ -#define PJSIP_EFAILEDCREDENTIAL (PJSIP_ERRNO_START_PJSIP + 100) /* 171100 */ +#define PJSIP_EFAILEDCREDENTIAL (PJSIP_ERRNO_START_PJSIP + 100) /* 171100 */ /** * @hideinitializer * No suitable credential is found to authenticate the request against @@ -334,72 +329,72 @@ PJ_BEGIN_DECL * is caused by different realm supplied in the credential than the realm * found in the challenge. */ -#define PJSIP_ENOCREDENTIAL (PJSIP_ERRNO_START_PJSIP + 101) /* 171101 */ +#define PJSIP_ENOCREDENTIAL (PJSIP_ERRNO_START_PJSIP + 101) /* 171101 */ /** * @hideinitializer * Invalid/unsupported algorithm. */ -#define PJSIP_EINVALIDALGORITHM (PJSIP_ERRNO_START_PJSIP + 102) /* 171102 */ +#define PJSIP_EINVALIDALGORITHM (PJSIP_ERRNO_START_PJSIP + 102) /* 171102 */ /** * @hideinitializer * Invalid/unsupported qop. */ -#define PJSIP_EINVALIDQOP (PJSIP_ERRNO_START_PJSIP + 103) /* 171103 */ +#define PJSIP_EINVALIDQOP (PJSIP_ERRNO_START_PJSIP + 103) /* 171103 */ /** * @hideinitializer * Invalid/unsupported authentication scheme. */ -#define PJSIP_EINVALIDAUTHSCHEME (PJSIP_ERRNO_START_PJSIP + 104)/* 171104 */ +#define PJSIP_EINVALIDAUTHSCHEME (PJSIP_ERRNO_START_PJSIP + 104) /* 171104 */ /** * @hideinitializer * No previous challenge. */ -#define PJSIP_EAUTHNOPREVCHAL (PJSIP_ERRNO_START_PJSIP + 105) /* 171105 */ +#define PJSIP_EAUTHNOPREVCHAL (PJSIP_ERRNO_START_PJSIP + 105) /* 171105 */ /** * @hideinitializer * No authorization is found. */ -#define PJSIP_EAUTHNOAUTH (PJSIP_ERRNO_START_PJSIP + 106) /* 171106 */ +#define PJSIP_EAUTHNOAUTH (PJSIP_ERRNO_START_PJSIP + 106) /* 171106 */ /** * @hideinitializer * Account not found. */ -#define PJSIP_EAUTHACCNOTFOUND (PJSIP_ERRNO_START_PJSIP + 107) /* 171107 */ +#define PJSIP_EAUTHACCNOTFOUND (PJSIP_ERRNO_START_PJSIP + 107) /* 171107 */ /** * @hideinitializer * Account is disabled. */ -#define PJSIP_EAUTHACCDISABLED (PJSIP_ERRNO_START_PJSIP + 108) /* 171108 */ +#define PJSIP_EAUTHACCDISABLED (PJSIP_ERRNO_START_PJSIP + 108) /* 171108 */ /** * @hideinitializer * Invalid realm. */ -#define PJSIP_EAUTHINVALIDREALM (PJSIP_ERRNO_START_PJSIP + 109) /* 171109 */ +#define PJSIP_EAUTHINVALIDREALM (PJSIP_ERRNO_START_PJSIP + 109) /* 171109 */ /** * @hideinitializer * Invalid digest. */ -#define PJSIP_EAUTHINVALIDDIGEST (PJSIP_ERRNO_START_PJSIP+110) /* 171110 */ +#define PJSIP_EAUTHINVALIDDIGEST (PJSIP_ERRNO_START_PJSIP + 110) /* 171110 */ /** * @hideinitializer * Maximum number of stale retries exceeded. This happens when server * keeps rejecting our authorization request with stale=true. */ -#define PJSIP_EAUTHSTALECOUNT (PJSIP_ERRNO_START_PJSIP + 111) /* 171111 */ +#define PJSIP_EAUTHSTALECOUNT (PJSIP_ERRNO_START_PJSIP + 111) /* 171111 */ /** * @hideinitializer * Invalid nonce value in the challenge. */ -#define PJSIP_EAUTHINNONCE (PJSIP_ERRNO_START_PJSIP + 112) /* 171112 */ +#define PJSIP_EAUTHINNONCE (PJSIP_ERRNO_START_PJSIP + 112) /* 171112 */ /** * @hideinitializer * Invalid AKA credential. */ -#define PJSIP_EAUTHINAKACRED (PJSIP_ERRNO_START_PJSIP + 113) /* 171113 */ +#define PJSIP_EAUTHINAKACRED (PJSIP_ERRNO_START_PJSIP + 113) /* 171113 */ /** * No challenge is found in the challenge. */ -#define PJSIP_EAUTHNOCHAL (PJSIP_ERRNO_START_PJSIP + 114) /* 171114 */ +#define PJSIP_EAUTHNOCHAL (PJSIP_ERRNO_START_PJSIP + 114) /* 171114 */ /************************************************************ * UA AND DIALOG ERRORS @@ -408,17 +403,17 @@ PJ_BEGIN_DECL * @hideinitializer * Missing From/To tag. */ -#define PJSIP_EMISSINGTAG (PJSIP_ERRNO_START_PJSIP+120) /* 171120 */ +#define PJSIP_EMISSINGTAG (PJSIP_ERRNO_START_PJSIP + 120) /* 171120 */ /** * @hideinitializer * Expecting REFER method */ -#define PJSIP_ENOTREFER (PJSIP_ERRNO_START_PJSIP+121) /* 171121 */ +#define PJSIP_ENOTREFER (PJSIP_ERRNO_START_PJSIP + 121) /* 171121 */ /** * @hideinitializer * Not associated with REFER subscription */ -#define PJSIP_ENOREFERSESSION (PJSIP_ERRNO_START_PJSIP+122) /* 171122 */ +#define PJSIP_ENOREFERSESSION (PJSIP_ERRNO_START_PJSIP + 122) /* 171122 */ /************************************************************ * INVITE SESSIONS ERRORS @@ -427,18 +422,18 @@ PJ_BEGIN_DECL * @hideinitializer * Session already terminated. */ -#define PJSIP_ESESSIONTERMINATED (PJSIP_ERRNO_START_PJSIP+140) /* 171140 */ +#define PJSIP_ESESSIONTERMINATED (PJSIP_ERRNO_START_PJSIP + 140) /* 171140 */ /** * @hideinitializer * Invalid session state for the specified operation. */ -#define PJSIP_ESESSIONSTATE (PJSIP_ERRNO_START_PJSIP+141) /* 171141 */ +#define PJSIP_ESESSIONSTATE (PJSIP_ERRNO_START_PJSIP + 141) /* 171141 */ /** * @hideinitializer * The feature being requested requires the use of secure session or * transport. */ -#define PJSIP_ESESSIONINSECURE (PJSIP_ERRNO_START_PJSIP+142) /* 171142 */ +#define PJSIP_ESESSIONINSECURE (PJSIP_ERRNO_START_PJSIP + 142) /* 171142 */ /************************************************************ * TLS TRANSPORT ERRORS @@ -447,73 +442,78 @@ PJ_BEGIN_DECL * @hideinitializer * Unknown TLS error */ -#define PJSIP_TLS_EUNKNOWN (PJSIP_ERRNO_START_PJSIP+160) /* 171160 */ +#define PJSIP_TLS_EUNKNOWN (PJSIP_ERRNO_START_PJSIP + 160) /* 171160 */ /** * @hideinitializer * Invalid SSL protocol method. */ -#define PJSIP_TLS_EINVMETHOD (PJSIP_ERRNO_START_PJSIP+161) /* 171161 */ +#define PJSIP_TLS_EINVMETHOD (PJSIP_ERRNO_START_PJSIP + 161) /* 171161 */ /** * @hideinitializer * Error loading/verifying SSL CA list file. */ -#define PJSIP_TLS_ECACERT (PJSIP_ERRNO_START_PJSIP+162) /* 171162 */ +#define PJSIP_TLS_ECACERT (PJSIP_ERRNO_START_PJSIP + 162) /* 171162 */ /** * @hideinitializer * Error loading SSL certificate chain file. */ -#define PJSIP_TLS_ECERTFILE (PJSIP_ERRNO_START_PJSIP+163) /* 171163 */ +#define PJSIP_TLS_ECERTFILE (PJSIP_ERRNO_START_PJSIP + 163) /* 171163 */ /** * @hideinitializer * Error adding private key from SSL certificate file. */ -#define PJSIP_TLS_EKEYFILE (PJSIP_ERRNO_START_PJSIP+164) /* 171164 */ +#define PJSIP_TLS_EKEYFILE (PJSIP_ERRNO_START_PJSIP + 164) /* 171164 */ /** * @hideinitializer * Error setting SSL cipher list. */ -#define PJSIP_TLS_ECIPHER (PJSIP_ERRNO_START_PJSIP+165) /* 171165 */ +#define PJSIP_TLS_ECIPHER (PJSIP_ERRNO_START_PJSIP + 165) /* 171165 */ /** * @hideinitializer * Error creating SSL context. */ -#define PJSIP_TLS_ECTX (PJSIP_ERRNO_START_PJSIP+166) /* 171166 */ +#define PJSIP_TLS_ECTX (PJSIP_ERRNO_START_PJSIP + 166) /* 171166 */ /** * @hideinitializer * Error creating SSL connection object. */ -#define PJSIP_TLS_ESSLCONN (PJSIP_ERRNO_START_PJSIP+167) /* 171167 */ +#define PJSIP_TLS_ESSLCONN (PJSIP_ERRNO_START_PJSIP + 167) /* 171167 */ /** * @hideinitializer * Unknown error when performing SSL connect(). */ -#define PJSIP_TLS_ECONNECT (PJSIP_ERRNO_START_PJSIP+168) /* 171168 */ +#define PJSIP_TLS_ECONNECT (PJSIP_ERRNO_START_PJSIP + 168) /* 171168 */ /** * @hideinitializer * Unknown error when performing SSL accept(). */ -#define PJSIP_TLS_EACCEPT (PJSIP_ERRNO_START_PJSIP+169) /* 171169 */ +#define PJSIP_TLS_EACCEPT (PJSIP_ERRNO_START_PJSIP + 169) /* 171169 */ /** * @hideinitializer * Unknown error when sending SSL data */ -#define PJSIP_TLS_ESEND (PJSIP_ERRNO_START_PJSIP+170) /* 171170 */ +#define PJSIP_TLS_ESEND (PJSIP_ERRNO_START_PJSIP + 170) /* 171170 */ /** * @hideinitializer * Unknown error when reading SSL data */ -#define PJSIP_TLS_EREAD (PJSIP_ERRNO_START_PJSIP+171) /* 171171 */ +#define PJSIP_TLS_EREAD (PJSIP_ERRNO_START_PJSIP + 171) /* 171171 */ /** * @hideinitializer * SSL negotiation has exceeded the maximum configured timeout. */ -#define PJSIP_TLS_ETIMEDOUT (PJSIP_ERRNO_START_PJSIP+172) /* 171172 */ +#define PJSIP_TLS_ETIMEDOUT (PJSIP_ERRNO_START_PJSIP + 172) /* 171172 */ /** * @hideinitializer * SSL certificate verification error. */ -#define PJSIP_TLS_ECERTVERIF (PJSIP_ERRNO_START_PJSIP+173) /* 171173 */ +#define PJSIP_TLS_ECERTVERIF (PJSIP_ERRNO_START_PJSIP + 173) /* 171173 */ +/** + * @tqcq + * TODO impl + **/ +#define PJSIP_ETODO (PJSIP_ERRNO_START_PJSIP + 174) /* 171174 */ /** * Get error message for the specified error code. Note that this @@ -529,16 +529,12 @@ PJ_BEGIN_DECL * @return The error message as NULL terminated string, * wrapped with pj_str_t. */ -PJ_DECL(pj_str_t) pjsip_strerror(pj_status_t status, - char *buffer, pj_size_t bufsize); - +PJ_DECL(pj_str_t) pjsip_strerror(pj_status_t status, char *buffer, pj_size_t bufsize); PJ_END_DECL - /** * @} */ -#endif /* __PJSIP_SIP_ERRNO_H__ */ - +#endif /* __PJSIP_SIP_ERRNO_H__ */ diff --git a/pjsip/include/pjsip/sip_msg.h b/pjsip/include/pjsip/sip_msg.h index abf37c8..3d2005a 100644 --- a/pjsip/include/pjsip/sip_msg.h +++ b/pjsip/include/pjsip/sip_msg.h @@ -248,6 +248,7 @@ typedef enum pjsip_hdr_e PJSIP_H_VIA, PJSIP_H_WARNING_UNIMP, /* N/A, use pjsip_generic_string_hdr */ PJSIP_H_WWW_AUTHENTICATE, + PJSIP_H_SECURITY_INFO, PJSIP_H_OTHER diff --git a/pjsip/include/pjsua2/account.hpp b/pjsip/include/pjsua2/account.hpp index ad7d447..39b8095 100644 --- a/pjsip/include/pjsua2/account.hpp +++ b/pjsip/include/pjsua2/account.hpp @@ -28,8 +28,7 @@ #include /** PJSUA2 API is inside pj namespace */ -namespace pj -{ +namespace pj { /** * @defgroup PJSUA2_ACC Account @@ -42,8 +41,7 @@ using std::string; /** * Account registration config. This will be specified in AccountConfig. */ -struct AccountRegConfig : public PersistentObject -{ +struct AccountRegConfig : public PersistentObject { /** * This is the URL to be put in the request URI for the registration, * and will look something like "sip:serviceprovider". @@ -51,7 +49,7 @@ struct AccountRegConfig : public PersistentObject * This field should be specified if registration is desired. If the * value is empty, no account registration will be performed. */ - string registrarUri; + string registrarUri; /** * Specify whether the account should register as soon as it is @@ -60,7 +58,7 @@ struct AccountRegConfig : public PersistentObject * * Default: True */ - bool registerOnAdd; + bool registerOnAdd; /** * Specify whether account modification with Account::modify() should @@ -72,13 +70,13 @@ struct AccountRegConfig : public PersistentObject * * Default: false. */ - bool disableRegOnModify; + bool disableRegOnModify; /** * The optional custom SIP headers to be put in the registration * request. */ - SipHeaderVector headers; + SipHeaderVector headers; /** * Additional parameters that will be appended in the Contact header @@ -89,7 +87,7 @@ struct AccountRegConfig : public PersistentObject * be properly escaped. Example: * ";my-param=X;another-param=Hi%20there" */ - string contactParams; + string contactParams; /** * Additional parameters that will be appended in the Contact URI @@ -100,13 +98,13 @@ struct AccountRegConfig : public PersistentObject * be properly escaped. Example: * ";my-param=X;another-param=Hi%20there" */ - string contactUriParams; + string contactUriParams; /** * Optional interval for registration, in seconds. If the value is zero, * default interval will be used (PJSUA_REG_INTERVAL, 300 seconds). */ - unsigned timeoutSec; + unsigned timeoutSec; /** * Specify interval of auto registration retry upon registration failure @@ -123,7 +121,7 @@ struct AccountRegConfig : public PersistentObject * * Default: PJSUA_REG_RETRY_INTERVAL */ - unsigned retryIntervalSec; + unsigned retryIntervalSec; /** * This specifies the interval for the first registration retry. The @@ -136,7 +134,7 @@ struct AccountRegConfig : public PersistentObject * * Default: 0 */ - unsigned firstRetryIntervalSec; + unsigned firstRetryIntervalSec; /** * This specifies maximum randomized value to be added/substracted @@ -151,7 +149,7 @@ struct AccountRegConfig : public PersistentObject * * Default: 10 */ - unsigned randomRetryIntervalSec; + unsigned randomRetryIntervalSec; /** * Specify the number of seconds to refresh the client registration @@ -159,7 +157,7 @@ struct AccountRegConfig : public PersistentObject * * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds */ - unsigned delayBeforeRefreshSec; + unsigned delayBeforeRefreshSec; /** * Specify whether calls of the configured account should be dropped @@ -168,7 +166,7 @@ struct AccountRegConfig : public PersistentObject * * Default: FALSE (disabled) */ - bool dropCallsOnFail; + bool dropCallsOnFail; /** * Specify the maximum time to wait for unregistration requests to @@ -176,7 +174,7 @@ struct AccountRegConfig : public PersistentObject * * Default: PJSUA_UNREG_TIMEOUT */ - unsigned unregWaitMsec; + unsigned unregWaitMsec; /** * Specify how the registration uses the outbound and account proxy @@ -188,7 +186,7 @@ struct AccountRegConfig : public PersistentObject * * Default: 3 (PJSUA_REG_USE_OUTBOUND_PROXY | PJSUA_REG_USE_ACC_PROXY) */ - unsigned proxyUse; + unsigned proxyUse; public: /** @@ -204,7 +202,6 @@ public: * @param node Container to write values to. */ virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error); - }; /** Array of SIP credentials */ @@ -214,8 +211,7 @@ typedef std::vector AuthCredInfoVector; * Various SIP settings for the account. This will be specified in * AccountConfig. */ -struct AccountSipConfig : public PersistentObject -{ +struct AccountSipConfig : public PersistentObject { /** * Array of credentials. If registration is desired, normally there should * be at least one credential specified, to successfully authenticate @@ -223,20 +219,20 @@ struct AccountSipConfig : public PersistentObject * example when the requests are expected to be challenged by the * proxies in the route set. */ - AuthCredInfoVector authCreds; + AuthCredInfoVector authCreds; /** * Array of proxy servers to visit for outgoing requests. Each of the * entry is translated into one Route URI. */ - StringVector proxies; + StringVector proxies; /** * 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. */ - string contactForced; + string contactForced; /** * Additional parameters that will be appended in the Contact header @@ -248,7 +244,7 @@ struct AccountSipConfig : public PersistentObject * be properly escaped. Example: * ";my-param=X;another-param=Hi%20there" */ - string contactParams; + string contactParams; /** * Additional URI parameters that will be appended in the Contact URI @@ -260,21 +256,20 @@ struct AccountSipConfig : public PersistentObject * be properly escaped. Example: * ";my-param=X;another-param=Hi%20there" */ - string contactUriParams; - + string contactUriParams; /** * If this flag is set, the authentication client framework will * send an empty Authorization header in each initial request. * Default is no. */ - bool authInitialEmpty; + bool authInitialEmpty; /** * Specify the algorithm to use when empty Authorization header * is to be sent for each initial request (see above) */ - string authInitialAlgorithm; + string authInitialAlgorithm; /** * Optionally bind this account to specific transport. This normally is @@ -287,7 +282,7 @@ struct AccountSipConfig : public PersistentObject * * @see Account::setTransport() */ - TransportId transportId; + TransportId transportId; /** * Specify whether IPv6 should be used for SIP signalling. @@ -296,7 +291,7 @@ struct AccountSipConfig : public PersistentObject * (IP version used will be based on the address resolution * returned by OS/resolver) */ - pjsua_ipv6_use ipv6Use; + pjsua_ipv6_use ipv6Use; public: /** @@ -317,8 +312,7 @@ public: /** * Account's call settings. This will be specified in AccountConfig. */ -struct AccountCallConfig : public PersistentObject -{ +struct AccountCallConfig : public PersistentObject { /** * Specify how to offer call hold to remote peer. Please see the * documentation on pjsua_call_hold_type for more info. @@ -334,7 +328,7 @@ struct AccountCallConfig : public PersistentObject * * Default: PJSUA_100REL_NOT_USED */ - pjsua_100rel_use prackUse; + pjsua_100rel_use prackUse; /** * Specify the usage of Session Timers for all sessions. See the @@ -348,23 +342,24 @@ struct AccountCallConfig : public PersistentObject * Specify minimum Session Timer expiration period, in seconds. * Must not be lower than 90. Default is 90. */ - unsigned timerMinSESec; + unsigned timerMinSESec; /** * Specify Session Timer expiration period, in seconds. * Must not be lower than timerMinSE. Default is 1800. */ - unsigned timerSessExpiresSec; + unsigned timerSessExpiresSec; public: /** * Default constructor */ - AccountCallConfig() : holdType(PJSUA_CALL_HOLD_TYPE_DEFAULT), - prackUse(PJSUA_100REL_NOT_USED), - timerUse(PJSUA_SIP_TIMER_OPTIONAL), - timerMinSESec(90), - timerSessExpiresSec(PJSIP_SESS_TIMER_DEF_SE) + AccountCallConfig() + : holdType(PJSUA_CALL_HOLD_TYPE_DEFAULT), + prackUse(PJSUA_100REL_NOT_USED), + timerUse(PJSUA_SIP_TIMER_OPTIONAL), + timerMinSESec(90), + timerSessExpiresSec(PJSIP_SESS_TIMER_DEF_SE) {} /** @@ -385,13 +380,12 @@ public: /** * Account presence config. This will be specified in AccountConfig. */ -struct AccountPresConfig : public PersistentObject -{ +struct AccountPresConfig : public PersistentObject { /** * The optional custom SIP headers to be put in the presence * subscription request. */ - SipHeaderVector headers; + SipHeaderVector headers; /** * If this flag is set, the presence information of this account will @@ -399,7 +393,7 @@ struct AccountPresConfig : public PersistentObject * * Default: PJ_FALSE */ - bool publishEnabled; + bool publishEnabled; /** * Specify whether the client publication session should queue the @@ -410,7 +404,7 @@ struct AccountPresConfig : public PersistentObject * * Default: PJSIP_PUBLISHC_QUEUE_REQUEST (TRUE) */ - bool publishQueue; + bool publishQueue; /** * Maximum time to wait for unpublication transaction(s) to complete @@ -425,13 +419,13 @@ struct AccountPresConfig : public PersistentObject * * Default: PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC (2000) */ - unsigned publishShutdownWaitMsec; + unsigned publishShutdownWaitMsec; /** * Optional PIDF tuple ID for outgoing PUBLISH and NOTIFY. If this value * is not specified, a random string will be used. */ - string pidfTupleId; + string pidfTupleId; public: /** @@ -453,8 +447,7 @@ public: * Account MWI (Message Waiting Indication) settings. This will be specified * in AccountConfig. */ -struct AccountMwiConfig : public PersistentObject -{ +struct AccountMwiConfig : public PersistentObject { /** * Subscribe to message waiting indication events (RFC 3842). * @@ -462,7 +455,7 @@ struct AccountMwiConfig : public PersistentObject * * Default: FALSE */ - bool enabled; + bool enabled; /** * Specify the default expiration time (in seconds) for Message @@ -471,7 +464,7 @@ struct AccountMwiConfig : public PersistentObject * * Default: PJSIP_MWI_DEFAULT_EXPIRES (3600) */ - unsigned expirationSec; + unsigned expirationSec; public: /** @@ -493,49 +486,48 @@ public: * Account's NAT (Network Address Translation) settings. This will be * specified in AccountConfig. */ -struct AccountNatConfig : public PersistentObject -{ +struct AccountNatConfig : public PersistentObject { /** * Control the use of STUN for the SIP signaling. * * Default: PJSUA_STUN_USE_DEFAULT */ - pjsua_stun_use sipStunUse; + pjsua_stun_use sipStunUse; /** * Control the use of STUN for the media transports. * * Default: PJSUA_STUN_USE_DEFAULT */ - pjsua_stun_use mediaStunUse; + pjsua_stun_use mediaStunUse; /** * Control the use of UPnP for the SIP signaling. * * Default: PJSUA_UPNP_USE_DEFAULT */ - pjsua_upnp_use sipUpnpUse; + pjsua_upnp_use sipUpnpUse; /** * Control the use of UPnP for the media transports. * * Default: PJSUA_UPNP_USE_DEFAULT */ - pjsua_upnp_use mediaUpnpUse; + pjsua_upnp_use mediaUpnpUse; /** * Specify NAT64 options. * * Default: PJSUA_NAT64_DISABLED */ - pjsua_nat64_opt nat64Opt; + pjsua_nat64_opt nat64Opt; /** * Enable ICE for the media transport. * * Default: False */ - bool iceEnabled; + bool iceEnabled; /** * Set trickle ICE mode for ICE media transport. @@ -549,14 +541,14 @@ struct AccountNatConfig : public PersistentObject * * Default: -1 (maximum not set) */ - int iceMaxHostCands; + int iceMaxHostCands; /** * Specify whether to use aggressive nomination. * * Default: True */ - bool iceAggressiveNomination; + bool iceAggressiveNomination; /** * For controlling agent if it uses regular nomination, specify the delay @@ -565,7 +557,7 @@ struct AccountNatConfig : public PersistentObject * * Default value is PJ_ICE_NOMINATED_CHECK_DELAY. */ - unsigned iceNominatedCheckDelayMsec; + unsigned iceNominatedCheckDelayMsec; /** * For a controlled agent, specify how long it wants to wait (in @@ -579,14 +571,14 @@ struct AccountNatConfig : public PersistentObject * ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT. Specify -1 to disable * this timer. */ - int iceWaitNominationTimeoutMsec; + int iceWaitNominationTimeoutMsec; /** * Disable RTCP component. * * Default: False */ - bool iceNoRtcp; + bool iceNoRtcp; /** * Always send re-INVITE/UPDATE after ICE negotiation regardless of whether @@ -596,18 +588,18 @@ struct AccountNatConfig : public PersistentObject * * Default: yes */ - bool iceAlwaysUpdate; + bool iceAlwaysUpdate; /** * Enable TURN candidate in ICE. */ - bool turnEnabled; + bool turnEnabled; /** * Specify TURN domain name or host name, in in "DOMAIN:PORT" or * "HOST:PORT" format. */ - string turnServer; + string turnServer; /** * Specify the connection type to be used to the TURN server. Valid @@ -615,23 +607,23 @@ struct AccountNatConfig : public PersistentObject * * Default: PJ_TURN_TP_UDP */ - pj_turn_tp_type turnConnType; + pj_turn_tp_type turnConnType; /** * Specify the username to authenticate with the TURN server. */ - string turnUserName; + string turnUserName; /** * Specify the type of password. Currently this must be zero to * indicate plain-text password will be used in the password. */ - int turnPasswordType; + int turnPasswordType; /** * Specify the password to authenticate with the TURN server. */ - string turnPassword; + string turnPassword; /** * This option is used to update the transport address and the Contact @@ -653,7 +645,7 @@ struct AccountNatConfig : public PersistentObject * * Default: 1 */ - int contactRewriteUse; + int contactRewriteUse; /** * Specify how Contact update will be done with the registration, if @@ -665,7 +657,7 @@ struct AccountNatConfig : public PersistentObject * Default value: PJSUA_CONTACT_REWRITE_METHOD * (PJSUA_CONTACT_REWRITE_NO_UNREG | PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE) */ - int contactRewriteMethod; + int contactRewriteMethod; /** * Specify if source TCP port should be used as the initial Contact @@ -678,7 +670,7 @@ struct AccountNatConfig : public PersistentObject * * Default: 1 (PJ_TRUE / yes). */ - int contactUseSrcPort; + int contactUseSrcPort; /** * This option is used to overwrite the "sent-by" field of the Via header @@ -688,7 +680,7 @@ struct AccountNatConfig : public PersistentObject * * Default: 1 (PJ_TRUE / yes) */ - int viaRewriteUse; + int viaRewriteUse; /** * This option controls whether the IP address in SDP should be replaced @@ -700,7 +692,7 @@ struct AccountNatConfig : public PersistentObject * * Default: PJ_FALSE (no) */ - int sdpNatRewriteUse; + int sdpNatRewriteUse; /** * Control the use of SIP outbound feature. SIP outbound is described in @@ -715,7 +707,7 @@ struct AccountNatConfig : public PersistentObject * * Default: 1 (PJ_TRUE / yes) */ - int sipOutboundUse; + int sipOutboundUse; /** * Specify SIP outbound (RFC 5626) instance ID to be used by this @@ -726,7 +718,7 @@ struct AccountNatConfig : public PersistentObject * * Default: empty */ - string sipOutboundInstanceId; + string sipOutboundInstanceId; /** * Specify SIP outbound (RFC 5626) registration ID. The default value @@ -735,7 +727,7 @@ struct AccountNatConfig : public PersistentObject * * Default: empty */ - string sipOutboundRegId; + string sipOutboundRegId; /** * Set the interval for periodic keep-alive transmission for this account. @@ -745,43 +737,44 @@ struct AccountNatConfig : public PersistentObject * * Default: 15 (seconds) */ - unsigned udpKaIntervalSec; + unsigned udpKaIntervalSec; /** * Specify the data to be transmitted as keep-alive packets. * * Default: CR-LF */ - string udpKaData; + string udpKaData; public: /** * Default constructor */ - AccountNatConfig() : sipStunUse(PJSUA_STUN_USE_DEFAULT), - mediaStunUse(PJSUA_STUN_USE_DEFAULT), - sipUpnpUse(PJSUA_UPNP_USE_DEFAULT), - mediaUpnpUse(PJSUA_UPNP_USE_DEFAULT), - nat64Opt(PJSUA_NAT64_DISABLED), - iceEnabled(false), - iceTrickle(PJ_ICE_SESS_TRICKLE_DISABLED), - iceMaxHostCands(-1), - iceAggressiveNomination(true), - iceNominatedCheckDelayMsec(PJ_ICE_NOMINATED_CHECK_DELAY), - iceWaitNominationTimeoutMsec(ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT), - iceNoRtcp(false), - iceAlwaysUpdate(true), - turnEnabled(false), - turnConnType(PJ_TURN_TP_UDP), - turnPasswordType(0), - contactRewriteUse(PJ_TRUE), - contactRewriteMethod(PJSUA_CONTACT_REWRITE_METHOD), - contactUseSrcPort(PJ_TRUE), - viaRewriteUse(PJ_TRUE), - sdpNatRewriteUse(PJ_FALSE), - sipOutboundUse(PJ_TRUE), - udpKaIntervalSec(15), - udpKaData("\r\n") + AccountNatConfig() + : sipStunUse(PJSUA_STUN_USE_DEFAULT), + mediaStunUse(PJSUA_STUN_USE_DEFAULT), + sipUpnpUse(PJSUA_UPNP_USE_DEFAULT), + mediaUpnpUse(PJSUA_UPNP_USE_DEFAULT), + nat64Opt(PJSUA_NAT64_DISABLED), + iceEnabled(false), + iceTrickle(PJ_ICE_SESS_TRICKLE_DISABLED), + iceMaxHostCands(-1), + iceAggressiveNomination(true), + iceNominatedCheckDelayMsec(PJ_ICE_NOMINATED_CHECK_DELAY), + iceWaitNominationTimeoutMsec(ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT), + iceNoRtcp(false), + iceAlwaysUpdate(true), + turnEnabled(false), + turnConnType(PJ_TURN_TP_UDP), + turnPasswordType(0), + contactRewriteUse(PJ_TRUE), + contactRewriteMethod(PJSUA_CONTACT_REWRITE_METHOD), + contactUseSrcPort(PJ_TRUE), + viaRewriteUse(PJ_TRUE), + sdpNatRewriteUse(PJ_FALSE), + sipOutboundUse(PJ_TRUE), + udpKaIntervalSec(15), + udpKaData("\r\n") {} /** @@ -802,24 +795,23 @@ public: /** * This structure contains parameters for Account::sendRequest() */ -struct SendRequestParam -{ +struct SendRequestParam { /** * Token or arbitrary user data ownd by the application, * which will be passed back in callback Account::onSendRequest(). */ - Token userData; + Token userData; /** * SIP method of the request. */ - string method; + string method; /** * Message body and/or list of headers etc. to be included in * the outgoing request. */ - SipTxOption txOption; + SipTxOption txOption; public: /** @@ -828,27 +820,24 @@ public: SendRequestParam(); }; - - /** * SRTP crypto. */ -struct SrtpCrypto -{ +struct SrtpCrypto { /** * Optional key. If empty, a random key will be autogenerated. */ - string key; + string key; /** * Crypto name. */ - string name; + string name; /** * Flags, bitmask from #pjmedia_srtp_crypto_option */ - unsigned flags; + unsigned flags; public: /** @@ -868,15 +857,14 @@ typedef std::vector SrtpCryptoVector; /** * SRTP settings. */ -struct SrtpOpt : public PersistentObject -{ +struct SrtpOpt : public PersistentObject { /** * Specify SRTP cryptos. If empty, all crypto will be enabled. * Available crypto can be enumerated using Endpoint::srtpCryptoEnum(). * * Default: empty. */ - SrtpCryptoVector cryptos; + SrtpCryptoVector cryptos; /** * Specify SRTP keying methods, valid keying method is defined in @@ -885,7 +873,7 @@ struct SrtpOpt : public PersistentObject * * Default: empty. */ - IntVector keyings; + IntVector keyings; public: /** @@ -922,37 +910,35 @@ public: /** * RTCP Feedback capability. */ -struct RtcpFbCap -{ +struct RtcpFbCap { /** * Specify the codecs to which the capability is applicable. Codec ID is * using the same format as in pjmedia_codec_mgr_find_codecs_by_id() and * pjmedia_vid_codec_mgr_find_codecs_by_id(), e.g: "L16/8000/1", "PCMU", * "H264". This can also be an asterisk ("*") to represent all codecs. */ - string codecId; + string codecId; /** * Specify the RTCP Feedback type. */ - pjmedia_rtcp_fb_type type; + pjmedia_rtcp_fb_type type; /** * Specify the type name if RTCP Feedback type is PJMEDIA_RTCP_FB_OTHER. */ - string typeName; + string typeName; /** * Specify the RTCP Feedback parameters. */ - string param; + string param; public: /** * Constructor. */ - RtcpFbCap() : type(PJMEDIA_RTCP_FB_OTHER) - {} + RtcpFbCap() : type(PJMEDIA_RTCP_FB_OTHER) {} /** * Convert from pjsip @@ -968,12 +954,10 @@ public: /** Array of RTCP Feedback capabilities. */ typedef std::vector RtcpFbCapVector; - /** * RTCP Feedback settings. */ -struct RtcpFbConfig : public PersistentObject -{ +struct RtcpFbConfig : public PersistentObject { /** * Specify whether transport protocol in SDP media description uses * RTP/AVP instead of RTP/AVPF. Note that the standard mandates to signal @@ -983,12 +967,12 @@ struct RtcpFbConfig : public PersistentObject * * Default: false. */ - bool dontUseAvpf; + bool dontUseAvpf; /** * RTCP Feedback capabilities. */ - RtcpFbCapVector caps; + RtcpFbCapVector caps; public: /** @@ -1026,8 +1010,7 @@ public: * Account media config (applicable for both audio and video). This will be * specified in AccountConfig. */ -struct AccountMediaConfig : public PersistentObject -{ +struct AccountMediaConfig : public PersistentObject { /** * Media transport (RTP) configuration. * @@ -1037,7 +1020,7 @@ struct AccountMediaConfig : public PersistentObject * - Available ports: 5000, 5002, 5004 (Media/RTP transport) * 5001, 5003, 5005 (Media/RTCP transport) */ - TransportConfig transportConfig; + TransportConfig transportConfig; /** * If remote sends SDP answer containing more than one format or codec in @@ -1046,7 +1029,7 @@ struct AccountMediaConfig : public PersistentObject * * Default: True (Yes). */ - bool lockCodecEnabled; + bool lockCodecEnabled; /** * Specify whether stream keep-alive and NAT hole punching with @@ -1055,7 +1038,7 @@ struct AccountMediaConfig : public PersistentObject * * Default: False */ - bool streamKaEnabled; + bool streamKaEnabled; /** * Specify whether secure media transport should be used for this account. @@ -1064,7 +1047,7 @@ struct AccountMediaConfig : public PersistentObject * * Default: PJSUA_DEFAULT_USE_SRTP */ - pjmedia_srtp_use srtpUse; + pjmedia_srtp_use srtpUse; /** * Specify whether SRTP requires secure signaling to be used. This option @@ -1077,12 +1060,12 @@ struct AccountMediaConfig : public PersistentObject * * Default: PJSUA_DEFAULT_SRTP_SECURE_SIGNALING */ - int srtpSecureSignaling; + int srtpSecureSignaling; /** * Specify SRTP settings, like cryptos and keying methods. */ - SrtpOpt srtpOpt; + SrtpOpt srtpOpt; /** * Specify whether IPv6 should be used on media. @@ -1091,25 +1074,25 @@ struct AccountMediaConfig : public PersistentObject * (Dual stack media, capable to use IPv4/IPv6. * Outgoing offer will prefer to use IPv4) */ - pjsua_ipv6_use ipv6Use; + pjsua_ipv6_use ipv6Use; /** * Enable RTP and RTCP multiplexing. * Default: false */ - bool rtcpMuxEnabled; + bool rtcpMuxEnabled; /** * RTCP Feedback settings. */ - RtcpFbConfig rtcpFbConfig; + RtcpFbConfig rtcpFbConfig; /** * Enable RTCP Extended Report (RTCP XR). * * Default: PJMEDIA_STREAM_ENABLE_XR */ - bool rtcpXrEnabled; + bool rtcpXrEnabled; /** * Use loopback media transport. This may be useful if application @@ -1118,7 +1101,7 @@ struct AccountMediaConfig : public PersistentObject * * Default: false */ - bool useLoopMedTp; + bool useLoopMedTp; /** * Enable local loopback when useLoopMedTp is set to TRUE. @@ -1127,22 +1110,22 @@ struct AccountMediaConfig : public PersistentObject * * Default: false */ - bool enableLoopback; + bool enableLoopback; public: /** * Default constructor */ - AccountMediaConfig() - : lockCodecEnabled(true), - streamKaEnabled(false), - srtpUse(PJSUA_DEFAULT_USE_SRTP), - srtpSecureSignaling(PJSUA_DEFAULT_SRTP_SECURE_SIGNALING), - ipv6Use(PJSUA_IPV6_ENABLED_PREFER_IPV4), - rtcpMuxEnabled(false), - rtcpXrEnabled(PJMEDIA_STREAM_ENABLE_XR), - useLoopMedTp(false), - enableLoopback(false) + AccountMediaConfig() + : lockCodecEnabled(true), + streamKaEnabled(false), + srtpUse(PJSUA_DEFAULT_USE_SRTP), + srtpSecureSignaling(PJSUA_DEFAULT_SRTP_SECURE_SIGNALING), + ipv6Use(PJSUA_IPV6_ENABLED_PREFER_IPV4), + rtcpMuxEnabled(false), + rtcpXrEnabled(PJMEDIA_STREAM_ENABLE_XR), + useLoopMedTp(false), + enableLoopback(false) {} /** @@ -1163,8 +1146,7 @@ public: /** * Account video config. This will be specified in AccountConfig. */ -struct AccountVideoConfig : public PersistentObject -{ +struct AccountVideoConfig : public PersistentObject { /** * Specify whether incoming video should be shown to screen by default. * This applies to incoming call (INVITE), incoming re-INVITE, and @@ -1179,7 +1161,7 @@ struct AccountVideoConfig : public PersistentObject * * Default: False */ - bool autoShowIncoming; + bool autoShowIncoming; /** * Specify whether outgoing video should be activated by default when @@ -1194,7 +1176,7 @@ struct AccountVideoConfig : public PersistentObject * * Default: False */ - bool autoTransmitOutgoing; + bool autoTransmitOutgoing; /** * Specify video window's flags. The value is a bitmask combination of @@ -1202,7 +1184,7 @@ struct AccountVideoConfig : public PersistentObject * * Default: 0 */ - unsigned windowFlags; + unsigned windowFlags; /** * Specify the default capture device to be used by this account. If @@ -1211,14 +1193,14 @@ struct AccountVideoConfig : public PersistentObject * * Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV */ - pjmedia_vid_dev_index defaultCaptureDevice; + pjmedia_vid_dev_index defaultCaptureDevice; /** * Specify the default rendering device to be used by this account. * * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV */ - pjmedia_vid_dev_index defaultRenderDevice; + pjmedia_vid_dev_index defaultRenderDevice; /** * Rate control method. @@ -1233,37 +1215,36 @@ struct AccountVideoConfig : public PersistentObject * * Default: 0 (follow codec maximum bitrate). */ - unsigned rateControlBandwidth; + unsigned rateControlBandwidth; /** * The number of keyframe to be sent after the stream is created. * * Default: PJMEDIA_VID_STREAM_START_KEYFRAME_CNT */ - unsigned startKeyframeCount; + unsigned startKeyframeCount; /** * The keyframe sending interval after the stream is created. * * Default: PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC */ - unsigned startKeyframeInterval; - + unsigned startKeyframeInterval; public: /** * Default constructor */ - AccountVideoConfig() - : autoShowIncoming(false), - autoTransmitOutgoing(false), - windowFlags(0), - defaultCaptureDevice(PJMEDIA_VID_DEFAULT_CAPTURE_DEV), - defaultRenderDevice(PJMEDIA_VID_DEFAULT_RENDER_DEV), - rateControlMethod(PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING), - rateControlBandwidth(0), - startKeyframeCount(PJMEDIA_VID_STREAM_START_KEYFRAME_CNT), - startKeyframeInterval(PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC) + AccountVideoConfig() + : autoShowIncoming(false), + autoTransmitOutgoing(false), + windowFlags(0), + defaultCaptureDevice(PJMEDIA_VID_DEFAULT_CAPTURE_DEV), + defaultRenderDevice(PJMEDIA_VID_DEFAULT_RENDER_DEV), + rateControlMethod(PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING), + rateControlBandwidth(0), + startKeyframeCount(PJMEDIA_VID_STREAM_START_KEYFRAME_CNT), + startKeyframeInterval(PJMEDIA_VID_STREAM_START_KEYFRAME_INTERVAL_MSEC) {} /** @@ -1284,8 +1265,7 @@ public: /** * Account config specific to IP address change. */ -typedef struct AccountIpChangeConfig -{ +typedef struct AccountIpChangeConfig { /** * Shutdown the transport used for account registration. If this is set to * PJ_TRUE, the transport will be shutdown altough it's used by multiple @@ -1294,7 +1274,7 @@ typedef struct AccountIpChangeConfig * * Default: true */ - bool shutdownTp; + bool shutdownTp; /** * Hangup active calls associated with the acount. If this is set to true, @@ -1302,7 +1282,7 @@ typedef struct AccountIpChangeConfig * * Default: false */ - bool hangupCalls; + bool hangupCalls; /** * Specify the call flags used in the re-INVITE when \a hangupCalls is set @@ -1312,7 +1292,7 @@ typedef struct AccountIpChangeConfig * Default: PJSUA_CALL_REINIT_MEDIA | PJSUA_CALL_UPDATE_CONTACT | * PJSUA_CALL_UPDATE_VIA */ - unsigned reinviteFlags; + unsigned reinviteFlags; /** * For refreshing the call, use SIP UPDATE, instead of re-INVITE, if @@ -1323,14 +1303,13 @@ typedef struct AccountIpChangeConfig * * Default: PJ_FALSE (using re-INVITE). */ - unsigned reinvUseUpdate; + unsigned reinvUseUpdate; public: /** * Virtual destructor */ - virtual ~AccountIpChangeConfig() - {} + virtual ~AccountIpChangeConfig() {} /** * Read this object from a container node. @@ -1345,20 +1324,19 @@ public: * @param node Container to write values to. */ virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error); - + } AccountIpChangeConfig; /** * Account configuration. */ -struct AccountConfig : public PersistentObject -{ +struct AccountConfig : public PersistentObject { /** * Account priority, which is used to control the order of matching * incoming/outgoing requests. The higher the number means the higher * the priority is, and the account will be matched first. */ - int priority; + int priority; /** * The Address of Record or AOR, that is full SIP URL that identifies the @@ -1367,47 +1345,47 @@ struct AccountConfig : public PersistentObject * * This field is mandatory. */ - string idUri; + string idUri; /** * Registration settings. */ - AccountRegConfig regConfig; + AccountRegConfig regConfig; /** * SIP settings. */ - AccountSipConfig sipConfig; + AccountSipConfig sipConfig; /** * Call settings. */ - AccountCallConfig callConfig; + AccountCallConfig callConfig; /** * Presence settings. */ - AccountPresConfig presConfig; + AccountPresConfig presConfig; /** * MWI (Message Waiting Indication) settings. */ - AccountMwiConfig mwiConfig; + AccountMwiConfig mwiConfig; /** * NAT settings. */ - AccountNatConfig natConfig; + AccountNatConfig natConfig; /** * Media settings (applicable for both audio and video). */ - AccountMediaConfig mediaConfig; + AccountMediaConfig mediaConfig; /** * Video settings. */ - AccountVideoConfig videoConfig; + AccountVideoConfig videoConfig; /** * IP Change settings. @@ -1449,56 +1427,54 @@ public: virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error); }; - /** * Account information. Application can query the account information * by calling Account::getInfo(). */ -struct AccountInfo -{ +struct AccountInfo { /** * The account ID. */ - pjsua_acc_id id; + pjsua_acc_id id; /** * Flag to indicate whether this is the default account. */ - bool isDefault; + bool isDefault; /** * Account URI */ - string uri; + string uri; /** * Flag to tell whether this account has registration setting * (reg_uri is not empty). */ - bool regIsConfigured; + bool regIsConfigured; /** * Flag to tell whether this account is currently registered * (has active registration session). */ - bool regIsActive; + bool regIsActive; /** * An up to date expiration interval for account registration session. */ - unsigned regExpiresSec; + unsigned regExpiresSec; /** * 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 regStatus; + pjsip_status_code regStatus; /** * String describing the registration status. */ - string regStatusText; + string regStatusText; /** * Last registration error code. When the status field contains a SIP @@ -1506,30 +1482,31 @@ struct AccountInfo * error code contains the error code that causes the failure. In any * other case, its value is zero. */ - pj_status_t regLastErr; + pj_status_t regLastErr; /** * Presence online status for this account. */ - bool onlineStatus; + bool onlineStatus; /** * Presence online status text. */ - string onlineStatusText; + string onlineStatusText; public: /** * Default constructor */ - AccountInfo() : id(PJSUA_INVALID_ID), - isDefault(false), - regIsConfigured(false), - regIsActive(false), - regExpiresSec(0), - regStatus(PJSIP_SC_NULL), - regLastErr(-1), - onlineStatus(false) + AccountInfo() + : id(PJSUA_INVALID_ID), + isDefault(false), + regIsConfigured(false), + regIsActive(false), + regExpiresSec(0), + regStatus(PJSIP_SC_NULL), + regLastErr(-1), + onlineStatus(false) {} /** Import from pjsip data */ @@ -1539,24 +1516,22 @@ public: /** * This structure contains parameters for onIncomingCall() account callback. */ -struct OnIncomingCallParam -{ +struct OnIncomingCallParam { /** * The library call ID allocated for the new call. */ - int callId; + int callId; /** * The incoming INVITE request. */ - SipRxData rdata; + SipRxData rdata; }; /** * This structure contains parameters for onRegStarted() account callback. */ -struct OnRegStartedParam -{ +struct OnRegStartedParam { /** * True for registration and False for unregistration. */ @@ -1566,255 +1541,245 @@ struct OnRegStartedParam /** * This structure contains parameters for onRegState() account callback. */ -struct OnRegStateParam -{ +struct OnRegStateParam { /** * Registration operation status. */ - pj_status_t status; + pj_status_t status; /** * SIP status code received. */ - pjsip_status_code code; + pjsip_status_code code; /** * SIP reason phrase received. */ - string reason; + string reason; /** * The incoming message. */ - SipRxData rdata; + SipRxData rdata; /** * Next expiration interval. */ - unsigned expiration; + unsigned expiration; }; /** * This structure contains parameters for onIncomingSubscribe() callback. */ -struct OnIncomingSubscribeParam -{ +struct OnIncomingSubscribeParam { /** * Server presence subscription instance. If application delays * the acceptance of the request, it will need to specify this object * when calling Account::presNotify(). */ - void *srvPres; + void *srvPres; /** * Sender URI. */ - string fromUri; + string fromUri; /** * The incoming message. */ - SipRxData rdata; + SipRxData rdata; /** * 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. */ - 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; + SipTxOption txOption; }; /** * Parameters for onInstantMessage() account callback. */ -struct OnInstantMessageParam -{ +struct OnInstantMessageParam { /** * Sender From URI. */ - string fromUri; + string fromUri; /** * To URI of the request. */ - string toUri; + string toUri; /** * Contact URI of the sender. */ - string contactUri; + string contactUri; /** * MIME type of the message body. */ - string contentType; + string contentType; /** * The message body. */ - string msgBody; + string msgBody; /** * The whole message. */ - SipRxData rdata; + SipRxData rdata; }; /** * Parameters for onInstantMessageStatus() account callback. */ -struct OnInstantMessageStatusParam -{ +struct OnInstantMessageStatusParam { /** * Token or a user data that was associated with the pager * transmission. */ - Token userData; + Token userData; /** * Destination URI. */ - string toUri; + string toUri; /** * The message body. */ - string msgBody; + string msgBody; /** * The SIP status code of the transaction. */ - pjsip_status_code code; + pjsip_status_code code; /** * The reason phrase of the transaction. */ - string reason; + 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; + SipRxData rdata; }; /** * Parameters for onTypingIndication() account callback. */ -struct OnTypingIndicationParam -{ +struct OnTypingIndicationParam { /** * Sender/From URI. */ - string fromUri; + string fromUri; /** * To URI. */ - string toUri; + string toUri; /** * The Contact URI. */ - string contactUri; + string contactUri; /** * Boolean to indicate if sender is typing. */ - bool isTyping; + bool isTyping; /** * The whole message buffer. */ - SipRxData rdata; + SipRxData rdata; }; /** * Parameters for onMwiInfo() account callback. */ -struct OnMwiInfoParam -{ +struct OnMwiInfoParam { /** * MWI subscription state. */ - pjsip_evsub_state state; + pjsip_evsub_state state; /** * The whole message buffer. */ - SipRxData rdata; + SipRxData rdata; }; /** * This structure contains parameters for Account::onSendRequest() callback. */ -struct OnSendRequestParam -{ +struct OnSendRequestParam { /** * Token or arbitrary user data owned by the application, * which was passed to Endpoint::sendRquest() function. */ - Token userData; + Token userData; /** * Transaction event that caused the state change. */ - SipEvent e; + SipEvent e; }; - /** * Parameters for presNotify() account method. */ -struct PresNotifyParam -{ +struct PresNotifyParam { /** * Server presence subscription instance. */ - void *srvPres; + void *srvPres; /** * Server presence subscription state to set. */ - pjsip_evsub_state state; - + pjsip_evsub_state state; + /** * Optionally specify the state string name, if state is not "active", * "pending", or "terminated". */ - string stateStr; + string stateStr; /** * If the new state is PJSIP_EVSUB_STATE_TERMINATED, optionally specify * the termination reason. */ - string reason; + string reason; /** * If the new state is PJSIP_EVSUB_STATE_TERMINATED, this specifies * whether the NOTIFY request should contain message body containing * account's presence information. */ - bool withBody; + bool withBody; /** * Optional list of headers to be sent with the NOTIFY request. */ - SipTxOption txOption; + SipTxOption txOption; }; - /** * Wrapper class for Buddy matching algo. * @@ -1823,8 +1788,7 @@ struct PresNotifyParam * matching algo by overriding this class and specifying its instance * in Account::findBuddy(). */ -class FindBuddyMatch -{ +class FindBuddyMatch { public: /** * Default algo implementation. @@ -1841,12 +1805,10 @@ public: virtual ~FindBuddyMatch() {} }; - /** * Account. */ -class Account -{ +class Account { public: /** * Constructor. @@ -1877,8 +1839,7 @@ public: * @param cfg The account config. * @param make_default Make this the default account. */ - void create(const AccountConfig &cfg, - bool make_default=false) PJSUA2_THROW(Error); + void create(const AccountConfig &cfg, bool make_default = false) PJSUA2_THROW(Error); /** * Shutdown the account. This will initiate unregistration if needed, @@ -1960,7 +1921,7 @@ public: * @param prm.txOption Optional message body and/or list of headers to be * included in outgoing request. */ - void sendRequest(const pj::SendRequestParam& prm) PJSUA2_THROW(Error); + void sendRequest(const pj::SendRequestParam &prm) PJSUA2_THROW(Error); /** * Update registration or perform unregistration. Application normally @@ -2008,7 +1969,7 @@ public: * @param prm The sending NOTIFY parameter. */ void presNotify(const PresNotifyParam &prm) PJSUA2_THROW(Error); - + #if !DEPRECATED_FOR_TICKET_2232 /** * Warning: deprecated, use enumBuddies2() instead. This function is not @@ -2018,7 +1979,7 @@ public: * * @return The buddy list. */ - const BuddyVector& enumBuddies() const PJSUA2_THROW(Error); + const BuddyVector &enumBuddies() const PJSUA2_THROW(Error); #endif /** @@ -2042,8 +2003,7 @@ public: * * @return The pointer to buddy. */ - Buddy* findBuddy(string uri, FindBuddyMatch *buddy_match = NULL) const - PJSUA2_THROW(Error); + Buddy *findBuddy(string uri, FindBuddyMatch *buddy_match = NULL) const PJSUA2_THROW(Error); #endif /** @@ -2066,8 +2026,7 @@ public: * * @param prm Callback parameter. */ - virtual void onIncomingCall(OnIncomingCallParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onIncomingCall(OnIncomingCallParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notify application when registration or unregistration has been @@ -2077,8 +2036,7 @@ public: * * @param prm Callback parameter. */ - virtual void onRegStarted(OnRegStartedParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onRegStarted(OnRegStartedParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notify application when registration status has changed. @@ -2087,8 +2045,7 @@ public: * * @param prm Callback parameter. */ - virtual void onRegState(OnRegStateParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onRegState(OnRegStateParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notification when incoming SUBSCRIBE request is received. Application @@ -2122,8 +2079,7 @@ public: * * @param prm Callback parameter. */ - virtual void onIncomingSubscribe(OnIncomingSubscribeParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onIncomingSubscribe(OnIncomingSubscribeParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notify application on incoming instant message or pager (i.e. MESSAGE @@ -2131,8 +2087,7 @@ public: * * @param prm Callback parameter. */ - virtual void onInstantMessage(OnInstantMessageParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onInstantMessage(OnInstantMessageParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notify application about the delivery status of outgoing pager/instant @@ -2140,8 +2095,7 @@ public: * * @param prm Callback parameter. */ - virtual void onInstantMessageStatus(OnInstantMessageStatusParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onInstantMessageStatus(OnInstantMessageStatusParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notify application when a transaction started by Account::sendRequest() @@ -2149,16 +2103,14 @@ public: * * @param prm Callback parameter. */ - virtual void onSendRequest(OnSendRequestParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onSendRequest(OnSendRequestParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notify application about typing indication. * * @param prm Callback parameter. */ - virtual void onTypingIndication(OnTypingIndicationParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onTypingIndication(OnTypingIndicationParam &prm) { PJ_UNUSED_ARG(prm); } /** * Notification about MWI (Message Waiting Indication) status change. @@ -2168,8 +2120,7 @@ public: * * @param prm Callback parameter. */ - virtual void onMwiInfo(OnMwiInfoParam &prm) - { PJ_UNUSED_ARG(prm); } + virtual void onMwiInfo(OnMwiInfoParam &prm) { PJ_UNUSED_ARG(prm); } private: friend class Endpoint; @@ -2188,10 +2139,10 @@ private: void removeBuddy(Buddy *buddy); private: - pjsua_acc_id id; - string tmpReason; // for saving response's reason + pjsua_acc_id id; + string tmpReason;// for saving response's reason #if !DEPRECATED_FOR_TICKET_2232 - BuddyVector buddyList; + BuddyVector buddyList; #endif }; @@ -2199,7 +2150,6 @@ private: * @} // PJSUA2_ACC */ -} // namespace pj - -#endif /* __PJSUA2_ACCOUNT_HPP__ */ +}// namespace pj +#endif /* __PJSUA2_ACCOUNT_HPP__ */ diff --git a/pjsip/include/pjsua2/endpoint.hpp b/pjsip/include/pjsua2/endpoint.hpp index cb78cc3..ce38317 100644 --- a/pjsip/include/pjsua2/endpoint.hpp +++ b/pjsip/include/pjsua2/endpoint.hpp @@ -611,6 +611,41 @@ struct DigestCredential pjsip_digest_credential toPj() const; }; +struct GBCredential { + /** + * Realm of the credential + */ + std::string realm; + + /** + * Other parameters. + */ + StringToStringMap otherParam; + + std::string algorithm; + std::string keyversion; + std::string random1; + std::string random2; + std::string deviceid; + std::string serverid; + std::string sign1; + std::string sign2; + std::string cryptkey; + std::string cryptkey1; + std::string cryptkey2; + std::string certificate; + + /** + * Convert from pjsip + */ + void fromPj(const pjsip_gb_credential &prm); + + /** + * Convert to pjsip + */ + pjsip_gb_credential toPj() const; +}; +typedef GBCredential GBChallenge ; /** * Parameter of Endpoint::onCredAuth() callback. @@ -623,6 +658,7 @@ struct OnCredAuthParam * as either Proxy-Authenticate or WWW-Authenticate header. */ DigestChallenge digestChallenge; + GBChallenge gbChallenge; /** * Credential info. @@ -644,6 +680,7 @@ struct OnCredAuthParam * \a DigestCredential.response. */ DigestCredential digestCredential; + GBCredential gbCredential; }; ////////////////////////////////////////////////////////////////////////////// @@ -2175,6 +2212,12 @@ private: const pjsip_cred_info *cred, const pj_str_t *method, pjsip_digest_credential *auth); + static pj_status_t on_auth_create_gb_response_callback( + pj_pool_t *pool, + const pjsip_gb_challenge*chal, + const pjsip_cred_info *cred, + const pj_str_t *method, + pjsip_gb_credential *auth); static void on_rejected_incoming_call( const pjsua_on_rejected_incoming_call_param *param); diff --git a/pjsip/include/pjsua2/siptypes.hpp b/pjsip/include/pjsua2/siptypes.hpp index 5192d5f..c167514 100644 --- a/pjsip/include/pjsua2/siptypes.hpp +++ b/pjsip/include/pjsua2/siptypes.hpp @@ -22,15 +22,14 @@ * @file pjsua2/types.hpp * @brief PJSUA2 Base Types */ -#include #include +#include #include #include /** PJSUA2 API is inside pj namespace */ -namespace pj -{ +namespace pj { /** * @defgroup PJSUA2_SIP_Types SIP Types @@ -42,35 +41,33 @@ namespace pj * Credential information. Credential contains information to authenticate * against a service. */ -struct AuthCredInfo : public PersistentObject -{ +struct AuthCredInfo : public PersistentObject { /** * The authentication scheme (e.g. "digest"). */ - string scheme; + string scheme; /** * Realm on which this credential is to be used. Use "*" to make * a credential that can be used to authenticate against any challenges. */ - string realm; + string realm; /** * Authentication user name. */ - string username; + string username; /** * Type of data that is contained in the "data" field. Use 0 if the data * contains plain text password. */ - int dataType; + int dataType; /** * The data, which can be a plain text password or a hashed digest. */ - string data; - + string data; /** * Digest algorithm type. @@ -85,18 +82,24 @@ struct AuthCredInfo : public PersistentObject */ /** Permanent subscriber key. */ - string akaK; + string akaK; /** Operator variant key. */ - string akaOp; + string akaOp; /** Authentication Management Field */ - string akaAmf; + string akaAmf; + + /** GB35114 algorithm **/ + string gbAlgorithm; + string gbKeyversion; public: /** Default constructor */ AuthCredInfo(); + static AuthCredInfo createGBAuthCredInfo(const string& scheme, const string& gb_algorithm, const string& keyversion, const string& realm); + /** Construct a credential with the specified parameters */ AuthCredInfo(const string &scheme, const string &realm, @@ -129,7 +132,6 @@ public: virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error); }; - ////////////////////////////////////////////////////////////////////////////// /** @@ -139,12 +141,12 @@ struct SockOpt { /** * The level at which the option is defined. */ - int level; + int level; /** * Option name. */ - int optName; + int optName; public: /** Default constructor. */ @@ -164,13 +166,13 @@ private: friend struct SockOptParams; /** Pointer to the buffer in which the option is specified. */ - void *optVal; + void *optVal; /** Buffer size of the buffer pointed by optVal. */ - int optLen; + int optLen; /** Option value if the type is integer. */ - int optValInt; + int optValInt; }; /** Array of socket options */ @@ -179,12 +181,11 @@ typedef std::vector SockOptVector; /** * Socket option parameters, to be specified in TransportConfig. */ -struct SockOptParams : public PersistentObject -{ +struct SockOptParams : public PersistentObject { /** * Array of socket options. */ - SockOptVector sockOpts; + SockOptVector sockOpts; public: /** Default constructor initialises with default values */ @@ -211,39 +212,37 @@ public: virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error); }; - /** * TLS transport settings, to be specified in TransportConfig. */ -struct TlsConfig : public PersistentObject -{ +struct TlsConfig : public PersistentObject { /** * Certificate of Authority (CA) list file. */ - string CaListFile; + string CaListFile; /** * Public endpoint certificate file, which will be used as client- * side certificate for outgoing TLS connection, and server-side * certificate for incoming TLS connection. */ - string certFile; + string certFile; /** * Optional private key of the endpoint certificate to be used. */ - string privKeyFile; + string privKeyFile; /** * Password to open private key. */ - string password; + string password; /** * Certificate of Authority (CA) buffer. If CaListFile, certFile or * privKeyFile are set, this setting will be ignored. */ - string CaBuf; + string CaBuf; /** * Public endpoint certificate buffer, which will be used as client- @@ -251,14 +250,14 @@ struct TlsConfig : public PersistentObject * certificate for incoming TLS connection. If CaListFile, certFile or * privKeyFile are set, this setting will be ignored. */ - string certBuf; + string certBuf; /** * Optional private key buffer of the endpoint certificate to be used. * If CaListFile, certFile or privKeyFile are set, this setting will * be ignored. */ - string privKeyBuf; + string privKeyBuf; /** * Lookup certificate from OS certificate store, this setting will @@ -277,7 +276,7 @@ struct TlsConfig : public PersistentObject * Currently only used by Windows Schannel backend, see also * \a pj_ssl_cert_load_from_store() for more info. */ - string certLookupKeyword; + string certLookupKeyword; /** * TLS protocol method from #pjsip_ssl_method. In the future, this field @@ -287,7 +286,7 @@ struct TlsConfig : public PersistentObject * Default is PJSIP_SSL_UNSPECIFIED_METHOD (0), which in turn will * use PJSIP_SSL_DEFAULT_METHOD, which default value is PJSIP_TLSV1_METHOD. */ - pjsip_ssl_method method; + pjsip_ssl_method method; /** * TLS protocol type from #pj_ssl_sock_proto. Use this field to enable @@ -296,7 +295,7 @@ struct TlsConfig : public PersistentObject * * Default is PJSIP_SSL_DEFAULT_PROTO. */ - unsigned proto; + unsigned proto; /** * Ciphers and order preference. The Endpoint::utilSslGetAvailableCiphers() @@ -304,7 +303,7 @@ struct TlsConfig : public PersistentObject * If the array is empty, then default cipher list of the backend * will be used. */ - IntVector ciphers; + IntVector ciphers; /** * Specifies TLS transport behavior on the server TLS certificate @@ -322,7 +321,7 @@ struct TlsConfig : public PersistentObject * * Default value is false. */ - bool verifyServer; + bool verifyServer; /** * Specifies TLS transport behavior on the client TLS certificate @@ -340,7 +339,7 @@ struct TlsConfig : public PersistentObject * * Default value is PJ_FALSE. */ - bool verifyClient; + bool verifyClient; /** * When acting as server (incoming TLS connections), reject incoming @@ -349,7 +348,7 @@ struct TlsConfig : public PersistentObject * This setting corresponds to SSL_VERIFY_FAIL_IF_NO_PEER_CERT flag. * Default value is PJ_FALSE. */ - bool requireClientCert; + bool requireClientCert; /** * TLS negotiation timeout to be applied for both outgoing and incoming @@ -358,7 +357,7 @@ struct TlsConfig : public PersistentObject * * Default: zero */ - unsigned msecTimeout; + unsigned msecTimeout; /** * QoS traffic type to be set on this transport. When application wants @@ -367,7 +366,7 @@ struct TlsConfig : public PersistentObject * * Default value is PJ_QOS_TYPE_BEST_EFFORT. */ - pj_qos_type qosType; + pj_qos_type qosType; /** * Set the low level QoS parameters to the transport. This is a lower @@ -376,7 +375,7 @@ struct TlsConfig : public PersistentObject * * By default all settings in this structure are disabled. */ - pj_qos_params qosParams; + pj_qos_params qosParams; /** * Specify if the transport should ignore any errors when setting the QoS @@ -384,7 +383,7 @@ struct TlsConfig : public PersistentObject * * Default: PJ_TRUE */ - bool qosIgnoreError; + bool qosIgnoreError; /** * Specify options to be set on the transport. @@ -392,7 +391,7 @@ struct TlsConfig : public PersistentObject * By default, this is unset, which means that the underlying sockopt * params as returned by #pj_ssl_sock_param_default() will be used. */ - SockOptParams sockOptParams; + SockOptParams sockOptParams; /** * Specify if the transport should ignore any errors when setting the @@ -400,14 +399,14 @@ struct TlsConfig : public PersistentObject * * Default: true */ - bool sockOptIgnoreError; + bool sockOptIgnoreError; /** * Specify if renegotiation is enabled for TLSv1.2 or earlier. * * Default: PJ_TRUE */ - bool enableRenegotiation; + bool enableRenegotiation; public: /** Default constructor initialises with default values */ @@ -434,19 +433,17 @@ public: virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error); }; - /** * Parameters to create a transport instance. */ -struct TransportConfig : public PersistentObject -{ +struct TransportConfig : public PersistentObject { /** * 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; + unsigned port; /** * Specify the port range for socket binding, relative to the start @@ -460,7 +457,7 @@ struct TransportConfig : public PersistentObject * * Default value is zero. */ - unsigned portRange; + unsigned portRange; /** * Specify whether to randomly pick the starting port number from @@ -470,7 +467,7 @@ struct TransportConfig : public PersistentObject * * Default is PJ_FALSE. */ - bool randomizePort; + bool randomizePort; /** * Optional address to advertise as the address of this transport. @@ -481,7 +478,7 @@ struct TransportConfig : public PersistentObject * * Note: this option can be used for both UDP and TCP as well! */ - string publicAddress; + string publicAddress; /** * Optional address where the socket should be bound to. This option @@ -494,13 +491,13 @@ struct TransportConfig : public PersistentObject * MUST correspond to the actual interface address in the host, since * this address will be specified as bind() argument. */ - string boundAddress; + string boundAddress; /** * This specifies TLS settings for TLS transport. * It's only used when creating a SIP TLS transport. */ - TlsConfig tlsConfig; + TlsConfig tlsConfig; /** * QoS traffic type to be set on this transport. When application wants @@ -512,7 +509,7 @@ struct TransportConfig : public PersistentObject * * Default is QoS not set. */ - pj_qos_type qosType; + pj_qos_type qosType; /** * Set the low level QoS parameters to the transport. This is a lower @@ -524,7 +521,7 @@ struct TransportConfig : public PersistentObject * * Default is QoS not set. */ - pj_qos_params qosParams; + pj_qos_params qosParams; /** * Set the low level socket options to the transport. @@ -534,7 +531,7 @@ struct TransportConfig : public PersistentObject * * Default is no socket option set. */ - SockOptParams sockOptParams; + SockOptParams sockOptParams; public: /** Default constructor initialises with default values */ @@ -565,31 +562,30 @@ public: * This structure describes transport information returned by * Endpoint::transportGetInfo() function. */ -struct TransportInfo -{ +struct TransportInfo { /** PJSUA transport identification. */ - TransportId id; + TransportId id; /** Transport type. */ - pjsip_transport_type_e type; + pjsip_transport_type_e type; /** Transport type name. */ - string typeName; + string typeName; /** Transport string info/description. */ - string info; + string info; /** Transport flags (see pjsip_transport_flags_e). */ - unsigned flags; + unsigned flags; /** Local/bound address. */ - SocketAddress localAddress; + SocketAddress localAddress; /** Published address (or transport address name). */ - SocketAddress localName; + SocketAddress localName; /** Current number of objects currently referencing this transport. */ - unsigned usageCount; + unsigned usageCount; public: /** @@ -607,30 +603,29 @@ public: * This structure describes an incoming SIP message. It corresponds to the * pjsip_rx_data structure in PJSIP library. */ -struct SipRxData -{ +struct SipRxData { /** * A short info string describing the request, which normally contains * the request method and its CSeq. */ - string info; + string info; /** * The whole message data as a string, containing both the header section * and message body section. */ - string wholeMsg; + string wholeMsg; /** * Source address of the message. */ - SocketAddress srcAddress; + SocketAddress srcAddress; /** * Pointer to original pjsip_rx_data. Only valid when the struct * is constructed from PJSIP's pjsip_rx_data. */ - void *pjRxData; + void *pjRxData; public: /** @@ -648,31 +643,30 @@ public: * This structure describes an outgoing SIP message. It corresponds to the * pjsip_tx_data structure in PJSIP library. */ -struct SipTxData -{ +struct SipTxData { /** * A short info string describing the request, which normally contains * the request method and its CSeq. */ - string info; - + string info; + /** * The whole message data as a string, containing both the header section * and message body section. */ - string wholeMsg; - + string wholeMsg; + /** * Destination address of the message. */ - SocketAddress dstAddress; - + SocketAddress dstAddress; + /** * Pointer to original pjsip_tx_data. Only valid when the struct * is constructed from PJSIP's pjsip_tx_data. */ - void *pjTxData; - + void *pjTxData; + public: /** * Default constructor. @@ -689,23 +683,22 @@ public: * This structure describes SIP transaction object. It corresponds to the * pjsip_transaction structure in PJSIP library. */ -struct SipTransaction -{ +struct SipTransaction { /* Transaction identification. */ - pjsip_role_e role; /**< Role (UAS or UAC) */ - string method; /**< The method. */ - + pjsip_role_e role; /**< Role (UAS or UAC) */ + string method; /**< The method. */ + /* State and status. */ - int statusCode; /**< Last status code seen. */ - string statusText; /**< Last reason phrase. */ - pjsip_tsx_state_e state; /**< State. */ - + int statusCode; /**< Last status code seen. */ + string statusText; /**< Last reason phrase. */ + pjsip_tsx_state_e state; /**< State. */ + /* Messages and timer. */ - SipTxData lastTx; /**< Msg kept for retrans. */ - + SipTxData lastTx; /**< Msg kept for retrans. */ + /* Original pjsip_transaction. */ - void *pjTransaction; /**< pjsip_transaction. */ - + void *pjTransaction; /**< pjsip_transaction. */ + public: /** * Default constructor. @@ -721,36 +714,31 @@ public: /** * This structure describes timer event. */ -struct TimerEvent -{ - TimerEntry entry; /**< The timer entry. */ +struct TimerEvent { + TimerEntry entry; /**< The timer entry. */ }; /** * This structure describes transaction state event source. */ -struct TsxStateEventSrc -{ - SipRxData rdata; /**< The incoming message. */ - SipTxData tdata; /**< The outgoing message. */ - TimerEntry timer; /**< The timer. */ - pj_status_t status; /**< Transport error status. */ - GenericData data; /**< Generic data. */ +struct TsxStateEventSrc { + SipRxData rdata; /**< The incoming message. */ + SipTxData tdata; /**< The outgoing message. */ + TimerEntry timer; /**< The timer. */ + pj_status_t status; /**< Transport error status. */ + GenericData data; /**< Generic data. */ - TsxStateEventSrc() - : timer(NULL), status(PJ_SUCCESS), data(NULL) - {} + TsxStateEventSrc() : timer(NULL), status(PJ_SUCCESS), data(NULL) {} }; /** * This structure describes transaction state changed event. */ -struct TsxStateEvent -{ - TsxStateEventSrc src; /**< Event source. */ - SipTransaction tsx; /**< The transaction. */ - pjsip_tsx_state_e prevState; /**< Previous state. */ - pjsip_event_id_e type; /**< Type of event source: +struct TsxStateEvent { + TsxStateEventSrc src; /**< Event source. */ + SipTransaction tsx; /**< The transaction. */ + pjsip_tsx_state_e prevState; /**< Previous state. */ + pjsip_event_id_e type; /**< Type of event source: * - PJSIP_EVENT_TX_MSG * - PJSIP_EVENT_RX_MSG, * - PJSIP_EVENT_TRANSPORT_ERROR @@ -764,98 +752,91 @@ struct TsxStateEvent /** * This structure describes message transmission event. */ -struct TxMsgEvent -{ - SipTxData tdata; /**< The transmit data buffer. */ +struct TxMsgEvent { + SipTxData tdata; /**< The transmit data buffer. */ }; /** * This structure describes transmission error event. */ -struct TxErrorEvent -{ - SipTxData tdata; /**< The transmit data. */ - SipTransaction tsx; /**< The transaction. */ +struct TxErrorEvent { + SipTxData tdata; /**< The transmit data. */ + SipTransaction tsx; /**< The transaction. */ }; /** * This structure describes message arrival event. */ -struct RxMsgEvent -{ - SipRxData rdata; /**< The receive data buffer. */ +struct RxMsgEvent { + SipRxData rdata; /**< The receive data buffer. */ }; /** * This structure describes user event. */ -struct UserEvent -{ - GenericData user1; /**< User data 1. */ - GenericData user2; /**< User data 2. */ - GenericData user3; /**< User data 3. */ - GenericData user4; /**< User data 4. */ +struct UserEvent { + GenericData user1; /**< User data 1. */ + GenericData user2; /**< User data 2. */ + GenericData user3; /**< User data 3. */ + GenericData user4; /**< User data 4. */ }; /** * The event body. */ -struct SipEventBody -{ +struct SipEventBody { /** * Timer event. */ - TimerEvent timer; - + TimerEvent timer; + /** * Transaction state has changed event. */ - TsxStateEvent tsxState; - + TsxStateEvent tsxState; + /** * Message transmission event. */ - TxMsgEvent txMsg; - + TxMsgEvent txMsg; + /** * Transmission error event. */ - TxErrorEvent txError; - + TxErrorEvent txError; + /** * Message arrival event. */ - RxMsgEvent rxMsg; - + RxMsgEvent rxMsg; + /** * User event. */ - UserEvent user; - + UserEvent user; }; /** * This structure describe event descriptor to fully identify a SIP event. It * corresponds to the pjsip_event structure in PJSIP library. */ -struct SipEvent -{ +struct SipEvent { /** * The event type, can be any value of \b pjsip_event_id_e. */ - pjsip_event_id_e type; - + pjsip_event_id_e type; + /** * The event body, which fields depends on the event type. */ - SipEventBody body; - + SipEventBody body; + /** * Pointer to its original pjsip_event. Only valid when the struct is * constructed from PJSIP's pjsip_event. */ - void *pjEvent; - + void *pjEvent; + public: /** * Default constructor. @@ -874,13 +855,12 @@ public: * SIP media type containing type and subtype. For example, for * "application/sdp", the type is "application" and the subtype is "sdp". */ -struct SipMediaType -{ +struct SipMediaType { /** Media type. */ - string type; + string type; /** Media subtype. */ - string subType; + string subType; public: /** @@ -897,17 +877,16 @@ public: /** * Simple SIP header. */ -struct SipHeader -{ +struct SipHeader { /** * Header name. */ - string hName; + string hName; /** * Header value. */ - string hValue; + string hValue; public: /** @@ -927,36 +906,34 @@ public: private: /** Interal buffer for conversion to PJSIP header */ - mutable pjsip_generic_string_hdr pjHdr; + mutable pjsip_generic_string_hdr pjHdr; }; - /** Array of strings */ typedef std::vector SipHeaderVector; /** * This describes each multipart part. */ -struct SipMultipartPart -{ +struct SipMultipartPart { /** * Optional headers to be put in this multipart part. */ - SipHeaderVector headers; + SipHeaderVector headers; /** * The MIME type of the body part of this multipart part. */ - SipMediaType contentType; + SipMediaType contentType; /** * The body part of tthis multipart part. */ - string body; + string body; public: SipMultipartPart(); - + /** * Initiaize from PJSIP's pjsip_multipart_part. */ @@ -965,12 +942,12 @@ public: /** * Convert to PJSIP's pjsip_multipart_part. */ - pjsip_multipart_part& toPj() const; + pjsip_multipart_part &toPj() const; private: /** Interal buffer for conversion to PJSIP pjsip_multipart_part */ - mutable pjsip_multipart_part pjMpp; - mutable pjsip_msg_body pjMsgBody; + mutable pjsip_multipart_part pjMpp; + mutable pjsip_msg_body pjMsgBody; }; /** Array of multipart parts */ @@ -980,38 +957,37 @@ typedef std::vector SipMultipartPartVector; * Additional options when sending outgoing SIP message. This corresponds to * pjsua_msg_data structure in PJSIP library. */ -struct SipTxOption -{ +struct SipTxOption { /** * Optional remote target URI (i.e. Target header). If empty (""), the * target will be set to the remote URI (To header). At the moment this * field is only used when sending initial INVITE and MESSAGE requests. */ - string targetUri; + string targetUri; /** * Optional local URI (i.e. From header). If empty (""), the * \a AccountConfig::idUri is used for the From header. At the moment this * field is only used when sending initial INVITE and MESSAGE requests. */ - string localUri; + string localUri; /** * Additional message headers to be included in the outgoing message. */ - SipHeaderVector headers; + SipHeaderVector headers; /** * MIME type of the message body, if application specifies the messageBody * in this structure. */ - string contentType; + string contentType; /** * Optional message body to be added to the message, only when the * message doesn't have a body. */ - string msgBody; + string msgBody; /** * Content type of the multipart body. If application wants to send @@ -1019,7 +995,7 @@ struct SipTxOption * the content type in multipartContentType. If the message already * contains a body, the body will be added to the multipart bodies. */ - SipMediaType multipartContentType; + SipMediaType multipartContentType; /** * Array of multipart parts. If application wants to send multipart @@ -1027,7 +1003,7 @@ struct SipTxOption * type in \a multipart_ctype. If the message already contains a body, * the body will be added to the multipart bodies. */ - SipMultipartPartVector multipartParts; + SipMultipartPartVector multipartParts; public: /** @@ -1038,7 +1014,7 @@ public: * @return True if the options are empty. */ bool isEmpty() const; - + /** * Initiaize from PJSUA's pjsua_msg_data. */ @@ -1056,28 +1032,27 @@ public: * This structure contains parameters for sending instance message methods, * e.g: Buddy::sendInstantMessage(), Call:sendInstantMessage(). */ -struct SendInstantMessageParam -{ +struct SendInstantMessageParam { /** * MIME type. Default is "text/plain". */ - string contentType; - + string contentType; + /** * The message content. */ - string content; - + string content; + /** * List of headers etc to be included in outgoing request. */ SipTxOption txOption; - + /** * User data, which will be given back when the IM callback is called. */ - Token userData; - + Token userData; + public: /** * Default constructor initializes with zero/empty values. @@ -1085,23 +1060,21 @@ public: SendInstantMessageParam(); }; - /** * This structure contains parameters for sending typing indication methods, * e.g: Buddy::sendTypingIndication(), Call:sendTypingIndication(). */ -struct SendTypingIndicationParam -{ +struct SendTypingIndicationParam { /** * True to indicate to remote that local person is currently typing an IM. */ - bool isTyping; - + bool isTyping; + /** * List of headers etc to be included in outgoing request. */ - SipTxOption txOption; - + SipTxOption txOption; + public: /** * Default constructor initializes with zero/empty values. @@ -1109,35 +1082,22 @@ public: SendTypingIndicationParam(); }; - /* Utilities */ #ifndef SWIG //! @cond Doxygen_Suppress -void readIntVector( ContainerNode &node, - const string &array_name, - IntVector &v) PJSUA2_THROW(Error); -void writeIntVector(ContainerNode &node, - const string &array_name, - const IntVector &v) PJSUA2_THROW(Error); -void readQosParams( ContainerNode &node, - pj_qos_params &qos) PJSUA2_THROW(Error); -void writeQosParams( ContainerNode &node, - const pj_qos_params &qos) PJSUA2_THROW(Error); -void readSipHeaders( const ContainerNode &node, - const string &array_name, - SipHeaderVector &headers) PJSUA2_THROW(Error); -void writeSipHeaders(ContainerNode &node, - const string &array_name, - const SipHeaderVector &headers) PJSUA2_THROW(Error); +void readIntVector(ContainerNode &node, const string &array_name, IntVector &v) PJSUA2_THROW(Error); +void writeIntVector(ContainerNode &node, const string &array_name, const IntVector &v) PJSUA2_THROW(Error); +void readQosParams(ContainerNode &node, pj_qos_params &qos) PJSUA2_THROW(Error); +void writeQosParams(ContainerNode &node, const pj_qos_params &qos) PJSUA2_THROW(Error); +void readSipHeaders(const ContainerNode &node, const string &array_name, SipHeaderVector &headers) PJSUA2_THROW(Error); +void writeSipHeaders(ContainerNode &node, const string &array_name, const SipHeaderVector &headers) PJSUA2_THROW(Error); //! @endcond -#endif // SWIG +#endif// SWIG /** * @} PJSUA2 */ -} // namespace pj +}// namespace pj - - -#endif /* __PJSUA2_SIPTYPES_HPP__ */ +#endif /* __PJSUA2_SIPTYPES_HPP__ */ diff --git a/pjsip/src/pjsip/sip_auth_client.c b/pjsip/src/pjsip/sip_auth_client.c index 989e7ea..4b5755a 100644 --- a/pjsip/src/pjsip/sip_auth_client.c +++ b/pjsip/src/pjsip/sip_auth_client.c @@ -17,110 +17,105 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include /* just to get pjsip_DIGEST_STR */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "pj/types.h" #include #include +#include +#include +#include +#include +#include +#include +#include +#include /* just to get pjsip_DIGEST_STR */ +#include +#include +#include +#include +#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 && PJ_SSL_SOCK_IMP == PJ_SSL_SOCK_IMP_OPENSSL +#include +#include +#include +#include -#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK != 0 && \ - PJ_SSL_SOCK_IMP==PJ_SSL_SOCK_IMP_OPENSSL -# include -# include -# include -# include -# include +#if OPENSSL_VERSION_NUMBER < 0x10100000L +#define EVP_MD_CTX_new() EVP_MD_CTX_create() +#define EVP_MD_CTX_free(ctx) EVP_MD_CTX_destroy(ctx) +#endif -# if OPENSSL_VERSION_NUMBER < 0x10100000L -# define EVP_MD_CTX_new() EVP_MD_CTX_create() -# define EVP_MD_CTX_free(ctx) EVP_MD_CTX_destroy(ctx) -# endif +#ifdef _MSC_VER +#include +#if OPENSSL_VERSION_NUMBER >= 0x10100000L +#pragma comment(lib, "libcrypto") +#else +#pragma comment(lib, "libeay32") +#pragma comment(lib, "ssleay32") +#endif +#endif -# ifdef _MSC_VER -# include -# if OPENSSL_VERSION_NUMBER >= 0x10100000L -# pragma comment(lib, "libcrypto") -# else -# pragma comment(lib, "libeay32") -# pragma comment(lib, "ssleay32") -# endif -# endif - -# define DEFINE_HASH_CONTEXT EVP_MD_CTX* mdctx +#define DEFINE_HASH_CONTEXT EVP_MD_CTX *mdctx #else -#define HAVE_NO_OPENSSL 1 -#define MD5_DIGEST_LENGTH (PJSIP_MD5STRLEN / 2) -#define SHA256_DIGEST_LENGTH (PJSIP_SHA256STRLEN / 2) +#define HAVE_NO_OPENSSL 1 +#define MD5_DIGEST_LENGTH (PJSIP_MD5STRLEN / 2) +#define SHA256_DIGEST_LENGTH (PJSIP_SHA256STRLEN / 2) /* A macro just to get rid of type mismatch between char and unsigned char */ -#define MD5_APPEND(pms,buf,len) pj_md5_update(pms, (const pj_uint8_t*)buf, \ - (unsigned)len) -#define EVP_MD char -#define EVP_MD_CTX pj_md5_context; -#define DEFINE_HASH_CONTEXT pj_md5_context pmc; pj_md5_context* mdctx = &pmc +#define MD5_APPEND(pms, buf, len) pj_md5_update(pms, (const pj_uint8_t *) buf, (unsigned) len) +#define EVP_MD char +#define EVP_MD_CTX pj_md5_context; +#define DEFINE_HASH_CONTEXT \ + pj_md5_context pmc; \ + pj_md5_context *mdctx = &pmc #define EVP_get_digestbyname(digest_name) (digest_name) -#define EVP_MD_CTX_new() &pmc -#define EVP_DigestInit_ex(mdctx, md, _unused) (void)md; pj_md5_init(mdctx) -#define EVP_DigestUpdate(mdctx, data, len) MD5_APPEND(mdctx, data, len) +#define EVP_MD_CTX_new() &pmc +#define EVP_DigestInit_ex(mdctx, md, _unused) \ + (void) md; \ + pj_md5_init(mdctx) +#define EVP_DigestUpdate(mdctx, data, len) MD5_APPEND(mdctx, data, len) #define EVP_DigestFinal_ex(mdctx, digest, _unused) pj_md5_final(mdctx, digest) #define EVP_MD_CTX_free(mdctx) #endif const pjsip_auth_algorithm pjsip_auth_algorithms[] = { -/* TYPE IANA name OpenSSL name */ -/* Raw digest byte length Hex representation length */ - { PJSIP_AUTH_ALGORITHM_NOT_SET, {"", 0}, "", - 0, 0}, - { PJSIP_AUTH_ALGORITHM_MD5, {"MD5", 3}, "MD5", - MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH * 2}, - { PJSIP_AUTH_ALGORITHM_SHA256, {"SHA-256", 7}, "SHA256", - SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH * 2}, - { PJSIP_AUTH_ALGORITHM_SHA512_256, {"SHA-512-256", 11}, "SHA512-256", - SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH * 2}, - { PJSIP_AUTH_ALGORITHM_AKAV1_MD5, {"AKAv1-MD5", 9}, "", - MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH * 2}, - { PJSIP_AUTH_ALGORITHM_AKAV2_MD5, {"AKAv2-MD5", 9}, "", - MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH * 2}, - { PJSIP_AUTH_ALGORITHM_COUNT, {"", 0}, "", - 0, 0}, + /* TYPE IANA name OpenSSL name */ + /* Raw digest byte length Hex representation length */ + {PJSIP_AUTH_ALGORITHM_NOT_SET, {"", 0}, "", 0, 0}, + {PJSIP_AUTH_ALGORITHM_MD5, {"MD5", 3}, "MD5", MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH * 2}, + {PJSIP_AUTH_ALGORITHM_SHA256, {"SHA-256", 7}, "SHA256", SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH * 2}, + {PJSIP_AUTH_ALGORITHM_SHA512_256, + {"SHA-512-256", 11}, + "SHA512-256", + SHA256_DIGEST_LENGTH, + SHA256_DIGEST_LENGTH * 2}, + {PJSIP_AUTH_ALGORITHM_AKAV1_MD5, {"AKAv1-MD5", 9}, "", MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH * 2}, + {PJSIP_AUTH_ALGORITHM_AKAV2_MD5, {"AKAv2-MD5", 9}, "", MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH * 2}, + {PJSIP_AUTH_ALGORITHM_COUNT, {"", 0}, "", 0, 0}, }; - /* Logging. */ -#define THIS_FILE "sip_auth_client.c" +#define THIS_FILE "sip_auth_client.c" #if 0 -# define AUTH_TRACE_(expr) PJ_LOG(3, expr) +#define AUTH_TRACE_(expr) PJ_LOG(3, expr) #else -# define AUTH_TRACE_(expr) +#define AUTH_TRACE_(expr) #endif - -static void dup_bin(pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src) +static void +dup_bin(pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src) { dst->slen = src->slen; if (dst->slen) { - dst->ptr = (char*) pj_pool_alloc(pool, src->slen); + dst->ptr = (char *) pj_pool_alloc(pool, src->slen); pj_memcpy(dst->ptr, src->ptr, src->slen); } else { dst->ptr = NULL; } } -PJ_DEF(void) pjsip_cred_info_dup(pj_pool_t *pool, - pjsip_cred_info *dst, - const pjsip_cred_info *src) +PJ_DEF(void) pjsip_cred_info_dup(pj_pool_t *pool, pjsip_cred_info *dst, const pjsip_cred_info *src) { pj_memcpy(dst, src, sizeof(pjsip_cred_info)); @@ -135,11 +130,13 @@ PJ_DEF(void) pjsip_cred_info_dup(pj_pool_t *pool, dup_bin(pool, &dst->ext.aka.op, &src->ext.aka.op); dup_bin(pool, &dst->ext.aka.amf, &src->ext.aka.amf); } + if (PJSIP_CRED_DATA_IS_GB(dst)) { + dup_bin(pool, &dst->gb.algorithm, &src->gb.algorithm); + dup_bin(pool, &dst->gb.keyversion, &src->gb.keyversion); + } } - -PJ_DEF(int) pjsip_cred_info_cmp(const pjsip_cred_info *cred1, - const pjsip_cred_info *cred2) +PJ_DEF(int) pjsip_cred_info_cmp(const pjsip_cred_info *cred1, const pjsip_cred_info *cred2) { int result; @@ -164,49 +161,55 @@ PJ_DEF(int) pjsip_cred_info_cmp(const pjsip_cred_info *cred1, result = pj_strcmp(&cred1->ext.aka.amf, &cred2->ext.aka.amf); if (result) goto on_return; } + if (PJSIP_CRED_DATA_IS_GB(cred1)) { + result = pj_strcmp(&cred1->gb.algorithm, &cred2->gb.algorithm); + if (result) goto on_return; + result = pj_strcmp(&cred1->gb.keyversion, &cred2->gb.keyversion); + if (result) goto on_return; + } on_return: return result; } -PJ_DEF(void) pjsip_auth_clt_pref_dup( pj_pool_t *pool, - pjsip_auth_clt_pref *dst, - const pjsip_auth_clt_pref *src) +PJ_DEF(void) pjsip_auth_clt_pref_dup(pj_pool_t *pool, pjsip_auth_clt_pref *dst, const pjsip_auth_clt_pref *src) { pj_memcpy(dst, src, sizeof(pjsip_auth_clt_pref)); pj_strdup_with_null(pool, &dst->algorithm, &src->algorithm); } - /* Transform digest to string. * output must be at least PJSIP_MD5STRLEN+1 bytes. * * NOTE: THE OUTPUT STRING IS NOT NULL TERMINATED! */ -static void digestNtoStr(const unsigned char digest[], int n, char *output) +static void +digestNtoStr(const unsigned char digest[], int n, char *output) { int i; - for (i = 0; ialgorithm_type)) { - PJ_LOG(4, (THIS_FILE, - "The algorithm (%.*s) referenced by algorithm_type is not supported", - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); + PJ_LOG(4, + (THIS_FILE, "The algorithm (%.*s) referenced by algorithm_type is not supported", + (int) algorithm->iana_name.slen, algorithm->iana_name.ptr)); return PJ_ENOTSUP; } @@ -243,17 +246,19 @@ PJ_DEF(pj_status_t) pjsip_auth_create_digest2( pj_str_t *result, digest_strlen = algorithm->digest_str_length; dig_len = digest_len; - if (result->slen < (pj_ssize_t)digest_strlen) { - PJ_LOG(4, (THIS_FILE, + if (result->slen < (pj_ssize_t) digest_strlen) { + PJ_LOG(4, + (THIS_FILE, "The length of the result buffer must be at least %d bytes " - "for algorithm %.*s", digest_strlen, - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); + "for algorithm %.*s", + digest_strlen, (int) algorithm->iana_name.slen, algorithm->iana_name.ptr)); return PJ_EINVAL; } result->slen = 0; if (!PJSIP_CRED_DATA_IS_PASSWD(cred_info) && !PJSIP_CRED_DATA_IS_DIGEST(cred_info)) { - PJ_LOG(4, (THIS_FILE, + PJ_LOG(4, + (THIS_FILE, "cred_info->data_type must be PJSIP_CRED_DATA_PLAIN_PASSWD " "or PJSIP_CRED_DATA_DIGEST")); return PJ_EINVAL; @@ -265,17 +270,17 @@ PJ_DEF(pj_status_t) pjsip_auth_create_digest2( pj_str_t *result, if (cred_algorithm_type == PJSIP_AUTH_ALGORITHM_NOT_SET) { cred_algorithm_type = algorithm_type; } else if (cred_algorithm_type != algorithm_type) { - PJ_LOG(4,(THIS_FILE, + PJ_LOG(4, + (THIS_FILE, "The algorithm specified in the cred_info (%.*s) " "doesn't match the algorithm requested for hashing (%.*s)", - (int)pjsip_auth_algorithms[cred_algorithm_type].iana_name.slen, + (int) pjsip_auth_algorithms[cred_algorithm_type].iana_name.slen, pjsip_auth_algorithms[cred_algorithm_type].iana_name.ptr, - (int)pjsip_auth_algorithms[algorithm_type].iana_name.slen, + (int) pjsip_auth_algorithms[algorithm_type].iana_name.slen, pjsip_auth_algorithms[algorithm_type].iana_name.ptr)); return PJ_EINVAL; } - PJ_ASSERT_RETURN(cred_info->data.slen >= (pj_ssize_t)digest_strlen, - PJ_EINVAL); + PJ_ASSERT_RETURN(cred_info->data.slen >= (pj_ssize_t) digest_strlen, PJ_EINVAL); } md = EVP_get_digestbyname(algorithm->openssl_name); @@ -284,13 +289,11 @@ PJ_DEF(pj_status_t) pjsip_auth_create_digest2( pj_str_t *result, return PJ_ENOTSUP; } - AUTH_TRACE_((THIS_FILE, "Begin creating %.*s digest", - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); + AUTH_TRACE_((THIS_FILE, "Begin creating %.*s digest", (int) algorithm->iana_name.slen, algorithm->iana_name.ptr)); - if (PJSIP_CRED_DATA_IS_PASSWD(cred_info)) - { - AUTH_TRACE_((THIS_FILE, " Using plain text password for %.*s digest", - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); + if (PJSIP_CRED_DATA_IS_PASSWD(cred_info)) { + AUTH_TRACE_((THIS_FILE, " Using plain text password for %.*s digest", (int) algorithm->iana_name.slen, + algorithm->iana_name.ptr)); /*** *** ha1 = (digest)(username ":" realm ":" password) ***/ @@ -308,9 +311,9 @@ PJ_DEF(pj_status_t) pjsip_auth_create_digest2( pj_str_t *result, digestNtoStr(digest, dig_len, ha1); } else { - AUTH_TRACE_((THIS_FILE, " Using pre computed digest for %.*s digest", - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); - pj_memcpy( ha1, cred_info->data.ptr, cred_info->data.slen ); + AUTH_TRACE_((THIS_FILE, " Using pre computed digest for %.*s digest", (int) algorithm->iana_name.slen, + algorithm->iana_name.ptr)); + pj_memcpy(ha1, cred_info->data.ptr, cred_info->data.slen); } AUTH_TRACE_((THIS_FILE, " ha1=%.*s", algorithm->digest_str_length, ha1)); @@ -359,105 +362,90 @@ PJ_DEF(pj_status_t) pjsip_auth_create_digest2( pj_str_t *result, result->slen = digest_strlen; digestNtoStr(digest, digest_len, result->ptr); - AUTH_TRACE_((THIS_FILE, "%.*s digest=%.*s", - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr, - (int)result->slen, result->ptr)); + AUTH_TRACE_((THIS_FILE, "%.*s digest=%.*s", (int) algorithm->iana_name.slen, algorithm->iana_name.ptr, + (int) result->slen, result->ptr)); return PJ_SUCCESS; } +PJ_DEF(pj_status_t) -PJ_DEF(pj_status_t) pjsip_auth_create_digest( pj_str_t *result, - const pj_str_t *nonce, - const pj_str_t *nc, - const pj_str_t *cnonce, - const pj_str_t *qop, - const pj_str_t *uri, - const pj_str_t *realm, - const pjsip_cred_info *cred_info, - const pj_str_t *method) +pjsip_auth_create_digest( + pj_str_t *result, + const pj_str_t *nonce, + const pj_str_t *nc, + const pj_str_t *cnonce, + const pj_str_t *qop, + const pj_str_t *uri, + const pj_str_t *realm, + const pjsip_cred_info *cred_info, + const pj_str_t *method) { PJ_ASSERT_RETURN(cred_info, PJ_EINVAL); PJ_ASSERT_RETURN(!PJSIP_CRED_DATA_IS_AKA(cred_info), PJ_EINVAL); - return pjsip_auth_create_digest2(result, nonce, nc, cnonce, - qop, uri, realm, cred_info, method, - PJSIP_AUTH_ALGORITHM_MD5); + return pjsip_auth_create_digest2( + result, nonce, nc, cnonce, qop, uri, realm, cred_info, method, PJSIP_AUTH_ALGORITHM_MD5); } - /* * Create response SHA-256 digest based on the parameters and store the * digest ASCII in 'result'. * \deprecated Use pjsip_auth_create_digest2 with * algorithm_type = PJSIP_AUTH_ALGORITHM_SHA256. */ -PJ_DEF(pj_status_t) pjsip_auth_create_digestSHA256(pj_str_t *result, - const pj_str_t *nonce, - const pj_str_t *nc, - const pj_str_t *cnonce, - const pj_str_t *qop, - const pj_str_t *uri, - const pj_str_t *realm, - const pjsip_cred_info *cred_info, - const pj_str_t *method) +PJ_DEF(pj_status_t) + +pjsip_auth_create_digestSHA256( + pj_str_t *result, + const pj_str_t *nonce, + const pj_str_t *nc, + const pj_str_t *cnonce, + const pj_str_t *qop, + const pj_str_t *uri, + const pj_str_t *realm, + const pjsip_cred_info *cred_info, + const pj_str_t *method) { PJ_ASSERT_RETURN(cred_info, PJ_EINVAL); PJ_ASSERT_RETURN(!PJSIP_CRED_DATA_IS_AKA(cred_info), PJ_EINVAL); - return pjsip_auth_create_digest2(result, nonce, nc, cnonce, - qop, uri, realm, cred_info, method, - PJSIP_AUTH_ALGORITHM_SHA256); + return pjsip_auth_create_digest2( + result, nonce, nc, cnonce, qop, uri, realm, cred_info, method, PJSIP_AUTH_ALGORITHM_SHA256); } - -PJ_DEF(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_type( - pjsip_auth_algorithm_type algorithm_type) +PJ_DEF(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_type(pjsip_auth_algorithm_type algorithm_type) { - if (algorithm_type > PJSIP_AUTH_ALGORITHM_NOT_SET - && algorithm_type < PJSIP_AUTH_ALGORITHM_COUNT) { + if (algorithm_type > PJSIP_AUTH_ALGORITHM_NOT_SET && algorithm_type < PJSIP_AUTH_ALGORITHM_COUNT) { return &pjsip_auth_algorithms[algorithm_type]; } return NULL; } - -PJ_DEF(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_iana_name( - const pj_str_t *iana_name) +PJ_DEF(const pjsip_auth_algorithm *) pjsip_auth_get_algorithm_by_iana_name(const pj_str_t *iana_name) { int i; - if (!iana_name) { - return NULL; - } + if (!iana_name) { return NULL; } - if (iana_name->slen == 0) { - return &pjsip_auth_algorithms[PJSIP_AUTH_ALGORITHM_MD5]; - } + if (iana_name->slen == 0) { return &pjsip_auth_algorithms[PJSIP_AUTH_ALGORITHM_MD5]; } #ifdef HAVE_NO_OPENSSL i = PJSIP_AUTH_ALGORITHM_MD5; - if (pj_stricmp(iana_name, &pjsip_auth_algorithms[i].iana_name) == 0) { - return &pjsip_auth_algorithms[i]; - } + if (pj_stricmp(iana_name, &pjsip_auth_algorithms[i].iana_name) == 0) { return &pjsip_auth_algorithms[i]; } #else for (i = PJSIP_AUTH_ALGORITHM_NOT_SET + 1; i < PJSIP_AUTH_ALGORITHM_COUNT; i++) { - if (pj_stricmp(iana_name, &pjsip_auth_algorithms[i].iana_name) == 0) { - return &pjsip_auth_algorithms[i]; - } + if (pj_stricmp(iana_name, &pjsip_auth_algorithms[i].iana_name) == 0) { return &pjsip_auth_algorithms[i]; } } #endif return NULL; } - -PJ_DEF(pj_bool_t) pjsip_auth_is_algorithm_supported( - pjsip_auth_algorithm_type algorithm_type) +PJ_DEF(pj_bool_t) pjsip_auth_is_algorithm_supported(pjsip_auth_algorithm_type algorithm_type) { const pjsip_auth_algorithm *algorithm = NULL; - if (algorithm_type <= PJSIP_AUTH_ALGORITHM_NOT_SET - || algorithm_type >= PJSIP_AUTH_ALGORITHM_COUNT) { + if (algorithm_type <= PJSIP_AUTH_ALGORITHM_NOT_SET || algorithm_type >= PJSIP_AUTH_ALGORITHM_COUNT) { return PJ_FALSE; } algorithm = &pjsip_auth_algorithms[algorithm_type]; @@ -466,45 +454,41 @@ PJ_DEF(pj_bool_t) pjsip_auth_is_algorithm_supported( * If the openssl_name is empty there's no need to check * if OpenSSL supports it. */ - if (algorithm->openssl_name[0] == '\0') { - return PJ_TRUE; - } + if (algorithm->openssl_name[0] == '\0') { return PJ_TRUE; } #ifdef HAVE_NO_OPENSSL return (algorithm_type == PJSIP_AUTH_ALGORITHM_MD5); #else { - const EVP_MD* md; + const EVP_MD *md; md = EVP_get_digestbyname(algorithm->openssl_name); - if (md == NULL) { - return PJ_FALSE; - } + if (md == NULL) { return PJ_FALSE; } return PJ_TRUE; } #endif } - /* * Finds out if qop offer contains "auth" token. */ -static pj_bool_t has_auth_qop( pj_pool_t *pool, const pj_str_t *qop_offer) +static pj_bool_t +has_auth_qop(pj_pool_t *pool, const pj_str_t *qop_offer) { pj_str_t qop; char *p; - pj_strdup_with_null( pool, &qop, qop_offer); + pj_strdup_with_null(pool, &qop, qop_offer); p = qop.ptr; while (*p) { - *p = (char)pj_tolower(*p); + *p = (char) pj_tolower(*p); ++p; } p = qop.ptr; while (*p) { - if (*p=='a' && *(p+1)=='u' && *(p+2)=='t' && *(p+3)=='h') { - int e = *(p+4); - if (e=='"' || e==',' || e==0) + if (*p == 'a' && *(p + 1) == 'u' && *(p + 2) == 't' && *(p + 3) == 'h') { + int e = *(p + 4); + if (e == '"' || e == ',' || e == 0) return PJ_TRUE; else p += 4; @@ -525,20 +509,20 @@ static pj_bool_t has_auth_qop( pj_pool_t *pool, const pj_str_t *qop_offer) * The resulting digest will be stored in cred->response. * The pool is used to allocate enough bytes to store the digest in cred->response. */ -static pj_status_t respond_digest( pj_pool_t *pool, - pjsip_digest_credential *cred, - const pjsip_digest_challenge *chal, - const pj_str_t *uri, - const pjsip_cred_info *cred_info, - const pj_str_t *cnonce, - pj_uint32_t nc, - const pj_str_t *method, - const pjsip_auth_algorithm_type challenge_algorithm_type) +static pj_status_t +respond_digest(pj_pool_t *pool, + pjsip_digest_credential *cred, + const pjsip_digest_challenge *chal, + const pj_str_t *uri, + const pjsip_cred_info *cred_info, + const pj_str_t *cnonce, + pj_uint32_t nc, + const pj_str_t *method, + const pjsip_auth_algorithm_type challenge_algorithm_type) { pj_status_t status = PJ_SUCCESS; - AUTH_TRACE_((THIS_FILE, "Begin responding to %.*s challenge", - (int)chal->algorithm.slen, chal->algorithm.ptr)); + AUTH_TRACE_((THIS_FILE, "Begin responding to %.*s challenge", (int) chal->algorithm.slen, chal->algorithm.ptr)); /* Build digest credential from arguments. */ pj_strdup(pool, &cred->username, &cred_info->username); @@ -550,22 +534,18 @@ static pj_status_t respond_digest( pj_pool_t *pool, /* Allocate memory. */ cred->response.slen = pjsip_auth_algorithms[challenge_algorithm_type].digest_str_length; - cred->response.ptr = (char*) pj_pool_alloc(pool, cred->response.slen); + cred->response.ptr = (char *) pj_pool_alloc(pool, cred->response.slen); if (chal->qop.slen == 0) { /* Server doesn't require quality of protection. */ if (PJSIP_CRED_DATA_IS_AKA(cred_info)) { /* Call application callback to create the response digest */ - return (*cred_info->ext.aka.cb)(pool, chal, cred_info, - method, cred); - } - else { + return (*cred_info->ext.aka.cb)(pool, chal, cred_info, method, cred); + } else { /* Convert digest to string and store in chal->response. */ - status = pjsip_auth_create_digest2( - &cred->response, &cred->nonce, NULL, - NULL, NULL, uri, &chal->realm, - cred_info, method, challenge_algorithm_type); + status = pjsip_auth_create_digest2(&cred->response, &cred->nonce, NULL, NULL, NULL, uri, &chal->realm, + cred_info, method, challenge_algorithm_type); } } else if (has_auth_qop(pool, &chal->qop)) { @@ -573,70 +553,56 @@ static pj_status_t respond_digest( pj_pool_t *pool, * We respond with selecting "qop=auth" protection. */ cred->qop = pjsip_AUTH_STR; - cred->nc.ptr = (char*) pj_pool_alloc(pool, 16); + cred->nc.ptr = (char *) pj_pool_alloc(pool, 16); cred->nc.slen = pj_ansi_snprintf(cred->nc.ptr, 16, "%08u", nc); if (cnonce && cnonce->slen) { pj_strdup(pool, &cred->cnonce, cnonce); } else { - pj_str_t dummy_cnonce = { "b39971", 6}; + pj_str_t dummy_cnonce = {"b39971", 6}; pj_strdup(pool, &cred->cnonce, &dummy_cnonce); } if (PJSIP_CRED_DATA_IS_AKA(cred_info)) { /* Call application callback to create the response digest */ - return (*cred_info->ext.aka.cb)(pool, chal, cred_info, - method, cred); - } - else { + return (*cred_info->ext.aka.cb)(pool, chal, cred_info, method, cred); + } else { /* Convert digest to string and store in chal->response. */ - status = pjsip_auth_create_digest2( - &cred->response, &cred->nonce, - &cred->nc, &cred->cnonce, - &pjsip_AUTH_STR, uri, - &chal->realm, cred_info, - method, challenge_algorithm_type); + status = pjsip_auth_create_digest2(&cred->response, &cred->nonce, &cred->nc, &cred->cnonce, &pjsip_AUTH_STR, + uri, &chal->realm, cred_info, method, challenge_algorithm_type); } } else { /* Server requires quality protection that we don't support. */ - PJ_LOG(4,(THIS_FILE, "Unsupported qop offer %.*s", - (int)chal->qop.slen, chal->qop.ptr)); + PJ_LOG(4, (THIS_FILE, "Unsupported qop offer %.*s", (int) chal->qop.slen, chal->qop.ptr)); return PJSIP_EINVALIDQOP; } return status; } -#if defined(PJSIP_AUTH_QOP_SUPPORT) && PJSIP_AUTH_QOP_SUPPORT!=0 +#if defined(PJSIP_AUTH_QOP_SUPPORT) && PJSIP_AUTH_QOP_SUPPORT != 0 /* * Update authentication session with a challenge. */ -static void update_digest_session( pjsip_cached_auth *cached_auth, - const pjsip_www_authenticate_hdr *hdr ) +static void +update_digest_session(pjsip_cached_auth *cached_auth, const pjsip_www_authenticate_hdr *hdr) { if (hdr->challenge.digest.qop.slen == 0) { -#if PJSIP_AUTH_AUTO_SEND_NEXT!=0 +#if PJSIP_AUTH_AUTO_SEND_NEXT != 0 if (!cached_auth->last_chal || pj_stricmp2(&hdr->scheme, "digest")) { - cached_auth->last_chal = (pjsip_www_authenticate_hdr*) - pjsip_hdr_clone(cached_auth->pool, hdr); + cached_auth->last_chal = (pjsip_www_authenticate_hdr *) pjsip_hdr_clone(cached_auth->pool, hdr); } else { /* Only update if the new challenge is "significantly different" * than the one in the cache, to reduce memory usage. */ - const pjsip_digest_challenge *d1 = - &cached_auth->last_chal->challenge.digest; + const pjsip_digest_challenge *d1 = &cached_auth->last_chal->challenge.digest; const pjsip_digest_challenge *d2 = &hdr->challenge.digest; - if (pj_strcmp(&d1->domain, &d2->domain) || - pj_strcmp(&d1->realm, &d2->realm) || - pj_strcmp(&d1->nonce, &d2->nonce) || - pj_strcmp(&d1->opaque, &d2->opaque) || - pj_strcmp(&d1->algorithm, &d2->algorithm) || - pj_strcmp(&d1->qop, &d2->qop)) - { - cached_auth->last_chal = (pjsip_www_authenticate_hdr*) - pjsip_hdr_clone(cached_auth->pool, hdr); + if (pj_strcmp(&d1->domain, &d2->domain) || pj_strcmp(&d1->realm, &d2->realm) + || pj_strcmp(&d1->nonce, &d2->nonce) || pj_strcmp(&d1->opaque, &d2->opaque) + || pj_strcmp(&d1->algorithm, &d2->algorithm) || pj_strcmp(&d1->qop, &d2->qop)) { + cached_auth->last_chal = (pjsip_www_authenticate_hdr *) pjsip_hdr_clone(cached_auth->pool, hdr); } } #endif @@ -646,13 +612,11 @@ static void update_digest_session( pjsip_cached_auth *cached_auth, /* Initialize cnonce and qop if not present. */ if (cached_auth->cnonce.slen == 0) { /* Save the whole challenge */ - cached_auth->last_chal = (pjsip_www_authenticate_hdr*) - pjsip_hdr_clone(cached_auth->pool, hdr); + cached_auth->last_chal = (pjsip_www_authenticate_hdr *) pjsip_hdr_clone(cached_auth->pool, hdr); /* Create cnonce */ - pj_create_unique_string( cached_auth->pool, &cached_auth->cnonce ); -#if defined(PJSIP_AUTH_CNONCE_USE_DIGITS_ONLY) && \ - PJSIP_AUTH_CNONCE_USE_DIGITS_ONLY!=0 + pj_create_unique_string(cached_auth->pool, &cached_auth->cnonce); +#if defined(PJSIP_AUTH_CNONCE_USE_DIGITS_ONLY) && PJSIP_AUTH_CNONCE_USE_DIGITS_ONLY != 0 if (pj_strchr(&cached_auth->cnonce, '-')) { /* remove hyphen character. */ pj_size_t w, r, len = pj_strlen(&cached_auth->cnonce); @@ -660,8 +624,7 @@ static void update_digest_session( pjsip_cached_auth *cached_auth, w = r = 0; for (; r < len; r++) { - if (s[r] != '-') - s[w++] = s[r]; + if (s[r] != '-') s[w++] = s[r]; } s[w] = '\0'; cached_auth->cnonce.slen = w; @@ -676,47 +639,35 @@ static void update_digest_session( pjsip_cached_auth *cached_auth, pj_assert(cached_auth->realm.slen != 0); */ if (cached_auth->realm.slen == 0) { - pj_strdup(cached_auth->pool, &cached_auth->realm, - &hdr->challenge.digest.realm); + pj_strdup(cached_auth->pool, &cached_auth->realm, &hdr->challenge.digest.realm); } } else { /* Update last_nonce and nonce-count */ - if (!pj_strcmp(&hdr->challenge.digest.nonce, - &cached_auth->last_chal->challenge.digest.nonce)) - { + if (!pj_strcmp(&hdr->challenge.digest.nonce, &cached_auth->last_chal->challenge.digest.nonce)) { /* Same nonce, increment nonce-count */ ++cached_auth->nc; } else { /* Server gives new nonce. */ - pj_strdup(cached_auth->pool, - &cached_auth->last_chal->challenge.digest.nonce, - &hdr->challenge.digest.nonce); + pj_strdup(cached_auth->pool, &cached_auth->last_chal->challenge.digest.nonce, &hdr->challenge.digest.nonce); /* Has the opaque changed? */ - if (pj_strcmp(&cached_auth->last_chal->challenge.digest.opaque, - &hdr->challenge.digest.opaque)) - { - pj_strdup(cached_auth->pool, - &cached_auth->last_chal->challenge.digest.opaque, + if (pj_strcmp(&cached_auth->last_chal->challenge.digest.opaque, &hdr->challenge.digest.opaque)) { + pj_strdup(cached_auth->pool, &cached_auth->last_chal->challenge.digest.opaque, &hdr->challenge.digest.opaque); } cached_auth->nc = 1; } } } -#endif /* PJSIP_AUTH_QOP_SUPPORT */ - +#endif /* PJSIP_AUTH_QOP_SUPPORT */ /* Find cached authentication in the list for the specified realm. */ -static pjsip_cached_auth *find_cached_auth( pjsip_auth_clt_sess *sess, - const pj_str_t *realm, - pjsip_auth_algorithm_type algorithm_type) +static pjsip_cached_auth * +find_cached_auth(pjsip_auth_clt_sess *sess, const pj_str_t *realm, pjsip_auth_algorithm_type algorithm_type) { pjsip_cached_auth *auth = sess->cached_auth.next; while (auth != &sess->cached_auth) { - if (pj_stricmp(&auth->realm, realm) == 0 - && auth->challenge_algorithm_type == algorithm_type) - return auth; + if (pj_stricmp(&auth->realm, realm) == 0 && auth->challenge_algorithm_type == algorithm_type) return auth; auth = auth->next; } @@ -724,35 +675,39 @@ static pjsip_cached_auth *find_cached_auth( pjsip_auth_clt_sess *sess, } /* Find credential to use for the specified realm and auth scheme. */ -static const pjsip_cred_info* auth_find_cred( const pjsip_auth_clt_sess *sess, - const pj_str_t *realm, - const pj_str_t *auth_scheme, - const pjsip_auth_algorithm_type algorithm_type) +static const pjsip_cred_info * +auth_find_cred(const pjsip_auth_clt_sess *sess, + const pj_str_t *realm, + const pj_str_t *auth_scheme, + const pjsip_auth_algorithm_type algorithm_type, + const pj_str_t* gb_algorithm_name, + const pj_str_t* gb_keyversion) { unsigned i; int wildcard = -1; PJ_UNUSED_ARG(auth_scheme); - for (i=0; icred_cnt; ++i) { - switch(sess->cred_info[i].data_type) { + for (i = 0; i < sess->cred_cnt; ++i) { + switch (sess->cred_info[i].data_type) { case PJSIP_CRED_DATA_PLAIN_PASSWD: /* PLAIN_PASSWD creds can be used for any algorithm other than AKA */ - if (algorithm_type != PJSIP_AUTH_ALGORITHM_AKAV1_MD5 - && algorithm_type != PJSIP_AUTH_ALGORITHM_AKAV2_MD5) { + if (algorithm_type != PJSIP_AUTH_ALGORITHM_AKAV1_MD5 && algorithm_type != PJSIP_AUTH_ALGORITHM_AKAV2_MD5) { break; } continue; case PJSIP_CRED_DATA_DIGEST: /* Digest creds can only be used if the algorithms match */ - if (sess->cred_info[i].algorithm_type == algorithm_type) { - break; - } + if (sess->cred_info[i].algorithm_type == algorithm_type) { break; } continue; case PJSIP_CRED_DATA_EXT_AKA: /* AKA creds can only be used for AKA algorithm */ - if (algorithm_type == PJSIP_AUTH_ALGORITHM_AKAV1_MD5 - || algorithm_type == PJSIP_AUTH_ALGORITHM_AKAV2_MD5) { + if (algorithm_type == PJSIP_AUTH_ALGORITHM_AKAV1_MD5 || algorithm_type == PJSIP_AUTH_ALGORITHM_AKAV2_MD5) { + break; + } + continue; + case PJSIP_CRED_DATA_GB: + if (!pj_stricmp(gb_algorithm_name, &sess->cred_info->gb.algorithm) /*&& !pj_stricmp(gb_keyversion, &sess->cred_info->gb.keyversion)*/) { break; } continue; @@ -763,9 +718,7 @@ static const pjsip_cred_info* auth_find_cred( const pjsip_auth_clt_sess *sess, */ if (pj_stricmp(&sess->cred_info[i].realm, realm) == 0) return &sess->cred_info[i]; - else if (sess->cred_info[i].realm.slen == 1 && - sess->cred_info[i].realm.ptr[0] == '*') - { + else if (sess->cred_info[i].realm.slen == 1 && sess->cred_info[i].realm.ptr[0] == '*') { wildcard = i; } } @@ -773,21 +726,18 @@ static const pjsip_cred_info* auth_find_cred( const pjsip_auth_clt_sess *sess, /* No matching realm. See if we have credential with wildcard ('*') * as the realm. */ - if (wildcard != -1) - return &sess->cred_info[wildcard]; + if (wildcard != -1) return &sess->cred_info[wildcard]; /* Nothing is suitable */ return NULL; } - /* Init client session. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_init( pjsip_auth_clt_sess *sess, - pjsip_endpoint *endpt, - pj_pool_t *pool, - unsigned options) +PJ_DEF(pj_status_t) + +pjsip_auth_clt_init(pjsip_auth_clt_sess *sess, pjsip_endpoint *endpt, pj_pool_t *pool, unsigned options) { - PJ_ASSERT_RETURN(sess && endpt && pool && (options==0), PJ_EINVAL); + PJ_ASSERT_RETURN(sess && endpt && pool && (options == 0), PJ_EINVAL); sess->pool = pool; sess->endpt = endpt; @@ -798,14 +748,13 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init( pjsip_auth_clt_sess *sess, return PJ_SUCCESS; } - /* Deinit client session. */ PJ_DEF(pj_status_t) pjsip_auth_clt_deinit(pjsip_auth_clt_sess *sess) { pjsip_cached_auth *auth; - + PJ_ASSERT_RETURN(sess && sess->endpt, PJ_EINVAL); - + auth = sess->cached_auth.next; while (auth != &sess->cached_auth) { pjsip_endpt_release_pool(sess->endpt, auth->pool); @@ -815,27 +764,21 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_deinit(pjsip_auth_clt_sess *sess) return PJ_SUCCESS; } - /* Clone session. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_clone( pj_pool_t *pool, - pjsip_auth_clt_sess *sess, - const pjsip_auth_clt_sess *rhs ) +PJ_DEF(pj_status_t) pjsip_auth_clt_clone(pj_pool_t *pool, pjsip_auth_clt_sess *sess, const pjsip_auth_clt_sess *rhs) { unsigned i; PJ_ASSERT_RETURN(pool && sess && rhs, PJ_EINVAL); - pjsip_auth_clt_init(sess, (pjsip_endpoint*)rhs->endpt, pool, 0); + pjsip_auth_clt_init(sess, (pjsip_endpoint *) rhs->endpt, pool, 0); sess->cred_cnt = rhs->cred_cnt; - sess->cred_info = (pjsip_cred_info*) - pj_pool_alloc(pool, - sess->cred_cnt*sizeof(pjsip_cred_info)); - for (i=0; icred_cnt; ++i) { + sess->cred_info = (pjsip_cred_info *) pj_pool_alloc(pool, sess->cred_cnt * sizeof(pjsip_cred_info)); + for (i = 0; i < rhs->cred_cnt; ++i) { pj_strdup(pool, &sess->cred_info[i].realm, &rhs->cred_info[i].realm); pj_strdup(pool, &sess->cred_info[i].scheme, &rhs->cred_info[i].scheme); - pj_strdup(pool, &sess->cred_info[i].username, - &rhs->cred_info[i].username); + pj_strdup(pool, &sess->cred_info[i].username, &rhs->cred_info[i].username); sess->cred_info[i].data_type = rhs->cred_info[i].data_type; pj_strdup(pool, &sess->cred_info[i].data, &rhs->cred_info[i].data); if (PJSIP_CRED_DATA_IS_DIGEST(&rhs->cred_info[i])) { @@ -847,6 +790,11 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_clone( pj_pool_t *pool, pj_strdup(pool, &sess->cred_info[i].ext.aka.amf, &rhs->cred_info[i].ext.aka.amf); sess->cred_info[i].ext.aka.cb = rhs->cred_info[i].ext.aka.cb; } + if (PJSIP_CRED_DATA_IS_GB(&rhs->cred_info[i])) { + pj_strdup(pool, &sess->cred_info[i].gb.algorithm, &rhs->cred_info[i].gb.algorithm); + pj_strdup(pool, &sess->cred_info[i].gb.keyversion, &rhs->cred_info[i].gb.keyversion); + sess->cred_info[i].gb.cb = rhs->cred_info[i].gb.cb; + } } /* TODO note: @@ -861,11 +809,8 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_clone( pj_pool_t *pool, return PJ_SUCCESS; } - /* Set client credentials. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_set_credentials( pjsip_auth_clt_sess *sess, - int cred_cnt, - const pjsip_cred_info *c) +PJ_DEF(pj_status_t) pjsip_auth_clt_set_credentials(pjsip_auth_clt_sess *sess, int cred_cnt, const pjsip_cred_info *c) { PJ_ASSERT_RETURN(sess && c, PJ_EINVAL); @@ -873,9 +818,8 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_set_credentials( pjsip_auth_clt_sess *sess, sess->cred_cnt = 0; } else { int i; - sess->cred_info = (pjsip_cred_info*) - pj_pool_alloc(sess->pool, cred_cnt * sizeof(*c)); - for (i=0; icred_info = (pjsip_cred_info *) pj_pool_alloc(sess->pool, cred_cnt * sizeof(*c)); + for (i = 0; i < cred_cnt; ++i) { sess->cred_info[i].data_type = c[i].data_type; /* When data_type is PJSIP_CRED_DATA_EXT_AKA, @@ -894,36 +838,30 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_set_credentials( pjsip_auth_clt_sess *sess, PJ_ASSERT_RETURN(c[i].ext.aka.cb != NULL, PJ_EINVAL); /* Verify K len */ - PJ_ASSERT_RETURN(c[i].ext.aka.k.slen <= PJSIP_AKA_KLEN, - PJSIP_EAUTHINAKACRED); + PJ_ASSERT_RETURN(c[i].ext.aka.k.slen <= PJSIP_AKA_KLEN, PJSIP_EAUTHINAKACRED); /* Verify OP len */ - PJ_ASSERT_RETURN(c[i].ext.aka.op.slen <= PJSIP_AKA_OPLEN, - PJSIP_EAUTHINAKACRED); + PJ_ASSERT_RETURN(c[i].ext.aka.op.slen <= PJSIP_AKA_OPLEN, PJSIP_EAUTHINAKACRED); /* Verify AMF len */ - PJ_ASSERT_RETURN(c[i].ext.aka.amf.slen <= PJSIP_AKA_AMFLEN, - PJSIP_EAUTHINAKACRED); + PJ_ASSERT_RETURN(c[i].ext.aka.amf.slen <= PJSIP_AKA_AMFLEN, PJSIP_EAUTHINAKACRED); sess->cred_info[i].ext.aka.cb = c[i].ext.aka.cb; - pj_strdup(sess->pool, &sess->cred_info[i].ext.aka.k, - &c[i].ext.aka.k); - pj_strdup(sess->pool, &sess->cred_info[i].ext.aka.op, - &c[i].ext.aka.op); - pj_strdup(sess->pool, &sess->cred_info[i].ext.aka.amf, - &c[i].ext.aka.amf); + pj_strdup(sess->pool, &sess->cred_info[i].ext.aka.k, &c[i].ext.aka.k); + pj_strdup(sess->pool, &sess->cred_info[i].ext.aka.op, &c[i].ext.aka.op); + pj_strdup(sess->pool, &sess->cred_info[i].ext.aka.amf, &c[i].ext.aka.amf); + } else if (PJSIP_CRED_DATA_IS_GB(&c[i])) { + pj_strdup(sess->pool, &sess->cred_info[i].scheme, &c[i].scheme); + pj_strdup(sess->pool, &sess->cred_info[i].realm, &c[i].realm); + pj_strdup(sess->pool, &sess->cred_info[i].gb.algorithm, &c[i].gb.algorithm); + pj_strdup(sess->pool, &sess->cred_info[i].gb.keyversion, &c[i].gb.keyversion); + sess->cred_info[i].gb.cb = c[i].gb.cb; } - - pj_strdup(sess->pool, &sess->cred_info[i].scheme, &c[i].scheme); - pj_strdup(sess->pool, &sess->cred_info[i].realm, &c[i].realm); - pj_strdup(sess->pool, &sess->cred_info[i].username, &c[i].username); - pj_strdup(sess->pool, &sess->cred_info[i].data, &c[i].data); /* * If the data type is DIGEST and an auth algorithm isn't set, * default it to MD5. */ - if (PJSIP_CRED_DATA_IS_DIGEST(&c[i]) && - c[i].algorithm_type == PJSIP_AUTH_ALGORITHM_NOT_SET) { + if (PJSIP_CRED_DATA_IS_DIGEST(&c[i]) && c[i].algorithm_type == PJSIP_AUTH_ALGORITHM_NOT_SET) { sess->cred_info[i].algorithm_type = PJSIP_AUTH_ALGORITHM_MD5; } else { sess->cred_info[i].algorithm_type = c[i].algorithm_type; @@ -935,12 +873,10 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_set_credentials( pjsip_auth_clt_sess *sess, return PJ_SUCCESS; } - /* * Set the preference for the client authentication session. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, - const pjsip_auth_clt_pref *p) +PJ_DEF(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, const pjsip_auth_clt_pref *p) { PJ_ASSERT_RETURN(sess && p, PJ_EINVAL); @@ -952,12 +888,10 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_set_prefs(pjsip_auth_clt_sess *sess, return PJ_SUCCESS; } - /* * Get the preference for the client authentication session. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, - pjsip_auth_clt_pref *p) +PJ_DEF(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, pjsip_auth_clt_pref *p) { PJ_ASSERT_RETURN(sess && p, PJ_EINVAL); @@ -965,20 +899,20 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_get_prefs(pjsip_auth_clt_sess *sess, return PJ_SUCCESS; } - /* * Create Authorization/Proxy-Authorization response header based on the challege * in WWW-Authenticate/Proxy-Authenticate header. */ -static pj_status_t auth_respond( pj_pool_t *req_pool, - const pjsip_www_authenticate_hdr *hdr, - const pjsip_uri *uri, - const pjsip_cred_info *cred_info, - const pjsip_method *method, - pj_pool_t *sess_pool, - pjsip_cached_auth *cached_auth, - pjsip_authorization_hdr **p_h_auth, - const pjsip_auth_algorithm_type challenge_algorithm_type) +static pj_status_t +auth_respond(pj_pool_t *req_pool, + const pjsip_www_authenticate_hdr *hdr, + const pjsip_uri *uri, + const pjsip_cred_info *cred_info, + const pjsip_method *method, + pj_pool_t *sess_pool, + pjsip_cached_auth *cached_auth, + pjsip_authorization_hdr **p_h_auth, + const pjsip_auth_algorithm_type challenge_algorithm_type) { pjsip_authorization_hdr *hauth; char tmp[PJSIP_MAX_URL_SIZE]; @@ -987,27 +921,24 @@ static pj_status_t auth_respond( pj_pool_t *req_pool, pj_status_t status; /* Verify arguments. */ - PJ_ASSERT_RETURN(req_pool && hdr && uri && cred_info && method && - sess_pool && cached_auth && p_h_auth, PJ_EINVAL); + PJ_ASSERT_RETURN(req_pool && hdr && uri && cred_info && method && sess_pool && cached_auth && p_h_auth, PJ_EINVAL); /* Print URL in the original request. */ uri_str.ptr = tmp; - uri_str.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, tmp,sizeof(tmp)); - if (uri_str.slen < 1) { - return PJSIP_EURITOOLONG; - } + uri_str.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, tmp, sizeof(tmp)); + if (uri_str.slen < 1) { return PJSIP_EURITOOLONG; } -# if (PJSIP_AUTH_HEADER_CACHING) +#if (PJSIP_AUTH_HEADER_CACHING) { pool = sess_pool; PJ_UNUSED_ARG(req_pool); } -# else +#else { pool = req_pool; PJ_UNUSED_ARG(sess_pool); } -# endif +#endif if (hdr->type == PJSIP_H_WWW_AUTHENTICATE) hauth = pjsip_authorization_hdr_create(pool); @@ -1023,23 +954,21 @@ static pj_status_t auth_respond( pj_pool_t *req_pool, pj_uint32_t nc = 1; /* Update the session (nonce-count etc) if required. */ -# if PJSIP_AUTH_QOP_SUPPORT +#if PJSIP_AUTH_QOP_SUPPORT { if (cached_auth) { - update_digest_session( cached_auth, hdr ); + update_digest_session(cached_auth, hdr); cnonce = &cached_auth->cnonce; nc = cached_auth->nc; } } -# endif /* PJSIP_AUTH_QOP_SUPPORT */ +#endif /* PJSIP_AUTH_QOP_SUPPORT */ hauth->scheme = pjsip_DIGEST_STR; - status = respond_digest( pool, &hauth->credential.digest, - &hdr->challenge.digest, &uri_str, cred_info, - cnonce, nc, &method->name, challenge_algorithm_type); - if (status != PJ_SUCCESS) - return status; + status = respond_digest(pool, &hauth->credential.digest, &hdr->challenge.digest, &uri_str, cred_info, cnonce, + nc, &method->name, challenge_algorithm_type); + if (status != PJ_SUCCESS) return status; /* Set qop type in auth session the first time only. */ if (hdr->challenge.digest.qop.slen != 0 && cached_auth) { @@ -1052,6 +981,8 @@ static pj_status_t auth_respond( pj_pool_t *req_pool, } } } + } else if (!pj_stricmp(&hdr->scheme, &pjsip_CAPABILITY_STR)) { + return PJSIP_ETODO; } else { return PJSIP_EINVALIDAUTHSCHEME; } @@ -1059,7 +990,7 @@ static pj_status_t auth_respond( pj_pool_t *req_pool, /* Keep the new authorization header in the cache, only * if no qop is not present. */ -# if PJSIP_AUTH_HEADER_CACHING +#if PJSIP_AUTH_HEADER_CACHING { if (hauth && cached_auth && cached_auth->qop_value == PJSIP_AUTH_QOP_NONE) { pjsip_cached_auth_hdr *cached_hdr; @@ -1067,8 +998,7 @@ static pj_status_t auth_respond( pj_pool_t *req_pool, /* Delete old header with the same method. */ cached_hdr = cached_auth->cached_hdr.next; while (cached_hdr != &cached_auth->cached_hdr) { - if (pjsip_method_cmp(method, &cached_hdr->method)==0) - break; + if (pjsip_method_cmp(method, &cached_hdr->method) == 0) break; cached_hdr = cached_hdr->next; } @@ -1077,31 +1007,28 @@ static pj_status_t auth_respond( pj_pool_t *req_pool, cached_hdr->hdr = hauth; } else { cached_hdr = pj_pool_alloc(pool, sizeof(*cached_hdr)); - pjsip_method_copy( pool, &cached_hdr->method, method); + pjsip_method_copy(pool, &cached_hdr->method, method); cached_hdr->hdr = hauth; - pj_list_insert_before( &cached_auth->cached_hdr, cached_hdr ); + pj_list_insert_before(&cached_auth->cached_hdr, cached_hdr); } } -# if defined(PJSIP_AUTH_AUTO_SEND_NEXT) && PJSIP_AUTH_AUTO_SEND_NEXT!=0 - if (hdr != cached_auth->last_chal) { - cached_auth->last_chal = pjsip_hdr_clone(sess_pool, hdr); - } -# endif +#if defined(PJSIP_AUTH_AUTO_SEND_NEXT) && PJSIP_AUTH_AUTO_SEND_NEXT != 0 + if (hdr != cached_auth->last_chal) { cached_auth->last_chal = pjsip_hdr_clone(sess_pool, hdr); } +#endif } -# endif +#endif *p_h_auth = hauth; return PJ_SUCCESS; - } - -#if defined(PJSIP_AUTH_AUTO_SEND_NEXT) && PJSIP_AUTH_AUTO_SEND_NEXT!=0 -static pj_status_t new_auth_for_req( pjsip_tx_data *tdata, - pjsip_auth_clt_sess *sess, - pjsip_cached_auth *auth, - pjsip_authorization_hdr **p_h_auth) +#if defined(PJSIP_AUTH_AUTO_SEND_NEXT) && PJSIP_AUTH_AUTO_SEND_NEXT != 0 +static pj_status_t +new_auth_for_req(pjsip_tx_data *tdata, + pjsip_auth_clt_sess *sess, + pjsip_cached_auth *auth, + pjsip_authorization_hdr **p_h_auth) { const pjsip_cred_info *cred; pjsip_authorization_hdr *hauth; @@ -1110,37 +1037,29 @@ static pj_status_t new_auth_for_req( pjsip_tx_data *tdata, PJ_ASSERT_RETURN(tdata && sess && auth, PJ_EINVAL); PJ_ASSERT_RETURN(auth->last_chal != NULL, PJSIP_EAUTHNOPREVCHAL); - cred = auth_find_cred( sess, &auth->realm, &auth->last_chal->scheme, - auth->challenge_algorithm_type ); - if (!cred) - return PJSIP_ENOCREDENTIAL; + cred = auth_find_cred(sess, &auth->realm, &auth->last_chal->scheme, auth->challenge_algorithm_type); + if (!cred) return PJSIP_ENOCREDENTIAL; - status = auth_respond( tdata->pool, auth->last_chal, - tdata->msg->line.req.uri, - cred, &tdata->msg->line.req.method, - sess->pool, auth, &hauth, auth->challenge_algorithm_type); - if (status != PJ_SUCCESS) - return status; + status = auth_respond(tdata->pool, auth->last_chal, tdata->msg->line.req.uri, cred, &tdata->msg->line.req.method, + sess->pool, auth, &hauth, auth->challenge_algorithm_type); + if (status != PJ_SUCCESS) return status; - pjsip_msg_add_hdr( tdata->msg, (pjsip_hdr*)hauth); + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) hauth); - if (p_h_auth) - *p_h_auth = hauth; + if (p_h_auth) *p_h_auth = hauth; return PJ_SUCCESS; } #endif - /* Find credential in list of (Proxy-)Authorization headers */ -static pjsip_authorization_hdr* get_header_for_cred_info( - const pjsip_hdr *hdr_list, - const pjsip_cred_info *cred_info) +static pjsip_authorization_hdr * +get_header_for_cred_info(const pjsip_hdr *hdr_list, const pjsip_cred_info *cred_info) { pjsip_authorization_hdr *h; - h = (pjsip_authorization_hdr*)hdr_list->next; - while (h != (pjsip_authorization_hdr*)hdr_list) { + h = (pjsip_authorization_hdr *) hdr_list->next; + while (h != (pjsip_authorization_hdr *) hdr_list) { /* If the realm doesn't match, just skip */ if (pj_stricmp(&h->credential.digest.realm, &cred_info->realm) != 0) { h = h->next; @@ -1159,8 +1078,8 @@ static pjsip_authorization_hdr* get_header_for_cred_info( * If cred_info->data_type is DIGEST, then we need to check if the * algorithms match. */ - if (pj_stricmp(&h->credential.digest.algorithm, - &pjsip_auth_algorithms[cred_info->algorithm_type].iana_name) == 0) { + if (pj_stricmp(&h->credential.digest.algorithm, &pjsip_auth_algorithms[cred_info->algorithm_type].iana_name) + == 0) { return h; } break; @@ -1170,9 +1089,11 @@ static pjsip_authorization_hdr* get_header_for_cred_info( * challenge algorithm is AKAv1-MD5 or AKAv2-MD5. */ if (pj_stricmp(&h->credential.digest.algorithm, - &pjsip_auth_algorithms[PJSIP_AUTH_ALGORITHM_AKAV1_MD5].iana_name) == 0 + &pjsip_auth_algorithms[PJSIP_AUTH_ALGORITHM_AKAV1_MD5].iana_name) + == 0 || pj_stricmp(&h->credential.digest.algorithm, - &pjsip_auth_algorithms[PJSIP_AUTH_ALGORITHM_AKAV2_MD5].iana_name) == 0) { + &pjsip_auth_algorithms[PJSIP_AUTH_ALGORITHM_AKAV2_MD5].iana_name) + == 0) { return h; } break; @@ -1183,10 +1104,8 @@ static pjsip_authorization_hdr* get_header_for_cred_info( return NULL; } - /* Initialize outgoing request. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, - pjsip_tx_data *tdata ) +PJ_DEF(pj_status_t) pjsip_auth_clt_init_req(pjsip_auth_clt_sess *sess, pjsip_tx_data *tdata) { const pjsip_method *method; pjsip_cached_auth *auth; @@ -1194,8 +1113,7 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, PJ_ASSERT_RETURN(sess && tdata, PJ_EINVAL); PJ_ASSERT_RETURN(sess->pool, PJSIP_ENOTINITIALIZED); - PJ_ASSERT_RETURN(tdata->msg->type==PJSIP_REQUEST_MSG, - PJSIP_ENOTREQUESTMSG); + PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG, PJSIP_ENOTREQUESTMSG); /* Init list */ pj_list_init(&added); @@ -1210,12 +1128,11 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, auth->stale_cnt = 0; if (auth->qop_value == PJSIP_AUTH_QOP_NONE) { -# if defined(PJSIP_AUTH_HEADER_CACHING) && \ - PJSIP_AUTH_HEADER_CACHING!=0 +#if defined(PJSIP_AUTH_HEADER_CACHING) && PJSIP_AUTH_HEADER_CACHING != 0 { pjsip_cached_auth_hdr *entry = auth->cached_hdr.next; while (entry != &auth->cached_hdr) { - if (pjsip_method_cmp(&entry->method, method)==0) { + if (pjsip_method_cmp(&entry->method, method) == 0) { pjsip_authorization_hdr *hauth; hauth = pjsip_hdr_shallow_clone(tdata->pool, entry->hdr); //pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); @@ -1225,26 +1142,21 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, entry = entry->next; } -# if defined(PJSIP_AUTH_AUTO_SEND_NEXT) && \ - PJSIP_AUTH_AUTO_SEND_NEXT!=0 +#if defined(PJSIP_AUTH_AUTO_SEND_NEXT) && PJSIP_AUTH_AUTO_SEND_NEXT != 0 { - if (entry == &auth->cached_hdr) - new_auth_for_req( tdata, sess, auth, NULL); + if (entry == &auth->cached_hdr) new_auth_for_req(tdata, sess, auth, NULL); } -# endif - +#endif } -# elif defined(PJSIP_AUTH_AUTO_SEND_NEXT) && \ - PJSIP_AUTH_AUTO_SEND_NEXT!=0 +#elif defined(PJSIP_AUTH_AUTO_SEND_NEXT) && PJSIP_AUTH_AUTO_SEND_NEXT != 0 { - new_auth_for_req( tdata, sess, auth, NULL); + new_auth_for_req(tdata, sess, auth, NULL); } -# endif +#endif } -# if defined(PJSIP_AUTH_QOP_SUPPORT) && \ - defined(PJSIP_AUTH_AUTO_SEND_NEXT) && \ - (PJSIP_AUTH_QOP_SUPPORT && PJSIP_AUTH_AUTO_SEND_NEXT) +#if defined(PJSIP_AUTH_QOP_SUPPORT) && defined(PJSIP_AUTH_AUTO_SEND_NEXT) \ + && (PJSIP_AUTH_QOP_SUPPORT && PJSIP_AUTH_AUTO_SEND_NEXT) else if (auth->qop_value == PJSIP_AUTH_QOP_AUTH) { /* For qop="auth", we have to re-create the authorization header. */ @@ -1252,27 +1164,21 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, pjsip_authorization_hdr *hauth; pj_status_t status; - cred = auth_find_cred(sess, &auth->realm, - &auth->last_chal->scheme, - auth->challenge_algorithm_type); + cred = auth_find_cred(sess, &auth->realm, &auth->last_chal->scheme, auth->challenge_algorithm_type); if (!cred) { auth = auth->next; continue; } - status = auth_respond( tdata->pool, auth->last_chal, - tdata->msg->line.req.uri, - cred, - &tdata->msg->line.req.method, - sess->pool, auth, &hauth, - auth->challenge_algorithm_type); - if (status != PJ_SUCCESS) - return status; + status = + auth_respond(tdata->pool, auth->last_chal, tdata->msg->line.req.uri, cred, &tdata->msg->line.req.method, + sess->pool, auth, &hauth, auth->challenge_algorithm_type); + if (status != PJ_SUCCESS) return status; //pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); pj_list_push_back(&added, hauth); } -# endif /* PJSIP_AUTH_QOP_SUPPORT && PJSIP_AUTH_AUTO_SEND_NEXT */ +#endif /* PJSIP_AUTH_QOP_SUPPORT && PJSIP_AUTH_AUTO_SEND_NEXT */ auth = auth->next; } @@ -1297,50 +1203,45 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, unsigned i; pj_str_t uri; - uri.ptr = (char*)pj_pool_alloc(tdata->pool, PJSIP_MAX_URL_SIZE); - uri.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, - tdata->msg->line.req.uri, - uri.ptr, PJSIP_MAX_URL_SIZE); - if (uri.slen < 1 || uri.slen >= PJSIP_MAX_URL_SIZE) - return PJSIP_EURITOOLONG; + uri.ptr = (char *) pj_pool_alloc(tdata->pool, PJSIP_MAX_URL_SIZE); + uri.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, tdata->msg->line.req.uri, uri.ptr, PJSIP_MAX_URL_SIZE); + if (uri.slen < 1 || uri.slen >= PJSIP_MAX_URL_SIZE) return PJSIP_EURITOOLONG; - for (i=0; icred_cnt; ++i) { + for (i = 0; i < sess->cred_cnt; ++i) { pjsip_cred_info *c = &sess->cred_info[i]; pjsip_authorization_hdr *h; h = get_header_for_cred_info(&added, c); if (h) { pj_list_erase(h); - pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)h); + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) h); } else { pjsip_authorization_hdr *hs; hs = pjsip_authorization_hdr_create(tdata->pool); pj_strdup(tdata->pool, &hs->scheme, &c->scheme); - if (pj_stricmp(&c->scheme, &pjsip_BEARER_STR)==0) { - pj_strdup(tdata->pool, &hs->credential.oauth.username, - &c->username); - pj_strdup(tdata->pool, &hs->credential.oauth.realm, - &c->realm); - pj_strdup(tdata->pool, &hs->credential.oauth.token, - &c->data); - } else { //if (pj_stricmp(&c->scheme, &pjsip_DIGEST_STR)==0) - pj_strdup(tdata->pool, &hs->credential.digest.username, - &c->username); - pj_strdup(tdata->pool, &hs->credential.digest.realm, - &c->realm); - pj_strdup(tdata->pool,&hs->credential.digest.uri, &uri); + if (pj_stricmp(&c->scheme, &pjsip_BEARER_STR) == 0) { + pj_strdup(tdata->pool, &hs->credential.oauth.username, &c->username); + pj_strdup(tdata->pool, &hs->credential.oauth.realm, &c->realm); + pj_strdup(tdata->pool, &hs->credential.oauth.token, &c->data); + } else if(pj_stricmp(&c->scheme, &pjsip_DIGEST_STR)==0) { + pj_strdup(tdata->pool, &hs->credential.digest.username, &c->username); + pj_strdup(tdata->pool, &hs->credential.digest.realm, &c->realm); + pj_strdup(tdata->pool, &hs->credential.digest.uri, &uri); - if (c->algorithm_type == PJSIP_AUTH_ALGORITHM_NOT_SET) { - pj_strdup(tdata->pool, &hs->credential.digest.algorithm, - &sess->pref.algorithm); - } else { - pj_strdup(tdata->pool, &hs->credential.digest.algorithm, - &pjsip_auth_algorithms[c->algorithm_type].iana_name); - } + if (c->algorithm_type == PJSIP_AUTH_ALGORITHM_NOT_SET) { + pj_strdup(tdata->pool, &hs->credential.digest.algorithm, &sess->pref.algorithm); + } else { + pj_strdup(tdata->pool, &hs->credential.digest.algorithm, + &pjsip_auth_algorithms[c->algorithm_type].iana_name); + } + } else if(pj_stricmp(&c->scheme, &pjsip_UNIDIRECTION_STR)==0 || pj_stricmp(&c->scheme, &pjsip_BIDIRECTION_STR)==0) { + pj_strdup(tdata->pool, &hs->credential.gb.realm, &c->realm); + pj_strdup(tdata->pool, &hs->credential.gb.algorithm, &c->gb.algorithm); + pj_strdup(tdata->pool, &hs->credential.gb.keyversion, &c->gb.keyversion); } - pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hs); + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) hs); } } } @@ -1348,12 +1249,10 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_init_req( pjsip_auth_clt_sess *sess, return PJ_SUCCESS; } - -static void recreate_cached_auth_pool( pjsip_endpoint *endpt, - pjsip_cached_auth *auth ) +static void +recreate_cached_auth_pool(pjsip_endpoint *endpt, pjsip_cached_auth *auth) { - pj_pool_t *auth_pool = pjsip_endpt_create_pool(endpt, "auth_cli%p", 1024, - 1024); + pj_pool_t *auth_pool = pjsip_endpt_create_pool(endpt, "auth_cli%p", 1024, 1024); if (auth->realm.slen) { pj_str_t realm; @@ -1368,8 +1267,7 @@ static void recreate_cached_auth_pool( pjsip_endpoint *endpt, } if (auth->last_chal) { - auth->last_chal = (pjsip_www_authenticate_hdr*) - pjsip_hdr_clone(auth_pool, auth->last_chal); + auth->last_chal = (pjsip_www_authenticate_hdr *) pjsip_hdr_clone(auth_pool, auth->last_chal); } pjsip_endpt_release_pool(endpt, auth->pool); @@ -1377,14 +1275,15 @@ static void recreate_cached_auth_pool( pjsip_endpoint *endpt, } /* Process authorization challenge */ -static pj_status_t process_auth( pj_pool_t *req_pool, - const pjsip_www_authenticate_hdr *hchal, - const pjsip_uri *uri, - pjsip_tx_data *tdata, - pjsip_auth_clt_sess *sess, - pjsip_cached_auth *cached_auth, - pjsip_authorization_hdr **h_auth, - const pjsip_auth_algorithm_type challenge_algorithm_type) +static pj_status_t +process_auth(pj_pool_t *req_pool, + const pjsip_www_authenticate_hdr *hchal, + const pjsip_uri *uri, + pjsip_tx_data *tdata, + pjsip_auth_clt_sess *sess, + pjsip_cached_auth *cached_auth, + pjsip_authorization_hdr **h_auth, + const pjsip_auth_algorithm_type challenge_algorithm_type) { const pjsip_cred_info *cred; pjsip_authorization_hdr *sent_auth = NULL; @@ -1394,27 +1293,20 @@ static pj_status_t process_auth( pj_pool_t *req_pool, /* See if we have sent authorization header for this realm (and scheme) */ hdr = tdata->msg->hdr.next; while (hdr != &tdata->msg->hdr) { - if ((hchal->type == PJSIP_H_WWW_AUTHENTICATE && - hdr->type == PJSIP_H_AUTHORIZATION) || - (hchal->type == PJSIP_H_PROXY_AUTHENTICATE && - hdr->type == PJSIP_H_PROXY_AUTHORIZATION)) - { - sent_auth = (pjsip_authorization_hdr*) hdr; - if (pj_stricmp(&hchal->challenge.common.realm, - &sent_auth->credential.common.realm)==0 && - pj_stricmp(&hchal->scheme, &sent_auth->scheme)==0) - { + if ((hchal->type == PJSIP_H_WWW_AUTHENTICATE && hdr->type == PJSIP_H_AUTHORIZATION) + || (hchal->type == PJSIP_H_PROXY_AUTHENTICATE && hdr->type == PJSIP_H_PROXY_AUTHORIZATION)) { + sent_auth = (pjsip_authorization_hdr *) hdr; + if (pj_stricmp(&hchal->challenge.common.realm, &sent_auth->credential.common.realm) == 0 + && pj_stricmp(&hchal->scheme, &sent_auth->scheme) == 0) { /* If this authorization has empty response, remove it. */ - if (pj_stricmp(&sent_auth->scheme, &pjsip_DIGEST_STR)==0 && - sent_auth->credential.digest.response.slen == 0) - { + if (pj_stricmp(&sent_auth->scheme, &pjsip_DIGEST_STR) == 0 + && sent_auth->credential.digest.response.slen == 0) { /* This is empty authorization, remove it. */ hdr = hdr->next; pj_list_erase(sent_auth); continue; } else { -#if defined(PJSIP_AUTH_ALLOW_MULTIPLE_AUTH_HEADER) && \ - PJSIP_AUTH_ALLOW_MULTIPLE_AUTH_HEADER!=0 +#if defined(PJSIP_AUTH_ALLOW_MULTIPLE_AUTH_HEADER) && PJSIP_AUTH_ALLOW_MULTIPLE_AUTH_HEADER != 0 /* * Keep sending additional headers if the the algorithm * is different. @@ -1423,17 +1315,16 @@ static pj_status_t process_auth( pj_pool_t *req_pool, * a header with a more secure digest algorithm has already * been sent. */ - if (pj_stricmp(&sent_auth->scheme, &pjsip_DIGEST_STR)==0 && - pj_stricmp(&sent_auth->credential.digest.algorithm, - &hchal->challenge.digest.algorithm)!=0) - { + if (pj_stricmp(&sent_auth->scheme, &pjsip_DIGEST_STR) == 0 + && pj_stricmp(&sent_auth->credential.digest.algorithm, &hchal->challenge.digest.algorithm) + != 0) { /* Same 'digest' scheme but different algo */ hdr = hdr->next; continue; } else #endif - /* Found previous authorization attempt */ - break; + /* Found previous authorization attempt */ + break; } } } @@ -1456,20 +1347,19 @@ static pj_status_t process_auth( pj_pool_t *req_pool, * (broken ones!) want to change nonce but they fail to set * stale to true. */ - stale = pj_strcmp(&hchal->challenge.digest.nonce, - &sent_auth->credential.digest.nonce); + stale = pj_strcmp(&hchal->challenge.digest.nonce, &sent_auth->credential.digest.nonce); } if (stale == PJ_FALSE) { /* Our credential is rejected. No point in trying to re-supply * the same credential. */ - PJ_LOG(4, (THIS_FILE, "Authorization failed for %.*s@%.*s: " - "server rejected with stale=false", - (int)sent_auth->credential.digest.username.slen, - sent_auth->credential.digest.username.ptr, - (int)sent_auth->credential.digest.realm.slen, - sent_auth->credential.digest.realm.ptr)); + PJ_LOG(4, + (THIS_FILE, + "Authorization failed for %.*s@%.*s: " + "server rejected with stale=false", + (int) sent_auth->credential.digest.username.slen, sent_auth->credential.digest.username.ptr, + (int) sent_auth->credential.digest.realm.slen, sent_auth->credential.digest.realm.ptr)); return PJSIP_EFAILEDCREDENTIAL; } @@ -1478,12 +1368,12 @@ static pj_status_t process_auth( pj_pool_t *req_pool, /* Our credential is rejected. No point in trying to re-supply * the same credential. */ - PJ_LOG(4, (THIS_FILE, "Authorization failed for %.*s@%.*s: " - "maximum number of stale retries exceeded", - (int)sent_auth->credential.digest.username.slen, - sent_auth->credential.digest.username.ptr, - (int)sent_auth->credential.digest.realm.slen, - sent_auth->credential.digest.realm.ptr)); + PJ_LOG(4, + (THIS_FILE, + "Authorization failed for %.*s@%.*s: " + "maximum number of stale retries exceeded", + (int) sent_auth->credential.digest.username.slen, sent_auth->credential.digest.username.ptr, + (int) sent_auth->credential.digest.realm.slen, sent_auth->credential.digest.realm.ptr)); return PJSIP_EAUTHSTALECOUNT; } @@ -1494,41 +1384,43 @@ static pj_status_t process_auth( pj_pool_t *req_pool, } /* Find credential to be used for the challenge. */ - cred = auth_find_cred( sess, &hchal->challenge.common.realm, - &hchal->scheme, challenge_algorithm_type); + cred = auth_find_cred(sess, + &hchal->challenge.common.realm, + &hchal->scheme, + challenge_algorithm_type, + NULL, NULL); if (!cred) { const pj_str_t *realm = &hchal->challenge.common.realm; - AUTH_TRACE_((THIS_FILE, "No cred for for %.*s", - (int)hchal->challenge.digest.algorithm.slen, hchal->challenge.digest.algorithm.ptr)); + AUTH_TRACE_((THIS_FILE, "No cred for for %.*s", (int) hchal->challenge.digest.algorithm.slen, + hchal->challenge.digest.algorithm.ptr)); - PJ_LOG(4,(THIS_FILE, - "Unable to set auth for %s: can not find credential for " - "%.*s/%.*s %.*s", - tdata->obj_name, - (int)realm->slen, realm->ptr, - (int)hchal->scheme.slen, hchal->scheme.ptr, - (int)hchal->challenge.digest.algorithm.slen, hchal->challenge.digest.algorithm.ptr)); + PJ_LOG(4, + (THIS_FILE, + "Unable to set auth for %s: can not find credential for " + "%.*s/%.*s %.*s", + tdata->obj_name, (int) realm->slen, realm->ptr, (int) hchal->scheme.slen, hchal->scheme.ptr, + (int) hchal->challenge.digest.algorithm.slen, hchal->challenge.digest.algorithm.ptr)); return PJSIP_ENOCREDENTIAL; } /* Respond to authorization challenge. */ - status = auth_respond( req_pool, hchal, uri, cred, - &tdata->msg->line.req.method, - sess->pool, cached_auth, h_auth, challenge_algorithm_type); + status = auth_respond(req_pool, hchal, uri, cred, &tdata->msg->line.req.method, sess->pool, cached_auth, h_auth, + challenge_algorithm_type); return status; } - /* Reinitialize outgoing request after 401/407 response is received. * The purpose of this function is: * - to add a Authorization/Proxy-Authorization header. * - to put the newly created Authorization/Proxy-Authorization header * in cached_list. */ -PJ_DEF(pj_status_t) pjsip_auth_clt_reinit_req( pjsip_auth_clt_sess *sess, - const pjsip_rx_data *rdata, - pjsip_tx_data *old_request, - pjsip_tx_data **new_request ) +PJ_DEF(pj_status_t) + +pjsip_auth_clt_reinit_req(pjsip_auth_clt_sess *sess, + const pjsip_rx_data *rdata, + pjsip_tx_data *old_request, + pjsip_tx_data **new_request) { pjsip_tx_data *tdata; const pjsip_hdr *hdr; @@ -1536,16 +1428,18 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_reinit_req( pjsip_auth_clt_sess *sess, pjsip_via_hdr *via; pj_status_t status; pj_status_t last_auth_err; + const pjsip_cred_info *cred; +#if (PJSIP_AUTH_HEADER_CACHING) + pj_pool_t *default_pool = old_request->pool; +#else + pj_pool_t *default_pool = sess->pool; +#endif - PJ_ASSERT_RETURN(sess && rdata && old_request && new_request, - PJ_EINVAL); + PJ_ASSERT_RETURN(sess && rdata && old_request && new_request, PJ_EINVAL); PJ_ASSERT_RETURN(sess->pool, PJSIP_ENOTINITIALIZED); - PJ_ASSERT_RETURN(rdata->msg_info.msg->type == PJSIP_RESPONSE_MSG, - PJSIP_ENOTRESPONSEMSG); - PJ_ASSERT_RETURN(old_request->msg->type == PJSIP_REQUEST_MSG, - PJSIP_ENOTREQUESTMSG); - PJ_ASSERT_RETURN(rdata->msg_info.msg->line.status.code == 401 || - rdata->msg_info.msg->line.status.code == 407, + PJ_ASSERT_RETURN(rdata->msg_info.msg->type == PJSIP_RESPONSE_MSG, PJSIP_ENOTRESPONSEMSG); + PJ_ASSERT_RETURN(old_request->msg->type == PJSIP_REQUEST_MSG, PJSIP_ENOTREQUESTMSG); + PJ_ASSERT_RETURN(rdata->msg_info.msg->line.status.code == 401 || rdata->msg_info.msg->line.status.code == 407, PJSIP_EINVALIDSTATUS); tdata = old_request; @@ -1565,99 +1459,125 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_reinit_req( pjsip_auth_clt_sess *sess, const pjsip_auth_algorithm *algorithm; /* Find WWW-Authenticate or Proxy-Authenticate header. */ - while (hdr != &rdata->msg_info.msg->hdr && - hdr->type != PJSIP_H_WWW_AUTHENTICATE && - hdr->type != PJSIP_H_PROXY_AUTHENTICATE) - { + while (hdr != &rdata->msg_info.msg->hdr && hdr->type != PJSIP_H_WWW_AUTHENTICATE + && hdr->type != PJSIP_H_PROXY_AUTHENTICATE) { hdr = hdr->next; } - if (hdr == &rdata->msg_info.msg->hdr) - break; + if (hdr == &rdata->msg_info.msg->hdr) break; - hchal = (const pjsip_www_authenticate_hdr*)hdr; + hchal = (const pjsip_www_authenticate_hdr *) hdr; ++chal_cnt; /* At the current time, "digest" scheme is the only one supported. */ - if (pj_stricmp(&hchal->scheme, &pjsip_DIGEST_STR) != 0) { - AUTH_TRACE_((THIS_FILE, "Skipped header for scheme %.*s", - (int)hchal->scheme.slen, hchal->scheme.ptr)); + if (pj_stricmp(&hchal->scheme, &pjsip_DIGEST_STR) == 0) { + + algorithm = pjsip_auth_get_algorithm_by_iana_name(&hchal->challenge.digest.algorithm); + if (!algorithm) { + AUTH_TRACE_((THIS_FILE, "Skipped header for algorithm %.*s", (int) algorithm->iana_name.slen, + algorithm->iana_name.ptr)); + last_auth_err = PJSIP_EINVALIDALGORITHM; + hdr = hdr->next; + continue; + } + + /* Find authentication session for this realm, create a new one + * if not present. + */ + cached_auth = find_cached_auth(sess, &hchal->challenge.common.realm, algorithm->algorithm_type); + if (!cached_auth) { + cached_auth = PJ_POOL_ZALLOC_T(sess->pool, pjsip_cached_auth); + cached_auth->pool = pjsip_endpt_create_pool(sess->endpt, "auth_cli%p", 1024, 1024); + pj_strdup(cached_auth->pool, &cached_auth->realm, &hchal->challenge.common.realm); + cached_auth->is_proxy = (hchal->type == PJSIP_H_PROXY_AUTHENTICATE); + cached_auth->challenge_algorithm_type = algorithm->algorithm_type; +#if (PJSIP_AUTH_HEADER_CACHING) + { + pj_list_init(&cached_auth->cached_hdr); + } +#endif + pj_list_insert_before(&sess->cached_auth, cached_auth); + } + + /* Create authorization header for this challenge, and update + * authorization session. + */ + status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri, tdata, sess, cached_auth, &hauth, + algorithm->algorithm_type); + if (status != PJ_SUCCESS) { + last_auth_err = status; + AUTH_TRACE_( + (THIS_FILE, "Skipped header for realm %.*s algorithm %.*s", (int) hchal->challenge.common.realm.slen, + hchal->challenge.common.realm.ptr, (int) algorithm->iana_name.slen, algorithm->iana_name.ptr)); + + /* Process next header. */ + hdr = hdr->next; + continue; + } + + if (pj_pool_get_used_size(cached_auth->pool) > PJSIP_AUTH_CACHED_POOL_MAX_SIZE) { + recreate_cached_auth_pool(sess->endpt, cached_auth); + } + + /* Add to the message. */ + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) hauth); + } else if (pj_stricmp(&hchal->scheme, &pjsip_CAPABILITY_STR)) { + cred = auth_find_cred(sess, + &hchal->challenge.gb.realm, + &hchal->scheme, + PJSIP_AUTH_ALGORITHM_NOT_SET, + &hchal->challenge.gb.algorithm, + &hchal->challenge.gb.keyversion); + if (!cred) { + const pj_str_t *realm = &hchal->challenge.common.realm; + AUTH_TRACE_((THIS_FILE, "No cred for for %.*s", (int) hchal->challenge.gb.algorithm.slen, + hchal->challenge.gb.algorithm.ptr)); + + PJ_LOG(4, + (THIS_FILE, + "Unable to set auth for %s: can not find credential for " + "%.*s/%.*s %.*s", + tdata->obj_name, (int) realm->slen, realm->ptr, (int) hchal->scheme.slen, hchal->scheme.ptr, + (int) hchal->challenge.gb.algorithm.slen, hchal->challenge.gb.algorithm.ptr)); + return PJSIP_ENOCREDENTIAL; + } + // TODO: Gb35114 Auth + hauth = pjsip_authorization_hdr_create(default_pool); + if (cred->gb.cb) { + status = cred->gb.cb(default_pool, &hchal->challenge.gb, cred, &tdata->msg->line.req.method.name, &hauth->credential.gb); + if (status != PJ_SUCCESS) { + last_auth_err = status; + AUTH_TRACE_( + (THIS_FILE, "Skipped header for realm %.*s algorithm %.*s", (int) hchal->challenge.common.realm.slen, + hchal->challenge.common.realm.ptr, (int) algorithm->iana_name.slen, algorithm->iana_name.ptr)); + + /* Process next header. */ + hdr = hdr->next; + continue; + } + pj_strdup(default_pool, &hauth->scheme, &hchal->scheme); + PJ_LOG(4, (THIS_FILE, "Add auth hdr %.*s", (int)hauth->scheme.slen, hauth->scheme.ptr)); + } + pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) hauth); + } else { + AUTH_TRACE_((THIS_FILE, "Skipped header for scheme %.*s", (int) hchal->scheme.slen, hchal->scheme.ptr)); last_auth_err = PJSIP_EINVALIDAUTHSCHEME; hdr = hdr->next; continue; } - algorithm = pjsip_auth_get_algorithm_by_iana_name(&hchal->challenge.digest.algorithm); - if (!algorithm) { - AUTH_TRACE_((THIS_FILE, "Skipped header for algorithm %.*s", - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); - last_auth_err = PJSIP_EINVALIDALGORITHM; - hdr = hdr->next; - continue; - } - - /* Find authentication session for this realm, create a new one - * if not present. - */ - cached_auth = find_cached_auth(sess, &hchal->challenge.common.realm, - algorithm->algorithm_type); - if (!cached_auth) { - cached_auth = PJ_POOL_ZALLOC_T(sess->pool, pjsip_cached_auth); - cached_auth->pool = pjsip_endpt_create_pool(sess->endpt, - "auth_cli%p", - 1024, - 1024); - pj_strdup(cached_auth->pool, &cached_auth->realm, - &hchal->challenge.common.realm); - cached_auth->is_proxy = (hchal->type == PJSIP_H_PROXY_AUTHENTICATE); - cached_auth->challenge_algorithm_type = algorithm->algorithm_type; -# if (PJSIP_AUTH_HEADER_CACHING) - { - pj_list_init(&cached_auth->cached_hdr); - } -# endif - pj_list_insert_before(&sess->cached_auth, cached_auth); - } - - /* Create authorization header for this challenge, and update - * authorization session. - */ - status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri, - tdata, sess, cached_auth, &hauth, algorithm->algorithm_type); - if (status != PJ_SUCCESS) { - last_auth_err = status; - AUTH_TRACE_((THIS_FILE, "Skipped header for realm %.*s algorithm %.*s", - (int)hchal->challenge.common.realm.slen, hchal->challenge.common.realm.ptr, - (int)algorithm->iana_name.slen, algorithm->iana_name.ptr)); - - /* Process next header. */ - hdr = hdr->next; - continue; - } - - if (pj_pool_get_used_size(cached_auth->pool) > - PJSIP_AUTH_CACHED_POOL_MAX_SIZE) - { - recreate_cached_auth_pool(sess->endpt, cached_auth); - } - - /* Add to the message. */ - pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); - /* Process next header. */ hdr = hdr->next; auth_cnt++; } /* Check if challenge is present */ - if (chal_cnt == 0) - return PJSIP_EAUTHNOCHAL; + if (chal_cnt == 0) return PJSIP_EAUTHNOCHAL; /* Check if any authorization header has been created */ - if (auth_cnt == 0) - return last_auth_err; + if (auth_cnt == 0) return last_auth_err; /* Remove branch param in Via header. */ - via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); + via = (pjsip_via_hdr *) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); via->branch_param.slen = 0; /* Restore strict route set. @@ -1677,6 +1597,4 @@ PJ_DEF(pj_status_t) pjsip_auth_clt_reinit_req( pjsip_auth_clt_sess *sess, /* Done. */ *new_request = tdata; return PJ_SUCCESS; - } - diff --git a/pjsip/src/pjsip/sip_auth_msg.c b/pjsip/src/pjsip/sip_auth_msg.c index 1e2eba1..3851e00 100644 --- a/pjsip/src/pjsip/sip_auth_msg.c +++ b/pjsip/src/pjsip/sip_auth_msg.c @@ -16,6 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "pjsip/sip_msg.h" #include #include #include @@ -36,6 +37,10 @@ static pjsip_authorization_hdr* pjsip_authorization_hdr_shallow_clone( pj_pool_t static int pjsip_authorization_hdr_print( pjsip_authorization_hdr *hdr, char *buf, pj_size_t size); +static pjsip_security_info_hdr* pjsip_security_info_hdr_clone(pj_pool_t* pool, const pjsip_security_info_hdr* hdr); +static pjsip_security_info_hdr* pjsip_security_info_hdr_shallow_clone(pj_pool_t* pool, const pjsip_security_info_hdr* hdr); +static int pjsip_security_info_hdr_print(const pjsip_security_info_hdr* hdr, char* buf, pj_size_t size); + static pjsip_hdr_vptr authorization_hdr_vptr = { (pjsip_hdr_clone_fptr) &pjsip_authorization_hdr_clone, @@ -43,6 +48,12 @@ static pjsip_hdr_vptr authorization_hdr_vptr = (pjsip_hdr_print_fptr) &pjsip_authorization_hdr_print, }; +static pjsip_hdr_vptr security_info_hdr_vptr = { + (pjsip_hdr_clone_fptr) &pjsip_security_info_hdr_clone, + (pjsip_hdr_clone_fptr) &pjsip_security_info_hdr_shallow_clone, + (pjsip_hdr_print_fptr) &pjsip_security_info_hdr_print, +}; + PJ_DEF(pjsip_authorization_hdr*) pjsip_authorization_hdr_create(pj_pool_t *pool) { @@ -61,6 +72,12 @@ PJ_DEF(pjsip_proxy_authorization_hdr*) pjsip_proxy_authorization_hdr_create(pj_p pj_list_init(&hdr->credential.common.other_param); return hdr; } +PJ_DEF(pjsip_security_info_hdr*) pjsip_security_info_hdr_create(pj_pool_t* pool) { + pjsip_security_info_hdr* hdr; + hdr = PJ_POOL_ZALLOC_T(pool, pjsip_security_info_hdr); + init_hdr(hdr, PJSIP_H_SECURITY_INFO, &security_info_hdr_vptr); + return hdr; +} static int print_digest_credential(pjsip_digest_credential *cred, char *buf, pj_size_t size) { @@ -118,11 +135,51 @@ static int print_oauth_credential(pjsip_oauth_credential *cred, char *buf, return (int) (buf-startbuf); } +static int print_gb_credential(const pjsip_gb_credential *cred, char *buf, pj_size_t size) { + int printed = 0; + char* startbuf = buf; + char* endbuf = buf + size - 1; + + copy_advance_pair_quote_cond(buf, "algorithm=", 10, cred->algorithm, '"', '"'); + copy_advance_pair_quote_cond(buf, ",keyversion=", 12, cred->keyversion, '"', '"'); + copy_advance_pair_quote_cond(buf, ",random1=", 9, cred->random1, '"', '"'); + copy_advance_pair_quote_cond(buf, ",random2=", 9, cred->random2, '"', '"'); + copy_advance_pair_quote_cond(buf, ",deviceid=", 10, cred->deviceid, '"', '"'); + copy_advance_pair_quote_cond(buf, ",serverid=", 10, cred->serverid, '"', '"'); + copy_advance_pair_quote_cond(buf, ",sign1=", 7, cred->sign1, '"', '"'); + copy_advance_pair_quote_cond(buf, ",sign2=", 7, cred->sign2, '"', '"'); + copy_advance_pair_quote_cond(buf, ",cryptkey=", 10, cred->cryptkey, '"', '"'); + copy_advance_pair_quote_cond(buf, ",cyrptkey1=", 11, cred->cryptkey1, '"', '"'); + copy_advance_pair_quote_cond(buf, ",cyrptkey2=", 11, cred->cryptkey2, '"', '"'); + copy_advance_pair_quote_cond(buf, ",certificate=", 13, cred->certificate, '"', '"'); + + if (printed < 0) { + return -1; + } + buf += printed; + return (int) (buf- startbuf); +} + +void pjsip_gb_credential_clone(pj_pool_t* pool, pjsip_gb_credential* cred, const pjsip_gb_credential* rhs) { + pj_strdup(pool, &cred->algorithm, &rhs->algorithm); + pj_strdup(pool, &cred->keyversion, &rhs->keyversion); + pj_strdup(pool, &cred->random1, &rhs->random1); + pj_strdup(pool, &cred->random2, &rhs->random2); + pj_strdup(pool, &cred->sign1, &rhs->sign1); + pj_strdup(pool, &cred->sign2, &rhs->sign2); + pj_strdup(pool, &cred->deviceid, &rhs->deviceid); + pj_strdup(pool, &cred->serverid, &rhs->serverid); + pj_strdup(pool, &cred->cryptkey, &rhs->cryptkey); + pj_strdup(pool, &cred->cryptkey1, &rhs->cryptkey1); + pj_strdup(pool, &cred->cryptkey2, &rhs->cryptkey2); + pj_strdup(pool, &cred->certificate, &rhs->certificate); + pjsip_param_clone(pool, &cred->other_param, &rhs->other_param); +} static int pjsip_authorization_hdr_print( pjsip_authorization_hdr *hdr, char *buf, pj_size_t size) { - int printed; + int printed = 0; char *startbuf = buf; char *endbuf = buf + size - 1; // Need to minus one for NULL terminator @@ -145,8 +202,13 @@ static int pjsip_authorization_hdr_print( pjsip_authorization_hdr *hdr, { printed = print_oauth_credential(&hdr->credential.oauth, buf, endbuf - buf); - } - else { + } + else if (pj_stricmp(&hdr->scheme, &pjsip_CAPABILITY_STR) == 0 + || pj_stricmp(&hdr->scheme, &pjsip_BIDIRECTION_STR) == 0 + || pj_stricmp(&hdr->scheme, &pjsip_UNIDIRECTION_STR) == 0) + { + printed = print_gb_credential(&hdr->credential.gb, buf, endbuf - buf); + } else { pj_assert(0); return -1; } @@ -186,6 +248,10 @@ static pjsip_authorization_hdr* pjsip_authorization_hdr_clone( pj_pool_t *pool, } else if (pj_stricmp2(&hdr->scheme, "pgp") == 0) { pj_assert(0); return NULL; + } else if (pj_stricmp2(&hdr->scheme, "capability") == 0 + || pj_stricmp2(&hdr->scheme, "bidirection") == 0 + || pj_stricmp2(&hdr->scheme, "unidirection") == 0) { + pjsip_gb_credential_clone(pool, &hdr->credential.gb, &rhs->credential.gb); } else { pj_assert(0); return NULL; @@ -288,7 +354,7 @@ static int print_pgp_challenge( pjsip_pgp_challenge *chal, static int pjsip_www_authenticate_hdr_print( pjsip_www_authenticate_hdr *hdr, char *buf, pj_size_t size) { - int printed; + int printed = 0; char *startbuf = buf; char *endbuf = buf + size - 1; // Need to minus one for NULL terminator @@ -303,7 +369,9 @@ static int pjsip_www_authenticate_hdr_print( pjsip_www_authenticate_hdr *hdr, printed = print_digest_challenge(&hdr->challenge.digest, buf, endbuf - buf); else if (pj_stricmp2(&hdr->scheme, "pgp") == 0) printed = print_pgp_challenge(&hdr->challenge.pgp, buf, endbuf - buf); - else { + else if (pj_stricmp2(&hdr->scheme, "bidirection") == 0 || pj_stricmp2(&hdr->scheme, "unidirection") == 0) { + printed = print_gb_credential(&hdr->challenge.gb, buf, endbuf - buf); + } else { pj_assert(0); return -1; } @@ -338,6 +406,8 @@ static pjsip_www_authenticate_hdr* pjsip_www_authenticate_hdr_clone( pj_pool_t * pj_strdup(pool, &hdr->challenge.digest.qop, &rhs->challenge.digest.qop); pjsip_param_clone(pool, &hdr->challenge.digest.other_param, &rhs->challenge.digest.other_param); + } else if (pj_stricmp2(&hdr->scheme, "bidirection") == 0 || pj_stricmp2(&hdr->scheme, "unidirection") == 0) { + pjsip_gb_credential_clone(pool, &hdr->challenge.gb, &rhs->challenge.gb); } else if (pj_stricmp2(&hdr->scheme, "pgp") == 0) { pj_assert(0); return NULL; @@ -362,4 +432,38 @@ static pjsip_www_authenticate_hdr* pjsip_www_authenticate_hdr_shallow_clone( pj_ return hdr; } +static pjsip_security_info_hdr* pjsip_security_info_hdr_clone(pj_pool_t* pool, const pjsip_security_info_hdr* rhs) { + pjsip_security_info_hdr *hdr= pjsip_security_info_hdr_create(pool); + pjsip_gb_credential_clone(pool, &hdr->gb, &rhs->gb); + return hdr; +} +static pjsip_security_info_hdr* pjsip_security_info_hdr_shallow_clone(pj_pool_t* pool, const pjsip_security_info_hdr* rhs) { + pjsip_security_info_hdr *hdr; + hdr = PJ_POOL_ALLOC_T(pool, pjsip_security_info_hdr); + pj_memcpy(hdr, rhs, sizeof(*hdr)); + return hdr; +} + +static int pjsip_security_info_hdr_print(const pjsip_security_info_hdr* hdr, char* buf, pj_size_t size) { + int printed = 0; + char *startbuf = buf; + char *endbuf = buf + size - 1; // Need to minus one for NULL terminator + + copy_advance(buf, hdr->name); + copy_advance_char_check(buf, ':'); + copy_advance_char_check(buf, ' '); + + copy_advance(buf, hdr->scheme); + copy_advance_char_check(buf, ' '); + + printed = print_gb_credential(&hdr->gb, buf, endbuf - buf); + + if (printed == -1) + return -1; + + buf += printed; + *buf = '\0'; + return (int)(buf-startbuf); +} + diff --git a/pjsip/src/pjsip/sip_auth_parser.c b/pjsip/src/pjsip/sip_auth_parser.c index dd98fc8..337353d 100644 --- a/pjsip/src/pjsip/sip_auth_parser.c +++ b/pjsip/src/pjsip/sip_auth_parser.c @@ -16,67 +16,63 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include #include -#include #include #include +#include +#include +#include +#include -static pjsip_hdr* parse_hdr_authorization ( pjsip_parse_ctx *ctx ); -static pjsip_hdr* parse_hdr_proxy_authorization ( pjsip_parse_ctx *ctx ); -static pjsip_hdr* parse_hdr_www_authenticate ( pjsip_parse_ctx *ctx ); -static pjsip_hdr* parse_hdr_proxy_authenticate ( pjsip_parse_ctx *ctx ); +static pjsip_hdr *parse_hdr_authorization(pjsip_parse_ctx *ctx); +static pjsip_hdr *parse_hdr_proxy_authorization(pjsip_parse_ctx *ctx); +static pjsip_hdr *parse_hdr_www_authenticate(pjsip_parse_ctx *ctx); +static pjsip_hdr *parse_hdr_proxy_authenticate(pjsip_parse_ctx *ctx); -static void parse_digest_credential ( pj_scanner *scanner, pj_pool_t *pool, - pjsip_digest_credential *cred); -static void parse_pgp_credential ( pj_scanner *scanner, pj_pool_t *pool, - pjsip_pgp_credential *cred); -static void parse_digest_challenge ( pj_scanner *scanner, pj_pool_t *pool, - pjsip_digest_challenge *chal); -static void parse_pgp_challenge ( pj_scanner *scanner, pj_pool_t *pool, - pjsip_pgp_challenge *chal); +static void parse_digest_credential(pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred); +static void parse_pgp_credential(pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_credential *cred); +static void parse_digest_challenge(pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal); +static void parse_pgp_challenge(pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_challenge *chal); -const pj_str_t pjsip_USERNAME_STR = { "username", 8 }, - pjsip_REALM_STR = { "realm", 5}, - pjsip_NONCE_STR = { "nonce", 5}, - pjsip_URI_STR = { "uri", 3 }, - pjsip_RESPONSE_STR = { "response", 8 }, - pjsip_ALGORITHM_STR = { "algorithm", 9 }, - pjsip_DOMAIN_STR = { "domain", 6 }, - pjsip_STALE_STR = { "stale", 5}, - pjsip_QOP_STR = { "qop", 3}, - pjsip_CNONCE_STR = { "cnonce", 6}, - pjsip_OPAQUE_STR = { "opaque", 6}, - pjsip_NC_STR = { "nc", 2}, - pjsip_TRUE_STR = { "true", 4}, - pjsip_QUOTED_TRUE_STR = { "\"true\"", 6}, - pjsip_FALSE_STR = { "false", 5}, - pjsip_QUOTED_FALSE_STR = { "\"false\"", 7}, - pjsip_DIGEST_STR = { "Digest", 6}, - pjsip_QUOTED_DIGEST_STR = { "\"Digest\"", 8}, - pjsip_PGP_STR = { "PGP", 3 }, - pjsip_QUOTED_PGP_STR = { "\"PGP\"", 5 }, - pjsip_BEARER_STR = { "Bearer", 6 }, - pjsip_MD5_STR = { "MD5", 3 }, - pjsip_QUOTED_MD5_STR = { "\"MD5\"", 5}, - pjsip_SHA256_STR = { "SHA-256", 7 }, - pjsip_QUOTED_SHA256_STR = { "\"SHA-256\"", 9}, - pjsip_AUTH_STR = { "auth", 4}, - pjsip_QUOTED_AUTH_STR = { "\"auth\"", 6 }; +const pj_str_t + pjsip_USERNAME_STR = {"username", 8}, + pjsip_REALM_STR = {"realm", 5}, + pjsip_NONCE_STR = {"nonce", 5}, + pjsip_URI_STR = {"uri", 3}, + pjsip_RESPONSE_STR = {"response", 8}, pjsip_ALGORITHM_STR = {"algorithm", 9}, pjsip_RANDOM1_STR = {"random1", 7}, + pjsip_RANDOM2_STR = {"random2", 7}, pjsip_KEYVERSION_STR = {"keyversion", 10}, pjsip_DEVICEID_STR = {"deviceid", 8}, + pjsip_SERVERID_STR = {"serverid", 8}, pjsip_SIGN1_STR = {"sign1", 5}, pjsip_SIGN2_STR = {"sign2", 5}, + pjsip_CRYPTOKEY_STR = {"cryptokey", 9}, pjsip_CRYPTOKEY1_STR = {"cryptokey1", 10}, + pjsip_CRYPTOKEY2_STR = {"cryptokey2", 10}, + pjsip_CERTIFICATE_STR = {"certificate", 11}, + pjsip_DOMAIN_STR = {"domain", 6}, + pjsip_STALE_STR = {"stale", 5}, + pjsip_QOP_STR = {"qop", 3}, + pjsip_CNONCE_STR = {"cnonce", 6}, + pjsip_OPAQUE_STR = {"opaque", 6}, + pjsip_NC_STR = {"nc", 2}, + pjsip_TRUE_STR = {"true", 4}, + pjsip_QUOTED_TRUE_STR = {"\"true\"", 6}, + pjsip_FALSE_STR = {"false", 5}, + pjsip_QUOTED_FALSE_STR = {"\"false\"", 7}, + pjsip_DIGEST_STR = {"Digest", 6}, + pjsip_QUOTED_DIGEST_STR = {"\"Digest\"", 8}, pjsip_CAPABILITY_STR = {"Capability", 10}, + pjsip_QUOTED_CAPABILITY_STR = {"\"Capability\"", 12}, pjsip_UNIDIRECTION_STR = {"Unidirection", 12}, + pjsip_QUOTED_UNIDIRECTION_STR = {"\"Unidirection\"", 14}, pjsip_BIDIRECTION_STR = {"Bidirection", 11}, + pjsip_QUOTED_BIDIRECTION_STR = {"\"Bidirection\"", 13}, pjsip_PGP_STR = {"PGP", 3}, + pjsip_QUOTED_PGP_STR = {"\"PGP\"", 5}, pjsip_BEARER_STR = {"Bearer", 6}, pjsip_MD5_STR = {"MD5", 3}, + pjsip_QUOTED_MD5_STR = {"\"MD5\"", 5}, pjsip_SHA256_STR = {"SHA-256", 7}, + pjsip_QUOTED_SHA256_STR = {"\"SHA-256\"", 9}, pjsip_AUTH_STR = {"auth", 4}, pjsip_QUOTED_AUTH_STR = {"\"auth\"", 6}; - -static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, - pjsip_digest_credential *cred) +static void +parse_digest_credential(pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred) { pj_list_init(&cred->other_param); for (;;) { pj_str_t name, value; - pjsip_parse_param_imp(scanner, pool, &name, &value, - PJSIP_PARSE_REMOVE_QUOTE); + pjsip_parse_param_imp(scanner, pool, &name, &value, PJSIP_PARSE_REMOVE_QUOTE); if (!pj_stricmp(&name, &pjsip_USERNAME_STR)) { cred->username = value; @@ -123,8 +119,8 @@ static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, } } -static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, - pjsip_pgp_credential *cred) +static void +parse_pgp_credential(pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_credential *cred) { PJ_UNUSED_ARG(scanner); PJ_UNUSED_ARG(pool); @@ -133,8 +129,60 @@ static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); } -static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, - pjsip_digest_challenge *chal) +static void +parse_gb_credential(pj_scanner *scanner, pj_pool_t *pool, pjsip_gb_credential *cred) { + for (;;) { + pj_str_t name, value, unquoted_value; + pjsip_parse_param_imp(scanner, pool, &name, &value, 0); + + if (value.ptr && (value.ptr[0] == '"')) { + unquoted_value.ptr = value.ptr + 1; + unquoted_value.slen = value.slen - 2; + } else { + unquoted_value.ptr = value.ptr; + unquoted_value.slen = value.slen; + } + + if (!pj_stricmp(&name, &pjsip_ALGORITHM_STR)) { + cred->algorithm = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_KEYVERSION_STR)) { + cred->keyversion = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_RANDOM1_STR)) { + cred->random1 = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_RANDOM2_STR)) { + cred->random2 = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_DEVICEID_STR)) { + cred->deviceid = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_SERVERID_STR)) { + cred->serverid = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_SIGN1_STR)) { + cred->sign1 = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_SIGN2_STR)) { + cred->sign2 = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_CRYPTOKEY_STR)) { + cred->cryptkey = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_CRYPTOKEY1_STR)) { + cred->cryptkey1 = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_CRYPTOKEY2_STR)) { + cred->cryptkey2 = unquoted_value; + } else if (!pj_stricmp(&name, &pjsip_CERTIFICATE_STR)) { + cred->certificate= unquoted_value; + } else { + pjsip_param *p = PJ_POOL_ALLOC_T(pool, pjsip_param); + p->name = name; + p->value = value; + pj_list_insert_before(&cred->other_param, p); + } + if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') + pj_scan_get_char(scanner); + else + break; + } +} + + +static void +parse_digest_challenge(pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal) { pj_list_init(&chal->other_param); @@ -164,16 +212,13 @@ static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, chal->opaque = unquoted_value; } else if (!pj_stricmp(&name, &pjsip_STALE_STR)) { - if (!pj_stricmp(&value, &pjsip_TRUE_STR) || - !pj_stricmp(&value, &pjsip_QUOTED_TRUE_STR)) - { + if (!pj_stricmp(&value, &pjsip_TRUE_STR) || !pj_stricmp(&value, &pjsip_QUOTED_TRUE_STR)) { chal->stale = 1; } } else if (!pj_stricmp(&name, &pjsip_ALGORITHM_STR)) { chal->algorithm = unquoted_value; - } else if (!pj_stricmp(&name, &pjsip_QOP_STR)) { chal->qop = unquoted_value; @@ -192,8 +237,8 @@ static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, } } -static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, - pjsip_pgp_challenge *chal) +static void +parse_pgp_challenge(pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_challenge *chal) { PJ_UNUSED_ARG(scanner); PJ_UNUSED_ARG(pool); @@ -202,11 +247,11 @@ static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); } -static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, - pjsip_authorization_hdr *hdr) +static void +int_parse_hdr_authorization(pj_scanner *scanner, pj_pool_t *pool, pjsip_authorization_hdr *hdr) { const pjsip_parser_const_t *pc = pjsip_parser_const(); - + if (*scanner->curptr == '"') { pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); hdr->scheme.ptr++; @@ -221,17 +266,26 @@ static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, } else if (!pj_stricmp(&hdr->scheme, &pjsip_PGP_STR)) { - parse_pgp_credential( scanner, pool, &hdr->credential.pgp); + parse_pgp_credential(scanner, pool, &hdr->credential.pgp); + + } else if (!pj_stricmp(&hdr->scheme, &pjsip_CAPABILITY_STR)) { + + parse_gb_credential(scanner, pool, &hdr->credential.gb); + + } else if (!pj_stricmp(&hdr->scheme, &pjsip_UNIDIRECTION_STR) + || !pj_stricmp(&hdr->scheme, &pjsip_BIDIRECTION_STR)) { + + parse_gb_credential(scanner, pool, &hdr->credential.gb); } else { PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); } - pjsip_parse_end_hdr_imp( scanner ); + pjsip_parse_end_hdr_imp(scanner); } -static void int_parse_hdr_authenticate( pj_scanner *scanner, pj_pool_t *pool, - pjsip_www_authenticate_hdr *hdr) +static void +int_parse_hdr_authenticate(pj_scanner *scanner, pj_pool_t *pool, pjsip_www_authenticate_hdr *hdr) { const pjsip_parser_const_t *pc = pjsip_parser_const(); @@ -251,67 +305,94 @@ static void int_parse_hdr_authenticate( pj_scanner *scanner, pj_pool_t *pool, parse_pgp_challenge(scanner, pool, &hdr->challenge.pgp); + } else if (!pj_stricmp(&hdr->scheme, &pjsip_UNIDIRECTION_STR) + || !pj_stricmp(&hdr->scheme, &pjsip_BIDIRECTION_STR)) { + + parse_gb_credential(scanner, pool, &hdr->challenge.gb); + } else { PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); } - pjsip_parse_end_hdr_imp( scanner ); + pjsip_parse_end_hdr_imp(scanner); } +static void +int_parse_hdr_security_info(pj_scanner *scanner, pj_pool_t *pool, pjsip_security_info_hdr *hdr) +{ + const pjsip_parser_const_t *pc = pjsip_parser_const(); + if (*scanner->curptr == '"') { + pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); + hdr->scheme.ptr++; + hdr->scheme.slen -= 2; + } else { + pj_scan_get(scanner, &pc->pjsip_TOKEN_SPEC, &hdr->scheme); + } -static pjsip_hdr* parse_hdr_authorization( pjsip_parse_ctx *ctx ) + if (!pj_stricmp(&hdr->scheme, &pjsip_UNIDIRECTION_STR) || !pj_stricmp(&hdr->scheme, &pjsip_UNIDIRECTION_STR)) { + parse_gb_credential(scanner, pool, &hdr->gb); + } else { + PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); + } + pjsip_parse_end_hdr_imp(scanner); +} + +static pjsip_hdr * +parse_hdr_authorization(pjsip_parse_ctx *ctx) { pjsip_authorization_hdr *hdr = pjsip_authorization_hdr_create(ctx->pool); int_parse_hdr_authorization(ctx->scanner, ctx->pool, hdr); - return (pjsip_hdr*)hdr; + return (pjsip_hdr *) hdr; } -static pjsip_hdr* parse_hdr_proxy_authorization( pjsip_parse_ctx *ctx ) +static pjsip_hdr * +parse_hdr_proxy_authorization(pjsip_parse_ctx *ctx) { - pjsip_proxy_authorization_hdr *hdr = - pjsip_proxy_authorization_hdr_create(ctx->pool); + pjsip_proxy_authorization_hdr *hdr = pjsip_proxy_authorization_hdr_create(ctx->pool); int_parse_hdr_authorization(ctx->scanner, ctx->pool, hdr); - return (pjsip_hdr*)hdr; + return (pjsip_hdr *) hdr; } -static pjsip_hdr* parse_hdr_www_authenticate( pjsip_parse_ctx *ctx ) +static pjsip_hdr * +parse_hdr_www_authenticate(pjsip_parse_ctx *ctx) { - pjsip_www_authenticate_hdr *hdr = - pjsip_www_authenticate_hdr_create(ctx->pool); + pjsip_www_authenticate_hdr *hdr = pjsip_www_authenticate_hdr_create(ctx->pool); int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); - return (pjsip_hdr*)hdr; + return (pjsip_hdr *) hdr; } -static pjsip_hdr* parse_hdr_proxy_authenticate( pjsip_parse_ctx *ctx ) +static pjsip_hdr * +parse_hdr_security_info(pjsip_parse_ctx *ctx) { - pjsip_proxy_authenticate_hdr *hdr = - pjsip_proxy_authenticate_hdr_create(ctx->pool); - int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); - return (pjsip_hdr*)hdr; + pjsip_security_info_hdr *hdr = pjsip_security_info_hdr_create(ctx->pool); + int_parse_hdr_security_info(ctx->scanner, ctx->pool, hdr); + return (pjsip_hdr *) hdr; } +static pjsip_hdr * +parse_hdr_proxy_authenticate(pjsip_parse_ctx *ctx) +{ + pjsip_proxy_authenticate_hdr *hdr = pjsip_proxy_authenticate_hdr_create(ctx->pool); + int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); + return (pjsip_hdr *) hdr; +} PJ_DEF(pj_status_t) pjsip_auth_init_parser() { pj_status_t status; - status = pjsip_register_hdr_parser( "Authorization", NULL, - &parse_hdr_authorization); - PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); - status = pjsip_register_hdr_parser( "Proxy-Authorization", NULL, - &parse_hdr_proxy_authorization); - PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); - status = pjsip_register_hdr_parser( "WWW-Authenticate", NULL, - &parse_hdr_www_authenticate); - PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); - status = pjsip_register_hdr_parser( "Proxy-Authenticate", NULL, - &parse_hdr_proxy_authenticate); - PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); + status = pjsip_register_hdr_parser("Authorization", NULL, &parse_hdr_authorization); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); + status = pjsip_register_hdr_parser("Proxy-Authorization", NULL, &parse_hdr_proxy_authorization); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); + status = pjsip_register_hdr_parser("WWW-Authenticate", NULL, &parse_hdr_www_authenticate); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); + status = pjsip_register_hdr_parser("SecurityInfo", NULL, &parse_hdr_security_info); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); + status = pjsip_register_hdr_parser("Proxy-Authenticate", NULL, &parse_hdr_proxy_authenticate); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); return PJ_SUCCESS; } -PJ_DEF(void) pjsip_auth_deinit_parser() -{ -} - +PJ_DEF(void) pjsip_auth_deinit_parser() {} diff --git a/pjsip/src/pjsip/sip_errno.c b/pjsip/src/pjsip/sip_errno.c index 6ea09c7..f1cd521 100644 --- a/pjsip/src/pjsip/sip_errno.c +++ b/pjsip/src/pjsip/sip_errno.c @@ -132,6 +132,7 @@ static const struct PJ_BUILD_ERR( PJSIP_TLS_EREAD, "Unknown error when reading SSL data"), PJ_BUILD_ERR( PJSIP_TLS_ETIMEDOUT, "SSL negotiation has timed out"), PJ_BUILD_ERR( PJSIP_TLS_ECERTVERIF, "SSL certificate verification error"), + PJ_BUILD_ERR( PJSIP_ETODO, "Not implement, @tqcq"), }; diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index c66c54f..64763c4 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -16,6 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "pjsip/sip_auth_parser.h" #include #include @@ -2960,23 +2961,29 @@ PJ_DEF(pj_status_t) pjsua_acc_set_registration( pjsua_acc_id acc_id, PJSUA_REG_AUTO_REG_REFRESH, &tdata); - if (0 && status == PJ_SUCCESS && pjsua_var.acc[acc_id].cred_cnt) { - pjsip_authorization_hdr *h; + // if (0 && status == PJ_SUCCESS && pjsua_var.acc[acc_id].cred_cnt) { + if (status == PJ_SUCCESS && pjsua_var.acc[acc_id].cred_cnt) { + pjsip_authorization_hdr *h = pjsip_authorization_hdr_create(tdata->pool); char *uri; int d; - uri = (char*) pj_pool_alloc(tdata->pool, acc->cfg.reg_uri.slen+10); - d = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, tdata->msg->line.req.uri, - uri, acc->cfg.reg_uri.slen+10); - pj_assert(d > 0); - PJ_UNUSED_ARG(d); + if (PJSIP_CRED_DATA_IS_GB(&pjsua_var.acc[acc_id].cred[0])) { + h->scheme = pjsip_CAPABILITY_STR; + h->credential.gb.algorithm = pjsua_var.acc[acc_id].cred[0].gb.algorithm; + h->credential.gb.keyversion= pjsua_var.acc[acc_id].cred[0].gb.keyversion; + } else { + uri = (char*) pj_pool_alloc(tdata->pool, acc->cfg.reg_uri.slen+10); + d = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, tdata->msg->line.req.uri, + uri, acc->cfg.reg_uri.slen+10); + pj_assert(d > 0); + PJ_UNUSED_ARG(d); - h = pjsip_authorization_hdr_create(tdata->pool); - h->scheme = pjsip_DIGEST_STR; - h->credential.digest.username = acc->cred[0].username; - h->credential.digest.realm = acc->srv_domain; - h->credential.digest.uri = pj_str(uri); - h->credential.digest.algorithm = pjsip_MD5_STR; + h->scheme = pjsip_DIGEST_STR; + h->credential.digest.username = acc->cred[0].username; + h->credential.digest.realm = acc->srv_domain; + h->credential.digest.uri = pj_str(uri); + h->credential.digest.algorithm = pjsip_MD5_STR; + } pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)h); } diff --git a/pjsip/src/pjsua2/account.cpp b/pjsip/src/pjsua2/account.cpp index 7c65bfc..cfed6f9 100644 --- a/pjsip/src/pjsua2/account.cpp +++ b/pjsip/src/pjsua2/account.cpp @@ -605,6 +605,7 @@ void AccountConfig::toPj(pjsua_acc_config &ret) const const AuthCredInfo &src = sipConfig.authCreds[i]; pjsip_cred_info *dst = &ret.cred_info[i]; + /* dst->realm = str2Pj(src.realm); dst->scheme = str2Pj(src.scheme); dst->username = str2Pj(src.username); @@ -613,6 +614,10 @@ void AccountConfig::toPj(pjsua_acc_config &ret) const dst->ext.aka.k = str2Pj(src.akaK); dst->ext.aka.op = str2Pj(src.akaOp); dst->ext.aka.amf= str2Pj(src.akaAmf); + dst->gb.algorithm = str2Pj(src.gbAlgorithm); + dst->gb.random1 = str2Pj(src.gbRandom1); + */ + *dst = src.toPj(); ret.cred_count++; } @@ -769,7 +774,9 @@ void AccountConfig::fromPj(const pjsua_acc_config &prm, for (i=0; iext.aka.cb = (pjsip_cred_cb) + dst->ext.aka.cb = (pjsip_cred_digest_cb) &Endpoint::on_auth_create_aka_response_callback; + dst->gb.cb = &Endpoint::on_auth_create_gb_response_callback; } pj_acc_cfg.user_data = (void*)this; PJSUA2_CHECK_EXPR( pjsua_acc_add(&pj_acc_cfg, make_default, &id) ); diff --git a/pjsip/src/pjsua2/endpoint.cpp b/pjsip/src/pjsua2/endpoint.cpp index 559e7aa..6a436ba 100644 --- a/pjsip/src/pjsua2/endpoint.cpp +++ b/pjsip/src/pjsua2/endpoint.cpp @@ -20,6 +20,7 @@ #include #include #include +#include "pjsip/sip_auth_msg.h" #include "util.hpp" using namespace pj; @@ -214,6 +215,51 @@ pjsip_digest_challenge DigestChallenge::toPj() const return challenge; } +void GBCredential::fromPj(const pjsip_gb_credential &prm) { + realm = pj2Str(prm.realm); + pjsip_param*p = (pjsip_param*)prm.other_param.next; + while (p != &prm.other_param) { + otherParam[pj2Str(p->name)] = pj2Str(p->value); + } + algorithm = pj2Str(prm.algorithm ); + keyversion = pj2Str(prm.keyversion); + random1 = pj2Str(prm.random1 ); + random2 = pj2Str(prm.random2); + deviceid = pj2Str(prm.deviceid); + serverid = pj2Str(prm.serverid); + sign1 = pj2Str(prm.sign1); + sign2 = pj2Str(prm.sign2); + cryptkey = pj2Str(prm.cryptkey ); + cryptkey1 = pj2Str(prm.cryptkey1 ); + cryptkey2 = pj2Str(prm.cryptkey2 ); + certificate = pj2Str(prm.certificate ); +} + +pjsip_gb_credential GBCredential::toPj() const { + pjsip_gb_credential challenge; + pj_list_init(&challenge.other_param); + for(const auto& item: otherParam) { + pjsip_param other_param; + other_param.name = str2Pj(item.first); + other_param.value= str2Pj(item.second); + pj_list_push_back(&challenge.other_param, &other_param); + } + challenge.algorithm = str2Pj(algorithm); + challenge.realm= str2Pj(realm); + challenge.keyversion= str2Pj(keyversion); + challenge.random1= str2Pj(random1); + challenge.random2= str2Pj(random2); + challenge.deviceid= str2Pj(deviceid); + challenge.serverid= str2Pj(serverid); + challenge.sign1= str2Pj(serverid); + challenge.sign2= str2Pj(serverid); + challenge.cryptkey= str2Pj(cryptkey); + challenge.cryptkey1= str2Pj(cryptkey1); + challenge.cryptkey2= str2Pj(cryptkey2); + challenge.certificate= str2Pj(certificate); + return challenge; +} + /////////////////////////////////////////////////////////////////////////////// IpChangeParam::IpChangeParam() { @@ -2753,6 +2799,26 @@ pj_status_t Endpoint::on_auth_create_aka_response_callback(pj_pool_t *pool, #endif return status; } +pj_status_t Endpoint::on_auth_create_gb_response_callback( + pj_pool_t *pool, + const pjsip_gb_challenge*chal, + const pjsip_cred_info *cred, + const pj_str_t *method, + pjsip_gb_credential *auth) { + OnCredAuthParam prm; + prm.gbChallenge.fromPj(*chal); + prm.credentialInfo.fromPj(*cred); + prm.method = pj2Str(*method); + prm.gbCredential.fromPj(*auth); + pj_status_t status = Endpoint::instance().onCredAuth(prm); + if (status == PJ_SUCCESS) { + pjsip_gb_credential auth_new = prm.gbCredential.toPj(); + pjsip_gb_credential_clone(pool, auth, &auth_new); + } + + return status; +} + void Endpoint::on_rejected_incoming_call( const pjsua_on_rejected_incoming_call_param *param) diff --git a/pjsip/src/pjsua2/siptypes.cpp b/pjsip/src/pjsua2/siptypes.cpp index 2799343..d86d10f 100644 --- a/pjsip/src/pjsua2/siptypes.cpp +++ b/pjsip/src/pjsua2/siptypes.cpp @@ -15,64 +15,57 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include #include "util.hpp" +#include +#include +#include using namespace pj; using namespace std; -#define THIS_FILE "siptypes.cpp" +#define THIS_FILE "siptypes.cpp" /////////////////////////////////////////////////////////////////////////////// -namespace pj -{ -void readIntVector( ContainerNode &node, - const string &array_name, - IntVector &v) PJSUA2_THROW(Error) +namespace pj { +void +readIntVector(ContainerNode &node, const string &array_name, IntVector &v) PJSUA2_THROW(Error) { ContainerNode array_node = node.readArray(array_name); v.resize(0); - while (array_node.hasUnread()) { - v.push_back((int)array_node.readNumber()); - } + while (array_node.hasUnread()) { v.push_back((int) array_node.readNumber()); } } -void writeIntVector(ContainerNode &node, - const string &array_name, - const IntVector &v) PJSUA2_THROW(Error) +void +writeIntVector(ContainerNode &node, const string &array_name, const IntVector &v) PJSUA2_THROW(Error) { ContainerNode array_node = node.writeNewArray(array_name); - for (unsigned i=0; ifromPj(ts); } -pjsip_tls_setting TlsConfig::toPj() const +pjsip_tls_setting +TlsConfig::toPj() const { pjsip_tls_setting ts; pjsip_tls_setting_default(&ts); - ts.ca_list_file = str2Pj(this->CaListFile); - ts.cert_file = str2Pj(this->certFile); - ts.privkey_file = str2Pj(this->privKeyFile); - ts.password = str2Pj(this->password); - ts.ca_buf = str2Pj(this->CaBuf); - ts.cert_buf = str2Pj(this->certBuf); - ts.privkey_buf = str2Pj(this->privKeyBuf); + ts.ca_list_file = str2Pj(this->CaListFile); + ts.cert_file = str2Pj(this->certFile); + ts.privkey_file = str2Pj(this->privKeyFile); + ts.password = str2Pj(this->password); + ts.ca_buf = str2Pj(this->CaBuf); + ts.cert_buf = str2Pj(this->certBuf); + ts.privkey_buf = str2Pj(this->privKeyBuf); ts.cert_lookup.type = this->certLookupType; ts.cert_lookup.keyword = str2Pj(this->certLookupKeyword); - ts.method = this->method; - ts.ciphers_num = (unsigned)this->ciphers.size(); - ts.proto = this->proto; + ts.method = this->method; + ts.ciphers_num = (unsigned) this->ciphers.size(); + ts.proto = this->proto; // The following will only work if sizeof(enum)==sizeof(int) pj_assert(sizeof(ts.ciphers[0]) == sizeof(int)); - ts.ciphers = ts.ciphers_num? - (pj_ssl_cipher*)&this->ciphers[0] : NULL; - ts.verify_server = this->verifyServer; - ts.verify_client = this->verifyClient; + ts.ciphers = ts.ciphers_num ? (pj_ssl_cipher *) &this->ciphers[0] : NULL; + ts.verify_server = this->verifyServer; + ts.verify_client = this->verifyClient; ts.require_client_cert = this->requireClientCert; - ts.timeout.sec = this->msecTimeout / 1000; - ts.timeout.msec = this->msecTimeout % 1000; - ts.qos_type = this->qosType; - ts.qos_params = this->qosParams; + ts.timeout.sec = this->msecTimeout / 1000; + ts.timeout.msec = this->msecTimeout % 1000; + ts.qos_type = this->qosType; + ts.qos_params = this->qosParams; ts.qos_ignore_error = this->qosIgnoreError; - ts.sockopt_params = this->sockOptParams.toPj(); + ts.sockopt_params = this->sockOptParams.toPj(); ts.sockopt_ignore_error = this->sockOptIgnoreError; ts.enable_renegotiation = this->enableRenegotiation; return ts; } -void TlsConfig::fromPj(const pjsip_tls_setting &prm) +void +TlsConfig::fromPj(const pjsip_tls_setting &prm) { - this->CaListFile = pj2Str(prm.ca_list_file); - this->certFile = pj2Str(prm.cert_file); - this->privKeyFile = pj2Str(prm.privkey_file); - this->password = pj2Str(prm.password); - this->CaBuf = pj2Str(prm.ca_buf); - this->certBuf = pj2Str(prm.cert_buf); - this->privKeyBuf = pj2Str(prm.privkey_buf); - this->certLookupType= prm.cert_lookup.type; + this->CaListFile = pj2Str(prm.ca_list_file); + this->certFile = pj2Str(prm.cert_file); + this->privKeyFile = pj2Str(prm.privkey_file); + this->password = pj2Str(prm.password); + this->CaBuf = pj2Str(prm.ca_buf); + this->certBuf = pj2Str(prm.cert_buf); + this->privKeyBuf = pj2Str(prm.privkey_buf); + this->certLookupType = prm.cert_lookup.type; this->certLookupKeyword = pj2Str(prm.cert_lookup.keyword); - this->method = (pjsip_ssl_method)prm.method; - this->proto = prm.proto; + this->method = (pjsip_ssl_method) prm.method; + this->proto = prm.proto; // The following will only work if sizeof(enum)==sizeof(int) pj_assert(sizeof(prm.ciphers[0]) == sizeof(int)); - this->ciphers = IntVector(prm.ciphers, prm.ciphers+prm.ciphers_num); - this->verifyServer = PJ2BOOL(prm.verify_server); - this->verifyClient = PJ2BOOL(prm.verify_client); + this->ciphers = IntVector(prm.ciphers, prm.ciphers + prm.ciphers_num); + this->verifyServer = PJ2BOOL(prm.verify_server); + this->verifyClient = PJ2BOOL(prm.verify_client); this->requireClientCert = PJ2BOOL(prm.require_client_cert); - this->msecTimeout = PJ_TIME_VAL_MSEC(prm.timeout); - this->qosType = prm.qos_type; - this->qosParams = prm.qos_params; + this->msecTimeout = PJ_TIME_VAL_MSEC(prm.timeout); + this->qosType = prm.qos_type; + this->qosParams = prm.qos_params; this->qosIgnoreError = PJ2BOOL(prm.qos_ignore_error); this->sockOptParams.fromPj(prm.sockopt_params); this->sockOptIgnoreError = PJ2BOOL(prm.sockopt_ignore_error); this->enableRenegotiation = PJ2BOOL(prm.enable_renegotiation); } -void TlsConfig::readObject(const ContainerNode &node) PJSUA2_THROW(Error) +void +TlsConfig::readObject(const ContainerNode &node) PJSUA2_THROW(Error) { ContainerNode this_node = node.readContainer("TlsConfig"); - NODE_READ_STRING ( this_node, CaListFile); - NODE_READ_STRING ( this_node, certFile); - NODE_READ_STRING ( this_node, privKeyFile); - NODE_READ_STRING ( this_node, password); - NODE_READ_STRING ( this_node, CaBuf); - NODE_READ_STRING ( this_node, certBuf); - NODE_READ_STRING ( this_node, privKeyBuf); - NODE_READ_NUM_T ( this_node, pjsip_ssl_method, method); - readIntVector ( this_node, "ciphers", ciphers); - NODE_READ_BOOL ( this_node, verifyServer); - NODE_READ_BOOL ( this_node, verifyClient); - NODE_READ_BOOL ( this_node, requireClientCert); - NODE_READ_UNSIGNED( this_node, msecTimeout); - NODE_READ_NUM_T ( this_node, pj_qos_type, qosType); - readQosParams ( this_node, qosParams); - NODE_READ_BOOL ( this_node, qosIgnoreError); - NODE_READ_OBJ ( this_node, sockOptParams); - NODE_READ_BOOL ( this_node, sockOptIgnoreError); - NODE_READ_NUM_T ( this_node, pj_ssl_cert_lookup_type, certLookupType); - NODE_READ_STRING ( this_node, certLookupKeyword); + NODE_READ_STRING(this_node, CaListFile); + NODE_READ_STRING(this_node, certFile); + NODE_READ_STRING(this_node, privKeyFile); + NODE_READ_STRING(this_node, password); + NODE_READ_STRING(this_node, CaBuf); + NODE_READ_STRING(this_node, certBuf); + NODE_READ_STRING(this_node, privKeyBuf); + NODE_READ_NUM_T(this_node, pjsip_ssl_method, method); + readIntVector(this_node, "ciphers", ciphers); + NODE_READ_BOOL(this_node, verifyServer); + NODE_READ_BOOL(this_node, verifyClient); + NODE_READ_BOOL(this_node, requireClientCert); + NODE_READ_UNSIGNED(this_node, msecTimeout); + NODE_READ_NUM_T(this_node, pj_qos_type, qosType); + readQosParams(this_node, qosParams); + NODE_READ_BOOL(this_node, qosIgnoreError); + NODE_READ_OBJ(this_node, sockOptParams); + NODE_READ_BOOL(this_node, sockOptIgnoreError); + NODE_READ_NUM_T(this_node, pj_ssl_cert_lookup_type, certLookupType); + NODE_READ_STRING(this_node, certLookupKeyword); } -void TlsConfig::writeObject(ContainerNode &node) const PJSUA2_THROW(Error) +void +TlsConfig::writeObject(ContainerNode &node) const PJSUA2_THROW(Error) { ContainerNode this_node = node.writeNewContainer("TlsConfig"); - NODE_WRITE_STRING ( this_node, CaListFile); - NODE_WRITE_STRING ( this_node, certFile); - NODE_WRITE_STRING ( this_node, privKeyFile); - NODE_WRITE_STRING ( this_node, password); - NODE_WRITE_STRING ( this_node, CaBuf); - NODE_WRITE_STRING ( this_node, certBuf); - NODE_WRITE_STRING ( this_node, privKeyBuf); - NODE_WRITE_NUM_T ( this_node, pjsip_ssl_method, method); - writeIntVector ( this_node, "ciphers", ciphers); - NODE_WRITE_BOOL ( this_node, verifyServer); - NODE_WRITE_BOOL ( this_node, verifyClient); - NODE_WRITE_BOOL ( this_node, requireClientCert); - NODE_WRITE_UNSIGNED( this_node, msecTimeout); - NODE_WRITE_NUM_T ( this_node, pj_qos_type, qosType); - writeQosParams ( this_node, qosParams); - NODE_WRITE_BOOL ( this_node, qosIgnoreError); - NODE_WRITE_OBJ ( this_node, sockOptParams); - NODE_WRITE_BOOL ( this_node, sockOptIgnoreError); - NODE_WRITE_NUM_T ( this_node, pj_ssl_cert_lookup_type, certLookupType); - NODE_WRITE_STRING ( this_node, certLookupKeyword); + NODE_WRITE_STRING(this_node, CaListFile); + NODE_WRITE_STRING(this_node, certFile); + NODE_WRITE_STRING(this_node, privKeyFile); + NODE_WRITE_STRING(this_node, password); + NODE_WRITE_STRING(this_node, CaBuf); + NODE_WRITE_STRING(this_node, certBuf); + NODE_WRITE_STRING(this_node, privKeyBuf); + NODE_WRITE_NUM_T(this_node, pjsip_ssl_method, method); + writeIntVector(this_node, "ciphers", ciphers); + NODE_WRITE_BOOL(this_node, verifyServer); + NODE_WRITE_BOOL(this_node, verifyClient); + NODE_WRITE_BOOL(this_node, requireClientCert); + NODE_WRITE_UNSIGNED(this_node, msecTimeout); + NODE_WRITE_NUM_T(this_node, pj_qos_type, qosType); + writeQosParams(this_node, qosParams); + NODE_WRITE_BOOL(this_node, qosIgnoreError); + NODE_WRITE_OBJ(this_node, sockOptParams); + NODE_WRITE_BOOL(this_node, sockOptIgnoreError); + NODE_WRITE_NUM_T(this_node, pj_ssl_cert_lookup_type, certLookupType); + NODE_WRITE_STRING(this_node, certLookupKeyword); } /////////////////////////////////////////////////////////////////////////////// -SockOpt::SockOpt() -{ - pj_bzero(this, sizeof(*this)); -} +SockOpt::SockOpt() { pj_bzero(this, sizeof(*this)); } SockOpt::SockOpt(int level, int optName, int optVal) { @@ -315,26 +327,25 @@ SockOpt::SockOpt(int level, int optName, int optVal) setOptValInt(optVal); } -void SockOpt::setOptValInt(int opt_val) +void +SockOpt::setOptValInt(int opt_val) { optVal = &optValInt; optLen = sizeof(int); optValInt = opt_val; } -SockOptParams::SockOptParams() -{ -} +SockOptParams::SockOptParams() {} -pj_sockopt_params SockOptParams::toPj() const +pj_sockopt_params +SockOptParams::toPj() const { pj_sockopt_params sop; unsigned i; pj_bzero(&sop, sizeof(sop)); - sop.cnt = (unsigned)this->sockOpts.size(); - if (sop.cnt > PJ_MAX_SOCKOPT_PARAMS) - sop.cnt = PJ_MAX_SOCKOPT_PARAMS; + sop.cnt = (unsigned) this->sockOpts.size(); + if (sop.cnt > PJ_MAX_SOCKOPT_PARAMS) sop.cnt = PJ_MAX_SOCKOPT_PARAMS; for (i = 0; i < sop.cnt; ++i) { sop.options[i].level = this->sockOpts[i].level; sop.options[i].optname = this->sockOpts[i].optName; @@ -345,7 +356,8 @@ pj_sockopt_params SockOptParams::toPj() const return sop; } -void SockOptParams::fromPj(const pj_sockopt_params &prm) +void +SockOptParams::fromPj(const pj_sockopt_params &prm) { unsigned i; @@ -354,14 +366,13 @@ void SockOptParams::fromPj(const pj_sockopt_params &prm) SockOpt so; so.level = prm.options[i].level; so.optName = prm.options[i].optname; - if (prm.options[i].optlen == sizeof(int)) { - so.setOptValInt(*((int *)prm.options[i].optval)); - } + if (prm.options[i].optlen == sizeof(int)) { so.setOptValInt(*((int *) prm.options[i].optval)); } this->sockOpts.push_back(so); } } -void SockOptParams::readObject(const ContainerNode &node) PJSUA2_THROW(Error) +void +SockOptParams::readObject(const ContainerNode &node) PJSUA2_THROW(Error) { ContainerNode array_node = node.readArray("sockOptParams"); sockOpts.resize(0); @@ -379,19 +390,17 @@ void SockOptParams::readObject(const ContainerNode &node) PJSUA2_THROW(Error) } } -void SockOptParams::writeObject(ContainerNode &node) const PJSUA2_THROW(Error) +void +SockOptParams::writeObject(ContainerNode &node) const PJSUA2_THROW(Error) { ContainerNode array_node = node.writeNewArray("sockOptParams"); - for (unsigned i=0; i 0? sockOpts[i].optLen : 0); + string so_val((char *) sockOpts[i].optVal, sockOpts[i].optLen > 0 ? sockOpts[i].optLen : 0); so_node.writeInt("level", sockOpts[i].level); so_node.writeInt("optName", sockOpts[i].optName); so_node.writeInt("optLen", sockOpts[i].optLen); - if (sockOpts[i].optLen == sizeof(int)) { - so_node.writeInt("optVal", sockOpts[i].optValInt); - } + if (sockOpts[i].optLen == sizeof(int)) { so_node.writeInt("optVal", sockOpts[i].optValInt); } } } @@ -404,74 +413,75 @@ TransportConfig::TransportConfig() : qosType(PJ_QOS_TYPE_BEST_EFFORT) this->fromPj(tc); } -void TransportConfig::fromPj(const pjsua_transport_config &prm) +void +TransportConfig::fromPj(const pjsua_transport_config &prm) { - this->port = prm.port; - this->portRange = prm.port_range; + this->port = prm.port; + this->portRange = prm.port_range; this->randomizePort = PJ2BOOL(prm.randomize_port); this->publicAddress = pj2Str(prm.public_addr); - this->boundAddress = pj2Str(prm.bound_addr); + this->boundAddress = pj2Str(prm.bound_addr); this->tlsConfig.fromPj(prm.tls_setting); - this->qosType = prm.qos_type; - this->qosParams = prm.qos_params; + this->qosType = prm.qos_type; + this->qosParams = prm.qos_params; this->sockOptParams.fromPj(prm.sockopt_params); } -pjsua_transport_config TransportConfig::toPj() const +pjsua_transport_config +TransportConfig::toPj() const { pjsua_transport_config tc; pjsua_transport_config_default(&tc); - tc.port = this->port; - tc.port_range = this->portRange; - tc.randomize_port = this->randomizePort; - tc.public_addr = str2Pj(this->publicAddress); - tc.bound_addr = str2Pj(this->boundAddress); - tc.tls_setting = this->tlsConfig.toPj(); - tc.qos_type = this->qosType; - tc.qos_params = this->qosParams; - tc.sockopt_params = this->sockOptParams.toPj(); + tc.port = this->port; + tc.port_range = this->portRange; + tc.randomize_port = this->randomizePort; + tc.public_addr = str2Pj(this->publicAddress); + tc.bound_addr = str2Pj(this->boundAddress); + tc.tls_setting = this->tlsConfig.toPj(); + tc.qos_type = this->qosType; + tc.qos_params = this->qosParams; + tc.sockopt_params = this->sockOptParams.toPj(); return tc; } -void TransportConfig::readObject(const ContainerNode &node) PJSUA2_THROW(Error) +void +TransportConfig::readObject(const ContainerNode &node) PJSUA2_THROW(Error) { ContainerNode this_node = node.readContainer("TransportConfig"); - NODE_READ_UNSIGNED ( this_node, port); - NODE_READ_UNSIGNED ( this_node, portRange); - NODE_READ_STRING ( this_node, publicAddress); - NODE_READ_STRING ( this_node, boundAddress); - NODE_READ_NUM_T ( this_node, pj_qos_type, qosType); - readQosParams ( this_node, qosParams); - NODE_READ_OBJ ( this_node, tlsConfig); - NODE_READ_OBJ ( this_node, sockOptParams); + NODE_READ_UNSIGNED(this_node, port); + NODE_READ_UNSIGNED(this_node, portRange); + NODE_READ_STRING(this_node, publicAddress); + NODE_READ_STRING(this_node, boundAddress); + NODE_READ_NUM_T(this_node, pj_qos_type, qosType); + readQosParams(this_node, qosParams); + NODE_READ_OBJ(this_node, tlsConfig); + NODE_READ_OBJ(this_node, sockOptParams); } -void TransportConfig::writeObject(ContainerNode &node) const - PJSUA2_THROW(Error) +void +TransportConfig::writeObject(ContainerNode &node) const PJSUA2_THROW(Error) { ContainerNode this_node = node.writeNewContainer("TransportConfig"); - NODE_WRITE_UNSIGNED ( this_node, port); - NODE_WRITE_UNSIGNED ( this_node, portRange); - NODE_WRITE_STRING ( this_node, publicAddress); - NODE_WRITE_STRING ( this_node, boundAddress); - NODE_WRITE_NUM_T ( this_node, pj_qos_type, qosType); - writeQosParams ( this_node, qosParams); - NODE_WRITE_OBJ ( this_node, tlsConfig); - NODE_WRITE_OBJ ( this_node, sockOptParams); + NODE_WRITE_UNSIGNED(this_node, port); + NODE_WRITE_UNSIGNED(this_node, portRange); + NODE_WRITE_STRING(this_node, publicAddress); + NODE_WRITE_STRING(this_node, boundAddress); + NODE_WRITE_NUM_T(this_node, pj_qos_type, qosType); + writeQosParams(this_node, qosParams); + NODE_WRITE_OBJ(this_node, tlsConfig); + NODE_WRITE_OBJ(this_node, sockOptParams); } /////////////////////////////////////////////////////////////////////////////// -TransportInfo::TransportInfo() -: id(), type(PJSIP_TRANSPORT_UNSPECIFIED), flags(), usageCount() -{ -} +TransportInfo::TransportInfo() : id(), type(PJSIP_TRANSPORT_UNSPECIFIED), flags(), usageCount() {} -void TransportInfo::fromPj(const pjsua_transport_info &tinfo) +void +TransportInfo::fromPj(const pjsua_transport_info &tinfo) { this->id = tinfo.id; this->type = tinfo.type; @@ -479,13 +489,11 @@ void TransportInfo::fromPj(const pjsua_transport_info &tinfo) this->info = pj2Str(tinfo.info); this->flags = tinfo.flag; - char straddr[PJ_INET6_ADDRSTRLEN+10]; + char straddr[PJ_INET6_ADDRSTRLEN + 10]; pj_sockaddr_print(&tinfo.local_addr, straddr, sizeof(straddr), 3); this->localAddress = straddr; - pj_ansi_snprintf(straddr, sizeof(straddr), "%.*s:%d", - (int)tinfo.local_name.host.slen, - tinfo.local_name.host.ptr, + pj_ansi_snprintf(straddr, sizeof(straddr), "%.*s:%d", (int) tinfo.local_name.host.slen, tinfo.local_name.host.ptr, tinfo.local_name.port); this->localName = straddr; this->usageCount = tinfo.usage_count; @@ -493,36 +501,36 @@ void TransportInfo::fromPj(const pjsua_transport_info &tinfo) /////////////////////////////////////////////////////////////////////////////// -SipRxData::SipRxData() -: pjRxData(NULL) -{ -} +SipRxData::SipRxData() : pjRxData(NULL) {} -void SipRxData::fromPj(pjsip_rx_data &rdata) +void +SipRxData::fromPj(pjsip_rx_data &rdata) { - char straddr[PJ_INET6_ADDRSTRLEN+10]; + char straddr[PJ_INET6_ADDRSTRLEN + 10]; - info = pjsip_rx_data_get_info(&rdata); - wholeMsg = string(rdata.msg_info.msg_buf, rdata.msg_info.len); + info = pjsip_rx_data_get_info(&rdata); + wholeMsg = string(rdata.msg_info.msg_buf, rdata.msg_info.len); pj_sockaddr_print(&rdata.pkt_info.src_addr, straddr, sizeof(straddr), 3); - srcAddress = straddr; - pjRxData = (void *)&rdata; + srcAddress = straddr; + pjRxData = (void *) &rdata; } /////////////////////////////////////////////////////////////////////////////// -void SipMediaType::fromPj(const pjsip_media_type &prm) +void +SipMediaType::fromPj(const pjsip_media_type &prm) { - type = pj2Str(prm.type); - subType = pj2Str(prm.subtype); + type = pj2Str(prm.type); + subType = pj2Str(prm.subtype); } -pjsip_media_type SipMediaType::toPj() const +pjsip_media_type +SipMediaType::toPj() const { pjsip_media_type pj_mt; pj_bzero(&pj_mt, sizeof(pj_mt)); - pj_mt.type = str2Pj(type); - pj_mt.subtype = str2Pj(subType); + pj_mt.type = str2Pj(type); + pj_mt.subtype = str2Pj(subType); return pj_mt; } @@ -537,11 +545,12 @@ SipHeader::SipHeader() pjsip_generic_string_hdr_init2(&pjHdr, &dummy, &dummy); } -void SipHeader::fromPj(const pjsip_hdr *hdr) PJSUA2_THROW(Error) +void +SipHeader::fromPj(const pjsip_hdr *hdr) PJSUA2_THROW(Error) { char *buf = NULL; int len = 0; - unsigned buf_size = 256>>1; + unsigned buf_size = 256 >> 1; /* Print header to a 256 bytes buffer first. * If buffer is not sufficient, try 512, 1024, soon @@ -549,18 +558,15 @@ void SipHeader::fromPj(const pjsip_hdr *hdr) PJSUA2_THROW(Error) */ do { buf_size <<= 1; - buf = (char*)malloc(buf_size); - if (!buf) - PJSUA2_RAISE_ERROR(PJ_ENOMEM); + buf = (char *) malloc(buf_size); + if (!buf) PJSUA2_RAISE_ERROR(PJ_ENOMEM); - len = pjsip_hdr_print_on((void*)hdr, buf, buf_size-1); - if (len < 0) - free(buf); + len = pjsip_hdr_print_on((void *) hdr, buf, buf_size - 1); + if (len < 0) free(buf); } while ((buf_size < PJSIP_MAX_PKT_LEN) && (len < 0)); - - if (len < 0) - PJSUA2_RAISE_ERROR(PJ_ETOOSMALL); + + if (len < 0) PJSUA2_RAISE_ERROR(PJ_ETOOSMALL); buf[len] = '\0'; @@ -572,10 +578,10 @@ void SipHeader::fromPj(const pjsip_hdr *hdr) PJSUA2_THROW(Error) // Trim white space after header name char *end_name = pos; - while (end_name>buf && pj_isspace(*(end_name-1))) --end_name; + while (end_name > buf && pj_isspace(*(end_name - 1))) --end_name; // Trim whitespaces after colon - char *start_val = pos+1; + char *start_val = pos + 1; while (*start_val && pj_isspace(*start_val)) ++start_val; hName = string(buf, end_name); @@ -583,9 +589,10 @@ void SipHeader::fromPj(const pjsip_hdr *hdr) PJSUA2_THROW(Error) free(buf); } -pjsip_generic_string_hdr &SipHeader::toPj() const +pjsip_generic_string_hdr & +SipHeader::toPj() const { - pj_str_t hname = str2Pj(hName); + pj_str_t hname = str2Pj(hName); pj_str_t hvalue = str2Pj(hValue); pjsip_generic_string_hdr_init2(&pjHdr, &hname, &hvalue); @@ -601,11 +608,11 @@ SipMultipartPart::SipMultipartPart() pj_list_init(&pjMpp.hdr); } -void SipMultipartPart::fromPj(const pjsip_multipart_part &prm) - PJSUA2_THROW(Error) +void +SipMultipartPart::fromPj(const pjsip_multipart_part &prm) PJSUA2_THROW(Error) { headers.clear(); - pjsip_hdr* pj_hdr = prm.hdr.next; + pjsip_hdr *pj_hdr = prm.hdr.next; while (pj_hdr != &prm.hdr) { SipHeader sh; sh.fromPj(pj_hdr); @@ -613,31 +620,31 @@ void SipMultipartPart::fromPj(const pjsip_multipart_part &prm) pj_hdr = pj_hdr->next; } - if (!prm.body) - PJSUA2_RAISE_ERROR(PJ_EINVAL); - + if (!prm.body) PJSUA2_RAISE_ERROR(PJ_EINVAL); + contentType.fromPj(prm.body->content_type); - body = string((char*)prm.body->data, prm.body->len); + body = string((char *) prm.body->data, prm.body->len); pj_list_init(&pjMpp.hdr); pjMpp.body = NULL; pj_bzero(&pjMsgBody, sizeof(pjMsgBody)); } -pjsip_multipart_part& SipMultipartPart::toPj() const +pjsip_multipart_part & +SipMultipartPart::toPj() const { pj_list_init(&pjMpp.hdr); for (unsigned i = 0; i < headers.size(); i++) { - pjsip_generic_string_hdr& pj_hdr = headers[i].toPj(); + pjsip_generic_string_hdr &pj_hdr = headers[i].toPj(); pj_list_push_back(&pjMpp.hdr, &pj_hdr); } pj_bzero(&pjMsgBody, sizeof(pjMsgBody)); - pjMsgBody.content_type = contentType.toPj(); - pjMsgBody.print_body = &pjsip_print_text_body; - pjMsgBody.clone_data = &pjsip_clone_text_data; - pjMsgBody.data = (void*)body.c_str(); - pjMsgBody.len = (unsigned)body.size(); + pjMsgBody.content_type = contentType.toPj(); + pjMsgBody.print_body = &pjsip_print_text_body; + pjMsgBody.clone_data = &pjsip_clone_text_data; + pjMsgBody.data = (void *) body.c_str(); + pjMsgBody.len = (unsigned) body.size(); pjMpp.body = &pjMsgBody; return pjMpp; @@ -645,27 +652,22 @@ pjsip_multipart_part& SipMultipartPart::toPj() const /////////////////////////////////////////////////////////////////////////////// -SipEvent::SipEvent() -: type(PJSIP_EVENT_UNKNOWN), pjEvent(NULL) -{ -} +SipEvent::SipEvent() : type(PJSIP_EVENT_UNKNOWN), pjEvent(NULL) {} -void SipEvent::fromPj(const pjsip_event &ev) +void +SipEvent::fromPj(const pjsip_event &ev) { type = ev.type; if (type == PJSIP_EVENT_TIMER) { body.timer.entry = ev.body.timer.entry; } else if (type == PJSIP_EVENT_TSX_STATE) { - body.tsxState.prevState = (pjsip_tsx_state_e) - ev.body.tsx_state.prev_state; + body.tsxState.prevState = (pjsip_tsx_state_e) ev.body.tsx_state.prev_state; body.tsxState.tsx.fromPj(*ev.body.tsx_state.tsx); body.tsxState.type = ev.body.tsx_state.type; if (body.tsxState.type == PJSIP_EVENT_TX_MSG) { - if (ev.body.tsx_state.src.tdata) - body.tsxState.src.tdata.fromPj(*ev.body.tsx_state.src.tdata); + if (ev.body.tsx_state.src.tdata) body.tsxState.src.tdata.fromPj(*ev.body.tsx_state.src.tdata); } else if (body.tsxState.type == PJSIP_EVENT_RX_MSG) { - if (ev.body.tsx_state.src.rdata) - body.tsxState.src.rdata.fromPj(*ev.body.tsx_state.src.rdata); + if (ev.body.tsx_state.src.rdata) body.tsxState.src.rdata.fromPj(*ev.body.tsx_state.src.rdata); } else if (body.tsxState.type == PJSIP_EVENT_TRANSPORT_ERROR) { body.tsxState.src.status = ev.body.tsx_state.src.status; } else if (body.tsxState.type == PJSIP_EVENT_TIMER) { @@ -674,86 +676,80 @@ void SipEvent::fromPj(const pjsip_event &ev) body.tsxState.src.data = ev.body.tsx_state.src.data; } } else if (type == PJSIP_EVENT_TX_MSG) { - if (ev.body.tx_msg.tdata) - body.txMsg.tdata.fromPj(*ev.body.tx_msg.tdata); + if (ev.body.tx_msg.tdata) body.txMsg.tdata.fromPj(*ev.body.tx_msg.tdata); } else if (type == PJSIP_EVENT_RX_MSG) { - if (ev.body.rx_msg.rdata) - body.rxMsg.rdata.fromPj(*ev.body.rx_msg.rdata); + if (ev.body.rx_msg.rdata) body.rxMsg.rdata.fromPj(*ev.body.rx_msg.rdata); } else if (type == PJSIP_EVENT_TRANSPORT_ERROR) { - if (ev.body.tx_error.tdata) - body.txError.tdata.fromPj(*ev.body.tx_error.tdata); - if (ev.body.tx_error.tsx) - body.txError.tsx.fromPj(*ev.body.tx_error.tsx); + if (ev.body.tx_error.tdata) body.txError.tdata.fromPj(*ev.body.tx_error.tdata); + if (ev.body.tx_error.tsx) body.txError.tsx.fromPj(*ev.body.tx_error.tsx); } else if (type == PJSIP_EVENT_USER) { body.user.user1 = ev.body.user.user1; body.user.user2 = ev.body.user.user2; body.user.user3 = ev.body.user.user3; body.user.user4 = ev.body.user.user4; } - pjEvent = (void *)&ev; + pjEvent = (void *) &ev; } -SipTxData::SipTxData() -: pjTxData(NULL) -{ -} +SipTxData::SipTxData() : pjTxData(NULL) {} -void SipTxData::fromPj(pjsip_tx_data &tdata) +void +SipTxData::fromPj(pjsip_tx_data &tdata) { - char straddr[PJ_INET6_ADDRSTRLEN+10]; - - info = pjsip_tx_data_get_info(&tdata); + char straddr[PJ_INET6_ADDRSTRLEN + 10]; + + info = pjsip_tx_data_get_info(&tdata); pjsip_tx_data_encode(&tdata); - wholeMsg = string(tdata.buf.start, tdata.buf.cur - tdata.buf.start); + wholeMsg = string(tdata.buf.start, tdata.buf.cur - tdata.buf.start); if (pj_sockaddr_has_addr(&tdata.tp_info.dst_addr)) { pj_sockaddr_print(&tdata.tp_info.dst_addr, straddr, sizeof(straddr), 3); - dstAddress = straddr; + dstAddress = straddr; } else { dstAddress = ""; } - pjTxData = (void *)&tdata; + pjTxData = (void *) &tdata; } SipTransaction::SipTransaction() -: role(PJSIP_ROLE_UAC), statusCode(PJSIP_SC_NULL), - state(PJSIP_TSX_STATE_NULL), pjTransaction(NULL) -{ -} + : role(PJSIP_ROLE_UAC), + statusCode(PJSIP_SC_NULL), + state(PJSIP_TSX_STATE_NULL), + pjTransaction(NULL) +{} -void SipTransaction::fromPj(pjsip_transaction &tsx) +void +SipTransaction::fromPj(pjsip_transaction &tsx) { - this->role = tsx.role; - this->method = pj2Str(tsx.method.name); - this->statusCode = tsx.status_code; - this->statusText = pj2Str(tsx.status_text); - this->state = tsx.state; + this->role = tsx.role; + this->method = pj2Str(tsx.method.name); + this->statusCode = tsx.status_code; + this->statusText = pj2Str(tsx.status_text); + this->state = tsx.state; if (tsx.last_tx) this->lastTx.fromPj(*tsx.last_tx); else this->lastTx.pjTxData = NULL; - this->pjTransaction = (void *)&tsx; + this->pjTransaction = (void *) &tsx; } -TsxStateEvent::TsxStateEvent() -: prevState(PJSIP_TSX_STATE_NULL), type(PJSIP_EVENT_UNKNOWN) +TsxStateEvent::TsxStateEvent() : prevState(PJSIP_TSX_STATE_NULL), type(PJSIP_EVENT_UNKNOWN) {} + +bool +SipTxOption::isEmpty() const { + return (targetUri == "" && localUri == "" && headers.size() == 0 && contentType == "" && msgBody == "" + && multipartContentType.type == "" && multipartContentType.subType == "" && multipartParts.size() == 0); } -bool SipTxOption::isEmpty() const -{ - return (targetUri == "" && localUri == "" && headers.size() == 0 && - contentType == "" && msgBody == "" && multipartContentType.type == "" && - multipartContentType.subType == "" && multipartParts.size() == 0); -} - -void SipTxOption::fromPj(const pjsua_msg_data &prm) PJSUA2_THROW(Error) +void +SipTxOption::fromPj(const pjsua_msg_data &prm) PJSUA2_THROW(Error) { targetUri = pj2Str(prm.target_uri); localUri = pj2Str(prm.local_uri); headers.clear(); - pjsip_hdr* pj_hdr = prm.hdr_list.next; + pjsip_hdr *pj_hdr = prm.hdr_list.next; while (pj_hdr != &prm.hdr_list) { SipHeader sh; sh.fromPj(pj_hdr); @@ -766,7 +762,7 @@ void SipTxOption::fromPj(const pjsua_msg_data &prm) PJSUA2_THROW(Error) multipartContentType.fromPj(prm.multipart_ctype); multipartParts.clear(); - pjsip_multipart_part* pj_mp = prm.multipart_parts.next; + pjsip_multipart_part *pj_mp = prm.multipart_parts.next; while (pj_mp != &prm.multipart_parts) { SipMultipartPart smp; smp.fromPj(*pj_mp); @@ -775,7 +771,8 @@ void SipTxOption::fromPj(const pjsua_msg_data &prm) PJSUA2_THROW(Error) } } -void SipTxOption::toPj(pjsua_msg_data &msg_data) const +void +SipTxOption::toPj(pjsua_msg_data &msg_data) const { unsigned i; @@ -787,7 +784,7 @@ void SipTxOption::toPj(pjsua_msg_data &msg_data) const pj_list_init(&msg_data.hdr_list); for (i = 0; i < headers.size(); i++) { - pjsip_generic_string_hdr& pj_hdr = headers[i].toPj(); + pjsip_generic_string_hdr &pj_hdr = headers[i].toPj(); pj_list_push_back(&msg_data.hdr_list, &pj_hdr); } @@ -797,19 +794,13 @@ void SipTxOption::toPj(pjsua_msg_data &msg_data) const pj_list_init(&msg_data.multipart_parts); for (i = 0; i < multipartParts.size(); i++) { - pjsip_multipart_part& pj_part = multipartParts[i].toPj(); + pjsip_multipart_part &pj_part = multipartParts[i].toPj(); pj_list_push_back(&msg_data.multipart_parts, &pj_part); } } ////////////////////////////////////////////////////////////////////////////// -SendInstantMessageParam::SendInstantMessageParam() -: contentType("text/plain"), content(""), userData(NULL) -{ -} +SendInstantMessageParam::SendInstantMessageParam() : contentType("text/plain"), content(""), userData(NULL) {} -SendTypingIndicationParam::SendTypingIndicationParam() -: isTyping(false) -{ -} +SendTypingIndicationParam::SendTypingIndicationParam() : isTyping(false) {}