From: Guus Sliepen Date: Sat, 5 Oct 2019 12:34:40 +0000 (+0200) Subject: Add the /whitelist command to the chat examples. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=ac63b6adaf29c4143f9e106039011b9ebeb96b93;p=meshlink Add the /whitelist command to the chat examples. This allows undoing a /kick. --- diff --git a/examples/channels.c b/examples/channels.c index d4e378f6..70c27004 100644 --- a/examples/channels.c +++ b/examples/channels.c @@ -139,6 +139,22 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { meshlink_blacklist(mesh, node); 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; + } + + meshlink_whitelist(mesh, node); + + printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { if(!arg) { nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes); diff --git a/examples/chat.c b/examples/chat.c index d0e511ca..77ba59e6 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -102,6 +102,22 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { meshlink_blacklist(mesh, node); 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; + } + + meshlink_whitelist(mesh, node); + + printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { if(!arg) { nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes); diff --git a/examples/groupchat.c b/examples/groupchat.c index 38bbd85b..7a5a300f 100644 --- a/examples/groupchat.c +++ b/examples/groupchat.c @@ -230,6 +230,22 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { meshlink_blacklist(mesh, node); fprintf(stderr, "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; + } + + meshlink_whitelist(mesh, node); + + fprintf(stderr, "Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { meshlink_submesh_t *node_group = NULL; diff --git a/examples/manynodes.c b/examples/manynodes.c index 3d82bd31..fbfd215f 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -251,6 +251,22 @@ static void parse_command(char *buf) { meshlink_blacklist(mesh[nodeindex], node); 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[nodeindex], arg); + + if(!node) { + fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno)); + return; + } + + meshlink_whitelist(mesh[nodeindex], node); + + printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { if(!arg) { nodes = meshlink_get_all_nodes(mesh[nodeindex], nodes, &nnodes);