diff --git a/purple-plugin/Makefile b/purple-plugin/Makefile index 0651517..41aff3e 100755 --- a/purple-plugin/Makefile +++ b/purple-plugin/Makefile @@ -4,7 +4,7 @@ EXTRA_LIBS = -lcrypto -lz -lm -lreadline LDFLAGSTG = -L/usr/local/lib CPPFLAGSTG = -I/usr/local/include -OBJECTSTG = ../main.o ../loop.o ../interface.o ../net.o ../mtproto-common.o ../mtproto-client.o ../queries.o ../structures.o ../binlog.o ../tools.o ../lua-tg.o ../msglog.o +OBJECTSTG = ../main.o ../loop.o ../interface.o ../net.o ../mtproto-common.o ../mtproto-client.o ../queries.o ../structures.o ../binlog.o ../tools.o ../lua-tg.o ../msglog.o ../tg-cli.o INCLUDE = -I. -I.. # @@ -34,6 +34,7 @@ CFLAGS = \ -fPIC \ -DPURPLE_PLUGINS \ -DPIC \ + -g \ $(CFLAGS_PURPLE) LIBS_PURPLE = $(shell pkg-config --libs purple) @@ -53,7 +54,7 @@ strip: $(LIBNAME) .PHONY: debug install debug: CFLAGS += -g -DDEBUG debug: $(LIBNAME) - gdb -tui pidgin + gdb -tui -ex 'break telegram-purple.c:tgprpl_login' pidgin PLUGIN_DIR_PURPLE:=$(shell pkg-config --variable=plugindir purple) @@ -83,4 +84,4 @@ clean: .PHONY: run run: all install - pidgin -d | grep telegram + pidgin -d diff --git a/tg-cli.c b/tg-cli.c new file mode 100755 index 0000000..b73eff8 --- /dev/null +++ b/tg-cli.c @@ -0,0 +1,59 @@ +#include +#include "mtproto-common.h" +#include "tg-cli.h" +#include "msglog.h" + +/* + * Events + */ + +/* + * New message received + */ +void (*on_msg_handler)(struct message *M); +void on_update_new_message(void (*on_msg)(struct message *M)) { + on_msg_handler = on_msg; +} +void event_update_new_message(struct message *M) { + if (on_msg_handler) { + on_msg_handler(M); + } +} + +/* + * User allocated + */ +void (*on_user_allocated_handler)(peer_t *user); +void on_user_allocated(void (*handler)(peer_t *user)) { + on_user_allocated_handler = handler; +} +void event_user_allocated(peer_t *user) { + if (on_user_allocated_handler) { + on_user_allocated_handler(user); + } +} + +/* + * Chat allocated + */ +void (*on_chat_allocated_handler)(peer_t *chat); +void on_chat_allocated(void (*handler)(peer_t *chat)) { + on_chat_allocated_handler = handler; +} +void event_chat_allocated(peer_t *chat) { + if (on_chat_allocated_handler) { + on_chat_allocated_handler(chat); + } +} + +// template +//void (*on_blarg_handler)(type); +//void on_blarg(void (*handler)(type)) { +// on_blarg_handler = handler; +//} +//void event_blarg(type) { +// if (on_blarg_handler) { +// on_blarg_handler(type); +// } +//} +