diff options
author | Benny Prijono <bennylp@teluu.com> | 2005-11-11 19:01:31 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2005-11-11 19:01:31 +0000 |
commit | 0b9e388f7f10dac01d5134ed6c1b24695810874e (patch) | |
tree | f01b4f05e8d074a8dba14a96b93803fd6797c105 /pjsip/include | |
parent | 0bc0f9112ac6319d7ce8662de86d6c076bd4b1e3 (diff) |
First clean compile of pjsip
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@43 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/include')
-rw-r--r-- | pjsip/include/pjsip/print_util.h | 99 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_auth.h | 5 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_auth_msg.h | 5 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_auth_parser.h | 7 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_config.h | 2 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_endpoint.h | 76 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_errno.h | 86 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_event.h | 241 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_misc.h | 58 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_module.h | 1 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_msg.h | 35 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_parser.h | 52 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_private.h | 11 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_resolve.h | 1 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_transaction.h | 175 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_transport.h | 55 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_types.h | 27 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_uri.h | 1 | ||||
-rw-r--r-- | pjsip/include/pjsip_core.h | 1 |
19 files changed, 724 insertions, 214 deletions
diff --git a/pjsip/include/pjsip/print_util.h b/pjsip/include/pjsip/print_util.h new file mode 100644 index 00000000..b23d45fc --- /dev/null +++ b/pjsip/include/pjsip/print_util.h @@ -0,0 +1,99 @@ +/* $Id$ + */ +#ifndef __PJSIP_PRINT_H__ +#define __PJSIP_PRINT_H__ + +#define copy_advance_check(buf,str) \ + do { \ + if ((str).slen+10 >= (endbuf-buf)) return -1; \ + pj_memcpy(buf, (str).ptr, (str).slen); \ + buf += (str).slen; \ + } while (0) + +/* +static char *imp_copy_advance_pair(char *buf, char *endbuf, const char *str1, int len1, const pj_str_t *str2) +{ + if (str2->slen) { + int printed = len1+str2->slen; + if (printed+10 >= (endbuf-buf)) return NULL; + pj_memcpy(buf,str1,len1); + pj_memcpy(buf+len1, str2->ptr, str2->slen); + return buf + printed; + } else + return buf; +} +*/ + +#define copy_advance_pair_check(buf,str1,len1,str2) \ + do { \ + if (str2.slen) { \ + printed = len1+str2.slen; \ + if (printed+10 >= (endbuf-buf)) return -1; \ + pj_memcpy(buf,str1,len1); \ + pj_memcpy(buf+len1, str2.ptr, str2.slen); \ + buf += printed; \ + } \ + } while (0) +/* +#define copy_advance_pair(buf,str1,len1,str2) \ + do { \ + buf = imp_copy_advance_pair(buf, endbuf, str1, len1, &str2); \ + if (buf == NULL) return -1; \ + } while (0) +*/ + +#define copy_advance_pair_quote_check(buf,str1,len1,str2,quotebegin,quoteend) \ + do { \ + if (str2.slen) { \ + printed = len1+str2.slen+2; \ + if (printed+10 >= (endbuf-buf)) return -1; \ + pj_memcpy(buf,str1,len1); \ + *(buf+len1)=quotebegin; \ + pj_memcpy(buf+len1+1, str2.ptr, str2.slen); \ + *(buf+printed-1) = quoteend; \ + buf += printed; \ + } \ + } while (0) + +#define copy_advance_no_check(buf,str) \ + pj_memcpy(buf, (str).ptr, (str).slen); \ + buf += (str).slen; + +#define copy_advance_pair_no_check(buf,str1,len1,str2) \ + if (str2.slen) { \ + pj_memcpy(buf,str1,len1); \ + pj_memcpy(buf+len1, str2.ptr, str2.slen); \ + buf += len1+str2.slen; \ + } + +#define copy_advance copy_advance_check +#define copy_advance_pair copy_advance_pair_check +#define copy_advance_pair_quote copy_advance_pair_quote_check + +#define copy_advance_pair_quote_cond(buf,str1,len1,str2,quotebegin,quoteend) \ + do { \ + if (str2.slen && *str2.ptr!=quotebegin) \ + copy_advance_pair_quote(buf,str1,len1,str2,quotebegin,quoteend); \ + else \ + copy_advance_pair(buf,str1,len1,str2); \ + } while (0) + +/* + * Internal type declarations. + */ +typedef void* (*pjsip_hdr_clone_fptr)(pj_pool_t *, const void*); +typedef int (*pjsip_hdr_print_fptr)(void *hdr, char *buf, pj_size_t len); + +extern const pj_str_t pjsip_hdr_names[]; + +PJ_INLINE(void) init_hdr(void *hptr, pjsip_hdr_e htype, void *vptr) +{ + pjsip_hdr *hdr = hptr; + hdr->type = htype; + hdr->name = hdr->sname = pjsip_hdr_names[htype]; + hdr->vptr = vptr; + pj_list_init(hdr); +} + +#endif /* __PJSIP_PRINT_H__ */ + diff --git a/pjsip/include/pjsip/sip_auth.h b/pjsip/include/pjsip/sip_auth.h index 3396b669..c34ca030 100644 --- a/pjsip/include/pjsip/sip_auth.h +++ b/pjsip/include/pjsip/sip_auth.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_AUTH_SIP_AUTH_H__ #define __PJSIP_AUTH_SIP_AUTH_H__ @@ -60,7 +59,7 @@ struct pjsip_cred_info */ typedef struct pjsip_cached_auth_hdr { - PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr) + PJ_DECL_LIST_MEMBER(struct pjsip_cached_auth_hdr); pjsip_method method; pjsip_authorization_hdr *hdr; @@ -80,7 +79,7 @@ typedef struct pjsip_cached_auth_hdr */ typedef struct pjsip_auth_session { - PJ_DECL_LIST_MEMBER(struct pjsip_auth_session) + PJ_DECL_LIST_MEMBER(struct pjsip_auth_session); pj_str_t realm; pj_bool_t is_proxy; diff --git a/pjsip/include/pjsip/sip_auth_msg.h b/pjsip/include/pjsip/sip_auth_msg.h index ce1ca1e7..8e68331d 100644 --- a/pjsip/include/pjsip/sip_auth_msg.h +++ b/pjsip/include/pjsip/sip_auth_msg.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_AUTH_SIP_AUTH_MSG_H__ #define __PJSIP_AUTH_SIP_AUTH_MSG_H__ @@ -68,7 +67,7 @@ typedef struct pjsip_pgp_credential pjsip_pgp_credential; */ struct pjsip_authorization_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_authorization_hdr); pj_str_t scheme; union { @@ -157,7 +156,7 @@ typedef struct pjsip_pgp_challenge pjsip_pgp_challenge; */ struct pjsip_www_authenticate_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_www_authenticate_hdr); pj_str_t scheme; union { diff --git a/pjsip/include/pjsip/sip_auth_parser.h b/pjsip/include/pjsip/sip_auth_parser.h index 7f280ecd..c1d4f231 100644 --- a/pjsip/include/pjsip/sip_auth_parser.h +++ b/pjsip/include/pjsip/sip_auth_parser.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_AUTH_SIP_AUTH_PARSER_H__ #define __PJSIP_AUTH_SIP_AUTH_PARSER_H__ @@ -23,9 +22,11 @@ PJ_BEGIN_DECL * Initialize and register authorization parser module. * This will register parser handler for various Authorization related headers * such as Authorization, WWW-Authenticate, Proxy-Authorizization, and - * Proxy-Authenticate headers. + * Proxy-Authenticate headers.
+ *
+ * @return PJ_SUCCESS or the appropriate status code. */ -PJ_DECL(void) pjsip_auth_init_parser(); +PJ_DECL(pj_status_t) pjsip_auth_init_parser(void); /** * DeInitialize authorization parser module. diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index a594d488..bba037cb 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_CONFIG_H__ #define __PJSIP_SIP_CONFIG_H__ @@ -133,7 +132,6 @@ #include <pj/config.h> -#include <pj/compat.h> #endif /* __PJSIP_SIP_CONFIG_H__ */ diff --git a/pjsip/include/pjsip/sip_endpoint.h b/pjsip/include/pjsip/sip_endpoint.h index d950657d..e67e2863 100644 --- a/pjsip/include/pjsip/sip_endpoint.h +++ b/pjsip/include/pjsip/sip_endpoint.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_ENDPOINT_H__ #define __PJSIP_SIP_ENDPOINT_H__ @@ -28,13 +27,15 @@ PJ_BEGIN_DECL * SIP Endpoint instance (pjsip_endpoint) can be viewed as the master/owner of * all SIP objects in an application. It performs the following roles: * - it manages the allocation/deallocation of memory pools for all objects. - * - it manages listeners and transports, and how they are used by transactions. + * - it manages listeners and transports, and how they are used by
+ * transactions. * - it owns transaction hash table. * - it receives incoming messages from transport layer and automatically * dispatches them to the correct transaction (or create a new one). * - it has a single instance of timer management (timer heap). * - it manages modules, which is the primary means of extending the library. - * - it provides single polling function for all objects and distributes events. + * - it provides single polling function for all objects and distributes
+ * events. * - it provides SIP policy such as which outbound proxy to use for all * outgoing SIP request messages. * - it automatically handles incoming requests which can not be handled by @@ -49,15 +50,22 @@ PJ_BEGIN_DECL /** * Create an instance of SIP endpoint from the specified pool factory. - * The pool factory reference then will be kept by the endpoint, so that future - * memory allocations by SIP components will be taken from the same pool factory. - * - * @param pf Pool factory that will be used for the lifetime of endpoint. - * - * @return the endpoint instance on success. + * The pool factory reference then will be kept by the endpoint, so that
+ * future memory allocations by SIP components will be taken from the same
+ * pool factory. + * + * @param pf Pool factory that will be used for the lifetime of
+ * endpoint.
+ * @param name Optional name to be specified for the endpoint.
+ * If this parameter is NULL, then the name will use
+ * local host name.
+ * @param endpt Pointer to receive endpoint instance. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(pjsip_endpoint*) pjsip_endpt_create(pj_pool_factory *pf); - +PJ_DECL(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf,
+ pjsip_endpoint **endpt); +
/** * Destroy endpoint instance. Application must make sure that all pending * transactions have been terminated properly, because this function does not @@ -66,6 +74,16 @@ PJ_DECL(pjsip_endpoint*) pjsip_endpt_create(pj_pool_factory *pf); * @param endpt The SIP endpoint to be destroyed. */ PJ_DECL(void) pjsip_endpt_destroy(pjsip_endpoint *endpt); +
+/**
+ * Get endpoint name.
+ *
+ * @param endpt The SIP endpoint instance.
+ *
+ * @return Endpoint name, as was registered during endpoint
+ * creation. The string is NULL terminated.
+ */
+PJ_DECL(const pj_str_t*) pjsip_endpt_name(const pjsip_endpoint *endpt);
/** * Poll for events. Application must call this function periodically to ensure @@ -153,10 +171,13 @@ PJ_DECL(void) pjsip_endpt_cancel_timer( pjsip_endpoint *endpt, * transaction to endpoint with #pjsip_endpt_register_tsx. * This function, like all other endpoint functions, is thread safe. * - * @param endpt The SIP endpoint. - * @return The new transaction, or NULL on failure. + * @param endpt The SIP endpoint.
+ * @param p_tsx Pointer to receive the transaction.
+ * + * @return PJ_SUCCESS or the appropriate error code. */ -PJ_DECL(pjsip_transaction*) pjsip_endpt_create_tsx(pjsip_endpoint *endpt); +PJ_DECL(pj_status_t) pjsip_endpt_create_tsx(pjsip_endpoint *endpt,
+ pjsip_transaction **p_tsx); /** * Register the transaction to the endpoint's transaction table. @@ -187,10 +208,13 @@ PJ_DECL(void) pjsip_endpt_destroy_tsx( pjsip_endpoint *endpt, * Create a new transmit data buffer. * This function, like all other endpoint functions, is thread safe. * - * @param endpt the endpoint. - * @return new transmit data. + * @param endpt The endpoint.
+ * @param p_tdata Pointer to receive transmit data buffer.
+ * + * @return PJ_SUCCESS or the appropriate error code. */ -PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_tdata( pjsip_endpoint *endpt ); +PJ_DECL(pj_status_t) pjsip_endpt_create_tdata( pjsip_endpoint *endpt,
+ pjsip_tx_data **p_tdata); /** * Asynchronously resolve a SIP target host or domain according to rule @@ -330,6 +354,24 @@ PJ_DECL(pj_status_t) pjsip_endpt_set_proxies( pjsip_endpoint *endpt, * @return List of "Route" header. */ PJ_DECL(const pjsip_route_hdr*) pjsip_endpt_get_routing( pjsip_endpoint *endpt ); +
+/**
+ * Log an error.
+ */
+PJ_DECL(void) pjsip_endpt_log_error( pjsip_endpoint *endpt,
+ const char *sender,
+ pj_status_t error_code,
+ const char *format,
+ ... );
+
+#define PJSIP_ENDPT_LOG_ERROR(expr) \
+ pjsip_endpt_log_error expr
+
+#define PJSIP_ENDPT_TRACE(tracing,expr) \
+ do { \
+ if ((tracing)) \
+ PJ_LOG(4,expr); \
+ } while (0)
/** * @} diff --git a/pjsip/include/pjsip/sip_errno.h b/pjsip/include/pjsip/sip_errno.h new file mode 100644 index 00000000..6e4a6f72 --- /dev/null +++ b/pjsip/include/pjsip/sip_errno.h @@ -0,0 +1,86 @@ +/* $Id$
+ */
+#ifndef __PJSIP_SIP_ERRNO_H__
+#define __PJSIP_SIP_ERRNO_H__
+
+#include <pj/errno.h>
+
+/**
+ * Start of error code relative to PJ_ERRNO_START_USER.
+ */
+#define PJSIP_ERRNO_START (PJ_ERRNO_START_USER+10000)
+
+/**
+ * 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)
+
+/**
+ * Get SIP status code from error value.
+ * If conversion to SIP status code is not available, a SIP status code
+ * 599 will be returned.
+ *
+ * @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(999)) ? \
+ status-PJSIP_ERRNO_FROM_SIP_STATUS(0) : 599)
+
+
+/**
+ * Start of PJSIP generated error code values.
+ */
+#define PJSIP_ERRNO_START_PJSIP (PJSIP_ERRNO_START + 10000)
+
+/**
+ * @hideinitializer
+ * Missing required header(s).
+ */
+#define PJSIP_EMISSINGHDR (PJSIP_ERRNO_START_PJSIP + 1)
+/**
+ * @hideinitializer
+ * Unsupported URL scheme.
+ */
+#define PJSIP_EINVALIDSCHEME (PJSIP_ERRNO_START_PJSIP + 2)
+/**
+ * @hideinitializer
+ * Transaction has just been destroyed.
+ */
+#define PJSIP_ETSXDESTROYED (PJSIP_ERRNO_START_PJSIP + 3)
+/**
+ * @hideinitializer
+ * Buffer overflow. See also PJSIP_EMSGTOOLONG.
+ */
+#define PJSIP_EOVERFLOW (PJSIP_ERRNO_START_PJSIP + 4)
+/**
+ * @hideinitializer
+ * Message not completely received.
+ */
+#define PJSIP_EPARTIALMSG (PJSIP_ERRNO_START_PJSIP + 5)
+/**
+ * @hideinitializer
+ * Message too long. See also PJSIP_EOVERFLOW.
+ */
+#define PJSIP_EMSGTOOLONG (PJSIP_ERRNO_START_PJSIP + 6)
+/**
+ * @hideinitializer
+ * Buffer is being sent, operation still pending.
+ */
+#define PJSIP_EPENDINGTX (PJSIP_ERRNO_START_PJSIP + 7)
+/**
+ * @hideinitializer
+ * Unsupported transport type.
+ */
+#define PJSIP_EUNSUPTRANSPORT (PJSIP_ERRNO_START_PJSIP + 8)
+/**
+ * @hideinitializer
+ * Invalid Via header in response (sent-by, etc).
+ */
+#define PJSIP_EINVALIDVIA (PJSIP_ERRNO_START_PJSIP + 9)
+
+
+#endif /* __PJSIP_SIP_ERRNO_H__ */
diff --git a/pjsip/include/pjsip/sip_event.h b/pjsip/include/pjsip/sip_event.h index ac7bc691..98ac3850 100644 --- a/pjsip/include/pjsip/sip_event.h +++ b/pjsip/include/pjsip/sip_event.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_EVENT_H__ #define __PJSIP_SIP_EVENT_H__ @@ -25,7 +24,7 @@ PJ_BEGIN_DECL typedef enum pjsip_event_id_e { /** Unidentified event. */ - PJSIP_EVENT_UNIDENTIFIED, + PJSIP_EVENT_UNKNOWN, /** Timer event, normally only used internally in transaction. */ PJSIP_EVENT_TIMER, @@ -40,10 +39,10 @@ typedef enum pjsip_event_id_e PJSIP_EVENT_TRANSPORT_ERROR, /** Transaction state changed event. */ - PJSIP_EVENT_TSX_STATE_CHANGED, + PJSIP_EVENT_TSX_STATE, /** 2xx response received event. */ - PJSIP_EVENT_RX_200_RESPONSE, + PJSIP_EVENT_RX_200_MSG, /** ACK request received event. */ PJSIP_EVENT_RX_ACK_MSG, @@ -55,7 +54,7 @@ typedef enum pjsip_event_id_e PJSIP_EVENT_USER, /** On before transmitting message. */ - PJSIP_EVENT_BEFORE_TX, + PJSIP_EVENT_PRE_TX_MSG, } pjsip_event_id_e; @@ -76,46 +75,208 @@ typedef enum pjsip_event_id_e struct pjsip_event { /** This is necessary so that we can put events as a list. */ - PJ_DECL_LIST_MEMBER(struct pjsip_event) + PJ_DECL_LIST_MEMBER(struct pjsip_event); /** The event type, can be any value of \b pjsip_event_id_e. - * @see pjsip_event_id_e */ pjsip_event_id_e type; - - /** This field determines what is the content of \b src (source data). - */ - pjsip_event_id_e src_type; - - /** Source data, which content is dependent on \b src_type. - * - if src_type==PJSIP_EVENT_RX_MSG, src.rdata is valid. - * - if src_type==PJSIP_EVENT_TX_MSG, src.tdata is valid. - * - if src_type==PJSIP_EVENT_TIMER, src.timer is valid. - */ - union - { - pjsip_rx_data *rdata; - pjsip_tx_data *tdata; - pj_timer_entry *timer; - void *data; - unsigned long udata; - } src; - - /** The object that generates this event. */ - union - { - pjsip_transaction *tsx; - void *ptr; - unsigned long udata; - } obj; - - /** Other data. */ - union - { - long long_data; - void * ptr_data; - } data; +
+ /*
+ * The event body.
+ * By convention, the first member of each struct in the union must be
+ * the pointer which is relevant to the event.
+ */
+ union
+ {
+ /** Timer event. */
+ struct
+ {
+ pj_timer_entry *entry; /**< The timer entry. */
+ } timer;
+
+ /** Transaction state has changed event. */
+ struct
+ {
+ union
+ {
+ pjsip_rx_data *rdata; /**< The incoming message. */
+ pjsip_tx_data *tdata; /**< The outgoing message. */
+ pj_timer_entry *timer; /**< The timer. */
+ pj_status_t status;/**< Transport error status. */
+ void *data; /**< Generic data. */
+ } src;
+ pjsip_transaction *tsx; /**< The transaction. */
+ pjsip_event_id_e type; /**< Type of event source:
+ * - PJSIP_EVENT_TX_MSG
+ * - PJSIP_EVENT_RX_MSG,
+ * - PJSIP_EVENT_TRANSPORT_ERROR
+ * - PJSIP_EVENT_TIMER
+ * - PJSIP_EVENT_USER
+ */
+ } tsx_state;
+
+ /** Message transmission event. */
+ struct
+ {
+ pjsip_tx_data *tdata; /**< The transmit data buffer. */
+ pjsip_transaction *tsx; /**< The transaction. */
+
+ } tx_msg;
+
+ /** Pre-transmission event. */
+ struct
+ {
+ pjsip_tx_data *tdata; /**< Msg to be transmitted. */
+ pjsip_transaction *tsx; /**< The transaction. */
+ int retcnt;/**< Retransmission count. */
+ } pre_tx_msg;
+
+ /** Transmission error event. */
+ struct
+ {
+ pjsip_tx_data *tdata; /**< The transmit data. */
+ pjsip_transaction *tsx; /**< The transaction. */
+ } tx_error;
+
+ /** Message arrival event. */
+ struct
+ {
+ pjsip_rx_data *rdata; /**< The receive data buffer. */
+ pjsip_transaction *tsx; /**< The transaction. */
+ } rx_msg;
+
+ /** Receipt of 200/INVITE response. */
+ struct
+ {
+ pjsip_rx_data *rdata; /**< The 200 response msg. */
+ } rx_200_msg;
+
+ /** Receipt of ACK message. */
+ struct
+ {
+ pjsip_rx_data *rdata; /**< The ack message. */
+ } rx_ack_msg;
+
+ /** Notification that endpoint has discarded a message. */
+ struct
+ {
+ pjsip_rx_data *rdata; /**< The discarded message. */
+ pj_status_t reason;/**< The reason. */
+ } discard_msg;
+
+ /** User event. */
+ struct
+ {
+ void *user1; /**< User data 1. */
+ void *user2; /**< User data 2. */
+ void *user3; /**< User data 3. */
+ void *user4; /**< User data 4. */
+ } user;
+
+ } body;
}; +
+/**
+ * Init timer event.
+ */
+#define PJSIP_EVENT_INIT_TIMER(event,pentry) \
+ do { \
+ (event).type = PJSIP_EVENT_TIMER; \
+ (event).body.timer.entry = pentry; \
+ } while (0)
+
+/**
+ * Init tsx state event.
+ */
+#define PJSIP_EVENT_INIT_TSX_STATE(event,ptsx,ptype,pdata) \
+ do { \
+ (event).type = PJSIP_EVENT_TSX_STATE; \
+ (event).body.tsx_state.tsx = ptsx; \
+ (event).body.tsx_state.type = ptype; \
+ (event).body.tsx_state.src.data = pdata; \
+ } while (0)
+
+/**
+ * Init tx msg event.
+ */
+#define PJSIP_EVENT_INIT_TX_MSG(event,ptsx,ptdata) \
+ do { \
+ (event).type = PJSIP_EVENT_TX_MSG; \
+ (event).body.tx_msg.tsx = ptsx; \
+ (event).body.tx_msg.tdata = ptdata; \
+ } while (0)
+
+/**
+ * Init rx msg event.
+ */
+#define PJSIP_EVENT_INIT_RX_MSG(event,ptsx,prdata) \
+ do { \
+ (event).type = PJSIP_EVENT_RX_MSG; \
+ (event).body.rx_msg.tsx = ptsx; \
+ (event).body.rx_msg.rdata = prdata; \
+ } while (0)
+
+/**
+ * Init transport error event.
+ */
+#define PJSIP_EVENT_INIT_TRANSPORT_ERROR(event,ptsx,ptdata) \
+ do { \
+ (event).type = PJSIP_EVENT_TRANSPORT_ERROR; \
+ (event).body.tx_error.tsx = ptsx; \
+ (event).body.tx_error.tdata = ptdata; \
+ } while (0)
+
+/**
+ * Init rx 200/INVITE event.
+ */
+#define PJSIP_EVENT_INIT_RX_200_MSG(event,prdata) \
+ do { \
+ (event).type = PJSIP_EVENT_RX_200_MSG; \
+ (event).body.rx_200_msg.rdata = prdata; \
+ } while (0)
+
+/**
+ * Init rx ack msg event.
+ */
+#define PJSIP_EVENT_INIT_RX_ACK_MSG(event,prdata) \
+ do { \
+ (event).type = PJSIP_EVENT_RX_ACK_MSG; \
+ (event).body.rx_ack_msg.rdata = prdata; \
+ } while (0)
+
+/**
+ * Init discard msg event.
+ */
+#define PJSIP_EVENT_INIT_DISCARD_MSG(event,prdata,preason) \
+ do { \
+ (event).type = PJSIP_EVENT_DISCARD_MSG; \
+ (event).body.discard_msg.rdata = prdata; \
+ (event).body.discard_msg.reason = preason; \
+ } while (0)
+
+/**
+ * Init user event.
+ */
+#define PJSIP_EVENT_INIT_USER(event,u1,u2,u3,u4) \
+ do { \
+ (event).type = PJSIP_EVENT_USER; \
+ (event).body.user.user1 = (void*)u1; \
+ (event).body.user.user2 = (void*)u2; \
+ (event).body.user.user3 = (void*)u3; \
+ (event).body.user.user4 = (void*)u4; \
+ } while (0)
+
+/**
+ * Init pre tx msg event.
+ */
+#define PJSIP_EVENT_INIT_PRE_TX_MSG(event,ptsx,ptdata,pretcnt) \
+ do { \
+ (event).type = PJSIP_EVENT_PRE_TX_MSG; \
+ (event).body.pre_tx_msg.tsx = ptsx; \
+ (event).body.pre_tx_msg.tdata = ptdata; \
+ (event).body.pre_tx_msg.retcnt = pretcnt; \
+ } while (0)
+
/** * Get the event string from the event ID. diff --git a/pjsip/include/pjsip/sip_misc.h b/pjsip/include/pjsip/sip_misc.h index be2ccca9..4101dbc1 100644 --- a/pjsip/include/pjsip/sip_misc.h +++ b/pjsip/include/pjsip/sip_misc.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_MISC_H__ #define __PJSIP_SIP_MISC_H__ @@ -29,19 +28,21 @@ PJ_BEGIN_DECL * @param contact URL to put in Contact header. * @param call_id Optional Call-ID (put NULL to generate unique Call-ID). * @param cseq Optional CSeq (put -1 to generate random CSeq). - * @param text Optional text body (put NULL to omit body). + * @param text Optional text body (put NULL to omit body).
+ * @param p_tdata Pointer to receive the transmit data. * - * @return The transmit data. + * @return PJ_SUCCESS, or the appropriate error code. */ -PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_request( pjsip_endpoint *endpt, - const pjsip_method *method, - const pj_str_t *target, - const pj_str_t *from, - const pj_str_t *to, - const pj_str_t *contact, - const pj_str_t *call_id, - int cseq, - const pj_str_t *text); +PJ_DECL(pj_status_t) pjsip_endpt_create_request( pjsip_endpoint *endpt, + const pjsip_method *method, + const pj_str_t *target, + const pj_str_t *from, + const pj_str_t *to, + const pj_str_t *contact, + const pj_str_t *call_id, + int cseq, + const pj_str_t *text,
+ pjsip_tx_data **p_tdata); /** * Create an independent request message from the specified headers. This @@ -57,11 +58,12 @@ PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_request( pjsip_endpoint *endpt, * @param contact URL to put in Contact header. * @param call_id Optional Call-ID (put NULL to generate unique Call-ID). * @param cseq Optional CSeq (put -1 to generate random CSeq). - * @param text Optional text body (put NULL to omit body). + * @param text Optional text body (put NULL to omit body).
+ * @param p_tdata Pointer to receive the transmit data. * - * @return The transmit data. + * @return PJ_SUCCESS, or the appropriate error code. */ -PJ_DECL(pjsip_tx_data*) +PJ_DECL(pj_status_t) pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, const pjsip_method *method, const pjsip_uri *target, @@ -70,7 +72,8 @@ pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, const pjsip_contact_hdr *contact, const pjsip_cid_hdr *call_id, int cseq, - const pj_str_t *text ); + const pj_str_t *text,
+ pjsip_tx_data **p_tdata); /** * Send outgoing request and initiate UAC transaction for the request. @@ -89,7 +92,7 @@ pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, * the previously registered token and the event that triggers * the completion of the transaction. * - * @return Zero if transaction is started successfully. + * @return PJ_SUCCESS, or the appropriate error code. */ PJ_DECL(pj_status_t) pjsip_endpt_send_request( pjsip_endpoint *endpt, pjsip_tx_data *tdata, @@ -106,13 +109,15 @@ PJ_DECL(pj_status_t) pjsip_endpt_send_request( pjsip_endpoint *endpt, * * @param endpt The endpoint. * @param rdata The request receive data. - * @param code Status code to be put in the response. + * @param code Status code to be put in the response.
+ * @param p_tdata Pointer to receive the transmit data. * - * @return Transmit data. + * @return PJ_SUCCESS, or the appropriate error code. */ -PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_response(pjsip_endpoint *endpt, - const pjsip_rx_data *rdata, - int code); +PJ_DECL(pj_status_t) pjsip_endpt_create_response( pjsip_endpoint *endpt, + const pjsip_rx_data *rdata, + int code,
+ pjsip_tx_data **p_tdata); /** * Construct a full ACK request for the received non-2xx final response. @@ -136,11 +141,13 @@ PJ_DECL(void) pjsip_endpt_create_ack( pjsip_endpoint *endpt, * * @param endpt The endpoint. * @param tdata The transmit buffer for the request being cancelled. + * @param p_tdata Pointer to receive the transmit data.
* - * @return Cancel request. + * @return PJ_SUCCESS, or the appropriate error code. */ -PJ_DECL(pjsip_tx_data*) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, - pjsip_tx_data *tdata ); +PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, + pjsip_tx_data *tdata,
+ pjsip_tx_data **p_tdata); /** @@ -159,7 +166,6 @@ PJ_DECL(pj_status_t) pjsip_get_response_addr(pj_pool_t *pool, const pjsip_via_hdr *via, pjsip_host_port *addr); - /** * @} */ diff --git a/pjsip/include/pjsip/sip_module.h b/pjsip/include/pjsip/sip_module.h index f380b967..7bf53ab4 100644 --- a/pjsip/include/pjsip/sip_module.h +++ b/pjsip/include/pjsip/sip_module.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_MODULE_H__ #define __PJSIP_SIP_MODULE_H__ diff --git a/pjsip/include/pjsip/sip_msg.h b/pjsip/include/pjsip/sip_msg.h index 76834c29..ed9450b1 100644 --- a/pjsip/include/pjsip/sip_msg.h +++ b/pjsip/include/pjsip/sip_msg.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_MSG_H__ #define __PJSIP_SIP_MSG_H__ @@ -260,7 +259,7 @@ typedef struct pjsip_hdr_vptr */ #define PJSIP_DECL_HDR_MEMBER(hdr) \ /** List members. */ \ - PJ_DECL_LIST_MEMBER(hdr) \ + PJ_DECL_LIST_MEMBER(hdr); \ /** Header type */ \ pjsip_hdr_e type; \ /** Header name. */ \ @@ -268,17 +267,17 @@ typedef struct pjsip_hdr_vptr /** Header short name version. */ \ pj_str_t sname; \ /** Virtual function table. */ \ - pjsip_hdr_vptr *vptr; + pjsip_hdr_vptr *vptr /** * Generic SIP header structure, for generic manipulation for headers in the * message. All header fields can be typecasted to this type. */ -typedef struct pjsip_hdr +struct pjsip_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr) -} pjsip_hdr; + PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr); +}; /** @@ -687,7 +686,7 @@ PJ_IDECL(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr ); * @return The length of the printed characters (in bytes), or NEGATIVE * value if the message is too large for the specified buffer. */ -PJ_DECL(int) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size); +PJ_DECL(pj_ssize_t) pjsip_msg_print(pjsip_msg *msg, char *buf, pj_size_t size); /** * @} @@ -707,7 +706,7 @@ PJ_DECL(int) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size); */ typedef struct pjsip_generic_string_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_string_hdr) /**< Standard header field. */ + PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_string_hdr); /**< Standard header field. */ pj_str_t hvalue; /**< hvalue */ } pjsip_generic_string_hdr; @@ -756,7 +755,7 @@ pjsip_generic_string_hdr_create_with_text( pj_pool_t *pool, */ typedef struct pjsip_generic_int_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_int_hdr) /**< Standard header field. */ + PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_int_hdr); /**< Standard header field. */ pj_int32_t ivalue; /**< ivalue */ } pjsip_generic_int_hdr; @@ -805,7 +804,7 @@ pjsip_generic_int_hdr_create_with_value( pj_pool_t *pool, typedef struct pjsip_generic_array_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr); unsigned count; /**< Number of elements. */ pj_str_t values[PJSIP_GENERIC_ARRAY_MAX_COUNT]; /**< Elements. */ } pjsip_generic_array_hdr; @@ -886,7 +885,7 @@ PJ_DECL(pjsip_allow_hdr*) pjsip_allow_hdr_create(pj_pool_t *pool); */ typedef struct pjsip_cid_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr); pj_str_t id; /**< Call-ID string. */ } pjsip_cid_hdr; @@ -917,7 +916,7 @@ PJ_DECL(pjsip_cid_hdr*) pjsip_cid_hdr_create( pj_pool_t *pool ); */ typedef struct pjsip_clen_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr); int len; /**< Content length. */ } pjsip_clen_hdr; @@ -945,7 +944,7 @@ PJ_DECL(pjsip_clen_hdr*) pjsip_clen_hdr_create( pj_pool_t *pool ); */ typedef struct pjsip_cseq_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr); int cseq; /**< CSeq number. */ pjsip_method method; /**< CSeq method. */ } pjsip_cseq_hdr; @@ -977,7 +976,7 @@ PJ_DECL(pjsip_cseq_hdr*) pjsip_cseq_hdr_create( pj_pool_t *pool ); */ typedef struct pjsip_contact_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr); int star; /**< The contact contains only a '*' character */ pjsip_uri *uri; /**< URI in the contact. */ int q1000; /**< The "q" value times 1000 (to avoid float) */ @@ -1010,7 +1009,7 @@ PJ_DECL(pjsip_contact_hdr*) pjsip_contact_hdr_create( pj_pool_t *pool ); */ typedef struct pjsip_ctype_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr); pjsip_media_type media; /**< Media type. */ } pjsip_ctype_hdr; @@ -1061,7 +1060,7 @@ PJ_DECL(pjsip_expires_hdr*) pjsip_expires_hdr_create( pj_pool_t *pool ); */ typedef struct pjsip_fromto_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr); pjsip_uri *uri; /**< URI in From/To header. */ pj_str_t tag; /**< Header "tag" parameter. */ pj_str_t other_param; /**< Other params, concatenated as a single string. */ @@ -1170,7 +1169,7 @@ PJ_DECL(pjsip_min_expires_hdr*) pjsip_min_expires_hdr_create(pj_pool_t *pool); */ typedef struct pjsip_routing_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr) /**< Generic header fields. */ + PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr); /**< Generic header fields. */ pjsip_name_addr name_addr; /**< The URL in the Route/Record-Route header. */ pj_str_t other_param; /** Other parameter. */ } pjsip_routing_hdr; @@ -1327,7 +1326,7 @@ PJ_DECL(pjsip_unsupported_hdr*) pjsip_unsupported_hdr_create(pj_pool_t *pool); */ typedef struct pjsip_via_hdr { - PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr) + PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr); pj_str_t transport; /**< Transport type. */ pjsip_host_port sent_by; /**< Host and optional port */ int ttl_param; /**< TTL parameter, or -1 if it's not specified. */ diff --git a/pjsip/include/pjsip/sip_parser.h b/pjsip/include/pjsip/sip_parser.h index 69e4aba7..5ae2f80f 100644 --- a/pjsip/include/pjsip/sip_parser.h +++ b/pjsip/include/pjsip/sip_parser.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_PARSER_H__ #define __PJSIP_SIP_PARSER_H__ @@ -10,7 +9,7 @@ */ #include <pjsip/sip_types.h> -#include <pj/scanner.h> +#include <pjlib-util/scanner.h> #include <pj/list.h> PJ_BEGIN_DECL @@ -51,13 +50,24 @@ enum */ typedef struct pjsip_parser_err_report { - PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report) + PJ_DECL_LIST_MEMBER(struct pjsip_parser_err_report); int exception_code; /**< Error exception (e.g. PJSIP_SYN_ERR_EXCEPTION) */ int line; /**< Line number. */ int col; /**< Column number. */ pj_str_t hname; /**< Header name, if any. */ } pjsip_parser_err_report; +
+/**
+ * Parsing context, the default argument for parsing functions.
+ */
+typedef struct pjsip_parse_ctx
+{
+ pj_scanner *scanner; /**< The scanner. */
+ pj_pool_t *pool; /**< The pool. */
+ pjsip_rx_data *rdata; /**< Optional rdata. */
+} pjsip_parse_ctx;
+
/** * Type of function to parse header. The parsing function must follow these @@ -76,7 +86,7 @@ typedef struct pjsip_parser_err_report * - for the last header, these separator is optional since parsing * can be terminated when seeing EOF. */ -typedef void* (pjsip_parse_hdr_func)(pj_scanner *scanner, pj_pool_t *pool); +typedef pjsip_hdr* (pjsip_parse_hdr_func)(pjsip_parse_ctx *context); /** * Type of function to parse URI scheme. @@ -94,8 +104,7 @@ typedef void* (pjsip_parse_uri_func)(pj_scanner *scanner, pj_pool_t *pool); * @param hshortname The short header name or NULL. * @param fptr The pointer to function to parser the header. * - * @return zero if success. - * @see pjsip_parse_hdr_func + * @return PJ_SUCCESS if success, or the appropriate error code. */ PJ_DECL(pj_status_t) pjsip_register_hdr_parser( const char *hname, const char *hshortname, @@ -183,6 +192,27 @@ PJ_DECL(pjsip_msg *) pjsip_parse_msg( pj_pool_t *pool, char *buf, pj_size_t size, pjsip_parser_err_report *err_list); +
+/**
+ * Parse a packet buffer and build a rdata. The resulting message will be
+ * stored in \c msg field in the \c rdata. This behaves pretty much like
+ * #pjsip_parse_msg(), except that it will also initialize the header fields
+ * in the \c rdata.
+ *
+ * This function is normally called by the transport layer.
+ *
+ * @param buf The input buffer
+ * @param buf The input buffer, which size must be at least (size+1)
+ * because the function will temporarily put NULL
+ * termination at the end of the buffer during parsing.
+ * @param size The length of the string (not counting NULL terminator).
+ * @param rdata The receive data buffer to store the message and
+ * its elements.
+ *
+ * @return The message inside the rdata if successfull, or NULL.
+ */
+PJ_DECL(pjsip_msg *) pjsip_parse_rdata( char *buf, pj_size_t size,
+ pjsip_rx_data *rdata );
/** * Check incoming packet to see if a (probably) valid SIP message has been @@ -193,10 +223,12 @@ PJ_DECL(pjsip_msg *) pjsip_parse_msg( pj_pool_t *pool, * @param msg_size [out] If message is valid, this parameter will contain * the size of the SIP message (including body, if any). * - * @return PJ_TRUE (1) if a message is found. + * @return PJ_SUCCESS if a message is found, or an error code. */ -PJ_DECL(pj_bool_t) pjsip_find_msg( const char *buf, pj_size_t size, - pj_bool_t is_datagram, pj_size_t *msg_size); +PJ_DECL(pj_status_t) pjsip_find_msg(const char *buf,
+ pj_size_t size, + pj_bool_t is_datagram,
+ pj_size_t *msg_size); /** * Parse the content of a header and return the header instance. @@ -247,7 +279,7 @@ PJ_DECL(pj_status_t) pjsip_parse_headers( pj_pool_t *pool, * parsers. */ extern -pj_char_spec pjsip_HOST_SPEC, /* For scanning host part. */ +pj_cis_t pjsip_HOST_SPEC, /* For scanning host part. */ pjsip_DIGIT_SPEC, /* Decimal digits */ pjsip_ALPHA_SPEC, /* Alpha (A-Z, a-z) */ pjsip_ALNUM_SPEC, /* Decimal + Alpha. */ diff --git a/pjsip/include/pjsip/sip_private.h b/pjsip/include/pjsip/sip_private.h index afcff08b..b2661350 100644 --- a/pjsip/include/pjsip/sip_private.h +++ b/pjsip/include/pjsip/sip_private.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_PRIVATE_H__ #define __PJSIP_SIP_PRIVATE_H__ @@ -26,16 +25,18 @@ PJ_BEGIN_DECL * @param endpt The endpoint * @param cb Callback to be called to receive messages from transport. */ -PJ_DECL(pjsip_transport_mgr*) pjsip_transport_mgr_create( pj_pool_t *pool, - pjsip_endpoint *endpt, - void (*cb)(pjsip_endpoint *,pjsip_rx_data *)); +PJ_DECL(pj_status_t) pjsip_transport_mgr_create( pj_pool_t *pool, + pjsip_endpoint *endpt, + void (*cb)(pjsip_endpoint *,
+ pjsip_rx_data *),
+ pjsip_transport_mgr **); /** * Destroy transport manager and release all transports. * @param mgr Transport manager to be destroyed. */ -PJ_DECL(void) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ); +PJ_DECL(pj_status_t) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr ); /** * Poll for transport events. diff --git a/pjsip/include/pjsip/sip_resolve.h b/pjsip/include/pjsip/sip_resolve.h index 4a47c135..5464db91 100644 --- a/pjsip/include/pjsip/sip_resolve.h +++ b/pjsip/include/pjsip/sip_resolve.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_RESOLVE_H__ #define __PJSIP_SIP_RESOLVE_H__ diff --git a/pjsip/include/pjsip/sip_transaction.h b/pjsip/include/pjsip/sip_transaction.h index 3ef6ad14..cdb11235 100644 --- a/pjsip/include/pjsip/sip_transaction.h +++ b/pjsip/include/pjsip/sip_transaction.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_TRANSACTION_H__ #define __PJSIP_SIP_TRANSACTION_H__ @@ -11,8 +10,6 @@ #include <pjsip/sip_msg.h> #include <pjsip/sip_resolve.h> -//#include <pjsip/sip_config.h> -//#include <pjsip/sip_endpoint.h> #include <pj/timer.h> PJ_BEGIN_DECL @@ -22,7 +19,8 @@ PJ_BEGIN_DECL * @ingroup PJSIP * @{ */ - +
+/* Forward decl. */ struct pjsip_transaction; @@ -60,68 +58,111 @@ typedef enum pjsip_tsx_transport_state_e * Transaction state. */ struct pjsip_transaction -{ - pj_pool_t *pool; - pjsip_endpoint *endpt; - char obj_name[PJ_MAX_OBJ_NAME]; - pjsip_role_e role; - int status_code; - pjsip_tsx_state_e state; - int (*state_handler)(struct pjsip_transaction *, pjsip_event *); - - pj_mutex_t *mutex; - pjsip_method method; - int cseq; - pj_str_t transaction_key; - pj_str_t branch; - - pjsip_tsx_transport_state_e transport_state; - pjsip_host_port dest_name; - int current_addr; - pjsip_server_addresses remote_addr; - pjsip_transport_t *transport; - - pjsip_tx_data *last_tx; - int has_unsent_msg; - int handle_ack; - int retransmit_count; - - pj_timer_entry retransmit_timer; - pj_timer_entry timeout_timer; +{
+ /*
+ * Administrivia
+ */
+ pj_pool_t *pool; /**< Pool owned by the tsx. */
+ pjsip_endpoint *endpt; /**< Endpoint instance. */
+ pj_mutex_t *mutex; /**< Mutex for this tsx. */
+ char obj_name[PJ_MAX_OBJ_NAME]; /**< Tsx name. */
+ int tracing; /**< Tracing enabled? */
+
+ /*
+ * Transaction identification.
+ */
+ pjsip_role_e role; /**< Role (UAS or UAC) */
+ pjsip_method method; /**< The method. */
+ int cseq; /**< The CSeq */
+ pj_str_t transaction_key;/**< hash table key. */
+ pj_str_t branch; /**< The branch Id. */
+
+ /*
+ * State and status.
+ */
+ int status_code; /**< Last status code seen. */
+ pjsip_tsx_state_e state; /**< State. */
+ int handle_ack; /**< Should we handle ACK? */
+
+ /** Handler according to current state. */
+ pj_status_t (*state_handler)(struct pjsip_transaction *, pjsip_event *); +
+ /*
+ * Transport.
+ */ + pjsip_tsx_transport_state_e transport_state;/**< Transport's state. */
+ pjsip_host_port dest_name; /**< Destination address. */
+ pjsip_server_addresses remote_addr; /**< Addresses resolved. */
+ int current_addr; /**< Address currently used. */
+
+ pjsip_transport_t *transport; /**< Transport to use. */ +
+ /*
+ * Messages and timer.
+ */
+ pjsip_tx_data *last_tx; /**< Msg kept for retrans. */
+ int has_unsent_msg; /**< Non-zero if tsx need to
+ transmit msg once resolver
+ completes. */
+ int retransmit_count;/**< Retransmission count. */ + pj_timer_entry retransmit_timer;/**< Retransmit timer. */
+ pj_timer_entry timeout_timer; /**< Timeout timer. */
+
+ /** Module specific data. */ void *module_data[PJSIP_MAX_MODULE]; }; /** - * Init transaction as UAC. - * @param tsx the transaction. - * @param tdata the transmit data. - * @return PJ_SUCCESS if successfull. + * Init transaction as UAC from the specified transmit data (\c tdata).
+ * The transmit data must have a valid \c Request-Line and \c CSeq header.
+ * If \c Route headers are present, it will be used to calculate remote
+ * destination.
+ *
+ * If \c Via header does not exist, it will be created along with a unique
+ * \c branch parameter. If it exists and contains branch parameter, then
+ * the \c branch parameter will be used as is as the transaction key.
+ *
+ * The \c Route headers in the transmit data, if present, are used to
+ * calculate remote destination.
+ *
+ * At the end of the function, the transaction will start resolving the
+ * addresses of remote server to contact. Transport will be acquired as soon
+ * as the resolving job completes.
+ * + * @param tsx The transaction. + * @param tdata The transmit data.
+ * + * @return PJ_SUCCESS if successfull. */ PJ_DECL(pj_status_t) pjsip_tsx_init_uac( pjsip_transaction *tsx, pjsip_tx_data *tdata); /** - * Init transaction as UAS. - * @param tsx the transaction to be initialized. - * @param rdata the received incoming request. + * Init transaction as UAS.
+ * + * @param tsx The transaction to be initialized. + * @param rdata The received incoming request.
+ * * @return PJ_SUCCESS if successfull. */ PJ_DECL(pj_status_t) pjsip_tsx_init_uas( pjsip_transaction *tsx, pjsip_rx_data *rdata); /** - * Process incoming message for this transaction. - * @param tsx the transaction. - * @param rdata the incoming message. + * Process incoming message for this transaction.
+ * + * @param tsx The transaction. + * @param rdata The incoming message. */ PJ_DECL(void) pjsip_tsx_on_rx_msg( pjsip_transaction *tsx, pjsip_rx_data *rdata); /** - * Transmit message with this transaction. - * @param tsx the transaction. - * @param tdata the outgoing message. + * Transmit message with this transaction.
+ * + * @param tsx The transaction. + * @param tdata The outgoing message. */ PJ_DECL(void) pjsip_tsx_on_tx_msg( pjsip_transaction *tsx, pjsip_tx_data *tdata); @@ -133,35 +174,41 @@ PJ_DECL(void) pjsip_tsx_on_tx_msg( pjsip_transaction *tsx, * This operation is only valid if the transaction is configured to handle ACK * (tsx->handle_ack is non-zero). If this attribute is not set, then the * transaction will comply with RFC-3261, i.e. it will set itself to - * TERMINATED state when it receives 2xx/INVITE. - * @param tsx The transaction. - * @param tdata The ACK request. + * TERMINATED state when it receives 2xx/INVITE.
+ * + * @param tsx The transaction. + * @param tdata The ACK request. */ PJ_DECL(void) pjsip_tsx_on_tx_ack( pjsip_transaction *tsx, pjsip_tx_data *tdata); /** - * Forcely terminate transaction. - * @param tsx the transaction. - * @param code the status code to report. + * Force terminate transaction.
+ * + * @param tsx The transaction. + * @param code The status code to report. */ PJ_DECL(void) pjsip_tsx_terminate( pjsip_transaction *tsx, int code ); /** * Create transaction key, which is used to match incoming requests - * or response (retransmissions) against transactions. - * @param pool The pool - * @param key Output key. - * @param role The role of the transaction. - * @param method The method to be put as a key. - * @param rdata The received data to calculate. - */ -PJ_DECL(void) pjsip_tsx_create_key( pj_pool_t *pool, - pj_str_t *key, - pjsip_role_e role, - const pjsip_method *method, - const pjsip_rx_data *rdata ); + * or response (retransmissions) against transactions.
+ * + * @param pool The pool + * @param key Output key. + * @param role The role of the transaction. + * @param method The method to be put as a key. + * @param rdata The received data to calculate.
+ *
+ * @return PJ_SUCCESS or the appropriate error code.
+ */ +PJ_DECL(pj_status_t) pjsip_tsx_create_key( pj_pool_t *pool, + pj_str_t *key, + pjsip_role_e role, + const pjsip_method *method, + const pjsip_rx_data *rdata ); +
/** * @} @@ -183,7 +230,7 @@ PJ_DECL(const char *) pjsip_role_name(pjsip_role_e role); /* Thread Local Storage ID for transaction lock (initialized by endpoint) */ -extern int pjsip_tsx_lock_tls_id; +extern long pjsip_tsx_lock_tls_id; PJ_END_DECL diff --git a/pjsip/include/pjsip/sip_transport.h b/pjsip/include/pjsip/sip_transport.h index 29b5d8d1..dd3baea9 100644 --- a/pjsip/include/pjsip/sip_transport.h +++ b/pjsip/include/pjsip/sip_transport.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_TRANSPORT_H__ #define __PJSIP_SIP_TRANSPORT_H__ @@ -13,6 +12,7 @@ #include <pjsip/sip_parser.h> #include <pj/sock.h> #include <pj/list.h> +#include <pj/ioqueue.h>
PJ_BEGIN_DECL @@ -36,10 +36,13 @@ PJ_BEGIN_DECL */ struct pjsip_rx_data { - PJ_DECL_LIST_MEMBER(struct pjsip_rx_data) + //PJ_DECL_LIST_MEMBER(struct pjsip_rx_data); /** Memory pool for this buffer. */ pj_pool_t *pool; +
+ /** Ioqueue op key. */
+ pj_ioqueue_op_key_t op_key;
/** Time when the message was received. */ pj_time_val timestamp; @@ -73,21 +76,33 @@ struct pjsip_rx_data /** The From header as found in the message. */ pjsip_from_hdr *from; - /** The tag in the From header as found in the message. */ - pj_str_t from_tag; - /** The To header as found in the message. */ pjsip_to_hdr *to; - /** The To tag header as found in the message. */ - pj_str_t to_tag; - /** The topmost Via header as found in the message. */ pjsip_via_hdr *via; /** The CSeq header as found in the message. */ pjsip_cseq_hdr *cseq; - +
+ /** Max forwards header. */
+ pjsip_max_forwards_hdr *max_fwd;
+
+ /** The first route header. */
+ pjsip_route_hdr *route;
+
+ /** The first record-route header. */
+ pjsip_rr_hdr *record_route;
+
+ /** Content-type header. */
+ pjsip_ctype_hdr *ctype;
+
+ /** Content-length header. */
+ pjsip_clen_hdr *clen;
+
+ /** The first Require header. */
+ pjsip_require_hdr *require;
+
/** The list of error generated by the parser when parsing this message. */ pjsip_parser_err_report parse_err; }; @@ -109,7 +124,7 @@ struct pjsip_rx_data */ struct pjsip_tx_data { - PJ_DECL_LIST_MEMBER(struct pjsip_tx_data) + PJ_DECL_LIST_MEMBER(struct pjsip_tx_data); /** Memory pool for this buffer. */ pj_pool_t *pool; @@ -126,6 +141,9 @@ struct pjsip_tx_data /** The transport manager for this buffer. */ pjsip_transport_mgr *mgr; +
+ /** Ioqueue asynchronous operation key. */
+ pj_ioqueue_op_key_t op_key;
/** The message in this buffer. */ pjsip_msg *msg; @@ -355,14 +373,16 @@ pjsip_transport_get_remote_addr( const pjsip_transport_t * tr ); * * @param tr The transport to send the message. * @param tdata The outgoing message buffer. - * @param addr The remote address. + * @param addr The remote address.
+ * @param sent If not null, it will be filled up with the length of
+ * data sent. * - * @return The number of bytes sent, or zero if the connection - * has closed, or -1 on error. + * @return PJ_SUCCESS on success, or the appropriate error code. */ -PJ_DECL(int) pjsip_transport_send_msg( pjsip_transport_t *tr, - pjsip_tx_data *tdata, - const pj_sockaddr_in *addr); +PJ_DECL(pj_status_t) pjsip_transport_send_msg( pjsip_transport_t *tr, + pjsip_tx_data *tdata, + const pj_sockaddr_in *addr,
+ pj_ssize_t *sent); /** @@ -386,7 +406,8 @@ PJ_DECL(int) pjsip_transport_send_msg( pjsip_transport_t *tr, * @param mgr The transport manager. * @return The transmit buffer data, or NULL on error. */ -pjsip_tx_data* pjsip_tx_data_create( pjsip_transport_mgr *mgr ); +pj_status_t pjsip_tx_data_create( pjsip_transport_mgr *mgr,
+ pjsip_tx_data **tdata ); /** diff --git a/pjsip/include/pjsip/sip_types.h b/pjsip/include/pjsip/sip_types.h index 33e8ca03..64f5f3ae 100644 --- a/pjsip/include/pjsip/sip_types.h +++ b/pjsip/include/pjsip/sip_types.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_TYPES_H__ #define __PJSIP_SIP_TYPES_H__ @@ -71,6 +70,11 @@ typedef struct pjsip_rx_data pjsip_rx_data; * Forward declaration for message (sip_msg.h). */ typedef struct pjsip_msg pjsip_msg; +
+/**
+ * Forward declaration for header field (sip_msg.h).
+ */
+typedef struct pjsip_hdr pjsip_hdr;
/** * Forward declaration for URI (sip_uri.h). @@ -132,7 +136,26 @@ typedef struct pjsip_host_port pj_str_t host; /**< Host part. */ int port; /**< Port number. */ } pjsip_host_port; - +
+
+/**
+ * Convert exception ID into pj_status_t status.
+ *
+ * @param exception_id Exception Id.
+ *
+ * @return Error code for the specified exception Id.
+ */
+PJ_DECL(pj_status_t) pjsip_exception_to_status(int exception_id);
+
+/**
+ * Return standard pj_status_t status from current exception.
+ */
+#define PJSIP_RETURN_EXCEPTION() pjsip_exception_to_status(PJ_GET_EXCEPTION())
+
+/**
+ * Attributes to inform that the function may throw exceptions.
+ */
+#define PJSIP_THROW_SPEC(list)
#endif /* __PJSIP_SIP_TYPES_H__ */ diff --git a/pjsip/include/pjsip/sip_uri.h b/pjsip/include/pjsip/sip_uri.h index c43bc3df..8d72d0ae 100644 --- a/pjsip/include/pjsip/sip_uri.h +++ b/pjsip/include/pjsip/sip_uri.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_SIP_URI_H__ #define __PJSIP_SIP_URI_H__ diff --git a/pjsip/include/pjsip_core.h b/pjsip/include/pjsip_core.h index acce9cc6..96b39488 100644 --- a/pjsip/include/pjsip_core.h +++ b/pjsip/include/pjsip_core.h @@ -1,5 +1,4 @@ /* $Id$ - * */ #ifndef __PJSIP_CORE_H__ #define __PJSIP_CORE_H__ |