Sun, 17 Jul 2016 10:40:15 +0200
implemented string functionality for some davql operators
libidav/davqlexec.c | file | annotate | diff | comparison | revisions |
--- a/libidav/davqlexec.c Wed Jul 13 17:10:00 2016 +0200 +++ b/libidav/davqlexec.c Sun Jul 17 10:40:15 2016 +0200 @@ -29,6 +29,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <inttypes.h> #include <ucx/utils.h> #include <ucx/map.h> @@ -885,6 +886,52 @@ return bcode; } +static int cmd_str_cmp(DavQLStackObj obj1, DavQLStackObj obj2, davqlcmdtype_t cmd) { + sstr_t s1 = obj1.type == 1 ? + sstrn(obj1.data.string, obj1.length) : + ucx_sprintf("%" PRId64, obj1.data.integer); + sstr_t s2 = obj1.type == 1 ? + sstrn(obj2.data.string, obj2.length) : + ucx_sprintf("%" PRId64, obj2.data.integer); + + int res = 0; + switch(cmd) { + case DAVQL_CMD_OP_EQ: { + res = sstrcmp(s1, s2) == 0; + break; + } + case DAVQL_CMD_OP_NEQ: { + res = sstrcmp(s1, s2) != 0; + break; + } + case DAVQL_CMD_OP_LT: { + res = sstrcmp(s1, s2) < 0; + break; + } + case DAVQL_CMD_OP_GT: { + res = sstrcmp(s1, s2) > 0; + break; + } + case DAVQL_CMD_OP_LE: { + res = sstrcmp(s1, s2) <= 0; + break; + } + case DAVQL_CMD_OP_GE: { + res = sstrcmp(s1, s2) >= 0; + break; + } + } + + if(obj1.type == 0) { + free(s1.ptr); + } + if(obj2.type == 0) { + free(s2.ptr); + } + + return res; +} + int dav_exec_expr(UcxBuffer *bcode, DavResource *res, DavQLStackObj *result) { if(!bcode) { result->type = 0; @@ -1175,7 +1222,7 @@ if(obj1.type == 0 && obj2.type == 0) { DAVQL_PUSH_INT(obj1.data.integer == obj2.data.integer); } else { - // TODO: string compare + DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type)); } break; } @@ -1186,7 +1233,7 @@ if(obj1.type == 0 && obj2.type == 0) { DAVQL_PUSH_INT(obj1.data.integer != obj2.data.integer); } else { - // TODO: string compare + DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type)); } break; } @@ -1197,7 +1244,7 @@ if(obj1.type == 0 && obj2.type == 0) { DAVQL_PUSH_INT(obj1.data.integer < obj2.data.integer); } else { - // TODO: string compare + DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type)); } break; } @@ -1208,7 +1255,7 @@ if(obj1.type == 0 && obj2.type == 0) { DAVQL_PUSH_INT(obj1.data.integer > obj2.data.integer); } else { - // TODO: string compare + DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type)); } break; } @@ -1219,7 +1266,7 @@ if(obj1.type == 0 && obj2.type == 0) { DAVQL_PUSH_INT(obj1.data.integer <= obj2.data.integer); } else { - // TODO: string compare + DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type)); } break; } @@ -1230,7 +1277,7 @@ if(obj1.type == 0 && obj2.type == 0) { DAVQL_PUSH_INT(obj1.data.integer >= obj2.data.integer); } else { - // TODO: string compare + DAVQL_PUSH_INT(cmd_str_cmp(obj1, obj2, cmd.type)); } break; }