/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_extensions.hxx" #include "errormail.hxx" #include "config.hxx" #include #include #include #include #if defined(UNIX) || defined(OS2) #include #endif #ifdef WIN32 #include #endif using namespace com::sun::star::lang; using namespace com::sun::star::uno; using namespace oooimprovement; using ::rtl::OUString; using ::rtl::OString; using ::rtl::OStringBuffer; namespace { static OString replaceAll(const OString& str, sal_Char old, const OString& replacement) { OStringBuffer result; sal_Int32 idx = 0; do { result.append(str.getToken(0, old, idx)); if(idx>=0) result.append(replacement); } while(idx >= 0); return result.makeStringAndClear(); }; static OString xmlAttrEncode(const OString& input) { OString result = replaceAll(input, '&', OString("&")); result = replaceAll(result, '<', OString("<")); result = replaceAll(result, '"', OString(""")); return replaceAll(result, '>', OString(">")); } static OString getPlatform() { #ifdef SOLARIS return "Solaris"; #elif defined LINUX return "Linux"; #elif defined WIN32 return "Win32"; #elif defined UNIX return "Unix"; #elif defined OS2 return "OS/2"; #else return "Unknown"; #endif }; #if defined(UNIX) || defined(OS2) static const OString getLocale() { const char * locale = getenv( "LC_ALL" ); if( NULL == locale ) locale = getenv( "LC_CTYPE" ); if( NULL == locale ) locale = getenv( "LANG" ); if( NULL == locale ) locale = "C"; return locale; }; static OString getSystemInfoXml(const Reference&) { struct utsname info; //memset(&info, 0, sizeof(info)); uname(&info); OStringBuffer result = "\n" "\n" "\n" "\n"; return result.makeStringAndClear(); }; #else static OString getSystemInfoXml(const Reference&) { OSVERSIONINFO info; ZeroMemory(&info, sizeof(OSVERSIONINFO)); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&info); OStringBuffer result = OString( "\n" "(info.dwMajorVersion)); result.append(".").append(static_cast(info.dwMinorVersion)); result.append("\" build=\"").append(static_cast(info.dwBuildNumber)); result.append("\" locale=\"").append(static_cast(GetUserDefaultLangID())); result.append("\"/>\n"); result.append("\n" "\n"); return result.makeStringAndClear(); }; #endif static OString getOfficeInfoXml(const Reference& sf) { Config config(sf); const OString product = OUStringToOString(config.getCompleteProductname(), RTL_TEXTENCODING_ASCII_US); const OString platform = getPlatform(); const OString language = OUStringToOString(config.getSetupLocale(), RTL_TEXTENCODING_ASCII_US); // If the oooimprovement lib is packaged in an extension, this needs to // be done in another way: The build version string needs to be made // available in an UNO service (if no better place is found for this, // com.sun.star.comp.extensions.oooimprovecore.Core in oooimprovecore // is likely the best fit) const OString build = OUStringToOString(::utl::Bootstrap::getBuildIdData(OUString()), RTL_TEXTENCODING_ASCII_US); const OString exceptiontype = ""; OStringBuffer result = "\n"; return result.makeStringAndClear(); }; } namespace oooimprovement { Errormail::Errormail(const Reference& sf) : m_ServiceFactory(sf) {} OString Errormail::getXml() { Config config(m_ServiceFactory); const OString usertype; const OString email = OUStringToOString(config.getReporterEmail(), RTL_TEXTENCODING_ASCII_US); OString feedback; { OStringBuffer temp; temp.append(config.getReportCount()); feedback = temp.makeStringAndClear(); } const OString title; OStringBuffer result = "\n" "\n" "\n" "\n" "" + xmlAttrEncode(title) + "\n" "\n" "\n" + getOfficeInfoXml(m_ServiceFactory) + getSystemInfoXml(m_ServiceFactory) + "\n"; return result.makeStringAndClear(); } }