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.
23 #include <netinet/in.h>
26 #define SYSLOG_NAMES 1
35 * Removes all leading and trailing whitespaces of a string.
36 * @param String The string to remove whitespaces from.
39 ngt_TrimStr(char *String)
43 assert(String != NULL);
47 /* Remove whitespaces at the beginning of the string ... */
48 while (*start == ' ' || *start == '\t' ||
49 *start == '\n' || *start == '\r')
57 /* ... and at the end: */
58 end = strchr(start, '\0');
60 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
64 /* New trailing NULL byte */
67 memmove(String, start, (size_t)(end - start)+1);
72 * Convert a string to uppercase letters.
75 ngt_UpperStr(char *String)
79 assert(String != NULL);
91 * Convert a string to lowercase letters.
94 ngt_LowerStr(char *String)
98 assert(String != NULL);
102 *ptr = tolower(*ptr);
110 ngt_TrimLastChr( char *String, const char Chr)
112 /* If last character in the string matches Chr, remove it.
113 * Empty strings are handled correctly. */
117 assert(String != NULL);
119 len = strlen(String);
125 if(String[len] == Chr)
127 } /* ngt_TrimLastChr */
133 #ifndef INTERNAL_MARK
136 typedef struct _code {
142 CODE facilitynames[] = {
144 { "auth", LOG_AUTH },
147 { "authpriv", LOG_AUTHPRIV },
150 { "cron", LOG_CRON },
153 { "daemon", LOG_DAEMON },
162 { "mail", LOG_MAIL },
165 { "news", LOG_NEWS },
168 { "uucp", LOG_UUCP },
171 { "user", LOG_USER },
174 { "local0", LOG_LOCAL0 },
175 { "local1", LOG_LOCAL1 },
176 { "local2", LOG_LOCAL2 },
177 { "local3", LOG_LOCAL3 },
178 { "local4", LOG_LOCAL4 },
179 { "local5", LOG_LOCAL5 },
180 { "local6", LOG_LOCAL6 },
181 { "local7", LOG_LOCAL7 },
190 *ngt_SyslogFacilityName(int Facility)
193 while(facilitynames[i].c_name) {
194 if (facilitynames[i].c_val == Facility)
195 return facilitynames[i].c_name;
203 ngt_SyslogFacilityID(char *Name, int DefaultFacility)
206 while(facilitynames[i].c_name) {
207 if (strcasecmp(facilitynames[i].c_name, Name) == 0)
208 return facilitynames[i].c_val;
211 return DefaultFacility;