Merge branch 'mongoose'
authorAndrew Karpow <andy@ndyk.de>
Tue, 18 Mar 2014 00:30:01 +0000 (01:30 +0100)
committerAndrew Karpow <andy@ndyk.de>
Tue, 18 Mar 2014 00:30:01 +0000 (01:30 +0100)
1  2 
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);
++}