Changeset: cd180d4fef46 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cd180d4fef46 Modified Files: monetdb5/mal/mal_http_daemon.c sql/backends/monet5/rest/rest_jsonstore.c sql/backends/monet5/rest/rest_jsonstore_handle_get.c sql/backends/monet5/rest/rest_jsonstore_handle_get.h Branch: default Log Message:
partial implementation of attachment handling diffs (193 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 @@ -54,7 +54,6 @@ struct connection_info_struct int connectiontype; char *answerstring; struct MHD_PostProcessor *postprocessor; - char * poststring; }; static int @@ -87,6 +86,7 @@ iterate_post (void *coninfo_cls, enum MH size_t size) { struct connection_info_struct *con_info = coninfo_cls; + char *answerstring; (void)key; (void)kind; @@ -99,7 +99,6 @@ iterate_post (void *coninfo_cls, enum MH { if ((size > 0) && (size <= MAXNAMESIZE)) { - char *answerstring; answerstring = malloc (MAXANSWERSIZE); if (!answerstring) return MHD_NO; @@ -111,24 +110,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) + answerstring = malloc (MAXANSWERSIZE); + if (!answerstring) return MHD_NO; - snprintf (poststring, MAXANSWERSIZE, "%s", data); - con_info->poststring = poststring; + snprintf (answerstring, MAXANSWERSIZE, "%s", data); + con_info->answerstring = answerstring; } else - con_info->poststring = NULL; + con_info->answerstring = NULL; return MHD_NO; } - + return MHD_YES; } 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 @@ -56,7 +56,7 @@ mserver_browser_get(const UriUriA uri) { if (uri.absolutePath) { if (uri.pathHead != NULL) { if (uri.pathHead->next == NULL) { - if (strncmp(uri.pathHead->text.first, API_SPECIAL_CHAR, 1) == 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; if (strcmp(uri.pathHead->text.first, MONETDB_REST_PATH_ALLDBS) == 0) { @@ -74,7 +74,7 @@ mserver_browser_get(const UriUriA uri) { } } else { // We have multiple paths - if (strncmp(uri.pathHead->text.first, API_SPECIAL_CHAR, 1) == 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; if (strcmp(uri.pathHead->text.first, MONETDB_REST_PATH_ALLDBS) == 0) { @@ -191,7 +191,8 @@ mserver_browser_post(const UriUriA uri) if (uri.absolutePath) { if (uri.pathHead != NULL) { if (uri.pathHead->next == NULL) { - if (strncmp(uri.pathHead->text.first, API_SPECIAL_CHAR, 1) == 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 { 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 @@ -284,13 +284,46 @@ str RESTinsertAttach(char ** result, cha size_t len = strlen(dbname) + strlen(doc_id) + strlen(attachment) + (7 * line) - (3 * place) + char0; */ + char *s; + char * attach; + size_t i; + + size_t len; char * query = - "INSERT INTO jsonblob_%s ( _id, mimetype, filename, value ) VALUES ( '%s', '', '\"text/plain\"','%s');"; - size_t len = strlen(dbname) + strlen(doc_id) + strlen(attachment) + "INSERT INTO jsonblob_%s ( _id, mimetype, filename, value ) VALUES ( '%s', '', '\"text/plain\"','%s');"; + char hexit[] = "0123456789ABCDEF"; + + size_t expectedlen; + + if (strlen(attachment) == ~(size_t) 0) + expectedlen = 4; + else + expectedlen = (strlen(attachment) * 2); + /*if (*l < 0 || (size_t) * l < expectedlen) { + if (*tostr != NULL) + GDKfree(*tostr); + *tostr = (str) GDKmalloc(expectedlen); + *l = (int) expectedlen; + } + */ + attach = malloc(expectedlen); + s = attach + strlen(attach); + + for (i = 0; i < strlen(attachment); i++) { + int val = (attachment[i] >> 4) & 15; + + //*s++ = ' '; + *s++ = hexit[val]; + val = attachment[i] & 15; + *s++ = hexit[val]; + } + *s = '\0'; + + len = strlen(dbname) + strlen(doc_id) + strlen(attach) + 95 + char0; querytext = malloc(len); - snprintf(querytext, len, query, dbname, doc_id, attachment); + snprintf(querytext, len, query, dbname, doc_id, attach); msg = RESTsqlQuery(result, querytext); if (querytext != NULL) { @@ -301,3 +334,38 @@ str RESTinsertAttach(char ** result, cha //} return msg; } + +str RESTgetAttach(char ** result, char * dbname, const char * doc_id) +{ + str msg = MAL_SUCCEED; + size_t len = strlen(dbname) + strlen(doc_id) + 40; + char * querytext = NULL; + + querytext = malloc(len); + snprintf(querytext, len, "SELECT * FROM jsonblob_%s WHERE _id = '%s';", dbname, doc_id); + + msg = RESTsqlQuery(result, querytext); + if (querytext != NULL) { + free(querytext); + } + return msg; +} + +str RESTdeleteAttach(char ** result, char * dbname, const char * doc_id) +{ + str msg = MAL_SUCCEED; + size_t len = strlen(dbname) + strlen(doc_id) + 37 + 1; + char * querytext = NULL; + + querytext = malloc(len); + snprintf(querytext, len, "DELETE FROM jsonblob_%s WHERE _id = '%s';", dbname, doc_id); + + msg = RESTsqlQuery(result, querytext); + if (querytext != NULL) { + free(querytext); + } + if (strcmp(*result,"&2 3 -1\n") == 0) { + msg = RESTsqlQuery(result, result_ok); + } + return msg; +} diff --git a/sql/backends/monet5/rest/rest_jsonstore_handle_get.h b/sql/backends/monet5/rest/rest_jsonstore_handle_get.h --- a/sql/backends/monet5/rest/rest_jsonstore_handle_get.h +++ b/sql/backends/monet5/rest/rest_jsonstore_handle_get.h @@ -45,5 +45,7 @@ rest_export str RESTupdateDoc(char **res rest_export str RESTdeleteDoc(char ** result, char * dbname, const char * doc_id); rest_export str RESTerror(char **result, int rest_command); rest_export str RESTinsertAttach(char ** result, char * dbname, const char * attachment, const char * doc_id); +rest_export str RESTgetAttach(char ** result, char * dbname, const char * doc_id); +rest_export str RESTdeleteAttach(char ** result, char * dbname, const char * doc_id); #endif _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list