|
Evan@653
|
1 |
/** |
|
Evan@653
|
2 |
* @file internal.h Internal definitions and includes |
|
Evan@653
|
3 |
* @ingroup core |
|
Evan@653
|
4 |
*/ |
|
Evan@653
|
5 |
|
|
Evan@653
|
6 |
/* purple |
|
Evan@653
|
7 |
* |
|
Evan@653
|
8 |
* Purple is the legal property of its developers, whose names are too numerous |
|
Evan@653
|
9 |
* to list here. Please refer to the COPYRIGHT file distributed with this |
|
Evan@653
|
10 |
* source distribution. |
|
Evan@653
|
11 |
* |
|
Evan@653
|
12 |
* This program is free software; you can redistribute it and/or modify |
|
Evan@653
|
13 |
* it under the terms of the GNU General Public License as published by |
|
Evan@653
|
14 |
* the Free Software Foundation; either version 2 of the License, or |
|
Evan@653
|
15 |
* (at your option) any later version. |
|
Evan@653
|
16 |
* |
|
Evan@653
|
17 |
* This program is distributed in the hope that it will be useful, |
|
Evan@653
|
18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
Evan@653
|
19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
Evan@653
|
20 |
* GNU General Public License for more details. |
|
Evan@653
|
21 |
* |
|
Evan@653
|
22 |
* You should have received a copy of the GNU General Public License |
|
Evan@653
|
23 |
* along with this program; if not, write to the Free Software |
|
Evan@653
|
24 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
Evan@653
|
25 |
*/ |
|
Evan@653
|
26 |
#ifndef _PURPLE_INTERNAL_H_ |
|
Evan@653
|
27 |
#define _PURPLE_INTERNAL_H_ |
|
Evan@653
|
28 |
|
|
Evan@653
|
29 |
#ifdef HAVE_CONFIG_H |
|
Evan@653
|
30 |
# include <config.h> |
|
Evan@653
|
31 |
#endif |
|
Evan@653
|
32 |
|
|
Evan@653
|
33 |
/* for SIOCGIFCONF in SKYOS */ |
|
Evan@653
|
34 |
#ifdef SKYOS |
|
Evan@653
|
35 |
#include <net/sockios.h> |
|
Evan@653
|
36 |
#endif |
|
Evan@653
|
37 |
/* |
|
Evan@653
|
38 |
* If we're using NLS, make sure gettext works. If not, then define |
|
Evan@653
|
39 |
* dummy macros in place of the normal gettext macros. |
|
Evan@653
|
40 |
* |
|
Evan@653
|
41 |
* Also, the perl XS config.h file sometimes defines _ So we need to |
|
Evan@653
|
42 |
* make sure _ isn't already defined before trying to define it. |
|
Evan@653
|
43 |
* |
|
Evan@653
|
44 |
* The Singular/Plural/Number ngettext dummy definition below was |
|
Evan@653
|
45 |
* taken from an email to the texinfo mailing list by Manuel Guerrero. |
|
Evan@653
|
46 |
* Thank you Manuel, and thank you Alex's good friend Google. |
|
Evan@653
|
47 |
*/ |
|
Evan@653
|
48 |
#ifdef ENABLE_NLS |
|
Evan@653
|
49 |
# include <locale.h> |
|
Evan@653
|
50 |
# include <libintl.h> |
|
Evan@653
|
51 |
# define _(String) ((const char *)dgettext(PACKAGE, String)) |
|
Evan@653
|
52 |
# ifdef gettext_noop |
|
Evan@653
|
53 |
# define N_(String) gettext_noop (String) |
|
Evan@653
|
54 |
# else |
|
Evan@653
|
55 |
# define N_(String) (String) |
|
Evan@653
|
56 |
# endif |
|
Evan@653
|
57 |
#else |
|
Evan@653
|
58 |
# include <locale.h> |
|
Evan@653
|
59 |
# define N_(String) (String) |
|
Evan@653
|
60 |
# ifndef _ |
|
Evan@653
|
61 |
# define _(String) ((const char *)String) |
|
Evan@653
|
62 |
# endif |
|
Evan@653
|
63 |
# define ngettext(Singular, Plural, Number) ((Number == 1) ? ((const char *)Singular) : ((const char *)Plural)) |
|
Evan@653
|
64 |
# define dngettext(Domain, Singular, Plural, Number) ((Number == 1) ? ((const char *)Singular) : ((const char *)Plural)) |
|
Evan@653
|
65 |
#endif |
|
Evan@653
|
66 |
|
|
Evan@653
|
67 |
#ifdef HAVE_ENDIAN_H |
|
Evan@653
|
68 |
# include <endian.h> |
|
Evan@653
|
69 |
#endif |
|
Evan@653
|
70 |
|
|
Evan@653
|
71 |
#define MSG_LEN 2048 |
|
Evan@653
|
72 |
/* The above should normally be the same as BUF_LEN, |
|
Evan@653
|
73 |
* but just so we're explicitly asking for the max message |
|
Evan@653
|
74 |
* length. */ |
|
Evan@653
|
75 |
#define BUF_LEN MSG_LEN |
|
Evan@653
|
76 |
#define BUF_LONG BUF_LEN * 2 |
|
Evan@653
|
77 |
|
|
Evan@653
|
78 |
#include <sys/stat.h> |
|
Evan@653
|
79 |
#include <sys/types.h> |
|
Evan@653
|
80 |
#ifndef _WIN32 |
|
Evan@653
|
81 |
#include <sys/time.h> |
|
Evan@653
|
82 |
#include <sys/wait.h> |
|
Evan@653
|
83 |
#include <sys/time.h> |
|
Evan@653
|
84 |
#endif |
|
Evan@653
|
85 |
#include <ctype.h> |
|
Evan@653
|
86 |
#include <errno.h> |
|
Evan@653
|
87 |
#include <fcntl.h> |
|
Evan@653
|
88 |
#include <math.h> |
|
Evan@653
|
89 |
#include <stdio.h> |
|
Evan@653
|
90 |
#include <stdlib.h> |
|
Evan@653
|
91 |
#include <string.h> |
|
Evan@653
|
92 |
#include <time.h> |
|
Evan@653
|
93 |
|
|
Evan@653
|
94 |
#ifdef HAVE_ICONV |
|
Evan@653
|
95 |
#include <iconv.h> |
|
Evan@653
|
96 |
#endif |
|
Evan@653
|
97 |
|
|
Evan@653
|
98 |
#ifdef HAVE_LANGINFO_CODESET |
|
Evan@653
|
99 |
#include <langinfo.h> |
|
Evan@653
|
100 |
#endif |
|
Evan@653
|
101 |
|
|
Evan@653
|
102 |
#include <gmodule.h> |
|
Evan@653
|
103 |
|
|
Evan@653
|
104 |
#ifdef PURPLE_PLUGINS |
|
Evan@1427
|
105 |
# ifdef HAVE_DLFCN_H |
|
Evan@653
|
106 |
# include <dlfcn.h> |
|
Evan@653
|
107 |
# endif |
|
Evan@653
|
108 |
#endif |
|
Evan@653
|
109 |
|
|
Evan@653
|
110 |
#ifndef _WIN32 |
|
Evan@653
|
111 |
# include <netinet/in.h> |
|
Evan@653
|
112 |
# include <sys/socket.h> |
|
Evan@653
|
113 |
# include <arpa/inet.h> |
|
Evan@653
|
114 |
# include <sys/un.h> |
|
Evan@653
|
115 |
# include <sys/utsname.h> |
|
Evan@653
|
116 |
# include <netdb.h> |
|
Evan@653
|
117 |
# include <signal.h> |
|
Evan@653
|
118 |
# include <unistd.h> |
|
Evan@653
|
119 |
#endif |
|
Evan@653
|
120 |
|
|
Evan@653
|
121 |
/* MAXPATHLEN should only be used with readlink() on glib < 2.4.0. For |
|
Evan@653
|
122 |
* anything else, use g_file_read_link() or other dynamic functions. This is |
|
Evan@653
|
123 |
* important because Hurd has no hard limits on path length. */ |
|
Evan@653
|
124 |
#if !GLIB_CHECK_VERSION(2,4,0) |
|
Evan@653
|
125 |
# ifndef MAXPATHLEN |
|
Evan@653
|
126 |
# ifdef PATH_MAX |
|
Evan@653
|
127 |
# define MAXPATHLEN PATH_MAX |
|
Evan@653
|
128 |
# else |
|
Evan@653
|
129 |
# define MAXPATHLEN 1024 |
|
Evan@653
|
130 |
# endif |
|
Evan@653
|
131 |
# endif |
|
Evan@653
|
132 |
#endif |
|
Evan@653
|
133 |
|
|
Evan@653
|
134 |
#ifndef HOST_NAME_MAX |
|
Evan@653
|
135 |
# define HOST_NAME_MAX 255 |
|
Evan@653
|
136 |
#endif |
|
Evan@653
|
137 |
|
|
Evan@653
|
138 |
#include <glib.h> |
|
Evan@653
|
139 |
#if !GLIB_CHECK_VERSION(2,4,0) |
|
Evan@653
|
140 |
# define G_MAXUINT32 ((guint32) 0xffffffff) |
|
Evan@653
|
141 |
#endif |
|
Evan@653
|
142 |
|
|
Evan@653
|
143 |
#ifndef G_MAXSIZE |
|
Evan@653
|
144 |
# if GLIB_SIZEOF_LONG == 8 |
|
Evan@653
|
145 |
# define G_MAXSIZE ((gsize) 0xffffffffffffffff) |
|
Evan@653
|
146 |
# else |
|
Evan@653
|
147 |
# define G_MAXSIZE ((gsize) 0xffffffff) |
|
Evan@653
|
148 |
# endif |
|
Evan@653
|
149 |
#endif |
|
Evan@653
|
150 |
|
|
zacw@2535
|
151 |
#ifndef G_MAXSSIZE |
|
zacw@2535
|
152 |
# if GLIB_SIZEOF_LONG == 8 |
|
zacw@2535
|
153 |
# define G_MAXSSIZE ((gssize) 0x7fffffffffffffff) |
|
zacw@2535
|
154 |
# else |
|
zacw@2535
|
155 |
# define G_MAXSSIZE ((gssize) 0x7fffffff) |
|
zacw@2535
|
156 |
# endif |
|
zacw@2535
|
157 |
#endif |
|
zacw@2535
|
158 |
|
|
Evan@653
|
159 |
#if GLIB_CHECK_VERSION(2,6,0) |
|
Evan@653
|
160 |
# include <glib/gstdio.h> |
|
Evan@653
|
161 |
#endif |
|
Evan@653
|
162 |
|
|
Evan@653
|
163 |
#if !GLIB_CHECK_VERSION(2,6,0) |
|
Evan@653
|
164 |
# define g_freopen freopen |
|
Evan@653
|
165 |
# define g_fopen fopen |
|
Evan@653
|
166 |
# define g_rmdir rmdir |
|
Evan@653
|
167 |
# define g_remove remove |
|
Evan@653
|
168 |
# define g_unlink unlink |
|
Evan@653
|
169 |
# define g_lstat lstat |
|
Evan@653
|
170 |
# define g_stat stat |
|
Evan@653
|
171 |
# define g_mkdir mkdir |
|
Evan@653
|
172 |
# define g_rename rename |
|
Evan@653
|
173 |
# define g_open open |
|
Evan@653
|
174 |
#endif |
|
Evan@653
|
175 |
|
|
Evan@653
|
176 |
#if !GLIB_CHECK_VERSION(2,8,0) && !defined _WIN32 |
|
Evan@653
|
177 |
# define g_access access |
|
Evan@653
|
178 |
#endif |
|
Evan@653
|
179 |
|
|
Evan@653
|
180 |
#if !GLIB_CHECK_VERSION(2,10,0) |
|
Evan@653
|
181 |
# define g_slice_new(type) g_new(type, 1) |
|
Evan@653
|
182 |
# define g_slice_new0(type) g_new0(type, 1) |
|
Evan@653
|
183 |
# define g_slice_free(type, mem) g_free(mem) |
|
Evan@653
|
184 |
#endif |
|
Evan@653
|
185 |
|
|
Evan@653
|
186 |
#ifdef _WIN32 |
|
Evan@653
|
187 |
#include "win32dep.h" |
|
Evan@653
|
188 |
#endif |
|
Evan@653
|
189 |
|
|
Evan@653
|
190 |
/* ugly ugly ugly */ |
|
Evan@653
|
191 |
/* This is a workaround for the fact that G_GINT64_MODIFIER and G_GSIZE_FORMAT |
|
Evan@653
|
192 |
* are only defined in Glib >= 2.4 */ |
|
Evan@653
|
193 |
#ifndef G_GINT64_MODIFIER |
|
Evan@653
|
194 |
# if GLIB_SIZEOF_LONG == 8 |
|
Evan@653
|
195 |
# define G_GINT64_MODIFIER "l" |
|
Evan@653
|
196 |
# else |
|
Evan@653
|
197 |
# define G_GINT64_MODIFIER "ll" |
|
Evan@653
|
198 |
# endif |
|
Evan@653
|
199 |
#endif |
|
Evan@653
|
200 |
|
|
Evan@653
|
201 |
#ifndef G_GSIZE_MODIFIER |
|
Evan@653
|
202 |
# if GLIB_SIZEOF_LONG == 8 |
|
Evan@653
|
203 |
# define G_GSIZE_MODIFIER "l" |
|
Evan@653
|
204 |
# else |
|
Evan@653
|
205 |
# define G_GSIZE_MODIFIER "" |
|
Evan@653
|
206 |
# endif |
|
Evan@653
|
207 |
#endif |
|
Evan@653
|
208 |
|
|
Evan@653
|
209 |
#ifndef G_GSIZE_FORMAT |
|
Evan@653
|
210 |
# if GLIB_SIZEOF_LONG == 8 |
|
Evan@653
|
211 |
# define G_GSIZE_FORMAT "lu" |
|
Evan@653
|
212 |
# else |
|
Evan@653
|
213 |
# define G_GSIZE_FORMAT "u" |
|
Evan@653
|
214 |
# endif |
|
Evan@653
|
215 |
#endif |
|
Evan@653
|
216 |
|
|
Evan@653
|
217 |
#ifndef G_GSSIZE_FORMAT |
|
Evan@653
|
218 |
# if GLIB_SIZEOF_LONG == 8 |
|
Evan@653
|
219 |
# define G_GSSIZE_FORMAT "li" |
|
Evan@653
|
220 |
# else |
|
Evan@653
|
221 |
# define G_GSSIZE_FORMAT "i" |
|
Evan@653
|
222 |
# endif |
|
Evan@653
|
223 |
#endif |
|
Evan@653
|
224 |
|
|
Evan@653
|
225 |
#ifndef G_GNUC_NULL_TERMINATED |
|
Evan@653
|
226 |
# if __GNUC__ >= 4 |
|
Evan@653
|
227 |
# define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__)) |
|
Evan@653
|
228 |
# else |
|
Evan@653
|
229 |
# define G_GNUC_NULL_TERMINATED |
|
Evan@653
|
230 |
# endif |
|
Evan@653
|
231 |
#endif |
|
Evan@653
|
232 |
|
|
zacw@2535
|
233 |
#ifdef HAVE_CONFIG_H |
|
zacw@2535
|
234 |
#if SIZEOF_TIME_T == 4 |
|
zacw@2535
|
235 |
# define PURPLE_TIME_T_MODIFIER "lu" |
|
zacw@2535
|
236 |
#elif SIZEOF_TIME_T == 8 |
|
zacw@2535
|
237 |
# define PURPLE_TIME_T_MODIFIER "zu" |
|
zacw@2535
|
238 |
#else |
|
zacw@2535
|
239 |
#error Unknown size of time_t |
|
zacw@2535
|
240 |
#endif |
|
zacw@2535
|
241 |
#endif |
|
zacw@2535
|
242 |
|
|
zacw@1759
|
243 |
#include <glib-object.h> |
|
zacw@1759
|
244 |
|
|
zacw@1759
|
245 |
#ifndef G_DEFINE_TYPE |
|
zacw@1759
|
246 |
#define G_DEFINE_TYPE(TypeName, type_name, TYPE_PARENT) \ |
|
zacw@1759
|
247 |
\ |
|
zacw@1759
|
248 |
static void type_name##_init (TypeName *self); \ |
|
zacw@1759
|
249 |
static void type_name##_class_init (TypeName##Class *klass); \ |
|
zacw@1759
|
250 |
static gpointer type_name##_parent_class = NULL; \ |
|
zacw@1759
|
251 |
static void type_name##_class_intern_init (gpointer klass) \ |
|
zacw@1759
|
252 |
{ \ |
|
zacw@1759
|
253 |
type_name##_parent_class = g_type_class_peek_parent (klass); \ |
|
zacw@1759
|
254 |
type_name##_class_init ((TypeName##Class*) klass); \ |
|
zacw@1759
|
255 |
} \ |
|
zacw@1759
|
256 |
\ |
|
zacw@1759
|
257 |
GType \ |
|
zacw@1759
|
258 |
type_name##_get_type (void) \ |
|
zacw@1759
|
259 |
{ \ |
|
zacw@1759
|
260 |
static GType g_define_type_id = 0; \ |
|
zacw@1759
|
261 |
if (G_UNLIKELY (g_define_type_id == 0)) \ |
|
zacw@1759
|
262 |
{ \ |
|
zacw@1759
|
263 |
g_define_type_id = \ |
|
zacw@1759
|
264 |
g_type_register_static_simple (TYPE_PARENT, \ |
|
zacw@1759
|
265 |
g_intern_static_string (#TypeName), \ |
|
zacw@1759
|
266 |
sizeof (TypeName##Class), \ |
|
zacw@1759
|
267 |
(GClassInitFunc)type_name##_class_intern_init, \ |
|
zacw@1759
|
268 |
sizeof (TypeName), \ |
|
zacw@1759
|
269 |
(GInstanceInitFunc)type_name##_init, \ |
|
zacw@1759
|
270 |
(GTypeFlags) 0); \ |
|
zacw@1759
|
271 |
} \ |
|
zacw@1759
|
272 |
return g_define_type_id; \ |
|
zacw@1759
|
273 |
} /* closes type_name##_get_type() */ |
|
zacw@1759
|
274 |
|
|
zacw@1759
|
275 |
#endif |
|
zacw@1759
|
276 |
|
|
Evan@653
|
277 |
/* Safer ways to work with static buffers. When using non-static |
|
Evan@653
|
278 |
* buffers, either use g_strdup_* functions (preferred) or use |
|
Evan@653
|
279 |
* g_strlcpy/g_strlcpy directly. */ |
|
Evan@653
|
280 |
#define purple_strlcpy(dest, src) g_strlcpy(dest, src, sizeof(dest)) |
|
Evan@653
|
281 |
#define purple_strlcat(dest, src) g_strlcat(dest, src, sizeof(dest)) |
|
Evan@653
|
282 |
|
|
Evan@653
|
283 |
#define PURPLE_WEBSITE "http://pidgin.im/" |
|
Evan@653
|
284 |
#define PURPLE_DEVEL_WEBSITE "http://developer.pidgin.im/" |
|
Evan@653
|
285 |
|
|
Evan@653
|
286 |
|
|
Evan@653
|
287 |
/* INTERNAL FUNCTIONS */ |
|
Evan@653
|
288 |
|
|
Evan@653
|
289 |
#include "account.h" |
|
Evan@653
|
290 |
#include "connection.h" |
|
Evan@653
|
291 |
|
|
Evan@653
|
292 |
/* This is for the accounts code to notify the buddy icon code that |
|
Evan@653
|
293 |
* it's done loading. We may want to replace this with a signal. */ |
|
Evan@653
|
294 |
void |
|
Evan@653
|
295 |
_purple_buddy_icons_account_loaded_cb(void); |
|
Evan@653
|
296 |
|
|
Evan@653
|
297 |
/* This is for the buddy list to notify the buddy icon code that |
|
Evan@653
|
298 |
* it's done loading. We may want to replace this with a signal. */ |
|
Evan@653
|
299 |
void |
|
Evan@653
|
300 |
_purple_buddy_icons_blist_loaded_cb(void); |
|
Evan@653
|
301 |
|
|
Evan@653
|
302 |
/* This is for the purple_core_migrate() code to tell the buddy |
|
Evan@653
|
303 |
* icon subsystem about the old icons directory so it can |
|
Evan@653
|
304 |
* migrate any icons in use. */ |
|
Evan@653
|
305 |
void |
|
Evan@653
|
306 |
_purple_buddy_icon_set_old_icons_dir(const char *dirname); |
|
Evan@653
|
307 |
|
|
Evan@653
|
308 |
/** |
|
Evan@653
|
309 |
* Creates a connection to the specified account and either connects |
|
Evan@653
|
310 |
* or attempts to register a new account. If you are logging in, |
|
Evan@653
|
311 |
* the connection uses the current active status for this account. |
|
Evan@653
|
312 |
* So if you want to sign on as "away," for example, you need to |
|
Evan@653
|
313 |
* have called purple_account_set_status(account, "away"). |
|
Evan@653
|
314 |
* (And this will call purple_account_connect() automatically). |
|
Evan@653
|
315 |
* |
|
Evan@653
|
316 |
* @note This function should only be called by purple_account_connect() |
|
Evan@653
|
317 |
* in account.c. If you're trying to sign on an account, use that |
|
Evan@653
|
318 |
* function instead. |
|
Evan@653
|
319 |
* |
|
Evan@653
|
320 |
* @param account The account the connection should be connecting to. |
|
Evan@653
|
321 |
* @param regist Whether we are registering a new account or just |
|
Evan@653
|
322 |
* trying to do a normal signon. |
|
Evan@653
|
323 |
* @param password The password to use. |
|
Evan@653
|
324 |
*/ |
|
Evan@653
|
325 |
void _purple_connection_new(PurpleAccount *account, gboolean regist, |
|
Evan@653
|
326 |
const char *password); |
|
Evan@653
|
327 |
/** |
|
Evan@653
|
328 |
* Tries to unregister the account on the server. If the account is not |
|
Evan@653
|
329 |
* connected, also creates a new connection. |
|
Evan@653
|
330 |
* |
|
Evan@653
|
331 |
* @note This function should only be called by purple_account_unregister() |
|
Evan@653
|
332 |
* in account.c. |
|
Evan@653
|
333 |
* |
|
Evan@653
|
334 |
* @param account The account to unregister |
|
Evan@653
|
335 |
* @param password The password to use. |
|
Evan@653
|
336 |
* @param cb Optional callback to be called when unregistration is complete |
|
Evan@653
|
337 |
* @param user_data user data to pass to the callback |
|
Evan@653
|
338 |
*/ |
|
Evan@653
|
339 |
void _purple_connection_new_unregister(PurpleAccount *account, const char *password, |
|
Evan@653
|
340 |
PurpleAccountUnregistrationCb cb, void *user_data); |
|
Evan@653
|
341 |
/** |
|
Evan@653
|
342 |
* Disconnects and destroys a PurpleConnection. |
|
Evan@653
|
343 |
* |
|
Evan@653
|
344 |
* @note This function should only be called by purple_account_disconnect() |
|
Evan@653
|
345 |
* in account.c. If you're trying to sign off an account, use that |
|
Evan@653
|
346 |
* function instead. |
|
Evan@653
|
347 |
* |
|
Evan@653
|
348 |
* @param gc The purple connection to destroy. |
|
Evan@653
|
349 |
*/ |
|
Evan@653
|
350 |
void _purple_connection_destroy(PurpleConnection *gc); |
|
Evan@653
|
351 |
|
|
Evan@653
|
352 |
#endif /* _PURPLE_INTERNAL_H_ */ |