[asterisk-commits] rizzo: trunk r48832 - /trunk/apps/app_sms.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Dec 21 15:15:04 MST 2006


Author: rizzo
Date: Thu Dec 21 16:15:03 2006
New Revision: 48832

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48832
Log:
make isodate thread-safe


Modified:
    trunk/apps/app_sms.c

Modified: trunk/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_sms.c?view=diff&rev=48832&r1=48831&r2=48832
==============================================================================
--- trunk/apps/app_sms.c (original)
+++ trunk/apps/app_sms.c Thu Dec 21 16:15:03 2006
@@ -264,7 +264,7 @@
 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++;
@@ -277,14 +277,13 @@
 }
 
 /*! \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)
@@ -708,12 +707,14 @@
 		int 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)), 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 : "-");
 			p = line + strlen (line);
 			for (n = 0; n < h->udl; n++)
@@ -902,13 +903,15 @@
 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++);
+	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) {
@@ -963,8 +966,10 @@
 				}
 			}
 		}
-		if (h->scts)
-			fprintf (o, "scts=%s\n", isodate (h->scts));
+		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)
@@ -1926,11 +1931,9 @@
 static int load_module(void)
 {
 #ifdef OUTALAW
-	{
-		int p;
-		for (p = 0; p < 80; p++)
-			wavea[p] = AST_LIN2A (wave[p]);
-	}
+	int p;
+	for (p = 0; p < 80; p++)
+		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);



More information about the asterisk-commits mailing list