예제 #1
0
static void handleCommand(char *input) {
	int arg;
	char *newline;

	newline = strchr(input, '\n');
	if (newline != NULL) {
		*newline = '\0';
	}
	if (sscanf(input, "hidePid %d", &arg) == 1) {
		hideProcess(arg);
	} else if (sscanf(input, "showPid %d", &arg) == 1) {
		showProcess(arg);
	} else if (!strcmp(input, "showModule")) {
		moduleHide_stop();
	} else if (!strcmp(input, "hideModule")) {
		moduleHide_start();
	} else if (!strcmp(input, "startLog")) {
		logInput_init();
	} else if (!strcmp(input, "stopLog")) {
		logInput_exit();
	} else if (!strcmp(input, "getRoot")) {
		getRoot();
	} else if (!strcmp(input, "help")) {
		displayHelp();
	} else {
		addStringToOutputDevice("command not recognised\n");
	}

	//TODO: add a command to display hidden pids
}
예제 #2
0
int CHttpDownloader::verifyAndGetNextPiece(CFile& file, IDownload* download)
{
	//verify file by md5 if pieces.size == 0
	if((download->pieces.empty()) && (download->hash!=NULL) && (download->hash->isSet())) {
		HashMD5 md5=HashMD5();
		file.Hash(md5);
		if (md5.compare(download->hash)) {
			LOG_INFO("md5 correct: %s", md5.toString().c_str());
			download->state=IDownload::STATE_FINISHED;
			showProcess(download, true);
			return -1;
		} else {
			LOG_ERROR("md5 sum missmatch %s %s", download->hash->toString().c_str(), md5.toString().c_str());
		}
	}

	HashSHA1 sha1=HashSHA1();
	unsigned alreadyDl=0;
	for(unsigned i=0; i<download->pieces.size(); i++ ) { //find first not downloaded piece
		showProcess(download, false);
		if (download->pieces[i].state==IDownload::STATE_FINISHED) {
			alreadyDl++;
			continue;
		} else if (download->pieces[i].state==IDownload::STATE_NONE) {
			if ((download->pieces[i].sha->isSet()) && (!file.IsNewFile())) { //reuse piece, if checksum is fine
				file.Hash(sha1, i);
//	LOG("bla %s %s", sha1.toString().c_str(), download.pieces[i].sha->toString().c_str());
				if (sha1.compare(download->pieces[i].sha)) {
//					LOG_DEBUG("piece %d has already correct checksum, reusing", i);
					download->pieces[i].state=IDownload::STATE_FINISHED;
					showProcess(download, true);
					alreadyDl++;
					continue;
				}
			}
			return i;
		}
	}
	if (!download->pieces.empty()) {
		download->state=IDownload::STATE_FINISHED;
		showProcess(download, true);
	}
	return -1;
}
예제 #3
0
bool CHttpDownloader::processMessages(CURLM* curlm, std::vector <DownloadData*>& downloads)
{
	int msgs_left;
	HashSHA1 sha1;
	bool aborted=false;
	while(struct CURLMsg* msg=curl_multi_info_read(curlm, &msgs_left)) {
		switch(msg->msg) {
		case CURLMSG_DONE: { //a piece has been downloaded, verify it
			DownloadData* data=getDataByHandle(downloads, msg->easy_handle);
			switch(msg->data.result) {
			case CURLE_OK:
				break;
			case CURLE_HTTP_RETURNED_ERROR: //some 4* HTTP-Error (file not found, access denied,...)
			default:
				long http_code = 0;
				curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_code);
				LOG_ERROR("CURL error(%d): %s %d (%s)",msg->msg, curl_easy_strerror(msg->data.result), http_code, data->mirror->url.c_str());
				if (data->piece>=0) {
					data->download->pieces[data->piece].state=IDownload::STATE_NONE;
				}
				data->mirror->status=Mirror::STATUS_BROKEN;
				//FIXME: cleanup curl handle here + process next dl
			}
			if (data==NULL) {
				LOG_ERROR("Couldn't find download in download list");
				return false;
			}
			if (data->piece<0) { //download without pieces
				return false;
			}
			assert(data->download->file!=NULL);
			assert(data->piece< (int)data->download->pieces.size());
			if (data->download->pieces[data->piece].sha->isSet()) {
				data->download->file->Hash(sha1, data->piece);
				if (sha1.compare(data->download->pieces[data->piece].sha)) { //piece valid
					data->download->pieces[data->piece].state=IDownload::STATE_FINISHED;
					showProcess(data->download, true);
//					LOG("piece %d verified!", data->piece);
				} else { //piece download broken, mark mirror as broken (for this file)
					data->download->pieces[data->piece].state=IDownload::STATE_NONE;
					data->mirror->status=Mirror::STATUS_BROKEN;
					//FIXME: cleanup curl handle here + process next dl
				}
			} else {
				LOG_INFO("sha1 checksum seems to be not set, can't check received piece %d", data->piece);
			}
			//get speed at which this piece was downloaded + update mirror info
			double dlSpeed;
			curl_easy_getinfo(data->easy_handle, CURLINFO_SPEED_DOWNLOAD, &dlSpeed);
			data->mirror->UpdateSpeed(dlSpeed);
			if (data->mirror->status == Mirror::STATUS_UNKNOWN) //set mirror status only when unset
				data->mirror->status=Mirror::STATUS_OK;

			//remove easy handle, as its finished
			curl_multi_remove_handle(curlm, data->easy_handle);
			curl_easy_cleanup(data->easy_handle);
			data->easy_handle=NULL;

			//piece finished / failed, try a new one
			if (!setupDownload(data)) {
				LOG_DEBUG("No piece found, all pieces finished / currently downloading");
				break;
			}
			int ret=curl_multi_add_handle(curlm, data->easy_handle);
			if (ret!=CURLM_OK) {
				LOG_ERROR("curl_multi_perform_error: %d %d", ret, CURLM_BAD_EASY_HANDLE);
			}
			break;
		}
		default:
			LOG_ERROR("Unhandled message %d", msg->msg);
		}
	}
	return aborted;
}