From d687fa16abe2a4a2dde25c94839caa6ecc6de2cd Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Tue, 3 Mar 2020 15:47:02 +0100 Subject: [PATCH] Code cleanup Signed-off-by: Janos SUTO --- src/archive.c | 2 -- src/attachment.c | 2 -- src/base64.c | 3 +-- src/bdat.c | 2 +- src/cfg.c | 8 +++----- src/clamd.c | 2 +- src/config.h | 1 - src/counters.c | 4 ++-- src/digest.c | 1 - src/extract.c | 2 -- src/hash.c | 1 - src/htmlentities.h | 1 - src/imap.c | 4 ++-- src/import.c | 4 ++-- src/import.h | 1 - src/list.c | 3 --- src/list.h | 1 - src/memc.c | 6 ++---- src/misc.c | 10 +++++----- src/mysql.c | 3 +-- src/parser.c | 4 ++-- src/parser_utils.c | 9 ++++----- src/pileraget.c | 2 -- src/pilerconf.c | 2 +- src/pilerexport.c | 8 +++----- src/pilerget.c | 2 -- src/pilerimport.c | 2 +- src/rules.h | 1 - src/sig.c | 1 - src/smtpcodes.h | 1 - src/store.c | 2 -- src/tai.h | 1 - src/test.c | 2 +- 33 files changed, 32 insertions(+), 66 deletions(-) diff --git a/src/archive.c b/src/archive.c index e85dbb05..9a0ffe97 100644 --- a/src/archive.c +++ b/src/archive.c @@ -305,5 +305,3 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct c return 0; } - - diff --git a/src/attachment.c b/src/attachment.c index 29850bbe..70a156b6 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -169,5 +169,3 @@ CLOSE: return attachments; } - - diff --git a/src/base64.c b/src/base64.c index d130c930..82e69ff2 100644 --- a/src/base64.c +++ b/src/base64.c @@ -71,9 +71,8 @@ void base64_encode(unsigned char *in, int inlen, char *out, int outlen){ } buf[i] = *(in+j); - i++; + i++; } base64_encode_block(buf, i, &out[pos]); } - diff --git a/src/bdat.c b/src/bdat.c index f410eb71..701fdf2e 100644 --- a/src/bdat.c +++ b/src/bdat.c @@ -78,7 +78,7 @@ void process_bdat(struct smtp_session *session, char *readbuf, int readlen, stru else syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__); } - + if(session->bdat_bytes_to_read < 0){ // malformed data from client: we got more data then had been told in BDAT argument syslog(LOG_PRIORITY, "ERROR: invalid BDAT data. Expected %d, got %d bytes", session->bdat_bytes_to_read + readlen, readlen); diff --git a/src/cfg.c b/src/cfg.c index 7734d985..820e5cd9 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -148,7 +148,7 @@ int parse_config_file(char *configfile, struct config *target_cfg, struct _parse printf("failed to parse %s: \"%s\"\n", line, chpos+1); } break; - } + } i++; } @@ -230,7 +230,7 @@ void print_config_item(struct config *cfg, struct _parse_rule *rules, int i){ trimBuffer(p); printf("%s=%s\n", rules[i].name, p); } - + } @@ -297,12 +297,10 @@ void print_config(char *configfile, struct config *cfg){ i++; } - + if(!rules[i].name) printf("unknown key: \"%s\" \n", line); } } fclose(f); } - - diff --git a/src/clamd.c b/src/clamd.c index e5a7d17d..8f7f3f08 100644 --- a/src/clamd.c +++ b/src/clamd.c @@ -41,7 +41,7 @@ int clamd_scan(char *tmpfile, struct config *cfg){ /* issue the SCAN command with full path to the temporary directory */ - + memset(scan_cmd, 0, SMALLBUFSIZE); snprintf(scan_cmd, SMALLBUFSIZE-1, "SCAN %s/%s\r\n", cfg->workdir, tmpfile); diff --git a/src/config.h b/src/config.h index 3ec7f1bc..117f3f8a 100644 --- a/src/config.h +++ b/src/config.h @@ -136,4 +136,3 @@ #define S_STATUS_ERROR "error" #endif /* _CONFIG_H */ - diff --git a/src/counters.c b/src/counters.c index 2bdeedc3..35ad9402 100644 --- a/src/counters.c +++ b/src/counters.c @@ -74,7 +74,7 @@ void update_counters(struct session_data *sdata, struct data *data, struct count if(counters->c_stored_size > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_STORED_SIZE, counters->c_stored_size, &mc); - bzero(&c, sizeof(c)); + bzero(&c, sizeof(c)); snprintf(buf, MAXBUFSIZE-1, "%s %s %s %s %s %s %s", MEMCACHED_MSGS_RCVD, MEMCACHED_MSGS_VIRUS, MEMCACHED_MSGS_DUPLICATE, MEMCACHED_MSGS_IGNORE, MEMCACHED_MSGS_SIZE, MEMCACHED_MSGS_STORED_SIZE, MEMCACHED_COUNTERS_LAST_UPDATE); @@ -94,7 +94,7 @@ void update_counters(struct session_data *sdata, struct data *data, struct count snprintf(buf, SMALLBUFSIZE-1, "%ld", sdata->now); memcached_add(&(data->memc), "set", MEMCACHED_COUNTERS_LAST_UPDATE, buf, strlen(buf), 0, 0); snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=%llu, `virus`=%llu, `duplicate`=%llu, `ignore`=%llu, `size`=%llu, `stored_size`=%llu", SQL_COUNTER_TABLE, c.c_rcvd, c.c_virus, c.c_duplicate, c.c_ignore, c.c_size, c.c_stored_size); - + //if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update counters: %s", sdata->ttmpfile, buf); p_query(sdata, buf); diff --git a/src/digest.c b/src/digest.c index 6f373ad2..d8146726 100644 --- a/src/digest.c +++ b/src/digest.c @@ -133,4 +133,3 @@ void digest_string(char *s, char *digest){ snprintf(digest + i*2, 2*DIGEST_LENGTH, "%02x", md[i]); } - diff --git a/src/extract.c b/src/extract.c index 4488baae..fb42b574 100644 --- a/src/extract.c +++ b/src/extract.c @@ -317,5 +317,3 @@ void extract_attachment_content(struct session_data *sdata, struct parser_state } - - diff --git a/src/hash.c b/src/hash.c index 5fe19cc6..027768b9 100644 --- a/src/hash.c +++ b/src/hash.c @@ -163,4 +163,3 @@ unsigned int DJBHash(char* str, unsigned int len){ return hash; } - diff --git a/src/htmlentities.h b/src/htmlentities.h index ef7e08f0..52389362 100644 --- a/src/htmlentities.h +++ b/src/htmlentities.h @@ -285,4 +285,3 @@ struct mi htmlentities[] = { #endif /* _HTMLENTITIES_H */ - diff --git a/src/imap.c b/src/imap.c index 2e611418..0af375d5 100644 --- a/src/imap.c +++ b/src/imap.c @@ -363,7 +363,7 @@ int process_imap_folder(char *folder, struct session_data *sdata, struct data *d void send_imap_close(struct data *data){ - char puf[SMALLBUFSIZE]; + char puf[SMALLBUFSIZE]; snprintf(puf, sizeof(puf)-1, "A%d CLOSE\r\n", data->import->seq); write1(data->net, puf, strlen(puf)); @@ -447,7 +447,7 @@ int list_folders(struct data *data){ q++; fldrlen = strtol(q, NULL, 10); } else { - + if(fldrlen) { ruf = malloc(strlen(q) * 2 + 1); memset(ruf, 0, strlen(q) * 2 + 1); diff --git a/src/import.c b/src/import.c index fa89b645..4ec7b7e4 100644 --- a/src/import.c +++ b/src/import.c @@ -65,7 +65,7 @@ int import_message(struct session_data *sdata, struct data *data, struct config data->import->total_size += sdata->tot_len; - + sdata->delivered = 0; sdata->import = 1; @@ -124,7 +124,7 @@ int import_message(struct session_data *sdata, struct data *data, struct config default: printf("failed to import: %s (id: %s)\n", data->import->filename, sdata->ttmpfile); break; - } + } if(rc != OK && data->import->failed_folder){ p = strrchr(data->import->filename, '/'); diff --git a/src/import.h b/src/import.h index 21e3f082..0fa2a211 100644 --- a/src/import.h +++ b/src/import.h @@ -23,4 +23,3 @@ int process_imap_folder(char *folder, struct session_data *sdata, struct data *d void send_imap_close(struct data *data); #endif /* _IMPORT_H */ - diff --git a/src/list.c b/src/list.c index 74a7b81c..965d48b3 100644 --- a/src/list.c +++ b/src/list.c @@ -92,6 +92,3 @@ void free_list(struct list *list){ p = q; } } - - - diff --git a/src/list.h b/src/list.h index 6e0ab6d7..56a413c7 100644 --- a/src/list.h +++ b/src/list.h @@ -14,4 +14,3 @@ int is_item_on_string(struct list *list, char *s); void free_list(struct list *list); #endif /* _LIST_H */ - diff --git a/src/memc.c b/src/memc.c index 0e2a1487..c56c4db8 100644 --- a/src/memc.c +++ b/src/memc.c @@ -197,7 +197,7 @@ int memcached_connect(struct memcached_server *ptr){ { (void)close(ptr->fd); ptr->fd= -1; - + } return MEMCACHED_FAILURE; @@ -299,7 +299,7 @@ char *memcached_get(struct memcached_server *ptr, char *key, unsigned int *len, *flags = atoi(p+1); *p = '\0'; - + p = strchr(ptr->result, '\r'); if(!p) return NULL; @@ -372,5 +372,3 @@ char *memcached_fetch_result(struct memcached_server *ptr, char *key, char *valu return p; } - - diff --git a/src/misc.c b/src/misc.c index 2e107227..cfa19828 100644 --- a/src/misc.c +++ b/src/misc.c @@ -410,28 +410,28 @@ int ssl_want_retry(SSL *ssl, int ret, int timeout){ i = SSL_get_error(ssl, ret); if(i == SSL_ERROR_NONE) return 1; - + tv.tv_sec = timeout/1000; tv.tv_usec = 0; FD_ZERO(&fds); - + switch(i){ case SSL_ERROR_WANT_READ: // pause until the socket is readable sock = SSL_get_rfd(ssl); FD_SET(sock, &fds); i = select(sock+1, &fds, 0, 0, &tv); break; - + case SSL_ERROR_WANT_WRITE: // pause until the socket is writeable sock = SSL_get_wfd(ssl); FD_SET(sock, &fds); i = select(sock+1, 0, &fds, 0, &tv); break; - + case SSL_ERROR_ZERO_RETURN: // the sock closed, just return quietly i = 0; break; - + default: // ERROR - unexpected error code i = -1; break; diff --git a/src/mysql.c b/src/mysql.c index 3899c7eb..83c93fd9 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -104,7 +104,6 @@ int p_exec_stmt(struct session_data *sdata, struct sql *sql){ bind[i].buffer = sql->sql[i]; bind[i].is_null = 0; - } else { break; } } @@ -222,7 +221,7 @@ int prepare_sql_statement(struct session_data *sdata, struct sql *sql, char *s){ return ERR; } - return OK; + return OK; } diff --git a/src/parser.c b/src/parser.c index aa11b885..6b755c42 100644 --- a/src/parser.c +++ b/src/parser.c @@ -259,7 +259,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata p = get_attachment_extractor_by_filename(state->attachments[state->n_attachments].filename); snprintf(state->attachments[state->n_attachments].shorttype, TINYBUFSIZE-1, "%s", p); - + if(strcmp("other", p)){ state->b64fd = open(state->attachments[state->n_attachments].aname, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); state->attachments[state->n_attachments].dumped = 1; @@ -590,7 +590,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata state->message_state = MSG_UNDEF; - return 0; + return 0; } if(boundary_line == 1){ return 0; } diff --git a/src/parser_utils.c b/src/parser_utils.c index 1c77886a..0d0a1f40 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -246,7 +246,7 @@ time_t parse_date_header(char *datestr){ } else { tm.tm_min = atoi(r); } - continue; + continue; } } @@ -518,13 +518,13 @@ void markHTML(char *buf, struct parser_state *state){ } if(state->htmltag == 1){ - + if(j == 0 && *s == '!'){ state->skip_html = 1; //printf("skiphtml=1\n"); } - if(state->skip_html == 0){ + if(state->skip_html == 0){ if(*s != '>' && *s != '<' && *s != '"'){ //printf("j=%d/%c", j, *s); html[j] = tolower(*s); @@ -973,7 +973,7 @@ char *determine_attachment_type(char *filename, char *type){ if(strncasecmp(p, "jpg", 3) == 0) return "image,"; if(strncasecmp(p, "jpeg", 4) == 0) return "image,"; if(strncasecmp(p, "tiff", 4) == 0) return "image,"; - } + } } return "other,"; @@ -1055,4 +1055,3 @@ void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len *at_sign = r; } } - diff --git a/src/pileraget.c b/src/pileraget.c index d926c7f8..3b780cc5 100644 --- a/src/pileraget.c +++ b/src/pileraget.c @@ -57,5 +57,3 @@ int main(int argc, char **argv){ return 0; } - - diff --git a/src/pilerconf.c b/src/pilerconf.c index bc9071ee..670bb36a 100644 --- a/src/pilerconf.c +++ b/src/pilerconf.c @@ -41,7 +41,7 @@ int main(int argc, char **argv){ break; - default : + default : break; } } diff --git a/src/pilerexport.c b/src/pilerexport.c index 035cd806..9abd03aa 100644 --- a/src/pilerexport.c +++ b/src/pilerexport.c @@ -508,7 +508,7 @@ int main(int argc, char **argv){ rc = append_email_to_buffer(&fromdomain, optarg); - break; + break; case 'R' : @@ -519,8 +519,8 @@ int main(int argc, char **argv){ rc = append_email_to_buffer(&todomain, optarg); - break; - + break; + case 'a' : startdate = convert_time(optarg, 0, 0, 0); break; @@ -604,5 +604,3 @@ int main(int argc, char **argv){ return 0; } - - diff --git a/src/pilerget.c b/src/pilerget.c index 1674014f..9adb1bf8 100644 --- a/src/pilerget.c +++ b/src/pilerget.c @@ -54,5 +54,3 @@ int main(int argc, char **argv){ return 0; } - - diff --git a/src/pilerimport.c b/src/pilerimport.c index 296b93ff..eaf7b87d 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -271,7 +271,7 @@ int main(int argc, char **argv){ break; - default : + default : break; } } diff --git a/src/rules.h b/src/rules.h index e965736e..bc5fb74b 100644 --- a/src/rules.h +++ b/src/rules.h @@ -21,4 +21,3 @@ void initrules(struct node *xhash[]); void clearrules(struct node *xhash[]); #endif /* _RULES_H */ - diff --git a/src/sig.c b/src/sig.c index 6d28b0a7..a1101694 100644 --- a/src/sig.c +++ b/src/sig.c @@ -56,4 +56,3 @@ signal_func *set_signal_handler(int signo, signal_func * func){ return oact.sa_handler; } - diff --git a/src/smtpcodes.h b/src/smtpcodes.h index fac0eaf6..ee0d2afc 100644 --- a/src/smtpcodes.h +++ b/src/smtpcodes.h @@ -64,4 +64,3 @@ // LMTP responses #define LMTP_RESP_220_BANNER "220 %s LMTP\r\n" - diff --git a/src/store.c b/src/store.c index 2cfc5e4b..dc3839a1 100644 --- a/src/store.c +++ b/src/store.c @@ -235,5 +235,3 @@ int remove_stored_message_files(struct session_data *sdata, struct parser_state return 0; } - - diff --git a/src/tai.h b/src/tai.h index 07f799d1..6b670fdf 100644 --- a/src/tai.h +++ b/src/tai.h @@ -26,4 +26,3 @@ void taia_now(struct taia *t); void taia_pack(char *s, struct taia *t); #endif /* _TAI_H */ - diff --git a/src/test.c b/src/test.c index b3695076..497c77fb 100644 --- a/src/test.c +++ b/src/test.c @@ -163,7 +163,7 @@ int main(int argc, char **argv){ printf("hdr len: %d\n", sdata.hdr_len); rule = check_against_ruleset(data.archiving_rules, &state, st.st_size, sdata.spam_message); - + printf("body digest: %s\n", sdata.bodydigest); printf("rules check: %s\n", rule);