Subversion Repositories Tewi

Rev

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

Rev 17 Rev 20
Line 1... Line 1...
1
/* $Id: http.c 17 2024-09-13 17:41:07Z nishi $ */
1
/* $Id: http.c 20 2024-09-14 09:59:15Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_http.h"
5
#include "tw_http.h"
6
 
6
 
Line 20... Line 20...
20
#endif
20
#endif
21
 
21
 
22
void tw_free_request(struct tw_http_request* req) {
22
void tw_free_request(struct tw_http_request* req) {
23
	if(req->method != NULL) free(req->method);
23
	if(req->method != NULL) free(req->method);
24
	if(req->path != NULL) free(req->path);
24
	if(req->path != NULL) free(req->path);
-
 
25
	if(req->query != NULL) free(req->query);
25
	if(req->headers != NULL) {
26
	if(req->headers != NULL) {
26
		int i;
27
		int i;
27
		for(i = 0; req->headers[i] != NULL; i++) free(req->headers[i]);
28
		for(i = 0; req->headers[i] != NULL; i++) free(req->headers[i]);
28
		free(req->headers);
29
		free(req->headers);
29
	}
30
	}
Line 41... Line 42...
41
 
42
 
42
	cbuf[1] = 0;
43
	cbuf[1] = 0;
43
 
44
 
44
	req->method = NULL;
45
	req->method = NULL;
45
	req->path = NULL;
46
	req->path = NULL;
-
 
47
	req->query = NULL;
46
	req->headers = NULL;
48
	req->headers = NULL;
47
	req->body = NULL;
49
	req->body = NULL;
48
	req->version = NULL;
50
	req->version = NULL;
49
 
51
 
50
	char* header = malloc(1);
52
	char* header = malloc(1);
Line 243... Line 245...
243
	free(header);
245
	free(header);
244
	if(bad) {
246
	if(bad) {
245
		tw_free_request(req);
247
		tw_free_request(req);
246
		return 1;
248
		return 1;
247
	}
249
	}
-
 
250
	char* result = malloc(1);
-
 
251
	result[0] = 0;
-
 
252
	int i;
-
 
253
	for(i = 0; req->path[i] != 0; i++) {
-
 
254
		if(req->path[i] == '?') {
-
 
255
			req->path[i] = 0;
-
 
256
			req->query = cm_strdup(req->path + i + 1);
-
 
257
			break;
-
 
258
		}
-
 
259
	}
-
 
260
	for(i = 0; req->path[i] != 0; i++) {
-
 
261
		if(req->path[i] == '%') {
-
 
262
			if(req->path[i + 1] == 0) continue;
-
 
263
			cbuf[0] = cm_hex(req->path + i + 1, 2);
-
 
264
			char* tmp = result;
-
 
265
			result = cm_strcat(tmp, cbuf);
-
 
266
			free(tmp);
-
 
267
			i += 2;
-
 
268
		} else {
-
 
269
			cbuf[0] = req->path[i];
-
 
270
			char* tmp = result;
-
 
271
			result = cm_strcat(tmp, cbuf);
-
 
272
			free(tmp);
-
 
273
		}
-
 
274
	}
-
 
275
	free(req->path);
-
 
276
	req->path = result;
248
	return 0;
277
	return 0;
249
}
278
}