[asterisk-commits] qwell: branch qwell/fun_with_transports r388213 - /team/qwell/fun_with_transp...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 9 13:26:50 CDT 2013


Author: qwell
Date: Thu May  9 13:26:48 2013
New Revision: 388213

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388213
Log:
Address a few comments.

Modified:
    team/qwell/fun_with_transports/res/res_sip_transport_websocket.c

Modified: team/qwell/fun_with_transports/res/res_sip_transport_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip_transport_websocket.c?view=diff&rev=388213&r1=388212&r2=388213
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip_transport_websocket.c (original)
+++ team/qwell/fun_with_transports/res/res_sip_transport_websocket.c Thu May  9 13:26:48 2013
@@ -70,11 +70,6 @@
 	return PJ_SUCCESS;
 }
 
-static pj_status_t ws_do_shutdown(pjsip_transport *transport)
-{
-	return PJ_SUCCESS;
-}
-
 /*!
  * \brief Destroy the pjsip transport.
  *
@@ -137,6 +132,7 @@
 
 	if (!(newtransport = PJ_POOL_ZALLOC_T(pool, struct ws_transport))) {
 		ast_log(LOG_ERROR, "Failed to allocate WebSocket transport.\n");
+		pjsip_endpt_release_pool(endpt, pool);
 		return -1;
 	}
 
@@ -166,7 +162,6 @@
 	newtransport->transport.endpt = endpt;
 	newtransport->transport.tpmgr = tpmgr;
 	newtransport->transport.send_msg = &ws_send_msg;
-	newtransport->transport.do_shutdown = &ws_do_shutdown;
 	newtransport->transport.destroy = &ws_destroy;
 
 	pjsip_transport_register(newtransport->transport.tpmgr, (pjsip_transport *)newtransport);
@@ -204,7 +199,7 @@
 
 	pj_gettimeofday(&rdata->pkt_info.timestamp);
 
-	pj_memcpy(rdata->pkt_info.packet, read_data->payload, read_data->payload_len);
+	pj_memcpy(rdata->pkt_info.packet, read_data->payload, sizeof(rdata->pkt_info.packet));
 	rdata->pkt_info.len = read_data->payload_len;
 	rdata->pkt_info.zero = 0;
 
@@ -227,6 +222,7 @@
 static void websocket_cb(struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers)
 {
 	struct ast_taskprocessor *serializer = NULL;
+	struct transport_create_data create_data;
 	struct ws_transport *transport = NULL;
 
 	if (ast_websocket_set_nonblock(session)) {
@@ -238,6 +234,16 @@
 		ast_websocket_unref(session);
 		return;
 	}
+
+	create_data.ws_session = session;
+
+	if (ast_sip_push_task_synchronous(serializer, transport_create, &create_data)) {
+		ast_log(LOG_ERROR, "Could not create WebSocket transport.\n");
+		ast_websocket_unref(session);
+		return;
+	}
+
+	transport = create_data.transport;
 
 	while (ast_wait_for_input(ast_websocket_fd(session), -1) > 0) {
 		struct transport_read_data read_data;
@@ -249,18 +255,6 @@
 		}
 
 		if (opcode == AST_WEBSOCKET_OPCODE_TEXT || opcode == AST_WEBSOCKET_OPCODE_BINARY) {
-			if (!transport) {
-				struct transport_create_data create_data;
-				create_data.ws_session = session;
-
-				if (ast_sip_push_task_synchronous(serializer, transport_create, &create_data)) {
-					ast_log(LOG_ERROR, "Could not create WebSocket transport.\n");
-					break;
-				}
-
-				transport = create_data.transport;
-			}
-
 			read_data.transport = transport;
 
 			ast_sip_push_task(serializer, transport_read, &read_data);
@@ -269,9 +263,7 @@
 		}
 	}
 
-	if (transport) {
-		ast_sip_push_task_synchronous(serializer, transport_shutdown, transport);
-	}
+	ast_sip_push_task_synchronous(serializer, transport_shutdown, transport);
 
 	ast_taskprocessor_unreference(serializer);
 	ast_websocket_unref(session);
@@ -314,10 +306,10 @@
 {
 	pjsip_contact_hdr *contact_hdr = NULL;
 
-	int type = rdata->tp_info.transport->key.type;
-
-	if (type != transport_type_ws && type != transport_type_wss) {
-		return 0;
+	long type = rdata->tp_info.transport->key.type;
+
+	if (type != (long)transport_type_ws && type != (long)transport_type_wss) {
+		return PJ_FALSE;
 	}
 
 	if ((contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL))) {
@@ -328,17 +320,22 @@
 
 		if ((ct = ast_sip_location_retrieve_contact_transport_by_uri(contact_uri))) {
 			RAII_VAR(struct ast_sip_contact_transport *, ct_copy, ast_sorcery_copy(ast_sip_get_sorcery(), ct), ao2_cleanup);
+			if (!ct_copy) {
+				return PJ_TRUE;
+			}
 			ct_copy->transport = rdata->tp_info.transport;
 			ast_sorcery_update(ast_sip_get_sorcery(), ct_copy);
 		} else {
-			ct = ast_sorcery_alloc(ast_sip_get_sorcery(), "contact_transport", NULL);
+			if (!(ct = ast_sorcery_alloc(ast_sip_get_sorcery(), "contact_transport", NULL))) {
+				return PJ_TRUE;
+			}
 			ast_string_field_set(ct, uri, contact_uri);
 			ct->transport = rdata->tp_info.transport;
 			ast_sorcery_create(ast_sip_get_sorcery(), ct);
 		}
 	}
 
-	return 0;
+	return PJ_FALSE;
 }
 
 static pjsip_module websocket_module = {




More information about the asterisk-commits mailing list