Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "dp_misc.h"
22 : #include "dp_platform.hxx"
23 : #include "rtl/ustring.hxx"
24 : #include "rtl/ustrbuf.hxx"
25 : #include "rtl/instance.hxx"
26 : #include "rtl/bootstrap.hxx"
27 :
28 : #define PLATFORM_ALL "all"
29 : #define PLATFORM_WIN_X86 "windows_x86"
30 : #define PLATFORM_WIN_X86_64 "windows_x86_64"
31 : #define PLATFORM_LINUX_X86 "linux_x86"
32 : #define PLATFORM_LINUX_X86_64 "linux_x86_64"
33 : #define PLATFORM_KFREEBSD_X86 "kfreebsd_x86"
34 : #define PLATFORM_KFREEBSD_X86_64 "kfreebsd_x86_64"
35 : #define PLATFORM_LINUX_SPARC "linux_sparc"
36 : #define PLATFORM_LINUX_POWERPC "linux_powerpc"
37 : #define PLATFORM_LINUX_POWERPC64 "linux_powerpc64"
38 : #define PLATFORM_LINUX_ARM_EABI "linux_arm_eabi"
39 : #define PLATFORM_LINUX_ARM_OABI "linux_arm_oabi"
40 : #define PLATFORM_LINUX_MIPS_EL "linux_mips_el"
41 : #define PLATFORM_LINUX_MIPS_EB "linux_mips_eb"
42 : #define PLATFORM_LINUX_IA64 "linux_ia64"
43 : #define PLATFORM_LINUX_M68K "linux_m68k"
44 : #define PLATFORM_LINUX_S390 "linux_s390"
45 : #define PLATFORM_LINUX_S390x "linux_s390x"
46 : #define PLATFORM_LINUX_HPPA "linux_hppa"
47 : #define PLATFORM_LINUX_ALPHA "linux_alpha"
48 :
49 :
50 :
51 : #define PLATFORM_SOLARIS_SPARC "solaris_sparc"
52 : #define PLATFORM_SOLARIS_SPARC64 "solaris_sparc64"
53 : #define PLATFORM_SOLARIS_X86 "solaris_x86"
54 : #define PLATFORM_FREEBSD_X86 "freebsd_x86"
55 : #define PLATFORM_FREEBSD_X86_64 "freebsd_x86_64"
56 : #define PLATFORM_NETBSD_X86 "netbsd_x86"
57 : #define PLATFORM_NETBSD_X86_64 "netbsd_x86_64"
58 : #define PLATFORM_MACOSX_X86 "macosx_x86"
59 : #define PLATFORM_MACOSX_PPC "macosx_powerpc"
60 : #define PLATFORM_OPENBSD_X86 "openbsd_x86"
61 : #define PLATFORM_OPENBSD_X86_64 "openbsd_x86_64"
62 : #define PLATFORM_DRAGONFLY_X86 "dragonfly_x86"
63 : #define PLATFORM_DRAGONFLY_X86_64 "dragonfly_x86_64"
64 :
65 :
66 : #define PLATFORM_AIX_POWERPC "aix_powerpc"
67 :
68 :
69 :
70 :
71 :
72 :
73 :
74 : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
75 : using ::rtl::OUString;
76 :
77 : namespace dp_misc
78 : {
79 : namespace
80 : {
81 : struct StrOperatingSystem :
82 : public rtl::StaticWithInit<OUString, StrOperatingSystem> {
83 0 : const OUString operator () () {
84 0 : OUString os( RTL_CONSTASCII_USTRINGPARAM("$_OS") );
85 0 : ::rtl::Bootstrap::expandMacros( os );
86 0 : return os;
87 : }
88 : };
89 :
90 : struct StrCPU :
91 : public rtl::StaticWithInit<OUString, StrCPU> {
92 0 : const OUString operator () () {
93 0 : OUString arch( RTL_CONSTASCII_USTRINGPARAM("$_ARCH") );
94 0 : ::rtl::Bootstrap::expandMacros( arch );
95 0 : return arch;
96 : }
97 : };
98 :
99 :
100 : struct StrPlatform : public rtl::StaticWithInit<
101 : OUString, StrPlatform> {
102 0 : const OUString operator () () {
103 0 : ::rtl::OUStringBuffer buf;
104 0 : buf.append( StrOperatingSystem::get() );
105 0 : buf.append( static_cast<sal_Unicode>('_') );
106 0 : buf.append( StrCPU::get() );
107 0 : return buf.makeStringAndClear();
108 : }
109 : };
110 :
111 0 : bool checkOSandCPU(OUString const & os, OUString const & cpu)
112 : {
113 0 : return os.equals(StrOperatingSystem::get())
114 0 : && cpu.equals(StrCPU::get());
115 : }
116 :
117 0 : bool isValidPlatform(OUString const & token )
118 : {
119 0 : bool ret = false;
120 0 : if (token.equals(OUSTR(PLATFORM_ALL)))
121 0 : ret = true;
122 0 : else if (token.equals(OUSTR(PLATFORM_WIN_X86)))
123 0 : ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86"));
124 0 : else if (token.equals(OUSTR(PLATFORM_WIN_X86_64)))
125 0 : ret = checkOSandCPU(OUSTR("Windows"), OUSTR("x86_64"));
126 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_X86)))
127 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("x86"));
128 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_X86_64)))
129 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("X86_64"));
130 0 : else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86)))
131 0 : ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("x86"));
132 0 : else if (token.equals(OUSTR(PLATFORM_KFREEBSD_X86_64)))
133 0 : ret = checkOSandCPU(OUSTR("kFreeBSD"), OUSTR("X86_64"));
134 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_SPARC)))
135 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("SPARC"));
136 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC)))
137 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC"));
138 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_POWERPC64)))
139 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("PowerPC_64"));
140 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_EABI)))
141 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_EABI"));
142 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_ARM_OABI)))
143 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ARM_OABI"));
144 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EL)))
145 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EL"));
146 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_MIPS_EB)))
147 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("MIPS_EB"));
148 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_IA64)))
149 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("IA64"));
150 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_M68K)))
151 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("M68K"));
152 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_S390)))
153 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390"));
154 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_S390x)))
155 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("S390x"));
156 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_HPPA)))
157 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("HPPA"));
158 0 : else if (token.equals(OUSTR(PLATFORM_LINUX_ALPHA)))
159 0 : ret = checkOSandCPU(OUSTR("Linux"), OUSTR("ALPHA"));
160 0 : else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC)))
161 0 : ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC"));
162 0 : else if (token.equals(OUSTR(PLATFORM_SOLARIS_SPARC64)))
163 0 : ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("SPARC64"));
164 0 : else if (token.equals(OUSTR(PLATFORM_SOLARIS_X86)))
165 0 : ret = checkOSandCPU(OUSTR("Solaris"), OUSTR("x86"));
166 0 : else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86)))
167 0 : ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("x86"));
168 0 : else if (token.equals(OUSTR(PLATFORM_FREEBSD_X86_64)))
169 0 : ret = checkOSandCPU(OUSTR("FreeBSD"), OUSTR("X86_64"));
170 0 : else if (token.equals(OUSTR(PLATFORM_NETBSD_X86)))
171 0 : ret = checkOSandCPU(OUSTR("NetBSD"), OUSTR("x86"));
172 0 : else if (token.equals(OUSTR(PLATFORM_NETBSD_X86_64)))
173 0 : ret = checkOSandCPU(OUSTR("NetBSD"), OUSTR("X86_64"));
174 0 : else if (token.equals(OUSTR(PLATFORM_MACOSX_X86)))
175 0 : ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("x86"));
176 0 : else if (token.equals(OUSTR(PLATFORM_MACOSX_PPC)))
177 0 : ret = checkOSandCPU(OUSTR("MacOSX"), OUSTR("PowerPC"));
178 0 : else if (token.equals(OUSTR(PLATFORM_AIX_POWERPC)))
179 0 : ret = checkOSandCPU(OUSTR("AIX"), OUSTR("PowerPC"));
180 0 : else if (token.equals(OUSTR(PLATFORM_OPENBSD_X86)))
181 0 : ret = checkOSandCPU(OUSTR("OpenBSD"), OUSTR("x86"));
182 0 : else if (token.equals(OUSTR(PLATFORM_OPENBSD_X86_64)))
183 0 : ret = checkOSandCPU(OUSTR("OpenBSD"), OUSTR("X86_64"));
184 0 : else if (token.equals(OUSTR(PLATFORM_DRAGONFLY_X86)))
185 0 : ret = checkOSandCPU(OUSTR("DragonFly"), OUSTR("x86"));
186 0 : else if (token.equals(OUSTR(PLATFORM_DRAGONFLY_X86_64)))
187 0 : ret = checkOSandCPU(OUSTR("DragonFly"), OUSTR("X86_64"));
188 : else
189 : {
190 : OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
191 : "Check the platform element in the description.xml");
192 0 : ret = false;
193 : }
194 0 : return ret;
195 : }
196 :
197 : } // anon namespace
198 : //=============================================================================
199 :
200 0 : OUString const & getPlatformString()
201 : {
202 0 : return StrPlatform::get();
203 : }
204 :
205 0 : bool platform_fits( OUString const & platform_string )
206 : {
207 0 : sal_Int32 index = 0;
208 0 : for (;;)
209 : {
210 : const OUString token(
211 0 : platform_string.getToken( 0, ',', index ).trim() );
212 : // check if this platform:
213 0 : if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
214 0 : (token.indexOf( '_' ) < 0 && /* check OS part only */
215 0 : token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
216 : {
217 0 : return true;
218 : }
219 0 : if (index < 0)
220 : break;
221 0 : }
222 0 : return false;
223 : }
224 :
225 0 : bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
226 : {
227 0 : bool ret = false;
228 0 : for (sal_Int32 i = 0; i < platformStrings.getLength(); i++)
229 : {
230 0 : if (isValidPlatform(platformStrings[i]))
231 : {
232 0 : ret = true;
233 0 : break;
234 : }
235 : }
236 0 : return ret;
237 : }
238 :
239 : }
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|