summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--msg.c13
-rw-r--r--obj.c84
-rw-r--r--obj.h5
-rw-r--r--queue.c8
4 files changed, 66 insertions, 44 deletions
diff --git a/msg.c b/msg.c
index f7943307..a224b308 100644
--- a/msg.c
+++ b/msg.c
@@ -380,15 +380,12 @@ msg_t* MsgDup(msg_t* pOld)
* during msg construction - and never again used later.
* rgerhards, 2008-01-03
*/
-static rsRetVal MsgSerialize(msg_t *pThis, uchar **ppOutBuf, size_t *pLenBuf)
+static rsRetVal MsgSerialize(msg_t *pThis, rsCStrObj **ppCStr)
{
DEFiRet;
rsCStrObj *pCStr;
- assert(ppOutBuf != NULL);
- assert(pLenBuf != NULL);
- assert(pThis != NULL);
-
+ assert(ppCStr != NULL);
CHKiRet(objBeginSerialize(&pCStr, (obj_t*) pThis));
objSerializeSCALAR(iProtocolVersion, SHORT);
@@ -411,11 +408,11 @@ static rsRetVal MsgSerialize(msg_t *pThis, uchar **ppOutBuf, size_t *pLenBuf)
objSerializePTR(pCSPROCID, CSTR);
objSerializePTR(pCSMSGID, CSTR);
- CHKiRet(objEndSerialize(pCStr, ppOutBuf));
- pCStr = NULL;
+ CHKiRet(objEndSerialize((&pCStr), (obj_t*) pThis));
+ *ppCStr = pCStr;
finalize_it:
- if(pCStr != NULL)
+ if(iRet != RS_RET_OK && pCStr != NULL)
rsCStrDestruct(pCStr);
return iRet;
diff --git a/obj.c b/obj.c
index 658c301c..dc8a1ca6 100644
--- a/obj.c
+++ b/obj.c
@@ -100,36 +100,21 @@ rsRetVal objInfoSetMethod(objInfo_t *pThis, objMethod_t objMethod, rsRetVal (*pH
/* --------------- object serializiation / deserialization support --------------- */
-/* begin serialization of an object
+/* begin serialization of an object - this is a very simple hook. It once wrote the wrapper,
+ * now it only constructs the string object. We still leave it in here so that we may utilize
+ * it in the future (it is a nice abstraction).
+ * rgerhards, 2008-01-06
*/
rsRetVal objBeginSerialize(rsCStrObj **ppCStr, obj_t *pObj)
{
DEFiRet;
- rsCStrObj *pCStr;
assert(ppCStr != NULL);
assert(pObj != NULL);
- if((pCStr = rsCStrConstruct()) == NULL)
+ if((*ppCStr = rsCStrConstruct()) == NULL)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
- /* cookie-char */
- CHKiRet(rsCStrAppendChar(pCStr, '$'));
- /* serializer version (so far always 1) */
- CHKiRet(rsCStrAppendChar(pCStr, '1'));
- CHKiRet(rsCStrAppendChar(pCStr, ':'));
-
- /* object Name */
- CHKiRet(rsCStrAppendStr(pCStr, objGetName(pObj)));
- CHKiRet(rsCStrAppendChar(pCStr, ':'));
- /* object version */
- CHKiRet(rsCStrAppendInt(pCStr, objGetVersion(pObj)));
-
- /* record trailer */
- CHKiRet(rsCStrAppendChar(pCStr, '\n'));
-
- *ppCStr = pCStr;
-
finalize_it:
return iRet;
}
@@ -152,7 +137,6 @@ rsRetVal objSerializeProp(rsCStrObj *pCStr, uchar *pszPropName, propertyType_t p
* rgerhards, 2008-01-06
*/
if(pUsr == NULL) {
-dbgprintf("ptr is NULL\n");
ABORT_FINALIZE(RS_RET_OK);
}
@@ -178,7 +162,7 @@ dbgprintf("ptr is NULL\n");
break;
case PROPTYPE_CSTR:
pszBuf = rsCStrGetSzStrNoNULL((rsCStrObj *) pUsr);
- lenBuf = strlen((char*) pszBuf);
+ lenBuf = rsCStrLen((rsCStrObj*) pUsr);
break;
case PROPTYPE_SYSLOGTIME:
lenBuf = snprintf((char*) szBuf, sizeof(szBuf), "%d %d %d %d %d %d %d %d %d %c %d %d",
@@ -221,25 +205,65 @@ finalize_it:
}
+static rsRetVal objSerializeHeader(rsCStrObj **ppCStr, obj_t *pObj, rsCStrObj *pCSObjString)
+{
+ DEFiRet;
+ rsCStrObj *pCStr;
+
+ assert(ppCStr != NULL);
+ assert(pObj != NULL);
+
+ if((pCStr = rsCStrConstruct()) == NULL)
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+
+ /* object cookie and serializer version (so far always 1) */
+ CHKiRet(rsCStrAppendStr(pCStr, (uchar*) "$Obj1"));
+
+ /* object type, version and string length */
+ CHKiRet(rsCStrAppendChar(pCStr, ':'));
+ CHKiRet(rsCStrAppendInt(pCStr, objGetObjID(pObj)));
+ CHKiRet(rsCStrAppendChar(pCStr, ':'));
+ CHKiRet(rsCStrAppendInt(pCStr, objGetVersion(pObj)));
+ CHKiRet(rsCStrAppendChar(pCStr, ':'));
+ CHKiRet(rsCStrAppendInt(pCStr, rsCStrLen(pCSObjString)));
+
+ /* and finally we write the object name - this is primarily meant for
+ * human readers. The idea is that it can be easily skipped when reading
+ * the object back in
+ */
+ CHKiRet(rsCStrAppendChar(pCStr, ':'));
+ CHKiRet(rsCStrAppendStr(pCStr, objGetName(pObj)));
+ /* record trailer */
+ CHKiRet(rsCStrAppendChar(pCStr, '\n'));
+
+ *ppCStr = pCStr;
+
+finalize_it:
+ return iRet;
+}
+
+
/* end serialization of an object. The caller receives a
* standard C string, which he must free when no longer needed.
*/
-rsRetVal objEndSerialize(rsCStrObj *pCStr, uchar **ppSz)
+rsRetVal objEndSerialize(rsCStrObj **ppCStr, obj_t *pObj)
{
DEFiRet;
- assert(pCStr != NULL);
+ rsCStrObj *pCStr = NULL;
- assert(pCStr != NULL);
- CHKiRet(rsCStrAppendStr(pCStr, (uchar*) ".EndObj.\n"));
+ assert(ppCStr != NULL);
+ CHKiRet(objSerializeHeader(&pCStr, pObj, *ppCStr));
+
+ CHKiRet(rsCStrAppendStrWithLen(pCStr, rsCStrGetBufBeg(*ppCStr), rsCStrLen(*ppCStr)));
+ CHKiRet(rsCStrAppendStr(pCStr, (uchar*) ".\n"));
CHKiRet(rsCStrFinish(pCStr));
- CHKiRet(rsCStrConvSzStrAndDestruct(pCStr, ppSz, 0));
- pCStr = NULL;
+ rsCStrDestruct(*ppCStr);
+ *ppCStr = pCStr;
finalize_it:
- if(pCStr != NULL)
+ if(iRet != RS_RET_OK && pCStr != NULL)
rsCStrDestruct(pCStr);
-
return iRet;
}
diff --git a/obj.h b/obj.h
index daa6bdee..09919e2d 100644
--- a/obj.h
+++ b/obj.h
@@ -38,7 +38,7 @@ typedef enum { /* do NOT start at 0 to detect uninitialized types after calloc(
PROPTYPE_SYSLOGTIME = 6
} propertyType_t;
-/* object Types */
+/* 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
@@ -74,6 +74,7 @@ typedef struct obj { /* the dummy struct that each derived class can be casted t
#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;
@@ -101,7 +102,7 @@ rsRetVal objInfoConstruct(objInfo_t **ppThis, objID_t objID, uchar *pszName, int
rsRetVal objInfoSetMethod(objInfo_t *pThis, objMethod_t objMethod, rsRetVal (*pHandler)(void*));
rsRetVal objBeginSerialize(rsCStrObj **ppCStr, obj_t *pObj);
rsRetVal objSerializePsz(rsCStrObj *pCStr, uchar *psz, size_t len);
-rsRetVal objEndSerialize(rsCStrObj *pCStr, uchar **ppSz);
+rsRetVal objEndSerialize(rsCStrObj **ppCStr, obj_t *pObj);
rsRetVal objSerializeProp(rsCStrObj *pCStr, uchar *pszPropName, propertyType_t propType, void *pUsr);
#endif /* #ifndef OBJ_H_INCLUDED */
diff --git a/queue.c b/queue.c
index ffd007e2..17e33675 100644
--- a/queue.c
+++ b/queue.c
@@ -40,6 +40,7 @@
#include "rsyslog.h"
#include "syslogd.h"
#include "queue.h"
+#include "stringbuf.h"
#include "srUtils.h"
/* static data */
@@ -233,13 +234,12 @@ rsRetVal qAddDisk(queue_t *pThis, void* pUsr)
{
DEFiRet;
int i;
- long lenBuf;
- uchar *pBuf;
+ rsCStrObj *pCStr;
assert(pThis != NULL);
dbgprintf("writing to file %d\n", pThis->tVars.disk.fd);
- CHKiRet((objSerialize(pUsr))(pUsr, &pBuf, &lenBuf)); // TODO: hier weiter machen!
- i = write(pThis->tVars.disk.fd, pBuf, strlen((char*) pBuf));
+ CHKiRet((objSerialize(pUsr))(pUsr, &pCStr)); // TODO: hier weiter machen!
+ i = write(pThis->tVars.disk.fd, rsCStrGetBufBeg(pCStr), rsCStrLen(pCStr));
dbgprintf("write wrote %d bytes, errno: %d, err %s\n", i, errno, strerror(errno));
finalize_it: