Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
DeviceDescriptionSchema.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
6#include "Stroika/Foundation/Containers/Mapping.h"
8
9#include "Stroika/Frameworks/UPnP/DeviceDescription.h"
10
11/*
12 * The UPnP device description schema, embedded.
13 *
14 * Its own translation unit so that a program which never validates never carries it: Stroika is a static library, so
15 * an object nothing references is not pulled from the archive at all - no linker flag, no pragma, nothing to get wrong
16 * on one toolchain and not another. Serialize references it, to check what it writes (Options::fValidateWrite), so a
17 * device publishing its description carries it; reading references it only through the schema a caller gives
18 * fValidateReadAgainst, so a program that only reads descriptions does not. The service description's schema is a
19 * translation unit of its own for the same reason.
20 *
21 * The schema is https://upnp.org/schemas/device-1-0.xsd as it stood 2026-10-13: what Serialize writes holds against
22 * it (@see Tests/55's DescriptionsValidateAgainstPublishedSchemas_).
23 *
24 * KEPT IN THE TREE and shipped, not fetched the way ThirdPartyComponents are - @see WebService/SOAP_EnvelopeSchema.cpp,
25 * which says why at length. upnp.org/schemas/ serves both files openly, and other open-source UPnP projects carry
26 * their own copies - GUPnP ships both as RELAX NG (doc/device-description.rnc, doc/service-description.rnc), and the
27 * .xsd itself sits in public repositories.
28 *
29 * Embedded as BYTES rather than written as a C++ string literal, for the same reason SOAP's is: a schema is someone
30 * else's file, and a literal would be read as cp1252 by the MSVC builds, which are passed no /utf-8, the day one of
31 * them gains a character outside ASCII.
32 *
33 * @todo the xxd rule in this directory's Makefile, and the .embed it generates, go away for #embed once every
34 * compiler Stroika supports has it - the file, and everything said above, stay as they are.
35 */
36// the embed too, not just the function: with no schema support this file has nothing to compile, and an unused array
37// of 11K would warn
38#if qStroika_Foundation_DataExchange_XML_SupportParsing and qStroika_Foundation_DataExchange_XML_SupportSchema and qStroika_Foundation_DataExchange_XML_SupportDOM
39namespace {
40 DISABLE_COMPILER_GCC_WARNING_START ("GCC diagnostic ignored \"-Wunused-variable\""); // warning suppression for Schemas_device_1_0_xsd_len
41 constexpr
42#include "device-1-0.xsd.embed"
43 DISABLE_COMPILER_GCC_WARNING_END ("GCC diagnostic ignored \"-Wunused-variable\"");
44}
45
46using namespace Stroika::Foundation;
48
49using namespace Stroika::Frameworks;
50using namespace Stroika::Frameworks::UPnP;
51
52XML::Schema::Ptr UPnP::DeviceDescriptionSchema (const XML::Options& o)
53{
54 // compiled once per provider - there are two, libxml2's and Xerces' - and kept; a schema keeps its XML library alive, so
55 // this may outlive the provider
57 auto compiled = sCompiled_.rwget ();
58 const XML::Providers::IXMLProvider* provider = &o.GetProvider ();
59 if (optional<XML::Schema::Ptr> s = compiled->Lookup (provider)) {
60 return *s;
61 }
62 XML::Schema::Ptr s = XML::Schema::New (Memory::BLOB::Attach (Schemas_device_1_0_xsd), nullptr, o);
63 compiled->Add (provider, s);
64 return s;
65}
66#endif
Wrap any object with Synchronized<> and it can be used similarly to the base type,...
nonvirtual WritableReference rwget()
get a read-write smart pointer to the underlying Synchronized<> object, holding the full lock the who...
How XML is read and written - for now, with which provider - taken last by each XML function (DOM::Do...