diff --git a/.gitignore b/.gitignore index 3c8bc12..7345b6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ telegram *.o +*.so +*.a Makefile autom4te.cache config.h @@ -7,3 +9,5 @@ config.log config.status .idea/ nbproject/ +tags +.DS_Store diff --git a/Makefile.in b/Makefile.in index 200252c..0c1e907 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,7 +29,8 @@ telegram: ${OBJECTS} .c.o : ${CC} ${COMPILE_FLAGS} ${INCLUDE} -c $< -o $@ +libtg.a: ${OBJECTS} + ar rs $@ ${OBJECTS} clean: - rm -rf *.o telegram config.log config.status > /dev/null || echo "all clean" - + rm -rf *.a *.o telegram config.log config.status > /dev/null || echo "all clean" diff --git a/libtg.h b/libtg.h new file mode 100755 index 0000000..13b1fb5 --- /dev/null +++ b/libtg.h @@ -0,0 +1 @@ +int runtg (int argc, char **argv); diff --git a/main.c b/main.c index 44de05a..7f6f32a 100644 --- a/main.c +++ b/main.c @@ -92,7 +92,7 @@ int sync_from_start; int allow_weak_random; void set_default_username (const char *s) { - if (default_username) { + if (default_username) { tfree_str (default_username); } default_username = tstrdup (s); @@ -238,7 +238,7 @@ void running_for_first_time (void) { close (auth_file_fd); printf ("[%s] created\n", config_filename);*/ - + /* create downloads directory */ /*if (mkdir (downloads_directory, 0755) !=0) { perror ("creating download directory"); @@ -249,7 +249,7 @@ void running_for_first_time (void) { #ifdef HAVE_LIBCONFIG void parse_config_val (config_t *conf, char **s, char *param_name, const char *default_name, const char *path) { - static char buf[1000]; + static char buf[1000]; int l = 0; if (prefix) { l = strlen (prefix); @@ -277,7 +277,7 @@ void parse_config_val (config_t *conf, char **s, char *param_name, const char *d void parse_config (void) { config_filename = make_full_path (config_filename); - + config_t conf; config_init (&conf); if (config_read_file (&conf, config_filename) != CONFIG_TRUE) { @@ -299,12 +299,12 @@ void parse_config (void) { test_dc = 0; strcpy (buf + l, "test"); config_lookup_bool (&conf, buf, &test_dc); - + strcpy (buf + l, "log_level"); long long t = log_level; config_lookup_int (&conf, buf, (void *)&t); log_level = t; - + if (!msg_num_mode) { strcpy (buf + l, "msg_num"); config_lookup_bool (&conf, buf, &msg_num_mode); @@ -318,10 +318,10 @@ void parse_config (void) { parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory); parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory); parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory); - + strcpy (buf + l, "binlog_enabled"); config_lookup_bool (&conf, buf, &binlog_enabled); - + if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) { printf ("[%s] created\n", config_directory); } @@ -417,7 +417,7 @@ void args_parse (int argc, char **argv) { binlog_enabled = 1; break; case 'L': - if (log_net_file) { + if (log_net_file) { usage (); } log_net_file = tstrdup (optarg); @@ -460,7 +460,7 @@ void print_backtrace (void) { void sig_segv_handler (int signum __attribute__ ((unused))) { set_terminal_attributes (); - if (write (1, "SIGSEGV received\n", 18) < 0) { + if (write (1, "SIGSEGV received\n", 18) < 0) { // Sad thing } print_backtrace (); @@ -469,19 +469,19 @@ void sig_segv_handler (int signum __attribute__ ((unused))) { void sig_abrt_handler (int signum __attribute__ ((unused))) { set_terminal_attributes (); - if (write (1, "SIGABRT received\n", 18) < 0) { + if (write (1, "SIGABRT received\n", 18) < 0) { // Sad thing } print_backtrace (); exit (EXIT_FAILURE); } -int main (int argc, char **argv) { +int runtg (int argc, char **argv) { signal (SIGSEGV, sig_segv_handler); signal (SIGABRT, sig_abrt_handler); log_level = 10; - + args_parse (argc, argv); printf ( "Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n" @@ -502,6 +502,6 @@ int main (int argc, char **argv) { #endif inner_main (); - + return 0; } diff --git a/telegram-purple.c b/purple-plugin/telegram-purple.c similarity index 97% rename from telegram-purple.c rename to purple-plugin/telegram-purple.c index 33591e7..287ad80 100644 --- a/telegram-purple.c +++ b/purple-plugin/telegram-purple.c @@ -34,6 +34,8 @@ #include "util.h" #include "prpl.h" +#include + #define PLUGIN_ID "prpl-telegram" #define TELEGRAM_APP_API_ID 16944 @@ -90,31 +92,38 @@ static void tgprpl_tooltip_text(PurpleBuddy * buddy, PurpleNotifyUserInfo * info static void tgprpl_login(PurpleAccount * acct) { purple_debug_info(PLUGIN_ID, "tgprpl_login()\n"); + + purple_debug_info(PLUGIN_ID, "calling runtg()\n"); + runtg(0, NULL); + purple_debug_info(PLUGIN_ID, "returned from runtg()\n"); + + /* PurpleConnection *gc = purple_account_get_connection(acct); const char *username = purple_account_get_username(acct); const char *sms_key = purple_account_get_string(acct, "sms_key", ""); const char *hostname = purple_account_get_string(acct, "server", TELEGRAM_TEST_SERVER); - int port = purple_account_get_int(acct, "port", TELEGRAM_DEFAULT_PORT); + int port = purple_account_get_int(acct, "port", TELEGRAM_DEFAULT_PORT); purple_debug_info(PLUGIN_ID, "logging in %s\n", username); - if (sms_key[0] == "") { + if (strcmp(sms_key[0], "")) { purple_debug_info(PLUGIN_ID, "no sms key -> send sms key request\n"); } - purple_debug_info(PLUGIN_ID, "Connect\n"); + purple_debug_info(PLUGIN_ID, "Connect\n"); purple_connection_update_progress(gc, "Connecting", 0, 4); telegram_conn *conn; conn = g_new0(telegram_conn, 1); conn->gc = gc; - conn->account = acct; + conn->account = acct; purple_connection_set_protocol_data(gc, conn); gc->proto_data = conn; purple_connection_set_state(gc, PURPLE_CONNECTED); - purple_debug_info(PLUGIN_ID, "Connected\n"); + purple_debug_info(PLUGIN_ID, "Connected\n"); + */ } @@ -273,12 +282,12 @@ static GList *tgprpl_status_types(PurpleAccount * acct) types = g_list_prepend(types, type); type = purple_status_type_new_with_attrs(PURPLE_STATUS_AWAY, "unavailable", NULL, TRUE, TRUE, FALSE, "message", "Message", purple_value_new(PURPLE_TYPE_STRING), NULL); - types = g_list_prepend(types, type); + types = g_list_prepend(types, type); - type = purple_status_type_new(PURPLE_STATUS_OFFLINE, NULL, NULL, TRUE); - types = g_list_append(types, type); + type = purple_status_type_new(PURPLE_STATUS_OFFLINE, NULL, NULL, TRUE); + types = g_list_append(types, type); - return g_list_reverse(types); + return g_list_reverse(types); } static void tgprpl_set_status(PurpleAccount * acct, PurpleStatus * status) @@ -550,5 +559,4 @@ static PurplePluginInfo info = { NULL // reserved }; - PURPLE_INIT_PLUGIN(telegram, init_plugin, info) diff --git a/telegram.png b/purple-plugin/telegram.png similarity index 100% rename from telegram.png rename to purple-plugin/telegram.png diff --git a/telegram.svg b/purple-plugin/telegram.svg similarity index 100% rename from telegram.svg rename to purple-plugin/telegram.svg diff --git a/telegram16.png b/purple-plugin/telegram16.png similarity index 100% rename from telegram16.png rename to purple-plugin/telegram16.png diff --git a/telegram22.png b/purple-plugin/telegram22.png similarity index 100% rename from telegram22.png rename to purple-plugin/telegram22.png diff --git a/telegram48.png b/purple-plugin/telegram48.png similarity index 100% rename from telegram48.png rename to purple-plugin/telegram48.png