summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_agent.c2
-rw-r--r--channels/chan_iax2.c41
-rw-r--r--channels/chan_mgcp.c17
-rw-r--r--channels/chan_phone.c5
-rw-r--r--channels/chan_sip.c12
-rw-r--r--channels/chan_skinny.c22
-rw-r--r--channels/chan_zap.c15
-rw-r--r--channels/iax2-parser.c4
-rw-r--r--channels/misdn/ie.c24
9 files changed, 59 insertions, 83 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index d1231556e..5590567ec 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -1812,7 +1812,7 @@ static int login_exec(struct ast_channel *chan, void *data)
login_state = 1; /* Successful Login */
/* Ensure we can't be gotten until we're done */
- gettimeofday(&p->lastdisc, NULL);
+ p->lastdisc = ast_tvnow();
p->lastdisc.tv_sec++;
/* Set Channel Specific Agent Overrides */
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 2ed8a3692..941695a13 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -1274,7 +1274,7 @@ static int make_trunk(unsigned short callno, int locked)
{
int x;
int res= 0;
- struct timeval now;
+ struct timeval now = ast_tvnow();
if (iaxs[callno]->oseqno) {
ast_log(LOG_WARNING, "Can't make trunk once a call has started!\n");
return -1;
@@ -1283,7 +1283,6 @@ static int make_trunk(unsigned short callno, int locked)
ast_log(LOG_WARNING, "Call %d is already a trunk\n", callno);
return -1;
}
- gettimeofday(&now, NULL);
for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
ast_mutex_lock(&iaxsl[x]);
if (!iaxs[x] && ((now.tv_sec - lastused[x].tv_sec) > MIN_REUSE_TIME)) {
@@ -1369,7 +1368,7 @@ static int find_callno(unsigned short callno, unsigned short dcallno, struct soc
* correct, but it will be changed if needed after authentication. */
if (!iax2_getpeername(*sin, host, sizeof(host), lockpeer))
snprintf(host, sizeof(host), "%s:%d", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
- gettimeofday(&now, NULL);
+ now = ast_tvnow();
for (x=1;x<TRUNK_CALL_START;x++) {
/* Find first unused call number that hasn't been used in a while */
ast_mutex_lock(&iaxsl[x]);
@@ -1872,7 +1871,7 @@ static void iax2_destroy(int callno)
retry:
pvt = iaxs[callno];
- gettimeofday(&lastused[callno], NULL);
+ lastused[callno] = ast_tvnow();
owner = pvt ? pvt->owner : NULL;
@@ -2274,9 +2273,7 @@ static int iax2_show_cache(int fd, int argc, char *argv[])
struct iax2_dpcache *dp = NULL;
char tmp[1024], *pc = NULL;
int s, x, y;
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
+ struct timeval tv = ast_tvnow();
AST_LIST_LOCK(&dpcache);
@@ -2387,7 +2384,7 @@ static void __get_from_jb(void *p)
int ret;
long now;
long next;
- struct timeval tv;
+ struct timeval tv = ast_tvnow();
/* Make sure we have a valid private structure before going on */
ast_mutex_lock(&iaxsl[callno]);
@@ -2400,7 +2397,6 @@ static void __get_from_jb(void *p)
pvt->jbid = -1;
- gettimeofday(&tv,NULL);
/* round up a millisecond since ast_sched_runq does; */
/* prevents us from spinning while waiting for our now */
/* to catch up with runq's now */
@@ -2882,14 +2878,10 @@ static int auto_congest(void *data)
static unsigned int iax2_datetime(const char *tz)
{
- time_t t;
- struct tm tm;
+ struct timeval t = ast_tvnow();
+ struct ast_tm tm;
unsigned int tmp;
- time(&t);
- if (!ast_strlen_zero(tz))
- ast_localtime(&t, &tm, tz);
- else
- ast_localtime(&t, &tm, NULL);
+ ast_localtime(&t, &tm, ast_strlen_zero(tz) ? NULL : tz);
tmp = (tm.tm_sec >> 1) & 0x1f; /* 5 bits of seconds */
tmp |= (tm.tm_min & 0x3f) << 5; /* 6 bits of minutes */
tmp |= (tm.tm_hour & 0x1f) << 11; /* 5 bits of hours */
@@ -3322,7 +3314,7 @@ static enum ast_bridge_result iax2_bridge(struct ast_channel *c0, struct ast_cha
}
if ((iaxs[callno0]->transferring == TRANSFER_RELEASED) && (iaxs[callno1]->transferring == TRANSFER_RELEASED)) {
/* Call has been transferred. We're no longer involved */
- gettimeofday(&tv, NULL);
+ tv = ast_tvnow();
if (ast_tvzero(waittimer)) {
waittimer = tv;
} else if (tv.tv_sec - waittimer.tv_sec > IAX_LINGER_TIMEOUT) {
@@ -3586,7 +3578,7 @@ static unsigned int fix_peerts(struct timeval *tv, int callno, unsigned int ts)
long ms; /* NOT unsigned */
if (ast_tvzero(iaxs[callno]->rxcore)) {
/* Initialize rxcore time if appropriate */
- gettimeofday(&iaxs[callno]->rxcore, NULL);
+ iaxs[callno]->rxcore = ast_tvnow();
/* Round to nearest 20ms so traces look pretty */
iaxs[callno]->rxcore.tv_usec -= iaxs[callno]->rxcore.tv_usec % 20000;
}
@@ -3622,7 +3614,7 @@ static unsigned int calc_timestamp(struct chan_iax2_pvt *p, unsigned int ts, str
}
}
if (ast_tvzero(p->offset)) {
- gettimeofday(&p->offset, NULL);
+ p->offset = ast_tvnow();
/* Round to nearest 20ms for nice looking traces */
p->offset.tv_usec -= p->offset.tv_usec % 20000;
}
@@ -3850,7 +3842,7 @@ static int iax2_trunk_queue(struct chan_iax2_pvt *pvt, struct iax_frame *fr)
/* if we have enough for a full MTU, ship it now without waiting */
if (global_max_trunk_mtu > 0 && tpeer->trunkdatalen + f->datalen + 4 >= global_max_trunk_mtu) {
- gettimeofday(&now, NULL);
+ now = ast_tvnow();
res = send_trunk(tpeer, &now);
trunk_untimed ++;
}
@@ -6243,10 +6235,9 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
#ifdef ZT_TIMERACK
int x = 1;
#endif
- struct timeval now;
+ struct timeval now = ast_tvnow();
if (iaxtrunkdebug)
ast_verbose("Beginning trunk processing. Trunk queue ceiling is %d bytes per host\n", trunkmaxsize);
- gettimeofday(&now, NULL);
if (events & AST_IO_PRI) {
#ifdef ZT_TIMERACK
/* Great, this is a timing interface, just call the ioctl */
@@ -9898,13 +9889,11 @@ static int cache_get_callno_locked(const char *data)
static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *data, const char *context, const char *exten, int priority)
{
struct iax2_dpcache *dp = NULL;
- struct timeval tv;
+ struct timeval tv = ast_tvnow();
int x, com[2], timeout, old = 0, outfd, abort, callno;
struct ast_channel *c = NULL;
struct ast_frame *f = NULL;
- gettimeofday(&tv, NULL);
-
AST_LIST_TRAVERSE_SAFE_BEGIN(&dpcache, dp, cache_list) {
if (ast_tvcmp(tv, dp->expiry) > 0) {
AST_LIST_REMOVE_CURRENT(&dpcache, cache_list);
@@ -9932,7 +9921,7 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
}
ast_copy_string(dp->peercontext, data, sizeof(dp->peercontext));
ast_copy_string(dp->exten, exten, sizeof(dp->exten));
- gettimeofday(&dp->expiry, NULL);
+ dp->expiry = ast_tvnow();
dp->orig = dp->expiry;
/* Expires in 30 mins by default */
dp->expiry.tv_sec += iaxdefaultdpcache;
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index c55f38976..76744cc10 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -736,15 +736,11 @@ static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub
gw->msgs = msg;
}
- if (gettimeofday(&tv, NULL) < 0) {
- /* This shouldn't ever happen, but let's be sure */
- ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
- } else {
- msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS;
+ tv = ast_tvnow();
+ msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS;
- if (gw->retransid == -1)
- gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
- }
+ if (gw->retransid == -1)
+ gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
ast_mutex_unlock(&gw->msgs_lock);
/* SC
if (!gw->messagepending) {
@@ -2232,11 +2228,10 @@ static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, ch
struct mgcp_request resp;
char tone2[256];
char *l, *n;
- time_t t;
- struct tm tm;
+ struct timeval t = ast_tvnow();
+ struct ast_tm tm;
struct mgcp_endpoint *p = sub->parent;
- time(&t);
ast_localtime(&t, &tm, NULL);
n = callername;
l = callernum;
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index 4a4629009..cf68d1d7f 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -293,11 +293,10 @@ static int phone_call(struct ast_channel *ast, char *dest, int timeout)
struct phone_pvt *p;
PHONE_CID cid;
- time_t UtcTime;
- struct tm tm;
+ struct timeval UtcTime = ast_tvnow();
+ struct ast_tm tm;
int start;
- time(&UtcTime);
ast_localtime(&UtcTime, &tm, NULL);
memset(&cid, 0, sizeof(PHONE_CID));
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 83c6e7b36..363b6673a 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1212,7 +1212,7 @@ struct sip_registry {
int refresh; /*!< How often to refresh */
struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration dialog" in progress */
enum sipregistrystate regstate; /*!< Registration state (see above) */
- time_t regtime; /*!< Last successful registration time */
+ struct timeval regtime; /*!< Last successful registration time */
int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
unsigned int ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
struct sockaddr_in us; /*!< Who the server thinks we are */
@@ -11042,7 +11042,7 @@ static int sip_show_registry(int fd, int argc, char *argv[])
#define FORMAT "%-30.30s %-12.12s %8d %-20.20s %-25.25s\n"
char host[80];
char tmpdat[256];
- struct tm tm;
+ struct ast_tm tm;
int counter = 0;
if (argc != 3)
@@ -11051,9 +11051,9 @@ static int sip_show_registry(int fd, int argc, char *argv[])
ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
ASTOBJ_RDLOCK(iterator);
snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);
- if (iterator->regtime) {
+ if (iterator->regtime.tv_sec) {
ast_localtime(&iterator->regtime, &tm, NULL);
- strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
+ ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
} else
tmpdat[0] = '\0';
ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
@@ -12975,7 +12975,7 @@ static int handle_response_register(struct sip_pvt *p, int resp, char *rest, str
}
r->regstate = REG_STATE_REGISTERED;
- r->regtime = time(NULL); /* Reset time of last succesful registration */
+ r->regtime = ast_tvnow(); /* Reset time of last succesful registration */
manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate));
r->regattempts = 0;
ast_debug(1, "Registration successful\n");
@@ -16177,7 +16177,7 @@ static int sip_poke_peer(struct sip_peer *peer)
#else
xmitres = transmit_invite(p, SIP_OPTIONS, 0, 2);
#endif
- gettimeofday(&peer->ps, NULL);
+ peer->ps = ast_tvnow();
if (xmitres == XMIT_ERROR)
sip_poke_noanswer(peer); /* Immediately unreachable, network problems */
else
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index f55002d64..31b5a5844 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -3735,21 +3735,21 @@ static int handle_line_state_req_message(struct skinny_req *req, struct skinnyse
static int handle_time_date_req_message(struct skinny_req *req, struct skinnysession *s)
{
- time_t timer;
- struct tm *cmtime;
+ struct timeval tv = ast_tvnow();
+ struct ast_tm cmtime;
if (!(req = req_alloc(sizeof(struct definetimedate_message), DEFINETIMEDATE_MESSAGE)))
return -1;
- timer = time(NULL);
- cmtime = localtime(&timer);
- req->data.definetimedate.year = htolel(cmtime->tm_year+1900);
- req->data.definetimedate.month = htolel(cmtime->tm_mon+1);
- req->data.definetimedate.dayofweek = htolel(cmtime->tm_wday);
- req->data.definetimedate.day = htolel(cmtime->tm_mday);
- req->data.definetimedate.hour = htolel(cmtime->tm_hour);
- req->data.definetimedate.minute = htolel(cmtime->tm_min);
- req->data.definetimedate.seconds = htolel(cmtime->tm_sec);
+ ast_localtime(&tv, &cmtime, NULL);
+ req->data.definetimedate.year = htolel(cmtime.tm_year+1900);
+ req->data.definetimedate.month = htolel(cmtime.tm_mon+1);
+ req->data.definetimedate.dayofweek = htolel(cmtime.tm_wday);
+ req->data.definetimedate.day = htolel(cmtime.tm_mday);
+ req->data.definetimedate.hour = htolel(cmtime.tm_hour);
+ req->data.definetimedate.minute = htolel(cmtime.tm_min);
+ req->data.definetimedate.seconds = htolel(cmtime.tm_sec);
+ req->data.definetimedate.milliseconds = htolel(cmtime.tm_usec / 1000);
transmit_response(s, req);
return 1;
}
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index c8b4feb76..0e52a7b2d 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -3059,7 +3059,7 @@ static int zt_answer(struct ast_channel *ast)
/* Pick up the line */
ast_debug(1, "Took %s off hook\n", ast->name);
if (p->hanguponpolarityswitch) {
- gettimeofday(&p->polaritydelaytv, NULL);
+ p->polaritydelaytv = ast_tvnow();
}
res = zt_set_hook(p->subs[SUB_REAL].zfd, ZT_OFFHOOK);
tone_zone_play_tone(p->subs[index].zfd, -1);
@@ -4463,7 +4463,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
break;
}
/* Remember last time we got a flash-hook */
- gettimeofday(&p->flashtime, NULL);
+ p->flashtime = ast_tvnow();
switch (mysig) {
case SIG_FXOLS:
case SIG_FXOGS:
@@ -4733,7 +4733,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
ast_debug(1, "Answering on polarity switch!\n");
ast_setstate(p->owner, AST_STATE_UP);
if (p->hanguponpolarityswitch) {
- gettimeofday(&p->polaritydelaytv, NULL);
+ p->polaritydelaytv = ast_tvnow();
}
} else
ast_debug(1, "Ignore switch to REVERSED Polarity on channel %d, state %d\n", p->channel, ast->_state);
@@ -4836,7 +4836,7 @@ static struct ast_frame *__zt_exception(struct ast_channel *ast)
/* Do nothing */
break;
case ZT_EVENT_WINKFLASH:
- gettimeofday(&p->flashtime, NULL);
+ p->flashtime = ast_tvnow();
if (p->owner) {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Channel %d flashed to other channel %s\n", p->channel, p->owner->name);
@@ -8539,7 +8539,7 @@ static void *ss7_linkset(void *data)
while(1) {
ast_mutex_lock(&linkset->lock);
if ((next = ss7_schedule_next(ss7))) {
- gettimeofday(&tv, NULL);
+ tv = ast_tvnow();
tv.tv_sec = next->tv_sec - tv.tv_sec;
tv.tv_usec = next->tv_usec - tv.tv_usec;
if (tv.tv_usec < 0) {
@@ -9302,7 +9302,7 @@ static void *pri_dchannel(void *vpri)
int nextidle = -1;
struct ast_channel *c;
struct timeval tv, lowest, *next;
- struct timeval lastidle = { 0, 0 };
+ struct timeval lastidle = ast_tvnow();
int doidling=0;
char *cc;
char idlen[80];
@@ -9319,7 +9319,6 @@ static void *pri_dchannel(void *vpri)
char plancallingani[256];
char calledtonstr[10];
- gettimeofday(&lastidle, NULL);
if (!ast_strlen_zero(pri->idledial) && !ast_strlen_zero(pri->idleext)) {
/* Need to do idle dialing, check to be sure though */
cc = strchr(pri->idleext, '@');
@@ -9389,7 +9388,7 @@ static void *pri_dchannel(void *vpri)
}
} else
ast_log(LOG_WARNING, "Unable to request channel 'Zap/%s' for idle call\n", idlen);
- gettimeofday(&lastidle, NULL);
+ lastidle = ast_tvnow();
}
} else if ((haveidles < pri->minunused) &&
(activeidles > pri->minidle)) {
diff --git a/channels/iax2-parser.c b/channels/iax2-parser.c
index 769505193..1c52cca59 100644
--- a/channels/iax2-parser.c
+++ b/channels/iax2-parser.c
@@ -140,7 +140,7 @@ static void dump_byte(char *output, int maxlen, void *value, int len)
static void dump_datetime(char *output, int maxlen, void *value, int len)
{
- struct tm tm;
+ struct ast_tm tm;
unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value));
if (len == (int)sizeof(unsigned int)) {
tm.tm_sec = (val & 0x1f) << 1;
@@ -149,7 +149,7 @@ static void dump_datetime(char *output, int maxlen, void *value, int len)
tm.tm_mday = (val >> 16) & 0x1f;
tm.tm_mon = ((val >> 21) & 0x0f) - 1;
tm.tm_year = ((val >> 25) & 0x7f) + 100;
- strftime(output, maxlen, "%Y-%m-%d %T", &tm);
+ ast_strftime(output, maxlen, "%Y-%m-%d %T", &tm);
} else
ast_copy_string(output, "Invalid DATETIME format!", maxlen);
}
diff --git a/channels/misdn/ie.c b/channels/misdn/ie.c
index 4093805b5..e7133ca75 100644
--- a/channels/misdn/ie.c
+++ b/channels/misdn/ie.c
@@ -852,17 +852,11 @@ static void enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int nt, s
unsigned char *p;
Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
int l;
+ struct timeval tv = { ti, 0 };
+ struct ast_tm tm;
- struct tm *tm;
-
- tm = localtime(&ti);
- if (!tm)
- {
- printf("%s: ERROR: gettimeofday() returned NULL.\n", __FUNCTION__);
- return;
- }
-
- if (MISDN_IE_DEBG) printf(" year=%d month=%d day=%d hour=%d minute=%d\n", tm->tm_year%100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min);
+ ast_localtime(&tv, &tm, NULL);
+ if (MISDN_IE_DEBG) printf(" year=%d month=%d day=%d hour=%d minute=%d\n", tm.tm_year%100, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
l = 5;
p = msg_put(msg, l+2);
@@ -872,11 +866,11 @@ static void enc_ie_date(unsigned char **ntmode, msg_t *msg, time_t ti, int nt, s
qi->QI_ELEMENT(date) = p - (unsigned char *)qi - sizeof(Q931_info_t);
p[0] = IE_DATE;
p[1] = l;
- p[2] = tm->tm_year % 100;
- p[3] = tm->tm_mon + 1;
- p[4] = tm->tm_mday;
- p[5] = tm->tm_hour;
- p[6] = tm->tm_min;
+ p[2] = tm.tm_year % 100;
+ p[3] = tm.tm_mon + 1;
+ p[4] = tm.tm_mday;
+ p[5] = tm.tm_hour;
+ p[6] = tm.tm_min;
}