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