1 /*
2 * Copyright (c) 2002-2015 Balabit
3 * Copyright (c) 2015 Viktor Juhasz <viktor.juhasz@balabit.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * As an additional exemption you are allowed to compile & link against the
20 * OpenSSL libraries as published by the OpenSSL project. See the file
21 * COPYING for details.
22 *
23 */
24
25 #include "timestamp-serialize.h"
26
27 static gboolean
_write_log_stamp(SerializeArchive * sa,const UnixTime * stamp)28 _write_log_stamp(SerializeArchive *sa, const UnixTime *stamp)
29 {
30 return serialize_write_uint64(sa, stamp->ut_sec) &&
31 serialize_write_uint32(sa, stamp->ut_usec) &&
32 serialize_write_uint32(sa, stamp->ut_gmtoff);
33 }
34
35 static gboolean
_read_log_stamp(SerializeArchive * sa,UnixTime * stamp)36 _read_log_stamp(SerializeArchive *sa, UnixTime *stamp)
37 {
38 guint64 val64;
39 guint32 val;
40
41 if (!serialize_read_uint64(sa, &val64))
42 return FALSE;
43 stamp->ut_sec = (gint64) val64;
44
45 if (!serialize_read_uint32(sa, &val))
46 return FALSE;
47 stamp->ut_usec = val;
48
49 if (!serialize_read_uint32(sa, &val))
50 return FALSE;
51 stamp->ut_gmtoff = (gint) val;
52 return TRUE;
53 }
54
55
56 gboolean
timestamp_serialize(SerializeArchive * sa,UnixTime * timestamps)57 timestamp_serialize(SerializeArchive *sa, UnixTime *timestamps)
58 {
59 return _write_log_stamp(sa, ×tamps[LM_TS_STAMP]) &&
60 _write_log_stamp(sa, ×tamps[LM_TS_RECVD]) &&
61 _write_log_stamp(sa, ×tamps[LM_TS_PROCESSED]);
62 }
63
64 gboolean
timestamp_deserialize_legacy(SerializeArchive * sa,UnixTime * timestamps)65 timestamp_deserialize_legacy(SerializeArchive *sa, UnixTime *timestamps)
66 {
67 return (_read_log_stamp(sa, ×tamps[LM_TS_STAMP]) &&
68 _read_log_stamp(sa, ×tamps[LM_TS_RECVD]));
69 }
70
71 gboolean
timestamp_deserialize(SerializeArchive * sa,UnixTime * timestamps)72 timestamp_deserialize(SerializeArchive *sa, UnixTime *timestamps)
73 {
74 return (timestamp_deserialize_legacy(sa, timestamps) &&
75 _read_log_stamp(sa, ×tamps[LM_TS_PROCESSED]));
76 }
77