1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Fix formatting when tabs and spaces got mixed up (if tabstop was not set to

8 this looked quite funny :)

Added a small formatting section for vim at the bottom, it also contains an
emacs portion (copied it from another project I'm working on), I don't know
if this is correct, but its a step (the vim part is correct :)
This commit is contained in:
Sterling Hughes 2001-09-05 02:49:04 +00:00
parent 06993556f3
commit 08238f4320

264
lib/ftp.c
View File

@ -134,10 +134,10 @@ static CURLcode AllowServerConnect(struct SessionHandle *data,
sclose(sock); /* close the first socket */ sclose(sock); /* close the first socket */
if( -1 == s) { if (-1 == s) {
/* DIE! */ /* DIE! */
failf(data, "Error accept()ing server connect"); failf(data, "Error accept()ing server connect");
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
infof(data, "Connection accepted from server\n"); infof(data, "Connection accepted from server\n");
@ -187,8 +187,8 @@ int Curl_GetFTPResponse(int sockfd,
#define SELECT_TIMEOUT 2 #define SELECT_TIMEOUT 2
int error = SELECT_OK; int error = SELECT_OK;
if(ftpcode) if (ftpcode)
*ftpcode=0; /* 0 for errors */ *ftpcode = 0; /* 0 for errors */
if(data->set.timeout) { if(data->set.timeout) {
/* if timeout is requested, find out how much remaining time we have */ /* if timeout is requested, find out how much remaining time we have */
@ -248,7 +248,7 @@ int Curl_GetFTPResponse(int sockfd,
int i; int i;
nread += gotbytes; nread += gotbytes;
for(i=0; i< gotbytes; ptr++, i++) { for(i = 0; i < gotbytes; ptr++, i++) {
perline++; perline++;
if(*ptr=='\n') { if(*ptr=='\n') {
/* a newline is CRLF in ftp-talk, so the CR is ignored as /* a newline is CRLF in ftp-talk, so the CR is ignored as
@ -855,7 +855,7 @@ CURLcode _ftp(struct connectdata *conn)
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
if (getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf), NULL, 0, if (getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf), NULL, 0,
niflags)) niflags))
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
@ -872,18 +872,18 @@ CURLcode _ftp(struct connectdata *conn)
for (ai = res; ai; ai = ai->ai_next) { for (ai = res; ai; ai = ai->ai_next) {
portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock < 0) if (portsock < 0)
continue; continue;
if (bind(portsock, ai->ai_addr, ai->ai_addrlen) < 0) { if (bind(portsock, ai->ai_addr, ai->ai_addrlen) < 0) {
sclose(portsock); sclose(portsock);
portsock = -1; portsock = -1;
continue; continue;
} }
if (listen(portsock, 1) < 0) { if (listen(portsock, 1) < 0) {
sclose(portsock); sclose(portsock);
portsock = -1; portsock = -1;
continue; continue;
} }
break; break;
@ -906,87 +906,96 @@ CURLcode _ftp(struct connectdata *conn)
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_INET: case AF_INET:
ap = (unsigned char *)&((struct sockaddr_in *)&ss)->sin_addr; ap = (unsigned char *)&((struct sockaddr_in *)&ss)->sin_addr;
alen = sizeof(((struct sockaddr_in *)&ss)->sin_addr); alen = sizeof(((struct sockaddr_in *)&ss)->sin_addr);
pp = (unsigned char *)&((struct sockaddr_in *)&ss)->sin_port; pp = (unsigned char *)&((struct sockaddr_in *)&ss)->sin_port;
plen = sizeof(((struct sockaddr_in *)&ss)->sin_port); plen = sizeof(((struct sockaddr_in *)&ss)->sin_port);
lprtaf = 4; lprtaf = 4;
eprtaf = 1; eprtaf = 1;
break; break;
case AF_INET6: case AF_INET6:
ap = (unsigned char *)&((struct sockaddr_in6 *)&ss)->sin6_addr; ap = (unsigned char *)&((struct sockaddr_in6 *)&ss)->sin6_addr;
alen = sizeof(((struct sockaddr_in6 *)&ss)->sin6_addr); alen = sizeof(((struct sockaddr_in6 *)&ss)->sin6_addr);
pp = (unsigned char *)&((struct sockaddr_in6 *)&ss)->sin6_port; pp = (unsigned char *)&((struct sockaddr_in6 *)&ss)->sin6_port;
plen = sizeof(((struct sockaddr_in6 *)&ss)->sin6_port); plen = sizeof(((struct sockaddr_in6 *)&ss)->sin6_port);
lprtaf = 6; lprtaf = 6;
eprtaf = 2; eprtaf = 2;
break; break;
default: default:
ap = pp = NULL; ap = pp = NULL;
lprtaf = eprtaf = -1; lprtaf = eprtaf = -1;
break; break;
} }
if (strcmp(*modep, "EPRT") == 0) { if (strcmp(*modep, "EPRT") == 0) {
if (eprtaf < 0) if (eprtaf < 0)
continue; continue;
if (getnameinfo((struct sockaddr *)&ss, sslen, if (getnameinfo((struct sockaddr *)&ss, sslen,
portmsgbuf, sizeof(portmsgbuf), tmp, sizeof(tmp), niflags)) portmsgbuf, sizeof(portmsgbuf), tmp, sizeof(tmp), niflags))
continue; continue;
/* do not transmit IPv6 scope identifier to the wire */
if (sa->sa_family == AF_INET6) { /* do not transmit IPv6 scope identifier to the wire */
char *q = strchr(portmsgbuf, '%'); if (sa->sa_family == AF_INET6) {
if (q) char *q = strchr(portmsgbuf, '%');
*q = '\0'; if (q)
} *q = '\0';
ftpsendf(conn->firstsocket, conn, "%s |%d|%s|%s|", *modep, eprtaf, }
portmsgbuf, tmp);
ftpsendf(conn->firstsocket, conn, "%s |%d|%s|%s|", *modep, eprtaf,
portmsgbuf, tmp);
} else if (strcmp(*modep, "LPRT") == 0 || } else if (strcmp(*modep, "LPRT") == 0 ||
strcmp(*modep, "PORT") == 0) { strcmp(*modep, "PORT") == 0) {
int i; int i;
if (strcmp(*modep, "LPRT") == 0 && lprtaf < 0) if (strcmp(*modep, "LPRT") == 0 && lprtaf < 0)
continue; continue;
if (strcmp(*modep, "PORT") == 0 && sa->sa_family != AF_INET) if (strcmp(*modep, "PORT") == 0 && sa->sa_family != AF_INET)
continue; continue;
portmsgbuf[0] = '\0'; portmsgbuf[0] = '\0';
if (strcmp(*modep, "LPRT") == 0) { if (strcmp(*modep, "LPRT") == 0) {
snprintf(tmp, sizeof(tmp), "%d,%d", lprtaf, alen); snprintf(tmp, sizeof(tmp), "%d,%d", lprtaf, alen);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf)) { if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf)) {
continue;
}
}
for (i = 0; i < alen; i++) {
if (portmsgbuf[0])
snprintf(tmp, sizeof(tmp), ",%u", ap[i]);
else
snprintf(tmp, sizeof(tmp), "%u", ap[i]);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf)) {
continue;
}
}
if (strcmp(*modep, "LPRT") == 0) {
snprintf(tmp, sizeof(tmp), ",%d", plen);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf))
continue;
}
for (i = 0; i < plen; i++) {
snprintf(tmp, sizeof(tmp), ",%u", pp[i]);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf)) {
continue; continue;
} }
} }
ftpsendf(conn->firstsocket, conn, "%s %s", *modep, portmsgbuf);
for (i = 0; i < alen; i++) {
if (portmsgbuf[0])
snprintf(tmp, sizeof(tmp), ",%u", ap[i]);
else
snprintf(tmp, sizeof(tmp), "%u", ap[i]);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf)) {
continue;
}
}
if (strcmp(*modep, "LPRT") == 0) {
snprintf(tmp, sizeof(tmp), ",%d", plen);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf))
continue;
}
for (i = 0; i < plen; i++) {
snprintf(tmp, sizeof(tmp), ",%u", pp[i]);
if (strlcat(portmsgbuf, tmp, sizeof(portmsgbuf)) >= sizeof(portmsgbuf)) {
continue;
}
}
ftpsendf(conn->firstsocket, conn, "%s %s", *modep, portmsgbuf);
} }
nread = Curl_GetFTPResponse(conn->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(conn->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
if (ftpcode != 200) { if (ftpcode != 200) {
failf(data, "Server does not grok %s", *modep); failf(data, "Server does not grok %s", *modep);
continue; continue;
} else } else
break; break;
} }
@ -1122,10 +1131,10 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(conn->firstsocket, conn, mode[modeoff]); ftpsendf(conn->firstsocket, conn, mode[modeoff]);
nread = Curl_GetFTPResponse(conn->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(conn->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
if (ftpcode == results[modeoff]) if (ftpcode == results[modeoff])
break; break;
} }
if (!mode[modeoff]) { if (!mode[modeoff]) {
@ -1159,15 +1168,16 @@ CURLcode _ftp(struct connectdata *conn)
*/ */
while(*str) { while(*str) {
if (6 == sscanf(str, "%d,%d,%d,%d,%d,%d", if (6 == sscanf(str, "%d,%d,%d,%d,%d,%d",
&ip[0], &ip[1], &ip[2], &ip[3], &ip[0], &ip[1], &ip[2], &ip[3],
&port[0], &port[1])) &port[0], &port[1]))
break; break;
str++; str++;
} }
if(!*str) { if(!*str) {
failf(data, "Couldn't interpret this 227-reply: %s", buf); failf(data, "Couldn't interpret this 227-reply: %s", buf);
return CURLE_FTP_WEIRD_227_FORMAT; return CURLE_FTP_WEIRD_227_FORMAT;
} }
sprintf(newhost, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); sprintf(newhost, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
@ -1205,48 +1215,49 @@ CURLcode _ftp(struct connectdata *conn)
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
conn->secondarysocket = -1; conn->secondarysocket = -1;
for (ai = res; ai; ai = ai->ai_next) { for (ai = res; ai; ai = ai->ai_next) {
/* XXX for now, we can do IPv4 only */ /* XXX for now, we can do IPv4 only */
if (ai->ai_family != AF_INET) if (ai->ai_family != AF_INET)
continue; continue;
conn->secondarysocket = socket(ai->ai_family, ai->ai_socktype, conn->secondarysocket = socket(ai->ai_family, ai->ai_socktype,
ai->ai_protocol); ai->ai_protocol);
if (conn->secondarysocket < 0) if (conn->secondarysocket < 0)
continue; continue;
if(data->set.verbose) { if(data->set.verbose) {
char hbuf[NI_MAXHOST]; char hbuf[NI_MAXHOST];
char nbuf[NI_MAXHOST]; char nbuf[NI_MAXHOST];
char sbuf[NI_MAXSERV]; char sbuf[NI_MAXSERV];
#ifdef NI_WITHSCOPEID #ifdef NI_WITHSCOPEID
const int niflags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID; const int niflags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
#else #else
const int niflags = NI_NUMERICHOST | NI_NUMERICSERV; const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
#endif #endif
if (getnameinfo(res->ai_addr, res->ai_addrlen, nbuf, sizeof(nbuf), if (getnameinfo(res->ai_addr, res->ai_addrlen, nbuf, sizeof(nbuf),
sbuf, sizeof(sbuf), niflags)) { sbuf, sizeof(sbuf), niflags)) {
snprintf(nbuf, sizeof(nbuf), "?"); snprintf(nbuf, sizeof(nbuf), "?");
snprintf(sbuf, sizeof(sbuf), "?"); snprintf(sbuf, sizeof(sbuf), "?");
} }
if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
NULL, 0, 0)) {
infof(data, "Connecting to %s port %s\n", nbuf, sbuf);
} else {
infof(data, "Connecting to %s (%s) port %s\n", hbuf, nbuf, sbuf);
}
}
if (connect(conn->secondarysocket, ai->ai_addr, ai->ai_addrlen) < 0) { if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
close(conn->secondarysocket); NULL, 0, 0)) {
conn->secondarysocket = -1; infof(data, "Connecting to %s port %s\n", nbuf, sbuf);
continue; } else {
} infof(data, "Connecting to %s (%s) port %s\n", hbuf, nbuf, sbuf);
}
}
break; if (connect(conn->secondarysocket, ai->ai_addr, ai->ai_addrlen) < 0) {
close(conn->secondarysocket);
conn->secondarysocket = -1;
continue;
}
break;
} }
if (conn->secondarysocket < 0) { if (conn->secondarysocket < 0) {
failf(data, strerror(errno)); failf(data, strerror(errno));
return CURLE_FTP_CANT_RECONNECT; return CURLE_FTP_CANT_RECONNECT;
} }
#else #else
@ -1590,18 +1601,18 @@ CURLcode _ftp(struct connectdata *conn)
} }
} }
if (downloadsize == 0) { if (downloadsize == 0) {
/* no data to transfer */ /* no data to transfer */
result=Curl_Transfer(conn, -1, -1, FALSE, NULL, -1, NULL); result=Curl_Transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
infof(data, "File already completely downloaded\n"); infof(data, "File already completely downloaded\n");
/* Set resume done so that we won't get any error in Curl_ftp_done() /* Set resume done so that we won't get any error in Curl_ftp_done()
* because we didn't transfer the amount of bytes that the remote * because we didn't transfer the amount of bytes that the remote
* file obviously is */ * file obviously is */
conn->bits.resume_done = TRUE; conn->bits.resume_done = TRUE;
return CURLE_OK; return CURLE_OK;
} }
/* Set resume file transfer offset */ /* Set resume file transfer offset */
infof(data, "Instructs server to resume from offset %d\n", infof(data, "Instructs server to resume from offset %d\n",
@ -1817,3 +1828,12 @@ CURLcode Curl_ftp_disconnect(struct connectdata *conn)
} }
return CURLE_OK; return CURLE_OK;
} }
/*
* Local variables:
* tab-width: 2
* c-basic-offset: 2
* End:
* vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker
* vim<600: et sw=2 ts=2 sts=2 tw=78
*/