On Tuesday 26 of June 2012 12:38:58 Jiri Moskovcak wrote:
- this API should ease the process of creating the problem directory
from hooks and actually doesn't require user to know anything about
the problem directory
- it should also prevent some problems with locking as most of the time
ot works with the in memory problem representation
---
src/include/Makefile.am | 3 ++-
src/include/hooklib.h | 22 ++++++++++++++++++++++
src/include/libabrt.h | 1 +
src/lib/hooklib.c | 47
+++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72
insertions(+), 1 deletion(-)
create mode 100644 src/include/hooklib.h
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index f98e2d5..a4f24b9 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -3,4 +3,5 @@ libabrt_includedir = \
libabrt_include_HEADERS = \
libabrt.h \
- abrt-dbus.h
+ abrt-dbus.h \
+ hooklib.h
diff --git a/src/include/hooklib.h b/src/include/hooklib.h
new file mode 100644
index 0000000..6a8b282
--- /dev/null
+++ b/src/include/hooklib.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation,
Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+problem_data_t * problem_data_new();
+int problem_data_add_item(problem_data_t *pd, char *key, char *value);
+int problem_data_add_file(problem_data_t *pd, const char* path);
+int problem_data_finalize(problem_data_t *pd, char **problem_id);
diff --git a/src/include/libabrt.h b/src/include/libabrt.h
index 2b50fe5..fff80ef 100644
--- a/src/include/libabrt.h
+++ b/src/include/libabrt.h
@@ -10,6 +10,7 @@
#include "abrt-dbus.h"
/* libreport's internal functions we use: */
#include <libreport/internal_libreport.h>
+#include "hooklib.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c
index b00b81e..d6db340 100644
--- a/src/lib/hooklib.c
+++ b/src/lib/hooklib.c
@@ -342,3 +342,50 @@ char *get_backtrace(const char *dump_dir_name, unsigned
timeout_sec, const char free(args[7]);
return bt;
}
+
+static const char *get_filename(const char *path)
+{
+ const char *filename = NULL;
+
+ filename = strrchr(path, '/');
+ if (filename)
+ /* +1 => strip the '/' */
+ return filename+1;
+
+ return path;
+}
+
+problem_data_t *problem_data_new()
+{
+ return new_problem_data();
+}
+
+int problem_data_add_item(problem_data_t *pd, char * key, char * value)
+{
+ add_to_problem_data_ext(pd, key, value, CD_FLAG_TXT);
+ return 0;
+}
+
+int problem_data_add_file(problem_data_t *pd, const char* path)
+{
+ add_to_problem_data_ext(pd, get_filename(path), path, CD_FLAG_FILE);
+ return 0;
+}
+
+/** Saves the problem data
+ * creates the problem_dir in the configured problems directory
+ * destroyes
+*/
+int problem_data_finalize(problem_data_t *pd, char **problem_id)
+{
IMHO, this function does a lot of things. I like functions that does only one
thing. Could you please split the function to two functions. One function for
saving a problem data and an another function fro freeing data.
+ load_abrt_conf();
+ LibreportError res = save_dump_dir_from_problem_data(pd, problem_id,
g_settings_dump_location); + VERB2 log("problem id: '%s'",
*problem_id);
+ if (res != LR_OK)
+ /* can't be sure if it's ok, when the save fails */
+ *problem_id = NULL;
+
+ free_problem_data(pd);
+ pd = NULL;
+ return res;
+}
Regards,
Jakub