Yate
yatejabber.h
1
20
21#ifndef __YATEJABBER_H
22#define __YATEJABBER_H
23
24#include <xmpputils.h>
25
29namespace TelEngine {
30
31class SASL; // SASL authentication mechanism
32class JBEvent; // A Jabber event
33class JBStream; // A Jabber stream
34class JBClientStream; // A client to server stream
35class JBServerStream; // A server to server stream
36class JBClusterStream; // A cluster stream
37class JBRemoteDomainDef; // Options and connect settings for a remote domain
38class JBConnect; // A socket connector
39class JBEngine; // A Jabber engine
40class JBServerEngine; // A Jabber server engine
41class JBClientEngine; // A Jabber client engine
42class JBStreamSet; // A set of streams to be processed in an uniform way
43class JBStreamSetProcessor; // Specialized stream processor
44class JBStreamSetReceive; // Specialized stream data receiver
45class JBStreamSetList; // A list of stream sets
46class JBEntityCaps; // Entity capability
47class JBEntityCapsList; // Entity capability list manager
48
49
53#define XMPP_C2S_PORT 5222
54
58#define XMPP_S2S_PORT 5269
59
64#define XMPP_MAX_INCOMPLETEXML 8192
65
66
71class YJABBER_API SASL : public GenObject
72{
73 YCLASS(SASL,GenObject)
74public:
80 SASL(bool plain, const char* realm = 0);
81
86 { TelEngine::destruct(m_params); }
87
93 void setAuthParams(const char* user = 0, const char* pwd = 0);
94
101 bool buildAuthRsp(String& buf, const char* digestUri = 0);
102
108 inline void buildAuthRspReply(String& buf, const String& rsp) {
109 if (m_plain)
110 return;
111 String tmp("rspauth=" + rsp);
112 Base64 b((void*)tmp.c_str(),tmp.length(),false);
113 b.encode(buf);
114 b.clear(false);
115 }
116
122 inline bool validAuthReply(const String& reply) {
123 String tmp;
124 if (m_params)
125 buildMD5Digest(tmp,m_params->getValue("password"),false);
126 return tmp == reply;
127 }
128
136
144 inline void buildMD5Digest(String& dest, const char* password,
145 bool challengeRsp = true) {
146 if (m_params)
147 buildMD5Digest(dest,*m_params,password,challengeRsp);
148 }
149
155 bool parsePlain(const DataBlock& buf);
156
162 bool parseMD5Challenge(const String& buf);
163
170 bool parseMD5ChallengeRsp(const String& buf);
171
181 static bool parsePlain(const DataBlock& buf, String& user, String& pwd,
182 String* authzid = 0);
183
192 static void buildMD5Digest(String& dest, const NamedList& params,
193 const char* password, bool challengeRsp = true);
194
195 bool m_plain;
196 NamedList* m_params;
197 String m_realm;
198 String m_nonce;
199 String m_cnonce;
200 unsigned int m_nonceCount;
201
202private:
203 SASL() {}
204};
205
206
212class YJABBER_API JBEvent : public RefObject
213{
214 YCLASS(JBEvent,RefObject)
215 friend class JBStream;
216 friend class JBClientStream;
217 friend class JBServerStream;
218public:
222 enum Type {
223 // Stream terminated. Try to connect or wait to be destroyed
224 Terminated,
225 // Stream is destroying
226 Destroy,
227 // Stream start was received: when processing this event, the upper
228 // layer must call stream's start() method or terminate the stream
229 Start,
230 // Incoming stream need auth: when processing this event, the upper
231 // layer must call stream's authenticated() method
232 // Component: the event's text contains the handshake data
233 Auth,
234 // The event's element is an 'iq' with a child qualified by bind namespace
235 // This event is generated by an incoming client stream without a bound resource
236 Bind,
237 // Stream is running (can send/recv stanzas)
238 Running,
239 // The event's element is a 'message'
240 Message,
241 // The event's element is a 'presence'
242 Presence,
243 // The event's element is an 'iq'
244 Iq,
245 // The event's element is a 'db:result' one received by a server-to-server stream
246 // containing the dialback key to verify
247 // The event's text is filled with dialback key to verify
248 DbResult,
249 // The event's element is a 'db:verify' one received by a server-to-server stream
250 DbVerify,
251 // New user register or user password change succeeded
252 RegisterOk,
253 // New user register or user password change failed
254 // The event's element is the response
255 RegisterFailed,
256 // Non stanza element received in Running state
257 Unknown
258 };
259
270 const JabberID& from, const JabberID& to, XmlElement* child = 0)
271 : m_type(type), m_stream(0), m_link(true), m_element(element),
272 m_child(child)
273 { init(stream,element,&from,&to); }
274
283 XmlElement* child = 0)
284 : m_type(type), m_stream(0), m_link(true), m_element(element),
285 m_child(child)
286 { init(stream,element); }
287
291 virtual ~JBEvent();
292
297 inline int type() const
298 { return m_type; }
299
304 inline const char* name() const
305 { return lookup(type()); }
306
311 inline const String& stanzaType() const
312 { return m_stanzaType; }
313
318 inline const JabberID& from() const
319 { return m_from; }
320
325 inline const JabberID& to() const
326 { return m_to; }
327
333 inline const String& id() const
334 { return m_id; }
335
340 inline const String& text() const
341 { return m_text; }
342
347 inline JBStream* stream() const
348 { return m_stream; }
349
354 JBClientStream* clientStream();
355
360 JBServerStream* serverStream();
361
367
372 inline XmlElement* element() const
373 { return m_element; }
374
379 inline XmlElement* child() const
380 { return m_child; }
381
388 XmlElement* releaseXml(bool del = false);
389
397
405
416 XmlElement* buildIqError(bool addTags, XMPPError::Type error, const char* reason = 0,
417 XMPPError::ErrorType type = XMPPError::TypeModify);
418
427 bool sendStanzaError(XMPPError::Type error, const char* reason = 0,
428 XMPPError::ErrorType type = XMPPError::TypeModify);
429
434 void releaseStream(bool release = false);
435
440 inline static const char* lookup(int type)
441 { return TelEngine::lookup(type,s_type); }
442
443private:
444 static const TokenDict s_type[]; // Event names
445 JBEvent() {} // Don't use it!
446 bool init(JBStream* stream, XmlElement* element,
447 const JabberID* from = 0, const JabberID* to = 0);
448
449 Type m_type; // Type of this event
450 JBStream* m_stream; // The stream that generated this event
451 bool m_link; // Stream link state
452 XmlElement* m_element; // Received XML element, if any
453 XmlElement* m_child; // The first child element for 'iq' elements
454 String m_stanzaType; // Stanza's 'type' attribute
455 JabberID m_from; // Stanza's 'from' attribute
456 JabberID m_to; // Stanza's 'to' attribute
457 String m_id; // 'id' attribute if the received element has one
458 String m_text; // The stanza's text or termination reason for
459 // Terminated/Destroy events
460};
461
462
468class YJABBER_API JBStream : public RefObject, public DebugEnabler, public Mutex
469{
470 friend class JBEngine;
471 friend class JBEvent;
472public:
476 enum Type {
477 c2s = 0, // Client to server
478 s2s, // Server to server
479 comp, // External component
480 cluster, // Cluster stream
481 TypeCount // Unknown
482 };
483
487 enum State {
488 Idle = 0, // Stream is waiting to be connected or destroyed
489 Connecting, // Outgoing stream is waiting for the socket to connect
490 WaitStart, // Waiting for remote's stream start
491 // (outgoing: stream start already sent)
492 Starting, // Incoming stream is processing a stream start element
493 Features, // Outgoing: waiting for stream features
494 // Incoming: stream features sent
495 WaitTlsRsp, // 'starttls' sent: waiting for response
496 Securing, // Stream is currently negotiating the TLS
497 Auth, // Auth element (db:result for s2s streams) sent
498 // Incoming comp: handshake received
499 Challenge, // 'challenge' element sent/received
500 Compressing, // Stream is negotiating compression
501 // outgoing: compress element sent, wait for response
502 // incoming: waiting for <compressed> element to be sent
503 Register, // A new user is currently registering
504 // Keep Running state here: we expect all other states
505 // (except for Destroy) to have lower values
506 Running, // Established. Allow XML stanzas to pass over the stream
507 Destroy, // Stream is destroying. No more traffic allowed
508 };
509
513 enum Flags {
514 NoAutoRestart = 0x00000001,// Don't restart stream when down
515 TlsRequired = 0x00000002,// TLS is mandatory on this stream
516 AllowPlainAuth = 0x00000004,// Allow plain password authentication
517 // If not allowed and this is the only method
518 // offered by server the stream will be terminated
519 DialbackOnly = 0x00000008,// Outgoing s2s dialback stream
520 RegisterUser = 0x00000010,// Outgoing c2s register new user
521 Compress = 0x00000020,// Offer/handle compression
522 InError = 0x00000080,// The stream was terminated with error
523 // Flags to be managed by the upper layer
524 RosterRequested = 0x00000100,// c2s: the roster was already requested
525 AvailableResource = 0x00000200,// c2s: available presence was sent/received
526 PositivePriority = 0x00000400,// c2s: the resource advertised by the client has priority >= 0
527 // Internal flags (cleared when the stream is re-started)
528 SetCompressed = 0x00010000,// Set StreamCompressed flag after succesfully sending
529 // the current stream xml buffer
530 StreamSecured = 0x00020000,// TLS stage was done (possible without using TLS)
531 StreamTls = 0x00040000,// The stream is using TLS
532 StreamAuthenticated = 0x00080000,// Stream already authenticated
533 StreamRemoteVer1 = 0x00100000,// Remote party advertised RFC3920 version=1.0
534 StreamLocalVer1 = 0x00200000,// Advertise RFC3920 version=1.0 on incoming streams
535 StreamWaitBindRsp = 0x01000000,// Outgoing c2s waiting for bind response
536 StreamWaitSessRsp = 0x02000000,// Outgoing c2s waiting for session response
537 StreamWaitChallenge = 0x04000000,// Outgoing waiting for auth challenge
538 StreamWaitChgRsp = 0x08000000,// Outgoing waiting challenge response confirmation
539 StreamRfc3920Chg = 0x10000000,// Outgoing sent empty response to challenge with rspauth (RFC3920)
540 StreamCompressed = 0x20000000,// The stream is using compression
541 StreamCanCompress = 0x40000000,// Incoming s2s may still be compressed
542 // Flag masks
543 StreamFlags = 0x000000ff,
544 InternalFlags = 0xffff0000,
545 };
546
551 virtual ~JBStream();
552
557 inline int type() const
558 { return m_type; }
559
564 inline int xmlns() const
565 { return m_xmlns; }
566
571 inline State state() const
572 { return m_state; }
573
578 inline bool incoming() const
579 { return m_incoming; }
580
585 inline bool outgoing() const
586 { return !m_incoming; }
587
592 inline JBEngine* engine() const
593 { return m_engine; }
594
599 inline const char* name() const
600 { return m_name; }
601
606 inline const String& id() const
607 { return m_id; }
608
615 inline bool isId(const String& str) {
616 Lock lock(this);
617 return str == m_id;
618 }
619
624 inline const JabberID& local() const
625 { return m_local; }
626
632 inline void local(JabberID& jid) {
633 Lock lock(this);
634 jid = m_local;
635 }
636
641 inline void setLocal(const char* jid)
642 { m_local.set(jid); }
643
648 inline const JabberID& remote() const
649 { return m_remote; }
650
656 inline void remote(JabberID& jid) {
657 Lock lock(this);
658 jid = m_remote;
659 }
660
667 inline bool remoteAddr(SocketAddr& addr) {
668 Lock lock(this);
669 return m_socket && m_socket->getPeerName(addr);
670 }
671
678 inline bool localAddr(SocketAddr& addr) {
679 Lock lock(this);
680 return m_socket && m_socket->getSockName(addr);
681 }
682
687 inline int flags() const
688 { return m_flags; }
689
695 inline bool flag(int mask) const
696 { return 0 != (m_flags & mask); }
697
703 inline void setTlsRequired(bool set) {
704 Lock lock(this);
705 if (set)
706 setFlags(TlsRequired);
707 else
708 resetFlags(TlsRequired);
709 }
710
717 bool haveData();
718
729 void connectAddr(String& addr, int& port, String& localip, int& stat,
730 ObjList& srvs, bool* isRedirect = 0) const;
731
737 inline const String& serverHost() const
738 { return m_serverHost ? m_serverHost : m_remote.domain(); }
739
745 void setRosterRequested(bool ok);
746
754 bool setAvailableResource(bool ok, bool positive = true);
755
763 bool readSocket(char* buf, unsigned int len);
764
770 { return 0; }
771
777 { return 0; }
778
784 { return 0; }
785
792 JBEvent* getEvent(u_int64_t time = Time::msecNow());
793
801
813 bool sendStreamXml(State newState, XmlElement* first, XmlElement* second = 0,
814 XmlElement* third = 0);
815
827 void start(XMPPFeatureList* features = 0, XmlElement* caps = 0, bool useVer1 = true);
828
842 bool authenticated(bool ok, const String& rsp = String::empty(),
843 XMPPError::Type error = XMPPError::NotAuthorized,
844 const char* username = 0, const char* id = 0, const char* resource = 0);
845
860 void terminate(int location, bool destroy, XmlElement* xml,
861 int error = XMPPError::NoError, const char* reason = "",
862 bool final = false, bool genEvent = true, const char* content = 0);
863
869 virtual void connectTerminated(Socket*& sock);
870
879 virtual bool connecting(bool sync, int stat, ObjList& srvs);
880
885 virtual void* getObject(const String& name) const;
886
891 inline const char* stateName() const
892 { return lookup(state(),s_stateName); }
893
898 inline const char* typeName() const
899 { return lookup(type(),s_typeName); }
900
906 inline void buildSha1Digest(String& buf, const String& secret) {
907 SHA1 sha(id() + secret);
908 buf = sha.hexDigest();
909 buf.toLower();
910 }
911
916 virtual const String& toString() const;
917
924 static inline Type lookupType(const char* text, Type defVal = TypeCount)
925 { return (Type)lookup(text,s_typeName,defVal); }
926
931
935 static const TokenDict s_stateName[];
936
940 static const TokenDict s_flagName[];
941
945 static const TokenDict s_typeName[];
946
947protected:
955 JBStream(JBEngine* engine, Socket* socket, Type t, bool ssl = false);
956
967 JBStream(JBEngine* engine, Type t, const JabberID& local, const JabberID& remote,
968 const char* name = 0, const NamedList* params = 0, const char* serverHost = 0);
969
973 virtual void destroyed();
974
982 virtual bool canProcess(u_int64_t time);
983
989 virtual void process(u_int64_t time);
990
998 virtual bool processRunning(XmlElement* xml, const JabberID& from,
999 const JabberID& to);
1000
1007 virtual void checkTimeouts(u_int64_t time);
1008
1014 virtual void resetConnection(Socket* sock = 0);
1015
1021 virtual XmlElement* buildPing(const String& stanzaId);
1022
1028
1036 virtual bool processStart(const XmlElement* xml, const JabberID& from,
1037 const JabberID& to);
1038
1046 virtual bool processAuth(XmlElement* xml, const JabberID& from,
1047 const JabberID& to);
1048
1056 virtual bool processCompressing(XmlElement* xml, const JabberID& from,
1057 const JabberID& to);
1058
1066 virtual bool processRegister(XmlElement* xml, const JabberID& from,
1067 const JabberID& to);
1068
1079
1087
1094
1102 bool getJids(XmlElement* xml, JabberID& from, JabberID& to);
1103
1116
1122 void changeState(State newState, u_int64_t time = Time::msecNow());
1123
1129
1134
1141 bool sendPending(bool streamOnly = false);
1142
1149 bool writeSocket(const void* data, unsigned int& len);
1150
1155
1161
1168 bool dropXml(XmlElement*& xml, const char* reason);
1169
1177 inline bool destroyDropXml(XmlElement*& xml, XMPPError::Type error, const char* reason) {
1178 dropXml(xml,reason);
1179 terminate(0,true,0,error);
1180 return false;
1181 }
1182
1187 void setFlags(int mask);
1188
1193 void resetFlags(int mask);
1194
1198 inline void setSecured() {
1199 setFlags(StreamSecured);
1200 m_features.remove(XMPPNamespace::Tls);
1201 }
1202
1207 void setIdleTimer(u_int64_t msecNow = Time::msecNow());
1208
1213
1221
1228 inline void generateIdIndex(String& buf, const char* extra = 0)
1229 { buf = id() + extra + String(++m_stanzaIndex); }
1230
1231 State m_state; // Stream state
1232 String m_id; // Stream id
1233 JabberID m_local; // Local peer's jid
1234 JabberID m_remote; // Remote peer's jid
1235 String m_serverHost; // Outgoing: optional server host (replaces remote domain when connecting)
1236 int m_flags; // Stream flags
1237 XMPPNamespace::Type m_xmlns; // Stream namespace
1238 XMPPFeatureList m_features; // Advertised features
1239 JBEvent* m_lastEvent; // Last event generated by this stream
1240 ObjList m_events; // Queued events
1241 ObjList m_pending; // Pending outgoing elements
1242 unsigned int m_stanzaIndex; // Index used to generate IDs for stanzas
1243 // Timers
1244 u_int64_t m_setupTimeout; // Overall stream setup timeout
1245 u_int64_t m_startTimeout; // Incoming: wait stream start period
1246 u_int64_t m_pingTimeout; // Sent ping timeout
1247 u_int64_t m_pingInterval; // Ping interval
1248 u_int64_t m_nextPing; // Next ping
1249 u_int64_t m_idleTimeout; // Stream idle timeout
1250 u_int64_t m_connectTimeout; // Stream connect timeout
1251 //
1252 unsigned int m_restart; // Remaining restarts
1253 u_int64_t m_timeToFillRestart; // The next time to increase the restart counter
1254
1255 String m_pingId;
1256
1257private:
1258 // Forbidden default constructor
1259 inline JBStream() {}
1260 // Process incoming elements in Challenge state
1261 // The element will be consumed
1262 // Return false if stream termination was initiated
1263 bool processChallenge(XmlElement* xml, const JabberID& from,
1264 const JabberID& to);
1265 // Process incoming 'auth' elements qualified by SASL namespace
1266 // The element will be consumed
1267 // Return false if stream termination was initiated
1268 bool processSaslAuth(XmlElement* xml, const JabberID& from,
1269 const JabberID& to);
1270 // Process received elements in Features state (incoming stream)
1271 // The element will be consumed
1272 // Return false if stream termination was initiated
1273 bool processFeaturesIn(XmlElement* xml, const JabberID& from,
1274 const JabberID& to);
1275 // Process received elements in Features state (outgoing stream)
1276 // The element will be consumed
1277 // Return false if stream termination was initiated
1278 bool processFeaturesOut(XmlElement* xml, const JabberID& from,
1279 const JabberID& to);
1280 // Process received elements in WaitTlsRsp state (outgoing stream)
1281 // The element will be consumed
1282 // Return false if stream termination was initiated
1283 bool processWaitTlsRsp(XmlElement* xml, const JabberID& from,
1284 const JabberID& to);
1285 // Set stream namespace from type
1286 void setXmlns();
1287 // Event termination notification
1288 // @param event The notifier. Ignored if it's not m_lastEvent
1289 void eventTerminated(const JBEvent* event);
1290 // Compress data to be sent (the pending stream xml buffer or pending stanza)
1291 // Return false on failure
1292 bool compress(XmlElementOut* xml = 0);
1293 // Reset connect status data
1294 void resetConnectStatus();
1295 // Postpone stream terminate until all parsed elements are processed
1296 // Terminate now if allowed
1297 // This method is thread safe
1298 void postponeTerminate(int location, bool destroy, int error, const char* reason);
1299 // Handle postponed termination. Return true if found
1300 // This method is not thread safe
1301 bool postponedTerminate();
1302 // Reset redirect data
1303 void setRedirect(const String& addr = String::empty(), int port = 0);
1304 // Reset postponed terminate data
1305 inline void resetPostponedTerminate() {
1306 m_ppTerminateTimeout = 0;
1307 TelEngine::destruct(m_ppTerminate);
1308 }
1309
1310 enum {
1311 SocketCanRead = 0x01,
1312 SocketReading = 0x02,
1313 SocketCanWrite = 0x10,
1314 SocketWriting = 0x20,
1315 SocketWaitReset = 0x80,
1316 };
1317 inline void socketSetCanRead(bool ok) {
1318 Lock lock(m_socketMutex);
1319 if (ok)
1320 m_socketFlags |= SocketCanRead;
1321 else
1322 m_socketFlags &= ~SocketCanRead;
1323 }
1324 inline void socketSetReading(bool ok) {
1325 if (ok)
1326 m_socketFlags |= SocketReading;
1327 else
1328 m_socketFlags &= ~SocketReading;
1329 }
1330 inline void socketSetCanWrite(bool ok) {
1331 Lock lock(m_socketMutex);
1332 if (ok)
1333 m_socketFlags |= SocketCanWrite;
1334 else
1335 m_socketFlags &= ~SocketCanWrite;
1336 }
1337 inline void socketSetWriting(bool ok) {
1338 if (ok)
1339 m_socketFlags |= SocketWriting;
1340 else
1341 m_socketFlags &= ~SocketWriting;
1342 }
1343 inline bool socketCanRead() const {
1344 return m_socket && (m_socketFlags & SocketCanRead) &&
1345 !socketWaitReset();
1346 }
1347 inline bool socketCanWrite() const {
1348 return m_socket && (m_socketFlags & SocketCanWrite) &&
1349 !socketWaitReset();
1350 }
1351 inline bool socketReading() const
1352 { return (m_socketFlags & SocketReading) != 0; }
1353 inline bool socketWriting() const
1354 { return (m_socketFlags & SocketWriting) != 0; }
1355 inline bool socketWaitReset() const
1356 { return 0 != (m_socketFlags & SocketWaitReset); }
1357
1358 JBEngine* m_engine; // The owner of this stream
1359 int m_type; // Stream type
1360 bool m_incoming; // Stream direction
1361 String m_name; // Local (internal) name
1362 JBEvent* m_terminateEvent; // Pending terminate event
1363 NamedList* m_ppTerminate; // Postponed terminate parameters
1364 u_int64_t m_ppTerminateTimeout; // Postponed terminate timeout
1365 // Pending outgoing XML
1366 String m_outStreamXml;
1367 DataBlock m_outStreamXmlCompress;
1368 DataBlock m_outXmlCompress;
1369 // Connection related data
1370 XmlDomParser* m_xmlDom;
1371 Socket* m_socket;
1372 char m_socketFlags; // Socket flags: 0: unavailable
1373 Mutex m_socketMutex; // Protect the socket and parser
1374 String m_connectAddr; // Remote ip to connect to
1375 int m_connectPort; // Remote port to connect to
1376 String m_localIp; // Local ip to bind when connecting
1377 Compressor* m_compress;
1378 int m_connectStatus; // Current connect stream status
1379 ObjList m_connectSrvs; // Current connect stream SRV records
1380 unsigned int m_redirectMax;
1381 unsigned int m_redirectCount;
1382 String m_redirectAddr;
1383 int m_redirectPort;
1384};
1385
1386
1391class YJABBER_API JBClientStream : public JBStream
1392{
1393 YCLASS(JBClientStream,JBStream)
1394 friend class JBStream;
1395public:
1402 JBClientStream(JBEngine* engine, Socket* socket, bool ssl = false);
1403
1413 JBClientStream(JBEngine* engine, const JabberID& jid, const String& account,
1414 const NamedList& params, const char* name = 0, const char* serverHost = 0);
1415
1420 inline const String& account() const
1421 { return m_account; }
1422
1428 { return m_userData; }
1429
1435 inline void userData(GenObject* data) {
1436 Lock lock(this);
1437 TelEngine::destruct(m_userData);
1438 m_userData = data;
1439 }
1440
1446 { return this; }
1447
1453 virtual XmlElement* buildPing(const String& stanzaId);
1454
1463 void bind(const String& resource, const char* id,
1464 XMPPError::Type error = XMPPError::NoError);
1465
1475 bool requestRegister(bool data, bool set = true,
1476 const String& newPass = String::empty());
1477
1478protected:
1486 virtual bool processRunning(XmlElement* xml, const JabberID& from,
1487 const JabberID& to);
1488
1496 virtual bool processStart(const XmlElement* xml, const JabberID& from,
1497 const JabberID& to);
1498
1506 virtual bool processAuth(XmlElement* xml, const JabberID& from,
1507 const JabberID& to);
1508
1516 virtual bool processRegister(XmlElement* xml, const JabberID& from,
1517 const JabberID& to);
1518
1522 virtual void destroyed();
1523
1529
1534 bool bind();
1535
1536private:
1537 inline bool isRegisterId(XmlElement& xml) {
1538 if (!m_registerReq)
1539 return false;
1540 String* id = xml.getAttribute("id");
1541 return id && id->length() == 1 && (*id)[0] == m_registerReq;
1542 }
1543
1544 String m_account; // Stream account
1545 GenObject* m_userData; // User (upper layer) data
1546 String m_password; // The password
1547 String m_newPassword; // New password
1548 char m_registerReq; // Register requested. 1(data) 2(register) 3(remove)
1549};
1550
1551
1556class YJABBER_API JBServerStream : public JBStream
1557{
1558 YCLASS(JBServerStream,JBStream)
1559 friend class JBStream;
1560public:
1567 JBServerStream(JBEngine* engine, Socket* socket, bool component = false);
1568
1580 const char* dbId = 0, const char* dbKey = 0, bool dbOnly = false,
1581 const NamedList* params = 0);
1582
1592 const String* name = 0, const NamedList* params = 0);
1593
1598 inline bool dialback() const
1599 { return outgoing() && flag(DialbackOnly); }
1600
1606 inline const NamedList& remoteDomains() const
1607 { return m_remoteDomains; }
1608
1616 inline bool hasRemoteDomain(const String& domain, bool auth = true) {
1617 NamedString* tmp = m_remoteDomains.getParam(domain);
1618 return tmp && (!auth || tmp->null());
1619 }
1620
1626 Lock lock(this);
1627 NamedString* tmp = m_dbKey;
1628 m_dbKey = 0;
1629 return tmp;
1630 }
1631
1637 { return this; }
1638
1648 bool sendDbVerify(const char* from, const char* to, const char* id,
1649 XMPPError::Type rsp = XMPPError::NoError);
1650
1660 bool sendDbResult(const JabberID& from, const JabberID& to,
1661 XMPPError::Type rsp = XMPPError::NoError);
1662
1668
1677
1678protected:
1682 virtual void destroyed();
1683
1691 virtual bool processRunning(XmlElement* xml, const JabberID& from,
1692 const JabberID& to);
1693
1699
1707 virtual bool processStart(const XmlElement* xml, const JabberID& from,
1708 const JabberID& to);
1709
1717 virtual bool processAuth(XmlElement* xml, const JabberID& from,
1718 const JabberID& to);
1719
1727 bool processDbResult(XmlElement* xml, const JabberID& from, const JabberID& to);
1728
1734 inline void adjustDbRsp(XMPPError::Type& rsp) {
1735 Lock lock(this);
1736 if (!flag(StreamRemoteVer1) && rsp != XMPPError::NoError)
1737 rsp = XMPPError::NotAuthorized;
1738 }
1739
1745
1746private:
1747 NamedString* m_dbKey; // Outgoing: initial dialback key to check
1748 String m_password; // Outgoing component: password
1749};
1750
1751
1756class YJABBER_API JBClusterStream : public JBStream
1757{
1758 YCLASS(JBClusterStream,JBStream)
1759 friend class JBStream;
1760public:
1766 JBClusterStream(JBEngine* engine, Socket* socket);
1767
1776 const NamedList* params = 0);
1777
1783 { return this; }
1784
1785protected:
1791
1799 virtual bool processStart(const XmlElement* xml, const JabberID& from,
1800 const JabberID& to);
1801
1809 virtual bool processRunning(XmlElement* xml, const JabberID& from,
1810 const JabberID& to);
1811};
1812
1813
1819class YJABBER_API JBRemoteDomainDef : public String
1820{
1822public:
1827 inline JBRemoteDomainDef(const char* domain = 0)
1828 : String(domain), m_port(0), m_flags(0)
1829 {}
1830
1835
1840
1845};
1846
1847
1853class YJABBER_API JBConnect : public GenObject
1854{
1855 YCLASS(JBConnect,GenObject)
1856public:
1857 enum Status {
1858 Start = 0,
1859 Address, // Use configured address
1860 Srv, // Use SRV records
1861 Domain // Use stream remote domain
1862 };
1863
1868 JBConnect(const JBStream& stream);
1869
1873 virtual ~JBConnect();
1874
1878 virtual void stopConnect();
1879
1884 virtual const String& toString() const;
1885
1889 static const TokenDict s_statusName[];
1890
1891protected:
1899 void connect();
1900
1901private:
1902 // No default constructor
1903 inline JBConnect()
1904 {}
1905 // Check if exiting. Release socket if exiting
1906 bool exiting(Socket*& sock);
1907 // Create and try to connect a socket. Return it on success
1908 // Set stop on fatal failure and return 0
1909 Socket* connect(const char* addr, int port, bool& stop);
1910 // Notify termination, remove from engine
1911 void terminated(Socket* sock, bool final);
1912 // Notify connecting to the stream. Return false if stream vanished
1913 bool notifyConnecting(bool sync, bool useCurrentStat = false);
1914 // Delete a socket and zero the pointer
1915 void deleteSocket(Socket*& sock);
1916 // Advance connect status
1917 void advanceStatus();
1918
1919 int m_status; // Current status
1920 String m_domain; // Remote domain
1921 String m_address; // Remote ip address
1922 int m_port; // Port to connect to
1923 JBEngine* m_engine; // The engine owning this connector
1924 String m_stream; // Stream name
1925 JBStream::Type m_streamType; // Stream type
1926 String m_localIp; // Local ip to bind when connecting
1927 ObjList m_srvs; // SRV records list
1928};
1929
1930
1935class YJABBER_API JBEngine : public DebugEnabler, public Mutex, public GenObject
1936{
1937 YCLASS(JBEngine,GenObject)
1938 friend class JBStream;
1939 friend class JBConnect;
1940 friend class JBStreamSetProcessor;
1941public:
1946 JBEngine(const char* name = "jbengine");
1947
1951 virtual ~JBEngine();
1952
1957 inline unsigned int streamReadBuffer() const
1958 { return m_streamReadBuffer; }
1959
1964 inline bool exiting() const
1965 { return m_exiting; }
1966
1970 inline void setExiting() {
1971 if (m_exiting)
1972 return;
1973 m_exiting = true;
1974 dropAll(JBStream::TypeCount,JabberID::empty(),JabberID::empty(),
1975 XMPPError::Shutdown);
1976 }
1977
1982 inline unsigned int redirectMax() const
1983 { return m_redirectMax; }
1984
1989 inline bool hasClientTls() const
1990 { return m_hasClientTls; }
1991
1999 ObjList* o = m_remoteDomains.find(domain);
2000 return o ? static_cast<JBRemoteDomainDef*>(o->get()) : &m_remoteDomain;
2001 }
2002
2006 virtual void destruct();
2007
2012 virtual void initialize(const NamedList& params);
2013
2019 virtual void cleanup(bool final = false, bool waitTerminate = true);
2020
2030 bool acceptConn(Socket* sock, SocketAddr& remote, JBStream::Type t, bool ssl = false);
2031
2038 virtual JBStream* findStream(const String& id,
2039 JBStream::Type hint = JBStream::TypeCount);
2040
2050 ObjList* findClientStreams(bool in, const JabberID& jid, int flags = 0xffffffff);
2051
2063 ObjList* findClientStreams(bool in, const JabberID& jid, const ObjList& resources,
2064 int flags = 0xffffffff);
2065
2074
2084 virtual unsigned int dropAll(JBStream::Type type = JBStream::TypeCount,
2085 const JabberID& local = JabberID::empty(),
2086 const JabberID& remote = JabberID::empty(),
2087 XMPPError::Type error = XMPPError::NoError, const char* reason = 0);
2088
2094 virtual void buildStreamName(String& name, const JBStream* stream)
2095 {}
2096
2102 virtual bool hasDomain(const String& domain)
2103 { return false; }
2104
2110 virtual void processEvent(JBEvent* ev);
2111
2119 virtual void returnEvent(JBEvent* ev, XMPPError::Type error = XMPPError::NoError,
2120 const char* reason = 0);
2121
2126 virtual void encryptStream(JBStream* stream);
2127
2132 virtual void connectStream(JBStream* stream);
2133
2139 virtual void compressStream(JBStream* stream, const String& formats);
2140
2148 virtual void buildDialbackKey(const String& id, const String& local,
2149 const String& remote, String& key);
2150
2156 bool checkDupId(JBStream* stream);
2157
2164 virtual void printXml(const JBStream* stream, bool send, XmlChild& xml) const;
2165
2172 virtual void printXml(const JBStream* stream, bool send, XmlFragment& frag) const;
2173
2174protected:
2179 virtual void addStream(JBStream* stream);
2180
2187 virtual void removeStream(JBStream* stream, bool delObj = true);
2188
2193 virtual void stopStreamSets(bool waitTerminate = true)
2194 {}
2195
2202 virtual void getStreamList(RefPointer<JBStreamSetList>& list, int type)
2203 {}
2204
2211 inline void getStreamLists(RefPointer<JBStreamSetList> list[JBStream::TypeCount],
2212 int type = JBStream::TypeCount) {
2213 if (type == JBStream::c2s || type == JBStream::TypeCount)
2214 getStreamList(list[JBStream::c2s],JBStream::c2s);
2215 if (type == JBStream::s2s || type == JBStream::TypeCount)
2216 getStreamList(list[JBStream::s2s],JBStream::s2s);
2217 if (type == JBStream::comp || type == JBStream::TypeCount)
2218 getStreamList(list[JBStream::comp],JBStream::comp);
2219 if (type == JBStream::cluster || type == JBStream::TypeCount)
2220 getStreamList(list[JBStream::cluster],JBStream::cluster);
2221 }
2222
2229 JBStream* findStream(const String& id, JBStreamSetList* list);
2230
2231 bool m_exiting; // Engine exiting flag
2232 JBRemoteDomainDef m_remoteDomain; // Default remote domain definition
2233 ObjList m_remoteDomains; // Remote domain definitions
2234 unsigned char m_restartMax; // Maximum value for stream restart counter
2235 unsigned int m_restartUpdInterval; // Update interval for stream restart counter
2236 unsigned int m_setupTimeout; // Overall stream setup timeout
2237 unsigned int m_startTimeout; // Wait stream start period
2238 unsigned int m_connectTimeout; // Outgoing: socket connect timeout
2239 unsigned int m_srvTimeout; // SRV query timeout
2240 unsigned int m_pingInterval; // Stream idle interval (no data received)
2241 unsigned int m_pingTimeout; // Sent ping timeout
2242 unsigned int m_idleTimeout; // Stream idle timeout (nothing sent or received)
2243 unsigned int m_pptTimeoutC2s; // Client streams postpone termination intervals
2244 unsigned int m_pptTimeout; // Non client streams postpone stream termination intervals
2245 unsigned int m_streamReadBuffer; // Stream read buffer length
2246 unsigned int m_maxIncompleteXml; // Maximum length of an incomplete xml
2247 unsigned int m_redirectMax; // Max redirect counter for outgoing streams
2248 bool m_hasClientTls; // True if TLS is available for outgoing streams
2249 int m_printXml; // Print XML data to output
2250 bool m_initialized; // True if already initialized
2251
2252private:
2253 // Add/remove a connect stream thread when started/stopped
2254 void connectStatus(JBConnect* conn, bool started);
2255 // Stop a connect stream
2256 void stopConnect(const String& name);
2257
2258 ObjList m_connect; // Connecting streams
2259};
2260
2265class YJABBER_API JBServerEngine : public JBEngine
2266{
2267 YCLASS(JBServerEngine,JBEngine)
2268public:
2273 JBServerEngine(const char* name = "jbserverengine");
2274
2279
2285 virtual void cleanup(bool final = false, bool waitTerminate = true);
2286
2292 virtual void buildStreamName(String& name, const JBStream* stream)
2293 { name << "stream/" << getStreamIndex(); }
2294
2306 JBServerStream* findServerStream(const String& local, const String& remote, bool out,
2307 bool auth = true);
2308
2319 JBServerStream* createServerStream(const String& local, const String& remote,
2320 const char* dbId = 0, const char* dbKey = 0, bool dbOnly = false,
2321 const NamedList* params = 0);
2322
2331 JBServerStream* createCompStream(const String& name, const String& local, const String& remote,
2332 const NamedList* params = 0);
2333
2342
2352 const String& remote, const NamedList* params = 0);
2353
2362 unsigned int terminateClientStreams(const JabberID& jid,
2363 XMPPError::Type error = XMPPError::NoError, const char* reason = 0);
2364
2365protected:
2370 virtual void addStream(JBStream* stream);
2371
2378 virtual void removeStream(JBStream* stream, bool delObj = true);
2379
2384 virtual void stopStreamSets(bool waitTerminate = true);
2385
2391 virtual void getStreamList(RefPointer<JBStreamSetList>& list, int type);
2392
2401
2406 inline unsigned int getStreamIndex() {
2407 Lock lock(this);
2408 return ++m_streamIndex;
2409 }
2410
2411 unsigned int m_streamIndex; // Index used to build stream name
2412 JBStreamSetList* m_c2sReceive; // c2s streams receive list
2413 JBStreamSetList* m_c2sProcess; // c2s streams process list
2414 JBStreamSetList* m_s2sReceive; // s2s streams receive list
2415 JBStreamSetList* m_s2sProcess; // s2s streams process list
2416 JBStreamSetList* m_compReceive; // comp streams receive list
2417 JBStreamSetList* m_compProcess; // comp streams process list
2418 JBStreamSetList* m_clusterReceive; // cluster streams receive list
2419 JBStreamSetList* m_clusterProcess; // cluster streams process list
2420};
2421
2426class YJABBER_API JBClientEngine : public JBEngine
2427{
2428 YCLASS(JBClientEngine,JBEngine)
2429public:
2434 JBClientEngine(const char* name = "jbclientengine");
2435
2440
2446 virtual void cleanup(bool final = false, bool waitTerminate = true);
2447
2454
2462 JBClientStream* create(const String& account, const NamedList& params,
2463 const String& name = String::empty());
2464
2470 virtual void getStreamList(RefPointer<JBStreamSetList>& list, int type);
2471
2472protected:
2477 virtual void addStream(JBStream* stream);
2478
2485 virtual void removeStream(JBStream* stream, bool delObj = true);
2486
2491 virtual void stopStreamSets(bool waitTerminate = true);
2492
2493 JBStreamSetList* m_receive; // Streams receive list
2494 JBStreamSetList* m_process; // Streams process list
2495};
2496
2503class YJABBER_API JBStreamSet : public GenObject, public Mutex
2504{
2505 YCLASS(JBStreamSet,GenObject);
2506 friend class JBStreamSetList;
2507public:
2511 virtual ~JBStreamSet();
2512
2519 { return m_clients; }
2520
2527 virtual bool add(JBStream* client);
2528
2536 virtual bool remove(JBStream* client, bool delObj = true);
2537
2546 unsigned int dropAll(const JabberID& local = JabberID::empty(),
2547 const JabberID& remote = JabberID::empty(),
2548 XMPPError::Type error = XMPPError::NoError, const char* reason = 0);
2549
2554 void run();
2555
2560 virtual bool start();
2561
2565 virtual void stop();
2566
2567protected:
2572 JBStreamSet(JBStreamSetList* owner);
2573
2581 virtual bool process(JBStream& stream) = 0;
2582
2583 bool m_changed; // List changed flag
2584 bool m_exiting; // The thread is exiting (don't accept clients)
2585 JBStreamSetList* m_owner; // The list owning this set
2586 ObjList m_clients; // The streams list
2587
2588private:
2589 JBStreamSet() {} // Private default constructor (forbidden)
2590};
2591
2592
2597class YJABBER_API JBStreamSetProcessor : public JBStreamSet
2598{
2600protected:
2605 inline JBStreamSetProcessor(JBStreamSetList* owner)
2607 {}
2608
2617 virtual bool process(JBStream& stream);
2618};
2619
2620
2625class YJABBER_API JBStreamSetReceive : public JBStreamSet
2626{
2628protected:
2633 JBStreamSetReceive(JBStreamSetList* owner);
2634
2642 virtual bool process(JBStream& stream);
2643
2644protected:
2645 DataBlock m_buffer; // Read buffer
2646};
2647
2648
2654class YJABBER_API JBStreamSetList : public RefObject, public Mutex
2655{
2656 YCLASS(JBStreamSetList,RefObject);
2657 friend class JBStreamSet;
2658public:
2666 JBStreamSetList(JBEngine* engine, unsigned int max, unsigned int sleepMs,
2667 const char* name);
2668
2674 inline ObjList& sets()
2675 { return m_sets; }
2676
2681
2686 inline unsigned int maxStreams() const
2687 { return m_max; }
2688
2693 inline unsigned int streamCount() const
2694 { return m_streamCount; }
2695
2700 inline JBEngine* engine() const
2701 { return m_engine; }
2702
2708 bool add(JBStream* client);
2709
2716 void remove(JBStream* client, bool delObj = true);
2717
2723 void stop(JBStreamSet* set = 0, bool waitTerminate = true);
2724
2729 virtual const String& toString() const;
2730
2731protected:
2735 virtual void destroyed();
2736
2741 void remove(JBStreamSet* set);
2742
2747 virtual JBStreamSet* build();
2748
2749 JBEngine* m_engine; // The engine owning this list
2750 String m_name; // List name
2751 unsigned int m_max; // The maximum number of streams per set
2752 unsigned int m_sleepMs; // Time to sleep if nothig processed
2753 ObjList m_sets; // The sets list
2754
2755private:
2756 JBStreamSetList() {} // Private default constructor (forbidden)
2757
2758 unsigned int m_streamCount; // Current number of streams in this list
2759};
2760
2761
2767class YJABBER_API JBEntityCaps : public String
2768{
2769 YCLASS(JBEntityCaps,String);
2770public:
2774 enum {
2775 Ver1_3 = 1, // Version lower then 1.4 (m_data is the node version + advertised extensions)
2776 Ver1_4 = 2, // Version 1.4 or greater (m_data is the SHA-1 hash of features and identities)
2777 };
2778
2786 inline JBEntityCaps(const char* id, char version, const char* node, const char* data)
2787 : String(id),
2788 m_version(version), m_node(node), m_data(data)
2789 {}
2790
2796 inline bool hasFeature(int ns)
2797 { return 0 != m_features.get(ns); }
2798
2803 inline bool hasAudio() {
2804 return hasFeature(XMPPNamespace::JingleAppsRtpAudio) ||
2805 hasFeature(XMPPNamespace::JingleAudio) ||
2806 hasFeature(XMPPNamespace::JingleVoiceV1);
2807 }
2808
2817 static inline void buildId(String& buf, char version, const char* node,
2818 const char* data, String* ext = 0)
2819 { buf << (int)version << node << data << (ext ? ext->c_str() : ""); }
2820
2821 char m_version;
2822 String m_node;
2823 String m_data;
2824 XMPPFeatureList m_features;
2825
2826private:
2827 JBEntityCaps() {}
2828};
2829
2830
2836class YJABBER_API JBEntityCapsList : public ObjList, public Mutex
2837{
2838 YCLASS(JBEntityCapsList,ObjList);
2839public:
2844 : Mutex(true,"JBEntityCapsList"), m_enable(true), m_reqIndex(0)
2845 { m_reqPrefix << "xep0115" << (unsigned int)Time::msecNow() << "_"; }
2846
2852 inline JBEntityCaps* findCaps(const String& id) {
2853 for (ObjList* o = skipNull(); o; o = o->skipNext())
2854 if (o->get()->toString() == id)
2855 return static_cast<JBEntityCaps*>(o->get());
2856 return 0;
2857 }
2858
2864 void expire(u_int64_t msecNow = Time::msecNow());
2865
2874 bool processRsp(XmlElement* rsp, const String& id, bool ok);
2875
2887 void requestCaps(JBStream* stream, const char* from, const char* to, const String& id,
2888 char version, const char* node, const char* data);
2889
2896 XmlDocument* toDocument(const char* rootName = "entitycaps");
2897
2905 void fromDocument(XmlDocument& doc, const char* rootName = "entitycaps");
2906
2919 virtual bool processCaps(String& capsId, XmlElement* xml, JBStream* stream,
2920 const char* from, const char* to);
2921
2928 inline void addCaps(NamedList& list, const String& id) {
2929 Lock lock(this);
2930 JBEntityCaps* caps = findCaps(id);
2931 if (caps)
2932 addCaps(list,*caps);
2933 }
2934
2941 virtual void addCaps(NamedList& list, JBEntityCaps& caps);
2942
2950 bool loadXmlDoc(const char* file, DebugEnabler* enabler = 0);
2951
2959 bool saveXmlDoc(const char* file, DebugEnabler* enabler = 0);
2960
2970 static bool decodeCaps(const XmlElement& xml, char& version, String*& node,
2971 String*& ver, String*& ext);
2972
2977
2978protected:
2984 virtual void capsAdded(JBEntityCaps* caps)
2985 {}
2986
2987 unsigned int m_reqIndex; // Disco info request index
2988 String m_reqPrefix; // Prefix for disco info stanza id
2989 ObjList m_requests; // List of sent disco info requests
2990};
2991
2992}; // namespace TelEngine
2993
2994#endif /* __YATEJABBER_H */
2995
2996/* vi: set ts=8 sw=4 sts=4 noet: */
Base64 encoder/decoder class.
Definition yateclass.h:4947
void encode(String &dest, unsigned int lineLen=0, bool lineAtEnd=false)
A class that holds just a block of raw data.
Definition yateclass.h:4237
void clear(bool deleteData=true)
A holder for a debug level.
Definition yateclass.h:312
DebugEnabler(int level=TelEngine::debugLevel(), bool enabled=true)
Definition yateclass.h:319
Definition yateclass.h:1049
const String & hexDigest()
Definition yateclass.h:4529
A Jabber ID.
Definition xmpputils.h:429
static const JabberID & empty()
Ephemeral mutex or semaphore locking object.
Definition yateclass.h:5833
Mutex(bool recursive=false, const char *name=0)
const char * owner() const
virtual bool lock(long maxwait=-1)
A named string container class.
Definition yateclass.h:5016
A named string class.
Definition yateclass.h:3481
An object list class.
Definition yateclass.h:1454
ObjList * find(const GenObject *obj) const
ObjList * skipNull() const
ObjList * skipNext() const
GenObject * get() const
Definition yateclass.h:1490
Templated smart pointer class.
Definition yateclass.h:1306
A standard SHA1 digest calculator.
Definition yateclass.h:4763
A socket address holder.
Definition yateclass.h:6400
A generic socket class.
Definition yateclass.h:7361
A C-style string handling class.
Definition yateclass.h:2131
const char * c_str() const
Definition yateclass.h:2236
bool null() const
Definition yateclass.h:2265
String & toLower()
static const String & empty()
unsigned int length() const
Definition yateclass.h:2258
A Jabber client engine.
Definition yatejabber.h:2427
virtual void stopStreamSets(bool waitTerminate=true)
virtual void addStream(JBStream *stream)
JBClientStream * create(const String &account, const NamedList &params, const String &name=String::empty())
JBClientEngine(const char *name="jbclientengine")
virtual void removeStream(JBStream *stream, bool delObj=true)
virtual void getStreamList(RefPointer< JBStreamSetList > &list, int type)
JBClientStream * findAccount(const String &account)
virtual void cleanup(bool final=false, bool waitTerminate=true)
A client to server stream.
Definition yatejabber.h:1392
void userData(GenObject *data)
Definition yatejabber.h:1435
virtual JBClientStream * clientStream()
Definition yatejabber.h:1445
virtual void destroyed()
virtual bool processStart(const XmlElement *xml, const JabberID &from, const JabberID &to)
JBClientStream(JBEngine *engine, const JabberID &jid, const String &account, const NamedList &params, const char *name=0, const char *serverHost=0)
virtual XmlElement * buildPing(const String &stanzaId)
void bind(const String &resource, const char *id, XMPPError::Type error=XMPPError::NoError)
virtual bool processRunning(XmlElement *xml, const JabberID &from, const JabberID &to)
virtual bool processAuth(XmlElement *xml, const JabberID &from, const JabberID &to)
JBClientStream(JBEngine *engine, Socket *socket, bool ssl=false)
bool requestRegister(bool data, bool set=true, const String &newPass=String::empty())
GenObject * userData()
Definition yatejabber.h:1427
virtual bool processRegister(XmlElement *xml, const JabberID &from, const JabberID &to)
const String & account() const
Definition yatejabber.h:1420
A cluster stream.
Definition yatejabber.h:1757
virtual JBClusterStream * clusterStream()
Definition yatejabber.h:1782
virtual bool processStart(const XmlElement *xml, const JabberID &from, const JabberID &to)
JBClusterStream(JBEngine *engine, Socket *socket)
virtual bool processRunning(XmlElement *xml, const JabberID &from, const JabberID &to)
virtual XmlElement * buildStreamStart()
JBClusterStream(JBEngine *engine, const JabberID &local, const JabberID &remote, const NamedList *params=0)
A socket connector.
Definition yatejabber.h:1854
virtual void stopConnect()
JBConnect(const JBStream &stream)
virtual const String & toString() const
static const TokenDict s_statusName[]
Definition yatejabber.h:1889
A Jabber engine.
Definition yatejabber.h:1936
virtual void stopStreamSets(bool waitTerminate=true)
Definition yatejabber.h:2193
virtual bool hasDomain(const String &domain)
Definition yatejabber.h:2102
bool hasClientTls() const
Definition yatejabber.h:1989
virtual void printXml(const JBStream *stream, bool send, XmlChild &xml) const
virtual unsigned int dropAll(JBStream::Type type=JBStream::TypeCount, const JabberID &local=JabberID::empty(), const JabberID &remote=JabberID::empty(), XMPPError::Type error=XMPPError::NoError, const char *reason=0)
virtual void addStream(JBStream *stream)
ObjList * findClientStreams(bool in, const JabberID &jid, int flags=0xffffffff)
JBEngine(const char *name="jbengine")
void getStreamLists(RefPointer< JBStreamSetList > list[JBStream::TypeCount], int type=JBStream::TypeCount)
Definition yatejabber.h:2211
JBRemoteDomainDef * remoteDomainDef(const String &domain)
Definition yatejabber.h:1998
bool checkDupId(JBStream *stream)
bool acceptConn(Socket *sock, SocketAddr &remote, JBStream::Type t, bool ssl=false)
bool exiting() const
Definition yatejabber.h:1964
virtual void processEvent(JBEvent *ev)
virtual void destruct()
virtual void connectStream(JBStream *stream)
void setExiting()
Definition yatejabber.h:1970
ObjList * findClientStreams(bool in, const JabberID &jid, const ObjList &resources, int flags=0xffffffff)
virtual void removeStream(JBStream *stream, bool delObj=true)
virtual void returnEvent(JBEvent *ev, XMPPError::Type error=XMPPError::NoError, const char *reason=0)
virtual void getStreamList(RefPointer< JBStreamSetList > &list, int type)
Definition yatejabber.h:2202
unsigned int redirectMax() const
Definition yatejabber.h:1982
virtual void encryptStream(JBStream *stream)
virtual void buildDialbackKey(const String &id, const String &local, const String &remote, String &key)
virtual void compressStream(JBStream *stream, const String &formats)
virtual void buildStreamName(String &name, const JBStream *stream)
Definition yatejabber.h:2094
virtual void initialize(const NamedList &params)
JBStream * findStream(const String &id, JBStreamSetList *list)
JBClientStream * findClientStream(bool in, const JabberID &jid)
unsigned int streamReadBuffer() const
Definition yatejabber.h:1957
virtual JBStream * findStream(const String &id, JBStream::Type hint=JBStream::TypeCount)
virtual void printXml(const JBStream *stream, bool send, XmlFragment &frag) const
virtual void cleanup(bool final=false, bool waitTerminate=true)
Entity capability list manager.
Definition yatejabber.h:2837
void requestCaps(JBStream *stream, const char *from, const char *to, const String &id, char version, const char *node, const char *data)
JBEntityCaps * findCaps(const String &id)
Definition yatejabber.h:2852
void expire(u_int64_t msecNow=Time::msecNow())
bool m_enable
Definition yatejabber.h:2976
XmlDocument * toDocument(const char *rootName="entitycaps")
virtual void capsAdded(JBEntityCaps *caps)
Definition yatejabber.h:2984
void addCaps(NamedList &list, const String &id)
Definition yatejabber.h:2928
bool processRsp(XmlElement *rsp, const String &id, bool ok)
bool saveXmlDoc(const char *file, DebugEnabler *enabler=0)
void fromDocument(XmlDocument &doc, const char *rootName="entitycaps")
JBEntityCapsList()
Definition yatejabber.h:2843
static bool decodeCaps(const XmlElement &xml, char &version, String *&node, String *&ver, String *&ext)
bool loadXmlDoc(const char *file, DebugEnabler *enabler=0)
virtual bool processCaps(String &capsId, XmlElement *xml, JBStream *stream, const char *from, const char *to)
virtual void addCaps(NamedList &list, JBEntityCaps &caps)
Entity capability.
Definition yatejabber.h:2768
bool hasFeature(int ns)
Definition yatejabber.h:2796
static void buildId(String &buf, char version, const char *node, const char *data, String *ext=0)
Definition yatejabber.h:2817
JBEntityCaps(const char *id, char version, const char *node, const char *data)
Definition yatejabber.h:2786
bool hasAudio()
Definition yatejabber.h:2803
A Jabber stream event.
Definition yatejabber.h:213
JBEvent(Type type, JBStream *stream, XmlElement *element, const JabberID &from, const JabberID &to, XmlElement *child=0)
Definition yatejabber.h:269
const JabberID & to() const
Definition yatejabber.h:325
Type
Definition yatejabber.h:222
JBClusterStream * clusterStream()
static const char * lookup(int type)
Definition yatejabber.h:440
const String & stanzaType() const
Definition yatejabber.h:311
JBClientStream * clientStream()
XmlElement * releaseXml(bool del=false)
const String & id() const
Definition yatejabber.h:333
XmlElement * element() const
Definition yatejabber.h:372
XmlElement * child() const
Definition yatejabber.h:379
const char * name() const
Definition yatejabber.h:304
XmlElement * buildIqError(bool addTags, XMPPError::Type error, const char *reason=0, XMPPError::ErrorType type=XMPPError::TypeModify)
bool sendStanzaError(XMPPError::Type error, const char *reason=0, XMPPError::ErrorType type=XMPPError::TypeModify)
XmlElement * buildIqResult(bool addTags, XmlElement *child=0)
const String & text() const
Definition yatejabber.h:340
JBServerStream * serverStream()
JBEvent(Type type, JBStream *stream, XmlElement *element, XmlElement *child=0)
Definition yatejabber.h:282
int type() const
Definition yatejabber.h:297
JBStream * stream() const
Definition yatejabber.h:347
bool sendIqResult(XmlElement *child=0)
void releaseStream(bool release=false)
const JabberID & from() const
Definition yatejabber.h:318
Options and connect settings for a remote domain.
Definition yatejabber.h:1820
int m_port
Definition yatejabber.h:1839
JBRemoteDomainDef(const char *domain=0)
Definition yatejabber.h:1827
int m_flags
Definition yatejabber.h:1844
String m_address
Definition yatejabber.h:1834
A Jabber server engine.
Definition yatejabber.h:2266
virtual void stopStreamSets(bool waitTerminate=true)
JBClusterStream * findClusterStream(const String &remote, JBClusterStream *skip=0)
unsigned int terminateClientStreams(const JabberID &jid, XMPPError::Type error=XMPPError::NoError, const char *reason=0)
virtual void addStream(JBStream *stream)
virtual void getStreamListsType(int type, RefPointer< JBStreamSetList > &recv, RefPointer< JBStreamSetList > &process)
JBServerEngine(const char *name="jbserverengine")
unsigned int getStreamIndex()
Definition yatejabber.h:2406
JBServerStream * createCompStream(const String &name, const String &local, const String &remote, const NamedList *params=0)
virtual JBClusterStream * createClusterStream(const String &local, const String &remote, const NamedList *params=0)
JBServerStream * findServerStream(const String &local, const String &remote, bool out, bool auth=true)
virtual void removeStream(JBStream *stream, bool delObj=true)
virtual void getStreamList(RefPointer< JBStreamSetList > &list, int type)
JBServerStream * createServerStream(const String &local, const String &remote, const char *dbId=0, const char *dbKey=0, bool dbOnly=false, const NamedList *params=0)
virtual void buildStreamName(String &name, const JBStream *stream)
Definition yatejabber.h:2292
virtual void cleanup(bool final=false, bool waitTerminate=true)
A server to server stream.
Definition yatejabber.h:1557
NamedList m_remoteDomains
Definition yatejabber.h:1744
virtual void destroyed()
virtual bool processStart(const XmlElement *xml, const JabberID &from, const JabberID &to)
JBServerStream(JBEngine *engine, const JabberID &local, const JabberID &remote, const String *name=0, const NamedList *params=0)
const NamedList & remoteDomains() const
Definition yatejabber.h:1606
bool processDbResult(XmlElement *xml, const JabberID &from, const JabberID &to)
bool sendDbResult(const JabberID &from, const JabberID &to, XMPPError::Type rsp=XMPPError::NoError)
bool hasRemoteDomain(const String &domain, bool auth=true)
Definition yatejabber.h:1616
bool dialback() const
Definition yatejabber.h:1598
virtual bool processRunning(XmlElement *xml, const JabberID &from, const JabberID &to)
JBServerStream(JBEngine *engine, Socket *socket, bool component=false)
bool startComp(const String &local=String::empty(), const String &remote=String::empty())
virtual XmlElement * buildStreamStart()
virtual bool processAuth(XmlElement *xml, const JabberID &from, const JabberID &to)
void adjustDbRsp(XMPPError::Type &rsp)
Definition yatejabber.h:1734
JBServerStream(JBEngine *engine, const JabberID &local, const JabberID &remote, const char *dbId=0, const char *dbKey=0, bool dbOnly=false, const NamedList *params=0)
NamedString * takeDb()
Definition yatejabber.h:1625
bool sendDbVerify(const char *from, const char *to, const char *id, XMPPError::Type rsp=XMPPError::NoError)
virtual JBServerStream * serverStream()
Definition yatejabber.h:1636
A list of stream sets.
Definition yatejabber.h:2655
JBEngine * engine() const
Definition yatejabber.h:2700
JBStreamSetList(JBEngine *engine, unsigned int max, unsigned int sleepMs, const char *name)
virtual JBStreamSet * build()
bool add(JBStream *client)
unsigned int streamCount() const
Definition yatejabber.h:2693
unsigned int maxStreams() const
Definition yatejabber.h:2686
virtual const String & toString() const
void stop(JBStreamSet *set=0, bool waitTerminate=true)
ObjList & sets()
Definition yatejabber.h:2674
void remove(JBStream *client, bool delObj=true)
void remove(JBStreamSet *set)
Specialized stream processor.
Definition yatejabber.h:2598
virtual bool process(JBStream &stream)
JBStreamSetProcessor(JBStreamSetList *owner)
Definition yatejabber.h:2605
Specialized stream data receiver.
Definition yatejabber.h:2626
virtual bool process(JBStream &stream)
JBStreamSetReceive(JBStreamSetList *owner)
A set of streams to be processed in an uniform way.
Definition yatejabber.h:2504
virtual bool remove(JBStream *client, bool delObj=true)
virtual bool start()
ObjList & clients()
Definition yatejabber.h:2518
JBStreamSet(JBStreamSetList *owner)
virtual bool add(JBStream *client)
unsigned int dropAll(const JabberID &local=JabberID::empty(), const JabberID &remote=JabberID::empty(), XMPPError::Type error=XMPPError::NoError, const char *reason=0)
virtual bool process(JBStream &stream)=0
virtual void stop()
A Jabber stream.
Definition yatejabber.h:469
JBEngine * engine() const
Definition yatejabber.h:592
JBStream(JBEngine *engine, Socket *socket, Type t, bool ssl=false)
void start(XMPPFeatureList *features=0, XmlElement *caps=0, bool useVer1=true)
virtual void * getObject(const String &name) const
virtual bool processCompressing(XmlElement *xml, const JabberID &from, const JabberID &to)
static const TokenDict s_typeName[]
Definition yatejabber.h:945
Type
Definition yatejabber.h:476
const String & serverHost() const
Definition yatejabber.h:737
void setSecured()
Definition yatejabber.h:1198
virtual JBClientStream * clientStream()
Definition yatejabber.h:769
void setIdleTimer(u_int64_t msecNow=Time::msecNow())
virtual JBClusterStream * clusterStream()
Definition yatejabber.h:783
void connectAddr(String &addr, int &port, String &localip, int &stat, ObjList &srvs, bool *isRedirect=0) const
virtual void destroyed()
void setLocal(const char *jid)
Definition yatejabber.h:641
void terminate(int location, bool destroy, XmlElement *xml, int error=XMPPError::NoError, const char *reason="", bool final=false, bool genEvent=true, const char *content=0)
void resetFlags(int mask)
virtual bool processStart(const XmlElement *xml, const JabberID &from, const JabberID &to)
bool readSocket(char *buf, unsigned int len)
bool authenticated(bool ok, const String &rsp=String::empty(), XMPPError::Type error=XMPPError::NotAuthorized, const char *username=0, const char *id=0, const char *resource=0)
bool destroyDropXml(XmlElement *&xml, XMPPError::Type error, const char *reason)
Definition yatejabber.h:1177
bool sendStanza(XmlElement *&xml)
void local(JabberID &jid)
Definition yatejabber.h:632
bool writeSocket(const void *data, unsigned int &len)
const JabberID & remote() const
Definition yatejabber.h:648
virtual bool canProcess(u_int64_t time)
const char * typeName() const
Definition yatejabber.h:898
const char * stateName() const
Definition yatejabber.h:891
XmlElement * checkCompress()
const String & id() const
Definition yatejabber.h:606
State
Definition yatejabber.h:487
bool streamError(XmlElement *xml)
void setTlsRequired(bool set)
Definition yatejabber.h:703
bool isId(const String &str)
Definition yatejabber.h:615
JBStream(JBEngine *engine, Type t, const JabberID &local, const JabberID &remote, const char *name=0, const NamedList *params=0, const char *serverHost=0)
virtual void connectTerminated(Socket *&sock)
virtual XmlElement * buildPing(const String &stanzaId)
void buildSha1Digest(String &buf, const String &secret)
Definition yatejabber.h:906
const char * name() const
Definition yatejabber.h:599
void setRosterRequested(bool ok)
virtual bool processRunning(XmlElement *xml, const JabberID &from, const JabberID &to)
bool setAvailableResource(bool ok, bool positive=true)
const JabberID & local() const
Definition yatejabber.h:624
virtual const String & toString() const
virtual void resetConnection(Socket *sock=0)
void changeState(State newState, u_int64_t time=Time::msecNow())
bool processStreamStart(const XmlElement *xml)
SASL * m_sasl
Definition yatejabber.h:930
virtual void process(u_int64_t time)
void remote(JabberID &jid)
Definition yatejabber.h:656
int flags() const
Definition yatejabber.h:687
Flags
Definition yatejabber.h:513
XmlElement * setNextPing(bool force)
bool sendStreamXml(State newState, XmlElement *first, XmlElement *second=0, XmlElement *third=0)
bool sendPending(bool streamOnly=false)
bool remoteAddr(SocketAddr &addr)
Definition yatejabber.h:667
virtual XmlElement * buildStreamStart()
bool localAddr(SocketAddr &addr)
Definition yatejabber.h:678
static const TokenDict s_flagName[]
Definition yatejabber.h:940
virtual void checkTimeouts(u_int64_t time)
virtual bool processAuth(XmlElement *xml, const JabberID &from, const JabberID &to)
bool flag(int mask) const
Definition yatejabber.h:695
bool getJids(XmlElement *xml, JabberID &from, JabberID &to)
JBEvent * getEvent(u_int64_t time=Time::msecNow())
int type() const
Definition yatejabber.h:557
bool dropXml(XmlElement *&xml, const char *reason)
virtual bool connecting(bool sync, int stat, ObjList &srvs)
bool incoming() const
Definition yatejabber.h:578
State state() const
Definition yatejabber.h:571
void generateIdIndex(String &buf, const char *extra=0)
Definition yatejabber.h:1228
int xmlns() const
Definition yatejabber.h:564
bool handleCompressReq(XmlElement *xml)
static const TokenDict s_stateName[]
Definition yatejabber.h:935
void setFlags(int mask)
XMPPFeature * firstRequiredFeature()
bool outgoing() const
Definition yatejabber.h:585
bool checkStanzaRecv(XmlElement *xml, JabberID &from, JabberID &to)
static Type lookupType(const char *text, Type defVal=TypeCount)
Definition yatejabber.h:924
virtual JBServerStream * serverStream()
Definition yatejabber.h:776
virtual bool processRegister(XmlElement *xml, const JabberID &from, const JabberID &to)
SASL authentication mechanism.
Definition yatejabber.h:72
void setAuthParams(const char *user=0, const char *pwd=0)
bool parseMD5ChallengeRsp(const String &buf)
void buildAuthRspReply(String &buf, const String &rsp)
Definition yatejabber.h:108
bool parsePlain(const DataBlock &buf)
SASL(bool plain, const char *realm=0)
static bool parsePlain(const DataBlock &buf, String &user, String &pwd, String *authzid=0)
static void buildMD5Digest(String &dest, const NamedList &params, const char *password, bool challengeRsp=true)
bool parseMD5Challenge(const String &buf)
bool validAuthReply(const String &reply)
Definition yatejabber.h:122
bool buildMD5Challenge(String &buf)
bool buildAuthRsp(String &buf, const char *digestUri=0)
void buildMD5Digest(String &dest, const char *password, bool challengeRsp=true)
Definition yatejabber.h:144
~SASL()
Definition yatejabber.h:85
Xml Child.
Definition yatexml.h:727
Xml Document.
Definition yatexml.h:980
Xml Element.
Definition yatexml.h:1137
String * getAttribute(const String &name) const
Definition yatexml.h:1516
Xml Fragment.
Definition yatexml.h:857
static u_int64_t msecNow()
Type
Definition xmpputils.h:220
ErrorType
Definition xmpputils.h:286
JID feature list.
Definition xmpputils.h:913
A feature.
Definition xmpputils.h:734
Type
Definition xmpputils.h:130
An outgoing XML element.
Definition xmpputils.h:2293
Definition yatemime.h:34
Definition yateclass.h:848