int loop (void) { tgl_set_callback (TLS, &upd_cb); struct event_base *ev = event_base_new (); tgl_set_ev_base (TLS, ev); tgl_set_net_methods (TLS, &tgl_conn_methods); tgl_set_timer_methods (TLS, &tgl_libevent_timers); assert (TLS->timer_methods); tgl_set_download_directory (TLS, get_downloads_directory ()); tgl_register_app_id (TLS, TELEGRAM_CLI_APP_ID, TELEGRAM_CLI_APP_HASH); tgl_set_app_version (TLS, "Telegram-cli " TELEGRAM_CLI_VERSION); if (ipv6_enabled) { tgl_enable_ipv6 (TLS); } if (bot_mode) { tgl_enable_bot (TLS); } if (disable_link_preview) { tgl_disable_link_preview (TLS); } tgl_init (TLS); if (binlog_enabled) { double t = tglt_get_double_time (); if (verbosity >= E_DEBUG) { logprintf ("replay log start\n"); } tgl_replay_log (TLS); if (verbosity >= E_DEBUG) { logprintf ("replay log end in %lf seconds\n", tglt_get_double_time () - t); } tgl_reopen_binlog_for_writing (TLS); } else { read_auth_file (); read_state_file (); read_secret_chat_file (); } binlog_read = 1; #ifdef USE_LUA lua_binlog_end (); #endif #ifdef USE_PYTHON py_binlog_end (); #endif if (sfd >= 0) { struct event *ev = event_new (TLS->ev_base, sfd, EV_READ | EV_PERSIST, accept_incoming, 0); event_add (ev, 0); } if (usfd >= 0) { struct event *ev = event_new (TLS->ev_base, usfd, EV_READ | EV_PERSIST, accept_incoming, 0); event_add (ev, 0); } update_prompt (); if (reset_authorization) { tgl_peer_t *P = tgl_peer_get (TLS, TGL_MK_USER (TLS->our_id)); if (P && P->user.phone && reset_authorization == 1) { set_default_username (P->user.phone); } bl_do_reset_authorization (TLS); } tgl_enable_pfs(TLS); set_interface_callbacks (); tgl_login (TLS); net_loop (); return 0; }
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) { fprintf (stderr, "Can not read config '%s': error '%s' on the line %d\n", config_filename, config_error_text (&conf), config_error_line (&conf)); exit (2); } if (!prefix) { config_lookup_string (&conf, "default_profile", (void *)&prefix); } static char buf[1000]; int l = 0; if (prefix) { l = strlen (prefix); memcpy (buf, prefix, l); buf[l ++] = '.'; } int test_mode = 0; strcpy (buf + l, "test"); config_lookup_bool (&conf, buf, &test_mode); if (test_mode) { tgl_set_test_mode (); } 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); } parse_config_val (&conf, &config_directory, "config_directory", CONFIG_DIRECTORY, 0); config_directory = make_full_path (config_directory); parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory); parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory); if (!lua_file) { parse_config_val (&conf, &lua_file, "lua_script", 0, config_directory); } strcpy (buf + l, "binlog_enabled"); config_lookup_bool (&conf, buf, &binlog_enabled); int pfs_enabled = 0; strcpy (buf + l, "pfs_enabled"); config_lookup_bool (&conf, buf, &pfs_enabled); if (pfs_enabled) { tgl_enable_pfs (); } if (binlog_enabled) { parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory); tgl_set_binlog_mode (1); tgl_set_binlog_path (binlog_file_name); } else { tgl_set_binlog_mode (0); parse_config_val (&conf, &state_file_name, "state_file", STATE_FILE, config_directory); parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory); //tgl_set_auth_file_path (auth_file_name); } tgl_set_download_directory (downloads_directory); if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) { if (!disable_output) { printf ("[%s] created\n", config_directory); } } if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) { if (!disable_output) { printf ("[%s] created\n", downloads_directory); } } config_destroy (&conf); }