]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-sql: Added support for value_type field, which deprecates value_hexblob.
authorTimo Sirainen <tss@iki.fi>
Tue, 13 Oct 2015 17:40:38 +0000 (20:40 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 13 Oct 2015 17:40:38 +0000 (20:40 +0300)
value_type=string|hexblob|uint are supported now.

src/lib-dict/dict-sql-settings.c
src/lib-dict/dict-sql-settings.h
src/lib-dict/dict-sql.c

index f0d871865c5d27e55f6c63f8e4c454532e293313..81da9a9314b7416f1f86aab691c8db9ae912d71b 100644 (file)
@@ -36,6 +36,7 @@ static const struct setting_def dict_sql_map_setting_defs[] = {
        DEF_STR(table),
        DEF_STR(username_field),
        DEF_STR(value_field),
+       DEF_STR(value_type),
        DEF_BOOL(value_hexblob),
 
        { 0, NULL, 0 }
@@ -129,6 +130,12 @@ static const char *dict_sql_map_finish(struct setting_parser_ctx *ctx)
                return "Missing setting: table";
        if (ctx->cur_map.value_field == NULL)
                return "Missing setting: value_field";
+       if (ctx->cur_map.value_type != NULL) {
+               if (strcmp(ctx->cur_map.value_type, "string") != 0 &&
+                   strcmp(ctx->cur_map.value_type, "hexblob") != 0 &&
+                   strcmp(ctx->cur_map.value_type, "uint") != 0)
+                       return "Invalid value in value_type";
+       }
 
        if (ctx->cur_map.username_field == NULL) {
                /* not all queries require this */
index c5d0f341a8fa18ac20cd9d820452e45c35904416..62aff2ec17f55dce8adf94776959ddd0d315f3f3 100644 (file)
@@ -19,6 +19,7 @@ struct dict_sql_map {
        const char *table;
        const char *username_field;
        const char *value_field;
+       const char *value_type;
        bool value_hexblob;
 
        ARRAY(struct dict_sql_field) sql_fields;
index d1f2d6b92f440259080db1dcd86f33eb407bec91..1257562d110e4b8586670b73304bdb44bebe1a33 100644 (file)
@@ -380,13 +380,26 @@ sql_dict_result_unescape(enum dict_sql_type type, pool_t pool,
        return str_c(str);
 }
 
+static enum dict_sql_type 
+sql_dict_map_type(const struct dict_sql_map *map)
+{
+       if (map->value_type != NULL) {
+               if (strcmp(map->value_type, "string") == 0)
+                       return DICT_SQL_TYPE_STRING;
+               if (strcmp(map->value_type, "hexblob") == 0)
+                       return DICT_SQL_TYPE_HEXBLOB;
+               if (strcmp(map->value_type, "uint") == 0)
+                       return DICT_SQL_TYPE_UINT;
+               i_unreached(); /* should have checked already at parsing */
+       }
+       return map->value_hexblob ? DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING;
+}
+
 static const char *
 sql_dict_result_unescape_value(const struct dict_sql_map *map, pool_t pool,
                               struct sql_result *result)
 {
-       enum dict_sql_type value_type = map->value_hexblob ?
-               DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING;
-       return sql_dict_result_unescape(value_type, pool, result, 0);
+       return sql_dict_result_unescape(sql_dict_map_type(map), pool, result, 0);
 }
 
 static const char *
@@ -876,8 +889,8 @@ static int sql_dict_set_query(const struct dict_sql_build_query *build,
                if (build->inc)
                        str_append(suffix, fields[i].value);
                else {
-                       enum dict_sql_type value_type = fields[i].map->value_hexblob ?
-                               DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING;
+                       enum dict_sql_type value_type =
+                               sql_dict_map_type(fields[i].map);
                        if (sql_dict_value_escape(suffix, dict, value_type,
                                "value", fields[i].value, "", error_r) < 0)
                                return -1;
@@ -919,8 +932,8 @@ static int sql_dict_set_query(const struct dict_sql_build_query *build,
                                    fields[i].map->value_field,
                                    fields[i].value);
                } else {
-                       enum dict_sql_type value_type = fields[i].map->value_hexblob ?
-                               DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING;
+                       enum dict_sql_type value_type =
+                               sql_dict_map_type(fields[i].map);
                        if (sql_dict_value_escape(prefix, dict, value_type,
                                "value", fields[i].value, "", error_r) < 0)
                                return -1;