QString Content::GetHash( const QString &sStorageGroup, const QString &sFileName ) { if ((sFileName.isEmpty()) || (sFileName.contains("/../")) || (sFileName.startsWith("../"))) { LOG(VB_GENERAL, LOG_ERR, QString("ERROR checking for file, filename '%1' " "fails sanity checks").arg(sFileName)); return QString(); } QString storageGroup = "Default"; if (!sStorageGroup.isEmpty()) storageGroup = sStorageGroup; StorageGroup sgroup(storageGroup, gCoreContext->GetHostName()); QString fullname = sgroup.FindFile(sFileName); QString hash = FileHash(fullname); if (hash == "NULL") return QString(); return hash; }
QString VideoMetadata::VideoFileHash(const QString &file_name, const QString &host) { if (!host.isEmpty() && !isHostMaster(host)) { QString url = generate_file_url("Videos", host, file_name); return RemoteFile::GetFileHash(url); } else if (!host.isEmpty()) { StorageGroup sgroup("Videos", host); QString fullname = sgroup.FindFile(file_name); return FileHash(fullname); } else return FileHash(file_name); }
bool Video::AddVideo( const QString &sFilename, const QString &sHost ) { if ( sHost.isEmpty() ) throw( QString( "Host not provided! Local storage is deprecated and " "is not supported by the API." )); if ( sFilename.isEmpty() || (sFilename.contains("/../")) || (sFilename.startsWith("../")) ) { throw( QString( "Filename not provided, or fails sanity checks!" )); } StorageGroup sgroup("Videos", sHost); QString fullname = sgroup.FindFile(sFilename); if ( !QFile::exists(fullname) ) throw( QString( "Provided filename does not exist!" )); QString hash = FileHash(fullname); if (hash == "NULL") { VERBOSE(VB_GENERAL, QString("Video Hash Failed. Unless this is a DVD " "or Blu-ray, something has probably gone " "wrong.")); hash = ""; } VideoMetadata newFile(sFilename, hash, VIDEO_TRAILER_DEFAULT, VIDEO_COVERFILE_DEFAULT, VIDEO_SCREENSHOT_DEFAULT, VIDEO_BANNER_DEFAULT, VIDEO_FANART_DEFAULT, VideoMetadata::FilenameToMeta(sFilename, 1), VideoMetadata::FilenameToMeta(sFilename, 4), QString(), VIDEO_YEAR_DEFAULT, QDate::fromString("0000-00-00","YYYY-MM-DD"), VIDEO_INETREF_DEFAULT, QString(), VIDEO_DIRECTOR_DEFAULT, QString(), VIDEO_PLOT_DEFAULT, 0.0, VIDEO_RATING_DEFAULT, 0, VideoMetadata::FilenameToMeta(sFilename, 2).toInt(), VideoMetadata::FilenameToMeta(sFilename, 3).toInt(), QDate::currentDate(), 0, ParentalLevel::plLowest); newFile.SetHost(sHost); newFile.SaveToDatabase(); return true; }
//Returns true on success, false on error bool listImages(const bf::path &dir, //Root directory std::vector<FileHash> &files) { if(!exists(dir)) return false; bf::directory_iterator endIt; //Default dir_iter constructor yields after the end for(bf::directory_iterator it(dir); it != endIt; ++it) { if(bf::is_directory(it->status())) { listImages(it->path(), files); } else { if(checkPathExtension(it->path())) { files.push_back(FileHash(it->path().string())); } } } return true; }
static void UpdateHashes(void) { MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT `filename`, `host` FROM videometadata WHERE " "`hash` = \"\""); if (query.exec() && query.size()) { while (query.next()) { QString filename = query.value(0).toString(); QString host = query.value(1).toString(); QString hash; if (!host.isEmpty()) { QString url = generate_file_url("Videos", host, filename); hash = RemoteFile::GetFileHash(url); } else hash = FileHash(filename); if (hash == "NULL") hash = QString(); MSqlQuery updatequery(MSqlQuery::InitCon()); updatequery.prepare("UPDATE videometadata set `hash` = :HASH " "WHERE `filename` = :FILENAME AND " "`host` = :HOST"); updatequery.bindValue(":HASH", hash); updatequery.bindValue(":FILENAME", filename); updatequery.bindValue(":HOST", host); if (!updatequery.exec()) MythDB::DBError(QObject::tr("Error: failed to hash file " "'%1'").arg(filename), updatequery); else LOG(VB_GENERAL, LOG_INFO, QString("Hash (%1) generated for file (%2)") .arg(hash).arg(filename)); } } }
void SubFileItem::cancel() { #ifdef DEBUG_ITEM std::cerr << "SubFileItem::cancel()"; std::cerr << std::endl; #endif //set the state to error mode mMode = SFI_STATE_ERROR; /* Only occurs - if it is downloading */ if (((mType == SFI_TYPE_ATTACH) || (mType == SFI_TYPE_CHANNEL)) && (mFlag & SFI_FLAG_CREATE)) { hide(); rsFiles->ExtraFileRemove(FileHash(), RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA); mPath = ""; } else { rsFiles->FileCancel(mFileHash); } updateItem(); }
/** * \addtogroup myth_network_protocol * \par QUERY_FILE_HASH \e storagegroup \e filename */ bool FileServerHandler::HandleQueryFileHash(SocketHandler *socket, QStringList &slist) { QString storageGroup = "Default"; QString hostname = gCoreContext->GetHostName(); QString filename = ""; QStringList res; switch (slist.size()) { case 4: if (!slist[3].isEmpty()) hostname = slist[3]; case 3: if (!slist[2].isEmpty()) storageGroup = slist[2]; case 2: filename = slist[1]; if (filename.isEmpty() || filename.contains("/../") || filename.startsWith("../")) { LOG(VB_GENERAL, LOG_ERR, QString("ERROR checking for file, filename '%1' " "fails sanity checks").arg(filename)); res << ""; socket->SendStringList(res); return true; } break; default: return false; } QString hash = ""; if (hostname == gCoreContext->GetHostName()) { // looking for file on me, return directly StorageGroup sgroup(storageGroup, gCoreContext->GetHostName()); QString fullname = sgroup.FindFile(filename); hash = FileHash(fullname); } else { QReadLocker rlock(&m_fsLock); if (m_fsMap.contains(hostname)) { // looking for file on connected host, query from it if (m_fsMap[hostname]->SendReceiveStringList(slist)) hash = slist[0]; } else { // looking for file on unknown host // assume host is an IP address, and look for matching // entry in database MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT hostname FROM settings " "WHERE value='BackendServerIP' " " OR value='BackendServerIP6' " "AND data=:HOSTNAME;"); query.bindValue(":HOSTNAME", hostname); if (query.exec() && query.next()) { // address matches an entry hostname = query.value(0).toString(); if (m_fsMap.contains(hostname)) { // entry matches a connection slist.clear(); slist << "QUERY_FILE_HASH" << filename << storageGroup; if (m_fsMap[hostname]->SendReceiveStringList(slist)) hash = slist[0]; } } } } res << hash; socket->SendStringList(res); return true; }
int main(int argc, char **argv) { int encryption = 0; int decryption = 0; int hashmode = 0; int c; char *fvalue = NULL; char *pvalue = NULL; char *ovalue = NULL; opterr = 0; while ((c = getopt(argc, argv, "hedf:p:o:")) != -1) { switch (c) { case 'e': encryption = 1; break; case 'd': decryption = 1; break; case 'f': fvalue = optarg; break; case 'p': pvalue = optarg; break; case 'o': ovalue = optarg; break; case 'h': hashmode = 1; break; case '?': if (optopt == 'f' || optopt == 'p') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option -%c\n", optopt); } return ARG_ERROR; default: abort(); } } if (!fvalue) { fprintf(stderr, "error: option -f is required\n"); return ARG_ERROR; } if (hashmode) { FileHash(fvalue); } else { if (encryption && decryption) { fprintf(stderr, "options -e and -d are mutually exclusive\n"); return ARG_ERROR; } if (!encryption && !decryption) { fprintf(stderr, "encrypt (option -e) or decrypt (option -d) file?\n"); return ARG_ERROR; } if (!pvalue || !ovalue) { fprintf(stderr, "options -p and -o are required\n"); return ARG_ERROR; } if(!FileTransformation(fvalue, ovalue, pvalue, encryption)) { fprintf(stderr, "done: success\n"); } else { fprintf(stderr, "file transformation aborted\n"); return 1; } } return SUCCESS; }