4#include "Stroika/Frameworks/StroikaPreComp.h"
11#include "Stroika/Foundation/Streams/MemoryStream.h"
12#include "Stroika/Foundation/Streams/TextToBinary.h"
22using namespace Stroika::Foundation::Streams;
25using namespace Stroika::Frameworks;
26using namespace Stroika::Frameworks::UPnP;
27using namespace Stroika::Frameworks::UPnP::SSDP;
34String Advertisement::ToString ()
const
39 sb <<
"Alive : "sv << fAlive;
41 sb <<
", USN : "sv << fUSN;
42 sb <<
", Location : "sv << fLocation;
43 sb <<
", Server : "sv << fServer;
44 sb <<
", Target : "sv << fTarget;
45 sb <<
", Raw-Headers : "sv << fRawHeaders;
56 {
"Alive"sv, &Advertisement::fAlive},
57 {
"USN"sv, &Advertisement::fUSN},
58 {
"Server"sv, &Advertisement::fServer},
59 {
"Target"sv, &Advertisement::fTarget},
60 {
"RawHeaders"sv, &Advertisement::fRawHeaders},
70Memory::BLOB SSDP::Serialize (
const String& headLine, SearchOrNotify searchOrNotify,
const Advertisement& ad)
72 using namespace Characters::Literals;
73 Require (not headLine.
Contains (
"\n"));
74 Require (not headLine.
Contains (
"\r"));
75 Require (headLine.
StartsWith (
"NOTIFY") or (headLine ==
"HTTP/1.1 200 OK"));
80 textOut.
Write (
"{}\r\n"_f(headLine));
81 textOut.
Write (
"Host: {}:{}\r\n"_f(SSDP::V4::kSocketAddress.GetInternetAddress (), SSDP::V4::kSocketAddress.GetPort ()));
82 textOut.
Write (
"Cache-Control: max-age=60\r\n"sv);
83 textOut.
Write (
"Location: {}\r\n"_f(ad.fLocation));
84 if (ad.fAlive.has_value ()) {
86 textOut.
Write (
"NTS: ssdp:alive\r\n"sv);
89 textOut.
Write (
"NTS: ssdp:byebye\r\n"sv);
92 if (not ad.fServer.empty ()) {
93 textOut.
Write (
"Server: {}\r\n"_f(ad.fServer));
95 if (searchOrNotify == SearchOrNotify::SearchResponse) {
96 textOut.
Write (
"ST: {}\r\n"_f(ad.fTarget));
99 textOut.
Write (
"NT: {}\r\n"_f(ad.fTarget));
101 textOut.
Write (
"USN: {}\r\n"_f(ad.fUSN));
104 textOut.
Write (
"\r\n"sv);
116void SSDP::DeSerialize (
const Memory::BLOB& b,
String* headLine, Advertisement* advertisement)
120 *advertisement = Advertisement{};
122#if qCompilerAndStdLib_span_requires_explicit_type_for_BLOBCVT_Buggy
138 if (optional<size_t> n = line.
Find (
':')) {
142 if (not label.empty ()) {
143 advertisement->fRawHeaders.Add (label, value);
145 constexpr auto kLabelComparer_ = String::ThreeWayComparer{Characters::eCaseInsensitive};
146 if (kLabelComparer_ (label,
"Location"sv) == 0) {
149 else if (kLabelComparer_ (label,
"NT"sv) == 0) {
150 advertisement->fTarget = value;
152 else if (kLabelComparer_ (label,
"USN"sv) == 0) {
153 advertisement->fUSN = value;
155 else if (kLabelComparer_ (label,
"Server"sv) == 0) {
156 advertisement->fServer = value;
158 else if (kLabelComparer_ (label,
"NTS"sv) == 0) {
159 constexpr auto kValueComparer_ = String::ThreeWayComparer{Characters::eCaseInsensitive};
160 if (kValueComparer_ (value,
"ssdp:alive"sv) == 0) {
161 advertisement->fAlive =
true;
163 else if (kValueComparer_ (value,
"ssdp:byebye"sv) == 0) {
164 advertisement->fAlive =
false;
#define RequireNotNull(p)
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual bool Contains(Character c, CompareOptions co=eWithCase) const
nonvirtual String SubString(SZ from) const
nonvirtual String Trim(bool(*shouldBeTrimmed)(Character)=Character::IsWhitespace) const
nonvirtual bool StartsWith(const Character &c, CompareOptions co=eWithCase) const
nonvirtual optional< size_t > Find(Character c, CompareOptions co=eWithCase) const
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
nonvirtual void AddClass(const Traversal::Iterable< StructFieldInfo > &fieldDescriptions, const ClassMapperOptions< CLASS > &mapperOptions={})
nonvirtual void AddCommonType(ARGS &&... args)
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
nonvirtual void Write(span< ELEMENT_TYPE2, EXTENT_2 > elts) const
Ptr New(const InputStream::Ptr< byte > &src, optional< AutomaticCodeCvtFlags > codeCvtFlags={}, optional< SeekableFlag > seekable={}, ReadAhead readAhead=eReadAheadAllowed)
Create an InputStream::Ptr<Character> from the arguments (usually binary source) - which can be used ...