pidgin 2.14.14dev
util.h File Reference

Utility Functions. More...

#include <stdio.h>
#include "account.h"
#include "signals.h"
#include "xmlnode.h"
#include "notify.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _PurpleMenuAction
 
struct  _PurpleKeyValuePair
 A key-value pair. More...
 

Typedefs

typedef struct _PurpleUtilFetchUrlData PurpleUtilFetchUrlData
 An opaque structure representing a URL request. More...
 
typedef struct _PurpleMenuAction PurpleMenuAction
 
typedef struct _PurpleKeyValuePair PurpleKeyValuePair
 A key-value pair. More...
 
typedef char *(* PurpleInfoFieldFormatCallback) (const char *field, size_t len)
 

Functions

PurpleMenuActionpurple_menu_action_new (const char *label, PurpleCallback callback, gpointer data, GList *children)
 Creates a new PurpleMenuAction. More...
 
void purple_menu_action_free (PurpleMenuAction *act)
 Frees a PurpleMenuAction. More...
 
void purple_util_set_current_song (const char *title, const char *artist, const char *album)
 Set the appropriate presence values for the currently playing song. More...
 
char * purple_util_format_song_info (const char *title, const char *artist, const char *album, gpointer unused)
 Format song information. More...
 
Utility Subsystem <br>
void purple_util_init (void)
 Initializes the utility subsystem. More...
 
void purple_util_uninit (void)
 Uninitializes the util subsystem. More...
 
Base16 Functions <br>
gchar * purple_base16_encode (const guchar *data, gsize len)
 Converts a chunk of binary data to its base-16 equivalent. More...
 
guchar * purple_base16_decode (const char *str, gsize *ret_len)
 Converts an ASCII string of base-16 encoded data to the binary equivalent. More...
 
gchar * purple_base16_encode_chunked (const guchar *data, gsize len)
 Converts a chunk of binary data to a chunked base-16 representation (handy for key fingerprints) More...
 
Base64 Functions <br>
gchar * purple_base64_encode (const guchar *data, gsize len)
 Converts a chunk of binary data to its base-64 equivalent. More...
 
guchar * purple_base64_decode (const char *str, gsize *ret_len)
 Converts an ASCII string of base-64 encoded data to the binary equivalent. More...
 
Quoted Printable Functions <br>
guchar * purple_quotedp_decode (const char *str, gsize *ret_len)
 Converts a quoted printable string back to its readable equivalent. More...
 
MIME Functions <br>
char * purple_mime_decode_field (const char *str)
 Converts a MIME header field string back to its readable equivalent according to RFC 2047. More...
 
Markup Functions <br>
gchar * purple_markup_escape_text (const gchar *text, gssize length)
 Escapes special characters in a plain-text string so they display correctly as HTML. More...
 
gboolean purple_markup_find_tag (const char *needle, const char *haystack, const char **start, const char **end, GData **attributes)
 Finds an HTML tag matching the given name. More...
 
gboolean purple_markup_extract_info_field (const char *str, int len, PurpleNotifyUserInfo *user_info, const char *start_token, int skip, const char *end_token, char check_value, const char *no_value_token, const char *display_name, gboolean is_link, const char *link_prefix, PurpleInfoFieldFormatCallback format_cb)
 Extracts a field of data from HTML. More...
 
void purple_markup_html_to_xhtml (const char *html, char **dest_xhtml, char **dest_plain)
 Converts HTML markup to XHTML. More...
 
char * purple_markup_strip_html (const char *str)
 Strips HTML tags from a string. More...
 
char * purple_markup_linkify (const char *str)
 Adds the necessary HTML code to turn URIs into HTML links in a string. More...
 
char * purple_unescape_text (const char *text)
 Unescapes HTML entities to their literal characters in the text. More...
 
char * purple_unescape_html (const char *html)
 Unescapes HTML entities to their literal characters and converts "<br>" to "\n". More...
 
char * purple_markup_slice (const char *str, guint x, guint y)
 Returns a newly allocated substring of the HTML UTF-8 string "str". More...
 
char * purple_markup_get_tag_name (const char *tag)
 Returns a newly allocated string containing the name of the tag located at "tag". More...
 
const char * purple_markup_unescape_entity (const char *text, int *length)
 Returns a constant string of the character representation of the HTML entity pointed to by text. More...
 
char * purple_markup_get_css_property (const gchar *style, const gchar *opt)
 Returns a newly allocated string containing the value of the CSS property specified in opt. More...
 
gboolean purple_markup_is_rtl (const char *html)
 Check if the given HTML contains RTL text. More...
 
Path/Filename Functions <br>
const gchar * purple_home_dir (void)
 Returns the user's home directory. More...
 
const char * purple_user_dir (void)
 Returns the purple settings directory in the user's home directory. More...
 
void purple_util_set_user_dir (const char *dir)
 Define a custom purple settings directory, overriding the default (user's home directory/.purple) More...
 
int purple_build_dir (const char *path, int mode)
 Builds a complete path from the root, making any directories along the path which do not already exist. More...
 
gboolean purple_util_write_data_to_file (const char *filename, const char *data, gssize size)
 Write a string of data to a file of the given name in the Purple user directory ($HOME/.purple by default). More...
 
gboolean purple_util_write_data_to_file_absolute (const char *filename_full, const char *data, gssize size)
 Write data to a file using the absolute path. More...
 
xmlnodepurple_util_read_xml_from_file (const char *filename, const char *description)
 Read the contents of a given file and parse the results into an xmlnode tree structure. More...
 
FILE * purple_mkstemp (char **path, gboolean binary)
 Creates a temporary file and returns a file pointer to it. More...
 
const char * purple_util_get_image_extension (gconstpointer data, size_t len)
 Returns an extension corresponding to the image data's file type. More...
 
char * purple_util_get_image_checksum (gconstpointer image_data, size_t image_len)
 Returns a SHA-1 hash string of the data passed in.
 
char * purple_util_get_image_filename (gconstpointer image_data, size_t image_len)
 
Environment Detection Functions <br>
gboolean purple_program_is_valid (const char *program)
 Checks if the given program name is valid and executable. More...
 
gboolean purple_running_gnome (void)
 Check if running GNOME. More...
 
gboolean purple_running_kde (void)
 Check if running KDE. More...
 
gboolean purple_running_osx (void)
 Check if running OS X. More...
 
char * purple_fd_get_ip (int fd)
 Returns the IP address from a socket file descriptor. More...
 
int purple_socket_get_family (int fd)
 Returns the address family of a socket. More...
 
gboolean purple_socket_speaks_ipv4 (int fd)
 Returns TRUE if a socket is capable of speaking IPv4. More...
 
String Functions <br>
gboolean purple_strequal (const gchar *left, const gchar *right)
 Tests two strings for equality. More...
 
const char * purple_normalize (const PurpleAccount *account, const char *str)
 Normalizes a string, so that it is suitable for comparison. More...
 
const char * purple_normalize_nocase (const PurpleAccount *account, const char *str)
 Normalizes a string, so that it is suitable for comparison. More...
 
gboolean purple_str_has_prefix (const char *s, const char *p)
 Compares two strings to see if the first contains the second as a proper prefix. More...
 
gboolean purple_str_has_suffix (const char *s, const char *x)
 Compares two strings to see if the second is a proper suffix of the first. More...
 
gchar * purple_strdup_withhtml (const gchar *src)
 Duplicates a string and replaces all newline characters from the source string with HTML linebreaks. More...
 
char * purple_str_add_cr (const char *str)
 Ensures that all linefeeds have a matching carriage return. More...
 
void purple_str_strip_char (char *str, char thechar)
 Strips all instances of the given character from the given string. More...
 
void purple_util_chrreplace (char *string, char delimiter, char replacement)
 Given a string, this replaces all instances of one character with another. More...
 
gchar * purple_strreplace (const char *string, const char *delimiter, const char *replacement)
 Given a string, this replaces one substring with another and returns a newly allocated string. More...
 
char * purple_utf8_ncr_encode (const char *in)
 Given a string, this replaces any utf-8 substrings in that string with the corresponding numerical character reference, and returns a newly allocated string. More...
 
char * purple_utf8_ncr_decode (const char *in)
 Given a string, this replaces any numerical character references in that string with the corresponding actual utf-8 substrings, and returns a newly allocated string. More...
 
gchar * purple_strcasereplace (const char *string, const char *delimiter, const char *replacement)
 Given a string, this replaces one substring with another ignoring case and returns a newly allocated string. More...
 
const char * purple_strcasestr (const char *haystack, const char *needle)
 This is like strstr, except that it ignores ASCII case in searching for the substring. More...
 
char * purple_str_size_to_units (size_t size)
 Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc.) More...
 
