pthread_setspecific(mk_cache_iov_log, (void *) cache_iov_log);
/* Cache iov header struct */
- cache_iov_header = mk_iov_create(45, 0);
+ cache_iov_header = mk_iov_create(32, 0);
pthread_setspecific(mk_cache_iov_header, (void *) cache_iov_header);
/* Cache header toc, monkey just search for MK_KNOWN_HEADERS
if (sh->ranges[0] >= 0 && sh->ranges[1] == -1) {
length = (unsigned int)
(sh->content_length - sh->ranges[0]);
- m_build_buffer(&buffer, &len, "%s%i", RH_CONTENT_LENGTH, length);
+ m_build_buffer(&buffer, &len, "%s %i", RH_CONTENT_LENGTH, length);
mk_iov_add_entry(iov, buffer, len, mk_iov_crlf, MK_IOV_FREE_BUF);
m_build_buffer(&buffer,
}
}
else if (sh->content_length >= 0) {
- mk_iov_add_entry(iov, mk_rh_content_length.data,
- mk_rh_content_length.len,
+ mk_iov_add_entry(iov, mk_header_content_length.data,
+ mk_header_content_length.len,
mk_iov_none, MK_IOV_NOT_FREE_BUF);
mk_iov_add_entry(iov, sh->content_length_p.data,
mk_socket_set_cork_flag(fd, TCP_CORK_ON);
mk_iov_send(fd, iov, MK_IOV_SEND_TO_SOCKET);
-
+
#ifdef DEBUG_HEADERS_OUT
mk_iov_send(0, iov, MK_IOV_SEND_TO_SOCKET);
#endif
#include "memory.h"
#include "str.h"
#include "config.h"
-#include "monkey.h"
#include "request.h"
+#include "monkey.h"
/* Carga en estructura los mimetypes */
void mk_mimetype_read_config()
{
- char path[MAX_PATH];
- struct mk_config *c;
+ char buffer[255], path[MAX_PATH];
+ char *name = 0, *type = 0, *last = 0;
+ FILE *mime_file;
snprintf(path, MAX_PATH, "%s/monkey.mime", config->serverconf);
- /* Read configuration file */
- c = mk_config_create(path);
+ if ((mime_file = fopen(path, "r")) == NULL) {
+ puts("Error: I can't open monkey.mime file");
+ exit(1);
+ }
- while (c) {
- if (mk_mimetype_add(c->key, c->val, NULL) != 0) {
- puts("Error loading Mime Types");
+ /* Rutina que carga en memoria los mime types */
+ while (fgets(buffer, 255, mime_file)) {
+ int len;
+ len = strlen(buffer);
+ if (buffer[len - 1] == '\n') {
+ buffer[--len] = 0;
+ if (len && buffer[len - 1] == '\r')
+ buffer[--len] = 0;
}
- c = c->next;
- }
- /* Free configuration */
- mk_config_free(c);
+ name = strtok_r(buffer, "\"\t ", &last);
+ type = strtok_r(NULL, "\"\t ", &last);
+
+ if (!name || !type)
+ continue;
+ if (buffer[0] == '#')
+ continue;
+
+ if (mk_mimetype_add(name, type, NULL) != 0)
+ puts("Error loading Mime Types");
+ }
+ fclose(mime_file);
/* Set default mime type */
mimetype_default = mk_mem_malloc_z(sizeof(struct mimetype));
new_mime = mk_mem_malloc_z(sizeof(struct mimetype));
- new_mime->name = name;
+ new_mime->name = mk_string_dup(name);
- len = strlen(name) + 2;
+ len = strlen(type) + 2;
new_mime->type.data = mk_mem_malloc(len);
- strcat(new_mime->type.data, MK_CRLF);
new_mime->type.len = len;
+ strcpy(new_mime->type.data, type);
+ strcat(new_mime->type.data, MK_CRLF);
+
+ //mk_pointer_set(&new_mime->type, mk_string_dup(type));
new_mime->script_bin_path = mk_string_dup(bin_path);
new_mime->next = NULL;