mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:55:10 +00:00
[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:
parent
42d69226f0
commit
37155316b2
4 changed files with 32 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue