--- libaitwww/src/mime.c 2012/08/01 00:40:41 1.4 +++ libaitwww/src/mime.c 2013/05/30 09:25:35 1.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: mime.c,v 1.4 2012/08/01 00:40:41 misho Exp $ +* $Id: mime.c,v 1.5 2013/05/30 09:25:35 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -68,9 +68,9 @@ bd_begin(const char *str) char *s; int len = strlen(str) + 6; - s = io_malloc(len + 1); + s = e_malloc(len + 1); if (!s) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { snprintf(s, len + 1, "\r\n--%s\r\n", str); @@ -86,9 +86,9 @@ bd_end(const char *str) char *s; int len = strlen(str) + 8; - s = io_malloc(len + 1); + s = e_malloc(len + 1); if (!s) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { snprintf(s, len + 1, "\r\n--%s--\r\n", str); @@ -150,11 +150,11 @@ freeHeader(struct tagMIME * __restrict m) struct tagCGI *c; while ((c = SLIST_FIRST(&m->mime_header))) { - io_freeVar(&c->cgi_name); - io_freeVar(&c->cgi_value); + ait_freeVar(&c->cgi_name); + ait_freeVar(&c->cgi_value); SLIST_REMOVE_HEAD(&m->mime_header, cgi_node); - io_free(c); + e_free(c); } } @@ -173,10 +173,10 @@ hdrValue(const char *str, size_t len, const char **end return NULL; } - tmp = io_realloc(s, crlf - str + off + 1); + tmp = e_realloc(s, crlf - str + off + 1); if (!tmp) { - LOGERR; - io_free(s); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + e_free(s); return NULL; } else s = tmp; @@ -194,10 +194,10 @@ hdrValue(const char *str, size_t len, const char **end } *end = crlf + strlen(CRLF); - ret = io_makeVar(string, s); + ret = ait_makeVar(string, s); if (!ret) - www_SetErr(io_GetErrno(), "%s", io_GetError()); - io_free(s); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + e_free(s); return ret; } @@ -340,9 +340,9 @@ mime_parseMultiPart(const char *str, size_t len, const } /* init MIME */ - mime = io_malloc(sizeof(mime_t)); + mime = e_malloc(sizeof(mime_t)); if (!mime) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); return NULL; } else { memset(mime, 0, sizeof(mime_t)); @@ -352,14 +352,14 @@ mime_parseMultiPart(const char *str, size_t len, const /* prepare boundary format */ bd[0].iov_base = bd_begin(bdtag); if (!bd[0].iov_base) { - io_free(mime); + e_free(mime); return NULL; } else bd[0].iov_len = strlen(bd[0].iov_base); bd[1].iov_base = bd_end(bdtag); if (!bd[1].iov_base) { - io_free(bd[0].iov_base); - io_free(mime); + e_free(bd[0].iov_base); + e_free(mime); return NULL; } else bd[1].iov_len = strlen(bd[1].iov_base); @@ -367,9 +367,9 @@ mime_parseMultiPart(const char *str, size_t len, const /* check boundary tag */ if (memcmp(str, strstr(bd[0].iov_base, "--"), strlen(strstr(bd[0].iov_base, "--")))) { www_SetErr(EFAULT, "Bad content data, not found boundary tag"); - io_free(bd[1].iov_base); - io_free(bd[0].iov_base); - io_free(mime); + e_free(bd[1].iov_base); + e_free(bd[0].iov_base); + e_free(mime); return NULL; } else { str += strlen(strstr(bd[0].iov_base, "--")); @@ -377,12 +377,12 @@ mime_parseMultiPart(const char *str, size_t len, const } while (len > 0) { - m = io_malloc(sizeof(struct tagMIME)); + m = e_malloc(sizeof(struct tagMIME)); if (!m) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); mime_close(&mime); - io_free(bd[1].iov_base); - io_free(bd[0].iov_base); + e_free(bd[1].iov_base); + e_free(bd[0].iov_base); return NULL; } else { memset(m, 0, sizeof(struct tagMIME)); @@ -395,8 +395,8 @@ mime_parseMultiPart(const char *str, size_t len, const /* parse message between tags */ if (mime_readPart(m, str, next - str)) { mime_close(&mime); - io_free(bd[1].iov_base); - io_free(bd[0].iov_base); + e_free(bd[1].iov_base); + e_free(bd[0].iov_base); return NULL; } @@ -424,8 +424,8 @@ mime_parseMultiPart(const char *str, size_t len, const len -= bd[0].iov_len; */ - io_free(bd[1].iov_base); - io_free(bd[0].iov_base); + e_free(bd[1].iov_base); + e_free(bd[0].iov_base); if (end) *end = str; @@ -436,11 +436,11 @@ static inline void freeMIME(struct tagMIME * __restrict m) { if (m->mime_body.iov_base) - io_free(m->mime_body.iov_base); + e_free(m->mime_body.iov_base); if (m->mime_prolog.iov_base) - io_free(m->mime_prolog.iov_base); + e_free(m->mime_prolog.iov_base); if (m->mime_epilog.iov_base) - io_free(m->mime_epilog.iov_base); + e_free(m->mime_epilog.iov_base); freeHeader(m); mime_close(&m->mime_attach); @@ -463,10 +463,10 @@ mime_close(mime_t ** __restrict mime) while ((m = SLIST_FIRST(*mime))) { SLIST_REMOVE_HEAD(*mime, mime_node); freeMIME(m); - io_free(m); + e_free(m); } - io_free(*mime); + e_free(*mime); *mime = NULL; } @@ -505,17 +505,17 @@ mime_parseHeader(struct tagMIME * __restrict m, const return -1; } - c = io_malloc(sizeof(struct tagCGI)); + c = e_malloc(sizeof(struct tagCGI)); if (!c) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); freeHeader(m); return -1; } /* get name */ - c->cgi_name = io_allocVar(); + c->cgi_name = ait_allocVar(); if (!c->cgi_name) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); - io_free(c); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); + e_free(c); freeHeader(m); return -1; } else @@ -548,7 +548,7 @@ mime_parseHeader(struct tagMIME * __restrict m, const * @name = Header name * return: NULL not found or !=NULL value */ -inline const char * +const char * mime_getValue(struct tagMIME * __restrict m, const char *name) { struct tagCGI *c; @@ -587,9 +587,9 @@ mime_readPart(struct tagMIME * __restrict m, const cha ct = mime_getValue(m, "content-type"); if (!ct || www_cmptype(ct, "multipart")) { /* not multi part, assign like body element */ - m->mime_body.iov_base = io_malloc(len - (eoh - str) + 1); + m->mime_body.iov_base = e_malloc(len - (eoh - str) + 1); if (!m->mime_body.iov_base) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); freeHeader(m); return -1; } @@ -607,13 +607,13 @@ mime_readPart(struct tagMIME * __restrict m, const cha bd.iov_base = bd_begin(AIT_GET_STR(v)); bd.iov_len = strlen(bd.iov_base); eb = findtextpos(eoh, len - (eoh - str), bd.iov_base, bd.iov_len); - io_free(bd.iov_base); + e_free(bd.iov_base); /* set prolog if exists */ if (eb != eoh) { - m->mime_prolog.iov_base = io_malloc(eb - eoh + 1); + m->mime_prolog.iov_base = e_malloc(eb - eoh + 1); if (!m->mime_prolog.iov_base) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); www_freeAttributes(&attr); freeHeader(m); return -1; @@ -629,9 +629,9 @@ mime_readPart(struct tagMIME * __restrict m, const cha /* set epilog if exists */ if (eoh - str < len) { - m->mime_epilog.iov_base = io_malloc(len - (eoh - str) + 1); + m->mime_epilog.iov_base = e_malloc(len - (eoh - str) + 1); if (!m->mime_epilog.iov_base) { - www_SetErr(io_GetErrno(), "%s", io_GetError()); + www_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); www_freeAttributes(&attr); freeHeader(m); return -1;