From: Andrew Karpow Date: Tue, 18 Mar 2014 00:30:01 +0000 (+0100) Subject: Merge branch 'mongoose' X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=14e807850c9ce74d0aa948351cf70807599093e0;p=ympd.git Merge branch 'mongoose' --- 14e807850c9ce74d0aa948351cf70807599093e0 diff --cc src/mpd_client.c index 3c34ac5,6ab4174..10180af --- a/src/mpd_client.c +++ b/src/mpd_client.c @@@ -471,6 -500,56 +500,56 @@@ int mpd_put_browse(char *buffer, char * /* remove last ',' */ cur--; - cur += snprintf(cur, end - cur, "] }"); + + cur += json_emit_raw_str(cur, end - cur, "]}"); + return cur - buffer; + } + + int mpd_search(char *buffer, char *searchstr) + { + int i = 0; + char *cur = buffer; + const char *end = buffer + MAX_SIZE; + struct mpd_song *song; + + if(mpd_search_db_songs(mpd.conn, false) == false) + RETURN_ERROR_AND_RECOVER("mpd_search_db_songs"); + else if(mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false) + RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint"); + else if(mpd_search_commit(mpd.conn) == false) + RETURN_ERROR_AND_RECOVER("mpd_search_commit"); + else { + cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"search\",\"data\":[ "); + + while((song = mpd_recv_song(mpd.conn)) != NULL) { + cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":"); + cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song)); + cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); + cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); + cur += json_emit_raw_str(cur, end - cur, ",\"title\":"); + cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song)); + cur += json_emit_raw_str(cur, end - cur, "},"); + mpd_song_free(song); + + /* Maximum results */ + if(i++ >= 300) + { + cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},"); + break; + } + } + + /* remove last ',' */ + cur--; + + cur += json_emit_raw_str(cur, end - cur, "]}"); + } return cur - buffer; } + + + void mpd_disconnect() + { + mpd.conn_state = MPD_DISCONNECT; + mpd_poll(NULL); -} ++}