xref: /AOO41X/main/xmlsecurity/tools/demo/mozprofile.cxx (revision 5be78d22e6c042fbf34ae49f26275dc40c5231d1)
1*06b3ce53SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*06b3ce53SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*06b3ce53SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*06b3ce53SAndrew Rist  * distributed with this work for additional information
6*06b3ce53SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*06b3ce53SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*06b3ce53SAndrew Rist  * "License"); you may not use this file except in compliance
9*06b3ce53SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*06b3ce53SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*06b3ce53SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*06b3ce53SAndrew Rist  * software distributed under the License is distributed on an
15*06b3ce53SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*06b3ce53SAndrew Rist  * KIND, either express or implied.  See the License for the
17*06b3ce53SAndrew Rist  * specific language governing permissions and limitations
18*06b3ce53SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*06b3ce53SAndrew Rist  *************************************************************/
21*06b3ce53SAndrew Rist 
22*06b3ce53SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "util.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir #include <tools/date.hxx>
31cdf0e10cSrcweir #include <tools/time.hxx>
32cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <xmlsecurity/biginteger.hxx>
35cdf0e10cSrcweir #include <xmlsecurity/xmlsignaturehelper.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir 
main(int argc,char ** argv)39cdf0e10cSrcweir int SAL_CALL main( int argc, char **argv )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	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" ) ;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
44cdf0e10cSrcweir 	if ( !xMSF.is() )
45cdf0e10cSrcweir 	{
46cdf0e10cSrcweir 	    fprintf( stdout, "\n\nERROR: Can't create Service Factory\n" );
47cdf0e10cSrcweir 	    exit (-1);
48cdf0e10cSrcweir 	}
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap( xMSF->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap" ) ) ), uno::UNO_QUERY );
51cdf0e10cSrcweir 	if ( !xMozillaBootstrap.is() )
52cdf0e10cSrcweir 	{
53cdf0e10cSrcweir 	    fprintf( stdout, "\n\nERROR: Can't create Mozilla Bootstrap Service\n" );
54cdf0e10cSrcweir 	    exit (-1);
55cdf0e10cSrcweir 	}
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	int nProducts = 4;
58cdf0e10cSrcweir 	mozilla::MozillaProductType productTypes[4] = { mozilla::MozillaProductType_Thunderbird, mozilla::MozillaProductType_Mozilla, mozilla::MozillaProductType_Firefox, mozilla::MozillaProductType_Default };
59cdf0e10cSrcweir 	for ( int i = 0; i < nProducts; i++)
60cdf0e10cSrcweir 	{
61cdf0e10cSrcweir 	    if ( i == 0 )
62cdf0e10cSrcweir 	        fprintf( stdout, "\nThunderbird: " );
63cdf0e10cSrcweir 	    else if ( i == 1 )
64cdf0e10cSrcweir 	        fprintf( stdout, "\nMozilla:     " );
65cdf0e10cSrcweir 	    else if ( i == 2 )
66cdf0e10cSrcweir 	        fprintf( stdout, "\nFireFox:     " );
67cdf0e10cSrcweir 	    else
68cdf0e10cSrcweir 	        fprintf( stdout, "\nDefault:     " );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 		::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]);
71cdf0e10cSrcweir 		if ( profile.getLength() )
72cdf0e10cSrcweir 		{
73cdf0e10cSrcweir 			::rtl::OUString profilepath = xMozillaBootstrap->getProfilePath(productTypes[i],profile);
74cdf0e10cSrcweir 	        fprintf( stdout, "Name=%s, Path=%s", rtl::OUStringToOString( profile , RTL_TEXTENCODING_ASCII_US ).getStr(), rtl::OUStringToOString( profilepath , RTL_TEXTENCODING_ASCII_US ).getStr() );
75cdf0e10cSrcweir 		}
76cdf0e10cSrcweir 		else
77cdf0e10cSrcweir 		{
78cdf0e10cSrcweir 		    fprintf( stdout, "NOT FOUND" );
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	/*
83cdf0e10cSrcweir 	 * creates a signature helper
84cdf0e10cSrcweir 	 */
85cdf0e10cSrcweir 	XMLSignatureHelper aSignatureHelper( xMSF );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	/*
88cdf0e10cSrcweir 	 * creates a security context.
89cdf0e10cSrcweir 	 */
90cdf0e10cSrcweir 	rtl::OUString aCryptoToken;
91cdf0e10cSrcweir 	bool bInit = aSignatureHelper.Init( aCryptoToken );
92cdf0e10cSrcweir 	if ( !bInit )
93cdf0e10cSrcweir 	{
94cdf0e10cSrcweir 		fprintf( stdout, "\n\nERROR: Unable to initialize security environment.\n\n" );
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 	else
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		fprintf( stdout, "\n\nSecurity environment can be initialized successfully.\n\n" );
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	return 0;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104