mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 15:05:11 +00:00
[MOD] Add width/height information when possible
This commit is contained in:
parent
09d38993bb
commit
d989331716
5 changed files with 103 additions and 3 deletions
|
|
@ -79,7 +79,7 @@ MatrixCreateNickChange(char *nick)
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
HashMap *
|
HashMap *
|
||||||
MatrixCreateMedia(char *mxc, char *body, char *mime)
|
MatrixCreateMedia(char *mxc, char *body, char *mime, FileInfo *info)
|
||||||
{
|
{
|
||||||
HashMap *map;
|
HashMap *map;
|
||||||
char *mime_type = NULL, *matrix_type = NULL;
|
char *mime_type = NULL, *matrix_type = NULL;
|
||||||
|
|
@ -120,6 +120,11 @@ MatrixCreateMedia(char *mxc, char *body, char *mime)
|
||||||
|
|
||||||
map = HashMapCreate();
|
map = HashMapCreate();
|
||||||
JsonSet(map, JsonValueString(mime), 2, "info", "mimetype");
|
JsonSet(map, JsonValueString(mime), 2, "info", "mimetype");
|
||||||
|
if (info && info->width && info->height)
|
||||||
|
{
|
||||||
|
JsonSet(map, JsonValueInteger(info->width), 2, "info", "w");
|
||||||
|
JsonSet(map, JsonValueInteger(info->height), 2, "info", "h");
|
||||||
|
}
|
||||||
HashMapSet(map, "msgtype", JsonValueString(matrix_type));
|
HashMapSet(map, "msgtype", JsonValueString(matrix_type));
|
||||||
HashMapSet(map, "mimetype", JsonValueString(mime));
|
HashMapSet(map, "mimetype", JsonValueString(mime));
|
||||||
HashMapSet(map, "body", JsonValueString(body));
|
HashMapSet(map, "body", JsonValueString(body));
|
||||||
|
|
|
||||||
66
src/FileInfo.c
Normal file
66
src/FileInfo.c
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
#include <FileInfo.h>
|
||||||
|
|
||||||
|
#include <Cytoplasm/Memory.h>
|
||||||
|
#include <Cytoplasm/Str.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
GetField(XMLElement *elem)
|
||||||
|
{
|
||||||
|
XMLElement *child;
|
||||||
|
if (!elem || ArraySize(elem->children) != 1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
child = ArrayGet(elem->children, 0);
|
||||||
|
|
||||||
|
return strtol(child->data, NULL, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInfo *
|
||||||
|
FileInfoFromXMPP(XMLElement *stanza)
|
||||||
|
{
|
||||||
|
FileInfo *info;
|
||||||
|
XMLElement *reference, *sims, *file;
|
||||||
|
|
||||||
|
if (!stanza)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
reference = XMLookForTKV(stanza,
|
||||||
|
"reference", "xmlns", "urn:xmpp:reference:0"
|
||||||
|
);
|
||||||
|
sims = XMLookForTKV(reference,
|
||||||
|
"media-sharing", "xmlns", "urn:xmpp:sims:1"
|
||||||
|
);
|
||||||
|
file = XMLookForTKV(sims,
|
||||||
|
"file", "xmlns", "urn:xmpp:jingle:apps:file-transfer:5"
|
||||||
|
);
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
info = Malloc(sizeof(*info));
|
||||||
|
|
||||||
|
|
||||||
|
info->width = GetField(XMLookForUnique(file, "width"));
|
||||||
|
info->height = GetField(XMLookForUnique(file, "height"));
|
||||||
|
info->size = GetField(XMLookForUnique(file, "size"));
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FileInfoFree(FileInfo *info)
|
||||||
|
{
|
||||||
|
if (!info)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Free(info);
|
||||||
|
}
|
||||||
|
|
@ -419,10 +419,13 @@ end_error:
|
||||||
|
|
||||||
if (oob_data)
|
if (oob_data)
|
||||||
{
|
{
|
||||||
|
FileInfo *info = FileInfoFromXMPP(stanza);
|
||||||
mxc = ASReupload(args->config, oob_data->data, &mime);
|
mxc = ASReupload(args->config, oob_data->data, &mime);
|
||||||
if (mxc)
|
if (mxc)
|
||||||
{
|
{
|
||||||
content = MatrixCreateMedia(mxc, data->data, mime);
|
content = MatrixCreateMedia(
|
||||||
|
mxc, data->data, mime, info
|
||||||
|
);
|
||||||
|
|
||||||
HashMapSet(content,
|
HashMapSet(content,
|
||||||
"at.kappach.at.parsee.external",
|
"at.kappach.at.parsee.external",
|
||||||
|
|
@ -436,6 +439,7 @@ end_error:
|
||||||
);
|
);
|
||||||
Free(mxc);
|
Free(mxc);
|
||||||
}
|
}
|
||||||
|
FileInfoFree(info);
|
||||||
Free(mime);
|
Free(mime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
src/include/FileInfo.h
Normal file
23
src/include/FileInfo.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef PARSEE_FILEINFO_H
|
||||||
|
#define PARSEE_FILEINFO_H
|
||||||
|
|
||||||
|
#include "XML.h"
|
||||||
|
|
||||||
|
typedef struct FileInfo {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int size;
|
||||||
|
} FileInfo;
|
||||||
|
|
||||||
|
/** Grab file metadata through SIMS.
|
||||||
|
* ----------------
|
||||||
|
* Returns: File information(SIMS)[HEAP]
|
||||||
|
* Thrasher: FileInfoFree */
|
||||||
|
extern FileInfo * FileInfoFromXMPP(XMLElement *stanza);
|
||||||
|
|
||||||
|
/** Frees all information related with file metadata.
|
||||||
|
* --------------
|
||||||
|
* Thrashes: info */
|
||||||
|
extern void FileInfoFree(FileInfo *info);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <Cytoplasm/Json.h>
|
#include <Cytoplasm/Json.h>
|
||||||
|
|
||||||
|
#include "FileInfo.h"
|
||||||
|
|
||||||
/* A simple representation of everything. It is not as complex as
|
/* A simple representation of everything. It is not as complex as
|
||||||
* Telodendria's CommonID parser, simply because Parsee does not
|
* Telodendria's CommonID parser, simply because Parsee does not
|
||||||
* need such complexity. */
|
* need such complexity. */
|
||||||
|
|
@ -33,7 +35,7 @@ extern HashMap * MatrixCreateReact(char *event, char *body);
|
||||||
extern HashMap * MatrixCreateReplace(char *event, char *body);
|
extern HashMap * MatrixCreateReplace(char *event, char *body);
|
||||||
|
|
||||||
/* Creates the content for a media file. */
|
/* Creates the content for a media file. */
|
||||||
extern HashMap * MatrixCreateMedia(char *mxc, char *body, char *mime);
|
extern HashMap * MatrixCreateMedia(char *mxc, char *body, char *mime, FileInfo *info);
|
||||||
|
|
||||||
/* Creates the content for a m.room.name state event */
|
/* Creates the content for a m.room.name state event */
|
||||||
extern HashMap * MatrixCreateNameState(char *name);
|
extern HashMap * MatrixCreateNameState(char *name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue