Changeset: 3fd1b1ebfc1f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3fd1b1ebfc1f
Added Files:
        monetdb5/mal/mal_http_daemon.c
        monetdb5/mal/mal_http_daemon.h
        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
        sql/backends/monet5/Makefile.ag
Branch: default
Log Message:

first working version of jsonstore


diffs (truncated from 1163 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],
@@ -2292,6 +2299,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
@@ -2755,6 +2820,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)
 
@@ -3077,6 +3143,7 @@ for comp in \
        monetdb5 \
        sql \
        jaql \
+       jsonstore \
        geom \
        fits \
        rdf \
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,232 @@
+/*
+ * 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>
+/*#include "rest_jsonstore.h"*/
+#endif
+
+/*
+void startHttpdaemon(void);
+void stopHttpdaemon(void);
+*/
+
+#ifdef HAVE_MICROHTTPD
+
+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;
+
+  if (key) {};
+  if (kind) {};
+  if (filename) {};
+  if (content_type) {};
+  if (transfer_encoding) {};
+  if (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;
+
+  if (cls) {};
+  if (connection) {};
+  if (toe) {};
+
+  if (NULL == con_info)
+    return;
+
+  if (con_info->connectiontype == POST)
+    {
+      MHD_destroy_post_processor (con_info->postprocessor);
+      if (con_info->answerstring)
+        free (con_info->answerstring);
+    }
+
+  free (con_info);
+  *con_cls = NULL;
+}
+
+static int
+answer_to_connection (void *cls, struct MHD_Connection *connection,
+                      const char *url, const char *method,
+                      const char *version, const char *upload_data,
+                      size_t *upload_data_size, void **con_cls)
+{
+  struct MHD_Response *response;
+  int ret;
+  int rest;
+  char * page = NULL;
+  struct connection_info_struct *con_info = *con_cls;
+
+  if (cls) {};
+  if (url) {};
+  if (method) {};
+  if (version) {};
+  //(void)upload_data;
+  //(void)upload_data_size;
+  //(void)con_cls;
+
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to