mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 20:20:12 +01:00
prepared statement fixes
This commit is contained in:
parent
1b693f3ba9
commit
a1d11d01b9
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#define VERSION "0.1.24-master-branch"
|
#define VERSION "0.1.24-master-branch"
|
||||||
|
|
||||||
#define BUILD 818
|
#define BUILD 819
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
11
src/import.c
11
src/import.c
@ -72,11 +72,6 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
|||||||
state = parse_message(sdata, 1, data, cfg);
|
state = parse_message(sdata, 1, data, cfg);
|
||||||
post_parse(sdata, &state, cfg);
|
post_parse(sdata, &state, cfg);
|
||||||
|
|
||||||
if(sdata->hdr_len < 10){
|
|
||||||
printf("invalid message, hdr_len: %d\n", sdata->hdr_len);
|
|
||||||
return ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sdata->sent <= 0 && sdata->delivered > 0) sdata->sent = sdata->delivered;
|
if(sdata->sent <= 0 && sdata->delivered > 0) sdata->sent = sdata->delivered;
|
||||||
|
|
||||||
if(sdata->sent > sdata->now) sdata->sent = sdata->now;
|
if(sdata->sent > sdata->now) sdata->sent = sdata->now;
|
||||||
@ -94,6 +89,12 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
make_digests(sdata, cfg);
|
make_digests(sdata, cfg);
|
||||||
|
|
||||||
|
if(sdata->hdr_len < 10){
|
||||||
|
printf("%s: invalid message, hdr_len: %d\n", filename, sdata->hdr_len);
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
|
||||||
rc = process_message(sdata, &state, data, cfg);
|
rc = process_message(sdata, &state, data, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ int store_index_data(struct session_data *sdata, struct _state *state, struct __
|
|||||||
uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data, char *message_id, struct __config *cfg){
|
uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data, char *message_id, struct __config *cfg){
|
||||||
uint64 id=0;
|
uint64 id=0;
|
||||||
|
|
||||||
|
if(prepare_sql_statement(sdata, &(data->stmt_get_meta_id_by_message_id), SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID) == ERR) return id;
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
data->sql[data->pos] = message_id; data->type[data->pos] = TYPE_STRING; data->pos++;
|
data->sql[data->pos] = message_id; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||||
@ -83,6 +84,8 @@ uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data,
|
|||||||
p_free_results(data->stmt_get_meta_id_by_message_id);
|
p_free_results(data->stmt_get_meta_id_by_message_id);
|
||||||
|
|
||||||
CLOSE:
|
CLOSE:
|
||||||
|
mysql_stmt_close(data->stmt_get_meta_id_by_message_id);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +94,8 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to,
|
|||||||
int ret=OK, n=0;
|
int ret=OK, n=0;
|
||||||
char *p, *q, puf[SMALLBUFSIZE];
|
char *p, *q, puf[SMALLBUFSIZE];
|
||||||
|
|
||||||
|
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_rcpt_table), SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE) == ERR) return ret;
|
||||||
|
|
||||||
p = to;
|
p = to;
|
||||||
do {
|
do {
|
||||||
p = split_str(p, " ", puf, sizeof(puf)-1);
|
p = split_str(p, " ", puf, sizeof(puf)-1);
|
||||||
@ -115,6 +120,7 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to,
|
|||||||
|
|
||||||
} while(p);
|
} while(p);
|
||||||
|
|
||||||
|
mysql_stmt_close(data->stmt_insert_into_rcpt_table);
|
||||||
|
|
||||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: added %d recipients", sdata->ttmpfile, n);
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: added %d recipients", sdata->ttmpfile, n);
|
||||||
|
|
||||||
@ -125,6 +131,7 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to,
|
|||||||
int update_metadata_reference(struct session_data *sdata, struct _state *state, struct __data *data, char *ref, struct __config *cfg){
|
int update_metadata_reference(struct session_data *sdata, struct _state *state, struct __data *data, char *ref, struct __config *cfg){
|
||||||
int ret = ERR;
|
int ret = ERR;
|
||||||
|
|
||||||
|
if(prepare_sql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE) == ERR) return ret;
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -133,6 +140,8 @@ int update_metadata_reference(struct session_data *sdata, struct _state *state,
|
|||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_update_metadata_reference, data) == OK) ret = OK;
|
if(p_exec_query(sdata, data->stmt_update_metadata_reference, data) == OK) ret = OK;
|
||||||
|
|
||||||
|
mysql_stmt_close(data->stmt_update_metadata_reference);
|
||||||
|
|
||||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: updated meta reference for '%s', rc=%d", sdata->ttmpfile, state->reference, ret);
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: updated meta reference for '%s', rc=%d", sdata->ttmpfile, state->reference, ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
21
src/mysql.c
21
src/mysql.c
@ -235,29 +235,8 @@ void insert_offset(struct session_data *sdata, int server_id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int create_prepared_statements(struct session_data *sdata, struct __data *data){
|
|
||||||
int rc = OK;
|
|
||||||
|
|
||||||
data->stmt_get_meta_id_by_message_id = NULL;
|
|
||||||
data->stmt_insert_into_rcpt_table = NULL;
|
|
||||||
data->stmt_update_metadata_reference = NULL;
|
|
||||||
|
|
||||||
if(prepare_sql_statement(sdata, &(data->stmt_get_meta_id_by_message_id), SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID) == ERR) rc = ERR;
|
|
||||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_rcpt_table), SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE) == ERR) rc = ERR;
|
|
||||||
if(prepare_sql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE) == ERR) rc = ERR;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void close_prepared_statement(MYSQL_STMT *stmt){
|
void close_prepared_statement(MYSQL_STMT *stmt){
|
||||||
if(stmt) mysql_stmt_close(stmt);
|
if(stmt) mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void close_prepared_statements(struct __data *data){
|
|
||||||
if(data->stmt_get_meta_id_by_message_id) mysql_stmt_close(data->stmt_get_meta_id_by_message_id);
|
|
||||||
if(data->stmt_insert_into_rcpt_table) mysql_stmt_close(data->stmt_insert_into_rcpt_table);
|
|
||||||
if(data->stmt_update_metadata_reference) mysql_stmt_close(data->stmt_update_metadata_reference);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -527,11 +527,6 @@ int main(int argc, char **argv){
|
|||||||
if(open_database(&sdata, &cfg) == ERR) return 0;
|
if(open_database(&sdata, &cfg) == ERR) return 0;
|
||||||
|
|
||||||
|
|
||||||
if(create_prepared_statements(&sdata, &data) == ERR){
|
|
||||||
rc = ERR;
|
|
||||||
goto ENDE;
|
|
||||||
}
|
|
||||||
|
|
||||||
setlocale(LC_CTYPE, cfg.locale);
|
setlocale(LC_CTYPE, cfg.locale);
|
||||||
|
|
||||||
(void) openlog("pilerimport", LOG_PID, LOG_MAIL);
|
(void) openlog("pilerimport", LOG_PID, LOG_MAIL);
|
||||||
@ -576,9 +571,6 @@ int main(int argc, char **argv){
|
|||||||
free_rule(data.archiving_rules);
|
free_rule(data.archiving_rules);
|
||||||
free_rule(data.retention_rules);
|
free_rule(data.retention_rules);
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statements(&data);
|
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
if(quiet == 0) printf("\n");
|
if(quiet == 0) printf("\n");
|
||||||
|
@ -146,13 +146,6 @@ int handle_pilerget_request(int new_sd, struct __data *data, struct __config *cf
|
|||||||
syslog(LOG_PRIORITY, "%s", ERR_MYSQL_CONNECT);
|
syslog(LOG_PRIORITY, "%s", ERR_MYSQL_CONNECT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(db_conn == 1 && create_prepared_statements(&sdata, data) == ERR){
|
|
||||||
close_prepared_statements(data);
|
|
||||||
close_database(&sdata);
|
|
||||||
db_conn = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(db_conn == 0){
|
if(db_conn == 0){
|
||||||
send(new_sd, SMTP_RESP_421_ERR_TMP, strlen(SMTP_RESP_421_ERR_TMP), 0);
|
send(new_sd, SMTP_RESP_421_ERR_TMP, strlen(SMTP_RESP_421_ERR_TMP), 0);
|
||||||
syslog(LOG_PRIORITY, "cannot make prepared statement");
|
syslog(LOG_PRIORITY, "cannot make prepared statement");
|
||||||
@ -264,7 +257,6 @@ int handle_pilerget_request(int new_sd, struct __data *data, struct __config *cf
|
|||||||
QUITTING:
|
QUITTING:
|
||||||
|
|
||||||
#ifdef NEED_MYSQL
|
#ifdef NEED_MYSQL
|
||||||
close_prepared_statements(data);
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -72,13 +72,6 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
|||||||
syslog(LOG_PRIORITY, "%s", ERR_MYSQL_CONNECT);
|
syslog(LOG_PRIORITY, "%s", ERR_MYSQL_CONNECT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(db_conn == 1 && create_prepared_statements(&sdata, data) == ERR){
|
|
||||||
close_prepared_statements(data);
|
|
||||||
close_database(&sdata);
|
|
||||||
db_conn = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(db_conn == 0){
|
if(db_conn == 0){
|
||||||
send(new_sd, SMTP_RESP_421_ERR_TMP, strlen(SMTP_RESP_421_ERR_TMP), 0);
|
send(new_sd, SMTP_RESP_421_ERR_TMP, strlen(SMTP_RESP_421_ERR_TMP), 0);
|
||||||
syslog(LOG_PRIORITY, "cannot make prepared statement");
|
syslog(LOG_PRIORITY, "cannot make prepared statement");
|
||||||
@ -563,7 +556,6 @@ QUITTING:
|
|||||||
update_counters(&sdata, data, &counters, cfg);
|
update_counters(&sdata, data, &counters, cfg);
|
||||||
|
|
||||||
#ifdef NEED_MYSQL
|
#ifdef NEED_MYSQL
|
||||||
close_prepared_statements(data);
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ void p_bind_init(struct __data *data);
|
|||||||
uint64 p_get_insert_id(MYSQL_STMT *stmt);
|
uint64 p_get_insert_id(MYSQL_STMT *stmt);
|
||||||
int p_get_affected_rows(MYSQL_STMT *stmt);
|
int p_get_affected_rows(MYSQL_STMT *stmt);
|
||||||
void close_prepared_statement(MYSQL_STMT *stmt);
|
void close_prepared_statement(MYSQL_STMT *stmt);
|
||||||
int create_prepared_statements(struct session_data *sdata, struct __data *data);
|
|
||||||
void close_prepared_statements(struct __data *data);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _PILER_H */
|
#endif /* _PILER_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user