Statistics
| Revision:

root / trunk / base / nntpgrab_utils.h @ 1913

History | View | Annotate | Download (28.8 KB)

1
/* 
2
    Copyright (C) 2005-2011  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_UTILS_H_
20
#define _NNTPGRAB_UTILS_H_
21

                
22
#include "nntpgrab_types.h"
23
#include "nntpgrab_glib_wrapper.h"
24

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

                
29
/** 
30
 * NNTPGrabNZB:
31
 * @files:  (element-type NZBFile):     A list containing NZBFile's
32
 */
33
typedef struct _nzb {
34
    NGList *files;
35
} NNTPGrabNZB;
36

                
37
/** 
38
 * NZBFile:
39
 * @subject:                                    The subject of the file
40
 * @poster:                                     The poster of the file
41
 * @stamp:                                      The stamp when (the first part of) this file was posted
42
 * @filesize:                                   The size of the file in bytes
43
 * @groups:     (element-type utf8):            A list containing the names of the newsgroups in which this file is posted
44
 * @segments:   (element-type NNTPGrabPart):    A list containing information of all the parts which belong to this file
45
 */
46
typedef struct _nzb_file {
47
    char subject[256];
48
    char poster[256];
49
    time_t stamp;
50
    nguint64 filesize;
51
    NGList *groups;
52
    NGList *segments;
53
} NNTPGrabNZBFile;
54

                
55
/** 
56
 * NZBCreatorGroup:
57
 * @newsgroup:              The name of the newsgroup
58
 * @group_id:               An identifier for this group
59
 */
60
typedef struct _nzbcreator_group {
61
    char newsgroup[512];
62
    int group_id;
63
} NZBCreatorGroup;
64

                
65
typedef enum _nzbcreator_search_only_in {
66
    NZBCREATOR_SEARCH_ONLY_IN_SUBJECTS,
67
    NZBCREATOR_SEARCH_ONLY_IN_FILENAMES,
68
    NZBCREATOR_SEARCH_ONLY_IN_POSTERS
69
} NZBCreatorSearchOnlyIn;
70

                
71
/** 
72
 * NZBCreatorMaintenanceInfo:
73
 * @down_for_maintenance:   If TRUE, then the NZBCreator service is currently down because of maintenance
74
 * @reason:                 The reason for the maintenance
75
 */
76
typedef struct _nzbcreator_maintenance_info {
77
    ngboolean down_for_maintenance;
78
    char reason[1024];
79
} NZBCreatorMaintenanceInfo;
80

                
81
/** 
82
 * NZBCreatorSearchOpts:
83
 * @query:                  The search query
84
 * @username:               The username which will be used to perform the search query (unused in NNTPGrab 0.7)
85
 * @password:               The password which will be used to perform the search query (unused in NNTPGrab 0.7)
86
 * @search_only_in:         Indicate what type of data needs to be searched
87
 * @max_age:                The maximum age of search results (in days)
88
 * @minimal_file_size:      The minimum size of files in bytes
89
 * @maximal_file_size:      The maximum size of files in bytes
90
 * @percentage_complete:    Only return results which are this percentage complete (0 to 100)
91
 * @group_to_search:        Limit searching to one specific groups (see the @group_id field from #NZBCreatorGroup)
92
 * @file_type:              Only search files of this type
93
 * @offset:                 The search result offset
94
 */
95
typedef struct _nzbcreator_search_opts {
96
    char query[64];
97
    char username[64];
98
    char password[64];
99
    NZBCreatorSearchOnlyIn search_only_in;
100
    int max_age;
101
    ngint64 minimal_file_size;
102
    ngint64 maximal_file_size;
103
    int percentage_complete;
104
    int group_to_search;
105
    NNTPFileType file_type;
106
    int offset;
107
} NZBCreatorSearchOpts;
108

                
109
/** 
110
 * NZBCreatorFile:
111
 * @file_id:                An identifier for this file
112
 * @subject:                The subject of this file
113
 * @poster:                 The poster of this file
114
 * @num_parts_found:        The number of parts which are found which belong to this file
115
 * @num_parts_expected:     The number of parts which are expected which belong to this file
116
 * @file_type:              The type of this file
117
 * @file_size:              The size of this file in bytes
118
 * @stamp:                  The stamp of the first part of this file
119
 * @complete_percentage:    The percentage which indicates how complete this file is
120
 */
