libmpdclient 2.22
Enumerations | Functions
parser.h File Reference
#include "protocol.h"
#include "compiler.h"
#include <stdbool.h>
Include dependency graph for parser.h:

Go to the source code of this file.

Enumerations

enum  mpd_parser_result { MPD_PARSER_MALFORMED , MPD_PARSER_SUCCESS , MPD_PARSER_ERROR , MPD_PARSER_PAIR }
 

Functions

struct mpd_parsermpd_parser_new (void)
 
void mpd_parser_free (struct mpd_parser *parser)
 
enum mpd_parser_result mpd_parser_feed (struct mpd_parser *parser, char *line)
 
bool mpd_parser_is_discrete (const struct mpd_parser *parser)
 
enum mpd_server_error mpd_parser_get_server_error (const struct mpd_parser *parser)
 
unsigned mpd_parser_get_at (const struct mpd_parser *parser)
 
const char * mpd_parser_get_message (const struct mpd_parser *parser)
 
const char * mpd_parser_get_name (const struct mpd_parser *parser)
 
const char * mpd_parser_get_value (const struct mpd_parser *parser)
 

Enumeration Type Documentation

◆ mpd_parser_result

Enumerator
MPD_PARSER_MALFORMED 

Response line was not understood.

MPD_PARSER_SUCCESS 

MPD has returned "OK" or "list_OK" (check with mpd_parser_is_discrete()).

MPD_PARSER_ERROR 

MPD has returned "ACK" with an error code. Call mpd_parser_get_server_error() to get the error code.

MPD_PARSER_PAIR 

MPD has returned a name-value pair. Call mpd_parser_get_name() and mpd_parser_get_value().

Definition at line 12 of file parser.h.

Function Documentation

◆ mpd_parser_new()

struct mpd_parser * mpd_parser_new ( void  )

Allocates a new mpd_parser object. Returns NULL on error (out of memory).

◆ mpd_parser_free()

void mpd_parser_free ( struct mpd_parser parser)

Frees a mpd_parser object.

◆ mpd_parser_feed()

enum mpd_parser_result mpd_parser_feed ( struct mpd_parser parser,
char *  line 
)

Feeds a line (without the trailing newline character) received from MPD / mpd_async_recv_line() into the parser.

Note that the line parameter is writable, because the parser will modify it. The functions mpd_parser_get_name() and mpd_parser_get_value() will return pointers inside this buffer. This means that after passing the line to this function, you must not modify or free it, until the name and value pointers are not used anymore.

Parameters
parserthe mpd_parser object
linea line received from the MPD server
Returns
a result code indicating the type of line, or error

◆ mpd_parser_is_discrete()

bool mpd_parser_is_discrete ( const struct mpd_parser parser)

Call this when mpd_parser_feed() has returned MPD_PARSER_SUCCESS to find out whether this is an "OK" (false) or a "list_OK" (true) response.

Parameters
parserthe mpd_parser object

◆ mpd_parser_get_server_error()

enum mpd_server_error mpd_parser_get_server_error ( const struct mpd_parser parser)

Call this when mpd_parser_feed() has returned MPD_PARSER_ERROR to obtain the reason for the error.

Parameters
parserthe mpd_parser object

◆ mpd_parser_get_at()

unsigned mpd_parser_get_at ( const struct mpd_parser parser)

On MPD_PARSER_ERROR, this returns the number of the list command which failed. Don't call this outside of a command list.

Parameters
parserthe mpd_parser object

◆ mpd_parser_get_message()

const char * mpd_parser_get_message ( const struct mpd_parser parser)

On MPD_PARSER_ERROR, this returns the human readable error message returned by MPD (UTF-8).

This returns a pointer into the line buffer passed to mpd_parser_feed(). It is valid as long as the buffer is not freed/modified.

Parameters
parserthe mpd_parser object

◆ mpd_parser_get_name()

const char * mpd_parser_get_name ( const struct mpd_parser parser)

On MPD_PARSER_PAIR, this returns the name.

This returns a pointer into the line buffer passed to mpd_parser_feed(). It is valid as long as the buffer is not freed/modified.

Parameters
parserthe mpd_parser object

◆ mpd_parser_get_value()

const char * mpd_parser_get_value ( const struct mpd_parser parser)

On MPD_PARSER_PAIR, this returns the value.

This returns a pointer into the line buffer passed to mpd_parser_feed(). It is valid as long as the buffer is not freed/modified.

Parameters
parserthe mpd_parser object