[lastfm/jsonapi/ws/main] New JSON-API-endpoints for Last.fm integration

In preparation for the new endpoints the following refactorings where
done in lastfm.c:
- Initialize lastfm.c in main.c instead of on first scrobble attempt
(necessary to retrieve the correct lastfm status)
- Return error messages if login attempt failed
- Add api function for status and logout
- Notify about Last.fm status changes

Unrelated changes in lastfm.c are:
- Refactoring of request_post
- Add request parameters sorted alphabetically and remove calling the
sort method in request_post
This commit is contained in:
chme
2017-09-24 06:57:49 +02:00
parent b64d282f32
commit f82b22042f
6 changed files with 275 additions and 66 deletions

View File

@@ -137,6 +137,10 @@ process_notify_request(struct ws_session_data_notify *session_data, void *in, si
{
session_data->events |= LISTENER_SPOTIFY;
}
else if (0 == strcmp(event_type, "lastfm"))
{
session_data->events |= LISTENER_LASTFM;
}
}
}
}
@@ -177,6 +181,10 @@ send_notify_reply(short events, struct lws* wsi)
{
json_object_array_add(notify, json_object_new_string("spotify"));
}
if (events & LISTENER_LASTFM)
{
json_object_array_add(notify, json_object_new_string("lastfm"));
}
reply = json_object_new_object();
json_object_object_add(reply, "notify", notify);
@@ -258,7 +266,7 @@ static struct lws_protocols protocols[] =
static void *
websocket(void *arg)
{
listener_add(listener_cb, LISTENER_UPDATE | LISTENER_PAIRING | LISTENER_SPOTIFY);
listener_add(listener_cb, LISTENER_UPDATE | LISTENER_PAIRING | LISTENER_SPOTIFY | LISTENER_LASTFM);
while(!ws_exit)
{