diff options
Diffstat (limited to 'src/libpiano')
-rw-r--r-- | src/libpiano/piano.h | 19 | ||||
-rw-r--r-- | src/libpiano/request.c | 41 | ||||
-rw-r--r-- | src/libpiano/response.c | 12 |
3 files changed, 72 insertions, 0 deletions
diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h index 28a2b45..f0ba4cf 100644 --- a/src/libpiano/piano.h +++ b/src/libpiano/piano.h @@ -148,6 +148,11 @@ typedef struct { PianoSong_t *feedback; } PianoStationInfo_t; +typedef struct { + char *username; + bool explicitContentFilter; +} PianoSettings_t; + typedef enum { /* 0 is reserved: memset (x, 0, sizeof (x)) */ PIANO_REQUEST_LOGIN = 1, @@ -170,6 +175,8 @@ typedef enum { PIANO_REQUEST_GET_STATION_INFO = 20, PIANO_REQUEST_DELETE_FEEDBACK = 21, PIANO_REQUEST_DELETE_SEED = 22, + PIANO_REQUEST_GET_SETTINGS = 23, + PIANO_REQUEST_CHANGE_SETTINGS = 24, } PianoRequestType_t; typedef struct PianoRequest { @@ -245,6 +252,18 @@ typedef struct { PianoStation_t *station; } PianoRequestDataDeleteSeed_t; +typedef enum { + PIANO_UNDEFINED = 0, + PIANO_FALSE = 1, + PIANO_TRUE = 2, +} PianoTristate_t; + +typedef struct { + char *currentUsername, *newUsername; + char *currentPassword, *newPassword; + PianoTristate_t explicitContentFilter; +} PianoRequestDataChangeSettings_t; + /* pandora error code offset */ #define PIANO_RET_OFFSET 1024 typedef enum { diff --git a/src/libpiano/request.c b/src/libpiano/request.c index cad0907..95ac2d0 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -402,6 +402,47 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, break; } + case PIANO_REQUEST_GET_SETTINGS: { + method = "user.getSettings"; + break; + } + + case PIANO_REQUEST_CHANGE_SETTINGS: { + PianoRequestDataChangeSettings_t *reqData = req->data; + assert (reqData != NULL); + assert (reqData->currentPassword != NULL); + assert (reqData->currentUsername != NULL); + + json_object_object_add (j, "userInitiatedChange", + json_object_new_boolean (true)); + json_object_object_add (j, "currentUsername", + json_object_new_string (reqData->currentUsername)); + json_object_object_add (j, "currentPassword", + json_object_new_string (reqData->currentPassword)); + + if (reqData->explicitContentFilter != PIANO_UNDEFINED) { + json_object_object_add (j, "isExplicitContentFilterEnabled", + json_object_new_boolean ( + reqData->explicitContentFilter == PIANO_TRUE)); + } + +#define changeIfSet(field) \ + if (reqData->field != NULL) { \ + json_object_object_add (j, #field, \ + json_object_new_string (reqData->field)); \ + } + + changeIfSet (newUsername); + changeIfSet (newPassword); + +#undef changeIfSet + + req->secure = true; + + method = "user.changeSettings"; + break; + } + /* "high-level" wrapper */ case PIANO_REQUEST_RATE_SONG: { /* love/ban song */ diff --git a/src/libpiano/response.c b/src/libpiano/response.c index b530f3a..542ef00 100644 --- a/src/libpiano/response.c +++ b/src/libpiano/response.c @@ -411,6 +411,7 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) { case PIANO_REQUEST_BOOKMARK_ARTIST: case PIANO_REQUEST_DELETE_FEEDBACK: case PIANO_REQUEST_DELETE_SEED: + case PIANO_REQUEST_CHANGE_SETTINGS: /* response unused */ break; @@ -508,6 +509,17 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) { break; } + case PIANO_REQUEST_GET_SETTINGS: { + PianoSettings_t * const settings = req->data; + + assert (settings != NULL); + + settings->explicitContentFilter = json_object_get_boolean ( + json_object_object_get (result, "isExplicitContentFilterEnabled")); + settings->username = PianoJsonStrdup (result, "username"); + break; + } + case PIANO_REQUEST_GET_STATION_INFO: { /* get station information (seeds and feedback) */ PianoRequestDataGetStationInfo_t *reqData = req->data; |