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