[asterisk-commits] file: branch file/pimp_my_publish r391853 - in /team/file/pimp_my_publish: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 14 13:07:36 CDT 2013


Author: file
Date: Fri Jun 14 13:07:34 2013
New Revision: 391853

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391853
Log:
Send responses statefully so that retransmissions don't get to res_sip_pubsub.

This means a serializer isn't needed! Yay!

Modified:
    team/file/pimp_my_publish/include/asterisk/res_sip_pubsub.h
    team/file/pimp_my_publish/res/res_sip_pubsub.c
    team/file/pimp_my_publish/res/res_sip_pubsub.exports.in

Modified: team/file/pimp_my_publish/include/asterisk/res_sip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_my_publish/include/asterisk/res_sip_pubsub.h?view=diff&rev=391853&r1=391852&r2=391853
==============================================================================
--- team/file/pimp_my_publish/include/asterisk/res_sip_pubsub.h (original)
+++ team/file/pimp_my_publish/include/asterisk/res_sip_pubsub.h Fri Jun 14 13:07:34 2013
@@ -114,7 +114,7 @@
 /*!
  * \brief Create a response to an inbound PUBLISH
  *
- * The created response can be sent using pjsip_endpt_send_response() or pjsip_endpt_send_response2()
+ * The created response must be sent using ast_sip_publication_send_response
  *
  * \param pub The publication
  * \param status code The status code to place in the response
@@ -123,6 +123,16 @@
  */
 int ast_sip_publication_create_response(struct ast_sip_publication *pub, int status_code, pjsip_rx_data *rdata,
 	pjsip_tx_data **tdata);
+
+/*!
+ * \brief Send a response for an inbound PUBLISH
+ *
+ * \param pub The publication
+ * \param rdata The request to which the response was made
+ * \param tdata The response to the request
+ */
+pj_status_t ast_sip_publication_send_response(struct ast_sip_publication *pub, pjsip_rx_data *rdata,
+	pjsip_tx_data *tdata);
 
 /*!
  * \brief Register a publish handler

Modified: team/file/pimp_my_publish/res/res_sip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_my_publish/res/res_sip_pubsub.c?view=diff&rev=391853&r1=391852&r2=391853
==============================================================================
--- team/file/pimp_my_publish/res/res_sip_pubsub.c (original)
+++ team/file/pimp_my_publish/res/res_sip_pubsub.c Fri Jun 14 13:07:34 2013
@@ -858,25 +858,40 @@
 int ast_sip_publication_create_response(struct ast_sip_publication *pub, int status_code, pjsip_rx_data *rdata,
 	pjsip_tx_data **tdata)
 {
-	RAII_VAR(char *, entity_tag, NULL, ast_free_ptr);
-	RAII_VAR(char *, expires, NULL, ast_free_ptr);
-
-	if (ast_asprintf(&entity_tag, "%d", pub->entity_tag) < 0) {
-		return -1;
-	}
-
-	if (ast_asprintf(&expires, "%d", pub->expires) < 0) {
-		return -1;
-	}
-
 	if (pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, status_code, NULL, tdata) != PJ_SUCCESS) {
 		return -1;
 	}
 
-	ast_sip_add_header(*tdata, "SIP-ETag", entity_tag);
-	ast_sip_add_header(*tdata, "Expires", expires);
+	if (PJSIP_IS_STATUS_IN_CLASS(status_code, 200)) {
+		RAII_VAR(char *, entity_tag, NULL, ast_free_ptr);
+		RAII_VAR(char *, expires, NULL, ast_free_ptr);
+
+		if ((ast_asprintf(&entity_tag, "%d", pub->entity_tag) < 0) ||
+			(ast_asprintf(&expires, "%d", pub->expires) < 0)) {
+			pjsip_tx_data_dec_ref(*tdata);
+			return -1;
+		}
+
+		ast_sip_add_header(*tdata, "SIP-ETag", entity_tag);
+		ast_sip_add_header(*tdata, "Expires", expires);
+	}
 
 	return 0;
+}
+
+pj_status_t ast_sip_publication_send_response(struct ast_sip_publication *pub, pjsip_rx_data *rdata,
+	pjsip_tx_data *tdata)
+{
+	pj_status_t status;
+	pjsip_transaction *tsx;
+
+	if ((status = pjsip_tsx_create_uas(&pubsub_module, rdata, &tsx)) != PJ_SUCCESS) {
+		return status;
+	}
+
+	pjsip_tsx_recv_msg(tsx, rdata);
+
+	return pjsip_tsx_send_msg(tsx, tdata);
 }
 
 static pj_bool_t pubsub_on_rx_request(pjsip_rx_data *rdata)

Modified: team/file/pimp_my_publish/res/res_sip_pubsub.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_my_publish/res/res_sip_pubsub.exports.in?view=diff&rev=391853&r1=391852&r2=391853
==============================================================================
--- team/file/pimp_my_publish/res/res_sip_pubsub.exports.in (original)
+++ team/file/pimp_my_publish/res/res_sip_pubsub.exports.in Fri Jun 14 13:07:34 2013
@@ -14,6 +14,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_create_publication;
 		LINKER_SYMBOL_PREFIXast_sip_publication_get_endpoint;
 		LINKER_SYMBOL_PREFIXast_sip_publication_create_response;
+		LINKER_SYMBOL_PREFIXast_sip_publication_send_response;
 		LINKER_SYMBOL_PREFIXast_sip_register_publish_handler;
 		LINKER_SYMBOL_PREFIXast_sip_unregister_publish_handler;
 		LINKER_SYMBOL_PREFIXast_sip_publication_add_datastore;




More information about the asterisk-commits mailing list