121
typedef struct _nzbcreator_file {
122
    ngint64 file_id;
123
    char subject[256];
124
    char poster[256];
125
    int num_parts_found;
126
    int num_parts_expected;
127
    NNTPFileType file_type;
128
    ngint64 file_size;
129
    time_t stamp;
130
    int complete_percentage;
131
} NZBCreatorFile;
132

                
133
/** 
134
 * NZBCreatorCollection:
135
 * @collection_name:                                        The name of the collection (most frequently this is the subject of the first file in the collection)
136
 * @short_collection_name:                                  An abbreviated version of @collection_name
137
 * @newsgroup:                                              The newsgroup in which all the files from this collection are poster
138
 * @total_size:                                             The total size in bytes of this collection
139
 * @stamp:                                                  The stamp of the first part of the first file in this collection
140
 */
141
typedef struct _nzbcreator_collection {
142
    ngint64 collection_id;
143
    char collection_name[256];
144
    char short_collection_name[256];
145
    char poster[256];
146
    char newsgroup[256];
147
    ngint64 total_size;
148
    time_t stamp;
149
    int num_parts_found;
150
    int num_parts_expected;
151
    int complete_percentage;
152
    int num_regular_files;
153
    int num_par2_files;
154
    ngint64 first_file_id;
155
} NZBCreatorCollection;
156

                
157
/** 
158
 * NZBCreatorSearchResult:
159
 * @number_of_hits:                                             The number of hits which were found for the given query
160
 * @number_of_results:                                          The number of files which were found and are part of the @collections
161
 * @results_per_page:                                           The number of search results per page
162
 * @offset:                                                     The search result offset
163
 * @collections:        (element-type NZBCreatorCollection):    A list containing all returned collections
164
 */
165
typedef struct _nzbcreator_search_result {
166
    int number_of_hits;
167
    int number_of_results;
168
    int results_per_page;
169
    int offset;
170
    NGList *collections;             // List of NZBCreatorCollection* instances
171
} NZBCreatorSearchResult;
172

                
173
/** 
174
 * NZBCreatorBrowseResult:
175
 * @number_of_results:                                          The number of collections which were returned in this result set
176
 * @oldest_stamp:                                               The stamp of the oldest collection in the result set
177
 * @newest_stamp:                                               The stamp of the newest collection in the result set
178
 * @collections:        (element-type NZBCreatorCollection):    A list containing all returned collections
179
 */
180
typedef struct _nzbcreator_browse_result {
181
    int number_of_results;
182
    time_t oldest_time_stamp;
183
    time_t newest_time_stamp;
184
    NGList *collections;             // List of NZBCreatorCollection* instances
185
} NZBCreatorBrowseResult;
186

                
187
#define NG_OPEN_NZB_CALLBACK(f)                   ((NGOpenNZBCallback) (f))
188
typedef void  (*NGOpenNZBCallback)                (const char *nzb_file, void *user_data);
189

                
190
#define NG_BRING_TO_FRONT_CALLBACK(f)             ((NGBringToFrontCallback) (f))
191
typedef void  (*NGBringToFrontCallback)           (void *user_data);
192

                
193
/** 
194
 * nntpgrab_utils_perform_base_initialization: (skip)
195
 *
196
 * Perform the initialization of the GLib system. Needs to be called before any other NNTPGrab function in non-GLib-based frontends
197
 */
198
void nntpgrab_utils_perform_base_initialization(void);
199

                
200
/** 
201
 * nntpgrab_utils_regex_compile:
202
 * @regex:     The (perl-compatible) regular expression which needs to be compiled
203
 *
204
 * Compile a regular expression
205
 *
206
 * Returns:    A compiled regular expression
207
 */
208
NGRegex     *nntpgrab_utils_regex_compile(const char *regex);
209

                
210
/** 
211
 * nntpgrab_utils_regex_free:
212
 * @re:        The compiled regular expression
213
 *
214
 * Free a compiled regular expression
215
 */
