libreport can now be built against satyr instead of btparser using
--with-satyr parameter to the configure script. RPMs are built against
btparser.
Signed-off-by: Martin Milata <mmilata(a)redhat.com>
---
configure.ac | 18 ++++++++-
libreport-web.pc.in | 2 +-
libreport.spec.in | 2 +
src/lib/Makefile.am | 4 +-
src/lib/json.c | 85 ++++++++++++++++++++++++++++++-----------
src/lib/ureport.h | 6 ++-
src/plugins/reporter-bugzilla.c | 56 ++++++++++++++++++++-------
src/plugins/ureport.c | 28 ++++++++------
8 files changed, 147 insertions(+), 54 deletions(-)
diff --git a/configure.ac b/configure.ac
index 01cf6f6..67310d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,16 +122,32 @@ PYTHON_LIBS=`python-config --libs 2> /dev/null`
AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_LIBS)
+AC_ARG_WITH([satyr],
+ AS_HELP_STRING([--with-satyr],
+ [use satyr instead of btparser (default is no)]),
+ [], [with_satyr=no])
+
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.21])
PKG_CHECK_MODULES([DBUS], [dbus-1])
PKG_CHECK_MODULES([LIBXML], [libxml-2.0])
PKG_CHECK_MODULES([NSS], [nss])
PKG_CHECK_MODULES([CURL], [libcurl])
-PKG_CHECK_MODULES([BTPARSER], [btparser])
PKG_CHECK_MODULES([PROXY], [libproxy-1.0], [
AC_DEFINE([HAVE_PROXY], [1], [Use libproxy])
], [:])
+[if test "$with_satyr" = "yes"]
+[then]
+ PKG_CHECK_MODULES([SATYR], [satyr])
+ AC_DEFINE([USE_SATYR], [1], [Use satyr instead of btparser])
+ SATYR_PKG="satyr"
+[else]
+ PKG_CHECK_MODULES([SATYR], [btparser])
+ SATYR_PKG="btparser"
+[fi]
+AC_SUBST(SATYR_PKG)
+AM_CONDITIONAL([USE_SATYR], [test "$with_satyr" = "yes"])
+
AC_ARG_WITH(newt,
AS_HELP_STRING([--with-newt],[use newt (default is YES)]),
LIBREPORT_PARSE_WITH([newt]))
diff --git a/libreport-web.pc.in b/libreport-web.pc.in
index c9af1d2..ec4ab8e 100644
--- a/libreport-web.pc.in
+++ b/libreport-web.pc.in
@@ -6,7 +6,7 @@ includedir=@includedir@
Name: libreport
Description: Library providing network API for libreport
Version: @VERSION@
-Requires: glib-2.0 libcurl libproxy-1.0 libxml-2.0 xmlrpc xmlrpc_client json btparser
libreport
+Requires: glib-2.0 libcurl libproxy-1.0 libxml-2.0 xmlrpc xmlrpc_client json @SATYR_PKG@
libreport
Libs: -L${libdir} -lreport-web
Cflags:
diff --git a/libreport.spec.in b/libreport.spec.in
index e2f4c50..22f74ea 100644
--- a/libreport.spec.in
+++ b/libreport.spec.in
@@ -27,6 +27,8 @@ BuildRequires: asciidoc
BuildRequires: xmlto
BuildRequires: newt-devel
BuildRequires: libproxy-devel
+##satyr migration:
+#BuildRequires: satyr-devel
BuildRequires: btparser-devel
BuildRequires: doxygen
Requires: libreport-filesystem
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 91d128f..5c0fd09 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -122,7 +122,7 @@ libreport_web_la_CPPFLAGS = \
$(LIBXML_CFLAGS) \
$(XMLRPC_CFLAGS) $(XMLRPC_CLIENT_CFLAGS) \
$(JSON_C_CFLAGS) \
- $(BTPARSER_CFLAGS) \
+ $(SATYR_CFLAGS) \
-D_GNU_SOURCE
libreport_web_la_LDFLAGS = \
-version-info 0:1:0
@@ -132,7 +132,7 @@ libreport_web_la_LIBADD = \
$(PROXY_LIBS) \
$(LIBXML_LIBS) \
$(JSON_C_LIBS) \
- $(BTPARSER_LIBS) \
+ $(SATYR_LIBS) \
$(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) \
libreport.la
diff --git a/src/lib/json.c b/src/lib/json.c
index 9cd5a2a..1e6d1b1 100644
--- a/src/lib/json.c
+++ b/src/lib/json.c
@@ -18,14 +18,47 @@
*/
#include <json/json.h>
-#include <btparser/thread.h>
-#include <btparser/core-backtrace.h>
#include "internal_libreport.h"
#include "ureport.h"
#include "libreport_curl.h"
+static void ureport_add_str(struct json_object *ur, const char *key,
+ const char *s)
+{
+ struct json_object *jstring = json_object_new_string(s);
+ if (!jstring)
+ die_out_of_memory();
+
+ json_object_object_add(ur, key, jstring);
+}
+
+#if USE_SATYR
+
+#include <satyr/abrt.h>
+#include <satyr/report.h>
+
+char *ureport_from_dump_dir(const char *dump_dir_path)
+{
+ char *error_message;
+ struct sr_report *report = sr_abrt_report_from_dir(dump_dir_path,
+ &error_message);
+
+ if (!report)
+ error_msg_and_die("%s", error_message);
+
+ char *json_ureport = sr_report_to_json(report);
+ sr_report_free(report);
+
+ return json_ureport;
+}
+
+#else /* USE_SATYR */
+
+#include <btparser/thread.h>
+#include <btparser/core-backtrace.h>
+
/* on success 1 returned, on error zero is returned and appropriate value
* is returned as third argument. You should never read third argument when
* function fails
@@ -64,16 +97,6 @@ static void ureport_add_int(struct json_object *ur, const char *key,
int i)
json_object_object_add(ur, key, jint);
}
-static void ureport_add_str(struct json_object *ur, const char *key,
- const char *s)
-{
- struct json_object *jstring = json_object_new_string(s);
- if (!jstring)
- die_out_of_memory();
-
- json_object_object_add(ur, key, jstring);
-}
-
static void ureport_add_os(struct json_object *ur, problem_data_t *pd)
{
/* paranoia - we only need OS_RELEASE_IN_ROOTDIR,
@@ -178,7 +201,6 @@ static void ureport_add_core_backtrace(struct json_object *ur,
problem_data_t *p
json_object_object_add(ur, FILENAME_CORE_BACKTRACE, jarray);
}
-
static void ureport_add_item_str(struct json_object *ur, problem_data_t *pd,
const char *key, const char *rename)
{
@@ -287,6 +309,32 @@ char *new_json_ureport(problem_data_t *pd)
return j;
}
+char *ureport_from_dump_dir(const char *dump_dir_path)
+{
+ struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+ if (!dd)
+ xfunc_die();
+
+ problem_data_t *pd = create_problem_data_from_dump_dir(dd);
+
+ dd_close(dd);
+ if (!pd)
+ xfunc_die(); /* create_problem_data_from_dump_dir already emitted error msg */
+
+ char *json_ureport = new_json_ureport(pd);
+ problem_data_free(pd);
+
+ if (json_ureport == NULL)
+ {
+ error_msg(_("Not uploading an empty uReport"));
+ return NULL;
+ }
+
+ return json_ureport;
+}
+
+#endif /* USE_SATYR */
+
char *new_json_attachment(const char *bthash, const char *type, const char *data)
{
struct json_object *attachment = json_object_new_object();
@@ -303,20 +351,13 @@ char *new_json_attachment(const char *bthash, const char *type,
const char *data
return result;
}
-struct post_state *post_ureport(problem_data_t *pd, struct ureport_server_config
*config)
+struct post_state *post_ureport(const char *json_ureport, struct ureport_server_config
*config)
{
int flags = POST_WANT_BODY | POST_WANT_ERROR_MSG;
if (config->ur_ssl_verify)
flags |= POST_WANT_SSL_VERIFY;
- char *json_ureport = new_json_ureport(pd);
- if (json_ureport == NULL)
- {
- error_msg(_("Not uploading an empty uReport"));
- return NULL;
- }
-
struct post_state *post_state = new_post_state(flags);
static const char *headers[] = {
@@ -328,8 +369,6 @@ struct post_state *post_ureport(problem_data_t *pd, struct
ureport_server_config
post_string_as_form_data(post_state, config->ur_url,
"application/json",
headers, json_ureport);
- free(json_ureport);
-
return post_state;
}
diff --git a/src/lib/ureport.h b/src/lib/ureport.h
index f851806..0d7b90d 100644
--- a/src/lib/ureport.h
+++ b/src/lib/ureport.h
@@ -37,12 +37,16 @@ struct ureport_server_config
struct abrt_post_state;
#define post_ureport libreport_post_ureport
-struct post_state *post_ureport(problem_data_t *pd, struct ureport_server_config
*config);
+struct post_state *post_ureport(const char *json_ureport,
+ struct ureport_server_config *config);
#define ureport_attach_rhbz libreport_ureport_attach_rhbz
struct post_state *ureport_attach_rhbz(const char *bthash, int rhbz_bug_id,
struct ureport_server_config *config);
+#define ureport_from_dump_dir libreport_ureport_from_dump_dir
+char *ureport_from_dump_dir(const char *dump_dir_path);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
index 4533df5..0d6c9a9 100644
--- a/src/plugins/reporter-bugzilla.c
+++ b/src/plugins/reporter-bugzilla.c
@@ -16,16 +16,44 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "internal_libreport.h"
+#include "client.h"
+#include "abrt_xmlrpc.h"
+#include "rhbz.h"
+
+/* btparser compatibility - once we move to satyr, the else branch of the ifdef
+ * can be removed
+ */
+#ifdef USE_SATYR
+
+#include <satyr/location.h>
+#include <satyr/gdb_stacktrace.h>
+#include <satyr/gdb_thread.h>
+#include <satyr/gdb_frame.h>
+#include <satyr/strbuf.h>
+
+#else /* USE_SATYR */
+
#include <btparser/location.h>
#include <btparser/backtrace.h>
#include <btparser/thread.h>
#include <btparser/frame.h>
#include <btparser/strbuf.h>
-#include "internal_libreport.h"
-#include "client.h"
-#include "abrt_xmlrpc.h"
-#include "rhbz.h"
+#define sr_location btp_location
+#define sr_location_init btp_location_init
+#define sr_gdb_stacktrace btp_backtrace
+#define sr_gdb_stacktrace_parse btp_backtrace_parse
+#define sr_gdb_stacktrace_get_optimized_thread btp_backtrace_get_optimized_thread
+#define sr_gdb_stacktrace_free btp_backtrace_free
+#define sr_gdb_thread btp_thread
+#define sr_gdb_thread_append_to_str btp_thread_append_to_str
+#define sr_gdb_thread_free btp_thread_free
+#define sr_strbuf btp_strbuf
+#define sr_strbuf_new btp_strbuf_new
+#define sr_strbuf_free_nobuf btp_strbuf_free_nobuf
+
+#endif /* USE_SATYR */
struct section_t {
char *name;
@@ -337,12 +365,12 @@ int append_short_backtrace(struct strbuf *result, problem_data_t
*problem_data,
if (strlen(item->content) >= max_text_size)
{
- struct btp_location location;
- btp_location_init(&location);
+ struct sr_location location;
+ sr_location_init(&location);
- /* btp_backtrace_parse modifies the input parameter */
+ /* sr_gdb_stacktrace_parse modifies the input parameter */
char *content = item->content;
- struct btp_backtrace *backtrace = btp_backtrace_parse((const char
**)&content, &location);
+ struct sr_gdb_stacktrace *backtrace = sr_gdb_stacktrace_parse((const char
**)&content, &location);
if (!backtrace)
{
@@ -351,9 +379,9 @@ int append_short_backtrace(struct strbuf *result, problem_data_t
*problem_data,
}
/* Get optimized thread stack trace for 10 top most frames */
- struct btp_thread *thread = btp_backtrace_get_optimized_thread(backtrace, 10);
+ struct sr_gdb_thread *thread = sr_gdb_stacktrace_get_optimized_thread(backtrace,
10);
- btp_backtrace_free(backtrace);
+ sr_gdb_stacktrace_free(backtrace);
if (!thread)
{
@@ -362,13 +390,13 @@ int append_short_backtrace(struct strbuf *result, problem_data_t
*problem_data,
}
/* Cannot be NULL, it dies on memory error */
- struct btp_strbuf *bt = btp_strbuf_new();
+ struct sr_strbuf *bt = sr_strbuf_new();
- btp_thread_append_to_str(thread, bt, true);
+ sr_gdb_thread_append_to_str(thread, bt, true);
- btp_thread_free(thread);
+ sr_gdb_thread_free(thread);
- truncated = btp_strbuf_free_nobuf(bt);
+ truncated = sr_strbuf_free_nobuf(bt);
}
append_text(result,
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index 67f55d4..ac016ce 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -276,6 +276,7 @@ int main(int argc, char **argv)
const char *dump_dir_path = ".";
const char *ureport_hash = NULL;
int rhbz_bug = -1;
+ struct dump_dir *dd = NULL;
struct options program_options[] = {
OPT__VERBOSE(&g_verbose),
OPT__DUMP_DIR(&dump_dir_path),
@@ -311,13 +312,13 @@ int main(int argc, char **argv)
if (!ureport_hash && rhbz_bug > 0)
error_msg_and_die(_("You need to specify bthash of the uReport to
attach."));
- struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
- if (!dd)
- xfunc_die();
-
/* -r */
if (attach_reported_to)
{
+ dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+ if (!dd)
+ xfunc_die();
+
report_result_t *ureport_result = find_in_reported_to(dd, "uReport");
report_result_t *bz_result = find_in_reported_to(dd, "Bugzilla");
@@ -350,16 +351,19 @@ int main(int argc, char **argv)
}
/* -b, -a nor -r were specified - upload uReport from dump_dir */
- problem_data_t *pd = create_problem_data_from_dump_dir(dd);
- dd_close(dd);
- if (!pd)
- xfunc_die(); /* create_problem_data_for_reporting already emitted error msg */
-
+ int ret = 1; /* return 1 by default */
char *dest_url = concat_path_file(config.ur_url, REPORT_URL_SFX);
config.ur_url = dest_url;
- post_state = post_ureport(pd, &config);
- problem_data_free(pd);
- int ret = 1; /* return 1 by default */
+
+ char *json_ureport = ureport_from_dump_dir(dump_dir_path);
+ if (!json_ureport)
+ {
+ error_msg(_("Not uploading an empty uReport"));
+ goto format_err;
+ }
+
+ post_state = post_ureport(json_ureport, &config);
+ free(json_ureport);
if (!post_state)
{
--
1.7.11.7