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>
|
| 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
} |
| |
|
| 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_list * | parse_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) |
| |
◆ PCRE2_CODE_UNIT_WIDTH
| #define PCRE2_CODE_UNIT_WIDTH 8 |
◆ search_filters
◆ search_operators
Private definitions Search operators like them from MPD
◆ cmp_regex()
| static bool cmp_regex |
( |
pcre2_code * |
re_compiled, |
|
|
const char * |
value |
|
) |
| |
|
static |
Matches the regex against a string
- Parameters
-
| re_compiled | the compiled regex from compile_regex |
| value | string 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
-
- 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
-
| p | Pointer to start of operator in the expression |
| tag | Filter type |
| len | Set 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
-
| p | Pointer to start of expression |
| len | Set 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
-
| p | Pointer to start of expression |
| len | Set 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
-
| p | Pointer to start of value in the expression |
| end | Pointer to end of the expression |
| tag | Filter type |
| buf | Already allocated sds string to append the value |
| rc | Set to true on success, else false |
- Returns
- Pointer to buf
◆ expr_parse_value()
Parses the search expression value
- Parameters
-
| expr | The parsed search expression |
- Returns
- true on success, else false
◆ free_search_expression()
◆ free_search_expression_list()
| void free_search_expression_list |
( |
struct t_list * |
expr_list | ) |
|
Frees the search expression list
- Parameters
-
| expr_list | pointer 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
-
| current | pointer 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
-
| expression | mpd search expression |
| type | type of struct for the search expression |
- Returns
- list of the expression or NULL on error
◆ search_expression_album()
Implements search expressions for albums.
- Parameters
-
| album | pointer to album struct |
| expr_list | expression list returned by parse_search_expression |
| any_tag_types | tags 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
-
| song | pointer to mpd song struct |
| expr_list | expression list returned by parse_search_expression |
| any_tag_types | tags for special "any" tag in expression |
- Returns
- expression result
◆ search_expression_webradio()
Implements search expressions for webradios.
- Parameters
-
| webradio | pointer to webradio struct |
| expr_list | expression list returned by parse_search_expression |
| any_tag_types | tags for special "any" tag in expression |
- Returns
- expression result