From 1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 Mon Sep 17 00:00:00 2001 From: Zhang zhengguang Date: Thu, 17 Jul 2014 10:37:39 +0800 Subject: Imported Upstream version 1.24 --- tools/dbus-test.c | 4 +- tools/dhcp-server-test.c | 2 +- tools/dhcp-test.c | 4 +- tools/dnsproxy-test.c | 5 +- tools/iptables-test.c | 8 +- tools/iptables-unit.c | 26 ++-- tools/manager-api.c | 40 +++--- tools/netlink-test.c | 123 +++++++++++++++++ tools/polkit-test.c | 2 +- tools/private-network-test.c | 2 +- tools/resolv-test.c | 12 +- tools/session-api.c | 52 ++++--- tools/session-test.c | 152 ++++++++------------- tools/session-test.h | 45 +++--- tools/session-utils.c | 140 +++++++++++++------ tools/stats-tool.c | 78 ++++++----- tools/supplicant-dbus.c | 62 ++++----- tools/supplicant-test.c | 4 +- tools/supplicant.c | 317 +++++++++++++++++++++---------------------- tools/tap-test.c | 4 +- tools/web-test.c | 24 ++-- tools/wispr.c | 104 +++++++------- tools/wpad-test.c | 20 +-- 23 files changed, 680 insertions(+), 550 deletions(-) create mode 100644 tools/netlink-test.c (limited to 'tools') diff --git a/tools/dbus-test.c b/tools/dbus-test.c index 94d94f02..ece5d193 100644 --- a/tools/dbus-test.c +++ b/tools/dbus-test.c @@ -59,8 +59,8 @@ int main(int argc, char *argv[]) dbus_error_init(&err); conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err); - if (conn == NULL) { - if (dbus_error_is_set(&err) == TRUE) { + if (!conn) { + if (dbus_error_is_set(&err)) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else diff --git a/tools/dhcp-server-test.c b/tools/dhcp-server-test.c index 4252e628..b7d2e540 100644 --- a/tools/dhcp-server-test.c +++ b/tools/dhcp-server-test.c @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) printf("Create DHCP server for interface %d\n", index); dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error); - if (dhcp_server == NULL) { + if (!dhcp_server) { handle_error(error); exit(0); } diff --git a/tools/dhcp-test.c b/tools/dhcp-test.c index 284656b3..c34e10a8 100644 --- a/tools/dhcp-test.c +++ b/tools/dhcp-test.c @@ -102,7 +102,7 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data) address = g_dhcp_client_get_address(dhcp_client); printf("address %s\n", address); - if (address == NULL) + if (!address) return; option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET); @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) printf("Create DHCP client for interface %d\n", index); dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error); - if (dhcp_client == NULL) { + if (!dhcp_client) { handle_error(error); exit(0); } diff --git a/tools/dnsproxy-test.c b/tools/dnsproxy-test.c index 418767a8..551cae91 100644 --- a/tools/dnsproxy-test.c +++ b/tools/dnsproxy-test.c @@ -147,6 +147,9 @@ static int connect_tcp_socket(char *server) if (sk >= 0 && connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) { err = -errno; + close(sk); + sk = -1; + fprintf(stderr, "Failed to connect to DNS server at %s " "errno %d/%s\n", server, -err, strerror(-err)); @@ -237,7 +240,7 @@ static int sendto_msg(int sk, struct sockaddr *sa, socklen_t salen, return 0; } -static unsigned short get_id() +static unsigned short get_id(void) { return random(); } diff --git a/tools/iptables-test.c b/tools/iptables-test.c index 1d964b9a..2df53ccd 100644 --- a/tools/iptables-test.c +++ b/tools/iptables-test.c @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) opterr = 0; while ((c = getopt_long(argc, argv, - "-A:I:D:P:N:X:F:Lt:", NULL, NULL)) != -1) { + "-A:I:D:P:N:X:F:Lt:", NULL, NULL)) != -1) { switch (c) { case 'A': chain = optarg; @@ -92,11 +92,11 @@ int main(int argc, char *argv[]) } out: - if (table == NULL) + if (!table) table = "filter"; for (i = optind - 1; i < argc; i++) { - if (rule != NULL) { + if (rule) { tmp = rule; rule = g_strdup_printf("%s %s", rule, argv[i]); g_free(tmp); @@ -129,7 +129,7 @@ out: err = __connman_iptables_flush_chain(table, chain); break; case IPTABLES_COMMAND_DUMP: - __connman_log_init(argv[0], "*", FALSE, FALSE, + __connman_log_init(argv[0], "*", false, false, "iptables-test", "1"); err = __connman_iptables_dump(table); break; diff --git a/tools/iptables-unit.c b/tools/iptables-unit.c index 8ddd9198..b9273cee 100644 --- a/tools/iptables-unit.c +++ b/tools/iptables-unit.c @@ -27,7 +27,7 @@ #include "../src/connman.h" -static connman_bool_t assert_rule(const char *table_name, const char *rule) +static bool assert_rule(const char *table_name, const char *rule) { char *cmd, *output, **lines; GError **error = NULL; @@ -40,17 +40,17 @@ static connman_bool_t assert_rule(const char *table_name, const char *rule) lines = g_strsplit(output, "\n", 0); g_free(output); - for (i = 0; lines[i] != NULL; i++) { + for (i = 0; lines[i]; i++) { DBG("lines[%02d]: %s\n", i, lines[i]); if (g_strcmp0(lines[i], rule) == 0) break; } g_strfreev(lines); - if (lines[i] == NULL) - return FALSE; + if (!lines[i]) + return false; - return TRUE; + return true; } static void assert_rule_exists(const char *table_name, const char *rule) @@ -408,7 +408,7 @@ static void test_firewall_basic0(void) int err; ctx = __connman_firewall_create(); - g_assert(ctx != NULL); + g_assert(ctx); err = __connman_firewall_add_rule(ctx, "filter", "INPUT", "-m mark --mark 999 -j LOG"); @@ -437,7 +437,7 @@ static void test_firewall_basic1(void) int err; ctx = __connman_firewall_create(); - g_assert(ctx != NULL); + g_assert(ctx); err = __connman_firewall_add_rule(ctx, "filter", "INPUT", "-m mark --mark 999 -j LOG"); @@ -462,7 +462,7 @@ static void test_firewall_basic2(void) int err; ctx = __connman_firewall_create(); - g_assert(ctx != NULL); + g_assert(ctx); err = __connman_firewall_add_rule(ctx, "mangle", "INPUT", "-j CONNMARK --restore-mark"); @@ -483,7 +483,7 @@ static void test_firewall_basic2(void) static gchar *option_debug = NULL; -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) @@ -491,7 +491,7 @@ static gboolean parse_debug(const char *key, const char *value, else option_debug = g_strdup("*"); - return TRUE; + return true; } static GOptionEntry options[] = { @@ -512,8 +512,8 @@ 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 (error != NULL) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { + if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else @@ -523,7 +523,7 @@ int main(int argc, char *argv[]) g_option_context_free(context); - __connman_log_init(argv[0], option_debug, FALSE, FALSE, + __connman_log_init(argv[0], option_debug, false, false, "Unit Tests Connection Manager", VERSION); __connman_iptables_init(); diff --git a/tools/manager-api.c b/tools/manager-api.c index 2a182d7f..9098fca5 100644 --- a/tools/manager-api.c +++ b/tools/manager-api.c @@ -38,7 +38,7 @@ static DBusMessage *set_property(DBusConnection *connection, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "SetProperty"); - if (message == NULL) + if (!message) return NULL; dbus_message_iter_init_append(message, &iter); @@ -48,8 +48,8 @@ static DBusMessage *set_property(DBusConnection *connection, reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { @@ -73,15 +73,15 @@ DBusMessage *manager_get_services(DBusConnection *connection) CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "GetServices"); - if (message == NULL) + if (!message) return NULL; dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { @@ -105,15 +105,15 @@ DBusMessage *manager_get_properties(DBusConnection *connection) CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "GetProperties"); - if (message == NULL) + if (!message) return NULL; dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { @@ -140,7 +140,7 @@ DBusMessage *manager_create_session(DBusConnection *connection, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "CreateSession"); - if (message == NULL) + if (!message) return NULL; dbus_error_init(&error); @@ -158,8 +158,8 @@ DBusMessage *manager_create_session(DBusConnection *connection, reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { @@ -185,7 +185,7 @@ DBusMessage *manager_destroy_session(DBusConnection *connection, CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "DestroySession"); - if (message == NULL) + if (!message) return NULL; dbus_error_init(&error); @@ -197,8 +197,8 @@ DBusMessage *manager_destroy_session(DBusConnection *connection, reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { @@ -214,10 +214,12 @@ DBusMessage *manager_destroy_session(DBusConnection *connection, } DBusMessage *manager_set_session_mode(DBusConnection *connection, - connman_bool_t enable) + bool enable) { + dbus_bool_t val = enable; + return set_property(connection, "SessionMode", - DBUS_TYPE_BOOLEAN, &enable); + DBUS_TYPE_BOOLEAN, &val); } int manager_parse_properties(DBusMessage *msg, @@ -240,11 +242,11 @@ int manager_parse_properties(DBusMessage *msg, switch (dbus_message_iter_get_arg_type(&value)) { case DBUS_TYPE_STRING: - if (g_str_equal(key, "State") == TRUE) { + if (g_str_equal(key, "State")) { const char *val; dbus_message_iter_get_basic(&value, &val); - if (manager->state != NULL) + if (manager->state) g_free(manager->state); LOG("State %s", val); diff --git a/tools/netlink-test.c b/tools/netlink-test.c new file mode 100644 index 00000000..c07806a3 --- /dev/null +++ b/tools/netlink-test.c @@ -0,0 +1,123 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2013 BWM CarIT GmbH. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "../src/shared/netlink.h" + +#define NFGEN_DATA(nlh) ((void *)((char *)(nlh) + \ + NLMSG_ALIGN(sizeof(struct nfgenmsg)))) +#define NLA_DATA(nla) ((void *)((char*)(nla) + NLA_HDRLEN)) +#define NLA_OK(nla,len) ((len) >= (int)sizeof(struct nlattr) && \ + (nla)->nla_len >= sizeof(struct nlattr) && \ + (nla)->nla_len <= (len)) +#define NLA_NEXT(nla,attrlen) ((attrlen) -= NLA_ALIGN((nla)->nla_len), \ + (struct nlattr*)(((char*)(nla)) + \ + NLA_ALIGN((nla)->nla_len))) + +static GMainLoop *mainloop; + +static void do_debug(const char *str, void *user_data) +{ + const char *prefix = user_data; + + printf("%s%s\n", prefix, str); +} + +static void getlink_callback(unsigned int error, uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + const struct ifinfomsg *ifi = data; + struct rtattr *rta; + int bytes; + char ifname[IF_NAMESIZE]; + uint32_t index, flags; + + g_assert_cmpuint(error, ==, 0); + + bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg)); + + memset(ifname, 0, sizeof(ifname)); + + index = ifi->ifi_index; + flags = ifi->ifi_flags; + + for (rta = IFLA_RTA(ifi); RTA_OK(rta, bytes); + rta = RTA_NEXT(rta, bytes)) { + switch (rta->rta_type) { + case IFLA_IFNAME: + if (RTA_PAYLOAD(rta) <= IF_NAMESIZE) + strcpy(ifname, RTA_DATA(rta)); + break; + } + } + + printf("index=%d flags=0x%08x name=%s\n", index, flags, ifname); + + g_main_loop_quit(mainloop); +} + +static void test_case_1(void) +{ + struct netlink_info *netlink; + struct ifinfomsg msg; + + netlink = netlink_new(NETLINK_ROUTE); + + printf("\n"); + netlink_set_debug(netlink, do_debug, "[NETLINK] ", NULL); + + memset(&msg, 0, sizeof(msg)); + + netlink_send(netlink, RTM_GETLINK, NLM_F_DUMP, &msg, sizeof(msg), + getlink_callback, NULL, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + netlink_destroy(netlink); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/netlink/Test case 1", test_case_1); + + return g_test_run(); +} diff --git a/tools/polkit-test.c b/tools/polkit-test.c index 45e6eb80..ea1d24ae 100644 --- a/tools/polkit-test.c +++ b/tools/polkit-test.c @@ -142,7 +142,7 @@ static int check_authorization(DBusConnection *conn) return -EIO; } - if (dbus_message_has_signature(reply, "(bba{ss})") == TRUE) { + if (dbus_message_has_signature(reply, "(bba{ss})")) { dbus_message_iter_init(reply, &iter); print_arguments(&iter); } diff --git a/tools/private-network-test.c b/tools/private-network-test.c index 24f9234c..3dd115ba 100644 --- a/tools/private-network-test.c +++ b/tools/private-network-test.c @@ -101,7 +101,7 @@ static void request_private_network(DBusConnection *conn, int *out_fd, return; } - if (dbus_message_iter_init(reply, &array) == FALSE) + if (!dbus_message_iter_init(reply, &array)) goto done; if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_UNIX_FD) diff --git a/tools/resolv-test.c b/tools/resolv-test.c index 9867a4bb..8953acd3 100644 --- a/tools/resolv-test.c +++ b/tools/resolv-test.c @@ -80,7 +80,7 @@ static void resolv_result(GResolvResultStatus status, g_print("status: %s\n", status2str(status)); - if (results != NULL) { + if (results) { for (i = 0; results[i]; i++) g_print("result: %s\n", results[i]); } @@ -88,7 +88,7 @@ static void resolv_result(GResolvResultStatus status, g_main_loop_quit(main_loop); } -static gboolean option_debug = FALSE; +static bool option_debug = false; static GOptionEntry options[] = { { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug, @@ -107,8 +107,8 @@ 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 (error != NULL) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { + if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else @@ -124,12 +124,12 @@ int main(int argc, char *argv[]) } resolv = g_resolv_new(index); - if (resolv == NULL) { + if (!resolv) { printf("failed to create resolver\n"); return 1; } - if (option_debug == TRUE) + if (option_debug) g_resolv_set_debug(resolv, resolv_debug, "RESOLV"); main_loop = g_main_loop_new(NULL, FALSE); diff --git a/tools/session-api.c b/tools/session-api.c index 72c0b09d..7162ade6 100644 --- a/tools/session-api.c +++ b/tools/session-api.c @@ -73,7 +73,7 @@ static GSList *session_parse_allowed_bearers(DBusMessageIter *iter) dbus_message_iter_get_basic(&array, &bearer); info = g_try_new0(struct test_bearer_info, 1); - if (info == NULL) { + if (!info) { g_slist_foreach(list, bearer_info_cleanup, NULL); g_slist_free(list); @@ -97,7 +97,7 @@ static DBusMessage *notify_release(DBusConnection *conn, LOG("session %p", session); - if (session->notify != NULL) + if (session->notify) session->notify(session); return NULL; @@ -128,7 +128,7 @@ static DBusMessage *notify_update(DBusConnection *conn, switch (dbus_message_iter_get_arg_type(&value)) { case DBUS_TYPE_ARRAY: - if (g_str_equal(key, "AllowedBearers") == TRUE) { + if (g_str_equal(key, "AllowedBearers")) { allowed_bearers = session_parse_allowed_bearers(&value); g_slist_foreach(info->allowed_bearers, @@ -137,10 +137,10 @@ static DBusMessage *notify_update(DBusConnection *conn, info->allowed_bearers = allowed_bearers; - } else if (g_str_equal(key, "IPv4") == TRUE) { + } else if (g_str_equal(key, "IPv4")) { /* XXX */ - } else if (g_str_equal(key, "IPv6") == TRUE) { + } else if (g_str_equal(key, "IPv6")) { /* XXX */ } else { @@ -149,40 +149,40 @@ static DBusMessage *notify_update(DBusConnection *conn, } break; case DBUS_TYPE_STRING: - if (g_str_equal(key, "State") == TRUE) { + if (g_str_equal(key, "State")) { const char *val; dbus_message_iter_get_basic(&value, &val); info->state = string2state(val); - } else if (g_str_equal(key, "Bearer") == TRUE) { + } else if (g_str_equal(key, "Bearer")) { const char *val; dbus_message_iter_get_basic(&value, &val); - if (info->bearer != NULL) + if (info->bearer) g_free(info->bearer); info->bearer = g_strdup(val); - } else if (g_str_equal(key, "Name") == TRUE) { + } else if (g_str_equal(key, "Name")) { const char *val; dbus_message_iter_get_basic(&value, &val); - if (info->name != NULL) + if (info->name) g_free(info->name); info->name = g_strdup(val); - } else if (g_str_equal(key, "Interface") == TRUE) { + } else if (g_str_equal(key, "Interface")) { const char *val; dbus_message_iter_get_basic(&value, &val); - if (info->interface != NULL) + if (info->interface) g_free(info->interface); info->interface = g_strdup(val); } else if (g_str_equal(key, "ConnectionType") - == TRUE) { + ) { const char *val; dbus_message_iter_get_basic(&value, &val); @@ -199,7 +199,7 @@ static DBusMessage *notify_update(DBusConnection *conn, dbus_message_iter_next(&array); } - if (session->notify != NULL) + if (session->notify) session->notify(session); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); @@ -216,10 +216,7 @@ static const GDBusMethodTable notify_methods[] = { int session_notify_register(struct test_session *session, const char *notify_path) { - if (g_dbus_register_interface(session->connection, notify_path, - CONNMAN_NOTIFICATION_INTERFACE, - notify_methods, NULL, NULL, - session, NULL) == FALSE) { + if (!g_dbus_register_interface(session->connection, notify_path, CONNMAN_NOTIFICATION_INTERFACE, notify_methods, NULL, NULL, session, NULL)) { return -EINVAL; } @@ -229,8 +226,7 @@ int session_notify_register(struct test_session *session, int session_notify_unregister(struct test_session *session, const char *notify_path) { - if (g_dbus_unregister_interface(session->connection, notify_path, - CONNMAN_NOTIFICATION_INTERFACE) == FALSE) { + if (!g_dbus_unregister_interface(session->connection, notify_path, CONNMAN_NOTIFICATION_INTERFACE)) { return -EINVAL; } @@ -243,7 +239,7 @@ static void append_allowed_bearers(DBusMessageIter *iter, void *user_data) GSList *list; for (list = info->allowed_bearers; - list != NULL; list = list->next) { + list; list = list->next) { struct test_bearer_info *bearer_info = list->data; dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, @@ -254,7 +250,7 @@ static void append_allowed_bearers(DBusMessageIter *iter, void *user_data) void session_append_settings(DBusMessageIter *dict, struct test_session_info *info) { - if (info->allowed_bearers == NULL) + if (!info->allowed_bearers) return; connman_dbus_dict_append_array(dict, "AllowedBearers", @@ -273,15 +269,15 @@ DBusMessage *session_connect(DBusConnection *connection, session->session_path, CONNMAN_SESSION_INTERFACE, "Connect"); - if (message == NULL) + if (!message) return NULL; dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { @@ -306,15 +302,15 @@ DBusMessage *session_disconnect(DBusConnection *connection, session->session_path, CONNMAN_SESSION_INTERFACE, "Disconnect"); - if (message == NULL) + if (!message) return NULL; dbus_error_init(&error); reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error); - if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (!reply) { + if (dbus_error_is_set(&error)) { LOG("%s", error.message); dbus_error_free(&error); } else { diff --git a/tools/session-test.c b/tools/session-test.c index ac918947..18fd588c 100644 --- a/tools/session-test.c +++ b/tools/session-test.c @@ -58,38 +58,32 @@ static struct test_session *get_session(struct test_session *session, return &session->fix->session[index]; } -static gboolean test_session_create_no_notify(gpointer data) +static void test_session_create_no_notify(struct test_fix *fix) { - struct test_fix *fix = data; DBusMessage *msg; util_session_create(fix, 1); msg = manager_create_session(fix->session->connection, fix->session->info, "/foo"); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } -static gboolean test_session_destroy_no_notify(gpointer data) +static void test_session_destroy_no_notify(struct test_fix *fix) { - struct test_fix *fix = data; DBusMessage *msg; util_session_create(fix, 1); msg = manager_destroy_session(fix->session->connection, "/foo"); - g_assert(msg == NULL); + g_assert(!msg); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } static void test_session_create_notify(struct test_session *session) @@ -99,9 +93,8 @@ static void test_session_create_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_create(gpointer data) +static void test_session_create(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; DBusMessage *msg; int err; @@ -118,17 +111,14 @@ static gboolean test_session_create(gpointer data) msg = manager_create_session(session->connection, session->info, session->notify_path); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); - - return FALSE; } -static gboolean test_session_create_destroy(gpointer data) +static void test_session_create_destroy(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; util_session_create(fix, 1); @@ -140,13 +130,10 @@ static gboolean test_session_create_destroy(gpointer data) util_session_cleanup(fix->session); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } -static gboolean test_session_create_already_exists(gpointer data) +static void test_session_create_dup_notification(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session0, *session1; DBusMessage *msg; @@ -162,13 +149,11 @@ static gboolean test_session_create_already_exists(gpointer data) msg = manager_create_session(session1->connection, session1->info, session1->notify_path); - g_assert(msg == NULL); + g_assert(msg); util_session_cleanup(session0); util_idle_call(fix, util_quit_loop, util_session_destroy); - - return FALSE; } static void test_session_create_many_notify(struct test_session *session) @@ -187,9 +172,8 @@ static void test_session_create_many_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_create_many(gpointer data) +static void test_session_create_many(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; unsigned int i, max; @@ -207,17 +191,15 @@ static gboolean test_session_create_many(gpointer data) util_session_init(session); } - - return FALSE; } static void set_session_mode(struct test_fix *fix, - connman_bool_t enable) + bool enable) { DBusMessage *msg; msg = manager_set_session_mode(fix->main_connection, enable); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); @@ -235,9 +217,8 @@ static void test_session_connect_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_connect(gpointer data) +static void test_session_connect(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; DBusMessage *msg; @@ -249,12 +230,10 @@ static gboolean test_session_connect(gpointer data) util_session_init(session); msg = session_connect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR); dbus_message_unref(msg); - - return FALSE; } static void test_session_disconnect_notify(struct test_session *session) @@ -269,9 +248,8 @@ static void test_session_disconnect_notify(struct test_session *session) util_idle_call(session->fix, util_quit_loop, util_session_destroy); } -static gboolean test_session_disconnect(gpointer data) +static void test_session_disconnect(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; DBusMessage *msg; @@ -283,10 +261,8 @@ static gboolean test_session_disconnect(gpointer data) util_session_init(session); msg = session_disconnect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); - - return FALSE; } static void test_session_connect_disconnect_notify(struct test_session *session) @@ -302,6 +278,10 @@ static void test_session_connect_disconnect_notify(struct test_session *session) case TEST_SESSION_STATE_0: if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED) next_state = TEST_SESSION_STATE_1; + if (session->info->state == CONNMAN_SESSION_STATE_CONNECTED) { + LOG("state was already connected, continuing"); + next_state = TEST_SESSION_STATE_2; + } break; case TEST_SESSION_STATE_1: if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED) @@ -324,12 +304,12 @@ static void test_session_connect_disconnect_notify(struct test_session *session) switch (next_state) { case TEST_SESSION_STATE_1: msg = session_connect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: msg = session_disconnect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_3: @@ -342,9 +322,8 @@ static void test_session_connect_disconnect_notify(struct test_session *session) } } -static gboolean test_session_connect_disconnect(gpointer data) +static void test_session_connect_disconnect(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; /* @@ -374,8 +353,6 @@ static gboolean test_session_connect_disconnect(gpointer data) util_session_init(session); set_session_state(session, TEST_SESSION_STATE_0); - - return FALSE; } static void test_session_connect_free_ride_notify(struct test_session *session) @@ -396,6 +373,12 @@ static void test_session_connect_free_ride_notify(struct test_session *session) CONNMAN_SESSION_STATE_DISCONNECTED) { next_state = TEST_SESSION_STATE_1; } + if (session0->info->state == CONNMAN_SESSION_STATE_CONNECTED && + session1->info->state == + CONNMAN_SESSION_STATE_CONNECTED) { + LOG("state was already connected, continuing"); + next_state = TEST_SESSION_STATE_2; + } break; case TEST_SESSION_STATE_1: @@ -408,8 +391,12 @@ static void test_session_connect_free_ride_notify(struct test_session *session) break; case TEST_SESSION_STATE_2: if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED - && session1->info->state == - CONNMAN_SESSION_STATE_DISCONNECTED) { + && (session1->info->state == + CONNMAN_SESSION_STATE_DISCONNECTED || + session1->info->state == + CONNMAN_SESSION_STATE_CONNECTED) ) { + LOG("session0 /foo is disconnected, session1 /bar " + "can be either connected or disconnected"); next_state = TEST_SESSION_STATE_3; } @@ -432,14 +419,14 @@ static void test_session_connect_free_ride_notify(struct test_session *session) return; case TEST_SESSION_STATE_1: msg = session_connect(session0->connection, session0); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: msg = session_disconnect(session0->connection, session0); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; @@ -454,9 +441,8 @@ static void test_session_connect_free_ride_notify(struct test_session *session) } } -static gboolean test_session_connect_free_ride(gpointer data) +static void test_session_connect_free_ride(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session0, *session1; /* @@ -496,8 +482,6 @@ static gboolean test_session_connect_free_ride(gpointer data) util_session_init(session1); set_session_state(session0, TEST_SESSION_STATE_0); - - return FALSE; } static void policy_save(GKeyFile *keyfile, char *pathname) @@ -508,7 +492,7 @@ static void policy_save(GKeyFile *keyfile, char *pathname) data = g_key_file_to_data(keyfile, &length, NULL); - if(!g_file_set_contents(pathname, data, length, &error)) { + if (!g_file_set_contents(pathname, data, length, &error)) { DBG("Failed to store information: %s", error->message); g_error_free(error); g_assert(0); @@ -528,7 +512,7 @@ static void policy_allowed_bearers(const char *allowed_bearers) uid = getuid(); pwd = getpwuid(uid); - g_assert(pwd != NULL); + g_assert(pwd); keyfile = g_key_file_new(); g_key_file_set_string(keyfile, "policy_foo", "uid", pwd->pw_name); @@ -588,7 +572,7 @@ static void test_session_policy_notify(struct test_session *session) policy_allowed_bearers("ethernet"); msg = session_connect(session->connection, session); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: @@ -605,9 +589,8 @@ static void test_session_policy_notify(struct test_session *session) } } -static gboolean test_session_policy(gpointer data) +static void test_session_policy(struct test_fix *fix) { - struct test_fix *fix = data; struct test_session *session; /* @@ -639,71 +622,48 @@ static gboolean test_session_policy(gpointer data) util_session_init(session); set_session_state(session, TEST_SESSION_STATE_0); - - return FALSE; } -static connman_bool_t is_online(struct test_fix *fix) +static bool is_online(struct test_fix *fix) { if (g_strcmp0(fix->manager.state, "online") == 0) - return TRUE; + return true; - return FALSE; + return false; } -static gboolean enable_session_mode(gpointer data) +static void enable_session_mode(struct test_fix *fix) { - struct test_fix *fix = data; - - set_session_mode(fix, TRUE); + set_session_mode(fix, true); - if (is_online(fix) == FALSE) + if (!is_online(fix)) util_idle_call(fix, util_quit_loop, NULL); - - return FALSE; } -static gboolean manager_state_changed(gpointer data) +static void manager_state_changed(struct test_fix *fix) { - struct test_fix *fix = data; - - if (is_online(fix) == FALSE) { + if (!is_online(fix)) { fix->manager_changed = NULL; util_idle_call(fix, util_quit_loop, NULL); } - - return FALSE; } -static gboolean disable_session_mode(gpointer data) +static void disable_session_mode(struct test_fix *fix) { - struct test_fix *fix = data; - - set_session_mode(fix, FALSE); - - return FALSE; + set_session_mode(fix, false); } -static void setup_cb(struct test_fix *fix, gconstpointer data) +static void setup_cb(struct test_fix *fix) { fix->manager_changed = manager_state_changed; - util_setup(fix, data); util_call(fix, enable_session_mode, NULL); - - g_main_loop_run(fix->main_loop); - - fix->manager_changed = NULL; } -static void teardown_cb(struct test_fix *fix, gconstpointer data) +static void teardown_cb(struct test_fix *fix) { util_call(fix, disable_session_mode, NULL); util_idle_call(fix, util_quit_loop, NULL); - - g_main_loop_run(fix->main_loop); - - util_teardown(fix, data); } int main(int argc, char *argv[]) @@ -718,8 +678,8 @@ int main(int argc, char *argv[]) test_session_create, setup_cb, teardown_cb); util_test_add("/manager/session create destroy", test_session_create_destroy, setup_cb, teardown_cb); - util_test_add("/manager/session create already exists", - test_session_create_already_exists, setup_cb, teardown_cb); + util_test_add("/manager/session create duplicate notification", + test_session_create_dup_notification, setup_cb, teardown_cb); util_test_add("/manager/session create many", test_session_create_many, setup_cb, teardown_cb); diff --git a/tools/session-test.h b/tools/session-test.h index a21f5269..5e6d196a 100644 --- a/tools/session-test.h +++ b/tools/session-test.h @@ -26,50 +26,47 @@ #include "../src/connman.h" struct test_session; +struct test_fix; struct test_manager { char *state; }; +typedef void (* util_test_func_t) (struct test_fix *fix); + struct test_fix { gpointer user_data; GMainLoop *main_loop; DBusConnection *main_connection; - guint watch; - guint manager_watch; + unsigned int watch; + unsigned int manager_watch; struct test_manager manager; - GSourceFunc manager_changed; + util_test_func_t manager_changed; /* session test cases */ unsigned int max_sessions; struct test_session *session; }; -/* utils.c */ -typedef void (* util_test_setup_cb) (struct test_fix *fix, - gconstpointer data); -typedef void (* util_test_teardown_cb) (struct test_fix *fix, - gconstpointer data); - -gboolean util_quit_loop(gpointer fix); -guint util_idle_call(struct test_fix *fix, GSourceFunc func, - GDestroyNotify notify); -guint util_call(struct test_fix *fix, GSourceFunc func, - GDestroyNotify notify); -void util_test_add(const char *test_name, GSourceFunc test_func, - util_test_setup_cb setup_cb, - util_test_teardown_cb teardown_cb); -void util_setup(struct test_fix *fix, gconstpointer data); -void util_teardown(struct test_fix *fix, gconstpointer data); +void util_quit_loop(struct test_fix *fix); +void util_idle_call(struct test_fix *fix, util_test_func_t func, + util_test_func_t destroy); +void util_call(struct test_fix *fix, util_test_func_t func, + util_test_func_t destroy); +void util_test_add(const char *test_name, util_test_func_t test, + util_test_func_t setup, + util_test_func_t teardown); +void util_setup(struct test_fix *fix); +void util_teardown(struct test_fix *fix); void util_session_create(struct test_fix *fix, unsigned int max_sessions); -void util_session_destroy(gpointer fix); +void util_session_destroy(struct test_fix *fix); void util_session_init(struct test_session *session); void util_session_cleanup(struct test_session *session); -typedef void (* notify_cb) (struct test_session *session); +typedef void (* notify_func_t) (struct test_session *session); enum connman_session_state { CONNMAN_SESSION_STATE_DISCONNECTED = 0, @@ -88,14 +85,14 @@ struct test_session_info { }; struct test_session { - gpointer user_data; + void *user_data; struct test_fix *fix; DBusConnection *connection; char *session_path; char *notify_path; - notify_cb notify; + notify_func_t notify; struct test_session_info *info; }; @@ -128,7 +125,7 @@ DBusMessage *manager_create_session(DBusConnection *connection, DBusMessage *manager_destroy_session(DBusConnection *connection, const char *notifier_path); DBusMessage *manager_set_session_mode(DBusConnection *connection, - connman_bool_t enable); + bool enable); int manager_parse_properties(DBusMessage *msg, struct test_manager *manager); diff --git a/tools/session-utils.c b/tools/session-utils.c index 6a3d9918..92273e61 100644 --- a/tools/session-utils.c +++ b/tools/session-utils.c @@ -25,34 +25,70 @@ #include +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #include +#include "../src/shared/util.h" #include "session-test.h" #define ENABLE_WRAPPER 1 #define PROPERTY_CHANGED "PropertyChanged" -gboolean util_quit_loop(gpointer data) +void util_quit_loop(struct test_fix *fix) { - struct test_fix *fix = data; - g_main_loop_quit(fix->main_loop); +} + +static gboolean func_cb(gpointer data) +{ + struct cb_data *cbd = data; + util_test_func_t cb = cbd->cb; + struct test_fix *fix = cbd->user_data; + + (*cb)(fix); return FALSE; } -guint util_idle_call(struct test_fix *fix, GSourceFunc func, - GDestroyNotify notify) +static void destroy_cb(gpointer data) +{ + struct cb_data *cbd = data; + util_test_func_t cb = cbd->data; + struct test_fix *fix = cbd->user_data; + + if (cb) + (*cb)(fix); + + g_free(cbd); +} + +void util_call(struct test_fix *fix, util_test_func_t func, + util_test_func_t destroy) { + struct cb_data *cbd = cb_data_new(func, fix); GSource *source; - guint id; - source = g_idle_source_new(); - g_source_set_callback(source, func, fix, notify); - id = g_source_attach(source, g_main_loop_get_context(fix->main_loop)); + cbd->data = destroy; + + source = g_timeout_source_new(0); + g_source_set_callback(source, func_cb, cbd, destroy_cb); + g_source_attach(source, g_main_loop_get_context(fix->main_loop)); g_source_unref(source); +} - return id; +void util_idle_call(struct test_fix *fix, util_test_func_t func, + util_test_func_t destroy) +{ + struct cb_data *cbd = cb_data_new(func, fix); + GSource *source; + + cbd->data = destroy; + + source = g_idle_source_new(); + g_source_set_callback(source, func_cb, cbd, destroy_cb); + g_source_attach(source, g_main_loop_get_context(fix->main_loop)); + g_source_unref(source); } static void connman_died(DBusConnection *connection, void *user_data) @@ -60,8 +96,7 @@ static void connman_died(DBusConnection *connection, void *user_data) g_assert(FALSE); } -static void manager_changed(struct test_fix *fix, - DBusMessageIter *entry) +static void manager_changed(struct test_fix *fix, DBusMessageIter *entry) { DBusMessageIter iter; const char *key; @@ -83,16 +118,16 @@ static void manager_changed(struct test_fix *fix, dbus_message_iter_get_basic(&iter, &value); - if (g_str_equal(key, "State") == TRUE) { + if (g_str_equal(key, "State")) { LOG("State %s", value); - if (fix->manager.state != NULL) + if (fix->manager.state) g_free(fix->manager.state); fix->manager.state = g_strdup(value); } - if (fix->manager_changed != NULL) + if (fix->manager_changed) fix->manager_changed(fix); } @@ -110,24 +145,13 @@ static gboolean handle_manager_changed(DBusConnection *connection, return TRUE; } -guint util_call(struct test_fix *fix, GSourceFunc func, - GDestroyNotify notify) -{ - GSource *source; - guint id; - - source = g_timeout_source_new(0); - g_source_set_callback(source, func, fix, notify); - id = g_source_attach(source, g_main_loop_get_context(fix->main_loop)); - g_source_unref(source); - - return id; -} - -void util_setup(struct test_fix *fix, gconstpointer data) +static struct test_fix *create_fix(void) { + struct test_fix *fix; DBusMessage *msg; + fix = g_new0(struct test_fix, 1); + fix->main_loop = g_main_loop_new(NULL, FALSE); fix->main_connection = g_dbus_setup_private(DBUS_BUS_SYSTEM, NULL, NULL); @@ -146,9 +170,11 @@ void util_setup(struct test_fix *fix, gconstpointer data) msg = manager_get_properties(fix->main_connection); manager_parse_properties(msg, &fix->manager); dbus_message_unref(msg); + + return fix; } -void util_teardown(struct test_fix *fix, gconstpointer data) +static void cleanup_fix(struct test_fix *fix) { g_dbus_remove_watch(fix->main_connection, fix->watch); g_dbus_remove_watch(fix->main_connection, fix->manager_watch); @@ -156,14 +182,29 @@ void util_teardown(struct test_fix *fix, gconstpointer data) dbus_connection_unref(fix->main_connection); g_main_loop_unref(fix->main_loop); + + g_free(fix); } -static void util_wrapper(struct test_fix *fix, gconstpointer data) +struct test_data_cb { + util_test_func_t func; + util_test_func_t setup; + util_test_func_t teardown; +}; + +static void run_test_cb(gconstpointer data) { - GSourceFunc func = data; + const struct test_data_cb *cbd = data; + struct test_fix *fix; + + fix = create_fix(); + + util_call(fix, cbd->setup, NULL); + g_main_loop_run(fix->main_loop); + #if ENABLE_WRAPPER - if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) { - util_call(fix, func, NULL); + if (g_test_trap_fork(60 * 1000 * 1000, 0)) { + util_call(fix, cbd->func, NULL); g_main_loop_run(fix->main_loop); exit(0); } @@ -173,14 +214,25 @@ static void util_wrapper(struct test_fix *fix, gconstpointer data) util_call(fix, func, NULL); g_main_loop_run(fix->main_loop); #endif + + util_call(fix, cbd->teardown, NULL); + g_main_loop_run(fix->main_loop); + + cleanup_fix(fix); } -void util_test_add(const char *test_name, GSourceFunc test_func, - util_test_setup_cb setup_cb, - util_test_teardown_cb teardown_cb) +void util_test_add(const char *test_name, util_test_func_t test_func, + util_test_func_t setup, util_test_func_t teardown) { - g_test_add(test_name, struct test_fix, test_func, - setup_cb, util_wrapper, teardown_cb); + struct test_data_cb *cbd = g_new0(struct test_data_cb, 1); + + cbd->func = test_func; + cbd->setup = setup; + cbd->teardown = teardown; + + g_test_add_vtable(test_name, 0, cbd, NULL, + (GTestFixtureFunc) run_test_cb, + (GTestFixtureFunc) g_free); } void util_session_create(struct test_fix *fix, unsigned int max_sessions) @@ -198,10 +250,8 @@ void util_session_create(struct test_fix *fix, unsigned int max_sessions) } } -void util_session_destroy(gpointer data) +void util_session_destroy(struct test_fix *fix) { - struct test_fix *fix = data; - unsigned int i; for (i = 0; i < fix->max_sessions; i++) { @@ -225,7 +275,7 @@ void util_session_init(struct test_session *session) msg = manager_create_session(session->connection, session->info, session->notify_path); - g_assert(msg != NULL); + g_assert(msg); dbus_message_iter_init(msg, &iter); dbus_message_iter_get_basic(&iter, &path); @@ -241,7 +291,7 @@ void util_session_cleanup(struct test_session *session) msg = manager_destroy_session(session->connection, session->session_path); - g_assert(msg != NULL); + g_assert(msg); dbus_message_unref(msg); err = session_notify_unregister(session, diff --git a/tools/stats-tool.c b/tools/stats-tool.c index 0f06d8e6..7957c471 100644 --- a/tools/stats-tool.c +++ b/tools/stats-tool.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -99,23 +100,23 @@ struct stats_iter { static gint option_create = 0; static gint option_interval = 3; -static gboolean option_dump = FALSE; -static gboolean option_summary = FALSE; +static bool option_dump = false; +static bool option_summary = false; static char *option_info_file_name = NULL; static time_t option_start_ts = -1; static char *option_last_file_name = NULL; -static gboolean parse_start_ts(const char *key, const char *value, +static bool parse_start_ts(const char *key, const char *value, gpointer user_data, GError **error) { GTimeVal time_val; - if (g_time_val_from_iso8601(value, &time_val) == FALSE) - return FALSE; + if (!g_time_val_from_iso8601(value, &time_val)) + return false; option_start_ts = time_val.tv_sec; - return TRUE; + return true; } static GOptionEntry options[] = { @@ -244,13 +245,13 @@ static void stats_hdr_info(struct stats_file *file) end = get_end(file); home = get_home(file); - if (home == NULL) + if (!home) home_idx = UINT_MAX; else home_idx = get_index(file, home); roaming = get_roaming(file); - if (roaming == NULL) + if (!roaming) roaming_idx = UINT_MAX; else roaming_idx = get_index(file, roaming); @@ -344,12 +345,12 @@ static void stats_print_diff(struct stats_file *file) printf("\t[%04d] ", get_index(file, end)); stats_print_record(end); - if (file->home_first != NULL && get_home(file) != NULL) { + if (file->home_first && get_home(file)) { printf("\nhome\n"); stats_print_rec_diff(file->home_first, get_home(file)); } - if (file->roaming_first != NULL && get_roaming(file) != NULL) { + if (file->roaming_first && get_roaming(file)) { printf("\roaming\n"); stats_print_rec_diff(file->roaming_first, get_roaming(file)); } @@ -409,13 +410,13 @@ static int stats_file_update_cache(struct stats_file *file) it != end; it = get_next(file, it)) { - if (file->home_first == NULL && it->roaming == 0) + if (!file->home_first && it->roaming == 0) file->home_first = it; - if (file->roaming_first == NULL && it->roaming == 1) + if (!file->roaming_first && it->roaming == 1) file->roaming_first = it; - if (file->home_first != NULL && file->roaming_first != NULL) + if (file->home_first && file->roaming_first) break; } @@ -438,7 +439,7 @@ static int stats_file_remap(struct stats_file *file, size_t size) return -errno; } - if (file->addr == NULL) { + if (!file->addr) { addr = mmap(NULL, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, file->fd, 0); } else { @@ -467,7 +468,7 @@ static int stats_open(struct stats_file *file, const char *name) bzero(file, sizeof(struct stats_file)); - if (name != NULL) { + if (name) { file->name = g_strdup(name); file->fd = TFR(open(file->name, @@ -554,7 +555,7 @@ static int stats_create(struct stats_file *file, unsigned int nr, stats_file_update_cache(file); - if (start != NULL) { + if (start) { struct stats_record *rec; rec = get_end(file); @@ -604,7 +605,7 @@ static int stats_create(struct stats_file *file, unsigned int nr, set_end(file, next); if ((rand() % 50) == 0) - roaming = roaming == TRUE? FALSE : TRUE; + roaming = roaming ? FALSE : TRUE; } @@ -662,18 +663,18 @@ static struct stats_record *process_file(struct stats_iter *iter, home = NULL; roaming = NULL; - if (cur == NULL) + if (!cur) cur = get_next_record(iter); next = get_next_record(iter); - while (next != NULL) { + while (next) { GDate date_cur; GDate date_next; int append; append = FALSE; - if (cur->roaming == TRUE) + if (cur->roaming) roaming = cur; else home = cur; @@ -694,7 +695,8 @@ static struct stats_record *process_file(struct stats_iter *iter, if (day_cur == day_next && month_cur != month_next) append = TRUE; - else if (day_cur < account_period_offset && day_next >= account_period_offset) + else if (day_cur < account_period_offset + && day_next >= account_period_offset) append = TRUE; } else { /* day period size */ @@ -702,13 +704,13 @@ static struct stats_record *process_file(struct stats_iter *iter, append = TRUE; } - if (append == TRUE) { - if (home != NULL) { + if (append) { + if (home) { append_record(temp_file, home); home = NULL; } - if (roaming != NULL) { + if (roaming) { append_record(temp_file, roaming); roaming = NULL; } @@ -750,14 +752,15 @@ static int summarize(struct stats_file *data_file, /* Now process history file */ cur = NULL; - if (history_file != NULL) { + if (history_file) { history_iter.file = history_file; history_iter.begin = get_iterator_begin(history_iter.file); history_iter.end = get_iterator_end(history_iter.file); history_iter.it = history_iter.begin; cur = process_file(&history_iter, temp_file, NULL, - &date_change_step_size, account_period_offset); + &date_change_step_size, + account_period_offset); } data_iter.file = data_file; @@ -769,9 +772,9 @@ static int summarize(struct stats_file *data_file, * Ensure date_file records are newer than the history_file * record */ - if (cur != NULL) { + if (cur) { next = get_next_record(&data_iter); - while(next != NULL && cur->ts > next->ts) + while (next && cur->ts > next->ts) next = get_next_record(&data_iter); } @@ -779,7 +782,7 @@ static int summarize(struct stats_file *data_file, cur = process_file(&data_iter, temp_file, cur, &date_change_step_size, account_period_offset); - if (cur != NULL) + if (cur) append_record(temp_file, cur); return 0; @@ -814,7 +817,7 @@ static void history_file_update(struct stats_file *data_file, history_file = &_history_file; if (stats_open(&tempory_file, NULL) < 0) { - if (history_file != NULL) + if (history_file) stats_close(history_file); return; } @@ -844,8 +847,8 @@ 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 (error != NULL) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { + if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else @@ -866,7 +869,7 @@ int main(int argc, char *argv[]) exit(1); } - if (option_last_file_name != NULL) { + if (option_last_file_name) { struct stats_file last; if (stats_open(&last, option_last_file_name) < 0) { fprintf(stderr, "failed open file %s\n", @@ -883,7 +886,8 @@ int main(int argc, char *argv[]) start_ts = option_start_ts; if (option_create > 0) - stats_create(data_file, option_create, option_interval, start_ts, rec); + stats_create(data_file, option_create, option_interval, + start_ts, rec); hdr = get_hdr(data_file); if (hdr->magic != MAGIC) { @@ -895,13 +899,13 @@ int main(int argc, char *argv[]) stats_hdr_info(data_file); - if (option_dump == TRUE) + if (option_dump) stats_print_entries(data_file); - if (option_summary == TRUE) + if (option_summary) stats_print_diff(data_file); - if (option_info_file_name != NULL) + if (option_info_file_name) history_file_update(data_file, option_info_file_name); err: diff --git a/tools/supplicant-dbus.c b/tools/supplicant-dbus.c index 028a2753..d409da2d 100644 --- a/tools/supplicant-dbus.c +++ b/tools/supplicant-dbus.c @@ -51,7 +51,7 @@ void supplicant_dbus_array_foreach(DBusMessageIter *iter, dbus_message_iter_recurse(iter, &entry); while (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_INVALID) { - if (function != NULL) + if (function) function(&entry, user_data); dbus_message_iter_next(&entry); @@ -86,11 +86,11 @@ void supplicant_dbus_property_foreach(DBusMessageIter *iter, dbus_message_iter_recurse(&entry, &value); - if (key != NULL) { + if (key) { if (strcmp(key, "Properties") == 0) supplicant_dbus_property_foreach(&value, function, user_data); - else if (function != NULL) + else if (function) function(key, &value, user_data); } @@ -114,13 +114,13 @@ static void property_get_all_reply(DBusPendingCall *call, void *user_data) if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) goto done; - if (dbus_message_iter_init(reply, &iter) == FALSE) + if (!dbus_message_iter_init(reply, &iter)) goto done; supplicant_dbus_property_foreach(&iter, data->function, data->user_data); - if (data->function != NULL) + if (data->function) data->function(NULL, NULL, data->user_data); done: @@ -137,19 +137,19 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface, DBusMessage *message; DBusPendingCall *call; - if (connection == NULL) + if (!connection) return -EINVAL; - if (path == NULL || interface == NULL) + if (!path || !interface) return -EINVAL; data = dbus_malloc0(sizeof(*data)); - if (data == NULL) + if (!data) return -ENOMEM; message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path, DBUS_INTERFACE_PROPERTIES, "GetAll"); - if (message == NULL) { + if (!message) { dbus_free(data); return -ENOMEM; } @@ -158,14 +158,14 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface, dbus_message_append_args(message, DBUS_TYPE_STRING, &interface, NULL); - if (dbus_connection_send_with_reply(connection, message, - &call, TIMEOUT) == FALSE) { + if (!dbus_connection_send_with_reply(connection, message, + &call, TIMEOUT)) { dbus_message_unref(message); dbus_free(data); return -EIO; } - if (call == NULL) { + if (!call) { dbus_message_unref(message); dbus_free(data); return -EIO; @@ -201,10 +201,10 @@ static void property_set_reply(DBusPendingCall *call, void *user_data) else error = NULL; - if (dbus_message_iter_init(reply, &iter) == FALSE) + if (!dbus_message_iter_init(reply, &iter)) goto done; - if (data->function != NULL) + if (data->function) data->function(error, &iter, data->user_data); done: @@ -224,22 +224,22 @@ int supplicant_dbus_property_set(const char *path, const char *interface, DBusMessageIter iter, value; DBusPendingCall *call; - if (connection == NULL) + if (!connection) return -EINVAL; - if (path == NULL || interface == NULL) + if (!path || !interface) return -EINVAL; - if (key == NULL || signature == NULL || setup == NULL) + if (!key || !signature || !setup) return -EINVAL; data = dbus_malloc0(sizeof(*data)); - if (data == NULL) + if (!data) return -ENOMEM; message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path, DBUS_INTERFACE_PROPERTIES, "Set"); - if (message == NULL) { + if (!message) { dbus_free(data); return -ENOMEM; } @@ -255,14 +255,14 @@ int supplicant_dbus_property_set(const char *path, const char *interface, setup(&value, user_data); dbus_message_iter_close_container(&iter, &value); - if (dbus_connection_send_with_reply(connection, message, - &call, TIMEOUT) == FALSE) { + if (!dbus_connection_send_with_reply(connection, message, + &call, TIMEOUT)) { dbus_message_unref(message); dbus_free(data); return -EIO; } - if (call == NULL) { + if (!call) { dbus_message_unref(message); dbus_free(data); return -EIO; @@ -300,7 +300,7 @@ static void method_call_reply(DBusPendingCall *call, void *user_data) dbus_message_iter_init(reply, &iter); - if (data->function != NULL) + if (data->function) data->function(error, &iter, data->user_data); dbus_message_unref(reply); @@ -319,19 +319,19 @@ int supplicant_dbus_method_call(const char *path, DBusMessageIter iter; DBusPendingCall *call; - if (connection == NULL) + if (!connection) return -EINVAL; - if (path == NULL || interface == NULL || method == NULL) + if (!path || !interface || !method) return -EINVAL; data = dbus_malloc0(sizeof(*data)); - if (data == NULL) + if (!data) return -ENOMEM; message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path, interface, method); - if (message == NULL) { + if (!message) { dbus_free(data); return -ENOMEM; } @@ -339,17 +339,17 @@ int supplicant_dbus_method_call(const char *path, dbus_message_set_auto_start(message, FALSE); dbus_message_iter_init_append(message, &iter); - if (setup != NULL) + if (setup) setup(&iter, user_data); - if (dbus_connection_send_with_reply(connection, message, - &call, TIMEOUT) == FALSE) { + if (!dbus_connection_send_with_reply(connection, message, + &call, TIMEOUT)) { dbus_message_unref(message); dbus_free(data); return -EIO; } - if (call == NULL) { + if (!call) { dbus_message_unref(message); dbus_free(data); return -EIO; diff --git a/tools/supplicant-test.c b/tools/supplicant-test.c index 9b33275b..a6408076 100644 --- a/tools/supplicant-test.c +++ b/tools/supplicant-test.c @@ -156,8 +156,8 @@ int main(int argc, char *argv[]) dbus_error_init(&err); conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err); - if (conn == NULL) { - if (dbus_error_is_set(&err) == TRUE) { + if (!conn) { + if (dbus_error_is_set(&err)) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else diff --git a/tools/supplicant.c b/tools/supplicant.c index 1c96823a..e2e6fea5 100644 --- a/tools/supplicant.c +++ b/tools/supplicant.c @@ -184,12 +184,12 @@ struct supplicant_bss { static enum supplicant_mode string2mode(const char *mode) { - if (mode == NULL) + if (!mode) return SUPPLICANT_MODE_UNKNOWN; - if (g_str_equal(mode, "infrastructure") == TRUE) + if (g_str_equal(mode, "infrastructure")) return SUPPLICANT_MODE_INFRA; - else if (g_str_equal(mode, "ad-hoc") == TRUE) + else if (g_str_equal(mode, "ad-hoc")) return SUPPLICANT_MODE_IBSS; return SUPPLICANT_MODE_UNKNOWN; @@ -229,28 +229,28 @@ static const char *security2string(enum supplicant_security security) static enum supplicant_state string2state(const char *state) { - if (state == NULL) + if (!state) return SUPPLICANT_STATE_UNKNOWN; - if (g_str_equal(state, "unknown") == TRUE) + if (g_str_equal(state, "unknown")) return SUPPLICANT_STATE_UNKNOWN; - else if (g_str_equal(state, "disconnected") == TRUE) + else if (g_str_equal(state, "disconnected")) return SUPPLICANT_STATE_DISCONNECTED; - else if (g_str_equal(state, "inactive") == TRUE) + else if (g_str_equal(state, "inactive")) return SUPPLICANT_STATE_INACTIVE; - else if (g_str_equal(state, "scanning") == TRUE) + else if (g_str_equal(state, "scanning")) return SUPPLICANT_STATE_SCANNING; - else if (g_str_equal(state, "authenticating") == TRUE) + else if (g_str_equal(state, "authenticating")) return SUPPLICANT_STATE_AUTHENTICATING; - else if (g_str_equal(state, "associating") == TRUE) + else if (g_str_equal(state, "associating")) return SUPPLICANT_STATE_ASSOCIATING; - else if (g_str_equal(state, "associated") == TRUE) + else if (g_str_equal(state, "associated")) return SUPPLICANT_STATE_ASSOCIATED; - else if (g_str_equal(state, "group_handshake") == TRUE) + else if (g_str_equal(state, "group_handshake")) return SUPPLICANT_STATE_GROUP_HANDSHAKE; - else if (g_str_equal(state, "4way_handshake") == TRUE) + else if (g_str_equal(state, "4way_handshake")) return SUPPLICANT_STATE_4WAY_HANDSHAKE; - else if (g_str_equal(state, "completed") == TRUE) + else if (g_str_equal(state, "completed")) return SUPPLICANT_STATE_COMPLETED; return SUPPLICANT_STATE_UNKNOWN; @@ -258,15 +258,15 @@ static enum supplicant_state string2state(const char *state) static void callback_system_ready(void) { - if (system_ready == TRUE) + if (system_ready) return; system_ready = TRUE; - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->system_ready == NULL) + if (!callbacks_pointer->system_ready) return; callbacks_pointer->system_ready(); @@ -276,10 +276,10 @@ static void callback_system_killed(void) { system_ready = FALSE; - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->system_killed == NULL) + if (!callbacks_pointer->system_killed) return; callbacks_pointer->system_killed(); @@ -287,10 +287,10 @@ static void callback_system_killed(void) static void callback_interface_added(struct supplicant_interface *interface) { - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->interface_added == NULL) + if (!callbacks_pointer->interface_added) return; callbacks_pointer->interface_added(interface); @@ -298,10 +298,10 @@ static void callback_interface_added(struct supplicant_interface *interface) static void callback_interface_removed(struct supplicant_interface *interface) { - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->interface_removed == NULL) + if (!callbacks_pointer->interface_removed) return; callbacks_pointer->interface_removed(interface); @@ -309,10 +309,10 @@ static void callback_interface_removed(struct supplicant_interface *interface) static void callback_scan_started(struct supplicant_interface *interface) { - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->scan_started == NULL) + if (!callbacks_pointer->scan_started) return; callbacks_pointer->scan_started(interface); @@ -320,10 +320,10 @@ static void callback_scan_started(struct supplicant_interface *interface) static void callback_scan_finished(struct supplicant_interface *interface) { - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->scan_finished == NULL) + if (!callbacks_pointer->scan_finished) return; callbacks_pointer->scan_finished(interface); @@ -331,10 +331,10 @@ static void callback_scan_finished(struct supplicant_interface *interface) static void callback_network_added(struct supplicant_network *network) { - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->network_added == NULL) + if (!callbacks_pointer->network_added) return; callbacks_pointer->network_added(network); @@ -342,10 +342,10 @@ static void callback_network_added(struct supplicant_network *network) static void callback_network_removed(struct supplicant_network *network) { - if (callbacks_pointer == NULL) + if (!callbacks_pointer) return; - if (callbacks_pointer->network_removed == NULL) + if (!callbacks_pointer->network_removed) return; callbacks_pointer->network_removed(network); @@ -396,7 +396,7 @@ static void debug_strvalmap(const char *label, struct strvalmap *map, { int i; - for (i = 0; map[i].str != NULL; i++) { + for (i = 0; map[i].str; i++) { if (val & map[i].val) DBG("%s: %s", label, map[i].str); } @@ -409,10 +409,10 @@ static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; keymgmt_capa_map[i].str != NULL; i++) + for (i = 0; keymgmt_capa_map[i].str; i++) if (strcmp(str, keymgmt_capa_map[i].str) == 0) { interface->keymgmt_capa |= keymgmt_capa_map[i].val; break; @@ -426,10 +426,10 @@ static void interface_capability_authalg(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; authalg_capa_map[i].str != NULL; i++) + for (i = 0; authalg_capa_map[i].str; i++) if (strcmp(str, authalg_capa_map[i].str) == 0) { interface->authalg_capa |= authalg_capa_map[i].val; break; @@ -443,10 +443,10 @@ static void interface_capability_proto(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; proto_capa_map[i].str != NULL; i++) + for (i = 0; proto_capa_map[i].str; i++) if (strcmp(str, proto_capa_map[i].str) == 0) { interface->proto_capa |= proto_capa_map[i].val; break; @@ -460,10 +460,10 @@ static void interface_capability_pairwise(DBusMessageIter *iter, void *user_data int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; pairwise_capa_map[i].str != NULL; i++) + for (i = 0; pairwise_capa_map[i].str; i++) if (strcmp(str, pairwise_capa_map[i].str) == 0) { interface->pairwise_capa |= pairwise_capa_map[i].val; break; @@ -477,10 +477,10 @@ static void interface_capability_group(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; group_capa_map[i].str != NULL; i++) + for (i = 0; group_capa_map[i].str; i++) if (strcmp(str, group_capa_map[i].str) == 0) { interface->group_capa |= group_capa_map[i].val; break; @@ -494,10 +494,10 @@ static void interface_capability_scan(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; scan_capa_map[i].str != NULL; i++) + for (i = 0; scan_capa_map[i].str; i++) if (strcmp(str, scan_capa_map[i].str) == 0) { interface->scan_capa |= scan_capa_map[i].val; break; @@ -511,10 +511,10 @@ static void interface_capability_mode(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; mode_capa_map[i].str != NULL; i++) + for (i = 0; mode_capa_map[i].str; i++) if (strcmp(str, mode_capa_map[i].str) == 0) { interface->mode_capa |= mode_capa_map[i].val; break; @@ -526,7 +526,7 @@ static void interface_capability(const char *key, DBusMessageIter *iter, { struct supplicant_interface *interface = user_data; - if (key == NULL) + if (!key) return; if (g_strcmp0(key, "KeyMgmt") == 0) @@ -557,7 +557,7 @@ static void interface_capability(const char *key, DBusMessageIter *iter, const char *supplicant_interface_get_ifname(struct supplicant_interface *interface) { - if (interface == NULL) + if (!interface) return NULL; return interface->ifname; @@ -565,7 +565,7 @@ const char *supplicant_interface_get_ifname(struct supplicant_interface *interfa const char *supplicant_interface_get_driver(struct supplicant_interface *interface) { - if (interface == NULL) + if (!interface) return NULL; return interface->driver; @@ -573,7 +573,7 @@ const char *supplicant_interface_get_driver(struct supplicant_interface *interfa struct supplicant_interface *supplicant_network_get_interface(struct supplicant_network *network) { - if (network == NULL) + if (!network) return NULL; return network->interface; @@ -581,7 +581,7 @@ struct supplicant_interface *supplicant_network_get_interface(struct supplicant_ const char *supplicant_network_get_name(struct supplicant_network *network) { - if (network == NULL || network->name == NULL) + if (!network || !network->name) return ""; return network->name; @@ -589,7 +589,7 @@ const char *supplicant_network_get_name(struct supplicant_network *network) const char *supplicant_network_get_identifier(struct supplicant_network *network) { - if (network == NULL || network->group == NULL) + if (!network || !network->group) return ""; return network->group; @@ -597,7 +597,7 @@ const char *supplicant_network_get_identifier(struct supplicant_network *network enum supplicant_mode supplicant_network_get_mode(struct supplicant_network *network) { - if (network == NULL) + if (!network) return SUPPLICANT_MODE_UNKNOWN; return network->mode; @@ -616,13 +616,13 @@ static void merge_network(struct supplicant_network *network) DBG("ssid %s mode %s", ssid, mode); - if (ssid != NULL) + if (ssid) ssid_len = strlen(ssid); else ssid_len = 0; str = g_string_sized_new((ssid_len * 2) + 24); - if (str == NULL) + if (!str) return; for (i = 0; i < ssid_len; i++) @@ -653,10 +653,10 @@ static void network_property(const char *key, DBusMessageIter *iter, { struct supplicant_network *network = user_data; - if (network->interface == NULL) + if (!network->interface) return; - if (key == NULL) { + if (!key) { merge_network(network); return; } @@ -669,7 +669,7 @@ static void network_property(const char *key, DBusMessageIter *iter, const char *str = NULL; dbus_message_iter_get_basic(iter, &str); - if (str != NULL) + if (str) g_hash_table_replace(network->config_table, g_strdup(key), g_strdup(str)); } else @@ -684,18 +684,18 @@ static void interface_network_added(DBusMessageIter *iter, void *user_data) const char *path = NULL; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) + if (!path) return; if (g_strcmp0(path, "/") == 0) return; network = g_hash_table_lookup(interface->net_mapping, path); - if (network != NULL) + if (network) return; network = g_try_new0(struct supplicant_network, 1); - if (network == NULL) + if (!network) return; network->interface = interface; @@ -724,11 +724,11 @@ static void interface_network_removed(DBusMessageIter *iter, void *user_data) const char *path = NULL; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) + if (!path) return; network = g_hash_table_lookup(interface->net_mapping, path); - if (network == NULL) + if (!network) return; g_hash_table_remove(interface->net_mapping, path); @@ -744,7 +744,7 @@ static char *create_name(unsigned char *ssid, int ssid_len) else name = g_try_malloc0(ssid_len + 1); - if (name == NULL) + if (!name) return g_strdup(""); for (i = 0; i < ssid_len; i++) { @@ -764,7 +764,7 @@ static char *create_group(struct supplicant_bss *bss) const char *mode, *security; str = g_string_sized_new((bss->ssid_len * 2) + 24); - if (str == NULL) + if (!str) return NULL; if (bss->ssid_len > 0 && bss->ssid[0] != '\0') { @@ -774,11 +774,11 @@ static char *create_group(struct supplicant_bss *bss) g_string_append_printf(str, "hidden"); mode = mode2string(bss->mode); - if (mode != NULL) + if (mode) g_string_append_printf(str, "_%s", mode); security = security2string(bss->security); - if (security != NULL) + if (security) g_string_append_printf(str, "_%s", security); return g_string_free(str, FALSE); @@ -791,17 +791,17 @@ static void add_bss_to_network(struct supplicant_bss *bss) char *group; group = create_group(bss); - if (group == NULL) + if (!group) return; network = g_hash_table_lookup(interface->network_table, group); - if (network != NULL) { + if (network) { g_free(group); goto done; } network = g_try_new0(struct supplicant_network, 1); - if (network == NULL) { + if (!network) { g_free(group); return; } @@ -914,15 +914,15 @@ static void bss_property(const char *key, DBusMessageIter *iter, { struct supplicant_bss *bss = user_data; - if (bss->interface == NULL) + if (!bss->interface) return; - if (key == NULL) { - if (bss->ieee8021x == TRUE) + if (!key) { + if (bss->ieee8021x) bss->security = SUPPLICANT_SECURITY_IEEE8021X; - else if (bss->psk == TRUE) + else if (bss->psk) bss->security = SUPPLICANT_SECURITY_PSK; - else if (bss->privacy == TRUE) + else if (bss->privacy) bss->security = SUPPLICANT_SECURITY_WEP; else bss->security = SUPPLICANT_SECURITY_NONE; @@ -1039,21 +1039,21 @@ static void interface_bss_added(DBusMessageIter *iter, void *user_data) const char *path = NULL; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) + if (!path) return; if (g_strcmp0(path, "/") == 0) return; network = g_hash_table_lookup(interface->bss_mapping, path); - if (network != NULL) { + if (network) { bss = g_hash_table_lookup(network->bss_table, path); - if (bss != NULL) + if (bss) return; } bss = g_try_new0(struct supplicant_bss, 1); - if (bss == NULL) + if (!bss) return; bss->interface = interface; @@ -1078,11 +1078,11 @@ static void interface_bss_removed(DBusMessageIter *iter, void *user_data) const char *path = NULL; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) + if (!path) return; network = g_hash_table_lookup(interface->bss_mapping, path); - if (network == NULL) + if (!network) return; g_hash_table_remove(bss_mapping, path); @@ -1099,10 +1099,10 @@ static void interface_property(const char *key, DBusMessageIter *iter, { struct supplicant_interface *interface = user_data; - if (interface == NULL) + if (!interface) return; - if (key == NULL) { + if (!key) { debug_strvalmap("KeyMgmt capability", keymgmt_capa_map, interface->keymgmt_capa); debug_strvalmap("AuthAlg capability", authalg_capa_map, @@ -1130,7 +1130,7 @@ static void interface_property(const char *key, DBusMessageIter *iter, const char *str = NULL; dbus_message_iter_get_basic(iter, &str); - if (str != NULL) + if (str) interface->state = string2state(str); DBG("state %s (%d)", str, interface->state); @@ -1140,8 +1140,8 @@ static void interface_property(const char *key, DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &scanning); interface->scanning = scanning; - if (interface->ready == TRUE) { - if (interface->scanning == TRUE) + if (interface->ready) { + if (interface->scanning) callback_scan_started(interface); else callback_scan_finished(interface); @@ -1155,19 +1155,19 @@ static void interface_property(const char *key, DBusMessageIter *iter, const char *str = NULL; dbus_message_iter_get_basic(iter, &str); - if (str != NULL) + if (str) interface->ifname = g_strdup(str); } else if (g_strcmp0(key, "Driver") == 0) { const char *str = NULL; dbus_message_iter_get_basic(iter, &str); - if (str != NULL) + if (str) interface->driver = g_strdup(str); } else if (g_strcmp0(key, "BridgeIfname") == 0) { const char *str = NULL; dbus_message_iter_get_basic(iter, &str); - if (str != NULL) + if (str) interface->bridge = g_strdup(str); } else if (g_strcmp0(key, "CurrentBSS") == 0) { interface_bss_added(iter, interface); @@ -1190,7 +1190,7 @@ static struct supplicant_interface *interface_alloc(const char *path) struct supplicant_interface *interface; interface = g_try_new0(struct supplicant_interface, 1); - if (interface == NULL) + if (!interface) return NULL; interface->path = g_strdup(path); @@ -1214,18 +1214,18 @@ static void interface_added(DBusMessageIter *iter, void *user_data) const char *path = NULL; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) + if (!path) return; if (g_strcmp0(path, "/") == 0) return; interface = g_hash_table_lookup(interface_table, path); - if (interface != NULL) + if (interface) return; interface = interface_alloc(path); - if (interface == NULL) + if (!interface) return; dbus_message_iter_next(iter); @@ -1246,7 +1246,7 @@ static void interface_removed(DBusMessageIter *iter, void *user_data) const char *path = NULL; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) + if (!path) return; g_hash_table_remove(interface_table, path); @@ -1258,10 +1258,10 @@ static void eap_method(DBusMessageIter *iter, void *user_data) int i; dbus_message_iter_get_basic(iter, &str); - if (str == NULL) + if (!str) return; - for (i = 0; eap_method_map[i].str != NULL; i++) + for (i = 0; eap_method_map[i].str; i++) if (strcmp(str, eap_method_map[i].str) == 0) { eap_methods |= eap_method_map[i].val; break; @@ -1271,7 +1271,7 @@ static void eap_method(DBusMessageIter *iter, void *user_data) static void service_property(const char *key, DBusMessageIter *iter, void *user_data) { - if (key == NULL) { + if (!key) { callback_system_ready(); return; } @@ -1281,7 +1281,7 @@ static void service_property(const char *key, DBusMessageIter *iter, int i; dbus_message_iter_get_basic(iter, &str); - for (i = 0; debug_strings[i] != NULL; i++) + for (i = 0; debug_strings[i]; i++) if (g_strcmp0(debug_strings[i], str) == 0) { debug_level = i; break; @@ -1318,7 +1318,7 @@ static void signal_name_owner_changed(const char *path, DBusMessageIter *iter) return; dbus_message_iter_get_basic(iter, &name); - if (name == NULL) + if (!name) return; if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0) @@ -1329,7 +1329,7 @@ static void signal_name_owner_changed(const char *path, DBusMessageIter *iter) dbus_message_iter_next(iter); dbus_message_iter_get_basic(iter, &new); - if (old == NULL || new == NULL) + if (!old || !new) return; if (strlen(old) > 0 && strlen(new) == 0) { @@ -1370,7 +1370,7 @@ static void signal_interface_changed(const char *path, DBusMessageIter *iter) struct supplicant_interface *interface; interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) + if (!interface) return; supplicant_dbus_property_foreach(iter, interface_property, interface); @@ -1382,15 +1382,15 @@ static void signal_scan_done(const char *path, DBusMessageIter *iter) dbus_bool_t success = FALSE; interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) + if (!interface) return; dbus_message_iter_get_basic(iter, &success); - if (interface->scan_callback != NULL) { + if (interface->scan_callback) { int result = 0; - if (success == FALSE) + if (!success) result = -EIO; interface->scan_callback(result, interface->scan_data); @@ -1405,7 +1405,7 @@ static void signal_bss_added(const char *path, DBusMessageIter *iter) struct supplicant_interface *interface; interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) + if (!interface) return; interface_bss_added(iter, interface); @@ -1416,7 +1416,7 @@ static void signal_bss_removed(const char *path, DBusMessageIter *iter) struct supplicant_interface *interface; interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) + if (!interface) return; interface_bss_removed(iter, interface); @@ -1427,7 +1427,7 @@ static void signal_network_added(const char *path, DBusMessageIter *iter) struct supplicant_interface *interface; interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) + if (!interface) return; interface_network_added(iter, interface); @@ -1438,7 +1438,7 @@ static void signal_network_removed(const char *path, DBusMessageIter *iter) struct supplicant_interface *interface; interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) + if (!interface) return; interface_network_removed(iter, interface); @@ -1451,15 +1451,15 @@ static void signal_bss_changed(const char *path, DBusMessageIter *iter) struct supplicant_bss *bss; interface = g_hash_table_lookup(bss_mapping, path); - if (interface == NULL) + if (!interface) return; network = g_hash_table_lookup(interface->bss_mapping, path); - if (network == NULL) + if (!network) return; bss = g_hash_table_lookup(network->bss_table, path); - if (bss == NULL) + if (!bss) return; supplicant_dbus_property_foreach(iter, bss_property, bss); @@ -1497,19 +1497,17 @@ static DBusHandlerResult supplicant_filter(DBusConnection *conn, int i; path = dbus_message_get_path(message); - if (path == NULL) + if (!path) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - if (dbus_message_iter_init(message, &iter) == FALSE) + if (!dbus_message_iter_init(message, &iter)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - for (i = 0; signal_map[i].interface != NULL; i++) { - if (dbus_message_has_interface(message, - signal_map[i].interface) == FALSE) + for (i = 0; signal_map[i].interface; i++) { + if (!dbus_message_has_interface(message, signal_map[i].interface)) continue; - if (dbus_message_has_member(message, - signal_map[i].member) == FALSE) + if (!dbus_message_has_member(message, signal_map[i].member)) continue; signal_map[i].function(path, &iter); @@ -1541,11 +1539,10 @@ static const char *supplicant_rule6 = "type=signal," int supplicant_register(const struct supplicant_callbacks *callbacks) { connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); - if (connection == NULL) + if (!connection) return -EIO; - if (dbus_connection_add_filter(connection, - supplicant_filter, NULL, NULL) == FALSE) { + if (!dbus_connection_add_filter(connection, supplicant_filter, NULL, NULL)) { dbus_connection_unref(connection); connection = NULL; return -EIO; @@ -1572,7 +1569,7 @@ int supplicant_register(const struct supplicant_callbacks *callbacks) dbus_connection_flush(connection); if (dbus_bus_name_has_owner(connection, - SUPPLICANT_SERVICE, NULL) == TRUE) { + SUPPLICANT_SERVICE, NULL)) { system_available = TRUE; supplicant_bootstrap(); } @@ -1582,7 +1579,7 @@ int supplicant_register(const struct supplicant_callbacks *callbacks) void supplicant_unregister(const struct supplicant_callbacks *callbacks) { - if (connection != NULL) { + if (connection) { dbus_bus_remove_match(connection, supplicant_rule6, NULL); dbus_bus_remove_match(connection, supplicant_rule5, NULL); dbus_bus_remove_match(connection, supplicant_rule4, NULL); @@ -1596,20 +1593,20 @@ void supplicant_unregister(const struct supplicant_callbacks *callbacks) supplicant_filter, NULL); } - if (bss_mapping != NULL) { + if (bss_mapping) { g_hash_table_destroy(bss_mapping); bss_mapping = NULL; } - if (interface_table != NULL) { + if (interface_table) { g_hash_table_destroy(interface_table); interface_table = NULL; } - if (system_available == TRUE) + if (system_available) callback_system_killed(); - if (connection != NULL) { + if (connection) { dbus_connection_unref(connection); connection = NULL; } @@ -1621,7 +1618,7 @@ void supplicant_unregister(const struct supplicant_callbacks *callbacks) static void debug_level_result(const char *error, DBusMessageIter *iter, void *user_data) { - if (error != NULL) + if (error) DBG("debug level failure: %s", error); } @@ -1640,7 +1637,7 @@ static void debug_level_params(DBusMessageIter *iter, void *user_data) void supplicant_set_debug_level(unsigned int level) { - if (system_available == FALSE) + if (!system_available) return; supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE, @@ -1663,8 +1660,8 @@ static void interface_create_property(const char *key, DBusMessageIter *iter, struct interface_create_data *data = user_data; struct supplicant_interface *interface = data->interface; - if (key == NULL) { - if (data->callback != NULL) + if (!key) { + if (data->callback) data->callback(0, data->interface, data->user_data); dbus_free(data); @@ -1680,26 +1677,26 @@ static void interface_create_result(const char *error, const char *path = NULL; int err; - if (error != NULL) { + if (error) { err = -EIO; goto done; } dbus_message_iter_get_basic(iter, &path); - if (path == NULL) { + if (!path) { err = -EINVAL; goto done; } - if (system_available == FALSE) { + if (!system_available) { err = -EFAULT; goto done; } data->interface = g_hash_table_lookup(interface_table, path); - if (data->interface == NULL) { + if (!data->interface) { data->interface = interface_alloc(path); - if (data->interface == NULL) { + if (!data->interface) { err = -ENOMEM; goto done; } @@ -1712,7 +1709,7 @@ static void interface_create_result(const char *error, return; done: - if (data->callback != NULL) + if (data->callback) data->callback(err, NULL, data->user_data); dbus_free(data); @@ -1728,7 +1725,7 @@ static void interface_create_params(DBusMessageIter *iter, void *user_data) supplicant_dbus_dict_append_basic(&dict, "Ifname", DBUS_TYPE_STRING, &data->ifname); - if (data->driver != NULL) + if (data->driver) supplicant_dbus_dict_append_basic(&dict, "Driver", DBUS_TYPE_STRING, &data->driver); @@ -1743,22 +1740,22 @@ static void interface_get_result(const char *error, const char *path = NULL; int err; - if (error != NULL) + if (error) goto create; dbus_message_iter_get_basic(iter, &path); - if (path == NULL) { + if (!path) { err = -EINVAL; goto done; } interface = g_hash_table_lookup(interface_table, path); - if (interface == NULL) { + if (!interface) { err = -ENOENT; goto done; } - if (data->callback != NULL) + if (data->callback) data->callback(0, interface, data->user_data); dbus_free(data); @@ -1766,7 +1763,7 @@ static void interface_get_result(const char *error, return; create: - if (system_available == FALSE) { + if (!system_available) { err = -EFAULT; goto done; } @@ -1780,7 +1777,7 @@ create: return; done: - if (data->callback != NULL) + if (data->callback) data->callback(err, NULL, data->user_data); dbus_free(data); @@ -1799,14 +1796,14 @@ int supplicant_interface_create(const char *ifname, const char *driver, { struct interface_create_data *data; - if (ifname == NULL) + if (!ifname) return -EINVAL; - if (system_available == FALSE) + if (!system_available) return -EFAULT; data = dbus_malloc0(sizeof(*data)); - if (data == NULL) + if (!data) return -ENOMEM; data->ifname = ifname; @@ -1825,10 +1822,10 @@ int supplicant_interface_remove(struct supplicant_interface *interface, supplicant_interface_remove_callback callback, void *user_data) { - if (interface == NULL) + if (!interface) return -EINVAL; - if (system_available == FALSE) + if (!system_available) return -EFAULT; return 0; @@ -1845,8 +1842,8 @@ static void interface_scan_result(const char *error, { struct interface_scan_data *data = user_data; - if (error != NULL) { - if (data->callback != NULL) + if (error) { + if (data->callback) data->callback(-EIO, data->user_data); } else { data->interface->scan_callback = data->callback; @@ -1875,17 +1872,17 @@ int supplicant_interface_scan(struct supplicant_interface *interface, { struct interface_scan_data *data; - if (interface == NULL) + if (!interface) return -EINVAL; - if (system_available == FALSE) + if (!system_available) return -EFAULT; - if (interface->scanning == TRUE) + if (interface->scanning) return -EALREADY; data = dbus_malloc0(sizeof(*data)); - if (data == NULL) + if (!data) return -ENOMEM; data->interface = interface; @@ -1908,10 +1905,10 @@ static void interface_disconnect_result(const char *error, struct interface_disconnect_data *data = user_data; int result = 0; - if (error != NULL) + if (error) result = -EIO; - if (data->callback != NULL) + if (data->callback) data->callback(result, data->user_data); dbus_free(data); @@ -1923,14 +1920,14 @@ int supplicant_interface_disconnect(struct supplicant_interface *interface, { struct interface_disconnect_data *data; - if (interface == NULL) + if (!interface) return -EINVAL; - if (system_available == FALSE) + if (!system_available) return -EFAULT; data = dbus_malloc0(sizeof(*data)); - if (data == NULL) + if (!data) return -ENOMEM; data->callback = callback; diff --git a/tools/tap-test.c b/tools/tap-test.c index 1074c9c9..fdc098aa 100644 --- a/tools/tap-test.c +++ b/tools/tap-test.c @@ -49,7 +49,7 @@ static int inet_ifup(const char *ifname) return -errno; memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) { err = -errno; @@ -89,7 +89,7 @@ static int create_tap(const char *ifname) memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) { perror("Failed to set TUN/TAP interface"); diff --git a/tools/web-test.c b/tools/web-test.c index a5073974..55c58af5 100644 --- a/tools/web-test.c +++ b/tools/web-test.c @@ -43,7 +43,7 @@ static void sig_term(int sig) g_main_loop_quit(main_loop); } -static gboolean web_result(GWebResult *result, gpointer user_data) +static bool web_result(GWebResult *result, gpointer user_data) { const guint8 *chunk; gsize length; @@ -54,7 +54,7 @@ static gboolean web_result(GWebResult *result, gpointer user_data) if (length > 0) { printf("%s\n", (char *) chunk); - return TRUE; + return true; } status = g_web_result_get_status(result); @@ -67,10 +67,10 @@ static gboolean web_result(GWebResult *result, gpointer user_data) g_main_loop_quit(main_loop); - return FALSE; + return false; } -static gboolean option_debug = FALSE; +static bool option_debug = false; static gchar *option_proxy = NULL; static gchar *option_nameserver = NULL; static gchar *option_user_agent = NULL; @@ -101,8 +101,8 @@ 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 (error != NULL) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { + if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else @@ -118,32 +118,32 @@ int main(int argc, char *argv[]) } web = g_web_new(index); - if (web == NULL) { + if (!web) { fprintf(stderr, "Failed to create web service\n"); return 1; } - if (option_debug == TRUE) + if (option_debug) g_web_set_debug(web, web_debug, "WEB"); main_loop = g_main_loop_new(NULL, FALSE); - if (option_proxy != NULL) { + if (option_proxy) { g_web_set_proxy(web, option_proxy); g_free(option_proxy); } - if (option_nameserver != NULL) { + if (option_nameserver) { g_web_add_nameserver(web, option_nameserver); g_free(option_nameserver); } - if (option_user_agent != NULL) { + if (option_user_agent) { g_web_set_user_agent(web, "%s", option_user_agent); g_free(option_user_agent); } - if (option_http_version != NULL) { + if (option_http_version) { g_web_set_http_version(web, option_http_version); g_free(option_http_version); } diff --git a/tools/wispr.c b/tools/wispr.c index 122bea50..d5f9341f 100644 --- a/tools/wispr.c +++ b/tools/wispr.c @@ -100,7 +100,7 @@ static const char *response_code_to_string(int response_code) } struct wispr_msg { - gboolean has_error; + bool has_error; const char *current_element; int message_type; int response_code; @@ -114,7 +114,7 @@ struct wispr_msg { static inline void wispr_msg_init(struct wispr_msg *msg) { - msg->has_error = FALSE; + msg->has_error = false; msg->current_element = NULL; msg->message_type = -1; @@ -212,12 +212,11 @@ static void text_handler(GMarkupParseContext *context, struct wispr_msg *msg = user_data; int i; - if (msg->current_element == NULL) + if (!msg->current_element) return; for (i = 0; wispr_element_map[i].str; i++) { - if (g_str_equal(wispr_element_map[i].str, - msg->current_element) == FALSE) + if (!g_str_equal(wispr_element_map[i].str, msg->current_element)) continue; switch (wispr_element_map[i].element) { @@ -266,7 +265,7 @@ static void error_handler(GMarkupParseContext *context, { struct wispr_msg *msg = user_data; - msg->has_error = TRUE; + msg->has_error = true; } static const GMarkupParser wispr_parser = { @@ -281,7 +280,7 @@ static void parser_callback(const char *str, gpointer user_data) { struct wispr_session *wispr = user_data; GMarkupParseContext *context; - gboolean result; + bool result; //printf("%s\n", str); @@ -289,7 +288,7 @@ static void parser_callback(const char *str, gpointer user_data) G_MARKUP_TREAT_CDATA_AS_TEXT, &wispr->msg, NULL); result = g_markup_parse_context_parse(context, str, strlen(str), NULL); - if (result == TRUE) + if (result) g_markup_parse_context_end_parse(context, NULL); g_markup_parse_context_free(context); @@ -301,7 +300,7 @@ struct user_input_data { GString *str; user_input_cb cb; gpointer user_data; - gboolean hidden; + bool hidden; int fd; struct termios saved_termios; }; @@ -310,7 +309,7 @@ static void user_callback(struct user_input_data *data) { char *value; - if (data->hidden == TRUE) { + if (data->hidden) { ssize_t len; len = write(data->fd, "\n", 1); @@ -351,13 +350,13 @@ static gboolean keyboard_input(GIOChannel *channel, GIOCondition condition, g_string_append_c(data->str, buf[0]); - if (data->hidden == TRUE) + if (data->hidden) len = write(data->fd, "*", 1); return TRUE; } -static gboolean user_input(const char *label, gboolean hidden, +static bool user_input(const char *label, bool hidden, user_input_cb func, gpointer user_data) { struct user_input_data *data; @@ -367,8 +366,8 @@ static gboolean user_input(const char *label, gboolean hidden, ssize_t len; data = g_try_new0(struct user_input_data, 1); - if (data == NULL) - return FALSE; + if (!data) + return false; data->str = g_string_sized_new(32); data->cb = func; @@ -385,7 +384,7 @@ static gboolean user_input(const char *label, gboolean hidden, } new_termios = data->saved_termios; - if (data->hidden == TRUE) + if (data->hidden) new_termios.c_lflag &= ~(ICANON|ECHO); else new_termios.c_lflag &= ~ICANON; @@ -411,13 +410,13 @@ static gboolean user_input(const char *label, gboolean hidden, if (len < 0) goto error; - return TRUE; + return true; error: g_string_free(data->str, TRUE); g_free(data); - return FALSE; + return false; } static void password_callback(const char *value, gpointer user_data) @@ -439,8 +438,8 @@ static void username_callback(const char *value, gpointer user_data) g_free(wispr->username); wispr->username = g_strdup(value); - if (wispr->password == NULL) { - user_input("Password", TRUE, password_callback, wispr); + if (!wispr->password) { + user_input("Password", true, password_callback, wispr); return; } @@ -449,7 +448,7 @@ static void username_callback(const char *value, gpointer user_data) execute_login(wispr); } -static gboolean wispr_input(const guint8 **data, gsize *length, +static bool wispr_input(const guint8 **data, gsize *length, gpointer user_data) { struct wispr_session *wispr = user_data; @@ -473,10 +472,10 @@ static gboolean wispr_input(const guint8 **data, gsize *length, *data = (guint8 *) wispr->formdata; *length = count; - return FALSE; + return false; } -static gboolean wispr_route(const char *addr, int ai_family, int if_index, +static bool wispr_route(const char *addr, int ai_family, int if_index, gpointer user_data) { char *family = "unknown"; @@ -489,12 +488,12 @@ static gboolean wispr_route(const char *addr, int ai_family, int if_index, printf("Route request: %s %s index %d\n", family, addr, if_index); if (ai_family != AF_INET && ai_family != AF_INET6) - return FALSE; + return false; - return TRUE; + return true; } -static gboolean wispr_result(GWebResult *result, gpointer user_data) +static bool wispr_result(GWebResult *result, gpointer user_data) { struct wispr_session *wispr = user_data; const guint8 *chunk; @@ -507,7 +506,7 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) if (length > 0) { //printf("%s\n", (char *) chunk); g_web_parser_feed_data(wispr->parser, chunk, length); - return TRUE; + return true; } g_web_parser_end_data(wispr->parser); @@ -526,8 +525,7 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) if (status != 302) goto done; - if (g_web_result_get_header(result, "Location", - &redirect) == FALSE) + if (!g_web_result_get_header(result, "Location", &redirect)) goto done; printf("Redirect URL: %s\n", redirect); @@ -536,7 +534,7 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) wispr->request = g_web_request_get(wispr->web, redirect, wispr_result, wispr_route, wispr); - return FALSE; + return false; } printf("Message type: %s (%d)\n", @@ -545,17 +543,17 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) printf("Response code: %s (%d)\n", response_code_to_string(wispr->msg.response_code), wispr->msg.response_code); - if (wispr->msg.access_procedure != NULL) + if (wispr->msg.access_procedure) printf("Access procedure: %s\n", wispr->msg.access_procedure); - if (wispr->msg.access_location != NULL) + if (wispr->msg.access_location) printf("Access location: %s\n", wispr->msg.access_location); - if (wispr->msg.location_name != NULL) + if (wispr->msg.location_name) printf("Location name: %s\n", wispr->msg.location_name); - if (wispr->msg.login_url != NULL) + if (wispr->msg.login_url) printf("Login URL: %s\n", wispr->msg.login_url); - if (wispr->msg.abort_login_url != NULL) + if (wispr->msg.abort_login_url) printf("Abort login URL: %s\n", wispr->msg.abort_login_url); - if (wispr->msg.logoff_url != NULL) + if (wispr->msg.logoff_url) printf("Logoff URL: %s\n", wispr->msg.logoff_url); printf("\n"); @@ -563,18 +561,19 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) goto done; if (wispr->msg.message_type == 100) { - if (wispr->username == NULL) { - user_input("Username", FALSE, username_callback, wispr); - return FALSE; + if (!wispr->username) { + user_input("Username", false, + username_callback, wispr); + return false; } - if (wispr->password == NULL) { - user_input("Password", TRUE, password_callback, wispr); - return FALSE; + if (!wispr->password) { + user_input("Password", true, password_callback, wispr); + return false; } g_idle_add(execute_login, wispr); - return FALSE; + return false; } else if (wispr->msg.message_type == 120 || wispr->msg.message_type == 140) { int code = wispr->msg.response_code; @@ -585,8 +584,7 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) if (status == 302) { const char *redirect; - if (g_web_result_get_header(result, "Location", - &redirect) == FALSE) + if (!g_web_result_get_header(result, "Location", &redirect)) goto done; printf("\n"); @@ -596,13 +594,13 @@ static gboolean wispr_result(GWebResult *result, gpointer user_data) wispr->request = g_web_request_get(wispr->web, redirect, wispr_result, NULL, wispr); - return FALSE; + return false; } done: g_main_loop_quit(main_loop); - return FALSE; + return false; } static gboolean execute_login(gpointer user_data) @@ -618,7 +616,7 @@ static gboolean execute_login(gpointer user_data) return FALSE; } -static gboolean option_debug = FALSE; +static bool option_debug = false; static gchar *option_nameserver = NULL; static gchar *option_username = NULL; static gchar *option_password = NULL; @@ -649,8 +647,8 @@ 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 (error != NULL) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { + if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else @@ -664,17 +662,17 @@ int main(int argc, char *argv[]) wispr_msg_init(&wispr.msg); wispr.web = g_web_new(index); - if (wispr.web == NULL) { + if (!wispr.web) { fprintf(stderr, "Failed to create web service\n"); return 1; } - if (option_debug == TRUE) + if (option_debug) g_web_set_debug(wispr.web, web_debug, "WEB"); main_loop = g_main_loop_new(NULL, FALSE); - if (option_nameserver != NULL) { + if (option_nameserver) { g_web_add_nameserver(wispr.web, option_nameserver); g_free(option_nameserver); } @@ -683,7 +681,7 @@ int main(int argc, char *argv[]) g_web_set_user_agent(wispr.web, "SmartClient/%s wispr", VERSION); g_web_set_close_connection(wispr.web, TRUE); - if (option_url == NULL) + if (!option_url) option_url = g_strdup(DEFAULT_URL); wispr.username = option_username; diff --git a/tools/wpad-test.c b/tools/wpad-test.c index a6cc7926..2ecbcdae 100644 --- a/tools/wpad-test.c +++ b/tools/wpad-test.c @@ -63,12 +63,12 @@ static void resolv_result(GResolvResultStatus status, g_print("No result for %s\n", hostname); ptr = strchr(hostname + 5, '.'); - if (ptr == NULL || strlen(ptr) < 2) { + if (!ptr || strlen(ptr) < 2) { g_print("No more names\n"); goto done; } - if (strchr(ptr + 1, '.') == NULL) { + if (!strchr(ptr + 1, '.')) { g_print("Not found\n"); goto done; } @@ -86,7 +86,7 @@ done: g_print("elapse: %f seconds\n", elapsed); - if (results != NULL) { + if (results) { for (i = 0; results[i]; i++) g_print("result: %s\n", results[i]); } @@ -101,7 +101,7 @@ static void start_wpad(const char *search) char domainname[256]; char *hostname; - if (search == NULL) { + if (!search) { if (getdomainname(domainname, sizeof(domainname)) < 0) { g_printerr("Failed to get domain name\n"); goto quit; @@ -113,7 +113,7 @@ static void start_wpad(const char *search) g_printerr("Domain name is not set\n"); goto quit; } - + g_print("domainname: %s\n", domainname); hostname = g_strdup_printf("wpad.%s", domainname); @@ -126,7 +126,7 @@ quit: g_main_loop_quit(main_loop); } -static gboolean option_debug = FALSE; +static bool option_debug = false; static gchar *option_search = NULL; static GOptionEntry options[] = { @@ -147,8 +147,8 @@ 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 (error != NULL) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { + if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else @@ -159,12 +159,12 @@ int main(int argc, char *argv[]) g_option_context_free(context); resolv = g_resolv_new(index); - if (resolv == NULL) { + if (!resolv) { g_printerr("Failed to create resolver\n"); return 1; } - if (option_debug == TRUE) + if (option_debug) g_resolv_set_debug(resolv, resolv_debug, "RESOLV"); main_loop = g_main_loop_new(NULL, FALSE); -- cgit v1.2.3