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