summaryrefslogtreecommitdiff
path: root/src/htsftp.c
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-05-14 20:30:28 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-05-14 20:30:28 +0000
commit07f4b003675260004c49755dde413944a16ca2d3 (patch)
tree11050b4c7fbe1d7c63a38f5f9a6b5ba6d8260ae1 /src/htsftp.c
parentb09def438c5e47305e4a5ab18d8a646a3b004fdc (diff)
Indenting cleanup for all *.[ch] files, except htsparse.c (too ugly to be automatically indented for now) and /minizip/, /mmsrip/ (external files)
setup: indent -l80 -lc80 -nhnl -nut -bad -bap -bbo -br -brf -bli2 -brs -bls -br -ss -sai -pmt -nsaw -nsaf -nprs -i2 -ce -npsl -npcs -cs -sob -cdw -nbc -lp logs: indent: ./src/htsback.c:157: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1417: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1826: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1833: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1981: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:2685: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:2747: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:2861: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:3128: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:3512: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:140: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:597: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:598: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:611: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:97: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:106: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:106: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:256: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:262: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:935: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:271: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:272: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:273: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:274: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:275: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:276: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:277: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:278: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:279: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:280: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:281: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:662: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:752: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:413: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:414: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:415: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:416: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:417: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:418: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:419: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:420: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:421: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:422: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:423: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:188: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:507: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:508: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:509: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:510: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:511: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:512: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:580: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:581: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:115: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:246: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:247: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:248: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:249: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:250: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:251: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:314: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:315: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:151: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:158: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:161: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:166: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:174: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:177: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:188: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:243: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:245: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:248: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:257: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:647: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsbauth.c:364: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsbauth.c:387: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscache.c:473: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsserver.h:112: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsserver.h:187: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsjava.c:312: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsjava.c:379: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsjava.c:407: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsjava.c:472: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsjava.c:483: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htslib.c:593: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:809: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1743: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1874: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1896: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1984: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2085: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2604: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2605: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2606: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2607: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2608: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2609: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2672: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2673: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2906: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2928: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2996: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:4802: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htslib.c:5353: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5354: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5355: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5357: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5429: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5435: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscore.c:208: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscore.c:277: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscore.c:279: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscore.c:357: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htscore.c:394: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htscore.c:1544: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscore.c:3330: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscore.c:3361: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htshash.c:140: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htshash.c:217: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsname.c:733: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsname.c:749: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsname.c:933: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsname.c:1520: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htszlib.c:76: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htszlib.c:81: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscatchurl.c:268: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsinthash.c:156: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:159: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:176: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:179: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:226: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:253: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsftp.c:169: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsftp.c:177: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsfilters.c:67: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsfilters.c:80: Warning:old style assignment ambiguity in "=*". Assuming "= *"
Diffstat (limited to 'src/htsftp.c')
-rw-r--r--src/htsftp.c1071
1 files changed, 560 insertions, 511 deletions
diff --git a/src/htsftp.c b/src/htsftp.c
index d8ed03d..1a9ff77 100644
--- a/src/htsftp.c
+++ b/src/htsftp.c
@@ -17,18 +17,15 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
Important notes:
- We hereby ask people using this source NOT to use it in purpose of grabbing
emails addresses, or collecting any other private information on persons.
This would disgrace our work, and spoil the many hours we spent on it.
-
Please visit our Website: http://www.httrack.com
*/
-
/* ------------------------------------------------------------ */
/* File: basic FTP protocol manager */
/* Author: Xavier Roche */
@@ -54,7 +51,7 @@ Please visit our Website: http://www.httrack.com
#ifndef __cplusplus
// DOS
#ifndef _WIN32_WCE
-#include <process.h> /* _beginthread, _endthread */
+#include <process.h> /* _beginthread, _endthread */
#endif
#endif
#endif
@@ -72,19 +69,20 @@ Please visit our Website: http://www.httrack.com
#if USE_BEGINTHREAD
-void back_launch_ftp( void* pP ) {
- FTPDownloadStruct *pStruct = (FTPDownloadStruct*)pP;
+void back_launch_ftp(void *pP) {
+ FTPDownloadStruct *pStruct = (FTPDownloadStruct *) pP;
+
if (pStruct == NULL)
- return ;
+ return;
- if (pStruct == NULL) {
+ if (pStruct == NULL) {
#if FTP_DEBUG
printf("[ftp error: no args]\n");
#endif
- return ;
+ return;
}
- /* Initialize */
+ /* Initialize */
hts_init();
// lancer ftp
@@ -93,22 +91,23 @@ void back_launch_ftp( void* pP ) {
#endif
run_launch_ftp(pStruct);
// prêt
- pStruct->pBack->status=STATUS_FTP_READY;
+ pStruct->pBack->status = STATUS_FTP_READY;
- /* Delete structure */
- free(pP);
+ /* Delete structure */
+ free(pP);
/* Uninitialize */
hts_uninit();
- return ;
+ return;
}
+
// lancer en back
-void launch_ftp(FTPDownloadStruct* params) {
+void launch_ftp(FTPDownloadStruct * params) {
// DOS
#if FTP_DEBUG
printf("[Launching main ftp thread]\n");
#endif
- hts_newthread(back_launch_ftp, (void*) params);
+ hts_newthread(back_launch_ftp, (void *) params);
}
#else
@@ -133,71 +132,81 @@ void launch_ftp(FTPDownloadStruct* params) {
}
// la véritable fonction une fois lancées les routines thread/fork
-int run_launch_ftp(FTPDownloadStruct *pStruct) {
- lien_back* back = pStruct->pBack;
- httrackp *opt = pStruct->pOpt;
- char user[256]="anonymous";
- char pass[256]="user@";
+int run_launch_ftp(FTPDownloadStruct * pStruct) {
+ lien_back *back = pStruct->pBack;
+ httrackp *opt = pStruct->pOpt;
+ char user[256] = "anonymous";
+ char pass[256] = "user@";
char line_retr[2048];
- int port=21;
+ int port = 21;
+
#if FTP_PASV
- int port_pasv=0;
+ int port_pasv = 0;
#endif
char BIGSTK adr_ip[1024];
- char *adr,*real_adr;
- char* ftp_filename="";
- int timeout = 300; // timeout
- int timeout_onfly=8; // attente réponse supplémentaire
- int transfer_list=0; // directory
- int rest_understood=0; // rest command understood
- t_fullhostent fullhostent_buffer; // buffer pour resolver
+ char *adr, *real_adr;
+ char *ftp_filename = "";
+ int timeout = 300; // timeout
+ int timeout_onfly = 8; // attente réponse supplémentaire
+ int transfer_list = 0; // directory
+ int rest_understood = 0; // rest command understood
+ t_fullhostent fullhostent_buffer; // buffer pour resolver
+
//
- T_SOC soc_ctl=INVALID_SOCKET;
- T_SOC soc_servdat=INVALID_SOCKET;
- T_SOC soc_dat=INVALID_SOCKET;
+ T_SOC soc_ctl = INVALID_SOCKET;
+ T_SOC soc_servdat = INVALID_SOCKET;
+ T_SOC soc_dat = INVALID_SOCKET;
+
//
SOCaddr server_data;
- int server_data_size=sizeof(server_data);
+ int server_data_size = sizeof(server_data);
+
//
- line_retr[0]=adr_ip[0]='\0';
-
- timeout=300;
-
+ line_retr[0] = adr_ip[0] = '\0';
+
+ timeout = 300;
+
// effacer
- strcpybuff(back->r.msg,"");
- back->r.statuscode=0;
- back->r.size=0;
-
+ strcpybuff(back->r.msg, "");
+ back->r.statuscode = 0;
+ back->r.size = 0;
+
// récupérer user et pass si présents, et sauter user:id@ dans adr
- real_adr = strchr(back->url_adr,':');
- if (real_adr) real_adr++;
- else real_adr=back->url_adr;
- while(*real_adr=='/') real_adr++; // sauter /
- if ( (adr = jump_identification(real_adr)) != real_adr) { // user
- int i=-1;
- pass[0]='\0';
+ real_adr = strchr(back->url_adr, ':');
+ if (real_adr)
+ real_adr++;
+ else
+ real_adr = back->url_adr;
+ while(*real_adr == '/')
+ real_adr++; // sauter /
+ if ((adr = jump_identification(real_adr)) != real_adr) { // user
+ int i = -1;
+
+ pass[0] = '\0';
do {
i++;
- user[i]=real_adr[i];
- } while( (real_adr[i]!=':') && (real_adr[i]) );
- user[i]='\0';
- if (real_adr[i]==':') { // pass
- int j=-1;
- i++; // oui on saute aussi le :
+ user[i] = real_adr[i];
+ } while((real_adr[i] != ':') && (real_adr[i]));
+ user[i] = '\0';
+ if (real_adr[i] == ':') { // pass
+ int j = -1;
+
+ i++; // oui on saute aussi le :
do {
j++;
- pass[j]=real_adr[i+j];
- } while( ((&real_adr[i+j+1]) < adr) && (real_adr[i+j]) );
- pass[j]='\0';
+ pass[j] = real_adr[i + j];
+ } while(((&real_adr[i + j + 1]) < adr) && (real_adr[i + j]));
+ pass[j] = '\0';
}
}
-
// Calculer RETR <nom>
{
- char* a;
+ char *a;
+
#if 0
- a=back->url_fil + strlen(back->url_fil)-1;
- while( (a > back->url_fil) && (*a!='/')) a--;
+ a = back->url_fil + strlen(back->url_fil) - 1;
+ while((a > back->url_fil) && (*a != '/'))
+ a--;
if (*a != '/') {
a = NULL;
}
@@ -206,349 +215,359 @@ int run_launch_ftp(FTPDownloadStruct *pStruct) {
#endif
if (a != NULL && *a != '\0') {
#if 0
- a++; // sauter /
+ a++; // sauter /
#endif
- ftp_filename=a;
+ ftp_filename = a;
if (strnotempty(a)) {
- char catbuff[CATBUFF_SIZE];
- char* ua=unescape_http(catbuff,a);
+ char catbuff[CATBUFF_SIZE];
+ char *ua = unescape_http(catbuff, a);
int len_a = (int) strlen(ua);
- if (len_a > 0 && ua[len_a -1] == '/') { /* obviously a directory listing */
- transfer_list=1;
- sprintf(line_retr,"LIST -A %s",ua);
- } else if (
- (strchr(ua, ' '))
- ||
- (strchr(ua, '\"'))
- ||
- (strchr(ua, '\''))
+
+ if (len_a > 0 && ua[len_a - 1] == '/') { /* obviously a directory listing */
+ transfer_list = 1;
+ sprintf(line_retr, "LIST -A %s", ua);
+ } else if ((strchr(ua, ' '))
+ || (strchr(ua, '\"'))
+ || (strchr(ua, '\''))
) {
- sprintf(line_retr,"RETR \"%s\"",ua);
- } else { /* Regular one */
- sprintf(line_retr,"RETR %s",ua);
+ sprintf(line_retr, "RETR \"%s\"", ua);
+ } else { /* Regular one */
+ sprintf(line_retr, "RETR %s", ua);
}
} else {
- transfer_list=1;
- sprintf(line_retr,"LIST -A");
+ transfer_list = 1;
+ sprintf(line_retr, "LIST -A");
}
} else {
- strcpybuff(back->r.msg,"Unexpected PORT error");
+ strcpybuff(back->r.msg, "Unexpected PORT error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
}
-
+
#if FTP_DEBUG
- printf("Connecting to %s...\n",adr);
+ printf("Connecting to %s...\n", adr);
#endif
-
+
// connexion
{
SOCaddr server;
- int server_size=sizeof(server);
- t_hostent* hp;
- char * a;
+ int server_size = sizeof(server);
+ t_hostent *hp;
+ char *a;
char _adr[256];
- _adr[0]='\0';
+
+ _adr[0] = '\0';
//T_SOC soc_ctl;
// effacer structure
memset(&server, 0, sizeof(server));
-
+
// port
- a=strchr(adr,':'); // port
+ a = strchr(adr, ':'); // port
if (a) {
- sscanf(a+1,"%d",&port);
- strncatbuff(_adr,adr,(int) (a - adr));
+ sscanf(a + 1, "%d", &port);
+ strncatbuff(_adr, adr, (int) (a - adr));
} else
- strcpybuff(_adr,adr);
-
+ strcpybuff(_adr, adr);
+
// récupérer adresse résolue
- strcpybuff(back->info,"host name");
- hp = hts_gethostbyname(opt,_adr, &fullhostent_buffer);
+ strcpybuff(back->info, "host name");
+ hp = hts_gethostbyname(opt, _adr, &fullhostent_buffer);
if (hp == NULL) {
- strcpybuff(back->r.msg,"Unable to get server's address");
+ strcpybuff(back->r.msg, "Unable to get server's address");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_NON_FATAL;
- _HALT_FTP
- return 0;
+ back->r.statuscode = STATUSCODE_NON_FATAL;
+ _HALT_FTP return 0;
}
_CHECK_HALT_FTP;
-
+
// copie adresse
SOCaddr_copyaddr(server, server_size, hp->h_addr_list[0], hp->h_length);
// copie adresse pour cnx data
- SOCaddr_copyaddr(server_data, server_data_size, hp->h_addr_list[0], hp->h_length);
+ SOCaddr_copyaddr(server_data, server_data_size, hp->h_addr_list[0],
+ hp->h_length);
// memcpy(&server.sin_addr, hp->h_addr, hp->h_length);
-
+
// créer ("attachement") une socket (point d'accès) internet,en flot
soc_ctl = (T_SOC) socket(SOCaddr_sinfamily(server), SOCK_STREAM, 0);
- if (soc_ctl==INVALID_SOCKET) {
- strcpybuff(back->r.msg,"Unable to create a socket");
+ if (soc_ctl == INVALID_SOCKET) {
+ strcpybuff(back->r.msg, "Unable to create a socket");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- _HALT_FTP
- return 0;
+ back->r.statuscode = STATUSCODE_INVALID;
+ _HALT_FTP return 0;
}
SOCaddr_initport(server, port);
// server.sin_port = htons((unsigned short int) port);
-
+
// connexion (bloquante, on est en thread)
- strcpybuff(back->info,"connect");
+ strcpybuff(back->info, "connect");
#ifdef _WIN32
- if (connect(soc_ctl, (const struct sockaddr FAR *)&server, server_size) != 0) {
+ if (connect(soc_ctl, (const struct sockaddr FAR *) &server, server_size) !=
+ 0) {
#else
- if (connect(soc_ctl, (struct sockaddr *)&server, server_size) == -1) {
+ if (connect(soc_ctl, (struct sockaddr *) &server, server_size) == -1) {
#endif
- strcpybuff(back->r.msg,"Unable to connect to the server");
- // back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- _HALT_FTP
- return 0;
+ strcpybuff(back->r.msg, "Unable to connect to the server");
+ // back->status=STATUS_FTP_READY; // fini
+ back->r.statuscode = STATUSCODE_INVALID;
+ _HALT_FTP return 0;
#ifdef _WIN32
- }
+ }
#else
}
#endif
_CHECK_HALT_FTP;
-
+
{
char BIGSTK line[1024];
+
// envoi du login
-
+
// --USER--
- get_ftp_line(soc_ctl,line,timeout); // en tête
+ get_ftp_line(soc_ctl, line, timeout); // en tête
_CHECK_HALT_FTP;
-
- if (line[0]=='2') { // ok, connecté
- strcpybuff(back->info,"login: user");
- sprintf(line,"USER %s",user);
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if ((line[0]=='3') || (line[0]=='2')) {
+
+ if (line[0] == '2') { // ok, connecté
+ strcpybuff(back->info, "login: user");
+ sprintf(line, "USER %s", user);
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if ((line[0] == '3') || (line[0] == '2')) {
// --PASS--
if (line[0] == '3') {
- strcpybuff(back->info,"login: pass");
- sprintf(line,"PASS %s",pass);
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
+ strcpybuff(back->info, "login: pass");
+ sprintf(line, "PASS %s", pass);
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
_CHECK_HALT_FTP;
}
- if (line[0]=='2') { // ok
- send_line(soc_ctl,"TYPE I");
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='2') {
+ if (line[0] == '2') { // ok
+ send_line(soc_ctl, "TYPE I");
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') {
// ok
} else {
- strcpybuff(back->r.msg,"TYPE I error");
+ strcpybuff(back->r.msg, "TYPE I error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
#if 0
// --CWD--
- char* a;
- a=back->url_fil + strlen(back->url_fil)-1;
- while( (a > back->url_fil) && (*a!='/')) a--;
+ char *a;
+
+ a = back->url_fil + strlen(back->url_fil) - 1;
+ while((a > back->url_fil) && (*a != '/'))
+ a--;
if (*a == '/') { // ok repéré
char BIGSTK target[1024];
- target[0]='\0';
- strncatbuff(target,back->url_fil,(int) (a - back->url_fil));
- if (strnotempty(target)==0)
- strcatbuff(target,"/");
- strcpybuff(back->info,"cwd");
- sprintf(line,"CWD %s",target);
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='2') {
- send_line(soc_ctl,"TYPE I");
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='2') {
+
+ target[0] = '\0';
+ strncatbuff(target, back->url_fil, (int) (a - back->url_fil));
+ if (strnotempty(target) == 0)
+ strcatbuff(target, "/");
+ strcpybuff(back->info, "cwd");
+ sprintf(line, "CWD %s", target);
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') {
+ send_line(soc_ctl, "TYPE I");
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') {
// ok..
} else {
- strcpybuff(back->r.msg,"TYPE I error");
+ strcpybuff(back->r.msg, "TYPE I error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- sprintf(back->r.msg,"CWD error: %s",linejmp(line));
+ sprintf(back->r.msg, "CWD error: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
} else {
- strcpybuff(back->r.msg,"Unexpected ftp error");
+ strcpybuff(back->r.msg, "Unexpected ftp error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
#endif
-
+
} else {
- sprintf(back->r.msg,"Bad password: %s",linejmp(line));
+ sprintf(back->r.msg, "Bad password: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- sprintf(back->r.msg,"Bad user name: %s",linejmp(line));
+ sprintf(back->r.msg, "Bad user name: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- sprintf(back->r.msg,"Connection refused: %s",linejmp(line));
+ sprintf(back->r.msg, "Connection refused: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
-
+
// ok, si on est prêts on écoute sur un port et on demande la sauce
if (back->r.statuscode != -1) {
-
//
// Pré-REST
//
#if FTP_PASV
if (SOCaddr_getproto(server, server_size) == '1') {
- strcpybuff(back->info,"pasv");
- sprintf(line,"PASV");
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- } else { /* ipv6 */
- line[0]='\0';
+ strcpybuff(back->info, "pasv");
+ sprintf(line, "PASV");
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ } else { /* ipv6 */
+ line[0] = '\0';
}
- _CHECK_HALT_FTP;
- if (line[0]=='2') {
- char *a,*b,*c;
- a=strchr(line,'('); // exemple: 227 Entering Passive Mode (123,45,67,89,177,27)
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') {
+ char *a, *b, *c;
+
+ a = strchr(line, '('); // exemple: 227 Entering Passive Mode (123,45,67,89,177,27)
if (a) {
-
+
// -- analyse de l'adresse IP et du port --
a++;
- b=strchr(a,',');
- if (b) b=strchr(b+1,',');
- if (b) b=strchr(b+1,',');
- if (b) b=strchr(b+1,',');
- c=a; while( (c=strchr(c,',')) ) *c='.'; // remplacer , par .
- if (b) *b='\0';
+ b = strchr(a, ',');
+ if (b)
+ b = strchr(b + 1, ',');
+ if (b)
+ b = strchr(b + 1, ',');
+ if (b)
+ b = strchr(b + 1, ',');
+ c = a;
+ while((c = strchr(c, ',')))
+ *c = '.'; // remplacer , par .
+ if (b)
+ *b = '\0';
//
- strcpybuff(adr_ip,a); // copier adresse ip
+ strcpybuff(adr_ip, a); // copier adresse ip
//
if (b) {
- a=b+1; // début du port
- b=strchr(a,'.');
+ a = b + 1; // début du port
+ b = strchr(a, '.');
if (b) {
- int n1,n2;
+ int n1, n2;
+
//
- *b='\0';
+ *b = '\0';
b++;
- c=strchr(b,')');
+ c = strchr(b, ')');
if (c) {
- *c='\0';
- if ( (sscanf(a,"%d",&n1)==1) && (sscanf(b,"%d",&n2)==1) && (strlen(adr_ip)<=16)) {
- port_pasv=n2+(n1<<8);
+ *c = '\0';
+ if ((sscanf(a, "%d", &n1) == 1) && (sscanf(b, "%d", &n2) == 1)
+ && (strlen(adr_ip) <= 16)) {
+ port_pasv = n2 + (n1 << 8);
}
} else {
- deletesoc(soc_dat); soc_dat=INVALID_SOCKET;
- } // sinon on est prêts
+ deletesoc(soc_dat);
+ soc_dat = INVALID_SOCKET;
+ } // sinon on est prêts
}
}
// -- fin analyse de l'adresse IP et du port --
} else {
- sprintf(back->r.msg,"PASV incorrect: %s",linejmp(line));
+ sprintf(back->r.msg, "PASV incorrect: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
} else {
/*
- * try epsv (ipv6) *
- */
- strcpybuff(back->info,"pasv");
- sprintf(line,"EPSV");
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='2') { /* got it */
+ * try epsv (ipv6) *
+ */
+ strcpybuff(back->info, "pasv");
+ sprintf(line, "EPSV");
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') { /* got it */
char *a;
- a=strchr(line,'('); // exemple: 229 Entering Extended Passive Mode (|||6446|)
- if (
- (a != NULL)
- &&
- (*a == '(')
- && (*(a+1))
- && (*(a+1) == *(a+2)) && (*(a+1) == *(a+3))
- && (isdigit(*(a+4)))
- && (*(a+5))
+
+ a = strchr(line, '('); // exemple: 229 Entering Extended Passive Mode (|||6446|)
+ if ((a != NULL)
+ && (*a == '(')
+ && (*(a + 1))
+ && (*(a + 1) == *(a + 2)) && (*(a + 1) == *(a + 3))
+ && (isdigit(*(a + 4)))
+ && (*(a + 5))
) {
unsigned int n1 = 0;
- if (sscanf(a+4,"%d",&n1)==1) {
+
+ if (sscanf(a + 4, "%d", &n1) == 1) {
if ((n1 < 65535) && (n1 > 0)) {
- port_pasv=n1;
+ port_pasv = n1;
}
}
} else {
- sprintf(back->r.msg,"EPSV incorrect: %s",linejmp(line));
+ sprintf(back->r.msg, "EPSV incorrect: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- sprintf(back->r.msg,"PASV/EPSV error: %s",linejmp(line));
+ sprintf(back->r.msg, "PASV/EPSV error: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
}
#else
// rien à faire avant
#endif
-
+
#if FTP_PASV
if (port_pasv) {
#endif
// SIZE
if (back->r.statuscode != -1) {
if (!transfer_list) {
- char catbuff[CATBUFF_SIZE];
- char* ua=unescape_http(catbuff,ftp_filename);
- if (
- (strchr(ua, ' '))
- ||
- (strchr(ua, '\"'))
- ||
- (strchr(ua, '\''))
+ char catbuff[CATBUFF_SIZE];
+ char *ua = unescape_http(catbuff, ftp_filename);
+
+ if ((strchr(ua, ' '))
+ || (strchr(ua, '\"'))
+ || (strchr(ua, '\''))
) {
- sprintf(line,"SIZE \"%s\"", ua);
+ sprintf(line, "SIZE \"%s\"", ua);
} else {
- sprintf(line,"SIZE %s", ua);
+ sprintf(line, "SIZE %s", ua);
}
-
+
// SIZE?
- strcpybuff(back->info,"size");
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='2') { // SIZE compris, ALORS tester REST (sinon pas tester: cf probleme des txt.gz decompresses a la volee)
- char* szstr = strchr(line, ' ');
+ strcpybuff(back->info, "size");
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') { // SIZE compris, ALORS tester REST (sinon pas tester: cf probleme des txt.gz decompresses a la volee)
+ char *szstr = strchr(line, ' ');
+
if (szstr) {
LLint size = 0;
+
szstr++;
if (sscanf(szstr, LLintP, &size) == 1) {
back->r.totalsize = size;
}
}
-
// REST?
- if (fexist(back->url_sav) && (transfer_list==0)) {
- strcpybuff(back->info,"rest");
- sprintf(line,"REST "LLintP,(LLint)fsize(back->url_sav));
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if ((line[0]=='3') || (line[0]=='2')) { // ok
- rest_understood=1;
- } // sinon tant pis
- }
- } // sinon tant pis
+ if (fexist(back->url_sav) && (transfer_list == 0)) {
+ strcpybuff(back->info, "rest");
+ sprintf(line, "REST " LLintP, (LLint) fsize(back->url_sav));
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if ((line[0] == '3') || (line[0] == '2')) { // ok
+ rest_understood = 1;
+ } // sinon tant pis
+ }
+ } // sinon tant pis
}
}
#if FTP_PASV
@@ -562,29 +581,31 @@ int run_launch_ftp(FTPDownloadStruct *pStruct) {
// Ok, se connecter
if (port_pasv) {
SOCaddr server;
- int server_size=sizeof(server);
- t_hostent* hp;
+ int server_size = sizeof(server);
+ t_hostent *hp;
+
// effacer structure
memset(&server, 0, sizeof(server));
-
+
// infos
- strcpybuff(back->info,"resolv");
-
+ strcpybuff(back->info, "resolv");
+
// résoudre
if (adr_ip[0]) {
- hp = hts_gethostbyname(opt,adr_ip, &fullhostent_buffer);
+ hp = hts_gethostbyname(opt, adr_ip, &fullhostent_buffer);
if (hp) {
- SOCaddr_copyaddr(server, server_size, hp->h_addr_list[0], hp->h_length);
+ SOCaddr_copyaddr(server, server_size, hp->h_addr_list[0],
+ hp->h_length);
} else {
- server_size=0;
+ server_size = 0;
}
} else {
memcpy(&server, &server_data, sizeof(server_data));
- server_size=server_data_size;
+ server_size = server_data_size;
}
-
+
// infos
- strcpybuff(back->info,"cnxdata");
+ strcpybuff(back->info, "cnxdata");
#if FTP_DEBUG
printf("Data: Connecting to %s:%d...\n", adr_ip, port_pasv);
#endif
@@ -596,79 +617,85 @@ int run_launch_ftp(FTPDownloadStruct *pStruct) {
SOCaddr_initport(server, port_pasv);
// server.sin_port = htons((unsigned short int) port_pasv);
#ifdef _WIN32
- if (connect(soc_dat, (const struct sockaddr FAR *)&server, server_size) == 0) {
+ if (connect
+ (soc_dat, (const struct sockaddr FAR *) &server,
+ server_size) == 0) {
#else
- if (connect(soc_dat, (struct sockaddr *)&server, server_size) != -1) {
+ if (connect(soc_dat, (struct sockaddr *) &server, server_size) !=
+ -1) {
#endif
- strcpybuff(back->info,"retr");
- strcpybuff(line,line_retr);
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='1') {
+ strcpybuff(back->info, "retr");
+ strcpybuff(line, line_retr);
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '1') {
// OK
} else {
- deletesoc(soc_dat); soc_dat=INVALID_SOCKET;
+ deletesoc(soc_dat);
+ soc_dat = INVALID_SOCKET;
//
- sprintf(back->r.msg,"RETR command errror: %s",linejmp(line));
+ sprintf(back->r.msg, "RETR command errror: %s",
+ linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
} else {
#if FTP_DEBUG
printf("Data: unable to connect\n");
#endif
- deletesoc(soc_dat); soc_dat=INVALID_SOCKET;
+ deletesoc(soc_dat);
+ soc_dat = INVALID_SOCKET;
//
- strcpybuff(back->r.msg,"Unable to connect");
+ strcpybuff(back->r.msg, "Unable to connect");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
} else {
- strcpybuff(back->r.msg,"Unable to create a socket");
+ strcpybuff(back->r.msg, "Unable to create a socket");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
} else {
- sprintf(back->r.msg,"Unable to resolve IP %s",adr_ip);
+ sprintf(back->r.msg, "Unable to resolve IP %s", adr_ip);
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
} else {
- sprintf(back->r.msg,"PASV incorrect: %s",linejmp(line));
+ sprintf(back->r.msg, "PASV incorrect: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- } // sinon on est prêts
+ back->r.statuscode = STATUSCODE_INVALID;
+ } // sinon on est prêts
#else
//T_SOC soc_servdat;
- strcpybuff(back->info,"listening");
- if ( (soc_servdat = get_datasocket(line)) != INVALID_SOCKET) {
- _CHECK_HALT_FTP;
- send_line(soc_ctl,line); // envoi du RETR
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='2') { // ok
- strcpybuff(back->info,"retr");
- strcpybuff(line,line_retr);
- send_line(soc_ctl,line);
- get_ftp_line(soc_ctl,line,timeout);
- _CHECK_HALT_FTP;
- if (line[0]=='1') {
+ strcpybuff(back->info, "listening");
+ if ((soc_servdat = get_datasocket(line)) != INVALID_SOCKET) {
+ _CHECK_HALT_FTP;
+ send_line(soc_ctl, line); // envoi du RETR
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '2') { // ok
+ strcpybuff(back->info, "retr");
+ strcpybuff(line, line_retr);
+ send_line(soc_ctl, line);
+ get_ftp_line(soc_ctl, line, timeout);
+ _CHECK_HALT_FTP;
+ if (line[0] == '1') {
//T_SOC soc_dat;
- if ( (soc_dat=accept(soc_servdat, NULL, NULL)) == INVALID_SOCKET) {
- strcpybuff(back->r.msg,"Unable to accept connection");
+ if ((soc_dat = accept(soc_servdat, NULL, NULL)) == INVALID_SOCKET) {
+ strcpybuff(back->r.msg, "Unable to accept connection");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- sprintf(back->r.msg,"RETR command errror: %s",linejmp(line));
+ sprintf(back->r.msg, "RETR command errror: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- sprintf(back->r.msg,"PORT command error: %s",linejmp(line));
+ sprintf(back->r.msg, "PORT command error: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
#ifdef _WIN32
closesocket(soc_servdat);
@@ -676,356 +703,374 @@ int run_launch_ftp(FTPDownloadStruct *pStruct) {
close(soc_servdat);
#endif
} else {
- strcpybuff(back->r.msg,"Unable to listen to a port");
+ strcpybuff(back->r.msg, "Unable to listen to a port");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
#endif
-
+
//
// Ok, connexion initiée
//
if (soc_dat != INVALID_SOCKET) {
- if (rest_understood) { // REST envoyée et comprise
- file_notify(opt, back->url_adr, back->url_fil, back->url_sav, 0, 1, 0);
- back->r.fp = fileappend(&opt->state.strc, back->url_sav);
+ if (rest_understood) { // REST envoyée et comprise
+ file_notify(opt, back->url_adr, back->url_fil, back->url_sav, 0, 1,
+ 0);
+ back->r.fp = fileappend(&opt->state.strc, back->url_sav);
} else {
- file_notify(opt, back->url_adr, back->url_fil, back->url_sav, 1, 1, 0);
+ file_notify(opt, back->url_adr, back->url_fil, back->url_sav, 1, 1,
+ 0);
back->r.fp = filecreate(&opt->state.strc, back->url_sav);
}
- strcpybuff(back->info,"receiving");
+ strcpybuff(back->info, "receiving");
if (back->r.fp != NULL) {
char BIGSTK buff[1024];
- int len=1;
- int read_len=1024;
+ int len = 1;
+ int read_len = 1024;
+
//HTS_TOTAL_RECV_CHECK(read_len); // Diminuer au besoin si trop de données reçues
-
- while( (len>0) && (!stop_ftp(back)) ) {
+
+ while((len > 0) && (!stop_ftp(back))) {
// attendre les données
- len=1; // pas d'erreur pour le moment
- switch(wait_socket_receive(soc_dat,timeout)) {
+ len = 1; // pas d'erreur pour le moment
+ switch (wait_socket_receive(soc_dat, timeout)) {
case -1:
- strcpybuff(back->r.msg,"FTP read error");
+ strcpybuff(back->r.msg, "FTP read error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- len=0; // fin
+ back->r.statuscode = STATUSCODE_INVALID;
+ len = 0; // fin
break;
case 0:
- sprintf(back->r.msg,"Time out (%d)",timeout);
+ sprintf(back->r.msg, "Time out (%d)", timeout);
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- len=0; // fin
+ back->r.statuscode = STATUSCODE_INVALID;
+ len = 0; // fin
break;
}
-
+
// réception
if (len) {
- len=recv(soc_dat,buff,read_len,0);
- if (len>0) {
- back->r.size+=len;
- HTS_STAT.HTS_TOTAL_RECV+=len;
+ len = recv(soc_dat, buff, read_len, 0);
+ if (len > 0) {
+ back->r.size += len;
+ HTS_STAT.HTS_TOTAL_RECV += len;
if (back->r.fp) {
- if ((INTsys)fwrite(buff,1,(INTsys)len,back->r.fp) != len) {
+ if ((INTsys) fwrite(buff, 1, (INTsys) len, back->r.fp) !=
+ len) {
/*
- int fcheck;
- if ((fcheck=check_fatal_io_errno())) {
- opt->state.exit_xh=-1;
- }
- */
- strcpybuff(back->r.msg,"Write error");
+ int fcheck;
+ if ((fcheck=check_fatal_io_errno())) {
+ opt->state.exit_xh=-1;
+ }
+ */
+ strcpybuff(back->r.msg, "Write error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
- len=0; // error
+ back->r.statuscode = STATUSCODE_INVALID;
+ len = 0; // error
}
} else {
- strcpybuff(back->r.msg,"Unexpected write error");
+ strcpybuff(back->r.msg, "Unexpected write error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else { // Erreur ou terminé
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=0;
- if (back->r.totalsize > 0 && back->r.size != back->r.totalsize) {
- back->r.statuscode=STATUSCODE_INVALID;
- strcpybuff(back->r.msg,"FTP file incomplete");
+ back->r.statuscode = 0;
+ if (back->r.totalsize > 0
+ && back->r.size != back->r.totalsize) {
+ back->r.statuscode = STATUSCODE_INVALID;
+ strcpybuff(back->r.msg, "FTP file incomplete");
}
}
- read_len=1024;
+ read_len = 1024;
//HTS_TOTAL_RECV_CHECK(read_len); // Diminuer au besoin si trop de données reçues
}
}
- if (back->r.fp) {
- fclose(back->r.fp);
- back->r.fp=NULL;
+ if (back->r.fp) {
+ fclose(back->r.fp);
+ back->r.fp = NULL;
}
} else {
- strcpybuff(back->r.msg,"Unable to write file");
+ strcpybuff(back->r.msg, "Unable to write file");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
#ifdef _WIN32
closesocket(soc_dat);
#else
close(soc_dat);
#endif
-
+
// 226 Transfer complete?
if (back->r.statuscode != -1) {
- if (wait_socket_receive(soc_ctl,timeout_onfly)>0) {
+ if (wait_socket_receive(soc_ctl, timeout_onfly) > 0) {
// récupérer 226 transfer complete
- get_ftp_line(soc_ctl,line,timeout);
- if (line[0]=='2') { // OK
- strcpybuff(back->r.msg,"OK");
+ get_ftp_line(soc_ctl, line, timeout);
+ if (line[0] == '2') { // OK
+ strcpybuff(back->r.msg, "OK");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=HTTP_OK;
+ back->r.statuscode = HTTP_OK;
} else {
- sprintf(back->r.msg,"RETR incorrect: %s",linejmp(line));
+ sprintf(back->r.msg, "RETR incorrect: %s", linejmp(line));
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
} else {
- strcpybuff(back->r.msg,"FTP read error");
+ strcpybuff(back->r.msg, "FTP read error");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
}
}
-
+
}
-
-
-
+
}
-
-
+
}
-
+
_CHECK_HALT_FTP;
- strcpybuff(back->info,"quit");
- send_line(soc_ctl,"QUIT"); // bye bye
- get_ftp_line(soc_ctl,NULL,timeout);
+ strcpybuff(back->info, "quit");
+ send_line(soc_ctl, "QUIT"); // bye bye
+ get_ftp_line(soc_ctl, NULL, timeout);
#ifdef _WIN32
closesocket(soc_ctl);
#else
close(soc_ctl);
#endif
}
-
- if (back->r.statuscode!=-1) {
- back->r.statuscode=HTTP_OK;
- strcpybuff(back->r.msg,"OK");
+
+ if (back->r.statuscode != -1) {
+ back->r.statuscode = HTTP_OK;
+ strcpybuff(back->r.msg, "OK");
}
// back->status=STATUS_FTP_READY; // fini
return 0;
}
-
-
// ouverture d'un port
-T_SOC get_datasocket(char* to_send) {
+T_SOC get_datasocket(char *to_send) {
T_SOC soc = INVALID_SOCKET;
- char h_loc[256+2];
-
- to_send[0]='\0';
- if (gethostname(h_loc,256)==0) { // host name
+ char h_loc[256 + 2];
+
+ to_send[0] = '\0';
+ if (gethostname(h_loc, 256) == 0) { // host name
SOCaddr server;
- int server_size=sizeof(server);
- t_hostent* hp_loc;
+ int server_size = sizeof(server);
+ t_hostent *hp_loc;
t_fullhostent buffer;
// effacer structure
memset(&server, 0, sizeof(server));
- if ( (hp_loc=vxgethostbyname(h_loc, &buffer)) ) { // notre host
+ if ((hp_loc = vxgethostbyname(h_loc, &buffer))) { // notre host
// copie adresse
- SOCaddr_copyaddr(server, server_size, hp_loc->h_addr_list[0], hp_loc->h_length);
+ SOCaddr_copyaddr(server, server_size, hp_loc->h_addr_list[0],
+ hp_loc->h_length);
- if ( (soc = (T_SOC) socket(SOCaddr_sinfamily(server), SOCK_STREAM, 0)) != INVALID_SOCKET) {
+ if ((soc =
+ (T_SOC) socket(SOCaddr_sinfamily(server), SOCK_STREAM,
+ 0)) != INVALID_SOCKET) {
- if ( bind(soc,(struct sockaddr*) &server, server_size) == 0 ) {
+ if (bind(soc, (struct sockaddr *) &server, server_size) == 0) {
SOCaddr server2;
SOClen len;
- len=sizeof(server2);
+
+ len = sizeof(server2);
// effacer structure
memset(&server2, 0, sizeof(server2));
- if (getsockname(soc,(struct sockaddr*) &server2, &len) == 0) {
+ if (getsockname(soc, (struct sockaddr *) &server2, &len) == 0) {
// *port=ntohs(server.sin_port); // récupérer port
- if (listen(soc,10)>=0) { // au pif le 10
+ if (listen(soc, 10) >= 0) { // au pif le 10
#if HTS_INET6==0
- unsigned short int a,n1,n2;
+ unsigned short int a, n1, n2;
+
// calculer port
- a = SOCaddr_sinport(server2);
+ a = SOCaddr_sinport(server2);
n1 = (a & 0xff);
- n2 = ((a>>8) & 0xff);
+ n2 = ((a >> 8) & 0xff);
{
- char dots[256+2];
- char dot[256+2];
- char* a;
+ char dots[256 + 2];
+ char dot[256 + 2];
+ char *a;
+
SOCaddr_inetntoa(dot, 256, server2, sizeof(server2));
//
- dots[0]='\0';
+ dots[0] = '\0';
strncatbuff(dots, dot, 128);
- while( (a=strchr(dots,'.')) ) *a=','; // virgules!
- while( (a=strchr(dots,':')) ) *a=','; // virgules!
- sprintf(to_send,"PORT %s,%d,%d",dots,n1,n2);
+ while((a = strchr(dots, '.')))
+ *a = ','; // virgules!
+ while((a = strchr(dots, ':')))
+ *a = ','; // virgules!
+ sprintf(to_send, "PORT %s,%d,%d", dots, n1, n2);
}
#else
/*
- EPRT |1|132.235.1.2|6275|
- EPRT |2|1080::8:800:200C:417A|5282|
- */
+ EPRT |1|132.235.1.2|6275|
+ EPRT |2|1080::8:800:200C:417A|5282|
+ */
{
- char dot[256+2];
+ char dot[256 + 2];
+
SOCaddr_inetntoa(dot, 256, server2, len);
- sprintf(to_send,"EPRT |%c|%s|%d|", SOCaddr_getproto(server2, len), dot, SOCaddr_sinport(server2));
+ sprintf(to_send, "EPRT |%c|%s|%d|",
+ SOCaddr_getproto(server2, len), dot,
+ SOCaddr_sinport(server2));
}
#endif
-
+
} else {
#ifdef _WIN32
closesocket(soc);
#else
close(soc);
#endif
- soc=INVALID_SOCKET;
+ soc = INVALID_SOCKET;
}
-
-
+
} else {
#ifdef _WIN32
closesocket(soc);
#else
close(soc);
#endif
- soc=INVALID_SOCKET;
+ soc = INVALID_SOCKET;
}
-
-
+
} else {
#ifdef _WIN32
closesocket(soc);
#else
close(soc);
#endif
- soc=INVALID_SOCKET;
+ soc = INVALID_SOCKET;
}
}
}
}
-
-
+
return soc;
}
#if FTP_DEBUG
-FILE* dd=NULL;
+FILE *dd = NULL;
#endif
// routines de réception/émission
// 0 = ERROR
-int send_line(T_SOC soc,char* data) {
+int send_line(T_SOC soc, char *data) {
char BIGSTK line[1024];
+
if (_DEBUG_HEAD) {
if (ioinfo) {
- fprintf(ioinfo,"---> %s\x0d\x0a",data);
+ fprintf(ioinfo, "---> %s\x0d\x0a", data);
fflush(ioinfo);
}
}
#if FTP_DEBUG
- if (dd == NULL) dd = fopen("toto.txt","w");
- fprintf(dd,"---> %s\x0d\x0a",data); fflush(dd);
- printf("---> %s",data); fflush(stdout);
+ if (dd == NULL)
+ dd = fopen("toto.txt", "w");
+ fprintf(dd, "---> %s\x0d\x0a", data);
+ fflush(dd);
+ printf("---> %s", data);
+ fflush(stdout);
#endif
- sprintf(line,"%s\x0d\x0a",data);
+ sprintf(line, "%s\x0d\x0a", data);
if (check_socket_connect(soc) != 1) {
#if FTP_DEBUG
printf("!SOC WRITE ERROR\n");
#endif
- return 0; // erreur, plus connecté!
+ return 0; // erreur, plus connecté!
}
#if FTP_DEBUG
{
- int r = (send(soc,line,strlen(line),0) == (int) strlen(line));
- printf("%s\x0d\x0a",data); fflush(stdout);
+ int r = (send(soc, line, strlen(line), 0) == (int) strlen(line));
+
+ printf("%s\x0d\x0a", data);
+ fflush(stdout);
return r;
}
#else
- return (send(soc,line,(int)strlen(line),0) == (int) strlen(line));
+ return (send(soc, line, (int) strlen(line), 0) == (int) strlen(line));
#endif
}
-int get_ftp_line(T_SOC soc,char* line,int timeout) {
+int get_ftp_line(T_SOC soc, char *line, int timeout) {
char BIGSTK data[1024];
- int i,ok,multiline;
+ int i, ok, multiline;
+
#if FTP_DEBUG
- if (dd == NULL) dd = fopen("toto.txt","w");
+ if (dd == NULL)
+ dd = fopen("toto.txt", "w");
#endif
-
- data[0]='\0';
- i=ok=multiline=0; data[3]='\0';
+
+ data[0] = '\0';
+ i = ok = multiline = 0;
+ data[3] = '\0';
do {
- char b;
-
+ char b;
+
// vérifier données
- switch(wait_socket_receive(soc,timeout)) {
- case -1: // erreur de lecture
- if (line) strcpybuff(line,"500 *read error");
+ switch (wait_socket_receive(soc, timeout)) {
+ case -1: // erreur de lecture
+ if (line)
+ strcpybuff(line, "500 *read error");
return 0;
break;
case 0:
- if (line) sprintf(line,"500 *read timeout (%d)",timeout);
+ if (line)
+ sprintf(line, "500 *read timeout (%d)", timeout);
return 0;
break;
}
-
+
//HTS_TOTAL_RECV_CHECK(dummy); // Diminuer au besoin si trop de données reçues
- switch(recv(soc,&b,1,0)) {
+ switch (recv(soc, &b, 1, 0)) {
//case 0: break; // pas encore --> erreur (on attend)!
case 1:
- HTS_STAT.HTS_TOTAL_RECV+=1; // compter flux entrant
- if ((b!=10) && (b!=13))
- data[i++]=b;
+ HTS_STAT.HTS_TOTAL_RECV += 1; // compter flux entrant
+ if ((b != 10) && (b != 13))
+ data[i++] = b;
break;
default:
- if (line) strcpybuff(line,"500 *read error");
- return 0; // error
+ if (line)
+ strcpybuff(line, "500 *read error");
+ return 0; // error
break;
}
- if ( ((b==13) || (b==10)) && (i>0) ){ // CR/LF
- if (
- (data[3] == '-')
- ||
- ((multiline) && (!isdigit((unsigned char)data[0])))
- )
- {
- data[3]='\0';
- i=0;
- multiline=1;
- }
- else
- ok=1; // sortir
+ if (((b == 13) || (b == 10)) && (i > 0)) { // CR/LF
+ if ((data[3] == '-')
+ || ((multiline) && (!isdigit((unsigned char) data[0])))
+ ) {
+ data[3] = '\0';
+ i = 0;
+ multiline = 1;
+ } else
+ ok = 1; // sortir
}
} while(!ok);
- data[i++]='\0';
-
+ data[i++] = '\0';
+
if (_DEBUG_HEAD) {
if (ioinfo) {
- fprintf(ioinfo,"<--- %s\x0d\x0a",data);
+ fprintf(ioinfo, "<--- %s\x0d\x0a", data);
fflush(ioinfo);
}
}
#if FTP_DEBUG
- fprintf(dd,"<--- %s\n",data); fflush(dd);
- printf("<--- %s\n",data);
+ fprintf(dd, "<--- %s\n", data);
+ fflush(dd);
+ printf("<--- %s\n", data);
#endif
- if (line) strcpybuff(line,data);
+ if (line)
+ strcpybuff(line, data);
return (strnotempty(data));
}
// sauter NNN
-char* linejmp(char* line) {
- if (strlen(line)>4)
- return line+4;
+char *linejmp(char *line) {
+ if (strlen(line) > 4)
+ return line + 4;
else
return line;
}
@@ -1035,78 +1080,82 @@ char* linejmp(char* line) {
// 1 : data detected
// -1: error
int check_socket(T_SOC soc) {
- fd_set fds,fds_e; // poll structures
- struct timeval tv; // structure for select
+ fd_set fds, fds_e; // poll structures
+ struct timeval tv; // structure for select
+
FD_ZERO(&fds);
- FD_ZERO(&fds_e);
+ FD_ZERO(&fds_e);
// socket read
- FD_SET(soc,&fds);
+ FD_SET(soc, &fds);
// socket error
- FD_SET(soc,&fds_e);
- tv.tv_sec=0;
- tv.tv_usec=0;
+ FD_SET(soc, &fds_e);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
// poll!
- select(soc + 1,&fds,NULL,&fds_e,&tv);
- if (FD_ISSET(soc,&fds_e)) { // error detected
+ select(soc + 1, &fds, NULL, &fds_e, &tv);
+ if (FD_ISSET(soc, &fds_e)) { // error detected
return -1;
- } else if (FD_ISSET(soc,&fds)) {
+ } else if (FD_ISSET(soc, &fds)) {
return 1;
}
return 0;
}
+
// check if connected
int check_socket_connect(T_SOC soc) {
- fd_set fds,fds_e; // poll structures
- struct timeval tv; // structure for select
+ fd_set fds, fds_e; // poll structures
+ struct timeval tv; // structure for select
+
FD_ZERO(&fds);
- FD_ZERO(&fds_e);
+ FD_ZERO(&fds_e);
// socket write
- FD_SET(soc,&fds);
+ FD_SET(soc, &fds);
// socket error
- FD_SET(soc,&fds_e);
- tv.tv_sec=0;
- tv.tv_usec=0;
+ FD_SET(soc, &fds_e);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
// poll!
- select(soc + 1,NULL,&fds,&fds_e,&tv);
- if (FD_ISSET(soc,&fds_e)) { // error detected
+ select(soc + 1, NULL, &fds, &fds_e, &tv);
+ if (FD_ISSET(soc, &fds_e)) { // error detected
return -1;
- } else if (FD_ISSET(soc,&fds)) {
+ } else if (FD_ISSET(soc, &fds)) {
return 1;
}
return 0;
}
+
// attendre des données
-int wait_socket_receive(T_SOC soc,int timeout) {
+int wait_socket_receive(T_SOC soc, int timeout) {
// attendre les données
- TStamp ltime=time_local();
+ TStamp ltime = time_local();
int r;
+
#if FTP_DEBUG
- printf("\x0dWaiting for data "); fflush(stdout);
+ printf("\x0dWaiting for data ");
+ fflush(stdout);
#endif
- while( (!(r = check_socket(soc))) && ( ((int) ((TStamp) (time_local()-ltime))) < timeout )) {
+ while((!(r = check_socket(soc)))
+ && (((int) ((TStamp) (time_local() - ltime))) < timeout)) {
Sleep(100);
#if FTP_DEBUG
- printf("."); fflush(stdout);
+ printf(".");
+ fflush(stdout);
#endif
}
#if FTP_DEBUG
- printf("\x0dreturn: %d\x0d",r); fflush(stdout);
+ printf("\x0dreturn: %d\x0d", r);
+ fflush(stdout);
#endif
return r;
}
-
// cancel reçu?
-int stop_ftp(lien_back* back) {
+int stop_ftp(lien_back * back) {
if (back->stop_ftp) {
strcpybuff(back->r.msg, "Cancelled by User");
// back->status=STATUS_FTP_READY; // fini
- back->r.statuscode=STATUSCODE_INVALID;
+ back->r.statuscode = STATUSCODE_INVALID;
return 1;
}
return 0;
}
-
-
-
-