/// - the next step status is set to @c CalloutHandle::NEXT_STEP CONTINUE
///
/// This class must never be modified to also delete the context
-/// information from the callout handle, because retaining this information
-/// is one of the primary reasons why this class is created. Otherwise,
-/// we could simply re-create the callout handle for each hook point
-/// without the need to reset the state like we do.
+/// information from the callout handle. The context is intended
+/// to be used to share stateful data across callouts and hook points
+/// and its contents must exist for the duration of the packet lifecycle.
+/// Otherwise, we could simply re-create the callout handle for
+/// each hook point and we wouldn't need this RAII class.
class ScopedCalloutHandleState {
public:
// Set two arguments and the non-default status.
int one = 1;
int two = 2;
+ int three = 3;
handle->setArgument("one", one);
handle->setArgument("two", two);
+ handle->setContext("three", three);
handle->setStatus(CalloutHandle::NEXT_STEP_DROP);
int value = 0;
EXPECT_THROW(handle->getArgument("two", value), NoSuchArgument);
EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, handle->getStatus());
+ // Context should be intact.
+ ASSERT_NO_THROW(handle->getContext("three", value));
+ EXPECT_EQ(three, value);
+
// Set the arguments and status again prior to the destruction of
// the wrapper.
handle->setArgument("one", one);
EXPECT_THROW(handle->getArgument("one", value), NoSuchArgument);
EXPECT_THROW(handle->getArgument("two", value), NoSuchArgument);
EXPECT_EQ(CalloutHandle::NEXT_STEP_CONTINUE, handle->getStatus());
+
+ // Context should be intact.
+ ASSERT_NO_THROW(handle->getContext("three", value));
+ EXPECT_EQ(three, value);
}
// Further tests of the "skip" flag and tests of getting the name of the