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 ee51713..c4adc87 100755 Binary files a/test and b/test differ