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1_6:1.7 FSL_0_1_5:1.7 FSL_0_1_1:1.7 LMTP2NNTP_1_2a5:1.7 LMTP2NNTP_1_2a4:1.7 LMTP2NNTP_1_2a3:1.7 LMTP2NNTP_1_2a1:1.6 LMTP2NNTP_1_1_1:1.5 LMTP2NNTP_1_1_0:1.5 LMTP2NNTP_1_1b4:1.5 LMTP2NNTP_1_1b3:1.5 L2_CHANNEL_ONLY_REVAMPING_BEFORE:1.6 LMTP2NNTP_1_1b2:1.5 LMTP2NNTP_1_1b1:1.5 L2_0_1_0:1.3; locks; strict; comment @ * @; 1.11 date 2005.10.03.08.08.11; author rse; state Exp; branches; next 1.10; 1.10 date 2005.01.24.15.03.18; author rse; state Exp; branches; next 1.9; 1.9 date 2003.01.06.11.41.52; author rse; state Exp; branches; next 1.8; 1.8 date 2002.07.30.19.08.25; author rse; state Exp; branches; next 1.7; 1.7 date 2002.01.02.17.07.38; author rse; state Exp; branches; next 1.6; 1.6 date 2001.10.31.16.47.05; author ms; state Exp; branches; next 1.5; 1.5 date 2001.10.09.15.34.55; author rse; state Exp; branches; next 1.4; 1.4 date 2001.10.09.14.03.04; author ms; state Exp; branches; next 1.3; 1.3 date 2001.09.13.12.19.45; author thl; state Exp; branches; next 1.2; 1.2 date 2001.09.06.14.37.53; author rse; state Exp; branches; next 1.1; 1.1 date 2001.09.05.13.32.04; author thl; state Exp; branches; next ; desc @@ 1.11 log @Adjust copyright messages for new year 2005. @ text @/* ** OSSP l2 - Flexible Logging ** Copyright (c) 2001-2005 Cable & Wireless ** Copyright (c) 2001-2005 The OSSP Project ** Copyright (c) 2001-2005 Ralf S. Engelschall ** ** This file is part of OSSP l2, a flexible logging library which ** can be found at http://www.ossp.org/pkg/lib/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_ut_level.c: level mask transformations */ #include "l2.h" #include "l2_p.h" #include #include static struct { l2_level_t level; char *string; } l2s_table[] = { { L2_LEVEL_PANIC, "panic" }, { L2_LEVEL_CRITICAL, "critical" }, { L2_LEVEL_ERROR, "error" }, { L2_LEVEL_WARNING, "warning" }, { L2_LEVEL_NOTICE, "notice" }, { L2_LEVEL_INFO, "info" }, { L2_LEVEL_TRACE, "trace" }, { L2_LEVEL_DEBUG, "debug" }, { 0, NULL } }; l2_result_t l2_util_l2s(char *string, size_t maxlen, int sep, unsigned int levelmask) { char hexbuf[2+(sizeof(unsigned int)*2)+1]; int len; int i; int l; len = maxlen; string[0] = '\0'; for (i = 0; l2s_table[i].level != 0; i++) { if (levelmask & l2s_table[i].level) { levelmask &= ~(l2s_table[i].level); l = strlen(l2s_table[i].string) + 1; if (len < l) return L2_ERR_MEM; sprintf(string+(maxlen-len), "%s%c", l2s_table[i].string, sep); len -= l; } } if (levelmask != 0) { sprintf(hexbuf, "0x%x", levelmask); l = strlen(hexbuf) + 1; if (len < l) return L2_ERR_MEM; sprintf(string+(maxlen-len), "%s%c", hexbuf, sep); len -= l; } /* remove trailing comma */ if ((maxlen-len) > 0) string[(maxlen-len)-1] = '\0'; return L2_OK; } static unsigned int hexval(const char *cpB, const char *cpE) { unsigned int hv; unsigned int nibble; hv = 0; while (cpB < cpE) { nibble = tolower((unsigned int)(*cpB++)); if (isdigit(nibble)) nibble = nibble - '0'; else nibble = nibble - 'a'; hv = ((hv << 4) | nibble); } return hv; } static int myishexnumber(int c) { if (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) return 1; return 0; } l2_result_t l2_util_s2l(const char *string, size_t maxlen, int sep, unsigned int *levelmask) { const char *cpB; const char *cpE; int bFound; int i; *levelmask = 0; cpE = string; while (1) { cpB = cpE; if (cpB >= (string+maxlen)) break; if ((int)(*cpB) == sep) cpB++; for (cpE = cpB; cpE < (string+maxlen) && (int)(*cpE) != sep; cpE++) ; if (cpE > (string+maxlen)) break; bFound = 0; for (i = 0; l2s_table[i].level != 0; i++) { if (strncasecmp(cpB, l2s_table[i].string, cpE-cpB) == 0) { *levelmask |= l2s_table[i].level; bFound = 1; break; } } if (!bFound) { if ((cpE > cpB+2) && strncasecmp(cpB, "0x", 2) == 0 && myishexnumber((int)(*(cpB+2)))) { *levelmask |= hexval(cpB+2, cpE); } else return L2_ERR_ARG; } } return L2_OK; } @ 1.10 log @Adjust copyright messages for new year 2005. @ text @d3 3 a5 3 ** Copyright (c) 2001-2004 Cable & Wireless ** Copyright (c) 2001-2004 The OSSP Project ** Copyright (c) 2001-2004 Ralf S. Engelschall @ 1.9 log @- remove trailing whitespaces - adjust copyright messages - consistently use "OSSP l2" - consistently talk about "Flexible Logging" - use standard OSSP ASCII-art @ text @d3 3 a5 3 ** Copyright (c) 2001-2003 Cable & Wireless Deutschland GmbH ** Copyright (c) 2001-2003 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2003 Ralf S. Engelschall @ 1.8 log @polish for release @ text @d2 4 a5 3 ** OSSP l2 - Logging Library ** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) d7 1 a7 1 ** This file is part of OSSP L2, a flexible logging library which d81 1 a81 1 string[(maxlen-len)-1] = '\0'; d94 1 a94 1 if (isdigit(nibble)) @ 1.7 log @bump copyright year @ text @d2 1 a2 1 ** L2 - OSSP Logging Library d7 1 a7 1 ** can be found at http://www.ossp.org/pkg/l2/. @ 1.6 log @Bug fixes, correction of sys/type.h inclusion, rid of warning errors. @ text @d3 2 a4 2 ** Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.5 log @Veto: back-out latest level-related changes. Sorry, Michael, the padding has to be done in l2_ch_prefix.c only. @ text @d60 1 a60 1 for (i = 0; l2s_table[i].level != NULL; i++) { d129 1 a129 1 for (i = 0; l2s_table[i].level != NULL; i++) { @ 1.4 log @Corrected prefix functionality, because channel write operations do not take level masks as input. @ text @d51 1 a51 1 l2_result_t l2_util_l2s(char *string, size_t maxlen, l2_level_t level) d53 4 a56 1 int len, i, j, l; d58 1 d60 8 a67 7 len = i = j = l = 0; for (i = 0; l2s_table[i].level != NULL; i++) { /* loop through levels */ if (level & l2s_table[i].level) { if (j != 0) return L2_ERR_ARG; /* level has matched more than one string */ else j = i; /* index the given level to its corresponding string */ a68 4 l = strlen(l2s_table[i].string); if (l > len) len = l; /* len is the size of the largest level string */ d70 11 a81 11 if (len + 1 > maxlen) return L2_ERR_MEM; else sprintf(string, "%s", l2s_table[j].string); for (i = 0; string[i] != '\0'; i++) /* process string to dynamically pad */ ; /* with spaces in order to line up */ while (i < len){ /* small level string text with the */ string[i++] = ' '; /* larger ones */ } string[i] = '\0'; /* don't forget to put back the EOL */ d109 1 a109 1 l2_result_t l2_util_s2l(const char *string, size_t maxlen, l2_level_t *level) d111 2 d116 11 a126 6 *level = 0; bFound = 0; for (i = 0; l2s_table[i].level != NULL; i++) { if (strcasecmp(string, l2s_table[i].string) == 0) { *level = l2s_table[i].level; bFound = 1; d128 7 d136 6 a141 4 } if (!bFound) { if (strncasecmp(string, "0x", 2) == 0 && myishexnumber((int)(*(string+2)))) { *level = hexval(string+2, string + strlen(string)); a142 2 else return L2_ERR_ARG; @ 1.3 log @portability fixes for solaris @ text @d51 1 a51 1 l2_result_t l2_util_l2s(char *string, size_t maxlen, int sep, unsigned int levelmask) d53 1 a53 4 char hexbuf[2+(sizeof(unsigned int)*2)+1]; int len; int i; int l; a54 1 len = maxlen; d56 7 a62 8 for (i = 0; l2s_table[i].level != NULL; i++) { if (levelmask & l2s_table[i].level) { levelmask &= ~(l2s_table[i].level); l = strlen(l2s_table[i].string) + 1; if (len < l) return L2_ERR_MEM; sprintf(string+(maxlen-len), "%s%c", l2s_table[i].string, sep); len -= l; d64 4 d69 10 a78 7 if (levelmask != 0) { sprintf(hexbuf, "0x%x", levelmask); l = strlen(hexbuf) + 1; if (len < l) return L2_ERR_MEM; sprintf(string+(maxlen-len), "%s%c", hexbuf, sep); len -= l; d80 1 a80 4 /* remove trailing comma */ if ((maxlen-len) > 0) string[(maxlen-len)-1] = '\0'; d108 1 a108 1 l2_result_t l2_util_s2l(const char *string, size_t maxlen, int sep, unsigned int *levelmask) a109 2 const char *cpB; const char *cpE; d113 6 a118 11 *levelmask = 0; cpE = string; while (1) { cpB = cpE; if (cpB >= (string+maxlen)) break; if ((int)(*cpB) == sep) cpB++; for (cpE = cpB; cpE < (string+maxlen) && (int)(*cpE) != sep; cpE++) ; if (cpE > (string+maxlen)) a119 7 bFound = 0; for (i = 0; l2s_table[i].level != NULL; i++) { if (strncasecmp(cpB, l2s_table[i].string, cpE-cpB) == 0) { *levelmask |= l2s_table[i].level; bFound = 1; break; } d121 4 a124 6 if (!bFound) { if ((cpE > cpB+2) && strncasecmp(cpB, "0x", 2) == 0 && myishexnumber((int)(*(cpB+2)))) { *levelmask |= hexval(cpB+2, cpE); } else return L2_ERR_ARG; d126 2 @ 1.2 log @Replace generic L2_ERROR with more granular L2_ERR_XXX and make sure that we always check with "!= L2_OK". @ text @d102 7 d137 1 a137 1 if ((cpE > cpB+2) && strncasecmp(cpB, "0x", 2) == 0 && ishexnumber((int)(*(cpB+2)))) { @ 1.1 log @added to utility functions for transforming levelmask between string and int and vice versa @ text @d65 1 a65 1 return L2_ERROR; d74 1 a74 1 return L2_ERROR; d134 1 a134 1 return L2_ERROR; @