utils.c File Reference

#include
#include
#include
#include
#include
#include "nntpgrab_utils.h"
#include "nntpgrab_types.h"

Functions

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)
  Strip a subject into useable pieces of data.
NNTPFileType  nntpgrab_utils_get_file_type_of_filename (const char *filename)
  Find out the file type of a given filename.
char *  nntpgrab_utils_calculate_file_size (nguint64 file_size)
  Transform a file size into a human readable notation.
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)
  Calculate the estimated time remaining to complete the given file size.
char *  nntpgrab_utils_get_readable_time_remaining (int estimated_time_remaining)
  Transform a estimated time remaining into a human readable value for the time remaining.
char *  nntpgrab_utils_get_readable_finished_time (int estimated_time_remaining)
  Transform a estimated time remaining into a human readable value for the expected time to finish.
ngboolean  nntpgrab_utils_get_folder_listing (const char *parent, NGList **folders)
  Retrieve all the folders which belong to path.
void  nntpgrab_utils_free_folder_listing (NGList *folders)
  Free a list of sub-folders.
void  nntpgrab_utils_sanitize_text (char *text, int length)
  Check whether the given text contains invalid UTF-8 characters and if they're found, replace them with something more sane.
void  nntpgrab_utils_sanitize_collection_name (char *collection_name)
  Remove forbidden characters from the collection name.
void  nntpgrab_utils_strip_nzb_extension (char *filename)
  Remove the extension from a filename.

Function Documentation

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  
)

Calculate the estimated time remaining to complete the given file size.

Parameters:
bytes_received1  The number of bytes received in now() - 10
bytes_received2  The number of bytes received in now() - 9
bytes_received3  The number of bytes received in now() - 8
bytes_received4  The number of bytes received in now() - 7
bytes_received5  The number of bytes received in now() - 6
bytes_received6  The number of bytes received in now() - 5
bytes_received7  The number of bytes received in now() - 4
bytes_received8  The number of bytes received in now() - 3
bytes_received9  The number of bytes received in now() - 2
bytes_received10  The number of bytes received in now() - 1
file_size  The file size
Returns:
The number of seconds in which the given file_size can be downloaded
Note:
The bytes_received parameters can be retrieved from the signalhandler for the signal 'traffic_monitor_update'

char* nntpgrab_utils_calculate_file_size ( nguint64  file_size  ) 

Transform a file size into a human readable notation.

Parameters:
file_size  The file size which needs to be transformed
Returns:
The human readable notation for the file size. Needs to be free'd using ng_free()

void nntpgrab_utils_free_folder_listing ( NGList *  folders  ) 

Free a list of sub-folders.

Parameters:
folders  A list containing subfolders as returned by the function nntpgrab_config_get_folder_listing()

NNTPFileType nntpgrab_utils_get_file_type_of_filename ( const char *  filename  ) 

Find out the file type of a given filename.

Parameters:
filename  The filename whose file type needs to be found out
Returns:
The file type (as an enumeration)
Note:
If the file type couldn't be found out, the value NNTP_FILE_TYPE_UNKNOWN will be returned

ngboolean nntpgrab_utils_get_folder_listing ( const char *  parent,
NGList **  folders  
)

Retrieve all the folders which belong to path.

Retrieves a list containing all the sub-folders which are in the given folder.

Parameters:
parent  The path whose belonging folders should be looked up. If NULL, all the drive letters will be returned (on Win32) or "/" is returned (*nix/osx)
folders  Return address for a list containing g_slice_new'ed ConfigFolder structures containing the requested info
Returns:
FALSE when the given parent is invalid

char* nntpgrab_utils_get_readable_finished_time ( int  estimated_time_remaining  ) 

Transform a estimated time remaining into a human readable value for the expected time to finish.

Parameters:
estimated_time_remaining  The estimated time remaining (in seconds)
Returns:
The human readable notation (like 'Friday Februari 6 2009 - 22:15'). Needs to be free'd using ng_free()

char* nntpgrab_utils_get_readable_time_remaining ( int  estimated_time_remaining  ) 

Transform a estimated time remaining into a human readable value for the time remaining.

Parameters:
estimated_time_remaining  The estimated time remaining (in seconds)
Returns:
The human readable notation (like '3 minutes and 10 seconds'). Needs to be free'd using ng_free()

void nntpgrab_utils_sanitize_collection_name ( char *  collection_name  ) 

Remove forbidden characters from the collection name.

Parameters:
collection_name  The collection name which need to be sanitized

void nntpgrab_utils_sanitize_text ( char *  text,
int  length  
)

Check whether the given text contains invalid UTF-8 characters and if they're found, replace them with something more sane.

Parameters:
text  The text which need to be sanitized
length  The length of the text

void nntpgrab_utils_strip_nzb_extension ( char *  filename  ) 

Remove the extension from a filename.

Parameters:
filename  The filename whose extension need to be stripped

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  
)

Strip a subject into useable pieces of data.

Parameters:
subject  The subject which need to be stripped
subject_without_partnum  Location for the subject without any part numbers
file_num  Location for the number of the file in the set
total_files  Location for the total number of files in the set
filename  Location for the filename
extension  Location for the extension of the filename (as an string)
file_type  Location for the extension of the filename (as an enumeration)
par2_startnum  Location for the start number of the PAR2 recovery file
num_par2_blocks  Location for the number blocks in the PAR2 recovery file
part_num  Location for the part number for this subject
total_parts  Location for the number of parts for this subject
Returns:
TRUE is the strip was successfull
Note:
All the parameters (except subject) can be NULL to ignore them

All the char* parameters need to be free'd using ng_free()


Generated on Thu May 21 21:25:05 2009 for NNTPGrab by  1.5.4