X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=examples%2Fchatpp.cc;h=f21e96dee2003d7d1cbe8913e3b2987999102473;hb=1c31a5dc4b17c274aac48444a3fe0da35a2b409c;hp=864a3e809b7258d20f8dcc7dcf561d3bb4c1d4aa;hpb=a67bc2279c8a562c9b162a75c7cfd09e2a59d17f;p=meshlink diff --git a/examples/chatpp.cc b/examples/chatpp.cc index 864a3e80..f21e96de 100644 --- a/examples/chatpp.cc +++ b/examples/chatpp.cc @@ -27,6 +27,9 @@ static void node_status(meshlink::mesh *mesh, meshlink::node *node, bool reachab printf("%s left.\n", node->name); } +static meshlink::node **nodes; +static size_t nnodes; + static void parse_command(meshlink::mesh *mesh, char *buf) { char *arg = strchr(buf, ' '); if(arg) @@ -42,7 +45,7 @@ static void parse_command(meshlink::mesh *mesh, char *buf) { invitation = mesh->invite(arg); if(!invitation) { - fprintf(stderr, "Could not invite '%s': %s\n", arg, mesh->errstr); + fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink::strerror()); return; } @@ -55,7 +58,7 @@ static void parse_command(meshlink::mesh *mesh, char *buf) { } if(!mesh->join(arg)) - fprintf(stderr, "Could not join using invitation: %s\n", mesh->errstr); + fprintf(stderr, "Could not join using invitation: %s\n", meshlink::strerror()); else fprintf(stderr, "Invitation accepted!\n"); } else if(!strcasecmp(buf, "kick")) { @@ -66,7 +69,7 @@ static void parse_command(meshlink::mesh *mesh, char *buf) { meshlink::node *node = mesh->get_node(arg); if(!node) { - fprintf(stderr, "Unknown node '%s'\n", arg); + fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink::strerror()); return; } @@ -75,22 +78,19 @@ static void parse_command(meshlink::mesh *mesh, char *buf) { printf("Node '%s' blacklisted.\n", arg); } else if(!strcasecmp(buf, "who")) { if(!arg) { - meshlink::node *nodes[100]; - size_t n = mesh->get_all_nodes(nodes, 100); - if(!n) { - fprintf(stderr, "No nodes known!\n"); + nodes = mesh->get_all_nodes(nodes, &nnodes); + if(!nodes) { + fprintf(stderr, "Could not get list of nodes: %s\n", meshlink::strerror()); } else { - printf("Known nodes:"); - for(int i = 0; i < n && i < 100; i++) + printf("%d known nodes:", nnodes); + for(size_t i = 0; i < nnodes; i++) printf(" %s", nodes[i]->name); - if(n > 100) - printf(" (and %zu more)", n - 100); printf("\n"); } } else { meshlink::node *node = mesh->get_node(arg); if(!node) { - fprintf(stderr, "Unknown node '%s'\n", arg); + fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink::strerror()); } else { printf("Node %s found\n", arg); } @@ -153,7 +153,7 @@ static void parse_input(meshlink::mesh *mesh, char *buf) { destination = mesh->get_node(buf); if(!destination) { - fprintf(stderr, "Unknown node '%s'\n", buf); + fprintf(stderr, "Error looking up '%s': %s\n", buf, meshlink::strerror()); return; } } @@ -164,7 +164,7 @@ static void parse_input(meshlink::mesh *mesh, char *buf) { } if(!mesh->send(destination, msg, strlen(msg) + 1)) { - fprintf(stderr, "Could not send message to '%s': %s\n", destination->name, mesh->errstr); + fprintf(stderr, "Could not send message to '%s': %s\n", destination->name, meshlink::strerror()); return; } @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) { meshlink::mesh *mesh = meshlink::open(confbase, nick); if(!mesh) { - fprintf(stderr, "Could not open MeshLink!\n"); + fprintf(stderr, "Could not open MeshLink: %s\n", meshlink::strerror()); return 1; } @@ -193,7 +193,7 @@ int main(int argc, char *argv[]) { mesh->set_log_cb(MESHLINK_INFO, log_message); if(!mesh->start()) { - fprintf(stderr, "Could not start MeshLink: %s\n", mesh->errstr); + fprintf(stderr, "Could not start MeshLink: %s\n", meshlink::strerror()); return 1; }