mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55: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.
|
allowed.
|
||||||
- Allows experimental MbedTLS through a specific Cytoplasm
|
- Allows experimental MbedTLS through a specific Cytoplasm
|
||||||
patch (though still unstable AND slow).
|
patch (though still unstable AND slow).
|
||||||
|
- Does basic work towards NetBSD support
|
||||||
|
|
||||||
#### Bugfixes
|
#### Bugfixes
|
||||||
- Adds more information to media events so that clients can
|
- Adds more information to media events so that clients can
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,43 @@ TrimBase64(char *b64)
|
||||||
return ret;
|
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 *
|
XMLElement *
|
||||||
GenerateAvatarData(ParseeData *data, char *mxid)
|
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;
|
XMLElement *elem = NULL, *type, *binval;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
if (!data || !mxid)
|
if (!data || !mxid)
|
||||||
|
|
@ -57,22 +90,12 @@ GenerateAvatarData(ParseeData *data, char *mxid)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Use the right room */
|
/* TODO: Use the right room for the avatar! */
|
||||||
mxc = ASGetAvatar(data->config, NULL, mxid);
|
mxc = ASGetAvatar(data->config, NULL, mxid);
|
||||||
|
if (!mxc || !AvatarGrab(data, mxc, &mime, &b64, &len))
|
||||||
if (!mxc || !ASGrab(data->config, mxc, &mime, &out, &len))
|
|
||||||
{
|
{
|
||||||
goto end;
|
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");
|
elem = XMLCreateTag("PHOTO");
|
||||||
type = XMLCreateTag("TYPE");
|
type = XMLCreateTag("TYPE");
|
||||||
|
|
@ -86,7 +109,6 @@ GenerateAvatarData(ParseeData *data, char *mxid)
|
||||||
|
|
||||||
end:
|
end:
|
||||||
Free(mime);
|
Free(mime);
|
||||||
Free(out);
|
|
||||||
Free(mxc);
|
Free(mxc);
|
||||||
Free(b64);
|
Free(b64);
|
||||||
return elem;
|
return elem;
|
||||||
|
|
@ -475,21 +497,12 @@ IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
* risk I do *not* want to take. */
|
* risk I do *not* want to take. */
|
||||||
char *to_matrix = ParseeDecodeMXID(to);
|
char *to_matrix = ParseeDecodeMXID(to);
|
||||||
char *avatar = ASGetAvatar(args->config, NULL, to_matrix);
|
char *avatar = ASGetAvatar(args->config, NULL, to_matrix);
|
||||||
char *buf, *mime;
|
char *mime = NULL;
|
||||||
char *b64;
|
char *b64 = NULL;
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
XMLElement *reply;
|
XMLElement *reply;
|
||||||
|
|
||||||
ASGrab(args->config, avatar, &mime, &buf, &len);
|
AvatarGrab(args, avatar, &mime, &b64, &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);
|
|
||||||
|
|
||||||
Log(LOG_DEBUG, "IQ-GET: PUBSUB AVATAR OF=%s", to_matrix);
|
Log(LOG_DEBUG, "IQ-GET: PUBSUB AVATAR OF=%s", to_matrix);
|
||||||
/* Strike back with a response */
|
/* Strike back with a response */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue