#include <stdio.h>
#include "account.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... | |
Date/Time Functions | |
#define | PURPLE_NO_TZ_OFF -500000 |
Used by purple_str_to_time to indicate no timezone offset was specified in the timestamp string. | |
const char * | purple_utf8_strftime (const char *format, const struct tm *tm) |
Formats a time into the specified format. | |
const char * | purple_get_tzoff_str (const struct tm *tm, gboolean iso) |
Gets a string representation of the local timezone offset. | |
const char * | purple_date_format_short (const struct tm *tm) |
Formats a time into the user's preferred short date format. | |
const char * | purple_date_format_long (const struct tm *tm) |
Formats a time into the user's preferred short date plus time format. | |
const char * | purple_date_format_full (const struct tm *tm) |
Formats a time into the user's preferred full date and time format. | |
const char * | purple_time_format (const struct tm *tm) |
Formats a time into the user's preferred time format. | |
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. | |
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. | |
URI/URL Functions | |
#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. | |
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(). | |
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. | |
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. | |
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(). | |
const char * | purple_url_decode (const char *str) |
Decodes a URL into a plain string. | |
const char * | purple_url_encode (const char *str) |
Encodes a URL into an escaped string. | |
gboolean | purple_email_is_valid (const char *address) |
Checks if the given email address is syntactically valid. | |
gboolean | purple_ip_address_is_valid (const char *ip) |
Checks if the given IP address is a syntactically valid IPv4 address. | |
GList * | purple_uri_list_extract_uris (const gchar *uri_list) |
This function extracts a list of URIs from the a "text/uri-list" string. | |
GList * | purple_uri_list_extract_filenames (const gchar *uri_list) |
This function extracts a list of filenames from a "text/uri-list" string. | |
Utility Subsystem | |
void | purple_util_init (void) |
Initializes the utility subsystem. | |
void | purple_util_uninit (void) |
Uninitializes the util subsystem. | |
Base16 Functions | |
gchar * | purple_base16_encode (const guchar *data, gsize len) |
Converts a chunk of binary data to its base-16 equivalent. | |
guchar * | purple_base16_decode (const char *str, gsize *ret_len) |
Converts an ASCII string of base-16 encoded data to the binary equivalent. | |
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). | |
Base64 Functions | |
gchar * | purple_base64_encode (const guchar *data, gsize len) |
Converts a chunk of binary data to its base-64 equivalent. | |
guchar * | purple_base64_decode (const char *str, gsize *ret_len) |
Converts an ASCII string of base-64 encoded data to the binary equivalent. | |
Quoted Printable Functions | |
guchar * | purple_quotedp_decode (const char *str, gsize *ret_len) |
Converts a quoted printable string back to its readable equivalent. | |
MIME Functions | |
char * | purple_mime_decode_field (const char *str) |
Converts a MIME header field string back to its readable equivalent according to RFC 2047. | |
Markup Functions | |
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. | |
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. | |
void | purple_markup_html_to_xhtml (const char *html, char **dest_xhtml, char **dest_plain) |
Converts HTML markup to XHTML. | |
char * | purple_markup_strip_html (const char *str) |
Strips HTML tags from a string. | |
char * | purple_markup_linkify (const char *str) |
Adds the necessary HTML code to turn URIs into HTML links in a string. | |
char * | purple_unescape_html (const char *html) |
Unescapes HTML entities to their literal characters. | |
char * | purple_markup_slice (const char *str, guint x, guint y) |
Returns a newly allocated substring of the HTML UTF-8 string "str". | |
char * | purple_markup_get_tag_name (const char *tag) |
Returns a newly allocated string containing the name of the tag located at "tag". | |
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. | |
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. | |
Path/Filename Functions | |
const gchar * | purple_home_dir (void) |
Returns the user's home directory. | |
const char * | purple_user_dir (void) |
Returns the purple settings directory in the user's home directory. | |
void | purple_util_set_user_dir (const char *dir) |
Define a custom purple settings directory, overriding the default (user's home directory/.purple). | |
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. | |
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). | |
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. | |
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. | |
FILE * | purple_mkstemp (char **path, gboolean binary) |
Creates a temporary file and returns a file pointer to it. | |
const char * | purple_util_get_image_extension (gconstpointer data, size_t len) |
Returns an extension corresponding to the image data's file type. | |
char * | purple_util_get_image_filename (gconstpointer image_data, size_t image_len) |
Returns a SHA-1 hash string of the data passed in with the correct file extention appended. | |
Environment Detection Functions | |
gboolean | purple_program_is_valid (const char *program) |
Checks if the given program name is valid and executable. | |
gboolean | purple_running_gnome (void) |
Check if running GNOME. | |
gboolean | purple_running_kde (void) |
Check if running KDE. | |
gboolean | purple_running_osx (void) |
Check if running OS X. | |
char * | purple_fd_get_ip (int fd) |
Returns the IP address from a socket file descriptor. | |
String Functions | |
const char * | purple_normalize (const PurpleAccount *account, const char *str) |
Normalizes a string, so that it is suitable for comparison. | |
const char * | purple_normalize_nocase (const PurpleAccount *account, const char *str) |
Normalizes a string, so that it is suitable for comparison. | |
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. | |
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. | |
gchar * | purple_strdup_withhtml (const gchar *src) |
Duplicates a string and replaces all newline characters from the source string with HTML linebreaks. | |
char * | purple_str_add_cr (const char *str) |
Ensures that all linefeeds have a matching carriage return. | |
void | purple_str_strip_char (char *str, char thechar) |
Strips all instances of the given character from the given string. | |
void | purple_util_chrreplace (char *string, char delimiter, char replacement) |
Given a string, this replaces all instances of one character with another. | |
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. | |
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. | |
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. | |
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. | |
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. | |
char * | purple_str_size_to_units (size_t size) |
Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc. | |
char * | purple_str_seconds_to_string (guint sec) |
Converts seconds into a human-readable form. | |
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. | |
gchar * | purple_utf8_try_convert (const char *str) |
Attempts to convert a string to UTF-8 from an unknown encoding. | |
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 '?'). | |
G_CONST_RETURN gchar * | purple_gai_strerror (gint errnum) |
Return the UTF-8 version of gai_strerror(). | |
int | purple_utf8_strcasecmp (const char *a, const char *b) |
Compares two UTF-8 strings case-insensitively. | |
gboolean | purple_utf8_has_word (const char *haystack, const char *needle) |
Case insensitive search for a word in a string. | |
void | purple_print_utf8_to_console (FILE *filestream, char *message) |
Prints a UTF-8 message to the given file stream. | |
gboolean | purple_message_meify (char *message, gssize len) |
Checks for messages starting (post-HTML) with "/me ", including the space. | |
char * | purple_text_strip_mnemonic (const char *in) |
Removes the underscore characters from a string used identify the mnemonic character. | |
Defines | |
#define | purple_add_eight(x) ((x)+8) |
Adds 8 to something. | |
Typedefs | |
typedef _PurpleUtilFetchUrlData | PurpleUtilFetchUrlData |
typedef _PurpleMenuAction | PurpleMenuAction |
typedef char *(* | PurpleInfoFieldFormatCallback )(const char *field, size_t len) |
typedef _PurpleKeyValuePair | PurpleKeyValuePair |
A key-value pair. | |
Functions | |
PurpleMenuAction * | purple_menu_action_new (const char *label, PurpleCallback callback, gpointer data, GList *children) |
Creates a new PurpleMenuAction. | |
void | purple_menu_action_free (PurpleMenuAction *act) |
Frees a PurpleMenuAction. | |
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. | |
char * | purple_util_format_song_info (const char *title, const char *artist, const char *album, gpointer unused) |
Format song information. | |
const char * | purple_unescape_filename (const char *str) |
Does the reverse of purple_escape_filename. | |
const char * | purple_escape_filename (const char *str) |
Escapes filesystem-unfriendly characters from a filename. | |
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. | |
void | purple_restore_default_signal_handlers (void) |
Restore default signal handlers for signals which might reasonably have handlers. |
Definition in file util.h.
|
Adds 8 to something. Blame SimGuy.
|
|
Value: purple_util_fetch_url_request(url, full, user_agent, http11, NULL, \ FALSE, cb, data);
|
|
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. |
|
This is the signature used for functions that act as the callback to purple_util_fetch_url() or purple_util_fetch_url_request().
|
|
This is added temporarily to assist the split of oscar into aim and icq. This should not be used by plugins. |
|
Converts an ASCII string of base-16 encoded data to the binary equivalent.
|
|
Converts a chunk of binary data to its base-16 equivalent.
|
|
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
|
|
Converts an ASCII string of base-64 encoded data to the binary equivalent.
|
|
Converts a chunk of binary data to its base-64 equivalent.
|
|
Builds a complete path from the root, making any directories along the path which do not already exist.
|
|
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.
|
|
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.
|
|
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.
|
|
Checks if the given email address is syntactically valid.
|
|
Escapes filesystem-unfriendly characters from a filename.
|
|
Returns the IP address from a socket file descriptor.
|
|
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().
|
|
Gets a string representation of the local timezone offset.
|
|
Returns the user's home directory.
|
|
Checks if the given IP address is a syntactically valid IPv4 address.
|
|
Extracts a field of data from HTML. This is a scary function. See protocols/msn/msn.c and protocols/yahoo/yahoo_profile.c for example usage.
|
|
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.
|
|
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
|
|
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.
|
|
Converts HTML markup to XHTML.
|
|
Adds the necessary HTML code to turn URIs into HTML links in a string.
|
|
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.
|
|
Strips HTML tags from a string.
|
|
Returns a constant string of the character representation of the HTML entity pointed to by text.
For example, purple_markup_unescape_entity("&") 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 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.
|
|
Frees a PurpleMenuAction.
|
|
Creates a new PurpleMenuAction.
|
|
Checks for messages starting (post-HTML) with "/me ", including the space.
|
|
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.
|
|
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().
|
|
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.
|
|
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.
|
|
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.
|
|
Checks if the given program name is valid and executable.
|
|
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 e-mails containing non-ASCII characters. Wikipedia has a pretty good explanation. Also see RFC 2045.
|
|
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. |
|
Check if running GNOME.
|
|
Check if running KDE.
|
|
Check if running OS X.
|
|
Ensures that all linefeeds have a matching carriage return.
|
|
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.
|
|
Compares two strings to see if the first contains the second as a proper prefix.
|
|
Compares two strings to see if the second is a proper suffix of the first.
|
|
Converts seconds into a human-readable form.
|
|
Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc. )
|
|
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, '
|
|
Parses a timestamp in jabber, ISO8601, or MM/DD/YYYY format and returns a time_t.
|
|
Given a string, this replaces one substring with another ignoring case and returns a newly allocated string.
|
|
This is like strstr, except that it ignores ASCII case in searching for the substring.
|
|
Duplicates a string and replaces all newline characters from the source string with HTML linebreaks.
|
|
Given a string, this replaces one substring with another and returns a newly allocated string.
|
|
Removes the underscore characters from a string used identify the mnemonic character.
|
|
Builds a time_t from the supplied information.
|
|
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.
|
|
Does the reverse of purple_escape_filename. This will change hex codes and such to their ascii equivalents.
|
|
Unescapes HTML entities to their literal characters. For example "&" is replaced by '&' and so on. Actually only "&", """, "<" and ">" are currently supported.
|
|
This function extracts a list of filenames from a "text/uri-list" string. It was "borrowed" from gnome_uri_list_extract_filenames
|
|
This function extracts a list of URIs from the a "text/uri-list" string. It was "borrowed" from gnome_uri_list_extract_uris
|
|
Decodes a URL into a plain string. This will change hex codes and such to their ascii equivalents.
|
|
Encodes a URL into an escaped string. This will change non-alphanumeric characters to hex codes.
|
|
Parses a URL, returning its host, port, file path, username and password. The returned data must be freed.
|
|
Returns the purple settings directory in the user's home directory. This is usually ~/.purple
|
|
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.
|
|
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.
|
|
Given a string, this replaces any utf-8 substrings in that string with the corresponding numerical character reference, and returns a newly allocated string.
|
|
Salvages the valid UTF-8 characters from a string, replacing any invalid characters with a filler character (currently hardcoded to '?').
|
|
Compares two UTF-8 strings case-insensitively. This string is more expensive than a simple g_utf8_collate() comparison because it calls g_utf8_casefold() on each string, which allocates new strings.
|
|
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.
|
|
Attempts to convert a string to UTF-8 from an unknown encoding. This function checks the locale and tries sane defaults.
|
|
Given a string, this replaces all instances of one character with another. This happens inline (the original string IS modified).
|
|
Cancel a pending URL request started with either purple_util_fetch_url_request() or purple_util_fetch_url().
|
|
Fetches the data from a URL, and passes it to a callback function.
|
|
Format song information.
|
|
Returns an extension corresponding to the image data's file type.
|
|
Initializes the utility subsystem.
|
|
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.)
|
|
Set the appropriate presence values for the currently playing song.
|
|
Define a custom purple settings directory, overriding the default (user's home directory/.purple).
|
|
Uninitializes the util subsystem.
|
|
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.
|
|
Write data to a file using the absolute path. This exists for Glib backwards compatibility reasons.
|