1 /*
2  *      $Id: conf.h 176 2006-11-07 05:54:55Z boote $
3  */
4 /************************************************************************
5 *									*
6 *			     Copyright (C)  2003			*
7 *				Internet2				*
8 *			     All Rights Reserved			*
9 *									*
10 ************************************************************************/
11 /*
12  *	File:		conf.h
13  *
14  *	Author:		Jeff W. Boote
15  *			Internet2
16  *
17  *	Date:		Tue Sep 16 14:28:48 MDT 2003
18  *
19  *	Description:
20  */
21 #ifndef	_i2_conf_h_
22 #define	_i2_conf_h_
23 
24 #include <I2util/util.h>
25 
26 #include <stdio.h>
27 
28 /*
29  * Growth increment for linebuffer.
30  */
31 #define I2LINEBUFINC	(120)
32 
33 /*
34  * same charactors isspace checks for - useful for strtok splits
35  * of whitespace.
36  */
37 #define I2WSPACESET   "\t\n\v\f\r "
38 
39 /*
40  * Maximum "identity"/"username" charactor length
41  */
42 #define I2MAXIDENTITYLEN	(16)
43 
44 /*
45  * Length of a key in bytes.
46  */
47 #define	I2KEYLEN		(16)
48 
49 extern int
50 I2GetConfLine(
51 	I2ErrHandle	eh,
52 	FILE		*fp,
53 	int		rc,
54 	char		**lbuf,
55 	size_t		*lbuf_max
56 	);
57 
58 extern int
59 I2ReadConfVar(
60 	FILE	*fp,
61 	int	rc,
62 	char	*key,
63 	char	*val,
64 	size_t	max,
65 	char	**lbuf,
66 	size_t	*lbuf_max
67 	);
68 
69 /*
70  * lbuf will contain an undisturbed copy of the last line to be parsed in
71  * the file. (It is the callers responsibility to free the memory pointed
72  * to by lbuf after calling this function.)
73  *
74  */
75 extern int
76 I2ParseKeyFile(
77 	I2ErrHandle eh,
78 	FILE	    *fp,
79 	int	    rc,
80 	char	    **lbuf,
81 	size_t	    *lbuf_max,
82 	FILE	    *tofp,	/* copy 'to' file, or null */
83 	const char  *id_query,
84 	char	    *id_ret,	/* [I2MAXIDENTITYLEN+1] or null */
85 	uint8_t	    *key_ret	/* [I2KEYLEN] or null */
86 	);
87 
88 extern int
89 I2WriteKeyLine(
90 	I2ErrHandle     eh,
91 	FILE	        *fp,
92 	const char      *id,	/* no more than [I2MAXIDENTITYLEN+1] */
93 	const uint8_t   *key	/* [I2KEYLEN] */
94 	);
95 
96 /*
97  * lbuf will NOT contain an undisturbed copy of the last line to be parsed in
98  * the file. lbuf is just a memory buffer to be used by the function, and
99  * realloc'd as needed.
100  *
101  * It is the callers responsibility to free the memory pointed
102  * to by lbuf after calling this function.
103  *
104  */
105 extern int
106 I2ParsePFFile(
107 	I2ErrHandle	eh,
108 	FILE		*fp,
109 	FILE		*tofp,
110 	int		rc,
111         const char      *id_query,
112         char            **id_ret,   /* nul terminated, points in lbuf */
113         char            **pf_ret,   /* points in lbuf */
114         size_t          *pf_len,
115 	char		**lbuf,
116 	size_t		*lbuf_max
117 	);
118 
119 /*
120  * lbuf has same semantics as above, caller must free memory eventually.
121  */
122 extern int
123 I2WritePFLine(
124 	I2ErrHandle	eh,
125 	FILE		*fp,
126 	const char	*id,
127         const uint8_t   *bytes,
128         size_t          nbytes,
129         char            **lbuf,
130         size_t          *lbuf_max
131 	);
132 
133 typedef uint64_t	I2numT;
134 
135 /*
136  * These two functions are destructive to the passed in string.
137  * StrToNum interprets k/m/g as base 10 numbers,
138  * StrToBytes interprets k == 1024 etc...
139  */
140 extern int
141 I2StrToNum(
142 	I2numT		*numret,
143 	char		*str
144 	  );
145 
146 extern int
147 I2StrToByte(
148 	I2numT		*numret,
149 	char		*str
150 	  );
151 
152 #endif	/* _i2_conf_h_ */
153