char * purple_str_seconds_to_string (guint sec)
 Converts seconds into a human-readable form. More...
 
char * purple_str_binary_to_ascii (const unsigned char *binary, guint len)
 Converts a binary string into a NUL terminated ascii string, replacing nonascii characters and characters below SPACE (including NUL) into \xyy, where yy are two hex digits. More...
 

Date/Time Functions <br>

#define PURPLE_NO_TZ_OFF   -500000
 Used by purple_str_to_time to indicate no timezone offset was specified in the timestamp string. More...
 
const char * purple_utf8_strftime (const char *format, const struct tm *tm)
 Formats a time into the specified format. More...
 
const char * purple_get_tzoff_str (const struct tm *tm, gboolean iso)
 Gets a string representation of the local timezone offset. More...
 
const char * purple_date_format_short (const struct tm *tm)
 Formats a time into the user's preferred short date format. More...
 
const char * purple_date_format_long (const struct tm *tm)
 Formats a time into the user's preferred short date plus time format. More...
 
const char * purple_date_format_full (const struct tm *tm)
 Formats a time into the user's preferred full date and time format. More...
 
const char * purple_time_format (const struct tm *tm)
 Formats a time into the user's preferred time format. More...
 
time_t purple_time_build (int year, int month, int day, int hour, int min, int sec)
 Builds a time_t from the supplied information. More...
 
time_t purple_str_to_time (const char *timestamp, gboolean utc, struct tm *tm, long *tz_off, const char **rest)
 Parses a timestamp in jabber, ISO8601, or MM/DD/YYYY format and returns a time_t. More...
 

URI/URL Functions <br>

#define purple_util_fetch_url(url, full, user_agent, http11, cb, data)
 Fetches the data from a URL, and passes it to a callback function. More...
 
#define purple_util_fetch_url_len(url, full, user_agent, http11, max_len, cb, data)
 Fetches the data from a URL, and passes it to a callback function. More...
 
#define purple_add_eight(x)   ((x)+8)
 Adds 8 to something. More...
 
typedef void(* PurpleUtilFetchUrlCallback) (PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
 This is the signature used for functions that act as the callback to purple_util_fetch_url() or purple_util_fetch_url_request(). More...
 
void purple_got_protocol_handler_uri (const char *uri)
 
gboolean purple_url_parse (const char *url, char **ret_host, int *ret_port, char **ret_path, char **ret_user, char **ret_passwd)
 Parses a URL, returning its host, port, file path, username and password. More...
 
PurpleUtilFetchUrlDatapurple_util_fetch_url_request (const gchar *url, gboolean full, const gchar *user_agent, gboolean http11, const gchar *request, gboolean include_headers, PurpleUtilFetchUrlCallback callback, gpointer data)
 Fetches the data from a URL, and passes it to a callback function. More...
 
PurpleUtilFetchUrlDatapurple_util_fetch_url_request_len (const gchar *url, gboolean full, const gchar *user_agent, gboolean http11, const gchar *request, gboolean include_headers, gssize max_len, PurpleUtilFetchUrlCallback callback, gpointer data)
 Fetches the data from a URL, and passes it to a callback function. More...
 
PurpleUtilFetchUrlDatapurple_util_fetch_url_request_len_with_account (PurpleAccount *account, const gchar *url, gboolean full, const gchar *user_agent, gboolean http11, const gchar *request, gboolean include_headers, gssize max_len, PurpleUtilFetchUrlCallback callback, gpointer data)
 Fetches the data from a URL, and passes it to a callback function. More...
 
PurpleUtilFetchUrlDatapurple_util_fetch_url_request_data_len_with_account (PurpleAccount *account, const char *url, gboolean full, const char *user_agent, gboolean http11, const char *request, gsize request_len, gboolean include_headers, gssize max_len, PurpleUtilFetchUrlCallback callback, void *user_data)
 Fetches the data from a URL, and passes it to a callback function. More...
 
void purple_util_fetch_url_cancel (PurpleUtilFetchUrlData *url_data)
 Cancel a pending URL request started with either purple_util_fetch_url_request() or purple_util_fetch_url(). More...
 
const char * purple_url_decode (const char *str)
 Decodes a URL into a plain string. More...
 
const char * purple_url_encode (const char *str)
 Encodes a URL into an escaped string. More...
 
gboolean purple_email_is_valid (const char *address)
 Checks if the given email address is syntactically valid. More...
 
gboolean purple_ip_address_is_valid (const char *ip)
 Checks if the given IP address is a syntactically valid IPv4 address. More...
 
gboolean purple_ipv4_address_is_valid (const char *ip)
 Checks if the given IP address is a syntactically valid IPv4 address. More...
 
gboolean purple_ipv6_address_is_valid (const char *ip)
 Checks if the given IP address is a syntactically valid IPv6 address. More...
 
GList * purple_uri_list_extract_uris (const gchar *uri_list)
 This function extracts a list of URIs from the a "text/uri-list" string. More...
 
GList * purple_uri_list_extract_filenames (const gchar *uri_list)
 This function extracts a list of filenames from a "text/uri-list" string. More...
 
char * purple_uri_escape_for_open (const char *unescaped)
 This function escapes any characters that might be interpreted by the shell when executing a program to open a URI on some systems. More...
 
gchar * purple_utf8_try_convert (const char *str)
 Attempts to convert a string to UTF-8 from an unknown encoding. More...
 
gchar * purple_utf8_salvage (const char *str)
 Salvages the valid UTF-8 characters from a string, replacing any invalid characters with a filler character (currently hardcoded to '?'). More...
 
gchar * purple_utf8_strip_unprintables (const gchar *str)
 Removes unprintable characters from a UTF-8 string. More...
 
const gchar * purple_gai_strerror (gint errnum)
 Return the UTF-8 version of gai_strerror(). More...
 
int purple_utf8_strcasecmp (const char *a, const char *b)
 Compares two UTF-8 strings case-insensitively. More...
 
gboolean purple_utf8_has_word (const char *haystack, const char *needle)
 Case insensitive search for a word in a string. More...
 
void purple_print_utf8_to_console (FILE *filestream, char *message)
 Prints a UTF-8 message to the given file stream. More...
 
gboolean purple_message_meify (char *message, gssize len)
 Checks for messages starting (post-HTML) with "/me ", including the space. More...
 
char * purple_text_strip_mnemonic (const char *in)
 Removes the underscore characters from a string used identify the mnemonic character. More...
 
const char * purple_unescape_filename (const char *str)
 Does the reverse of purple_escape_filename. More...
 
const char * purple_escape_filename (const char *str)
 Escapes filesystem-unfriendly characters from a filename. More...
 
const char * _purple_oscar_convert (const char *act, const char *protocol)
 This is added temporarily to assist the split of oscar into aim and icq. More...
 
void purple_restore_default_signal_handlers (void)
 Restore default signal handlers for signals which might reasonably have handlers. More...
 
const gchar * purple_get_host_name (void)
 Gets the host name of the machine. More...
 
gchar * purple_uuid_random (void)
 Returns a type 4 (random) UUID. More...
 

Detailed Description

Utility Functions.

Definition in file util.h.

Macro Definition Documentation

◆ purple_add_eight

#define purple_add_eight (   x)    ((x)+8)

Adds 8 to something.

Blame SimGuy.

Parameters
xThe number to add 8 to.
Returns
x + 8

Definition at line 1468 of file util.h.

◆ PURPLE_NO_TZ_OFF

#define PURPLE_NO_TZ_OFF   -500000

Used by purple_str_to_time to indicate no timezone offset was specified in the timestamp string.

Definition at line 391 of file util.h.

◆ purple_util_fetch_url

#define purple_util_fetch_url (   url,
  full,
  user_agent,
  http11,
  cb,
  data 
)
Value:
purple_util_fetch_url_request(url, full, user_agent, http11, NULL, \
FALSE, cb, data);
PurpleUtilFetchUrlData * purple_util_fetch_url_request(const gchar *url, gboolean full, const gchar *user_agent, gboolean http11, const gchar *request, gboolean include_headers, PurpleUtilFetchUrlCallback callback, gpointer data)
Fetches the data from a URL, and passes it to a callback function.

