--- /dev/null
+/* $Id$ */
+
+#include "rv_magick.h"
+
+#include "rv_util.h"
+
+#include "../config.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <wand/magick_wand.h>
+
+void rv_init_magick(void) {}
+
+bool rv_resize_picture(const char* input, const char* output, char** reason) {
+ MagickWand* wand = NULL;
+ wand = NewMagickWand();
+ if(MagickReadImage(wand, input)) {
+ int width = MagickGetImageWidth(wand);
+ int height = MagickGetImageHeight(wand);
+
+ double scale = 0;
+ if(width >= height) {
+ scale = (double)256 / width;
+ } else if(width < height) {
+ scale = (double)256 / height;
+ }
+
+ MagickResizeImage(wand, width * scale, height * scale, LanczosFilter, 1);
+ MagickSetCompressionQuality(wand, 80);
+ MagickWriteImage(wand, output);
+
+ if(wand) DestroyMagickWand(wand);
+ return true;
+ }
+ if(wand) DestroyMagickWand(wand);
+ *reason = rv_strdup("Magick error");
+ return false;
+}
#include "rv_auth.h"
#include "rv_multipart.h"
+#ifdef USE_GRAPHICSMAGICK
+#include "rv_magick.h"
+#endif
+
#include <stdlib.h>
#include <string.h>
#include <time.h>
char* postdata;
+char* nocache;
int main() {
srand(time(NULL));
+ nocache = malloc(512);
+ sprintf(nocache, "?time=%llu", (unsigned long long)time(NULL));
rv_check_sanity();
rv_init_db();
+ rv_init_magick();
rv_parse_query(getenv("QUERY_STRING"));
rv_save_query('Q');
postdata = malloc(1);
unsigned long long fstart = 0;
char* b = rv_strcat3("--", boundary, "\r");
char* eb = rv_strcat3("--", boundary, "--\r");
+ multipart_entries = malloc(sizeof(*multipart_entries));
+ multipart_entries[0] = NULL;
+ char* name = NULL;
for(i = 0;; i++) {
if(i == length || buffer[i] == '\n') {
char* line = malloc(i - incr + 1);
unsigned long long fend = i - strlen(line) - 2;
char* data = buffer + fstart;
unsigned long long datalen = fend - fstart;
+ struct multipart_entry* entry = malloc(sizeof(*entry));
+ entry->length = datalen;
+ entry->data = malloc(datalen);
+ entry->name = rv_strdup(name);
+ unsigned long long j;
+ for(j = 0; j < datalen; j++) entry->data[j] = data[j];
+
+ struct multipart_entry** old_entries = multipart_entries;
+ for(j = 0; old_entries[j] != NULL; j++)
+ ;
+ multipart_entries = malloc(sizeof(*multipart_entries) * (j + 2));
+ for(j = 0; old_entries[j] != NULL; j++) {
+ multipart_entries[j] = old_entries[j];
+ }
+ multipart_entries[j] = entry;
+ multipart_entries[j + 1] = NULL;
+ free(old_entries);
}
phase = 0;
if(strcmp(eb, line) == 0) {
}
} else if(phase == 0) {
line[strlen(line) - 1] = 0;
- fprintf(stderr, "%s\n", line);
+ int j;
+ for(j = 0; line[j] != 0; j++) {
+ if(line[j] == ':') {
+ line[j] = 0;
+ char* value = "";
+ j++;
+ for(; line[j] != 0; j++) {
+ if(line[j] != ' ' && line[j] != '\t') {
+ value = line + j;
+ break;
+ }
+ }
+ if(strcasecmp(line, "Content-Disposition") == 0) {
+ int j;
+ int incrval = 0;
+ for(j = 0;; j++) {
+ if(value[j] == ';' || value[j] == 0) {
+ char oldc = value[j];
+ value[j] = 0;
+ char* kv = value + incrval;
+ j++;
+ for(; value[j] != 0; j++) {
+ if(value[j] != ' ' && value[j] != '\t') break;
+ }
+ incrval = j;
+ int k;
+ for(k = 0; kv[k] != 0; k++) {
+ if(kv[k] == '=') {
+ kv[k] = 0;
+ if(strcmp(kv, "name") == 0) {
+ if(name != NULL) free(name);
+ name = malloc(strlen(kv + k + 1) + 1);
+ char* nkv = kv + k + 1;
+ int l = 0;
+ int incrn = 0;
+ for(l = 0; nkv[l] != 0; l++) {
+ if(nkv[l] != '"') {
+ name[incrn++] = nkv[l];
+ }
+ }
+ name[incrn] = 0;
+ }
+ break;
+ }
+ }
+ if(oldc == 0) break;
+ }
+ }
+ }
+ break;
+ }
+ }
}
free(line);
incr = i + 1;
if(i == length) break;
}
}
+ if(name != NULL) free(name);
free(b);
}
--- /dev/null
+/* $Id$ */
+
+#ifndef __RV_MAGICK_H__
+#define __RV_MAGICK_H__
+
+#include <stdbool.h>
+
+void rv_init_magick(void);
+bool rv_resize_picture(const char* input, const char* output, char** reason);
+
+#endif
#include "rv_auth.h"
#include "rv_db.h"
#include "rv_repo.h"
+#include "rv_multipart.h"
#include "../../config.h"
#include "rv_avatar.h"
#endif
+#ifdef USE_GRAPHICSMAGICK
+#include "rv_magick.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+extern char* nocache;
extern char* buffer;
void add_data(char** data, const char* txt);
void render_stuff();
bool reject = false;
char* name = rv_get_query("username");
for(i = 0; name[i] != 0; i++) {
- if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/') {
+ if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/' || name[i] == ':' || name[i] == '\n' || name[i] == '\r') {
char cbuf[2];
cbuf[0] = REPO_USER_DELIM;
cbuf[1] = 0;
add_data(&page, WWW_AVATAR_ROOT);
add_data(&page, "/");
add_data(&page, user);
- add_data(&page, ".png\" alt=\"Your Icon\"></a>");
+ add_data(&page, ".png");
+ add_data(&page, nocache);
+ add_data(&page, "\" alt=\"Your Icon\" width=\"50%\"></a>");
add_data(&page, "<form action=\"");
add_data(&page, INSTANCE_ROOT);
add_data(&page, "/?page=uploadpfp\" method=\"POST\" enctype=\"multipart/form-data\">\n");
add_data(&page, " <input type=\"submit\" value=\"Upload\">\n");
add_data(&page, "</form>\n");
}
+#endif
+#ifdef USE_AVATAR
+ } else if(strcmp(query, "uploadpfp") == 0) {
+ title = rv_strdup("Uploading Profile Picture Result");
+ page = rv_strdup("");
+ if(user == NULL) {
+ add_data(&page, "It looks like you are not logged in.<br>Want to <a href=\"");
+ add_data(&page, INSTANCE_ROOT);
+ add_data(&page, "/?page=login\">log in</a>?\n");
+ } else if(rv_get_multipart("pfp") == NULL) {
+ add_data(&page, "Invalid Form.");
+ } else {
+ struct multipart_entry* entry = rv_get_multipart("pfp");
+ char* tmp = rv_strcat3(AVATAR_ROOT, "/", user);
+ char* path = rv_strcat(tmp, ".tmp");
+ char* outpath = rv_strcat(tmp, ".png");
+ free(tmp);
+ FILE* f = fopen(path, "wb");
+ fwrite(entry->data, 1, entry->length, f);
+ fclose(f);
+ char* reason;
+ if(rv_resize_picture(path, outpath, &reason)) {
+ add_data(&page, "Uploaded the profile picture successfully.\n");
+ } else {
+ add_data(&page, "Failed to upload the profile picture.<br><code>\n");
+ char* esc = html_escape(reason);
+ add_data(&page, esc);
+ free(esc);
+ add_data(&page, "</code>\n");
+ free(reason);
+ }
+ free(path);
+ free(outpath);
+ }
#endif
} else if(strcmp(query, "myrepo") == 0) {
title = rv_strdup("My Repositories");
bool reject = false;
char* name = rv_get_query("name");
for(i = 0; name[i] != 0; i++) {
- if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/') {
+ if(name[i] == REPO_USER_DELIM || name[i] == '#' || name[i] == '\\' || name[i] == '/' || name[i] == ':' || name[i] == '\n' || name[i] == '\r') {
char cbuf[2];
cbuf[0] = REPO_USER_DELIM;
cbuf[1] = 0;
printf("enscript.o");
#endif
printf(" ");
+#if defined(USE_AVATAR)
+ printf("magick.o");
+#endif
+ printf(" ");
#if defined(USE_AVATAR)
printf("avatar.o");
#endif