summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2011-08-30 20:52:04 (UTC)
committer Michael Krelin <hacker@klever.net>2011-08-30 20:52:04 (UTC)
commit55bdd80087710b94e747a622fad8bd0ee3e3dec3 (patch) (side-by-side diff)
tree6d4b8ab76b18c7f6e3d6d2823470c8662cbdf8f5
parent77706495aa0cc1706cfe1535b40477e004312081 (diff)
downloadiii-55bdd80087710b94e747a622fad8bd0ee3e3dec3.zip
iii-55bdd80087710b94e747a622fad8bd0ee3e3dec3.tar.gz
iii-55bdd80087710b94e747a622fad8bd0ee3e3dec3.tar.bz2
updated list of supported suffixes
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyefiservice.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc
index d7f0f04..77526b9 100644
--- a/src/eyefiservice.cc
+++ b/src/eyefiservice.cc
@@ -1,29 +1,30 @@
#include <cassert>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <iterator>
+#include <algorithm>
#include <syslog.h>
#include <sys/wait.h>
#include <autosprintf.h>
#include "eyekinfig.h"
#include "eyetil.h"
#include "soapeyefiService.h"
static binary_t session_nonce;
static bool detached_child() {
pid_t p = fork();
if(p<0) {
syslog(LOG_ERR,"Failed to fork away for hook execution");
_exit(-1);
}
if(!p) {
setsid();
for(int i=getdtablesize();i>=0;--i) close(i);
int i=open("/dev/null",O_RDWR); assert(i==0);
i = dup(i); assert(i==1);
i = dup(i); assert(i==2);
return true;
}
return false;
@@ -147,49 +148,52 @@ int eyefiService::UploadPhoto(
idigest.from_hex(idigestr);
}
if( (*i).id && !strcmp((*i).id,"FILENAME") ) {
assert( (*i).type && !strcmp((*i).type,"application/x-tar") );
#ifdef III_SAVE_TARS
std::string tarfile = indir.get_file(filename);
{
std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size);
}
#endif
if(!tf.empty()) throw std::runtime_error("already seen tarball");
if(!digest.empty()) throw std::runtime_error("already have integrity digest");
digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key());
#ifndef NDEBUG
syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str());
#endif
tarchive_t a((*i).ptr,(*i).size);
while(a.read_next_header()) {
std::string f = indir.get_file(a.entry_pathname());
std::string::size_type fl = f.length();
if(fl<4) continue;
const char *s = f.c_str()+fl-4;
- if(!(strcasecmp(s,".JPG") && strcasecmp(s,".AVI")))
+ static const char *suffixes[] = { ".JPG",".AVI",".MP4",".NEF",".RAW",".TIF" };
+ if(std::find_if(suffixes,suffixes+sizeof(suffixes)/sizeof(*suffixes),
+ std::not1(std::bind1st(std::ptr_fun(strcasecmp),s)))
+ != suffixes+sizeof(suffixes)/sizeof(*suffixes))
tf = f;
else if(!strcasecmp(s,".log"))
lf = f;
else continue;
int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666);
if(fd<0)
throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str()));
if(!a.read_data_into_fd(fd))
throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str()));
close(fd);
}
}
}
if(tf.empty()) throw std::runtime_error("haven't seen THE file");
if(digest!=idigest) throw std::runtime_error("integrity digest verification failed");
std::string::size_type ls = tf.rfind('/');
// XXX: actually, lack of '/' signifies error here
std::string tbn = (ls==std::string::npos)?tf:tf.substr(ls+1);
ls = lf.rfind('/');
std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1);
std::string ttf,tlf;
bool success = false;