[asterisk-commits] may: branch may/smpp r401311 - /team/may/smpp/branches/10/addons/res_smpp.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 21 11:50:59 CDT 2013


Author: may
Date: Mon Oct 21 11:50:57 2013
New Revision: 401311

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=401311
Log:
add tlv support with numerical ids

Modified:
    team/may/smpp/branches/10/addons/res_smpp.c

Modified: team/may/smpp/branches/10/addons/res_smpp.c
URL: http://svnview.digium.com/svn/asterisk/team/may/smpp/branches/10/addons/res_smpp.c?view=diff&rev=401311&r1=401310&r2=401311
==============================================================================
--- team/may/smpp/branches/10/addons/res_smpp.c (original)
+++ team/may/smpp/branches/10/addons/res_smpp.c Mon Oct 21 11:50:57 2013
@@ -271,6 +271,8 @@
 		struct ast_msg *msg = ast_msg_alloc();
 		char body[1024];
 		char tmp[1024];
+		char tmp2[256];
+		tlv_t *tlv;
 		int res;
 		deliver_sm_resp_t sm_resp;
 
@@ -305,8 +307,33 @@
 		ast_msg_set_var(msg, "smpp_type", "MO");
 
 		ast_msg_set_var(msg, "smpp_source", smsc->name);
+// parse tlv
+
+#define GET_TLVS(msg, deliver, tlv, tmp, tmp2) \
+		int tlvnum = 0; \
+		tlv = deliver->tlv; \
+		while (tlv) { \
+			tlvnum++; \
+			snprintf(tmp2, sizeof(tmp2), "tlv.%d.tag",  tlvnum); \
+			snprintf(tmp, sizeof(tmp), "%d" , tlv->tag); \
+			ast_msg_set_var(msg, tmp2, tmp); \
+			snprintf(tmp2, sizeof(tmp2), "tlv.%d.length",  tlvnum); \
+			snprintf(tmp, sizeof(tmp), "%d" , tlv->length); \
+			ast_msg_set_var(msg, tmp2, tmp); \
+			snprintf(tmp2, sizeof(tmp2), "tlv.%d.value",  tlvnum); \
+			ast_base64encode(tmp, (void *)&tlv->value, tlv->length, sizeof(tmp)); \
+			ast_msg_set_var(msg, tmp2, tmp); \
+			tlv = tlv->next; \
+		} \
+		snprintf(tmp, sizeof(tmp), "%d",  tlvnum); \
+		ast_msg_set_var(msg, "tlvs", tmp);
+
+		GET_TLVS(msg, deliver, tlv, tmp, tmp2);
 
 		res = ast_msg_queue(msg);
+		if (tlv) {
+			destroy_tlv(tlv);
+		}
 
 		memset(&sm_resp, 0, sizeof(sm_resp));
 		sm_resp.command_length = 0;
@@ -321,8 +348,10 @@
 		struct ast_msg *msg = ast_msg_alloc();
 		char body[1024];
 		char tmp[1024];
+		char tmp2[256];
 		char messageid[66];
 		int res;
+		tlv_t *tlv;
 		submit_sm_resp_t sm_resp;
 
 		if (!msg) {
@@ -347,7 +376,13 @@
 
 		ast_msg_set_var(msg, "smpp_source", smsc->name);
 
+		GET_TLVS(msg, submit, tlv, tmp, tmp2);
+
 		res = ast_msg_queue(msg);
+		if (tlv) {
+			destroy_tlv(tlv);
+		}
+
 
 		memset(&sm_resp, 0, sizeof(sm_resp));
 		sm_resp.command_length = 0;
@@ -1180,9 +1215,10 @@
 	uint32_t sequence_number;
 
 	void *unpack;
-
-	const char *var, *val;
-	struct ast_msg_var_iterator *iter;
+	tlv_t *tlv = NULL;
+
+	// const char *var, *val;
+	// struct ast_msg_var_iterator *iter;
 
 	message = (struct ast_msg *)msg;
 	body = ast_msg_get_body(msg);
@@ -1221,13 +1257,14 @@
 
 // get message custom variables
 
-	for (iter = ast_msg_var_iterator_init(msg); ast_msg_var_iterator_next(msg, iter, &var, &val); 
-									ast_msg_var_unref_current(iter)) {
-	}
-	ast_msg_var_iterator_destroy(iter);
+	// for (iter = ast_msg_var_iterator_init(msg); ast_msg_var_iterator_next(msg, iter, &var, &val); 
+	//								ast_msg_var_unref_current(iter)) {
+	// }
+	// ast_msg_var_iterator_destroy(iter);
 
 	if (!smsc->esme) {
 		submit_sm_t submit;
+
 		memset(&submit, 0, sizeof(submit));
 		submit.command_length = 0;
 		submit.command_id = SUBMIT_SM;
@@ -1248,6 +1285,31 @@
 								sizeof(submit.short_message) - 1); \
 		}
 
+
+#define PUT_TLVS(submit, message, tlv, tmp) \
+		int tlvnum = atoi(ast_msg_get_var(message, "tlvs")); \
+		while (tlvnum) { \
+			tlv = ast_calloc(1, sizeof(tlv_t)); \
+			snprintf(tmp, sizeof(tmp), "tlv.%d.tag", tlvnum); \
+			if (ast_msg_get_var(message, tmp)) { \
+				tlv->tag = atoi(ast_msg_get_var(message, tmp)); \
+			} \
+			snprintf(tmp, sizeof(tmp), "tlv.%d.length", tlvnum); \
+			if (ast_msg_get_var(message, tmp)) { \
+				tlv->length = atoi(ast_msg_get_var(message, tmp)); \
+			} \
+			snprintf(tmp, sizeof(tmp), "tlv.%d.value", tlvnum); \
+			if (tlv->tag && tlv->length &&  ast_msg_get_var(message, tmp) && \
+				 ast_base64decode((unsigned char *)&tlv->value, \
+					ast_msg_get_var(message, tmp), sizeof(tlv->value))) { \
+				build_tlv(&submit.tlv, tlv); \
+			} else { \
+				free(tlv); \
+			} \
+			tlvnum--; \
+		} \
+		tlv = submit.tlv; \
+
 		submit.source_addr_ton = 0;
 		submit.source_addr_npi = 0;
 		submit.dest_addr_ton = 0;
@@ -1276,6 +1338,9 @@
 		if (!submit.sm_length) {
 			submit.sm_length = strlen((char *)submit.short_message);
 		}
+
+		PUT_TLVS(submit, message, tlv, tmp);
+
 		unpack = &submit;
 	} else {
 		deliver_sm_t deliver;
@@ -1313,6 +1378,9 @@
 		if (!deliver.sm_length) {
 			deliver.sm_length = strlen((char *)deliver.short_message);
 		}
+
+		PUT_TLVS(deliver, message, tlv, tmp);
+
 		unpack = &deliver;
 	}
 
@@ -1339,7 +1407,14 @@
 		ast_mutex_destroy(&resp->lock);
 		free(resp);
 		ast_mutex_unlock(&smsc->lock);
+		if (tlv) {
+			destroy_tlv(tlv);
+		}
 		return -1;
+	}
+
+	if (tlv) {
+		destroy_tlv(tlv);
 	}
 
 	if (smppDebug) {




More information about the asterisk-commits mailing list