Squashed 'third_party/rawrtc/rawrtc-data-channel/' content from commit 7b1b8d57c
Change-Id: I84850720e2b51961981d55f67238f4d282314fff
git-subtree-dir: third_party/rawrtc/rawrtc-data-channel
git-subtree-split: 7b1b8d57c6d07da18cc0de8bbca8cc5e8bd06eae
diff --git a/src/data_channel_parameters/attributes.c b/src/data_channel_parameters/attributes.c
new file mode 100644
index 0000000..f09deb6
--- /dev/null
+++ b/src/data_channel_parameters/attributes.c
@@ -0,0 +1,138 @@
+#include "parameters.h"
+#include <rawrtcdc/data_channel.h>
+#include <rawrtcdc/data_channel_parameters.h>
+#include <rawrtcc/code.h>
+#include <re.h>
+
+/*
+ * Get the label from the data channel parameters.
+ * `*labelp` will be set to a copy of the parameter's label and must be
+ * unreferenced.
+ *
+ * Return `RAWRTC_CODE_NO_VALUE` in case no label has been set.
+ * Otherwise, `RAWRTC_CODE_SUCCESS` will be returned and `*parameters*
+ * must be unreferenced.
+ */
+enum rawrtc_code rawrtc_data_channel_parameters_get_label(
+ char** const labelp, // de-referenced
+ struct rawrtc_data_channel_parameters* const parameters) {
+ // Check arguments
+ if (!labelp || !parameters) {
+ return RAWRTC_CODE_INVALID_ARGUMENT;
+ }
+
+ // Set value
+ if (parameters->label) {
+ *labelp = mem_ref(parameters->label);
+ return RAWRTC_CODE_SUCCESS;
+ } else {
+ return RAWRTC_CODE_NO_VALUE;
+ }
+}
+
+/*
+ * Get the channel type from the data channel parameters.
+ */
+enum rawrtc_code rawrtc_data_channel_parameters_get_channel_type(
+ enum rawrtc_data_channel_type* const channel_typep, // de-referenced
+ struct rawrtc_data_channel_parameters* const parameters) {
+ // Check arguments
+ if (!channel_typep || !parameters) {
+ return RAWRTC_CODE_INVALID_ARGUMENT;
+ }
+
+ // Set value
+ *channel_typep = parameters->channel_type;
+ return RAWRTC_CODE_SUCCESS;
+}
+
+/*
+ * Get the reliability parameter from the data channel parameters.
+ *
+ * Return `RAWRTC_CODE_NO_VALUE` in case the channel type is
+ * `RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_*`. Otherwise,
+ * `RAWRTC_CODE_SUCCESS` will be returned.
+ */
+enum rawrtc_code rawrtc_data_channel_parameters_get_reliability_parameter(
+ uint32_t* const reliability_parameterp, // de-referenced
+ struct rawrtc_data_channel_parameters* const parameters) {
+ // Check arguments
+ if (!reliability_parameterp || !parameters) {
+ return RAWRTC_CODE_INVALID_ARGUMENT;
+ }
+
+ // Set value
+ switch (parameters->channel_type) {
+ case RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED:
+ case RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_UNORDERED:
+ return RAWRTC_CODE_NO_VALUE;
+ default:
+ *reliability_parameterp = parameters->reliability_parameter;
+ return RAWRTC_CODE_SUCCESS;
+ }
+}
+
+/*
+ * Get the protocol from the data channel parameters.
+ * `*protocolp` will be set to a copy of the parameter's protocol and
+ * must be unreferenced.
+ *
+ * Return `RAWRTC_CODE_NO_VALUE` in case no protocol has been set.
+ * Otherwise, `RAWRTC_CODE_SUCCESS` will be returned and `*protocolp*
+ * must be unreferenced.
+ */
+enum rawrtc_code rawrtc_data_channel_parameters_get_protocol(
+ char** const protocolp, // de-referenced
+ struct rawrtc_data_channel_parameters* const parameters) {
+ // Check arguments
+ if (!protocolp || !parameters) {
+ return RAWRTC_CODE_INVALID_ARGUMENT;
+ }
+
+ // Set value
+ if (parameters->protocol) {
+ *protocolp = mem_ref(parameters->protocol);
+ return RAWRTC_CODE_SUCCESS;
+ } else {
+ return RAWRTC_CODE_NO_VALUE;
+ }
+}
+
+/*
+ * Get the 'negotiated' flag from the data channel parameters.
+ */
+enum rawrtc_code rawrtc_data_channel_parameters_get_negotiated(
+ bool* const negotiatedp, // de-referenced
+ struct rawrtc_data_channel_parameters* const parameters) {
+ // Check arguments
+ if (!negotiatedp || !parameters) {
+ return RAWRTC_CODE_INVALID_ARGUMENT;
+ }
+
+ // Set value
+ *negotiatedp = parameters->negotiated;
+ return RAWRTC_CODE_SUCCESS;
+}
+
+/*
+ * Get the negotiated id from the data channel parameters.
+ *
+ * Return `RAWRTC_CODE_NO_VALUE` in case the 'negotiated' flag is set
+ * `false`. Otherwise, `RAWRTC_CODE_SUCCESS` will be returned.
+ */
+enum rawrtc_code rawrtc_data_channel_parameters_get_id(
+ uint16_t* const idp, // de-referenced
+ struct rawrtc_data_channel_parameters* const parameters) {
+ // Check arguments
+ if (!idp || !parameters) {
+ return RAWRTC_CODE_INVALID_ARGUMENT;
+ }
+
+ // Set value
+ if (parameters->negotiated) {
+ *idp = parameters->id;
+ return RAWRTC_CODE_SUCCESS;
+ } else {
+ return RAWRTC_CODE_NO_VALUE;
+ }
+}