[WIP/FIX] Lock write operations to XMPP

I *think* that fixes stream errors with two threads writing at once.
Even if it doesn't, I think it's always a nice-to-have.
This commit is contained in:
LDA 2024-06-23 17:54:58 +02:00
commit 37155316b2
4 changed files with 32 additions and 0 deletions

View file

@ -15,6 +15,8 @@ XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type)
{
return;
}
pthread_mutex_lock(&comp->write_lock);
message = XMLCreateTag("message");
XMLAddAttr(message, "from", (from = StrConcat(3, fr, "@", comp->host)));
@ -56,6 +58,8 @@ XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type)
StreamFlush(comp->stream);
XMLFreeElement(message);
Free(from);
pthread_mutex_unlock(&comp->write_lock);
}
void
XMPPSendMUC(XMPPComponent *comp, char *fr, char *as, char *to, char *msg, char *type)
@ -67,6 +71,8 @@ XMPPSendMUC(XMPPComponent *comp, char *fr, char *as, char *to, char *msg, char *
return;
}
pthread_mutex_lock(&comp->write_lock);
message = XMLCreateTag("message");
XMLAddAttr(message, "from",
(from = StrConcat(5, fr, "@", comp->host, "/", as)));
@ -86,6 +92,8 @@ XMPPSendMUC(XMPPComponent *comp, char *fr, char *as, char *to, char *msg, char *
XMLFreeElement(message);
Free(from);
Free(id);
pthread_mutex_unlock(&comp->write_lock);
}
void
XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc)
@ -97,6 +105,8 @@ XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc)
return;
}
pthread_mutex_lock(&comp->write_lock);
presence = XMLCreateTag("presence");
x = XMLCreateTag("x");
XMLAddAttr(presence, "from", (from = StrConcat(3, fr, "@", comp->host)));
@ -112,6 +122,8 @@ XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc)
XMLFreeElement(presence);
Free(from);
Free(id);
pthread_mutex_unlock(&comp->write_lock);
}
void
XMPPKillThread(XMPPComponent *jabber, char *killer)
@ -124,6 +136,8 @@ XMPPKillThread(XMPPComponent *jabber, char *killer)
return;
}
pthread_mutex_lock(&jabber->write_lock);
from = StrConcat(3, killer, "@", jabber->host);
message = XMLCreateTag("message");
XMLAddAttr(message, "from", from);
@ -136,6 +150,8 @@ XMPPKillThread(XMPPComponent *jabber, char *killer)
StreamFlush(jabber->stream);
XMLFreeElement(message);
Free(from);
pthread_mutex_unlock(&jabber->write_lock);
}
bool
XMPPIsKiller(XMLElement *stanza)