Change ARI user config to use a type field
authorDavid M. Lee <dlee@digium.com>
Thu, 11 Jul 2013 14:39:55 +0000 (14:39 +0000)
committerDavid M. Lee <dlee@digium.com>
Thu, 11 Jul 2013 14:39:55 +0000 (14:39 +0000)
When I initially wrote the configuration support for ARI users, I
determined the section type by a category prefix (i.e., [user-admin]).

This is neither idiomatic Asterisk configuration, nor is it really
that user friendly. This patch replaces the category prefix with a
type field in the section, which is much cleaner.

Review: https://reviewboard.asterisk.org/r/2664/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394076 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configs/ari.conf.sample
res/res_stasis_http.c
res/stasis_http/config.c

index 11e2b06..414f89d 100644 (file)
@@ -8,7 +8,8 @@ enabled = yes           ; When set to no, stasis-http support is disabled.
 ;auth_realm =          ; Realm to use for authentication. Defaults to Asterisk
 ;                      ; REST Interface.
 
-;[user-username]
+;[username]
+;type = user           ; Specifies user configuration
 ;read_only = no                ; When set to yes, user is only authorized for
 ;                      ; read-only requests.
 ;
index f76752d..7cd92f4 100644 (file)
 
                        <configObject name="user">
                                <synopsis>Per-user configuration settings</synopsis>
+                               <configOption name="type">
+                                       <synopsis>Define this configuration section as a user.</synopsis>
+                                       <description>
+                                               <enumlist>
+                                                       <enum name="user"><para>Configure this section as a <replaceable>user</replaceable></para></enum>
+                                               </enumlist>
+                                       </description>
+                               </configOption>
                                <configOption name="read_only">
                                        <synopsis>When set to yes, user is only authorized for read-only requests</synopsis>
                                </configOption>
index 09db01e..2181907 100644 (file)
@@ -89,19 +89,11 @@ static void user_dtor(void *obj)
 static void *user_alloc(const char *cat)
 {
        RAII_VAR(struct ari_conf_user *, user, NULL, ao2_cleanup);
-       const char *username;
 
        if (!cat) {
                return NULL;
        }
 
-       username = strchr(cat, '-') + 1;
-
-       if (!username) {
-               ast_log(LOG_ERROR, "Invalid user category '%s'\n", cat);
-               return NULL;
-       }
-
        ast_debug(3, "Allocating user %s\n", cat);
 
        user = ao2_alloc_options(sizeof(*user), user_dtor,
@@ -110,7 +102,7 @@ static void *user_alloc(const char *cat)
                return NULL;
        }
 
-       user->username = ast_strdup(username);
+       user->username = ast_strdup(cat);
        if (!user->username) {
                return NULL;
        }
@@ -141,21 +133,20 @@ static int user_sort_cmp(const void *obj_left, const void *obj_right, int flags)
 /*! \brief \ref aco_type item_find function */
 static void *user_find(struct ao2_container *tmp_container, const char *cat)
 {
-       const char *username;
-
        if (!cat) {
                return NULL;
        }
 
-       username = strchr(cat, '-') + 1;
-       return ao2_find(tmp_container, username, OBJ_KEY);
+       return ao2_find(tmp_container, cat, OBJ_KEY);
 }
 
 static struct aco_type user_option = {
        .type = ACO_ITEM,
        .name = "user",
-       .category_match = ACO_WHITELIST,
-       .category = "^user-.+$",
+       .category_match = ACO_BLACKLIST,
+       .category = "^general$",
+       .matchfield = "type",
+       .matchvalue = "user",
        .item_alloc = user_alloc,
        .item_find = user_find,
        .item_offset = offsetof(struct ari_conf, users),
@@ -318,6 +309,8 @@ int ari_config_init(void)
                FLDSET(struct ari_conf_general, auth_realm),
                ARI_AUTH_REALM_LEN);
 
+       aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL,
+               OPT_NOOP_T, 0, 0);
        aco_option_register(&cfg_info, "read_only", ACO_EXACT, user,
                "no", OPT_BOOL_T, 1,
                FLDSET(struct ari_conf_user, read_only));