Fix coding style and remove old commented-out code
This commit is contained in:
parent
2f44ea928f
commit
adc429beb4
7 changed files with 34 additions and 127 deletions
|
@ -178,7 +178,6 @@ void read_dc (struct tgl_state *TLS, int auth_file_fd, int id, unsigned ver) {
|
|||
assert (read (auth_file_fd, &auth_key_id, 8) == 8);
|
||||
assert (read (auth_file_fd, auth_key, 256) == 256);
|
||||
|
||||
//bl_do_add_dc (id, ip, l, port, auth_key_id, auth_key);
|
||||
bl_do_dc_option (TLS, id, 2, "DC", l, ip, port);
|
||||
bl_do_set_auth_key_id (TLS, id, auth_key);
|
||||
bl_do_dc_signed (TLS, id);
|
||||
|
@ -264,7 +263,6 @@ void write_secret_chat (tgl_peer_t *_P, void *extra) {
|
|||
|
||||
int id = tgl_get_peer_id (P->id);
|
||||
assert (write (fd, &id, 4) == 4);
|
||||
//assert (write (fd, &P->flags, 4) == 4);
|
||||
int l = strlen (P->print_name);
|
||||
assert (write (fd, &l, 4) == 4);
|
||||
assert (write (fd, P->print_name, l) == l);
|
||||
|
@ -315,7 +313,6 @@ void read_secret_chat (struct tgl_state *TLS, int fd, int v) {
|
|||
static unsigned char key[256];
|
||||
static unsigned char sha[20];
|
||||
assert (read (fd, &id, 4) == 4);
|
||||
//assert (read (fd, &flags, 4) == 4);
|
||||
assert (read (fd, &l, 4) == 4);
|
||||
assert (l > 0 && l < 1000);
|
||||
assert (read (fd, s, l) == l);
|
||||
|
@ -613,8 +610,7 @@ void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat) {
|
|||
/**
|
||||
* This function generates a png image to visualize the sha1 key from an encrypted chat.
|
||||
*/
|
||||
int generate_ident_icon (struct tgl_state *TLS, unsigned char* sha1_key)
|
||||
{
|
||||
int generate_ident_icon (struct tgl_state *TLS, unsigned char* sha1_key) {
|
||||
int colors[4] = {
|
||||
0xffffff,
|
||||
0xd5e6f3,
|
||||
|
|
|
@ -82,8 +82,7 @@ static char *format_status (struct tgl_user_status *status) {
|
|||
return status->online ? "Online" : "Mobile";
|
||||
}
|
||||
|
||||
static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M)
|
||||
{
|
||||
static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) {
|
||||
assert (M && M->service);
|
||||
|
||||
char *txt_user = NULL;
|
||||
|
@ -169,8 +168,7 @@ static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M)
|
|||
return txt;
|
||||
}
|
||||
|
||||
char *format_user_status (struct tgl_user_status *status)
|
||||
{
|
||||
char *format_user_status (struct tgl_user_status *status) {
|
||||
char *when;
|
||||
switch (status->online) {
|
||||
case -1:
|
||||
|
@ -236,28 +234,12 @@ static char *format_document_desc (char *type, char *caption, gint64 size) {
|
|||
static char *format_message (struct tgl_message *M) {
|
||||
|
||||
switch (M->media.type) {
|
||||
/*
|
||||
case tgl_message_media_audio:
|
||||
return format_document_desc("AUDIO", "", M->media.audio.size);
|
||||
break;
|
||||
case tgl_message_media_audio_encr:
|
||||
return format_document_desc("AUDIO", "", M->media.encr_audio.size);
|
||||
break;
|
||||
*/
|
||||
case tgl_message_media_document:
|
||||
return format_document_desc("DOCUMENT", M->media.document.caption, M->media.document.size);
|
||||
break;
|
||||
case tgl_message_media_document_encr:
|
||||
return format_document_desc("DOCUMENT", M->media.encr_document.caption, M->media.encr_document.size);
|
||||
break;
|
||||
/*
|
||||
case tgl_message_media_video:
|
||||
return format_document_desc("VIDEO", M->media.video.caption, M->media.video.size);
|
||||
break;
|
||||
case tgl_message_media_video_encr:
|
||||
return format_document_desc("VIDEO", "", M->media.encr_video.size);
|
||||
break;
|
||||
*/
|
||||
case tgl_message_media_photo_encr:
|
||||
return format_document_desc("PHOTO", "", M->media.encr_photo.size);
|
||||
break;
|
||||
|
@ -274,8 +256,7 @@ static char *format_message (struct tgl_message *M) {
|
|||
}
|
||||
|
||||
|
||||
static void tgl_do_send_unescape_message (struct tgl_state *TLS, const char *message, tgl_peer_id_t to)
|
||||
{
|
||||
static void tgl_do_send_unescape_message (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) {
|
||||
gchar *raw = purple_unescape_html(message);
|
||||
tgl_do_send_message (TLS, to, raw, (int)strlen (raw), 0, 0);
|
||||
g_free(raw);
|
||||
|
@ -408,7 +389,7 @@ static void update_message_received (struct tgl_state *TLS, struct tgl_message *
|
|||
return;
|
||||
}
|
||||
|
||||
char *text = format_message(M);
|
||||
char *text = format_message (M);
|
||||
switch (tgl_get_peer_type (M->to_id)) {
|
||||
case TGL_PEER_CHAT:
|
||||
chat_add_message (TLS, M, text);
|
||||
|
@ -425,7 +406,7 @@ static void update_message_received (struct tgl_state *TLS, struct tgl_message *
|
|||
|
||||
case TGL_PEER_USER:
|
||||
|
||||
if (out_msg(TLS, M)) {
|
||||
if (out_msg (TLS, M)) {
|
||||
// Outgoing message sent from a different device
|
||||
// :TODO: figure out how to add messages from different devices to history
|
||||
p2tgl_got_im (TLS, M->to_id, text, PURPLE_MESSAGE_SEND, M->date);
|
||||
|
@ -678,9 +659,9 @@ void on_ready (struct tgl_state *TLS) {
|
|||
debug ("on_ready().\n");
|
||||
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));
|
||||
purple_blist_add_account(conn->pa);
|
||||
purple_connection_set_state (conn->gc, PURPLE_CONNECTED);
|
||||
purple_connection_set_display_name (conn->gc, purple_account_get_username(conn->pa));
|
||||
purple_blist_add_account (conn->pa);
|
||||
tggroup = purple_find_group ("Telegram");
|
||||
if (tggroup == NULL) {
|
||||
tggroup = purple_group_new ("Telegram");
|
||||
|
@ -815,7 +796,6 @@ static void tgprpl_close (PurpleConnection * gc) {
|
|||
debug ("tgprpl_close()\n");
|
||||
connection_data *conn = purple_connection_get_protocol_data (gc);
|
||||
|
||||
|
||||
connection_data_free (conn);
|
||||
}
|
||||
|
||||
|
@ -938,11 +918,11 @@ static void tgprpl_remove_buddy (PurpleConnection * gc, PurpleBuddy * buddy, Pur
|
|||
|
||||
}
|
||||
|
||||
static void tgprpl_add_deny (PurpleConnection * gc, const char *name){
|
||||
static void tgprpl_add_deny (PurpleConnection * gc, const char *name) {
|
||||
debug ("tgprpl_add_deny()\n");
|
||||
}
|
||||
|
||||
static void tgprpl_rem_deny (PurpleConnection * gc, const char *name){
|
||||
static void tgprpl_rem_deny (PurpleConnection * gc, const char *name) {
|
||||
debug ("tgprpl_rem_deny()\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -324,8 +324,7 @@ PurpleNotifyUserInfo *p2tgl_notify_peer_info_new (struct tgl_state *TLS, tgl_pee
|
|||
}
|
||||
}
|
||||
|
||||
int p2tgl_imgstore_add_with_id (const char* filename)
|
||||
{
|
||||
int p2tgl_imgstore_add_with_id (const char* filename) {
|
||||
gchar *data = NULL;
|
||||
size_t len;
|
||||
GError *err = NULL;
|
||||
|
@ -335,8 +334,7 @@ int p2tgl_imgstore_add_with_id (const char* filename)
|
|||
return id;
|
||||
}
|
||||
|
||||
void p2tgl_buddy_icons_set_for_user (PurpleAccount *pa, tgl_peer_id_t *id, const char* filename)
|
||||
{
|
||||
void p2tgl_buddy_icons_set_for_user (PurpleAccount *pa, tgl_peer_id_t *id, const char* filename) {
|
||||
char *who = g_strdup_printf("%d", tgl_get_peer_id(*id));
|
||||
|
||||
gchar *data = NULL;
|
||||
|
|
49
tgp-net.c
49
tgp-net.c
|
@ -220,10 +220,6 @@ int tgln_read_in_lookup (struct connection *c, void *_data, int len) {
|
|||
void tgln_flush_out (struct connection *c) {
|
||||
}
|
||||
|
||||
//#define MAX_CONNECTIONS 100
|
||||
//static struct connection *Connections[MAX_CONNECTIONS];
|
||||
//static int max_connection_fd;
|
||||
|
||||
static void rotate_port (struct connection *c) {
|
||||
switch (c->port) {
|
||||
case 443:
|
||||
|
@ -478,51 +474,6 @@ static void try_read (struct connection *c) {
|
|||
try_rpc_read (c);
|
||||
}
|
||||
}
|
||||
/*
|
||||
int tgl_connections_make_poll_array (struct pollfd *fds, int max) {
|
||||
int _max = max;
|
||||
int i;
|
||||
for (i = 0; i <= max_connection_fd; i++) {
|
||||
if (Connections[i] && Connections[i]->state == conn_failed) {
|
||||
restart_connection (Connections[i]);
|
||||
}
|
||||
if (Connections[i] && Connections[i]->state != conn_failed) {
|
||||
assert (max > 0);
|
||||
struct connection *c = Connections[i];
|
||||
fds[0].fd = c->fd;
|
||||
fds[0].events = POLLERR | POLLHUP | POLLRDHUP | POLLIN;
|
||||
if (c->out_bytes || c->state == conn_connecting) {
|
||||
fds[0].events |= POLLOUT;
|
||||
}
|
||||
fds ++;
|
||||
max --;
|
||||
}
|
||||
}
|
||||
return _max - max;
|
||||
}
|
||||
|
||||
void tgl_connections_poll_result (struct pollfd *fds, int max) {
|
||||
int i;
|
||||
for (i = 0; i < max; i++) {
|
||||
struct connection *c = Connections[fds[i].fd];
|
||||
if (fds[i].revents & POLLIN) {
|
||||
try_read (c);
|
||||
}
|
||||
if (fds[i].revents & (POLLHUP | POLLERR | POLLRDHUP)) {
|
||||
vlogprintf (E_NOTICE, "fail_connection: events_mask=0x%08x\n", fds[i].revents);
|
||||
fail_connection (c);
|
||||
} else if (fds[i].revents & POLLOUT) {
|
||||
if (c->state == conn_connecting) {
|
||||
vlogprintf (E_DEBUG, "connection ready\n");
|
||||
c->state = conn_ready;
|
||||
c->last_receive_time = tglt_get_double_time ();
|
||||
}
|
||||
if (c->out_bytes) {
|
||||
try_write (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
static void incr_out_packet_num (struct connection *c) {
|
||||
c->out_packet_num ++;
|
||||
|
|
|
@ -26,27 +26,19 @@
|
|||
#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)
|
||||
{
|
||||
void pending_reads_free_cb (gpointer data) {
|
||||
free (data);
|
||||
}
|
||||
|
||||
static void pending_reads_cb (struct tgl_state *TLS, void *extra, int success)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
void pending_reads_send_all (GQueue *queue, struct tgl_state *TLS) {
|
||||
debug ("send all pending ack");
|
||||
|
||||
tgl_peer_id_t *pending;
|
||||
|
@ -58,8 +50,7 @@ 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_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)) {
|
||||
|
@ -67,8 +58,7 @@ void pending_reads_add (GQueue *queue, tgl_peer_id_t id)
|
|||
}
|
||||
}
|
||||
|
||||
struct message_text *message_text_init (struct tgl_message *M, gchar *text)
|
||||
{
|
||||
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;
|
||||
|
@ -84,21 +74,16 @@ void message_text_free (gpointer data)
|
|||
free (mt);
|
||||
}
|
||||
|
||||
static void used_image_free (gpointer data)
|
||||
{
|
||||
static void used_image_free (gpointer data) {
|
||||
int id = GPOINTER_TO_INT(data);
|
||||
purple_imgstore_unref_by_id (id);
|
||||
debug ("used_image: unref %d", id);
|
||||
}
|
||||
|
||||
void used_images_add (connection_data *data, gint imgid)
|
||||
{
|
||||
void used_images_add (connection_data *data, gint imgid) {
|
||||
data->used_images = g_list_append (data->used_images, GINT_TO_POINTER(imgid));
|
||||
debug ("used_image: add %d", imgid);
|
||||
}
|
||||
|
||||
connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection *gc, PurpleAccount *pa)
|
||||
{
|
||||
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;
|
||||
|
@ -109,8 +94,7 @@ connection_data *connection_data_init (struct tgl_state *TLS, PurpleConnection *
|
|||
return conn;
|
||||
}
|
||||
|
||||
void *connection_data_free (connection_data *conn)
|
||||
{
|
||||
void *connection_data_free (connection_data *conn) {
|
||||
if (conn->write_timer) { purple_timeout_remove (conn->write_timer); }
|
||||
if (conn->login_timer) { purple_timeout_remove (conn->login_timer); }
|
||||
|
||||
|
@ -125,8 +109,7 @@ void *connection_data_free (connection_data *conn)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
get_user_info_data* get_user_info_data_new (int show_info, tgl_peer_id_t peer)
|
||||
{
|
||||
get_user_info_data* get_user_info_data_new (int show_info, tgl_peer_id_t peer) {
|
||||
get_user_info_data *info_data = malloc (sizeof(get_user_info_data));
|
||||
info_data->show_info = show_info;
|
||||
info_data->peer = peer;
|
||||
|
|
12
tgp-utils.c
12
tgp-utils.c
|
@ -40,22 +40,15 @@ int str_not_empty (const char *string) {
|
|||
return string && string[0] != '\0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this message was created by our client in this session
|
||||
*/
|
||||
int our_msg (struct tgl_state *TLS, struct tgl_message *M) {
|
||||
return (M->flags & FLAG_SESSION_OUTBOUND) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this message was created by the current user.
|
||||
*/
|
||||
int out_msg (struct tgl_state *TLS, struct tgl_message *M) {
|
||||
return M->out;
|
||||
}
|
||||
|
||||
tgl_peer_t *tgp_encr_chat_get_partner (struct tgl_state *TLS, struct tgl_secret_chat *chat)
|
||||
{
|
||||
tgl_peer_t *tgp_encr_chat_get_partner (struct tgl_state *TLS, struct tgl_secret_chat *chat) {
|
||||
return tgl_peer_get (TLS, TGL_MK_USER(chat->admin_id == TLS->our_id ? chat->user_id : chat->admin_id));
|
||||
}
|
||||
|
||||
|
@ -76,8 +69,7 @@ char *tgp_g_format_size (gint64 size) {
|
|||
return g_strdup_printf ("%.1f %s, ", s, sizes[base]);
|
||||
}
|
||||
|
||||
void tgp_g_queue_free_full (GQueue *queue, GDestroyNotify free_func)
|
||||
{
|
||||
void tgp_g_queue_free_full (GQueue *queue, GDestroyNotify free_func) {
|
||||
void *entry;
|
||||
|
||||
while ((entry = g_queue_pop_head(queue))) {
|
||||
|
|
|
@ -30,10 +30,17 @@ const char *format_time (time_t date);
|
|||
char *format_img_full (int imgstore);
|
||||
int str_not_empty (const char *string);
|
||||
|
||||
/**
|
||||
* Return whether this message was created by our client in this session
|
||||
*/
|
||||
int our_msg (struct tgl_state *TLS, struct tgl_message *M);
|
||||
|
||||
/**
|
||||
* Return whether this message was created by the current user.
|
||||
*/
|
||||
int out_msg (struct tgl_state *TLS, struct tgl_message *M);
|
||||
|
||||
char *tgp_g_format_size (gint64 size);
|
||||
void tgp_g_queue_free_full (GQueue *queue, GDestroyNotify free_func);
|
||||
|
||||
#endif /* defined(__telegram_adium__tgp_util__) */
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue