blob: 754f5b888ecad9fa4139dd72d0ba520b3dc7f2ab [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file sdp/util.c SDP utility functions
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6#include <string.h>
7#include <re_types.h>
8#include <re_fmt.h>
9#include <re_list.h>
10#include <re_sa.h>
11#include <re_sdp.h>
12
13
14/**
15 * Decode RTP Header Extension SDP attribute value
16 *
17 * @param ext Extension-map object
18 * @param val SDP attribute value
19 *
20 * @return 0 for success, otherwise errorcode
21 */
22int sdp_extmap_decode(struct sdp_extmap *ext, const char *val)
23{
24 struct pl id, dir;
25
26 if (!ext || !val)
27 return EINVAL;
28
29 if (re_regex(val, strlen(val), "[0-9]+[/]*[a-z]* [^ ]+[ ]*[^ ]*",
30 &id, NULL, &dir, &ext->name, NULL, &ext->attrs))
31 return EBADMSG;
32
33 ext->dir_set = false;
34 ext->dir = SDP_SENDRECV;
35
36 if (pl_isset(&dir)) {
37
38 ext->dir_set = true;
39
40 if (!pl_strcmp(&dir, "sendonly")) ext->dir = SDP_SENDONLY;
41 else if (!pl_strcmp(&dir, "sendrecv")) ext->dir = SDP_SENDRECV;
42 else if (!pl_strcmp(&dir, "recvonly")) ext->dir = SDP_RECVONLY;
43 else if (!pl_strcmp(&dir, "inactive")) ext->dir = SDP_INACTIVE;
44 else ext->dir_set = false;
45 }
46
47 ext->id = pl_u32(&id);
48
49 return 0;
50}