Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa28a6b
commit 37772a1
Showing
13 changed files
with
223 additions
and
103 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
NOMBRE=ARCHIVO | ||
IP=127.0.0.1 | ||
PUERTO=4444 | ||
CLAVE=VALOR | ||
CLAVE=Hola, soy un valor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Como nos conviene armar un makefile? | ||
# Primero podemos definir algunas constantes que vamos a usar muchas veces | ||
# Como por ejemplo, bibliotecas, flags, el compilador (el "CC") | ||
|
||
TARGET = tp0 # Definimos la tarea que va a ejecutar make por defecto Y el nombre del binario final | ||
LIBS = -lcrypto -lcommons # Incluimos las bibliotecas que necesitamos, las commos y la biblio para el MD5 | ||
CC = gcc # Vamos a usar gcc como compilador, porque nos encanta! | ||
CFLAGS = -g -Wall # Compilamos con los flags -g (con simbolos de debug) y -Wall (que nos muestre todos los warnings) | ||
|
||
# Ahora creemos las tareas del makefile | ||
# Cuando hagamos make sin argumentos, se ejecutará la tarea por default | ||
# Mientras que si le pasamos un argumento, ejecutará la tarea con ese nombre | ||
# como por ejemplo make all o make clean | ||
|
||
.PHONY: default all clean | ||
# Esta regla .PHONY es para decirle a make que si hay archivos con nombres similares | ||
# a alguna regla, que entonces no asuma que el argumento es el archivo, sino que es la regla | ||
# dado que va a tratar de tomar el archivo y no la regla por defecto | ||
|
||
default: $(TARGET) # la regla por defecto (tp0) | ||
all: default # Si ejecutan all, que ejecute la default | ||
|
||
# Definamos un par de constantes mas, OBJECTS (que vamos a usar para generar los .o) | ||
# y HEADERS, para incluir los headers que definamos. | ||
# Nota: wildcard implica que seleccione todos los que cumplen con la regex (osea todos los que terminen con .h) | ||
|
||
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) | ||
HEADERS = $(wildcard *.h) | ||
|
||
%.o: %.c $(HEADERS) # Las variables que le pasamos a la tarea, le decimos que use todos los .c y todos los .h | ||
$(CC) $(CFLAGS) -c $< -o $@ # Creamos los objects sin linkear | ||
|
||
.PRECIOUS: $(TARGET) $(OBJECTS) # Nos permite mantener los archivos temporales terminados si matan a make con Cntl-C | ||
|
||
$(TARGET): $(OBJECTS) # Le pasamos a la tarea los objects ya compilados | ||
$(CC) $(OBJECTS) $(CFLAGS) $(LIBS) -o $@ # Usamos el compilador para linkear los objects a las bibliotecas y tener nuestro binario | ||
|
||
clean: # Finalmente creamos una tarea para eliminar todos los .o y el binario | ||
-rm -f *.o | ||
-rm -f $(TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* main.c | ||
* | ||
* Created on: 28 feb. 2019 | ||
* Author: utnso | ||
*/ | ||
|
||
#include "tp0.h" | ||
|
||
int main(void) | ||
{ | ||
t_log* logger; | ||
t_config* config; | ||
int conexion; | ||
|
||
iniciar_logger(logger); | ||
|
||
leer_config(config, logger); | ||
|
||
//antes de poder hacer esta parte, vas a tener que incluir en "tp0.h" readline (vease el enunciado), y agregar la biblioteca al proyecto de Eclipse | ||
//Lo vamos a estar explicando en la puesta en comun. Si te adelantaste, llamá a un ayudante! | ||
leer_consola(logger); | ||
|
||
//antes de continuar, tenemos que asegurarnos que el servidor esté corriendo porque lo necesitaremos para lo que sigue. | ||
//Una vez hecho eso, tenemos que conectarnos a él! Las conexiones se representan mediante enteros por cosas que hablaremos más adelante | ||
conexion = conectar_cliente(config); | ||
|
||
enviar_clave(config, conexion); | ||
|
||
paquete(conexion); | ||
|
||
terminar_programa(logger, config, conexion); | ||
} | ||
|
||
void iniciar_logger(t_log* logger) | ||
{ | ||
//creemos el log! Este se debe crear con el nombre "tp0.log", se debe mostrar por consola y debe estar en el nivel INFO | ||
//logger = log_create(/*nombre del archivo, nombre del programa, 1 para mostrar por consona 0 caso contrario, nivel de log deseado */); | ||
|
||
//logeemos el mensaje "Soy un log" | ||
//log_info(/*logger, mensaje*/); | ||
} | ||
|
||
void leer_config(t_config* config, t_log* logger) | ||
{ | ||
char* valor; | ||
|
||
//ahora, vamos a abrir el archivo de configuracion "tp0.config" | ||
//config = config_create(/*path*/); | ||
|
||
//tenemos que levantar en valor asociado a la clave "CLAVE" del archivo y asignarselo a la variable valor | ||
//config_get_string_value(/*config, clave*/); | ||
|
||
//Por último, logeame ese valor :) | ||
} | ||
|
||
void leer_consola(t_log* logger) | ||
{ | ||
char* leido; | ||
|
||
//aca vas a tener que asignarle lo que devuelve readline a 'leido' y loggearlo hasta que eso sea nulo. Te doy uno pista: No es con un for ;) | ||
//readline(">"); | ||
|
||
//Loggeamelo | ||
|
||
//Y no te olvides de liberar la memoria antes de volver al readline! | ||
//free(/*puntero a liberar*/); | ||
} | ||
|
||
int conectar_cliente(t_config* config) | ||
{ | ||
int conexion; | ||
char* ip; | ||
char* puerto; | ||
|
||
//Primero, hay que conseguir la ip y el puerto del servidor. Ya te las dejamos en el archivo de configuracion, asi que ahora toca levantarlas | ||
//las claves son PUERTO e IP | ||
|
||
|
||
//hecho esto, ahora toca conectarnos. No te olvides de asignarle el entero que devuelve a conexion! | ||
//crear_conexion(/*ip, puerto*/); | ||
|
||
return conexion; | ||
} | ||
|
||
void enviar_clave(t_config* config, int conexion) | ||
{ | ||
char* valor; | ||
|
||
//ahora que tenemos la conexion, es hora de empezar a enviar cosas. Primero, el mensaje. | ||
//Levantá el valor que le corresponde a CLAVE del archivo de configuracion de nuevo. | ||
|
||
//Ahora le podés mandar el mensaje al servidor! | ||
//enviar_mensaje(/*mensaje, entero de conexion*/) | ||
} | ||
|
||
void paquete(int conexion) | ||
{ | ||
//Ahora toca lo divertido! | ||
|
||
char* leido; | ||
t_paquete* paquete = crear_paquete(); | ||
|
||
|
||
//De nuevo vas a tener que usar readline hasta que te llegue un nulo igual que antes, solo que ahora vas a agregar esa cadena al paquete! | ||
//Recomiendo revisar bien el enunciado del TP ya que ahi está explicado con detalles | ||
|
||
//agregar_a_paquete(/*paquete, mensaje, tamanio*/); | ||
|
||
//Una vez hayamos terminado, toca enviarlo | ||
//enviar_paquete(/*paquete, conexion*/); | ||
|
||
//Y no nos olvidemos de borrar el paquete con eliminar_paquete | ||
} | ||
|
||
void terminar_programa(t_log* logger, t_config* config, int conexion) | ||
{ | ||
//Y por ultimo, para cerrar, hay que liberar estas cosas con las funciones de las commons y del TP mencionadas en el enunciado | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Cliente.h | ||
* | ||
* Created on: 28 feb. 2019 | ||
* Author: utnso | ||
*/ | ||
|
||
#ifndef TP0_H_ | ||
#define TP0_H_ | ||
|
||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<commons/log.h> | ||
#include<commons/string.h> | ||
#include<commons/config.h> | ||
|
||
#include "utils.h" | ||
|
||
void iniciar_logger(t_log*); | ||
void leer_config(t_config*, t_log*); | ||
void leer_consola(t_log*); | ||
void enviar_clave(t_config*, int); | ||
int conectar_cliente(t_config*); | ||
void paquete(int); | ||
void terminar_programa(t_log*, t_config*, int); | ||
|
||
#endif /* TP0_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: servidor.c utils.c | ||
gcc servidor.c utils.c -o Server -lcommons |
Oops, something went wrong.