diff options
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | linux/Makefile | 7 | ||||
-rw-r--r-- | master.make | 16 | ||||
-rw-r--r-- | rfc3195d.c | 156 | ||||
-rw-r--r-- | rsyslog.h | 9 | ||||
-rwxr-xr-x | stringbuf.c | 2 | ||||
-rw-r--r-- | syslog.c | 4 |
7 files changed, 183 insertions, 13 deletions
@@ -1,5 +1,7 @@ --------------------------------------------------------------------------- Version 1.11.0 (RGer), 2005-??-?? +- support for receiving messages via RFC 3195; added rfc3195d for that + purpose --------------------------------------------------------------------------- Version 1.10.2 (RGer), 2005-09-27 - added comparison operations in property-based filters: diff --git a/linux/Makefile b/linux/Makefile index 7b1c99e5..4ec862f4 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -30,6 +30,9 @@ FEATURE_DB=0 # Enable regular expressions FEATURE_REGEXP=1 +# Enable RFC 3195 support (REQUIRES LIBLOGGING 0.6.0 or above!) +FEATURE_RFC3195=1 + # Enable debug mode (much slower code) FEATURE_DEBUG=1 @@ -56,6 +59,10 @@ ifeq ($(strip $(FEATURE_REGEXP)), 1) F_REGEXP=-DFEATURE_REGEXP endif +ifeq ($(strip $(FEATURE_RFC3195)), 1) + F_RFC3195=-DFEATURE_RFC3195 +endif + ifeq ($(strip $(FEATURE_DEBUG)), 0) DBG=-DNDEBUG endif diff --git a/master.make b/master.make index 39530d72..e5174b39 100644 --- a/master.make +++ b/master.make @@ -11,7 +11,7 @@ #LDFLAGS= -g -Wall -fno-omit-frame-pointer #CFLAGS= -DSYSV -g -Wall -fno-omit-frame-pointer -CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -I/usr/local/include $(NOLARGEFILE) $(WITHDB) $(F_REGEXP) $(DBG) +CFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -I/usr/local/include $(NOLARGEFILE) $(WITHDB) $(F_REGEXP) $(DBG) $(F_RFC3195) LDFLAGS= -s # There is one report that under an all ELF system there may be a need to @@ -23,6 +23,12 @@ LDFLAGS= -s # file system standard. FSSTND = -DFSSTND +# The following defines tell us where liblogging is located. This +# is only needed if we build with RFC 3195 support. By default, +# liblogging is expected to be present in the our parent directory. +LIBLOGGING_INC=-I../../liblogging/src +LIBLOGGING_BIN=../../liblogging/src/linux/liblogging.a + # The following define establishes the name of the pid file for the # rsyslogd daemon. The library include file (paths.h) defines the # name for the rsyslogd pid to be rsyslog.pid. @@ -33,9 +39,9 @@ SYSLOGD_FLAGS= -DSYSLOG_INET -DSYSLOG_UNIXAF ${FSSTND} \ SYSLOG_FLAGS= -DALLOW_KERNEL_LOGGING .c.o: - ${CC} ${CFLAGS} -c $(VPATH)$*.c + ${CC} ${CFLAGS} ${LIBLOGGING_INC} -c $(VPATH)$*.c -all: syslogd +all: rfc3195d syslogd test: syslog_tst tsyslogd @@ -44,11 +50,15 @@ install: install_man install_exec syslogd: syslogd.o pidfile.o template.o stringbuf.o srUtils.o outchannel.o parse.o ${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o template.o outchannel.o stringbuf.o srUtils.o parse.o ${LIBS} +rfc3195d: rfc3195d.o + ${CC} ${LDFLAGS} -o rfc3195d rfc3195d.o ${LIBLOGGING_BIN} + srUtils.o: srUtils.c srUtils.h liblogging-stub.h rsyslog.h stringbuf.o: stringbuf.c stringbuf.h rsyslog.h parse.o: parse.c parse.h rsyslog.h template.o: template.c template.h stringbuf.h rsyslog.h outchannel.o: outchannel.c outchannel.h stringbuf.h syslogd.h rsyslog.h +rfc3195d.o: rfc3195d.c rsyslog.h syslogd.o: syslogd.c version.h parse.h template.h stringbuf.h outchannel.h syslogd.h rsyslog.h ${CC} ${CFLAGS} ${SYSLOGD_FLAGS} -c $(VPATH)syslogd.c diff --git a/rfc3195d.c b/rfc3195d.c new file mode 100644 index 00000000..d9ae4d50 --- /dev/null +++ b/rfc3195d.c @@ -0,0 +1,156 @@ +/**
+ * testsrvr.cpp : This is a small sample C++ server app
+ * using liblogging. It just demonstrates how things can be
+ * done. It accepts incoming messages and just dumps them
+ * to stdout. It is single-threaded.
+ *
+ * \author Rainer Gerhards <rgerhards@adiscon.com>
+ * \date 2003-08-13
+ * file created.
+ *
+ * Copyright 2003
+ * Rainer Gerhards and Adiscon GmbH. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Adiscon GmbH or Rainer Gerhards
+ * nor the names of its contributors may be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/socket.h>
+#include "rsyslog.h"
+#include "liblogging.h"
+#include "srAPI.h"
+#include "syslogmessage.h"
+
+/* configurable params! */
+#define _PATH_LOGNAME "/dev/log"
+
+/* quick hack, so all can access it. Do NOT do this in your server ;-) */
+static srAPIObj* pAPI;
+
+static int LogFile = -1; /* fd for log */
+static int connected; /* have done connect */
+static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
+
+/*
+ * OPENLOG -- open system log
+ */
+static void openlog()
+{
+ if (LogFile == -1) {
+ SyslogAddr.sa_family = AF_UNIX;
+ strncpy(SyslogAddr.sa_data, _PATH_LOGNAME,
+ sizeof(SyslogAddr.sa_data));
+ LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
+ }
+ if (LogFile != -1 && !connected &&
+ connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family)+
+ strlen(SyslogAddr.sa_data)) != -1)
+ connected = 1;
+}
+
+/* This method is called when a message has been fully received.
+ * In a real sample, you would do all your enqueuing and/or
+ * processing here.
+ *
+ * It is highly recommended that no lengthy processing is done in
+ * this callback. Please see \ref architecture.c for a suggested
+ * threading model.
+ */
+void OnReceive(srAPIObj* pAPI, srSLMGObj* pSLMG)
+{
+ unsigned char *pszRawMsg;
+
+ srSLMGGetRawMSG(pSLMG, &pszRawMsg);
+
+ if (LogFile < 0 || !connected)
+ openlog();
+
+ /* output the message to the local logger */
+ write(LogFile, pszRawMsg, strlen(pszRawMsg));
+
+ printf("RAW:%s\n\n", pszRawMsg);
+}
+
+
+/* As we are single-threaded in this example, we need
+ * one way to shut down the listener running on this
+ * single thread. We use SIG_INT to do so - it effectively
+ * provides a short-lived second thread ;-)
+ */
+void doSIGINT(int i)
+{
+ printf("SIG_INT - shutting down listener. Be patient, can take up to 30 seconds...\n");
+ srAPIShutdownListener(pAPI);
+}
+
+int main(int argc, char* argv[])
+{
+ srRetVal iRet;
+
+# ifdef WIN32
+ _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+# endif
+
+ printf("testsrvr test server - just a quick debuging aid and sample....\n");
+ printf("Compiled with liblogging version %d.%d.%d.\n", LIBLOGGING_VERSION_MAJOR, LIBLOGGING_VERSION_MINOR, LIBLOGGING_VERSION_SUBMINOR);
+ printf("See http://www.monitorware.com/liblogging/ for updates.\n");
+ printf("Listening for incoming requests....\n");
+
+ signal(SIGINT, doSIGINT);
+
+ if((pAPI = srAPIInitLib()) == NULL)
+ {
+ printf("Error initializing lib!\n");
+ exit(1);
+ }
+
+ if((iRet = srAPISetupListener(pAPI, OnReceive)) != SR_RET_OK)
+ {
+ printf("Error %d setting up listener!\n", iRet);
+ exit(100);
+ }
+
+ /* now move the listener to running state. Control will only
+ * return after SIG_INT.
+ */
+ if((iRet = srAPIRunListener(pAPI)) != SR_RET_OK)
+ {
+ printf("Error %d running the listener!\n", iRet);
+ exit(100);
+ }
+
+ /** control will reach this point after SIG_INT */
+
+ srAPIExitLib(pAPI);
+ return 0;
+}
+
@@ -9,8 +9,7 @@ /* ############################################################# * * # Config Settings # * * ############################################################# */ -/* from liblogging config.h */ -#define STRINGBUF_ALLOC_INCREMENT 128 +#define RS_STRINGBUF_ALLOC_INCREMENT 128 /* ############################################################# * * # End Config Settings # * @@ -53,11 +52,11 @@ typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */ */ enum rsObjectID { - OID_Freed = -1, /**< assigned, when an object is freed. If this + OIDrsFreed = -1, /**< assigned, when an object is freed. If this * is seen during a method call, this is an * invalid object pointer! */ - OID_Invalid = 0, /**< value created by calloc(), so do not use ;) */ + OIDrsInvalid = 0, /**< value created by calloc(), so do not use ;) */ /* The 0xEFCD is a debug aid. It helps us find object IDs in memory * dumps (on X86, this is CDEF in the dump ;) * If you are on an embedded device and you would like to save space @@ -84,6 +83,6 @@ typedef enum rsObjectID rsObjID; #ifdef NDEBUG #define RSFREEOBJ(x) free(x) #else -#define RSFREEOBJ(x) {(x)->OID = OID_Freed; free(x);} +#define RSFREEOBJ(x) {(x)->OID = OIDrsFreed; free(x);} #endif #endif diff --git a/stringbuf.c b/stringbuf.c index 738a1f81..6d6d122d 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -39,7 +39,7 @@ rsCStrObj *rsCStrConstruct(void) pThis->pszBuf = NULL; pThis->iBufSize = 0; pThis->iStrLen = 0; - pThis->iAllocIncrement = STRINGBUF_ALLOC_INCREMENT; + pThis->iAllocIncrement = RS_STRINGBUF_ALLOC_INCREMENT; return pThis; } @@ -17,10 +17,6 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90"; -#endif /* LIBC_SCCS and not lint */ - /* * SYSLOG -- print message on log file * |