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

Jsonrpc implementation. More...

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

Go to the source code of this file.

Enumerations

enum  jsonrpc_response_types { RESPONSE_TYPE_JSONRPC_RESPONSE = 0 , RESPONSE_TYPE_JSONRPC_NOTIFY , RESPONSE_TYPE_PLAIN , RESPONSE_TYPE_NONE }
enum  jsonrpc_severities {
  JSONRPC_SEVERITY_EMERG = 0 , JSONRPC_SEVERITY_ALERT , JSONRPC_SEVERITY_CRIT , JSONRPC_SEVERITY_ERROR ,
  JSONRPC_SEVERITY_WARN , JSONRPC_SEVERITY_NOTICE , JSONRPC_SEVERITY_INFO , JSONRPC_SEVERITY_DEBUG ,
  JSONRPC_SEVERITY_MAX
}
enum  jsonrpc_facilities {
  JSONRPC_FACILITY_DATABASE = 0 , JSONRPC_FACILITY_GENERAL , JSONRPC_FACILITY_HOME , JSONRPC_FACILITY_JUKEBOX ,
  JSONRPC_FACILITY_LYRICS , JSONRPC_FACILITY_MPD , JSONRPC_FACILITY_PLAYLIST , JSONRPC_FACILITY_PLAYER ,
  JSONRPC_FACILITY_QUEUE , JSONRPC_FACILITY_SESSION , JSONRPC_FACILITY_SCRIPT , JSONRPC_FACILITY_STICKER ,
  JSONRPC_FACILITY_TIMER , JSONRPC_FACILITY_TRIGGER , JSONRPC_FACILITY_MAX
}
enum  jsonrpc_events {
  JSONRPC_EVENT_MPD_CONNECTED = 0 , JSONRPC_EVENT_MPD_DISCONNECTED , JSONRPC_EVENT_NOTIFY , JSONRPC_EVENT_UPDATE_DATABASE ,
  JSONRPC_EVENT_UPDATE_FINISHED , JSONRPC_EVENT_UPDATE_HOME , JSONRPC_EVENT_UPDATE_JUKEBOX , JSONRPC_EVENT_UPDATE_LAST_PLAYED ,
  JSONRPC_EVENT_UPDATE_OPTIONS , JSONRPC_EVENT_UPDATE_OUTPUTS , JSONRPC_EVENT_UPDATE_QUEUE , JSONRPC_EVENT_UPDATE_STARTED ,
  JSONRPC_EVENT_UPDATE_STATE , JSONRPC_EVENT_UPDATE_STORED_PLAYLIST , JSONRPC_EVENT_UPDATE_VOLUME , JSONRPC_EVENT_WELCOME ,
  JSONRPC_EVENT_UPDATE_CACHE_STARTED , JSONRPC_EVENT_UPDATE_CACHE_FINISHED , JSONRPC_EVENT_UPDATE_NEIGHBOR , JSONRPC_EVENT_UPDATE_MOUNT ,
  JSONRPC_EVENT_MAX
}

Functions

void send_jsonrpc_notify (enum jsonrpc_facilities facility, enum jsonrpc_severities severity, const char *partition, const char *message)
void send_jsonrpc_notify_client (enum jsonrpc_facilities facility, enum jsonrpc_severities severity, unsigned request_id, const char *message)
void send_jsonrpc_event (enum jsonrpc_events event, const char *partition)
sds jsonrpc_event (sds buffer, enum jsonrpc_events event)
sds jsonrpc_notify (sds buffer, enum jsonrpc_facilities facility, enum jsonrpc_severities severity, const char *message)
sds jsonrpc_notify_phrase (sds buffer, enum jsonrpc_facilities facility, enum jsonrpc_severities severity, const char *message, int count,...)
sds jsonrpc_notify_start (sds buffer, enum jsonrpc_events event)
sds jsonrpc_respond_start (sds buffer, enum mympd_cmd_ids cmd_id, unsigned request_id)
sds jsonrpc_end (sds buffer)
sds jsonrpc_respond_ok (sds buffer, enum mympd_cmd_ids cmd_id, unsigned request_id, enum jsonrpc_facilities facility)
sds jsonrpc_respond_with_ok_or_error (sds buffer, enum mympd_cmd_ids cmd_id, unsigned request_id, bool rc, enum jsonrpc_facilities facility, const char *error)
sds jsonrpc_respond_with_message_or_error (sds buffer, enum mympd_cmd_ids cmd_id, unsigned request_id, bool rc, enum jsonrpc_facilities facility, const char *message, const char *error)
sds jsonrpc_respond_message (sds buffer, enum mympd_cmd_ids cmd_id, unsigned request_id, enum jsonrpc_facilities facility, enum jsonrpc_severities severity, const char *message)
sds jsonrpc_respond_message_phrase (sds buffer, enum mympd_cmd_ids cmd_id, unsigned request_id, enum jsonrpc_facilities facility, enum jsonrpc_severities severity, const char *message, int count,...)

Detailed Description

Jsonrpc implementation.

Enumeration Type Documentation

◆ jsonrpc_events

Jsonrpc events

◆ jsonrpc_facilities

Jsonrpc facilities

◆ jsonrpc_response_types

Response types for error messages

◆ jsonrpc_severities

Jsonrpc severities

Function Documentation

◆ jsonrpc_end()

sds jsonrpc_end ( sds buffer)

Creates the end of a jsonrpc response

Parameters
bufferpointer to already allocated sds string
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_event()

sds jsonrpc_event ( sds buffer,
enum jsonrpc_events event )

Creates a simple jsonrpc notification with the event as method

