~ubuntu-branches/ubuntu/karmic/rsyslog/karmic-200908151517

« back to all changes in this revision

Viewing changes to stream.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-04-23 16:46:39 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080423164639-5acmt8a4vpxjgnxw
Tags: 3.14.2-3
* debian/rsyslog-doc.install
  - Fix a typo in the install path of the dia files. Closes: #477489
    Thanks to Justin B Rye for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Definition of serial stream class (strm).
 
2
 *
 
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
 
6
 * "driver").
 
7
 *
 
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
 
13
 * stream mode).
 
14
 *
 
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.
 
21
 *
 
22
 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
 
23
 *
 
24
 * This file is part of rsyslog.
 
25
 *
 
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.
 
30
 *
 
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.
 
35
 *
 
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/>.
 
38
 *
 
39
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 
40
 */
 
41
 
 
42
#ifndef STREAM_H_INCLUDED
 
43
#define STREAM_H_INCLUDED
 
44
 
 
45
#include <pthread.h>
 
46
#include "obj-types.h"
 
47
#include "glbl.h"
 
48
#include "stream.h"
 
49
 
 
50
/* stream types */
 
51
typedef enum {
 
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 */
 
55
} strmType_t;
 
56
 
 
57
typedef enum {
 
58
        STREAMMMODE_INVALID = 0,
 
59
        STREAMMODE_READ = 1,
 
60
        STREAMMODE_WRITE = 2
 
61
} strmMode_t;
 
62
 
 
63
/* The strm_t data structure */
 
64
typedef struct strm_s {
 
65
        BEGINobjInstance;       /* Data to implement generic object - MUST be the first data element! */
 
66
        strmType_t sType;
 
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 */
 
70
        int lenFName;
 
71
        strmMode_t tOperationsMode;
 
72
        mode_t tOpenMode;
 
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 */
 
83
        int lenDir;
 
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 */
 
91
} strm_t;
 
92
 
 
93
/* interfaces */
 
94
BEGINinterface(strm) /* name must also be changed in ENDinterface macro! */
 
95
ENDinterface(strm)
 
96
#define strmCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
 
97
 
 
98
 
 
99
/* prototypes */
 
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);
 
129
 
 
130
#endif /* #ifndef STREAM_H_INCLUDED */