]> sjero.net Git - linphone/commitdiff
add proxy support to buddy_status tutorial
authorJehan Monnier <jehan.monnier@linphone.org>
Fri, 3 Dec 2010 09:02:29 +0000 (10:02 +0100)
committerJehan Monnier <jehan.monnier@linphone.org>
Fri, 3 Dec 2010 09:02:29 +0000 (10:02 +0100)
coreapi/help/buddy_status.c
coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java

index 3791229742e030436db382c8e524c5ce7859b76c..6fdb47f4099955db99340f7990134441241a82e8 100644 (file)
@@ -66,19 +66,36 @@ static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *friend,
        linphone_core_add_friend(lc,friend); /* add this new friend to the buddy list*/
 
 }
+/**
+ * Registration state notification callback
+ */
+static void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message){
+               printf("New registration state %s for user id [%s] at proxy [%s]\n"
+                               ,linphone_registration_state_to_string(cstate)
+                               ,linphone_proxy_config_get_identity(cfg)
+                               ,linphone_proxy_config_get_addr(cfg));
+}
 
 LinphoneCore *lc;
 int main(int argc, char *argv[]){
        LinphoneCoreVTable vtable={0};
 
        char* dest_friend=NULL;
-
+       char* identity=NULL;
+       char* password=NULL;
 
        /* takes   sip uri  identity from the command line arguments */
        if (argc>1){
                dest_friend=argv[1];
        }
-
+       /* takes   sip uri  identity from the command line arguments */
+       if (argc>2){
+               identity=argv[2];
+       }
+       /* takes   password from the command line arguments */
+       if (argc>3){
+               password=argv[3];
+       }
        signal(SIGINT,stop);
 //#define DEBUG
 #ifdef DEBUG
@@ -91,11 +108,47 @@ int main(int argc, char *argv[]){
         */
        vtable.notify_presence_recv=notify_presence_recv_updated;
        vtable.new_subscription_request=new_subscription_request;
+       vtable.registration_state_changed=registration_state_changed; /*just in case sip proxy is used*/
 
        /*
         Instantiate a LinphoneCore object given the LinphoneCoreVTable
        */
        lc=linphone_core_new(&vtable,NULL,NULL,NULL);
+       /*sip proxy might be requested*/
+       if (identity != NULL)  {
+               /*create proxy config*/
+               LinphoneProxyConfig* proxy_cfg = linphone_proxy_config_new();
+               /*parse identity*/
+               LinphoneAddress *from = linphone_address_new(identity);
+               if (from==NULL){
+                       printf("%s not a valid sip uri, must be like sip:toto@sip.linphone.org \n",identity);
+                       goto end;
+               }
+               LinphoneAuthInfo *info;
+               if (password!=NULL){
+                       info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL); /*create authentication structure from identity*/
+                       linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/
+               }
+
+               // configure proxy entries
+               linphone_proxy_config_set_identity(proxy_cfg,identity); /*set identity with user name and domain*/
+               linphone_proxy_config_set_server_addr(proxy_cfg,linphone_address_get_domain(from)); /* we assume domain = proxy server address*/
+               linphone_proxy_config_enable_register(proxy_cfg,TRUE); /*activate registration for this proxy config*/
+               linphone_proxy_config_enable_publish(proxy_cfg,TRUE); /* enable presence satus publication for this proxy*/
+               linphone_address_destroy(from); /*release resource*/
+
+               linphone_core_add_proxy_config(lc,proxy_cfg); /*add proxy config to linphone core*/
+               linphone_core_set_default_proxy(lc,proxy_cfg); /*set to default proxy*/
+
+
+               /* Loop until registration status is available */
+               do {
+                       linphone_core_iterate(lc); /* first iterate initiates registration */
+                       ms_usleep(100000);
+               }
+               while(  running && linphone_proxy_config_get_state(proxy_cfg) == LinphoneRegistrationProgress);
+
+       }
        LinphoneFriend* my_friend=NULL;
 
        if (dest_friend) {
index 61855d9e531162334d4dc098ec3580a4728b57d7..1c6c6715c2fd909f70e9d832e347f468f69d2e85 100644 (file)
@@ -40,7 +40,9 @@ import org.linphone.core.LinphoneFriend.SubscribePolicy;
  * from a sip uri identity passed from the command line.
  * <br>Argument must be like sip:jehan@sip.linphone.org .
  * ex budy_list sip:jehan@sip.linphone.org
- * <br>Subscription is cleared on SIGINT
+ * <br>
+ * Optionnally argument 2 can be registration sip identy.Argument 3 can be passord.
+ * ex: budy_list sip:jehan@sip.linphone.org sip:myidentity@sip.linphone.org mypassword
  *
  * Ported from buddy_status.c
  *