Reste à faire: [1- Gestion du roulement de BUFFER], [2- Gestion de l'erreur de connexion à un serveur FTP incorrect], [3- Gestion du timeout pour ne pas bloquer le BUS de commandes à cause du BUS de données], [4- Gestion propre des THREADS (lequel est actif, etc)]
This commit is contained in:
parent
8188a7d38a
commit
0c822226fc
13
dep/server.c
13
dep/server.c
|
@ -329,16 +329,16 @@ void MANAGE_RESPONSE(char* pAnswer, int* USER_SOCKET, int* FTP_SOCKET, int* DUSE
|
|||
|
||||
|
||||
/* 2. On lit la SOCKET FTP (BUS DE DONNEES) */
|
||||
int nbRead = WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||
tmp[0] = WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||
|
||||
if( DEBUGMOD&DAT && nbRead == -1 ) printf("ERROR\n");
|
||||
if( DEBUGMOD&DAT && tmp[0] == -1 ) printf("ERROR\n");
|
||||
else if( DEBUGMOD&DAT ) xPrint("[BUS_IN]: %s\n", BUFFER);
|
||||
|
||||
|
||||
/* 3. On redirige sur la SOCKET utilisateur (BUS DE DONNEES) */
|
||||
int nbSend = swrite(DUSER_SOCKET, BUFFER);
|
||||
tmp[1] = swrite(DUSER_SOCKET, BUFFER);
|
||||
|
||||
if( DEBUGMOD&DAT && nbSend == -1 ) printf("ERROR\n");
|
||||
if( DEBUGMOD&DAT && tmp[1] == -1 ) printf("ERROR\n");
|
||||
else if( DEBUGMOD&DAT ) xPrint("[BUS_OUT]: %s\n", BUFFER);
|
||||
|
||||
if( DEBUGMOD&DAT ) xPrint("BUS_FTP->BUS_CLIENT: %s\n", BUFFER);
|
||||
|
@ -357,8 +357,9 @@ void MANAGE_RESPONSE(char* pAnswer, int* USER_SOCKET, int* FTP_SOCKET, int* DUSE
|
|||
// printf("")
|
||||
|
||||
/* 5. On vide le BUS DE COMMANDE du serveur FTP */
|
||||
sread(FTP_SOCKET, BUFFER);
|
||||
|
||||
printf("XX: [%d]\n", tmp[2]);
|
||||
tmp[2] = sread(FTP_SOCKET, BUFFER);
|
||||
printf("YY: [%d]\n", tmp[2]);
|
||||
|
||||
/* 6. On transmet le message de fin de la transaction (226) */
|
||||
strcpy(response, STOP_DAT_MSG);
|
||||
|
|
|
@ -92,20 +92,6 @@ void formatBuffer(char* pBuffer){
|
|||
}
|
||||
|
||||
|
||||
|
||||
void read_stdin(char* pBuffer, unsigned long pLength){
|
||||
fgets(pBuffer, pLength, stdin); // on lit l'entrée standard
|
||||
|
||||
// on supprimes les retours à la ligne de la fin
|
||||
int i = strlen(pBuffer);
|
||||
|
||||
while( pBuffer[strlen(pBuffer)-1] == '\r' || pBuffer[strlen(pBuffer)-1] == '\n' )
|
||||
pBuffer[strlen(pBuffer)-1] = '\0';
|
||||
|
||||
strcat(pBuffer, "\r\n\0");
|
||||
}
|
||||
|
||||
|
||||
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; // si on a rien à écrire, on n'écrit rien :p
|
||||
|
|
|
@ -41,9 +41,6 @@ int indexOf(char* haystack, char needle);
|
|||
void formatBuffer(char *pBuffer);
|
||||
|
||||
|
||||
void read_stdin(char* pBuffer, unsigned long pLength);
|
||||
|
||||
|
||||
|
||||
/* read/write socket */
|
||||
int swrite(int* pSocket, char* pBuffer);
|
||||
|
|
38
proxy_ftp.c
38
proxy_ftp.c
|
@ -2,28 +2,6 @@
|
|||
|
||||
|
||||
|
||||
/*****************/
|
||||
/* CORPS DU PROG */
|
||||
/*****************/
|
||||
int main(int argc, char* argv[]){
|
||||
if( argc > 1 )
|
||||
testServer(argv[1]);
|
||||
else
|
||||
testServer("");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -121,10 +99,10 @@ void* manageConnection(void* THREADABLE_SOCKET){
|
|||
int DUSER_SOCKET = -1; // contiendra le BUS DE DONNES utilisateur
|
||||
int DFTP_SOCKET = -1; // contiendra le BUS DE DONNEES FTP
|
||||
|
||||
char BUFFER[maxBuffLen]; // contiendra le BUFFER
|
||||
char* BUFFER; // contiendra le BUFFER
|
||||
char* ftp_response; // contiendra le BUFFER de réponse du serveur FTP (commandes)
|
||||
int nbReceived, nbSend; // contiendra les nb reçu && envoyé
|
||||
|
||||
BUFFER = malloc( maxBuffLen );
|
||||
/* [2] Envoi de la séquence de bienvenue
|
||||
============================================================================*/
|
||||
swrite(&USER_SOCKET, WLCM_MSG);
|
||||
|
@ -149,25 +127,25 @@ void* manageConnection(void* THREADABLE_SOCKET){
|
|||
/* [5] Redirection vers le serveur FTP
|
||||
============================================================================*/
|
||||
if( DEBUGMOD&CMD ) xPrint("P->F: %s\n\n", BUFFER);
|
||||
CLIENT_SEND(&FTP_SOCKET, BUFFER, &ftp_response);
|
||||
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", ftp_response);
|
||||
CLIENT_SEND(&FTP_SOCKET, BUFFER, &BUFFER);
|
||||
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", BUFFER);
|
||||
|
||||
/* [6] Traitement de la réponse (FTP)
|
||||
============================================================================*/
|
||||
MANAGE_RESPONSE(ftp_response, &USER_SOCKET, &FTP_SOCKET, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||
MANAGE_RESPONSE(BUFFER, &USER_SOCKET, &FTP_SOCKET, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||
|
||||
|
||||
|
||||
/* [7] Redirection vers le CLIENT
|
||||
============================================================================*/
|
||||
if( swrite(&USER_SOCKET, ftp_response) == -1 ) break;
|
||||
if( DEBUGMOD&CMD ) xPrint("P->C: %s\n", ftp_response);
|
||||
if( swrite(&USER_SOCKET, BUFFER) == -1 ) break;
|
||||
if( DEBUGMOD&CMD ) xPrint("P->C: %s\n", BUFFER);
|
||||
|
||||
|
||||
/* [8] On vide les buffers
|
||||
============================================================================*/
|
||||
memset(BUFFER, '\0', maxBuffLen); // on vide le buffer
|
||||
memset(ftp_response, '\0', maxBuffLen);
|
||||
memset(BUFFER, '\0', maxBuffLen);
|
||||
}
|
||||
|
||||
/* [9] Fermeture des connections (SOCKETS)
|
||||
|
|
|
@ -108,7 +108,6 @@
|
|||
|
||||
|
||||
/* headers */
|
||||
void testServer();
|
||||
void* manageConnection(void* THREADABLE_SOCKET);
|
||||
|
||||
// VARIABLES
|
||||
|
|
Loading…
Reference in New Issue