fix(discord-misc.c): discord_params_to_mime() assigning of incorrect types
@@ -15,38 +15,37 @@ struct msg {
void
_discord_params_to_mime(curl_mime *mime, void *p_cxt)
{
- NTL_T(struct discord_attachment) attachments = ((void**)p_cxt)[0];
+ NTL_T(struct discord_attachment) atchs = ((void**)p_cxt)[0];
struct sized_buffer *buf = ((void**)p_cxt)[1];
+ curl_mimepart *part;
+ char name[64];
/* json part */
- if (buf->start) {
- curl_mimepart *part = curl_mime_addpart(mime);
+ if (buf->start && buf->size) {
+ part = curl_mime_addpart(mime);
curl_mime_data(part, buf->start, buf->size);
curl_mime_type(part, "application/json");
curl_mime_name(part, "payload_json");
}
/* attachment part */
- char name[64];
- for (int i=0; attachments[i]; ++i) {
+ for (int i=0; atchs[i]; ++i) {
snprintf(name, sizeof(name), "files[%d]", i);
-
- curl_mimepart *part = curl_mime_addpart(mime);
- if (attachments[i]->content) {
- char *fname = IS_EMPTY_STRING(attachments[i]->filename) ? "a.out" : attachments[i]->filename;
- int fsize = attachments[i]->size ? attachments[i]->size : CURL_ZERO_TERMINATED;
- curl_mime_data(part, attachments[i]->content, fsize);
- curl_mime_filename(part, fname);
- }
- else if (!IS_EMPTY_STRING(attachments[i]->filename)) {
- curl_mime_filedata(part, attachments[i]->filename);
+ if (atchs[i]->content) {
+ part = curl_mime_addpart(mime);
+ curl_mime_data(part, atchs[i]->content, atchs[i]->size ? atchs[i]->size : CURL_ZERO_TERMINATED);
+ curl_mime_filename(part, IS_EMPTY_STRING(atchs[i]->filename) ? "a.out" : atchs[i]->filename);
+ curl_mime_type(part, IS_EMPTY_STRING(atchs[i]->content_type) ? "application/octet-stream" : atchs[i]->content_type);
+ curl_mime_name(part, name);
}
- curl_mime_type(part, (IS_EMPTY_STRING(attachments[i]->content_type))
- ? "application/octet-stream"
- : attachments[i]->content_type);
+ else if (!IS_EMPTY_STRING(atchs[i]->filename)) { /* fetch local file by the filename */
+ part = curl_mime_addpart(mime);
+ curl_mime_filedata(part, atchs[i]->filename);
+ curl_mime_type(part, IS_EMPTY_STRING(atchs[i]->content_type) ? "application/octet-stream" : atchs[i]->content_type);
curl_mime_name(part, name);
}
}
+}
ORCAcode
discord_delete_messages_by_author_id(
