|
|
|
@ -14,14 +14,14 @@ |
|
|
|
#include <libgen.h> |
|
|
|
#include <libgen.h> |
|
|
|
|
|
|
|
|
|
|
|
int photo_send(const char* channel_id, const char* src_file_path, const char* db_path, |
|
|
|
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) { |
|
|
|
if (!channel_id || !src_file_path || !db_path) { |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: invalid args"); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "photo_send: invalid args"); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct UASYNC* ua = instance_lite_get_uasync(); |
|
|
|
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)); |
|
|
|
struct stat st; memset(&st, 0, sizeof(st)); |
|
|
|
if (stat(src_file_path, &st) != 0 || st.st_size <= 0) { |
|
|
|
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]; |
|
|
|
tmp[off++] = media_dir[i]; |
|
|
|
if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); } |
|
|
|
if (media_dir[i] == '/' && off > 1) { tmp[off] = '\0'; mkdir(tmp, 0755); } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tmp[off] = '\0'; |
|
|
|
mkdir(tmp, 0755); |
|
|
|
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); |
|
|
|
size_t datalen = strlen(original_basename); |
|
|
|
struct chat_msg_submit* req = u_calloc(1, sizeof(struct chat_msg_submit) + datalen + 1); |
|
|
|
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(); |
|
|
|
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->channel_id, sizeof(req->channel_id), "%s", channel_id); |
|
|
|
snprintf(req->content_type, sizeof(req->content_type), "%s", content_type); |
|
|
|
snprintf(req->content_type, sizeof(req->content_type), "%s", content_type); |
|
|
|
snprintf(req->media_src, sizeof(req->media_src), "%s", src_file_path); |
|
|
|
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, |
|
|
|
channel_id, content_type, src_file_path, media_file, original_basename, |
|
|
|
(long long)st.st_size, width, height); |
|
|
|
(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; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|