nntpgrab_utils.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2005-2009 Erik van Pienbroek
00003 
00004  This program is free software; you can redistribute it and/or modify
00005  it under the terms of the GNU General Public License as published by
00006  the Free Software Foundation; either version 2 of the License, or
00007  (at your option) any later version.
00008 
00009  This program is distributed in the hope that it will be useful,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012  GNU General Public License for more details.
00013 
00014  You should have received a copy of the GNU General Public License
00015  along with this program; if not, write to the Free Software
00016  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00017 */
00018 
00019 #ifndef _NNTPGRAB_UTILS_H_
00020 #define _NNTPGRAB_UTILS_H_
00021 
00022 #include "nntpgrab_types.h"
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /* These declarations are actually from GLib, but to easy the development
00029  * of external frontends, they have been duplicated here to avoid linkage bloat */
00030 
00031 typedef void NGFileMonitor;
00032 
00038 void          ng_free(void *data);
00039 
00047 NGList       *ng_list_append  (NGList *list, void *data);
00048 
00056 NGList       *ng_list_prepend (NGList *list, void *data);
00057 
00067 NGList       *ng_list_remove  (NGList *list, void *data);
00068 
00075 unsigned int  ng_list_length  (NGList *list);
00076 
00084 void          ng_list_free    (NGList *list);
00085 
00086 #define ng_list_previous(list) ((list) ? (((NGList *)(list))->prev) : NULL)
00087 #define ng_list_next(list) ((list) ? (((NGList *)(list))->next) : NULL)
00088 
00089 /* signals */
00100 void     ng_signal_connect(void *instance, const char *signal_name, NGCallback cb_handler, void *data);
00101 
00109 void     ng_signal_handlers_disconnect_by_func(void *instance, NGCallback cb_handler, void *data);
00110 
00118 void     ng_signal_handlers_block_by_func(void *instance, NGCallback cb_handler, void *data);
00119 
00127 void     ng_signal_handlers_unblock_by_func(void *instance, NGCallback cb_handler, void *data);
00128 
00135 void     ng_event_handler_loop_run(void);
00136 
00142 void     ng_event_handler_loop_quit(void);
00143 
00144 /* End of GLib declarations */
00145 
00146 typedef struct _nntpgrab_folder {
00147     char folder[2048];
00148     ngboolean has_subfolders;
00149 } NNTPGrabFolder;
00150 
00151 typedef struct _nzb {
00152     NGList *files;
00153 } NZB;
00154 
00155 typedef struct _nzb_file {
00156     char subject[256];
00157     char poster[256];
00158     time_t stamp;
00159     nguint64 filesize;
00160     NGList *groups;
00161     NGList *segments;
00162 } NZBFile;
00163 
00164 typedef struct _nzbcreator_group {
00165     char newsgroup[512];
00166     int group_id;
00167 } NZBCreatorGroup;
00168 
00169 typedef enum _nzbcreator_search_only_in {
00170     NZBCREATOR_SEARCH_ONLY_IN_SUBJECTS,
00171     NZBCREATOR_SEARCH_ONLY_IN_FILENAMES,
00172     NZBCREATOR_SEARCH_ONLY_IN_POSTERS
00173 } NZBCreatorSearchOnlyIn;
00174 
00175 typedef struct _nzbcreator_search_opts {
00176     char query[64];
00177     char username[64];
00178     char password[64];
00179     NZBCreatorSearchOnlyIn search_only_in;
00180     int max_age;
00181     ngint64 minimal_file_size;
00182     ngint64 maximal_file_size;
00183     int percentage_complete;
00184     int group_to_search;
00185     NNTPFileType file_type;
00186 } NZBCreatorSearchOpts;
00187 
00188 typedef struct _nzbcreator_file {
00189     ngint64 file_id;
00190     char subject[256];
00191     char poster[256];
00192     int num_parts_found;
00193     int num_parts_expected;
00194     NNTPFileType file_type;
00195     ngint64 file_size;
00196     time_t stamp;
00197     int complete_percentage;
00198 } NZBCreatorFile;
00199 
00200 typedef struct _nzbcreator_collection {
00201     char collection_name[256];
00202     char newsgroup[256];
00203     ngint64 total_file_size;
00204     time_t stamp;
00205     NGList *files;                   // List of NZBCreatorFile* instances
00206 } NZBCreatorCollection;
00207 
00208 typedef struct _nzbcreator_search_result {
00209     int number_of_hits;
00210     int number_of_results;
00211     NGList *collections;             // List of NZBCreatorCollection* instances
00212 } NZBCreatorSearchResult;
00213 
00220 NGRegex     *nntpgrab_utils_regex_compile(const char *regex);
00221 
00227 void         nntpgrab_utils_regex_free(NGRegex *re);
00228 
00236 const char **nntpgrab_utils_regex_match(NGRegex *re, const char *line);
00237 
00243 void         nntpgrab_utils_regex_matches_free(const char **matches);
00244 
00264 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);
00265 
00274 NNTPFileType     nntpgrab_utils_get_file_type_of_filename(const char *filename);
00275 
00282 char            *nntpgrab_utils_calculate_file_size(nguint64 file_size);
00283 
00302 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);
00303 
00310 char            *nntpgrab_utils_get_readable_time_remaining(int estimated_time_remaining);
00311 
00318 char            *nntpgrab_utils_get_readable_finished_time(int estimated_time_remaining);
00319 
00326 void             nntpgrab_utils_sanitize_text(char *text, int length);
00327 
00333 void             nntpgrab_utils_strip_nzb_extension(char *filename);
00334 
00340 void             nntpgrab_utils_sanitize_collection_name(char *collection_name);
00341 
00349 ngboolean        nntpgrab_utils_get_folder_listing(const char *parent, NGList **folders);
00350 
00356 void             nntpgrab_utils_free_folder_listing(NGList *folders);
00357 
00365 NZB             *nntpgrab_utils_parse_nzb_file(const char *contents, char **errmsg);
00366 
00372 void             nntpgrab_utils_nzb_file_free(NZB *nzbfile);
00373 
00380 NGList                  *nntpgrab_utils_nzbcreator_get_all_groups(char **errmsg);
00381 
00387 void                     nntpgrab_utils_nzbcreator_free_groups(NGList *groups);
00388 
00396 NZBCreatorSearchResult  *nntpgrab_utils_nzbcreator_perform_search(NZBCreatorSearchOpts opts, char **errmsg);
00397 
00403 void                     nntpgrab_utils_nzbcreator_free_result(NZBCreatorSearchResult *result);
00404 
00412 char                    *nntpgrab_utils_nzbcreator_generate_NZB(NGList *file_ids, char **errmsg);
00413 
00423 NGFileMonitor   *nntpgrab_utils_monitor_directory(const char *path, char **errmsg);
00424 
00430 void             nntpgrab_utils_cancel_directory_monitor(NGFileMonitor *monitor);
00431 
00432 #ifdef __cplusplus
00433 }
00434 #endif
00435 
00436 #endif /* _NNTPGRAB_UTILS_H_ */
00437 

Generated on Wed May 20 22:37:09 2009 for NNTPGrab by  1.5.4