aboutsummaryrefslogtreecommitdiffstats
path: root/src/permission.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-01 14:33:25 +0100
committerMax Kellermann <max@duempel.org>2008-11-01 14:33:25 +0100
commit83f6222ae74e6601383cf934a1bbf176656bf5c5 (patch)
tree4bf9228d13c5f0fa17d14ba24a313fa04846f83d /src/permission.c
parentaa772ebc02031a6044cfe1bbd35833527bc2b285 (diff)
downloadmpd-83f6222ae74e6601383cf934a1bbf176656bf5c5.tar.gz
mpd-83f6222ae74e6601383cf934a1bbf176656bf5c5.tar.xz
mpd-83f6222ae74e6601383cf934a1bbf176656bf5c5.zip
permission: store passwords in GHashTable
Eliminating the deprecated linked list library.
Diffstat (limited to 'src/permission.c')
-rw-r--r--src/permission.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/permission.c b/src/permission.c
index 193d21f8a..15e2382b5 100644
--- a/src/permission.c
+++ b/src/permission.c
@@ -19,11 +19,13 @@
#include "permission.h"
#include "conf.h"
-#include "list.h"
#include "log.h"
#include "utils.h"
#include "os_compat.h"
+#include <glib.h>
+#include <stdbool.h>
+
#define PERMISSION_PASSWORD_CHAR "@"
#define PERMISSION_SEPERATOR ","
@@ -32,7 +34,7 @@
#define PERMISSION_CONTROL_STRING "control"
#define PERMISSION_ADMIN_STRING "admin"
-static List *permission_passwords;
+static GHashTable *permission_passwords;
static unsigned permission_default;
@@ -70,10 +72,11 @@ void initPermissions(void)
char *temp;
char *cp2;
char *password;
- unsigned *permission;
+ unsigned permission;
ConfigParam *param;
- permission_passwords = makeList(free, 1);
+ permission_passwords = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
permission_default = PERMISSION_READ | PERMISSION_ADD |
PERMISSION_CONTROL | PERMISSION_ADMIN;
@@ -99,12 +102,12 @@ void initPermissions(void)
password = temp;
- permission = xmalloc(sizeof(unsigned));
- *permission =
+ permission =
parsePermissions(strtok_r(NULL, "", &cp2));
- insertInList(permission_passwords, password,
- permission);
+ g_hash_table_replace(permission_passwords,
+ g_strdup(password),
+ GINT_TO_POINTER(permission));
} while ((param = getNextConfigParam(CONF_PASSWORD, param)));
}
@@ -112,25 +115,25 @@ void initPermissions(void)
if (param)
permission_default = parsePermissions(param->value);
-
- sortList(permission_passwords);
}
int getPermissionFromPassword(char *password, unsigned *permission)
{
- void *foundPermission;
+ bool found;
+ gpointer key, value;
- if (findInList(permission_passwords, password, &foundPermission)) {
- *permission = *((unsigned *)foundPermission);
- return 0;
- }
+ found = g_hash_table_lookup_extended(permission_passwords,
+ password, &key, &value);
+ if (!found)
+ return -1;
- return -1;
+ *permission = GPOINTER_TO_INT(value);
+ return 0;
}
void finishPermissions(void)
{
- freeList(permission_passwords);
+ g_hash_table_destroy(permission_passwords);
}
unsigned getDefaultPermissions(void)