diff --git a/tools/chatgui-android/libutun_lite/attachment_sender.c b/tools/chatgui-android/libutun_lite/attachment_sender.c index bc1f5e81..d14bc719 100644 --- a/tools/chatgui-android/libutun_lite/attachment_sender.c +++ b/tools/chatgui-android/libutun_lite/attachment_sender.c @@ -12,14 +12,15 @@ #include #include -int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path) { +int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path, + const uint8_t reply_to[32], uint64_t request_id) { if (!channel_id || !src_file_path || !db_path) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: invalid args"); return -1; } struct UASYNC* ua = instance_lite_get_uasync(); - if (!ua) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: no uasync"); return -1; } + if (!uasync_is_running(ua)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "attachment_send: core stopped"); return -1; } /* get original basename for display, then make unique filename for storage */ char path_copy[1024]; @@ -52,6 +53,7 @@ int attachment_send(const char* channel_id, const char* src_file_path, const cha tmp[off++] = media_dir[i]; if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); } } + tmp[off] = '\0'; mkdir(tmp, 0755); } @@ -64,9 +66,14 @@ int attachment_send(const char* channel_id, const char* src_file_path, const cha data = original_basename — becomes first part of message "d" field: "name.ext|size|..." */ size_t datalen = strlen(original_basename); struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1); - if (!req) return -1; + struct posted_task* post = u_calloc(1, sizeof(*post)); + if (!req || !post) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment_send: allocation failed"); u_free(req); u_free(post); return -1; + } req->inst = instance_lite_get_instance(); + memcpy(req->reply_to, reply_to, sizeof(req->reply_to)); + req->request_id = request_id; snprintf(req->channel_id, sizeof(req->channel_id), "%s", channel_id); snprintf(req->content_type, sizeof(req->content_type), "application/octet-stream"); snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path); @@ -80,6 +87,7 @@ int attachment_send(const char* channel_id, const char* src_file_path, const cha DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "attachment_send: ch=%s src=%s dst=%s name=%s size=%lld", channel_id, src_file_path, media_file, original_basename, (long long)st.st_size); - uasync_post(ua, chat_core_submit_trampoline, req); + post->callback = chat_core_submit_trampoline; post->arg = req; + uasync_post_reserved(ua, post); return 0; } diff --git a/tools/chatgui-android/libutun_lite/attachment_sender.h b/tools/chatgui-android/libutun_lite/attachment_sender.h index 1447f5dc..5ad36020 100644 --- a/tools/chatgui-android/libutun_lite/attachment_sender.h +++ b/tools/chatgui-android/libutun_lite/attachment_sender.h @@ -3,12 +3,14 @@ * 0 = запрос поставлен в uasync, -1 = отказ подготовки. Исходный файл нужен до завершения media-задачи. */ #ifndef ATTACHMENT_SENDER_H #define ATTACHMENT_SENDER_H +#include #ifdef __cplusplus extern "C" { #endif -int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path); +int attachment_send(const char* channel_id, const char* src_file_path, const char* db_path, + const uint8_t reply_to[32], uint64_t request_id); #ifdef __cplusplus } diff --git a/tools/chatgui-android/libutun_lite/photo_sender.c b/tools/chatgui-android/libutun_lite/photo_sender.c index 68ee35f2..242a4acd 100644 --- a/tools/chatgui-android/libutun_lite/photo_sender.c +++ b/tools/chatgui-android/libutun_lite/photo_sender.c @@ -14,14 +14,14 @@ #include int photo_send(const char* channel_id, const char* src_file_path, const char* db_path, - int width, int height) { + int width, int height, const uint8_t reply_to[32], uint64_t request_id) { if (!channel_id || !src_file_path || !db_path) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: invalid args"); return -1; } struct UASYNC* ua = instance_lite_get_uasync(); - if (!ua) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: no uasync"); return -1; } + if (!uasync_is_running(ua)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: core stopped"); return -1; } struct stat st; memset(&st, 0, sizeof(st)); if (stat(src_file_path, &st) != 0 || st.st_size <= 0) { @@ -64,6 +64,7 @@ int photo_send(const char* channel_id, const char* src_file_path, const char* db tmp[off++] = media_dir[i]; if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); } } + tmp[off] = '\0'; mkdir(tmp, 0755); } @@ -72,9 +73,14 @@ int photo_send(const char* channel_id, const char* src_file_path, const char* db size_t datalen = strlen(original_basename); struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1); - if (!req) return -1; + struct posted_task* post = u_calloc(1, sizeof(*post)); + if (!req || !post) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "photo_send: allocation failed"); u_free(req); u_free(post); return -1; + } req->inst = instance_lite_get_instance(); + memcpy(req->reply_to, reply_to, sizeof(req->reply_to)); + req->request_id = request_id; snprintf(req->channel_id, sizeof(req->channel_id), "%s", channel_id); snprintf(req->content_type, sizeof(req->content_type), "%s", content_type); snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path); @@ -92,6 +98,7 @@ int photo_send(const char* channel_id, const char* src_file_path, const char* db channel_id, content_type, src_file_path, media_file, original_basename, (long long)st.st_size, width, height); - uasync_post(ua, chat_core_submit_trampoline, req); + post->callback = chat_core_submit_trampoline; post->arg = req; + uasync_post_reserved(ua, post); return 0; } diff --git a/tools/chatgui-android/libutun_lite/photo_sender.h b/tools/chatgui-android/libutun_lite/photo_sender.h index 7bb84c9f..69288eb7 100644 --- a/tools/chatgui-android/libutun_lite/photo_sender.h +++ b/tools/chatgui-android/libutun_lite/photo_sender.h @@ -3,13 +3,14 @@ * 0 = запрос поставлен в uasync, -1 = отказ. src_file_path должен существовать до завершения задачи. */ #ifndef PHOTO_SENDER_H #define PHOTO_SENDER_H +#include #ifdef __cplusplus extern "C" { #endif int photo_send(const char* channel_id, const char* src_file_path, const char* db_path, - int width, int height); + int width, int height, const uint8_t reply_to[32], uint64_t request_id); #ifdef __cplusplus }