Squashed 'third_party/rawrtc/re/' content from commit f3163ce8b
Change-Id: I6a235e6ac0f03269d951026f9d195da05c40fdab
git-subtree-dir: third_party/rawrtc/re
git-subtree-split: f3163ce8b526a13b35ef71ce4dd6f43585064d8a
diff --git a/src/sdp/util.c b/src/sdp/util.c
new file mode 100644
index 0000000..754f5b8
--- /dev/null
+++ b/src/sdp/util.c
@@ -0,0 +1,50 @@
+/**
+ * @file sdp/util.c SDP utility functions
+ *
+ * Copyright (C) 2010 Creytiv.com
+ */
+#include <string.h>
+#include <re_types.h>
+#include <re_fmt.h>
+#include <re_list.h>
+#include <re_sa.h>
+#include <re_sdp.h>
+
+
+/**
+ * Decode RTP Header Extension SDP attribute value
+ *
+ * @param ext Extension-map object
+ * @param val SDP attribute value
+ *
+ * @return 0 for success, otherwise errorcode
+ */
+int sdp_extmap_decode(struct sdp_extmap *ext, const char *val)
+{
+ struct pl id, dir;
+
+ if (!ext || !val)
+ return EINVAL;
+
+ if (re_regex(val, strlen(val), "[0-9]+[/]*[a-z]* [^ ]+[ ]*[^ ]*",
+ &id, NULL, &dir, &ext->name, NULL, &ext->attrs))
+ return EBADMSG;
+
+ ext->dir_set = false;
+ ext->dir = SDP_SENDRECV;
+
+ if (pl_isset(&dir)) {
+
+ ext->dir_set = true;
+
+ if (!pl_strcmp(&dir, "sendonly")) ext->dir = SDP_SENDONLY;
+ else if (!pl_strcmp(&dir, "sendrecv")) ext->dir = SDP_SENDRECV;
+ else if (!pl_strcmp(&dir, "recvonly")) ext->dir = SDP_RECVONLY;
+ else if (!pl_strcmp(&dir, "inactive")) ext->dir = SDP_INACTIVE;
+ else ext->dir_set = false;
+ }
+
+ ext->id = pl_u32(&id);
+
+ return 0;
+}