216
void         nntpgrab_utils_regex_free(NGRegex *re);
217

                
218
/** 
219
 * nntpgrab_utils_regex_match:
220
 * @re:        The compiled regular expression
221
 * @line:      The data which need to be matched against the compiled regular expression
222
 *
223
 * Perform a match against a compiled regular expression
224
 *
225
 * Returns:    A NULL-terminated array of matches items (needs to be free'd using nntpgrab_utils_regex_matches_free())
226
 */
227
const char **nntpgrab_utils_regex_match(NGRegex *re, const char *line);
228

                
229
/** 
230
 * nntpgrab_utils_regex_matches_free:
231
 * @param matches   The NULL-terminated array of matches as returned by the function nntpgrab_utils_regex_match()
232
 *
233
 * Free an array of matched items
234
 */
235
void         nntpgrab_utils_regex_matches_free(const char **matches);
236

                
237
/** 
238
 * nntpgrab_utils_strip_subject:
239
 * @subject                                       The subject which need to be stripped
240
 * @subject_without_partnum  (allow-none) (out):  Location for the subject without any part numbers
241
 * @file_num                 (allow-none) (out):  Location for the number of the file in the set
242
 * @total_files              (allow-none) (out):  Location for the total number of files in the set
243
 * @filename                 (allow-none) (out):  Location for the filename
244
 * @extension                (allow-none) (out):  Location for the extension of the filename (as an string)
245
 * @file_type                (allow-none) (out):  Location for the extension of the filename (as an enumeration)
246
 * @par2_startnum            (allow-none) (out):  Location for the start number of the PAR2 recovery file
247
 * @num_par2_blocks          (allow-none) (out):  Location for the number blocks in the PAR2 recovery file
248
 * @part_num                 (allow-none) (out):  Location for the part number for this subject
249
 * @total_parts              (allow-none) (out):  Location for the number of parts for this subject
250
 *
251
 * Strip a subject into useable pieces of data
252
 * All the parameters (except subject) can be NULL to ignore them
253
 * All the char* parameters need to be free'd using ng_free()
254
 *
255
 * Returns:         TRUE is the strip was successfull
256
 */
257
ngboolean        nntpgrab_utils_strip_subject(const char *subject, char **subject_without_partnum, int *file_num, int *total_files, char **filename, char **extension, NNTPFileType *file_type, int *par2_startnum, int *num_par2_blocks, int *part_num, int *total_parts);
258

                
259
/** 
260
 * nntpgrab_utils_get_file_type_of_filename:
261
 * @filename:       The filename whose file type needs to be found out
262
 *
263
 * Find out the file type of a given filename
264
 * If the file type couldn't be found out, the value NNTP_FILE_TYPE_UNKNOWN will be returned
265
 *
266
 * Returns:         The file type (as an enumeration)
267
 */
268
NNTPFileType     nntpgrab_utils_get_file_type_of_filename(const char *filename);
269

                
270
/** 
271
 * nntpgrab_utils_calculate_file_size:
272
 * @file_size:                  The file size which needs to be transformed
273
 * @file_size_str:     (out):   Pointer to the location where the result needs to be saved
274
 * @file_size_str_len:          The maximum length of the file_size_str buffer
275
 *
276
 * Transform a file size into a human readable notation
277
 */
278
void nntpgrab_utils_calculate_file_size(nguint64 file_size, char *file_size_str, int file_size_str_len);
279

                
280
/** 
281
 * nntpgrab_utils_calculate_estimated_time_remaining:
282
 * @bytes_received1:      The number of bytes received in now() - 10
283
 * @bytes_received2:      The number of bytes received in now() - 9
284
 * @bytes_received3:      The number of bytes received in now() - 8
285
 * @bytes_received4:      The number of bytes received in now() - 7
286
 * @bytes_received5:      The number of bytes received in now() - 6
287
 * @bytes_received6:      The number of bytes received in now() - 5
288
 * @bytes_received7:      The number of bytes received in now() - 4
289
 * @bytes_received8:      The number of bytes received in now() - 3
290
 * @bytes_received9:      The number of bytes received in now() - 2
291
 * @bytes_received10:     The number of bytes received in now() - 1
292
 * @file_size:            The file size in bytes
293
 *
294
 * Calculate the estimated time remaining to complete the given file size
295
 * The bytes_received parameters can be retrieved from the signalhandler for the signal #NNTPGrabCore::traffic-monitor-update
296
 *
297
 * Returns:               The number of seconds in which the given @file_size can be downloaded
298
 */
