Changeset - 21a6955ca049
[Not reviewed]
0 2 0
Jan Kaluza - 9 years ago 2016-01-26 19:44:33
jkaluza@redhat.com
Increase the timeout for set_oauth2_code to 10 seconds
2 files changed with 4 insertions and 4 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/server.cpp
Show inline comments
 
@@ -274,24 +274,24 @@ void Server::print_html(struct mg_connection *conn, struct http_message *hm, con
 
			"Content-Length: %d\r\n"        // Always set Content-Length
 
			"\r\n"
 
			"%s%s%s",
 
			(int) html.size() + m_header.size() + m_footer.size(), m_header.c_str(), html.c_str(), m_footer.c_str());
 
}
 

	
 
std::string Server::send_command(const std::string &jid, const std::string &cmd) {
 
std::string Server::send_command(const std::string &jid, const std::string &cmd, int timeout) {
 
	Swift::SimpleEventLoop eventLoop;
 
	Swift::BoostNetworkFactories networkFactories(&eventLoop);
 

	
 
	ask_local_server(m_config, networkFactories, jid, cmd);
 
	struct timeval td_start,td_end;
 
	float elapsed = 0; 
 
	gettimeofday(&td_start, NULL);
 
	gettimeofday(&td_end, NULL);
 

	
 
	time_t started = time(NULL);
 
	while(get_response().empty() && td_end.tv_sec - td_start.tv_sec < 1) {
 
	while(get_response().empty() && td_end.tv_sec - td_start.tv_sec < timeout) {
 
		gettimeofday(&td_end, NULL);
 
		eventLoop.runOnce();
 
	}
 

	
 
	std::string response = get_response();
 
	if (response == "Empty response") {
 
@@ -393,13 +393,13 @@ void Server::serve_oauth2(struct mg_connection *conn, struct http_message *hm) {
 
// 	http://slack.spectrum.im/oauth2/localhostxmpp?code=14830663267.19140123492.e7f78a836d&state=534ab3b6-8bf1-4974-8274-847df8490bc5
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 
	std::string code = get_http_var(hm, "code");
 
	std::string state = get_http_var(hm, "state");
 

	
 
	std::string response = send_command(instance, "set_oauth2_code " + code + " " + state);
 
	std::string response = send_command(instance, "set_oauth2_code " + code + " " + state, 10);
 
	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) {
spectrum_manager/src/server.h
Show inline comments
 
@@ -61,13 +61,13 @@ class Server {
 
		bool start();
 

	
 
		void event_handler(struct mg_connection *nc, int ev, void *p);
 

	
 
		void redirect_to(struct mg_connection *conn, struct http_message *hm, const char *where);
 

	
 
		std::string send_command(const std::string &jid, const std::string &cmd);
 
		std::string send_command(const std::string &jid, const std::string &cmd, int timeout = 1);
 

	
 
	private:
 
		void serve_logout(struct mg_connection *conn, struct http_message *hm);
 
		void serve_oauth2(struct mg_connection *conn, struct http_message *hm);
 
		void print_html(struct mg_connection *conn, struct http_message *hm, const std::string &html);
 

	
0 comments (0 inline, 0 general)