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

Search implementation. More...

#include "src/lib/search/search.h"
#include "src/lib/convert.h"
#include "src/lib/datetime.h"
#include "src/lib/log.h"
#include "src/lib/mem.h"
#include "src/lib/sds/sds_extras.h"
#include "src/lib/search/search_fuzzy.h"
#include "src/lib/search/search_pcre.h"
#include "src/lib/utf8_wrapper.h"
#include <ctype.h>
#include <inttypes.h>
#include <string.h>
Include dependency graph for search.c:

Data Structures

struct  t_search_expression

Enumerations

enum  search_operators {
  SEARCH_OP_UNKNOWN = -1 , SEARCH_OP_EQUAL , SEARCH_OP_STARTS_WITH , SEARCH_OP_CONTAINS ,
  SEARCH_OP_NOT_EQUAL , SEARCH_OP_REGEX , SEARCH_OP_NOT_REGEX , SEARCH_OP_GREATER ,
  SEARCH_OP_GREATER_EQUAL , SEARCH_OP_FUZZY
}
enum  search_filters {
  SEARCH_FILTER_ANY_TAG = -2 , SEARCH_FILTER_MODIFIED_SINCE = -3 , SEARCH_FILTER_ADDED_SINCE = -4 , SEARCH_FILTER_FILE = -5 ,
  SEARCH_FILTER_BITRATE = -6 , SEARCH_FILTER_BASE = -7 , SEARCH_FILTER_PRIO = -8 , SEARCH_FILTER_AUDIO_FORMAT = -9
}

Functions

static int expr_get_tag_song (const char *p, size_t *len)
static int expr_get_tag_webradio (const char *p, size_t *len)
static int expr_get_op (const char *p, int tag, size_t *len)
static sds expr_get_value (const char *p, const char *end, int tag, sds buf, bool *rc)
static bool expr_parse_value (struct t_search_expression *expr)
static void * free_search_expression_struct (struct t_search_expression *expr)
static void free_search_expression_node (struct t_list_node *current)
static bool match_tag (const char *value, size_t value_len, struct t_search_expression *expr)
static bool exit_search_loop (bool rc, struct t_search_expression *expr)
struct t_listsearch_expression_parse (const char *expression, enum search_type type)
void search_expression_free (struct t_list *expr_list)
bool search_expression_song (const struct mpd_song *song, const struct t_list *expr_list, const struct t_mympd_mpd_tags *any_tag_types)
bool search_expression_album (const struct t_album *album, const struct t_list *expr_list, const struct t_mympd_mpd_tags *any_tag_types)
bool search_expression_webradio (const struct t_webradio_data *webradio, const struct t_list *expr_list, const struct t_webradio_tags *any_tag_types)

Detailed Description

Search implementation.

Enumeration Type Documentation

◆ search_filters

Search filter types

◆ search_operators

Private definitions Search operators like them from MPD

Function Documentation

◆ exit_search_loop()

bool exit_search_loop ( bool rc,
struct t_search_expression * expr )
static

Determines if the search loop can end

Parameters
rcResult of match_tag function
exprSearch expression
Returns
true if search loop can be prematurely exited, else false

◆ expr_get_op()

int expr_get_op ( const char * p,
int tag,
size_t * len )
static

Extracts the search operator

Parameters
pPointer to start of operator in the expression
tagFilter type
lenSet to count of bytes parsed
Returns
Search operator or -1 on error

◆ expr_get_tag_song()

int expr_get_tag_song ( const char * p,
size_t * len )
static

Extracts the tag from a song search expression

Parameters
pPointer to start of expression
lenSet to count of bytes parsed
Returns
MPD song tag, filter type or -1 on error

◆ expr_get_tag_webradio()

int expr_get_tag_webradio ( const char * p,
size_t * len )
static

Extracts the tag from a webradio search expression

Parameters
pPointer to start of expression
lenSet to count of bytes parsed
Returns
Webradio tag, filter type or -1 on error

◆ expr_get_value()

sds expr_get_value ( const char * p,
const char * end,
int tag,
sds buf,
bool * rc )
static

Extracts the value to search for

Parameters
pPointer to start of value in the expression
endPointer to end of the expression
tagFilter type
bufAlready allocated sds string to append the value
rcSet to true on success, else false
Returns
Pointer to buf

◆ expr_parse_value()

bool expr_parse_value ( struct t_search_expression * expr)
static

Parses the search expression value

Parameters
exprThe parsed search expression
Returns
true on success, else false

◆ free_search_expression_node()

void free_search_expression_node ( struct t_list_node * current)
static

Callback function for freeing a list node with t_search_expression user_data

Parameters
currentpointer to list node

◆ free_search_expression_struct()

void * free_search_expression_struct ( struct t_search_expression * expr)
static

Frees the t_search_expression struct

Parameters
exprpointer to t_search_expression struct
Returns
NULL

◆ match_tag()

bool match_tag ( const char * value,
size_t value_len,
struct t_search_expression * expr )
static

Private functions Search expression matching against a tag value

Parameters
valueValue to match search expression against
value_lenValue length
exprSearch expression
Returns
true if search expression matches, else false

◆ search_expression_album()

bool search_expression_album ( const struct t_album * album,
const struct t_list * expr_list,
const struct t_mympd_mpd_tags * any_tag_types )

Implements search expressions for albums.

Parameters
albumpointer to album struct
expr_listexpression list returned by parse_search_expression
any_tag_typestags for special "any" tag in expression
Returns
expression result

◆ search_expression_free()

void search_expression_free ( struct t_list * expr_list)

Frees the search expression list

Parameters
expr_listpointer to the list

◆ search_expression_parse()

struct t_list * search_expression_parse ( const char * expression,
enum search_type type )

Public functions Parses a mpd search expression string to a list

Parameters
expressionmpd search expression
typetype of struct for the search expression
Returns
list of the expression or NULL on error

◆ search_expression_song()

bool search_expression_song ( const struct mpd_song * song,
const struct t_list * expr_list,
const struct t_mympd_mpd_tags * any_tag_types )

Implements search expressions for mpd songs.

Parameters
songpointer to mpd song struct
expr_listexpression list returned by parse_search_expression
any_tag_typestags for special "any" tag in expression
Returns
expression result

◆ search_expression_webradio()

bool search_expression_webradio ( const struct t_webradio_data * webradio,
const struct t_list * expr_list,
const struct t_webradio_tags * any_tag_types )

Implements search expressions for webradios.

Parameters
webradiopointer to webradio struct
expr_listexpression list returned by parse_search_expression
any_tag_typestags for special "any" tag in expression
Returns
expression result