Overview
Comment: | Adjust to ObjFW changes |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ffbc5cb529282a3f8920efe47dd72bbc |
User & Date: | js on 2018-12-22 20:59:02 |
Other Links: | manifest | tags |
Context
2019-01-20
| ||
12:38 | Make use of objfw-config's new package support check-in: 874510053a user: js tags: trunk | |
2018-12-22
| ||
20:59 | Adjust to ObjFW changes check-in: ffbc5cb529 user: js tags: trunk | |
2018-11-11
| ||
19:13 | Add MUC namespace check-in: 5a6c7fcfb8 user: js tags: trunk | |
Changes
Modified src/XMPPConnection.h from [4fbe933481] to [8e9ce8e74b].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import <ObjFW/ObjFW.h> #import "XMPPCallback.h" #import "XMPPStorage.h" OF_ASSUME_NONNULL_BEGIN @class XMPPConnection; @class XMPPJID; @class XMPPIQ; @class XMPPMessage; @class XMPPPresence; @class XMPPAuthenticator; @class SSLSocket; | > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #import <ObjFW/ObjFW.h> #import "XMPPCallback.h" #import "XMPPStorage.h" OF_ASSUME_NONNULL_BEGIN #define XMPP_CONNECTION_BUFFER_LENGTH 512 @class XMPPConnection; @class XMPPJID; @class XMPPIQ; @class XMPPMessage; @class XMPPPresence; @class XMPPAuthenticator; @class SSLSocket; |
︙ | ︙ | |||
106 107 108 109 110 111 112 113 | - (void)connection: (XMPPConnection *)connection didReceiveMessage: (XMPPMessage *)message; /*! * @brief This callback is called when the connection was closed. * * @param connection The connection that was closed */ | > | > | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | - (void)connection: (XMPPConnection *)connection didReceiveMessage: (XMPPMessage *)message; /*! * @brief This callback is called when the connection was closed. * * @param connection The connection that was closed * @param error The error XML element the stream encountered or nil */ - (void)connectionWasClosed: (XMPPConnection *)connection error: (nullable OFXMLElement *)error; /*! * @brief This callback is called when the connection threw an exception. * * @param connection The connection which threw an exception * @param exception The exception the connection threw */ |
︙ | ︙ | |||
137 138 139 140 141 142 143 | */ - (void)connectionDidUpgradeToTLS: (XMPPConnection *)connection; @end /*! * @brief A class which abstracts a connection to an XMPP service. */ | | < > > | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | */ - (void)connectionDidUpgradeToTLS: (XMPPConnection *)connection; @end /*! * @brief A class which abstracts a connection to an XMPP service. */ @interface XMPPConnection: OFObject { OF_KINDOF(OFTCPSocket *) _socket; char _buffer[XMPP_CONNECTION_BUFFER_LENGTH]; OFXMLParser *_parser, *_oldParser; OFXMLElementBuilder *_elementBuilder, *_oldElementBuilder; OFString *_Nullable _username, *_Nullable _password, *_Nullable _server; OFString *_Nullable _resource; bool _usesAnonymousAuthentication; OFString *_Nullable _privateKeyFile, *_Nullable _certificateFile; const char *_Nullable _privateKeyPassphrase; OFString *_Nullable _domain, *_Nullable _domainToASCII; XMPPJID *_Nullable _JID; uint16_t _port; id <XMPPStorage> _Nullable _dataStorage; OFString *_Nullable _language; OFMutableArray *_nextSRVRecords; XMPPMulticastDelegate *_delegates; OFMutableDictionary OF_GENERIC(OFString *, XMPPCallback *) *_callbacks; XMPPAuthenticator *_authModule; bool _streamOpen, _needsSession, _encryptionRequired, _encrypted; bool _supportsRosterVersioning, _supportsStreamManagement; unsigned int _lastID; } |
︙ | ︙ |
Modified src/XMPPConnection.m from [0b3550d382] to [55a67721ce].
︙ | ︙ | |||
52 53 54 55 56 57 58 | #import "XMPPStanza.h" #import "XMPPXMLElementBuilder.h" #import "namespaces.h" #import <ObjFW/macros.h> | < < | < < < > | < < < < < < < < < < < | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #import "XMPPStanza.h" #import "XMPPXMLElementBuilder.h" #import "namespaces.h" #import <ObjFW/macros.h> @interface XMPPConnection () <OFDNSResolverDelegate, OFTCPSocketDelegate, OFXMLParserDelegate, OFXMLElementBuilderDelegate> - (void)xmpp_tryNextSRVRecord; - (bool)xmpp_parseBuffer: (const void *)buffer length: (size_t)length; - (void)xmpp_startStream; - (void)xmpp_handleStanza: (OFXMLElement *)element; - (void)xmpp_handleStream: (OFXMLElement *)element; - (void)xmpp_handleTLS: (OFXMLElement *)element; - (void)xmpp_handleSASL: (OFXMLElement *)element; - (void)xmpp_handleIQ: (XMPPIQ *)IQ; - (void)xmpp_handleMessage: (XMPPMessage *)message; |
︙ | ︙ | |||
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | [_password release]; [_privateKeyFile release]; [_certificateFile release]; [_server release]; [_domain release]; [_resource release]; [_JID release]; [_delegates release]; [_callbacks release]; [_authModule release]; [super dealloc]; } | > | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | [_password release]; [_privateKeyFile release]; [_certificateFile release]; [_server release]; [_domain release]; [_resource release]; [_JID release]; [_nextSRVRecords release]; [_delegates release]; [_callbacks release]; [_authModule release]; [super dealloc]; } |
︙ | ︙ | |||
267 268 269 270 271 272 273 | } } else _password = nil; [old release]; } | | > | | < < | | | | | | < | | < < < < | | > < | | | | > | < < < < | < | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | } } else _password = nil; [old release]; } - (void)socket: (OF_KINDOF(OFTCPSocket *))sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { if (exception != nil) { if ([_nextSRVRecords count] > 0) { [self xmpp_tryNextSRVRecord]; return; } [_delegates broadcastSelector: @selector(connection: didThrowException:) withObject: self withObject: exception]; return; } [self xmpp_startStream]; [_socket asyncReadIntoBuffer: _buffer length: XMPP_CONNECTION_BUFFER_LENGTH]; } - (void)xmpp_tryNextSRVRecord { OFSRVDNSResourceRecord *record = [[[_nextSRVRecords objectAtIndex: 0] copy] autorelease]; if ([_nextSRVRecords count] == 0) { [_nextSRVRecords release]; _nextSRVRecords = nil; } [_socket asyncConnectToHost: [record target] port: [record port]]; } - (void)resolver: (OFDNSResolver *)resolver didResolveDomainName: (OFString *)domainName answerRecords: (OFDictionary *)answerRecords authorityRecords: (OFDictionary *)authorityRecords additionalRecords: (OFDictionary *)additionalRecords exception: (id)exception { OFMutableArray *records = [OFMutableArray array]; if (exception != nil) { [_delegates broadcastSelector: @selector(connection:didThrowException:) |
︙ | ︙ | |||
341 342 343 344 345 346 347 | if ([record isKindOfClass: [OFSRVDNSResourceRecord class]]) [records addObject: record]; /* TODO: Sort records */ [records makeImmutable]; if ([records count] == 0) { | | | | < < < < > > > | > | < < < < | < | < < < < < | > | > | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | if ([record isKindOfClass: [OFSRVDNSResourceRecord class]]) [records addObject: record]; /* TODO: Sort records */ [records makeImmutable]; if ([records count] == 0) { /* Fall back to A / AAAA record. */ [_socket asyncConnectToHost: _domainToASCII port: _port]; return; } [_nextSRVRecords release]; _nextSRVRecords = nil; _nextSRVRecords = [records mutableCopy]; [self xmpp_tryNextSRVRecord]; } - (void)asyncConnect { void *pool = objc_autoreleasePoolPush(); if (_socket != nil) @throw [OFAlreadyConnectedException exception]; _socket = [[OFTCPSocket alloc] init]; [_socket setDelegate: self]; if (_server != nil) [_socket asyncConnectToHost: _server port: _port]; else [[OFThread DNSResolver] asyncResolveHost: _domainToASCII delegate: self]; objc_autoreleasePoolPop(pool); } - (bool)xmpp_parseBuffer: (const void *)buffer length: (size_t)length { if ([_socket isAtEndOfStream]) { [_delegates broadcastSelector: @selector(connectionWasClosed: error:) withObject: self withObject: nil]; return false; } @try { [_parser parseBuffer: buffer length: length]; } @catch (OFMalformedXMLException *e) { |
︙ | ︙ | |||
418 419 420 421 422 423 424 | [_oldParser release]; [_oldElementBuilder release]; _oldParser = nil; _oldElementBuilder = nil; } | | | | | 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | [_oldParser release]; [_oldElementBuilder release]; _oldParser = nil; _oldElementBuilder = nil; } - (bool)stream: (OF_KINDOF(OFStream *))stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { if (exception != nil) { [_delegates broadcastSelector: @selector(connection: didThrowException:) withObject: self withObject: exception]; [self close]; |
︙ | ︙ | |||
452 453 454 455 456 457 458 | if (_oldParser != nil || _oldElementBuilder != nil) { [_oldParser release]; [_oldElementBuilder release]; _oldParser = nil; _oldElementBuilder = nil; | | | < < < < < < | 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | if (_oldParser != nil || _oldElementBuilder != nil) { [_oldParser release]; [_oldElementBuilder release]; _oldParser = nil; _oldElementBuilder = nil; [_socket asyncReadIntoBuffer: _buffer length: XMPP_CONNECTION_BUFFER_LENGTH]; return false; } return true; } - (bool)streamOpen |
︙ | ︙ | |||
582 583 584 585 586 587 588 | { return [OFString stringWithFormat: @"objxmpp_%u", _lastID++]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix | | | | 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | { return [OFString stringWithFormat: @"objxmpp_%u", _lastID++]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attributes { if (![name isEqual: @"stream"]) { // No dedicated stream error for this, may not even be XMPP [self close]; [_socket close]; return; } if (![prefix isEqual: @"stream"]) { [self xmpp_sendStreamError: @"bad-namespace-prefix" text: nil]; return; } if (![namespace isEqual: XMPP_NS_STREAM]) { [self xmpp_sendStreamError: @"invalid-namespace" text: nil]; return; } for (OFXMLAttribute *attribute in attributes) { if ([[attribute name] isEqual: @"from"] && |
︙ | ︙ | |||
751 752 753 754 755 756 757 | [self xmpp_handleFeatures: element]; return; } if ([[element name] isEqual: @"error"]) { OFString *condition, *reason; [self close]; | < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | < | | < < | < < < < < < < < < < < < < < < < < < < < < < | 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | [self xmpp_handleFeatures: element]; return; } if ([[element name] isEqual: @"error"]) { OFString *condition, *reason; [self close]; [_delegates broadcastSelector: @selector(connectionWasClosed:) withObject: self withObject: element]; condition = [[[element elementsForNamespace: XMPP_NS_XMPP_STREAM] firstObject] name]; if (condition == nil) condition = @"undefined"; reason = [[element elementForName: @"text" namespace: XMPP_NS_XMPP_STREAM] stringValue]; @throw [XMPPStreamErrorException |
︙ | ︙ | |||
866 867 868 869 870 871 872 873 874 875 876 877 878 879 | [newSock setCertificateFile: _certificateFile]; [newSock setPrivateKeyFile: _privateKeyFile]; [newSock setPrivateKeyPassphrase: _privateKeyPassphrase]; #endif [newSock startTLSWithExpectedHost: nil]; [_socket release]; _socket = newSock; _encrypted = true; [_delegates broadcastSelector: @selector( connectionDidUpgradeToTLS:) withObject: self]; | > | 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | [newSock setCertificateFile: _certificateFile]; [newSock setPrivateKeyFile: _privateKeyFile]; [newSock setPrivateKeyPassphrase: _privateKeyPassphrase]; #endif [newSock startTLSWithExpectedHost: nil]; [_socket release]; _socket = newSock; [_socket setDelegate: self]; _encrypted = true; [_delegates broadcastSelector: @selector( connectionDidUpgradeToTLS:) withObject: self]; |
︙ | ︙ |
Modified tests/test.m from [654249e42f] to [d958b131ca].
︙ | ︙ | |||
265 266 267 268 269 270 271 272 | - (void)connection: (XMPPConnection *)conn didThrowException: (id)e { @throw e; } - (void)connectionWasClosed: (XMPPConnection *)conn { | > | | 265 266 267 268 269 270 271 272 273 274 275 276 | - (void)connection: (XMPPConnection *)conn didThrowException: (id)e { @throw e; } - (void)connectionWasClosed: (XMPPConnection *)conn error: (OFXMLElement *)error { of_log(@"Connection was closed: %@", error); } @end |