summaryrefslogtreecommitdiffabout
path: root/src
Unidiff
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
@@ -111,25 +111,24 @@ int eyefiService::UploadPhoto(
111#ifndef NDEBUG 111#ifndef NDEBUG
112 syslog(LOG_DEBUG, 112 syslog(LOG_DEBUG,
113 "UploadPhoto request from %s with fileid=%d, filename=%s, filesize=%ld," 113 "UploadPhoto request from %s with fileid=%d, filename=%s, filesize=%ld,"
114 " filesignature=%s, encryption=%s, flags=%04X", 114 " filesignature=%s, encryption=%s, flags=%04X",
115 macaddress.c_str(), fileid, filename.c_str(), filesize, 115 macaddress.c_str(), fileid, filename.c_str(), filesize,
116 filesignature.c_str(), encryption.c_str(), flags ); 116 filesignature.c_str(), encryption.c_str(), flags );
117#endif 117#endif
118 eyekinfig_t eyekinfig(macaddress); 118 eyekinfig_t eyekinfig(macaddress);
119 119
120 umask(eyekinfig.get_umask()); 120 umask(eyekinfig.get_umask());
121 121
122 std::string td = eyekinfig.get_targetdir(); 122 std::string td = eyekinfig.get_targetdir();
123 /* TODO: try to create, if needed */
124 tmpdir_t indir(td+"/.incoming.XXXXXX"); 123 tmpdir_t indir(td+"/.incoming.XXXXXX");
125 124
126 for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { 125 for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) {
127#ifndef NDEBUG 126#ifndef NDEBUG
128 syslog(LOG_DEBUG, 127 syslog(LOG_DEBUG,
129 " MIME attachment with id=%s, type=%s, size=%ld", 128 " MIME attachment with id=%s, type=%s, size=%ld",
130 (*i).id, (*i).type, (long)(*i).size ); 129 (*i).id, (*i).type, (long)(*i).size );
131#endif 130#endif
132 131
133#ifndef NDEBUG 132#ifndef NDEBUG
134 if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { 133 if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) {
135 std::string idigest((*i).ptr,(*i).size); 134 std::string idigest((*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,13 +1,14 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h>
2#include <syslog.h> 3#include <syslog.h>
3#include <iostream> 4#include <iostream>
4#include <cassert> 5#include <cassert>
5#include <stdexcept> 6#include <stdexcept>
6#include <openssl/md5.h> 7#include <openssl/md5.h>
7#include "eyetil.h" 8#include "eyetil.h"
8 9
9binary_t& binary_t::from_hex(const std::string& h) { 10binary_t& binary_t::from_hex(const std::string& h) {
10 /* TODO: algorithmize */ 11 /* TODO: algorithmize */
11 std::string::size_type hs = h.length(); 12 std::string::size_type hs = h.length();
12 if(hs&1) 13 if(hs&1)
13 throw std::runtime_error("odd number of characters in hexadecimal number"); 14 throw std::runtime_error("odd number of characters in hexadecimal number");
@@ -42,25 +43,40 @@ std::string binary_t::hex() const {
42 return rv; 43 return rv;
43} 44}
44 45
45binary_t binary_t::md5() const { 46binary_t binary_t::md5() const {
46 binary_t rv(MD5_DIGEST_LENGTH); 47 binary_t rv(MD5_DIGEST_LENGTH);
47 if(!MD5( 48 if(!MD5(
48 (const unsigned char*)&(front()),size(), 49 (const unsigned char*)&(front()),size(),
49 (unsigned char*)&(rv.front()) )) 50 (unsigned char*)&(rv.front()) ))
50 throw std::runtime_error("failed to md5()"); 51 throw std::runtime_error("failed to md5()");
51 return rv; 52 return rv;
52} 53}
53 54
55static void make_path_for_template(const std::string& p,mode_t m) {
56 struct stat st;
57 std::string pp;
58 for(std::string::size_type sl=p.find('/',1);
59 sl!=std::string::npos;
60 sl=p.find('/',sl+1)) {
61 if(stat( (pp=p.substr(0,sl)).c_str() ,&st)
62 || !S_ISDIR(st.st_mode)) {
63 if(mkdir(pp.c_str(),m))
64 throw std::runtime_error("failed to mkdir()");
65 }
66 }
67}
68
54tmpdir_t::tmpdir_t(const std::string& dt) : dir(dt) { 69tmpdir_t::tmpdir_t(const std::string& dt) : dir(dt) {
70 make_path_for_template(dt,0777);
55 if(!mkdtemp((char*)dir.data())) 71 if(!mkdtemp((char*)dir.data()))
56 throw std::runtime_error("failed to mkdtmp()"); 72 throw std::runtime_error("failed to mkdtmp()");
57} 73}
58tmpdir_t::~tmpdir_t() { 74tmpdir_t::~tmpdir_t() {
59 assert(!dir.empty()); 75 assert(!dir.empty());
60 if(rmdir(dir.c_str())) { 76 if(rmdir(dir.c_str())) {
61 syslog(LOG_WARNING,"Failed to remove '%s' directory",dir.c_str()); 77 syslog(LOG_WARNING,"Failed to remove '%s' directory",dir.c_str());
62 } 78 }
63} 79}
64 80
65std::string tmpdir_t::get_file(const std::string& f) { 81std::string tmpdir_t::get_file(const std::string& f) {
66 std::string::size_type ls = f.rfind('/'); 82 std::string::size_type ls = f.rfind('/');