Toutes les commandes FTP fonctionnent sauf un pb de blocage niveau proxy juste après débug de "BUS_FTP->BUS_CLIENT .." de temps en temps
This commit is contained in:
parent
e25c64e785
commit
0c09165d57
48
dep/server.c
48
dep/server.c
|
@ -182,63 +182,68 @@ void MANAGE_REQUEST(char* pRequest, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MANAGE_RESPONSE(int* USER_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
void MANAGE_RESPONSE(int* USER_SOCKET, int* FTP_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);
|
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 response[maxBuffLen]; // contiendra la réponse
|
||||||
char ftpCode[4]; // contiendra le code FTP (1ère partie)
|
char ftpCodeStr[4]; // contiendra le code FTP (1ère partie)
|
||||||
char ftpText[maxBuffLen]; // contiendra le texte associé à la commande (2ème partie)
|
char ftpText[maxBuffLen]; // contiendra le texte associé à la commande (2ème partie)
|
||||||
|
int ftpCode; // contiendra le code FTP en numérique
|
||||||
|
|
||||||
// on vide les buffers
|
// on vide les buffers
|
||||||
memset(&ftpCode, '\0', sizeof(ftpCode));
|
memset(&ftpCodeStr, '\0', sizeof(ftpCode));
|
||||||
memset(&ftpText, '\0', sizeof(ftpText));
|
memset(&ftpText, '\0', sizeof(ftpText));
|
||||||
memset(&response, '\0', sizeof(response));
|
memset(&response, '\0', sizeof(response));
|
||||||
|
|
||||||
|
|
||||||
/* [1] On découpe la requête en 2 parties
|
/* [1] On découpe la requête en 2 parties
|
||||||
================================================*/
|
================================================*/
|
||||||
splitFtpResponse(pAnswer, ftpCode, ftpText);
|
splitFtpResponse(pAnswer, ftpCodeStr, ftpText);
|
||||||
|
|
||||||
|
// on met le code FTP en <int>
|
||||||
|
ftpCode = atoi( ftpCodeStr );
|
||||||
|
|
||||||
|
|
||||||
/* [2] Selection en fonction de @ftpCode
|
/* [2] Selection en fonction de @ftpCode
|
||||||
================================================*/
|
================================================*/
|
||||||
|
|
||||||
/* (2) Demande d'username
|
/* (2) Demande d'username
|
||||||
--------------------------------------------*/
|
--------------------------------------------*/
|
||||||
if( strcmp(ftpCode, "220") == 0 )
|
if( ftpCode == 220 )
|
||||||
strcpy(response, WLCM_MSG);
|
strcpy(response, WLCM_MSG);
|
||||||
|
|
||||||
|
|
||||||
/* (3) username OK -> demande MDP
|
/* (3) username OK -> demande MDP
|
||||||
--------------------------------------------*/
|
--------------------------------------------*/
|
||||||
else if( strcmp(ftpCode, "331") == 0 )
|
else if( ftpCode == 331 )
|
||||||
strcpy(response, USER_MSG);
|
strcpy(response, USER_MSG);
|
||||||
|
|
||||||
/* (4) Bon mdp -> connection
|
/* (4) Bon mdp -> connection
|
||||||
--------------------------------------------*/
|
--------------------------------------------*/
|
||||||
else if( strcmp(ftpCode, "230") == 0 )
|
else if( ftpCode == 230 )
|
||||||
strcpy(response, PASS_BON_MSG);
|
strcpy(response, PASS_BON_MSG);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (5) Mauvais mdp -> connection
|
/* (5) Mauvais mdp -> connection
|
||||||
--------------------------------------------*/
|
--------------------------------------------*/
|
||||||
else if( strcmp(ftpCode, "530") == 0 )
|
else if( ftpCode == 530 )
|
||||||
strcpy(response, PASS_BAD_MSG);
|
strcpy(response, PASS_BAD_MSG);
|
||||||
|
|
||||||
/* (6) Info SYST
|
/* (6) Info SYST
|
||||||
--------------------------------------------*/
|
--------------------------------------------*/
|
||||||
// else if( strcmp(ftpCode, "215") == 0 )
|
// else if( ftpCode == 215 )
|
||||||
// strcpy(response, "bla\n");
|
// strcpy(response, "bla\n");
|
||||||
|
|
||||||
/* (7) LOGOUT => EXIT
|
/* (7) LOGOUT => EXIT
|
||||||
--------------------------------------------*/
|
--------------------------------------------*/
|
||||||
else if( strcmp(ftpCode, "221") == 0 )
|
else if( ftpCode == 221 )
|
||||||
strcpy(response, EXIT_MSG);
|
strcpy(response, EXIT_MSG);
|
||||||
|
|
||||||
|
|
||||||
/* (8) 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
|
else if( ftpCode == 227 ){ // on lance la SOCKET FTP du BUS DE DONNEES
|
||||||
int a1, a2, a3, a4 = 0;
|
int a1, a2, a3, a4 = 0;
|
||||||
int p1, p2 = 0;
|
int p1, p2 = 0;
|
||||||
|
|
||||||
|
@ -261,12 +266,12 @@ void MANAGE_RESPONSE(int* USER_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DF
|
||||||
|
|
||||||
/* (9) 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
|
else if( ftpCode == 150 ){ // on lit la SOCKET FTP du BUS DE DONNEES
|
||||||
|
|
||||||
char BUFFER[maxBuffLen];
|
char BUFFER[maxBuffLen];
|
||||||
|
|
||||||
// on lit la SOCKET FTP
|
// on lit la SOCKET FTP
|
||||||
int nbRead = sread(DFTP_SOCKET, BUFFER);
|
int nbRead = WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||||
|
|
||||||
if( DEBUGMOD && nbRead == -1 ) printf("ERROR\n");
|
if( DEBUGMOD && nbRead == -1 ) printf("ERROR\n");
|
||||||
else if( DEBUGMOD ) xPrint("[BUS_IN]: %s\n", BUFFER);
|
else if( DEBUGMOD ) xPrint("[BUS_IN]: %s\n", BUFFER);
|
||||||
|
@ -285,15 +290,20 @@ void MANAGE_RESPONSE(int* USER_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DF
|
||||||
close(*DUSER_SOCKET);
|
close(*DUSER_SOCKET);
|
||||||
if( DEBUGMOD ) printf("BUS_USER fermé\n");
|
if( DEBUGMOD ) printf("BUS_USER fermé\n");
|
||||||
|
|
||||||
// strcpy(response, "226 Tout est ok\n");
|
// on vide le SOCKET FTP du BUS DE DONNEES
|
||||||
swrite(USER_SOCKET, "150 Serveur en attente!\n");
|
WAIT_SOCKET_UPDATE(FTP_SOCKET, BUFFER);
|
||||||
strcpy(response, "226 Fin de la transaction\n");
|
WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||||
|
|
||||||
|
swrite(USER_SOCKET, "150 Attente de la réception!\n");
|
||||||
|
|
||||||
|
|
||||||
|
strcpy(response, "226 Données reçues!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (10) 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
|
else if( ftpCode == 226 ){ // on ferme les SOCKETS du BUS DE DONNEES
|
||||||
strcpy(response, "226 Fin de la transaction!\n");
|
strcpy(response, "226 Fin de la transaction!\n");
|
||||||
close(*DUSER_SOCKET);
|
close(*DUSER_SOCKET);
|
||||||
close(*DFTP_SOCKET);
|
close(*DFTP_SOCKET);
|
||||||
|
|
|
@ -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
|
* [4] SI 226, on ferme les SOCKETS du BUS DE DONNEES
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void MANAGE_RESPONSE(int* USER_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET);
|
void MANAGE_RESPONSE(int* USER_SOCKET, int* FTP_SOCKET, char* pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,9 +102,8 @@ int swrite(int* pSocket, char* pBuffer){
|
||||||
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
||||||
|
|
||||||
|
|
||||||
if( strlen(pBuffer) == 0 ) return 0;
|
// if( strlen(pBuffer) == 0 ) return 0;
|
||||||
// on formatte @pBuffer
|
|
||||||
// formatBuffer(pBuffer);
|
|
||||||
|
|
||||||
return write(*pSocket, pBuffer, strlen(pBuffer));
|
return write(*pSocket, pBuffer, strlen(pBuffer));
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void* testServer(char* localPort){
|
||||||
============================================================================*/
|
============================================================================*/
|
||||||
strcpy(BUFFER, "");
|
strcpy(BUFFER, "");
|
||||||
CLIENT_SEND(&FTP_SOCKET, BUFFER, &ftp_response);
|
CLIENT_SEND(&FTP_SOCKET, BUFFER, &ftp_response);
|
||||||
MANAGE_RESPONSE(&USER_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
|
MANAGE_RESPONSE(&USER_SOCKET, &FTP_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||||
swrite(&USER_SOCKET, ftp_response);
|
swrite(&USER_SOCKET, ftp_response);
|
||||||
|
|
||||||
xPrint("P->F: %s\n\n", BUFFER);
|
xPrint("P->F: %s\n\n", BUFFER);
|
||||||
|
@ -112,7 +112,7 @@ static void* testServer(char* localPort){
|
||||||
|
|
||||||
/* [6] Traitement de la réponse (FTP)
|
/* [6] Traitement de la réponse (FTP)
|
||||||
============================================================================*/
|
============================================================================*/
|
||||||
MANAGE_RESPONSE(&USER_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
|
MANAGE_RESPONSE(&USER_SOCKET, &FTP_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||||
|
|
||||||
|
|
||||||
/* [7] Redirection vers le CLIENT
|
/* [7] Redirection vers le CLIENT
|
||||||
|
|
Loading…
Reference in New Issue