Correction LIST ok, mais tjs un décalage de BUFFER

This commit is contained in:
xdrm-brackets 2015-12-15 19:44:19 +01:00
parent a79a813458
commit e25c64e785
5 changed files with 30 additions and 35 deletions

View File

@ -182,8 +182,8 @@ void MANAGE_REQUEST(char* pRequest, int* DUSER_SOCKET, int* DFTP_SOCKET){
void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
if( DEBUGMOD ) printf("====== MANAGE_RESPONSE(%s, %d, %d) ======\n\n", *pAnswer, *DUSER_SOCKET, *DFTP_SOCKET);
void MANAGE_RESPONSE(int* USER_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
if( DEBUGMOD ) printf("====== MANAGE_RESPONSE(%d, %s, %d, %d) ======\n\n", *USER_SOCKET, pAnswer, *DUSER_SOCKET, *DFTP_SOCKET);
char response[maxBuffLen]; // contiendra la réponse
char ftpCode[4]; // contiendra le code FTP (1ère partie)
@ -197,7 +197,7 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
/* [1] On découpe la requête en 2 parties
================================================*/
splitFtpResponse(*pAnswer, ftpCode, ftpText);
splitFtpResponse(pAnswer, ftpCode, ftpText);
/* [2] Selection en fonction de @ftpCode
================================================*/
@ -213,39 +213,38 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
else if( strcmp(ftpCode, "331") == 0 )
strcpy(response, USER_MSG);
/* (3) Bon mdp -> connection
/* (4) Bon mdp -> connection
--------------------------------------------*/
else if( strcmp(ftpCode, "230") == 0 )
strcpy(response, PASS_BON_MSG);
/* (4) Mauvais mdp -> connection
/* (5) Mauvais mdp -> connection
--------------------------------------------*/
else if( strcmp(ftpCode, "530") == 0 )
strcpy(response, PASS_BAD_MSG);
/* (5) Info SYST
/* (6) Info SYST
--------------------------------------------*/
// else if( strcmp(ftpCode, "215") == 0 )
// strcpy(response, "bla\n");
/* (6) LOGOUT => EXIT
/* (7) LOGOUT => EXIT
--------------------------------------------*/
else if( strcmp(ftpCode, "221") == 0 )
strcpy(response, EXIT_MSG);
/* (7) Mode passif => On lance les SOCKETS du BUS DE DONNEES
/* (8) 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 Connection établie.\n");
int a1, a2, a3, a4 = 0;
int p1, p2 = 0;
char serverHost[maxHostLen];
char serverPort[maxPortLen];
sscanf(*pAnswer, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)", &a1, &a2, &a3, &a4, &p1, &p2);
sscanf(pAnswer, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)", &a1, &a2, &a3, &a4, &p1, &p2);
// on récupère l'adresse en <char*>
sprintf(serverHost, "%d.%d.%d.%d", a1, a2, a3, a4);
// on récupère le port en <char*>
@ -255,10 +254,12 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
printf("CONNECTING TO FTP %s:%s\n", serverHost, serverPort);
CONNECT_CLIENT(serverHost, serverPort, DFTP_SOCKET);
printf("CONNECTED TO FTP %s:%s\n", serverHost, serverPort);
strcpy(response, "200 PORT command successful\n");
}
/* (8) On lit la SOCKET FTP du BUS DE DONNEES
/* (9) On lit la SOCKET FTP du BUS DE DONNEES
--------------------------------------------*/
else if( strcmp(ftpCode, "150") == 0 ){ // on lit la SOCKET FTP du BUS DE DONNEES
@ -285,12 +286,12 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
if( DEBUGMOD ) printf("BUS_USER fermé\n");
// strcpy(response, "226 Tout est ok\n");
strcpy(response, "150 Serveur en attente!\n");
swrite(USER_SOCKET, "150 Serveur en attente!\n");
strcpy(response, "226 Fin de la transaction\n");
}
/* (9) Fin de transfert de données
/* (10) Fin de transfert de données
--------------------------------------------*/
else if( strcmp(ftpCode, "226") == 0 ){ // on ferme les SOCKETS du BUS DE DONNEES
strcpy(response, "226 Fin de la transaction!\n");
@ -301,12 +302,12 @@ void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
/* (n) Commande inconnue
--------------------------------------------*/
else
strcpy(response, *pAnswer);
strcpy(response, pAnswer);
/* [3] Retour de la réponse
================================================*/
strcpy(*pAnswer, response);
strcpy(pAnswer, response);
}

View File

@ -43,7 +43,7 @@ void MANAGE_REQUEST(char* pRequest, int* DUSER_SOCKET, int* DFTP_SOCKET);
* [4] SI 226, on ferme les SOCKETS du BUS DE DONNEES
*
*/
void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET);
void MANAGE_RESPONSE(int* USER_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET);

View File

@ -76,15 +76,6 @@ void formatBuffer(char* pBuffer){
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';
/* [2] On ajoute "\r\n" à la fin
============================================================*/
strcpy(pBuffer, strcat(pBuffer, "\r\n"));
@ -97,13 +88,11 @@ void formatBuffer(char* pBuffer){
void read_stdin(char* pBuffer, unsigned long pLength){
fgets(pBuffer, pLength, stdin); // on lit l'entrée standard
int i;
// on supprimes les retours à la ligne de la fin
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;
int i = strlen(pBuffer);
while( pBuffer[strlen(pBuffer)-1] == '\r' || pBuffer[strlen(pBuffer)-1] == '\n' )
pBuffer[strlen(pBuffer)-1] = '\0';
strcpy(pBuffer, strcat(pBuffer, "\r\n"));
}
@ -112,6 +101,11 @@ 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
if( strlen(pBuffer) == 0 ) return 0;
// on formatte @pBuffer
// formatBuffer(pBuffer);
return write(*pSocket, pBuffer, strlen(pBuffer));
}
@ -150,5 +144,5 @@ void xPrint(char* pPattern, char* pBuffer){
else
break;
printf(pPattern, tmpBuffer);
printf(pPattern, pBuffer);
}

View File

@ -80,7 +80,7 @@ static void* testServer(char* localPort){
============================================================================*/
strcpy(BUFFER, "");
CLIENT_SEND(&FTP_SOCKET, BUFFER, &ftp_response);
MANAGE_RESPONSE(&ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
MANAGE_RESPONSE(&USER_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
swrite(&USER_SOCKET, ftp_response);
xPrint("P->F: %s\n\n", BUFFER);
@ -112,7 +112,7 @@ static void* testServer(char* localPort){
/* [6] Traitement de la réponse (FTP)
============================================================================*/
MANAGE_RESPONSE(&ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
MANAGE_RESPONSE(&USER_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
/* [7] Redirection vers le CLIENT

BIN
test

Binary file not shown.