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
f4dcc509
Commit
f4dcc509
authored
Oct 30, 2013
by
vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added add_contact/rename_contact queries
parent
c4e3052d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
0 deletions
+122
-0
interface.c
interface.c
+53
-0
queries.c
queries.c
+68
-0
queries.h
queries.h
+1
-0
No files found.
interface.c
View file @
f4dcc509
...
...
@@ -228,6 +228,8 @@ char *commands[] = {
"view_video_thumb"
,
"load_video"
,
"view_video"
,
"add_contact"
,
"rename_contact"
,
"show_license"
,
0
};
...
...
@@ -252,6 +254,8 @@ int commands_flags[] = {
07
,
07
,
07
,
071
,
07
,
};
int
get_complete_mode
(
void
)
{
...
...
@@ -607,6 +611,55 @@ void interpreter (char *line UU) {
}
int
limit
=
next_token_int
();
do_get_history
(
id
,
limit
>
0
?
limit
:
40
);
}
else
if
(
IS_WORD
(
"add_contact"
))
{
int
phone_len
,
first_name_len
,
last_name_len
;
char
*
phone
,
*
first_name
,
*
last_name
;
phone
=
next_token
(
&
phone_len
);
if
(
!
phone
)
{
printf
(
"No phone number found
\n
"
);
RET
;
}
first_name
=
next_token
(
&
first_name_len
);
if
(
!
first_name_len
)
{
printf
(
"No first name found
\n
"
);
RET
;
}
last_name
=
next_token
(
&
last_name_len
);
if
(
!
last_name_len
)
{
printf
(
"No last name found
\n
"
);
RET
;
}
do_add_contact
(
phone
,
phone_len
,
first_name
,
first_name_len
,
last_name
,
last_name_len
,
0
);
}
else
if
(
IS_WORD
(
"rename_contact"
))
{
int
id
=
next_token_user
();
if
(
id
==
NOT_FOUND
)
{
printf
(
"Bad user
\n
"
);
RET
;
}
union
user_chat
*
U
=
user_chat_get
(
id
);
if
(
!
U
)
{
printf
(
"No such user
\n
"
);
RET
;
}
if
(
!
U
->
user
.
phone
||
!
strlen
(
U
->
user
.
phone
))
{
printf
(
"User has no phone. Can not rename
\n
"
);
RET
;
}
int
phone_len
,
first_name_len
,
last_name_len
;
char
*
phone
,
*
first_name
,
*
last_name
;
phone_len
=
strlen
(
U
->
user
.
phone
);
phone
=
U
->
user
.
phone
;
first_name
=
next_token
(
&
first_name_len
);
if
(
!
first_name_len
)
{
printf
(
"No first name found
\n
"
);
RET
;
}
last_name
=
next_token
(
&
last_name_len
);
if
(
!
last_name_len
)
{
printf
(
"No last name found
\n
"
);
RET
;
}
do_add_contact
(
phone
,
phone_len
,
first_name
,
first_name_len
,
last_name
,
last_name_len
,
1
);
}
else
if
(
IS_WORD
(
"help"
))
{
//print_start ();
push_color
(
COLOR_YELLOW
);
...
...
queries.c
View file @
f4dcc509
...
...
@@ -1365,3 +1365,71 @@ void do_import_auth (int num) {
send_query
(
DC_list
[
num
],
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
import_auth_methods
,
0
);
net_loop
(
0
,
isn_export_auth_str
);
}
int
add_contact_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_contacts_imported_contacts
);
assert
(
fetch_int
()
==
CODE_vector
);
int
n
=
fetch_int
();
if
(
n
>
0
)
{
logprintf
(
"Added successfully"
);
}
else
{
logprintf
(
"Not added"
);
}
int
i
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_imported_contact
);
fetch_int
();
// uid
fetch_long
();
// client_id
}
assert
(
fetch_int
()
==
CODE_vector
);
n
=
fetch_int
();
for
(
i
=
0
;
i
<
n
;
i
++
)
{
struct
user
*
U
=
fetch_alloc_user
();
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
);
if
(
U
->
phone
)
{
printf
(
" "
);
printf
(
"%s"
,
U
->
phone
);
}
printf
(
") "
);
pop_color
();
if
(
U
->
status
.
online
>
0
)
{
printf
(
"online
\n
"
);
}
else
{
if
(
U
->
status
.
online
<
0
)
{
printf
(
"offline. Was online "
);
print_date_full
(
U
->
status
.
when
);
}
else
{
printf
(
"offline permanent"
);
}
printf
(
"
\n
"
);
}
pop_color
();
print_end
();
}
return
0
;
}
struct
query_methods
add_contact_methods
=
{
.
on_answer
=
add_contact_on_answer
,
};
void
do_add_contact
(
const
char
*
phone
,
int
phone_len
,
const
char
*
first_name
,
int
first_name_len
,
const
char
*
last_name
,
int
last_name_len
,
int
force
)
{
clear_packet
();
out_int
(
CODE_contacts_import_contacts
);
out_int
(
CODE_vector
);
out_int
(
1
);
out_int
(
CODE_input_phone_contact
);
out_long
(
lrand48
()
*
(
1ll
<<
32
)
+
lrand48
());
out_cstring
(
phone
,
phone_len
);
out_cstring
(
first_name
,
first_name_len
);
out_cstring
(
last_name
,
last_name_len
);
out_int
(
force
?
CODE_bool_true
:
CODE_bool_false
);
send_query
(
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
add_contact_methods
,
0
);
}
queries.h
View file @
f4dcc509
...
...
@@ -90,5 +90,6 @@ int do_get_nearest_dc (void);
int
do_send_code_result_auth
(
const
char
*
code
,
const
char
*
first_name
,
const
char
*
last_name
);
void
do_import_auth
(
int
num
);
void
do_export_auth
(
int
num
);
void
do_add_contact
(
const
char
*
phone
,
int
phone_len
,
const
char
*
first_name
,
int
first_name_len
,
const
char
*
last_name
,
int
last_name_len
,
int
force
);
#endif
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