Changeset: 1f66e1251666 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1f66e1251666 Added Files: monetdb5/mal/mal_http_daemon.c monetdb5/mal/mal_http_daemon.h monetdb5/modules/atoms/Tests/curl00.mal monetdb5/modules/atoms/Tests/curl00.stable.err monetdb5/modules/atoms/Tests/curl00.stable.out monetdb5/modules/atoms/mcurl.c monetdb5/modules/atoms/mcurl.h monetdb5/modules/atoms/mcurl.mal sql/backends/monet5/rest/73_jsonstore.mal sql/backends/monet5/rest/Makefile.ag sql/backends/monet5/rest/jsonstore.mal sql/backends/monet5/rest/rest_jsonstore.c sql/backends/monet5/rest/rest_jsonstore.h sql/backends/monet5/rest/rest_jsonstore_handle_get.c sql/backends/monet5/rest/rest_jsonstore_handle_get.h Modified Files: configure.ag monetdb5/mal/Makefile.ag monetdb5/mal/mal.c monetdb5/modules/atoms/Makefile.ag monetdb5/modules/atoms/Tests/All monetdb5/modules/mal/mal_init.mal sql/backends/monet5/Makefile.ag Branch: default Log Message:
merge with local clone diffs (truncated from 1478 to 300 lines): diff --git a/configure.ag b/configure.ag --- a/configure.ag +++ b/configure.ag @@ -227,6 +227,13 @@ no-auto) ;; esac +dft_jsonstore=no +AC_ARG_ENABLE(jsonstore, + AS_HELP_STRING([--enable-jsonstore], + [enable support for MonetDB/jsonstore (default=no)]), + enable_jsonstore=$enableval, + enable_jsonstore=$dft_jsonstore) + dft_odbc=auto AC_ARG_ENABLE(odbc, AS_HELP_STRING([--enable-odbc], @@ -2097,6 +2104,7 @@ if test x"$have_curl" = x"yes" ; then AC_DEFINE(HAVE_CURL, 1, [Define if you have the cURL library]) AC_SUBST(PKG_CURL, libcurl) fi +AM_CONDITIONAL(HAVE_CURL, test x"$have_curl" != xno) PKG_CHECK_MODULES([zlib], [zlib], [have_zlib="yes"], [have_zlib="no"; why_have_zlib="(zlib not found)"]) if test x"$have_zlib" = x"yes" ; then @@ -2373,6 +2381,64 @@ if test x"$have_atomic_ops" = x"yes" ; t LIBS="$LIBS $atomic_ops_LIBS" fi +dnl MicroHTTPD library +dnl required for MonetDB5 SQL jsonstore, optional otherwise +have_libmicrohttpd=auto +AC_ARG_WITH(libmicrohttpd, + AS_HELP_STRING([--with-libmicrohttpd=DIR], + [libmicrohttpd library is installed in DIR]), + have_libmicrohttpd="$withval") + +dnl Uriparser library +dnl required for MonetDB5 SQL jsonstore, optional otherwise +have_liburiparser=auto +AC_ARG_WITH(liburiparser, + AS_HELP_STRING([--with-liburiparser=DIR], + [liburiparser library is installed in DIR]), + have_liburiparser="$withval") + + if test "x$have_liburiparser" == xauto; then + PKG_CHECK_MODULES([liburiparser], [liburiparser], + [have_liburiparser=yes], + [have_liburiparser=no]) + fi + + if test "x$have_libmicrohttpd" == xauto; then + PKG_CHECK_MODULES([libmicrohttpd], [libmicrohttpd], + [have_libmicrohttpd=yes], + [have_libmicrohttpd=no]) + fi + +if test "x$enable_jsonstore" != xno; then + AC_DEFINE(HAVE_JSONSTORE, 1, [Define that you want to build the jsonstore library]) + + case "$enable_jsonstore-$have_libmicrohttpd" in + yes-no) + AC_MSG_ERROR([LibMicroHTTPD library not found but required for jsonstore]) + ;; + yes-yes) + AC_DEFINE(HAVE_MICROHTTPD, 1, [Define if you have the LibMicroHTTPD library]) + save_LIBS="$LIBS" + LIBS="$LIBS $libmicrohttpd_LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $libmicrohttpd_CFLAGS" + ;; + esac + + case "$enable_jsonstore-$have_liburiparser" in + yes-no) + AC_MSG_ERROR([LibUriParser library not found but required for jsonstore]) + ;; + yes-yes) + AC_DEFINE(HAVE_URIPARSER, 1, [Define if you have the LibUriParser library]) + save_LIBS="$LIBS" + LIBS="$LIBS $liburiparser_LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $liburiparser_CFLAGS" + ;; + esac +fi + dnl checks for header files AC_HEADER_STDBOOL AC_HEADER_STDC @@ -2841,6 +2907,7 @@ AM_CONDITIONAL(HAVE_MONETDB5, test "x$en AM_CONDITIONAL(HAVE_SQL, test "x$enable_sql" = xyes -o "x$enable_sql" = xauto) AM_CONDITIONAL(HAVE_JAQL, test "x$enable_jaql" = xyes -o "x$enable_jaql" = xauto) AM_CONDITIONAL(HAVE_GEOM, test "x$enable_geom" = xyes -o "x$enable_geom" = xauto) +AM_CONDITIONAL(HAVE_JSONSTORE, test "x$enable_jsonstore" = xyes -o "x$enable_jsonstore" = xauto) AM_CONDITIONAL(HAVE_TESTING, test "x$enable_testing" = xyes -o "x$enable_testing" = xauto) AM_CONDITIONAL(HAVE_DEVELOPER, test "x$enable_developer" = xyes) @@ -3180,18 +3247,19 @@ done echo echo "* Enabled/disabled components:" for comp in \ - 'gdk ' \ - 'monetdb5' \ - 'sql ' \ - 'jaql ' \ - 'geom ' \ - 'fits ' \ - 'rdf ' \ - 'datacell' \ - 'odbc ' \ - 'jdbc ' \ - 'control ' \ - 'testing ' \ + 'gdk ' \ + 'monetdb5 ' \ + 'sql ' \ + 'jaql ' \ + 'jsonstore' \ + 'geom ' \ + 'fits ' \ + 'rdf ' \ + 'datacell ' \ + 'odbc ' \ + 'jdbc ' \ + 'control ' \ + 'testing ' \ ; do eval "dft=\$dft_$comp" eval "enable=\$enable_$comp" diff --git a/monetdb5/mal/Makefile.ag b/monetdb5/mal/Makefile.ag --- a/monetdb5/mal/Makefile.ag +++ b/monetdb5/mal/Makefile.ag @@ -20,6 +20,7 @@ INCLUDES = ../../common/options \ ../../common/utils \ ../../clients/mapilib \ ../../gdk \ + #../../sql/backends/monet5/rest \ $(READLINE_INCS) MTSAFE @@ -37,6 +38,7 @@ lib_mal = { mal_exception.c mal_exception.h \ mal_factory.c mal_factory.h \ mal_function.c mal_function.h \ + mal_http_daemon.c mal_http_daemon.h \ mal_import.c mal_import.h \ mal_runtime.c mal_runtime.h \ mal_instruction.c mal_instruction.h \ diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c --- a/monetdb5/mal/mal.c +++ b/monetdb5/mal/mal.c @@ -191,6 +191,7 @@ char *mal_trace; /* enable profile even #include "mal_recycle.h" #include "mal_dataflow.h" #include "mal_profiler.h" +#include "mal_http_daemon.h" MT_Lock mal_contextLock MT_LOCK_INITIALIZER("mal_contextLock"); MT_Lock mal_namespaceLock MT_LOCK_INITIALIZER("mal_namespaceLock"); @@ -254,6 +255,9 @@ int mal_init(void){ initParser(); initHeartbeat(); initResource(); +#ifdef HAVE_JSONSTORE + startHttpdaemon(); +#endif RECYCLEinit(); if( malBootstrap() == 0) return -1; @@ -328,6 +332,9 @@ void mal_exit(void){ RECYCLEdrop(mal_clients); /* remove any left over intermediates */ stopProfiling(); stopHeartbeat(); +#ifdef HAVE_JSONSTORE + stopHttpdaemon(); +#endif stopMALdataflow(); #if 0 diff --git a/monetdb5/mal/mal_http_daemon.c b/monetdb5/mal/mal_http_daemon.c new file mode 100644 --- /dev/null +++ b/monetdb5/mal/mal_http_daemon.c @@ -0,0 +1,214 @@ +/* + * The contents of this file are subject to the MonetDB Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.monetdb.org/Legal/MonetDBLicense + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is the MonetDB Database System. + * + * The Initial Developer of the Original Code is CWI. + * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + * Copyright August 2008-2013 MonetDB B.V. + * All Rights Reserved. +*/ + +#include "monetdb_config.h" + +#include <sys/types.h> +#include <sys/select.h> +#include <sys/socket.h> +#include <stdint.h> +#include <stdarg.h> +#include <stdio.h> + +#include "mal_client.h" +#include "mal_http_daemon.h" +#ifdef HAVE_MICROHTTPD +#include <microhttpd.h> + +static MT_Id hdthread; +static int volatile hdrunning; +struct MHD_Daemon *http_daemon; +#define PORT 8998 +#define POSTBUFFERSIZE 512 +#define MAXNAMESIZE 20 +#define MAXANSWERSIZE 512 + +#define GET 0 +#define POST 1 + +static +http_request_handler http_handler; + +void register_http_handler(http_request_handler handler) { + http_handler = handler; +} + +struct connection_info_struct +{ + int connectiontype; + char *answerstring; + struct MHD_PostProcessor *postprocessor; +}; + +static int +iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, + const char *filename, const char *content_type, + const char *transfer_encoding, const char *data, uint64_t off, + size_t size) +{ + struct connection_info_struct *con_info = coninfo_cls; + + (void)key; + (void)kind; + (void)filename; + (void)content_type; + (void)transfer_encoding; + (void)off; + + if (strcmp (key, "json") == 0) + { + if ((size > 0) && (size <= MAXNAMESIZE)) + { + char *answerstring; + answerstring = malloc (MAXANSWERSIZE); + if (!answerstring) + return MHD_NO; + + snprintf (answerstring, MAXANSWERSIZE, "%s", data); + con_info->answerstring = answerstring; + } + else + con_info->answerstring = NULL; + + return MHD_NO; + } + + return MHD_YES; +} + +static void +request_completed (void *cls, struct MHD_Connection *connection, + void **con_cls, enum MHD_RequestTerminationCode toe) +{ + struct connection_info_struct *con_info = *con_cls; + + (void)cls; + (void)connection; + (void)toe; + + if (con_info == NULL) + return; + + if (con_info->connectiontype == POST) + { + MHD_destroy_post_processor (con_info->postprocessor); + if (con_info->answerstring) + free (con_info->answerstring); + } + + free (con_info); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list