On 03/29/2012 04:52 PM, Jiri Moskovcak wrote:
+ else if (g_strcmp0(method_name, "DeleteProblem") == 0)
+ {
+ VERB1 log("DeleteProblem");
+
+ GList *problem_dirs = string_list_from_variant(parameters);
+
+ while (problem_dirs)
+ {
+ if (!dir_accessible_by_uid((const char*)problem_dirs->data,
caller_uid))
+ {
+ if (polkit_check_authorization_dname(caller,
"org.freedesktop.problems.getall") != PolkitYes)
+ { // if user didn't provide correct credentials, just move to
the next dir
+ problem_dirs = g_list_next((const
char*)problem_dirs->data);
Bug. You meant g_list_next(problem_dirs).
Unfortunately, compiler won't help here,
since /usr/include/glib-2.0/glib/glist.h casts the pointer:
#define g_list_next(list) ((list) ? (((GList *)(list))->next) :
NULL)
and thus suppresses type check.
I'd just use
problem_dirs = problem_dirs->next;
here...
+GList *string_list_from_variant(GVariant *variant)
+{
+ GList *list = NULL;
+ GVariantIter *iter;
+ gchar *str;
+ g_variant_get(variant, "(as)",&iter);
+ while (g_variant_iter_loop(iter, "s",&str))
+ {
+ VERB1 log("adding: %s", str);
+ list = g_list_prepend(list, xstrdup(str));
+ }
+ g_variant_unref(variant);
+
+ return list;
+}
It might make sense to g_list_reverse the list before returning:
people got to be surprised that "abc", "def" variant
converts to "def", "abc" list.
--
vda