Remove 'query formats' feature
[libquvi.git] / src / api / free.c
blob049550a46256a3e63b3126c7e779d7ca9bd19138
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 /** @file free.c */
22 #include "config.h"
24 #include <lualib.h>
25 #include <proxy.h>
26 #include <glib.h>
28 #include "quvi.h"
29 /* -- */
30 #include "_quvi_s.h"
31 #include "_quvi_script_s.h"
32 /* -- */
33 #include "misc/script_free.h"
35 /** @cond NODOC */
36 extern void c_close(_quvi_t);
37 /** @endcond */
39 /** @brief Free all of memory used by a library handle
40 @note If handle is NULL the function simply returns
41 @sa @ref getting_started
42 @ingroup lib
44 void quvi_free(quvi_t handle)
46 _quvi_t q = (_quvi_t) handle;
48 if (handle == NULL)
49 return;
51 c_close(q);
53 /* Strings. */
55 g_string_free(q->status.errmsg, TRUE);
56 q->status.errmsg = NULL;
58 g_string_free(q->opt.format, TRUE);
59 q->opt.format = NULL;
61 /* Scripts. */
63 #ifdef HAVE_GLIB_2_28
64 g_slist_free_full(q->scripts.playlist, m_script_free);
65 #else
66 g_slist_foreach(q->scripts.playlist, m_script_free, NULL);
67 g_slist_free(q->scripts.playlist);
68 #endif
69 q->scripts.playlist = NULL;
71 #ifdef HAVE_GLIB_2_28
72 g_slist_free_full(q->scripts.media, m_script_free);
73 #else
74 g_slist_foreach(q->scripts.media, m_script_free, NULL);
75 g_slist_free(q->scripts.media);
76 #endif
77 q->scripts.media = NULL;
79 #ifdef HAVE_GLIB_2_28
80 g_slist_free_full(q->scripts.scan, m_script_free);
81 #else
82 g_slist_foreach(q->scripts.scan, m_script_free, NULL);
83 g_slist_free(q->scripts.scan);
84 #endif
85 q->scripts.scan = NULL;
87 #ifdef HAVE_GLIB_2_28
88 g_slist_free_full(q->scripts.util, m_script_free);
89 #else
90 g_slist_foreach(q->scripts.util, m_script_free, NULL);
91 g_slist_free(q->scripts.util);
92 #endif
93 q->scripts.util = NULL;
95 /* Handles. */
97 if (q->handle.lua != NULL)
99 lua_close(q->handle.lua);
100 q->handle.lua = NULL;
103 if (q->handle.proxy != NULL)
105 px_proxy_factory_free(q->handle.proxy);
106 q->handle.proxy = NULL;
109 g_free(q);
110 q = NULL;
113 /* vim: set ts=2 sw=2 tw=72 expandtab: */