This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
powersync-core/libguh/coap/corelinkparser.cpp
Simon Stürz b00bba1c2b add qtcoap to the lib
add osdomotics plugin
2019-04-01 20:48:17 +02:00

64 lines
3.0 KiB
C++

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <simon.stuerz@guh.guru> *
* *
* This file is part of QtCoap. *
* *
* QtCoap is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* QtCoap is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with QtCoap. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "corelinkparser.h"
#include <QDebug>
CoreLinkParser::CoreLinkParser(const QByteArray &data, QObject *parent) :
QObject(parent),
m_data(data)
{
QList<QByteArray> linkList = data.split(',');
foreach (const QByteArray &linkLine, linkList) {
qDebug() << "-------------------------------------";
qDebug() << linkLine;
QList<QByteArray> valueList = linkLine.split(';');
CoreLink link;
foreach (const QByteArray &value, valueList) {
qDebug() << value;
if (value.startsWith("<")) {
link.setPath(QString(value.mid(1, value.length() - 2)));
} else if (value.startsWith("rt=")) {
link.setResourceType(QString(value.right(value.length() - 3)).remove('"'));
} else if (value.startsWith("if=")) {
link.setInterfaceDescription(QString(value.right(value.length() - 3)).remove('"'));
} else if (value.startsWith("sz=")) {
link.setMaximumSize(value.right(value.length() - 3).toInt());
} else if (value.startsWith("ct=")) {
link.setContentType(static_cast<CoapPdu::ContentType>(value.right(value.length() - 3).toUInt()));
} else if (value.startsWith("title=")) {
link.setTitle(QString(value.right(value.length() - 6)).remove('"'));
} else if (value == "obs") {
link.setObservable(true);
}
}
qDebug() << endl << link;
m_links.append(link);
}
}
QList<CoreLink> CoreLinkParser::links() const
{
return m_links;
}