Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce CBOR format support for REST payloads #169

Merged
merged 7 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,33 @@ add_custom_target(curlclean
WORKING_DIRECTORY "${LIBCURL_PATH_SRC}/winbuild"
)

#
# add tinycbor to the project
#
set(TINYCBOR_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/tinycbor CACHE PATH
"Lib tinycbor source path")
aux_source_directory(${TINYCBOR_PATH_SRC}/src DRV_SRC)
list(FILTER DRV_SRC EXCLUDE REGEX .*open_memstream.c$) # Win-unsupported
list(FILTER DRV_SRC EXCLUDE REGEX .*cborparser.c$) # to be patched
file(COPY ${TINYCBOR_PATH_SRC}/src/cborparser.c DESTINATION ${CMAKE_BINARY_DIR})
# tinycbor doesn't expose (yet? #125) the text/binary string pointer, since the
# string can span multiple stream chunks. However, in our case the CBOR object
# is available entirely, so access to it can safely be had; this saves a
# superfluous allocation/copy. FIXME -- lib PR, proper exposure.
file(APPEND ${CMAKE_BINARY_DIR}/cborparser.c
"
CborError cbor_value_get_string_chunk(CborValue *it,
const void **bufferptr, size_t *len)
{
CborError err = get_string_chunk(it, bufferptr, len);
return err != CborNoError ? err : preparse_next_value(it);
}")
aux_source_directory(${CMAKE_BINARY_DIR} DRV_SRC)
set(TINYCBOR_INC ${TINYCBOR_PATH_SRC}/src)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DWITHOUT_OPEN_MEMSTREAM")
# limit how deep the parser will recurse (current need: 3)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DCBOR_PARSER_MAX_RECURSIONS=16")

#
# Patch installer's and editor's AssemblyInfos with the version being built
#
Expand Down Expand Up @@ -339,7 +366,8 @@ add_library(${DRV_NAME} SHARED ${DRV_SRC} ${CMAKE_BINARY_DIR}/${DRV_NAME}.def
target_compile_definitions(${DRV_NAME} PRIVATE "DRIVER_BUILD")
add_dependencies(${DRV_NAME} dsneditor)
include_directories(${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC_PATH}
${UJSON4C_INC} ${CTIMESTAMP_PATH_SRC} ${DSNEDITOR_INC_PATH})
${UJSON4C_INC} ${CTIMESTAMP_PATH_SRC} ${TINYCBOR_INC}
${DSNEDITOR_INC_PATH})
target_link_libraries(${DRV_NAME} odbccp32 legacy_stdio_definitions
${DSNBND_LIB_BIN_DIR_BASE}-$<CONFIG>/esdsnbnd${BARCH}${CMAKE_IMPORT_LIBRARY_SUFFIX}
libcurl ${LIBCURL_WIN_LIBS})
Expand Down
2 changes: 2 additions & 0 deletions devtools/3rd_party/licenses/tinycbor-INFO.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,version,revision,url,license,copyright
tinycbor,,d2dd95c,https://github.com/intel/tinycbor.git,MIT,Copyright (c) 2017 Intel Corporation
21 changes: 21 additions & 0 deletions devtools/3rd_party/licenses/tinycbor-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Intel Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file.
26 changes: 13 additions & 13 deletions driver/catalogue.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
" CATALOG " ESODBC_STRING_DELIM WPFWP_LDESC ESODBC_STRING_DELIM


static SQLRETURN fake_answer(SQLHSTMT hstmt, const char *src, size_t cnt)
static SQLRETURN fake_answer(SQLHSTMT hstmt, cstr_st *answer)
{
char *dup;
cstr_st fake = *answer;

if (! (dup = strdup(src))) {
ERRNH(hstmt, "OOM with %zu.", cnt);
if (! (fake.str = strdup(answer->str))) {
ERRNH(hstmt, "OOM with %zu.", fake.cnt);
RET_HDIAGS(hstmt, SQL_STATE_HY001);
}
return attach_answer(STMH(hstmt), dup, cnt);
return attach_answer(STMH(hstmt), &fake, /*is JSON*/TRUE);

}

Expand Down Expand Up @@ -86,10 +86,10 @@ SQLRETURN EsSQLStatisticsW(
"\"rows\":[]" \
"}"
/*INDENT-ON*/
cstr_st statistics = CSTR_INIT(STATISTICS_EMPTY);

INFOH(hstmt, "no statistics available.");
return fake_answer(hstmt, STATISTICS_EMPTY,
sizeof(STATISTICS_EMPTY) - /*\0*/1);
return fake_answer(hstmt, &statistics);

# undef STATISTICS_EMPTY
}
Expand Down Expand Up @@ -614,11 +614,11 @@ SQLRETURN EsSQLSpecialColumnsW
"\"rows\":[]" \
"}"
/*INDENT-ON*/
cstr_st special_cols = CSTR_INIT(SPECIAL_COLUMNS_EMPTY);


INFOH(hstmt, "no special columns available.");
return fake_answer(hstmt, SPECIAL_COLUMNS_EMPTY,
sizeof(SPECIAL_COLUMNS_EMPTY) - /*\0*/1);
return fake_answer(hstmt, &special_cols);

# undef SPECIAL_COLUMNS_EMPTY
}
Expand Down Expand Up @@ -661,10 +661,10 @@ SQLRETURN EsSQLForeignKeysW(
"\"rows\":[]" \
"}"
/*INDENT-ON*/
cstr_st foreign_keys = CSTR_INIT(FOREIGN_KEYS_EMPTY);

INFOH(hstmt, "no foreign keys supported.");
return fake_answer(hstmt, FOREIGN_KEYS_EMPTY,
sizeof(FOREIGN_KEYS_EMPTY) - /*\0*/1);
return fake_answer(hstmt, &foreign_keys);

# undef FOREIGN_KEYS_EMPTY
}
Expand Down Expand Up @@ -692,10 +692,10 @@ SQLRETURN EsSQLPrimaryKeysW(
"\"rows\":[]" \
"}"
/*INDENT-ON*/
cstr_st prim_keys = CSTR_INIT(PRIMARY_KEYS_EMPTY);

INFOH(hstmt, "no primary keys supported.");
return fake_answer(hstmt, PRIMARY_KEYS_EMPTY,
sizeof(PRIMARY_KEYS_EMPTY) - /*\0*/1);
return fake_answer(hstmt, &prim_keys);

# undef PRIMARY_KEYS_EMPTY
}
Expand Down
Loading