Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Fixed resource binding
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Oct 14, 2020
1 parent ce075f4 commit 91ef53c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions esp32/main/Esp32Jura.hpp
@@ -1,10 +1,10 @@
#pragma once

// #define MODE_SNOOPER
#define MODE_COFFEE_MAKER
// #define MODE_COFFEE_MAKER
// #define MODE_BRIDGE
// #define MODE_SERIAL
// #define MODE_XMPP
#define MODE_XMPP

#include <smooth/core/Application.h>

Expand Down
10 changes: 7 additions & 3 deletions esp32/main/xmpp/Jid.cpp
Expand Up @@ -4,7 +4,7 @@
namespace esp32jura::xmpp {
//---------------------------------------------------------------------------
Jid::Jid(std::string&& userPart, std::string&& domainPart, std::string&& resourcePart)
: isValid(!userPart.empty() && domainPart.empty()), userPart(std::move(userPart)), domainPart(std::move(domainPart)), resourcePart(std::move(resourcePart)) {}
: isValid(!userPart.empty() && !domainPart.empty()), userPart(std::move(userPart)), domainPart(std::move(domainPart)), resourcePart(std::move(resourcePart)) {}

std::string Jid::get_bare() const { return userPart + "@" + domainPart; }

Expand All @@ -21,8 +21,12 @@ void Jid::split_full_jid(const std::string& fullJid, std::string* userPart, std:
split_bare_jid(fullJid, userPart, &tmp);

std::size_t pos = tmp.find('/');
*domainPart = tmp.substr(0, pos);
*resourcePart = tmp.substr(pos + 1, tmp.length() - pos);
if (pos != std::string::npos) {
*domainPart = tmp.substr(0, pos);
*resourcePart = tmp.substr(pos + 1, tmp.length() - pos);
} else {
*domainPart = tmp;
}
}

Jid&& Jid::from_bare_jid(const std::string& bareJid) {
Expand Down
9 changes: 8 additions & 1 deletion esp32/main/xmpp/XmppConnection.cpp
@@ -1,6 +1,10 @@
#include "XmppConnection.hpp"

#include <cassert>

#include "XmppUtils.hpp"
#include "crypto/CryptoUtils.hpp"
#include "xmpp/messages/BindResourceMessage.hpp"

//---------------------------------------------------------------------------
namespace esp32jura::xmpp {
Expand Down Expand Up @@ -29,7 +33,10 @@ std::string XmppConnection::genPlainAuthMessage() {
}

std::string XmppConnection::genResourceBindMessage() {
return "<iq id='yhc13a95' type='set'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>" + account->jid.resourcePart + "</resource></bind></iq>";
assert(account->jid.is_full());
std::string resource = account->jid.resourcePart;
messages::BindResourceMessage msg(std::move(resource));
return msg.to_xml_str();
}

std::string XmppConnection::genPresenceMessage() { return "<presence/>"; }
Expand Down
3 changes: 3 additions & 0 deletions esp32/main/xmpp/XmppTask.cpp
Expand Up @@ -4,6 +4,7 @@
#include <smooth/core/task_priorities.h>
#include <tinyxml2.h>

#include <cassert>
#include <iostream>
#include <string>

Expand Down Expand Up @@ -41,6 +42,8 @@ void XmppTask::init() {
// XMPP:
std::string jidString = storage->readString(esp::Storage::JID);
xmpp::Jid jid = xmpp::Jid::from_full_jid(jidString);
assert(jid.is_full());

std::string password = storage->readString(esp::Storage::JID_PASSWORD);
xmpp::XmppAccount account(std::move(jid), std::move(password), std::make_shared<smooth::core::network::IPv4>(jid.domainPart, 5222));
client = std::make_unique<xmpp::XmppClient>(std::move(account), *this, *this);
Expand Down
2 changes: 1 addition & 1 deletion esp32/main/xmpp/messages/AbstractAddressableMessage.hpp
Expand Up @@ -16,7 +16,7 @@ class AbstractAddressableMessage : public AbstractMessage {
public:
AbstractAddressableMessage(const Jid from, const Jid to);
AbstractAddressableMessage(const Jid from, const Jid to, const std::string&& id);
~AbstractAddressableMessage() = default;
virtual ~AbstractAddressableMessage() = default;
};
//---------------------------------------------------------------------------
} // namespace esp32jura::xmpp::messages
Expand Down
2 changes: 1 addition & 1 deletion esp32/main/xmpp/messages/BindResourceMessage.cpp
Expand Up @@ -7,7 +7,7 @@ namespace esp32jura::xmpp::messages {
//---------------------------------------------------------------------------
BindResourceMessage::BindResourceMessage(const std::string&& resource) : IQMessage(IQType::SET), resource(std::move(resource)) {}

MessageType IQMessage::get_type() { return MessageType::BindResourceMessageType; }
MessageType BindResourceMessage::get_type() { return MessageType::BindResourceMessageType; }

tinyxml2::XMLElement* BindResourceMessage::get_query(tinyxml2::XMLDocument& doc) const {
tinyxml2::XMLElement* bindNode = doc.NewElement("bind");
Expand Down
2 changes: 1 addition & 1 deletion esp32/main/xmpp/messages/BindResourceMessage.hpp
Expand Up @@ -15,7 +15,7 @@ class BindResourceMessage : public IQMessage {

public:
BindResourceMessage(const std::string&& resource);
~BindResourceMessage() = default;
virtual ~BindResourceMessage() = default;

MessageType get_type() override;

Expand Down
2 changes: 1 addition & 1 deletion esp32/main/xmpp/messages/IQMessage.hpp
Expand Up @@ -22,7 +22,7 @@ class IQMessage : public AbstractAddressableMessage {
IQMessage(const std::string&& id, IQType iqType);
IQMessage(IQType iqType);
IQMessage(const tinyxml2::XMLElement* node);
~IQMessage() = default;
virtual ~IQMessage() = default;

MessageType get_type() override;

Expand Down

0 comments on commit 91ef53c

Please sign in to comment.