diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2013-07-28 17:06:33 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2013-07-28 17:06:33 +0200 |
commit | 6e82d7e6852fdac4a178445b3e2bcdb6d4e0fa63 (patch) | |
tree | f588b7ca384efce0a86d7dfd6ac8b3bfaf5e5f5a | |
parent | 02b89aa2d2e0df87cb51bae8ffcbfb6439e474dc (diff) | |
download | pianobar-windows-6e82d7e6852fdac4a178445b3e2bcdb6d4e0fa63.tar.gz pianobar-windows-6e82d7e6852fdac4a178445b3e2bcdb6d4e0fa63.tar.bz2 pianobar-windows-6e82d7e6852fdac4a178445b3e2bcdb6d4e0fa63.zip |
piano: Replace station with same id
-rw-r--r-- | src/libpiano/response.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/libpiano/response.c b/src/libpiano/response.c index 1b63bee..ae7b140 100644 --- a/src/libpiano/response.c +++ b/src/libpiano/response.c @@ -438,15 +438,31 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) { PianoJsonParseStation (result, tmpStation); - /* start new linked list or append */ if (ph->stations == NULL) { ph->stations = tmpStation; } else { - PianoStation_t *curStation = ph->stations; + PianoStation_t *curStation = ph->stations, *prevStation = NULL; while (curStation->next != NULL) { + /* replace if station with same id exists already */ + if (strcmp (curStation->id, tmpStation->id) == 0) { + if (prevStation == NULL) { + ph->stations = tmpStation; + } else { + prevStation->next = tmpStation; + } + tmpStation->next = curStation->next; + + PianoDestroyStation (curStation); + free (curStation); + break; + } + prevStation = curStation; curStation = curStation->next; } - curStation->next = tmpStation; + /* append otherwise */ + if (tmpStation->next == NULL) { + curStation->next = tmpStation; + } } break; } |