merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / oooimprovement / errormail.cxx
blob6d755d8135af261079c690be904d435a56cccd0b
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 #if defined(UNIX) || defined(OS2)
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 #elif defined OS2
87 return "OS/2";
88 #else
89 return "Unknown";
90 #endif
93 #if defined(UNIX) || defined(OS2)
94 static const OString getLocale()
96 const char * locale = getenv( "LC_ALL" );
97 if( NULL == locale )
98 locale = getenv( "LC_CTYPE" );
100 if( NULL == locale )
101 locale = getenv( "LANG" );
103 if( NULL == locale )
104 locale = "C";
105 return locale;
108 static OString getSystemInfoXml(const Reference<XMultiServiceFactory>&)
110 struct utsname info;
111 //memset(&info, 0, sizeof(info));
112 uname(&info);
113 OStringBuffer result =
114 "<systeminfo:systeminfo xmlns:systeminfo=\"http://openoffice.org/2002/systeminfo\">\n"
115 "<systeminfo:System name=\""
116 + xmlAttrEncode(OString(info.sysname)) + "\" version=\""
117 + xmlAttrEncode(OString(info.version)) + "\" build=\""
118 + xmlAttrEncode(OString(info.release)) + "\" locale=\""
119 + xmlAttrEncode(OString(getLocale())) + "\"/>\n"
120 "<systeminfo:CPU type=\""
121 + xmlAttrEncode(OString(info.machine)) + "\"/>\n"
122 "</systeminfo:systeminfo>\n";
123 return result.makeStringAndClear();
125 #else
126 static OString getSystemInfoXml(const Reference<XMultiServiceFactory>&)
128 OSVERSIONINFO info;
129 ZeroMemory(&info, sizeof(OSVERSIONINFO));
130 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
131 GetVersionEx(&info);
132 OStringBuffer result = OString(
133 "<systeminfo:systeminfo xmlns:systeminfo=\"http://openoffice.org/2002/systeminfo\">\n"
134 "<systeminfo:System name=\"");
135 if(VER_PLATFORM_WIN32_NT == info.dwPlatformId)
136 result.append(OString("Windows NT"));
137 else
138 result.append(OString("Windows"));
139 result.append("\" version=\"").append(static_cast<long>(info.dwMajorVersion));
140 result.append(".").append(static_cast<long>(info.dwMinorVersion));
141 result.append("\" build=\"").append(static_cast<long>(info.dwBuildNumber));
142 result.append("\" locale=\"").append(static_cast<long>(GetUserDefaultLangID()));
143 result.append("\"/>\n");
144 result.append("<systeminfo:CPU type=\""
145 /* x86 or AMD64 */ "\"/>\n"
146 "</systeminfo:systeminfo>\n");
147 return result.makeStringAndClear();
149 #endif
151 static OString getOfficeInfoXml(const Reference<XMultiServiceFactory>& sf)
153 Config config(sf);
154 const OString product = OUStringToOString(config.getCompleteProductname(), RTL_TEXTENCODING_ASCII_US);
155 const OString platform = getPlatform();
156 const OString language = OUStringToOString(config.getSetupLocale(), RTL_TEXTENCODING_ASCII_US);
157 // If the oooimprovement lib is packaged in an extension, this needs to
158 // be done in another way: The build version string needs to be made
159 // available in an UNO service (if no better place is found for this,
160 // com.sun.star.comp.extensions.oooimprovecore.Core in oooimprovecore
161 // is likely the best fit)
162 const OString build = OUStringToOString(::utl::Bootstrap::getBuildIdData(OUString()), RTL_TEXTENCODING_ASCII_US);
163 const OString exceptiontype = "";
164 OStringBuffer result =
165 "<officeinfo:officeinfo xmlns:officeinfo=\"http://openoffice.org/2002/officeinfo\" platform=\""
166 + xmlAttrEncode(platform) + "\" language=\""
167 + xmlAttrEncode(language) + "\" build=\""
168 + xmlAttrEncode(build) + "\" exceptiontype=\""
169 + xmlAttrEncode(exceptiontype) + "\" product=\""
170 + xmlAttrEncode(product) + " \" />\n";
171 return result.makeStringAndClear();
175 namespace oooimprovement
177 Errormail::Errormail(const Reference<XMultiServiceFactory>& sf)
178 : m_ServiceFactory(sf)
181 OString Errormail::getXml()
183 Config config(m_ServiceFactory);
184 const OString usertype;
185 const OString email = OUStringToOString(config.getReporterEmail(), RTL_TEXTENCODING_ASCII_US);
186 OString feedback;
188 OStringBuffer temp;
189 temp.append(config.getReportCount());
190 feedback = temp.makeStringAndClear();
192 const OString title;
193 OStringBuffer result =
194 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
195 "<!DOCTYPE errormail:errormail PUBLIC \"-//OpenOffice.org//DTD ErrorMail 1.0//EN\" \"errormail.dtd\">\n"
196 "<errormail:errormail xmlns:errormail=\"http://openoffice.org/2002/errormail\" usertype=\""
197 + xmlAttrEncode(usertype) + "\">\n"
198 "<reportmail:mail xmlns:reportmail=\"http://openoffice.org/2002/reportmail\" version=\"1.1\" feedback=\""
199 + xmlAttrEncode(feedback) + "\" email=\""
200 + xmlAttrEncode(email) + "\">\n"
201 "<reportmail:title>"
202 + xmlAttrEncode(title) + "</reportmail:title>\n"
203 "<reportmail:attachment name=\"data.zip\" media-type=\"application/zip\" class=\"OOoImprovementLog\"/>\n"
204 "</reportmail:mail>\n"
205 + getOfficeInfoXml(m_ServiceFactory)
206 + getSystemInfoXml(m_ServiceFactory) +
207 "</errormail:errormail>\n";
208 return result.makeStringAndClear();