mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-18 06:03:39 +03:00
Feature #687: Add method AclRule::from_xml
This commit is contained in:
parent
b37b4be45e
commit
d813946556
@ -74,6 +74,15 @@ public:
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Rebuilds the rule from an xml formatted string
|
||||
*
|
||||
* @param xml_str The xml-formatted string
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
/**
|
||||
* Returns the 32 less significant bits of the user long long attribute
|
||||
*
|
||||
|
@ -94,6 +94,20 @@ public:
|
||||
int xpath(unsigned int& value, const char * xpath_expr,
|
||||
const unsigned int& def);
|
||||
|
||||
/**
|
||||
* Gets and sets a xpath attribute, if the attribute is not found a default
|
||||
* is used
|
||||
* @param value to set
|
||||
* @param xpath_expr of the xml element
|
||||
* @param def default value if the element is not found
|
||||
* @param hex if true, the contents of the element are expected to be in
|
||||
* hexadecimal instead of decimal
|
||||
*
|
||||
* @return -1 if default was set
|
||||
*/
|
||||
long long xpath(long long& value, const char * xpath_expr,
|
||||
const long long& def, bool hex=true);
|
||||
|
||||
/**
|
||||
* Gets and sets a xpath attribute, if the attribute is not found a default
|
||||
* is used
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "AclRule.h"
|
||||
#include "AuthManager.h"
|
||||
#include "ObjectXML.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -315,3 +316,28 @@ string& AclRule::to_xml(string& xml) const
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AclRule::from_xml(const string &xml_str)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
string tmp_error;
|
||||
|
||||
ObjectXML xml_obj(xml_str);
|
||||
|
||||
rc += xml_obj.xpath(oid , "/ACL/ID" , 0);
|
||||
rc += xml_obj.xpath(user , "/ACL/USER" , 0);
|
||||
rc += xml_obj.xpath(resource, "/ACL/RESOURCE", 0);
|
||||
rc += xml_obj.xpath(rights , "/ACL/RIGHTS" , 0);
|
||||
rc += xml_obj.xpath(str , "/ACL/STRING" , "");
|
||||
|
||||
if ( (rc != 0) || malformed(tmp_error) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -222,6 +222,47 @@ int ObjectXML::xpath(unsigned int& value, const char * xpath_expr,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
long long ObjectXML::xpath(long long& value, const char * xpath_expr,
|
||||
const long long& def, bool hex)
|
||||
{
|
||||
vector<string> values;
|
||||
int rc = 0;
|
||||
|
||||
values = (*this)[xpath_expr];
|
||||
|
||||
if (values.empty() == true)
|
||||
{
|
||||
value = def;
|
||||
rc = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
istringstream iss;
|
||||
|
||||
iss.str(values[0]);
|
||||
|
||||
if ( hex )
|
||||
{
|
||||
iss >> hex >> value;
|
||||
}
|
||||
else
|
||||
{
|
||||
iss >> dec >> value;
|
||||
}
|
||||
|
||||
if (iss.fail() == true)
|
||||
{
|
||||
value = def;
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ObjectXML::xpath(time_t& value, const char * xpath_expr, const time_t& def)
|
||||
{
|
||||
int int_val;
|
||||
|
Loading…
x
Reference in New Issue
Block a user