diff --git a/parser.h b/parser.h new file mode 100644 index 0000000..b7694e0 --- /dev/null +++ b/parser.h @@ -0,0 +1,41 @@ +#include +#include + +enum cmd_type { + NEIGHBOUR_REQ, NETWORK_STATE_REQ, NODE_STATE_REQ, SEND, ERROR +}; + +struct cmd_token { + enum cmd_type type; + char arg[193]; +}; + +// retourne le type de commande à exécuter +struct cmd_token parse_cmd() { + char buf[198], cmd[5], arg[193]; + struct cmd_token token; + token.type = ERROR; + memset(token.arg, 0, 193); + + if(fgets(buf, 198, stdin) == NULL) + return token; + + // cmd sera le premier mot rencontré et arg la suite de mots après celui ci, si les deux variables ne sont pas remplies alors il y a une erreur + if(sscanf(buf, "%s %[^\t\n]", cmd, arg) != 2) + return token; + + if(strcmp("req", cmd) == 0) { + if(strcmp("neighbour", arg) == 0) + token.type = NEIGHBOUR_REQ; + else if(strcmp("network state", arg) == 0) + token.type = NETWORK_STATE_REQ; + else if(strcmp("node state", arg) == 0) + token.type = NODE_STATE_REQ; + } else if(strcmp("send", cmd) == 0) { + token.type = SEND; + //arg[192] = 0; + strcpy(token.arg, arg); + } + + return token; +} \ No newline at end of file diff --git a/tlv.h b/tlv.h index 105b198..9fbbf07 100644 --- a/tlv.h +++ b/tlv.h @@ -1,5 +1,6 @@ #include #include +#include "parser.h" // 8 octets min (struct pointer 4 octets), 1024 octets max typedef struct packet { @@ -93,4 +94,27 @@ typedef struct warning { unsigned char type; unsigned char length; char *message; -} warning; \ No newline at end of file +} warning; + +// creer un tlv +void build_tlv(tlv *t) { + struct cmd_token token = parse_cmd(); + + switch(token.type) { + case NEIGHBOUR_REQ: + // a remplir + break; + case NETWORK_STATE_REQ: + // a remplir + break; + case NODE_STATE_REQ: + // a remplir + break; + case SEND: + // a remplir + break; + case ERROR: + printf("Wrong format, use 'req {neighbour | network state | node state}' or 'send {message}'"); + break; + } +} \ No newline at end of file