Subversion Repositories RepoView

Rev

Rev 6 | Rev 40 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 39
Line 1... Line 1...
1
/* $Id: main.c 6 2024-08-21 00:44:17Z nishi $ */
1
/* $Id: main.c 39 2024-08-22 03:38:21Z nishi $ */
2
 
2
 
3
#include <stdio.h>
3
#include <stdio.h>
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 10... Line 10...
10
#include "rv_util.h"
10
#include "rv_util.h"
11
#include "rv_db.h"
11
#include "rv_db.h"
12
#include "rv_auth.h"
12
#include "rv_auth.h"
13
 
13
 
14
#include <stdlib.h>
14
#include <stdlib.h>
-
 
15
#include <string.h>
15
#include <time.h>
16
#include <time.h>
16
 
17
 
17
char* postdata;
18
char* postdata;
18
 
19
 
19
int main() {
20
int main() {
Line 22... Line 23...
22
	rv_init_db();
23
	rv_init_db();
23
	rv_parse_query(getenv("QUERY_STRING"));
24
	rv_parse_query(getenv("QUERY_STRING"));
24
	rv_save_query('Q');
25
	rv_save_query('Q');
25
	postdata = malloc(1);
26
	postdata = malloc(1);
26
	postdata[0] = 0;
27
	postdata[0] = 0;
-
 
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);
-
 
34
	}
-
 
35
	if(strcmp(type, "application/x-www-form-urlencoded") == 0) {
27
	char cbuf[2];
36
		char cbuf[2];
28
	cbuf[1] = 0;
37
		cbuf[1] = 0;
29
	while(1) {
38
		while(1) {
30
		fread(cbuf, 1, 1, stdin);
39
			fread(cbuf, 1, 1, stdin);
31
		if(feof(stdin)) break;
40
			if(feof(stdin)) break;
32
		char* tmp = postdata;
41
			char* tmp = postdata;
33
		postdata = rv_strcat(tmp, cbuf);
42
			postdata = rv_strcat(tmp, cbuf);
34
		free(tmp);
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
		}
35
	}
66
	}
36
	rv_parse_query(postdata);
67
	rv_parse_query(postdata);
37
	rv_save_query('P');
68
	rv_save_query('P');
38
	rv_init_auth();
69
	rv_init_auth();
-
 
70
	hasauth = 1;
39
	rv_process_page();
71
	rv_process_page();
40
	printf("Content-Type: text/html\r\n");
72
	printf("Content-Type: text/html\r\n");
41
	printf("\r\n");
73
	printf("\r\n");
42
	rv_print_page();
74
	rv_print_page();
43
	rv_load_query('Q');
-
 
44
	rv_free_query();
-
 
45
	rv_load_query('P');
75
	rv_load_query('P');
46
	rv_free_query();
76
	rv_free_query();
-
 
77
freeall:
-
 
78
	rv_load_query('Q');
-
 
79
	rv_free_query();
47
	rv_close_db();
80
	rv_close_db();
48
	rv_free_auth();
81
	if(hasauth) rv_free_auth();
-
 
82
	free(type);
49
}
83
}