1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "dp_misc.h"
32*cdf0e10cSrcweir #include "dp_platform.hxx"
33*cdf0e10cSrcweir #include "rtl/ustring.hxx"
34*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
35*cdf0e10cSrcweir #include "rtl/instance.hxx"
36*cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #define PLATFORM_ALL                "all"
39*cdf0e10cSrcweir #define PLATFORM_WIN_X86            "windows_x86"
40*cdf0e10cSrcweir #define PLATFORM_LINUX_X86          "linux_x86"
41*cdf0e10cSrcweir #define PLATFORM_LINUX_X86_64       "linux_x86_64"
42*cdf0e10cSrcweir #define PLATFORM_KFREEBSD_X86       "kfreebsd_x86"
43*cdf0e10cSrcweir #define PLATFORM_KFREEBSD_X86_64    "kfreebsd_x86_64"
44*cdf0e10cSrcweir #define PLATFORM_LINUX_SPARC        "linux_sparc"
45*cdf0e10cSrcweir #define PLATFORM_LINUX_POWERPC      "linux_powerpc"
46*cdf0e10cSrcweir #define PLATFORM_LINUX_POWERPC64    "linux_powerpc64"
47*cdf0e10cSrcweir #define PLATFORM_LINUX_ARM_EABI     "linux_arm_eabi"
48*cdf0e10cSrcweir #define PLATFORM_LINUX_ARM_OABI     "linux_arm_oabi"
49*cdf0e10cSrcweir #define PLATFORM_LINUX_MIPS_EL      "linux_mips_el"
50*cdf0e10cSrcweir #define PLATFORM_LINUX_MIPS_EB      "linux_mips_eb"
51*cdf0e10cSrcweir #define PLATFORM_LINUX_IA64         "linux_ia64"
52*cdf0e10cSrcweir #define PLATFORM_LINUX_M68K         "linux_m68k"
53*cdf0e10cSrcweir #define PLATFORM_LINUX_S390         "linux_s390"
54*cdf0e10cSrcweir #define PLATFORM_LINUX_S390x        "linux_s390x"
55*cdf0e10cSrcweir #define PLATFORM_LINUX_HPPA         "linux_hppa"
56*cdf0e10cSrcweir #define PLATFORM_LINUX_ALPHA        "linux_alpha"
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #define PLATFORM_SOLARIS_SPARC      "solaris_sparc"
61*cdf0e10cSrcweir #define PLATFORM_SOLARIS_SPARC64    "solaris_sparc64"
62*cdf0e10cSrcweir #define PLATFORM_SOLARIS_X86        "solaris_x86"
63*cdf0e10cSrcweir #define PLATFORM_FREEBSD_X86        "freebsd_x86"
64*cdf0e10cSrcweir #define PLATFORM_FREEBSD_X86_64     "freebsd_x86_64"
65*cdf0e10cSrcweir #define PLATFORM_MACOSX_X86         "macosx_x86"
66*cdf0e10cSrcweir #define PLATFORM_MACOSX_PPC         "macosx_powerpc"
67*cdf0e10cSrcweir #define PLATFORM_OS2_X86            "os2_x86"
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
78*cdf0e10cSrcweir using ::rtl::OUString;
79*cdf0e10cSrcweir namespace css = ::com::sun::star;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir namespace dp_misc
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir namespace
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     struct StrOperatingSystem :
86*cdf0e10cSrcweir         public rtl::StaticWithInit<const OUString, StrOperatingSystem> {
87*cdf0e10cSrcweir             const OUString operator () () {
88*cdf0e10cSrcweir                 OUString os( RTL_CONSTASCII_USTRINGPARAM("$_OS") );
89*cdf0e10cSrcweir                 ::rtl::Bootstrap::expandMacros( os );
90*cdf0e10cSrcweir                 return os;
91*cdf0e10cSrcweir             }
92*cdf0e10cSrcweir     };
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     struct StrCPU :
95*cdf0e10cSrcweir         public rtl::StaticWithInit<const OUString, StrCPU> {
96*cdf0e10cSrcweir             const OUString operator () () {
97*cdf0e10cSrcweir                 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
98*cdf0e10cSrcweir                 ::rtl::Bootstrap::expandMacros( arch );
99*cdf0e10cSrcweir                 return arch;
100*cdf0e10cSrcweir             }
101*cdf0e10cSrcweir     };
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     struct StrPlatform : public rtl::StaticWithInit<
105*cdf0e10cSrcweir         const OUString, StrPlatform> {
106*cdf0e10cSrcweir             const OUString operator () () {
107*cdf0e10cSrcweir                 ::rtl::OUStringBuffer buf;
108*cdf0e10cSrcweir                 buf.append( StrOperatingSystem::get() );
109*cdf0e10cSrcweir                 buf.append( static_cast<sal_Unicode>('_') );
110*cdf0e10cSrcweir                 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
111*cdf0e10cSrcweir                 ::rtl::Bootstrap::expandMacros( arch );
112*cdf0e10cSrcweir                 buf.append( arch );
113*cdf0e10cSrcweir                 return buf.makeStringAndClear();
114*cdf0e10cSrcweir             }
115*cdf0e10cSrcweir     };
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     bool checkOSandCPU(OUString const & os, OUString const & cpu)
118*cdf0e10cSrcweir     {
119*cdf0e10cSrcweir         return os.equals(StrOperatingSystem::get())
120*cdf0e10cSrcweir             && cpu.equals(StrCPU::get());
121*cdf0e10cSrcweir     }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     bool isValidPlatform(OUString const &  token )
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir         bool ret = false;
126*cdf0e10cSrcweir         if (token.equals(OUSTR(PLATFORM_ALL)))
127*cdf0e10cSrcweir             ret = true;
128*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_WIN_X86)))
129*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86"));
130*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_X86)))
131*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("x86"));
132*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_X86_64)))
133*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("X86_64"));
134*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86)))
135*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("x86"));
136*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86_64)))
137*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("X86_64"));
138*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_SPARC)))
139*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("SPARC"));
140*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC)))
141*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC"));
142*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC64)))
143*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC_64"));
144*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_EABI)))
145*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_EABI"));
146*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_OABI)))
147*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_OABI"));
148*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EL)))
149*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EL"));
150*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EB)))
151*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EB"));
152*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_IA64)))
153*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("IA64"));
154*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_M68K)))
155*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("M68K"));
156*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_S390)))
157*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390"));
158*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_S390x)))
159*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390x"));
160*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_HPPA)))
161*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("HPPA"));
162*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_LINUX_ALPHA)))
163*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ALPHA"));
164*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC)))
165*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC"));
166*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC64)))
167*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC64"));
168*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_SOLARIS_X86)))
169*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("x86"));
170*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86)))
171*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("x86"));
172*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86_64)))
173*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("X86_64"));
174*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_MACOSX_X86)))
175*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86"));
176*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_MACOSX_PPC)))
177*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("PowerPC"));
178*cdf0e10cSrcweir         else if (token.equals(OUSTR(PLATFORM_OS2_X86)))
179*cdf0e10cSrcweir             ret = checkOSandCPU(OUSTR("OS2"), OUSTR("x86"));
180*cdf0e10cSrcweir         else
181*cdf0e10cSrcweir         {
182*cdf0e10cSrcweir             OSL_ENSURE(0, "Extension Manager: The extension supports an unknown platform. "
183*cdf0e10cSrcweir             "Check the platform element in the descripion.xml");
184*cdf0e10cSrcweir             ret = false;
185*cdf0e10cSrcweir         }
186*cdf0e10cSrcweir         return ret;
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir } // anon namespace
190*cdf0e10cSrcweir //=============================================================================
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir OUString const & getPlatformString()
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     return StrPlatform::get();
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir bool platform_fits( OUString const & platform_string )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     sal_Int32 index = 0;
200*cdf0e10cSrcweir     for (;;)
201*cdf0e10cSrcweir     {
202*cdf0e10cSrcweir         const OUString token(
203*cdf0e10cSrcweir             platform_string.getToken( 0, ',', index ).trim() );
204*cdf0e10cSrcweir         // check if this platform:
205*cdf0e10cSrcweir         if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
206*cdf0e10cSrcweir             (token.indexOf( '_' ) < 0 && /* check OS part only */
207*cdf0e10cSrcweir              token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
208*cdf0e10cSrcweir         {
209*cdf0e10cSrcweir             return true;
210*cdf0e10cSrcweir         }
211*cdf0e10cSrcweir         if (index < 0)
212*cdf0e10cSrcweir             break;
213*cdf0e10cSrcweir     }
214*cdf0e10cSrcweir     return false;
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     bool ret = false;
220*cdf0e10cSrcweir     for (sal_Int32 i  = 0; i < platformStrings.getLength(); i++)
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         if (isValidPlatform(platformStrings[i]))
223*cdf0e10cSrcweir         {
224*cdf0e10cSrcweir             ret = true;
225*cdf0e10cSrcweir             break;
226*cdf0e10cSrcweir         }
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir     return ret;
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233