From 2595acbf5c72a6c35e4d329cb268c12972e760cc Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 8 Aug 2013 10:42:35 +0200 Subject: core: Convert to stdbool with coccinelle This patch is completely generated by set of coccille rules and containts zero manual changes. This conversion contains two steps: 1) Use stdbool instead gboolean where possible 2) Do not compare explicit against boolean values The rules are as following: @@ expression E; symbol TRUE; symbol FALSE; @@ ( E - == TRUE | - TRUE == E + E | - E != TRUE + !E | - TRUE != E + !E | - E == FALSE + !E | - FALSE == E + !E | E - != FALSE | - FALSE != E + E ) // This is not a beautiful script but it does the job. // Improvemtents are welcome. // Fix all assigments but do not convert yet the type @@ gboolean x; @@ x = ( - TRUE + true | - FALSE + false ) // Figure out which function signature will to be fixed... // when we have the defitition @r@ identifier f; parameter list[n] ps; identifier i; @@ f(ps, gboolean i, ...) { ... } // ... and now convert all call sites @@ identifier r.f; expression list [r.n] es; @@ f(es, ( - FALSE + false | - TRUE + true ) ,...) // Figure out which function signature will to be fixed... // when we have the declaration only @r2@ type T; identifier f; parameter list[n] ps; identifier i; @@ T f(ps, gboolean i, ...); // ... and now convert all call sites @@ identifier r2.f; expression list [r.n] es; @@ f(es, ( - FALSE + false | - TRUE + true ) ,...) // A handfull of the GLib hooks we can't change. Let's remember // all ther positions. // 1. timeouts @k1@ identifier f; position p; typedef gpointer; identifier ptr; @@ static gboolean@p f(gpointer ptr); @k2@ identifier f; position p; identifier ptr; @@ static gboolean@p f(gpointer ptr) { ... } // hash map iterator functions @k3@ identifier f; position p; identifier p1, p2, p3; @@ static gboolean@p f(gpointer p1, gpointer p2, gpointer p3) { ... } // 2. GIOChannel @k4@ identifier f; position p; typedef GIOChannel, GIOCondition; identifier ptr; identifier ch, cn; @@ static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr); @k5@ identifier f; position p; identifier ptr; identifier ch, cn; @@ static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr) { ... } // 3. GSourceFuncs @k6@ identifier f; position p; typedef GSource; identifier src; @@ static gboolean@p f(GSource *src, ...) { ... } // gdbus functions @k7@ identifier f; position p; typedef DBusConnection; identifier con; @@ static gboolean@p f(DBusConnection *con, ...) { ... } // Now convert all gboolean which are are not used for interactin // with GLib // Note here happens the magic! @@ typedef bool; position p != {k1.p,k2.p,k3.p,k4.p,k5.p,k6.p,k7.p}; @@ - gboolean@p + bool // Update all return types @@ identifier f; @@ bool f(...) { <... - return TRUE; + return true; ...> } @@ identifier f; @@ bool f(...) { <... - return FALSE; + return false; ...> } --- src/log.c | 20 ++++++++-------- src/main.c | 18 +++++++------- src/manager.c | 22 ++++++++--------- src/manual.c | 74 ++++++++++++++++++++++++++++----------------------------- src/pacrunner.h | 2 +- src/plugin.c | 29 +++++++++++----------- src/proxy.c | 2 +- 7 files changed, 83 insertions(+), 84 deletions(-) diff --git a/src/log.c b/src/log.c index 959ea6f..9769e3d 100644 --- a/src/log.c +++ b/src/log.c @@ -77,26 +77,26 @@ extern struct pacrunner_debug_desc __stop___debug[]; static gchar **enabled = NULL; -static gboolean is_enabled(struct pacrunner_debug_desc *desc) +static bool is_enabled(struct pacrunner_debug_desc *desc) { int i; if (enabled == NULL) - return FALSE; + return false; for (i = 0; enabled[i] != NULL; i++) { if (desc->name != NULL && g_pattern_match_simple(enabled[i], - desc->name) == TRUE) - return TRUE; + desc->name)) + return true; if (desc->file != NULL && g_pattern_match_simple(enabled[i], - desc->file) == TRUE) - return TRUE; + desc->file)) + return true; } - return FALSE; + return false; } -int __pacrunner_log_init(const char *debug, gboolean detach) +int __pacrunner_log_init(const char *debug, bool detach) { int option = LOG_NDELAY | LOG_PID; struct pacrunner_debug_desc *desc; @@ -114,11 +114,11 @@ int __pacrunner_log_init(const char *debug, gboolean detach) file = NULL; } - if (is_enabled(desc) == TRUE) + if (is_enabled(desc)) desc->flags |= PACRUNNER_DEBUG_FLAG_PRINT; } - if (detach == FALSE) + if (!detach) option |= LOG_PERROR; openlog("pacrunner", option, LOG_DAEMON); diff --git a/src/main.c b/src/main.c index edf61a3..7822660 100644 --- a/src/main.c +++ b/src/main.c @@ -116,10 +116,10 @@ static void disconnect_callback(DBusConnection *conn, void *user_data) static gchar *option_debug = NULL; static gchar *option_plugin = NULL; static gchar *option_noplugin = NULL; -static gboolean option_detach = TRUE; -static gboolean option_version = FALSE; +static bool option_detach = true; +static bool option_version = false; -static gboolean parse_debug(const char *key, const char *value, +static bool parse_debug(const char *key, const char *value, gpointer user_data, GError **error) { if (value) @@ -127,7 +127,7 @@ static gboolean parse_debug(const char *key, const char *value, else option_debug = g_strdup("*"); - return TRUE; + return true; } static GOptionEntry options[] = { @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); - if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { if (error != NULL) { g_printerr("%s\n", error->message); g_error_free(error); @@ -168,12 +168,12 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (option_version == TRUE) { + if (option_version) { printf("%s\n", VERSION); exit(0); } - if (option_detach == TRUE) { + if (option_detach) { if (daemon(0, 0)) { perror("Can't start daemon"); exit(1); @@ -182,7 +182,7 @@ int main(int argc, char *argv[]) main_loop = g_main_loop_new(NULL, FALSE); - if (dbus_threads_init_default() == FALSE) { + if (!dbus_threads_init_default()) { fprintf(stderr, "Can't init usage of threads\n"); exit(1); } @@ -193,7 +193,7 @@ int main(int argc, char *argv[]) conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, PACRUNNER_SERVICE, &err); if (conn == NULL) { - if (dbus_error_is_set(&err) == TRUE) { + if (dbus_error_is_set(&err)) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else diff --git a/src/manager.c b/src/manager.c index b6e03c5..dd0cb1f 100644 --- a/src/manager.c +++ b/src/manager.c @@ -162,19 +162,19 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, switch (dbus_message_iter_get_arg_type(&value)) { case DBUS_TYPE_STRING: - if (g_str_equal(key, "Method") == TRUE) { + if (g_str_equal(key, "Method")) { dbus_message_iter_get_basic(&value, &method); if (strlen(method) == 0) method = NULL; - } else if (g_str_equal(key, "URL") == TRUE) { + } else if (g_str_equal(key, "URL")) { dbus_message_iter_get_basic(&value, &url); if (strlen(url) == 0) url = NULL; - } else if (g_str_equal(key, "Script") == TRUE) { + } else if (g_str_equal(key, "Script")) { dbus_message_iter_get_basic(&value, &script); if (strlen(script) == 0) script = NULL; - } else if (g_str_equal(key, "Interface") == TRUE) { + } else if (g_str_equal(key, "Interface")) { dbus_message_iter_get_basic(&value, &interface); if (strlen(interface) == 0) interface = NULL; @@ -187,16 +187,16 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, DBUS_TYPE_INVALID) break; - if (g_str_equal(key, "Servers") == TRUE) { + if (g_str_equal(key, "Servers")) { g_strfreev(servers); servers = extract_string_array(&list); - } else if (g_str_equal(key, "Excludes") == TRUE) { + } else if (g_str_equal(key, "Excludes")) { g_strfreev(excludes); excludes = extract_string_array(&list); - } else if (g_str_equal(key, "Domains") == TRUE) { + } else if (g_str_equal(key, "Domains")) { g_strfreev(domains); domains = extract_string_array(&list); - } else if (g_str_equal(key, "Nameservers") == TRUE) { + } else if (g_str_equal(key, "Nameservers")) { g_strfreev(nameservers); nameservers = extract_string_array(&list); } @@ -230,14 +230,14 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, domains = NULL; nameservers = NULL; - if (g_str_equal(method, "direct") == TRUE) { + if (g_str_equal(method, "direct")) { if (pacrunner_proxy_set_direct(config->proxy) < 0) pacrunner_error("Failed to set direct proxy"); - } else if (g_str_equal(method, "manual") == TRUE) { + } else if (g_str_equal(method, "manual")) { if (pacrunner_proxy_set_manual(config->proxy, servers, excludes) < 0) pacrunner_error("Failed to set proxy servers"); - } else if (g_str_equal(method, "auto") == TRUE) { + } else if (g_str_equal(method, "auto")) { if (pacrunner_proxy_set_auto(config->proxy, url, script) < 0) pacrunner_error("Failed to set auto proxy"); } else { diff --git a/src/manual.c b/src/manual.c index ca83de0..73d9398 100644 --- a/src/manual.c +++ b/src/manual.c @@ -56,16 +56,16 @@ struct pacrunner_manual_exclude { static int parse_uri(char *uri, char **host, char **protocol, - gboolean no_path, - gboolean exclusion) + bool no_path, + bool exclusion) { int ret = PACRUNNER_MANUAL_EXCLUDE_POST; - gboolean proto, post_confirmed, ipv6; + bool proto, post_confirmed, ipv6; char *scheme, *sep, *cur; long int port; int length; - proto = post_confirmed = ipv6 = FALSE; + proto = post_confirmed = ipv6 = false; port = -1; /** @@ -104,7 +104,7 @@ static int parse_uri(char *uri, } cur = sep + 3; - proto = TRUE; + proto = true; } /** @@ -114,8 +114,8 @@ static int parse_uri(char *uri, */ sep = strchr(cur, '/'); if (sep != NULL) { - if (exclusion == TRUE || (*(sep + 1) != '\0' && - no_path == TRUE)) + if (exclusion || (*(sep + 1) != '\0' && + no_path)) goto error; *sep = '\0'; @@ -127,7 +127,7 @@ static int parse_uri(char *uri, */ sep = strchr(cur, '@'); if (sep != NULL) { - if (exclusion == TRUE) + if (exclusion) goto error; *sep = '\0'; @@ -149,7 +149,7 @@ static int parse_uri(char *uri, cur = sep; sep = strchr(bracket, ':'); - ipv6 = TRUE; + ipv6 = true; } else sep = strchr(cur, ':'); @@ -160,7 +160,7 @@ static int parse_uri(char *uri, if (sep != NULL) { char *err = NULL; - if (exclusion == TRUE) + if (exclusion) goto error; errno = 0; @@ -180,11 +180,11 @@ static int parse_uri(char *uri, *sep = '\0'; if (sep != cur) { - if (exclusion == FALSE) + if (!exclusion) goto error; cur = sep; - post_confirmed = TRUE; + post_confirmed = true; } /** @@ -204,26 +204,26 @@ static int parse_uri(char *uri, *sep = '\0'; if (sep - cur + 1 != length) { - if (exclusion == FALSE) + if (!exclusion) goto error; length = sep - cur + 1; ret = PACRUNNER_MANUAL_EXCLUDE_PRE; - if (post_confirmed == TRUE) + if (post_confirmed) ret = PACRUNNER_MANUAL_EXCLUDE_ANY; } if ((length > 255) || (*cur == '-' || *sep == '-') || - ((*cur == '\0') && (exclusion == FALSE || - (exclusion == TRUE && proto == FALSE)))) + ((*cur == '\0') && (!exclusion || + (exclusion && !proto)))) goto error; /** * We do not allow some characters. However we do not run * a strict check if it's an IP address which is given */ - if (ipv6 == TRUE) + if (ipv6) forbidden_chars = "%?!,;@\\'*|<>{}()+=$&~# \""; else forbidden_chars = "%?!,;@\\'*|<>{}[]()+=$&~# \""; @@ -260,8 +260,8 @@ static int parse_uri(char *uri, goto error; } } else { - if (exclusion == FALSE || - (exclusion == TRUE && proto == FALSE)) + if (!exclusion || + (exclusion && !proto)) goto error; else ret = PACRUNNER_MANUAL_EXCLUDE_ANY; @@ -355,7 +355,7 @@ GList **__pacrunner_manual_parse_servers(char **servers) return NULL; for (uri = (char **)servers; *uri != NULL; uri++) { - ret = parse_uri(*uri, &host, &protocol, TRUE, FALSE); + ret = parse_uri(*uri, &host, &protocol, true, false); if (ret < 0) continue; @@ -421,7 +421,7 @@ GList **__pacrunner_manual_parse_excludes(char **excludes) return NULL; for (uri = (char **)excludes; *uri != NULL; uri++) { - ret = parse_uri(*uri, &host, &protocol, TRUE, TRUE); + ret = parse_uri(*uri, &host, &protocol, true, true); if (ret < 0) continue; @@ -484,7 +484,7 @@ void __pacrunner_manual_destroy_excludes(GList **excludes) g_free(excludes); } -static gboolean is_exclusion_matching(GList *excludes_list, +static bool is_exclusion_matching(GList *excludes_list, const char *host) { struct pacrunner_manual_exclude *exclusion; @@ -511,51 +511,51 @@ static gboolean is_exclusion_matching(GList *excludes_list, break; if (*(cursor + exclusion->host_length) == '\0') - return TRUE; + return true; break; case PACRUNNER_MANUAL_EXCLUDE_PRE: if (cursor == host) - return TRUE; + return true; break; case PACRUNNER_MANUAL_EXCLUDE_ANY: if (exclusion->host != NULL) { if (cursor != NULL) - return TRUE; + return true; else break; } - return TRUE; + return true; default: break; } } - return FALSE; + return false; } -static gboolean is_url_excluded(GList **excludes, +static bool is_url_excluded(GList **excludes, const char *host, enum pacrunner_manual_protocol proto) { if (excludes == NULL) - return FALSE; + return false; if (excludes[PACRUNNER_PROTOCOL_ALL] != NULL) if (is_exclusion_matching(excludes[PACRUNNER_PROTOCOL_ALL], - host) == TRUE) - return TRUE; + host)) + return true; if (proto == PACRUNNER_PROTOCOL_UNKNOWN) - return FALSE; + return false; if (excludes[proto] != NULL) - if (is_exclusion_matching(excludes[proto], host) == TRUE) - return TRUE; + if (is_exclusion_matching(excludes[proto], host)) + return true; - return FALSE; + return false; } static inline char *append_server(char *prev_result, const char *proxy) @@ -643,12 +643,12 @@ char *__pacrunner_manual_execute(const char *url, const char *host, if (url == NULL) url = host; - if (parse_uri((char *)url, &host_p, &protocol, FALSE, FALSE) < 0) + if (parse_uri((char *)url, &host_p, &protocol, false, false) < 0) goto direct; proto = get_protocol_from_string(protocol); - if (is_url_excluded(excludes, host_p, proto) == TRUE) + if (is_url_excluded(excludes, host_p, proto)) goto direct; result = generate_proxy_string(servers, proto); diff --git a/src/pacrunner.h b/src/pacrunner.h index 6731d7c..6d08b65 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -38,7 +38,7 @@ #include "log.h" -int __pacrunner_log_init(const char *debug, gboolean detach); +int __pacrunner_log_init(const char *debug, bool detach); void __pacrunner_log_cleanup(void); #include "plugin.h" diff --git a/src/plugin.c b/src/plugin.c index 2c5a94b..c8552ca 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -39,32 +39,32 @@ struct pacrunner_plugin { struct pacrunner_plugin_desc *desc; }; -static gboolean add_plugin(void *handle, struct pacrunner_plugin_desc *desc) +static bool add_plugin(void *handle, struct pacrunner_plugin_desc *desc) { struct pacrunner_plugin *plugin; if (desc->init == NULL) - return FALSE; + return false; plugin = g_try_new0(struct pacrunner_plugin, 1); if (plugin == NULL) - return FALSE; + return false; plugin->handle = handle; plugin->desc = desc; if (desc->init() < 0) { g_free(plugin); - return FALSE; + return false; } plugins = g_slist_append(plugins, plugin); DBG("Plugin %s loaded", desc->name); - return TRUE; + return true; } -static gboolean check_plugin(struct pacrunner_plugin_desc *desc, +static bool check_plugin(struct pacrunner_plugin_desc *desc, char **patterns, char **excludes) { if (excludes) { @@ -73,7 +73,7 @@ static gboolean check_plugin(struct pacrunner_plugin_desc *desc, break; if (*excludes) { pacrunner_info("Excluding %s", desc->name); - return FALSE; + return false; } } @@ -83,11 +83,11 @@ static gboolean check_plugin(struct pacrunner_plugin_desc *desc, break; if (!*patterns) { pacrunner_info("Ignoring %s", desc->name); - return FALSE; + return false; } } - return TRUE; + return true; } #include "builtin.h" @@ -112,8 +112,7 @@ int __pacrunner_plugin_init(const char *pattern, const char *exclude) excludes = g_strsplit_set(exclude, ", ", -1); for (i = 0; __pacrunner_builtin[i]; i++) { - if (check_plugin(__pacrunner_builtin[i], - patterns, excludes) == FALSE) + if (!check_plugin(__pacrunner_builtin[i], patterns, excludes)) continue; add_plugin(NULL, __pacrunner_builtin[i]); @@ -128,8 +127,8 @@ int __pacrunner_plugin_init(const char *pattern, const char *exclude) void *handle; char *filename; - if (g_str_has_prefix(file, "lib") == TRUE || - g_str_has_suffix(file, ".so") == FALSE) + if (g_str_has_prefix(file, "lib") || + !g_str_has_suffix(file, ".so")) continue; filename = g_build_filename(PLUGINDIR, file, NULL); @@ -152,12 +151,12 @@ int __pacrunner_plugin_init(const char *pattern, const char *exclude) continue; } - if (check_plugin(desc, patterns, excludes) == FALSE) { + if (!check_plugin(desc, patterns, excludes)) { dlclose(handle); continue; } - if (add_plugin(handle, desc) == FALSE) + if (!add_plugin(handle, desc)) dlclose(handle); } diff --git a/src/proxy.c b/src/proxy.c index 8e99f3b..28521ea 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -101,7 +101,7 @@ void pacrunner_proxy_unref(struct pacrunner_proxy *proxy) if (proxy == NULL) return; - if (g_atomic_int_dec_and_test(&proxy->refcount) == FALSE) + if (!g_atomic_int_dec_and_test(&proxy->refcount)) return; reset_proxy(proxy); -- cgit 1.2.3-korg