return rc;
}
+/*
+ * ares_query_completed_cb() is the callback that ares will call when
+ * the host query initiated by ares_gethostbyname() from Curl_getaddrinfo(),
+ * when using ares, is completed either successfully or with failure.
+ */
+static void ares_query_completed_cb(void *arg, /* (struct connectdata *) */
+ int status,
+#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
+ int timeouts,
+#endif
+ struct hostent *hostent)
+{
+ struct connectdata *conn = (struct connectdata *)arg;
+ struct Curl_addrinfo * ai = NULL;
+
+#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
+ (void)timeouts; /* ignored */
+#endif
+
+ if (status == CURL_ASYNC_SUCCESS) {
+ ai = Curl_he2ai(hostent, conn->async.port);
+ }
+
+ (void)Curl_addrinfo_callback(arg, status, ai);
+}
/*
* Curl_getaddrinfo() - when using ares
/* areschannel is already setup in the Curl_open() function */
ares_gethostbyname(data->state.areschannel, hostname, family,
- (ares_host_callback)Curl_addrinfo4_callback, conn);
+ (ares_host_callback)ares_query_completed_cb, conn);
*waitp = TRUE; /* please wait for the response */
}
* Only for builds using asynchronous name resolves
**********************************************************************/
#ifdef CURLRES_ASYNCH
+
/*
- * addrinfo_callback() gets called by ares, gethostbyname_thread() or
- * getaddrinfo_thread() when we got the name resolved (or not!).
- *
- * If the status argument is CURL_ASYNC_SUCCESS, we might need to copy the
- * address field since it might be freed when this function returns. This
- * operation stores the resolved data in the DNS cache.
+ * Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
+ * or getaddrinfo_thread() when we got the name resolved (or not!).
*
- * NOTE: for IPv6 operations, Curl_addrinfo_copy() returns the same
- * pointer it is given as argument!
+ * If the status argument is CURL_ASYNC_SUCCESS, this function takes
+ * ownership of the Curl_addrinfo passed, storing the resolved data
+ * in the DNS cache.
*
* The storage operation locks and unlocks the DNS cache.
*/
-static CURLcode addrinfo_callback(void *arg, /* "struct connectdata *" */
- int status,
- void *addr)
+CURLcode Curl_addrinfo_callback(struct connectdata * conn,
+ int status,
+ struct Curl_addrinfo *ai)
{
- struct connectdata *conn = (struct connectdata *)arg;
struct Curl_dns_entry *dns = NULL;
CURLcode rc = CURLE_OK;
conn->async.status = status;
if(CURL_ASYNC_SUCCESS == status) {
-
- /*
- * IPv4/ares: Curl_addrinfo_copy() copies the address and returns an
- * allocated version.
- *
- * IPv6: Curl_addrinfo_copy() returns the input pointer!
- */
- Curl_addrinfo *ai = Curl_addrinfo_copy(addr, conn->async.port);
if(ai) {
struct SessionHandle *data = conn->data;
return rc;
}
-CURLcode Curl_addrinfo4_callback(void *arg, /* "struct connectdata *" */
- int status,
-#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
- int timeouts,
-#endif
- struct hostent *hostent)
-{
-#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
- (void)timeouts; /* ignored */
-#endif
- return addrinfo_callback(arg, status, hostent);
-}
-
-#ifdef CURLRES_IPV6
-CURLcode Curl_addrinfo6_callback(void *arg, /* "struct connectdata *" */
- int status,
-#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
- int timeouts,
-#endif
- Curl_addrinfo *ai)
-{
- /* NOTE: for CURLRES_ARES, the 'ai' argument is really a
- * 'struct hostent' pointer.
- */
-#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
- (void)timeouts; /* ignored */
-#endif
- return addrinfo_callback(arg, status, ai);
-}
-#endif
-
-#endif /* CURLRES_ASYNC */
+#endif /* CURLRES_ASYNCH */
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
return Curl_hash_alloc(7, Curl_hash_str, Curl_str_key_compare, freednsentry);
}
-#ifdef CURLRES_ADDRINFO_COPY
-/* align on even 64bit boundaries */
-#define MEMALIGN(x) ((x)+(8-(((unsigned long)(x))&0x7)))
-
-/*
- * Curl_addrinfo_copy() performs a "deep" copy of a hostent into a buffer and
- * returns a pointer to the malloc()ed copy. You need to call free() on the
- * returned buffer when you're done with it.
- */
-Curl_addrinfo *Curl_addrinfo_copy(const void *org, int port)
-{
- const struct hostent *orig = org;
-
- return Curl_he2ai(orig, port);
-}
-#endif /* CURLRES_ADDRINFO_COPY */
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
#define CURLRES_IPV4
#endif
-#if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
-#if !defined(HAVE_GETHOSTBYNAME_R) || defined(CURLRES_ASYNCH)
-/* If built for ipv4 and missing gethostbyname_r(), or if using async name
- resolve, we need the Curl_addrinfo_copy() function (which itself needs the
- Curl_he2ai() function)) */
-#define CURLRES_ADDRINFO_COPY
-#endif
-#endif /* IPv4/ares-only */
-
#ifndef CURLRES_ASYNCH
#define CURLRES_SYNCH
#endif
-#ifndef USE_LIBIDN
-#define CURLRES_IDN
-#endif
-
/* Allocate enough memory to hold the full name information structs and
* everything. OSF1 is known to require at least 8872 bytes. The buffer
* required for storing all possible aliases and IP numbers is according to
int line, const char *source);
#endif
-/* This is the callback function that is used when we build with asynch
- resolve, ipv4 */
-CURLcode Curl_addrinfo4_callback(void *arg,
- int status,
-#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
- int timeouts,
-#endif
- struct hostent *hostent);
-/* This is the callback function that is used when we build with asynch
- resolve, ipv6 */
-CURLcode Curl_addrinfo6_callback(void *arg,
- int status,
-#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
- int timeouts,
-#endif
- Curl_addrinfo *ai);
-
-
-/* Clone a Curl_addrinfo struct, works protocol independently */
-Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port);
+/*
+ * Curl_addrinfo_callback() is used when we build with any asynch specialty.
+ * Handles end of async request processing. Inserts ai into hostcache when
+ * status is CURL_ASYNC_SUCCESS. Twiddles fields in conn to indicate async
+ * request completed wether successfull or failed.
+ */
+CURLcode Curl_addrinfo_callback(struct connectdata *conn,
+ int status,
+ Curl_addrinfo *ai);
/*
* Curl_printable_address() returns a printable version of the 1st address
**********************************************************************/
#ifdef CURLRES_IPV6
-#ifndef CURLRES_ARES
-#ifdef CURLRES_ASYNCH
-/*
- * Curl_addrinfo_copy() is used by the asynch callback to copy a given
- * address. But this is an ipv6 build and then we don't copy the address, we
- * just return the same pointer!
- */
-Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port)
-{
- (void) port;
- return (Curl_addrinfo*)orig;
-}
-#endif /* CURLRES_ASYNCH */
-#endif /* CURLRES_ARES */
#if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
/* These are strictly for memory tracing and are using the same style as the
return res;
}
#endif /* !USE_THREADING_GETADDRINFO && !CURLRES_ARES */
-#endif /* ipv6 */
+#endif /* CURLRES_IPV6 */
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
#if defined(CURLRES_IPV4)
/*
- * gethostbyname_thread() resolves a name, calls the Curl_addrinfo4_callback
+ * gethostbyname_thread() resolves a name, calls the Curl_addrinfo_callback
* and then exits.
*
* For builds without ARES/ENABLE_IPV6, create a resolver thread and wait on
/* is parent thread waiting for us and are we able to access conn members? */
if(acquire_thread_sync(&tsd)) {
+ Curl_addrinfo *ai = Curl_he2ai(he, conn->async.port);
+
/* Mark that we have obtained the information, and that we are calling
* back with it. */
SetEvent(td->event_resolved);
- if(he) {
- rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he);
+ if(ai) {
+ rc = Curl_addrinfo_callback(conn, CURL_ASYNC_SUCCESS, ai);
}
else {
- rc = Curl_addrinfo4_callback(conn, SOCKERRNO, NULL);
+ rc = Curl_addrinfo_callback(conn, SOCKERRNO, NULL);
}
release_thread_sync(&tsd);
}
#elif defined(CURLRES_IPV6)
/*
- * getaddrinfo_thread() resolves a name, calls Curl_addrinfo6_callback and then
+ * getaddrinfo_thread() resolves a name, calls Curl_addrinfo_callback and then
* exits.
*
* For builds without ARES, but with ENABLE_IPV6, create a resolver thread
SetEvent(td->event_resolved);
if(rc == 0) {
- rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res);
+ rc = Curl_addrinfo_callback(conn, CURL_ASYNC_SUCCESS, res);
}
else {
- rc = Curl_addrinfo6_callback(conn, SOCKERRNO, NULL);
+ rc = Curl_addrinfo_callback(conn, SOCKERRNO, NULL);
}
release_thread_sync(&tsd);
}