Ajout de DEBUGMOD en mode avancé (selectif)
This commit is contained in:
parent
0c09165d57
commit
67fe286a03
87
dep/client.c
87
dep/client.c
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
void CLIENT_REQUEST(char* serverHost, char* serverPort, char* pRequest, char** pAnswer){
|
||||
if( DEBUGMOD ) printf("====== CLIENT_REQUEST(%s, %s, %s, %s) ======\n\n", serverHost, serverPort, pRequest, *pAnswer);
|
||||
if( DEBUGMOD&HDR ) printf("====== CLIENT_REQUEST(%s, %s, %s, %s) ======\n\n", serverHost, serverPort, pRequest, *pAnswer);
|
||||
|
||||
struct addrinfo hints; // contiendra le filtre/format
|
||||
struct addrinfo* addrinfo; // contiendra les infos
|
||||
|
@ -23,32 +23,32 @@ void CLIENT_REQUEST(char* serverHost, char* serverPort, char* pRequest, char** p
|
|||
hints.ai_flags = 0; // non spécifié
|
||||
hints.ai_protocol = 0; // non spécifié
|
||||
|
||||
if( DEBUGMOD ) printf("============HINTS===========\n");
|
||||
if( DEBUGMOD ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int
|
||||
if( DEBUGMOD ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int
|
||||
if( DEBUGMOD ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int
|
||||
if( DEBUGMOD ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int
|
||||
if( DEBUGMOD ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int
|
||||
if( DEBUGMOD ) printf("\n");
|
||||
if( DEBUGMOD&SCK ) printf("============HINTS===========\n");
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int
|
||||
if( DEBUGMOD&SCK ) printf("\n");
|
||||
|
||||
|
||||
/* [2] On récupère les infos
|
||||
=======================================================*/
|
||||
getaddrinfo(serverHost, serverPort, &hints, &addrinfo);
|
||||
|
||||
if( DEBUGMOD ) printf("=============RES============\n");
|
||||
if( DEBUGMOD ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int
|
||||
if( DEBUGMOD ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int
|
||||
if( DEBUGMOD ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int
|
||||
if( DEBUGMOD ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int
|
||||
if( DEBUGMOD ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int
|
||||
if( DEBUGMOD ) printf("\n");
|
||||
if( DEBUGMOD&SCK ) printf("=============RES============\n");
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int
|
||||
if( DEBUGMOD&SCK ) printf("\n");
|
||||
|
||||
/* [3] Création de la socket
|
||||
=======================================================*/
|
||||
SOCKET = socket(addrinfo->ai_family, addrinfo->ai_socktype, 0);
|
||||
|
||||
if( DEBUGMOD ) printf("SOCKET = %d\n", SOCKET);
|
||||
if( DEBUGMOD&SCK ) printf("SOCKET = %d\n", SOCKET);
|
||||
|
||||
// si erreur
|
||||
if( SOCKET == -1 ) return;
|
||||
|
@ -61,7 +61,7 @@ void CLIENT_REQUEST(char* serverHost, char* serverPort, char* pRequest, char** p
|
|||
addrinfo->ai_addrlen
|
||||
);
|
||||
|
||||
if( DEBUGMOD ) printf("CONNECT = %d\n", CONNECT);
|
||||
if( DEBUGMOD&SCK ) printf("CONNECT = %d\n", CONNECT);
|
||||
|
||||
// si erreur
|
||||
if( CONNECT == -1 ) return;
|
||||
|
@ -74,8 +74,8 @@ void CLIENT_REQUEST(char* serverHost, char* serverPort, char* pRequest, char** p
|
|||
=======================================================*/
|
||||
int nbSend = swrite(&SOCKET, pRequest);
|
||||
|
||||
if( DEBUGMOD ) printf("nbSend: %d\n", nbSend);
|
||||
if( DEBUGMOD ) printf("Message: %s\n", pRequest);
|
||||
if( DEBUGMOD&BUF ) printf("nbSend: %d\n", nbSend);
|
||||
if( DEBUGMOD&BUF ) printf("Message: %s\n", pRequest);
|
||||
|
||||
// si pas tout envoyé
|
||||
if( strlen(pRequest) != nbSend ) return;
|
||||
|
@ -88,8 +88,8 @@ void CLIENT_REQUEST(char* serverHost, char* serverPort, char* pRequest, char** p
|
|||
*pAnswer = malloc( maxBuffLen );
|
||||
strcpy(*pAnswer, BUFFER);
|
||||
|
||||
if( DEBUGMOD ) printf("nbReceived: %d\n", nbRecup);
|
||||
if( DEBUGMOD ) printf("Message: %s\n", *pAnswer);
|
||||
if( DEBUGMOD&BUF ) printf("nbReceived: %d\n", nbRecup);
|
||||
if( DEBUGMOD&BUF ) printf("Message: %s\n", *pAnswer);
|
||||
|
||||
|
||||
/* [7] On ferme la connection
|
||||
|
@ -103,7 +103,7 @@ void CLIENT_REQUEST(char* serverHost, char* serverPort, char* pRequest, char** p
|
|||
|
||||
|
||||
void CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){
|
||||
if( DEBUGMOD ) printf("====== INIT_CLIENT(%s, %s, %d) ======\n\n", serverHost, serverPort, *pSocket);
|
||||
if( DEBUGMOD&HDR ) printf("====== INIT_CLIENT(%s, %s, %d) ======\n\n", serverHost, serverPort, *pSocket);
|
||||
|
||||
struct addrinfo hints; // contiendra le filtre/format
|
||||
struct addrinfo* addrinfo; // contiendra les infos
|
||||
|
@ -119,32 +119,32 @@ void CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){
|
|||
hints.ai_flags = 0; // non spécifié
|
||||
hints.ai_protocol = 0; // non spécifié
|
||||
|
||||
if( DEBUGMOD ) printf("============HINTS===========\n");
|
||||
if( DEBUGMOD ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int
|
||||
if( DEBUGMOD ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int
|
||||
if( DEBUGMOD ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int
|
||||
if( DEBUGMOD ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int
|
||||
if( DEBUGMOD ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int
|
||||
if( DEBUGMOD ) printf("\n");
|
||||
if( DEBUGMOD&SCK ) printf("============HINTS===========\n");
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int
|
||||
if( DEBUGMOD&SCK ) printf("\n");
|
||||
|
||||
|
||||
/* [2] On récupère les infos
|
||||
=======================================================*/
|
||||
getaddrinfo(serverHost, serverPort, &hints, &addrinfo);
|
||||
|
||||
if( DEBUGMOD ) printf("=============RES============\n");
|
||||
if( DEBUGMOD ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int
|
||||
if( DEBUGMOD ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int
|
||||
if( DEBUGMOD ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int
|
||||
if( DEBUGMOD ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int
|
||||
if( DEBUGMOD ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int
|
||||
if( DEBUGMOD ) printf("\n");
|
||||
if( DEBUGMOD&SCK ) printf("=============RES============\n");
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int
|
||||
if( DEBUGMOD&SCK ) printf("\n");
|
||||
|
||||
/* [3] Création de la socket
|
||||
=======================================================*/
|
||||
*pSocket = socket(addrinfo->ai_family, addrinfo->ai_socktype, 0);
|
||||
|
||||
if( DEBUGMOD ) printf("SOCKET = %d\n", *pSocket);
|
||||
if( DEBUGMOD&SCK ) printf("SOCKET = %d\n", *pSocket);
|
||||
|
||||
// si erreur
|
||||
if( *pSocket == -1 ) return;
|
||||
|
@ -157,7 +157,7 @@ void CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){
|
|||
addrinfo->ai_addrlen
|
||||
);
|
||||
|
||||
if( DEBUGMOD ) printf("CONNECT = %d\n", CONNECT);
|
||||
if( DEBUGMOD&SCK ) printf("CONNECT = %d\n", CONNECT);
|
||||
|
||||
// si erreur
|
||||
if( CONNECT == -1 ) return;
|
||||
|
@ -169,14 +169,15 @@ void CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){
|
|||
|
||||
|
||||
void CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer){
|
||||
char BUFFER[maxBuffLen] = {'\0'};
|
||||
if( DEBUGMOD&HDR ) printf("====== CLIENT_SEND(%d, %s, %s) ======\n\n", *pSocket, pRequest, *pRequest);
|
||||
char BUFFER[maxBuffLen] = {0};
|
||||
|
||||
/* [5] On écrit sur la socket
|
||||
=======================================================*/
|
||||
int nbSend = swrite(pSocket, pRequest);
|
||||
|
||||
if( DEBUGMOD ) printf("nbSend: %d\n", nbSend);
|
||||
if( DEBUGMOD ) printf("Message: %s\n", pRequest);
|
||||
if( DEBUGMOD&BUF ) printf("nbSend: %d\n", nbSend);
|
||||
if( DEBUGMOD&BUF ) printf("Message: %s\n", pRequest);
|
||||
|
||||
// si pas tout envoyé
|
||||
if( strlen(pRequest) != nbSend ) return;
|
||||
|
@ -188,6 +189,6 @@ void CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer){
|
|||
*pAnswer = malloc( maxBuffLen );
|
||||
strcpy(*pAnswer, BUFFER);
|
||||
|
||||
if( DEBUGMOD ) printf("nbReceived: %d\n", nbRecup);
|
||||
if( DEBUGMOD ) printf("Message: %s\n", *pAnswer);
|
||||
if( DEBUGMOD&BUF ) printf("nbReceived: %d\n", nbRecup);
|
||||
if( DEBUGMOD&BUF ) printf("Message: %s\n", *pAnswer);
|
||||
}
|
94
dep/server.c
94
dep/server.c
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
||||
if( DEBUGMOD ) printf("====== DROP_SERVER(%s, %s, %d) ======\n\n", serverHost, *givenPort, *listenSocket);
|
||||
if( DEBUGMOD&HDR ) printf("====== DROP_SERVER(%s, %s, %d) ======\n\n", serverHost, *givenPort, *listenSocket);
|
||||
|
||||
// FONCTIONNEMENT
|
||||
struct addrinfo hints; // contiendra le filtre/format
|
||||
|
@ -28,13 +28,13 @@ void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
|||
hints.ai_flags = AI_PASSIVE; // mode SERVER
|
||||
hints.ai_protocol = 0; // non spécifié
|
||||
|
||||
if( DEBUGMOD ) printf("============HINTS===========\n");
|
||||
if( DEBUGMOD ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int
|
||||
if( DEBUGMOD ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int
|
||||
if( DEBUGMOD ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int
|
||||
if( DEBUGMOD ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int
|
||||
if( DEBUGMOD ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int
|
||||
if( DEBUGMOD ) printf("\n");
|
||||
if( DEBUGMOD&SCK ) printf("============HINTS===========\n");
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int
|
||||
if( DEBUGMOD&SCK ) printf("\n");
|
||||
|
||||
|
||||
/* [2] On récupère les infos
|
||||
|
@ -45,20 +45,20 @@ void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
|||
getaddrinfo(serverHost, *givenPort, &hints, &addrinfo);
|
||||
// Remarque: port=0 donc va être défini dynamiquement
|
||||
|
||||
if( DEBUGMOD ) printf("=============RES============\n");
|
||||
if( DEBUGMOD ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int
|
||||
if( DEBUGMOD ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int
|
||||
if( DEBUGMOD ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int
|
||||
if( DEBUGMOD ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int
|
||||
if( DEBUGMOD ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int
|
||||
if( DEBUGMOD ) printf("\n");
|
||||
if( DEBUGMOD&SCK ) printf("=============RES============\n");
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int
|
||||
if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int
|
||||
if( DEBUGMOD&SCK ) printf("\n");
|
||||
|
||||
/* [3] Création de la socket
|
||||
=======================================================*/
|
||||
|
||||
SOCKET = socket(addrinfo->ai_family, addrinfo->ai_socktype, 0);
|
||||
|
||||
if( DEBUGMOD ) printf("SOCKET = %d\n", SOCKET);
|
||||
if( DEBUGMOD&SCK ) printf("SOCKET = %d\n", SOCKET);
|
||||
|
||||
// si erreur
|
||||
if( SOCKET == -1 ) return;
|
||||
|
@ -71,7 +71,7 @@ void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
|||
addrinfo->ai_addrlen
|
||||
);
|
||||
|
||||
if( DEBUGMOD ) printf("BIND = %d\n", BIND);
|
||||
if( DEBUGMOD&SCK ) printf("BIND = %d\n", BIND);
|
||||
|
||||
// si erreur
|
||||
if( BIND == -1 ) return;
|
||||
|
@ -92,8 +92,8 @@ void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
|||
|
||||
if( getInfo == -1 ) return;
|
||||
|
||||
if( DEBUGMOD ) printf("Server host: %s\n", infoHost);
|
||||
if( DEBUGMOD ) printf("Server port: %s\n", infoPort);
|
||||
if( DEBUGMOD&SCKL ) printf("Server host: %s\n", infoHost);
|
||||
if( DEBUGMOD&SCKL ) printf("Server port: %s\n", infoPort);
|
||||
|
||||
|
||||
// on a plus besoin des infos de l'adresse
|
||||
|
@ -104,7 +104,7 @@ void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
|||
=======================================================*/
|
||||
LISTEN = listen(SOCKET, maxListLen);
|
||||
|
||||
if( DEBUGMOD ) printf("LISTEN = %d\n", LISTEN);
|
||||
if( DEBUGMOD&SCK ) printf("LISTEN = %d\n", LISTEN);
|
||||
|
||||
// si erreur
|
||||
if( LISTEN == -1 ) return;
|
||||
|
@ -128,7 +128,7 @@ void DROP_SERVER(char* serverHost, char** givenPort, int* listenSocket){
|
|||
// DTA: CLIENT (CLT) PROXY (CLT) FTP
|
||||
//
|
||||
void MANAGE_REQUEST(char* pRequest, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
||||
if( DEBUGMOD ) printf("====== MANAGE_REQUEST(%s, %d, %d) ======\n\n", pRequest, *DUSER_SOCKET, *DFTP_SOCKET);
|
||||
if( DEBUGMOD&HDR ) printf("====== MANAGE_REQUEST(%s, %d, %d) ======\n\n", pRequest, *DUSER_SOCKET, *DFTP_SOCKET);
|
||||
|
||||
char answer[maxBuffLen]; // contiendra la réponse
|
||||
int nbSend; // contiendra le nombre de données envoyées
|
||||
|
@ -166,9 +166,9 @@ void MANAGE_REQUEST(char* pRequest, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
|||
|
||||
|
||||
// on se connecte au client
|
||||
printf("CONNECTING TO CLIENT %s:%s\n", serverHost, serverPort);
|
||||
if( DEBUGMOD&SCK ) printf("CONNECTING TO CLIENT %s:%s\n", serverHost, serverPort);
|
||||
CONNECT_CLIENT(serverHost, serverPort, DUSER_SOCKET);
|
||||
printf("CONNECTED TO CLIENT %s:%s\n", serverHost, serverPort);
|
||||
if( DEBUGMOD&SCK ) printf("CONNECTED TO CLIENT %s:%s\n", serverHost, serverPort);
|
||||
|
||||
// on envoie PASV car on veut être en mode passif entre le proxy et le serveur FTP
|
||||
strcpy(pRequest, "PASV\n");
|
||||
|
@ -183,7 +183,7 @@ void MANAGE_REQUEST(char* pRequest, 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&HDR ) printf("====== MANAGE_RESPONSE(%d, %s, %d, %d) ======\n\n", *USER_SOCKET, pAnswer, *DUSER_SOCKET, *DFTP_SOCKET);
|
||||
|
||||
char response[maxBuffLen]; // contiendra la réponse
|
||||
char ftpCodeStr[4]; // contiendra le code FTP (1ère partie)
|
||||
|
@ -256,9 +256,9 @@ void MANAGE_RESPONSE(int* USER_SOCKET, int* FTP_SOCKET, char* pAnswer, int* DUSE
|
|||
sprintf(serverPort, "%d", p1*256+p2);
|
||||
|
||||
// on se connecte au serveur FTP
|
||||
printf("CONNECTING TO FTP %s:%s\n", serverHost, serverPort);
|
||||
if( DEBUGMOD&SCK ) printf("CONNECTING TO FTP %s:%s\n", serverHost, serverPort);
|
||||
CONNECT_CLIENT(serverHost, serverPort, DFTP_SOCKET);
|
||||
printf("CONNECTED TO FTP %s:%s\n", serverHost, serverPort);
|
||||
if( DEBUGMOD&SCK ) printf("CONNECTED TO FTP %s:%s\n", serverHost, serverPort);
|
||||
|
||||
strcpy(response, "200 PORT command successful\n");
|
||||
}
|
||||
|
@ -270,33 +270,41 @@ void MANAGE_RESPONSE(int* USER_SOCKET, int* FTP_SOCKET, char* pAnswer, int* DUSE
|
|||
|
||||
char BUFFER[maxBuffLen];
|
||||
|
||||
// on lit la SOCKET FTP
|
||||
/* 1. Envoi au client de l'écoute de la réponse (associée) du BUS DE DONNEES */
|
||||
sread(FTP_SOCKET, BUFFER);
|
||||
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", BUFFER);
|
||||
swrite(USER_SOCKET, "150 Connection établie!\n");
|
||||
if( DEBUGMOD&CMD ) xPrint("P->C: %s\n", "150 Connection établie!\n");
|
||||
|
||||
/* 2. On lit la SOCKET FTP (BUS DE DONNEES)*/
|
||||
int nbRead = WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||
|
||||
if( DEBUGMOD && nbRead == -1 ) printf("ERROR\n");
|
||||
else if( DEBUGMOD ) xPrint("[BUS_IN]: %s\n", BUFFER);
|
||||
if( DEBUGMOD&DAT && nbRead == -1 ) printf("ERROR\n");
|
||||
else if( DEBUGMOD&DAT ) xPrint("[BUS_IN]: %s\n", BUFFER);
|
||||
|
||||
|
||||
// on redirige sur la SOCKET utilisateur
|
||||
int nbWritten = swrite(DUSER_SOCKET, BUFFER);
|
||||
/* 3. On redirige sur la SOCKET utilisateur (BUS DE DONNEES) */
|
||||
int nbSend = swrite(DUSER_SOCKET, BUFFER);
|
||||
|
||||
if( DEBUGMOD && nbWritten == -1 ) printf("ERROR\n");
|
||||
else if( DEBUGMOD ) xPrint("[BUS_OUT]: %s\n", BUFFER);
|
||||
if( DEBUGMOD&DAT && nbSend == -1 ) printf("ERROR\n");
|
||||
else if( DEBUGMOD&DAT ) xPrint("[BUS_OUT]: %s\n", BUFFER);
|
||||
|
||||
xPrint("BUS_FTP->BUS_CLIENT: %s\n", BUFFER);
|
||||
if( DEBUGMOD&DAT ) xPrint("BUS_FTP->BUS_CLIENT: %s\n", BUFFER);
|
||||
|
||||
/* 4. On ferme les SOCKETS du BUS DE DONNEES */
|
||||
close(*DFTP_SOCKET);
|
||||
if( DEBUGMOD ) printf("BUS_FTP fermé\n");
|
||||
if( DEBUGMOD&CMD ) printf("BUS_FTP fermé\n");
|
||||
close(*DUSER_SOCKET);
|
||||
if( DEBUGMOD ) printf("BUS_USER fermé\n");
|
||||
if( DEBUGMOD&CMD ) printf("BUS_USER fermé\n");
|
||||
|
||||
// on vide le SOCKET FTP du BUS DE DONNEES
|
||||
WAIT_SOCKET_UPDATE(FTP_SOCKET, BUFFER);
|
||||
WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||
|
||||
swrite(USER_SOCKET, "150 Attente de la réception!\n");
|
||||
|
||||
// on vide les SOCKET FTP des 2 BUS
|
||||
// WAIT_SOCKET_UPDATE(FTP_SOCKET, BUFFER); // command
|
||||
// WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER); // données
|
||||
// printf("")
|
||||
|
||||
|
||||
// fin de la transaction
|
||||
strcpy(response, "226 Données reçues!\n");
|
||||
}
|
||||
|
||||
|
@ -348,6 +356,6 @@ int WAIT_SOCKET_UPDATE(int* pSocket, char* pBuffer){
|
|||
|
||||
|
||||
|
||||
void prefixFtpResponse(char* pBuffer, char* ftpCode){
|
||||
// void prefixFtpResponse(char* pBuffer, char* ftpCode){
|
||||
|
||||
}
|
||||
// }
|
|
@ -16,7 +16,7 @@ void splitFtpRequest(char* pRequest, char* pCommand, char* pContent){
|
|||
===========================================*/
|
||||
int i;
|
||||
|
||||
for( i = 0 ; i < strlen(pRequest) || pRequest[i] != '\0' ; i++ ){
|
||||
for( i = 0 ; i < strlen(pRequest) && pRequest[i] != '\0' ; i++ ){
|
||||
|
||||
if( i < firstSpaceIndex ) // première partie (pCommand)
|
||||
strcpy( pCommand, strcat(pCommand, (char[2]) { (char) pRequest[i], '\0' }) );
|
||||
|
@ -39,7 +39,7 @@ void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText){
|
|||
===========================================*/
|
||||
int i;
|
||||
|
||||
for( i = 0 ; i < strlen(pAnswer) || pAnswer[i] != '\0' ; i++ ){
|
||||
for( i = 0 ; i < strlen(pAnswer) && pAnswer[i] != '\0' ; i++ ){
|
||||
|
||||
if( i < codeLength ) // première partie (ftpCode)
|
||||
strcpy( ftpCode, strcat(ftpCode, (char[2]) { (char) pAnswer[i], '\0' }) );
|
||||
|
@ -57,7 +57,7 @@ void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText){
|
|||
int indexOf(char* haystack, char needle){
|
||||
int i;
|
||||
|
||||
for( i = 0 ; i < strlen(haystack) || haystack[i] != '\0' ; i++ )
|
||||
for( i = 0 ; i < strlen(haystack) && haystack[i] != '\0' ; i++ )
|
||||
if( haystack[i] == needle ) // si on trouve le caractère
|
||||
return i;
|
||||
|
||||
|
@ -66,8 +66,8 @@ int indexOf(char* haystack, char needle){
|
|||
}
|
||||
|
||||
void formatBuffer(char* pBuffer){
|
||||
if( DEBUGMOD ) printf( "BUFLEN (bef): %lu\n", strlen(pBuffer) );
|
||||
if( DEBUGMOD ) printf( "BUFFER: (%s)\n", pBuffer );
|
||||
if( DEBUGMOD&BUF ) printf( "BUFLEN (bef): %lu\n", strlen(pBuffer) );
|
||||
if( DEBUGMOD&BUF ) printf( "BUFFER: (%s)\n", pBuffer );
|
||||
|
||||
/* [1] On retire les "\n" et "\r" de la fin de la chaine
|
||||
============================================================*/
|
||||
|
@ -80,7 +80,7 @@ void formatBuffer(char* pBuffer){
|
|||
============================================================*/
|
||||
strcpy(pBuffer, strcat(pBuffer, "\r\n"));
|
||||
|
||||
if( DEBUGMOD ) printf( "BUFLEN (aft): %lu\n", strlen(pBuffer) );
|
||||
if( DEBUGMOD&BUF ) printf( "BUFLEN (aft): %lu\n", strlen(pBuffer) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,18 +94,30 @@ void read_stdin(char* pBuffer, unsigned long pLength){
|
|||
while( pBuffer[strlen(pBuffer)-1] == '\r' || pBuffer[strlen(pBuffer)-1] == '\n' )
|
||||
pBuffer[strlen(pBuffer)-1] = '\0';
|
||||
|
||||
strcpy(pBuffer, strcat(pBuffer, "\r\n"));
|
||||
strcpy(pBuffer, 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
|
||||
|
||||
|
||||
// if( strlen(pBuffer) == 0 ) return 0;
|
||||
if( DEBUGMOD&BUF ) printf("SENDLEN_1: %lu\n", strlen(pBuffer));
|
||||
int nbSent = write(*pSocket, pBuffer, strlen(pBuffer));
|
||||
if( DEBUGMOD&BUF ) printf("SENDLEN_2: %d\n", nbSent);
|
||||
|
||||
|
||||
return write(*pSocket, pBuffer, strlen(pBuffer));
|
||||
// si on est déconnecté, on ferme la SOCKET
|
||||
if( nbSent <= 0 ){
|
||||
if( DEBUGMOD&BUF ) printf("NOTHING TO SEND\n");
|
||||
return -1; // on retourne une erreur
|
||||
}
|
||||
|
||||
if( DEBUGMOD&RVL ) printf("SEND_1\n");
|
||||
if( DEBUGMOD&RVL ) revealString(pBuffer);
|
||||
if( DEBUGMOD&RVL ) printf("SEND_2\n");
|
||||
|
||||
return nbSent;
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,15 +127,20 @@ int sread(int* pSocket, char* pBuffer){
|
|||
|
||||
// on vide le buffer avant de lire
|
||||
memset(pBuffer, '\0', maxBuffLen);
|
||||
if( DEBUGMOD&BUF ) printf("READLEN_1: %lu\n", strlen(pBuffer));
|
||||
int nbRead = read(*pSocket, pBuffer, maxBuffLen);
|
||||
|
||||
if( DEBUGMOD&BUF ) printf("READLEN_3: %d\n", nbRead);
|
||||
|
||||
// si on est déconnecté, on ferme la SOCKET
|
||||
if( nbRead == 0 ){
|
||||
// close(*pSocket);
|
||||
if( nbRead <= 0 ){
|
||||
if( DEBUGMOD&BUF ) printf("NOTHING TO READ\n");
|
||||
return -1; // on retourne une erreur
|
||||
}
|
||||
|
||||
if( DEBUGMOD&RVL ) printf("READ_1\n");
|
||||
if( DEBUGMOD&RVL ) revealString(pBuffer);
|
||||
if( DEBUGMOD&RVL ) printf("READ_2\n");
|
||||
|
||||
return nbRead;
|
||||
}
|
||||
|
||||
|
@ -137,11 +154,30 @@ void xPrint(char* pPattern, char* pBuffer){
|
|||
int i;
|
||||
|
||||
// on supprimes les retours à la ligne de la fin
|
||||
for( i = strlen(tmpBuffer)-1 ; i >= 0 || tmpBuffer[i] != '\0' ; i-- )
|
||||
for( i = strlen(tmpBuffer)-1 ; i >= 0 && tmpBuffer[i] != '\0' ; i-- )
|
||||
if( tmpBuffer[i] == '\n' || tmpBuffer[i] == '\r' ) // si c'est un retour chariot
|
||||
tmpBuffer[i] = '\0'; // on efface
|
||||
else
|
||||
break;
|
||||
|
||||
printf(pPattern, pBuffer);
|
||||
}
|
||||
|
||||
|
||||
void revealString(char* pString){
|
||||
/* 1. On créé une copie de @pString */
|
||||
char revealedString[maxBuffLen] = {0};
|
||||
|
||||
/* 2. On rend visible tous les caractères "invisibles" */
|
||||
int i;
|
||||
for( i = 0 ; i < strlen(pString) && pString[i] != '\0' ; i++ ){
|
||||
if( pString[i] == '\r' ){ revealedString[strlen(revealedString)] = '\\'; revealedString[strlen(revealedString)] = 'r'; }
|
||||
else if( pString[i] == '\n' ){ revealedString[strlen(revealedString)] = '\\'; revealedString[strlen(revealedString)] = 'n'; }
|
||||
else revealedString[strlen(revealedString)] = pString[i];
|
||||
|
||||
revealedString[strlen(revealedString)] = '\0';
|
||||
}
|
||||
|
||||
/* 3. On affiche la chaîne explicite */
|
||||
if( DEBUGMOD&RVL ) printf("REVEALED: %s\n", revealedString);
|
||||
}
|
|
@ -51,5 +51,21 @@ int sread(int* pSocket, char* pBuffer);
|
|||
|
||||
|
||||
|
||||
/* Affiche une string en supprimant les retours à la ligne de fin de chaînes
|
||||
*
|
||||
* @pPattern<char*> Schéma du print (1er arg)
|
||||
* @pBuffer<char*> Buffer en question
|
||||
*
|
||||
*/
|
||||
void xPrint(char* pPattern, char* pBuffer);
|
||||
|
||||
void xPrint(char* pPattern, char* pBuffer);
|
||||
|
||||
/* Révèle les caractères spéciaux d'une string
|
||||
*
|
||||
* @pString<char*> La string à révéler
|
||||
*
|
||||
*
|
||||
* @print explicitString<char*> On affiche la chaîne explicité
|
||||
*
|
||||
*/
|
||||
void revealString(char* pString);
|
14
proxy_ftp.c
14
proxy_ftp.c
|
@ -83,8 +83,8 @@ static void* testServer(char* localPort){
|
|||
MANAGE_RESPONSE(&USER_SOCKET, &FTP_SOCKET, ftp_response, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||
swrite(&USER_SOCKET, ftp_response);
|
||||
|
||||
xPrint("P->F: %s\n\n", BUFFER);
|
||||
xPrint("F->P: %s\n", ftp_response);
|
||||
if( DEBUGMOD&CMD ) xPrint("P->F: %s\n\n", BUFFER);
|
||||
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", ftp_response);
|
||||
|
||||
/* BOUCLE DE COMMANDES */
|
||||
while( USER_SOCKET != -1 && FTP_SOCKET != -1 ){
|
||||
|
@ -92,10 +92,7 @@ static void* testServer(char* localPort){
|
|||
/* [3] On récupère les données reçues (+attente)
|
||||
============================================================================*/
|
||||
if( WAIT_SOCKET_UPDATE(&USER_SOCKET, BUFFER) == -1 ) break;
|
||||
xPrint("C->P: %s\n", BUFFER);
|
||||
|
||||
if( DEBUGMOD ) printf("Recu: %d\n", nbReceived);
|
||||
if( DEBUGMOD ) printf("C->P: %s\n", BUFFER);
|
||||
if( DEBUGMOD&CMD ) xPrint("C->P: %s\n", BUFFER);
|
||||
|
||||
|
||||
/* [4] Traitement de la requête
|
||||
|
@ -107,8 +104,7 @@ static void* testServer(char* localPort){
|
|||
============================================================================*/
|
||||
xPrint("P->F: %s\n\n", BUFFER);
|
||||
CLIENT_SEND(&FTP_SOCKET, BUFFER, &ftp_response);
|
||||
xPrint("F->P: %s\n", ftp_response);
|
||||
|
||||
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", ftp_response);
|
||||
|
||||
/* [6] Traitement de la réponse (FTP)
|
||||
============================================================================*/
|
||||
|
@ -118,7 +114,7 @@ static void* testServer(char* localPort){
|
|||
/* [7] Redirection vers le CLIENT
|
||||
============================================================================*/
|
||||
if( swrite(&USER_SOCKET, ftp_response) == -1 ) break;
|
||||
printf("P->C: %s\n", ftp_response);
|
||||
if( DEBUGMOD&CMD ) xPrint("P->C: %s\n", ftp_response);
|
||||
|
||||
|
||||
/* [8] On vide les buffers
|
||||
|
|
22
proxy_ftp.h
22
proxy_ftp.h
|
@ -13,14 +13,24 @@
|
|||
#include <netdb.h> // getaddrinfo, getnameinfo
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/* basis */
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
|
||||
/* debug */
|
||||
#define DEBUGMOD FALSE // <Boolean> TRUE = débugmode activé
|
||||
// #define DEBUGMOD TRUE // <Boolean> TRUE = débugmode activé
|
||||
#define ONLY_SOCKETS 0x01 // debug RESEAU
|
||||
#define ONLY_COMMAND 0x02 // debug COMMANDES
|
||||
#define ONLY_DATA 0x04 // debug DONNEES
|
||||
#define ONLY_REVEALS 0x08 // debug EXPLICITATION des strings
|
||||
#define ONLY_BUFFERS 0x10 // debug des BUFFERS
|
||||
#define ONLY_HEADERS 0x20 // debug des HEADERS de fonctions
|
||||
|
||||
#define SCK 0x01 // FILTRE pour ONLY_SOCKET
|
||||
#define CMD 0x02 // FILTRE pour ONLY_COMMAND
|
||||
#define DAT 0x04 // FILTRE pour ONLY_DATA
|
||||
#define RVL 0x08 // FILTRE pour ONLY_REVEALS
|
||||
#define BUF 0x10 // FILTRE pour ONLY_BUFFERS
|
||||
#define HDR 0x20 // FILTRE pour ONLY_HEADERS
|
||||
|
||||
#define DEBUGMOD ONLY_SOCKETS
|
||||
|
||||
|
||||
/* vars */
|
||||
#define remoteHost "localhost"
|
||||
|
|
Loading…
Reference in New Issue