Beispiel #1
0
void SessionListener::processPresence(const SessionPtr& session, const xml_document_ptr& doc){
	xml_node hiNode = doc->child("hi");
	string userid = hiNode.child("userid").child_value();
	string ticket = hiNode.child("ticket").child_value();
	string token = hiNode.child("session").child_value();

	MCE_INFO("LoginAction::execute -> userid: " << userid << ", ticket: "
			<< ticket << ", token: " << token);
	JidPtr jid = new Jid();
	try {
		jid->userId = boost::lexical_cast<int>(userid);
	} catch (std::exception& e) {
		MCE_WARN("LoginAction::execute -> invalid userid: " << userid << ", " << e.what());
		session->shutdown();
		return;
	} catch (...) {
		MCE_WARN("LoginAction::execute -> invalid userid: " << userid);
		session->shutdown();
		return;
	}
	jid->endpoint = ServiceI::instance().getName();
	session->jid(jid);
	bool success = false;
	try {
		success = session->bind(token, ticket);//WTalkProxyAdapter::instance().bind(token, ticket, jid);
	} catch (Ice::Exception& e) {
		MCE_WARN("LoginAction::execute -> failure binding, jid: " << jidToString(jid) << ", " << e);
		session->shutdown();
		return;
	}
	if (success) {
		//_session->jid(jid);
		session->token(token);
		session->verify(true);

		//Server::instance().join(_session, jid);
		string
				msg =
						"<?xml version=\"1.0\" encoding=\"utf-8\"?><hi cmd=\"login_res\"><res>0</res></hi>";
		msg.push_back('\0');
		if (session->deliver(msg)) {
			MCE_INFO("LoginAction::execute -> success -> userid:"<<userid
					<<"  ticket:"<<ticket);
		} else {
			//Server::instance().leave(_session);
			session->shutdown();
		}
	} else {
		MCE_WARN("LoginAction::execute -> failure binding, userid:" << userid);
		string
				msg =
						"<?xml version=\"1.0\" encoding=\"utf-8\"?><hi cmd='login_res'><res>1</res></hi>";
		msg.push_back('\0');
		session->deliver(msg);
		session->shutdown();
	}
}
Beispiel #2
0
void SessionListener::messaged(SharedPtr channel, xml_document_ptr& doc) {
	MCE_DEBUG("RequestHandler::handle -> " << doc->xml());
	SessionPtr session = SessionPtr::dynamicCast(channel);
	string name = doc->first_child().attribute("cmd").value();
	if (name == "login") {
		//MCE_DEBUG("SessionListener::messaged --> CONN_ID:"<<session->connectionId());
		//session->schedule(new LoginAction, doc);
		//do not start a thread, otherwise a stop may be processed before this login
		processPresence(session, doc);

	} else if (name == "msg") {
		session->schedule(new ChatAction, doc);
	} else {
		if (doc->child("policy-file-request")) {
			string msg =
			//xiaonei
							"<cross-domain-policy><allow-access-from domain=\"*.xiaonei.com\" to-ports=\"39000\" /></cross-domain-policy>";
			//kaixin
			//"<cross-domain-policy><allow-access-from domain=\"*.kaixin.com\" to-ports=\"39000\" /></cross-domain-policy>";

			msg.push_back('\0');
			session->deliver(msg);
			return;
		}
		session->shutdown();
	}
}
Beispiel #3
0
void ConnectionStat::deliver(const SessionPtr& session, int status_code,
		int cache_time, bool is_gzip, bool keep_alive,
		const string& extra_header, const string& body, bool bin_data,
		const string& content_type) {
	//MCE_INFO("-----deliver--- conn:"<<session->connectionId()<< " body:"
	//		<< body);
	ostringstream res;
	if (status_code != 200) {
		if (status_code == 403) {
			res << "HTTP/1.1 403 Forbidden\r\n";
		} else if(status_code == 408){
			res << "HTTP/1.1 408 Request Timeout\r\n";
		} else {
			res << "HTTP/1.1 404 Not Found\r\n";
		}
	} else {
		res << "HTTP/1.1 200 OK\r\n";
	}

	if (is_gzip && !body.empty() && (!bin_data) && (!Server::instance().isWap())) {
		res << "Content-Encoding: gzip\r\n";
	}

	res << "Server: XNHttpServer1.0\r\n" << "Content-Type: "<<content_type
			<<"\r\n" << "Content-Length: "<< body.length()<<"\r\n"
			<< extra_header;
	if (keep_alive) {
		res << "Connection: keep-alive\r\n" << "Keep-Alive: 300\r\n";
	} else {
		res << "Connection: close\r\n";
	}
	if (cache_time > 0 && status_code == 200) {
		res << "Cache-Control: max-age="<< cache_time << "\r\n";
		res << "Expires: "<< gmtTime(time(NULL)+cache_time)<< "\r\n";
	} else if (cache_time == -1) {
		res << "Cache-Control: max-age="<<60*60*24*10<<"\r\n";
		res << "Expires: "<< gmtTime(time(NULL)+60*60*24*10)<< "\r\n";
	} else if (cache_time == 0) {
		res << "Cache-Control: no-cache"<< "\r\n"
				<< "Expires: Thu, 01 Jan 1970 00:00:00 GMT"<< "\r\n";
	}
	res << "\r\n";
//	MCE_DEBUG("ConnectionStat -->deliver :"<< res.str() << " ISWAP:"<<IS_WAP);
	res.write(body.c_str(), body.length());
	//MCE_INFO("Session::deliver --> " << res.str());
	session->deliver(res.str());
	if (!keep_alive) {
		session->shutdown();
	}
}
Beispiel #4
0
void ConnectionStat::deliver(const SessionPtr& session, int status_code,
		int cache_time, bool is_gzip, bool keep_alive,
		const string& extra_header, const string& body, bool bin_data,
		const string& content_type, const string& nogzipmsg) {
	//MCE_DEBUG("ConnectionStat::deliver --> " << jidToString(session->jid()) << " body:" << body);
	ostringstream res;
	if (status_code != 200) {
		if (status_code == 403) {
			res << "HTTP/1.1 403 Forbidden\r\n";
		} else if(status_code == 408){
			res << "HTTP/1.1 408 Request Timeout\r\n";
		} else if(status_code == 211){
			res << "HTTP/1.1 211 Comet Switch\r\n";
		}else {
			res << "HTTP/1.1 404 Not Found\r\n";
		}
	} else {
		res << "HTTP/1.1 200 OK\r\n";
	}

	if (is_gzip && !body.empty() && (!bin_data) && (!Server::instance().isWap())) {
		res << "Content-Encoding: gzip\r\n";
	}

	res << "Server: XNHttpServer1.0\r\n" << "Content-Type: "<<content_type
			<<"\r\n" << "Content-Length: "<< body.length()<<"\r\n"
			<< extra_header;
	if (keep_alive) {
		res << "Connection: keep-alive\r\n" << "Keep-Alive: 300\r\n";
	} else {
		res << "Connection: close\r\n";
	}
	if (cache_time > 0 && status_code == 200) {
		res << "Cache-Control: max-age="<< cache_time << "\r\n";
		res << "Expires: "<< gmtTime(time(NULL)+cache_time)<< "\r\n";
	} else if (cache_time == -1) {
		res << "Cache-Control: max-age="<<60*60*24*10<<"\r\n";
		res << "Expires: "<< gmtTime(time(NULL)+60*60*24*10)<< "\r\n";
	} else if (cache_time == 0) {
		res << "Cache-Control: no-cache"<< "\r\n"
				<< "Expires: Thu, 01 Jan 1970 00:00:00 GMT"<< "\r\n";
	}
	res << "\r\n";
//	MCE_DEBUG("ConnectionStat -->deliver :"<< res.str() << " ISWAP:"<<IS_WAP);
	res.write(body.c_str(), body.length());
	bool ok = false;
	ok = session->deliver(res.str());
	if (!keep_alive) {
		session->shutdown();
	}


	string msg = nogzipmsg;
	xml_document doc;
	if (doc.load(msg.c_str())) {
		xml_node n = doc.child("msglist").child("message");
		for (; n; n = n.next_sibling("message")) {
			string s = n.child("body").first_child().value();
			if( s.find("ugc_content") != string::npos){
				MCE_INFO("ConnectionStat::deliver -->deliver ugc_content ok = " << ok);
			}
		}
	}else{
		MCE_WARN("CometResponseStat::deliver -->deliver ugc_content document.load error");
	}
}