Changeset - 8ef6fb320ae8
[Not reviewed]
0 2 0
Vitaly Takmazov - 9 years ago 2016-04-27 13:16:49
vitalyster@gmail.com
spectrum2_manager: enable SSL only when using OpenSSL library
2 files changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp *.c)
 

	
 
ADD_EXECUTABLE(spectrum2_manager ${SRC})
 

	
 
ADD_DEPENDENCIES(spectrum2_manager pb)
 
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.pb.cc PROPERTIES GENERATED 1)
 

	
 
target_link_libraries(spectrum2_manager transport ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES})
 

	
 
if (${OPENSSL_FOUND})
 
add_definitions(-DMG_ENABLE_SSL)
 
endif()
 
if (CMAKE_COMPILER_IS_GNUCXX)
 
target_link_libraries(spectrum2_manager ${OPENSSL_LIBRARIES})
 
endif()
 

	
 
if(APPLE)
 
target_link_libraries(spectrum2_manager transport ${APPLE_FRAMEWORKS})
 
endif()
 
INSTALL(TARGETS spectrum2_manager RUNTIME DESTINATION bin)
 

	
 
# IF(NOT EXISTS "/etc/spectrum2/spectrum_manager.cfg")
 
# INSTALL(FILES
 
# 	spectrum_manager.cfg
spectrum_manager/src/server.cpp
Show inline comments
 
@@ -66,32 +66,33 @@ Server::Server(ManagerConfig *config, const std::string &config_file) {
 

	
 
	mg_mgr_init(&m_mgr, this);
 

	
 
	struct mg_bind_opts opts;
 
	memset(&opts, 0, sizeof(opts));
 
	const char *error_string;
 
	opts.error_string = &error_string;
 
	m_nc = mg_bind_opt(&m_mgr, std::string(":" + boost::lexical_cast<std::string>(CONFIG_INT(m_config, "service.port"))).c_str(), &_event_handler, opts);
 
	if (!m_nc) {
 
		std::cerr << "Error creating server: " << error_string << "\n";
 
		exit(1);
 
	}
 

	
 
#ifdef MG_ENABLE_SSL
 
	if (!CONFIG_STRING(m_config, "service.cert").empty()) {
 
		const char *err_str = mg_set_ssl(m_nc, CONFIG_STRING(m_config, "service.cert").c_str(), NULL);
 
		if (err_str) {
 
			std::cerr << "Error setting SSL certificate: " << err_str << "\n";
 
			exit(1);
 
		}
 
	}
 
#endif
 
	mg_set_protocol_http_websocket(m_nc);
 

	
 
	s_http_server_opts.document_root = CONFIG_STRING(m_config, "service.data_dir").c_str();
 

	
 
	std::ifstream header(std::string(CONFIG_STRING(m_config, "service.data_dir") + "/header.html").c_str(), std::ios::in);
 
	if (header) {
 
		header.seekg(0, std::ios::end);
 
		m_header.resize(header.tellg());
 
		header.seekg(0, std::ios::beg);
 
		header.read(&m_header[0], m_header.size());
 
		header.close();
 
	}
0 comments (0 inline, 0 general)