getting closer...
$ grep glib *.c
polkit-authorization.c:#include <glib.h>
polkit-authorization-db.c:#include <glib.h>
polkit-authorization-db-dummy.c:#include <glib.h>
polkit-config.c:#include <glib.h>
polkit-context.c:#include <glib.h>
polkit-sysdeps.c:#include <glib.h>
AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],[compile with coverage profiling instrumentation (gcc only)]),enable_gcov=$enableval,enable_gcov=no)
AC_ARG_ENABLE(man-pages, [ --enable-man-pages build manual pages],enable_man_pages=$enableval,enable_man_pages=yes)
+AM_CONDITIONAL(KIT_BUILD_TESTS, test x$enable_tests = xyes)
AM_CONDITIONAL(POLKIT_BUILD_TESTS, test x$enable_tests = xyes)
if test x$enable_tests = xyes; then
+ AC_DEFINE(KIT_BUILD_TESTS,1,[Build test code])
AC_DEFINE(POLKIT_BUILD_TESTS,1,[Build test code])
fi
if test x$enable_gcov = xyes; then
## so that config.h changes when you toggle gcov support
+ AC_DEFINE_UNQUOTED(KIT_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
AC_DEFINE_UNQUOTED(POLKIT_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
-
- AC_MSG_CHECKING([for gcc 3.3 version of gcov file format])
- have_gcc33_gcov=no
- AC_RUN_IFELSE( [AC_LANG_PROGRAM( , [[ if (__GNUC__ >=3 && __GNUC_MINOR__ >= 3) exit (0); else exit (1); ]])],
- have_gcc33_gcov=yes)
- if test x$have_gcc33_gcov = xyes ; then
- AC_DEFINE_UNQUOTED(POLKIT_HAVE_GCC33_GCOV, 1, [Defined if we have gcc 3.3 and thus the new gcov format])
- fi
- AC_MSG_RESULT($have_gcc33_gcov)
fi
+AM_CONDITIONAL(KIT_GCOV_ENABLED, test x$enable_gcov = xyes)
AM_CONDITIONAL(POLKIT_GCOV_ENABLED, test x$enable_gcov = xyes)
data/polkit-dbus.pc
data/polkit-grant.pc
src/Makefile
+src/kit/Makefile
src/polkit/Makefile
src/polkit-dbus/Makefile
src/polkit-grant/Makefile
DOC_SOURCE_DIR=../src
# Used for dependencies
-HFILE_GLOB=$(top_srcdir)/src/polkit*/*.h
-CFILE_GLOB=$(top_srcdir)/src/polkit*/*.c
+HFILE_GLOB=$(top_srcdir)/src/*/*.h
+CFILE_GLOB=$(top_srcdir)/src/*/*.c
# Headers to ignore
IGNORE_HFILES= \
<xi:include href="spec/polkit-spec-configuration.xml" />
</reference>
+ <reference id="ref-internal">
+ <title>Internal API Reference</title>
+ <partintro>
+ <para>
+ This part presents the class and function reference for the
+ internal support classes, data structures and functions. These
+ symbols are not exported.
+ </para>
+ </partintro>
+ <xi:include href="xml/kit.xml"/>
+ <xi:include href="xml/kit-memory.xml"/>
+ <xi:include href="xml/kit-string.xml"/>
+ <xi:include href="xml/kit-message.xml"/>
+ <xi:include href="xml/kit-list.xml"/>
+ <xi:include href="xml/kit-hash.xml"/>
+ <xi:include href="xml/kit-file.xml"/>
+ </reference>
+
<reference id="ref-core">
<title>Core API Reference</title>
<partintro>
</partintro>
<xi:include href="xml/polkit-types.xml"/>
<xi:include href="xml/polkit-sysdeps.xml"/>
- <xi:include href="xml/polkit-memory.xml"/>
- <xi:include href="xml/polkit-list.xml"/>
- <xi:include href="xml/polkit-hash.xml"/>
<xi:include href="xml/polkit-error.xml"/>
<xi:include href="xml/polkit-result.xml"/>
<xi:include href="xml/polkit-action.xml"/>
-SUBDIRS = polkit polkit-dbus polkit-grant
+SUBDIRS = kit polkit polkit-dbus polkit-grant
clean-local :
rm -f *~
--- /dev/null
+## Process this file with automake to produce Makefile.in
+
+NULL =
+
+INCLUDES = \
+ -I$(top_builddir)/src -I$(top_srcdir)/src \
+ -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
+ -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+ -DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
+ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \
+ -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
+ -DKIT_COMPILATION \
+ @GLIB_CFLAGS@
+
+noinst_LTLIBRARIES=libkit.la
+
+
+libkit_la_SOURCES = \
+ kit.h \
+ kit-memory.h kit-memory.c \
+ kit-string.h kit-string.c \
+ kit-list.h kit-list.c \
+ kit-hash.h kit-hash.c \
+ kit-file.h kit-file.c \
+ kit-message.h kit-message.c \
+ $(NULL)
+
+
+## note that TESTS has special meaning (stuff to use in make check)
+## so if adding tests not to be run in make check, don't add them to
+## TESTS
+if KIT_BUILD_TESTS
+TESTS_ENVIRONMENT=
+TESTS=kit-test
+
+if KIT_GCOV_ENABLED
+clean-gcov:
+ rm -f *.gcov .libs/*.gcda
+
+.PHONY: coverage-report.txt
+coverage-report.txt :
+ $(top_srcdir)/test/create-coverage-report.sh kit $(filter %.c,$(libkit_la_SOURCES)) > coverage-report.txt
+
+check-coverage : clean-gcov all check coverage-report.txt
+ cat coverage-report.txt
+else
+coverage-report.txt:
+ @echo "Need to reconfigure with --enable-gcov"
+
+check-coverage:
+ @echo "Need to reconfigure with --enable-gcov"
+endif
+
+else
+TESTS=
+endif
+
+## we use noinst_PROGRAMS not check_PROGRAMS so that we build
+## even when not doing "make check"
+noinst_PROGRAMS=$(TESTS)
+
+kit_test_SOURCES= \
+ kit-test.h kit-test.c
+
+kit_test_LDADD=$(top_builddir)/src/kit/libkit.la
+kit_test_LDFLAGS=
+#@R_DYNAMIC_LDFLAG@
+
+
+clean-local :
+ rm -f *~ *.bb *.bbg *.da *.gcov .libs/*.da .libs/*.bbg
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-file.c : File utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include <kit/kit.h>
+#include "kit-test.h"
+
+
+/**
+ * SECTION:kit-file
+ * @title: File utilities
+ * @short_description: File utilities
+ *
+ * Various file utilities.
+ **/
+
+#define BUF_SIZE 4096
+
+/**
+ * kit_file_get_contents:
+ * @path: path to file
+ * @out_contents: Return location for allocated memory. Free with kit_free().
+ * @out_contents_size: Return location for size of the file.
+ *
+ * Reads an entire file into allocated memory.
+ *
+ * Returns: #TRUE if the file was read into memory; #FALSE if an error
+ * occured and errno will be set.
+ */
+kit_bool_t
+kit_file_get_contents (const char *path, char **out_contents, size_t *out_contents_size)
+{
+ int fd;
+ kit_bool_t ret;
+ ssize_t num_read;
+ char *p;
+ char *q;
+ size_t total_allocated;
+ size_t total_size;
+ char buf[BUF_SIZE];
+
+ kit_return_val_if_fail (path != NULL, FALSE);
+ kit_return_val_if_fail (out_contents != NULL, FALSE);
+ kit_return_val_if_fail (out_contents_size != NULL, FALSE);
+
+ fd = -1;
+ ret = FALSE;
+ *out_contents = NULL;
+
+ fd = open (path, O_RDONLY);
+ if (fd == 0)
+ goto out;
+
+ p = kit_malloc (BUF_SIZE);
+ if (p == NULL) {
+ errno = ENOMEM;
+ goto out;
+ }
+ total_allocated = BUF_SIZE;
+ total_size = 0;
+
+ do {
+ again:
+ num_read = read (fd, buf, BUF_SIZE);
+ if (num_read == -1) {
+ if (errno == EINTR)
+ goto again;
+ else
+ goto out;
+ }
+
+
+ if (total_size + num_read > total_allocated) {
+ total_allocated += BUF_SIZE;
+ q = kit_realloc (p, total_allocated);
+ if (q == NULL) {
+ errno = ENOMEM;
+ goto out;
+ }
+ p = q;
+ }
+
+ memcpy (p + total_size, buf, num_read);
+ total_size += num_read;
+
+ } while (num_read > 0);
+
+ /* add terminating zero */
+ if (total_size + 1 > total_allocated) {
+ total_allocated += BUF_SIZE;
+ q = kit_realloc (p, total_allocated);
+ if (q == NULL) {
+ errno = ENOMEM;
+ goto out;
+ }
+ p = q;
+ }
+ p[total_size] = '\0';
+
+ *out_contents = p;
+ *out_contents_size = total_size;
+ ret = TRUE;
+
+out:
+ if (fd >= 0) {
+ again2:
+ if (close (fd) != 0) {
+ if (errno == EINTR)
+ goto again2;
+ else
+ ret = FALSE;
+ }
+ }
+
+ if (!ret) {
+ kit_free (p);
+ *out_contents = NULL;
+ }
+
+ return ret;
+}
+
+static kit_bool_t
+_write_to_fd (int fd, const char *str, ssize_t str_len)
+{
+ kit_bool_t ret;
+ ssize_t written;
+
+ ret = FALSE;
+
+ written = 0;
+ while (written < str_len) {
+ ssize_t ret;
+ ret = write (fd, str + written, str_len - written);
+ if (ret < 0) {
+ if (errno == EAGAIN || errno == EINTR) {
+ continue;
+ } else {
+ goto out;
+ }
+ }
+ written += ret;
+ }
+
+ ret = TRUE;
+
+out:
+ return ret;
+}
+
+/**
+ * kit_file_set_contents:
+ * @path: path to file
+ * @mode: mode for file
+ * @contents: contents to set
+ * @contents_size: size of contents
+ *
+ * Writes all of contents to a file named @path, with good error
+ * checking. If a file called @path already exists it will be
+ * overwritten. This write is atomic in the sense that it is first
+ * written to a temporary file which is then renamed to the final
+ * name.
+ *
+ * If the file already exists hard links to @path will break. Also
+ * since the file is recreated, existing permissions, access control
+ * lists, metadata etc. may be lost. If @path is a symbolic link, the
+ * link itself will be replaced, not the linked file.
+ *
+ * Returns: #TRUE if contents were set; #FALSE if an error occured and
+ * errno will be set
+ */
+kit_bool_t
+kit_file_set_contents (const char *path, mode_t mode, const char *contents, size_t contents_size)
+{
+ int fd;
+ char *path_tmp;
+ kit_bool_t ret;
+
+ path_tmp = NULL;
+ ret = FALSE;
+
+ kit_return_val_if_fail ((contents == NULL && contents_size == 0) || (contents != NULL), FALSE);
+ kit_return_val_if_fail (path != NULL, FALSE);
+
+ path_tmp = kit_strdup_printf ("%s.XXXXXX", path);
+ if (path_tmp == NULL) {
+ errno = ENOMEM;
+ goto out;
+ }
+
+ fd = mkstemp (path_tmp);
+ if (fd < 0) {
+ kit_warning ("Cannot create file '%s': %m", path_tmp);
+ goto out;
+ }
+ if (fchmod (fd, mode) != 0) {
+ kit_warning ("Cannot change mode for '%s' to 0%o: %m", path_tmp, mode);
+ close (fd);
+ unlink (path_tmp);
+ goto out;
+ }
+
+ if (contents_size > 0) {
+ if (!_write_to_fd (fd, contents, contents_size)) {
+ kit_warning ("Cannot write to file %s: %m", path_tmp);
+ close (fd);
+ if (unlink (path_tmp) != 0) {
+ kit_warning ("Cannot unlink %s: %m", path_tmp);
+ }
+ goto out;
+ }
+ }
+ close (fd);
+
+ if (rename (path_tmp, path) != 0) {
+ kit_warning ("Cannot rename %s to %s: %m", path_tmp, path);
+ if (unlink (path_tmp) != 0) {
+ kit_warning ("Cannot unlink %s: %m", path_tmp);
+ }
+ goto out;
+ }
+
+ ret = TRUE;
+
+out:
+ if (path_tmp != NULL)
+ kit_free (path_tmp);
+
+ return ret;
+}
+
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+ char path[] = "/tmp/kit-test";
+ char *buf;
+ size_t buf_size;
+ char *p;
+ size_t s;
+ unsigned int n;
+
+ buf_size = 3 * BUF_SIZE;
+ if ((buf = kit_malloc (buf_size)) == NULL)
+ goto out;
+
+ for (n = 0; n < buf_size; n++)
+ buf[n] = n;
+
+ if (!kit_file_set_contents (path, 0400, buf, buf_size)) {
+ kit_assert (errno == ENOMEM);
+ } else {
+ if (!kit_file_get_contents (path, &p, &s)) {
+ kit_assert (errno == ENOMEM);
+ } else {
+ kit_assert (s == buf_size && memcmp (p, buf, buf_size) == 0);
+ kit_free (p);
+ }
+
+ kit_assert (unlink (path) == 0);
+
+ kit_assert (!kit_file_get_contents (path, &p, &s));
+ }
+
+ kit_free (buf);
+
+out:
+ return TRUE;
+}
+
+KitTest _test_file = {
+ "kit_file",
+ NULL,
+ NULL,
+ _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-file.h : File utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_FILE_H
+#define KIT_FILE_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+kit_bool_t kit_file_get_contents (const char *path, char **out_contents, size_t *out_contents_size);
+kit_bool_t kit_file_set_contents (const char *path, mode_t mode, const char *contents, size_t contents_size);
+
+KIT_END_DECLS
+
+#endif /* KIT_FILE_H */
+
+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
- * polkit-hash.c : Hash tables
+ * kit-hash.c : Hash tables
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
-#include <polkit/polkit-hash.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-test.h>
+#include <kit/kit-memory.h>
+#include <kit/kit-hash.h>
+#include <kit/kit-test.h>
/**
- * SECTION:polkit-hash
- * @title: Hash Tables
- * @short_description: Hash Tables
+ * SECTION:kit-hash
+ * @title: Hash tables
+ * @short_description: Hash tables
*
* This class provides support for hash tables.
- *
- * Since: 0.7
**/
-struct _PolKitHashNode;
+struct _KitHashNode;
-typedef struct _PolKitHashNode {
+typedef struct _KitHashNode {
void *key;
void *value;
- struct _PolKitHashNode *next;
-} PolKitHashNode;
+ struct _KitHashNode *next;
+} KitHashNode;
/**
- * PolKitHash:
- *
- * The #PolKitHash structure not be accessed directly.
+ * KitHash:
*
- * Since: 0.7
+ * The #KitHash structure not be accessed directly.
*/
-struct _PolKitHash
+struct _KitHash
{
int refcount;
int num_top_nodes;
- PolKitHashNode **top_nodes;
-
- PolKitHashFunc hash_func;
- PolKitEqualFunc key_equal_func;
- PolKitCopyFunc key_copy_func;
- PolKitCopyFunc value_copy_func;
- PolKitFreeFunc key_destroy_func;
- PolKitFreeFunc value_destroy_func;
+ KitHashNode **top_nodes;
+
+ KitHashFunc hash_func;
+ KitEqualFunc key_equal_func;
+ KitCopyFunc key_copy_func;
+ KitCopyFunc value_copy_func;
+ KitFreeFunc key_destroy_func;
+ KitFreeFunc value_destroy_func;
};
/**
- * polkit_hash_new:
+ * kit_hash_new:
* @hash_func: The hash function to use
* @key_equal_func: The function used to determine key equality
* @key_copy_func: Function for copying keys or #NULL
* Creates a new Hash Table.
*
* Returns: The new hash table. Returns #NULL on OOM.
- *
- * Since: 0.7
*/
-PolKitHash *
-polkit_hash_new (PolKitHashFunc hash_func,
- PolKitEqualFunc key_equal_func,
- PolKitCopyFunc key_copy_func,
- PolKitCopyFunc value_copy_func,
- PolKitFreeFunc key_destroy_func,
- PolKitFreeFunc value_destroy_func)
+KitHash *
+kit_hash_new (KitHashFunc hash_func,
+ KitEqualFunc key_equal_func,
+ KitCopyFunc key_copy_func,
+ KitCopyFunc value_copy_func,
+ KitFreeFunc key_destroy_func,
+ KitFreeFunc value_destroy_func)
{
- PolKitHash *h;
+ KitHash *h;
- g_return_val_if_fail (hash_func != NULL, NULL);
- g_return_val_if_fail (key_equal_func != NULL, NULL);
+ kit_return_val_if_fail (hash_func != NULL, NULL);
+ kit_return_val_if_fail (key_equal_func != NULL, NULL);
- h = p_new0 (PolKitHash, 1);
+ h = kit_new0 (KitHash, 1);
if (h == NULL)
goto error;
h->value_destroy_func = value_destroy_func;
h->num_top_nodes = 11; /* TODO: configurable? */
- h->top_nodes = p_new0 (PolKitHashNode*, h->num_top_nodes);
+ h->top_nodes = kit_new0 (KitHashNode*, h->num_top_nodes);
if (h->top_nodes == NULL)
goto error;
return h;
error:
if (h != NULL)
- polkit_hash_unref (h);
+ kit_hash_unref (h);
return NULL;
}
/**
- * polkit_hash_ref:
+ * kit_hash_ref:
* @hash: the hash table
*
* Increase reference count.
*
* Returns: the hash table
- *
- * Since: 0.7
*/
-PolKitHash *
-polkit_hash_ref (PolKitHash *hash)
+KitHash *
+kit_hash_ref (KitHash *hash)
{
- g_return_val_if_fail (hash != NULL, hash);
+ kit_return_val_if_fail (hash != NULL, hash);
hash->refcount++;
return hash;
}
/**
- * polkit_hash_unref:
+ * kit_hash_unref:
* @hash: the hash table
*
* Decrease reference count. If reference count drop to zero the hash
* table is freed.
- *
- * Since: 0.7
*/
void
-polkit_hash_unref (PolKitHash *hash)
+kit_hash_unref (KitHash *hash)
{
- g_return_if_fail (hash != NULL);
+ kit_return_if_fail (hash != NULL);
hash->refcount--;
if (hash->refcount > 0)
int n;
for (n = 0; n < hash->num_top_nodes; n++) {
- PolKitHashNode *node;
- PolKitHashNode *next;
+ KitHashNode *node;
+ KitHashNode *next;
for (node = hash->top_nodes[n]; node != NULL; node = next) {
if (hash->key_destroy_func != NULL)
if (hash->value_destroy_func != NULL)
hash->value_destroy_func (node->value);
next = node->next;
- p_free (node);
+ kit_free (node);
}
}
}
- p_free (hash->top_nodes);
- p_free (hash);
+ kit_free (hash->top_nodes);
+ kit_free (hash);
}
/**
- * polkit_hash_insert:
+ * kit_hash_insert:
* @hash: the hash table
* @key: key to insert
* @value: value to insert
* new value.
*
* Returns: #TRUE unless OOM
- *
- * Since: 0.7
*/
-polkit_bool_t
-polkit_hash_insert (PolKitHash *hash,
+kit_bool_t
+kit_hash_insert (KitHash *hash,
void *key,
void *value)
{
int bucket;
- PolKitHashNode **nodep;
- PolKitHashNode *node;
+ KitHashNode **nodep;
+ KitHashNode *node;
void *key_copy;
void *value_copy;
- g_return_val_if_fail (hash != NULL, FALSE);
- g_return_val_if_fail (key != NULL, FALSE);
+ kit_return_val_if_fail (hash != NULL, FALSE);
+ kit_return_val_if_fail (key != NULL, FALSE);
key_copy = NULL;
value_copy = NULL;
}
}
- node = p_new0 (PolKitHashNode, 1);
+ node = kit_new0 (KitHashNode, 1);
if (node == NULL)
goto oom;
}
/**
- * polkit_hash_lookup:
+ * kit_hash_lookup:
* @hash: the hash table
* @key: key to look up
* @found: if not #NULL, will return #TRUE only if the key was found in the hash table
* Look up a value in the hash table.
*
* Returns: the value; caller shall not free/unref this value
- *
- * Since: 0.7
*/
void *
-polkit_hash_lookup (PolKitHash *hash, void *key, polkit_bool_t *found)
+kit_hash_lookup (KitHash *hash, void *key, kit_bool_t *found)
{
int bucket;
void *value;
- PolKitHashNode *node;
+ KitHashNode *node;
value = NULL;
if (found != NULL)
*found = FALSE;
- g_return_val_if_fail (hash != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
+ kit_return_val_if_fail (hash != NULL, NULL);
+ kit_return_val_if_fail (key != NULL, NULL);
bucket = hash->hash_func (key) % hash->num_top_nodes;
/**
- * polkit_hash_foreach:
+ * kit_hash_foreach:
* @hash: the hash table
* @cb: callback function
* @user_data: user data
* Iterate over all elements in a hash table
*
* Returns: #TRUE only if the callback short-circuited the iteration
- *
- * Since: 0.7
*/
-polkit_bool_t
-polkit_hash_foreach (PolKitHash *hash, PolKitHashForeachFunc cb, void *user_data)
+kit_bool_t
+kit_hash_foreach (KitHash *hash, KitHashForeachFunc cb, void *user_data)
{
int n;
- g_return_val_if_fail (hash != NULL, FALSE);
- g_return_val_if_fail (cb != NULL, FALSE);
+ kit_return_val_if_fail (hash != NULL, FALSE);
+ kit_return_val_if_fail (cb != NULL, FALSE);
for (n = 0; n < hash->num_top_nodes; n++) {
- PolKitHashNode *node;
+ KitHashNode *node;
for (node = hash->top_nodes[n]; node != NULL; node = node->next) {
if (cb (hash, node->key, node->value, user_data))
/**
- * polkit_hash_direct_hash_func:
+ * kit_hash_direct_hash_func:
* @key: the key
*
* Converts a pointer to a hash value.
*
* Returns: a hash value corresponding to the key
- *
- * Since: 0.7
*/
-polkit_uint32_t
-polkit_hash_direct_hash_func (const void *key)
+uint32_t
+kit_hash_direct_hash_func (const void *key)
{
- /* TODO: reimplement */
- return g_direct_hash (key);
+ return (uint32_t) key;
}
/**
- * polkit_hash_direct_equal_func:
+ * kit_hash_direct_equal_func:
* @v1: first value
* @v2: second value
*
* Compares two pointers and return #TRUE if they are equal (same address).
*
* Returns: #TRUE only if the values are equal
- *
- * Since: 0.7
*/
-polkit_bool_t
-polkit_hash_direct_equal_func (const void *v1, const void *v2)
+kit_bool_t
+kit_hash_direct_equal_func (const void *v1, const void *v2)
{
- /* TODO: reimplement */
- return g_direct_equal (v1, v2);
+ return v1 == v2;
}
/**
- * polkit_hash_str_hash_func:
+ * kit_hash_str_hash_func:
* @key: the key
*
* Converts a string to a hash value.
*
* Returns: a hash value corresponding to the key
- *
- * Since: 0.7
*/
-polkit_uint32_t
-polkit_hash_str_hash_func (const void *key)
+uint32_t
+kit_hash_str_hash_func (const void *key)
{
const char *p;
- polkit_uint32_t hash;
+ uint32_t hash;
hash = 0;
for (p = key; *p != '\0'; p++)
}
/**
- * polkit_hash_str_equal_func:
+ * kit_hash_str_equal_func:
* @v1: first value
* @v2: second value
*
* Compares two strings and return #TRUE if they are equal.
*
* Returns: #TRUE only if the values are equal
- *
- * Since: 0.7
*/
-polkit_bool_t
-polkit_hash_str_equal_func (const void *v1, const void *v2)
+kit_bool_t
+kit_hash_str_equal_func (const void *v1, const void *v2)
{
return strcmp (v1, v2) == 0;
}
/**
- * polkit_hash_str_copy:
+ * kit_hash_str_copy:
* @p: void pointer to string
*
- * Similar to p_strdup() except for types.
+ * Similar to kit_strdup() except for types.
*
* Returns: a void pointer to a copy or #NULL on OOM
*/
void *
-polkit_hash_str_copy (const void *p)
+kit_hash_str_copy (const void *p)
{
- return (void *) p_strdup ((const char *) p);
+ return (void *) kit_strdup ((const char *) p);
}
-#ifdef POLKIT_BUILD_TESTS
+#ifdef KIT_BUILD_TESTS
-static polkit_bool_t
-_it1 (PolKitHash *hash, void *key, void *value, void *user_data)
+static kit_bool_t
+_it1 (KitHash *hash, void *key, void *value, void *user_data)
{
int *count = (int *) user_data;
*count += 1;
return FALSE;
}
-static polkit_bool_t
-_it2 (PolKitHash *hash, void *key, void *value, void *user_data)
+static kit_bool_t
+_it2 (KitHash *hash, void *key, void *value, void *user_data)
{
int *count = (int *) user_data;
*count += 1;
return TRUE;
}
-static polkit_bool_t
+static kit_bool_t
_run_test (void)
{
int count;
- PolKitHash *h;
- polkit_bool_t found;
+ KitHash *h;
+ kit_bool_t found;
/* string hash tables */
- if ((h = polkit_hash_new (polkit_hash_str_hash_func, polkit_hash_str_equal_func,
- polkit_hash_str_copy, polkit_hash_str_copy,
- p_free, p_free)) != NULL) {
+ if ((h = kit_hash_new (kit_hash_str_hash_func, kit_hash_str_equal_func,
+ kit_hash_str_copy, kit_hash_str_copy,
+ kit_free, kit_free)) != NULL) {
int n;
char *key;
char *value;
/* first insert the values */
for (n = 0; test_data [n*2] != NULL; n++) {
- if (!polkit_hash_insert (h, test_data [n*2], test_data [n*2 + 1])) {
+ if (!kit_hash_insert (h, test_data [n*2], test_data [n*2 + 1])) {
goto oom;
}
}
/* then check that we can look them up */
for (n = 0; test_data [n*2] != NULL; n++) {
key = test_data [n*2];
- value = polkit_hash_lookup (h, test_data[n*2], &found);
+ value = kit_hash_lookup (h, test_data[n*2], &found);
- g_assert (found && strcmp (value, test_data[n*2 + 1]) == 0);
+ kit_assert (found && strcmp (value, test_data[n*2 + 1]) == 0);
}
/* lookup unknown key */
- g_assert (polkit_hash_lookup (h, "unknown", &found) == NULL && !found);
+ kit_assert (kit_hash_lookup (h, "unknown", &found) == NULL && !found);
/* replace key */
if (key != NULL) {
- if (polkit_hash_insert (h, "key1", "val1-replaced")) {
+ if (kit_hash_insert (h, "key1", "val1-replaced")) {
/* check for replaced value */
- value = polkit_hash_lookup (h, "key1", &found);
- g_assert (found && value != NULL && strcmp (value, "val1-replaced") == 0);
+ value = kit_hash_lookup (h, "key1", &found);
+ kit_assert (found && value != NULL && strcmp (value, "val1-replaced") == 0);
}
}
count = 0;
- g_assert (polkit_hash_foreach (h, _it1, &count) == FALSE);
- g_assert (count == ((sizeof (test_data) / sizeof (char *) - 1) / 2));
+ kit_assert (kit_hash_foreach (h, _it1, &count) == FALSE);
+ kit_assert (count == ((sizeof (test_data) / sizeof (char *) - 1) / 2));
count = 0;
- g_assert (polkit_hash_foreach (h, _it2, &count) == TRUE);
- g_assert (count == 1);
+ kit_assert (kit_hash_foreach (h, _it2, &count) == TRUE);
+ kit_assert (count == 1);
- polkit_hash_ref (h);
- polkit_hash_unref (h);
+ kit_hash_ref (h);
+ kit_hash_unref (h);
oom:
- polkit_hash_unref (h);
+ kit_hash_unref (h);
}
/* direct hash tables */
- if ((h = polkit_hash_new (polkit_hash_direct_hash_func, polkit_hash_direct_equal_func,
+ if ((h = kit_hash_new (kit_hash_direct_hash_func, kit_hash_direct_equal_func,
NULL, NULL,
NULL, NULL)) != NULL) {
- if (polkit_hash_insert (h, h, h)) {
- g_assert ((polkit_hash_lookup (h, h, &found) == h) && found);
- if (polkit_hash_insert (h, h, NULL)) {
- g_assert (polkit_hash_lookup (h, h, &found) == NULL && found);
+ if (kit_hash_insert (h, h, h)) {
+ kit_assert ((kit_hash_lookup (h, h, &found) == h) && found);
+ if (kit_hash_insert (h, h, NULL)) {
+ kit_assert (kit_hash_lookup (h, h, &found) == NULL && found);
}
}
- polkit_hash_unref (h);
+ kit_hash_unref (h);
}
return TRUE;
}
-PolKitTest _test_hash = {
- "polkit_hash",
+KitTest _test_hash = {
+ "kit_hash",
NULL,
NULL,
_run_test
};
-#endif /* POLKIT_BUILD_TESTS */
+#endif /* KIT_BUILD_TESTS */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-hash.h : Hash tables
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_HASH_H
+#define KIT_HASH_H
+
+#include <stdint.h>
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+struct _KitHash;
+typedef struct _KitHash KitHash;
+
+/**
+ * KitHashFunc:
+ * @key: a key
+ *
+ * The function is passed a key and should return a hash value. The
+ * functions kit_hash_direct_hash_func() and
+ * kit_hash_str_hash_func() provide hash functions which can be
+ * used when the key is a pointer and an char* respectively.
+ *
+ * Returns: the hash value corresponding to the key
+ *
+ * Since: 0.7
+ */
+typedef uint32_t (*KitHashFunc) (const void *key);
+
+/**
+ * KitEqualFunc:
+ * @key1: first key
+ * @key2: second key
+ *
+ * Determines if two keys are equal. The functions
+ * kit_hash_direct_equal_func() and kit_hash_str_equal_func()
+ * provide equality functions which can be used when the key is a
+ * pointer and an char* respectively.
+ *
+ * Returns: #TRUE iff the keys are equal
+ *
+ * Since: 0.7
+ */
+typedef kit_bool_t (*KitEqualFunc) (const void *key1, const void *key2);
+
+/**
+ * KitFreeFunc:
+ * @p: pointer
+ *
+ * Specifies the type of function which is called when a data element
+ * is destroyed. It is passed the pointer to the data element and
+ * should free any memory and resources allocated for it. The function
+ * p_free() or any of the object unref functions can be passed here.
+ *
+ * Since: 0.7
+ */
+typedef void (*KitFreeFunc) (void *p);
+
+/**
+ * KitCopyFunc:
+ * @p: pointer
+ *
+ * Specifies the type of function which is called when a data element
+ * is to be cloned or reffed. It is passed the pointer to the data
+ * element and should return a new pointer to a reffed or cloned
+ * object. The function kit_hash_str_copy() or any of the object
+ * ref functions can be passed here.
+ *
+ * Returns: A copy or ref of the object in question
+ *
+ * Since: 0.7
+ */
+typedef void *(*KitCopyFunc) (const void *p);
+
+/**
+ * KitHashForeachFunc:
+ * @hash: the hash table
+ * @key: key
+ * @value: value
+ * @user_data: user data passed to kit_hash_foreach()
+ *
+ * Type signature for callback function used in kit_hash_foreach().
+ *
+ * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
+ *
+ * Since: 0.7
+ */
+typedef kit_bool_t (*KitHashForeachFunc) (KitHash *hash,
+ void *key,
+ void *value,
+ void *user_data);
+
+
+KitHash *kit_hash_new (KitHashFunc hash_func,
+ KitEqualFunc key_equal_func,
+ KitCopyFunc key_copy_func,
+ KitCopyFunc value_copy_func,
+ KitFreeFunc key_destroy_func,
+ KitFreeFunc value_destroy_func);
+
+KitHash *kit_hash_ref (KitHash *hash);
+void kit_hash_unref (KitHash *hash);
+
+kit_bool_t kit_hash_insert (KitHash *hash, void *key, void *value);
+
+void *kit_hash_lookup (KitHash *hash, void *key, kit_bool_t *found);
+
+kit_bool_t kit_hash_foreach (KitHash *hash, KitHashForeachFunc cb, void *user_data);
+
+
+uint32_t kit_hash_direct_hash_func (const void *key);
+kit_bool_t kit_hash_direct_equal_func (const void *v1, const void *v2);
+
+uint32_t kit_hash_str_hash_func (const void *key);
+kit_bool_t kit_hash_str_equal_func (const void *v1, const void *v2);
+void *kit_hash_str_copy (const void *p);
+
+KIT_END_DECLS
+
+#endif /* KIT_HASH_H */
+
+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
- * polkit-list.c : Doubly-linked lists
+ * kit-list.c : Doubly-linked lists
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
-#include <polkit/polkit-list.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-test.h>
+#include <kit/kit.h>
+#include "kit-test.h"
/**
- * SECTION:polkit-list
+ * SECTION:kit-list
* @title: Doubly-linked lists
* @short_description: Doubly-linked lists
*
* This class provides support for doubly-linked lists.
- *
- * Since: 0.7
**/
/**
- * polkit_list_append:
+ * kit_list_append:
* @list: existing list or #NULL to create a new list
* @data: data to append to the list
*
* Append an entry to a list.
*
* Returns: the head of the new list or #NULL on OOM
- *
- * Since: 0.7
*/
-PolKitList *
-polkit_list_append (PolKitList *list, void *data)
+KitList *
+kit_list_append (KitList *list, void *data)
{
- PolKitList *l;
- PolKitList *j;
+ KitList *l;
+ KitList *j;
for (j = list; j != NULL && j->next != NULL; j = j->next)
;
- l = p_new0 (PolKitList, 1);
+ l = kit_new0 (KitList, 1);
if (l == NULL)
goto oom;
}
/**
- * polkit_list_prepend:
+ * kit_list_prepend:
* @list: existing list or #NULL to create a new list
* @data: data to prepend to the list
*
* Prepend an entry to a list.
*
* Returns: the head of the new list or #NULL on OOM
- *
- * Since: 0.7
*/
-PolKitList *
-polkit_list_prepend (PolKitList *list, void *data)
+KitList *
+kit_list_prepend (KitList *list, void *data)
{
- PolKitList *l;
+ KitList *l;
- l = p_new0 (PolKitList, 1);
+ l = kit_new0 (KitList, 1);
if (l == NULL)
goto oom;
}
/**
- * polkit_list_delete_link:
+ * kit_list_delete_link:
* @list: existing list, cannot be #NULL
* @link: link to delete, cannot be #NULL
*
* Delete a link from a list.
*
* Returns: the new head of the list or #NULL if the list is empty after deletion.
- *
- * Since: 0.7
*/
-PolKitList *
-polkit_list_delete_link (PolKitList *list, PolKitList *link)
+KitList *
+kit_list_delete_link (KitList *list, KitList *link)
{
- PolKitList *ret;
+ KitList *ret;
- g_return_val_if_fail (list != NULL, NULL);
- g_return_val_if_fail (link != NULL, NULL);
+ kit_return_val_if_fail (list != NULL, NULL);
+ kit_return_val_if_fail (link != NULL, NULL);
if (list == link)
ret = link->next;
link->next->prev = link->prev;
}
- p_free (link);
+ kit_free (link);
return ret;
}
/**
- * polkit_list_free:
+ * kit_list_free:
* @list: the list
*
* Frees all links in a list
- *
- * Since: 0.7
*/
void
-polkit_list_free (PolKitList *list)
+kit_list_free (KitList *list)
{
- PolKitList *l;
- PolKitList *j;
+ KitList *l;
+ KitList *j;
for (l = list; l != NULL; l = j) {
j = l->next;
- p_free (l);
+ kit_free (l);
}
}
/**
- * polkit_list_length:
+ * kit_list_length:
* @list: the list
*
* Compute the length of a list.
*
* Returns: Number of entries in list
- *
- * Since: 0.7
*/
size_t
-polkit_list_length (PolKitList *list)
+kit_list_length (KitList *list)
{
ssize_t n;
- PolKitList *l;
+ KitList *l;
n = 0;
for (l = list; l != NULL; l = l->next)
}
/**
- * polkit_list_foreach:
+ * kit_list_foreach:
* @list: the list
* @func: callback function
* @user_data: user data to pass to callback
* Iterate over all entries in a list.
*
* Returns: #TRUE only if the callback short-circuited the iteration
- *
- * Since: 0.7
*/
-polkit_bool_t
-polkit_list_foreach (PolKitList *list, PolKitListForeachFunc func, void *user_data)
+kit_bool_t
+kit_list_foreach (KitList *list, KitListForeachFunc func, void *user_data)
{
- PolKitList *l;
+ KitList *l;
- g_return_val_if_fail (list != NULL, FALSE);
- g_return_val_if_fail (func != NULL, FALSE);
+ kit_return_val_if_fail (list != NULL, FALSE);
+ kit_return_val_if_fail (func != NULL, FALSE);
for (l = list; l != NULL; l = l->next) {
if (func (list, l->data, user_data))
}
-#ifdef POLKIT_BUILD_TESTS
+#ifdef KIT_BUILD_TESTS
typedef struct {
int num;
int result;
} _Closure;
-static polkit_bool_t
-_sum (PolKitList *list, void *data, void *user_data)
+static kit_bool_t
+_sum (KitList *list, void *data, void *user_data)
{
_Closure *c = (_Closure*) user_data;
return FALSE;
}
-static polkit_bool_t
-_sum2 (PolKitList *list, void *data, void *user_data)
+static kit_bool_t
+_sum2 (KitList *list, void *data, void *user_data)
{
_Closure *c = (_Closure*) user_data;
return FALSE;
}
-static polkit_bool_t
+static kit_bool_t
_run_test (void)
{
_Closure c;
int items[] = {1, 2, 3, 4, 5};
unsigned int num_items = sizeof (items) / sizeof (int);
unsigned int n;
- PolKitList *l;
- PolKitList *j;
+ KitList *l;
+ KitList *j;
l = NULL;
for (n = 0; n < num_items; n++) {
j = l;
- l = polkit_list_prepend (l, (void *) items[n]);
+ l = kit_list_prepend (l, (void *) items[n]);
if (l == NULL)
goto oom;
}
- g_assert (polkit_list_length (l) == num_items);
+ kit_assert (kit_list_length (l) == num_items);
c.num = 0;
c.result = 0;
- polkit_list_foreach (l, _sum, &c);
- g_assert (c.result == 1*5 + 2*4 + 3*3 + 4*2 + 5*1);
+ kit_list_foreach (l, _sum, &c);
+ kit_assert (c.result == 1*5 + 2*4 + 3*3 + 4*2 + 5*1);
c.num = 0;
c.result = 0;
- polkit_list_foreach (l, _sum2, &c);
- g_assert (c.result == 1*5 + 2*4);
+ kit_list_foreach (l, _sum2, &c);
+ kit_assert (c.result == 1*5 + 2*4);
- l = polkit_list_delete_link (l, l);
- g_assert (polkit_list_length (l) == num_items - 1);
+ l = kit_list_delete_link (l, l);
+ kit_assert (kit_list_length (l) == num_items - 1);
c.num = 0;
c.result = 0;
- polkit_list_foreach (l, _sum, &c);
- g_assert (c.result == 1*4 + 2*3 + 3*2 + 4*1);
+ kit_list_foreach (l, _sum, &c);
+ kit_assert (c.result == 1*4 + 2*3 + 3*2 + 4*1);
- l = polkit_list_delete_link (l, l->next);
- g_assert (polkit_list_length (l) == num_items - 2);
+ l = kit_list_delete_link (l, l->next);
+ kit_assert (kit_list_length (l) == num_items - 2);
c.num = 0;
c.result = 0;
- polkit_list_foreach (l, _sum, &c);
- g_assert (c.result == 1*4 + 2*2 + 3*1);
+ kit_list_foreach (l, _sum, &c);
+ kit_assert (c.result == 1*4 + 2*2 + 3*1);
- polkit_list_free (l);
+ kit_list_free (l);
l = NULL;
for (n = 0; n < num_items; n++) {
j = l;
- l = polkit_list_append (l, (void *) items[n]);
+ l = kit_list_append (l, (void *) items[n]);
if (l == NULL)
goto oom;
}
c.num = 0;
c.result = 0;
- polkit_list_foreach (l, _sum, &c);
- g_assert (c.result == 1*1 + 2*2 + 3*3 + 4*4 + 5*5);
+ kit_list_foreach (l, _sum, &c);
+ kit_assert (c.result == 1*1 + 2*2 + 3*3 + 4*4 + 5*5);
- polkit_list_free (l);
+ kit_list_free (l);
return TRUE;
oom:
- polkit_list_free (j);
+ kit_list_free (j);
return TRUE;
}
-PolKitTest _test_list = {
- "polkit_list",
+KitTest _test_list = {
+ "kit_list",
NULL,
NULL,
_run_test
};
-#endif /* POLKIT_BUILD_TESTS */
+#endif /* KIT_BUILD_TESTS */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
- * polkit-list.h : Doubly-linked list
+ * kit-list.h : Doubly-linked list
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
*
**************************************************************************/
-#if !defined (POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H)
-#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
#endif
-#ifndef POLKIT_LIST_H
-#define POLKIT_LIST_H
+#ifndef KIT_LIST_H
+#define KIT_LIST_H
-#include <polkit/polkit-types.h>
+#include <kit/kit.h>
-POLKIT_BEGIN_DECLS
+KIT_BEGIN_DECLS
-struct _PolKitList;
-typedef struct _PolKitList PolKitList;
+struct _KitList;
+typedef struct _KitList KitList;
/**
- * PolKitList:
- * @data: the value passed in polkit_list_append() and polkit_list_prepend()
+ * KitList:
+ * @data: the value passed in kit_list_append() and kit_list_prepend()
* @next: the next element in the list or #NULL if this is the last element
* @prev: the previous element in the list or #NULL if this is the last element
*
- * Public members of the #PolKitList data structure
+ * Public members of the #KitList data structure
*
* Since: 0.7
*/
-struct _PolKitList {
+struct _KitList {
void *data;
- PolKitList *next;
- PolKitList *prev;
+ KitList *next;
+ KitList *prev;
};
/**
- * PolKitListForeachFunc:
+ * KitListForeachFunc:
* @list: the list
* @data: data of link entry
- * @user_data: user data passed to polkit_list_foreach()
+ * @user_data: user data passed to kit_list_foreach()
*
- * Type signature for callback function used in polkit_list_foreach().
+ * Type signature for callback function used in kit_list_foreach().
*
* Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
*
* Since: 0.7
*/
-typedef polkit_bool_t (*PolKitListForeachFunc) (PolKitList *list,
- void *data,
- void *user_data);
+typedef kit_bool_t (*KitListForeachFunc) (KitList *list,
+ void *data,
+ void *user_data);
-PolKitList *polkit_list_append (PolKitList *list, void *data);
-PolKitList *polkit_list_prepend (PolKitList *list, void *data);
-void polkit_list_free (PolKitList *list);
-PolKitList *polkit_list_delete_link (PolKitList *list, PolKitList *link);
+KitList *kit_list_append (KitList *list, void *data);
+KitList *kit_list_prepend (KitList *list, void *data);
+void kit_list_free (KitList *list);
+KitList *kit_list_delete_link (KitList *list, KitList *link);
-size_t polkit_list_length (PolKitList *list);
-polkit_bool_t polkit_list_foreach (PolKitList *list, PolKitListForeachFunc func, void *user_data);
+size_t kit_list_length (KitList *list);
+kit_bool_t kit_list_foreach (KitList *list, KitListForeachFunc func, void *user_data);
-POLKIT_END_DECLS
+KIT_END_DECLS
-#endif /* POLKIT_LIST_H */
+#endif /* KIT_LIST_H */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-memory.c : Memory management
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <kit/kit-memory.h>
+#include <kit/kit-test.h>
+
+/**
+ * SECTION:kit-memory
+ * @title: Memory management
+ * @short_description: Memory management
+ *
+ * Functions used for memory management.
+ **/
+
+
+#ifdef KIT_BUILD_TESTS
+
+static int _cur_allocs = 0;
+static int _total_allocs = 0;
+static int _fail_nth = -1;
+
+void
+_kit_memory_reset (void)
+{
+ _cur_allocs = 0;
+ _total_allocs = 0;
+ _fail_nth = -1;
+}
+
+int
+_kit_memory_get_current_allocations (void)
+{
+ return _cur_allocs;
+}
+
+int
+_kit_memory_get_total_allocations (void)
+{
+ return _total_allocs;
+}
+
+void
+_kit_memory_fail_nth_alloc (int number)
+{
+ _fail_nth = number;
+}
+
+/**
+ * kit_malloc:
+ * @bytes: number of 8-bit bytes to allocate
+ *
+ * Allocate memory
+ *
+ * Returns: memory location or #NULL on OOM. Free with kit_free().
+ */
+void *
+kit_malloc (size_t bytes)
+{
+ void *p;
+
+ if (_fail_nth != -1 && _total_allocs == _fail_nth) {
+ return NULL;
+ }
+
+ p = malloc (bytes);
+
+ if (p != NULL) {
+ _cur_allocs++;
+ _total_allocs++;
+ }
+
+ return p;
+}
+
+/**
+ * kit_malloc0:
+ * @bytes: number of 8-bit bytes to allocate
+ *
+ * Allocate memory and zero it.
+ *
+ * Returns: memory location or #NULL on OOM. Free with kit_free().
+ */
+void *
+kit_malloc0 (size_t bytes)
+{
+ void *p;
+
+ if (_fail_nth != -1 && _total_allocs == _fail_nth) {
+ return NULL;
+ }
+
+ p = calloc (1, bytes);
+
+ if (p != NULL) {
+ _cur_allocs++;
+ _total_allocs++;
+ }
+
+ return p;
+}
+
+/**
+ * kit_realloc:
+ * @memory: memory previously allocated
+ * @bytes: new size
+ *
+ * Reallocate memory; like realloc(3).
+ *
+ * Returns: memory location or #NULL on OOM. Free with kit_free().
+ */
+void *
+kit_realloc (void *memory, size_t bytes)
+{
+ void *p;
+
+ if (memory == NULL)
+ return kit_malloc (bytes);
+
+ if (bytes == 0) {
+ kit_free (memory);
+ return memory;
+ }
+
+ if (_fail_nth != -1 && _total_allocs == _fail_nth) {
+ return NULL;
+ }
+
+ p = realloc (memory, bytes);
+
+ return p;
+}
+
+/**
+ * kit_free:
+ * @memory: pointer to memory allocated with kit_malloc() + friends
+ *
+ * Free memory allocated by kit_malloc() + friends.
+ */
+void
+kit_free (void *memory)
+{
+ free (memory);
+ if (memory != NULL) {
+ _cur_allocs--;
+ }
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
+#else
+/*--------------------------------------------------------------------------------------------------------------*/
+
+void *
+kit_malloc (size_t bytes)
+{
+ return malloc (bytes);
+}
+
+void *
+kit_malloc0 (size_t bytes)
+{
+ return calloc (1, bytes);
+}
+
+void *
+kit_realloc (void *memory, size_t bytes)
+{
+ return realloc (memory, bytes);
+}
+
+void
+kit_free (void *memory)
+{
+ free (memory);
+}
+
+void
+_kit_memory_reset (void)
+{
+}
+
+int
+_kit_memory_get_current_allocations (void)
+{
+ return -1;
+}
+
+int
+_kit_memory_get_total_allocations (void)
+{
+ return -1;
+}
+
+void
+_kit_memory_fail_nth_alloc (int number)
+{
+}
+
+#endif /* KIT_BUILD_TESTS */
+
+
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+ int n;
+ char *p;
+ char *p2;
+
+ if ((p = kit_malloc (1000)) != NULL) {
+ for (n = 0; n < 1000; n++)
+ p[n] = n;
+
+ p2 = kit_realloc (p, 2000);
+ if (p2 != NULL) {
+ p = p2;
+
+ for (n = 0; n < 2000; n++)
+ p[n] = n;
+ }
+
+ kit_free (p);
+ }
+
+ if ((p = kit_realloc (NULL, 1000)) != NULL) {
+ for (n = 0; n < 1000; n++)
+ p[n] = n;
+
+ kit_realloc (p, 0);
+ }
+
+ if ((p = kit_malloc0 (1000)) != NULL) {
+ for (n = 0; n < 1000; n++)
+ kit_assert (p[n] == '\0');
+ kit_free (p);
+ }
+
+ return TRUE;
+}
+
+KitTest _test_memory = {
+ "kit_memory",
+ NULL,
+ NULL,
+ _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
- * polkit-memory.h : Memory management
+ * kit-memory.h : Memory management
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
*
**************************************************************************/
-#if !defined (POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H)
-#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
#endif
-#ifndef POLKIT_MEMORY_H
-#define POLKIT_MEMORY_H
+#ifndef KIT_MEMORY_H
+#define KIT_MEMORY_H
#include <stdarg.h>
-#include <polkit/polkit-types.h>
+#include <stdlib.h>
+#include <kit/kit.h>
-POLKIT_BEGIN_DECLS
+KIT_BEGIN_DECLS
-void *p_malloc (size_t bytes);
-void *p_malloc0 (size_t bytes);
-void *p_realloc (void *memory, size_t bytes);
-void p_free (void *memory);
+void *kit_malloc (size_t bytes);
+void *kit_malloc0 (size_t bytes);
+void *kit_realloc (void *memory, size_t bytes);
+void kit_free (void *memory);
/**
- * p_new:
+ * kit_new:
* @type: the type of object to allocate
* @count: number of objects to allocate
*
*
* Returns: Allocated memory, cast to a pointer of #type or #NULL on OOM.
*/
-#define p_new(type, count) ((type*)p_malloc (sizeof (type) * (count)));
+#define kit_new(type, count) ((type*)kit_malloc (sizeof (type) * (count)));
/**
- * p_new0:
+ * kit_new0:
* @type: the type of object to allocate
* @count: number of objects to allocate
*
*
* Returns: Allocated memory, cast to a pointer of #type or #NULL on OOM.
*/
-#define p_new0(type, count) ((type*)p_malloc0 (sizeof (type) * (count)));
+#define kit_new0(type, count) ((type*)kit_malloc0 (sizeof (type) * (count)));
-char *p_strdup (const char *s);
-char *p_strndup (const char *s, size_t n);
-char* p_strdup_printf (const char *format, ...);
-char* p_strdup_vprintf (const char *format, va_list args);
+void _kit_memory_reset (void);
+int _kit_memory_get_current_allocations (void);
+int _kit_memory_get_total_allocations (void);
+void _kit_memory_fail_nth_alloc (int number);
+KIT_END_DECLS
-POLKIT_END_DECLS
-
-#endif /* POLKIT_MEMORY_H */
+#endif /* KIT_MEMORY_H */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-message.c : Message utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <kit/kit.h>
+#include "kit-test.h"
+
+/**
+ * SECTION:kit-message
+ * @title: Message utilities
+ * @short_description: Message utilities
+ *
+ * Various message and logging utilities.
+ **/
+
+/**
+ * kit_debug:
+ * @format: printf(3) style format string
+ * @...: the parameters to insert into @format
+ *
+ * Outputs a debug message on stdout.
+ */
+void
+kit_debug (const char *format, ...)
+{
+ va_list args;
+ char buf[1024];
+
+ kit_return_if_fail (format != NULL);
+
+ va_start (args, format);
+ vsnprintf (buf, sizeof (buf), format, args);
+ va_end (args);
+
+ printf ("[INFO %5d] %s\n", getpid (), buf);
+}
+
+/**
+ * kit_warning:
+ * @format: printf(3) style format string
+ * @...: the parameters to insert into @format
+ *
+ * Outputs a warning message on stderr.
+ */
+void
+kit_warning (const char *format, ...)
+{
+ va_list args;
+ char buf[1024];
+
+ kit_return_if_fail (format != NULL);
+
+ va_start (args, format);
+ vsnprintf (buf, sizeof (buf), format, args);
+ va_end (args);
+
+ fprintf (stderr, "[WARN %5d] %s\n", getpid (), buf);
+}
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+ kit_debug ("Debug %d", 42);
+ kit_warning ("Warning %d %s", 42, "foo");
+ return TRUE;
+}
+
+KitTest _test_message = {
+ "kit_message",
+ NULL,
+ NULL,
+ _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-message.h : Message utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_MESSAGE_H
+#define KIT_MESSAGE_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+void kit_debug (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+void kit_warning (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+
+KIT_END_DECLS
+
+#endif /* KIT_MESSAGE_H */
+
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-string.c : String utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <kit/kit.h>
+#include "kit-test.h"
+
+
+/**
+ * SECTION:kit-string
+ * @title: String utilities
+ * @short_description: String utilities
+ *
+ * Various string utilities.
+ **/
+
+#ifdef KIT_BUILD_TESTS
+
+/**
+ * kit_strdup:
+ * @s: string
+ *
+ * Duplicate a string. Similar to strdup(3).
+ *
+ * Returns: Allocated memory or #NULL on OOM. Free with kit_free().
+ */
+char *
+kit_strdup (const char *s)
+{
+ char *p;
+ size_t len;
+
+ len = strlen (s);
+
+ p = kit_malloc (len + 1);
+ if (p == NULL)
+ goto out;
+
+ memcpy (p, s, len);
+ p[len] = '\0';
+
+out:
+ return p;
+}
+
+/**
+ * kit_strndup:
+ * @s: string
+ * @n: size
+ *
+ * Duplicate a string but copy at most @n characters. If @s is longer
+ * than @n, only @n characters are copied, and a terminating null byte
+ * is added. Similar to strndup(3).
+ *
+ * Returns: Allocated memory or #NULL on OOM. Free with kit_free().
+ */
+char *
+kit_strndup (const char *s, size_t n)
+{
+ char *p;
+ size_t len;
+
+ for (len = 0; len < n; len++) {
+ if (s[len] == '\0')
+ break;
+ }
+
+
+ p = kit_malloc (len + 1);
+ if (p == NULL)
+ goto out;
+
+ memcpy (p, s, len);
+ p[len] = '\0';
+out:
+ return p;
+}
+
+#else
+
+char *
+kit_strdup (const char *s)
+{
+ return strdup (s);
+}
+
+char *
+kit_strndup (const char *s, size_t n)
+{
+ return strndup (s, n);
+}
+
+#endif /* KIT_BUILD_TESTS */
+
+/**
+ * kit_strdup_printf:
+ * @format: sprintf(3) format string
+ * @...: the parameters to insert into the format string.
+ *
+ * Similar to the standard C sprintf(3) function but safer, since it
+ * calculates the maximum space required and allocates memory to hold
+ * the result. The returned string should be freed when no longer
+ * needed.
+ *
+ * Returns: A newly allocated string or #NULL on OOM. Free with kit_free().
+ */
+char*
+kit_strdup_printf (const char *format, ...)
+{
+ char *s;
+ va_list args;
+
+ va_start (args, format);
+ s = kit_strdup_vprintf (format, args);
+ va_end (args);
+
+ return s;
+}
+
+/**
+ * kit_strdup_vprintf:
+ * @format: printf(3) format string
+ * @args: list of parameters to insert
+ *
+ * Similar to the standard C vsprintf(3) function but safer, since it
+ * calculates the maximum space required and allocates memory to hold
+ * the result. The returned string should be freed when no longer
+ * needed.
+ *
+ * Returns: A newly allocated string or #NULL on OOM. Free with kit_free().
+ */
+char*
+kit_strdup_vprintf (const char *format, va_list args)
+{
+ char *s;
+
+#ifdef KIT_BUILD_TESTS
+ char *p;
+ vasprintf (&p, format, args);
+ s = kit_strdup (p);
+ free (p);
+#else
+ if (vasprintf (&s, format, args) == -1) {
+ s = NULL;
+ }
+#endif
+ return s;
+}
+
+
+/**
+ * kit_str_has_prefix:
+ * @s: string to check
+ * @prefix: prefix to check for
+ *
+ * Determines if a string has a given prefix.
+ *
+ * Returns: #TRUE only if @s starts with @prefix
+ */
+kit_bool_t
+kit_str_has_prefix (const char *s, const char *prefix)
+{
+ size_t s_len;
+ size_t prefix_len;
+
+ kit_return_val_if_fail (s != NULL, FALSE);
+ kit_return_val_if_fail (prefix != NULL, FALSE);
+
+ s_len = strlen (s);
+ prefix_len = strlen (prefix);
+ if (prefix_len > s_len)
+ return FALSE;
+
+ return strncmp (s, prefix, prefix_len) == 0;
+}
+
+/**
+ * kit_str_has_suffix:
+ * @s: string to check
+ * @suffix: suffix to check for
+ *
+ * Determines if a string has a given suffix.
+ *
+ * Returns: #TRUE only if @s ends with @suffix
+ */
+kit_bool_t
+kit_str_has_suffix (const char *s, const char *suffix)
+{
+ size_t s_len;
+ size_t suffix_len;
+
+ kit_return_val_if_fail (s != NULL, FALSE);
+ kit_return_val_if_fail (suffix != NULL, FALSE);
+
+ s_len = strlen (s);
+ suffix_len = strlen (suffix);
+ if (suffix_len > s_len)
+ return FALSE;
+
+ return strncmp (s + s_len - suffix_len, suffix, suffix_len) == 0;
+}
+
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+ char str[] = "Hello world";
+ char *p;
+
+ if ((p = kit_strdup (str)) != NULL) {
+ kit_assert (strcmp (p, "Hello world") == 0);
+ kit_free (p);
+ }
+
+ if ((p = kit_strndup (str, 5)) != NULL) {
+ kit_assert (strcmp (p, "Hello") == 0);
+ kit_free (p);
+ }
+
+ if ((p = kit_strndup (str, 100)) != NULL) {
+ kit_assert (strcmp (p, "Hello world") == 0);
+ kit_free (p);
+ }
+
+ if ((p = kit_strdup_printf ("Hello %d", 5)) != NULL) {
+ kit_assert (strcmp (p, "Hello 5") == 0);
+ kit_free (p);
+ }
+
+ kit_assert ( kit_str_has_suffix ("12345", "45"));
+ kit_assert ( kit_str_has_suffix ("12345", "12345"));
+ kit_assert (!kit_str_has_suffix ("12345", "123456"));
+
+ kit_assert ( kit_str_has_prefix ("12345", "12"));
+ kit_assert ( kit_str_has_prefix ("12345", "12345"));
+ kit_assert (!kit_str_has_prefix ("12345", "123456"));
+
+ return TRUE;
+}
+
+KitTest _test_string = {
+ "kit_string",
+ NULL,
+ NULL,
+ _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-string.h : String utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_STRING_H
+#define KIT_STRING_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+char *kit_strdup (const char *s);
+char *kit_strndup (const char *s, size_t n);
+char *kit_strdup_printf (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+char *kit_strdup_vprintf (const char *format, va_list args);
+
+kit_bool_t kit_str_has_prefix (const char *s, const char *prefix);
+kit_bool_t kit_str_has_suffix (const char *s, const char *suffix);
+
+KIT_END_DECLS
+
+#endif /* KIT_STRING_H */
+
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-test.c : PolicyKit test
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <kit/kit-test.h>
+#include <kit/kit-memory.h>
+
+#define MAX_TESTS 64
+
+/**
+ * SECTION:kit-test
+ * @short_description: Testing code for libkit
+ *
+ * Testing code for libkit.
+ */
+
+static KitTest *tests[] = {
+ &_test_memory,
+ &_test_string,
+ &_test_list,
+ &_test_hash,
+ &_test_file,
+ &_test_message,
+};
+
+int
+main (int argc, char *argv[])
+{
+ int ret;
+ int n;
+ int num_tests;
+
+ ret = 0;
+
+ num_tests = sizeof (tests) / sizeof (KitTest*);
+
+ printf ("Running %d unit tests\n", num_tests);
+ for (n = 0; n < num_tests; n++) {
+ int m;
+ int total_allocs;
+ int delta;
+ KitTest *test = tests[n];
+
+ _kit_memory_reset ();
+
+ if (test->setup != NULL)
+ test->setup ();
+
+ printf ("Running: %s\n", test->name);
+ if (!test->run ()) {
+ printf ("Failed\n");
+ ret = 1;
+ goto test_done;
+ }
+
+ total_allocs = _kit_memory_get_total_allocations ();
+ printf (" Unit test made %d allocations in total\n", total_allocs);
+
+ delta = _kit_memory_get_current_allocations ();
+ if (delta != 0) {
+ printf (" Unit test leaked %d allocations\n", delta);
+ ret = 1;
+ }
+
+ for (m = 0; m < total_allocs; m++) {
+ printf (" Failing allocation %d of %d\n", m + 1, total_allocs);
+
+ _kit_memory_reset ();
+ _kit_memory_fail_nth_alloc (m);
+
+ if (!test->run ()) {
+ printf (" Failed\n");
+ ret = 1;
+ continue;
+ }
+
+ delta = _kit_memory_get_current_allocations ();
+ if (delta != 0) {
+ printf (" Unit test leaked %d allocations\n", delta);
+ ret = 1;
+ }
+ }
+
+ test_done:
+ if (test->teardown != NULL)
+ test->teardown ();
+ }
+
+ return ret;
+}
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-test.h : PolicyKit test
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION)
+#error "kit-test.h is a private file."
+#endif
+
+#ifndef KIT_TEST_H
+#define KIT_TEST_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+/**
+ * KitTest:
+ *
+ * Test suite abstraction.
+ */
+typedef struct {
+ /*< private >*/
+ const char *name;
+ void (*setup) (void);
+ void (*teardown) (void);
+ kit_bool_t (*run) (void);
+} KitTest;
+
+extern KitTest _test_memory;
+extern KitTest _test_string;
+extern KitTest _test_hash;
+extern KitTest _test_list;
+extern KitTest _test_file;
+extern KitTest _test_message;
+
+KIT_END_DECLS
+
+#endif /* KIT_TEST_H */
+
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit.h : OOM-safe utility library
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifndef KIT_H
+#define KIT_H
+
+/**
+ * SECTION:kit
+ * @title: Macros
+ * @short_description: Macros
+ *
+ * Various low-level macros.
+ **/
+
+#ifdef __cplusplus
+# define KIT_BEGIN_DECLS extern "C" {
+# define KIT_END_DECLS }
+#else
+/**
+ * KIT_BEGIN_DECLS:
+ *
+ * C++ include header guard.
+ */
+# define KIT_BEGIN_DECLS
+/**
+ * KIT_END_DECLS:
+ *
+ * C++ include header guard.
+ */
+# define KIT_END_DECLS
+#endif
+
+/**
+ * kit_bool_t:
+ *
+ * A boolean, valid values are #TRUE and #FALSE.
+ */
+typedef int kit_bool_t;
+
+#ifndef TRUE
+# define TRUE 1
+#endif
+#ifndef FALSE
+# define FALSE 0
+#endif
+
+/**
+ * kit_assert:
+ * @expr: expression
+ *
+ * Debugging macro to terminate the application if the assertion
+ * fails. If the assertion fails (i.e. the expression is not true), an
+ * error message is logged and the application is terminated.
+ */
+#define kit_assert(expr) \
+do { \
+ if (expr) { \
+ ; \
+ } else { \
+ kit_warning ("%s:%d:%s(): %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
+ exit (1); \
+ } \
+} while (0)
+
+/**
+ * kit_return_if_fail:
+ * @expr: expression
+ *
+ * Returns from the current function if the expression is not true. If
+ * the expression evaluates to #FALSE, an error message is logged and
+ * the function returns. This can only be used in functions which do
+ * not return a value.
+ */
+#define kit_return_if_fail(expr) \
+do { \
+ if (expr) { \
+ ; \
+ } else { \
+ kit_warning ("%s:%d:%s(): %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
+ return; \
+ } \
+} while (0)
+
+/**
+ * kit_return_val_if_fail:
+ * @expr: expression
+ * @val: the value to return if the expression evaluates does not
+ * evaluate to #TRUE
+ *
+ * Returns from the current function, returning the value @val, if the
+ * expression is not true. If the expression evaluates to #FALSE, an
+ * error message is logged and val is returned.
+ */
+#define kit_return_val_if_fail(expr,val) \
+do { \
+ if (expr) { \
+ ; \
+ } else { \
+ kit_warning ("%s:%d:%s(): %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
+ return val; \
+ } \
+} while (0)
+
+
+
+#define _KIT_INSIDE_KIT_H 1
+
+#include <kit/kit-memory.h>
+#include <kit/kit-string.h>
+#include <kit/kit-list.h>
+#include <kit/kit-hash.h>
+#include <kit/kit-file.h>
+#include <kit/kit-message.h>
+
+#undef _KIT_INSIDE_KIT_H
+
+#endif /* KIT_H */
+
+
ret = 1;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- //if (clearenv () != 0)
- // goto out;
+ if (clearenv () != 0)
+ goto out;
/* set a minimal environment */
- //setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
+ setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
openlog ("polkit-read-auth-helper", LOG_CONS | LOG_PID, LOG_AUTHPRIV);
libpolkitinclude_HEADERS = \
polkit.h \
polkit-sysdeps.h \
- polkit-memory.h \
- polkit-hash.h \
- polkit-list.h \
polkit-types.h \
polkit-error.h \
polkit-result.h \
polkit.h \
polkit-private.h \
polkit-types.h \
- polkit-memory.h polkit-memory.c \
- polkit-hash.h polkit-hash.c \
- polkit-list.h polkit-list.c \
polkit-sysdeps.h polkit-sysdeps.c \
polkit-error.h polkit-error.c \
polkit-result.h polkit-result.c \
polkit-authorization-db.c
endif
-libpolkit_la_LIBADD = @GLIB_LIBS@ @EXPAT_LIBS@
+libpolkit_la_LIBADD = @GLIB_LIBS@ @EXPAT_LIBS@ $(top_builddir)/src/kit/libkit.la
libpolkit_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
#include <grp.h>
#include <unistd.h>
#include <errno.h>
+#include <ctype.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-action.h"
#include "polkit-utils.h"
#include "polkit-utils.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
#include "polkit-test.h"
/**
polkit_action_new (void)
{
PolKitAction *action;
- action = p_new0 (PolKitAction, 1);
+ action = kit_new0 (PolKitAction, 1);
if (action == NULL)
goto out;
action->refcount = 1;
PolKitAction *
polkit_action_ref (PolKitAction *action)
{
- g_return_val_if_fail (action != NULL, action);
+ kit_return_val_if_fail (action != NULL, action);
action->refcount++;
return action;
}
void
polkit_action_unref (PolKitAction *action)
{
- g_return_if_fail (action != NULL);
+ kit_return_if_fail (action != NULL);
action->refcount--;
if (action->refcount > 0)
return;
- p_free (action->id);
- p_free (action);
+ kit_free (action->id);
+ kit_free (action);
}
/**
polkit_bool_t
polkit_action_set_action_id (PolKitAction *action, const char *action_id)
{
- g_return_val_if_fail (action != NULL, FALSE);
- g_return_val_if_fail (polkit_action_validate_id (action_id), FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (polkit_action_validate_id (action_id), FALSE);
if (action->id != NULL)
- p_free (action->id);
- action->id = p_strdup (action_id);
+ kit_free (action->id);
+ action->id = kit_strdup (action_id);
if (action->id == NULL)
return FALSE;
polkit_bool_t
polkit_action_get_action_id (PolKitAction *action, char **out_action_id)
{
- g_return_val_if_fail (action != NULL, FALSE);
- g_return_val_if_fail (out_action_id != NULL, FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (out_action_id != NULL, FALSE);
if (action->id == NULL)
return FALSE;
*out_action_id = action->id;
void
polkit_action_debug (PolKitAction *action)
{
- g_return_if_fail (action != NULL);
+ kit_return_if_fail (action != NULL);
_pk_debug ("PolKitAction: refcount=%d id=%s", action->refcount, action->id);
}
{
int n;
- g_return_val_if_fail (action_id != NULL, FALSE);
+ kit_return_val_if_fail (action_id != NULL, FALSE);
/* validate that the form of the action identifier is correct */
- if (!g_ascii_islower (action_id[0]))
+ if (!islower (action_id[0]))
goto malformed;
for (n = 1; action_id[n] != '\0'; n++) {
if (n >= 255)
goto malformed;
- if (! (g_ascii_islower (action_id[n]) ||
- g_ascii_isdigit (action_id[n]) ||
+ if (! (islower (action_id[n]) ||
+ isdigit (action_id[n]) ||
action_id[n] == '.' ||
action_id[n] == '-'))
goto malformed;
polkit_bool_t
polkit_action_validate (PolKitAction *action)
{
- g_return_val_if_fail (action != NULL, FALSE);
- g_return_val_if_fail (action->id != NULL, FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (action->id != NULL, FALSE);
return polkit_action_validate_id (action->id);
}
NULL};
for (n = 0; valid_action_ids[n] != NULL; n++) {
- g_assert (polkit_action_validate_id (valid_action_ids[n]));
+ kit_assert (polkit_action_validate_id (valid_action_ids[n]));
}
for (n = 0; invalid_action_ids[n] != NULL; n++) {
- g_assert (! polkit_action_validate_id (invalid_action_ids[n]));
+ kit_assert (! polkit_action_validate_id (invalid_action_ids[n]));
}
PolKitAction *a;
/* OOM */
} else {
- g_assert (! polkit_action_get_action_id (a, &s));
+ kit_assert (! polkit_action_get_action_id (a, &s));
if (!polkit_action_set_action_id (a, "org.example.action")) {
/* OOM */
} else {
- g_assert (polkit_action_validate (a));
+ kit_assert (polkit_action_validate (a));
polkit_action_ref (a);
- g_assert (polkit_action_validate (a));
+ kit_assert (polkit_action_validate (a));
polkit_action_unref (a);
- g_assert (polkit_action_validate (a));
+ kit_assert (polkit_action_validate (a));
if (!polkit_action_set_action_id (a, "org.example.action2")) {
/* OOM */
} else {
- g_assert (polkit_action_validate (a));
- g_assert (polkit_action_get_action_id (a, &s));
- g_assert (strcmp (s, "org.example.action2") == 0);
+ kit_assert (polkit_action_validate (a));
+ kit_assert (polkit_action_get_action_id (a, &s));
+ kit_assert (strcmp (s, "org.example.action2") == 0);
polkit_action_debug (a);
}
}
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-authorization-constraint.h"
#include "polkit-utils.h"
#include "polkit-private.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-authorization-constraint
_polkit_authorization_constraint_new (const char *entry_in_auth_file)
{
PolKitAuthorizationConstraint *authc;
- authc = p_new0 (PolKitAuthorizationConstraint, 1);
+ authc = kit_new0 (PolKitAuthorizationConstraint, 1);
if (authc == NULL)
goto oom;
authc->refcount = 1;
PolKitAuthorizationConstraint *
polkit_authorization_constraint_ref (PolKitAuthorizationConstraint *authc)
{
- g_return_val_if_fail (authc != NULL, authc);
+ kit_return_val_if_fail (authc != NULL, authc);
if (authc->refcount == -1)
return authc;
authc->refcount++;
void
polkit_authorization_constraint_unref (PolKitAuthorizationConstraint *authc)
{
- g_return_if_fail (authc != NULL);
+ kit_return_if_fail (authc != NULL);
if (authc->refcount == -1)
return;
authc->refcount--;
if (authc->refcount > 0)
return;
- p_free (authc);
+ kit_free (authc);
}
/**
void
polkit_authorization_constraint_debug (PolKitAuthorizationConstraint *authc)
{
- g_return_if_fail (authc != NULL);
+ kit_return_if_fail (authc != NULL);
_pk_debug ("PolKitAuthorizationConstraint: refcount=%d", authc->refcount);
}
polkit_bool_t
polkit_authorization_constraint_validate (PolKitAuthorizationConstraint *authc)
{
- g_return_val_if_fail (authc != NULL, FALSE);
+ kit_return_val_if_fail (authc != NULL, FALSE);
return TRUE;
}
polkit_bool_t is_active;
polkit_bool_t is_local;
- g_return_val_if_fail (authc != NULL, FALSE);
- g_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (authc != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
ret = FALSE;
polkit_bool_t ret;
PolKitSession *session;
- g_return_val_if_fail (authc != NULL, FALSE);
- g_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (authc != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
ret = FALSE;
PolKitAuthorizationConstraintFlags
polkit_authorization_constraint_get_flags (PolKitAuthorizationConstraint *authc)
{
- g_return_val_if_fail (authc != NULL, FALSE);
+ kit_return_val_if_fail (authc != NULL, FALSE);
return authc->flags;
}
size_t
polkit_authorization_constraint_to_string (PolKitAuthorizationConstraint *authc, char *out_buf, size_t buf_size)
{
- g_return_val_if_fail (authc != NULL, buf_size);
+ kit_return_val_if_fail (authc != NULL, buf_size);
switch (authc->flags) {
default:
{
PolKitAuthorizationConstraint *ret;
- g_return_val_if_fail (str != NULL, NULL);
+ kit_return_val_if_fail (str != NULL, NULL);
ret = NULL;
polkit_bool_t
polkit_authorization_constraint_equal (PolKitAuthorizationConstraint *a, PolKitAuthorizationConstraint *b)
{
- g_return_val_if_fail (a != NULL, FALSE);
- g_return_val_if_fail (b != NULL, FALSE);
+ kit_return_val_if_fail (a != NULL, FALSE);
+ kit_return_val_if_fail (b != NULL, FALSE);
return a->flags == b->flags;
}
if ((c = polkit_caller_new ()) != NULL) {
if (ac->flags == 0) {
- g_assert (polkit_authorization_constraint_check_caller (ac, c) == TRUE);
+ kit_assert (polkit_authorization_constraint_check_caller (ac, c) == TRUE);
} else {
- g_assert (polkit_authorization_constraint_check_caller (ac, c) == FALSE);
+ kit_assert (polkit_authorization_constraint_check_caller (ac, c) == FALSE);
}
- g_assert (polkit_caller_set_ck_session (c, s));
- g_assert (*out_result == polkit_authorization_constraint_check_caller (ac, c));
+ kit_assert (polkit_caller_set_ck_session (c, s));
+ kit_assert (*out_result == polkit_authorization_constraint_check_caller (ac, c));
polkit_caller_unref (c);
}
PolKitAuthorizationConstraint *ac2;
/* not enough space */
- g_assert (polkit_authorization_constraint_to_string (ac, buf, 2) >= 2);
+ kit_assert (polkit_authorization_constraint_to_string (ac, buf, 2) >= 2);
- g_assert (polkit_authorization_constraint_to_string (ac, buf, sizeof (buf)) < sizeof (buf));
+ kit_assert (polkit_authorization_constraint_to_string (ac, buf, sizeof (buf)) < sizeof (buf));
if ((ac2 = polkit_authorization_constraint_from_string (buf)) != NULL) {
- g_assert (polkit_authorization_constraint_equal (ac, ac2) == TRUE);
+ kit_assert (polkit_authorization_constraint_equal (ac, ac2) == TRUE);
polkit_authorization_constraint_unref (ac2);
}
}
if ((c = polkit_caller_new ()) != NULL) {
ac = polkit_authorization_constraint_get_from_caller (c);
- g_assert (polkit_authorization_constraint_equal (ac, polkit_authorization_constraint_get_null ()));
+ kit_assert (polkit_authorization_constraint_equal (ac, polkit_authorization_constraint_get_null ()));
- g_assert (polkit_caller_set_ck_session (c, s));
+ kit_assert (polkit_caller_set_ck_session (c, s));
ac = polkit_authorization_constraint_get_from_caller (c);
polkit_session_unref (s_active);
s_active = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_active, TRUE));
- g_assert (polkit_session_set_ck_is_active (s_active, TRUE));
+ kit_assert (polkit_session_set_ck_is_local (s_active, TRUE));
+ kit_assert (polkit_session_set_ck_is_active (s_active, TRUE));
}
}
polkit_session_unref (s_inactive);
s_inactive = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
- g_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
+ kit_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
+ kit_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
}
}
polkit_session_unref (s_active_remote);
s_active_remote = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
- g_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
+ kit_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
+ kit_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
}
}
polkit_session_unref (s_inactive_remote);
s_inactive_remote = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
- g_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
+ kit_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
+ kit_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
}
}
/* null constraint */
- g_assert ((ac = polkit_authorization_constraint_get_null ()) != NULL);
+ kit_assert ((ac = polkit_authorization_constraint_get_null ()) != NULL);
polkit_authorization_constraint_ref (ac);
polkit_authorization_constraint_unref (ac);
flags = polkit_authorization_constraint_get_flags (ac);
- g_assert (flags == 0);
- g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == TRUE);
+ kit_assert (flags == 0);
+ kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == TRUE);
_tst2 (ac);
/* local constraint */
- g_assert ((ac = polkit_authorization_constraint_get_require_local ()) != NULL);
+ kit_assert ((ac = polkit_authorization_constraint_get_require_local ()) != NULL);
flags = polkit_authorization_constraint_get_flags (ac);
- g_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL);
- g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
- g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
+ kit_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL);
+ kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
+ kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
_tst2 (ac);
/* active constraint */
- g_assert ((ac = polkit_authorization_constraint_get_require_active ()) != NULL);
+ kit_assert ((ac = polkit_authorization_constraint_get_require_active ()) != NULL);
flags = polkit_authorization_constraint_get_flags (ac);
- g_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_ACTIVE);
- g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
- g_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
+ kit_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_ACTIVE);
+ kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
+ kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
_tst2 (ac);
/* local+active constraint */
- g_assert ((ac = polkit_authorization_constraint_get_require_local_active ()) != NULL);
+ kit_assert ((ac = polkit_authorization_constraint_get_require_local_active ()) != NULL);
flags = polkit_authorization_constraint_get_flags (ac);
- g_assert (flags == (POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL|
+ kit_assert (flags == (POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL|
POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_ACTIVE));
- g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
- g_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
- g_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
- g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
+ kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+ kit_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
+ kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
+ kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
_tst2 (ac);
for (n = 0; n < 4; n++) {
break;
}
- g_assert (_tst3 (s, polkit_authorization_constraint_get_require_local_active (), &ret) || ret == expected[0]);
- g_assert (_tst3 (s, polkit_authorization_constraint_get_require_local (), &ret) || ret == expected[1]);
- g_assert (_tst3 (s, polkit_authorization_constraint_get_require_active (), &ret) || ret == expected[2]);
- g_assert (_tst3 (s, polkit_authorization_constraint_get_null (), &ret) || ret == expected[3]);
+ kit_assert (_tst3 (s, polkit_authorization_constraint_get_require_local_active (), &ret) || ret == expected[0]);
+ kit_assert (_tst3 (s, polkit_authorization_constraint_get_require_local (), &ret) || ret == expected[1]);
+ kit_assert (_tst3 (s, polkit_authorization_constraint_get_require_active (), &ret) || ret == expected[2]);
+ kit_assert (_tst3 (s, polkit_authorization_constraint_get_null (), &ret) || ret == expected[3]);
}
if ((ac = _polkit_authorization_constraint_new ("local+active")) != NULL) {
PolKitAuthorizationDB *
polkit_authorization_db_ref (PolKitAuthorizationDB *authdb)
{
- g_return_val_if_fail (authdb != NULL, authdb);
+ kit_return_val_if_fail (authdb != NULL, authdb);
authdb->refcount++;
return authdb;
}
void
polkit_authorization_db_unref (PolKitAuthorizationDB *authdb)
{
- g_return_if_fail (authdb != NULL);
+ kit_return_if_fail (authdb != NULL);
authdb->refcount--;
if (authdb->refcount > 0)
return;
void
polkit_authorization_db_debug (PolKitAuthorizationDB *authdb)
{
- g_return_if_fail (authdb != NULL);
+ kit_return_if_fail (authdb != NULL);
_pk_debug ("PolKitAuthorizationDB: refcount=%d", authdb->refcount);
}
polkit_bool_t
polkit_authorization_db_validate (PolKitAuthorizationDB *authdb)
{
- g_return_val_if_fail (authdb != NULL, FALSE);
+ kit_return_val_if_fail (authdb != NULL, FALSE);
return TRUE;
}
#include "polkit-authorization-db.h"
#include "polkit-utils.h"
#include "polkit-private.h"
+#include "polkit-test.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-authorization-db
PolKitAuthorizationDB *
polkit_authorization_db_ref (PolKitAuthorizationDB *authdb)
{
- g_return_val_if_fail (authdb != NULL, authdb);
+ kit_return_val_if_fail (authdb != NULL, authdb);
authdb->refcount++;
return authdb;
}
void
polkit_authorization_db_unref (PolKitAuthorizationDB *authdb)
{
- g_return_if_fail (authdb != NULL);
+ kit_return_if_fail (authdb != NULL);
authdb->refcount--;
if (authdb->refcount > 0)
return;
- g_hash_table_destroy (authdb->uid_to_authlist);
+ kit_hash_unref (authdb->uid_to_authlist);
g_free (authdb);
}
void
polkit_authorization_db_debug (PolKitAuthorizationDB *authdb)
{
- g_return_if_fail (authdb != NULL);
+ kit_return_if_fail (authdb != NULL);
_pk_debug ("PolKitAuthorizationDB: refcount=%d", authdb->refcount);
}
polkit_bool_t
polkit_authorization_db_validate (PolKitAuthorizationDB *authdb)
{
- g_return_val_if_fail (authdb != NULL, FALSE);
+ kit_return_val_if_fail (authdb != NULL, FALSE);
return TRUE;
}
{
/* out with the old, in the with new */
if (authdb->uid_to_authlist != NULL) {
- g_hash_table_destroy (authdb->uid_to_authlist);
+ kit_hash_unref (authdb->uid_to_authlist);
}
- authdb->uid_to_authlist = g_hash_table_new_full (g_direct_hash,
- g_direct_equal,
- NULL,
- (GDestroyNotify) _free_authlist);
+ authdb->uid_to_authlist = kit_hash_new (kit_hash_direct_hash_func,
+ kit_hash_direct_equal_func,
+ NULL,
+ NULL,
+ NULL,
+ (KitFreeFunc) _free_authlist);
}
/**
standard_output = NULL;
/* first, see if this is in the cache */
- ret = g_hash_table_lookup (authdb->uid_to_authlist, (gpointer) uid);
+ ret = kit_hash_lookup (authdb->uid_to_authlist, (void *) uid, NULL);
if (ret != NULL)
goto out;
n = m + 1;
}
- g_hash_table_insert (authdb->uid_to_authlist, (gpointer) uid, ret);
+ kit_hash_insert (authdb->uid_to_authlist, (void *) uid, ret);
out:
g_free (helper_argv[1]);
polkit_bool_t ret;
char *action_id;
- g_return_val_if_fail (authdb != NULL, FALSE);
- g_return_val_if_fail (cb != NULL, FALSE);
+ kit_return_val_if_fail (authdb != NULL, FALSE);
+ kit_return_val_if_fail (cb != NULL, FALSE);
ret = FALSE;
void *user_data,
PolKitError **error)
{
- g_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
return _internal_foreach (authdb, action, -1, cb, user_data, error);
}
void *user_data,
PolKitError **error)
{
- g_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
return _internal_foreach (authdb, action, uid, cb, user_data, error);
}
ret = FALSE;
- g_return_val_if_fail (authdb != NULL, FALSE);
- g_return_val_if_fail (action != NULL, FALSE);
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_is_authorized != NULL, FALSE);
+ kit_return_val_if_fail (authdb != NULL, FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_is_authorized != NULL, FALSE);
if (!polkit_action_get_action_id (action, &cd.action_id))
return FALSE;
ret = FALSE;
- g_return_val_if_fail (authdb != NULL, FALSE);
- g_return_val_if_fail (action != NULL, FALSE);
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (out_is_authorized != NULL, FALSE);
+ kit_return_val_if_fail (authdb != NULL, FALSE);
+ kit_return_val_if_fail (action != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (out_is_authorized != NULL, FALSE);
if (!polkit_action_get_action_id (action, &cd.action_id))
return FALSE;
ret = FALSE;
- g_return_val_if_fail (authdb != NULL, FALSE);
- g_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (authdb != NULL, FALSE);
+ kit_return_val_if_fail (auth != NULL, FALSE);
auth_file_entry = _polkit_authorization_get_authfile_entry (auth);
//g_debug ("should delete line '%s'", auth_file_entry);
g_free (helper_argv[3]);
return ret;
}
+
+#ifdef POLKIT_BUILD_TESTS
+
+static polkit_bool_t
+_run_test (void)
+{
+ PolKitAuthorizationDB *adb;
+ const char test_passwd[] =
+ "pu1:x:50400:50400:PolKit Test user 1:/home/polkittest1:/bin/bash\n"
+ "pu2:x:50401:50401:PolKit Test user 2:/home/polkittest2:/bin/bash\n";
+ const char test_pu1_run[] =
+ "";
+ const char test_pu1_lib[] =
+ "grant:org.freedesktop.policykit.read:1194634242:0:none\n";
+ const char test_pu2_run[] =
+ "";
+ const char test_pu2_lib[] =
+ "";
+
+ if (setenv ("POLKIT_TEST_LOCALSTATE_DIR", TEST_DATA_DIR "authdb-test", 1) != 0)
+ goto fail;
+
+ if (setenv ("POLKIT_TEST_PASSWD_FILE", TEST_DATA_DIR "authdb-test/passwd", 1) != 0)
+ goto fail;
+
+ /* create test users */
+ if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/passwd", 0644,
+ test_passwd, sizeof (test_passwd) - 1))
+ goto out;
+
+ /* seed the authdb with known defaults */
+ if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/run/PolicyKit/user-pu1.auths", 0644,
+ test_pu1_run, sizeof (test_pu1_run) - 1))
+ goto out;
+ if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/lib/PolicyKit/user-pu1.auths", 0644,
+ test_pu1_lib, sizeof (test_pu1_lib) - 1))
+ goto out;
+ if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/run/PolicyKit/user-pu2.auths", 0644,
+ test_pu2_run, sizeof (test_pu2_run) - 1))
+ goto out;
+ if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/lib/PolicyKit/user-pu2.auths", 0644,
+ test_pu2_lib, sizeof (test_pu2_lib) - 1))
+ goto out;
+
+ if ((adb = _polkit_authorization_db_new ()) == NULL)
+ goto out;
+
+ if (setenv ("POLKIT_TEST_PRETEND_TO_BE_UID", "50400", 1) != 0)
+ goto fail;
+
+ /* TODO: FIXME: this code is not finished */
+
+
+ polkit_authorization_db_unref (adb);
+
+out:
+ if (unsetenv ("POLKIT_TEST_PRETEND_TO_BE_UID") != 0)
+ goto fail;
+
+ if (unsetenv ("POLKIT_TEST_LOCALSTATE_DIR") != 0)
+ goto fail;
+
+ if (unsetenv ("POLKIT_TEST_PASSWD_FILE") != 0)
+ goto fail;
+
+ return TRUE;
+fail:
+ return FALSE;
+}
+
+
+PolKitTest _test_authorization_db = {
+ "polkit_authorization_db",
+ NULL,
+ NULL,
+ _run_test
+};
+
+#endif /* POLKIT_BUILD_TESTS */
#include <errno.h>
#include <glib.h>
+
#include "polkit-debug.h"
#include "polkit-authorization.h"
#include "polkit-utils.h"
#include "polkit-private.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-authorization
const char *
_polkit_authorization_get_authfile_entry (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, NULL);
+ kit_return_val_if_fail (auth != NULL, NULL);
return auth->entry_in_auth_file;
}
PolKitAuthorization *auth;
int n;
- g_return_val_if_fail (entry_in_auth_file != NULL, NULL);
+ kit_return_val_if_fail (entry_in_auth_file != NULL, NULL);
t = NULL;
- auth = p_new0 (PolKitAuthorization, 1);
+ auth = kit_new0 (PolKitAuthorization, 1);
if (auth == NULL)
goto oom;
auth->refcount = 1;
- auth->entry_in_auth_file = p_strdup (entry_in_auth_file);
+ auth->entry_in_auth_file = kit_strdup (entry_in_auth_file);
if (auth->entry_in_auth_file == NULL)
goto oom;
if (!polkit_action_validate_id (t[n]))
goto error;
- auth->action_id = p_strdup (t[n++]);
+ auth->action_id = kit_strdup (t[n++]);
if (auth->action_id == NULL)
goto oom;
auth->scope = POLKIT_AUTHORIZATION_SCOPE_SESSION;
- auth->session_id = p_strdup (t[n++]);
+ auth->session_id = kit_strdup (t[n++]);
if (auth->session_id == NULL)
goto oom;
if (!polkit_action_validate_id (t[n]))
goto error;
- auth->action_id = p_strdup (t[n++]);
+ auth->action_id = kit_strdup (t[n++]);
if (auth->action_id == NULL)
goto oom;
if (!polkit_action_validate_id (t[n]))
goto error;
- auth->action_id = p_strdup (t[n++]);
+ auth->action_id = kit_strdup (t[n++]);
if (auth->action_id == NULL)
goto oom;
if (!polkit_action_validate_id (t[n]))
goto error;
- auth->action_id = p_strdup (t[n++]);
+ auth->action_id = kit_strdup (t[n++]);
if (auth->action_id == NULL)
goto oom;
PolKitAuthorization *
polkit_authorization_ref (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, auth);
+ kit_return_val_if_fail (auth != NULL, auth);
auth->refcount++;
return auth;
}
void
polkit_authorization_unref (PolKitAuthorization *auth)
{
- g_return_if_fail (auth != NULL);
+ kit_return_if_fail (auth != NULL);
auth->refcount--;
if (auth->refcount > 0)
return;
- p_free (auth->entry_in_auth_file);
- p_free (auth->action_id);
- p_free (auth->session_id);
+ kit_free (auth->entry_in_auth_file);
+ kit_free (auth->action_id);
+ kit_free (auth->session_id);
if (auth->constraint != NULL)
polkit_authorization_constraint_unref (auth->constraint);
- p_free (auth);
+ kit_free (auth);
}
/**
void
polkit_authorization_debug (PolKitAuthorization *auth)
{
- g_return_if_fail (auth != NULL);
+ kit_return_if_fail (auth != NULL);
_pk_debug ("PolKitAuthorization: refcount=%d", auth->refcount);
_pk_debug (" scope = %d", auth->scope);
_pk_debug (" pid = %d", auth->pid);
polkit_bool_t
polkit_authorization_validate (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (auth != NULL, FALSE);
return TRUE;
}
const char *
polkit_authorization_get_action_id (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, NULL);
+ kit_return_val_if_fail (auth != NULL, NULL);
return auth->action_id;
}
PolKitAuthorizationScope
polkit_authorization_get_scope (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, 0);
+ kit_return_val_if_fail (auth != NULL, 0);
return auth->scope;
}
pid_t *out_pid,
polkit_uint64_t *out_pid_start_time)
{
- g_return_val_if_fail (auth != NULL, FALSE);
- g_return_val_if_fail (out_pid != NULL, FALSE);
- g_return_val_if_fail (out_pid_start_time != NULL, FALSE);
- g_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_PROCESS ||
+ kit_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (out_pid != NULL, FALSE);
+ kit_return_val_if_fail (out_pid_start_time != NULL, FALSE);
+ kit_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_PROCESS ||
auth->scope == POLKIT_AUTHORIZATION_SCOPE_PROCESS_ONE_SHOT, FALSE);
*out_pid = auth->pid;
const char *
polkit_authorization_scope_session_get_ck_objref (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, FALSE);
- g_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_SESSION, FALSE);
+ kit_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_SESSION, FALSE);
return auth->session_id;
}
uid_t
polkit_authorization_get_uid (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, 0);
+ kit_return_val_if_fail (auth != NULL, 0);
return auth->uid;
}
time_t
polkit_authorization_get_time_of_grant (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, 0);
+ kit_return_val_if_fail (auth != NULL, 0);
return auth->when;
}
polkit_authorization_was_granted_via_defaults (PolKitAuthorization *auth,
uid_t *out_user_authenticated_as)
{
- g_return_val_if_fail (auth != NULL, FALSE);
- g_return_val_if_fail (out_user_authenticated_as != NULL, FALSE);
+ kit_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (out_user_authenticated_as != NULL, FALSE);
if (auth->explicitly_granted)
return FALSE;
polkit_authorization_was_granted_explicitly (PolKitAuthorization *auth,
uid_t *out_by_whom)
{
- g_return_val_if_fail (auth != NULL, FALSE);
- g_return_val_if_fail (out_by_whom != NULL, FALSE);
+ kit_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (out_by_whom != NULL, FALSE);
if (!auth->explicitly_granted)
return FALSE;
PolKitAuthorizationConstraint *
polkit_authorization_get_constraint (PolKitAuthorization *auth)
{
- g_return_val_if_fail (auth != NULL, FALSE);
+ kit_return_val_if_fail (auth != NULL, FALSE);
return auth->constraint;
}
polkit_authorization_debug (a);
polkit_authorization_validate (a);
- g_assert (t->scope == polkit_authorization_get_scope (a));
- g_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
- g_assert (500 == polkit_authorization_get_uid (a));
+ kit_assert (t->scope == polkit_authorization_get_scope (a));
+ kit_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
+ kit_assert (500 == polkit_authorization_get_uid (a));
switch (t->scope) {
case POLKIT_AUTHORIZATION_SCOPE_PROCESS_ONE_SHOT: /* explicit fallthrough */
case POLKIT_AUTHORIZATION_SCOPE_PROCESS:
- g_assert (polkit_authorization_scope_process_get_pid (a, &pid, &pid_start_time) &&
+ kit_assert (polkit_authorization_scope_process_get_pid (a, &pid, &pid_start_time) &&
t->pid == pid && t->pid_start_time == pid_start_time);
break;
case POLKIT_AUTHORIZATION_SCOPE_SESSION:
- g_assert ((s = polkit_authorization_scope_session_get_ck_objref (a)) != NULL &&
+ kit_assert ((s = polkit_authorization_scope_session_get_ck_objref (a)) != NULL &&
strcmp (s, t->session) == 0);
break;
case POLKIT_AUTHORIZATION_SCOPE_ALWAYS:
break;
}
- g_assert ((s = _polkit_authorization_get_authfile_entry (a)) != NULL && strcmp (t->entry, s) == 0);
+ kit_assert ((s = _polkit_authorization_get_authfile_entry (a)) != NULL && strcmp (t->entry, s) == 0);
- g_assert ((s = polkit_authorization_get_action_id (a)) != NULL && strcmp (t->action_id, s) == 0);
+ kit_assert ((s = polkit_authorization_get_action_id (a)) != NULL && strcmp (t->action_id, s) == 0);
- g_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
+ kit_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
- g_assert ((ac = polkit_authorization_get_constraint (a)) != NULL &&
+ kit_assert ((ac = polkit_authorization_get_constraint (a)) != NULL &&
polkit_authorization_constraint_equal (ac, t->constraint));
if (t->explicit) {
- g_assert (!polkit_authorization_was_granted_via_defaults (a, &uid));
- g_assert (polkit_authorization_was_granted_explicitly (a, &uid) && uid == t->from);
+ kit_assert (!polkit_authorization_was_granted_via_defaults (a, &uid));
+ kit_assert (polkit_authorization_was_granted_explicitly (a, &uid) && uid == t->from);
} else {
- g_assert (polkit_authorization_was_granted_via_defaults (a, &uid) && uid == t->from);
- g_assert (!polkit_authorization_was_granted_explicitly (a, &uid));
+ kit_assert (polkit_authorization_was_granted_via_defaults (a, &uid) && uid == t->from);
+ kit_assert (!polkit_authorization_was_granted_explicitly (a, &uid));
}
polkit_authorization_ref (a);
}
for (n = 0; n < num_invalid_auths; n++) {
- g_assert (_polkit_authorization_new_for_uid (invalid_auths[n], 500) == NULL);
+ kit_assert (_polkit_authorization_new_for_uid (invalid_auths[n], 500) == NULL);
}
return TRUE;
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-caller.h"
#include "polkit-utils.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* PolKitCaller:
polkit_caller_new (void)
{
PolKitCaller *caller;
- caller = p_new0 (PolKitCaller, 1);
+ caller = kit_new0 (PolKitCaller, 1);
if (caller == NULL)
goto out;
caller->refcount = 1;
PolKitCaller *
polkit_caller_ref (PolKitCaller *caller)
{
- g_return_val_if_fail (caller != NULL, caller);
+ kit_return_val_if_fail (caller != NULL, caller);
caller->refcount++;
return caller;
}
void
polkit_caller_unref (PolKitCaller *caller)
{
- g_return_if_fail (caller != NULL);
+ kit_return_if_fail (caller != NULL);
caller->refcount--;
if (caller->refcount > 0)
return;
- p_free (caller->dbus_name);
- p_free (caller->selinux_context);
+ kit_free (caller->dbus_name);
+ kit_free (caller->selinux_context);
if (caller->session != NULL)
polkit_session_unref (caller->session);
- p_free (caller);
+ kit_free (caller);
}
/**
polkit_bool_t
polkit_caller_set_dbus_name (PolKitCaller *caller, const char *dbus_name)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (dbus_name == NULL || _pk_validate_unique_bus_name (dbus_name), FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (dbus_name == NULL || _pk_validate_unique_bus_name (dbus_name), FALSE);
if (caller->dbus_name != NULL)
- p_free (caller->dbus_name);
+ kit_free (caller->dbus_name);
if (dbus_name == NULL) {
caller->dbus_name = NULL;
return TRUE;
} else {
- caller->dbus_name = p_strdup (dbus_name);
+ caller->dbus_name = kit_strdup (dbus_name);
if (caller->dbus_name == NULL)
return FALSE;
else
polkit_bool_t
polkit_caller_set_uid (PolKitCaller *caller, uid_t uid)
{
- g_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
caller->uid = uid;
return TRUE;
}
polkit_bool_t
polkit_caller_set_pid (PolKitCaller *caller, pid_t pid)
{
- g_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
caller->pid = pid;
return TRUE;
}
polkit_bool_t
polkit_caller_set_selinux_context (PolKitCaller *caller, const char *selinux_context)
{
- g_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
/* TODO: probably should have a separate validation function for SELinux contexts */
- g_return_val_if_fail (selinux_context == NULL || _pk_validate_identifier (selinux_context), FALSE);
+ kit_return_val_if_fail (selinux_context == NULL || _pk_validate_identifier (selinux_context), FALSE);
if (caller->selinux_context != NULL)
- p_free (caller->selinux_context);
+ kit_free (caller->selinux_context);
if (selinux_context == NULL) {
caller->selinux_context = NULL;
return TRUE;
} else {
- caller->selinux_context = p_strdup (selinux_context);
+ caller->selinux_context = kit_strdup (selinux_context);
if (caller->selinux_context == NULL)
return FALSE;
else
polkit_bool_t
polkit_caller_set_ck_session (PolKitCaller *caller, PolKitSession *session)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (session == NULL || polkit_session_validate (session), FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (session == NULL || polkit_session_validate (session), FALSE);
if (caller->session != NULL)
polkit_session_unref (caller->session);
caller->session = session != NULL ? polkit_session_ref (session) : NULL;
polkit_bool_t
polkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (out_dbus_name != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (out_dbus_name != NULL, FALSE);
*out_dbus_name = caller->dbus_name;
return TRUE;
}
polkit_bool_t
polkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (out_uid != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (out_uid != NULL, FALSE);
*out_uid = caller->uid;
return TRUE;
}
polkit_bool_t
polkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (out_pid != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (out_pid != NULL, FALSE);
*out_pid = caller->pid;
return TRUE;
}
polkit_bool_t
polkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_context)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (out_selinux_context != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (out_selinux_context != NULL, FALSE);
*out_selinux_context = caller->selinux_context;
return TRUE;
}
polkit_bool_t
polkit_caller_get_ck_session (PolKitCaller *caller, PolKitSession **out_session)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (out_session != NULL, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (out_session != NULL, FALSE);
*out_session = caller->session;
return TRUE;
}
void
polkit_caller_debug (PolKitCaller *caller)
{
- g_return_if_fail (caller != NULL);
+ kit_return_if_fail (caller != NULL);
_pk_debug ("PolKitCaller: refcount=%d dbus_name=%s uid=%d pid=%d selinux_context=%s",
caller->refcount, caller->dbus_name, caller->uid, caller->pid, caller->selinux_context);
if (caller->session != NULL)
polkit_bool_t
polkit_caller_validate (PolKitCaller *caller)
{
- g_return_val_if_fail (caller != NULL, FALSE);
- g_return_val_if_fail (caller->pid > 0, FALSE);
+ kit_return_val_if_fail (caller != NULL, FALSE);
+ kit_return_val_if_fail (caller->pid > 0, FALSE);
return TRUE;
}
if ((c = polkit_caller_new ()) != NULL) {
- g_assert (! polkit_caller_set_dbus_name (c, "org.invalid.name"));
- g_assert (polkit_caller_set_dbus_name (c, NULL));
+ kit_assert (! polkit_caller_set_dbus_name (c, "org.invalid.name"));
+ kit_assert (polkit_caller_set_dbus_name (c, NULL));
if (polkit_caller_set_dbus_name (c, ":1.43")) {
- g_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.43") == 0);
+ kit_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.43") == 0);
if (polkit_caller_set_dbus_name (c, ":1.44")) {
- g_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.44") == 0);
+ kit_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.44") == 0);
}
}
- g_assert (polkit_caller_set_selinux_context (c, NULL));
+ kit_assert (polkit_caller_set_selinux_context (c, NULL));
if (polkit_caller_set_selinux_context (c, "system_u:object_r:bin_t")) {
- g_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:bin_t") == 0);
+ kit_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:bin_t") == 0);
if (polkit_caller_set_selinux_context (c, "system_u:object_r:httpd_exec_t")) {
- g_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:httpd_exec_t") == 0);
+ kit_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:httpd_exec_t") == 0);
}
}
- g_assert (polkit_caller_set_uid (c, 0));
- g_assert (polkit_caller_get_uid (c, &uid) && uid == 0);
- g_assert (polkit_caller_set_pid (c, 1));
- g_assert (polkit_caller_get_pid (c, &pid) && pid == 1);
+ kit_assert (polkit_caller_set_uid (c, 0));
+ kit_assert (polkit_caller_get_uid (c, &uid) && uid == 0);
+ kit_assert (polkit_caller_set_pid (c, 1));
+ kit_assert (polkit_caller_get_pid (c, &pid) && pid == 1);
/* validate where caller is not in a session */
- g_assert (polkit_caller_validate (c));
+ kit_assert (polkit_caller_validate (c));
polkit_caller_ref (c);
- g_assert (polkit_caller_validate (c));
+ kit_assert (polkit_caller_validate (c));
polkit_caller_unref (c);
- g_assert (polkit_caller_validate (c));
+ kit_assert (polkit_caller_validate (c));
if ((session = polkit_session_new ()) != NULL) {
if (polkit_session_set_ck_objref (session, "/somesession")) {
if ((seat = polkit_seat_new ()) != NULL) {
if (polkit_seat_set_ck_objref (seat, "/someseat")) {
- g_assert (polkit_session_set_seat (session, seat));
- g_assert (polkit_session_set_ck_is_local (session, TRUE));
+ kit_assert (polkit_session_set_seat (session, seat));
+ kit_assert (polkit_session_set_ck_is_local (session, TRUE));
- g_assert (polkit_caller_set_ck_session (c, NULL));
- g_assert (polkit_caller_get_ck_session (c, &session2) && session2 == NULL);
+ kit_assert (polkit_caller_set_ck_session (c, NULL));
+ kit_assert (polkit_caller_get_ck_session (c, &session2) && session2 == NULL);
- g_assert (polkit_caller_set_ck_session (c, session));
- g_assert (polkit_caller_set_ck_session (c, session));
- g_assert (polkit_caller_get_ck_session (c, &session2) && session2 == session);
+ kit_assert (polkit_caller_set_ck_session (c, session));
+ kit_assert (polkit_caller_set_ck_session (c, session));
+ kit_assert (polkit_caller_get_ck_session (c, &session2) && session2 == session);
/* validate where caller is in a session */
- g_assert (polkit_caller_validate (c));
+ kit_assert (polkit_caller_validate (c));
polkit_caller_debug (c);
#include "polkit-config.h"
#include "polkit-debug.h"
#include "polkit-error.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-config
PolKitConfig *
polkit_config_ref (PolKitConfig *pk_config)
{
- g_return_val_if_fail (pk_config != NULL, pk_config);
+ kit_return_val_if_fail (pk_config != NULL, pk_config);
pk_config->refcount++;
return pk_config;
}
void
polkit_config_unref (PolKitConfig *pk_config)
{
- g_return_if_fail (pk_config != NULL);
+ kit_return_if_fail (pk_config != NULL);
pk_config->refcount--;
if (pk_config->refcount > 0)
return;
polkit_bool_t
polkit_context_init (PolKitContext *pk_context, PolKitError **error)
{
- g_return_val_if_fail (pk_context != NULL, FALSE);
+ kit_return_val_if_fail (pk_context != NULL, FALSE);
pk_context->policy_dir = g_strdup (PACKAGE_DATA_DIR "/PolicyKit/policy");
_pk_debug ("Using policy files from directory %s", pk_context->policy_dir);
PolKitContext *
polkit_context_ref (PolKitContext *pk_context)
{
- g_return_val_if_fail (pk_context != NULL, pk_context);
+ kit_return_val_if_fail (pk_context != NULL, pk_context);
pk_context->refcount++;
return pk_context;
}
polkit_context_unref (PolKitContext *pk_context)
{
- g_return_if_fail (pk_context != NULL);
+ kit_return_if_fail (pk_context != NULL);
pk_context->refcount--;
if (pk_context->refcount > 0)
return;
PolKitContextConfigChangedCB cb,
void *user_data)
{
- g_return_if_fail (pk_context != NULL);
+ kit_return_if_fail (pk_context != NULL);
pk_context->config_changed_cb = cb;
pk_context->config_changed_user_data = user_data;
}
{
gboolean config_changed;
- g_return_if_fail (pk_context != NULL);
+ kit_return_if_fail (pk_context != NULL);
_pk_debug ("polkit_context_io_func: data on fd %d", fd);
PolKitContextAddIOWatch io_add_watch_func,
PolKitContextRemoveIOWatch io_remove_watch_func)
{
- g_return_if_fail (pk_context != NULL);
+ kit_return_if_fail (pk_context != NULL);
pk_context->io_add_watch_func = io_add_watch_func;
pk_context->io_remove_watch_func = io_remove_watch_func;
}
void
polkit_context_set_load_descriptions (PolKitContext *pk_context)
{
- g_return_if_fail (pk_context != NULL);
+ kit_return_if_fail (pk_context != NULL);
pk_context->load_descriptions = TRUE;
}
PolKitPolicyCache *
polkit_context_get_policy_cache (PolKitContext *pk_context)
{
- g_return_val_if_fail (pk_context != NULL, NULL);
+ kit_return_val_if_fail (pk_context != NULL, NULL);
if (pk_context->priv_cache == NULL) {
PolKitError *error;
PolKitConfig *config;
result = POLKIT_RESULT_NO;
- g_return_val_if_fail (pk_context != NULL, result);
+ kit_return_val_if_fail (pk_context != NULL, result);
config = polkit_context_get_config (pk_context, NULL);
/* if the configuration file is malformed, always say no */
polkit_bool_t from_authdb;
result = POLKIT_RESULT_NO;
- g_return_val_if_fail (pk_context != NULL, result);
+ kit_return_val_if_fail (pk_context != NULL, result);
/* if the configuration file is malformed, always say no */
config = polkit_context_get_config (pk_context, NULL);
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
-
#include "polkit-types.h"
#include "polkit-error.h"
#include "polkit-debug.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* PolKitError:
const char *
polkit_error_get_error_name (PolKitError *error)
{
- g_return_val_if_fail (error != NULL, NULL);
- g_return_val_if_fail (error->error_code >= 0 && error->error_code < POLKIT_ERROR_NUM_ERROR_CODES, NULL);
+ kit_return_val_if_fail (error != NULL, NULL);
+ kit_return_val_if_fail (error->error_code >= 0 && error->error_code < POLKIT_ERROR_NUM_ERROR_CODES, NULL);
return error_names[error->error_code];
}
PolKitErrorCode
polkit_error_get_error_code (PolKitError *error)
{
- g_return_val_if_fail (error != NULL, -1);
+ kit_return_val_if_fail (error != NULL, -1);
return error->error_code;
}
const char *
polkit_error_get_error_message (PolKitError *error)
{
- g_return_val_if_fail (error != NULL, NULL);
+ kit_return_val_if_fail (error != NULL, NULL);
return error->error_message;
}
void
polkit_error_free (PolKitError *error)
{
- g_return_if_fail (error != NULL);
+ kit_return_if_fail (error != NULL);
if (!error->is_static) {
- p_free (error->error_message);
- p_free (error);
+ kit_free (error->error_message);
+ kit_free (error);
}
}
va_list args;
PolKitError *e;
- g_return_val_if_fail (format != NULL, FALSE);
- g_return_val_if_fail (error_code >= 0 && error_code < POLKIT_ERROR_NUM_ERROR_CODES, FALSE);
+ kit_return_val_if_fail (format != NULL, FALSE);
+ kit_return_val_if_fail (error_code >= 0 && error_code < POLKIT_ERROR_NUM_ERROR_CODES, FALSE);
if (error == NULL)
goto out;
- e = p_new0 (PolKitError, 1);
+ e = kit_new0 (PolKitError, 1);
if (e == NULL) {
*error = &_oom_error;
} else {
e->is_static = FALSE;
e->error_code = error_code;
va_start (args, format);
- e->error_message = p_strdup_vprintf (format, args);
+ e->error_message = kit_strdup_vprintf (format, args);
va_end (args);
if (e->error_message == NULL) {
- p_free (e);
+ kit_free (e);
*error = &_oom_error;
} else {
*error = e;
char s[256];
e = NULL;
- g_assert (! polkit_error_is_set (e));
- g_assert (! polkit_error_set_error (&e, -1, "Testing"));
- g_assert (! polkit_error_set_error (&e, POLKIT_ERROR_NUM_ERROR_CODES, "Testing"));
+ kit_assert (! polkit_error_is_set (e));
+ kit_assert (! polkit_error_set_error (&e, -1, "Testing"));
+ kit_assert (! polkit_error_set_error (&e, POLKIT_ERROR_NUM_ERROR_CODES, "Testing"));
for (n = 0; n < POLKIT_ERROR_NUM_ERROR_CODES; n++) {
polkit_error_set_error (&e, n, "Testing error code %d", n);
- g_assert (polkit_error_is_set (e));
- g_assert (polkit_error_get_error_code (e) == n || polkit_error_get_error_code (e) == POLKIT_ERROR_OUT_OF_MEMORY);
- g_assert (strcmp (polkit_error_get_error_name (e), error_names[polkit_error_get_error_code (e)]) == 0);
+ kit_assert (polkit_error_is_set (e));
+ kit_assert (polkit_error_get_error_code (e) == n || polkit_error_get_error_code (e) == POLKIT_ERROR_OUT_OF_MEMORY);
+ kit_assert (strcmp (polkit_error_get_error_name (e), error_names[polkit_error_get_error_code (e)]) == 0);
if (polkit_error_get_error_code (e) != POLKIT_ERROR_OUT_OF_MEMORY) {
snprintf (s, sizeof (s), "Testing error code %d", n);
- g_assert (strcmp (polkit_error_get_error_message (e), s) == 0);
+ kit_assert (strcmp (polkit_error_get_error_message (e), s) == 0);
}
polkit_error_free (e);
}
- g_assert (polkit_error_set_error (NULL, POLKIT_ERROR_OUT_OF_MEMORY, "This error will never get set"));
+ kit_assert (polkit_error_set_error (NULL, POLKIT_ERROR_OUT_OF_MEMORY, "This error will never get set"));
return TRUE;
}
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-hash.h : Hash tables
- *
- * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#if !defined (POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H)
-#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
-#endif
-
-#ifndef POLKIT_HASH_H
-#define POLKIT_HASH_H
-
-#include <polkit/polkit-types.h>
-
-POLKIT_BEGIN_DECLS
-
-struct _PolKitHash;
-typedef struct _PolKitHash PolKitHash;
-
-/**
- * PolKitHashFunc:
- * @key: a key
- *
- * The function is passed a key and should return a hash value. The
- * functions polkit_hash_direct_hash_func() and
- * polkit_hash_str_hash_func() provide hash functions which can be
- * used when the key is a pointer and an char* respectively.
- *
- * Returns: the hash value corresponding to the key
- *
- * Since: 0.7
- */
-typedef polkit_uint32_t (*PolKitHashFunc) (const void *key);
-
-/**
- * PolKitEqualFunc:
- * @key1: first key
- * @key2: second key
- *
- * Determines if two keys are equal. The functions
- * polkit_hash_direct_equal_func() and polkit_hash_str_equal_func()
- * provide equality functions which can be used when the key is a
- * pointer and an char* respectively.
- *
- * Returns: #TRUE iff the keys are equal
- *
- * Since: 0.7
- */
-typedef polkit_bool_t (*PolKitEqualFunc) (const void *key1, const void *key2);
-
-/**
- * PolKitFreeFunc:
- * @p: pointer
- *
- * Specifies the type of function which is called when a data element
- * is destroyed. It is passed the pointer to the data element and
- * should free any memory and resources allocated for it. The function
- * p_free() or any of the object unref functions can be passed here.
- *
- * Since: 0.7
- */
-typedef void (*PolKitFreeFunc) (void *p);
-
-/**
- * PolKitCopyFunc:
- * @p: pointer
- *
- * Specifies the type of function which is called when a data element
- * is to be cloned or reffed. It is passed the pointer to the data
- * element and should return a new pointer to a reffed or cloned
- * object. The function polkit_hash_str_copy() or any of the object
- * ref functions can be passed here.
- *
- * Returns: A copy or ref of the object in question
- *
- * Since: 0.7
- */
-typedef void *(*PolKitCopyFunc) (const void *p);
-
-/**
- * PolKitHashForeachFunc:
- * @hash: the hash table
- * @key: key
- * @value: value
- * @user_data: user data passed to polkit_hash_foreach()
- *
- * Type signature for callback function used in polkit_hash_foreach().
- *
- * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
- *
- * Since: 0.7
- */
-typedef polkit_bool_t (*PolKitHashForeachFunc) (PolKitHash *hash,
- void *key,
- void *value,
- void *user_data);
-
-
-PolKitHash *polkit_hash_new (PolKitHashFunc hash_func,
- PolKitEqualFunc key_equal_func,
- PolKitCopyFunc key_copy_func,
- PolKitCopyFunc value_copy_func,
- PolKitFreeFunc key_destroy_func,
- PolKitFreeFunc value_destroy_func);
-
-PolKitHash *polkit_hash_ref (PolKitHash *hash);
-void polkit_hash_unref (PolKitHash *hash);
-
-polkit_bool_t polkit_hash_insert (PolKitHash *hash, void *key, void *value);
-
-void *polkit_hash_lookup (PolKitHash *hash, void *key, polkit_bool_t *found);
-
-polkit_bool_t polkit_hash_foreach (PolKitHash *hash, PolKitHashForeachFunc cb, void *user_data);
-
-
-polkit_uint32_t polkit_hash_direct_hash_func (const void *key);
-polkit_bool_t polkit_hash_direct_equal_func (const void *v1, const void *v2);
-
-polkit_uint32_t polkit_hash_str_hash_func (const void *key);
-polkit_bool_t polkit_hash_str_equal_func (const void *v1, const void *v2);
-void *polkit_hash_str_copy (const void *p);
-
-POLKIT_END_DECLS
-
-#endif /* POLKIT_HASH_H */
-
-
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-memory.c : Memory management
- *
- * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-private.h>
-
-/**
- * SECTION:polkit-memory
- * @title: Memory management
- * @short_description: Memory management
- *
- * Functions used for memory management.
- *
- * Since: 0.7
- **/
-
-
-#ifdef POLKIT_BUILD_TESTS
-
-static int _cur_allocs = 0;
-static int _total_allocs = 0;
-static int _fail_nth = -1;
-
-void
-_polkit_memory_reset (void)
-{
- _cur_allocs = 0;
- _total_allocs = 0;
- _fail_nth = -1;
-}
-
-int
-_polkit_memory_get_current_allocations (void)
-{
- return _cur_allocs;
-}
-
-int
-_polkit_memory_get_total_allocations (void)
-{
- return _total_allocs;
-}
-
-void
-_polkit_memory_fail_nth_alloc (int number)
-{
- _fail_nth = number;
-}
-
-/**
- * p_malloc:
- * @bytes: number of 8-bit bytes to allocate
- *
- * Allocate memory
- *
- * Returns: memory location or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-void *
-p_malloc (size_t bytes)
-{
- void *p;
-
- if (_fail_nth != -1 && _total_allocs == _fail_nth) {
- return NULL;
- }
-
- p = malloc (bytes);
-
- if (p != NULL) {
- _cur_allocs++;
- _total_allocs++;
- }
-
- return p;
-}
-
-/**
- * p_malloc0:
- * @bytes: number of 8-bit bytes to allocate
- *
- * Allocate memory and zero it.
- *
- * Returns: memory location or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-void *
-p_malloc0 (size_t bytes)
-{
- void *p;
-
- if (_fail_nth != -1 && _total_allocs == _fail_nth) {
- return NULL;
- }
-
- p = calloc (1, bytes);
-
- if (p != NULL) {
- _cur_allocs++;
- _total_allocs++;
- }
-
- return p;
-}
-
-/**
- * p_realloc:
- * @memory: memory previously allocated
- * @bytes: new size
- *
- * Reallocate memory; like realloc(3).
- *
- * Returns: memory location or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-void *
-p_realloc (void *memory, size_t bytes)
-{
- void *p;
-
- g_debug ("realloc %p %d", memory, bytes);
-
- if (memory == NULL)
- return p_malloc (bytes);
-
- if (bytes == 0) {
- p_free (memory);
- return memory;
- }
-
- if (_fail_nth != -1 && _total_allocs == _fail_nth) {
- return NULL;
- }
-
- p = realloc (memory, bytes);
-
- return p;
-}
-
-/**
- * p_free:
- * @memory: pointer to memory allocated with p_malloc() + friends
- *
- * Free memory allocated by p_malloc() + friends.
- *
- * Since: 0.7
- */
-void
-p_free (void *memory)
-{
- free (memory);
- if (memory != NULL) {
- _cur_allocs--;
- }
-}
-
-/**
- * p_strdup:
- * @s: string
- *
- * Duplicate a string. Similar to strdup(3).
- *
- * Returns: Allocated memory or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char *
-p_strdup (const char *s)
-{
- char *p;
- size_t len;
-
- len = strlen (s);
-
- p = p_malloc (len + 1);
- if (p == NULL)
- goto out;
-
- memcpy (p, s, len);
- p[len] = '\0';
-
-out:
- return p;
-}
-
-/**
- * p_strndup:
- * @s: string
- * @n: size
- *
- * Duplicate a string but copy at most @n characters. If @s is longer
- * than @n, only @n characters are copied, and a terminating null byte
- * is added. Similar to strndup(3).
- *
- * Returns: Allocated memory or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char *
-p_strndup (const char *s, size_t n)
-{
- char *p;
- size_t len;
-
- for (len = 0; len < n; len++) {
- if (s[len] == '\0')
- break;
- if (len == n)
- break;
- }
-
-
- p = p_malloc (len + 1);
- if (p == NULL)
- goto out;
-
- memcpy (p, s, len);
- p[len] = '\0';
-out:
- return p;
-}
-
-/*--------------------------------------------------------------------------------------------------------------*/
-#else
-/*--------------------------------------------------------------------------------------------------------------*/
-
-void *
-p_malloc (size_t bytes)
-{
- return malloc (bytes);
-}
-
-void *
-p_malloc0 (size_t bytes)
-{
- return calloc (1, bytes);
-}
-
-void *
-p_realloc (void *memory, size_t bytes)
-{
- return realloc (memory, bytes);
-}
-
-void
-p_free (void *memory)
-{
- free (memory);
-}
-
-void
-_polkit_memory_reset (void)
-{
-}
-
-int
-_polkit_memory_get_current_allocations (void)
-{
- return -1;
-}
-
-int
-_polkit_memory_get_total_allocations (void)
-{
- return -1;
-}
-
-void
-_polkit_memory_fail_nth_alloc (int number)
-{
-}
-
-char *
-p_strdup (const char *s)
-{
- return strdup (s);
-}
-
-char *
-p_strndup (const char *s, size_t n)
-{
- return strndup (s, n);
-}
-
-#endif /* POLKIT_BUILD_TESTS */
-
-/**
- * p_strdup_printf:
- * @format: sprintf(3) format string
- * @...: the parameters to insert into the format string.
- *
- * Similar to the standard C sprintf(3) function but safer, since it
- * calculates the maximum space required and allocates memory to hold
- * the result. The returned string should be freed when no longer
- * needed.
- *
- * Returns: A newly allocated string or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char*
-p_strdup_printf (const char *format, ...)
-{
- char *s;
- va_list args;
-
- va_start (args, format);
- s = p_strdup_vprintf (format, args);
- va_end (args);
-
- return s;
-}
-
-/**
- * p_strdup_vprintf:
- * @format: printf(3) format string
- * @args: list of parameters to insert
- *
- * Similar to the standard C vsprintf(3) function but safer, since it
- * calculates the maximum space required and allocates memory to hold
- * the result. The returned string should be freed when no longer
- * needed.
- *
- * Returns: A newly allocated string or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char*
-p_strdup_vprintf (const char *format, va_list args)
-{
- char *s;
- char *gs;
- /* TODO: reimplement */
- gs = g_strdup_vprintf (format, args);
- s = p_strdup (gs);
- g_free (gs);
-
- return s;
-}
#include <fcntl.h>
#include <dirent.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-policy-file.h"
#include "polkit-policy-cache.h"
#include "polkit-private.h"
-#include "polkit-memory.h"
-#include "polkit-list.h"
#include "polkit-test.h"
/**
{
int refcount;
- PolKitList *priv_entries;
+ KitList *priv_entries;
};
PolKitPolicyFileEntry *policy_file_entry,
void *user_data)
{
- PolKitList *l;
+ KitList *l;
PolKitPolicyCache *policy_cache = user_data;
polkit_policy_file_entry_ref (policy_file_entry);
- l = polkit_list_prepend (policy_cache->priv_entries, policy_file_entry);
+ l = kit_list_prepend (policy_cache->priv_entries, policy_file_entry);
if (l == NULL) {
polkit_policy_file_entry_unref (policy_file_entry);
goto oom;
dir = NULL;
- pc = p_new0 (PolKitPolicyCache, 1);
+ pc = kit_new0 (PolKitPolicyCache, 1);
if (pc == NULL) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory");
goto out;
if (name_len < sizeof (suffix) || strcmp ((filename + name_len - sizeof (suffix) + 1), suffix) != 0)
continue;
- path = g_strdup_printf ("%s/%s", dirname, filename);
+ path = kit_strdup_printf ("%s/%s", dirname, filename);
+ if (path == NULL) {
+ polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory");
+ goto out;
+ }
_pk_debug ("Loading %s", path);
pk_error = NULL;
pf = polkit_policy_file_new (path, load_descriptions, &pk_error);
- g_free (path);
+ kit_free (path);
if (pf == NULL) {
if (polkit_error_get_error_code (pk_error) == POLKIT_ERROR_OUT_OF_MEMORY) {
PolKitPolicyCache *
polkit_policy_cache_ref (PolKitPolicyCache *policy_cache)
{
- g_return_val_if_fail (policy_cache != NULL, policy_cache);
+ kit_return_val_if_fail (policy_cache != NULL, policy_cache);
policy_cache->refcount++;
return policy_cache;
}
void
polkit_policy_cache_unref (PolKitPolicyCache *policy_cache)
{
- PolKitList *i;
+ KitList *i;
- g_return_if_fail (policy_cache != NULL);
+ kit_return_if_fail (policy_cache != NULL);
policy_cache->refcount--;
if (policy_cache->refcount > 0)
return;
polkit_policy_file_entry_unref (pfe);
}
if (policy_cache->priv_entries != NULL)
- polkit_list_free (policy_cache->priv_entries);
+ kit_list_free (policy_cache->priv_entries);
- p_free (policy_cache);
+ kit_free (policy_cache);
}
/**
void
polkit_policy_cache_debug (PolKitPolicyCache *policy_cache)
{
- PolKitList *i;
- g_return_if_fail (policy_cache != NULL);
+ KitList *i;
+ kit_return_if_fail (policy_cache != NULL);
_pk_debug ("PolKitPolicyCache: refcount=%d num_entries=%d ...",
policy_cache->refcount,
- policy_cache->priv_entries == NULL ? 0 : polkit_list_length (policy_cache->priv_entries));
+ policy_cache->priv_entries == NULL ? 0 : kit_list_length (policy_cache->priv_entries));
for (i = policy_cache->priv_entries; i != NULL; i = i->next) {
PolKitPolicyFileEntry *pfe = i->data;
PolKitPolicyFileEntry*
polkit_policy_cache_get_entry_by_id (PolKitPolicyCache *policy_cache, const char *action_id)
{
- PolKitList *i;
+ KitList *i;
PolKitPolicyFileEntry *pfe;
- g_return_val_if_fail (policy_cache != NULL, NULL);
- g_return_val_if_fail (action_id != NULL, NULL);
+ kit_return_val_if_fail (policy_cache != NULL, NULL);
+ kit_return_val_if_fail (action_id != NULL, NULL);
pfe = NULL;
/* I'm sure it would be easy to make this O(1)... */
- g_return_val_if_fail (policy_cache != NULL, NULL);
- g_return_val_if_fail (action != NULL, NULL);
+ kit_return_val_if_fail (policy_cache != NULL, NULL);
+ kit_return_val_if_fail (action != NULL, NULL);
pfe = NULL;
PolKitPolicyCacheForeachFunc callback,
void *user_data)
{
- PolKitList *i;
+ KitList *i;
PolKitPolicyFileEntry *pfe;
- g_return_val_if_fail (policy_cache != NULL, FALSE);
- g_return_val_if_fail (callback != NULL, FALSE);
+ kit_return_val_if_fail (policy_cache != NULL, FALSE);
+ kit_return_val_if_fail (callback != NULL, FALSE);
for (i = policy_cache->priv_entries; i != NULL; i = i->next) {
pfe = i->data;
const char *annotation_key,
const char *annotation_value)
{
- PolKitList *i;
+ KitList *i;
- g_return_val_if_fail (policy_cache != NULL, NULL);
- g_return_val_if_fail (annotation_key != NULL, NULL);
- g_return_val_if_fail (annotation_value != NULL, NULL);
+ kit_return_val_if_fail (policy_cache != NULL, NULL);
+ kit_return_val_if_fail (annotation_key != NULL, NULL);
+ kit_return_val_if_fail (annotation_value != NULL, NULL);
for (i = policy_cache->priv_entries; i != NULL; i = i->next) {
const char *value;
int counter;
error = NULL;
- g_assert (_polkit_policy_cache_new (TEST_DATA_DIR "/non-existant", TRUE, &error) == NULL);
- g_assert (polkit_error_is_set (error) &&
+ kit_assert (_polkit_policy_cache_new (TEST_DATA_DIR "/non-existant", TRUE, &error) == NULL);
+ kit_assert (polkit_error_is_set (error) &&
(polkit_error_get_error_code (error) == POLKIT_ERROR_POLICY_FILE_INVALID ||
polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY));
polkit_error_free (error);
error = NULL;
if ((pc = _polkit_policy_cache_new (TEST_DATA_DIR "/invalid", TRUE, &error)) == NULL) {
- g_assert (polkit_error_is_set (error) &&
+ kit_assert (polkit_error_is_set (error) &&
polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
polkit_error_free (error);
} else {
error = NULL;
if ((pc = _polkit_policy_cache_new (TEST_DATA_DIR "/valid", TRUE, &error)) == NULL) {
- g_assert (polkit_error_is_set (error) &&
+ kit_assert (polkit_error_is_set (error) &&
polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
polkit_error_free (error);
goto out;
}
- g_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.valid1") != NULL);
- g_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.non-existant") == NULL);
+ kit_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.valid1") != NULL);
+ kit_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.non-existant") == NULL);
pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key1", "Some Value 1");
- g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
+ kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key2", "Some Value 2");
- g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
+ kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key1", "Some Value 1b");
- g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2b") == 0);
+ kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2b") == 0);
pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key1", "NON-EXISTANT VALUE");
- g_assert (pfe == NULL);
+ kit_assert (pfe == NULL);
pfe = polkit_policy_cache_get_entry_by_annotation (pc, "NON_EXISTANT KEY", "NON-EXISTANT VALUE");
- g_assert (pfe == NULL);
+ kit_assert (pfe == NULL);
if ((a = polkit_action_new ()) != NULL) {
pfe = polkit_policy_cache_get_entry (pc, a);
- g_assert (pfe == NULL);
+ kit_assert (pfe == NULL);
if (polkit_action_set_action_id (a, "org.example.valid1")) {
pfe = polkit_policy_cache_get_entry (pc, a);
- g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid1") == 0);
+ kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid1") == 0);
}
if (polkit_action_set_action_id (a, "org.example.non-existant")) {
pfe = polkit_policy_cache_get_entry (pc, a);
- g_assert (pfe == NULL);
+ kit_assert (pfe == NULL);
}
polkit_action_unref (a);
counter = 0;
polkit_policy_cache_foreach (pc, _test_count, &counter);
- g_assert (counter == 6);
+ kit_assert (counter == 6);
counter = 0;
polkit_policy_cache_foreach (pc, _test_short_circuit, &counter);
- g_assert (counter == 1);
+ kit_assert (counter == 1);
polkit_policy_cache_debug (pc);
polkit_policy_cache_ref (pc);
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-error.h"
#include "polkit-policy-default.h"
#include "polkit-private.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-policy-default
{
PolKitPolicyDefault *pd;
- pd = p_new0 (PolKitPolicyDefault, 1);
+ pd = kit_new0 (PolKitPolicyDefault, 1);
if (pd == NULL)
goto out;
pd->refcount = 1;
PolKitPolicyDefault *
polkit_policy_default_ref (PolKitPolicyDefault *policy_default)
{
- g_return_val_if_fail (policy_default != NULL, policy_default);
+ kit_return_val_if_fail (policy_default != NULL, policy_default);
policy_default->refcount++;
return policy_default;
}
void
polkit_policy_default_unref (PolKitPolicyDefault *policy_default)
{
- g_return_if_fail (policy_default != NULL);
+ kit_return_if_fail (policy_default != NULL);
policy_default->refcount--;
if (policy_default->refcount > 0)
return;
- p_free (policy_default);
+ kit_free (policy_default);
}
/**
void
polkit_policy_default_debug (PolKitPolicyDefault *policy_default)
{
- g_return_if_fail (policy_default != NULL);
+ kit_return_if_fail (policy_default != NULL);
_pk_debug ("PolKitPolicyDefault: refcount=%d\n"
" default_any=%s\n"
" default_inactive=%s\n"
ret = POLKIT_RESULT_NO;
- g_return_val_if_fail (policy_default != NULL, ret);
- g_return_val_if_fail (action != NULL, ret);
- g_return_val_if_fail (session != NULL, ret);
+ kit_return_val_if_fail (policy_default != NULL, ret);
+ kit_return_val_if_fail (action != NULL, ret);
+ kit_return_val_if_fail (session != NULL, ret);
ret = policy_default->default_any;
ret = POLKIT_RESULT_NO;
- g_return_val_if_fail (policy_default != NULL, ret);
- g_return_val_if_fail (action != NULL, ret);
- g_return_val_if_fail (caller != NULL, ret);
+ kit_return_val_if_fail (policy_default != NULL, ret);
+ kit_return_val_if_fail (action != NULL, ret);
+ kit_return_val_if_fail (caller != NULL, ret);
ret = policy_default->default_any;
PolKitResult
polkit_policy_default_get_allow_any (PolKitPolicyDefault *policy_default)
{
- g_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
+ kit_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
return policy_default->default_any;
}
PolKitResult
polkit_policy_default_get_allow_inactive (PolKitPolicyDefault *policy_default)
{
- g_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
+ kit_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
return policy_default->default_inactive;
}
PolKitResult
polkit_policy_default_get_allow_active (PolKitPolicyDefault *policy_default)
{
- g_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
+ kit_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
return policy_default->default_active;
}
oom = FALSE;
if ((c = polkit_caller_new ()) != NULL) {
- g_assert (polkit_policy_default_can_caller_do_action (d, a, c) == any);
+ kit_assert (polkit_policy_default_can_caller_do_action (d, a, c) == any);
- g_assert (polkit_caller_set_ck_session (c, s));
- g_assert (polkit_policy_default_can_caller_do_action (d, a, c) == *ret);
+ kit_assert (polkit_caller_set_ck_session (c, s));
+ kit_assert (polkit_policy_default_can_caller_do_action (d, a, c) == *ret);
polkit_caller_unref (c);
}
polkit_session_unref (s_active);
s_active = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_active, TRUE));
- g_assert (polkit_session_set_ck_is_active (s_active, TRUE));
+ kit_assert (polkit_session_set_ck_is_local (s_active, TRUE));
+ kit_assert (polkit_session_set_ck_is_active (s_active, TRUE));
}
}
polkit_session_unref (s_inactive);
s_inactive = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
- g_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
+ kit_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
+ kit_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
}
}
polkit_session_unref (s_active_remote);
s_active_remote = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
- g_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
+ kit_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
+ kit_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
}
}
polkit_session_unref (s_inactive_remote);
s_inactive_remote = NULL;
} else {
- g_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
- g_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
+ kit_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
+ kit_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
}
}
- g_assert (_ts (s_active,
+ kit_assert (_ts (s_active,
POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
- g_assert (_ts (s_inactive,
+ kit_assert (_ts (s_inactive,
POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_NO);
- g_assert (_ts (s_active_remote,
+ kit_assert (_ts (s_active_remote,
POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_NO);
- g_assert (_ts (s_inactive_remote,
+ kit_assert (_ts (s_inactive_remote,
POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_NO);
- g_assert (_ts (s_active,
+ kit_assert (_ts (s_active,
POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
- g_assert (_ts (s_inactive,
+ kit_assert (_ts (s_inactive,
POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
- g_assert (_ts (s_active_remote,
+ kit_assert (_ts (s_active_remote,
POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_NO);
- g_assert (_ts (s_inactive_remote,
+ kit_assert (_ts (s_inactive_remote,
POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_NO);
- g_assert (_ts (s_active,
+ kit_assert (_ts (s_active,
POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
- g_assert (_ts (s_inactive,
+ kit_assert (_ts (s_inactive,
POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
- g_assert (_ts (s_active_remote,
+ kit_assert (_ts (s_active_remote,
POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
- g_assert (_ts (s_inactive_remote,
+ kit_assert (_ts (s_inactive_remote,
POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) ||
ret == POLKIT_RESULT_YES);
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-error.h"
#include "polkit-result.h"
#include "polkit-authorization-db.h"
#include "polkit-private.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-policy-file-entry
char *policy_description;
char *policy_message;
- PolKitHash *annotations;
+ KitHash *annotations;
};
PolKitResult defaults_allow_any,
PolKitResult defaults_allow_inactive,
PolKitResult defaults_allow_active,
- PolKitHash *annotations)
+ KitHash *annotations)
{
PolKitPolicyFileEntry *pfe;
- g_return_val_if_fail (action_id != NULL, NULL);
+ kit_return_val_if_fail (action_id != NULL, NULL);
- pfe = p_new0 (PolKitPolicyFileEntry, 1);
+ pfe = kit_new0 (PolKitPolicyFileEntry, 1);
if (pfe == NULL)
goto error;
pfe->refcount = 1;
- pfe->action = p_strdup (action_id);
+ pfe->action = kit_strdup (action_id);
if (pfe->action == NULL)
goto error;
const char *policy_description,
const char *policy_message)
{
- g_return_val_if_fail (pfe != NULL, FALSE);
+ kit_return_val_if_fail (pfe != NULL, FALSE);
if (pfe->policy_description != NULL)
- p_free (pfe->policy_description);
+ kit_free (pfe->policy_description);
if (pfe->policy_message != NULL)
- p_free (pfe->policy_message);
+ kit_free (pfe->policy_message);
- pfe->policy_description = p_strdup (policy_description);
- pfe->policy_message = p_strdup (policy_message);
+ pfe->policy_description = kit_strdup (policy_description);
+ pfe->policy_message = kit_strdup (policy_message);
if (policy_description != NULL && pfe->policy_description == NULL)
return FALSE;
const char *
polkit_policy_file_entry_get_action_description (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_val_if_fail (policy_file_entry != NULL, NULL);
+ kit_return_val_if_fail (policy_file_entry != NULL, NULL);
return policy_file_entry->policy_description;
}
const char *
polkit_policy_file_entry_get_action_message (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_val_if_fail (policy_file_entry != NULL, NULL);
+ kit_return_val_if_fail (policy_file_entry != NULL, NULL);
return policy_file_entry->policy_message;
}
PolKitPolicyFileEntry *
polkit_policy_file_entry_ref (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_val_if_fail (policy_file_entry != NULL, policy_file_entry);
+ kit_return_val_if_fail (policy_file_entry != NULL, policy_file_entry);
policy_file_entry->refcount++;
return policy_file_entry;
}
void
polkit_policy_file_entry_unref (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_if_fail (policy_file_entry != NULL);
+ kit_return_if_fail (policy_file_entry != NULL);
policy_file_entry->refcount--;
if (policy_file_entry->refcount > 0)
return;
- p_free (policy_file_entry->action);
+ kit_free (policy_file_entry->action);
if (policy_file_entry->defaults != NULL)
polkit_policy_default_unref (policy_file_entry->defaults);
if (policy_file_entry->annotations != NULL)
- polkit_hash_unref (policy_file_entry->annotations);
+ kit_hash_unref (policy_file_entry->annotations);
- p_free (policy_file_entry->policy_description);
- p_free (policy_file_entry->policy_message);
+ kit_free (policy_file_entry->policy_description);
+ kit_free (policy_file_entry->policy_message);
- p_free (policy_file_entry);
+ kit_free (policy_file_entry);
}
/**
void
polkit_policy_file_entry_debug (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_if_fail (policy_file_entry != NULL);
+ kit_return_if_fail (policy_file_entry != NULL);
_pk_debug ("PolKitPolicyFileEntry: refcount=%d action=%s",
policy_file_entry->refcount,
policy_file_entry->action);
const char *
polkit_policy_file_entry_get_id (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_val_if_fail (policy_file_entry != NULL, NULL);
+ kit_return_val_if_fail (policy_file_entry != NULL, NULL);
return policy_file_entry->action;
}
PolKitPolicyDefault *
polkit_policy_file_entry_get_default (PolKitPolicyFileEntry *policy_file_entry)
{
- g_return_val_if_fail (policy_file_entry != NULL, NULL);
+ kit_return_val_if_fail (policy_file_entry != NULL, NULL);
return policy_file_entry->defaults;
}
} _AnnotationsClosure;
static polkit_bool_t
-_annotations_cb (PolKitHash *hash,
+_annotations_cb (KitHash *hash,
void *key,
void *value,
void *user_data)
{
_AnnotationsClosure closure;
- g_return_val_if_fail (policy_file_entry != NULL, FALSE);
+ kit_return_val_if_fail (policy_file_entry != NULL, FALSE);
if (policy_file_entry->annotations == NULL)
return FALSE;
closure.cb = cb;
closure.user_data = user_data;
- return polkit_hash_foreach (policy_file_entry->annotations,
+ return kit_hash_foreach (policy_file_entry->annotations,
_annotations_cb,
&closure);
}
const char *key)
{
const char *value;
- g_return_val_if_fail (policy_file_entry != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
+ kit_return_val_if_fail (policy_file_entry != NULL, NULL);
+ kit_return_val_if_fail (key != NULL, NULL);
value = NULL;
if (policy_file_entry->annotations != NULL) {
- value = polkit_hash_lookup (policy_file_entry->annotations, (void *) key, NULL);
+ value = kit_hash_lookup (policy_file_entry->annotations, (void *) key, NULL);
}
return value;
}
{
PolKitPolicyFileEntry *pfe;
PolKitPolicyDefault *d;
- PolKitHash *a;
+ KitHash *a;
int count;
a = NULL;
pfe = NULL;
- if ((a = polkit_hash_new (polkit_hash_str_hash_func,
- polkit_hash_str_equal_func,
- NULL, NULL,
- NULL, NULL)) == NULL)
+ if ((a = kit_hash_new (kit_hash_str_hash_func,
+ kit_hash_str_equal_func,
+ NULL, NULL,
+ NULL, NULL)) == NULL)
goto oom;
- if (!polkit_hash_insert (a, "a1", "v1"))
+ if (!kit_hash_insert (a, "a1", "v1"))
goto oom;
- if (!polkit_hash_insert (a, "a2", "v2"))
+ if (!kit_hash_insert (a, "a2", "v2"))
goto oom;
if ((pfe = _polkit_policy_file_entry_new ("org.example-action",
/* _file_entry_new assumes ownership of the passed a variable */
a = NULL;
- g_assert (strcmp (polkit_policy_file_entry_get_id (pfe), "org.example-action") == 0);
+ kit_assert (strcmp (polkit_policy_file_entry_get_id (pfe), "org.example-action") == 0);
if (_polkit_policy_file_entry_set_descriptions (pfe,
"the desc",
"the msg")) {
- g_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc") == 0);
- g_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg") == 0);
+ kit_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc") == 0);
+ kit_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg") == 0);
}
if (_polkit_policy_file_entry_set_descriptions (pfe,
"the desc2",
"the msg2")) {
- g_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc2") == 0);
- g_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg2") == 0);
+ kit_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc2") == 0);
+ kit_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg2") == 0);
}
- g_assert ((d = polkit_policy_file_entry_get_default (pfe)) != NULL);
- g_assert (polkit_policy_default_get_allow_any (d) == POLKIT_RESULT_NO);
- g_assert (polkit_policy_default_get_allow_inactive (d) == POLKIT_RESULT_ONLY_VIA_SELF_AUTH);
- g_assert (polkit_policy_default_get_allow_active (d) == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH);
+ kit_assert ((d = polkit_policy_file_entry_get_default (pfe)) != NULL);
+ kit_assert (polkit_policy_default_get_allow_any (d) == POLKIT_RESULT_NO);
+ kit_assert (polkit_policy_default_get_allow_inactive (d) == POLKIT_RESULT_ONLY_VIA_SELF_AUTH);
+ kit_assert (polkit_policy_default_get_allow_active (d) == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH);
polkit_policy_file_entry_ref (pfe);
polkit_policy_file_entry_unref (pfe);
polkit_policy_file_entry_debug (pfe);
- g_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a1"), "v1") == 0);
- g_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a2"), "v2") == 0);
- g_assert (polkit_policy_file_entry_get_annotation (pfe, "a3") == NULL);
+ kit_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a1"), "v1") == 0);
+ kit_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a2"), "v2") == 0);
+ kit_assert (polkit_policy_file_entry_get_annotation (pfe, "a3") == NULL);
count = 0;
polkit_policy_file_entry_annotations_foreach (pfe, _pfe_cb, &count);
- g_assert (count == 2);
+ kit_assert (count == 2);
polkit_policy_file_entry_unref (pfe);
if ((pfe = _polkit_policy_file_entry_new ("org.example-action-2",
goto oom;
count = 0;
polkit_policy_file_entry_annotations_foreach (pfe, _pfe_cb2, &count);
- g_assert (count == 0);
+ kit_assert (count == 0);
_pfe_cb2 (pfe, NULL, NULL, &count); /* want to get coverage of _pfe_cb2 */
- g_assert (count == 1);
+ kit_assert (count == 1);
oom:
if (pfe != NULL)
polkit_policy_file_entry_unref (pfe);
if (a != NULL)
- polkit_hash_unref (a);
+ kit_hash_unref (a);
return TRUE;
}
#include <unistd.h>
#include <errno.h>
#include <syslog.h>
+#include <sys/stat.h>
#include <expat.h>
-#include <glib.h>
#include "polkit-error.h"
#include "polkit-result.h"
#include "polkit-policy-file.h"
#include "polkit-debug.h"
#include "polkit-private.h"
#include "polkit-test.h"
-#include "polkit-list.h"
/**
* SECTION:polkit-policy-file
struct _PolKitPolicyFile
{
int refcount;
- PolKitList *entries;
+ KitList *entries;
};
enum {
polkit_bool_t load_descriptions;
- PolKitHash *policy_descriptions;
- PolKitHash *policy_messages;
+ KitHash *policy_descriptions;
+ KitHash *policy_messages;
char *policy_description_nolang;
char *policy_message_nolang;
char *elem_lang;
char *annotate_key;
- PolKitHash *annotations;
+ KitHash *annotations;
polkit_bool_t is_oom;
} ParserData;
static void
pd_unref_action_data (ParserData *pd)
{
- p_free (pd->action_id);
+ kit_free (pd->action_id);
pd->action_id = NULL;
- p_free (pd->policy_description_nolang);
+ kit_free (pd->policy_description_nolang);
pd->policy_description_nolang = NULL;
- p_free (pd->policy_message_nolang);
+ kit_free (pd->policy_message_nolang);
pd->policy_message_nolang = NULL;
if (pd->policy_descriptions != NULL) {
- polkit_hash_unref (pd->policy_descriptions);
+ kit_hash_unref (pd->policy_descriptions);
pd->policy_descriptions = NULL;
}
if (pd->policy_messages != NULL) {
- polkit_hash_unref (pd->policy_messages);
+ kit_hash_unref (pd->policy_messages);
pd->policy_messages = NULL;
}
- p_free (pd->annotate_key);
+ kit_free (pd->annotate_key);
pd->annotate_key = NULL;
if (pd->annotations != NULL) {
- polkit_hash_unref (pd->annotations);
+ kit_hash_unref (pd->annotations);
pd->annotations = NULL;
}
- p_free (pd->elem_lang);
+ kit_free (pd->elem_lang);
pd->elem_lang = NULL;
}
pd_unref_data (ParserData *pd)
{
pd_unref_action_data (pd);
- p_free (pd->lang);
+ kit_free (pd->lang);
pd->lang = NULL;
}
goto error;
pd_unref_action_data (pd);
- pd->action_id = p_strdup (attr[1]);
+ pd->action_id = kit_strdup (attr[1]);
if (pd->action_id == NULL)
goto oom;
- pd->policy_descriptions = polkit_hash_new (polkit_hash_str_hash_func,
- polkit_hash_str_equal_func,
- polkit_hash_str_copy, polkit_hash_str_copy,
- p_free, p_free);
- pd->policy_messages = polkit_hash_new (polkit_hash_str_hash_func,
- polkit_hash_str_equal_func,
- polkit_hash_str_copy, polkit_hash_str_copy,
- p_free, p_free);
+ pd->policy_descriptions = kit_hash_new (kit_hash_str_hash_func,
+ kit_hash_str_equal_func,
+ kit_hash_str_copy, kit_hash_str_copy,
+ kit_free, kit_free);
+ pd->policy_messages = kit_hash_new (kit_hash_str_hash_func,
+ kit_hash_str_equal_func,
+ kit_hash_str_copy, kit_hash_str_copy,
+ kit_free, kit_free);
/* initialize defaults */
pd->defaults_allow_any = POLKIT_RESULT_NO;
state = STATE_IN_DEFAULTS;
} else if (strcmp (el, "description") == 0) {
if (num_attr == 2 && strcmp (attr[0], "xml:lang") == 0) {
- pd->elem_lang = p_strdup (attr[1]);
+ pd->elem_lang = kit_strdup (attr[1]);
if (pd->elem_lang == NULL)
goto oom;
}
state = STATE_IN_ACTION_DESCRIPTION;
} else if (strcmp (el, "message") == 0) {
if (num_attr == 2 && strcmp (attr[0], "xml:lang") == 0) {
- pd->elem_lang = p_strdup (attr[1]);
+ pd->elem_lang = kit_strdup (attr[1]);
if (pd->elem_lang == NULL)
goto oom;
}
goto error;
state = STATE_IN_ANNOTATE;
- p_free (pd->annotate_key);
- pd->annotate_key = p_strdup (attr[1]);
+ kit_free (pd->annotate_key);
+ pd->annotate_key = kit_strdup (attr[1]);
if (pd->annotate_key == NULL)
goto oom;
}
char *str;
ParserData *pd = data;
- str = p_strndup (s, len);
+ str = kit_strndup (s, len);
if (str == NULL)
goto oom;
case STATE_IN_ACTION_DESCRIPTION:
if (pd->load_descriptions) {
if (pd->elem_lang == NULL) {
- p_free (pd->policy_description_nolang);
+ kit_free (pd->policy_description_nolang);
pd->policy_description_nolang = str;
str = NULL;
} else {
- if (!polkit_hash_insert (pd->policy_descriptions, pd->elem_lang, str))
+ if (!kit_hash_insert (pd->policy_descriptions, pd->elem_lang, str))
goto oom;
}
}
case STATE_IN_ACTION_MESSAGE:
if (pd->load_descriptions) {
if (pd->elem_lang == NULL) {
- p_free (pd->policy_message_nolang);
+ kit_free (pd->policy_message_nolang);
pd->policy_message_nolang = str;
str = NULL;
} else {
- if (!polkit_hash_insert (pd->policy_messages, pd->elem_lang, str))
+ if (!kit_hash_insert (pd->policy_messages, pd->elem_lang, str))
goto oom;
}
}
case STATE_IN_ANNOTATE:
if (pd->annotations == NULL) {
- pd->annotations = polkit_hash_new (polkit_hash_str_hash_func,
- polkit_hash_str_equal_func,
- polkit_hash_str_copy, polkit_hash_str_copy,
- p_free, p_free);
+ pd->annotations = kit_hash_new (kit_hash_str_hash_func,
+ kit_hash_str_equal_func,
+ kit_hash_str_copy, kit_hash_str_copy,
+ kit_free, kit_free);
if (pd->annotations == NULL)
goto oom;
}
- if (!polkit_hash_insert (pd->annotations, pd->annotate_key, str))
+ if (!kit_hash_insert (pd->annotations, pd->annotate_key, str))
goto oom;
break;
default:
break;
}
- p_free (str);
+ kit_free (str);
return;
oom:
pd->is_oom = TRUE;
error:
- p_free (str);
+ kit_free (str);
XML_StopParser (pd->parser, FALSE);
}
* Returns: the localized string to use
*/
static const char *
-_localize (PolKitHash *translations, const char *untranslated, const char *lang)
+_localize (KitHash *translations, const char *untranslated, const char *lang)
{
const char *result;
char lang2[256];
}
/* first see if we have the translation */
- result = (const char *) polkit_hash_lookup (translations, (void *) lang, NULL);
+ result = (const char *) kit_hash_lookup (translations, (void *) lang, NULL);
if (result != NULL)
goto out;
break;
}
}
- result = (const char *) polkit_hash_lookup (translations, (void *) lang2, NULL);
+ result = (const char *) kit_hash_lookup (translations, (void *) lang2, NULL);
if (result != NULL)
goto out;
_end (void *data, const char *el)
{
ParserData *pd = data;
- PolKitList *l;
+ KitList *l;
- p_free (pd->elem_lang);
+ kit_free (pd->elem_lang);
pd->elem_lang = NULL;
switch (pd->state) {
}
}
- l = polkit_list_prepend (pd->pf->entries, pfe);
+ l = kit_list_prepend (pd->pf->entries, pfe);
if (l == NULL) {
polkit_policy_file_entry_unref (pfe);
goto oom;
XML_StopParser (pd->parser, FALSE);
}
-
/**
* polkit_policy_file_new:
* @path: path to file
int xml_res;
char *lang;
char *buf;
- gsize buflen;
- GError *g_error;
+ size_t buflen;
pf = NULL;
buf = NULL;
/* clear parser data */
memset (&pd, 0, sizeof (ParserData));
- if (!g_str_has_suffix (path, ".policy")) {
+ if (!kit_str_has_suffix (path, ".policy")) {
polkit_error_set_error (error,
POLKIT_ERROR_POLICY_FILE_INVALID,
"Policy files must have extension .policy; file '%s' doesn't", path);
goto error;
}
- g_error = NULL;
- if (!g_file_get_contents (path, &buf, &buflen, &g_error)) {
- polkit_error_set_error (error, POLKIT_ERROR_POLICY_FILE_INVALID,
- "Cannot load PolicyKit policy file at '%s': %s",
- path,
- g_error->message);
- g_error_free (g_error);
+ if (!kit_file_get_contents (path, &buf, &buflen)) {
+ if (errno == ENOMEM) {
+ polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
+ "Cannot load PolicyKit policy file at '%s': %s",
+ path,
+ "No memory for parser");
+ } else {
+ polkit_error_set_error (error, POLKIT_ERROR_POLICY_FILE_INVALID,
+ "Cannot load PolicyKit policy file at '%s': %m",
+ path);
+ }
goto error;
}
TODO: expat appears to leak on certain OOM paths
*/
#if 0
- XML_Memory_Handling_Suite memsuite = {p_malloc, p_realloc, p_free};
+ XML_Memory_Handling_Suite memsuite = {p_malloc, p_realloc, kit_free};
pd.parser = XML_ParserCreate_MM (NULL, &memsuite, NULL);
#else
pd.parser = XML_ParserCreate (NULL);
XML_SetElementHandler (pd.parser, _start, _end);
XML_SetCharacterDataHandler (pd.parser, _cdata);
- pf = p_new0 (PolKitPolicyFile, 1);
+ pf = kit_new0 (PolKitPolicyFile, 1);
if (pf == NULL) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
"Cannot load PolicyKit policy file at '%s': No memory for object",
lang = getenv ("LANG");
if (lang != NULL) {
int n;
- pd.lang = p_strdup (lang);
+ pd.lang = kit_strdup (lang);
if (pd.lang == NULL) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
"Cannot load PolicyKit policy file at '%s': No memory for lang",
}
XML_ParserFree (pd.parser);
- g_free (buf);
+ kit_free (buf);
pd_unref_data (&pd);
return pf;
error:
if (pf != NULL)
polkit_policy_file_unref (pf);
pd_unref_data (&pd);
- g_free (buf);
+ kit_free (buf);
return NULL;
}
PolKitPolicyFile *
polkit_policy_file_ref (PolKitPolicyFile *policy_file)
{
- g_return_val_if_fail (policy_file != NULL, policy_file);
+ kit_return_val_if_fail (policy_file != NULL, policy_file);
policy_file->refcount++;
return policy_file;
}
void
polkit_policy_file_unref (PolKitPolicyFile *policy_file)
{
- PolKitList *i;
- g_return_if_fail (policy_file != NULL);
+ KitList *i;
+ kit_return_if_fail (policy_file != NULL);
policy_file->refcount--;
if (policy_file->refcount > 0)
return;
polkit_policy_file_entry_unref (i->data);
}
if (policy_file->entries != NULL)
- polkit_list_free (policy_file->entries);
- p_free (policy_file);
+ kit_list_free (policy_file->entries);
+ kit_free (policy_file);
}
/**
PolKitPolicyFileEntryForeachFunc cb,
void *user_data)
{
- PolKitList *i;
+ KitList *i;
- g_return_val_if_fail (policy_file != NULL, FALSE);
- g_return_val_if_fail (cb != NULL, FALSE);
+ kit_return_val_if_fail (policy_file != NULL, FALSE);
+ kit_return_val_if_fail (cb != NULL, FALSE);
for (i = policy_file->entries; i != NULL; i = i->next) {
PolKitPolicyFileEntry *pfe = i->data;
for (n = 0; n < sizeof (invalid_files) / sizeof (char*); n++) {
error = NULL;
- g_assert (polkit_policy_file_new (invalid_files[n], TRUE, &error) == NULL);
- g_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY ||
+ kit_assert (polkit_policy_file_new (invalid_files[n], TRUE, &error) == NULL);
+ kit_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY ||
polkit_error_get_error_code (error) == POLKIT_ERROR_POLICY_FILE_INVALID);
polkit_error_free (error);
}
error = NULL;
if ((pf = polkit_policy_file_new (valid_files[n], load_descriptions, &error)) == NULL) {
- g_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
+ kit_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
polkit_error_free (error);
} else {
polkit_policy_file_entry_foreach (pf,
_check_pf,
&num_passed);
- g_assert (num_passed == 2);
+ kit_assert (num_passed == 2);
}
polkit_policy_file_ref (pf);
#ifndef POLKIT_PRIVATE_H
#define POLKIT_PRIVATE_H
-#include <glib.h>
+#include <kit/kit.h>
#include <polkit/polkit.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-hash.h>
+#include <polkit/polkit-debug.h>
/**
* SECTION:polkit-private
PolKitResult defaults_allow_any,
PolKitResult defaults_allow_inactive,
PolKitResult defaults_allow_active,
- PolKitHash *annotations);
+ KitHash *annotations);
#ifdef POLKIT_AUTHDB_DUMMY
{
/*< private >*/
int refcount;
- GHashTable *uid_to_authlist;
+ KitHash *uid_to_authlist;
};
#endif
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-result.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
static const struct {
polkit_result_to_string_representation (PolKitResult result)
{
if (result < 0 || result >= POLKIT_RESULT_N_RESULTS) {
- g_warning ("The passed result code, %d, is not valid", result);
+ kit_warning ("The passed result code, %d, is not valid", result);
return NULL;
}
{
int n;
- g_return_val_if_fail (out_result != NULL, FALSE);
+ kit_return_val_if_fail (out_result != NULL, FALSE);
for (n = 0; n < POLKIT_RESULT_N_RESULTS; n++) {
if (strcmp (mapping[n].str, string) == 0) {
PolKitResult m;
for (n = 0; n < POLKIT_RESULT_N_RESULTS; n++) {
- g_assert (polkit_result_from_string_representation (polkit_result_to_string_representation (n), &m) && n== m);
+ kit_assert (polkit_result_from_string_representation (polkit_result_to_string_representation (n), &m) && n== m);
}
- g_assert (polkit_result_to_string_representation ((PolKitResult) -1) == NULL);
- g_assert (polkit_result_to_string_representation (POLKIT_RESULT_N_RESULTS) == NULL);
+ kit_assert (polkit_result_to_string_representation ((PolKitResult) -1) == NULL);
+ kit_assert (polkit_result_to_string_representation (POLKIT_RESULT_N_RESULTS) == NULL);
- g_assert (! polkit_result_from_string_representation ("non-exiting-result-id", &m));
+ kit_assert (! polkit_result_from_string_representation ("non-exiting-result-id", &m));
return TRUE;
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-seat.h"
#include "polkit-utils.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-seat
polkit_seat_new (void)
{
PolKitSeat *seat;
- seat = p_new0 (PolKitSeat, 1);
+ seat = kit_new0 (PolKitSeat, 1);
if (seat == NULL)
goto out;
seat->refcount = 1;
PolKitSeat *
polkit_seat_ref (PolKitSeat *seat)
{
- g_return_val_if_fail (seat != NULL, seat);
+ kit_return_val_if_fail (seat != NULL, seat);
seat->refcount++;
return seat;
}
void
polkit_seat_unref (PolKitSeat *seat)
{
- g_return_if_fail (seat != NULL);
+ kit_return_if_fail (seat != NULL);
seat->refcount--;
if (seat->refcount > 0)
return;
- p_free (seat->ck_objref);
- p_free (seat);
+ kit_free (seat->ck_objref);
+ kit_free (seat);
}
/**
polkit_bool_t
polkit_seat_set_ck_objref (PolKitSeat *seat, const char *ck_objref)
{
- g_return_val_if_fail (seat != NULL, FALSE);
- g_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
+ kit_return_val_if_fail (seat != NULL, FALSE);
+ kit_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
if (seat->ck_objref != NULL)
- p_free (seat->ck_objref);
- seat->ck_objref = p_strdup (ck_objref);
+ kit_free (seat->ck_objref);
+ seat->ck_objref = kit_strdup (ck_objref);
if (seat->ck_objref == NULL)
return FALSE;
else
polkit_bool_t
polkit_seat_get_ck_objref (PolKitSeat *seat, char **out_ck_objref)
{
- g_return_val_if_fail (seat != NULL, FALSE);
- g_return_val_if_fail (out_ck_objref != NULL, FALSE);
+ kit_return_val_if_fail (seat != NULL, FALSE);
+ kit_return_val_if_fail (out_ck_objref != NULL, FALSE);
*out_ck_objref = seat->ck_objref;
return TRUE;
}
void
polkit_seat_debug (PolKitSeat *seat)
{
- g_return_if_fail (seat != NULL);
+ kit_return_if_fail (seat != NULL);
_pk_debug ("PolKitSeat: refcount=%d objpath=%s", seat->refcount, seat->ck_objref);
}
polkit_bool_t
polkit_seat_validate (PolKitSeat *seat)
{
- g_return_val_if_fail (seat != NULL, FALSE);
- g_return_val_if_fail (seat->ck_objref != NULL, FALSE);
+ kit_return_val_if_fail (seat != NULL, FALSE);
+ kit_return_val_if_fail (seat->ck_objref != NULL, FALSE);
return TRUE;
}
if (! polkit_seat_set_ck_objref (s, "/someseat")) {
/* OOM */
} else {
- g_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat") == 0);
- g_assert (polkit_seat_validate (s));
+ kit_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat") == 0);
+ kit_assert (polkit_seat_validate (s));
polkit_seat_ref (s);
- g_assert (polkit_seat_validate (s));
+ kit_assert (polkit_seat_validate (s));
polkit_seat_unref (s);
- g_assert (polkit_seat_validate (s));
+ kit_assert (polkit_seat_validate (s));
polkit_seat_debug (s);
if (! polkit_seat_set_ck_objref (s, "/someseat2")) {
/* OOM */
} else {
- g_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat2") == 0);
+ kit_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat2") == 0);
}
}
polkit_seat_unref (s);
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include "polkit-debug.h"
#include "polkit-session.h"
#include "polkit-utils.h"
#include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-session
polkit_session_new (void)
{
PolKitSession *session;
- session = p_new0 (PolKitSession, 1);
+ session = kit_new0 (PolKitSession, 1);
if (session == NULL)
goto out;
session->refcount = 1;
PolKitSession *
polkit_session_ref (PolKitSession *session)
{
- g_return_val_if_fail (session != NULL, session);
+ kit_return_val_if_fail (session != NULL, session);
session->refcount++;
return session;
}
void
polkit_session_unref (PolKitSession *session)
{
- g_return_if_fail (session != NULL);
+ kit_return_if_fail (session != NULL);
session->refcount--;
if (session->refcount > 0)
return;
- p_free (session->ck_objref);
- p_free (session->remote_host);
+ kit_free (session->ck_objref);
+ kit_free (session->remote_host);
if (session->seat != NULL)
polkit_seat_unref (session->seat);
- p_free (session);
+ kit_free (session);
}
/**
polkit_bool_t
polkit_session_set_uid (PolKitSession *session, uid_t uid)
{
- g_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
session->uid = uid;
return TRUE;
}
polkit_bool_t
polkit_session_set_ck_objref (PolKitSession *session, const char *ck_objref)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
if (session->ck_objref != NULL)
- p_free (session->ck_objref);
- session->ck_objref = p_strdup (ck_objref);
+ kit_free (session->ck_objref);
+ session->ck_objref = kit_strdup (ck_objref);
if (session->ck_objref == NULL)
return FALSE;
else
polkit_bool_t
polkit_session_set_ck_is_active (PolKitSession *session, polkit_bool_t is_active)
{
- g_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
session->is_active = is_active;
return TRUE;
}
polkit_bool_t
polkit_session_set_ck_is_local (PolKitSession *session, polkit_bool_t is_local)
{
- g_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
session->is_local = is_local;
return TRUE;
}
polkit_bool_t
polkit_session_set_ck_remote_host (PolKitSession *session, const char *remote_host)
{
- g_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
/* TODO: FIXME: probably need to allow a lot more here */
- g_return_val_if_fail (_pk_validate_identifier (remote_host), FALSE);
+ kit_return_val_if_fail (_pk_validate_identifier (remote_host), FALSE);
if (session->remote_host != NULL)
- p_free (session->remote_host);
- session->remote_host = p_strdup (remote_host);
+ kit_free (session->remote_host);
+ session->remote_host = kit_strdup (remote_host);
if (session->remote_host == NULL)
return FALSE;
else
polkit_bool_t
polkit_session_set_seat (PolKitSession *session, PolKitSeat *seat)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (polkit_seat_validate (seat), FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (polkit_seat_validate (seat), FALSE);
if (session->seat != NULL)
polkit_seat_unref (session->seat);
session->seat = seat != NULL ? polkit_seat_ref (seat) : NULL;
polkit_bool_t
polkit_session_get_uid (PolKitSession *session, uid_t *out_uid)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_uid != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_uid != NULL, FALSE);
*out_uid = session->uid;
return TRUE;
}
polkit_bool_t
polkit_session_get_ck_objref (PolKitSession *session, char **out_ck_objref)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_ck_objref != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_ck_objref != NULL, FALSE);
*out_ck_objref = session->ck_objref;
return TRUE;
}
polkit_bool_t
polkit_session_get_ck_is_active (PolKitSession *session, polkit_bool_t *out_is_active)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_is_active != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_is_active != NULL, FALSE);
*out_is_active = session->is_active;
return TRUE;
}
polkit_bool_t
polkit_session_get_ck_is_local (PolKitSession *session, polkit_bool_t *out_is_local)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_is_local != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_is_local != NULL, FALSE);
*out_is_local = session->is_local;
return TRUE;
}
polkit_bool_t
polkit_session_get_ck_remote_host (PolKitSession *session, char **out_remote_host)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_remote_host != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_remote_host != NULL, FALSE);
*out_remote_host = session->remote_host;
return TRUE;
}
polkit_bool_t
polkit_session_get_seat (PolKitSession *session, PolKitSeat **out_seat)
{
- g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (out_seat != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (out_seat != NULL, FALSE);
*out_seat = session->seat;
return TRUE;
}
void
polkit_session_debug (PolKitSession *session)
{
- g_return_if_fail (session != NULL);
+ kit_return_if_fail (session != NULL);
_pk_debug ("PolKitSession: refcount=%d uid=%d objpath=%s is_active=%d is_local=%d remote_host=%s",
session->refcount, session->uid,
session->ck_objref, session->is_active, session->is_local, session->remote_host);
polkit_session_validate (PolKitSession *session)
{
polkit_bool_t ret;
- g_return_val_if_fail (session != NULL, FALSE);
+ kit_return_val_if_fail (session != NULL, FALSE);
ret = FALSE;
if (session->is_local) {
if (! polkit_session_set_ck_objref (s, "/somesession")) {
/* OOM */
} else {
- g_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession") == 0);
+ kit_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession") == 0);
polkit_session_ref (s);
polkit_session_unref (s);
polkit_session_debug (s);
if (! polkit_session_set_ck_objref (s, "/somesession2")) {
/* OOM */
} else {
- g_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession2") == 0);
+ kit_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession2") == 0);
}
if ((seat = polkit_seat_new ()) != NULL) {
if (polkit_seat_set_ck_objref (seat, "/someseat")) {
- g_assert (polkit_session_set_seat (s, seat));
- g_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
+ kit_assert (polkit_session_set_seat (s, seat));
+ kit_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
}
polkit_seat_unref (seat);
if ((seat = polkit_seat_new ()) != NULL) {
if (polkit_seat_set_ck_objref (seat, "/someseat2")) {
- g_assert (polkit_session_set_seat (s, seat));
- g_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
+ kit_assert (polkit_session_set_seat (s, seat));
+ kit_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
}
polkit_seat_unref (seat);
}
}
- g_assert (polkit_session_set_uid (s, 0));
- g_assert (polkit_session_get_uid (s, &uid) && uid == 0);
- g_assert (polkit_session_set_ck_is_active (s, TRUE));
- g_assert (polkit_session_get_ck_is_active (s, &b) && b == TRUE);
- g_assert (polkit_session_set_ck_is_local (s, TRUE));
- g_assert (polkit_session_get_ck_is_local (s, &b) && b == TRUE);
- g_assert (polkit_session_validate (s));
-
- g_assert (polkit_session_set_uid (s, 500));
- g_assert (polkit_session_get_uid (s, &uid) && uid == 500);
- g_assert (polkit_session_set_ck_is_active (s, FALSE));
- g_assert (polkit_session_get_ck_is_active (s, &b) && b == FALSE);
- g_assert (polkit_session_set_ck_is_local (s, FALSE));
- g_assert (polkit_session_get_ck_is_local (s, &b) && b == FALSE);
+ kit_assert (polkit_session_set_uid (s, 0));
+ kit_assert (polkit_session_get_uid (s, &uid) && uid == 0);
+ kit_assert (polkit_session_set_ck_is_active (s, TRUE));
+ kit_assert (polkit_session_get_ck_is_active (s, &b) && b == TRUE);
+ kit_assert (polkit_session_set_ck_is_local (s, TRUE));
+ kit_assert (polkit_session_get_ck_is_local (s, &b) && b == TRUE);
+ kit_assert (polkit_session_validate (s));
+
+ kit_assert (polkit_session_set_uid (s, 500));
+ kit_assert (polkit_session_get_uid (s, &uid) && uid == 500);
+ kit_assert (polkit_session_set_ck_is_active (s, FALSE));
+ kit_assert (polkit_session_get_ck_is_active (s, &b) && b == FALSE);
+ kit_assert (polkit_session_set_ck_is_local (s, FALSE));
+ kit_assert (polkit_session_get_ck_is_local (s, &b) && b == FALSE);
/* not valid because remote host is not set.. */
- g_assert (!polkit_session_validate (s));
+ kit_assert (!polkit_session_validate (s));
if (polkit_session_set_ck_remote_host (s, "somehost.com")) {
- g_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost.com") == 0);
- g_assert (polkit_session_validate (s));
+ kit_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost.com") == 0);
+ kit_assert (polkit_session_validate (s));
/* not valid because remote host is set and local==TRUE */
- g_assert (polkit_session_set_ck_is_local (s, TRUE));
- g_assert (!polkit_session_validate (s));
- g_assert (polkit_session_set_ck_is_local (s, FALSE));
+ kit_assert (polkit_session_set_ck_is_local (s, TRUE));
+ kit_assert (!polkit_session_validate (s));
+ kit_assert (polkit_session_set_ck_is_local (s, FALSE));
if (polkit_session_set_ck_remote_host (s, "somehost2.com")) {
- g_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost2.com") == 0);
- g_assert (polkit_session_validate (s));
+ kit_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost2.com") == 0);
+ kit_assert (polkit_session_validate (s));
}
polkit_session_debug (s);
}
#include <syslog.h>
#include <glib.h>
+
#include "polkit-sysdeps.h"
+#include "polkit-private.h"
/**
{
char *filename;
char *contents;
- gsize length;
+ size_t length;
polkit_uint64_t start_time;
- GError *error = NULL;
char **tokens;
char *p;
char *endp;
start_time = 0;
contents = NULL;
- filename = g_strdup_printf ("/proc/%d/stat", pid);
+ filename = kit_strdup_printf ("/proc/%d/stat", pid);
if (filename == NULL) {
- fprintf (stderr, "Out of memory\n");
+ kit_warning ("Out of memory");
goto out;
}
- if (!g_file_get_contents (filename, &contents, &length, &error)) {
+ if (!kit_file_get_contents (filename, &contents, &length)) {
//fprintf (stderr, "Cannot get contents of '%s': %s\n", filename, error->message);
- g_error_free (error);
goto out;
}
g_strfreev (tokens);
out:
- g_free (filename);
- g_free (contents);
+ kit_free (filename);
+ kit_free (contents);
return start_time;
}
if (ret == -1) {
goto out;
}
- g_assert (ret >= 0 && ret < (int) buf_size - 1);
+ kit_assert (ret >= 0 && ret < (int) buf_size - 1);
out_buf[ret] = '\0';
out:
#include <stdio.h>
#include <stdlib.h>
#include <polkit/polkit-test.h>
-#include <polkit/polkit-memory.h>
+#include <polkit/polkit-private.h>
#include <polkit/polkit-private.h>
#define MAX_TESTS 64
*/
static PolKitTest *tests[] = {
- &_test_list,
- &_test_hash,
&_test_action,
&_test_error,
&_test_result,
&_test_policy_cache,
&_test_authorization_constraint,
&_test_authorization,
+ &_test_authorization_db,
};
int
int delta;
PolKitTest *test = tests[n];
- _polkit_memory_reset ();
+ _kit_memory_reset ();
if (test->setup != NULL)
test->setup ();
goto test_done;
}
- total_allocs = _polkit_memory_get_total_allocations ();
+ total_allocs = _kit_memory_get_total_allocations ();
printf (" Unit test made %d allocations in total\n", total_allocs);
- delta = _polkit_memory_get_current_allocations ();
+ delta = _kit_memory_get_current_allocations ();
if (delta != 0) {
printf (" Unit test leaked %d allocations\n", delta);
ret = 1;
for (m = 0; m < total_allocs; m++) {
printf (" Failing allocation %d of %d\n", m + 1, total_allocs);
- _polkit_memory_reset ();
- _polkit_memory_fail_nth_alloc (m);
+ _kit_memory_reset ();
+ _kit_memory_fail_nth_alloc (m);
if (!test->run ()) {
printf (" Failed\n");
continue;
}
- delta = _polkit_memory_get_current_allocations ();
+ delta = _kit_memory_get_current_allocations ();
if (delta != 0) {
printf (" Unit test leaked %d allocations\n", delta);
ret = 1;
extern PolKitTest _test_caller;
extern PolKitTest _test_policy_default;
extern PolKitTest _test_policy_file_entry;
-extern PolKitTest _test_hash;
extern PolKitTest _test_policy_file;
-extern PolKitTest _test_list;
extern PolKitTest _test_policy_cache;
extern PolKitTest _test_authorization_constraint;
extern PolKitTest _test_authorization;
+extern PolKitTest _test_authorization_db;
POLKIT_END_DECLS
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
-#include <glib.h>
#include <string.h>
#include "polkit-utils.h"
#include "polkit-debug.h"
+#include "polkit-private.h"
/**
* SECTION:polkit-utils
unsigned int n;
polkit_bool_t ret;
- g_return_val_if_fail (identifier != NULL, FALSE);
+ kit_return_val_if_fail (identifier != NULL, FALSE);
ret = FALSE;
for (n = 0; identifier[n] != '\0'; n++) {
++s;
while (s != end) {
if (*s == '.') {
- if (G_UNLIKELY ((s + 1) == end))
+ if ((s + 1) == end)
goto error;
- if (G_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*(s + 1))))
+ if (!VALID_BUS_NAME_CHARACTER (*(s + 1)))
goto error;
++s; /* we just validated the next char, so skip two */
- } else if (G_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s))) {
+ } else if (!VALID_BUS_NAME_CHARACTER (*s)) {
goto error;
}
++s;
#define _POLKIT_INSIDE_POLKIT_H 1
#include <polkit/polkit-types.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-hash.h>
#include <polkit/polkit-sysdeps.h>
#include <polkit/polkit-error.h>
#include <polkit/polkit-result.h>