source: protocols/bee.h @ aa9f1ac

Last change on this file since aa9f1ac was d88c92a, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-12-06T00:03:49Z

First bits of CTCP support to contacts. (Try /CTCP VERSION on a Jabber
contact.)

  • Property mode set to 100644
File size: 8.4 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* Stuff to handle, save and search buddies                             */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#ifndef __BEE_H__
27#define __BEE_H__
28
29struct bee_ui_funcs;
30struct groupchat;
31
32typedef struct bee
33{
34        /* Settings. See set.h for how these work. The UI can add its
35           own settings here. */
36        struct set *set;
37       
38        GSList *users;  /* struct bee_user */
39        GSList *groups; /* struct bee_group */
40        struct account *accounts; /* TODO(wilmer): Use GSList here too? */
41       
42        /* Symbolic, to refer to the local user (who has no real bee_user
43           object). Not to be used by anything except so far imcb_chat_add/
44           remove_buddy(). */
45        struct bee_user *user;
46       
47        /* Fill in the callbacks for events you care about. */
48        const struct bee_ui_funcs *ui;
49       
50        /* And this one will be passed to every callback for any state the
51           UI may want to keep. */
52        void *ui_data;
53} bee_t;
54
55bee_t *bee_new();
56void bee_free( bee_t *b );
57
58/* TODO(wilmer): Kill at least the OPT_ flags that have an equivalent here. */
59typedef enum
60{
61        BEE_USER_ONLINE = 1,    /* Compatibility with old OPT_LOGGED_IN flag */
62        BEE_USER_AWAY = 4,      /* Compatibility with old OPT_AWAY flag */
63        BEE_USER_MOBILE = 8,    /* Compatibility with old OPT_MOBILE flag */
64        BEE_USER_LOCAL = 256,   /* Locally-added contacts (not in real contact list) */
65} bee_user_flags_t;
66
67typedef struct bee_user
68{
69        struct im_connection *ic;
70        char *handle;
71        char *fullname;
72        char *nick;
73        struct bee_group *group;
74
75        bee_user_flags_t flags;
76        char *status;     /* NULL means available, anything else is an away state. */
77        char *status_msg; /* Status and/or away message. */
78       
79        /* Set using imcb_buddy_times(). */
80        time_t login_time, idle_time;
81       
82        bee_t *bee;
83        void *ui_data;
84        void *data; /* Can be used by the IM module. */
85} bee_user_t;
86
87/* This one's mostly used so save space and make it easier (cheaper) to
88   compare groups of contacts, etc. */
89typedef struct bee_group
90{
91        char *key;  /* Lower case version of the name. */
92        char *name;
93} bee_group_t;
94
95typedef struct bee_ui_funcs
96{
97        void (*imc_connected)( struct im_connection *ic );
98        void (*imc_disconnected)( struct im_connection *ic );
99       
100        gboolean (*user_new)( bee_t *bee, struct bee_user *bu );
101        gboolean (*user_free)( bee_t *bee, struct bee_user *bu );
102        /* Set the fullname first, then call this one to notify the UI. */
103        gboolean (*user_fullname)( bee_t *bee, bee_user_t *bu );
104        gboolean (*user_nick_hint)( bee_t *bee, bee_user_t *bu, const char *hint );
105        /* Notify the UI when an existing user is moved between groups. */
106        gboolean (*user_group)( bee_t *bee, bee_user_t *bu );
107        /* State info is already updated, old is provided in case the UI needs a diff. */
108        gboolean (*user_status)( bee_t *bee, struct bee_user *bu, struct bee_user *old );
109        /* On every incoming message. sent_at = 0 means unknown. */
110        gboolean (*user_msg)( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at );
111        /* Flags currently defined (OPT_TYPING/THINKING) in nogaim.h. */
112        gboolean (*user_typing)( bee_t *bee, bee_user_t *bu, guint32 flags );
113        /* CTCP-like stuff (buddy action) response */
114        gboolean (*user_action_response)( bee_t *bee, bee_user_t *bu, const char *action, char * const args[], void *data );
115       
116        /* Called at creation time. Don't show to the user until s/he is
117           added using chat_add_user().  UI state can be stored via c->data. */
118        gboolean (*chat_new)( bee_t *bee, struct groupchat *c );
119        gboolean (*chat_free)( bee_t *bee, struct groupchat *c );
120        /* System messages of any kind. */
121        gboolean (*chat_log)( bee_t *bee, struct groupchat *c, const char *text );
122        gboolean (*chat_msg)( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at );
123        gboolean (*chat_add_user)( bee_t *bee, struct groupchat *c, bee_user_t *bu );
124        gboolean (*chat_remove_user)( bee_t *bee, struct groupchat *c, bee_user_t *bu );
125        gboolean (*chat_topic)( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu );
126        gboolean (*chat_name_hint)( bee_t *bee, struct groupchat *c, const char *name );
127        gboolean (*chat_invite)( bee_t *bee, bee_user_t *bu, const char *name, const char *msg );
128       
129        struct file_transfer* (*ft_in_start)( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size );
130        gboolean (*ft_out_start)( struct im_connection *ic, struct file_transfer *ft );
131        void (*ft_close)( struct im_connection *ic, struct file_transfer *ft );
132        void (*ft_finished)( struct im_connection *ic, struct file_transfer *ft );
133} bee_ui_funcs_t;
134
135
136/* bee.c */
137bee_t *bee_new();
138void bee_free( bee_t *b );
139
140/* bee_user.c */
141bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle, bee_user_flags_t flags );
142int bee_user_free( bee_t *bee, bee_user_t *bu );
143bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle );
144int bee_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, int flags );
145bee_group_t *bee_group_by_name( bee_t *bee, const char *name, gboolean creat );
146void bee_group_free( bee_t *bee );
147
148/* Callbacks from IM modules to core: */
149/* Buddy activity */
150/* To manipulate the status of a handle.
151 * - flags can be |='d with OPT_* constants. You will need at least:
152 *   OPT_LOGGED_IN and OPT_AWAY.
153 * - 'state' and 'message' can be NULL */
154G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message );
155G_MODULE_EXPORT void imcb_buddy_status_msg( struct im_connection *ic, const char *handle, const char *message );
156G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle );
157/* Call when a handle says something. 'flags' and 'sent_at may be just 0. */
158G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, guint32 flags, time_t sent_at );
159
160/* bee_chat.c */
161/* These two functions are to create a group chat.
162 * - imcb_chat_new(): the 'handle' parameter identifies the chat, like the
163 *   channel name on IRC.
164 * - After you have a groupchat pointer, you should add the handles, finally 
165 *   the user her/himself. At that point the group chat will be visible to the
166 *   user, too. */
167G_MODULE_EXPORT struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle );
168G_MODULE_EXPORT void imcb_chat_name_hint( struct groupchat *c, const char *name );
169G_MODULE_EXPORT void imcb_chat_free( struct groupchat *c );
170/* To tell BitlBee 'who' said 'msg' in 'c'. 'flags' and 'sent_at' can be 0. */
171G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, guint32 flags, time_t sent_at );
172/* System messages specific to a groupchat, so they can be displayed in the right context. */
173G_MODULE_EXPORT void imcb_chat_log( struct groupchat *c, char *format, ... );
174/* To tell BitlBee 'who' changed the topic of 'c' to 'topic'. */
175G_MODULE_EXPORT void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at );
176G_MODULE_EXPORT void imcb_chat_add_buddy( struct groupchat *c, const char *handle );
177/* To remove a handle from a group chat. Reason can be NULL. */
178G_MODULE_EXPORT void imcb_chat_remove_buddy( struct groupchat *c, const char *handle, const char *reason );
179G_MODULE_EXPORT int bee_chat_msg( bee_t *bee, struct groupchat *c, const char *msg, int flags );
180G_MODULE_EXPORT struct groupchat *bee_chat_by_title( bee_t *bee, struct im_connection *ic, const char *title );
181G_MODULE_EXPORT void imcb_chat_invite( struct im_connection *ic, const char *name, const char *who, const char *msg );
182
183#endif /* __BEE_H__ */
Note: See TracBrowser for help on using the repository browser.