Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/Remmina/Remmina.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAntenore Gatta <antenore@simbiosi.org>2019-10-17 18:26:28 +0300
committerAntenore Gatta <antenore@simbiosi.org>2019-10-17 18:26:28 +0300
commitf17fa9678bf5aeeb09418d21dd4c0c008da08d61 (patch)
tree84fbf944b3d1048d57fc57191c84b3cd594d1dbd /src
parent29fbbf6066001fba75ee7e5440f15cc9d2d03597 (diff)
Code cleaning and indentation
Diffstat (limited to 'src')
-rw-r--r--src/remmina_stats.c159
-rw-r--r--src/remmina_utils.c235
2 files changed, 186 insertions, 208 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;
-
}
diff --git a/src/remmina_utils.c b/src/remmina_utils.c
index bf44852bf..df2988477 100644
--- a/src/remmina_utils.c
+++ b/src/remmina_utils.c
@@ -57,67 +57,67 @@ struct utsname u;
* Some of the code in this file is taken from the VMware open client.
*/
typedef struct lsb_distro_info {
- gchar *name;
- gchar *scanstring;
+ gchar * name;
+ gchar * scanstring;
} LSBDistroInfo;
/*
-static LSBDistroInfo lsbFields[] = {
- { "DISTRIB_ID=", "DISTRIB_ID=%s" },
- { "DISTRIB_RELEASE=", "DISTRIB_RELEASE=%s" },
- { "DISTRIB_CODENAME=", "DISTRIB_CODENAME=%s" },
- { "DISTRIB_DESCRIPTION=", "DISTRIB_DESCRIPTION=%s" },
- { NULL, NULL },
-};
-*/
+ * static LSBDistroInfo lsbFields[] = {
+ * { "DISTRIB_ID=", "DISTRIB_ID=%s" },
+ * { "DISTRIB_RELEASE=", "DISTRIB_RELEASE=%s" },
+ * { "DISTRIB_CODENAME=", "DISTRIB_CODENAME=%s" },
+ * { "DISTRIB_DESCRIPTION=", "DISTRIB_DESCRIPTION=%s" },
+ * { NULL, NULL },
+ * };
+ */
typedef struct distro_info {
- gchar *name;
- gchar *filename;
+ gchar * name;
+ gchar * filename;
} DistroInfo;
static DistroInfo distroArray[] = {
- { "RedHat", "/etc/redhat-release" },
- { "RedHat", "/etc/redhat_version" },
- { "Sun", "/etc/sun-release" },
- { "SuSE", "/etc/SuSE-release" },
- { "SuSE", "/etc/novell-release" },
- { "SuSE", "/etc/sles-release" },
- { "SuSE", "/etc/os-release" },
- { "Debian", "/etc/debian_version" },
- { "Debian", "/etc/debian_release" },
- { "Ubuntu", "/etc/lsb-release" },
- { "Mandrake", "/etc/mandrake-release" },
- { "Mandriva", "/etc/mandriva-release" },
- { "Mandrake", "/etc/mandrakelinux-release" },
- { "TurboLinux", "/etc/turbolinux-release" },
- { "Fedora Core", "/etc/fedora-release" },
- { "Gentoo", "/etc/gentoo-release" },
- { "Novell", "/etc/nld-release" },
- { "Annvix", "/etc/annvix-release" },
- { "Arch", "/etc/arch-release" },
- { "Arklinux", "/etc/arklinux-release" },
- { "Aurox", "/etc/aurox-release" },
- { "BlackCat", "/etc/blackcat-release" },
- { "Cobalt", "/etc/cobalt-release" },
- { "Conectiva", "/etc/conectiva-release" },
- { "Immunix", "/etc/immunix-release" },
- { "Knoppix", "/etc/knoppix_version" },
- { "Linux-From-Scratch", "/etc/lfs-release" },
- { "Linux-PPC", "/etc/linuxppc-release" },
- { "MkLinux", "/etc/mklinux-release" },
- { "PLD", "/etc/pld-release" },
- { "Slackware", "/etc/slackware-version" },
- { "Slackware", "/etc/slackware-release" },
- { "SMEServer", "/etc/e-smith-release" },
- { "Solaris", "/etc/release" },
- { "Solus", "/etc/solus-release" },
- { "Tiny Sofa", "/etc/tinysofa-release" },
- { "UltraPenguin", "/etc/ultrapenguin-release" },
- { "UnitedLinux", "/etc/UnitedLinux-release" },
- { "VALinux", "/etc/va-release" },
- { "Yellow Dog", "/etc/yellowdog-release" },
- { NULL, NULL },
+ { "RedHat", "/etc/redhat-release" },
+ { "RedHat", "/etc/redhat_version" },
+ { "Sun", "/etc/sun-release" },
+ { "SuSE", "/etc/SuSE-release" },
+ { "SuSE", "/etc/novell-release" },
+ { "SuSE", "/etc/sles-release" },
+ { "SuSE", "/etc/os-release" },
+ { "Debian", "/etc/debian_version" },
+ { "Debian", "/etc/debian_release" },
+ { "Ubuntu", "/etc/lsb-release" },
+ { "Mandrake", "/etc/mandrake-release" },
+ { "Mandriva", "/etc/mandriva-release" },
+ { "Mandrake", "/etc/mandrakelinux-release" },
+ { "TurboLinux", "/etc/turbolinux-release" },
+ { "Fedora Core", "/etc/fedora-release" },
+ { "Gentoo", "/etc/gentoo-release" },
+ { "Novell", "/etc/nld-release" },
+ { "Annvix", "/etc/annvix-release" },
+ { "Arch", "/etc/arch-release" },
+ { "Arklinux", "/etc/arklinux-release" },
+ { "Aurox", "/etc/aurox-release" },
+ { "BlackCat", "/etc/blackcat-release" },
+ { "Cobalt", "/etc/cobalt-release" },
+ { "Conectiva", "/etc/conectiva-release" },
+ { "Immunix", "/etc/immunix-release" },
+ { "Knoppix", "/etc/knoppix_version" },
+ { "Linux-From-Scratch", "/etc/lfs-release" },
+ { "Linux-PPC", "/etc/linuxppc-release" },
+ { "MkLinux", "/etc/mklinux-release" },
+ { "PLD", "/etc/pld-release" },
+ { "Slackware", "/etc/slackware-version" },
+ { "Slackware", "/etc/slackware-release" },
+ { "SMEServer", "/etc/e-smith-release" },
+ { "Solaris", "/etc/release" },
+ { "Solus", "/etc/solus-release" },
+ { "Tiny Sofa", "/etc/tinysofa-release" },
+ { "UltraPenguin", "/etc/ultrapenguin-release" },
+ { "UnitedLinux", "/etc/UnitedLinux-release" },
+ { "VALinux", "/etc/va-release" },
+ { "Yellow Dog", "/etc/yellowdog-release" },
+ { NULL, NULL },
};
gint remmina_utils_strpos(const gchar *haystack, const gchar *needle)
@@ -224,11 +224,10 @@ gchar *remmina_utils_string_strip(const gchar *s)
if (p) {
gchar *p2 = p;
while (*s != '\0') {
- if (*s != '\t' && *s != '\n' && *s != '\"') {
+ if (*s != '\t' && *s != '\n' && *s != '\"')
*p2++ = *s++;
- } else {
+ else
++s;
- }
}
*p2 = '\0';
}
@@ -249,7 +248,7 @@ gchar *remmina_utils_string_strip(const gchar *s)
* @return Returns a string containing distro information verbatium from /etc/xxx-release (distro). Use g_free to free the string.
*
*/
-static gchar* remmina_utils_read_distrofile(gchar *filename)
+static gchar *remmina_utils_read_distrofile(gchar *filename)
{
TRACE_CALL(__func__);
gsize file_sz;
@@ -285,7 +284,7 @@ static gchar* remmina_utils_read_distrofile(gchar *filename)
* Return the current language defined in the LC_ALL.
* @return a language string or en_US.
*/
-gchar* remmina_utils_get_lang()
+gchar *remmina_utils_get_lang()
{
gchar *lang = setlocale(LC_ALL, NULL);
gchar *ptr;
@@ -294,9 +293,8 @@ gchar* remmina_utils_get_lang()
lang = "en_US\0";
} else {
ptr = strchr(lang, '.');
- if (ptr != NULL) {
+ if (ptr != NULL)
*ptr = '\0';
- }
}
return lang;
@@ -305,14 +303,14 @@ gchar* remmina_utils_get_lang()
* Return the OS name as in "uname -s".
* @return The OS name or NULL.
*/
-const gchar* remmina_utils_get_kernel_name()
+const gchar *remmina_utils_get_kernel_name()
{
TRACE_CALL(__func__);
if (u.sysname)
return u.sysname;
}
-const gchar* remmina_utils_get_kernel_release()
+const gchar *remmina_utils_get_kernel_release()
/**
* Return the OS version as in "uname -r".
* @return The OS release or NULL.
@@ -327,7 +325,7 @@ const gchar* remmina_utils_get_kernel_release()
* Return the machine hardware name as in "uname -m".
* @return The machine hardware name or NULL.
*/
-const gchar* remmina_utils_get_kernel_arch()
+const gchar *remmina_utils_get_kernel_arch()
{
TRACE_CALL(__func__);
if (u.machine)
@@ -338,13 +336,12 @@ const gchar* remmina_utils_get_kernel_arch()
* Print the Distributor as specified by the lsb_release command.
* @return the distributor ID string or NULL. Caller must free it with g_free().
*/
-gchar* remmina_utils_get_lsb_id()
+gchar *remmina_utils_get_lsb_id()
{
TRACE_CALL(__func__);
gchar *lsb_id = NULL;
- if (g_spawn_command_line_sync("/usr/bin/lsb_release -si", &lsb_id, NULL, NULL, NULL)) {
+ if (g_spawn_command_line_sync("/usr/bin/lsb_release -si", &lsb_id, NULL, NULL, NULL))
return lsb_id;
- }
return NULL;
}
@@ -352,7 +349,7 @@ gchar* remmina_utils_get_lsb_id()
* Print the Distribution description as specified by the lsb_release command.
* @return the Distribution description string or NULL. Caller must free it with g_free().
*/
-gchar* remmina_utils_get_lsb_description()
+gchar *remmina_utils_get_lsb_description()
{
TRACE_CALL(__func__);
gchar *lsb_description = NULL;
@@ -360,7 +357,7 @@ gchar* remmina_utils_get_lsb_description()
if (g_spawn_command_line_sync("/usr/bin/lsb_release -sd", &lsb_description, NULL, NULL, &err)) {
return lsb_description;
- }else {
+ } else {
g_debug("%s: could not execute lsb_release %s\n", __func__, err->message);
g_error_free(err);
}
@@ -372,13 +369,12 @@ gchar* remmina_utils_get_lsb_description()
* Print the Distribution release name as specified by the lsb_release command.
* @return the Distribution release name string or NULL. Caller must free it with g_free().
*/
-gchar* remmina_utils_get_lsb_release()
+gchar *remmina_utils_get_lsb_release()
{
TRACE_CALL(__func__);
gchar *lsb_release = NULL;
- if (g_spawn_command_line_sync("/usr/bin/lsb_release -sr", &lsb_release, NULL, NULL, NULL)) {
+ if (g_spawn_command_line_sync("/usr/bin/lsb_release -sr", &lsb_release, NULL, NULL, NULL))
return lsb_release;
- }
return NULL;
}
@@ -386,13 +382,12 @@ gchar* remmina_utils_get_lsb_release()
* Print the Distribution codename as specified by the lsb_release command.
* @return the codename string or NULL. Caller must free it with g_free().
*/
-gchar* remmina_utils_get_lsb_codename()
+gchar *remmina_utils_get_lsb_codename()
{
TRACE_CALL(__func__);
gchar *lsb_codename = NULL;
- if (g_spawn_command_line_sync("/usr/bin/lsb_release -sc", &lsb_codename, NULL, NULL, NULL)) {
+ if (g_spawn_command_line_sync("/usr/bin/lsb_release -sc", &lsb_codename, NULL, NULL, NULL))
return lsb_codename;
- }
return NULL;
}
@@ -401,7 +396,7 @@ gchar* remmina_utils_get_lsb_codename()
* Test each known distribution specific information file and print it’s content.
* @return a string or NULL. Caller must free it with g_free().
*/
-GHashTable* remmina_utils_get_etc_release()
+GHashTable *remmina_utils_get_etc_release()
{
TRACE_CALL(__func__);
gchar *etc_release = NULL;
@@ -417,8 +412,9 @@ GHashTable* remmina_utils_get_etc_release()
if (etc_release[0] != '\0') {
g_debug("%s: Distro description %s\n", __func__, etc_release);
g_hash_table_insert(r, distroArray[i].filename, etc_release);
- } else
+ } else {
g_free(etc_release);
+ }
}
}
return r;
@@ -428,7 +424,7 @@ GHashTable* remmina_utils_get_etc_release()
* A sample function to show how use the other fOS releated functions.
* @return a semicolon separated OS data like in "uname -srm".
*/
-const gchar* remmina_utils_get_os_info()
+const gchar *remmina_utils_get_os_info()
{
TRACE_CALL(__func__);
gchar *kernel_string;
@@ -437,14 +433,15 @@ const gchar* remmina_utils_get_os_info()
g_print("uname:");
kernel_string = g_strdup_printf("%s;%s;%s\n",
- remmina_utils_get_kernel_name(),
- remmina_utils_get_kernel_release(),
- remmina_utils_get_kernel_arch());
- if (!kernel_string || kernel_string[0] == '\0')
+ remmina_utils_get_kernel_name(),
+ remmina_utils_get_kernel_release(),
+ remmina_utils_get_kernel_arch());
+ if (!kernel_string || kernel_string[0] == '\0') {
kernel_string = g_strdup_printf("%s;%s;%s\n",
- "UNKNOWN",
- "UNKNOWN",
- "UNKNOWN");
+ "UNKNOWN",
+ "UNKNOWN",
+ "UNKNOWN");
+ }
return kernel_string;
}
@@ -461,51 +458,52 @@ const gchar* remmina_utils_get_os_info()
* Taken from https://github.com/ttuegel/notmuch do PR in case of substantial modifications.
*
*/
-gchar* remmina_sha1_file (const gchar *filename)
+gchar *remmina_sha1_file(const gchar *filename)
{
- FILE *file;
-#define BLOCK_SIZE 4096
- unsigned char block[BLOCK_SIZE];
- size_t bytes_read;
- GChecksum *sha1;
- char *digest = NULL;
+ FILE *file;
- file = fopen (filename, "r");
- if (file == NULL)
- return NULL;
+#define BLOCK_SIZE 4096
+ unsigned char block[BLOCK_SIZE];
+ size_t bytes_read;
+ GChecksum *sha1;
+ char *digest = NULL;
- sha1 = g_checksum_new (G_CHECKSUM_SHA1);
- if (sha1 == NULL)
- goto DONE;
+ file = fopen(filename, "r");
+ if (file == NULL)
+ return NULL;
- while (1) {
- bytes_read = fread (block, 1, 4096, file);
- if (bytes_read == 0) {
- if (feof (file))
- break;
- else if (ferror (file))
+ sha1 = g_checksum_new(G_CHECKSUM_SHA1);
+ if (sha1 == NULL)
goto DONE;
- } else {
- g_checksum_update (sha1, block, bytes_read);
+
+ while (1) {
+ bytes_read = fread(block, 1, 4096, file);
+ if (bytes_read == 0) {
+ if (feof(file))
+ break;
+ else if (ferror(file))
+ goto DONE;
+ } else {
+ g_checksum_update(sha1, block, bytes_read);
+ }
}
- }
- digest = g_strdup (g_checksum_get_string (sha1));
+ digest = g_strdup(g_checksum_get_string(sha1));
- DONE:
- if (sha1)
- g_checksum_free (sha1);
- if (file)
- fclose (file);
+DONE:
+ if (sha1)
+ g_checksum_free(sha1);
+ if (file)
+ fclose(file);
- return digest;
+ return digest;
}
/**
* Generate a random sting of chars to be used as part of UID for news or stats
- * @return a string or NULL. Caller must free it with g_free().
+ * @return a string or NULL. Caller must free it with g_free().
*/
-gchar* remmina_gen_random_uuid()
+gchar *remmina_gen_random_uuid()
{
TRACE_CALL(__func__);
GRand *rand;
@@ -519,16 +517,13 @@ gchar* remmina_gen_random_uuid()
g_get_current_time(&t);
rand = g_rand_new_with_seed((guint32)t.tv_sec ^ (guint32)t.tv_usec);
- for (i = 0; i < 7; i++) {
+ for (i = 0; i < 7; i++)
result[i] = alpha[g_rand_int_range(rand, 0, sizeof(alpha) - 1)];
- }
g_rand_set_seed(rand, (guint32)t.tv_usec);
- for (i = 0; i < 7; i++) {
+ for (i = 0; i < 7; i++)
result[i + 7] = alpha[g_rand_int_range(rand, 0, sizeof(alpha) - 1)];
- }
g_rand_free(rand);
return result;
}
-