l_quvi_http_fetch: Remove unused variable
[libquvi.git] / src / lua / quvi / http / fetch.c
blob76c39fd50324d0876a7a2e3eacfbd0c876d37873
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 <lauxlib.h>
24 #include <glib.h>
26 #include "quvi.h"
27 /* -- */
28 #include "_quvi_s.h"
29 #include "_quvi_net_s.h"
30 /* -- */
31 #include "lua/def.h"
32 #include "lua/getfield.h"
33 #include "lua/setfield.h"
34 #include "lua/quvi/opts.h"
35 #include "net/handle.h"
36 #include "net/fetch.h"
38 gint l_quvi_http_fetch(lua_State *l)
40 gboolean croak_if_error;
41 const gchar *url;
42 _quvi_net_t n;
43 GSList *opts;
44 _quvi_t q;
46 q = (_quvi_t) l_get_reg_userdata(l, USERDATA_QUVI_T);
47 n = NULL;
49 url = luaL_checkstring(l, 1);
50 lua_pop(l, 1);
52 opts = l_quvi_object_opts_new(l, 2);
53 croak_if_error = l_quvi_object_opts_croak_if_error(opts);
54 l_quvi_object_opts_curl(opts, q);
56 n_fetch(q, &n, url, opts);
58 lua_newtable(l);
59 l_setfield_n(l, QO_RESPONSE_CODE, q->status.resp_code);
60 l_setfield_n(l, QO_QUVI_CODE, q->status.rc);
61 l_setfield_s(l, QO_ERROR_MESSAGE, (q->status.rc != QUVI_OK)
62 ? q->status.errmsg->str
63 : MS_EMPTY, -1);
66 * The string (data) cannot contain embedded zeros; it is assumed
67 * to end at the first zero.
68 * -- http://pgl.yoyo.org/luai/i/lua_pushstring
71 if (quvi_ok(q) == QUVI_FALSE)
73 if (croak_if_error == TRUE)
74 luaL_error(l, "%s", q->status.errmsg->str);
76 l_setfield_s(l, QO_DATA, n->fetch.content->str, -1);
78 l_quvi_object_opts_free(opts);
79 n_free(n);
81 return (1); /* no. of returned values (one table) */
84 /* vim: set ts=2 sw=2 tw=72 expandtab: */