Browse Source

use quick fit approach in message

release0.1.5
Georg Hopp 12 years ago
parent
commit
c54dc20cc4
  1. 6
      src/http/message.c
  2. 4
      src/http/parser/p_header.c
  3. 2
      src/http/response/404.c
  4. 2
      src/http/response/login_form.c
  5. 2
      src/http/response/randval.c
  6. 2
      src/http/response/session.c

6
src/http/message.c

@ -43,7 +43,7 @@ httpMessageCtor(void * _this, va_list * params)
HttpMessage this = _this; HttpMessage this = _this;
char * version = va_arg(* params, char *); char * version = va_arg(* params, char *);
this->version = calloc(1, strlen(version)+1);
this->version = memCalloc(1, strlen(version)+1);
strcpy(this->version, version); strcpy(this->version, version);
this->header = new(Hash); this->header = new(Hash);
@ -59,11 +59,11 @@ httpMessageDtor(void * _this)
delete(this->header); delete(this->header);
FREE(this->version);
MEM_FREE(this->version);
switch (this->type) { switch (this->type) {
case HTTP_MESSAGE_BUFFERED: case HTTP_MESSAGE_BUFFERED:
FREE(this->body);
MEM_FREE(this->body);
break; break;
case HTTP_MESSAGE_PIPED: case HTTP_MESSAGE_PIPED:

4
src/http/parser/p_header.c

@ -31,6 +31,8 @@
#include "http/request.h" #include "http/request.h"
#include "hash.h" #include "hash.h"
#include "utils/memory.h"
void void
httpParserHeader( httpParserHeader(
HttpParser this, HttpParser this,
@ -55,7 +57,7 @@ httpParserHeader(
if (0 == strncasecmp("content-length", name, nname-1)) { if (0 == strncasecmp("content-length", name, nname-1)) {
current->nbody = strtoul(value, NULL, 10); current->nbody = strtoul(value, NULL, 10);
if (0 < this->current->nbody) { if (0 < this->current->nbody) {
current->body = malloc(current->nbody);
current->body = memMalloc(current->nbody);
} }
current->dbody = 0; current->dbody = 0;
} }

2
src/http/response/404.c

@ -57,7 +57,7 @@ httpResponse404()
message->type = HTTP_MESSAGE_BUFFERED; message->type = HTTP_MESSAGE_BUFFERED;
message->nbody = sizeof(RESP_DATA) - 1; message->nbody = sizeof(RESP_DATA) - 1;
message->body = malloc(sizeof(RESP_DATA));
message->body = memMalloc(sizeof(RESP_DATA));
memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)); memcpy(message->body, RESP_DATA, sizeof(RESP_DATA));
return response; return response;

2
src/http/response/login_form.c

@ -55,7 +55,7 @@ httpResponseLoginForm()
message->type = HTTP_MESSAGE_BUFFERED; message->type = HTTP_MESSAGE_BUFFERED;
message->nbody = sizeof(RESP_DATA)-1; message->nbody = sizeof(RESP_DATA)-1;
message->body = malloc(message->nbody);
message->body = memMalloc(message->nbody);
memcpy(message->body, RESP_DATA, message->nbody); memcpy(message->body, RESP_DATA, message->nbody);
return response; return response;

2
src/http/response/randval.c

@ -59,7 +59,7 @@ httpResponseRandval(time_t ctime, int value)
nbuf = sprintf(buffer, RESP_DATA, ctime, remaining, value); nbuf = sprintf(buffer, RESP_DATA, ctime, remaining, value);
message->nbody = nbuf; message->nbody = nbuf;
message->body = malloc(nbuf);
message->body = memMalloc(nbuf);
memcpy(message->body, buffer, nbuf); memcpy(message->body, buffer, nbuf);
return response; return response;

2
src/http/response/session.c

@ -61,7 +61,7 @@ httpResponseSession(Session session)
(NULL != session)? session->username : ""); (NULL != session)? session->username : "");
message->nbody = nbuf; message->nbody = nbuf;
message->body = malloc(nbuf);
message->body = memMalloc(nbuf);
memcpy(message->body, buffer, nbuf); memcpy(message->body, buffer, nbuf);
return response; return response;

Loading…
Cancel
Save