<commit_before>// ------------------------------------------------------------------
// pion-platform: a C++ framework for building lightweight HTTP interfaces
// ------------------------------------------------------------------
// Copyright (C) 2007 Atomic Labs, Inc.  (http://www.atomiclabs.com)
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file COPYING or copy at http://www.boost.org/LICENSE_1_0.txt
//

#ifndef _MSC_VER
	#include <fcntl.h>
	#include <unistd.h>
	#include <sys/stat.h>
#endif

#ifdef PION_HAVE_SSL
	#include <openssl/ssl.h>
#endif

#include <iostream>
#include <boost/filesystem/operations.hpp>
#include "PlatformConfig.hpp"
#include "../../net/utils/ShutdownManager.hpp"

using namespace std;
using namespace pion;
using namespace pion::net;
using namespace pion::platform;
using namespace pion::server;


// some forward declarations of functions used by main()
void daemonize_server(void);
void argument_error(void);


/// main control function
int main (int argc, char *argv[])
{
	// get platform config file
	bool run_as_daemon = false;
	std::string platform_config_file("/etc/pion/platform.xml");
	for (int argnum=1; argnum < argc; ++argnum) {
		if (argv[argnum][0] == '-') {
			if (argv[argnum][1] == 'D') {
				run_as_daemon = true;
			} else if (argv[argnum][1] == 'c' && argv[argnum][2] == '\0' && argnum+1 < argc) {
				platform_config_file = boost::filesystem::system_complete(argv[++argnum]).normalize().file_string();
			} else if (strncmp(argv[argnum], "--version", 9) == 0) {
				std::cout << "pion version " << PION_VERSION << std::endl;
				return 0;
			} else {
				argument_error();
				return 1;
			}
		} else {
			argument_error();
			return 1;
		}
	}
	
	/// become a daemon if the -D option is given
	if (run_as_daemon)
		daemonize_server();
	
	// setup signal handler
#ifdef PION_WIN32
	SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
#else
	signal(SIGPIPE, SIG_IGN);
	signal(SIGCHLD, SIG_IGN);
	signal(SIGTSTP, SIG_IGN);
	signal(SIGTTOU, SIG_IGN);
	signal(SIGTTIN, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGINT, handle_signal);
	signal(SIGTERM, handle_signal);
#endif
	
	// initialize log system (use simple configuration)
	PionLogger pion_log(PION_GET_LOGGER("pion"));

	// This level might be overridden if there is a LogConfig file specified in the platform 
	// configuration (and if using a logging library that supports logging configuration.)
	PION_LOG_SETLEVEL_INFO(pion_log);

	PION_LOG_CONFIG_BASIC;
	
#ifdef PION_HAVE_SSL
	// initialize the OpenSSL library
	SSL_library_init();
#endif

	PlatformConfig platform_cfg;<commit_msg>OpenSSL initializations and "applink" hack for Windows (trac #480)<commit_after>// ------------------------------------------------------------------
// pion-platform: a C++ framework for building lightweight HTTP interfaces
// ------------------------------------------------------------------
// Copyright (C) 2007 Atomic Labs, Inc.  (http://www.atomiclabs.com)
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file COPYING or copy at http://www.boost.org/LICENSE_1_0.txt
//

#ifndef _MSC_VER
	#include <fcntl.h>
	#include <unistd.h>
	#include <sys/stat.h>
#endif

#ifdef PION_HAVE_SSL
	#include <openssl/ssl.h>
#ifdef _MSC_VER
	#include <openssl/applink.c>
#endif
#endif

#include <iostream>
#include <boost/filesystem/operations.hpp>
#include "PlatformConfig.hpp"
#include "../../net/utils/ShutdownManager.hpp"

using namespace std;
using namespace pion;
using namespace pion::net;
using namespace pion::platform;
using namespace pion::server;


// some forward declarations of functions used by main()
void daemonize_server(void);
void argument_error(void);


/// main control function
int main (int argc, char *argv[])
{
	// get platform config file
	bool run_as_daemon = false;
	std::string platform_config_file("/etc/pion/platform.xml");
	for (int argnum=1; argnum < argc; ++argnum) {
		if (argv[argnum][0] == '-') {
			if (argv[argnum][1] == 'D') {
				run_as_daemon = true;
			} else if (argv[argnum][1] == 'c' && argv[argnum][2] == '\0' && argnum+1 < argc) {
				platform_config_file = boost::filesystem::system_complete(argv[++argnum]).normalize().file_string();
			} else if (strncmp(argv[argnum], "--version", 9) == 0) {
				std::cout << "pion version " << PION_VERSION << std::endl;
				return 0;
			} else {
				argument_error();
				return 1;
			}
		} else {
			argument_error();
			return 1;
		}
	}
	
	/// become a daemon if the -D option is given
	if (run_as_daemon)
		daemonize_server();
	
	// setup signal handler
#ifdef PION_WIN32
	SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
#else
	signal(SIGPIPE, SIG_IGN);
	signal(SIGCHLD, SIG_IGN);
	signal(SIGTSTP, SIG_IGN);
	signal(SIGTTOU, SIG_IGN);
	signal(SIGTTIN, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGINT, handle_signal);
	signal(SIGTERM, handle_signal);
#endif
	
	// initialize log system (use simple configuration)
	PionLogger pion_log(PION_GET_LOGGER("pion"));

	// This level might be overridden if there is a LogConfig file specified in the platform 
	// configuration (and if using a logging library that supports logging configuration.)
	PION_LOG_SETLEVEL_INFO(pion_log);

	PION_LOG_CONFIG_BASIC;
	
#ifdef PION_HAVE_SSL
	// initialize the OpenSSL library
	CRYPTO_malloc_init();
	SSL_library_init();
#endif

	PlatformConfig platform_cfg;
{'fraction_non_alphanumeric': 0.1781939551270165, 'fraction_numerical': 0.008715000927127759, 'mean_word_length': 3.4763485477178424, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040431', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1740, 'n_words': 467}