summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-09 18:54:20 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-09 18:54:20 +0000
commitdee5485ade5b77748f2cebcd6b65ea71f01123f8 (patch)
treef4fb68a599e3ee0d0c41dc5a66b15a79e6255632
parentaa7e00d8e1a1d67fa2860623ffab75bd387faffc (diff)
downloadrsyslog-dee5485ade5b77748f2cebcd6b65ea71f01123f8.tar.gz
rsyslog-dee5485ade5b77748f2cebcd6b65ea71f01123f8.tar.xz
rsyslog-dee5485ade5b77748f2cebcd6b65ea71f01123f8.zip
some cleanup on object model
-rw-r--r--obj.c59
-rw-r--r--obj.h126
-rw-r--r--queue.c38
-rw-r--r--stream.c59
-rw-r--r--stream.h6
5 files changed, 93 insertions, 195 deletions
diff --git a/obj.c b/obj.c
index a50a74f6..eb9fd2c9 100644
--- a/obj.c
+++ b/obj.c
@@ -37,6 +37,7 @@
#include "syslogd-types.h"
#include "srUtils.h"
#include "obj.h"
+#include "stream.h"
/* static data */
static objInfo_t *arrObjInfo[OBJ_NUM_IDS]; /* array with object information pointers */
@@ -301,10 +302,10 @@ finalize_it:
/* define a helper to make code below a bit cleaner (and quicker to write) */
-#define NEXTC CHKiRet(serialStoreGetChar(pSerStore, &c))//;dbgprintf("c: %c\n", c);
+#define NEXTC CHKiRet(strmReadChar(pStrm, &c))//;dbgprintf("c: %c\n", c);
/* de-serialize an (long) integer */
-static rsRetVal objDeserializeLong(long *pInt, serialStore_t *pSerStore)
+static rsRetVal objDeserializeLong(long *pInt, strm_t *pStrm)
{
DEFiRet;
int i;
@@ -328,7 +329,7 @@ finalize_it:
/* de-serialize a string, length must be provided */
-static rsRetVal objDeserializeStr(rsCStrObj **ppCStr, int iLen, serialStore_t *pSerStore)
+static rsRetVal objDeserializeStr(rsCStrObj **ppCStr, int iLen, strm_t *pStrm)
{
DEFiRet;
int i;
@@ -363,9 +364,9 @@ finalize_it:
/* de-serialize a syslogTime -- rgerhards,2008-01-08 */
#define GETVAL(var) \
- CHKiRet(objDeserializeLong(&l, pSerStore)); \
+ CHKiRet(objDeserializeLong(&l, pStrm)); \
pTime->var = l;
-static rsRetVal objDeserializeSyslogTime(syslogTime_t *pTime, serialStore_t *pSerStore)
+static rsRetVal objDeserializeSyslogTime(syslogTime_t *pTime, strm_t *pStrm)
{
DEFiRet;
long l;
@@ -396,7 +397,7 @@ finalize_it:
/* de-serialize an object header
* rgerhards, 2008-01-07
*/
-static rsRetVal objDeserializeHeader(objID_t *poID, int* poVers, serialStore_t *pSerStore)
+static rsRetVal objDeserializeHeader(objID_t *poID, int* poVers, strm_t *pStrm)
{
DEFiRet;
long ioID;
@@ -415,8 +416,8 @@ static rsRetVal objDeserializeHeader(objID_t *poID, int* poVers, serialStore_t *
NEXTC; if(c != ':') ABORT_FINALIZE(RS_RET_INVALID_HEADER_VERS);
/* object type and version and string length */
- CHKiRet(objDeserializeLong(&ioID, pSerStore));
- CHKiRet(objDeserializeLong(&oVers, pSerStore));
+ CHKiRet(objDeserializeLong(&ioID, pStrm));
+ CHKiRet(objDeserializeLong(&oVers, pStrm));
if(ioID < 1 || ioID >= OBJ_NUM_IDS)
ABORT_FINALIZE(RS_RET_INVALID_OID);
@@ -438,7 +439,7 @@ dbgprintf("DeserializeHeader oid: %ld, vers: %ld, iRet: %d\n", ioID, oVers, iRet
/* Deserialize a single property. Pointer must be positioned at begin of line. Whole line
* up until the \n is read.
*/
-static rsRetVal objDeserializeProperty(property_t *pProp, serialStore_t *pSerStore)
+static rsRetVal objDeserializeProperty(property_t *pProp, strm_t *pStrm)
{
DEFiRet;
long i;
@@ -451,7 +452,7 @@ static rsRetVal objDeserializeProperty(property_t *pProp, serialStore_t *pSerSto
NEXTC;
if(c != COOKIE_PROPLINE) {
/* oops, we've read one char that does not belong to use - unget it first */
- CHKiRet(serialStoreUngetChar(pSerStore, c));
+ CHKiRet(strmUnreadChar(pStrm, c));
ABORT_FINALIZE(RS_RET_NO_PROPLINE);
}
@@ -467,34 +468,34 @@ static rsRetVal objDeserializeProperty(property_t *pProp, serialStore_t *pSerSto
CHKiRet(rsCStrFinish(pProp->pcsName));
/* property type */
- CHKiRet(objDeserializeLong(&i, pSerStore));
+ CHKiRet(objDeserializeLong(&i, pStrm));
pProp->propType = i;
/* size (needed for strings) */
- CHKiRet(objDeserializeLong(&iLen, pSerStore));
+ CHKiRet(objDeserializeLong(&iLen, pStrm));
/* we now need to deserialize the value */
//dbgprintf("deserialized property name '%s', type %d, size %ld, c: %c\n", rsCStrGetSzStrNoNULL(pProp->pcsName), pProp->propType, iLen, c);
switch(pProp->propType) {
case PROPTYPE_PSZ:
- CHKiRet(objDeserializeStr(&pProp->val.vpCStr, iLen, pSerStore));
+ CHKiRet(objDeserializeStr(&pProp->val.vpCStr, iLen, pStrm));
break;
case PROPTYPE_SHORT:
- CHKiRet(objDeserializeLong(&i, pSerStore));
+ CHKiRet(objDeserializeLong(&i, pStrm));
pProp->val.vShort = i;
break;
case PROPTYPE_INT:
- CHKiRet(objDeserializeLong(&i, pSerStore));
+ CHKiRet(objDeserializeLong(&i, pStrm));
pProp->val.vInt = i;
break;
case PROPTYPE_LONG:
- CHKiRet(objDeserializeLong(&pProp->val.vLong, pSerStore));
+ CHKiRet(objDeserializeLong(&pProp->val.vLong, pStrm));
break;
case PROPTYPE_CSTR:
- CHKiRet(objDeserializeStr(&pProp->val.vpCStr, iLen, pSerStore));
+ CHKiRet(objDeserializeStr(&pProp->val.vpCStr, iLen, pStrm));
break;
case PROPTYPE_SYSLOGTIME:
- CHKiRet(objDeserializeSyslogTime(&pProp->val.vSyslogTime, pSerStore));
+ CHKiRet(objDeserializeSyslogTime(&pProp->val.vSyslogTime, pStrm));
break;
}
@@ -511,7 +512,7 @@ finalize_it:
* format is ok.
* rgerhards, 2008-01-07
*/
-static rsRetVal objDeserializeTrailer(serialStore_t *pSerStore)
+static rsRetVal objDeserializeTrailer(strm_t *pStrm)
{
DEFiRet;
uchar c;
@@ -542,14 +543,14 @@ finalize_it:
* looks like a valid object or end of store.
* rgerhards, 2008-01-07
*/
-static rsRetVal objDeserializeTryRecover(serialStore_t *pSerStore)
+static rsRetVal objDeserializeTryRecover(strm_t *pStrm)
{
DEFiRet;
uchar c;
int bWasNL;
int bRun;
- assert(pSerStore != NULL);
+ assert(pStrm != NULL);
bRun = 1;
bWasNL = 0;
@@ -565,7 +566,7 @@ static rsRetVal objDeserializeTryRecover(serialStore_t *pSerStore)
}
}
- CHKiRet(serialStoreUngetChar(pSerStore, c));
+ CHKiRet(strmUnreadChar(pStrm, c));
finalize_it:
dbgprintf("deserializer has possibly been able to re-sync and recover, state %d\n", iRet);
@@ -581,7 +582,7 @@ finalize_it:
* The caller must destruct the created object.
* rgerhards, 2008-01-07
*/
-rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, serialStore_t *pSerStore)
+rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, strm_t *pStrm)
{
DEFiRet;
rsRetVal iRetLocal;
@@ -592,7 +593,7 @@ rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, serialStore_t *pSe
assert(ppObj != NULL);
assert(objTypeExpected > 0 && objTypeExpected < OBJ_NUM_IDS);
- assert(pSerStore != NULL);
+ assert(pStrm != NULL);
/* we de-serialize the header. if all goes well, we are happy. However, if
* we experience a problem, we try to recover. We do this by skipping to
@@ -602,10 +603,10 @@ rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, serialStore_t *pSe
* rgerhards, 2008-07-08
*/
do {
- iRetLocal = objDeserializeHeader(&oID, &oVers, pSerStore);
+ iRetLocal = objDeserializeHeader(&oID, &oVers, pStrm);
if(iRetLocal != RS_RET_OK) {
dbgprintf("objDeserialize error %d during header processing - trying to recover\n", iRetLocal);
- CHKiRet(objDeserializeTryRecover(pSerStore));
+ CHKiRet(objDeserializeTryRecover(pStrm));
}
} while(iRetLocal != RS_RET_OK);
@@ -614,17 +615,17 @@ rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, serialStore_t *pSe
CHKiRet(arrObjInfo[oID]->objMethods[objMethod_CONSTRUCT](&pObj));
/* we got the object, now we need to fill the properties */
- iRet = objDeserializeProperty(&propBuf, pSerStore);
+ iRet = objDeserializeProperty(&propBuf, pStrm);
while(iRet == RS_RET_OK) {
CHKiRet(arrObjInfo[oID]->objMethods[objMethod_SETPROPERTY](pObj, &propBuf));
- iRet = objDeserializeProperty(&propBuf, pSerStore);
+ iRet = objDeserializeProperty(&propBuf, pStrm);
}
rsCStrDestruct(propBuf.pcsName); /* todo: a destructor would be nice here... -- rger, 2008-01-07 */
if(iRet != RS_RET_NO_PROPLINE)
FINALIZE;
- CHKiRet(objDeserializeTrailer(pSerStore)); /* do trailer checks */
+ CHKiRet(objDeserializeTrailer(pStrm)); /* do trailer checks */
/* we have a valid object, let's finalize our work and return */
if(objInfoIsImplemented(arrObjInfo[oID], objMethod_CONSTRUCTION_FINALIZER))
diff --git a/obj.h b/obj.h
index 0c24c279..7a5b07f1 100644
--- a/obj.h
+++ b/obj.h
@@ -44,128 +44,8 @@
#ifndef OBJ_H_INCLUDED
#define OBJ_H_INCLUDED
-#include "stringbuf.h"
-
-/* property types */
-typedef enum { /* do NOT start at 0 to detect uninitialized types after calloc() */
- PROPTYPE_PSZ = 1,
- PROPTYPE_SHORT = 2,
- PROPTYPE_INT = 3,
- PROPTYPE_LONG = 4,
- PROPTYPE_CSTR = 5,
- PROPTYPE_SYSLOGTIME = 6
-} propertyType_t;
-
-typedef struct {
- rsCStrObj *pcsName;
- propertyType_t propType;
- union {
- short vShort;
- int vInt;
- long vLong;
- rsCStrObj *vpCStr; /* used for both rsCStr and psz */
- syslogTime_t vSyslogTime;
-
- } val;
-} property_t;
-
-/* object Types/IDs */
-typedef enum { /* IDs of known object "types/classes" */
- OBJNull = 0, /* no valid object (we do not start at zero so we can detect calloc()) */
- OBJMsg = 1,
- OBJstrm = 2
-} objID_t;
-#define OBJ_NUM_IDS 3
-
-typedef enum { /* IDs of base methods supported by all objects - used for jump table, so
- * they must start at zero and be incremented. -- rgerahrds, 2008-01-04
- */
- objMethod_CONSTRUCT = 0,
- objMethod_DESTRUCT = 1,
- objMethod_SERIALIZE = 2,
- objMethod_DESERIALIZE = 3,
- objMethod_SETPROPERTY = 4,
- objMethod_CONSTRUCTION_FINALIZER = 5,
- objMethod_DEBUGPRINT = 6
-} objMethod_t;
-#define OBJ_NUM_METHODS 7 /* must be updated to contain the max number of methods supported */
-
-typedef struct objInfo_s {
- objID_t objID;
- int iObjVers;
- uchar *pszName;
- rsRetVal (*objMethods[OBJ_NUM_METHODS])();
-} objInfo_t;
-
-typedef struct obj { /* the dummy struct that each derived class can be casted to */
- objInfo_t *pObjInfo;
-} obj_t;
-
-/* the following structure is used for deserialization. It defines a serial storage with a single
- * ungetc() capability. This should probably become its own object some time. -- rgerhards, 2008-01-07
- */
-typedef struct serialStore_s {
- void *pUsr; /* Pointer to some user data */
- /* methods */
- rsRetVal (*funcGetChar)(void*, uchar*);
- rsRetVal (*funcUngetChar)(void*, uchar);
-} serialStore_t;
-#define serialStoreGetChar(pThis, c) (pThis->funcGetChar(pThis->pUsr, c))
-#define serialStoreUngetChar(pThis, c) (pThis->funcUngetChar(pThis->pUsr, c))
-
-
-/* macros */
-/* the following one is a helper that prevents us from writing the
- * ever-same code at the end of Construct()
- */
-#define OBJCONSTRUCT_CHECK_SUCCESS_AND_CLEANUP \
- if(iRet == RS_RET_OK) { \
- *ppThis = pThis; \
- } else { \
- if(pThis != NULL) \
- free(pThis); \
- }
-
-#define DEFpropSetMeth(obj, prop, dataType)\
- rsRetVal obj##Set##prop(obj##_t *pThis, dataType pVal)\
- { \
- pThis->prop = pVal; \
- return RS_RET_OK; \
- }
-#define PROTOTYPEpropSetMeth(obj, prop, dataType)\
- rsRetVal obj##Set##prop(obj##_t *pThis, dataType pVal)
-
-#define objSerializeSCALAR(propName, propType) \
- CHKiRet(objSerializeProp(pCStr, (uchar*) #propName, PROPTYPE_##propType, (void*) &pThis->propName));
-#define objSerializePTR(propName, propType) \
- CHKiRet(objSerializeProp(pCStr, (uchar*) #propName, PROPTYPE_##propType, (void*) pThis->propName));
-#define DEFobjStaticHelpers static objInfo_t *pObjInfoOBJ = NULL;
-#define BEGINobjInstance objInfo_t *pObjInfo
-#define objGetName(pThis) (((obj_t*) (pThis))->pObjInfo->pszName)
-#define objGetObjID(pThis) (((obj_t*) (pThis))->pObjInfo->objID)
-#define objGetVersion(pThis) (((obj_t*) (pThis))->pObjInfo->iObjVers)
-/* must be called in Constructor: */
-#define objConstructSetObjInfo(pThis) ((obj_t*) (pThis))->pObjInfo = pObjInfoOBJ;
-#define objDestruct(pThis) (((obj_t*) (pThis))->pObjInfo->objMethods[objMethod_DESTRUCT])(pThis)
-#define objSerialize(pThis) (((obj_t*) (pThis))->pObjInfo->objMethods[objMethod_SERIALIZE])
-/* class initializer */
-#define PROTOTYPEObjClassInit(objName) rsRetVal objName##ClassInit(void)
-#define BEGINObjClassInit(objName, objVers) \
-rsRetVal objName##ClassInit(void) \
-{ \
- DEFiRet; \
- CHKiRet(objInfoConstruct(&pObjInfoOBJ, OBJ##objName, (uchar*) #objName, objVers, \
- (rsRetVal (*)(void*))objName##Construct, (rsRetVal (*)(void*))objName##Destruct));
-
-#define ENDObjClassInit(objName) \
- objRegisterObj(OBJ##objName, pObjInfoOBJ); \
-finalize_it: \
- return iRet; \
-}
-
-#define OBJSetMethodHandler(methodID, pHdlr) \
- CHKiRet(objInfoSetMethod(pObjInfoOBJ, methodID, (rsRetVal (*)(void*)) pHdlr))
-
+#include "obj-types.h"
+#include "stream.h"
/* prototypes */
rsRetVal objInfoConstruct(objInfo_t **ppThis, objID_t objID, uchar *pszName, int iObjVers, rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *));
@@ -175,7 +55,7 @@ rsRetVal objSerializePsz(rsCStrObj *pCStr, uchar *psz, size_t len);
rsRetVal objEndSerialize(rsCStrObj **ppCStr, obj_t *pObj);
rsRetVal objSerializeProp(rsCStrObj *pCStr, uchar *pszPropName, propertyType_t propType, void *pUsr);
rsRetVal objRegisterObj(objID_t oID, objInfo_t *pInfo);
-rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, serialStore_t *pSerStore);
+rsRetVal objDeserialize(void *ppObj, objID_t objTypeExpected, strm_t *pSerStore);
PROTOTYPEObjClassInit(obj);
#endif /* #ifndef OBJ_H_INCLUDED */
diff --git a/queue.c b/queue.c
index 76dbace6..834dab8b 100644
--- a/queue.c
+++ b/queue.c
@@ -196,10 +196,12 @@ static rsRetVal qConstructDisk(queue_t *pThis)
assert(pThis != NULL);
CHKiRet(strmConstruct(&pThis->tVars.disk.pWrite));
+ CHKiRet(strmSetDir(pThis->tVars.disk.pWrite, pszSpoolDirectory, strlen((char*)pszSpoolDirectory)));
CHKiRet(strmConstructFinalize(pThis->tVars.disk.pWrite));
CHKiRet(strmConstruct(&pThis->tVars.disk.pRead));
CHKiRet(strmSetbDeleteOnClose(pThis->tVars.disk.pRead, 1));
+ CHKiRet(strmSetDir(pThis->tVars.disk.pRead, pszSpoolDirectory, strlen((char*)pszSpoolDirectory)));
CHKiRet(strmConstructFinalize(pThis->tVars.disk.pRead));
finalize_it:
@@ -240,39 +242,7 @@ finalize_it:
static rsRetVal qDelDisk(queue_t *pThis, void **ppUsr)
{
- DEFiRet;
- msg_t *pMsg = NULL;
- serialStore_t serialStore;
- int bRun;
-
- assert(pThis != NULL);
-
- /* de-serialize object from file
- * We need to try at least twice because we may run into EOF and need
- * to switch files.
- */
- serialStore.pUsr = pThis->tVars.disk.pRead;
- serialStore.funcGetChar = (rsRetVal (*)(void*, uchar*)) strmReadChar;
- serialStore.funcUngetChar = (rsRetVal (*)(void*, uchar)) strmUnreadChar;
- bRun = 1;
- while(bRun) {
- /* first check if we need to (re)open the file (we may have switched to a new one!) */
- CHKiRet(strmOpenFile(pThis->tVars.disk.pRead, O_RDONLY, 0600)); // TODO: open modes!
-
- iRet = objDeserialize((void*) &pMsg, OBJMsg, &serialStore);
- if(iRet == RS_RET_OK)
- bRun = 0; /* we are done */
- else if(iRet == RS_RET_EOF) {
- dbgprintf("Queue 0x%lx: EOF on file %d\n", (unsigned long) pThis, pThis->tVars.disk.pRead->fd);
- CHKiRet(strmNextFile(pThis->tVars.disk.pRead));
- } else
- FINALIZE;
- }
-
- *ppUsr = (void*) pMsg;
-
-finalize_it:
- return iRet;
+ return objDeserialize(ppUsr, OBJMsg, pThis->tVars.disk.pRead);
}
/* -------------------- direct (no queueing) -------------------- */
@@ -602,6 +572,8 @@ queueSetMaxFileSize(queue_t *pThis, size_t iMaxFileSize)
}
pThis->iMaxFileSize = iMaxFileSize;
+// TODO: check queue mode! also in other places!!!
+ CHKiRet(strmSetiMaxFileSize(pThis->tVars.disk.pWrite, iMaxFileSize));
finalize_it:
return iRet;
diff --git a/stream.c b/stream.c
index caf78bec..0f224787 100644
--- a/stream.c
+++ b/stream.c
@@ -117,6 +117,7 @@ rsRetVal strmNextFile(strm_t *pThis)
{
DEFiRet;
+dbgprintf("strmNextFile in\n");
assert(pThis != NULL);
CHKiRet(strmCloseFile(pThis));
@@ -127,6 +128,7 @@ rsRetVal strmNextFile(strm_t *pThis)
pThis->iCurrFNum = (pThis->iCurrFNum + 1) % 1000000;
finalize_it:
+dbgprintf("strmNextFile out %d\n", iRet);
return iRet;
}
@@ -143,6 +145,7 @@ finalize_it:
rsRetVal strmReadChar(strm_t *pThis, uchar *pC)
{
DEFiRet;
+ int bRun;
assert(pThis != NULL);
assert(pC != NULL);
@@ -162,13 +165,22 @@ rsRetVal strmReadChar(strm_t *pThis, uchar *pC)
/* do we need to obtain a new buffer */
if(pThis->iBufPtr >= pThis->iBufPtrMax) {
- /* read */
- pThis->iBufPtrMax = read(pThis->fd, pThis->pIOBuf, STRM_IOBUF_SIZE);
- dbgprintf("strmReadChar read %d bytes from file %d\n", pThis->iBufPtrMax, pThis->fd);
- if(pThis->iBufPtrMax == 0)
- ABORT_FINALIZE(RS_RET_EOF);
- else if(pThis->iBufPtrMax < 0)
- ABORT_FINALIZE(RS_RET_IO_ERROR);
+ /* We need to try read at least twice because we may run into EOF and need to switch files. */
+ bRun = 1;
+ while(bRun) {
+ /* first check if we need to (re)open the file (we may have switched to a new one!) */
+ CHKiRet(strmOpenFile(pThis, O_RDONLY, 0600)); // TODO: open modes!
+ pThis->iBufPtrMax = read(pThis->fd, pThis->pIOBuf, STRM_IOBUF_SIZE);
+ dbgprintf("strmReadChar read %d bytes from file %d\n", pThis->iBufPtrMax, pThis->fd);
+ if(pThis->iBufPtrMax == 0) {
+// TODO: only when single file! ABORT_FINALIZE(RS_RET_EOF);
+ dbgprintf("Stream 0x%lx: EOF on file %d\n", (unsigned long) pThis, pThis->fd);
+ CHKiRet(strmNextFile(pThis));
+ } else if(pThis->iBufPtrMax < 0)
+ ABORT_FINALIZE(RS_RET_IO_ERROR);
+ else
+ bRun = 0; /* exit loop */
+ }
/* if we reach this point, we had a good read */
pThis->iBufPtr = 0;
}
@@ -316,8 +328,11 @@ dbgprintf("strmWrite()\n");
/* TODO: handle error case -- rgerhards, 2008-01-07 */
pThis->iCurrOffs += iWritten;
- if(pThis->iCurrOffs >= pThis->iMaxFileSize)
+ if(pThis->iCurrOffs >= pThis->iMaxFileSize) {
+ dbgprintf("Stream 0x%lx: max file size %ld reached for %d, now %ld - starting new file\n",
+ (unsigned long) pThis, (long) pThis->iMaxFileSize, pThis->fd, (long) pThis->iCurrOffs);
CHKiRet(strmNextFile(pThis));
+ }
finalize_it:
return iRet;
@@ -327,6 +342,7 @@ finalize_it:
/* property set methods */
/* simple ones first */
DEFpropSetMeth(strm, bDeleteOnClose, int)
+DEFpropSetMeth(strm, iMaxFileSize, int)
/* set the stream's file prefix
* The passed-in string is duplicated. So if the caller does not need
@@ -355,6 +371,33 @@ finalize_it:
}
+/* set the stream's directory
+ * The passed-in string is duplicated. So if the caller does not need
+ * it any longer, it must free it.
+ * rgerhards, 2008-01-09
+ */
+rsRetVal
+strmSetDir(strm_t *pThis, uchar *pszDir, size_t iLenDir)
+{
+ DEFiRet;
+
+ assert(pThis != NULL);
+ assert(pszDir != NULL);
+
+ if(iLenDir < 1)
+ ABORT_FINALIZE(RS_RET_FILE_PREFIX_MISSING);
+
+ if((pThis->pszDir = malloc(sizeof(uchar) * iLenDir + 1)) == NULL)
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+
+ memcpy(pThis->pszDir, pszDir, iLenDir + 1); /* always think about the \0! */
+ pThis->lenDir = iLenDir;
+
+finalize_it:
+ return iRet;
+}
+
+
/* Initialize the stream class. Must be called as the very first method
* before anything else is called inside this class.
* rgerhards, 2008-01-09
diff --git a/stream.h b/stream.h
index a8ace8a6..dd8f7d5b 100644
--- a/stream.h
+++ b/stream.h
@@ -43,7 +43,7 @@
#define STREAM_H_INCLUDED
#include <pthread.h>
-#include "obj.h"
+#include "obj-types.h"
#include "stream.h"
/* stream types */
@@ -52,7 +52,7 @@ typedef enum {
} strmType_t;
/* The strm_t data structure */
-typedef struct {
+typedef struct strm_s {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
strmType_t sType;
int fd; /* the file descriptor, -1 if closed */
@@ -86,7 +86,9 @@ rsRetVal strmWrite(strm_t *pThis, uchar *pBuf, size_t lenBuf);
rsRetVal strmNextFile(strm_t *pThis);
rsRetVal strmOpenFile(strm_t *pThis, int flags, mode_t mode);
rsRetVal strmSetFilePrefix(strm_t *pThis, uchar *pszPrefix, size_t iLenPrefix);
+rsRetVal strmSetDir(strm_t *pThis, uchar *pszDir, size_t iLenDir);
PROTOTYPEObjClassInit(strm);
PROTOTYPEpropSetMeth(strm, bDeleteOnClose, int);
+PROTOTYPEpropSetMeth(strm, iMaxFileSize, int);
#endif /* #ifndef STREAM_H_INCLUDED */