~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/auth/db-dict.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "auth-common.h"
4
4
 
5
5
#include "settings.h"
6
6
#include "dict.h"
7
7
#include "json-parser.h"
 
8
#include "istream.h"
8
9
#include "str.h"
9
10
#include "auth-request.h"
10
11
#include "auth-worker-client.h"
62
63
struct dict_connection *db_dict_init(const char *config_path)
63
64
{
64
65
        struct dict_connection *conn;
 
66
        const char *error;
65
67
        pool_t pool;
66
68
 
67
69
        conn = dict_conn_find(config_path);
81
83
 
82
84
        conn->config_path = p_strdup(pool, config_path);
83
85
        conn->set = default_dict_settings;
84
 
        if (!settings_read(config_path, NULL, parse_setting,
85
 
                           null_settings_section_callback, conn))
86
 
                exit(FATAL_DEFAULT);
 
86
        if (!settings_read_nosection(config_path, parse_setting, conn, &error))
 
87
                i_fatal("dict %s: %s", config_path, error);
87
88
 
88
89
        if (conn->set.uri == NULL)
89
90
                i_fatal("dict %s: Empty uri setting", config_path);
91
92
                i_fatal("dict %s: Unsupported value_format %s in ",
92
93
                        config_path, conn->set.value_format);
93
94
        }
94
 
        conn->dict = dict_init(conn->set.uri, DICT_DATA_TYPE_STRING, "",
95
 
                               global_auth_settings->base_dir);
 
95
        if (dict_init(conn->set.uri, DICT_DATA_TYPE_STRING, "",
 
96
                      global_auth_settings->base_dir, &conn->dict, &error) < 0)
 
97
                i_fatal("dict %s: Failed to init dict: %s", config_path, error);
96
98
 
97
99
        conn->next = connections;
98
100
        connections = conn;
121
123
db_dict_value_iter_init(struct dict_connection *conn, const char *value)
122
124
{
123
125
        struct db_dict_value_iter *iter;
 
126
        struct istream *input;
124
127
 
125
128
        i_assert(strcmp(conn->set.value_format, "json") == 0);
126
129
 
128
131
           value types are supported. */
129
132
        iter = i_new(struct db_dict_value_iter, 1);
130
133
        iter->key = str_new(default_pool, 64);
131
 
        iter->parser = json_parser_init((const void *)value, strlen(value));
 
134
        input = i_stream_create_from_data(value, strlen(value));
 
135
        iter->parser = json_parser_init(input);
 
136
        i_stream_unref(&input);
132
137
        return iter;
133
138
}
134
139
 
138
143
        enum json_type type;
139
144
        const char *value;
140
145
 
141
 
        if (!json_parse_next(iter->parser, &type, &value))
 
146
        if (json_parse_next(iter->parser, &type, &value) < 0)
142
147
                return FALSE;
143
148
        if (type != JSON_TYPE_OBJECT_KEY) {
144
149
                iter->error = "Object expected";
151
156
        str_truncate(iter->key, 0);
152
157
        str_append(iter->key, value);
153
158
 
154
 
        if (!json_parse_next(iter->parser, &type, &value)) {
 
159
        if (json_parse_next(iter->parser, &type, &value) < 0) {
155
160
                iter->error = "Missing value";
156
161
                return FALSE;
157
162
        }
 
163
        if (type == JSON_TYPE_OBJECT) {
 
164
                iter->error = "Nested objects not supported";
 
165
                return FALSE;
 
166
        }
158
167
        *key_r = str_c(iter->key);
159
168
        *value_r = value;
160
169
        return TRUE;