* Move to GPL v3
[citadel.git] / gaim-citadel / gaim.pkg
1 /* gaim.pkg
2  * Gaim Citadel plugin.
3  *
4  * © 2006 David Given.
5  * This code is licensed under the GPL v3. See the file COPYING in this
6  * directory for the full license text.
7  *
8  * $Id:gaim.pkg 4326 2006-02-18 12:26:22Z hjalfi $
9  */
10
11 typedef unsigned int size_t;
12 typedef bool gboolean;
13 typedef long time_t;
14 typedef void* GCallback;
15
16 $typedef int bool;
17 $#include "connection.h"
18 $#include "sslconn.h"
19 $#include "account.h"
20 $#include "conversation.h"
21 $#include "server.h"
22 $#include "notify.h"
23 $#include "util.h"
24 $#include "debug.h"
25
26 $#include "interface.h"
27
28 /* Private entrypoints */
29
30 char* interface_readdata(int fd, GaimSslConnection* gsc);
31 int interface_writedata(int fd, GaimSslConnection* gsc, char* data);
32 int interface_connect(GaimAccount* ga, GaimConnection* gc, char* server, int port);
33 void interface_disconnect(int fd, GaimSslConnection* gsc);
34 void interface_tlson(GaimConnection* gc, GaimAccount* ga, int fd);
35 int interface_timeron(GaimConnection* gc, time_t timeout);
36 void interface_timeroff(GaimConnection* gc, int handle);
37         
38 /* --- connection.h ------------------------------------------------------ */
39
40 typedef enum
41 {
42         GAIM_CONNECTION_HTML       = 0x0001, /**< Connection sends/receives in 'HTML'. */
43         GAIM_CONNECTION_NO_BGCOLOR = 0x0002, /**< Connection does not send/receive
44                                                    background colors.                  */
45         GAIM_CONNECTION_AUTO_RESP  = 0x0004,  /**< Send auto responses when away.       */
46         GAIM_CONNECTION_FORMATTING_WBFO = 0x0008, /**< The text buffer must be formatted as a whole */
47         GAIM_CONNECTION_NO_NEWLINES = 0x0010, /**< No new lines are allowed in outgoing messages */
48         GAIM_CONNECTION_NO_FONTSIZE = 0x0020, /**< Connection does not send/receive font sizes */
49         GAIM_CONNECTION_NO_URLDESC = 0x0040,  /**< Connection does not support descriptions with links */
50         GAIM_CONNECTION_NO_IMAGES = 0x0080  /**< Connection does not support sending of images */
51 } GaimConnectionFlags;
52
53 typedef enum
54 {
55         GAIM_DISCONNECTED = 0, /**< Disconnected. */
56         GAIM_CONNECTED,        /**< Connected.    */
57         GAIM_CONNECTING        /**< Connecting.   */
58
59 } GaimConnectionState;
60
61 void gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state);
62 void gaim_connection_set_account(GaimConnection *gc, GaimAccount *account);
63 void gaim_connection_set_display_name(GaimConnection *gc, char *name);
64 GaimConnectionState gaim_connection_get_state(GaimConnection *gc);
65 GaimAccount *gaim_connection_get_account(GaimConnection *gc);
66 char *gaim_connection_get_display_name(GaimConnection *gc);
67 void gaim_connection_update_progress(GaimConnection *gc, char *text,
68                                                                          size_t step, size_t count);
69 void gaim_connection_notice(GaimConnection *gc, char *text);
70 void gaim_connection_error(GaimConnection *gc, char *reason);
71
72 /* --- account.h --------------------------------------------------------- */
73
74 void gaim_account_request_change_password(GaimAccount *account);
75 void gaim_account_request_change_user_info(GaimAccount *account);
76 void gaim_account_set_username(GaimAccount *account, char *username);
77 void gaim_account_set_password(GaimAccount *account, char *password);
78 void gaim_account_set_alias(GaimAccount *account, char *alias);
79 void gaim_account_set_user_info(GaimAccount *account, char *user_info);
80 void gaim_account_set_buddy_icon(GaimAccount *account, char *icon);
81 void gaim_account_set_protocol_id(GaimAccount *account,
82                                                                   char *protocol_id);
83 void gaim_account_set_remember_password(GaimAccount *account, gboolean value);
84 void gaim_account_set_check_mail(GaimAccount *account, gboolean value);
85 void gaim_account_set_auto_login(GaimAccount *account, char *ui,
86                                                                  gboolean value);
87 void gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info);
88 void gaim_account_clear_settings(GaimAccount *account);
89 void gaim_account_set_int(GaimAccount *account, char *name, int value);
90 void gaim_account_set_string(GaimAccount *account, char *name,
91                                                          char *value);
92 void gaim_account_set_bool(GaimAccount *account, char *name,
93                                                    gboolean value);
94 void gaim_account_set_ui_int(GaimAccount *account, char *ui,
95                                                          char *name, int value);
96 void gaim_account_set_ui_string(GaimAccount *account, char *ui,
97                                                                 char *name, char *value);
98 void gaim_account_set_ui_bool(GaimAccount *account, char *ui,
99                                                           char *name, gboolean value);
100 gboolean gaim_account_is_connected(GaimAccount *account);
101 char *gaim_account_get_username(GaimAccount *account);
102 char *gaim_account_get_password(GaimAccount *account);
103 char *gaim_account_get_alias(GaimAccount *account);
104 char *gaim_account_get_user_info(GaimAccount *account);
105 char *gaim_account_get_buddy_icon(GaimAccount *account);
106 char *gaim_account_get_protocol_id(GaimAccount *account);
107 char *gaim_account_get_protocol_name(GaimAccount *account);
108 GaimConnection *gaim_account_get_connection(GaimAccount *account);
109 gboolean gaim_account_get_remember_password(GaimAccount *account);
110 gboolean gaim_account_get_check_mail(GaimAccount *account);
111 gboolean gaim_account_get_auto_login(GaimAccount *account, char *ui);
112 int gaim_account_get_int(GaimAccount *account, char *name, int default_value);
113 char *gaim_account_get_string(GaimAccount *account, char *name, char *default_value);
114 gboolean gaim_account_get_bool(GaimAccount *account, char *name, gboolean default_value);
115 int gaim_account_get_ui_int(GaimAccount *account, char *ui, char *name, int default_value);
116 char *gaim_account_get_ui_string(GaimAccount *account, char *ui, char *name, char *default_value);
117 gboolean gaim_account_get_ui_bool(GaimAccount *account, char *ui, char *name, gboolean default_value);
118
119 /* --- server.h ---------------------------------------------------------- */
120
121 void serv_login(GaimAccount *);
122 void serv_close(GaimConnection *);
123 void serv_touch_idle(GaimConnection *);
124 int  serv_send_im(GaimConnection *, const char *, const char *, GaimConvImFlags);
125 void serv_get_info(GaimConnection *, const char *);
126 void serv_set_idle(GaimConnection *, int);
127 void serv_set_info(GaimConnection *, const char *);
128 void serv_set_away(GaimConnection *, const char *, const char *);
129 void serv_set_away_all(const char *);
130 int  serv_send_typing(GaimConnection *, const char *, int);
131 void serv_change_passwd(GaimConnection *, const char *, const char *);
132 void serv_add_buddy(GaimConnection *, GaimBuddy *);
133 void serv_add_buddies(GaimConnection *, GList *);
134 void serv_remove_buddy(GaimConnection *, GaimBuddy *, GaimGroup *);
135 void serv_remove_buddies(GaimConnection *, GList *, GList *);
136 void serv_remove_group(GaimConnection *, GaimGroup *);
137 void serv_move_buddy(GaimBuddy *, GaimGroup *, GaimGroup *);
138 void serv_rename_group(GaimConnection *, const char *, GaimGroup *, GList *);
139 void serv_add_permit(GaimConnection *, const char *);
140 void serv_add_deny(GaimConnection *, const char *);
141 void serv_rem_permit(GaimConnection *, const char *);
142 void serv_rem_deny(GaimConnection *, const char *);
143 void serv_set_permit_deny(GaimConnection *);
144 void serv_warn(GaimConnection *, const char *, gboolean);
145 void serv_join_chat(GaimConnection *, GHashTable *);
146 void serv_reject_chat(GaimConnection *, GHashTable *);
147 void serv_chat_invite(GaimConnection *, int, const char *, const char *);
148 void serv_chat_leave(GaimConnection *, int);
149 void serv_chat_whisper(GaimConnection *, int, const char *, const char *);
150 int  serv_chat_send(GaimConnection *, int, const char *);
151 void serv_alias_buddy(GaimBuddy *);
152 void serv_got_alias(GaimConnection *gc, const char *who, const char *alias);
153 void serv_got_eviled(GaimConnection *gc, const char *name, int lev);
154 void serv_got_typing(GaimConnection *gc, const char *name, int timeout,
155                                          GaimTypingState state);
156 void serv_set_buddyicon(GaimConnection *gc, const char *filename);
157 void serv_got_typing_stopped(GaimConnection *gc, const char *name);
158 void serv_got_im(GaimConnection *gc, const char *who, const char *msg,
159                                  GaimConvImFlags imflags, time_t mtime);
160 void serv_got_update(GaimConnection *gc, const char *name, gboolean loggedin,
161                                          int evil, time_t signon, time_t idle, int type);
162 void serv_finish_login(GaimConnection *gc);
163 void serv_got_chat_invite(GaimConnection *gc, const char *name,
164                                                   const char *who, const char *message,
165                                                   GHashTable *data);
166 GaimConversation *serv_got_joined_chat(GaimConnection *gc,
167                                                                            int id, const char *name);
168 void serv_got_chat_left(GaimConnection *g, int id);
169 void serv_got_chat_in(GaimConnection *g, int id, const char *who,
170                                           GaimConvChatFlags chatflags, const char *message, time_t mtime);
171 void serv_send_file(GaimConnection *gc, const char *who, const char *file);
172
173 /* --- conversation.h ---------------------------------------------------- */
174
175 typedef enum
176 {
177         GAIM_CONV_UNKNOWN = 0, /**< Unknown conversation type. */
178         GAIM_CONV_IM,          /**< Instant Message.           */
179         GAIM_CONV_CHAT,        /**< Chat room.                 */
180         GAIM_CONV_MISC         /**< A misc. conversation.      */
181
182 } GaimConversationType;
183
184 typedef enum
185 {
186         GAIM_UNSEEN_NONE = 0,  /**< No unseen text in the conversation. */
187         GAIM_UNSEEN_TEXT,      /**< Unseen text in the conversation.    */
188         GAIM_UNSEEN_NICK,      /**< Unseen text and the nick was said.  */
189         GAIM_UNSEEN_EVENT      /**< Unseen events in the conversation.  */
190
191 } GaimUnseenState;
192
193 typedef enum
194 {
195         GAIM_CONV_UPDATE_ADD = 0, /**< The buddy associated with the conversation
196                                        was added.   */
197         GAIM_CONV_UPDATE_REMOVE,  /**< The buddy associated with the conversation
198                                        was removed. */
199         GAIM_CONV_UPDATE_ACCOUNT, /**< The gaim_account was changed. */
200         GAIM_CONV_UPDATE_TYPING,  /**< The typing state was updated. */
201         GAIM_CONV_UPDATE_UNSEEN,  /**< The unseen state was updated. */
202         GAIM_CONV_UPDATE_LOGGING, /**< Logging for this conversation was
203                                        enabled or disabled. */
204         GAIM_CONV_UPDATE_TOPIC,   /**< The topic for a chat was updated. */
205         /*
206          * XXX These need to go when we implement a more generic core/UI event
207          * system.
208          */
209         GAIM_CONV_ACCOUNT_ONLINE,  /**< One of the user's accounts went online.  */
210         GAIM_CONV_ACCOUNT_OFFLINE, /**< One of the user's accounts went offline. */
211         GAIM_CONV_UPDATE_AWAY,     /**< The other user went away.                */
212         GAIM_CONV_UPDATE_ICON,     /**< The other user's buddy icon changed.     */
213         GAIM_CONV_UPDATE_TITLE,
214         GAIM_CONV_UPDATE_CHATLEFT,
215
216         GAIM_CONV_UPDATE_FEATURES /**< The features for a chat have changed */
217
218 } GaimConvUpdateType;
219
220 typedef enum
221 {
222         GAIM_NOT_TYPING = 0,  /**< Not typing.                 */
223         GAIM_TYPING,          /**< Currently typing.           */
224         GAIM_TYPED            /**< Stopped typing momentarily. */
225
226 } GaimTypingState;
227
228 typedef enum
229 {
230         GAIM_MESSAGE_SEND      = 0x0001, /**< Outgoing message.        */
231         GAIM_MESSAGE_RECV      = 0x0002, /**< Incoming message.        */
232         GAIM_MESSAGE_SYSTEM    = 0x0004, /**< System message.          */
233         GAIM_MESSAGE_AUTO_RESP = 0x0008, /**< Auto response.           */
234         GAIM_MESSAGE_COLORIZE  = 0x0010, /**< Colorize nicks.          */
235         GAIM_MESSAGE_NICK      = 0x0020, /**< Contains your nick.      */
236         GAIM_MESSAGE_NO_LOG    = 0x0040, /**< Do not log.              */
237         GAIM_MESSAGE_WHISPER   = 0x0080, /**< Whispered message.       */
238         GAIM_MESSAGE_ERROR     = 0x0200, /**< Error message.           */
239         GAIM_MESSAGE_DELAYED   = 0x0400  /**< Delayed message.         */
240 } GaimMessageFlags;
241
242 typedef enum
243 {
244         GAIM_CBFLAGS_NONE          = 0x0000, /**< No flags                     */
245         GAIM_CBFLAGS_VOICE         = 0x0001, /**< Voiced user or "Participant" */
246         GAIM_CBFLAGS_HALFOP        = 0x0002, /**< Half-op                      */
247         GAIM_CBFLAGS_OP            = 0x0004, /**< Channel Op or Moderator      */
248         GAIM_CBFLAGS_FOUNDER       = 0x0008  /**< Channel Founder              */
249 } GaimConvChatBuddyFlags;
250
251 /* --- prpl.h ------------------------------------------------------------ */
252
253 typedef enum
254 {
255         GAIM_CONV_IM_AUTO_RESP = 0x0001,    /**< Auto response.    */
256         GAIM_CONV_IM_IMAGES    = 0x0002     /**< Contains images.  */
257 } GaimConvImFlags;
258
259 typedef enum
260 {
261         GAIM_CONV_CHAT_WHISPER = 0x0001,    /**< Whispered message.*/
262         GAIM_CONV_CHAT_DELAYED = 0x0002     /**< Delayed message.  */
263
264 } GaimConvChatFlags;
265
266 typedef enum {
267         GAIM_ICON_SCALE_DISPLAY = 0x01,         /**< We scale the icon when we display it */
268         GAIM_ICON_SCALE_SEND = 0x02                     /**< We scale the icon before we send it to the server */
269 } GaimIconScaleRules;
270
271 /* --- blist.h ----------------------------------------------------------- */
272
273 typedef enum
274 {
275         GAIM_BLIST_GROUP_NODE,
276         GAIM_BLIST_CONTACT_NODE,
277         GAIM_BLIST_BUDDY_NODE,
278         GAIM_BLIST_CHAT_NODE,
279         GAIM_BLIST_OTHER_NODE
280
281 } GaimBlistNodeType;
282
283 typedef enum
284 {
285         GAIM_BUDDY_SIGNING_OFF = -1,
286         GAIM_BUDDY_OFFLINE = 0,
287         GAIM_BUDDY_ONLINE,
288         GAIM_BUDDY_SIGNING_ON
289
290 } GaimBuddyPresenceState;
291
292 GaimGroup *gaim_group_new(const char *name);
293 GaimGroup *gaim_find_group(const char *name);
294 GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy);
295 GaimBuddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias);
296 const char *gaim_group_get_name(GaimGroup *group); // fake --- added by plugin
297 const char *gaim_buddy_get_alias_only(GaimBuddy *buddy);
298 const char *gaim_buddy_get_contact_alias(GaimBuddy *buddy);
299 const char *gaim_buddy_get_alias(GaimBuddy *buddy);
300 GaimBuddy *gaim_find_buddy(GaimAccount *account, const char *name);
301 void gaim_blist_add_buddy(GaimBuddy *buddy, GaimContact *contact, GaimGroup *group, GaimBlistNode *node);
302 void gaim_blist_add_group(GaimGroup* group, GaimBlistNode* node);
303
304 /* --- notify.h ---------------------------------------------------------- */
305
306 typedef enum
307 {
308         GAIM_NOTIFY_MESSAGE = 0, /**< Message notification.         */
309         GAIM_NOTIFY_EMAIL,       /**< Single e-mail notification.   */
310         GAIM_NOTIFY_EMAILS,      /**< Multiple e-mail notification. */
311         GAIM_NOTIFY_FORMATTED,   /**< Formatted text.               */
312         GAIM_NOTIFY_USERINFO,    /**< Formatted userinfo text.      */
313         GAIM_NOTIFY_URI          /**< URI notification or display.  */
314
315 } GaimNotifyType;
316
317 typedef enum
318 {
319         GAIM_NOTIFY_MSG_ERROR   = 0, /**< Error notification.       */
320         GAIM_NOTIFY_MSG_WARNING,     /**< Warning notification.     */
321         GAIM_NOTIFY_MSG_INFO         /**< Information notification. */
322
323 } GaimNotifyMsgType;
324
325 void *gaim_notify_message(void *handle, GaimNotifyMsgType type,
326                                                   const char *title, const char *primary,
327                                                   const char *secondary, GCallback cb,
328                                                   void *user_data);
329 void *gaim_notify_email(void *handle, const char *subject,
330                                                 const char *from, const char *to,
331                                                 const char *url, GCallback cb,
332                                                 void *user_data);
333 void *gaim_notify_emails(void *handle, size_t count, gboolean detailed,
334                                                  const char **subjects, const char **froms,
335                                                  const char **tos, const char **urls,
336                                                  GCallback cb, void *user_data);
337 void *gaim_notify_formatted(void *handle, const char *title,
338                                                         const char *primary, const char *secondary,
339                                                         const char *text, GCallback cb, void *user_data);
340 void *gaim_notify_userinfo(GaimConnection *gc, const char *who,
341                                                    const char *title, const char *primary,
342                                                    const char *secondary, const char *text,
343                                                    GCallback cb, void *user_data);
344 void *gaim_notify_uri(void *handle, const char *uri);
345
346 /* --- util.h ------------------------------------------------------------ */
347
348 void gaim_quotedp_decode (const char *str, char **ret_str, int *ret_len);
349 char *gaim_mime_decode_field (const char *str);
350 const char *gaim_date(void);
351 const char *gaim_date_full(void);
352 time_t gaim_time_build(int year, int month, int day, int hour, int min, int sec);
353 time_t gaim_str_to_time(const char *timestamp, gboolean utc);
354
355 const gchar *gaim_home_dir(void);
356 char *gaim_user_dir(void);
357 void set_gaim_user_dir(const char *dir);
358 int gaim_build_dir(const char *path, int mode);
359 gboolean gaim_program_is_valid(const char *program);
360
361 const char *gaim_normalize(const GaimAccount *account, const char *str);
362 const char *gaim_normalize_nocase(const GaimAccount *account, const char *str);
363
364 /* --- debug.h ----------------------------------------------------------- */
365
366 typedef enum
367 {
368         GAIM_DEBUG_ALL = 0,  /**< All debug levels.              */
369         GAIM_DEBUG_MISC,     /**< General chatter.               */
370         GAIM_DEBUG_INFO,     /**< General operation Information. */
371         GAIM_DEBUG_WARNING,  /**< Warnings.                      */
372         GAIM_DEBUG_ERROR,    /**< Errors.                        */
373         GAIM_DEBUG_FATAL     /**< Fatal errors.                  */
374
375 } GaimDebugLevel;
376
377 void gaim_debug(GaimDebugLevel level, const char *category,
378                                 const char *format);
379 void gaim_debug_misc(const char *category, const char *format);
380 void gaim_debug_info(const char *category, const char *format);
381 void gaim_debug_warning(const char *category, const char *format);
382 void gaim_debug_error(const char *category, const char *format);
383 void gaim_debug_fatal(const char *category, const char *format);
384