1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2008 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * $RCSfile: errormail.cxx,v $
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"
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>
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::uno
;
50 using namespace oooimprovement
;
51 using ::rtl::OUString
;
53 using ::rtl::OStringBuffer
;
57 static OString
replaceAll(const OString
& str
, sal_Char old
, const OString
& replacement
)
62 result
.append(str
.getToken(0, old
, idx
));
63 if(idx
>=0) result
.append(replacement
);
65 return result
.makeStringAndClear();
68 static OString
xmlAttrEncode(const OString
& input
)
70 OString result
= replaceAll(input
, '&', OString("&"));
71 result
= replaceAll(result
, '<', OString("<"));
72 result
= replaceAll(result
, '"', OString("""));
73 return replaceAll(result
, '>', OString(">"));
76 static OString
getPlatform()
93 #if defined(UNIX) || defined(OS2)
94 static const OString
getLocale()
96 const char * locale
= getenv( "LC_ALL" );
98 locale
= getenv( "LC_CTYPE" );
101 locale
= getenv( "LANG" );
108 static OString
getSystemInfoXml(const Reference
<XMultiServiceFactory
>&)
111 //memset(&info, 0, sizeof(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();
126 static OString
getSystemInfoXml(const Reference
<XMultiServiceFactory
>&)
129 ZeroMemory(&info
, sizeof(OSVERSIONINFO
));
130 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
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"));
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();
151 static OString
getOfficeInfoXml(const Reference
<XMultiServiceFactory
>& 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
);
189 temp
.append(config
.getReportCount());
190 feedback
= temp
.makeStringAndClear();
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"
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();