Skip to content

Commit

Permalink
LOGCXX-1: Migrate SMTPAppender to libesmtp
Browse files Browse the repository at this point in the history
  • Loading branch information
Curt Arnold committed Dec 11, 2007
1 parent bf8fa7a commit 8a35b42
Show file tree
Hide file tree
Showing 11 changed files with 914 additions and 353 deletions.
42 changes: 10 additions & 32 deletions configure.in
Expand Up @@ -121,7 +121,7 @@ AC_SUBST(base_dir)

AC_ARG_ENABLE(cppunit,
AC_HELP_STRING(--enable-cppunit,
[enable test excution with cppunit (auto)]))
[enable test execution with cppunit (auto)]))

enable_tests=yes

Expand Down Expand Up @@ -198,12 +198,6 @@ fi
AC_PROG_RANLIB


# for SocketAppender
AC_CHECK_FUNCS(gethostbyname,,
[AC_CHECK_LIB(nsl,gethostbyname,,
[AC_CHECK_LIB(socket,gethostbyname)])])
AC_CHECK_FUNCS(setsockopt,,[AC_CHECK_LIB(socket,setsockopt)])

#for ODBCAppender
AC_MSG_CHECKING(for ODBC support)
AC_ARG_WITH(ODBC,
Expand Down Expand Up @@ -256,44 +250,28 @@ AC_CHECK_FUNCS(gettimeofday ftime setenv mbsnrtowcs wcsnrtombs)
AC_MSG_CHECKING(for SMTP support)
AC_ARG_WITH(SMTP,
AC_HELP_STRING(--with-SMTP, [SMTP support. Accepted arguments :
libsmtp, CDO, no (default=no)]),
libesmtp, no (default=no)]),
[ac_with_smtp=$withval],
[ac_with_smtp=no])
case "$ac_with_smtp" in
CDO)
AC_MSG_RESULT(CDO)
AC_DEFINE(HAVE_CDO_SMTP, 1, SMTP support through Microsoft CDO.)
AC_DEFINE(HAVE_SMTP, 1, SMTP support)
;;
libsmtp)
AC_MSG_RESULT(libsmtp)
AC_CHECK_LIB([smtp_mime], [libsmtp_session_initialize],,
AC_MSG_ERROR(libsmtp library not found !),
`glib-config --libs` -lsmtp)
AC_DEFINE(HAVE_LIBSMTP, 1, SMTP support through libsmtp library.)
AC_DEFINE(HAVE_SMTP, 1, SMTP support)
LIBS="`glib-config --libs` -lsmtp $LIBS"
CPPFLAGS="`glib-config --cflags` $CPPFLAGS"
libesmtp)
AC_MSG_RESULT(libesmtp)
AC_CHECK_LIB([esmtp], [smtp_create_session],,
AC_MSG_ERROR(libesmtp library not found !),
-lesmtp)
AC_SUBST(HAS_LIBESMTP, 1, SMTP support through libesmtp library.)
LIBS="-lesmtp $LIBS"
;;
no)
AC_MSG_RESULT(no)
AC_SUBST(HAS_LIBESMTP, 0, SMTP support through libesmtp library.)
;;
*)
AC_MSG_RESULT(???)
AC_MSG_ERROR(Unknown option : $ac_with_smtp)
;;
esac

#for _T

case "$host" in
*apple-darwin*)
AC_DEFINE(MUST_UNDEF_T, 1, Defined to 1 if macro _T has to be undefined)
;;
esac

CPPFLAGS="-DLOG4CXX $CPPFLAGS"

