-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
data: expand the OP parsing with new API functions #19
data: expand the OP parsing with new API functions #19
Conversation
aade806
to
76d1199
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@choppsv1 Thanks for these additions! Please see my review comments inline below.
src/data.rs
Outdated
data: impl AsRef<[u8]>, | ||
format: DataFormat, | ||
op_type: ffi::lyd_type::Type, | ||
) -> Result<DataNodeRef<'a, 'a>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this method signature.
lyd_parse_op()
has the following params related to data trees:
* @param[in] parent Optional parent to connect the parsed nodes to.
* @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL.
* @param[out] op Optional pointer to the operation (action/RPC) node.
You're passing a NULL pointer to parent
, which is the only input data tree (tree
and op
are output parameters). So why does this function need to take &mut self
?
The why I'm seeing this, lyd_parse_op
will allocate a new data tree to op
, which is independent from &mut self
, so the return value must be a DataTree
that owns that data. Returning a DataNodeRef
means op
will leak once it goes out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you are correct. I actually am using the restconf routine in DataNodeRef and wrote these 4 functions for completeness sake to cover the other 3 transport based OP types. I'll redo these.
src/data.rs
Outdated
@@ -530,6 +530,97 @@ impl<'a> DataTree<'a> { | |||
Ok(unsafe { DataTree::from_raw(context, rnode) }) | |||
} | |||
|
|||
pub fn _parse_op( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a private function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
That's possible. We have unit tests where we use The doc comments of The doc mentions |
b266ea0
to
b283ba2
Compare
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
1b31963
to
f5abb0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I've only a few minor comments (please see inline).
@@ -28,6 +28,12 @@ pub struct DataTree<'a> { | |||
raw: *mut ffi::lyd_node, | |||
} | |||
|
|||
#[derive(Debug)] | |||
pub struct DataTreeOwningRef<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please add a doc comment for this struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/data.rs
Outdated
Ok(unsafe { DataTreeOwningRef::from_raw(tree, raw) }) | ||
} | ||
|
||
pub fn noderef(&'a self) -> DataNodeRef<'a, 'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing doc comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/data.rs
Outdated
// Create input handler. | ||
let mut ly_in = std::ptr::null_mut(); | ||
let ret = if data.as_ref().is_empty() { | ||
let blank = CString::new("").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary?
I just checked the source of ly_in_new_memory()
and it does this:
LIBYANG_API_DEF LY_ERR
ly_in_new_memory(const char *str, struct ly_in **in)
{
LY_CHECK_ARG_RET(NULL, str, in, LY_EINVAL);
I believe you want this function to do nothing when data
is empty, instead of returning an error. Could you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct; however, this code is buggy as it doesn't allocate new memory it just keeps a pointer to the passed in data. So I need to fix it.
493add4
to
55a8dbf
Compare
Signed-off-by: Christian Hopps <[email protected]>
The new functions handle the 3 NETCONF and 3 RESTCONF variations. It also seems like the existing `fn parse_op` is broken as it returns the envelope node which will not be the actual tree, but opaque data. Signed-off-by: Christian Hopps <[email protected]>
Signed-off-by: Christian Hopps <[email protected]>
55a8dbf
to
41858cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
The new functions handle the 3 NETCONF and 3 RESTCONF variations. It also seems like the existing
fn parse_op
is broken as it returns the envelope node which will not be the actual tree, but opaque data.