utils

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

Functions

gboolean uc_utils_str_is_not_alphanum ()
void uc_utils_swap_file_proto_option ()
void uc_utils_clear_container ()
time_t uc_utils_http_atotm ()
gchar * uc_utils_url_reencode_escapes ()
gboolean uc_utils_ftp_code_search ()
gchar * uc_utils_get_string_from_size ()
gchar * uc_utils_get_server_from_header_field ()
void uc_utils_copy ()
gboolean uc_utils_get_meta_refresh_location ()
gchar * uc_utils_to_utf8 ()
void uc_utils_copy_files ()
void uc_utils_debug ()
void uc_utils_debug_dump_link_properties ()
void uc_utils_set_userfriendly_treeview_column ()
gchar * uc_utils_get_file_content ()
void uc_utils_split_email ()
gchar * uc_utils_get_mx ()
gboolean uc_utils_get_yesno ()
gboolean uc_utils_mx_is_valid ()
gchar * uc_utils_get_ip ()
UCEmailStatus uc_utils_email_is_valid ()
gchar * uc_utils_string_cut ()
gchar * uc_utils_string_format4display ()
gchar * uc_utils_replace ()
gchar * uc_utils_replace1 ()
gchar * uc_utils_replacelr ()
gchar * uc_utils_convert_uid2file ()
void uc_utils_get_gnome_proxy_conf ()
gchar * uc_utils_clean_tag_link_value ()
gpointer uc_utils_search_string_next ()
gboolean uc_utils_memcasecmp ()
void uc_utils_rmfiles ()
gboolean uc_utils_mkdirs ()
void uc_utils_rmdirs ()
guint32 uc_utils_vector_length ()
gchar * uc_utils_strpbrk_or_eos ()
gchar * uc_utils_strdup_delim ()
gboolean uc_utils_test_socket_open ()
gchar * uc_utils_get_gnome_browser_conf ()
gboolean uc_utils_get_auth_fields ()
gchar * uc_utils_build_auth_line ()

Description

Functions

uc_utils_str_is_not_alphanum ()

gboolean
uc_utils_str_is_not_alphanum (const gchar *str);


uc_utils_swap_file_proto_option ()

void
uc_utils_swap_file_proto_option (const gboolean begin);


uc_utils_clear_container ()

void
uc_utils_clear_container (GtkContainer *container);


uc_utils_http_atotm ()

time_t
uc_utils_http_atotm (const gchar *time_string);


uc_utils_url_reencode_escapes ()

gchar *
uc_utils_url_reencode_escapes (const gchar *s);


uc_utils_ftp_code_search ()

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

Search for a given FTP code in a buffer.

Parameters

buffer

a buffer containing some FTP output stuff.

 

code

the FTP code to search for (string format).

 

len

length of the given buffer buffer .

 

Returns

TRUE if the given FTP code code has been found in buffer .


uc_utils_get_string_from_size ()

gchar *
uc_utils_get_string_from_size (const gsize size);

Convert a size in string format (with unit indication (KB, MB...)).

Parameters

size

size to convert in string

 

Returns

a string representation of the given size size .


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.

Parameters

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.

Parameters

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 with a value of 0, replace the current page URL with it.

Parameters

prop

A UCLinkProperties node.

 

tag

A UCHTMLTag tag.

 

Returns

TRUE if there was a REFRESH META tag.


uc_utils_to_utf8 ()

gchar *
uc_utils_to_utf8 (const gchar *data);

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

Parameters

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.

Parameters

src

Source path.

 

dest

Destination path.

 

uc_utils_debug ()

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

Display debug informations.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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 E-Mail address. user and domain argument are filled with new allocated strings.

Parameters

email

E-Mail to work with.

 

user

Pointer for the "user" part of the E-Mail.

 

domain

Pointer for the "domain" part of the E-Mail.

 

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

Parameters

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".

Parameters

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.

Parameters

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.

Parameters

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 E-Mail syntax and MX if required.

Parameters

email

E-Mail to check.

 

check_mx

TRUE if we also must check the MX.

 

Returns

The UCEmailStatus status of the E-Mail. 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()

Parameters

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()

Parameters

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()

Parameters

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()

Parameters

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.

Parameters

string

String to work with.

 

c

Character for LR replacement.

 

Returns

The modified string.


uc_utils_convert_uid2file ()

gchar *
uc_utils_convert_uid2file (const guint32 uid);

Convert a cache uid to filename.

Parameters

uid

The uid of a UCLinkProperties node.

 

Returns

The corresponding path. A new allocated string.


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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

begin

The source position.

 

end

The end position.

 

Returns

A new allocated string.


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

Parameters

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


uc_utils_get_auth_fields ()

gboolean
uc_utils_get_auth_fields (GladeXML *g,
                          GtkWidget *w_auth_user,
                          GtkWidget *w_auth_password,
                          gchar **auth_user,
                          gchar **auth_password,
                          gchar **auth_line);

Get user/password from a authentication dialog and build the line for basic authentication to pass to HTTP headers.

See: uc_utils_build_auth_line()

Parameters

g

a GladeXML object.

 

w_auth_user

GtkWidget containing auth user string

 

w_auth_password

GtkWidget containing auth password string

 

auth_user

user will be store here.

 

auth_password

password will be store here.

 

auth_line

authentication line will be store here.

 

Returns

TRUE if user and password have been entered.


uc_utils_build_auth_line ()

gchar *
uc_utils_build_auth_line (const gchar *auth_user,
                          const gchar *auth_password);

Build the line for basic authentication to pass to HTTP headers.

See: uc_utils_get_auth_fields()

Parameters

auth_user

user

 

auth_password

password

 

Returns

a new memoty allocated string containing basic authentication line.

Types and Values