utils

Name

utils -- Manage some common functions used by all other files.

Synopsis

#define             uc_utils_strstrip                   ( string )
gboolean            uc_utils_ftp_code_search            (const gchar *buffer,
                                                         const gchar *code,
                                                         const gint len);
gchar *             uc_utils_get_string_from_size       (const gsize size);
gchar *             uc_utils_get_server_from_header_field
                                                        (gchar *field);
void                uc_utils_copy                       (const gchar *src,
                                                         const gchar *dest);
gboolean            uc_utils_get_meta_refresh_location  (UCLinkProperties *prop,
                                                         UCHTMLTag *tag);
gchar *             uc_utils_html_decode                (const gchar *str);
gchar *             uc_utils_to_utf8                    (gchar *data);
void                uc_utils_copy_files                 (const gchar *src,
                                                         const gchar *dest);
void                uc_utils_debug                      (const gchar *format,
                                                         ...);
void                uc_utils_debug_dump_link_properties (const UCLinkProperties *prop);
void                uc_utils_set_userfriendly_treeview_column
                                                        (const GtkTreeView *tv,
                                                         const gint position);
gchar *             uc_utils_get_file_content           (const gchar *path,
                                                         gsize *length);
void                uc_utils_split_email                (const gchar *email,
                                                         gchar **user,
                                                         gchar **domain);
gchar *             uc_utils_get_mx                     (const gchar *domain);
gboolean            uc_utils_get_yesno                  (const gchar *yesno);
gboolean            uc_utils_mx_is_valid                (const gchar *mx);
gchar *             uc_utils_get_ip                     (const gchar *host);
UCEmailStatus       uc_utils_email_is_valid             (const gchar *email,
                                                         const gboolean check_mx);
gchar *             uc_utils_string_cut                 (const gchar *label,
                                                         const gsize size);
gchar *             uc_utils_string_format4display      (const gchar *label,
                                                         const gsize size);
gchar *             uc_utils_replace                    (const gchar *str,
                                                         const gchar *old,
                                                         const gchar *new);
gchar *             uc_utils_replace1                   (gchar *string,
                                                         const gchar c1,
                                                         const char c2);
gchar *             uc_utils_replacelr                  (gchar *string,
                                                         const gchar c);
gchar *             uc_utils_strchomp                   (gchar *string);
gchar *             uc_utils_strchug                    (gchar *string);
gchar *             uc_utils_convert_uid2file           (const guint32 uid);
gboolean            uc_utils_disk_free_enough           (const guint32 requested_size);
void                uc_utils_get_gnome_proxy_conf       (gchar **host,
                                                         guint *port);
gchar *             uc_utils_clean_tag_link_value       (gchar *value);
gpointer            uc_utils_search_string_next         (gpointer buf,
                                                         const gchar *str,
                                                         const gchar limit_char);
gboolean            uc_utils_memcasecmp                 (const gchar *str1,
                                                         const gchar *str2);
void                uc_utils_rmfiles                    (const gchar *path);
gboolean            uc_utils_mkdirs                     (const gchar *path,
                                                         const gboolean create_all);
void                uc_utils_rmdirs                     (const gchar *path,
                                                         const gboolean delete_all);
guint32             uc_utils_vector_length              (gpointer data);
gchar *             uc_utils_strpbrk_or_eos             (const gchar *str,
                                                         const gchar *accept);
gchar *             uc_utils_strdup_delim               (const gchar *begin,
                                                         const gchar *end);
gboolean            uc_utils_array_is_in                (const gchar *item,
                                                         gpointer array,
                                                         const guint size);
gboolean            uc_utils_test_socket_open           (const guint sock);
gchar *             uc_utils_get_gnome_browser_conf     (void);

Description

Details

uc_utils_strstrip()

#define             uc_utils_strstrip( string )

Remove leading and trailing spaces, tabulations and carriages returns.

string :

The string to strip.


uc_utils_ftp_code_search ()

gboolean            uc_utils_ftp_code_search            (const gchar *buffer,
                                                         const gchar *code,
                                                         const gint len);

buffer :

code :

len :

Returns :


uc_utils_get_string_from_size ()

gchar *             uc_utils_get_string_from_size       (const gsize size);

size :

Returns :


uc_utils_get_server_from_header_field ()

gchar *             uc_utils_get_server_from_header_field
                                                        (gchar *field);

Extract server name/type from a HTTP header "Server" field.

field :

A string from the "Server" HTTP header field.

Returns :

A string with the HTTP server. A new allocated string.


uc_utils_copy ()

void                uc_utils_copy                       (const gchar *src,
                                                         const gchar *dest);

Copy a file from src to dest.

src :

Source file.

dest :

Destination file.


uc_utils_get_meta_refresh_location ()

gboolean            uc_utils_get_meta_refresh_location  (UCLinkProperties *prop,
                                                         UCHTMLTag *tag);

