author | Michael Krelin <hacker@klever.net> | 2011-05-24 20:27:01 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-05-24 21:30:57 (UTC) |
commit | 09b6e86aaad70bc7488604b2e291d098a7de0eac (patch) (unidiff) | |
tree | 1f79c3eea40a555cc5f354563d55ee773f75a6c7 /src/eyefiservice.cc | |
parent | f9b17f10f8f43da6998bbd1fb13d3a48c35ec653 (diff) | |
download | iii-09b6e86aaad70bc7488604b2e291d098a7de0eac.zip iii-09b6e86aaad70bc7488604b2e291d098a7de0eac.tar.gz iii-09b6e86aaad70bc7488604b2e291d098a7de0eac.tar.bz2 |
don't whine there's no jpeg if there was avi
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | src/eyefiservice.cc | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index 4ca2777..d7f0f04 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc | |||
@@ -128,9 +128,9 @@ int eyefiService::UploadPhoto( | |||
128 | 128 | ||
129 | std::string td = eyekinfig.get_targetdir(); | 129 | std::string td = eyekinfig.get_targetdir(); |
130 | tmpdir_t indir(td+"/.incoming.XXXXXX"); | 130 | tmpdir_t indir(td+"/.incoming.XXXXXX"); |
131 | 131 | ||
132 | std::string jf,lf; | 132 | std::string tf,lf; |
133 | binary_t digest, idigest; | 133 | binary_t digest, idigest; |
134 | 134 | ||
135 | for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { | 135 | for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { |
136 | #ifndef NDEBUG | 136 | #ifndef NDEBUG |
@@ -154,9 +154,9 @@ int eyefiService::UploadPhoto( | |||
154 | std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size); | 154 | std::ofstream(tarfile.c_str(),std::ios::out|std::ios::binary).write((*i).ptr,(*i).size); |
155 | } | 155 | } |
156 | #endif | 156 | #endif |
157 | 157 | ||
158 | if(!jf.empty()) throw std::runtime_error("already seen tarball"); | 158 | if(!tf.empty()) throw std::runtime_error("already seen tarball"); |
159 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); | 159 | if(!digest.empty()) throw std::runtime_error("already have integrity digest"); |
160 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); | 160 | digest = integrity_digest((*i).ptr,(*i).size,eyekinfig.get_upload_key()); |
161 | #ifndef NDEBUG | 161 | #ifndef NDEBUG |
162 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); | 162 | syslog(LOG_DEBUG," computed integrity digest=%s", digest.hex().c_str()); |
@@ -167,10 +167,10 @@ int eyefiService::UploadPhoto( | |||
167 | std::string f = indir.get_file(a.entry_pathname()); | 167 | std::string f = indir.get_file(a.entry_pathname()); |
168 | std::string::size_type fl = f.length(); | 168 | std::string::size_type fl = f.length(); |
169 | if(fl<4) continue; | 169 | if(fl<4) continue; |
170 | const char *s = f.c_str()+fl-4; | 170 | const char *s = f.c_str()+fl-4; |
171 | if(!strcasecmp(s,".JPG")) | 171 | if(!(strcasecmp(s,".JPG") && strcasecmp(s,".AVI"))) |
172 | jf = f; | 172 | tf = f; |
173 | else if(!strcasecmp(s,".log")) | 173 | else if(!strcasecmp(s,".log")) |
174 | lf = f; | 174 | lf = f; |
175 | else continue; | 175 | else continue; |
176 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); | 176 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); |
@@ -182,35 +182,35 @@ int eyefiService::UploadPhoto( | |||
182 | } | 182 | } |
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | if(jf.empty()) throw std::runtime_error("haven't seen jpeg file"); | 186 | if(tf.empty()) throw std::runtime_error("haven't seen THE file"); |
187 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); | 187 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); |
188 | 188 | ||
189 | std::string::size_type ls = jf.rfind('/'); | 189 | std::string::size_type ls = tf.rfind('/'); |
190 | // XXX: actually, lack of '/' signifies error here | 190 | // XXX: actually, lack of '/' signifies error here |
191 | std::string jbn = (ls==std::string::npos)?jf:jf.substr(ls+1); | 191 | std::string tbn = (ls==std::string::npos)?tf:tf.substr(ls+1); |
192 | ls = lf.rfind('/'); | 192 | ls = lf.rfind('/'); |
193 | std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1); | 193 | std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1); |
194 | std::string tjf,tlf; | 194 | std::string ttf,tlf; |
195 | bool success = false; | 195 | bool success = false; |
196 | for(int i=0;i<32767;++i) { | 196 | for(int i=0;i<32767;++i) { |
197 | const char *fmt = i ? "%1$s/(%3$05d)%2$s" : "%1$s/%2$s"; | 197 | const char *fmt = i ? "%1$s/(%3$05d)%2$s" : "%1$s/%2$s"; |
198 | tjf = (const char*)gnu::autosprintf(fmt,td.c_str(),jbn.c_str(),i); | 198 | 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); | 199 | if(!lf.empty()) tlf = (const char*)gnu::autosprintf(fmt,td.c_str(),lbn.c_str(),i); |
200 | if( (!link(jf.c_str(),tjf.c_str())) && (lf.empty()) || !link(lf.c_str(),tlf.c_str()) ) { | 200 | if( (!link(tf.c_str(),ttf.c_str())) && (lf.empty()) || !link(lf.c_str(),tlf.c_str()) ) { |
201 | unlink(jf.c_str()); | 201 | unlink(tf.c_str()); |
202 | if(!lf.empty()) unlink(lf.c_str()); | 202 | if(!lf.empty()) unlink(lf.c_str()); |
203 | success=true; | 203 | success=true; |
204 | break; | 204 | break; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | std::string cmd = eyekinfig.get_on_upload_photo(); | 207 | std::string cmd = eyekinfig.get_on_upload_photo(); |
208 | if(success && !cmd.empty()) { | 208 | if(success && !cmd.empty()) { |
209 | if(detached_child()) { | 209 | if(detached_child()) { |
210 | putenv( gnu::autosprintf("EYEFI_UPLOADED_ORIG=%s",jbn.c_str()) ); | 210 | putenv( gnu::autosprintf("EYEFI_UPLOADED_ORIG=%s",tbn.c_str()) ); |
211 | putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); | 211 | putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); |
212 | putenv( gnu::autosprintf("EYEFI_UPLOADED=%s",tjf.c_str()) ); | 212 | putenv( gnu::autosprintf("EYEFI_UPLOADED=%s",ttf.c_str()) ); |
213 | if(!lf.empty()) putenv( gnu::autosprintf("EYEFI_LOG=%s",tlf.c_str()) ); | 213 | if(!lf.empty()) putenv( gnu::autosprintf("EYEFI_LOG=%s",tlf.c_str()) ); |
214 | char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; | 214 | char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; |
215 | execv("/bin/sh",argv); | 215 | execv("/bin/sh",argv); |
216 | syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); | 216 | syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); |