]> sjero.net Git - linphone/blobdiff - coreapi/proxy.c
fix sending of PUBLISH requests (was not set to the proxy address actually)
[linphone] / coreapi / proxy.c
index 15f10b744d3311d10fe800ed8899cba8a6938dc0..42c21f01b29a36000a9f0ed4b7ef882613c545f2 100644 (file)
@@ -119,7 +119,7 @@ int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char *
                if (addr==NULL)
                        addr=linphone_address_new(server_addr);
                if (addr){
-                       obj->reg_proxy=linphone_address_as_string_uri_only(addr);
+                       obj->reg_proxy=linphone_address_as_string(addr);
                        linphone_address_destroy(addr);
                }else{
                        ms_warning("Could not parse %s",server_addr);
@@ -263,15 +263,30 @@ static char *guess_contact_for_register(LinphoneProxyConfig *obj){
        if (proxy==NULL) return NULL;
        host=linphone_address_get_domain (proxy);
        if (host!=NULL){
-               char localip[LINPHONE_IPADDR_SIZE];
+               int localport = -1;
+               char localip_tmp[LINPHONE_IPADDR_SIZE] = {'\0'};
+               const char *localip = NULL;
                char *tmp;
                LCSipTransports tr;
                LinphoneAddress *contact;
                
-               linphone_core_get_local_ip(obj->lc,host,localip);
                contact=linphone_address_new(obj->reg_identity);
-               linphone_address_set_domain (contact,localip);
-               linphone_address_set_port_int(contact,linphone_core_get_sip_port(obj->lc));
+#ifdef BUILD_UPNP
+               if (obj->lc->upnp != NULL && linphone_core_get_firewall_policy(obj->lc)==LinphonePolicyUseUpnp &&
+                       linphone_upnp_context_get_state(obj->lc->upnp) == LinphoneUpnpStateOk) {
+                       localip = linphone_upnp_context_get_external_ipaddress(obj->lc->upnp);
+                       localport = linphone_upnp_context_get_external_port(obj->lc->upnp);
+               }
+#endif //BUILD_UPNP            
+               if(localip == NULL) {
+                       localip = localip_tmp;
+                       linphone_core_get_local_ip(obj->lc,host,localip_tmp);
+               }
+               if(localport == -1) {
+                       localport = linphone_core_get_sip_port(obj->lc);
+               }
+               linphone_address_set_port_int(contact,localport);
+               linphone_address_set_domain(contact,localip);
                linphone_address_set_display_name(contact,NULL);
                
                linphone_core_get_sip_transports(obj->lc,&tr);
@@ -427,7 +442,7 @@ static dial_plan_t const dial_plans[]={
     {"Congo Democratic Republic"       ,"CD"           , "243"     , 9         , "00"  },
     {"Cook Islands"                 ,"CK"              , "682"     , 5         , "00"  },
     {"Costa Rica"                   ,"CR"              , "506"     , 8     , "00"      },
-    {"C\99te d'Ivoire"               ,"AD"               , "225"     , 8     , "00"  },
+    {"C�te d'Ivoire"             ,"AD"               , "225"     , 8     , "00"  },
     {"Croatia"                      ,"HR"              , "385"     , 9         , "00"  },
     {"Cuba"                         ,"CU"              , "53"      , 8     , "119" },
     {"Cyprus"                       ,"CY"              , "357"     , 8     , "00"      },
@@ -545,7 +560,7 @@ static dial_plan_t const dial_plans[]={
     {"Portugal"                     ,"PT"              , "351"     , 9     , "00"      },
     {"Puerto Rico"                  ,"PR"              , "1"       , 10        , "011" },
     {"Qatar"                        ,"QA"              , "974"     , 8     , "00"  },
-    {"R\8eunion Island"                          ,"RE"           , "262"     , 9     , "011"     },
+    {"R�union Island"                                ,"RE"           , "262"     , 9     , "011"     },
     {"Romania"                      ,"RO"              , "40"      , 9     , "00"      },
     {"Russian Federation"           ,"RU"              , "7"       , 10        , "8"   },
     {"Rwanda"                       ,"RW"              , "250"     , 9         , "00"  },
@@ -556,7 +571,7 @@ static dial_plan_t const dial_plans[]={
     {"Saint Vincent and the Grenadines","VC"   , "1"       , 10        , "011" },
     {"Samoa"                        ,"WS"              , "685"     , 7     , "0"       },
     {"San Marino"                   ,"SM"              , "378"     , 10        , "00"  },
-    {"S\8bo Tom\8e and Pr\92ncipe"        ,"ST"              , "239"     , 7         , "00"  },
+    {"S�o Tom� and Pr�ncipe"        ,"ST"                , "239"     , 7         , "00"  },
     {"Saudi Arabia"                 ,"SA"              , "966"     , 9         , "00"  },
     {"Senegal"                      ,"SN"              , "221"     , 9     , "00"  },
     {"Serbia"                       ,"RS"              , "381"     , 9     , "00"  },
@@ -625,7 +640,7 @@ int linphone_dial_plan_lookup_ccc_from_e164(const char* e164) {
                                found++;
                        }
                }
-       } while (found>1 || found==0);
+       } while ((found>1 || found==0) && i < sizeof(dial_plan->ccc));
        if (found==1) {
                return atoi(elected_dial_plan->ccc);
        } else {
@@ -777,6 +792,7 @@ int linphone_proxy_config_send_publish(LinphoneProxyConfig *proxy,
                               LinphoneOnlineStatus presence_mode){
        int err;
        SalOp *op=sal_op_new(proxy->lc->sal);
+       sal_op_set_route(op,proxy->reg_proxy);
        err=sal_publish(op,linphone_proxy_config_get_identity(proxy),
            linphone_proxy_config_get_identity(proxy),linphone_online_status_to_sal(presence_mode));
        if (proxy->publish_op!=NULL)
@@ -981,7 +997,7 @@ void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyC
                lp_config_set_string(config,key,"reg_identity",obj->reg_identity);
        }
        if (obj->contact_params!=NULL){
-               lp_config_set_string(config,key,"contact_params",obj->contact_params);
+               lp_config_set_string(config,key,"contact_parameters",obj->contact_params);
        }
        lp_config_set_int(config,key,"reg_expires",obj->expires);
        lp_config_set_int(config,key,"reg_sendregister",obj->reg_sendregister);
@@ -1082,8 +1098,19 @@ void linphone_proxy_config_update(LinphoneProxyConfig *cfg){
                if (cfg->type && cfg->ssctx==NULL){
                        linphone_proxy_config_activate_sip_setup(cfg);
                }
-               if (!lc->sip_conf.register_only_when_network_is_up || lc->network_reachable)
-                       linphone_proxy_config_register(cfg);
+               switch(linphone_core_get_firewall_policy(lc)) {
+                       case LinphonePolicyUseUpnp:
+#ifdef BUILD_UPNP
+                       if(lc->sip_conf.register_only_when_upnp_is_ok && 
+                          (lc->upnp == NULL || !linphone_upnp_context_is_ready_for_register(lc->upnp))) {
+                               break;
+                       }
+#endif //BUILD_UPNP
+                       default:
+                       if ((!lc->sip_conf.register_only_when_network_is_up || lc->network_reachable)) {
+                               linphone_proxy_config_register(cfg);
+                       }
+               }       
                if (cfg->publish && cfg->publish_op==NULL){
                        linphone_proxy_config_send_publish(cfg,lc->presence_mode);
                }