mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:05:10 +00:00
[MOD] Hash-based name conflict resolution
Still basic, but should prevent basic name issues.
This commit is contained in:
parent
c0c13883d1
commit
59cbd8b22d
11 changed files with 147 additions and 109 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Sha.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -11,6 +12,38 @@
|
|||
#include <Matrix.h>
|
||||
#include <AS.h>
|
||||
|
||||
static void
|
||||
JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name)
|
||||
{
|
||||
char *sender = GrabString(event, 1, "sender");
|
||||
|
||||
char *rev = StrConcat(3, muc, "/", name);
|
||||
int nonce = 0;
|
||||
|
||||
while (!XMPPJoinMUC(data->jabber, jid, rev, true) && nonce < 20)
|
||||
{
|
||||
char *nonce_str = StrInt(nonce);
|
||||
char *input = StrConcat(4, sender, name, data->id, nonce_str);
|
||||
unsigned char *digest = Sha256(input);
|
||||
char *hex = ShaToHex(digest);
|
||||
|
||||
if (strlen(hex) >= 8)
|
||||
{
|
||||
hex[8] = '\0';
|
||||
}
|
||||
|
||||
Free(rev);
|
||||
rev = StrConcat(6, muc, "/", name, "[", hex, "]");
|
||||
nonce++;
|
||||
|
||||
Free(nonce_str);
|
||||
Free(digest);
|
||||
Free(input);
|
||||
Free(hex);
|
||||
}
|
||||
Free(rev);
|
||||
}
|
||||
|
||||
static void
|
||||
ParseeMemberHandler(ParseeData *data, HashMap *event)
|
||||
{
|
||||
|
|
@ -55,10 +88,10 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
|
|||
if (chat_id)
|
||||
{
|
||||
char *muc = ParseeGetMUCID(data, chat_id);
|
||||
char *rev = StrConcat(2, muc, "/parsee");
|
||||
char *name = ASGetName(data->config, room_id, state_key);
|
||||
|
||||
XMPPJoinMUC(data->jabber, jid, rev);
|
||||
Free(rev);
|
||||
JoinMUC(data, event, jid, muc, name);
|
||||
Free(name);
|
||||
Free(muc);
|
||||
|
||||
/* TODO: XEP-0084 magic to advertise a new avatar if possible. */
|
||||
|
|
@ -162,8 +195,6 @@ GetXMPPInformation(ParseeData *data, HashMap *event, char **from, char **to)
|
|||
DbRef *room_data;
|
||||
HashMap *data_json;
|
||||
|
||||
XMPPComponent *jabber = data ? data->jabber : NULL;
|
||||
|
||||
bool direct = false;
|
||||
if (!data || !event || !from || !to)
|
||||
{
|
||||
|
|
@ -194,7 +225,7 @@ GetXMPPInformation(ParseeData *data, HashMap *event, char **from, char **to)
|
|||
}
|
||||
else
|
||||
{
|
||||
char *matrix_name, *muc_join_as;
|
||||
char *matrix_name;
|
||||
|
||||
muc_id = ParseeGetMUCID(data, chat_id);
|
||||
if (!chat_id)
|
||||
|
|
@ -208,18 +239,16 @@ GetXMPPInformation(ParseeData *data, HashMap *event, char **from, char **to)
|
|||
}
|
||||
|
||||
matrix_name = ASGetName(data->config, room_id, matrix_sender);
|
||||
muc_join_as = StrConcat(4, muc_id, "/", matrix_name, "[p]");
|
||||
|
||||
/* TODO: Manage name conflicts. That would have been an easy
|
||||
* task(try the original one, and use a counter if it fails),
|
||||
* but that'd involve modifying the rest of the code, which
|
||||
* I'm not doing at 01:39 ... */
|
||||
XMPPJoinMUC(jabber, *from, muc_join_as);
|
||||
JoinMUC(data, event, *from, muc_id, matrix_name);
|
||||
|
||||
*to = muc_id;
|
||||
|
||||
Free(matrix_name);
|
||||
Free(muc_join_as);
|
||||
}
|
||||
|
||||
Free(chat_id);
|
||||
|
|
@ -295,7 +324,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
}
|
||||
else
|
||||
{
|
||||
char *name, *rev;
|
||||
char *name;
|
||||
/* Try to find the chat ID */
|
||||
muc_id = ParseeGetMUCID(data, chat_id);
|
||||
if (!chat_id)
|
||||
|
|
@ -307,14 +336,12 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
* Is there a good way to check for that that isn't
|
||||
* just "await on join and try again?" */
|
||||
name = ASGetName(data->config, id, m_sender);
|
||||
rev = StrConcat(4, muc_id, "/", name, "[p]");
|
||||
|
||||
XMPPJoinMUC(jabber, encoded_from, rev);
|
||||
JoinMUC(data, event, encoded_from, muc_id, name);
|
||||
|
||||
to = muc_id;
|
||||
|
||||
Free(name);
|
||||
Free(rev);
|
||||
}
|
||||
if (reply_id)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue