diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2007-07-18 19:47:20 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2007-07-18 19:47:20 +0000 |
commit | 81bc1d7af5886089bcd065382476f202ad7cc9ea (patch) | |
tree | 540f82bac3e6105b6fc34cd4b4613c1756a7512b /apps | |
parent | b96fde308cd75eb17e5fdb0ea6d54c0f1f593ff9 (diff) |
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75706 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps')
-rw-r--r-- | apps/app_alarmreceiver.c | 8 | ||||
-rw-r--r-- | apps/app_minivm.c | 42 | ||||
-rw-r--r-- | apps/app_playback.c | 5 | ||||
-rw-r--r-- | apps/app_rpt.c | 9 | ||||
-rw-r--r-- | apps/app_sms.c | 28 | ||||
-rw-r--r-- | apps/app_voicemail.c | 26 |
6 files changed, 60 insertions, 58 deletions
diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c index 1c759cd42..14f417dcb 100644 --- a/apps/app_alarmreceiver.c +++ b/apps/app_alarmreceiver.c @@ -306,8 +306,8 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan) { int res = 0; - time_t t; - struct tm now; + struct timeval t; + struct ast_tm now; char *cl,*cn; char workstring[80]; char timestamp[80]; @@ -324,12 +324,12 @@ static int write_metadata( FILE *logfile, char *signalling_type, struct ast_chan /* Get the current time */ - time(&t); + t = ast_tvnow(); ast_localtime(&t, &now, NULL); /* Format the time */ - strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); + ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); res = fprintf(logfile, "\n\n[metadata]\n\n"); diff --git a/apps/app_minivm.c b/apps/app_minivm.c index 24ebd0cb9..f5dee8b07 100644 --- a/apps/app_minivm.c +++ b/apps/app_minivm.c @@ -425,9 +425,9 @@ struct minivm_stats { int timezones; /*!< Number of time zones */ int templates; /*!< Number of templates */ - time_t reset; /*!< Time for last reset */ + struct timeval reset; /*!< Time for last reset */ int receivedmessages; /*!< Number of received messages since reset */ - time_t lastreceived; /*!< Time for last voicemail sent */ + struct timeval lastreceived; /*!< Time for last voicemail sent */ }; /*! \brief Statistics for voicemail */ @@ -713,12 +713,11 @@ static int base_encode(char *filename, FILE *so) static int get_date(char *s, int len) { - struct tm tm; - time_t t; + struct ast_tm tm; + struct timeval tv = ast_tvnow(); - t = time(0); - ast_localtime(&t, &tm, NULL); - return strftime(s, len, "%a %b %e %r %Z %Y", &tm); + ast_localtime(&tv, &tm, NULL); + return ast_strftime(s, len, "%a %b %e %r %Z %Y", &tm); } @@ -898,8 +897,8 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu char dur[PATH_MAX]; char tmp[80] = "/tmp/astmail-XXXXXX"; char tmp2[PATH_MAX]; - time_t now; - struct tm tm; + struct timeval now; + struct ast_tm tm; struct minivm_zone *the_zone = NULL; int len_passdata; struct ast_channel *ast; @@ -986,15 +985,15 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu AST_LIST_UNLOCK(&minivm_zones); } - time(&now); + now = ast_tvnow(); ast_localtime(&now, &tm, the_zone ? the_zone->timezone : NULL); - strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm); + ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm); /* Start printing the email to the temporary file */ fprintf(p, "Date: %s\n", date); /* Set date format for voicemail mail */ - strftime(date, sizeof(date), template->dateformat, &tm); + ast_strftime(date, sizeof(date), template->dateformat, &tm); /* Populate channel with channel variables for substitution */ @@ -1550,14 +1549,13 @@ static int leave_voicemail(struct ast_channel *chan, char *username, struct leav if (!txt) { ast_log(LOG_WARNING, "Error opening text file for output\n"); } else { - struct tm tm; - time_t now; + struct ast_tm tm; + struct timeval now = ast_tvnow(); char timebuf[30]; char logbuf[BUFSIZ]; get_date(date, sizeof(date)); - now = time(NULL); ast_localtime(&now, &tm, NULL); - strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm); + ast_strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm); snprintf(logbuf, sizeof(logbuf), /* "Mailbox:domain:macrocontext:exten:priority:callerchan:callerid:origdate:origtime:duration:durationstatus:accountcode" */ @@ -1608,7 +1606,7 @@ static int leave_voicemail(struct ast_channel *chan, char *username, struct leav pbx_builtin_setvar_helper(chan, "MVM_FORMAT", fmt); } - global_stats.lastreceived = time(NULL); + global_stats.lastreceived = ast_tvnow(); global_stats.receivedmessages++; // /* Go ahead and delete audio files from system, they're not needed any more */ // if (ast_fileexists(tmptxtfile, NULL, NULL) <= 0) { @@ -2384,8 +2382,8 @@ static int load_config(void) ast_set2_flag((&globalflags), FALSE, MVM_OPERATOR); strcpy(global_charset, "ISO-8859-1"); /* Reset statistics */ - memset(&global_stats, 0, sizeof(struct minivm_stats)); - global_stats.reset = time(NULL); + memset(&global_stats, 0, sizeof(global_stats)); + global_stats.reset = ast_tvnow(); /* Make sure we could load configuration file */ if (!cfg) { @@ -2651,7 +2649,7 @@ static int handle_minivm_show_settings(int fd, int argc, char *argv[]) /*! \brief Show stats */ static int handle_minivm_show_stats(int fd, int argc, char *argv[]) { - struct tm time; + struct ast_tm time; char buf[BUFSIZ]; ast_cli(fd, "* Mini-Voicemail statistics\n"); @@ -2665,11 +2663,11 @@ static int handle_minivm_show_stats(int fd, int argc, char *argv[]) } else { ast_cli(fd, " Received messages since last reset: %d\n", global_stats.receivedmessages); ast_localtime(&global_stats.lastreceived, &time, NULL); - strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time); + ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time); ast_cli(fd, " Last received voicemail: %s\n", buf); } ast_localtime(&global_stats.reset, &time, NULL); - strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time); + ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time); ast_cli(fd, " Last reset: %s\n", buf); ast_cli(fd, "\n"); diff --git a/apps/app_playback.c b/apps/app_playback.c index a3ff14cde..542382ea8 100644 --- a/apps/app_playback.c +++ b/apps/app_playback.c @@ -281,12 +281,13 @@ static int say_date_generic(struct ast_channel *chan, time_t t, const char *ints, const char *lang, const char *format, const char *timezone, const char *prefix) { char buf[128]; - struct tm tm; + struct ast_tm tm; + struct timeval tv = { t, 0 }; say_args_t a = { chan, ints, lang, -1, -1 }; if (format == NULL) format = ""; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); snprintf(buf, sizeof(buf), "%s:%s:%04d%02d%02d%02d%02d.%02d-%d-%3d", prefix, format, diff --git a/apps/app_rpt.c b/apps/app_rpt.c index 70badd255..c81fbbdb0 100644 --- a/apps/app_rpt.c +++ b/apps/app_rpt.c @@ -587,6 +587,7 @@ static void rpt_mutex_spew(void) int i, j; long long diff; char a[100] = ""; + struct ast_tm tm; struct timeval lasttv; ast_mutex_lock(&locklock); @@ -597,8 +598,8 @@ static void rpt_mutex_spew(void) lasttv.tv_sec = lasttv.tv_usec = 0; for (i = 0; i < 32; i++) { j = (i + lock_ring_index_copy) % 32; - strftime(a, sizeof(a) - 1, "%m/%d/%Y %H:%M:%S", - localtime(&lock_ring_copy[j].tv.tv_sec)); + ast_strftime(a, sizeof(a) - 1, "%m/%d/%Y %H:%M:%S", + ast_localtime(&lock_ring_copy[j].tv, &tm, NULL)); diff = 0; if (lasttv.tv_sec) { diff = (lock_ring_copy[j].tv.tv_sec - lasttv.tv_sec) * 1000000; @@ -1890,7 +1891,7 @@ static void *rpt_tele_thread(void *this) struct ast_channel *mychannel; const char *p, *ct; time_t t; - struct tm localtm; + struct ast_tm localtm; #ifdef APP_RPT_LOCK_DEBUG struct lockthread *t; #endif @@ -5619,7 +5620,7 @@ static void queue_id(struct rpt *myrpt) static void do_scheduler(struct rpt *myrpt) { int res; - struct tm tmnow; + struct ast_tm tmnow; memcpy(&myrpt->lasttv, &myrpt->curtv, sizeof(struct timeval)); diff --git a/apps/app_sms.c b/apps/app_sms.c index 5575945eb..9c645379b 100644 --- a/apps/app_sms.c +++ b/apps/app_sms.c @@ -277,9 +277,10 @@ 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) { - struct tm tm; - ast_localtime(&t, &tm, NULL); - strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm); + struct ast_tm tm; + struct timeval tv = { t, 0 }; + ast_localtime(&tv, &tm, NULL); + ast_strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm); return buf; } @@ -511,10 +512,11 @@ 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; + struct ast_tm t; + struct timeval tv = { w, 0 }; int z; - ast_localtime(&w, &t, NULL); + ast_localtime(&tv, &t, NULL); #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) z = -t.tm_gmtoff / 60 / 15; #else @@ -1113,7 +1115,8 @@ static void putdummydata_proto2(sms_t *h) static void sms_compose2(sms_t *h, int more) { - struct tm tm; + struct ast_tm tm; + struct timeval tv = { h->scts, 0 }; char stm[9]; h->omsg[0] = 0x00; /* set later... */ @@ -1122,7 +1125,7 @@ static void sms_compose2(sms_t *h, int more) if (h->smsc) { /* deliver */ h->omsg[0] = 0x11; /* SMS_DELIVERY */ /* Required: 10 11 12 13 14 15 17 (seems they must be ordered!) */ - ast_localtime(&h->scts, &tm, NULL); + ast_localtime(&tv, &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) @@ -1160,14 +1163,15 @@ static int sms_handleincoming_proto2(sms_t *h) { int f, i, sz = 0; int msg, msgsz; - struct tm tm; + struct ast_tm tm; + struct timeval tv = { 0, 0 }; 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(NULL); + tv.tv_sec = h->scts = time(NULL); for (f = 4; f < sz; ) { msg = h->imsg[f++]; msgsz = h->imsg[f++]; @@ -1183,14 +1187,14 @@ static int sms_handleincoming_proto2(sms_t *h) h->udl = msgsz; break; case 0x14: /* Date SCTS */ - h->scts = time(NULL); - ast_localtime(&h->scts, &tm, NULL); + tv.tv_sec = h->scts = time(NULL); + ast_localtime(&tv, &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); + h->scts = ast_mktime(&tm, NULL); 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); break; diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 4f3fd9968..4c051dc8b 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -1964,10 +1964,10 @@ static char *quote(const char *from, char *to, size_t len) * fill in *tm for current time according to the proper timezone, if any. * Return tm so it can be used as a function argument. */ -static const struct tm *vmu_tm(const struct ast_vm_user *vmu, struct tm *tm) +static const struct ast_tm *vmu_tm(const struct ast_vm_user *vmu, struct ast_tm *tm) { const struct vm_zone *z = NULL; - time_t t = time(NULL); + struct timeval t = ast_tvnow(); /* Does this user have a timezone specified? */ if (!ast_strlen_zero(vmu->zonetag)) { @@ -2007,7 +2007,7 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in char fname[256]; char dur[256]; char tmpcmd[256]; - struct tm tm; + struct ast_tm tm; char *passdata2; size_t len_passdata; char *greeting_attachment; @@ -2029,11 +2029,11 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in *greeting_attachment++ = '\0'; snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60); - strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm)); + ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm)); fprintf(p, "Date: %s" ENDL, date); /* Set date format for voicemail mail */ - strftime(date, sizeof(date), emaildateformat, &tm); + ast_strftime(date, sizeof(date), emaildateformat, &tm); if (!ast_strlen_zero(fromstring)) { struct ast_channel *ast; @@ -2214,7 +2214,7 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char char dur[PATH_MAX]; char tmp[80] = "/tmp/astmail-XXXXXX"; char tmp2[PATH_MAX]; - struct tm tm; + struct ast_tm tm; FILE *p; if ((p = vm_mkftemp(tmp)) == NULL) { @@ -2227,7 +2227,7 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char else snprintf(who, sizeof(who), "%s@%s", srcemail, host); snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60); - strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm)); + ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm)); fprintf(p, "Date: %s\n", date); if (*pagerfromstring) { @@ -2266,7 +2266,7 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char } else fprintf(p, "Subject: New VM\n\n"); - strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm); + ast_strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm); if (pagerbody) { struct ast_channel *ast; if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) { @@ -2293,11 +2293,10 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char static int get_date(char *s, int len) { - struct tm tm; - time_t t; - t = time(0); + struct ast_tm tm; + struct timeval t = ast_tvnow(); ast_localtime(&t, &tm, NULL); - return strftime(s, len, "%a %b %e %r %Z %Y", &tm); + return ast_strftime(s, len, "%a %b %e %r %Z %Y", &tm); } static int invent_message(struct ast_channel *chan, char *context, char *ext, int busy, char *ecodes) @@ -4472,8 +4471,7 @@ static int play_message_datetime(struct ast_channel *chan, struct ast_vm_user *v /* Set the DIFF_* variables */ ast_localtime(&t, &time_now, NULL); tv_now = ast_tvnow(); - tnow = tv_now.tv_sec; - ast_localtime(&tnow, &time_then, NULL); + ast_localtime(&tv_now, &time_then, NULL); /* Day difference */ if (time_now.tm_year == time_then.tm_year) |