Skip to content
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

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

choppsv1
Copy link
Contributor

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.

Copy link
Member

@rwestphal rwestphal left a 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>> {
Copy link
Member

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.

Copy link
Contributor Author

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(
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@rwestphal
Copy link
Member

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.

That's possible. We have unit tests where we use parse_op() to parse RPCs and notifications and it works. But if that's opaque data, I don't know what the implications would be.

The doc comments of lyd_parse_op() says this about the tree parameter:
* @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL.

The doc mentions tree being an opaque data tree only for specific data types, like RESTCONF/NETCONF RPCs and notifications. For LYD_TYPE_RPC_YANG and LYD_TYPE_NOTIF_YANG, it's unclear to me whether that's also the case just by looking at the documentation. I should investigate once time permits.

@choppsv1 choppsv1 force-pushed the chopps/fix-parse_op branch 2 times, most recently from b266ea0 to b283ba2 Compare October 19, 2024 23:41
Copy link

codecov bot commented Oct 19, 2024

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 ☂️

@choppsv1 choppsv1 force-pushed the chopps/fix-parse_op branch 3 times, most recently from 1b31963 to f5abb0a Compare October 20, 2024 14:06
Copy link
Member

@rwestphal rwestphal left a 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> {
Copy link
Member

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

Copy link
Contributor Author

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> {
Copy link
Member

Choose a reason for hiding this comment

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

nit: missing doc comment

Copy link
Contributor Author

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();
Copy link
Member

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?

Copy link
Contributor Author

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.

@choppsv1 choppsv1 force-pushed the chopps/fix-parse_op branch 2 times, most recently from 493add4 to 55a8dbf Compare October 21, 2024 06:48
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]>
Copy link
Member

@rwestphal rwestphal left a comment

Choose a reason for hiding this comment

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

Looks good!

@rwestphal rwestphal merged commit 97de7ad into holo-routing:master Oct 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants