diff options
author | Antenore Gatta <antenore@simbiosi.org> | 2019-10-17 18:26:28 +0300 |
---|---|---|
committer | Antenore Gatta <antenore@simbiosi.org> | 2019-10-17 18:26:28 +0300 |
commit | f17fa9678bf5aeeb09418d21dd4c0c008da08d61 (patch) | |
tree | 84fbf944b3d1048d57fc57191c84b3cd594d1dbd /src/remmina_stats.c | |
parent | 29fbbf6066001fba75ee7e5440f15cc9d2d03597 (diff) |
Code cleaning and indentation
Diffstat (limited to 'src/remmina_stats.c')
-rw-r--r-- | src/remmina_stats.c | 159 |
1 files changed, 71 insertions, 88 deletions
diff --git a/src/remmina_stats.c b/src/remmina_stats.c index f5cf8072c..5391e56eb 100644 --- a/src/remmina_stats.c +++ b/src/remmina_stats.c @@ -152,22 +152,23 @@ #include "remmina_plugin_manager.h" #ifdef GDK_WINDOWING_WAYLAND - #include <gdk/gdkwayland.h> +#include <gdk/gdkwayland.h> #endif #ifdef GDK_WINDOWING_X11 - #include <gdk/gdkx.h> +#include <gdk/gdkx.h> #endif #include "remmina_stats.h" struct utsname u; struct ProfilesData { - GHashTable *proto_count; - GHashTable *proto_date; - const gchar *protocol; /** Key in the proto_count hash table.*/ - const gchar *pdatestr; /** Date in string format in the proto_date hash table. */ - gint pcount; - gchar datestr; + GHashTable * proto_count; + GHashTable * preexec_count; + GHashTable * postexec_count; + GHashTable * proto_date; + const gchar * protocol; /** Key in the proto_count hash table.*/ + const gchar * pdatestr; /** Date in string format in the proto_date hash table. */ + gchar datestr; }; JsonNode *remmina_stats_get_uid() @@ -196,8 +197,8 @@ JsonNode *remmina_stats_get_uid() uname = g_get_user_name(); hname = g_get_host_name(); chs = g_checksum_new(G_CHECKSUM_SHA256); - g_checksum_update(chs, (const guchar*)uname, strlen(uname)); - g_checksum_update(chs, (const guchar*)hname, strlen(hname)); + g_checksum_update(chs, (const guchar *)uname, strlen(uname)); + g_checksum_update(chs, (const guchar *)hname, strlen(hname)); uid_suffix = g_checksum_get_string(chs); uid = g_strdup_printf("%s-%.10s", remmina_pref.periodic_usage_stats_uuid_prefix, uid_suffix); @@ -209,7 +210,6 @@ JsonNode *remmina_stats_get_uid() g_free(uid); return r; - } JsonNode *remmina_stats_get_os_info() @@ -237,80 +237,73 @@ JsonNode *remmina_stats_get_os_info() json_builder_set_member_name(b, "kernel_name"); kernel_name = g_strdup_printf("%s", remmina_utils_get_kernel_name()); - if (!kernel_name || kernel_name[0] == '\0') { + if (!kernel_name || kernel_name[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, kernel_name); - } g_free(kernel_name); json_builder_set_member_name(b, "kernel_release"); kernel_release = g_strdup_printf("%s", remmina_utils_get_kernel_release()); - if (!kernel_release || kernel_release[0] == '\0') { + if (!kernel_release || kernel_release[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, kernel_release); - } g_free(kernel_release); json_builder_set_member_name(b, "kernel_arch"); kernel_arch = g_strdup_printf("%s", remmina_utils_get_kernel_arch()); - if (!kernel_arch || kernel_arch[0] == '\0') { + if (!kernel_arch || kernel_arch[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, kernel_arch); - } g_free(kernel_arch); json_builder_set_member_name(b, "lsb_distributor"); id = remmina_utils_get_lsb_id(); - if (!id || id[0] == '\0') { + if (!id || id[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, id); - } g_free(id); json_builder_set_member_name(b, "lsb_distro_description"); description = remmina_utils_get_lsb_description(); - if (!description || description[0] == '\0') { + if (!description || description[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, description); - } g_free(description); json_builder_set_member_name(b, "lsb_distro_release"); release = remmina_utils_get_lsb_release(); - if (!release || release[0] == '\0') { + if (!release || release[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, release); - } g_free(release); json_builder_set_member_name(b, "lsb_distro_codename"); codename = remmina_utils_get_lsb_codename(); - if (!codename || codename[0] == '\0') { + if (!codename || codename[0] == '\0') json_builder_add_null_value(b); - }else { + else json_builder_add_string_value(b, codename); - } g_free(codename); etc_release = remmina_utils_get_etc_release(); json_builder_set_member_name(b, "etc_release"); if (etc_release) { json_builder_begin_object(b); - g_hash_table_iter_init (&iter, etc_release); - while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value)) { + g_hash_table_iter_init(&iter, etc_release); + while (g_hash_table_iter_next(&iter, (gpointer) & key, (gpointer) & value)) { json_builder_set_member_name(b, key); json_builder_add_string_value(b, value); } json_builder_end_object(b); g_hash_table_remove_all(etc_release); g_hash_table_unref(etc_release); - }else { + } else { json_builder_add_null_value(b); } @@ -350,7 +343,6 @@ JsonNode *remmina_stats_get_user_env() r = json_builder_get_root(b); g_object_unref(b); return r; - } JsonNode *remmina_stats_get_version() @@ -382,11 +374,10 @@ JsonNode *remmina_stats_get_version() json_builder_set_member_name(b, "flatpak_build"); /* Flatpak sandbox should contain the file ${XDG_RUNTIME_DIR}/flatpak-info */ flatpak_info = g_build_filename(g_get_user_runtime_dir(), "flatpak-info", NULL); - if (g_file_test(flatpak_info, G_FILE_TEST_EXISTS)) { + if (g_file_test(flatpak_info, G_FILE_TEST_EXISTS)) json_builder_add_int_value(b, 1); - } else { + else json_builder_add_int_value(b, 0); - } g_free(flatpak_info); json_builder_end_object(b); @@ -417,7 +408,6 @@ JsonNode *remmina_stats_get_gtk_version() r = json_builder_get_root(b); g_object_unref(b); return r; - } JsonNode *remmina_stats_get_gtk_backend() @@ -434,14 +424,14 @@ JsonNode *remmina_stats_get_gtk_backend() disp = gdk_display_get_default(); #ifdef GDK_WINDOWING_WAYLAND - if (GDK_IS_WAYLAND_DISPLAY(disp)) { + if (GDK_IS_WAYLAND_DISPLAY(disp)) bkend = "Wayland"; - }else + else #endif #ifdef GDK_WINDOWING_X11 - if (GDK_IS_X11_DISPLAY(disp)) { + if (GDK_IS_X11_DISPLAY(disp)) bkend = "X11"; - } else + else #endif bkend = "n/a"; @@ -449,7 +439,6 @@ JsonNode *remmina_stats_get_gtk_backend() json_node_init_string(r, bkend); return r; - } JsonNode *remmina_stats_get_wm_name() @@ -469,7 +458,7 @@ JsonNode *remmina_stats_get_wm_name() wmver = remmina_sysinfo_get_gnome_shell_version(); if (!wmver || wmver[0] == '\0') { remmina_log_print("Gnome Shell not found\n"); - }else { + } else { remmina_log_printf("Gnome Shell version: %s\n", wmver); json_builder_add_string_value(b, "Gnome Shell"); json_builder_set_member_name(b, "gnome_shell_ver"); @@ -483,13 +472,13 @@ JsonNode *remmina_stats_get_wm_name() /** When everything else fails with set the WM name to NULL **/ remmina_log_print("Cannot determine the Window Manger name\n"); json_builder_add_string_value(b, "n/a"); - }else { + } else { remmina_log_printf("Window Manger names %s\n", wmname); json_builder_add_string_value(b, wmname); } g_free(wmname); - end: +end: json_builder_end_object(b); r = json_builder_get_root(b); g_object_unref(b); @@ -534,7 +523,7 @@ JsonNode *remmina_stats_get_indicator() /** Remmina fallback to GtkStatusIcon/xembed */ json_builder_add_string_value(b, "Remmina icon on GtkStatusIcon/xembed"); #endif - }else { + } else { /** Remmina icon is NOT active */ json_builder_add_int_value(b, 0); } @@ -557,17 +546,18 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da gint count = 0; gpointer pcount, kpo; gpointer pdate, kdo; + gpointer ppreexec, kxo; + gpointer ppostexec, kpo; gchar *hday, *hmonth, *hyear; gchar *pday, *pmonth, *pyear; GDateTime *prof_gdate; /** Source date -> from profile */ - GDateTime *pdata_gdate; /** Destination date -> The date in the pdata structure */ + GDateTime *pdata_gdate; /** Destination date -> The date in the pdata structure */ - struct ProfilesData* pdata; - pdata = (struct ProfilesData*)user_data; + struct ProfilesData *pdata; + pdata = (struct ProfilesData *)user_data; pdata->protocol = remmina_file_get_string(remminafile, "protocol"); - //pdata->pdatestr = remmina_file_get_string(remminafile, "last_success"); const gchar *last_success = remmina_file_get_string(remminafile, "last_success"); g_debug("%s date %s", pdata->protocol, last_success); @@ -577,9 +567,9 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da pmonth = g_strdup_printf("%.2s", last_success + 4); pday = g_strdup_printf("%.2s", last_success + 6); prof_gdate = g_date_time_new_local( - atoi(pyear), - atoi(pmonth), - atoi(pday), 0, 0, 0); + atoi(pyear), + atoi(pmonth), + atoi(pday), 0, 0, 0); g_free(pyear); g_free(pmonth); g_free(pday); @@ -589,42 +579,40 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da if (pdata->protocol && pdata->protocol[0] != '\0') { if (g_hash_table_lookup_extended(pdata->proto_count, pdata->protocol, &kpo, &pcount)) { count = GPOINTER_TO_INT(pcount) + 1; - }else { + } else { count = 1; g_hash_table_insert(pdata->proto_count, g_strdup(pdata->protocol), GINT_TO_POINTER(count)); } g_hash_table_replace(pdata->proto_count, g_strdup(pdata->protocol), GINT_TO_POINTER(count)); pdate = NULL; if (g_hash_table_lookup_extended(pdata->proto_date, pdata->protocol, &kdo, &pdate)) { - pdata_gdate = NULL; if (pdate && strlen(pdate) >= 6) { pdata->pdatestr = g_strdup(pdate); - hyear = g_strdup_printf("%.4s", (char*)pdate); - hmonth = g_strdup_printf("%.2s", (char*)pdate + 4); - hday = g_strdup_printf("%.2s", (char*)pdate + 6); + hyear = g_strdup_printf("%.4s", (char *)pdate); + hmonth = g_strdup_printf("%.2s", (char *)pdate + 4); + hday = g_strdup_printf("%.2s", (char *)pdate + 6); pdata_gdate = g_date_time_new_local( - atoi(hyear), - atoi(hmonth), - atoi(hday), 0, 0, 0); + atoi(hyear), + atoi(hmonth), + atoi(hday), 0, 0, 0); g_free(hyear); g_free(hmonth); g_free(hday); } /** When both date in the hash and in the profile are valid we compare the date */ - if (prof_gdate != NULL && pdata_gdate != NULL ) { + if (prof_gdate != NULL && pdata_gdate != NULL) { g_debug("Comparing dates"); - gint res = g_date_time_compare( pdata_gdate, prof_gdate ); + gint res = g_date_time_compare(pdata_gdate, prof_gdate); /** If the date in the hash less than the date in the profile, we take the latter */ - if (res < 0 ) { + if (res < 0) { g_debug("hash date is less than profile date. Replacing date in the hashtable"); g_hash_table_replace(pdata->proto_date, g_strdup(pdata->protocol), g_strdup(last_success)); } else { g_debug("profile date is less than hash date. Replacing date in the hashtable"); g_hash_table_replace(pdata->proto_date, g_strdup(pdata->protocol), g_strdup(pdata->pdatestr)); } - } /** If the date in the profile is NOT valid and the date in the hash is valid we keep the latter */ if (prof_gdate == NULL && pdata_gdate != NULL) { @@ -642,22 +630,22 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da g_debug("All dates are NULL, replacing date in the hashtable"); g_hash_table_replace(pdata->proto_date, g_strdup(pdata->protocol), NULL); } - }else { + } else { /** If there is not the protocol in the hash, we add it */ /** If the date in the profile is not NULL we use it */ - if (pdata->pdatestr) { + if (pdata->pdatestr) g_hash_table_replace(pdata->proto_date, g_strdup(pdata->protocol), g_strdup(pdata->pdatestr)); - }else { + else /** Otherwise we set it to NULL */ g_hash_table_replace(pdata->proto_date, g_strdup(pdata->protocol), NULL); - } } } - g_debug("pdata set to %s protocol with last_success to %s", pdata->protocol, pdata->pdatestr); + g_debug("pdata set to %s protocol with last_success to %s", pdata->protocol, pdata->pdatestr); if (pdata_gdate) g_date_time_unref(pdata_gdate); if (prof_gdate) g_date_time_unref(prof_gdate); + count = 0; } /** @@ -708,9 +696,9 @@ JsonNode *remmina_stats_get_profiles() * not on the main thread */ pdata->proto_date = g_hash_table_new_full(g_str_hash, g_str_equal, - (GDestroyNotify)g_free, (GDestroyNotify)g_free); + (GDestroyNotify)g_free, (GDestroyNotify)g_free); pdata->proto_count = g_hash_table_new_full(g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); + (GDestroyNotify)g_free, NULL); profiles_count = remmina_file_manager_iterate( (GFunc)remmina_profiles_get_data, @@ -721,18 +709,18 @@ JsonNode *remmina_stats_get_profiles() g_hash_table_iter_init(&pcountiter, pdata->proto_count); while (g_hash_table_iter_next(&pcountiter, &pcountkey, &pcountvalue)) { - json_builder_set_member_name(b, (gchar*)pcountkey); + json_builder_set_member_name(b, (gchar *)pcountkey); json_builder_add_int_value(b, GPOINTER_TO_INT(pcountvalue)); } g_hash_table_iter_init(&pdateiter, pdata->proto_date); while (g_hash_table_iter_next(&pdateiter, &pdatekey, &pdatevalue)) { - s = g_strdup_printf("DATE_%s", (gchar*)pdatekey); + s = g_strdup_printf("DATE_%s", (gchar *)pdatekey); g_debug("Protocol date label: %s", s); json_builder_set_member_name(b, s); g_free(s); - json_builder_add_string_value(b, (gchar*)pdatevalue); - g_debug("Protocol date: %s", (gchar*)pdatevalue); + json_builder_add_string_value(b, (gchar *)pdatevalue); + g_debug("Protocol date: %s", (gchar *)pdatevalue); } json_builder_end_object(b); @@ -795,11 +783,10 @@ JsonNode *remmina_stats_get_master_password_status() json_builder_begin_object(b); json_builder_set_member_name(b, "master_password_status"); - if (remmina_pref_get_boolean("use_master_password")) { + if (remmina_pref_get_boolean("use_master_password")) json_builder_add_string_value(b, "ON"); - } else { + else json_builder_add_string_value(b, "OFF"); - } json_builder_end_object(b); r = json_builder_get_root(b); @@ -825,11 +812,10 @@ JsonNode *remmina_stats_get_kiosk_mode() json_builder_begin_object(b); json_builder_set_member_name(b, "kiosk_status"); - if (!kioskmode && kioskmode == FALSE) { + if (!kioskmode && kioskmode == FALSE) json_builder_add_string_value(b, "OFF"); - }else { + else json_builder_add_string_value(b, "ON"); - } json_builder_end_object(b); r = json_builder_get_root(b); @@ -838,8 +824,6 @@ JsonNode *remmina_stats_get_kiosk_mode() return r; } - - /** * Get all statistics in json format to send periodically to the PHP server. * The caller should free the returned buffer with g_free() @@ -917,5 +901,4 @@ JsonNode *remmina_stats_get_all() g_object_unref(b); return n; - } |