Pass lua_State arg to l_quvi_object_opts_croak_if_error
[libquvi.git] / src / api / scan_new.c
blob073e1f4d2f23a1bc065bbaa8d9ba59a6a85bf2be
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 /** @file scan_new.c */
23 #include "config.h"
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_net_s.h"
31 #include "_quvi_scan_s.h"
32 /* -- */
33 #include "net/handle.h"
34 #include "net/fetch.h"
35 #include "lua/exec.h"
36 #include "misc/scan_new.h"
38 /** @cond NODOC */
39 struct _exec_scan_script_s
41 struct
43 _quvi_scan_t scan;
44 _quvi_net_t net;
45 } handle;
48 typedef struct _exec_scan_script_s *_exec_scan_script_t;
50 static void _exec_scan_script(gpointer p, gpointer userdata)
52 _exec_scan_script_t ess = (_exec_scan_script_t) userdata;
53 _quvi_t q = (ess != NULL) ? ess->handle.scan->handle.quvi : NULL;
55 if (p == NULL || userdata == NULL)
56 return;
58 if (q->status.rc == QUVI_OK)
60 q->status.rc = l_exec_scan_script_parse(
61 ess->handle.scan, p,
62 ess->handle.net->fetch.content->str);
65 /** @endcond */
67 extern gint c_reset(_quvi_t);
69 /** @brief Scan URL contents for supported embedded media URLs
70 @return New handle, @ref quvi_scan_free it when done using it
71 @note
72 - Calling this function restores the current @ref sess_handle to its
73 initial state (cookies cleared, custom headers cleared, default
74 user-agent string restored, ...)
75 - Use @ref quvi_ok for checking if an error occurred
76 @sa @ref scan_media
77 @ingroup scan
79 quvi_scan_t quvi_scan_new(quvi_t handle, const char *url)
81 _quvi_t q = (_quvi_t) handle;
82 _quvi_scan_t qs = NULL;
84 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
85 g_return_val_if_fail(handle != NULL, NULL);
86 g_return_val_if_fail(url != NULL, NULL);
88 c_reset(q);
90 qs = m_scan_new(q, url);
92 _quvi_net_t n = NULL;
93 n_fetch(q, &n, qs->url.input->str, NULL);
95 if (quvi_ok(q) == QUVI_TRUE)
97 struct _exec_scan_script_s e;
99 e.handle.scan = qs;
100 e.handle.net = n;
102 g_slist_foreach(q->scripts.scan, _exec_scan_script, &e);
104 n_free(n);
105 n = NULL;
107 return (qs);
110 /* vim: set ts=2 sw=2 tw=72 expandtab: */