2014-08-21 18:02:43 -04:00
|
|
|
/*
|
|
|
|
This file is part of tgl-library
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Copyright Vitaly Valtman 2014
|
|
|
|
*/
|
|
|
|
|
2014-08-13 08:56:55 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "tgl.h"
|
2014-08-14 14:03:33 -04:00
|
|
|
#include "tools.h"
|
|
|
|
#include "mtproto-client.h"
|
2014-08-20 18:33:19 -04:00
|
|
|
#include "structures.h"
|
2014-08-15 10:57:43 -04:00
|
|
|
#include "net.h"
|
2014-08-14 14:03:33 -04:00
|
|
|
|
|
|
|
#include <event2/event.h>
|
2014-08-14 18:16:01 -04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2014-08-13 08:56:55 -04:00
|
|
|
struct tgl_state tgl_state;
|
|
|
|
|
2014-08-13 21:31:24 -04:00
|
|
|
|
|
|
|
void tgl_set_binlog_mode (int mode) {
|
|
|
|
tgl_state.binlog_enabled = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tgl_set_binlog_path (const char *path) {
|
|
|
|
tgl_state.binlog_name = tstrdup (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tgl_set_auth_file_path (const char *path) {
|
|
|
|
tgl_state.auth_file = tstrdup (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tgl_set_download_directory (const char *path) {
|
|
|
|
tgl_state.downloads_directory = tstrdup (path);
|
|
|
|
}
|
2014-08-14 14:03:33 -04:00
|
|
|
|
|
|
|
void tgl_set_callback (struct tgl_update_callback *cb) {
|
|
|
|
tgl_state.callback = *cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tgl_set_rsa_key (const char *key) {
|
2014-08-21 18:02:43 -04:00
|
|
|
assert (tgl_state.rsa_key_num < TGL_MAX_RSA_KEYS_NUM);
|
|
|
|
tgl_state.rsa_key_list[tgl_state.rsa_key_num ++] = tstrdup (key);
|
2014-08-14 14:03:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void tgl_init (void) {
|
|
|
|
tgl_state.ev_base = event_base_new ();
|
2014-08-15 10:57:43 -04:00
|
|
|
|
|
|
|
if (!tgl_state.net_methods) {
|
|
|
|
tgl_state.net_methods = &tgl_conn_methods;
|
|
|
|
}
|
2014-08-20 18:33:19 -04:00
|
|
|
if (!tgl_state.callback.create_print_name) {
|
|
|
|
tgl_state.callback.create_print_name = tgls_default_create_print_name;
|
|
|
|
}
|
2014-08-21 18:02:43 -04:00
|
|
|
tglmp_on_start ();
|
2014-08-14 14:03:33 -04:00
|
|
|
}
|
2014-08-15 10:57:43 -04:00
|
|
|
|
2014-08-20 23:24:52 -04:00
|
|
|
int tgl_authorized_dc (struct tgl_dc *DC) {
|
2014-08-15 10:57:43 -04:00
|
|
|
assert (DC);
|
|
|
|
return DC->auth_key_id;
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:24:52 -04:00
|
|
|
int tgl_signed_dc (struct tgl_dc *DC) {
|
2014-08-15 10:57:43 -04:00
|
|
|
assert (DC);
|
|
|
|
return DC->has_auth;
|
|
|
|
}
|
2014-08-20 21:56:53 -04:00
|
|
|
|