syslog.c revision 135446
1/*
2 * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2001  Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/* $Id: syslog.c,v 1.1.12.3 2004/03/08 09:04:57 marka Exp $ */
19
20#include <config.h>
21
22#include <stdlib.h>
23#include <string.h>
24#include <syslog.h>
25
26#include <isc/result.h>
27#include <isc/syslog.h>
28#include <isc/util.h>
29
30static struct dsn_c_pvt_sfnt {
31	int val;
32	const char *strval;
33} facilities[] = {
34	{ LOG_KERN,			"kern" },
35	{ LOG_USER,			"user" },
36	{ LOG_MAIL,			"mail" },
37	{ LOG_DAEMON,			"daemon" },
38	{ LOG_AUTH,			"auth" },
39	{ LOG_SYSLOG,			"syslog" },
40	{ LOG_LPR,			"lpr" },
41#ifdef LOG_NEWS
42	{ LOG_NEWS,			"news" },
43#endif
44#ifdef LOG_UUCP
45	{ LOG_UUCP,			"uucp" },
46#endif
47#ifdef LOG_CRON
48	{ LOG_CRON,			"cron" },
49#endif
50#ifdef LOG_AUTHPRIV
51	{ LOG_AUTHPRIV,			"authpriv" },
52#endif
53#ifdef LOG_FTP
54	{ LOG_FTP,			"ftp" },
55#endif
56	{ LOG_LOCAL0,			"local0"},
57	{ LOG_LOCAL1,			"local1"},
58	{ LOG_LOCAL2,			"local2"},
59	{ LOG_LOCAL3,			"local3"},
60	{ LOG_LOCAL4,			"local4"},
61	{ LOG_LOCAL5,			"local5"},
62	{ LOG_LOCAL6,			"local6"},
63	{ LOG_LOCAL7,			"local7"},
64	{ 0,				NULL }
65};
66
67isc_result_t
68isc_syslog_facilityfromstring(const char *str, int *facilityp) {
69	int i;
70
71	REQUIRE(str != NULL);
72	REQUIRE(facilityp != NULL);
73
74	for (i = 0; facilities[i].strval != NULL; i++) {
75		if (strcasecmp(facilities[i].strval, str) == 0) {
76			*facilityp = facilities[i].val;
77			return (ISC_R_SUCCESS);
78		}
79	}
80	return (ISC_R_NOTFOUND);
81
82}
83