n_new, n_resolve_new: Escape URL for libcurl
[libquvi.git] / src / net / handle.c
blob0bc8a10c4e1b27b67d223c3943a9fcc3e94f0b5d
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 #include "config.h"
23 #include <lua.h>
24 #include <glib.h>
26 #include "quvi.h"
27 /* -- */
28 #include "_quvi_s.h"
29 #include "_quvi_net_s.h"
30 #include "_quvi_net_resolve_s.h"
31 /* -- */
32 #include "net/handle.h"
33 #include "misc/url.h"
35 static GString *_escaped(const gchar *url)
37 GString *r;
38 gchar *e;
40 /* Pass the URL in escaped form to libcurl. */
41 e = m_url_escaped_form(url);
42 r = g_string_new(e);
43 g_free(e);
45 return (r);
48 gpointer n_new(_quvi_t q, const gchar *url)
50 _quvi_net_t n = g_new0(struct _quvi_net_s, 1);
51 n->http_metainfo.content_type = g_string_new(NULL);
52 n->status.errmsg = g_string_new(NULL);
53 n->fetch.content = g_string_new(NULL);
54 n->url.addr = _escaped(url);
55 n->handle.quvi = q;
56 return (n);
59 void n_free(gpointer p)
61 _quvi_net_t n = (_quvi_net_t) p;
63 if (n == NULL)
64 return;
66 g_string_free(n->url.addr, TRUE);
67 n->url.addr = NULL;
69 g_string_free(n->status.errmsg, TRUE);
70 n->status.errmsg = NULL;
72 g_string_free(n->fetch.content, TRUE);
73 n->fetch.content = NULL;
75 g_string_free(n->http_metainfo.content_type, TRUE);
76 n->http_metainfo.content_type = NULL;
78 g_free(n);
79 n = NULL;
82 gpointer n_resolve_new(_quvi_t q, const gchar *url)
84 _quvi_net_resolve_t r = g_new0(struct _quvi_net_resolve_s, 1);
85 r->status.errmsg = g_string_new(NULL);
86 r->url.dst = g_string_new(NULL);
87 r->url.addr = _escaped(url);
88 r->handle.quvi = q;
89 return (r);
92 void n_resolve_free(gpointer p)
94 _quvi_net_resolve_t r = (_quvi_net_resolve_t) p;
96 g_string_free(r->status.errmsg, TRUE);
97 r->status.errmsg = NULL;
99 g_string_free(r->url.addr, TRUE);
100 r->url.addr = NULL;
102 g_string_free(r->url.dst, TRUE);
103 r->url.dst = NULL;
105 g_free(r);
106 r = NULL;
109 /* vim: set ts=2 sw=2 tw=72 expandtab: */