-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
126 lines (111 loc) · 3.84 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* These are helping routines for the main module of CNTLM
*
* CNTLM is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* CNTLM is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2007 David Kubicek
*
*/
#ifndef _UTILS_H
#define _UTILS_H
#include <pthread.h>
#include "config/config.h"
#define BUFSIZE 1024
#define MINIBUF_SIZE 50
#define VAL(var, type, offset) *((type *)(var+offset))
#define MEM(var, type, offset) (type *)(var+offset)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/*
* Two single-linked list types. First is for storing headers,
* second keeps a list of finished threads or cached connections.
* Each has a different set of manipulation routines.
*/
typedef struct hlist_s *hlist_t;
struct hlist_s {
char *key;
char *value;
struct hlist_s *next;
};
typedef struct plist_s *plist_t;
struct plist_s {
unsigned long key;
char *aux;
struct plist_s *next;
};
/*
* Request/response data structure. Complete and parsed req/res is
* kept in this. See below for (de)allocation routines.
*/
typedef struct rr_data_s *rr_data_t;
struct rr_data_s {
int req;
hlist_t headers;
int code;
int skip_http;
char *method;
char *url;
char *http;
char *msg;
};
/*
* This is used in main() for passing arguments to the thread.
*/
struct thread_arg_s {
int fd;
char *target;
};
extern plist_t plist_add(plist_t list, unsigned long key, char *aux);
extern plist_t plist_del(plist_t list, unsigned long key);
extern int plist_in(plist_t list, unsigned long key);
extern void plist_dump(plist_t list);
extern char *plist_get(plist_t list, int key);
extern int plist_pop(plist_t *list);
extern int plist_count(plist_t list);
extern plist_t plist_free(plist_t list);
extern hlist_t hlist_add(hlist_t list, char *key, char *value, int allockey, int allocvalue);
extern hlist_t hlist_dup(hlist_t list);
extern hlist_t hlist_del(hlist_t list, const char *key);
extern hlist_t hlist_mod(hlist_t list, char *key, char *value, int add);
extern int hlist_in(hlist_t list, const char *key);
extern int hlist_count(hlist_t list);
extern char *hlist_get(hlist_t list, const char *key);
extern int hlist_subcmp(hlist_t list, const char *key, const char *substr);
extern hlist_t hlist_free(hlist_t list);
extern void hlist_dump(hlist_t list);
extern char *substr(const char *src, int pos, int len);
extern size_t strlcpy(char *dst, const char *src, size_t siz);
extern size_t strlcat(char *dst, const char *src, size_t siz);
extern char *trimr(char *buf);
extern char *lowercase(char *str);
extern char *uppercase(char *str);
extern int head_ok(const char *src);
extern char *head_name(const char *src);
extern char *head_value(const char *src);
extern int unicode(char **dst, char *src);
extern char *new(size_t size);
extern char *urlencode(const char *str);
extern rr_data_t new_rr_data(void);
extern rr_data_t dup_rr_data(rr_data_t data);
extern void free_rr_data(rr_data_t data);
extern char *printmem(char *src, size_t len, int bitwidth);
extern char *scanmem(char *src, int bitwidth);
extern void to_base64(unsigned char *out, const unsigned char *in, size_t len, size_t olen);
extern int from_base64(char *out, const char *in);
extern long int random(void);
#if config_gethostname == 1
extern int gethostname(char *name, size_t len);
#endif
extern char *strdup(const char *src);
#endif /* _UTILS_H */