xref: /illumos-gate/usr/src/cmd/ipf/lib/common/loglevel.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (C) 1993-2001 by Darren Reed.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
5*7c478bd9Sstevel@tonic-gate  *
6*7c478bd9Sstevel@tonic-gate  * $Id: loglevel.c,v 1.5 2001/06/09 17:09:24 darrenr Exp $
7*7c478bd9Sstevel@tonic-gate  */
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate #include "ipf.h"
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate 
loglevel(cpp,facpri,linenum)12*7c478bd9Sstevel@tonic-gate int loglevel(cpp, facpri, linenum)
13*7c478bd9Sstevel@tonic-gate char **cpp;
14*7c478bd9Sstevel@tonic-gate u_int *facpri;
15*7c478bd9Sstevel@tonic-gate int linenum;
16*7c478bd9Sstevel@tonic-gate {
17*7c478bd9Sstevel@tonic-gate 	int fac, pri;
18*7c478bd9Sstevel@tonic-gate 	char *s;
19*7c478bd9Sstevel@tonic-gate 
20*7c478bd9Sstevel@tonic-gate 	fac = 0;
21*7c478bd9Sstevel@tonic-gate 	pri = 0;
22*7c478bd9Sstevel@tonic-gate 	if (!*++cpp) {
23*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%d: %s\n", linenum,
24*7c478bd9Sstevel@tonic-gate 			"missing identifier after level");
25*7c478bd9Sstevel@tonic-gate 		return -1;
26*7c478bd9Sstevel@tonic-gate 	}
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate 	s = strchr(*cpp, '.');
29*7c478bd9Sstevel@tonic-gate 	if (s) {
30*7c478bd9Sstevel@tonic-gate 		*s++ = '\0';
31*7c478bd9Sstevel@tonic-gate 		fac = fac_findname(*cpp);
32*7c478bd9Sstevel@tonic-gate 		if (fac == -1) {
33*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%d: %s %s\n", linenum,
34*7c478bd9Sstevel@tonic-gate 				"Unknown facility", *cpp);
35*7c478bd9Sstevel@tonic-gate 			return -1;
36*7c478bd9Sstevel@tonic-gate 		}
37*7c478bd9Sstevel@tonic-gate 		pri = pri_findname(s);
38*7c478bd9Sstevel@tonic-gate 		if (pri == -1) {
39*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%d: %s %s\n", linenum,
40*7c478bd9Sstevel@tonic-gate 				"Unknown priority", s);
41*7c478bd9Sstevel@tonic-gate 			return -1;
42*7c478bd9Sstevel@tonic-gate 		}
43*7c478bd9Sstevel@tonic-gate 	} else {
44*7c478bd9Sstevel@tonic-gate 		pri = pri_findname(*cpp);
45*7c478bd9Sstevel@tonic-gate 		if (pri == -1) {
46*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%d: %s %s\n", linenum,
47*7c478bd9Sstevel@tonic-gate 				"Unknown priority", *cpp);
48*7c478bd9Sstevel@tonic-gate 			return -1;
49*7c478bd9Sstevel@tonic-gate 		}
50*7c478bd9Sstevel@tonic-gate 	}
51*7c478bd9Sstevel@tonic-gate 	*facpri = fac|pri;
52*7c478bd9Sstevel@tonic-gate 	return 0;
53*7c478bd9Sstevel@tonic-gate }
54