]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: oauth2-jwt - Split off get_field_node()
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 11 Nov 2023 03:19:10 +0000 (04:19 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Sat, 18 Nov 2023 18:58:04 +0000 (18:58 +0000)
src/lib-oauth2/oauth2-jwt.c

index b1bbda77454177dc9814fafbe6b02ff37d3ee686..67d9f3099b5dfb048451dd754cc8cd80e4f6bf00 100644 (file)
@@ -21,9 +21,8 @@
 
 #include <time.h>
 
-static const char *
-get_field(const struct json_tree *tree, const char *key,
-         enum json_type *type_r)
+static const struct json_tree_node *
+get_field_node(const struct json_tree *tree, const char *key)
 {
        const struct json_tree_node *root = json_tree_root(tree);
        const struct json_tree_node *value_node = json_tree_find_key(root, key);
@@ -31,6 +30,18 @@ get_field(const struct json_tree *tree, const char *key,
        if (value_node == NULL || value_node->value_type == JSON_TYPE_OBJECT ||
            value_node->value_type == JSON_TYPE_ARRAY)
                return NULL;
+
+       return value_node;
+}
+
+static const char *
+get_field(const struct json_tree *tree, const char *key,
+         enum json_type *type_r)
+{
+       const struct json_tree_node *value_node = get_field_node(tree, key);
+
+       if (value_node == NULL)
+               return NULL;
        if (type_r != NULL)
                *type_r = value_node->value_type;
        return json_tree_get_value_str(value_node);