[10a96f4] | 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 | |
---|
| 29 | struct bee_ui_funcs; |
---|
[aea8b68] | 30 | struct groupchat; |
---|
[ebaebfe] | 31 | |
---|
| 32 | typedef struct bee |
---|
| 33 | { |
---|
[f6f5eee] | 34 | /* Settings. See set.h for how these work. The UI can add its |
---|
| 35 | own settings here. */ |
---|
[ebaebfe] | 36 | struct set *set; |
---|
| 37 | |
---|
[f6f5eee] | 38 | GSList *users; /* struct bee_user */ |
---|
| 39 | GSList *groups; /* struct bee_group */ |
---|
[81e04e1] | 40 | struct account *accounts; /* TODO(wilmer): Use GSList here too? */ |
---|
[ebaebfe] | 41 | |
---|
[aea8b68] | 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/ |
---|
[f6f5eee] | 44 | remove_buddy(). */ |
---|
[aea8b68] | 45 | struct bee_user *user; |
---|
| 46 | |
---|
[f6f5eee] | 47 | /* Fill in the callbacks for events you care about. */ |
---|
[10a96f4] | 48 | const struct bee_ui_funcs *ui; |
---|
[f6f5eee] | 49 | |
---|
| 50 | /* And this one will be passed to every callback for any state the |
---|
| 51 | UI may want to keep. */ |
---|
[ebaebfe] | 52 | void *ui_data; |
---|
| 53 | } bee_t; |
---|
| 54 | |
---|
| 55 | bee_t *bee_new(); |
---|
| 56 | void bee_free( bee_t *b ); |
---|
[10a96f4] | 57 | |
---|
| 58 | typedef enum |
---|
| 59 | { |
---|
[e63507a] | 60 | BEE_USER_ONLINE = 1, /* Compatibility with old OPT_LOGGED_IN flag */ |
---|
| 61 | BEE_USER_AWAY = 4, /* Compatibility with old OPT_AWAY flag */ |
---|
[ad404ab] | 62 | BEE_USER_LOCAL = 256, /* Locally-added contacts (not in real contact list) */ |
---|
[10a96f4] | 63 | } bee_user_flags_t; |
---|
| 64 | |
---|
| 65 | typedef struct bee_user |
---|
| 66 | { |
---|
| 67 | struct im_connection *ic; |
---|
| 68 | char *handle; |
---|
| 69 | char *fullname; |
---|
[69b896b] | 70 | char *nick; |
---|
[7aadd71] | 71 | struct bee_group *group; |
---|
[10a96f4] | 72 | |
---|
[81e04e1] | 73 | bee_user_flags_t flags; |
---|
[f6f5eee] | 74 | char *status; /* NULL means available, anything else is an away state. */ |
---|
| 75 | char *status_msg; /* Status and/or away message. */ |
---|
[10a96f4] | 76 | |
---|
[f6f5eee] | 77 | /* Set using imcb_buddy_times(). */ |
---|
[56699f0] | 78 | time_t login_time, idle_time; |
---|
| 79 | |
---|
[10a96f4] | 80 | bee_t *bee; |
---|
| 81 | void *ui_data; |
---|
[203a2d2] | 82 | void *data; /* Can be used by the IM module. */ |
---|
[10a96f4] | 83 | } bee_user_t; |
---|
| 84 | |
---|
[f6f5eee] | 85 | /* This one's mostly used so save space and make it easier (cheaper) to |
---|
| 86 | compare groups of contacts, etc. */ |
---|
[7aadd71] | 87 | typedef struct bee_group |
---|
| 88 | { |
---|
[f6f5eee] | 89 | char *key; /* Lower case version of the name. */ |
---|
[7aadd71] | 90 | char *name; |
---|
| 91 | } bee_group_t; |
---|
| 92 | |
---|
[10a96f4] | 93 | typedef struct bee_ui_funcs |
---|
| 94 | { |
---|
[5c7b45c] | 95 | void (*imc_connected)( struct im_connection *ic ); |
---|
| 96 | void (*imc_disconnected)( struct im_connection *ic ); |
---|
| 97 | |
---|
[10a96f4] | 98 | gboolean (*user_new)( bee_t *bee, struct bee_user *bu ); |
---|
| 99 | gboolean (*user_free)( bee_t *bee, struct bee_user *bu ); |
---|
[f6f5eee] | 100 | /* Set the fullname first, then call this one to notify the UI. */ |
---|
[1d39159] | 101 | gboolean (*user_fullname)( bee_t *bee, bee_user_t *bu ); |
---|
[6ef9065] | 102 | gboolean (*user_nick_hint)( bee_t *bee, bee_user_t *bu, const char *hint ); |
---|
[f6f5eee] | 103 | /* Notify the UI when an existing user is moved between groups. */ |
---|
[7e83e8e4] | 104 | gboolean (*user_group)( bee_t *bee, bee_user_t *bu ); |
---|
[f6f5eee] | 105 | /* State info is already updated, old is provided in case the UI needs a diff. */ |
---|
[81e04e1] | 106 | gboolean (*user_status)( bee_t *bee, struct bee_user *bu, struct bee_user *old ); |
---|
[f6f5eee] | 107 | /* On every incoming message. sent_at = 0 means unknown. */ |
---|
[f012a9f] | 108 | gboolean (*user_msg)( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at ); |
---|
[f6f5eee] | 109 | /* Flags currently defined (OPT_TYPING/THINKING) in nogaim.h. */ |
---|
[573dab0] | 110 | gboolean (*user_typing)( bee_t *bee, bee_user_t *bu, guint32 flags ); |
---|
[17a6ee9] | 111 | |
---|
[f6f5eee] | 112 | /* Called at creation time. Don't show to the user until s/he is |
---|
| 113 | added using chat_add_user(). UI state can be stored via c->data. */ |
---|
[aea8b68] | 114 | gboolean (*chat_new)( bee_t *bee, struct groupchat *c ); |
---|
| 115 | gboolean (*chat_free)( bee_t *bee, struct groupchat *c ); |
---|
[f6f5eee] | 116 | /* System messages of any kind. */ |
---|
[27e2c66] | 117 | gboolean (*chat_log)( bee_t *bee, struct groupchat *c, const char *text ); |
---|
| 118 | gboolean (*chat_msg)( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at ); |
---|
[aea8b68] | 119 | gboolean (*chat_add_user)( bee_t *bee, struct groupchat *c, bee_user_t *bu ); |
---|
| 120 | gboolean (*chat_remove_user)( bee_t *bee, struct groupchat *c, bee_user_t *bu ); |
---|
[9e27f18] | 121 | gboolean (*chat_topic)( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu ); |
---|
[d343eaa] | 122 | gboolean (*chat_name_hint)( bee_t *bee, struct groupchat *c, const char *name ); |
---|
[aea8b68] | 123 | |
---|
[17a6ee9] | 124 | struct file_transfer* (*ft_in_start)( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size ); |
---|
| 125 | gboolean (*ft_out_start)( struct im_connection *ic, struct file_transfer *ft ); |
---|
| 126 | void (*ft_close)( struct im_connection *ic, struct file_transfer *ft ); |
---|
| 127 | void (*ft_finished)( struct im_connection *ic, struct file_transfer *ft ); |
---|
[10a96f4] | 128 | } bee_ui_funcs_t; |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /* bee.c */ |
---|
| 132 | bee_t *bee_new(); |
---|
| 133 | void bee_free( bee_t *b ); |
---|
| 134 | |
---|
| 135 | /* bee_user.c */ |
---|
[ad404ab] | 136 | bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle, bee_user_flags_t flags ); |
---|
[eabc9d2] | 137 | int bee_user_free( bee_t *bee, bee_user_t *bu ); |
---|
[10a96f4] | 138 | bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle ); |
---|
[d860a8d] | 139 | int bee_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, int flags ); |
---|
[7aadd71] | 140 | bee_group_t *bee_group_by_name( bee_t *bee, const char *name, gboolean creat ); |
---|
| 141 | void bee_group_free( bee_t *bee ); |
---|
[d860a8d] | 142 | |
---|
| 143 | /* Callbacks from IM modules to core: */ |
---|
| 144 | /* Buddy activity */ |
---|
| 145 | /* To manipulate the status of a handle. |
---|
| 146 | * - flags can be |='d with OPT_* constants. You will need at least: |
---|
| 147 | * OPT_LOGGED_IN and OPT_AWAY. |
---|
| 148 | * - 'state' and 'message' can be NULL */ |
---|
| 149 | G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ); |
---|
[d93c0eb9] | 150 | G_MODULE_EXPORT void imcb_buddy_status_msg( struct im_connection *ic, const char *handle, const char *message ); |
---|
[56699f0] | 151 | G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle ); |
---|
[d860a8d] | 152 | /* Call when a handle says something. 'flags' and 'sent_at may be just 0. */ |
---|
[fb117aee] | 153 | G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, guint32 flags, time_t sent_at ); |
---|
[10a96f4] | 154 | |
---|
[aea8b68] | 155 | /* bee_chat.c */ |
---|
[f6f5eee] | 156 | /* These two functions are to create a group chat. |
---|
| 157 | * - imcb_chat_new(): the 'handle' parameter identifies the chat, like the |
---|
| 158 | * channel name on IRC. |
---|
| 159 | * - After you have a groupchat pointer, you should add the handles, finally |
---|
| 160 | * the user her/himself. At that point the group chat will be visible to the |
---|
| 161 | * user, too. */ |
---|
| 162 | G_MODULE_EXPORT struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ); |
---|
| 163 | G_MODULE_EXPORT void imcb_chat_name_hint( struct groupchat *c, const char *name ); |
---|
| 164 | G_MODULE_EXPORT void imcb_chat_free( struct groupchat *c ); |
---|
| 165 | /* To tell BitlBee 'who' said 'msg' in 'c'. 'flags' and 'sent_at' can be 0. */ |
---|
| 166 | G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, guint32 flags, time_t sent_at ); |
---|
| 167 | /* System messages specific to a groupchat, so they can be displayed in the right context. */ |
---|
| 168 | G_MODULE_EXPORT void imcb_chat_log( struct groupchat *c, char *format, ... ); |
---|
| 169 | /* To tell BitlBee 'who' changed the topic of 'c' to 'topic'. */ |
---|
| 170 | G_MODULE_EXPORT void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ); |
---|
| 171 | G_MODULE_EXPORT void imcb_chat_add_buddy( struct groupchat *c, const char *handle ); |
---|
| 172 | /* To remove a handle from a group chat. Reason can be NULL. */ |
---|
| 173 | G_MODULE_EXPORT void imcb_chat_remove_buddy( struct groupchat *c, const char *handle, const char *reason ); |
---|
| 174 | G_MODULE_EXPORT int bee_chat_msg( bee_t *bee, struct groupchat *c, const char *msg, int flags ); |
---|
| 175 | G_MODULE_EXPORT struct groupchat *bee_chat_by_title( bee_t *bee, struct im_connection *ic, const char *title ); |
---|
[aea8b68] | 176 | |
---|
[10a96f4] | 177 | #endif /* __BEE_H__ */ |
---|