summaryrefslogtreecommitdiff
path: root/tpsip
diff options
context:
space:
mode:
authorMikhail Zabaluev <mikhail.zabaluev@nokia.com>2009-11-05 02:17:36 +0200
committerMikhail Zabaluev <mikhail.zabaluev@nokia.com>2009-11-05 02:17:36 +0200
commit7c42c3b5e2baa34ffb322636a27d3c0d4f565c88 (patch)
tree059072c8870653e78f59fa0bdb7f181d39669ad8 /tpsip
parente2defa88a1684f475a416b2e396f7dd2e078ec1c (diff)
Initial code for codec parameter formatters and parsers
Diffstat (limited to 'tpsip')
-rw-r--r--tpsip/codec-param-formats.c64
-rw-r--r--tpsip/codec-param-formats.h75
2 files changed, 139 insertions, 0 deletions
diff --git a/tpsip/codec-param-formats.c b/tpsip/codec-param-formats.c
new file mode 100644
index 0000000..f29fd64
--- /dev/null
+++ b/tpsip/codec-param-formats.c
@@ -0,0 +1,64 @@
+/*
+ * codec-param-formats.c - Implementation of codec parameter formatter infra
+ * Copyright (C) 2009 Nokia Corporation
+ * @author Mikhail Zabaluev <mikhail.zabaluev@nokia.com>
+ *
+ * This work is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this work; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "codec-param-formats.h"
+
+#include <string.h>
+
+#include <tpsip/util.h>
+
+static void
+format_param_generic (gpointer key, gpointer val, gpointer user_data)
+{
+ const gchar *name = key;
+ const gchar *value = val;
+ GString *out = user_data;
+
+ /* Ignore freaky parameters */
+ g_return_if_fail (name != NULL && name[0]);
+ g_return_if_fail (value != NULL && value[0]);
+
+ if (out->len != 0)
+ g_string_append_c (out, ';');
+
+ if (strchr (value, ';') == NULL)
+ g_string_append_printf (out, "%s=%s", name, value);
+ else
+ {
+ g_string_append (out, name);
+ g_string_append_c (out, '=');
+ tpsip_string_append_quoted (out, value);
+ }
+}
+
+/**
+ * tpsip_codec_param_format_generic:
+ * @params: the map of codec parameters
+ * @out: a #GString for the output
+ *
+ * Formats the parameters as a semicolon separated list of
+ * <replaceable>parameter</replaceable><literal>=</literal><replaceable>value</replaceable>
+ * pairs, as recommended in IETF RFC 4855 Section 3.
+ */
+void
+tpsip_codec_param_format_generic (GHashTable *params, GString *out)
+{
+ g_hash_table_foreach (params, format_param_generic, out);
+}
diff --git a/tpsip/codec-param-formats.h b/tpsip/codec-param-formats.h
new file mode 100644
index 0000000..6707ec0
--- /dev/null
+++ b/tpsip/codec-param-formats.h
@@ -0,0 +1,75 @@
+/*
+ * codec-param-formats.h - Declarations for codec parameter formatters
+ * Copyright (C) 2009 Nokia Corporation
+ * @author Mikhail Zabaluev <mikhail.zabaluev@nokia.com>
+ *
+ * This work is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this work; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __TPSIP_CODEC_PARAM_FORMATS_H__
+#define __TPSIP_CODEC_PARAM_FORMATS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * TpsipCodecParamFormatFunc:
+ * @params: the map of codec parameters
+ * @out: a #GString for the output
+ *
+ * Defines the function pointer signature for codec parameter formatters.
+ * A formatter takes a codec parameter map as passed in
+ * a org.freedesktop.Telepathy.Media.StreamHandler codec structure,
+ * and outputs its SDP representation, as per the value for an a=fmtp
+ * attribute, into the string buffer @out.
+ *
+ * <note>
+ * <para>The function is allowed to modify the @params hash table.
+ * This is useful to implement a custom formatter that processes the
+ * few parameters treated specially, removes them from the map, and
+ * calls a more generic formatter such as tpsip_codec_param_format_generic().
+ * </para>
+ * </note>
+ */
+typedef void (* TpsipCodecParamFormatFunc) (GHashTable *params, GString *out);
+
+/**
+ * TpsipCodecParamParseFunc:
+ * @str: a string value with format-specific parameter description
+ * @out: the parameter map to populate
+ *
+ * Defines the function pointer signature for codec parameter parsers.
+ * A parser takes the string value coming from an a=fmtp SDP attribute,
+ * and populates the parameter hash table.
+ */
+typedef void (* TpsipCodecParamParseFunc) (const gchar *str, GHashTable *out);
+
+void tpsip_codec_param_format_generic (GHashTable *params, GString *out);
+
+/**
+ * tpsip_codec_param_parse_generic:
+ * @str: a string value with the parameter description
+ * @out: the parameter map to populate
+ *
+ * Parses parameters formatted as a semicolon separated list of
+ * <replaceable>parameter</replaceable><literal>=</literal><replaceable>value</replaceable>
+ * pairs, as recommended in IETF RFC 4855 Section 3.
+ */
+void tpsip_codec_param_parse_generic (const gchar *str, GHashTable *out);
+
+G_END_DECLS
+
+#endif /* !__TPSIP_CODEC_PARAM_FORMATS_H__ */