lua: exec_util_*.c: Revise comment
[libquvi.git] / src / lua / util / exec_util_to_file_ext.c
blob5bad31d583d6d148ac2f8895eadf9151dae6f1f2
1 /* libquvi
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/>.
21 #include "config.h"
23 #include <lauxlib.h>
24 #include <lualib.h>
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_http_metainfo_s.h"
31 #include "_quvi_net_s.h"
32 /* -- */
33 #include "lua/load_util_script.h"
35 static const gchar script_fname[]= "to_file_ext.lua";
36 static const gchar script_func[] = "to_file_ext";
38 QuviError l_exec_util_to_file_ext(_quvi_http_metainfo_t qmi, _quvi_net_t n)
40 lua_State *l;
41 QuviError rc;
42 _quvi_t q;
44 q = qmi->handle.quvi;
45 rc = l_load_util_script(q, script_fname, script_func);
47 if (rc != QUVI_OK)
48 return (rc);
50 l = q->handle.lua;
51 lua_pushstring(l, n->http_metainfo.content_type->str);
54 * 2=qargs,content-type [qargs: set in l_load_util_script]
55 * 1=returns a string
57 if (lua_pcall(l, 2, 1, 0))
59 g_string_assign(q->status.errmsg, lua_tostring(l, -1));
60 return (QUVI_ERROR_SCRIPT);
63 if (!lua_isstring(l, -1))
64 luaL_error(l, "%s: did not return a string", script_func);
66 g_string_assign(qmi->file_ext, lua_tostring(l,-1));
67 lua_pop(l, 1);
69 return (QUVI_OK);
72 /* vim: set ts=2 sw=2 tw=72 expandtab: */