2 * These are helping routines for the main module of CNTLM
4 * CNTLM is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
9 * CNTLM is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
16 * St, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Copyright (c) 2007 David Kubicek
25 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
26 # include <sys/param.h>
29 #include <netinet/in.h>
31 #include "config/config.h"
34 #define MINIBUF_SIZE 50
35 #define VAL(var, type, offset) *((type *)(var+offset))
36 #define MEM(var, type, offset) (type *)(var+offset)
38 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
39 # define MIN(a, b) ((a) < (b) ? (a) : (b))
43 #define isalnum(c) (isalpha(c) || isdigit(c))
44 #define isspace(c) ((c) == ' ' || (c) == '\f' || (c) == '\t' || (c) == '\r' || (c) == '\n')
48 * Solaris doesn't have LOG_PERROR
51 # define LOG_PERROR LOG_CONS
55 * Two single-linked list types. First is for storing headers,
56 * second keeps a list of finished threads or cached connections.
57 * Each has a different set of manipulation routines.
59 typedef struct hlist_s
*hlist_t
;
67 typedef struct plist_s
*plist_t
;
80 * Request/response data structure. Complete and parsed req/res is
81 * kept in this. See below for (de)allocation routines.
83 typedef struct rr_data_s
*rr_data_t
;
103 * This is used in main() for passing arguments to the thread.
105 struct thread_arg_s
{
108 struct sockaddr_in addr
;
111 extern void myexit(int rc
);
112 extern void croak(const char *msg
, int console
);
114 extern plist_t
plist_add(plist_t list
, unsigned long key
, void *aux
);
115 extern plist_t
plist_del(plist_t list
, unsigned long key
);
116 extern int plist_in(plist_t list
, unsigned long key
);
117 extern void plist_dump(plist_t list
);
118 extern char *plist_get(plist_t list
, int key
);
119 extern int plist_pop(plist_t
*list
, void **aux
);
120 extern int plist_count(plist_t list
);
121 extern plist_t
plist_free(plist_t list
);
123 extern hlist_t
hlist_add(hlist_t list
, char *key
, char *value
, hlist_add_t allockey
, hlist_add_t allocvalue
);
124 extern hlist_t
hlist_dup(hlist_t list
);
125 extern hlist_t
hlist_del(hlist_t list
, const char *key
);
126 extern hlist_t
hlist_mod(hlist_t list
, char *key
, char *value
, int add
);
127 extern int hlist_in(hlist_t list
, const char *key
);
128 extern int hlist_count(hlist_t list
);
129 extern char *hlist_get(hlist_t list
, const char *key
);
130 extern int hlist_subcmp(hlist_t list
, const char *key
, const char *substr
);
131 extern int hlist_subcmp_all(hlist_t list
, const char *key
, const char *substr
);
132 extern hlist_t
hlist_free(hlist_t list
);
133 extern void hlist_dump(hlist_t list
);
135 extern char *substr(const char *src
, int pos
, int len
);
136 extern size_t strlcpy(char *dst
, const char *src
, size_t siz
);
137 extern size_t strlcat(char *dst
, const char *src
, size_t siz
);
138 extern char *trimr(char *buf
);
139 extern char *lowercase(char *str
);
140 extern char *uppercase(char *str
);
141 extern int unicode(char **dst
, char *src
);
142 extern char *new(size_t size
);
143 extern char *urlencode(const char *str
);
145 extern rr_data_t
new_rr_data(void);
146 extern rr_data_t
copy_rr_data(rr_data_t dst
, rr_data_t src
);
147 extern rr_data_t
dup_rr_data(rr_data_t data
);
148 extern rr_data_t
reset_rr_data(rr_data_t data
);
149 extern void free_rr_data(rr_data_t data
);
151 extern char *printmem(char *src
, size_t len
, int bitwidth
);
152 extern char *scanmem(char *src
, int bitwidth
);
154 extern void to_base64(unsigned char *out
, const unsigned char *in
, size_t len
, size_t olen
);
155 extern int from_base64(char *out
, const char *in
);
157 extern long int random(void);
158 #if config_gethostname == 1
159 extern int gethostname(char *name
, size_t len
);
162 extern char *strdup(const char *src
);
165 #endif /* _UTILS_H */