Fetches the data from a URL, and passes it to a callback function.

Parameters
urlThe URL.
fullTRUE if this is the full URL, or FALSE if it's a partial URL.
user_agentThe user agent field to use, or NULL.
http11TRUE if HTTP/1.1 should be used to download the file.
cbThe callback function.
dataThe user data to pass to the callback function.

Definition at line 1123 of file util.h.

◆ purple_util_fetch_url_len

#define purple_util_fetch_url_len (   url,
  full,
  user_agent,
  http11,
  max_len,
  cb,
  data 
)
Value:
purple_util_fetch_url_request_len(url, full, user_agent, http11, NULL, \
FALSE, max_len, cb, data);
PurpleUtilFetchUrlData * purple_util_fetch_url_request_len(const gchar *url, gboolean full, const gchar *user_agent, gboolean http11, const gchar *request, gboolean include_headers, gssize max_len, PurpleUtilFetchUrlCallback callback, gpointer data)
Fetches the data from a URL, and passes it to a callback function.

Fetches the data from a URL, and passes it to a callback function.

Parameters
urlThe URL.
fullTRUE if this is the full URL, or FALSE if it's a partial URL.
user_agentThe user agent field to use, or NULL.
http11TRUE if HTTP/1.1 should be used to download the file.
max_lenThe maximum number of bytes to retrieve (-1 for unlimited)
cbThe callback function.
dataThe user data to pass to the callback function.
Deprecated:
In 3.0.0, we'll rename this to "purple_util_fetch_url" and get rid of the old one

Definition at line 1140 of file util.h.

Typedef Documentation

◆ PurpleInfoFieldFormatCallback

typedef char *(* PurpleInfoFieldFormatCallback) (const char *field, size_t len)

Definition at line 62 of file util.h.

◆ PurpleKeyValuePair

A key-value pair.

This is used by, among other things, purple_gtk_combo* functions to pass in a list of key-value pairs so it can display a user-friendly value.

Definition at line 42 of file util.h.

◆ PurpleMenuAction

Definition at line 40 of file util.h.

◆ PurpleUtilFetchUrlCallback

typedef void(* PurpleUtilFetchUrlCallback) (PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)

This is the signature used for functions that act as the callback to purple_util_fetch_url() or purple_util_fetch_url_request().

Parameters
url_dataThe same value that was returned when you called purple_fetch_url() or purple_fetch_url_request().
user_dataThe user data that your code passed into either purple_util_fetch_url() or purple_util_fetch_url_request().
url_textThis will be NULL on error. Otherwise this will contain the contents of the URL.
len0 on error, otherwise this is the length of buf.
error_messageIf something went wrong then this will contain a descriptive error message, and buf will be NULL and len will be 0.

Definition at line 1110 of file util.h.

◆ PurpleUtilFetchUrlData

typedef struct _PurpleUtilFetchUrlData PurpleUtilFetchUrlData

An opaque structure representing a URL request.

Can be used to cancel the request.

Definition at line 38 of file util.h.

Function Documentation

◆ _purple_oscar_convert()

const char * _purple_oscar_convert ( const char *  act,
const char *  protocol 
)

This is added temporarily to assist the split of oscar into aim and icq.

This should not be used by plugins.

Deprecated:
This function should not be used in new code and should be removed in 3.0.0. The aim/icq prpl split happened a long time ago, and we don't need to keep migrating old data.

◆ purple_base16_decode()

guchar * purple_base16_decode ( const char *  str,
gsize *  ret_len 
)

Converts an ASCII string of base-16 encoded data to the binary equivalent.

Parameters
strThe base-16 string to convert to raw data.
ret_lenThe length of the returned data. You can pass in NULL if you're sure that you know the length of the decoded data, or if you know you'll be able to use strlen to determine the length, etc.
Returns
The raw data. Must be g_free'd when no longer needed.
See also
purple_base16_encode()

◆ purple_base16_encode()

gchar * purple_base16_encode ( const guchar *  data,
gsize  len 
)

Converts a chunk of binary data to its base-16 equivalent.

Parameters
dataThe data to convert.
lenThe length of the data.
Returns
The base-16 string in the ASCII encoding. Must be g_free'd when no longer needed.
See also
purple_base16_decode()

◆ purple_base16_encode_chunked()

gchar * purple_base16_encode_chunked ( const guchar *  data,
gsize  len 
)

Converts a chunk of binary data to a chunked base-16 representation (handy for key fingerprints)

Example output: 01:23:45:67:89:AB:CD:EF

Parameters
dataThe data to convert.
lenThe length of the data.
Returns
The base-16 string in the ASCII chunked encoding. Must be g_free'd when no longer needed.

◆ purple_base64_decode()

guchar * purple_base64_decode ( const char *  str,
gsize *  ret_len 
)

Converts an ASCII string of base-64 encoded data to the binary equivalent.

Parameters
strThe base-64 string to convert to raw data.
ret_lenThe length of the returned data. You can pass in NULL if you're sure that you know the length of the decoded data, or if you know you'll be able to use strlen to determine the length, etc.
Returns
The raw data. Must be g_free'd when no longer needed.
See also
purple_base64_encode()

◆ purple_base64_encode()

gchar * purple_base64_encode ( const guchar *  data,
gsize  len 
)

Converts a chunk of binary data to its base-64 equivalent.

