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
73cdb880
Commit
73cdb880
authored
Oct 23, 2013
by
vysheng
Browse files
Options
Browse Files
Download
Plain Diff
Merge github.com:vysheng/tg
parents
121f0f1d
94d55325
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
7 deletions
+158
-7
interface.c
interface.c
+56
-5
interface.h
interface.h
+2
-1
loop.c
loop.c
+6
-0
queries.c
queries.c
+91
-1
queries.h
queries.h
+2
-0
structures.h
structures.h
+1
-0
No files found.
interface.c
View file @
73cdb880
...
...
@@ -36,6 +36,7 @@ char *commands[] = {
"send_photo"
,
"send_video"
,
"send_text"
,
"chat_info"
,
0
};
int
commands_flags
[]
=
{
...
...
@@ -48,6 +49,7 @@ int commands_flags[] = {
0732
,
0732
,
0732
,
074
,
};
char
*
a
=
0
;
...
...
@@ -132,6 +134,19 @@ int complete_user_list (int index, const char *text, int len, char **R) {
}
}
int
complete_chat_list
(
int
index
,
const
char
*
text
,
int
len
,
char
**
R
)
{
index
++
;
while
(
index
<
user_num
+
chat_num
&&
(
!
Peers
[
index
]
->
print_name
||
strncmp
(
Peers
[
index
]
->
print_name
,
text
,
len
)
||
Peers
[
index
]
->
id
>
0
))
{
index
++
;
}
if
(
index
<
user_num
+
chat_num
)
{
*
R
=
strdup
(
Peers
[
index
]
->
print_name
);
return
index
;
}
else
{
return
-
1
;
}
}
int
complete_user_chat_list
(
int
index
,
const
char
*
text
,
int
len
,
char
**
R
)
{
index
++
;
while
(
index
<
user_num
+
chat_num
&&
(
!
Peers
[
index
]
->
print_name
||
strncmp
(
Peers
[
index
]
->
print_name
,
text
,
len
)))
{
...
...
@@ -192,6 +207,9 @@ char *command_generator (const char *text, int state) {
return
R
;
case
3
:
return
rl_filename_completion_function
(
text
,
state
);
case
4
:
index
=
complete_chat_list
(
index
,
text
,
len
,
&
R
);
return
R
;
default:
return
0
;
}
...
...
@@ -272,6 +290,17 @@ void interpreter (char *line UU) {
do_send_text
(
Peers
[
index
],
strndup
(
f
,
len
));
}
}
}
else
if
(
!
memcmp
(
line
,
"chat_info"
,
9
))
{
char
*
q
=
line
+
10
;
int
len
;
char
*
text
=
get_token
(
&
q
,
&
len
);
int
index
=
0
;
while
(
index
<
user_num
+
chat_num
&&
(
!
Peers
[
index
]
->
print_name
||
strncmp
(
Peers
[
index
]
->
print_name
,
text
,
len
)))
{
index
++
;
}
if
(
index
<
user_num
+
chat_num
&&
Peers
[
index
]
->
id
<
0
)
{
do_get_chat_info
(
Peers
[
index
]);
}
}
else
if
(
!
memcmp
(
line
,
"history"
,
7
))
{
char
*
q
=
line
+
7
;
int
len
;
...
...
@@ -472,17 +501,39 @@ void print_media (struct message_media *M) {
}
}
int
unknown_user_list_pos
;
int
unknown_user_list
[
1000
];
void
print_user_name
(
int
id
,
union
user_chat
*
U
)
{
push_color
(
COLOR_RED
);
if
(
!
U
)
{
printf
(
"user#%d"
,
id
);
}
else
if
(
!
U
->
user
.
first_name
)
{
int
i
;
for
(
i
=
0
;
i
<
unknown_user_list_pos
;
i
++
)
{
if
(
unknown_user_list
[
i
]
==
id
)
{
id
=
0
;
break
;
}
}
if
(
id
)
{
assert
(
unknown_user_list_pos
<
1000
);
unknown_user_list
[
unknown_user_list_pos
++
]
=
id
;
}
}
else
{
if
(
U
->
flags
&
20
)
{
push_color
(
COLOR_REDB
);
}
if
(
!
U
->
user
.
first_name
)
{
printf
(
"%s"
,
U
->
user
.
last_name
);
}
else
if
(
!
U
->
user
.
last_name
)
{
printf
(
"%s"
,
U
->
user
.
first_name
);
}
else
{
printf
(
"%s %s"
,
U
->
user
.
first_name
,
U
->
user
.
last_name
);
}
if
(
U
->
flags
&
20
)
{
pop_color
();
}
}
pop_color
();
}
...
...
interface.h
View file @
73cdb880
#ifndef __INTERFACE_H__
#define __INTERFACE_H__
#define COLOR_RED "\033[31;1m"
#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"
...
...
loop.c
View file @
73cdb880
...
...
@@ -27,6 +27,8 @@ extern char *auth_token;
void
set_default_username
(
const
char
*
s
);
int
default_dc_num
;
extern
int
unknown_user_list_pos
;
extern
int
unknown_user_list
[];
void
net_loop
(
int
flags
,
int
(
*
is_end
)(
void
))
{
while
(
!
is_end
())
{
...
...
@@ -58,6 +60,10 @@ void net_loop (int flags, int (*is_end)(void)) {
rl_callback_read_char
();
}
connections_poll_result
(
fds
+
cc
,
x
-
cc
);
if
(
unknown_user_list_pos
)
{
do_get_user_list_info_silent
(
unknown_user_list_pos
,
unknown_user_list
);
unknown_user_list_pos
=
0
;
}
}
}
...
...
queries.c
View file @
73cdb880
...
...
@@ -416,7 +416,17 @@ int get_contacts_on_answer (struct query *q UU) {
n
=
fetch_int
();
for
(
i
=
0
;
i
<
n
;
i
++
)
{
struct
user
*
U
=
fetch_alloc_user
();
rprintf
(
"User #%d: "
COLOR_RED
"%s %s"
COLOR_NORMAL
" ("
COLOR_GREEN
"%s"
COLOR_NORMAL
")
\n
"
,
U
->
id
,
U
->
first_name
,
U
->
last_name
,
U
->
print_name
);
print_start
();
push_color
(
COLOR_YELLOW
);
printf
(
"User #%d: "
,
U
->
id
);
print_user_name
(
U
->
id
,
(
union
user_chat
*
)
U
);
push_color
(
COLOR_GREEN
);
printf
(
" ("
);
printf
(
"%s"
,
U
->
print_name
);
printf
(
")
\n
"
);
pop_color
();
pop_color
();
print_end
();
}
return
0
;
}
...
...
@@ -782,3 +792,83 @@ void do_send_photo (int type, int to_id, char *file_name) {
}
send_part
(
f
);
}
int
chat_info_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_messages_chat_full
);
assert
(
fetch_int
()
==
(
int
)
CODE_chat_full
);
int
id
=
fetch_int
();
// id
assert
(
fetch_int
()
==
(
int
)
CODE_chat_participants
);
assert
(
id
==
fetch_int
());
// id
int
admin_id
=
fetch_int
();
assert
(
fetch_int
()
==
CODE_vector
);
int
n
=
fetch_int
();
assert
(
n
<=
100
);
int
i
;
static
int
a
[
300
];
for
(
i
=
0
;
i
<
n
;
i
++
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_chat_participant
);
a
[
3
*
i
+
0
]
=
fetch_int
();
a
[
3
*
i
+
1
]
=
fetch_int
();
a
[
3
*
i
+
2
]
=
fetch_int
();
}
fetch_int
();
// version
print_start
();
push_color
(
COLOR_YELLOW
);
printf
(
"Chat "
);
print_chat_name
(
-
id
,
user_chat_get
(
-
id
));
printf
(
" members:
\n
"
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"
\t\t
"
);
print_user_name
(
a
[
3
*
i
],
user_chat_get
(
a
[
3
*
i
]));
if
(
a
[
3
*
i
]
==
admin_id
)
{
printf
(
" admin"
);
}
printf
(
"
\n
"
);
}
pop_color
();
print_end
();
return
0
;
}
struct
query_methods
chat_info_methods
=
{
.
on_answer
=
chat_info_on_answer
};
void
do_get_chat_info
(
union
user_chat
*
chat
)
{
clear_packet
();
out_int
(
CODE_messages_get_full_chat
);
out_int
(
-
chat
->
id
);
send_query
(
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
chat_info_methods
,
0
);
}
int
user_list_info_silent_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
CODE_vector
);
int
n
=
fetch_int
();
int
i
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
fetch_alloc_user
();
}
return
0
;
}
struct
query_methods
user_list_info_silent_methods
=
{
.
on_answer
=
user_list_info_silent_on_answer
};
void
do_get_user_list_info_silent
(
int
num
,
int
*
list
)
{
clear_packet
();
out_int
(
CODE_users_get_users
);
out_int
(
CODE_vector
);
out_int
(
num
);
int
i
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
out_int
(
CODE_input_user_contact
);
out_int
(
list
[
i
]);
//out_long (0);
}
send_query
(
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
user_list_info_silent_methods
,
0
);
}
queries.h
View file @
73cdb880
...
...
@@ -52,5 +52,7 @@ void do_send_text (union user_chat *U, char *file);
void
do_get_history
(
union
user_chat
*
U
,
int
limit
);
void
do_get_dialog_list
(
void
);
void
do_send_photo
(
int
type
,
int
to_id
,
char
*
file_name
);
void
do_get_chat_info
(
union
user_chat
*
chat
);
void
do_get_user_list_info_silent
(
int
num
,
int
*
list
);
#endif
structures.h
View file @
73cdb880
...
...
@@ -37,6 +37,7 @@ struct chat {
int
user_num
;
int
date
;
int
version
;
int
admin_id
;
};
union
user_chat
{
...
...
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