| 227 | } |
| 228 | |
| 229 | optional<Track> ParseTrackArchiveData(string const & content, TemporaryFile & tmpArchiveFile) |
| 230 | { |
| 231 | string binaryData = FromHex(content); |
| 232 | optional<string> archiveBody; |
| 233 | |
| 234 | if (HasZipSignature(binaryData)) |
| 235 | { |
| 236 | archiveBody = binaryData; |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | archiveBody = ParseMultipartData(binaryData); |
| 241 | if (!archiveBody) |
| 242 | { |
| 243 | LOG(LERROR, ("Bad HTTP body (expect multipart/form-data or application/zip):", content)); |
| 244 | return nullopt; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | tmpArchiveFile.WriteData(*archiveBody); |
| 249 | |
| 250 | unzip::File zipReader = unzip::Open(tmpArchiveFile.GetFilePath().c_str()); |
| 251 | |
| 252 | Track trackData; |
| 253 | |
| 254 | bool result = ParseTrackFile(zipReader, trackData); |
| 255 | while (result && unzip::GoToNextFile(zipReader) == unzip::Code::Ok) |
| 256 | result = ParseTrackFile(zipReader, trackData); |
| 257 | |
| 258 | if (unzip::Close(zipReader) != unzip::Code::Ok) |
| 259 | LOG(LERROR, ("Unable to close temporary zip archive")); |
| 260 | |
| 261 | return result ? optional<Track>(std::move(trackData)) : nullopt; |
| 262 | } |
| 263 | |
| 264 | optional<UserTrackInfo> ParseLogRecord(string const & record, TemporaryFile & tmpArchiveFile) |
| 265 | { |
no test coverage detected