299
int              nntpgrab_utils_calculate_estimated_time_remaining(int bytes_received1, int bytes_received2, int bytes_received3, int bytes_received4, int bytes_received5, int bytes_received6, int bytes_received7, int bytes_received8, int bytes_received9, int bytes_received10, nguint64 file_size);
300

                
301
/** 
302
 * nntpgrab_utils_get_readable_time_remaining:
303
 * @estimated_time_remaining:         The estimated time remaining (in seconds)
304
 * @time_remaining_str:       (out):  Pointer to the location where the human readable notation (like '3 minutes and 10 seconds') can be saved
305
 * @time_remaining_str_len:           The maximum length of the time_remaining_str buffer
306
 *
307
 * Transform a estimated time remaining into a human readable value for the time remaining
308
 */
309
void             nntpgrab_utils_get_readable_time_remaining(int estimated_time_remaining, char *time_remaining_str, int time_remaining_str_len);
310

                
311
/** 
312
 * nntpgrab_utils_get_readable_finished_time:
313
 * @estimated_time_remaining:          The estimated time remaining (in seconds)
314
 * @time_remaining_str:        (out):  Pointer to the location where the human readable notation (like 'Friday February 6 2009 - 22:15') can be saved
315
 * @time_remaining_str_len:            The maximum length of the time_remaining_str buffer
316
 *
317
 * Transform a estimated time remaining into a human readable value for the expected time to finish
318
 */
319
void             nntpgrab_utils_get_readable_finished_time(int estimated_time_remaining, char *time_remaining_str, int time_remaining_str_len);
320

                
321
/** 
322
 * nntpgrab_utils_get_readable_time_stamp:
323
 * @stamp:                             The time stamp which needs to be transformed to a readable notation
324
 * @stamp_str:                 (out):  Pointer to the location where the human readable notation (like 'Friday February 6 2009 - 22:15') can be saved
325
 * @stamp_str_len:                     The maximum length of the time_remaining_str buffer
326
 *
327
 * Transform a time stamp into a human readable value
328
 */
329
void             nntpgrab_utils_get_readable_time_stamp(time_t stamp, char *stamp_str, int stamp_str_len);
330

                
331
/** 
332
 * nntpgrab_utils_sanitize_text:
333
 * @text:      (inout):  The text which need to be sanitized
334
 * @length:              The length of the text
335
 *
336
 * Check whether the given text contains invalid UTF-8 characters and if they're found, replace them with something more sane
337
 */
338
void             nntpgrab_utils_sanitize_text(char *text, int length);
339

                
340
/** 
341
 * nntpgrab_utils_strip_nzb_extension:
342
 * @filename:   (inout):  The filename whose extension need to be stripped
343
 *
344
 * Remove the extension from a filename
345
 */
346
void             nntpgrab_utils_strip_nzb_extension(char *filename);
347

                
348
/** 
349
 * nntpgrab_utils_sanitize_collection_name:
350
 * @collection_name:  (inout):  The collection name which need to be sanitized
351
 *
352
 * Remove forbidden characters from the collection name
353
 */
354
void             nntpgrab_utils_sanitize_collection_name(char *collection_name);
355

                
356
/** 
357
 * nntpgrab_utils_extract_par2set_name_from_par2_filename:
358
 * @par2filename:             The filename of the PAR2 file which needs to be extracted
359
 * @par2set:          (out):  Pointer to a location where the result can be saved
360
 * @par2set_length:           Size of the par2set length
361
 *
362
 * Extract the name of a PAR2 set out of a PAR2 filename
363
 *
364
 * Returns:                   TRUE of success (par2set will be set), FALSE on failure
365
 */
