Added export_card/import_card queries

This commit is contained in:
vvaltman 2014-08-29 19:46:04 +04:00
parent 201e2deaf2
commit 949aa7f92f
4 changed files with 110 additions and 0 deletions

View File

@ -2,3 +2,6 @@ decryptedMessageMediaVideoL12#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int durat
decryptedMessageMediaAudioL12#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
auth.bindTempAuthKey perm_auth_key_id:long nonce:long expires_at:int encrypted_message:string = Bool;
contacts.exportCard = Vector<int>;
contacts.importCard export_card:Vector<int> = User;

View File

@ -374,6 +374,8 @@ struct command commands[] = {
{"chat_set_photo", {ca_chat, ca_file_name_end}},
{"set_profile_photo", {ca_file_name_end}},
{"accept_secret_chat", {ca_secret_chat, ca_none}},
{"export_card", {ca_none}},
{"import_card", {ca_string, ca_none}},
{0, {ca_none}}
};
@ -559,6 +561,14 @@ void print_user_list_gw (void *extra, int success, int num, struct tgl_user *UL[
print_end ();
}
void print_user_gw (void *extra, int success, struct tgl_user *U) {
if (!success) { return; }
print_start ();
print_user_name (U->id, (void *)U);
printf ("\n");
print_end ();
}
void print_filename_gw (void *extra, int success, char *name) {
if (!success) { return; }
print_start ();
@ -972,6 +982,17 @@ void secret_chat_update_gw (struct tgl_secret_chat *U, unsigned flags) {
}
}
void print_card_gw (void *extra, int success, int size, int *card) {
assert (success);
print_start ();
printf ("Card: ");
int i;
for (i = 0; i < size; i++) {
printf ("%08x%c", card[i], i == size - 1 ? '\n' : ':');
}
print_end ();
}
struct tgl_update_callback upd_cb = {
.new_msg = print_message_gw,
.marked_read = mark_read_upd,
@ -1572,6 +1593,36 @@ void interpreter (char *line UU) {
}
tgl_do_delete_msg (num, 0, 0);
tgl_do_restore_msg (num, 0, 0);
} else if (IS_WORD ("export_card")) {
tgl_do_export_card (print_card_gw, 0);
} else if (IS_WORD ("import_card")) {
int l;
char *s = next_token (&l);
if (l > 0) {
int i;
static int p[10];
int pp = 0;
int cur = 0;
int ok = 1;
for (i = 0; i < l; i ++) {
if (s[i] >= '0' && s[i] <= '9') {
cur = cur * 16 + s[i] - '0';
} else if (s[i] >= 'a' && s[i] <= 'f') {
cur = cur * 16 + s[i] - 'a' + 10;
} else if (s[i] == ':') {
if (pp >= 9) {
ok = 0;
break;
}
p[pp ++] = cur;
cur = 0;
}
}
if (ok) {
p[pp ++] = cur;
tgl_do_import_card (pp, p, print_user_gw, 0);
}
}
} else if (IS_WORD ("quit")) {
exit (0);
} else if (IS_WORD ("accept_secret_chat")) {

View File

@ -3208,6 +3208,60 @@ void tgl_do_restore_msg (long long id, void (*callback)(void *callback_extra, in
}
/* }}} */
/* {{{ Export card */
static int export_card_on_answer (struct query *q UU) {
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
//logprintf ("Restored %d messages\n", n);
int *r = talloc (4 * n);
fetch_ints (r, n);
if (q->callback) {
((void (*)(void *, int, int, int *))q->callback) (q->callback_extra, 1, n, r);
}
free (r);
return 0;
}
static struct query_methods export_card_methods = {
.on_answer = export_card_on_answer,
.type = TYPE_TO_PARAM_1(vector, TYPE_TO_PARAM (bare_int))
};
void tgl_do_export_card (void (*callback)(void *callback_extra, int success, int size, int *card), void *callback_extra) {
clear_packet ();
out_int (CODE_contacts_export_card);
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &export_card_methods, 0, callback, callback_extra);
}
/* }}} */
/* {{{ Import card */
static int import_card_on_answer (struct query *q UU) {
struct tgl_user *U = tglf_fetch_alloc_user ();
if (q->callback) {
((void (*)(void *, int, struct tgl_user *))q->callback) (q->callback_extra, 1, U);
}
return 0;
}
static struct query_methods import_card_methods = {
.on_answer = import_card_on_answer,
.type = TYPE_TO_PARAM (user)
};
void tgl_do_import_card (int size, int *card, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra) {
clear_packet ();
out_int (CODE_contacts_import_card);
out_int (CODE_vector);
out_int (size);
out_ints (card, size);
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &import_card_methods, 0, callback, callback_extra);
}
/* }}} */
static void set_flag_4 (void *_D, int success) {
struct tgl_dc *D = _D;
assert (success);

2
tgl.h
View File

@ -274,6 +274,8 @@ void tgl_do_delete_msg (long long id, void (*callback)(void *callback_extra, int
void tgl_do_restore_msg (long long id, void (*callback)(void *callback_extra, int success), void *callback_extra);
void tgl_do_update_status (int online, void (*callback)(void *callback_extra, int success), void *callback_extra);
void tgl_do_help_get_config_dc (struct tgl_dc *D, void (*callback)(void *, int), void *callback_extra);
void tgl_do_export_card (void (*callback)(void *callback_extra, int success, int size, int *card), void *callback_extra);
void tgl_do_import_card (int size, int *card, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
void tgl_do_visualize_key (tgl_peer_id_t id, unsigned char buf[16]);