The R Project SVN R

Rev

Rev 59039 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 59039 Rev 59990
Line 573... Line 573...
573
    }
573
    }
574
 
574
 
575
    /*
575
    /*
576
     * Read the amount left on the control connection
576
     * Read the amount left on the control connection
577
     */
577
     */
578
    if ((len = recv(ctxt->controlFd, &ctxt->controlBuf[ctxt->controlBufIndex],
578
    if ((len = (int) recv(ctxt->controlFd, &ctxt->controlBuf[ctxt->controlBufIndex],
579
		    size, 0)) < 0) {
579
			  size, 0)) < 0) {
580
	RxmlMessage(1, "recv failed");
580
	RxmlMessage(1, "recv failed");
581
	closesocket(ctxt->controlFd); ctxt->controlFd = -1;
581
	closesocket(ctxt->controlFd); ctxt->controlFd = -1;
582
	ctxt->controlFd = -1;
582
	ctxt->controlFd = -1;
583
	return(-1);
583
	return(-1);
584
    }
584
    }
Line 636... Line 636...
636
    ptr = &ctxt->controlBuf[ctxt->controlBufIndex];
636
    ptr = &ctxt->controlBuf[ctxt->controlBufIndex];
637
    end = &ctxt->controlBuf[ctxt->controlBufUsed];
637
    end = &ctxt->controlBuf[ctxt->controlBufUsed];
638
 
638
 
639
    RxmlMessage(0, "\n<<<\n%s\n--\n", ptr);
639
    RxmlMessage(0, "\n<<<\n%s\n--\n", ptr);
640
    while (ptr < end) {
640
    while (ptr < end) {
641
	cur = RxmlNanoFTPParseResponse(ptr, end - ptr);
641
	cur = RxmlNanoFTPParseResponse(ptr, (int)(end - ptr));
642
	if (cur > 0) {
642
	if (cur > 0) {
643
	    /*
643
	    /*
644
	     * Successfully scanned the control code, scratch
644
	     * Successfully scanned the control code, scratch
645
	     * till the end of the line, but keep the index to be
645
	     * till the end of the line, but keep the index to be
646
	     * able to analyze the result if needed.
646
	     * able to analyze the result if needed.
647
	     */
647
	     */
648
	    res = cur;
648
	    res = cur;
649
	    if(res == 150) RxmlFindLength(ctxt, ptr);
649
	    if(res == 150) RxmlFindLength(ctxt, ptr);
650
	    ptr += 3;
650
	    ptr += 3;
651
	    ctxt->controlBufAnswer = ptr - ctxt->controlBuf;
651
	    ctxt->controlBufAnswer = (int)(ptr - ctxt->controlBuf);
652
	    while ((ptr < end) && (*ptr != '\n')) ptr++;
652
	    while ((ptr < end) && (*ptr != '\n')) ptr++;
653
	    if (*ptr == '\n') ptr++;
653
	    if (*ptr == '\n') ptr++;
654
	    if (*ptr == '\r') ptr++;
654
	    if (*ptr == '\r') ptr++;
655
	    break;
655
	    break;
656
	}
656
	}
Line 661... Line 661...
661
	}
661
	}
662
	if (*ptr != '\r') ptr++;
662
	if (*ptr != '\r') ptr++;
663
    }
663
    }
664
 
664
 
665
    if (res < 0) goto get_more;
665
    if (res < 0) goto get_more;
666
    ctxt->controlBufIndex = ptr - ctxt->controlBuf;
666
    ctxt->controlBufIndex = (int)(ptr - ctxt->controlBuf);
667
    ptr = &ctxt->controlBuf[ctxt->controlBufIndex];
667
    ptr = &ctxt->controlBuf[ctxt->controlBufIndex];
668
    RxmlMessage(1, "\n---\n%s\n--\n", ptr);
668
    RxmlMessage(1, "\n---\n%s\n--\n", ptr);
669
    RxmlMessage(1, "Got %d", res);
669
    RxmlMessage(1, "Got %d", res);
670
    return(res / 100);
670
    return(res / 100);
