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>
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()
92 static const OString
getLocale()
94 const char * locale
= getenv( "LC_ALL" );
96 locale
= getenv( "LC_CTYPE" );
99 locale
= getenv( "LANG" );
106 static OString
getSystemInfoXml(const Reference
<XMultiServiceFactory
>&)
109 //memset(&info, 0, sizeof(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();
124 static OString
getSystemInfoXml(const Reference
<XMultiServiceFactory
>&)
127 ZeroMemory(&info
, sizeof(OSVERSIONINFO
));
128 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
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"));
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();
149 static OString
getOfficeInfoXml(const Reference
<XMultiServiceFactory
>& 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
);
187 temp
.append(config
.getReportCount());
188 feedback
= temp
.makeStringAndClear();
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"
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();