head 1.6; access; symbols LMTP2NNTP_1_1_1:1.5 LMTP2NNTP_1_1_0:1.5 LMTP2NNTP_1_1b4:1.5 LMTP2NNTP_1_1b3:1.5 LMTP2NNTP_1_1b2:1.5 LMTP2NNTP_1_1b1:1.5 L2_0_1_0:1.5; locks; strict; comment @ * @; 1.6 date 2001.10.31.21.27.57; author rse; state dead; branches; next 1.5; 1.5 date 2001.08.26.13.02.27; author ms; state Exp; branches; next 1.4; 1.4 date 2001.08.24.15.15.47; author ms; state Exp; branches; next 1.3; 1.3 date 2001.08.23.05.32.45; author ms; state Exp; branches; next 1.2; 1.2 date 2001.08.22.18.08.13; author ms; state Exp; branches; next 1.1; 1.1 date 2001.08.20.17.17.16; author ms; state Exp; branches; next ; desc @@ 1.6 log @remove code obsoleted by l2_test.c @ text @/* ** L2 - OSSP Logging Library ** Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) ** ** This file is part of OSSP L2, a flexible logging library which ** can be found at http://www.ossp.org/pkg/l2/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** 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. ** ** l2_epreuve.c: channel-level test code ** */ #include "l2.h" #include "l2_p.h" #include #define L2_HEXBASE 16 #define L2_COMMANDARG 0 #define L2_BUFSIZEARG 1 #define L2_FILEARG 2 #define L2_MESSAGEARG 3 #define L2_VONBUFSTRING " in L2_buffer.\n" #define L2_VONFILESTRING " von L2_file Kanal.\n" #define L2_VONL2LIB " L2Lib" #define L2_VONSYSLOGSTRING " von L2_syslog Kanal.\n" void throwup(char *); int trybuf(char **); int trysyslog(char **); int tryfile(char **); /*--------------------------------------------------------*/ /* void throwup(char *pszError) */ /* Quick exception kludge */ /*--------------------------------------------------------*/ void throwup(char *pszError) { fprintf(stderr, pszError); exit(1); } /*--------------------------------------------------------*/ /* void trybuf(char *pszArgs[]) */ /* Test logic for the buffer channel handler */ /*--------------------------------------------------------*/ int trybuf(char *pszArgs[]) { int iRet = 0; /* for checking return value */ int iMsgSize = 0; /* holds the message size */ char *pszMsgIn = NULL; /* string we pass to ch_write */ l2_channel_t *pMyBChannel = NULL; /* handle to channel instance */ l2_handler_t *g_pBufferHandler = &l2_handler_buffer; fprintf(stdout, "Trying buffer channel handler...\n"); pMyBChannel = l2_channel_create(g_pBufferHandler); if (pMyBChannel == NULL) return 1; /* Params "size", */ iRet = l2_channel_configure(pMyBChannel, "size",\ strtol(pszArgs[L2_BUFSIZEARG], NULL, L2_HEXBASE)); if (iRet != L2_OK) return 1; iRet = l2_channel_open(pMyBChannel); if (iRet != L2_OK) return 1; /* Need to add extra bytes to string length to allow for the text we add */ iMsgSize = strlen(pszArgs[L2_MESSAGEARG]); pszMsgIn = malloc(iMsgSize); strcpy(pszMsgIn, pszArgs[L2_MESSAGEARG]); iRet = l2_channel_write(pMyBChannel, pszMsgIn, iMsgSize); if (iRet != L2_OK) return 1; free(pszMsgIn); /* We are breaking an opaque data type to examine its contents by */ /* casting it. ANSI C allows this hack, but it's not good practice. */ fprintf(stderr, "0x%X octets Speichersize.\n",\ (int)(*((char **)pMyBChannel->context.vp + 2))); fprintf(stderr, *(char **)pMyBChannel->context.vp); fprintf(stderr, " von de Buffer\n"); iRet = l2_channel_flush(pMyBChannel); if (iRet != L2_OK) return 1; iRet = l2_channel_close(pMyBChannel); if (iRet != L2_OK) return 1; iRet = l2_channel_destroy(pMyBChannel); if (iRet != L2_OK) return 1; return 0; /* All stages of execution completed successfully */ } /*--------------------------------------------------------*/ /* void trysyslog(char *pszArgs[]) */ /* Test logic for the syslog channel handler */ /*--------------------------------------------------------*/ int trysyslog(char *pszArgs[]) { int iRet = 0; int iMsgSize = 0; char *pszMsgIn = NULL; l2_channel_t *pMySChannel = NULL; l2_handler_t *g_pSLogHandler = &l2_handler_syslog; fprintf(stdout, "Trying syslog channel handler...\n"); pMySChannel = l2_channel_create(g_pSLogHandler); if (pMySChannel == NULL) return 1; /* Params "ident", , "logopts", , "facility", */ /* "priority", , "maskpriority", */ iRet = l2_channel_configure(pMySChannel, "ident", L2_VONL2LIB,\ "logopts", (LOG_PID|LOG_CONS), "facility", LOG_USER, "priority",\ (LOG_CRIT|LOG_ALERT|LOG_NOTICE), "maskpriority", 0xFFFFFFFF); if (iRet != L2_OK) return 1; iRet = l2_channel_open(pMySChannel); if (iRet != L2_OK) return 1; /* Need to add n bytes to string length to allow for the text we add */ iMsgSize = strlen(pszArgs[L2_MESSAGEARG]) + strlen(L2_VONSYSLOGSTRING); pszMsgIn = malloc(iMsgSize); strcpy(pszMsgIn, pszArgs[L2_MESSAGEARG]); strcat(pszMsgIn, L2_VONSYSLOGSTRING); iRet = l2_channel_write(pMySChannel, pszMsgIn, iMsgSize); if (iRet != L2_OK) return 1; free(pszMsgIn); iRet = l2_channel_flush(pMySChannel); if (iRet != L2_OK) return 1; iRet = l2_channel_close(pMySChannel); if (iRet != L2_OK) return 1; iRet = l2_channel_destroy(pMySChannel); if (iRet != L2_OK) return 1; return 0; /* All stages of execution completed successfully */ } /*--------------------------------------------------------*/ /* void tryfile(char *pszArgs[]) */ /* Test logic for the file channel handler */ /*--------------------------------------------------------*/ int tryfile(char *pszArgs[]) { int iRet = 0; int iMsgSize = 0; char *pszMsgIn = NULL; l2_channel_t *pMyFChannel = NULL; l2_handler_t *g_pFileHandler = &l2_handler_file; fprintf(stdout, "Trying file channel handler...\n"); pMyFChannel = l2_channel_create(g_pFileHandler); if (pMyFChannel == NULL) return 1; /* Params "path", , "append", , "perm", <0xValue> */ iRet = l2_channel_configure(pMyFChannel, "path", pszArgs[L2_FILEARG],\ "append", TRUE, "perm", 0x755); if (iRet != L2_OK) return 1; iRet = l2_channel_open(pMyFChannel); if (iRet != L2_OK) return 1; /* Need to add n bytes to string length to allow for the text we add */ iMsgSize = strlen(pszArgs[L2_MESSAGEARG]) + strlen(L2_VONFILESTRING); pszMsgIn = malloc(iMsgSize); strcpy(pszMsgIn, pszArgs[L2_MESSAGEARG]); strcat(pszMsgIn, L2_VONFILESTRING); iRet = l2_channel_write(pMyFChannel, pszMsgIn, iMsgSize); if (iRet != L2_OK) return 1; free(pszMsgIn); iRet = l2_channel_flush(pMyFChannel); if (iRet != L2_OK) return 1; iRet = l2_channel_close(pMyFChannel); if (iRet != L2_OK) return 1; iRet = l2_channel_destroy(pMyFChannel); if (iRet != L2_OK) return 1; return 0; /* All stages of execution completed successfully */ } /*--------------------------------------------------------*/ /* int main(int argc, char *argv[]) */ /* Main program code */ /*--------------------------------------------------------*/ int main(int argc, char *argv[]) { if (argc < 4) { fprintf(stdout, "Usage: %s 0xbufsize file string\n"\ "Example: %s 2F myoutfile DontPutAnySpacesInThisString\n",\ *argv, *argv); exit(1); } if (trybuf(argv)) { throwup("Buffer channel handler failed!\n"); exit(1); } if (trysyslog(argv)) { throwup("Syslog channel handler failed!\n"); exit(1); } if (tryfile(argv)) { throwup("File channel handler failed!\n"); exit(1); } fprintf(stdout, "Success, exiting.\n"); return 0; } @ 1.5 log @Added code to check syslog channel logic. @ text @@ 1.4 log @Some output format changes. @ text @d33 1 d35 9 a43 7 #define L2_HEXBASE 16 #define L2_COMMANDARG 0 #define L2_BUFSIZEARG 1 #define L2_FILEARG 2 #define L2_MESSAGEARG 3 #define L2_VONBUFSTRING " in L2_buffer.\n" #define L2_VONFILESTRING " von L2_file Kanal.\n" d47 1 d120 55 d192 1 a192 1 /* Params "path", , "append", , "perm", <0xValue>, */ d244 6 @ 1.3 log @Removed problematic after-flush buf-checker. Now we don't verify that the buffer is left unused after an immediate flush operation. @ text @d85 1 a85 1 iMsgSize = strlen(pszArgs[L2_MESSAGEARG]) + strlen(L2_VONBUFSTRING); a87 1 strcat(pszMsgIn, L2_VONBUFSTRING); d98 1 @ 1.2 log @Additionally tests the buffer handler. @ text @a103 10 fprintf(stderr, "\nThis next test should not return any data, because "\ "we are\ntrying to read the buffer after it has been flushed.\n"\ " Buffer contents: "); if (strlen(*(char **)pMyBChannel->context.vp)) fprintf(stderr, *(char **)pMyBChannel->context.vp); else fprintf(stderr, "(Nada)"); fputc('\n', stderr); fputc('\n', stderr); @ 1.1 log @Test file for individual channel testing @ text @d32 13 a44 1 #define SZ_LOGSTRING "String LogTest c'est deja la.\n" d57 71 a127 2 /* int main(int argc, char *argv[]) */ /* Main program code */ d129 1 a129 1 int main(int argc, char *argv[]) d132 3 a134 1 l2_channel_t *pMyChannel = NULL; a136 6 if (argc < 2) { fprintf(stdout, "Usage: %s filepath\n", *argv); exit(1); } d139 3 a141 3 pMyChannel = l2_channel_create(g_pFileHandler); if (pMyChannel == NULL) throwup("Channel create failed!\n"); d144 1 a144 1 iRet = l2_channel_configure(pMyChannel, "path", argv[1],\ d147 1 a147 1 throwup("Channel configure failed!\n"); d149 1 a149 1 iRet = l2_channel_open(pMyChannel); d151 1 a151 1 throwup("Channel open failed!\n"); d153 6 a158 2 /* Need to subtract one to throw away null termination */ iRet = l2_channel_write(pMyChannel, SZ_LOGSTRING, sizeof(SZ_LOGSTRING) - 1); d160 2 a161 1 throwup("Channel write failed!\n"); d163 1 a163 1 iRet = l2_channel_flush(pMyChannel); d165 1 a165 1 throwup("Channel flush failed!\n"); d167 1 a167 1 iRet = l2_channel_close(pMyChannel); d169 1 a169 1 throwup("Channel close failed!\n"); d171 1 a171 1 iRet = l2_channel_destroy(pMyChannel); d173 30 a202 1 throwup("Channel destroy failed!\n"); d204 1 a204 1 fprintf(stdout, "Success, exiting...\n"); @