X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=examples%2Fchat.c;h=5d06538c3915a8a943ecfa7c2fde23a090513fa0;hb=92bae04187d9ecd7900b5a28154a2c046001a7f3;hp=88fe127a1df25368512078c89868a0dddc2336c6;hpb=9d23fe58052b3ef971305699a00ea6dbd1111744;p=meshlink-tiny diff --git a/examples/chat.c b/examples/chat.c index 88fe127..5d06538 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -2,7 +2,7 @@ #include #include #include -#include "../src/meshlink.h" +#include "../src/meshlink-tiny.h" static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { (void)mesh; @@ -41,9 +41,6 @@ static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool rea } } -static meshlink_node_t **nodes; -static size_t nnodes; - static void parse_command(meshlink_handle_t *mesh, char *buf) { char *arg = strchr(buf, ' '); @@ -51,24 +48,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { *arg++ = 0; } - if(!strcasecmp(buf, "invite")) { - char *invitation; - - if(!arg) { - fprintf(stderr, "/invite requires an argument!\n"); - return; - } - - invitation = meshlink_invite(mesh, NULL, arg); - - if(!invitation) { - fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); - return; - } - - printf("Invitation for %s: %s\n", arg, invitation); - free(invitation); - } else if(!strcasecmp(buf, "join")) { + if(!strcasecmp(buf, "join")) { if(!arg) { fprintf(stderr, "/join requires an argument!\n"); return; @@ -86,68 +66,6 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { fprintf(stderr, "Could not restart MeshLink: %s\n", meshlink_strerror(meshlink_errno)); exit(1); } - } else if(!strcasecmp(buf, "kick")) { - if(!arg) { - fprintf(stderr, "/kick requires an argument!\n"); - return; - } - - meshlink_node_t *node = meshlink_get_node(mesh, arg); - - if(!node) { - fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); - return; - } - - if(!meshlink_blacklist(mesh, node)) { - fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno)); - return; - } - - printf("Node '%s' blacklisted.\n", arg); - } else if(!strcasecmp(buf, "whitelist")) { - if(!arg) { - fprintf(stderr, "/whitelist requires an argument!\n"); - return; - } - - meshlink_node_t *node = meshlink_get_node(mesh, arg); - - if(!node) { - fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); - return; - } - - if(!meshlink_whitelist(mesh, node)) { - fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno)); - return; - } - - printf("Node '%s' whitelisted.\n", arg); - } else if(!strcasecmp(buf, "who")) { - if(!arg) { - nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes); - - if(!nnodes) { - fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno)); - } else { - printf("%zu known nodes:", nnodes); - - for(size_t i = 0; i < nnodes; i++) { - printf(" %s", nodes[i]->name); - } - - printf("\n"); - } - } else { - meshlink_node_t *node = meshlink_get_node(mesh, arg); - - if(!node) { - fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); - } else { - printf("Node %s found\n", arg); - } - } } else if(!strcasecmp(buf, "quit")) { printf("Bye!\n"); fclose(stdin); @@ -155,7 +73,6 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { printf( ": Send a message to the given node.\n" " Subsequent messages don't need the : prefix.\n" - "/invite Create an invitation for a new node.\n" "/join Join an existing mesh using an invitation.\n" "/kick Blacklist the given node.\n" "/who [] List all nodes or show information about the given node.\n"