Example #1
0
VMRequest *
VMGahp::preExecuteCommand(const char* cmd, Gahp_Args *args)
{
	char *command = args->argv[0];

	vmprintf(D_FULLDEBUG, "Command: %s\n", command);

	// Special commands first
	if(strcasecmp(command, VMGAHP_COMMAND_ASYNC_MODE_ON) == 0 ) {
		m_async_mode = true;
		m_new_results_signaled = false;
		returnOutputSuccess();
	} else if(strcasecmp(command, VMGAHP_COMMAND_ASYNC_MODE_OFF) == 0 ) {
		m_async_mode = false;
		returnOutputSuccess();
	} else if(strcasecmp(command, VMGAHP_COMMAND_QUIT) == 0 ) {
		executeQuit();
	} else if(strcasecmp(command, VMGAHP_COMMAND_VERSION) == 0 ) {
		executeVersion();
	} else if(strcasecmp(command, VMGAHP_COMMAND_COMMANDS) == 0 ) {
		executeCommands();
	} else if(strcasecmp(command, VMGAHP_COMMAND_SUPPORT_VMS) == 0 ) {
		executeSupportVMS();
	} else if(strcasecmp(command, VMGAHP_COMMAND_RESULTS) == 0 ) {
		executeResults();
	} else if(strcasecmp(command, VMGAHP_COMMAND_CLASSAD) == 0 ) {
		if( m_jobAd != NULL ) {
			delete m_jobAd;
			m_jobAd = NULL;
		}
		m_jobAd = new ClassAd;
		ASSERT(m_jobAd);
		m_inClassAd = true;
		returnOutputSuccess();
	} else if(strcasecmp(command, VMGAHP_COMMAND_CLASSAD_END) == 0 ) {
		if( m_jobAd != NULL ) {
			delete m_jobAd;
			m_jobAd = NULL;
		}
		m_inClassAd = false;
		returnOutputSuccess();
	} else {
		VMRequest *new_req;
		new_req = addNewRequest(cmd);
		returnOutputSuccess();
		return new_req;
	}
	return NULL;
}
// called when adding a request from the GUI
void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient)
{
    RecentRequestEntry newEntry;
    newEntry.id = ++nReceiveRequestsMaxId;
    newEntry.date = QDateTime::currentDateTime();
    newEntry.recipient = recipient;

    CDataStream ss(SER_DISK, CLIENT_VERSION);
    ss << newEntry;

    if (!walletModel->saveReceiveRequest(recipient.address.toStdString(), newEntry.id, ss.str()))
        return;

    addNewRequest(newEntry);
}
RecentRequestsTableModel::RecentRequestsTableModel(CWallet *wallet, WalletModel *parent) :
    walletModel(parent)
{
    Q_UNUSED(wallet);
    nReceiveRequestsMaxId = 0;

    // Load entries from wallet
    std::vector<std::string> vReceiveRequests;
    parent->loadReceiveRequests(vReceiveRequests);
    BOOST_FOREACH(const std::string& request, vReceiveRequests)
        addNewRequest(request);

    /* These columns must match the indices in the ColumnIndex enumeration */
    columns << tr("Date") << tr("Label") << tr("Message") << tr("Amount");
}
// called from ctor when loading from wallet
void RecentRequestsTableModel::addNewRequest(const std::string &recipient)
{
    std::vector<char> data(recipient.begin(), recipient.end());
    CDataStream ss(data, SER_DISK, CLIENT_VERSION);

    RecentRequestEntry entry;
    ss >> entry;

    if (entry.id == 0) // should not happen
        return;

    if (entry.id > nReceiveRequestsMaxId)
        nReceiveRequestsMaxId = entry.id;

    addNewRequest(entry);
}
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
    QAbstractTableModel(parent), walletModel(parent)
{
    nReceiveRequestsMaxId = 0;

    // Load entries from wallet
    std::vector<std::string> vReceiveRequests;
    parent->loadReceiveRequests(vReceiveRequests);
    for (const std::string& request : vReceiveRequests)
        addNewRequest(request);

    /* These columns must match the indices in the ColumnIndex enumeration */
    columns << tr("Date") << tr("Label") << tr("Message") << getAmountTitle();

    connect(walletModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
}
Example #6
0
int
IOProcess::stdinPipeHandler()
{
	char command[131072];
	while( m_stdin_buffer.GetNextLine( command, sizeof( command ) ) ) {
		dprintf (D_FULLDEBUG, "got stdin: '%s'\n", command);

		Gahp_Args args;

		if (parse_gahp_command (command, &args) &&
			verify_gahp_command (args.argv, args.argc)) {

				// Catch "special commands first
			if (strcasecmp (args.argv[0], GAHP_COMMAND_RESULTS) == 0) {
				// Print each result line

				// Print number of results
				printf("%s %d\n", GAHP_RESULT_SUCCESS, numOfResult());
				fflush(stdout);

				startResultIteration();

				char* next = NULL;
				while ((next = NextResult()) != NULL) {
					printf ("%s", next);
					fflush(stdout);
					deleteCurrentResult();
				}
				m_new_results_signaled = false;
			} else if (strcasecmp (args.argv[0], GAHP_COMMAND_VERSION) == 0) {
				printf ("S %s\n", version);
				fflush (stdout);
			} else if (strcasecmp (args.argv[0], GAHP_COMMAND_QUIT) == 0) {
				gahp_output_return_success();
				io_process_exit(0);
			} else if (strcasecmp (args.argv[0], GAHP_COMMAND_ASYNC_MODE_ON) == 0) {
				m_async_mode = true;
				m_new_results_signaled = false;
				gahp_output_return_success();
			} else if (strcasecmp (args.argv[0], GAHP_COMMAND_ASYNC_MODE_OFF) == 0) {
				m_async_mode = false;
				gahp_output_return_success();
			} else if (strcasecmp (args.argv[0], GAHP_COMMAND_STATISTICS) == 0) {
				printf( "%s %d %d %d %d\n", GAHP_RESULT_SUCCESS,
					NumRequests, NumDistinctRequests,
					NumRequestsExceedingLimit, NumExpiredSignatures
				);
				fflush( stdout );
			} else if (strcasecmp (args.argv[0], GAHP_COMMAND_COMMANDS) == 0) {
				StringList amazon_commands;
				int num_commands = 0;

				num_commands = allAmazonCommands(amazon_commands);
				num_commands += 7;

				const char *commands[num_commands];
				int i = 0;
				commands[i++] = GAHP_RESULT_SUCCESS;
				commands[i++] = GAHP_COMMAND_ASYNC_MODE_ON;
				commands[i++] = GAHP_COMMAND_ASYNC_MODE_OFF;
				commands[i++] = GAHP_COMMAND_RESULTS;
				commands[i++] = GAHP_COMMAND_QUIT;
				commands[i++] = GAHP_COMMAND_VERSION;
				commands[i++] = GAHP_COMMAND_COMMANDS;

				amazon_commands.rewind();
				char *one_amazon_command = NULL;

				while( (one_amazon_command = amazon_commands.next() ) != NULL ) {
					commands[i++] = one_amazon_command;
				}

				gahp_output_return (commands, i);
			} else {
				// got new command
				if( !addNewRequest(command) ) {
					gahp_output_return_error();
				} else {
					gahp_output_return_success();
				}
			}
		} else {
			gahp_output_return_error();
		}
	}

	// check if GetNextLine() returned NULL because of an error or EOF
	if (m_stdin_buffer.IsError() || m_stdin_buffer.IsEOF()) {
		dprintf (D_ALWAYS, "stdin buffer closed, exiting\n");
		io_process_exit(1);
	}

	return TRUE;
}