~ubuntu-branches/ubuntu/trusty/linphone/trusty

« back to all changes in this revision

Viewing changes to .pc/port-to-exosip-4.patch/coreapi/presence.c

  • Committer: Package Import Robot
  • Author(s): Luk Claes
  • Date: 2013-09-11 19:08:43 UTC
  • mfrom: (1.1.19) (16.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20130911190843-fkydjxsdvy1fmx24
Tags: 3.6.1-2.1
* Non-maintainer upload.
* Apply Sebastian Ramacher's patch to fix FTBFS (Closes: #720668).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
linphone
 
3
Copyright (C) 2000  Simon MORLAT (simon.morlat@linphone.org)
 
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
#include "linphonecore.h"
 
21
#include "private.h"
 
22
 
 
23
 
 
24
extern const char *__policy_enum_to_str(LinphoneSubscribePolicy pol);
 
25
 
 
26
 
 
27
void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalOp *op){
 
28
        LinphoneFriend *fl=linphone_friend_new_with_addr(subscriber);
 
29
        if (fl==NULL) return ;
 
30
        fl->insub=op;
 
31
        linphone_friend_set_inc_subscribe_policy(fl,LinphoneSPAccept);
 
32
        fl->inc_subscribe_pending=TRUE;
 
33
        lc->subscribers=ms_list_append(lc->subscribers,(void *)fl);
 
34
        if (lc->vtable.new_subscription_request!=NULL) {
 
35
                char *tmp=linphone_address_as_string(fl->uri);
 
36
                lc->vtable.new_subscription_request(lc,fl,tmp);
 
37
                ms_free(tmp);
 
38
        }
 
39
}
 
40
 
 
41
void linphone_core_reject_subscriber(LinphoneCore *lc, LinphoneFriend *lf){
 
42
        linphone_friend_set_inc_subscribe_policy(lf,LinphoneSPDeny);
 
43
}
 
44
 
 
45
void linphone_core_notify_all_friends(LinphoneCore *lc, LinphoneOnlineStatus os){
 
46
        MSList *elem;
 
47
        ms_message("Notifying all friends that we are in status %i",os);
 
48
        for(elem=lc->friends;elem!=NULL;elem=elem->next){
 
49
                LinphoneFriend *lf=(LinphoneFriend *)elem->data;
 
50
                if (lf->insub){
 
51
                        linphone_friend_notify(lf,os);
 
52
                }
 
53
        }
 
54
}
 
55
 
 
56
void linphone_subscription_new(LinphoneCore *lc, SalOp *op, const char *from){
 
57
        LinphoneFriend *lf=NULL;
 
58
        char *tmp;
 
59
        LinphoneAddress *uri;
 
60
        LinphoneProxyConfig *cfg;
 
61
        const char *fixed_contact;
 
62
        
 
63
        uri=linphone_address_new(from);
 
64
        linphone_address_clean(uri);
 
65
        tmp=linphone_address_as_string(uri);
 
66
        ms_message("Receiving new subscription from %s.",from);
 
67
 
 
68
        cfg=linphone_core_lookup_known_proxy(lc,uri);
 
69
        if (cfg!=NULL){
 
70
                if (cfg->op){
 
71
                        fixed_contact=sal_op_get_contact(cfg->op);
 
72
                        if (fixed_contact) {
 
73
                                sal_op_set_contact (op,fixed_contact);
 
74
                                ms_message("Contact for next subscribe answer has been fixed using proxy to %s",fixed_contact);
 
75
                        }
 
76
                }
 
77
        }
 
78
        /* check if we answer to this subscription */
 
79
        if (linphone_find_friend(lc->friends,uri,&lf)!=NULL){
 
80
                lf->insub=op;
 
81
                lf->inc_subscribe_pending=TRUE;
 
82
                sal_subscribe_accept(op);
 
83
                linphone_friend_done(lf);       /*this will do all necessary actions */
 
84
        }else{
 
85
                /* check if this subscriber is in our black list */
 
86
                if (linphone_find_friend(lc->subscribers,uri,&lf)){
 
87
                        if (lf->pol==LinphoneSPDeny){
 
88
                                ms_message("Rejecting %s because we already rejected it once.",from);
 
89
                                sal_subscribe_decline(op);
 
90
                        }
 
91
                        else {
 
92
                                /* else it is in wait for approval state, because otherwise it is in the friend list.*/
 
93
                                ms_message("New subscriber found in friend list, in %s state.",__policy_enum_to_str(lf->pol));
 
94
                        }
 
95
                }else {
 
96
                        sal_subscribe_accept(op);
 
97
                        linphone_core_add_subscriber(lc,tmp,op);
 
98
                }
 
99
        }
 
100
        linphone_address_destroy(uri);
 
101
        ms_free(tmp);
 
102
}
 
