xref: /trunk/main/xmlsecurity/tools/demo/mozprofile.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
30 
31 #include "util.hxx"
32 
33 #include <stdio.h>
34 #include <tools/date.hxx>
35 #include <tools/time.hxx>
36 #include <cppuhelper/servicefactory.hxx>
37 
38 #include <xmlsecurity/biginteger.hxx>
39 #include <xmlsecurity/xmlsignaturehelper.hxx>
40 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
41 
42 using namespace ::com::sun::star;
43 
44 int SAL_CALL main( int argc, char **argv )
45 {
46     fprintf( stdout, "\nTesting Mozilla Profile Detection...\n\nOpenOffice.org will use the first detected profile.\nResults might be different when started in OOo program folder!\n" ) ;
47 
48     uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
49     if ( !xMSF.is() )
50     {
51         fprintf( stdout, "\n\nERROR: Can't create Service Factory\n" );
52         exit (-1);
53     }
54 
55     uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap( xMSF->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap" ) ) ), uno::UNO_QUERY );
56     if ( !xMozillaBootstrap.is() )
57     {
58         fprintf( stdout, "\n\nERROR: Can't create Mozilla Bootstrap Service\n" );
59         exit (-1);
60     }
61 
62     int nProducts = 4;
63     mozilla::MozillaProductType productTypes[4] = { mozilla::MozillaProductType_Thunderbird, mozilla::MozillaProductType_Mozilla, mozilla::MozillaProductType_Firefox, mozilla::MozillaProductType_Default };
64     for ( int i = 0; i < nProducts; i++)
65     {
66         if ( i == 0 )
67             fprintf( stdout, "\nThunderbird: " );
68         else if ( i == 1 )
69             fprintf( stdout, "\nMozilla:     " );
70         else if ( i == 2 )
71             fprintf( stdout, "\nFireFox:     " );
72         else
73             fprintf( stdout, "\nDefault:     " );
74 
75         ::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]);
76         if ( profile.getLength() )
77         {
78             ::rtl::OUString profilepath = xMozillaBootstrap->getProfilePath(productTypes[i],profile);
79             fprintf( stdout, "Name=%s, Path=%s", rtl::OUStringToOString( profile , RTL_TEXTENCODING_ASCII_US ).getStr(), rtl::OUStringToOString( profilepath , RTL_TEXTENCODING_ASCII_US ).getStr() );
80         }
81         else
82         {
83             fprintf( stdout, "NOT FOUND" );
84         }
85     }
86 
87     /*
88      * creates a signature helper
89      */
90     XMLSignatureHelper aSignatureHelper( xMSF );
91 
92     /*
93      * creates a security context.
94      */
95     rtl::OUString aCryptoToken;
96     bool bInit = aSignatureHelper.Init( aCryptoToken );
97     if ( !bInit )
98     {
99         fprintf( stdout, "\n\nERROR: Unable to initialize security environment.\n\n" );
100     }
101     else
102     {
103         fprintf( stdout, "\n\nSecurity environment can be initialized successfully.\n\n" );
104     }
105 
106     return 0;
107 }
108 
109