comparison libpurple/util.h @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents 98520ee78f12
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
34 /** 34 /**
35 * An opaque structure representing a URL request. Can be used to cancel 35 * An opaque structure representing a URL request. Can be used to cancel
36 * the request. 36 * the request.
37 */ 37 */
38 typedef struct _PurpleUtilFetchUrlData PurpleUtilFetchUrlData; 38 typedef struct _PurpleUtilFetchUrlData PurpleUtilFetchUrlData;
39 /** @copydoc _PurpleMenuAction */ 39
40 /**
41 * A generic structure that contains information about an "action." One
42 * place this is is used is by PRPLs to tell the core the list of available
43 * right-click actions for a buddy list row.
44 */
40 typedef struct _PurpleMenuAction PurpleMenuAction; 45 typedef struct _PurpleMenuAction PurpleMenuAction;
41 /** @copydoc _PurpleKeyValuePair */ 46
47 /**
48 * A key-value pair.
49 *
50 * This is used by, among other things, purple_gtk_combo* functions to pass in a
51 * list of key-value pairs so it can display a user-friendly value.
52 */
42 typedef struct _PurpleKeyValuePair PurpleKeyValuePair; 53 typedef struct _PurpleKeyValuePair PurpleKeyValuePair;
43 54
44 #include "account.h" 55 #include "account.h"
45 #include "signals.h" 56 #include "signals.h"
46 #include "xmlnode.h" 57 #include "xmlnode.h"
47 #include "notify.h" 58 #include "notify.h"
48 59
49 60
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 struct _PurpleMenuAction
55 {
56 char *label;
57 PurpleCallback callback;
58 gpointer data;
59 GList *children;
60 };
61
62 typedef char *(*PurpleInfoFieldFormatCallback)(const char *field, size_t len); 61 typedef char *(*PurpleInfoFieldFormatCallback)(const char *field, size_t len);
63 62
64 /**
65 * A key-value pair.
66 *
67 * This is used by, among other things, purple_gtk_combo* functions to pass in a
68 * list of key-value pairs so it can display a user-friendly value.
69 */
70 struct _PurpleKeyValuePair 63 struct _PurpleKeyValuePair
71 { 64 {
72 gchar *key; 65 gchar *key;
73 void *value; 66 void *value;
74 67
75 }; 68 };
69
70 G_BEGIN_DECLS
76 71
77 /** 72 /**
78 * Creates a new PurpleMenuAction. 73 * Creates a new PurpleMenuAction.
79 * 74 *
80 * @param label The text label to display for this action. 75 * @param label The text label to display for this action.
94 * @param act The PurpleMenuAction to free. 89 * @param act The PurpleMenuAction to free.
95 */ 90 */
96 void purple_menu_action_free(PurpleMenuAction *act); 91 void purple_menu_action_free(PurpleMenuAction *act);
97 92
98 /** 93 /**
94 * Returns the label of the PurpleMenuAction.
95 *
96 * @param act The PurpleMenuAction.
97 *
98 * @return The label string.
99 */
100 char * purple_menu_action_get_label(const PurpleMenuAction *act);
101
102 /**
103 * Returns the callback of the PurpleMenuAction.
104 *
105 * @param act The PurpleMenuAction.
106 *
107 * @return The callback function.
108 */
109 PurpleCallback purple_menu_action_get_callback(const PurpleMenuAction *act);
110
111 /**
112 * Returns the data stored in the PurpleMenuAction.
113 *
114 * @param act The PurpleMenuAction.
115 *
116 * @return The data.
117 */
118 gpointer purple_menu_action_get_data(const PurpleMenuAction *act);
119
120 /**
121 * Returns the children of the PurpleMenuAction.
122 *
123 * @param act The PurpleMenuAction.
124 *
125 * @return The GList of children.
126 */
127 GList* purple_menu_action_get_children(const PurpleMenuAction *act);
128
129 /**
130 * Set the label to the PurpleMenuAction.
131 *
132 * @param act The menu action.
133 * @param label The label for the menu action.
134 */
135 void purple_menu_action_set_label(PurpleMenuAction *act, char *label);
136
137 /**
138 * Set the callback that will be used by the PurpleMenuAction.
139 *
140 * @param act The menu action.
141 * @param callback The callback.
142 */
143 void purple_menu_action_set_callback(PurpleMenuAction *act, PurpleCallback callback);
144
145 /**
146 * Set the label to the PurpleMenuAction.
147 *
148 * @param act The menu action.
149 * @param data The data used by this PurpleMenuAction
150 */
151 void purple_menu_action_set_data(PurpleMenuAction *act, gpointer data);
152
153 /**
154 * Set the children of the PurpleMenuAction.
155 *
156 * @param act The menu action.
157 * @param children The PurpleMenuAtion children
158 */
159 void purple_menu_action_set_children(PurpleMenuAction *act, GList *children);
160
161 /**
99 * Set the appropriate presence values for the currently playing song. 162 * Set the appropriate presence values for the currently playing song.
100 * 163 *
101 * @param title The title of the song, @c NULL to unset the value. 164 * @param title The title of the song, @c NULL to unset the value.
102 * @param artist The artist of the song, can be @c NULL. 165 * @param artist The artist of the song, can be @c NULL.
103 * @param album The album of the song, can be @c NULL. 166 * @param album The album of the song, can be @c NULL.
104 * @since 2.4.0
105 */ 167 */
106 void purple_util_set_current_song(const char *title, const char *artist, 168 void purple_util_set_current_song(const char *title, const char *artist,
107 const char *album); 169 const char *album);
108 170
109 /** 171 /**
113 * @param artist The artist of the song, can be @c NULL. 175 * @param artist The artist of the song, can be @c NULL.
114 * @param album The album of the song, can be @c NULL. 176 * @param album The album of the song, can be @c NULL.
115 * @param unused Currently unused, must be @c NULL. 177 * @param unused Currently unused, must be @c NULL.
116 * 178 *
117 * @return The formatted string. The caller must g_free the returned string. 179 * @return The formatted string. The caller must g_free the returned string.
118 * @since 2.4.0
119 */ 180 */
120 char * purple_util_format_song_info(const char *title, const char *artist, 181 char * purple_util_format_song_info(const char *title, const char *artist,
121 const char *album, gpointer unused); 182 const char *album, gpointer unused);
122 183
123 /**************************************************************************/ 184 /**************************************************************************/
125 /**************************************************************************/ 186 /**************************************************************************/
126 /*@{*/ 187 /*@{*/
127 188
128 /** 189 /**
129 * Initializes the utility subsystem. 190 * Initializes the utility subsystem.
130 *
131 * @since 2.3.0
132 */ 191 */
133 void purple_util_init(void); 192 void purple_util_init(void);
134 193
135 /** 194 /**
136 * Uninitializes the util subsystem. 195 * Uninitializes the util subsystem.
137 *
138 * @since 2.3.0
139 */ 196 */
140 void purple_util_uninit(void); 197 void purple_util_uninit(void);
141 198
142 /*@}*/ 199 /*@}*/
143 200
427 * replaced with &lt; 484 * replaced with &lt;
428 * 485 *
429 * This is exactly the same as g_markup_escape_text(), except that it 486 * This is exactly the same as g_markup_escape_text(), except that it
430 * does not change ' to &apos; because &apos; is not a valid HTML 4 entity, 487 * does not change ' to &apos; because &apos; is not a valid HTML 4 entity,
431 * and is displayed literally in IE7. 488 * and is displayed literally in IE7.
432 *
433 * @since 2.6.0
434 */ 489 */
435 gchar *purple_markup_escape_text(const gchar *text, gssize length); 490 gchar *purple_markup_escape_text(const gchar *text, gssize length);
436 491
437 /** 492 /**
438 * Finds an HTML tag matching the given name. 493 * Finds an HTML tag matching the given name.
529 * 584 *
530 * @return The text with HTML entities literalized. You must g_free 585 * @return The text with HTML entities literalized. You must g_free
531 * this string when finished with it. 586 * this string when finished with it.
532 * 587 *
533 * @see purple_unescape_html() 588 * @see purple_unescape_html()
534 * @since 2.7.0
535 */ 589 */
536 char *purple_unescape_text(const char *text); 590 char *purple_unescape_text(const char *text);
537 591
538 /** 592 /**
539 * Unescapes HTML entities to their literal characters and converts 593 * Unescapes HTML entities to their literal characters and converts
622 * Check if the given HTML contains RTL text. 676 * Check if the given HTML contains RTL text.
623 * 677 *
624 * @param html The HTML text. 678 * @param html The HTML text.
625 * 679 *
626 * @return TRUE if the text contains RTL text, FALSE otherwise. 680 * @return TRUE if the text contains RTL text, FALSE otherwise.
627 *
628 * @since 2.6.0
629 */ 681 */
630 gboolean purple_markup_is_rtl(const char *html); 682 gboolean purple_markup_is_rtl(const char *html);
631 683
632 /*@}*/ 684 /*@}*/
633 685
824 * 876 *
825 * @param fd The socket file descriptor. 877 * @param fd The socket file descriptor.
826 * 878 *
827 * @return The address family of the socket (AF_INET, AF_INET6, etc) or -1 879 * @return The address family of the socket (AF_INET, AF_INET6, etc) or -1
828 * on error. 880 * on error.
829 * @since 2.7.0
830 */ 881 */
831 int purple_socket_get_family(int fd); 882 int purple_socket_get_family(int fd);
832 883
833 /** 884 /**
834 * Returns TRUE if a socket is capable of speaking IPv4. 885 * Returns TRUE if a socket is capable of speaking IPv4.
836 * This is the case for IPv4 sockets and, on some systems, IPv6 sockets 887 * This is the case for IPv4 sockets and, on some systems, IPv6 sockets
837 * (due to the IPv4-mapped address functionality). 888 * (due to the IPv4-mapped address functionality).
838 * 889 *
839 * @param fd The socket file descriptor 890 * @param fd The socket file descriptor
840 * @return TRUE if a socket can speak IPv4. 891 * @return TRUE if a socket can speak IPv4.
841 * @since 2.7.0
842 */ 892 */
843 gboolean purple_socket_speaks_ipv4(int fd); 893 gboolean purple_socket_speaks_ipv4(int fd);
844 894
845 /*@}*/ 895 /*@}*/
846 896
858 * 908 *
859 * @param left A string 909 * @param left A string
860 * @param right A string to compare with left 910 * @param right A string to compare with left
861 * 911 *
862 * @return @c TRUE if the strings are the same, else @c FALSE. 912 * @return @c TRUE if the strings are the same, else @c FALSE.
863 *
864 * @since 2.6.0
865 */ 913 */
866 gboolean purple_strequal(const gchar *left, const gchar *right); 914 gboolean purple_strequal(const gchar *left, const gchar *right);
867 915
868 /** 916 /**
869 * Normalizes a string, so that it is suitable for comparison. 917 * Normalizes a string, so that it is suitable for comparison.
1039 * 1087 *
1040 * @param size The size 1088 * @param size The size
1041 * 1089 *
1042 * @return The string in units form. This must be freed. 1090 * @return The string in units form. This must be freed.
1043 */ 1091 */
1044 char *purple_str_size_to_units(size_t size); 1092 char *purple_str_size_to_units(goffset size);
1045 1093
1046 /** 1094 /**
1047 * Converts seconds into a human-readable form. 1095 * Converts seconds into a human-readable form.
1048 * 1096 *
1049 * @param sec The seconds. 1097 * @param sec The seconds.
1115 * @param url The URL. 1163 * @param url The URL.
1116 * @param full TRUE if this is the full URL, or FALSE if it's a 1164 * @param full TRUE if this is the full URL, or FALSE if it's a
1117 * partial URL. 1165 * partial URL.
1118 * @param user_agent The user agent field to use, or NULL. 1166 * @param user_agent The user agent field to use, or NULL.
1119 * @param http11 TRUE if HTTP/1.1 should be used to download the file. 1167 * @param http11 TRUE if HTTP/1.1 should be used to download the file.
1120 * @param cb The callback function.
1121 * @param data The user data to pass to the callback function.
1122 */
1123 #define purple_util_fetch_url(url, full, user_agent, http11, cb, data) \
1124 purple_util_fetch_url_request(url, full, user_agent, http11, NULL, \
1125 FALSE, cb, data);
1126
1127 /**
1128 * Fetches the data from a URL, and passes it to a callback function.
1129 *
1130 * @param url The URL.
1131 * @param full TRUE if this is the full URL, or FALSE if it's a
1132 * partial URL.
1133 * @param user_agent The user agent field to use, or NULL.
1134 * @param http11 TRUE if HTTP/1.1 should be used to download the file.
1135 * @param max_len The maximum number of bytes to retrieve (-1 for unlimited) 1168 * @param max_len The maximum number of bytes to retrieve (-1 for unlimited)
1136 * @param cb The callback function. 1169 * @param cb The callback function.
1137 * @param data The user data to pass to the callback function. 1170 * @param data The user data to pass to the callback function.
1138 * @deprecated In 3.0.0, we'll rename this to "purple_util_fetch_url" and get rid of the old one 1171 */
1139 */ 1172 #define purple_util_fetch_url(url, full, user_agent, http11, max_len, cb, data) \
1140 #define purple_util_fetch_url_len(url, full, user_agent, http11, max_len, cb, data) \ 1173 purple_util_fetch_url_request(NULL, url, full, user_agent, http11, NULL, \
1141 purple_util_fetch_url_request_len(url, full, user_agent, http11, NULL, \
1142 FALSE, max_len, cb, data); 1174 FALSE, max_len, cb, data);
1143
1144 /**
1145 * Fetches the data from a URL, and passes it to a callback function.
1146 *
1147 * @param url The URL.
1148 * @param full TRUE if this is the full URL, or FALSE if it's a
1149 * partial URL.
1150 * @param user_agent The user agent field to use, or NULL.
1151 * @param http11 TRUE if HTTP/1.1 should be used to download the file.
1152 * @param request A HTTP request to send to the server instead of the
1153 * standard GET
1154 * @param include_headers
1155 * If TRUE, include the HTTP headers in the response.
1156 * @param callback The callback function.
1157 * @param data The user data to pass to the callback function.
1158 */
1159 PurpleUtilFetchUrlData *purple_util_fetch_url_request(const gchar *url,
1160 gboolean full, const gchar *user_agent, gboolean http11,
1161 const gchar *request, gboolean include_headers,
1162 PurpleUtilFetchUrlCallback callback, gpointer data);
1163
1164 /**
1165 * Fetches the data from a URL, and passes it to a callback function.
1166 *
1167 * @param url The URL.
1168 * @param full TRUE if this is the full URL, or FALSE if it's a
1169 * partial URL.
1170 * @param user_agent The user agent field to use, or NULL.
1171 * @param http11 TRUE if HTTP/1.1 should be used to download the file.
1172 * @param request A HTTP request to send to the server instead of the
1173 * standard GET
1174 * @param include_headers
1175 * If TRUE, include the HTTP headers in the response.
1176 * @param max_len The maximum number of bytes to retrieve (-1 for unlimited)
1177 * @param callback The callback function.
1178 * @param data The user data to pass to the callback function.
1179 * @deprecated In 3.0.0, this will go away.
1180 */
1181 PurpleUtilFetchUrlData *purple_util_fetch_url_request_len(const gchar *url,
1182 gboolean full, const gchar *user_agent, gboolean http11,
1183 const gchar *request, gboolean include_headers, gssize max_len,
1184 PurpleUtilFetchUrlCallback callback, gpointer data);
1185 1175
1186 /** 1176 /**
1187 * Fetches the data from a URL, and passes it to a callback function. 1177 * Fetches the data from a URL, and passes it to a callback function.
1188 * 1178 *
1189 * @param account The account for which the request is needed, or NULL. 1179 * @param account The account for which the request is needed, or NULL.
1197 * @param include_headers 1187 * @param include_headers
1198 * If TRUE, include the HTTP headers in the response. 1188 * If TRUE, include the HTTP headers in the response.
1199 * @param max_len The maximum number of bytes to retrieve (-1 for unlimited) 1189 * @param max_len The maximum number of bytes to retrieve (-1 for unlimited)
1200 * @param callback The callback function. 1190 * @param callback The callback function.
1201 * @param data The user data to pass to the callback function. 1191 * @param data The user data to pass to the callback function.
1202 * @deprecated In 3.0.0, we'll rename this to "purple_util_fetch_url_request" and get rid of the old one 1192 */
1203 */ 1193 PurpleUtilFetchUrlData *purple_util_fetch_url_request(
1204 PurpleUtilFetchUrlData *purple_util_fetch_url_request_len_with_account(
1205 PurpleAccount *account, const gchar *url, 1194 PurpleAccount *account, const gchar *url,
1206 gboolean full, const gchar *user_agent, gboolean http11, 1195 gboolean full, const gchar *user_agent, gboolean http11,
1207 const gchar *request, gboolean include_headers, gssize max_len, 1196 const gchar *request, gboolean include_headers, gssize max_len,
1208 PurpleUtilFetchUrlCallback callback, gpointer data); 1197 PurpleUtilFetchUrlCallback callback, gpointer data);
1209 1198
1245 * @return True if the email address is syntactically correct. 1234 * @return True if the email address is syntactically correct.
1246 */ 1235 */
1247 gboolean purple_email_is_valid(const char *address); 1236 gboolean purple_email_is_valid(const char *address);
1248 1237
1249 /** 1238 /**
1239 * Checks if the given IP address is a syntactically valid IPv4 or
1240 * IPv6 address.
1241 * If you specifically want to check for an IPv4 address use
1242 * purple_ipv4_address_is_valid(), or for an IPv6 address use
1243 * purple_ipv6_address_is_valid().
1244 *
1245 * @param ip The IP address to validate.
1246 *
1247 * @return True if the IP address is syntactically correct.
1248 */
1249 gboolean purple_ip_address_is_valid(const char *ip);
1250
1251 /**
1250 * Checks if the given IP address is a syntactically valid IPv4 address. 1252 * Checks if the given IP address is a syntactically valid IPv4 address.
1251 * 1253 *
1252 * @param ip The IP address to validate. 1254 * @param ip The IP address to validate.
1253 * 1255 *
1254 * @return True if the IP address is syntactically correct. 1256 * @return True if the IP address is syntactically correct.
1255 * @deprecated This function will be replaced with one that validates 1257 */
1256 * as either IPv4 or IPv6 in 3.0.0. If you don't want this, 1258 gboolean purple_ipv4_address_is_valid(const char *ip);
1257 * behavior, use one of the more specific functions. 1259
1258 */ 1260 /**
1259 gboolean purple_ip_address_is_valid(const char *ip); 1261 * Checks if the given IP address is a syntactically valid IPv6 address.
1260
1261 /**
1262 * Checks if the given IP address is a syntactically valid IPv4 address.
1263 * 1262 *
1264 * @param ip The IP address to validate. 1263 * @param ip The IP address to validate.
1265 * 1264 *
1266 * @return True if the IP address is syntactically correct. 1265 * @return True if the IP address is syntactically correct.
1267 * @since 2.6.0
1268 */
1269 gboolean purple_ipv4_address_is_valid(const char *ip);
1270
1271 /**
1272 * Checks if the given IP address is a syntactically valid IPv6 address.
1273 *
1274 * @param ip The IP address to validate.
1275 *
1276 * @return True if the IP address is syntactically correct.
1277 * @since 2.6.0
1278 */ 1266 */
1279 gboolean purple_ipv6_address_is_valid(const char *ip); 1267 gboolean purple_ipv6_address_is_valid(const char *ip);
1280 1268
1281 /** 1269 /**
1282 * This function extracts a list of URIs from the a "text/uri-list" 1270 * This function extracts a list of URIs from the a "text/uri-list"
1340 * The returned string must be freed by the caller. 1328 * The returned string must be freed by the caller.
1341 * 1329 *
1342 * @param str A valid UTF-8 string. 1330 * @param str A valid UTF-8 string.
1343 * 1331 *
1344 * @return A newly allocated UTF-8 string without the unprintable characters. 1332 * @return A newly allocated UTF-8 string without the unprintable characters.
1345 * @since 2.6.0
1346 */ 1333 */
1347 gchar *purple_utf8_strip_unprintables(const gchar *str); 1334 gchar *purple_utf8_strip_unprintables(const gchar *str);
1348 1335
1349 /** 1336 /**
1350 * Return the UTF-8 version of gai_strerror(). It calls gai_strerror() 1337 * Return the UTF-8 version of gai_strerror(). It calls gai_strerror()
1352 * g_strerror(). 1339 * g_strerror().
1353 * 1340 *
1354 * @param errnum The error code. 1341 * @param errnum The error code.
1355 * 1342 *
1356 * @return The UTF-8 error message. 1343 * @return The UTF-8 error message.
1357 * @since 2.4.0 1344 */
1358 */ 1345 const gchar *purple_gai_strerror(gint errnum);
1359 G_CONST_RETURN gchar *purple_gai_strerror(gint errnum);
1360 1346
1361 /** 1347 /**
1362 * Compares two UTF-8 strings case-insensitively. This comparison is 1348 * Compares two UTF-8 strings case-insensitively. This comparison is
1363 * more expensive than a simple g_utf8_collate() comparison because 1349 * more expensive than a simple g_utf8_collate() comparison because
1364 * it calls g_utf8_casefold() on each string, which allocates new 1350 * it calls g_utf8_casefold() on each string, which allocates new
1448 * @return The resulting string. 1434 * @return The resulting string.
1449 */ 1435 */
1450 const char *purple_escape_filename(const char *str); 1436 const char *purple_escape_filename(const char *str);
1451 1437
1452 /** 1438 /**
1453 * This is added temporarily to assist the split of oscar into aim and icq.
1454 * This should not be used by plugins.
1455 *
1456 * @deprecated This function should not be used in new code and should be
1457 * removed in 3.0.0. The aim/icq prpl split happened a long
1458 * time ago, and we don't need to keep migrating old data.
1459 */
1460 const char *_purple_oscar_convert(const char *act, const char *protocol);
1461
1462 /**
1463 * Restore default signal handlers for signals which might reasonably have 1439 * Restore default signal handlers for signals which might reasonably have
1464 * handlers. This should be called by a fork()'d child process, since child processes 1440 * handlers. This should be called by a fork()'d child process, since child processes
1465 * inherit the handlers of the parent. 1441 * inherit the handlers of the parent.
1466 */ 1442 */
1467 void purple_restore_default_signal_handlers(void); 1443 void purple_restore_default_signal_handlers(void);
1476 1452
1477 /** 1453 /**
1478 * Returns a type 4 (random) UUID 1454 * Returns a type 4 (random) UUID
1479 * 1455 *
1480 * @return A UUID, caller is responsible for freeing it 1456 * @return A UUID, caller is responsible for freeing it
1481 * @since 2.7.0
1482 */ 1457 */
1483 gchar *purple_uuid_random(void); 1458 gchar *purple_uuid_random(void);
1484 1459
1485 #ifdef __cplusplus 1460 G_END_DECLS
1486 }
1487 #endif
1488 1461
1489 #endif /* _PURPLE_UTIL_H_ */ 1462 #endif /* _PURPLE_UTIL_H_ */