Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions D4ParserSax2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "D4ParserSax2.h"
#include "DapXmlNamespaces.h"

#include "cerealization_patch.h"
#include "debug.h"
#include "util.h"

Expand Down Expand Up @@ -651,6 +652,10 @@
if (parser->check_attribute("dmrVersion"))
parser->dmr()->set_dmr_version(parser->xml_attrs["dmrVersion"].value);

// TODO - Do we ever need/want to read serialization flag into a DMR state variable? (I don't think so...)

Check warning on line 655 in D4ParserSax2.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrSry8hqXC4K2pae&open=AZ2WTrSry8hqXC4K2pae&pullRequest=354
// if (parser->check_attribute(CEREALIZATION_PATCH_ATTR_NAME))
// parser->dmr()->set_serialization(parser->xml_attrs[CEREALIZATION_PATCH_ATTR_NAME].value);

if (parser->check_attribute("base"))
parser->dmr()->set_request_xml_base(parser->xml_attrs["base"].value);

Expand Down
9 changes: 7 additions & 2 deletions DDS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "DapIndent.h"
#include "Error.h"
#include "InternalErr.h"
#include "cerealization_patch.h"
#include "debug.h"
#include "escaping.h"
#include "parser.h"
Expand Down Expand Up @@ -1225,7 +1226,7 @@ void DDS::print_xml_writer(ostream &out, bool constrained, const string &blob) {
* @param out Write the XML to this stream
* @param constrained Should the DMR be subject to a constraint?
*/
void DDS::print_dmr(ostream &out, bool constrained) {
void DDS::print_dmr(ostream &out, bool constrained, bool add_serialization_attr) {
if (get_dap_major() < 4)
throw InternalErr(__FILE__, __LINE__, "Tried to print a DMR with DAP major version less than 4");

Expand Down Expand Up @@ -1257,7 +1258,11 @@ void DDS::print_dmr(ostream &out, bool constrained) {

if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"dmrVersion",
(const xmlChar *)get_dmr_version().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for dapVersion");
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for dmrVersion");

if (add_serialization_attr) {
add_serialization_patch_attribute(xml, get_namespace());
}

if (!get_request_xml_base().empty()) {
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"xml:base",
Expand Down
6 changes: 5 additions & 1 deletion DDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@
/** @brief Returns the DAP4 DMR version corresponding to DDS exports. */
string get_dmr_version() const { return "1.0"; }

// TODO - Do we need a state variable for the serialization flag? (I don't think so...)

Check warning on line 289 in DDS.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUMy8hqXC4K2pag&open=AZ2WTrUMy8hqXC4K2pag&pullRequest=354
/** @brief Returns the DAP4 data serialization scheme. */
// string get_serialization() const { return "4.0"; }

Check warning on line 291 in DDS.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUMy8hqXC4K2pah&open=AZ2WTrUMy8hqXC4K2pah&pullRequest=354

/// @deprecated
void set_dap_major(int p);
/// @deprecated
Expand Down Expand Up @@ -415,7 +419,7 @@
void print_xml_writer(ostream &out, bool constrained, const string &blob = "");

// Print the DAP4 DMR 'object'
void print_dmr(ostream &out, bool constrained);
void print_dmr(ostream &out, bool constrained, bool add_serialization_attr = false);

void print_das(ostream &out);
DAS *get_das();
Expand Down
14 changes: 12 additions & 2 deletions DMR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "DDS.h" // Included so DMRs can be built using a DDS for 'legacy' handlers

#include "DapIndent.h"
#include "cerealization_patch.h"
#include "debug.h"

using namespace std;
Expand All @@ -69,6 +70,9 @@

d_dmr_version = dmr.d_dmr_version;

// TODO - Do we need a state variable for the serialization flag? (I don't think so...)

Check warning on line 73 in DMR.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrTny8hqXC4K2paf&open=AZ2WTrTny8hqXC4K2paf&pullRequest=354
// d_serialization = dmr.d_serialization;

d_request_xml_base = dmr.d_request_xml_base;

d_namespace = dmr.d_namespace;
Expand Down Expand Up @@ -311,8 +315,10 @@
* @param xml use this XMLWriter to build the XML.
* @param constrained Should the DMR be subject to a constraint? Defaults to
* False
* @param add_serialization_attr Add the servers serialization version
* attribute to the Dataset element
*/
void DMR::print_dap4(XMLWriter &xml, bool constrained) {
void DMR::print_dap4(XMLWriter &xml, bool constrained, bool add_serialization_attr) {
if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)"Dataset") < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write Dataset element");

Expand All @@ -332,7 +338,11 @@

if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"dmrVersion",
(const xmlChar *)dmr_version().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for dapVersion");
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for dmrVersion");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your idea to make the 'serialization = ...' XML attribute a function of the response - and resetting the 'dmrVersion' XML attribute to 1.0. This would mean that a DMR response does not have the 'serialization' attribute and uses 'dmrVersion = 1.0'. Then for the DAP response, the "DMR Part" does have the 'serialization' attribute and has the 'dmrVersion = 1.0'.

If you're going to do that, this would nominally be the place and and you could do that by adding a third parameter. You could keep this existing method by making the two parameter version call the new three parameter version (thus maintaining ABI of this class).


if (add_serialization_attr) {
add_serialization_patch_attribute(xml, get_namespace());
}

if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
Expand Down
26 changes: 25 additions & 1 deletion DMR.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
/// The 2.0 version indicates the DAP4 Serialization bug fix.
std::string d_dmr_version = "2.0";

/// The version of the DAP4 serialization used to encode the data response values.
/// Prior to adding this indicator variable and its expression in the DMR
/// a non-dap4 compliant serialization scheme, in which Groups were serialized first
/// and then the top-level variables was implemented.
/// We mended this problem with dap4 serialization add added this state
/// variable along with a Dataset xml attribute dap:serialization to express this state.
/// The original patch changed the d_dmr_version to 2.0 - ndp 4/14/26
// TODO - Do we need a DMR state variable for the serialization flag? (I don't think so...)

Check warning on line 86 in DMR.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUyy8hqXC4K2pai&open=AZ2WTrUyy8hqXC4K2pai&pullRequest=354
// std::string d_serialization = "4.0";

/// The URL for the request base
std::string d_request_xml_base;

Expand Down Expand Up @@ -179,6 +189,19 @@
*/
void set_dmr_version(const std::string &v) { d_dmr_version = v; }

/**
* @brief Returns the DAP4 serialization that the source service will deliver.
* TODO - Do we need a DMR state variable for the serialization flag? (I don't think so...)
*/

Check warning on line 195 in DMR.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUyy8hqXC4K2paj&open=AZ2WTrUyy8hqXC4K2paj&pullRequest=354
// std::string serialization() const { return d_serialization; }

Check warning on line 196 in DMR.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUyy8hqXC4K2pal&open=AZ2WTrUyy8hqXC4K2pal&pullRequest=354

/**
* @brief Sets the DAP4 serialization string.
* TODO - Do we need a DMR state variable for the serialization flag? (I don't think so...)
* @param v DAP4 serialization value.
*/

Check warning on line 202 in DMR.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUyy8hqXC4K2pak&open=AZ2WTrUyy8hqXC4K2pak&pullRequest=354
// void set_serialization(const std::string &v) { d_serialization = v; }

Check warning on line 203 in DMR.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUyy8hqXC4K2pam&open=AZ2WTrUyy8hqXC4K2pam&pullRequest=354

/// Get the URL that will return this DMR
std::string request_xml_base() const { return d_request_xml_base; }

Expand Down Expand Up @@ -255,7 +278,8 @@

virtual bool is_dap4_projected(std::vector<string> &inventory);

void print_dap4(XMLWriter &xml, bool constrained = false);
// void print_dap4(XMLWriter &xml, bool constrained = false){print_dap4(xml,constrained,false);};

Check warning on line 281 in DMR.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrUyy8hqXC4K2pan&open=AZ2WTrUyy8hqXC4K2pan&pullRequest=354
void print_dap4(XMLWriter &xml, bool constrained = false, bool add_serialization_attr = false);

void dump(std::ostream &strm) const override;

Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ DAP4_ONLY_HDR = D4StreamMarshaller.h D4StreamUnMarshaller.h Int64.h \
D4Maps.h D4Dimensions.h D4EnumDefs.h D4Group.h DMR.h D4Attributes.h \
D4AttributeType.h D4Enum.h chunked_stream.h chunked_ostream.h \
chunked_istream.h D4Sequence.h crc.h D4Opaque.h D4AsyncUtil.h \
D4Function.h D4RValue.h D4FilterClause.h
D4Function.h D4RValue.h D4FilterClause.h cerealization_patch.h

if USE_C99_TYPES
dods-datatypes.h: dods-datatypes-static.h
Expand Down
65 changes: 65 additions & 0 deletions cerealization_patch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2026 OPeNDAP, Inc.
// Author: NAthan Potter <ndp@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
//
// cerealization_patch.h
//

#ifndef CEREALIZATION_PATCH_H
#define CEREALIZATION_PATCH_H

#define CEREALIZATION_PATCH_ATTR_NAME "hyrax_dap"

Check failure on line 31 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this macro by "const", "constexpr" or an "enum".

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2pao&open=AZ2WTrWAy8hqXC4K2pao&pullRequest=354
#define CEREALIZATION_PATCH_ATTR_VALUE "4.0"

Check failure on line 32 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this macro by "const", "constexpr" or an "enum".

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2pap&open=AZ2WTrWAy8hqXC4K2pap&pullRequest=354

#include "InternalErr.h"
#include "XMLWriter.h"
namespace libdap {

/**
*
* Adds the serialization patch attribute to the current element.
* @param xml
* @param dap4_namespace_name
*/
static void add_serialization_patch_attribute(libdap::XMLWriter &xml, const string &) {

Check warning on line 44 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a reference-to-const. The current type of "xml" is "class libdap::XMLWriter &".

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2pav&open=AZ2WTrWAy8hqXC4K2pav&pullRequest=354

Check warning on line 44 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

unused function 'add_serialization_patch_attribute'

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2pau&open=AZ2WTrWAy8hqXC4K2pau&pullRequest=354

/*
TODO - If we don't need a namespace prefix we can drop this bit.
if (!dap4_namespace_name.empty()) {
// Oddly, the dap namespace prefix is not defined by default. We have to add it to

Check warning on line 49 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the misleading "//" characters.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2paq&open=AZ2WTrWAy8hqXC4K2paq&pullRequest=354
// namespace prefix our special attribute.

Check warning on line 50 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the misleading "//" characters.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2par&open=AZ2WTrWAy8hqXC4K2par&pullRequest=354
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"xmlns:dap",
(const xmlChar *)dap4_namespace_name.c_str()) < 0)
throw libdap::InternalErr(__FILE__, __LINE__, "Could not write attribute for xmlns:dap");
}
*/

Check warning on line 55 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2pas&open=AZ2WTrWAy8hqXC4K2pas&pullRequest=354

// TODO - Is this really just a hyrax thing? Rethink this attribute name!

Check warning on line 57 in cerealization_patch.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=OPENDAP-libdap4&issues=AZ2WTrWAy8hqXC4K2pat&open=AZ2WTrWAy8hqXC4K2pat&pullRequest=354
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)CEREALIZATION_PATCH_ATTR_NAME,
(const xmlChar *)CEREALIZATION_PATCH_ATTR_VALUE) < 0)
throw libdap::InternalErr(__FILE__, __LINE__, "Could not write attribute for " CEREALIZATION_PATCH_ATTR_NAME);
}

} // namespace libdap

#endif // CEREALIZATION_PATCH_H
2 changes: 1 addition & 1 deletion getdap4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void read_local_dap4(D4Connect &url, const string &name, const bool get_dmr_flag

// Always write the DMR
XMLWriter xml;
dmr.print_dap4(xml);
dmr.print_dap4(xml, false, true);
cout << xml.get_doc() << endl;

if (get_data_flag)
Expand Down
2 changes: 1 addition & 1 deletion tests/D4ResponseBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void D4ResponseBuilder::send_dap(ostream &out, DMR &dmr, bool with_mime_headers,

// Write the DMR
XMLWriter xml;
dmr.print_dap4(xml, constrained);
dmr.print_dap4(xml, constrained, true);

// now make the chunked output stream; set the size to be at least chunk_size
// but make sure that the whole of the xml plus the CRLF can fit in the first
Expand Down
11 changes: 8 additions & 3 deletions unit-tests/DMRTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,15 @@ class DMRTest : public TestFixture {
dmr = build_dmr(dds_file, attr);
XMLWriter xml;
dmr->print_dap4(xml);
DBG(cerr << "DMR: " << endl << xml.get_doc() << endl);
string dmr_doc(xml.get_doc());
DBG(cerr << "DMR: " << endl << dmr_doc << endl);

string prefix = string(TEST_SRC_DIR) + "/dmr-testsuite/";
CPPUNIT_ASSERT(string(xml.get_doc()) == read_test_baseline(prefix + dmr_baseline));
string baseline_file = string(TEST_SRC_DIR) + "/dmr-testsuite/" + dmr_baseline;
DBG(cerr << "baseline_file: " << baseline_file << endl);
string baseline = read_test_baseline(baseline_file);
DBG(cerr << "BASELINE: " << endl << baseline << endl);

CPPUNIT_ASSERT(dmr_doc == baseline);
delete dmr;
} catch (Error &e) {
delete dmr;
Expand Down
Loading