1
/* Definition of serial stream class (strm).
3
* A serial stream provides serial data access. In theory, serial streams
4
* can be implemented via a number of methods (e.g. files or in-memory
5
* streams). In practice, there currently only exist the file type (aka
8
* In practice, many stream features are bound to files. I have not yet made
9
* any serious effort, except for the naming of this class, to try to make
10
* the interfaces very generic. However, I assume that we could work much
11
* like in the strm class, where some properties are simply ignored when
12
* the wrong strm mode is selected (which would translate here to the wrong
15
* Most importantly, this class provides generic input and output functions
16
* which can directly be used to work with the strms and file output. It
17
* provides such useful things like a circular file buffer and, hopefully
18
* at a later stage, a lazy writer. The object is also seriazable and thus
19
* can easily be persistet. The bottom line is that it makes much sense to
20
* use this class whereever possible as its features may grow in the future.
22
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
24
* This file is part of rsyslog.
26
* Rsyslog is free software: you can redistribute it and/or modify
27
* it under the terms of the GNU General Public License as published by
28
* the Free Software Foundation, either version 3 of the License, or
29
* (at your option) any later version.
31
* Rsyslog is distributed in the hope that it will be useful,
32
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
* GNU General Public License for more details.
36
* You should have received a copy of the GNU General Public License
37
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
39
* A copy of the GPL can be found in the file "COPYING" in this distribution.
42
#ifndef STREAM_H_INCLUDED
43
#define STREAM_H_INCLUDED
46
#include "obj-types.h"
52
STREAMTYPE_FILE_SINGLE = 0, /**< read a single file */
53
STREAMTYPE_FILE_CIRCULAR = 1, /**< circular files */
54
STREAMTYPE_FILE_MONITOR = 2 /**< monitor a (third-party) file */
58
STREAMMMODE_INVALID = 0,
63
/* The strm_t data structure */
64
typedef struct strm_s {
65
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
67
/* descriptive properties */
68
int iCurrFNum;/* current file number (NOT descriptor, but the number in the file name!) */
69
uchar *pszFName; /* prefix for generated filenames */
71
strmMode_t tOperationsMode;
73
int iAddtlOpenFlags; /* can be used to specifiy additional (compatible!) open flags */
74
int64 iMaxFileSize;/* maximum size a file may grow to */
75
int iMaxFiles; /* maximum number of files if a circular mode is in use */
76
int iFileNumDigits;/* min number of digits to use in file number (only in circular mode) */
77
int bDeleteOnClose; /* set to 1 to auto-delete on close -- be careful with that setting! */
78
int64 iCurrOffs;/* current offset */
79
int64 *pUsrWCntr; /* NULL or a user-provided counter that receives the nbr of bytes written since the last CntrSet() */
80
/* dynamic properties, valid only during file open, not to be persistet */
81
size_t sIOBufSize;/* size of IO buffer */
82
uchar *pszDir; /* Directory */
84
int fd; /* the file descriptor, -1 if closed */
85
uchar *pszCurrFName; /* name of current file (if open) */
86
uchar *pIOBuf; /* io Buffer */
87
size_t iBufPtrMax; /* current max Ptr in Buffer (if partial read!) */
88
size_t iBufPtr; /* pointer into current buffer */
89
int iUngetC; /* char set via UngetChar() call or -1 if none set */
90
int bInRecord; /* if 1, indicates that we are currently writing a not-yet complete record */
94
BEGINinterface(strm) /* name must also be changed in ENDinterface macro! */
96
#define strmCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
100
rsRetVal strmConstruct(strm_t **ppThis);
101
rsRetVal strmConstructFinalize(strm_t __attribute__((unused)) *pThis);
102
rsRetVal strmDestruct(strm_t **ppThis);
103
rsRetVal strmSetMaxFileSize(strm_t *pThis, int64 iMaxFileSize);
104
rsRetVal strmSetFileName(strm_t *pThis, uchar *pszName, size_t iLenName);
105
rsRetVal strmReadChar(strm_t *pThis, uchar *pC);
106
rsRetVal strmUnreadChar(strm_t *pThis, uchar c);
107
rsRetVal strmReadLine(strm_t *pThis, cstr_t **ppCStr);
108
rsRetVal strmSeekCurrOffs(strm_t *pThis);
109
rsRetVal strmWrite(strm_t *pThis, uchar *pBuf, size_t lenBuf);
110
rsRetVal strmWriteChar(strm_t *pThis, uchar c);
111
rsRetVal strmWriteLong(strm_t *pThis, long i);
112
rsRetVal strmSetFName(strm_t *pThis, uchar *pszPrefix, size_t iLenPrefix);
113
rsRetVal strmSetDir(strm_t *pThis, uchar *pszDir, size_t iLenDir);
114
rsRetVal strmFlush(strm_t *pThis);
115
rsRetVal strmRecordBegin(strm_t *pThis);
116
rsRetVal strmRecordEnd(strm_t *pThis);
117
rsRetVal strmSerialize(strm_t *pThis, strm_t *pStrm);
118
rsRetVal strmSetiAddtlOpenFlags(strm_t *pThis, int iNewVal);
119
rsRetVal strmGetCurrOffset(strm_t *pThis, int64 *pOffs);
120
rsRetVal strmSetWCntr(strm_t *pThis, number_t *pWCnt);
121
PROTOTYPEObjClassInit(strm);
122
PROTOTYPEpropSetMeth(strm, bDeleteOnClose, int);
123
PROTOTYPEpropSetMeth(strm, iMaxFileSize, int);
124
PROTOTYPEpropSetMeth(strm, iMaxFiles, int);
125
PROTOTYPEpropSetMeth(strm, iFileNumDigits, int);
126
PROTOTYPEpropSetMeth(strm, tOperationsMode, int);
127
PROTOTYPEpropSetMeth(strm, tOpenMode, mode_t);
128
PROTOTYPEpropSetMeth(strm, sType, strmType_t);
130
#endif /* #ifndef STREAM_H_INCLUDED */