103
 
 
104
void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, SalPresenceStatus sal_status){
 
105
        char *tmp;
 
106
        LinphoneFriend *lf;
 
107
        LinphoneAddress *friend=NULL;
 
108
        LinphoneOnlineStatus estatus=LinphoneStatusOffline;
 
109
        
 
110
        switch(sal_status){
 
111
                case SalPresenceOffline:
 
112
                        estatus=LinphoneStatusOffline;
 
113
                break;
 
114
                case SalPresenceOnline:
 
115
                        estatus=LinphoneStatusOnline;
 
116
                break;
 
117
                case SalPresenceBusy:
 
118
                        estatus=LinphoneStatusBusy;
 
119
                break;
 
120
                case SalPresenceBerightback:
 
121
                        estatus=LinphoneStatusBeRightBack;
 
122
                break;
 
123
                case SalPresenceAway:
 
124
                        estatus=LinphoneStatusAway;
 
125
                break;
 
126
                case SalPresenceOnthephone:
 
127
                        estatus=LinphoneStatusOnThePhone;
 
128
                break;
 
129
                case SalPresenceOuttolunch:
 
130
                        estatus=LinphoneStatusOutToLunch;
 
131
                break;
 
132
                case SalPresenceDonotdisturb:
 
133
                        estatus=LinphoneStatusDoNotDisturb;
 
134
                break;
 
135
                case SalPresenceMoved:
 
136
                case SalPresenceAltService:
 
137
                        estatus=LinphoneStatusMoved;
 
138
                break;
 
139
        }
 
140
        lf=linphone_find_friend_by_out_subscribe(lc->friends,op);
 
141
        if (lf!=NULL){
 
142
                friend=lf->uri;
 
143
                tmp=linphone_address_as_string(friend);
 
144
                lf->status=estatus;
 
145
                lf->subscribe_active=TRUE;
 
146
                if (lc->vtable.notify_presence_recv)
 
147
                        lc->vtable.notify_presence_recv(lc,(LinphoneFriend*)lf);
 
148
                ms_free(tmp);
 
149
        }else{
 
150
                ms_message("But this person is not part of our friend list, so we don't care.");
 
151
        }
 
152
        if (ss==SalSubscribeTerminated){
 
153
                sal_op_release(op);
 
154
                if (lf){
 
155
                        lf->outsub=NULL;
 
156
                        lf->subscribe_active=FALSE;
 
157
                }
 
158
        }
 
159
}
 
160
 
 
161
void linphone_subscription_closed(LinphoneCore *lc, SalOp *op){
 
162
        LinphoneFriend *lf;
 
163
        lf=linphone_find_friend_by_inc_subscribe(lc->friends,op);
 
164
        sal_op_release(op);
 
165
        if (lf!=NULL){
 
166
                lf->insub=NULL;
 
167
        }else{
 
168
                ms_warning("Receiving unsuscribe for unknown in-subscribtion from %s", sal_op_get_from(op));
 
169
        }
 
170
}