hostasyn.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #ifdef HAVE_NETINET_IN_H
00026 #include <netinet/in.h>
00027 #endif
00028 #ifdef HAVE_NETDB_H
00029 #include <netdb.h>
00030 #endif
00031 #ifdef HAVE_ARPA_INET_H
00032 #include <arpa/inet.h>
00033 #endif
00034 #ifdef __VMS
00035 #include <in.h>
00036 #include <inet.h>
00037 #endif
00038 
00039 #ifdef HAVE_PROCESS_H
00040 #include <process.h>
00041 #endif
00042 
00043 #include "urldata.h"
00044 #include "sendf.h"
00045 #include "hostip.h"
00046 #include "hash.h"
00047 #include "share.h"
00048 #include "strerror.h"
00049 #include "url.h"
00050 #include "curl_memory.h"
00051 /* The last #include file should be: */
00052 #include "memdebug.h"
00053 
00054 /***********************************************************************
00055  * Only for builds using asynchronous name resolves
00056  **********************************************************************/
00057 #ifdef CURLRES_ASYNCH
00058 
00059 /*
00060  * Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
00061  * or getaddrinfo_thread() when we got the name resolved (or not!).
00062  *
00063  * If the status argument is CURL_ASYNC_SUCCESS, this function takes
00064  * ownership of the Curl_addrinfo passed, storing the resolved data
00065  * in the DNS cache.
00066  *
00067  * The storage operation locks and unlocks the DNS cache.
00068  */
00069 CURLcode Curl_addrinfo_callback(struct connectdata *conn,
00070                                 int status,
00071                                 struct Curl_addrinfo *ai)
00072 {
00073   struct Curl_dns_entry *dns = NULL;
00074   CURLcode result = CURLE_OK;
00075 
00076   conn->async.status = status;
00077 
00078   if(CURL_ASYNC_SUCCESS == status) {
00079     if(ai) {
00080       struct Curl_easy *data = conn->data;
00081 
00082       if(data->share)
00083         Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
00084 
00085       dns = Curl_cache_addr(data, ai,
00086                             conn->async.hostname,
00087                             conn->async.port);
00088       if(!dns) {
00089         /* failed to store, cleanup and return error */
00090         Curl_freeaddrinfo(ai);
00091         result = CURLE_OUT_OF_MEMORY;
00092       }
00093 
00094       if(data->share)
00095         Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
00096     }
00097     else {
00098       result = CURLE_OUT_OF_MEMORY;
00099     }
00100   }
00101 
00102   conn->async.dns = dns;
00103 
00104  /* Set async.done TRUE last in this function since it may be used multi-
00105     threaded and once this is TRUE the other thread may read fields from the
00106     async struct */
00107   conn->async.done = TRUE;
00108 
00109   /* IPv4: The input hostent struct will be freed by ares when we return from
00110      this function */
00111   return result;
00112 }
00113 
00114 /* Call this function after Curl_connect() has returned async=TRUE and
00115    then a successful name resolve has been received.
00116 
00117    Note: this function disconnects and frees the conn data in case of
00118    resolve failure */
00119 CURLcode Curl_async_resolved(struct connectdata *conn,
00120                              bool *protocol_done)
00121 {
00122   CURLcode result;
00123 
00124   if(conn->async.dns) {
00125     conn->dns_entry = conn->async.dns;
00126     conn->async.dns = NULL;
00127   }
00128 
00129   result = Curl_setup_conn(conn, protocol_done);
00130 
00131   if(result)
00132     /* We're not allowed to return failure with memory left allocated
00133        in the connectdata struct, free those here */
00134     Curl_disconnect(conn, FALSE); /* close the connection */
00135 
00136   return result;
00137 }
00138 
00139 /*
00140  * Curl_getaddrinfo() is the generic low-level name resolve API within this
00141  * source file. There are several versions of this function - for different
00142  * name resolve layers (selected at build-time). They all take this same set
00143  * of arguments
00144  */
00145 Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
00146                                 const char *hostname,
00147                                 int port,
00148                                 int *waitp)
00149 {
00150   return Curl_resolver_getaddrinfo(conn, hostname, port, waitp);
00151 }
00152 
00153 #endif /* CURLRES_ASYNCH */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04