366
ngboolean
367
nntpgrab_utils_extract_par2set_name_from_par2_filename(const char *par2filename, char *par2set, int par2set_length);
368

                
369
/** 
370
 * nntpgrab_utils_get_folder_listing:
371
 * @parent:                                              The name of the directory whose sub-folders should be retrieved. If NULL, all available drives will be returned (when the host is running Windows)
372
 * @folders:    (out) (element-type NNTPGrabFolder):     Pointer to a NGList*. The list of sub-folders will be placed in this field. This list needs to be free'd using the function nntpgrab_config_free_folder_listing()
373
 *
374
 * Retrieves a list containing all the sub-folders which are in the given folder
375
 *
376
 * Returns:            TRUE on sucess, FALSE if the given directory isn't found or readable
377
 */
378
ngboolean        nntpgrab_utils_get_folder_listing(const char *parent, NGList **folders);
379

                
380
/** 
381
 * nntpgrab_utils_free_folder_listing: (skip)
382
 * @folders:       A list containing subfolders as returned by the function nntpgrab_config_get_folder_listing()
383
 *
384
 * Free a list of sub-folders
385
 */
386
void             nntpgrab_utils_free_folder_listing(NGList *folders);
387

                
388
/** 
389
 * nntpgrab_utils_parse_nzb_file:
390
 * @contents:                         The contents of the NZB file
391
 * @errmsg:      (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
392
 *
393
 * Parse the contents of a NZB file and put the information in a structure
394
 *
395
 * Returns:      A structure containing information about the NZB file. Needs to be free'd using the function nntpgrab_utils_nzb_file_free(). If the value NULL is returned, an error occured and errmsg will be set
396
 */
397
NNTPGrabNZB     *nntpgrab_utils_parse_nzb_file(const char *contents, char **errmsg);
398

                
399
/** 
400
 * nntpgrab_utils_nzb_file_free: (skip)
401
 * @nzbfile:       The structure containing information about the NZB file
402
 *
403
 * Free a structure containing details about a NZB file
404
 */
405
void             nntpgrab_utils_nzb_file_free(NNTPGrabNZB *nzbfile);
406

                
407
/** 
408
 * nntpgrab_utils_nzbcreator_check_api_version:
409
 * @api_okay:                          Location where the result can be saved
410
 * @errmsg:      (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
411
 *
412
 * Verify if this version of NNTPGrab can be used to communicate with the NZBCreator service
413
 *
414
 * Returns:      TRUE when the online search server returned a valid response (use @api_okay to find out if the API version matches)
415
 */
416
ngboolean        nntpgrab_utils_nzbcreator_check_api_version(ngboolean *api_okay, char **errmsg);
417

                
418
/** 
419
 * nntpgrab_utils_nzbcreator_free_maintenance_info: (skip)
420
 * @result:        The NZBCreator maintenance information
421
 *
422
 * Free the NZBCreator maintenance information
423
 */
424
void                     nntpgrab_utils_nzbcreator_free_maintenance_info(NZBCreatorMaintenanceInfo *info);
425

                
426
/** 
427
 * nntpgrab_utils_nzbcreator_get_maintenance_info:
428
 * @errmsg:      (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
429
 *
430
 * Retrieve information whether the NZBCreator service is currently under maintenance
431
 *
432
 * Returns:                             A structure containing maintenance information. Needs to be free'd using nntpgrab_utils_nzbcreator_free_maintenance_info(). If an error occurs, the value NULL will be returned and errmsg will be set
433
 */
434
NZBCreatorMaintenanceInfo   *nntpgrab_utils_nzbcreator_get_maintenance_info(char **errmsg);
435

                
436
/** 
437
 * nntpgrab_utils_nzbcreator_get_all_groups:
438
 * @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
439
 *
440
 * Retrieve a list of all the usenet groups which are indexed by the NZBCreator service
441
 *
442
 * Returns:     (element-type NZBCreatorGroup):   A list of all the indexed usenet groups. Needs to be free'd using nntpgrab_utils_nzbcreator_free_groups(). If an error occures, the value NULL will be returned and errmsg will be set
443
 */
444
NGList                  *nntpgrab_utils_nzbcreator_get_all_groups(char **errmsg);
445

                
446
/** 
447
 * nntpgrab_utils_nzbcreator_free_groups: (skip)
448
 * @groups:        A list of all the indexed usenet groups
449
 *
450
 * Free the list of usenet groups which are indexed by the NZBCreator service
451
 */
