mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-26 02:50:26 +00:00
Fix: error checking for smart playlist saving
This commit is contained in:
parent
afd030f6b6
commit
74991ac003
@ -270,25 +270,32 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
|||||||
break;
|
break;
|
||||||
case MPD_API_SMARTPLS_SAVE:
|
case MPD_API_SMARTPLS_SAVE:
|
||||||
je = json_scanf(msg.p, msg.len, "{data: {type: %Q}}", &p_charbuf1);
|
je = json_scanf(msg.p, msg.len, "{data: {type: %Q}}", &p_charbuf1);
|
||||||
|
n = 1;
|
||||||
if (je == 1) {
|
if (je == 1) {
|
||||||
if (strcmp(p_charbuf1, "sticker") == 0) {
|
if (strcmp(p_charbuf1, "sticker") == 0) {
|
||||||
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, sticker: %Q, maxentries: %d}}", &p_charbuf2, &p_charbuf3, &int_buf1);
|
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, sticker: %Q, maxentries: %d}}", &p_charbuf2, &p_charbuf3, &int_buf1);
|
||||||
|
if (je == 3) {
|
||||||
n = mympd_smartpls_save(p_charbuf1, p_charbuf2, p_charbuf3, NULL, int_buf1, 0);
|
n = mympd_smartpls_save(p_charbuf1, p_charbuf2, p_charbuf3, NULL, int_buf1, 0);
|
||||||
free(p_charbuf2);
|
free(p_charbuf2);
|
||||||
free(p_charbuf3);
|
free(p_charbuf3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (strcmp(p_charbuf1, "newest") == 0) {
|
else if (strcmp(p_charbuf1, "newest") == 0) {
|
||||||
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, timerange: %d}}", &p_charbuf2, &int_buf1);
|
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, timerange: %d}}", &p_charbuf2, &int_buf1);
|
||||||
|
if (je == 2) {
|
||||||
n = mympd_smartpls_save(p_charbuf1, p_charbuf2, NULL, NULL, 0, int_buf1);
|
n = mympd_smartpls_save(p_charbuf1, p_charbuf2, NULL, NULL, 0, int_buf1);
|
||||||
free(p_charbuf2);
|
free(p_charbuf2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (strcmp(p_charbuf1, "search") == 0) {
|
else if (strcmp(p_charbuf1, "search") == 0) {
|
||||||
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, tag: %Q, searchstr: %Q}}", &p_charbuf2, &p_charbuf3, &p_charbuf4);
|
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, tag: %Q, searchstr: %Q}}", &p_charbuf2, &p_charbuf3, &p_charbuf4);
|
||||||
|
if (je == 3) {
|
||||||
n = mympd_smartpls_save(p_charbuf1, p_charbuf2, p_charbuf3, p_charbuf4, 0, 0);
|
n = mympd_smartpls_save(p_charbuf1, p_charbuf2, p_charbuf3, p_charbuf4, 0, 0);
|
||||||
free(p_charbuf2);
|
free(p_charbuf2);
|
||||||
free(p_charbuf3);
|
free(p_charbuf3);
|
||||||
free(p_charbuf4);
|
free(p_charbuf4);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
free(p_charbuf1);
|
free(p_charbuf1);
|
||||||
}
|
}
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
@ -2602,28 +2609,46 @@ int mympd_smartpls_save(char *smartpltype, char *playlist, char *tag, char *sear
|
|||||||
snprintf(tmp_file, 400, "%s/tmp/%s", config.varlibdir, playlist);
|
snprintf(tmp_file, 400, "%s/tmp/%s", config.varlibdir, playlist);
|
||||||
snprintf(pl_file, 400, "%s/smartpls/%s", config.varlibdir, playlist);
|
snprintf(pl_file, 400, "%s/smartpls/%s", config.varlibdir, playlist);
|
||||||
if (strcmp(smartpltype, "sticker") == 0) {
|
if (strcmp(smartpltype, "sticker") == 0) {
|
||||||
if (json_fprintf(tmp_file, "{type: %Q, sticker: %Q, maxentries: %d}", smartpltype, tag, maxentries) == -1)
|
if (json_fprintf(tmp_file, "{type: %Q, sticker: %Q, maxentries: %d}", smartpltype, tag, maxentries) == -1) {
|
||||||
printf("Error creating file %s\n", tmp_file);
|
printf("Error creating file %s\n", tmp_file);
|
||||||
else if (rename(tmp_file, pl_file) == -1)
|
return 1;
|
||||||
|
}
|
||||||
|
else if (rename(tmp_file, pl_file) == -1) {
|
||||||
printf("Error renaming file from %s to %s\n", tmp_file, pl_file);
|
printf("Error renaming file from %s to %s\n", tmp_file, pl_file);
|
||||||
else
|
return 1;
|
||||||
mympd_smartpls_update_sticker(playlist, tag, maxentries);
|
}
|
||||||
|
else if (mympd_smartpls_update_sticker(playlist, tag, maxentries) == 1) {
|
||||||
|
printf("Update of smart playlist %s failed.\n", playlist);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(smartpltype, "newest") == 0) {
|
else if (strcmp(smartpltype, "newest") == 0) {
|
||||||
if (json_fprintf(tmp_file, "{type: %Q, timerange: %d}", smartpltype, timerange) == -1)
|
if (json_fprintf(tmp_file, "{type: %Q, timerange: %d}", smartpltype, timerange) == -1) {
|
||||||
printf("Error creating file %s\n", tmp_file);
|
printf("Error creating file %s\n", tmp_file);
|
||||||
else if (rename(tmp_file, pl_file) == -1)
|
return 1;
|
||||||
|
}
|
||||||
|
else if (rename(tmp_file, pl_file) == -1) {
|
||||||
printf("Error renaming file from %s to %s\n", tmp_file, pl_file);
|
printf("Error renaming file from %s to %s\n", tmp_file, pl_file);
|
||||||
else
|
return 1;
|
||||||
mympd_smartpls_update_newest(playlist, timerange);
|
}
|
||||||
|
else if (mympd_smartpls_update_newest(playlist, timerange) == 1) {
|
||||||
|
printf("Update of smart playlist %s failed.\n", playlist);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(smartpltype, "search") == 0) {
|
else if (strcmp(smartpltype, "search") == 0) {
|
||||||
if (json_fprintf(tmp_file, "{type: %Q, tag: %Q, searchstr: %Q}", smartpltype, tag, searchstr) == -1)
|
if (json_fprintf(tmp_file, "{type: %Q, tag: %Q, searchstr: %Q}", smartpltype, tag, searchstr) == -1) {
|
||||||
printf("Error creating file %s\n", tmp_file);
|
printf("Error creating file %s\n", tmp_file);
|
||||||
else if (rename(tmp_file, pl_file) == -1)
|
return 1;
|
||||||
|
}
|
||||||
|
else if (rename(tmp_file, pl_file) == -1) {
|
||||||
printf("Error renaming file from %s to %s\n", tmp_file, pl_file);
|
printf("Error renaming file from %s to %s\n", tmp_file, pl_file);
|
||||||
else
|
return 1;
|
||||||
mympd_smartpls_update_search(playlist, tag, searchstr);
|
}
|
||||||
|
else if (mympd_smartpls_update_search(playlist, tag, searchstr) == 1) {
|
||||||
|
printf("Update of smart playlist %s failed.\n", playlist);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user