diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-03-01 23:08:32 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-03-01 23:08:32 +0000 |
commit | 7128853094a3df29948dc949ff04b43cccd400f7 (patch) | |
tree | 69db0978e6b835b7a736490a06a4307b1e32aa0c /gacopyz/gacopyz.c | |
parent | c6eecf2842218ed97a7084fbecae06388ec358f3 (diff) | |
download | mailfromd-7128853094a3df29948dc949ff04b43cccd400f7.tar.gz mailfromd-7128853094a3df29948dc949ff04b43cccd400f7.tar.bz2 |
Start implementing test MTA simulator and Gacopyz server code
git-svn-id: file:///svnroot/mailfromd/trunk@1269 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'gacopyz/gacopyz.c')
-rw-r--r-- | gacopyz/gacopyz.c | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/gacopyz/gacopyz.c b/gacopyz/gacopyz.c index ae337941..d88a2496 100644 --- a/gacopyz/gacopyz.c +++ b/gacopyz/gacopyz.c @@ -1,5 +1,5 @@ /* This file is part of gacopyz. - Copyright (C) 2006 Sergey Poznyakoff + Copyright (C) 2006, 2007 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,6 +18,14 @@ #include <gacopyz_priv.h> +#define TRACE(conn,cmd,size,buf) do { \ + gacopyz_log(conn, SMI_LOG_DEBUG, \ + "send header: size=%lu, cmd=%c", \ + size, cmd); \ + gacopyz_logdump(conn, SMI_LOG_DEBUG, \ + "send data", buf, size); \ +} while (0) + int gacopyz_init(gacopyz_conn_t *pconn, struct smfiDesc *desc) { @@ -63,10 +71,9 @@ gacopyz_free(gacopyz_conn_t conn) free(conn); } -static int -parse_connection(gacopyz_conn_t conn, - const char *cstr, - char **pproto, char **pport, char **ppath) +int +gacopyz_parse_connection(const char *cstr, + char **pproto, char **pport, char **ppath) { const char *p; size_t len; @@ -77,11 +84,8 @@ parse_connection(gacopyz_conn_t conn, else { len = p - cstr; *pproto = malloc(len + 1); - if (!*pproto) { - gacopyz_log(conn, SMI_LOG_ERR, - "parse_connection: not enough memory"); + if (!*pproto) return MI_FAILURE; - } memcpy(*pproto, cstr, len); (*pproto)[len] = 0; @@ -96,8 +100,6 @@ parse_connection(gacopyz_conn_t conn, *pport = malloc(len + 1); if (!*pport) { free(*pproto); - gacopyz_log(conn, SMI_LOG_ERR, - "parse_connection: not enough memory"); return MI_FAILURE; } memcpy(*pport, cstr, len); @@ -111,13 +113,25 @@ parse_connection(gacopyz_conn_t conn, free(*pproto); free(*pport); free(*ppath); - gacopyz_log(conn, SMI_LOG_ERR, - "parse_connection: not enough memory"); return MI_FAILURE; } return MI_SUCCESS; } + +static int +parse_connection(gacopyz_conn_t conn, + const char *cstr, + char **pproto, char **pport, char **ppath) +{ + int rc = gacopyz_parse_connection(cstr, pproto, pport, ppath); + if (rc) + gacopyz_log(conn, SMI_LOG_ERR, + "parse_connection: not enough memory"); + return rc; + +} + static int do_connect(gacopyz_conn_t conn, const char *cstr, char *proto, char *port, char *path, @@ -244,6 +258,11 @@ do_connect(gacopyz_conn_t conn, return -1; } } + } else { + gacopyz_log(conn, SMI_LOG_ERR, + "%s: unsupported protocol: %s", + conn->desc.xxfi_name, proto); + return -1; } fd = socket(addr.sa.sa_family, SOCK_STREAM, 0); @@ -641,7 +660,7 @@ send_reply(SMFICTX *ctx, unsigned char cmd) gacopyz_uint32_t v[3]; v[0] = htonl(ctx->conn->desc.xxfi_version); v[1] = htonl(ctx->conn->desc.xxfi_flags); - v[2] = htonl(ctx->flags); + v[2] = htonl(ctx->flags); buf = (char*) v; bufsize = sizeof v; break; @@ -651,6 +670,8 @@ send_reply(SMFICTX *ctx, unsigned char cmd) break; } + TRACE(ctx->conn, cmd, bufsize, buf); + header.hdr.size = htonl(bufsize + 1); header.hdr.cmd = cmd; rc = ctx_write(ctx, header.buf, sizeof header.buf); @@ -1416,7 +1437,7 @@ gacopyz_stop(gacopyz_conn_t conn) conn->stop = 1; return MI_SUCCESS; } - + static int gacopyz_header_command(SMFICTX *ctx, unsigned char cmd, int idx, const char *headerf, @@ -1449,6 +1470,9 @@ gacopyz_header_command(SMFICTX *ctx, unsigned char cmd, cptr += lenf; memcpy(cptr, headerv, lenv); cptr += lenv; + + TRACE(ctx->conn, cmd, bufsize, buf); + hptr->hdr.cmd = cmd; hptr->hdr.size = htonl(bufsize + 1); rc = ctx_write(ctx, buf, sizeof hptr->buf + bufsize); @@ -1474,6 +1498,9 @@ gacopyz_rcpt_command(SMFICTX *ctx, unsigned char cmd, const char *rcpt) hptr = (union header *) buf; cptr = buf + sizeof hptr->buf; strcpy(cptr, rcpt); + + TRACE(ctx->conn, cmd, bufsize, buf); + hptr->hdr.cmd = cmd; hptr->hdr.size = htonl(bufsize + 1); rc = ctx_write(ctx, buf, sizeof hptr->buf + bufsize); @@ -1554,6 +1581,9 @@ gacopyz_replace_body(SMFICTX *ctx, unsigned char *bodyp, size_t bodylen) while (bodylen) { size_t size = (bodylen >= GACOPYZ_CHUNK_SIZE) ? GACOPYZ_CHUNK_SIZE : bodylen; + + TRACE(ctx->conn, hptr->hdr.cmd, size, buf); + hptr->hdr.size = htonl(size + 1); memcpy(buf + sizeof hptr->buf, bodyp, size); if (ctx_write(ctx, buf, sizeof hptr->buf + size)) @@ -1570,6 +1600,7 @@ gacopyz_progress(SMFICTX *ctx) union header hdr; hdr.hdr.cmd = SMFIR_PROGRESS; hdr.hdr.size = htonl(1); + TRACE(ctx->conn, hdr.hdr.cmd, 0, NULL); return ctx_write(ctx, hdr.buf, sizeof hdr.buf); } |