Browse Source

Report preparation rejection and release abandoned owned sources

master
evgeny 2 days ago
parent
commit
f2ff3ee5ab
  1. 16
      src/dm/dm_media.c
  2. 14
      src/media_async/attachment_send.c

16
src/dm/dm_media.c

@ -620,16 +620,24 @@ static void dm_source_cleanup(void* arg) {
}
static void dm_source_cleaned(void* arg, int error) {
if (error) DEBUG_WARN(DEBUG_CATEGORY_DM, "dm_media: source cleanup cancelled error=%d", error);
if (error) {
DEBUG_WARN(DEBUG_CATEGORY_DM, "dm_media: source cleanup cancelled error=%d", error);
dm_source_cleanup(arg);
}
u_free(arg);
}
void dm_send_file_trampoline(void* arg) {
struct dm_file_req* req = arg;
if (!req) return;
if (dm_send_file(req->inst, req->conv, req->path, &req->info, req->remove_source) && req->remove_source) {
media_async_submit(req->inst->media_async, req->inst->ua, dm_source_cleanup, req, dm_source_cleaned, req);
return;
if (dm_send_file(req->inst, req->conv, req->path, &req->info, req->remove_source)) {
const uint8_t rejected[16] = {0};
chat_event_attachment(req->inst, 1, req->conv, rejected, 2);
if (req->remove_source) {
media_async_submit(req->inst ? req->inst->media_async : NULL, req->inst ? req->inst->ua : NULL,
dm_source_cleanup, req, dm_source_cleaned, req);
return;
}
}
u_free(req);
}

14
src/media_async/attachment_send.c

@ -48,7 +48,7 @@ static void attachment_prepare_work(void* arg) {
req->error = ma_copy_file(req->source, req->output);
}
done:
if (req->temporary_source && remove(req->source) && errno != ENOENT) {
if (req->temporary_source && !req->transcode && remove(req->source) && errno != ENOENT) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: source cleanup failed path=%s", req->source); req->error = -1;
}
attachment_release_pcm(req);
@ -59,12 +59,14 @@ done:
/* Один выбор транспорта после общей подготовки; групповой индекс и PM crypto не смешиваются. */
static void attachment_publish(struct attachment_send_req* req, int error) {
attachment_release_pcm(req); /* Submit мог завершиться ошибкой до запуска work. */
if (req->temporary_source && remove(req->source) && errno != ENOENT) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: abandoned source cleanup failed path=%s", req->source);
error = -1;
}
if (error || req->error || attachment_validate(&req->info)) {
chat_event_attachment(req->inst, req->is_dm, req->target, req->id, 2);
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: preparation failed target=%s error=%d worker=%d", req->target, error, req->error);
if (remove(req->output) && errno != ENOENT) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "attachment: output cleanup failed path=%s", req->output);
if (req->temporary_source && remove(req->source) && errno != ENOENT)
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "attachment: abandoned source cleanup failed path=%s", req->source);
u_free(req); return;
}
chat_event_attachment(req->inst, req->is_dm, req->target, req->id, 1);
@ -132,11 +134,11 @@ void attachment_send_trampoline(void* arg) {
if (!req->inst || !req->inst->chat_core || !req->inst->media_async || !req->target[0] ||
strspn(req->target, "0123456789") != strlen(req->target)) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: invalid target/stopped service");
attachment_release_pcm(req); u_free(req); return;
attachment_publish(req, -1); return;
}
uint8_t uuid[16]; char hex[33];
if (RAND_bytes(uuid, sizeof(uuid)) != 1) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: UUID generation failed"); attachment_release_pcm(req); u_free(req); return;
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: UUID generation failed"); attachment_publish(req, -1); return;
}
for (unsigned i = 0; i < 16; i++) snprintf(hex + 2 * i, 3, "%02x", uuid[i]);
memcpy(req->id, uuid, sizeof(req->id));
@ -144,7 +146,7 @@ void attachment_send_trampoline(void* arg) {
int n = snprintf(req->output, sizeof(req->output), "%s/media/%s/%s.%s", base[0] ? base : ".",
req->is_dm ? "pm-prepared" : req->target, hex, req->info.kind == ATTACHMENT_VOICE ? "opus" : "mp4");
if (n < 0 || (size_t)n >= sizeof(req->output)) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: output path too long"); attachment_release_pcm(req); u_free(req); return;
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: output path too long"); req->output[0] = 0; attachment_publish(req, -1); return;
}
if (!req->info.name[0]) snprintf(req->info.name, sizeof(req->info.name), "%s.%s", hex,
req->info.kind == ATTACHMENT_VOICE ? "opus" : "mp4");

Loading…
Cancel
Save