summaryrefslogtreecommitdiffabout
path: root/src
authorMichael Krelin <hacker@klever.net>2009-04-04 23:28:48 (UTC)
committer Michael Krelin <hacker@klever.net>2009-04-05 00:40:46 (UTC)
commit6b71fd1e4edd46b7caf47135740c961d5d4f051c (patch) (side-by-side diff)
tree03dbdfb8fdbdf1c823af1a5bd32611d736f5ddf1 /src
parentaadaa8b5d7eda23e72dbded9d6437b40358353f3 (diff)
downloadiii-6b71fd1e4edd46b7caf47135740c961d5d4f051c.zip
iii-6b71fd1e4edd46b7caf47135740c961d5d4f051c.tar.gz
iii-6b71fd1e4edd46b7caf47135740c961d5d4f051c.tar.bz2
make upload directory if it doesn't exist
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyefiservice.cc1
-rw-r--r--src/eyetil.cc16
2 files changed, 16 insertions, 1 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc
index 30c06fa..97cb33b 100644
--- a/src/eyefiservice.cc
+++ b/src/eyefiservice.cc
@@ -99,49 +99,48 @@ int eyefiService::MarkLastPhotoInRoll(
syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str());
_exit(-1);
}
}
return SOAP_OK;
}
int eyefiService::UploadPhoto(
int fileid, std::string macaddress,
std::string filename, long filesize, std::string filesignature,
std::string encryption, int flags,
struct rns__UploadPhotoResponse& r ) {
#ifndef NDEBUG
syslog(LOG_DEBUG,
"UploadPhoto request from %s with fileid=%d, filename=%s, filesize=%ld,"
" filesignature=%s, encryption=%s, flags=%04X",
macaddress.c_str(), fileid, filename.c_str(), filesize,
filesignature.c_str(), encryption.c_str(), flags );
#endif
eyekinfig_t eyekinfig(macaddress);
umask(eyekinfig.get_umask());
std::string td = eyekinfig.get_targetdir();
- /* TODO: try to create, if needed */
tmpdir_t indir(td+"/.incoming.XXXXXX");
for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) {
#ifndef NDEBUG
syslog(LOG_DEBUG,
" MIME attachment with id=%s, type=%s, size=%ld",
(*i).id, (*i).type, (long)(*i).size );
#endif
#ifndef NDEBUG
if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) {
std::string idigest((*i).ptr,(*i).size);
syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigest.c_str());
}
#endif
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
tarchive_t a((*i).ptr,(*i).size);
diff --git a/src/eyetil.cc b/src/eyetil.cc
index d00c2ee..2fbd687 100644
--- a/src/eyetil.cc
+++ b/src/eyetil.cc
@@ -1,25 +1,26 @@
#include <stdlib.h>
+#include <sys/stat.h>
#include <syslog.h>
#include <iostream>
#include <cassert>
#include <stdexcept>
#include <openssl/md5.h>
#include "eyetil.h"
binary_t& binary_t::from_hex(const std::string& h) {
/* TODO: algorithmize */
std::string::size_type hs = h.length();
if(hs&1)
throw std::runtime_error("odd number of characters in hexadecimal number");
int rvs = hs>>1;
resize(rvs);
const unsigned char *hp = (const unsigned char*)h.data();
iterator oi=begin();
char t[3] = { 0,0,0 };
for(int i=0;i<rvs;++i) {
t[0]=*(hp++); t[1]=*(hp++);
*(oi++) = strtol(t,0,16);
}
return *this;
}
@@ -30,49 +31,64 @@ binary_t& binary_t::from_data(const void *d,size_t s) {
return *this;
}
std::string binary_t::hex() const {
std::string rv;
rv.reserve((size()<<1)+1);
char t[3] = {0,0,0};
for(const_iterator i=begin(),ie=end();i!=ie;++i) {
int rc = snprintf(t,sizeof(t),"%02x",*i);
assert(rc<sizeof(t));
rv += t;
}
return rv;
}
binary_t binary_t::md5() const {
binary_t rv(MD5_DIGEST_LENGTH);
if(!MD5(
(const unsigned char*)&(front()),size(),
(unsigned char*)&(rv.front()) ))
throw std::runtime_error("failed to md5()");
return rv;
}
+static void make_path_for_template(const std::string& p,mode_t m) {
+ struct stat st;
+ std::string pp;
+ for(std::string::size_type sl=p.find('/',1);
+ sl!=std::string::npos;
+ sl=p.find('/',sl+1)) {
+ if(stat( (pp=p.substr(0,sl)).c_str() ,&st)
+ || !S_ISDIR(st.st_mode)) {
+ if(mkdir(pp.c_str(),m))
+ throw std::runtime_error("failed to mkdir()");
+ }
+ }
+}
+
tmpdir_t::tmpdir_t(const std::string& dt) : dir(dt) {
+ make_path_for_template(dt,0777);
if(!mkdtemp((char*)dir.data()))
throw std::runtime_error("failed to mkdtmp()");
}
tmpdir_t::~tmpdir_t() {
assert(!dir.empty());
if(rmdir(dir.c_str())) {
syslog(LOG_WARNING,"Failed to remove '%s' directory",dir.c_str());
}
}
std::string tmpdir_t::get_file(const std::string& f) {
std::string::size_type ls = f.rfind('/');
return dir+'/'+(
(ls==std::string::npos)
? f
: f.substr(ls+1)
);
}
tarchive_t::tarchive_t(void *p,size_t s) : a(archive_read_new()), e(0) {
if(!a) throw std::runtime_error("failed to archive_read_new()");
if(archive_read_support_format_tar(a)) {
archive_read_finish(a);
throw std::runtime_error("failed to archive_read_support_format_tar()");