Parameters
dataThe data to convert.
lenThe length of the data.
Returns
The base-64 string in the ASCII encoding. Must be g_free'd when no longer needed.
See also
purple_base64_decode()

◆ purple_build_dir()

int purple_build_dir ( const char *  path,
int  mode 
)

Builds a complete path from the root, making any directories along the path which do not already exist.

Parameters
pathThe path you wish to create. Note that it must start from the root or this function will fail.
modeUnix-style permissions for this directory.
Returns
0 for success, nonzero on any error.

◆ purple_date_format_full()

const char * purple_date_format_full ( const struct tm *  tm)

Formats a time into the user's preferred full date and time format.

The returned string is stored in a static buffer, so the result should be g_strdup()'d if it's going to be kept.

Parameters
tmThe time to format, or NULL to use the current local time
Returns
The date and time, formatted as per the user's settings.

◆ purple_date_format_long()

const char * purple_date_format_long ( const struct tm *  tm)

Formats a time into the user's preferred short date plus time format.

The returned string is stored in a static buffer, so the result should be g_strdup()'d if it's going to be kept.

Parameters
tmThe time to format, or NULL to use the current local time
Returns
The timestamp, formatted as per the user's settings.

◆ purple_date_format_short()

const char * purple_date_format_short ( const struct tm *  tm)

Formats a time into the user's preferred short date format.

The returned string is stored in a static buffer, so the result should be g_strdup()'d if it's going to be kept.

Parameters
tmThe time to format, or NULL to use the current local time
Returns
The date, formatted as per the user's settings.

◆ purple_email_is_valid()

gboolean purple_email_is_valid ( const char *  address)

Checks if the given email address is syntactically valid.

Parameters
addressThe email address to validate.
Returns
True if the email address is syntactically correct.

◆ purple_escape_filename()

const char * purple_escape_filename ( const char *  str)

Escapes filesystem-unfriendly characters from a filename.

Parameters
strThe string to translate.
Returns
The resulting string.

◆ purple_fd_get_ip()

char * purple_fd_get_ip ( int  fd)

Returns the IP address from a socket file descriptor.

Parameters
fdThe socket file descriptor.
Returns
The IP address, or NULL on error.

◆ purple_gai_strerror()

const gchar * purple_gai_strerror ( gint  errnum)

Return the UTF-8 version of gai_strerror().

It calls gai_strerror() then converts the result to UTF-8. This function is analogous to g_strerror().

Parameters
errnumThe error code.
Returns
The UTF-8 error message.
Since
2.4.0

◆ purple_get_host_name()

const gchar * purple_get_host_name ( void  )

Gets the host name of the machine.

If it not possible to determine the host name, "localhost" is returned

Note
The return value of this function must not be modified or freed.
Returns
The hostname

◆ purple_get_tzoff_str()

const char * purple_get_tzoff_str ( const struct tm *  tm,
gboolean  iso 
)

Gets a string representation of the local timezone offset.

Parameters
tmThe time to get the timezone for
isoTRUE to format the offset according to ISO-8601, FALSE to not substitute 'Z' for 0 offset, and to not separate hours and minutes with a colon.

◆ purple_home_dir()

const gchar * purple_home_dir ( void  )

Returns the user's home directory.

Returns
The user's home directory.
See also
purple_user_dir()

◆ purple_ip_address_is_valid()

gboolean purple_ip_address_is_valid ( const char *  ip)

Checks if the given IP address is a syntactically valid IPv4 address.

Parameters
ipThe IP address to validate.
Returns
True if the IP address is syntactically correct.
Deprecated:
This function will be replaced with one that validates as either IPv4 or IPv6 in 3.0.0. If you don't want this, behavior, use one of the more specific functions.

◆ purple_ipv4_address_is_valid()

gboolean purple_ipv4_address_is_valid ( const char *  ip)

Checks if the given IP address is a syntactically valid IPv4 address.

Parameters
ipThe IP address to validate.
Returns
True if the IP address is syntactically correct.
Since
2.6.0

◆ purple_ipv6_address_is_valid()

gboolean purple_ipv6_address_is_valid ( const char *  ip)

Checks if the given IP address is a syntactically valid IPv6 address.

Parameters
ipThe IP address to validate.
Returns
True if the IP address is syntactically correct.
Since
2.6.0

◆ purple_markup_escape_text()

gchar * purple_markup_escape_text ( const gchar *  text,
gssize  length 
)

Escapes special characters in a plain-text string so they display correctly as HTML.

For example, & is replaced with & and < is replaced with <

This is exactly the same as g_markup_escape_text(), except that it does not change ' to ' because ' is not a valid HTML 4 entity, and is displayed literally in IE7.

Since
2.6.0

◆ purple_markup_extract_info_field()

gboolean purple_markup_extract_info_field ( const char *  str,
int  len,
PurpleNotifyUserInfo *  user_info,
const char *  start_token,
int  skip,
const char *  end_token,
char  check_value,
const char *  no_value_token,
const char *  display_name,
gboolean  is_link,
const char *  link_prefix,
PurpleInfoFieldFormatCallback  format_cb 
)

Extracts a field of data from HTML.

This is a scary function. It used to be used for MSN and Yahoo prpls, but since those prpls have been removed, this is now deprecated.

Parameters
strThe string to parse.
lenThe size of str.
user_infoThe destination PurpleNotifyUserInfo to which the new field info should be added.
start_tokenThe beginning token.
skipThe number of characters to skip after the start token.
end_tokenThe ending token.
check_valueThe value that the last character must meet.
no_value_tokenThe token indicating no value is given.
display_nameThe short descriptive name to display for this token.
is_linkTRUE if this should be a link, or FALSE otherwise.
link_prefixThe prefix for the link.
format_cbA callback to format the value before adding it.
Returns
TRUE if successful, or FALSE otherwise.

◆ purple_markup_find_tag()

gboolean purple_markup_find_tag ( const char *  needle,
const char *  haystack,
const char **  start,
const char **  end,
GData **  attributes 
)

Finds an HTML tag matching the given name.

This locates an HTML tag's start and end, and stores its attributes in a GData hash table. The names of the attributes are lower-cased in the hash table, and the name of the tag is case insensitive.

Parameters
needleThe name of the tag
haystackThe null-delimited string to search in
startA pointer to the start of the tag if found
endA pointer to the end of the tag if found
attributesThe attributes, if the tag was found. This should be freed with g_datalist_clear().
Returns
TRUE if the tag was found

◆ purple_markup_get_css_property()

char * purple_markup_get_css_property ( const gchar *  style,
const gchar *  opt 
)

Returns a newly allocated string containing the value of the CSS property specified in opt.

The style argument is expected to point to a HTML inline CSS. The function will seek for the CSS property and return its value.

For example, purple_markup_get_css_property("direction:rtl;color:#dc4d1b;", "color") would return "#dc4d1b".

On error or if the requested property was not found, the function returns NULL.

Parameters
styleA string containing the inline CSS text.
optThe requested CSS property.
Returns
The value of the requested CSS property.

◆ purple_markup_get_tag_name()

char * purple_markup_get_tag_name ( const char *  tag)

Returns a newly allocated string containing the name of the tag located at "tag".

Tag is expected to point to a '<', and contain a '>' sometime after that. If there is no '>' and the string is not NUL terminated, this function can be expected to segfault.

Parameters
tagThe string starting a HTML tag.
Returns
A string containing the name of the tag.

◆ purple_markup_html_to_xhtml()

