]> sjero.net Git - linphone/blob - coreapi/sal.c
sal is code complete !
[linphone] / coreapi / sal.c
1 /*
2 linphone
3 Copyright (C) 2010  Simon MORLAT (simon.morlat@free.fr)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 /** 
21  This header files defines the Signaling Abstraction Layer.
22  The purpose of this layer is too allow experiment different call signaling 
23  protocols and implementations under linphone, for example SIP, JINGLE...
24 **/
25
26 #include "sal.h"
27
28 SalMediaDescription *sal_media_description_new(){
29         return ms_new0(SalMediaDescription,1);
30 }
31
32 void sal_media_description_destroy(SalMediaDescription *md){
33         int i;
34         for(i=0;i<SAL_MEDIA_DESCRIPTION_MAX_STREAMS;i++){
35                 ms_list_for_each(md->streams[i].payloads,(void (*)(void *))payload_type_destroy);
36                 ms_list_free(md->streams[i].payloads);
37         }
38         ms_free(md);
39 }
40
41 static void assign_string(char **str, const char *arg){
42         if (*str){
43                 ms_free(*str);
44                 *str=NULL;
45         }
46         if (arg)
47                 *str=ms_strdup(arg);
48 }
49
50 void sal_op_set_contact(SalOp *op, const char *contact){
51         assign_string(&((SalOpBase*)op)->contact,contact);
52 }
53
54 void sal_op_set_route(SalOp *op, const char *route){
55         assign_string(&((SalOpBase*)op)->route,route);
56 }
57
58 void sal_op_set_from(SalOp *op, const char *from){
59         assign_string(&((SalOpBase*)op)->from,from);
60 }
61
62 void sal_op_set_to(SalOp *op, const char *to){
63         assign_string(&((SalOpBase*)op)->to,to);
64 }
65
66 void sal_op_set_user_pointer(SalOp *op, void *up){
67         ((SalOpBase*)op)->user_pointer=up;
68 }
69
70 const char *sal_op_get_from(const SalOp *op){
71         return ((SalOpBase*)op)->from;
72 }
73
74 const char *sal_op_get_to(const SalOp *op){
75         return ((SalOpBase*)op)->to;
76 }
77
78 const char *sal_op_get_contact(const SalOp *op){
79         return ((SalOpBase*)op)->contact;
80 }
81
82 const char *sal_op_get_route(const SalOp *op){
83         return ((SalOpBase*)op)->route;
84 }
85
86 void *sal_op_get_user_pointer(const SalOp *op){
87         return ((SalOpBase*)op)->user_pointer;
88 }
89
90 void __sal_op_init(SalOp *b, Sal *sal){
91         memset(b,0,sizeof(SalOpBase));
92         ((SalOpBase*)b)->root=sal;
93 }
94
95 void __sal_op_free(SalOp *op){
96         SalOpBase *b=(SalOpBase *)op;
97         if (b->from) {
98                 ms_free(b->from);
99                 b->from=NULL;
100         }
101         if (b->to) {
102                 ms_free(b->to);
103                 b->to=NULL;
104         }
105         if (b->route) {
106                 ms_free(b->route);
107                 b->route=NULL;
108         }
109         if (b->contact) {
110                 ms_free(b->contact);
111                 b->contact=NULL;
112         }
113         if (b->local_media)
114                 sal_media_description_destroy(b->local_media);
115         if (b->remote_media)
116                 sal_media_description_destroy(b->remote_media);
117         ms_free(op);
118 }