Compare commits

..

205 commits

Author SHA1 Message Date
Vysheng
5ec9a88872 Fixed loop.c 2014-09-24 14:35:27 +04:00
Vysheng
4f7778c8e9 fixes in bignum padding 2014-09-23 19:06:20 +04:00
Vysheng
6f60ed5818 mtproto-client: fixed bad bignum pad 2014-09-23 18:59:28 +04:00
Vysheng
ef37551f04 Fixed readline_disable mode 2014-09-23 18:39:28 +04:00
Vysheng
39819d2eb9 Some more clear 2014-09-23 17:18:42 +04:00
Vysheng
a0a3361d7d Fixed small memory leaks. Added functions to clear most part of data 2014-09-23 16:58:49 +04:00
vysheng
998b89d124 Update CHANGELOG 2014-09-23 12:37:57 +04:00
vvaltman
8eeac24783 Merge github.com:vysheng/tg 2014-09-23 02:23:54 +04:00
vvaltman
95a9edbd8a Support for unix sockets 2014-09-23 02:23:40 +04:00
vysheng
508d23cebc Update test.lua 2014-09-22 22:52:35 +04:00
Vysheng
dc27be5eae Updated test.lua. Libnotify use example 2014-09-22 17:41:51 +04:00
vvaltman
4440f5b80e Small bugfixes 2014-09-22 01:00:46 +04:00
vvaltman
7c32c52116 Make get_state once per hour 2014-09-21 14:13:40 +04:00
vvaltman
05e1606d03 Fixes for listening socket 2014-09-21 13:41:10 +04:00
vvaltman
d577731f98 fixes for libevent 1.4 2014-09-21 13:25:46 +04:00
vvaltman
7a0fdd7f35 Fixed CE with old libevent 2014-09-21 13:18:12 +04:00
vvaltman
990221ea4d Fixed CE on some systems 2014-09-21 13:10:22 +04:00
vvaltman
11e6e19272 Fixed missing include on some systems 2014-09-21 13:07:06 +04:00
vvaltman
76e7c8fd38 updated CHANGELOG 2014-09-21 12:59:47 +04:00
vvaltman
02b37e503e Fixes in refcnt 2014-09-21 12:58:57 +04:00
vvaltman
db85bf4836 Added listening socket support 2014-09-21 02:22:35 +04:00
vvaltman
48e96f3a7a test-lua: updated with sample cron function 2014-09-18 21:16:27 +04:00
Vysheng
9d40537345 updated changelog 2014-09-18 19:16:26 +04:00
Vysheng
53e9491914 increased version 2014-09-18 19:15:47 +04:00
Vysheng
997116ff43 Fixed search 2014-09-18 19:14:24 +04:00
Vysheng
3fcfe6fc3b Fix get difference after reset_authorization 2014-09-18 18:36:43 +04:00
Vysheng
82dad2b1f4 Fixed geo in lua 2014-09-18 18:11:22 +04:00
Vysheng
65843d7695 Added reset authorization key 2014-09-18 17:57:23 +04:00
Vysheng
3a7da2d67b Fixed help 2014-09-18 17:10:42 +04:00
Vysheng
d56cd2e2cb Fixed escape string 2014-09-18 14:42:02 +04:00
Vysheng
35f90fd0b9 Merge github.com:vysheng/tg 2014-09-18 14:11:36 +04:00
Vysheng
5c2f7d688e Fixed small memory leaks 2014-09-18 14:11:23 +04:00
vvaltman
a6af86a266 rewitten input parse 2014-09-18 01:03:20 +04:00
Vysheng
0326dbf69e Merge github.com:vysheng/tg 2014-09-15 18:48:04 +04:00
vvaltman
c9a0346971 Run get_differece on new_session_created 2014-09-15 12:45:17 +04:00
Vysheng
9488f56f4b Deleted bad def 2014-09-12 19:58:47 +04:00
vvaltman
8bdaf6e55b Fixed send_photo to encr chats 2014-09-12 00:57:59 +04:00
vvaltman
efebedc08a Fixed escape of string 2014-09-11 19:47:44 +04:00
vvaltman
1896b2b905 Merge github.com:vysheng/tg 2014-09-11 19:30:10 +04:00
vvaltman
3e868b4249 Fixed problems with send_msg on start 2014-09-11 19:29:16 +04:00
vysheng
342a7f323c Update README.md 2014-09-11 16:05:25 +04:00
vysheng
4e55083b41 Update README.es 2014-09-11 15:54:40 +04:00
Vysheng
324221f5de support for set_ttl query 2014-09-11 15:04:04 +04:00
Vysheng
ecc1ef02f5 Deleted unneeded code 2014-09-11 14:33:12 +04:00
Vysheng
a240e3536b Changed default DC. Fixed memory leak 2014-09-11 14:28:56 +04:00
Vysheng
56b30ac358 Fixed memory leak 2014-09-11 13:35:27 +04:00
Vysheng
a7e0f25a6a Check return values of malloc, realloc, strdup and strndup 2014-09-11 13:24:06 +04:00
Vysheng
51b3f5295b Fixed fail when trying to send emssage before get_difference end 2014-09-10 21:54:41 +04:00
Vysheng
01746fe177 Merge github.com:vysheng/tg 2014-09-10 21:36:25 +04:00
Vysheng
f9528ff627 Fixed check_utf8 2014-09-10 21:36:05 +04:00
Vysheng
c7a15630c6 Fixed extended_functions mode. Small memory leak there. Should be fixed shorly. 2014-09-10 21:29:57 +04:00
vysheng
595346391e Update README.md 2014-09-10 18:38:46 +04:00
Vysheng
2cd6465440 ext_f added to lua. fixed del_contact from lua 2014-09-10 18:25:31 +04:00
Vysheng
ba10513786 del_contact query 2014-09-10 18:13:52 +04:00
Vysheng
dd4e757ea5 Fixed strange warn about unused result of strtod and strtoll 2014-09-10 16:25:49 +04:00
Vysheng
da451e6436 Added support for direct queries enter 2014-09-10 15:52:42 +04:00
vvaltman
9f90a325b7 Increased version 2014-09-10 01:02:50 +04:00
vvaltman
41287c13d7 added SIGUSR1 handler to rotate logs 2014-09-10 01:01:22 +04:00
vvaltman
6b9ce8a2b6 Added scripts to help run telegram as daemon 2014-09-10 00:47:34 +04:00
Vysheng
47ef058f84 Merge github.com:vysheng/tg
Conflicts:
	main.c
2014-09-09 22:07:30 +04:00
Vysheng
dfc0578302 Added -U and -G keys to make setuid and setgid at start if started as root 2014-09-09 22:05:56 +04:00
vvaltman
1c46ba8e3a Added [-D] (disable output) key 2014-09-09 21:05:36 +04:00
vvaltman
8f84df8789 Fixed rsa pad 2014-09-09 20:50:07 +04:00
Vysheng
55ce5bac99 Fixed config search 2014-09-09 19:10:01 +04:00
Vysheng
db4d36c8b6 Daemonize options 2014-09-09 19:01:27 +04:00
Vysheng
d3f2ac2eba Merge github.com:vysheng/tg 2014-09-09 17:28:05 +04:00
Vysheng
4e35360aff status function to lua 2014-09-09 17:27:43 +04:00
vysheng
1d58448e19 Update README.md 2014-09-09 17:11:37 +04:00
Vysheng
30656e49be deleted debug 2014-09-09 16:03:35 +04:00
Vysheng
5539d232d5 Fixed __builtin config 2014-09-09 15:58:47 +04:00
Vysheng
74de6b24d1 Merge github.com:vysheng/tg 2014-09-09 15:53:19 +04:00
vysheng
22e9f7778d Merge pull request #253 from corsaroquad/patch-1
Included MacPorts commands
2014-09-09 15:55:13 +04:00
Vysheng
bb1fd17d08 Debug 2014-09-09 15:52:58 +04:00
Giovanni Grieco
bfe3d140b3 Included MacPorts commands
Included solution to build correctly telegram-cli if using MacPorts on OS X.
Details: https://github.com/vysheng/tg/issues/237#issuecomment-54955961
2014-09-09 13:39:01 +02:00
Vysheng
e6efa4097c Support for compilers without __builtin_bswap32 2014-09-09 15:34:59 +04:00
Vysheng
9eef9444d5 Fixed get history 2014-09-09 15:05:30 +04:00
Vysheng
6d2fa85b70 Merge github.com:vysheng/tg 2014-09-09 15:02:57 +04:00
vvaltman
6074086de6 Support for big history 2014-09-09 00:09:05 +04:00
vvaltman
ff805e1140 Fixed set of real_name of uninitialezed user 2014-09-08 23:18:51 +04:00
vvaltman
b15ea055d0 Merge github.com:vysheng/tg 2014-09-08 23:18:02 +04:00
vvaltman
da201171ab Updated test.lua 2014-09-08 23:17:47 +04:00
Vysheng
8b558db00b Fixed crush on real_name update for unknown user 2014-09-08 20:55:22 +04:00
Vysheng
d28209e3d1 Fixed rare crush in case of multiple query answers 2014-09-08 20:48:59 +04:00
Vysheng
c9ed692d24 increased version 2014-09-08 17:35:00 +04:00
Vysheng
5369423e3c Fixed event-1.4 2014-09-08 17:33:33 +04:00
Vysheng
6d8deb9135 Added _GNU_SOURCE for strndup 2014-09-08 17:05:41 +04:00
Vysheng
3dd341a08f Added attribute unused 2014-09-08 17:02:59 +04:00
Vysheng
34b81ab400 Try to build with libevent-1.4 2014-09-08 16:49:51 +04:00
Vysheng
fac3ddf2d8 Fixes for old libevent 2014-09-08 16:40:35 +04:00
Vysheng
613867fb09 Try to fix net 2014-09-08 15:56:12 +04:00
vvaltman
7ac53571d2 Fixed CE 2014-09-08 01:50:19 +04:00
vvaltman
743cc4b3f3 Fixed double send of one message 2014-09-08 00:23:45 +04:00
vvaltman
176d19fc4b Merge github.com:vysheng/tg 2014-09-07 23:13:13 +04:00
vvaltman
8f50bab9f0 Try to add support of libevent 1.4.* 2014-09-07 23:12:39 +04:00
vvaltman
3871561c09 Fixed updates 2014-09-07 22:44:19 +04:00
vvaltman
44a8a813c8 Fixed lua media types 2014-09-07 19:30:46 +04:00
vvaltman
2e7d468397 Fixed configure. Added fwd_media command 2014-09-07 19:17:35 +04:00
vvaltman
56f31ae3be Merge github.com:vysheng/tg 2014-09-04 20:50:13 +04:00
vvaltman
62cefe5a8e Fixed parse of create_group_chat 2014-09-04 20:48:04 +04:00
vysheng
91871043b1 Merge pull request #242 from nopjmp/fix_rand_bytes
fixed RAND_bytes return code checking
2014-09-04 15:13:49 +04:00
nopjmp
66d35aea76 fixed RAND_bytes return code checking 2014-09-03 19:39:42 -05:00
Vysheng
a245f86dd5 Fixed chat_info 2014-09-03 20:32:56 +04:00
vysheng
8d923387ba Update README.md 2014-09-03 20:02:50 +04:00
Vysheng
05f6824de7 changed user#... to user#id... 2014-09-03 19:54:50 +04:00
Vysheng
e113d3469b Merge github.com:vysheng/tg 2014-09-03 19:15:57 +04:00
Vysheng
a60ae1ae93 Fixed CE on MACH 2014-09-03 19:15:39 +04:00
vysheng
6a5b001de7 Merge pull request #241 from wiseoldman95/patch-1
Added Debian to installation instructions
2014-09-03 19:03:07 +04:00
wiseoldman95
6d8f975567 Added Debian.
The Ubuntu instructions work for Debian. See https://github.com/vysheng/tg/issues/128
2014-09-03 17:28:37 +03:00
Vysheng
017851107c Fixed mark_read 2014-09-03 17:25:35 +04:00
Vysheng
ad6a38454e Merge github.com:vysheng/tg 2014-09-03 17:06:18 +04:00
Vysheng
f4f4be579e Mark read messages from not peers 2014-09-03 17:05:48 +04:00
vysheng
523fa3f6d5 Update README.md 2014-09-03 14:33:45 +04:00
vysheng
ce462d4a70 Update README.md 2014-09-03 13:54:51 +04:00
Vysheng
6937fa0bee Fixed CE 2014-09-03 13:49:38 +04:00
Vysheng
d2ac430c9c Fixed bad assertion. Maybe fixed MACH CE 2014-09-03 13:39:28 +04:00
Vysheng
6c9d18cacf Fixed bad assertion 2014-09-03 13:31:39 +04:00
Vysheng
6fb56f1496 Supported user#id... and chat#id... from lua 2014-09-02 16:22:32 +04:00
Vysheng
c711019ea8 Added send_contact function 2014-09-02 15:20:18 +04:00
Vysheng
784db14d6a Added dependence to Makefile 2014-09-02 14:32:25 +04:00
Vysheng
306c571794 Fixed chat_add_user/chat_del_user queries 2014-09-02 14:27:23 +04:00
Vysheng
e0782b77a3 Added dependences to Makefile 2014-09-02 14:23:22 +04:00
Vysheng
0e13277938 Fixed params types in create_group_chat 2014-09-02 14:22:26 +04:00
vysheng
1814b2f581 Update README.md 2014-08-31 20:51:57 +01:00
vysheng
5731386848 Update README.md 2014-08-31 20:51:41 +01:00
vvaltman
c840b636c3 Fixed secert_chat_file read 2014-08-31 21:24:39 +04:00
vvaltman
f51f3b4da3 Fixed CE on 32-bit platforms 2014-08-31 21:19:56 +04:00
vvaltman
c1fa31c3d7 Fixed fail on startup 2014-08-31 21:15:49 +04:00
vvaltman
8ce965f045 Updated to layer 16 2014-08-31 18:57:03 +04:00
vvaltman
d5109e2545 support for secret chats file in no-binlog mode 2014-08-31 18:18:19 +04:00
vvaltman
c7bd5587ff Added changlog. increased version 2014-08-31 14:04:16 +04:00
vvaltman
d44dfa859d Fail on error 2014-08-31 14:02:00 +04:00
vvaltman
4b3c936cd4 Added export_card/import_card queries 2014-08-29 19:46:04 +04:00
vvaltman
92c9d0d7f0 generate random_id with secure_random 2014-08-29 18:04:04 +04:00
vvaltman
63605c7971 clear ack flag when session is renewed 2014-08-29 17:50:05 +04:00
vvaltman
4fb3d3503b Fixes small bug in query resend while changing session 2014-08-29 17:48:47 +04:00
vvaltman
548f4fe997 Added PFS support. Parallel auth_key generation. Small bug fixes 2014-08-29 17:33:15 +04:00
vvaltman
13313af979 Fixed encrypted chat updates. 2014-08-27 20:59:42 +04:00
vvaltman
d954f87514 added accept_secret_chat 2014-08-27 19:40:21 +04:00
vvaltman
654df2c05c fixed bug in crc32 2014-08-27 19:40:04 +04:00
vvaltman
a7b8b1286c Fixed work with updates 2014-08-27 19:12:45 +04:00
vvaltman
5e653e85c8 Fixed assert after hibernate 2014-08-27 03:17:28 +04:00
vvaltman
d39193f2f7 fixed get difference 2014-08-27 02:10:52 +04:00
vvaltman
cdb6b9cec5 debug output 2014-08-27 02:02:19 +04:00
vvaltman
c66d07ce35 Fixed updates work 2014-08-27 01:55:46 +04:00
vvaltman
050560ece9 Merge branch 'test' of github.com:vysheng/tg into test 2014-08-27 01:16:19 +04:00
vysheng
abdae6a6f7 Update README.md 2014-08-27 20:15:58 +04:00
vvaltman
8fd05fdba4 Fixed name 2014-08-27 01:06:59 +04:00
vvaltman
3bf992f0cb Fixed visualize key in nocolor output mode. 2014-08-27 01:03:50 +04:00
vvaltman
ecc239e291 Added disable_readline. Do not try read stdin, after end of stdin reached 2014-08-26 22:26:00 +04:00
vvaltman
d67fc774bf Fixed seq 2014-08-26 20:57:30 +04:00
vvaltman
29d06e6d1e Updated test lua script 2014-08-26 20:30:30 +04:00
vvaltman
e5534b6545 Added lua readme 2014-08-26 20:26:01 +04:00
vvaltman
152ebc3898 Updates in lua callbacks 2014-08-26 20:06:30 +04:00
vvaltman
1bd7d2cfad Fixed updates 2014-08-26 00:48:22 +04:00
vvaltman
eb4e9055b7 Some fixes in updates 2014-08-25 22:26:19 +04:00
vvaltman
82e9e0b09d More logic in autocompletion. Added set_chat_photo and set_profile_photo methods 2014-08-25 20:17:17 +04:00
vvaltman
8b2aec9703 Fixed bug with short updates 2014-08-25 18:12:17 +04:00
vvaltman
fef8398860 Fixed problems with read mark. Deleted unused code 2014-08-25 18:04:27 +04:00
vvaltman
ca34ddd404 Fixed chat_add_user query 2014-08-25 05:11:03 +04:00
vvaltman
6f711aa1fb Fixed args parse 2014-08-25 04:54:12 +04:00
vvaltman
cf7e7b45bb interface updates 2014-08-25 04:11:41 +04:00
vvaltman
93cb32a43f Updated ebuild 2014-08-25 02:40:54 +04:00
vvaltman
b083e80dc7 Fixed bug in set_friend() 2014-08-24 20:49:06 +04:00
vvaltman
ab5b9c306f Fixed licenses. libtgl is now distributed under LGPL 2.1+ 2014-08-22 02:02:43 +04:00
vvaltman
29d2e32912 Updated unread notification 2014-08-22 00:35:27 +04:00
V Valtman
e2e18c9f34 Fixes with awk and upper case 2014-08-22 13:49:11 +00:00
Vysheng
e7b04da661 Fixed small error 2014-08-22 16:30:28 +04:00
Vysheng
c97cba7e9e added attribute unused 2014-08-22 16:27:16 +04:00
Vysheng
021db46dc4 Fixed awk 2014-08-22 16:18:15 +04:00
Vysheng
cfca590a30 added more debug 2014-08-22 16:13:21 +04:00
Vysheng
1cd379abd0 debug to travis.yml 2014-08-22 16:09:52 +04:00
Vysheng
6d56f4ac6b Fixed dependence list 2014-08-22 16:00:33 +04:00
Vysheng
3c1d61bf26 Fixes travis.tml 2014-08-22 15:52:48 +04:00
Vysheng
e7d554dc81 Fixed gentoo ebuild 2014-08-22 15:50:21 +04:00
Vysheng
3ae872010e fix queries_num 2014-08-22 15:45:16 +04:00
vvaltman
07b1646423 Merge branch 'test' of github.com:vysheng/tg 2014-08-21 07:25:09 +04:00
vvaltman
0299a6375d changes 2014-08-21 07:24:52 +04:00
vvaltman
ec15b4b1b6 Merge branch 'test' of github.com:vysheng/tg 2014-08-21 06:06:46 +04:00
vysheng
e58ff46e96 Update README.md 2014-08-21 22:43:14 +01:00
vvaltman
8c58fb7f00 fixes 2014-08-21 05:56:53 +04:00
vvaltman
bd4e59b6ab updates 2014-08-21 02:33:19 +04:00
Vysheng
45778cffdf fixes 2014-08-21 20:28:01 +04:00
Vysheng
3b58fed8e4 updates 2014-08-21 19:38:51 +04:00
vvaltman
64981ad777 Merge branch 'master' of adm239:tg
Conflicts:
	interface.c
	tgl.h
2014-08-20 20:41:56 +04:00
vvaltman
311489b168 Fixes 2014-08-20 20:36:45 +04:00
Vysheng
52b5a2d3ce fixes 2014-08-19 16:57:55 +04:00
vvaltman
d08a64a481 updates 2014-08-18 20:39:04 +04:00
vvaltman
b1cbaa5105 many fixes 2014-08-15 02:16:01 +04:00
Vysheng
e0ded4a86c fixes 2014-08-15 18:57:43 +04:00
Vysheng
4a48059e8a many updates 2014-08-14 22:03:33 +04:00
vysheng
3dde03db86 more code 2014-08-14 01:31:24 +00:00
Vysheng
3b5458de54 fixes 2014-08-13 19:55:16 +04:00
Vysheng
cb95039f51 Some refactoring 2014-08-13 16:56:55 +04:00
Vysheng
bc1648a7c7 renamed user_chat_get to peer_get 2014-08-13 14:09:52 +04:00
vysheng
ddbe7ba88c Mant fixes. Sometimes work now 2014-08-13 01:22:15 +00:00
vysheng
c05bb2683e Some renaming 2014-08-12 21:51:16 +00:00
vysheng
143d672884 A bit working version 2014-08-12 21:32:11 +00:00
Vysheng
c34e6a3abe Fixes 2014-08-12 22:05:18 +04:00
vvaltman
fc8a20b74c fixes 2014-08-12 01:15:22 +04:00
Vysheng
7741fe8da9 many changes 2014-08-12 19:15:04 +04:00
Vysheng
30f949ee75 Fixed build options. Updated gitignore 2014-08-12 16:29:42 +04:00
Vysheng
474a76a010 many fixes. Autogenerated code probably works 2014-08-12 16:20:00 +04:00
vysheng
a8fae1278f Updates 2014-08-12 09:59:59 +00:00
Vysheng
9b622ba083 temp 2014-08-11 22:04:59 +04:00
Vysheng
74b05dbf8e files for new version 2014-08-11 19:27:34 +04:00
202 changed files with 32009 additions and 21600 deletions

25
.gitignore vendored
View file

@ -1,11 +1,14 @@
/objs/
/autom4te.cache/
/config.h
*~
/dep/
/libs/
/bin/
/config.log
/config.status
/Makefile
/commit.h
telegram
*.o
Makefile
autom4te.cache
config.h
config.log
config.status
.idea/
nbproject/
bin/
objs/
dep/
auto/
libs/

4
.gitmodules vendored
View file

@ -1,4 +0,0 @@
[submodule "tgl"]
path = tgl
branch = test
url = https://github.com/majn/tgl

View file

@ -1,48 +1,16 @@
language: c
# Select Trusty Tahr.
sudo: required
dist: trusty
# Travis' git submodule support is ... broken? half-broken? Maybe intentional?
git:
submodules: false
depth: 3
before_install:
- git submodule update --init --recursive
- sudo apt-get update -qq
- sudo apt-get install -qq libssl-dev libgcrypt20-dev libpurple-dev libwebp-dev
script:
- ./configure $CONFIGURE_FLAGS
- make -j2
- make check
compiler:
- clang
- gcc
env:
# Try to be nice to the builder
- CONFIGURE_FLAGS=""
- CONFIGURE_FLAGS="--disable-gcrypt"
- CONFIGURE_FLAGS=" --disable-libwebp"
# - CONFIGURE_FLAGS="--disable-gcrypt --disable-libwebp"
- CONFIGURE_FLAGS=" --disable-translation"
# - CONFIGURE_FLAGS="--disable-gcrypt --disable-translation"
# - CONFIGURE_FLAGS=" --disable-libwebp --disable-translation"
- CONFIGURE_FLAGS="--disable-gcrypt --disable-libwebp --disable-translation"
matrix:
# Be even nicer by excluding half of the combinations
exclude:
- compiler: clang
env: CONFIGURE_FLAGS=""
- compiler: gcc
env: CONFIGURE_FLAGS="--disable-gcrypt"
- compiler: clang
env: CONFIGURE_FLAGS=" --disable-libwebp"
# - compiler: XXX
# env: CONFIGURE_FLAGS="--disable-gcrypt --disable-libwebp"
- compiler: gcc
env: CONFIGURE_FLAGS=" --disable-translation"
# - compiler: clang
# env: CONFIGURE_FLAGS="--disable-gcrypt --disable-translation"
# - compiler: gcc
# env: CONFIGURE_FLAGS=" --disable-libwebp --disable-translation"
- compiler: clang
env: CONFIGURE_FLAGS="--disable-gcrypt --disable-libwebp --disable-translation"
- clang
install:
- sudo apt-get install libconfig8-dev
- sudo apt-get install libreadline6-dev
- sudo apt-get install libssl-dev
- sudo apt-get install liblua5.2-dev lua5.2
- sudo apt-get install libevent-dev
script:
- ./configure
- make

View file

@ -1,4 +0,0 @@
Matthias Jentsch <mtthsjntsch@gmail.com>
Ben Wiederhake <Ben.Wiederhake@gmail.com>
Vitaly Valtman <vvaltman@aurum>
Christopher Althaus <althaus.christopher@gmail.com>

View file

@ -1,45 +0,0 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Ben Wiederhake 2016
# This file is NOT meant for inclusion into the main Makefile.
LOCALES=$(shell cat po/LINGUAS)
LOCALE_MOS=$(addprefix po/,$(addsuffix .mo,$(LOCALES)))
# Hardcoded, since this should only be run on very few machines anyway,
# which are expected to have msgfmt on their $PATH
MSGFMT_PATH=msgfmt
all: translate
po/%.mo: po/%.po
${MSGFMT_PATH} -cf -o $@ $<
po/telegram-purple.metainfo.xml.pot: telegram-purple.metainfo.untranslated.xml as-metainfo.its
itstool -i as-metainfo.its -o $@ $<
# CAREFUL WHEN EDITING!
# "-j raw.xml *.mo" must be the last options!
telegram-purple.metainfo.xml: as-metainfo.its telegram-purple.metainfo.untranslated.xml $(LOCALE_MOS) po/LINGUAS
itstool -i as-metainfo.its -o $@ \
-j telegram-purple.metainfo.untranslated.xml $(LOCALE_MOS)
.PHONY: potfile
potfile: po/telegram-purple.metainfo.xml.pot
.PHONY: translate
translate: telegram-purple.metainfo.xml

View file

@ -1,23 +0,0 @@
<!-- Copyright © 2012-2015 Matthias Klumpp.
This material may only be distributed subject to the terms and
conditions set forth in the GNU Free Documentation License (GFDL),
V1.2 with no invariant sections or later (the latest version is
presently available at http://www.gnu.org/licenses/fdl.txt).
This file bases on the "Quickstart Translation using itstool":
http://www.freedesktop.org/software/appstream/docs/sect-Quickstart-Translation.html
The copyright for the base transformer was found at:
http://www.freedesktop.org/software/appstream/docs/index.html
-->
<its:rules
xmlns:its="http://www.w3.org/2005/11/its"
version="1.0">
<its:translateRule translate="no" selector="/component"/>
<its:translateRule translate="yes"
selector="/component/name |
/component/summary |
/component/description |
/component/screenshots/screenshot/caption |
/component/developer_name"/>
</its:rules>

View file

@ -1 +0,0 @@
/*.mo

View file

@ -1,12 +0,0 @@
bg
cs_CZ
de_DE
es
es_AR
fr
it_IT
nl
pl_PL
ru_RU
sq
uk

View file

@ -1,25 +0,0 @@
#
# Translators:
# Любомир Василев, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-10-19 14:07+0000\n"
"Last-Translator: Любомир Василев\n"
"Language-Team: Bulgarian (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/bg/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: bg\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Добавка, която добавя поддръжка на Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Jan Breuer <j123b567@jaybee.cz>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-02-18 14:45+0000\n"
"Last-Translator: Jan Breuer <j123b567@jaybee.cz>\n"
"Language-Team: Czech (Czech Republic) (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/cs_CZ/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: cs_CZ\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Zásuvný modul, který přidá podporu pro Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Ben Wiederhake <BenWiederhake.GitHub@gmx.de>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-01-09 13:14+0000\n"
"Last-Translator: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>\n"
"Language-Team: German (Germany) (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/de_DE/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: de_DE\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Plugin zur Unterstützung von Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# aguador <aguador@openmailbox.org>, 2017
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2017-02-27 09:08+0000\n"
"Last-Translator: aguador <aguador@openmailbox.org>\n"
"Language-Team: Spanish (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Un plugin que añade soporte para Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# KNTRO <kntro@msn.com>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-10-08 19:37+0000\n"
"Last-Translator: KNTRO <kntro@msn.com>\n"
"Language-Team: Spanish (Argentina) (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/es_AR/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: es_AR\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Un plugin que agrega soporte para Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Javier Sixto, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-04-14 19:51+0000\n"
"Last-Translator: Javier Sixto\n"
"Language-Team: French (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/fr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Une extension qui ajoute le support pour Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Giuseppe Pignataro (Fasbyte01) <rogepix@gmail.com>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2017-02-27 09:08+0000\n"
"Last-Translator: Giuseppe Pignataro (Fasbyte01) <rogepix@gmail.com>\n"
"Language-Team: Italian (Italy) (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/it_IT/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: it_IT\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Un plugin che aggiunge il supporto per Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# justin [notsupplied] <inactive+justin50@transifex.com>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-10-19 17:56+0000\n"
"Last-Translator: justin [notsupplied] <inactive+justin50@transifex.com>\n"
"Language-Team: Dutch (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/nl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: nl\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Een plug-in die ondersteuning voor Telegram toevoegt"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Piotr Drąg <piotrdrag@gmail.com>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2017-02-27 09:08+0000\n"
"Last-Translator: Piotr Drąg <piotrdrag@gmail.com>\n"
"Language-Team: Polish (Poland) (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/pl_PL/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: pl_PL\n"
"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && (n%100<12 || n%100>=14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Wtyczka dodająca obsługę protokołu Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Vladimir <TurbaVladimir@yandex.ru>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-02-18 14:45+0000\n"
"Last-Translator: Vladimir <TurbaVladimir@yandex.ru>\n"
"Language-Team: Russian (Russia) (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/ru_RU/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ru_RU\n"
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Плагин, добавляющий поддержку Telegram"

View file

@ -1,25 +0,0 @@
#
# Translators:
# Besnik <besnik@programeshqip.org>, 2016
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2016-02-18 14:45+0000\n"
"Last-Translator: Besnik <besnik@programeshqip.org>\n"
"Language-Team: Albanian (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/sq/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: sq\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Telegram"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Një shtojcë që shton mbulim për Telegram-in"

View file

@ -1,21 +0,0 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr ""
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr ""

View file

@ -1,25 +0,0 @@
#
# Translators:
# Самохвалов Антон <samant.ua@mail.ru>, 2017
msgid ""
msgstr ""
"Project-Id-Version: telegram-purple\n"
"POT-Creation-Date: 2016-01-07 23:23+0100\n"
"PO-Revision-Date: 2017-03-04 06:36+0000\n"
"Last-Translator: Самохвалов Антон <samant.ua@mail.ru>\n"
"Language-Team: Ukrainian (http://www.transifex.com/telegram-purple-developers/telegram-purple/language/uk/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: uk\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#. (itstool) path: component/name
#: telegram-purple.metainfo.untranslated.xml:9
msgid "Telegram"
msgstr "Телеграм"
#. (itstool) path: component/summary
#: telegram-purple.metainfo.untranslated.xml:10
msgid "A plugin that adds support for Telegram"
msgstr "Плагін, що додає підтримку у Телеграм"

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 Jiri Eischmann <eischmann@redhat.com>
It is very important that this file does *not* receive any
Invariant Sections as per GFDL.
-->
<component type="addon">
<id>telegram-purple</id>
<extends>pidgin.desktop</extends>
<name>Telegram</name>
<summary>A plugin that adds support for Telegram</summary>
<url type="homepage">https://github.com/majn/telegram-purple</url>
<url type="bugtracker">https://github.com/majn/telegram-purple/issues/</url>
<metadata_license>GFDL-1.3</metadata_license>
<project_license>GPL-2.0+</project_license>
<update_contact>eischmann_at_redhat.com</update_contact>
</component>

View file

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 Jiri Eischmann <eischmann@redhat.com>
It is very important that this file does *not* receive any
Invariant Sections as per GFDL.
-->
<component type="addon">
<id>telegram-purple</id>
<extends>pidgin.desktop</extends>
<name>Telegram</name>
<name xml:lang="bg">Telegram</name>
<name xml:lang="cs-CZ">Telegram</name>
<name xml:lang="de-DE">Telegram</name>
<name xml:lang="es">Telegram</name>
<name xml:lang="es-AR">Telegram</name>
<name xml:lang="fr">Telegram</name>
<name xml:lang="it-IT">Telegram</name>
<name xml:lang="nl">Telegram</name>
<name xml:lang="pl-PL">Telegram</name>
<name xml:lang="ru-RU">Telegram</name>
<name xml:lang="sq">Telegram</name>
<name xml:lang="uk">Телеграм</name>
<summary>A plugin that adds support for Telegram</summary>
<summary xml:lang="bg">Добавка, която добавя поддръжка на Telegram</summary>
<summary xml:lang="cs-CZ">Zásuvný modul, který přidá podporu pro Telegram</summary>
<summary xml:lang="de-DE">Plugin zur Unterstützung von Telegram</summary>
<summary xml:lang="es">Un plugin que añade soporte para Telegram</summary>
<summary xml:lang="es-AR">Un plugin que agrega soporte para Telegram</summary>
<summary xml:lang="fr">Une extension qui ajoute le support pour Telegram</summary>
<summary xml:lang="it-IT">Un plugin che aggiunge il supporto per Telegram</summary>
<summary xml:lang="nl">Een plug-in die ondersteuning voor Telegram toevoegt</summary>
<summary xml:lang="pl-PL">Wtyczka dodająca obsługę protokołu Telegram</summary>
<summary xml:lang="ru-RU">Плагин, добавляющий поддержку Telegram</summary>
<summary xml:lang="sq">Një shtojcë që shton mbulim për Telegram-in</summary>
<summary xml:lang="uk">Плагін, що додає підтримку у Телеграм</summary>
<url type="homepage">https://github.com/majn/telegram-purple</url>
<url type="bugtracker">https://github.com/majn/telegram-purple/issues/</url>
<metadata_license>GFDL-1.3</metadata_license>
<project_license>GPL-2.0+</project_license>
<update_contact>eischmann_at_redhat.com</update_contact>
</component>

13
CHANGELOG Normal file
View file

@ -0,0 +1,13 @@
1.0.5
* listening socket (tcp and unix) for commands
1.0.4
* changed create_group_chat format
* changed search query
* rewritten interface code. Support for escaped characters in quotes
1.0.3
* options to help to run telegram-cli as daemon
1.0.2
* Bug fixes
1.0.1
* Added pfs support. To use it you should add 'pfs_enabled=true' line to config.
* Added export_card/import_card methods

View file

@ -1,156 +0,0 @@
Changelog
---------
##### 1.3.1
- Stability improvements
- Support auto-loading for documents
- Add support for "typing" in group chats (using group-typing-notifications plugin)
- Add support for /kick command in group chats
##### 1.3.0
- channel/supergroup support
- support sending code tags in markdown "backtick" format (see README for example)
- reduce amount of file-transfer popups in Pidgin, auto-load media in the background
- fix stability issues for the win32 build
- fix multiple crashes in libtgl
##### 1.2.6
- Include libtgl bugfix "use-after-not-created for photos"
- Fix Adium bundle version incompatibillity for newest version
##### 1.2.5
- Include libtgl fix to prevent crashes on certain channel messages
- Improve error handling to be more graceful
##### 1.2.4
- Fix crash on unknown media type
- Fix crash on logout after cancelling a file transfer
##### 1.2.3
- Build: Allow compilation on Windows #52 Thanks Eion!
- Build: Drop dependency on LodePNG, Thanks Ben!
- Build: Gettext is now optional
- Fix issue that prevented to send messages to deleted users in certain cases (#174)
- Fix own user being added to the buddy list in certain cases
- Fix that read recipes of own messages are being displayed (#139)
- Fix encoding inconsistencies with Unicode characters (#177)
- Fix auto-joining for chats (#179)
- Fix client not reconnecting anymore under certain circumstances (#173)
- Fix crash on compat-verification (PullRequest #183)
- Remove pointless "create chat" confirmation dialogue
- Improve logging messages
- Always send read recipes when the user is typing or sending a message
- Improve translation and user messages (#139)
- Use native password prompts (Adium)
##### 1.2.2
- fix some licensing issues by not depending on OpenSSL any longer (thanks Ben!)
- add tons of translations (thanks to anyone helping!)
- fix issue that caused empty files
- fix pidgin not reconnecting after hibernation
- fix adium not reconnecting after hibernation
- fix secret chat fingerprint not being displayed after restart
- fix secret chat name not being displayed after restart
##### 1.2.1
##### Bugfixes
- Fix buggy group chat handling
* Assure that foreign users are always listed by their full name instead of the user ID
* Don't automatically add group chats to buddy list to prevent incompatibillities with some libpurple clients
* Fix issue that caused the buddy list to not be correctly updated on joining / leaving participants
* Fix an issue that caused the user list to be printed on every group chat message in Finch
- Fetch chat information lazily to reduce traffic and prevent flood errors
- Improve input validation for phone numbers
###### Features
- Support leaving chats
- Implement the roomlist-API to allow listing of all active chats
##### Version 1.2.0 (Beta 3)
##### Bugfixes
- Fix error in incoming message handling that caused segmentation faults
- Fix failing audio and video transfers
- Mark messages read on other devices as 'deferred' to avoid needless notifications
- Improved buddy list handling (should avoid "unknown" contacts popping up)
- Many small issues (see commit history)
- Fix issues that caused audio and video downloads to not have a proper file ending
- Fix issue that caused very old unused chats to not be available
###### Features
- Allow creation of new group chats
- Allow joining chats by invite link
- Allow exporting chats by invite link
- Support displaying and sending GIFs
- Support joining chats by invite link
##### Version 1.1.0 (Beta 2)
- update to libtgl 2
- support two-factor authentication
- improve sticker support
- add option to control message read recipes
- many bugfixes
##### Version 1.0.0 (Beta 1)
- Move state files into .purple/telegram-purple directory
- Add extended account settings for controlling history and read notifications
- Improved support for Adium
* fix chat bookmarking
* add custom views for account settings and chat joining
##### Version 0.7
- Support uploads and downloads (with some caveats though):
* Uploads wont contain the current file name but a generic one
* Every file is uploaded as a document or picture, so unfortunately no embedded videos and audio (right now)
* Group chats only support picture uploads since nothing else is supported by the UI
- Fix HTML escaping issues
##### Version 0.6.1
- Fix many stability issues
- Do not readd left chats on login
##### Version 0.6
- Support for secret chats
- Receiving geo messages
##### Version 0.5
- Display incoming photos
- Respect received user and chat property updates
- Support changing own profile picture
- Support adding new contacts
- Display service messages
- Works with libpurple proxy settings
##### TODO:
- Picture Uploads
- Audio, Video and File Transfers

View file

@ -1,38 +0,0 @@
# Hacking on the build system
This list was previously maintained as [issue #242](https://github.com/majn/telegram-purple/issues/242), until we realized that this needs proper version-control. (Duh!)
## Exhaustive list of requirements on the build system:
1. `commit.h` must change whenever it disagrees with the current git commit
1. `commit.h` must not change whenever it agrees with the current git commit
1. Must call `cd tgl && ./configure` with appropriate options whenever `tgl/Makefile` is missing, or notices that `./configure` was run. ("Too often" is acceptable as long as `make && make` isn't violated.)
1. Must call `make -C tgl` whenever this might have any effect. ("Too often" is acceptable as long as `make && make` isn't violated.)
1. Any changes due to `make -C tgl` must cause all necessary rebuilds in telegram-purple during the same invocation of make. ("Too often" is acceptable as long as `make && make` isn't violated.)
1. If `tgl/Makefile.in` is missing, explain that we need submodules, and stop.
1. `make -j12` must work fine
1. Must support out-of-CVS builds.
## While ensuring that:
- Must not `-include tgl/Makefile` as it doesn't really support that, and I'm not going to try and convince @vysheng to do that. Also, it's too fragile. You know how he ticks.
- `make && make` must not create any files in the second run (otherwise, `sudo make install` would become hairy)
- Compatibility with other makes
## Approach:
- `commit.h` is a regular file which depends on a .PHONY target `commit`. Building `commit.h` *only* touches `commit.h` if necessary and possible. (=> 1, 2, half of 8)
- Have a target `tgl/Makefile` which depends on `Makefile`. (=> 3)
- The central target `${PRPL_LIBNAME}` shall depend on the .PHONY `submade`, which depends on `tgl/Makefile`, and essentially executes `make -C tgl`. (=> 4, time constraint of 5)
- All objects of telegram-purple depend on `tgl/libs/libtgl.a`. Rationale: if `tgl/libs/libtgl.a` stays the same, then nothing in tgl changed. If `tgl/libs/libtgl.a` changes, then due to lots of black preprocessor magic within tgl, it can't be safely determined which, if any, objects of telegram-purple can be re-used. Also, if tgl got recompiled (~ 1 minute), then tgp can be recompiled, too (~ 5 seconds). (=> dependency constraint of 5)
- Let `tgl/Makefile` depend on `tgl/Makefile.in`, and put the warning into the rule for the latter. (=> 6)
- The above already implies a dependency DAG that is completely known to make; except at one point: let `tgl/libs/libtgl.a` depend on `submade`, without any own code. Now make ensure thread-safety on it's own. (=> 7)
- Bundle commit.h into the origtar (=> other half of 8)
## Side effects:
- Should be ultimately robust. Then again, that's what I thought about the last few attempts, and they didn't last long.
- This reduces the number of .PHONYs drastically, making it easier to read, and making it easier to prove that `make && make` doesn't change anything.
- Even though `submade` should trigger once and only once, this can handle multiple invocations just fine, too.
- All files dependent on `commit.h` need to be mentioned explicitly as dependents in the Makefile. This is ugly, but (as far as I can see) unavoidable. Thankfully, any errors here will get detected by automated testing.
- We currently use only one GNU make specific extension. See https://github.com/majn/telegram-purple/issues/137#issuecomment-167970054

View file

@ -1,20 +0,0 @@
# Contributing
This is Open Source Software. We realized that we didn't pass the Patch Test
## What to contribute
Here's a few places to start:
- Report any bugs you find.
- No, seriously! Most of the bugs don't even get reported, or the reporter only writes "Doesn't work for me" and then vanishes.
- ["help wanted" issues](https://github.com/majn/telegram-purple/issues?utf8=%E2%9C%93&q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+-label%3A%22in-pipeline%22), especially automated testing
- ["secret chat" issues](https://github.com/majn/telegram-purple/issues?utf8=%E2%9C%93&q=is%3Aopen+is%3Aissue+label%3A%22secret+chats%22+-label%3A%22in-pipeline%22+)
- Portability (especially endianness) of tgl (external project)
- [Issues of tgl](https://github.com/vysheng/tgl/issues) -- lots and lots of false or obsolete reports
- Slim down the size of the generated files in `tgl/auto`, as this currently dominates the build time. Yuk!
- Make sure that the libpurple-devs don't break libpurple any further.
## How to contribute
Write [an issue](https://github.com/majn/telegram-purple/issues/new), shoot us a mail (scrape the address from the git history), or contact us in dev chat (changing URL, see README for that).

View file

339
LICENSE.h Normal file
View file

@ -0,0 +1,339 @@
" GNU GENERAL PUBLIC LICENSE\n"
" Version 2, June 1991\n"
"\n"
" Copyright (C) 1989, 1991 Free Software Foundation, Inc.,\n"
" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
" Everyone is permitted to copy and distribute verbatim copies\n"
" of this license document, but changing it is not allowed.\n"
"\n"
" Preamble\n"
"\n"
" The licenses for most software are designed to take away your\n"
"freedom to share and change it. By contrast, the GNU General Public\n"
"License is intended to guarantee your freedom to share and change free\n"
"software--to make sure the software is free for all its users. This\n"
"General Public License applies to most of the Free Software\n"
"Foundation's software and to any other program whose authors commit to\n"
"using it. (Some other Free Software Foundation software is covered by\n"
"the GNU Lesser General Public License instead.) You can apply it to\n"
"your programs, too.\n"
"\n"
" When we speak of free software, we are referring to freedom, not\n"
"price. Our General Public Licenses are designed to make sure that you\n"
"have the freedom to distribute copies of free software (and charge for\n"
"this service if you wish), that you receive source code or can get it\n"
"if you want it, that you can change the software or use pieces of it\n"
"in new free programs; and that you know you can do these things.\n"
"\n"
" To protect your rights, we need to make restrictions that forbid\n"
"anyone to deny you these rights or to ask you to surrender the rights.\n"
"These restrictions translate to certain responsibilities for you if you\n"
"distribute copies of the software, or if you modify it.\n"
"\n"
" For example, if you distribute copies of such a program, whether\n"
"gratis or for a fee, you must give the recipients all the rights that\n"
"you have. You must make sure that they, too, receive or can get the\n"
"source code. And you must show them these terms so they know their\n"
"rights.\n"
"\n"
" We protect your rights with two steps: (1) copyright the software, and\n"
"(2) offer you this license which gives you legal permission to copy,\n"
"distribute and/or modify the software.\n"
"\n"
" Also, for each author's protection and ours, we want to make certain\n"
"that everyone understands that there is no warranty for this free\n"
"software. If the software is modified by someone else and passed on, we\n"
"want its recipients to know that what they have is not the original, so\n"
"that any problems introduced by others will not reflect on the original\n"
"authors' reputations.\n"
"\n"
" Finally, any free program is threatened constantly by software\n"
"patents. We wish to avoid the danger that redistributors of a free\n"
"program will individually obtain patent licenses, in effect making the\n"
"program proprietary. To prevent this, we have made it clear that any\n"
"patent must be licensed for everyone's free use or not licensed at all.\n"
"\n"
" The precise terms and conditions for copying, distribution and\n"
"modification follow.\n"
"\n"
" GNU GENERAL PUBLIC LICENSE\n"
" TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
"\n"
" 0. This License applies to any program or other work which contains\n"
"a notice placed by the copyright holder saying it may be distributed\n"
"under the terms of this General Public License. The \"Program\", below,\n"
"refers to any such program or work, and a \"work based on the Program\"\n"
"means either the Program or any derivative work under copyright law:\n"
"that is to say, a work containing the Program or a portion of it,\n"
"either verbatim or with modifications and/or translated into another\n"
"language. (Hereinafter, translation is included without limitation in\n"
"the term \"modification\".) Each licensee is addressed as \"you\".\n"
"\n"
"Activities other than copying, distribution and modification are not\n"
"covered by this License; they are outside its scope. The act of\n"
"running the Program is not restricted, and the output from the Program\n"
"is covered only if its contents constitute a work based on the\n"
"Program (independent of having been made by running the Program).\n"
"Whether that is true depends on what the Program does.\n"
"\n"
" 1. You may copy and distribute verbatim copies of the Program's\n"
"source code as you receive it, in any medium, provided that you\n"
"conspicuously and appropriately publish on each copy an appropriate\n"
"copyright notice and disclaimer of warranty; keep intact all the\n"
"notices that refer to this License and to the absence of any warranty;\n"
"and give any other recipients of the Program a copy of this License\n"
"along with the Program.\n"
"\n"
"You may charge a fee for the physical act of transferring a copy, and\n"
"you may at your option offer warranty protection in exchange for a fee.\n"
"\n"
" 2. You may modify your copy or copies of the Program or any portion\n"
"of it, thus forming a work based on the Program, and copy and\n"
"distribute such modifications or work under the terms of Section 1\n"
"above, provided that you also meet all of these conditions:\n"
"\n"
" a) You must cause the modified files to carry prominent notices\n"
" stating that you changed the files and the date of any change.\n"
"\n"
" b) You must cause any work that you distribute or publish, that in\n"
" whole or in part contains or is derived from the Program or any\n"
" part thereof, to be licensed as a whole at no charge to all third\n"
" parties under the terms of this License.\n"
"\n"
" c) If the modified program normally reads commands interactively\n"
" when run, you must cause it, when started running for such\n"
" interactive use in the most ordinary way, to print or display an\n"
" announcement including an appropriate copyright notice and a\n"
" notice that there is no warranty (or else, saying that you provide\n"
" a warranty) and that users may redistribute the program under\n"
" these conditions, and telling the user how to view a copy of this\n"
" License. (Exception: if the Program itself is interactive but\n"
" does not normally print such an announcement, your work based on\n"
" the Program is not required to print an announcement.)\n"
"\n"
"These requirements apply to the modified work as a whole. If\n"
"identifiable sections of that work are not derived from the Program,\n"
"and can be reasonably considered independent and separate works in\n"
"themselves, then this License, and its terms, do not apply to those\n"
"sections when you distribute them as separate works. But when you\n"
"distribute the same sections as part of a whole which is a work based\n"
"on the Program, the distribution of the whole must be on the terms of\n"
"this License, whose permissions for other licensees extend to the\n"
"entire whole, and thus to each and every part regardless of who wrote it.\n"
"\n"
"Thus, it is not the intent of this section to claim rights or contest\n"
"your rights to work written entirely by you; rather, the intent is to\n"
"exercise the right to control the distribution of derivative or\n"
"collective works based on the Program.\n"
"\n"
"In addition, mere aggregation of another work not based on the Program\n"
"with the Program (or with a work based on the Program) on a volume of\n"
"a storage or distribution medium does not bring the other work under\n"
"the scope of this License.\n"
"\n"
" 3. You may copy and distribute the Program (or a work based on it,\n"
"under Section 2) in object code or executable form under the terms of\n"
"Sections 1 and 2 above provided that you also do one of the following:\n"
"\n"
" a) Accompany it with the complete corresponding machine-readable\n"
" source code, which must be distributed under the terms of Sections\n"
" 1 and 2 above on a medium customarily used for software interchange; or,\n"
"\n"
" b) Accompany it with a written offer, valid for at least three\n"
" years, to give any third party, for a charge no more than your\n"
" cost of physically performing source distribution, a complete\n"
" machine-readable copy of the corresponding source code, to be\n"
" distributed under the terms of Sections 1 and 2 above on a medium\n"
" customarily used for software interchange; or,\n"
"\n"
" c) Accompany it with the information you received as to the offer\n"
" to distribute corresponding source code. (This alternative is\n"
" allowed only for noncommercial distribution and only if you\n"
" received the program in object code or executable form with such\n"
" an offer, in accord with Subsection b above.)\n"
"\n"
"The source code for a work means the preferred form of the work for\n"
"making modifications to it. For an executable work, complete source\n"
"code means all the source code for all modules it contains, plus any\n"
"associated interface definition files, plus the scripts used to\n"
"control compilation and installation of the executable. However, as a\n"
"special exception, the source code distributed need not include\n"
"anything that is normally distributed (in either source or binary\n"
"form) with the major components (compiler, kernel, and so on) of the\n"
"operating system on which the executable runs, unless that component\n"
"itself accompanies the executable.\n"
"\n"
"If distribution of executable or object code is made by offering\n"
"access to copy from a designated place, then offering equivalent\n"
"access to copy the source code from the same place counts as\n"
"distribution of the source code, even though third parties are not\n"
"compelled to copy the source along with the object code.\n"
"\n"
" 4. You may not copy, modify, sublicense, or distribute the Program\n"
"except as expressly provided under this License. Any attempt\n"
"otherwise to copy, modify, sublicense or distribute the Program is\n"
"void, and will automatically terminate your rights under this License.\n"
"However, parties who have received copies, or rights, from you under\n"
"this License will not have their licenses terminated so long as such\n"
"parties remain in full compliance.\n"
"\n"
" 5. You are not required to accept this License, since you have not\n"
"signed it. However, nothing else grants you permission to modify or\n"
"distribute the Program or its derivative works. These actions are\n"
"prohibited by law if you do not accept this License. Therefore, by\n"
"modifying or distributing the Program (or any work based on the\n"
"Program), you indicate your acceptance of this License to do so, and\n"
"all its terms and conditions for copying, distributing or modifying\n"
"the Program or works based on it.\n"
"\n"
" 6. Each time you redistribute the Program (or any work based on the\n"
"Program), the recipient automatically receives a license from the\n"
"original licensor to copy, distribute or modify the Program subject to\n"
"these terms and conditions. You may not impose any further\n"
"restrictions on the recipients' exercise of the rights granted herein.\n"
"You are not responsible for enforcing compliance by third parties to\n"
"this License.\n"
"\n"
" 7. If, as a consequence of a court judgment or allegation of patent\n"
"infringement or for any other reason (not limited to patent issues),\n"
"conditions are imposed on you (whether by court order, agreement or\n"
"otherwise) that contradict the conditions of this License, they do not\n"
"excuse you from the conditions of this License. If you cannot\n"
"distribute so as to satisfy simultaneously your obligations under this\n"
"License and any other pertinent obligations, then as a consequence you\n"
"may not distribute the Program at all. For example, if a patent\n"
"license would not permit royalty-free redistribution of the Program by\n"
"all those who receive copies directly or indirectly through you, then\n"
"the only way you could satisfy both it and this License would be to\n"
"refrain entirely from distribution of the Program.\n"
"\n"
"If any portion of this section is held invalid or unenforceable under\n"
"any particular circumstance, the balance of the section is intended to\n"
"apply and the section as a whole is intended to apply in other\n"
"circumstances.\n"
"\n"
"It is not the purpose of this section to induce you to infringe any\n"
"patents or other property right claims or to contest validity of any\n"
"such claims; this section has the sole purpose of protecting the\n"
"integrity of the free software distribution system, which is\n"
"implemented by public license practices. Many people have made\n"
"generous contributions to the wide range of software distributed\n"
"through that system in reliance on consistent application of that\n"
"system; it is up to the author/donor to decide if he or she is willing\n"
"to distribute software through any other system and a licensee cannot\n"
"impose that choice.\n"
"\n"
"This section is intended to make thoroughly clear what is believed to\n"
"be a consequence of the rest of this License.\n"
"\n"
" 8. If the distribution and/or use of the Program is restricted in\n"
"certain countries either by patents or by copyrighted interfaces, the\n"
"original copyright holder who places the Program under this License\n"
"may add an explicit geographical distribution limitation excluding\n"
"those countries, so that distribution is permitted only in or among\n"
"countries not thus excluded. In such case, this License incorporates\n"
"the limitation as if written in the body of this License.\n"
"\n"
" 9. The Free Software Foundation may publish revised and/or new versions\n"
"of the General Public License from time to time. Such new versions will\n"
"be similar in spirit to the present version, but may differ in detail to\n"
"address new problems or concerns.\n"
"\n"
"Each version is given a distinguishing version number. If the Program\n"
"specifies a version number of this License which applies to it and \"any\n"
"later version\", you have the option of following the terms and conditions\n"
"either of that version or of any later version published by the Free\n"
"Software Foundation. If the Program does not specify a version number of\n"
"this License, you may choose any version ever published by the Free Software\n"
"Foundation.\n"
"\n"
" 10. If you wish to incorporate parts of the Program into other free\n"
"programs whose distribution conditions are different, write to the author\n"
"to ask for permission. For software which is copyrighted by the Free\n"
"Software Foundation, write to the Free Software Foundation; we sometimes\n"
"make exceptions for this. Our decision will be guided by the two goals\n"
"of preserving the free status of all derivatives of our free software and\n"
"of promoting the sharing and reuse of software generally.\n"
"\n"
" NO WARRANTY\n"
"\n"
" 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
"FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"
"OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
"PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
"OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
"MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"
"TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"
"PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
"REPAIR OR CORRECTION.\n"
"\n"
" 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
"WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
"REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
"INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
"OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
"TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
"YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
"PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
"POSSIBILITY OF SUCH DAMAGES.\n"
"\n"
" END OF TERMS AND CONDITIONS\n"
"\n"
" How to Apply These Terms to Your New Programs\n"
"\n"
" If you develop a new program, and you want it to be of the greatest\n"
"possible use to the public, the best way to achieve this is to make it\n"
"free software which everyone can redistribute and change under these terms.\n"
"\n"
" To do so, attach the following notices to the program. It is safest\n"
"to attach them to the start of each source file to most effectively\n"
"convey the exclusion of warranty; and each file should have at least\n"
"the \"copyright\" line and a pointer to where the full notice is found.\n"
"\n"
" <one line to give the program's name and a brief idea of what it does.>\n"
" Copyright (C) <year> <name of author>\n"
"\n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License along\n"
" with this program; if not, write to the Free Software Foundation, Inc.,\n"
" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n"
"\n"
"Also add information on how to contact you by electronic and paper mail.\n"
"\n"
"If the program is interactive, make it output a short notice like this\n"
"when it starts in an interactive mode:\n"
"\n"
" Gnomovision version 69, Copyright (C) year name of author\n"
" Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n"
" This is free software, and you are welcome to redistribute it\n"
" under certain conditions; type `show c' for details.\n"
"\n"
"The hypothetical commands `show w' and `show c' should show the appropriate\n"
"parts of the General Public License. Of course, the commands you use may\n"
"be called something other than `show w' and `show c'; they could even be\n"
"mouse-clicks or menu items--whatever suits your program.\n"
"\n"
"You should also get your employer (if you work as a programmer) or your\n"
"school, if any, to sign a \"copyright disclaimer\" for the program, if\n"
"necessary. Here is a sample; alter the names:\n"
"\n"
" Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n"
" `Gnomovision' (which makes passes at compilers) written by James Hacker.\n"
"\n"
" <signature of Ty Coon>, 1 April 1989\n"
" Ty Coon, President of Vice\n"
"\n"
"This General Public License does not permit incorporating your program into\n"
"proprietary programs. If your program is a subroutine library, you may\n"
"consider it more useful to permit linking proprietary applications with the\n"
"library. If this is what you want to do, use the GNU Lesser General\n"
"Public License instead of this License.\n"

View file

@ -1,234 +1,90 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Vitaly Valtman, Christopher Althaus, Markus Endres 2014-2015
srcdir=@srcdir@
prefix=@prefix@
datarootdir=@datarootdir@
localedir=@localedir@
gettext_package=@GETTEXT_PACKAGE@
CFLAGS=@CFLAGS@ @PURPLE_CFLAGS@ @DEFS@ -DENABLE_NLS -DLOCALEDIR='"$(localedir)"' -Wall -Wextra -Wno-deprecated-declarations -Wno-unused-parameter -I${srcdir} -I. -fno-strict-aliasing -fPIC -D_FORTIFY_SOURCE=2
LDFLAGS=@LDFLAGS@ @OPENSSL_LIBS@ @PURPLE_LIBS@ @LIBS@ -rdynamic -ggdb
DIR_PERM=0755
FILE_PERM=0644
CFLAGS=@CFLAGS@
LDFLAGS=@LDFLAGS@ @OPENSSL_LDFLAGS@
CPPFLAGS=@CPPFLAGS@ @OPENSSL_INCLUDES@
DEFS=@DEFS@
COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC
EXTRA_LIBS=@LIBS@ @EXTRA_LIBS@ @OPENSSL_LIBS@
LOCAL_LDFLAGS=-rdynamic -ggdb -levent ${EXTRA_LIBS}
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
DEP=${srcdir}/dep
AUTO=${srcdir}/auto
EXE=${srcdir}/bin
OBJ=${srcdir}/objs
LIB=${srcdir}/libs
DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto
EXE_LIST=${EXE}/generate ${EXE}/tlc ${EXE}/telegram-cli
LIB_LIST=${LIB}/libtgl.a
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o
TGL_OBJECTS=${OBJ}/net.o ${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/auto/auto.o ${OBJ}/tgl.o ${OBJ}/updates.o
TLC_OBJECTS=${OBJ}/tlc.o ${OBJ}/tl-parser.o ${OBJ}/crc32.o
GENERATE_OBJECTS=${OBJ}/generate.o
COMMON_OBJECTS=${OBJ}/tools.o
OBJ_LIST=${TG_OBJECTS} ${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS}
OBJ_C=${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS}
DEPENDENCE=$(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJ_LIST}))
DEPENDENCE_LIST=${DEPENDENCE}
INCLUDE=-I. -I${srcdir}
CC=@CC@
PKG_CONFIG=@PKG_CONFIG@
MSGFMT_PATH=@MSGFMT_PATH@
# Check if -fstack-protector-strong is supported before enabling it
SPUNSUPPORTED = $(shell $(CC) -fstack-protector-strong 2>&1 | grep -c 'stack-protector-strong')
ifeq "$(SPUNSUPPORTED)" "0"
CFLAGS += -fstack-protector-strong
endif
DEP=dep
EXE=bin
OBJ=objs
DIR_LIST=${DEP} ${EXE} ${OBJ}
PLUGIN_OBJECTS=${OBJ}/tgp-net.o ${OBJ}/tgp-timers.o ${OBJ}/msglog.o ${OBJ}/telegram-base.o ${OBJ}/telegram-purple.o ${OBJ}/tgp-2prpl.o ${OBJ}/tgp-structs.o ${OBJ}/tgp-utils.o ${OBJ}/tgp-chat.o ${OBJ}/tgp-ft.o ${OBJ}/tgp-msg.o ${OBJ}/tgp-request.o ${OBJ}/tgp-blist.o ${OBJ}/tgp-info.o
ALL_OBJS=${PLUGIN_OBJECTS}
ifdef MSGFMT_PATH
LOCALES=$(shell cat po/LINGUAS)
LOCALE_MOS=$(addprefix po/,$(addsuffix .mo,$(LOCALES)))
endif
.SUFFIXES:
.SUFFIXES: .c .h .o
PRPL_NAME=telegram-purple.so
PRPL_LIBNAME=${EXE}/${PRPL_NAME}
all: ${PRPL_LIBNAME} $(LOCALE_MOS)
PLUGIN_DIR_PURPLE=$(shell ${PKG_CONFIG} --variable=plugindir purple)
DATA_ROOT_DIR_PURPLE=$(shell ${PKG_CONFIG} --variable=datarootdir purple)
CRYPTO_FLAG=@CRYPTO_FLAG@
### == 'Magic' targets and infrastructure. == ###
# Here be dragons! See https://github.com/majn/telegram-purple/issues/242
# For the full list of requirements, goals, and rationale.
.PHONY: create_dirs
all: ${EXE_LIST} ${DIR_LIST} ${LIB_LIST}
create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h ${AUTO}/constants.h
create_dirs: ${DIR_LIST}
${DIR_LIST}:
@test -d $@ || mkdir -p $@
DEPENDENCE=$(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${ALL_OBJS}))
DEPENDENCE_LIST=${DEPENDENCE}
-include ${DEPENDENCE_LIST}
tgl/Makefile.in:
@echo "tgl/Makefile.in not found. Maybe you need to 'git submodule update --init --recursive' ?" && exit 1
${TG_OBJECTS} ${TGL_OBJECTS}: ${AUTO}/constants.h ${AUTO}/auto-header.h
tgl/Makefile: tgl/Makefile.in Makefile
cd tgl && ./configure -q ${CRYPTO_FLAG} --disable-extf CFLAGS="@CFLAGS@" LDFLAGS="@LDFLAGS@"
${TG_OBJECTS}: ${OBJ}/%.o: %.c | create_dirs_and_headers
${CC} ${INCLUDE} ${COMPILE_FLAGS} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
tgl/libs/libtgl.a: tgl/Makefile
+${MAKE} -C tgl libs/libtgl.a
${OBJ_C}: ${OBJ}/%.o: %.c | create_dirs
${CC} ${INCLUDE} ${COMPILE_FLAGS} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
.PHONY: commit
commit:
${EXE}/tlc: ${TLC_OBJECTS} ${COMMON_OBJECTS}
${CC} ${TLC_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@
# The *commands* for commit.h shall always be executed, but the
# *file* commit.h should only be considered to have changed in rare cases.
GIT_COMMIT=$(shell git rev-parse HEAD | cut -c1-10)
commit.h: commit
@./commit.h.gen
${EXE}/telegram-cli: ${TG_OBJECTS} ${COMMON_OBJECTS} ${LIB}/libtgl.a
${CC} ${TG_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -L${LIB} -l tgl -o $@
# Ugly, but necessary, because otherwise commit.h would not get generated:
test/loadtest.c: commit.h
${LIB}/libtgl.a: ${TGL_OBJECTS} ${COMMON_OBJECTS}
ar ruv $@ ${TGL_OBJECTS} ${COMMON_OBJECTS}
# Ugly, but necessary, because otherwise commit.h would not get generated:
telegram-purple.c: commit.h
${EXE}/generate: ${GENERATE_OBJECTS} ${COMMON_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@
${AUTO}/scheme.tlo: ${AUTO}/scheme.tl ${EXE}/tlc
${EXE}/tlc -e $@ ${AUTO}/scheme.tl
### == 'Normal' build. == ###
${AUTO}/scheme.tl: ${srcdir}/scheme.tl ${srcdir}/encrypted_scheme.tl ${srcdir}/binlog.tl ${srcdir}/append.tl | ${AUTO}
cat $^ > $@
${PLUGIN_OBJECTS}: ${OBJ}/%.o: ${srcdir}/%.c tgl/libs/libtgl.a | create_dirs
echo $@ && ${CC} ${CFLAGS} ${CPPFLAGS} -I ${srcdir}/tgl -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${AUTO}/scheme2.tl: ${AUTO}/scheme.tl ${EXE}/tlc
${EXE}/tlc -E ${AUTO}/scheme.tl 2> $@ || ( cat $@ && rm $@ && false )
po/%.mo: po/%.po
${MSGFMT_PATH} -cf -o $@ $< >/dev/null 2>&1
${AUTO}/auto.c: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate ${AUTO}/scheme.tlo > $@
${PRPL_LIBNAME}: ${PLUGIN_OBJECTS} tgl/libs/libtgl.a | create_dirs
${CC} -shared -o $@ $^ ${LDFLAGS}
${AUTO}/auto-header.h: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate -H ${AUTO}/scheme.tlo > $@
${AUTO}/constants.h: ${AUTO}/scheme2.tl ${srcdir}/gen_constants_h.awk
awk -f ${srcdir}/gen_constants_h.awk < $< > $@
### == noicon_{,un}install targets. Use only if you know that you don't need icons. Note that pidgin uses those files. == ###
clean:
rm -rf ${DIR_LIST} config.log config.status > /dev/null || echo "all clean"
.PHONY: noicon_install
noicon_install: $(PRPL_LIBNAME) $(LOCALE_MOS)
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(PLUGIN_DIR_PURPLE)
install -m $(FILE_PERM) $(PRPL_LIBNAME) $(DESTDIR)$(PLUGIN_DIR_PURPLE)/$(PRPL_NAME)
mkdir -m $(DIR_PERM) -p $(DESTDIR)/etc/telegram-purple
install -m $(FILE_PERM) tg-server.tglpub $(DESTDIR)/etc/telegram-purple/server.tglpub
# Assume that the user does not use AppStream if she doesn't want icons
@for lang in $(LOCALES); do \
mkdir -p $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES; \
echo "installing po/$$lang.mo to $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo"; \
install -m $(FILE_PERM) po/$$lang.mo $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo; \
done
.PHONY: noicon_uninstall
noicon_uninstall:
rm -f $(DESTDIR)$(PLUGIN_DIR_PURPLE)/$(PRPL_NAME)
rm -f $(DESTDIR)/etc/telegram-purple/server.pub # TODO: Remove this in later versions
rm -f $(DESTDIR)/etc/telegram-purple/server.tglpub
# TODO: Delete all installed .mo's, no matter what LINGUAS says.
@for lang in $(LOCALES); do \
echo "removing $(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo"; \
rm -f $(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo; \
done
### == Main {,un}install targets. This should satisfy most needs. == ###
.PHONY: install
install: noicon_install
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/16
install -m $(FILE_PERM) imgs/telegram16.png $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/16/telegram.png
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/22
install -m $(FILE_PERM) imgs/telegram22.png $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/22/telegram.png
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/48
install -m $(FILE_PERM) imgs/telegram48.png $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/48/telegram.png
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(datarootdir)/appdata
install -m $(FILE_PERM) AppStream/telegram-purple.metainfo.xml $(DESTDIR)$(datarootdir)/appdata/telegram-purple.metainfo.xml
.PHONY: uninstall
uninstall: noicon_uninstall
rm -f $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/16/telegram.png
rm -f $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/22/telegram.png
rm -f $(DESTDIR)$(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/48/telegram.png
rm -f $(DESTDIR)$(datarootdir)/appdata/telegram-purple.metainfo.xml
### == The local_{,un}install targets, in case you're not root. == ###
.PHONY: local_install
local_install:
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(HOME)/.purple/plugins
install -m $(FILE_PERM) $(PRPL_LIBNAME) $(DESTDIR)$(HOME)/.purple/plugins/$(PRPL_NAME)
# See telegram-base.c, function get_user_pk_path for justification:
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(HOME)/.purple/telegram-purple
install -m $(FILE_PERM) tg-server.tglpub $(DESTDIR)$(HOME)/.purple/telegram-purple/server.tglpub
.PHONY: local_uninstall
local_uninstall:
rm -f $(DESTDIR)$(HOME)/.purple/plugins/$(PRPL_NAME)
rm -f $(DESTDIR)$(HOME)/.purple/telegram-purple/server.tglpub
### == Handling and maintenance. Subject to rapid change, shouldn't be used in scripts. == ###
.PHONY: plugin
plugin: $(PRPL_LIBNAME)
.PHONY: strip
strip: $(PRPL_LIBNAME)
$(STRIP) --strip-unneeded $(PRPL_LIBNAME)
.PHONY: build-nsi
build-nsi: telegram-purple.nsi.awk telegram-purple.nsi.awk-in
awk -f telegram-purple.nsi.awk telegram-purple.nsi.awk-in > telegram-purple.nsi
.PHONY: run
run:
pidgin -d | grep 'telegram\|plugin\|proxy'
.PHONY: debug
debug: install
ddd pidgin
DIST_ERR_MSG="Working directory is not git clean.\
Run 'git status' to show what files are causing this.\
Please note that 'make dist' packages the state in git, not the one on your disk."
SUBMOD_ERR_MSG="Couldn't find tgl/tl-parser/tl-parser.c\
Are all submodules properly initialized and updated?"
# Not PHONY
.git:
@echo "Not in a git folder. Features that require git are disabled."; exit 1
.PHONY: check-clean
check-clean: .git
@test "x" = x"`git status --porcelain`" || (echo ${DIST_ERR_MSG}; exit 1)
@test -r tgl/tl-parser/.git || (echo ${SUBMOD_ERR_MSG}; exit 1)
# Feel free to remove the "check-clean" dependency if you know what you're doing.
.PHONY: dist
dist: check-clean commit.h .git create_dirs
./gen-origtar
### == Cleaning in various flavors == ###
.PHONY: clean-here
clean-here:
rm -rf ${DIR_LIST} $(PRPL_LIBNAME) po/*.mo autom4te.cache AppStream/po/*.mo
-include test/Makefile
.PHONY: clean
clean: clean-here clean-test tgl/Makefile
+${MAKE} -C tgl clean

View file

@ -1,173 +0,0 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Vitaly Valtman, Christopher Althaus, Markus Endres, Eion Robb 2014-2015
srcdir=.
gettext_package=telegram-purple
PURPLE_VERSION = 2.10.11
PIDGIN_TREE_TOP := ../pidgin-$(PURPLE_VERSION)
WIN32_DEV_TOP = $(PIDGIN_TREE_TOP)/../win32-dev
MAKENSIS ?= "$(PROGRAMFILES)/NSIS/makensis.exe"
PLUGIN_VERSION ?= 1.2.2
GMSGFMT ?= $(WIN32_DEV_TOP)/gettext-0.17/bin/msgfmt
CFLAGS=-I$(WIN32_DEV_TOP)/libgcrypt-1.6.3/include -I$(WIN32_DEV_TOP)/libgpg-error-1.12-2/include -I$(WIN32_DEV_TOP)/glib-2.28.8/include -I$(WIN32_DEV_TOP)/glib-2.28.8/include/glib-2.0 -I$(WIN32_DEV_TOP)/glib-2.28.8/lib/glib-2.0/include -I$(PIDGIN_TREE_TOP)/libpurple -I$(WIN32_DEV_TOP)/libwebp-0.4.3-1/include -DHAVE_CONFIG_H -DENABLE_NLS -DPACKAGE_VERSION='"$(PLUGIN_VERSION)"' -Wall -Wextra -Werror -Wno-deprecated-declarations -Wno-unused-parameter -I${srcdir} -I. -fno-strict-aliasing
LDFLAGS=-L$(WIN32_DEV_TOP)/libgcrypt-1.6.3/lib -L$(WIN32_DEV_TOP)/libwebp-0.4.3-1/lib -L$(WIN32_DEV_TOP)/gettext-0.18/bin -L$(PIDGIN_TREE_TOP)/libpurple -L$(WIN32_DEV_TOP)/glib-2.28.8/lib -lpurple -lintl -lglib-2.0 -lwebp -lz -lgcrypt -Wl,--export-all-symbols -ggdb -lws2_32 -static-libgcc
DIR_PERM=0755
FILE_PERM=0644
CC = $(WIN32_DEV_TOP)/mingw/bin/gcc
PKG_CONFIG=
DEP=dep
EXE=bin
OBJ=objs
LIB=libs
DIR_LIST=${DEP} ${EXE} ${OBJ} ${LIB} ${DEP}/lodepng ${OBJ}/lodepng
PLUGIN_OBJECTS=${OBJ}/tgp-net.o ${OBJ}/tgp-timers.o ${OBJ}/msglog.o ${OBJ}/telegram-base.o ${OBJ}/telegram-purple.o ${OBJ}/tgp-2prpl.o ${OBJ}/tgp-structs.o ${OBJ}/tgp-utils.o ${OBJ}/tgp-chat.o ${OBJ}/tgp-ft.o ${OBJ}/tgp-msg.o ${OBJ}/tgp-request.o ${OBJ}/tgp-blist.o ${OBJ}/lodepng/lodepng.o
ALL_OBJS=${PLUGIN_OBJECTS} ${OBJ}/tgp-info.o
LOCALES=$(patsubst %.po, %.mo, $(wildcard po/*.po))
.SUFFIXES:
.SUFFIXES: .c .h .o
PRPL_NAME=libtelegram.dll
PRPL_LIBNAME=${EXE}/${PRPL_NAME}
all: ${PRPL_LIBNAME} ${LOCALES}
PLUGIN_DIR_PURPLE="$(PROGRAMFILES)/Pidgin/plugins"
DATA_ROOT_DIR_PURPLE="$(PROGRAMFILES)/Pidgin"
COPY_ICONS=yes
localedir=$(DATA_ROOT_DIR_PURPLE)/locale
create_dirs: ${DIR_LIST}
${DIR_LIST}:
@test -d $@ || mkdir -p $@
DEPENDENCE=$(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${ALL_OBJS}))
DEPENDENCE_LIST=${DEPENDENCE}
-include ${DEPENDENCE_LIST}
# The dependency on tgl/libs/libtgl.a ensures that "make -C tgl" was called,
# and most importantly: It ensures that all automatic headers exist.
${PLUGIN_OBJECTS}: ${OBJ}/%.o: ${srcdir}/%.c ${LIB}/libtgl.a | create_dirs
echo $@ && ${CC} ${CFLAGS} ${CPPFLAGS} -I ${srcdir}/tgl -I ${srcdir}/lodepng -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
tgl/Makefile.mingw: ${srcdir}/Makefile.tgl.mingw
cp $< $@
tgl/libs/libtgl.a: tgl/Makefile.mingw
+make -C tgl -f Makefile.mingw
tgl/config.h: ${srcdir}/config.h.tgl.mingw
cp $< $@
config.h: ${srcdir}/config.h.mingw
cp $< $@
po/%.mo: po/%.po
$(GMSGFMT) -cf -o $@ $<
${LIB}/libtgl.a: tgl/libs/libtgl.a | create_dirs
cp $< $@
${PRPL_LIBNAME}: ${PLUGIN_OBJECTS} ${LIB}/libtgl.a | create_dirs
${CC} -shared -o $@ $^ ${LDFLAGS}
.PHONY: plugin
plugin: $(PRPL_LIBNAME)
.PHONY: strip
strip: $(PRPL_LIBNAME)
$(STRIP) --strip-unneeded $(PRPL_LIBNAME)
.PHONY: install
install: $(PRPL_LIBNAME) $(LOCALES)
mkdir -m $(DIR_PERM) -p $(PLUGIN_DIR_PURPLE)
install -m $(FILE_PERM) $(PRPL_LIBNAME) $(PLUGIN_DIR_PURPLE)/$(PRPL_NAME)
install -m $(FILE_PERM) tg-server.tglpub $(DATA_ROOT_DIR_PURPLE)/server.tglpub
ifeq ($(COPY_ICONS),no)
@echo "Not copying icons due to configure-option --disable-icons."
@echo " If you're using Finch, Empathy, or Telepathy, then this is a good idea."
@echo " If you're using Pidgin, then this is a bad idea."
@echo " If you're using Adium, read the README.md: You're using the wrong build system!"
else
mkdir -m $(DIR_PERM) -p $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/16
install -m $(FILE_PERM) imgs/telegram16.png $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/16/telegram.png
mkdir -m $(DIR_PERM) -p $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/22
install -m $(FILE_PERM) imgs/telegram22.png $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/22/telegram.png
mkdir -m $(DIR_PERM) -p $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/48
install -m $(FILE_PERM) imgs/telegram48.png $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/48/telegram.png
endif
@for lang in $(shell cat po/LINGUAS); do \
mkdir -p $(localedir)/$$lang/LC_MESSAGES; \
echo "installing po/$$lang.mo to $(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo"; \
install -m $(FILE_PERM) po/$$lang.mo $(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo; \
done
.PHONY: uninstall
uninstall:
rm -f $(PLUGIN_DIR_PURPLE)/$(PRPL_NAME)
rm -f $(DATA_ROOT_DIR_PURPLE)/server.tglpub
rm -f $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/16/telegram.png
rm -f $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/22/telegram.png
rm -f $(DATA_ROOT_DIR_PURPLE)/pixmaps/pidgin/protocols/48/telegram.png
# TODO: Delete all installed .mo's, no matter what LINGUAS says.
@for lang in $(shell cat po/LINGUAS); do \
echo "removing $(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo"; \
rm -f $(localedir)/$$lang/LC_MESSAGES/$(gettext_package).mo; \
done
.PHONY: local_install
local_install:
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(HOME)/.purple/plugins
install -m $(FILE_PERM) $(PRPL_LIBNAME) $(DESTDIR)$(HOME)/.purple/plugins/$(PRPL_NAME)
# See telegram-base.c, function get_user_pk_path for justification:
mkdir -m $(DIR_PERM) -p $(DESTDIR)$(HOME)/.purple/telegram-purple
install -m $(FILE_PERM) tg-server.tglpub $(DESTDIR)$(HOME)/.purple/telegram-purple/server.tglpub
.PHONY: local_uninstall
local_uninstall:
rm -f $(DESTDIR)$(HOME)/.purple/plugins/$(PRPL_NAME)
rm -f $(DESTDIR)$(HOME)/.purple/telegram-purple/server.tglpub
.PHONY: run
run:
pidgin -d | grep 'telegram\|plugin\|proxy'
.PHONY: debug
debug: install
ddd pidgin
.PHONY: clean-here
clean-here:
rm -rf ${DIR_LIST} $(PRPL_C_OBJS) $(PRPL_LIBNAME) po/*.mo
.PHONY: clean
clean: clean-here tgl/Makefile.mingw
+make -C tgl -f Makefile.mingw clean
.PHONY: installer
installer: telegram-purple.nsi $(PRPL_LIBNAME) $(LOCALES)
$(MAKENSIS) -DPLUGIN_VERSION="$(PLUGIN_VERSION)" -DPRPL_NAME="$(PRPL_NAME)" -DWIN32_DEV_TOP="$(WIN32_DEV_TOP)" telegram-purple.nsi

View file

@ -1,116 +0,0 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Vitaly Valtman, Christopher Althaus, Markus Endres, Eion Robb 2014-2015
srcdir=.
WIN32_DEV_TOP ?= ../../win32-dev
CFLAGS=-I$(WIN32_DEV_TOP)/libgcrypt-1.6.3/include -I$(WIN32_DEV_TOP)/libgpg-error-1.12-2/include -I$(WIN32_DEV_TOP)/glib-2.28.8/include -DHAVE_CONFIG_H
LDFLAGS=-L$(WIN32_DEV_TOP)/libgcrypt-1.6.3/lib -I$(WIN32_DEV_TOP)/libgpg-error-1.12-2/lib -L$(WIN32_DEV_TOP)/libwebp-0.4.3-1/lib -L$(WIN32_DEV_TOP)/glib-2.28.8/lib -lwebp -lz -lgcrypt -Wl,--export-all-symbols -ggdb
CPPFLAGS=
DEFS=-DHAVE_CONFIG_H
COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter
EXTRA_LIBS=-lz -lgcrypt
LOCAL_LDFLAGS=-ggdb ${EXTRA_LIBS}
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
DEP=dep
AUTO=auto
OBJ=objs
LIB=libs
EXE=bin
DIR_LIST=${DEP} ${DEP}/crypto ${AUTO} ${EXE} ${OBJ} ${OBJ}/crypto ${LIB} ${DEP}/auto ${OBJ}/auto
LIB_LIST=${LIB}/libtgl.a ${LIB}/libtgl.dll
TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/mtproto-key.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tg-mime-types.o ${OBJ}/mtproto-utils.o ${OBJ}/crypto/bn_openssl.o ${OBJ}/crypto/bn_altern.o ${OBJ}/crypto/rsa_pem_openssl.o ${OBJ}/crypto/rsa_pem_altern.o ${OBJ}/crypto/md5_openssl.o ${OBJ}/crypto/md5_altern.o ${OBJ}/crypto/sha_openssl.o ${OBJ}/crypto/sha_altern.o ${OBJ}/crypto/aes_openssl.o ${OBJ}/crypto/aes_altern.o
TGL_OBJECTS_AUTO=${OBJ}/auto/auto-skip.o ${OBJ}/auto/auto-fetch.o ${OBJ}/auto/auto-store.o ${OBJ}/auto/auto-autocomplete.o ${OBJ}/auto/auto-types.o ${OBJ}/auto/auto-fetch-ds.o ${OBJ}/auto/auto-free-ds.o ${OBJ}/auto/auto-store-ds.o ${OBJ}/auto/auto-print-ds.o
TLD_OBJECTS=${OBJ}/dump-tl-file.o
GENERATE_OBJECTS=${OBJ}/generate.o
COMMON_OBJECTS=${OBJ}/tools.o ${OBJ}/crypto/rand_openssl.o ${OBJ}/crypto/rand_altern.o ${OBJ}/crypto/err_openssl.o ${OBJ}/crypto/err_altern.o
OBJ_C=${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS}
DEPENDENCE=$(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJ_C}))
DEPENDENCE_LIST=${DEPENDENCE}
INCLUDE=-I. -I${srcdir}
CC=$(WIN32_DEV_TOP)/mingw/bin/gcc
.SUFFIXES:
.SUFFIXES: .c .h .o
all: ${LIB_LIST}
create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto-skip.h ${AUTO}/auto-fetch.h ${AUTO}/auto-store.h ${AUTO}/auto-autocomplete.h ${AUTO}/auto-types.h
create_dirs: ${DIR_LIST}
dump-tl: ${EXE}/dump-tl-file
#include ${srcdir}/Makefile.tl-parser
${DIR_LIST}:
@test -d $@ || mkdir -p $@
-include ${DEPENDENCE_LIST}
${TGL_OBJECTS}: ${AUTO}/constants.h ${AUTO}/auto-skip.h ${AUTO}/auto-fetch.h ${AUTO}/auto-store.h ${AUTO}/auto-autocomplete.h ${AUTO}/auto-types.h ${AUTO}/auto-fetch-ds.h ${AUTO}/auto-free-ds.h ${AUTO}/auto-store-ds.h ${AUTO}/auto-print-ds.h
${OBJ_C}: ${OBJ}/%.o: ${srcdir}/%.c | create_dirs
${CC} ${INCLUDE} ${COMPILE_FLAGS} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${TGL_OBJECTS_AUTO}: ${OBJ}/auto/%.o: ${AUTO}/%.c | create_dirs
${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${LIB}/libtgl.a: ${TGL_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS_AUTO}
rm -f $@ && ar ruv $@ $^
${LIB}/libtgl.dll: ${TGL_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS_AUTO}
${CC} -shared -o $@ $^ ${LINK_FLAGS}
${EXE}/generate: ${GENERATE_OBJECTS} ${COMMON_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@
${AUTO}/scheme.tlo: ${AUTO}/scheme.tl ${EXE}/tl-parser
${EXE}/tl-parser -e $@ ${AUTO}/scheme.tl
${AUTO}/scheme.tl: ${srcdir}/scheme.tl ${srcdir}/encrypted_scheme.tl ${srcdir}/binlog.tl ${srcdir}/mtproto.tl ${srcdir}/append.tl | ${AUTO}
cat $^ > $@
${AUTO}/scheme2.tl: ${AUTO}/scheme.tl ${EXE}/tl-parser
${EXE}/tl-parser -E ${AUTO}/scheme.tl 2> $@ || ( cat $@ && rm $@ && false )
${AUTO}/auto.c: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate ${AUTO}/scheme.tlo > $@
${AUTO}/auto-%.c: ${AUTO}/scheme.tlo ${EXE}/generate auto/constants.h ${AUTO}/auto-%.h | create_dirs_and_headers
${EXE}/generate -g $(patsubst ${AUTO}/auto-%.c,%,$@) ${AUTO}/scheme.tlo > $@ || ( rm $@ && false )
${AUTO}/auto-%.h: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate -g $(patsubst ${AUTO}/auto-%.h,%-header,$@) ${AUTO}/scheme.tlo > $@ || ( rm $@ && false )
${AUTO}/constants.h: ${AUTO}/scheme2.tl ${srcdir}/gen_constants_h.awk
awk -f ${srcdir}/gen_constants_h.awk < $< > $@
${EXE}/dump-tl-file: ${OBJ}/auto/auto.o ${TLD_OBJECTS}
${CC} ${OBJ}/auto/auto.o ${TLD_OBJECTS} ${LINK_FLAGS} -o $@
clean:
rm -rf ${DIR_LIST}

78
README-LUA Normal file
View file

@ -0,0 +1,78 @@
To use lua with client you should write lua script. You can specify it from config ("lua_script" option) or from command_line [-s].
It should have several functions:
on_binlog_replay_end() - it is called when replay of old events end. Any updates prior this call were already received by this client
some time ago.
on_get_difference_end() - it is called after first get_difference call. So we received all updates after last client execute.
on_our_id(our_id) - Informs about id of currently logged in user.
on_msg_receive(msg) - it is called when we receive new msg (!! may be called before on_binlog_replay_end, than it is old msg).
on_user_update(user,what_changed) - updated info about user. what_changed is array of strings.
on_chat_update(user,what_changed) - updated info about user. what_changed is array of strings.
on_secret_chat_update(user,what_changed) - updated info about user. what_changed is array of strings.
Also, you can call several functions. Each this function last two arguments, are cb_function and cb_extra.
These functions may return false immidiately if something is bad with args, or return true and call cb_function in future.
cb_function would have two or three arguments: first cb_extra, second success (1 or 0), third result (if applicable).
If you want to pass msg to function, you should pass it's id.
If you want to pass peer to function, you should pass it's print_name.
Or, you can pass string user#id<id> chat#id<id> and secret_chat#id<id> as peer. It is in some cases better. For example if you want to postpone and you are afraid, that print_name would be changed in the meantime.
Function_list (arguments are listed aside from cb_function and cb_extra, :
get_contact_list ()
get_dialog_list ()
rename_chat (chat, new_name)
chat_set_photo (chat, file)
send_msg (peer, text)
fwd_msg (peer, msg)
send_photo (peer, file)
send_video (peer, file)
send_audio (peer, file)
send_document (peer, file)
send_text (peer, file)
load_photo(msg)
load_video(msg)
load_video_thumb(msg)
load_audio(msg)
load_document(msg)
load_document_thumb(msg)
chat_info (chat)
user_info (user)
get_history (peer, limit)
chat_add_user (chat, user)
chat_del_user (chat, user)
add_contactt (phone, first_name, last_name)
rename_contactt (phone, first_name, last_name)
msg_search (peer, text)
msg_global_search (text)
mark_read (peer)
set_profile_photo (file)
create_secret_chat (user)
create_group_chat (user, name)
delete_msg (msg)
restore_msg (number)
status_online ()
status_offline ()
Also, you have function
postpone (cb_function, cb_extra, timeout). It will call your cb_function in specified number of seconds (number of seconds may be double).

145
README.es Normal file
View file

@ -0,0 +1,145 @@
## Telegram messenger CLI [![Build Status](https://travis-ci.org/vysheng/tg.png)](https://travis-ci.org/vysheng/tg)
!!!! May be outdated. Please refer to english README as more actual.
Interfaz de línea de comandos para: [Telegram](http://telegram.org). Usa interfaz readline.
### Documentación del API y el protocolo
La documentación del APi de Telegram está disponible aquí: http://core.telegram.org/api
La documentación del protocolo MTproto está disponible aquí: http://core.telegram.org/mtproto
### Instalación
Clona el Repositorio GitHub
$ git clone https://github.com/vysheng/tg.git && cd tg
o descarga y descomprime el zip
$ wget https://github.com/vysheng/tg/archive/master.zip -O tg-master.zip
$ unzip tg-master.zip && cd tg-master
#### Linux
Librerías requeridas: readline openssl y (si desea usar config) libconfig y liblua.
Si no deseas usarlo, pasa las siguientes opciones --disable-libconfig y --disable-liblua respectivamente.
En Ubuntu usa:
$ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev
En gentoo:
$ sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua
En Fedora:
$ sudo yum install lua-devel openssl-devel libconfig-devel readline-devel
Por defecto Makefile utiliza liblua5.2 de ubuntu. Si utilizas una versión diferente de liblua o linux, tienes que ejecutar el script ./configure o recibirás un error de compilación extraño.
Entonces
$ ./configure
$ make
#### Mac OS X
El cliente depende de [librería readline](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) y [libconfig](http://www.hyperrealm.com/libconfig/), las cuales no están incluídas en OS X por defecto. Debes instalar estas librerías de forma manual, usando por ejemplo [Homebrew](http://brew.sh/).
$ brew install libconfig
$ brew install readline
$ brew install lua
$ export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.2.4/include"
$ export LDFLAGS="-L/usr/local/lib -L/usr/local/Cellar/readline/6.2.4/lib"
$ ./configure && make
Gracias a [@jfontan](https://github.com/vysheng/tg/issues/3#issuecomment-28293731) por esta solución.
#### FreeBSD
Instalar estos puertos:
* devel/libconfig
* devel/libexecinfo
Entonces construir:
$ env CC=clang CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure
$ make
#### Otros UNIX
Si logras ejecutarlo en otros UNIX, por favor házmelo saber.
### Uso
./telegram -k <clave-servidor-público>
Por defecto la clave pública se almacena en la misma carpeta con el nombre tg-server.pub o en /etc/telegram/server.pub, si no lo es, indica dónde encontrarlo:
./telegram -k tg-server.pub
El Cliente soporta completamiento con TAB e historial de comandos.
Peer se refiere al nombre del contacto o de diálogo y se puede acceder por completamiento con Tab.
Para los contactos de usuario el peer es el Nombre <guión bajo> Apellido con todos los espacios cambiados a guiones bajos.
Para los chats es su título con todos los espacios cambiados a guiones bajos.
Para los chats encriptados es <marca de exclamación> <guión bajo> Nombre <guión bajo> Apellido con todos los espacios cambiados a guiones bajos.
Si dos o más peers tienen el mismo nombre, una almohadilla y un número es añadido al nombre. (por ejemplo A_B,A_B#1,A_B#2 y así sucesivamente).
### Comandos soportados
#### Mensajería
* **msg** \<peer\> texto - envía el mensaje a este usuario.
* **fwd** \<usuario\> \<numero-mensaje\> - reenviar un mensaje al usuario. Puedes ver los número de mensajes iniciando el Cliente con -N.
* **chat_with_peer** \<peer\> - inicia un chat con este usuario. /exit o /quit para salir de este modo.
* **add_contact** \<numero-teléfono\> \<nombre\> \<apellido\> - intenta añadir este contacto a la lista de contactos.
* **rename_contact** \<usuario\> \<nombre\> \<apellido\> - intenta renombrar el contacto. Si tienes otro dispositivo será una pelea.
* **mark_read** \<peer\> - marca todos los mensajes como recibidos de ese usuario.
#### Multimedia
* **send_photo** \<peer\> \<nombre-archivo-foto\> - manda una foto al usuario.
* **send_video** \<peer\> \<nombre-archivo-video\> - envia un video al usuario.
* **send_text** \<peer\> \<nombre-archivo-texto> - envia un archivo de texto como un mensaje en plano.
* **load_photo**/load_video/load_video_thumb \<numero-mensaje\> - carga foto/video indicado del directorio de descarga.
* **view_photo**/view_video/view_video_thumb \<numero-mensaje\> - carga foto/video indicado del directorio de descarga y lo abre con el visor por defecto del sistema.
#### Opciones de chat de grupo
* **chat_info** \<chat\> - imprime información del chat.
* **chat_add_user** \<chat\> \<usuario\> - agrega un usuario al chat.
* **chat_del_user** \<chat\> \<usuario\> - elimina un usuario del chat.
* **rename_chat** \<chat\> \<nuevo-nombre\> - cambia el nombre al chat.
#### Search
* **search** \<peer\> patrón - busca el patrón indicado en los mensajes con ese usuario.
* **global_search** patrón - busca el patrón indicado en todos los mensajes.
#### Chat secreto
* **create_secret_chat** \<user\> - crea un chat secreto con el usuario indicado.
* **visualize_key** \<secret_chat\> - Muestra la clave de cifrado. Debes compararla con la del otro usuario.
#### Estadísticas e información varia.
* **user_info** \<user\> - muestra información sobre el usuario.
* **history** \<peer\> [limit] - muestra el historial (y la marca como leído). Limite por defecto = 40.
* **dialog_list** - muestra información acerca del dialogo
* **contact_list** - muestra información acerca de tu lista de contactos.
* **suggested_contacts** - muestra información sobre sus contactos, tiene un máximo de amigos comunes.
* **stats** - solo para depuración.
* **show_license** - muestra la licencia GPLv2.
* **help** - imprime esta ayuda.

397
README.md
View file

@ -1,339 +1,190 @@
Telegram-Purple Unofficial (Beta)
=================================
## Telegram messenger CLI [![Build Status](https://travis-ci.org/vysheng/tg.png)](https://travis-ci.org/vysheng/tg)
Telegram-purple is a Libpurple protocol plugin that adds support for the Telegram messenger.
Command-line interface for [Telegram](http://telegram.org). Uses readline interface.
I keep getting many questions about this plugin in my E-mail, so I've created a [telegram group chat](https://goo.gl/VudXys) for
telegram-purple related discussions or questions.
### API, Protocol documentation
Installation
------------
Documentation for Telegram API is available here: http://core.telegram.org/api
If you are just interested in using the plugin you probably want to use one of the following binary distributions. Please note that I do not control most of those package sources and the version may lag behind.
Documentation for MTproto protocol is available here: http://core.telegram.org/mtproto
If your platform is not supported or you want to contribute by testing or development, scroll down to "Building form Source".
### Upgrading to version 1.0
First of all, the binary is now in ./bin folder and is named telegram-cli. So be careful, not to use old binary.
#### OSX (Adium)
Second, config folder is now ${HOME}/.telegram-cli
1. Download and execute the [Telegram-Adium bundle] (https://github.com/majn/telegram-purple/releases/download/v1.3.0/telegram-adium-1.3.0.AdiumLibpurplePlugin.zip)
2. Restart Adium
Third, database is not compatible with older versions, so you'll have to login again.
#### Windows
Fourth, in peer_name '#' are substitued to '@'. (Not applied to appending of '#%d' in case of two peers having same name).
Eion Robb provides a binary for Windows users:
### Installation
1. Download and execute the setup from http://eion.robbmob.com/telegram/
2. Restart Pidgin
Clone GitHub Repository
#### Fedora (22, 23)
git clone https://github.com/vysheng/tg.git && cd tg
The package is available in the Fedora 22 and 23 testing repositories:
or download and extract zip
dnf config-manager --set-enabled updates-testing
dnf install purple-telegram
wget https://github.com/vysheng/tg/archive/master.zip -O tg-master.zip
unzip tg-master.zip && cd tg-master
#### Linux and BSDs
#### Arch Linux (AUR)
Install libs: readline or libedit, openssl and (if you want to use config) libconfig and liblua.
If you do not want to use them pass options --disable-libconfig and --disable-liblua respectively.
https://aur.archlinux.org/packages/telegram-purple/
On Ubuntu/Debian use:
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev
#### Debian
On gentoo:
At the time of writing, the package hasn't been accepted yet.
Please first check if it's already available to you: `sudo apt-get install telegram-purple`
sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua dev-libs/libevent
If this doesn't work because the package doesn't exist (yet), please build it from source.
On Fedora:
sudo yum install lua-devel openssl-devel libconfig-devel readline-devel
Building From Source
--------------------
On FreeBSD:
Below, you will find the instructions for how to build the libpurple protocol plugin from source.
pkg install libconfig libexecinfo lua52
#### 1. Clone
On OpenBSD:
This repository has submodules, so you need to clone recursively.
pkg_add libconfig libexecinfo lua
Then,
git clone --recursive https://github.com/majn/telegram-purple
cd telegram-purple
./configure
make
#### Other methods to install on linux
#### 1b. Cloning if you're a packager
On Gentoo: use ebuild provided.
If you are unsure about whether you need this, then you are not a
packager and don't have any use for this.
On Arch: https://aur.archlinux.org/packages/telegram-git/
If you need an "orig-tarball", it can be generated by `make dist`. Note
that this automatically generates an appropriate version number like
`1.2.4-58-g8e3cebf`. You can truncate the git suffix (`-g8e3cebf`). If
the `-58` part exists, it means that you're using a development
version, which is probably not what you want. If you still want to
package this, please leave the commit number (i.e., `58`) intact, as
this indicates that this version is in fact much further than just
`1.2.4`.
#### Mac OS X
The client depends on [readline library](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) and [libconfig](http://www.hyperrealm.com/libconfig/), which are not included in OS X by default. You have to install these libraries manually.
#### 2. Fetch all dependencies
If using [Homebrew](http://brew.sh/):
##### Fedora
brew install libconfig
brew install readline
brew install lua
export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.2.4/include"
export LDFLAGS="-L/usr/local/lib -L/usr/local/Cellar/readline/6.2.4/lib"
./configure && make
sudo dnf install gcc gettext libgcrypt-devel libwebp-devel libpurple-devel zlib-devel
Thanks to [@jfontan](https://github.com/vysheng/tg/issues/3#issuecomment-28293731) for this solution.
If using [MacPorts](https://www.macports.org):
sudo port install libconfig-hr
sudo port install readline
sudo port install lua51
export CFLAGS="-I/usr/local/include -I/opt/local/include"
export LDFLAGS="-L/usr/local/lib -L/opt/local/lib/"
./configure && make
##### Debian / Ubuntu
Install these ports:
We are working on a Debian package! Please first check if it's already available to you: `sudo apt-get install telegram-purple`
* devel/libconfig
* devel/libexecinfo
* lang/lua52
If the above works, then you should stop here: It is now installed.
Then build:
If the above fails: Don't worry, just continue building it by yourself. Next you need to install these dependencies:
env CC=clang CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib LUA=/usr/local/bin/lua52 LUA_INCLUDE=-I/usr/local/include/lua52 LUA_LIB=-llua-5.2 ./configure
make
sudo apt-get install libgcrypt20-dev libpurple-dev libwebp-dev gettext build-essential
#### Other UNIX
If you manage to launch it on other UNIX, please let me know.
##### OpenSUSE
### Contacts
If you would like to ask a question, you can write to my telegram or to the github (or both). To contact me via telegram, you should use import_card method with argument 000653bf:0738ca5d:5521fbac:29246815:a27d0cda
sudo zypper install gcc glib glib-devel libpurple libpurple-devel zlib-devel libwebp-devel
And the development files for gcrypt, probably `gcrypt-devel` or something. (FIXME)
### Usage
bin/telegram-cli -k <public-server-key>
By default public key is stored in the same folder named tg-server.pub or in /etc/telegram-cli/server.pub, if it's not, specify where to find it:
#### 3. Compile and install
bin/telegram-cli -k tg-server.pub
If libwebp is not available, you can disable sticker support by calling ./configure --disable-libweb instead.
Please note that this is usually not necessary.
Client support TAB completion and command history.
./configure
make
sudo make install
Peer refers to the name of the contact or dialog and can be accessed by TAB completion.
For user contacts peer name is Name <underscore> Lastname with all spaces changed to underscores.
For chats it is it's title with all spaces changed to underscores
For encrypted chats it is <Exсlamation mark> <underscore> Name <underscore> Lastname with all spaces changed to underscores.
If two or more peers have same name, <sharp>number is appended to the name. (for example A_B, A_B#1, A_B#2 and so on)
### Supported commands
Pulling Updates
---------------
#### Messaging
This repository contains submodules, and a simple pull just won't be enough to update all the submodules files. Pull new changes with:
* **msg** \<peer\> Text - sends message to this peer
* **fwd** \<user\> \<msg-seqno\> - forward message to user. You can see message numbers starting client with -N
* **chat_with_peer** \<peer\> starts one on one chat session with this peer. /exit or /quit to end this mode.
* **add_contact** \<phone-number\> \<first-name\> \<last-name\> - tries to add contact to contact-list by phone
* **rename_contact** \<user\> \<first-name\> \<last-name\> - tries to rename contact. If you have another device it will be a fight
* **mark_read** \<peer\> - mark read all received messages with peer
* **delete_msg** \<msg-seqno\> - deletes message (not completly, though)
* **restore_msg** \<msg-seqno\> - restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion
#### Multimedia
git pull
git submodule sync # just in case the configuration has changed
git submodule update --recursive
* **send_photo** \<peer\> \<photo-file-name\> - sends photo to peer
* **send_video** \<peer\> \<video-file-name\> - sends video to peer
* **send_text** \<peer\> \<text-file-name> - sends text file as plain messages
* **load_photo**/load_video/load_video_thumb/load_audio/load_document/load_document_thumb \<msg-seqno\> - loads photo/video/audio/document to download dir
* **view_photo**/view_video/view_video_thumb/view_audio/view_document/view_document_thumb \<msg-seqno\> - loads photo/video to download dir and starts system default viewer
* **fwd_media** \<msg-seqno\> send media in your message. Use this to prevent sharing info about author of media (though, it is possible to determine user_id from media itself, it is not possible get access_hash of this user)
* **set_profile_photo** \<photo-file-name\> - sets userpic. Photo should be square, or server will cut biggest central square part
Usage
-----
#### Group chat options
#### First Login
* **chat_info** \<chat\> - prints info about chat
* **chat_add_user** \<chat\> \<user\> - add user to chat
* **chat_del_user** \<chat\> \<user\> - remove user from chat
* **rename_chat** \<chat\> \<new-name\>
* **create_group_chat** \<user\> \<chat topic\> - creates a groupchat with user, use chat_add_user to add more users
* **chat_set_photo** \<chat\> \<photo-file-name\> - sets group chat photo. Same limits as for profile photos.
The username is your current phone number, including your full country prefix. For Germany, this would be '+49', resulting in a user name like '+49151123456'. Telegram will verify your phone number by sending you a code via SMS. You will be prompted for this code, once that happens.
#### Search
#### Buddy List
* **search** \<peer\> pattern - searches pattern in messages with peer
* **global_search** pattern - searches pattern in all messages
Like in the official Telegram apps, the displayed buddy list consists of all active conversations.
#### Secret chat
##### Foreign Users
* **create_secret_chat** \<user\> - creates secret chat with this user
* **visualize_key** \<secret_chat\> - prints visualization of encryption key. You should compare it to your partner's one
* **set_ttl** \<secret_chat\> \<ttl\> - sets ttl to secret chat. Though client does ignore it, client on other end can make use of it
* **accept_secret_chat** \<secret_chat\> - manually accept secret chat (only useful when starting with -E key)
Foreign users, like for example people you only know through a group chat but never had any conversation with, will not be part of your buddy list by default. You can add those users to the buddy list by clicking on "Add contact..." in the users context menu.
#### Stats and various info
#### Using secret chats
* **user_info** \<user\> - prints info about user
* **history** \<peer\> [limit] - prints history (and marks it as read). Default limit = 40
* **dialog_list** - prints info about your dialogs
* **contact_list** - prints info about users in your contact list
* **suggested_contacts** - print info about contacts, you have max common friends
* **stats** - just for debugging
* **show_license** - prints contents of GPLv2
* **help** - prints this help
You can use Telegram secret chats with this plugin, they will show up as a new buddy with a '!' in front of the buddy name.
#### Card
* **export_card** - print your 'card' that anyone can later use to import your contact
* **import_card** \<card\> - gets user by card. You can write messages to him after that.
One caveat of secret chats in Telegram is that they can only have one endpoint, this is a limitation of the protocol. This means that if you create a secret chat in Pidgin you will not be able to use that chat on your phone. You will be asked whether to accept each secret chat, so you can always choose to accept the chat on a different device if you want. You can set a default behavior for dealing with secret chats (Accept or Decline) in the account settings, if you don't want that prompt to appear every time.
Self destructive messages will be ignored, since I don't know any way to delete them from the conversation and the history.
##### Confirming the key authenticity
Click on the buddy in the buddy list and click on "Show Info" to visualize the key fingerprint.
##### Initiate secret chats
To initiate a secret chat from Pidgin, click on a Buddy in the Buddy List and hit "Start Secret Chat"
##### Deleting secret chats
If you delete a secret chat from the buddy list, it will be terminated and no longer be usable.
#### Unicode Emojis for Pidgin
The Telegram phone applications for iOS and Android make use of standardized Unicode smileys (called [Emojis](https://en.wikipedia.org/wiki/Emoji)). Pidgin
does not display those smileys natively, but you can install a custom smiley theme like (https://github.com/stv0g/unicode-emoji) or (https://github.com/VxJasonxV/emoji-for-pidgin) and activate it under Settings > Themes > Smiley Theme.
#### Code-Tags
Since 1.3.0 it is possible to write messages in monospaced fonts using the markdown backtick syntax.
##### Example
``` if (true) {
// do smth
}```
##### Result
if (true) {
// do smth
}
Building the Adium Plugin
-------------------------
Compiling with XCode is a little bit problematic, since it requires you to compile Adium first to get the necessary framework files. My advice is to just use the [prebuilt bundle](https://github.com/majn/telegram-purple/releases), but if you really want to do it, follow these steps:
1. Get the Adium source, compile it with XCode and copy the build output into telegram-adium/Frameworks/Adium. It should contain at least Adium.framework, AdiumLibpurple.framework and AIUitilies.framework
2. Open the Adium source code, go to ./Frameworks and copy libglib.framework and libpurple.framework into telegram-adium/Frameworks/Adium
3. Build the tgl submodule and delete libtgl.so from libs/ (it should only contain libtgl.a)
4. Install libwebp, libgcrypt and gnupg with homebrew:
brew install webp
brew install libgcrypt libgpg-error
5. If you already downloaded libwebp/libgcrypt in previous builds make sure that the binaries are up-to-date
brew update
brew upgrade webp libgcrypt
6. Install with homebrew and move it into the appropriate directory so that XCode can find them. Note that the versions might differ, use the one that is
mkdir -p ./telegram-adium/Frameworks/Adium
cp /usr/local/Cellar/webp/0.4.3/lib/libwebp.a ./telegram-adium/Frameworks
cp /usr/local/Cellar/libgcrypt/1.6.4/lib/libgcrypt.20.dylib ./telegram-adium/Frameworks/Adium
cp /usr/local/Cellar/libgpg-error/1.20_1/lib/libgpg-error.0.dylib ./telegram-adium/Frameworks/Adium
7. Update the paths in the dylibs, to assure that the resulting binary will load them form within the bundle.
cd ./telegram-adium/Frameworks/Adium
install_name_tool -id "@loader_path/../Resources/libgcrypt.20.dylib" ./libgcrypt.20.dylib
install_name_tool -id "@loader_path/../Resources/libgpg-error.0.dylib" ./libgpg-error.0.dylib
install_name_tool -change "/usr/local/lib/libgpg-error.0.dylib" "@loader_path/../Resources/libgpg-error.0.dylib" ./libgcrypt.20.dylib
7. Build the XCode-Project and execute the created bundle
Building the Debian Package
---------------------------
If you just need a `.deb`, simply do:
sudo apt-get install debhelper
git checkout debian-master
git submodule update --recursive
fakeroot ./debian/rules binary
And you're done! The `.deb` is in the directory at which you started.
To show some info about it, try this:
dpkg --info telegram-purple_*.deb
`debian-master` always points to a version that was submitted to Debian. (Note that this doesn't exist yet, as we haven't released to Debian yet.)
`debian-develop` is the candidate for the next submission.
#### Debian Maintainers ####
If you're a maintainer (if you're not sure, then you aren't a
maintainer), you need to produce a lot more files than that.
Here's how you can generate a `.orig.tar.gz`:
make dist
Note that these are incompatible with the old `debian/genorigtar.sh`
tarballs, and can't be made compatible easily. If you need the tarball
from "back then", see the documentation there.
This command requires the original tar to exist (and will fail otherwise,
although the error message will be misleading) will build all further files,
specifically `.debian.tar.xz`, `.dsc`, `.deb`, and `.changes`:
dpkg-buildpackage
For the upload, you should use `pbuilder` and similar to build the package
in a more minimalistic environment. That covers the official part of the work-flow.
Of course, you can call small parts of the build process directly, in order to avoid
overhead like rebuilding. For example, if you only need the `.debian.tar.xz`
and `.dsc` files, do this:
make dist
false # Move tar to parent directory, by hand
dpkg-source -b .
Discussion / Help
-----------------
#### Custom pubkeys
As we want to avoid OpenSSL, it has become necessary to replace the PEM file format. This means that if you use a custom pubkey (which you really REALLY shouldn't be doing), you have to adapt, sorry.
We no longer ship `tg-server.pub` (old format), but instead `tg-server.tglpub` (new format). If you have a `.pub` and want to continue using telegram-purple, please use this (hopefully highly portable) tool: [pem2bignum](https://github.com/BenWiederhake/pem2bignum)
You can also write your own conversion tool if you prefer. The format is really simple:
1. `e`, the public exponent, encoded as big endian 32 bit fixed length (e.g. `0x00 01 00 01` for 65537)
2. `n_len`, the length of `n` in bytes, encoded as big endian 32 bit fixed length (e.g. `0x00 00 01 00` for a 2048-bit = 256-byte key)
3. `n_raw`, the raw modulus, encoded as big endian, using the previously indicated length (e.g. `0xC1 50 02 3E [248 bytes omitted] 21 79 25 1F` in the case of telegram's public RSA key.)
If you are interested in developing a non-OpenSSL-licensed converter, look into [insane-triangle-banana](https://github.com/BenWiederhake/insane-triangle-banana).
FAQ
---
- I receive pictures in a chat, but they aren't showing up
* A: Make sure that you don't have a plugin like "Conversation Colors" that strips HTML from messages and removes the pictures.
- I receive RPC_CALL_FAIL_401: SESSION REVOKED
* A: This basically means your session has been terminated but the program
doesn't handle terminated sessions properly yet. You have to clean the
~/.purple/telegram-purple/$PHONENUMBER directory to fix this issue.
For Arch Linux users that use Bitlbee you can find this directory in
`/var/lib/bitlbee/purple/telegram-purple/`
#### Group chat
Telegram group chat for telegram-purple or libtgl related discussions or questions:
- https://goo.gl/VudXys
Submitting Bug Reports
----------------------
**IMPORTANT**: if you report bugs PLEASE make sure to always **include as much information as possible**. This should always include **at least the telegram-purple version and (if possible) commit**, where you got telegram-purple from (Source build, package repository, etc.), the Pidgin version (if you use a different messenger please state that too!) and your OS Version.
If you describe some issue please be as precise as possible. Descriptions like "XY doesn't work" will not help me. Describe what you are doing what kind of issue you are experiencing: "If I click on X, Y happens, but instead I would expect Z to happen".
For error reports please include the application logs. To get Pidgin to print a log, [start it from command line, specifying the -d option](https://developer.pidgin.im/wiki/GetABacktrace#TheEasyWay). **ATTENTION**: This log will contain personal information like your phone number, message content or contact or chat names. If you plan on uploading it somewhere public mask those entries in the log.
Bug reports regarding crashes should include a backtrace if possible, there is extended documentation available on [how to get a backtrace for crashes](https://developer.pidgin.im/wiki/GetABacktrace)
Empathy / libtelepathy
----------------------
Empathy doesn't natively support libpurple plugins since its based on libtelepathy, but there is a compatibillity layer called telepathy-haze that can be used to execute libpurple
plugins. This means that you can basically run this plugin thanks to telepathy-haze but you will usually get less features and worse usability compared to real libpurple clients. If you use Empathy (or anything else based on libtelepathy) I recommend [telepathy-morse](https://projects.kde.org/projects/playground/network/telepathy/telepathy-morse/repository) which is a connection manager written specifically for your messenger.
Authors
-------
Telegram-Purple was written by:
- Matthias Jentsch <mtthsjntsch@gmail.com>
- Vitaly Valtman
- Ben Wiederhake <Ben.Wiederhake@gmail.com>
- Christopher Althaus <althaus.christopher@gmail.com>
Acknowledgements
----------------
This software is based on the library [Libtgl](https://github.com/vysheng/tgl), which was written by Vitaly Valtman <mail@vysheng.ru> and others, see (https://github.com/vysheng/tgl/)
#### Other
* **quit** - quit
* **safe_quit** - wait for all queries to end then quit

2
append.tl Normal file
View file

@ -0,0 +1,2 @@
decryptedMessageMediaVideoL12#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaAudioL12#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia;

437
auto-static.c Normal file
View file

@ -0,0 +1,437 @@
/*
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
*/
#include "mtproto-common.h"
#include <string.h>
static int cur_token_len;
static char *cur_token;
static int cur_token_real_len;
static int cur_token_quoted;
static int multiline_output = 1;
static int multiline_offset;
static int multiline_offset_size = 2;
static int disable_field_names;
#define expect_token(token,len) \
if (len != cur_token_len || memcmp (cur_token, token, cur_token_len)) { return -1; } \
local_next_token ();
#define expect_token_ptr(token,len) \
if (len != cur_token_len || memcmp (cur_token, token, cur_token_len)) { return 0; } \
local_next_token ();
#define expect_token_autocomplete(token,len) \
if (cur_token_len == -3 && len >= cur_token_real_len && !memcmp (cur_token, token, cur_token_real_len)) { set_autocomplete_string (token); return -1; }\
if (len != cur_token_len || memcmp (cur_token, token, cur_token_len)) { return -1; } \
local_next_token ();
#define expect_token_ptr_autocomplete(token,len) \
if (cur_token_len == -3 && len >= cur_token_real_len && !memcmp (cur_token, token, cur_token_real_len)) { set_autocomplete_string (token); return 0; }\
if (len != cur_token_len || memcmp (cur_token, token, cur_token_len)) { return 0; } \
local_next_token ();
static int autocomplete_mode;
static char *autocomplete_string;
static int (*autocomplete_fun)(const char *, int, int, char **);
static void set_autocomplete_string (const char *s) {
if (autocomplete_string) { free (autocomplete_string); }
autocomplete_string = strdup (s);
assert (autocomplete_string);
autocomplete_mode = 1;
}
static void set_autocomplete_type (int (*f)(const char *, int, int, char **)) {
autocomplete_fun = f;
autocomplete_mode = 2;
}
static int is_int (void) {
if (cur_token_len <= 0) { return 0; }
char c = cur_token[cur_token_len];
cur_token[cur_token_len] = 0;
char *p = 0;
if (strtoll (cur_token, &p, 10)) {}
cur_token[cur_token_len] = c;
return p == cur_token + cur_token_len;
}
static long long get_int (void) {
if (cur_token_len <= 0) { return 0; }
char c = cur_token[cur_token_len];
cur_token[cur_token_len] = 0;
char *p = 0;
long long val = strtoll (cur_token, &p, 0);
cur_token[cur_token_len] = c;
return val;
}
static int is_double (void) {
if (cur_token_len <= 0) { return 0; }
char c = cur_token[cur_token_len];
cur_token[cur_token_len] = 0;
char *p = 0;
if (strtod (cur_token, &p)) {}
cur_token[cur_token_len] = c;
return p == cur_token + cur_token_len;
}
static double get_double (void) {
if (cur_token_len <= 0) { return 0; }
char c = cur_token[cur_token_len];
cur_token[cur_token_len] = 0;
char *p = 0;
double val = strtod (cur_token, &p);
cur_token[cur_token_len] = c;
return val;
}
static struct paramed_type *paramed_type_dup (struct paramed_type *P) {
if (ODDP (P)) { return P; }
struct paramed_type *R = malloc (sizeof (*R));
assert (R);
R->type = malloc (sizeof (*R->type));
assert (R->type);
memcpy (R->type, P->type, sizeof (*P->type));
R->type->id = strdup (P->type->id);
assert (R->type->id);
if (P->type->params_num) {
R->params = malloc (sizeof (void *) * P->type->params_num);
assert (R->params);
int i;
for (i = 0; i < P->type->params_num; i++) {
R->params[i] = paramed_type_dup (P->params[i]);
}
}
return R;
}
void tgl_paramed_type_free (struct paramed_type *P) {
if (ODDP (P)) { return; }
if (P->type->params_num) {
int i;
for (i = 0; i < P->type->params_num; i++) {
tgl_paramed_type_free (P->params[i]);
}
free (P->params);
}
free (P->type->id);
free (P->type);
free (P);
}
static char *buffer_pos, *buffer_end;
static int is_wspc (char c) {
return c <= 32 && c > 0;
}
static void skip_wspc (void) {
while (buffer_pos < buffer_end && is_wspc (*buffer_pos)) {
buffer_pos ++;
}
}
static int is_letter (char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '_' || c == '-';
}
static char exp_buffer[1 << 25];;
static int exp_buffer_pos;
static inline int is_hex (char c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
}
static inline int hex2dec (char c) {
if (c >= '0' && c <= '9') { return c - '0'; }
else { return c - 'a' + 10; }
}
static void expand_backslashed (char *s, int len) {
int backslashed = 0;
exp_buffer_pos = 0;
int i = 0;
while (i < len) {
assert (i + 3 <= (1 << 25));
if (backslashed) {
backslashed = 0;
switch (s[i ++]) {
case 'n':
exp_buffer[exp_buffer_pos ++] = '\n';
break;
case 'r':
exp_buffer[exp_buffer_pos ++] = '\r';
break;
case 't':
exp_buffer[exp_buffer_pos ++] = '\t';
break;
case 'b':
exp_buffer[exp_buffer_pos ++] = '\b';
break;
case 'a':
exp_buffer[exp_buffer_pos ++] = '\a';
break;
case '\\':
exp_buffer[exp_buffer_pos ++] = '\\';
break;
case 'x':
if (i + 2 > len || !is_hex (s[i]) || !is_hex (s[i + 1])) {
exp_buffer_pos = -1;
return;
}
exp_buffer[exp_buffer_pos ++] = hex2dec (s[i]) * 16 + hex2dec (s[i + 1]);
i += 2;
break;
default:
break;
}
} else {
if (s[i] == '\\') {
backslashed = 1;
i ++;
} else {
exp_buffer[exp_buffer_pos ++] = s[i ++];
}
}
}
}
static void local_next_token (void) {
skip_wspc ();
cur_token_quoted = 0;
if (buffer_pos >= buffer_end) {
cur_token_len = -3;
cur_token_real_len = 0;
return;
}
char c = *buffer_pos;
if (is_letter (c)) {
cur_token = buffer_pos;
while (buffer_pos < buffer_end && is_letter (*buffer_pos)) {
buffer_pos ++;
}
if (buffer_pos < buffer_end) {
cur_token_len = buffer_pos - cur_token;
} else {
cur_token_real_len = buffer_pos - cur_token;
cur_token_len = -3;
}
return;
} else if (c == '"') {
cur_token_quoted = 1;
cur_token = buffer_pos ++;
int backslashed = 0;
while (buffer_pos < buffer_end && (*buffer_pos != '"' || backslashed)) {
if (*buffer_pos == '\\') {
backslashed ^= 1;
} else {
backslashed = 0;
}
buffer_pos ++;
}
if (*buffer_pos == '"') {
buffer_pos ++;
expand_backslashed (cur_token + 1, buffer_pos - cur_token - 2);
if (exp_buffer_pos < 0) {
cur_token_len = -2;
} else {
cur_token_len = exp_buffer_pos;
cur_token = exp_buffer;
}
} else {
cur_token_len = -2;
}
return;
} else {
if (c) {
cur_token = buffer_pos ++;
cur_token_len = 1;
} else {
cur_token_len = -3;
cur_token_real_len = 0;
}
}
}
#define MAX_FVARS 100
static struct paramed_type *fvars[MAX_FVARS];
static int fvars_pos;
static void add_var_to_be_freed (struct paramed_type *P) {
assert (fvars_pos < MAX_FVARS);
fvars[fvars_pos ++] = P;
}
static void free_vars_to_be_freed (void) {
int i;
for (i = 0; i < fvars_pos; i++) {
tgl_paramed_type_free (fvars[i]);
}
fvars_pos = 0;
}
int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R, char *data, int data_len) {
if (index == -1) {
buffer_pos = data;
buffer_end = data + data_len;
autocomplete_mode = 0;
local_next_token ();
struct paramed_type *P = autocomplete_function_any ();
free_vars_to_be_freed ();
if (P) { tgl_paramed_type_free (P); }
}
if (autocomplete_mode == 0) { return -1; }
int len = strlen (text);
if (autocomplete_mode == 1) {
if (index >= 0) { return -1; }
index = 0;
if (!strncmp (text, autocomplete_string, len)) {
*R = strdup (autocomplete_string);
assert (*R);
return index;
} else {
return -1;
}
} else {
return autocomplete_fun (text, len, index, R);
}
}
struct paramed_type *tglf_extf_store (const char *data, int data_len) {
buffer_pos = (char *)data;
buffer_end = (char *)(data + data_len);
local_next_token ();
return store_function_any ();
}
#define OUT_BUF_SIZE (1 << 25)
static char out_buf[OUT_BUF_SIZE];
static int out_buf_pos;
#define eprintf(...) \
do { \
out_buf_pos += snprintf (out_buf + out_buf_pos, OUT_BUF_SIZE - out_buf_pos, __VA_ARGS__);\
assert (out_buf_pos < OUT_BUF_SIZE);\
} while (0)\
static int valid_utf8_char (const char *str) {
unsigned char c = (unsigned char) *str;
int n = 0;
if ((c & 0x80) == 0x00) {
n = 0;
} else if ((c & 0xe0) == 0xc0) {
n = 1;
} else if ((c & 0xf0) == 0xe0) {
n = 2;
} else if ((c & 0xf8) == 0xf0) {
n = 3;
} else if ((c & 0xfc) == 0xf8) {
n = 4;
} else if ((c & 0xfe) == 0xfc) {
n = 5;
} else {
return -1;
}
int i;
for (i = 0; i < n; i ++) {
if ((((unsigned char)(str[i + 1])) & 0xc0) != 0x80) {
return -1;
}
}
return n + 1;
}
static void print_escaped_string (const char *str, int len) {
eprintf ("\"");
const char *end = str + len;
while (str < end) {
int n = valid_utf8_char (str);
if (n < 0) {
eprintf ("\\x%02x", (int)(unsigned char)*str);
str ++;
} else if (n >= 2) {
int i;
for (i = 0; i < n; i++) {
eprintf ("%c", *(str ++));
}
} else if (((unsigned char)*str) >= ' ' && *str != '"' && *str != '\\') {
eprintf ("%c", *str);
str ++;
} else {
switch (*str) {
case '\n':
eprintf("\\n");
break;
case '\r':
eprintf("\\r");
break;
case '\t':
eprintf("\\t");
break;
case '\b':
eprintf("\\b");
break;
case '\a':
eprintf("\\a");
break;
case '\\':
eprintf ("\\\\");
break;
case '"':
eprintf ("\\\"");
break;
default:
eprintf ("\\x%02x", (int)(unsigned char)*str);
break;
}
str ++;
}
}
eprintf ("\"");
}
static void print_offset (void) {
int i;
for (i = 0; i < multiline_offset; i++) {
eprintf (" ");
}
}
char *tglf_extf_fetch (struct paramed_type *T) {
out_buf_pos = 0;
fetch_type_any (T);
return out_buf;
}

48
auto.h Normal file
View file

@ -0,0 +1,48 @@
/*
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
*/
#ifndef __AUTO_H__
#define __AUTO_H__
struct tl_type_descr {
unsigned name;
char *id;
int params_num;
long long params_types;
};
struct paramed_type {
struct tl_type_descr *type;
struct paramed_type **params;
};
#define NAME_ARRAY 0x89932ad9
#define TYPE_TO_PARAM(NAME) (&(struct paramed_type) {.type = &tl_type_## NAME, .params=0})
#define TYPE_TO_PARAM_1(NAME,PARAM1) (&(struct paramed_type) {.type = &tl_type_## NAME, .params=(struct paramed_type *[1]){PARAM1}})
#define ODDP(x) (((long)(x)) & 1)
#define EVENP(x) (!ODDP(x))
#define INT2PTR(x) (void *)(long)(((long)x) * 2 + 1)
#define PTR2INT(x) ((((long)x) - 1) / 2)
void tgl_paramed_type_free (struct paramed_type *P);
#include "auto/auto-header.h"
#endif

View file

@ -1,16 +0,0 @@
#!/bin/sh
set -e
autoreconf
(
cd po
export XGETTEXT="xgettext -kP_:1,2"
intltool-update --pot
## Translations are managed at https://www.transifex.com/telegram-purple-developers/telegram-purple/
## To update the .po files, download it from there, since intltool, msginit, and transifex produce slightly different files, and I'd like to avoid gigantic git diffs that only change indentation or similar things.
)
test -r Makefile || (echo "Autoreconf didn't create Makefile?!"; exit 1)
make --quiet build-nsi

614
ax_lua.m4 Normal file
View file

@ -0,0 +1,614 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_lua.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_PROG_LUA[([MINIMUM-VERSION], [TOO-BIG-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
# AX_LUA_HEADERS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
# AX_LUA_LIBS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
# AX_LUA_READLINE[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
#
# DESCRIPTION
#
# Detect a Lua interpreter, optionally specifying a minimum and maximum
# version number. Set up important Lua paths, such as the directories in
# which to install scripts and modules (shared libraries).
#
# Also detect Lua headers and libraries. The Lua version contained in the
# header is checked to match the Lua interpreter version exactly. When
# searching for Lua libraries, the version number is used as a suffix.
# This is done with the goal of supporting multiple Lua installs (5.1 and
# 5.2 side-by-side).
#
# A note on compatibility with previous versions: This file has been
# mostly rewritten for serial 18. Most developers should be able to use
# these macros without needing to modify configure.ac. Care has been taken
# to preserve each macro's behavior, but there are some differences:
#
# 1) AX_WITH_LUA is deprecated; it now expands to the exact same thing as
# AX_PROG_LUA with no arguments.
#
# 2) AX_LUA_HEADERS now checks that the version number defined in lua.h
# matches the interpreter version. AX_LUA_HEADERS_VERSION is therefore
# unnecessary, so it is deprecated and does not expand to anything.
#
# 3) The configure flag --with-lua-suffix no longer exists; the user
# should instead specify the LUA precious variable on the command line.
# See the AX_PROG_LUA description for details.
#
# Please read the macro descriptions below for more information.
#
# This file was inspired by Andrew Dalke's and James Henstridge's
# python.m4 and Tom Payne's, Matthieu Moy's, and Reuben Thomas's ax_lua.m4
# (serial 17). Basically, this file is a mash-up of those two files. I
# like to think it combines the best of the two!
#
# AX_PROG_LUA: Search for the Lua interpreter, and set up important Lua
# paths. Adds precious variable LUA, which may contain the path of the Lua
# interpreter. If LUA is blank, the user's path is searched for an
# suitable interpreter.
#
# If MINIMUM-VERSION is supplied, then only Lua interpreters with a
# version number greater or equal to MINIMUM-VERSION will be accepted. If
# TOO-BIG- VERSION is also supplied, then only Lua interpreters with a
# version number greater or equal to MINIMUM-VERSION and less than
# TOO-BIG-VERSION will be accepted.
#
# Version comparisons require the AX_COMPARE_VERSION macro, which is
# provided by ax_compare_version.m4 from the Autoconf Archive.
#
# The Lua version number, LUA_VERSION, is found from the interpreter, and
# substituted. LUA_PLATFORM is also found, but not currently supported (no
# standard representation).
#
# Finally, the macro finds four paths:
#
# luadir Directory to install Lua scripts.
# pkgluadir $luadir/$PACKAGE
# luaexecdir Directory to install Lua modules.
# pkgluaexecdir $luaexecdir/$PACKAGE
#
# These paths a found based on $prefix, $exec_prefix, Lua's package.path,
# and package.cpath. The first path of package.path beginning with $prefix
# is selected as luadir. The first path of package.cpath beginning with
# $exec_prefix is used as luaexecdir. This should work on all reasonable
# Lua installations. If a path cannot be determined, a default path is
# used. Of course, the user can override these later when invoking make.
#
# luadir Default: $prefix/share/lua/$LUA_VERSION
# luaexecdir Default: $exec_prefix/lib/lua/$LUA_VERSION
#
# These directories can be used by Automake as install destinations. The
# variable name minus 'dir' needs to be used as a prefix to the
# appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
#
# If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
# performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
# FOUND is blank, then it will default to printing an error. To prevent
# the default behavior, give ':' as an action.
#
# AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
# expanded before this macro. Adds precious variable LUA_INCLUDE, which
# may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
# LUA_INCLUDE is blank, then this macro will attempt to find suitable
# flags.
#
# LUA_INCLUDE can be used by Automake to compile Lua modules or
# executables with embedded interpreters. The *_CPPFLAGS variables should
# be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
#
# This macro searches for the header lua.h (and others). The search is
# performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
# If the search is unsuccessful, then some common directories are tried.
# If the headers are then found, then LUA_INCLUDE is set accordingly.
#
# The paths automatically searched are:
#
# * /usr/include/luaX.Y
# * /usr/include/lua/X.Y
# * /usr/include/luaXY
# * /usr/local/include/luaX.Y
# * /usr/local/include/lua-X.Y
# * /usr/local/include/lua/X.Y
# * /usr/local/include/luaXY
#
# (Where X.Y is the Lua version number, e.g. 5.1.)
#
# The Lua version number found in the headers is always checked to match
# the Lua interpreter's version number. Lua headers with mismatched
# version numbers are not accepted.
#
# If headers are found, then ACTION-IF-FOUND is performed, otherwise
# ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
# it will default to printing an error. To prevent the default behavior,
# set the action to ':'.
#
# AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
# expanded before this macro. Adds precious variable LUA_LIB, which may
# contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
# then this macro will attempt to find suitable flags.
#
# LUA_LIB can be used by Automake to link Lua modules or executables with
# embedded interpreters. The *_LIBADD and *_LDADD variables should be used
# for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
#
# This macro searches for the Lua library. More technically, it searches
# for a library containing the function lua_load. The search is performed
# with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
#
# If the search determines that some linker flags are missing, then those
# flags will be added to LUA_LIB.
#
# If libraries are found, then ACTION-IF-FOUND is performed, otherwise
# ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
# it will default to printing an error. To prevent the default behavior,
# set the action to ':'.
#
# AX_LUA_READLINE: Search for readline headers and libraries. Requires the
# AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
# Autoconf Archive.
#
# If a readline compatible library is found, then ACTION-IF-FOUND is
# performed, otherwise ACTION-IF-NOT-FOUND is performed.
#
# LICENSE
#
# Copyright (c) 2013 Tim Perkins <tprk77@gmail.com>
# Copyright (c) 2013 Reuben Thomas <rrt@sc3d.org>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program 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 General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 21
dnl =========================================================================
dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
dnl =========================================================================
AC_DEFUN([AX_PROG_LUA],
[
dnl Make LUA a precious variable.
AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
dnl Find a Lua interpreter.
m4_define_default([_AX_LUA_INTERPRETER_LIST],
[lua lua5.2 lua52 lua5.1 lua51 lua50])
m4_if([$1], [],
[ dnl No version check is needed. Find any Lua interpreter.
AS_IF([test "x$LUA" = 'x'],
[AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
ax_display_LUA='lua'
dnl At least check if this is a Lua interpreter.
AC_MSG_CHECKING([if $LUA is a Lua interpreter])
_AX_LUA_CHK_IS_INTRP([$LUA],
[AC_MSG_RESULT([yes])],
[ AC_MSG_RESULT([no])
AC_MSG_ERROR([not a Lua interpreter])
])
],
[ dnl A version check is needed.
AS_IF([test "x$LUA" != 'x'],
[ dnl Check if this is a Lua interpreter.
AC_MSG_CHECKING([if $LUA is a Lua interpreter])
_AX_LUA_CHK_IS_INTRP([$LUA],
[AC_MSG_RESULT([yes])],
[ AC_MSG_RESULT([no])
AC_MSG_ERROR([not a Lua interpreter])
])
dnl Check the version.
m4_if([$2], [],
[_ax_check_text="whether $LUA version >= $1"],
[_ax_check_text="whether $LUA version >= $1, < $2"])
AC_MSG_CHECKING([$_ax_check_text])
_AX_LUA_CHK_VER([$LUA], [$1], [$2],
[AC_MSG_RESULT([yes])],
[ AC_MSG_RESULT([no])
AC_MSG_ERROR([version is out of range for specified LUA])])
ax_display_LUA=$LUA
],
[ dnl Try each interpreter until we find one that satisfies VERSION.
m4_if([$2], [],
[_ax_check_text="for a Lua interpreter with version >= $1"],
[_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
AC_CACHE_CHECK([$_ax_check_text],
[ax_cv_pathless_LUA],
[ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
test "x$ax_cv_pathless_LUA" = 'xnone' && break
_AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
_AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
done
])
dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
[LUA=':'],
[AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
ax_display_LUA=$ax_cv_pathless_LUA
])
])
AS_IF([test "x$LUA" = 'x:'],
[ dnl Run any user-specified action, or abort.
m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
],
[ dnl Query Lua for its version number.
AC_CACHE_CHECK([for $ax_display_LUA version], [ax_cv_lua_version],
[ ax_cv_lua_version=`$LUA -e "print(_VERSION)" | \
sed "s|^Lua \(.*\)|\1|" | \
grep -E -o "^@<:@0-9@:>@+\.@<:@0-9@:>@+"`
])
AS_IF([test "x$ax_cv_lua_version" = 'x'],
[AC_MSG_ERROR([invalid Lua version number])])
AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | sed 's|\.||'`])
dnl The following check is not supported:
dnl At times (like when building shared libraries) you may want to know
dnl which OS platform Lua thinks this is.
AC_CACHE_CHECK([for $ax_display_LUA platform], [ax_cv_lua_platform],
[ax_cv_lua_platform=`$LUA -e "print('unknown')"`])
AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
dnl Use the values of $prefix and $exec_prefix for the corresponding
dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
dnl variables so they can be overridden if need be. However, the general
dnl consensus is that you shouldn't need this ability.
AC_SUBST([LUA_PREFIX], ['${prefix}'])
AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
dnl Lua provides no way to query the script directory, and instead
dnl provides LUA_PATH. However, we should be able to make a safe educated
dnl guess. If the built-in search path contains a directory which is
dnl prefixed by $prefix, then we can store scripts there. The first
dnl matching path will be used.
AC_CACHE_CHECK([for $ax_display_LUA script directory],
[ax_cv_lua_luadir],
[ AS_IF([test "x$prefix" = 'xNONE'],
[ax_lua_prefix=$ac_default_prefix],
[ax_lua_prefix=$prefix])
dnl Initialize to the default path.
ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
dnl Try to find a path with the prefix.
_AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [package.path])
AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
[ dnl Fix the prefix.
_ax_strip_prefix=`echo "$ax_lua_prefix" | sed 's|.|.|g'`
ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
sed "s,^$_ax_strip_prefix,$LUA_PREFIX,"`
])
])
AC_SUBST([luadir], [$ax_cv_lua_luadir])
AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
dnl Lua provides no way to query the module directory, and instead
dnl provides LUA_PATH. However, we should be able to make a safe educated
dnl guess. If the built-in search path contains a directory which is
dnl prefixed by $exec_prefix, then we can store modules there. The first
dnl matching path will be used.
AC_CACHE_CHECK([for $ax_display_LUA module directory],
[ax_cv_lua_luaexecdir],
[ AS_IF([test "x$exec_prefix" = 'xNONE'],
[ax_lua_exec_prefix=$ax_lua_prefix],
[ax_lua_exec_prefix=$exec_prefix])
dnl Initialize to the default path.
ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
dnl Try to find a path with the prefix.
_AX_LUA_FND_PRFX_PTH([$LUA],
[$ax_lua_exec_prefix], [package.cpathd])
AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
[ dnl Fix the prefix.
_ax_strip_prefix=`echo "$ax_lua_exec_prefix" | sed 's|.|.|g'`
ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
sed "s,^$_ax_strip_prefix,$LUA_EXEC_PREFIX,"`
])
])
AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
dnl Run any user specified action.
$3
])
])
dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
AC_DEFUN([AX_WITH_LUA],
[
AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA]])
AX_PROG_LUA
])
dnl =========================================================================
dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
dnl =========================================================================
AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
[
dnl Just print _VERSION because all Lua interpreters have this global.
AS_IF([$1 -e "print('Hello ' .. _VERSION .. '!')" &>/dev/null],
[$2], [$3])
])
dnl =========================================================================
dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
dnl [ACTION-IF-TRUE], [ACTION-IF-FALSE])
dnl =========================================================================
AC_DEFUN([_AX_LUA_CHK_VER],
[
_ax_test_ver=`$1 -e "print(_VERSION)" 2>/dev/null | \
sed "s|^Lua \(.*\)|\1|" | grep -E -o "^@<:@0-9@:>@+\.@<:@0-9@:>@+"`
AS_IF([test "x$_ax_test_ver" = 'x'],
[_ax_test_ver='0'])
AX_COMPARE_VERSION([$_ax_test_ver], [ge], [$2])
m4_if([$3], [], [],
[ AS_IF([$ax_compare_version],
[AX_COMPARE_VERSION([$_ax_test_ver], [lt], [$3])])
])
AS_IF([$ax_compare_version], [$4], [$5])
])
dnl =========================================================================
dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, LUA-PATH-VARIABLE)
dnl =========================================================================
AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
[
dnl Invokes the Lua interpreter PROG to print the path variable
dnl LUA-PATH-VARIABLE, usually package.path or package.cpath. Paths are
dnl then matched against PREFIX. The first path to begin with PREFIX is set
dnl to ax_lua_prefixed_path.
ax_lua_prefixed_path=''
_ax_package_paths=`$1 -e 'print($3)' 2>/dev/null | sed 's|;|\n|g'`
dnl Try the paths in order, looking for the prefix.
for _ax_package_path in $_ax_package_paths; do
dnl Copy the path, up to the use of a Lua wildcard.
_ax_path_parts=`echo "$_ax_package_path" | sed 's|/|\n|g'`
_ax_reassembled=''
for _ax_path_part in $_ax_path_parts; do
echo "$_ax_path_part" | grep '\?' >/dev/null && break
_ax_reassembled="$_ax_reassembled/$_ax_path_part"
done
dnl Check the path against the prefix.
_ax_package_path=$_ax_reassembled
if echo "$_ax_package_path" | grep "^$2" >/dev/null; then
dnl Found it.
ax_lua_prefixed_path=$_ax_package_path
break
fi
done
])
dnl =========================================================================
dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
dnl =========================================================================
AC_DEFUN([AX_LUA_HEADERS],
[
dnl Check for LUA_VERSION.
AC_MSG_CHECKING([if LUA_VERSION is defined])
AS_IF([test "x$LUA_VERSION" != 'x'],
[AC_MSG_RESULT([yes])],
[ AC_MSG_RESULT([no])
AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
])
dnl Make LUA_INCLUDE a precious variable.
AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
dnl Some default directories to search.
LUA_SHORT_VERSION=`echo "$LUA_VERSION" | sed 's|\.||'`
m4_define_default([_AX_LUA_INCLUDE_LIST],
[ /usr/include/lua$LUA_VERSION \
/usr/include/lua/$LUA_VERSION \
/usr/include/lua$LUA_SHORT_VERSION \
/usr/local/include/lua$LUA_VERSION \
/usr/local/include/lua-$LUA_VERSION \
/usr/local/include/lua/$LUA_VERSION \
/usr/local/include/lua$LUA_SHORT_VERSION \
])
dnl Try to find the headers.
_ax_lua_saved_cppflags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
CPPFLAGS=$_ax_lua_saved_cppflags
dnl Try some other directories if LUA_INCLUDE was not set.
AS_IF([test "x$LUA_INCLUDE" = 'x' &&
test "x$ac_cv_header_lua_h" != 'xyes'],
[ dnl Try some common include paths.
for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
test ! -d "$_ax_include_path" && continue
AC_MSG_CHECKING([for Lua headers in])
AC_MSG_RESULT([$_ax_include_path])
AS_UNSET([ac_cv_header_lua_h])
AS_UNSET([ac_cv_header_lualib_h])
AS_UNSET([ac_cv_header_lauxlib_h])
AS_UNSET([ac_cv_header_luaconf_h])
_ax_lua_saved_cppflags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
CPPFLAGS=$_ax_lua_saved_cppflags
AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
[ LUA_INCLUDE="-I$_ax_include_path"
break
])
done
])
AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
[ dnl Make a program to print LUA_VERSION defined in the header.
dnl TODO This probably shouldn't be a runtime test.
AC_CACHE_CHECK([for Lua header version],
[ax_cv_lua_header_version],
[ _ax_lua_saved_cppflags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
AC_RUN_IFELSE(
[ AC_LANG_SOURCE([[
#include <lua.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char ** argv)
{
if(argc > 1) printf("%s", LUA_VERSION);
exit(EXIT_SUCCESS);
}
]])
],
[ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
sed "s|^Lua \(.*\)|\1|" | \
grep -E -o "^@<:@0-9@:>@+\.@<:@0-9@:>@+"`
],
[ax_cv_lua_header_version='unknown'])
CPPFLAGS=$_ax_lua_saved_cppflags
])
dnl Compare this to the previously found LUA_VERSION.
AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
[ AC_MSG_RESULT([yes])
ax_header_version_match='yes'
],
[ AC_MSG_RESULT([no])
ax_header_version_match='no'
])
])
dnl Was LUA_INCLUDE specified?
AS_IF([test "x$ax_header_version_match" != 'xyes' &&
test "x$LUA_INCLUDE" != 'x'],
[AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
dnl Test the final result and run user code.
AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
[m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
])
dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
AC_DEFUN([AX_LUA_HEADERS_VERSION],
[
AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS]])
])
dnl =========================================================================
dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
dnl =========================================================================
AC_DEFUN([AX_LUA_LIBS],
[
dnl TODO Should this macro also check various -L flags?
dnl Check for LUA_VERSION.
AC_MSG_CHECKING([if LUA_VERSION is defined])
AS_IF([test "x$LUA_VERSION" != 'x'],
[AC_MSG_RESULT([yes])],
[ AC_MSG_RESULT([no])
AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
])
dnl Make LUA_LIB a precious variable.
AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
AS_IF([test "x$LUA_LIB" != 'x'],
[ dnl Check that LUA_LIBS works.
_ax_lua_saved_libs=$LIBS
LIBS="$LIBS $LUA_LIB"
AC_SEARCH_LIBS([lua_load], [],
[_ax_found_lua_libs='yes'],
[_ax_found_lua_libs='no'])
LIBS=$_ax_lua_saved_libs
dnl Check the result.
AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
[AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
],
[ dnl First search for extra libs.
_ax_lua_extra_libs=''
_ax_lua_saved_libs=$LIBS
LIBS="$LIBS $LUA_LIB"
AC_SEARCH_LIBS([exp], [m])
AC_SEARCH_LIBS([dlopen], [dl])
LIBS=$_ax_lua_saved_libs
AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
test "x$ac_cv_search_exp" != 'xnone required'],
[_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
test "x$ac_cv_search_dlopen" != 'xnone required'],
[_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
dnl Try to find the Lua libs.
_ax_lua_saved_libs=$LIBS
LIBS="$LIBS $LUA_LIB"
AC_SEARCH_LIBS([lua_load],
[ lua$LUA_VERSION \
lua$LUA_SHORT_VERSION \
lua-$LUA_VERSION \
lua-$LUA_SHORT_VERSION \
lua],
[_ax_found_lua_libs='yes'],
[_ax_found_lua_libs='no'],
[$_ax_lua_extra_libs])
LIBS=$_ax_lua_saved_libs
AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
test "x$ac_cv_search_lua_load" != 'xnone required'],
[LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
])
dnl Test the result and run user code.
AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
[m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
])
dnl =========================================================================
dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
dnl =========================================================================
AC_DEFUN([AX_LUA_READLINE],
[
AX_LIB_READLINE
AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
test "x$ac_cv_header_readline_history_h" != 'x'],
[ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
$1
],
[$2])
])

2132
binlog.c Normal file

File diff suppressed because it is too large Load diff

99
binlog.h Normal file
View file

@ -0,0 +1,99 @@
/*
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 2013-2014
*/
#ifndef __BINLOG_H__
#define __BINLOG_H__
//#include "structures.h"
#include "tgl.h"
void bl_do_set_auth_key_id (int num, unsigned char *buf);
void bl_do_dc_option (int id, int l1, const char *name, int l2, const char *ip, int port);
void bl_do_set_our_id (int id);
void bl_do_user_add (int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact);
void bl_do_user_delete (struct tgl_user *U);
void bl_do_set_user_profile_photo (struct tgl_user *U, long long photo_id, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_user_set_name (struct tgl_user *U, const char *f, int fl, const char *l, int ll);
void bl_do_user_set_access_hash (struct tgl_user *U, long long access_token);
void bl_do_user_set_phone (struct tgl_user *U, const char *p, int pl);
void bl_do_user_set_friend (struct tgl_user *U, int friend);
void bl_do_user_set_full_photo (struct tgl_user *U, const int *start, int len);
void bl_do_user_set_blocked (struct tgl_user *U, int blocked);
void bl_do_user_set_real_name (struct tgl_user *U, const char *f, int fl, const char *l, int ll);
void bl_do_encr_chat_delete (struct tgl_secret_chat *U);
void bl_do_encr_chat_requested (struct tgl_secret_chat *U, long long access_hash, int date, int admin_id, int user_id, unsigned char g_key[], unsigned char nonce[]);
void bl_do_encr_chat_create (int id, int user_id, int admin_id, char *name, int name_len);
void bl_do_encr_chat_set_access_hash (struct tgl_secret_chat *U, long long access_hash);
void bl_do_encr_chat_set_date (struct tgl_secret_chat *U, int date);
void bl_do_encr_chat_set_state (struct tgl_secret_chat *U, enum tgl_secret_chat_state state);
void bl_do_encr_chat_set_ttl (struct tgl_secret_chat *U, int ttl);
void bl_do_encr_chat_set_layer (struct tgl_secret_chat *U, int layer);
void bl_do_encr_chat_accepted (struct tgl_secret_chat *U, const unsigned char g_key[], const unsigned char nonce[], long long key_fingerprint);
void bl_do_encr_chat_set_key (struct tgl_secret_chat *E, unsigned char key[], long long key_fingerprint);
void bl_do_encr_chat_init (int id, int user_id, unsigned char random[], unsigned char g_a[]);
void bl_do_dc_signed (int id);
void bl_do_set_working_dc (int num);
void bl_do_set_dh_params (int root, unsigned char prime[], int version);
void bl_do_set_pts (int pts);
void bl_do_set_qts (int qts);
void bl_do_set_seq (int seq);
void bl_do_set_date (int date);
void bl_do_create_chat (struct tgl_chat *C, int y, const char *s, int l, int users_num, int date, int version, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_chat_forbid (struct tgl_chat *C, int on);
void bl_do_chat_set_title (struct tgl_chat *C, const char *s, int l);
void bl_do_chat_set_photo (struct tgl_chat *C, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_chat_set_date (struct tgl_chat *C, int date);
void bl_do_chat_set_set_in_chat (struct tgl_chat *C, int on);
void bl_do_chat_set_version (struct tgl_chat *C, int version, int user_num);
void bl_do_chat_set_admin (struct tgl_chat *C, int admin);
void bl_do_chat_set_participants (struct tgl_chat *C, int version, int user_num, struct tgl_chat_user *users);
void bl_do_chat_set_full_photo (struct tgl_chat *U, const int *start, int len);
void bl_do_chat_add_user (struct tgl_chat *C, int version, int user, int inviter, int date);
void bl_do_chat_del_user (struct tgl_chat *C, int version, int user);
void bl_do_create_message_text (int msg_id, int from_id, int to_type, int to_id, int date, int unread, int l, const char *s);
void bl_do_create_message_text_fwd (int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int unread, int l, const char *s);
void bl_do_create_message_service (int msg_id, int from_id, int to_type, int to_id, int date, int unread, const int *data, int len);
void bl_do_create_message_service_fwd (int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int unread, const int *data, int len);
void bl_do_create_message_media (int msg_id, int from_id, int to_type, int to_id, int date, int unread, int l, const char *s, const int *data, int len);
void bl_do_create_message_media_encr_pending (long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s, const int *data, int len);
void bl_do_create_message_media_encr_sent (long long msg_id, const int *data, int len);
void bl_do_create_message_media_fwd (int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int unread, int l, const char *s, const int *data, int len);
void bl_do_create_message_media_encr (long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s, const int *data, int len, const int *data2, int len2);
void bl_do_create_message_service_encr (long long msg_id, int from_id, int to_type, int to_id, int date, const int *data, int len);
void bl_do_send_message_text (long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s);
void bl_do_send_message_action_encr (long long msg_id, int from_id, int to_type, int to_id, int date, int l, const int *s);
void bl_do_set_unread (struct tgl_message *M, int unread);
void bl_do_set_message_sent (struct tgl_message *M);
void bl_do_set_msg_id (struct tgl_message *M, int id);
void bl_do_delete_msg (struct tgl_message *M);
void bl_do_msg_seq_update (long long id);
void bl_do_msg_update (long long id);
void bl_do_reset_authorization (void);
//void bl_do_add_dc (int id, const char *ip, int l, int port, long long auth_key_id, const char *auth_key);
#endif

79
binlog.tl Normal file
View file

@ -0,0 +1,79 @@
---types---
binlog.fileLocation dc:int volume:long local_id:int secret:long = binlog.FileLocation;
binlog.chatParticipant user:int inviter:int date:int = binlog.ChatParticipant;
binlog.start = binlog.Update;
binlog.dcOption id:int name:string ip:string port:int = binlog.Update;
binlog.authKey dc:int key_id:long key:64*[int] = binlog.Update;
binlog.defaultDc dc:int = binlog.Update;
binlog.ourId id:int = binlog.Update;
binlog.dcSigned id:int = binlog.Update;
binlog.dcSalt id:int salt:long = binlog.Update;
binlog.setDhParams root:int prime:64*[int] version:int = binlog.Update;
binlog.setPts pts:int = binlog.Update;
binlog.setQts qts:int = binlog.Update;
binlog.setDate date:int = binlog.Update;
binlog.setSeq seq:int = binlog.Update;
binlog.userAdd id:int first_name:string last_name:string hash:long phone:string is_contact:int = binlog.Update;
binlog.userDelete id:int = binlog.Update;
binlog.userSetAccessHash id:int hash:long = binlog.Update;
binlog.userSetPhone id:int phone:string = binlog.Update;
binlog.userSetFriend id:int friend:int = binlog.Update;
binlog.userSetFullPhoto id:int photo:Photo = binlog.Update;
binlog.userSetBlocked id:int blocked:int = binlog.Update;
binlog.userSetRealName id:int real_first_name:string real_last_name:string = binlog.Update;
binlog.userSetName id:int first_name:string last_name:string = binlog.Update;
binlog.userSetPhoto id:int photo:UserProfilePhoto = binlog.Update;
binlog.encrChatDelete id:int = binlog.Update;
binlog.encrChatRequested id:int hash:long date:int admin:int user:int key:64*[int] nonce:64*[int] = binlog.Update;
binlog.encrChatAccepted id:int key:64*[int] nonce:64*[int] fingerprint:long = binlog.Update;
binlog.encrChatInit id:int user:int key:64*[int] g_key:64*[int] = binlog.Update;
binlog.encrChatCreate id:int user_id:int admin_id:int name:string = binlog.Update;
binlog.encrChatSetAccessHash id:int hash:long = binlog.Update;
binlog.encrChatSetDate id:int date:int = binlog.Update;
binlog.encrChatSetTtl id:int ttl:int = binlog.Update;
binlog.encrChatSetLayer id:int layer:int = binlog.Update;
binlog.encrChatSetState id:int state:int = binlog.Update;
binlog.encrChatSetKey id:int key:64*[int] fingerprint:long = binlog.Update;
binlog.chatCreate id:int flags:int title:string user_num:int date:int version:int photo_big:%binlog.FileLocation photo_small:%binlog.FileLocation = binlog.Update;
binlog.chatChangeFlags id:int set_flags:int clear_flags:int = binlog.Update;
binlog.chatSetTitle id:int title:string = binlog.Update;
binlog.chatSetPhoto id:int photo_big:%binlog.FileLocation photo_small:%binlog.FileLocation = binlog.Update;
binlog.chatSetDate id:int date:int = binlog.Update;
binlog.chatSetVersion id:int version:int users_num:int = binlog.Update;
binlog.chatSetAdmin id:int admin:int = binlog.Update;
binlog.chatSetParticipants id:int version:int participants:%(Vector %binlog.ChatParticipant) = binlog.Update;
binlog.chatSetFullPhoto id:int photo:Photo = binlog.Update;
binlog.chatAddParticipant id:int version:int user:%binlog.ChatParticipant = binlog.Update;
binlog.chatDelParticipant id:int version:int user:int = binlog.Update;
binlog.createMessageText id:int from_id:int to_type:int to_id:int date:int unread:int text:string = binlog.Update;
binlog.sendMessageText id:long from_id:int to_type:int to_id:int date:int text:string = binlog.Update;
binlog.sendMessageActionEncr id:long from_id:int to_type:int to_id:int date:int action:DecryptedMessageAction = binlog.Update;
binlog.createMessageTextFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int unread:int text:string = binlog.Update;
binlog.createMessageMedia id:int from_id:int to_type:int to_id:int date:int unread:int text:string media:MessageMedia = binlog.Update;
binlog.createMessageMediaEncr id:long from_id:int to_type:int to_id:int date:int text:string media:DecryptedMessageMedia file:EncryptedFile = binlog.Update;
binlog.createMessageMediaEncrPending id:long from_id:int to_type:int to_id:int date:int text:string media:DecryptedMessageMedia = binlog.Update;
binlog.createMessageMediaEncrSent id:long file:EncryptedFile = binlog.Update;
binlog.createMessageMediaFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int unread:int text:string media:MessageMedia = binlog.Update;
binlog.createMessageService id:int from_id:int to_type:int to_id:int date:int unread:int action:MessageAction = binlog.Update;
binlog.createMessageServiceEncr id:long from_id:int to_type:int to_id:int date:int action:DecryptedMessageAction = binlog.Update;
binlog.createMessageServiceFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int unread:int action:MessageAction = binlog.Update;
binlog.messageSetUnread id:int = binlog.Update;
binlog.messageSetUnreadLong id:long = binlog.Update;
binlog.setMessageSent id:long = binlog.Update;
binlog.setMsgId old_id:long new_id:int = binlog.Update;
binlog.deleteMsg id:long = binlog.Update;
binlog.msgSeqUpdate id:long = binlog.Update;
binlog.msgUpdate id:long = binlog.Update;
binlog.resetAuthorization = binlog.Update;
//binlog.addDc id:int ip:string port:int auth_key_id:long auth_key:64*[int] = binlog.Update;

View file

@ -1,45 +0,0 @@
#!/bin/sh
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Ben Wiederhake 2016
set -e
if ! (command -v git && git status) >/dev/null 2>&1
then
if test -r commit.h
then
echo "No git available. Assuming everything is up-to-date."
exit 0
else
echo >&2 "No git available. Can't reconstruct commit.h"
exit 1
fi
fi
GIT_COMMIT=`git rev-parse HEAD | cut -c1-10`
if grep -scq "${GIT_COMMIT}" commit.h
then
echo "commit.h is up-to-date"
else
echo "Refresh commit.h"
echo "#ifndef GIT_COMMIT" > commit.h
echo "# define GIT_COMMIT \"${GIT_COMMIT}\"" >> commit.h
echo "#endif" >> commit.h
fi

View file

@ -1,45 +1,91 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define the gettext package to be used */
#undef GETTEXT_PACKAGE
/* Use libevent v1 */
#undef EVENT_V1
/* Use libevent v2 */
#undef EVENT_V2
/* Define to 1 if you have the `alarm' function. */
#undef HAVE_ALARM
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H
/* Define to 1 if you have the `endpwent' function. */
#undef HAVE_ENDPWENT
/* Define to 1 if you have the <execinfo.h> header file. */
#undef HAVE_EXECINFO_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
#undef HAVE_LIBGCRYPT
/* Define to 1 if you have the <lauxlib.h> header file. */
#undef HAVE_LAUXLIB_H
/* Define to 1 if you have the `rt' library (-lrt). */
#undef HAVE_LIBRT
/* Define to 1 if you have the `config' library (-lconfig). */
#undef HAVE_LIBCONFIG
/* Define to 1 if you have the `webp' library (-lwebp). */
#undef HAVE_LIBWEBP
/* Define to 1 if you have the `event' library (-levent). */
#undef HAVE_LIBEVENT
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
/* Define to 1 if you have `z' library (-lz) */
#undef HAVE_LIBZ
/* Define to 1 if you have the <luaconf.h> header file. */
#undef HAVE_LUACONF_H
/* Define to 1 if you have the <lualib.h> header file. */
#undef HAVE_LUALIB_H
/* Define to 1 if you have the <lua.h> header file. */
#undef HAVE_LUA_H
/* Define to 1 if you have the <mach/mach.h> header file. */
#undef HAVE_MACH_MACH_H
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
/* Define to 1 if you have the `memmove' function. */
#undef HAVE_MEMMOVE
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the `mkdir' function. */
#undef HAVE_MKDIR
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
@ -55,21 +101,33 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strndup' function. */
#undef HAVE_STRNDUP
/* Define to 1 if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
/* Define to 1 if you have the `uname' function. */
#undef HAVE_UNAME
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if the system has the `__builtin_bswap32' built-in function */
#undef HAVE___BUILTIN_BSWAP32
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
@ -88,11 +146,32 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Use custom prog name */
#undef PROG_NAME
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* use lua */
#undef USE_LUA
/* Define to `int' if <sys/types.h> doesn't define. */
#undef gid_t
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#undef inline
#endif
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to rpl_realloc if the replacement function should be used. */
#undef realloc
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
/* Define to `int' if <sys/types.h> doesn't define. */
#undef uid_t

View file

@ -1,116 +0,0 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Vitaly Valtman, Christopher Althaus, Markus Endres, Eion Robb 2014-2015
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define the gettext package to be used */
#define GETTEXT_PACKAGE "telegram-purple"
#define ENABLE_NLS 1
/* Define to 1 if you have the <arpa/inet.h> header file. */
/* #undef HAVE_ARPA_INET_H */
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
#define HAVE_LIBGCRYPT 1
/* Define to 1 if you have the `rt' library (-lrt). */
/* #undef HAVE_LIBRT */
/* Define to 1 if you have the `webp' library (-lwebp). */
#define HAVE_LIBWEBP 1
/* Define to 1 if you have `z' library (-lz) */
#define HAVE_LIBZ 1
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#define HAVE_MALLOC 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the <netdb.h> header file. */
/* #undef HAVE_NETDB_H */
/* Define to 1 if you have the <netinet/in.h> header file. */
/* #undef HAVE_NETINET_IN_H */
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
/* #undef HAVE_SYS_SOCKET_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "telegram-purple"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME PACKAGE_NAME
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to rpl_malloc if the replacement function should be used. */
/* #undef malloc */
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */

View file

@ -1,185 +0,0 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Vitaly Valtman, Christopher Althaus, Markus Endres, Eion Robb 2014-2015
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* disable extf queries */
/* #undef DISABLE_EXTF */
/* Use libevent v1 */
/* #undef EVENT_V1 */
/* Use libevent v2 */
/* #undef EVENT_V2 */
/* Define to 1 if you have the `alarm' function. */
#define HAVE_ALARM 1
/* Define to 1 if you have the <arpa/inet.h> header file. */
/* #undef HAVE_ARPA_INET_H */
/* Define to 1 if you have the `endpwent' function. */
/* #undef HAVE_ENDPWENT */
/* Define to 1 if you have the <execinfo.h> header file. */
/* #undef HAVE_EXECINFO_H */
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `event' library (-levent). */
/* #undef HAVE_LIBEVENT */
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
#define HAVE_LIBGCRYPT 1
/* Define to 1 if you have `z' library (-lz) */
#define HAVE_LIBZ 1
/* Define to 1 if you have the <mach/mach.h> header file. */
/* #undef HAVE_MACH_MACH_H */
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#define HAVE_MALLOC 1
/* Define to 1 if you have the <malloc.h> header file. */
#define HAVE_MALLOC_H 1
/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the `mkdir' function. */
#define HAVE_MKDIR 1
/* Define to 1 if you have the <netdb.h> header file. */
/* #undef HAVE_NETDB_H */
/* Define to 1 if you have the <netinet/in.h> header file. */
/* #undef HAVE_NETINET_IN_H */
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#define HAVE_REALLOC 1
/* Define to 1 if you have the `select' function. */
/* #undef HAVE_SELECT */
/* Define to 1 if you have the `socket' function. */
/* #undef HAVE_SOCKET */
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `strndup' function. */
/* #undef HAVE_STRNDUP */
/* Define to 1 if you have the <sys/file.h> header file. */
#define HAVE_SYS_FILE_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
/* #undef HAVE_SYS_SOCKET_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <termios.h> header file. */
/* #undef HAVE_TERMIOS_H */
/* Define to 1 if you have the `uname' function. */
/* #undef HAVE_UNAME */
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if the system has the `__builtin_bswap32' built-in function */
#define HAVE___BUILTIN_BSWAP32 1
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "telegram-cli"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "telegram-cli 1.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "telegram-cli"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.0"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* avoid OpenSSL entirely, use libgcrypt instead (this can't read *.pub files,
though.) */
#define TGL_AVOID_OPENSSL 1
/* fixed for correct valgrind work */
/* #undef VALGRIND_FIXES */
/* Define to `int' if <sys/types.h> doesn't define. */
#define gid_t int
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to rpl_malloc if the replacement function should be used. */
/* #undef malloc */
/* Define to rpl_realloc if the replacement function should be used. */
/* #undef realloc */
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define to `int' if <sys/types.h> doesn't define. */
#define uid_t int

66
config.sample Normal file
View file

@ -0,0 +1,66 @@
# This is an empty config file
# Feel free to put something here
default_profile = "binlog";
test_dc1 = {
config_directory = ".telegram/test_dc1";
test = true;
msg_num = true;
binlog_enabled = true;
};
binlog = {
config_directory = ".telegram/binlog";
test = false;
msg_num = true;
binlog_enabled = true;
log_level = 2;
};
binlog_mts = {
config_directory = ".telegram/binlog_mts";
test = false;
msg_num = true;
binlog_enabled = true;
log_level = 2;
};
mega = {
config_directory = ".telegram/mega";
test = false;
msg_num = true;
binlog_enabled = true;
log_level = 2;
};
new = {
config_directory = ".telegram/new";
test = false;
msg_num = true;
};
production = {
config_directory = ".telegram/production";
test = false;
msg_num = true;
};
test = {
config_directory = ".telegram/test";
test = true;
msg_num = true;
};
test1 = {
config_directory = ".telegram/test1";
msg_num = true;
binlog_enabled = true;
};
test2 = {
config_directory = ".telegram/test2";
msg_num = true;
binlog_enabled = true;
};

3075
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -1,101 +1,122 @@
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Vitaly Valtman, Christopher Althaus, Markus Endres 2014-2015
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([telegram-purple], [1.3.1])
AC_PREREQ([2.68])
AC_INIT([telegram-cli], [1.0])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])
m4_include([ax_lua.m4])
m4_include([m4_ax_check_openssl.m4])
m4_include([m4_ax_check_zlib.m4])
m4_include([m4_ax_pkg_config.m4])
m4_include([m4-ax_gcc_builtin.m4])
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_CHECK_LIB([rt], [clock_gettime])
# BSD locations for headers and libraries from packages, Linux locations for self-compiled stuff.
CPPFLAGS="$CPPFLAGS -I/usr/local/include"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
AC_ARG_ENABLE([gcrypt],
AS_HELP_STRING([--disable-gcrypt], [Disable gcrypt, use OpenSSL instead. DO NOT DISTRIBUTE BINARIES!]))
# Checks for libraries.
AC_CHECK_LIB([m], [sqrt])
AC_SEARCH_LIBS([clock_gettime], [rt])
AC_SEARCH_LIBS([backtrace], [execinfo])
AC_CHECK_LIB([event], [event_base_new], [], [AC_MSG_ERROR([no libevent found])])
AS_IF([test "x$enable_gcrypt" != "xno"], [
# Even though tgl/configure will do this too, still call our own libgcrypt check to assure that -lgcrypt is added to our makefile
AC_CHECK_LIB([gcrypt], [gcry_mpi_snatch], [], [
echo "no libgcrypt >= 1.60 found. If its not available try --disable-gcrypt to link against openssl, but in that case YOU MAY NOT REDISTRIBUTE THE BINARY due to licensing restrictions."
exit -1
EVENT_VER=""
AC_CHECK_HEADER(event2/event.h, [AC_DEFINE([EVENT_V2], [1], [Use libevent v2])], [
AC_CHECK_HEADER(event.h, [AC_DEFINE([EVENT_V1], [1], [Use libevent v1])], [AC_MSG_ERROR([no libevent found])])
])
AC_SUBST([CRYPTO_FLAG], [--disable-openssl])
], [
AX_CHECK_OPENSSL([], [No openssl found.])
])
EXTRA_LIBS=""
# OPENSSL_INCLUDES to the include directives required
# OPENSSL_LIBS to the -l directives required
# OPENSSL_LDFLAGS to the -L or -R flags required
AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found])])
AX_CHECK_ZLIB(, [AC_MSG_ERROR([No zlib found])])
PKG_CHECK_MODULES([PURPLE], [purple])
AC_CHECK_LIB([readline], [rl_save_prompt], [ EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; ], [AC_MSG_ERROR([no libreadline found])])
AC_MSG_CHECKING([for libwebp])
AC_ARG_ENABLE([libwebp],
AS_HELP_STRING([--disable-libwebp], [Disable libwebp, stickers won't be displayed in the chat]))
AS_IF([test "x$enable_libwebp" != "xno"], [
AC_MSG_CHECKING([for libconfig])
AC_ARG_ENABLE(libconfig,[--enable-libconfig/--disable-libconfig],
[
if test "x$enableval" = "xno" ; then
AC_MSG_RESULT([disabled])
else
AC_MSG_RESULT([enabled])
AC_CHECK_LIB([webp], [WebPDecodeRGBA], [], [AC_MSG_ERROR([no libwebp found, try --disable-libwebp, but stickers won't be displayed in the chat])])
AC_CHECK_LIB([config],[config_init],[],AC_MSG_ERROR([No libconfig found. Try --disable-libconfig]))
fi
],[
AC_MSG_RESULT([enabled])
AC_CHECK_LIB([config],[config_init],[],AC_MSG_ERROR([No libconfig found. Try --disable-libconfig]))
])
AC_ARG_ENABLE([icons],
AS_HELP_STRING([--disable-icons], [Unsupported option. Use 'make noicon_install' instead.]))
AS_IF([test "x$enable_icons" == "xno"], [
AC_MSG_ERROR([--disable-icons is now obsolete. Please use 'make noicon_install' for the same effect.])
])
AC_MSG_CHECKING([for liblua])
AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
[
if test "x$enableval" = "xno" ; then
AC_MSG_RESULT([disabled])
else
AC_MSG_RESULT([enabled])
AX_PROG_LUA([],[],
[
AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Try --disable-liblua])])
AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Try --disable-liblua])])
[EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ]
[CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ]
AC_DEFINE(USE_LUA,1,[use lua])
],
[
AC_MSG_ERROR([No lua found. Try --disable-liblua])
])
fi
],[
AC_MSG_RESULT([enabled])
AX_PROG_LUA([],[],
[
AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Try --disable-liblua])])
AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Try --disable-liblua])])
[EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ]
[CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ]
AC_DEFINE(USE_LUA,1,[use lua])
],
[
AC_MSG_ERROR([No lua found. Try --disable-liblua])
])
])
#check for custom prog name
AC_ARG_WITH(progname,[--with-progname=<name>],
[
if test "x$with_progname" = "xno" ; then
AC_MSG_RESULT([default])
elif test "x$with_progname" = "xyes" ; then
AC_MSG_RESULT([default])
else
AC_MSG_RESULT(["$with_progname"])
AC_DEFINE_UNQUOTED([PROG_NAME], ["$with_progname"], [Use custom prog name])
fi
],[
AC_MSG_RESULT([default])
])
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
AC_CHECK_HEADERS([execinfo.h fcntl.h malloc.h netdb.h stdlib.h string.h unistd.h arpa/inet.h mach/mach.h netinet/in.h sys/file.h sys/socket.h termios.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_C_INLINE
# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset strdup])
AC_FUNC_REALLOC
AC_CHECK_FUNCS([alarm endpwent memset memmove mkdir select socket strdup strndup uname])
AC_SUBST(PURPLE_CFLAGS)
AC_SUBST(PURPLE_CPPFLAGS)
AC_SUBST(PURPLE_LIBS)
AC_ARG_ENABLE([translation],
AS_HELP_STRING([--disable-translation], [Disable gettext translation]))
AS_IF([test "x$enable_translation" != "xno"], [
AC_CHECK_PROG(CHECK_GETTEXT, msgfmt, "yes", "no", $PATH)
if test x"$CHECK_GETTEXT" != x"yes" ; then
AC_MSG_ERROR([no gettext found, use --disable-translation if you dont need it.])
fi
AC_SUBST(MSGFMT_PATH, $(which msgfmt))
])
# Define the domain name for the translated words
GETTEXT_PACKAGE=$PACKAGE_NAME
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Define the gettext package to be used])
AX_GCC_BUILTIN(__builtin_bswap32)
AC_SUBST(EXTRA_LIBS)
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

668
crc32.c Normal file
View file

@ -0,0 +1,668 @@
/*
This file is part of VK/KittenPHP-DB-Engine Library.
VK/KittenPHP-DB-Engine 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 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine 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 VK/KittenPHP-DB-Engine Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009-2012 Vkontakte Ltd
2009-2012 Nikolai Durov
2009-2012 Andrei Lopatin
2012 Anton Maydell
*/
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "config.h"
#ifdef HAVE_CONFIG_H
#include "crc32.h"
#endif
#ifndef HAVE___BUILTIN_BSWAP32
static inline unsigned __builtin_bswap32(unsigned x) {
return ((x << 24) & 0xff000000 ) |
((x << 8) & 0x00ff0000 ) |
((x >> 8) & 0x0000ff00 ) |
((x >> 24) & 0x000000ff );
}
#endif
unsigned int crc32_table[256] =
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
unsigned int crc32_table2[256] =
{
0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3,
0x646cc504, 0x7d77f445, 0x565aa786, 0x4f4196c7,
0xc8d98a08, 0xd1c2bb49, 0xfaefe88a, 0xe3f4d9cb,
0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, 0x87981ccf,
0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192,
0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496,
0x821b9859, 0x9b00a918, 0xb02dfadb, 0xa936cb9a,
0xe6775d5d, 0xff6c6c1c, 0xd4413fdf, 0xcd5a0e9e,
0x958424a2, 0x8c9f15e3, 0xa7b24620, 0xbea97761,
0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265,
0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69,
0x39316bae, 0x202a5aef, 0x0b07092c, 0x121c386d,
0xdf4636f3, 0xc65d07b2, 0xed705471, 0xf46b6530,
0xbb2af3f7, 0xa231c2b6, 0x891c9175, 0x9007a034,
0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38,
0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c,
0xf0794f05, 0xe9627e44, 0xc24f2d87, 0xdb541cc6,
0x94158a01, 0x8d0ebb40, 0xa623e883, 0xbf38d9c2,
0x38a0c50d, 0x21bbf44c, 0x0a96a78f, 0x138d96ce,
0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca,
0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97,
0xded79850, 0xc7cca911, 0xece1fad2, 0xf5facb93,
0x7262d75c, 0x6b79e61d, 0x4054b5de, 0x594f849f,
0x160e1258, 0x0f152319, 0x243870da, 0x3d23419b,
0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864,
0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60,
0xad24e1af, 0xb43fd0ee, 0x9f12832d, 0x8609b26c,
0xc94824ab, 0xd05315ea, 0xfb7e4629, 0xe2657768,
0x2f3f79f6, 0x362448b7, 0x1d091b74, 0x04122a35,
0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31,
0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d,
0x838a36fa, 0x9a9107bb, 0xb1bc5478, 0xa8a76539,
0x3b83984b, 0x2298a90a, 0x09b5fac9, 0x10aecb88,
0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, 0x74c20e8c,
0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180,
0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484,
0x71418a1a, 0x685abb5b, 0x4377e898, 0x5a6cd9d9,
0x152d4f1e, 0x0c367e5f, 0x271b2d9c, 0x3e001cdd,
0xb9980012, 0xa0833153, 0x8bae6290, 0x92b553d1,
0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5,
0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a,
0xca6b79ed, 0xd37048ac, 0xf85d1b6f, 0xe1462a2e,
0x66de36e1, 0x7fc507a0, 0x54e85463, 0x4df36522,
0x02b2f3e5, 0x1ba9c2a4, 0x30849167, 0x299fa026,
0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b,
0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f,
0x2c1c24b0, 0x350715f1, 0x1e2a4632, 0x07317773,
0x4870e1b4, 0x516bd0f5, 0x7a468336, 0x635db277,
0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, 0xe0d7848d,
0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189,
0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85,
0x674f9842, 0x7e54a903, 0x5579fac0, 0x4c62cb81,
0x8138c51f, 0x9823f45e, 0xb30ea79d, 0xaa1596dc,
0xe554001b, 0xfc4f315a, 0xd7626299, 0xce7953d8,
0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4,
0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0,
0x5e7ef3ec, 0x4765c2ad, 0x6c48916e, 0x7553a02f,
0x3a1236e8, 0x230907a9, 0x0824546a, 0x113f652b,
0x96a779e4, 0x8fbc48a5, 0xa4911b66, 0xbd8a2a27,
0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23,
0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e,
0x70d024b9, 0x69cb15f8, 0x42e6463b, 0x5bfd777a,
0xdc656bb5, 0xc57e5af4, 0xee530937, 0xf7483876,
0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, 0x9324fd72,
};
unsigned int crc32_table1[256] =
{
0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59,
0x0709a8dc, 0x06cbc2eb, 0x048d7cb2, 0x054f1685,
0x0e1351b8, 0x0fd13b8f, 0x0d9785d6, 0x0c55efe1,
0x091af964, 0x08d89353, 0x0a9e2d0a, 0x0b5c473d,
0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29,
0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5,
0x1235f2c8, 0x13f798ff, 0x11b126a6, 0x10734c91,
0x153c5a14, 0x14fe3023, 0x16b88e7a, 0x177ae44d,
0x384d46e0, 0x398f2cd7, 0x3bc9928e, 0x3a0bf8b9,
0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065,
0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901,
0x3157bf84, 0x3095d5b3, 0x32d36bea, 0x331101dd,
0x246be590, 0x25a98fa7, 0x27ef31fe, 0x262d5bc9,
0x23624d4c, 0x22a0277b, 0x20e69922, 0x2124f315,
0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71,
0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad,
0x709a8dc0, 0x7158e7f7, 0x731e59ae, 0x72dc3399,
0x7793251c, 0x76514f2b, 0x7417f172, 0x75d59b45,
0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, 0x7ccf6221,
0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd,
0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9,
0x6bb5866c, 0x6a77ec5b, 0x68315202, 0x69f33835,
0x62af7f08, 0x636d153f, 0x612bab66, 0x60e9c151,
0x65a6d7d4, 0x6464bde3, 0x662203ba, 0x67e0698d,
0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579,
0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5,
0x46c49a98, 0x4706f0af, 0x45404ef6, 0x448224c1,
0x41cd3244, 0x400f5873, 0x4249e62a, 0x438b8c1d,
0x54f16850, 0x55330267, 0x5775bc3e, 0x56b7d609,
0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5,
0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1,
0x5deb9134, 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d,
0xe1351b80, 0xe0f771b7, 0xe2b1cfee, 0xe373a5d9,
0xe63cb35c, 0xe7fed96b, 0xe5b86732, 0xe47a0d05,
0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461,
0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd,
0xfd13b8f0, 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9,
0xfa1a102c, 0xfbd87a1b, 0xf99ec442, 0xf85cae75,
0xf300e948, 0xf2c2837f, 0xf0843d26, 0xf1465711,
0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd,
0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339,
0xde71f5bc, 0xdfb39f8b, 0xddf521d2, 0xdc374be5,
0xd76b0cd8, 0xd6a966ef, 0xd4efd8b6, 0xd52db281,
0xd062a404, 0xd1a0ce33, 0xd3e6706a, 0xd2241a5d,
0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049,
0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895,
0xcb4dafa8, 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1,
0xcc440774, 0xcd866d43, 0xcfc0d31a, 0xce02b92d,
0x91af9640, 0x906dfc77, 0x922b422e, 0x93e92819,
0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5,
0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1,
0x98b56f24, 0x99770513, 0x9b31bb4a, 0x9af3d17d,
0x8d893530, 0x8c4b5f07, 0x8e0de15e, 0x8fcf8b69,
0x8a809dec, 0x8b42f7db, 0x89044982, 0x88c623b5,
0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1,
0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d,
0xa9e2d0a0, 0xa820ba97, 0xaa6604ce, 0xaba46ef9,
0xaeeb787c, 0xaf29124b, 0xad6fac12, 0xacadc625,
0xa7f18118, 0xa633eb2f, 0xa4755576, 0xa5b73f41,
0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d,
0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89,
0xb2cddb0c, 0xb30fb13b, 0xb1490f62, 0xb08b6555,
0xbbd72268, 0xba15485f, 0xb853f606, 0xb9919c31,
0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, 0xbe9834ed,
};
unsigned int crc32_table0[256] = {
0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee,
0x8f629757, 0x37def032, 0x256b5fdc, 0x9dd738b9,
0xc5b428ef, 0x7d084f8a, 0x6fbde064, 0xd7018701,
0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, 0x58631056,
0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871,
0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26,
0x95ad7f70, 0x2d111815, 0x3fa4b7fb, 0x8718d09e,
0x1acfe827, 0xa2738f42, 0xb0c620ac, 0x087a47c9,
0xa032af3e, 0x188ec85b, 0x0a3b67b5, 0xb28700d0,
0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787,
0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f,
0xeae41086, 0x525877e3, 0x40edd80d, 0xf851bf68,
0xf02bf8a1, 0x48979fc4, 0x5a22302a, 0xe29e574f,
0x7f496ff6, 0xc7f50893, 0xd540a77d, 0x6dfcc018,
0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0,
0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7,
0x9b14583d, 0x23a83f58, 0x311d90b6, 0x89a1f7d3,
0x1476cf6a, 0xaccaa80f, 0xbe7f07e1, 0x06c36084,
0x5ea070d2, 0xe61c17b7, 0xf4a9b859, 0x4c15df3c,
0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b,
0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c,
0x446f98f5, 0xfcd3ff90, 0xee66507e, 0x56da371b,
0x0eb9274d, 0xb6054028, 0xa4b0efc6, 0x1c0c88a3,
0x81dbb01a, 0x3967d77f, 0x2bd27891, 0x936e1ff4,
0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed,
0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba,
0xfe92dfec, 0x462eb889, 0x549b1767, 0xec277002,
0x71f048bb, 0xc94c2fde, 0xdbf98030, 0x6345e755,
0x6b3fa09c, 0xd383c7f9, 0xc1366817, 0x798a0f72,
0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825,
0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d,
0x21e91f24, 0x99557841, 0x8be0d7af, 0x335cb0ca,
0xed59b63b, 0x55e5d15e, 0x47507eb0, 0xffec19d5,
0x623b216c, 0xda874609, 0xc832e9e7, 0x708e8e82,
0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a,
0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d,
0xbd40e1a4, 0x05fc86c1, 0x1749292f, 0xaff54e4a,
0x322276f3, 0x8a9e1196, 0x982bbe78, 0x2097d91d,
0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, 0x6a4166a5,
0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2,
0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb,
0xc2098e52, 0x7ab5e937, 0x680046d9, 0xd0bc21bc,
0x88df31ea, 0x3063568f, 0x22d6f961, 0x9a6a9e04,
0x07bda6bd, 0xbf01c1d8, 0xadb46e36, 0x15080953,
0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174,
0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623,
0xd8c66675, 0x607a0110, 0x72cfaefe, 0xca73c99b,
0x57a4f122, 0xef189647, 0xfdad39a9, 0x45115ecc,
0x764dee06, 0xcef18963, 0xdc44268d, 0x64f841e8,
0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf,
0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907,
0x3c9b51be, 0x842736db, 0x96929935, 0x2e2efe50,
0x2654b999, 0x9ee8defc, 0x8c5d7112, 0x34e11677,
0xa9362ece, 0x118a49ab, 0x033fe645, 0xbb838120,
0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98,
0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf,
0xd67f4138, 0x6ec3265d, 0x7c7689b3, 0xc4caeed6,
0x591dd66f, 0xe1a1b10a, 0xf3141ee4, 0x4ba87981,
0x13cb69d7, 0xab770eb2, 0xb9c2a15c, 0x017ec639,
0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e,
0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949,
0x090481f0, 0xb1b8e695, 0xa30d497b, 0x1bb12e1e,
0x43d23e48, 0xfb6e592d, 0xe9dbf6c3, 0x516791a6,
0xccb0a91f, 0x740cce7a, 0x66b96194, 0xde0506f1,
};
unsigned crc32_partial_old (const void *data, int len, unsigned crc) {
const char *p = data;
for (; len > 0; len--) {
crc = crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
}
return crc;
}
/*
unsigned crc32_partial_fast (const void *data, int len, unsigned crc) {
const int *p = (const int *) data;
int x;
for (x = (len >> 2); x > 0; x--) {
crc ^= *p++;
crc = crc32_table0[crc & 0xff] ^ crc32_table1[(crc & 0xff00) >> 8] ^ crc32_table2[(crc & 0xff0000) >> 16] ^ crc32_table[crc >> 24];
}
const char *q = (const char *) p;
switch (len & 3) {
case 3:
crc = crc32_table[(crc ^ *q++) & 0xff] ^ (crc >> 8);
case 2:
crc = crc32_table[(crc ^ *q++) & 0xff] ^ (crc >> 8);
case 1:
crc = crc32_table[(crc ^ *q++) & 0xff] ^ (crc >> 8);
}
return crc;
}
*/
unsigned crc32_partial (const void *data, int len, unsigned crc) {
const int *p = (const int *) data;
int x;
#define DO_ONE(v) crc ^= v; crc = crc32_table0[crc & 0xff] ^ crc32_table1[(crc & 0xff00) >> 8] ^ crc32_table2[(crc & 0xff0000) >> 16] ^ crc32_table[crc >> 24];
#define DO_FOUR(p) DO_ONE((p)[0]); DO_ONE((p)[1]); DO_ONE((p)[2]); DO_ONE((p)[3]);
for (x = (len >> 5); x > 0; x--) {
DO_FOUR (p);
DO_FOUR (p + 4);
p += 8;
}
if (len & 16) {
DO_FOUR (p);
p += 4;
}
if (len & 8) {
DO_ONE (p[0]);
DO_ONE (p[1]);
p += 2;
}
if (len & 4) {
DO_ONE (*p++);
}
/*
for (x = (len >> 2) & 7; x > 0; x--) {
DO_ONE (*p++);
}
*/
#undef DO_ONE
#undef DO_FOUR
const char *q = (const char *) p;
if (len & 2) {
crc = crc32_table[(crc ^ q[0]) & 0xff] ^ (crc >> 8);
crc = crc32_table[(crc ^ q[1]) & 0xff] ^ (crc >> 8);
q += 2;
}
if (len & 1) {
crc = crc32_table[(crc ^ *q++) & 0xff] ^ (crc >> 8);
}
return crc;
}
unsigned compute_crc32 (const void *data, int len) {
return crc32_partial (data, len, -1) ^ -1;
}
unsigned long long crc64_table[256] = {
0x0000000000000000LL, 0xb32e4cbe03a75f6fLL, 0xf4843657a840a05bLL, 0x47aa7ae9abe7ff34LL,
0x7bd0c384ff8f5e33LL, 0xc8fe8f3afc28015cLL, 0x8f54f5d357cffe68LL, 0x3c7ab96d5468a107LL,
0xf7a18709ff1ebc66LL, 0x448fcbb7fcb9e309LL, 0x0325b15e575e1c3dLL, 0xb00bfde054f94352LL,
0x8c71448d0091e255LL, 0x3f5f08330336bd3aLL, 0x78f572daa8d1420eLL, 0xcbdb3e64ab761d61LL,
0x7d9ba13851336649LL, 0xceb5ed8652943926LL, 0x891f976ff973c612LL, 0x3a31dbd1fad4997dLL,
0x064b62bcaebc387aLL, 0xb5652e02ad1b6715LL, 0xf2cf54eb06fc9821LL, 0x41e11855055bc74eLL,
0x8a3a2631ae2dda2fLL, 0x39146a8fad8a8540LL, 0x7ebe1066066d7a74LL, 0xcd905cd805ca251bLL,
0xf1eae5b551a2841cLL, 0x42c4a90b5205db73LL, 0x056ed3e2f9e22447LL, 0xb6409f5cfa457b28LL,
0xfb374270a266cc92LL, 0x48190ecea1c193fdLL, 0x0fb374270a266cc9LL, 0xbc9d3899098133a6LL,
0x80e781f45de992a1LL, 0x33c9cd4a5e4ecdceLL, 0x7463b7a3f5a932faLL, 0xc74dfb1df60e6d95LL,
0x0c96c5795d7870f4LL, 0xbfb889c75edf2f9bLL, 0xf812f32ef538d0afLL, 0x4b3cbf90f69f8fc0LL,
0x774606fda2f72ec7LL, 0xc4684a43a15071a8LL, 0x83c230aa0ab78e9cLL, 0x30ec7c140910d1f3LL,
0x86ace348f355aadbLL, 0x3582aff6f0f2f5b4LL, 0x7228d51f5b150a80LL, 0xc10699a158b255efLL,
0xfd7c20cc0cdaf4e8LL, 0x4e526c720f7dab87LL, 0x09f8169ba49a54b3LL, 0xbad65a25a73d0bdcLL,
0x710d64410c4b16bdLL, 0xc22328ff0fec49d2LL, 0x85895216a40bb6e6LL, 0x36a71ea8a7ace989LL,
0x0adda7c5f3c4488eLL, 0xb9f3eb7bf06317e1LL, 0xfe5991925b84e8d5LL, 0x4d77dd2c5823b7baLL,
0x64b62bcaebc387a1LL, 0xd7986774e864d8ceLL, 0x90321d9d438327faLL, 0x231c512340247895LL,
0x1f66e84e144cd992LL, 0xac48a4f017eb86fdLL, 0xebe2de19bc0c79c9LL, 0x58cc92a7bfab26a6LL,
0x9317acc314dd3bc7LL, 0x2039e07d177a64a8LL, 0x67939a94bc9d9b9cLL, 0xd4bdd62abf3ac4f3LL,
0xe8c76f47eb5265f4LL, 0x5be923f9e8f53a9bLL, 0x1c4359104312c5afLL, 0xaf6d15ae40b59ac0LL,
0x192d8af2baf0e1e8LL, 0xaa03c64cb957be87LL, 0xeda9bca512b041b3LL, 0x5e87f01b11171edcLL,
0x62fd4976457fbfdbLL, 0xd1d305c846d8e0b4LL, 0x96797f21ed3f1f80LL, 0x2557339fee9840efLL,
0xee8c0dfb45ee5d8eLL, 0x5da24145464902e1LL, 0x1a083bacedaefdd5LL, 0xa9267712ee09a2baLL,
0x955cce7fba6103bdLL, 0x267282c1b9c65cd2LL, 0x61d8f8281221a3e6LL, 0xd2f6b4961186fc89LL,
0x9f8169ba49a54b33LL, 0x2caf25044a02145cLL, 0x6b055fede1e5eb68LL, 0xd82b1353e242b407LL,
0xe451aa3eb62a1500LL, 0x577fe680b58d4a6fLL, 0x10d59c691e6ab55bLL, 0xa3fbd0d71dcdea34LL,
0x6820eeb3b6bbf755LL, 0xdb0ea20db51ca83aLL, 0x9ca4d8e41efb570eLL, 0x2f8a945a1d5c0861LL,
0x13f02d374934a966LL, 0xa0de61894a93f609LL, 0xe7741b60e174093dLL, 0x545a57dee2d35652LL,
0xe21ac88218962d7aLL, 0x5134843c1b317215LL, 0x169efed5b0d68d21LL, 0xa5b0b26bb371d24eLL,
0x99ca0b06e7197349LL, 0x2ae447b8e4be2c26LL, 0x6d4e3d514f59d312LL, 0xde6071ef4cfe8c7dLL,
0x15bb4f8be788911cLL, 0xa6950335e42fce73LL, 0xe13f79dc4fc83147LL, 0x521135624c6f6e28LL,
0x6e6b8c0f1807cf2fLL, 0xdd45c0b11ba09040LL, 0x9aefba58b0476f74LL, 0x29c1f6e6b3e0301bLL,
0xc96c5795d7870f42LL, 0x7a421b2bd420502dLL, 0x3de861c27fc7af19LL, 0x8ec62d7c7c60f076LL,
0xb2bc941128085171LL, 0x0192d8af2baf0e1eLL, 0x4638a2468048f12aLL, 0xf516eef883efae45LL,
0x3ecdd09c2899b324LL, 0x8de39c222b3eec4bLL, 0xca49e6cb80d9137fLL, 0x7967aa75837e4c10LL,
0x451d1318d716ed17LL, 0xf6335fa6d4b1b278LL, 0xb199254f7f564d4cLL, 0x02b769f17cf11223LL,
0xb4f7f6ad86b4690bLL, 0x07d9ba1385133664LL, 0x4073c0fa2ef4c950LL, 0xf35d8c442d53963fLL,
0xcf273529793b3738LL, 0x7c0979977a9c6857LL, 0x3ba3037ed17b9763LL, 0x888d4fc0d2dcc80cLL,
0x435671a479aad56dLL, 0xf0783d1a7a0d8a02LL, 0xb7d247f3d1ea7536LL, 0x04fc0b4dd24d2a59LL,
0x3886b22086258b5eLL, 0x8ba8fe9e8582d431LL, 0xcc0284772e652b05LL, 0x7f2cc8c92dc2746aLL,
0x325b15e575e1c3d0LL, 0x8175595b76469cbfLL, 0xc6df23b2dda1638bLL, 0x75f16f0cde063ce4LL,
0x498bd6618a6e9de3LL, 0xfaa59adf89c9c28cLL, 0xbd0fe036222e3db8LL, 0x0e21ac88218962d7LL,
0xc5fa92ec8aff7fb6LL, 0x76d4de52895820d9LL, 0x317ea4bb22bfdfedLL, 0x8250e80521188082LL,
0xbe2a516875702185LL, 0x0d041dd676d77eeaLL, 0x4aae673fdd3081deLL, 0xf9802b81de97deb1LL,
0x4fc0b4dd24d2a599LL, 0xfceef8632775faf6LL, 0xbb44828a8c9205c2LL, 0x086ace348f355aadLL,
0x34107759db5dfbaaLL, 0x873e3be7d8faa4c5LL, 0xc094410e731d5bf1LL, 0x73ba0db070ba049eLL,
0xb86133d4dbcc19ffLL, 0x0b4f7f6ad86b4690LL, 0x4ce50583738cb9a4LL, 0xffcb493d702be6cbLL,
0xc3b1f050244347ccLL, 0x709fbcee27e418a3LL, 0x3735c6078c03e797LL, 0x841b8ab98fa4b8f8LL,
0xadda7c5f3c4488e3LL, 0x1ef430e13fe3d78cLL, 0x595e4a08940428b8LL, 0xea7006b697a377d7LL,
0xd60abfdbc3cbd6d0LL, 0x6524f365c06c89bfLL, 0x228e898c6b8b768bLL, 0x91a0c532682c29e4LL,
0x5a7bfb56c35a3485LL, 0xe955b7e8c0fd6beaLL, 0xaeffcd016b1a94deLL, 0x1dd181bf68bdcbb1LL,
0x21ab38d23cd56ab6LL, 0x9285746c3f7235d9LL, 0xd52f0e859495caedLL, 0x6601423b97329582LL,
0xd041dd676d77eeaaLL, 0x636f91d96ed0b1c5LL, 0x24c5eb30c5374ef1LL, 0x97eba78ec690119eLL,
0xab911ee392f8b099LL, 0x18bf525d915feff6LL, 0x5f1528b43ab810c2LL, 0xec3b640a391f4fadLL,
0x27e05a6e926952ccLL, 0x94ce16d091ce0da3LL, 0xd3646c393a29f297LL, 0x604a2087398eadf8LL,
0x5c3099ea6de60cffLL, 0xef1ed5546e415390LL, 0xa8b4afbdc5a6aca4LL, 0x1b9ae303c601f3cbLL,
0x56ed3e2f9e224471LL, 0xe5c372919d851b1eLL, 0xa26908783662e42aLL, 0x114744c635c5bb45LL,
0x2d3dfdab61ad1a42LL, 0x9e13b115620a452dLL, 0xd9b9cbfcc9edba19LL, 0x6a978742ca4ae576LL,
0xa14cb926613cf817LL, 0x1262f598629ba778LL, 0x55c88f71c97c584cLL, 0xe6e6c3cfcadb0723LL,
0xda9c7aa29eb3a624LL, 0x69b2361c9d14f94bLL, 0x2e184cf536f3067fLL, 0x9d36004b35545910LL,
0x2b769f17cf112238LL, 0x9858d3a9ccb67d57LL, 0xdff2a94067518263LL, 0x6cdce5fe64f6dd0cLL,
0x50a65c93309e7c0bLL, 0xe388102d33392364LL, 0xa4226ac498dedc50LL, 0x170c267a9b79833fLL,
0xdcd7181e300f9e5eLL, 0x6ff954a033a8c131LL, 0x28532e49984f3e05LL, 0x9b7d62f79be8616aLL,
0xa707db9acf80c06dLL, 0x14299724cc279f02LL, 0x5383edcd67c06036LL, 0xe0ada17364673f59LL
};
unsigned long long crc64_partial (const void *data, int len, unsigned long long crc) {
const char *p = data;
for (; len > 0; len--) {
crc = crc64_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
}
return crc;
}
unsigned long long crc64 (const void *data, int len) {
return crc64_partial (data, len, -1LL) ^ -1LL;
}
static unsigned gf32_matrix_times (unsigned *matrix, unsigned vector) {
unsigned sum = 0;
while (vector) {
if (vector & 1) {
sum ^= *matrix;
}
vector >>= 1;
matrix++;
}
return sum;
}
static void gf32_matrix_square (unsigned *square, unsigned *matrix) {
int n = 0;
do {
square[n] = gf32_matrix_times (matrix, matrix[n]);
} while (++n < 32);
}
unsigned compute_crc32_combine (unsigned crc1, unsigned crc2, int len2) {
assert (len2 < (1 << 29));
static int power_buf_initialized = 0;
static unsigned power_buf[1024];
int n;
/* degenerate case (also disallow negative lengths) */
if (len2 <= 0) {
return crc1;
}
if (!power_buf_initialized) {
power_buf[0] = 0xedb88320UL;
for (n = 0; n < 31; n++) {
power_buf[n+1] = 1U << n;
}
for (n = 1; n < 32; n++) {
gf32_matrix_square (power_buf + (n << 5), power_buf + ((n - 1) << 5));
}
power_buf_initialized = 1;
}
unsigned int *p = power_buf + 64;
do {
p += 32;
if (len2 & 1) {
crc1 = gf32_matrix_times (p, crc1);
}
len2 >>= 1;
} while (len2);
return crc1 ^ crc2;
}
/********************************* crc32 repair ************************/
struct fcb_table_entry {
unsigned p; //zeta ^ k
int i;
};
static inline unsigned gf32_mod (unsigned long long r, int high_bit) {
int j = high_bit;
for (j = high_bit; j >= 32; j--) {
if ((1ULL << j) & r) {
r ^= 0x04C11DB7ULL << (j - 32);
}
}
return (unsigned) r;
}
static unsigned gf32_mult (unsigned a, unsigned b) {
int i;
const unsigned long long m = b;
unsigned long long r = 0;
for (i = 0; i < 32; i++) {
if (a & (1U << i)) {
r ^= m << i;
}
}
return gf32_mod (r, 62);
}
static unsigned gf32_shl (unsigned int a, int shift) {
unsigned long long r = a;
r <<= shift;
return gf32_mod (r, 31 + shift);
}
static unsigned gf32_pow (unsigned a, int k) {
if (!k) { return 1; }
unsigned x = gf32_pow (gf32_mult (a, a), k >> 1);
if (k & 1) {
x = gf32_mult (x, a);
}
return x;
}
static int cmp_fcb_table_entry (const void *a, const void *b) {
const struct fcb_table_entry *x = a;
const struct fcb_table_entry *y = b;
if (x->p < y->p) { return -1; }
if (x->p > y->p) { return 1; }
if (x->i < y->i) { return -1; }
if (x->i > y->i) { return 1; }
return 0;
}
#define GROUP_SWAP(x,m,s) ((x & m) << s) | ((x & (~m)) >> s)
static unsigned revbin (unsigned x) {
x = GROUP_SWAP(x,0x55555555U,1);
x = GROUP_SWAP(x,0x33333333U,2);
x = GROUP_SWAP(x,0x0f0f0f0fU,4);
x = __builtin_bswap32 (x);
return x;
}
#undef GROUP_SWAP
static inline unsigned xmult (unsigned a) {
unsigned r = a << 1;
if (a & (1U<<31)) {
r ^= 0x04C11DB7U;
}
return r;
}
static int find_corrupted_bit (int size, unsigned d) {
int i, j;
size += 4;
d = revbin (d);
int n = size << 3;
int r = (int) (sqrt (n) + 0.5);
struct fcb_table_entry *T = calloc (r, sizeof (struct fcb_table_entry));
assert (T != NULL);
T[0].i = 0;
T[0].p = 1;
for (i = 1; i < r; i++) {
T[i].i = i;
T[i].p = xmult (T[i-1].p);
}
assert (xmult (0x82608EDB) == 1);
qsort (T, r, sizeof (T[0]), cmp_fcb_table_entry);
unsigned q = gf32_pow (0x82608EDB, r);
unsigned A[32];
for (i = 0; i < 32; i++) {
A[i] = gf32_shl (q, i);
}
unsigned x = d;
int max_j = n / r, res = -1;
for (j = 0; j <= max_j; j++) {
int a = -1, b = r;
while (b - a > 1) {
int c = ((a + b) >> 1);
if (T[c].p <= x) { a = c; } else { b = c; }
}
if (a >= 0 && T[a].p == x) {
res = T[a].i + r * j;
break;
}
x = gf32_matrix_times (A, x);
}
free (T);
return res;
}
static int repair_bit (unsigned char *input, int l, int k) {
if (k < 0) {
return -1;
}
int idx = k >> 5, bit = k & 31, i = (l - 1) - (idx - 1) * 4;
while (bit >= 8) {
i--;
bit -= 8;
}
if (i < 0) {
return -2;
}
if (i >= l) {
return -3;
}
int j = 7 - bit;
input[i] ^= 1 << j;
return 0;
}
int crc32_check_and_repair (void *input, int l, unsigned *input_crc32, int force_exit) {
unsigned computed_crc32 = compute_crc32 (input, l);
const unsigned crc32_diff = computed_crc32 ^ (*input_crc32);
if (!crc32_diff) {
return 0;
}
int k = find_corrupted_bit (l, crc32_diff);
int r = repair_bit (input, l, k);
if (!r) {
assert (compute_crc32 (input, l) == *input_crc32);
return 1;
}
if (!(crc32_diff & (crc32_diff - 1))) { /* crc32_diff is power of 2 */
*input_crc32 = computed_crc32;
return 2;
}
assert (!force_exit);
*input_crc32 = computed_crc32;
return -1;
}

59
crc32.h Normal file
View file

@ -0,0 +1,59 @@
/*
This file is part of VK/KittenPHP-DB-Engine Library.
VK/KittenPHP-DB-Engine 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 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine 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 VK/KittenPHP-DB-Engine Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009-2012 Vkontakte Ltd
2009-2012 Nikolai Durov
2009-2012 Andrei Lopatin
2012 Anton Maydell
*/
#ifndef __CRC32_H__
#define __CRC32_H__
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int crc32_table[256];
unsigned crc32_partial (const void *data, int len, unsigned crc);
//unsigned crc32_partial_fast (const void *data, int len, unsigned crc);
//unsigned crc32_partial_fastest (const void *data, int len, unsigned crc);
unsigned compute_crc32 (const void *data, int len);
unsigned compute_crc32_combine (unsigned crc1, unsigned crc2, int len2);
extern unsigned long long crc64_table[256];
unsigned long long crc64_partial (const void *data, int len, unsigned long long crc);
unsigned long long crc64 (const void *data, int len);
//unsigned gf32_matrix_times (unsigned *matrix, unsigned vector);
/* crc32_check_and_repair returns
0 : Cyclic redundancy check is ok
1 : Cyclic redundancy check fails, but we fix one bit in input
2 : Cyclic redundancy check fails, but we fix one bit in input_crc32
-1 : Cyclic redundancy check fails, no repair possible.
In this case *input_crc32 will be equal crc32 (input, l)
Case force_exit == 1 (case 1, 2: kprintf call, case -1: assert fail).
*/
int crc32_check_and_repair (void *input, int l, unsigned *input_crc32, int force_exit);
#ifdef __cplusplus
}
#endif
#endif

5
debian/changelog vendored Normal file
View file

@ -0,0 +1,5 @@
telegram-cli (0.1-1) unstable; urgency=low
* Initial release (Closes #737563)
-- Cleto Martín <cleto@debian.org> Mon, 03 Feb 2014 20:00:03 +0000

1
debian/clean vendored Normal file
View file

@ -0,0 +1 @@
Makefile

1
debian/compat vendored Normal file
View file

@ -0,0 +1 @@
9

36
debian/control vendored Normal file
View file

@ -0,0 +1,36 @@
Source: telegram-cli
Section: net
Priority: optional
Maintainer: Cleto Martín <cleto@debian.org>
Build-Depends: debhelper (>= 8.0.0),
autotools-dev,
autoconf-archive,
libreadline-dev,
libconfig-dev,
libssl-dev,
lua5.2,
liblua5.2-dev
Standards-Version: 3.9.4
Homepage: https://github.com/vysheng/tg
Vcs-Git: git://github.com/vysheng/tg.git
Vcs-Browser: https://github.com/vysheng/tg
Package: telegram-cli
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Command-line interface for Telegram messenger
Telegram messenger is a cloud-based instant messaging designed for
smart phones and similar to Whatsapp but more flexible, and
powerful. You can send messages, photos, videos and documents to
people who are in your phone contacts (and have Telegram). Telegram
also supports secret chats whose provide a private (encrypted) way of
communication.
.
This package contains a command-line based client for Telegram with
the following features:
* Colored terminal messages.
* Message management: history, stats, etc.
* Group chat: create and manage groups.
* Secret chat: secured and encrypted conversations.
* Contact management: add/edit/remove contacts.
* Multimedia support: send/load photos and videos.

28
debian/copyright vendored Normal file
View file

@ -0,0 +1,28 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: telegram-cli
Source: https://github.com/vysheng/tg
Files: *
Copyright: 2013 Vitaly Valtman
License: GPL-2.0+
Files: debian/*
Copyright: 2014 Cleto Martín <cleto@debian.org>
License: GPL-2.0+
License: GPL-2.0+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package 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 General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".

1
debian/docs vendored Normal file
View file

@ -0,0 +1 @@
README.md

1
debian/install vendored Normal file
View file

@ -0,0 +1 @@
telegram usr/bin

17
debian/rules vendored Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/make -f
# -*- makefile -*-
VERSION=$(shell dpkg-parsechangelog | sed -n 's/^Version: //p' | cut -f1 -d'-')
PACKAGE_NAME=$(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
%:
dh $@ --with autotools-dev
build-orig:
mkdir -p $(PACKAGE_NAME)-$(VERSION)
tar --exclude=ax_lua.m4 --exclude=debian --exclude=\.pc \
--exclude=$(PACKAGE_NAME)-$(VERSION) -cf - . \
| ( cd $(PACKAGE_NAME)-$(VERSION) && tar xf - )
tar -cf ../$(PACKAGE_NAME)_$(VERSION).orig.tar $(PACKAGE_NAME)-$(VERSION)
$(RM) -r $(PACKAGE_NAME)-$(VERSION)
xz ../$(PACKAGE_NAME)_$(VERSION).orig.tar

1
debian/source/format vendored Normal file
View file

@ -0,0 +1 @@
3.0 (quilt)

4
debian/watch vendored Normal file
View file

@ -0,0 +1,4 @@
version=3
opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/tg-$1\.tar\.gz/ \
https://github.com/vysheng/tg/tags .*/v?(\d\S*)\.tar\.gz

1
encrypted_scheme.tl Symbolic link
View file

@ -0,0 +1 @@
encrypted_scheme16.tl

22
encrypted_scheme16.tl Normal file
View file

@ -0,0 +1,22 @@
---types---
decryptedMessageLayer#99a438cf layer:int message:DecryptedMessage = DecryptedMessageLayer;
decryptedMessage#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage;
decryptedMessageService#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage;
decryptedMessageMediaEmpty#89f5c4a = DecryptedMessageMedia;
decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
//decryptedMessageMediaVideo#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaGeoPoint#35480a59 lat:double long:double = DecryptedMessageMedia;
decryptedMessageMediaContact#588a0a97 phone_number:string first_name:string last_name:string user_id:int = DecryptedMessageMedia;
decryptedMessageActionSetMessageTTL#a1733aec ttl_seconds:int = DecryptedMessageAction;
decryptedMessageMediaDocument#b095434b thumb:bytes thumb_w:int thumb_h:int file_name:string mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia;
//decryptedMessageMediaAudio#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaVideo#524a415d thumb:bytes thumb_w:int thumb_h:int duration:int mime_type:string w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaAudio#57e0a9cb duration:int mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageActionReadMessages#c4f40be random_ids:Vector<long> = DecryptedMessageAction;
decryptedMessageActionDeleteMessages#65614304 random_ids:Vector<long> = DecryptedMessageAction;
decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector<long> = DecryptedMessageAction;
decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction;
decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction;
---functions---

43
event-old.h Normal file
View file

@ -0,0 +1,43 @@
#ifndef __EVENT_OLD_H__
#define __EVENT_OLD_H__
#include <assert.h>
#define BEV_EVENT_READ EVBUFFER_READ
#define BEV_EVENT_WRITE EVBUFFER_WRITE
#define BEV_EVENT_EOF EVBUFFER_EOF
#define BEV_EVENT_ERROR EVBUFFER_ERROR
#define BEV_EVENT_TIMEOUT EVBUFFER_TIMEOUT
typedef int evutil_socket_t;
static inline struct event *event_new (struct event_base *base, int fd, int what, void(*callback)(int, short, void *), void *arg) __attribute__ ((unused));
static inline struct event *event_new (struct event_base *base, int fd, int what, void(*callback)(int, short, void *), void *arg) {
struct event *ev = malloc (sizeof (*ev));
event_set (ev, fd, what, callback, arg);
event_base_set (base, ev);
return ev;
}
static inline struct event *evtimer_new (struct event_base *base, void(*callback)(int, short, void *), void *arg) __attribute__ ((unused));
static inline struct event *evtimer_new (struct event_base *base, void(*callback)(int, short, void *), void *arg) {
struct event *ev = malloc (sizeof (*ev));
event_set (ev, -1, 0, callback, arg);
event_base_set (base, ev);
return ev;
}
static void event_free (struct event *ev) __attribute__ ((unused));
static void event_free (struct event *ev) {
event_del (ev);
free (ev);
}
static struct bufferevent *bufferevent_socket_new (struct event_base *base, int fd, int flags) __attribute__ ((unused));
static struct bufferevent *bufferevent_socket_new (struct event_base *base, int fd, int flags) {
assert (!flags);
struct bufferevent *bev = bufferevent_new(fd, 0, 0, 0, 0);
bufferevent_base_set (base, bev);
return bev;
}
#endif

View file

@ -1,53 +0,0 @@
#!/bin/sh
# This file is part of telegram-purple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
#
# Copyright Matthias Jentsch, Ben Wiederhake 2016
set -e
# -- Cleanup possibly left-over artifacts
rm -f bin/tgl_tl-parser.tar bin/tgl.tar bin/commit.h.tar bin/result.tar bin/result.tar.gz
# -- Create parts
# Abuse the "bin" dir for temporary files.
( cd tgl/tl-parser && git archive --prefix=telegram-purple/tgl/tl-parser/ --output=../../bin/tgl_tl-parser.tar HEAD )
( cd tgl && git archive --prefix=telegram-purple/tgl/ --output=../bin/tgl.tar HEAD )
git archive --prefix=telegram-purple/ --output=bin/result.tar HEAD
# This is a lot of options. Here's why.
# --sort --mtime --owner --group => be reproducible (same commit produces binarily identical files)
# --transform => be in the same "tar-folder" as the rest
# (absence of --numeric-ids) => have identical behavior as git-archive
# --mode=664 => have identical behavior as git-archive
# http://www.gelato.unsw.edu.au/archives/git/0701/36326.html
# This is hacky. TODO: Find a better way to unify permissions.
tar --sort=name --mtime="1970-01-01 00:00Z" --owner=root --group=root --transform s%^%telegram-purple/% --mode=664 -cf bin/commit.h.tar commit.h
# -- Concatenate it all
tar --concatenate -f bin/result.tar bin/tgl.tar
tar --concatenate -f bin/result.tar bin/tgl_tl-parser.tar
tar --concatenate -f bin/result.tar bin/commit.h.tar
gzip -n bin/result.tar
# -- Determine name and move
TARNAME="telegram-purple_`git describe --tags | sed s/^v// `.orig.tar.gz"
# "mv -f" means "overwrite, if necessary"
echo mv -f bin/result.tar.gz $TARNAME
mv -f bin/result.tar.gz $TARNAME
# -- Cleanup (never fail)
rm -f bin/tgl_tl-parser.tar bin/tgl.tar bin/commit.h.tar bin/result.tar bin/result.tar.gz || true

37
gen_constants_h.awk Normal file
View file

@ -0,0 +1,37 @@
BEGIN {
print "/*";
print " This file is part of telegram-client.";
print "";
print " Telegram-client is free software: you can redistribute it and/or modify";
print " it under the terms of the GNU General Public License as published by";
print " the Free Software Foundation, either version 2 of the License, or";
print " (at your option) any later version.";
print "";
print " Telegram-client is distributed in the hope that it will be useful,";
print " but WITHOUT ANY WARRANTY; without even the implied warranty of";
print " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the";
print " GNU General Public License for more details.";
print "";
print " You should have received a copy of the GNU General Public License";
print " along with this telegram-client. If not, see <http://www.gnu.org/licenses/>.";
print "";
print " Copyright Vitaly Valtman 2013";
print "*/";
print "#ifndef CONSTANTS_H";
print "#define CONSTANTS_H";
}
// {
if (split ($1, a, "#") == 2) {
gsub (/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/, "_&", a[1]);
gsub (/[.]/, "_", a[1]);
if (a[2] in h) {
print "ERROR: Duplicate magic " a[2] " for define " a[1] " and " h[a[2]] >"/dev/stderr/"
exit 1;
}
h[a[2]] = a[1];
print "#define", "CODE_" tolower(a[1]), "0x" a[2];
}
}
END {
print "#endif";
}

1812
generate.c Normal file

File diff suppressed because it is too large Load diff

171
generate.h Normal file
View file

@ -0,0 +1,171 @@
/*
This file is part of tgl-libary/generate
Tgl-library/generate is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Tgl-library/generate 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this tgl-library/generate. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2014
It is derivative work of VK/KittenPHP-DB-Engine (https://github.com/vk-com/kphp-kdb/)
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#ifndef __GENERATE_H__
#define __GENERATE_H__
struct tl_combinator;
struct tl_type {
// struct tl_type_methods *methods;
char *id;
char *print_id;
unsigned name;
int arity;
int flags;
int constructors_num;
struct tl_combinator **constructors;
long long params_types;
int extra;
};
#define NODE_TYPE_TYPE 1
#define NODE_TYPE_NAT_CONST 2
#define NODE_TYPE_VAR_TYPE 3
#define NODE_TYPE_VAR_NUM 4
#define NODE_TYPE_ARRAY 5
#define MAX_COMBINATOR_VARS 64
#define NAME_VAR_NUM 0x70659eff
#define NAME_VAR_TYPE 0x2cecf817
#define NAME_INT 0xa8509bda
#define NAME_LONG 0x22076cba
#define NAME_DOUBLE 0x2210c154
#define NAME_STRING 0xb5286e24
#define NAME_VECTOR 0x1cb5c415
#define NAME_MAYBE_TRUE 0x3f9c8ef8
#define NAME_MAYBE_FALSE 0x27930a7b
#define NAME_BOOL_FALSE 0xbc799737
#define NAME_BOOL_TRUE 0x997275b5
#define FLAG_OPT_VAR (1 << 17)
#define FLAG_EXCL (1 << 18)
#define FLAG_OPT_FIELD (1 << 20)
#define FLAG_NOVAR (1 << 21)
#define FLAG_BARE 1
#define FLAGS_MASK ((1 << 16) - 1)
#define FLAG_DEFAULT_CONSTRUCTOR (1 << 25)
#define FLAG_NOCONS (1 << 1)
extern struct tl_tree_methods tl_nat_const_methods;
extern struct tl_tree_methods tl_nat_const_full_methods;
extern struct tl_tree_methods tl_pnat_const_full_methods;
extern struct tl_tree_methods tl_array_methods;
extern struct tl_tree_methods tl_type_methods;
extern struct tl_tree_methods tl_parray_methods;
extern struct tl_tree_methods tl_ptype_methods;
extern struct tl_tree_methods tl_var_num_methods;
extern struct tl_tree_methods tl_var_type_methods;
extern struct tl_tree_methods tl_pvar_num_methods;
extern struct tl_tree_methods tl_pvar_type_methods;
#define TL_IS_NAT_VAR(x) (((long)x) & 1)
#define TL_TREE_METHODS(x) (TL_IS_NAT_VAR (x) ? &tl_nat_const_methods : ((struct tl_tree *)(x))->methods)
#define DEC_REF(x) (TL_TREE_METHODS(x)->dec_ref ((void *)x))
#define INC_REF(x) (TL_TREE_METHODS(x)->inc_ref ((void *)x))
#define TYPE(x) (TL_TREE_METHODS(x)->type ((void *)x))
typedef unsigned long long tl_tree_hash_t;
struct tl_tree;
struct tl_tree_methods {
int (*type)(struct tl_tree *T);
int (*eq)(struct tl_tree *T, struct tl_tree *U);
void (*inc_ref)(struct tl_tree *T);
void (*dec_ref)(struct tl_tree *T);
};
struct tl_tree {
int ref_cnt;
int flags;
//tl_tree_hash_t hash;
struct tl_tree_methods *methods;
};
/*
struct tl_tree_nat_const {
struct tl_tree self;
int value;
};*/
struct tl_tree_type {
struct tl_tree self;
struct tl_type *type;
int children_num;
struct tl_tree **children;
};
struct tl_tree_array {
struct tl_tree self;
struct tl_tree *multiplicity;
int args_num;
struct arg **args;
};
struct tl_tree_var_type {
struct tl_tree self;
int var_num;
};
struct tl_tree_var_num {
struct tl_tree self;
int var_num;
int dif;
};
struct tl_tree_nat_const {
struct tl_tree self;
long long value;
};
struct arg {
char *id;
int var_num;
int flags;
int exist_var_num;
int exist_var_bit;
struct tl_tree *type;
};
struct tl_combinator {
//struct tl_combinator_methods *methods;
char *id;
char *print_id;
unsigned name;
int is_fun;
int var_num;
int args_num;
struct arg **args;
struct tl_tree *result;
void **IP;
void **fIP;
int IP_len;
int fIP_len;
};
#endif

View file

@ -0,0 +1 @@
EBUILD telegram-cli-9999.ebuild 665 SHA256 446cf5cd54f60485dda2f47e5c027b78f182053ef88cd09d7327603e2d5f3d86 SHA512 8a3673de91ec60e89391956523a4b61872161a23a7e0babdbd90cbdd8602104ba1855d09bd0af1d2092890eb202f498750610bf71e3bd0562e37ec984deb333e WHIRLPOOL e943b8870f461c62e3dc7f061dcad264c25758d1d50a0c34f5232d3be6ae26e9dd2ca1289e65b6153ff5b8800194969f1c53e3adc81aa4e47bf25c2f7e6aab7c

View file

@ -0,0 +1,33 @@
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
EAPI=5
EGIT_REPO_URI="https://github.com/vysheng/tg.git"
EGIT_BRANCH="test"
inherit git-2
IUSE="lua"
DESCRIPTION="Command line interface client for Telegram"
HOMEPAGE="https://github.com/vysheng/tg"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
DEPEND="sys-libs/zlib
sys-libs/readline
dev-libs/libconfig
dev-libs/openssl
dev-libs/libevent
lua? ( dev-lang/lua )"
src_configure() {
econf $(use_enable lua liblua )
}
src_install() {
newbin bin/telegram-cli telegram-cli
insinto /etc/telegram-cli/
newins tg-server.pub server.pub
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 943 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

24
include.h Normal file
View file

@ -0,0 +1,24 @@
/*
This file is part of telegram-client.
Telegram-client is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-client 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-client. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013
*/
#ifndef __INCLUDE_H__
#define __INCLUDE_H__
#define UU __attribute__ ((unused))
#endif

View file

@ -1,527 +0,0 @@
#!/bin/sh
# install - install a program, script, or datafile
scriptversion=2011-11-20.07; # UTC
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# 'make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
nl='
'
IFS=" "" $nl"
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit=${DOITPROG-}
if test -z "$doit"; then
doit_exec=exec
else
doit_exec=$doit
fi
# Put in absolute file names if you don't have them in your path;
# or use environment vars.
chgrpprog=${CHGRPPROG-chgrp}
chmodprog=${CHMODPROG-chmod}
chownprog=${CHOWNPROG-chown}
cmpprog=${CMPPROG-cmp}
cpprog=${CPPROG-cp}
mkdirprog=${MKDIRPROG-mkdir}
mvprog=${MVPROG-mv}
rmprog=${RMPROG-rm}
stripprog=${STRIPPROG-strip}
posix_glob='?'
initialize_posix_glob='
test "$posix_glob" != "?" || {
if (set -f) 2>/dev/null; then
posix_glob=
else
posix_glob=:
fi
}
'
posix_mkdir=
# Desired mode of installed file.
mode=0755
chgrpcmd=
chmodcmd=$chmodprog
chowncmd=
mvcmd=$mvprog
rmcmd="$rmprog -f"
stripcmd=
src=
dst=
dir_arg=
dst_arg=
copy_on_change=false
no_target_directory=
usage="\
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
or: $0 [OPTION]... -d DIRECTORIES...
In the 1st form, copy SRCFILE to DSTFILE.
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES.
Options:
--help display this help and exit.
--version display version info and exit.
-c (ignored)
-C install only if different (preserve the last data modification time)
-d create directories instead of installing files.
-g GROUP $chgrpprog installed files to GROUP.
-m MODE $chmodprog installed files to MODE.
-o USER $chownprog installed files to USER.
-s $stripprog installed files.
-t DIRECTORY install into DIRECTORY.
-T report an error if DSTFILE is a directory.
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
RMPROG STRIPPROG
"
while test $# -ne 0; do
case $1 in
-c) ;;
-C) copy_on_change=true;;
-d) dir_arg=true;;
-g) chgrpcmd="$chgrpprog $2"
shift;;
--help) echo "$usage"; exit $?;;
-m) mode=$2
case $mode in
*' '* | *' '* | *'
'* | *'*'* | *'?'* | *'['*)
echo "$0: invalid mode: $mode" >&2
exit 1;;
esac
shift;;
-o) chowncmd="$chownprog $2"
shift;;
-s) stripcmd=$stripprog;;
-t) dst_arg=$2
# Protect names problematic for 'test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
shift;;
-T) no_target_directory=true;;
--version) echo "$0 $scriptversion"; exit $?;;
--) shift
break;;
-*) echo "$0: invalid option: $1" >&2
exit 1;;
*) break;;
esac
shift
done
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
# When -d is used, all remaining arguments are directories to create.
# When -t is used, the destination is already specified.
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dst_arg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dst_arg"
shift # fnord
fi
shift # arg
dst_arg=$arg
# Protect names problematic for 'test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
done
fi
if test $# -eq 0; then
if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2
exit 1
fi
# It's OK to call 'install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
if test -z "$dir_arg"; then
do_exit='(exit $ret); exit $ret'
trap "ret=129; $do_exit" 1
trap "ret=130; $do_exit" 2
trap "ret=141; $do_exit" 13
trap "ret=143; $do_exit" 15
# Set umask so as not to create temps with too-generous modes.
# However, 'strip' requires both read and write access to temps.
case $mode in
# Optimize common cases.
*644) cp_umask=133;;
*755) cp_umask=22;;
*[0-7])
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw='% 200'
fi
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
*)
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw=,u+rw
fi
cp_umask=$mode$u_plus_rw;;
esac
fi
for src
do
# Protect names problematic for 'test' and other utilities.
case $src in
-* | [=\(\)!]) src=./$src;;
esac
if test -n "$dir_arg"; then
dst=$src
dstdir=$dst
test -d "$dstdir"
dstdir_status=$?
else
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dst_arg"; then
echo "$0: no destination specified." >&2
exit 1
fi
dst=$dst_arg
# If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored.
if test -d "$dst"; then
if test -n "$no_target_directory"; then
echo "$0: $dst_arg: Is a directory" >&2
exit 1
fi
dstdir=$dst
dst=$dstdir/`basename "$src"`
dstdir_status=0
else
# Prefer dirname, but fall back on a substitute if dirname fails.
dstdir=`
(dirname "$dst") 2>/dev/null ||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
X"$dst" : 'X\(//\)[^/]' \| \
X"$dst" : 'X\(//\)$' \| \
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
echo X"$dst" |
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
s//\1/
q
}
/^X\(\/\/\)[^/].*/{
s//\1/
q
}
/^X\(\/\/\)$/{
s//\1/
q
}
/^X\(\/\).*/{
s//\1/
q
}
s/.*/./; q'
`
test -d "$dstdir"
dstdir_status=$?
fi
fi
obsolete_mkdir_used=false
if test $dstdir_status != 0; then
case $posix_mkdir in
'')
# Create intermediate dirs using mode 755 as modified by the umask.
# This is like FreeBSD 'install' as of 1997-10-28.
umask=`umask`
case $stripcmd.$umask in
# Optimize common cases.
*[2367][2367]) mkdir_umask=$umask;;
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
*[0-7])
mkdir_umask=`expr $umask + 22 \
- $umask % 100 % 40 + $umask % 20 \
- $umask % 10 % 4 + $umask % 2
`;;
*) mkdir_umask=$umask,go-w;;
esac
# With -d, create the new directory with the user-specified mode.
# Otherwise, rely on $mkdir_umask.
if test -n "$dir_arg"; then
mkdir_mode=-m$mode
else
mkdir_mode=
fi
posix_mkdir=false
case $umask in
*[123567][0-7][0-7])
# POSIX mkdir -p sets u+wx bits regardless of umask, which
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
;;
*)
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
if (umask $mkdir_umask &&
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
then
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
# other-writable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
ls_ld_tmpdir=`ls -ld "$tmpdir"`
case $ls_ld_tmpdir in
d????-?r-*) different_mode=700;;
d????-?--*) different_mode=755;;
*) false;;
esac &&
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
}
}
then posix_mkdir=:
fi
rmdir "$tmpdir/d" "$tmpdir"
else
# Remove any dirs left behind by ancient mkdir implementations.
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
fi
trap '' 0;;
esac;;
esac
if
$posix_mkdir && (
umask $mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
)
then :
else
# The umask is ridiculous, or mkdir does not conform to POSIX,
# or it failed possibly due to a race condition. Create the
# directory the slow way, step by step, checking for races as we go.
case $dstdir in
/*) prefix='/';;
[-=\(\)!]*) prefix='./';;
*) prefix='';;
esac
eval "$initialize_posix_glob"
oIFS=$IFS
IFS=/
$posix_glob set -f
set fnord $dstdir
shift
$posix_glob set +f
IFS=$oIFS
prefixes=
for d
do
test X"$d" = X && continue
prefix=$prefix$d
if test -d "$prefix"; then
prefixes=
else
if $posix_mkdir; then
(umask=$mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
# Don't fail if two instances are running concurrently.
test -d "$prefix" || exit 1
else
case $prefix in
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
*) qprefix=$prefix;;
esac
prefixes="$prefixes '$qprefix'"
fi
fi
prefix=$prefix/
done
if test -n "$prefixes"; then
# Don't fail if two instances are running concurrently.
(umask $mkdir_umask &&
eval "\$doit_exec \$mkdirprog $prefixes") ||
test -d "$dstdir" || exit 1
obsolete_mkdir_used=true
fi
fi
fi
if test -n "$dir_arg"; then
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
else
# Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_
rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit.
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
# Copy the file name to the temp name.
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $cpprog $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
# If -C, don't bother to copy if it wouldn't change the file.
if $copy_on_change &&
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
eval "$initialize_posix_glob" &&
$posix_glob set -f &&
set X $old && old=:$2:$4:$5:$6 &&
set X $new && new=:$2:$4:$5:$6 &&
$posix_glob set +f &&
test "$old" = "$new" &&
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
then
rm -f "$dsttmp"
else
# Rename the file to the real destination.
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
# The rename failed, perhaps because mv can't rename something else
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
{
# Now remove or move aside any old file at destination location.
# We try this two ways since rm can't unlink itself on some
# systems and the destination file might be busy for other
# reasons. In this case, the final cleanup might fail but the new
# file should still install successfully.
{
test ! -f "$dst" ||
$doit $rmcmd -f "$dst" 2>/dev/null ||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
} ||
{ echo "$0: cannot unlink or rename $dst" >&2
(exit 1); exit 1
}
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dst"
}
fi || exit 1
trap '' 0
fi
done
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:

2532
interface.c Normal file

File diff suppressed because it is too large Load diff

86
interface.h Normal file
View file

@ -0,0 +1,86 @@
/*
This file is part of telegram-cli.
Telegram-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-cli 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-cli. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013-2014
*/
#ifndef __INTERFACE_H__
#define __INTERFACE_H__
#include "structures.h"
#include "tgl-layout.h"
#define COLOR_RED "\033[0;31m"
#define COLOR_REDB "\033[1;31m"
#define COLOR_NORMAL "\033[0m"
#define COLOR_GREEN "\033[32;1m"
#define COLOR_GREY "\033[37;1m"
#define COLOR_YELLOW "\033[33;1m"
#define COLOR_BLUE "\033[34;1m"
#define COLOR_MAGENTA "\033[35;1m"
#define COLOR_CYAN "\033[36;1m"
#define COLOR_LCYAN "\033[0;36m"
#define COLOR_INVERSE "\033[7m"
char *get_default_prompt (void);
char *complete_none (const char *text, int state);
char **complete_text (char *text, int start, int end);
void interpreter (char *line);
void interpreter_ex (char *line, void *ex);
void rprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
#define vlogprintf(v,...) \
do { \
if (tgl_state.verbosity >= (v)) {\
logprintf (__VA_ARGS__);\
}\
} while (0);\
//void hexdump (int *in_ptr, int *in_end);
struct bufferevent;
struct in_ev {
struct bufferevent *bev;
char in_buf[4096];
int in_buf_pos;
int refcnt;
int error;
int fd;
};
struct tgl_message;
struct in_ev;
void print_message (struct in_ev *ev, struct tgl_message *M);
void print_chat_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
void print_user_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *U);
void print_encr_chat_name_full (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
void print_encr_chat_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
//void print_media (struct tgl_message_media *M);
//
void pop_color (void);
void push_color (const char *color);
void print_start (void);
void print_end (void);
void print_date_full (struct in_ev *ev, long t);
void print_date (struct in_ev *ev, long t);
void play_sound (void);
void update_prompt (void);
void set_interface_callbacks (void);
#endif

854
loop.c Normal file
View file

@ -0,0 +1,854 @@
/*
This file is part of telegram-cli.
Telegram-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-cli 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-cli. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013-2014
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _GNU_SOURCE
#define READLINE_CALLBACKS
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef READLINE_GNU
#include <readline/readline.h>
#include <readline/history.h>
#else
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include <errno.h>
#include <poll.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <netinet/in.h>
#ifdef EVENT_V2
#include <event2/event.h>
#include <event2/bufferevent.h>
#else
#include <event.h>
#include "event-old.h"
#endif
#include "interface.h"
#include "telegram.h"
#include "loop.h"
#include "lua-tg.h"
#include "tgl.h"
#include "binlog.h"
int verbosity;
extern int readline_disabled;
int binlog_read;
extern char *default_username;
extern char *auth_token;
void set_default_username (const char *s);
extern int binlog_enabled;
extern int unknown_user_list_pos;
extern int unknown_user_list[];
int register_mode;
extern int safe_quit;
extern int sync_from_start;
extern int disable_output;
extern int reset_authorization;
extern int sfd;
extern int usfd;
void got_it (char *line, int len);
void write_state_file (void);
static char *line_buffer;
static int line_buffer_size;
static int line_buffer_pos;
static int delete_stdin_event;
extern volatile int sigterm_cnt;
static void stdin_read_callback_all (int arg, short what, struct event *self) {
if (!readline_disabled) {
if (((long)arg) & 1) {
rl_callback_read_char ();
} else {
char *line = 0;
size_t len = 0;
assert (getline (&line, &len, stdin) >= 0);
got_it (line, strlen (line));
}
} else {
while (1) {
if (line_buffer_pos == line_buffer_size) {
line_buffer = realloc (line_buffer, line_buffer_size * 2 + 100);
assert (line_buffer);
line_buffer_size = line_buffer_size * 2 + 100;
assert (line_buffer);
}
int r = read (0, line_buffer + line_buffer_pos, line_buffer_size - line_buffer_pos);
//logprintf ("r = %d, size = %d, pos = %d, what = 0x%x, fd = %d\n", r, line_buffer_size, line_buffer_pos, (int)what, fd);
if (r < 0) {
perror ("read");
break;
}
if (r == 0) {
//struct event *ev = event_base_get_running_event (tgl_state.ev_base);
//event_del (ev);
//event_del (self);
delete_stdin_event = 1;
break;
}
line_buffer_pos += r;
while (1) {
int p = 0;
while (p < line_buffer_pos && line_buffer[p] != '\n') { p ++; }
if (p < line_buffer_pos) {
if (((long)arg) & 1) {
line_buffer[p] = 0;
interpreter (line_buffer);
} else {
got_it (line_buffer, p + 1);
}
memmove (line_buffer, line_buffer + p + 1, line_buffer_pos - p - 1);
line_buffer_pos -= (p + 1);
} else {
break;
}
}
break;
}
}
}
static void stdin_read_callback_char (evutil_socket_t fd, short what, void *arg) {
stdin_read_callback_all (1, what, arg);
}
static void stdin_read_callback_line (evutil_socket_t fd, short what, void *arg) {
stdin_read_callback_all (2, what, arg);
}
struct event *term_ev = 0;
void net_loop (int flags, int (*is_end)(void)) {
delete_stdin_event = 0;
if (verbosity >= E_DEBUG) {
logprintf ("Starting netloop\n");
}
if (flags & 3) {
if (flags & 1) {
term_ev = event_new (tgl_state.ev_base, 0, EV_READ | EV_PERSIST, stdin_read_callback_char, 0);
} else {
term_ev = event_new (tgl_state.ev_base, 0, EV_READ | EV_PERSIST, stdin_read_callback_line, 0);
}
event_add (term_ev, 0);
}
int last_get_state = time (0);
while (!is_end || !is_end ()) {
event_base_loop (tgl_state.ev_base, EVLOOP_ONCE);
if (term_ev && delete_stdin_event) {
event_free (term_ev);
term_ev = 0;
}
#ifdef USE_LUA
lua_do_all ();
#endif
if (safe_quit && !tgl_state.active_queries) {
printf ("All done. Exit\n");
do_halt (0);
}
if (sigterm_cnt > 0) {
do_halt (0);
}
if (time (0) - last_get_state > 3600) {
tgl_do_lookup_state ();
last_get_state = time (0);
}
write_state_file ();
update_prompt ();
if (unknown_user_list_pos) {
int i;
for (i = 0; i < unknown_user_list_pos; i++) {
tgl_do_get_user_info (TGL_MK_USER (unknown_user_list[i]), 0, 0, 0);
}
unknown_user_list_pos = 0;
}
}
if (term_ev) {
event_free (term_ev);
term_ev = 0;
}
if (verbosity >= E_DEBUG) {
logprintf ("End of netloop\n");
}
}
char **_s;
size_t *_l;
int got_it_ok;
void got_it (char *line, int len) {
assert (len > 0);
line[-- len] = 0; // delete end of line
*_s = line;
*_l = len;
got_it_ok = 1;
}
int is_got_it (void) {
return got_it_ok;
}
int net_getline (char **s, size_t *l) {
fflush (stdout);
// rl_already_prompted = 1;
got_it_ok = 0;
_s = s;
_l = l;
// rl_callback_handler_install (0, got_it);
net_loop (2, is_got_it);
return 0;
}
int main_loop (void) {
net_loop (1, 0);
return 0;
}
struct tgl_dc *cur_a_dc;
int is_authorized (void) {
return tgl_authorized_dc (cur_a_dc);
}
int all_authorized (void) {
int i;
for (i = 0; i <= tgl_state.max_dc_num; i++) if (tgl_state.DC_list[i]) {
if (!tgl_authorized_dc (tgl_state.DC_list[i])) {
return 0;
}
}
return 1;
}
int config_got;
int got_config (void) {
return config_got;
}
void on_get_config (void *extra, int success) {
if (!success) {
logprintf ("Can not get config.\n");
do_halt (1);
}
config_got = 1;
}
int should_register;
char *hash;
void sign_in_callback (void *extra, int success, int registered, const char *mhash) {
if (!success) {
logprintf ("Can not send code\n");
do_halt (1);
}
should_register = !registered;
hash = strdup (mhash);
assert (hash);
}
int signed_in_ok;
void sign_in_result (void *extra, int success, struct tgl_user *U) {
if (!success) {
logprintf ("Can not login\n");
do_halt (1);
}
signed_in_ok = 1;
}
int signed_in (void) {
return signed_in_ok;
}
int sent_code (void) {
return hash != 0;
}
int dc_signed_in (void) {
return tgl_signed_dc (cur_a_dc);
}
void export_auth_callback (void *DC, int success) {
if (!success) {
logprintf ("Can not export auth\n");
do_halt (1);
}
}
int d_got_ok;
void get_difference_callback (void *extra, int success) {
assert (success);
d_got_ok = 1;
}
int dgot (void) {
return d_got_ok;
}
int zero[512];
int readline_active;
int new_dc_num;
int wait_dialog_list;
extern struct tgl_update_callback upd_cb;
#define DC_SERIALIZED_MAGIC 0x868aa81d
#define STATE_FILE_MAGIC 0x28949a93
#define SECRET_CHAT_FILE_MAGIC 0x37a1988a
char *get_auth_key_filename (void);
char *get_state_filename (void);
char *get_secret_chat_filename (void);
void read_state_file (void) {
if (binlog_enabled) { return; }
int state_file_fd = open (get_state_filename (), O_CREAT | O_RDWR, 0600);
if (state_file_fd < 0) {
return;
}
int version, magic;
if (read (state_file_fd, &magic, 4) < 4) { close (state_file_fd); return; }
if (magic != (int)STATE_FILE_MAGIC) { close (state_file_fd); return; }
if (read (state_file_fd, &version, 4) < 4) { close (state_file_fd); return; }
assert (version >= 0);
int x[4];
if (read (state_file_fd, x, 16) < 16) {
close (state_file_fd);
return;
}
int pts = x[0];
int qts = x[1];
int seq = x[2];
int date = x[3];
close (state_file_fd);
bl_do_set_seq (seq);
bl_do_set_pts (pts);
bl_do_set_qts (qts);
bl_do_set_date (date);
}
void write_state_file (void) {
if (binlog_enabled) { return; }
static int wseq;
static int wpts;
static int wqts;
static int wdate;
if (wseq >= tgl_state.seq && wpts >= tgl_state.pts && wqts >= tgl_state.qts && wdate >= tgl_state.date) { return; }
wseq = tgl_state.seq; wpts = tgl_state.pts; wqts = tgl_state.qts; wdate = tgl_state.date;
int state_file_fd = open (get_state_filename (), O_CREAT | O_RDWR, 0600);
if (state_file_fd < 0) {
logprintf ("Can not write state file '%s': %m\n", get_state_filename ());
do_halt (1);
}
int x[6];
x[0] = STATE_FILE_MAGIC;
x[1] = 0;
x[2] = wpts;
x[3] = wqts;
x[4] = wseq;
x[5] = wdate;
assert (write (state_file_fd, x, 24) == 24);
close (state_file_fd);
}
void write_dc (struct tgl_dc *DC, void *extra) {
int auth_file_fd = *(int *)extra;
if (!DC) {
int x = 0;
assert (write (auth_file_fd, &x, 4) == 4);
return;
} else {
int x = 1;
assert (write (auth_file_fd, &x, 4) == 4);
}
assert (DC->has_auth);
assert (write (auth_file_fd, &DC->port, 4) == 4);
int l = strlen (DC->ip);
assert (write (auth_file_fd, &l, 4) == 4);
assert (write (auth_file_fd, DC->ip, l) == l);
assert (write (auth_file_fd, &DC->auth_key_id, 8) == 8);
assert (write (auth_file_fd, DC->auth_key, 256) == 256);
}
void write_auth_file (void) {
if (binlog_enabled) { return; }
int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
assert (auth_file_fd >= 0);
int x = DC_SERIALIZED_MAGIC;
assert (write (auth_file_fd, &x, 4) == 4);
assert (write (auth_file_fd, &tgl_state.max_dc_num, 4) == 4);
assert (write (auth_file_fd, &tgl_state.dc_working_num, 4) == 4);
tgl_dc_iterator_ex (write_dc, &auth_file_fd);
assert (write (auth_file_fd, &tgl_state.our_id, 4) == 4);
close (auth_file_fd);
}
void write_secret_chat (tgl_peer_t *_P, void *extra) {
struct tgl_secret_chat *P = (void *)_P;
if (tgl_get_peer_type (P->id) != TGL_PEER_ENCR_CHAT) { return; }
if (P->state != sc_ok) { return; }
int *a = extra;
int fd = a[0];
a[1] ++;
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);
assert (write (fd, &P->user_id, 4) == 4);
assert (write (fd, &P->admin_id, 4) == 4);
assert (write (fd, &P->date, 4) == 4);
assert (write (fd, &P->ttl, 4) == 4);
assert (write (fd, &P->layer, 4) == 4);
assert (write (fd, &P->access_hash, 8) == 8);
assert (write (fd, &P->state, 4) == 4);
assert (write (fd, &P->key_fingerprint, 8) == 8);
assert (write (fd, &P->key, 256) == 256);
}
void write_secret_chat_file (void) {
if (binlog_enabled) { return; }
int secret_chat_fd = open (get_secret_chat_filename (), O_CREAT | O_RDWR, 0600);
assert (secret_chat_fd >= 0);
int x = SECRET_CHAT_FILE_MAGIC;
assert (write (secret_chat_fd, &x, 4) == 4);
x = 0;
assert (write (secret_chat_fd, &x, 4) == 4); // version
assert (write (secret_chat_fd, &x, 4) == 4); // num
int y[2];
y[0] = secret_chat_fd;
y[1] = 0;
tgl_peer_iterator_ex (write_secret_chat, y);
lseek (secret_chat_fd, 8, SEEK_SET);
assert (write (secret_chat_fd, &y[1], 4) == 4);
close (secret_chat_fd);
}
void read_dc (int auth_file_fd, int id, unsigned ver) {
int port = 0;
assert (read (auth_file_fd, &port, 4) == 4);
int l = 0;
assert (read (auth_file_fd, &l, 4) == 4);
assert (l >= 0 && l < 100);
char ip[100];
assert (read (auth_file_fd, ip, l) == l);
ip[l] = 0;
long long auth_key_id;
static unsigned char auth_key[256];
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 (id, 2, "DC", l, ip, port);
bl_do_set_auth_key_id (id, auth_key);
bl_do_dc_signed (id);
}
void empty_auth_file (void) {
char *ip = tgl_state.test_mode ? TG_SERVER_TEST : TG_SERVER;
bl_do_dc_option (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC, 0, "", strlen (ip), ip, 443);
bl_do_set_working_dc (tgl_state.test_mode ? TG_SERVER_TEST_DC : TG_SERVER_DC);
}
int need_dc_list_update;
void read_auth_file (void) {
if (binlog_enabled) { return; }
int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
if (auth_file_fd < 0) {
empty_auth_file ();
return;
}
assert (auth_file_fd >= 0);
unsigned x;
unsigned m;
if (read (auth_file_fd, &m, 4) < 4 || (m != DC_SERIALIZED_MAGIC)) {
close (auth_file_fd);
empty_auth_file ();
return;
}
assert (read (auth_file_fd, &x, 4) == 4);
assert (x > 0);
int dc_working_num;
assert (read (auth_file_fd, &dc_working_num, 4) == 4);
int i;
for (i = 0; i <= (int)x; i++) {
int y;
assert (read (auth_file_fd, &y, 4) == 4);
if (y) {
read_dc (auth_file_fd, i, m);
}
}
bl_do_set_working_dc (dc_working_num);
int our_id;
int l = read (auth_file_fd, &our_id, 4);
if (l < 4) {
assert (!l);
}
if (our_id) {
bl_do_set_our_id (our_id);
}
close (auth_file_fd);
}
void read_secret_chat (int fd) {
int id, l, user_id, admin_id, date, ttl, layer, state;
long long access_hash, key_fingerprint;
static char s[1000];
static unsigned char key[256];
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);
assert (read (fd, &user_id, 4) == 4);
assert (read (fd, &admin_id, 4) == 4);
assert (read (fd, &date, 4) == 4);
assert (read (fd, &ttl, 4) == 4);
assert (read (fd, &layer, 4) == 4);
assert (read (fd, &access_hash, 8) == 8);
assert (read (fd, &state, 4) == 4);
assert (read (fd, &key_fingerprint, 8) == 8);
assert (read (fd, &key, 256) == 256);
bl_do_encr_chat_create (id, user_id, admin_id, s, l);
struct tgl_secret_chat *P = (void *)tgl_peer_get (TGL_MK_ENCR_CHAT (id));
assert (P && (P->flags & FLAG_CREATED));
bl_do_encr_chat_set_date (P, date);
bl_do_encr_chat_set_ttl (P, ttl);
bl_do_encr_chat_set_layer (P, layer);
bl_do_encr_chat_set_access_hash (P, access_hash);
bl_do_encr_chat_set_state (P, state);
bl_do_encr_chat_set_key (P, key, key_fingerprint);
}
void read_secret_chat_file (void) {
if (binlog_enabled) { return; }
int secret_chat_fd = open (get_secret_chat_filename (), O_RDWR, 0600);
if (secret_chat_fd < 0) { return; }
//assert (secret_chat_fd >= 0);
int x;
if (read (secret_chat_fd, &x, 4) < 4) { close (secret_chat_fd); return; }
if (x != SECRET_CHAT_FILE_MAGIC) { close (secret_chat_fd); return; }
assert (read (secret_chat_fd, &x, 4) == 4);
assert (!x); // version
assert (read (secret_chat_fd, &x, 4) == 4);
assert (x >= 0);
while (x --> 0) {
read_secret_chat (secret_chat_fd);
}
close (secret_chat_fd);
}
void dlist_cb (void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]) {
d_got_ok = 1;
}
static void read_incoming (struct bufferevent *bev, void *_arg) {
vlogprintf (E_WARNING, "Read from incoming connection\n");
struct in_ev *ev = _arg;
assert (ev->bev == bev);
ev->in_buf_pos += bufferevent_read (bev, ev->in_buf + ev->in_buf_pos, 4096 - ev->in_buf_pos);
while (1) {
int pos = 0;
int ok = 0;
while (pos < ev->in_buf_pos) {
if (ev->in_buf[pos] == '\n') {
if (!ev->error) {
ev->in_buf[pos] = 0;
interpreter_ex (ev->in_buf, ev);
} else {
ev->error = 0;
}
ok = 1;
ev->in_buf_pos -= (pos + 1);
memmove (ev->in_buf, ev->in_buf + pos + 1, ev->in_buf_pos);
pos = 0;
} else {
pos ++;
}
}
if (ok) {
ev->in_buf_pos += bufferevent_read (bev, ev->in_buf + ev->in_buf_pos, 4096 - ev->in_buf_pos);
} else {
if (ev->in_buf_pos == 4096) {
ev->error = 1;
}
break;
}
}
}
static void event_incoming (struct bufferevent *bev, short what, void *_arg) {
struct in_ev *ev = _arg;
if (what & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
vlogprintf (E_WARNING, "Closing incoming connection\n");
assert (ev->fd >= 0);
close (ev->fd);
bufferevent_free (bev);
ev->bev = 0;
if (!--ev->refcnt) { free (ev); }
}
}
static void accept_incoming (evutil_socket_t efd, short what, void *arg) {
vlogprintf (E_WARNING, "Accepting incoming connection\n");
unsigned clilen;
struct sockaddr_in cli_addr;
int fd = accept (efd, (struct sockaddr *)&cli_addr, &clilen);
assert (fd >= 0);
struct bufferevent *bev = bufferevent_socket_new (tgl_state.ev_base, fd, 0);
struct in_ev *e = malloc (sizeof (*e));
e->bev = bev;
e->refcnt = 1;
e->in_buf_pos = 0;
e->error = 0;
e->fd = fd;
bufferevent_setcb (bev, read_incoming, 0, event_incoming, e);
bufferevent_enable(bev, EV_READ|EV_WRITE);
}
int loop (void) {
//on_start ();
tgl_set_callback (&upd_cb);
//tgl_state.temp_key_expire_time = 60;
tgl_init ();
if (binlog_enabled) {
double t = tglt_get_double_time ();
if (verbosity >= E_DEBUG) {
logprintf ("replay log start\n");
}
tgl_replay_log ();
if (verbosity >= E_DEBUG) {
logprintf ("replay log end in %lf seconds\n", tglt_get_double_time () - t);
}
tgl_reopen_binlog_for_writing ();
} else {
read_auth_file ();
read_state_file ();
read_secret_chat_file ();
}
binlog_read = 1;
#ifdef USE_LUA
lua_binlog_end ();
#endif
if (sfd >= 0) {
struct event *ev = event_new (tgl_state.ev_base, sfd, EV_READ | EV_PERSIST, accept_incoming, 0);
event_add (ev, 0);
}
if (usfd >= 0) {
struct event *ev = event_new (tgl_state.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 (TGL_MK_USER (tgl_state.our_id));
if (P && P->user.phone && reset_authorization == 1) {
set_default_username (P->user.phone);
}
bl_do_reset_authorization ();
}
net_loop (0, all_authorized);
int i;
for (i = 0; i <= tgl_state.max_dc_num; i++) if (tgl_state.DC_list[i] && !tgl_authorized_dc (tgl_state.DC_list[i])) {
assert (0);
}
if (!tgl_signed_dc (tgl_state.DC_working)) {
if (disable_output) {
fprintf (stderr, "Can not login without output\n");
do_halt (1);
}
if (!default_username) {
size_t size = 0;
char *user = 0;
if (!user) {
printf ("Telephone number (with '+' sign): ");
if (net_getline (&user, &size) == -1) {
perror ("getline()");
do_halt (1);
}
set_default_username (user);
}
}
tgl_do_send_code (default_username, sign_in_callback, 0);
net_loop (0, sent_code);
if (verbosity >= E_DEBUG) {
logprintf ("%s\n", should_register ? "phone not registered" : "phone registered");
}
if (!should_register) {
char *code = 0;
size_t size = 0;
printf ("Code from sms (if you did not receive an SMS and want to be called, type \"call\"): ");
while (1) {
if (net_getline (&code, &size) == -1) {
perror ("getline()");
do_halt (1);
}
if (!strcmp (code, "call")) {
printf ("You typed \"call\", switching to phone system.\n");
tgl_do_phone_call (default_username, hash, 0, 0);
printf ("Calling you! Code: ");
continue;
}
if (tgl_do_send_code_result (default_username, hash, code, sign_in_result, 0) >= 0) {
break;
}
printf ("Invalid code. Try again: ");
free (code);
}
} else {
printf ("User is not registered. Do you want to register? [Y/n] ");
char *code;
size_t size;
if (net_getline (&code, &size) == -1) {
perror ("getline()");
do_halt (1);
}
if (!*code || *code == 'y' || *code == 'Y') {
printf ("Ok, starting registartion.\n");
} else {
printf ("Then try again\n");
do_halt (1);
}
char *first_name;
printf ("First name: ");
if (net_getline (&first_name, &size) == -1) {
perror ("getline()");
do_halt (1);
}
char *last_name;
printf ("Last name: ");
if (net_getline (&last_name, &size) == -1) {
perror ("getline()");
do_halt (1);
}
printf ("Code from sms (if you did not receive an SMS and want to be called, type \"call\"): ");
while (1) {
if (net_getline (&code, &size) == -1) {
perror ("getline()");
do_halt (1);
}
if (!strcmp (code, "call")) {
printf ("You typed \"call\", switching to phone system.\n");
tgl_do_phone_call (default_username, hash, 0, 0);
printf ("Calling you! Code: ");
continue;
}
if (tgl_do_send_code_result_auth (default_username, hash, code, first_name, last_name, sign_in_result, 0) >= 0) {
break;
}
printf ("Invalid code. Try again: ");
free (code);
}
}
net_loop (0, signed_in);
//bl_do_dc_signed (tgl_state.DC_working);
}
for (i = 0; i <= tgl_state.max_dc_num; i++) if (tgl_state.DC_list[i] && !tgl_signed_dc (tgl_state.DC_list[i])) {
tgl_do_export_auth (i, export_auth_callback, (void*)(long)tgl_state.DC_list[i]);
cur_a_dc = tgl_state.DC_list[i];
net_loop (0, dc_signed_in);
assert (tgl_signed_dc (tgl_state.DC_list[i]));
}
write_auth_file ();
fflush (stdout);
fflush (stderr);
//read_state_file ();
//read_secret_chat_file ();
set_interface_callbacks ();
tglm_send_all_unsent ();
tgl_do_get_difference (sync_from_start, get_difference_callback, 0);
net_loop (0, dgot);
assert (!(tgl_state.locks & TGL_LOCK_DIFF));
tgl_state.started = 1;
if (wait_dialog_list) {
d_got_ok = 0;
tgl_do_get_dialog_list (dlist_cb, 0);
net_loop (0, dgot);
}
#ifdef USE_LUA
lua_diff_end ();
#endif
/*tgl_do_get_dialog_list (get_dialogs_callback, 0);
if (wait_dialog_list) {
dialog_list_got = 0;
net_loop (0, dlgot);
}*/
return main_loop ();
}

27
loop.h Normal file
View file

@ -0,0 +1,27 @@
/*
This file is part of telegram-cli.
Telegram-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-cli 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-cli. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013-2014
*/
#ifndef __LOOP_H__
#define __LOOP_H__
int loop (void);
void do_halt (int error);
void net_loop (int flags, int (*end)(void));
void write_auth_file (void);
void write_state_file (void);
void write_secret_chat_file (void);
#endif

1448
lua-tg.c Normal file

File diff suppressed because it is too large Load diff

35
lua-tg.h Normal file
View file

@ -0,0 +1,35 @@
/*
This file is part of telegram-cli.
Telegram-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-cli 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-cli. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013-2014
*/
#ifndef __LUA_TG_H__
#define __LUA_TG_H__
#include <string.h>
#include "lua-tg.h"
#include "tgl.h"
void lua_init (const char *file);
void lua_new_msg (struct tgl_message *M);
void lua_our_id (int id);
void lua_secret_chat_update (struct tgl_secret_chat *U, unsigned flags);
void lua_user_update (struct tgl_user *U, unsigned flags);
void lua_chat_update (struct tgl_chat *C, unsigned flags);
void lua_binlog_end (void);
void lua_diff_end (void);
void lua_do_all (void);
#endif

168
m4-ax_gcc_builtin.m4 Normal file
View file

@ -0,0 +1,168 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_GCC_BUILTIN(BUILTIN)
#
# DESCRIPTION
#
# This macro checks if the compiler supports one of GCC's built-in
# functions; many other compilers also provide those same built-ins.
#
# The BUILTIN parameter is the name of the built-in function.
#
# If BUILTIN is supported define HAVE_<BUILTIN>. Keep in mind that since
# builtins usually start with two underscores they will be copied over
# into the HAVE_<BUILTIN> definition (e.g. HAVE___BUILTIN_EXPECT for
# __builtin_expect()).
#
# The macro caches its result in the ax_cv_have_<BUILTIN> variable (e.g.
# ax_cv_have___builtin_expect).
#
# The macro currently supports the following built-in functions:
#
# __builtin_assume_aligned
# __builtin_bswap32
# __builtin_bswap64
# __builtin_choose_expr
# __builtin___clear_cache
# __builtin_clrsb
# __builtin_clrsbl
# __builtin_clrsbll
# __builtin_clz
# __builtin_clzl
# __builtin_clzll
# __builtin_complex
# __builtin_constant_p
# __builtin_ctz
# __builtin_ctzl
# __builtin_ctzll
# __builtin_expect
# __builtin_ffs
# __builtin_ffsl
# __builtin_ffsll
# __builtin_fpclassify
# __builtin_huge_val
# __builtin_huge_valf
# __builtin_huge_vall
# __builtin_inf
# __builtin_infd128
# __builtin_infd32
# __builtin_infd64
# __builtin_inff
# __builtin_infl
# __builtin_isinf_sign
# __builtin_nan
# __builtin_nand128
# __builtin_nand32
# __builtin_nand64
# __builtin_nanf
# __builtin_nanl
# __builtin_nans
# __builtin_nansf
# __builtin_nansl
# __builtin_object_size
# __builtin_parity
# __builtin_parityl
# __builtin_parityll
# __builtin_popcount
# __builtin_popcountl
# __builtin_popcountll
# __builtin_powi
# __builtin_powif
# __builtin_powil
# __builtin_prefetch
# __builtin_trap
# __builtin_types_compatible_p
# __builtin_unreachable
#
# Unsuppored built-ins will be tested with an empty parameter set and the
# result of the check might be wrong or meaningless so use with care.
#
# LICENSE
#
# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 2
AC_DEFUN([AX_GCC_BUILTIN], [
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$1])
AC_CACHE_CHECK([for $1], [ac_var], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
m4_case([$1],
[__builtin_assume_aligned], [$1("", 0)],
[__builtin_bswap32], [$1(0)],
[__builtin_bswap64], [$1(0)],
[__builtin_choose_expr], [$1(0, 0, 0)],
[__builtin___clear_cache], [$1("", "")],
[__builtin_clrsb], [$1(0)],
[__builtin_clrsbl], [$1(0)],
[__builtin_clrsbll], [$1(0)],
[__builtin_clz], [$1(0)],
[__builtin_clzl], [$1(0)],
[__builtin_clzll], [$1(0)],
[__builtin_complex], [$1(0.0, 0.0)],
[__builtin_constant_p], [$1(0)],
[__builtin_ctz], [$1(0)],
[__builtin_ctzl], [$1(0)],
[__builtin_ctzll], [$1(0)],
[__builtin_expect], [$1(0, 0)],
[__builtin_ffs], [$1(0)],
[__builtin_ffsl], [$1(0)],
[__builtin_ffsll], [$1(0)],
[__builtin_fpclassify], [$1(0, 1, 2, 3, 4, 0.0)],
[__builtin_huge_val], [$1()],
[__builtin_huge_valf], [$1()],
[__builtin_huge_vall], [$1()],
[__builtin_inf], [$1()],
[__builtin_infd128], [$1()],
[__builtin_infd32], [$1()],
[__builtin_infd64], [$1()],
[__builtin_inff], [$1()],
[__builtin_infl], [$1()],
[__builtin_isinf_sign], [$1(0.0)],
[__builtin_nan], [$1("")],
[__builtin_nand128], [$1("")],
[__builtin_nand32], [$1("")],
[__builtin_nand64], [$1("")],
[__builtin_nanf], [$1("")],
[__builtin_nanl], [$1("")],
[__builtin_nans], [$1("")],
[__builtin_nansf], [$1("")],
[__builtin_nansl], [$1("")],
[__builtin_object_size], [$1("", 0)],
[__builtin_parity], [$1(0)],
[__builtin_parityl], [$1(0)],
[__builtin_parityll], [$1(0)],
[__builtin_popcount], [$1(0)],
[__builtin_popcountl], [$1(0)],
[__builtin_popcountll], [$1(0)],
[__builtin_powi], [$1(0, 0)],
[__builtin_powif], [$1(0, 0)],
[__builtin_powil], [$1(0, 0)],
[__builtin_prefetch], [$1("")],
[__builtin_trap], [$1()],
[__builtin_types_compatible_p], [$1(int, int)],
[__builtin_unreachable], [$1()],
[m4_warn([syntax], [Unsupported built-in $1, the test may fail])
$1()]
)
])],
[AS_VAR_SET([ac_var], [yes])],
[AS_VAR_SET([ac_var], [no])])
])
AS_IF([test yes = AS_VAR_GET([ac_var])],
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1,
[Define to 1 if the system has the `$1' built-in function])], [])
AS_VAR_POPDEF([ac_var])
])

View file

@ -1,214 +0,0 @@
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
# serial 1 (pkg-config-0.24)
#
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
# ----------------------------------
AC_DEFUN([PKG_PROG_PKG_CONFIG],
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
fi
if test -n "$PKG_CONFIG"; then
_pkg_min_version=m4_default([$1], [0.9.0])
AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
PKG_CONFIG=""
fi
fi[]dnl
])# PKG_PROG_PKG_CONFIG
# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
#
# Check to see whether a particular set of modules exists. Similar
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
#
# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
# only at the first occurence in configure.ac, so if the first place
# it's called might be skipped (such as if it is within an "if", you
# have to call PKG_CHECK_EXISTS manually
# --------------------------------------------------------------
AC_DEFUN([PKG_CHECK_EXISTS],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
if test -n "$PKG_CONFIG" && \
AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
m4_default([$2], [:])
m4_ifvaln([$3], [else
$3])dnl
fi])
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
# ---------------------------------------------
m4_define([_PKG_CONFIG],
[if test -n "$$1"; then
pkg_cv_[]$1="$$1"
elif test -n "$PKG_CONFIG"; then
PKG_CHECK_EXISTS([$3],
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes ],
[pkg_failed=yes])
else
pkg_failed=untried
fi[]dnl
])# _PKG_CONFIG
# _PKG_SHORT_ERRORS_SUPPORTED
# -----------------------------
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
_pkg_short_errors_supported=yes
else
_pkg_short_errors_supported=no
fi[]dnl
])# _PKG_SHORT_ERRORS_SUPPORTED
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
# [ACTION-IF-NOT-FOUND])
#
#
# Note that if there is a possibility the first call to
# PKG_CHECK_MODULES might not happen, you should be sure to include an
# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
#
#
# --------------------------------------------------------------
AC_DEFUN([PKG_CHECK_MODULES],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
pkg_failed=no
AC_MSG_CHECKING([for $1])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
and $1[]_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
m4_default([$4], [AC_MSG_ERROR(
[Package requirements ($2) were not met:
$$1_PKG_ERRORS
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
_PKG_TEXT])[]dnl
])
elif test $pkg_failed = untried; then
AC_MSG_RESULT([no])
m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
_PKG_TEXT
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
])
else
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
AC_MSG_RESULT([yes])
$3
fi[]dnl
])# PKG_CHECK_MODULES
# PKG_INSTALLDIR(DIRECTORY)
# -------------------------
# Substitutes the variable pkgconfigdir as the location where a module
# should install pkg-config .pc files. By default the directory is
# $libdir/pkgconfig, but the default can be changed by passing
# DIRECTORY. The user can override through the --with-pkgconfigdir
# parameter.
AC_DEFUN([PKG_INSTALLDIR],
[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
m4_pushdef([pkg_description],
[pkg-config installation directory @<:@]pkg_default[@:>@])
AC_ARG_WITH([pkgconfigdir],
[AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
[with_pkgconfigdir=]pkg_default)
AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
m4_popdef([pkg_default])
m4_popdef([pkg_description])
]) dnl PKG_INSTALLDIR
# PKG_NOARCH_INSTALLDIR(DIRECTORY)
# -------------------------
# Substitutes the variable noarch_pkgconfigdir as the location where a
# module should install arch-independent pkg-config .pc files. By
# default the directory is $datadir/pkgconfig, but the default can be
# changed by passing DIRECTORY. The user can override through the
# --with-noarch-pkgconfigdir parameter.
AC_DEFUN([PKG_NOARCH_INSTALLDIR],
[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
m4_pushdef([pkg_description],
[pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
AC_ARG_WITH([noarch-pkgconfigdir],
[AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
[with_noarch_pkgconfigdir=]pkg_default)
AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
m4_popdef([pkg_default])
m4_popdef([pkg_description])
]) dnl PKG_NOARCH_INSTALLDIR
# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# -------------------------------------------
# Retrieves the value of the pkg-config variable for the given module.
AC_DEFUN([PKG_CHECK_VAR],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
_PKG_CONFIG([$1], [variable="][$3]["], [$2])
AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR

821
main.c Normal file
View file

@ -0,0 +1,821 @@
/*
This file is part of telegram-cli.
Telegram-cli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-cli 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-cli. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013-2014
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <termios.h>
#include <unistd.h>
#include <assert.h>
#if (READLINE == GNU)
#include <readline/readline.h>
#else
#include <editline/readline.h>
#endif
#ifdef EVENT_V2
#include <event2/event.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#else
#include <event.h>
#include "event-old.h"
#endif
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <time.h>
#include <fcntl.h>
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#include <signal.h>
#ifdef HAVE_LIBCONFIG
#include <libconfig.h>
#endif
#include <grp.h>
#include <arpa/inet.h>
#include "telegram.h"
#include "loop.h"
#include "interface.h"
#include "tools.h"
#ifdef USE_LUA
# include "lua-tg.h"
#endif
#include "tgl.h"
#define PROGNAME "telegram-cli"
#define VERSION "0.07"
#define CONFIG_DIRECTORY "." PROG_NAME
#define CONFIG_FILE "config"
#define AUTH_KEY_FILE "auth"
#define STATE_FILE "state"
#define SECRET_CHAT_FILE "secret"
#define DOWNLOADS_DIRECTORY "downloads"
#define BINLOG_FILE "binlog"
#define CONFIG_DIRECTORY_MODE 0700
#define DEFAULT_CONFIG_CONTENTS \
"# This is an empty config file\n" \
"# Feel free to put something here\n"
int verbosity;
int msg_num_mode;
char *default_username;
char *config_filename;
char *prefix;
char *auth_file_name;
char *state_file_name;
char *secret_chat_file_name;
char *downloads_directory;
char *config_directory;
char *binlog_file_name;
char *lua_file;
int binlog_enabled;
extern int log_level;
int sync_from_start;
int allow_weak_random;
int disable_colors;
int readline_disabled;
int disable_output;
int reset_authorization;
int port;
void set_default_username (const char *s) {
if (default_username) {
tfree_str (default_username);
}
default_username = tstrdup (s);
}
/* {{{ TERMINAL */
static struct termios term_in, term_out;
static int term_set_in;
static int term_set_out;
void get_terminal_attributes (void) {
if (tcgetattr (STDIN_FILENO, &term_in) < 0) {
} else {
term_set_in = 1;
}
if (tcgetattr (STDOUT_FILENO, &term_out) < 0) {
} else {
term_set_out = 1;
}
}
void set_terminal_attributes (void) {
if (term_set_in) {
if (tcsetattr (STDIN_FILENO, 0, &term_in) < 0) {
perror ("tcsetattr()");
}
}
if (term_set_out) {
if (tcsetattr (STDOUT_FILENO, 0, &term_out) < 0) {
perror ("tcsetattr()");
}
}
}
/* }}} */
char *get_home_directory (void) {
static char *home_directory = NULL;
if (home_directory != NULL) {
return home_directory;
}
struct passwd *current_passwd;
uid_t user_id;
setpwent ();
user_id = getuid ();
while ((current_passwd = getpwent ())) {
if (current_passwd->pw_uid == user_id) {
home_directory = tstrdup (current_passwd->pw_dir);
break;
}
}
endpwent ();
if (home_directory == NULL) {
home_directory = tstrdup (".");
}
return home_directory;
}
char *get_config_directory (void) {
char *config_directory;
tasprintf (&config_directory, "%s/" CONFIG_DIRECTORY, get_home_directory ());
return config_directory;
}
char *get_config_filename (void) {
return config_filename;
}
char *get_auth_key_filename (void) {
return auth_file_name;
}
char *get_state_filename (void) {
return state_file_name;
}
char *get_secret_chat_filename (void) {
return secret_chat_file_name;
}
char *get_downloads_directory (void) {
return downloads_directory;
}
char *get_binlog_file_name (void) {
return binlog_file_name;
}
char *make_full_path (char *s) {
if (*s != '/') {
char *t = s;
tasprintf (&s, "%s/%s", get_home_directory (), s);
tfree_str (t);
}
return s;
}
void check_type_sizes (void) {
if (sizeof (int) != 4u) {
logprintf ("sizeof (int) isn't equal 4.\n");
exit (1);
}
if (sizeof (char) != 1u) {
logprintf ("sizeof (char) isn't equal 1.\n");
exit (1);
}
}
void running_for_first_time (void) {
check_type_sizes ();
if (config_filename) {
return; // Do not create custom config file
}
tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE);
config_filename = make_full_path (config_filename);
int config_file_fd;
char *config_directory = get_config_directory ();
//char *downloads_directory = get_downloads_directory ();
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
if (!disable_output) {
printf ("[%s] created\n", config_directory);
}
}
tfree_str (config_directory);
config_directory = NULL;
// see if config file is there
if (access (config_filename, R_OK) != 0) {
// config file missing, so touch it
config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600);
if (config_file_fd == -1) {
perror ("open[config_file]");
exit (EXIT_FAILURE);
}
if (write (config_file_fd, DEFAULT_CONFIG_CONTENTS, strlen (DEFAULT_CONFIG_CONTENTS)) <= 0) {
perror ("write[config_file]");
exit (EXIT_FAILURE);
}
close (config_file_fd);
/*int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
int x = -1;
assert (write (auth_file_fd, &x, 4) == 4);
close (auth_file_fd);
printf ("[%s] created\n", config_filename);*/
/* create downloads directory */
/*if (mkdir (downloads_directory, 0755) !=0) {
perror ("creating download directory");
exit (EXIT_FAILURE);
}*/
}
}
#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];
int l = 0;
if (prefix) {
l = strlen (prefix);
memcpy (buf, prefix, l);
buf[l ++] = '.';
}
*s = 0;
const char *r = 0;
strcpy (buf + l, param_name);
config_lookup_string (conf, buf, &r);
if (r) {
if (path) {
tasprintf (s, "%s/%s", path, r);
} else {
*s = tstrdup (r);
}
} else {
if (path && default_name) {
tasprintf (s, "%s/%s", path, default_name);
} else {
*s = default_name ? tstrdup (default_name) : 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);
}
#else
void parse_config (void) {
if (!disable_output) {
printf ("libconfig not enabled\n");
}
tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
if (binlog_enabled) {
tasprintf (&binlog_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, BINLOG_FILE);
tgl_set_binlog_mode (1);
tgl_set_binlog_path (binlog_file_name);
} else {
tgl_set_binlog_mode (0);
//tgl_set_auth_file_path (auth_file_name;
tasprintf (&auth_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, AUTH_KEY_FILE);
tasprintf (&state_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, STATE_FILE);
tasprintf (&secret_chat_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, SECRET_CHAT_FILE);
}
tgl_set_download_directory (downloads_directory);
}
#endif
void inner_main (void) {
loop ();
}
void usage (void) {
printf ("%s Usage\n", PROGNAME);
printf (" -u specify username (would not be asked during authorization)\n");
printf (" -k specify location of public key (possible multiple entries)\n");
printf (" -v increase verbosity (0-ERROR 1-WARNIN 2-NOTICE 3+-DEBUG-levels)\n");
printf (" -N message num mode\n");
#ifdef HAVE_LIBCONFIG
printf (" -c config file name\n");
printf (" -p use specified profile\n");
#else
printf (" -B enable binlog\n");
#endif
printf (" -l log level\n");
printf (" -f during authorization fetch all messages since registration\n");
printf (" -E diable auto accept of encrypted chats\n");
#ifdef USE_LUA
printf (" -s lua script file\n");
#endif
printf (" -W send dialog_list query and wait for answer before reading input\n");
printf (" -C disable color output\n");
printf (" -R disable readline\n");
printf (" -d daemon mode\n");
printf (" -L <log-name> log file name\n");
printf (" -U <user-name> change uid after start\n");
printf (" -G <group-name> change gid after start\n");
printf (" -D disable output\n");
printf (" -P <port> port to listen for input commands\n");
printf (" -S <socket-name> unix socket to create\n");
exit (1);
}
//extern char *rsa_public_key_name;
//extern int default_dc_num;
char *log_net_file;
FILE *log_net_f;
int register_mode;
int disable_auto_accept;
int wait_dialog_list;
char *logname;
int daemonize;
void reopen_logs (void) {
int fd;
fflush (stdout);
fflush (stderr);
if ((fd = open ("/dev/null", O_RDWR, 0)) != -1) {
dup2 (fd, 0);
dup2 (fd, 1);
dup2 (fd, 2);
if (fd > 2) {
close (fd);
}
}
if (logname && (fd = open (logname, O_WRONLY|O_APPEND|O_CREAT, 0640)) != -1) {
dup2 (fd, 1);
dup2 (fd, 2);
if (fd > 2) {
close (fd);
}
}
}
static void sigusr1_handler (const int sig) {
fprintf(stderr, "got SIGUSR1, rotate logs.\n");
reopen_logs ();
signal (SIGUSR1, sigusr1_handler);
}
static void sighup_handler (const int sig) {
fprintf(stderr, "got SIGHUP.\n");
signal (SIGHUP, sighup_handler);
}
char *set_user_name;
char *set_group_name;
int change_user_group () {
char *username = set_user_name;
char *groupname = set_group_name;
struct passwd *pw;
/* lose root privileges if we have them */
if (getuid() == 0 || geteuid() == 0) {
if (username == 0 || *username == '\0') {
username = "telegramd";
}
if ((pw = getpwnam (username)) == 0) {
fprintf (stderr, "change_user_group: can't find the user %s to switch to\n", username);
return -1;
}
gid_t gid = pw->pw_gid;
if (setgroups (1, &gid) < 0) {
fprintf (stderr, "change_user_group: failed to clear supplementary groups list: %m\n");
return -1;
}
if (groupname) {
struct group *g = getgrnam (groupname);
if (g == NULL) {
fprintf (stderr, "change_user_group: can't find the group %s to switch to\n", groupname);
return -1;
}
gid = g->gr_gid;
}
if (setgid (gid) < 0) {
fprintf (stderr, "change_user_group: setgid (%d) failed. %m\n", (int) gid);
return -1;
}
if (setuid (pw->pw_uid) < 0) {
fprintf (stderr, "change_user_group: failed to assume identity of user %s\n", username);
return -1;
}
}
return 0;
}
char *unix_socket;
void args_parse (int argc, char **argv) {
int opt = 0;
while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:qP:S:"
#ifdef HAVE_LIBCONFIG
"c:p:"
#else
"B"
#endif
#ifdef USE_LUA
"s:"
#endif
)) != -1) {
switch (opt) {
case 'u':
set_default_username (optarg);
break;
case 'k':
//rsa_public_key_name = tstrdup (optarg);
tgl_set_rsa_key (optarg);
break;
case 'v':
tgl_incr_verbosity ();
verbosity ++;
break;
case 'N':
msg_num_mode ++;
break;
#ifdef HAVE_LIBCONFIG
case 'c':
config_filename = tstrdup (optarg);
break;
case 'p':
prefix = tstrdup (optarg);
assert (strlen (prefix) <= 100);
break;
#else
case 'B':
binlog_enabled = 1;
break;
#endif
case 'l':
log_level = atoi (optarg);
break;
case 'f':
sync_from_start = 1;
break;
case 'E':
disable_auto_accept = 1;
break;
case 'w':
allow_weak_random = 1;
break;
#ifdef USE_LUA
case 's':
lua_file = strdup (optarg);
break;
#endif
case 'W':
wait_dialog_list = 1;
break;
case 'C':
disable_colors ++;
break;
case 'R':
readline_disabled ++;
break;
case 'd':
daemonize ++;
break;
case 'L':
logname = optarg;
break;
case 'U':
set_user_name = optarg;
break;
case 'G':
set_group_name = optarg;
break;
case 'D':
disable_output ++;
break;
case 'q':
reset_authorization ++;
break;
case 'P':
port = atoi (optarg);
break;
case 'S':
unix_socket = optarg;
break;
case 'h':
default:
usage ();
break;
}
}
}
#ifdef HAVE_EXECINFO_H
void print_backtrace (void) {
void *buffer[255];
const int calls = backtrace (buffer, sizeof (buffer) / sizeof (void *));
backtrace_symbols_fd (buffer, calls, 1);
}
#else
void print_backtrace (void) {
if (write (1, "No libexec. Backtrace disabled\n", 32) < 0) {
// Sad thing
}
}
#endif
int sfd;
int usfd;
void termination_signal_handler (int signum) {
if (!readline_disabled) {
rl_free_line_state ();
rl_cleanup_after_signal ();
}
if (write (1, "SIGNAL received\n", 18) < 0) {
// Sad thing
}
if (unix_socket) {
unlink (unix_socket);
}
if (usfd > 0) {
close (usfd);
}
if (sfd > 0) {
close (sfd);
}
print_backtrace ();
exit (EXIT_FAILURE);
}
volatile int sigterm_cnt;
void sig_term_handler (int signum __attribute__ ((unused))) {
signal (signum, termination_signal_handler);
//set_terminal_attributes ();
if (write (1, "SIGTERM/SIGINT received\n", 25) < 0) {
// Sad thing
}
if (tgl_state.ev_base) {
event_base_loopbreak(tgl_state.ev_base);
}
sigterm_cnt ++;
}
void do_halt (int error) {
if (!readline_disabled) {
rl_free_line_state ();
rl_cleanup_after_signal ();
}
if (write (1, "halt\n", 5) < 0) {
// Sad thing
}
if (unix_socket) {
unlink (unix_socket);
}
if (usfd > 0) {
close (usfd);
}
if (sfd > 0) {
close (sfd);
}
exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
}
int main (int argc, char **argv) {
signal (SIGSEGV, termination_signal_handler);
signal (SIGABRT, termination_signal_handler);
signal (SIGBUS, termination_signal_handler);
signal (SIGQUIT, termination_signal_handler);
signal (SIGFPE, termination_signal_handler);
signal (SIGPIPE, SIG_IGN);
signal (SIGTERM, sig_term_handler);
signal (SIGINT, sig_term_handler);
rl_catch_signals = 0;
log_level = 10;
args_parse (argc, argv);
change_user_group ();
if (port > 0) {
struct sockaddr_in serv_addr;
sfd = socket (AF_INET, SOCK_STREAM, 0);
if (sfd < 0) {
perror ("socket");
exit(1);
}
memset (&serv_addr, 0, sizeof (serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl (0x7f000001);
serv_addr.sin_port = htons (port);
if (bind (sfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
perror ("bind");
exit(1);
}
listen (sfd, 5);
} else {
sfd = -1;
}
if (unix_socket) {
assert (strlen (unix_socket) < 100);
struct sockaddr_un serv_addr;
usfd = socket (AF_UNIX, SOCK_STREAM, 0);
if (usfd < 0) {
perror ("socket");
exit(1);
}
memset (&serv_addr, 0, sizeof (serv_addr));
serv_addr.sun_family = AF_UNIX;
snprintf (serv_addr.sun_path, 108, "%s", unix_socket);
if (bind (usfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
perror ("bind");
exit(1);
}
listen (usfd, 5);
} else {
usfd = -1;
}
if (daemonize) {
signal (SIGHUP, sighup_handler);
reopen_logs ();
}
signal (SIGUSR1, sigusr1_handler);
if (!disable_output) {
printf (
"Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
"Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; type `show_license' for details.\n"
);
}
running_for_first_time ();
parse_config ();
tgl_set_rsa_key ("/etc/" PROG_NAME "/server.pub");
tgl_set_rsa_key ("tg-server.pub");
get_terminal_attributes ();
#ifdef USE_LUA
if (lua_file) {
lua_init (lua_file);
}
#endif
inner_main ();
return 0;
}

172
msglog.c
View file

@ -1,172 +0,0 @@
/*
This file is part of telegram-purple
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
Copyright Matthias Jentsch 2014-2015
*/
#include <stdio.h>
#include <stdarg.h>
#include "telegram-purple.h"
/*
msglog.c: Convenience methods for logging to libpurple log
*/
void log_level_printf (const char* format, va_list ap, int level) {
char buffer[256];
vsnprintf (buffer, sizeof(buffer), format, ap);
int last = (int)strlen (buffer) - 1;
if (last >= 2 && buffer[last] == '\n') {
buffer[last] = '\0';
}
purple_debug (level, PLUGIN_ID, "%s\n", buffer);
}
void debug(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_MISC);
va_end (ap);
}
void info(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_INFO);
va_end (ap);
}
void warning(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_WARNING);
va_end (ap);
}
void failure(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_ERROR);
va_end (ap);
}
void fatal(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_FATAL);
va_end (ap);
info ("\n");
}
const char *print_flags (const char **names, int len, unsigned flags) {
static char *text = NULL;
if (text) {
g_free (text);
text = NULL;
}
int i;
for (i = 0; i < len; i ++) {
if (flags & 1) {
char *new;
if (text) {
new = g_strconcat (text, " ", names[i], NULL);
g_free (text);
} else {
new = g_strdup (names[i]);
}
text = new;
}
flags >>= 1;
}
return (const char*)text;
}
const char *print_flags_peer (unsigned flags) {
const char *names[] = {
"CREATED",
"HAS_PHOTO",
"DELETED",
"OFFICIAL",
"KICKED",
"ADMIN",
"CREATOR",
"LEFT",
"DEACTIVATED"
};
return print_flags (names, 9, flags);
}
const char *print_flags_channel (unsigned flags) {
static char *text;
if (text) {
g_free (text);
text = NULL;
}
const char *names[] = {
"BROADCAST",
"EDITOR",
"MODERATOR",
"MEGAGROUP"
};
text = g_strdup (print_flags_peer (flags));
char *old = text;
text = g_strconcat (text, " ", print_flags (names, 4, flags >> 16), NULL);
g_free (old);
return text;
}
const char *print_flags_user (unsigned flags) {
static char *text;
if (text) {
g_free (text);
text = NULL;
}
const char *names[] = {
"CONTACT",
"MUTUAL_CONTACT",
"BLOCKED",
"SELF",
"BOT"
};
text = g_strdup (print_flags_peer (flags));
char *old = text;
text = g_strconcat (text, " ", print_flags (names, 5, flags >> 16), NULL);
g_free (old);
return text;
}
const char *print_flags_update (unsigned flags) {
const char *names[] = {
"CREATED",
"DELETED",
"PHONE",
"CONTACT",
"PHOTO",
"BLOCKED",
"REAL_NAME",
"NAME",
"REQUESTED",
"WORKING",
"FLAGS",
"TITLE",
"ADMIN",
"MEMBERS",
"ACCESS_HASH",
"USERNAME"
};
return print_flags (names, 16, flags);
}

View file

@ -1,30 +0,0 @@
/*
This file is part of telegram-purple
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
Copyright Matthias Jentsch 2014-2015
*/
#include <stdarg.h>
void debug(const char* format, ...);
void info(const char* format, ...);
void warning(const char* format, ...);
void failure(const char* format, ...);
void fatal(const char* format, ...);
const char *print_flags_update (unsigned update);
const char *print_flags_channel (unsigned flags);
const char *print_flags_peer (unsigned flags);
const char *print_flags_user (unsigned flags);

1449
mtproto-client.c Normal file

File diff suppressed because it is too large Load diff

60
mtproto-client.h Normal file
View file

@ -0,0 +1,60 @@
/*
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 Nikolay Durov, Andrey Lopatin 2012-2013
Vitaly Valtman 2013-2014
*/
#ifndef __MTPROTO_CLIENT_H__
#define __MTPROTO_CLIENT_H__
//#include "net.h"
#include <openssl/bn.h>
//void on_start (void);
//..long long encrypt_send_message (struct connection *c, int *msg, int msg_ints, int useful);
//void dc_authorize (struct tgl_dc *DC);
//void work_update (struct connection *c, long long msg_id);
//void work_update_binlog (void);
//int check_g (unsigned char p[256], BIGNUM *g);
//int check_g_bn (BIGNUM *p, BIGNUM *g);
//int check_DH_params (BIGNUM *p, int g);
//void secure_random (void *s, int l);
#include "tgl.h"
struct connection;
struct tgl_dc;
//#include "queries.h"
#define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74"
#define TG_APP_ID 2899
#define ACK_TIMEOUT 1
#define MAX_DC_ID 10
struct connection;
long long tglmp_encrypt_send_message (struct connection *c, int *msg, int msg_ints, int flags);
void tglmp_dc_create_session (struct tgl_dc *DC);
int tglmp_check_g (unsigned char p[256], BIGNUM *g);
int tglmp_check_DH_params (BIGNUM *p, int g);
struct tgl_dc *tglmp_alloc_dc (int id, char *ip, int port);
void tglmp_regenerate_temp_auth_key (struct tgl_dc *D);
void tgln_insert_msg_id (struct tgl_session *S, long long id);
void tglmp_on_start (void);
void tgl_dc_authorize (struct tgl_dc *DC);
void tgls_free_dc (struct tgl_dc *DC);
void tgls_free_pubkey (void);
#endif

394
mtproto-common.c Normal file
View file

@ -0,0 +1,394 @@
/*
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 Nikolay Durov, Andrey Lopatin 2012-2013
Vitaly Valtman 2013-2014
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _FILE_OFFSET_BITS 64
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <netdb.h>
#include <openssl/bn.h>
#include <openssl/rand.h>
#include <openssl/pem.h>
#include <openssl/aes.h>
#include <openssl/sha.h>
#include "mtproto-common.h"
#include "include.h"
#include "tools.h"
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
static int __packet_buffer[PACKET_BUFFER_SIZE + 16];
int *tgl_packet_ptr;
int *tgl_packet_buffer = __packet_buffer + 16;
static long long rsa_encrypted_chunks, rsa_decrypted_chunks;
//int verbosity;
static int get_random_bytes (unsigned char *buf, int n) {
int r = 0, h = open ("/dev/random", O_RDONLY | O_NONBLOCK);
if (h >= 0) {
r = read (h, buf, n);
if (r > 0) {
vlogprintf (E_DEBUG, "added %d bytes of real entropy to secure random numbers seed\n", r);
} else {
r = 0;
}
close (h);
}
if (r < n) {
h = open ("/dev/urandom", O_RDONLY);
if (h < 0) {
return r;
}
int s = read (h, buf + r, n - r);
close (h);
if (s > 0) {
r += s;
}
}
if (r >= (int) sizeof (long)) {
*(long *)buf ^= lrand48 ();
srand48 (*(long *)buf);
}
return r;
}
/* RDTSC */
#if defined(__i386__)
#define HAVE_RDTSC
static __inline__ unsigned long long rdtsc (void) {
unsigned long long int x;
__asm__ volatile ("rdtsc" : "=A" (x));
return x;
}
#elif defined(__x86_64__)
#define HAVE_RDTSC
static __inline__ unsigned long long rdtsc (void) {
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long) lo) | (((unsigned long long) hi) << 32);
}
#endif
void tgl_prng_seed (const char *password_filename, int password_length) {
struct timespec T;
tgl_my_clock_gettime (CLOCK_REALTIME, &T);
RAND_add (&T, sizeof (T), 4.0);
#ifdef HAVE_RDTSC
unsigned long long r = rdtsc ();
RAND_add (&r, 8, 4.0);
#endif
unsigned short p = getpid ();
RAND_add (&p, sizeof (p), 0.0);
p = getppid ();
RAND_add (&p, sizeof (p), 0.0);
unsigned char rb[32];
int s = get_random_bytes (rb, 32);
if (s > 0) {
RAND_add (rb, s, s);
}
memset (rb, 0, sizeof (rb));
if (password_filename && password_length > 0) {
int fd = open (password_filename, O_RDONLY);
if (fd < 0) {
vlogprintf (E_WARNING, "Warning: fail to open password file - \"%s\", %m.\n", password_filename);
} else {
unsigned char *a = talloc0 (password_length);
int l = read (fd, a, password_length);
if (l < 0) {
vlogprintf (E_WARNING, "Warning: fail to read password file - \"%s\", %m.\n", password_filename);
} else {
vlogprintf (E_DEBUG, "read %d bytes from password file.\n", l);
RAND_add (a, l, l);
}
close (fd);
tfree_secure (a, password_length);
}
}
tgl_state.BN_ctx = BN_CTX_new ();
ensure_ptr (tgl_state.BN_ctx);
}
int tgl_serialize_bignum (BIGNUM *b, char *buffer, int maxlen) {
int itslen = BN_num_bytes (b);
int reqlen;
if (itslen < 254) {
reqlen = itslen + 1;
} else {
reqlen = itslen + 4;
}
int newlen = (reqlen + 3) & -4;
int pad = newlen - reqlen;
reqlen = newlen;
if (reqlen > maxlen) {
return -reqlen;
}
if (itslen < 254) {
*buffer++ = itslen;
} else {
*(int *)buffer = (itslen << 8) + 0xfe;
buffer += 4;
}
int l = BN_bn2bin (b, (unsigned char *)buffer);
assert (l == itslen);
buffer += l;
while (pad --> 0) {
*buffer++ = 0;
}
return reqlen;
}
long long tgl_do_compute_rsa_key_fingerprint (RSA *key) {
static char tempbuff[4096];
static unsigned char sha[20];
assert (key->n && key->e);
int l1 = tgl_serialize_bignum (key->n, tempbuff, 4096);
assert (l1 > 0);
int l2 = tgl_serialize_bignum (key->e, tempbuff + l1, 4096 - l1);
assert (l2 > 0 && l1 + l2 <= 4096);
SHA1 ((unsigned char *)tempbuff, l1 + l2, sha);
return *(long long *)(sha + 12);
}
void tgl_out_cstring (const char *str, long len) {
assert (len >= 0 && len < (1 << 24));
assert ((char *) packet_ptr + len + 8 < (char *) (packet_buffer + PACKET_BUFFER_SIZE));
char *dest = (char *) packet_ptr;
if (len < 254) {
*dest++ = len;
} else {
*packet_ptr = (len << 8) + 0xfe;
dest += 4;
}
memcpy (dest, str, len);
dest += len;
while ((long) dest & 3) {
*dest++ = 0;
}
packet_ptr = (int *) dest;
}
void tgl_out_cstring_careful (const char *str, long len) {
assert (len >= 0 && len < (1 << 24));
assert ((char *) packet_ptr + len + 8 < (char *) (packet_buffer + PACKET_BUFFER_SIZE));
char *dest = (char *) packet_ptr;
if (len < 254) {
dest++;
if (dest != str) {
memmove (dest, str, len);
}
dest[-1] = len;
} else {
dest += 4;
if (dest != str) {
memmove (dest, str, len);
}
*packet_ptr = (len << 8) + 0xfe;
}
dest += len;
while ((long) dest & 3) {
*dest++ = 0;
}
packet_ptr = (int *) dest;
}
void tgl_out_data (const void *data, long len) {
assert (len >= 0 && len < (1 << 24) && !(len & 3));
assert ((char *) packet_ptr + len + 8 < (char *) (packet_buffer + PACKET_BUFFER_SIZE));
memcpy (packet_ptr, data, len);
packet_ptr += len >> 2;
}
int *tgl_in_ptr, *tgl_in_end;
int tgl_fetch_bignum (BIGNUM *x) {
int l = prefetch_strlen ();
if (l < 0) {
return l;
}
char *str = fetch_str (l);
assert (BN_bin2bn ((unsigned char *) str, l, x) == x);
return l;
}
int tgl_pad_rsa_encrypt (char *from, int from_len, char *to, int size, BIGNUM *N, BIGNUM *E) {
int pad = (255000 - from_len - 32) % 255 + 32;
int chunks = (from_len + pad) / 255;
int bits = BN_num_bits (N);
assert (bits >= 2041 && bits <= 2048);
assert (from_len > 0 && from_len <= 2550);
assert (size >= chunks * 256);
assert (RAND_pseudo_bytes ((unsigned char *) from + from_len, pad) >= 0);
int i;
BIGNUM x, y;
BN_init (&x);
BN_init (&y);
rsa_encrypted_chunks += chunks;
for (i = 0; i < chunks; i++) {
BN_bin2bn ((unsigned char *) from, 255, &x);
assert (BN_mod_exp (&y, &x, E, N, tgl_state.BN_ctx) == 1);
unsigned l = 256 - BN_num_bytes (&y);
assert (l <= 256);
memset (to, 0, l);
BN_bn2bin (&y, (unsigned char *) to + l);
to += 256;
}
BN_free (&x);
BN_free (&y);
return chunks * 256;
}
int tgl_pad_rsa_decrypt (char *from, int from_len, char *to, int size, BIGNUM *N, BIGNUM *D) {
if (from_len < 0 || from_len > 0x1000 || (from_len & 0xff)) {
return -1;
}
int chunks = (from_len >> 8);
int bits = BN_num_bits (N);
assert (bits >= 2041 && bits <= 2048);
assert (size >= chunks * 255);
int i;
BIGNUM x, y;
BN_init (&x);
BN_init (&y);
for (i = 0; i < chunks; i++) {
++rsa_decrypted_chunks;
BN_bin2bn ((unsigned char *) from, 256, &x);
assert (BN_mod_exp (&y, &x, D, N, tgl_state.BN_ctx) == 1);
int l = BN_num_bytes (&y);
if (l > 255) {
BN_free (&x);
BN_free (&y);
return -1;
}
assert (l >= 0 && l <= 255);
memset (to, 0, 255 - l);
BN_bn2bin (&y, (unsigned char *) to + 255 - l);
to += 255;
}
BN_free (&x);
BN_free (&y);
return chunks * 255;
}
static unsigned char aes_key_raw[32], aes_iv[32];
static AES_KEY aes_key;
void tgl_init_aes_unauth (const char server_nonce[16], const char hidden_client_nonce[32], int encrypt) {
static unsigned char buffer[64], hash[20];
memcpy (buffer, hidden_client_nonce, 32);
memcpy (buffer + 32, server_nonce, 16);
SHA1 (buffer, 48, aes_key_raw);
memcpy (buffer + 32, hidden_client_nonce, 32);
SHA1 (buffer, 64, aes_iv + 8);
memcpy (buffer, server_nonce, 16);
memcpy (buffer + 16, hidden_client_nonce, 32);
SHA1 (buffer, 48, hash);
memcpy (aes_key_raw + 20, hash, 12);
memcpy (aes_iv, hash + 12, 8);
memcpy (aes_iv + 28, hidden_client_nonce, 4);
if (encrypt == AES_ENCRYPT) {
AES_set_encrypt_key (aes_key_raw, 32*8, &aes_key);
} else {
AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key);
}
memset (aes_key_raw, 0, sizeof (aes_key_raw));
}
void tgl_init_aes_auth (char auth_key[192], char msg_key[16], int encrypt) {
static unsigned char buffer[48], hash[20];
// sha1_a = SHA1 (msg_key + substr (auth_key, 0, 32));
// sha1_b = SHA1 (substr (auth_key, 32, 16) + msg_key + substr (auth_key, 48, 16));
// sha1_с = SHA1 (substr (auth_key, 64, 32) + msg_key);
// sha1_d = SHA1 (msg_key + substr (auth_key, 96, 32));
// aes_key = substr (sha1_a, 0, 8) + substr (sha1_b, 8, 12) + substr (sha1_c, 4, 12);
// aes_iv = substr (sha1_a, 8, 12) + substr (sha1_b, 0, 8) + substr (sha1_c, 16, 4) + substr (sha1_d, 0, 8);
memcpy (buffer, msg_key, 16);
memcpy (buffer + 16, auth_key, 32);
SHA1 (buffer, 48, hash);
memcpy (aes_key_raw, hash, 8);
memcpy (aes_iv, hash + 8, 12);
memcpy (buffer, auth_key + 32, 16);
memcpy (buffer + 16, msg_key, 16);
memcpy (buffer + 32, auth_key + 48, 16);
SHA1 (buffer, 48, hash);
memcpy (aes_key_raw + 8, hash + 8, 12);
memcpy (aes_iv + 12, hash, 8);
memcpy (buffer, auth_key + 64, 32);
memcpy (buffer + 32, msg_key, 16);
SHA1 (buffer, 48, hash);
memcpy (aes_key_raw + 20, hash + 4, 12);
memcpy (aes_iv + 20, hash + 16, 4);
memcpy (buffer, msg_key, 16);
memcpy (buffer + 16, auth_key + 96, 32);
SHA1 (buffer, 48, hash);
memcpy (aes_iv + 24, hash, 8);
if (encrypt == AES_ENCRYPT) {
AES_set_encrypt_key (aes_key_raw, 32*8, &aes_key);
} else {
AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key);
}
memset (aes_key_raw, 0, sizeof (aes_key_raw));
}
int tgl_pad_aes_encrypt (char *from, int from_len, char *to, int size) {
int padded_size = (from_len + 15) & -16;
assert (from_len > 0 && padded_size <= size);
if (from_len < padded_size) {
assert (RAND_pseudo_bytes ((unsigned char *) from + from_len, padded_size - from_len) >= 0);
}
AES_ige_encrypt ((unsigned char *) from, (unsigned char *) to, padded_size, &aes_key, aes_iv, AES_ENCRYPT);
return padded_size;
}
int tgl_pad_aes_decrypt (char *from, int from_len, char *to, int size) {
if (from_len <= 0 || from_len > size || (from_len & 15)) {
return -1;
}
AES_ige_encrypt ((unsigned char *) from, (unsigned char *) to, from_len, &aes_key, aes_iv, AES_DECRYPT);
return from_len;
}

387
mtproto-common.h Normal file
View file

@ -0,0 +1,387 @@
/*
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 Nikolay Durov, Andrey Lopatin 2012-2013
Vitaly Valtman 2013-2014
*/
#ifndef __MTPROTO_COMMON_H__
#define __MTPROTO_COMMON_H__
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/bn.h>
#include <openssl/aes.h>
#include <stdio.h>
#include <assert.h>
//#include "interface.h"
#include "tools.h"
#include "auto/constants.h"
#include "tgl.h"
#include "tgl-inner.h"
/* DH key exchange protocol data structures */
#define CODE_req_pq 0x60469778
#define CODE_resPQ 0x05162463
#define CODE_req_DH_params 0xd712e4be
#define CODE_p_q_inner_data 0x83c95aec
#define CODE_p_q_inner_data_temp 0x3c6a84d4
#define CODE_server_DH_inner_data 0xb5890dba
#define CODE_server_DH_params_fail 0x79cb045d
#define CODE_server_DH_params_ok 0xd0e8075c
#define CODE_set_client_DH_params 0xf5045f1f
#define CODE_client_DH_inner_data 0x6643b654
#define CODE_dh_gen_ok 0x3bcbf734
#define CODE_dh_gen_retry 0x46dc1fb9
#define CODE_dh_gen_fail 0xa69dae02
#define CODE_bind_auth_key_inner 0x75a3f765
/* service messages */
#define CODE_rpc_result 0xf35c6d01
#define CODE_rpc_error 0x2144ca19
#define CODE_msg_container 0x73f1f8dc
#define CODE_msg_copy 0xe06046b2
#define CODE_msgs_ack 0x62d6b459
#define CODE_bad_msg_notification 0xa7eff811
#define CODE_bad_server_salt 0xedab447b
#define CODE_msgs_state_req 0xda69fb52
#define CODE_msgs_state_info 0x04deb57d
#define CODE_msgs_all_info 0x8cc0d131
#define CODE_new_session_created 0x9ec20908
#define CODE_msg_resend_req 0x7d861a08
#define CODE_ping 0x7abe77ec
#define CODE_pong 0x347773c5
#define CODE_destroy_session 0xe7512126
#define CODE_destroy_session_ok 0xe22045fc
#define CODE_destroy_session_none 0x62d350c9
#define CODE_destroy_sessions 0x9a6face8
#define CODE_destroy_sessions_res 0xa8164668
#define CODE_get_future_salts 0xb921bd04
#define CODE_future_salt 0x0949d9dc
#define CODE_future_salts 0xae500895
#define CODE_rpc_drop_answer 0x58e4a740
#define CODE_rpc_answer_unknown 0x5e2ad36e
#define CODE_rpc_answer_dropped_running 0xcd78e586
#define CODE_rpc_answer_dropped 0xa43ad8b7
#define CODE_msg_detailed_info 0x276d3ec6
#define CODE_msg_new_detailed_info 0x809db6df
#define CODE_ping_delay_disconnect 0xf3427b8c
#define CODE_gzip_packed 0x3072cfa1
#define CODE_input_peer_notify_settings_old 0x3cf4b1be
#define CODE_peer_notify_settings_old 0xddbcd4a5
#define CODE_user_profile_photo_old 0x990d1493
#define CODE_config_old 0x232d5905
#define CODE_msg_new_detailed_info 0x809db6df
#define CODE_msg_detailed_info 0x276d3ec6
/* not really a limit, for struct encrypted_message only */
// #define MAX_MESSAGE_INTS 16384
#define MAX_MESSAGE_INTS 1048576
#define MAX_PROTO_MESSAGE_INTS 1048576
#define PACKET_BUFFER_SIZE (16384 * 100 + 16) // temp fix
#pragma pack(push,4)
struct encrypted_message {
// unencrypted header
long long auth_key_id;
char msg_key[16];
// encrypted part, starts with encrypted header
long long server_salt;
long long session_id;
// long long auth_key_id2; // removed
// first message follows
long long msg_id;
int seq_no;
int msg_len; // divisible by 4
int message[MAX_MESSAGE_INTS];
};
#pragma pack(pop)
//BN_CTX *BN_ctx;
void tgl_prng_seed (const char *password_filename, int password_length);
int tgl_serialize_bignum (BIGNUM *b, char *buffer, int maxlen);
long long tgl_do_compute_rsa_key_fingerprint (RSA *key);
#define packet_buffer tgl_packet_buffer
#define packet_ptr tgl_packet_ptr
extern int *tgl_packet_buffer;
extern int *tgl_packet_ptr;
static inline void out_ints (const int *what, int len) {
assert (packet_ptr + len <= packet_buffer + PACKET_BUFFER_SIZE);
memcpy (packet_ptr, what, len * 4);
packet_ptr += len;
}
static inline void out_int (int x) {
assert (packet_ptr + 1 <= packet_buffer + PACKET_BUFFER_SIZE);
*packet_ptr++ = x;
}
static inline void out_long (long long x) {
assert (packet_ptr + 2 <= packet_buffer + PACKET_BUFFER_SIZE);
*(long long *)packet_ptr = x;
packet_ptr += 2;
}
static inline void out_double (double x) {
assert (packet_ptr + 2 <= packet_buffer + PACKET_BUFFER_SIZE);
*(double *)packet_ptr = x;
packet_ptr += 2;
}
static inline void clear_packet (void) {
packet_ptr = packet_buffer;
}
void tgl_out_cstring (const char *str, long len);
void tgl_out_cstring_careful (const char *str, long len);
void tgl_out_data (const void *data, long len);
#define out_cstring tgl_out_cstring
#define out_cstring_careful tgl_out_cstring_careful
#define out_data tgl_out_data
static inline void out_string (const char *str) {
out_cstring (str, strlen (str));
}
static inline void out_bignum (BIGNUM *n) {
int l = tgl_serialize_bignum (n, (char *)packet_ptr, (PACKET_BUFFER_SIZE - (packet_ptr - packet_buffer)) * 4);
assert (l > 0);
packet_ptr += l >> 2;
}
#define in_ptr tgl_in_ptr
#define in_end tgl_in_end
extern int *tgl_in_ptr, *tgl_in_end;
//void fetch_pts (void);
//void fetch_qts (void);
//void fetch_date (void);
//void fetch_seq (void);
static inline int prefetch_strlen (void) {
if (in_ptr >= in_end) {
return -1;
}
unsigned l = *in_ptr;
if ((l & 0xff) < 0xfe) {
l &= 0xff;
return (in_end >= in_ptr + (l >> 2) + 1) ? (int)l : -1;
} else if ((l & 0xff) == 0xfe) {
l >>= 8;
return (l >= 254 && in_end >= in_ptr + ((l + 7) >> 2)) ? (int)l : -1;
} else {
return -1;
}
}
static inline char *fetch_str (int len) {
assert (len >= 0);
vlogprintf (E_DEBUG + 3, "fetch_string: len = %d\n", len);
if (len < 254) {
char *str = (char *) in_ptr + 1;
in_ptr += 1 + (len >> 2);
return str;
} else {
char *str = (char *) in_ptr + 4;
in_ptr += (len + 7) >> 2;
return str;
}
}
static inline char *fetch_str_dup (void) {
int l = prefetch_strlen ();
assert (l >= 0);
int i;
char *s = fetch_str (l);
for (i = 0; i < l; i++) {
if (!s[i]) { break; }
}
char *r = talloc (i + 1);
memcpy (r, s, i);
r[i] = 0;
return r;
}
static inline int fetch_update_str (char **s) {
if (!*s) {
*s = fetch_str_dup ();
return 1;
}
int l = prefetch_strlen ();
char *r = fetch_str (l);
if (memcmp (*s, r, l) || (*s)[l]) {
tfree_str (*s);
*s = talloc (l + 1);
memcpy (*s, r, l);
(*s)[l] = 0;
return 1;
}
return 0;
}
static inline int fetch_update_int (int *value) {
if (*value == *in_ptr) {
in_ptr ++;
return 0;
} else {
*value = *(in_ptr ++);
return 1;
}
}
static inline int fetch_update_long (long long *value) {
if (*value == *(long long *)in_ptr) {
in_ptr += 2;
return 0;
} else {
*value = *(long long *)(in_ptr);
in_ptr += 2;
return 1;
}
}
static inline int set_update_int (int *value, int new_value) {
if (*value == new_value) {
return 0;
} else {
*value = new_value;
return 1;
}
}
static inline void fetch_skip (int n) {
in_ptr += n;
assert (in_ptr <= in_end);
}
static inline void fetch_skip_str (void) {
int l = prefetch_strlen ();
assert (l >= 0);
fetch_str (l);
}
static inline long have_prefetch_ints (void) {
return in_end - in_ptr;
}
int tgl_fetch_bignum (BIGNUM *x);
#define fetch_bignum tgl_fetch_bignum
static inline int fetch_int (void) {
assert (in_ptr + 1 <= in_end);
vlogprintf (E_DEBUG + 3, "fetch_int: 0x%08x (%d)\n", *in_ptr, *in_ptr);
return *(in_ptr ++);
}
static inline int fetch_bool (void) {
vlogprintf (E_DEBUG + 3, "fetch_bool: 0x%08x (%d)\n", *in_ptr, *in_ptr);
assert (in_ptr + 1 <= in_end);
assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false);
return *(in_ptr ++) == (int)CODE_bool_true;
}
static inline int prefetch_int (void) {
assert (in_ptr < in_end);
return *(in_ptr);
}
static inline void prefetch_data (void *data, int size) {
assert (in_ptr + (size >> 2) <= in_end);
memcpy (data, in_ptr, size);
}
static inline void fetch_data (void *data, int size) {
assert (in_ptr + (size >> 2) <= in_end);
memcpy (data, in_ptr, size);
assert (!(size & 3));
in_ptr += (size >> 2);
}
static inline long long fetch_long (void) {
assert (in_ptr + 2 <= in_end);
long long r = *(long long *)in_ptr;
in_ptr += 2;
return r;
}
static inline double fetch_double (void) {
assert (in_ptr + 2 <= in_end);
double r = *(double *)in_ptr;
in_ptr += 2;
return r;
}
static inline void fetch_ints (void *data, int count) {
assert (in_ptr + count <= in_end);
memcpy (data, in_ptr, 4 * count);
in_ptr += count;
}
static inline void fetch256 (void *buf) {
int l = prefetch_strlen ();
assert (l >= 0);
char *s = fetch_str (l);
if (l < 256) {
memcpy (buf + 256 - l, s, l);
} else {
memcpy (buf, s + (l - 256), 256);
}
}
static inline int in_remaining (void) {
return 4 * (in_end - in_ptr);
}
//int get_random_bytes (unsigned char *buf, int n);
int tgl_pad_rsa_encrypt (char *from, int from_len, char *to, int size, BIGNUM *N, BIGNUM *E);
int tgl_pad_rsa_decrypt (char *from, int from_len, char *to, int size, BIGNUM *N, BIGNUM *D);
//extern long long rsa_encrypted_chunks, rsa_decrypted_chunks;
//extern unsigned char aes_key_raw[32], aes_iv[32];
//extern AES_KEY aes_key;
void tgl_init_aes_unauth (const char server_nonce[16], const char hidden_client_nonce[32], int encrypt);
void tgl_init_aes_auth (char auth_key[192], char msg_key[16], int encrypt);
int tgl_pad_aes_encrypt (char *from, int from_len, char *to, int size);
int tgl_pad_aes_decrypt (char *from, int from_len, char *to, int size);
/*
static inline void hexdump_in (void) {
hexdump (in_ptr, in_end);
}
static inline void hexdump_out (void) {
hexdump (packet_buffer, packet_ptr);
}*/
#ifdef __MACH__
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#endif
#endif

View file

@ -15,110 +15,122 @@
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, Matthias Jentsch 2013-2015
Copyright Vitaly Valtman 2013-2014
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _GNU_SOURCE
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/types.h>
#ifndef WIN32
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <poll.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <poll.h>
#include <openssl/rand.h>
#include <arpa/inet.h>
#ifdef EVENT_V2
#include <event2/event.h>
#else
#include <event.h>
#include "event-old.h"
#endif
#include <sys/time.h>
#include <time.h>
#include "telegram-purple.h"
#include <mtproto-client.h>
#include "net.h"
#include "include.h"
#include "tgl.h"
#include "tgl-inner.h"
//#include "mtproto-client.h"
//#include "mtproto-common.h"
#include "tree.h"
#include "tools.h"
#ifndef POLLRDHUP
#define POLLRDHUP 0
#endif
#define PING_TIMEOUT 15
#define CONNECT_TIMEOUT 5
//double get_utime (int clock_id);
//extern struct mtproto_methods auth_methods;
static void fail_connection (struct connection *c);
static void restart_connection (struct connection *c);
static void start_ping_timer (struct connection *c);
static void conn_try_write (gpointer arg, gint source, PurpleInputCondition cond);
static void try_read (struct connection *c);
static void try_write (struct connection *c);
static int ping_alarm (gpointer arg) {
#define PING_TIMEOUT 10
static void start_ping_timer (struct connection *c);
static void ping_alarm (evutil_socket_t fd, short what, void *arg) {
struct connection *c = arg;
debug ("ping alarm");
assert (c->state == conn_failed || c->state == conn_ready || c->state == conn_connecting);
vlogprintf (E_DEBUG + 2,"ping alarm\n");
assert (c->state == conn_ready || c->state == conn_connecting);
if (tglt_get_double_time () - c->last_receive_time > 6 * PING_TIMEOUT) {
warning ("fail connection: reason: ping timeout");
vlogprintf (E_WARNING, "fail connection: reason: ping timeout\n");
c->state = conn_failed;
fail_connection (c);
return FALSE;
} else if (tglt_get_double_time () - c->last_receive_time > 3 * PING_TIMEOUT && c->state == conn_ready) {
tgl_do_send_ping (c->TLS, c);
return TRUE;
tgl_do_send_ping (c);
start_ping_timer (c);
} else {
return TRUE;
start_ping_timer (c);
}
}
static void stop_ping_timer (struct connection *c) {
purple_timeout_remove (c->ping_ev);
c->ping_ev = -1;
event_del (c->ping_ev);
}
static void start_ping_timer (struct connection *c) {
c->ping_ev = purple_timeout_add_seconds (PING_TIMEOUT, ping_alarm, c);
static struct timeval ptimeout = { PING_TIMEOUT, 0};
event_add (c->ping_ev, &ptimeout);
}
static int fail_alarm (gpointer arg) {
static void restart_connection (struct connection *c);
static void fail_alarm (evutil_socket_t fd, short what, void *arg) {
struct connection *c = arg;
c->in_fail_timer = 0;
restart_connection (c);
return FALSE;
}
static void start_fail_timer (struct connection *c) {
if (c->in_fail_timer) { return; }
c->in_fail_timer = 1;
c->fail_ev = purple_timeout_add_seconds (CONNECT_TIMEOUT, fail_alarm, c);
c->in_fail_timer = 1;
static struct timeval ptimeout = { 10, 0};
event_add (c->fail_ev, &ptimeout);
}
static struct connection_buffer *new_connection_buffer (int size) {
struct connection_buffer *b = malloc (sizeof (*b));
memset (b, 0, sizeof (*b));
b->start = malloc (size);
struct connection_buffer *b = talloc0 (sizeof (*b));
b->start = talloc (size);
b->end = b->start + size;
b->rptr = b->wptr = b->start;
return b;
}
static void delete_connection_buffer (struct connection_buffer *b) {
free (b->start);
free (b);
tfree (b->start, b->end - b->start);
tfree (b, sizeof (*b));
}
int tgln_write_out (struct connection *c, const void *_data, int len) {
// debug ( "write_out: %d bytes\n", len);
vlogprintf (E_DEBUG, "write_out: %d bytes\n", len);
const unsigned char *data = _data;
if (!len) { return 0; }
assert (len > 0);
int x = 0;
if (!c->out_bytes) {
assert (c->write_ev == -1);
c->write_ev = purple_input_add (c->fd, PURPLE_INPUT_WRITE, conn_try_write, c);
event_add (c->write_ev, 0);
}
if (!c->out_head) {
struct connection_buffer *b = new_connection_buffer (1 << 20);
@ -204,9 +216,13 @@ int tgln_read_in_lookup (struct connection *c, void *_data, int len) {
return x;
}
void tgln_flush_out (struct connection *c) {
void tgln_flush_out (struct connection *c UU) {
}
#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:
@ -221,127 +237,153 @@ static void rotate_port (struct connection *c) {
}
}
static void conn_try_read (gpointer arg, gint source, PurpleInputCondition cond) {
static void try_read (struct connection *c);
static void try_write (struct connection *c);
static void conn_try_read (evutil_socket_t fd, short what, void *arg) {
struct connection *c = arg;
// debug ("Try read. Fd = %d\n", c->fd);
vlogprintf (E_DEBUG + 1, "Try read. Fd = %d\n", c->fd);
try_read (c);
}
static void conn_try_write (gpointer arg, gint source, PurpleInputCondition cond) {
static void conn_try_write (evutil_socket_t fd, short what, void *arg) {
struct connection *c = arg;
struct tgl_state *TLS = c->TLS;
if (c->state == conn_connecting) {
c->state = conn_ready;
c->methods->ready (TLS, c);
c->methods->ready (c);
}
try_write (c);
if (!c->out_bytes) {
purple_input_remove (c->write_ev);
c->write_ev = -1;
if (c->out_bytes) {
event_add (c->write_ev, 0);
}
}
static void net_on_connected (gpointer arg, gint fd, const gchar *error_message) {
struct connection *c = arg;
// debug ("connect result: %d\n", fd);
if (c->fail_ev >= 0) {
purple_timeout_remove (c->fail_ev);
c->fail_ev = -1;
}
struct connection *tgln_create_connection (const char *host, int port, struct tgl_session *session, struct tgl_dc *dc, struct mtproto_methods *methods) {
struct connection *c = talloc0 (sizeof (*c));
int fd = socket (AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
const char *msg = "Connection not possible, either your network or a Telegram data center is down, or the"
" Telegram network configuration has changed.";
warning (msg);
return;
vlogprintf (E_ERROR, "Can not create socket: %m\n");
exit (1);
}
assert (fd >= 0 && fd < MAX_CONNECTIONS);
if (fd > max_connection_fd) {
max_connection_fd = fd;
}
int flags = -1;
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof (flags));
setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof (flags));
setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof (flags));
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons (port);
addr.sin_addr.s_addr = inet_addr (host);
fcntl (fd, F_SETFL, O_NONBLOCK);
if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1) {
//vlogprintf (E_ERROR, "Can not connect to %s:%d %m\n", host, port);
if (errno != EINPROGRESS) {
vlogprintf (E_ERROR, "Can not connect to %s:%d %m\n", host, port);
close (fd);
tfree (c, sizeof (*c));
return 0;
}
}
c->fd = fd;
c->read_ev = purple_input_add (fd, PURPLE_INPUT_READ, conn_try_read, c);
unsigned char byte = 0xef;
assert (tgln_write_out (c, &byte, 1) == 1);
c->last_receive_time = tglt_get_double_time ();
start_ping_timer (c);
}
static void net_on_connected_assert_success (gpointer arg, gint fd, const gchar *error_message) {
struct connection *c = arg;
if (c->fail_ev >= 0) {
purple_timeout_remove (c->fail_ev);
c->fail_ev = -1;
}
if (fd == -1) {
struct tgl_state *TLS = c->TLS;
info ("Connection to main data center (%d) %s:%d not possible\n", c->dc->id, c->ip, c->port);
purple_connection_error_reason (tls_get_conn (TLS), PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Cannot connect to main server"));
return;
}
net_on_connected (arg, fd, error_message);
}
struct connection *tgln_create_connection (struct tgl_state *TLS, const char *host, int port, struct tgl_session *session, struct tgl_dc *dc, struct mtproto_methods *methods) {
struct connection *c = malloc (sizeof (*c));
memset (c, 0, sizeof (*c));
c->TLS = TLS;
c->fd = -1;
c->state = conn_connecting;
c->last_receive_time = tglt_get_double_time ();
c->ip = strdup (host);
c->ip = tstrdup (host);
c->flags = 0;
c->port = port;
assert (!Connections[fd]);
Connections[fd] = c;
c->ping_ev = evtimer_new (tgl_state.ev_base, ping_alarm, c);
c->fail_ev = evtimer_new (tgl_state.ev_base, fail_alarm, c);
c->write_ev = event_new (tgl_state.ev_base, c->fd, EV_WRITE, conn_try_write, c);
c->ping_ev = -1;
c->fail_ev = -1;
c->write_ev = -1;
c->read_ev = -1;
struct timeval tv = {5, 0};
c->read_ev = event_new (tgl_state.ev_base, c->fd, EV_READ | EV_PERSIST, conn_try_read, c);
event_add (c->read_ev, &tv);
start_ping_timer (c);
c->dc = dc;
c->session = session;
c->methods = methods;
c->prpl_data = purple_proxy_connect (tls_get_conn (TLS), tls_get_pa (TLS), host, port,
TLS->dc_working_num == dc->id ? net_on_connected_assert_success : net_on_connected, c);
char byte = 0xef;
assert (tgln_write_out (c, &byte, 1) == 1);
tgln_flush_out (c);
start_fail_timer (c);
return c;
}
static void restart_connection (struct connection *c) {
debug("restart_connection()");
if (tglt_get_double_time () - c->last_receive_time > 6 * PING_TIMEOUT) {
purple_connection_error_reason (tls_get_conn (c->TLS), PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
_("Cannot connect to server: Ping timeout."));
if (c->last_connect_time == time (0)) {
start_fail_timer (c);
return;
}
purple_proxy_connect_cancel (c->prpl_data);
c->prpl_data = purple_proxy_connect (tls_get_conn (c->TLS), tls_get_pa (c->TLS), c->ip, c->port,
c->TLS->dc_working_num == c->dc->id ? net_on_connected_assert_success : net_on_connected, c);
c->last_connect_time = time (0);
int fd = socket (AF_INET, SOCK_STREAM, 0);
if (fd == -1) {
vlogprintf (E_ERROR, "Can not create socket: %m\n");
exit (1);
}
assert (fd >= 0 && fd < MAX_CONNECTIONS);
if (fd > max_connection_fd) {
max_connection_fd = fd;
}
int flags = -1;
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof (flags));
setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof (flags));
setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof (flags));
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons (c->port);
addr.sin_addr.s_addr = inet_addr (c->ip);
fcntl (fd, F_SETFL, O_NONBLOCK);
if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1) {
if (errno != EINPROGRESS) {
vlogprintf (E_WARNING, "Can not connect to %s:%d %m\n", c->ip, c->port);
start_fail_timer (c);
close (fd);
return;
}
}
c->fd = fd;
c->state = conn_connecting;
c->last_receive_time = tglt_get_double_time ();
start_ping_timer (c);
Connections[fd] = c;
c->write_ev = event_new (tgl_state.ev_base, c->fd, EV_WRITE, conn_try_write, c);
struct timeval tv = {5, 0};
c->read_ev = event_new (tgl_state.ev_base, c->fd, EV_READ | EV_PERSIST, conn_try_read, c);
event_add (c->read_ev, &tv);
char byte = 0xef;
assert (tgln_write_out (c, &byte, 1) == 1);
tgln_flush_out (c);
}
static void fail_connection (struct connection *c) {
if (c->state == conn_ready) {
if (c->state == conn_ready || c->state == conn_connecting) {
stop_ping_timer (c);
}
if (c->write_ev >= 0) {
purple_input_remove (c->write_ev);
c->write_ev = -1;
}
if (c->read_ev >= 0) {
purple_input_remove (c->read_ev);
c->read_ev = -1;
}
event_free (c->write_ev);
event_free (c->read_ev);
rotate_port (c);
struct connection_buffer *b = c->out_head;
while (b) {
struct connection_buffer *d = b;
@ -357,19 +399,18 @@ static void fail_connection (struct connection *c) {
c->out_head = c->out_tail = c->in_head = c->in_tail = 0;
c->state = conn_failed;
c->out_bytes = c->in_bytes = 0;
c->prpl_data = NULL;
info ("Lost connection to server ... %s:%d\n", c->ip, c->port);
purple_connection_error_reason (tls_get_conn (c->TLS), PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
_("Lost connection to the server..."));
close (c->fd);
Connections[c->fd] = 0;
vlogprintf (E_NOTICE, "Lost connection to server... %s:%d\n", c->ip, c->port);
restart_connection (c);
}
//extern FILE *log_net_f;
static void try_write (struct connection *c) {
// debug ("try write: fd = %d\n", c->fd);
vlogprintf (E_DEBUG, "try write: fd = %d\n", c->fd);
int x = 0;
while (c->out_head) {
int r = send (c->fd, (const char *)c->out_head->rptr, c->out_head->wptr - c->out_head->rptr, 0);
int r = write (c->fd, c->out_head->rptr, c->out_head->wptr - c->out_head->rptr);
if (r >= 0) {
x += r;
c->out_head->rptr += r;
@ -384,7 +425,7 @@ static void try_write (struct connection *c) {
delete_connection_buffer (b);
} else {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
info ("fail_connection: write_error %s\n", g_strerror(errno));
vlogprintf (E_NOTICE, "fail_connection: write_error %m\n");
fail_connection (c);
return;
} else {
@ -392,13 +433,12 @@ static void try_write (struct connection *c) {
}
}
}
// debug ("Sent %d bytes to %d\n", x, c->fd);
vlogprintf (E_DEBUG, "Sent %d bytes to %d\n", x, c->fd);
c->out_bytes -= x;
}
static void try_rpc_read (struct connection *c) {
assert (c->in_head);
struct tgl_state *TLS = c->TLS;
while (1) {
if (c->in_bytes < 1) { return; }
@ -428,14 +468,12 @@ static void try_rpc_read (struct connection *c) {
len *= 4;
int op;
assert (tgln_read_in_lookup (c, &op, 4) == 4);
if (c->methods->execute (TLS, c, op, len) < 0) {
return;
}
c->methods->execute (c, op, len);
}
}
static void try_read (struct connection *c) {
// debug ( "try read: fd = %d\n", c->fd);
vlogprintf (E_DEBUG, "try read: fd = %d\n", c->fd);
if (!c->in_tail) {
c->in_head = c->in_tail = new_connection_buffer (1 << 20);
}
@ -445,7 +483,7 @@ static void try_read (struct connection *c) {
#endif
int x = 0;
while (1) {
int r = recv (c->fd, (char *)c->in_tail->wptr, c->in_tail->end - c->in_tail->wptr, 0);
int r = read (c->fd, c->in_tail->wptr, c->in_tail->end - c->in_tail->wptr);
if (r > 0) {
c->last_receive_time = tglt_get_double_time ();
stop_ping_timer (c);
@ -462,7 +500,7 @@ static void try_read (struct connection *c) {
c->in_tail = b;
} else {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
debug ("fail_connection: read_error %s\n", strerror(errno));
vlogprintf (E_NOTICE, "fail_connection: read_error %m\n");
fail_connection (c);
return;
} else {
@ -470,13 +508,58 @@ static void try_read (struct connection *c) {
}
}
}
// debug ("Received %d bytes from %d\n", x, c->fd);
vlogprintf (E_DEBUG, "Received %d bytes from %d\n", x, c->fd);
c->in_bytes += x;
if (x) {
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 ++;
}
@ -490,7 +573,7 @@ static struct tgl_session *get_session (struct connection *c) {
}
static void tgln_free (struct connection *c) {
if (c->ip) { free (c->ip); }
if (c->ip) { tfree_str (c->ip); }
struct connection_buffer *b = c->out_head;
while (b) {
struct connection_buffer *d = b;
@ -504,27 +587,16 @@ static void tgln_free (struct connection *c) {
delete_connection_buffer (d);
}
if (c->ping_ev >= 0) {
purple_timeout_remove (c->ping_ev);
c->ping_ev = -1;
}
if (c->fail_ev >= 0) {
purple_timeout_remove (c->fail_ev);
c->fail_ev = -1;
}
if (c->read_ev >= 0) {
purple_input_remove (c->read_ev);
}
if (c->write_ev >= 0) {
purple_input_remove (c->write_ev);
}
if (c->ping_ev) { event_free (c->ping_ev); }
if (c->fail_ev) { event_free (c->fail_ev); }
if (c->read_ev) { event_free (c->read_ev); }
if (c->write_ev) { event_free (c->write_ev); }
if (c->fd >= 0) { close (c->fd); }
c->fd = -1;
tfree (c, sizeof (*c));
}
struct tgl_net_methods tgp_conn_methods = {
struct tgl_net_methods tgl_conn_methods = {
.write_out = tgln_write_out,
.read_in = tgln_read_in,
.read_in_lookup = tgln_read_in_lookup,

View file

@ -20,6 +20,23 @@
#ifndef __NET_H__
#define __NET_H__
#include <poll.h>
#define DC_SERIALIZED_MAGIC 0x64582faa
#define DC_SERIALIZED_MAGIC_V2 0x94032abb
#define STATE_FILE_MAGIC 0x84217a0d
#define SECRET_CHAT_FILE_MAGIC 0xa9840add
struct tgl_dc_serialized {
int magic;
int port;
char ip[64];
char user[64];
char auth_key[256];
long long auth_key_id, server_salt;
int authorized;
};
struct connection_buffer {
unsigned char *start;
unsigned char *end;
@ -54,27 +71,33 @@ struct connection {
int last_connect_time;
int in_fail_timer;
struct mtproto_methods *methods;
struct tgl_state *TLS;
struct tgl_session *session;
struct tgl_dc *dc;
void *extra;
int ping_ev;
int fail_ev;
int read_ev;
int write_ev;
struct event *ping_ev;
struct event *fail_ev;
struct event *read_ev;
struct event *write_ev;
double last_receive_time;
void *prpl_data;
};
//extern struct connection *Connections[];
int tgln_write_out (struct connection *c, const void *data, int len);
void tgln_flush_out (struct connection *c);
int tgln_read_in (struct connection *c, void *data, int len);
int tgln_read_in_lookup (struct connection *c, void *data, int len);
void tgln_insert_msg_id (struct tgl_session *S, long long id);
extern struct tgl_net_methods tgp_conn_methods;
struct connection *tgln_create_connection (struct tgl_state *TLS, const char *host, int port, struct tgl_session *session, struct tgl_dc *dc, struct mtproto_methods *methods);
extern struct tgl_net_methods tgl_conn_methods;
//void create_all_outbound_connections (void);
//struct connection *create_connection (const char *host, int port, struct tgl_session *session, struct connection_methods *methods);
struct tgl_dc *tgln_alloc_dc (int id, char *ip, int port);
void tgln_dc_create_session (struct tgl_dc *DC, struct mtproto_methods *methods);
struct connection *tgln_create_connection (const char *host, int port, struct tgl_session *session, struct tgl_dc *dc, struct mtproto_methods *methods);
#define GET_DC(c) (c->session->dc)
#endif

106
no-preview.h Normal file
View file

@ -0,0 +1,106 @@
/*
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 2013-2014
*/
// Just sample jpg file 90x90
int thumb_file_size = (82 * 6 - 2) * 4;
int thumb_file [] = {
0xe0ffd8ff, 0x464a1000, 0x01004649, 0x64000101, 0x00006400, 0xa002e2ff,
0x5f434349, 0x464f5250, 0x00454c49, 0x00000101, 0x636c9002, 0x3004736d,
0x6e6d0000, 0x47527274, 0x59582042, 0xdd07205a, 0x04000b00, 0x1b001600,
0x63612400, 0x50417073, 0x00004c50, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x0100d6f6, 0x00000000, 0x636c2dd3,
0x0000736d, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x65640b00, 0x00006373, 0x00000801, 0x70633800, 0x00007472, 0x00004001,
0x74774e00, 0x00007470, 0x00009001, 0x68631400, 0x00006461, 0x0000a401,
0x58722c00, 0x00005a59, 0x0000d001, 0x58621400, 0x00005a59, 0x0000e401,
0x58671400, 0x00005a59, 0x0000f801, 0x54721400, 0x00004352, 0x00000c02,
0x54672000, 0x00004352, 0x00002c02, 0x54622000, 0x00004352, 0x00004c02,
0x68632000, 0x00006d72, 0x00006c02, 0x6c6d2400, 0x00006375, 0x00000000,
0x00000100, 0x6e650c00, 0x00005355, 0x00001c00, 0x73001c00, 0x47005200,
0x20004200, 0x75006200, 0x6c006900, 0x2d007400, 0x6e006900, 0x6c6d0000,
0x00006375, 0x00000000, 0x00000100, 0x6e650c00, 0x00005355, 0x00003200,
0x4e001c00, 0x20006f00, 0x6f006300, 0x79007000, 0x69007200, 0x68006700,
0x2c007400, 0x75002000, 0x65007300, 0x66002000, 0x65007200, 0x6c006500,
0x00007900, 0x59580000, 0x0000205a, 0x00000000, 0x0100d6f6, 0x00000000,
0x66732dd3, 0x00003233, 0x01000000, 0x00004a0c, 0xffffe305, 0x00002af3,
0x00009b07, 0xffff87fd, 0xffffa2fb, 0x0000a3fd, 0x0000d803, 0x595894c0,
0x0000205a, 0x00000000, 0x0000946f, 0x0000ee38, 0x59589003, 0x0000205a,
0x00000000, 0x00009d24, 0x0000830f, 0x5958beb6, 0x0000205a, 0x00000000,
0x0000a562, 0x000090b7, 0x6170de18, 0x00006172, 0x03000000, 0x02000000,
0x00006666, 0x0000a7f2, 0x0000590d, 0x0000d013, 0x61705b0a, 0x00006172,
0x03000000, 0x02000000, 0x00006666, 0x0000a7f2, 0x0000590d, 0x0000d013,
0x61705b0a, 0x00006172, 0x03000000, 0x02000000, 0x00006666, 0x0000a7f2,
0x0000590d, 0x0000d013, 0x68635b0a, 0x00006d72, 0x03000000, 0x00000000,
0x0000d7a3, 0x00007b54, 0x0000cd4c, 0x00009a99, 0x00006626, 0xdbff5c0f,
0x14004300, 0x0f120f0e, 0x1112140d, 0x14161712, 0x21331f18, 0x1f1c1c1f,
0x252f2d3f, 0x4e414a33, 0x4841494d, 0x765c5246, 0x6f575264, 0x66484658,
0x7a6f688c, 0x8485847d, 0x9b91634f, 0x769a808f, 0xff7f8481, 0x014300db,
0x1f171716, 0x213c1f1b, 0x547f3c21, 0x7f7f5448, 0x7f7f7f7f, 0x7f7f7f7f,
0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f,
0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x1100c0ff, 0x005a0008,
0x2201035a, 0x01110200, 0xff011103, 0x001900c4, 0x01010101, 0x00000101,
0x00000000, 0x00000000, 0x02030400, 0xc4ff0605, 0x00103600, 0x02010401,
0x06050304, 0x00000306, 0x01000000, 0x11030200, 0x05211204, 0x13514131,
0x32146122, 0x23918171, 0x72423424, 0x432515a1, 0xa2827444, 0xc4fff0b3,
0x01011400, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1400c4ff,
0x00000111, 0x00000000, 0x00000000, 0x00000000, 0xdaff0000, 0x01030c00,
0x03110200, 0x003f0011, 0x404434fb, 0xbcb4875c, 0x006b38b0, 0x03dcdb12,
0xf4637f74, 0xe519f153, 0x09d7c5c7, 0x47d29160, 0x20692f18, 0xd06d786a,
0x53f7f922, 0x17b3e260, 0x2fe8668c, 0x1786a473, 0x9775efbd, 0xe917e43a,
0x1d0a1bb0, 0x114d0f82, 0x14651110, 0x35f299ed, 0xe9b09680, 0xf5a4fc2f,
0xe975bd03, 0xb506737b, 0x04444440, 0x5c444044, 0x8e8dedbd, 0xc61adc7b,
0x689c738b, 0x92a0dc01, 0x58e2b77f, 0x7bfb37d1, 0xb5b5e79d, 0xdbf968cc,
0xead3f48d, 0x38ed1313, 0xdea77c86, 0xae089963, 0xc743435a, 0x403fe4ce,
0x392ee1b9, 0xed39e718, 0xd6517e2d, 0x7fc4aa03, 0xb7ad7590, 0x77e7e6ab,
0x34bf705d, 0x7c77ca53, 0x3dea1299, 0x7fb0bcf4, 0x241fadc5, 0x95a7a816,
0x13fbe6f3, 0x3182b135, 0xd1b4b224, 0x1b0d48a2, 0xbf9d26d8, 0x82dc3640,
0x63569a2a, 0xbbd224c3, 0xb9b4714c, 0x1680aec6, 0x3d311856, 0x9b59be91,
0x09876ca6, 0x61d86564, 0x5a9f06d2, 0x36f51b0d, 0x8682e476, 0xacb1b131,
0xd1584363, 0x00456b4d, 0x22d2053b, 0x22202202, 0xf3f30222, 0xe3e513e5,
0xf1e6e1f0, 0x2380496e, 0x5fdcdb68, 0x549b3a27, 0x825e6a6c, 0x6522028b,
0xaf91ccc8, 0x341cf26b, 0x58dbc4b5, 0xf2289add, 0x0854ddbd, 0x0b9247d5,
0xf02b5c54, 0x3f917f92, 0xaf56affd, 0xe3760637, 0x05cebde0, 0xed4c76ce,
0x3cef1b63, 0x7fd8aff8, 0xa0c902ea, 0x7e730d0a, 0x435834f3, 0x26edbb76,
0xd3ec00fd, 0x76d48efa, 0xa8560f2d, 0x0e766331, 0xd319993c, 0x20243209,
0x61b7e6c8, 0x998331d0, 0x640ee802, 0x47a3d493, 0xfab99413, 0x4fd871f1,
0xe9443792, 0x627e051c, 0xd8f3051c, 0x2f28f558, 0x64b51745, 0x1b2bfee3,
0xb8783953, 0x9900fff6, 0xd8176a65, 0x5a3bf56a, 0x1b331fdb, 0x64b3572f,
0xd59a3643, 0xaf3abce1, 0x11dd20bd, 0x01111110, 0x5c141011, 0xb3e3083f,
0xd9b19cc4, 0x17edb20e, 0xa78e9aa1, 0x4ef4de06, 0x00c0bfe7, 0x7e1e442d,
0x9221fe38, 0xedb5c7dc, 0x6338078a, 0x62495b8d, 0xc11d9b8c, 0x49e81b16,
0x51d02bea, 0x3eb86d70, 0xc8bc4f13, 0xa10ec758, 0xd40751c0, 0x5ac94710,
0xc4c8b080, 0x95492b83, 0x975ee696, 0xb7bd96b4, 0x17379cce, 0x82e856e8,
0xe4c2c82a, 0x398e935f, 0x632437ea, 0x7c9c87d2, 0xdc1ddb7c, 0x65a80a48,
0x2309f164, 0x51fab475, 0x081dc11d, 0xda45573b, 0x6622f3f3, 0x48f1b214,
0x676c4edb, 0x243468c7, 0x00ffde60, 0xf1630350, 0xa0076c1d, 0x8f2c0c8b,
0x2383c26b, 0x361a8f4e, 0xaceea6c9, 0x01dd5a5d, 0x11111011, 0xc3780c04,
0xbf093ee2, 0xc7972c0b, 0x00d99040, 0xc0c20eb7, 0x659d3bd4, 0x269ab85e,
0x468e114f, 0x11ad4fdb, 0x83d083d8, 0x8c52f4bd, 0x3c9664bf, 0xa4f9c77c,
0x22a68876, 0xadb18784, 0xf480be83, 0x885a00ea, 0x220e0a88, 0xc303e4f6,
0xc866e058, 0xdddbd661, 0xdf395db1, 0xbad64343, 0xe6e65b03, 0x668e81c3,
0xad619e98, 0xeeb94563, 0xd4d19a3c, 0x3316ce95, 0x9d65f1e1, 0x3bf324fe,
0x0e468f53, 0xc386068c, 0xa89e24f7, 0xf0c7c73b, 0xb60e391f, 0x1b8827cb,
0x58601954, 0xc54f90f9, 0x80886ec5, 0x88088888, 0x1b7bb980, 0xb4c71c23,
0xe6148e39, 0xb12358b8, 0xbd08225d, 0x0ffef085, 0x72b4f025, 0x635ce389,
0xb90277e4, 0x0d05e000, 0x9bf9dbb9, 0x8e749fbc, 0x7ee6abbf, 0x4ddbf4af,
0x728df7f3, 0x10b59adf, 0xe3c38f49, 0xb23c638a, 0xdb3d9349, 0x66899a64,
0x00004dd5, 0xf51b5adf, 0x2220a255, 0xd9ff0f22};

1
po/.gitignore vendored
View file

@ -1 +0,0 @@
/*.mo

View file

@ -1,11 +0,0 @@
bg
cs_CZ
de_DE
es_AR
fr
it_IT
nl
pl_PL
ru_RU
sq
uk

View file

@ -1,6 +0,0 @@
# This file lists translations that are too bad or incomplete for installation.
# If you would like to improve the state of this, please see the translation page:
# https://www.transifex.com/telegram-purple-developers/telegram-purple/
da # < 55% complete
pt_BR # < 75% complete

View file

@ -1,11 +0,0 @@
# List of source files containing translatable strings.
telegram-base.c
telegram-purple.c
tgp-2prpl.c
tgp-msg.c
tgp-net.c
tgp-request.c
tgp-utils.c
tgp-chat.c

614
po/bg.po
View file

@ -1,614 +0,0 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-08-31 22:53+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Любомир Василев <lyubomirv@abv.bg>, 2016\n"
"Language-Team: Bulgarian (https://www.transifex.com/telegram-purple-developers/teams/53149/bg/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: bg\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: ../telegram-base.c:500
msgid "Couldn't create group"
msgstr "Неуспешно създаване на група"
#: ../telegram-base.c:501
msgid "Please select at least one other user."
msgstr "Моля, изберете поне един друг потребител:"
#: ../telegram-base.c:555
msgid "Query Failed"
msgstr "Заявката беше неуспешна"
#: ../telegram-purple.c:162
msgid "Secret chat ready."
msgstr "Тайният разговор е готов."
#: ../telegram-purple.c:170
msgid "Secret chat terminated."
msgstr "Тайният разговор беше приключен."
#: ../telegram-purple.c:182
msgid "Telegram"
msgstr "Telegram"
#: ../telegram-purple.c:229
msgid "Message marked as read."
msgstr "Съобщението е отбелязано като прочетено."
#: ../telegram-purple.c:339
#, c-format
msgid "Invite link: %s"
msgstr "Връзка за покана: %s"
#. FIXME: Can TGLCHF_MODERATOR export links?
#: ../telegram-purple.c:350
msgid "Creating chat link failed"
msgstr "Създаването на връзка беше неуспешно"
#: ../telegram-purple.c:351
msgid "You need to be admin of the group to do that."
msgstr "Само администраторите на групата могат да правят това."
#: ../telegram-purple.c:416
msgid "Chat joined"
msgstr "Присъединихте се към разговора"
#: ../telegram-purple.c:417
msgid "Chat added to list of chat rooms."
msgstr "Разговорът беше добавен към списъка от стаи за разговори."
#: ../telegram-purple.c:443
msgid "Start secret chat..."
msgstr "Започване на таен разговор…"
#. Generate Public Link
#: ../telegram-purple.c:450
msgid "Invite users by link..."
msgstr "Покана на потребители чрез връзка…"
#. Delete self from chat
#: ../telegram-purple.c:458
msgid "Delete and exit..."
msgstr "Изтриване и изход…"
#: ../telegram-purple.c:546
#, c-format
msgid "Unable to sign on as %s: file (public key) not found."
msgstr "Неуспешно вписване като %s: файлът (публичният ключ) не беше открит."
#: ../telegram-purple.c:550
#, c-format
msgid ""
"Make sure telegram-purple is installed properly,\n"
"including the .tglpub file.\n"
"If you're running SELinux (e.g. when using Tails),\n"
"try 'make local_install', or simply copy\n"
"%1$s to %2$s."
msgstr ""
"Уверете се, че „telegram-purple“ е инсталирано правилно,\n"
"включително файлът „.tglpub“.\n"
"Ако използвате SELinux (наприбер при използване на „Tails“),\n"
"опитайте „make local_install“ или просто копирайте\n"
"%1$s в %2$s."
#: ../telegram-purple.c:572
#, c-format
msgid ""
"Unable to sign on as %s: problem in the underlying library 'tgl'. Please "
"submit a bug report with the debug log."
msgstr ""
"Неуспешно вписване като %s: има проблем с вътрешната библиотека „tgl“. Моля,"
" изпратете доклад за грешката, заедно с журнала."
#: ../telegram-purple.c:576
msgid "Problem in tgl"
msgstr "Проблем в „tgl“"
#. TRANSLATORS: Please fill in your own prefix!
#: ../telegram-purple.c:584
#, c-format
msgid ""
"Unable to sign on as %s: phone number lacks country prefix. Numbers must "
"start with the full international prefix code, e.g. +1 for USA."
msgstr ""
"Неуспешно вписване като %s: телефонният код не съдържа код на страната. "
"Номерата трябва да започват с пълния международен телефонен код на страната,"
" например +359 за България."
#: ../telegram-purple.c:589
msgid "Incomplete phone number"
msgstr "Непълен телефонен номер"
#: ../telegram-purple.c:642
msgid "Secret chat was already deleted"
msgstr "Тайният разговор вече е изтрит"
#: ../telegram-purple.c:644
msgid "Secret chat is not ready"
msgstr "Тайният разговор не е готов"
#: ../telegram-purple.c:652
msgid "Only the creator of a channel can post messages."
msgstr "Само създателят на канала може да публикува съобщения."
#: ../telegram-purple.c:695
msgid "Cannot invite buddy to chat"
msgstr "Неуспешно канене на приятел в разговора"
#: ../telegram-purple.c:696
msgid "Specified user does not exist."
msgstr "Посоченият потребител не съществува."
#: ../telegram-purple.c:709
msgid "phone no. (+ country prefix)"
msgstr "тел. номер (+ код на страната)"
#. Login
#: ../telegram-purple.c:817
msgid "Password (two factor authentication)"
msgstr "Парола (двустепенно удостоверяване)"
#: ../telegram-purple.c:822
msgid ""
"Fallback SMS verification\n"
"(Helps when not using Pidgin and you aren't being prompted for the code)"
msgstr ""
"Резервно удостоверяване чрез КС\n"
"(Помага, когато не използвате „Pidgin“ и от Вас не се изисква кода)"
#: ../telegram-purple.c:828
msgid "always"
msgstr "винаги"
#: ../telegram-purple.c:829
msgid "never"
msgstr "никога"
#: ../telegram-purple.c:830
msgid "ask"
msgstr "питане всеки път"
#: ../telegram-purple.c:832
msgid "Accept secret chats"
msgstr "Приемане на тайни разговори"
#: ../telegram-purple.c:836
msgid "Display buddies offline after (days)"
msgstr "Показване на приятелите извън линия след (брой дни)"
#: ../telegram-purple.c:840
msgid ""
"Don't fetch history older than (days)\n"
"(0 for unlimited)"
msgstr ""
"Да не се изтегля историята, по-стара от (брой дни)\n"
"(0 = неограничено)"
#. Media
#: ../telegram-purple.c:845
msgid "Autoload media size (kb)"
msgstr "Размер за авто. зареждане на медийни файлове (кбит)"
#. Chats
#: ../telegram-purple.c:850
msgid "Add all group chats to buddy list"
msgstr "Добавяне на всички групови разговори в списъка с приятели"
#. Read notifications
#: ../telegram-purple.c:855
msgid "Display notices of receipt"
msgstr "Показване на уведомления за получаване"
#: ../telegram-purple.c:859
msgid "Send notices of receipt when present"
msgstr "Изпращане на уведомления за получаване при присъствие"
#: ../telegram-purple.c:884
msgid "Telegram Protocol Plugin."
msgstr "Добавка за протокола „Telegram“."
#: ../tgp-msg.c:58
#, c-format
msgid "%2$s created chat %1$s."
msgstr "%2$s създаде разговор %1$s."
#: ../tgp-msg.c:61
#, c-format
msgid "%2$s changed title to %1$s."
msgstr "%2$s промени заглавието на „%1$s“."
#: ../tgp-msg.c:64
#, c-format
msgid "%s changed photo."
msgstr "%s промени снимката си."
#: ../tgp-msg.c:67
#, c-format
msgid "%s deleted photo."
msgstr "%s изтри снимка."
#: ../tgp-msg.c:75
#, c-format
msgid "%1$s added user %2$s by link."
msgstr "%1$s добави потребителя %2$s чрез връзка."
#: ../tgp-msg.c:90
#, c-format
msgid "%2$s added user %1$s."
msgstr "%2$s добави потребителя %1$s."
#: ../tgp-msg.c:114 ../tgp-msg.c:131
#, c-format
msgid "%2$s deleted user %1$s."
msgstr "%2$s изтри потребителя %1$s."
#: ../tgp-msg.c:138
#, c-format
msgid "%2$s set self destruction timer to %1$d second."
msgid_plural "%2$s set self destruction timer to %1$d seconds."
msgstr[0] "%2$s настрои брояч за самоунищожение на %1$d секунда."
msgstr[1] "%2$s настрои брояч за самоунищожение на %1$d секунди."
#: ../tgp-msg.c:144
#, c-format
msgid "%2$s marked %1$d message read."
msgid_plural "%2$s marked %1$d messages read."
msgstr[0] "%2$s отбеляза %1$d съобщение като прочетено."
msgstr[1] "%2$s отбеляза %1$d съобщения като прочетени."
#: ../tgp-msg.c:150
#, c-format
msgid "%2$s deleted %1$d message."
msgid_plural "%2$s deleted %1$d messages."
msgstr[0] "%2$s изтри %1$d съобщение."
msgstr[1] "%2$s изтри %1$d съобщения."
#: ../tgp-msg.c:156
#, c-format
msgid "%2$s made a screenshot of %1$d message."
msgid_plural "%2$s made a screenshot of %1$d messages."
msgstr[0] "%2$s направи снимка на %1$d съобщение."
msgstr[1] "%2$s направи снимка на %1$d съобщения."
#: ../tgp-msg.c:162
#, c-format
msgid "Channel %1$s created"
msgstr "Каналът „%1$s“ беше създаден"
#. FIXME: check if this makes sense
#: ../tgp-msg.c:165 ../tgp-chat.c:124 ../tgp-chat.c:576
msgid "Telegram Channels"
msgstr "Канали в Telegram"
#: ../tgp-msg.c:191
msgid "Sending message failed."
msgstr "Неуспешно изпращане на съобщението."
#: ../tgp-msg.c:253
msgid "Sending image failed."
msgstr "Неуспешно изпращане на изображениео."
#: ../tgp-msg.c:417
#, c-format
msgid "%s sent a sticker."
msgstr "%s изпрати стикер."
#: ../tgp-msg.c:463
msgid "failed loading message"
msgstr "неуспешно зареждане на съобщение"
#: ../tgp-msg.c:498
msgid "[animation]"
msgstr "[анимация]"
#: ../tgp-msg.c:515
msgid "[audio]"
msgstr "[звук]"
#: ../tgp-msg.c:515
msgid "[video]"
msgstr "[видео]"
#: ../tgp-msg.c:604
#, c-format
msgid "<b>Forwarded message from: %s</b><br>%s"
msgstr "<b>Препратено съобщение от: %s</b><br>%s"
#. FIXME: sometimes users aren't part of the response when receiving a
#. forwarded message
#: ../tgp-msg.c:607
#, c-format
msgid "<b>Forwarded message:</b><br>%s"
msgstr "<b>Препратено съобщение:</b><br>%s"
#: ../tgp-msg.c:720
msgid "loading document or picture failed"
msgstr "неуспешно зареждане на документ или изображение"
#: ../tgp-net.c:281
msgid "Cannot connect to main server"
msgstr "Неуспешно свързване с главния сървър"
#: ../tgp-net.c:322
msgid "Cannot connect to server: Ping timeout."
msgstr "Неуспешно свързване със сървъра. Изтече времето за изчакване."
#: ../tgp-net.c:365
msgid "Lost connection to the server..."
msgstr "Връзката със сървъра беше прекъсната…"
#: ../tgp-request.c:51
msgid ""
"Telegram wants to verify your identity. Please enter the login code that you"
" have received via SMS."
msgstr ""
"Telegram иска да потвърди самоличността Ви. Моля, въведете кода за влизане, "
"който трябва да сте получили чрез КС."
#: ../tgp-request.c:54
msgid "Login code"
msgstr "Код за влизане"
#: ../tgp-request.c:54
msgid "Enter login code"
msgstr "Въведете кода за влизане"
#: ../tgp-request.c:54
msgid "the code"
msgstr "кодът"
#: ../tgp-request.c:54 ../tgp-request.c:104 ../tgp-request.c:198
#: ../tgp-request.c:233 ../tgp-request.c:263
msgid "OK"
msgstr "Добре"
#: ../tgp-request.c:55 ../tgp-request.c:104 ../tgp-request.c:123
#: ../tgp-request.c:199 ../tgp-request.c:234 ../tgp-request.c:264
msgid "Cancel"
msgstr "Отказ"
#: ../tgp-request.c:95
msgid "Registration"
msgstr "Регистрация"
#: ../tgp-request.c:96
msgid "First name"
msgstr "Собствено име"
#: ../tgp-request.c:99
msgid "Last name"
msgstr "Фамилия"
#: ../tgp-request.c:103
msgid "Register"
msgstr "Регистриране"
#: ../tgp-request.c:103
msgid "Please register your phone number."
msgstr "Моля, регистрирайте телефонния си номер"
#. purple_request API not available
#: ../tgp-request.c:108
msgid ""
"Phone number is not registered. Please register your phone on a different "
"client."
msgstr ""
"Телефонният номер не е регистриран. Моля, регистрирайте телефона си чрез "
"друг клиент."
#: ../tgp-request.c:110
msgid "Not registered"
msgstr "Нерегистриран"
#: ../tgp-request.c:122
msgid "Password needed"
msgstr "Нужна е парола"
#: ../tgp-request.c:122
msgid "Enter password for two factor authentication"
msgstr "Въведете парола за двустепенно удостоверяване"
#: ../tgp-request.c:123
msgid "Ok"
msgstr "Добре"
#: ../tgp-request.c:125
msgid ""
"No password set for two factor authentication. Please enter it in the "
"extended settings."
msgstr ""
"Няма зададена парола за двустепенно удостоверяване. Моля, въведете я в "
"разширените настройки."
#: ../tgp-request.c:127
msgid "Password invalid"
msgstr "Паролата е грешна"
#: ../tgp-request.c:150
#, c-format
msgid "Accept secret chat '%s' on this device?"
msgstr "Приемане на тайния разговор „%s“ на това устройство?"
#: ../tgp-request.c:151
msgid "Secret chat"
msgstr "Таен разговор"
#: ../tgp-request.c:151
msgid ""
"Secret chats can only have one end point. If you accept a secret chat on "
"this device, its messages will not be available anywhere else. If you "
"decline, you can still accept the chat on other devices."
msgstr ""
"Тайните разговори могат да се провеждат само на едно устройство. Ако "
"приемете таен разговор на това устройство, той няма да бъде достъпен никъде "
"другаде. Ако откажете, ще можете да го приемете на друго устройство."
#: ../tgp-request.c:182
msgid ""
"Invite at least one additional user by specifying\n"
" their full name (autocompletion available).\n"
"You can add more users once the chat was created."
msgstr ""
"Поканете поне още един потребител, като посочите\n"
" пълното му име (разполагате с авт. допълване).\n"
"Можете да добавите повече потребители и след началото на разговора."
#: ../tgp-request.c:185 ../tgp-request.c:189 ../tgp-request.c:193
msgid "Username"
msgstr "Потребителско име"
#: ../tgp-request.c:198
msgid "Create group chat"
msgstr "Създаване на групов разговор"
#: ../tgp-request.c:198
msgid "Invite users"
msgstr "Канене на потребители"
#: ../tgp-request.c:217 ../tgp-request.c:232
msgid "Change password"
msgstr "Промяна на паролата"
#: ../tgp-request.c:219
msgid "Current"
msgstr "Текуща"
#: ../tgp-request.c:223 ../tgp-request.c:253
msgid "Password"
msgstr "Парола"
#: ../tgp-request.c:227 ../tgp-request.c:257
msgid "Confirm"
msgstr "Потвърждаване"
#: ../tgp-request.c:251 ../tgp-request.c:262
msgid "New password"
msgstr "Нова парола"
#. if we arrive here for the second time the specified phone number is not
#. valid. We do not
#. ask for the phone number directly, cause in that case the account would
#. still be created
#. named with the invalid phone number, even though the login will work
#: ../tgp-request.c:300
msgid "Invalid phone number"
msgstr "Грешен телефонен номер"
#: ../tgp-request.c:301
msgid ""
"Please enter only numbers in the international phone number format, a leading + following by the country prefix and the phone number.\n"
"Do not use any other special chars."
msgstr ""
"Моля, въвеждайте само цифри във формата за международен телефонен номер: знака +, следван от кода на страната и телефонния номер.\n"
"Не използвайте други специални знаци."
#: ../tgp-request.c:370
msgid "Leave Chat"
msgstr "Напускане на разговора"
#: ../tgp-request.c:372
msgid "Do you want to leave this chat permantently?"
msgstr "Наистина ли искате да напуснете този разговор завинаги?"
#: ../tgp-request.c:377
msgid "Abort Secret Chat"
msgstr "Край на тайния разговор"
#: ../tgp-request.c:379
msgid "Do you want to terminate this secret chat permantently?"
msgstr "Наистина ли искате да прекратите този таен разговор завинаги?"
#: ../tgp-request.c:384
msgid "Delete Contact"
msgstr "Изтриване на контакта"
#: ../tgp-request.c:386
msgid "Do you want to remove this user from your global contact list?"
msgstr ""
"Наистина ли искате да премахнете този потребител от общия си списък с "
"контакти?"
#: ../tgp-request.c:401
msgid "Leave Channel"
msgstr "Напускане на канала"
#: ../tgp-request.c:403
msgid "Do you want to leave this channel?"
msgstr "Наистина ли искате да напуснете този канал?"
#. This should be the language's timestamp format. This is preceded by a
#. colon.
#: ../tgp-utils.c:27
msgid "%d.%m.%Y %H:%M"
msgstr "%d.%m.%Y %H:%M"
#. This is preceded by a colon.
#: ../tgp-utils.c:48
msgid "recently"
msgstr "наскоро"
#. This is preceded by a colon.
#: ../tgp-utils.c:52
msgid "last week"
msgstr "последната седмица"
#. This is preceded by a colon.
#: ../tgp-utils.c:56
msgid "last month"
msgstr "последния месец"
#. This is preceded by a colon. It refers to a point on time.
#: ../tgp-utils.c:60
msgid "unknown"
msgstr "неизвестно"
#: ../tgp-chat.c:108 ../tgp-chat.c:582
msgid "Telegram Chats"
msgstr "Разговори в Telegram"
#: ../tgp-chat.c:113
msgid "You have already left this chat."
msgstr "Вече сте напуснали този разговор"
#: ../tgp-chat.c:224
msgid "Subject:"
msgstr "Тема:"
#: ../tgp-chat.c:230
msgid "Invite link:"
msgstr "Връзка за покана:"
#: ../tgp-chat.c:236
msgid "Chat ID:"
msgstr "Ид. на разговора:"
#: ../tgp-chat.c:342
msgid "Supergroup"
msgstr "Надгрупа"
#: ../tgp-chat.c:342
msgid "Channel"
msgstr "Канал"
#: ../tgp-chat.c:345
msgid "Group"
msgstr "Група"
#: ../tgp-chat.c:367
msgid "Users in chat"
msgstr "Потребители в разговора"
#: ../tgp-chat.c:370
msgid "Type"
msgstr "Вид"

Some files were not shown because too many files have changed in this diff Show more