1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c82f2877SAndrew Rist  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c82f2877SAndrew Rist  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19*c82f2877SAndrew Rist  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "diagnose.hxx"
25cdf0e10cSrcweir #include <stdio.h>
26cdf0e10cSrcweir #include <stdarg.h>
27cdf0e10cSrcweir #include "rtl/instance.hxx"
28cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace xmlsecurity {
31cdf0e10cSrcweir 
32cdf0e10cSrcweir struct UseDiagnose : public rtl::StaticWithInit<
33cdf0e10cSrcweir     const bool, UseDiagnose>
34cdf0e10cSrcweir {
operator ()xmlsecurity::UseDiagnose35cdf0e10cSrcweir     bool operator () () const
36cdf0e10cSrcweir     {
37cdf0e10cSrcweir         ::rtl::OUString value;
38cdf0e10cSrcweir         sal_Bool res = rtl::Bootstrap::get(
39cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XMLSECURITY_TRACE")), value);
40cdf0e10cSrcweir         return res == sal_True ? true : false;
41cdf0e10cSrcweir     }
42cdf0e10cSrcweir };
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /* the function will print the string when
45cdf0e10cSrcweir    - build with debug
46cdf0e10cSrcweir    - the bootstrap variable XMLSECURITY_TRACE is set.
47cdf0e10cSrcweir  */
xmlsec_trace(const char * pszFormat,...)48cdf0e10cSrcweir void xmlsec_trace(const char* pszFormat, ...)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     bool bDebug = false;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
53cdf0e10cSrcweir     bDebug = true;
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir     if (bDebug || UseDiagnose::get())
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         va_list args;
58cdf0e10cSrcweir         fprintf(stderr, "[xmlsecurity] ");
59cdf0e10cSrcweir         va_start(args, pszFormat);
60cdf0e10cSrcweir         vfprintf(stderr, pszFormat, args);
61cdf0e10cSrcweir         va_end(args);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         fprintf(stderr,"\n");
64cdf0e10cSrcweir         fflush(stderr);
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir }
71