-/*
- * Copyright 2001-2009 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
*/
/**
char* ddf_strdup(const char* s)
{
- return (s && *s) ? strdup(s) : NULL;
+ return (s && *s) ? strdup(s) : nullptr;
}
#define MAX_NAME_LEN 255
The name buffer is returned from the function. */
char* ddf_token(const char** path, char* name)
{
- const char* temp=NULL;
-
- *name='\0';
- if (*path==NULL || **path=='\0')
+ *name=0;
+ if (*path==nullptr || **path==0)
return name;
- temp=strchr(*path,'.');
- if (temp==NULL)
- {
- strcpy(name,*path);
- *path=NULL;
+ const char* temp=strchr(*path,'.');
+ if (temp==nullptr) {
+ strncpy(name,*path,MAX_NAME_LEN);
+ name[MAX_NAME_LEN]=0;
+ *path=nullptr;
}
- else if (temp>*path)
- {
+ else if (temp>*path) {
strncpy(name,*path,temp-*path);
- name[temp-*path]='\0';
+ name[temp-*path]=0;
*path=temp+1;
}
else
// body implementation
struct shibsp::ddf_body_t {
- ddf_body_t() : name(NULL), parent(NULL), next(NULL), prev(NULL), type(DDF_EMPTY) {}
+ ddf_body_t() : name(nullptr), parent(nullptr), next(nullptr), prev(nullptr), type(DDF_EMPTY) {}
char* name; // name of node
ddf_body_t* parent; // parent node, if any
// library implementation
+DDF::DDF() : m_handle(nullptr)
+{
+}
+
DDF::DDF(const char* n)
{
m_handle=new(nothrow) ddf_body_t;
DDF& DDF::destroy()
{
- remove().empty().name(NULL);
+ remove().empty().name(nullptr);
delete m_handle;
- m_handle=NULL;
+ m_handle=nullptr;
return *this;
}
DDF DDF::copy() const
{
- if (m_handle==NULL)
+ if (m_handle==nullptr)
return DDF();
switch (m_handle->type) {
temp.m_handle=child;
DDF temp2=temp.copy();
copy.add(temp2);
- if (copy.m_handle==NULL)
+ if (copy.m_handle==nullptr)
return copy;
if (m_handle->value.children.current==child)
copy.m_handle->value.children.current=copy.m_handle->value.children.last;
const char* DDF::name() const
{
- return (m_handle) ? m_handle->name : NULL;
+ return (m_handle) ? m_handle->name : nullptr;
}
DDF& DDF::name(const char* name)
destroy();
}
else
- m_handle->name=NULL;
+ m_handle->name=nullptr;
}
return *this;
}
const char* DDF::string() const
{
- return isstring() ? m_handle->value.string : NULL;
+ return isstring() ? m_handle->value.string : nullptr;
}
long DDF::integer() const
void* DDF::pointer() const
{
- return ispointer() ? m_handle->value.pointer : NULL;
+ return ispointer() ? m_handle->value.pointer : nullptr;
}
size_t DDF::strlen() const
bool DDF::operator==(const char* s) const
{
- if (string()==NULL || s==NULL)
- return (string()==NULL && s==NULL);
+ if (string()==nullptr || s==nullptr)
+ return (string()==nullptr && s==nullptr);
else
return (::strcmp(string(),s)==0);
}
return *this;
}
+DDF& DDF::string(const char* val)
+{
+ return string(const_cast<char*>(val), true);
+}
+
+DDF& DDF::unsafe_string(const char* val)
+{
+ return string(const_cast<char*>(val), true, false);
+}
+
DDF& DDF::string(long val)
{
char buf[20];
{
if (empty().m_handle) {
m_handle->type=ddf_body_t::DDF_STRUCT;
- m_handle->value.children.first=NULL;
- m_handle->value.children.last=NULL;
- m_handle->value.children.current=NULL;
+ m_handle->value.children.first=nullptr;
+ m_handle->value.children.last=nullptr;
+ m_handle->value.children.current=nullptr;
m_handle->value.children.count=0;
}
return *this;
{
if (empty().m_handle) {
m_handle->type=ddf_body_t::DDF_LIST;
- m_handle->value.children.first=NULL;
- m_handle->value.children.last=NULL;
- m_handle->value.children.current=NULL;
+ m_handle->value.children.first=nullptr;
+ m_handle->value.children.last=nullptr;
+ m_handle->value.children.current=nullptr;
m_handle->value.children.count=0;
}
return *this;
m_handle->parent->value.children.current=m_handle->prev;
m_handle->parent->value.children.count--;
- m_handle->parent=NULL;
- m_handle->next=NULL;
- m_handle->prev=NULL;
+ m_handle->parent=nullptr;
+ m_handle->next=nullptr;
+ m_handle->prev=nullptr;
return *this;
}
{
DDF p;
- p.m_handle=(m_handle ? m_handle->parent : NULL);
+ p.m_handle=(m_handle ? m_handle->parent : nullptr);
return p;
}
return p;
}
+DDF DDF::operator[](const char* path) const
+{
+ return getmember(path);
+}
+
DDF DDF::operator[](unsigned long index) const
{
DDF d;
DDF DDF::getmember(const char* path) const
{
+ DDF current;
char name[MAX_NAME_LEN+1];
const char* path_ptr=path;
- DDF current;
-
- if (isstruct() && ddf_strlen(ddf_token(&path_ptr,name))>0) {
- current.m_handle=m_handle->value.children.first;
- while (current.m_handle && strcmp(current.m_handle->name,name)!=0)
- current.m_handle=current.m_handle->next;
- if (current.m_handle && ddf_strlen(path_ptr)>0)
- current=current.getmember(path_ptr);
+ ddf_token(&path_ptr, name);
+ if (*name == 0)
+ return current;
+ else if (*name == '[') {
+ unsigned long i = strtoul(name+1, nullptr, 10);
+ if (islist() && i < m_handle->value.children.count)
+ current=operator[](i);
+ else if (i == 0)
+ current = *this;
}
- else if (islist() && ddf_strlen(ddf_token(&path_ptr,name))>0 && *name=='#') {
- current=operator[](strtoul(name+1, NULL, 10));
- if (current.m_handle && ddf_strlen(path_ptr)>0)
- current=current.getmember(path_ptr);
+ else if (isstruct()) {
+ current.m_handle = m_handle->value.children.first;
+ while (current.m_handle && strcmp(current.m_handle->name,name) != 0)
+ current.m_handle = current.m_handle->next;
}
+ else if (islist()) {
+ current.m_handle = m_handle->value.children.first;
+ return current.getmember(path);
+ }
+
+ if (current.m_handle && path_ptr && *path_ptr)
+ current = current.getmember(path_ptr);
return current;
}
putc('"',f);
}
else
- fprintf(f,"NULL");
+ fprintf(f,"nullptr");
break;
case ddf_body_t::DDF_INT:
if (m_handle->value.pointer)
fprintf(f,"%p",m_handle->value.pointer);
else
- fprintf(f,"NULL");
+ fprintf(f,"nullptr");
break;
default:
}
}
else
- fprintf(f,"NULL");
+ fprintf(f,"nullptr");
fprintf(f,";\n");
}
DDF deserialize(DOMElement* root, bool lowercase)
{
- DDF obj(NULL);
- auto_ptr_char name_val(root->getAttributeNS(NULL, _name));
+ DDF obj(nullptr);
+ auto_ptr_char name_val(root->getAttributeNS(nullptr, _name));
if (name_val.get() && *name_val.get()) {
if (lowercase)
for (char* pch=const_cast<char*>(name_val.get()); *pch=tolower(*pch); pch++);
if (XMLString::equals(tag,_string)) {
DOMNode* child=root->getFirstChild();
if (child && child->getNodeType()==DOMNode::TEXT_NODE) {
- const XMLCh* unsafe = root->getAttributeNS(NULL, _unsafe);
+ const XMLCh* unsafe = root->getAttributeNS(nullptr, _unsafe);
if (unsafe && *unsafe==chDigit_1) {
// If it's unsafe, it's not UTF-8 data, so we have to convert to ASCII and decode it.
char* encoded = XMLString::transcode(child->getNodeValue());
}
else {
char* val = toUTF8(child->getNodeValue(), true); // use malloc
- if (val)
- obj.string(val, false); // don't re-copy the string
+ obj.string(val, false); // don't re-copy the string
}
}
}