aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-03-31 03:19:34 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-03-31 03:19:34 +0000
commitd53be73ebe9f97b545594f1c2db16926aaddf524 (patch)
tree06b9e7ecdef28acd64e8fe5614020f23b743687f
parente0c466aa42beff5788490914ece124091e8a7da7 (diff)
Eliminate localtime calls, various cleanups
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@723 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xapps/app_voicemail.c23
-rwxr-xr-xapps/app_zapateller.c13
-rwxr-xr-xcallerid.c8
-rwxr-xr-xcdr/cdr_csv.c6
-rwxr-xr-xcdr/cdr_mysql.c6
-rwxr-xr-xchannels/chan_mgcp.c6
-rwxr-xr-xchannels/chan_phone.c14
-rwxr-xr-xchannels/chan_sip.c12
-rwxr-xr-xlogger.c12
-rwxr-xr-xpbx.c16
-rwxr-xr-xsay.c75
11 files changed, 91 insertions, 100 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 13ddcd8cb..82150d9ee 100755
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -98,10 +98,11 @@ static char *synopsis_vmain =
"Enter voicemail system";
static char *descrip_vmain =
-" VoiceMailMain(): Enters the main voicemail system for the checking of voicemail. The mailbox\n"
-"can be passed as the option, which will stop the voicemail system from prompting the user\n"
-"for the mailbox. If the mailbox is preceeded by 's' then the passsword check will be skipped.\n"
-"Returns -1 if the user hangs up or 0 otherwise.\n";
+" VoiceMailMain(): Enters the main voicemail system for the checking of\n"
+"voicemail. The mailbox can be passed as the option, which will stop the\n"
+"voicemail system from prompting the user for the mailbox. If the mailbox\n"
+"is preceded by 's' then the password check will be skipped. Returns -1 if\n"
+"the user hangs up or 0 otherwise.\n";
/* Leave a message */
static char *app = "VoiceMail";
@@ -332,7 +333,7 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
char fname[256];
char dur[256];
time_t t;
- struct tm *tm;
+ struct tm tm;
char *astattach;
struct ast_config *cfg;
p = popen(SENDMAIL, "w");
@@ -348,8 +349,8 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
}
snprintf(dur, sizeof(dur), "%ld:%02ld", duration / 60, duration % 60);
time(&t);
- tm = localtime(&t);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", tm);
+ localtime_r(&t,&tm);
+ strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
fprintf(p, "Date: %s\n", date);
fprintf(p, "From: Asterisk PBX <%s>\n", who);
fprintf(p, "To: %s <%s>\n", name, email);
@@ -365,7 +366,7 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
fprintf(p, "--%s\n", bound);
}
fprintf(p, "Content-Type: TEXT/PLAIN; charset=US-ASCII\n\n");
- strftime(date, sizeof(date), "%A, %B %d, %Y at %r", tm);
+ strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
fprintf(p, "Dear %s:\n\n\tJust wanted to let you know you were just left a %s long message (number %d)\n"
"in mailbox %s from %s, on %s so you might\n"
@@ -392,11 +393,11 @@ static int sendmail(char *srcemail, char *email, char *name, int msgnum, char *m
static int get_date(char *s, int len)
{
- struct tm *tm;
+ struct tm tm;
time_t t;
t = time(0);
- tm = localtime(&t);
- return strftime(s, len, "%a %b %e %r %Z %Y", tm);
+ localtime_r(&t,&tm);
+ return strftime(s, len, "%a %b %e %r %Z %Y", &tm);
}
static int invent_message(struct ast_channel *chan, char *ext, int busy, char *ecodes)
diff --git a/apps/app_zapateller.c b/apps/app_zapateller.c
index 55de6bf31..497bd3a05 100755
--- a/apps/app_zapateller.c
+++ b/apps/app_zapateller.c
@@ -29,12 +29,13 @@ static char *app = "Zapateller";
static char *synopsis = "Block telemarketers with SIT";
static char *descrip =
-" Zapateller(options): Generates special information tone to block telemarketers\n"
-"from calling you. Returns 0 normally or -1 on hangup. Options is a pipe-delimited\n"
-"list of options. The following options are available: 'answer' causes the line to\n"
-"be answered before playing the tone, 'nocallerid' causes Zapateller to only play\n"
-"the tone if there is no callerid information available. Options should be\n"
-"seperated by | characters.\n";
+" Zapateller(options): Generates special information tone to block\n"
+"telemarketers from calling you. Returns 0 normally or -1 on hangup.\n"
+"Options is a pipe-delimited list of options. The following options\n"
+"are available: 'answer' causes the line to be answered before playing\n"
+"the tone, 'nocallerid' causes Zapateller to only play the tone if there\n"
+"is no callerid information available. Options should be separated by |\n"
+"characters\n";
STANDARD_LOCAL_USER;
diff --git a/callerid.c b/callerid.c
index f1827b76b..d1a8545f4 100755
--- a/callerid.c
+++ b/callerid.c
@@ -324,19 +324,19 @@ void callerid_free(struct callerid_state *cid)
static int callerid_genmsg(char *msg, int size, char *number, char *name, int flags)
{
time_t t;
- struct tm *tm;
+ struct tm tm;
char *ptr;
int res;
int i,x;
/* Get the time */
time(&t);
- tm = localtime(&t);
+ localtime_r(&t,&tm);
ptr = msg;
/* Format time and message header */
- res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm->tm_mon + 1,
- tm->tm_mday, tm->tm_hour, tm->tm_min);
+ res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm.tm_mon + 1,
+ tm.tm_mday, tm.tm_hour, tm.tm_min);
size -= res;
ptr += res;
if (!number || !strlen(number) || (flags & CID_UNKNOWN_NUMBER)) {
diff --git a/cdr/cdr_csv.c b/cdr/cdr_csv.c
index da7b07edc..17170a990 100755
--- a/cdr/cdr_csv.c
+++ b/cdr/cdr_csv.c
@@ -107,7 +107,7 @@ static int append_int(char *buf, int s, int len)
static int append_date(char *buf, struct timeval tv, int len)
{
char tmp[80];
- struct tm *tm;
+ struct tm tm;
time_t t;
t = tv.tv_sec;
if (strlen(buf) > len - 3)
@@ -116,8 +116,8 @@ static int append_date(char *buf, struct timeval tv, int len)
strncat(buf, ",", len);
return 0;
}
- tm = localtime(&t);
- strftime(tmp, sizeof(tmp), DATE_FORMAT, tm);
+ localtime_r(&t,&tm);
+ strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
return append_string(buf, tmp, len);
}
diff --git a/cdr/cdr_mysql.c b/cdr/cdr_mysql.c
index 137febb46..f28562998 100755
--- a/cdr/cdr_mysql.c
+++ b/cdr/cdr_mysql.c
@@ -38,7 +38,7 @@ static MYSQL *mysql;
static int mysql_log(struct ast_cdr *cdr)
{
- struct tm *tm;
+ struct tm tm;
struct timeval tv;
struct timezone tz;
char *sqlcmd, timestr[128];
@@ -51,8 +51,8 @@ static int mysql_log(struct ast_cdr *cdr)
gettimeofday(&tv,&tz);
t = tv.tv_sec;
- tm = localtime(&t);
- strftime(timestr,128,DATE_FORMAT,tm);
+ localtime_r(&t,&tm);
+ strftime(timestr,128,DATE_FORMAT,&tm);
ast_log(LOG_DEBUG,"cdr_mysql: inserting a CDR record.\n");
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index fdf6e1dba..09cdfabb0 100755
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -1223,10 +1223,10 @@ static int transmit_notify_request_with_callerid(struct mgcp_endpoint *p, char *
char tone2[256];
char *l, *n;
time_t t;
- struct tm *tm;
+ struct tm tm;
time(&t);
- tm = localtime(&t);
+ localtime_r(&t,&tm);
if (callerid)
strncpy(cid, callerid, sizeof(cid) - 1);
else
@@ -1244,7 +1244,7 @@ static int transmit_notify_request_with_callerid(struct mgcp_endpoint *p, char *
if (!l)
l = "";
snprintf(tone2, sizeof(tone2), "%s,L/ci(%02d/%02d/%02d/%02d,%s,%s)", tone,
- tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, l, n);
+ tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, l, n);
strncpy(p->curtone, tone, sizeof(p->curtone) - 1);
reqprep(&resp, p, "RQNT");
add_header(&resp, "X", p->txident);
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index b8ce778f9..b0a54443a 100755
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -146,18 +146,18 @@ static int phone_call(struct ast_channel *ast, char *dest, int timeout)
PHONE_CID cid;
time_t UtcTime;
- struct tm *t;
+ struct tm tm;
if (ast->callerid) {
time(&UtcTime);
- t = localtime(&UtcTime);
+ localtime_r(&UtcTime,&tm);
- if(t != NULL) {
- sprintf(cid.month, "%02d",(t->tm_mon + 1));
- sprintf(cid.day, "%02d", t->tm_mday);
- sprintf(cid.hour, "%02d", t->tm_hour);
- sprintf(cid.min, "%02d", t->tm_min);
+ if(&tm != NULL) {
+ sprintf(cid.month, "%02d",(tm.tm_mon + 1));
+ sprintf(cid.day, "%02d", tm.tm_mday);
+ sprintf(cid.hour, "%02d", tm.tm_hour);
+ sprintf(cid.min, "%02d", tm.tm_min);
}
strcpy(cid.name, "Unknown");
sprintf(cid.number,"%s",ast->callerid);
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 2d6ddcd98..e1322a4d6 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -747,16 +747,8 @@ static void sip_destroy(struct sip_pvt *p)
/* Interface lookup code courtesy Tilghman of DrunkCoder.com. Thanks! */
struct my_ifreq {
- union
- {
char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */
- } ifr_ifrn;
-
- union
- {
struct sockaddr_in ifru_addr;
- char ifru_data[512];
- } ifr_ifru;
};
struct in_addr *lookup_iface(char *iface) {
@@ -764,7 +756,7 @@ struct in_addr *lookup_iface(char *iface) {
int res;
static struct my_ifreq ifreq;
memset(&ifreq, 0, sizeof(ifreq));
- strncpy(ifreq.ifr_ifrn.ifrn_name,iface,sizeof(ifreq.ifr_ifrn.ifrn_name) - 1);
+ strncpy(ifreq.ifrn_name,iface,sizeof(ifreq.ifrn_name) - 1);
mysock = socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);
res = ioctl(mysock,SIOCGIFADDR,&ifreq);
@@ -774,7 +766,7 @@ struct in_addr *lookup_iface(char *iface) {
ast_log(LOG_WARNING, "Unable to get IP of %s: %s\n", iface, strerror(errno));
return &__ourip;
}
- return( (struct in_addr *) &ifreq.ifr_ifru.ifru_addr.sin_addr );
+ return( (struct in_addr *) &ifreq.ifru_addr.sin_addr );
}
static struct in_addr *myaddrfor(struct in_addr *them)
diff --git a/logger.c b/logger.c
index fac8dc13b..66375de27 100755
--- a/logger.c
+++ b/logger.c
@@ -228,7 +228,7 @@ extern void ast_log(int level, const char *file, int line, const char *function,
char tmp4[80];
char linestr[80];
time_t t;
- struct tm *tm;
+ struct tm tm;
struct logfile *f;
va_list ap;
@@ -238,10 +238,10 @@ extern void ast_log(int level, const char *file, int line, const char *function,
ast_pthread_mutex_lock(&loglock);
if (level == 1 /* Event */) {
time(&t);
- tm = localtime(&t);
- if (tm) {
+ localtime_r(&t,&tm);
+ if (&tm) {
/* Log events into the event log file, with a different format */
- strftime(date, sizeof(date), "%b %e %T", tm);
+ strftime(date, sizeof(date), "%b %e %T", &tm);
fprintf(eventlog, "%s asterisk[%d]: ", date, getpid());
va_start(ap, fmt);
vfprintf(eventlog, fmt, ap);
@@ -258,8 +258,8 @@ extern void ast_log(int level, const char *file, int line, const char *function,
if (f->logflags & (1 << level) && f->f) {
if ((f->f != stdout) && (f->f != stderr)) {
time(&t);
- tm = localtime(&t);
- strftime(date, sizeof(date), "%b %e %T", tm);
+ localtime_r(&t,&tm);
+ strftime(date, sizeof(date), "%b %e %T", &tm);
fprintf(f->f, "%s %s[%ld]: File %s, Line %d (%s): ", date, levels[level], pthread_self(), file, line, function);
} else {
sprintf(linestr, "%d", line);
diff --git a/pbx.c b/pbx.c
index 655f9bd7d..718fec531 100755
--- a/pbx.c
+++ b/pbx.c
@@ -406,40 +406,40 @@ static struct ast_switch *pbx_findswitch(char *sw)
static inline int include_valid(struct ast_include *i)
{
- struct tm *tm;
+ struct tm tm;
time_t t;
if (!i->hastime)
return 1;
time(&t);
- tm = localtime(&t);
- if (!tm) {
+ localtime_r(&t,&tm);
+ if (!&tm) {
ast_log(LOG_WARNING, "Failed to get local time\n");
return 0;
}
/* If it's not the right month, return */
- if (!(i->monthmask & (1 << tm->tm_mon))) {
+ if (!(i->monthmask & (1 << tm.tm_mon))) {
return 0;
}
/* If it's not that time of the month.... */
/* Warning, tm_mday has range 1..31! */
- if (!(i->daymask & (1 << (tm->tm_mday-1))))
+ if (!(i->daymask & (1 << (tm.tm_mday-1))))
return 0;
/* If it's not the right day of the week */
- if (!(i->dowmask & (1 << tm->tm_wday)))
+ if (!(i->dowmask & (1 << tm.tm_wday)))
return 0;
/* Sanity check the hour just to be safe */
- if ((tm->tm_hour < 0) || (tm->tm_hour > 23)) {
+ if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
ast_log(LOG_WARNING, "Insane time...\n");
return 0;
}
/* Now the tough part, we calculate if it fits
in the right time based on min/hour */
- if (!(i->minmask[tm->tm_hour] & (1 << (tm->tm_min / 2))))
+ if (!(i->minmask[tm.tm_hour] & (1 << (tm.tm_min / 2))))
return 0;
/* If we got this far, then we're good */
diff --git a/say.c b/say.c
index cee2b4e55..fec0812a5 100755
--- a/say.c
+++ b/say.c
@@ -191,47 +191,47 @@ int ast_say_number(struct ast_channel *chan, int num, char *ints, char *language
}
int ast_say_date(struct ast_channel *chan, time_t t, char *ints, char *lang)
{
- struct tm *tm;
+ struct tm tm;
char fn[256];
int res = 0;
- tm = localtime(&t);
- if (!tm) {
+ localtime_r(&t,&tm);
+ if (!&tm) {
ast_log(LOG_WARNING, "Unable to derive local time\n");
return -1;
}
if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm->tm_wday);
+ snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm->tm_mon);
+ snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
- res = ast_say_number(chan, tm->tm_mday, ints, lang);
+ res = ast_say_number(chan, tm.tm_mday, ints, lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
- res = ast_say_number(chan, tm->tm_year + 1900, ints, lang);
+ res = ast_say_number(chan, tm.tm_year + 1900, ints, lang);
return res;
}
int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang)
{
- struct tm *tm;
+ struct tm tm;
int res = 0;
int hour, pm=0;
- tm = localtime(&t);
- if (!tm) {
+ localtime_r(&t,&tm);
+ if (!&tm) {
ast_log(LOG_WARNING, "Unable to derive local time\n");
return -1;
}
- hour = tm->tm_hour;
+ hour = tm.tm_hour;
if (!hour)
hour = 12;
else if (hour == 12)
@@ -243,16 +243,16 @@ int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang)
if (!res)
res = ast_say_number(chan, hour, ints, lang);
- if (tm->tm_min > 9) {
+ if (tm.tm_min > 9) {
if (!res)
- res = ast_say_number(chan, tm->tm_min, ints, lang);
- } else if (tm->tm_min) {
+ res = ast_say_number(chan, tm.tm_min, ints, lang);
+ } else if (tm.tm_min) {
if (!res)
res = ast_streamfile(chan, "digits/oh", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
- res = ast_say_number(chan, tm->tm_min, ints, lang);
+ res = ast_say_number(chan, tm.tm_min, ints, lang);
} else {
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
@@ -273,31 +273,31 @@ int ast_say_time(struct ast_channel *chan, time_t t, char *ints, char *lang)
int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang)
{
- struct tm *tm;
+ struct tm tm;
char fn[256];
int res = 0;
int hour, pm=0;
- tm = localtime(&t);
- if (!tm) {
+ localtime_r(&t,&tm);
+ if (!&tm) {
ast_log(LOG_WARNING, "Unable to derive local time\n");
return -1;
}
if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm->tm_wday);
+ snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm->tm_mon);
+ snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
- res = ast_say_number(chan, tm->tm_mday, ints, lang);
+ res = ast_say_number(chan, tm.tm_mday, ints, lang);
- hour = tm->tm_hour;
+ hour = tm.tm_hour;
if (!hour)
hour = 12;
else if (hour == 12)
@@ -309,16 +309,16 @@ int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang)
if (!res)
res = ast_say_number(chan, hour, ints, lang);
- if (tm->tm_min > 9) {
+ if (tm.tm_min > 9) {
if (!res)
- res = ast_say_number(chan, tm->tm_min, ints, lang);
- } else if (tm->tm_min) {
+ res = ast_say_number(chan, tm.tm_min, ints, lang);
+ } else if (tm.tm_min) {
if (!res)
res = ast_streamfile(chan, "digits/oh", lang);
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
- res = ast_say_number(chan, tm->tm_min, ints, lang);
+ res = ast_say_number(chan, tm.tm_min, ints, lang);
} else {
if (!res)
res = ast_streamfile(chan, "digits/oclock", lang);
@@ -335,7 +335,7 @@ int ast_say_datetime(struct ast_channel *chan, time_t t, char *ints, char *lang)
if (!res)
res = ast_waitstream(chan, ints);
if (!res)
- res = ast_say_number(chan, tm->tm_year + 1900, ints, lang);
+ res = ast_say_number(chan, tm.tm_year + 1900, ints, lang);
return res;
}
@@ -344,37 +344,34 @@ int ast_say_datetime_from_now(struct ast_channel *chan, time_t t, char *ints, ch
int res=0;
time_t nowt;
int daydiff;
- struct tm *tm;
- struct tm tm2;
- struct tm *now;
+ struct tm tm;
+ struct tm now;
char fn[256];
time(&nowt);
- tm = localtime(&t);
- if (!tm) {
+ localtime_r(&t,&tm);
+ if (!&tm) {
ast_log(LOG_WARNING, "Unable to derive local time\n");
return -1;
}
- memcpy(&tm2, tm, sizeof(struct tm));
- tm = &tm2;
- now = localtime(&nowt);
- daydiff = now->tm_yday - tm->tm_yday;
+ localtime_r(&nowt,&now);
+ daydiff = now.tm_yday - tm.tm_yday;
if ((daydiff < 0) || (daydiff > 6)) {
/* Day of month and month */
if (!res) {
- snprintf(fn, sizeof(fn), "digits/mon-%d", tm->tm_mon);
+ snprintf(fn, sizeof(fn), "digits/mon-%d", tm.tm_mon);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);
}
if (!res)
- res = ast_say_number(chan, tm->tm_mday, ints, lang);
+ res = ast_say_number(chan, tm.tm_mday, ints, lang);
} else if (daydiff) {
/* Just what day of the week */
if (!res) {
- snprintf(fn, sizeof(fn), "digits/day-%d", tm->tm_wday);
+ snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday);
res = ast_streamfile(chan, fn, lang);
if (!res)
res = ast_waitstream(chan, ints);