From: Nishi Date: Thu, 22 Aug 2024 03:38:21 +0000 (+0000) Subject: trying to add multipart X-Git-Url: https://git.chaotic.ninja/gitweb/nishi/?a=commitdiff_plain;h=e148e68af8ca111387273c7a84ccbeb3631b1982;p=repoview.git trying to add multipart git-svn-id: file:///raid/svn-personal/repoview/trunk@39 7e8b2a19-8934-dd40-8cb3-db22cdd5a80f --- diff --git a/CGI/main.c b/CGI/main.c index 8cf9f8e..f1b2803 100644 --- a/CGI/main.c +++ b/CGI/main.c @@ -12,6 +12,7 @@ #include "rv_auth.h" #include +#include #include char* postdata; @@ -24,26 +25,59 @@ int main() { rv_save_query('Q'); postdata = malloc(1); postdata[0] = 0; - char cbuf[2]; - cbuf[1] = 0; - while(1) { - fread(cbuf, 1, 1, stdin); - if(feof(stdin)) break; - char* tmp = postdata; - postdata = rv_strcat(tmp, cbuf); - free(tmp); + int hasauth = 0; + char* type = getenv("CONTENT_TYPE"); + if(type == NULL) { + type = rv_strdup(""); + } else { + type = rv_strdup(type); + } + if(strcmp(type, "application/x-www-form-urlencoded") == 0) { + char cbuf[2]; + cbuf[1] = 0; + while(1) { + fread(cbuf, 1, 1, stdin); + if(feof(stdin)) break; + char* tmp = postdata; + postdata = rv_strcat(tmp, cbuf); + free(tmp); + } + } else { + int i; + for(i = 0; type[i] != 0; i++) { + if(type[i] == ';') { + type[i] = 0; + i++; + bool found = false; + rv_error_http(); + for(; type[i] != 0; i++) { + if(type[i] != ' ' && type[i] != '\t') { + printf("%s\n", type + i); + break; + } + } + if(!found) { + printf("Bad multipart/form-data. Parsing fail."); + goto freeall; + } + break; + } + } } rv_parse_query(postdata); rv_save_query('P'); rv_init_auth(); + hasauth = 1; rv_process_page(); printf("Content-Type: text/html\r\n"); printf("\r\n"); rv_print_page(); - rv_load_query('Q'); - rv_free_query(); rv_load_query('P'); rv_free_query(); +freeall: + rv_load_query('Q'); + rv_free_query(); rv_close_db(); - rv_free_auth(); + if(hasauth) rv_free_auth(); + free(type); } diff --git a/CGI/theme/modern.c b/CGI/theme/modern.c index ac01979..df0bd9b 100644 --- a/CGI/theme/modern.c +++ b/CGI/theme/modern.c @@ -14,9 +14,14 @@ #include "rv_enscript.h" #endif +#ifdef USE_AVATAR +#include "rv_avatar.h" +#endif + #include #include #include +#include extern char* buffer; void add_data(char** data, const char* txt); @@ -208,11 +213,27 @@ void list_files(const char* pathname) { free(urlpath); } +void generate_avatar(void) { + if(user != NULL) { + char* tmp = rv_strcat3(AVATAR_ROOT, "/", user); + char* path = rv_strcat(tmp, ".png"); + free(tmp); + if(access(path, F_OK) != 0) { + rv_avatar_generate(path, user); + } + free(path); + } +} + void render_page(void) { rv_load_query('Q'); char* query = rv_get_query("page"); if(query == NULL) query = "welcome"; +#ifdef USE_AVATAR + generate_avatar(); +#endif + if(strcmp(query, "welcome") == 0) { title = rv_strdup("Welcome"); desc = rv_strdup("Welcome to " INSTANCE_NAME "."); @@ -356,6 +377,24 @@ void render_page(void) { page = rv_strdup("It looks like you are not logged in.
Want to log in?\n"); + } else { + page = rv_strdup(""); + add_data(&page, "

Your Icon

\n"); + add_data(&page, "\"Your"); + add_data(&page, "
\n"); + add_data(&page, " \n"); + add_data(&page, " \n"); + add_data(&page, "
\n"); } #endif } else if(strcmp(query, "myrepo") == 0) { @@ -694,6 +733,11 @@ void render_page(void) { if(desc == NULL) desc = rv_strdup(""); if(page == NULL) page = rv_strdup(""); if(nav == NULL) nav = rv_strdup(""); + +#ifdef USE_AVATAR + generate_avatar(); +#endif + render_stuff(); freeall: free(page);