Changeset: 5586e168c723 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5586e168c723 Modified Files: monetdb5/mal/mal_http_daemon.c 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 Branch: default Log Message:
add new functions and partial implementation of attachments diffs (truncated from 379 to 300 lines): diff --git a/monetdb5/mal/mal_http_daemon.c b/monetdb5/mal/mal_http_daemon.c --- a/monetdb5/mal/mal_http_daemon.c +++ b/monetdb5/mal/mal_http_daemon.c @@ -3,14 +3,14 @@ * 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. @@ -54,6 +54,7 @@ struct connection_info_struct int connectiontype; char *answerstring; struct MHD_PostProcessor *postprocessor; + char * poststring; }; static int @@ -111,6 +112,23 @@ iterate_post (void *coninfo_cls, enum MH return MHD_NO; } + if (strcmp (key, "file") == 0) + { + if ((size > 0) && (size <= MAXNAMESIZE)) + { + char *poststring; + poststring = malloc (MAXANSWERSIZE); + if (!poststring) + return MHD_NO; + + snprintf (poststring, MAXANSWERSIZE, "%s", data); + con_info->poststring = poststring; + } else + con_info->poststring = NULL; + + return MHD_NO; + } + return MHD_YES; } @@ -187,9 +205,11 @@ answer_to_connection (void *cls, struct *upload_data_size); *upload_data_size = 0; return MHD_YES; - } else if (con_info->answerstring != NULL) { - return send_page(connection, url, method, page, - con_info->answerstring); + } else { + if (con_info->answerstring != NULL) { + return send_page(connection, url, method, page, + con_info->answerstring); + } } } diff --git a/sql/backends/monet5/rest/rest_jsonstore.c b/sql/backends/monet5/rest/rest_jsonstore.c --- a/sql/backends/monet5/rest/rest_jsonstore.c +++ b/sql/backends/monet5/rest/rest_jsonstore.c @@ -165,6 +165,14 @@ mserver_browser_delete(const UriUriA uri mserver_rest_command = MONETDB_REST_DELETE_DB; fprintf(stderr, "url: %s\n", uri.pathHead->text.first); } + } else { + if (strcmp(uri.pathHead->text.first, API_SPECIAL_CHAR) < 0) { + // This path element is on of the special cases + mserver_rest_command = MONETDB_REST_UNKWOWN_SPECIAL; + } else { + mserver_rest_command = MONETDB_REST_DB_DELETE_DOC; + fprintf(stderr, "url: %s\n", uri.pathHead->text.first); + } } } else { // A absolutePath with an empty pathHead means the root url @@ -183,17 +191,31 @@ mserver_browser_post(const UriUriA uri) if (uri.absolutePath) { if (uri.pathHead != NULL) { if (uri.pathHead->next == NULL) { - if (strcmp(uri.pathHead->text.first, API_SPECIAL_CHAR) < 0) { + if (strncmp(uri.pathHead->text.first, API_SPECIAL_CHAR, 1) == 0) { // This path element is on of the special cases mserver_rest_command = MONETDB_REST_UNKWOWN_SPECIAL; } else { - mserver_rest_command = MONETDB_REST_POST_NEW_DOC; - fprintf(stderr, "url: %s\n", uri.pathHead->text.first); + if (uri.pathHead->next == NULL) { + mserver_rest_command = MONETDB_REST_POST_NEW_DOC; + fprintf(stderr, "url: %s\n", uri.pathHead->text.first); + } else { + if (strcmp(uri.pathTail->text.first, MONETDB_REST_ATTACHMENT) == 0) { + mserver_rest_command = MONETDB_REST_INSERT_ATTACHMENT; + } else { + mserver_rest_command = MONETDB_REST_NO_ATTACHMENT_PATH; + } + } + } + } else { + if (strcmp(uri.pathTail->text.first, MONETDB_REST_ATTACHMENT) == 0) { + mserver_rest_command = MONETDB_REST_INSERT_ATTACHMENT; + } else { + mserver_rest_command = MONETDB_REST_NO_ATTACHMENT_PATH; } } } else { // A absolutePath with an empty pathHead means the root url - // This is not allowed in a put message + // This is not allowed in a post message mserver_rest_command = MONETDB_REST_MISSING_DATABASENAME; } } else { @@ -215,11 +237,13 @@ char * get_dbname(UriUriA uri) { static char * get_docid(UriUriA uri) { - int len; + size_t len; char * docid; - len = strlen(uri.pathHead->next->text.first); + //len = strlen(uri.pathHead->next->text.first); + len = uri.pathHead->next->text.afterLast + - uri.pathHead->next->text.first; docid = malloc(len + 1); - strcpy(docid, uri.pathHead->next->text.first); + strncpy(docid, uri.pathHead->next->text.first, len); return docid; } @@ -251,7 +275,7 @@ handle_http_request (const char *url, co } else if ((strcmp(method, "DELETE")) == 0) { mserver_rest_command = mserver_browser_delete(uri); } else { - // error + /* error */ } switch (mserver_rest_command) { @@ -272,6 +296,12 @@ handle_http_request (const char *url, co case MONETDB_REST_GET_ALLUUIDS: RESTuuid(page); break; + case MONETDB_REST_MISSING_DATABASENAME: + RESTerror(page, mserver_rest_command); + break; + case MONETDB_REST_NO_PARAMETER_ALLOWED: + RESTerror(page, mserver_rest_command); + break; case MONETDB_REST_POST_NEW_DOC: dbname = get_dbname(uri); RESTcreateDoc(page, dbname, postdata); @@ -290,8 +320,21 @@ handle_http_request (const char *url, co docid = get_docid(uri); RESTupdateDoc(page, dbname, postdata, docid); break; + case MONETDB_REST_DB_DELETE_DOC: + dbname = get_dbname(uri); + docid = get_docid(uri); + RESTdeleteDoc(page, dbname, docid); + break; + case MONETDB_REST_INSERT_ATTACHMENT: + dbname = get_dbname(uri); + docid = get_docid(uri); + RESTinsertAttach(page, dbname, postdata, docid); + break; + case MONETDB_REST_NO_ATTACHMENT_PATH: + RESTerror(page, mserver_rest_command); + break; default: - // error, unknown command + /* error, unknown command */ ret = 1; } @@ -299,6 +342,10 @@ handle_http_request (const char *url, co if (dbname != NULL) { free(dbname); } + if (docid != NULL) { + free(docid); + } + return ret; } diff --git a/sql/backends/monet5/rest/rest_jsonstore.h b/sql/backends/monet5/rest/rest_jsonstore.h --- a/sql/backends/monet5/rest/rest_jsonstore.h +++ b/sql/backends/monet5/rest/rest_jsonstore.h @@ -46,9 +46,20 @@ #define MONETDB_REST_POST_NEW_DOC 10 #define MONETDB_REST_DB_GETDOCID 11 #define MONETDB_REST_DB_UPDATE_DOC 12 +#define MONETDB_REST_DB_DELETE_DOC 13 +#define MONETDB_REST_INSERT_ATTACHMENT 14 +#define MONETDB_REST_NO_ATTACHMENT_PATH 15 +#define MONETDB_REST_ATTACHMENT "attachment" #define MONETDB_REST_PATH_ALLDBS "_all_dbs" #define MONETDB_REST_PATH_UUIDS "_uuids" +#define MONETDB_REST_PATH_DESIGN "_design" +#define MONETDB_REST_PATH_INFO "_info" +#define MONETDB_REST_PATH_VIEW "_view" +#define MONETDB_REST_PATH_SHOW "_show" +#define MONETDB_REST_PATH_LIST "_list" +#define MONETDB_REST_PATH_UPDATE "_update" +#define MONETDB_REST_PATH_REWRITE "_rewrite" rest_export str RESTprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); rest_export int diff --git a/sql/backends/monet5/rest/rest_jsonstore_handle_get.c b/sql/backends/monet5/rest/rest_jsonstore_handle_get.c --- a/sql/backends/monet5/rest/rest_jsonstore_handle_get.c +++ b/sql/backends/monet5/rest/rest_jsonstore_handle_get.c @@ -25,11 +25,15 @@ #include "stream.h" #include "sql_scenario.h" #include <mapi.h> +#include <rest_jsonstore.h> #include <rest_jsonstore_handle_get.h> #include "mal_backend.h" static str RESTsqlQuery(char **result, char * query); -char * result_ok = "select true as ok;"; +static char * result_ok = "select true as ok;"; +static int char0 = 1; +static int place = 2; +static int line = 30; static str RESTsqlQuery(char **result, char * query) @@ -89,7 +93,7 @@ str RESTwelcome(char **result) str RESTallDBs(char **result) { str msg = MAL_SUCCEED; - char * querytext = "select substring(name, 6, length(name) -5) as name from tables where name like 'json_%';"; + char * querytext = "select substring(name, 6, length(name) -5) as name from tables where name like 'json!_%'ESCAPE'!';"; msg = RESTsqlQuery(result, querytext); return msg; } @@ -105,11 +109,20 @@ str RESTuuid(char **result) str RESTcreateDB(char ** result, char * dbname) { str msg = MAL_SUCCEED; - int len = strlen(dbname) + 58; char * querytext = NULL; + char * query = + "CREATE TABLE json_%s ( " + "_id uuid, _rev VARCHAR(34), " + "js json); " + "CREATE TABLE jsonblob_%s ( " + "_id uuid, " + "mimetype varchar(128), " + "filename varchar(128), " + "value blob); "; + size_t len = 2 * strlen(dbname) + (8 * line) - (2 * place) + char0; querytext = malloc(len); - snprintf(querytext, len, "CREATE TABLE json_%s (_id uuid, _rev VARCHAR(34), js json);", dbname); + snprintf(querytext, len, query, dbname, dbname); msg = RESTsqlQuery(result, querytext); if (querytext != NULL) { @@ -124,11 +137,14 @@ str RESTcreateDB(char ** result, char * str RESTdeleteDB(char ** result, char * dbname) { str msg = MAL_SUCCEED; - int len = strlen(dbname) + 23; char * querytext = NULL; + char * query = + "DROP TABLE json_%s; " + "DROP TABLE jsonblob_%s; "; + int len = 2 * strlen(dbname) + (2 * line) - (2 * place) + char0; querytext = malloc(len); - snprintf(querytext, len, "DROP TABLE json_%s;", dbname); + snprintf(querytext, len, query, dbname, dbname); msg = RESTsqlQuery(result, querytext); if (querytext != NULL) { @@ -210,3 +226,78 @@ str RESTupdateDoc(char ** result, char * } return msg; } + +str RESTdeleteDoc(char ** result, char * dbname, const char * doc_id) +{ + str msg = MAL_SUCCEED; + size_t len = strlen(dbname) + strlen(doc_id) + 33 + 1; + char * querytext = NULL; + + querytext = malloc(len); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list