Changeset - 8780e3a1d0af
[Not reviewed]
0 1 0
Vitaly Takmazov - 7 years ago 2018-09-18 19:06:31
vitalyster@gmail.com
fix compatibility with gcc 4.9
1 file changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -78,25 +78,25 @@ void APIServer::send_ack(struct mg_connection *conn, bool error, const std::stri
 

	
 
void APIServer::serve_instances(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	// rapidjson stores const char* pointer to status, so we have to keep
 
	// the std::string stored out of BOOST_FOREACH scope, otherwise the
 
	// const char * returned by c_str() would be invalid during send_json.
 
	std::vector<std::string> statuses;
 
	std::vector<std::string> usernames;
 
	std::vector<std::string> list = show_list(m_config, false);
 

	
 
	Json::Value json;
 
	json["error"] = 0;
 

	
 
	Json::Value instances(Json::ValueType::arrayValue);
 
	Json::Value instances(Json::arrayValue);
 
	BOOST_FOREACH(std::string &id, list) {
 
		Json::Value instance;
 
		instance["id"] = id;
 

	
 
		std::string name = get_config(m_config, id, "identity.name");
 
		if (name.empty() || name == "Spectrum 2 Transport") {
 
			instance["name"] = id;
 
		}
 
		else {
 
			statuses.push_back(name);
 
			instance["name"] = statuses.back();
 
		}
 
@@ -281,25 +281,25 @@ void APIServer::serve_instances_commands(Server *server, Server::session *sessio
 
	int type = (int) TYPE_STRING;
 
	m_storage->getUserSetting(info.id, instance, type, username);
 

	
 
	std::string response = server->send_command(instance, "commands");
 

	
 
	std::vector<std::string> commands;
 
	boost::split(commands, response, boost::is_any_of("\n"));
 

	
 
	Json::Value json;
 
	json["error"] = 0;
 

	
 
	std::vector<std::vector<std::string> > tmp;
 
	Json::Value cmds(Json::ValueType::arrayValue);
 
	Json::Value cmds(Json::arrayValue);
 
	BOOST_FOREACH(const std::string &command, commands) {
 
		escaped_list_separator<char> els('\\', ' ', '\"');
 
		tokenizer<escaped_list_separator<char> > tok(command, els);
 

	
 
		std::vector<std::string> tokens;
 
		for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg) {
 
			tokens.push_back(*beg);
 
		}
 

	
 
		if (tokens.size() != 11) {
 
			continue;
 
		}
 
@@ -345,25 +345,25 @@ void APIServer::serve_instances_variables(Server *server, Server::session *sessi
 
	int type = (int) TYPE_STRING;
 
	m_storage->getUserSetting(info.id, instance, type, username);
 

	
 
	std::string response = server->send_command(instance, "variables");
 

	
 
	std::vector<std::string> commands;
 
	boost::split(commands, response, boost::is_any_of("\n"));
 

	
 
	Json::Value json;
 
	json["error"] = 0;
 

	
 
	std::vector<std::vector<std::string> > tmp;
 
	Json::Value cmds(Json::ValueType::arrayValue);
 
	Json::Value cmds(Json::arrayValue);
 
	BOOST_FOREACH(const std::string &command, commands) {
 
		escaped_list_separator<char> els('\\', ' ', '\"');
 
		tokenizer<escaped_list_separator<char> > tok(command, els);
 

	
 
		std::vector<std::string> tokens;
 
		for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg) {
 
			tokens.push_back(*beg);
 
		}
 

	
 
		if (tokens.size() != 13) {
 
			continue;
 
		}
 
@@ -442,25 +442,25 @@ void APIServer::serve_instances_command_args(Server *server, Server::session *se
 
		return;
 
	}
 

	
 
	
 

	
 
	std::vector<std::string> args;
 
	boost::split(args, response, boost::is_any_of("\n"));
 

	
 
	Json::Value json;
 
	json["error"] = 0;
 

	
 
	std::vector<std::vector<std::string> > tmp;
 
	Json::Value argList(Json::ValueType::arrayValue);
 
	Json::Value argList(Json::arrayValue);
 

	
 
	if (userContext && session->admin) {
 
		Json::Value arg;
 
		arg["name"] = "username";
 
		arg["label"] = "Username";
 
		arg["example"] = "";
 
		argList.append(arg);
 
	}
 

	
 
	BOOST_FOREACH(const std::string &argument, args) {
 
		escaped_list_separator<char> els('\\', ' ', '\"');
 
		tokenizer<escaped_list_separator<char> > tok(argument, els);
 
@@ -562,25 +562,25 @@ void APIServer::serve_instances_execute(Server *server, Server::session *session
 
	if (response.find("Error:") == 0) {
 
		send_ack(conn, false, response);
 
	}
 

	
 
	std::vector<std::string> fields;
 
	boost::split(fields, response, boost::is_any_of("\n"));
 
	if (!fields.empty() && /*fields[0].find(" - ") != std::string::npos &&*/ (fields[0].find(": ") != std::string::npos || fields[0].find(":\"") != std::string::npos)) {
 
		Json::Value json;
 
		json["error"] = 0;
 

	
 
		std::vector<std::string> tmp;
 
		std::vector<std::string> tmp2;
 
		Json::Value table(Json::ValueType::arrayValue);
 
		Json::Value table(Json::arrayValue);
 

	
 
		BOOST_FOREACH(const std::string &line, fields) {
 
			escaped_list_separator<char> els('\\', ' ', '\"');
 
			tokenizer<escaped_list_separator<char> > tok(line, els);
 

	
 
			Json::Value arg;
 

	
 
			std::string key;
 
			int i = 0;
 
			bool hasDesc = true;
 
			for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg, ++i) {
 
				if (i == 1 && *beg != "-") {
 
@@ -619,25 +619,25 @@ void APIServer::serve_instances_execute(Server *server, Server::session *session
 
	}
 
}
 

	
 
void APIServer::serve_users(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	ALLOW_ONLY_ADMIN();
 

	
 
	Json::Value json;
 
	json["error"] = 0;
 

	
 
	std::vector<std::string> list;
 
	m_storage->getUsers(list);
 

	
 
	Json::Value users(Json::ValueType::arrayValue);
 
	Json::Value users(Json::arrayValue);
 
	BOOST_FOREACH(std::string &id, list) {
 
		Json::Value user;
 
		user["username"] = id;
 
		users.append(user);
 
	}
 

	
 
	json["users"] = users;
 
	send_json(conn, json);
 
}
 

	
 
void APIServer::serve_users_add(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	std::string user = get_http_var(hm, "username");
0 comments (0 inline, 0 general)