2012-10-03 23:27:33 +02:00
|
|
|
/*
|
|
|
|
* pileraget.c, SJ
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <piler.h>
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv){
|
2012-11-03 23:42:36 +01:00
|
|
|
int readkey=1;
|
2012-10-03 23:27:33 +02:00
|
|
|
char filename[SMALLBUFSIZE];
|
2015-02-14 19:47:40 +01:00
|
|
|
#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT
|
2012-12-15 09:57:24 +01:00
|
|
|
struct stat st;
|
2015-02-14 19:47:40 +01:00
|
|
|
#endif
|
2012-10-03 23:27:33 +02:00
|
|
|
struct __config cfg;
|
|
|
|
|
|
|
|
|
|
|
|
if(argc < 3){
|
|
|
|
printf("usage: %s <piler-id> <attachment-id>\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cfg = read_config(CONFIG_FILE);
|
|
|
|
|
|
|
|
if(argc >= 4) readkey = 0;
|
|
|
|
|
|
|
|
if(readkey == 1 && read_key(&cfg)){
|
|
|
|
printf("%s\n", ERR_READING_KEY);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(strlen(argv[1]) != RND_STR_LEN){
|
|
|
|
printf("invalid piler id: '%s'\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-15 20:58:58 +01:00
|
|
|
snprintf(filename, sizeof(filename)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg.queuedir, cfg.server_id, argv[1][8], argv[1][9], argv[1][10], argv[1][RND_STR_LEN-4], argv[1][RND_STR_LEN-3], argv[1][RND_STR_LEN-2], argv[1][RND_STR_LEN-1], argv[1], atoi(argv[2]));
|
2015-02-01 10:40:18 +01:00
|
|
|
#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT
|
2012-12-15 09:57:24 +01:00
|
|
|
if(stat(filename, &st)){
|
2013-02-15 20:58:58 +01:00
|
|
|
snprintf(filename, sizeof(filename)-1, "%s/%02x/%c%c/%c%c/%c%c/%s.a%d", cfg.queuedir, cfg.server_id, argv[1][RND_STR_LEN-6], argv[1][RND_STR_LEN-5], argv[1][RND_STR_LEN-4], argv[1][RND_STR_LEN-3], argv[1][RND_STR_LEN-2], argv[1][RND_STR_LEN-1], argv[1], atoi(argv[2]));
|
2012-12-15 09:57:24 +01:00
|
|
|
}
|
2015-02-01 10:40:18 +01:00
|
|
|
#endif
|
2012-10-03 23:27:33 +02:00
|
|
|
|
2012-11-03 23:42:36 +01:00
|
|
|
retrieve_file_from_archive(filename, WRITE_TO_STDOUT, NULL, stdout, &cfg);
|
2012-10-03 23:27:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|