2 * Copyright (C) 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/>.
29 #include "_quvi_http_metainfo_s.h"
32 #include "lua/getfield.h"
33 #include "lua/setfield.h"
34 #include "lua/quvi/opts.h"
36 gint
l_quvi_http_metainfo(lua_State
*l
)
38 _quvi_http_metainfo_t qmi
;
39 gboolean croak_if_error
;
44 q
= (_quvi_t
) l_get_reg_userdata(l
, USERDATA_QUVI_T
);
46 url
= luaL_checkstring(l
, 1);
49 opts
= l_quvi_object_opts_new(l
, 2);
50 croak_if_error
= l_quvi_object_opts_croak_if_error(l
, opts
);
52 l_quvi_object_opts_curl(opts
, q
);
54 qmi
= quvi_http_metainfo_new(q
, url
);
57 l_setfield_n(l
, QO_RESPONSE_CODE
, q
->status
.resp_code
);
58 l_setfield_n(l
, QO_QUVI_CODE
, q
->status
.rc
);
59 l_setfield_s(l
, QO_ERROR_MESSAGE
, (q
->status
.rc
!= QUVI_OK
)
60 ? q
->status
.errmsg
->str
63 if (quvi_ok(q
) == QUVI_TRUE
)
65 l_setfield_s(l
, QO_CONTENT_TYPE
, qmi
->content_type
->str
, -1);
66 l_setfield_n(l
, QO_CONTENT_LENGTH
, qmi
->length_bytes
);
70 if (croak_if_error
== TRUE
)
71 luaL_error(l
, "%s", q
->status
.errmsg
->str
);
74 l_quvi_object_opts_free(opts
);
75 quvi_http_metainfo_free(qmi
);
77 return (1); /* no. of returned values (one table) */
80 /* vim: set ts=2 sw=2 tw=72 expandtab: */