Handle localhost.localdomain in initHttp.
[polipo.git] / util.h
blob3da1c32a0525f69ebbfee8b4cd99f658a2404807
1 /*
2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
23 /* These are Polipo's error codes. They need to be positive integers,
24 and must not collide with possible errno values.
25 Starting at 2^16 should be safe enough. */
27 #define E0 (1 << 16)
28 #define E1 (2 << 16)
29 #define E2 (3 << 16)
30 #define E3 (4 << 16)
31 #define EUNKNOWN (E0)
32 #define EDOSHUTDOWN (E0 + 1)
33 #define EDOGRACEFUL (E0 + 2)
34 #define EDOTIMEOUT (E0 + 3)
35 #define ECLIENTRESET (E0 + 4)
36 #define ESYNTAX (E0 + 5)
37 #define EDNS_HOST_NOT_FOUND (E1)
38 #define EDNS_NO_ADDRESS (E1 + 1)
39 #define EDNS_NO_RECOVERY (E1 + 2)
40 #define EDNS_TRY_AGAIN (E1 + 3)
41 #define EDNS_INVALID (E1 + 4)
42 #define EDNS_UNSUPPORTED (E1 + 5)
43 #define EDNS_FORMAT (E1 + 6)
44 #define EDNS_REFUSED (E1 + 7)
45 #define EDNS_CNAME_LOOP (E1 + 8)
46 #define ESOCKS_PROTOCOL (E2)
47 /* These correspond to SOCKS status codes 91 through 93 */
48 #define ESOCKS_REJECT_FAIL (E2 + 1)
49 #define ESOCKS_REJECT_IDENTD (E2 + 2)
50 #define ESOCKS_REJECT_UID_MISMATCH (E2 + 3)
51 #define ESOCKS5_BASE (E3)
53 typedef struct _IntRange {
54 int from;
55 int to;
56 } IntRangeRec, *IntRangePtr;
58 typedef struct _IntList {
59 int length;
60 int size;
61 IntRangePtr ranges;
62 } IntListRec, *IntListPtr;
64 char *strdup_n(const char *restrict buf, int n) ATTRIBUTE ((malloc));
65 int snnprintf(char *restrict buf, int n, int len, const char *format, ...)
66 ATTRIBUTE ((format (printf, 4, 5)));
67 int snnprint_n(char *restrict buf, int n, int len, const char *s, int slen);
68 int strcmp_n(const char *string, const char *buf, int n) ATTRIBUTE ((pure));
69 int digit(char) ATTRIBUTE ((const));
70 int letter(char) ATTRIBUTE ((const));
71 char lwr(char) ATTRIBUTE ((const));
72 char* lwrcpy(char *dst, const char *src, int n);
73 int lwrcmp(const char *as, const char *bs, int n) ATTRIBUTE ((pure));
74 int strcasecmp_n(const char *string, const char *buf, int n)
75 ATTRIBUTE ((pure));
76 int atoi_n(const char *restrict string, int n, int len, int *value_return);
77 int isWhitespace(const char *string) ATTRIBUTE((pure));
78 #ifndef HAVE_MEMRCHR
79 void *memrchr(const void *s, int c, size_t n) ATTRIBUTE ((pure));
80 #endif
81 int h2i(char h) ATTRIBUTE ((const));
82 char i2h(int i) ATTRIBUTE ((const));
83 int log2_floor(int x) ATTRIBUTE ((const));
84 int log2_ceil(int x) ATTRIBUTE ((const));
85 char* vsprintf_a(const char *f, va_list args) ATTRIBUTE ((malloc));
86 char* sprintf_a(const char *f, ...) ATTRIBUTE ((malloc));
87 unsigned int hash(unsigned seed, const void *restrict key, int key_size,
88 unsigned int hash_size)
89 ATTRIBUTE ((pure));
90 char *pstrerror(int e);
91 time_t mktime_gmt(struct tm *tm) ATTRIBUTE ((pure));
92 char *expandTildeString(char *string);
93 AtomPtr expandTilde(AtomPtr filename);
94 void do_daemonise(int noclose);
95 void writePid(char *pidfile);
96 int b64cpy(char *restrict dst, const char *restrict src, int n, int fss);
97 int b64cmp(const char *a, int an, const char *b, int bn) ATTRIBUTE ((pure));
98 IntListPtr makeIntList(int size) ATTRIBUTE ((malloc));
99 void destroyIntList(IntListPtr list);
100 int intListMember(int n, IntListPtr list) ATTRIBUTE ((pure));
101 int intListCons(int from, int to, IntListPtr list);