Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
60f4f504
Commit
60f4f504
authored
Oct 05, 2014
by
Steve Illichevskiy
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
parents
52470ce2
7a9764f2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
138 additions
and
14 deletions
+138
-14
README-LUA
README-LUA
+2
-0
interface.c
interface.c
+47
-7
lua-tg.c
lua-tg.c
+24
-1
queries.c
queries.c
+62
-4
structures.c
structures.c
+2
-2
tgl.h
tgl.h
+1
-0
No files found.
README-LUA
View file @
60f4f504
...
...
@@ -74,5 +74,7 @@ Function_list (arguments are listed aside from cb_function and cb_extra, :
status_online ()
status_offline ()
send_location (peer, latitude, longitude)
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).
interface.c
View file @
60f4f504
...
...
@@ -292,6 +292,23 @@ long long cur_token_int (void) {
}
}
double
cur_token_double
(
void
)
{
if
(
cur_token_len
<=
0
)
{
return
NOT_FOUND
;
}
else
{
char
c
=
cur_token
[
cur_token_len
];
cur_token
[
cur_token_len
]
=
0
;
char
*
end
=
0
;
double
x
=
strtod
(
cur_token
,
&
end
);
cur_token
[
cur_token_len
]
=
c
;
if
(
end
!=
cur_token
+
cur_token_len
)
{
return
NOT_FOUND
;
}
else
{
return
x
;
}
}
}
tgl_peer_id_t
cur_token_user
(
void
)
{
if
(
cur_token_len
<=
0
)
{
return
TGL_PEER_NOT_FOUND
;
}
int
l
=
cur_token_len
;
...
...
@@ -519,6 +536,7 @@ enum command_argument {
ca_file_name_end
,
ca_period
,
ca_number
,
ca_double
,
ca_string_end
,
ca_string
,
ca_modifier
,
...
...
@@ -536,6 +554,7 @@ struct arg {
struct
tgl_message
*
M
;
char
*
str
;
long
long
num
;
double
dval
;
};
};
...
...
@@ -996,6 +1015,11 @@ void do_clear (int arg_num, struct arg args[], struct in_ev *ev) {
do_halt
(
0
);
}
void
do_send_location
(
int
arg_num
,
struct
arg
args
[],
struct
in_ev
*
ev
)
{
assert
(
arg_num
==
3
);
tgl_do_send_location
(
args
[
0
].
P
->
id
,
args
[
1
].
dval
,
args
[
2
].
dval
,
0
,
0
);
}
struct
command
commands
[]
=
{
{
"help"
,
{
ca_none
},
do_help
,
"help
\t
Prints this help"
},
...
...
@@ -1054,6 +1078,7 @@ struct command commands[] = {
{
"send_contact"
,
{
ca_peer
,
ca_string
,
ca_string
,
ca_string
,
ca_none
},
do_send_contact
,
"send_contact <peer> <phone> <first-name> <last-name>
\t
Sends contact (not necessary telegram user)"
},
{
"main_session"
,
{
ca_none
},
do_main_session
,
"main_session
\t
Sends updates to this connection (or terminal). Useful only with listening socket"
},
{
"clear"
,
{
ca_none
},
do_clear
,
"clear
\t
Clears all data and exits. For debug."
},
{
"send_location"
,
{
ca_peer
,
ca_double
,
ca_double
,
ca_none
},
do_send_location
,
"send_location <peer> <latitude> <longitude>
\t
Sends geo location"
},
{
0
,
{
ca_none
},
0
,
""
}
};
...
...
@@ -1116,7 +1141,7 @@ enum command_argument get_complete_mode (void) {
char
*
save
=
line_ptr
;
next_token
();
if
(
op
==
ca_user
||
op
==
ca_chat
||
op
==
ca_secret_chat
||
op
==
ca_peer
||
op
==
ca_number
)
{
if
(
op
==
ca_user
||
op
==
ca_chat
||
op
==
ca_secret_chat
||
op
==
ca_peer
||
op
==
ca_number
||
op
==
ca_double
)
{
if
(
cur_token_quoted
)
{
if
(
opt
)
{
line_ptr
=
save
;
...
...
@@ -1145,6 +1170,9 @@ enum command_argument get_complete_mode (void) {
case
ca_number
:
ok
=
(
cur_token_int
()
!=
NOT_FOUND
);
break
;
case
ca_double
:
ok
=
(
cur_token_double
()
!=
NOT_FOUND
);
break
;
default:
assert
(
0
);
}
...
...
@@ -1230,7 +1258,7 @@ char *command_generator (const char *text, int state) {
if
(
index
==
-
1
)
{
return
0
;
}
}
if
(
mode
==
ca_none
||
mode
==
ca_string
||
mode
==
ca_string_end
||
mode
==
ca_number
)
{
if
(
mode
==
ca_none
||
mode
==
ca_string
||
mode
==
ca_string_end
||
mode
==
ca_number
||
mode
==
ca_double
)
{
if
(
c
)
{
rl_line_buffer
[
rl_point
]
=
c
;
}
return
0
;
}
...
...
@@ -1999,13 +2027,17 @@ void interpreter_ex (char *line UU, void *ex) {
break
;
}
if
(
op
==
ca_user
||
op
==
ca_chat
||
op
==
ca_secret_chat
||
op
==
ca_peer
||
op
==
ca_number
)
{
if
(
op
==
ca_user
||
op
==
ca_chat
||
op
==
ca_secret_chat
||
op
==
ca_peer
||
op
==
ca_number
||
op
==
ca_double
)
{
if
(
cur_token_quoted
)
{
if
(
opt
)
{
if
(
op
!=
ca_number
)
{
if
(
op
!=
ca_number
&&
op
!=
ca_double
)
{
args
[
args_num
++
].
P
=
0
;
}
else
{
args
[
args_num
++
].
num
=
NOT_FOUND
;
if
(
op
==
ca_number
)
{
args
[
args_num
++
].
num
=
NOT_FOUND
;
}
else
{
args
[
args_num
++
].
dval
=
NOT_FOUND
;
}
}
line_ptr
=
save
;
flags
++
;
...
...
@@ -2016,10 +2048,14 @@ void interpreter_ex (char *line UU, void *ex) {
}
else
{
if
(
cur_token_end_str
)
{
if
(
opt
)
{
if
(
op
!=
ca_number
)
{
if
(
op
!=
ca_number
&&
op
!=
ca_double
)
{
args
[
args_num
++
].
P
=
0
;
}
else
{
args
[
args_num
++
].
num
=
NOT_FOUND
;
if
(
op
==
ca_number
)
{
args
[
args_num
++
].
num
=
NOT_FOUND
;
}
else
{
args
[
args_num
++
].
dval
=
NOT_FOUND
;
}
}
line_ptr
=
save
;
flags
++
;
...
...
@@ -2050,6 +2086,10 @@ void interpreter_ex (char *line UU, void *ex) {
args
[
args_num
++
].
num
=
cur_token_int
();
ok
=
(
args
[
args_num
-
1
].
num
!=
NOT_FOUND
);
break
;
case
ca_double
:
args
[
args_num
++
].
dval
=
cur_token_double
();
ok
=
(
args
[
args_num
-
1
].
dval
!=
NOT_FOUND
);
break
;
default:
assert
(
0
);
}
...
...
lua-tg.c
View file @
60f4f504
...
...
@@ -495,6 +495,7 @@ enum lua_query_type {
lq_send_contact
,
lq_status_online
,
lq_status_offline
,
lq_send_location
,
lq_extf
};
...
...
@@ -1086,6 +1087,14 @@ void lua_do_all (void) {
free
(
s
);
p
+=
2
;
break
;
case
lq_send_location
:
if
(
sizeof
(
void
*
)
==
4
)
{
tgl_do_send_location
(((
tgl_peer_t
*
)
lua_ptr
[
p
+
1
])
->
id
,
*
(
float
*
)(
lua_ptr
+
p
+
2
),
*
(
float
*
)(
lua_ptr
+
p
+
3
),
lua_msg_cb
,
lua_ptr
[
p
]);
}
else
{
tgl_do_send_location
(((
tgl_peer_t
*
)
lua_ptr
[
p
+
1
])
->
id
,
*
(
double
*
)(
lua_ptr
+
p
+
2
),
*
(
double
*
)(
lua_ptr
+
p
+
3
),
lua_msg_cb
,
lua_ptr
[
p
]);
}
p
+=
4
;
break
;
/*
lq_delete_msg,
lq_restore_msg,
...
...
@@ -1120,7 +1129,8 @@ enum lua_function_param {
lfp_number
,
lfp_positive_number
,
lfp_nonnegative_number
,
lfp_msg
lfp_msg
,
lfp_double
};
struct
lua_function
{
...
...
@@ -1168,6 +1178,7 @@ struct lua_function functions[] = {
{
"send_contact"
,
lq_send_contact
,
{
lfp_peer
,
lfp_string
,
lfp_string
,
lfp_string
,
lfp_none
}},
{
"status_online"
,
lq_status_online
,
{
lfp_none
}},
{
"status_offline"
,
lq_status_offline
,
{
lfp_none
}},
{
"send_location"
,
lq_send_location
,
{
lfp_peer
,
lfp_double
,
lfp_double
,
lfp_none
}},
{
"ext_function"
,
lq_extf
,
{
lfp_string
,
lfp_none
}},
{
0
,
0
,
{
lfp_none
}}
};
...
...
@@ -1203,6 +1214,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) {
const
char
*
s
;
tgl_peer_t
*
P
;
long
long
num
;
double
dval
;
struct
tgl_message
*
M
;
switch
(
F
->
params
[
p
])
{
case
lfp_none
:
...
...
@@ -1256,6 +1268,17 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) {
lua_ptr
[
pos
+
p
]
=
(
void
*
)(
long
)
num
;
break
;
case
lfp_double
:
dval
=
lua_tonumber
(
L
,
-
cc
);
if
(
sizeof
(
void
*
)
==
4
)
{
*
(
float
*
)(
lua_ptr
+
pos
+
p
)
=
dval
;
}
else
{
assert
(
sizeof
(
void
*
)
>=
8
);
*
(
double
*
)(
lua_ptr
+
pos
+
p
)
=
dval
;
}
break
;
case
lfp_positive_number
:
num
=
lua_tonumber
(
L
,
-
cc
);
if
(
num
<=
0
)
{
...
...
queries.c
View file @
60f4f504
...
...
@@ -1837,9 +1837,7 @@ static void send_part (struct send_file *f, void *callback, void *callback_extra
out_cstring
((
void
*
)
f
->
key
,
32
);
out_cstring
((
void
*
)
f
->
init_iv
,
32
);
long
long
msg_id
;
tglt_secure_random
(
&
msg_id
,
8
);
bl_do_create_message_media_encr_pending
(
msg_id
,
tgl_state
.
our_id
,
tgl_get_peer_type
(
f
->
to_id
),
tgl_get_peer_id
(
f
->
to_id
),
time
(
0
),
0
,
0
,
save_ptr
,
packet_ptr
-
save_ptr
);
bl_do_create_message_media_encr_pending
(
r
,
tgl_state
.
our_id
,
tgl_get_peer_type
(
f
->
to_id
),
tgl_get_peer_id
(
f
->
to_id
),
time
(
0
),
0
,
0
,
save_ptr
,
packet_ptr
-
save_ptr
);
encr_finish
(
&
P
->
encr_chat
);
if
(
f
->
size
<
(
16
<<
20
))
{
...
...
@@ -1861,7 +1859,7 @@ static void send_part (struct send_file *f, void *callback, void *callback_extra
out_int
((
*
(
int
*
)
md5
)
^
(
*
(
int
*
)(
md5
+
4
)));
tfree_secure
(
f
->
iv
,
32
);
struct
tgl_message
*
M
=
tgl_message_get
(
msg_id
);
struct
tgl_message
*
M
=
tgl_message_get
(
r
);
assert
(
M
);
//M->media.encr_photo.key = f->key;
...
...
@@ -1997,6 +1995,7 @@ void tgl_do_set_profile_photo (char *file_name, void (*callback)(void *callback_
}
/* }}} */
/* {{{ Forward */
static
int
fwd_msg_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_messages_stated_message
);
...
...
@@ -2147,6 +2146,65 @@ void tgl_do_forward_media (tgl_peer_id_t id, int n, void (*callback)(void *callb
}
/* }}} */
/* {{{ Send location */
void
tgl_do_send_location
(
tgl_peer_id_t
id
,
double
latitude
,
double
longitude
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
)
{
if
(
tgl_get_peer_type
(
id
)
==
TGL_PEER_ENCR_CHAT
)
{
clear_packet
();
out_int
(
CODE_messages_send_encrypted
);
out_int
(
CODE_input_encrypted_chat
);
out_int
(
tgl_get_peer_id
(
id
));
tgl_peer_t
*
P
=
tgl_peer_get
(
id
);
assert
(
P
);
out_long
(
P
->
encr_chat
.
access_hash
);
long
long
r
;
tglt_secure_random
(
&
r
,
8
);
out_long
(
r
);
encr_start
();
if
(
P
->
encr_chat
.
layer
<=
16
)
{
out_int
(
CODE_decrypted_message_l16
);
}
else
{
out_int
(
CODE_decrypted_message
);
out_int
(
2
*
P
->
encr_chat
.
in_seq_no
+
(
P
->
encr_chat
.
admin_id
!=
tgl_state
.
our_id
));
out_int
(
2
*
P
->
encr_chat
.
out_seq_no
+
(
P
->
encr_chat
.
admin_id
==
tgl_state
.
our_id
)
+
2
);
out_int
(
0
);
}
out_long
(
r
);
out_random
(
15
+
4
*
(
lrand48
()
%
3
));
out_string
(
""
);
int
*
save_ptr
=
packet_ptr
;
out_int
(
CODE_decrypted_message_media_geo_point
);
out_double
(
latitude
);
out_double
(
longitude
);
bl_do_create_message_media_encr_pending
(
r
,
tgl_state
.
our_id
,
tgl_get_peer_type
(
id
),
tgl_get_peer_id
(
id
),
time
(
0
),
0
,
0
,
save_ptr
,
packet_ptr
-
save_ptr
);
encr_finish
(
&
P
->
encr_chat
);
struct
tgl_message
*
M
=
tgl_message_get
(
r
);
assert
(
M
);
tglq_send_query
(
tgl_state
.
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
msg_send_encr_methods
,
M
,
callback
,
callback_extra
);
}
else
{
long
long
t
;
tglt_secure_random
(
&
t
,
8
);
vlogprintf
(
E_DEBUG
,
"t = %lld
\n
"
,
t
);
clear_packet
();
out_int
(
CODE_messages_send_media
);
out_peer_id
(
id
);
out_int
(
CODE_input_media_geo_point
);
out_int
(
CODE_input_geo_point
);
out_double
(
latitude
);
out_double
(
longitude
);
out_long
(
t
);
tglq_send_query
(
tgl_state
.
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
fwd_msg_methods
,
0
,
callback
,
callback_extra
);
}
}
/* }}} */
/* {{{ Rename chat */
static
int
rename_chat_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_messages_stated_message
);
...
...
structures.c
View file @
60f4f504
...
...
@@ -540,8 +540,8 @@ void tglf_fetch_photo_size (struct tgl_photo_size *S) {
void
tglf_fetch_geo
(
struct
tgl_geo
*
G
)
{
unsigned
x
=
fetch_int
();
if
(
x
==
CODE_geo_point
)
{
G
->
longitude
=
fetch_double
();
G
->
latitude
=
fetch_double
();
G
->
longitude
=
fetch_double
();
}
else
{
assert
(
x
==
CODE_geo_point_empty
);
G
->
longitude
=
0
;
...
...
@@ -951,8 +951,8 @@ void tglf_fetch_message_media_encrypted (struct tgl_message_media *M) {
*/
case
CODE_decrypted_message_media_geo_point
:
M
->
type
=
tgl_message_media_geo
;
M
->
geo
.
longitude
=
fetch_double
();
M
->
geo
.
latitude
=
fetch_double
();
M
->
geo
.
longitude
=
fetch_double
();
break
;
case
CODE_decrypted_message_media_contact
:
M
->
type
=
tgl_message_media_contact
;
...
...
tgl.h
View file @
60f4f504
...
...
@@ -295,6 +295,7 @@ void tgl_do_send_contact (tgl_peer_id_t id, const char *phone, int phone_len, co
void
tgl_do_forward_media
(
tgl_peer_id_t
id
,
int
n
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_del_contact
(
tgl_peer_id_t
id
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
);
void
tgl_do_set_encr_chat_ttl
(
struct
tgl_secret_chat
*
E
,
int
ttl
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_send_location
(
tgl_peer_id_t
id
,
double
latitude
,
double
longitude
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_visualize_key
(
tgl_peer_id_t
id
,
unsigned
char
buf
[
16
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment