First commit <xdrm-brackets:proxy.ftp.c> Import
This commit is contained in:
commit
b41a8d304f
|
@ -0,0 +1,196 @@
|
||||||
|
#include "central-manager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [0] Initialisation des variables
|
||||||
|
* [1] On démarre le SERVEUR d'écoute globale
|
||||||
|
* [2] Attente d'une demande de connection, puis création d'un THREAD
|
||||||
|
* [3] On attends la fin de tous les THREADS
|
||||||
|
* [4] On ferme la SOCKET d'écoute globale
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int main(int argc, char* argv[]){
|
||||||
|
/* [0] Initialisation des variables
|
||||||
|
==========================================================*/
|
||||||
|
int THREADABLE_SOCKET = -1; // contiendra le BUS DE COMMANDE utilisateur à envoyer à un THREAD
|
||||||
|
struct sockaddr_storage clientInfo; // contiendra les infos client
|
||||||
|
char repeat; // sert à sortir de la boucle
|
||||||
|
socklen_t len = sizeof(struct sockaddr_storage);
|
||||||
|
|
||||||
|
// retour de @DROP_SERVER
|
||||||
|
char* serverPort; // contiendra le port
|
||||||
|
int LISTENSOCK; // contiendra la socket d'écoute
|
||||||
|
|
||||||
|
|
||||||
|
/* [1] On démarre le SERVEUR d'écoute globale
|
||||||
|
==========================================================*/
|
||||||
|
serverPort = malloc(maxPortLen);
|
||||||
|
|
||||||
|
// attribution du port si dans les arguments
|
||||||
|
if( argc > 1 ) strcpy(serverPort, argv[1]);
|
||||||
|
|
||||||
|
DROP_SERVER(remoteHost, &serverPort, &LISTENSOCK);
|
||||||
|
printf("Port: %s\n", serverPort);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] Attente d'une demande de connection, puis création d'un THREAD
|
||||||
|
============================================================================*/
|
||||||
|
int index = -1;
|
||||||
|
while( 1 ){
|
||||||
|
/* 1. On initialise la SOCKET en attendant la connexion et le rang du "manager" inactif */
|
||||||
|
THREADABLE_SOCKET = -1;
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
/* 2. On attends une connection */
|
||||||
|
THREADABLE_SOCKET = accept(LISTENSOCK, (struct sockaddr *) &clientInfo, &len);
|
||||||
|
|
||||||
|
/* 3. On cherche un "manager" libre */
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// si on trouve un "manager" inactif, on l'enregistre dans index
|
||||||
|
for( i = 0 ; i < maxListLen ; i++ )
|
||||||
|
if( activeManagers[i] == 0 ){ index = i; break; }
|
||||||
|
|
||||||
|
// si on a trouvé un "manager" libre
|
||||||
|
if( index != -1 ){
|
||||||
|
|
||||||
|
/* 4. On lance un thread pour le traitement de ce client */
|
||||||
|
pthread_create(&managers[index], NULL, manageConnection, (void*)(intptr_t) THREADABLE_SOCKET);
|
||||||
|
if( DEBUGMOD&THR ) printf("THREAD[%d] démarré\n", index);
|
||||||
|
|
||||||
|
/* 5. On signale que ce "manager" est maintenant actif */
|
||||||
|
activeManagers[index] = 1;
|
||||||
|
}else
|
||||||
|
if( DEBUGMOD&THR ) printf("Demande de thread refusée!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [3] On attends la fin de tous les THREADS
|
||||||
|
==========================================================*/
|
||||||
|
int i;
|
||||||
|
for( i = 0 ; i < maxListLen ; i++ )
|
||||||
|
pthread_join(managers[i], NULL);
|
||||||
|
|
||||||
|
/* [4] On ferme la SOCKET d'écoute globale
|
||||||
|
==========================================================*/
|
||||||
|
printf("FERMETURE DE TOUTES LES CONNECTIONS!\n");
|
||||||
|
close(LISTENSOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Gestion d'une connexion client
|
||||||
|
*
|
||||||
|
* @THREADABLE_SOCKET<void*> SOCKET de la connexion client
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Initialisation des variables
|
||||||
|
* [2] Envoi de la séquence de bienvenue
|
||||||
|
* [3] Attente des données reçues et reception (CLIENT_FTP->PROXY)
|
||||||
|
* [4] Traitement de la requête client
|
||||||
|
* [5] Redirection de la requête vers le serveur FTP (PROXY->SERVER_FTP)
|
||||||
|
* [6] Traitement de la reponse du serveur FTP
|
||||||
|
* [7] Redirection de la réponse vers le client (PROXY->CLIENT_FTP)
|
||||||
|
* [8] On vide les buffers
|
||||||
|
* [9] Fermeture des connections (SOCKETS)
|
||||||
|
* [10] Arrêt du THREAD
|
||||||
|
* 1. On récupère le rang dans les "managers"
|
||||||
|
* 2. On met à jour "activeManagers"
|
||||||
|
* 3. On arrête le THREAD
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void* manageConnection(void* THREADABLE_SOCKET){
|
||||||
|
int USER_SOCKET = (intptr_t) THREADABLE_SOCKET; // BUS DE COMMANDE utilisateur
|
||||||
|
|
||||||
|
/* [1] Variables
|
||||||
|
============================================================================*/
|
||||||
|
// int USER_SOCKET = -1;
|
||||||
|
int FTP_SOCKET = -1; // contiendra le BUS DE COMMANDE FTP
|
||||||
|
int DUSER_SOCKET = -1; // contiendra le BUS DE DONNES utilisateur
|
||||||
|
int DFTP_SOCKET = -1; // contiendra le BUS DE DONNEES FTP
|
||||||
|
|
||||||
|
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 );
|
||||||
|
int error;
|
||||||
|
|
||||||
|
/* [2] Envoi de la séquence de bienvenue
|
||||||
|
============================================================================*/
|
||||||
|
swrite(&USER_SOCKET, WLCM_MSG);
|
||||||
|
|
||||||
|
/* BOUCLE DE COMMANDES */
|
||||||
|
while( USER_SOCKET != -1 ){
|
||||||
|
|
||||||
|
/* [3] On récupère les données reçues (+attente)
|
||||||
|
============================================================================*/
|
||||||
|
if( WAIT_SOCKET_UPDATE(&USER_SOCKET, BUFFER) == -1 ) break;
|
||||||
|
if( DEBUGMOD&CMD ) xPrint("C->P: %s\n", BUFFER);
|
||||||
|
|
||||||
|
|
||||||
|
/* [4] Traitement de la requête
|
||||||
|
============================================================================*/
|
||||||
|
error = MANAGE_REQUEST(BUFFER, &USER_SOCKET, &FTP_SOCKET, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||||
|
|
||||||
|
// si on a pas la connection FTP (commande) initialisée, on quitte
|
||||||
|
if( error == -1 ) break;
|
||||||
|
|
||||||
|
|
||||||
|
/* [5] Redirection vers le serveur FTP
|
||||||
|
============================================================================*/
|
||||||
|
if( DEBUGMOD&CMD ) xPrint("P->F: %s\n\n", BUFFER);
|
||||||
|
CLIENT_SEND(&FTP_SOCKET, BUFFER, &BUFFER);
|
||||||
|
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", BUFFER);
|
||||||
|
|
||||||
|
/* [6] Traitement de la réponse (FTP)
|
||||||
|
============================================================================*/
|
||||||
|
MANAGE_RESPONSE(BUFFER, &USER_SOCKET, &FTP_SOCKET, &DUSER_SOCKET, &DFTP_SOCKET);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [7] Redirection vers le CLIENT
|
||||||
|
============================================================================*/
|
||||||
|
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(BUFFER, '\0', maxBuffLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [9] Fermeture des connections (SOCKETS)
|
||||||
|
============================================================================*/
|
||||||
|
printf("CLOSING CONNECTIONS\n");
|
||||||
|
close(USER_SOCKET);
|
||||||
|
close(FTP_SOCKET);
|
||||||
|
|
||||||
|
/* [10] Arrêt du THREAD
|
||||||
|
============================================================================*/
|
||||||
|
/* 1. On récupère le rang dans les "managers" */
|
||||||
|
int i, index = -1;
|
||||||
|
for( i = 0 ; i < maxListLen ; i++ )
|
||||||
|
if( managers[i] == pthread_self() ){ index = i; break; }
|
||||||
|
|
||||||
|
/* 2. On met à jour "activeManagers" */
|
||||||
|
if( index != -1 )
|
||||||
|
activeManagers[index] = 0;
|
||||||
|
|
||||||
|
/* 3. On arrête le THREAD */
|
||||||
|
if( DEBUGMOD&THR ) printf("THREAD[%d] libéré\n", index);
|
||||||
|
pthread_exit(NULL);
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* global */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
/* sys */
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
/* socket */
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h> // getaddrinfo, getnameinfo
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* debug */
|
||||||
|
#define SOCKETS 0x01 // debug RESEAU
|
||||||
|
#define COMMANDS 0x02 // debug COMMANDES
|
||||||
|
#define DATA 0x04 // debug DONNEES
|
||||||
|
#define REVEALS 0x08 // debug EXPLICITATION des strings
|
||||||
|
#define BUFFERS 0x10 // debug des BUFFERS
|
||||||
|
#define HEADERS 0x20 // debug des HEADERS de fonctions
|
||||||
|
#define THREADS 0x40 // debug des THREADS
|
||||||
|
|
||||||
|
#define SCK 0x01 // FILTRE pour SOCKET
|
||||||
|
#define CMD 0x02 // FILTRE pour COMMAND
|
||||||
|
#define DAT 0x04 // FILTRE pour DATA
|
||||||
|
#define RVL 0x08 // FILTRE pour REVEALS
|
||||||
|
#define BUF 0x10 // FILTRE pour BUFFERS
|
||||||
|
#define HDR 0x20 // FILTRE pour HEADERS
|
||||||
|
#define THR 0x40 // FILTRE pour THREADS
|
||||||
|
|
||||||
|
// possibilité de cumuler les DEBUGMODES
|
||||||
|
#define DEBUGMOD SOCKETS + THREADS // REVEALS + HEADER + THREADS
|
||||||
|
|
||||||
|
|
||||||
|
/* vars */
|
||||||
|
#define remoteHost "localhost"
|
||||||
|
#define remotePort "80"
|
||||||
|
#define maxBuffLen 4096
|
||||||
|
#define maxListLen 10
|
||||||
|
#define maxHostLen 64
|
||||||
|
#define maxPortLen 6
|
||||||
|
|
||||||
|
/* local dependencies */
|
||||||
|
#include "dep/utility.c"
|
||||||
|
#include "dep/server.c"
|
||||||
|
|
||||||
|
|
||||||
|
/* headers */
|
||||||
|
void* manageConnection(void* THREADABLE_SOCKET);
|
||||||
|
|
||||||
|
// VARIABLES
|
||||||
|
static pthread_t managers[maxListLen]; // contiendra les THREADS
|
||||||
|
static int activeManagers[maxListLen] = {0}; // contiendra les THREADS actifs
|
|
@ -0,0 +1,430 @@
|
||||||
|
#include "server.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DROP_SERVER(const char* serverHost, char** givenPort, int* listenSocket){
|
||||||
|
if( DEBUGMOD&HDR ) printf("====== DROP_SERVER(%s, %s, %d) ======\n\n", serverHost, *givenPort, *listenSocket);
|
||||||
|
|
||||||
|
// FONCTIONNEMENT
|
||||||
|
struct addrinfo hints; // contiendra le filtre/format
|
||||||
|
struct addrinfo* addrinfo; // contiendra les infos du serveur
|
||||||
|
int SOCKET, BIND, LISTEN; // file_desc(s)
|
||||||
|
|
||||||
|
// INFOS
|
||||||
|
struct sockaddr_storage serverInfo; // contiendra les informations du server
|
||||||
|
socklen_t sockaddr_len = sizeof(struct sockaddr_storage);
|
||||||
|
char infoHost[maxHostLen]; // contiendra l'adresse du server
|
||||||
|
char infoPort[maxPortLen]; // contiendra le port du server
|
||||||
|
|
||||||
|
/* [1] On définit le filtre/format
|
||||||
|
=======================================================*/
|
||||||
|
memset(&hints, 0, sizeof(struct addrinfo)); // on vide le filtre
|
||||||
|
hints.ai_family = AF_UNSPEC; // Allow IPv4 ou IPv6
|
||||||
|
hints.ai_socktype = SOCK_STREAM; // TCP (SOCK_DGRAM = UDP)
|
||||||
|
hints.ai_flags = AI_PASSIVE; // mode SERVER
|
||||||
|
hints.ai_protocol = 0; // non spécifié
|
||||||
|
|
||||||
|
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
|
||||||
|
=======================================================*/
|
||||||
|
if( strlen(*givenPort) == 0 ) // si pas défini, port dynamique
|
||||||
|
getaddrinfo(serverHost, 0, &hints, &addrinfo);
|
||||||
|
else // sinon manuel
|
||||||
|
getaddrinfo(serverHost, *givenPort, &hints, &addrinfo);
|
||||||
|
// Remarque: port=0 donc va être défini dynamiquement
|
||||||
|
|
||||||
|
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&SCK ) printf("SOCKET = %d\n", SOCKET);
|
||||||
|
|
||||||
|
// si erreur
|
||||||
|
if( SOCKET == -1 ) return;
|
||||||
|
|
||||||
|
|
||||||
|
/* [4] On publie la SOCKET
|
||||||
|
=======================================================*/
|
||||||
|
BIND = bind(
|
||||||
|
SOCKET,
|
||||||
|
addrinfo->ai_addr,
|
||||||
|
addrinfo->ai_addrlen
|
||||||
|
);
|
||||||
|
|
||||||
|
if( DEBUGMOD&SCK ) printf("BIND = %d\n", BIND);
|
||||||
|
|
||||||
|
// si erreur
|
||||||
|
if( BIND == -1 ) return;
|
||||||
|
|
||||||
|
/* [5] On récupère les informations du serveur (host/port)
|
||||||
|
=======================================================*/
|
||||||
|
int getInfo = getsockname(SOCKET, (struct sockaddr *) &serverInfo, &sockaddr_len);
|
||||||
|
|
||||||
|
if( getInfo == -1 ) return;
|
||||||
|
|
||||||
|
getInfo = getnameinfo( // on récupère le host et le port
|
||||||
|
(struct sockaddr *) &serverInfo,
|
||||||
|
sizeof(serverInfo),
|
||||||
|
infoHost, maxHostLen,
|
||||||
|
infoPort, maxPortLen,
|
||||||
|
NI_NUMERICHOST | NI_NUMERICSERV
|
||||||
|
);
|
||||||
|
|
||||||
|
if( getInfo == -1 ) return;
|
||||||
|
|
||||||
|
if( DEBUGMOD&SCK ) printf("Server host: %s\n", infoHost);
|
||||||
|
if( DEBUGMOD&SCK ) printf("Server port: %s\n", infoPort);
|
||||||
|
|
||||||
|
|
||||||
|
// on a plus besoin des infos de l'adresse
|
||||||
|
freeaddrinfo(addrinfo);
|
||||||
|
|
||||||
|
|
||||||
|
/* [6] On met la socket sur écoute
|
||||||
|
=======================================================*/
|
||||||
|
LISTEN = listen(SOCKET, maxListLen);
|
||||||
|
|
||||||
|
if( DEBUGMOD&SCK ) printf("LISTEN = %d\n", LISTEN);
|
||||||
|
|
||||||
|
// si erreur
|
||||||
|
if( LISTEN == -1 ) return;
|
||||||
|
|
||||||
|
/* [7] On envoie les données par référence
|
||||||
|
=======================================================*/
|
||||||
|
// port
|
||||||
|
*givenPort = malloc( maxPortLen );
|
||||||
|
strcpy(*givenPort, infoPort);
|
||||||
|
|
||||||
|
// socket d'écoute
|
||||||
|
*listenSocket = SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int MANAGE_REQUEST(char* pRequest, int* USER_SOCKET, int* FTP_SOCKET, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
||||||
|
if( DEBUGMOD&HDR ) printf("====== MANAGE_REQUEST(%s, %d, %d, %d, %d) ======\n\n", pRequest, *USER_SOCKET, *FTP_SOCKET, *DUSER_SOCKET, *DFTP_SOCKET);
|
||||||
|
|
||||||
|
|
||||||
|
char response[maxBuffLen]; // contiendra la réponse (2*taille buffer pour strcat(BUFLEN, BUFLEN))
|
||||||
|
int nbSend; // contiendra le nombre de données envoyées
|
||||||
|
char rCommand[5]; // contiendra les commandes (1ère partie)
|
||||||
|
char rContent[maxBuffLen]; // contiendra le contenu associé à la commande (2ème partie)
|
||||||
|
|
||||||
|
// on vide les buffers
|
||||||
|
memset(&rCommand, '\0', sizeof(rCommand));
|
||||||
|
memset(&rContent, '\0', sizeof(rContent));
|
||||||
|
memset(&response, '\0', sizeof(response));
|
||||||
|
|
||||||
|
|
||||||
|
/* [1] On découpe la requête en 2 parties
|
||||||
|
================================================*/
|
||||||
|
splitFtpRequest(pRequest, rCommand, rContent);
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] Selection en fonction de @rCommand
|
||||||
|
================================================*/
|
||||||
|
|
||||||
|
/* (1) USER username@serveur => connection FTP (commande)
|
||||||
|
--------------------------------------------*/
|
||||||
|
if( strcmp(rCommand, "USER") == 0 && indexOf(rContent, '@') >= 0 ){
|
||||||
|
char userName[100] = {0};
|
||||||
|
char hostName[maxHostLen] = {0};
|
||||||
|
// pour l'envoi de la séquence d'initialisation
|
||||||
|
char* ftp_response; ftp_response = malloc(maxBuffLen);
|
||||||
|
memset(ftp_response, 0, maxBuffLen);
|
||||||
|
|
||||||
|
/* 1. On extrait @username et @hostname */
|
||||||
|
sscanf(rContent, "%[^@]@%s\r\n", userName, hostName);
|
||||||
|
|
||||||
|
if( DEBUGMOD&BUF ) printf("USERNAME [[%s]]\n", userName);
|
||||||
|
if( DEBUGMOD&BUF ) printf("HOSTNAME [[%s]]\n", hostName);
|
||||||
|
|
||||||
|
|
||||||
|
/* 2. On se connecte au serveur FTP (commandes) */
|
||||||
|
int error = CONNECT_CLIENT(hostName, FTP_PORT, FTP_SOCKET);
|
||||||
|
|
||||||
|
if( error == -1 || *FTP_SOCKET == -1 ){ // si erreur
|
||||||
|
printf("Impossible de se connecter au serveur (%s:%s)\n", hostName, FTP_PORT);
|
||||||
|
strcpy(pRequest, "421 ERREUR: impossible de se connecter au serveur!!\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( DEBUGMOD&SCK ) printf("FTP SOCKET CONNECTED AT %s:%s\n", hostName, FTP_PORT);
|
||||||
|
|
||||||
|
|
||||||
|
/* 3. On envoie la séquence d'initialisation */
|
||||||
|
CLIENT_SEND(FTP_SOCKET, "", &ftp_response);
|
||||||
|
|
||||||
|
if( DEBUGMOD&CMD ) xPrint("P->F: %s\n\n", "\r\n");
|
||||||
|
if( DEBUGMOD&CMD ) xPrint("F->P: %s\n", ftp_response);
|
||||||
|
|
||||||
|
|
||||||
|
/* 4. On envoie la requête USER au serveur FTP auquel on vient de se connecter */
|
||||||
|
char newRequest[maxBuffLen];
|
||||||
|
strcat(newRequest, "USER ");
|
||||||
|
strcat(newRequest, userName);
|
||||||
|
strcat(newRequest, "\r\n");
|
||||||
|
strcpy(response, "USER xdrm\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
else if( strcmp(rCommand, "USER") == 0 ) // si oubli serveur
|
||||||
|
strcpy(response, "421 'username@FTPserver' attendu\n");
|
||||||
|
|
||||||
|
/* (2) PORT a1,a2,a3,a4,p1,p2 => utilisateur (actif)
|
||||||
|
--------------------------------------------*/
|
||||||
|
else if( strcmp(rCommand, "PORT") == 0 ){
|
||||||
|
int a1, a2, a3, a4 = 0;
|
||||||
|
int p1, p2 = 0;
|
||||||
|
|
||||||
|
char serverHost[maxHostLen] = {0};
|
||||||
|
char serverPort[maxPortLen] = {0};
|
||||||
|
char BUFFER[maxBuffLen] = {0};
|
||||||
|
|
||||||
|
/* 1. On récupère l'ip et le port de la réponse */
|
||||||
|
sscanf(pRequest, "PORT %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*>
|
||||||
|
sprintf(serverPort, "%d", p1*256+p2);
|
||||||
|
|
||||||
|
|
||||||
|
/* 2. On se connecte au client */
|
||||||
|
if( DEBUGMOD&SCK ) printf("CONNECTING TO CLIENT %s:%s\n", serverHost, serverPort);
|
||||||
|
CONNECT_CLIENT(serverHost, serverPort, DUSER_SOCKET);
|
||||||
|
if( DEBUGMOD&SCK ) printf("CONNECTED TO CLIENT %s:%s\n", serverHost, serverPort);
|
||||||
|
|
||||||
|
/* 3. Envoi de "PASV" car on veut être en mode passif entre le proxy et le serveur FTP */
|
||||||
|
strcpy(response, "PASV\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (n) Si aucun traitement on recopie la requête telquel
|
||||||
|
--------------------------------------------*/
|
||||||
|
else
|
||||||
|
strcpy(response, pRequest);
|
||||||
|
|
||||||
|
/* [3] Retour de la réponse
|
||||||
|
================================================*/
|
||||||
|
strcpy(pRequest, response);
|
||||||
|
printf("RESP: %s\n", pRequest);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MANAGE_RESPONSE(char* pAnswer, int* USER_SOCKET, int* FTP_SOCKET, int* DUSER_SOCKET, int* DFTP_SOCKET){
|
||||||
|
if( DEBUGMOD&HDR ) printf("====== MANAGE_RESPONSE(%s, %d, %d, %d, %d) ======\n\n", pAnswer, *USER_SOCKET, *FTP_SOCKET, *DUSER_SOCKET, *DFTP_SOCKET);
|
||||||
|
|
||||||
|
char response[maxBuffLen]; // contiendra la réponse
|
||||||
|
char ftpCodeStr[4]; // contiendra le code FTP (1ère 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
|
||||||
|
memset(&ftpCodeStr, '\0', sizeof(ftpCode));
|
||||||
|
memset(&ftpText, '\0', sizeof(ftpText));
|
||||||
|
memset(&response, '\0', sizeof(response));
|
||||||
|
|
||||||
|
|
||||||
|
/* [1] On découpe la requête en 2 parties
|
||||||
|
================================================*/
|
||||||
|
splitFtpResponse(pAnswer, ftpCodeStr, ftpText);
|
||||||
|
|
||||||
|
// on met le code FTP en <int>
|
||||||
|
ftpCode = atoi( ftpCodeStr );
|
||||||
|
|
||||||
|
// mise à disposition de variables temporaires
|
||||||
|
int tmp[6] = {0};
|
||||||
|
char serverHost[maxHostLen];
|
||||||
|
char serverPort[maxPortLen];
|
||||||
|
char BUFFER[maxBuffLen] = {0};
|
||||||
|
|
||||||
|
/* [2] Selection en fonction de @ftpCode
|
||||||
|
================================================*/
|
||||||
|
switch(ftpCode){
|
||||||
|
/* (1) Demande d'username
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 220:
|
||||||
|
strcpy(response, WLCM_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* (2) username OK -> demande MDP
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 331:
|
||||||
|
strcpy(response, USER_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* (3) Bon mdp -> connection
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 230:
|
||||||
|
strcpy(response, PASS_BON_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* (4) Mauvais mdp -> message erreur
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 530:
|
||||||
|
strcpy(response, PASS_BAD_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* (5) Info SYST
|
||||||
|
--------------------------------------------*/
|
||||||
|
// case 215:
|
||||||
|
// strcpy(response, "bla\n");
|
||||||
|
// break;
|
||||||
|
|
||||||
|
|
||||||
|
/* (6) LOGOUT => EXIT
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 221:
|
||||||
|
strcpy(response, EXIT_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
/* (7) Mode passif => On lance les SOCKETS du BUS DE DONNEES
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 227: // on lance la SOCKET FTP du BUS DE DONNEES
|
||||||
|
|
||||||
|
/* 1. On récupère l'ip et le port de la réponse */
|
||||||
|
sscanf(pAnswer, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
|
||||||
|
// on récupère l'adresse en <char*>
|
||||||
|
sprintf(serverHost, "%d.%d.%d.%d", tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||||
|
// on récupère le port en <char*>
|
||||||
|
sprintf(serverPort, "%d", tmp[4]*256+tmp[5]);
|
||||||
|
|
||||||
|
/* 2. Connexion au serveur FTP */
|
||||||
|
if( DEBUGMOD&SCK ) printf("CONNECTING TO FTP %s:%s\n", serverHost, serverPort);
|
||||||
|
CONNECT_CLIENT(serverHost, serverPort, DFTP_SOCKET);
|
||||||
|
if( DEBUGMOD&SCK ) printf("CONNECTED TO FTP %s:%s\n", serverHost, serverPort);
|
||||||
|
|
||||||
|
/* 3. Envoi du message de code 200 */
|
||||||
|
strcpy(response, LIST_DAT_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
/* (8) On lit la SOCKET FTP du BUS DE DONNEES
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 150:
|
||||||
|
|
||||||
|
/* 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, READ_CON_MSG);
|
||||||
|
if( DEBUGMOD&CMD ) xPrint("P->C: %s\n", READ_CON_MSG);
|
||||||
|
|
||||||
|
|
||||||
|
/* 2. On lit la SOCKET FTP (BUS DE DONNEES) */
|
||||||
|
tmp[0] = WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER);
|
||||||
|
|
||||||
|
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) */
|
||||||
|
tmp[1] = swrite(DUSER_SOCKET, BUFFER);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
/* 4. On ferme les SOCKETS du BUS DE DONNEES */
|
||||||
|
close(*DFTP_SOCKET);
|
||||||
|
if( DEBUGMOD&CMD ) printf("BUS_FTP fermé (%d)\n", *DFTP_SOCKET);
|
||||||
|
close(*DUSER_SOCKET);
|
||||||
|
if( DEBUGMOD&CMD ) printf("BUS_USER fermé (%d)\n", *DUSER_SOCKET);
|
||||||
|
|
||||||
|
|
||||||
|
// on vide les SOCKET FTP des 2 BUS
|
||||||
|
// WAIT_SOCKET_UPDATE(FTP_SOCKET, BUFFER); // command
|
||||||
|
// WAIT_SOCKET_UPDATE(DFTP_SOCKET, BUFFER); // données
|
||||||
|
// printf("")
|
||||||
|
|
||||||
|
/* 5. On vide le BUS DE COMMANDE du serveur FTP */
|
||||||
|
/* A. On définit un TIMEOUT (1 sec) */
|
||||||
|
setSocketTimeout(FTP_SOCKET, 0, 50);
|
||||||
|
|
||||||
|
/* B. On attends une réponse */
|
||||||
|
tmp[2] = sread(FTP_SOCKET, BUFFER);
|
||||||
|
|
||||||
|
/* C. On enlève le TIMEOUT (default) */
|
||||||
|
setSocketTimeout(FTP_SOCKET, SOCKET_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
|
/* 6. On transmet le message de fin de la transaction (226) */
|
||||||
|
strcpy(response, STOP_DAT_MSG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
/* (9) Fin de transfert de données (fermeture SOCKETS du BUS DE DONNEES)
|
||||||
|
--------------------------------------------*/
|
||||||
|
case 226:
|
||||||
|
strcpy(response, "226 Fin de la transaction!\r\n");
|
||||||
|
close(*DUSER_SOCKET);
|
||||||
|
close(*DFTP_SOCKET);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* (n) Commande inconnue
|
||||||
|
--------------------------------------------*/
|
||||||
|
default:
|
||||||
|
strcpy(response, pAnswer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [3] Retour de la réponse
|
||||||
|
================================================*/
|
||||||
|
strcpy(pAnswer, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int WAIT_SOCKET_UPDATE(int* pSocket, char* pBuffer){
|
||||||
|
memset(pBuffer, 0, maxBuffLen); // on vide le buffer
|
||||||
|
|
||||||
|
int nbRead = 0;
|
||||||
|
|
||||||
|
do{
|
||||||
|
nbRead = sread(pSocket, pBuffer);
|
||||||
|
|
||||||
|
// si on est déconnecté, on renvoie une erreur
|
||||||
|
if( nbRead == -1 ){
|
||||||
|
printf("Client déconnecté!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}while( pBuffer[nbRead-1] != '\n' && pBuffer[nbRead-2] != '\r' );
|
||||||
|
|
||||||
|
|
||||||
|
// on retourne -1 si erreur, SINON 0
|
||||||
|
return nbRead;
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
/* Créé et met un serveur sur écoute
|
||||||
|
*
|
||||||
|
* ==IN==
|
||||||
|
* @serverHost<char*> Nom de l'hôte local (localhost)
|
||||||
|
* @givenPort<char**> Si renseigné, définit le port à utiliser
|
||||||
|
*
|
||||||
|
* ==OUT==
|
||||||
|
* @givenPort<char**> Pointeur sur le <char*> à remplir => contiendra le port donné par le système (si pas renseigné en entrée)
|
||||||
|
* @listenSocket<int*> Pointeur sur le <int> à remplir => contiendra un pointeur sur la socket d'écoute
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] On définit le filtre/format
|
||||||
|
* [2] On récupère les infos (adresse, port)
|
||||||
|
* Note: Gestion IPv4/IPv6
|
||||||
|
* [3] Création de la socket
|
||||||
|
* [4] On publie la SOCKET (bind)
|
||||||
|
* [5] On récupère les informations du serveur (host/port)
|
||||||
|
* [6] On met la socket sur écoute (listen)
|
||||||
|
* [7] On envoie les données par référence
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void DROP_SERVER(const char* serverHost, char** givenPort, int* listenSocket);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Gestion de la requête du client
|
||||||
|
* ==IN/OUT==
|
||||||
|
* @pBuffer<char*> Requête en question
|
||||||
|
* @USER_SOCKET<int*> Pointeur sur la SOCKET du BUS DE COMMANDES utilisateur
|
||||||
|
* @FTP_SOCKET<int*> Pointeur sur la SOCKET du BUS DE COMMANDES 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] On découpe la requête en 2 parties (rCommand, rContent)
|
||||||
|
* [2] Selection en fonction de @rCommand
|
||||||
|
* (1) USER username@serveur => connection FTP (commande)
|
||||||
|
* 1. On extrait @username et @hostname
|
||||||
|
* 2. On se connecte au serveur FTP (commandes)
|
||||||
|
* 3. On envoie la séquence d'initialisation
|
||||||
|
* 4. On envoie la requête USER au serveur FTP auquel on vient de se connecter
|
||||||
|
*
|
||||||
|
* (2) PORT a1,a2,a3,a4,p1,p2 => utilisateur (actif)
|
||||||
|
* 1. On récupère l'ip et le port de la requête
|
||||||
|
* 2. On se connecte au client
|
||||||
|
* 3. Envoi de "PASV" car on veut être en mode passif entre le proxy et le serveur FTP
|
||||||
|
* (n) Si aucun traitement on recopie la requête telquel
|
||||||
|
*
|
||||||
|
* [3] Retour de la réponse
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int MANAGE_REQUEST(char* pRequest, int* USER_SOCKET, int* FTP_SOCKET, int* DUSER_SOCKET, int* DFTP_SOCKET);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
* @USER_SOCKET<int*> Pointeur sur la SOCKET du BUS DE COMMANDES utilisateur
|
||||||
|
* @FTP_SOCKET<int*> Pointeur sur la SOCKET du BUS DE COMMANDES 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] On découpe la requête en 2 parties (ftpCode, ftpText)
|
||||||
|
* [2] Selection en fonction de @ftpCode
|
||||||
|
* (1) 220- Demande d'username
|
||||||
|
* (2) 331- username OK -> demande MDP
|
||||||
|
* (3) 230- Bon mdp -> connection
|
||||||
|
* (4) 530- Mauvais mdp -> message erreur
|
||||||
|
* (5) 215- Info SYST [COMMENTÉ]
|
||||||
|
* (6) 221- LOGOUT => EXIT (commande QUIT)
|
||||||
|
* (7) 227- Mode passif => On lance les SOCKETS du BUS DE DONNEES
|
||||||
|
* 1. On récupère l'ip et le port de la réponse
|
||||||
|
* 2. Connexion au serveur FTP
|
||||||
|
* 3. Envoi du message de code 200
|
||||||
|
*
|
||||||
|
* (8) 150- On lit la SOCKET FTP du BUS DE DONNEES
|
||||||
|
* 1. Envoi au client de l'écoute de la réponse (associée) du BUS DE DONNEES
|
||||||
|
* 2. On lit la SOCKET FTP (BUS DE DONNEES)
|
||||||
|
* 3. On redirige sur la SOCKET utilisateur (BUS DE DONNEES)
|
||||||
|
* 4. On ferme les SOCKETS du BUS DE DONNEES
|
||||||
|
* 5. On vide le BUS DE COMMANDE du serveur FTP
|
||||||
|
* A. On définit un TIMEOUT (1 sec
|
||||||
|
* B. On attends une réponse
|
||||||
|
* C. On enlève le TIMEOUT (default)
|
||||||
|
* 6. On transmet le message de fin de la transaction (226)
|
||||||
|
*
|
||||||
|
* (9) 226- Fin de transfert de données (fermeture SOCKETS du BUS DE DONNEES)
|
||||||
|
* (n) xxx- Commande inconnue
|
||||||
|
*
|
||||||
|
* [3] Retour de la réponse
|
||||||
|
*/
|
||||||
|
void MANAGE_RESPONSE(char* pAnswer, int* USER_SOCKET, int* FTP_SOCKET, 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
|
||||||
|
*
|
||||||
|
* @return nbRead<int> On retourne le nombre de char lus, sinon -1 si erreur
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @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 se produit, on retourne -1
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int WAIT_CLIENT(int* pSocket, char* pBuffer);
|
|
@ -0,0 +1,169 @@
|
||||||
|
#include "utility.h"
|
||||||
|
|
||||||
|
void splitFtpRequest(char* pRequest, char* pCommand, char* pContent){
|
||||||
|
/* [1] Vérification du format
|
||||||
|
===========================================*/
|
||||||
|
int firstSpaceIndex = indexOf(pRequest, ' ');
|
||||||
|
|
||||||
|
if( firstSpaceIndex != 3 && firstSpaceIndex != 4){ // contient aucun espace en position 3 ou 4, on quitte
|
||||||
|
strcpy(pCommand, "ERROR");
|
||||||
|
strcpy(pContent, "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] Séparation des 2 parties
|
||||||
|
===========================================*/
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = 0 ; i < strlen(pRequest) && pRequest[i] != '\0' ; i++ ){
|
||||||
|
|
||||||
|
if( i < firstSpaceIndex ) // première partie (pCommand)
|
||||||
|
strcat( pCommand, (char[2]){(char) pRequest[i], '\0'});
|
||||||
|
if( i > firstSpaceIndex ) // seconde partie (pContent)
|
||||||
|
strcat( pContent, (char[2]){(char) pRequest[i], '\0'});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText){
|
||||||
|
/* [1] Vérification du format
|
||||||
|
===========================================*/
|
||||||
|
int codeLength = 3; // taille du code
|
||||||
|
|
||||||
|
/* [2] Séparation des 2 parties
|
||||||
|
===========================================*/
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = 0 ; i < strlen(pAnswer) && pAnswer[i] != '\0' ; i++ ){
|
||||||
|
|
||||||
|
if( i < codeLength ) // première partie (ftpCode)
|
||||||
|
strcat(ftpCode, (char[2]){(char)pAnswer[i], '\0' });
|
||||||
|
if( i > codeLength ) // seconde partie (ftpText)
|
||||||
|
strcat(ftpText, (char[2]){(char)pAnswer[i], '\0' });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int indexOf(char* haystack, char needle){
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = 0 ; i < strlen(haystack) && haystack[i] != '\0' ; i++ )
|
||||||
|
if( haystack[i] == needle ) // si on trouve le caractère
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
/* 1. On écrit sur la SOCKET */
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* 2. Si on est déconnecté, on retourne une erreur */
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
/* 3. On retourne le nombre de <char> envoyés */
|
||||||
|
return nbSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int sread(int* pSocket, char* pBuffer){
|
||||||
|
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
||||||
|
|
||||||
|
|
||||||
|
/* 1. On vide le buffer avant de lire */
|
||||||
|
memset(pBuffer, '\0', maxBuffLen);
|
||||||
|
if( DEBUGMOD&BUF ) printf("READLEN_1: %lu\n", strlen(pBuffer));
|
||||||
|
|
||||||
|
/* 2. On lit la SOCKET */
|
||||||
|
int nbRead = read(*pSocket, pBuffer, maxBuffLen);
|
||||||
|
if( DEBUGMOD&BUF ) printf("READLEN_3: %d\n", nbRead);
|
||||||
|
|
||||||
|
|
||||||
|
/* 3. Si on est déconnecté, on retourne une erreur */
|
||||||
|
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");
|
||||||
|
|
||||||
|
/* 4. On retourne le nombre de caractères lus */
|
||||||
|
return nbRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec){
|
||||||
|
/* 1. On créé la structure contenant le timeout */
|
||||||
|
struct timeval timeout;
|
||||||
|
timeout.tv_sec = pSec;
|
||||||
|
timeout.tv_usec = pUSec;
|
||||||
|
|
||||||
|
setsockopt(*pSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(struct timeval));
|
||||||
|
|
||||||
|
if( DEBUGMOD&SCK ) printf("Set socket(%d) timeout to %lus\n", *pSocket, (long unsigned) timeout.tv_sec );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xPrint(char* pPattern, char* pBuffer){
|
||||||
|
char tmpBuffer[maxBuffLen];
|
||||||
|
strcpy(tmpBuffer, pBuffer);
|
||||||
|
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// on supprimes les retours à la ligne de la fin
|
||||||
|
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("[[%s]]\n", revealedString);
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* Découpe la requête FTP en 2 parties
|
||||||
|
*
|
||||||
|
* @pRequest<char*> La requête en question
|
||||||
|
*
|
||||||
|
* @pCommand<char*> Remplissage: commande (1ère partie)
|
||||||
|
* @pContant<char*> Remplissage: contenu (2ème partie)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void splitFtpRequest(char* pRequest, char* pCommand, char* pContent);
|
||||||
|
|
||||||
|
/* Découpe la réponse FTP en 2 parties
|
||||||
|
*
|
||||||
|
* @pAnswer<char*> La réponse en question
|
||||||
|
*
|
||||||
|
* @ftpCode<char*> Remplissage: code FTP (1ère partie)
|
||||||
|
* @ftpText<char*> Remplissage: text associé (2ème partie)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText);
|
||||||
|
|
||||||
|
|
||||||
|
/* Retourne le rang d'un caractère dans une string
|
||||||
|
*
|
||||||
|
* @haystack<char*> La chaîne dans laquelle rechercher
|
||||||
|
* @needle<char> Le caractère recherché
|
||||||
|
*
|
||||||
|
* @return position<int> Retourne l'index de @needle dans @haystack ou -1 si ne trouve pas
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int indexOf(char* haystack, char needle);
|
||||||
|
|
||||||
|
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec);
|
||||||
|
|
||||||
|
|
||||||
|
/* read/write socket */
|
||||||
|
int swrite(int* pSocket, char* pBuffer);
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
/* 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);
|
|
@ -0,0 +1,500 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head data-suburl="">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
|
||||||
|
<meta name="author" content="xdrm-brackets" />
|
||||||
|
<meta name="description" content="proxy.ftp.c" />
|
||||||
|
<meta name="keywords" content="go, git, self-hosted, gogs">
|
||||||
|
|
||||||
|
<meta name="referrer" content="no-referrer" />
|
||||||
|
<meta name="_csrf" content="oL9HDhjy3U7tPSwjawLkQB4VNfA6MTQ5MDcxOTc2NTY0Nzg0MDkyNQ==" />
|
||||||
|
<meta name="_suburl" content="" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<meta property="og:url" content="https://git.xdrm.io/xdrm-brackets/proxy.ftp.c" />
|
||||||
|
<meta property="og:type" content="object" />
|
||||||
|
<meta property="og:title" content="xdrm-brackets/proxy.ftp.c">
|
||||||
|
<meta property="og:description" content="">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="shortcut icon" href="/img/favicon.png" />
|
||||||
|
|
||||||
|
<script src="/js/jquery-1.11.3.min.js"></script>
|
||||||
|
<script src="/js/libs/jquery.are-you-sure.js"></script>
|
||||||
|
<link rel="stylesheet" href="/assets/font-awesome-4.6.3/css/font-awesome.min.css">
|
||||||
|
<link rel="stylesheet" href="/assets/octicons-4.3.0/octicons.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/css/semantic-2.2.7.min.css">
|
||||||
|
<link rel="stylesheet" href="/css/gogs.css?v=73519fd9811805bce6fc4aa2d24bb413">
|
||||||
|
|
||||||
|
|
||||||
|
<script src="/js/semantic-2.2.7.min.js"></script>
|
||||||
|
<script src="/js/gogs.js?v=73519fd9811805bce6fc4aa2d24bb413"></script>
|
||||||
|
|
||||||
|
<title>xdrm-brackets/proxy.ftp.c - xdrm-brackets' git server</title>
|
||||||
|
|
||||||
|
<meta name="theme-color" content="#ff5343">
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="full height">
|
||||||
|
<noscript>Please enable JavaScript in your browser!</noscript>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="following bar light">
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="column">
|
||||||
|
<div class="ui top secondary menu">
|
||||||
|
<a class="item brand" href="/">
|
||||||
|
<img class="ui mini image" src="/img/favicon.png">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="item" href="/">Home</a>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="item" href="/explore/repos">Explore</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a class="item" target="_blank" href="https://gogs.io/docs" rel="noreferrer">Help</a>
|
||||||
|
<div class="right menu">
|
||||||
|
|
||||||
|
<a class="item" href="/user/sign_up">
|
||||||
|
<i class="octicon octicon-person"></i> Register
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="item" href="/user/login?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
|
||||||
|
<i class="octicon octicon-sign-in"></i> Sign In
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="repository file list">
|
||||||
|
<div class="header-wrapper">
|
||||||
|
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui vertically padded grid head">
|
||||||
|
<div class="column">
|
||||||
|
<div class="ui header">
|
||||||
|
<div class="ui huge breadcrumb">
|
||||||
|
<i class="mega-octicon octicon-repo"></i>
|
||||||
|
<a href="/xdrm-brackets">xdrm-brackets</a>
|
||||||
|
<div class="divider"> / </div>
|
||||||
|
<a href="/xdrm-brackets/proxy.ftp.c">proxy.ftp.c</a>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui right">
|
||||||
|
<div class="ui labeled button" tabindex="0">
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/watch?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
|
||||||
|
<i class="icon fa-eye-slash"></i>Watch
|
||||||
|
</a>
|
||||||
|
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/watchers">
|
||||||
|
1
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="ui labeled button" tabindex="0">
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/star?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
|
||||||
|
<i class="icon fa-star-o"></i>Star
|
||||||
|
</a>
|
||||||
|
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/stars">
|
||||||
|
0
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui labeled button" tabindex="0">
|
||||||
|
<a class="ui button " href="/repo/fork/49">
|
||||||
|
<i class="octicon octicon-repo-forked"></i>Fork
|
||||||
|
</a>
|
||||||
|
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/forks">
|
||||||
|
0
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="ui tabs container">
|
||||||
|
<div class="ui tabular menu navbar">
|
||||||
|
<a class="active item" href="/xdrm-brackets/proxy.ftp.c">
|
||||||
|
<i class="octicon octicon-file-text"></i> Files
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/issues">
|
||||||
|
<i class="octicon octicon-issue-opened"></i> Issues <span class="ui gray small label">0</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/pulls">
|
||||||
|
<i class="octicon octicon-git-pull-request"></i> Pull Requests <span class="ui gray small label">0</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/commits/master">
|
||||||
|
<i class="octicon octicon-history"></i> Commits <span class="ui blue small label">23</span>
|
||||||
|
</a>
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/releases">
|
||||||
|
<i class="octicon octicon-tag"></i> Releases <span class="ui gray small label">0</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/wiki">
|
||||||
|
<i class="octicon octicon-book"></i> Wiki
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui tabs divider"></div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p id="repo-desc">
|
||||||
|
<span class="no-description text-italic">No Description</span>
|
||||||
|
<a class="link" href=""></a>
|
||||||
|
</p>
|
||||||
|
<div class="ui secondary menu">
|
||||||
|
|
||||||
|
<div class="fitted item choose reference">
|
||||||
|
<div class="ui floating filter dropdown" data-no-results="No results found.">
|
||||||
|
<div class="ui basic small button">
|
||||||
|
<span class="text">
|
||||||
|
<i class="octicon octicon-git-branch"></i>
|
||||||
|
Branch:
|
||||||
|
<strong>master</strong>
|
||||||
|
</span>
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
</div>
|
||||||
|
<div class="menu">
|
||||||
|
<div class="ui icon search input">
|
||||||
|
<i class="filter icon"></i>
|
||||||
|
<input name="search" placeholder="Filter branch or tag...">
|
||||||
|
</div>
|
||||||
|
<div class="header">
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="two column row">
|
||||||
|
<a class="reference column" href="#" data-target="#branch-list">
|
||||||
|
<span class="text black">
|
||||||
|
<i class="octicon octicon-git-branch"></i> Branches
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<a class="reference column" href="#" data-target="#tag-list">
|
||||||
|
<span class="text ">
|
||||||
|
<i class="reference tags icon"></i> Tags
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="branch-list" class="scrolling menu" >
|
||||||
|
|
||||||
|
<div class="item selected" data-url="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c">master</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="tag-list" class="scrolling menu" style="display: none">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="fitted item">
|
||||||
|
<div class="ui breadcrumb">
|
||||||
|
<a class="section" href="/xdrm-brackets/proxy.ftp.c/src/master">proxy.ftp.c</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="divider"> / </div>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="section"><a href="/xdrm-brackets/proxy.ftp.c/src/master/dep">dep</a></span>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="divider"> / </div>
|
||||||
|
|
||||||
|
<span class="active section">client.c</span>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="right fitted item">
|
||||||
|
|
||||||
|
<div id="file-buttons" class="ui tiny blue buttons">
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="file-content" class="tab-size-8">
|
||||||
|
<h4 class="ui top attached header" id="repo-read-file">
|
||||||
|
|
||||||
|
<i class="file text outline icon ui left"></i>
|
||||||
|
<strong>client.c</strong> <span class="text grey normal">3.9KB</span>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="ui right file-actions">
|
||||||
|
<div class="ui buttons">
|
||||||
|
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/src/18a5e4338baaec92912eee057d26004b57b0b2a0/dep/client.c">Permalink</a>
|
||||||
|
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/commits/master/dep/client.c">History</a>
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/raw/master/dep/client.c">Raw</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="You must fork this repository before editing the file" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||||
|
|
||||||
|
|
||||||
|
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="You must have write access to make or propose changes to this file" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</h4>
|
||||||
|
<div class="ui attached table segment">
|
||||||
|
<div id="" class="file-view code-view has-emoji">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<td class="lines-num"><span id="L1">1</span><span id="L2">2</span><span id="L3">3</span><span id="L4">4</span><span id="L5">5</span><span id="L6">6</span><span id="L7">7</span><span id="L8">8</span><span id="L9">9</span><span id="L10">10</span><span id="L11">11</span><span id="L12">12</span><span id="L13">13</span><span id="L14">14</span><span id="L15">15</span><span id="L16">16</span><span id="L17">17</span><span id="L18">18</span><span id="L19">19</span><span id="L20">20</span><span id="L21">21</span><span id="L22">22</span><span id="L23">23</span><span id="L24">24</span><span id="L25">25</span><span id="L26">26</span><span id="L27">27</span><span id="L28">28</span><span id="L29">29</span><span id="L30">30</span><span id="L31">31</span><span id="L32">32</span><span id="L33">33</span><span id="L34">34</span><span id="L35">35</span><span id="L36">36</span><span id="L37">37</span><span id="L38">38</span><span id="L39">39</span><span id="L40">40</span><span id="L41">41</span><span id="L42">42</span><span id="L43">43</span><span id="L44">44</span><span id="L45">45</span><span id="L46">46</span><span id="L47">47</span><span id="L48">48</span><span id="L49">49</span><span id="L50">50</span><span id="L51">51</span><span id="L52">52</span><span id="L53">53</span><span id="L54">54</span><span id="L55">55</span><span id="L56">56</span><span id="L57">57</span><span id="L58">58</span><span id="L59">59</span><span id="L60">60</span><span id="L61">61</span><span id="L62">62</span><span id="L63">63</span><span id="L64">64</span><span id="L65">65</span><span id="L66">66</span><span id="L67">67</span><span id="L68">68</span><span id="L69">69</span><span id="L70">70</span><span id="L71">71</span><span id="L72">72</span><span id="L73">73</span><span id="L74">74</span><span id="L75">75</span><span id="L76">76</span><span id="L77">77</span><span id="L78">78</span><span id="L79">79</span><span id="L80">80</span><span id="L81">81</span><span id="L82">82</span><span id="L83">83</span><span id="L84">84</span><span id="L85">85</span><span id="L86">86</span><span id="L87">87</span><span id="L88">88</span><span id="L89">89</span><span id="L90">90</span><span id="L91">91</span><span id="L92">92</span><span id="L93">93</span><span id="L94">94</span><span id="L95">95</span><span id="L96">96</span><span id="L97">97</span><span id="L98">98</span><span id="L99">99</span><span id="L100">100</span><span id="L101">101</span><span id="L102">102</span><span id="L103">103</span><span id="L104">104</span><span id="L105">105</span><span id="L106">106</span><span id="L107">107</span></td>
|
||||||
|
<td class="lines-code"><pre><code class="c"><ol class="linenums"><li class="L1" rel="L1">#include "client.h"</li>
|
||||||
|
<li class="L2" rel="L2"></li>
|
||||||
|
<li class="L3" rel="L3"></li>
|
||||||
|
<li class="L4" rel="L4">int CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){</li>
|
||||||
|
<li class="L5" rel="L5"> if( DEBUGMOD&HDR ) printf("====== CONNECT_CLIENT(%s, %s, %d) ======\n\n", serverHost, serverPort, *pSocket);</li>
|
||||||
|
<li class="L6" rel="L6"></li>
|
||||||
|
<li class="L7" rel="L7"> struct addrinfo hints; // contiendra le filtre/format</li>
|
||||||
|
<li class="L8" rel="L8"> struct addrinfo* addrinfo; // contiendra les infos</li>
|
||||||
|
<li class="L9" rel="L9"> int CONNECT; // file_desc(s)</li>
|
||||||
|
<li class="L10" rel="L10"> int GETADDRINFO; // contiendra l'erreur ou pas de getaddrinfo()</li>
|
||||||
|
<li class="L11" rel="L11"> char BUFFER[maxBuffLen]; // BUFFER de communication</li>
|
||||||
|
<li class="L12" rel="L12"></li>
|
||||||
|
<li class="L13" rel="L13"> /* [1] On définit le filtre/format</li>
|
||||||
|
<li class="L14" rel="L14"> =======================================================*/</li>
|
||||||
|
<li class="L15" rel="L15"> memset(&hints, 0, sizeof(struct addrinfo)); // on vide le filtre</li>
|
||||||
|
<li class="L16" rel="L16"> hints.ai_family = AF_UNSPEC; // Allow IPv4 ou IPv6</li>
|
||||||
|
<li class="L17" rel="L17"> hints.ai_socktype = SOCK_STREAM; // TCP (SOCK_DGRAM = UDP)</li>
|
||||||
|
<li class="L18" rel="L18"> hints.ai_flags = 0; // non spécifié</li>
|
||||||
|
<li class="L19" rel="L19"> hints.ai_protocol = 0; // non spécifié</li>
|
||||||
|
<li class="L20" rel="L20"></li>
|
||||||
|
<li class="L21" rel="L21"> if( DEBUGMOD&SCK ) printf("============HINTS===========\n");</li>
|
||||||
|
<li class="L22" rel="L22"> if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int</li>
|
||||||
|
<li class="L23" rel="L23"> if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int</li>
|
||||||
|
<li class="L24" rel="L24"> if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int</li>
|
||||||
|
<li class="L25" rel="L25"> if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int</li>
|
||||||
|
<li class="L26" rel="L26"> if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int</li>
|
||||||
|
<li class="L27" rel="L27"> if( DEBUGMOD&SCK ) printf("\n");</li>
|
||||||
|
<li class="L28" rel="L28"></li>
|
||||||
|
<li class="L29" rel="L29"></li>
|
||||||
|
<li class="L30" rel="L30"> /* [2] On récupère les infos</li>
|
||||||
|
<li class="L31" rel="L31"> =======================================================*/</li>
|
||||||
|
<li class="L32" rel="L32"> GETADDRINFO = getaddrinfo(serverHost, serverPort, &hints, &addrinfo);</li>
|
||||||
|
<li class="L33" rel="L33"></li>
|
||||||
|
<li class="L34" rel="L34"> // si erreur</li>
|
||||||
|
<li class="L35" rel="L35"> if( GETADDRINFO < 0 ) return -1;</li>
|
||||||
|
<li class="L36" rel="L36"></li>
|
||||||
|
<li class="L37" rel="L37"> if( DEBUGMOD&SCK ) printf("=============RES============\n");</li>
|
||||||
|
<li class="L38" rel="L38"> if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int</li>
|
||||||
|
<li class="L39" rel="L39"> if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int</li>
|
||||||
|
<li class="L40" rel="L40"> if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int</li>
|
||||||
|
<li class="L41" rel="L41"> if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int</li>
|
||||||
|
<li class="L42" rel="L42"> if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int</li>
|
||||||
|
<li class="L43" rel="L43"> if( DEBUGMOD&SCK ) printf("\n");</li>
|
||||||
|
<li class="L44" rel="L44"></li>
|
||||||
|
<li class="L45" rel="L45"> /* [3] Création de la socket</li>
|
||||||
|
<li class="L46" rel="L46"> =======================================================*/</li>
|
||||||
|
<li class="L47" rel="L47"> *pSocket = socket(addrinfo->ai_family, addrinfo->ai_socktype, 0);</li>
|
||||||
|
<li class="L48" rel="L48"></li>
|
||||||
|
<li class="L49" rel="L49"> if( DEBUGMOD&SCK ) printf("SOCKET = %d\n", *pSocket);</li>
|
||||||
|
<li class="L50" rel="L50"></li>
|
||||||
|
<li class="L51" rel="L51"> // si erreur</li>
|
||||||
|
<li class="L52" rel="L52"> if( *pSocket == -1 ) return -1;</li>
|
||||||
|
<li class="L53" rel="L53"></li>
|
||||||
|
<li class="L54" rel="L54"></li>
|
||||||
|
<li class="L55" rel="L55"> /* [4] On établit la connection</li>
|
||||||
|
<li class="L56" rel="L56"> =======================================================*/</li>
|
||||||
|
<li class="L57" rel="L57"> CONNECT = connect(</li>
|
||||||
|
<li class="L58" rel="L58"> *pSocket,</li>
|
||||||
|
<li class="L59" rel="L59"> addrinfo->ai_addr,</li>
|
||||||
|
<li class="L60" rel="L60"> addrinfo->ai_addrlen</li>
|
||||||
|
<li class="L61" rel="L61"> );</li>
|
||||||
|
<li class="L62" rel="L62"></li>
|
||||||
|
<li class="L63" rel="L63"> if( DEBUGMOD&SCK ) printf("CONNECT = %d\n", CONNECT);</li>
|
||||||
|
<li class="L64" rel="L64"></li>
|
||||||
|
<li class="L65" rel="L65"> // si erreur</li>
|
||||||
|
<li class="L66" rel="L66"> if( CONNECT == -1 ) return -1;</li>
|
||||||
|
<li class="L67" rel="L67"></li>
|
||||||
|
<li class="L68" rel="L68"> // on a plus besoin des infos de l'adresse</li>
|
||||||
|
<li class="L69" rel="L69"> freeaddrinfo(addrinfo);</li>
|
||||||
|
<li class="L70" rel="L70"></li>
|
||||||
|
<li class="L71" rel="L71"></li>
|
||||||
|
<li class="L72" rel="L72"> /* [5] On retourne la SOCKET</li>
|
||||||
|
<li class="L73" rel="L73"> =======================================================*/</li>
|
||||||
|
<li class="L74" rel="L74"> return *pSocket;</li>
|
||||||
|
<li class="L75" rel="L75">}</li>
|
||||||
|
<li class="L76" rel="L76"></li>
|
||||||
|
<li class="L77" rel="L77"></li>
|
||||||
|
<li class="L78" rel="L78"></li>
|
||||||
|
<li class="L79" rel="L79"></li>
|
||||||
|
<li class="L80" rel="L80"></li>
|
||||||
|
<li class="L81" rel="L81"></li>
|
||||||
|
<li class="L82" rel="L82">int CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer){</li>
|
||||||
|
<li class="L83" rel="L83"> if( DEBUGMOD&HDR ) printf("====== CLIENT_SEND(%d, %s, %s) ======\n\n", *pSocket, pRequest, *pAnswer);</li>
|
||||||
|
<li class="L84" rel="L84"> char BUFFER[maxBuffLen] = {0};</li>
|
||||||
|
<li class="L85" rel="L85"></li>
|
||||||
|
<li class="L86" rel="L86"> /* [1] On écrit sur la socket</li>
|
||||||
|
<li class="L87" rel="L87"> =======================================================*/</li>
|
||||||
|
<li class="L88" rel="L88"> int nbSend = swrite(pSocket, pRequest);</li>
|
||||||
|
<li class="L89" rel="L89"></li>
|
||||||
|
<li class="L90" rel="L90"> if( DEBUGMOD&BUF ) printf("nbSend: %d\n", nbSend);</li>
|
||||||
|
<li class="L91" rel="L91"> if( DEBUGMOD&BUF ) printf("Message: %s\n", pRequest);</li>
|
||||||
|
<li class="L92" rel="L92"></li>
|
||||||
|
<li class="L93" rel="L93"> // si pas tout envoyé</li>
|
||||||
|
<li class="L94" rel="L94"> if( strlen(pRequest) != nbSend ) return -1;</li>
|
||||||
|
<li class="L95" rel="L95"></li>
|
||||||
|
<li class="L96" rel="L96"> /* [2] On attends et lit la réponse</li>
|
||||||
|
<li class="L97" rel="L97"> =======================================================*/</li>
|
||||||
|
<li class="L98" rel="L98"> int nbRecup = WAIT_SOCKET_UPDATE(pSocket, BUFFER);</li>
|
||||||
|
<li class="L99" rel="L99"></li>
|
||||||
|
<li class="L100" rel="L100"> /* [3] On retourne la réponse par référence</li>
|
||||||
|
<li class="L101" rel="L101"> =======================================================*/</li>
|
||||||
|
<li class="L102" rel="L102"> *pAnswer = malloc( maxBuffLen );</li>
|
||||||
|
<li class="L103" rel="L103"> strcpy(*pAnswer, BUFFER);</li>
|
||||||
|
<li class="L104" rel="L104"></li>
|
||||||
|
<li class="L105" rel="L105"> if( DEBUGMOD&BUF ) printf("nbReceived: %d\n", nbRecup);</li>
|
||||||
|
<li class="L106" rel="L106"> if( DEBUGMOD&BUF ) printf("Message: %s\n", *pAnswer);</li>
|
||||||
|
<li class="L107" rel="L107">}</li>
|
||||||
|
</ol></code></pre></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function submitDeleteForm() {
|
||||||
|
var message = prompt("delete_confirm_message\n\ndelete_commit_summary", "Delete ''");
|
||||||
|
if (message != null) {
|
||||||
|
$("#delete-message").val(message);
|
||||||
|
$("#delete-file-form").submit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui left">
|
||||||
|
© 2017 Gogs Version: 0.10.10.0308 Page: <strong>52ms</strong> Template: <strong>2ms</strong>
|
||||||
|
</div>
|
||||||
|
<div class="ui right links">
|
||||||
|
|
||||||
|
<div class="ui language bottom floating slide up dropdown link item">
|
||||||
|
<i class="world icon"></i>
|
||||||
|
<div class="text">English</div>
|
||||||
|
<div class="menu">
|
||||||
|
|
||||||
|
<a class="item active selected" href="#">English</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-CN">简体中文</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-HK">繁體中文(香港)</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-TW">繁體中文(台湾)</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=de-DE">Deutsch</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=fr-FR">Français</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=nl-NL">Nederlands</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=lv-LV">Latviešu</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=ru-RU">Русский</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=ja-JP">日本語</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=es-ES">Español</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=pt-BR">Português do Brasil</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=pl-PL">Polski</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=bg-BG">български</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=it-IT">Italiano</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=fi-FI">Suomalainen</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=tr-TR">Türkçe</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=cs-CZ">čeština</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a href="/assets/librejs/librejs.html" style="display:none" data-jslicense="1">Javascript Licenses</a>
|
||||||
|
<a target="_blank" href="https://gogs.io">Website</a>
|
||||||
|
<span class="version">Go1.8</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/plugins/highlight-9.6.0/github.css">
|
||||||
|
<script src="/plugins/highlight-9.6.0/highlight.pack.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="/js/libs/emojify-1.1.0.min.js"></script>
|
||||||
|
<script src="/js/libs/clipboard-1.5.9.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,433 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head data-suburl="">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
|
||||||
|
<meta name="author" content="xdrm-brackets" />
|
||||||
|
<meta name="description" content="proxy.ftp.c" />
|
||||||
|
<meta name="keywords" content="go, git, self-hosted, gogs">
|
||||||
|
|
||||||
|
<meta name="referrer" content="no-referrer" />
|
||||||
|
<meta name="_csrf" content="sS0pasZdHndRhsO38JoAUyyuIWs6MTQ5MDcxOTc2NzE3OTU4NzUxOA==" />
|
||||||
|
<meta name="_suburl" content="" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<meta property="og:url" content="https://git.xdrm.io/xdrm-brackets/proxy.ftp.c" />
|
||||||
|
<meta property="og:type" content="object" />
|
||||||
|
<meta property="og:title" content="xdrm-brackets/proxy.ftp.c">
|
||||||
|
<meta property="og:description" content="">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="shortcut icon" href="/img/favicon.png" />
|
||||||
|
|
||||||
|
<script src="/js/jquery-1.11.3.min.js"></script>
|
||||||
|
<script src="/js/libs/jquery.are-you-sure.js"></script>
|
||||||
|
<link rel="stylesheet" href="/assets/font-awesome-4.6.3/css/font-awesome.min.css">
|
||||||
|
<link rel="stylesheet" href="/assets/octicons-4.3.0/octicons.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/css/semantic-2.2.7.min.css">
|
||||||
|
<link rel="stylesheet" href="/css/gogs.css?v=73519fd9811805bce6fc4aa2d24bb413">
|
||||||
|
|
||||||
|
|
||||||
|
<script src="/js/semantic-2.2.7.min.js"></script>
|
||||||
|
<script src="/js/gogs.js?v=73519fd9811805bce6fc4aa2d24bb413"></script>
|
||||||
|
|
||||||
|
<title>xdrm-brackets/proxy.ftp.c - xdrm-brackets' git server</title>
|
||||||
|
|
||||||
|
<meta name="theme-color" content="#ff5343">
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="full height">
|
||||||
|
<noscript>Please enable JavaScript in your browser!</noscript>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="following bar light">
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="column">
|
||||||
|
<div class="ui top secondary menu">
|
||||||
|
<a class="item brand" href="/">
|
||||||
|
<img class="ui mini image" src="/img/favicon.png">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="item" href="/">Home</a>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="item" href="/explore/repos">Explore</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a class="item" target="_blank" href="https://gogs.io/docs" rel="noreferrer">Help</a>
|
||||||
|
<div class="right menu">
|
||||||
|
|
||||||
|
<a class="item" href="/user/sign_up">
|
||||||
|
<i class="octicon octicon-person"></i> Register
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="item" href="/user/login?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.h">
|
||||||
|
<i class="octicon octicon-sign-in"></i> Sign In
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="repository file list">
|
||||||
|
<div class="header-wrapper">
|
||||||
|
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui vertically padded grid head">
|
||||||
|
<div class="column">
|
||||||
|
<div class="ui header">
|
||||||
|
<div class="ui huge breadcrumb">
|
||||||
|
<i class="mega-octicon octicon-repo"></i>
|
||||||
|
<a href="/xdrm-brackets">xdrm-brackets</a>
|
||||||
|
<div class="divider"> / </div>
|
||||||
|
<a href="/xdrm-brackets/proxy.ftp.c">proxy.ftp.c</a>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui right">
|
||||||
|
<div class="ui labeled button" tabindex="0">
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/watch?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.h">
|
||||||
|
<i class="icon fa-eye-slash"></i>Watch
|
||||||
|
</a>
|
||||||
|
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/watchers">
|
||||||
|
1
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="ui labeled button" tabindex="0">
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/star?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.h">
|
||||||
|
<i class="icon fa-star-o"></i>Star
|
||||||
|
</a>
|
||||||
|
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/stars">
|
||||||
|
0
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui labeled button" tabindex="0">
|
||||||
|
<a class="ui button " href="/repo/fork/49">
|
||||||
|
<i class="octicon octicon-repo-forked"></i>Fork
|
||||||
|
</a>
|
||||||
|
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/forks">
|
||||||
|
0
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="ui tabs container">
|
||||||
|
<div class="ui tabular menu navbar">
|
||||||
|
<a class="active item" href="/xdrm-brackets/proxy.ftp.c">
|
||||||
|
<i class="octicon octicon-file-text"></i> Files
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/issues">
|
||||||
|
<i class="octicon octicon-issue-opened"></i> Issues <span class="ui gray small label">0</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/pulls">
|
||||||
|
<i class="octicon octicon-git-pull-request"></i> Pull Requests <span class="ui gray small label">0</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/commits/master">
|
||||||
|
<i class="octicon octicon-history"></i> Commits <span class="ui blue small label">23</span>
|
||||||
|
</a>
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/releases">
|
||||||
|
<i class="octicon octicon-tag"></i> Releases <span class="ui gray small label">0</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/wiki">
|
||||||
|
<i class="octicon octicon-book"></i> Wiki
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui tabs divider"></div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ui container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p id="repo-desc">
|
||||||
|
<span class="no-description text-italic">No Description</span>
|
||||||
|
<a class="link" href=""></a>
|
||||||
|
</p>
|
||||||
|
<div class="ui secondary menu">
|
||||||
|
|
||||||
|
<div class="fitted item choose reference">
|
||||||
|
<div class="ui floating filter dropdown" data-no-results="No results found.">
|
||||||
|
<div class="ui basic small button">
|
||||||
|
<span class="text">
|
||||||
|
<i class="octicon octicon-git-branch"></i>
|
||||||
|
Branch:
|
||||||
|
<strong>master</strong>
|
||||||
|
</span>
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
</div>
|
||||||
|
<div class="menu">
|
||||||
|
<div class="ui icon search input">
|
||||||
|
<i class="filter icon"></i>
|
||||||
|
<input name="search" placeholder="Filter branch or tag...">
|
||||||
|
</div>
|
||||||
|
<div class="header">
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="two column row">
|
||||||
|
<a class="reference column" href="#" data-target="#branch-list">
|
||||||
|
<span class="text black">
|
||||||
|
<i class="octicon octicon-git-branch"></i> Branches
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<a class="reference column" href="#" data-target="#tag-list">
|
||||||
|
<span class="text ">
|
||||||
|
<i class="reference tags icon"></i> Tags
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="branch-list" class="scrolling menu" >
|
||||||
|
|
||||||
|
<div class="item selected" data-url="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h">master</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="tag-list" class="scrolling menu" style="display: none">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="fitted item">
|
||||||
|
<div class="ui breadcrumb">
|
||||||
|
<a class="section" href="/xdrm-brackets/proxy.ftp.c/src/master">proxy.ftp.c</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="divider"> / </div>
|
||||||
|
|
||||||
|
|
||||||
|
<span class="section"><a href="/xdrm-brackets/proxy.ftp.c/src/master/dep">dep</a></span>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="divider"> / </div>
|
||||||
|
|
||||||
|
<span class="active section">client.h</span>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="right fitted item">
|
||||||
|
|
||||||
|
<div id="file-buttons" class="ui tiny blue buttons">
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="file-content" class="tab-size-8">
|
||||||
|
<h4 class="ui top attached header" id="repo-read-file">
|
||||||
|
|
||||||
|
<i class="file text outline icon ui left"></i>
|
||||||
|
<strong>client.h</strong> <span class="text grey normal">1.0KB</span>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="ui right file-actions">
|
||||||
|
<div class="ui buttons">
|
||||||
|
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/src/18a5e4338baaec92912eee057d26004b57b0b2a0/dep/client.h">Permalink</a>
|
||||||
|
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/commits/master/dep/client.h">History</a>
|
||||||
|
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/raw/master/dep/client.h">Raw</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="You must fork this repository before editing the file" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||||
|
|
||||||
|
|
||||||
|
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="You must have write access to make or propose changes to this file" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</h4>
|
||||||
|
<div class="ui attached table segment">
|
||||||
|
<div id="" class="file-view code-view has-emoji">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<td class="lines-num"><span id="L1">1</span><span id="L2">2</span><span id="L3">3</span><span id="L4">4</span><span id="L5">5</span><span id="L6">6</span><span id="L7">7</span><span id="L8">8</span><span id="L9">9</span><span id="L10">10</span><span id="L11">11</span><span id="L12">12</span><span id="L13">13</span><span id="L14">14</span><span id="L15">15</span><span id="L16">16</span><span id="L17">17</span><span id="L18">18</span><span id="L19">19</span><span id="L20">20</span><span id="L21">21</span><span id="L22">22</span><span id="L23">23</span><span id="L24">24</span><span id="L25">25</span><span id="L26">26</span><span id="L27">27</span><span id="L28">28</span><span id="L29">29</span><span id="L30">30</span><span id="L31">31</span><span id="L32">32</span><span id="L33">33</span><span id="L34">34</span><span id="L35">35</span><span id="L36">36</span><span id="L37">37</span><span id="L38">38</span><span id="L39">39</span><span id="L40">40</span></td>
|
||||||
|
<td class="lines-code"><pre><code class=""><ol class="linenums"><li class="L1" rel="L1">/* Envoi d'une requête à un serveur et réception de la réponse</li>
|
||||||
|
<li class="L2" rel="L2">*</li>
|
||||||
|
<li class="L3" rel="L3">* @serverHost<char*> Nom de l'hôte distant (server)</li>
|
||||||
|
<li class="L4" rel="L4">* @serverPort<char*> Numéro du port distant (server)</li>
|
||||||
|
<li class="L5" rel="L5">* @pSocket<int*> Pointeur sur la requête à créer</li>
|
||||||
|
<li class="L6" rel="L6">*</li>
|
||||||
|
<li class="L7" rel="L7">*</li>
|
||||||
|
<li class="L8" rel="L8">* @return error<int> retourne -1 en cas d'erreur, sinon la SOCKET</li>
|
||||||
|
<li class="L9" rel="L9">*</li>
|
||||||
|
<li class="L10" rel="L10">*</li>
|
||||||
|
<li class="L11" rel="L11">* </li>
|
||||||
|
<li class="L12" rel="L12">* @history</li>
|
||||||
|
<li class="L13" rel="L13">* [1] On définit le filtre/format</li>
|
||||||
|
<li class="L14" rel="L14">* [2] On récupère les infos</li>
|
||||||
|
<li class="L15" rel="L15">* [3] Création de la socket</li>
|
||||||
|
<li class="L16" rel="L16">* [4] On établit la connection</li>
|
||||||
|
<li class="L17" rel="L17">* [5] On retourne la SOCKET</li>
|
||||||
|
<li class="L18" rel="L18">* </li>
|
||||||
|
<li class="L19" rel="L19">*/</li>
|
||||||
|
<li class="L20" rel="L20">int CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket);</li>
|
||||||
|
<li class="L21" rel="L21"></li>
|
||||||
|
<li class="L22" rel="L22"></li>
|
||||||
|
<li class="L23" rel="L23"></li>
|
||||||
|
<li class="L24" rel="L24">/* Envoi d'une requête vers une SOCKET et récupère la réponse</li>
|
||||||
|
<li class="L25" rel="L25">*</li>
|
||||||
|
<li class="L26" rel="L26">* @pSocket<int*> Pointeur sur la SOCKET en question</li>
|
||||||
|
<li class="L27" rel="L27">* @pRequest<char*> Requête à lui envoyer (swrite)</li>
|
||||||
|
<li class="L28" rel="L28">* @pAnswer<char**> Réponse qui se lira après la requête (sread)</li>
|
||||||
|
<li class="L29" rel="L29">*</li>
|
||||||
|
<li class="L30" rel="L30">* @return error<int> Retourne -1 en cas d'erreur</li>
|
||||||
|
<li class="L31" rel="L31">*</li>
|
||||||
|
<li class="L32" rel="L32">*</li>
|
||||||
|
<li class="L33" rel="L33">*</li>
|
||||||
|
<li class="L34" rel="L34">* @history</li>
|
||||||
|
<li class="L35" rel="L35">* [1] On écrit sur la socket</li>
|
||||||
|
<li class="L36" rel="L36">* [2] On attends et lit la réponse</li>
|
||||||
|
<li class="L37" rel="L37">* [3] On retourne la réponse par référence</li>
|
||||||
|
<li class="L38" rel="L38">* </li>
|
||||||
|
<li class="L39" rel="L39">*/</li>
|
||||||
|
<li class="L40" rel="L40">int CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer);</li>
|
||||||
|
</ol></code></pre></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function submitDeleteForm() {
|
||||||
|
var message = prompt("delete_confirm_message\n\ndelete_commit_summary", "Delete ''");
|
||||||
|
if (message != null) {
|
||||||
|
$("#delete-message").val(message);
|
||||||
|
$("#delete-file-form").submit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<div class="ui container">
|
||||||
|
<div class="ui left">
|
||||||
|
© 2017 Gogs Version: 0.10.10.0308 Page: <strong>53ms</strong> Template: <strong>1ms</strong>
|
||||||
|
</div>
|
||||||
|
<div class="ui right links">
|
||||||
|
|
||||||
|
<div class="ui language bottom floating slide up dropdown link item">
|
||||||
|
<i class="world icon"></i>
|
||||||
|
<div class="text">English</div>
|
||||||
|
<div class="menu">
|
||||||
|
|
||||||
|
<a class="item active selected" href="#">English</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=zh-CN">简体中文</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=zh-HK">繁體中文(香港)</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=zh-TW">繁體中文(台湾)</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=de-DE">Deutsch</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=fr-FR">Français</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=nl-NL">Nederlands</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=lv-LV">Latviešu</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=ru-RU">Русский</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=ja-JP">日本語</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=es-ES">Español</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=pt-BR">Português do Brasil</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=pl-PL">Polski</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=bg-BG">български</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=it-IT">Italiano</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=fi-FI">Suomalainen</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=tr-TR">Türkçe</a>
|
||||||
|
|
||||||
|
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=cs-CZ">čeština</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a href="/assets/librejs/librejs.html" style="display:none" data-jslicense="1">Javascript Licenses</a>
|
||||||
|
<a target="_blank" href="https://gogs.io">Website</a>
|
||||||
|
<span class="version">Go1.8</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/plugins/highlight-9.6.0/github.css">
|
||||||
|
<script src="/plugins/highlight-9.6.0/highlight.pack.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="/js/libs/emojify-1.1.0.min.js"></script>
|
||||||
|
<script src="/js/libs/clipboard-1.5.9.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
|
@ -0,0 +1,169 @@
|
||||||
|
#include "utility.h"
|
||||||
|
|
||||||
|
void splitFtpRequest(char* pRequest, char* pCommand, char* pContent){
|
||||||
|
/* [1] Vérification du format
|
||||||
|
===========================================*/
|
||||||
|
int firstSpaceIndex = indexOf(pRequest, ' ');
|
||||||
|
|
||||||
|
if( firstSpaceIndex != 3 && firstSpaceIndex != 4){ // contient aucun espace en position 3 ou 4, on quitte
|
||||||
|
strcpy(pCommand, "ERROR");
|
||||||
|
strcpy(pContent, "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] Séparation des 2 parties
|
||||||
|
===========================================*/
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = 0 ; i < strlen(pRequest) && pRequest[i] != '\0' ; i++ ){
|
||||||
|
|
||||||
|
if( i < firstSpaceIndex ) // première partie (pCommand)
|
||||||
|
strcat( pCommand, (char[2]){(char) pRequest[i], '\0'});
|
||||||
|
if( i > firstSpaceIndex ) // seconde partie (pContent)
|
||||||
|
strcat( pContent, (char[2]){(char) pRequest[i], '\0'});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText){
|
||||||
|
/* [1] Vérification du format
|
||||||
|
===========================================*/
|
||||||
|
int codeLength = 3; // taille du code
|
||||||
|
|
||||||
|
/* [2] Séparation des 2 parties
|
||||||
|
===========================================*/
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = 0 ; i < strlen(pAnswer) && pAnswer[i] != '\0' ; i++ ){
|
||||||
|
|
||||||
|
if( i < codeLength ) // première partie (ftpCode)
|
||||||
|
strcat(ftpCode, (char[2]){(char)pAnswer[i], '\0' });
|
||||||
|
if( i > codeLength ) // seconde partie (ftpText)
|
||||||
|
strcat(ftpText, (char[2]){(char)pAnswer[i], '\0' });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int indexOf(char* haystack, char needle){
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = 0 ; i < strlen(haystack) && haystack[i] != '\0' ; i++ )
|
||||||
|
if( haystack[i] == needle ) // si on trouve le caractère
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
/* 1. On écrit sur la SOCKET */
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* 2. Si on est déconnecté, on retourne une erreur */
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
/* 3. On retourne le nombre de <char> envoyés */
|
||||||
|
return nbSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int sread(int* pSocket, char* pBuffer){
|
||||||
|
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
||||||
|
|
||||||
|
|
||||||
|
/* 1. On vide le buffer avant de lire */
|
||||||
|
memset(pBuffer, '\0', maxBuffLen);
|
||||||
|
if( DEBUGMOD&BUF ) printf("READLEN_1: %lu\n", strlen(pBuffer));
|
||||||
|
|
||||||
|
/* 2. On lit la SOCKET */
|
||||||
|
int nbRead = read(*pSocket, pBuffer, maxBuffLen);
|
||||||
|
if( DEBUGMOD&BUF ) printf("READLEN_3: %d\n", nbRead);
|
||||||
|
|
||||||
|
|
||||||
|
/* 3. Si on est déconnecté, on retourne une erreur */
|
||||||
|
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");
|
||||||
|
|
||||||
|
/* 4. On retourne le nombre de caractères lus */
|
||||||
|
return nbRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec){
|
||||||
|
/* 1. On créé la structure contenant le timeout */
|
||||||
|
struct timeval timeout;
|
||||||
|
timeout.tv_sec = pSec;
|
||||||
|
timeout.tv_usec = pUSec;
|
||||||
|
|
||||||
|
setsockopt(*pSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(struct timeval));
|
||||||
|
|
||||||
|
if( DEBUGMOD&SCK ) printf("Set socket(%d) timeout to %lus\n", *pSocket, (long unsigned) timeout.tv_sec );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xPrint(char* pPattern, char* pBuffer){
|
||||||
|
char tmpBuffer[maxBuffLen];
|
||||||
|
strcpy(tmpBuffer, pBuffer);
|
||||||
|
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// on supprimes les retours à la ligne de la fin
|
||||||
|
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("[[%s]]\n", revealedString);
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* Découpe la requête FTP en 2 parties
|
||||||
|
*
|
||||||
|
* @pRequest<char*> La requête en question
|
||||||
|
*
|
||||||
|
* @pCommand<char*> Remplissage: commande (1ère partie)
|
||||||
|
* @pContant<char*> Remplissage: contenu (2ème partie)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void splitFtpRequest(char* pRequest, char* pCommand, char* pContent);
|
||||||
|
|
||||||
|
/* Découpe la réponse FTP en 2 parties
|
||||||
|
*
|
||||||
|
* @pAnswer<char*> La réponse en question
|
||||||
|
*
|
||||||
|
* @ftpCode<char*> Remplissage: code FTP (1ère partie)
|
||||||
|
* @ftpText<char*> Remplissage: text associé (2ème partie)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText);
|
||||||
|
|
||||||
|
|
||||||
|
/* Retourne le rang d'un caractère dans une string
|
||||||
|
*
|
||||||
|
* @haystack<char*> La chaîne dans laquelle rechercher
|
||||||
|
* @needle<char> Le caractère recherché
|
||||||
|
*
|
||||||
|
* @return position<int> Retourne l'index de @needle dans @haystack ou -1 si ne trouve pas
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int indexOf(char* haystack, char needle);
|
||||||
|
|
||||||
|
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec);
|
||||||
|
|
||||||
|
|
||||||
|
/* read/write socket */
|
||||||
|
int swrite(int* pSocket, char* pBuffer);
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
/* 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);
|
Loading…
Reference in New Issue