Changeset - 27e0dd7bb59b
[Not reviewed]
0 3 0
Jan Kaluza - 13 years ago 2012-08-20 12:42:10
hanzz.k@gmail.com
Send curl debug to stdcerr
3 files changed with 14 insertions and 4 deletions:
0 comments (0 inline, 0 general)
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
#include <memory.h>
 
#include "twitcurl.h"
 
#include "urlencode.h"
 
 
static int myDebugCallback(CURL *,
 
                    curl_infotype type,
 
                    char *data,
 
                    size_t size,
 
                    void *handle)
 
{
 
	std::cerr << std::string(data, size);
 
  return 0;
 
};
 
 
/*++
 
* @method: twitCurl::twitCurl
 
*
 
* @description: constructor
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
twitCurl::twitCurl():
 
m_curlHandle( NULL ),
 
m_curlProxyParamsSet( false ),
 
m_curlLoginParamsSet( false ),
 
m_curlCallbackParamsSet( false ),
 
m_eApiFormatType( twitCurlTypes::eTwitCurlApiFormatXml ),
 
m_eProtocolType( twitCurlTypes::eTwitCurlProtocolHttp )
 
{
 
    /* Clear callback buffers */
 
    clearCurlCallbackBuffers();
 
 
    /* Initialize cURL */
 
    m_curlHandle = curl_easy_init();
 
    if( NULL == m_curlHandle )
 
    {
 
        std::string dummyStr;
 
        getLastCurlError( dummyStr );
 
    }
 
    curl_easy_setopt(m_curlHandle, CURLOPT_VERBOSE, 1);
 
	curl_easy_setopt(m_curlHandle, CURLOPT_DEBUGFUNCTION, myDebugCallback);
 
}
 
 
/*++
 
* @method: twitCurl::~twitCurl
 
*
 
* @description: destructor
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
twitCurl::~twitCurl()
 
{
 
    /* Cleanup cURL */
 
    if( m_curlHandle )
 
    {
 
        curl_easy_cleanup( m_curlHandle );
 
        m_curlHandle = NULL;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::clone
 
*
 
* @description: creates a clone of twitcurl object
 
*
 
* @input: none
 
*
 
* @output: cloned object
 
*
 
*--*/
 
twitCurl* twitCurl::clone()
 
{
 
	twitCurl *cloneObj = new twitCurl();
 
 
	/* cURL proxy data */
 
	cloneObj->setProxyServerIp(m_proxyServerIp);
 
	cloneObj->setProxyServerPort(m_proxyServerPort);
 
	cloneObj->setProxyUserName(m_proxyUserName);
 
	cloneObj->setProxyPassword(m_proxyPassword);
 
 
	/* Twitter data */
 
	cloneObj->setTwitterUsername(m_twitterUsername);
 
	cloneObj->setTwitterPassword(m_twitterPassword);
 
 
	/* Twitter API type */
 
	cloneObj->setTwitterApiType(m_eApiFormatType);
 
 
	/* OAuth data */
 
	cloneObj->m_oAuth = m_oAuth.clone();
 
 
	return cloneObj;
 
}
 
 
/*++
 
* @method: twitCurl::setTwitterApiType
 
*
 
* @description: method to set API type
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatType eType )
 
{
 
    m_eApiFormatType = ( eType < twitCurlTypes::eTwitCurlApiFormatMax ) ?
 
                        eType : twitCurlTypes::eTwitCurlApiFormatXml;
 
}
 
 
/*++
 
* @method: twitCurl::setTwitterProcotolType
 
*
 
* @description: method to set protocol
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterProcotolType( twitCurlTypes::eTwitCurlProtocolType eType )
 
{
 
    m_eProtocolType = ( eType < twitCurlTypes::eTwitCurlProtocolMax ) ?
 
                        eType : twitCurlTypes::eTwitCurlProtocolHttp;
 
}
 
 
/*++
 
* @method: twitCurl::isCurlInit
 
*
 
* @description: method to check if cURL is initialized properly
 
*
 
* @input: none
 
*
 
* @output: true if cURL is intialized, otherwise false
 
*
cmake_modules/opensslConfig.cmake
Show inline comments
 
@@ -143,110 +143,108 @@
 
          ${_OPENSSL_ROOT_HINTS_AND_PATHS}
 
          PATH_SUFFIXES
 
            "lib"
 
            "lib/MinGW"
 
        )
 
     
 
        FIND_LIBRARY(SSL_EAY
 
          NAMES
 
            ssleay32
 
          ${_OPENSSL_ROOT_HINTS_AND_PATHS}
 
          PATH_SUFFIXES
 
            "lib"
 
            "lib/MinGW"
 
        )
 
     
 
        MARK_AS_ADVANCED(SSL_EAY LIB_EAY)
 
        set( OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} )
 
      ELSE(MSVC)
 
        # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues:
 
        FIND_LIBRARY(LIB_EAY
 
          NAMES
 
            libeay32
 
          HINTS
 
            ${_OPENSSL_LIBDIR}
 
          ${_OPENSSL_ROOT_HINTS_AND_PATHS}
 
          PATH_SUFFIXES
 
            lib
 
        )
 
     
 
        FIND_LIBRARY(SSL_EAY
 
          NAMES
 
            ssleay32
 
          HINTS
 
            ${_OPENSSL_LIBDIR}
 
          ${_OPENSSL_ROOT_HINTS_AND_PATHS}
 
          PATH_SUFFIXES
 
            lib
 
        )
 
     
 
        MARK_AS_ADVANCED(SSL_EAY LIB_EAY)
 
        set( OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} )
 
      ENDIF(MSVC)
 
    ELSE(WIN32 AND NOT CYGWIN)
 
     
 
      FIND_LIBRARY(OPENSSL_SSL_LIBRARY
 
        NAMES
 
          ssl
 
          ssleay32
 
          ssleay32MD
 
        HINTS
 
          ${_OPENSSL_LIBDIR}
 
        ${_OPENSSL_ROOT_HINTS_AND_PATHS}
 
        PATH_SUFFIXES
 
          lib
 
      )
 
     
 
      FIND_LIBRARY(OPENSSL_CRYPTO_LIBRARY
 
        NAMES
 
          crypto
 
        HINTS
 
          ${_OPENSSL_LIBDIR}
 
        ${_OPENSSL_ROOT_HINTS_AND_PATHS}
 
        PATH_SUFFIXES
 
          lib
 
      )
 
     
 
      MARK_AS_ADVANCED(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
 
     
 
      # compat defines
 
      SET(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
 
      SET(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
 
     
 
      SET(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
 
     
 
    ENDIF(WIN32 AND NOT CYGWIN)
 
     
 
    if (OPENSSL_INCLUDE_DIR)
 
      file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x[0-9][0-9][0-9][0-9][0-9][0-9].*")
 
     
 
      string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9]).*$" "\\1" OPENSSL_VERSION_MAJOR "${openssl_version_str}")
 
      string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x[0-9]([0-9][0-9]).*$" "\\1" OPENSSL_VERSION_MINOR  "${openssl_version_str}")
 
      string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x[0-9][0-9][0-9]([0-9][0-9]).*$" "\\1" OPENSSL_VERSION_PATCH "${openssl_version_str}")
 
     
 
      string(REGEX REPLACE "^0" "" OPENSSL_VERSION_MINOR "${OPENSSL_VERSION_MINOR}")
 
      string(REGEX REPLACE "^0" "" OPENSSL_VERSION_PATCH "${OPENSSL_VERSION_PATCH}")
 
     
 
      set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_PATCH}")
 
    endif (OPENSSL_INCLUDE_DIR)
 
     
 
    include(FindPackageHandleStandardArgs)
 
     
 
    if (OPENSSL_VERSION)
 
      find_package_handle_standard_args(OpenSSL
 
        REQUIRED_VARS
 
          OPENSSL_LIBRARIES
 
          OPENSSL_INCLUDE_DIR
 
        VERSION_VAR
 
          OPENSSL_VERSION
 
        FAIL_MESSAGE
 
          "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
 
      )
 
    else (OPENSSL_VERSION)
 
      find_package_handle_standard_args(OpenSSL "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
 
        OPENSSL_LIBRARIES
 
        OPENSSL_INCLUDE_DIR
 
      )
 
    endif (OPENSSL_VERSION)
 
     
 
    MARK_AS_ADVANCED(OPENSSL_INCLUDE_DIR OPENSSL_LIBRARIES)
 
     
 
\ No newline at end of file
src/logging.cpp
Show inline comments
 
/**
 
 * libtransport -- C++ library for easy XMPP Transports development
 
 *
 
 * Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/logging.h"
 
#include "transport/config.h"
 
#include <boost/foreach.hpp>
 
#include <iostream>
 
#include <iterator>
 
#include <algorithm>
 

	
 

	
 
#include <boost/filesystem.hpp>
 
#include <boost/algorithm/string.hpp>
 

	
 
#ifndef WIN32
 
#include "sys/signal.h"
 
#include <pwd.h>
 
#include <grp.h>
 
#include <sys/resource.h>
 
#include "libgen.h"
 
#else
 
#include <windows.h>
 
#include <process.h>
 
#define getpid _getpid
 
#endif
 

	
 
using namespace boost::filesystem;
 

	
 

	
 
namespace Transport {
 

	
 
namespace Logging {
 

	
 
#ifdef WITH_LOG4CXX
 
using namespace log4cxx;
 
static LoggerPtr root;
 

	
 

	
 
class intercept_stream : public std::streambuf{
 
public:
 
    intercept_stream(std::ostream& stream, char const* logger):
 
      _logger(log4cxx::Logger::getLogger(logger))
 
    {
 
		stream.rdbuf(this);
 
    }
 
    ~intercept_stream(){
 
    }
 
protected:
 
    virtual std::streamsize xsputn(const char *msg, std::streamsize count){
 

	
 
        //Output to log4cxx logger
 
        std::string s(msg,count);
 
		LOG4CXX_INFO(_logger, msg);
 
        std::string s(msg, count - 1); // remove last \n
 
		LOG4CXX_INFO(_logger, s);
 
        return count;
 
    }
 

	
 
	int overflow(int c)
 
	{
 
		return 0;
 
	}
 

	
 
	int sync()
 
	{
 
		return 0;
 
	}
 

	
 
private:
 
    log4cxx::LoggerPtr _logger;
 
};
 

	
 
static intercept_stream* intercepter_cout;
 
static intercept_stream* intercepter_cerr;
 

	
 

	
 
static void initLogging(Config *config, std::string key) {
 
	if (CONFIG_STRING(config, key).empty()) {
 
		root = log4cxx::Logger::getRootLogger();
 
#ifdef WIN32
 
		root->addAppender(new ConsoleAppender(new PatternLayout(L"%d %-5p %c: %m%n")));
 
#else
 
		root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n")));
 
#endif
 
	}
 
	else {
 
		log4cxx::helpers::Properties p;
 

	
 
		log4cxx::helpers::FileInputStream *istream = NULL;
 
		try {
 
			istream = new log4cxx::helpers::FileInputStream(CONFIG_STRING(config, key));
 
		}
 
		catch(log4cxx::helpers::IOException &ex) {
 
			std::cerr << "Can't create FileInputStream logger instance: " << ex.what() << "\n";
 
		}
 
		catch (...) {
 
			std::cerr << "Can't create FileInputStream logger instance\n";
 
		}
 

	
 
		if (!istream) {
 
			return;
 
		}
 

	
 
		p.load(istream);
 
		LogString pid, jid;
 
		log4cxx::helpers::Transcoder::decode(boost::lexical_cast<std::string>(getpid()), pid);
 
		log4cxx::helpers::Transcoder::decode(CONFIG_STRING(config, "service.jid"), jid);
 
#ifdef WIN32
 
		p.setProperty(L"pid", pid);
 
		p.setProperty(L"jid", jid);
 
#else
 
		p.setProperty("pid", pid);
 
		p.setProperty("jid", jid);
 
#endif
 

	
 
		std::string dir;
 
		BOOST_FOREACH(const log4cxx::LogString &prop, p.propertyNames()) {
 
			if (boost::ends_with(prop, ".File")) {
 
				log4cxx::helpers::Transcoder::encode(p.get(prop), dir);
 
				boost::replace_all(dir, "${jid}", jid);
 
				break;
 
			}
 
		}
 

	
 
		if (!dir.empty()) {
 
			// create directories
 
			try {
 
				boost::filesystem::create_directories(
 
					boost::filesystem::path(dir).parent_path().string()
 
				);
 
			}
 
			catch (...) {
 
				std::cerr << "Can't create logging directory directory " << boost::filesystem::path(dir).parent_path().string() << ".\n";
 
			}
 

	
 
#ifndef WIN32
 
			if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) {
 
				struct group *gr;
 
				if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) {
 
					std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n";
 
				}
 
				struct passwd *pw;
 
				if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) {
 
					std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n";
 
				}
 
				chown(dir.c_str(), pw->pw_uid, gr->gr_gid);
 
			}
 

	
 
#endif
 
		}
 

	
0 comments (0 inline, 0 general)