00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include
00020 #include
00021 #include
00022 #include
00023 #include
00024
00025 #include "nntpgrab_internal.h"
00026 #include "nntpgrab_utils.h"
00027 #include "par2.h"
00028 #include "plugin_par2.h"
00029 #include "nntpgrab_plugin_par2.h"
00030
00031 static PluginPar2ExportedFuncs plugin_funcs;
00032
00033 typedef struct Par2Class Par2Class;
00034
00035 static GType par2_get_type (void);
00036
00037 struct Par2
00038 {
00039 GObject parent;
00040
00041 GStaticRWLock rwlock;
00042 };
00043
00044 struct Par2Class
00045 {
00046 GObjectClass parent;
00047 };
00048
00049 G_DEFINE_TYPE(Par2, par2, G_TYPE_OBJECT);
00050
00051 static void
00052 par2_init (Par2 *obj)
00053 {
00054 g_static_rw_lock_init(&obj->rwlock);
00055 }
00056
00057 static void
00058 par2_finalize (GObject *obj)
00059 {
00060 Par2 *par2 = PAR2(obj);
00061
00062 g_static_rw_lock_free(&par2->rwlock);
00063 }
00064
00065 static void
00066 par2_class_init (Par2Class *klass)
00067 {
00068 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
00069
00070 gobject_class->finalize = par2_finalize;
00071 }
00072
00073 gboolean
00074 par2_initialize(char **errmsg)
00075 {
00076 GModule *plugin = NULL;
00077 PluginPar2ImportedFuncs imported_funcs;
00078 plugin_par2_init_func init_func;
00079 char *filename;
00080
00081 #ifdef WIN32
00082 #define EXT "-0.dll"
00083 #else
00084 #define EXT ".so"
00085 #endif
00086
00087 if (g_getenv("NNTPGRAB_LIBDIR")) {
00088 filename = g_strdup_printf("%s/libnntpgrab_plugin_par2%s", g_getenv("NNTPGRAB_LIBDIR"), EXT);
00089 } else {
00090 filename = g_strdup_printf("%s/libnntpgrab_plugin_par2%s", PLUGIN_DIR, EXT);
00091 }
00092
00093 plugin = g_module_open(filename, G_MODULE_BIND_LOCAL);
00094
00095 g_free(filename);
00096
00097 if (!plugin) {
00098 if (errmsg) {
00099 *errmsg = g_strdup(g_module_error());
00100 }
00101
00102 return FALSE;
00103 }
00104
00105 imported_funcs.version = NNTPGRAB_PLUGIN_API_VERSION;
00106 #if 0
00107 imported_funcs.update_progress = update_progress_callback;
00108 imported_funcs.notify_download_complete = download_complete_callback;
00109 imported_funcs.notify_part_not_available = part_not_available_callback;
00110 imported_funcs.notify_connecting = connecting_callback;
00111 imported_funcs.notify_connected = connected_callback;
00112 imported_funcs.notify_disconnect = disconnect_callback;
00113 #endif
00114
00115 if (!g_module_symbol(plugin, "nntpgrab_plugin_par2_get_version", (gpointer *) &plugin_funcs.get_version)) {
00116 if (errmsg) {
00117 *errmsg = g_strdup(g_module_error());
00118 }
00119
00120 return FALSE;
00121 }
00122
00123 if (plugin_funcs.get_version() != NNTPGRAB_PLUGIN_API_VERSION) {
00124 if (errmsg) {
00125 *errmsg = g_strdup_printf(_("PAR2 Plugin API mismatch (Plugin API version = %i, expected = %i)"), plugin_funcs.get_version(), NNTPGRAB_PLUGIN_API_VERSION);
00126 }
00127
00128 return FALSE;
00129 }
00130
00131
00132 if (!g_module_symbol(plugin, "nntpgrab_plugin_par2_initialize", (gpointer *) &init_func)) {
00133 if (errmsg) {
00134 *errmsg = g_strdup(g_module_error());
00135 }
00136
00137 return FALSE;
00138 }
00139
00140 #if 0
00141 if (!g_module_symbol(plugin, "nntpgrab_plugin_decoder_decode_file", (gpointer *) &plugin_funcs.decode_file)) {
00142 if (errmsg) {
00143 *errmsg = g_strdup(g_module_error());
00144 }
00145
00146 return FALSE;
00147 }
00148 #endif
00149
00150 if (!init_func(imported_funcs)) {
00151 if (errmsg) {
00152 *errmsg = g_strdup(_("PAR2 Plugin initialization failed!"));
00153 }
00154
00155 return FALSE;
00156 }
00157
00158 nntpgrab_core_emit_debug_message(_("PAR2 plugin initialized"));
00159
00160 return TRUE;
00161 }
00162
00163 Par2 *
00164 par2_new(void)
00165 {
00166 Par2 *par2;
00167
00168 par2 = g_object_new(PAR2_TYPE_OBJECT, NULL);
00169
00170 return par2;
00171 }
00172
00173 void
00174 par2_destroy(Par2 *obj)
00175 {
00176 g_object_unref(obj);
00177 }
00178
00179 #if 0
00180 gboolean
00181 decoder_decode_file(Decoder *obj, const char *collection_name, const NNTPFile *file, int *saved_errno)
00182 {
00183 Decoder *decoder = DECODER(obj);
00184 ConfigOpts opts;
00185 char *msg;
00186 gboolean retval;
00187 char *errmsg = NULL;
00188
00189 msg = g_strdup_printf(_("Trying to decode file with from collection '%s' with subject = '%s'"), collection_name, file->subject);
00190 nntpgrab_core_emit_debug_message(msg);
00191 g_free(msg);
00192
00193 g_static_rw_lock_reader_lock(&decoder->rwlock);
00194
00195 opts = configuration_get_opts(decoder->config);
00196
00197 g_static_rw_lock_reader_unlock(&decoder->rwlock);
00198
00199 retval = plugin_funcs.decode_file(collection_name, file, opts.temp_directory, opts.download_directory, saved_errno, &errmsg);
00200
00201 if (!retval && errmsg) {
00202 char *filename = NULL;
00203
00204 nntpgrab_utils_strip_subject(file->subject, NULL, NULL, NULL, &filename, NULL, NULL, NULL, NULL, NULL, NULL);
00205 msg = g_strdup_printf(_("Decode of file '%s' failed:\n%s"), filename, errmsg);
00206 nntpgrab_core_emit_warning(msg);
00207
00208 g_free(filename);
00209 g_free(errmsg);
00210 }
00211
00212 msg = g_strdup_printf(_("Decoder returned %i"), retval);
00213 nntpgrab_core_emit_debug_message(msg);
00214 g_free(msg);
00215
00216 return retval;
00217 }
00218 #endif