void purple_markup_html_to_xhtml ( const char *  html,
char **  dest_xhtml,
char **  dest_plain 
)

Converts HTML markup to XHTML.

Parameters
htmlThe HTML markup.
dest_xhtmlThe destination XHTML output.
dest_plainThe destination plain-text output.

◆ purple_markup_is_rtl()

gboolean purple_markup_is_rtl ( const char *  html)

Check if the given HTML contains RTL text.

Parameters
htmlThe HTML text.
Returns
TRUE if the text contains RTL text, FALSE otherwise.
Since
2.6.0

◆ purple_markup_linkify()

char * purple_markup_linkify ( const char *  str)

Adds the necessary HTML code to turn URIs into HTML links in a string.

Parameters
strThe string to linkify.
Returns
The new string with all URIs surrounded in standard HTML tags. You must g_free this string when finished with it.

◆ purple_markup_slice()

char * purple_markup_slice ( const char *  str,
guint  x,
guint  y 
)

Returns a newly allocated substring of the HTML UTF-8 string "str".

The markup is preserved such that the substring will have the same formatting as original string, even though some tags may have been opened before "x", or may close after "y". All open tags are closed at the end of the returned string, in the proper order.

Note that x and y are in character offsets, not byte offsets, and are offsets into an unformatted version of str. Because of this, this function may be sensitive to changes in GtkIMHtml and may break when used with other UI's. libpurple users are encouraged to report and work out any problems encountered.

Parameters
strThe input NUL terminated, HTML, UTF-8 (or ASCII) string.
xThe character offset into an unformatted version of str to begin at.
yThe character offset (into an unformatted vesion of str) of one past the last character to include in the slice.
Returns
The HTML slice of string, with all formatting retained.

◆ purple_markup_strip_html()

char * purple_markup_strip_html ( const char *  str)

Strips HTML tags from a string.

Parameters
strThe string to strip HTML from.
Returns
The new string without HTML. You must g_free this string when finished with it.

◆ purple_markup_unescape_entity()

const char * purple_markup_unescape_entity ( const char *  text,
int *  length 
)

Returns a constant string of the character representation of the HTML entity pointed to by text.

For example, purple_markup_unescape_entity("&amp;") will return "&". The text variable is expected to point to an '&', the first character of the entity. If given an unrecognized entity, the function returns NULL.

Note that this function, unlike purple_unescape_html(), does not search the string for the entity, does not replace the entity, and does not return a newly allocated string.

Parameters
textA string containing an HTML entity.
lengthIf not NULL, the string length of the entity is stored in this location.
Returns
A constant string containing the character representation of the given entity.

◆ purple_menu_action_free()

void purple_menu_action_free ( PurpleMenuAction act)

Frees a PurpleMenuAction.

Parameters
actThe PurpleMenuAction to free.

◆ purple_menu_action_new()

PurpleMenuAction * purple_menu_action_new ( const char *  label,
PurpleCallback  callback,
gpointer  data,
GList *  children 
)

Creates a new PurpleMenuAction.

Parameters
labelThe text label to display for this action.
callbackThe function to be called when the action is used on the selected item.
dataAdditional data to be passed to the callback.
childrenA GList of PurpleMenuActions to be added as a submenu of the action.
Returns
The PurpleMenuAction.

◆ purple_message_meify()

gboolean purple_message_meify ( char *  message,
gssize  len 
)

Checks for messages starting (post-HTML) with "/me ", including the space.

Parameters
messageThe message to check
lenThe message length, or -1
Returns
TRUE if it starts with "/me ", and it has been removed, otherwise FALSE

◆ purple_mime_decode_field()

char * purple_mime_decode_field ( const char *  str)

Converts a MIME header field string back to its readable equivalent according to RFC 2047.

Basically, a header is plain ASCII and can contain any number of sections called "encoded-words." The format of an encoded word is =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= =? designates the beginning of the encoded-word ?= designates the end of the encoded-word

An encoded word is segmented into three pieces by the use of a question mark. The first piece is the character set, the second piece is the encoding, and the third piece is the encoded text.

Parameters
strThe ASCII string, possibly containing any number of encoded-word sections.
Returns
The string, with any encoded-word sections decoded and converted to UTF-8. Must be g_free'd when no longer needed.

◆ purple_mkstemp()

FILE * purple_mkstemp ( char **  path,
gboolean  binary 
)

Creates a temporary file and returns a file pointer to it.

This is like mkstemp(), but returns a file pointer and uses a pre-set template. It uses the semantics of tempnam() for the directory to use and allocates the space for the file path.

The caller is responsible for closing the file and removing it when done, as well as freeing the space pointed to by path with g_free().

Parameters
pathThe returned path to the temp file.
binaryText or binary, for platforms where it matters.
Returns
A file pointer to the temporary file, or NULL on failure.

◆ purple_normalize()

const char * purple_normalize ( const PurpleAccount account,
const char *  str 
)

Normalizes a string, so that it is suitable for comparison.

The returned string will point to a static buffer, so if the string is intended to be kept long-term, you must g_strdup() it. Also, calling normalize() twice in the same line will lead to problems.

Parameters
accountThe account the string belongs to, or NULL if you do not know the account. If you use NULL, the string will still be normalized, but if the PRPL uses a custom normalization function then the string may not be normalized correctly.
strThe string to normalize.
Returns
A pointer to the normalized version stored in a static buffer.

◆ purple_normalize_nocase()

const char * purple_normalize_nocase ( const PurpleAccount account,
const char *  str 
)

Normalizes a string, so that it is suitable for comparison.

This is one possible implementation for the PRPL callback function "normalize." It returns a lowercase and UTF-8 normalized version of the string.

Parameters
accountThe account the string belongs to.
strThe string to normalize.
Returns
A pointer to the normalized version stored in a static buffer.

◆ purple_print_utf8_to_console()

void purple_print_utf8_to_console ( FILE *  filestream,
char *  message 
)

Prints a UTF-8 message to the given file stream.

The function tries to convert the UTF-8 message to user's locale. If this is not possible, the original UTF-8 text will be printed.

Parameters
filestreamThe file stream (e.g. STDOUT or STDERR)
messageThe message to print.

◆ purple_program_is_valid()

gboolean purple_program_is_valid ( const char *  program)

Checks if the given program name is valid and executable.

Parameters
programThe file name of the application.
Returns
TRUE if the program is runable.

◆ purple_quotedp_decode()

guchar * purple_quotedp_decode ( const char *  str,
gsize *  ret_len 
)

Converts a quoted printable string back to its readable equivalent.

What is a quoted printable string, you ask? It's an encoding used to transmit binary data as ASCII. It's intended purpose is to send emails containing non-ASCII characters. Wikipedia has a pretty good explanation. Also see RFC 2045.

Parameters
strThe quoted printable ASCII string to convert to raw data.
ret_lenThe length of the returned data.
Returns
The readable string. Must be g_free'd when no longer needed.

◆ purple_restore_default_signal_handlers()

void purple_restore_default_signal_handlers ( void  )

Restore default signal handlers for signals which might reasonably have handlers.

This should be called by a fork()'d child process, since child processes inherit the handlers of the parent.

◆ purple_running_gnome()

gboolean purple_running_gnome ( void  )

Check if running GNOME.

Returns
TRUE if running GNOME, FALSE otherwise.

◆ purple_running_kde()

gboolean purple_running_kde ( void  )

Check if running KDE.

