author | Michael Krelin <hacker@klever.net> | 2011-08-30 20:52:04 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-08-30 20:52:04 (UTC) |
commit | 55bdd80087710b94e747a622fad8bd0ee3e3dec3 (patch) (unidiff) | |
tree | 6d4b8ab76b18c7f6e3d6d2823470c8662cbdf8f5 | |
parent | 77706495aa0cc1706cfe1535b40477e004312081 (diff) | |
download | iii-55bdd80087710b94e747a622fad8bd0ee3e3dec3.zip iii-55bdd80087710b94e747a622fad8bd0ee3e3dec3.tar.gz iii-55bdd80087710b94e747a622fad8bd0ee3e3dec3.tar.bz2 |
updated list of supported suffixes
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | src/eyefiservice.cc | 6 |
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,37 +1,38 @@ | |||
1 | #include <cassert> | 1 | #include <cassert> |
2 | #include <iostream> | 2 | #include <iostream> |
3 | #include <fstream> | 3 | #include <fstream> |
4 | #include <stdexcept> | 4 | #include <stdexcept> |
5 | #include <iterator> | 5 | #include <iterator> |
6 | #include <algorithm> | ||
6 | #include <syslog.h> | 7 | #include <syslog.h> |
7 | #include <sys/wait.h> | 8 | #include <sys/wait.h> |
8 | #include <autosprintf.h> | 9 | #include <autosprintf.h> |
9 | #include "eyekinfig.h" | 10 | #include "eyekinfig.h" |
10 | #include "eyetil.h" | 11 | #include "eyetil.h" |
11 | #include "soapeyefiService.h" | 12 | #include "soapeyefiService.h" |
12 | 13 | ||
13 | static binary_t session_nonce; | 14 | static binary_t session_nonce; |
14 | 15 | ||
15 | static bool detached_child() { | 16 | static bool detached_child() { |
16 | pid_t p = fork(); | 17 | pid_t p = fork(); |
17 | if(p<0) { | 18 | if(p<0) { |
18 | syslog(LOG_ERR,"Failed to fork away for hook execution"); | 19 | syslog(LOG_ERR,"Failed to fork away for hook execution"); |
19 | _exit(-1); | 20 | _exit(-1); |
20 | } | 21 | } |
21 | if(!p) { | 22 | if(!p) { |
22 | setsid(); | 23 | setsid(); |
23 | for(int i=getdtablesize();i>=0;--i) close(i); | 24 | for(int i=getdtablesize();i>=0;--i) close(i); |
24 | int i=open("/dev/null",O_RDWR); assert(i==0); | 25 | int i=open("/dev/null",O_RDWR); assert(i==0); |
25 | i = dup(i); assert(i==1); | 26 | i = dup(i); assert(i==1); |
26 | i = dup(i); assert(i==2); | 27 | i = dup(i); assert(i==2); |
27 | return true; | 28 | return true; |
28 | } | 29 | } |
29 | return false; | 30 | return false; |
30 | } | 31 | } |
31 | 32 | ||
32 | int eyefiService::StartSession( | 33 | int eyefiService::StartSession( |
33 | std::string macaddress,std::string cnonce, | 34 | std::string macaddress,std::string cnonce, |
34 | int transfermode,long transfermodetimestamp, | 35 | int transfermode,long transfermodetimestamp, |
35 | struct rns__StartSessionResponse &r ) try { | 36 | struct rns__StartSessionResponse &r ) try { |
36 | #ifndef NDEBUG | 37 | #ifndef NDEBUG |
37 | syslog(LOG_DEBUG, | 38 | syslog(LOG_DEBUG, |
@@ -139,65 +140,68 @@ int eyefiService::UploadPhoto( | |||
139 | (*i).id, (*i).type, (long)(*i).size ); | 140 | (*i).id, (*i).type, (long)(*i).size ); |
140 | #endif | 141 | #endif |
141 | 142 | ||
142 | if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { | 143 | if((*i).id && !strcmp((*i).id,"INTEGRITYDIGEST")) { |
143 | std::string idigestr((*i).ptr,(*i).size); | 144 | std::string idigestr((*i).ptr,(*i).size); |
144 | #ifndef NDEBUG | 145 | #ifndef NDEBUG |
145 | syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigestr.c_str()); | 146 | syslog(LOG_DEBUG, " INTEGRITYDIGEST=%s", idigestr.c_str()); |
146 | #endif | 147 | #endif |
147 | idigest.from_hex(idigestr); | 148 | idigest.from_hex(idigestr); |
148 | } | 149 | } |
149 | if( (*i).id && !strcmp((*i).id,"FILENAME") ) { | 150 | if( (*i).id && !strcmp((*i).id,"FILENAME") ) { |
150 | assert( (*i).type && !strcmp((*i).type,"application/x-tar") ); | 151 | assert( (*i).type && !strcmp((*i).type,"application/x-tar") ); |
151 | #ifdef III_SAVE_TARS | 152 | #ifdef III_SAVE_TARS |
152 | std::string tarfile = indir.get_file(filename); | 153 | std::string tarfile = indir.get_file(filename); |
153 | { | 154 | { |
154 | std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size); | 155 | std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size); |
155 | } | 156 | } |
156 | #endif | 157 | #endif |
157 | 158 | ||
158 | if(!tf.empty()) throw std::runtime_error("already seen tarball"); | 159 | if(!tf.empty()) throw std::runtime_error("already seen tarball"); |
159 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); | 160 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); |
160 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); | 161 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); |
161 | #ifndef NDEBUG | 162 | #ifndef NDEBUG |
162 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); | 163 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); |
163 | #endif | 164 | #endif |
164 | 165 | ||
165 | tarchive_t a((*i).ptr,(*i).size); | 166 | tarchive_t a((*i).ptr,(*i).size); |
166 | while(a.read_next_header()) { | 167 | while(a.read_next_header()) { |
167 | std::string f = indir.get_file(a.entry_pathname()); | 168 | std::string f = indir.get_file(a.entry_pathname()); |
168 | std::string::size_type fl = f.length(); | 169 | std::string::size_type fl = f.length(); |
169 | if(fl<4) continue; | 170 | if(fl<4) continue; |
170 | const char *s = f.c_str()+fl-4; | 171 | const char *s = f.c_str()+fl-4; |
171 | if(!(strcasecmp(s,".JPG") && strcasecmp(s,".AVI"))) | 172 | static const char *suffixes[] = { ".JPG",".AVI",".MP4",".NEF",".RAW",".TIF" }; |
173 | if(std::find_if(suffixes,suffixes+sizeof(suffixes)/sizeof(*suffixes), | ||
174 | std::not1(std::bind1st(std::ptr_fun(strcasecmp),s))) | ||
175 | != suffixes+sizeof(suffixes)/sizeof(*suffixes)) | ||
172 | tf = f; | 176 | tf = f; |
173 | else if(!strcasecmp(s,".log")) | 177 | else if(!strcasecmp(s,".log")) |
174 | lf = f; | 178 | lf = f; |
175 | else continue; | 179 | else continue; |
176 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); | 180 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); |
177 | if(fd<0) | 181 | if(fd<0) |
178 | throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str())); | 182 | throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str())); |
179 | if(!a.read_data_into_fd(fd)) | 183 | if(!a.read_data_into_fd(fd)) |
180 | throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str())); | 184 | throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str())); |
181 | close(fd); | 185 | close(fd); |
182 | } | 186 | } |
183 | } | 187 | } |
184 | } | 188 | } |
185 | 189 | ||
186 | if(tf.empty()) throw std::runtime_error("haven't seen THE file"); | 190 | if(tf.empty()) throw std::runtime_error("haven't seen THE file"); |
187 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); | 191 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); |
188 | 192 | ||
189 | std::string::size_type ls = tf.rfind('/'); | 193 | std::string::size_type ls = tf.rfind('/'); |
190 | // XXX: actually, lack of '/' signifies error here | 194 | // XXX: actually, lack of '/' signifies error here |
191 | std::string tbn = (ls==std::string::npos)?tf:tf.substr(ls+1); | 195 | std::string tbn = (ls==std::string::npos)?tf:tf.substr(ls+1); |
192 | ls = lf.rfind('/'); | 196 | ls = lf.rfind('/'); |
193 | std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1); | 197 | std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1); |
194 | std::string ttf,tlf; | 198 | std::string ttf,tlf; |
195 | bool success = false; | 199 | bool success = false; |
196 | for(int i=0;i<32767;++i) { | 200 | for(int i=0;i<32767;++i) { |
197 | const char *fmt = i ? "%1$s/(%3$05d)%2$s" : "%1$s/%2$s"; | 201 | const char *fmt = i ? "%1$s/(%3$05d)%2$s" : "%1$s/%2$s"; |
198 | ttf = (const char*)gnu::autosprintf(fmt,td.c_str(),tbn.c_str(),i); | 202 | ttf = (const char*)gnu::autosprintf(fmt,td.c_str(),tbn.c_str(),i); |
199 | if(!lf.empty()) tlf = (const char*)gnu::autosprintf(fmt,td.c_str(),lbn.c_str(),i); | 203 | if(!lf.empty()) tlf = (const char*)gnu::autosprintf(fmt,td.c_str(),lbn.c_str(),i); |
200 | if( (!link(tf.c_str(),ttf.c_str())) && (lf.empty()) || !link(lf.c_str(),tlf.c_str()) ) { | 204 | if( (!link(tf.c_str(),ttf.c_str())) && (lf.empty()) || !link(lf.c_str(),tlf.c_str()) ) { |
201 | unlink(tf.c_str()); | 205 | unlink(tf.c_str()); |
202 | if(!lf.empty()) unlink(lf.c_str()); | 206 | if(!lf.empty()) unlink(lf.c_str()); |
203 | success=true; | 207 | success=true; |