/* The upload handler functions as a filter. It never actually handles a request */ static bool uploadHandler(Webs *wp) { assert(websValid(wp)); if (!(wp->flags & WEBS_UPLOAD)) { return 0; } return initUpload(wp); }
PUBLIC bool websProcessUploadData(Webs *wp) { char *line, *nextTok; ssize len, nbytes; bool canProceed; line = 0; canProceed = 1; while (canProceed && !wp->finalized && wp->uploadState != UPLOAD_CONTENT_END) { if (wp->uploadState == UPLOAD_BOUNDARY || wp->uploadState == UPLOAD_CONTENT_HEADER) { /* Parse the next input line */ line = wp->input.servp; if ((nextTok = memchr(line, '\n', bufLen(&wp->input))) == 0) { /* Incomplete line */ canProceed = 0; break; } *nextTok++ = '\0'; nbytes = nextTok - line; websConsumeInput(wp, nbytes); strim(line, "\r", WEBS_TRIM_END); len = strlen(line); if (line[len - 1] == '\r') { line[len - 1] = '\0'; } } switch (wp->uploadState) { case 0: initUpload(wp); break; case UPLOAD_BOUNDARY: processContentBoundary(wp, line); break; case UPLOAD_CONTENT_HEADER: processUploadHeader(wp, line); break; case UPLOAD_CONTENT_DATA: canProceed = processContentData(wp); if (bufLen(&wp->input) < wp->boundaryLen) { /* Incomplete boundary - return to get more data */ canProceed = 0; } break; case UPLOAD_CONTENT_END: break; } } bufCompact(&wp->input); return canProceed; }
void UploadInfoPage::onFileValidate(bool res, const char* path) { if (res) { initUpload(path, m_pUpInfo->upsize); } else { gcMessageBox(GetParent(), Managers::GetString(L"#UDF_NONMATCHING_FILE"), Managers::GetString(L"#UDF_UPLOAD_ERRTITLE") ); m_butUpload->Enable(true); m_tbItemFile->Enable(true); m_butFile->Enable(true); } }
void loadBlocksOfType(daveConnection * dc, int blockType, int doReadout) { int j, i, uploadID, len, more; #ifdef UNIX_STYLE int fd; #endif #ifdef WIN_STYLE HANDLE fd; unsigned long res; #endif char blockName [20]; uc blockBuffer[20000],*bb; daveBlockEntry dbe[256]; j=daveListBlocksOfType(dc, blockType, dbe); if (j<0) { printf("error %d=%s\n",-j,daveStrerror(-j)); return; } printf("%d blocks of type %s\n",j,daveBlockName(blockType)); for (i=0; i<j; i++) { printf("%s%d %d %d\n", daveBlockName(blockType), dbe[i].number, dbe[i].type[0],dbe[i].type[1]); bb=blockBuffer; if(doReadout) { len=0; if (0==initUpload(dc, blockType, dbe[i].number, &uploadID)) { do { doUpload(dc,&more,&bb,&len,uploadID); } while (more); sprintf(blockName,"%s%d.mc7",daveBlockName(blockType), dbe[i].number); #ifdef UNIX_STYLE fd=open(blockName,O_RDWR|O_CREAT|O_TRUNC,0644); write(fd, blockBuffer, len); close(fd); #endif #ifdef WIN_STYLE fd = CreateFile(blockName, GENERIC_WRITE, 0, 0, 2, FILE_FLAG_WRITE_THROUGH, 0); WriteFile(fd, blockBuffer, len, &res, NULL); CloseHandle(fd); #endif endUpload(dc,uploadID); } } } }
void UploadInfoPage::onResumeComplete(const char* path) { if (path && strcmp(path, "NULL") != 0) { initUpload(path, m_pUpInfo->upsize); } else { m_butUpload->Enable(true); m_tbItemFile->Enable(true); m_butFile->Enable(true); resetAllValues(); gcMessageBox(GetParent(), Managers::GetString(L"#UDF_NOFILE"), Managers::GetString(L"#UDF_RESUME_ERRTITLE") ); } }
void UploadInfoPage::onButtonClicked( wxCommandEvent& event ) { if (event.GetId() == m_butUpload->GetId()) { m_butUpload->Enable(false); m_tbItemFile->Enable(false); m_butFile->Enable(false); gcString path((const wchar_t*)m_tbItemFile->GetValue().c_str()); initUpload(path.c_str()); } else if (event.GetId() == m_butCancel->GetId()) { GetParent()->Close(); } else if (event.GetId() == m_butFile->GetId()) { showDialog(); } }
void UploadInfoPage::setInfo_path(DesuraId id, const char* path) { setInfo(id); if (path) { m_tbItemFile->SetValue(gcString(path)); if (validateInput()) { m_butUpload->Enable(false); m_tbItemFile->Enable(false); m_butFile->Enable(false); initUpload(path); } else { gcMessageBox(GetParent(), Managers::GetString(L"#UDF_ERROR_VALIDATION"), Managers::GetString(L"#UDF_ERRTITLE") ); } } }
void UploadInfoPage::onComplete(gcString& key) { gcString path((const wchar_t*)m_tbItemFile->GetValue().c_str()); m_szKey = key; initUpload(path.c_str(), 0); }
PUBLIC int websProcessUploadData(Webs *wp) { char *line, *nextTok; ssize len, nbytes; int done, rc; for (done = 0, line = 0; !done; ) { if (wp->uploadState == UPLOAD_BOUNDARY || wp->uploadState == UPLOAD_CONTENT_HEADER) { /* Parse the next input line */ line = wp->input.servp; if ((nextTok = memchr(line, '\n', bufLen(&wp->input))) == 0) { /* Incomplete line */ break; } *nextTok++ = '\0'; nbytes = nextTok - line; websConsumeInput(wp, nbytes); strim(line, "\r", WEBS_TRIM_END); len = strlen(line); if (line[len - 1] == '\r') { line[len - 1] = '\0'; } } switch (wp->uploadState) { case 0: if (initUpload(wp) < 0) { done++; } break; case UPLOAD_BOUNDARY: if (processContentBoundary(wp, line) < 0) { done++; } break; case UPLOAD_CONTENT_HEADER: if (processUploadHeader(wp, line) < 0) { done++; } break; case UPLOAD_CONTENT_DATA: if ((rc = processContentData(wp)) < 0) { done++; } if (bufLen(&wp->input) < wp->boundaryLen) { /* Incomplete boundary - return to get more data */ done++; } break; case UPLOAD_CONTENT_END: done++; break; } } if (!websValid(wp)) { return -1; } bufCompact(&wp->input); return 0; }