_quvi_s: Add user_agent
[libquvi.git] / src / api / free.c
blobdf4af5b3e6164ad0a384a0a970d0c68fc041fa55
1 /* libquvi
2 * Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file free.c */
23 #include "config.h"
25 #include <lualib.h>
26 #include <proxy.h>
27 #include <glib.h>
29 #include "quvi.h"
30 /* -- */
31 #include "_quvi_s.h"
32 #include "_quvi_script_s.h"
33 /* -- */
34 #include "misc/script_free.h"
35 #include "misc/slst.h"
37 /** @cond NODOC */
38 extern void c_close(_quvi_t);
39 /** @endcond */
41 /** @brief Free all of memory used by a library handle
42 @note If handle is NULL the function simply returns
43 @sa @ref getting_started
44 @ingroup lib
46 void quvi_free(quvi_t handle)
48 _quvi_t q = (_quvi_t) handle;
50 if (handle == NULL)
51 return;
53 c_close(q);
55 /* Strings. */
57 g_string_free(q->opt.user_agent, TRUE);
58 q->opt.user_agent = NULL;
60 g_string_free(q->status.errmsg, TRUE);
61 q->status.errmsg = NULL;
63 /* Scripts. */
65 m_slist_free_full(q->scripts.subtitle_export, m_script_free);
66 q->scripts.subtitle_export = NULL;
68 m_slist_free_full(q->scripts.subtitle, m_script_free);
69 q->scripts.subtitle = NULL;
71 m_slist_free_full(q->scripts.playlist, m_script_free);
72 q->scripts.playlist = NULL;
74 m_slist_free_full(q->scripts.media, m_script_free);
75 q->scripts.media = NULL;
77 m_slist_free_full(q->scripts.scan, m_script_free);
78 q->scripts.scan = NULL;
80 m_slist_free_full(q->scripts.util, m_script_free);
81 q->scripts.util = NULL;
83 /* Handles. */
85 if (q->handle.lua != NULL)
87 lua_close(q->handle.lua);
88 q->handle.lua = NULL;
91 if (q->handle.proxy != NULL)
93 px_proxy_factory_free(q->handle.proxy);
94 q->handle.proxy = NULL;
97 g_free(q);
98 q = NULL;
101 /* vim: set ts=2 sw=2 tw=72 expandtab: */