1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * This file is part of OpenOffice.org. 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 12*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 19*cdf0e10cSrcweir * 20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 21*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 23*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 24*cdf0e10cSrcweir * 25*cdf0e10cSrcweir ************************************************************************/ 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_extensions.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "errormail.hxx" 31*cdf0e10cSrcweir #include "config.hxx" 32*cdf0e10cSrcweir #include <unotools/bootstrap.hxx> 33*cdf0e10cSrcweir #include <rtl/ustring.hxx> 34*cdf0e10cSrcweir #include <rtl/string.hxx> 35*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #if defined(UNIX) || defined(OS2) 38*cdf0e10cSrcweir #include <sys/utsname.h> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifdef WIN32 41*cdf0e10cSrcweir #include <windows.h> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace com::sun::star::lang; 46*cdf0e10cSrcweir using namespace com::sun::star::uno; 47*cdf0e10cSrcweir using namespace oooimprovement; 48*cdf0e10cSrcweir using ::rtl::OUString; 49*cdf0e10cSrcweir using ::rtl::OString; 50*cdf0e10cSrcweir using ::rtl::OStringBuffer; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir namespace { 54*cdf0e10cSrcweir static OString replaceAll(const OString& str, sal_Char old, const OString& replacement) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir OStringBuffer result; 57*cdf0e10cSrcweir sal_Int32 idx = 0; 58*cdf0e10cSrcweir do { 59*cdf0e10cSrcweir result.append(str.getToken(0, old, idx)); 60*cdf0e10cSrcweir if(idx>=0) result.append(replacement); 61*cdf0e10cSrcweir } while(idx >= 0); 62*cdf0e10cSrcweir return result.makeStringAndClear(); 63*cdf0e10cSrcweir }; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir static OString xmlAttrEncode(const OString& input) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir OString result = replaceAll(input, '&', OString("&")); 68*cdf0e10cSrcweir result = replaceAll(result, '<', OString("<")); 69*cdf0e10cSrcweir result = replaceAll(result, '"', OString(""")); 70*cdf0e10cSrcweir return replaceAll(result, '>', OString(">")); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir static OString getPlatform() 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir #ifdef SOLARIS 76*cdf0e10cSrcweir return "Solaris"; 77*cdf0e10cSrcweir #elif defined LINUX 78*cdf0e10cSrcweir return "Linux"; 79*cdf0e10cSrcweir #elif defined WIN32 80*cdf0e10cSrcweir return "Win32"; 81*cdf0e10cSrcweir #elif defined UNIX 82*cdf0e10cSrcweir return "Unix"; 83*cdf0e10cSrcweir #elif defined OS2 84*cdf0e10cSrcweir return "OS/2"; 85*cdf0e10cSrcweir #else 86*cdf0e10cSrcweir return "Unknown"; 87*cdf0e10cSrcweir #endif 88*cdf0e10cSrcweir }; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir #if defined(UNIX) || defined(OS2) 91*cdf0e10cSrcweir static const OString getLocale() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir const char * locale = getenv( "LC_ALL" ); 94*cdf0e10cSrcweir if( NULL == locale ) 95*cdf0e10cSrcweir locale = getenv( "LC_CTYPE" ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir if( NULL == locale ) 98*cdf0e10cSrcweir locale = getenv( "LANG" ); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir if( NULL == locale ) 101*cdf0e10cSrcweir locale = "C"; 102*cdf0e10cSrcweir return locale; 103*cdf0e10cSrcweir }; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir static OString getSystemInfoXml(const Reference<XMultiServiceFactory>&) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir struct utsname info; 108*cdf0e10cSrcweir //memset(&info, 0, sizeof(info)); 109*cdf0e10cSrcweir uname(&info); 110*cdf0e10cSrcweir OStringBuffer result = 111*cdf0e10cSrcweir "<systeminfo:systeminfo xmlns:systeminfo=\"http://openoffice.org/2002/systeminfo\">\n" 112*cdf0e10cSrcweir "<systeminfo:System name=\"" 113*cdf0e10cSrcweir + xmlAttrEncode(OString(info.sysname)) + "\" version=\"" 114*cdf0e10cSrcweir + xmlAttrEncode(OString(info.version)) + "\" build=\"" 115*cdf0e10cSrcweir + xmlAttrEncode(OString(info.release)) + "\" locale=\"" 116*cdf0e10cSrcweir + xmlAttrEncode(OString(getLocale())) + "\"/>\n" 117*cdf0e10cSrcweir "<systeminfo:CPU type=\"" 118*cdf0e10cSrcweir + xmlAttrEncode(OString(info.machine)) + "\"/>\n" 119*cdf0e10cSrcweir "</systeminfo:systeminfo>\n"; 120*cdf0e10cSrcweir return result.makeStringAndClear(); 121*cdf0e10cSrcweir }; 122*cdf0e10cSrcweir #else 123*cdf0e10cSrcweir static OString getSystemInfoXml(const Reference<XMultiServiceFactory>&) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir OSVERSIONINFO info; 126*cdf0e10cSrcweir ZeroMemory(&info, sizeof(OSVERSIONINFO)); 127*cdf0e10cSrcweir info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 128*cdf0e10cSrcweir GetVersionEx(&info); 129*cdf0e10cSrcweir OStringBuffer result = OString( 130*cdf0e10cSrcweir "<systeminfo:systeminfo xmlns:systeminfo=\"http://openoffice.org/2002/systeminfo\">\n" 131*cdf0e10cSrcweir "<systeminfo:System name=\""); 132*cdf0e10cSrcweir if(VER_PLATFORM_WIN32_NT == info.dwPlatformId) 133*cdf0e10cSrcweir result.append(OString("Windows NT")); 134*cdf0e10cSrcweir else 135*cdf0e10cSrcweir result.append(OString("Windows")); 136*cdf0e10cSrcweir result.append("\" version=\"").append(static_cast<long>(info.dwMajorVersion)); 137*cdf0e10cSrcweir result.append(".").append(static_cast<long>(info.dwMinorVersion)); 138*cdf0e10cSrcweir result.append("\" build=\"").append(static_cast<long>(info.dwBuildNumber)); 139*cdf0e10cSrcweir result.append("\" locale=\"").append(static_cast<long>(GetUserDefaultLangID())); 140*cdf0e10cSrcweir result.append("\"/>\n"); 141*cdf0e10cSrcweir result.append("<systeminfo:CPU type=\"" 142*cdf0e10cSrcweir /* x86 or AMD64 */ "\"/>\n" 143*cdf0e10cSrcweir "</systeminfo:systeminfo>\n"); 144*cdf0e10cSrcweir return result.makeStringAndClear(); 145*cdf0e10cSrcweir }; 146*cdf0e10cSrcweir #endif 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir static OString getOfficeInfoXml(const Reference<XMultiServiceFactory>& sf) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir Config config(sf); 151*cdf0e10cSrcweir const OString product = OUStringToOString(config.getCompleteProductname(), RTL_TEXTENCODING_ASCII_US); 152*cdf0e10cSrcweir const OString platform = getPlatform(); 153*cdf0e10cSrcweir const OString language = OUStringToOString(config.getSetupLocale(), RTL_TEXTENCODING_ASCII_US); 154*cdf0e10cSrcweir // If the oooimprovement lib is packaged in an extension, this needs to 155*cdf0e10cSrcweir // be done in another way: The build version string needs to be made 156*cdf0e10cSrcweir // available in an UNO service (if no better place is found for this, 157*cdf0e10cSrcweir // com.sun.star.comp.extensions.oooimprovecore.Core in oooimprovecore 158*cdf0e10cSrcweir // is likely the best fit) 159*cdf0e10cSrcweir const OString build = OUStringToOString(::utl::Bootstrap::getBuildIdData(OUString()), RTL_TEXTENCODING_ASCII_US); 160*cdf0e10cSrcweir const OString exceptiontype = ""; 161*cdf0e10cSrcweir OStringBuffer result = 162*cdf0e10cSrcweir "<officeinfo:officeinfo xmlns:officeinfo=\"http://openoffice.org/2002/officeinfo\" platform=\"" 163*cdf0e10cSrcweir + xmlAttrEncode(platform) + "\" language=\"" 164*cdf0e10cSrcweir + xmlAttrEncode(language) + "\" build=\"" 165*cdf0e10cSrcweir + xmlAttrEncode(build) + "\" exceptiontype=\"" 166*cdf0e10cSrcweir + xmlAttrEncode(exceptiontype) + "\" product=\"" 167*cdf0e10cSrcweir + xmlAttrEncode(product) + " \" />\n"; 168*cdf0e10cSrcweir return result.makeStringAndClear(); 169*cdf0e10cSrcweir }; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir namespace oooimprovement 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir Errormail::Errormail(const Reference<XMultiServiceFactory>& sf) 175*cdf0e10cSrcweir : m_ServiceFactory(sf) 176*cdf0e10cSrcweir {} 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir OString Errormail::getXml() 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir Config config(m_ServiceFactory); 181*cdf0e10cSrcweir const OString usertype; 182*cdf0e10cSrcweir const OString email = OUStringToOString(config.getReporterEmail(), RTL_TEXTENCODING_ASCII_US); 183*cdf0e10cSrcweir OString feedback; 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir OStringBuffer temp; 186*cdf0e10cSrcweir temp.append(config.getReportCount()); 187*cdf0e10cSrcweir feedback = temp.makeStringAndClear(); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir const OString title; 190*cdf0e10cSrcweir OStringBuffer result = 191*cdf0e10cSrcweir "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 192*cdf0e10cSrcweir "<!DOCTYPE errormail:errormail PUBLIC \"-//OpenOffice.org//DTD ErrorMail 1.0//EN\" \"errormail.dtd\">\n" 193*cdf0e10cSrcweir "<errormail:errormail xmlns:errormail=\"http://openoffice.org/2002/errormail\" usertype=\"" 194*cdf0e10cSrcweir + xmlAttrEncode(usertype) + "\">\n" 195*cdf0e10cSrcweir "<reportmail:mail xmlns:reportmail=\"http://openoffice.org/2002/reportmail\" version=\"1.1\" feedback=\"" 196*cdf0e10cSrcweir + xmlAttrEncode(feedback) + "\" email=\"" 197*cdf0e10cSrcweir + xmlAttrEncode(email) + "\">\n" 198*cdf0e10cSrcweir "<reportmail:title>" 199*cdf0e10cSrcweir + xmlAttrEncode(title) + "</reportmail:title>\n" 200*cdf0e10cSrcweir "<reportmail:attachment name=\"data.zip\" media-type=\"application/zip\" class=\"OOoImprovementLog\"/>\n" 201*cdf0e10cSrcweir "</reportmail:mail>\n" 202*cdf0e10cSrcweir + getOfficeInfoXml(m_ServiceFactory) 203*cdf0e10cSrcweir + getSystemInfoXml(m_ServiceFactory) + 204*cdf0e10cSrcweir "</errormail:errormail>\n"; 205*cdf0e10cSrcweir return result.makeStringAndClear(); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208