Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes print_media crash #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3442,8 +3442,8 @@ void print_media (struct in_ev *ev, struct tgl_message_media *M) {
return;

default:
mprintf (ev, "x = %d\n", M->type);
assert (0);
M->type = tgl_message_media_unsupported;
break;
}
}

Expand Down
68 changes: 67 additions & 1 deletion lua-tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ enum lua_query_type {
lq_send_file,
lq_load_audio,
lq_load_document,
lq_res_user,
lq_load_document_thumb,
lq_delete_msg,
lq_restore_msg,
Expand All @@ -654,7 +655,11 @@ enum lua_query_type {
lq_status_offline,
lq_send_location,
lq_extf,
lq_import_chat_link
lq_import_chat_link,
lq_export_chat_link,
lq_block_user,
lq_unblock_user,
lq_get_message
};

struct lua_query_extra {
Expand Down Expand Up @@ -914,6 +919,40 @@ void lua_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tg
free (cb);
}

void lua_link_cb (struct tgl_state *TLSR, void *cb_extra, int success, const char *link) {
assert (TLSR == TLS);
struct lua_query_extra *cb = cb_extra;
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
my_lua_checkstack (luaState, 20);

lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);

lua_pushnumber (luaState, success);

if (success) {
lua_pushstring (luaState, link);
} else {
lua_pushboolean (luaState, 0);
}

assert (lua_gettop (luaState) == 4);

int r = ps_lua_pcall (luaState, 3, 0, 0);

luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);

if (r) {
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
}

free (cb);
}



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 *cb = cb_extra;
Expand Down Expand Up @@ -1242,6 +1281,10 @@ void lua_do_all (void) {
free (s);
p += 2;
break;
case lq_export_chat_link:
tgl_do_export_chat_link (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_str_cb, lua_ptr[p]);
p += 2;
break;
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), 0, lua_msg_cb, lua_ptr[p]);
Expand All @@ -1250,6 +1293,24 @@ void lua_do_all (void) {
}
p += 4;
break;
case lq_res_user:
s = lua_ptr[p + 1];
tgl_do_contact_search (TLS, s, strlen (s), lua_user_cb, lua_ptr[p]);
free (s);
p += 2;
break;
case lq_block_user:
tgl_do_block_user (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
p += 2;
break;
case lq_unblock_user:
tgl_do_unblock_user (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_empty_cb, lua_ptr[p]);
p += 2;
break;
case lq_get_message:
tgl_do_get_message (TLS, (long)lua_ptr[p + 1], lua_msg_cb, lua_ptr[p]);
p += 2;
break;
/*
lq_delete_msg,
lq_restore_msg,
Expand Down Expand Up @@ -1340,6 +1401,11 @@ struct lua_function functions[] = {
{"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }},
{"ext_function", lq_extf, { lfp_string, lfp_none }},
{"import_chat_link", lq_import_chat_link, { lfp_string, lfp_none }},
{"res_user", lq_res_user, { lfp_string, lfp_none }},
{"export_chat_link", lq_export_chat_link, { lfp_chat, lfp_none }},
{"block_user", lq_block_user, { lfp_user, lfp_none }},
{"unblock_user", lq_unblock_user, { lfp_user, lfp_none }},
{"get_message", lq_get_message, { lfp_positive_number, lfp_none }},
{ 0, 0, { lfp_none}}
};

Expand Down