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.
27 #include <netinet/in.h>
30 #define SYSLOG_NAMES 1
39 * Removes all leading and trailing whitespaces of a string.
40 * @param String The string to remove whitespaces from.
43 ngt_TrimStr(char *String)
47 assert(String != NULL);
51 /* Remove whitespaces at the beginning of the string ... */
52 while (*start == ' ' || *start == '\t' ||
53 *start == '\n' || *start == '\r')
61 /* ... and at the end: */
62 end = strchr(start, '\0');
64 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
68 /* New trailing NULL byte */
71 memmove(String, start, (size_t)(end - start)+1);
76 * Convert a string to uppercase letters.
79 ngt_UpperStr(char *String)
83 assert(String != NULL);
87 *ptr = toupper((int)*ptr);
95 * Convert a string to lowercase letters.
98 ngt_LowerStr(char *String)
102 assert(String != NULL);
106 *ptr = tolower((int)*ptr);
114 ngt_TrimLastChr( char *String, const char Chr)
116 /* If last character in the string matches Chr, remove it.
117 * Empty strings are handled correctly. */
121 assert(String != NULL);
123 len = strlen(String);
129 if(String[len] == Chr)
131 } /* ngt_TrimLastChr */
135 * Fill a String with random chars
138 ngt_RandomStr(char *String, const size_t len)
140 static const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$&'()*+,-./:;<=>?@[\\]^_`";
144 assert(String != NULL);
146 gettimeofday(&t, NULL);
147 srand((unsigned)(t.tv_usec * t.tv_sec));
149 for (i = 0; i < len; ++i) {
150 String[i] = chars[rand() % (sizeof(chars) - 1)];
155 } /* ngt_RandomStr */
161 #ifndef INTERNAL_MARK
164 typedef struct _code {
170 CODE facilitynames[] = {
172 { "auth", LOG_AUTH },
175 { "authpriv", LOG_AUTHPRIV },
178 { "cron", LOG_CRON },
181 { "daemon", LOG_DAEMON },
190 { "mail", LOG_MAIL },
193 { "news", LOG_NEWS },
196 { "uucp", LOG_UUCP },
199 { "user", LOG_USER },
202 { "local0", LOG_LOCAL0 },
203 { "local1", LOG_LOCAL1 },
204 { "local2", LOG_LOCAL2 },
205 { "local3", LOG_LOCAL3 },
206 { "local4", LOG_LOCAL4 },
207 { "local5", LOG_LOCAL5 },
208 { "local6", LOG_LOCAL6 },
209 { "local7", LOG_LOCAL7 },
218 ngt_SyslogFacilityName(int Facility)
221 while(facilitynames[i].c_name) {
222 if (facilitynames[i].c_val == Facility)
223 return facilitynames[i].c_name;
231 ngt_SyslogFacilityID(char *Name, int DefaultFacility)
234 while(facilitynames[i].c_name) {
235 if (strcasecmp(facilitynames[i].c_name, Name) == 0)
236 return facilitynames[i].c_val;
239 return DefaultFacility;