From 62e149e1a4ba8916bc5e1b6a21459c4e618b0c54 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Wed, 4 Oct 2017 01:31:50 +0200 Subject: POST Multipart works Private message can be sent on board.kolibrios.org --- content/fetchers/httplib_kolibri.c | 121 +++++++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 13 deletions(-) diff --git a/content/fetchers/httplib_kolibri.c b/content/fetchers/httplib_kolibri.c index 501909daf..711b5d827 100644 --- a/content/fetchers/httplib_kolibri.c +++ b/content/fetchers/httplib_kolibri.c @@ -13,8 +13,6 @@ #include "content/fetchers/httplib_kolibri.h" #include "frontends/kolibrios/kolibri_http.h" -// #define STOP __asm__ __volatile__("int3") - extern struct fetch; struct httpfetcher { @@ -31,7 +29,6 @@ struct httpfetcher *head = NULL; void add_to_poll(struct httpfetcher *newfetcher) { LOG("-=- add: newfetcher 0x%x, newfetcher->handle 0x%x", newfetcher, newfetcher->handle); - /* STOP; */ struct httpfetcher *t = head; assert(newfetcher->next == NULL); @@ -51,7 +48,6 @@ void add_to_poll(struct httpfetcher *newfetcher) { void remove_from_poll(struct http_msg *donehttp) { struct httpfetcher *t = head, *p = head; LOG("-=- remove: (->handle) donehttp 0x%x", donehttp); - /* STOP; */ while(t) { if (t->handle == donehttp) { @@ -112,20 +108,119 @@ void *setup_fetch(struct fetch *parent_fetch, struct nsurl *url, for(i = 0; headers[i] != NULL; i++) LOG("[SETUP] -- Headers : %s", headers[i]); - struct fetch_multipart_data *printer = post_multipart; - - while(printer != NULL) { - LOG("Multipart POST : (%s = %s)\n", printer->name, printer->value); - printer = printer->next; - } if(post_multipart != NULL) { + struct fetch_multipart_data *printer = post_multipart; + while(printer != NULL) { + LOG("Multipart POST : (%s = %s)\n", printer->name, printer->value); + debug_board_printf("Multipart POST : (%s = %s)\n", printer->name, printer->value); + printer = printer->next; + } + LOG("[WARNING] We dont support POST multipart yet!\n"); LOG("[NETSURF ERROR] We dont support POST multipart yet!\n"); - return NULL; - } + char *boundary = "--------Netsurf------------KolibriOS----Multipart----"; + int lenb = strlen(boundary); + char *contenttype = "multipart/form-data; boundary=--------Netsurf------------KolibriOS----Multipart----"; + + /* Intermediate boundaries have 2 additional dashes at the beginning */ + char *iboundary = "----------Netsurf------------KolibriOS----Multipart----"; + char *content = NULL; + int contentlen = 0; + + printer = post_multipart; + while(printer != NULL) { + int leninc = strlen(iboundary) + 2 + strlen("Content-Disposition: form-data; name=") + 1 + strlen(printer->name) + 1 + 2 + 2 + strlen(printer->value) + 2; + contentlen+=leninc; + printer = printer -> next; + } + + /* Space for last boundary (which has 2 empty boundary dashes) and CRLF */ + contentlen += strlen(iboundary) + 2 + 2; + + /* Space for terminating NULL */ + contentlen += 1; + + content = realloc(content, contentlen); + + char *tmp = content; + debug_board_printf("Before Loop tmp = %u\n", tmp); + + printer = post_multipart; + while(printer != NULL) { + int i = 0; + strcpy(tmp, iboundary); + tmp+=strlen(iboundary); + + debug_board_printf("tmp = %u\n", tmp); + + *tmp++ = '\r'; + *tmp++ = '\n'; + + debug_board_printf("tmp = %u\n", tmp); + + strcpy(tmp, "Content-Disposition: form-data; name=\""); + tmp+= strlen("Content-Disposition: form-data; name=\""); + + debug_board_printf("tmp = %u\n", tmp); + + strcpy(tmp, printer->name); + tmp += strlen(printer->name); + + debug_board_printf("tmp = %u\n", tmp); + + *tmp++ = '"'; + *tmp++ = '\r'; + *tmp++ = '\n'; + *tmp++ = '\r'; + *tmp++ = '\n'; - if(post_urlenc) { + debug_board_printf("tmp = %u\n", tmp); + + strcpy(tmp, printer->value); + tmp += strlen(printer->value); + + debug_board_printf("tmp = %u\n", tmp); + + *tmp++ = '\r'; + *tmp++ = '\n'; + + debug_board_printf("END OF LOOP tmp = %u\n", tmp); + + printer = printer->next; + } + + debug_board_printf("AFTER LOOP tmp = %u, content=%u\n", tmp, content); + + strcpy(tmp, iboundary); + tmp+=strlen(iboundary); + + strcpy(tmp, "--"); + tmp+=2; + + *tmp++ = '\r'; + *tmp++ = '\n'; + + *tmp='\0'; + + debug_board_printf("TERMINATING NULL tmp = %u\n", tmp); + + LOG("Multipart request content length : %d", contentlen); + LOG("Multipart request content: %s", content); + + request = http_post_asm(nsurl_access(url), NULL, 1<<8, *headers, contenttype, contentlen - 1); + + if(request != NULL) { + int datasent = 0; + + debug_board_printf("--- Sending data : %s with length %u\n", content, contentlen); + LOG("--- Sending data : with length %u\n", contentlen); + datasent = http_send_asm(request, content, contentlen - 1); + debug_board_printf("--- Sent %d bytes of data.\n", datasent); + LOG("--- Sent %d bytes of data.\n", datasent); + } + } + else if(post_urlenc) { LOG("http_post: %s", nsurl_access(url)); request = http_post_asm(nsurl_access(url), NULL, 0, *headers, "application/x-www-form-urlencoded", strlen(post_urlenc)); if(request != NULL) { -- cgit v1.2.3