[svn-commits] may: branch may/smpp r411580 - in /team/may/smpp/trunk: ./ addons/ addons/smpp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Mar 31 13:21:36 CDT 2014


Author: may
Date: Mon Mar 31 13:21:30 2014
New Revision: 411580

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411580
Log:
add smpp_recode function to transcode smpp data from/to utf8
add gsm.c/.h helper files for that from android sources
........

Merged revisions 411579 from http://svn.asterisk.org/svn/asterisk/team/may/smpp/branches/10

Added:
    team/may/smpp/trunk/addons/smpp/
      - copied from r411579, team/may/smpp/branches/10/addons/smpp/
Modified:
    team/may/smpp/trunk/   (props changed)
    team/may/smpp/trunk/addons/Makefile
    team/may/smpp/trunk/addons/res_smpp.c

Propchange: team/may/smpp/trunk/
------------------------------------------------------------------------------
--- smpp-10-merge (original)
+++ smpp-10-merge Mon Mar 31 13:21:30 2014
@@ -1,1 +1,1 @@
-/team/may/smpp/branches/10:1-410963
+/team/may/smpp/branches/10:1-411579

Propchange: team/may/smpp/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Mar 31 13:21:30 2014
@@ -1,1 +1,1 @@
-/team/may/smpp/branches/10:400905-401373,401882,402222,403011,404526,404528-404529,410963
+/team/may/smpp/branches/10:400905-401373,401882,402222,403011,404526,404528-404529,410963,411579

Modified: team/may/smpp/trunk/addons/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/may/smpp/trunk/addons/Makefile?view=diff&rev=411580&r1=411579&r2=411580
==============================================================================
--- team/may/smpp/trunk/addons/Makefile (original)
+++ team/may/smpp/trunk/addons/Makefile Mon Mar 31 13:21:30 2014
@@ -25,6 +25,8 @@
 	h323/MULTIMEDIA-SYSTEM-CONTROLDec.o h323/MULTIMEDIA-SYSTEM-CONTROLEnc.o
 
 H323CFLAGS:=-Iooh323c/src -Iooh323c/src/h323
+
+GSMOBJS:=gsm.o
 
 ALL_C_MODS:=app_mysql \
             app_saycountpl \
@@ -66,11 +68,13 @@
 $(if $(filter format_mp3,$(EMBEDDED_MODS)),modules.link,format_mp3.so): mp3/common.o mp3/dct64_i386.o mp3/decode_ntom.o mp3/layer3.o mp3/tabinit.o mp3/interface.o
 
 chan_ooh323.o: _ASTCFLAGS+=$(H323CFLAGS)
-res_smpp.o: _ASTCFLAGS+=-I/usr/local/include
-res_smpp.so: LIBS+=-L/usr/local/lib -lsmpp34
+res_smpp.o: _ASTCFLAGS+=-I.
+res_smpp.so: LIBS+=-lsmpp34
 
 $(if $(filter chan_ooh323,$(EMBEDDED_MODS)),modules.link,chan_ooh323.so): _ASTCFLAGS+=$(H323CFLAGS)
 $(if $(filter chan_ooh323,$(EMBEDDED_MODS)),modules.link,chan_ooh323.so): $(addprefix ooh323c/src/,$(H323OBJS)) chan_ooh323.o ooh323cDriver.o
 $(addprefix ooh323c/src/,$(H323OBJS)) chan_ooh323.o ooh323cDriver.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_ooh323)
+$(if $(filter res_smpp,$(EMBEDDED_MODS)),modules.link,res_smpp.so): $(addprefix smpp/,$(GSMOBJS)) res_smpp.o
+$(addprefix smpp/,$(GSMOBJS)) res_smpp.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_smpp)
 
 .PHONY: check_mp3

Modified: team/may/smpp/trunk/addons/res_smpp.c
URL: http://svnview.digium.com/svn/asterisk/team/may/smpp/trunk/addons/res_smpp.c?view=diff&rev=411580&r1=411579&r2=411580
==============================================================================
--- team/may/smpp/trunk/addons/res_smpp.c (original)
+++ team/may/smpp/trunk/addons/res_smpp.c Mon Mar 31 13:21:30 2014
@@ -55,12 +55,36 @@
 #include "asterisk/causes.h"
 #include "asterisk/message.h"
 
+/***	DOCUMENTATION
+	<function name="smpp_recode" language="en_US">
+		<synopsis>
+			transcode message base64 content from/to UTF-8
+		</synopsis>
+		<syntax>
+			<parameter name="direction" required="true">
+				<para>from or to UTF8</para>
+			</parameter>
+			<parameter name="smpp encdoning" required="true">
+				<para>ucs-2 or gsm8</para>
+			</parameter>
+			<parameter name="string" required="true">
+				<para>input string</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Returns the transcoded string in base64.</para>
+		</description>
+
+	</function>
+***/
+
 
 #define	MODULE_DESCRIPTION	"SMPP messaging resource module"
 
 #include "smpp34.h"
 #include "smpp34_structs.h"
 #include "smpp34_params.h"
+#include "smpp/gsm.h"
 
 #define	TRUE	1
 #define	FALSE	0
