mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-01-12 22:30:12 +01:00
code refactoring
This commit is contained in:
parent
c31b13d77b
commit
d203ee63d4
@ -36,8 +36,7 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, st
|
|||||||
data->sql[data->pos] = state->attachments[i].digest; data->type[data->pos] = TYPE_STRING; data->pos++;
|
data->sql[data->pos] = state->attachments[i].digest; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||||
data->sql[data->pos] = (char *)&(state->attachments[i].size); data->type[data->pos] = TYPE_LONG; data->pos++;
|
data->sql[data->pos] = (char *)&(state->attachments[i].size); data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_get_attachment_id_by_signature, data) == ERR) goto NOT_FOUND;
|
if(p_exec_query(sdata, data->stmt_get_attachment_id_by_signature, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -46,8 +45,7 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, st
|
|||||||
p_store_results(sdata, data->stmt_get_attachment_id_by_signature, data);
|
p_store_results(sdata, data->stmt_get_attachment_id_by_signature, data);
|
||||||
if(p_fetch_results(data->stmt_get_attachment_id_by_signature) == OK) found = 1;
|
if(p_fetch_results(data->stmt_get_attachment_id_by_signature) == OK) found = 1;
|
||||||
p_free_results(data->stmt_get_attachment_id_by_signature);
|
p_free_results(data->stmt_get_attachment_id_by_signature);
|
||||||
|
}
|
||||||
NOT_FOUND:
|
|
||||||
|
|
||||||
if(found == 0){
|
if(found == 0){
|
||||||
if(store_file(sdata, state->attachments[i].internalname, 0, 0, cfg) == 0){
|
if(store_file(sdata, state->attachments[i].internalname, 0, 0, cfg) == 0){
|
||||||
@ -103,9 +101,7 @@ int query_attachment_pointers(struct session_data *sdata, struct __data *data, u
|
|||||||
|
|
||||||
data->sql[data->pos] = (char *)&ptr; data->type[data->pos] = TYPE_LONGLONG; data->pos++;
|
data->sql[data->pos] = (char *)&ptr; data->type[data->pos] = TYPE_LONGLONG; data->pos++;
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_get_attachment_pointer, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_get_attachment_pointer, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -116,8 +112,8 @@ int query_attachment_pointers(struct session_data *sdata, struct __data *data, u
|
|||||||
|
|
||||||
if(p_fetch_results(data->stmt_get_attachment_pointer) == OK) rc = 1;
|
if(p_fetch_results(data->stmt_get_attachment_pointer) == OK) rc = 1;
|
||||||
p_free_results(data->stmt_get_attachment_pointer);
|
p_free_results(data->stmt_get_attachment_pointer);
|
||||||
|
}
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statement(data->stmt_get_attachment_pointer);
|
close_prepared_statement(data->stmt_get_attachment_pointer);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -130,7 +126,7 @@ int query_attachments(struct session_data *sdata, struct __data *data, struct pt
|
|||||||
|
|
||||||
for(i=0; i<MAX_ATTACHMENTS; i++) memset((char*)&ptr_arr[i], 0, sizeof(struct ptr_array));
|
for(i=0; i<MAX_ATTACHMENTS; i++) memset((char*)&ptr_arr[i], 0, sizeof(struct ptr_array));
|
||||||
|
|
||||||
if(prepare_sql_statement(sdata, &(data->stmt_query_attachment), SQL_PREPARED_STMT_QUERY_ATTACHMENT, cfg) == ERR) goto ENDE;
|
if(prepare_sql_statement(sdata, &(data->stmt_query_attachment), SQL_PREPARED_STMT_QUERY_ATTACHMENT, cfg) == ERR) return attachments;
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -170,8 +166,6 @@ int query_attachments(struct session_data *sdata, struct __data *data, struct pt
|
|||||||
CLOSE:
|
CLOSE:
|
||||||
close_prepared_statement(data->stmt_query_attachment);
|
close_prepared_statement(data->stmt_query_attachment);
|
||||||
|
|
||||||
ENDE:
|
|
||||||
|
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#define VERSION "1.2.0-master"
|
#define VERSION "1.2.0-master"
|
||||||
|
|
||||||
#define BUILD 931
|
#define BUILD 932
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
@ -72,8 +72,7 @@ uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data,
|
|||||||
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++;
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_get_meta_id_by_message_id, data) == ERR) goto CLOSE;
|
if(p_exec_query(sdata, data->stmt_get_meta_id_by_message_id, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||||
@ -83,8 +82,8 @@ uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data,
|
|||||||
p_fetch_results(data->stmt_get_meta_id_by_message_id);
|
p_fetch_results(data->stmt_get_meta_id_by_message_id);
|
||||||
|
|
||||||
p_free_results(data->stmt_get_meta_id_by_message_id);
|
p_free_results(data->stmt_get_meta_id_by_message_id);
|
||||||
|
}
|
||||||
|
|
||||||
CLOSE:
|
|
||||||
mysql_stmt_close(data->stmt_get_meta_id_by_message_id);
|
mysql_stmt_close(data->stmt_get_meta_id_by_message_id);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
@ -22,9 +22,7 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_generic, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_generic, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -42,8 +40,8 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
|||||||
}
|
}
|
||||||
|
|
||||||
p_free_results(data->stmt_generic);
|
p_free_results(data->stmt_generic);
|
||||||
|
}
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statement(data->stmt_generic);
|
close_prepared_statement(data->stmt_generic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
src/mysql.c
11
src/mysql.c
@ -108,18 +108,17 @@ int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *da
|
|||||||
if(mysql_stmt_bind_param(stmt, bind)){
|
if(mysql_stmt_bind_param(stmt, bind)){
|
||||||
sdata->sql_errno = mysql_stmt_errno(stmt);
|
sdata->sql_errno = mysql_stmt_errno(stmt);
|
||||||
syslog(LOG_PRIORITY, "%s: mysql_stmt_bind_param() error: %s (errno: %d)", sdata->ttmpfile, mysql_stmt_error(stmt), sdata->sql_errno);
|
syslog(LOG_PRIORITY, "%s: mysql_stmt_bind_param() error: %s (errno: %d)", sdata->ttmpfile, mysql_stmt_error(stmt), sdata->sql_errno);
|
||||||
goto CLOSE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mysql_stmt_execute(stmt)){
|
if(mysql_stmt_execute(stmt)){
|
||||||
sdata->sql_errno = mysql_stmt_errno(stmt);
|
sdata->sql_errno = mysql_stmt_errno(stmt);
|
||||||
syslog(LOG_PRIORITY, "%s: mysql_stmt_execute error: *%s* (errno: %d)", sdata->ttmpfile, mysql_error(&(sdata->mysql)), sdata->sql_errno);
|
syslog(LOG_PRIORITY, "%s: mysql_stmt_execute error: *%s* (errno: %d)", sdata->ttmpfile, mysql_error(&(sdata->mysql)), sdata->sql_errno);
|
||||||
goto CLOSE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
|
||||||
CLOSE:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,18 +168,16 @@ int p_store_results(struct session_data *sdata, MYSQL_STMT *stmt, struct __data
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(mysql_stmt_bind_result(stmt, bind)){
|
if(mysql_stmt_bind_result(stmt, bind)){
|
||||||
goto CLOSE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(mysql_stmt_store_result(stmt)){
|
if(mysql_stmt_store_result(stmt)){
|
||||||
goto CLOSE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
|
||||||
CLOSE:
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,9 +419,7 @@ int read_gui_import_data(struct session_data *sdata, struct __data *data, char *
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_generic, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_generic, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -436,10 +434,8 @@ int read_gui_import_data(struct session_data *sdata, struct __data *data, char *
|
|||||||
if(p_fetch_results(data->stmt_generic) == OK) rc = OK;
|
if(p_fetch_results(data->stmt_generic) == OK) rc = OK;
|
||||||
|
|
||||||
p_free_results(data->stmt_generic);
|
p_free_results(data->stmt_generic);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statement(data->stmt_generic);
|
close_prepared_statement(data->stmt_generic);
|
||||||
|
|
||||||
data->import->processed_messages = 0;
|
data->import->processed_messages = 0;
|
||||||
|
@ -38,9 +38,7 @@ int is_purge_allowed(struct session_data *sdata, struct __data *data, struct __c
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_generic, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_generic, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -49,8 +47,8 @@ int is_purge_allowed(struct session_data *sdata, struct __data *data, struct __c
|
|||||||
p_store_results(sdata, data->stmt_generic, data);
|
p_store_results(sdata, data->stmt_generic, data);
|
||||||
p_fetch_results(data->stmt_generic);
|
p_fetch_results(data->stmt_generic);
|
||||||
p_free_results(data->stmt_generic);
|
p_free_results(data->stmt_generic);
|
||||||
|
}
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statement(data->stmt_generic);
|
close_prepared_statement(data->stmt_generic);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -252,8 +250,7 @@ int purge_messages_round1(struct session_data *sdata, struct __data *data, char
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_select_from_meta_table, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_select_from_meta_table, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -291,7 +288,8 @@ int purge_messages_round1(struct session_data *sdata, struct __data *data, char
|
|||||||
purged += remove_message_frame_files(buf, update_meta_sql, sdata, cfg);
|
purged += remove_message_frame_files(buf, update_meta_sql, sdata, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
ENDE:
|
}
|
||||||
|
|
||||||
close_prepared_statement(data->stmt_select_from_meta_table);
|
close_prepared_statement(data->stmt_select_from_meta_table);
|
||||||
|
|
||||||
return purged;
|
return purged;
|
||||||
@ -311,8 +309,7 @@ int purge_messages_with_attachments(struct session_data *sdata, struct __data *d
|
|||||||
if(prepare_sql_statement(sdata, &(data->stmt_select_from_meta_table), s, cfg) == ERR) return purged;
|
if(prepare_sql_statement(sdata, &(data->stmt_select_from_meta_table), s, cfg) == ERR) return purged;
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
if(p_exec_query(sdata, data->stmt_select_from_meta_table, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_select_from_meta_table, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -336,12 +333,12 @@ int purge_messages_with_attachments(struct session_data *sdata, struct __data *d
|
|||||||
|
|
||||||
p_free_results(data->stmt_select_from_meta_table);
|
p_free_results(data->stmt_select_from_meta_table);
|
||||||
|
|
||||||
|
|
||||||
if(strlen(idlist) > 5){
|
if(strlen(idlist) > 5){
|
||||||
purged += remove_attachments(idlist, sdata, data, cfg);
|
purged += remove_attachments(idlist, sdata, data, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
ENDE:
|
}
|
||||||
|
|
||||||
close_prepared_statement(data->stmt_select_from_meta_table);
|
close_prepared_statement(data->stmt_select_from_meta_table);
|
||||||
|
|
||||||
return purged;
|
return purged;
|
||||||
|
@ -54,9 +54,7 @@ uint64 get_max_meta_id(struct session_data *sdata, struct __data *data, struct _
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_generic, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_generic, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -65,8 +63,8 @@ uint64 get_max_meta_id(struct session_data *sdata, struct __data *data, struct _
|
|||||||
p_store_results(sdata, data->stmt_generic, data);
|
p_store_results(sdata, data->stmt_generic, data);
|
||||||
p_fetch_results(data->stmt_generic);
|
p_fetch_results(data->stmt_generic);
|
||||||
p_free_results(data->stmt_generic);
|
p_free_results(data->stmt_generic);
|
||||||
|
}
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statement(data->stmt_generic);
|
close_prepared_statement(data->stmt_generic);
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +88,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_generic, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_generic, data) == OK){
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -142,11 +140,9 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p_free_results(data->stmt_generic);
|
p_free_results(data->stmt_generic);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ENDE:
|
|
||||||
close_prepared_statement(data->stmt_generic);
|
close_prepared_statement(data->stmt_generic);
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,9 +33,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
|||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
if(p_exec_query(sdata, data->stmt_generic, data) == ERR) goto ENDE;
|
if(p_exec_query(sdata, data->stmt_generic, data) == OK){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_bind_init(data);
|
p_bind_init(data);
|
||||||
|
|
||||||
@ -54,8 +52,6 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
|||||||
data->sql[data->pos] = (char *)&rule_cond.days; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
data->sql[data->pos] = (char *)&rule_cond.days; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||||
data->sql[data->pos] = (char *)&rule_cond.folder_id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
data->sql[data->pos] = (char *)&rule_cond.folder_id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p_store_results(sdata, data->stmt_generic, data);
|
p_store_results(sdata, data->stmt_generic, data);
|
||||||
|
|
||||||
while(p_fetch_results(data->stmt_generic) == OK){
|
while(p_fetch_results(data->stmt_generic) == OK){
|
||||||
@ -76,7 +72,8 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
|||||||
|
|
||||||
p_free_results(data->stmt_generic);
|
p_free_results(data->stmt_generic);
|
||||||
|
|
||||||
ENDE:
|
}
|
||||||
|
|
||||||
close_prepared_statement(data->stmt_generic);
|
close_prepared_statement(data->stmt_generic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user