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);
95 * Convert a string to lowercase letters.
98 ngt_LowerStr(char *String)
102 assert(String != NULL);
106 *ptr = tolower(*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 assert(String != NULL);
142 static const char chars[] =
143 "0123456789ABCDEFGHIJKLMNO"
144 "PQRSTUVWXYZabcdefghijklmn"
145 "opqrstuvwxyz!\"#$&'()*+,-"
149 gettimeofday(&t, NULL);
150 srand((unsigned)(t.tv_usec * t.tv_sec));
152 for (size_t i = 0; i < len; ++i) {
153 String[i] = chars[rand() % (sizeof(chars) - 1)];
159 } /* ngt_RandomStr */
165 #ifndef INTERNAL_MARK
168 typedef struct _code {
174 CODE facilitynames[] = {
176 { "auth", LOG_AUTH },
179 { "authpriv", LOG_AUTHPRIV },
182 { "cron", LOG_CRON },
185 { "daemon", LOG_DAEMON },
194 { "mail", LOG_MAIL },
197 { "news", LOG_NEWS },
200 { "uucp", LOG_UUCP },
203 { "user", LOG_USER },
206 { "local0", LOG_LOCAL0 },
207 { "local1", LOG_LOCAL1 },
208 { "local2", LOG_LOCAL2 },
209 { "local3", LOG_LOCAL3 },
210 { "local4", LOG_LOCAL4 },
211 { "local5", LOG_LOCAL5 },
212 { "local6", LOG_LOCAL6 },
213 { "local7", LOG_LOCAL7 },
222 ngt_SyslogFacilityName(int Facility)
225 while(facilitynames[i].c_name) {
226 if (facilitynames[i].c_val == Facility)
227 return facilitynames[i].c_name;
235 ngt_SyslogFacilityID(char *Name, int DefaultFacility)
238 while(facilitynames[i].c_name) {
239 if (strcasecmp(facilitynames[i].c_name, Name) == 0)
240 return facilitynames[i].c_val;
243 return DefaultFacility;