diff --git a/SO-1920-EnunciadoTP-v.9i.pdf b/SO-1920-EnunciadoTP-v.9i.pdf new file mode 100644 index 0000000..836c05a Binary files /dev/null and b/SO-1920-EnunciadoTP-v.9i.pdf differ diff --git a/dec.h b/dec.h new file mode 100644 index 0000000..bc1af6a --- /dev/null +++ b/dec.h @@ -0,0 +1 @@ +int obtem_rand(int min, int max); \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..801ee2d --- /dev/null +++ b/makefile @@ -0,0 +1,27 @@ +# Usage: +# make # compile all binary +# make clean # remove ALL binaries and objects + +.PHONY = all clean + +# compiler to use +CC = gcc + +LINKERFLAG = -lm + +SRCS := $(wildcard *.c) +BINS := $(SRCS:%.c=%) + +all: ${BINS} + +%: %.o + @echo "Checking.." + ${CC} ${LINKERFLAG} $< -o $@ + +%.o: %.c + @echo "Creating object.." + ${CC} -c $< + +clean: + @echo "Cleaning up..." + rm -rvf *.o ${BINS} \ No newline at end of file diff --git a/server.c b/server.c new file mode 100644 index 0000000..c2f17b2 --- /dev/null +++ b/server.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +//declaraao de funcoes +#include "dec.h" +//estructuras e outras coisas uteis +#include "util.h" + +int main(int argc, char *argv[]){ + + int fd_servidor; + /* VERIFICAR SE EXISTE "CP" DO SERVIDOR (access) -- APENAS UM!!!*/ + if(access("CPservidor", F_OK)==0){ + printf("[SERVIDOR] Ja existe um servidor!\n"); + exit(1); + } + /* CRIAR "CP" DO SERVIDOR - MINHA (mkfifo) */ + mkfifo("CPservidor", 0600); + /* ABRIR "CP" DO SERVIDOR - MINHA (open - O_RDONLY) */ + fd_servidor = open("CPservidor", O_RDWR); + + printf("[SERVER] Servidor Iniciado!\n"); + + /* Fazer coisas aqui! */ + do{ + + }while(true); + + printf("[SERVIDOR] SERVIDOR DESLIGADO\n"); + + /* FECHAR "CP" DO SERVIDOR - MINHA (close) */ + close(fd_servidor); + /* REMOVER "CP" DO SERVIDOR- MINHA (UNLINK) */ + unlink("CPservidor"); + exit(0); +} + +int obtem_rand(int min, int max){ + int random; + random = min + (rand() % (max - min + 1)); + return random; +} \ No newline at end of file diff --git a/util.h b/util.h new file mode 100644 index 0000000..6321896 --- /dev/null +++ b/util.h @@ -0,0 +1,23 @@ +#define TAM_TITULO 128 +#define TAM_CORPO 1001 +#define TAM_NOME 100 + +typedef struct msgdef +{ + int id; + char titulo[TAM_TITULO]; + char corpo[TAM_CORPO]; + int duracao; + int time_added; + + struct topicdef * topico; + struct msgdef * prox; +}msg; + +typedef struct topicdef +{ + int id; + char nome[TAM_NOME]; + struct msgdef * mensg; + struct topicdef * prox; +}topic; diff --git a/verificador.c b/verificador.c new file mode 100644 index 0000000..8de53b7 --- /dev/null +++ b/verificador.c @@ -0,0 +1,87 @@ +/* verificador.c */ + +#include +#include +#include +#include + + +/* maximum word def */ +#define MAXNW 50 +/* maximum word length including \0 */ +#define MAXWL 19 + +/* This function does what its name tells */ +void exitNow(int s) { + exit(0); +} + +/* reads forbidden word list from file */ +/* assume all words have at most 19 chars */ +/* file must not have more than one word per line */ +/* return number of word read */ +int readWordFile(FILE * f, char wdef[][MAXWL], int maxw) { + int numw = 0; + while (!feof(f) && numw < maxw) + if (fscanf(f,"%s", wdef[numw])>0) + numw++; + return numw; +} + +/* checks word agains forbidden word dictionary */ +/* word must match exactly - partials do not count */ +/* returns 0 or 1*/ +int checkWord(char * word, char wdef[][MAXWL], int maxw) { + int i; + for (i=0; i