Subversion Repositories RepoView

Rev

Rev 6 | Rev 40 | 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 39 2024-08-22 03:38:21Z 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') {
55
						printf("%s\n", type + i);
56
						break;
57
					}
58
				}
59
				if(!found) {
60
					printf("Bad multipart/form-data. Parsing fail.");
61
					goto freeall;
62
				}
63
				break;
64
			}
65
		}
66
	}
1 nishi 67
	rv_parse_query(postdata);
68
	rv_save_query('P');
5 nishi 69
	rv_init_auth();
39 nishi 70
	hasauth = 1;
1 nishi 71
	rv_process_page();
72
	printf("Content-Type: text/html\r\n");
73
	printf("\r\n");
74
	rv_print_page();
39 nishi 75
	rv_load_query('P');
76
	rv_free_query();
77
freeall:
3 nishi 78
	rv_load_query('Q');
1 nishi 79
	rv_free_query();
80
	rv_close_db();
39 nishi 81
	if(hasauth) rv_free_auth();
82
	free(type);
1 nishi 83
}