Changeset - 4c334e9f1c0b
[Not reviewed]
0 7 0
HanzZ - 14 years ago 2011-12-09 13:51:50
hanzz.k@gmail.com
Move random port generating to util.cpp
7 files changed with 24 insertions and 18 deletions:
0 comments (0 inline, 0 general)
include/transport/util.h
Show inline comments
 
@@ -40,6 +40,8 @@ std::string serializeGroups(const std::vector<std::string> &groups);
 

	
 
std::vector<std::string> deserializeGroups(std::string &groups);
 

	
 
int getRandomPort(const std::string &s);
 

	
 
}
 

	
 
}
spectrum/src/sample2.cfg
Show inline comments
 
@@ -24,7 +24,9 @@ port = 5222
 
backend_host = localhost
 

	
 
# Port on which Spectrum listens for backends.
 
backend_port=10001
 
# By default Spectrum chooses random backend port and there's
 
# no need to change it normally
 
#backend_port=10001
 

	
 
# Full path to PKCS#12 cetficiate used for TLS in server mode.
 
#cert=
spectrum_manager/src/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_manager ${SRC} ../../src/config.cpp)
 
ADD_EXECUTABLE(spectrum2_manager ${SRC} ../../src/config.cpp ../../src/util.cpp)
 
 
target_link_libraries(spectrum2_manager ${SWIFTEN_LIBRARY})
 
src/config.cpp
Show inline comments
 
@@ -19,6 +19,7 @@
 
 */
 

	
 
#include "transport/config.h"
 
#include "transport/util.h"
 
#include <fstream>
 
#ifdef _MSC_VER
 
#include <direct.h>
 
@@ -120,13 +121,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		else if (opt.string_key == "service.backend_port") {
 
			found_backend_port = true;
 
			if (opt.value[0] == "0") {
 
				unsigned long r = 0;
 
				BOOST_FOREACH(char c, _jid) {
 
					r += (int) c;
 
				}
 
				srand(time(NULL) + r);
 
				int randomPort = 30000 + rand() % 10000;
 
				opt.value[0] = boost::lexical_cast<std::string>(randomPort);
 
				opt.value[0] = boost::lexical_cast<std::string>(Util::getRandomPort(_jid.empty() ? jid : _jid));
 
			}
 
		}
 
		else if (opt.string_key == "service.working_dir") {
 
@@ -148,14 +143,9 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		parsed.options.push_back(boost::program_options::basic_option<char>("service.pidfile", value));
 
	}
 
	if (!found_backend_port) {
 
		unsigned long r = 0;
 
		BOOST_FOREACH(char c, _jid) {
 
			r += (int) c;
 
		}
 
		srand(time(NULL) + r);
 
		int randomPort = 30000 + rand() % 10000;
 
		std::vector<std::string> value;
 
		value.push_back(boost::lexical_cast<std::string>(randomPort));
 
		std::string p = boost::lexical_cast<std::string>(Util::getRandomPort(_jid.empty() ? jid : _jid));
 
		value.push_back(p);
 
		parsed.options.push_back(boost::program_options::basic_option<char>("service.backend_port", value));
 
	}
 

	
src/presenceoracle.cpp
Show inline comments
 
@@ -19,6 +19,7 @@
 
 */
 

	
 
#include "transport/presenceoracle.h"
 
#include "Swiften/Swiften.h"
 

	
 
#include <boost/bind.hpp>
 

	
 
@@ -46,9 +47,10 @@ void PresenceOracle::handleStanzaChannelAvailableChanged(bool available) {
 

	
 
void PresenceOracle::handleIncomingPresence(Presence::ref presence) {
 
	// ignore presences for some contact, we're checking only presences for the transport itself here.
 
	if (!presence->getTo().getNode().empty()) {
 
	bool isMUC = presence->getPayload<MUCPayload>() != NULL || *presence->getTo().getNode().c_str() == '#';
 
	// filter out login/logout presence spam
 
	if (!presence->getTo().getNode().empty() && isMUC == false)
 
		return;
 
	}
 

	
 
	JID bareJID(presence->getFrom().toBare());
 
	if (presence->getType() == Presence::Subscribe) {
src/transport.cpp
Show inline comments
 
@@ -45,6 +45,7 @@
 
#include "log4cxx/consoleappender.h"
 
#include "log4cxx/patternlayout.h"
 
#include "log4cxx/propertyconfigurator.h"
 
#include "Swiften/Swiften.h"
 

	
 
using namespace Swift;
 
using namespace boost;
src/util.cpp
Show inline comments
 
@@ -128,6 +128,15 @@ std::vector<std::string> deserializeGroups(std::string &groups) {
 
	return ret;
 
}
 

	
 
int getRandomPort(const std::string &s) {
 
	unsigned long r = 0;
 
	BOOST_FOREACH(char c, s) {
 
		r += (int) c;
 
	}
 
	srand(time(NULL) + r);
 
	return 30000 + rand() % 10000;
 
}
 

	
 
}
 

	
 
}
0 comments (0 inline, 0 general)