Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Code clean-up.

  • Loading branch information...
commit 630c28314139095e138ac685c5c4ddd2e04e593d 1 parent 9d9a155
@iafonov authored
View
9 src/http_request.c
@@ -22,7 +22,8 @@ typedef void (*free_body_parser) (void *);
struct http_request_state {
void *body_processor;
free_body_parser free_body_parser_func;
- char * _last_header_name;
+
+ char *last_header_name;
int parsed;
int content_length;
int socket_fd;
@@ -81,7 +82,7 @@ static int request_url_cb(http_parser *p, const char *buf, size_t len) {
static int header_field_cb(http_parser *p, const char *buf, size_t len) {
http_request *request = (http_request *)p->data;
- request->_s->_last_header_name = extract_from_buffer(buf, len);
+ request->_s->last_header_name = extract_from_buffer(buf, len);
return 0;
}
@@ -89,8 +90,8 @@ static int header_value_cb(http_parser *p, const char *buf, size_t len) {
http_request *request = (http_request *)p->data;
char *header_value = extract_from_buffer(buf, len);
- headers_map_add(request->headers, request->_s->_last_header_name, header_value);
- free(request->_s->_last_header_name);
+ headers_map_add(request->headers, request->_s->last_header_name, header_value);
+ free(request->_s->last_header_name);
free(header_value);
return 0;
}
View
22 src/mpart_body_processor.c
@@ -37,7 +37,7 @@ static char *copy_chunk_from_buffer(const char *buf, size_t len) {
static int header_field_cb(multipart_parser *p, const char *buf, size_t len) {
mpart_body_processor *processor = (mpart_body_processor *)p->data;
- processor->_last_header_name = copy_chunk_from_buffer(buf, len);
+ processor->last_header_name = copy_chunk_from_buffer(buf, len);
return 0;
}
@@ -46,8 +46,8 @@ static int header_value_cb(multipart_parser *p, const char *buf, size_t len) {
mpart_body_processor *processor = (mpart_body_processor *)p->data;
char *header_value = copy_chunk_from_buffer(buf, len);
- headers_map_add(processor->part_headers, processor->_last_header_name, header_value);
- free(processor->_last_header_name);
+ headers_map_add(processor->part_headers, processor->last_header_name, header_value);
+ free(processor->last_header_name);
free(header_value);
return 0;
@@ -65,12 +65,11 @@ static int headers_complete_cb(multipart_parser *p) {
char *name = attrs_map_get(cd_attrs_map, "name");
char *filename = attrs_map_get(cd_attrs_map, "filename");
- info("BEFORE %s", filename);
- str_sanitize(filename);
- info("AFTER %s", filename);
bool is_file = (filename != NULL);
- processor->_current_param = param_entry_init(name, NULL, is_file);
+ str_sanitize(filename);
+
+ processor->current_param = param_entry_init(name, NULL, is_file);
if (is_file) {
char *upload_folder_path = http_request_uploads_path(request);
@@ -79,7 +78,7 @@ static int headers_complete_cb(multipart_parser *p) {
char *file_path = malloc_str(strlen(upload_folder_path) + strlen("/") + strlen(filename));
sprintf(file_path, "%s/%s", upload_folder_path, filename);
- processor->_current_param->file = fopen(file_path, "a");
+ processor->current_param->file = fopen(file_path, "a");
free(upload_folder_path);
free(file_path);
@@ -93,7 +92,7 @@ static int headers_complete_cb(multipart_parser *p) {
static int part_data_cb(multipart_parser *p, const char *buf, size_t len) {
if (len != 0) {
mpart_body_processor *processor = (mpart_body_processor *)p->data;
- param_entry_append(processor->_current_param, buf, len);
+ param_entry_append(processor->current_param, buf, len);
}
return 0;
}
@@ -109,7 +108,7 @@ static int part_data_end_cb(multipart_parser *p) {
mpart_body_processor *processor = (mpart_body_processor *)p->data;
http_request *request = (http_request *)processor->request;
- params_map_add(request->params, processor->_current_param);
+ params_map_add(request->params, processor->current_param);
headers_map_free(processor->part_headers);
return 0;
@@ -133,7 +132,6 @@ static char *get_boundary(http_request *request) {
return boundary;
}
-// public api
mpart_body_processor *mpart_body_processor_init(http_request *request) {
mpart_body_processor *processor = malloc(sizeof(mpart_body_processor));
char *boundary = get_boundary(request);
@@ -141,7 +139,7 @@ mpart_body_processor *mpart_body_processor_init(http_request *request) {
processor->request = request;
processor->parser = init_multipart_parser(boundary, &settings);
processor->parser->data = processor;
- processor->_current_param = NULL;
+ processor->current_param = NULL;
free(boundary);
return processor;
View
4 src/mpart_body_processor.h
@@ -12,8 +12,8 @@ typedef struct mpart_body_processor {
// headers of current part - don't try to use it outside callbacks it's reset on every part
headers_map *part_headers;
- char * _last_header_name;
- param_entry * _current_param;
+ char *last_header_name;
+ param_entry *current_param;
} mpart_body_processor;
mpart_body_processor *mpart_body_processor_init(http_request *request);
View
2  src/net.c
@@ -18,7 +18,7 @@ static void reset_hints(struct addrinfo *hints, int ai_flags) {
memset(hints, 0, sizeof *hints);
hints->ai_family = AF_UNSPEC; // v4/v6
hints->ai_socktype = SOCK_STREAM; // TCP stream sockets
- hints->ai_flags = ai_flags; // fill in my IP for me
+ hints->ai_flags = ai_flags; // fill in my IP for me
}
static void *get_in_addr(struct sockaddr *sa) {
View
1  src/routing_engine.c
@@ -21,5 +21,4 @@ void routing_engine_execute_action(http_request *request, http_response *respons
}
free(relative_file_path);
-
}

0 comments on commit 630c283

Please sign in to comment.
Something went wrong with that request. Please try again.