]> sjero.net Git - linphone/blob - coreapi/sal.c
sal in progress, near to 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         SalMediaDescription *md=ms_new0(SalMediaDescription,1);
30         md->refcount=1;
31         return md;
32 }
33
34 static void sal_media_description_destroy(SalMediaDescription *md){
35         int i;
36         for(i=0;i<SAL_MEDIA_DESCRIPTION_MAX_STREAMS;i++){
37                 ms_list_for_each(md->streams[i].payloads,(void (*)(void *))payload_type_destroy);
38                 ms_list_free(md->streams[i].payloads);
39         }
40         ms_free(md);
41 }
42
43 void sal_media_description_ref(SalMediaDescription *md){
44         md->refcount++;
45 }
46
47 void sal_media_description_unref(SalMediaDescription *md){
48         md->refcount--;
49         if (md->refcount==0){
50                 sal_media_description_destroy (md);
51         }
52 }
53
54 SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
55     SalMediaProto proto, SalStreamType type){
56         int i;
57         for(i=0;i<md->nstreams;++i){
58                 SalStreamDescription *ss=&md->streams[i];
59                 if (ss->proto==proto && ss->type==type) return ss;
60         }
61         return NULL;
62 }
63
64 bool_t sal_media_description_empty(SalMediaDescription *md){
65         int i;
66         for(i=0;i<md->nstreams;++i){
67                 SalStreamDescription *ss=&md->streams[i];
68                 if (ss->port!=0) return FALSE;
69         }
70         return TRUE;
71 }
72
73 static void assign_string(char **str, const char *arg){
74         if (*str){
75                 ms_free(*str);
76                 *str=NULL;
77         }
78         if (arg)
79                 *str=ms_strdup(arg);
80 }
81
82 void sal_op_set_contact(SalOp *op, const char *contact){
83         assign_string(&((SalOpBase*)op)->contact,contact);
84 }
85
86 void sal_op_set_route(SalOp *op, const char *route){
87         assign_string(&((SalOpBase*)op)->route,route);
88 }
89
90 void sal_op_set_from(SalOp *op, const char *from){
91         assign_string(&((SalOpBase*)op)->from,from);
92 }
93
94 void sal_op_set_to(SalOp *op, const char *to){
95         assign_string(&((SalOpBase*)op)->to,to);
96 }
97
98 void sal_op_set_user_pointer(SalOp *op, void *up){
99         ((SalOpBase*)op)->user_pointer=up;
100 }
101
102 Sal *sal_op_get_sal(const SalOp *op){
103         return ((SalOpBase*)op)->root;
104 }
105
106 const char *sal_op_get_from(const SalOp *op){
107         return ((SalOpBase*)op)->from;
108 }
109
110 const char *sal_op_get_to(const SalOp *op){
111         return ((SalOpBase*)op)->to;
112 }
113
114 const char *sal_op_get_contact(const SalOp *op){
115         return ((SalOpBase*)op)->contact;
116 }
117
118 const char *sal_op_get_route(const SalOp *op){
119         return ((SalOpBase*)op)->route;
120 }
121
122 void *sal_op_get_user_pointer(const SalOp *op){
123         return ((SalOpBase*)op)->user_pointer;
124 }
125
126 const char *sal_op_get_proxy(const SalOp *op){
127         return ((SalOpBase*)op)->route;
128 }
129
130 void __sal_op_init(SalOp *b, Sal *sal){
131         memset(b,0,sizeof(SalOpBase));
132         ((SalOpBase*)b)->root=sal;
133 }
134
135 void __sal_op_free(SalOp *op){
136         SalOpBase *b=(SalOpBase *)op;
137         if (b->from) {
138                 ms_free(b->from);
139                 b->from=NULL;
140         }
141         if (b->to) {
142                 ms_free(b->to);
143                 b->to=NULL;
144         }
145         if (b->route) {
146                 ms_free(b->route);
147                 b->route=NULL;
148         }
149         if (b->contact) {
150                 ms_free(b->contact);
151                 b->contact=NULL;
152         }
153         if (b->local_media)
154                 sal_media_description_unref(b->local_media);
155         if (b->remote_media)
156                 sal_media_description_unref(b->remote_media);
157         ms_free(op);
158 }