Exemplo n.º 1
0
int download(const char *params)
{
	char parbuf[512];
	char bigbuf[10000];
	const char *srcstrh;
	int discon = 0;
	struct FFlag *myf;
	FILE *listh;
	char lastfile[100];
	int keepc = 1;

	bgrun = 0;
	wasbg = 0;

	setprotocol();
	changenodestatus("Downloading");
	TypeFile("download", TYPE_MAKE | TYPE_CONF | TYPE_WARN);

	if (!conference()->conf.CONF_FILEAREAS) {
		DDPut(sd[dlnoareasstr]);
		return 0;
	}
	if ((protocol->PROTOCOL_TYPE == 3 || protocol->PROTOCOL_TYPE == 2) && !conference()->conf.CONF_UPLOADAREA) {
		DDPut(sd[dlnouploadsstr]);
		return 0;
	}
	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		if (cleantemp() == -1) {
			DDPut(sd[tempcleanerrstr]);
			return 0;
		}
		if (!freespace())
			return 0;
		maketmplist();
	}
	srcstrh = params;

	for (;;) {
		if (strtoken(parbuf, &srcstrh, sizeof parbuf) > sizeof parbuf)
			continue;
		if (!*parbuf)
			break;
		flagfile(parbuf, 1);
	}
	for (;;) {
		typedlprompt();
		bigbuf[0] = 0;
		if (!(Prompt(bigbuf, 200, 0)))
			return 0;
		if (!bigbuf[0]) {
			break;
		} else if (!strcasecmp(bigbuf, "a")) {
			return 0;
		} else {
			srcstrh = bigbuf;
			for (;;) {
				if (strtoken(parbuf, &srcstrh, 
					     sizeof parbuf) > sizeof parbuf)
					continue;
				if (!*parbuf)
					break;
				flagfile(parbuf, 1);
			}
		}
	}
	if (!filestagged)
		return 0;
	listtags();
	if (estimsecs(bytestagged) > timeleft) {
		DDPut(sd[dlnotimestr]);
		return 0;
	}
	for (;;) {
		DDPut(sd[dlproceedstr]);
		bigbuf[0] = 0;
		if (!(Prompt(bigbuf, 3, 0)))
			return 0;
		if (!bigbuf[0] || bigbuf[0] == 'p' || bigbuf[0] == 'P')
			break;
		else if (bigbuf[0] == 'e' || bigbuf[0] == 'E') {
			taged(0);
		} else if (bigbuf[0] == 'd' || bigbuf[0] == 'D') {
			discon = 1;
			break;
		} else if (bigbuf[0] == 'a' || bigbuf[0] == 'A') {
			return 0;
		}
	}
	snprintf(parbuf, sizeof parbuf, "%s/dszlog.%d", DDTMP, node);

	sprintf(&parbuf[250], "%s/ddfilelist.%d", DDTMP, node);
	unlink(&parbuf[250]);

	if (!(listh = fopen(&parbuf[250], "w")))
		return 0;

	myf = (struct FFlag *) flaggedfiles->lh_Head;
	while (myf->fhead.ln_Succ) {
		char tbu[256];
		snprintf(tbu, sizeof tbu, "%s%s\n", 
			myf->f_path, myf->f_filename);
		fputs(tbu, listh);
		myf = (struct FFlag *) myf->fhead.ln_Succ;
	}
	fclose(listh);
	*lastfile = 0;

	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		if ((!(user.user_toggles & (1L << 15))) && (maincfg.CFG_FLAGS & (1L << 11))) {
			initbgchecker();

		}
	}
	sendfiles(&parbuf[250], lastfile, sizeof lastfile);


	if (protocol->PROTOCOL_TYPE == 2 || protocol->PROTOCOL_TYPE == 3) {
		upload(2);
	}
	if (*lastfile) {
		myf = (struct FFlag *) flaggedfiles->lh_Head;
		while (myf->fhead.ln_Succ && keepc) {
			struct FFlag *oldf;
			struct DD_DownloadLog ddl;
			char lbuf[100];
			int logfd;

			snprintf(lbuf, sizeof lbuf, 
				"%s/logfiles/downloadlog.dat", origdir);
			logfd = open(lbuf, O_WRONLY | O_CREAT, 0666);
			if (logfd != -1) {
				fsetperm(logfd, 0666);
				memset((char *) &ddl, 0, sizeof(struct DD_DownloadLog));
				ddl.DL_SLOT = user.user_account_id;
				strlcpy(ddl.DL_FILENAME, myf->f_filename, sizeof ddl.DL_FILENAME);
				ddl.DL_FILESIZE = myf->f_size;
				ddl.DL_TIME = time(0);
				ddl.DL_BPSRATE = bpsrate;
				ddl.DL_NODE = node;
				ddl.DL_CONF = (unsigned char) myf->f_conf;
				lseek(logfd, 0, SEEK_END);
				safe_write(logfd, &ddl, sizeof(struct DD_DownloadLog));
				close(logfd);
			}
			if (!(myf->f_flags & FLAG_FREE)) {
				user.user_dlbytes += myf->f_size;
				user.user_dlfiles++;
			}
			if (!strcasecmp(lastfile, myf->f_filename))
				keepc = 0;
			Remove((struct Node *) myf);
			oldf = myf;
			myf = (struct FFlag *) myf->fhead.ln_Succ;
			free(oldf);
		}
	}
	recountfiles();

	unlink(&parbuf[250]);

	if (discon) {
		if (autodisconnect())
			return 2;
	}
	return 1;
}
Exemplo n.º 2
0
    // run a test
    void s_RunTest(const string &sTestName, const STestInfo & testInfo)
    {
        CAgpToSeqEntry::TFlags fFlags = 0;

        // adjust flags based on whatever's in the flags file
        if( ! testInfo.m_FlagFile.GetPath().empty() ) {
            CNcbiIfstream flagfile( testInfo.m_FlagFile.GetPath().c_str() );
            BOOST_CHECK(flagfile);
            while( flagfile ) {
                string sLine;
                NcbiGetlineEOL(flagfile, sLine);
                NStr::TruncateSpacesInPlace(sLine);
                if( sLine.empty() ) {
                    // ignore blank lines
                } else if( sLine == "fForceLocalId" ) {
                    // make sure flag not already set
                    BOOST_CHECK(0 == (fFlags & CAgpToSeqEntry::fForceLocalId));
                    fFlags |= CAgpToSeqEntry::fForceLocalId;
                } else if( sLine == "fSetSeqGap" ) {
                    BOOST_CHECK(0 == (fFlags & CAgpToSeqEntry::fSetSeqGap));
                    fFlags |= CAgpToSeqEntry::fSetSeqGap;
                } else {
                    BOOST_ERROR("Unknown line in flags file (" 
                        << testInfo.m_FlagFile.GetPath() << "): " << sLine);
                }
            }
            BOOST_CHECK(flagfile.eof());
        }

        // create the object to do the actual reading
        CAgpToSeqEntry agpToSeqEntry(fFlags);

        // read the AGP
        CAgpToSeqEntry::TSeqEntryRefVec seqEntryRefVec;
        {
            CNcbiIfstream agpfile(testInfo.m_AGPFile.GetPath().c_str());
            BOOST_CHECK(agpfile);
            int iErrCode = agpToSeqEntry.ReadStream(agpfile);
            // in the future, we might have a file to allow us
            // to expect certain errors rather than assuming all errors are
            // bad.
            BOOST_CHECK_EQUAL( iErrCode, 0 );

            const string sErrorMsgs = 
                agpToSeqEntry.GetErrorHandler()->GetErrorMessage();
            if( ! sErrorMsgs.empty() ) {
                cout << "AGP errors/warnings: " << endl;
                cout << "(Ignore warnings about assuming AGP version)" << endl;
                cout << sErrorMsgs << endl;
            }

            // swap faster than assignment, and okay in this case
            seqEntryRefVec.swap( agpToSeqEntry.GetResult() );
        }

        const size_t uNumExpected = testInfo.m_vecExpectedSeqEntryFiles.size();
        const size_t uNumResulted = seqEntryRefVec.size();
        BOOST_CHECK_EQUAL( uNumResulted, uNumExpected );

        // check the results against what was expected
        for( size_t idx = 0; idx < uNumResulted; ++idx ) {

            // the SeqEntry that we got
            CConstRef<CSeq_entry> pResultingSeqEntry = seqEntryRefVec[idx];

            // determine what SeqEntry was expected
            CRef<CSeq_entry> pExpectedSeqEntry;
            if( idx < uNumExpected )
            {
                CNcbiIfstream expected_seq_entry_file( 
                    testInfo.m_vecExpectedSeqEntryFiles[idx].GetPath().c_str() );
                pExpectedSeqEntry.Reset( new CSeq_entry );
                BOOST_CHECK_NO_THROW(expected_seq_entry_file >> MSerial_AsnText >> *pExpectedSeqEntry);
            }

            // check if same (or if none was expected here)
            if( pExpectedSeqEntry.IsNull() ||
                ! pResultingSeqEntry->Equals(*pExpectedSeqEntry) ) 
            {
                BOOST_ERROR("For test " << sTestName 
                    << " on index " << idx 
                    << ", the resulting seq-entry does not match "
                    "what was expected");
                cerr << "##### Resulting Seq-entry: " << endl;
                cerr << MSerial_AsnText << *pResultingSeqEntry << endl;
            }
        }