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