diff options
author | Max Kellermann <max@duempel.org> | 2013-01-03 03:06:35 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-03 03:11:39 +0100 |
commit | c4090b670d4a1fdb2b5d18e30764d50827838ee1 (patch) | |
tree | 2a7e3f24a8c8aa8b5e78d38007c084114342c834 /src | |
parent | ddf112378b7e9abef79fde13828ba904723c1ffd (diff) | |
download | mpd-c4090b670d4a1fdb2b5d18e30764d50827838ee1.tar.gz mpd-c4090b670d4a1fdb2b5d18e30764d50827838ee1.tar.xz mpd-c4090b670d4a1fdb2b5d18e30764d50827838ee1.zip |
Permission: use std::map instead of GHashTable
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.cxx | 1 | ||||
-rw-r--r-- | src/Permission.cxx | 28 | ||||
-rw-r--r-- | src/Permission.hxx | 2 |
3 files changed, 9 insertions, 22 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index 4dc606a30..fa21ddbd9 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -538,7 +538,6 @@ int mpd_main(int argc, char *argv[]) volume_finish(); mapper_finish(); path_global_finish(); - finishPermissions(); pc_free(global_player_control); command_finish(); update_global_finish(); diff --git a/src/Permission.cxx b/src/Permission.cxx index e455f7ee7..0b76e3364 100644 --- a/src/Permission.cxx +++ b/src/Permission.cxx @@ -25,6 +25,9 @@ extern "C" { #include "conf.h" } +#include <map> +#include <string> + #include <glib.h> #include <stdbool.h> @@ -38,7 +41,7 @@ extern "C" { #define PERMISSION_CONTROL_STRING "control" #define PERMISSION_ADMIN_STRING "admin" -static GHashTable *permission_passwords; +static std::map<std::string, unsigned> permission_passwords; static unsigned permission_default; @@ -78,9 +81,6 @@ void initPermissions(void) unsigned permission; const struct config_param *param; - 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; @@ -104,9 +104,8 @@ void initPermissions(void) permission = parsePermissions(separator + 1); - g_hash_table_replace(permission_passwords, - password, - GINT_TO_POINTER(permission)); + permission_passwords.insert(std::make_pair(password, + permission)); } while ((param = config_get_next_param(CONF_PASSWORD, param))); } @@ -118,23 +117,14 @@ void initPermissions(void) int getPermissionFromPassword(char const* password, unsigned* permission) { - bool found; - gpointer key, value; - - found = g_hash_table_lookup_extended(permission_passwords, - password, &key, &value); - if (!found) + auto i = permission_passwords.find(password); + if (i == permission_passwords.end()) return -1; - *permission = GPOINTER_TO_INT(value); + *permission = i->second; return 0; } -void finishPermissions(void) -{ - g_hash_table_destroy(permission_passwords); -} - unsigned getDefaultPermissions(void) { return permission_default; diff --git a/src/Permission.hxx b/src/Permission.hxx index de8558494..4ff3850e0 100644 --- a/src/Permission.hxx +++ b/src/Permission.hxx @@ -29,8 +29,6 @@ int getPermissionFromPassword(char const* password, unsigned* permission); -void finishPermissions(void); - unsigned getDefaultPermissions(void); void initPermissions(void); |