| 1 |
/* The datetime object. Contains time-related functions. |
| 2 |
* |
| 3 |
* Copyright 2008-2015 Adiscon GmbH. |
| 4 |
* |
| 5 |
* This file is part of the rsyslog runtime library. |
| 6 |
* |
| 7 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
* you may not use this file except in compliance with the License. |
| 9 |
* You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* -or- |
| 13 |
* see COPYING.ASL20 in the source distribution |
| 14 |
* |
| 15 |
* Unless required by applicable law or agreed to in writing, software |
| 16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 |
* See the License for the specific language governing permissions and |
| 19 |
* limitations under the License. |
| 20 |
*/ |
| 21 |
#ifndef INCLUDED_DATETIME_H |
| 22 |
#define INCLUDED_DATETIME_H |
| 23 |
|
| 24 |
/* TODO: define error codes */ |
| 25 |
#define NO_ERRCODE -1 |
| 26 |
|
| 27 |
/* the datetime object */ |
| 28 |
typedef struct datetime_s { |
| 29 |
char dummy; |
| 30 |
} datetime_t; |
| 31 |
|
| 32 |
typedef enum { |
| 33 |
DATE_INVALID = -1, |
| 34 |
DATE_RFC3164 = 0, |
| 35 |
DATE_RFC3339 = 1, |
| 36 |
DATE_UNIX = 2, |
| 37 |
} dateTimeFormat_t; |
| 38 |
|
| 39 |
/* interfaces */ |
| 40 |
BEGINinterface(datetime) /* name must also be changed in ENDinterface macro! */ |
| 41 |
void (*getCurrTime)(struct syslogTime *t, time_t *ttSeconds, const int inUTC); |
| 42 |
rsRetVal (*ParseTIMESTAMP3339)(struct syslogTime *pTime, uchar **ppszTS, int *); |
| 43 |
rsRetVal (*ParseTIMESTAMP3164)(struct syslogTime *pTime, uchar **pszTS, int *, const int bParseTZ, |
| 44 |
const int bDetectYearAfterTime); |
| 45 |
int (*formatTimestampToMySQL)(struct syslogTime *ts, char *pDst); |
| 46 |
int (*formatTimestampToPgSQL)(struct syslogTime *ts, char *pDst); |
| 47 |
int (*formatTimestamp3339)(struct syslogTime *ts, char *pBuf); |
| 48 |
int (*formatTimestamp3164)(struct syslogTime *ts, char *pBuf, int); |
| 49 |
int (*formatTimestampSecFrac)(struct syslogTime *ts, char *pBuf); |
| 50 |
/* v3, 2009-11-12 */ |
| 51 |
time_t (*GetTime)(time_t *ttSeconds); |
| 52 |
/* v6, 2011-06-20 , v10, 2016-01-12*/ |
| 53 |
void (*timeval2syslogTime)(struct timeval *tp, struct syslogTime *t, const int inUTC); |
| 54 |
/* v7, 2012-03-29 */ |
| 55 |
int (*formatTimestampUnix)(struct syslogTime *ts, char *pBuf); |
| 56 |
time_t (*syslogTime2time_t)(const struct syslogTime *ts); |
| 57 |
/* v11, 2017-10-05 */ |
| 58 |
int (*formatUnixTimeFromTime_t)(time_t time, const char *format, char *pBuf, uint pBufMax); |
| 59 |
ENDinterface(datetime) |
| 60 |
#define datetimeCURR_IF_VERSION 11 /* increment whenever you change the interface structure! */ |
| 61 |
/* interface changes: |
| 62 |
* 1 - initial version |
| 63 |
* 2 - not compatible to 1 - bugfix required ParseTIMESTAMP3164 to accept char ** as |
| 64 |
* last parameter. Did not try to remain compatible as this is not something any |
| 65 |
* third-party module should call. -- rgerhards, 2008.-09-12 |
| 66 |
* 3 - taken by v5 branch! |
| 67 |
* 4 - formatTimestamp3164 takes a third int parameter |
| 68 |
* 5 - merge of versions 3 + 4 (2010-03-09) |
| 69 |
* 6 - see above |
| 70 |
* 8 - ParseTIMESTAMP3164 has addtl parameter to permit TZ string parsing |
| 71 |
* 9 - ParseTIMESTAMP3164 has addtl parameter to permit year parsing |
| 72 |
* 10 - functions having addtl paramater inUTC to emit time in UTC: |
| 73 |
* timeval2syslogTime, getCurrtime |
| 74 |
* 11 - Add formatUnixTimeFromTime_t |
| 75 |
*/ |
| 76 |
|
| 77 |
#define PARSE3164_TZSTRING 1 |
| 78 |
#define NO_PARSE3164_TZSTRING 0 |
| 79 |
|
| 80 |
#define PERMIT_YEAR_AFTER_TIME 1 |
| 81 |
#define NO_PERMIT_YEAR_AFTER_TIME 0 |
| 82 |
|
| 83 |
/* two defines for functions that create timestamps either in local |
| 84 |
* time or UTC. |
| 85 |
*/ |
| 86 |
#define TIME_IN_UTC 1 |
| 87 |
#define TIME_IN_LOCALTIME 0 |
| 88 |
|
| 89 |
/* prototypes */ |
| 90 |
PROTOTYPEObj(datetime); |
| 91 |
void applyDfltTZ(struct syslogTime *pTime, char *tz); |
| 92 |
int getWeekdayNbr(struct syslogTime *ts); |
| 93 |
int getOrdinal(struct syslogTime *ts); |
| 94 |
int getWeek(struct syslogTime *ts); |
| 95 |
int getISOWeek(struct syslogTime *ts, int *year); |
| 96 |
void timeConvertToUTC(const struct syslogTime *const __restrict__ local, struct syslogTime *const __restrict__ utc); |
| 97 |
time_t getTime(time_t *ttSeconds); |
| 98 |
dateTimeFormat_t getDateTimeFormatFromStr(const char *const __restrict__ s); |
| 99 |
|
| 100 |
#endif /* #ifndef INCLUDED_DATETIME_H */ |