summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2010-03-10 13:33:25 +0000
committerBenny Prijono <bennylp@teluu.com>2010-03-10 13:33:25 +0000
commit8e703ff217b32a9cc4d29393769ac85688900fbf (patch)
treed857fa788375d164e87eb7bc578dd9d8b09d606f
parent44c2febe5e74bb190b1d68dd506e1ce48714bc97 (diff)
More #1032 (new SIP TCP/TLS transport callback):
- PJSUA-LIB transport callback, if installed, will call the previously registered callback, to allow multiple transport callbacks to be installed - there seem to be a bug with the use of "pjsip_tp_state_callback" everywhere (the "pjsip_tp_state_callback" type is pointer, but most variables of this type are declared to pointer too) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3119 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip-apps/src/pjsua/pjsua_app.c4
-rw-r--r--pjsip/include/pjsip/sip_transport.h4
-rw-r--r--pjsip/include/pjsua-lib/pjsua_internal.h1
-rw-r--r--pjsip/src/pjsip/sip_transport.c6
-rw-r--r--pjsip/src/pjsip/sip_transport_tcp.c7
-rw-r--r--pjsip/src/pjsip/sip_transport_tls.c6
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c25
7 files changed, 37 insertions, 16 deletions
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c
index 083453a2..b312b3a3 100644
--- a/pjsip-apps/src/pjsua/pjsua_app.c
+++ b/pjsip-apps/src/pjsua/pjsua_app.c
@@ -2804,7 +2804,7 @@ static void on_transport_state(pjsip_transport *tp,
switch (state) {
case PJSIP_TP_STATE_CONNECTED:
{
- PJ_LOG(3,(THIS_FILE, "SIP transport %s is connected to %s",
+ PJ_LOG(3,(THIS_FILE, "SIP %s transport is connected to %s",
tp->type_name, host_port));
}
break;
@@ -2813,7 +2813,7 @@ static void on_transport_state(pjsip_transport *tp,
{
char buf[100];
- snprintf(buf, sizeof(buf), "SIP transport %s is disconnected from %s",
+ snprintf(buf, sizeof(buf), "SIP %s transport is disconnected from %s",
tp->type_name, host_port);
pjsua_perror(THIS_FILE, buf, info->status);
}
diff --git a/pjsip/include/pjsip/sip_transport.h b/pjsip/include/pjsip/sip_transport.h
index 8da4d561..92c624fe 100644
--- a/pjsip/include/pjsip/sip_transport.h
+++ b/pjsip/include/pjsip/sip_transport.h
@@ -1312,7 +1312,7 @@ typedef void (*pjsip_tp_state_callback)(
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pjsip_tpmgr_set_status_cb(pjsip_tpmgr *mgr,
- pjsip_tp_state_callback *cb);
+ pjsip_tp_state_callback cb);
/**
@@ -1322,7 +1322,7 @@ PJ_DECL(pj_status_t) pjsip_tpmgr_set_status_cb(pjsip_tpmgr *mgr,
*
* @return The transport state callback or NULL if it is not set.
*/
-PJ_DECL(pjsip_tp_state_callback*) pjsip_tpmgr_get_status_cb(
+PJ_DECL(pjsip_tp_state_callback) pjsip_tpmgr_get_status_cb(
const pjsip_tpmgr *mgr);
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h
index caba46aa..527b53ae 100644
--- a/pjsip/include/pjsua-lib/pjsua_internal.h
+++ b/pjsip/include/pjsua-lib/pjsua_internal.h
@@ -252,6 +252,7 @@ struct pjsua_data
pjsip_endpoint *endpt; /**< Global endpoint. */
pjsip_module mod; /**< pjsua's PJSIP module. */
pjsua_transport_data tpdata[8]; /**< Array of transports. */
+ pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
/* Threading: */
pj_bool_t thread_quit_flag; /**< Thread quit flag. */
diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index ecfba2c9..6041fdb7 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -89,7 +89,7 @@ struct pjsip_tpmgr
#endif
void (*on_rx_msg)(pjsip_endpoint*, pj_status_t, pjsip_rx_data*);
pj_status_t (*on_tx_msg)(pjsip_endpoint*, pjsip_tx_data*);
- pjsip_tp_state_callback *tp_state_cb;
+ pjsip_tp_state_callback tp_state_cb;
void *tp_state_user_data;
};
@@ -1738,7 +1738,7 @@ PJ_DEF(void) pjsip_tpmgr_dump_transports(pjsip_tpmgr *mgr)
}
PJ_DEF(pj_status_t) pjsip_tpmgr_set_status_cb(pjsip_tpmgr *mgr,
- pjsip_tp_state_callback *cb)
+ pjsip_tp_state_callback cb)
{
PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
@@ -1747,7 +1747,7 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_set_status_cb(pjsip_tpmgr *mgr,
return PJ_SUCCESS;
}
-PJ_DEF(pjsip_tp_state_callback*) pjsip_tpmgr_get_status_cb(
+PJ_DEF(pjsip_tp_state_callback) pjsip_tpmgr_get_status_cb(
const pjsip_tpmgr *mgr)
{
PJ_ASSERT_RETURN(mgr, NULL);
diff --git a/pjsip/src/pjsip/sip_transport_tcp.c b/pjsip/src/pjsip/sip_transport_tcp.c
index b5e826c0..d8f74a9d 100644
--- a/pjsip/src/pjsip/sip_transport_tcp.c
+++ b/pjsip/src/pjsip/sip_transport_tcp.c
@@ -169,7 +169,7 @@ static void sockaddr_to_host_port( pj_pool_t *pool,
static void tcp_init_shutdown(struct tcp_transport *tcp, pj_status_t status)
{
- pjsip_tp_state_callback *state_cb;
+ pjsip_tp_state_callback state_cb;
if (tcp->close_reason == PJ_SUCCESS)
tcp->close_reason = status;
@@ -952,7 +952,7 @@ static pj_bool_t on_accept_complete(pj_activesock_t *asock,
struct tcp_listener *listener;
struct tcp_transport *tcp;
char addr[PJ_INET6_ADDRSTRLEN+10];
- pjsip_tp_state_callback *state_cb;
+ pjsip_tp_state_callback state_cb;
pj_status_t status;
PJ_UNUSED_ARG(src_addr_len);
@@ -1262,8 +1262,7 @@ static pj_bool_t on_connect_complete(pj_activesock_t *asock,
struct tcp_transport *tcp;
pj_sockaddr_in addr;
int addrlen;
-
- pjsip_tp_state_callback *state_cb;
+ pjsip_tp_state_callback state_cb;
tcp = (struct tcp_transport*) pj_activesock_get_user_data(asock);
diff --git a/pjsip/src/pjsip/sip_transport_tls.c b/pjsip/src/pjsip/sip_transport_tls.c
index 0d4ef882..1fd5c7bd 100644
--- a/pjsip/src/pjsip/sip_transport_tls.c
+++ b/pjsip/src/pjsip/sip_transport_tls.c
@@ -176,7 +176,7 @@ static void sockaddr_to_host_port( pj_pool_t *pool,
static void tls_init_shutdown(struct tls_transport *tls, pj_status_t status)
{
- pjsip_tp_state_callback *state_cb;
+ pjsip_tp_state_callback state_cb;
if (tls->close_reason == PJ_SUCCESS)
tls->close_reason = status;
@@ -977,7 +977,7 @@ static pj_bool_t on_accept_complete(pj_ssl_sock_t *ssock,
struct tls_transport *tls;
pj_ssl_sock_info ssl_info;
char addr[PJ_INET6_ADDRSTRLEN+10];
- pjsip_tp_state_callback *state_cb;
+ pjsip_tp_state_callback state_cb;
pj_bool_t is_shutdown;
pj_status_t status;
@@ -1337,7 +1337,7 @@ static pj_bool_t on_connect_complete(pj_ssl_sock_t *ssock,
struct tls_transport *tls;
pj_ssl_sock_info ssl_info;
pj_sockaddr_in addr, *tp_addr;
- pjsip_tp_state_callback *state_cb;
+ pjsip_tp_state_callback state_cb;
pj_bool_t is_shutdown;
tls = (struct tls_transport*) pj_ssl_sock_get_user_data(ssock);
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 8870b87e..41eda871 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1525,6 +1525,19 @@ static const char *addr_string(const pj_sockaddr_t *addr)
return str;
}
+/* Callback to receive transport state notifications */
+static void on_tp_state_callback(pjsip_transport *tp,
+ pjsip_transport_state state,
+ const pjsip_transport_state_info *info)
+{
+ if (pjsua_var.ua_cfg.cb.on_transport_state) {
+ (*pjsua_var.ua_cfg.cb.on_transport_state)(tp, state, info);
+ }
+ if (pjsua_var.old_tp_cb) {
+ (*pjsua_var.old_tp_cb)(tp, state, info);
+ }
+}
+
/*
* Create and initialize SIP socket (and possibly resolve public
* address via STUN, depending on config).
@@ -1866,8 +1879,16 @@ PJ_DEF(pj_status_t) pjsua_transport_create( pjsip_transport_type_e type,
/* Set transport state callback */
if (pjsua_var.ua_cfg.cb.on_transport_state) {
- pjsip_tpmgr_set_status_cb(pjsip_endpt_get_tpmgr(pjsua_var.endpt),
- &pjsua_var.ua_cfg.cb.on_transport_state);
+ pjsip_tp_state_callback tpcb;
+ pjsip_tpmgr *tpmgr;
+
+ tpmgr = pjsip_endpt_get_tpmgr(pjsua_var.endpt);
+ tpcb = pjsip_tpmgr_get_status_cb(tpmgr);
+
+ if (tpcb != &on_tp_state_callback) {
+ pjsua_var.old_tp_cb = tpcb;
+ pjsip_tpmgr_set_status_cb(tpmgr, &on_tp_state_callback);
+ }
}
/* Return the ID */