From aff2ce1e5755f87293135ebf9f3995313c05cec9 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 12 Jun 2008 15:53:54 +0200 Subject: lib: Split DestroyStations --- libpiano/main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'libpiano/main.c') diff --git a/libpiano/main.c b/libpiano/main.c index 52d7a1b..8ec19bb 100644 --- a/libpiano/main.c +++ b/libpiano/main.c @@ -84,6 +84,18 @@ void PianoDestroySearchResult (PianoSearchResult_t *searchResult) { } } +/* free single station + * @author PromyLOPh + * @added 2008-06-12 + * @public yes + * @param station + */ +void PianoDestroyStation (PianoStation_t *station) { + free (station->name); + free (station->id); + memset (station, 0, sizeof (station)); +} + /* free complete station list * @author PromyLOPh * @added 2008-06-09 @@ -94,11 +106,9 @@ void PianoDestroyStations (PianoHandle_t *ph) { curStation = ph->stations; while (curStation != NULL) { - free (curStation->name); - free (curStation->id); lastStation = curStation; curStation = curStation->next; - memset (lastStation, 0, sizeof (*lastStation)); + PianoDestroyStation (lastStation); free (lastStation); } ph->stations = NULL; -- cgit v1.2.3 From 8fe2fdd58acebf96c9fdacb4d13d63ff50a1f898 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 12 Jun 2008 16:06:56 +0200 Subject: lib: Delete station pointer when deleting station --- libpiano/main.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'libpiano/main.c') diff --git a/libpiano/main.c b/libpiano/main.c index 8ec19bb..17bef4b 100644 --- a/libpiano/main.c +++ b/libpiano/main.c @@ -384,7 +384,25 @@ PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station) { PianoHttpPost (ph->curlHandle, url, requestStr, &retStr); ret = PianoXmlParseSimple (retStr); - /* FIXME would be our job to delete station from global station list... */ + if (ret == PIANO_RET_OK) { + /* delete station from local station list */ + PianoStation_t *curStation = ph->stations, *lastStation = NULL; + while (curStation != NULL) { + if (curStation == station) { + printf ("deleting station\n"); + if (lastStation != NULL) { + lastStation->next = curStation->next; + } else { + /* first station in list */ + ph->stations = curStation->next; + } + PianoDestroyStation (curStation); + free (curStation); + } + lastStation = curStation; + curStation = curStation->next; + } + } free (requestStr); free (retStr); -- cgit v1.2.3