If the page contain a refresh meta tag, replace the current page URL with it.

prop :

A UCLinkProperties node.

tag :

A UCHTMLTag tag.

Returns :

TRUE if there was a REFRESH META tag.


uc_utils_html_decode ()

gchar *             uc_utils_html_decode                (const gchar *str);

HTML decode (very basic stuff) a given string.

str :

The string to HTML decode.

Returns :

A new allocated HTML decoded string.


uc_utils_to_utf8 ()

gchar *             uc_utils_to_utf8                    (gchar *data);

UTF-8 encode a given string. Adapted from screem "screem_support_charset_convert()" function.

data :

String to proceed.

Returns :

A new allocated UTF-8 encoded string.


uc_utils_copy_files ()

void                uc_utils_copy_files                 (const gchar *src,
                                                         const gchar *dest);

Copy all the file from a given directorie in another.

src :

Source path.

dest :

Destination path.


uc_utils_debug ()

void                uc_utils_debug                      (const gchar *format,
                                                         ...);

Display debug informations.

format :

The message format.

... :

The parameters to insert into the format string.


uc_utils_debug_dump_link_properties ()

void                uc_utils_debug_dump_link_properties (const UCLinkProperties *prop);

Dump the link properties structure to the standard output.

prop :

A UCLinkProperties node.


uc_utils_set_userfriendly_treeview_column ()

void                uc_utils_set_userfriendly_treeview_column
                                                        (const GtkTreeView *tv,
                                                         const gint position);

Set a treeview column sortable and resizable.

tv :

Tree view to work with.

position :

Position of the column to work with.


uc_utils_get_file_content ()

gchar *             uc_utils_get_file_content           (const gchar *path,
                                                         gsize *length);

Open and read a file to return its content.

path :

Path of the file.

length :

Pointer to fill with file length.

Returns :

A new allocated string with the content of a the file. The length argument contain the file length.


uc_utils_split_email ()

void                uc_utils_split_email                (const gchar *email,
                                                         gchar **user,
                                                         gchar **domain);

Fill the two parts of a email address. user and domain argument are filled with new allocated strings.

email :

Email to work with.

user :

Pointer for the "user" part of the email.

domain :

Pointer for the "domain" part of the email.


uc_utils_get_mx ()

gchar *             uc_utils_get_mx                     (const gchar *domain);

Return the prefered MX for a given domain. Function adapted from http://www.sslug.dk/emailarkiv/cprog/1999_10/msg00056.html

domain :

Domain from which returning the corresponding MX.

Returns :

A new allocated string with the corresponding MX.


uc_utils_get_yesno ()

gboolean            uc_utils_get_yesno                  (const gchar *yesno);

Proceed a given string to see if it contains "yes" or "no".

yesno :

A string containing "yes" or "no".

Returns :

TRUE if the given string is "yes".


uc_utils_mx_is_valid ()

gboolean            uc_utils_mx_is_valid                (const gchar *mx);

Check if a given MX is valid or not.

mx :

The MX to check.

Returns :

TRUE if the given MX is alive and listen on port 25.


uc_utils_get_ip ()

gchar *             uc_utils_get_ip                     (const gchar *host);

Return the IP of the given host. if arg is already an IP, return it as is.

host :

Host to work with.

Returns :

A new allocated string with the IP.


uc_utils_email_is_valid ()

UCEmailStatus       uc_utils_email_is_valid             (const gchar *email,
                                                         const gboolean check_mx);

Check email syntax and MX if required.

email :

Email to check.

check_mx :

TRUE if we also must check the MX.

Returns :

The UCEmailStatus status of the email. Return codes are: - 0: bad syntax (UC_EMAIL_SYNTAX_BAD) - 1: syntax ok but MX not respond (UC_EMAIL_SYNTAX_MX_BAD) - 2: syntax ok and MX ok (UC_EMAIL_OK)


uc_utils_string_cut ()

gchar *             uc_utils_string_cut                 (const gchar *label,
                                                         const gsize size);

Cut a given string to fit with the given length.

See: uc_utils_string_format4display()

label :

Label to cut.

size :

Size limit.

Returns :

A new allocated string with the cutted label.


uc_utils_string_format4display ()

gchar *             uc_utils_string_format4display      (const gchar *label,
                                                         const gsize size);

format a given string to be displayed in UI.

See: uc_utils_string_cut()

label :

Label to format.

size :

Size limit.

Returns :

A new allocated string with the new formated label.


uc_utils_replace ()

gchar *             uc_utils_replace                    (const gchar *str,
                                                         const gchar *old,
                                                         const gchar *new);

Replace one or more characters in a given string.

See: uc_utils_replace1()

str :

String to work with.

old :

String to replace.

new :

New string to replace old with.

Returns :

A new allocated string.


uc_utils_replace1 ()

