From 7642b1c6d70ce44a659a0def647fc0604c10299e Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Tue, 2 Jun 2009 16:31:36 +0200 Subject: [PATCH] Use the new ANTLR parser for DAAP queries --- src/db-generic.h | 1 + src/db-sql.c | 17 ++++++++++++++--- src/httpd_daap.c | 43 +++++++++++++++---------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/db-generic.h b/src/db-generic.h index d36d7968..06bb7d1c 100644 --- a/src/db-generic.h +++ b/src/db-generic.h @@ -60,6 +60,7 @@ typedef struct tag_dbqueryinfo { int uri_count; int correct_order; char *uri_sections[10]; + char *filter; /* SQL WHERE clause */ PARSETREE pt; void *output_info; } DBQUERYINFO; diff --git a/src/db-sql.c b/src/db-sql.c index ef47cfda..2b6bafa6 100644 --- a/src/db-sql.c +++ b/src/db-sql.c @@ -1253,8 +1253,19 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) { } /* Apply the query/filter */ - if(pinfo->pt) { - DPRINTF(E_DBG,L_DB,"Got query/filter\n"); + if (pinfo->filter) { /* New parsers */ + DPRINTF(E_DBG, L_DB, "Got new-style query/filter\n"); + + if(have_clause) { + strcat(query_rest, " and "); + } else { + strcpy(query_rest, " where "); + have_clause = 1; + } + strcat(query_rest, pinfo->filter); + } + else if (pinfo->pt) { /* Old parsers (smart-parser.c) */ + DPRINTF(E_DBG,L_DB,"Got old-style query/filter\n"); filter = sp_sql_clause(pinfo->pt); if(filter) { if(have_clause) { @@ -1276,7 +1287,7 @@ int db_sql_enum_start(char **pe, DBQUERYINFO *pinfo) { /* disable empty */ if(browse) { - if((have_clause) || (pinfo->pt)) { + if((have_clause) || (pinfo->filter) || (pinfo->pt)) { strcat(query_rest," and ("); } else { strcpy(query_rest," where ("); diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 84f520a4..15958f73 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -625,22 +625,9 @@ get_query_params(struct evkeyvalq *query, DBQUERYINFO *qi) { DPRINTF(E_DBG, L_DAAP, "DAAP browse query filter: %s\n", param); - qi->pt = sp_init(); - if (!qi->pt) - { - DPRINTF(E_LOG, L_DAAP, "Could not init query filter\n"); - } - else - { - ret = sp_parse(qi->pt, param, FILTER_TYPE_APPLE); - if (ret != 1) - { - DPRINTF(E_LOG, L_DAAP, "Ignoring improper query: %s\n", sp_get_error(qi->pt)); - - sp_dispose(qi->pt); - qi->pt = NULL; - } - } + qi->filter = daap_query_parse_sql(param); + if (!qi->filter) + DPRINTF(E_LOG, L_DAAP, "Ignoring improper DAAP query\n"); } qi->want_count = 1; @@ -1099,8 +1086,8 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf, free(meta); evbuffer_free(song); evbuffer_free(songlist); - if (qi.pt) - sp_dispose(qi.pt); + if (qi.filter) + free(qi.filter); return; } @@ -1258,8 +1245,8 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf, evbuffer_free(song); - if (qi.pt) - sp_dispose(qi.pt); + if (qi.filter) + free(qi.filter); if (ret != DB_E_SUCCESS) { @@ -1440,8 +1427,8 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char ** free(meta); evbuffer_free(playlist); evbuffer_free(playlistlist); - if (qi.pt) - sp_dispose(qi.pt); + if (qi.filter) + free(qi.filter); return; } @@ -1522,8 +1509,8 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char ** free(meta); evbuffer_free(playlist); - if (qi.pt) - sp_dispose(qi.pt); + if (qi.filter) + free(qi.filter); if (ret != DB_E_SUCCESS) { @@ -1657,8 +1644,8 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri free(db_errmsg); evbuffer_free(itemlist); - if (qi.pt) - sp_dispose(qi.pt); + if (qi.filter) + free(qi.filter); return; } @@ -1670,8 +1657,8 @@ daap_reply_browse(struct evhttp_request *req, struct evbuffer *evbuf, char **uri dmap_add_string(itemlist, "mlit", *item); } - if (qi.pt) - sp_dispose(qi.pt); + if (qi.filter) + free(qi.filter); if (ret != DB_E_SUCCESS) {