Subversion Repositories RepoView

Rev

Rev 39 | Rev 41 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: main.c 40 2024-08-22 03:43:42Z nishi $ */
2
 
3
#include <stdio.h>
4
 
5
#include "../config.h"
6
 
7
#include "rv_sanity.h"
8
#include "rv_query.h"
9
#include "rv_page.h"
10
#include "rv_util.h"
11
#include "rv_db.h"
3 nishi 12
#include "rv_auth.h"
1 nishi 13
 
14
#include <stdlib.h>
39 nishi 15
#include <string.h>
5 nishi 16
#include <time.h>
1 nishi 17
 
18
char* postdata;
19
 
3 nishi 20
int main() {
5 nishi 21
	srand(time(NULL));
1 nishi 22
	rv_check_sanity();
23
	rv_init_db();
24
	rv_parse_query(getenv("QUERY_STRING"));
25
	rv_save_query('Q');
26
	postdata = malloc(1);
27
	postdata[0] = 0;
39 nishi 28
	int hasauth = 0;
29
	char* type = getenv("CONTENT_TYPE");
30
	if(type == NULL) {
31
		type = rv_strdup("");
32
	} else {
33
		type = rv_strdup(type);
1 nishi 34
	}
39 nishi 35
	if(strcmp(type, "application/x-www-form-urlencoded") == 0) {
36
		char cbuf[2];
37
		cbuf[1] = 0;
38
		while(1) {
39
			fread(cbuf, 1, 1, stdin);
40
			if(feof(stdin)) break;
41
			char* tmp = postdata;
42
			postdata = rv_strcat(tmp, cbuf);
43
			free(tmp);
44
		}
45
	} else {
46
		int i;
47
		for(i = 0; type[i] != 0; i++) {
48
			if(type[i] == ';') {
49
				type[i] = 0;
50
				i++;
51
				bool found = false;
52
				rv_error_http();
53
				for(; type[i] != 0; i++) {
54
					if(type[i] != ' ' && type[i] != '\t') {
40 nishi 55
						int j;
56
						char* boundary = type + i;
57
						for(j = 0; boundary[j] != 0; j++){
58
							if(boundary[j] == '='){
59
								boundary[j] = 0;
60
								printf("%s\n%s\n", boundary, boundary + j + 1);
61
								found = true;
62
								break;
63
							}
64
						}
39 nishi 65
						break;
66
					}
67
				}
68
				if(!found) {
69
					printf("Bad multipart/form-data. Parsing fail.");
70
					goto freeall;
71
				}
72
				break;
73
			}
74
		}
75
	}
1 nishi 76
	rv_parse_query(postdata);
77
	rv_save_query('P');
5 nishi 78
	rv_init_auth();
39 nishi 79
	hasauth = 1;
1 nishi 80
	rv_process_page();
81
	printf("Content-Type: text/html\r\n");
82
	printf("\r\n");
83
	rv_print_page();
39 nishi 84
	rv_load_query('P');
85
	rv_free_query();
86
freeall:
3 nishi 87
	rv_load_query('Q');
1 nishi 88
	rv_free_query();
89
	rv_close_db();
39 nishi 90
	if(hasauth) rv_free_auth();
91
	free(type);
1 nishi 92
}