452
void                     nntpgrab_utils_nzbcreator_free_groups(NGList *groups);
453

                
454
/** 
455
 * nntpgrab_utils_nzbcreator_perform_search:
456
 * @opts:                                               A structure containing information about the requested search
457
 * @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
458
 *
459
 * Perform a search using the NZBCreator service
460
 *
461
 * Returns:                                             A structure containing the search results. Needs to be free'd using nntpgrab_utils_nzbcreator_free_result(). If an error occurs, the value NULL will be returned and errmsg will be set
462
 */
463
NZBCreatorSearchResult  *nntpgrab_utils_nzbcreator_perform_search(NZBCreatorSearchOpts opts, char **errmsg);
464

                
465
/** 
466
 * nntpgrab_utils_nzbcreator_free_result: (skip)
467
 * @result:        The NZBCreator search results
468
 *
469
 * Free the NZBCreator search results
470
 */
471
void                     nntpgrab_utils_nzbcreator_free_result(NZBCreatorSearchResult *result);
472

                
473
/** 
474
 * nntpgrab_utils_nzbcreator_retrieve_collection_details:
475
 * @collection_id:                                  The id of the collection whose details need to be retrieved
476
 * @stamp:                                          The stamp belonging to the collection id
477
 * @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
478
 *
479
 * Retrieve a list of files belonging to a collection
480
 *
481
 * Returns:         (element-type NZBCreatorFile):  A list containing NZBCreatorFile's. Needs to be free'd using nntpgrab_utils_nzbcreator_free_collection_details(). If an error occurs, the value NULL will be returned and errmsg will be set
482
 */
483
NGList *nntpgrab_utils_nzbcreator_retrieve_collection_details(ngint64 collection_id, time_t stamp, char **errmsg);
484

                
485
/** 
486
 * nntpgrab_utils_nzbcreator_free_collection_details: (skip)
487
 * @files:          The list of files as returned by nntpgrab_utils_nzbcreator_retrieve_collection_details()
488
 *
489
 * Free the list with collection details
490
 */
491
void nntpgrab_utils_nzbcreator_free_collection_details(NGList *files);
492

                
493
/** 
494
 * nntpgrab_utils_nzbcreator_generate_NZB:
495
 * @file_ids:       (element-type int):  A list containing file ID's of all the files which needs to be retrieved
496
 * @oldest_stamp:                        The timestamp of the oldest file in the collection
497
 * @newest_stamp:                        The timestamp of the newest file in the collection
498
 * @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
499
 *
500
 * Generate a NZB file based on a list of file ID's
501
 *
502
 * Returns:    The contents of the NZB file containing all the details of the given file_ids. Needs to be free'd using ng_free(). If an error occurs, the value NULL will be returned and errmsg will be set
503
 */
504
char                    *nntpgrab_utils_nzbcreator_generate_NZB(NGList *file_ids, time_t oldest_stamp, time_t newest_stamp, char **errmsg);
505

                
506
/** 
507
 * nntpgrab_utils_nzbcreator_perform_browse:
508
 * @newsgroup_id:                       The ID of the newsgroup which needs to be browsed
509
 * @older_than_stamp:                   Return only files older than this stamp (can be 0)
510
 * @newer_than_stamp:                   Return only files newer than this stamp (can be 0)
511
 * @username:                           The username to use to communicate with the server. Unused in NNTPGrab 0.8
512
 * @password:                           The password to use to communicate with the server. Unused in NNTPGrab 0.8
513
 * @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
514
 *
515
 * Browse a newsgroup using the NZBCreator service
516
 *
517
 * Returns:                             A structure containing the search results. Needs to be free'd using nntpgrab_utils_nzbcreator_free_result(). If an error occurs, the value NULL will be returned and errmsg will be set
518
 */
519
NZBCreatorBrowseResult *nntpgrab_utils_nzbcreator_perform_browse(int newsgroup_id, time_t older_than_stamp, time_t newer_than_stamp, char *username, char *password, char **errmsg);
520

                
521
/** 
522
 * nntpgrab_utils_nzbcreator_free_browse_result: (skip)
523
 * @result:        The NZBCreator browse results
524
 *
525
 * Free the NZBCreator browse results
526
 */
