[asterisk-commits] mmichelson: branch group/pimp_my_sip r380247 - in /team/group/pimp_my_sip/res...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 28 10:51:32 CST 2013


Author: mmichelson
Date: Mon Jan 28 10:51:28 2013
New Revision: 380247

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380247
Log:
Backport PJSIP trunk function to clone pjsip_rx_data.

This function is going to be necessary for us to use a threadpool the way we wish.
The function will be present in PJSIP version 2.0.5 and is already in PJSIP trunk.
For now, we are backporting the function where we need it. Whenever PJSIP 2.0.5 is
released, we will  not need to maintain this backport any further.


Modified:
    team/group/pimp_my_sip/res/pjproject/pjsip/include/pjsip/sip_transport.h
    team/group/pimp_my_sip/res/pjproject/pjsip/src/pjsip/sip_transport.c

Modified: team/group/pimp_my_sip/res/pjproject/pjsip/include/pjsip/sip_transport.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/pjproject/pjsip/include/pjsip/sip_transport.h?view=diff&rev=380247&r1=380246&r2=380247
==============================================================================
--- team/group/pimp_my_sip/res/pjproject/pjsip/include/pjsip/sip_transport.h (original)
+++ team/group/pimp_my_sip/res/pjproject/pjsip/include/pjsip/sip_transport.h Mon Jan 28 10:51:28 2013
@@ -426,6 +426,42 @@
  * @return	    Printable information.
  */
 PJ_DECL(char*) pjsip_rx_data_get_info(pjsip_rx_data *rdata);
+
+/** 
+ * Clone pjsip_rx_data. This will duplicate the contents of 
+ * pjsip_rx_data and add reference count to the transport. 
+ * Once application has finished using the cloned pjsip_rx_data, 
+ * it must release it by calling  #pjsip_rx_data_free_cloned(). 
+ * 
+ * By default (if flags is set to zero), this function copies the 
+ * transport pointer in \a tp_info, duplicates the \a pkt_info, 
+ * perform deep clone of the \a msg_info parts of the rdata, and 
+ * fills the \a endpt_info (i.e. the \a mod_data) with zeros. 
+ * 
+ * @param src       The source to be cloned. 
+ * @param flags     Optional flags. Must be zero for now. 
+ * @param p_rdata   Pointer to receive the cloned rdata. 
+ * 
+ * @return          PJ_SUCCESS on success or the appropriate error. 
+ */ 
+PJ_DECL(pj_status_t) pjsip_rx_data_clone(const pjsip_rx_data *src, 
+                                         unsigned flags, 
+                                         pjsip_rx_data **p_rdata); 
+ 
+/** 
+ * Free cloned pjsip_rx_data. This function must be and must only 
+ * be called for a cloned pjsip_rx_data. Specifically, it must NOT 
+ * be called for the original pjsip_rx_data that is returned by 
+ * transports. 
+ * 
+ * This function will free the memory used by the pjsip_rx_data and 
+ * decrement the transport reference counter. 
+ * 
+ * @param rdata     The receive data buffer. 
+ * 
+ * @return          PJ_SUCCESS on success or the appropriate error. 
+ */ 
+PJ_DECL(pj_status_t) pjsip_rx_data_free_cloned(pjsip_rx_data *rdata);
 
 
 /*****************************************************************************

Modified: team/group/pimp_my_sip/res/pjproject/pjsip/src/pjsip/sip_transport.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/pjproject/pjsip/src/pjsip/sip_transport.c?view=diff&rev=380247&r1=380246&r2=380247
==============================================================================
--- team/group/pimp_my_sip/res/pjproject/pjsip/src/pjsip/sip_transport.c (original)
+++ team/group/pimp_my_sip/res/pjproject/pjsip/src/pjsip/sip_transport.c Mon Jan 28 10:51:28 2013
@@ -594,6 +594,89 @@
     return rdata->msg_info.info;
 }
 
+/* Clone pjsip_rx_data. */
+PJ_DEF(pj_status_t) pjsip_rx_data_clone( const pjsip_rx_data *src,
+                                         unsigned flags,
+                                         pjsip_rx_data **p_rdata)
+{
+    pj_pool_t *pool;
+    pjsip_rx_data *dst;
+    pjsip_hdr *hdr;
+
+    PJ_ASSERT_RETURN(src && flags==0 && p_rdata, PJ_EINVAL);
+
+    pool = pj_pool_create(src->tp_info.pool->factory,
+                          "rtd%p",
+                          PJSIP_POOL_RDATA_LEN,
+                          PJSIP_POOL_RDATA_INC,
+                          NULL);
+    if (!pool)
+        return PJ_ENOMEM;
+
+    dst = PJ_POOL_ZALLOC_T(pool, pjsip_rx_data);
+
+    /* Parts of tp_info */
+    dst->tp_info.pool = pool;
+    dst->tp_info.transport = (pjsip_transport*)src->tp_info.transport;
+
+    /* pkt_info can be memcopied */
+    pj_memcpy(&dst->pkt_info, &src->pkt_info, sizeof(src->pkt_info));
+
+    /* msg_info needs deep clone */
+    dst->msg_info.msg_buf = dst->pkt_info.packet;
+    dst->msg_info.len = src->msg_info.len;
+    dst->msg_info.msg = pjsip_msg_clone(pool, src->msg_info.msg);
+    pj_list_init(&dst->msg_info.parse_err);
+
+#define GET_MSG_HDR2(TYPE, type, var)   \
+                        case PJSIP_H_##TYPE: \
+                            if (!dst->msg_info.var) { \
+                                dst->msg_info.var = (pjsip_##type##_hdr*)hdr; \
+                            } \
+                            break
+#define GET_MSG_HDR(TYPE, var_type)     GET_MSG_HDR2(TYPE, var_type, var_type)
+
+    hdr = dst->msg_info.msg->hdr.next;
+    while (hdr != &dst->msg_info.msg->hdr) {
+        switch (hdr->type) {
+        GET_MSG_HDR(CALL_ID, cid);
+        GET_MSG_HDR(FROM, from);
+        GET_MSG_HDR(TO, to);
+        GET_MSG_HDR(VIA, via);
+        GET_MSG_HDR(CSEQ, cseq);
+        GET_MSG_HDR(MAX_FORWARDS, max_fwd);
+        GET_MSG_HDR(ROUTE, route);
+        GET_MSG_HDR2(RECORD_ROUTE, rr, record_route);
+        GET_MSG_HDR(CONTENT_TYPE, ctype);
+        GET_MSG_HDR(CONTENT_LENGTH, clen);
+        GET_MSG_HDR(REQUIRE, require);
+        GET_MSG_HDR(SUPPORTED, supported);
+        default:
+            break;
+        }
+        hdr = hdr->next;
+    }
+
+#undef GET_MSG_HDR
+#undef GET_MSG_HDR2
+
+    *p_rdata = dst;
+
+    /* Finally add transport ref */
+    return pjsip_transport_add_ref(dst->tp_info.transport);
+}
+
+/* Free previously cloned pjsip_rx_data. */
+PJ_DEF(pj_status_t) pjsip_rx_data_free_cloned(pjsip_rx_data *rdata)
+{
+    PJ_ASSERT_RETURN(rdata, PJ_EINVAL);
+
+    pjsip_transport_dec_ref(rdata->tp_info.transport);
+    pj_pool_release(rdata->tp_info.pool);
+
+    return PJ_SUCCESS;
+}
+
 /*****************************************************************************
  *
  * TRANSPORT KEY




More information about the asterisk-commits mailing list