myMPD API handling
More...
#include "dist/sds/sds.h"
#include "src/lib/list.h"
#include "src/lib/webradio.h"
#include <stdbool.h>
Go to the source code of this file.
|
| enum | mympd_cmd_ids |
| |
| enum | mympd_cmd_acl_entity {
API_INTERNAL = 0x1
, API_PUBLIC = 0x2
, API_PROTECTED = 0x4
, API_SCRIPT = 0x8
,
API_MPD_DISCONNECTED = 0x10
, API_MYMPD_ONLY = 0x20
, API_MYMPD_WORKER_ONLY = 0x40
, API_INVALID = 0x80
,
API_SCRIPT_THREAD = 0x100
} |
| |
| enum | work_response_types {
RESPONSE_TYPE_DEFAULT = 0
, RESPONSE_TYPE_NOTIFY_CLIENT
, RESPONSE_TYPE_NOTIFY_PARTITION
, RESPONSE_TYPE_PUSH_CONFIG
,
RESPONSE_TYPE_SCRIPT
, RESPONSE_TYPE_DISCARD
, RESPONSE_TYPE_RAW
, RESPONSE_TYPE_SCRIPT_DIALOG
,
RESPONSE_TYPE_REDIRECT
} |
| |
| enum | work_request_types { REQUEST_TYPE_DEFAULT = 0
, REQUEST_TYPE_SCRIPT
, REQUEST_TYPE_NOTIFY_PARTITION
, REQUEST_TYPE_DISCARD
} |
| |
|
| enum mympd_cmd_ids | get_cmd_id (const char *cmd) |
| |
| const char * | get_cmd_id_method_name (enum mympd_cmd_ids cmd_id) |
| |
| bool | check_cmd_acl (enum mympd_cmd_ids cmd_id, enum mympd_cmd_acl_entity ace) |
| |
| void | ws_notify (sds message, const char *partition) |
| |
| void | ws_notify_client (sds message, unsigned request_id) |
| |
| void | ws_script_dialog (sds message, unsigned request_id) |
| |
| struct t_work_response * | create_response (struct t_work_request *request) |
| |
| struct t_work_response * | create_response_new (enum work_response_types type, unsigned long conn_id, unsigned request_id, enum mympd_cmd_ids cmd_id, const char *partition) |
| |
| struct t_work_request * | create_request (enum work_request_types type, unsigned long conn_id, unsigned request_id, enum mympd_cmd_ids cmd_id, const char *data, const char *partition) |
| |
| void | free_request (struct t_work_request *request) |
| |
| void | free_response (struct t_work_response *response) |
| |
| bool | push_response (struct t_work_response *response) |
| |
| bool | push_request (struct t_work_request *request, unsigned id) |
| |
◆ GEN_ENUM
Macro to generate enum for the API methods
◆ GEN_STR
Macro to generate strings for the API methods
◆ MYMPD_CMDS
myMPD api methods Must be added to mympd_cmd_acl_entity also! TOTAL_API_COUNT must be the last
◆ mympd_cmd_acl_entity
myMPD ACL values
| Enumerator |
|---|
| API_INTERNAL | Defines internal methods.
|
| API_PUBLIC | Defines methods that are public.
|
| API_PROTECTED | Defines methods that need authentication if a pin is set.
|
| API_SCRIPT | Defines internal methods that are accessible by scripts.
|
| API_MPD_DISCONNECTED | Defines methods that should be handled if MPD is disconnected.
|
| API_MYMPD_ONLY | Defines methods that do not require to leave the mpd idle mode in the mympd_api thread.
|
| API_MYMPD_WORKER_ONLY | Defines methods that do not require to create a mpd connection in the mympd_worker thread.
|
| API_INVALID | API methods that should not be called.
|
| API_SCRIPT_THREAD | API methods that are handled by the script thread.
|
◆ mympd_cmd_ids
Enum of myMPD jsonrpc api methods
◆ work_request_types
Request types
| Enumerator |
|---|
| REQUEST_TYPE_DEFAULT | Request is from a mongoose connection.
|
| REQUEST_TYPE_SCRIPT | Request is from the script thread.
|
| REQUEST_TYPE_NOTIFY_PARTITION | Send message to all clients in a specific partition.
|
| REQUEST_TYPE_DISCARD | Response will be discarded.
|
◆ work_response_types
Response types
| Enumerator |
|---|
| RESPONSE_TYPE_DEFAULT | Send message back to the mongoose connection.
|
| RESPONSE_TYPE_NOTIFY_CLIENT | Send message to client identified by jsonrpc id.
|
| RESPONSE_TYPE_NOTIFY_PARTITION | Send message to all clients in a specific partition.
|
| RESPONSE_TYPE_PUSH_CONFIG | Internal message from myMPD API thread to webserver thread to push the configuration.
|
| RESPONSE_TYPE_SCRIPT | Response is for the script thread.
|
| RESPONSE_TYPE_DISCARD | Response will be discarded.
|
| RESPONSE_TYPE_RAW | Raw http message.
|
| RESPONSE_TYPE_SCRIPT_DIALOG | Script dialog.
|
| RESPONSE_TYPE_REDIRECT | Send a redirect.
|
◆ check_cmd_acl()
Checks the myMPD method ACL
- Parameters
-
| cmd_id | method to check |
| ace | Access method |
- Returns
- bool true on success, else false
◆ create_request()
Mallocs and initializes a t_work_request struct
- Parameters
-
| type | work request type |
| conn_id | connection id (from webserver) |
| request_id | id for the request |
| cmd_id | myMPD API method |
| data | jsonrpc request, if NULL the start of a jsonrpc request is added, use a empty string to assign NULL, else a sds string is malloced from data |
| partition | mpd partition |
- Returns
- the initialized t_work_request struct
◆ create_response()
Mallocs and initializes a t_work_response struct, as reply of the provided request
- Parameters
-
| request | the request the ids are copied |
- Returns
- the initialized t_work_response struct
◆ create_response_new()
Mallocs and initializes a t_work_response struct
- Parameters
-
| type | work response type |
| conn_id | connection id (from webserver) |
| request_id | id for the request |
| cmd_id | myMPD API method |
| partition | mpd partition |
- Returns
- the initialized t_work_response struct
◆ free_request()
Frees the request struct
- Parameters
-
| request | request struct to free |
◆ free_response()
Frees the response struct
- Parameters
-
| response | response struct to free |
◆ get_cmd_id()
Public functions
Converts a string to the mympd_cmd_ids enum
- Parameters
-
- Returns
- enum mympd_cmd_ids
◆ get_cmd_id_method_name()
Converts the mympd_cmd_ids enum to the string
- Parameters
-
- Returns
- the API method as string
◆ push_request()
Pushes the request to a queue
- Parameters
-
| request | pointer to request struct to push |
| id | request id |
- Returns
- true on success, else false
◆ push_response()
Pushes the response to a queue or frees it
- Parameters
-
| response | pointer to response struct to push |
- Returns
- true on success, else false
◆ ws_notify()
| void ws_notify |
( |
sds |
message, |
|
|
const char * |
partition |
|
) |
| |
Sends a websocket message to all clients in a partition
- Parameters
-
| message | the message to send |
| partition | mpd partition |
◆ ws_notify_client()
| void ws_notify_client |
( |
sds |
message, |
|
|
unsigned |
request_id |
|
) |
| |
Sends a websocket message to a client
- Parameters
-
| message | the message to send |
| request_id | the jsonrpc id of the client |
◆ ws_script_dialog()
| void ws_script_dialog |
( |
sds |
message, |
|
|
unsigned |
request_id |
|
) |
| |
Sends a websocket message to a client to display a dialog.
- Parameters
-
| message | The message to send |
| request_id | the jsonrpc id of the client |