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 /**
28  * A timeval with 32 bit fields.
29  *
30  * Used by the unified on disk file format.
31  */
32 typedef struct SCTimeval32_ {
33  uint32_t tv_sec;
34  uint32_t tv_usec;
35 } SCTimeval32;
36 
37 void TimeInit(void);
38 void TimeDeinit(void);
39 
40 void TimeSetByThread(const int thread_id, const struct timeval *tv);
41 void TimeGet(struct timeval *);
42 
43 /** \brief intialize a 'struct timespec' from a 'struct timeval'. */
44 #define FROM_TIMEVAL(timev) { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
45 
46 #ifdef UNITTESTS
47 void TimeSet(struct timeval *);
48 void TimeSetToCurrentTime(void);
49 void TimeSetIncrementTime(uint32_t);
50 #endif
51 
52 void TimeModeSetLive(void);
53 void TimeModeSetOffline (void);
54 int TimeModeIsLive(void);
55 
56 struct tm *SCLocalTime(time_t timep, struct tm *result);
57 void CreateTimeString(const struct timeval *ts, char *str, size_t size);
58 void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size);
59 void CreateUtcIsoTimeString(const struct timeval *ts, char *str, size_t size);
60 void CreateFormattedTimeString(const struct tm *t, const char * fmt, char *str, size_t size);
61 time_t SCMkTimeUtc(struct tm *tp);
62 int SCStringPatternToTime(char *string, const char **patterns,
63  int num_patterns, struct tm *time);
64 int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str,
65  size_t size);
66 uint64_t SCParseTimeSizeString (const char *str);
67 uint64_t SCGetSecondsUntil (const char *str, time_t epoch);
68 uint64_t SCTimespecAsEpochMillis(const struct timespec *ts);
69 
70 #endif /* __UTIL_TIME_H__ */
71 
void TimeSetIncrementTime(uint32_t)
increment the time in the engine
Definition: util-time.c:175
struct SCTimeval32_ SCTimeval32
void CreateUtcIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:203
void CreateFormattedTimeString(const struct tm *t, const char *fmt, char *str, size_t size)
Definition: util-time.c:219
void TimeSetByThread(const int thread_id, const struct timeval *tv)
Definition: util-time.c:107
void TimeModeSetLive(void)
Definition: util-time.c:90
int SCTimeToStringPattern(time_t epoch, const char *pattern, char *str, size_t size)
Convert epoch time to string pattern.
Definition: util-time.c:517
#define str(s)
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
Definition: util-time.c:418
int TimeModeIsLive(void)
Definition: util-time.c:102
void TimeGet(struct timeval *)
Definition: util-time.c:146
uint64_t SCTimespecAsEpochMillis(const struct timespec *ts)
Definition: util-time.c:615
void TimeInit(void)
Definition: util-time.c:77
void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:187
void TimeDeinit(void)
Definition: util-time.c:85
void TimeModeSetOffline(void)
Definition: util-time.c:96
uint32_t tv_sec
Definition: util-time.h:33
uint64_t ts
uint64_t SCGetSecondsUntil(const char *str, time_t epoch)
Get seconds until a time unit changes.
Definition: util-time.c:597
void TimeSetToCurrentTime(void)
set the time to "gettimeofday" meant for testing
Definition: util-time.c:135
struct tm * SCLocalTime(time_t timep, struct tm *result)
Definition: util-time.c:240
uint32_t tv_usec
Definition: util-time.h:34
void TimeSet(struct timeval *)
Definition: util-time.c:116
void CreateTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:245
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:461
uint64_t SCParseTimeSizeString(const char *str)
Parse string containing time size (1m, 1h, etc).
Definition: util-time.c:546