Skip to content

Commit

Permalink
stop using deprecated json-c functions
Browse files Browse the repository at this point in the history
Resolves: #1125743

Signed-off-by: Jakub Filak <jfilak@redhat.com>
  • Loading branch information
Jakub Filak committed Aug 4, 2014
1 parent 3601095 commit 712ca27
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions src/plugins/ureport.c
Expand Up @@ -157,16 +157,13 @@ static char *parse_solution_from_json_list(struct json_object *list, GList **rep
if (!list_elem)
continue;

struct_elem = json_object_object_get(list_elem, "cause");
if (!struct_elem)
if (!json_object_object_get_ex(list_elem, "cause", &struct_elem))
continue;

cause = json_object_get_string(struct_elem);
if (!cause)

This comment has been minimized.

Copy link
@jfilak

jfilak Nov 21, 2014

Contributor

I shouldn't have removed this line. Fixed in adfc3e6

continue;

struct_elem = json_object_object_get(list_elem, "note");
if (!struct_elem)
if (!json_object_object_get_ex(list_elem, "note", &struct_elem))
continue;

note = json_object_get_string(struct_elem);
Expand All @@ -176,8 +173,7 @@ static char *parse_solution_from_json_list(struct json_object *list, GList **rep
empty = false;
strbuf_append_strf(solution_buf, one_format, cause, note);

struct_elem = json_object_object_get(list_elem, "url");
if (!struct_elem)
if (!json_object_object_get_ex(list_elem, "url", &struct_elem))
continue;

url = json_object_get_string(struct_elem);
Expand Down Expand Up @@ -216,24 +212,21 @@ static GList *parse_reported_to_from_json_list(struct json_object *list)
if (!list_elem)
continue;

struct_elem = json_object_object_get(list_elem, "reporter");
if (!struct_elem)
if (!json_object_object_get_ex(list_elem, "reporter", &struct_elem))
continue;

reporter = json_object_get_string(struct_elem);
if (!reporter)
continue;

struct_elem = json_object_object_get(list_elem, "value");
if (!struct_elem)
if (!json_object_object_get_ex(list_elem, "value", &struct_elem))
continue;

value = json_object_get_string(struct_elem);
if (!value)
continue;

struct_elem = json_object_object_get(list_elem, "type");
if (!struct_elem)
if (!json_object_object_get_ex(list_elem, "type", &struct_elem))
continue;

type = json_object_get_string(struct_elem);
Expand Down Expand Up @@ -265,9 +258,8 @@ static GList *parse_reported_to_from_json_list(struct json_object *list)
*/
static struct ureport_server_response *ureport_server_parse_json(json_object *json)
{
json_object *obj = json_object_object_get(json, "error");

if (obj)
json_object *obj = NULL;
if (json_object_object_get_ex(json, "error", &obj))
{
struct ureport_server_response *out_response = xzalloc(sizeof(*out_response));
out_response->is_error = true;
Expand All @@ -279,27 +271,25 @@ static struct ureport_server_response *ureport_server_parse_json(json_object *js
return out_response;
}

obj = json_object_object_get(json, "result");

if (obj)
if (json_object_object_get_ex(json, "result", &obj))
{
struct ureport_server_response *out_response = xzalloc(sizeof(*out_response));
out_response->value = xstrdup(json_object_get_string(obj));

json_object *message = json_object_object_get(json, "message");
if (message)
json_object *message = NULL;
if (json_object_object_get_ex(json, "message", &message))
out_response->message = xstrdup(json_object_get_string(message));

json_object *bthash = json_object_object_get(json, "bthash");
if (bthash)
json_object *bthash = NULL;
if (json_object_object_get_ex(json, "bthash", &bthash))
out_response->bthash = xstrdup(json_object_get_string(bthash));

json_object *reported_to_list = json_object_object_get(json, "reported_to");
if (reported_to_list)
json_object *reported_to_list = NULL;
if (json_object_object_get_ex(json, "reported_to", &reported_to_list))
out_response->reported_to_list = parse_reported_to_from_json_list(reported_to_list);

json_object *solutions = json_object_object_get(json, "solutions");
if (solutions)
json_object *solutions = NULL;
if (json_object_object_get_ex(json, "solutions", &solutions))
out_response->solution = parse_solution_from_json_list(solutions, &(out_response->reported_to_list));

return out_response;
Expand Down

0 comments on commit 712ca27

Please sign in to comment.