Example #1
0
void OrthancContext::ExtractGetArguments(Arguments& arguments,
        const OrthancPluginHttpRequest& request)
{
    Check();
    arguments.clear();

    for (uint32_t i = 0; i < request.getCount; i++)
    {
        arguments[request.getKeys[i]] = request.getValues[i];
    }
}
Example #2
0
void GTPReader::ReaderLoop() {
    // Main loop to read commands from standard input 

    std::string inputstring;
    int id;
    std::string command("");
    std::string rawargs;
    std::stringstream ss;
    Arguments arguments;
  
    while(command != "quit") {

	std::getline(std::cin, inputstring);
	ss.str(inputstring);
	ss.clear();
	ss.seekg(0, std::ios::beg);
	ss >> id;

	if(ss.fail()) {
	    id = -1;
	    ss.clear();
	    ss.seekg(0, std::ios::beg);
	}
    
	ss >> command;
    
	if(ss.fail()) {
	    ss.clear();
	    ss.seekg(0, std::ios::beg);
	    continue;
	}
    
	while (ss >> rawargs){
	    arguments.add(rawargs);
	    rawargs.clear();
	}

	ss.clear();
	ss.seekg(0, std::ios::beg);
	rawargs.clear();
    
	engine.command(id, command, arguments);

	arguments.clear();
    }

}
void
ArchDaemonWindows::serviceMain(DWORD argc, LPTSTR* argvIn)
{
	typedef std::vector<LPCTSTR> ArgList;
	typedef std::vector<std::string> Arguments;
	const char** argv = const_cast<const char**>(argvIn);

	// create synchronization objects
	m_serviceMutex        = ARCH->newMutex();
	m_serviceCondVar      = ARCH->newCondVar();
	
	// register our service handler function
	m_statusHandle = RegisterServiceCtrlHandler(argv[0],
								&ArchDaemonWindows::serviceHandlerEntry);
	if (m_statusHandle == 0) {
		// cannot start as service
		m_daemonResult = -1;
		ARCH->closeCondVar(m_serviceCondVar);
		ARCH->closeMutex(m_serviceMutex);
		return;
	}

	// tell service control manager that we're starting
	m_serviceState = SERVICE_START_PENDING;
	setStatus(m_serviceState, 0, 10000);

	std::string commandLine;

	// if no arguments supplied then try getting them from the registry.
	// the first argument doesn't count because it's the service name.
	Arguments args;
	ArgList myArgv;
	if (argc <= 1) {
		// read command line
		HKEY key = openNTServicesKey();
		key      = ArchMiscWindows::openKey(key, argvIn[0]);
		key      = ArchMiscWindows::openKey(key, _T("Parameters"));
		if (key != NULL) {
			commandLine = ArchMiscWindows::readValueString(key,
												_T("CommandLine"));
		}

		// if the command line isn't empty then parse and use it
		if (!commandLine.empty()) {
			// parse, honoring double quoted substrings
			std::string::size_type i = commandLine.find_first_not_of(" \t");
			while (i != std::string::npos && i != commandLine.size()) {
				// find end of string
				std::string::size_type e;
				if (commandLine[i] == '\"') {
					// quoted.  find closing quote.
					++i;
					e = commandLine.find("\"", i);

					// whitespace must follow closing quote
					if (e == std::string::npos ||
						(e + 1 != commandLine.size() &&
						commandLine[e + 1] != ' ' &&
						commandLine[e + 1] != '\t')) {
						args.clear();
						break;
					}

					// extract
					args.push_back(commandLine.substr(i, e - i));
					i = e + 1;
				}
				else {
					// unquoted.  find next whitespace.
					e = commandLine.find_first_of(" \t", i);
					if (e == std::string::npos) {
						e = commandLine.size();
					}

					// extract
					args.push_back(commandLine.substr(i, e - i));
					i = e + 1;
				}

				// next argument
				i = commandLine.find_first_not_of(" \t", i);
			}

			// service name goes first
			myArgv.push_back(argv[0]);

			// get pointers
			for (size_t j = 0; j < args.size(); ++j) {
				myArgv.push_back(args[j].c_str());
			}

			// adjust argc/argv
			argc = (DWORD)myArgv.size();
			argv = &myArgv[0];
		}
	}

	m_commandLine = commandLine;

	try {
		// invoke daemon function
		m_daemonResult = m_daemonFunc(static_cast<int>(argc), argv);
	}
	catch (XArchDaemonRunFailed& e) {
		setStatusError(e.m_result);
		m_daemonResult = -1;
	}
	catch (...) {
		setStatusError(1);
		m_daemonResult = -1;
	}

	// clean up
	ARCH->closeCondVar(m_serviceCondVar);
	ARCH->closeMutex(m_serviceMutex);

	// we're going to exit now, so set status to stopped
	m_serviceState = SERVICE_STOPPED;
	setStatus(m_serviceState, 0, 10000);
}