#for wchar_t
AC_ARG_ENABLE(wchar_t,
AC_HELP_STRING(--enable-wchar_t,
Expand Down
233 changes: 233 additions & 0 deletions src/dependencies/esmtp/build.xml
@@ -0,0 +1,233 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!--
This file builds libesmtp using Apache Ant (http://ant.apache.org)
and the C++ compilation tasks from http://ant-contrib.sourceforge.net.
-->
<project name="esmtp" default="build">

<property name="debug" value="true"/>
<property name="esmtp.version" value="1.0.4"/>
<property name="esmtp.dir" location="${ant.file}/../../../../../libesmtp-${esmtp.version}"/>
<property name="esmtp.include.dir" location="${esmtp.dir}"/>
<property name="build.dir" location="${user.dir}/target"/>
<property name="src.dir" location="${esmtp.dir}"/>
<property name="esmtp.lib.type" value="shared"/>
<property name="project.dir" location="${build.dir}"/>

<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>

<target name="usage" description="Displays usage notes on build">
<echo>
</echo>
</target>

<target name="os-detect">
<condition property="is-mac" value="true">
<and>
<os family="mac"/>
<not><isset property="is-windows"/></not>
</and>
</condition>
<condition property="is-unix" value="true">
<and>
<not>
<or>
<isset property="is-windows"/>
<equals arg1="${os.family}" arg2="windows"/>
</or>
</not>
<or>
<os family="unix"/>
<equals arg1="${os.family}" arg2="cygwin"/>
<equals arg1="${os.family}" arg2="unix"/>
</or>
</and>
</condition>
<condition property="is-windows" value="true">
<and>
<not><isset property="is-unix"/></not>
<or>
<os family="windows"/>
<equals arg1="${os.family}" arg2="windows"/>
</or>
</and>
</condition>
</target>


<target name="win-init" depends="os-detect" if="is-windows">
<property name="compiler" value="msvc"/>
<property name="arch" value="win32"/>
<property name="project.type" value="msvc6"/>
</target>

<target name="unix-init" depends="os-detect" if="is-unix">
<property name="compiler" value="gcc"/>
<condition property="is-gcc" value="true">
<or>
<equals arg1="${compiler}" arg2="gcc"/>
<equals arg1="${compiler}" arg2="g++"/>
</or>
</condition>
<property name="arch" value="unix"/>
<property name="project.type" value="cbuilderx"/>
</target>

<target name="init" depends="win-init, unix-init">
<property environment="env"/>
<condition property="pic-option" value="-fPIC">
<and>
<isset property="is-gcc"/>
<istrue value="${use-pic}"/>
</and>
</condition>

<condition property="is-debug" value="true">
<istrue value="${debug}"/>
</condition>

<condition property="esmtp.lib.dir" value="${build.dir}/debug/${esmtp.lib.type}">
<isset property="is-debug"/>
</condition>
<property name="esmtp.lib.dir" location="${build.dir}/release/${esmtp.lib.type}"/>
<mkdir dir="${esmtp.lib.dir}"/>

<condition property="lib-suffix" value="d">
<isset property="is-debug"/>
</condition>
<property name="lib-suffix" value=""/>

<condition property="is-esmtp-shared" value="true">
<equals arg1="${esmtp.lib.type}" arg2="shared"/>
</condition>

<condition property="is-bcc" value="true">
<equals arg1="${compiler}" arg2="bcc"/>
</condition>
<condition property="project.if" value="true">
<istrue value="${project.if.value}"/>
</condition>
</target>

<target name="clean" description="Removes build product files">
<delete dir="${build.dir}"/>
</target>


<target name="configure-check" depends="init">
<condition property="esmtp-configure-available" value="true">
<available file="${esmtp.include.dir}/libesmtp.h"/>
</condition>
</target>


<target name="win-configure" depends="configure-check" if="is-windows" unless="esmtp-configure-available">
<copy tofile="${esmtp.include.dir}/libesmtp.h" file="${esmtp.include.dir}/libesmtp.hw"/>
</target>

<target name="unix-configure" depends="configure-check" if="is-unix" unless="esmtp-configure-available">
<!-- shelling to configure allows cygwin to work -->
<exec executable="sh" dir="${esmtp.dir}">
<arg value="./configure"/>
</exec>
</target>


<target name="configure" depends="unix-configure, win-configure"/>


<target name="build" depends="configure" description="Build library">
<mkdir dir="${esmtp.lib.dir}/esmtp_obj"/>
<property name="project.compiler" value="${compiler}"/>
<cc name="${project.compiler}"
outfile="${esmtp.lib.dir}/esmtp${lib-suffix}"
subsystem="console"
multithreaded="true"
outtype="${esmtp.lib.type}"
objdir="${esmtp.lib.dir}/esmtp_obj"
outputfileproperty="esmtp.dll"
debug="${debug}"
projectsOnly="${projectsOnly}">
<fileset dir="${src.dir}" includes="*.c" excludes="getaddrinfo.c"/>
<includepath path="${esmtp.include.dir}"/>
<defineset define="HAVE_CONFIG_H"/>
<defineset>
<define name="VERSION" value='"${esmtp.version}"'/>
</defineset>
<compilerarg value="${pic-option}" if="pic-option"/>
<libset libs="advapi32 ws2_32 mswsock rpcrt4" if="is-windows"/>
<libset libs="ssl crypto" if="is-unix"/>
<libset libs="cw32mt" if="is-bcc"/>
<project type="${project.type}" outfile="${project.dir}/esmtp" if="project.if"/>
</cc>
</target>


<target name="build-projects">
<mkdir dir="${project.dir}"/>
<antcall target="build">
<param name="project.if" value="true"/>
<param name="project.type" value="${project.type}"/>
<param name="project.compiler" value="${project.compiler}"/>
<param name="projects.dir" value="${project.dir}"/>
<param name="projectsOnly" value="true"/>
</antcall>
</target>

<target name="build-projects-vc6" description="Builds project files for Microsoft Visual C++ 6">
<antcall target="build-projects">
<param name="project.dir" value="msvc"/>
<param name="project.type" value="msvc6"/>
<param name="project.compiler" value="msvc"/>
</antcall>
</target>

<target name="build-projects-vc8" description="Builds project files for Microsoft Visual C++ 2005">
<antcall target="build-projects">
<param name="project.dir" value="msvc"/>
<param name="project.type" value="msvc8"/>
<param name="project.compiler" value="msvc"/>
</antcall>
</target>

<target name="build-projects-xcode" description="Builds project files for Apple Xcode">
<antcall target="build-projects">
<param name="project.dir" value="xcode"/>
<param name="project.type" value="xcode"/>
<param name="project.compiler" value="${compiler}"/>
</antcall>
</target>

<target name="build-projects-cbx" description="Builds project files for Borland CBuilderX">
<antcall target="build-projects">
<param name="project.dir" value="cbx"/>
<param name="project.type" value="cbuilderx"/>
<param name="project.compiler" value="${compiler}"/>
</antcall>
</target>



</project>
2 changes: 1 addition & 1 deletion src/main/cpp/class.cpp
Expand Up @@ -114,7 +114,7 @@ const Class& Class::forName(const LogString& className)
//
const Class* clazz = getRegistry()[lowerName];
if (clazz == 0) {
LogString::size_type pos = className.find_last_of(LOG4CXX_STR('.'));
LogString::size_type pos = className.find_last_of(LOG4CXX_STR(".$"));
if (pos != LogString::npos) {
LogString terminalName(lowerName, pos + 1, LogString::npos);
clazz = getRegistry()[terminalName];
Expand Down
18 changes: 12 additions & 6 deletions src/main/cpp/domconfigurator.cpp
Expand Up @@ -46,6 +46,7 @@
#include <apr_xml.h>
#include <log4cxx/helpers/bytebuffer.h>
#include <log4cxx/helpers/charsetdecoder.h>
#include <log4cxx/net/smtpappender.h>

using namespace log4cxx;
using namespace log4cxx::xml;
Expand Down Expand Up @@ -224,10 +225,16 @@ AppenderPtr DOMConfigurator::parseAppender(Pool& p,
}
else if (tagName == TRIGGERING_POLICY_TAG)
{
TriggeringPolicyPtr triggerPolicy(parseTriggeringPolicy(p, utf8Decoder, currentElement));
ObjectPtr policy(parseTriggeringPolicy(p, utf8Decoder, currentElement));
RollingFileAppenderPtr rfa(appender);
if (rfa != NULL) {
rfa->setTriggeringPolicy(triggerPolicy);
rfa->setTriggeringPolicy(policy);
} else {
log4cxx::net::SMTPAppenderPtr smtpa(appender);
if (smtpa != NULL) {
log4cxx::spi::TriggeringEventEvaluatorPtr evaluator(policy);
smtpa->setEvaluator(evaluator);
}
}
}
else if (tagName == APPENDER_REF_TAG)
Expand Down Expand Up @@ -521,7 +528,7 @@ LayoutPtr DOMConfigurator::parseLayout (
/**
Used internally to parse a triggering policy
*/
TriggeringPolicyPtr DOMConfigurator::parseTriggeringPolicy (
ObjectPtr DOMConfigurator::parseTriggeringPolicy (
log4cxx::helpers::Pool& p,
log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
apr_xml_elem* layout_element)
Expand All @@ -531,8 +538,7 @@ TriggeringPolicyPtr DOMConfigurator::parseTriggeringPolicy (
try
{
ObjectPtr instance = Loader::loadClass(className).newInstance();
TriggeringPolicyPtr layout = instance;
PropertySetter propSetter(layout);
PropertySetter propSetter(instance);

for (apr_xml_elem* currentElement = layout_element->first_child;
currentElement;
Expand All @@ -557,7 +563,7 @@ TriggeringPolicyPtr DOMConfigurator::parseTriggeringPolicy (
}

propSetter.activate(p);
return layout;
return instance;
}
catch (Exception& oops)
{
Expand Down
5 changes: 3 additions & 2 deletions src/main/cpp/propertysetter.cpp
Expand Up @@ -69,6 +69,7 @@ void PropertySetter::setProperties(helpers::Properties& properties,
LogString value = OptionConverter::findAndSubst(key, properties);
key = key.substr(len);
if (key == LOG4CXX_STR("layout")
&& obj != 0
&& obj->instanceof(Appender::getStaticClass()))
{
continue;
Expand All @@ -86,7 +87,7 @@ void PropertySetter::setProperty(const LogString& option,
if (value.empty())
return;

if (obj->instanceof(OptionHandler::getStaticClass()))
if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
{
LogLog::debug(LOG4CXX_STR("Setting option name=[") +
option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
Expand All @@ -96,7 +97,7 @@ void PropertySetter::setProperty(const LogString& option,

void PropertySetter::activate(Pool& p)
{
if (obj->instanceof(OptionHandler::getStaticClass()))
if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
{
OptionHandlerPtr(obj)->activateOptions(p);
}
Expand Down

0 comments on commit 8a35b42

Please sign in to comment.