mirror of
https://github.com/SuperBFG7/ympd
synced 2025-12-01 04:08:05 +00:00
fix: source code formating
This commit is contained in:
@@ -46,7 +46,7 @@ const char * mpd_cmd_strs[] = {
|
||||
static inline enum mpd_cmd_ids get_cmd_id(const char *cmd)
|
||||
{
|
||||
for(int i = 0; i < sizeof(mpd_cmd_strs)/sizeof(mpd_cmd_strs[0]); i++)
|
||||
if(!strncmp(cmd, mpd_cmd_strs[i], strlen(mpd_cmd_strs[i])))
|
||||
if (!strncmp(cmd, mpd_cmd_strs[i], strlen(mpd_cmd_strs[i])))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
@@ -73,7 +73,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg)
|
||||
else
|
||||
cmd_id = get_cmd_id("MPD_API_UNKNOWN");
|
||||
|
||||
if(cmd_id == -1)
|
||||
if (cmd_id == -1)
|
||||
cmd_id = get_cmd_id("MPD_API_UNKNOWN");
|
||||
|
||||
switch(cmd_id) {
|
||||
@@ -342,7 +342,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg)
|
||||
je = json_scanf(msg.p, msg.len, "{ data: { uri:%Q } }", &p_charbuf1);
|
||||
if (je == 1) {
|
||||
int_buf = mpd_run_add_id(mpd.conn, p_charbuf1);
|
||||
if(int_buf != -1)
|
||||
if (int_buf != -1)
|
||||
mpd_run_play_id(mpd.conn, int_buf);
|
||||
free(p_charbuf1);
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
@@ -479,12 +479,12 @@ static int mympd_notify_callback(struct mg_connection *c, const char *param) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!c->user_data)
|
||||
if (!c->user_data)
|
||||
c->user_data = calloc(1, sizeof(struct t_mpd_client_session));
|
||||
|
||||
struct t_mpd_client_session *s = (struct t_mpd_client_session *)c->user_data;
|
||||
|
||||
if(mpd.conn_state != MPD_CONNECTED) {
|
||||
if (mpd.conn_state != MPD_CONNECTED) {
|
||||
n=snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"disconnected\"}");
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout,"Notify: disconnected\n");
|
||||
@@ -497,7 +497,7 @@ static int mympd_notify_callback(struct mg_connection *c, const char *param) {
|
||||
#endif
|
||||
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, mpd.buf, strlen(mpd.buf));
|
||||
|
||||
if(s->song_id != mpd.song_id) {
|
||||
if (s->song_id != mpd.song_id) {
|
||||
n=mympd_put_current_song(mpd.buf);
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout,"Notify: %s\n",mpd.buf);
|
||||
@@ -506,7 +506,7 @@ static int mympd_notify_callback(struct mg_connection *c, const char *param) {
|
||||
s->song_id = mpd.song_id;
|
||||
}
|
||||
|
||||
if(s->queue_version != mpd.queue_version) {
|
||||
if (s->queue_version != mpd.queue_version) {
|
||||
n=snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"update_queue\"}");
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout,"Notify: update_queue\n");
|
||||
@@ -539,7 +539,7 @@ void mympd_poll(struct mg_mgr *s) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(mpd.password && !mpd_run_password(mpd.conn, mpd.password)) {
|
||||
if (mpd.password && !mpd_run_password(mpd.conn, mpd.password)) {
|
||||
fprintf(stderr, "MPD connection: %s\n", mpd_connection_get_error_message(mpd.conn));
|
||||
for (struct mg_connection *c = mg_next(s, NULL); c != NULL; c = mg_next(s, c)) {
|
||||
mympd_notify_callback(c, mpd_connection_get_error_message(mpd.conn));
|
||||
@@ -558,7 +558,7 @@ void mympd_poll(struct mg_mgr *s) {
|
||||
|
||||
case MPD_DISCONNECT:
|
||||
case MPD_RECONNECT:
|
||||
if(mpd.conn != NULL)
|
||||
if (mpd.conn != NULL)
|
||||
mpd_connection_free(mpd.conn);
|
||||
mpd.conn = NULL;
|
||||
mpd.conn_state = MPD_DISCONNECTED;
|
||||
@@ -670,7 +670,7 @@ int mympd_put_settings(char *buffer) {
|
||||
int je;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
struct mympd_state { int a; int b; } state = { .a = 0, .b = 0 };
|
||||
if( access( mpd.statefile, F_OK ) != -1 ) {
|
||||
if (access( mpd.statefile, F_OK ) != -1 ) {
|
||||
char *content = json_fread(mpd.statefile);
|
||||
je = json_scanf(content, strlen(content), "{notificationWeb: %d, notificationPage: %d}", &state.a, &state.b);
|
||||
if (je != 2) {
|
||||
@@ -906,7 +906,7 @@ int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter
|
||||
const struct mpd_song *song;
|
||||
const struct mpd_directory *dir;
|
||||
entity_count ++;
|
||||
if(entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
switch (mpd_entity_get_type(entity)) {
|
||||
case MPD_ENTITY_TYPE_UNKNOWN:
|
||||
entity_count --;
|
||||
@@ -1003,7 +1003,7 @@ int mympd_put_db_tag(char *buffer, unsigned int offset, char *mpdtagtype, char *
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
if(mpd_search_db_tags(mpd.conn, mpd_tag_name_parse(mpdtagtype)) == false)
|
||||
if (mpd_search_db_tags(mpd.conn, mpd_tag_name_parse(mpdtagtype)) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_db_tags");
|
||||
|
||||
if (mpd_tag_name_parse(mpdsearchtagtype) != MPD_TAG_UNKNOWN) {
|
||||
@@ -1011,13 +1011,13 @@ int mympd_put_db_tag(char *buffer, unsigned int offset, char *mpdtagtype, char *
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint");
|
||||
}
|
||||
|
||||
if(mpd_search_commit(mpd.conn) == false)
|
||||
if (mpd_search_commit(mpd.conn) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_commit");
|
||||
|
||||
len = json_printf(&out, "{type: listDBtags, data: [ ");
|
||||
while((pair = mpd_recv_pair_tag(mpd.conn, mpd_tag_name_parse(mpdtagtype))) != NULL) {
|
||||
entity_count ++;
|
||||
if(entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (strncmp(filter,"-",1) == 0 || strncasecmp(filter,pair->value,1) == 0 ||
|
||||
( strncmp(filter,"0",1) == 0 && isalpha(*pair->value) == 0 )
|
||||
) {
|
||||
@@ -1056,7 +1056,7 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album) {
|
||||
char cover[500];
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
if(mpd_search_db_songs(mpd.conn, true) == false) {
|
||||
if (mpd_search_db_songs(mpd.conn, true) == false) {
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_db_songs");
|
||||
}
|
||||
|
||||
@@ -1066,14 +1066,14 @@ int mympd_put_songs_in_album(char *buffer, char *albumartist, char *album) {
|
||||
if (mpd_search_add_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, MPD_TAG_ALBUM, album) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint");
|
||||
|
||||
if(mpd_search_commit(mpd.conn) == false)
|
||||
if (mpd_search_commit(mpd.conn) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_commit");
|
||||
else {
|
||||
len = json_printf(&out, "{ type: listTitles, data: [ ");
|
||||
|
||||
while((song = mpd_recv_song(mpd.conn)) != NULL) {
|
||||
entity_count ++;
|
||||
if(entity_count <= MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entity_count <= MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entities_returned ++) len += json_printf(&out, ", ");
|
||||
else mympd_get_cover(mpd_song_get_uri(song),cover,500);
|
||||
len += json_printf(&out, "{ type: song, uri: %Q, duration: %d, title: %Q, track: %Q }",
|
||||
@@ -1114,7 +1114,7 @@ int mympd_put_playlists(char *buffer, unsigned int offset, char *filter) {
|
||||
|
||||
while((pl = mpd_recv_playlist(mpd.conn)) != NULL) {
|
||||
entity_count ++;
|
||||
if(entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
plpath = mpd_playlist_get_path(pl);
|
||||
if (strncmp(filter,"-",1) == 0 || strncasecmp(filter,plpath,1) == 0 ||
|
||||
( strncmp(filter,"0",1) == 0 && isalpha(*plpath) == 0 )
|
||||
@@ -1203,9 +1203,8 @@ int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *sear
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
if(mpd_search_db_songs(mpd.conn, false) == false) {
|
||||
if (mpd_search_db_songs(mpd.conn, false) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_db_songs");
|
||||
}
|
||||
|
||||
if (mpd_tag_name_parse(mpdtagtype) != MPD_TAG_UNKNOWN) {
|
||||
if (mpd_search_add_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, mpd_tag_name_parse(mpdtagtype), searchstr) == false)
|
||||
@@ -1216,14 +1215,14 @@ int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *sear
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
|
||||
}
|
||||
|
||||
if(mpd_search_commit(mpd.conn) == false)
|
||||
if (mpd_search_commit(mpd.conn) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_commit");
|
||||
else {
|
||||
len = json_printf(&out, "{ type: search, data: [ ");
|
||||
|
||||
while((song = mpd_recv_song(mpd.conn)) != NULL) {
|
||||
entity_count ++;
|
||||
if(entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entities_returned ++) len += json_printf(&out, ", ");
|
||||
len += json_printf(&out, "{ type: song, uri: %Q, album: %Q, artist: %Q, duration: %d, title: %Q, name: %Q }",
|
||||
mpd_song_get_uri(song),
|
||||
@@ -1256,7 +1255,7 @@ int mympd_search_add(char *buffer,char *mpdtagtype, char *searchstr) {
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
len = 0;
|
||||
|
||||
if(mpd_search_add_db_songs(mpd.conn, false) == false) {
|
||||
if (mpd_search_add_db_songs(mpd.conn, false) == false) {
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_db_songs");
|
||||
}
|
||||
|
||||
@@ -1269,7 +1268,7 @@ int mympd_search_add(char *buffer,char *mpdtagtype, char *searchstr) {
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
|
||||
}
|
||||
|
||||
if(mpd_search_commit(mpd.conn) == false)
|
||||
if (mpd_search_commit(mpd.conn) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_commit");
|
||||
|
||||
while((song = mpd_recv_song(mpd.conn)) != NULL) {
|
||||
@@ -1288,7 +1287,7 @@ int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
if(mpd_search_queue_songs(mpd.conn, false) == false) {
|
||||
if (mpd_search_queue_songs(mpd.conn, false) == false) {
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_queue_songs");
|
||||
}
|
||||
|
||||
@@ -1301,14 +1300,14 @@ int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
|
||||
}
|
||||
|
||||
if(mpd_search_commit(mpd.conn) == false)
|
||||
if (mpd_search_commit(mpd.conn) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_commit");
|
||||
else {
|
||||
len = json_printf(&out, "{ type: queuesearch, data: [ ");
|
||||
|
||||
while((song = mpd_recv_song(mpd.conn)) != NULL) {
|
||||
entity_count ++;
|
||||
if(entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entity_count > offset && entity_count <= offset+MAX_ELEMENTS_PER_PAGE) {
|
||||
if (entities_returned ++) len += json_printf(&out, ", ");
|
||||
len += json_printf(&out, "{ type: song, id: %d, pos: %d, album: %Q, artist: %Q, duration: %d, title: %Q }",
|
||||
mpd_song_get_id(song),
|
||||
|
||||
@@ -249,7 +249,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if(run_as_user != NULL) {
|
||||
if (run_as_user != NULL) {
|
||||
printf("Droping privileges\n");
|
||||
struct passwd *pw;
|
||||
if ((pw = getpwnam(run_as_user)) == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user