]> git.meshlink.io Git - meshlink/blobdiff - examples/chat.c
Don't install the example programs.
[meshlink] / examples / chat.c
index 3eaa5c7e3b3fe5ef093b7955d0db011cf15591f0..f5f41c936126c98393e1e53c1792d8e7267b2357 100644 (file)
@@ -65,12 +65,11 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
                meshlink_stop(mesh);
                if(!meshlink_join(mesh, arg))
                        fprintf(stderr, "Could not join using invitation: %s\n", meshlink_strerror(meshlink_errno));
-               else {
+               else
                        fprintf(stderr, "Invitation accepted!\n");
-                       if(!meshlink_start(mesh)) {
-                               fprintf(stderr, "Could not start MeshLink: %s\n", meshlink_strerror(meshlink_errno));
-                       return;
-                       }
+               if(!meshlink_start(mesh)) {
+                       fprintf(stderr, "Could not restart MeshLink: %s\n", meshlink_strerror(meshlink_errno));
+                       exit(1);
                }
        } else if(!strcasecmp(buf, "kick")) {
                if(!arg) {
@@ -90,9 +89,9 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
        } else if(!strcasecmp(buf, "who")) {
                if(!arg) {
                        nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes);
-                       if(!nnodes) {
+                       if(!nnodes)
                                fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
-                       else {
+                       else {
                                printf("%zu known nodes:", nnodes);
                                for(int i = 0; i < nnodes; i++)
                                        printf(" %s", nodes[i]->name);
@@ -100,28 +99,26 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
                        }
                } else {
                        meshlink_node_t *node = meshlink_get_node(mesh, arg);
-                       if(!node) {
+                       if(!node)
                                fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
-                       } else {
+                       else
                                printf("Node %s found\n", arg);
-                       }
                }
        } else if(!strcasecmp(buf, "quit")) {
                printf("Bye!\n");
                fclose(stdin);
        } else if(!strcasecmp(buf, "help")) {
                printf(
-                       "<name>: <message>     Send a message to the given node.\n"
-                       "                      Subsequent messages don't need the <name>: prefix.\n"
-                       "/invite <name>        Create an invitation for a new node.\n"
-                       "/join <invitation>    Join an existing mesh using an invitation.\n"
-                       "/kick <name>          Blacklist the given node.\n"
-                       "/who [<name>]         List all nodes or show information about the given node.\n"
-                       "/quit                 Exit this program.\n"
-                       );
-       } else {
+                       "<name>: <message>     Send a message to the given node.\n"
+                       "                      Subsequent messages don't need the <name>: prefix.\n"
+                       "/invite <name>        Create an invitation for a new node.\n"
+                       "/join <invitation>    Join an existing mesh using an invitation.\n"
+                       "/kick <name>          Blacklist the given node.\n"
+                       "/who [<name>]         List all nodes or show information about the given node.\n"
+                       "/quit                 Exit this program.\n"
+               );
+       } else
                fprintf(stderr, "Unknown command '/%s'\n", buf);
-       }
 }
 
 static void parse_input(meshlink_handle_t *mesh, char *buf) {
@@ -195,7 +192,7 @@ int main(int argc, char *argv[]) {
 
        meshlink_set_log_cb(NULL, MESHLINK_INFO, log_message);
 
-       meshlink_handle_t *mesh = meshlink_open(confbase, nick, "chat", STATIONARY);
+       meshlink_handle_t *mesh = meshlink_open(confbase, nick, "chat", DEV_CLASS_STATIONARY);
        if(!mesh) {
                fprintf(stderr, "Could not open MeshLink: %s\n", meshlink_strerror(meshlink_errno));
                return 1;
@@ -212,7 +209,7 @@ int main(int argc, char *argv[]) {
 
        printf("Chat started.\nType /help for a list of commands.\n");
 
-       while(fgets(buf, sizeof buf, stdin))
+       while(fgets(buf, sizeof(buf), stdin))
                parse_input(mesh, buf);
 
        printf("Chat stopping.\n");