示例#1
0
文件: bodhi.c 项目: wlindauer/abrt
static GHashTable *bodhi_query_list(const char *query, const char *release)
{
    char *bodhi_url_bugs = xasprintf("%s/?%s", bodhi_url, query);

    post_state_t *post_state = new_post_state(POST_WANT_BODY
                                              | POST_WANT_SSL_VERIFY
                                              | POST_WANT_ERROR_MSG);

    const char *headers[] = {
        "Accept: application/json",
        NULL
    };

    get(post_state, bodhi_url_bugs, "application/x-www-form-urlencoded",
                     headers);

    if (post_state->http_resp_code != 200 && post_state->http_resp_code != 400)
    {
        char *errmsg = post_state->curl_error_msg;
        if (errmsg && errmsg[0])
            error_msg_and_die("%s '%s'", errmsg, bodhi_url_bugs);
    }
    free(bodhi_url_bugs);

//    log_warning("%s", post_state->body);

    json_object *json = json_tokener_parse(post_state->body);
    if (is_error(json))
        error_msg_and_die("fatal: unable parse response from bodhi server");

    /* we must check the http_resp_code because only error responses contain
     * 'status' item. 'bodhi_read_value' function prints an error message in
     * the case it did not found the item */
    if (post_state->http_resp_code != 200)
    {
        char *status_item = NULL;
        bodhi_read_value(json, "status", &status_item, BODHI_READ_STR);
        if (status_item != NULL && strcmp(status_item, "error") == 0)
        {
            free(status_item);
            bodhi_print_errors_from_json(json);
            json_object_put(json);
            xfunc_die(); // error_msg are printed in bodhi_print_errors_from_json
        }
    }

    GHashTable *bodhi_table = bodhi_parse_json(json, release);
    json_object_put(json);
    free_post_state(post_state);

    return bodhi_table;
}
示例#2
0
文件: bodhi.c 项目: vrutkovs/abrt
static GHashTable *bodhi_query_list(const char *query, const char *release)
{
    char *bodhi_url_bugs = xasprintf("%s/list", bodhi_url);

    post_state_t *post_state = new_post_state(POST_WANT_BODY
                                              | POST_WANT_SSL_VERIFY
                                              | POST_WANT_ERROR_MSG);

    const char *headers[] = {
        "Accept: application/json",
        NULL
    };

    post_string(post_state, bodhi_url_bugs, "application/x-www-form-urlencoded",
                     headers, query);

    if (post_state->http_resp_code != 200)
    {
        char *errmsg = post_state->curl_error_msg;
        if (errmsg && errmsg[0])
            error_msg_and_die("%s '%s'", errmsg, bodhi_url_bugs);
    }
    free(bodhi_url_bugs);

//    log("%s", post_state->body);

    json_object *json = json_tokener_parse(post_state->body);
    if (is_error(json))
        error_msg_and_die("fatal: unable parse response from bodhi server");

    GHashTable *bodhi_table = bodhi_parse_json(json, release);
    json_object_put(json);
    free_post_state(post_state);

    return bodhi_table;
}