2011-11-30 23:42:15 +01:00
|
|
|
/*
|
|
|
|
* pilerget.c, SJ
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-12-28 15:30:53 +01:00
|
|
|
#include <sys/time.h>
|
2011-11-30 23:42:15 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2011-12-28 15:30:53 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include <locale.h>
|
2011-11-30 23:42:15 +01:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <piler.h>
|
|
|
|
|
|
|
|
|
2011-12-28 15:30:53 +01:00
|
|
|
|
2011-12-29 12:11:28 +01:00
|
|
|
uint64 get_id_by_piler_id(struct session_data *sdata, char *digest, char *bodydigest, struct __config *cfg){
|
|
|
|
char s[SMALLBUFSIZE];
|
|
|
|
MYSQL_STMT *stmt;
|
|
|
|
MYSQL_BIND bind[3];
|
|
|
|
unsigned long len=0;
|
|
|
|
uint64 id=0;
|
|
|
|
|
|
|
|
memset(digest, 0, 2*DIGEST_LENGTH+1);
|
|
|
|
memset(bodydigest, 0, 2*DIGEST_LENGTH+1);
|
|
|
|
|
|
|
|
snprintf(s, SMALLBUFSIZE-1, "SELECT `id`,`digest`,`bodydigest` FROM %s WHERE piler_id=?", SQL_METADATA_TABLE);
|
|
|
|
|
2012-02-07 17:21:23 +01:00
|
|
|
if(prepare_a_mysql_statement(sdata, &stmt, s) == ERR) goto ENDE;
|
2011-12-29 12:11:28 +01:00
|
|
|
|
|
|
|
memset(bind, 0, sizeof(bind));
|
|
|
|
|
|
|
|
bind[0].buffer_type = MYSQL_TYPE_STRING;
|
|
|
|
bind[0].buffer = sdata->ttmpfile;
|
|
|
|
bind[0].is_null = 0;
|
|
|
|
len = strlen(sdata->ttmpfile); bind[0].length = &len;
|
|
|
|
|
|
|
|
|
|
|
|
if(mysql_stmt_bind_param(stmt, bind)){
|
2012-01-29 09:02:21 +01:00
|
|
|
goto CLOSE;
|
2011-12-29 12:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(mysql_stmt_execute(stmt)){
|
2012-01-29 09:02:21 +01:00
|
|
|
goto CLOSE;
|
2011-12-29 12:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memset(bind, 0, sizeof(bind));
|
|
|
|
|
|
|
|
bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
|
|
|
|
bind[0].buffer = (char *)&id;
|
|
|
|
bind[0].is_null = 0;
|
|
|
|
bind[0].length = 0;
|
|
|
|
|
|
|
|
bind[1].buffer_type = MYSQL_TYPE_STRING;
|
|
|
|
bind[1].buffer = digest;
|
|
|
|
bind[1].buffer_length = 2*DIGEST_LENGTH+1;
|
|
|
|
bind[1].is_null = 0;
|
|
|
|
bind[1].length = &len;
|
|
|
|
|
|
|
|
bind[2].buffer_type = MYSQL_TYPE_STRING;
|
|
|
|
bind[2].buffer = bodydigest;
|
|
|
|
bind[2].buffer_length = 2*DIGEST_LENGTH+1;
|
|
|
|
bind[2].is_null = 0;
|
|
|
|
bind[2].length = &len;
|
|
|
|
|
|
|
|
if(mysql_stmt_bind_result(stmt, bind)){
|
2012-01-29 09:02:21 +01:00
|
|
|
goto CLOSE;
|
2011-12-29 12:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(mysql_stmt_store_result(stmt)){
|
2012-01-29 09:02:21 +01:00
|
|
|
goto CLOSE;
|
2011-12-29 12:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mysql_stmt_fetch(stmt);
|
|
|
|
|
2012-01-29 09:02:21 +01:00
|
|
|
|
|
|
|
CLOSE:
|
2011-12-29 12:11:28 +01:00
|
|
|
mysql_stmt_close(stmt);
|
|
|
|
|
|
|
|
ENDE:
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-27 20:51:56 +01:00
|
|
|
int main(int argc, char **argv){
|
2011-12-28 15:30:53 +01:00
|
|
|
int rc;
|
|
|
|
struct session_data sdata;
|
2011-12-27 20:51:56 +01:00
|
|
|
struct __config cfg;
|
|
|
|
|
|
|
|
|
2011-12-28 15:30:53 +01:00
|
|
|
if(argc < 2){
|
2011-12-29 21:25:40 +01:00
|
|
|
printf("usage: %s <piler-id>\n", argv[0]);
|
2011-12-28 15:30:53 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cfg = read_config(CONFIG_FILE);
|
|
|
|
|
2011-12-27 20:51:56 +01:00
|
|
|
|
|
|
|
if(read_key(&cfg)){
|
|
|
|
printf("%s\n", ERR_READING_KEY);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-28 15:30:53 +01:00
|
|
|
mysql_init(&(sdata.mysql));
|
|
|
|
mysql_options(&(sdata.mysql), MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&cfg.mysql_connect_timeout);
|
|
|
|
if(mysql_real_connect(&(sdata.mysql), cfg.mysqlhost, cfg.mysqluser, cfg.mysqlpwd, cfg.mysqldb, cfg.mysqlport, cfg.mysqlsocket, 0) == 0){
|
|
|
|
printf("cannot connect to mysql server\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mysql_real_query(&(sdata.mysql), "SET NAMES utf8", strlen("SET NAMES utf8"));
|
|
|
|
mysql_real_query(&(sdata.mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8"));
|
|
|
|
|
|
|
|
|
2012-01-07 23:26:47 +01:00
|
|
|
snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]);
|
|
|
|
snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", sdata.ttmpfile);
|
|
|
|
rc = retrieve_email_from_archive(&sdata, stdout, &cfg);
|
2011-12-27 20:51:56 +01:00
|
|
|
|
|
|
|
|
2011-12-28 15:30:53 +01:00
|
|
|
mysql_close(&(sdata.mysql));
|
2011-12-27 20:51:56 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-28 15:30:53 +01:00
|
|
|
|
|
|
|
|