gchar *             uc_utils_replace1                   (gchar *string,
                                                         const gchar c1,
                                                         const char c2);

Replace a caracter by another (but do not allocate new memory for the result string).

See: uc_utils_replace()

string :

String to work with.

c1 :

Character to replace.

c2 :

Replacement.

Returns :

The modified string.


uc_utils_replacelr ()

gchar *             uc_utils_replacelr                  (gchar *string,
                                                         const gchar c);

Remove all line return in a given string.

string :

String to work with.

c :

Character for LR replacement.

Returns :

The modified string.


uc_utils_strchomp ()

gchar *             uc_utils_strchomp                   (gchar *string);

Remove all spaces or separators before a given string.

string :

A string.

Returns :

The modified string.


uc_utils_strchug ()

gchar *             uc_utils_strchug                    (gchar *string);

Remove all spaces or separator after a given string.

string :

A string.

Returns :

The modified string.


uc_utils_convert_uid2file ()

gchar *             uc_utils_convert_uid2file           (const guint32 uid);

Convert a cache uid to filename.

uid :

The uid of a UCLinkProperties node.

Returns :

The corresponding path. A new allocated string.


uc_utils_disk_free_enough ()

gboolean            uc_utils_disk_free_enough           (const guint32 requested_size);

Check if there is enought space on the partition to write on it.

requested_size :

The size needed on the partition.

Returns :

TRUE if it exist enough space on the parition of the given path to write on it.


uc_utils_get_gnome_proxy_conf ()

void                uc_utils_get_gnome_proxy_conf       (gchar **host,
                                                         guint *port);

Fill given args with the gconf values for the gnome network proxy settings.

host :

A string to fill for the host.

port :

A integer to fill for the port.


uc_utils_clean_tag_link_value ()

gchar *             uc_utils_clean_tag_link_value       (gchar *value);

Clean a link value string.

value :

String to clean.

Returns :

A cleaned value. A new allocated string.


uc_utils_search_string_next ()

gpointer            uc_utils_search_string_next         (gpointer buf,
                                                         const gchar *str,
                                                         const gchar limit_char);

Search for the next char after the searched string.

buf :

A gpointer to the source buffer.

str :

The string to search.

limit_char :

The char to stop if found.

Returns :

If found, retrun a pointer on the next char, else return the original pointer.


uc_utils_memcasecmp ()

gboolean            uc_utils_memcasecmp                 (const gchar *str1,
                                                         const gchar *str2);

Comparison between two strings, based on the length of the second string.

str1 :

First string to compare.

str2 :

Second string to compare.

Returns :

TRUE if the beginning of str1 match with str2.


uc_utils_rmfiles ()

void                uc_utils_rmfiles                    (const gchar *path);

Remove all files in a given directory.

path :

The path in witch deleting files.


uc_utils_mkdirs ()

gboolean            uc_utils_mkdirs                     (const gchar *path,
                                                         const gboolean create_all);

Make given path -- create intermediate paths if they don't exist -- and test if we are authorized to write in.

path :

Path to create.

create_all :

TRUE if we must create intermediar paths (mkdir -p).

Returns :

TRUE if all is ok.


uc_utils_rmdirs ()

void                uc_utils_rmdirs                     (const gchar *path,
                                                         const gboolean delete_all);

Remove a given path -- remove intermediate paths too.

path :

The path to remove.

delete_all :

If TRUE, remove all intermediar paths.


uc_utils_vector_length ()

guint32             uc_utils_vector_length              (gpointer data);

Calculate the length of the given vector.

data :

A vector.

Returns :

The length of a given vector.


uc_utils_strpbrk_or_eos ()

gchar *             uc_utils_strpbrk_or_eos             (const gchar *str,
                                                         const gchar *accept);

Return a pointer on a given char address or on the end of the passed string.

str :

A string.

accept :

A string with characters to search for.

Returns :

A pointer on the new offset.


uc_utils_strdup_delim ()

gchar *             uc_utils_strdup_delim               (const gchar *begin,
                                                         const gchar *end);

Make a string with 2 given pointers.

begin :

The source position.

end :

The end position.

Returns :

A new allocated string.


uc_utils_array_is_in ()

gboolean            uc_utils_array_is_in                (const gchar *item,
                                                         gpointer array,
                                                         const guint size);

Search for the first argument in the second argument vector.

item :

Item to search for.

array :

Vector to search in.

size :

Size of the vector.

Returns :

TRUE if the first argument is in the second argument vector.


uc_utils_test_socket_open ()

gboolean            uc_utils_test_socket_open           (const guint sock);

Check if a connection if alive or not. -> taken from wget source code

sock :

The socket to test.

Returns :

TRUE if it is alive.


uc_utils_get_gnome_browser_conf ()

gchar *             uc_utils_get_gnome_browser_conf     (void);

Get the current default gnome web browser or "mozilla" if it does not find it.

Returns :

The current gnome default web browser