Move functions and defintions for plugin-internal structs into separate file and fix memory leak
This commit is contained in:
parent
4fa2b91eaa
commit
d08e54d3e0
8 changed files with 214 additions and 124 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <telegram-purple.h>
|
||||
#include <msglog.h>
|
||||
#include <tgp-2prpl.h>
|
||||
#include "tgp-structs.h"
|
||||
|
||||
#define DC_SERIALIZED_MAGIC 0x868aa81d
|
||||
#define STATE_FILE_MAGIC 0x28949a93
|
||||
|
@ -165,7 +166,7 @@ void read_dc (struct tgl_state *TLS, int auth_file_fd, int id, unsigned ver) {
|
|||
|
||||
int error_if_val_false (struct tgl_state *TLS, int val, const char *msg) {
|
||||
if (!val) {
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
purple_connection_error_reason (conn->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, msg);
|
||||
return 1;
|
||||
}
|
||||
|
@ -271,21 +272,21 @@ static void code_auth_receive_result (struct tgl_state *TLS, void *extra, int su
|
|||
|
||||
void request_code_entered (gpointer data, const gchar *code) {
|
||||
struct tgl_state *TLS = data;
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
char const *username = purple_account_get_username(conn->pa);
|
||||
tgl_do_send_code_result (TLS, username, conn->hash, code, code_receive_result, 0) ;
|
||||
}
|
||||
|
||||
static void request_code_canceled (gpointer data) {
|
||||
struct tgl_state *TLS = data;
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
purple_connection_error_reason(conn->gc,
|
||||
PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, "registration canceled");
|
||||
}
|
||||
|
||||
static void request_name_code_entered (PurpleConnection* gc, PurpleRequestFields* fields) {
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data(gc);
|
||||
struct tgl_state *TLS = conn->TLS;
|
||||
char const *username = purple_account_get_username(conn->pa);
|
||||
|
||||
|
@ -302,7 +303,7 @@ static void request_name_code_entered (PurpleConnection* gc, PurpleRequestFields
|
|||
|
||||
static void request_code (struct tgl_state *TLS) {
|
||||
debug ("Client is not registered, registering...\n");
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
int compat = purple_account_get_bool (tg_get_acc(TLS), "compat-verification", 0);
|
||||
|
||||
if (compat || ! purple_request_input (conn->gc, "Telegram Code", "Enter Telegram Code",
|
||||
|
@ -324,7 +325,7 @@ static void request_code (struct tgl_state *TLS) {
|
|||
static void request_name_and_code (struct tgl_state *TLS) {
|
||||
debug ("Phone is not registered, registering...\n");
|
||||
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
PurpleRequestFields* fields = purple_request_fields_new();
|
||||
PurpleRequestField* field = 0;
|
||||
|
@ -351,7 +352,7 @@ static void request_name_and_code (struct tgl_state *TLS) {
|
|||
}
|
||||
|
||||
static void sign_in_callback (struct tgl_state *TLS, void *extra, int success, int registered, const char *mhash) {
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
if (!error_if_val_false (TLS, success, "Invalid or non-existing phone number.")) {
|
||||
conn->hash = strdup (mhash);
|
||||
if (registered) {
|
||||
|
@ -367,7 +368,7 @@ static void telegram_send_sms (struct tgl_state *TLS) {
|
|||
telegram_export_authorization (TLS);
|
||||
return;
|
||||
}
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
char const *username = purple_account_get_username(conn->pa);
|
||||
tgl_do_send_code (TLS, username, sign_in_callback, 0);
|
||||
}
|
||||
|
@ -404,7 +405,7 @@ void telegram_login (struct tgl_state *TLS) {
|
|||
|
||||
PurpleConversation *chat_show (PurpleConnection *gc, int id) {
|
||||
debug ("show chat");
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data(gc);
|
||||
|
||||
PurpleConversation *convo = purple_find_chat(gc, id);
|
||||
if (! convo) {
|
||||
|
@ -420,7 +421,7 @@ PurpleConversation *chat_show (PurpleConnection *gc, int id) {
|
|||
}
|
||||
|
||||
int chat_add_message (struct tgl_state *TLS, struct tgl_message *M, char *text) {
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) {
|
||||
p2tgl_got_chat_in(TLS, M->to_id, M->from_id, text ? text : M->message,
|
||||
|
@ -428,9 +429,7 @@ int chat_add_message (struct tgl_state *TLS, struct tgl_message *M, char *text)
|
|||
return 1;
|
||||
} else {
|
||||
// add message once the chat was initialised
|
||||
struct message_text *mt = malloc (sizeof (*mt));
|
||||
mt->M = M;
|
||||
mt->text = text ? g_strdup (text) : text;
|
||||
struct message_text *mt = message_text_init (M, text);
|
||||
g_queue_push_tail (conn->new_messages, mt);
|
||||
return 0;
|
||||
}
|
||||
|
@ -451,45 +450,3 @@ void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void pending_reads_cb (struct tgl_state *TLS, void *extra, int success)
|
||||
{
|
||||
debug ("ack state: %d", success);
|
||||
}
|
||||
|
||||
static gint pending_reads_compare (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return !memcmp ((tgl_peer_id_t *)a, (tgl_peer_id_t *)b, sizeof(tgl_peer_id_t));
|
||||
}
|
||||
|
||||
void pending_reads_send_all (GQueue *queue, struct tgl_state *TLS)
|
||||
{
|
||||
debug ("send all pending ack");
|
||||
|
||||
tgl_peer_id_t *pending;
|
||||
|
||||
while ((pending = (tgl_peer_id_t*) g_queue_pop_head(queue))) {
|
||||
tgl_do_mark_read (TLS, *pending, pending_reads_cb, queue);
|
||||
debug ("tgl_do_mark_read (%d)", pending->id);
|
||||
free (pending);
|
||||
}
|
||||
}
|
||||
|
||||
void pending_reads_add (GQueue *queue, tgl_peer_id_t id)
|
||||
{
|
||||
tgl_peer_id_t *copy = malloc (sizeof(tgl_peer_id_t));
|
||||
*copy = id;
|
||||
if (! g_queue_find_custom (queue, copy, pending_reads_compare)) {
|
||||
g_queue_push_tail (queue, copy);
|
||||
}
|
||||
}
|
||||
|
||||
void pending_reads_clear (GQueue *queue)
|
||||
{
|
||||
tgl_peer_id_t *pending;
|
||||
|
||||
while ((pending = (tgl_peer_id_t*) g_queue_pop_head(queue))) {
|
||||
free (pending);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,4 @@ int chat_add_message (struct tgl_state *TLS, struct tgl_message *M, char *text);
|
|||
void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat);
|
||||
void request_code_entered (gpointer data, const gchar *code);
|
||||
|
||||
void pending_reads_send_all (GQueue *queue, struct tgl_state *TLS);
|
||||
void pending_reads_add (GQueue *queue, tgl_peer_id_t id);
|
||||
void pending_reads_clear (GQueue *queue);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "request.h"
|
||||
|
||||
#include <tgl.h>
|
||||
#include "tgp-structs.h"
|
||||
#include "tgp-2prpl.h"
|
||||
#include "tgp-net.h"
|
||||
#include "tgp-timers.h"
|
||||
|
@ -66,8 +67,8 @@ const char *pk_path = "/etc/telegram-purple/server.pub";
|
|||
void tgprpl_login_on_connected();
|
||||
void on_user_get_info (struct tgl_state *TLS, void *show_info, int success, struct tgl_user *U);
|
||||
|
||||
static telegram_conn *get_conn_from_buddy (PurpleBuddy *buddy) {
|
||||
telegram_conn *c = purple_connection_get_protocol_data (
|
||||
static connection_data *get_conn_from_buddy (PurpleBuddy *buddy) {
|
||||
connection_data *c = purple_connection_get_protocol_data (
|
||||
purple_account_get_connection (purple_buddy_get_account (buddy)));
|
||||
return c;
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ static int out_msg (struct tgl_state *TLS, struct tgl_message *M) {
|
|||
|
||||
static gboolean queries_timerfunc (gpointer data) {
|
||||
debug ("queries_timerfunc()\n");
|
||||
telegram_conn *conn = data;
|
||||
connection_data *conn = data;
|
||||
|
||||
if (conn->updated) {
|
||||
conn->updated = 0;
|
||||
|
@ -267,13 +268,13 @@ void on_message_load_photo (struct tgl_state *TLS, void *extra, int success, cha
|
|||
}
|
||||
|
||||
g_free (image);
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
conn->updated = 1;
|
||||
}
|
||||
|
||||
static void update_message_received (struct tgl_state *TLS, struct tgl_message *M) {
|
||||
debug ("received message\n");
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
conn->updated = 1;
|
||||
|
||||
if (M->service) {
|
||||
|
@ -436,7 +437,7 @@ static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success,
|
|||
struct tgl_user *U = dld->data;
|
||||
warning ("Can not load userpic for user %s %s\n", U->first_name, U->last_name);
|
||||
}
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
gchar *data = NULL;
|
||||
size_t len;
|
||||
|
@ -484,7 +485,7 @@ void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct t
|
|||
assert (success);
|
||||
|
||||
debug ("on_chat_joined(%d)\n", tgl_get_peer_id (C->id));
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
PurpleConversation *conv;
|
||||
if (!(conv = purple_find_chat(conn->gc, tgl_get_peer_id(C->id)))) {
|
||||
|
@ -513,7 +514,7 @@ void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct t
|
|||
|
||||
void on_ready (struct tgl_state *TLS) {
|
||||
debug ("on_ready().\n");
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
purple_connection_set_state(conn->gc, PURPLE_CONNECTED);
|
||||
purple_connection_set_display_name(conn->gc, purple_account_get_username(conn->pa));
|
||||
|
@ -619,13 +620,7 @@ static void tgprpl_login (PurpleAccount * acct) {
|
|||
|
||||
// create handle to store additional info for libpurple in
|
||||
// the new telegram instance
|
||||
telegram_conn *conn = g_new0(telegram_conn, 1);
|
||||
conn->TLS = TLS;
|
||||
conn->gc = gc;
|
||||
conn->pa = acct;
|
||||
conn->new_messages = g_queue_new ();
|
||||
conn->pending_reads = g_queue_new ();
|
||||
conn->joining_chats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
connection_data *conn = connection_data_init (TLS, gc, acct);
|
||||
purple_connection_set_protocol_data (gc, conn);
|
||||
|
||||
tgl_set_ev_base (TLS, conn);
|
||||
|
@ -642,22 +637,16 @@ static void tgprpl_login (PurpleAccount * acct) {
|
|||
|
||||
static void tgprpl_close (PurpleConnection * gc) {
|
||||
debug ("tgprpl_close()\n");
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
purple_timeout_remove(conn->timer);
|
||||
|
||||
pending_reads_clear (conn->pending_reads);
|
||||
|
||||
tgl_free_all (conn->TLS);
|
||||
g_queue_free (conn->new_messages);
|
||||
g_queue_free (conn->pending_reads);
|
||||
g_hash_table_destroy (conn->joining_chats);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
purple_timeout_remove (conn->timer);
|
||||
|
||||
connection_data_free (conn);
|
||||
}
|
||||
|
||||
static int tgprpl_send_im (PurpleConnection * gc, const char *who, const char *message, PurpleMessageFlags flags) {
|
||||
debug ("tgprpl_send_im()\n");
|
||||
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data(gc);
|
||||
PurpleAccount *pa = conn->pa;
|
||||
|
||||
// this is part of a workaround to support clients without
|
||||
|
@ -688,7 +677,7 @@ static int tgprpl_send_im (PurpleConnection * gc, const char *who, const char *m
|
|||
static unsigned int tgprpl_send_typing (PurpleConnection * gc, const char *who, PurpleTypingState typing) {
|
||||
debug ("tgprpl_send_typing()\n");
|
||||
int id = atoi (who);
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data(gc);
|
||||
tgl_peer_t *U = tgl_peer_get (conn->TLS, TGL_MK_USER (id));
|
||||
if (U) {
|
||||
if (typing == PURPLE_TYPING) {
|
||||
|
@ -702,7 +691,7 @@ static unsigned int tgprpl_send_typing (PurpleConnection * gc, const char *who,
|
|||
|
||||
static void tgprpl_get_info (PurpleConnection * gc, const char *username) {
|
||||
debug ("tgprpl_get_info()\n");
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data(gc);
|
||||
tgl_peer_id_t u = TGL_MK_USER(atoi(username));
|
||||
tgl_do_get_user_info (conn->TLS, u, 0, on_user_get_info, (void *)1l);
|
||||
}
|
||||
|
@ -713,7 +702,7 @@ static void tgprpl_set_status (PurpleAccount * acct, PurpleStatus * status) {
|
|||
|
||||
PurpleConnection *gc = purple_account_get_connection(acct);
|
||||
if (!gc) { return; }
|
||||
telegram_conn *conn = purple_connection_get_protocol_data (gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
|
||||
if (p2tgl_status_is_present(status)) {
|
||||
pending_reads_send_all (conn->pending_reads, conn->TLS);
|
||||
|
@ -721,7 +710,7 @@ static void tgprpl_set_status (PurpleAccount * acct, PurpleStatus * status) {
|
|||
}
|
||||
|
||||
static void tgprpl_add_buddy (PurpleConnection * gc, PurpleBuddy * buddy, PurpleGroup * group) {
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data(gc);
|
||||
const char* first = buddy->alias ? buddy->alias : "";
|
||||
|
||||
tgl_do_add_contact (conn->TLS, buddy->name, (int)strlen (buddy->name), first, (int)strlen (first), "", 0, 0, on_contact_added, buddy);
|
||||
|
@ -735,7 +724,7 @@ static void tgprpl_remove_buddy (PurpleConnection * gc, PurpleBuddy * buddy, Pur
|
|||
debug ("tgprpl_remove_buddy()\n");
|
||||
if (!buddy) { return; }
|
||||
|
||||
telegram_conn *conn = purple_connection_get_protocol_data (gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
struct tgl_user *user = purple_buddy_get_protocol_data (buddy);
|
||||
if (!user) { warning ("cannot remove buddy '%s', no protocol data found\n", buddy->name); return; }
|
||||
|
||||
|
@ -757,7 +746,7 @@ static void tgprpl_rem_deny (PurpleConnection * gc, const char *name){
|
|||
static void tgprpl_chat_join (PurpleConnection * gc, GHashTable * data) {
|
||||
debug ("tgprpl_chat_join()\n");
|
||||
|
||||
telegram_conn *conn = purple_connection_get_protocol_data (gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
const char *groupname = g_hash_table_lookup (data, "subject");
|
||||
|
||||
char *id = g_hash_table_lookup(data, "id");
|
||||
|
@ -794,7 +783,7 @@ static GHashTable *tgprpl_chat_info_deflt (PurpleConnection * gc, const char *ch
|
|||
static void tgprpl_chat_invite (PurpleConnection * gc, int id, const char *message, const char *name) {
|
||||
debug ("tgprpl_chat_invite()\n");
|
||||
|
||||
telegram_conn *conn = purple_connection_get_protocol_data (gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
tgl_peer_t *chat = tgl_peer_get(conn->TLS, TGL_MK_CHAT (id));
|
||||
tgl_peer_t *user = tgl_peer_get(conn->TLS, TGL_MK_USER (atoi(name)));
|
||||
|
||||
|
@ -808,7 +797,7 @@ static void tgprpl_chat_invite (PurpleConnection * gc, int id, const char *messa
|
|||
|
||||
static int tgprpl_send_chat (PurpleConnection * gc, int id, const char *message, PurpleMessageFlags flags) {
|
||||
debug ("tgprpl_send_chat()\n");
|
||||
telegram_conn *conn = purple_connection_get_protocol_data (gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
|
||||
gchar *raw = purple_unescape_html(message);
|
||||
tgl_do_send_message (conn->TLS, TGL_MK_CHAT(id), raw, (int)strlen (raw), 0, 0);
|
||||
|
@ -834,7 +823,7 @@ static void tgprpl_convo_closed (PurpleConnection * gc, const char *who){
|
|||
static void tgprpl_set_buddy_icon (PurpleConnection * gc, PurpleStoredImage * img) {
|
||||
debug ("tgprpl_set_buddy_icon()\n");
|
||||
|
||||
telegram_conn *conn = purple_connection_get_protocol_data (gc);
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
if (purple_imgstore_get_filename (img)) {
|
||||
char* filename = g_strdup_printf ("%s/icons/%s", purple_user_dir(), purple_imgstore_get_filename (img));
|
||||
debug (filename);
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#define TG_VERSION "0.5"
|
||||
#define TG_BUILD "10"
|
||||
|
||||
#include <glib.h>
|
||||
#include <notify.h>
|
||||
#include <plugin.h>
|
||||
#include <version.h>
|
||||
|
@ -38,29 +37,6 @@
|
|||
#define TGP_APP_HASH "99428c722d0ed59b9cd844e4577cb4bb"
|
||||
#define TGP_APP_ID 16154
|
||||
|
||||
typedef struct {
|
||||
struct tgl_state *TLS;
|
||||
char *hash;
|
||||
PurpleAccount *pa;
|
||||
PurpleConnection *gc;
|
||||
int updated;
|
||||
GQueue *new_messages;
|
||||
GQueue *pending_reads;
|
||||
GHashTable *joining_chats;
|
||||
guint timer;
|
||||
int in_fallback_chat;
|
||||
} telegram_conn;
|
||||
|
||||
struct download_desc {
|
||||
int type;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct message_text {
|
||||
struct tgl_message *M;
|
||||
char *text;
|
||||
};
|
||||
|
||||
void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct tgl_chat *C);
|
||||
void on_ready (struct tgl_state *TLS);
|
||||
extern const char *pk_path;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
#include "telegram-purple.h"
|
||||
#include "tgp-2prpl.h"
|
||||
#include "tgp-structs.h"
|
||||
|
||||
#include <server.h>
|
||||
#include <tgl.h>
|
||||
|
@ -56,11 +57,11 @@ static int user_get_alias (tgl_peer_t *user, char *buffer, int maxlen) {
|
|||
}
|
||||
|
||||
PurpleAccount *tg_get_acc (struct tgl_state *TLS) {
|
||||
return (PurpleAccount *) ((telegram_conn *)TLS->ev_base)->pa;
|
||||
return (PurpleAccount *) ((connection_data *)TLS->ev_base)->pa;
|
||||
}
|
||||
|
||||
PurpleConnection *tg_get_conn (struct tgl_state *TLS) {
|
||||
return (PurpleConnection *) ((telegram_conn *)TLS->ev_base)->gc;
|
||||
return (PurpleConnection *) ((connection_data *)TLS->ev_base)->gc;
|
||||
}
|
||||
|
||||
static char *peer_strdup_id(tgl_peer_id_t user) {
|
||||
|
@ -120,7 +121,7 @@ static int hasht_cmp_id(GHashTable *hasht, void *data) {
|
|||
|
||||
|
||||
PurpleConversation *p2tgl_got_joined_chat (struct tgl_state *TLS, struct tgl_chat *chat) {
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
gchar *alias = p2tgl_strdup_alias((tgl_peer_t *)chat);
|
||||
|
||||
PurpleConversation *conv = serv_got_joined_chat(conn->gc, tgl_get_peer_id(chat->id), alias);
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <time.h>
|
||||
|
||||
#include "tgp-net.h"
|
||||
#include "tgp-structs.h"
|
||||
#include <tgl.h>
|
||||
#include <tgl-inner.h>
|
||||
|
||||
|
@ -334,7 +335,7 @@ struct connection *tgln_create_connection (struct tgl_state *TLS, const char *ho
|
|||
|
||||
c->conn_timeout = MIN_EXP_TIMEOUT;
|
||||
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
c->prpl_data = purple_proxy_connect (conn->gc, conn->pa, host, port, net_on_connected, c);
|
||||
|
||||
return c;
|
||||
|
@ -347,8 +348,8 @@ static void restart_connection (struct connection *c) {
|
|||
return;
|
||||
}
|
||||
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
c->prpl_data = purple_proxy_connect (conn->gc, conn->pa, c->ip, c->port, net_on_connected, c);
|
||||
connection_data *conn = TLS->ev_base;
|
||||
// c->prpl_data = purple_proxy_connect (conn->gc, conn->pa, c->ip, c->port, net_on_connected, c);
|
||||
}
|
||||
|
||||
static void fail_connection (struct connection *c) {
|
||||
|
@ -384,7 +385,7 @@ static void fail_connection (struct connection *c) {
|
|||
c->out_bytes = c->in_bytes = 0;
|
||||
|
||||
if (c->state == conn_ready) {
|
||||
telegram_conn *conn = TLS->ev_base;
|
||||
connection_data *conn = TLS->ev_base;
|
||||
purple_connection_error_reason(conn->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, "connection fail");
|
||||
}
|
||||
c->prpl_data = NULL; // Did not find any destroy code. What should be done here?
|
||||
|
|
109
tgp-structs.c
Normal file
109
tgp-structs.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
This file is part of telegram-purple
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
|
||||
Copyright Matthias Jentsch 2014
|
||||
*/
|
||||
|
||||
#include "tgp-structs.h"
|
||||
#include "purple.h"
|
||||
#include "msglog.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <tgl.h>
|
||||
|
||||
/*
|
||||
tgp-structs.c: Structs that are only used internally by the protocol plugin
|
||||
*/
|
||||
|
||||
void pending_reads_free_cb (gpointer data)
|
||||
{
|
||||
free (data);
|
||||
}
|
||||
|
||||
static void pending_reads_cb (struct tgl_state *TLS, void *extra, int success)
|
||||
{
|
||||
debug ("ack state: %d", success);
|
||||
}
|
||||
|
||||
static gint pending_reads_compare (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return !memcmp ((tgl_peer_id_t *)a, (tgl_peer_id_t *)b, sizeof(tgl_peer_id_t));
|
||||
}
|
||||
|
||||
void pending_reads_send_all (GQueue *queue, struct tgl_state *TLS)
|
||||
{
|
||||
debug ("send all pending ack");
|
||||
|
||||
tgl_peer_id_t *pending;
|
||||
|
||||
while ((pending = (tgl_peer_id_t*) g_queue_pop_head(queue))) {
|
||||
tgl_do_mark_read (TLS, *pending, pending_reads_cb, queue);
|
||||
debug ("tgl_do_mark_read (%d)", pending->id);
|
||||
free (pending);
|
||||
}
|
||||
}
|
||||
|
||||
void pending_reads_add (GQueue *queue, tgl_peer_id_t id)
|
||||
{
|
||||
tgl_peer_id_t *copy = malloc (sizeof(tgl_peer_id_t));
|
||||
*copy = id;
|
||||
if (! g_queue_find_custom (queue, copy, pending_reads_compare)) {
|
||||
g_queue_push_tail (queue, copy);
|
||||
}
|
||||
}
|
||||
|
||||
struct message_text *message_text_init (struct tgl_message *M, gchar *text)
|
||||
{
|
||||
struct message_text *mt = malloc (sizeof (struct message_text));
|
||||
mt->M = M;
|
||||
mt->text = text ? g_strdup (text) : text;
|
||||
return mt;
|
||||
}
|
||||
|
||||
void message_text_free (gpointer data)
|
||||
{
|
||||
struct message_text *mt = (struct message_text*)data;
|
||||
if (mt->text) {
|
||||
g_free (mt->text);
|
||||
}
|
||||
free (mt);
|
||||
}
|
||||
|
||||
|
||||
connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection *gc, PurpleAccount *pa)
|
||||
{
|
||||
connection_data *conn = g_new0 (connection_data, 1);
|
||||
conn->TLS = TLS;
|
||||
conn->gc = gc;
|
||||
conn->pa = pa;
|
||||
conn->new_messages = g_queue_new ();
|
||||
conn->pending_reads = g_queue_new ();
|
||||
conn->joining_chats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
return conn;
|
||||
}
|
||||
|
||||
void *connection_data_free (connection_data *conn)
|
||||
{
|
||||
purple_timeout_remove(conn->timer);
|
||||
g_queue_free_full (conn->pending_reads, pending_reads_free_cb);
|
||||
g_queue_free_full (conn->new_messages, message_text_free);
|
||||
g_hash_table_destroy (conn->joining_chats);
|
||||
tgl_free_all (conn->TLS);
|
||||
free (conn);
|
||||
return NULL;
|
||||
}
|
||||
|
61
tgp-structs.h
Normal file
61
tgp-structs.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
This file is part of telegram-purple
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
|
||||
Copyright Matthias Jentsch 2014
|
||||
*/
|
||||
|
||||
#ifndef __telegram_adium__tgp_data__
|
||||
#define __telegram_adium__tgp_data__
|
||||
|
||||
#include "purple.h"
|
||||
|
||||
#include <tgl.h>
|
||||
#include <glib.h>
|
||||
|
||||
typedef struct {
|
||||
struct tgl_state *TLS;
|
||||
char *hash;
|
||||
PurpleAccount *pa;
|
||||
PurpleConnection *gc;
|
||||
int updated;
|
||||
GQueue *new_messages;
|
||||
GQueue *pending_reads;
|
||||
GHashTable *joining_chats;
|
||||
guint timer;
|
||||
int in_fallback_chat;
|
||||
} connection_data;
|
||||
|
||||
struct download_desc {
|
||||
int type;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct message_text {
|
||||
struct tgl_message *M;
|
||||
char *text;
|
||||
};
|
||||
|
||||
void pending_reads_send_all (GQueue *queue, struct tgl_state *TLS);
|
||||
void pending_reads_add (GQueue *queue, tgl_peer_id_t id);
|
||||
|
||||
struct message_text *message_text_init (struct tgl_message *M, gchar *text);
|
||||
void message_text_free (gpointer data);
|
||||
|
||||
void *connection_data_free (connection_data *conn);
|
||||
connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection *gc, PurpleAccount *pa);
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue