1 /*
2  * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
3  *
4  * This file is part of NetSurf, http://www.netsurf-browser.org/
5  *
6  * NetSurf is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * NetSurf is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /**
20  * \file content/fetchers.h
21  *
22  * Interface for fetchers factory.
23  */
24 
25 #ifndef _NETSURF_DESKTOP_FETCHERS_H_
26 #define _NETSURF_DESKTOP_FETCHERS_H_
27 
28 #include "utils/inet.h" /* this is necessary for the fd_set definition */
29 #include <libwapcaplet/libwapcaplet.h>
30 
31 struct nsurl;
32 struct fetch_multipart_data;
33 struct fetch;
34 
35 /**
36  * Fetcher operations API
37  *
38  * These are the operations a fetcher must implement.
39  *
40  * Each fetcher is called once for initialisaion and finalisation.
41  * The poll entry point will be called to allow all active fetches to progress.
42  * The flow of a fetch operation is:
43  *   URL is checked for aceptability.
44  *   setup with all applicable data.
45  *   start is called before the first poll
46  *   after completion or abort it is freed
47  *
48  */
49 struct fetcher_operation_table {
50 	/**
51 	 * The initialiser for the fetcher.
52 	 *
53 	 * Called once to initialise the fetcher.
54 	 */
55 	bool (*initialise)(lwc_string *scheme);
56 
57 	/**
58 	 * Can this fetcher accept a url.
59 	 *
60 	 * \param url the URL to check
61 	 * \return true if the fetcher can handle the url else false.
62 	 */
63 	bool (*acceptable)(const struct nsurl *url);
64 
65 	/**
66 	 * Setup a fetch
67 	 */
68 	void *(*setup)(struct fetch *parent_fetch, struct nsurl *url,
69 		bool only_2xx, bool downgrade_tls, const char *post_urlenc,
70 		const struct fetch_multipart_data *post_multipart,
71 		const char **headers);
72 
73 	/**
74 	 * start a fetch.
75 	 */
76 	bool (*start)(void *fetch);
77 
78 	/**
79 	 * abort a fetch.
80 	 */
81 	void (*abort)(void *fetch);
82 
83 	/**
84 	 * free a fetch allocated through the setup method.
85 	 */
86 	void (*free)(void *fetch);
87 
88 	/**
89 	 * poll a fetcher to let it make progress.
90 	 */
91 	void (*poll)(lwc_string *scheme);
92 
93 	/**
94 	 * update an fdset with the FDs needed to poll cleanly
95 	 */
96 	int (*fdset)(lwc_string *scheme, fd_set *read_set, fd_set *write_set,
97 		     fd_set *error_set);
98 
99 	/**
100 	 * Finalise the fetcher.
101 	 */
102 	void (*finalise)(lwc_string *scheme);
103 };
104 
105 
106 /**
107  * Register a fetcher for a scheme
108  *
109  * \param scheme The scheme fetcher is for (caller relinquishes ownership)
110  * \param ops The operations for the fetcher.
111  * \return NSERROR_OK or appropriate error code.
112  */
113 nserror fetcher_add(lwc_string *scheme, const struct fetcher_operation_table *ops);
114 
115 
116 /**
117  * Initialise all registered fetchers.
118  *
119  * \return NSERROR_OK or error code
120  */
121 nserror fetcher_init(void);
122 
123 
124 /**
125  * Clean up for quit.
126  *
127  * Must be called before exiting.
128  */
129 void fetcher_quit(void);
130 
131 
132 #endif
133