Subversion Repositories Tewi

Rev

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

Rev 104 Rev 118
Line 1... Line 1...
1
/* $Id: http.c 104 2024-09-19 15:16:52Z nishi $ */
1
/* $Id: http.c 118 2024-09-21 09:03:27Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 16... Line 16...
16
#include <string.h>
16
#include <string.h>
17
 
17
 
18
#ifdef __MINGW32__
18
#ifdef __MINGW32__
19
#include <winsock2.h>
19
#include <winsock2.h>
20
#else
20
#else
-
 
21
#ifdef USE_POLL
-
 
22
#include <poll.h>
-
 
23
#else
21
#include <sys/select.h>
24
#include <sys/select.h>
22
#endif
25
#endif
-
 
26
#endif
23
 
27
 
24
void tw_free_request(struct tw_http_request* req) {
28
void tw_free_request(struct tw_http_request* req) {
25
	if(req->method != NULL) free(req->method);
29
	if(req->method != NULL) free(req->method);
26
	if(req->path != NULL) free(req->path);
30
	if(req->path != NULL) free(req->path);
27
	if(req->query != NULL) free(req->query);
31
	if(req->query != NULL) free(req->query);
Line 43... Line 47...
43
 
47
 
44
int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req) {
48
int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req) {
45
	char buffer[512];
49
	char buffer[512];
46
	char cbuf[2];
50
	char cbuf[2];
47
	int phase = 0;
51
	int phase = 0;
-
 
52
 
-
 
53
#ifdef USE_POLL
-
 
54
	struct pollfd pollfds[1];
-
 
55
	pollfds[0].fd = sock;
-
 
56
	pollfds[0].events = POLLIN | POLLPRI;
-
 
57
#else
48
	fd_set fds;
58
	fd_set fds;
-
 
59
#endif
49
 
60
 
50
	bool bad = false;
61
	bool bad = false;
51
 
62
 
52
	cbuf[1] = 0;
63
	cbuf[1] = 0;
53
 
64
 
Line 61... Line 72...
61
	char* header = malloc(1);
72
	char* header = malloc(1);
62
	header[0] = 0;
73
	header[0] = 0;
63
	int nl = 0;
74
	int nl = 0;
64
 
75
 
65
	while(1) {
76
	while(1) {
-
 
77
#ifndef USE_POLL
66
		FD_ZERO(&fds);
78
		FD_ZERO(&fds);
67
		FD_SET(sock, &fds);
79
		FD_SET(sock, &fds);
68
		struct timeval tv;
80
		struct timeval tv;
69
		tv.tv_sec = 5;
81
		tv.tv_sec = 5;
70
		tv.tv_usec = 0;
82
		tv.tv_usec = 0;
-
 
83
#endif
71
#ifndef NO_SSL
84
#ifndef NO_SSL
72
		if(ssl == NULL || !SSL_has_pending(ssl)) {
85
		if(ssl == NULL || !SSL_has_pending(ssl)) {
73
#endif
86
#endif
-
 
87
#ifdef USE_POLL
-
 
88
			int n = poll(pollfds, 1, 5000);
-
 
89
#else
74
#ifdef __HAIKU__
90
#ifdef __HAIKU__
75
			int n = select(32, &fds, NULL, NULL, &tv);
91
		int n = select(32, &fds, NULL, NULL, &tv);
76
#else
92
#else
77
		int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
93
		int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
78
#endif
94
#endif
-
 
95
#endif
79
			if(n <= 0) {
96
			if(n <= 0) {
80
				cm_log("HTTP", "Timeout, disconncting");
97
				cm_log("HTTP", "Timeout, disconncting");
81
				free(header);
98
				free(header);
82
				tw_free_request(req);
99
				tw_free_request(req);
83
				return -1;
100
				return -1;