| File: | libbaul-private/baul-extensions.c | 
| Warning: | line 234, column 46 Access to field 'filename' results in a dereference of a null pointer (loaded from variable 'ext')  | 
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * baul-extension.c - extension management functions | |||
| 3 | * | |||
| 4 | * Copyright (C) 2014 CAFE Desktop. | |||
| 5 | * | |||
| 6 | * This library is free software; you can redistribute it and/or | |||
| 7 | * modify it under the terms of the GNU Library General Public | |||
| 8 | * License as published by the Free Software Foundation; either | |||
| 9 | * version 2 of the License, or (at your option) any later version. | |||
| 10 | * | |||
| 11 | * This library is distributed in the hope that it will be useful, | |||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 14 | * Library General Public License for more details. | |||
| 15 | * | |||
| 16 | * You should have received a copy of the GNU Library General Public | |||
| 17 | * License along with this library; if not, write to the Free | |||
| 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, | |||
| 19 | * Boston, MA 02110-1301, USA. | |||
| 20 | * | |||
| 21 | * Author: Alexander van der Meij <alexandervdm@gliese.me> | |||
| 22 | */ | |||
| 23 | ||||
| 24 | #include "baul-extensions.h" | |||
| 25 | ||||
| 26 | #include "baul-global-preferences.h" | |||
| 27 | #include "baul-module.h" | |||
| 28 | #include "baul-debug-log.h" | |||
| 29 | ||||
| 30 | #include <string.h> | |||
| 31 | ||||
| 32 | #define BAUL_EXTENSION_GROUP"Baul Extension" "Baul Extension" | |||
| 33 | ||||
| 34 | static GList *baul_extensions = NULL((void*)0); | |||
| 35 | ||||
| 36 | ||||
| 37 | static Extension * | |||
| 38 | extension_new (gchar *filename, gboolean state, gboolean python, GObject *module) | |||
| 39 | { | |||
| 40 | GError *error = NULL((void*)0); | |||
| 41 | Extension *ext; | |||
| 42 | GKeyFile *extension_file; | |||
| 43 | gchar *extension_filename; | |||
| 44 | ||||
| 45 | ext = g_new0 (Extension, 1)((Extension *) g_malloc0_n ((1), sizeof (Extension))); | |||
| 46 | ext->filename = filename; | |||
| 47 | ext->name = NULL((void*)0); | |||
| 48 | ext->description = NULL((void*)0); | |||
| 49 | ext->author = NULL((void*)0); | |||
| 50 | ext->copyright = NULL((void*)0); | |||
| 51 | ext->version = NULL((void*)0); | |||
| 52 | ext->website = NULL((void*)0); | |||
| 53 | ext->state = state; | |||
| 54 | ext->module = module; | |||
| 55 | ||||
| 56 | extension_file = g_key_file_new (); | |||
| 57 | extension_filename = g_strdup_printf(BAUL_DATADIR"/usr/share/baul" "/extensions/%s.baul-extension", filename); | |||
| 58 | if (g_key_file_load_from_file (extension_file, extension_filename, G_KEY_FILE_NONE, &error)) | |||
| 59 | { | |||
| 60 | ext->name = g_key_file_get_locale_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Name", NULL((void*)0), NULL((void*)0)); | |||
| 61 | ext->description = g_key_file_get_locale_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Description", NULL((void*)0), NULL((void*)0)); | |||
| 62 | ext->icon = g_key_file_get_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Icon", NULL((void*)0)); | |||
| 63 | ext->author = g_key_file_get_string_list (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Author", NULL((void*)0), NULL((void*)0)); | |||
| 64 | ext->copyright = g_key_file_get_locale_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Copyright", NULL((void*)0), NULL((void*)0)); | |||
| 65 | ext->version = g_key_file_get_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Version", NULL((void*)0)); | |||
| 66 | ext->website = g_key_file_get_string (extension_file, BAUL_EXTENSION_GROUP"Baul Extension", "Website", NULL((void*)0)); | |||
| 67 | g_key_file_free (extension_file); | |||
| 68 | } | |||
| 69 | else | |||
| 70 | { | |||
| 71 | baul_debug_log (FALSE(0), BAUL_DEBUG_LOG_DOMAIN_USER"USER", "Error loading keys from file: %s\n", error->message); | |||
| 72 | g_error_free (error); | |||
| 73 | } | |||
| 74 | g_free (extension_filename); | |||
| 75 | ||||
| 76 | if (python) | |||
| 77 | { | |||
| 78 | ext->name = g_strconcat("Python: ", filename, NULL((void*)0)); | |||
| 79 | ext->description = "Python-baul extension"; | |||
| 80 | } | |||
| 81 | ||||
| 82 | return ext; | |||
| 83 | } | |||
| 84 | ||||
| 85 | /* functions related to persistent configuration through gsettings: */ | |||
| 86 | ||||
| 87 | static gboolean | |||
| 88 | gsettings_key_has_value (const gchar *value) | |||
| 89 | { | |||
| 90 | gchar **list; | |||
| 91 | gint i; | |||
| 92 | ||||
| 93 | list = g_settings_get_strv (baul_extension_preferences, | |||
| 94 | BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions"); | |||
| 95 | ||||
| 96 | if (list != NULL((void*)0)) | |||
| 97 | { | |||
| 98 | for (i = 0; list[i]; i++) | |||
| 99 | { | |||
| 100 | if (g_ascii_strcasecmp (value, list[i]) == 0) | |||
| 101 | { | |||
| 102 | g_strfreev (list); | |||
| 103 | return TRUE(!(0)); | |||
| 104 | } | |||
| 105 | } | |||
| 106 | } | |||
| 107 | g_strfreev (list); | |||
| 108 | return FALSE(0); | |||
| 109 | } | |||
| 110 | ||||
| 111 | static gboolean | |||
| 112 | gsettings_append_to_list (const char *value) | |||
| 113 | { | |||
| 114 | gchar **current; | |||
| 115 | gchar **new; | |||
| 116 | gint size; | |||
| 117 | gboolean retval; | |||
| 118 | ||||
| 119 | current = g_settings_get_strv (baul_extension_preferences, | |||
| 120 | BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions"); | |||
| 121 | ||||
| 122 | for (size = 0; current[size] != NULL((void*)0); size++); | |||
| 123 | ||||
| 124 | size += 1; | |||
| 125 | size += 1; | |||
| 126 | ||||
| 127 | new = g_realloc_n (current, size, sizeof (gchar *)); | |||
| 128 | ||||
| 129 | new[size - 2] = g_strdup (value)g_strdup_inline (value); | |||
| 130 | new[size - 1] = NULL((void*)0); | |||
| 131 | ||||
| 132 | retval = g_settings_set_strv (baul_extension_preferences, | |||
| 133 | BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions", | |||
| 134 | (const gchar **) new); | |||
| 135 | ||||
| 136 | g_strfreev (new); | |||
| 137 | return retval; | |||
| 138 | } | |||
| 139 | ||||
| 140 | static gboolean | |||
| 141 | gsettings_remove_from_list (const char *value) | |||
| 142 | { | |||
| 143 | gchar **current; | |||
| 144 | GArray *array; | |||
| 145 | gint i; | |||
| 146 | gboolean retval; | |||
| 147 | ||||
| 148 | current = g_settings_get_strv (baul_extension_preferences, | |||
| 149 | BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions"); | |||
| 150 | ||||
| 151 | array = g_array_new (TRUE(!(0)), TRUE(!(0)), sizeof (gchar *)); | |||
| 152 | ||||
| 153 | for (i = 0; current[i] != NULL((void*)0); i++) | |||
| 154 | { | |||
| 155 | if (g_strcmp0 (current[i], value) != 0) | |||
| 156 | array = g_array_append_val (array, current[i])g_array_append_vals (array, &(current[i]), 1); | |||
| 157 | } | |||
| 158 | ||||
| 159 | retval = g_settings_set_strv (baul_extension_preferences, | |||
| 160 | BAUL_PREFERENCES_DISABLED_EXTENSIONS"disabled-extensions", | |||
| 161 | (const gchar **) array->data); | |||
| 162 | ||||
| 163 | g_strfreev (current); | |||
| 164 | g_array_free (array, TRUE(!(0))); | |||
| 165 | return retval; | |||
| 166 | } | |||
| 167 | ||||
| 168 | /* functions related to the extension management */ | |||
| 169 | ||||
| 170 | static gboolean | |||
| 171 | baul_extension_get_state (const gchar *extname) | |||
| 172 | { | |||
| 173 | return !gsettings_key_has_value (extname); | |||
| 174 | } | |||
| 175 | ||||
| 176 | GList * | |||
| 177 | baul_extensions_get_for_type (GType type) | |||
| 178 | { | |||
| 179 | GList *l; | |||
| 180 | GList *ret = NULL((void*)0); | |||
| 181 | ||||
| 182 | for (l = baul_extensions; l != NULL((void*)0); l = l->next) | |||
| 183 | { | |||
| 184 | Extension *ext = l->data; | |||
| 185 | ext->state = baul_extension_get_state (ext->filename); | |||
| 186 | if (ext->state) // only load enabled extensions | |||
| 187 | { | |||
| 188 |             if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (ext->module), type)((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( ((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ext->module)), (((GType) ((20) << (2))))))))); GType __t = (type); gboolean __r; if (!__inst) __r = (0); else if ( __inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst , __t); __r; }))))  | |||
| 189 | { | |||
| 190 |                 g_object_ref (ext->module)((__typeof__ (ext->module)) (g_object_ref) (ext->module ));  | |||
| 191 | ret = g_list_prepend (ret, ext->module); | |||
| 192 | } | |||
| 193 | } | |||
| 194 | } | |||
| 195 | ||||
| 196 | return ret; | |||
| 197 | } | |||
| 198 | ||||
| 199 | GList * | |||
| 200 | baul_extensions_get_list (void) | |||
| 201 | { | |||
| 202 | return baul_extensions; | |||
| 203 | } | |||
| 204 | ||||
| 205 | void | |||
| 206 | baul_extension_register (gchar *filename, GObject *module) | |||
| 207 | { | |||
| 208 | gboolean ext_state = TRUE(!(0)); // new extensions are enabled by default. | |||
| 209 | gboolean ext_python = FALSE(0); | |||
| 210 | gchar *ext_filename; | |||
| 211 | ||||
| 212 | ext_filename = g_strndup (filename, strlen(filename) - 3); | |||
| 213 | ext_state = baul_extension_get_state (ext_filename); | |||
| 214 | ||||
| 215 |     if (g_str_has_suffix (filename, ".py")(__builtin_constant_p (".py")? __extension__ ({ const char * const __str = (filename); const char * const __suffix = (".py"); gboolean __result = (0); if (__str == ((void*)0) || __suffix == ((void *)0)) __result = (g_str_has_suffix) (__str, __suffix); else { const size_t __str_len = strlen (((__str) + !(__str))); const size_t __suffix_len = strlen (((__suffix) + !(__suffix))); if (__str_len >= __suffix_len) __result = memcmp (__str + __str_len - __suffix_len, ((__suffix) + !(__suffix)), __suffix_len) == 0; } __result; }) : (g_str_has_suffix) (filename, ".py") )) {  | |||
| 216 | ext_python = TRUE(!(0)); | |||
| 217 | } | |||
| 218 | ||||
| 219 | Extension *ext = extension_new (ext_filename, ext_state, ext_python, module); | |||
| 220 | baul_extensions = g_list_append (baul_extensions, ext); | |||
| 221 | } | |||
| 222 | ||||
| 223 | gboolean | |||
| 224 | baul_extension_set_state (Extension *ext, gboolean new_state) | |||
| 225 | { | |||
| 226 | if (ext) | |||
  | ||||
| 227 | { | |||
| 228 |         g_return_val_if_fail (ext->state != new_state, FALSE)do { if ((ext->state != new_state)) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "ext->state != new_state" ); return ((0)); } } while (0);  | |||
| 229 | ext->state = new_state; | |||
| 230 | } | |||
| 231 | ||||
| 232 | gboolean retval; | |||
| 233 | if (new_state) { | |||
| 234 | retval = gsettings_remove_from_list (ext->filename); | |||
  | ||||
| 235 | } | |||
| 236 | else { | |||
| 237 | retval = gsettings_append_to_list (ext->filename); | |||
| 238 | } | |||
| 239 | ||||
| 240 |     g_return_val_if_fail (retval == TRUE, FALSE)do { if ((retval == (!(0)))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "retval == TRUE") ; return ((0)); } } while (0);  | |||
| 241 | return TRUE(!(0)); | |||
| 242 | } | |||
| 243 |