Diff

Differences From Artifact [a1927fba4d]:

To Artifact [0f86783dca]:


1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17









+







#include <sys/sendfile.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>

/* Default values */
#define MAX_FAILURE_COUNT 30
#define PORT 8080
#define THREAD_COUNT 10
94
95
96
97
98
99
100




101
102

103
104
105
106

















107










108
109




110

111
112
113
114
115
116
117
95
96
97
98
99
100
101
102
103
104
105
106
107
108




109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150







+
+
+
+


+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+


+
+
+
+
-
+







	buffer->type = "text/plain";
	buffer->lastmod = "Now";

	return(buffer);
}

static char *filed_get_http_request(FILE *fp, char *buffer, size_t buffer_len) {
	char *method, *path, *version;
	char tmpbuf[1010];
	int i;

	setlinebuf(fp);

	fgets(buffer, buffer_len, fp);
	/* XXX:TODO: Unimplemented */
	fp = fp;
	buffer = buffer;
	buffer_len = buffer_len;

	method = buffer;

	buffer = strchr(buffer, ' ');
	if (buffer == NULL) {
		return(NULL);
	}

	*buffer = '\0';
	buffer++;

	path = buffer;

	buffer = strchr(buffer, ' ');
	if (buffer != NULL) {
		*buffer = '\0';
		buffer++;

		version = buffer;
	}

	for (i = 0; i < 100; i++) {
		fgets(tmpbuf, sizeof(tmpbuf), fp);
		if (memcmp(tmpbuf, "\r\n", 2) == 0) {
			break;
		}
	}

	fflush(fp);

	/* IGNORED */
	version = version;
	method = method;

	return("./hello_world.txt");
	return(path);
}

static void filed_handle_client(int fd) {
	struct filed_fileinfo *fileinfo, fileinfo_b;
	char *path, path_b[1010];
	char *date_current;
	FILE *fp;
125
126
127
128
129
130
131

132
133
134
135
136
137
138
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172







+







		close(fd);

		return;
	}

	path = filed_get_http_request(fp, path_b, sizeof(path_b));
	if (path == NULL) {
		/* XXX: TODO: Return error page */
		fclose(fp);

		return;
	}

	fileinfo = filed_open_file(path, &fileinfo_b);
	if (fileinfo == NULL) {