Statistics
| Revision:

root / trunk / nntpgrab_core / nntpgrab.h @ 1853

History | View | Annotate | Download (19.2 KB)

1
/* 
2
    Copyright (C) 2005-2010  Erik van Pienbroek
3

                
4
    This program is free software; you can redistribute it and/or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation; either version 2 of the License, or
7
    (at your option) any later version.
8

                
9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU General Public License for more details.
13

                
14
    You should have received a copy of the GNU General Public License
15
    along with this program; if not, write to the Free Software
16
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
*/
18

                
19
#ifndef _NNTPGRAB_H_
20
#define _NNTPGRAB_H_
21

                
22
#include "nntpgrab_types.h"
23

                
24
#ifdef  __cplusplus
25
extern "C" {
26
#endif
27

                
28
#define NNTPGRAB_API_VERSION    20110712
29

                
30
#define NNTPGRAB_TYPE_CORE              (nntpgrab_core_get_type ())
31
#define NNTPGRAB_CORE(object)           (NG_TYPE_CHECK_INSTANCE_CAST ((object), NNTPGRAB_TYPE_CORE, NntpgrabCore))
32
#define NNTPGRAB_CORE_CLASS(klass)      (NG_TYPE_CHECK_CLASS_CAST ((klass), NNTPGRAB_TYPE_CORE, NntpgrabCoreClass))
33
#define IS_NNTPGRAB_CORE(object)        (NG_TYPE_CHECK_INSTANCE_TYPE ((object), NNTPGRAB_TYPE_CORE))
34
#define IS_NNTPGRAB_CORE_CLASS(klass)   (NG_TYPE_CHECK_CLASS_TYPE ((klass), NNTPGRAB_TYPE_CORE))
35
#define NNTPGRAB_CORE_GET_CLASS(obj)    (NG_TYPE_INSTANCE_GET_CLASS ((obj), NNTPGRAB_TYPE_CORE, NntpgrabCoreClass))
36

                
37
typedef struct NntpgrabCore NntpgrabCore;
38
typedef struct NntpgrabCoreClass NntpgrabCoreClass;
39

                
40
NGType nntpgrab_core_get_type(void);
41

                
42
/** 
43
 * nntpgrab_core_new:
44
 *
45
 * Creates a new instance of the NntpgrabCore object. This is required for all other NNTPGrab functions
46
 *
47
 * Return value: An instance of the NntpgrabCore which need to be used for other NNTPGrab functions
48
 */
49
NntpgrabCore   *nntpgrab_core_new(void);
50

                
51
/** 
52
 * nntpgrab_core_init:
53
 * @obj:                          An instance of the NntpgrabCore
54
 * @version:                      Needs to be NNTPGRAB_API_VERSION, this is used to prevent version conflicts
55
 * @err:      (out) (allow-none): Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
56
 * @warnings: (out) (allow-none): Pointer to a char*. If an (non-fatal) warning occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
57
 *
58
 * Initialize the NNTPGrab Core library. This function needs to be called before any other NNTPGrab functions can be called
59
 * Note that even if this function returns TRUE, the warnings argument MAY be set
60
 *
61
 * Return value:                  TRUE on success, FALSE if an error has occured (the reason is saved in the err variable)
62
 */
63
ngboolean        nntpgrab_core_init(NntpgrabCore *obj, int version, char **err, char **warnings);
64

                
65
/** 
66
 * nntpgrab_core_destroy: (skip)
67
 * @obj:        An instance of the NntpgrabCore
68
 *
69
 * Cleanup the NNTPGrab Core library. After this function is called, the NntpgrabCore instance can't be used anymore
70
 */
71
void            nntpgrab_core_destroy(NntpgrabCore *obj);
72

                
73
/** 
74
 * nntpgrab_core_config_get_avail_servers:
75
 * @obj:        An instance of the NntpgrabCore
76
 *
77
 * Retrieve a list of the available usenet servers
78
 *
79
 * Return value: (transfer full) (element-type utf8): A list of all the available usenet servers. Needs to be freed using nntpgrab_config_free_avail_servers()
80
 */
81
NGList         *nntpgrab_core_config_get_avail_servers(NntpgrabCore *obj);
82

                
83
/** 
84
 * nntpgrab_core_config_free_avail_servers: (skip)
85
 * @obj:           An instance of the NntpgrabCore
86
 * @servers:       A list of the available usenet servers as returned from the function nntpgrab_config_get_avail_servers()
87
 *
88
 * Free the list of available usenet servers
89
 */
90
void            nntpgrab_core_config_free_avail_servers(NntpgrabCore *obj, NGList *servers);
91

                
92
/** 
93
 * nntpgrab_core_config_get_server_info:
94
 * @obj:                An instance of the NntpgrabCore
95
 * @servername:         The name of the server whose details should be retrieved
96
 * @server:     (out):  The address of a ConfigServer structure which will be used to fill in the configuration details
97
 *
98
 * Get the configuration details about a specific usenet server
99
 *
100
 * Returns:              TRUE on success (server will be filled in), FALSE if the server isn't known
101
 */
102
ngboolean       nntpgrab_core_config_get_server_info(NntpgrabCore *obj, const char *servername, NGConfigServer *server);
103

                
104
/** 
105
 * nntpgrab_core_config_add_server:
106
 * @obj:                             An instance of the NntpgrabCore
107
 * @new_server:                      A structure containing the details about the new usenet server
108
 * @errmsg:     (allow-none) (out):  Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
109
 *
110
 * Add a new usenet server to the NNTPGrab configuration
111
 *
112
 * Returns:                          TRUE when the server was successfully added. FALSE on failure (the reason will be placed in the errmsg field)
113
 */
114
ngboolean       nntpgrab_core_config_add_server(NntpgrabCore *obj, NGConfigServer new_server, char **errmsg);
115

                
116
/** 
117
 * nntpgrab_core_config_del_server:
118
 * @obj:                            An instance of the NntpgrabCore
119
 * @servername:                     The name of the server whose entry should be removed
120
 * @errmsg:    (allow-none) (out):  Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
121
 *
122
 * Remove a usenet server from the NNTPGrab configuration
123
 *
124
 * Returns:                         TRUE when the server was successfully removed. FALSE on failure (the reason will be placed in the errmsg field)
125
 */
126
ngboolean       nntpgrab_core_config_del_server(NntpgrabCore *obj, const char *servername, char **errmsg);
127

                
128
/** 
129
 * nntpgrab_core_config_edit_server:
130
 * @obj:                             An instance of the NntpgrabCore
131
 * @servername:                      The name of the server whose entry should be adjusted
132
 * @server:                          A structure containing the new configuration details of the given servername
133
 * @errmsg:     (allow-none) (out):  Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
134
 *
135
 * Adjust the configuration details of an usenet server
136
 *
137
 * Returns:                          TRUE when the server was successfully adjusted. FALSE on failure (the reason will be placed in the errmsg field)
138
 */
139
ngboolean       nntpgrab_core_config_edit_server(NntpgrabCore *obj, const char *servername, NGConfigServer server, char **errmsg);
140

                
141
/** 
142
 * nntpgrab_core_config_get_opts:
143
 * @obj:           An instance of the NntpgrabCore
144
 *
145
 * Retrieve the general configuration options
146
 *
147
 * Returns:        A structure containing the general configuration options
148
 */
149
NGConfigOpts    nntpgrab_core_config_get_opts(NntpgrabCore *obj);
150

                
151
/** 
152
 * nntpgrab_core_config_set_opts:
153
 * @obj:           An instance of the NntpgrabCore
154
 * @opts:          A structure containing the new general configuration options
155
 *
156
 * Adjust the general configuration options
157
 */
158
void            nntpgrab_core_config_set_opts(NntpgrabCore *obj, NGConfigOpts opts);
159

                
160
/** 
161
 * nntpgrab_core_schedular_start:
162
 * @obj:    An instance of the NntpgrabCore
163
 *
164
 * Start the NNTPGrab schedular
165
 *
166
 * Returns: TRUE is the schedular was successfully started, FALSE if the schedular was already running or in the 'stopping' state
167
 */
168
ngboolean       nntpgrab_core_schedular_start(NntpgrabCore *obj);
169

                
170
/** 
171
 * nntpgrab_core_schedular_stop:
172
 * @obj:     An instance of the NntpgrabCore
173
 * @wait:    Whether this function should wait until the schedular really has stopped
174
 *
175
 * Stop the NNTPGrab schedular
176
 *
177
 * Returns:  TRUE is schedular was successfully stopped, FALSE if the schedular was already stopped or the in 'stopping' state
178
 */
179
ngboolean       nntpgrab_core_schedular_stop(NntpgrabCore *obj, ngboolean wait);
180

                
181
/** 
182
 * nntpgrab_core_schedular_get_state:
183
 * @obj:     An instance of the NntpgrabCore
184
 *
185
 * Retrieve the current state of the schedular
186
 *
187
 * Returns:  The current state of the schedular
188
 */
189
NGSchedularState nntpgrab_core_schedular_get_state(NntpgrabCore *obj);
190

                
191
/** 
192
 * nntpgrab_core_schedular_add_task_to_queue:
193
 * @obj:                                          An instance of the NntpgrabCore
194
 * @collection_name:                              The name of the collection in which this task should be added. If there is no collection in the download queue with the given name, it will automatically be created
195
 * @subject:                                      The subject of the file
196
 * @poster:                                       The name of the poster
197
 * @stamp:                                        The UNIX timestamp of the post date
198
 * @file_size:                                    The size of the file
199
 * @groups:         (element-type utf8):          A list containing the newsgroups in which this file is posted
200
 * @parts:          (element-type NNTPGrabPart):  A list containing the message-id's of all the individual parts belonging to this file
201
 * @errmsg:         (allow-none) (out):           Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
202
 *
203
 * Add a new task to the download queue
204
 *
205
 * Returns:         TRUE if the task was succesfully added, FALSE if an error occured (errmsg will be set)
206
 */
207
ngboolean       nntpgrab_core_schedular_add_task_to_queue(NntpgrabCore *obj, const char *collection_name, const char *subject, const char *poster, time_t stamp, nguint64 file_size, NGList *groups, NGList *parts, char **errmsg);
208

                
209
/** 
210
 * nntpgrab_core_schedular_del_task_from_queue:
211
 * @obj:                                   An instance of the NntpgrabCore
212
 * @collection_name:                       The name of the collection in which the task resides
213
 * @subject:          (allow-none):        The subject of the task
214
 * @errmsg            (allow-none) (out):  Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
215
 *
216
 * Remove a task from the download queue
217
 *
218
 * Returns:           TRUE if the task was successfully removed, FALSE if an error occured (errmsg will be set)
219
 */
220
ngboolean       nntpgrab_core_schedular_del_task_from_queue(NntpgrabCore *obj, const char *collection_name, const char *subject, char **errmsg);
221

                
222
/** 
223
 * nntpgrab_core_schedular_restart_task:
224
 * @obj:                                   An instance of the NntpgrabCore
225
 * @collection_name:                       The name of the collection in which the task resides
226
 * @subject:          (allow-none):        The subject of the task
227
 * @errmsg            (allow-none) (out):  Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
228
 *
229
 * Restart a task in the download queue
230
 *
231
 * Returns:           TRUE if the task was successfully removed, FALSE if an error occured (errmsg will be set)
232
 */
233
ngboolean       nntpgrab_core_schedular_restart_task(NntpgrabCore *obj, const char *collection_name, const char *subject, char **errmsg);
234

                
235
/** 
236
 * nntpgrab_core_schedular_save_queue:
237
 * @obj:                          An instance of the NntpgrabCore
238
 * @errmsg:  (allow-none) (out):  Pointer to a char*. If an errors occurs, the reason will be placed in this field. Needs to be freed using ngfree(). Can be NULL to ignore errors
239
 *
240
 * Save any recent changes in the download queue to the disk
241
 * Note that the download queue will automatically be saved every now and then by the NNTPGrab Core, but it is recommended to perform a manual save as soon as a lot of file have been added to the download queue (like directly after an NZB import)
242
 *
243
 * Returns:  TRUE if the task was successfully removed, FALSE if an error occured (errmsg will be set)
244
 */
245
ngboolean       nntpgrab_core_schedular_save_queue(NntpgrabCore *obj, char **errmsg);
246

                
247
/** 
248
 * nntpgrab_core_schedular_foreach_task:
249
 * @obj:                              An instance of the NntpgrabCore
250
 * @collection_func:   (allow-none):  The function which should be called for every collection in the download queue
251
 * @file_func:         (allow-none):  The function which should be called for every file in the download queue
252
 * @group_func:        (allow-none):  The function which should be called for every group in every file in the download queue
253
 * @user_data:         (allow-none):  Pointer to some data which will be made available in the callback functions
254
 *
255
 * Retrieve a list of all the items in the download queue (using callback functions)
256
 */
257
void            nntpgrab_core_schedular_foreach_task(NntpgrabCore *obj, ForeachCollectionFunc collection_func, ForeachFileFunc file_func, ForeachGroupFunc group_func, void *user_data);
258

                
259
/** 
260
 * nntpgrab_core_schedular_move_task:
261
 * @obj:                                  An instance of the NntpgrabCore
262
 * @collection_name_src:                  The name of the collection where the subject is part of
263
 * @subject_src:                          The name of the subject which needs to be moved
264
 * @collection_name_dest:  (allow-none):  The name of the collection where the subject needs to be moved to (if NULL, the task will stay in the same collection as it is now)
265
 * @position_dest                         The position in collection_name_dest where the task needs to be placed at
266
 *
267
 * Move a task in the download queue
268
 *
269
 * Returns:                TRUE on success, FALSE if the collection_name_src or subject_src could not be found
270
 */
271
ngboolean       nntpgrab_core_schedular_move_task(NntpgrabCore *obj, const char *collection_name_src, const char *subject_src, const char *collection_name_dest, int position_dest);
272

                
273
/** 
274
 * nntpgrab_core_schedular_move_collection:
275
 * @obj:              An instance of the NntpgrabCore
276
 * @collection_name:  The name of the collection which needs to be moved
277
 * @new_position:     The position in the download queue where the collection needs to be moved to
278
 *
279
 * Move the position of a collection in the download queue
280
 *
281
 * Returns:           TRUE on success, FALSE is the collection_name could not be found
282
 */
283
ngboolean       nntpgrab_core_schedular_move_collection(NntpgrabCore *obj, const char *collection_name, int new_position);
284

                
285
/** 
286
 * nntpgrab_core_schedular_mark_task_optional:
287
 * @obj:              An instance of the NntpgrabCore
288
 * @collection_name:  The name of the collection in which the task resides
289
 * @subject:          The subject of the task
290
 * @is_optional:      TRUE if the task needs to be marked optional, FALSE is the task needs to be marked non-optional
291
 *
292
 * Mark a task in the download queue optional or non-optional
293
 *
294
 * Returns:           TRUE if the task was successfully updated, FALSE if the task wasn't found
295
 */
296
ngboolean       nntpgrab_core_schedular_mark_task_optional(NntpgrabCore *obj, const char *collection_name, const char *subject, ngboolean is_optional);
297

                
298
/** 
299
 * nntpgrab_core_plugins_get_avail_plugins:
300
 * @obj:    An instance of the NntpgrabCore
301
 *
302
 * Retrieve a list of all the available plugins
303
 *
304
 * Returns: (transfer full) (element-type utf8):  A list containing all the available plugins (const char* items). Needs to be free'd using nntpgrab_core_plugins_free_avail_plugins()
305
 */
306
NGList         *nntpgrab_core_plugins_get_avail_plugins(NntpgrabCore *obj);
307

                
308
/** 
309
 * nntpgrab_core_plugins_free_avail_plugins: (skip)
310
 * @obj:               An instance of the NntpgrabCore
311
 * @plugins:           The list of available plugins
312
 *
313
 * Free a list as returned by the function nntpgrab_core_plugins_get_avail_plugins()
314
 */
315
void            nntpgrab_core_plugins_free_avail_plugins(NntpgrabCore *obj, NGList *plugins);
316

                
317
/** 
318
 * nntpgrab_core_plugins_get_plugin_info:
319
 * @obj:                 An instance of the NntpgrabCore
320
 * @plugin_name:         The name of the plugin whose information needs to be retrieved
321
 * @plugin_info: (out):  Pointer to an NNTPGrabPluginInfo structure where the plugin information can be saved
322
 *
323
 * Retrieve information about a specific plugin
324
 *
325
 * Returns:              TRUE on success, FALSE if the given plugin_name is unknown
326
 */
327
ngboolean       nntpgrab_core_plugins_get_plugin_info(NntpgrabCore *obj, const char *plugin_name, NNTPGrabPluginInfo *plugin_info);
328

                
329
/** 
330
 * nntpgrab_core_plugins_load_plugin:
331
 * @obj:                               An instance of the NntpgrabCore
332
 * @plugin_name:                       The name of the plugin which needs to be loaded
333
 * @errmsg:       (allow-none) (out):  Pointer to a location where an error message can be saved. Needs to be free'd using ng_free()
334
 *
335
 * Load a plugin
336
 *
337
 * Returns:                            TRUE on success, FALSE is the given plugin_name is unknown or an error occured while loading the plugin
338
 */
339
ngboolean       nntpgrab_core_plugins_load_plugin(NntpgrabCore *obj, const char *plugin_name, char **errmsg);
340

                
341
/** 
342
 * nntpgrab_core_plugins_unload_plugin:
343
 * @obj:                               An instance of the NntpgrabCore
344
 * @plugin_name:                       The name of the plugin which needs to be unloaded
345
 * @errmsg:       (allow-none) (out):  Pointer to a location where an error message can be saved. Needs to be free'd using ng_free()
346
 *
347
 * Unload a plugin
348
 *
349
 * Returns:                            TRUE on success, FALSE is the given plugin_name is unknown or an error occured while unloading the plugin
350
 */
351
ngboolean       nntpgrab_core_plugins_unload_plugin(NntpgrabCore *obj, const char *plugin_name, char **errmsg);
352

                
353
/** 
354
 * nntpgrab_core_plugins_set_persistent:
355
 * @obj:          An instance of the NntpgrabCore
356
 * @plugin_name:  The name of the plugin
357
 * @persistent:   Flag to indicate whether this plugin needs to be automatically loaded or not
358
 *
359
 * Indicate whether a plugin needs to be automatically loaded on startup
360
 * Note that this API function is unused in NNTPGrab 0.6
361
 *
362
 * Returns:       TRUE on success, FALSE is the given plugin_name is unknown
363
 */
364
ngboolean       nntpgrab_core_plugins_set_persistent(NntpgrabCore *obj, const char *plugin_name, ngboolean persistent);
365

                
366
/** 
367
 * nntpgrab_core_embedded_server_start:
368
 * @obj:                          An instance of the NntpgrabCore
369
 * @port:                         The port on which the embedded webserver needs to listen
370
 * @errmsg:  (allow-none) (out):  Pointer to a location where an error message can be saved. Needs to be free'd using ng_free()
371
 *
372
 * Start the embedded server on the specified port (even if it's disabled in the configuration)
373
 * Note that this API function is implemented temporary for NNTPGrab 0.6. For future versions it needs to be moved to a more generic API function
374
 *
375
 * Returns:                       TRUE on success, FALSE if an error occured (errmsg will be set)
376
 */
377
ngboolean       nntpgrab_core_embedded_server_start(NntpgrabCore *obj, int port, char **errmsg);
378

                
379
/** 
380
 * nntpgrab_core_set_emit_log_messages:
381
 * @obj:           An instance of the NntpgrabCore
382
 * @val:           Boolean which needs to be set to TRUE if log messages need to be emit or FALSE when they don't
383
 *
384
 * Indicate whether log messages should be emit the frontend
385
 */
386
void     nntpgrab_core_set_emit_log_messages(NntpgrabCore *obj, ngboolean val);
387

                
388
#ifdef  __cplusplus
389
}
390
#endif
391

                
392
#endif /* _NNTPGRAB_H_ */