mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-29 18:19:30 +00:00
Code cleanups
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@71190 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -72,7 +72,6 @@ static volatile unsigned char message_ref; /* arbitary message ref */
|
||||
static volatile unsigned int seq; /* arbitrary message sequence number for unqiue files */
|
||||
|
||||
static char log_file[255];
|
||||
static char spool_dir[255];
|
||||
|
||||
static char *app = "SMS";
|
||||
|
||||
@@ -82,9 +81,9 @@ static char *descrip =
|
||||
" 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"
|
||||
"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"
|
||||
"Typical usage is to use to handle calls 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"
|
||||
"name is the name of the queue used in /var/spool/asterisk/sms\n"
|
||||
@@ -278,7 +277,9 @@ static void numcpy(char *d, char *s)
|
||||
/*! \brief static, return a date/time in ISO format */
|
||||
static char *isodate(time_t t, char *buf, int len)
|
||||
{
|
||||
strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime (&t));
|
||||
struct tm tm;
|
||||
ast_localtime(&t, &tm, NULL);
|
||||
strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -510,18 +511,19 @@ static int packsms(unsigned char dcs, unsigned char *base, unsigned int udhl, un
|
||||
/*! \brief pack a date and return */
|
||||
static void packdate(unsigned char *o, time_t w)
|
||||
{
|
||||
struct tm *t = localtime (&w);
|
||||
struct tm t;
|
||||
ast_localtime(&w, &t, NULL);
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__)
|
||||
int z = -t->tm_gmtoff / 60 / 15;
|
||||
int z = -t.tm_gmtoff / 60 / 15;
|
||||
#else
|
||||
int z = timezone / 60 / 15;
|
||||
#endif
|
||||
*o++ = ((t->tm_year % 10) << 4) + (t->tm_year % 100) / 10;
|
||||
*o++ = (((t->tm_mon + 1) % 10) << 4) + (t->tm_mon + 1) / 10;
|
||||
*o++ = ((t->tm_mday % 10) << 4) + t->tm_mday / 10;
|
||||
*o++ = ((t->tm_hour % 10) << 4) + t->tm_hour / 10;
|
||||
*o++ = ((t->tm_min % 10) << 4) + t->tm_min / 10;
|
||||
*o++ = ((t->tm_sec % 10) << 4) + t->tm_sec / 10;
|
||||
*o++ = ((t.tm_year % 10) << 4) + (t.tm_year % 100) / 10;
|
||||
*o++ = (((t.tm_mon + 1) % 10) << 4) + (t.tm_mon + 1) / 10;
|
||||
*o++ = ((t.tm_mday % 10) << 4) + t.tm_mday / 10;
|
||||
*o++ = ((t.tm_hour % 10) << 4) + t.tm_hour / 10;
|
||||
*o++ = ((t.tm_min % 10) << 4) + t.tm_min / 10;
|
||||
*o++ = ((t.tm_sec % 10) << 4) + t.tm_sec / 10;
|
||||
if (z < 0)
|
||||
*o++ = (((-z) % 10) << 4) + (-z) / 10 + 0x08;
|
||||
else
|
||||
@@ -723,7 +725,7 @@ static void sms_log(sms_t * h, char status)
|
||||
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)),
|
||||
isodate(time(NULL), 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);
|
||||
@@ -760,7 +762,7 @@ static void sms_readfile(sms_t * h, char *fn)
|
||||
h->rx = h->udl = *h->oa = *h->da = h->pid = h->srr = h->udhi = h->rp = h->vp = h->udhl = 0;
|
||||
h->mr = -1;
|
||||
h->dcs = 0xF1; /* normal messages class 1 */
|
||||
h->scts = time (0);
|
||||
h->scts = time(NULL);
|
||||
s = fopen(fn, "r");
|
||||
if (s) {
|
||||
if (unlink(fn)) { /* concurrent access, we lost */
|
||||
@@ -916,7 +918,7 @@ static void sms_writefile(sms_t * h)
|
||||
char buf[30];
|
||||
FILE *o;
|
||||
|
||||
snprintf(fn, sizeof(fn), "%s/%s", spool_dir, h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
|
||||
snprintf(fn, sizeof(fn), "%s/sms/%s", ast_config_AST_SPOOL_DIR, h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
|
||||
ast_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++);
|
||||
@@ -1021,7 +1023,7 @@ static unsigned char sms_handleincoming (sms_t * h)
|
||||
h->udhi = ((h->imsg[2] & 0x40) ? 1 : 0);
|
||||
h->rp = ((h->imsg[2] & 0x80) ? 1 : 0);
|
||||
ast_copy_string(h->oa, h->cli, sizeof(h->oa));
|
||||
h->scts = time (0);
|
||||
h->scts = time(NULL);
|
||||
h->mr = h->imsg[p++];
|
||||
p += unpackaddress(h->da, h->imsg + p);
|
||||
h->pid = h->imsg[p++];
|
||||
@@ -1109,7 +1111,7 @@ static void putdummydata_proto2 (sms_t *h)
|
||||
|
||||
static void sms_compose2(sms_t *h, int more)
|
||||
{
|
||||
struct tm *tm;
|
||||
struct tm tm;
|
||||
char stm[9];
|
||||
|
||||
h->omsg[0] = 0x00; /* set later... */
|
||||
@@ -1117,9 +1119,9 @@ static void sms_compose2(sms_t *h, int more)
|
||||
putdummydata_proto2(h);
|
||||
if (h->smsc) { /* deliver */
|
||||
h->omsg[0] = 0x11; /* SMS_DELIVERY */
|
||||
// Required: 10 11 12 13 14 15 17 (seems they must be ordered!)
|
||||
tm=localtime(&h->scts);
|
||||
sprintf (stm, "%02d%02d%02d%02d", tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min); // Date mmddHHMM
|
||||
/* Required: 10 11 12 13 14 15 17 (seems they must be ordered!) */
|
||||
ast_localtime(&h->scts, &tm, NULL);
|
||||
sprintf(stm, "%02d%02d%02d%02d", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min); /* Date mmddHHMM */
|
||||
adddata_proto2(h, 0x14, stm, 8); /* Date */
|
||||
if (*h->oa == 0)
|
||||
strcpy(h->oa, "00000000");
|
||||
@@ -1127,7 +1129,7 @@ static void sms_compose2(sms_t *h, int more)
|
||||
adddata_proto2(h, 0x17, "\1", 1); /* Calling Terminal ID */
|
||||
} else { /* submit */
|
||||
h->omsg[0] = 0x10; /* SMS_SUBMIT */
|
||||
// Required: 10 11 12 13 17 18 1B 1C (seems they must be ordered!)
|
||||
/* Required: 10 11 12 13 17 18 1B 1C (seems they must be ordered!) */
|
||||
adddata_proto2(h, 0x17, "\1", 1); /* Calling Terminal ID */
|
||||
if (*h->da == 0)
|
||||
strcpy(h->da, "00000000");
|
||||
@@ -1156,14 +1158,14 @@ static int sms_handleincoming_proto2(sms_t * h)
|
||||
{
|
||||
int f, i, sz = 0;
|
||||
int msg, msgsz;
|
||||
struct tm *tm;
|
||||
struct tm tm;
|
||||
char debug_buf[MAX_DEBUG_LEN * 3 + 1];
|
||||
|
||||
sz = h->imsg[1] + 2;
|
||||
/* ast_verbose(VERBOSE_PREFIX_3 "SMS-P2 Frame: %s\n", sms_hexdump(h->imsg, sz, debug_buf)); */
|
||||
|
||||
/* Parse message body (called payload) */
|
||||
h->scts = time (0);
|
||||
h->scts = time(NULL);
|
||||
for (f = 4; f < sz; ) {
|
||||
msg = h->imsg[f++];
|
||||
msgsz = h->imsg[f++];
|
||||
@@ -1179,16 +1181,16 @@ static int sms_handleincoming_proto2(sms_t * h)
|
||||
h->udl = msgsz;
|
||||
break;
|
||||
case 0x14: /* Date SCTS */
|
||||
h->scts = time (0);
|
||||
tm = localtime (&h->scts);
|
||||
tm->tm_mon = ( (h->imsg[f]*10) + h->imsg[f+1] ) - 1;
|
||||
tm->tm_mday = ( (h->imsg[f+2]*10) + h->imsg[f+3] );
|
||||
tm->tm_hour = ( (h->imsg[f+4]*10) + h->imsg[f+5] );
|
||||
tm->tm_min = ( (h->imsg[f+6]*10) + h->imsg[f+7] );
|
||||
tm->tm_sec = 0;
|
||||
h->scts = mktime (tm);
|
||||
h->scts = time(NULL);
|
||||
ast_localtime(&h->scts, &tm, NULL);
|
||||
tm.tm_mon = ( (h->imsg[f] * 10) + h->imsg[f + 1] ) - 1;
|
||||
tm.tm_mday = ( (h->imsg[f + 2] * 10) + h->imsg[f + 3] );
|
||||
tm.tm_hour = ( (h->imsg[f + 4] * 10) + h->imsg[f + 5] );
|
||||
tm.tm_min = ( (h->imsg[f + 6] * 10) + h->imsg[f + 7] );
|
||||
tm.tm_sec = 0;
|
||||
h->scts = mktime(&tm);
|
||||
if (option_verbose > 2)
|
||||
ast_verbose (VERBOSE_PREFIX_3 "SMS-P2 Date#%02X=%02d/%02d %02d:%02d\n", msg, tm->tm_mday, tm->tm_mon+1, tm->tm_hour, tm->tm_min);
|
||||
ast_verbose(VERBOSE_PREFIX_3 "SMS-P2 Date#%02X=%02d/%02d %02d:%02d\n", msg, tm.tm_mday, tm.tm_mon + 1, tm.tm_hour, tm.tm_min);
|
||||
break;
|
||||
case 0x15: /* Calling line (from SMSC) */
|
||||
if (msgsz >= 20)
|
||||
@@ -1243,7 +1245,7 @@ static void sms_messagerx2(sms_t * h)
|
||||
switch (p) {
|
||||
case DLL2_SMS_EST: /* Protocol 2: Connection ready (fake): send message */
|
||||
sms_nextoutgoing (h);
|
||||
//smssend(h,"11 29 27 00 10 01 00 00 11 06 00 00 00 00 00 00 00 12 03 00 02 00 04 13 01 00 41 14 08 00 30 39 31 35 30 02 30 02 15 02 00 39 30 ");
|
||||
/* smssend(h,"11 29 27 00 10 01 00 00 11 06 00 00 00 00 00 00 00 12 03 00 02 00 04 13 01 00 41 14 08 00 30 39 31 35 30 02 30 02 15 02 00 39 30 "); */
|
||||
break;
|
||||
|
||||
case DLL2_SMS_INFO_MO: /* transport SMS_SUBMIT */
|
||||
@@ -1338,7 +1340,7 @@ static void sms_nextoutgoing (sms_t * h)
|
||||
|
||||
*h->da = *h->oa = '\0'; /* clear destinations */
|
||||
h->rx = 0; /* outgoing message */
|
||||
snprintf(fn, sizeof(fn), "%s/%s", spool_dir, h->smsc ? "mttx" : "motx");
|
||||
snprintf(fn, sizeof(fn), "%s/sms/%s", ast_config_AST_SPOOL_DIR, h->smsc ? "mttx" : "motx");
|
||||
ast_mkdir(fn, 0777); /* ensure it exists */
|
||||
d = opendir(fn);
|
||||
if (d) {
|
||||
@@ -1825,7 +1827,7 @@ static int sms_exec (struct ast_channel *chan, void *data)
|
||||
|
||||
/* submitting a message, not taking call. */
|
||||
/* deprecated, use smsq instead */
|
||||
h.scts = time (0);
|
||||
h.scts = time(NULL);
|
||||
if (ast_strlen_zero(sms_args.addr) || strlen(sms_args.addr) >= sizeof(h.oa)) {
|
||||
ast_log(LOG_ERROR, "Address too long %s\n", sms_args.addr);
|
||||
goto done;
|
||||
@@ -1942,7 +1944,6 @@ static int load_module(void)
|
||||
wavea[p] = AST_LIN2A (wave[p]);
|
||||
#endif
|
||||
snprintf(log_file, sizeof(log_file), "%s/sms", ast_config_AST_LOG_DIR);
|
||||
snprintf (spool_dir, sizeof (spool_dir), "%s/sms", ast_config_AST_SPOOL_DIR);
|
||||
return ast_register_application(app, sms_exec, synopsis, descrip);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user