Comment + Refactor min
This commit is contained in:
parent
5f5c8a7eaf
commit
85901e9119
28
dep/server.c
28
dep/server.c
|
@ -185,17 +185,17 @@ void MANAGE_REQUEST(int* SOCKET, char* pRequest){
|
|||
|
||||
|
||||
|
||||
void MANAGE_RESPONSE(int* SOCKET, char** pAnswer){
|
||||
void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
||||
if( DEBUGMOD ) printf("====== MANAGE_RESPONSE(%d, %s) ======\n\n", *SOCKET, *pAnswer);
|
||||
|
||||
char answer[maxBuffLen]; // contiendra la réponse
|
||||
char response[maxBuffLen]; // contiendra la réponse
|
||||
char ftpCode[4]; // contiendra le code FTP (1ère partie)
|
||||
char ftpText[maxBuffLen]; // contiendra le texte associé à la commande (2ème partie)
|
||||
|
||||
// on vide les buffers
|
||||
memset(&ftpCode, '\0', sizeof(ftpCode));
|
||||
memset(&ftpText, '\0', sizeof(ftpText));
|
||||
memset(&answer, '\0', sizeof(answer));
|
||||
memset(&response, '\0', sizeof(response));
|
||||
|
||||
|
||||
/* [1] On découpe la requête en 2 parties
|
||||
|
@ -205,56 +205,50 @@ void MANAGE_RESPONSE(int* SOCKET, char** pAnswer){
|
|||
/* [2] Selection en fonction de @ftpCode
|
||||
================================================*/
|
||||
|
||||
// /* (1) Demande d'username
|
||||
// --------------------------------------------*/
|
||||
// if( strcmp(ftpCode, "220") == 0 )
|
||||
// strcpy(answer, USER_MSG);
|
||||
|
||||
|
||||
/* (2) Demande d'username
|
||||
--------------------------------------------*/
|
||||
if( strcmp(ftpCode, "220") == 0 )
|
||||
strcpy(answer, WLCM_MSG);
|
||||
strcpy(response, WLCM_MSG);
|
||||
|
||||
|
||||
/* (3) username OK -> demande MDP
|
||||
--------------------------------------------*/
|
||||
else if( strcmp(ftpCode, "331") == 0 )
|
||||
strcpy(answer, USER_MSG);
|
||||
strcpy(response, USER_MSG);
|
||||
|
||||
/* (3) Bon mdp -> connection
|
||||
--------------------------------------------*/
|
||||
else if( strcmp(ftpCode, "230") == 0 )
|
||||
strcpy(answer, PASS_BON_MSG);
|
||||
strcpy(response, PASS_BON_MSG);
|
||||
|
||||
|
||||
|
||||
/* (4) Mauvais mdp -> connection
|
||||
--------------------------------------------*/
|
||||
else if( strcmp(ftpCode, "530") == 0 )
|
||||
strcpy(answer, PASS_BAD_MSG);
|
||||
strcpy(response, PASS_BAD_MSG);
|
||||
|
||||
/* (5) Info SYST
|
||||
--------------------------------------------*/
|
||||
// else if( strcmp(ftpCode, "215") == 0 )
|
||||
// strcpy(answer, "bla\n");
|
||||
// strcpy(response, "bla\n");
|
||||
|
||||
/* (6) LOGOUT => EXIT
|
||||
--------------------------------------------*/
|
||||
else if( strcmp(ftpCode, "221") == 0 )
|
||||
strcpy(answer, EXIT_MSG);
|
||||
strcpy(response, EXIT_MSG);
|
||||
|
||||
|
||||
|
||||
/* (n) Commande inconnue
|
||||
--------------------------------------------*/
|
||||
else
|
||||
strcpy(answer, *pAnswer);
|
||||
strcpy(response, *pAnswer);
|
||||
|
||||
|
||||
/* [3] Retour de la réponse
|
||||
================================================*/
|
||||
strcpy(*pAnswer, answer);
|
||||
strcpy(*pAnswer, response);
|
||||
}
|
||||
|
||||
|
||||
|
|
33
dep/server.h
33
dep/server.h
|
@ -20,10 +20,37 @@ void MANAGE_REQUEST(int* SOCKET, char* pRequest);
|
|||
|
||||
|
||||
|
||||
|
||||
void MANAGE_RESPONSE(int* SOCKET, char** pAnswer);
|
||||
|
||||
/* Gestion de la réponse du serveur FTP et modification de la réponse
|
||||
*
|
||||
* @pAnswer<char**> Pointeur sur le buffer de réponse du serveur FTP
|
||||
* @DUSER_SOCKET<int*> Pointeur sur la SOCKET du BUS DE DONNEES utilisateur
|
||||
* @DFTP_SOCKET<int*> Pointeur sur la SOCKET du BUS DE DONNEES FTP
|
||||
*
|
||||
* @history
|
||||
* [1] si commande sans transfert nécessaire, on modifie la réponse
|
||||
* [2] si on a besoin d'un transfert de données
|
||||
* (1) On initialise les SOCKETS avec la valeur de PORT a,b,c,d,p1,p2
|
||||
* (2) a.b.c.d (adresse ip) + p1*256+p2 (port)
|
||||
* (3) UTILISATEUR (ACIF) PROXY (PASSIF) SRV_FTP
|
||||
*
|
||||
*/
|
||||
void MANAGE_RESPONSE(char** pAnswer, int* DUSER_SOCKET, int* DFTP_SOCKET);
|
||||
|
||||
|
||||
|
||||
/* Attends une réponse du client
|
||||
*
|
||||
* @pSocket<int*> Pointeur sur la SOCKET en question
|
||||
* @pBuffer<char*> Buffer qui contiendra la réponse
|
||||
*
|
||||
* @history
|
||||
* [1] On read() tant qu'on a pas les symboles de fin (\r\n)
|
||||
* [2] On écrit sur le buffer
|
||||
*
|
||||
* [3] Si une erreur occure, on retourne -1
|
||||
*
|
||||
*
|
||||
* @return nbRead<int> On retourne le nombre de char lus, sinon -1 si erreur
|
||||
*
|
||||
*/
|
||||
int WAIT_CLIENT(int* pSocket, char* pBuffer);
|
24
proxy_ftp.c
24
proxy_ftp.c
|
@ -56,7 +56,7 @@ static void* testServer(){
|
|||
int LISTENSOCK; // contiendra la socket d'écoute
|
||||
char* ftp_response;
|
||||
|
||||
/* [0] On lance @DROP_SERVER
|
||||
/* [0] On démarre le SERVEUR + le CLIENT
|
||||
==========================================================*/
|
||||
serverPort = malloc(4*sizeof(char));
|
||||
strcpy(serverPort, "4444");
|
||||
|
@ -92,31 +92,37 @@ static void* testServer(){
|
|||
if( DEBUGMOD ) printf("C->P: %s\n", BUFFER);
|
||||
|
||||
|
||||
/* [4] Redirection vers le serveur FTP
|
||||
/* [4] Traitement de la requête
|
||||
============================================================================*/
|
||||
MANAGE_REQUEST(&BUFFER, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||
|
||||
|
||||
/* [5] Redirection vers le serveur FTP
|
||||
============================================================================*/
|
||||
CLIENT_SEND(&FTP_SOCKET, BUFFER, &ftp_response);
|
||||
// printf("U22: %d\n", USER_SOCKET);
|
||||
xPrint("P->F: %s\n\n", BUFFER);
|
||||
xPrint("F->P: %s\n", ftp_response);
|
||||
|
||||
|
||||
/* [5] On analyse et renvoie la réponse à l'utilisateur
|
||||
/* [6] Traitement de la réponse (FTP)
|
||||
============================================================================*/
|
||||
// on analyse
|
||||
MANAGE_RESPONSE(&USER_SOCKET, &ftp_response);
|
||||
MANAGE_RESPONSE(&USER_SOCKET, &ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||
|
||||
// on réponds au client
|
||||
|
||||
/* [7] Redirection vers le CLIENT
|
||||
============================================================================*/
|
||||
if( swrite(&USER_SOCKET, ftp_response) == -1 ) break;
|
||||
printf("P->C: %s\n", ftp_response);
|
||||
|
||||
|
||||
|
||||
/* [6] On vide les buffers
|
||||
/* [8] On vide les buffers
|
||||
============================================================================*/
|
||||
memset(BUFFER, '\0', sizeof(BUFFER)); // on vide le buffer
|
||||
ftp_response = NULL;
|
||||
}
|
||||
|
||||
/* [9] Fermeture des connections (SOCKETS)
|
||||
============================================================================*/
|
||||
close(USER_SOCKET);
|
||||
close(FTP_SOCKET);
|
||||
close(LISTENSOCK);
|
||||
|
|
Loading…
Reference in New Issue