1
0
mirror of https://github.com/thearcanum/WIFSS synced 2025-07-26 00:00:37 +02:00
This commit is contained in:
HorlogeSkynet
2015-05-09 13:57:05 +02:00
parent 7cf1594c78
commit 8fa1866a54
4 changed files with 65 additions and 21 deletions

@@ -27,11 +27,14 @@ typedef char bool;
bool keepGoing;
//FCT
void initialisation(struct sockaddr_in*, int*, bool*);
void disconnect(int);
int str_beginwith(const char*, const char*);
int upload(const char*, int);
int download(const char*, int);
//THREAD
void* scom(void*);

@@ -2,16 +2,24 @@
#define __COM_H
//ACK
#define OK "ok"
#define END "quit"
#define ENDT "ENDT"
#define FAIL "fail"
#define LIST "list"
#define ENDT "ENDT"
//CMD
#define QUIT "quit"
#define STOP "stop"
#define PRESENT "present"
#define FINISHED "finished"
#define UPLOAD "upload"
#define DOWNLOAD "download"
#define ISPRESENT "ispresent"
//COM
#define LIST "list"
#define PRESENT "present"
#define FINISHED "finished"
//SIG
#define ENDSIG -1
#define ASKFILE 1
#define FILEDWL 2

@@ -1,16 +1,47 @@
#include <client.h>
void handle_command(const char *command, int sock)
void handle_command(const char *command, int sock, bool *connected)
{
/* si download, quit, etc ... */
if(str_beginwith(command, QUIT))
{
printf("\n\nLet's close connection with Server...");
*connected = false;
}
else if(str_beginwith(command, DOWNLOAD))
{
char _path[BUFFER] = {0};
printf("File to download: ");
scanf("%s", _path);
if(!download(_path, sock))
{
printf("File couldn't be downloaded correctly.\n\n");
}
else
{
printf("File downloaded !\n\n");
}
}
/*else if()
{
}*/
else
{
printf("\nCommand unknown.\n");
}
}
int main(void)
{
int sock;
struct sockaddr_in SERVER;
bool connected;
char buff[BUFFER];
unsigned short int _i;
struct sockaddr_in SERVER;
pthread_t sthread;
@@ -20,21 +51,23 @@ int main(void)
pthread_create(&sthread, NULL, &scom, (void*)&sock);
keepGoing = true;
while(keepGoing && connected)
{
memset(buff, 0, BUFFER);
printf("|: ");
scanf("%s", buff);
// send(sock, buff, BUFFER, 0);
handle_command(buff, sock);
if(!strcmp(buff, END))
//send(sock, buff, BUFFER, false);
//
for(_i = 0; _i < strlen(buff) && buff[_i] != ' '; _i++) //On passe en minuscule le premier terme
{
keepGoing = false;
printf("\n\nLet's close connection with Server...");
buff[_i] = tolower(buff[_i]);
}
handle_command(buff, sock, &connected);
//
}

@@ -19,7 +19,7 @@ int str_beginwith(const char *w, const char *s)
void* scom(void *data)
{
int sock;
int res;
int result;
char buff[BUFFER] = {0};
sock = *((int*)data);
@@ -28,22 +28,22 @@ void* scom(void *data)
while(keepGoing)
{
memset(buff, 0, BUFFER);
res = recv(sock, buff, BUFFER, 0);
result = recv(sock, buff, BUFFER, 0);
/* Ici on reçoit des choses du serveur */
if(str_beginwith(buff, "upload"))
if(str_beginwith(buff, UPLOAD))
{
/* Le serv demande d'upload un fichier
on l'envoie au serveur via la fonction upload */
char path[BUFFER] = {0};
sscanf(buff, "upload %s", path);
sscanf(buff, "Upload %s", path);
printf("Server is asking us to upload: %s\n", path);
upload(path, sock);
}
if(res <= 0)
if(result <= 0)
{
keepGoing = false;
//keepGoing = false;
return NULL;
}