671
}
671
}
Line 728... Line 728...
728
static int
728
static int
729
RxmlNanoFTPSendUser(void *ctx) {
729
RxmlNanoFTPSendUser(void *ctx) {
730
    RxmlNanoFTPCtxtPtr ctxt = (RxmlNanoFTPCtxtPtr) ctx;
730
    RxmlNanoFTPCtxtPtr ctxt = (RxmlNanoFTPCtxtPtr) ctx;
731
    char buf[200];
731
    char buf[200];
732
    int len;
732
    int len;
733
    int res;
733
    ssize_t res;
734
 
734
 
735
    if (ctxt->user == NULL)
735
    if (ctxt->user == NULL)
736
	snprintf(buf, sizeof(buf), "USER anonymous\r\n");
736
	snprintf(buf, sizeof(buf), "USER anonymous\r\n");
737
    else
737
    else
738
	snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
738
	snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
739
    buf[sizeof(buf) - 1] = 0;
739
    buf[sizeof(buf) - 1] = 0;
740
    len = strlen(buf);
740
    len = (int) strlen(buf);
741
    RxmlMessage(0, "%s", buf);
741
    RxmlMessage(0, "%s", buf);
742
    res = send(ctxt->controlFd, buf, len, 0);
742
    res = send(ctxt->controlFd, buf, len, 0);
743
    if (res < 0) {
743
    if (res < 0) {
744
	RxmlMessage(1, "send failed");
744
	RxmlMessage(1, "send failed");
745
	return(res);
745
	return(res);
Line 754... Line 754...
754
static int
754
static int
755
RxmlNanoFTPSendPasswd(void *ctx) {
755
RxmlNanoFTPSendPasswd(void *ctx) {
756
    RxmlNanoFTPCtxtPtr ctxt = (RxmlNanoFTPCtxtPtr) ctx;
756
    RxmlNanoFTPCtxtPtr ctxt = (RxmlNanoFTPCtxtPtr) ctx;
757
    char buf[200];
757
    char buf[200];
758
    int len;
758
    int len;
759
    int res;
759
    ssize_t res;
760
 
760
 
761
    if (ctxt->passwd == NULL)
761
    if (ctxt->passwd == NULL)
762
	snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
762
	snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
763
    else
763
    else
764
	snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
764
	snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
765
    buf[sizeof(buf) - 1] = 0;
765
    buf[sizeof(buf) - 1] = 0;
766
    len = strlen(buf);
766
    len = (int) strlen(buf);
767
    RxmlMessage(0, "%s", buf);
767
    RxmlMessage(0, "%s", buf);
768
    res = send(ctxt->controlFd, buf, len, 0);
768
    res = send(ctxt->controlFd, buf, len, 0);
769
    if (res < 0) {
769
    if (res < 0) {
770
	RxmlMessage(1, "send failed");
770
	RxmlMessage(1, "send failed");
771
	return(res);
771
	return(res);
Line 790... Line 790...
790
    int len;
790
    int len;
791
 
791
 
792
    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
792
    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
793
 
793
 
794
    snprintf(buf, sizeof(buf), "QUIT\r\n");
794
    snprintf(buf, sizeof(buf), "QUIT\r\n");
795
    len = strlen(buf);
795
    len = (int) strlen(buf);
796
    RxmlMessage(0, "%s", buf);
796
    RxmlMessage(0, "%s", buf);
797
    send(ctxt->controlFd, buf, len, 0);
797
    send(ctxt->controlFd, buf, len, 0);
798
    return(0);
798
    return(0);
799
}
799
}
800
 
800
 
Line 810... Line 810...
810
static int
810
static int
811
RxmlNanoFTPConnect(void *ctx) {
811
RxmlNanoFTPConnect(void *ctx) {
812
    RxmlNanoFTPCtxtPtr ctxt = (RxmlNanoFTPCtxtPtr) ctx;
812
    RxmlNanoFTPCtxtPtr ctxt = (RxmlNanoFTPCtxtPtr) ctx;
813
    struct hostent *hp;
813
    struct hostent *hp;
814
    int port;
814
    int port;
815
    int res;
815
    ssize_t res;
816
 
816
 
817
    if (ctxt == NULL)
817
    if (ctxt == NULL)
818
	return(-1);
818
	return(-1);
819
    if (ctxt->hostname == NULL)
819
    if (ctxt->hostname == NULL)
820
	return(-1);
820
	return(-1);
Line 915... Line 915...
915
	    /*
915
	    /*
916
	     * We need proxy auth
916
	     * We need proxy auth
917
	     */
917
	     */
918
	    snprintf(buf, sizeof(buf), "USER %s\r\n", proxyUser);
918
	    snprintf(buf, sizeof(buf), "USER %s\r\n", proxyUser);
919
	    buf[sizeof(buf) - 1] = 0;
919
	    buf[sizeof(buf) - 1] = 0;
920
	    len = strlen(buf);
920
	    len = (int) strlen(buf);
921
	    RxmlMessage(0, "%s", buf);
921
	    RxmlMessage(0, "%s", buf);
922
	    res = send(ctxt->controlFd, buf, len, 0);
922
	    res = send(ctxt->controlFd, buf, len, 0);
923
	    if (res < 0) {
923
	    if (res < 0) {
924
		RxmlMessage(1, "send failed");
924
		RxmlMessage(1, "send failed");
925
		closesocket(ctxt->controlFd);
925
		closesocket(ctxt->controlFd);
Line 935... Line 935...
935
		    if (proxyPasswd != NULL)
935
		    if (proxyPasswd != NULL)
936
			snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd);
936
			snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd);
937
		    else
937
		    else
938
			snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
938
			snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
939
		    buf[sizeof(buf) - 1] = 0;
939
		    buf[sizeof(buf) - 1] = 0;
940
		    len = strlen(buf);
940
		    len = (int) strlen(buf);
941
		    RxmlMessage(0, "%s", buf);
941
		    RxmlMessage(0, "%s", buf);
942
		    res = send(ctxt->controlFd, buf, len, 0);
942
		    res = send(ctxt->controlFd, buf, len, 0);
943
		    if (res < 0) {
943
		    if (res < 0) {
944
			RxmlMessage(1, "send failed");
944
			RxmlMessage(1, "send failed");
945
			closesocket(ctxt->controlFd);
945
			closesocket(ctxt->controlFd);
Line 974... Line 974...
974
		/* we will try in sequence */
974
		/* we will try in sequence */
975
	    case 1:
975
	    case 1:
976
		/* Using SITE command */
976
		/* Using SITE command */
977
		snprintf(buf, sizeof(buf), "SITE %s\r\n", ctxt->hostname);
977
		snprintf(buf, sizeof(buf), "SITE %s\r\n", ctxt->hostname);
978
		buf[sizeof(buf) - 1] = 0;
978
		buf[sizeof(buf) - 1] = 0;
979
		len = strlen(buf);
979
		len = (int) strlen(buf);
980
		RxmlMessage(0, "%s", buf);
980
		RxmlMessage(0, "%s", buf);
981
		res = send(ctxt->controlFd, buf, len, 0);
981
		res = send(ctxt->controlFd, buf, len, 0);
982
		if (res < 0) {
982
		if (res < 0) {
983
		    RxmlMessage(1, "send failed");
983
		    RxmlMessage(1, "send failed");
984
		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
984
		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
Line 1003... Line 1003...
1003
				   ctxt->hostname);
1003
				   ctxt->hostname);
1004
		else
1004
		else
1005
		    snprintf(buf, sizeof(buf), "USER %s@%s\r\n",
1005
		    snprintf(buf, sizeof(buf), "USER %s@%s\r\n",
1006
				   ctxt->user, ctxt->hostname);
1006
				   ctxt->user, ctxt->hostname);
1007
		buf[sizeof(buf) - 1] = 0;
1007
		buf[sizeof(buf) - 1] = 0;
1008
		len = strlen(buf);
1008
		len = (int) strlen(buf);
1009
		RxmlMessage(0, "%s", buf);
1009
		RxmlMessage(0, "%s", buf);
1010
		res = send(ctxt->controlFd, buf, len, 0);
1010
		res = send(ctxt->controlFd, buf, len, 0);
1011
		if (res < 0) {
1011
		if (res < 0) {
1012
		    RxmlMessage(1, "send failed");
1012
		    RxmlMessage(1, "send failed");
1013
		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
1013
		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
Line 1024... Line 1024...
1024
		    snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
1024
		    snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
1025
		else
1025
		else
1026
 
1026
 
1027
		    snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
1027
		    snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
1028
		buf[sizeof(buf) - 1] = 0;
1028
		buf[sizeof(buf) - 1] = 0;
1029
		len = strlen(buf);
1029
		len = (int) strlen(buf);
1030
		RxmlMessage(0, "%s", buf);
1030
		RxmlMessage(0, "%s", buf);
1031
		res = send(ctxt->controlFd, buf, len, 0);
1031
		res = send(ctxt->controlFd, buf, len, 0);
1032
		if (res < 0) {
1032
		if (res < 0) {
1033
		    RxmlMessage(1, "send failed");
1033
		    RxmlMessage(1, "send failed");
1034
		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
1034
		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
Line 1138... Line 1138...
1138
    memset(&dataAddr, 0, dataAddrLen);
1138
    memset(&dataAddr, 0, dataAddrLen);
1139
    dataAddr.sin_family = AF_INET;
1139
    dataAddr.sin_family = AF_INET;
1140
 
1140
 
1141
    if (ctxt->passive) {
1141
    if (ctxt->passive) {
1142
	snprintf (buf, sizeof(buf), "PASV\r\n");
1142
	snprintf (buf, sizeof(buf), "PASV\r\n");
1143
	len = strlen(buf);
1143
	len = (int) strlen(buf);
1144
#ifdef DEBUG_FTP
1144
#ifdef DEBUG_FTP
1145
	RxmlMessage(0, "%s", buf);
1145
	RxmlMessage(0, "%s", buf);
1146
#endif
1146
#endif
1147
	res = send(ctxt->controlFd, buf, len, 0);
1147
	res = send(ctxt->controlFd, buf, len, 0);
1148
	if (res < 0) {
1148
	if (res < 0) {
Line 1201... Line 1201...
1201
	portp = (unsigned char *) &dataAddr.sin_port;
1201
	portp = (unsigned char *) &dataAddr.sin_port;
1202
	snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n",
1202
	snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n",
1203
	       adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
1203
	       adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
1204
	       portp[0] & 0xff, portp[1] & 0xff);
1204
	       portp[0] & 0xff, portp[1] & 0xff);
1205
	buf[sizeof(buf) - 1] = 0;
1205
	buf[sizeof(buf) - 1] = 0;
1206
	len = strlen(buf);
1206
	len = (int) strlen(buf);
1207
#ifdef DEBUG_FTP
1207
#ifdef DEBUG_FTP
1208
	RxmlMessage(1, "%s", buf);
1208
	RxmlMessage(1, "%s", buf);
1209
#endif
1209
#endif
1210
 
1210
 
1211
	res = send(ctxt->controlFd, buf, len, 0);
1211
	res = send(ctxt->controlFd, buf, len, 0);
Line 1249... Line 1249...
1249
    ctxt->dataFd = RxmlNanoFTPGetConnection(ctxt);
1249
    ctxt->dataFd = RxmlNanoFTPGetConnection(ctxt);
1250
    if (ctxt->dataFd == -1)
1250
    if (ctxt->dataFd == -1)
1251
	return(-1);
1251
	return(-1);
1252
 
1252
 
1253
    snprintf(buf, sizeof(buf), "TYPE I\r\n");
1253
    snprintf(buf, sizeof(buf), "TYPE I\r\n");
1254
    len = strlen(buf);
1254
    len = (int) strlen(buf);
1255
#ifdef DEBUG_FTP
1255
#ifdef DEBUG_FTP
1256
    RxmlMessage(0, "%s", buf);
1256
    RxmlMessage(0, "%s", buf);
1257
#endif
1257
#endif
1258
    res = send(ctxt->controlFd, buf, len, 0);
1258
    res = send(ctxt->controlFd, buf, len, 0);
1259
    if (res < 0) {
1259
    if (res < 0) {
Line 1269... Line 1269...
1269
    if (filename == NULL)
1269
    if (filename == NULL)
1270
	snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path);
1270
	snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path);
1271
    else
1271
    else
1272
	snprintf(buf, sizeof(buf), "RETR %s\r\n", filename);
1272
	snprintf(buf, sizeof(buf), "RETR %s\r\n", filename);
1273
    buf[sizeof(buf) - 1] = 0;
1273
    buf[sizeof(buf) - 1] = 0;
1274
    len = strlen(buf);
1274
    len = (int) strlen(buf);
1275
#ifdef DEBUG_FTP
1275
#ifdef DEBUG_FTP
1276
    RxmlMessage(0, "%s", buf);
1276
    RxmlMessage(0, "%s", buf);
1277
#endif
1277
#endif
1278
    res = send(ctxt->controlFd, buf, len, 0);
1278
    res = send(ctxt->controlFd, buf, len, 0);
1279
    if (res < 0) {
1279
    if (res < 0) {