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