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/msg/param.c b/src/msg/param.c
new file mode 100644
index 0000000..1974b82
--- /dev/null
+++ b/src/msg/param.c
@@ -0,0 +1,70 @@
+/**
+ * @file param.c  SIP Parameter decode
+ *
+ * Copyright (C) 2010 Creytiv.com
+ */
+#include <re_types.h>
+#include <re_fmt.h>
+#include <re_msg.h>
+
+
+/**
+ * Check if a parameter exists
+ *
+ * @param pl   Pointer-length string
+ * @param name Parameter name
+ * @param val  Returned parameter value
+ *
+ * @return 0 for success, otherwise errorcode
+ */
+int msg_param_exists(const struct pl *pl, const char *name, struct pl *val)
+{
+	struct pl v1, v2;
+	char xpr[128];
+
+	if (!pl || !name || !val)
+		return EINVAL;
+
+	(void)re_snprintf(xpr, sizeof(xpr), ";[ \t\r\n]*%s[ \t\r\n;=]*", name);
+
+	if (re_regex(pl->p, pl->l, xpr, &v1, &v2))
+		return ENOENT;
+
+	if (!v2.l && v2.p < pl->p + pl->l)
+		return ENOENT;
+
+	val->p = v1.p - 1;
+	val->l = v2.p - val->p;
+
+	return 0;
+}
+
+
+/**
+ * Decode a Parameter
+ *
+ * @param pl   Pointer-length string
+ * @param name Parameter name
+ * @param val  Returned parameter value
+ *
+ * @return 0 for success, otherwise errorcode
+ */
+int msg_param_decode(const struct pl *pl, const char *name, struct pl *val)
+{
+	char expr[128];
+	struct pl v;
+
+	if (!pl || !name || !val)
+		return EINVAL;
+
+	(void)re_snprintf(expr, sizeof(expr),
+			  ";[ \t\r\n]*%s[ \t\r\n]*=[ \t\r\n]*[~ \t\r\n;]+",
+			  name);
+
+	if (re_regex(pl->p, pl->l, expr, NULL, NULL, NULL, &v))
+		return ENOENT;
+
+	*val = v;
+
+	return 0;
+}