2 * Copyright (C) 2012 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/>.
30 #include "_quvi_media_s.h"
32 #include "lua/load_util_script.h"
33 #include "lua/setfield.h"
36 static const gchar script_fname
[]= "resolve_redirections.lua";
37 static const gchar script_func
[] = "resolve_redirections";
39 /* Resolve URL redirections with exception rules. */
40 gchar
*l_exec_util_resolve_redirections(_quvi_t q
, const gchar
*url
)
45 q
->status
.rc
= l_load_util_script(q
, script_fname
, script_func
);
47 if (quvi_ok(q
) == QUVI_FALSE
)
51 l_setfield_s(l
, US_INPUT_URL
, url
, -1); /* Set as qargs.input_url */
54 * 1=qargs [qargs: set in l_load_util_script]
57 if (lua_pcall(l
, 1, 1, 0))
59 g_string_assign(q
->status
.errmsg
, lua_tostring(l
, -1));
61 /* Keep error code if it was set by a callback: quvi.resolve
62 * calling the network callback responsible for resolving URL
63 * redirections. The error is most likely a network error. */
64 if (q
->status
.rc
!= QUVI_ERROR_CALLBACK
)
65 q
->status
.rc
= QUVI_ERROR_SCRIPT
;
72 if (lua_isstring(l
, -1))
74 const gchar
*s
= lua_tostring(l
, -1);
75 if (g_strcmp0(s
, url
) != 0) /* Ignore, unless it is different. */
79 luaL_error(l
, "%s: did not return a string", script_func
);
83 /* quvi.resolve which is called from the script sets q->status.rc . */
87 /* vim: set ts=2 sw=2 tw=72 expandtab: */