|
|
|
|
@ -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"); |
|
|
|
|
|