2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
25 #include <netinet/in.h>
28 #define SYSLOG_NAMES 1
37 * Removes all leading and trailing whitespaces of a string.
38 * @param String The string to remove whitespaces from.
41 ngt_TrimStr(char *String)
45 assert(String != NULL);
49 /* Remove whitespaces at the beginning of the string ... */
50 while (*start == ' ' || *start == '\t' ||
51 *start == '\n' || *start == '\r')
59 /* ... and at the end: */
60 end = strchr(start, '\0');
62 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
66 /* New trailing NULL byte */
69 memmove(String, start, (size_t)(end - start)+1);
74 * Convert a string to uppercase letters.
77 ngt_UpperStr(char *String)
81 assert(String != NULL);
93 * Convert a string to lowercase letters.
96 ngt_LowerStr(char *String)
100 assert(String != NULL);
104 *ptr = tolower(*ptr);
112 ngt_TrimLastChr( char *String, const char Chr)
114 /* If last character in the string matches Chr, remove it.
115 * Empty strings are handled correctly. */
119 assert(String != NULL);
121 len = strlen(String);
127 if(String[len] == Chr)
129 } /* ngt_TrimLastChr */
135 #ifndef INTERNAL_MARK
138 typedef struct _code {
144 CODE facilitynames[] = {
146 { "auth", LOG_AUTH },
149 { "authpriv", LOG_AUTHPRIV },
152 { "cron", LOG_CRON },
155 { "daemon", LOG_DAEMON },
164 { "mail", LOG_MAIL },
167 { "news", LOG_NEWS },
170 { "uucp", LOG_UUCP },
173 { "user", LOG_USER },
176 { "local0", LOG_LOCAL0 },
177 { "local1", LOG_LOCAL1 },
178 { "local2", LOG_LOCAL2 },
179 { "local3", LOG_LOCAL3 },
180 { "local4", LOG_LOCAL4 },
181 { "local5", LOG_LOCAL5 },
182 { "local6", LOG_LOCAL6 },
183 { "local7", LOG_LOCAL7 },
192 ngt_SyslogFacilityName(int Facility)
195 while(facilitynames[i].c_name) {
196 if (facilitynames[i].c_val == Facility)
197 return facilitynames[i].c_name;
205 ngt_SyslogFacilityID(char *Name, int DefaultFacility)
208 while(facilitynames[i].c_name) {
209 if (strcasecmp(facilitynames[i].c_name, Name) == 0)
210 return facilitynames[i].c_val;
213 return DefaultFacility;