]> git.mikk.net Git - smtpsink/commitdiff
After a few scattered changes, it all compiles and links.
authorchris mikkelson <chris@mikk.net>
Wed, 25 Mar 2009 03:06:28 +0000 (22:06 -0500)
committerchris mikkelson <chris@mikk.net>
Wed, 25 Mar 2009 03:06:28 +0000 (22:06 -0500)
Makefile [new file with mode: 0644]
conn_pool.c
io.c
smtp.c
smtpsink-int.h
smtpsink.c

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..d7e6048
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,25 @@
+CFLAGS=-g -Wall -I/usr/local/include
+
+SMTPSINK_OBJS=conn_pool.o conn_queue.o io.o smtp.o smtpsink.o
+
+default: smtpsink
+
+smtpsink: $(SMTPSINK_OBJS)
+       cc -o smtpsink $(SMTPSINK_OBJS) -L/usr/local/lib -levent -lpthread
+
+conn_pool.o: conn_pool.c smtpsink.h conn_queue.h smtpsink-int.h
+       cc $(CFLAGS) -c conn_pool.c
+
+conn_queue.o: conn_queue.c smtpsink.h conn_queue.h
+       cc $(CFLAGS) -c conn_queue.c
+
+io.o: io.c smtpsink.h conn_queue.h smtpsink-int.h
+       cc $(CFLAGS) -c io.c
+
+smtp.o: smtp.c smtpsink.h conn_queue.h smtpsink-int.h responses.inc
+       cc $(CFLAGS) -c smtp.c
+
+smtpsink.o: smtpsink.c smtpsink.h conn_queue.h smtpsink-int.h
+
+clean:
+       rm -f $(SMTPSINK_OBJS) smtpsink
index 84976bfb1e8c7886dba05ff441e51d68387ca273..daf10e48b3ec118c8f065975bdd1d0f0f7e80dab 100644 (file)
@@ -102,7 +102,7 @@ listener_loop(void *data)
         * before all queues are initialized.
         */
        if (pthread_mutex_lock(&lmtx)) assert(0);
