Spectrum2_manager: add method to detect frontend type

This commit is contained in:
Jan Kaluza 2016-01-26 19:24:14 +01:00
parent fd9c9af71b
commit 42b653a23f
3 changed files with 42 additions and 0 deletions

View file

@ -501,6 +501,45 @@ static void handleConnected(boost::shared_ptr<Swift::Connection> m_conn, const s
}
}
bool is_slack(ManagerConfig *config, const std::string &jid) {
path p(CONFIG_STRING(config, "service.config_directory"));
try {
if (!exists(p)) {
std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
exit(6);
}
if (!is_directory(p)) {
std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
exit(7);
}
directory_iterator end_itr;
for (directory_iterator itr(p); itr != end_itr; ++itr) {
if (is_regular(itr->path()) && extension(itr->path()) == ".cfg") {
Config cfg;
if (cfg.load(itr->path().string()) == false) {
std::cerr << "Can't load config file " << itr->path().string() << ". Skipping...\n";
continue;
}
if (CONFIG_STRING(&cfg, "service.jid") != jid) {
continue;
}
return CONFIG_STRING(&cfg, "service.frontend") == "slack";
}
}
}
catch (const filesystem_error& ex) {
return false;
}
return false;
}
void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &jid, const std::string &message) {
response = "";
path p(CONFIG_STRING(config, "service.config_directory"));

View file

@ -51,6 +51,7 @@ void stop_instances(ManagerConfig *config, const std::string &_jid = "");
int show_status(ManagerConfig *config);
void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &jid, const std::string &message);
bool is_slack(ManagerConfig *config, const std::string &jid);
std::vector<std::string> show_list(ManagerConfig *config, bool show = true);

View file

@ -397,9 +397,11 @@ void Server::serve_oauth2(struct mg_connection *conn, struct http_message *hm) {
std::string state = get_http_var(hm, "state");
std::string response = send_command(instance, "set_oauth2_code " + code + " " + state);
std::cerr << "set_oauth2_code response: '" << response << "'\n";
if (response.find("Registered as ") == 0) {
std::vector<std::string> args;
boost::split(args, response, boost::is_any_of(" "));
std::cerr << "set_oauth2_code response size " << args.size() << "\n";
if (args.size() == 3) {
Server:session *session = get_session(hm);
UserInfo info;