Signed-off-by: Jakub Filak <[email protected]>
---
 src/lib/json.c        |   21 ++++++---------------
 src/lib/ureport.h     |   11 +++++++++--
 src/plugins/ureport.c |   23 ++++++++++++++++++-----
 3 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/src/lib/json.c b/src/lib/json.c
index 659eda2..c9aed5f 100644
--- a/src/lib/json.c
+++ b/src/lib/json.c
@@ -96,18 +96,9 @@ static void ureport_add_os(struct json_object *ur, 
problem_data_t *pd)
     json_object_object_add(ur, "os", jobject);
 }
 
-static void ureport_add_type(struct json_object *ur, problem_data_t *pd)
+static void ureport_add_type(struct json_object *ur, const char *problem_type)
 {
-    char *pd_item = get_problem_item_content_or_NULL(pd, FILENAME_ANALYZER);
-    if (!pd_item)
-        return;
-
-    if (!strcmp(pd_item, "CCpp"))
-        ureport_add_str(ur, "type", "USERSPACE");
-    if (!strcmp(pd_item, "Python"))
-        ureport_add_str(ur, "type", "PYTHON");
-    if (!strcmp(pd_item, "Kerneloops"))
-        ureport_add_str(ur, "type", "KERNELOOPS");
+    ureport_add_str(ur, "type", problem_type);
 }
 
 static void ureport_add_core_backtrace(struct json_object *ur, problem_data_t 
*pd)
@@ -216,7 +207,7 @@ static void ureport_add_reporter(struct json_object *ur, 
const char *name, const
     json_object_object_add(ur, "reporter", jobject);
 }
 
-char *new_json_ureport(problem_data_t *pd)
+char *new_json_ureport(problem_data_t *pd, const char *problem_type)
 {
     struct json_object *ureport = json_object_new_object();
     if (!ureport)
@@ -236,7 +227,7 @@ char *new_json_ureport(problem_data_t *pd)
     ureport_add_item_str(ureport, pd, FILENAME_REASON, NULL);
     ureport_add_item_str(ureport, pd, FILENAME_COMPONENT, NULL);
 
-    ureport_add_type(ureport, pd);
+    ureport_add_type(ureport, problem_type);
 
     ureport_add_pkg(ureport, pd);
     ureport_add_related_pkgs(ureport, pd);
@@ -251,7 +242,7 @@ char *new_json_ureport(problem_data_t *pd)
     return j;
 }
 
-struct abrt_post_state *post_ureport(problem_data_t *pd, struct 
ureport_server_config *config)
+struct abrt_post_state *post_ureport(problem_data_t *pd, struct ureport_config 
*config)
 {
     int flags = ABRT_POST_WANT_BODY | ABRT_POST_WANT_ERROR_MSG;
 
@@ -266,7 +257,7 @@ struct abrt_post_state *post_ureport(problem_data_t *pd, 
struct ureport_server_c
         NULL,
     };
 
-    char *json_ureport = new_json_ureport(pd);
+    char *json_ureport = new_json_ureport(pd, config->ur_problem_type);
 
     abrt_post_string_as_form_data(post_state, config->ur_url, 
"application/json",
                      headers, json_ureport);
diff --git a/src/lib/ureport.h b/src/lib/ureport.h
index b1b1d89..8b76e9d 100644
--- a/src/lib/ureport.h
+++ b/src/lib/ureport.h
@@ -26,18 +26,25 @@ extern "C" {
 #endif
 
 /*
+ * Maximal allowed lenght of problem type string
+ */
+#define UREPORT_PROBLEM_TYPE_MAX_LEN 16
+#define UREPORT_PROBLEM_TYPE_MAX_LEN_STR "16"
+
+/*
  * uReport server configuration
  */
-struct ureport_server_config
+struct ureport_config
 {
     const char *ur_url; ///< Web service URL
     bool ur_ssl_verify; ///< Verify HOST and PEER certificates
+    const char *ur_problem_type; ///< Type of problem
 };
 
 struct abrt_post_state;
 
 #define post_ureport libreport_post_ureport
-struct abrt_post_state *post_ureport(problem_data_t *pd, struct 
ureport_server_config *config);
+struct abrt_post_state *post_ureport(problem_data_t *pd, struct ureport_config 
*config);
 
 #ifdef __cplusplus
 }
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index 5ffcea3..f003bf1 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -30,7 +30,7 @@
  *
  * @param config a server configuration to be populated
  */
-static void load_ureport_server_config(struct ureport_server_config *config)
+static void load_ureport_config(struct ureport_config *config)
 {
     const char *environ;
 
@@ -88,9 +88,10 @@ int main(int argc, char **argv)
 {
     abrt_init(argv);
 
-    struct ureport_server_config config = {
+    struct ureport_config config = {
         .ur_url = "https://retrace.fedoraproject.org/faf/reports/new/";,
         .ur_ssl_verify = true,
+        .ur_problem_type = NULL,
     };
 
     bool insecure = !config.ur_ssl_verify;
@@ -101,13 +102,19 @@ int main(int argc, char **argv)
         OPT_STRING('u', "url", &config.ur_url, "URL", _("Specify url")),
         OPT_BOOL('k', "insecure", &insecure,
                           _("Allow insecure connection to ureport server")),
+        OPT_STRING('t', "problem-type", &config.ur_problem_type, "TYPE", 
_("Specify type of reported problem")),
         OPT_END(),
     };
 
     const char *program_usage_string = _(
-        "& [-v] [-u URL] [-k] -d DIR\n"
+        _("& [-v] [-u URL] [-k] -t TYPE -d DIR\n"
         "\n"
-        "Upload micro report"
+        "Upload micro report\n"
+        "\n"
+        "Option -t sets type of reported problem. A value of the problem type 
is\n"
+        "an arbitrary string shorter than "UREPORT_PROBLEM_TYPE_MAX_LEN_STR" 
letters. Server rejects all ureports\n"
+        "with uknown problem types."
+        )
     );
 
     parse_opts(argc, argv, program_options, program_usage_string);
@@ -115,8 +122,14 @@ int main(int argc, char **argv)
     if (!dd)
         xfunc_die();
 
+    if (!config.ur_problem_type
+        || strlen(config.ur_problem_type) > UREPORT_PROBLEM_TYPE_MAX_LEN )
+        error_msg_and_die(
+            _("Type of problem must be set and must not be longer than "\
+              UREPORT_PROBLEM_TYPE_MAX_LEN_STR" letters"));
+
     config.ur_ssl_verify = !insecure;
-    load_ureport_server_config(&config);
+    load_ureport_config(&config);
 
     problem_data_t *pd = create_problem_data_from_dump_dir(dd);
     dd_close(dd);
-- 
1.7.10.2

Reply via email to