[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 | { |
---|
| 34 | struct set *set; |
---|
| 35 | |
---|
| 36 | GSList *users; |
---|
[7aadd71] | 37 | GSList *groups; |
---|
[81e04e1] | 38 | struct account *accounts; /* TODO(wilmer): Use GSList here too? */ |
---|
[ebaebfe] | 39 | |
---|
[aea8b68] | 40 | /* Symbolic, to refer to the local user (who has no real bee_user |
---|
| 41 | object). Not to be used by anything except so far imcb_chat_add/ |
---|
| 42 | remove_buddy(). This seems slightly cleaner than abusing NULL. */ |
---|
| 43 | struct bee_user *user; |
---|
| 44 | |
---|
[10a96f4] | 45 | const struct bee_ui_funcs *ui; |
---|
[ebaebfe] | 46 | void *ui_data; |
---|
| 47 | } bee_t; |
---|
| 48 | |
---|
| 49 | bee_t *bee_new(); |
---|
| 50 | void bee_free( bee_t *b ); |
---|
[10a96f4] | 51 | |
---|
| 52 | typedef enum |
---|
| 53 | { |
---|
[e63507a] | 54 | BEE_USER_ONLINE = 1, /* Compatibility with old OPT_LOGGED_IN flag */ |
---|
| 55 | BEE_USER_AWAY = 4, /* Compatibility with old OPT_AWAY flag */ |
---|
[ad404ab] | 56 | BEE_USER_LOCAL = 256, /* Locally-added contacts (not in real contact list) */ |
---|
[10a96f4] | 57 | } bee_user_flags_t; |
---|
| 58 | |
---|
| 59 | typedef struct bee_user |
---|
| 60 | { |
---|
| 61 | struct im_connection *ic; |
---|
| 62 | char *handle; |
---|
| 63 | char *fullname; |
---|
[69b896b] | 64 | char *nick; |
---|
[7aadd71] | 65 | struct bee_group *group; |
---|
[10a96f4] | 66 | |
---|
[81e04e1] | 67 | bee_user_flags_t flags; |
---|
| 68 | char *status; |
---|
[10a96f4] | 69 | char *status_msg; |
---|
| 70 | |
---|
[56699f0] | 71 | time_t login_time, idle_time; |
---|
| 72 | |
---|
[10a96f4] | 73 | bee_t *bee; |
---|
| 74 | void *ui_data; |
---|
| 75 | } bee_user_t; |
---|
| 76 | |
---|
[7aadd71] | 77 | typedef struct bee_group |
---|
| 78 | { |
---|
| 79 | char *key; |
---|
| 80 | char *name; |
---|
| 81 | } bee_group_t; |
---|
| 82 | |
---|
[10a96f4] | 83 | typedef struct bee_ui_funcs |
---|
| 84 | { |
---|
[5c7b45c] | 85 | void (*imc_connected)( struct im_connection *ic ); |
---|
| 86 | void (*imc_disconnected)( struct im_connection *ic ); |
---|
| 87 | |
---|
[10a96f4] | 88 | gboolean (*user_new)( bee_t *bee, struct bee_user *bu ); |
---|
| 89 | gboolean (*user_free)( bee_t *bee, struct bee_user *bu ); |
---|
[1d39159] | 90 | gboolean (*user_fullname)( bee_t *bee, bee_user_t *bu ); |
---|
[6ef9065] | 91 | gboolean (*user_nick_hint)( bee_t *bee, bee_user_t *bu, const char *hint ); |
---|
[7e83e8e4] | 92 | gboolean (*user_group)( bee_t *bee, bee_user_t *bu ); |
---|
[81e04e1] | 93 | gboolean (*user_status)( bee_t *bee, struct bee_user *bu, struct bee_user *old ); |
---|
[f012a9f] | 94 | gboolean (*user_msg)( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at ); |
---|
[573dab0] | 95 | gboolean (*user_typing)( bee_t *bee, bee_user_t *bu, guint32 flags ); |
---|
[17a6ee9] | 96 | |
---|
[aea8b68] | 97 | gboolean (*chat_new)( bee_t *bee, struct groupchat *c ); |
---|
| 98 | gboolean (*chat_free)( bee_t *bee, struct groupchat *c ); |
---|
[27e2c66] | 99 | gboolean (*chat_log)( bee_t *bee, struct groupchat *c, const char *text ); |
---|
| 100 | gboolean (*chat_msg)( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at ); |
---|
[aea8b68] | 101 | gboolean (*chat_add_user)( bee_t *bee, struct groupchat *c, bee_user_t *bu ); |
---|
| 102 | gboolean (*chat_remove_user)( bee_t *bee, struct groupchat *c, bee_user_t *bu ); |
---|
[9e27f18] | 103 | gboolean (*chat_topic)( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu ); |
---|
[d343eaa] | 104 | gboolean (*chat_name_hint)( bee_t *bee, struct groupchat *c, const char *name ); |
---|
[aea8b68] | 105 | |
---|
[17a6ee9] | 106 | struct file_transfer* (*ft_in_start)( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size ); |
---|
| 107 | gboolean (*ft_out_start)( struct im_connection *ic, struct file_transfer *ft ); |
---|
| 108 | void (*ft_close)( struct im_connection *ic, struct file_transfer *ft ); |
---|
| 109 | void (*ft_finished)( struct im_connection *ic, struct file_transfer *ft ); |
---|
[10a96f4] | 110 | } bee_ui_funcs_t; |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | /* bee.c */ |
---|
| 114 | bee_t *bee_new(); |
---|
| 115 | void bee_free( bee_t *b ); |
---|
| 116 | |
---|
| 117 | /* bee_user.c */ |
---|
[ad404ab] | 118 | bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle, bee_user_flags_t flags ); |
---|
[eabc9d2] | 119 | int bee_user_free( bee_t *bee, bee_user_t *bu ); |
---|
[10a96f4] | 120 | bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle ); |
---|
[d860a8d] | 121 | int bee_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, int flags ); |
---|
[7aadd71] | 122 | bee_group_t *bee_group_by_name( bee_t *bee, const char *name, gboolean creat ); |
---|
| 123 | void bee_group_free( bee_t *bee ); |
---|
[d860a8d] | 124 | |
---|
| 125 | /* Callbacks from IM modules to core: */ |
---|
| 126 | /* Buddy activity */ |
---|
| 127 | /* To manipulate the status of a handle. |
---|
| 128 | * - flags can be |='d with OPT_* constants. You will need at least: |
---|
| 129 | * OPT_LOGGED_IN and OPT_AWAY. |
---|
| 130 | * - 'state' and 'message' can be NULL */ |
---|
| 131 | G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ); |
---|
[56699f0] | 132 | G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle ); |
---|
[d860a8d] | 133 | /* Call when a handle says something. 'flags' and 'sent_at may be just 0. */ |
---|
[fb117aee] | 134 | G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, guint32 flags, time_t sent_at ); |
---|
[10a96f4] | 135 | |
---|
[aea8b68] | 136 | /* bee_chat.c */ |
---|
| 137 | #if 0 |
---|
| 138 | struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ); |
---|
| 139 | void imcb_chat_name_hint( struct groupchat *c, const char *name ); |
---|
| 140 | void imcb_chat_free( struct groupchat *c ); |
---|
| 141 | void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at ); |
---|
| 142 | void imcb_chat_log( struct groupchat *c, char *format, ... ); |
---|
| 143 | void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ); |
---|
| 144 | void imcb_chat_add_buddy( struct groupchat *b, const char *handle ); |
---|
| 145 | void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason ); |
---|
| 146 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); |
---|
| 147 | #endif |
---|
[a87754b] | 148 | int bee_chat_msg( bee_t *bee, struct groupchat *c, const char *msg, int flags ); |
---|
[eaaa986] | 149 | struct groupchat *bee_chat_by_title( bee_t *bee, struct im_connection *ic, const char *title ); |
---|
[aea8b68] | 150 | |
---|
[10a96f4] | 151 | #endif /* __BEE_H__ */ |
---|