Parameters
bufferpointer to already allocated sds string
eventthe event to use
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_notify()

sds jsonrpc_notify ( sds buffer,
enum jsonrpc_facilities facility,
enum jsonrpc_severities severity,
const char * message )

Creates a jsonrpc notification with facility, severity and a message

Parameters
bufferpointer to already allocated sds string
facilityone of enum jsonrpc_facilities
severityone of enum jsonrpc_severities
messagethe message to send
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_notify_phrase()

sds jsonrpc_notify_phrase ( sds buffer,
enum jsonrpc_facilities facility,
enum jsonrpc_severities severity,
const char * message,
int count,
... )

Creates a jsonrpc notification with facility, severity and a message phrase. A message phrase can include %{key} placeholders that are replaced on the client side with the value. Key/value pairs are variadic arguments.

Parameters
bufferpointer to already allocated sds string
facilityone of enum jsonrpc_facilities
severityone of enum jsonrpc_severities
messagethe message to send
countnumber of following variadic arguments
...key/value pairs for the phrase
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_notify_start()

sds jsonrpc_notify_start ( sds buffer,
enum jsonrpc_events event )

Creates the start of a jsonrpc notification.

Parameters
bufferpointer to already allocated sds string
eventthe event to use
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_respond_message()

sds jsonrpc_respond_message ( sds buffer,
enum mympd_cmd_ids cmd_id,
unsigned request_id,
enum jsonrpc_facilities facility,
enum jsonrpc_severities severity,
const char * message )

Creates a simple jsonrpc response with a custom message

Parameters
bufferpointer to already allocated sds string
cmd_idenum mympd_cmd_ids
request_idid of the jsonrpc request to answer
facilityone of enum jsonrpc_facilities
severityone of enum jsonrpc_severities
messagethe response message
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_respond_message_phrase()

sds jsonrpc_respond_message_phrase ( sds buffer,
enum mympd_cmd_ids cmd_id,
unsigned request_id,
enum jsonrpc_facilities facility,
enum jsonrpc_severities severity,
const char * message,
int count,
... )

Creates a jsonrpc response with facility, severity and a message phrase. A message phrase can include %{key} placeholders that are replaced on the client side with the value. Key/value pairs are variadic arguments.

Parameters
bufferpointer to already allocated sds string
cmd_idenum mympd_cmd_ids
request_idid of the jsonrpc request to answer
facilityone of enum jsonrpc_facilities
severityone of enum jsonrpc_severities
messagethe message to send
countnumber of following variadic arguments
...key/value pairs for the phrase
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_respond_ok()

sds jsonrpc_respond_ok ( sds buffer,
enum mympd_cmd_ids cmd_id,
unsigned request_id,
enum jsonrpc_facilities facility )

Creates a simple jsonrpc response with "ok" as message

Parameters
bufferpointer to already allocated sds string
cmd_idenum mympd_cmd_ids
request_idid of the jsonrpc request to answer
facilityone of enum jsonrpc_facilities
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_respond_start()

sds jsonrpc_respond_start ( sds buffer,
enum mympd_cmd_ids cmd_id,
unsigned request_id )

Creates the start of a jsonrpc response.

Parameters
bufferpointer to already allocated sds string
cmd_idenum mympd_cmd_ids
request_idid of the jsonrpc request to answer
Returns
pointer to buffer with jsonrpc string

◆ jsonrpc_respond_with_message_or_error()

sds jsonrpc_respond_with_message_or_error ( sds buffer,
enum mympd_cmd_ids cmd_id,
unsigned request_id,
bool rc,
enum jsonrpc_facilities facility,
const char * message,
const char * error )

Checks rc and responses with ok or the message

Parameters
bufferalready allocated sds string for the jsonrpc response
cmd_idenum mympd_cmd_ids
request_idjsonrpc request id to respond
rcreturn code to check
facilityone of enum jsonrpc_facilities
messagethe response message, if rc == true
errorthe response message, if rc == false
Returns
pointer to buffer

◆ jsonrpc_respond_with_ok_or_error()

sds jsonrpc_respond_with_ok_or_error ( sds buffer,
enum mympd_cmd_ids cmd_id,
unsigned request_id,
bool rc,
enum jsonrpc_facilities facility,
const char * error )

Checks rc and responses with ok or the message

Parameters
bufferalready allocated sds string for the jsonrpc response
cmd_idenum mympd_cmd_ids
request_idjsonrpc request id to respond
rcreturn code to check
facilityone of enum jsonrpc_facilities
errorthe response message, if rc == false
Returns
pointer to buffer

◆ send_jsonrpc_event()

void send_jsonrpc_event ( enum jsonrpc_events event,
const char * partition )

Creates and sends a jsonrpc event to all connected websockets

Parameters
eventthe event to send
partitionmpd partition

◆ send_jsonrpc_notify()

void send_jsonrpc_notify ( enum jsonrpc_facilities facility,
enum jsonrpc_severities severity,
const char * partition,
const char * message )

public functions Jsonrpc printing Creates and sends a jsonrpc notify to all connected websockets for a partition

Parameters
facilityone of enum jsonrpc_facilities
severityone of enum jsonrpc_severities
partitionmpd partition
messagethe message to send

◆ send_jsonrpc_notify_client()

void send_jsonrpc_notify_client ( enum jsonrpc_facilities facility,
enum jsonrpc_severities severity,
unsigned request_id,
const char * message )

Creates and sends a jsonrpc notify to a client

Parameters
facilityone of enum jsonrpc_facilities
severityone of enum jsonrpc_severities
request_idthe jsonrpc id of the client
messagethe message to send