mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55:10 +00:00
[MOD/FIX] Licensewerk, start counting by codepoint
XEP-0426 came out of the blue, and it *hit* me!
This commit is contained in:
parent
dba3dcc85f
commit
c2ea3807ec
7 changed files with 100 additions and 8 deletions
2
LICENSE
2
LICENSE
|
|
@ -1,4 +1,4 @@
|
|||
For the files src/Parsee/HMAC.c, src/XML/*, tools/*, src/include/XML.h, etc/*, and Makefile,
|
||||
For the files src/include/Unistring.h, src/Unistr.h rc/Parsee/HMAC.c, src/XML/*, tools/*, src/include/XML.h, etc/*, and Makefile,
|
||||
see COPYING.CC0.
|
||||
For any other file in src/, see COPYING.AGPL as the primary license.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Unistring.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -37,6 +39,22 @@ ParseeFindDatastart(char *data)
|
|||
|
||||
return (int) (startline - data);
|
||||
}
|
||||
int
|
||||
ParseeFindDatastartU(char *data)
|
||||
{
|
||||
Unistr *str;
|
||||
size_t ret;
|
||||
if (!data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
str = UnistrCreate(data);
|
||||
ret = UnistrGetOffset(str, (uint32_t) '>');
|
||||
UnistrFree(str);
|
||||
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
char *
|
||||
ParseeStringifyDate(uint64_t millis)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ ExportStanza(StanzaBuilder *builder)
|
|||
builder->replying_to_sender &&
|
||||
builder->body)
|
||||
{
|
||||
int off = ParseeFindDatastart(builder->body);
|
||||
int off = ParseeFindDatastartU(builder->body);
|
||||
char *ostr = StrInt(off);
|
||||
XMLElement *reply = XMLCreateTag("reply");
|
||||
XMLElement *fallback = XMLCreateTag("fallback");
|
||||
|
|
|
|||
45
src/Unistr.c
45
src/Unistr.c
|
|
@ -3,8 +3,10 @@
|
|||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct Unistr {
|
||||
size_t length;
|
||||
|
|
@ -222,3 +224,46 @@ UnistrFilter(Unistr *str, UnistrFilterFunc filter)
|
|||
|
||||
return unistr;
|
||||
}
|
||||
|
||||
Unistr *
|
||||
UnistrConcat(size_t n, ...)
|
||||
{
|
||||
va_list list;
|
||||
size_t i;
|
||||
Unistr *ret = UnistrCreate("");
|
||||
|
||||
va_start(list, n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
Unistr *to_concat = va_arg(list, Unistr *);
|
||||
size_t j;
|
||||
for (j = 0; j < UnistrSize(to_concat); j++)
|
||||
{
|
||||
UnistrAddch(ret, UnistrGetch(to_concat, j));
|
||||
}
|
||||
}
|
||||
|
||||
va_end(list);
|
||||
return ret;
|
||||
}
|
||||
size_t
|
||||
UnistrGetOffset(Unistr *str, uint32_t sep)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t prev = 0x0A;
|
||||
if (!str || !sep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < str->length; i++)
|
||||
{
|
||||
uint32_t curr = str->codepoints[i];
|
||||
if (prev == 0x0A && curr != sep)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
prev = curr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,20 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
LazyRegister(ParseeData *data, char *mxid, char *name)
|
||||
{
|
||||
if (!DbExists(data->db, 2, "users", mxid))
|
||||
{
|
||||
ASRegisterUser(data->config, mxid);
|
||||
DbUnlock(data->db, DbCreate(data->db, 2, "users", mxid));
|
||||
}
|
||||
if (name)
|
||||
{
|
||||
ASSetName(data->config, mxid, name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ProcessChatstates(ParseeData *args, XMLElement *stanza)
|
||||
{
|
||||
|
|
@ -211,7 +225,7 @@ end_error:
|
|||
HashMap *room_json;
|
||||
char *from = HashMapGet(stanza->attrs, "from");
|
||||
|
||||
ASRegisterUser(args->config, from_matrix);
|
||||
LazyRegister(args, from_matrix, NULL);
|
||||
room = ASCreateDM(args->config, from_matrix, to);
|
||||
mroom_id = StrDuplicate(room);
|
||||
Log(LOG_INFO, "Creating a DM to '%s'(%s)...", to, mroom_id);
|
||||
|
|
@ -273,11 +287,10 @@ end_error:
|
|||
XMLElement *oob, *oob_data;
|
||||
|
||||
pthread_mutex_unlock(&thr->info->chk_lock);
|
||||
ASRegisterUser(args->config, encoded);
|
||||
if (!chat)
|
||||
{
|
||||
ASSetName(args->config, encoded, res);
|
||||
}
|
||||
|
||||
LazyRegister(args, encoded, !chat ? res : NULL);
|
||||
/* TODO: I don't think we can quite remove that. Maybe
|
||||
* the user was kicked and the bridge is unaware? */
|
||||
ASInvite(args->config, mroom_id, encoded);
|
||||
Free(ASJoin(args->config, mroom_id, encoded));
|
||||
|
||||
|
|
|
|||
|
|
@ -286,6 +286,10 @@ extern void ParseeCleanup(void *data);
|
|||
/* Finds the offset of the first line without a '>' at its start. */
|
||||
extern int ParseeFindDatastart(char *data);
|
||||
|
||||
/* Finds the offset of the first line without a '>' at its start(as
|
||||
* Unicode codepoints). */
|
||||
extern int ParseeFindDatastartU(char *data);
|
||||
|
||||
|
||||
/* XMPP-ifies a message event to XEP-0393 if possible. */
|
||||
extern char * ParseeXMPPify(HashMap *event);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ extern uint32_t UnistrGetch(Unistr *unistr, size_t i);
|
|||
* Modifies: unistr */
|
||||
extern void UnistrAddch(Unistr *unistr, uint32_t u);
|
||||
|
||||
/** Concats N unistrings into a new, separate unistring.
|
||||
* ---------------------
|
||||
* Returns: a new unistring[HEAP]
|
||||
* Modifies: NOTHING
|
||||
* Thrasher: UnistrFree */
|
||||
extern Unistr * UnistrConcat(size_t n, ...);
|
||||
|
||||
/** Encodes a unistring into a C UTF-8 string
|
||||
* --------------
|
||||
* Returns: a valid NULL-terminated string[HEAP] | NULL
|
||||
|
|
@ -64,4 +71,9 @@ typedef bool (*UnistrFilterFunc)(uint32_t u);
|
|||
* Returns: a new unistring with filtered characters removed */
|
||||
extern Unistr * UnistrFilter(Unistr *str, UnistrFilterFunc filter);
|
||||
|
||||
/** Finds the offset of the first line not starting with a specific
|
||||
* characters in terms of Unicode codepoints.
|
||||
* --------
|
||||
* Returns: an offset of the first line to not start by {c} | 0 */
|
||||
extern size_t UnistrGetOffset(Unistr *str, uint32_t sep);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue