]> granicus.if.org Git - curl/commitdiff
FTP: call opensocket callback properly
authorDaniel Stenberg <daniel@haxx.se>
Mon, 5 Dec 2011 10:42:10 +0000 (11:42 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 5 Dec 2011 10:42:10 +0000 (11:42 +0100)
When the new socket is created for an active connection, it is now done
using the open socket callback.

Test case 596 was modified to run fine, although it hides the fact that
the close callback is still called too many times, as it also gets
called for closing sockets that were created with accept().

docs/libcurl/curl_easy_setopt.3
lib/connect.c
lib/ftp.c
tests/data/test596

index 29151802f76295c3392277282bf30985d3c73ccc..2f7e40e2684b74aa6318e09b4b9a4924617c0134 100644 (file)
@@ -294,10 +294,9 @@ argument in the sockopt callback set with \fICURLOPT_SOCKOPTFUNCTION\fP.
 Function pointer that should match the \fIcurl_opensocket_callback\fP
 prototype found in \fI<curl/curl.h>\fP. This function gets called by libcurl
 instead of the \fIsocket(2)\fP call. The callback's \fIpurpose\fP argument
-identifies the exact purpose for this particular socket, and currently only
-one value is supported: \fICURLSOCKTYPE_IPCXN\fP for the primary connection
-(meaning the control connection in the FTP case). Future versions of libcurl
-may support more purposes. It passes the resolved peer address as a
+identifies the exact purpose for this particular socket:
+\fICURLSOCKTYPE_IPCXN\fP is for IP based connections. Future versions of
+libcurl may support more purposes. It passes the resolved peer address as a
 \fIaddress\fP argument so the callback can modify the address or refuse to
 connect at all. The callback function should return the socket or
 \fICURL_SOCKET_BAD\fP in case no connection should be established or any error
index 2eef242d49f847a35e98f497af0eb64f194e1d4c..44526175478d3acb3fdddb107876f81d26fe957f 100644 (file)
@@ -1119,8 +1119,10 @@ int Curl_closesocket(struct connectdata *conn,
 /*
  * Create a socket based on info from 'conn' and 'ai'.
  *
- * Fill in 'addr' and 'sockfd' accordingly if OK is returned. If the open
- * socket callback is set, used that!
+ * 'addr' should be a pointer to the correct struct to get data back, or NULL.
+ * 'sockfd' must be a pointer to a socket descriptor.
+ *
+ * If the open socket callback is set, used that!
  *
  */
 CURLcode Curl_socket(struct connectdata *conn,
@@ -1129,9 +1131,11 @@ CURLcode Curl_socket(struct connectdata *conn,
                      curl_socket_t *sockfd)
 {
   struct SessionHandle *data = conn->data;
-#if defined(ENABLE_IPV6) && defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
-  struct sockaddr_in6 * const sa6 = (void *)&addr->sa_addr;
-#endif
+  struct Curl_sockaddr_ex dummy;
+
+  if(!addr)
+    /* if the caller doesn't want info back, use a local temp copy */
+    addr = &dummy;
 
   /*
    * The Curl_sockaddr_ex structure is basically libcurl's external API
@@ -1172,8 +1176,10 @@ CURLcode Curl_socket(struct connectdata *conn,
     return CURLE_FAILED_INIT;
 
 #if defined(ENABLE_IPV6) && defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
-  if(conn->scope && (addr->family == AF_INET6))
+  if(conn->scope && (addr->family == AF_INET6)) {
+    struct sockaddr_in6 * const sa6 = (void *)&addr->sa_addr;
     sa6->sin6_scope_id = conn->scope;
+  }
 #endif
 
   return CURLE_OK;
index 05f6f450f8e5cc810907d2c7c868aa335e8828a7..38a5f10c91dc53ff3e9fb86c45660fb298869950 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -901,14 +901,8 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
   portsock = CURL_SOCKET_BAD;
   error = 0;
   for(ai = res; ai; ai = ai->ai_next) {
-    /*
-     * Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype):
-     */
-    if(ai->ai_socktype == 0)
-      ai->ai_socktype = conn->socktype;
-
-    portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
-    if(portsock == CURL_SOCKET_BAD) {
+    result = Curl_socket(conn, ai, NULL, &portsock);
+    if(result) {
       error = SOCKERRNO;
       continue;
     }
index 9703f047188120a6210768a7ed1c323f9c347f30..73e8a78d589e2c160dc2578d2c62d9c23b096f77 100644 (file)
@@ -16,9 +16,10 @@ moo
 <datacheck>
 [OPEN] counter: 1
 [OPEN] counter: 2
-moo
 [CLOSE] counter: 2
+moo
 [CLOSE] counter: 1
+[CLOSE] counter: 0
 </datacheck>
 </reply>
 
@@ -43,11 +44,14 @@ ftp://%HOSTIP:%FTPPORT/596 log/ip596 activeftp
 #
 # Verify data after the test has been "shot"
 <verify>
+<strippart>
+s/^(EPRT \|1\|)(.*)/$1/
+</strippart>
 <protocol>
 USER anonymous\r
 PASS ftp@example.com\r
 PWD\r
-EPSV\r
+EPRT |1|
 TYPE I\r
 SIZE 596\r
 RETR 596\r