Commit db463be5 authored by Vincent Castellano's avatar Vincent Castellano

Missing changes to python-tg.c

parent b290af88
...@@ -47,1421 +47,1420 @@ extern int verbosity; ...@@ -47,1421 +47,1420 @@ extern int verbosity;
extern struct tgl_state *TLS; extern struct tgl_state *TLS;
static int have_file; static int have_file;
//
#define my_lua_checkstack(L,x) assert (lua_checkstack (L, x)) //void push_user (tgl_peer_t *P);
void push_user (tgl_peer_t *P); //void push_peer (tgl_peer_id_t id, tgl_peer_t *P);
void push_peer (tgl_peer_id_t id, tgl_peer_t *P); //
//void lua_add_string_field (const char *name, const char *value) {
void lua_add_string_field (const char *name, const char *value) { // assert (name && strlen (name));
assert (name && strlen (name)); // if (!value || !strlen (value)) { return; }
if (!value || !strlen (value)) { return; } // my_lua_checkstack (luaState, 3);
my_lua_checkstack (luaState, 3); // lua_pushstring (luaState, name);
lua_pushstring (luaState, name); // lua_pushstring (luaState, value);
lua_pushstring (luaState, value); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void lua_add_string_field_arr (int num, const char *value) {
void lua_add_string_field_arr (int num, const char *value) { // if (!value || !strlen (value)) { return; }
if (!value || !strlen (value)) { return; } // my_lua_checkstack (luaState, 3);
my_lua_checkstack (luaState, 3); // lua_pushnumber (luaState, num);
lua_pushnumber (luaState, num); // lua_pushstring (luaState, value);
lua_pushstring (luaState, value); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void lua_add_num_field (const char *name, double value) {
void lua_add_num_field (const char *name, double value) { // assert (name && strlen (name));
assert (name && strlen (name)); // my_lua_checkstack (luaState, 3);
my_lua_checkstack (luaState, 3); // lua_pushstring (luaState, name);
lua_pushstring (luaState, name); // lua_pushnumber (luaState, value);
lua_pushnumber (luaState, value); // lua_settable (luaState, -3);
lua_settable (luaState, -3); //}
} //
//void push_tgl_peer_type (int x) {
void push_tgl_peer_type (int x) { // switch (x) {
switch (x) { // case TGL_PEER_USER:
case TGL_PEER_USER: // lua_pushstring (luaState, "user");
lua_pushstring (luaState, "user"); // break;
break; // case TGL_PEER_CHAT:
case TGL_PEER_CHAT: // lua_pushstring (luaState, "chat");
lua_pushstring (luaState, "chat"); // break;
break; // case TGL_PEER_ENCR_CHAT:
case TGL_PEER_ENCR_CHAT: // lua_pushstring (luaState, "encr_chat");
lua_pushstring (luaState, "encr_chat"); // break;
break; // default:
default: // assert (0);
assert (0); // }
} //}
//
//void push_user (tgl_peer_t *P) {
// my_lua_checkstack (luaState, 4);
// lua_add_string_field ("first_name", P->user.first_name);
// lua_add_string_field ("last_name", P->user.last_name);
// lua_add_string_field ("real_first_name", P->user.real_first_name);
// lua_add_string_field ("real_last_name", P->user.real_last_name);
// lua_add_string_field ("phone", P->user.phone);
// if (P->user.access_hash) {
// lua_add_num_field ("access_hash", 1);
// }
//}
//
//void push_chat (tgl_peer_t *P) {
// my_lua_checkstack (luaState, 4);
// assert (P->chat.title);
// lua_add_string_field ("title", P->chat.title);
// lua_add_num_field ("members_num", P->chat.users_num);
// if (P->chat.user_list) {
// lua_pushstring (luaState, "members");
// lua_newtable (luaState);
// int i;
// for (i = 0; i < P->chat.users_num; i++) {
// lua_pushnumber (luaState, i);
// tgl_peer_id_t id = TGL_MK_USER (P->chat.user_list[i].user_id);
// push_peer (id, tgl_peer_get (TLS, id));
// lua_settable (luaState, -3);
// }
// lua_settable (luaState, -3);
// }
//}
//
//void push_encr_chat (tgl_peer_t *P) {
// my_lua_checkstack (luaState, 4);
// lua_pushstring (luaState, "user");
// push_peer (TGL_MK_USER (P->encr_chat.user_id), tgl_peer_get (TLS, TGL_MK_USER (P->encr_chat.user_id)));
// lua_settable (luaState, -3);
//}
//
//void push_update_types (unsigned flags) {
// my_lua_checkstack (luaState, 4);
// lua_newtable (luaState);
// int cc = 0;
//
//
// if (flags & TGL_UPDATE_CREATED) {
// lua_add_string_field_arr (cc++, "created");
// }
// if (flags & TGL_UPDATE_DELETED) {
// lua_add_string_field_arr (cc++, "deleted");
// }
// if (flags & TGL_UPDATE_PHONE) {
// lua_add_string_field_arr (cc++, "phone");
// }
// if (flags & TGL_UPDATE_CONTACT) {
// lua_add_string_field_arr (cc++, "contact");
// }
// if (flags & TGL_UPDATE_PHOTO) {
// lua_add_string_field_arr (cc++, "photo");
// }
// if (flags & TGL_UPDATE_BLOCKED) {
// lua_add_string_field_arr (cc++, "blocked");
// }
// if (flags & TGL_UPDATE_REAL_NAME) {
// lua_add_string_field_arr (cc++, "real_name");
// }
// if (flags & TGL_UPDATE_NAME) {
// lua_add_string_field_arr (cc++, "name");
// }
// if (flags & TGL_UPDATE_REQUESTED) {
// lua_add_string_field_arr (cc++, "requested");
// }
// if (flags & TGL_UPDATE_WORKING) {
// lua_add_string_field_arr (cc++, "working");
// }
// if (flags & TGL_UPDATE_FLAGS) {
// lua_add_string_field_arr (cc++, "flags");
// }
// if (flags & TGL_UPDATE_TITLE) {
// lua_add_string_field_arr (cc++, "title");
// }
// if (flags & TGL_UPDATE_ADMIN) {
// lua_add_string_field_arr (cc++, "admin");
// }
// if (flags & TGL_UPDATE_MEMBERS) {
// lua_add_string_field_arr (cc++, "members");
// }
// if (flags & TGL_UPDATE_ACCESS_HASH) {
// lua_add_string_field_arr (cc++, "access_hash");
// }
// if (flags & TGL_UPDATE_USERNAME) {
// lua_add_string_field_arr (cc++, "username");
// }
//
//}
//
//void push_peer (tgl_peer_id_t id, tgl_peer_t *P) {
// lua_newtable (luaState);
//
// lua_add_num_field ("id", tgl_get_peer_id (id));
// lua_pushstring (luaState, "type");
// push_tgl_peer_type (tgl_get_peer_type (id));
// lua_settable (luaState, -3);
//
//
// if (!P || !(P->flags & FLAG_CREATED)) {
// lua_pushstring (luaState, "print_name");
// static char s[100];
// switch (tgl_get_peer_type (id)) {
// case TGL_PEER_USER:
// sprintf (s, "user#%d", tgl_get_peer_id (id));
// break;
// case TGL_PEER_CHAT:
// sprintf (s, "chat#%d", tgl_get_peer_id (id));
// break;
// case TGL_PEER_ENCR_CHAT:
// sprintf (s, "encr_chat#%d", tgl_get_peer_id (id));
// break;
// default:
// assert (0);
// }
// lua_pushstring (luaState, s);
// lua_settable (luaState, -3); // flags
//
// return;
// }
//
// lua_add_string_field ("print_name", P->print_name);
// lua_add_num_field ("flags", P->flags);
//
// switch (tgl_get_peer_type (id)) {
// case TGL_PEER_USER:
// push_user (P);
// break;
// case TGL_PEER_CHAT:
// push_chat (P);
// break;
// case TGL_PEER_ENCR_CHAT:
// push_encr_chat (P);
// break;
// default:
// assert (0);
// }
//}
//
//void push_media (struct tgl_message_media *M) {
// my_lua_checkstack (luaState, 4);
//
// switch (M->type) {
// case tgl_message_media_photo:
// case tgl_message_media_photo_encr:
// lua_newtable (luaState);
// lua_add_string_field ("type", "photo");
// break;
// /*case tgl_message_media_video:
// case tgl_message_media_video_encr:
// lua_newtable (luaState);
// lua_add_string_field ("type", "video");
// break;
// case tgl_message_media_audio:
// case tgl_message_media_audio_encr:
// lua_newtable (luaState);
// lua_add_string_field ("type", "audio");
// break;*/
// case tgl_message_media_document:
// case tgl_message_media_document_encr:
// lua_newtable (luaState);
// lua_add_string_field ("type", "document");
// break;
// case tgl_message_media_unsupported:
// lua_newtable (luaState);
// lua_add_string_field ("type", "unsupported");
// break;
// case tgl_message_media_geo:
// lua_newtable (luaState);
// lua_add_string_field ("type", "geo");
// lua_add_num_field ("longitude", M->geo.longitude);
// lua_add_num_field ("latitude", M->geo.latitude);
// break;
// case tgl_message_media_contact:
// lua_newtable (luaState);
// lua_add_string_field ("type", "contact");
// lua_add_string_field ("phone", M->phone);
// lua_add_string_field ("first_name", M->first_name);
// lua_add_string_field ("last_name", M->last_name);
// lua_add_num_field ("user_id", M->user_id);
// break;
// default:
// lua_pushstring (luaState, "???");
// }
//}
//
//void push_message (struct tgl_message *M) {
// assert (M);
// my_lua_checkstack (luaState, 10);
// lua_newtable (luaState);
//
// static char s[30];
// snprintf (s, 30, "%lld", M->id);
// lua_add_string_field ("id", s);
// if (!(M->flags & FLAG_CREATED)) { return; }
// lua_add_num_field ("flags", M->flags);
//
// if (tgl_get_peer_type (M->fwd_from_id)) {
// lua_pushstring (luaState, "fwd_from");
// push_peer (M->fwd_from_id, tgl_peer_get (TLS, M->fwd_from_id));
// lua_settable (luaState, -3); // fwd_from
//
// lua_add_num_field ("fwd_date", M->fwd_date);
// }
//
// lua_pushstring (luaState, "from");
// push_peer (M->from_id, tgl_peer_get (TLS, M->from_id));
// lua_settable (luaState, -3);
//
// lua_pushstring (luaState, "to");
// push_peer (M->to_id, tgl_peer_get (TLS, M->to_id));
// lua_settable (luaState, -3);
//
// lua_pushstring (luaState, "out");
// lua_pushboolean (luaState, M->out);
// lua_settable (luaState, -3);
//
// lua_pushstring (luaState, "unread");
// lua_pushboolean (luaState, M->unread);
// lua_settable (luaState, -3);
//
// lua_pushstring (luaState, "date");
// lua_pushnumber (luaState, M->date);
// lua_settable (luaState, -3);
//
// lua_pushstring (luaState, "service");
// lua_pushboolean (luaState, M->service);
// lua_settable (luaState, -3);
//
// if (!M->service) {
// if (M->message_len && M->message) {
// lua_pushstring (luaState, "text");
// lua_pushlstring (luaState, M->message, M->message_len);
// lua_settable (luaState, -3);
// }
// if (M->media.type && M->media.type != tgl_message_media_none) {
// lua_pushstring (luaState, "media");
// push_media (&M->media);
// lua_settable (luaState, -3);
// }
// }
//}
//
//void lua_binlog_end (void) {
// if (!have_file) { return; }
// lua_settop (luaState, 0);
// //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_binlog_replay_end");
// assert (lua_gettop (luaState) == 1);
//
// int r = lua_pcall (luaState, 0, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
//}
//
//void lua_diff_end (void) {
// if (!have_file) { return; }
// lua_settop (luaState, 0);
// //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_get_difference_end");
// assert (lua_gettop (luaState) == 1);
//
// int r = lua_pcall (luaState, 0, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
//}
//
void py_our_id (int id) {
// if (!have_file) { return; }
// lua_settop (luaState, 0);
// //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_our_id");
// lua_pushnumber (luaState, id);
// assert (lua_gettop (luaState) == 2);
//
// int r = lua_pcall (luaState, 1, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
} }
void push_user (tgl_peer_t *P) { void py_new_msg (struct tgl_message *M) {
my_lua_checkstack (luaState, 4); // if (!have_file) { return; }
lua_add_string_field ("first_name", P->user.first_name); // lua_settop (luaState, 0);
lua_add_string_field ("last_name", P->user.last_name); // //lua_checkstack (luaState, 20);
lua_add_string_field ("real_first_name", P->user.real_first_name); // my_lua_checkstack (luaState, 20);
lua_add_string_field ("real_last_name", P->user.real_last_name); // lua_getglobal (luaState, "on_msg_receive");
lua_add_string_field ("phone", P->user.phone); // push_message (M);
if (P->user.access_hash) { // assert (lua_gettop (luaState) == 2);
lua_add_num_field ("access_hash", 1); //
} // int r = lua_pcall (luaState, 1, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
} }
void push_chat (tgl_peer_t *P) { void py_secret_chat_update (struct tgl_secret_chat *C, unsigned flags) {
my_lua_checkstack (luaState, 4); // if (!have_file) { return; }
assert (P->chat.title); // lua_settop (luaState, 0);
lua_add_string_field ("title", P->chat.title); // //lua_checkstack (luaState, 20);
lua_add_num_field ("members_num", P->chat.users_num); // my_lua_checkstack (luaState, 20);
if (P->chat.user_list) { // lua_getglobal (luaState, "on_secret_chat_update");
lua_pushstring (luaState, "members"); // push_peer (C->id, (void *)C);
lua_newtable (luaState); // push_update_types (flags);
int i; // assert (lua_gettop (luaState) == 3);
for (i = 0; i < P->chat.users_num; i++) { //
lua_pushnumber (luaState, i); // int r = lua_pcall (luaState, 2, 0, 0);
tgl_peer_id_t id = TGL_MK_USER (P->chat.user_list[i].user_id); // if (r) {
push_peer (id, tgl_peer_get (TLS, id)); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
lua_settable (luaState, -3); // }
}
lua_settable (luaState, -3);
}
} }
void push_encr_chat (tgl_peer_t *P) { void py_user_update (struct tgl_user *U, unsigned flags) {
my_lua_checkstack (luaState, 4); // if (!have_file) { return; }
lua_pushstring (luaState, "user"); // lua_settop (luaState, 0);
push_peer (TGL_MK_USER (P->encr_chat.user_id), tgl_peer_get (TLS, TGL_MK_USER (P->encr_chat.user_id))); // //lua_checkstack (luaState, 20);
lua_settable (luaState, -3); // my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_user_update");
// push_peer (U->id, (void *)U);
// push_update_types (flags);
// assert (lua_gettop (luaState) == 3);
//
// int r = lua_pcall (luaState, 2, 0, 0);
// if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
} }
void push_update_types (unsigned flags) { void py_chat_update (struct tgl_chat *C, unsigned flags) {
my_lua_checkstack (luaState, 4); // if (!have_file) { return; }
lua_newtable (luaState); // lua_settop (luaState, 0);
int cc = 0; // //lua_checkstack (luaState, 20);
// my_lua_checkstack (luaState, 20);
// lua_getglobal (luaState, "on_chat_update");
if (flags & TGL_UPDATE_CREATED) { // push_peer (C->id, (void *)C);
lua_add_string_field_arr (cc++, "created"); // push_update_types (flags);
} // assert (lua_gettop (luaState) == 3);
if (flags & TGL_UPDATE_DELETED) { //
lua_add_string_field_arr (cc++, "deleted"); // int r = lua_pcall (luaState, 2, 0, 0);
} // if (r) {
if (flags & TGL_UPDATE_PHONE) { // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
lua_add_string_field_arr (cc++, "phone"); // }
}
if (flags & TGL_UPDATE_CONTACT) {
lua_add_string_field_arr (cc++, "contact");
}
if (flags & TGL_UPDATE_PHOTO) {
lua_add_string_field_arr (cc++, "photo");
}
if (flags & TGL_UPDATE_BLOCKED) {
lua_add_string_field_arr (cc++, "blocked");
}
if (flags & TGL_UPDATE_REAL_NAME) {
lua_add_string_field_arr (cc++, "real_name");
}
if (flags & TGL_UPDATE_NAME) {
lua_add_string_field_arr (cc++, "name");
}
if (flags & TGL_UPDATE_REQUESTED) {
lua_add_string_field_arr (cc++, "requested");
}
if (flags & TGL_UPDATE_WORKING) {
lua_add_string_field_arr (cc++, "working");
}
if (flags & TGL_UPDATE_FLAGS) {
lua_add_string_field_arr (cc++, "flags");
}
if (flags & TGL_UPDATE_TITLE) {
lua_add_string_field_arr (cc++, "title");
}
if (flags & TGL_UPDATE_ADMIN) {
lua_add_string_field_arr (cc++, "admin");
}
if (flags & TGL_UPDATE_MEMBERS) {
lua_add_string_field_arr (cc++, "members");
}
if (flags & TGL_UPDATE_ACCESS_HASH) {
lua_add_string_field_arr (cc++, "access_hash");
}
if (flags & TGL_UPDATE_USERNAME) {
lua_add_string_field_arr (cc++, "username");
}
} }
//
void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { ////extern tgl_peer_t *Peers[];
lua_newtable (luaState); ////extern int peer_num;
//
lua_add_num_field ("id", tgl_get_peer_id (id)); //#define MAX_LUA_COMMANDS 1000
lua_pushstring (luaState, "type"); //void *lua_ptr[MAX_LUA_COMMANDS];
push_tgl_peer_type (tgl_get_peer_type (id)); //static int pos;
lua_settable (luaState, -3); //
//static inline tgl_peer_t *get_peer (const char *s) {
// return tgl_peer_get_by_name (TLS, s);
if (!P || !(P->flags & FLAG_CREATED)) { //}
lua_pushstring (luaState, "print_name"); //
static char s[100]; //enum lua_query_type {
switch (tgl_get_peer_type (id)) { // lq_contact_list,
case TGL_PEER_USER: // lq_dialog_list,
sprintf (s, "user#%d", tgl_get_peer_id (id)); // lq_msg,
break; // lq_send_typing,
case TGL_PEER_CHAT: // lq_send_typing_abort,
sprintf (s, "chat#%d", tgl_get_peer_id (id)); // lq_rename_chat,
break; // lq_send_photo,
case TGL_PEER_ENCR_CHAT: // lq_chat_set_photo,
sprintf (s, "encr_chat#%d", tgl_get_peer_id (id)); // lq_set_profile_photo,
break; // lq_set_profile_name,
default: // lq_send_video,
assert (0); // lq_send_text,
} // lq_fwd,
lua_pushstring (luaState, s); // lq_fwd_media,
lua_settable (luaState, -3); // flags // lq_load_photo,
// lq_load_video_thumb,
return; // lq_load_video,
} // lq_chat_info,
// lq_user_info,
lua_add_string_field ("print_name", P->print_name); // lq_history,
lua_add_num_field ("flags", P->flags); // lq_chat_add_user,
// lq_chat_del_user,
switch (tgl_get_peer_type (id)) { // lq_add_contact,
case TGL_PEER_USER: // lq_del_contact,
push_user (P); // lq_rename_contact,
break; // lq_search,
case TGL_PEER_CHAT: // lq_global_search,
push_chat (P); // lq_mark_read,
break; // lq_create_secret_chat,
case TGL_PEER_ENCR_CHAT: // lq_create_group_chat,
push_encr_chat (P); // lq_send_audio,
break; // lq_send_document,
default: // lq_send_file,
assert (0); // lq_load_audio,
} // lq_load_document,
} // lq_load_document_thumb,
// lq_delete_msg,
void push_media (struct tgl_message_media *M) { // lq_restore_msg,
my_lua_checkstack (luaState, 4); // lq_accept_secret_chat,
// lq_send_contact,
switch (M->type) { // lq_status_online,
case tgl_message_media_photo: // lq_status_offline,
case tgl_message_media_photo_encr: // lq_send_location,
lua_newtable (luaState); // lq_extf
lua_add_string_field ("type", "photo"); //};
break; //
/*case tgl_message_media_video: //struct lua_query_extra {
case tgl_message_media_video_encr: // int func;
lua_newtable (luaState); // int param;
lua_add_string_field ("type", "video"); //};
break; //
case tgl_message_media_audio: //void lua_empty_cb (struct tgl_state *TLSR, void *cb_extra, int success) {
case tgl_message_media_audio_encr: // assert (TLSR == TLS);
lua_newtable (luaState); // struct lua_query_extra *cb = cb_extra;
lua_add_string_field ("type", "audio"); // lua_settop (luaState, 0);
break;*/ // //lua_checkstack (luaState, 20);
case tgl_message_media_document: // my_lua_checkstack (luaState, 20);
case tgl_message_media_document_encr: //
lua_newtable (luaState); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
lua_add_string_field ("type", "document"); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
break; //
case tgl_message_media_unsupported: // lua_pushnumber (luaState, success);
lua_newtable (luaState); //
lua_add_string_field ("type", "unsupported"); // assert (lua_gettop (luaState) == 3);
break; //
case tgl_message_media_geo: // int r = lua_pcall (luaState, 2, 0, 0);
lua_newtable (luaState); //
lua_add_string_field ("type", "geo"); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_add_num_field ("longitude", M->geo.longitude); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_add_num_field ("latitude", M->geo.latitude); //
break; // if (r) {
case tgl_message_media_contact: // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
lua_newtable (luaState); // }
lua_add_string_field ("type", "contact"); //
lua_add_string_field ("phone", M->phone); // free (cb);
lua_add_string_field ("first_name", M->first_name); //}
lua_add_string_field ("last_name", M->last_name); //
lua_add_num_field ("user_id", M->user_id); //void lua_contact_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_user **UL) {
break; // assert (TLSR == TLS);
default: // struct lua_query_extra *cb = cb_extra;
lua_pushstring (luaState, "???"); // lua_settop (luaState, 0);
} // //lua_checkstack (luaState, 20);
} // my_lua_checkstack (luaState, 20);
//
void push_message (struct tgl_message *M) { // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
assert (M); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
my_lua_checkstack (luaState, 10); //
lua_newtable (luaState); // lua_pushnumber (luaState, success);
//
static char s[30]; // if (success) {
snprintf (s, 30, "%lld", M->id); // lua_newtable (luaState);
lua_add_string_field ("id", s); // int i;
if (!(M->flags & FLAG_CREATED)) { return; } // for (i = 0; i < num; i++) {
lua_add_num_field ("flags", M->flags); // lua_pushnumber (luaState, i);
// push_peer (UL[i]->id, (void *)UL[i]);
if (tgl_get_peer_type (M->fwd_from_id)) { // lua_settable (luaState, -3);
lua_pushstring (luaState, "fwd_from"); // }
push_peer (M->fwd_from_id, tgl_peer_get (TLS, M->fwd_from_id)); // } else {
lua_settable (luaState, -3); // fwd_from // lua_pushboolean (luaState, 0);
// }
lua_add_num_field ("fwd_date", M->fwd_date); //
} // assert (lua_gettop (luaState) == 4);
//
lua_pushstring (luaState, "from"); // int r = lua_pcall (luaState, 3, 0, 0);
push_peer (M->from_id, tgl_peer_get (TLS, M->from_id)); //
lua_settable (luaState, -3); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_pushstring (luaState, "to"); //
push_peer (M->to_id, tgl_peer_get (TLS, M->to_id)); // if (r) {
lua_settable (luaState, -3); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
// }
lua_pushstring (luaState, "out"); //
lua_pushboolean (luaState, M->out); // free (cb);
lua_settable (luaState, -3); //}
//
lua_pushstring (luaState, "unread"); //void lua_dialog_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, tgl_peer_id_t peers[], int msgs[], int unread[]) {
lua_pushboolean (luaState, M->unread); // assert (TLSR == TLS);
lua_settable (luaState, -3); // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
lua_pushstring (luaState, "date"); // //lua_checkstack (luaState, 20);
lua_pushnumber (luaState, M->date); // my_lua_checkstack (luaState, 20);
lua_settable (luaState, -3); //
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
lua_pushstring (luaState, "service"); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
lua_pushboolean (luaState, M->service); //
lua_settable (luaState, -3); // lua_pushnumber (luaState, success);
// if (success) {
if (!M->service) { // lua_newtable (luaState);
if (M->message_len && M->message) { // int i;
lua_pushstring (luaState, "text"); // for (i = 0; i < num; i++) {
lua_pushlstring (luaState, M->message, M->message_len); // lua_pushnumber (luaState, i);
lua_settable (luaState, -3); //
} // lua_newtable (luaState);
if (M->media.type && M->media.type != tgl_message_media_none) { //
lua_pushstring (luaState, "media"); // lua_pushstring (luaState, "peer");
push_media (&M->media); // push_peer (peers[i], tgl_peer_get (TLS, peers[i]));
lua_settable (luaState, -3); // lua_settable (luaState, -3);
} //
} // struct tgl_message *M = tgl_message_get (TLS, msgs[i]);
} // if (M && (M->flags & FLAG_CREATED)) {
// lua_pushstring (luaState, "message");
void lua_binlog_end (void) { // push_message (M);
if (!have_file) { return; } // lua_settable (luaState, -3);
lua_settop (luaState, 0); // }
//lua_checkstack (luaState, 20); //
my_lua_checkstack (luaState, 20); // lua_pushstring (luaState, "unread");
lua_getglobal (luaState, "on_binlog_replay_end"); // lua_pushnumber (luaState, unread[i]);
assert (lua_gettop (luaState) == 1); // lua_settable (luaState, -3);
//
int r = lua_pcall (luaState, 0, 0, 0); // lua_settable (luaState, -3);
if (r) { // }
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // } else {
} // lua_pushboolean (luaState, 0);
} // }
// assert (lua_gettop (luaState) == 4);
void lua_diff_end (void) { //
if (!have_file) { return; } //
lua_settop (luaState, 0); // int r = lua_pcall (luaState, 3, 0, 0);
//lua_checkstack (luaState, 20); //
my_lua_checkstack (luaState, 20); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lua_getglobal (luaState, "on_get_difference_end"); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
assert (lua_gettop (luaState) == 1); //
// if (r) {
int r = lua_pcall (luaState, 0, 0, 0); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
if (r) { // }
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); //
} // free (cb);
} //}
//
void lua_our_id (int id) { //void lua_msg_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_message *M) {
if (!have_file) { return; } // assert (TLSR == TLS);
lua_settop (luaState, 0); // struct lua_query_extra *cb = cb_extra;
//lua_checkstack (luaState, 20); // lua_settop (luaState, 0);
my_lua_checkstack (luaState, 20); // //lua_checkstack (luaState, 20);
lua_getglobal (luaState, "on_our_id"); // my_lua_checkstack (luaState, 20);
lua_pushnumber (luaState, id); //
assert (lua_gettop (luaState) == 2); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
int r = lua_pcall (luaState, 1, 0, 0); //
if (r) { // lua_pushnumber (luaState, success);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); //
} // if (success) {
} // push_message (M);
// } else {
void lua_new_msg (struct tgl_message *M) { // lua_pushboolean (luaState, 0);
if (!have_file) { return; } // }
lua_settop (luaState, 0); //
//lua_checkstack (luaState, 20); // assert (lua_gettop (luaState) == 4);
my_lua_checkstack (luaState, 20); //
lua_getglobal (luaState, "on_msg_receive"); // int r = lua_pcall (luaState, 3, 0, 0);
push_message (M); //
assert (lua_gettop (luaState) == 2); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
int r = lua_pcall (luaState, 1, 0, 0); //
if (r) { // if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
} // }
} //
// free (cb);
void lua_secret_chat_update (struct tgl_secret_chat *C, unsigned flags) { //}
if (!have_file) { return; } //
lua_settop (luaState, 0); //void lua_msg_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_message *M[]) {
//lua_checkstack (luaState, 20); // assert (TLSR == TLS);
my_lua_checkstack (luaState, 20); // struct lua_query_extra *cb = cb_extra;
lua_getglobal (luaState, "on_secret_chat_update"); // lua_settop (luaState, 0);
push_peer (C->id, (void *)C); // //lua_checkstack (luaState, 20);
push_update_types (flags); // my_lua_checkstack (luaState, 20);
assert (lua_gettop (luaState) == 3); //
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
int r = lua_pcall (luaState, 2, 0, 0); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // lua_pushnumber (luaState, success);
} //
} // if (success) {
// lua_newtable (luaState);
void lua_user_update (struct tgl_user *U, unsigned flags) { // int i;
if (!have_file) { return; } // for (i = 0; i < num; i++) {
lua_settop (luaState, 0); // lua_pushnumber (luaState, i);
//lua_checkstack (luaState, 20); // push_message (M[i]);
my_lua_checkstack (luaState, 20); // lua_settable (luaState, -3);
lua_getglobal (luaState, "on_user_update"); // }
push_peer (U->id, (void *)U); // } else {
push_update_types (flags); // lua_pushboolean (luaState, 0);
assert (lua_gettop (luaState) == 3); // }
//
int r = lua_pcall (luaState, 2, 0, 0); // assert (lua_gettop (luaState) == 4);
if (r) { //
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // int r = lua_pcall (luaState, 3, 0, 0);
} //
} // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
void lua_chat_update (struct tgl_chat *C, unsigned flags) { //
if (!have_file) { return; } // if (r) {
lua_settop (luaState, 0); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
//lua_checkstack (luaState, 20); // }
my_lua_checkstack (luaState, 20); //
lua_getglobal (luaState, "on_chat_update"); // free (cb);
push_peer (C->id, (void *)C); //}
push_update_types (flags); //
assert (lua_gettop (luaState) == 3); //void lua_file_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *file_name) {
// assert (TLSR == TLS);
int r = lua_pcall (luaState, 2, 0, 0); // struct lua_query_extra *cb = cb_extra;
if (r) { // lua_settop (luaState, 0);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // //lua_checkstack (luaState, 20);
} // my_lua_checkstack (luaState, 20);
} //
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
//extern tgl_peer_t *Peers[]; // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
//extern int peer_num; //
// lua_pushnumber (luaState, success);
#define MAX_LUA_COMMANDS 1000 //
void *lua_ptr[MAX_LUA_COMMANDS]; // if (success) {
static int pos; // lua_pushstring (luaState, file_name);
// } else {
static inline tgl_peer_t *get_peer (const char *s) { // lua_pushboolean (luaState, 0);
return tgl_peer_get_by_name (TLS, s); // }
} //
// assert (lua_gettop (luaState) == 4);
enum lua_query_type { //
lq_contact_list, // int r = lua_pcall (luaState, 3, 0, 0);
lq_dialog_list, //
lq_msg, // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lq_send_typing, // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lq_send_typing_abort, //
lq_rename_chat, // if (r) {
lq_send_photo, // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
lq_chat_set_photo, // }
lq_set_profile_photo, //
lq_set_profile_name, // free (cb);
lq_send_video, //}
lq_send_text, //
lq_fwd, //void lua_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_chat *C) {
lq_fwd_media, // assert (TLSR == TLS);
lq_load_photo, // struct lua_query_extra *cb = cb_extra;
lq_load_video_thumb, // lua_settop (luaState, 0);
lq_load_video, // //lua_checkstack (luaState, 20);
lq_chat_info, // my_lua_checkstack (luaState, 20);
lq_user_info, //
lq_history, // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
lq_chat_add_user, // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
lq_chat_del_user, //
lq_add_contact, // lua_pushnumber (luaState, success);
lq_del_contact, //
lq_rename_contact, // if (success) {
lq_search, // push_peer (C->id, (void *)C);
lq_global_search, // } else {
lq_mark_read, // lua_pushboolean (luaState, 0);
lq_create_secret_chat, // }
lq_create_group_chat, //
lq_send_audio, // assert (lua_gettop (luaState) == 4);
lq_send_document, //
lq_send_file, // int r = lua_pcall (luaState, 3, 0, 0);
lq_load_audio, //
lq_load_document, // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
lq_load_document_thumb, // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lq_delete_msg, //
lq_restore_msg, // if (r) {
lq_accept_secret_chat, // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
lq_send_contact, // }
lq_status_online, //
lq_status_offline, // free (cb);
lq_send_location, //}
lq_extf //
}; //void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_secret_chat *C) {
// assert (TLSR == TLS);
struct lua_query_extra { // struct lua_query_extra *cb = cb_extra;
int func; // lua_settop (luaState, 0);
int param; // //lua_checkstack (luaState, 20);
}; // my_lua_checkstack (luaState, 20);
//
void lua_empty_cb (struct tgl_state *TLSR, void *cb_extra, int success) { // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
assert (TLSR == TLS); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
struct lua_query_extra *cb = cb_extra; //
lua_settop (luaState, 0); // lua_pushnumber (luaState, success);
//lua_checkstack (luaState, 20); //
my_lua_checkstack (luaState, 20); // if (success) {
// push_peer (C->id, (void *)C);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // } else {
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // lua_pushboolean (luaState, 0);
// }
lua_pushnumber (luaState, success); //
// assert (lua_gettop (luaState) == 4);
assert (lua_gettop (luaState) == 3); //
// int r = lua_pcall (luaState, 3, 0, 0);
int r = lua_pcall (luaState, 2, 0, 0); //
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); //
// if (r) {
if (r) { // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // }
} //
// free (cb);
free (cb); //}
} //
//void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) {
void lua_contact_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_user **UL) { // assert (TLSR == TLS);
assert (TLSR == TLS); // struct lua_query_extra *cb = cb_extra;
struct lua_query_extra *cb = cb_extra; // lua_settop (luaState, 0);
lua_settop (luaState, 0); // //lua_checkstack (luaState, 20);
//lua_checkstack (luaState, 20); // my_lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20); //
// lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); //
// lua_pushnumber (luaState, success);
lua_pushnumber (luaState, success); //
// if (success) {
if (success) { // push_peer (C->id, (void *)C);
lua_newtable (luaState); // } else {
int i; // lua_pushboolean (luaState, 0);
for (i = 0; i < num; i++) { // }
lua_pushnumber (luaState, i); //
push_peer (UL[i]->id, (void *)UL[i]); // assert (lua_gettop (luaState) == 4);
lua_settable (luaState, -3); //
} // int r = lua_pcall (luaState, 3, 0, 0);
} else { //
lua_pushboolean (luaState, 0); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
} // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
//
assert (lua_gettop (luaState) == 4); // if (r) {
// logprintf ("lua: %s\n", lua_tostring (luaState, -1));
int r = lua_pcall (luaState, 3, 0, 0); // }
//
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // free (cb);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); //}
//
if (r) { //void lua_str_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *data) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // assert (TLSR == TLS);
} // struct lua_query_extra *cb = cb_extra;
// lua_settop (luaState, 0);
free (cb); // //lua_checkstack (luaState, 20);
} // my_lua_checkstack (luaState, 20);
//
void lua_dialog_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, tgl_peer_id_t peers[], int msgs[], int unread[]) { // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
assert (TLSR == TLS); // lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
struct lua_query_extra *cb = cb_extra; //
lua_settop (luaState, 0); // lua_pushnumber (luaState, success);
//lua_checkstack (luaState, 20); //
my_lua_checkstack (luaState, 20); // if (success) {
// lua_pushstring (luaState, data);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // } else {
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // lua_pushboolean (luaState, 0);
// }
lua_pushnumber (luaState, success); //
if (success) { // assert (lua_gettop (luaState) == 4);
lua_newtable (luaState); //
int i; // int r = lua_pcall (luaState, 3, 0, 0);
for (i = 0; i < num; i++) { //
lua_pushnumber (luaState, i); // luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
// luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
lua_newtable (luaState); //
// if (r) {
lua_pushstring (luaState, "peer"); // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
push_peer (peers[i], tgl_peer_get (TLS, peers[i])); // }
lua_settable (luaState, -3); //
// free (cb);
struct tgl_message *M = tgl_message_get (TLS, msgs[i]); //}
if (M && (M->flags & FLAG_CREATED)) { //
lua_pushstring (luaState, "message"); //void lua_do_all (void) {
push_message (M); // int p = 0;
lua_settable (luaState, -3); // while (p < pos) {
} // int l = (long)lua_ptr[p ++];
// assert (p + l + 1 <= pos);
lua_pushstring (luaState, "unread"); // enum lua_query_type f = (long)lua_ptr[p ++];
lua_pushnumber (luaState, unread[i]); // struct tgl_message *M;
lua_settable (luaState, -3); // char *s, *s1, *s2, *s3;
// switch (f) {
lua_settable (luaState, -3); // case lq_contact_list:
} // tgl_do_update_contact_list (TLS, lua_contact_list_cb, lua_ptr[p ++]);
} else { // break;
lua_pushboolean (luaState, 0); // case lq_dialog_list:
} // tgl_do_get_dialog_list (TLS, lua_dialog_list_cb, lua_ptr[p ++]);
assert (lua_gettop (luaState) == 4); // break;
// case lq_msg:
// tgl_do_send_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], strlen (lua_ptr[p + 2]), lua_msg_cb, lua_ptr[p]);
int r = lua_pcall (luaState, 3, 0, 0); // free (lua_ptr[p + 2]);
// p += 3;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // break;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // case lq_send_typing:
// tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_typing, lua_empty_cb, lua_ptr[p]);
if (r) { // p += 2;
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // break;
} // case lq_send_typing_abort:
// tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_cancel, lua_empty_cb, lua_ptr[p]);
free (cb); // p += 2;
} // break;
// case lq_rename_chat:
void lua_msg_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_message *M) { // tgl_do_rename_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
assert (TLSR == TLS); // free (lua_ptr[p + 2]);
struct lua_query_extra *cb = cb_extra; // p += 3;
lua_settop (luaState, 0); // break;
//lua_checkstack (luaState, 20); // case lq_send_photo:
my_lua_checkstack (luaState, 20); // tgl_do_send_document (TLS, -1, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
// free (lua_ptr[p + 2]);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // p += 3;
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // break;
// case lq_send_video:
lua_pushnumber (luaState, success); // tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
// free (lua_ptr[p + 2]);
if (success) { // p += 3;
push_message (M); // break;
} else { // case lq_send_audio:
lua_pushboolean (luaState, 0); // tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
} // free (lua_ptr[p + 2]);
// p += 3;
assert (lua_gettop (luaState) == 4); // break;
// case lq_send_document:
int r = lua_pcall (luaState, 3, 0, 0); // tgl_do_send_document (TLS, 0, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
// free (lua_ptr[p + 2]);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // p += 3;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // break;
// case lq_send_file:
if (r) { // tgl_do_send_document (TLS, -2, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // free (lua_ptr[p + 2]);
} // p += 3;
// break;
free (cb); // case lq_send_text:
} // tgl_do_send_text (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
// free (lua_ptr[p + 2]);
void lua_msg_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, int num, struct tgl_message *M[]) { // p += 3;
assert (TLSR == TLS); // break;
struct lua_query_extra *cb = cb_extra; // case lq_chat_set_photo:
lua_settop (luaState, 0); // tgl_do_set_chat_photo (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]);
//lua_checkstack (luaState, 20); // free (lua_ptr[p + 2]);
my_lua_checkstack (luaState, 20); // p += 3;
// break;
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // case lq_load_photo:
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // case lq_load_video:
// case lq_load_audio:
lua_pushnumber (luaState, success); // case lq_load_document:
// M = lua_ptr[p + 1];
if (success) { // if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) {
lua_newtable (luaState); // lua_file_cb (TLS, lua_ptr[p], 0, 0);
int i; // } else {
for (i = 0; i < num; i++) { // if (M->media.type == tgl_message_media_photo) {
lua_pushnumber (luaState, i); // tgl_do_load_photo (TLS, &M->media.photo, lua_file_cb, lua_ptr[p]);
push_message (M[i]); // } else if (M->media.type == tgl_message_media_document) {
lua_settable (luaState, -3); // tgl_do_load_document (TLS, &M->media.document, lua_file_cb, lua_ptr[p]);
} // } else {
} else { // tgl_do_load_encr_document (TLS, &M->media.encr_document, lua_file_cb, lua_ptr[p]);
lua_pushboolean (luaState, 0); // }
} // }
// p += 2;
assert (lua_gettop (luaState) == 4); // break;
// case lq_load_video_thumb:
int r = lua_pcall (luaState, 3, 0, 0); // case lq_load_document_thumb:
// M = lua_ptr[p + 1];
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // if (!M || (M->media.type != tgl_message_media_document)) {
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // lua_file_cb (TLS, lua_ptr[p], 0, 0);
// } else {
if (r) { // tgl_do_load_document_thumb (TLS, &M->media.document, lua_file_cb, lua_ptr[p]);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // }
} // p += 2;
// break;
free (cb); // case lq_fwd:
} // tgl_do_forward_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]);
// p += 3;
void lua_file_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *file_name) { // break;
assert (TLSR == TLS); // case lq_fwd_media:
struct lua_query_extra *cb = cb_extra; // tgl_do_forward_media (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]);
lua_settop (luaState, 0); // p += 3;
//lua_checkstack (luaState, 20); // break;
my_lua_checkstack (luaState, 20); // case lq_chat_info:
// tgl_do_get_chat_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_chat_cb, lua_ptr[p]);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // p += 2;
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // break;
// case lq_user_info:
lua_pushnumber (luaState, success); // tgl_do_get_user_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_user_cb, lua_ptr[p]);
// p += 2;
if (success) { // break;
lua_pushstring (luaState, file_name); // case lq_history:
} else { // tgl_do_get_history (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, (long)lua_ptr[p + 2], 0, lua_msg_list_cb, lua_ptr[p]);
lua_pushboolean (luaState, 0); // p += 3;
} // break;
// case lq_chat_add_user:
assert (lua_gettop (luaState) == 4); // tgl_do_add_user_to_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, 10, lua_msg_cb, lua_ptr[p]);
// p += 3;
int r = lua_pcall (luaState, 3, 0, 0); // break;
// case lq_chat_del_user:
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // tgl_do_del_user_from_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // p += 3;
// break;
if (r) { // case lq_add_contact:
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // s1 = lua_ptr[p + 1];
} // s2 = lua_ptr[p + 2];
// s3 = lua_ptr[p + 3];
free (cb); // tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 0, lua_contact_list_cb, lua_ptr[p]);
} // free (s1);
// free (s2);
void lua_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_chat *C) { // free (s3);
assert (TLSR == TLS); // p += 4;
struct lua_query_extra *cb = cb_extra; // break;
lua_settop (luaState, 0); // case lq_del_contact:
//lua_checkstack (luaState, 20); // tgl_do_del_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
my_lua_checkstack (luaState, 20); // p += 2;
// break;
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // case lq_rename_contact:
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // s1 = lua_ptr[p + 1];
// s2 = lua_ptr[p + 2];
lua_pushnumber (luaState, success); // s3 = lua_ptr[p + 3];
// tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 1, lua_contact_list_cb, lua_ptr[p]);
if (success) { // free (s1);
push_peer (C->id, (void *)C); // free (s2);
} else { // free (s3);
lua_pushboolean (luaState, 0); // p += 4;
} // break;
// case lq_search:
assert (lua_gettop (luaState) == 4); // s = lua_ptr[p + 2];
// tgl_do_msg_search (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]);
int r = lua_pcall (luaState, 3, 0, 0); // free (s);
// p += 3;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // break;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // case lq_global_search:
// s = lua_ptr[p + 1];
if (r) { // tgl_do_msg_search (TLS, tgl_set_peer_id (TGL_PEER_UNKNOWN, 0), 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // free (s);
} // p += 2;
// break;
free (cb); // case lq_mark_read:
} // tgl_do_mark_read (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
// p += 2;
void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_secret_chat *C) { // break;
assert (TLSR == TLS); // case lq_set_profile_photo:
struct lua_query_extra *cb = cb_extra; // s = lua_ptr[p + 1];
lua_settop (luaState, 0); // tgl_do_set_profile_photo (TLS, s, lua_empty_cb, lua_ptr[p]);
//lua_checkstack (luaState, 20); // free (s);
my_lua_checkstack (luaState, 20); // p += 2;
// break;
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // case lq_set_profile_name:
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // s1 = lua_ptr[p + 1];
// s2 = lua_ptr[p + 1];
lua_pushnumber (luaState, success); // tgl_do_set_profile_name (TLS, s1, s2, lua_user_cb, lua_ptr[p]);
// free (s1);
if (success) { // free (s2);
push_peer (C->id, (void *)C); // p += 3;
} else { // break;
lua_pushboolean (luaState, 0); // case lq_create_secret_chat:
} // tgl_do_create_secret_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_secret_chat_cb, lua_ptr[p]);
// p += 2;
assert (lua_gettop (luaState) == 4); // break;
// case lq_create_group_chat:
int r = lua_pcall (luaState, 3, 0, 0); // s = lua_ptr[p + 2];
// tgl_do_create_group_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s, lua_msg_cb, lua_ptr[p]);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // free (s);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // p += 3;
// break;
if (r) { // case lq_delete_msg:
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // tgl_do_delete_msg (TLS, ((struct tgl_message *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
} // p += 2;
// break;
free (cb); // case lq_restore_msg:
} // tgl_do_delete_msg (TLS, (long)lua_ptr[p + 1], lua_empty_cb, lua_ptr[p]);
// p += 2;
void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) { // break;
assert (TLSR == TLS); // case lq_accept_secret_chat:
struct lua_query_extra *cb = cb_extra; // tgl_do_accept_encr_chat_request (TLS, lua_ptr[p + 1], lua_secret_chat_cb, lua_ptr[p]);
lua_settop (luaState, 0); // p += 2;
//lua_checkstack (luaState, 20); // break;
my_lua_checkstack (luaState, 20); // case lq_send_contact:
// s1 = lua_ptr[p + 2];
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // s2 = lua_ptr[p + 3];
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // s3 = lua_ptr[p + 4];
// tgl_do_send_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), lua_msg_cb, lua_ptr[p]);
lua_pushnumber (luaState, success); // free (s1);
// free (s2);
if (success) { // free (s3);
push_peer (C->id, (void *)C); // p += 5;
} else { // break;
lua_pushboolean (luaState, 0); // case lq_status_online:
} // tgl_do_update_status (TLS, 1, lua_empty_cb, lua_ptr[p]);
// p ++;
assert (lua_gettop (luaState) == 4); // break;
// case lq_status_offline:
int r = lua_pcall (luaState, 3, 0, 0); // tgl_do_update_status (TLS, 0, lua_empty_cb, lua_ptr[p]);
// p ++;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // break;
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // case lq_extf:
// s = lua_ptr[p + 1];
if (r) { // tgl_do_send_extf (TLS, s, strlen (s), lua_str_cb, lua_ptr[p]);
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); // free (s);
} // p += 2;
// break;
free (cb); // case lq_send_location:
} // if (sizeof (void *) == 4) {
// tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(float *)(lua_ptr + p + 2), *(float *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]);
void lua_str_cb (struct tgl_state *TLSR, void *cb_extra, int success, char *data) { // } else {
assert (TLSR == TLS); // tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(double *)(lua_ptr + p + 2), *(double *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]);
struct lua_query_extra *cb = cb_extra; // }
lua_settop (luaState, 0); // p += 4;
//lua_checkstack (luaState, 20); // break;
my_lua_checkstack (luaState, 20); // /*
// lq_delete_msg,
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); // lq_restore_msg,
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); // case 0:
// tgl_do_send_message (((tgl_peer_t *)lua_ptr[p])->id, lua_ptr[p + 1], strlen (lua_ptr[p + 1]), 0, 0);
lua_pushnumber (luaState, success); // free (lua_ptr[p + 1]);
// p += 2;
if (success) { // break;
lua_pushstring (luaState, data); // case 1:
} else { // tgl_do_forward_message (((tgl_peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1], 0, 0);
lua_pushboolean (luaState, 0); // p += 2;
} // break;
// case 2:
assert (lua_gettop (luaState) == 4); // tgl_do_mark_read (((tgl_peer_t *)lua_ptr[p])->id, 0, 0);
// p += 1;
int r = lua_pcall (luaState, 3, 0, 0); // break;*/
// default:
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); // assert (0);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); // }
// }
if (r) { // pos = 0;
logprintf ("lua: %s\n", lua_tostring (luaState, -1)); //}
} //
//
free (cb); //enum lua_function_param {
} // lfp_none,
// lfp_peer,
void lua_do_all (void) { // lfp_chat,
int p = 0; // lfp_user,
while (p < pos) { // lfp_secret_chat,
int l = (long)lua_ptr[p ++]; // lfp_string,
assert (p + l + 1 <= pos); // lfp_number,
enum lua_query_type f = (long)lua_ptr[p ++]; // lfp_positive_number,
struct tgl_message *M; // lfp_nonnegative_number,
char *s, *s1, *s2, *s3; // lfp_msg,
switch (f) { // lfp_double
case lq_contact_list: //};
tgl_do_update_contact_list (TLS, lua_contact_list_cb, lua_ptr[p ++]); //
break; //struct lua_function {
case lq_dialog_list: // char *name;
tgl_do_get_dialog_list (TLS, lua_dialog_list_cb, lua_ptr[p ++]); // enum lua_query_type type;
break; // enum lua_function_param params[10];
case lq_msg: //};
tgl_do_send_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], strlen (lua_ptr[p + 2]), lua_msg_cb, lua_ptr[p]); //
free (lua_ptr[p + 2]); //struct lua_function functions[] = {
p += 3; // {"get_contact_list", lq_contact_list, { lfp_none }},
break; // {"get_dialog_list", lq_dialog_list, { lfp_none }},
case lq_send_typing: // {"rename_chat", lq_rename_chat, { lfp_chat, lfp_string, lfp_none }},
tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_typing, lua_empty_cb, lua_ptr[p]); // {"send_msg", lq_msg, { lfp_peer, lfp_string, lfp_none }},
p += 2; // {"send_typing", lq_send_typing, { lfp_peer, lfp_none }},
break; // {"send_typing_abort", lq_send_typing_abort, { lfp_peer, lfp_none }},
case lq_send_typing_abort: // {"send_photo", lq_send_photo, { lfp_peer, lfp_string, lfp_none }},
tgl_do_send_typing (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, tgl_typing_cancel, lua_empty_cb, lua_ptr[p]); // {"send_video", lq_send_video, { lfp_peer, lfp_string, lfp_none }},
p += 2; // {"send_audio", lq_send_audio, { lfp_peer, lfp_string, lfp_none }},
break; // {"send_document", lq_send_document, { lfp_peer, lfp_string, lfp_none }},
case lq_rename_chat: // {"send_file", lq_send_file, { lfp_peer, lfp_string, lfp_none }},
tgl_do_rename_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"send_text", lq_send_text, { lfp_peer, lfp_string, lfp_none }},
free (lua_ptr[p + 2]); // {"chat_set_photo", lq_chat_set_photo, { lfp_chat, lfp_string, lfp_none }},
p += 3; // {"load_photo", lq_load_photo, { lfp_msg, lfp_none }},
break; // {"load_video", lq_load_video, { lfp_msg, lfp_none }},
case lq_send_photo: // {"load_video_thumb", lq_load_video_thumb, { lfp_msg, lfp_none }},
tgl_do_send_document (TLS, -1, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"load_audio", lq_load_audio, { lfp_msg, lfp_none }},
free (lua_ptr[p + 2]); // {"load_document", lq_load_document, { lfp_msg, lfp_none }},
p += 3; // {"load_document_thumb", lq_load_document_thumb, { lfp_msg, lfp_none }},
break; // {"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }},
case lq_send_video: // {"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }},
tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"chat_info", lq_chat_info, { lfp_chat, lfp_none }},
free (lua_ptr[p + 2]); // {"user_info", lq_user_info, { lfp_user, lfp_none }},
p += 3; // {"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }},
break; // {"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }},
case lq_send_audio: // {"chat_del_user", lq_chat_del_user, { lfp_chat, lfp_user, lfp_none }},
tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"add_contact", lq_add_contact, { lfp_string, lfp_string, lfp_string, lfp_none }},
free (lua_ptr[p + 2]); // {"del_contact", lq_del_contact, { lfp_user, lfp_none }},
p += 3; // {"rename_contact", lq_rename_contact, { lfp_string, lfp_string, lfp_string, lfp_none }},
break; // {"msg_search", lq_search, { lfp_peer, lfp_string, lfp_none }},
case lq_send_document: // {"msg_global_search", lq_global_search, { lfp_string, lfp_none }},
tgl_do_send_document (TLS, 0, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"mark_read", lq_mark_read, { lfp_peer, lfp_none }},
free (lua_ptr[p + 2]); // {"set_profile_photo", lq_set_profile_photo, { lfp_string, lfp_none }},
p += 3; // {"set_profile_name", lq_set_profile_name, { lfp_string, lfp_none }},
break; // {"create_secret_chat", lq_create_secret_chat, { lfp_user, lfp_none }},
case lq_send_file: // {"create_group_chat", lq_create_group_chat, { lfp_user, lfp_string, lfp_none }},
tgl_do_send_document (TLS, -2, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"delete_msg", lq_delete_msg, { lfp_msg, lfp_none }},
free (lua_ptr[p + 2]); // {"restore_msg", lq_restore_msg, { lfp_positive_number, lfp_none }},
p += 3; // {"accept_secret_chat", lq_accept_secret_chat, { lfp_secret_chat, lfp_none }},
break; // {"send_contact", lq_send_contact, { lfp_peer, lfp_string, lfp_string, lfp_string, lfp_none }},
case lq_send_text: // {"status_online", lq_status_online, { lfp_none }},
tgl_do_send_text (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); // {"status_offline", lq_status_offline, { lfp_none }},
free (lua_ptr[p + 2]); // {"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }},
p += 3; // {"ext_function", lq_extf, { lfp_string, lfp_none }},
break; // { 0, 0, { lfp_none}}
case lq_chat_set_photo: //};
tgl_do_set_chat_photo (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], lua_msg_cb, lua_ptr[p]); //
free (lua_ptr[p + 2]); //static int parse_lua_function (lua_State *L, struct lua_function *F) {
p += 3; // int p = 0;
break; // while (F->params[p] != lfp_none) { p ++; }
case lq_load_photo: // if (lua_gettop (L) != p + 2) {
case lq_load_video: // lua_pushboolean (L, 0);
case lq_load_audio: // return 1;
case lq_load_document: // }
M = lua_ptr[p + 1]; //
if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) { // int a1 = luaL_ref (L, LUA_REGISTRYINDEX);
lua_file_cb (TLS, lua_ptr[p], 0, 0); // int a2 = luaL_ref (L, LUA_REGISTRYINDEX);
} else { //
if (M->media.type == tgl_message_media_photo) { // struct lua_query_extra *e = malloc (sizeof (*e));
tgl_do_load_photo (TLS, &M->media.photo, lua_file_cb, lua_ptr[p]); // assert (e);
} else if (M->media.type == tgl_message_media_document) { // e->func = a2;
tgl_do_load_document (TLS, &M->media.document, lua_file_cb, lua_ptr[p]); // e->param = a1;
} else { //
tgl_do_load_encr_document (TLS, &M->media.encr_document, lua_file_cb, lua_ptr[p]); // assert (pos + 3 + p < MAX_LUA_COMMANDS);
} //
} // lua_ptr[pos ++] = (void *)(long)(p + 1);
p += 2; // lua_ptr[pos ++] = (void *)(long)F->type;
break; // lua_ptr[pos ++] = e;
case lq_load_video_thumb: //
case lq_load_document_thumb: // int sp = p;
M = lua_ptr[p + 1]; // int ok = 1;
if (!M || (M->media.type != tgl_message_media_document)) { // int cc = 0;
lua_file_cb (TLS, lua_ptr[p], 0, 0); // while (p > 0) {
} else { // p --;
tgl_do_load_document_thumb (TLS, &M->media.document, lua_file_cb, lua_ptr[p]); // cc ++;
} // const char *s;
p += 2; // tgl_peer_t *P;
break; // long long num;
case lq_fwd: // double dval;
tgl_do_forward_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]); // struct tgl_message *M;
p += 3; // switch (F->params[p]) {
break; // case lfp_none:
case lq_fwd_media: // assert (0);
tgl_do_forward_media (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((struct tgl_message *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]); // break;
p += 3; // case lfp_peer:
break; // case lfp_user:
case lq_chat_info: // case lfp_chat:
tgl_do_get_chat_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_chat_cb, lua_ptr[p]); // case lfp_secret_chat:
p += 2; // s = lua_tostring (L, -cc);
break; // if (!s) {
case lq_user_info: // ok = 0;
tgl_do_get_user_info (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, lua_user_cb, lua_ptr[p]); // break;
p += 2; // }
break; // if (sscanf (s, "user#id%lld", &num) == 1 && num > 0) {
case lq_history: // tgl_insert_empty_user (TLS, num);
tgl_do_get_history (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, (long)lua_ptr[p + 2], 0, lua_msg_list_cb, lua_ptr[p]); // P = tgl_peer_get (TLS, TGL_MK_USER (num));
p += 3; // } else if (sscanf (s, "chat#id%lld", &num) == 1 && num > 0) {
break; // tgl_insert_empty_chat (TLS, num);
case lq_chat_add_user: // P = tgl_peer_get (TLS, TGL_MK_CHAT (num));
tgl_do_add_user_to_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, 10, lua_msg_cb, lua_ptr[p]); // } else {
p += 3; // P = get_peer (s);
break; // }
case lq_chat_del_user: // if (!P/* || !(P->flags & FLAG_CREATED)*/) {
tgl_do_del_user_from_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, ((tgl_peer_t *)lua_ptr[p + 2])->id, lua_msg_cb, lua_ptr[p]); // ok = 0;
p += 3; // break;
break; // }
case lq_add_contact: // if (F->params[p] != lfp_peer) {
s1 = lua_ptr[p + 1]; // if ((tgl_get_peer_type (P->id) == TGL_PEER_USER && F->params[p] != lfp_user) ||
s2 = lua_ptr[p + 2]; // (tgl_get_peer_type (P->id) == TGL_PEER_CHAT && F->params[p] != lfp_chat) ||
s3 = lua_ptr[p + 3]; // (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT && F->params[p] != lfp_secret_chat)) {
tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 0, lua_contact_list_cb, lua_ptr[p]); // ok = 0;
free (s1); // break;
free (s2); // }
free (s3); // }
p += 4; // lua_ptr[pos + p] = P;
break; // break;
case lq_del_contact: //
tgl_do_del_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); // case lfp_string:
p += 2; // s = lua_tostring (L, -cc);
break; // if (!s) {
case lq_rename_contact: // ok = 0;
s1 = lua_ptr[p + 1]; // break;
s2 = lua_ptr[p + 2]; // }
s3 = lua_ptr[p + 3]; // lua_ptr[pos + p] = (void *)s;
tgl_do_add_contact (TLS, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), 1, lua_contact_list_cb, lua_ptr[p]); // break;
free (s1); //
free (s2); // case lfp_number:
free (s3); // num = lua_tonumber (L, -cc);
p += 4; //
break; // lua_ptr[pos + p] = (void *)(long)num;
case lq_search: // break;
s = lua_ptr[p + 2]; //
tgl_do_msg_search (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]); // case lfp_double:
free (s); // dval = lua_tonumber (L, -cc);
p += 3; //
break; // if (sizeof (void *) == 4) {
case lq_global_search: // *(float *)(lua_ptr + pos + p) = dval;
s = lua_ptr[p + 1]; // } else {
tgl_do_msg_search (TLS, tgl_set_peer_id (TGL_PEER_UNKNOWN, 0), 0, 0, 40, 0, s, lua_msg_list_cb, lua_ptr[p]); // assert (sizeof (void *) >= 8);
free (s); // *(double *)(lua_ptr + pos + p) = dval;
p += 2; // }
break; // break;
case lq_mark_read: //
tgl_do_mark_read (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); // case lfp_positive_number:
p += 2; // num = lua_tonumber (L, -cc);
break; // if (num <= 0) {
case lq_set_profile_photo: // ok = 0;
s = lua_ptr[p + 1]; // break;
tgl_do_set_profile_photo (TLS, s, lua_empty_cb, lua_ptr[p]); // }
free (s); //
p += 2; // lua_ptr[pos + p] = (void *)(long)num;
break; // break;
case lq_set_profile_name: //
s1 = lua_ptr[p + 1]; // case lfp_nonnegative_number:
s2 = lua_ptr[p + 1]; // num = lua_tonumber (L, -cc);
tgl_do_set_profile_name (TLS, s1, s2, lua_user_cb, lua_ptr[p]); // if (num < 0) {
free (s1); // ok = 0;
free (s2); // break;
p += 3; // }
break; //
case lq_create_secret_chat: // lua_ptr[pos + p] = (void *)(long)num;
tgl_do_create_secret_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_secret_chat_cb, lua_ptr[p]); // break;
p += 2; //
break; // case lfp_msg:
case lq_create_group_chat: // s = lua_tostring (L, -cc);
s = lua_ptr[p + 2]; // if (!s || !strlen (s)) {
tgl_do_create_group_chat (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s, lua_msg_cb, lua_ptr[p]); // ok = 0;
free (s); // break;
p += 3; // }
break; //
case lq_delete_msg: // num = atoll (s);
tgl_do_delete_msg (TLS, ((struct tgl_message *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]); //
p += 2; // M = tgl_message_get (TLS, num);
break; //
case lq_restore_msg: // if (!M || !(M->flags & FLAG_CREATED)) {
tgl_do_delete_msg (TLS, (long)lua_ptr[p + 1], lua_empty_cb, lua_ptr[p]); // ok = 0;
p += 2; // break;
break; // }
case lq_accept_secret_chat: //
tgl_do_accept_encr_chat_request (TLS, lua_ptr[p + 1], lua_secret_chat_cb, lua_ptr[p]); // lua_ptr[pos + p] = M;
p += 2; // break;
break; //
case lq_send_contact: // default:
s1 = lua_ptr[p + 2]; // assert (0);
s2 = lua_ptr[p + 3]; // }
s3 = lua_ptr[p + 4]; // }
tgl_do_send_contact (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, s1, strlen (s1), s2, strlen (s2), s3, strlen (s3), lua_msg_cb, lua_ptr[p]); // if (!ok) {
free (s1); // luaL_unref (luaState, LUA_REGISTRYINDEX, a1);
free (s2); // luaL_unref (luaState, LUA_REGISTRYINDEX, a2);
free (s3); // free (e);
p += 5; // pos -= 3;
break; // lua_pushboolean (L, 0);
case lq_status_online: // return 1;
tgl_do_update_status (TLS, 1, lua_empty_cb, lua_ptr[p]); // }
p ++; //
break; // for (p = 0; p < sp; p++) {
case lq_status_offline: // if (F->params[p] == lfp_string) {
tgl_do_update_status (TLS, 0, lua_empty_cb, lua_ptr[p]); // lua_ptr[pos + p] = strdup (lua_ptr[pos + p]);
p ++; // }
break; // }
case lq_extf: // pos += p;
s = lua_ptr[p + 1]; //
tgl_do_send_extf (TLS, s, strlen (s), lua_str_cb, lua_ptr[p]); // lua_pushboolean (L, 1);
free (s); // return 1;
p += 2; //}
break; //
case lq_send_location: //
if (sizeof (void *) == 4) { //static void lua_postpone_alarm (evutil_socket_t fd, short what, void *arg) {
tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(float *)(lua_ptr + p + 2), *(float *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]); // int *t = arg;
} else { //
tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(double *)(lua_ptr + p + 2), *(double *)(lua_ptr + p + 3), lua_msg_cb, lua_ptr[p]); // lua_settop (luaState, 0);
} // //lua_checkstack (luaState, 20);
p += 4; // my_lua_checkstack (luaState, 20);
break; //
/* // lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[1]);
lq_delete_msg, // lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[0]);
lq_restore_msg, // assert (lua_gettop (luaState) == 2);
case 0: //
tgl_do_send_message (((tgl_peer_t *)lua_ptr[p])->id, lua_ptr[p + 1], strlen (lua_ptr[p + 1]), 0, 0); // int r = lua_pcall (luaState, 1, 0, 0);
free (lua_ptr[p + 1]); //
p += 2; // luaL_unref (luaState, LUA_REGISTRYINDEX, t[0]);
break; // luaL_unref (luaState, LUA_REGISTRYINDEX, t[1]);
case 1: //
tgl_do_forward_message (((tgl_peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1], 0, 0); // if (r) {
p += 2; // logprintf ("lua: %s\n", lua_tostring (luaState, -1));
break; // }
case 2: //
tgl_do_mark_read (((tgl_peer_t *)lua_ptr[p])->id, 0, 0); //}
p += 1; //
break;*/ //static int postpone_from_lua (lua_State *L) {
default: // int n = lua_gettop (L);
assert (0); // if (n != 3) {
} // lua_pushboolean (L, 0);
} // return 1;
pos = 0; // }
} //
// double timeout = lua_tonumber (L, -1);
// if (timeout < 0) {
enum lua_function_param { // lua_pushboolean (L, 0);
lfp_none, // return 1;
lfp_peer, // }
lfp_chat, //
lfp_user, // lua_pop (L, 1);
lfp_secret_chat, // int a1 = luaL_ref (L, LUA_REGISTRYINDEX);
lfp_string, // int a2 = luaL_ref (L, LUA_REGISTRYINDEX);
lfp_number, //
lfp_positive_number, //
lfp_nonnegative_number, // int *t = malloc (16);
lfp_msg, // assert (t);
lfp_double // struct event *ev = evtimer_new (TLS->ev_base, lua_postpone_alarm, t);
}; // t[0] = a1;
// t[1] = a2;
struct lua_function { // *(void **)(t + 2) = ev;
char *name; //
enum lua_query_type type; // struct timeval ts= {
enum lua_function_param params[10]; // .tv_sec = (long)timeout,
}; // .tv_usec = (timeout - ((long)timeout)) * 1000000
// };
struct lua_function functions[] = { // event_add (ev, &ts);
{"get_contact_list", lq_contact_list, { lfp_none }}, //
{"get_dialog_list", lq_dialog_list, { lfp_none }}, // lua_pushboolean (L, 1);
{"rename_chat", lq_rename_chat, { lfp_chat, lfp_string, lfp_none }}, // return 1;
{"send_msg", lq_msg, { lfp_peer, lfp_string, lfp_none }}, //}
{"send_typing", lq_send_typing, { lfp_peer, lfp_none }}, //
{"send_typing_abort", lq_send_typing_abort, { lfp_peer, lfp_none }}, //extern int safe_quit;
{"send_photo", lq_send_photo, { lfp_peer, lfp_string, lfp_none }}, //static int safe_quit_from_lua (lua_State *L) {
{"send_video", lq_send_video, { lfp_peer, lfp_string, lfp_none }}, // int n = lua_gettop (L);
{"send_audio", lq_send_audio, { lfp_peer, lfp_string, lfp_none }}, // if (n != 0) {
{"send_document", lq_send_document, { lfp_peer, lfp_string, lfp_none }}, // lua_pushboolean (L, 0);
{"send_file", lq_send_file, { lfp_peer, lfp_string, lfp_none }}, // return 1;
{"send_text", lq_send_text, { lfp_peer, lfp_string, lfp_none }}, // }
{"chat_set_photo", lq_chat_set_photo, { lfp_chat, lfp_string, lfp_none }}, // safe_quit = 1;
{"load_photo", lq_load_photo, { lfp_msg, lfp_none }}, //
{"load_video", lq_load_video, { lfp_msg, lfp_none }}, // lua_pushboolean (L, 1);
{"load_video_thumb", lq_load_video_thumb, { lfp_msg, lfp_none }}, // return 1;
{"load_audio", lq_load_audio, { lfp_msg, lfp_none }}, //}
{"load_document", lq_load_document, { lfp_msg, lfp_none }}, //
{"load_document_thumb", lq_load_document_thumb, { lfp_msg, lfp_none }}, //static int universal_from_lua (lua_State *L) {
{"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }}, // const char *s = lua_tostring(L, lua_upvalueindex(1));
{"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }}, // if (!s) {
{"chat_info", lq_chat_info, { lfp_chat, lfp_none }}, // lua_pushboolean (L, 0);
{"user_info", lq_user_info, { lfp_user, lfp_none }}, // return 1;
{"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }}, // }
{"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }}, // int i = 0;
{"chat_del_user", lq_chat_del_user, { lfp_chat, lfp_user, lfp_none }}, // while (functions[i].name) {
{"add_contact", lq_add_contact, { lfp_string, lfp_string, lfp_string, lfp_none }}, // if (!strcmp (functions[i].name, s)) {
{"del_contact", lq_del_contact, { lfp_user, lfp_none }}, // return parse_lua_function (L, &functions[i]);
{"rename_contact", lq_rename_contact, { lfp_string, lfp_string, lfp_string, lfp_none }}, // }
{"msg_search", lq_search, { lfp_peer, lfp_string, lfp_none }}, // i ++;
{"msg_global_search", lq_global_search, { lfp_string, lfp_none }}, // }
{"mark_read", lq_mark_read, { lfp_peer, lfp_none }}, // lua_pushboolean (L, 0);
{"set_profile_photo", lq_set_profile_photo, { lfp_string, lfp_none }}, // return 1;
{"set_profile_name", lq_set_profile_name, { lfp_string, lfp_none }}, //}
{"create_secret_chat", lq_create_secret_chat, { lfp_user, lfp_none }}, //
{"create_group_chat", lq_create_group_chat, { lfp_user, lfp_string, lfp_none }}, //
{"delete_msg", lq_delete_msg, { lfp_msg, lfp_none }}, //static void my_python_register (const char *name, lua_CFunction f) {
{"restore_msg", lq_restore_msg, { lfp_positive_number, lfp_none }}, // lua_pushstring(L, name);
{"accept_secret_chat", lq_accept_secret_chat, { lfp_secret_chat, lfp_none }}, // lua_pushcclosure(L, f, 1);
{"send_contact", lq_send_contact, { lfp_peer, lfp_string, lfp_string, lfp_string, lfp_none }}, // lua_setglobal(L, name);
{"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}}
};
static int parse_lua_function (lua_State *L, struct lua_function *F) {
int p = 0;
while (F->params[p] != lfp_none) { p ++; }
if (lua_gettop (L) != p + 2) {
lua_pushboolean (L, 0);
return 1;
}
int a1 = luaL_ref (L, LUA_REGISTRYINDEX);
int a2 = luaL_ref (L, LUA_REGISTRYINDEX);
struct lua_query_extra *e = malloc (sizeof (*e));
assert (e);
e->func = a2;
e->param = a1;
assert (pos + 3 + p < MAX_LUA_COMMANDS);
lua_ptr[pos ++] = (void *)(long)(p + 1);
lua_ptr[pos ++] = (void *)(long)F->type;
lua_ptr[pos ++] = e;
int sp = p;
int ok = 1;
int cc = 0;
while (p > 0) {
p --;
cc ++;
const char *s;
tgl_peer_t *P;
long long num;
double dval;
struct tgl_message *M;
switch (F->params[p]) {
case lfp_none:
assert (0);
break;
case lfp_peer:
case lfp_user:
case lfp_chat:
case lfp_secret_chat:
s = lua_tostring (L, -cc);
if (!s) {
ok = 0;
break;
}
if (sscanf (s, "user#id%lld", &num) == 1 && num > 0) {
tgl_insert_empty_user (TLS, num);
P = tgl_peer_get (TLS, TGL_MK_USER (num));
} else if (sscanf (s, "chat#id%lld", &num) == 1 && num > 0) {
tgl_insert_empty_chat (TLS, num);
P = tgl_peer_get (TLS, TGL_MK_CHAT (num));
} else {
P = get_peer (s);
}
if (!P/* || !(P->flags & FLAG_CREATED)*/) {
ok = 0;
break;
}
if (F->params[p] != lfp_peer) {
if ((tgl_get_peer_type (P->id) == TGL_PEER_USER && F->params[p] != lfp_user) ||
(tgl_get_peer_type (P->id) == TGL_PEER_CHAT && F->params[p] != lfp_chat) ||
(tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT && F->params[p] != lfp_secret_chat)) {
ok = 0;
break;
}
}
lua_ptr[pos + p] = P;
break;
case lfp_string:
s = lua_tostring (L, -cc);
if (!s) {
ok = 0;
break;
}
lua_ptr[pos + p] = (void *)s;
break;
case lfp_number:
num = lua_tonumber (L, -cc);
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) {
ok = 0;
break;
}
lua_ptr[pos + p] = (void *)(long)num;
break;
case lfp_nonnegative_number:
num = lua_tonumber (L, -cc);
if (num < 0) {
ok = 0;
break;
}
lua_ptr[pos + p] = (void *)(long)num;
break;
case lfp_msg:
s = lua_tostring (L, -cc);
if (!s || !strlen (s)) {
ok = 0;
break;
}
num = atoll (s);
M = tgl_message_get (TLS, num);
if (!M || !(M->flags & FLAG_CREATED)) {
ok = 0;
break;
}
lua_ptr[pos + p] = M;
break;
default:
assert (0);
}
}
if (!ok) {
luaL_unref (luaState, LUA_REGISTRYINDEX, a1);
luaL_unref (luaState, LUA_REGISTRYINDEX, a2);
free (e);
pos -= 3;
lua_pushboolean (L, 0);
return 1;
}
for (p = 0; p < sp; p++) {
if (F->params[p] == lfp_string) {
lua_ptr[pos + p] = strdup (lua_ptr[pos + p]);
}
}
pos += p;
lua_pushboolean (L, 1);
return 1;
}
static void lua_postpone_alarm (evutil_socket_t fd, short what, void *arg) {
int *t = arg;
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[1]);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[0]);
assert (lua_gettop (luaState) == 2);
int r = lua_pcall (luaState, 1, 0, 0);
luaL_unref (luaState, LUA_REGISTRYINDEX, t[0]);
luaL_unref (luaState, LUA_REGISTRYINDEX, t[1]);
if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
}
}
static int postpone_from_lua (lua_State *L) {
int n = lua_gettop (L);
if (n != 3) {
lua_pushboolean (L, 0);
return 1;
}
double timeout = lua_tonumber (L, -1);
if (timeout < 0) {
lua_pushboolean (L, 0);
return 1;
}
lua_pop (L, 1);
int a1 = luaL_ref (L, LUA_REGISTRYINDEX);
int a2 = luaL_ref (L, LUA_REGISTRYINDEX);
int *t = malloc (16);
assert (t);
struct event *ev = evtimer_new (TLS->ev_base, lua_postpone_alarm, t);
t[0] = a1;
t[1] = a2;
*(void **)(t + 2) = ev;
struct timeval ts= {
.tv_sec = (long)timeout,
.tv_usec = (timeout - ((long)timeout)) * 1000000
};
event_add (ev, &ts);
lua_pushboolean (L, 1);
return 1;
}
extern int safe_quit;
static int safe_quit_from_lua (lua_State *L) {
int n = lua_gettop (L);
if (n != 0) {
lua_pushboolean (L, 0);
return 1;
}
safe_quit = 1;
lua_pushboolean (L, 1);
return 1;
}
static int universal_from_lua (lua_State *L) {
const char *s = lua_tostring(L, lua_upvalueindex(1));
if (!s) {
lua_pushboolean (L, 0);
return 1;
}
int i = 0;
while (functions[i].name) {
if (!strcmp (functions[i].name, s)) {
return parse_lua_function (L, &functions[i]);
}
i ++;
}
lua_pushboolean (L, 0);
return 1;
}
static void my_python_register (const char *name, lua_CFunction f) {
lua_pushstring(L, name);
lua_pushcclosure(L, f, 1);
lua_setglobal(L, name);
}
void py_init (const char *file) { void py_init (const char *file) {
if (!file) { return; } if (!file) { return; }
have_file = 1; have_file = 1;
PyObject *pName, *pModule; // PyObject *pName;//, *pModule;
Py_Initialize() Py_Initialize();
pName = PyFile_FromFile(file, "telegram.py", 'r', null); // pName = PyFile_FromFile(file, "telegram.py", 'r', null);
err = PyErr_Occurred(); // PyObject* err = PyErr_Occurred();
if (err != NULL) { // if (err != NULL) {
logprintf("python error occurred"); // TODO: implement the backtrace // logprintf("python error occurred"); // TODO: implement the backtrace
exit(1); // exit(1);
} // }
int i = 0; // int i = 0;
while (functions[i].name) { // while (functions[i].name) {
my_lua_register (luaState, functions[i].name, universal_from_lua); // my_lua_register (luaState, functions[i].name, universal_from_lua);
i ++; // i ++;
} // }
//lua_register (luaState, "fwd_msg", fwd_msg_from_lua); //lua_register (luaState, "fwd_msg", fwd_msg_from_lua);
//lua_register (luaState, "mark_read", mark_read_from_lua); //lua_register (luaState, "mark_read", mark_read_from_lua);
lua_register (luaState, "postpone", postpone_from_lua); // lua_register (luaState, "postpone", postpone_from_lua);
lua_register (luaState, "safe_quit", safe_quit_from_lua); // lua_register (luaState, "safe_quit", safe_quit_from_lua);
//lua_register (luaState, "get_contact_list", get_contacts_from_lua); //lua_register (luaState, "get_contact_list", get_contacts_from_lua);
/*lua_register (luaState, "get_dialog_list", get_dialog_list_from_lua); /*lua_register (luaState, "get_dialog_list", get_dialog_list_from_lua);
lua_register (luaState, "send_msg", send_msg_from_lua); lua_register (luaState, "send_msg", send_msg_from_lua);
...@@ -1487,11 +1486,6 @@ void py_init (const char *file) { ...@@ -1487,11 +1486,6 @@ void py_init (const char *file) {
lua_register (luaState, "add_contact", add_contact_from_lua); lua_register (luaState, "add_contact", add_contact_from_lua);
lua_register (luaState, "rename_contact", rename_contact_from_lua);*/ lua_register (luaState, "rename_contact", rename_contact_from_lua);*/
int ret = luaL_dofile (luaState, file);
if (ret) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
exit (1);
}
} }
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment