summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-27 11:50:01 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-27 11:50:01 +0100
commitde73835bdadaf13a7cc5a2f1b08428da3a8e78b6 (patch)
tree1adfe2d5c878646f85244b38b83d2eadfa664f31 /lib
parentb9305465f239d3cd338d0c913b95bdc264f76ea9 (diff)
downloadabrt-de73835bdadaf13a7cc5a2f1b08428da3a8e78b6.tar.gz
abrt-de73835bdadaf13a7cc5a2f1b08428da3a8e78b6.tar.xz
abrt-de73835bdadaf13a7cc5a2f1b08428da3a8e78b6.zip
simplify base64 conversion
text data bss dec hexfilename 39575 2016 288 41879 old/libBugzilla.so 38598 1840 288 40726 new/libBugzilla.so Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Plugins/Bugzilla.cpp32
-rw-r--r--lib/Plugins/Makefile.am4
-rw-r--r--lib/Utils/Makefile.am9
-rw-r--r--lib/Utils/encbase64.cpp78
4 files changed, 90 insertions, 33 deletions
diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp
index 4ed5946f..2da39087 100644
--- a/lib/Plugins/Bugzilla.cpp
+++ b/lib/Plugins/Bugzilla.cpp
@@ -1,4 +1,3 @@
-#include <nssb64.h>
#include <xmlrpc-c/base.h>
#include <xmlrpc-c/client.h>
@@ -97,21 +96,6 @@ CReporterBugzilla::CReporterBugzilla() :
CReporterBugzilla::~CReporterBugzilla()
{}
-static PRInt32 base64_encode_cb(void *arg, const char* obuf, PRInt32 size)
-{
- std::string& attachment_b64 = *static_cast<std::string*>(arg);
- int ii;
- for (ii = 0; ii < size; ii++)
- {
- if (isprint(obuf[ii]))
- {
- attachment_b64 += obuf[ii];
- }
- }
- return 1;
-}
-
-
static void login(const char* login, const char* passwd)
{
xmlrpc_value* result = NULL;
@@ -409,25 +393,17 @@ static void add_attachments(const std::string& pBugId, const map_crash_report_t&
{
if (it->second[CD_TYPE] == CD_ATT)
{
- std::string attachment_b64;
- NSSBase64Encoder* base64 = NSSBase64Encoder_Create(&base64_encode_cb, &attachment_b64);
- if (!base64)
- {
- error_msg_and_die("cannot initialize base64"); // never happens
- }
- NSSBase64Encoder_Update(base64,
- reinterpret_cast<const unsigned char*>(it->second[CD_CONTENT].c_str()),
- it->second[CD_CONTENT].length());
- NSSBase64Encoder_Destroy(base64, PR_FALSE);
-
std::string description = "File: " + it->first;
+ const std::string& to_encode = it->second[CD_CONTENT];
+ char *encoded64 = encode_base64(to_encode.c_str(), to_encode.length());
xmlrpc_value* param = xmlrpc_build_value(&env,"(s{s:s,s:s,s:s,s:s})",
pBugId.c_str(),
"description", description.c_str(),
"filename", it->first.c_str(),
"contenttype", "text/plain",
- "data", attachment_b64.c_str()
+ "data", encoded64
);
+ free(encoded64);
throw_if_fault_occurred(&env);
xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result);
diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am
index a5c5a461..cf46aeea 100644
--- a/lib/Plugins/Makefile.am
+++ b/lib/Plugins/Makefile.am
@@ -80,9 +80,9 @@ libSOSreport_la_LDFLAGS = -avoid-version
# Bugzilla
libBugzilla_la_SOURCES = Bugzilla.h Bugzilla.cpp
-libBugzilla_la_LIBADD = $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) $(NSS_LIBS)
+libBugzilla_la_LIBADD = $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS)
libBugzilla_la_LDFLAGS = -avoid-version
-libBugzilla_la_CPPFLAGS = $(XMLRPC_CFLAGS) $(XMLRPC_CLIENT_CFLAGS) $(NSS_CFLAGS) -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\"
+libBugzilla_la_CPPFLAGS = $(XMLRPC_CFLAGS) $(XMLRPC_CLIENT_CFLAGS) -I$(srcdir)/../../inc -I$(srcdir)/../Utils -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\"
# TicketUploader
libTicketUploader_la_SOURCES = TicketUploader.h TicketUploader.cpp
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index d24afa72..3c510851 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -1,10 +1,13 @@
lib_LTLIBRARIES = libABRTUtils.la
+# Not used just yet:
+# time.cpp
+# xconnect.cpp
+# skip_whitespace.cpp
+
libABRTUtils_la_SOURCES = \
- time.cpp \
xfuncs.cpp \
- xconnect.cpp \
- skip_whitespace.cpp \
+ encbase64.cpp \
read_write.cpp \
logging.cpp \
copyfd.cpp \
diff --git a/lib/Utils/encbase64.cpp b/lib/Utils/encbase64.cpp
new file mode 100644
index 00000000..6a6f1f75
--- /dev/null
+++ b/lib/Utils/encbase64.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 Rob Landley <rob@landley.net>
+ *
+ * Licensed under GPLv2 or later.
+ */
+#include "abrtlib.h" /* xmalloc */
+
+/* Conversion table for base 64 */
+static const char tbl_base64[65 /*+ 2*/] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/',
+ '=' /* termination character */,
+ // '\n', '\0' /* needed for uudecode.c */
+};
+
+/* Conversion table for uuencode
+const char tbl_uuencode[65] ALIGN1 = {
+ '`', '!', '"', '#', '$', '%', '&', '\'',
+ '(', ')', '*', '+', ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', ':', ';', '<', '=', '>', '?',
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
+ '`'
+};
+*/
+
+/*
+ * Encode bytes at S of length LENGTH.
+ * Result will be 0-terminated, and must point to a writable
+ * buffer of at least 1+BASE64_LENGTH(length) bytes,
+ * where BASE64_LENGTH(len) = 4 * ((LENGTH + 2) / 3)
+ */
+static void encode_64bit(char *p, const void *src, int length, const char *tbl)
+{
+ const unsigned char *s = (const unsigned char *)src;
+
+ /* Transform the 3x8 bits to 4x6 bits */
+ while (length > 0) {
+ unsigned s1, s2;
+
+ /* Are s[1], s[2] valid or should be assumed 0? */
+ s1 = s2 = 0;
+ length -= 3; /* can be >=0, -1, -2 */
+ if (length >= -1) {
+ s1 = s[1];
+ if (length >= 0)
+ s2 = s[2];
+ }
+ *p++ = tbl[s[0] >> 2];
+ *p++ = tbl[((s[0] & 3) << 4) + (s1 >> 4)];
+ *p++ = tbl[((s1 & 0xf) << 2) + (s2 >> 6)];
+ *p++ = tbl[s2 & 0x3f];
+ s += 3;
+ }
+ /* Zero-terminate */
+ *p = '\0';
+ /* If length is -2 or -1, pad last char or two */
+ while (length) {
+ *--p = tbl[64];
+ length++;
+ }
+}
+
+char *encode_base64(const void *src, int length)
+{
+ char *dst = (char *)xmalloc(4 * ((length + 2) / 3) + 1);
+ encode_64bit(dst, src, length, tbl_base64);
+ return dst;
+}