make isodate thread-safe

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48832 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo
2006-12-21 22:15:03 +00:00
parent 99359a4b27
commit 250c74d10c

View File

@@ -264,7 +264,7 @@ typedef struct sms_s {
static void sms_messagetx (sms_t * h); static void sms_messagetx (sms_t * h);
/*! \brief copy number, skipping non digits apart from leading + */ /*! \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 == '+') if (*s == '+')
*d++ = *s++; *d++ = *s++;
@@ -277,14 +277,13 @@ static void numcpy (char *d, char *s)
} }
/*! \brief static, return a date/time in ISO format */ /*! \brief static, return a date/time in ISO format */
static char * isodate (time_t t) static char * isodate(time_t t, char *buf, int len)
{ {
static char date[20]; strftime(buf, len, "%Y-%m-%dT%H:%M:%S", localtime (&t));
strftime (date, sizeof (date), "%Y-%m-%dT%H:%M:%S", localtime (&t)); return buf;
return date;
} }
/*! \brief reads next UCS character from null terminated UTF-8 string and advanced pointer */ /*! \brief Reads next UCS character from NUL terminated UTF-8 string and advance pointer */
/* for non valid UTF-8 sequences, returns character as is */ /* for non valid UTF-8 sequences, returns character as is */
/* Does not advance pointer for null termination */ /* Does not advance pointer for null termination */
static long utf8decode (unsigned char **pp) static long utf8decode (unsigned char **pp)
@@ -708,12 +707,14 @@ static void sms_log (sms_t * h, char status)
int o = open (log_file, O_CREAT | O_APPEND | O_WRONLY, AST_FILE_MODE); int o = open (log_file, O_CREAT | O_APPEND | O_WRONLY, AST_FILE_MODE);
if (o >= 0) { if (o >= 0) {
char line[1000], mrs[3] = "", *p; char line[1000], mrs[3] = "", *p;
char buf[30];
unsigned char n; unsigned char n;
if (h->mr >= 0) if (h->mr >= 0)
snprintf (mrs, sizeof (mrs), "%02X", h->mr); snprintf (mrs, sizeof (mrs), "%02X", h->mr);
snprintf (line, sizeof (line), "%s %c%c%c%s %s %s %s ", 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 : "-", isodate(time(0), buf, sizeof(buf)),
status, h->rx ? 'I' : 'O', h->smsc ? 'S' : 'M', mrs, h->queue, *h->oa ? h->oa : "-",
*h->da ? h->da : "-"); *h->da ? h->da : "-");
p = line + strlen (line); p = line + strlen (line);
for (n = 0; n < h->udl; n++) for (n = 0; n < h->udl; n++)
@@ -902,13 +903,15 @@ static void sms_readfile (sms_t * h, char *fn)
static void sms_writefile (sms_t * h) static void sms_writefile (sms_t * h)
{ {
char fn[200] = "", fn2[200] = ""; char fn[200] = "", fn2[200] = "";
char buf[30];
FILE *o; FILE *o;
ast_copy_string (fn, spool_dir, sizeof (fn)); ast_copy_string (fn, spool_dir, sizeof (fn));
mkdir (fn, 0777); /* ensure it exists */ 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"); 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 */ mkdir (fn, 0777); /* ensure it exists */
ast_copy_string (fn2, fn, sizeof (fn2)); ast_copy_string (fn2, fn, sizeof (fn2));
snprintf (fn2 + strlen (fn2), sizeof (fn2) - strlen (fn2), "/%s.%s-%d", h->queue, isodate (h->scts), seq++); 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); snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/.%s", fn2 + strlen (fn) + 1);
o = fopen (fn, "w"); o = fopen (fn, "w");
if (o) { if (o) {
@@ -963,8 +966,10 @@ static void sms_writefile (sms_t * h)
} }
} }
} }
if (h->scts) if (h->scts) {
fprintf (o, "scts=%s\n", isodate (h->scts)); char buf[30];
fprintf (o, "scts=%s\n", isodate(h->scts, buf, sizeof(buf)));
}
if (h->pid) if (h->pid)
fprintf (o, "pid=%d\n", h->pid); fprintf (o, "pid=%d\n", h->pid);
if (h->dcs != 0xF1) if (h->dcs != 0xF1)
@@ -1926,11 +1931,9 @@ static int unload_module(void)
static int load_module(void) static int load_module(void)
{ {
#ifdef OUTALAW #ifdef OUTALAW
{ int p;
int p; for (p = 0; p < 80; p++)
for (p = 0; p < 80; p++) wavea[p] = AST_LIN2A (wave[p]);
wavea[p] = AST_LIN2A (wave[p]);
}
#endif #endif
snprintf (log_file, sizeof (log_file), "%s/sms", ast_config_AST_LOG_DIR); 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); snprintf (spool_dir, sizeof (spool_dir), "%s/sms", ast_config_AST_SPOOL_DIR);