suricata
util-time.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef __UTIL_TIME_H__
25 #define __UTIL_TIME_H__
26 
27 void TimeInit(void);
28 void TimeDeinit(void);
29 
30 void TimeSetByThread(const int thread_id, const struct timeval *tv);
31 void TimeGet(struct timeval *);
32 
33 /** \brief intialize a 'struct timespec' from a 'struct timeval'. */
34 #define FROM_TIMEVAL(timev) { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
35 
36 #ifdef UNITTESTS
37 void TimeSet(struct timeval *);
38 void TimeSetToCurrentTime(void);
39 void TimeSetIncrementTime(uint32_t);
40 #endif
41 
42 bool TimeModeIsReady(void);
43 void TimeModeSetLive(void);
44 void TimeModeSetOffline (void);
45 bool TimeModeIsLive(void);
46 
47 struct tm *SCLocalTime(time_t timep, struct tm *result);
48 void CreateTimeString(const struct timeval *ts, char *str, size_t size);
49 void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size);
50 void CreateUtcIsoTimeString(const struct timeval *ts, char *str, size_t size);
51 void CreateFormattedTimeString(const struct tm *t, const char * fmt, char *str, size_t size);
52 time_t SCMkTimeUtc(struct tm *tp);
53 int SCStringPatternToTime(char *string, const char **patterns,
54  int num_patterns, struct tm *time);
55 int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str,
56  size_t size);
57 uint64_t SCParseTimeSizeString (const char *str);
58 uint64_t SCGetSecondsUntil (const char *str, time_t epoch);
59 uint64_t SCTimespecAsEpochMillis(const struct timespec *ts);
60 
61 #endif /* __UTIL_TIME_H__ */
62 
TimeSetToCurrentTime
void TimeSetToCurrentTime(void)
set the time to "gettimeofday" meant for testing
Definition: util-time.c:142
ts
uint64_t ts
Definition: source-erf-file.c:2
TimeSet
void TimeSet(struct timeval *)
Definition: util-time.c:123
CreateTimeString
void CreateTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:252
CreateFormattedTimeString
void CreateFormattedTimeString(const struct tm *t, const char *fmt, char *str, size_t size)
Definition: util-time.c:226
TimeModeSetLive
void TimeModeSetLive(void)
Definition: util-time.c:97
CreateUtcIsoTimeString
void CreateUtcIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:210
TimeSetByThread
void TimeSetByThread(const int thread_id, const struct timeval *tv)
Definition: util-time.c:114
SCMkTimeUtc
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
Definition: util-time.c:425
SCTimeToStringPattern
int SCTimeToStringPattern(time_t epoch, const char *pattern, char *str, size_t size)
Convert epoch time to string pattern.
Definition: util-time.c:524
TimeInit
void TimeInit(void)
Definition: util-time.c:77
TimeGet
void TimeGet(struct timeval *)
Definition: util-time.c:153
TimeModeIsLive
bool TimeModeIsLive(void)
Definition: util-time.c:109
SCTimespecAsEpochMillis
uint64_t SCTimespecAsEpochMillis(const struct timespec *ts)
Definition: util-time.c:622
TimeModeIsReady
bool TimeModeIsReady(void)
Definition: util-time.c:90
TimeModeSetOffline
void TimeModeSetOffline(void)
Definition: util-time.c:103
TimeDeinit
void TimeDeinit(void)
Definition: util-time.c:85
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
CreateIsoTimeString
void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:194
str
#define str(s)
Definition: suricata-common.h:256
SCParseTimeSizeString
uint64_t SCParseTimeSizeString(const char *str)
Parse string containing time size (1m, 1h, etc).
Definition: util-time.c:553
SCGetSecondsUntil
uint64_t SCGetSecondsUntil(const char *str, time_t epoch)
Get seconds until a time unit changes.
Definition: util-time.c:604
SCLocalTime
struct tm * SCLocalTime(time_t timep, struct tm *result)
Definition: util-time.c:247
TimeSetIncrementTime
void TimeSetIncrementTime(uint32_t)
increment the time in the engine
Definition: util-time.c:182
SCStringPatternToTime
int SCStringPatternToTime(char *string, const char **patterns, int num_patterns, struct tm *time)
Parse a date string based on specified patterns.
Definition: util-time.c:468