示例#1
0
文件: request.c 项目: cnh/kurma
// Called when all of the processing on the outer requests has finished.
static int outer_done(struct request *r)
{
	DEBUG("[%d] Request received, processing it.\n", r->fd);

	// The request has finished sending all of its data. Process it.
	r->data[r->outer_index] = NULL;
	r->buffer = &r->buffer_char;
	r->buffer_len = 0;
	r->inner_index = 0;
	r->inner_len = 0;
	r->string_len = 0;

	// Check to see that the user sent a command.
	if (r->data == NULL || r->outer_len < 1 || r->data[0][0] == NULL) {
		ERROR("[%d] Command is missing from request.\n", r->fd);
		initd_response_protocol_error(r);
	} else if (!strncmp(r->data[0][0], "CHROOT", 7)) {
		chroot_request(r);
	} else if (!strncmp(r->data[0][0], "SETHOSTNAME", 12)) {
		sethostname_request(r);
	} else if (!strncmp(r->data[0][0], "EXEC", 5)) {
		exec_request(r);
	} else if (!strncmp(r->data[0][0], "START", 6)) {
		start_request(r);
	} else if (!strncmp(r->data[0][0], "MOUNT", 6)) {
		mount_request(r);
	} else if (!strncmp(r->data[0][0], "STATUS", 7)) {
		status_request(r);
	} else if (!strncmp(r->data[0][0], "WAIT", 5)) {
		wait_request(r);
	} else {
		// This is an unknown request!
		ERROR("[%d] Unknown command: %s\n", r->fd, r->data[0][0]);
		initd_response_protocol_error(r);
	}

	// Let the reader know that this request is done processing.
	return 1;
}
示例#2
0
void CServer::handle_request(const char *request)
{
	const char *p;
	int cmd_len;
	int ok;

	logger->log(3, "Got request: %s", request);
	p = strchr(request,' ');
	if (p == 0) {
		p = request + strlen(request);
	}
	cmd_len = p - request;
	while (*p == ' ') {
		p++;
	}
	ok = 0;
	if (cmd_len == 0) {
		logger->log(2, "Empty request!");
		return;
	}
	char *command = new char[cmd_len+1];
	memcpy(command, request, cmd_len);
	command[cmd_len] = 0;
	try {
		if (strcmp(command, "SEARCH") == 0) {
			ok = 1;
			search_request(p);
		}
		if (strcmp(command, "COUNT") == 0) {
			ok = 1;
			count_request();
		}
		if (strcmp(command, "DELETEHOST") == 0) {
			ok = 1;
			delete_request(p);
		}
		if (strcmp(command, "LOAD") == 0) {
			ok = 1;
			load_request(p);
		}
		if (strcmp(command, "STATUS") == 0) {
			ok = 1;
			status_request();
		}
		if (strcmp(command, "HOSTINFO") == 0) {
			ok = 1;
			host_info_request(p);
		}
		if (strcmp(command, "HOSTSTAT") == 0) {
			ok = 1;
			host_stat_request(p);
		}
		if (strcmp(command, "CACHEINFO") == 0) {
			ok = 1;
			cache_info_request();
		}
		if (strcmp(command, "UPDATEHOSTS") == 0) {
			ok = 1;
			update_hosts_request(p);
		}
		if (strcmp(command, "SERVERSTAT") == 0) {
			ok = 1;
			server_stat_request();
		}
		if (strcmp(command, "DEBUG") == 0) {
			ok = 1;
			debug_request(p);
		}
		if (strcmp(command, "DUMP") == 0) {
			ok = 1;
			dump_state_request();
		}
		if (strcmp(command, "FULLSCAN") == 0) {
			ok = 1;
			enable_full_request(p);
		}
		if (strcmp(command, "WORDORDER") == 0) {
			ok = 1;
			word_order_request();
		}
		if (strcmp(command, "CLEARPAGECACHE") == 0) {
			ok = 1;
			clear_pagecache_request();
		}
		if (strcmp(command, "CLEARQUERYCACHE") == 0) {
			ok = 1;
			clear_querycache_request();
		}
		if (strcmp(command, "DUMPFILES") == 0) {
			ok = 1;
			dump_files_request(p);
		}
		if (strcmp(command, "DUMPINDEX") == 0) {
			ok = 1;
			dump_index_request(p);
		}
		if (!ok) {
			throw std::runtime_error(std::string("Unrecognized request: ") + request);
		}
	}
	catch (std::runtime_error &e) {
		logger->log(1, "Error: %s", e.what());
		send_string("ERROR");
	}
	delete[] command;	
	m_request_count++;
}