1 /* 2 * Copyright 2015 Artem Savkov <artem.savkov@gmail.com> 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #ifndef __DISCORD_H 18 #define __DISCORD_H 19 20 #include <bitlbee.h> 21 22 #define DISCORD_HOST "discordapp.com" 23 #define DEFAULT_KEEPALIVE_INTERVAL 30000 24 #define DISCORD_MFA_HANDLE "discord_mfa" 25 26 typedef enum { 27 WS_IDLE, 28 WS_CONNECTING, 29 WS_CONNECTED, 30 WS_ALMOST_READY, 31 WS_READY, 32 WS_CLOSING, 33 } ws_state; 34 35 typedef enum { 36 CHANNEL_TEXT, 37 CHANNEL_PRIVATE, 38 CHANNEL_VOICE, 39 CHANNEL_GROUP_PRIVATE 40 } channel_type; 41 42 typedef enum { 43 RELATIONSHIP_NONE, 44 RELATIONSHIP_FRIENDS, 45 RELATIONSHIP_UNKNOWN, 46 RELATIONSHIP_REQUEST_RECEIVED, 47 RELATIONSHIP_REQUEST_SENT 48 } relationship_type; 49 50 typedef struct _gw_data { 51 int wss; 52 gchar *addr; 53 gchar *path; 54 } gw_data; 55 56 typedef struct _discord_data { 57 char *token; 58 char *id; 59 char *session_id; 60 char *uname; 61 gw_data *gateway; 62 GSList *servers; 63 GSList *pchannels; 64 gint main_loop_id; 65 GString *ws_buf; 66 ws_state state; 67 gint keepalive_interval; 68 gint keepalive_loop_id; 69 gint heartbeat_timeout_id; 70 gint status_timeout_id; 71 void *ssl; 72 int sslfd; 73 gint inpa; 74 gint wsid; 75 guint64 seq; 76 GSList *pending_reqs; 77 GSList *pending_events; 78 gboolean reconnecting; 79 GHashTable *sent_message_ids; 80 } discord_data; 81 82 typedef struct _server_info { 83 char *name; 84 char *id; 85 GSList *users; 86 GSList *channels; 87 struct im_connection *ic; 88 } server_info; 89 90 typedef struct _channel_info { 91 char *id; 92 guint64 last_msg; 93 guint64 last_read; 94 union { 95 struct { 96 struct groupchat *gc; 97 char *name; 98 bee_chat_info_t *bci; 99 server_info *sinfo; 100 } channel; 101 struct { 102 char *name; 103 struct im_connection *ic; 104 } handle; 105 struct { 106 struct groupchat *gc; 107 char *name; 108 bee_chat_info_t *bci; 109 GSList *users; 110 struct im_connection *ic; 111 } group; 112 } to; 113 channel_type type; 114 GSList *pinned; 115 } channel_info; 116 117 typedef struct _user_info { 118 char *id; 119 char *name; 120 channel_info *voice_channel; 121 bee_user_t *user; 122 guint32 flags; 123 } user_info; 124 125 gboolean discord_is_self(struct im_connection *ic, const char *who); 126 127 struct groupchat *discord_chat_do_join(struct im_connection *ic, 128 const char *name, 129 gboolean is_auto_join); 130 void discord_soft_reconnect(struct im_connection *ic); 131 132 #endif //__DISCORD_H 133