#include "linphonecore.h"
#include "private.h"
-#include <eXosip2/eXosip.h>
-#include <osipparser2/osip_message.h>
#include "lpconfig.h"
const char *linphone_online_status_to_string(LinphoneOnlineStatus ss){
const char *str=NULL;
switch(ss){
- case LINPHONE_STATUS_ONLINE:
+ case LinphoneStatusOnline:
str=_("Online");
break;
- case LINPHONE_STATUS_BUSY:
+ case LinphoneStatusBusy:
str=_("Busy");
break;
- case LINPHONE_STATUS_BERIGHTBACK:
+ case LinphoneStatusBeRightBack:
str=_("Be right back");
break;
- case LINPHONE_STATUS_AWAY:
+ case LinphoneStatusAway:
str=_("Away");
break;
- case LINPHONE_STATUS_ONTHEPHONE:
+ case LinphoneStatusOnThePhone:
str=_("On the phone");
break;
- case LINPHONE_STATUS_OUTTOLUNCH:
+ case LinphoneStatusOutToLunch:
str=_("Out to lunch");
break;
- case LINPHONE_STATUS_NOT_DISTURB:
+ case LinphoneStatusDoNotDisturb:
str=_("Do not disturb");
break;
- case LINPHONE_STATUS_MOVED:
+ case LinphoneStatusMoved:
str=_("Moved");
break;
- case LINPHONE_STATUS_ALT_SERVICE:
+ case LinphoneStatusAltService:
str=_("Using another messaging service");
break;
- case LINPHONE_STATUS_OFFLINE:
+ case LinphoneStatusOffline:
str=_("Offline");
break;
- case LINPHONE_STATUS_PENDING:
+ case LinphoneStatusPending:
str=_("Pending");
break;
default:
return str;
}
-static int friend_data_compare(const void * a, const void * b, void * data){
+static int friend_compare(const void * a, const void * b){
LinphoneAddress *fa=((LinphoneFriend*)a)->uri;
LinphoneAddress *fb=((LinphoneFriend*)b)->uri;
- const char *ua,*ub;
- ua=linphone_address_get_username(fa);
- ub=linphone_address_get_username(fb);
- if (ua!=NULL && ub!=NULL) {
- //printf("Comparing usernames %s,%s\n",ua,ub);
- return strcasecmp(ua,ub);
- }
- else {
- /* compare hosts*/
- ua=linphone_address_get_domain(fa);
- ub=linphone_address_get_domain(fb);
- if (ua!=NULL && ub!=NULL){
- int ret=strcasecmp(ua,ub);
- //printf("Comparing hostnames %s,%s,res=%i\n",ua,ub,ret);
- return ret;
- }
- else return -1;
- }
-}
-
-static int friend_compare(const void * a, const void * b){
- return friend_data_compare(a,b,NULL);
+ if (linphone_address_weak_equal (fa,fb)) return 0;
+ return 1;
}
char *friend=NULL;
const char *route=NULL;
const char *from=NULL;
+ const char *fixed_contact=NULL;
LinphoneProxyConfig *cfg;
friend=linphone_address_as_string(fr->uri);
if (cfg!=NULL){
route=linphone_proxy_config_get_route(cfg);
from=linphone_proxy_config_get_identity(cfg);
+ if (cfg->op){
+ fixed_contact=sal_op_get_contact(cfg->op);
+ if (fixed_contact) {
+ ms_message("Contact for subscribe has been fixed using proxy to %s",fixed_contact);
+ }
+ }
}else from=linphone_core_get_primary_contact(fr->lc);
if (fr->outsub==NULL){
/* people for which we don't have yet an answer should appear as offline */
- fr->status=LINPHONE_STATUS_OFFLINE;
+ fr->status=LinphoneStatusOffline;
/*
if (fr->lc->vtable.notify_recv)
fr->lc->vtable.notify_recv(fr->lc,(LinphoneFriend*)fr);
}
fr->outsub=sal_op_new(fr->lc->sal);
sal_op_set_route(fr->outsub,route);
+ sal_op_set_contact(fr->outsub,fixed_contact);
sal_subscribe_presence(fr->outsub,from,friend);
fr->subscribe_active=TRUE;
ms_free(friend);
LinphoneFriend * linphone_friend_new(){
LinphoneFriend *obj=ms_new0(LinphoneFriend,1);
obj->pol=LinphoneSPAccept;
- obj->status=LINPHONE_STATUS_OFFLINE;
+ obj->status=LinphoneStatusOffline;
obj->subscribe=TRUE;
return obj;
}
LinphoneFriend *linphone_friend_new_with_addr(const char *addr){
+ LinphoneAddress* linphone_address = linphone_address_new(addr);
+ if (linphone_address == NULL) {
+ ms_error("Cannot create friend for address [%s]",addr?addr:"null");
+ return NULL;
+ }
LinphoneFriend *fr=linphone_friend_new();
- if (linphone_friend_set_sip_addr(fr,addr)<0){
+ if (linphone_friend_set_addr(fr,linphone_address)<0){
linphone_friend_destroy(fr);
return NULL;
}
/*try adding domain part from default current proxy*/
LinphoneAddress * id=linphone_address_new(linphone_core_get_identity(lc));
if (id!=NULL){
+ linphone_address_set_display_name(id,NULL);
linphone_address_set_username(id,uri);
*result=linphone_address_as_string(id);
linphone_address_destroy(id);
linphone_address_destroy(fr);
}
-int linphone_friend_set_sip_addr(LinphoneFriend *lf, const char *addr){
- LinphoneAddress *fr=linphone_address_new(addr);
- if (fr==NULL) {
- ms_warning("Invalid friend sip uri: %s",addr);
- return -1;
- }
+int linphone_friend_set_addr(LinphoneFriend *lf, const LinphoneAddress *addr){
+ LinphoneAddress *fr=linphone_address_clone(addr);
linphone_address_clean(fr);
if (lf->uri!=NULL) linphone_address_destroy(lf->uri);
lf->uri=fr;
return 0;
}
-int linphone_friend_send_subscribe(LinphoneFriend *fr, bool_t val){
+int linphone_friend_enable_subscribes(LinphoneFriend *fr, bool_t val){
fr->subscribe=val;
return 0;
}
SalPresenceStatus linphone_online_status_to_sal(LinphoneOnlineStatus os){
switch(os){
- case LINPHONE_STATUS_OFFLINE:
+ case LinphoneStatusOffline:
return SalPresenceOffline;
break;
- case LINPHONE_STATUS_ONLINE:
+ case LinphoneStatusOnline:
return SalPresenceOnline;
break;
- case LINPHONE_STATUS_BUSY:
+ case LinphoneStatusBusy:
return SalPresenceBusy;
break;
- case LINPHONE_STATUS_BERIGHTBACK:
+ case LinphoneStatusBeRightBack:
return SalPresenceBerightback;
break;
- case LINPHONE_STATUS_AWAY:
+ case LinphoneStatusAway:
return SalPresenceAway;
break;
- case LINPHONE_STATUS_ONTHEPHONE:
+ case LinphoneStatusOnThePhone:
return SalPresenceOnthephone;
break;
- case LINPHONE_STATUS_OUTTOLUNCH:
+ case LinphoneStatusOutToLunch:
return SalPresenceOuttolunch;
break;
- case LINPHONE_STATUS_NOT_DISTURB:
+ case LinphoneStatusDoNotDisturb:
return SalPresenceDonotdisturb;
break;
- case LINPHONE_STATUS_MOVED:
+ case LinphoneStatusMoved:
return SalPresenceMoved;
break;
- case LINPHONE_STATUS_ALT_SERVICE:
+ case LinphoneStatusAltService:
return SalPresenceAltService;
break;
- case LINPHONE_STATUS_PENDING:
+ case LinphoneStatusPending:
return SalPresenceOffline;
break;
default:
}
void linphone_friend_notify(LinphoneFriend *lf, LinphoneOnlineStatus os){
- //printf("Wish to notify %p, lf->nid=%i\n",lf,lf->nid);
+ char *addr=linphone_address_as_string(linphone_friend_get_address(lf));
+ ms_message("Want to notify %s, insub=%p",addr,lf->insub);
+ ms_free(addr);
if (lf->insub!=NULL){
sal_notify_presence(lf->insub,linphone_online_status_to_sal(os),NULL);
}
static void linphone_friend_unsubscribe(LinphoneFriend *lf){
if (lf->outsub!=NULL) {
sal_unsubscribe(lf->outsub);
- sal_op_release(lf->outsub);
- lf->outsub=NULL;
lf->subscribe_active=FALSE;
}
}
linphone_friend_unsubscribe(lf);
if (lf->insub){
sal_notify_close(lf->insub);
- sal_op_release(lf->insub);
- lf->insub=NULL;
+
}
}
void linphone_friend_destroy(LinphoneFriend *lf){
-
+ if (lf->insub) {
+ sal_op_release(lf->insub);
+ lf->insub=NULL;
+ }
+ if (lf->outsub){
+ sal_op_release(lf->outsub);
+ lf->outsub=NULL;
+ }
if (lf->uri!=NULL) linphone_address_destroy(lf->uri);
if (lf->info!=NULL) buddy_info_free(lf->info);
ms_free(lf);
if (fr->inc_subscribe_pending){
switch(fr->pol){
case LinphoneSPWait:
- linphone_friend_notify(fr,LINPHONE_STATUS_PENDING);
+ linphone_friend_notify(fr,LinphoneStatusPending);
break;
case LinphoneSPAccept:
if (fr->lc!=NULL)
}
break;
case LinphoneSPDeny:
- linphone_friend_notify(fr,LINPHONE_STATUS_OFFLINE);
+ linphone_friend_notify(fr,LinphoneStatusOffline);
break;
}
fr->inc_subscribe_pending=FALSE;
}
ms_message("linphone_friend_apply() done.");
lc->bl_refresh=TRUE;
+ fr->commit=FALSE;
}
void linphone_friend_edit(LinphoneFriend *fr){
return ;
}
lc->friends=ms_list_append(lc->friends,lf);
- linphone_friend_apply(lf,lc);
+ if ( linphone_core_ready(lc)) linphone_friend_apply(lf,lc);
+ else lf->commit=TRUE;
return ;
}
void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend* fl){
MSList *el=ms_list_find(lc->friends,(void *)fl);
if (el!=NULL){
- lc->friends=ms_list_remove_link(lc->friends,el);
linphone_friend_destroy((LinphoneFriend*)el->data);
+ lc->friends=ms_list_remove_link(lc->friends,el);
linphone_core_write_friends_config(lc);
}
}
+void linphone_core_send_initial_subscribes(LinphoneCore *lc){
+ const MSList *elem;
+ for(elem=lc->friends;elem!=NULL;elem=elem->next){
+ LinphoneFriend *f=(LinphoneFriend*)elem->data;
+ if (f->commit)
+ linphone_friend_apply(f,lc);
+ }
+}
+
void linphone_friend_set_ref_key(LinphoneFriend *lf, const char *key){
if (lf->refkey!=NULL){
ms_free(lf->refkey);
LinphoneFriend *linphone_core_get_friend_by_address(const LinphoneCore *lc, const char *uri){
LinphoneAddress *puri=linphone_address_new(uri);
const MSList *elem;
- const char *username=linphone_address_get_username(puri);
- const char *domain=linphone_address_get_domain(puri);
+ const char *username;
+ const char *domain;
LinphoneFriend *lf=NULL;
if (puri==NULL){
return NULL;
}
+ username=linphone_address_get_username(puri);
+ domain=linphone_address_get_domain(puri);
+ if (domain==NULL) {
+ linphone_address_destroy(puri);
+ return NULL;
+ }
for(elem=lc->friends;elem!=NULL;elem=ms_list_next(elem)){
lf=(LinphoneFriend*)elem->data;
const char *it_username=linphone_address_get_username(lf->uri);
return;
}
lp_config_set_string(config,key,"url",tmp);
- osip_free(tmp);
+ ms_free(tmp);
}
lp_config_set_string(config,key,"pol",__policy_enum_to_str(lf->pol));
lp_config_set_int(config,key,"subscribe",lf->subscribe);
{
MSList *elem;
int i;
- if (!lc->ready) return; /*dont write config when reading it !*/
+ if (! linphone_core_ready(lc)) return; /*dont write config when reading it !*/
for (elem=lc->friends,i=0; elem!=NULL; elem=ms_list_next(elem),i++){
linphone_friend_write_to_config_file(lc->config,(LinphoneFriend*)elem->data,i);
}