summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-11 20:35:40 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-11 20:35:40 (GMT)
commite9a402583b02866c87475711c57b04f499e846ef (patch)
tree3d8ad0f22ff0b167c0bc47a0ba2c006217abbbfa /Swiften
parentaa32913718442aecb7b22e891bd6f1a1ceca9d8c (diff)
downloadswift-e9a402583b02866c87475711c57b04f499e846ef.zip
swift-e9a402583b02866c87475711c57b04f499e846ef.tar.bz2
Some code layout improvement in Client/Session.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Client/Session.cpp211
1 files changed, 101 insertions, 110 deletions
diff --git a/Swiften/Client/Session.cpp b/Swiften/Client/Session.cpp
index aa3cc62..c4adfa0 100644
--- a/Swiften/Client/Session.cpp
+++ b/Swiften/Client/Session.cpp
@@ -112,139 +112,130 @@ void Session::handleElement(boost::shared_ptr<Element> element) {
if (getState() == SessionStarted) {
onElementReceived(element);
}
- else {
- StreamFeatures* streamFeatures = dynamic_cast<StreamFeatures*>(element.get());
- if (streamFeatures) {
- if (!checkState(Negotiating)) {
- return;
- }
+ else if (StreamFeatures* streamFeatures = dynamic_cast<StreamFeatures*>(element.get())) {
+ if (!checkState(Negotiating)) {
+ return;
+ }
- if (streamFeatures->hasStartTLS() && tlsLayerFactory_->canCreate()) {
- state_ = Encrypting;
- xmppLayer_->writeElement(boost::shared_ptr<StartTLSRequest>(new StartTLSRequest()));
- }
- else if (streamFeatures->hasAuthenticationMechanisms()) {
- if (!certificate_.isNull()) {
- if (streamFeatures->hasAuthenticationMechanism("EXTERNAL")) {
- state_ = Authenticating;
- xmppLayer_->writeElement(boost::shared_ptr<Element>(new AuthRequest("EXTERNAL", "")));
- }
- else {
- setError(ClientCertificateError);
- }
- }
- else if (streamFeatures->hasAuthenticationMechanism("PLAIN")) {
- state_ = WaitingForCredentials;
- onNeedCredentials();
+ if (streamFeatures->hasStartTLS() && tlsLayerFactory_->canCreate()) {
+ state_ = Encrypting;
+ xmppLayer_->writeElement(boost::shared_ptr<StartTLSRequest>(new StartTLSRequest()));
+ }
+ else if (streamFeatures->hasAuthenticationMechanisms()) {
+ if (!certificate_.isNull()) {
+ if (streamFeatures->hasAuthenticationMechanism("EXTERNAL")) {
+ state_ = Authenticating;
+ xmppLayer_->writeElement(boost::shared_ptr<Element>(new AuthRequest("EXTERNAL", "")));
}
else {
- setError(NoSupportedAuthMechanismsError);
+ setError(ClientCertificateError);
}
}
+ else if (streamFeatures->hasAuthenticationMechanism("PLAIN")) {
+ state_ = WaitingForCredentials;
+ onNeedCredentials();
+ }
else {
- // Start the session
+ setError(NoSupportedAuthMechanismsError);
+ }
+ }
+ else {
+ // Start the session
- // Add a whitespace ping layer
- whitespacePingLayer_ = new WhitespacePingLayer();
- streamStack_->addLayer(whitespacePingLayer_);
+ // Add a whitespace ping layer
+ whitespacePingLayer_ = new WhitespacePingLayer();
+ streamStack_->addLayer(whitespacePingLayer_);
- if (streamFeatures->hasSession()) {
- needSessionStart_ = true;
- }
+ if (streamFeatures->hasSession()) {
+ needSessionStart_ = true;
+ }
- if (streamFeatures->hasResourceBind()) {
- state_ = BindingResource;
- boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
- if (!jid_.getResource().isEmpty()) {
- resourceBind->setResource(jid_.getResource());
- }
- xmppLayer_->writeElement(IQ::createRequest(IQ::Set, JID(), "session-bind", resourceBind));
- }
- else if (needSessionStart_) {
- sendSessionStart();
- }
- else {
- state_ = SessionStarted;
- onSessionStarted();
+ if (streamFeatures->hasResourceBind()) {
+ state_ = BindingResource;
+ boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
+ if (!jid_.getResource().isEmpty()) {
+ resourceBind->setResource(jid_.getResource());
}
+ xmppLayer_->writeElement(IQ::createRequest(IQ::Set, JID(), "session-bind", resourceBind));
+ }
+ else if (needSessionStart_) {
+ sendSessionStart();
}
+ else {
+ state_ = SessionStarted;
+ onSessionStarted();
+ }
+ }
+ }
+ else if (dynamic_cast<AuthSuccess*>(element.get())) {
+ checkState(Authenticating);
+ state_ = WaitingForStreamStart;
+ xmppLayer_->resetParser();
+ sendStreamHeader();
+ }
+ else if (dynamic_cast<AuthFailure*>(element.get())) {
+ setError(AuthenticationFailedError);
+ }
+ else if (dynamic_cast<TLSProceed*>(element.get())) {
+ tlsLayer_ = tlsLayerFactory_->createTLSLayer();
+ streamStack_->addLayer(tlsLayer_);
+ if (!certificate_.isNull() && !tlsLayer_->setClientCertificate(certificate_)) {
+ setError(ClientCertificateLoadError);
}
else {
- AuthSuccess* authSuccess = dynamic_cast<AuthSuccess*>(element.get());
- if (authSuccess) {
- checkState(Authenticating);
- state_ = WaitingForStreamStart;
- xmppLayer_->resetParser();
- sendStreamHeader();
+ tlsLayer_->onConnected.connect(boost::bind(&Session::handleTLSConnected, this));
+ tlsLayer_->onError.connect(boost::bind(&Session::handleTLSError, this));
+ tlsLayer_->connect();
+ }
+ }
+ else if (dynamic_cast<StartTLSFailure*>(element.get())) {
+ setError(TLSError);
+ }
+ else if (IQ* iq = dynamic_cast<IQ*>(element.get())) {
+ if (state_ == BindingResource) {
+ boost::shared_ptr<ResourceBind> resourceBind(iq->getPayload<ResourceBind>());
+ if (iq->getType() == IQ::Error && iq->getID() == "session-bind") {
+ setError(ResourceBindError);
}
- else if (dynamic_cast<AuthFailure*>(element.get())) {
- setError(AuthenticationFailedError);
+ else if (!resourceBind) {
+ setError(UnexpectedElementError);
}
- else if (dynamic_cast<TLSProceed*>(element.get())) {
- tlsLayer_ = tlsLayerFactory_->createTLSLayer();
- streamStack_->addLayer(tlsLayer_);
- if (!certificate_.isNull() && !tlsLayer_->setClientCertificate(certificate_)) {
- setError(ClientCertificateLoadError);
+ else if (iq->getType() == IQ::Result) {
+ jid_ = resourceBind->getJID();
+ if (!jid_.isValid()) {
+ setError(ResourceBindError);
+ }
+ if (needSessionStart_) {
+ sendSessionStart();
}
else {
- tlsLayer_->onConnected.connect(boost::bind(&Session::handleTLSConnected, this));
- tlsLayer_->onError.connect(boost::bind(&Session::handleTLSError, this));
- tlsLayer_->connect();
+ state_ = SessionStarted;
}
}
- else if (dynamic_cast<StartTLSFailure*>(element.get())) {
- setError(TLSError);
+ else {
+ setError(UnexpectedElementError);
+ }
+ }
+ else if (state_ == StartingSession) {
+ if (iq->getType() == IQ::Result) {
+ state_ = SessionStarted;
+ onSessionStarted();
+ }
+ else if (iq->getType() == IQ::Error) {
+ setError(SessionStartError);
}
else {
- IQ* iq = dynamic_cast<IQ*>(element.get());
- if (iq) {
- if (state_ == BindingResource) {
- boost::shared_ptr<ResourceBind> resourceBind(iq->getPayload<ResourceBind>());
- if (iq->getType() == IQ::Error && iq->getID() == "session-bind") {
- setError(ResourceBindError);
- }
- else if (!resourceBind) {
- setError(UnexpectedElementError);
- }
- else if (iq->getType() == IQ::Result) {
- jid_ = resourceBind->getJID();
- if (!jid_.isValid()) {
- setError(ResourceBindError);
- }
- if (needSessionStart_) {
- sendSessionStart();
- }
- else {
- state_ = SessionStarted;
- }
- }
- else {
- setError(UnexpectedElementError);
- }
- }
- else if (state_ == StartingSession) {
- if (iq->getType() == IQ::Result) {
- state_ = SessionStarted;
- onSessionStarted();
- }
- else if (iq->getType() == IQ::Error) {
- setError(SessionStartError);
- }
- else {
- setError(UnexpectedElementError);
- }
- }
- else {
- setError(UnexpectedElementError);
- }
- }
- else {
- // FIXME Not correct?
- state_ = SessionStarted;
- onSessionStarted();
- }
+ setError(UnexpectedElementError);
}
}
+ else {
+ setError(UnexpectedElementError);
+ }
+ }
+ else {
+ // FIXME Not correct?
+ state_ = SessionStarted;
+ onSessionStarted();
}
}