]> git.meshlink.io Git - meshlink/commitdiff
Reformat the code.
authorGuus Sliepen <guus@meshlink.io>
Tue, 9 Oct 2018 14:08:20 +0000 (16:08 +0200)
committerGuus Sliepen <guus@meshlink.io>
Tue, 9 Oct 2018 21:33:57 +0000 (23:33 +0200)
src/meshlink.c
src/utils.c

index 6df7c419261fc30f175ef016d00538c295d77f29..b407e5b53dca8e7a263be76d08c6a1e8511ac661 100644 (file)
@@ -349,10 +349,11 @@ char *meshlink_get_external_address_for_family(meshlink_handle_t *mesh, int fami
 
 // String comparison which handles NULL arguments
 static bool safe_streq(const char *a, const char *b) {
 
 // String comparison which handles NULL arguments
 static bool safe_streq(const char *a, const char *b) {
-       if (!a || !b)
+       if(!a || !b) {
                return a == b;
                return a == b;
-       else
+       } else {
                return !strcmp(a, b);
                return !strcmp(a, b);
+       }
 }
 
 // This gets the hostname part for use in invitation URLs
 }
 
 // This gets the hostname part for use in invitation URLs
@@ -370,21 +371,22 @@ static char *get_my_hostname(meshlink_handle_t *mesh) {
        hostname[2] = meshlink_get_external_address_for_family(mesh, AF_INET6);
 
        // Concatenate all unique address to the hostport string
        hostname[2] = meshlink_get_external_address_for_family(mesh, AF_INET6);
 
        // Concatenate all unique address to the hostport string
-       for (int i = 0; i < 3; i++) {
-               if (!hostname[i])
+       for(int i = 0; i < 3; i++) {
+               if(!hostname[i]) {
                        continue;
                        continue;
+               }
 
                // Ignore duplicate hostnames
                bool found = false;
 
 
                // Ignore duplicate hostnames
                bool found = false;
 
-               for (int j = 0; i < j; j++) {
-                       if (safe_streq(hostname[i], hostname[j]) && safe_streq(port[i], port[j])) {
+               for(int j = 0; i < j; j++) {
+                       if(safe_streq(hostname[i], hostname[j]) && safe_streq(port[i], port[j])) {
                                found = true;
                                break;
                        }
                }
 
                                found = true;
                                break;
                        }
                }
 
-               if (found) {
+               if(found) {
                        free(hostname[i]);
                        free(port[i]);
                        hostname[i] = NULL;
                        free(hostname[i]);
                        free(port[i]);
                        hostname[i] = NULL;
@@ -1136,12 +1138,14 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const c
 #ifdef HAVE_MINGW
        // TODO: use _locking()?
 #else
 #ifdef HAVE_MINGW
        // TODO: use _locking()?
 #else
+
        if(flock(fileno(mesh->conffile), LOCK_EX | LOCK_NB) != 0) {
                logger(NULL, MESHLINK_ERROR, "Cannot lock %s: %s\n", filename, strerror(errno));
                meshlink_close(mesh);
                meshlink_errno = MESHLINK_EBUSY;
                return NULL;
        }
        if(flock(fileno(mesh->conffile), LOCK_EX | LOCK_NB) != 0) {
                logger(NULL, MESHLINK_ERROR, "Cannot lock %s: %s\n", filename, strerror(errno));
                meshlink_close(mesh);
                meshlink_errno = MESHLINK_EBUSY;
                return NULL;
        }
+
 #endif
 
        // Read the configuration
 #endif
 
        // Read the configuration
index 503b16a1433884baa243e76a8c94649ad9b3af80..92505b4a6f8a17a60f8f60a9dbb88c18214075a8 100644 (file)
@@ -27,22 +27,22 @@ static const char base64_original[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno
 static const char base64_urlsafe[] =  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
 static const char base64_decode[256] = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 static const char base64_urlsafe[] =  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
 static const char base64_decode[256] = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63,
-       52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-       -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
-       15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,
-       -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-       41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-};
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63,
+               52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
+               -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
+               15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,
+               -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+               41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        };
 
 static int charhex2bin(char c) {
        if(isdigit(c)) {
 
 static int charhex2bin(char c) {
        if(isdigit(c)) {