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

Search implementation. More...

#include "compile_time.h"
#include "src/lib/search.h"
#include "dist/utf8/utf8.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_extras.h"
#include <ctype.h>
#include <inttypes.h>
#include <pcre2.h>
#include <string.h>
Include dependency graph for search.c:

Data Structures

struct  t_search_expression
 

Macros

#define PCRE2_CODE_UNIT_WIDTH   8
 

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
}
 
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 t_search_expression *expr)
 
static void free_search_expression_node (struct t_list_node *current)
 
static pcre2_code * compile_regex (char *regex_str)
 
static bool cmp_regex (pcre2_code *re_compiled, const char *value)
 
struct t_listparse_search_expression_to_list (const char *expression, enum search_type type)
 
void free_search_expression_list (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.

Macro Definition Documentation

◆ PCRE2_CODE_UNIT_WIDTH

#define PCRE2_CODE_UNIT_WIDTH   8

PCRE for UTF-8

Enumeration Type Documentation

◆ search_filters

Search filter types

◆ search_operators

Private definitions Search operators like them from MPD

Function Documentation

◆ cmp_regex()

static bool cmp_regex ( pcre2_code *  re_compiled,
const char *  value 
)
static

Matches the regex against a string

Parameters
re_compiledthe compiled regex from compile_regex
valuestring to match against
Returns
true if regex matches else false

◆ compile_regex()

static pcre2_code * compile_regex ( char *  regex_str)
static

Compiles a string to regex code

Parameters
regex_strregex string
Returns
regex code

◆ expr_get_op()

static 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()

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

Private functions 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()

static 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()

static 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()

static 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()

static void * free_search_expression ( struct t_search_expression expr)
static

Frees the t_search_expression struct

Parameters
exprpointer to t_search_expression struct
Returns
NULL

◆ free_search_expression_list()

void free_search_expression_list ( struct t_list expr_list)

Frees the search expression list

Parameters
expr_listpointer to the list

◆ free_search_expression_node()

static 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

◆ parse_search_expression_to_list()

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

Public functions Parses a mpd search expression

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

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