1 /* 2 * Copyright (c) 2017-2021 Free Software Foundation, Inc. 3 * 4 * This file is part of Wget. 5 * 6 * Wget 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, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Wget 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 General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Wget. If not, see <https://www.gnu.org/licenses/>. 18 * 19 * 20 * Plugin support implementation 21 * 22 */ 23 24 #ifndef SRC_WGET_PLUGIN_H 25 #define SRC_WGET_PLUGIN_H 26 27 #include <wget.h> 28 #include "wget_dl.h" 29 30 // Needed for fuzzers that are compiled by C++ 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 // Initializes the plugin framework 36 void plugin_db_init(void); 37 38 // Sets a list of directories to search for plugins, separated by 39 // _separator_. 40 void plugin_db_add_search_paths(const char *paths, char separator); 41 42 // Clears list of directories to search for plugins 43 void plugin_db_clear_search_paths(void); 44 45 // Extended plugin handle 46 typedef struct 47 { 48 wget_plugin parent; 49 50 // Plugin name 51 char *name; 52 // Object file associated with the plugin 53 dl_file_t *dm; 54 } plugin_t; 55 56 // Loads a plugin using its path. On failure it sets error and 57 // returns NULL. 58 plugin_t *plugin_db_load_from_path(const char *path, dl_error_t *e); 59 60 // Loads a plugin using its name. On failure it sets error and 61 // returns NULL. 62 plugin_t *plugin_db_load_from_name(const char *name, dl_error_t *e); 63 64 // Loads all plugins from environment variables. On any errors it 65 // logs them using wget_error_printf(). 66 int plugin_db_load_from_envvar(void); 67 68 // Creates a list of all plugins found in plugin search paths. 69 void plugin_db_list(wget_vector *names_out); 70 71 // Forwards a command line option to appropriate plugin. 72 // On errors, it returns -1 and sets error. Otherwise it returns 0. 73 int plugin_db_forward_option(const char *plugin_option, dl_error_t *e); 74 75 // Returns 1 if any of the previous options forwarded was 'help'. 76 int plugin_db_help_forwarded(void); 77 78 // Shows help from all loaded plugins 79 void plugin_db_show_help(void); 80 81 // Plugin's verdict on forwarded URLs 82 struct plugin_db_forward_url_verdict { 83 wget_iri *alt_iri; 84 char *alt_local_filename; 85 bool 86 reject : 1, 87 accept : 1; 88 }; 89 90 // Forwards a URL about to be enqueued to interested plugins 91 void plugin_db_forward_url(const wget_iri *iri, struct plugin_db_forward_url_verdict *verdict); 92 93 // Free's all contents of plugin_db_forward_url_verdict 94 void plugin_db_forward_url_verdict_free(struct plugin_db_forward_url_verdict *verdict); 95 96 // Forwards downloaded file to interested plugins 97 // Returns 0 if wget must not post-process the file, 1 otherwise 98 int plugin_db_forward_downloaded_file(const wget_iri *iri, int64_t size, const char *filename, const void *data, 99 wget_vector *recurse_iris); 100 101 // Sends 'finalize' signal to all plugins and unloads all plugins 102 void plugin_db_finalize(int exitcode); 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 #endif /* SRC_WGET_PLUGIN_H */ 109