diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..05dd360 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "gcc-8 build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "/home/zmiguel/TP/${fileBasenameNoExtension}", + "args": [], + "stopAtEntry": false, + "cwd": "/home/zmiguel/TP", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "gcc-8 build active file", + "miDebuggerPath": "/usr/bin/gdb" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5cf0927 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "gcc-8 build active file", + "command": "/usr/bin/gcc-8", + "args": [ + "-g", + "${file}", + "-o", + "/home/zmiguel/TP/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "/usr/bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": "build" + } + ] +} \ No newline at end of file diff --git a/client b/client deleted file mode 100644 index f4930cf..0000000 Binary files a/client and /dev/null differ diff --git a/client.c b/client.c index 23f2504..fb54aa3 100644 --- a/client.c +++ b/client.c @@ -15,7 +15,7 @@ int main(int argc, char *argv[]){ int sair=0, test=-1; - char str[80], *palavra[10], *username[30]; + char str[80], *palavra[10], username[30]; int i; cl2sv msg2sv; @@ -111,7 +111,7 @@ int main(int argc, char *argv[]){ i = write(fd_servidor, &msg2sv, sizeof(msg2sv)); }else if(strcmp(palavra[0],"verifica")==0){ strcpy(msg2sv.cmd, "verifica"); - strcpy(msg2sv.opts,palavra[1]); + strcpy(msg2sv.opts, palavra[1]); /* ENVIAR PEDIDO PARA "CP" DO SERVIDOR (write) */ i = write(fd_servidor, &msg2sv, sizeof(msg2sv)); //ler resposta do servidor diff --git a/dec.h b/dec.h index 7e2982d..98c5c8a 100644 --- a/dec.h +++ b/dec.h @@ -6,4 +6,5 @@ char *getUsernameFromfifo(clients *users, char *fifo); void listusers(clients *users); void closeapp(int sig); void desligarClientes(clients *users); -clients *removeUser(clients *users, char *cp, int *nUsers); \ No newline at end of file +clients *removeUser(clients *users, char *cp, int *nUsers); +void verificador(char *verify); \ No newline at end of file diff --git a/server b/server deleted file mode 100644 index 9f67cd3..0000000 Binary files a/server and /dev/null differ diff --git a/server.c b/server.c index 6dc6786..1167c9a 100644 --- a/server.c +++ b/server.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -27,7 +29,7 @@ int main(int argc, char *argv[]){ int userCounter = 0; srand(time(NULL)); - int fd_servidor, fd_cliente, fd_child[2]; + int fd_servidor, fd_cliente; /* VERIFICAR SE EXISTE "CP" DO SERVIDOR (access) -- APENAS UM!!!*/ if(access("CPservidor", F_OK)==0){ printf("[SERVIDOR] Ja existe um servidor!\n"); @@ -93,21 +95,7 @@ int main(int argc, char *argv[]){ printf("[SERVER] Cliente removido!\n"); uinit = users; }else if(strcmp(clResp.cmd,"verifica")==0){ - printf("[SERVER] A verificar '%s'\n",clResp.opts); - pipe(fd_child); - switch(fork()){ - case 0://child - close(fd_child[1]); - dup2(fd_child[0], STDIN_FILENO); - close(fd_child[0]); - execl("verificador", "./verificador", "words.txt", NULL); - default://me - close(fd_child[0]); - write(fd_child[1], clResp.opts, sizeof(clResp.opts)); - close(fd_child[1]); - wait(NULL); - } - + verificador(clResp.opts); } }while(sair==0); @@ -168,7 +156,7 @@ clients *addUser(clients *users, int *nUsers, char *username, int pid, char *fif char *getUsernameFromfifo(clients *users, char *fifo){ clients *uinit = users; - char send[100]; + char *send = malloc(sizeof(char)*100); while(users!=NULL){ if(strcmp(users->fifostr,fifo)==0){ strcpy(send,users->nome); @@ -219,4 +207,33 @@ clients *removeUser(clients *users, char *cp, int *nUsers){ } } return uinit; +} + +void verificador(char *verify){ + int fd_child[2], estado; + + pipe(fd_child); + switch(fork()){ + case 0://child + /*close(fd_child[1]); + dup2(fd_child[0], STDIN_FILENO); + close(fd_child[0]);*/ + close(0); + dup(fd_child[0]); + close(fd_child[1]); + close(fd_child[0]); + execl("verificador", "./verificador", "words.txt", NULL); + break; + default://me + /*close(fd_child[0]); + write(fd_child[1], clResp.opts, sizeof(clResp.opts)); + close(fd_child[1]);*/ + close(1); + dup(fd_child[1]); + printf("%s\n",verify); + close(fd_child[0]); + close(fd_child[1]); + close(1); + wait(&estado); + } } \ No newline at end of file diff --git a/util.h b/util.h index f26af8f..4daa8b9 100644 --- a/util.h +++ b/util.h @@ -14,16 +14,18 @@ typedef struct st_mensagem{ int duracao; int time_added; - struct topic * topico; - struct mensagem * prox; + struct st_topic * topico; + struct st_mensagem * prox; }mensagem; typedef struct st_topic{ int id; char nome[TAM_NOME]; - struct mensagem * mensg; - struct topic * prox; + struct st_mensagem * mensg; + struct st_topic * prox; }topic; + + //guardar clientes typedef struct st_clients{ int pid; @@ -31,7 +33,7 @@ typedef struct st_clients{ char fifostr[TAM_NOME]; int topics[TAM_SUB]; - struct clients *prox; + struct st_clients *prox; }clients; //estructura dados de cliente --> servidor diff --git a/verificador b/verificador deleted file mode 100644 index adce2ee..0000000 Binary files a/verificador and /dev/null differ