Frameworks/libpurple.framework/Versions/0.6.2/Headers/util.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2535 Frameworks/libpurple.framework/Versions/0.6.0/Headers/util.h@39c3c161de14
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file util.h Utility Functions
     3  * @ingroup core
     4  */
     5 
     6 /* purple
     7  *
     8  * Purple is the legal property of its developers, whose names are too numerous
     9  * to list here.  Please refer to the COPYRIGHT file distributed with this
    10  * source distribution.
    11  *
    12  * This program is free software; you can redistribute it and/or modify
    13  * it under the terms of the GNU General Public License as published by
    14  * the Free Software Foundation; either version 2 of the License, or
    15  * (at your option) any later version.
    16  *
    17  * This program is distributed in the hope that it will be useful,
    18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  * GNU General Public License for more details.
    21  *
    22  * You should have received a copy of the GNU General Public License
    23  * along with this program; if not, write to the Free Software
    24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    25  *
    26  * @todo Rename the functions so that they live somewhere in the purple
    27  *       namespace.
    28  */
    29 #ifndef _PURPLE_UTIL_H_
    30 #define _PURPLE_UTIL_H_
    31 
    32 #include <stdio.h>
    33 
    34 typedef struct _PurpleUtilFetchUrlData PurpleUtilFetchUrlData;
    35 typedef struct _PurpleMenuAction PurpleMenuAction;
    36 typedef struct _PurpleKeyValuePair PurpleKeyValuePair;
    37 
    38 #include "account.h"
    39 #include "xmlnode.h"
    40 #include "notify.h"
    41 
    42 
    43 #ifdef __cplusplus
    44 extern "C" {
    45 #endif
    46 
    47 struct _PurpleMenuAction
    48 {
    49 	char *label;
    50 	PurpleCallback callback;
    51 	gpointer data;
    52 	GList *children;
    53 };
    54 
    55 typedef char *(*PurpleInfoFieldFormatCallback)(const char *field, size_t len);
    56 
    57 /**
    58  * A key-value pair.
    59  *
    60  * This is used by, among other things, purple_gtk_combo* functions to pass in a
    61  * list of key-value pairs so it can display a user-friendly value.
    62  */
    63 struct _PurpleKeyValuePair
    64 {
    65 	gchar *key;
    66 	void *value;
    67 
    68 };
    69 
    70 /**
    71  * Creates a new PurpleMenuAction.
    72  *
    73  * @param label    The text label to display for this action.
    74  * @param callback The function to be called when the action is used on
    75  *                 the selected item.
    76  * @param data     Additional data to be passed to the callback.
    77  * @param children A GList of PurpleMenuActions to be added as a submenu
    78  *                 of the action.
    79  * @return The PurpleMenuAction.
    80  */
    81 PurpleMenuAction *purple_menu_action_new(const char *label, PurpleCallback callback,
    82                                      gpointer data, GList *children);
    83 
    84 /**
    85  * Frees a PurpleMenuAction
    86  *
    87  * @param act The PurpleMenuAction to free.
    88  */
    89 void purple_menu_action_free(PurpleMenuAction *act);
    90 
    91 /**
    92  * Set the appropriate presence values for the currently playing song.
    93  *
    94  * @param title     The title of the song, @c NULL to unset the value.
    95  * @param artist    The artist of the song, can be @c NULL.
    96  * @param album     The album of the song, can be @c NULL.
    97  * @since 2.4.0
    98  */
    99 void purple_util_set_current_song(const char *title, const char *artist,
   100 		const char *album);
   101 
   102 /**
   103  * Format song information.
   104  *
   105  * @param title     The title of the song, @c NULL to unset the value.
   106  * @param artist    The artist of the song, can be @c NULL.
   107  * @param album     The album of the song, can be @c NULL.
   108  * @param unused    Currently unused, must be @c NULL.
   109  *
   110  * @return   The formatted string. The caller must #g_free the returned string.
   111  * @since 2.4.0
   112  */
   113 char * purple_util_format_song_info(const char *title, const char *artist,
   114 		const char *album, gpointer unused);
   115 
   116 /**************************************************************************/
   117 /** @name Utility Subsystem                                               */
   118 /**************************************************************************/
   119 /*@{*/
   120 
   121 /**
   122  * Initializes the utility subsystem.
   123  *
   124  * @since 2.3.0
   125  */
   126 void purple_util_init(void);
   127 
   128 /**
   129  * Uninitializes the util subsystem.
   130  *
   131  * @since 2.3.0
   132  */
   133 void purple_util_uninit(void);
   134 
   135 /*@}*/
   136 
   137 /**************************************************************************/
   138 /** @name Base16 Functions                                                */
   139 /**************************************************************************/
   140 /*@{*/
   141 
   142 /**
   143  * Converts a chunk of binary data to its base-16 equivalent.
   144  *
   145  * @param data The data to convert.
   146  * @param len  The length of the data.
   147  *
   148  * @return The base-16 string in the ASCII encoding.  Must be
   149  *         g_free'd when no longer needed.
   150  *
   151  * @see purple_base16_decode()
   152  */
   153 gchar *purple_base16_encode(const guchar *data, gsize len);
   154 
   155 /**
   156  * Converts an ASCII string of base-16 encoded data to
   157  * the binary equivalent.
   158  *
   159  * @param str     The base-16 string to convert to raw data.
   160  * @param ret_len The length of the returned data.  You can
   161  *                pass in NULL if you're sure that you know
   162  *                the length of the decoded data, or if you
   163  *                know you'll be able to use strlen to
   164  *                determine the length, etc.
   165  *
   166  * @return The raw data.  Must be g_free'd when no longer needed.
   167  *
   168  * @see purple_base16_encode()
   169  */
   170 guchar *purple_base16_decode(const char *str, gsize *ret_len);
   171 
   172 /**
   173  * Converts a chunk of binary data to a chunked base-16 representation
   174  * (handy for key fingerprints)
   175  *
   176  * Example output: 01:23:45:67:89:AB:CD:EF
   177  *
   178  * @param data The data to convert.
   179  * @param len  The length of the data.
   180  *
   181  * @return The base-16 string in the ASCII chunked encoding.  Must be
   182  *         g_free'd when no longer needed.
   183  */
   184 gchar *purple_base16_encode_chunked(const guchar *data, gsize len);
   185 
   186 
   187 /*@}*/
   188 
   189 /**************************************************************************/
   190 /** @name Base64 Functions                                                */
   191 /**************************************************************************/
   192 /*@{*/
   193 
   194 /**
   195  * Converts a chunk of binary data to its base-64 equivalent.
   196  *
   197  * @param data The data to convert.
   198  * @param len  The length of the data.
   199  *
   200  * @return The base-64 string in the ASCII encoding.  Must be
   201  *         g_free'd when no longer needed.
   202  *
   203  * @see purple_base64_decode()
   204  */
   205 gchar *purple_base64_encode(const guchar *data, gsize len);
   206 
   207 /**
   208  * Converts an ASCII string of base-64 encoded data to
   209  * the binary equivalent.
   210  *
   211  * @param str     The base-64 string to convert to raw data.
   212  * @param ret_len The length of the returned data.  You can
   213  *                pass in NULL if you're sure that you know
   214  *                the length of the decoded data, or if you
   215  *                know you'll be able to use strlen to
   216  *                determine the length, etc.
   217  *
   218  * @return The raw data.  Must be g_free'd when no longer needed.
   219  *
   220  * @see purple_base64_encode()
   221  */
   222 guchar *purple_base64_decode(const char *str, gsize *ret_len);
   223 
   224 /*@}*/
   225 
   226 /**************************************************************************/
   227 /** @name Quoted Printable Functions                                      */
   228 /**************************************************************************/
   229 /*@{*/
   230 
   231 /**
   232  * Converts a quoted printable string back to its readable equivalent.
   233  * What is a quoted printable string, you ask?  It's an encoding used
   234  * to transmit binary data as ASCII.  It's intended purpose is to send
   235  * emails containing non-ASCII characters.  Wikipedia has a pretty good
   236  * explanation.  Also see RFC 2045.
   237  *
   238  * @param str     The quoted printable ASCII string to convert to raw data.
   239  * @param ret_len The length of the returned data.
   240  *
   241  * @return The readable string.  Must be g_free'd when no longer needed.
   242  */
   243 guchar *purple_quotedp_decode(const char *str, gsize *ret_len);
   244 
   245 /*@}*/
   246 
   247 /**************************************************************************/
   248 /** @name MIME Functions                                                  */
   249 /**************************************************************************/
   250 /*@{*/
   251 
   252 /**
   253  * Converts a MIME header field string back to its readable equivalent
   254  * according to RFC 2047.  Basically, a header is plain ASCII and can
   255  * contain any number of sections called "encoded-words."  The format
   256  * of an encoded word is =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?=
   257  * =? designates the beginning of the encoded-word
   258  * ?= designates the end of the encoded-word
   259  *
   260  * An encoded word is segmented into three pieces by the use of a
   261  * question mark.  The first piece is the character set, the second
   262  * piece is the encoding, and the third piece is the encoded text.
   263  *
   264  * @param str The ASCII string, possibly containing any number of
   265  *            encoded-word sections.
   266  *
   267  * @return The string, with any encoded-word sections decoded and
   268  *         converted to UTF-8.  Must be g_free'd when no longer
   269  *         needed.
   270  */
   271 char *purple_mime_decode_field(const char *str);
   272 
   273 /*@}*/
   274 
   275 
   276 /**************************************************************************/
   277 /** @name Date/Time Functions                                             */
   278 /**************************************************************************/
   279 /*@{*/
   280 
   281 /**
   282  * Formats a time into the specified format.
   283  *
   284  * This is essentially strftime(), but it has a static buffer
   285  * and handles the UTF-8 conversion for the caller.
   286  *
   287  * This function also provides the GNU %z formatter if the underlying C
   288  * library doesn't.  However, the format string parser is very naive, which
   289  * means that conversions specifiers to %z cannot be guaranteed.  The GNU
   290  * strftime(3) man page describes %z as: 'The time-zone as hour offset from
   291  * GMT.  Required to emit RFC822-conformant dates
   292  * (using "%a, %d %b %Y %H:%M:%S %z"). (GNU)'
   293  *
   294  * On Windows, this function also converts the results for %Z from a timezone
   295  * name (as returned by the system strftime() %Z format string) to a timezone
   296  * abbreviation (as is the case on Unix).  As with %z, conversion specifiers
   297  * should not be used.
   298  *
   299  * @param format The format string, in UTF-8
   300  * @param tm     The time to format, or @c NULL to use the current local time
   301  *
   302  * @return The formatted time, in UTF-8.
   303  *
   304  * @note @a format is required to be in UTF-8.  This differs from strftime(),
   305  *       where the format is provided in the locale charset.
   306  */
   307 const char *purple_utf8_strftime(const char *format, const struct tm *tm);
   308 
   309 /**
   310  * Gets a string representation of the local timezone offset
   311  *
   312  * @param tm   The time to get the timezone for
   313  * @param iso  TRUE to format the offset according to ISO-8601, FALSE to
   314  *             not substitute 'Z' for 0 offset, and to not separate
   315  *             hours and minutes with a colon.
   316  */
   317 const char *purple_get_tzoff_str(const struct tm *tm, gboolean iso);
   318 
   319 /**
   320  * Formats a time into the user's preferred short date format.
   321  *
   322  * The returned string is stored in a static buffer, so the result
   323  * should be g_strdup()'d if it's going to be kept.
   324  *
   325  * @param tm The time to format, or @c NULL to use the current local time
   326  *
   327  * @return The date, formatted as per the user's settings.
   328  */
   329 const char *purple_date_format_short(const struct tm *tm);
   330 
   331 /**
   332  * Formats a time into the user's preferred short date plus time format.
   333  *
   334  * The returned string is stored in a static buffer, so the result
   335  * should be g_strdup()'d if it's going to be kept.
   336  *
   337  * @param tm The time to format, or @c NULL to use the current local time
   338  *
   339  * @return The timestamp, formatted as per the user's settings.
   340  */
   341 const char *purple_date_format_long(const struct tm *tm);
   342 
   343 /**
   344  * Formats a time into the user's preferred full date and time format.
   345  *
   346  * The returned string is stored in a static buffer, so the result
   347  * should be g_strdup()'d if it's going to be kept.
   348  *
   349  * @param tm The time to format, or @c NULL to use the current local time
   350  *
   351  * @return The date and time, formatted as per the user's settings.
   352  */
   353 const char *purple_date_format_full(const struct tm *tm);
   354 
   355 /**
   356  * Formats a time into the user's preferred time format.
   357  *
   358  * The returned string is stored in a static buffer, so the result
   359  * should be g_strdup()'d if it's going to be kept.
   360  *
   361  * @param tm The time to format, or @c NULL to use the current local time
   362  *
   363  * @return The time, formatted as per the user's settings.
   364  */
   365 const char *purple_time_format(const struct tm *tm);
   366 
   367 /**
   368  * Builds a time_t from the supplied information.
   369  *
   370  * @param year  The year.
   371  * @param month The month.
   372  * @param day   The day.
   373  * @param hour  The hour.
   374  * @param min   The minute.
   375  * @param sec   The second.
   376  *
   377  * @return A time_t.
   378  */
   379 time_t purple_time_build(int year, int month, int day, int hour,
   380 					   int min, int sec);
   381 
   382 /** Used by purple_str_to_time to indicate no timezone offset was
   383   * specified in the timestamp string. */
   384 #define PURPLE_NO_TZ_OFF -500000
   385 
   386 /**
   387  * Parses a timestamp in jabber, ISO8601, or MM/DD/YYYY format and returns
   388  * a time_t.
   389  *
   390  * @param timestamp The timestamp
   391  * @param utc       Assume UTC if no timezone specified
   392  * @param tm        If not @c NULL, the caller can get a copy of the
   393  *                  struct tm used to calculate the time_t return value.
   394  * @param tz_off    If not @c NULL, the caller can get a copy of the
   395  *                  timezone offset (from UTC) used to calculate the time_t
   396  *                  return value. Note: Zero is a valid offset. As such,
   397  *                  the value of the macro @c PURPLE_NO_TZ_OFF indicates no
   398  *                  offset was specified (which means that the local
   399  *                  timezone was used in the calculation).
   400  * @param rest      If not @c NULL, the caller can get a pointer to the
   401  *                  part of @a timestamp left over after parsing is
   402  *                  completed, if it's not the end of @a timestamp.
   403  *
   404  * @return A time_t.
   405  */
   406 time_t purple_str_to_time(const char *timestamp, gboolean utc,
   407                         struct tm *tm, long *tz_off, const char **rest);
   408 
   409 /*@}*/
   410 
   411 
   412 /**************************************************************************/
   413 /** @name Markup Functions                                                */
   414 /**************************************************************************/
   415 /*@{*/
   416 
   417 /**
   418  * Escapes special characters in a plain-text string so they display
   419  * correctly as HTML.  For example, & is replaced with &amp; and < is
   420  * replaced with &lt;
   421  *
   422  * This is exactly the same as g_markup_escape_text(), except that it
   423  * does not change ' to &apos; because &apos; is not a valid HTML 4 entity,
   424  * and is displayed literally in IE7.
   425  *
   426  * @since 2.6.0
   427  */
   428 gchar *purple_markup_escape_text(const gchar *text, gssize length);
   429 
   430 /**
   431  * Finds an HTML tag matching the given name.
   432  *
   433  * This locates an HTML tag's start and end, and stores its attributes
   434  * in a GData hash table. The names of the attributes are lower-cased
   435  * in the hash table, and the name of the tag is case insensitive.
   436  *
   437  * @param needle	  The name of the tag
   438  * @param haystack	  The null-delimited string to search in
   439  * @param start		  A pointer to the start of the tag if found
   440  * @param end		  A pointer to the end of the tag if found
   441  * @param attributes  The attributes, if the tag was found.  This should
   442  *                    be freed with g_datalist_clear().
   443  * @return TRUE if the tag was found
   444  */
   445 gboolean purple_markup_find_tag(const char *needle, const char *haystack,
   446 							  const char **start, const char **end,
   447 							  GData **attributes);
   448 
   449 /**
   450  * Extracts a field of data from HTML.
   451  *
   452  * This is a scary function. See protocols/msn/msn.c and
   453  * protocols/yahoo/yahoo_profile.c for example usage.
   454  *
   455  * @param str            The string to parse.
   456  * @param len            The size of str.
   457  * @param user_info      The destination PurpleNotifyUserInfo to which the new
   458  *                       field info should be added.
   459  * @param start_token    The beginning token.
   460  * @param skip           The number of characters to skip after the
   461  *                       start token.
   462  * @param end_token      The ending token.
   463  * @param check_value    The value that the last character must meet.
   464  * @param no_value_token The token indicating no value is given.
   465  * @param display_name   The short descriptive name to display for this token.
   466  * @param is_link        TRUE if this should be a link, or FALSE otherwise.
   467  * @param link_prefix    The prefix for the link.
   468  * @param format_cb      A callback to format the value before adding it.
   469  *
   470  * @return TRUE if successful, or FALSE otherwise.
   471  */
   472 gboolean purple_markup_extract_info_field(const char *str, int len, PurpleNotifyUserInfo *user_info,
   473                                         const char *start_token, int skip,
   474                                         const char *end_token, char check_value,
   475                                         const char *no_value_token,
   476                                         const char *display_name, gboolean is_link,
   477                                         const char *link_prefix,
   478 					PurpleInfoFieldFormatCallback format_cb);
   479 
   480 /**
   481  * Converts HTML markup to XHTML.
   482  *
   483  * @param html       The HTML markup.
   484  * @param dest_xhtml The destination XHTML output.
   485  * @param dest_plain The destination plain-text output.
   486  */
   487 void purple_markup_html_to_xhtml(const char *html, char **dest_xhtml,
   488 							   char **dest_plain);
   489 
   490 /**
   491  * Strips HTML tags from a string.
   492  *
   493  * @param str The string to strip HTML from.
   494  *
   495  * @return The new string without HTML.  You must g_free this string
   496  *         when finished with it.
   497  */
   498 char *purple_markup_strip_html(const char *str);
   499 
   500 /**
   501  * Adds the necessary HTML code to turn URIs into HTML links in a string.
   502  *
   503  * @param str The string to linkify.
   504  *
   505  * @return The new string with all URIs surrounded in standard
   506  *         HTML <a href="whatever"></a> tags.  You must g_free this
   507  *         string when finished with it.
   508  */
   509 char *purple_markup_linkify(const char *str);
   510 
   511 /**
   512  * Unescapes HTML entities to their literal characters. Also translates
   513  * "<br>" to "\n".
   514  * For example "&amp;" is replaced by '&' and so on.
   515  * Actually only "&amp;", "&quot;", "&lt;" and "&gt;" are currently
   516  * supported.
   517  *
   518  * @param html The string in which to unescape any HTML entities
   519  *
   520  * @return The text with HTML entities literalized.  You must g_free
   521  *         this string when finished with it.
   522  */
   523 char *purple_unescape_html(const char *html);
   524 
   525 /**
   526  * Returns a newly allocated substring of the HTML UTF-8 string "str".
   527  * The markup is preserved such that the substring will have the same
   528  * formatting as original string, even though some tags may have been
   529  * opened before "x", or may close after "y". All open tags are closed
   530  * at the end of the returned string, in the proper order.
   531  *
   532  * Note that x and y are in character offsets, not byte offsets, and
   533  * are offsets into an unformatted version of str. Because of this,
   534  * this function may be sensitive to changes in GtkIMHtml and may break
   535  * when used with other UI's. libpurple users are encouraged to report and
   536  * work out any problems encountered.
   537  *
   538  * @param str The input NUL terminated, HTML, UTF-8 (or ASCII) string.
   539  * @param x The character offset into an unformatted version of str to
   540  *          begin at.
   541  * @param y The character offset (into an unformatted vesion of str) of
   542  *          one past the last character to include in the slice.
   543  *
   544  * @return The HTML slice of string, with all formatting retained.
   545  */
   546 char *purple_markup_slice(const char *str, guint x, guint y);
   547 
   548 /**
   549  * Returns a newly allocated string containing the name of the tag
   550  * located at "tag". Tag is expected to point to a '<', and contain
   551  * a '>' sometime after that. If there is no '>' and the string is
   552  * not NUL terminated, this function can be expected to segfault.
   553  *
   554  * @param tag The string starting a HTML tag.
   555  * @return A string containing the name of the tag.
   556  */
   557 char *purple_markup_get_tag_name(const char *tag);
   558 
   559 /**
   560  * Returns a constant string of the character representation of the HTML
   561  * entity pointed to by @a text. For example, purple_markup_unescape_entity("&amp;")
   562  * will return "&". The @a text variable is expected to point to an '&',
   563  * the first character of the entity. If given an unrecognized entity, the function
   564  * returns @c NULL.
   565  *
   566  * Note that this function, unlike purple_unescape_html(), does not search
   567  * the string for the entity, does not replace the entity, and does not
   568  * return a newly allocated string.
   569  *
   570  * @param text   A string containing an HTML entity.
   571  * @param length If not @c NULL, the string length of the entity is stored in this location.
   572  *
   573  * @return A constant string containing the character representation of the given entity.
   574  */
   575 const char * purple_markup_unescape_entity(const char *text, int *length);
   576 
   577 /**
   578  * Returns a newly allocated string containing the value of the CSS property specified
   579  * in opt. The @a style argument is expected to point to a HTML inline CSS.
   580  * The function will seek for the CSS property and return its value.
   581  *
   582  * For example, purple_markup_get_css_property("direction:rtl;color:#dc4d1b;",
   583  * "color") would return "#dc4d1b".
   584  *
   585  * On error or if the requested property was not found, the function returns
   586  * @c NULL.
   587  *
   588  * @param style A string containing the inline CSS text.
   589  * @param opt   The requested CSS property.
   590  *
   591  * @return The value of the requested CSS property.
   592  */
   593 char * purple_markup_get_css_property(const gchar *style, const gchar *opt);
   594 
   595 /**
   596  * Check if the given HTML contains RTL text.
   597  *
   598  * @param html  The HTML text.
   599  *
   600  * @return  TRUE if the text contains RTL text, FALSE otherwise.
   601  *
   602  * @since 2.6.0
   603  */
   604 gboolean purple_markup_is_rtl(const char *html);
   605 
   606 /*@}*/
   607 
   608 
   609 /**************************************************************************/
   610 /** @name Path/Filename Functions                                         */
   611 /**************************************************************************/
   612 /*@{*/
   613 
   614 /**
   615  * Returns the user's home directory.
   616  *
   617  * @return The user's home directory.
   618  *
   619  * @see purple_user_dir()
   620  */
   621 const gchar *purple_home_dir(void);
   622 
   623 /**
   624  * Returns the purple settings directory in the user's home directory.
   625  * This is usually ~/.purple
   626  *
   627  * @return The purple settings directory.
   628  *
   629  * @see purple_home_dir()
   630  */
   631 const char *purple_user_dir(void);
   632 
   633 /**
   634  * Define a custom purple settings directory, overriding the default (user's home directory/.purple)
   635  * @param dir The custom settings directory
   636  */
   637 void purple_util_set_user_dir(const char *dir);
   638 
   639 /**
   640  * Builds a complete path from the root, making any directories along
   641  * the path which do not already exist.
   642  *
   643  * @param path The path you wish to create.  Note that it must start
   644  *        from the root or this function will fail.
   645  * @param mode Unix-style permissions for this directory.
   646  *
   647  * @return 0 for success, nonzero on any error.
   648  */
   649 int purple_build_dir(const char *path, int mode);
   650 
   651 /**
   652  * Write a string of data to a file of the given name in the Purple
   653  * user directory ($HOME/.purple by default).  The data is typically
   654  * a serialized version of one of Purple's config files, such as
   655  * prefs.xml, accounts.xml, etc.  And the string is typically
   656  * obtained using xmlnode_to_formatted_str.  However, this function
   657  * should work fine for saving binary files as well.
   658  *
   659  * @param filename The basename of the file to write in the purple_user_dir.
   660  * @param data     A null-terminated string of data to write.
   661  * @param size     The size of the data to save.  If data is
   662  *                 null-terminated you can pass in -1.
   663  *
   664  * @return TRUE if the file was written successfully.  FALSE otherwise.
   665  */
   666 gboolean purple_util_write_data_to_file(const char *filename, const char *data,
   667 									  gssize size);
   668 
   669 /**
   670  * Write data to a file using the absolute path.
   671  *
   672  * This exists for Glib backwards compatibility reasons.
   673  *
   674  * @param filename_full Filename to write to
   675  * @param data          A null-terminated string of data to write.
   676  * @param size          The size of the data to save.  If data is
   677  *                      null-terminated you can pass in -1.
   678  *
   679  * @return TRUE if the file was written successfully.  FALSE otherwise.
   680  *
   681  * @todo Remove this function (use g_file_set_contents instead) when 3.0.0
   682  *       rolls around.
   683  * @see purple_util_write_data_to_file()
   684  *
   685  */
   686 gboolean
   687 purple_util_write_data_to_file_absolute(const char *filename_full, const char *data, gssize size);
   688 
   689 /**
   690  * Read the contents of a given file and parse the results into an
   691  * xmlnode tree structure.  This is intended to be used to read
   692  * Purple's configuration xml files (prefs.xml, pounces.xml, etc.)
   693  *
   694  * @param filename    The basename of the file to open in the purple_user_dir.
   695  * @param description A very short description of the contents of this
   696  *                    file.  This is used in error messages shown to the
   697  *                    user when the file can not be opened.  For example,
   698  *                    "preferences," or "buddy pounces."
   699  *
   700  * @return An xmlnode tree of the contents of the given file.  Or NULL, if
   701  *         the file does not exist or there was an error reading the file.
   702  */
   703 xmlnode *purple_util_read_xml_from_file(const char *filename,
   704 									  const char *description);
   705 
   706 /**
   707  * Creates a temporary file and returns a file pointer to it.
   708  *
   709  * This is like mkstemp(), but returns a file pointer and uses a
   710  * pre-set template. It uses the semantics of tempnam() for the
   711  * directory to use and allocates the space for the file path.
   712  *
   713  * The caller is responsible for closing the file and removing it when
   714  * done, as well as freeing the space pointed to by @a path with
   715  * g_free().
   716  *
   717  * @param path   The returned path to the temp file.
   718  * @param binary Text or binary, for platforms where it matters.
   719  *
   720  * @return A file pointer to the temporary file, or @c NULL on failure.
   721  */
   722 FILE *purple_mkstemp(char **path, gboolean binary);
   723 
   724 /**
   725  * Returns an extension corresponding to the image data's file type.
   726  *
   727  * @param data A pointer to the image data
   728  * @param len  The length of the image data
   729  *
   730  * @return The appropriate extension, or "icon" if unknown.
   731  */
   732 const char *
   733 purple_util_get_image_extension(gconstpointer data, size_t len);
   734 
   735 /**
   736  * Returns a SHA-1 hash string of the data passed in.
   737  */
   738 char *purple_util_get_image_checksum(gconstpointer image_data, size_t image_len);
   739 
   740 /**
   741  * @return A hex encoded version of the SHA-1 hash of the data passed
   742  *         in with the correct file extention appended.  The file
   743  *         extension is determined by calling
   744  *         purple_util_get_image_extension().  This return value must
   745  *         be g_freed by the caller.
   746  */
   747 char *purple_util_get_image_filename(gconstpointer image_data, size_t image_len);
   748 
   749 /*@}*/
   750 
   751 
   752 /**************************************************************************/
   753 /** @name Environment Detection Functions                                 */
   754 /**************************************************************************/
   755 /*@{*/
   756 
   757 /**
   758  * Checks if the given program name is valid and executable.
   759  *
   760  * @param program The file name of the application.
   761  *
   762  * @return TRUE if the program is runable.
   763  */
   764 gboolean purple_program_is_valid(const char *program);
   765 
   766 /**
   767  * Check if running GNOME.
   768  *
   769  * @return TRUE if running GNOME, FALSE otherwise.
   770  */
   771 gboolean purple_running_gnome(void);
   772 
   773 /**
   774  * Check if running KDE.
   775  *
   776  * @return TRUE if running KDE, FALSE otherwise.
   777  */
   778 gboolean purple_running_kde(void);
   779 
   780 /**
   781  * Check if running OS X.
   782  *
   783  * @return TRUE if running OS X, FALSE otherwise.
   784  */
   785 gboolean purple_running_osx(void);
   786 
   787 /**
   788  * Returns the IP address from a socket file descriptor.
   789  *
   790  * @param fd The socket file descriptor.
   791  *
   792  * @return The IP address, or @c NULL on error.
   793  */
   794 char *purple_fd_get_ip(int fd);
   795 
   796 /*@}*/
   797 
   798 
   799 /**************************************************************************/
   800 /** @name String Functions                                                */
   801 /**************************************************************************/
   802 /*@{*/
   803 
   804 /**
   805  * Tests two strings for equality.
   806  *
   807  * Unlike strcmp(), this function will not crash if one or both of the
   808  * strings are @c NULL.
   809  *
   810  * @param left	A string
   811  * @param right A string to compare with left
   812  *
   813  * @return @c TRUE if the strings are the same, else @c FALSE.
   814  *
   815  * @since 2.6.0
   816  */
   817 gboolean purple_strequal(const gchar *left, const gchar *right);
   818 
   819 /**
   820  * Normalizes a string, so that it is suitable for comparison.
   821  *
   822  * The returned string will point to a static buffer, so if the
   823  * string is intended to be kept long-term, you <i>must</i>
   824  * g_strdup() it. Also, calling normalize() twice in the same line
   825  * will lead to problems.
   826  *
   827  * @param account  The account the string belongs to, or NULL if you do
   828  *                 not know the account.  If you use NULL, the string
   829  *                 will still be normalized, but if the PRPL uses a
   830  *                 custom normalization function then the string may
   831  *                 not be normalized correctly.
   832  * @param str      The string to normalize.
   833  *
   834  * @return A pointer to the normalized version stored in a static buffer.
   835  */
   836 const char *purple_normalize(const PurpleAccount *account, const char *str);
   837 
   838 /**
   839  * Normalizes a string, so that it is suitable for comparison.
   840  *
   841  * This is one possible implementation for the PRPL callback
   842  * function "normalize."  It returns a lowercase and UTF-8
   843  * normalized version of the string.
   844  *
   845  * @param account  The account the string belongs to.
   846  * @param str      The string to normalize.
   847  *
   848  * @return A pointer to the normalized version stored in a static buffer.
   849  */
   850 const char *purple_normalize_nocase(const PurpleAccount *account, const char *str);
   851 
   852 /**
   853  * Compares two strings to see if the first contains the second as
   854  * a proper prefix.
   855  *
   856  * @param s  The string to check.
   857  * @param p  The prefix in question.
   858  *
   859  * @return   TRUE if p is a prefix of s, otherwise FALSE.
   860  */
   861 gboolean purple_str_has_prefix(const char *s, const char *p);
   862 
   863 /**
   864  * Compares two strings to see if the second is a proper suffix
   865  * of the first.
   866  *
   867  * @param s  The string to check.
   868  * @param x  The suffix in question.
   869  *
   870  * @return   TRUE if x is a a suffix of s, otherwise FALSE.
   871  */
   872 gboolean purple_str_has_suffix(const char *s, const char *x);
   873 
   874 /**
   875  * Duplicates a string and replaces all newline characters from the
   876  * source string with HTML linebreaks.
   877  *
   878  * @param src The source string.
   879  *
   880  * @return The new string.  Must be g_free'd by the caller.
   881  */
   882 gchar *purple_strdup_withhtml(const gchar *src);
   883 
   884 /**
   885  * Ensures that all linefeeds have a matching carriage return.
   886  *
   887  * @param str The source string.
   888  *
   889  * @return The string with carriage returns.
   890  */
   891 char *purple_str_add_cr(const char *str);
   892 
   893 /**
   894  * Strips all instances of the given character from the
   895  * given string.  The string is modified in place.  This
   896  * is useful for stripping new line characters, for example.
   897  *
   898  * Example usage:
   899  * purple_str_strip_char(my_dumb_string, '\n');
   900  *
   901  * @param str     The string to strip characters from.
   902  * @param thechar The character to strip from the given string.
   903  */
   904 void purple_str_strip_char(char *str, char thechar);
   905 
   906 /**
   907  * Given a string, this replaces all instances of one character
   908  * with another.  This happens inline (the original string IS
   909  * modified).
   910  *
   911  * @param string The string from which to replace stuff.
   912  * @param delimiter The character you want replaced.
   913  * @param replacement The character you want inserted in place
   914  *        of the delimiting character.
   915  */
   916 void purple_util_chrreplace(char *string, char delimiter,
   917 						  char replacement);
   918 
   919 /**
   920  * Given a string, this replaces one substring with another
   921  * and returns a newly allocated string.
   922  *
   923  * @param string The string from which to replace stuff.
   924  * @param delimiter The substring you want replaced.
   925  * @param replacement The substring you want inserted in place
   926  *        of the delimiting substring.
   927  *
   928  * @return A new string, after performing the substitution.
   929  *         free this with g_free().
   930  */
   931 gchar *purple_strreplace(const char *string, const char *delimiter,
   932 					   const char *replacement);
   933 
   934 
   935 /**
   936  * Given a string, this replaces any utf-8 substrings in that string with
   937  * the corresponding numerical character reference, and returns a newly
   938  * allocated string.
   939  *
   940  * @param in The string which might contain utf-8 substrings
   941  *
   942  * @return A new string, with utf-8 replaced with numerical character
   943  *         references, free this with g_free()
   944 */
   945 char *purple_utf8_ncr_encode(const char *in);
   946 
   947 
   948 /**
   949  * Given a string, this replaces any numerical character references
   950  * in that string with the corresponding actual utf-8 substrings,
   951  * and returns a newly allocated string.
   952  *
   953  * @param in The string which might contain numerical character references.
   954  *
   955  * @return A new string, with numerical character references
   956  *         replaced with actual utf-8, free this with g_free().
   957  */
   958 char *purple_utf8_ncr_decode(const char *in);
   959 
   960 
   961 /**
   962  * Given a string, this replaces one substring with another
   963  * ignoring case and returns a newly allocated string.
   964  *
   965  * @param string The string from which to replace stuff.
   966  * @param delimiter The substring you want replaced.
   967  * @param replacement The substring you want inserted in place
   968  *        of the delimiting substring.
   969  *
   970  * @return A new string, after performing the substitution.
   971  *         free this with g_free().
   972  */
   973 gchar *purple_strcasereplace(const char *string, const char *delimiter,
   974 						   const char *replacement);
   975 
   976 /**
   977  * This is like strstr, except that it ignores ASCII case in
   978  * searching for the substring.
   979  *
   980  * @param haystack The string to search in.
   981  * @param needle   The substring to find.
   982  *
   983  * @return the location of the substring if found, or NULL if not
   984  */
   985 const char *purple_strcasestr(const char *haystack, const char *needle);
   986 
   987 /**
   988  * Returns a string representing a filesize in the appropriate
   989  * units (MB, KB, GB, etc.)
   990  *
   991  * @param size The size
   992  *
   993  * @return The string in units form. This must be freed.
   994  */
   995 char *purple_str_size_to_units(size_t size);
   996 
   997 /**
   998  * Converts seconds into a human-readable form.
   999  *
  1000  * @param sec The seconds.
  1001  *
  1002  * @return A human-readable form, containing days, hours, minutes, and
  1003  *         seconds.
  1004  */
  1005 char *purple_str_seconds_to_string(guint sec);
  1006 
  1007 /**
  1008  * Converts a binary string into a NUL terminated ascii string,
  1009  * replacing nonascii characters and characters below SPACE (including
  1010  * NUL) into \\xyy, where yy are two hex digits. Also backslashes are
  1011  * changed into two backslashes (\\\\). The returned, newly allocated
  1012  * string can be outputted to the console, and must be g_free()d.
  1013  *
  1014  * @param binary A string of random data, possibly with embedded NULs
  1015  *               and such.
  1016  * @param len The length in bytes of the input string. Must not be 0.
  1017  *
  1018  * @return A newly allocated ASCIIZ string.
  1019  */
  1020 char *purple_str_binary_to_ascii(const unsigned char *binary, guint len);
  1021 /*@}*/
  1022 
  1023 
  1024 /**************************************************************************/
  1025 /** @name URI/URL Functions                                               */
  1026 /**************************************************************************/
  1027 /*@{*/
  1028 
  1029 void purple_got_protocol_handler_uri(const char *uri);
  1030 
  1031 /**
  1032  * Parses a URL, returning its host, port, file path, username and password.
  1033  *
  1034  * The returned data must be freed.
  1035  *
  1036  * @param url      The URL to parse.
  1037  * @param ret_host The returned host.
  1038  * @param ret_port The returned port.
  1039  * @param ret_path The returned path.
  1040  * @param ret_user The returned username.
  1041  * @param ret_passwd The returned password.
  1042  */
  1043 gboolean purple_url_parse(const char *url, char **ret_host, int *ret_port,
  1044 						char **ret_path, char **ret_user, char **ret_passwd);
  1045 
  1046 /**
  1047  * This is the signature used for functions that act as the callback
  1048  * to purple_util_fetch_url() or purple_util_fetch_url_request().
  1049  *
  1050  * @param url_data      The same value that was returned when you called
  1051  *                      purple_fetch_url() or purple_fetch_url_request().
  1052  * @param user_data     The user data that your code passed into either
  1053  *                      purple_util_fetch_url() or purple_util_fetch_url_request().
  1054  * @param url_text      This will be NULL on error.  Otherwise this
  1055  *                      will contain the contents of the URL.
  1056  * @param len           0 on error, otherwise this is the length of buf.
  1057  * @param error_message If something went wrong then this will contain
  1058  *                      a descriptive error message, and buf will be
  1059  *                      NULL and len will be 0.
  1060  */
  1061 typedef void (*PurpleUtilFetchUrlCallback)(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message);
  1062 
  1063 /**
  1064  * Fetches the data from a URL, and passes it to a callback function.
  1065  *
  1066  * @param url        The URL.
  1067  * @param full       TRUE if this is the full URL, or FALSE if it's a
  1068  *                   partial URL.
  1069  * @param user_agent The user agent field to use, or NULL.
  1070  * @param http11     TRUE if HTTP/1.1 should be used to download the file.
  1071  * @param cb         The callback function.
  1072  * @param data       The user data to pass to the callback function.
  1073  */
  1074 #define purple_util_fetch_url(url, full, user_agent, http11, cb, data) \
  1075 	purple_util_fetch_url_request(url, full, user_agent, http11, NULL, \
  1076 		FALSE, cb, data);
  1077 
  1078 /**
  1079  * Fetches the data from a URL, and passes it to a callback function.
  1080  *
  1081  * @param url        The URL.
  1082  * @param full       TRUE if this is the full URL, or FALSE if it's a
  1083  *                   partial URL.
  1084  * @param user_agent The user agent field to use, or NULL.
  1085  * @param http11     TRUE if HTTP/1.1 should be used to download the file.
  1086  * @param max_len    The maximum number of bytes to retrieve (-1 for unlimited)
  1087  * @param cb         The callback function.
  1088  * @param data       The user data to pass to the callback function.
  1089  * @deprecated       In 3.0.0, we'll rename this to "purple_util_fetch_url" and get rid of the old one
  1090  */
  1091 #define purple_util_fetch_url_len(url, full, user_agent, http11, max_len, cb, data) \
  1092 	purple_util_fetch_url_request_len(url, full, user_agent, http11, NULL, \
  1093 		FALSE, max_len, cb, data);
  1094 
  1095 /**
  1096  * Fetches the data from a URL, and passes it to a callback function.
  1097  *
  1098  * @param url        The URL.
  1099  * @param full       TRUE if this is the full URL, or FALSE if it's a
  1100  *                   partial URL.
  1101  * @param user_agent The user agent field to use, or NULL.
  1102  * @param http11     TRUE if HTTP/1.1 should be used to download the file.
  1103  * @param request    A HTTP request to send to the server instead of the
  1104  *                   standard GET
  1105  * @param include_headers
  1106  *                   If TRUE, include the HTTP headers in the response.
  1107  * @param callback   The callback function.
  1108  * @param data       The user data to pass to the callback function.
  1109  */
  1110 PurpleUtilFetchUrlData *purple_util_fetch_url_request(const gchar *url,
  1111 		gboolean full, const gchar *user_agent, gboolean http11,
  1112 		const gchar *request, gboolean include_headers,
  1113 		PurpleUtilFetchUrlCallback callback, gpointer data);
  1114 
  1115 /**
  1116  * Fetches the data from a URL, and passes it to a callback function.
  1117  *
  1118  * @param url        The URL.
  1119  * @param full       TRUE if this is the full URL, or FALSE if it's a
  1120  *                   partial URL.
  1121  * @param user_agent The user agent field to use, or NULL.
  1122  * @param http11     TRUE if HTTP/1.1 should be used to download the file.
  1123  * @param request    A HTTP request to send to the server instead of the
  1124  *                   standard GET
  1125  * @param include_headers
  1126  *                   If TRUE, include the HTTP headers in the response.
  1127  * @param max_len    The maximum number of bytes to retrieve (-1 for unlimited)
  1128  * @param callback   The callback function.
  1129  * @param data       The user data to pass to the callback function.
  1130  * @deprecated       In 3.0.0, this will go away.
  1131  */
  1132 PurpleUtilFetchUrlData *purple_util_fetch_url_request_len(const gchar *url,
  1133 		gboolean full, const gchar *user_agent, gboolean http11,
  1134 		const gchar *request, gboolean include_headers, gssize max_len,
  1135 		PurpleUtilFetchUrlCallback callback, gpointer data);
  1136 
  1137 /**
  1138  * Fetches the data from a URL, and passes it to a callback function.
  1139  *
  1140  * @param account    The account for which the request is needed, or NULL.
  1141  * @param url        The URL.
  1142  * @param full       TRUE if this is the full URL, or FALSE if it's a
  1143  *                   partial URL.
  1144  * @param user_agent The user agent field to use, or NULL.
  1145  * @param http11     TRUE if HTTP/1.1 should be used to download the file.
  1146  * @param request    A HTTP request to send to the server instead of the
  1147  *                   standard GET
  1148  * @param include_headers
  1149  *                   If TRUE, include the HTTP headers in the response.
  1150  * @param max_len    The maximum number of bytes to retrieve (-1 for unlimited)
  1151  * @param callback   The callback function.
  1152  * @param data       The user data to pass to the callback function.
  1153  * @deprecated       In 3.0.0, we'll rename this to "purple_util_fetch_url_request" and get rid of the old one
  1154  */
  1155 PurpleUtilFetchUrlData *purple_util_fetch_url_request_len_with_account(
  1156 		PurpleAccount *account, const gchar *url,
  1157 		gboolean full, const gchar *user_agent, gboolean http11,
  1158 		const gchar *request, gboolean include_headers, gssize max_len,
  1159 		PurpleUtilFetchUrlCallback callback, gpointer data);
  1160 
  1161 /**
  1162  * Cancel a pending URL request started with either
  1163  * purple_util_fetch_url_request() or purple_util_fetch_url().
  1164  *
  1165  * @param url_data The data returned when you initiated the URL fetch.
  1166  */
  1167 void purple_util_fetch_url_cancel(PurpleUtilFetchUrlData *url_data);
  1168 
  1169 /**
  1170  * Decodes a URL into a plain string.
  1171  *
  1172  * This will change hex codes and such to their ascii equivalents.
  1173  *
  1174  * @param str The string to translate.
  1175  *
  1176  * @return The resulting string.
  1177  */
  1178 const char *purple_url_decode(const char *str);
  1179 
  1180 /**
  1181  * Encodes a URL into an escaped string.
  1182  *
  1183  * This will change non-alphanumeric characters to hex codes.
  1184  *
  1185  * @param str The string to translate.
  1186  *
  1187  * @return The resulting string.
  1188  */
  1189 const char *purple_url_encode(const char *str);
  1190 
  1191 /**
  1192  * Checks if the given email address is syntactically valid.
  1193  *
  1194  * @param address The email address to validate.
  1195  *
  1196  * @return True if the email address is syntactically correct.
  1197  */
  1198 gboolean purple_email_is_valid(const char *address);
  1199 
  1200 /**
  1201  * Checks if the given IP address is a syntactically valid IPv4 address.
  1202  *
  1203  * @param ip The IP address to validate.
  1204  *
  1205  * @return True if the IP address is syntactically correct.
  1206  * @deprecated This function will be replaced with one that validates
  1207  *             as either IPv4 or IPv6 in 3.0.0. If you don't want this,
  1208  *             behavior, use one of the more specific functions.
  1209  */
  1210 gboolean purple_ip_address_is_valid(const char *ip);
  1211 
  1212 /**
  1213  * Checks if the given IP address is a syntactically valid IPv4 address.
  1214  *
  1215  * @param ip The IP address to validate.
  1216  *
  1217  * @return True if the IP address is syntactically correct.
  1218  * @since 2.6.0
  1219  */
  1220 gboolean purple_ipv4_address_is_valid(const char *ip);
  1221 
  1222 /**
  1223  * Checks if the given IP address is a syntactically valid IPv6 address.
  1224  *
  1225  * @param ip The IP address to validate.
  1226  *
  1227  * @return True if the IP address is syntactically correct.
  1228  * @since 2.6.0
  1229  */
  1230 gboolean purple_ipv6_address_is_valid(const char *ip);
  1231 
  1232 /**
  1233  * This function extracts a list of URIs from the a "text/uri-list"
  1234  * string.  It was "borrowed" from gnome_uri_list_extract_uris
  1235  *
  1236  * @param uri_list An uri-list in the standard format.
  1237  *
  1238  * @return A GList containing strings allocated with g_malloc
  1239  *         that have been splitted from uri-list.
  1240  */
  1241 GList *purple_uri_list_extract_uris(const gchar *uri_list);
  1242 
  1243 /**
  1244  * This function extracts a list of filenames from a
  1245  * "text/uri-list" string.  It was "borrowed" from
  1246  * gnome_uri_list_extract_filenames
  1247  *
  1248  * @param uri_list A uri-list in the standard format.
  1249  *
  1250  * @return A GList containing strings allocated with g_malloc that
  1251  *         contain the filenames in the uri-list. Note that unlike
  1252  *         purple_uri_list_extract_uris() function, this will discard
  1253  *         any non-file uri from the result value.
  1254  */
  1255 GList *purple_uri_list_extract_filenames(const gchar *uri_list);
  1256 
  1257 /*@}*/
  1258 
  1259 /**************************************************************************
  1260  * UTF8 String Functions
  1261  **************************************************************************/
  1262 /*@{*/
  1263 
  1264 /**
  1265  * Attempts to convert a string to UTF-8 from an unknown encoding.
  1266  *
  1267  * This function checks the locale and tries sane defaults.
  1268  *
  1269  * @param str The source string.
  1270  *
  1271  * @return The UTF-8 string, or @c NULL if it could not be converted.
  1272  */
  1273 gchar *purple_utf8_try_convert(const char *str);
  1274 
  1275 /**
  1276  * Salvages the valid UTF-8 characters from a string, replacing any
  1277  * invalid characters with a filler character (currently hardcoded to
  1278  * '?').
  1279  *
  1280  * @param str The source string.
  1281  *
  1282  * @return A valid UTF-8 string.
  1283  */
  1284 gchar *purple_utf8_salvage(const char *str);
  1285 
  1286 /**
  1287  * Removes unprintable characters from a UTF-8 string. These characters
  1288  * (in particular low-ASCII characters) are invalid in XML 1.0 and thus
  1289  * are not allowed in XMPP and are rejected by libxml2 by default. This
  1290  * function uses g_unichar_isprint to determine what characters should
  1291  * be stripped. The returned string must be freed by the caller.
  1292  *
  1293  * @param str A valid UTF-8 string.
  1294  *
  1295  * @return A newly allocated UTF-8 string without the unprintable characters.
  1296  * @since 2.6.0
  1297  *
  1298  * @see g_unichar_isprint
  1299  */
  1300 gchar *purple_utf8_strip_unprintables(const gchar *str);
  1301 
  1302 /**
  1303  * Return the UTF-8 version of gai_strerror().  It calls gai_strerror()
  1304  * then converts the result to UTF-8.  This function is analogous to
  1305  * g_strerror().
  1306  *
  1307  * @param errnum The error code.
  1308  *
  1309  * @return The UTF-8 error message.
  1310  * @since 2.4.0
  1311  */
  1312 G_CONST_RETURN gchar *purple_gai_strerror(gint errnum);
  1313 
  1314 /**
  1315  * Compares two UTF-8 strings case-insensitively.  This comparison is
  1316  * more expensive than a simple g_utf8_collate() comparison because
  1317  * it calls g_utf8_casefold() on each string, which allocates new
  1318  * strings.
  1319  *
  1320  * @param a The first string.
  1321  * @param b The second string.
  1322  *
  1323  * @return -1 if @a is less than @a b.
  1324  *          0 if @a is equal to @a b.
  1325  *          1 if @a is greater than @a b.
  1326  */
  1327 int purple_utf8_strcasecmp(const char *a, const char *b);
  1328 
  1329 /**
  1330  * Case insensitive search for a word in a string. The needle string
  1331  * must be contained in the haystack string and not be immediately
  1332  * preceded or immediately followed by another alpha-numeric character.
  1333  *
  1334  * @param haystack The string to search in.
  1335  * @param needle   The substring to find.
  1336  *
  1337  * @return TRUE if haystack has the word, otherwise FALSE
  1338  */
  1339 gboolean purple_utf8_has_word(const char *haystack, const char *needle);
  1340 
  1341 /**
  1342  * Prints a UTF-8 message to the given file stream. The function
  1343  * tries to convert the UTF-8 message to user's locale. If this
  1344  * is not possible, the original UTF-8 text will be printed.
  1345  *
  1346  * @param filestream The file stream (e.g. STDOUT or STDERR)
  1347  * @param message    The message to print.
  1348  */
  1349 void purple_print_utf8_to_console(FILE *filestream, char *message);
  1350 
  1351 /**
  1352  * Checks for messages starting (post-HTML) with "/me ", including the space.
  1353  *
  1354  * @param message The message to check
  1355  * @param len     The message length, or -1
  1356  *
  1357  * @return TRUE if it starts with "/me ", and it has been removed, otherwise
  1358  *         FALSE
  1359  */
  1360 gboolean purple_message_meify(char *message, gssize len);
  1361 
  1362 /**
  1363  * Removes the underscore characters from a string used identify the mnemonic
  1364  * character.
  1365  *
  1366  * @param in  The string to strip
  1367  *
  1368  * @return The stripped string
  1369  */
  1370 char *purple_text_strip_mnemonic(const char *in);
  1371 
  1372 /*@}*/
  1373 
  1374 /**
  1375  * Adds 8 to something.
  1376  *
  1377  * Blame SimGuy.
  1378  *
  1379  * @param x The number to add 8 to.
  1380  *
  1381  * @return x + 8
  1382  */
  1383 #define purple_add_eight(x) ((x)+8)
  1384 
  1385 /**
  1386  * Does the reverse of purple_escape_filename
  1387  *
  1388  * This will change hex codes and such to their ascii equivalents.
  1389  *
  1390  * @param str The string to translate.
  1391  *
  1392  * @return The resulting string.
  1393  */
  1394 const char *purple_unescape_filename(const char *str);
  1395 
  1396 /**
  1397  * Escapes filesystem-unfriendly characters from a filename
  1398  *
  1399  * @param str The string to translate.
  1400  *
  1401  * @return The resulting string.
  1402  */
  1403 const char *purple_escape_filename(const char *str);
  1404 
  1405 /**
  1406  * This is added temporarily to assist the split of oscar into aim and icq.
  1407  * This should not be used by plugins.
  1408  */
  1409 const char *_purple_oscar_convert(const char *act, const char *protocol);
  1410 
  1411 /**
  1412  * Restore default signal handlers for signals which might reasonably have
  1413  * handlers. This should be called by a fork()'d child process, since child processes
  1414  * inherit the handlers of the parent.
  1415  */
  1416 void purple_restore_default_signal_handlers(void);
  1417 
  1418 /**
  1419  * Gets the host name of the machine. If it not possible to determine the
  1420  * host name, "localhost" is returned
  1421  *
  1422  * @constreturn The hostname
  1423  */
  1424 const gchar *purple_get_host_name(void);
  1425 
  1426 #ifdef __cplusplus
  1427 }
  1428 #endif
  1429 
  1430 #endif /* _PURPLE_UTIL_H_ */