Updated connman to version 1.35
[platform/upstream/connman.git] / tools / iptables-unit.c
old mode 100644 (file)
new mode 100755 (executable)
index e8616ef..426631a
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2013  BWM CarIT GmbH. All rights reserved.
+ *  Copyright (C) 2013-2014  BMW Car IT 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
 #endif
 
 #include <glib.h>
+#include <errno.h>
 
 #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;
        int i;
+       bool ret = true;
 
        cmd = g_strdup_printf(IPTABLES_SAVE " -t %s", table_name);
        g_spawn_command_line_sync(cmd, &output, NULL, NULL, error);
@@ -39,18 +41,20 @@ static connman_bool_t assert_rule(const char *table_name, const char *rule)
 
        lines = g_strsplit(output, "\n", 0);
        g_free(output);
+       if (!lines)
+               return false;
 
-       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])
+               ret = false;
 
-       return TRUE;
+       g_strfreev(lines);
+       return ret;
 }
 
 static void assert_rule_exists(const char *table_name, const char *rule)
@@ -404,7 +408,7 @@ static void test_nat_basic1(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)
@@ -412,7 +416,7 @@ static gboolean parse_debug(const char *key, const char *value,
        else
                option_debug = g_strdup("*");
 
-       return TRUE;
+       return true;
 }
 
 static GOptionEntry options[] = {
@@ -433,8 +437,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
@@ -444,7 +448,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();