527
void
528
nntpgrab_utils_nzbcreator_free_browse_result(NZBCreatorBrowseResult *result);
529

                
530
/** 
531
 * nntpgrab_utils_monitor_directory:
532
 * @path:                         The directory which needs to be monitored for changes
533
 * @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
534
 *
535
 * Start the monitoring of a directory
536
 * The NGFileMonitor is an GObject where the event 'changed' can be caught using ng_signal_connect()
537
 *
538
 * Returns:                       An instance of a NGFileMonitor or NULL in case an error occured (errmsg will be set)
539
 */
540
NGFileMonitor   *nntpgrab_utils_monitor_directory(const char *path, char **errmsg);
541

                
542
/** 
543
 * nntpgrab_utils_cancel_directory_monitor:
544
 * @monitor:       The instance of the NGFileMonitor which needs to be stopped
545
 *
546
 * Cancel the monitoring of a directory
547
 */
548
void             nntpgrab_utils_cancel_directory_monitor(NGFileMonitor *monitor);
549

                
550
/** 
551
 * nntpgrab_utils_test_is_server_already_running:
552
 *
553
 * Find out if the NNTPGrab Server is already running on this computer
554
 *
555
 * Returns: TRUE when a running NNTPGrab Server has been detected on this computer
556
 */
557
ngboolean        nntpgrab_utils_test_is_server_already_running(void);
558

                
559
/** 
560
 * nntpgrab_utils_test_is_frontend_already_running:
561
 * @is_running:                     This flag will be set to TRUE when an already running frontend was detected
562
 * @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
563
 *
564
 * Find out if a NNTPGrab frontend is already running on this computer
565
 *
566
 * Returns: TRUE when the check has completed successfully, check the is_running variable for the real status
567
 */
568
ngboolean       nntpgrab_utils_test_is_frontend_already_running(ngboolean *is_running, char **errmsg);
569

                
570
/** 
571
 * nntpgrab_utils_register_frontend:
572
 * @open_nzb_callback:              Function which needs to be called when a 'open NZB' request is received
573
 * @bring_to_front_callback:        Function which needs to be called when a 'bring to front' request is received
574
 * @user_data:                      Optional data to use with the callback function
575
 * @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
576
 *
577
 * Allow this frontend to receive 'open NZB' and 'bring to front' requests using the given handlers
578
 *
579
 * Returns: TRUE when the registration succeeded succesfully
580
 */
581
ngboolean       nntpgrab_utils_register_frontend(NGOpenNZBCallback open_nzb_callback, NGBringToFrontCallback bring_to_front_callback, void *user_data, char **errmsg);
582

                
583
/** 
584
 * nntpgrab_utils_unregister_frontend:
585
 *
586
 * Indicate that this frontend doesn't want to receive 'open NZB' requests anymore
587
 */
588
void            nntpgrab_utils_unregister_frontend(void);
589

                
590
/** 
591
 * nntpgrab_utils_send_open_nzb_file_request:
592
 * @nzb_file:                       The location of the NZB file which needs to be opened
593
 * @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
594
 *
595
 * Send a request to an already running NNTPGrab frontend to open an NZB file
596
 *
597
 * Returns: TRUE when the request was sent succesfully
598
 */
599
ngboolean       nntpgrab_utils_send_open_nzb_file_request(const char *nzb_file, char **errmsg);
600

                
601
/** 
602
 * nntpgrab_utils_send_bring_to_front_request:
603
 * @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
604
 *
605
 * Send a request to an already running NNTPGrab frontend to present itself
606
 *
607
 * Returns: TRUE when the request was sent succesfully
608
 */
609
ngboolean       nntpgrab_utils_send_bring_to_front_request(char **errmsg);
610

                
611
/** 
612
 * nntpgrab_utils_perform_shutdown:
613
 *
614
 * Shut down the system
615
 *
616
 * Returns: TRUE when a shutdown command has been executed successfully
617
 */
618
ngboolean        nntpgrab_utils_perform_shutdown(void);
619

                
620
#ifdef  __cplusplus
621
}
622
#endif
623

                
624
#endif /* _NNTPGRAB_UTILS_H_ */