From: Guus Sliepen Date: Tue, 9 Oct 2018 14:08:20 +0000 (+0200) Subject: Reformat the code. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=e99687f6b8c784e9a1805d1435e91a08b4ea6408;p=meshlink Reformat the code. --- diff --git a/src/meshlink.c b/src/meshlink.c index 6df7c419..b407e5b5 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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) { - if (!a || !b) + if(!a || !b) { return a == b; - else + } else { return !strcmp(a, b); + } } // 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 - for (int i = 0; i < 3; i++) { - if (!hostname[i]) + for(int i = 0; i < 3; i++) { + if(!hostname[i]) { continue; + } // 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; } } - if (found) { + if(found) { 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 + 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 diff --git a/src/utils.c b/src/utils.c index 503b16a1..92505b4a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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, - -1, -1, -1, -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)) {