summaryrefslogtreecommitdiffstats
path: root/tinySDP/src/tsdp.c
blob: 2c549082d300df4d677add4b3036fbbfc1d8d18b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
/**@file tsdp.c
 * @brief SDP (RFC 4566) implementations with both MMTel and PoC extensions.
 *
 * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
 *

 */
#include "tsdp.h"

#include "tinysdp/parsers/tsdp_parser_message.h"

// Defined in tsdp_message.c
extern int __pred_find_media_by_name(const tsk_list_item_t *item, const void *name);


typedef struct tsdp_ctx_s {
    TSK_DECLARE_OBJECT;

    tsdp_message_t* local;
    tsdp_message_t* remote;
    tsdp_message_t* negotiated;
}
tsdp_ctx_t;

const tsdp_message_t* tsdp_ctx_local_get_sdp(const tsdp_ctx_handle_t* self)
{
    const tsdp_ctx_t* ctx = self;

    if(ctx) {
        return ctx->local;
    }
    else {
        return tsk_null;
    }
}

int tsdp_ctx_local_create_sdp(tsdp_ctx_handle_t* self, const tsdp_message_t* local)
{
    tsdp_ctx_t* ctx = self;
    tsdp_message_t* newsdp;

    if(!ctx || !local) {
        return -1;
    }

    // set new local sdp
    if((newsdp = tsdp_message_clone(local))) {
        TSK_OBJECT_SAFE_FREE(ctx->local);
        ctx->local = newsdp;
        return 0;
    }
    else {
        return -2;
    }
}

int tsdp_ctx_local_create_sdp_2(tsdp_ctx_handle_t* self, const char* sdp, tsk_size_t size)
{
    tsdp_ctx_t* ctx = self;
    tsdp_message_t* newsdp;

    if(!ctx || !sdp || !size) {
        return -1;
    }

    if((newsdp = tsdp_message_parse(sdp, size))) {
        TSK_OBJECT_SAFE_FREE(ctx->local);
        ctx->local = newsdp;
        return 0;
    }
    else {
        return -2;
    }
}

int tsdp_ctx_local_add_headers(tsdp_ctx_handle_t* self, ...)
{
    tsdp_ctx_t* ctx = self;
    const tsk_object_def_t* objdef;
    tsdp_header_t *header;
    va_list ap;

    if(!ctx || !ctx->local) {
        return -1;
    }

    va_start(ap, self);
    while((objdef = va_arg(ap, const tsk_object_def_t*))) {
        if((header = tsk_object_new_2(objdef, &ap))) {
            tsdp_message_add_header(ctx->local, header);
            TSK_OBJECT_SAFE_FREE(header);
        }
    }
    va_end(ap);

    return 0;
}

int tsdp_ctx_local_add_media(tsdp_ctx_handle_t* self, const tsdp_header_M_t* media)
{
    tsdp_ctx_t* ctx = self;

    if(!ctx || !media) {
        return -1;
    }

    if(ctx->local) {
        return tsdp_message_add_header(ctx->local, TSDP_HEADER(media));
    }
    else {
        return -2;
    }
}

int tsdp_ctx_local_add_media_2(tsdp_ctx_handle_t* self, const char* media, uint32_t port, const char* proto, ...)
{
    tsdp_ctx_t* ctx = self;
    va_list ap;

    if(!ctx || !media || !proto) {
        return -1;
    }

    if(ctx->local) {
        int ret;
        va_start(ap, proto);
        ret = tsdp_message_add_media_2(ctx->local, media, port, proto, &ap);
        va_end(ap);
        return ret;
    }
    else {
        return -2;
    }
}

const tsdp_message_t* tsdp_ctx_remote_get_sdp(const tsdp_ctx_handle_t* self)
{
    const tsdp_ctx_t* ctx = self;

    if(ctx) {
        return ctx->remote;
    }
    else {
        return tsk_null;
    }
}

const tsdp_message_t* tsdp_ctx_negotiated_get_sdp(const tsdp_ctx_handle_t* self)
{
    const tsdp_ctx_t* ctx = self;

    if(ctx) {
        return ctx->negotiated;
    }
    else {
        return tsk_null;
    }
}















//=================================================================================================
//	Sdp ctx object definition
//
static void* tsdp_ctx_create(void * self, va_list * app)
{
    tsdp_ctx_t *ctx = self;
    if(ctx) {
    }
    return self;
}

static void* tsdp_ctx_destroy(void * self)
{
    tsdp_ctx_t *ctx = self;
    if(ctx) {
        TSK_OBJECT_SAFE_FREE(ctx->local);
        TSK_OBJECT_SAFE_FREE(ctx->remote);
        TSK_OBJECT_SAFE_FREE(ctx->negotiated);
    }
    return self;
}

static const tsk_object_def_t tsdp_ctx_def_s = {
    sizeof(tsdp_ctx_t),
    tsdp_ctx_create,
    tsdp_ctx_destroy,
    tsk_null,
};
const tsk_object_def_t *tsdp_ctx_def_t = &tsdp_ctx_def_s;
OpenPOWER on IntegriCloud