On Monday 20 of August 2012 10:17:38 Michal Toman wrote:
> ---
>  src/plugins/ureport.c |   59
> ++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 56
> insertions(+), 3 deletions(-)
> 
> diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
> index 99ce60a..3f8b3c2 100644
> --- a/src/plugins/ureport.c
> +++ b/src/plugins/ureport.c
> @@ -126,6 +126,7 @@ int main(int argc, char **argv)
>      };
> 
>      bool insecure = !config.ur_ssl_verify;
> +    bool attach_reported_to = false;
>      const char *dump_dir_path = ".";
>      const char *ureport_hash = NULL;
>      int rhbz_bug = -1;
> @@ -139,11 +140,13 @@ int main(int argc, char **argv)
>                            _("bthash of uReport to attach")),
>          OPT_INTEGER('b', "bug-id", &rhbz_bug,
>                            _("Attach RHBZ bug (requires -a)")),
> +        OPT_BOOL('r', "attach-reported-to", &attach_reported_to,
> +                          _("Attach contents of reported_to")),
>          OPT_END(),
>      };
> 
>      const char *program_usage_string = _(
> -        "& [-v] [-u URL] [-k] [-a bthash -b bug-id] [-d DIR]\n"
> +        "& [-v] [-u URL] [-k] [-a bthash -b bug-id] [-r] [-d DIR]\n"
>          "\n"
>          "Upload micro report or add an attachment to a micro report"
>      );
> @@ -175,11 +178,61 @@ int main(int argc, char **argv)
>      else if (!ureport_hash && rhbz_bug > 0)
>          error_msg_and_die(_("You need to specify bthash of the uReport to
> attach."));
> 
> -    /* -b nor -a were specified - upload uReport from dump_dir */

cosmetic: you can safely open a dump directory here ...

+    struct dump_dir *dd;
+    dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
+    if (!dd)
+        xfunc_die();

> +
> +    /* -r */
> +    if (attach_reported_to)
> +    {
> +        if (!config.ur_url)
> +            config.ur_url = ATTACH_URL;
> +
> +        report_result_t *ureport_result = find_in_reported_to(dd,
> "uReport"); +        report_result_t *bz_result = find_in_reported_to(dd,
> "Bugzilla"); +
> +        dd_close(dd);
> +
> +        if (!ureport_result || !ureport_result->bthash)
> +            error_msg_and_die("This problem has not an uReport assigned.");
> +

cosmetic: consider the following change, it looks more natural to me

           if (!bz_result || !bz_result->url)
               error_msg_and_die("This problem has not been reported to  
Bugzilla.");

           char *bthash = xstrdup(ureport_result->bthash);
           free_report_result(ureport_result);
> +
> +        char *bugid_ptr = strstr(bz_result->url, "show_bug.cgi?id=");
> +        if (!bugid_ptr)
> +            error_msg_and_die("Unable to find bug ID in bugzilla URL.");
> +
> +        bugid_ptr += strlen("show_bug.cgi?id=");
> +        int bugid;

- maybe a short note about why sscanf() is good enought would be nice :)

> +        if (sscanf(bugid_ptr, "%d", &bugid) != 1)
> +            error_msg_and_die("Unable to parse bug ID from bugzilla URL.");
> +
> +        free_report_result(bz_result);
> +
> +        post_state = ureport_attach_rhbz(bthash, bugid, &config);
> +        free(bthash);
> +

another cosmetic change:

           const int result = !check_response_statuscode(post_state, 
config.ur_url))
           free_post_state(post_state);
           return result;
> +    }
> +
> +    /* -b, -a nor -r were specified - upload uReport from dump_dir */
>      if (!config.ur_url)
>          config.ur_url = REPORT_URL;
> 
-    struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
-    if (!dd)
-        xfunc_die();


It looks good to me. The notes above are just cosmetic and it is no necessary 
to take care about them. Anyway, I didn't found any memory error nor leak, it 
compiles and works. Push it, please.

Reply via email to