ird::loadIrdFile( const std::string& path ) { IRDFile *ird = readIRD( path.c_str() ); FileList *list = buildFileListFromIRD("", ird); unsigned int *hash = (unsigned int *) getFileHash(ird, list); printf("Hash for file %s is : %X%X%X%X\n", list->path, hash[0], hash[1], hash[2], hash[3]); printf("\nPress ENTER to quit."); while (getchar() != '\n'); return 0; }
bool Repo::findFile(const char *path, const std::string &root, MD5& md5) { if (m_dbc == nullptr) { return false; } int repoId; for (repoId = RepoIdCount - 1; repoId >= 0; --repoId) { if (*path == '/' && !root.empty() && !strncmp(root.c_str(), path, root.size()) && getFileHash(repoId).get(path + root.size(), md5)) { TRACE(3, "Repo loaded file hash for '%s' from '%s'\n", path + root.size(), repoName(repoId).c_str()); return true; } if (getFileHash(repoId).get(path, md5)) { TRACE(3, "Repo loaded file hash for '%s' from '%s'\n", path, repoName(repoId).c_str()); return true; } } TRACE(3, "Repo file hash: error loading '%s'\n", path); return false; }
ProjectClip::ProjectClip(const QString &id, QIcon thumb, ClipController *controller, ProjectFolder* parent) : AbstractProjectItem(AbstractProjectItem::ClipItem, id, parent) , audioFrameCache() , m_controller(controller) , m_gpuProducer(NULL) , m_abortAudioThumb(false) { m_clipStatus = StatusReady; m_thumbnail = thumb; m_name = m_controller->clipName(); m_duration = m_controller->getStringDuration(); m_date = m_controller->date; m_description = m_controller->description(); m_type = m_controller->clipType(); getFileHash(); setParent(parent); bin()->loadSubClips(id, m_controller->getPropertiesFromPrefix("kdenlive:clipzone.")); if (KdenliveSettings::audiothumbnails()) { m_audioThumbsThread = QtConcurrent::run(this, &ProjectClip::slotCreateAudioThumbs); } }
int server(int portnum, int fd0) { int clientfd = 0, n = 0, listenfd = 0; char *srecvBuff, *crecvBuff; char ssendBuff[1025], csendBuff[1025]; struct sockaddr_in s_addr, c_addr; int numrv; char line[1000]; struct sFileDownload cFileDownload; struct sFileDownload sFileDownload; struct sFileUpload cFileUpload; struct sFileUpload sFileUpload; memset(&c_addr, '0', sizeof(c_addr)); memset(csendBuff, '0', sizeof(csendBuff)); memset(ssendBuff, '0', sizeof(ssendBuff)); int cmd; s_addr.sin_family = AF_INET; s_addr.sin_addr.s_addr = htonl(INADDR_ANY); s_addr.sin_port = htons(portnum); listenfd = socket(AF_INET, SOCK_STREAM, 0); printf("created socket\n"); bind(listenfd,(struct sockaddr *) &s_addr, sizeof(s_addr)); printf("listening on port %d\n", portnum); if(listen(listenfd, 10) == -1) { printf("Failed to listen\n"); return -1; } clientfd = accept(listenfd,(struct sockaddr *) NULL, NULL); // accept awaiting request if(clientfd == -1) printf ("accept faileindent: Standard input:476: Warning:old style assignment ambiguity in \"=-\". Assuming \"= -\"d\n"); else printf("accepted connection \n"); while(1) { if((n = read(clientfd, &cmd, sizeof(int))) > 0) { printf("Recieved %d %d\n", n, cmd); n = 0; } if((CMD) cmd == FileDownload) { printf("Got FileDownload command\n"); if((n =read(clientfd,(void *) &sFileDownload,sizeof(sFileDownload))) != sizeof(sFileDownload)) printf("Error reading filename\n"); printf("Sending file %s\n", sFileDownload.filename); char temp[100]; strcpy(temp, "./shared/"); strcat(temp, sFileDownload.filename); char *fname = temp; FILE *fs = fopen(fname, "r"); if(fs == NULL) { printf("Unable to open file.\n"); return 0; } int block; char *readbuf; struct stat vstat; // get size of file if(stat(temp, &vstat) == -1) { printf("vstat error\n"); return 0; } // send file size first int size = vstat.st_size; readbuf =(char *) malloc(size * sizeof(char)); if(readbuf == NULL) { printf("error, No memory\n"); exit(0); } if(send(clientfd, &size, sizeof(int), 0) < 0) { printf("send error\n"); return 0; } else printf("sending file size %d\n", size); while((block = fread(readbuf, sizeof(char), size, fs)) > 0) { if(send(clientfd, readbuf, block, 0) < 0) { printf("send error\n"); return 0; } printf("File Sent\n"); } fclose(fs); } else if((CMD) cmd == FileUpload) { char temp[100]; printf("Got FileUpload command\n"); if((n = read(clientfd,(void *) &sFileUpload,sizeof(sFileUpload))) != sizeof(sFileUpload)) printf("Error reading filename\n"); printf("File name: %s\n", sFileUpload.filename); int size; int fr_block_sz = 0; if((fr_block_sz = recv(clientfd, &size, sizeof(int), 0)) != sizeof(int)) { printf("Error reading size of file %s\n", temp); return 0; } else printf("File size: %dB\n", size); char result[100]; printf("FileUploadDeny or FileUploadAllow?\n"); read(fd0, result, sizeof("FileUploadAllow")); if(strcmp(result, "FileUploadDeny") == 0) { if((n = write(clientfd, &result, sizeof(result))) == -1) printf("Failed to send result %s\n", result); else printf("Result sent: %d %s\n", n, result); continue; } else { printf("Accepted file\n"); write(clientfd, &result, sizeof(result)); } strcpy(temp, "./shared/"); strcat(temp, sFileUpload.filename); FILE *fr = fopen(temp, "w+"); if(fr == NULL) { printf("Error creating file %s\n", temp); return 0; } else printf("created file %s\n", temp); srecvBuff =(char *) malloc(size * sizeof(char)); int recvdsize = 0; while((fr_block_sz = recv(clientfd, srecvBuff, LENGTH, 0)) > 0) { srecvBuff[fr_block_sz] = 0; int write_sz = fwrite(srecvBuff, sizeof(char), fr_block_sz, fr); srecvBuff += fr_block_sz; if(write_sz == -1) { printf("Error writing to file %s\n", temp); return 0; } else printf("wrote to file %s %d bytes\n", temp, write_sz); recvdsize += fr_block_sz; if(recvdsize >= size) break; } printf("Done Upload!\n"); fclose(fr); } if((CMD) cmd == FileHash) { MD5_CTX md5Context; char sign[16]; int num_responses; char temp[100]; printf("Got FileHash command\n"); if((n =read(clientfd,(void *) &sFileHash,sizeof(sFileHash))) != sizeof(sFileHash)) printf("Error reading cFileHash\n"); else printf("Type:%s\n", sFileHash.type); if(strcmp(sFileHash.type, "Verify") == 0) { printf("Got Verify\n"); num_responses = 1; if(send(clientfd, &num_responses, sizeof(int), 0) < 0) { printf("send error\n"); return 0; } else printf("sent number of responses %d\n", num_responses); printf("ALL DONE\n"); getFileHash(); if(send(clientfd, &sFileHash_response, sizeof(sFileHash_response),0) < 0) { printf("send error\n"); return 0; } else printf("sent sFileHash_response %s\n", sFileHash_response.filename); } else if(strcmp(sFileHash.type, "CheckAll") == 0) { DIR *fd; int i; printf("Got CheckAll\n"); strcpy(temp, "./shared/"); fd = opendir(temp); if(NULL == fd) { printf("Error opening directory %s\n", temp); return 0; } num_responses = GetFileCnt(); printf("Found %d files in shared folder\n", num_responses); if(send(clientfd, &num_responses, sizeof(num_responses), 0) < 0) { printf("send error\n"); return 0; } else printf("sent number of responses %d\n", num_responses); fd = opendir(temp); for(i = 0; i < num_responses; i++) { strcpy(sFileHash.filename, GetNxtFile(fd)); getFileHash(); if(send(clientfd, &sFileHash_response,sizeof(sFileHash_response), 0) < 0) { printf("send error\n"); return 0; } else printf("sent sFileHash_response %s\n",sFileHash_response.filename); } closedir(fd); } else { printf("RReceived invalid FileHash Command %s\n", sFileHash.type); return 0; } } else if((CMD) cmd == IndexGet) { char filelist[1000]; strcpy(filelist, ""); fileget(filelist, clientfd); printf("File List Sent\n"); } if(n < 0) printf("\n Read Error \n"); } close(clientfd); return 0; }
// checkFileChanges(watcher) static FileEntry* checkFileChanges(ClipWatcher* watcher) { WCHAR dirpath[MAX_PATH]; StringCchPrintf(dirpath, _countof(dirpath), L"%s\\*.*", watcher->srcdir); WIN32_FIND_DATA data; FileEntry* found = NULL; HANDLE fft = FindFirstFile(dirpath, &data); if (fft == NULL) goto fail; for (;;) { LPWSTR name = data.cFileName; int index = rindex(name, L'.'); if (0 <= index && wcsnicmp(name, watcher->name, index) != 0) { WCHAR path[MAX_PATH]; StringCchPrintf(path, _countof(path), L"%s\\%s", watcher->srcdir, name); HANDLE fp = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, (FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING), NULL); if (fp != INVALID_HANDLE_VALUE) { DWORD hash = getFileHash(fp, 256); FILETIME mtime; GetFileTime(fp, NULL, NULL, &mtime); if (logfp != NULL) { fwprintf(logfp, L"check: name=%s (%08x, %08x)\n", name, hash, mtime.dwLowDateTime); } FileEntry* entry = findFileEntry(watcher->files, path); if (entry == NULL) { if (logfp != NULL) { fwprintf(logfp, L"added: name=%s\n", name); } entry = (FileEntry*) malloc(sizeof(FileEntry)); StringCchCopy(entry->path, _countof(entry->path), path); entry->hash = hash; entry->mtime = mtime; entry->next = watcher->files; watcher->files = entry; found = entry; } else if (hash != entry->hash || CompareFileTime(&mtime, &(entry->mtime)) != 0) { if (logfp != NULL) { fwprintf(logfp, L"updated: name=%s\n", name); } entry->hash = hash; entry->mtime = mtime; found = entry; } CloseHandle(fp); } } if (!FindNextFile(fft, &data)) break; } FindClose(fft); fail: return found; }