Changeset: ceea046dfaaa for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ceea046dfaaa
Added Files:
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
Modified Files:
configure.ag
monetdb5/modules/atoms/Makefile.ag
monetdb5/modules/atoms/Tests/All
monetdb5/modules/mal/mal_init.mal
Branch: default
Log Message:
wrap curl library functions in mal to be able to test jsonstore
diffs (truncated from 353 to 300 lines):
diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -2104,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
diff --git a/monetdb5/modules/atoms/Makefile.ag
b/monetdb5/modules/atoms/Makefile.ag
--- a/monetdb5/modules/atoms/Makefile.ag
+++ b/monetdb5/modules/atoms/Makefile.ag
@@ -20,7 +20,7 @@ INCLUDES = ../../mal \
../../../common/stream \
../../../common/utils \
../../../gdk \
- $(libxml2_CFLAGS)
+ $(libxml2_CFLAGS) $(curl_CFLAGS)
MTSAFE
lib_atoms = {
@@ -37,6 +37,7 @@ lib_atoms = {
url.c url.h \
json_atom.c json_atom.h \
uuid.c uuid.h \
+ mcurl.c mcurl.h \
xml.c xml.h
}
@@ -55,8 +56,9 @@ headers_mal = {
json_atom.mal \
uuid.mal \
xml.mal \
+ mcurl.mal \
mtime.mal
}
EXTRA_DIST_DIR = Tests
-EXTRA_DIST = blob.mal color.mal identifier.mal inet.mal xml.mal xml.sql
batxml.sql str.mal batxml.mal url.mal json_atom.mal uuid.mal streams.mal
mtime.mal
+EXTRA_DIST = blob.mal color.mal identifier.mal inet.mal xml.mal xml.sql
batxml.sql str.mal batxml.mal url.mal json_atom.mal uuid.mal streams.mal
mtime.mal mcurl.mal
diff --git a/monetdb5/modules/atoms/Tests/All b/monetdb5/modules/atoms/Tests/All
--- a/monetdb5/modules/atoms/Tests/All
+++ b/monetdb5/modules/atoms/Tests/All
@@ -24,3 +24,4 @@ json05
jsonrender
uuid00
+#curl00
\ No newline at end of file
diff --git a/monetdb5/modules/atoms/Tests/curl00.mal
b/monetdb5/modules/atoms/Tests/curl00.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/Tests/curl00.mal
@@ -0,0 +1,8 @@
+
+a:="http://localhost:8998/";
+b:str:= mcurl.getrequest(a);
+io.print(b);
+
+#a:="http://www.example.com/";
+#b:str:= mcurl.getrequest(a);
+#io.print(b);
diff --git a/monetdb5/modules/atoms/Tests/curl00.stable.err
b/monetdb5/modules/atoms/Tests/curl00.stable.err
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/Tests/curl00.stable.err
@@ -0,0 +1,29 @@
+stderr of test 'curl00` in directory 'monetdb5/modules/atoms` itself:
+
+
+# 18:14:24 >
+# 18:14:24 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=35895" "--set"
"mapi_usock=/var/tmp/mtest-19428/.s.monetdb.35895" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/work/arjen/monetdb/monetdb/default/var/MonetDB/mTests_monetdb5_modules_atoms"
"curl00.mal"
+# 18:14:24 >
+
+# builtin opt gdk_dbpath =
/export/work/arjen/monetdb/monetdb/default/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = yes
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 35895
+# cmdline opt mapi_usock = /var/tmp/mtest-19428/.s.monetdb.35895
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbpath =
/export/work/arjen/monetdb/monetdb/default/var/MonetDB/mTests_monetdb5_modules_atoms
+
+# 18:14:25 >
+# 18:14:25 > "Done."
+# 18:14:25 >
+
diff --git a/monetdb5/modules/atoms/Tests/curl00.stable.out
b/monetdb5/modules/atoms/Tests/curl00.stable.out
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/Tests/curl00.stable.out
@@ -0,0 +1,37 @@
+stdout of test 'curl00` in directory 'monetdb5/modules/atoms` itself:
+
+
+# 18:14:24 >
+# 18:14:24 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=35895" "--set"
"mapi_usock=/var/tmp/mtest-19428/.s.monetdb.35895" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/work/arjen/monetdb/monetdb/default/var/MonetDB/mTests_monetdb5_modules_atoms"
"curl00.mal"
+# 18:14:24 >
+
+# MonetDB 5 server v11.16.0
+# This is an unreleased version
+# Serving database 'mTests_monetdb5_modules_atoms', using 2 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 3.875 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2013 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://harvest:35895/
+# Listening for UNIX domain connection requests on
mapi:monetdb:///var/tmp/mtest-19428/.s.monetdb.35895
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+function user.main():void;
+ a := "http://localhost:8888/";
+ b:str := mcurl.getrequest(a);
+ io.print(b);
+ a := "http://www.example.com/";
+ b:str := mcurl.getrequest(a);
+ io.print(b);
+end main;
+38 bytes retrieved
+[ "<html><body>Hello, json!</body></html>" ]
+0 bytes retrieved
+[ "<html><body>Hello, json!</body></html>" ]
+
+# 18:14:25 >
+# 18:14:25 > "Done."
+# 18:14:25 >
+
diff --git a/monetdb5/modules/atoms/mcurl.c b/monetdb5/modules/atoms/mcurl.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/mcurl.c
@@ -0,0 +1,141 @@
+/*
+ * 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.
+*/
+
+/*
+ * A. de Rijke
+ * The cURL module
+ * The cURL module contains a wrapper for all function in
+ * libcurl.
+ */
+
+#include "monetdb_config.h"
+#include "mcurl.h"
+#include "mal.h"
+#include "mal_exception.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+struct MemoryStruct {
+ char *memory;
+ size_t size;
+};
+
+#ifdef HAVE_CURL
+#include <curl/curl.h>
+
+str
+handle_get_request(str *retval, str *url);
+
+static size_t
+WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
+{
+ size_t realsize = size * nmemb;
+ struct MemoryStruct *mem = (struct MemoryStruct *)userp;
+
+ mem->memory = realloc(mem->memory, mem->size + realsize + 1);
+ if(mem->memory == NULL) {
+ /* out of memory! */
+ printf("not enough memory (realloc returned NULL)\n");
+ return 0;
+ }
+
+ memcpy(&(mem->memory[mem->size]), contents, realsize);
+ mem->size += realsize;
+ mem->memory[mem->size] = 0;
+
+ return realsize;
+}
+
+str
+handle_get_request(str *retval, str *url) {
+ str d;
+ char err_string[128];
+
+ CURL *curl_handle;
+ CURLcode res = 0;
+
+ struct MemoryStruct chunk;
+
+ chunk.memory = malloc(1); /* will be grown as needed by the realloc above
*/
+ chunk.size = 0; /* no data at this point */
+
+ curl_global_init(CURL_GLOBAL_ALL);
+ /* init the curl session */
+ curl_handle = curl_easy_init();
+ curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
+ /* set URL to get */
+
+ curl_easy_setopt(curl_handle, CURLOPT_URL, *url);
+
+ /* no progress meter please */
+ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
+
+ /* send all data to this function */
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+
+ /* we want the body be written to this file handle instead of stdout */
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
+
+ /* get it! */
+ res = curl_easy_perform(curl_handle);
+
+ /* check for errors */
+ if(res != CURLE_OK) {
+ sprintf(err_string, "curl_easy_perform() failed: %s\n",
+ curl_easy_strerror(res));
+ d = GDKstrdup(err_string);
+ }
+ else {
+ /*
+ * Now, our chunk.memory points to a memory block that is chunk.size
+ * bytes big and contains the remote file.
+ *
+ * Do something nice with it!
+ *
+ * You should be aware of the fact that at this point we might have an
+ * allocated data block, and nothing has yet deallocated that data. So when
+ * you're done with it, you should free() it as a nice application.
+ */
+
+ printf("%lu bytes retrieved\n", (long)chunk.size);
+ }
+ if (chunk.size) {
+ d = GDKstrdup(chunk.memory);
+ if(chunk.memory)
+ free(chunk.memory);
+ }
+ /* cleanup curl stuff */
+ curl_easy_cleanup(curl_handle);
+
+ *retval = d;
+ return MAL_SUCCEED;
+}
+#endif
+
+str CURLgetRequest(str *retval, str *url) {
+ (void)retval;
+ (void)url;
+#ifdef HAVE_CURL
+ return handle_get_request(retval, url);
+#endif
+ return MAL_SUCCEED;
+}
diff --git a/monetdb5/modules/atoms/mcurl.h b/monetdb5/modules/atoms/mcurl.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/atoms/mcurl.h
@@ -0,0 +1,41 @@
+/*
+ * 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
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list