From b58ff0886b560045445c1323b71f31a8dd8d7165 Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 9 Dec 2011 15:24:15 +0100 Subject: [PATCH] digest fixes --- src/digest.c | 28 +++++++++++++++------------- src/parser_utils.c | 3 ++- src/session.c | 1 + 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/digest.c b/src/digest.c index e99c2eb4..ae7e862c 100644 --- a/src/digest.c +++ b/src/digest.c @@ -15,8 +15,8 @@ int make_body_digest(struct session_data *sdata, struct __config *cfg){ - int i=0, n, fd, hdr_len=0, offset=3; - char *body=NULL; + int i=0, n, fd, offset=3; + char *p, *body=NULL; unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH]; SHA256_CTX context; @@ -29,25 +29,27 @@ int make_body_digest(struct session_data *sdata, struct __config *cfg){ if(fd == -1) return -1; while((n = read(fd, buf, sizeof(buf))) > 0){ + body = (char *)&buf[0]; if(i == 0){ - hdr_len = searchStringInBuffer(body, sizeof(buf), "\n\r\n", 3); - if(hdr_len == 0){ - searchStringInBuffer(body, sizeof(buf), "\n\n", 2); - offset = 2; + p = strstr(body, "\n\r\n"); + if(!p){ + p = strstr(body, "\n\n"); + if(p){ + offset = 2; + + } } - if(hdr_len > 0){ - hdr_len += offset; + if(p){ + sdata->hdr_len = p - body + offset; + body += sdata->hdr_len; - sdata->hdr_len = hdr_len; + n -= sdata->hdr_len; - body += hdr_len; - n -= hdr_len; - - if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: hdr_len: %d, offset: %d", sdata->ttmpfile, hdr_len, offset); + if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: hdr_len: %d, offset: %d", sdata->ttmpfile, sdata->hdr_len, offset); } } diff --git a/src/parser_utils.c b/src/parser_utils.c index 9b996f66..3b0fbf89 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -468,7 +468,8 @@ void translateLine(unsigned char *p, struct _state *state){ if(delimiter_characters[(unsigned int)*p] != ' ') *p = ' '; else { - *p = tolower(*p); + // commented out because it breaks utf-8 encoding, 2011.12.07. + //*p = tolower(*p); } } diff --git a/src/session.c b/src/session.c index 07fcdadb..82e46e4a 100644 --- a/src/session.c +++ b/src/session.c @@ -54,6 +54,7 @@ void handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ if(mysql_real_connect(&(sdata.mysql), cfg->mysqlhost, cfg->mysqluser, cfg->mysqlpwd, cfg->mysqldb, cfg->mysqlport, cfg->mysqlsocket, 0)){ db_conn = 1; mysql_real_query(&(sdata.mysql), "SET NAMES utf8", strlen("SET NAMES utf8")); + mysql_real_query(&(sdata.mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8")); } else syslog(LOG_PRIORITY, "%s", ERR_MYSQL_CONNECT);