-       if (pthread_cond_wait(&lc)) assert(0);
+       if (pthread_cond_wait(&lc, &lmtx)) assert(0);
        pthread_mutex_unlock(&lmtx);
 
        while (1) {
@@ -118,7 +118,7 @@ listener_loop(void *data)
                c->peer = addr;
                c->fd = fd;
                io_initconn(c);
-               respond(c, greeting);
+               greeting(c);
                if (c->wdata.s) {
                        c->event = EV_WRITE;
                } else {
diff --git a/io.c b/io.c
index 5fcd6732fb2c48604d417bc962475fcda83fc0d3..e47c2029e82580ddacbead1232c06bf1ec425b3c 100644 (file)
--- a/io.c
+++ b/io.c
@@ -43,7 +43,7 @@ read_cb(int fd, short event, void *data)
                smtp_queue.enqueue(&smtp_queue, c);
                break;
        case EV_TIMEOUT:
-               respond(c, readtimeoutresp);
+               read_timeout(c);
                if (c->wdata.s) {
                        c->state = SMTP_CLOSED;
                        event_add(&c->we, &timeout);
@@ -92,7 +92,7 @@ write_cb(int fd, short event, void *data)
 }
 
 void
-conn_startio(struct conn *c)
+io_initconn(struct conn *c)
 {
        event_set(&c->re, c->fd, EV_READ, read_cb, (void *)c);
        event_set(&c->re, c->fd, EV_WRITE, write_cb, (void *)c);
diff --git a/smtp.c b/smtp.c
index 86b28fc1343f5931b8645fe777016d6a4121a096..5035464cac593b348e49c69939450399d315b9a0 100644 (file)
--- a/smtp.c
+++ b/smtp.c
@@ -57,13 +57,25 @@ respond(struct conn *c, const char *fmt, ...)
 
 #include "responses.inc"
 
+int
+greeting(struct conn *c)
+{
+       return respond(c, banner, banner_hostname);
+}
+
+int
+read_timeout(struct conn *c)
+{
+       return respond(c, err_timeout);
+
+}
+
 static int
 smtpd_helo(struct conn *c, char *cmd, int len, int argoff)
 {
        const char *resp = helo_ok;
        if (cmd[0] == 'e' || cmd[0] == 'E')
                resp = ehlo_ok;
-       }
        /* if (c->state == SMTP_GREET) {
                call-hook;
        } */
@@ -248,14 +260,7 @@ handle_smtp(struct conn *c)
                        len += nr;
                }
                else {
-                       if (nr == 0)
-                               close_conn(c);
-                       else if (respond(c, readerrresp))
-                               close_conn(c);
-                       else {
-                               c->event = EV_WRITE;
-                               io_queue.enqueue(&io_queue, c);
-                       } 
+                       close_conn(c);
                        return;
                }
        }
index 992af309e63ccac24795bd5b36d380ef6812fb17..fcc4529419938732c9cdcfcf53924397b8101b06 100644 (file)
@@ -1,17 +1,19 @@
 /* internal functions and interfaces */
 
-void conn_pool_init(int);
-void close_conn(struct conn *);
-void new_listener(char *);
-void start_listeners(void);
+extern void conn_pool_init(int);
+extern void close_conn(struct conn *);
+extern void new_listener(char *);
+extern void start_listeners(void);
 
-void io_init(void);
-void io_initconn(struct conn *);
+extern void io_init(void);
+extern void io_initconn(struct conn *);
 
-int conn_queue_init(struct conn_queue *, void (*)(struct conn *), int);
-int conn_queue_set_tpool_size(struct conn_queue *, int);
+extern int conn_queue_init(struct conn_queue *, void (*)(struct conn *), int);
+extern int conn_queue_set_tpool_size(struct conn_queue *, int);
 
-void smtp_init(int);
+extern void smtp_init(int);
+extern int greeting(struct conn *);
+extern int read_timeout(struct conn *);
 
 extern struct conn_queue io_queue, smtp_queue;
 extern char *banner_hostname;
index 4cc64fbdbb20fca1891a7205b45d190b0dc17e6d..6f6d2ea3d98a06316da1c9e566eda00b85eb89cd 100644 (file)
@@ -1,27 +1,41 @@
-/* #include system header files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <syslog.h>
+#include <err.h>
+
+#include <sys/queue.h>
+#include <netinet/in.h>
+#include <event.h>
 #include "smtpsink.h"
-#include "queues.h"
+#include "conn_queue.h"
+#include "smtpsink-int.h"
 
 static void
-sig_exit(int fd, short event, void *arg)
+sigev_exit(int fd, short event, void *arg)
 {
-       exit 0;
+       exit(0);
 }
 
 int
-main(char **argv, int argc)
+main(int argc, char **argv)
 {
        /* defaults */
        int concurrency = 10000;
-       int defaultport = "0.0.0.0:25";
+       char *l_default = "0.0.0.0:25";
        
        int daemonize = 1;
+       int pidfd = -1;
        uid_t uid = 0;
        gid_t gid = 0;
+
+       struct event sigint, sigterm;
        struct group *gr;
        struct passwd *pw;
 
-       int tstart = 1, tmax = 1, tspare = 1;
+       int tstart = 1;
 
        /* parse cmdline args */
 
@@ -33,18 +47,7 @@ main(char **argv, int argc)
                write (pidfd, pid, strlen(pid));
        }
 
-       s_addr.sin_family=AF_INET;
-       s_addr.sin_port=htons(listen_port);
-       s_addr.sin_addr.s_addr = listen_ip;
-
-       lsock = socket(PF_INET, SOCK_STREAM, 0);
-       if (lsock < 0) err (1, "socket");
-       setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-
-       if (bind(lsock, (struct sockaddr *)&s_addr, sizeof s_addr) < 0)
-               err (1, "bind");
-
-       if (listen(lsock, -1) < 0) errx (1, "listen");
+       new_listener(l_default);
 
        if (gid) {
                if (setgid(gid) < 0) {
@@ -68,7 +71,8 @@ main(char **argv, int argc)
 
        conn_pool_init(concurrency);
        io_init();
-       smtp_init(tstart, tmax, tspare);
+       smtp_init(tstart);
+       start_listeners();
        /* modules_init(); */
        event_dispatch();
 }