From: Matthew Mondor Date: Thu, 15 Mar 2007 04:41:12 +0000 (+0000) Subject: Removed no longer supported in-db message storage (we use files) X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=1c8b310e911ec12b43ecfc7d745b8ab2509db55c;p=mmondor.git Removed no longer supported in-db message storage (we use files) --- diff --git a/mmsoftware/mmmail/src/mmpop3d/mmpop3d.c b/mmsoftware/mmmail/src/mmpop3d/mmpop3d.c index fe0e72b..31d0c02 100644 --- a/mmsoftware/mmmail/src/mmpop3d/mmpop3d.c +++ b/mmsoftware/mmmail/src/mmpop3d/mmpop3d.c @@ -1,4 +1,4 @@ -/* $Id: mmpop3d.c,v 1.41 2007/03/13 20:28:22 mmondor Exp $ */ +/* $Id: mmpop3d.c,v 1.41.4.1 2007/03/15 04:41:09 mmondor Exp $ */ /* * Copyright (C) 2001-2004, Matthew Mondor @@ -84,7 +84,7 @@ MMCOPYRIGHT("@(#) Copyright (c) 2001-2004\n\ \tMatthew Mondor. All rights reserved.\n"); -MMRCSID("$Id: mmpop3d.c,v 1.41 2007/03/13 20:28:22 mmondor Exp $"); +MMRCSID("$Id: mmpop3d.c,v 1.41.4.1 2007/03/15 04:41:09 mmondor Exp $"); @@ -1120,19 +1120,10 @@ do_buildindex(clientenv *clenv) unsigned long *lengths; /* Query mysql server */ -#if defined(MMMAIL_MYSQL) - snprintf(line, 1023, - "SELECT mail_id,mail_size FROM mail WHERE mail_box='%s'", - clenv->mailbox); - numfields = 2; -#elif defined(MMMAIL_FILE) snprintf(line, 1023, "SELECT mail_id,mail_size,mail_file FROM mail WHERE " "mail_box='%s'", clenv->mailbox); numfields = 3; -#else -#error "One of MMMAIL_FILE or MMMAIL_MYSQL must be #defined!" -#endif if ((mysqlres = mmsql_query(line, mm_strlen(line))) != NULL) { @@ -1164,7 +1155,6 @@ do_buildindex(clientenv *clenv) ok = FALSE; break; } -#if defined(MMMAIL_FILE) if (row[2] != NULL) { mm_memcpy(mnode[i].file, row[2], lengths[2]); @@ -1173,7 +1163,6 @@ do_buildindex(clientenv *clenv) ok = FALSE; break; } -#endif } else { ok = FALSE; break; @@ -1220,40 +1209,6 @@ do_buildindex(clientenv *clenv) static bool do_message_load(msgdata *mdata, msgnode *mnode) { -#if defined(MMMAIL_MYSQL) - - char line[1024]; - MYSQL_RES *mysqlres; - MYSQL_ROW *row; - unsigned long *lengths; - - snprintf(line, 1024, "SELECT mail_data FROM mail WHERE mail_id=%s", - mnode->id); - if ((mysqlres = mmsql_query(line, mm_strlen(line))) != NULL) { - if ((mysql_num_rows(mysqlres)) == 1) { - if ((row = (MYSQL_ROW *)mysql_fetch_row(mysqlres)) != NULL) { - if ((mysql_num_fields(mysqlres)) == 1) { - lengths = mysql_fetch_lengths(mysqlres); - if (row[0] != NULL) { - mdata->internal = mysqlres; - mdata->body = (char *)row[0]; - mdata->size = lengths[0]; - - return TRUE; - } else - DEBUG_PRINTF("do_message_load", "row[0] == NULL"); - } else - DEBUG_PRINTF("do_message_load", "mysql_num_fields != 1"); - } else - DEBUG_PRINTF("do_message_load", "mysql_fetch_row()"); - } else - DEBUG_PRINTF("do_message_load", "mysql_num_rows != 1"); - mmsql_free_result(mysqlres); - } else - DEBUG_PRINTF("do_message_load", "mmsql_query(%s)", line); - -#elif defined(MMMAIL_FILE) - int fd; if ((fd = open(mnode->file, O_RDONLY)) != -1) { @@ -1277,8 +1232,6 @@ do_message_load(msgdata *mdata, msgnode *mnode) DEBUG_PRINTF("do_message_load", "open(%s) == %s", mnode->file, strerror(errno)); -#endif - mdata->internal = NULL; mdata->body = NULL; mdata->size = 0; @@ -1290,11 +1243,7 @@ do_message_load(msgdata *mdata, msgnode *mnode) static void do_message_free(msgdata *mdata) { -#if defined(MMMAIL_MYSQL) - mmsql_free_result(mdata->internal); -#elif defined(MMMAIL_FILE) (void) munmap(mdata->internal, mdata->size); -#endif mdata->internal = NULL; mdata->body = NULL; @@ -1470,12 +1419,10 @@ do_update(clientenv *clenv) ok = FALSE; break; } else { -#if defined(MMMAIL_FILE) /* Also unlink associated file */ if (unlink(mnode[i].file) == -1) mmsyslog(0, LOGLEVEL, "unlink(%s) == %s", mnode[i].file, strerror(errno)); -#endif messages++; size += mnode[i].size; } diff --git a/mmsoftware/mmmail/src/mmpop3d/mmpop3d.h b/mmsoftware/mmmail/src/mmpop3d/mmpop3d.h index 7f5caff..0e6c62a 100644 --- a/mmsoftware/mmmail/src/mmpop3d/mmpop3d.h +++ b/mmsoftware/mmmail/src/mmpop3d/mmpop3d.h @@ -1,4 +1,4 @@ -/* $Id: mmpop3d.h,v 1.17 2007/03/13 20:28:22 mmondor Exp $ */ +/* $Id: mmpop3d.h,v 1.17.4.1 2007/03/15 04:41:09 mmondor Exp $ */ /* * Copyright (C) 2001-2004, Matthew Mondor @@ -101,12 +101,7 @@ typedef struct config { /* For the messages list during the session */ typedef struct msgnode { char id[24]; /* ID in the database */ -#if defined(MMMAIL_FILE) char file[256]; /* Fullpath to message file */ -#elif defined(MMMAIL_MYSQL) -#else -#error "One of MMMAIL_FILE or MMMAIL_MYSQL myst be #defined!" -#endif long size; /* Message size in bytes */ bool retreived, deleted; /* Flags */ } msgnode; diff --git a/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.c b/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.c index 3c9759e..65145dd 100644 --- a/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.c +++ b/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.c @@ -1,4 +1,4 @@ -/* $Id: mmsmtpd.c,v 1.75 2007/03/13 20:28:22 mmondor Exp $ */ +/* $Id: mmsmtpd.c,v 1.75.4.1 2007/03/15 04:41:12 mmondor Exp $ */ /* * Copyright (C) 2001-2004, Matthew Mondor @@ -83,7 +83,7 @@ MMCOPYRIGHT("@(#) Copyright (c) 2001-2004\n\ \tMatthew Mondor. All rights reserved.\n"); -MMRCSID("$Id: mmsmtpd.c,v 1.75 2007/03/13 20:28:22 mmondor Exp $"); +MMRCSID("$Id: mmsmtpd.c,v 1.75.4.1 2007/03/15 04:41:12 mmondor Exp $"); @@ -454,7 +454,6 @@ main(int argc, char **argv) printf("\nMAIL_DIR must be an absolute pathname to a directory\n\n"); exit(-1); } else { -#if defined(MMMAIL_FILE) struct stat st; if (stat(CONF.MAIL_DIR, &st) == -1) { @@ -465,7 +464,6 @@ main(int argc, char **argv) printf("\nMAIL_DIR not a directory: '%s'\n\n", CONF.MAIL_DIR); exit(-1); } -#endif /* defined(MMMAIL_FILE) */ } /* Finally init everything */ @@ -838,7 +836,6 @@ all_rcpt(clientenv *clenv) } if (!valid) reason = RCPT_UNKNOWN; -#if defined(MMMAIL_FILE) if (CONF.RELAYING && !valid) { /* Address is not local. If relaying is allowed, we must be * able to verify that the address indeed belongs to a @@ -863,7 +860,6 @@ all_rcpt(clientenv *clenv) relay = TRUE; } } -#endif /* defined(MMMAIL_FILE) */ if (!valid) { switch (reason) { case RCPT_RELAY: @@ -1855,25 +1851,13 @@ do_data(clientenv *clenv) } if (ok) { - /* XXX The following could easily simply be provided by separately * compiled mmsmtpd modules, designed to support multple storage * methods, as do_data_store() or such. But, we only support MySQL * and file storage for now... Which suffices for me. */ -#if defined(MMMAIL_MYSQL) - - ok = do_data_mysql(clenv, fdbrb); - -#elif defined(MMMAIL_FILE) - ok = do_data_file(clenv, fdbrb); - -#else -#error "One of MMMAIL_MYSQL or MMMAIL_FILE must be #defined!" -#endif - } fdbfreebuf(&fdbrb); /* Internally only frees if not already freed */ @@ -1961,106 +1945,6 @@ do_data_stats(clientenv *clenv, rcptnode *rnode, size_t len) } -#if defined(MMMAIL_MYSQL) - -static bool -do_data_mysql(clientenv *clenv, struct fdbrb_buffer *fdbrb) -{ - char line[1024], line2[2048], smtptime[32], *tmp, *query; - rcptnode *rnode; - bool ok = TRUE; - - /* Allocate query buffer for mysql_real_query(), should be large - * enough to handle the worst of cases where each character would - * be escaped to two chars, and must also hold the rest of the - * query string. We first process the message data through - * mysql_escape_string(), leaving enough room for the query and our - * "Received:" line, which will be copied before the message buffer - * for each RCPT. The message buffer will start at offset 2048 - * to make sure that there is enough room to insert the - * RCPT-specific data (query+received). - */ - if ((query = malloc((fdbrb->current * 2) + 2053)) != NULL) { - size_t len, qlen, tlen, clen; - - /* Prepare message buffer for mysql query */ - clen = fdbrb->current; /* Used after freeing buffer as well */ - tmp = &query[2048]; - tmp += mysql_escape_string(tmp, fdbrb->array, clen); - *tmp++ = '\''; - *tmp++ = ')'; - *tmp++ = '\0'; - qlen = tmp - &query[2048]; - rfc_time(smtptime); - - /* For each RCPT, create query and execute it */ - DLIST_FOREACH(&clenv->rcpt, rnode) { - /* Use the common message buffer, but append the query and - * message line before it (in it's 2048 bytes free area) - */ - do_data_received(line, 1024, clenv, rnode, smtptime); - tlen = mm_strlen(line) + clen; - snprintf(line2, 255, - "INSERT INTO mail (mail_box,mail_created,mail_size," - "mail_data) VALUES('%s',NOW(),%ld,'", - rnode->address, (long)tlen); - tmp = line2 + mm_strlen(line2); - tmp += mysql_escape_string(tmp, line, mm_strlen(line)); - len = tmp - line2; - tmp = &query[2048 - len]; - mm_memcpy(tmp, line2, len); - - /* Query buffer prepared, execute query. This glock is - * required for safety between the two queries which have - * to be performed within a single transaction. See - * mmlib/mmsql.c for implementation details; Currently uses - * MySQL GET_LOCK() and RELEASE_LOCK(), which contrary to - * table locking will permit to only cause the current thread - * to sleep rather than the whole process in this case. - */ - mmsql_glock("mmmail_boxmail"); - if (!mmsql_command(tmp, qlen + len)) { - mmsyslog(0, LOGLEVEL, "mmsql_command(%s)", tmp); - ok = FALSE; - break; - } else { - u_int64_t id; - - /* Obtain auto-increment value usd in last command */ - id = mmsql_last_auto_id(); - - if (!(ok = do_data_update(rnode, tlen))) { - /* Delete previous successful entry, since updating quota - * information did not succeed, and it must always be - * accurate according to actual mail data. - */ - snprintf(line, 1023, - "DELETE FROM mail WHERE mail_id=%llu", id); - (void) mmsql_command(line, mm_strlen(line)); - } - } - mmsql_gunlock("mmmail_boxmail"); - - if (!ok) - break; - - /* Everything successful, record statistics */ - do_data_stats(clenv, rnode, tlen); - } - - free(query); - } else { - DEBUG_PRINTF("do_data", - "malloc(%d)", (int)(fdbrb->current * 2) + 2053); - REGISTER_ERROR(clenv); - ok = FALSE; - } - - return ok; -} - -#elif defined(MMMAIL_FILE) - /* Returns TRUE if the client address/hostname is allowed to relay messages * for non-local addresses, or FALSE otherwise, with reason set to either * RCPT_UNKNOWN (destination address on a locally handled domain but @@ -2476,10 +2360,6 @@ do_data_queue_notify_connect(void) return fd; } -#else -#error "One of MMMAIL_MYSQL or MMMAIL_FILE must be #defined!" -#endif - /* This is the main function that is called to serve a client. * It comports the main loop and state switcher. @@ -2879,7 +2759,6 @@ db_gc_thread(void *args) * ones. We also don't need to do anything if we are not * using files for message storage. */ -#if defined(MMMAIL_FILE) if (valid_address(NULL, deladdr, 64, addr, HOST_NORES)) { MYSQL_RES *mysqlres2; @@ -2896,7 +2775,6 @@ db_gc_thread(void *args) (void) mmsql_free_result(mysqlres2); } } -#endif /* defined(MMMAIL_FILE) */ /* Delete db entry unconditionally */ (void) snprintf(query, 1023, "DELETE FROM boxdelete WHERE " diff --git a/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.h b/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.h index e46674b..612e393 100644 --- a/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.h +++ b/mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.h @@ -1,4 +1,4 @@ -/* $Id: mmsmtpd.h,v 1.34 2007/03/13 20:28:22 mmondor Exp $ */ +/* $Id: mmsmtpd.h,v 1.34.4.1 2007/03/15 04:41:12 mmondor Exp $ */ /* * Copyright (C) 2001-2004, Matthew Mondor @@ -297,9 +297,6 @@ inline static size_t do_data_received(char *, size_t, clientenv *, rcptnode *, const char *); inline static bool do_data_update(rcptnode *, size_t); static void do_data_stats(clientenv *, rcptnode *, size_t); -#if defined(MMMAIL_MYSQL) -static bool do_data_mysql(clientenv *, struct fdbrb_buffer *); -#elif defined(MMMAIL_FILE) static bool address_relay_allow(clientenv *, int *, const char *); static void iso_time(char *); static bool message_write(char *, const char *, size_t, struct fdbrb_buffer *, @@ -311,9 +308,6 @@ static bool do_data_queue_relay(clientenv *, const char *, size_t, struct fdbrb_buffer *, rcptnode *); static void do_data_queue_notify(clientenv *); static int do_data_queue_notify_connect(void); -#else -#error "One of MMMAIL_MYSQL or MMMAIL_FILE must be #defined!" -#endif static int handleclient(unsigned long, int, clientlistnode *, struct iface *, struct async_clenv *);