[asterisk-commits] oej: branch oej/realtimetext-t140 r48973 - in
/team/oej/realtimetext-t140: ./...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Dec 27 08:22:59 MST 2006
Author: oej
Date: Wed Dec 27 09:22:57 2006
New Revision: 48973
URL: http://svn.digium.com/view/asterisk?view=rev&rev=48973
Log:
Update, reset automerge
Added:
team/oej/realtimetext-t140/codecs/codec_g722.c
- copied unchanged from r48967, trunk/codecs/codec_g722.c
team/oej/realtimetext-t140/codecs/g722/
- copied from r48967, trunk/codecs/g722/
team/oej/realtimetext-t140/codecs/g722/Makefile
- copied unchanged from r48967, trunk/codecs/g722/Makefile
team/oej/realtimetext-t140/codecs/g722/g722.h
- copied unchanged from r48967, trunk/codecs/g722/g722.h
team/oej/realtimetext-t140/codecs/g722/g722_decode.c
- copied unchanged from r48967, trunk/codecs/g722/g722_decode.c
team/oej/realtimetext-t140/codecs/g722/g722_encode.c
- copied unchanged from r48967, trunk/codecs/g722/g722_encode.c
team/oej/realtimetext-t140/codecs/g722_slin_ex.h
- copied unchanged from r48967, trunk/codecs/g722_slin_ex.h
team/oej/realtimetext-t140/codecs/slin_g722_ex.h
- copied unchanged from r48967, trunk/codecs/slin_g722_ex.h
Modified:
team/oej/realtimetext-t140/ (props changed)
team/oej/realtimetext-t140/CHANGES
team/oej/realtimetext-t140/Makefile
team/oej/realtimetext-t140/apps/app_chanspy.c
team/oej/realtimetext-t140/apps/app_dictate.c
team/oej/realtimetext-t140/apps/app_directory.c
team/oej/realtimetext-t140/apps/app_disa.c
team/oej/realtimetext-t140/apps/app_festival.c
team/oej/realtimetext-t140/apps/app_meetme.c
team/oej/realtimetext-t140/apps/app_mixmonitor.c
team/oej/realtimetext-t140/apps/app_read.c
team/oej/realtimetext-t140/apps/app_record.c
team/oej/realtimetext-t140/apps/app_sms.c
team/oej/realtimetext-t140/apps/app_voicemail.c
team/oej/realtimetext-t140/build_tools/embed_modules.xml
team/oej/realtimetext-t140/cdr/cdr_sqlite.c
team/oej/realtimetext-t140/channels/chan_iax2.c
team/oej/realtimetext-t140/channels/chan_misdn.c
team/oej/realtimetext-t140/channels/chan_oss.c
team/oej/realtimetext-t140/channels/chan_sip.c
team/oej/realtimetext-t140/channels/chan_skinny.c
team/oej/realtimetext-t140/channels/chan_zap.c
team/oej/realtimetext-t140/codecs/Makefile
team/oej/realtimetext-t140/configs/http.conf.sample
team/oej/realtimetext-t140/configs/iax.conf.sample
team/oej/realtimetext-t140/configure
team/oej/realtimetext-t140/configure.ac
team/oej/realtimetext-t140/contrib/utils/zones2indications.c
team/oej/realtimetext-t140/funcs/func_callerid.c
team/oej/realtimetext-t140/funcs/func_channel.c
team/oej/realtimetext-t140/funcs/func_math.c
team/oej/realtimetext-t140/include/asterisk.h
team/oej/realtimetext-t140/include/asterisk/channel.h
team/oej/realtimetext-t140/include/asterisk/http.h
team/oej/realtimetext-t140/include/asterisk/indications.h
team/oej/realtimetext-t140/include/asterisk/lock.h
team/oej/realtimetext-t140/include/asterisk/rtp.h
team/oej/realtimetext-t140/include/jitterbuf.h
team/oej/realtimetext-t140/main/app.c
team/oej/realtimetext-t140/main/channel.c
team/oej/realtimetext-t140/main/db.c
team/oej/realtimetext-t140/main/file.c
team/oej/realtimetext-t140/main/frame.c
team/oej/realtimetext-t140/main/http.c
team/oej/realtimetext-t140/main/indications.c
team/oej/realtimetext-t140/main/jitterbuf.c
team/oej/realtimetext-t140/main/logger.c
team/oej/realtimetext-t140/main/manager.c
team/oej/realtimetext-t140/main/pbx.c
team/oej/realtimetext-t140/main/rtp.c
team/oej/realtimetext-t140/main/stdtime/localtime.c
team/oej/realtimetext-t140/pbx/pbx_config.c
team/oej/realtimetext-t140/redhat/asterisk.spec
team/oej/realtimetext-t140/res/res_agi.c
team/oej/realtimetext-t140/res/res_convert.c
team/oej/realtimetext-t140/res/res_indications.c
team/oej/realtimetext-t140/res/res_monitor.c
team/oej/realtimetext-t140/res/snmp/agent.c
Propchange: team/oej/realtimetext-t140/
------------------------------------------------------------------------------
automerge = http://edvina.net/training/
Propchange: team/oej/realtimetext-t140/
------------------------------------------------------------------------------
Binary property 'branch-1.4-blocked' - no diff available.
Propchange: team/oej/realtimetext-t140/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.
Propchange: team/oej/realtimetext-t140/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Dec 27 09:22:57 2006
@@ -1,1 +1,1 @@
-/trunk:1-48652
+/trunk:1-48972
Modified: team/oej/realtimetext-t140/CHANGES
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/CHANGES?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/CHANGES (original)
+++ team/oej/realtimetext-t140/CHANGES Wed Dec 27 09:22:57 2006
@@ -63,4 +63,6 @@
does not count paused queue members as unavailable.
* Added maxfiles option to options section of asterisk.conf which allows you to specify
what Asterisk should set as the maximum number of open files when it loads.
+ * Added the jittertargetextra configuration option.
+ * Added the URI redirect option for the built-in HTTP server
* Added support for T.140 realtime text in SIP/RTP
Modified: team/oej/realtimetext-t140/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/Makefile?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/Makefile (original)
+++ team/oej/realtimetext-t140/Makefile Wed Dec 27 09:22:57 2006
@@ -58,6 +58,7 @@
export SOLINK
export STRIP
export DOWNLOAD
+export OSARCH
# even though we could use '-include makeopts' here, use a wildcard
# lookup anyway, so that make won't try to build makeopts if it doesn't
Modified: team/oej/realtimetext-t140/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_chanspy.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_chanspy.c (original)
+++ team/oej/realtimetext-t140/apps/app_chanspy.c Wed Dec 27 09:22:57 2006
@@ -617,7 +617,7 @@
char filename[512];
snprintf(filename, sizeof(filename), "%s/%s.%d.raw", ast_config_AST_MONITOR_DIR, recbase, (int) time(NULL));
- if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644)) <= 0) {
+ if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, AST_FILE_MODE)) <= 0) {
ast_log(LOG_WARNING, "Cannot open '%s' for recording\n", filename);
fd = 0;
}
@@ -701,7 +701,7 @@
char filename[512];
snprintf(filename, sizeof(filename), "%s/%s.%d.raw", ast_config_AST_MONITOR_DIR, recbase, (int) time(NULL));
- if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644)) <= 0) {
+ if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, AST_FILE_MODE)) <= 0) {
ast_log(LOG_WARNING, "Cannot open '%s' for recording\n", filename);
fd = 0;
}
Modified: team/oej/realtimetext-t140/apps/app_dictate.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_dictate.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_dictate.c (original)
+++ team/oej/realtimetext-t140/apps/app_dictate.c Wed Dec 27 09:22:57 2006
@@ -150,7 +150,7 @@
}
snprintf(path, len, "%s/%s", base, filein);
- fs = ast_writefile(path, "raw", NULL, O_CREAT|O_APPEND, 0, 0700);
+ fs = ast_writefile(path, "raw", NULL, O_CREAT|O_APPEND, 0, AST_FILE_MODE);
mode = DMODE_PLAY;
memset(&flags, 0, sizeof(flags));
ast_set_flag(&flags, DFLAG_PAUSE);
@@ -307,7 +307,7 @@
} else {
oflags |= O_APPEND;
}
- fs = ast_writefile(path, "raw", NULL, oflags, 0, 0700);
+ fs = ast_writefile(path, "raw", NULL, oflags, 0, AST_FILE_MODE);
if (ast_test_flag(&flags, DFLAG_TRUNC)) {
ast_seekstream(fs, 0, SEEK_SET);
ast_clear_flag(&flags, DFLAG_TRUNC);
Modified: team/oej/realtimetext-t140/apps/app_directory.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_directory.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_directory.c (original)
+++ team/oej/realtimetext-t140/apps/app_directory.c Wed Dec 27 09:22:57 2006
@@ -142,7 +142,7 @@
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
break;
}
- fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, 0770);
+ fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, AST_FILE_MODE);
if (fd < 0) {
ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
Modified: team/oej/realtimetext-t140/apps/app_disa.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_disa.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_disa.c (original)
+++ team/oej/realtimetext-t140/apps/app_disa.c Wed Dec 27 09:22:57 2006
@@ -99,7 +99,7 @@
static void play_dialtone(struct ast_channel *chan, char *mailbox)
{
- const struct tone_zone_sound *ts = NULL;
+ const struct ind_tone_zone_sound *ts = NULL;
if(ast_app_has_voicemail(mailbox, NULL))
ts = ast_get_indication_tone(chan->zone, "dialrecall");
else
Modified: team/oej/realtimetext-t140/apps/app_festival.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_festival.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_festival.c (original)
+++ team/oej/realtimetext-t140/apps/app_festival.c Wed Dec 27 09:22:57 2006
@@ -433,7 +433,7 @@
snprintf(cachefile, sizeof(cachefile), "%s/%s", cachedir, MD5Hex);
fdesc=open(cachefile,O_RDWR);
if (fdesc==-1) {
- fdesc=open(cachefile,O_CREAT|O_RDWR,0777);
+ fdesc=open(cachefile,O_CREAT|O_RDWR,AST_FILE_MODE);
if (fdesc!=-1) {
writecache=1;
strln=strlen((char *)data);
Modified: team/oej/realtimetext-t140/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_meetme.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_meetme.c (original)
+++ team/oej/realtimetext-t140/apps/app_meetme.c Wed Dec 27 09:22:57 2006
@@ -1979,25 +1979,21 @@
if (!strcmp(confno, cnf->confno))
break;
}
- if (cnf){
+ if (cnf) {
cnf->refcount += refcount;
}
AST_LIST_UNLOCK(&confs);
if (!cnf) {
char *pin = NULL, *pinadmin = NULL; /* For temp use */
-
- cnf = ast_calloc(1, sizeof(struct ast_conference));
- if (!cnf) {
- ast_log(LOG_ERROR, "Out of memory\n");
+
+ var = ast_load_realtime("meetme", "confno", confno, NULL);
+
+ if (!var)
return NULL;
- }
-
- var = ast_load_realtime("meetme", "confno", confno, NULL);
+
while (var) {
- if (!strcasecmp(var->name, "confno")) {
- ast_copy_string(cnf->confno, var->value, sizeof(cnf->confno));
- } else if (!strcasecmp(var->name, "pin")) {
+ if (!strcasecmp(var->name, "pin")) {
pin = ast_strdupa(var->value);
} else if (!strcasecmp(var->name, "adminpin")) {
pinadmin = ast_strdupa(var->value);
@@ -2005,7 +2001,7 @@
var = var->next;
}
ast_variables_destroy(var);
-
+
cnf = build_conf(confno, pin ? pin : "", pinadmin ? pinadmin : "", make, dynamic, refcount);
}
@@ -2874,7 +2870,7 @@
break;
}
if (!s && cnf->recordingfilename && (cnf->recordingfilename != oldrecordingfilename)) {
- s = ast_writefile(cnf->recordingfilename, cnf->recordingformat, NULL, flags, 0, 0644);
+ s = ast_writefile(cnf->recordingfilename, cnf->recordingformat, NULL, flags, 0, AST_FILE_MODE);
oldrecordingfilename = cnf->recordingfilename;
}
Modified: team/oej/realtimetext-t140/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_mixmonitor.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_mixmonitor.c (original)
+++ team/oej/realtimetext-t140/apps/app_mixmonitor.c Wed Dec 27 09:22:57 2006
@@ -256,7 +256,7 @@
}
/* Move onto actually creating the filestream */
- mixmonitor->fs = ast_writefile(file_name, ext, NULL, oflags, 0, 0644);
+ mixmonitor->fs = ast_writefile(file_name, ext, NULL, oflags, 0, AST_FILE_MODE);
if (!mixmonitor->fs) {
ast_log(LOG_ERROR, "Cannot open %s.%s\n", file_name, ext);
free(mixmonitor);
Modified: team/oej/realtimetext-t140/apps/app_read.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_read.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_read.c (original)
+++ team/oej/realtimetext-t140/apps/app_read.c Wed Dec 27 09:22:57 2006
@@ -93,7 +93,7 @@
int tries = 1, to = 0, x = 0;
double tosec;
char *argcopy = NULL;
- struct tone_zone_sound *ts;
+ struct ind_tone_zone_sound *ts;
struct ast_flags flags = {0};
AST_DECLARE_APP_ARGS(arglist,
Modified: team/oej/realtimetext-t140/apps/app_record.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_record.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_record.c (original)
+++ team/oej/realtimetext-t140/apps/app_record.c Wed Dec 27 09:22:57 2006
@@ -265,7 +265,7 @@
flags = option_append ? O_CREAT|O_APPEND|O_WRONLY : O_CREAT|O_TRUNC|O_WRONLY;
- s = ast_writefile( tmp, ext, NULL, flags , 0, 0644);
+ s = ast_writefile( tmp, ext, NULL, flags , 0, AST_FILE_MODE);
if (!s) {
ast_log(LOG_WARNING, "Could not create file %s\n", filename);
Modified: team/oej/realtimetext-t140/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/team/oej/realtimetext-t140/apps/app_sms.c?view=diff&rev=48973&r1=48972&r2=48973
==============================================================================
--- team/oej/realtimetext-t140/apps/app_sms.c (original)
+++ team/oej/realtimetext-t140/apps/app_sms.c Wed Dec 27 09:22:57 2006
@@ -16,10 +16,24 @@
/*! \file
*
- * \brief SMS application - ETSI ES 201 912 protocol 1 implimentation
+ * \brief SMS application - ETSI ES 201 912 protocol 1 implementation
+ *
+ * \par Development notes
+ * \note The ETSI standards are available free of charge from ETSI at
+ * http://pda.etsi.org/pda/queryform.asp
+ * Among the relevant documents here we have:
+ *
+ * ES 201 912 SMS for PSTN/ISDN
+ * TS 123 040 Technical realization of SMS
+ *
+ * \note 2006-09-19: ETSI ES 201 912 protocol 2 used in Italy and Spain
+ * support added by Filippo Grassilli (Hyppo)
+ * <http://hyppo.com> (Hyppo)
+ * Not fully tested, under development
+ *
* \ingroup applications
*
- * \author Adrian Kennard
+ * \author Adrian Kennard (for the original protocol 1 code)
*/
#include "asterisk.h"
@@ -45,6 +59,8 @@
#include "asterisk/module.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
/* #define OUTALAW */ /* enable this to output Alaw rather than linear */
@@ -65,9 +81,11 @@
static char *synopsis = "Communicates with SMS service centres and SMS capable analogue phones";
static char *descrip =
- " SMS(name|[a][s]): SMS handles exchange of SMS data with a call to/from SMS capabale\n"
+ " SMS(name|[a][s][t][p(d)][r][o]|addr|body):\n"
+ "SMS handles exchange of SMS data with a call to/from SMS capable\n"
"phone or SMS PSTN service center. Can send and/or receive SMS messages.\n"
"Works to ETSI ES 201 912 compatible with BT SMS PSTN service in UK\n"
+ "and Telecom Italia in Italy.\n"
"Typical usage is to use to handle called from the SMS service centre CLI,\n"
"or to set up a call using 'outgoing' or manager interface to connect\n"
"service centre to SMS()\n"
@@ -75,9 +93,17 @@
"Arguments:\n"
" a: answer, i.e. send initial FSK packet.\n"
" s: act as service centre talking to a phone.\n"
+ " t: use protocol 2 (default used is protocol 1).\n"
+ " p(N): set the initial delay to N ms (default is 300).\n"
+ "addr and body are a deprecated format to send messages out.\n"
+ " s: set the Status Report Request (SRR) bit.\n"
+ " o: the body should be coded as octets not 7-bit symbols.\n"
"Messages are processed as per text file message queues.\n"
"smsq (a separate software) is a command to generate message\n"
- "queues and send messages.\n";
+ "queues and send messages.\n"
+ "NOTE: the protocol has tight delay bounds. Please use short frames\n"
+ "and disable/keep short the jitter buffer on the ATA to make sure that\n"
+ "respones (ACK etc.) are received in time.\n";
/*
* 80 samples of a single period of the wave. At 8000 Hz, it means these
@@ -105,6 +131,43 @@
#define __OUT_FMT AST_FORMAT_SLINEAR
#endif
+#define OSYNC_BITS 80 /* initial sync bits */
+
+/*!
+ * The SMS spec ETSI ES 201 912 defines two protocols with different message types.
+ * Also note that the high bit is used to indicate whether the message
+ * is complete or not, but in two opposite ways:
+ * for Protocol 1, 0x80 means that the message is complete;
+ * for Protocol 2, 0x00 means that the message is complete;
+ */
+enum message_types {
+ DLL_SMS_MASK = 0x7f, /* mask for the valid bits */
+
+ /* Protocol 1 values */
+ DLL1_SMS_DATA = 0x11, /* data packet */
+ DLL1_SMS_ERROR = 0x12,
+ DLL1_SMS_EST = 0x13, /* start the connection */
+ DLL1_SMS_REL = 0x14, /* end the connection */
+ DLL1_SMS_ACK = 0x15,
+ DLL1_SMS_NACK = 0x16,
+
+ DLL1_SMS_COMPLETE = 0x80, /* packet is complete */
+ DLL1_SMS_MORE = 0x00, /* more data to follow */
+
+ /* Protocol 2 values */
+ DLL2_SMS_EST = 0x7f, /* magic number. No message body */
+ DLL2_SMS_INFO_MO = 0x10,
+ DLL2_SMS_INFO_MT = 0x11,
+ DLL2_SMS_INFO_STA = 0x12,
+ DLL2_SMS_NACK = 0x13,
+ DLL2_SMS_ACK0 = 0x14, /* ack even-numbered frame */
+ DLL2_SMS_ACK1 = 0x15, /* ack odd-numbered frame */
+ DLL2_SMS_ENQ = 0x16,
+ DLL2_SMS_REL = 0x17, /* end the connection */
+
+ DLL2_SMS_COMPLETE = 0x00, /* packet is complete */
+ DLL2_SMS_MORE = 0x80, /* more data to follow */
+};
/* SMS 7 bit character mapping to UCS-2 */
static const unsigned short defaultalphabet[] = {
@@ -131,10 +194,10 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-#define SMSLEN 160 /*!< max SMS length */
-
-typedef struct sms_s
-{
+#define SMSLEN 160 /*!< max SMS length */
+#define SMSLEN_8 140 /*!< max SMS length for 8-bit char */
+
+typedef struct sms_s {
unsigned char hangup; /*!< we are done... */
unsigned char err; /*!< set for any errors */
unsigned char smsc:1; /*!< we are SMSC */
@@ -145,7 +208,7 @@
time_t scts; /*!< time stamp, UTC */
unsigned char pid; /*!< protocol ID */
unsigned char dcs; /*!< data coding scheme */
- short mr; /*!< message reference - actually a byte, but usde -1 for not set */
+ short mr; /*!< message reference - actually a byte, but use -1 for not set */
int udl; /*!< user data length */
int udhl; /*!< user data header length */
unsigned char srr:1; /*!< Status Report request */
@@ -186,27 +249,23 @@
unsigned char ibith; /*!< history of last bits */
unsigned char ibitt; /*!< total of 1's in last 3 bytes */
/* more to go here */
+
+ int opause_0; /*!< initial delay in ms, p() option */
+ int protocol; /*!< ETSI SMS protocol to use (passed at app call) */
+ int oseizure; /*!< protocol 2: channel seizure bits to send */
+ int framenumber; /*!< protocol 2: frame number (for sending ACK0 or ACK1) */
+ char udtxt[SMSLEN]; /*!< user data (message), PLAIN text */
} sms_t;
/* different types of encoding */
-#define is7bit(dcs) (((dcs)&0xC0)?(!((dcs)&4)):(!((dcs)&12)))
-#define is8bit(dcs) (((dcs)&0xC0)?(((dcs)&4)):(((dcs)&12)==4))
-#define is16bit(dcs) (((dcs)&0xC0)?0:(((dcs)&12)==8))
-
-static void *sms_alloc (struct ast_channel *chan, void *params)
-{
- return params;
-}
-
-static void sms_release (struct ast_channel *chan, void *data)
-{
- return;
-}
+#define is7bit(dcs) ( ((dcs) & 0xC0) ? (!((dcs)&4) ) : (((dcs) & 0xc) == 0) )
+#define is8bit(dcs) ( ((dcs) & 0xC0) ? ( ((dcs)&4) ) : (((dcs) & 0xc) == 4) )
+#define is16bit(dcs) ( ((dcs) & 0xC0) ? 0 : (((dcs) & 0xc) == 8) )
static void sms_messagetx (sms_t * h);
/*! \brief copy number, skipping non digits apart from leading + */
-static void numcpy (char *d, char *s)
+static void numcpy(char *d, char *s)
{
if (*s == '+')
*d++ = *s++;
@@ -219,17 +278,16 @@
}
/*! \brief static, return a date/time in ISO format */
-static char * isodate (time_t t)
-{
- static char date[20];
- strftime (date, sizeof (date), "%Y-%m-%dT%H:%M:%S", localtime (&t));
- return date;
-}
-
-/*! \brief reads next UCS character from null terminated UTF-8 string and advanced pointer */
+static char * isodate(time_t t, char *buf, int len)
+{
+ strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime (&t));
+ return buf;
+}
+
+/*! \brief Reads next UCS character from NUL terminated UTF-8 string and advance pointer */
/* for non valid UTF-8 sequences, returns character as is */
/* Does not advance pointer for null termination */
-static long utf8decode (unsigned char **pp)
+static long utf8decode(unsigned char **pp)
{
unsigned char *p = *pp;
if (!*p)
@@ -276,18 +334,22 @@
/* The return value is the number of septets packed in to o, which is internally limited to SMSLEN */
/* o can be null, in which case this is used to validate or count only */
/* if the input contains invalid characters then the return value is -1 */
-static int packsms7 (unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
-{
- unsigned char p = 0, b = 0, n = 0;
+static int packsms7(unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
+{
+ unsigned char p = 0; /* output pointer (bytes) */
+ unsigned char b = 0; /* bit position */
+ unsigned char n = 0; /* output character count */
+ unsigned char dummy[SMSLEN];
+
+ if (o == NULL) /* output to a dummy buffer if o not set */
+ o = dummy;
if (udhl) { /* header */
- if (o)
- o[p++] = udhl;
+ o[p++] = udhl;
b = 1;
n = 1;
while (udhl--) {
- if (o)
- o[p++] = *udh++;
+ o[p++] = *udh++;
b += 8;
while (b >= 7) {
b -= 7;
@@ -300,41 +362,41 @@
b = 7 - b;
if (++n >= SMSLEN)
return n;
- }; /* filling to septet boundary */
- }
- if (o)
- o[p] = 0;
- /* message */
- while (udl--) {
- long u;
- unsigned char v;
- u = *ud++;
- for (v = 0; v < 128 && defaultalphabet[v] != u; v++);
- if (v == 128 && u && n + 1 < SMSLEN) {
- for (v = 0; v < 128 && escapes[v] != u; v++);
- if (v < 128) { /* escaped sequence */
- if (o)
- o[p] |= (27 << b);
+ }; /* filling to septet boundary */
+ }
+ o[p] = 0;
+ /* message */
+ while (udl--) {
+ long u;
+ unsigned char v;
+ u = *ud++;
+ /* XXX 0 is invalid ? */
+ /* look up in defaultalphabet[]. If found, v is the 7-bit code */
+ for (v = 0; v < 128 && defaultalphabet[v] != u; v++);
+ if (v == 128 /* not found */ && u && n + 1 < SMSLEN) {
+ /* if not found, look in the escapes table (we need 2 bytes) */
+ for (v = 0; v < 128 && escapes[v] != u; v++);
+ if (v < 128) { /* escaped sequence, esc + v */
+ /* store the low (8-b) bits in o[p], the remaining bits in o[p+1] */
+ o[p] |= (27 << b); /* the low bits go into o[p] */
b += 7;
if (b >= 8) {
b -= 8;
p++;
- if (o)
- o[p] = (27 >> (7 - b));
+ o[p] = (27 >> (7 - b));
}
n++;
}
}
if (v == 128)
return -1; /* invalid character */
- if (o)
- o[p] |= (v << b);
+ /* store, same as above */
+ o[p] |= (v << b);
b += 7;
if (b >= 8) {
b -= 8;
p++;
- if (o)
- o[p] = (v >> (7 - b));
+ o[p] = (v >> (7 - b));
}
if (++n >= SMSLEN)
return n;
@@ -342,22 +404,25 @@
return n;
}
-/*! \brief takes a binary header (udhl bytes at udh) and UCS-2 message (udl characters at ud) and packs in to o using 8 bit character codes */
-/* The return value is the number of bytes packed in to o, which is internally limited to 140 */
-/* o can be null, in which case this is used to validate or count only */
-/* if the input contains invalid characters then the return value is -1 */
-static int packsms8 (unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
+/*! \brief takes a binary header (udhl bytes at udh) and UCS-2 message (udl characters at ud)
+ * and packs in to o using 8 bit character codes.
+ * The return value is the number of bytes packed in to o, which is internally limited to 140.
+ * o can be null, in which case this is used to validate or count only.
+ * if the input contains invalid characters then the return value is -1
+ */
+static int packsms8(unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
{
unsigned char p = 0;
-
+ unsigned char dummy[SMSLEN_8];
+
+ if (o == NULL)
+ o = dummy;
/* header - no encoding */
if (udhl) {
- if (o)
- o[p++] = udhl;
+ o[p++] = udhl;
while (udhl--) {
- if (o)
- o[p++] = *udh++;
- if (p >= 140)
+ o[p++] = *udh++;
+ if (p >= SMSLEN_8)
return p;
}
}
@@ -366,9 +431,8 @@
u = *ud++;
if (u < 0 || u > 0xFF)
return -1; /* not valid */
- if (o)
- o[p++] = u;
- if (p >= 140)
+ o[p++] = u;
+ if (p >= SMSLEN_8)
return p;
}
return p;
@@ -382,30 +446,30 @@
o can be null, in which case this is used to validate or count
only if the input contains invalid characters then
the return value is -1 */
-static int packsms16 (unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
+static int packsms16(unsigned char *o, int udhl, unsigned char *udh, int udl, unsigned short *ud)
{
unsigned char p = 0;
+ unsigned char dummy[SMSLEN_8];
+
+ if (o == NULL)
+ o = dummy;
/* header - no encoding */
if (udhl) {
- if (o)
- o[p++] = udhl;
+ o[p++] = udhl;
while (udhl--) {
- if (o)
- o[p++] = *udh++;
- if (p >= 140)
+ o[p++] = *udh++;
+ if (p >= SMSLEN_8)
return p;
}
}
while (udl--) {
long u;
u = *ud++;
- if (o)
- o[p++] = (u >> 8);
- if (p >= 140)
+ o[p++] = (u >> 8);
+ if (p >= SMSLEN_8)
return p - 1; /* could not fit last character */
- if (o)
- o[p++] = u;
- if (p >= 140)
+ o[p++] = u;
+ if (p >= SMSLEN_8)
return p;
}
return p;
@@ -413,38 +477,40 @@
/*! \brief general pack, with length and data,
returns number of bytes of target used */
-static int packsms (unsigned char dcs, unsigned char *base, unsigned int udhl, unsigned char *udh, int udl, unsigned short *ud)
+static int packsms(unsigned char dcs, unsigned char *base, unsigned int udhl, unsigned char *udh, int udl, unsigned short *ud)
{
unsigned char *p = base;
- if (udl) {
+ if (udl == 0)
+ *p++ = 0; /* no user data */
+ else {
+
int l = 0;
- if (is7bit (dcs)) { /* 7 bit */
- l = packsms7 (p + 1, udhl, udh, udl, ud);
+ if (is7bit(dcs)) { /* 7 bit */
+ l = packsms7(p + 1, udhl, udh, udl, ud);
if (l < 0)
l = 0;
*p++ = l;
p += (l * 7 + 7) / 8;
- } else if (is8bit (dcs)) { /* 8 bit */
- l = packsms8 (p + 1, udhl, udh, udl, ud);
+ } else if (is8bit(dcs)) { /* 8 bit */
+ l = packsms8(p + 1, udhl, udh, udl, ud);
if (l < 0)
l = 0;
*p++ = l;
p += l;
- } else { /* UCS-2 */
- l = packsms16 (p + 1, udhl, udh, udl, ud);
+ } else { /* UCS-2 */
+ l = packsms16(p + 1, udhl, udh, udl, ud);
if (l < 0)
l = 0;
*p++ = l;
p += l;
}
- } else
- *p++ = 0; /* no user data */
+ }
return p - base;
}
/*! \brief pack a date and return */
-static void packdate (unsigned char *o, time_t w)
+static void packdate(unsigned char *o, time_t w)
{
struct tm *t = localtime (&w);
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__)
@@ -485,7 +551,7 @@
/*! \brief unpacks bytes (7 bit encoding) at i, len l septets,
and places in udh and ud setting udhl and udl. udh not used
if udhi not set */
-static void unpacksms7 (unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
+static void unpacksms7(unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
{
unsigned char b = 0, p = 0;
unsigned short *o = ud;
@@ -517,7 +583,7 @@
while (l--) {
unsigned char v;
if (b < 2)
- v = ((i[p] >> b) & 0x7F);
+ v = ((i[p] >> b) & 0x7F); /* everything in one byte */
else
v = ((((i[p] >> b) + (i[p + 1] << (8 - b)))) & 0x7F);
b += 7;
@@ -525,6 +591,7 @@
b -= 8;
p++;
}
+ /* 0x00A0 is the encoding of ESC (27) in defaultalphabet */
if (o > ud && o[-1] == 0x00A0 && escapes[v])
o[-1] = escapes[v];
else
@@ -536,7 +603,7 @@
/*! \brief unpacks bytes (8 bit encoding) at i, len l septets,
and places in udh and ud setting udhl and udl. udh not used
if udhi not set */
-static void unpacksms8 (unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
+static void unpacksms8(unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
{
unsigned short *o = ud;
*udhl = 0;
@@ -561,7 +628,7 @@
/*! \brief unpacks bytes (16 bit encoding) at i, len l septets,
and places in udh and ud setting udhl and udl.
udh not used if udhi not set */
-static void unpacksms16 (unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
+static void unpacksms16(unsigned char *i, unsigned char l, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
{
unsigned short *o = ud;
*udhl = 0;
@@ -588,7 +655,7 @@
}
/*! \brief general unpack - starts with length byte (octet or septet) and returns number of bytes used, inc length */
-static int unpacksms (unsigned char dcs, unsigned char *i, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
+static int unpacksms(unsigned char dcs, unsigned char *i, unsigned char *udh, int *udhl, unsigned short *ud, int *udl, char udhi)
{
int l = *i++;
if (is7bit (dcs)) {
@@ -602,7 +669,7 @@
}
/*! \brief unpack an address from i, return byte length, unpack to o */
-static unsigned char unpackaddress (char *o, unsigned char *i)
+static unsigned char unpackaddress(char *o, unsigned char *i)
{
unsigned char l = i[0],
p;
@@ -619,70 +686,74 @@
}
/*! \brief store an address at o, and return number of bytes used */
-static unsigned char packaddress (unsigned char *o, char *i)
+static unsigned char packaddress(unsigned char *o, char *i)
{
unsigned char p = 2;
- o[0] = 0;
- if (*i == '+') {
+ o[0] = 0; /* number of bytes */
+ if (*i == '+') { /* record as bit 0 in byte 1 */
i++;
o[1] = 0x91;
} else
o[1] = 0x81;
- while (*i)
- if (isdigit (*i)) {
- if (o[0] & 1)
- o[p++] |= ((*i & 0xF) << 4);
- else
- o[p] = (*i & 0xF);
- o[0]++;
- i++;
- } else
- i++;
+ for ( ; *i ; i++) {
+ if (!isdigit (*i)) /* ignore non-digits */
+ continue;
+ if (o[0] & 1)
+ o[p++] |= ((*i & 0xF) << 4);
+ else
+ o[p] = (*i & 0xF);
+ o[0]++;
+ }
if (o[0] & 1)
o[p++] |= 0xF0; /* pad */
return p;
}
/*! \brief Log the output, and remove file */
-static void sms_log (sms_t * h, char status)
-{
- if (*h->oa || *h->da) {
- int o = open (log_file, O_CREAT | O_APPEND | O_WRONLY, 0666);
- if (o >= 0) {
- char line[1000], mrs[3] = "", *p;
- unsigned char n;
-
- if (h->mr >= 0)
- snprintf (mrs, sizeof (mrs), "%02X", h->mr);
- snprintf (line, sizeof (line), "%s %c%c%c%s %s %s %s ",
- isodate (time (0)), status, h->rx ? 'I' : 'O', h->smsc ? 'S' : 'M', mrs, h->queue, *h->oa ? h->oa : "-",
- *h->da ? h->da : "-");
- p = line + strlen (line);
- for (n = 0; n < h->udl; n++)
- if (h->ud[n] == '\\') {
- *p++ = '\\';
- *p++ = '\\';
- } else if (h->ud[n] == '\n') {
- *p++ = '\\';
- *p++ = 'n';
- } else if (h->ud[n] == '\r') {
- *p++ = '\\';
- *p++ = 'r';
- } else if (h->ud[n] < 32 || h->ud[n] == 127)
- *p++ = 191;
- else
- *p++ = h->ud[n];
- *p++ = '\n';
- *p = 0;
- write (o, line, strlen (line));
- close (o);
- }
- *h->oa = *h->da = h->udl = 0;
- }
+static void sms_log(sms_t * h, char status)
+{
+ int o;
+
+ if (*h->oa == '\0' && *h->da == '\0')
+ return;
+ o = open (log_file, O_CREAT | O_APPEND | O_WRONLY, AST_FILE_MODE);
+ if (o >= 0) {
+ char line[1000], mrs[3] = "", *p;
+ char buf[30];
+ unsigned char n;
+
+ if (h->mr >= 0)
+ snprintf (mrs, sizeof (mrs), "%02X", h->mr);
+ snprintf (line, sizeof (line), "%s %c%c%c%s %s %s %s ",
+ isodate(time(0), buf, sizeof(buf)),
+ status, h->rx ? 'I' : 'O', h->smsc ? 'S' : 'M', mrs, h->queue,
+ S_OR(h->oa, "-"), S_OR(h->da, "-") );
+ p = line + strlen (line);
+ for (n = 0; n < h->udl; n++) {
+ if (h->ud[n] == '\\') {
+ *p++ = '\\';
+ *p++ = '\\';
+ } else if (h->ud[n] == '\n') {
+ *p++ = '\\';
+ *p++ = 'n';
+ } else if (h->ud[n] == '\r') {
+ *p++ = '\\';
+ *p++ = 'r';
+ } else if (h->ud[n] < 32 || h->ud[n] == 127)
+ *p++ = 191;
+ else
+ *p++ = h->ud[n];
+ }
+ *p++ = '\n';
+ *p = 0;
+ write (o, line, strlen (line));
+ close (o);
+ }
+ *h->oa = *h->da = h->udl = 0;
}
/*! \brief parse and delete a file */
-static void sms_readfile (sms_t * h, char *fn)
+static void sms_readfile(sms_t * h, char *fn)
{
char line[1000];
FILE *s;
@@ -716,6 +787,7 @@
*p++ = 0;
if (!strcmp (line, "ud")) { /* parse message (UTF-8) */
unsigned char o = 0;
+ memcpy(h->udtxt,p,SMSLEN); /* for protocol 2 */
while (*p && o < SMSLEN)
h->ud[o++] = utf8decode(pp);
h->udl = o;
@@ -840,100 +912,105 @@
}
/*! \brief white a received text message to a file */
-static void sms_writefile (sms_t * h)
+static void sms_writefile(sms_t * h)
{
char fn[200] = "", fn2[200] = "";
+ char buf[30];
FILE *o;
- ast_copy_string (fn, spool_dir, sizeof (fn));
- mkdir (fn, 0777); /* ensure it exists */
- snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
- mkdir (fn, 0777); /* ensure it exists */
- ast_copy_string (fn2, fn, sizeof (fn2));
- snprintf (fn2 + strlen (fn2), sizeof (fn2) - strlen (fn2), "/%s.%s-%d", h->queue, isodate (h->scts), seq++);
+
+ ast_copy_string(fn, spool_dir, sizeof (fn));
+ mkdir(fn, 0777); /* ensure it exists */
+ snprintf(fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
+ mkdir(fn, 0777); /* ensure it exists */
+ ast_copy_string(fn2, fn, sizeof (fn2));
+ snprintf(fn2 + strlen (fn2), sizeof (fn2) - strlen (fn2), "/%s.%s-%d", h->queue, isodate(h->scts, buf, sizeof(buf)), seq++);
snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/.%s", fn2 + strlen (fn) + 1);
o = fopen (fn, "w");
- if (o) {
- if (*h->oa)
- fprintf (o, "oa=%s\n", h->oa);
- if (*h->da)
- fprintf (o, "da=%s\n", h->da);
- if (h->udhi) {
- unsigned int p;
- fprintf (o, "udh#");
- for (p = 0; p < h->udhl; p++)
- fprintf (o, "%02X", h->udh[p]);
- fprintf (o, "\n");
- }
- if (h->udl) {
- unsigned int p;
- for (p = 0; p < h->udl && h->ud[p] >= ' '; p++);
- if (p < h->udl)
- fputc (';', o); /* cannot use ud=, but include as a comment for human readable */
- fprintf (o, "ud=");
- for (p = 0; p < h->udl; p++) {
- unsigned short v = h->ud[p];
- if (v < 32)
- fputc (191, o);
- else if (v < 0x80)
- fputc (v, o);
- else if (v < 0x800)
- {
- fputc (0xC0 + (v >> 6), o);
- fputc (0x80 + (v & 0x3F), o);
- } else
- {
- fputc (0xE0 + (v >> 12), o);
- fputc (0x80 + ((v >> 6) & 0x3F), o);
- fputc (0x80 + (v & 0x3F), o);
- }
+ if (o == NULL)
+ return;
+
+ if (*h->oa)
+ fprintf (o, "oa=%s\n", h->oa);
+ if (*h->da)
+ fprintf (o, "da=%s\n", h->da);
+ if (h->udhi) {
+ unsigned int p;
+ fprintf (o, "udh#");
+ for (p = 0; p < h->udhl; p++)
+ fprintf (o, "%02X", h->udh[p]);
+ fprintf (o, "\n");
+ }
+ if (h->udl) {
+ unsigned int p;
+ for (p = 0; p < h->udl && h->ud[p] >= ' '; p++);
+ if (p < h->udl)
+ fputc (';', o); /* cannot use ud=, but include as a comment for human readable */
+ fprintf (o, "ud=");
+ for (p = 0; p < h->udl; p++) {
+ unsigned short v = h->ud[p];
+ if (v < 32)
+ fputc (191, o);
+ else if (v < 0x80)
+ fputc (v, o);
+ else if (v < 0x800)
+ {
+ fputc (0xC0 + (v >> 6), o);
+ fputc (0x80 + (v & 0x3F), o);
+ } else
+ {
+ fputc (0xE0 + (v >> 12), o);
+ fputc (0x80 + ((v >> 6) & 0x3F), o);
+ fputc (0x80 + (v & 0x3F), o);
}
- fprintf (o, "\n");
- for (p = 0; p < h->udl && h->ud[p] >= ' '; p++);
- if (p < h->udl) {
- for (p = 0; p < h->udl && h->ud[p] < 0x100; p++);
- if (p == h->udl) { /* can write in ucs-1 hex */
- fprintf (o, "ud#");
- for (p = 0; p < h->udl; p++)
- fprintf (o, "%02X", h->ud[p]);
- fprintf (o, "\n");
- } else { /* write in UCS-2 */
- fprintf (o, "ud##");
- for (p = 0; p < h->udl; p++)
- fprintf (o, "%04X", h->ud[p]);
- fprintf (o, "\n");
- }
+ }
+ fprintf (o, "\n");
+ for (p = 0; p < h->udl && h->ud[p] >= ' '; p++);
+ if (p < h->udl) {
+ for (p = 0; p < h->udl && h->ud[p] < 0x100; p++);
+ if (p == h->udl) { /* can write in ucs-1 hex */
+ fprintf (o, "ud#");
+ for (p = 0; p < h->udl; p++)
+ fprintf (o, "%02X", h->ud[p]);
+ fprintf (o, "\n");
+ } else { /* write in UCS-2 */
+ fprintf (o, "ud##");
+ for (p = 0; p < h->udl; p++)
+ fprintf (o, "%04X", h->ud[p]);
+ fprintf (o, "\n");
}
}
- if (h->scts)
- fprintf (o, "scts=%s\n", isodate (h->scts));
- if (h->pid)
- fprintf (o, "pid=%d\n", h->pid);
- if (h->dcs != 0xF1)
- fprintf (o, "dcs=%d\n", h->dcs);
- if (h->vp)
- fprintf (o, "vp=%d\n", h->vp);
- if (h->srr)
- fprintf (o, "srr=1\n");
- if (h->mr >= 0)
- fprintf (o, "mr=%d\n", h->mr);
- if (h->rp)
- fprintf (o, "rp=1\n");
- fclose (o);
- if (rename (fn, fn2))
- unlink (fn);
- else
- ast_log (LOG_EVENT, "Received to %s\n", fn2);
- }
+ }
+ if (h->scts) {
+ char buf[30];
+ fprintf (o, "scts=%s\n", isodate(h->scts, buf, sizeof(buf)));
+ }
+ if (h->pid)
+ fprintf (o, "pid=%d\n", h->pid);
+ if (h->dcs != 0xF1)
+ fprintf (o, "dcs=%d\n", h->dcs);
+ if (h->vp)
+ fprintf (o, "vp=%d\n", h->vp);
+ if (h->srr)
+ fprintf (o, "srr=1\n");
+ if (h->mr >= 0)
+ fprintf (o, "mr=%d\n", h->mr);
+ if (h->rp)
+ fprintf (o, "rp=1\n");
+ fclose (o);
+ if (rename (fn, fn2))
+ unlink (fn);
+ else
+ ast_log (LOG_EVENT, "Received to %s\n", fn2);
}
/*! \brief read dir skipping dot files... */
static struct dirent *readdirqueue (DIR * d, char *queue)
{
- struct dirent *f;
- do {
- f = readdir (d);
[... 7223 lines stripped ...]
More information about the asterisk-commits
mailing list