summaryrefslogtreecommitdiff
path: root/src/status.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/status.c b/src/status.c
index 139c719..69d1fa2 100644
--- a/src/status.c
+++ b/src/status.c
@@ -5,39 +5,40 @@
#include "status.h"
#include "log.h"
-struct status *status_from_json(char *json_data)
+struct status *status_from_json(const char *json_data)
{
+ struct status *s;
json_t *root;
json_error_t error;
root = json_loads(json_data, 0, &error);
if (!root) {
- log_msg(LOG_ERROR, "status_from_json", "json parse error: line %d: %s",
+ log_msg(LOG_WARNING, "status_from_json", "json parse error: line %d: %s",
error.line, error.text);
return NULL;
}
- return status_from_json_t(root);
+ s = status_from_json_t(root);
+ json_decref(root);
+ return s;
}
-struct status *status_from_json_t(json_t *root)
+struct status *status_from_json_t(const json_t *root)
{
struct status *s;
if (!root) {
- log_msg(LOG_ERROR, "status_from_json_t", "json data is null");
+ log_msg(LOG_WARNING, "status_from_json_t", "json data is null");
return NULL;
}
if (!json_is_object(root)) {
- log_msg(LOG_ERROR, "status_from_json_t", "json root is not object");
- json_decref(root);
+ log_msg(LOG_WARNING, "status_from_json_t", "json root is not object");
return NULL;
}
s = calloc(1, sizeof(struct status));
if (!s) {
- err(1, NULL);
- json_decref(root);
+ err(1, "status_from_json_t");
return NULL;
}
@@ -88,16 +89,11 @@ struct status *status_from_json_t(json_t *root)
s->favourites_count = json_integer_value(favourites_count);
}
- json_decref(root);
return s;
}
void status_free(struct status *s)
{
- if (!s) {
- log_msg(LOG_ERROR, "status_free", "status not initializes");
- return;
- }
if (s->id)
free(s->id);
if (s->uri)