From a79a8134583ea0f8aad31f5fe4612641e437948e Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 15 Dec 2015 12:31:14 +0100 Subject: [PATCH] =?UTF-8?q?LS=20bient=C3=B4t=20fini=20(probl=C3=A8me=20de?= =?UTF-8?q?=20fermeture=20de=20BUFFER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dep/server.c | 33 +++++++++++++++++++++++++++------ dep/utility.c | 21 ++++++++++++--------- proxy_ftp.c | 4 ++-- test | Bin 22815 -> 18761 bytes 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/dep/server.c b/dep/server.c index de3187f..15214bf 100644 --- a/dep/server.c +++ b/dep/server.c @@ -239,7 +239,7 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){ /* (7) Mode passif => On lance les SOCKETS du BUS DE DONNEES --------------------------------------------*/ else if( strcmp(ftpCode, "227") == 0 ){ // on lance la SOCKET FTP du BUS DE DONNEES - strcpy(response, "200 Tout s'est bien passé.\n"); + strcpy(response, "200 Connection établie.\n"); int a1, a2, a3, a4 = 0; int p1, p2 = 0; @@ -265,13 +265,27 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){ char BUFFER[maxBuffLen]; // on lit la SOCKET FTP - if( sread(DFTP_SOCKET, BUFFER) == -1 ) printf("ERROR\n"); - else xPrint("[BUS_IN]: %s\n", BUFFER); + int nbRead = sread(DFTP_SOCKET, BUFFER); + + if( DEBUGMOD && nbRead == -1 ) printf("ERROR\n"); + else if( DEBUGMOD ) xPrint("[BUS_IN]: %s\n", BUFFER); + // on redirige sur la SOCKET utilisateur - if( swrite(DUSER_SOCKET, BUFFER) == -1 ) printf("ERROR\n"); - else xPrint("[BUS_OUT]: %s\n", BUFFER); + int nbWritten = swrite(DUSER_SOCKET, BUFFER); + if( DEBUGMOD && nbWritten == -1 ) printf("ERROR\n"); + else if( DEBUGMOD ) xPrint("[BUS_OUT]: %s\n", BUFFER); + + xPrint("BUS_FTP->BUS_CLIENT: %s\n", BUFFER); + + close(*DFTP_SOCKET); + if( DEBUGMOD ) printf("BUS_FTP fermé\n"); + close(*DUSER_SOCKET); + if( DEBUGMOD ) printf("BUS_USER fermé\n"); + + // strcpy(response, "226 Tout est ok\n"); + strcpy(response, "150 Serveur en attente!\n"); } @@ -279,7 +293,7 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){ /* (9) Fin de transfert de données --------------------------------------------*/ else if( strcmp(ftpCode, "226") == 0 ){ // on ferme les SOCKETS du BUS DE DONNEES - strcpy(response, *pAnswer); + strcpy(response, "226 Fin de la transaction!\n"); close(*DUSER_SOCKET); close(*DFTP_SOCKET); } @@ -318,4 +332,11 @@ int WAIT_SOCKET_UPDATE(int* pSocket, char* pBuffer){ // on retourne -1 si erreur, SINON 0 return nbRead; +} + + + + +void prefixFtpResponse(char* pBuffer, char* ftpCode){ + } \ No newline at end of file diff --git a/dep/utility.c b/dep/utility.c index 8ab4610..62b9819 100644 --- a/dep/utility.c +++ b/dep/utility.c @@ -71,16 +71,19 @@ void formatBuffer(char* pBuffer){ /* [1] On retire les "\n" et "\r" de la fin de la chaine ============================================================*/ - int i; + int i = strlen(pBuffer); - for( i = strlen(pBuffer)-1 ; i >= 0 || pBuffer[i] != '\0' ; i-- ) - if( pBuffer[i] == '\n' || pBuffer[i] == '\r' ) // si c'est un retour chariot - pBuffer[i] = '\0'; // on efface - else - break; + while( pBuffer[strlen(pBuffer)-1] == '\r' || pBuffer[strlen(pBuffer)-1] == '\n' ) + pBuffer[strlen(pBuffer)-1] = '\0'; + + // for( i = strlen(pBuffer)-1 ; i >= 0 || pBuffer[i] != '\0' ; i-- ) + // if( pBuffer[i] == '\n' || pBuffer[i] == '\r' ) // si c'est un retour chariot + // pBuffer[i] = '\0'; // on efface + // else + // break; // on ferme ensuite la chaîne - pBuffer[i] = '\0'; + // pBuffer[i] = '\0'; /* [2] On ajoute "\r\n" à la fin ============================================================*/ @@ -109,7 +112,7 @@ void read_stdin(char* pBuffer, unsigned long pLength){ int swrite(int* pSocket, char* pBuffer){ if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur - return write(*pSocket, pBuffer, strlen(pBuffer), MSG_DONTROUTE); + return write(*pSocket, pBuffer, strlen(pBuffer)); } @@ -124,7 +127,7 @@ int sread(int* pSocket, char* pBuffer){ // si on est déconnecté, on ferme la SOCKET if( nbRead == 0 ){ - close(*pSocket); + // close(*pSocket); return -1; // on retourne une erreur } diff --git a/proxy_ftp.c b/proxy_ftp.c index 483ca69..046a1b0 100644 --- a/proxy_ftp.c +++ b/proxy_ftp.c @@ -123,8 +123,8 @@ static void* testServer(char* localPort){ /* [8] On vide les buffers ============================================================================*/ - memset(BUFFER, '\0', sizeof(BUFFER)); // on vide le buffer - ftp_response = NULL; + memset(BUFFER, '\0', maxBuffLen); // on vide le buffer + memset(ftp_response, '\0', maxBuffLen); } /* [9] Fermeture des connections (SOCKETS) diff --git a/test b/test index ee51713707aa497a025352f50a241c0a307e0678..c4adc8744851418791327fb0e24810081d41c49a 100755 GIT binary patch delta 7220 zcmZ`;3s_WFl0LVaM}r{Uyt;WwH-Z61nue^zObj;i@V0}BudJUN14x>PNq}gRad%9> zF`c!;k|EZ(8?&<$%{QBI@>-0VLB}ANtYq@-7?Rm9G5eShGn#HmA}Sj4(7RRVp4)pH zcaI-cr~ax_r_QOm=iWX(|GM=1JyO3dxoMW0QBx^n4du@izgTsD2?v?R8MAXhLK=gA zW+xYsH}Q_fFB$|67Rl-;6jp`8O55)>OYWW0WQ@&oTLRt-EqzqaV<8?WTN+BdeEV#elHG!u3jOTkydZ zTfNP&FDBd8@=(V%FMGi2+t$(YV0-h!Ue?^w;_dXoaLjF~Ki=Br^RmXq2OjQdZ`|f< z-s)>?1SvMHduhFANp)knv)s7=CoqVA#&AzVNEdYrs%j}Ri5c+^i-H7f*0#1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