myMPD
Internal API documentation
Loading...
Searching...
No Matches
api.h File Reference

myMPD API handling More...

#include "dist/sds/sds.h"
#include "src/lib/list.h"
#include "src/lib/webradio.h"
#include <stdbool.h>
Include dependency graph for api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  t_work_request
 
struct  t_work_response
 
struct  set_mg_user_data_request
 

Macros

#define MYMPD_CMDS(X)
 
#define GEN_ENUM(X)   X,
 
#define GEN_STR(X)   #X,
 

Enumerations

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 }
 

Functions

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_responsecreate_response (struct t_work_request *request)
 
struct t_work_responsecreate_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_requestcreate_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)
 

Detailed Description

myMPD API handling

Macro Definition Documentation

◆ GEN_ENUM

#define GEN_ENUM (   X)    X,

Macro to generate enum for the API methods

◆ GEN_STR

#define GEN_STR (   X)    #X,

Macro to generate strings for the API methods

◆ MYMPD_CMDS

#define MYMPD_CMDS (   X)

myMPD api methods Must be added to mympd_cmd_acl_entity also! TOTAL_API_COUNT must be the last

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ check_cmd_acl()

bool check_cmd_acl ( enum mympd_cmd_ids  cmd_id,
enum mympd_cmd_acl_entity  ace 
)

Checks the myMPD method ACL

Parameters
cmd_idmethod to check
aceAccess method
Returns
bool true on success, else false

◆ create_request()

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 
)

Mallocs and initializes a t_work_request struct

Parameters
typework request type
conn_idconnection id (from webserver)
request_idid for the request
cmd_idmyMPD API method
datajsonrpc 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
partitionmpd partition
Returns
the initialized t_work_request struct

◆ create_response()

struct t_work_response * create_response ( struct t_work_request request)

Mallocs and initializes a t_work_response struct, as reply of the provided request

Parameters
requestthe request the ids are copied
Returns
the initialized t_work_response struct

◆ create_response_new()

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 
)

Mallocs and initializes a t_work_response struct

Parameters
typework response type
conn_idconnection id (from webserver)
request_idid for the request
cmd_idmyMPD API method
partitionmpd partition
Returns
the initialized t_work_response struct

◆ free_request()

void free_request ( struct t_work_request request)

Frees the request struct

Parameters
requestrequest struct to free

◆ free_response()

void free_response ( struct t_work_response response)

Frees the response struct

Parameters
responseresponse struct to free

◆ get_cmd_id()

enum mympd_cmd_ids get_cmd_id ( const char *  cmd)

Public functions

Converts a string to the mympd_cmd_ids enum

Parameters
cmdstring to convert
Returns
enum mympd_cmd_ids

◆ get_cmd_id_method_name()

const char * get_cmd_id_method_name ( enum mympd_cmd_ids  cmd_id)

Converts the mympd_cmd_ids enum to the string

Parameters
cmd_idmyMPD API method
Returns
the API method as string

◆ push_request()

bool push_request ( struct t_work_request request,
unsigned  id 
)

Pushes the request to a queue

Parameters
requestpointer to request struct to push
idrequest id
Returns
true on success, else false

◆ push_response()

bool push_response ( struct t_work_response response)

Pushes the response to a queue or frees it

Parameters
responsepointer 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
messagethe message to send
partitionmpd partition

◆ ws_notify_client()

void ws_notify_client ( sds  message,
unsigned  request_id 
)

Sends a websocket message to a client

Parameters
messagethe message to send
request_idthe 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
messageThe message to send
request_idthe jsonrpc id of the client