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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26
27 #include "dp_misc.h"
28 #include "dp_platform.hxx"
29 #include "rtl/ustring.hxx"
30 #include "rtl/ustrbuf.hxx"
31 #include "rtl/instance.hxx"
32 #include "rtl/bootstrap.hxx"
33
34 #define PLATFORM_ALL "all"
35 #define PLATFORM_WIN_X86 "windows_x86"
36 #define PLATFORM_WIN_X86_64 "windows_x86_64"
37 #define PLATFORM_LINUX_X86 "linux_x86"
38 #define PLATFORM_LINUX_X86_64 "linux_x86_64"
39 #define PLATFORM_KFREEBSD_X86 "kfreebsd_x86"
40 #define PLATFORM_KFREEBSD_X86_64 "kfreebsd_x86_64"
41 #define PLATFORM_LINUX_SPARC "linux_sparc"
42 #define PLATFORM_LINUX_POWERPC "linux_powerpc"
43 #define PLATFORM_LINUX_POWERPC64 "linux_powerpc64"
44 #define PLATFORM_LINUX_ARM_EABI "linux_arm_eabi"
45 #define PLATFORM_LINUX_ARM_OABI "linux_arm_oabi"
46 #define PLATFORM_LINUX_MIPS_EL "linux_mips_el"
47 #define PLATFORM_LINUX_MIPS_EB "linux_mips_eb"
48 #define PLATFORM_LINUX_IA64 "linux_ia64"
49 #define PLATFORM_LINUX_M68K "linux_m68k"
50 #define PLATFORM_LINUX_S390 "linux_s390"
51 #define PLATFORM_LINUX_S390x "linux_s390x"
52 #define PLATFORM_LINUX_HPPA "linux_hppa"
53 #define PLATFORM_LINUX_ALPHA "linux_alpha"
54
55
56
57 #define PLATFORM_SOLARIS_SPARC "solaris_sparc"
58 #define PLATFORM_SOLARIS_SPARC64 "solaris_sparc64"
59 #define PLATFORM_SOLARIS_X86 "solaris_x86"
60 #define PLATFORM_FREEBSD_ARM "freebsd_arm"
61 #define PLATFORM_FREEBSD_POWERPC "freebsd_powerpc"
62 #define PLATFORM_FREEBSD_POWERPC64 "freebsd_powerpc64"
63 #define PLATFORM_FREEBSD_X86 "freebsd_x86"
64 #define PLATFORM_FREEBSD_X86_64 "freebsd_x86_64"
65 #define PLATFORM_MACOSX_X86 "macosx_x86"
66 #define PLATFORM_MACOSX_X86_64 "macosx_x86_64"
67 #define PLATFORM_MACOSX_PPC "macosx_powerpc"
68 #define PLATFORM_OS2_X86 "os2_x86"
69
70
71
72
73
74
75
76
77
78 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
79 using ::rtl::OUString;
80 namespace css = ::com::sun::star;
81
82 namespace dp_misc
83 {
84 namespace
85 {
86 struct StrOperatingSystem :
87 public rtl::StaticWithInit<const OUString, StrOperatingSystem> {
operator ()dp_misc::__anonc05f74a30111::StrOperatingSystem88 const OUString operator () () {
89 OUString os( RTL_CONSTASCII_USTRINGPARAM("$_OS") );
90 ::rtl::Bootstrap::expandMacros( os );
91 return os;
92 }
93 };
94
95 struct StrCPU :
96 public rtl::StaticWithInit<const OUString, StrCPU> {
operator ()dp_misc::__anonc05f74a30111::StrCPU97 const OUString operator () () {
98 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
99 ::rtl::Bootstrap::expandMacros( arch );
100 return arch;
101 }
102 };
103
104
105 struct StrPlatform : public rtl::StaticWithInit<
106 const OUString, StrPlatform> {
operator ()dp_misc::__anonc05f74a30111::StrPlatform107 const OUString operator () () {
108 ::rtl::OUStringBuffer buf;
109 buf.append( StrOperatingSystem::get() );
110 buf.append( static_cast<sal_Unicode>('_') );
111 OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
112 ::rtl::Bootstrap::expandMacros( arch );
113 buf.append( arch );
114 return buf.makeStringAndClear();
115 }
116 };
117
checkOSandCPU(OUString const & os,OUString const & cpu)118 bool checkOSandCPU(OUString const & os, OUString const & cpu)
119 {
120 return os.equals(StrOperatingSystem::get())
121 && cpu.equals(StrCPU::get());
122 }
123
isValidPlatform(OUString const & token)124 bool isValidPlatform(OUString const & token )
125 {
126 bool ret = false;
127 if (token.equals(OUSTR(PLATFORM_ALL)))
128 ret = true;
129 else if (token.equals(OUSTR(PLATFORM_WIN_X86)))
130 ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86"));
131 else if (token.equals(OUSTR(PLATFORM_WIN_X86_64)))
132 ret = checkOSandCPU(OUSTR("Windows"), OUSTR("X86_64"));
133 else if (token.equals(OUSTR(PLATFORM_LINUX_X86)))
134 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("x86"));
135 else if (token.equals(OUSTR(PLATFORM_LINUX_X86_64)))
136 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("X86_64"));
137 else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86)))
138 ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("x86"));
139 else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86_64)))
140 ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("X86_64"));
141 else if (token.equals(OUSTR(PLATFORM_LINUX_SPARC)))
142 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("SPARC"));
143 else if (token.equals(OUSTR(PLATFORM_FREEBSD_POWERPC)))
144 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("PowerPC"));
145 else if (token.equals(OUSTR(PLATFORM_FREEBSD_POWERPC64)))
146 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("PowerPC64"));
147 else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC)))
148 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC"));
149 else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC64)))
150 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC_64"));
151 else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_EABI)))
152 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_EABI"));
153 else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_OABI)))
154 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_OABI"));
155 else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EL)))
156 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EL"));
157 else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EB)))
158 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EB"));
159 else if (token.equals(OUSTR(PLATFORM_LINUX_IA64)))
160 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("IA64"));
161 else if (token.equals(OUSTR(PLATFORM_LINUX_M68K)))
162 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("M68K"));
163 else if (token.equals(OUSTR(PLATFORM_LINUX_S390)))
164 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390"));
165 else if (token.equals(OUSTR(PLATFORM_LINUX_S390x)))
166 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390x"));
167 else if (token.equals(OUSTR(PLATFORM_LINUX_HPPA)))
168 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("HPPA"));
169 else if (token.equals(OUSTR(PLATFORM_LINUX_ALPHA)))
170 ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ALPHA"));
171 else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC)))
172 ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC"));
173 else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC64)))
174 ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC64"));
175 else if (token.equals(OUSTR(PLATFORM_SOLARIS_X86)))
176 ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("x86"));
177 else if (token.equals(OUSTR(PLATFORM_FREEBSD_POWERPC)))
178 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("PowerPC"));
179 else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86)))
180 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("x86"));
181 else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86_64)))
182 ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("X86_64"));
183 else if (token.equals(OUSTR(PLATFORM_MACOSX_X86)))
184 ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86"));
185 else if (token.equals(OUSTR(PLATFORM_MACOSX_X86_64)))
186 ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86_64"));
187 else if (token.equals(OUSTR(PLATFORM_MACOSX_PPC)))
188 ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("PowerPC"));
189 else if (token.equals(OUSTR(PLATFORM_OS2_X86)))
190 ret = checkOSandCPU(OUSTR("OS2"), OUSTR("x86"));
191 else
192 {
193 OSL_ENSURE(0, "Extension Manager: The extension supports an unknown platform. "
194 "Check the platform element in the description.xml");
195 ret = false;
196 }
197 return ret;
198 }
199
200 } // anon namespace
201 //=============================================================================
202
getPlatformString()203 OUString const & getPlatformString()
204 {
205 return StrPlatform::get();
206 }
207
platform_fits(OUString const & platform_string)208 bool platform_fits( OUString const & platform_string )
209 {
210 sal_Int32 index = 0;
211 for (;;)
212 {
213 const OUString token(
214 platform_string.getToken( 0, ',', index ).trim() );
215 // check if this platform:
216 if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
217 (token.indexOf( '_' ) < 0 && /* check OS part only */
218 token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
219 {
220 return true;
221 }
222 if (index < 0)
223 break;
224 }
225 return false;
226 }
227
hasValidPlatform(css::uno::Sequence<OUString> const & platformStrings)228 bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
229 {
230 bool ret = false;
231 for (sal_Int32 i = 0; i < platformStrings.getLength(); i++)
232 {
233 if (isValidPlatform(platformStrings[i]))
234 {
235 ret = true;
236 break;
237 }
238 }
239 return ret;
240 }
241
242 }
243