Returns
TRUE if running KDE, FALSE otherwise.

◆ purple_running_osx()

gboolean purple_running_osx ( void  )

Check if running OS X.

Returns
TRUE if running OS X, FALSE otherwise.

◆ purple_socket_get_family()

int purple_socket_get_family ( int  fd)

Returns the address family of a socket.

Parameters
fdThe socket file descriptor.
Returns
The address family of the socket (AF_INET, AF_INET6, etc) or -1 on error.
Since
2.7.0

◆ purple_socket_speaks_ipv4()

gboolean purple_socket_speaks_ipv4 ( int  fd)

Returns TRUE if a socket is capable of speaking IPv4.

This is the case for IPv4 sockets and, on some systems, IPv6 sockets (due to the IPv4-mapped address functionality).

Parameters
fdThe socket file descriptor
Returns
TRUE if a socket can speak IPv4.
Since
2.7.0

◆ purple_str_add_cr()

char * purple_str_add_cr ( const char *  str)

Ensures that all linefeeds have a matching carriage return.

Parameters
strThe source string.
Returns
The string with carriage returns.

◆ purple_str_binary_to_ascii()

char * purple_str_binary_to_ascii ( const unsigned char *  binary,
guint  len 
)

Converts a binary string into a NUL terminated ascii string, replacing nonascii characters and characters below SPACE (including NUL) into \xyy, where yy are two hex digits.

Also backslashes are changed into two backslashes (\\). The returned, newly allocated string can be outputted to the console, and must be g_free()d.

Parameters
binaryA string of random data, possibly with embedded NULs and such.
lenThe length in bytes of the input string. Must not be 0.
Returns
A newly allocated ASCIIZ string.

◆ purple_str_has_prefix()

gboolean purple_str_has_prefix ( const char *  s,
const char *  p 
)

Compares two strings to see if the first contains the second as a proper prefix.

Parameters
sThe string to check.
pThe prefix in question.
Returns
TRUE if p is a prefix of s, otherwise FALSE.

◆ purple_str_has_suffix()

gboolean purple_str_has_suffix ( const char *  s,
const char *  x 
)

Compares two strings to see if the second is a proper suffix of the first.

Parameters
sThe string to check.
xThe suffix in question.
Returns
TRUE if x is a a suffix of s, otherwise FALSE.

◆ purple_str_seconds_to_string()

char * purple_str_seconds_to_string ( guint  sec)

Converts seconds into a human-readable form.

Parameters
secThe seconds.
Returns
A human-readable form, containing days, hours, minutes, and seconds.

◆ purple_str_size_to_units()

char * purple_str_size_to_units ( size_t  size)

Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc.)

Parameters
sizeThe size
Returns
The string in units form. This must be freed.

◆ purple_str_strip_char()

void purple_str_strip_char ( char *  str,
char  thechar 
)

Strips all instances of the given character from the given string.

The string is modified in place. This is useful for stripping new line characters, for example.

