0
static int server_socket(const int port);
0
static int server_socket_unix(const char *path, int access_mask);
0
-#define env_add(client, field,flen,value,vlen) \
0
- client->env_fields[client->env_size] = field; \
0
- client->env_field_lengths[client->env_size] = flen; \
0
- client->env_values[client->env_size] = value; \
0
- client->env_value_lengths[client->env_size] = vlen; \
0
- client->env_size += 1;
0
-#define env_add_const(client,field,value,vlen) \
0
- client->env_fields[client->env_size] = NULL; \
0
- client->env_field_lengths[client->env_size] = field; \
0
- client->env_values[client->env_size] = value; \
0
- client->env_value_lengths[client->env_size] = vlen; \
0
- client->env_size += 1;
0
-#define env_error(client) \
0
- client->env_fields[client->env_size] = NULL; \
0
- client->env_field_lengths[client->env_size] = -1; \
0
- client->env_values[client->env_size] = NULL; \
0
- client->env_value_lengths[client->env_size] = -1; \
0
- client->env_size += 1;
0
-int env_has_error(ebb_client *client)
0
+void env_add(ebb_client *client, const char *field, int flen, const char *value, int vlen)
0
- for(i = 0; i < client->env_size; i++)
0
- if(client->env_field_lengths[i] < 0)
0
+ if(client->env_size >= EBB_MAX_ENV) {
0
+ client->parser.overflow_error = TRUE;
0
+ client->env[client->env_size].type = EBB_FIELD_VALUE_PAIR;
0
+ client->env[client->env_size].field = field;
0
+ client->env[client->env_size].field_length = flen;
0
+ client->env[client->env_size].value = value;
0
+ client->env[client->env_size].value_length = vlen;
0
+ client->env_size += 1;
0
-/** Defines common length and error messages for input length validation. */
0
-#define DEF_MAX_LENGTH(N,length) const size_t MAX_##N##_LENGTH = length; const char *MAX_##N##_LENGTH_ERR = "HTTP Parse Error: HTTP element " # N " is longer than the " # length " allowed length."
0
-/** Validates the max length of given input and throws an exception if over. */
0
-#define VALIDATE_MAX_LENGTH(len, N) if(len > MAX_##N##_LENGTH) { env_error(client); g_message(MAX_##N##_LENGTH_ERR); }
0
-/* Defines the maximum allowed lengths for various input elements.*/
0
-DEF_MAX_LENGTH(FIELD_NAME, 256);
0
-DEF_MAX_LENGTH(FIELD_VALUE, 80 * 1024);
0
-DEF_MAX_LENGTH(REQUEST_URI, 1024 * 12);
0
-DEF_MAX_LENGTH(FRAGMENT, 1024); /* Don't know if this length is specified somewhere or not */
0
-DEF_MAX_LENGTH(REQUEST_PATH, 1024);
0
-DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10));
0
-DEF_MAX_LENGTH(HEADER, (1024 * (80 + 32)));
0
+void env_add_const(ebb_client *client, int type, const char *value, int vlen)
0
+ if(client->env_size >= EBB_MAX_ENV) {
0
+ client->parser.overflow_error = TRUE;
0
+ client->env[client->env_size].type = type;
0
+ client->env[client->env_size].field = NULL;
0
+ client->env[client->env_size].field_length = -1;
0
+ client->env[client->env_size].value = value;
0
+ client->env[client->env_size].value_length = vlen;
0
+ client->env_size += 1;
0
void http_field_cb(void *data, const char *field, size_t flen, const char *value, size_t vlen)
0
ebb_client *client = (ebb_client*)(data);
0
- VALIDATE_MAX_LENGTH(flen, FIELD_NAME);
0
- VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE);
0
+ assert(field != NULL);
0
+ assert(value != NULL);
0
env_add(client, field, flen, value, vlen);
0
@@ -94,7 +80,6 @@ void request_method_cb(void *data, const char *at, size_t length)
0
void request_uri_cb(void *data, const char *at, size_t length)
0
ebb_client *client = (ebb_client*)(data);
0
- VALIDATE_MAX_LENGTH(length, REQUEST_URI);
0
env_add_const(client, EBB_REQUEST_URI, at, length);
0
@@ -102,7 +87,6 @@ void request_uri_cb(void *data, const char *at, size_t length)
0
void fragment_cb(void *data, const char *at, size_t length)
0
ebb_client *client = (ebb_client*)(data);
0
- VALIDATE_MAX_LENGTH(length, FRAGMENT);
0
env_add_const(client, EBB_FRAGMENT, at, length);
0
@@ -110,7 +94,6 @@ void fragment_cb(void *data, const char *at, size_t length)
0
void request_path_cb(void *data, const char *at, size_t length)
0
ebb_client *client = (ebb_client*)(data);
0
- VALIDATE_MAX_LENGTH(length, REQUEST_PATH);
0
env_add_const(client, EBB_REQUEST_PATH, at, length);
0
@@ -118,7 +101,6 @@ void request_path_cb(void *data, const char *at, size_t length)
0
void query_string_cb(void *data, const char *at, size_t length)
0
ebb_client *client = (ebb_client*)(data);
0
- VALIDATE_MAX_LENGTH(length, QUERY_STRING);
0
env_add_const(client, EBB_QUERY_STRING, at, length);
0
@@ -246,6 +228,7 @@ void* read_body_into_file(void *_client)
0
// g_debug("%d bytes written to file %s", written, client->upload_file_filename);
0
ebb_client_close(client);
0
@@ -264,15 +247,17 @@ void on_readable(struct ev_loop *loop, ev_io *watcher, int revents)
0
ssize_t read = recv( client->fd
0
, client->request_buffer + client->read
0
- , EBB_BUFFERSIZE - client->read //- 1 /* -1 is for making ragel happy below */
0
+ , EBB_BUFFERSIZE - client->read
0
- if(read <= 0) goto error; /* XXX is this the right action to take for read==0 ? */
0
+ if(read < 0) goto error; /* XXX is this the right action to take for read==0 ? */
0
ev_timer_again(loop, &client->timeout_watcher);
0
+ if(client->read == EBB_BUFFERSIZE) goto error;
0
if(FALSE == client_finished_parsing) {
0
- //client->request_buffer[client->read] = '\0'; /* make ragel happy */
0
http_parser_execute( &client->parser
0
, client->request_buffer
0
@@ -281,21 +266,21 @@ void on_readable(struct ev_loop *loop, ev_io *watcher, int revents)
0
if(http_parser_has_error(&client->parser)) goto error;
0
- if(total_request_size == client->read) {
0
- ev_io_stop(loop, watcher);
0
- client->nread_from_body = 0;
0
- if(client_finished_parsing && total_request_size > EBB_BUFFERSIZE ) {
0
- /* read body into file - in a thread */
0
- ev_io_stop(loop, watcher);
0
- assert(0 <= pthread_create(&thread, NULL, read_body_into_file, client));
0
- pthread_join(thread, NULL);
0
+ if(client_finished_parsing) {
0
+ if(total_request_size == client->read) {
0
+ ev_io_stop(loop, watcher);
0
+ client->nread_from_body = 0;
0
+ if(total_request_size > EBB_BUFFERSIZE ) {
0
+ /* read body into file - in a thread */
0
+ ev_io_stop(loop, watcher);
0
+ assert(0 <= pthread_create(&thread, NULL, read_body_into_file, client));
0
+ pthread_detach(thread);
0
@@ -708,5 +693,4 @@ static int server_socket_unix(const char *path, int access_mask) {
0
\ No newline at end of file