Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 345 lines (269 sloc) 7.571 kb
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-97f1...
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
24
25 #include "common-internal.h"
26
27 #ifndef _WIN32
28 # include <sys/socket.h>
29 # include <netinet/in.h>
30 # include <arpa/inet.h>
31 # include <netdb.h>
32 #endif
33
34 #include "resolv_cache.h"
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
35 #include "socket_lowlevel.h"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
36 #include "util.h"
5beb917 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@837 5dc97367-97f1-...
alobbs authored
37 #include "avl.h"
0c2c2bd @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@884 5dc97367-97f1-...
alobbs authored
38 #include "socket.h"
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
39 #include "bogotime.h"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
40
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
41
758d7f4 @alobbs Adds a couple of new TRACE entries, so the hostname resolution cache
alobbs authored
42 #define ENTRIES "resolve"
43
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
44
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
45 typedef struct {
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
46 struct addrinfo *addr;
47 cherokee_buffer_t ip_str;
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
48 cherokee_buffer_t ip_str_all;
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
49 } cherokee_resolv_cache_entry_t;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
50
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
51 struct cherokee_resolv_cache {
10e39b4 @alobbs Use a case-insensitive AVL tree for host names.
alobbs authored
52 cherokee_avl_t table;
53 CHEROKEE_RWLOCK_T (lock);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
54 };
55
56 static cherokee_resolv_cache_t *__global_resolv = NULL;
57
58
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
59 /* Entries
60 */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
61 static ret_t
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
62 entry_new (cherokee_resolv_cache_entry_t **entry)
63 {
64 CHEROKEE_NEW_STRUCT(n, resolv_cache_entry);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
65
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
66 n->addr = NULL;
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
67 cherokee_buffer_init (&n->ip_str);
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
68 cherokee_buffer_init (&n->ip_str_all);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
69
70 *entry = n;
71 return ret_ok;
72 }
73
74
75 static void
76 entry_free (void *entry)
77 {
78 cherokee_resolv_cache_entry_t *e = entry;
79
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
80 if (e->addr) {
81 freeaddrinfo (e->addr);
82 }
83
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
84 cherokee_buffer_mrproper (&e->ip_str);
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
85 cherokee_buffer_mrproper (&e->ip_str_all);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
86 free(entry);
87 }
88
89
90 static ret_t
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
91 entry_fill_up (cherokee_resolv_cache_entry_t *entry,
92 cherokee_buffer_t *domain)
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
93 {
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
94 ret_t ret;
95 char tmp[46]; // Max IPv6 length is 45
96 struct addrinfo *addr;
97 time_t eagain_at = 0;
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
98
99 while (true) {
4182717 @alobbs The first parameter (char *) of cherokee_gethostbyname() function
alobbs authored
100 ret = cherokee_gethostbyname (domain, &entry->addr);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
101 if (ret == ret_ok) {
102 break;
103
104 } else if (ret == ret_eagain) {
105 if (eagain_at == 0) {
106 eagain_at = cherokee_bogonow_now;
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
107
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
108 } else if (cherokee_bogonow_now > eagain_at + 3) {
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
109 LOG_WARNING (CHEROKEE_ERROR_RESOLVE_TIMEOUT, domain->buf);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
110 return ret_error;
111 }
112
3e09989 @alobbs Fixes a compilation error on system without sched_yield() support.
alobbs authored
113 CHEROKEE_THREAD_YIELD;
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
114 continue;
115
116 } else {
117 return ret_error;
118 }
119 }
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
120
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
121 if (unlikely (entry->addr == NULL)) {
122 return ret_error;
123 }
124
125 /* Render the text representation
126 */
127 ret = cherokee_ntop (entry->addr->ai_family, entry->addr->ai_addr, tmp, sizeof(tmp));
128 if (ret != ret_ok) {
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
129 return ret_error;
130 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
131
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
132 cherokee_buffer_add (&entry->ip_str, tmp, strlen(tmp));
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
133
134 /* Render the text representation (all the IPs)
135 */
136 cherokee_buffer_add_buffer (&entry->ip_str_all, &entry->ip_str);
137
138 addr = entry->addr;
139 while (addr != NULL) {
140 ret = cherokee_ntop (entry->addr->ai_family, addr->ai_addr, tmp, sizeof(tmp));
141 if (ret != ret_ok) {
142 return ret_error;
143 }
144
145 cherokee_buffer_add_char (&entry->ip_str_all, ',');
146 cherokee_buffer_add (&entry->ip_str_all, tmp, strlen(tmp));
147
148 addr = addr->ai_next;
149 }
150
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
151 return ret_ok;
152 }
153
154
155
156 /* Table
157 */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
158 ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
159 cherokee_resolv_cache_init (cherokee_resolv_cache_t *resolv)
160 {
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
161 ret_t ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
162
5beb917 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@837 5dc97367-97f1-...
alobbs authored
163 ret = cherokee_avl_init (&resolv->table);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
164 if (unlikely (ret != ret_ok)) return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
165
10e39b4 @alobbs Use a case-insensitive AVL tree for host names.
alobbs authored
166 ret = cherokee_avl_set_case (&resolv->table, true);
167 if (unlikely (ret != ret_ok)) return ret;
168
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
169 CHEROKEE_RWLOCK_INIT (&resolv->lock, NULL);
170 return ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
171 }
172
173
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
174 ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
175 cherokee_resolv_cache_mrproper (cherokee_resolv_cache_t *resolv)
176 {
5beb917 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@837 5dc97367-97f1-...
alobbs authored
177 cherokee_avl_mrproper (&resolv->table, entry_free);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
178 CHEROKEE_RWLOCK_DESTROY (&resolv->lock);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
179
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
180 return ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
181 }
182
183
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
184 ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
185 cherokee_resolv_cache_get_default (cherokee_resolv_cache_t **resolv)
186 {
10e39b4 @alobbs Use a case-insensitive AVL tree for host names.
alobbs authored
187 ret_t ret;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
188
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
189 if (unlikely (__global_resolv == NULL)) {
10e39b4 @alobbs Use a case-insensitive AVL tree for host names.
alobbs authored
190 CHEROKEE_NEW_STRUCT (n, resolv_cache);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
191
192 ret = cherokee_resolv_cache_init (n);
193 if (ret != ret_ok) return ret;
194
195 __global_resolv = n;
196 }
197
198 *resolv = __global_resolv;
199 return ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
200 }
201
202
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
203 ret_t
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
204 cherokee_resolv_cache_clean (cherokee_resolv_cache_t *resolv)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
205 {
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
206 CHEROKEE_RWLOCK_WRITER (&resolv->lock);
5beb917 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@837 5dc97367-97f1-...
alobbs authored
207 cherokee_avl_mrproper (&resolv->table, entry_free);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
208 CHEROKEE_RWLOCK_UNLOCK (&resolv->lock);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
209
210 return ret_ok;
211 }
212
213
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
214 static ret_t
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
215 table_add_new_entry (cherokee_resolv_cache_t *resolv,
216 cherokee_buffer_t *domain,
217 cherokee_resolv_cache_entry_t **entry)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
218 {
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
219 ret_t ret;
abd23e1 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2833 5dc97367-97f1...
alobbs authored
220 cherokee_resolv_cache_entry_t *n = NULL;
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
221
222 /* Instance the entry
223 */
224 ret = entry_new (&n);
bb33470 @alobbs Fixes a couple of issues: A file descriptor leak in Cherokee tweak,
alobbs authored
225 if (unlikely (ret != ret_ok)) {
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
226 return ret;
bb33470 @alobbs Fixes a couple of issues: A file descriptor leak in Cherokee tweak,
alobbs authored
227 }
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
228
229 /* Fill it up
230 */
231 ret = entry_fill_up (n, domain);
fbe0dec @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1790 5dc97367-97f1...
alobbs authored
232 if (unlikely (ret != ret_ok)) {
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
233 entry_free (n);
234 return ret;
235 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
236
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
237 /* Add it to the table
238 */
239 CHEROKEE_RWLOCK_WRITER (&resolv->lock);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
240 ret = cherokee_avl_add (&resolv->table, domain, (void **)n);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
241 CHEROKEE_RWLOCK_UNLOCK (&resolv->lock);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
242
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
243 *entry = n;
244 return ret_ok;
245 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
246
247
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
248 ret_t
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
249 cherokee_resolv_cache_get_ipstr (cherokee_resolv_cache_t *resolv,
250 cherokee_buffer_t *domain,
251 const char **ip)
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
252 {
253 ret_t ret;
254 cherokee_resolv_cache_entry_t *entry = NULL;
255
256 /* Look for the name in the cache
257 */
e17d296 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@689 5dc97367-97f1-...
alobbs authored
258 CHEROKEE_RWLOCK_READER (&resolv->lock);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
259 ret = cherokee_avl_get (&resolv->table, domain, (void **)&entry);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
260 CHEROKEE_RWLOCK_UNLOCK (&resolv->lock);
261
262 if (ret != ret_ok) {
fc0b5ee @alobbs Fixes a few TRACE entries where \n characters were missing.
alobbs authored
263 TRACE (ENTRIES, "Resolve '%s': missed.\n", domain->buf);
758d7f4 @alobbs Adds a couple of new TRACE entries, so the hostname resolution cache
alobbs authored
264
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
265 /* Bad luck: it wasn't cached
266 */
267 ret = table_add_new_entry (resolv, domain, &entry);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
268 if (ret != ret_ok) {
269 return ret;
270 }
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
271 TRACE (ENTRIES, "Resolve '%s': added succesfuly as '%s'.\n", domain->buf, entry->ip_str_all.buf);
758d7f4 @alobbs Adds a couple of new TRACE entries, so the hostname resolution cache
alobbs authored
272 } else {
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
273 TRACE (ENTRIES, "Resolve '%s': hit: %s\n", domain->buf, entry->ip_str_all.buf);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
274 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
275
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
276 /* Return the ip string
277 */
758d7f4 @alobbs Adds a couple of new TRACE entries, so the hostname resolution cache
alobbs authored
278 if (ip != NULL) {
279 *ip = entry->ip_str.buf;
280 }
281
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
282 return ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
283 }
284
285
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
286 ret_t
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
287 cherokee_resolv_cache_get_host (cherokee_resolv_cache_t *resolv,
288 cherokee_buffer_t *domain,
289 void *sock_)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
290 {
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
291 ret_t ret;
292 const struct addrinfo *addr = NULL;
293 cherokee_socket_t *sock = sock_;
294
295 /* Get addrinfo
296 */
297 ret = cherokee_resolv_cache_get_addrinfo (resolv, domain, &addr);
298 if (ret != ret_ok) {
299 return ret;
300 }
301
302 /* Copy it to the socket object
303 */
d2e7b95 @alobbs Enhances the handle_proxy so it can handle multi-IP sources nicely.
alobbs authored
304 ret = cherokee_socket_update_from_addrinfo (sock, addr, 0);
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
305 if (ret != ret_ok) {
306 return ret;
307 }
308
309 return ret_ok;
310 }
311
312
313 ret_t
314 cherokee_resolv_cache_get_addrinfo (cherokee_resolv_cache_t *resolv,
315 cherokee_buffer_t *domain,
316 const struct addrinfo **addr_info)
317 {
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
318 ret_t ret;
319 cherokee_resolv_cache_entry_t *entry = NULL;
320
321 /* Look for the name in the cache
322 */
e17d296 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@689 5dc97367-97f1-...
alobbs authored
323 CHEROKEE_RWLOCK_READER (&resolv->lock);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
324 ret = cherokee_avl_get (&resolv->table, domain, (void **)&entry);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
325 CHEROKEE_RWLOCK_UNLOCK (&resolv->lock);
326
327 if (ret != ret_ok) {
fc0b5ee @alobbs Fixes a few TRACE entries where \n characters were missing.
alobbs authored
328 TRACE (ENTRIES, "Resolve '%s': missed.\n", domain->buf);
758d7f4 @alobbs Adds a couple of new TRACE entries, so the hostname resolution cache
alobbs authored
329
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
330 /* Bad luck: it wasn't cached
331 */
332 ret = table_add_new_entry (resolv, domain, &entry);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
333 if (ret != ret_ok) {
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
334 TRACE (ENTRIES, "Resolve '%s': error ret=%d.\n", domain->buf, ret);
f2106e5 @alobbs This patch improves the gethostbyname() usage in Cherokee. Besides, it
alobbs authored
335 return ret;
336 }
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
337 TRACE (ENTRIES, "Resolve '%s': added succesfuly as '%s'.\n", domain->buf, entry->ip_str.buf);
758d7f4 @alobbs Adds a couple of new TRACE entries, so the hostname resolution cache
alobbs authored
338 } else {
fc0b5ee @alobbs Fixes a few TRACE entries where \n characters were missing.
alobbs authored
339 TRACE (ENTRIES, "Resolve '%s': hit.\n", domain->buf);
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
340 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
341
85a296d @alobbs Solves a number of issues around the IPv6 support of the server,
alobbs authored
342 *addr_info = entry->addr;
c7bad7d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@543 5dc97367-97f1-...
alobbs authored
343 return ret_ok;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
344 }
Something went wrong with that request. Please try again.