mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45:10 +00:00
[MOD] Hide avatar code behind another function
This commit is contained in:
parent
4bc2d1606a
commit
ce8bbb5540
2 changed files with 41 additions and 27 deletions
|
|
@ -29,6 +29,7 @@ wiki page.
|
|||
allowed.
|
||||
- Allows experimental MbedTLS through a specific Cytoplasm
|
||||
patch (though still unstable AND slow).
|
||||
- Does basic work towards NetBSD support
|
||||
|
||||
#### Bugfixes
|
||||
- Adds more information to media events so that clients can
|
||||
|
|
|
|||
|
|
@ -46,10 +46,43 @@ TrimBase64(char *b64)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static bool
|
||||
AvatarGrab(ParseeData *data, char *mxc, char **mime, char **b64, size_t *len)
|
||||
{
|
||||
char *mimei = NULL, *outi = NULL, *b64i = NULL;
|
||||
size_t sizei;
|
||||
if (!data || !mxc || !mime || !b64 || !len)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ASGrab(data->config, mxc, &mimei, &outi, &sizei))
|
||||
{
|
||||
Free(mimei);
|
||||
Free(outi);
|
||||
return false;
|
||||
}
|
||||
|
||||
b64i = Base64Encode(outi, sizei);
|
||||
Free(outi);
|
||||
if (!b64i || strlen(b64i) > 64 KB)
|
||||
{
|
||||
Free(b64i);
|
||||
Free(mimei);
|
||||
b64i = StrDuplicate(media_parsee_logo); /* TODO: Different assets! */
|
||||
mimei = StrDuplicate("image/png");
|
||||
}
|
||||
|
||||
*mime = mimei;
|
||||
*b64 = b64i;
|
||||
*len = sizei;
|
||||
return true;
|
||||
}
|
||||
|
||||
XMLElement *
|
||||
GenerateAvatarData(ParseeData *data, char *mxid)
|
||||
{
|
||||
char *mxc = NULL, *mime = NULL, *out = NULL, *b64 = NULL;
|
||||
char *mxc = NULL, *mime = NULL, *b64 = NULL;
|
||||
XMLElement *elem = NULL, *type, *binval;
|
||||
size_t len = 0;
|
||||
if (!data || !mxid)
|
||||
|
|
@ -57,22 +90,12 @@ GenerateAvatarData(ParseeData *data, char *mxid)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO: Use the right room */
|
||||
/* TODO: Use the right room for the avatar! */
|
||||
mxc = ASGetAvatar(data->config, NULL, mxid);
|
||||
|
||||
if (!mxc || !ASGrab(data->config, mxc, &mime, &out, &len))
|
||||
if (!mxc || !AvatarGrab(data, mxc, &mime, &b64, &len))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
b64 = Base64Encode(out, len);
|
||||
if (!b64 || strlen(b64) > 64 KB) /* We still have stanza limitations. Thanks, Array.
|
||||
* TODO: Communicate with the server to discover it. */
|
||||
{
|
||||
Free(b64);
|
||||
Free(mime);
|
||||
b64 = StrDuplicate(media_parsee_logo); /* TODO: Different assets! */
|
||||
mime = StrDuplicate("image/png");
|
||||
}
|
||||
|
||||
elem = XMLCreateTag("PHOTO");
|
||||
type = XMLCreateTag("TYPE");
|
||||
|
|
@ -86,7 +109,6 @@ GenerateAvatarData(ParseeData *data, char *mxid)
|
|||
|
||||
end:
|
||||
Free(mime);
|
||||
Free(out);
|
||||
Free(mxc);
|
||||
Free(b64);
|
||||
return elem;
|
||||
|
|
@ -475,21 +497,12 @@ IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
* risk I do *not* want to take. */
|
||||
char *to_matrix = ParseeDecodeMXID(to);
|
||||
char *avatar = ASGetAvatar(args->config, NULL, to_matrix);
|
||||
char *buf, *mime;
|
||||
char *b64;
|
||||
size_t len;
|
||||
char *mime = NULL;
|
||||
char *b64 = NULL;
|
||||
size_t len = 0;
|
||||
XMLElement *reply;
|
||||
|
||||
ASGrab(args->config, avatar, &mime, &buf, &len);
|
||||
b64 = Base64Encode(buf, len);
|
||||
if (!b64 || strlen(b64) > 64 KB)
|
||||
{
|
||||
Free(b64);
|
||||
Free(mime);
|
||||
b64 = StrDuplicate(media_parsee_logo); /* TODO: Different assets! */
|
||||
mime = StrDuplicate("image/png");
|
||||
}
|
||||
Free(buf);
|
||||
AvatarGrab(args, avatar, &mime, &b64, &len);
|
||||
|
||||
Log(LOG_DEBUG, "IQ-GET: PUBSUB AVATAR OF=%s", to_matrix);
|
||||
/* Strike back with a response */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue