Commit c58e884e authored by smorlat's avatar smorlat
Browse files

use buddy lookup to display buddy images in contact list (not finished).

buddy lookup important refactoring.

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@727 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 3536b484
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* friend.c * friend.c
* *
* Sat May 15 15:25:16 2004 * Sat May 15 15:25:16 2004
* Copyright 2004 Simon Morlat * Copyright 2004-2009 Simon Morlat
* Email * Email
****************************************************************************/ ****************************************************************************/
...@@ -561,6 +561,7 @@ void linphone_friend_destroy(LinphoneFriend *lf){ ...@@ -561,6 +561,7 @@ void linphone_friend_destroy(LinphoneFriend *lf){
linphone_friend_notify(lf,EXOSIP_SUBCRSTATE_TERMINATED,LINPHONE_STATUS_CLOSED); linphone_friend_notify(lf,EXOSIP_SUBCRSTATE_TERMINATED,LINPHONE_STATUS_CLOSED);
linphone_friend_unsubscribe(lf); linphone_friend_unsubscribe(lf);
if (lf->url!=NULL) osip_from_free(lf->url); if (lf->url!=NULL) osip_from_free(lf->url);
if (lf->info!=NULL) buddy_info_free(lf->info);
ms_free(lf); ms_free(lf);
} }
...@@ -606,6 +607,9 @@ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){ ...@@ -606,6 +607,9 @@ LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf){
return lf->status; return lf->status;
} }
BuddyInfo * linphone_friend_get_info(const LinphoneFriend *lf){
return lf->info;
}
void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc){ void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc){
if (fr->url==NULL) { if (fr->url==NULL) {
...@@ -638,6 +642,7 @@ void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc){ ...@@ -638,6 +642,7 @@ void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc){
__linphone_friend_do_subscribe(fr); __linphone_friend_do_subscribe(fr);
} }
ms_message("linphone_friend_apply() done."); ms_message("linphone_friend_apply() done.");
lc->bl_refresh=TRUE;
} }
void linphone_friend_edit(LinphoneFriend *fr){ void linphone_friend_edit(LinphoneFriend *fr){
...@@ -667,6 +672,31 @@ void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend* fl){ ...@@ -667,6 +672,31 @@ void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend* fl){
} }
} }
static bool_t username_match(const char *u1, const char *u2){
if (u1==NULL && u2==NULL) return TRUE;
if (u1 && u2 && strcasecmp(u1,u2)==0) return TRUE;
return FALSE;
}
LinphoneFriend *linphone_core_get_friend_by_uri(const LinphoneCore *lc, const char *uri){
osip_from_t *from;
osip_from_init(&from);
const MSList *elem;
if (osip_from_parse(from,uri)!=0){
osip_from_free(from);
return NULL;
}
for(elem=lc->friends;elem!=NULL;elem=ms_list_next(elem)){
LinphoneFriend *lf=(LinphoneFriend*)elem->data;
const char *it_username=lf->url->url->username;
const char *it_host=lf->url->url->host;
if (strcasecmp(from->url->host,it_host)==0 && username_match(from->url->username,it_username)){
return lf;
}
}
return NULL;
}
#define key_compare(key, word) strncasecmp((key),(word),strlen(key)) #define key_compare(key, word) strncasecmp((key),(word),strlen(key))
LinphoneSubscribePolicy __policy_str_to_enum(const char* pol){ LinphoneSubscribePolicy __policy_str_to_enum(const char* pol){
......
...@@ -1036,6 +1036,77 @@ static void proxy_update(LinphoneCore *lc, time_t curtime){ ...@@ -1036,6 +1036,77 @@ static void proxy_update(LinphoneCore *lc, time_t curtime){
if (doit) ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update); if (doit) ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
} }
static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
LinphoneFriend *lf=linphone_core_get_friend_by_uri(lc,info->sip_uri);
if (lf!=NULL){
lf->info=info;
ms_message("%s has a BuddyInfo assigned.",info->sip_uri);
}else{
ms_warning("Could not any friend with uri %s",info->sip_uri);
}
}
static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
MSList *elem;
SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
if (req->results!=NULL){
BuddyInfo *i=(BuddyInfo*)req->results->data;
ms_list_free(req->results);
req->results=NULL;
assign_buddy_info(lc,i);
}
sip_setup_context_buddy_lookup_free(ctx,req);
elem->data=NULL;
}
}
/*purge completed requests */
while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
}
}
static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
const MSList *elem;
SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
LinphoneFriend *lf=(LinphoneFriend*)elem->data;
if (lf->info==NULL){
char *url=linphone_friend_get_url(lf);
if (linphone_core_lookup_known_proxy(lc,url)==cfg){
char *name=linphone_friend_get_name(lf);
if (name!=NULL && strlen(name)>0){
BuddyLookupRequest *req;
req=sip_setup_context_create_buddy_lookup_request(ctx);
buddy_lookup_request_set_key(req,name);
buddy_lookup_request_set_max_results(req,1);
sip_setup_context_buddy_lookup_submit(ctx,req);
lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
}
ms_free(name);
}
ms_free(url);
}
}
}
static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
LinphoneProxyConfig *cfg=NULL;
linphone_core_get_default_proxy(lc,&cfg);
if (cfg){
if (lc->bl_refresh){
SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
linphone_core_grab_buddy_infos(lc,cfg);
lc->bl_refresh=FALSE;
}
}
if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
}
}
void linphone_core_iterate(LinphoneCore *lc) void linphone_core_iterate(LinphoneCore *lc)
{ {
eXosip_event_t *ev; eXosip_event_t *ev;
...@@ -1109,6 +1180,9 @@ void linphone_core_iterate(LinphoneCore *lc) ...@@ -1109,6 +1180,9 @@ void linphone_core_iterate(LinphoneCore *lc)
} }
if (disconnected) if (disconnected)
linphone_core_disconnected(lc); linphone_core_disconnected(lc);
linphone_core_do_plugin_tasks(lc);
if (one_second_elapsed && lp_config_needs_commit(lc->config)){ if (one_second_elapsed && lp_config_needs_commit(lc->config)){
lp_config_sync(lc->config); lp_config_sync(lc->config);
} }
...@@ -1197,7 +1271,10 @@ bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, char **rea ...@@ -1197,7 +1271,10 @@ bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, char **rea
osip_from_free(uri); osip_from_free(uri);
return FALSE; return FALSE;
} }
sipaddr=ortp_strdup_printf("sip:%s@%s",url,uri->url->host); if (uri->url->port!=NULL && uri->url->port[0]!='\0')
sipaddr=ortp_strdup_printf("sip:%s@%s:%s",url,uri->url->host,uri->url->port);
else
sipaddr=ortp_strdup_printf("sip:%s@%s",url,uri->url->host);
if (real_parsed_url!=NULL) *real_parsed_url=osip_to_create(sipaddr); if (real_parsed_url!=NULL) *real_parsed_url=osip_to_create(sipaddr);
if (real_url!=NULL) *real_url=sipaddr; if (real_url!=NULL) *real_url=sipaddr;
else ms_free(sipaddr); else ms_free(sipaddr);
......
...@@ -212,6 +212,7 @@ typedef struct _LinphoneFriend{ ...@@ -212,6 +212,7 @@ typedef struct _LinphoneFriend{
LinphoneOnlineStatus status; LinphoneOnlineStatus status;
struct _LinphoneProxyConfig *proxy; struct _LinphoneProxyConfig *proxy;
struct _LinphoneCore *lc; struct _LinphoneCore *lc;
BuddyInfo *info;
bool_t subscribe; bool_t subscribe;
bool_t inc_subscribe_pending; bool_t inc_subscribe_pending;
}LinphoneFriend; }LinphoneFriend;
...@@ -233,6 +234,7 @@ char *linphone_friend_get_url(LinphoneFriend *lf); /* name <sip address> */ ...@@ -233,6 +234,7 @@ char *linphone_friend_get_url(LinphoneFriend *lf); /* name <sip address> */
bool_t linphone_friend_get_send_subscribe(const LinphoneFriend *lf); bool_t linphone_friend_get_send_subscribe(const LinphoneFriend *lf);
LinphoneSubscribePolicy linphone_friend_get_inc_subscribe_policy(const LinphoneFriend *lf); LinphoneSubscribePolicy linphone_friend_get_inc_subscribe_policy(const LinphoneFriend *lf);
LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf); LinphoneOnlineStatus linphone_friend_get_status(const LinphoneFriend *lf);
BuddyInfo * linphone_friend_get_info(const LinphoneFriend *lf);
#define linphone_friend_in_list(lf) ((lf)->lc!=NULL) #define linphone_friend_in_list(lf) ((lf)->lc!=NULL)
#define linphone_friend_url(lf) ((lf)->url) #define linphone_friend_url(lf) ((lf)->url)
...@@ -477,6 +479,7 @@ typedef struct _LinphoneCore ...@@ -477,6 +479,7 @@ typedef struct _LinphoneCore
struct _VideoStream *videostream; struct _VideoStream *videostream;
struct _VideoStream *previewstream; struct _VideoStream *previewstream;
struct _RtpProfile *local_profile; struct _RtpProfile *local_profile;
MSList *bl_reqs;
MSList *subscribers; /* unknown subscribers */ MSList *subscribers; /* unknown subscribers */
int minutes_away; int minutes_away;
LinphoneOnlineStatus presence_mode; LinphoneOnlineStatus presence_mode;
...@@ -501,6 +504,7 @@ typedef struct _LinphoneCore ...@@ -501,6 +504,7 @@ typedef struct _LinphoneCore
bool_t use_files; bool_t use_files;
bool_t apply_nat_settings; bool_t apply_nat_settings;
bool_t ready; bool_t ready;
bool_t bl_refresh;
#ifdef VINCENT_MAURY_RSVP #ifdef VINCENT_MAURY_RSVP
/* QoS parameters*/ /* QoS parameters*/
int rsvp_enable; int rsvp_enable;
...@@ -695,6 +699,7 @@ void linphone_core_reject_subscriber(LinphoneCore *lc, LinphoneFriend *lf); ...@@ -695,6 +699,7 @@ void linphone_core_reject_subscriber(LinphoneCore *lc, LinphoneFriend *lf);
const MSList * linphone_core_get_friend_list(LinphoneCore *lc); const MSList * linphone_core_get_friend_list(LinphoneCore *lc);
/* notify all friends that have subscribed */ /* notify all friends that have subscribed */
void linphone_core_notify_all_friends(LinphoneCore *lc, LinphoneOnlineStatus os); void linphone_core_notify_all_friends(LinphoneCore *lc, LinphoneOnlineStatus os);
LinphoneFriend *linphone_core_get_friend_by_uri(const LinphoneCore *lc, const char *uri);
/* returns a list of LinphoneCallLog */ /* returns a list of LinphoneCallLog */
MSList * linphone_core_get_call_logs(LinphoneCore *lc); MSList * linphone_core_get_call_logs(LinphoneCore *lc);
......
...@@ -9,18 +9,15 @@ ...@@ -9,18 +9,15 @@
static bool_t buddy_lookup_init(void){ static bool_t buddy_lookup_init(void){
return TRUE; return TRUE;
} };
typedef struct _BuddyLookupState{ typedef struct _BLReq{
SoupSession *session; BuddyLookupRequest base;
BuddyLookupStatus status;
SoupMessage *msg; SoupMessage *msg;
SoupSession *session;
ortp_thread_t th; ortp_thread_t th;
MSList *results; }BLReq;
bool_t processing;
}BuddyLookupState;
#define get_buddy_lookup_state(ctx) ((BuddyLookupState*)((ctx)->data))
void set_proxy(SoupSession *session, const char *proxy){ void set_proxy(SoupSession *session, const char *proxy){
SoupURI *uri=soup_uri_new(proxy); SoupURI *uri=soup_uri_new(proxy);
...@@ -29,21 +26,12 @@ void set_proxy(SoupSession *session, const char *proxy){ ...@@ -29,21 +26,12 @@ void set_proxy(SoupSession *session, const char *proxy){
} }
static void buddy_lookup_instance_init(SipSetupContext *ctx){ static void buddy_lookup_instance_init(SipSetupContext *ctx){
BuddyLookupState *s=ms_new0(BuddyLookupState,1);
const char *proxy=NULL;
s->session=soup_session_sync_new();
proxy=getenv("http_proxy");
if (proxy && strlen(proxy)>0) set_proxy(s->session,proxy);
ctx->data=s;
} }
static void buddy_lookup_instance_uninit(SipSetupContext *ctx){ static void buddy_lookup_instance_uninit(SipSetupContext *ctx){
BuddyLookupState *s=get_buddy_lookup_state(ctx);
g_object_unref(G_OBJECT(s->session));
ms_free(s);
} }
static SoupMessage * build_xmlrpc_request(const char *identity, const char *password, const char *key, const char *domain, const char *url){ static SoupMessage * build_xmlrpc_request(const char *identity, const char *password, const char *key, const char *domain, const char *url, int max_results){
SoupMessage * msg; SoupMessage * msg;
msg=soup_xmlrpc_request_new(url, msg=soup_xmlrpc_request_new(url,
...@@ -51,7 +39,7 @@ static SoupMessage * build_xmlrpc_request(const char *identity, const char *pass ...@@ -51,7 +39,7 @@ static SoupMessage * build_xmlrpc_request(const char *identity, const char *pass
G_TYPE_STRING, identity, G_TYPE_STRING, identity,
G_TYPE_STRING, password ? password : "", G_TYPE_STRING, password ? password : "",
G_TYPE_STRING, key, G_TYPE_STRING, key,
G_TYPE_INT , 100, G_TYPE_INT , max_results,
G_TYPE_INT , 0, G_TYPE_INT , 0,
G_TYPE_STRING, domain, G_TYPE_STRING, domain,
G_TYPE_INVALID); G_TYPE_INVALID);
...@@ -65,10 +53,9 @@ static SoupMessage * build_xmlrpc_request(const char *identity, const char *pass ...@@ -65,10 +53,9 @@ static SoupMessage * build_xmlrpc_request(const char *identity, const char *pass
return msg; return msg;
} }
static void got_headers(SipSetupContext *ctx, SoupMessage*msg){ static void got_headers(BLReq *blreq, SoupMessage*msg){
BuddyLookupState *s=get_buddy_lookup_state(ctx);
ms_message("Got headers !"); ms_message("Got headers !");
s->status=BuddyLookupConnected; blreq->base.status=BuddyLookupConnected;
} }
static void fill_item(GHashTable *ht , const char *name, char *dest, size_t dest_size){ static void fill_item(GHashTable *ht , const char *name, char *dest, size_t dest_size){
...@@ -81,7 +68,7 @@ static void fill_item(GHashTable *ht , const char *name, char *dest, size_t dest ...@@ -81,7 +68,7 @@ static void fill_item(GHashTable *ht , const char *name, char *dest, size_t dest
}else ms_warning("no field named '%s'", name); }else ms_warning("no field named '%s'", name);
} }
static void fill_buddy_info(BuddyLookupState *s, BuddyInfo *bi, GHashTable *ht){ static void fill_buddy_info(BLReq *blreq, BuddyInfo *bi, GHashTable *ht){
char tmp[256]; char tmp[256];
fill_item(ht,"first_name",bi->firstname,sizeof(bi->firstname)); fill_item(ht,"first_name",bi->firstname,sizeof(bi->firstname));
fill_item(ht,"last_name",bi->lastname,sizeof(bi->lastname)); fill_item(ht,"last_name",bi->lastname,sizeof(bi->lastname));
...@@ -105,7 +92,7 @@ static void fill_buddy_info(BuddyLookupState *s, BuddyInfo *bi, GHashTable *ht){ ...@@ -105,7 +92,7 @@ static void fill_buddy_info(BuddyLookupState *s, BuddyInfo *bi, GHashTable *ht){
guint status; guint status;
ms_message("This buddy has an image, let's download it: %s",tmp); ms_message("This buddy has an image, let's download it: %s",tmp);
msg=soup_message_new("GET",tmp); msg=soup_message_new("GET",tmp);
if ((status=soup_session_send_message(s->session,msg))==200){ if ((status=soup_session_send_message(blreq->session,msg))==200){
SoupMessageBody *body=msg->response_body; SoupMessageBody *body=msg->response_body;
ms_message("Received %i bytes",body->length); ms_message("Received %i bytes",body->length);
strncpy(bi->image_type,"png",sizeof(bi->image_type)); strncpy(bi->image_type,"png",sizeof(bi->image_type));
...@@ -119,7 +106,7 @@ static void fill_buddy_info(BuddyLookupState *s, BuddyInfo *bi, GHashTable *ht){ ...@@ -119,7 +106,7 @@ static void fill_buddy_info(BuddyLookupState *s, BuddyInfo *bi, GHashTable *ht){
} }
static MSList * make_buddy_list(BuddyLookupState *s, GValue *retval){ static MSList * make_buddy_list(BLReq *blreq, GValue *retval){
MSList *ret=NULL; MSList *ret=NULL;
if (G_VALUE_TYPE(retval)==G_TYPE_VALUE_ARRAY){ if (G_VALUE_TYPE(retval)==G_TYPE_VALUE_ARRAY){
GValueArray *array=(GValueArray*)g_value_get_boxed(retval); GValueArray *array=(GValueArray*)g_value_get_boxed(retval);
...@@ -130,7 +117,7 @@ static MSList * make_buddy_list(BuddyLookupState *s, GValue *retval){ ...@@ -130,7 +117,7 @@ static MSList * make_buddy_list(BuddyLookupState *s, GValue *retval){
if (G_VALUE_TYPE(gelem)==G_TYPE_HASH_TABLE){ if (G_VALUE_TYPE(gelem)==G_TYPE_HASH_TABLE){
GHashTable *ht=(GHashTable*)g_value_get_boxed(gelem); GHashTable *ht=(GHashTable*)g_value_get_boxed(gelem);
BuddyInfo *bi=buddy_info_new(); BuddyInfo *bi=buddy_info_new();
fill_buddy_info(s,bi,ht); fill_buddy_info(blreq,bi,ht);
ret=ms_list_append(ret,bi); ret=ms_list_append(ret,bi);
}else{ }else{
ms_error("Element is not a hash table"); ms_error("Element is not a hash table");
...@@ -141,8 +128,7 @@ static MSList * make_buddy_list(BuddyLookupState *s, GValue *retval){ ...@@ -141,8 +128,7 @@ static MSList * make_buddy_list(BuddyLookupState *s, GValue *retval){
} }
static int xml_rpc_parse_response(SipSetupContext *ctx, SoupMessage *sm){ static int xml_rpc_parse_response(BLReq *blreq, SoupMessage *sm){
BuddyLookupState *s=get_buddy_lookup_state(ctx);
SoupBuffer *sb; SoupBuffer *sb;
GValue retval; GValue retval;
GError *error=NULL; GError *error=NULL;
...@@ -155,38 +141,35 @@ static int xml_rpc_parse_response(SipSetupContext *ctx, SoupMessage *sm){ ...@@ -155,38 +141,35 @@ static int xml_rpc_parse_response(SipSetupContext *ctx, SoupMessage *sm){
}else{ }else{
ms_error("Could not parse xml-rpc response !"); ms_error("Could not parse xml-rpc response !");
} }
s->status=BuddyLookupFailure; blreq->base.status=BuddyLookupFailure;
}else{ }else{
ms_message("Extracting values from return type..."); ms_message("Extracting values from return type...");
s->results=make_buddy_list(s,&retval); blreq->base.results=make_buddy_list(blreq,&retval);
g_value_unset(&retval); g_value_unset(&retval);
s->status=BuddyLookupDone; blreq->base.status=BuddyLookupDone;
} }
soup_buffer_free(sb); soup_buffer_free(sb);
return s->status==BuddyLookupDone ? 0 : -1; return blreq->base.status==BuddyLookupDone ? 0 : -1;
} }
static void * process_xml_rpc_request(void *up){ static void * process_xml_rpc_request(void *up){
SipSetupContext *ctx=(SipSetupContext*)up; BLReq *blreq=(BLReq*)up;
BuddyLookupState *s=get_buddy_lookup_state(ctx); SoupMessage *sm=blreq->msg;
SoupMessage *sm=s->msg;
int code; int code;
g_signal_connect_swapped(G_OBJECT(sm),"got-headers",(GCallback)got_headers,ctx); g_signal_connect_swapped(G_OBJECT(sm),"got-headers",(GCallback)got_headers,blreq);
s->status=BuddyLookupConnecting; blreq->base.status=BuddyLookupConnecting;
code=soup_session_send_message(s->session,sm); code=soup_session_send_message(blreq->session,sm);
if (code==200){ if (code==200){
ms_message("Got a response from server, yeah !"); ms_message("Got a response from server, yeah !");
xml_rpc_parse_response(ctx,sm); xml_rpc_parse_response(blreq,sm);
}else{ }else{
ms_error("request failed, error-code=%i (%s)",code,soup_status_get_phrase(code)); ms_error("request failed, error-code=%i (%s)",code,soup_status_get_phrase(code));
s->status=BuddyLookupFailure; blreq->base.status=BuddyLookupFailure;
} }
s->processing=FALSE;
return NULL; return NULL;
} }
static int lookup_buddy(SipSetupContext *ctx, const char *key){ static int lookup_buddy(SipSetupContext *ctx, BLReq *req){
BuddyLookupState *s=get_buddy_lookup_state(ctx);
LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx);
LinphoneCore *lc=linphone_proxy_config_get_core(cfg); LinphoneCore *lc=linphone_proxy_config_get_core(cfg);
LpConfig *config=linphone_core_get_config(lc); LpConfig *config=linphone_core_get_config(lc);
...@@ -199,15 +182,6 @@ static int lookup_buddy(SipSetupContext *ctx, const char *key){ ...@@ -199,15 +182,6 @@ static int lookup_buddy(SipSetupContext *ctx, const char *key){
ms_error("No url defined for BuddyLookup in config file, aborting search."); ms_error("No url defined for BuddyLookup in config file, aborting search.");
return -1; return -1;
} }
if (s->th!=0){
if (s->processing){
ms_message("Canceling previous request...");
soup_session_cancel_message(s->session,s->msg, SOUP_STATUS_CANCELLED);
}
ortp_thread_join(s->th,NULL);
s->th=0;
g_object_unref(G_OBJECT(s->msg));
}
osip_from_t *from; osip_from_t *from;
osip_from_init(&from); osip_from_init(&from);
...@@ -219,42 +193,61 @@ static int lookup_buddy(SipSetupContext *ctx, const char *key){ ...@@ -219,42 +193,61 @@ static int lookup_buddy(SipSetupContext *ctx, const char *key){
aa=linphone_core_find_auth_info(lc,from->url->host,from->url->username); aa=linphone_core_find_auth_info(lc,from->url->host,from->url->username);
if (aa) ms_message("There is a password: %s",aa->passwd); if (aa) ms_message("There is a password: %s",aa->passwd);
else ms_message("No password for %s on %s",from->url->username,from->url->host); else ms_message("No password for %s on %s",from->url->username,from->url->host);
sm=build_xmlrpc_request(identity, aa ? aa->passwd : NULL, key, from->url->host, url); sm=build_xmlrpc_request(identity, aa ? aa->passwd : NULL, req->base.key, from->url->host, url, req->base.max_results);
osip_from_free(from); osip_from_free(from);
s->msg=sm; req->msg=sm;
s->processing=TRUE; ortp_thread_create(&req->th,NULL,process_xml_rpc_request,req);
ortp_thread_create(&s->th,NULL,process_xml_rpc_request,ctx);
if (!sm) return -1; if (!sm) return -1;
return 0; return 0;
} }
static BuddyLookupStatus get_buddy_lookup_status(SipSetupContext *ctx){ static BuddyLookupRequest * create_request(SipSetupContext *ctx){
BuddyLookupState *s=get_buddy_lookup_state(ctx); BLReq *req=ms_new0(BLReq,1);
return s->status; const char *proxy=NULL;
req->session=soup_session_sync_new();
proxy=getenv("http_proxy");
if (proxy && strlen(proxy)>0) set_proxy(req->session,proxy);
return (BuddyLookupRequest*)req;
}
static int submit_request(SipSetupContext *ctx, BuddyLookupRequest *req){
BLReq *blreq=(BLReq*)req;
return lookup_buddy(ctx,blreq);
} }
static int get_buddy_lookup_results(SipSetupContext *ctx, MSList **results){ static int free_request(SipSetupContext *ctx, BuddyLookupRequest *req){
BuddyLookupState *s=get_buddy_lookup_state(ctx); BLReq *blreq=(BLReq*)req;
if (s->results){ if (blreq->th!=0){
*results=s->results; soup_session_cancel_message(blreq->session,blreq->msg, SOUP_STATUS_CANCELLED);
s->results=NULL; ortp_thread_join(blreq->th,NULL);
blreq->th=0;
g_object_unref(G_OBJECT(blreq->msg));
} }
if (blreq->session)
g_object_unref(G_OBJECT(blreq->session));
buddy_lookup_request_free(req);
return 0; return 0;
} }
static void buddy_lookup_exit(void){ static void buddy_lookup_exit(void){
} }
static BuddyLookupFuncs bl_funcs={
.request_create=create_request,
.request_submit=submit_request,
.request_free=free_request
};
static SipSetup buddy_lookup_funcs={ static SipSetup buddy_lookup_funcs={
.name="BuddyLookup", .name="BuddyLookup",
.capabilities=SIP_SETUP_CAP_BUDDY_LOOKUP, .capabilities=SIP_SETUP_CAP_BUDDY_LOOKUP,
.init=buddy_lookup_init,