@@ -162,9 +186,10 @@
 		snprintf(tmp2, tmp2len, "tlv.%d.tag",  tlvnum);
 		tmp[0] = 0;
 		for (k = 0; tlvs[k].tlvid; k++) {
+			char *space;
 			if (tlvs[k].tlvid == tlv->tag) {
 				strcpy(tmp, tlvs[k].tlv);
-				char *space = strchr(tmp, ' ');
+				space = strchr(tmp, ' ');
 				if (space) {
 					*space = 0;
 				}
@@ -1664,6 +1689,7 @@
 
 static char *handle_cli_smpp_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+	 struct smpp_smsc* smsc;
 #define FORMAT "%24s %18s %9s %9s %12s %12s\n"
 #define FORMAT2 "%24s %18s %9s %9s %12s %12d\n"
 	switch (cmd) {
@@ -1683,7 +1709,7 @@
 	ast_cli(a->fd, FORMAT, "Peer Name", "IP addr", "IP Port", "SMPP type", "Connected", "Sequence");
 
 	ast_mutex_lock(&smpp_lock);
-	struct smpp_smsc* smsc = smsc_list;
+	smsc = smsc_list;
 	while (smsc) {
 		char *host = smsc->host;
 		char port[9];
@@ -1708,6 +1734,97 @@
 #undef FORMAT2
 }
 
+
+static int smpp_recode(struct ast_channel *chan, const char *cmd, char *arguments, char *buf, size_t len)
+{
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(direction);
+		AST_APP_ARG(smpp_charset);
+		AST_APP_ARG(text);
+	);
+
+	int incount = 0, outcount = 0;
+	char *parse;
+	char *text = NULL;
+	unsigned char *tmpin, *tmp;
+	char esm_class[1024] = "";
+	int offset = 0;
+
+	
+
+
+	if (ast_strlen_zero(arguments)) {
+		ast_log(LOG_WARNING, "Syntax: SMPP_RECODE(<from/to>,<CHARSET>,<text>) - missing arguments!\n");
+		return -1;
+	}
+
+	parse = ast_strdupa(arguments);
+	AST_STANDARD_APP_ARGS(args, parse);
+	if (args.argc < 3) {
+		ast_log(LOG_WARNING, "Syntax: SMPP_RECODE(<from/to>,<CHARSET>,<text>) - missing arguments!\n");
+		return -1;
+	}
+
+	text = args.text;
+	if (!(tmpin = ast_alloca(strlen(text)))) {
+		ast_log(LOG_ERROR, "can't allocate buffer memory\n");
+		return -1;
+	}
+	if (!(tmp = ast_alloca(strlen(text)*2))) {
+		ast_log(LOG_ERROR, "can't allocate buffer memory\n");
+		return -1;
+	}
+        incount = ast_base64decode(tmpin, text, sizeof(tmpin)-1);
+
+//	check UDH header on message data
+
+	if (ast_func_read(chan, "MESSAGE_DATA(esm_class)", esm_class, sizeof(esm_class)) != -1) {
+		if (atoi(esm_class) & 0x40) {
+			offset = tmpin[0] + 1;
+			if (offset >= incount) {
+				offset = 0; // the case of incorrect message
+			} else {
+				incount -= offset;
+			}
+		}
+	}
+
+	if (!strcasecmp(args.direction, "from")) {
+		if (!strcasecmp(args.smpp_charset, "ucs2")) {
+			outcount = ucs2_to_utf8(tmpin + offset, incount, tmp);
+			ast_base64encode(buf, (void *)tmp, outcount, len);
+			goto doneok;
+		}
+		if (!strcasecmp(args.smpp_charset, "gsm8")) {
+			outcount = utf8_from_gsm8(tmpin + offset, incount, tmp);
+			ast_base64encode(buf, (void *)tmp, outcount, len);
+			goto doneok;
+		}
+	}
+	if (!strcasecmp(args.direction, "to")) {
+		if (!strcasecmp(args.smpp_charset, "ucs2")) {
+			outcount = utf8_to_ucs2(tmpin + offset, incount, tmp) * 2;	// 2 bytes on UCS2 char
+			ast_base64encode(buf, (void *)tmp, outcount, len);
+			goto doneok;
+		}
+		if (!strcasecmp(args.smpp_charset, "gsm8")) {
+			outcount = utf8_to_gsm8(tmpin + offset, incount, tmp);
+			ast_base64encode(buf, (void *)tmp, outcount, len);
+			goto doneok;
+		}
+	}
+
+	ast_log(LOG_WARNING, "Wrong direction: %s\n", args.direction);
+	return -1;
+
+doneok:
+
+	ast_free(tmp);
+	ast_free(tmpin);
+	return 0;
+}
+
+
 static const struct ast_msg_tech smpp_msg_tech = {
 	.name = "smpp",
 	.msg_send = smpp_msg_send,
@@ -1719,9 +1836,18 @@
 	AST_CLI_DEFINE(handle_cli_smpp_show_peers,	     "Show SMPP peers"),
 };
 
+static struct ast_custom_function acf_smpprecode = {
+	.name = "SMPP_RECODE",
+	.read = smpp_recode,
+};
+
 static int load_module(void)
 {
 	if (ast_msg_tech_register(&smpp_msg_tech)) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	if (ast_custom_function_register(&acf_smpprecode)) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -1755,6 +1881,7 @@
 
 	ast_msg_tech_unregister(&smpp_msg_tech);
 	ast_cli_unregister_multiple(cli_smpp, sizeof(cli_smpp) / sizeof(struct ast_cli_entry));
+	ast_custom_function_unregister(&acf_smpprecode);
 	stop_monitor_threads();
 	destroy_smscs();
 




More information about the svn-commits mailing list