1*2dc7e66cSDamjan Jovanovic /**************************************************************
2*2dc7e66cSDamjan Jovanovic  *
3*2dc7e66cSDamjan Jovanovic  * Licensed to the Apache Software Foundation (ASF) under one
4*2dc7e66cSDamjan Jovanovic  * or more contributor license agreements.  See the NOTICE file
5*2dc7e66cSDamjan Jovanovic  * distributed with this work for additional information
6*2dc7e66cSDamjan Jovanovic  * regarding copyright ownership.  The ASF licenses this file
7*2dc7e66cSDamjan Jovanovic  * to you under the Apache License, Version 2.0 (the
8*2dc7e66cSDamjan Jovanovic  * "License"); you may not use this file except in compliance
9*2dc7e66cSDamjan Jovanovic  * with the License.  You may obtain a copy of the License at
10*2dc7e66cSDamjan Jovanovic  *
11*2dc7e66cSDamjan Jovanovic  *   http://www.apache.org/licenses/LICENSE-2.0
12*2dc7e66cSDamjan Jovanovic  *
13*2dc7e66cSDamjan Jovanovic  * Unless required by applicable law or agreed to in writing,
14*2dc7e66cSDamjan Jovanovic  * software distributed under the License is distributed on an
15*2dc7e66cSDamjan Jovanovic  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2dc7e66cSDamjan Jovanovic  * KIND, either express or implied.  See the License for the
17*2dc7e66cSDamjan Jovanovic  * specific language governing permissions and limitations
18*2dc7e66cSDamjan Jovanovic  * under the License.
19*2dc7e66cSDamjan Jovanovic  *
20*2dc7e66cSDamjan Jovanovic  *************************************************************/
21*2dc7e66cSDamjan Jovanovic 
22*2dc7e66cSDamjan Jovanovic 
23*2dc7e66cSDamjan Jovanovic 
24*2dc7e66cSDamjan Jovanovic // MARKER(update_precomp.py): autogen include statement, do not remove
25*2dc7e66cSDamjan Jovanovic #include "precompiled_extensions.hxx"
26*2dc7e66cSDamjan Jovanovic 
27*2dc7e66cSDamjan Jovanovic #include "log_module.hxx"
28*2dc7e66cSDamjan Jovanovic #include "methodguard.hxx"
29*2dc7e66cSDamjan Jovanovic #include "loghandler.hxx"
30*2dc7e66cSDamjan Jovanovic 
31*2dc7e66cSDamjan Jovanovic /** === begin UNO includes === **/
32*2dc7e66cSDamjan Jovanovic #include <com/sun/star/logging/XConsoleHandler.hpp>
33*2dc7e66cSDamjan Jovanovic #include <com/sun/star/lang/XServiceInfo.hpp>
34*2dc7e66cSDamjan Jovanovic #include <com/sun/star/logging/LogLevel.hpp>
35*2dc7e66cSDamjan Jovanovic #include <com/sun/star/lang/XInitialization.hpp>
36*2dc7e66cSDamjan Jovanovic #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
37*2dc7e66cSDamjan Jovanovic #include <com/sun/star/lang/IllegalArgumentException.hpp>
38*2dc7e66cSDamjan Jovanovic #include <com/sun/star/beans/NamedValue.hpp>
39*2dc7e66cSDamjan Jovanovic /** === end UNO includes === **/
40*2dc7e66cSDamjan Jovanovic 
41*2dc7e66cSDamjan Jovanovic #include <tools/diagnose_ex.h>
42*2dc7e66cSDamjan Jovanovic 
43*2dc7e66cSDamjan Jovanovic #include <comphelper/componentcontext.hxx>
44*2dc7e66cSDamjan Jovanovic 
45*2dc7e66cSDamjan Jovanovic #include <cppuhelper/compbase3.hxx>
46*2dc7e66cSDamjan Jovanovic #include <cppuhelper/basemutex.hxx>
47*2dc7e66cSDamjan Jovanovic 
48*2dc7e66cSDamjan Jovanovic #include <rtl/strbuf.hxx>
49*2dc7e66cSDamjan Jovanovic #include <osl/process.h>
50*2dc7e66cSDamjan Jovanovic #include <osl/socket.hxx>
51*2dc7e66cSDamjan Jovanovic #include <osl/time.h>
52*2dc7e66cSDamjan Jovanovic 
53*2dc7e66cSDamjan Jovanovic #include <stdio.h>
54*2dc7e66cSDamjan Jovanovic 
55*2dc7e66cSDamjan Jovanovic //........................................................................
56*2dc7e66cSDamjan Jovanovic namespace logging
57*2dc7e66cSDamjan Jovanovic {
58*2dc7e66cSDamjan Jovanovic //........................................................................
59*2dc7e66cSDamjan Jovanovic 
60*2dc7e66cSDamjan Jovanovic 	/** === begin UNO using === **/
61*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::logging::XLogHandler;
62*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::lang::XServiceInfo;
63*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::Reference;
64*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::XComponentContext;
65*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::RuntimeException;
66*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::logging::XLogFormatter;
67*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::Sequence;
68*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::logging::LogRecord;
69*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::UNO_QUERY_THROW;
70*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::Exception;
71*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::Any;
72*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::uno::XInterface;
73*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::lang::XInitialization;
74*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::ucb::AlreadyInitializedException;
75*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::lang::IllegalArgumentException;
76*2dc7e66cSDamjan Jovanovic     using ::com::sun::star::beans::NamedValue;
77*2dc7e66cSDamjan Jovanovic 	/** === end UNO using === **/
78*2dc7e66cSDamjan Jovanovic     namespace LogLevel = ::com::sun::star::logging::LogLevel;
79*2dc7e66cSDamjan Jovanovic 
80*2dc7e66cSDamjan Jovanovic 	//====================================================================
81*2dc7e66cSDamjan Jovanovic 	//= SyslogHandler - declaration
82*2dc7e66cSDamjan Jovanovic 	//====================================================================
83*2dc7e66cSDamjan Jovanovic 	//--------------------------------------------------------------------
84*2dc7e66cSDamjan Jovanovic     typedef ::cppu::WeakComponentImplHelper3    <   XLogHandler
85*2dc7e66cSDamjan Jovanovic                                                 ,   XServiceInfo
86*2dc7e66cSDamjan Jovanovic                                                 ,   XInitialization
87*2dc7e66cSDamjan Jovanovic                                                 >   SyslogHandler_Base;
88*2dc7e66cSDamjan Jovanovic     class SyslogHandler    :public ::cppu::BaseMutex
89*2dc7e66cSDamjan Jovanovic                             ,public SyslogHandler_Base
90*2dc7e66cSDamjan Jovanovic 	{
91*2dc7e66cSDamjan Jovanovic     private:
92*2dc7e66cSDamjan Jovanovic         ::comphelper::ComponentContext  m_aContext;
93*2dc7e66cSDamjan Jovanovic         LogHandlerHelper                m_aHandlerHelper;
94*2dc7e66cSDamjan Jovanovic         ::osl::SocketAddr               m_aSocketAddress;
95*2dc7e66cSDamjan Jovanovic         ::osl::DatagramSocket           m_aSocket;
96*2dc7e66cSDamjan Jovanovic 
97*2dc7e66cSDamjan Jovanovic     protected:
98*2dc7e66cSDamjan Jovanovic         SyslogHandler( const Reference< XComponentContext >& _rxContext );
99*2dc7e66cSDamjan Jovanovic         virtual ~SyslogHandler();
100*2dc7e66cSDamjan Jovanovic 
101*2dc7e66cSDamjan Jovanovic         // XLogHandler
102*2dc7e66cSDamjan Jovanovic         virtual ::rtl::OUString SAL_CALL getEncoding() throw (RuntimeException);
103*2dc7e66cSDamjan Jovanovic         virtual void SAL_CALL setEncoding( const ::rtl::OUString& _encoding ) throw (RuntimeException);
104*2dc7e66cSDamjan Jovanovic         virtual Reference< XLogFormatter > SAL_CALL getFormatter() throw (RuntimeException);
105*2dc7e66cSDamjan Jovanovic         virtual void SAL_CALL setFormatter( const Reference< XLogFormatter >& _formatter ) throw (RuntimeException);
106*2dc7e66cSDamjan Jovanovic         virtual ::sal_Int32 SAL_CALL getLevel() throw (RuntimeException);
107*2dc7e66cSDamjan Jovanovic         virtual void SAL_CALL setLevel( ::sal_Int32 _level ) throw (RuntimeException);
108*2dc7e66cSDamjan Jovanovic         virtual void SAL_CALL flush(  ) throw (RuntimeException);
109*2dc7e66cSDamjan Jovanovic         virtual ::sal_Bool SAL_CALL publish( const LogRecord& Record ) throw (RuntimeException);
110*2dc7e66cSDamjan Jovanovic 
111*2dc7e66cSDamjan Jovanovic         // XInitialization
112*2dc7e66cSDamjan Jovanovic         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
113*2dc7e66cSDamjan Jovanovic 
114*2dc7e66cSDamjan Jovanovic         // XServiceInfo
115*2dc7e66cSDamjan Jovanovic 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
116*2dc7e66cSDamjan Jovanovic         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException);
117*2dc7e66cSDamjan Jovanovic         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
118*2dc7e66cSDamjan Jovanovic 
119*2dc7e66cSDamjan Jovanovic         // OComponentHelper
120*2dc7e66cSDamjan Jovanovic         virtual void SAL_CALL disposing();
121*2dc7e66cSDamjan Jovanovic 
122*2dc7e66cSDamjan Jovanovic     public:
123*2dc7e66cSDamjan Jovanovic         // XServiceInfo - static version
124*2dc7e66cSDamjan Jovanovic 		static ::rtl::OUString SAL_CALL getImplementationName_static();
125*2dc7e66cSDamjan Jovanovic         static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
126*2dc7e66cSDamjan Jovanovic         static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
127*2dc7e66cSDamjan Jovanovic 
128*2dc7e66cSDamjan Jovanovic     public:
129*2dc7e66cSDamjan Jovanovic         typedef ComponentMethodGuard< SyslogHandler > MethodGuard;
130*2dc7e66cSDamjan Jovanovic         void    enterMethod( MethodGuard::Access );
131*2dc7e66cSDamjan Jovanovic         void    leaveMethod( MethodGuard::Access );
132*2dc7e66cSDamjan Jovanovic 	};
133*2dc7e66cSDamjan Jovanovic 
134*2dc7e66cSDamjan Jovanovic     //====================================================================
135*2dc7e66cSDamjan Jovanovic 	//= SyslogHandler - implementation
136*2dc7e66cSDamjan Jovanovic 	//====================================================================
137*2dc7e66cSDamjan Jovanovic 	//--------------------------------------------------------------------
SyslogHandler(const Reference<XComponentContext> & _rxContext)138*2dc7e66cSDamjan Jovanovic     SyslogHandler::SyslogHandler( const Reference< XComponentContext >& _rxContext )
139*2dc7e66cSDamjan Jovanovic         :SyslogHandler_Base( m_aMutex )
140*2dc7e66cSDamjan Jovanovic         ,m_aContext( _rxContext )
141*2dc7e66cSDamjan Jovanovic         ,m_aHandlerHelper( _rxContext, m_aMutex, rBHelper )
142*2dc7e66cSDamjan Jovanovic         ,m_aSocketAddress()
143*2dc7e66cSDamjan Jovanovic         ,m_aSocket()
144*2dc7e66cSDamjan Jovanovic     {
145*2dc7e66cSDamjan Jovanovic     }
146*2dc7e66cSDamjan Jovanovic 
147*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
~SyslogHandler()148*2dc7e66cSDamjan Jovanovic     SyslogHandler::~SyslogHandler()
149*2dc7e66cSDamjan Jovanovic     {
150*2dc7e66cSDamjan Jovanovic         if ( !rBHelper.bDisposed )
151*2dc7e66cSDamjan Jovanovic         {
152*2dc7e66cSDamjan Jovanovic             acquire();
153*2dc7e66cSDamjan Jovanovic             dispose();
154*2dc7e66cSDamjan Jovanovic         }
155*2dc7e66cSDamjan Jovanovic     }
156*2dc7e66cSDamjan Jovanovic 
157*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
disposing()158*2dc7e66cSDamjan Jovanovic     void SAL_CALL SyslogHandler::disposing()
159*2dc7e66cSDamjan Jovanovic     {
160*2dc7e66cSDamjan Jovanovic         m_aHandlerHelper.setFormatter( NULL );
161*2dc7e66cSDamjan Jovanovic     }
162*2dc7e66cSDamjan Jovanovic 
163*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
enterMethod(MethodGuard::Access)164*2dc7e66cSDamjan Jovanovic     void SyslogHandler::enterMethod( MethodGuard::Access )
165*2dc7e66cSDamjan Jovanovic     {
166*2dc7e66cSDamjan Jovanovic         m_aHandlerHelper.enterMethod();
167*2dc7e66cSDamjan Jovanovic     }
168*2dc7e66cSDamjan Jovanovic 
169*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
leaveMethod(MethodGuard::Access)170*2dc7e66cSDamjan Jovanovic     void SyslogHandler::leaveMethod( MethodGuard::Access )
171*2dc7e66cSDamjan Jovanovic     {
172*2dc7e66cSDamjan Jovanovic         m_aMutex.release();
173*2dc7e66cSDamjan Jovanovic     }
174*2dc7e66cSDamjan Jovanovic 
175*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getEncoding()176*2dc7e66cSDamjan Jovanovic     ::rtl::OUString SAL_CALL SyslogHandler::getEncoding() throw (RuntimeException)
177*2dc7e66cSDamjan Jovanovic     {
178*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
179*2dc7e66cSDamjan Jovanovic         ::rtl::OUString sEncoding;
180*2dc7e66cSDamjan Jovanovic         OSL_VERIFY( m_aHandlerHelper.getEncoding( sEncoding ) );
181*2dc7e66cSDamjan Jovanovic         return sEncoding;
182*2dc7e66cSDamjan Jovanovic     }
183*2dc7e66cSDamjan Jovanovic 
184*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
setEncoding(const::rtl::OUString & _rEncoding)185*2dc7e66cSDamjan Jovanovic     void SAL_CALL SyslogHandler::setEncoding( const ::rtl::OUString& _rEncoding ) throw (RuntimeException)
186*2dc7e66cSDamjan Jovanovic     {
187*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
188*2dc7e66cSDamjan Jovanovic         OSL_VERIFY( m_aHandlerHelper.setEncoding( _rEncoding ) );
189*2dc7e66cSDamjan Jovanovic     }
190*2dc7e66cSDamjan Jovanovic 
191*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getFormatter()192*2dc7e66cSDamjan Jovanovic     Reference< XLogFormatter > SAL_CALL SyslogHandler::getFormatter() throw (RuntimeException)
193*2dc7e66cSDamjan Jovanovic     {
194*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
195*2dc7e66cSDamjan Jovanovic         return m_aHandlerHelper.getFormatter();
196*2dc7e66cSDamjan Jovanovic     }
197*2dc7e66cSDamjan Jovanovic 
198*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
setFormatter(const Reference<XLogFormatter> & _rxFormatter)199*2dc7e66cSDamjan Jovanovic     void SAL_CALL SyslogHandler::setFormatter( const Reference< XLogFormatter >& _rxFormatter ) throw (RuntimeException)
200*2dc7e66cSDamjan Jovanovic     {
201*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
202*2dc7e66cSDamjan Jovanovic         m_aHandlerHelper.setFormatter( _rxFormatter );
203*2dc7e66cSDamjan Jovanovic     }
204*2dc7e66cSDamjan Jovanovic 
205*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getLevel()206*2dc7e66cSDamjan Jovanovic     ::sal_Int32 SAL_CALL SyslogHandler::getLevel() throw (RuntimeException)
207*2dc7e66cSDamjan Jovanovic     {
208*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
209*2dc7e66cSDamjan Jovanovic         return m_aHandlerHelper.getLevel();
210*2dc7e66cSDamjan Jovanovic     }
211*2dc7e66cSDamjan Jovanovic 
212*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
setLevel(::sal_Int32 _nLevel)213*2dc7e66cSDamjan Jovanovic     void SAL_CALL SyslogHandler::setLevel( ::sal_Int32 _nLevel ) throw (RuntimeException)
214*2dc7e66cSDamjan Jovanovic     {
215*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
216*2dc7e66cSDamjan Jovanovic         m_aHandlerHelper.setLevel( _nLevel );
217*2dc7e66cSDamjan Jovanovic     }
218*2dc7e66cSDamjan Jovanovic 
219*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
flush()220*2dc7e66cSDamjan Jovanovic     void SAL_CALL SyslogHandler::flush(  ) throw (RuntimeException)
221*2dc7e66cSDamjan Jovanovic     {
222*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
223*2dc7e66cSDamjan Jovanovic         fflush( stdout );
224*2dc7e66cSDamjan Jovanovic         fflush( stderr );
225*2dc7e66cSDamjan Jovanovic     }
226*2dc7e66cSDamjan Jovanovic 
227*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
publish(const LogRecord & _rRecord)228*2dc7e66cSDamjan Jovanovic     ::sal_Bool SAL_CALL SyslogHandler::publish( const LogRecord& _rRecord ) throw (RuntimeException)
229*2dc7e66cSDamjan Jovanovic     {
230*2dc7e66cSDamjan Jovanovic         MethodGuard aGuard( *this );
231*2dc7e66cSDamjan Jovanovic 
232*2dc7e66cSDamjan Jovanovic         ::rtl::OString sEntry;
233*2dc7e66cSDamjan Jovanovic         if ( !m_aHandlerHelper.formatForPublishing( _rRecord, sEntry ) )
234*2dc7e66cSDamjan Jovanovic             return sal_False;
235*2dc7e66cSDamjan Jovanovic 
236*2dc7e66cSDamjan Jovanovic         ::rtl::OStringBuffer buffer;
237*2dc7e66cSDamjan Jovanovic         // PRI
238*2dc7e66cSDamjan Jovanovic         const sal_Int32 facility = 1; // USER
239*2dc7e66cSDamjan Jovanovic         sal_Int32 severity;
240*2dc7e66cSDamjan Jovanovic         switch ( _rRecord.Level )
241*2dc7e66cSDamjan Jovanovic         {
242*2dc7e66cSDamjan Jovanovic             case LogLevel::SEVERE:
243*2dc7e66cSDamjan Jovanovic                 severity = 3; // error
244*2dc7e66cSDamjan Jovanovic                 break;
245*2dc7e66cSDamjan Jovanovic             case LogLevel::WARNING:
246*2dc7e66cSDamjan Jovanovic                 severity = 4; // warning
247*2dc7e66cSDamjan Jovanovic                 break;
248*2dc7e66cSDamjan Jovanovic             case LogLevel::INFO:
249*2dc7e66cSDamjan Jovanovic             case LogLevel::CONFIG:
250*2dc7e66cSDamjan Jovanovic                 severity = 5; // notice
251*2dc7e66cSDamjan Jovanovic                 break;
252*2dc7e66cSDamjan Jovanovic             default:
253*2dc7e66cSDamjan Jovanovic                 severity = 7; // debug
254*2dc7e66cSDamjan Jovanovic         }
255*2dc7e66cSDamjan Jovanovic         buffer.append( '<' );
256*2dc7e66cSDamjan Jovanovic         buffer.append( ( facility * 8 ) + severity );
257*2dc7e66cSDamjan Jovanovic         buffer.append( '>' );
258*2dc7e66cSDamjan Jovanovic 
259*2dc7e66cSDamjan Jovanovic         // VERSION
260*2dc7e66cSDamjan Jovanovic         buffer.append( '1' );
261*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
262*2dc7e66cSDamjan Jovanovic 
263*2dc7e66cSDamjan Jovanovic         // TIMESTAMP
264*2dc7e66cSDamjan Jovanovic         char timestampBuffer[256];
265*2dc7e66cSDamjan Jovanovic         snprintf( timestampBuffer, sizeof( timestampBuffer ),
266*2dc7e66cSDamjan Jovanovic             "%04i-%02i-%02iT%02i:%02i:%02i.%02iZ",
267*2dc7e66cSDamjan Jovanovic             (int)_rRecord.LogTime.Year, (int)_rRecord.LogTime.Month, (int)_rRecord.LogTime.Day,
268*2dc7e66cSDamjan Jovanovic             (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds,
269*2dc7e66cSDamjan Jovanovic             (int)_rRecord.LogTime.HundredthSeconds );
270*2dc7e66cSDamjan Jovanovic         buffer.append( timestampBuffer );
271*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
272*2dc7e66cSDamjan Jovanovic 
273*2dc7e66cSDamjan Jovanovic         // HOSTNAME
274*2dc7e66cSDamjan Jovanovic         ::rtl::OUString hostname = ::osl::SocketAddr::getLocalHostname( 0 );
275*2dc7e66cSDamjan Jovanovic         if ( !hostname.isEmpty() )
276*2dc7e66cSDamjan Jovanovic             buffer.append( ::rtl::OUStringToOString( hostname, RTL_TEXTENCODING_UTF8 ) );
277*2dc7e66cSDamjan Jovanovic         else
278*2dc7e66cSDamjan Jovanovic             buffer.append( '-' );
279*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
280*2dc7e66cSDamjan Jovanovic 
281*2dc7e66cSDamjan Jovanovic         // APP-NAME
282*2dc7e66cSDamjan Jovanovic         buffer.append( "soffice" );
283*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
284*2dc7e66cSDamjan Jovanovic 
285*2dc7e66cSDamjan Jovanovic         // PROC-ID
286*2dc7e66cSDamjan Jovanovic         oslProcessInfo pInfo;
287*2dc7e66cSDamjan Jovanovic         pInfo.Size = sizeof(oslProcessInfo);
288*2dc7e66cSDamjan Jovanovic         oslProcessError prerr = osl_getProcessInfo( NULL, osl_Process_IDENTIFIER, &pInfo );
289*2dc7e66cSDamjan Jovanovic         if ( prerr == osl_Process_E_None )
290*2dc7e66cSDamjan Jovanovic             buffer.append( (sal_Int64) pInfo.Ident );
291*2dc7e66cSDamjan Jovanovic         else
292*2dc7e66cSDamjan Jovanovic             buffer.append( '-' );
293*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
294*2dc7e66cSDamjan Jovanovic 
295*2dc7e66cSDamjan Jovanovic         // MESSAGE-ID
296*2dc7e66cSDamjan Jovanovic         buffer.append( '-' );
297*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
298*2dc7e66cSDamjan Jovanovic 
299*2dc7e66cSDamjan Jovanovic         // STRUCTURED DATA
300*2dc7e66cSDamjan Jovanovic         buffer.append( '-' );
301*2dc7e66cSDamjan Jovanovic         buffer.append( ' ' );
302*2dc7e66cSDamjan Jovanovic 
303*2dc7e66cSDamjan Jovanovic         // MESSAGE
304*2dc7e66cSDamjan Jovanovic         buffer.append( sEntry );
305*2dc7e66cSDamjan Jovanovic 
306*2dc7e66cSDamjan Jovanovic         sal_Int32 sockRes = m_aSocket.sendTo( m_aSocketAddress, buffer.getStr(), buffer.getLength() );
307*2dc7e66cSDamjan Jovanovic 
308*2dc7e66cSDamjan Jovanovic         return sockRes == osl_Socket_MsgNormal;
309*2dc7e66cSDamjan Jovanovic     }
310*2dc7e66cSDamjan Jovanovic 
311*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
initialize(const Sequence<Any> & _rArguments)312*2dc7e66cSDamjan Jovanovic     void SAL_CALL SyslogHandler::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
313*2dc7e66cSDamjan Jovanovic     {
314*2dc7e66cSDamjan Jovanovic         ::osl::MutexGuard aGuard( m_aMutex );
315*2dc7e66cSDamjan Jovanovic 
316*2dc7e66cSDamjan Jovanovic         if ( m_aHandlerHelper.getIsInitialized() )
317*2dc7e66cSDamjan Jovanovic             throw AlreadyInitializedException();
318*2dc7e66cSDamjan Jovanovic 
319*2dc7e66cSDamjan Jovanovic         if ( _rArguments.getLength() != 1 )
320*2dc7e66cSDamjan Jovanovic             throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
321*2dc7e66cSDamjan Jovanovic 
322*2dc7e66cSDamjan Jovanovic         Sequence< NamedValue > aSettings;
323*2dc7e66cSDamjan Jovanovic         if ( !( _rArguments[0] >>= aSettings ) )
324*2dc7e66cSDamjan Jovanovic             throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
325*2dc7e66cSDamjan Jovanovic 
326*2dc7e66cSDamjan Jovanovic         // createWithSettings( [in] sequence< ::com::sun::star::beans::NamedValue > Settings )
327*2dc7e66cSDamjan Jovanovic         ::comphelper::NamedValueCollection aTypedSettings( aSettings );
328*2dc7e66cSDamjan Jovanovic         m_aHandlerHelper.initFromSettings( aTypedSettings );
329*2dc7e66cSDamjan Jovanovic 
330*2dc7e66cSDamjan Jovanovic         ::rtl::OUString host;
331*2dc7e66cSDamjan Jovanovic         if ( !aTypedSettings.get_ensureType( "Host", host ) )
332*2dc7e66cSDamjan Jovanovic             throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
333*2dc7e66cSDamjan Jovanovic         sal_Int32 port;
334*2dc7e66cSDamjan Jovanovic         if ( !aTypedSettings.get_ensureType( "Port", port ) )
335*2dc7e66cSDamjan Jovanovic             throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
336*2dc7e66cSDamjan Jovanovic         ::osl::SocketAddr address( host, port );
337*2dc7e66cSDamjan Jovanovic         if ( address.is() )
338*2dc7e66cSDamjan Jovanovic             m_aSocketAddress = address;
339*2dc7e66cSDamjan Jovanovic         else
340*2dc7e66cSDamjan Jovanovic             throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
341*2dc7e66cSDamjan Jovanovic 
342*2dc7e66cSDamjan Jovanovic         m_aHandlerHelper.setIsInitialized();
343*2dc7e66cSDamjan Jovanovic     }
344*2dc7e66cSDamjan Jovanovic 
345*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getImplementationName()346*2dc7e66cSDamjan Jovanovic     ::rtl::OUString SAL_CALL SyslogHandler::getImplementationName() throw(RuntimeException)
347*2dc7e66cSDamjan Jovanovic     {
348*2dc7e66cSDamjan Jovanovic         return getImplementationName_static();
349*2dc7e66cSDamjan Jovanovic     }
350*2dc7e66cSDamjan Jovanovic 
351*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)352*2dc7e66cSDamjan Jovanovic     ::sal_Bool SAL_CALL SyslogHandler::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
353*2dc7e66cSDamjan Jovanovic     {
354*2dc7e66cSDamjan Jovanovic         const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() );
355*2dc7e66cSDamjan Jovanovic         for (   const ::rtl::OUString* pServiceNames = aServiceNames.getConstArray();
356*2dc7e66cSDamjan Jovanovic                 pServiceNames != aServiceNames.getConstArray() + aServiceNames.getLength();
357*2dc7e66cSDamjan Jovanovic                 ++pServiceNames
358*2dc7e66cSDamjan Jovanovic             )
359*2dc7e66cSDamjan Jovanovic             if ( _rServiceName == *pServiceNames )
360*2dc7e66cSDamjan Jovanovic                 return sal_True;
361*2dc7e66cSDamjan Jovanovic         return sal_False;
362*2dc7e66cSDamjan Jovanovic     }
363*2dc7e66cSDamjan Jovanovic 
364*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getSupportedServiceNames()365*2dc7e66cSDamjan Jovanovic     Sequence< ::rtl::OUString > SAL_CALL SyslogHandler::getSupportedServiceNames() throw(RuntimeException)
366*2dc7e66cSDamjan Jovanovic     {
367*2dc7e66cSDamjan Jovanovic         return getSupportedServiceNames_static();
368*2dc7e66cSDamjan Jovanovic     }
369*2dc7e66cSDamjan Jovanovic 
370*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getImplementationName_static()371*2dc7e66cSDamjan Jovanovic     ::rtl::OUString SAL_CALL SyslogHandler::getImplementationName_static()
372*2dc7e66cSDamjan Jovanovic     {
373*2dc7e66cSDamjan Jovanovic         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.SyslogHandler" ) );
374*2dc7e66cSDamjan Jovanovic     }
375*2dc7e66cSDamjan Jovanovic 
376*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
getSupportedServiceNames_static()377*2dc7e66cSDamjan Jovanovic     Sequence< ::rtl::OUString > SAL_CALL SyslogHandler::getSupportedServiceNames_static()
378*2dc7e66cSDamjan Jovanovic     {
379*2dc7e66cSDamjan Jovanovic         Sequence< ::rtl::OUString > aServiceNames(1);
380*2dc7e66cSDamjan Jovanovic         aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.SyslogHandler" ) );
381*2dc7e66cSDamjan Jovanovic         return aServiceNames;
382*2dc7e66cSDamjan Jovanovic     }
383*2dc7e66cSDamjan Jovanovic 
384*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
Create(const Reference<XComponentContext> & _rxContext)385*2dc7e66cSDamjan Jovanovic     Reference< XInterface > SyslogHandler::Create( const Reference< XComponentContext >& _rxContext )
386*2dc7e66cSDamjan Jovanovic     {
387*2dc7e66cSDamjan Jovanovic         return *( new SyslogHandler( _rxContext ) );
388*2dc7e66cSDamjan Jovanovic     }
389*2dc7e66cSDamjan Jovanovic 
390*2dc7e66cSDamjan Jovanovic     //--------------------------------------------------------------------
createRegistryInfo_SyslogHandler()391*2dc7e66cSDamjan Jovanovic     void createRegistryInfo_SyslogHandler()
392*2dc7e66cSDamjan Jovanovic     {
393*2dc7e66cSDamjan Jovanovic         static OAutoRegistration< SyslogHandler > aAutoRegistration;
394*2dc7e66cSDamjan Jovanovic     }
395*2dc7e66cSDamjan Jovanovic 
396*2dc7e66cSDamjan Jovanovic //........................................................................
397*2dc7e66cSDamjan Jovanovic } // namespace logging
398*2dc7e66cSDamjan Jovanovic //........................................................................
399