Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/ewanc26/wolfram. Pure C11 AT Protocol SDK: client-side, wire-level implementation (XRPC, OAuth/DPoP
ansi-c api-client at-protocol atproto bluesky c c-sdk decentralized decentralized-social embedded lexicon libwolfram memory-management oauth2 posix sdk shared-library static-library systems-programming xrpc
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246#include "wolfram/embed.h"#include "wolfram/util.h"#include <cJSON.h>#include <stdlib.h>#include <string.h>#include "wolfram/embed_typed.h"
cJSON *wf_embed_images_new(void) { cJSON *embed = cJSON_CreateObject(); if (!embed) return NULL; if (!cJSON_AddStringToObject(embed, "$type", wf_embed_type_str(WF_EMBED_IMAGES))) { cJSON_Delete(embed); return NULL; } cJSON *images = cJSON_CreateArray(); if (!images) { cJSON_Delete(embed); return NULL; } if (!cJSON_AddItemToObject(embed, "images", images)) { cJSON_Delete(images); cJSON_Delete(embed); return NULL; } return embed;}
wf_status wf_embed_images_add_image(cJSON *embed, const wf_uploaded_blob *blob, const char *alt) { if (!embed || !blob) return WF_ERR_INVALID_ARG; cJSON *images = cJSON_GetObjectItem(embed, "images"); if (!images || !cJSON_IsArray(images)) return WF_ERR_INVALID_ARG;
// Build blob JSON cJSON *blob_obj = cJSON_CreateObject(); if (!blob_obj) return WF_ERR_ALLOC; if (!cJSON_AddStringToObject(blob_obj, "$type", "blob")) { cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } cJSON *ref = cJSON_CreateObject(); if (!ref) { cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } if (!cJSON_AddStringToObject(ref, "$link", blob->cid)) { cJSON_Delete(ref); cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } if (!cJSON_AddItemToObject(blob_obj, "ref", ref)) { cJSON_Delete(ref); cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } if (!cJSON_AddStringToObject(blob_obj, "mimeType", blob->mime_type)) { cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } if (!cJSON_AddNumberToObject(blob_obj, "size", (double)blob->size)) { cJSON_Delete(blob_obj); return WF_ERR_ALLOC; }
// Image object cJSON *image_obj = cJSON_CreateObject(); if (!image_obj) { cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } if (!cJSON_AddItemToObject(image_obj, "image", blob_obj)) { cJSON_Delete(image_obj); cJSON_Delete(blob_obj); return WF_ERR_ALLOC; } if (alt && alt[0]) { if (!cJSON_AddStringToObject(image_obj, "alt", alt)) { cJSON_Delete(image_obj); return WF_ERR_ALLOC; } } else { // optional empty alt if (!cJSON_AddStringToObject(image_obj, "alt", "")) { cJSON_Delete(image_obj); return WF_ERR_ALLOC; } }
if (!cJSON_AddItemToArray(images, image_obj)) { cJSON_Delete(image_obj); return WF_ERR_ALLOC; } return WF_OK;}
cJSON *wf_embed_video_new(const wf_uploaded_blob *blob, const char *alt) { if (!blob) return NULL; cJSON *embed = cJSON_CreateObject(); if (!embed) return NULL; if (!cJSON_AddStringToObject(embed, "$type", wf_embed_type_str(WF_EMBED_VIDEO))) { cJSON_Delete(embed); return NULL; } // Build blob object (same as images) cJSON *blob_obj = cJSON_CreateObject(); if (!blob_obj) { cJSON_Delete(embed); return NULL; } if (!cJSON_AddStringToObject(blob_obj, "$type", "blob")) { cJSON_Delete(blob_obj); cJSON_Delete(embed); return NULL; } cJSON *ref = cJSON_CreateObject(); if (!ref) { cJSON_Delete(blob_obj); cJSON_Delete(embed); return NULL; } if (!cJSON_AddStringToObject(ref, "$link", blob->cid)) { cJSON_Delete(ref); cJSON_Delete(blob_obj); cJSON_Delete(embed); return NULL; } if (!cJSON_AddItemToObject(blob_obj, "ref", ref)) { cJSON_Delete(blob_obj); cJSON_Delete(embed); return NULL; } if (!cJSON_AddStringToObject(blob_obj, "mimeType", blob->mime_type)) { cJSON_Delete(blob_obj); cJSON_Delete(embed); return NULL; } if (!cJSON_AddNumberToObject(blob_obj, "size", (double)blob->size)) { cJSON_Delete(blob_obj); cJSON_Delete(embed); return NULL; } if (!cJSON_AddItemToObject(embed, "video", blob_obj)) { cJSON_Delete(embed); return NULL; } if (alt && alt[0]) { if (!cJSON_AddStringToObject(embed, "alt", alt)) { cJSON_Delete(embed); return NULL; } } return embed;}
cJSON *wf_embed_external_new(const char *uri, const char *thumb, const char *title, const char *description) { if (!uri) return NULL; cJSON *embed = cJSON_CreateObject(); if (!embed) return NULL; if (!cJSON_AddStringToObject(embed, "$type", wf_embed_type_str(WF_EMBED_EXTERNAL))) { cJSON_Delete(embed); return NULL; } if (!cJSON_AddStringToObject(embed, "uri", uri)) { cJSON_Delete(embed); return NULL; } if (thumb && thumb[0]) { if (!cJSON_AddStringToObject(embed, "thumb", thumb)) { cJSON_Delete(embed); return NULL; } } if (title && title[0]) { if (!cJSON_AddStringToObject(embed, "title", title)) { cJSON_Delete(embed); return NULL; } } if (description && description[0]) { if (!cJSON_AddStringToObject(embed, "description", description)) { cJSON_Delete(embed); return NULL; } } return embed;}
cJSON *wf_embed_record_new(const char *uri, const char *cid) { if (!uri || !cid) return NULL; cJSON *embed = cJSON_CreateObject(); if (!embed) return NULL; if (!cJSON_AddStringToObject(embed, "$type", wf_embed_type_str(WF_EMBED_RECORD))) { cJSON_Delete(embed); return NULL; } cJSON *record = cJSON_CreateObject(); if (!record) { cJSON_Delete(embed); return NULL; } if (!cJSON_AddStringToObject(record, "uri", uri)) { cJSON_Delete(record); cJSON_Delete(embed); return NULL; } if (!cJSON_AddStringToObject(record, "cid", cid)) { cJSON_Delete(record); cJSON_Delete(embed); return NULL; } if (!cJSON_AddItemToObject(embed, "record", record)) { cJSON_Delete(record); cJSON_Delete(embed); return NULL; } return embed;}
cJSON *wf_embed_record_with_media_new(cJSON *record_embed, cJSON *media_embed) { if (!record_embed || !media_embed) return NULL; cJSON *embed = cJSON_CreateObject(); if (!embed) return NULL; if (!cJSON_AddStringToObject( embed, "$type", wf_embed_type_str(WF_EMBED_RECORD_WITH_MEDIA))) { cJSON_Delete(embed); return NULL; } // Both inputs are objects; attach them and transfer ownership. if (!cJSON_AddItemToObject(embed, "record", record_embed)) { cJSON_Delete(record_embed); cJSON_Delete(embed); return NULL; } if (!cJSON_AddItemToObject(embed, "media", media_embed)) { cJSON_Delete(media_embed); cJSON_Delete(embed); return NULL; } return embed;}