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

myMPD API handling More...

#include "compile_time.h"
#include "src/lib/api.h"
#include "src/lib/log.h"
#include "src/lib/mem.h"
#include "src/lib/msg_queue.h"
#include "src/lib/sds_extras.h"
#include <string.h>
Include dependency graph for api.c:

Macros

#define IFV_N   (sizeof mympd_cmd_acl/sizeof mympd_cmd_acl[0])
 

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)
 

Variables

static const char * mympd_cmd_strs [] = { MYMPD_CMDS(GEN_STR) }
 
static enum mympd_cmd_acl_entity mympd_cmd_acl []
 

Detailed Description

myMPD API handling

Macro Definition Documentation

◆ IFV_N

#define IFV_N   (sizeof mympd_cmd_acl/sizeof mympd_cmd_acl[0])

Compile time initialization check

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)

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

Variable Documentation

◆ mympd_cmd_acl

enum mympd_cmd_acl_entity mympd_cmd_acl[]
static

ACL for myMPD API methods

◆ mympd_cmd_strs

const char* mympd_cmd_strs[] = { MYMPD_CMDS(GEN_STR) }
static

myMPD API methods as strings