Example usage: purple_str_strip_char(my_dumb_string, '
');

Parameters
strThe string to strip characters from.
thecharThe character to strip from the given string.

◆ purple_str_to_time()

time_t purple_str_to_time ( const char *  timestamp,
gboolean  utc,
struct tm *  tm,
long *  tz_off,
const char **  rest 
)

Parses a timestamp in jabber, ISO8601, or MM/DD/YYYY format and returns a time_t.

Parameters
timestampThe timestamp
utcAssume UTC if no timezone specified
tmIf not NULL, the caller can get a copy of the struct tm used to calculate the time_t return value.
tz_offIf not NULL, the caller can get a copy of the timezone offset (from UTC) used to calculate the time_t return value. Note: Zero is a valid offset. As such, the value of the macro PURPLE_NO_TZ_OFF indicates no offset was specified (which means that the local timezone was used in the calculation).
restIf not NULL, the caller can get a pointer to the part of timestamp left over after parsing is completed, if it's not the end of timestamp.
Returns
A time_t.

◆ purple_strcasereplace()

gchar * purple_strcasereplace ( const char *  string,
const char *  delimiter,
const char *  replacement 
)

Given a string, this replaces one substring with another ignoring case and returns a newly allocated string.

Parameters
stringThe string from which to replace stuff.
delimiterThe substring you want replaced.
replacementThe substring you want inserted in place of the delimiting substring.
Returns
A new string, after performing the substitution. free this with g_free().

◆ purple_strcasestr()

const char * purple_strcasestr ( const char *  haystack,
const char *  needle 
)

This is like strstr, except that it ignores ASCII case in searching for the substring.

Parameters
haystackThe string to search in.
needleThe substring to find.
Returns
the location of the substring if found, or NULL if not

◆ purple_strdup_withhtml()

gchar * purple_strdup_withhtml ( const gchar *  src)

Duplicates a string and replaces all newline characters from the source string with HTML linebreaks.

Parameters
srcThe source string.
Returns
The new string. Must be g_free'd by the caller.

◆ purple_strequal()

gboolean purple_strequal ( const gchar *  left,
const gchar *  right 
)

Tests two strings for equality.

Unlike strcmp(), this function will not crash if one or both of the strings are NULL.

Parameters
leftA string
rightA string to compare with left
Returns
TRUE if the strings are the same, else FALSE.
Since
2.6.0

◆ purple_strreplace()

gchar * purple_strreplace ( const char *  string,
const char *  delimiter,
const char *  replacement 
)

Given a string, this replaces one substring with another and returns a newly allocated string.

Parameters
stringThe string from which to replace stuff.
delimiterThe substring you want replaced.
replacementThe substring you want inserted in place of the delimiting substring.
Returns
A new string, after performing the substitution. free this with g_free().

◆ purple_text_strip_mnemonic()

char * purple_text_strip_mnemonic ( const char *  in)

Removes the underscore characters from a string used identify the mnemonic character.

Parameters
inThe string to strip
Returns
The stripped string

◆ purple_time_build()

time_t purple_time_build ( int  year,
int  month,
int  day,
int  hour,
int  min,
int  sec 
)

Builds a time_t from the supplied information.

Parameters
yearThe year.
monthThe month.
dayThe day.
hourThe hour.
minThe minute.
secThe second.
Returns
A time_t.

◆ purple_time_format()

const char * purple_time_format ( const struct tm *  tm)

Formats a time into the user's preferred time format.

The returned string is stored in a static buffer, so the result should be g_strdup()'d if it's going to be kept.

Parameters
tmThe time to format, or NULL to use the current local time
Returns
The time, formatted as per the user's settings.

◆ purple_unescape_filename()

const char * purple_unescape_filename ( const char *  str)

Does the reverse of purple_escape_filename.

This will change hex codes and such to their ascii equivalents.

Parameters
strThe string to translate.
Returns
The resulting string.

◆ purple_unescape_html()

char * purple_unescape_html ( const char *  html)

Unescapes HTML entities to their literal characters and converts "<br>" to "\n".

See purple_unescape_text() for more details.

Parameters
htmlThe string in which to unescape any HTML entities
Returns
The text with HTML entities literalized. You must g_free this string when finished with it.
See also
purple_unescape_text()

◆ purple_unescape_text()

char * purple_unescape_text ( const char *  text)

Unescapes HTML entities to their literal characters in the text.

For example "&amp;" is replaced by '&' and so on. Also converts numerical entities (e.g. "&#38;" is also '&').

This function currently supports the following named entities: "&amp;", "&lt;", "&gt;", "&copy;", "&quot;", "&reg;", "&apos;"

purple_unescape_html() is similar, but also converts "<br>" into "\n".

Parameters
textThe string in which to unescape any HTML entities
Returns
The text with HTML entities literalized. You must g_free this string when finished with it.
See also
purple_unescape_html()
Since
2.7.0

◆ purple_uri_escape_for_open()

char * purple_uri_escape_for_open ( const char *  unescaped)

This function escapes any characters that might be interpreted by the shell when executing a program to open a URI on some systems.

Parameters
unescapedThe unescaped URI.
Returns
A newly allocated string with any shell metacharacters replaced with their escaped equivalents.

◆ purple_uri_list_extract_filenames()

GList * purple_uri_list_extract_filenames ( const gchar *  uri_list)

This function extracts a list of filenames from a "text/uri-list" string.

It was "borrowed" from gnome_uri_list_extract_filenames

Parameters
uri_listA uri-list in the standard format.
Returns
A GList containing strings allocated with g_malloc that contain the filenames in the uri-list. Note that unlike purple_uri_list_extract_uris() function, this will discard any non-file uri from the result value.

◆ purple_uri_list_extract_uris()

GList * purple_uri_list_extract_uris ( const gchar *  uri_list)

This function extracts a list of URIs from the a "text/uri-list" string.

It was "borrowed" from gnome_uri_list_extract_uris

Parameters
uri_listAn uri-list in the standard format.
Returns
A GList containing strings allocated with g_malloc that have been splitted from uri-list.

◆ purple_url_decode()

const char * purple_url_decode ( const char *  str)

Decodes a URL into a plain string.

This will change hex codes and such to their ascii equivalents.

Parameters
strThe string to translate.
Returns
The resulting string.

◆ purple_url_encode()

const char * purple_url_encode ( const char *  str)

Encodes a URL into an escaped string.

This will change non-alphanumeric characters to hex codes.

Parameters
strThe string to translate.
Returns
The resulting string.

◆ purple_url_parse()

gboolean purple_url_parse ( const char *  url,
char **  ret_host,
int *  ret_port,
char **  ret_path,
char **  ret_user,
char **  ret_passwd 
)

Parses a URL, returning its host, port, file path, username and password.

The returned data must be freed.

Parameters
urlThe URL to parse.
ret_hostThe returned host.
ret_portThe returned port.
ret_pathThe returned path.
ret_userThe returned username.
ret_passwdThe returned password.

◆ purple_user_dir()

const char * purple_user_dir ( void  )

Returns the purple settings directory in the user's home directory.

This is usually ~/.purple

Returns
The purple settings directory.
See also
purple_home_dir()

◆ purple_utf8_has_word()

gboolean purple_utf8_has_word ( const char *  haystack,
const char *  needle 
)

Case insensitive search for a word in a string.

The needle string must be contained in the haystack string and not be immediately preceded or immediately followed by another alpha-numeric character.

Parameters
haystackThe string to search in.
needleThe substring to find.
Returns
TRUE if haystack has the word, otherwise FALSE

◆ purple_utf8_ncr_decode()

char * purple_utf8_ncr_decode ( const char *  in)

Given a string, this replaces any numerical character references in that string with the corresponding actual utf-8 substrings, and returns a newly allocated string.

Parameters
inThe string which might contain numerical character references.
Returns
A new string, with numerical character references replaced with actual utf-8, free this with g_free().

◆ purple_utf8_ncr_encode()

char * purple_utf8_ncr_encode ( const char *  in)

Given a string, this replaces any utf-8 substrings in that string with the corresponding numerical character reference, and returns a newly allocated string.

Parameters
inThe string which might contain utf-8 substrings
Returns
A new string, with utf-8 replaced with numerical character references, free this with g_free()

◆ purple_utf8_salvage()

gchar * purple_utf8_salvage ( const char *  str)

Salvages the valid UTF-8 characters from a string, replacing any invalid characters with a filler character (currently hardcoded to '?').

Parameters
strThe source string.
Returns
A valid UTF-8 string.

◆ purple_utf8_strcasecmp()

int purple_utf8_strcasecmp ( const char *  a,
const char *  b 
)

Compares two UTF-8 strings case-insensitively.

This comparison is more expensive than a simple g_utf8_collate() comparison because it calls g_utf8_casefold() on each string, which allocates new strings.

Parameters
aThe first string.
bThe second string.
Returns
-1 if is less than b. 0 if is equal to b. 1 if is greater than b.

◆ purple_utf8_strftime()

const char * purple_utf8_strftime ( const char *  format,
const struct tm *  tm 
)

Formats a time into the specified format.

This is essentially strftime(), but it has a static buffer and handles the UTF-8 conversion for the caller.

This function also provides the GNU z formatter if the underlying C library doesn't. However, the format string parser is very naive, which means that conversions specifiers to z cannot be guaranteed. The GNU strftime(3) man page describes z as: 'The time-zone as hour offset from GMT. Required to emit RFC822-conformant dates (using "%a, %d %b %Y %H:%M:%S %z"). (GNU)'

On Windows, this function also converts the results for Z from a timezone name (as returned by the system strftime() Z format string) to a timezone abbreviation (as is the case on Unix). As with z, conversion specifiers should not be used.

Parameters
formatThe format string, in UTF-8
tmThe time to format, or NULL to use the current local time
Returns
The formatted time, in UTF-8.
Note
format is required to be in UTF-8. This differs from strftime(), where the format is provided in the locale charset.

◆ purple_utf8_strip_unprintables()

gchar * purple_utf8_strip_unprintables ( const gchar *  str)

Removes unprintable characters from a UTF-8 string.

These characters (in particular low-ASCII characters) are invalid in XML 1.0 and thus are not allowed in XMPP and are rejected by libxml2 by default.

The returned string must be freed by the caller.

Parameters
strA valid UTF-8 string.
Returns
A newly allocated UTF-8 string without the unprintable characters.
Since
2.6.0

◆ purple_utf8_try_convert()

gchar * purple_utf8_try_convert ( const char *  str)

Attempts to convert a string to UTF-8 from an unknown encoding.

This function checks the locale and tries sane defaults.

Parameters
strThe source string.
Returns
The UTF-8 string, or NULL if it could not be converted.

◆ purple_util_chrreplace()

void purple_util_chrreplace ( char *  string,
char  delimiter,
char  replacement 
)

Given a string, this replaces all instances of one character with another.

This happens inline (the original string IS modified).

Parameters
stringThe string from which to replace stuff.
delimiterThe character you want replaced.
replacementThe character you want inserted in place of the delimiting character.

◆ purple_util_fetch_url_cancel()

void purple_util_fetch_url_cancel ( PurpleUtilFetchUrlData url_data)

Cancel a pending URL request started with either purple_util_fetch_url_request() or purple_util_fetch_url().

Parameters
url_dataThe data returned when you initiated the URL fetch.

◆ purple_util_fetch_url_request()

PurpleUtilFetchUrlData * purple_util_fetch_url_request ( const gchar *  url,
gboolean  full,
const gchar *  user_agent,
gboolean  http11,
const gchar *  request,
gboolean  include_headers,
PurpleUtilFetchUrlCallback  callback,
gpointer  data 
)

Fetches the data from a URL, and passes it to a callback function.

Parameters
urlThe URL.
fullTRUE if this is the full URL, or FALSE if it's a partial URL.
user_agentThe user agent field to use, or NULL.
http11TRUE if HTTP/1.1 should be used to download the file.
requestA HTTP request to send to the server instead of the standard GET
include_headersIf TRUE, include the HTTP headers in the response.
callbackThe callback function.
dataThe user data to pass to the callback function.

◆ purple_util_fetch_url_request_data_len_with_account()

PurpleUtilFetchUrlData * purple_util_fetch_url_request_data_len_with_account ( PurpleAccount account,
const char *  url,
gboolean  full,
const char *  user_agent,
gboolean  http11,
const char *  request,
gsize  request_len,
gboolean  include_headers,
gssize  max_len,
PurpleUtilFetchUrlCallback  callback,
void *  user_data 
)

Fetches the data from a URL, and passes it to a callback function.

Parameters
accountThe account for which the request is needed, or NULL.
urlThe URL.
fullTRUE if this is the full URL, or FALSE if it's a partial URL.
user_agentThe user agent field to use, or NULL.
http11TRUE if HTTP/1.1 should be used to download the file.
requestA HTTP request to send to the server instead of the standard GET
request_lenThen length of the request being sent
include_headersIf TRUE, include the HTTP headers in the response.
max_lenThe maximum number of bytes to retrieve, or a negative number to use the default max of 512 KiB.
callbackThe callback function.
dataThe user data to pass to the callback function.
Deprecated:
In 3.0.0, we'll rename this to "purple_util_fetch_url_request" and get rid of the old one

◆ purple_util_fetch_url_request_len()

PurpleUtilFetchUrlData * purple_util_fetch_url_request_len ( const gchar *  url,
gboolean  full,
const gchar *  user_agent,
gboolean  http11,
const gchar *  request,
gboolean  include_headers,
gssize  max_len,
PurpleUtilFetchUrlCallback  callback,
gpointer  data 
)

Fetches the data from a URL, and passes it to a callback function.

Parameters
urlThe URL.
fullTRUE if this is the full URL, or FALSE if it's a partial URL.
user_agentThe user agent field to use, or NULL.
http11TRUE if HTTP/1.1 should be used to download the file.
requestA HTTP request to send to the server instead of the standard GET
include_headersIf TRUE, include the HTTP headers in the response.
max_lenThe maximum number of bytes to retrieve (-1 for unlimited)
callbackThe callback function.
dataThe user data to pass to the callback function.
Deprecated:
In 3.0.0, this will go away.

◆ purple_util_fetch_url_request_len_with_account()

PurpleUtilFetchUrlData * purple_util_fetch_url_request_len_with_account ( PurpleAccount account,
const gchar *  url,
gboolean  full,
const gchar *  user_agent,
gboolean  http11,
const gchar *  request,
gboolean  include_headers,
gssize  max_len,
PurpleUtilFetchUrlCallback  callback,
gpointer  data 
)

Fetches the data from a URL, and passes it to a callback function.

Parameters
accountThe account for which the request is needed, or NULL.
urlThe URL.
fullTRUE if this is the full URL, or FALSE if it's a partial URL.
user_agentThe user agent field to use, or NULL.
http11TRUE if HTTP/1.1 should be used to download the file.
requestA HTTP request to send to the server instead of the standard GET
include_headersIf TRUE, include the HTTP headers in the response.
max_lenThe maximum number of bytes to retrieve, or a negative number to use the default max of 512 KiB.
callbackThe callback function.
dataThe user data to pass to the callback function.
Deprecated:
In 3.0.0, we'll rename this to "purple_util_fetch_url_request" and get rid of the old one

◆ purple_util_format_song_info()

char * purple_util_format_song_info ( const char *  title,
const char *  artist,
const char *  album,
gpointer  unused 
)

Format song information.

Parameters
titleThe title of the song, NULL to unset the value.
artistThe artist of the song, can be NULL.
albumThe album of the song, can be NULL.
unusedCurrently unused, must be NULL.
Returns
The formatted string. The caller must g_free the returned string.
Since
2.4.0

◆ purple_util_get_image_extension()

const char * purple_util_get_image_extension ( gconstpointer  data,
size_t  len 
)

Returns an extension corresponding to the image data's file type.

Parameters
dataA pointer to the image data
lenThe length of the image data
Returns
The appropriate extension, or "icon" if unknown.

◆ purple_util_get_image_filename()

char * purple_util_get_image_filename ( gconstpointer  image_data,
size_t  image_len 
)
Returns
A hex encoded version of the SHA-1 hash of the data passed in with the correct file extention appended. The file extension is determined by calling purple_util_get_image_extension(). This return value must be g_freed by the caller.

◆ purple_util_init()

void purple_util_init ( void  )

Initializes the utility subsystem.

Since
2.3.0

◆ purple_util_read_xml_from_file()

xmlnode * purple_util_read_xml_from_file ( const char *  filename,
const char *  description 
)

Read the contents of a given file and parse the results into an xmlnode tree structure.

This is intended to be used to read Purple's configuration xml files (prefs.xml, pounces.xml, etc.)

Parameters
filenameThe basename of the file to open in the purple_user_dir.
descriptionA very short description of the contents of this file. This is used in error messages shown to the user when the file can not be opened. For example, "preferences," or "buddy pounces."
Returns
An xmlnode tree of the contents of the given file. Or NULL, if the file does not exist or there was an error reading the file.

◆ purple_util_set_current_song()

void purple_util_set_current_song ( const char *  title,
const char *  artist,
const char *  album 
)

Set the appropriate presence values for the currently playing song.

Parameters
titleThe title of the song, NULL to unset the value.
artistThe artist of the song, can be NULL.
albumThe album of the song, can be NULL.
Since
2.4.0

◆ purple_util_set_user_dir()

void purple_util_set_user_dir ( const char *  dir)

Define a custom purple settings directory, overriding the default (user's home directory/.purple)

Parameters
dirThe custom settings directory

◆ purple_util_uninit()

void purple_util_uninit ( void  )

Uninitializes the util subsystem.

Since
2.3.0

◆ purple_util_write_data_to_file()

gboolean purple_util_write_data_to_file ( const char *  filename,
const char *  data,
gssize  size 
)

Write a string of data to a file of the given name in the Purple user directory ($HOME/.purple by default).

The data is typically a serialized version of one of Purple's config files, such as prefs.xml, accounts.xml, etc. And the string is typically obtained using xmlnode_to_formatted_str. However, this function should work fine for saving binary files as well.

Parameters
filenameThe basename of the file to write in the purple_user_dir.
dataA null-terminated string of data to write.
sizeThe size of the data to save. If data is null-terminated you can pass in -1.
Returns
TRUE if the file was written successfully. FALSE otherwise.

◆ purple_util_write_data_to_file_absolute()

gboolean purple_util_write_data_to_file_absolute ( const char *  filename_full,
const char *  data,
gssize  size 
)

Write data to a file using the absolute path.

This exists for Glib backwards compatibility reasons.

Parameters
filename_fullFilename to write to
dataA null-terminated string of data to write.
sizeThe size of the data to save. If data is null-terminated you can pass in -1.
Returns
TRUE if the file was written successfully. FALSE otherwise.
Todo:
Remove this function (use g_file_set_contents instead) when 3.0.0 rolls around.
See also
purple_util_write_data_to_file()

◆ purple_uuid_random()

gchar * purple_uuid_random ( void  )

Returns a type 4 (random) UUID.

Returns
A UUID, caller is responsible for freeing it
Since
2.7.0