pilerexport.c fixes

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2020-08-08 21:28:25 +02:00
parent 3e33bf99c8
commit cf97a9161b

View File

@ -87,15 +87,12 @@ unsigned long convert_time(char *yyyymmdd, int h, int m, int s){
tm.tm_mday = atoi(yyyymmdd); tm.tm_mday = atoi(yyyymmdd);
tm.tm_isdst = -1;
return mktime(&tm); return mktime(&tm);
} }
int append_email_to_buffer(char **buffer, char *email){ int append_email_to_buffer(char **buffer, char *email){
int len, arglen; int arglen;
char *s=NULL, emailaddress[SMALLBUFSIZE]; char *s=NULL, emailaddress[SMALLBUFSIZE];
snprintf(emailaddress, sizeof(emailaddress)-1, "'%s'", email); snprintf(emailaddress, sizeof(emailaddress)-1, "'%s'", email);
@ -107,7 +104,7 @@ int append_email_to_buffer(char **buffer, char *email){
memcpy(*buffer, emailaddress, arglen); memcpy(*buffer, emailaddress, arglen);
} }
else { else {
len = strlen(*buffer); int len = strlen(*buffer);
s = realloc(*buffer, len + arglen+2); s = realloc(*buffer, len + arglen+2);
if(!s){ if(!s){
printf("malloc problem!\n"); printf("malloc problem!\n");
@ -126,7 +123,7 @@ int append_email_to_buffer(char **buffer, char *email){
int append_string_to_buffer(char **buffer, char *str){ int append_string_to_buffer(char **buffer, char *str){
int len, arglen; int arglen;
char *s=NULL; char *s=NULL;
arglen = strlen(str); arglen = strlen(str);
@ -137,7 +134,7 @@ int append_string_to_buffer(char **buffer, char *str){
memcpy(*buffer, str, arglen); memcpy(*buffer, str, arglen);
} }
else { else {
len = strlen(*buffer); int len = strlen(*buffer);
s = realloc(*buffer, len + arglen+1); s = realloc(*buffer, len + arglen+1);
if(!s) return 1; if(!s) return 1;
@ -152,9 +149,7 @@ int append_string_to_buffer(char **buffer, char *str){
uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *where_condition, uint64 last_id, int *num, struct config *cfg){ uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *where_condition, uint64 last_id, int *num, struct config *cfg){
MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
int rc=0;
uint64 id=0; uint64 id=0;
char s[SMALLBUFSIZE]; char s[SMALLBUFSIZE];
@ -168,7 +163,7 @@ uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *
snprintf(s, sizeof(s)-1, "SELECT id FROM %s WHERE %s AND id > %llu ORDER BY id ASC LIMIT 0,%d", index_list, where_condition, last_id, max_matches); snprintf(s, sizeof(s)-1, "SELECT id FROM %s WHERE %s AND id > %llu ORDER BY id ASC LIMIT 0,%d", index_list, where_condition, last_id, max_matches);
if(mysql_real_query(&(sdata2->mysql), s, strlen(s)) == 0){ if(mysql_real_query(&(sdata2->mysql), s, strlen(s)) == 0){
res = mysql_store_result(&(sdata2->mysql)); MYSQL_RES *res = mysql_store_result(&(sdata2->mysql));
if(res != NULL){ if(res != NULL){
while((row = mysql_fetch_row(res))){ while((row = mysql_fetch_row(res))){
id = strtoull(row[0], NULL, 10); id = strtoull(row[0], NULL, 10);
@ -194,12 +189,11 @@ uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *
uint64 get_total_found(struct session_data *sdata){ uint64 get_total_found(struct session_data *sdata){
MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
uint64 total_found=0; uint64 total_found=0;
if(mysql_real_query(&(sdata->mysql), "SHOW META LIKE 'total_found'", 28) == 0){ if(mysql_real_query(&(sdata->mysql), "SHOW META LIKE 'total_found'", 28) == 0){
res = mysql_store_result(&(sdata->mysql)); MYSQL_RES *res = mysql_store_result(&(sdata->mysql));
if(res != NULL){ if(res != NULL){
while((row = mysql_fetch_row(res))){ while((row = mysql_fetch_row(res))){
total_found = strtoull(row[1], NULL, 10); total_found = strtoull(row[1], NULL, 10);
@ -313,7 +307,7 @@ int build_query_from_args(char *from, char *to, char *fromdomain, char *todomain
if(startdate > 0){ if(startdate > 0){
if(where_condition) rc = append_string_to_buffer(&query, " AND "); if(where_condition) rc = append_string_to_buffer(&query, " AND ");
snprintf(s, sizeof(s)-1, " `sent` >= %ld", startdate); snprintf(s, sizeof(s)-1, " `sent` >= %lu", startdate);
rc += append_string_to_buffer(&query, s); rc += append_string_to_buffer(&query, s);
where_condition++; where_condition++;
@ -322,10 +316,8 @@ int build_query_from_args(char *from, char *to, char *fromdomain, char *todomain
if(stopdate > 0){ if(stopdate > 0){
if(where_condition) rc = append_string_to_buffer(&query, " AND "); if(where_condition) rc = append_string_to_buffer(&query, " AND ");
snprintf(s, sizeof(s)-1, " `sent` <= %ld", stopdate); snprintf(s, sizeof(s)-1, " `sent` <= %lu", stopdate);
rc += append_string_to_buffer(&query, s); rc += append_string_to_buffer(&query, s);
where_condition++;
} }
@ -340,7 +332,6 @@ int export_emails_matching_to_query(struct session_data *sdata, char *s, struct
uint64 id, n=0; uint64 id, n=0;
char digest[SMALLBUFSIZE], bodydigest[SMALLBUFSIZE]; char digest[SMALLBUFSIZE], bodydigest[SMALLBUFSIZE];
char filename[SMALLBUFSIZE]; char filename[SMALLBUFSIZE];
int rc=0;
struct sql sql; struct sql sql;
if(prepare_sql_statement(sdata, &sql, s) == ERR) return ERR; if(prepare_sql_statement(sdata, &sql, s) == ERR) return ERR;
@ -410,7 +401,7 @@ ENDE:
int main(int argc, char **argv){ int main(int argc, char **argv){
int c, minsize=0, maxsize=0; int minsize=0, maxsize=0;
size_t nmatch=0; size_t nmatch=0;
unsigned long startdate=0, stopdate=0; unsigned long startdate=0, stopdate=0;
char *configfile=CONFIG_FILE; char *configfile=CONFIG_FILE;
@ -451,9 +442,9 @@ int main(int argc, char **argv){
int option_index = 0; int option_index = 0;
c = getopt_long(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?", long_options, &option_index); int c = getopt_long(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?", long_options, &option_index);
#else #else
c = getopt(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?"); int c = getopt(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?");
#endif #endif
if(c == -1) break; if(c == -1) break;