]> sjero.net Git - linphone/blobdiff - coreapi/linphonecore.c
fix bug when choosing SDP connection address
[linphone] / coreapi / linphonecore.c
index 673131218e6ad58ec8ece0db983a3237d4bfabd7..729df1fc6e7118c6edba9621aa6e1a6fe7e87de2 100644 (file)
@@ -92,12 +92,7 @@ int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
 
 /*prevent a gcc bug with %c*/
 static size_t my_strftime(char *s, size_t max, const char  *fmt,  const struct tm *tm){
-#if !defined(_WIN32_WCE)
        return strftime(s, max, fmt, tm);
-#else
-       return 0;
-       /*FIXME*/
-#endif /*_WIN32_WCE*/
 }
 
 static void set_call_log_date(LinphoneCallLog *cl, time_t start_time){
@@ -120,7 +115,8 @@ LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *fro
        set_call_log_date(cl,cl->start_date_time);
        cl->from=from;
        cl->to=to;
-    cl->status=LinphoneCallAborted; /*default status*/
+       cl->status=LinphoneCallAborted; /*default status*/
+       cl->quality=-1;
        return cl;
 }
 
@@ -203,8 +199,8 @@ static void call_logs_read_from_config_file(LinphoneCore *lc){
                        if (tmp) cl->refkey=ms_strdup(tmp);
                        cl->quality=lp_config_get_float(cfg,logsection,"quality",-1);
                        cl->video_enabled=lp_config_get_int(cfg,logsection,"video_enabled",0);
-                       cl->call_id=lp_config_get_string(cfg,logsection,"call_id",NULL);
-                       if(cl->call_id) cl->call_id=ms_strdup(cl->call_id);
+                       tmp=lp_config_get_string(cfg,logsection,"call_id",NULL);
+                       if (tmp) cl->call_id=ms_strdup(tmp);
                        lc->call_logs=ms_list_append(lc->call_logs,cl);
                }else break;
        }
@@ -270,10 +266,20 @@ const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl)
        return &cl->remote_stats;
 }
 
+const char *linphone_call_log_get_call_id(const LinphoneCallLog *cl){
+       return cl->call_id;
+}
+
+/**
+ * Assign a user pointer to the call log.
+**/
 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
        cl->user_pointer=up;
 }
 
+/**
+ * Returns the user pointer associated with the call log.
+**/
 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
        return cl->user_pointer;
 }
@@ -306,13 +312,74 @@ const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
        return cl->refkey;
 }
 
+/**
+ * Returns origin (ie from) address of the call.
+**/
+LinphoneAddress *linphone_call_log_get_from(LinphoneCallLog *cl){
+       return cl->from;
+}
+
+/**
+ * Returns destination address (ie to) of the call.
+**/
+LinphoneAddress *linphone_call_log_get_to(LinphoneCallLog *cl){
+       return cl->to;
+}
+
+/**
+ * Returns remote address (that is from or to depending on call direction).
+**/
+LinphoneAddress *linphone_call_log_get_remote_address(LinphoneCallLog *cl){
+       return (cl->dir == LinphoneCallIncoming) ? cl->from : cl->to;
+}
+
+/**
+ * Returns the direction of the call.
+**/
+LinphoneCallDir linphone_call_log_get_dir(LinphoneCallLog *cl){
+       return cl->dir;
+}
+
+/**
+ * Returns the status of the call.
+**/
+LinphoneCallStatus linphone_call_log_get_status(LinphoneCallLog *cl){
+       return cl->status;
+}
+
+/**
+ * Returns the start date of the call, expressed as a POSIX time_t.
+**/
+time_t linphone_call_log_get_start_date(LinphoneCallLog *cl){
+       return cl->start_date_time;
+}
+
+/**
+ * Returns duration of the call.
+**/
+int linphone_call_log_get_duration(LinphoneCallLog *cl){
+       return cl->duration;
+}
+
+/**
+ * Returns overall quality indication of the call.
+**/
+float linphone_call_log_get_quality(LinphoneCallLog *cl){
+       return cl->quality;
+}
+/**
+ * return true if video was enabled at the end of the call
+ */
+LinphoneCallStatus linphone_call_log_video_enabled(LinphoneCallLog *cl) {
+       return cl->video_enabled;
+}
 /** @} */
 
 void linphone_call_log_destroy(LinphoneCallLog *cl){
        if (cl->from!=NULL) linphone_address_destroy(cl->from);
        if (cl->to!=NULL) linphone_address_destroy(cl->to);
        if (cl->refkey!=NULL) ms_free(cl->refkey);
-       if (cl->call_id) ms_free((void*)cl->call_id);
+       if (cl->call_id) ms_free(cl->call_id);
        ms_free(cl);
 }
 
@@ -340,10 +407,24 @@ const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _Lin
        return linphone_call_get_remote_address(call);
 }
 
+void linphone_core_set_log_handler(OrtpLogFunc logfunc) {
+       ortp_set_log_handler(logfunc);
+}
+
+void linphone_core_set_log_file(FILE *file) {
+       if (file == NULL) file = stdout;
+       ortp_set_log_file(file);
+}
+
+void linphone_core_set_log_level(OrtpLogLevel loglevel) {
+       ortp_set_log_level_mask(loglevel);
+}
+
 /**
  * Enable logs in supplied FILE*.
  *
  * @ingroup misc
+ * @deprecated Use #linphone_core_set_log_file and #linphone_core_set_log_level instead.
  *
  * @param file a C FILE* where to fprintf logs. If null stdout is used.
  *
@@ -358,6 +439,7 @@ void linphone_core_enable_logs(FILE *file){
  * Enable logs through the user's supplied log callback.
  *
  * @ingroup misc
+ * @deprecated Use #linphone_core_set_log_handler and #linphone_core_set_log_level instead.
  *
  * @param logfunc The address of a OrtpLogFunc callback whose protoype is
  *               typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
@@ -372,6 +454,7 @@ void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
  * Entirely disable logging.
  *
  * @ingroup misc
+ * @deprecated Use #linphone_core_set_log_level instead.
 **/
 void linphone_core_disable_logs(){
        ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
@@ -397,7 +480,7 @@ static void net_config_read (LinphoneCore *lc)
        linphone_core_set_firewall_policy(lc,tmp);
        tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
        lc->net_conf.nat_sdp_only=tmp;
-       tmp=lp_config_get_int(lc->config,"net","mtu",0);
+       tmp=lp_config_get_int(lc->config,"net","mtu",1300);
        linphone_core_set_mtu(lc,tmp);
        tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
        linphone_core_set_download_ptime(lc,tmp);
@@ -486,11 +569,11 @@ static void sound_config_read(LinphoneCore *lc)
        check_sound_device(lc);
        lc->sound_conf.latency=0;
 #ifndef __ios 
-    tmp=TRUE;
+       tmp=TRUE;
 #else
-    tmp=FALSE; /* on iOS we have builtin echo cancellation.*/
+       tmp=FALSE; /* on iOS we have builtin echo cancellation.*/
 #endif
-    tmp=lp_config_get_int(lc->config,"sound","echocancellation",tmp);
+       tmp=lp_config_get_int(lc->config,"sound","echocancellation",tmp);
        linphone_core_enable_echo_cancellation(lc,tmp);
        linphone_core_enable_echo_limiter(lc,
                lp_config_get_int(lc->config,"sound","echolimiter",0));
@@ -600,6 +683,9 @@ static void sip_config_read(LinphoneCore *lc)
 
        tmp=lp_config_get_int(lc->config,"sip","in_call_timeout",0);
        linphone_core_set_in_call_timeout(lc,tmp);
+       
+       tmp=lp_config_get_int(lc->config,"sip","delayed_timeout",4);
+       linphone_core_set_delayed_timeout(lc,tmp);
 
        /* get proxies config */
        for(i=0;; i++){
@@ -631,6 +717,8 @@ static void sip_config_read(LinphoneCore *lc)
        lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
        lc->sip_conf.register_only_when_network_is_up=
                lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
+       lc->sip_conf.register_only_when_upnp_is_ok=
+               lp_config_get_int(lc->config,"sip","register_only_when_upnp_is_ok",1);
        lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
        lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
        lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
@@ -680,6 +768,7 @@ static void rtp_config_read(LinphoneCore *lc)
        linphone_core_enable_audio_adaptive_jittcomp(lc, adaptive_jitt_comp_enabled);
        adaptive_jitt_comp_enabled = lp_config_get_int(lc->config, "rtp", "video_adaptive_jitt_comp_enabled", TRUE);
        linphone_core_enable_video_adaptive_jittcomp(lc, adaptive_jitt_comp_enabled);
+       lc->rtp_conf.disable_upnp = lp_config_get_int(lc->config, "rtp", "disable_upnp", FALSE);
 }
 
 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, int channels, const char *recv_fmtp){
@@ -1122,8 +1211,8 @@ void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const
 }
 static void misc_config_read (LinphoneCore *lc) {
        LpConfig *config=lc->config;
-    lc->max_call_logs=lp_config_get_int(config,"misc","history_max_size",15);
-    lc->max_calls=lp_config_get_int(config,"misc","max_calls",NB_MAX_CALLS);
+       lc->max_call_logs=lp_config_get_int(config,"misc","history_max_size",15);
+       lc->max_calls=lp_config_get_int(config,"misc","max_calls",NB_MAX_CALLS);
 }
 
 
@@ -1236,9 +1325,6 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
        lc->tunnel=linphone_core_tunnel_new(lc);
        if (lc->tunnel) linphone_tunnel_configure(lc->tunnel);
 #endif
-#ifdef BUILD_UPNP
-       lc->upnp = linphone_upnp_context_new(lc);
-#endif  //BUILD_UPNP
        if (lc->vtable.display_status)
                lc->vtable.display_status(lc,_("Ready"));
        lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
@@ -1341,7 +1427,7 @@ void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result
                strncpy(result,ip,LINPHONE_IPADDR_SIZE);
                return;
        }
-#endif  //BUILD_UPNP
+#endif //BUILD_UPNP
        if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
                return;
        /*else fallback to SAL routine that will attempt to find the most realistic interface */
@@ -1986,9 +2072,11 @@ void linphone_core_iterate(LinphoneCore *lc){
                                lc->ecc->cb(lc,ecs,lc->ecc->delay,lc->ecc->cb_data);
                        if (ecs==LinphoneEcCalibratorDone){
                                int len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
-                               lp_config_set_int(lc->config, "sound", "ec_delay",MAX(lc->ecc->delay-(len/2),0));
+                               int margin=len/2;
+                               
+                               lp_config_set_int(lc->config, "sound", "ec_delay",MAX(lc->ecc->delay-margin,0));
                        } else if (ecs == LinphoneEcCalibratorFailed) {
-                               lp_config_set_int(lc->config, "sound", "ec_delay", LP_CONFIG_DEFAULT_INT(lc->config, "ec_delay", 250));
+                               lp_config_set_int(lc->config, "sound", "ec_delay", -1);/*use default value from soundcard*/
                        } else if (ecs == LinphoneEcCalibratorDoneNoEcho) {
                                linphone_core_enable_echo_cancellation(lc, FALSE);
                        }
@@ -2027,7 +2115,7 @@ void linphone_core_iterate(LinphoneCore *lc){
                 linphone_core_start_invite() */
                calls=calls->next;
                linphone_call_background_tasks(call,one_second_elapsed);
-               if (call->state==LinphoneCallOutgoingInit && (curtime-call->start_time>=2)){
+               if (call->state==LinphoneCallOutgoingInit && (elapsed>=lc->sip_conf.delayed_timeout)){
                        /*start the call even if the OPTIONS reply did not arrive*/
                        if (call->ice_session != NULL) {
                                ms_warning("ICE candidates gathering from [%s] has not finished yet, proceed with the call without ICE anyway."
@@ -2046,10 +2134,12 @@ void linphone_core_iterate(LinphoneCore *lc){
                if (call->state==LinphoneCallIncomingReceived){
                        ms_message("incoming call ringing for %i seconds",elapsed);
                        if (elapsed>lc->sip_conf.inc_timeout){
+                               LinphoneReason decline_reason;
                                ms_message("incoming call timeout (%i)",lc->sip_conf.inc_timeout);
+                               decline_reason=lc->current_call ? LinphoneReasonBusy : LinphoneReasonDeclined;
                                call->log->status=LinphoneCallMissed;
                                call->reason=LinphoneReasonNotAnswered;
-                               linphone_core_terminate_call(lc,call);
+                               linphone_core_decline_call(lc,call,decline_reason);
                        }
                }
                if (lc->sip_conf.in_call_timeout > 0 && elapsed>lc->sip_conf.in_call_timeout) {
@@ -2078,8 +2168,10 @@ void linphone_core_iterate(LinphoneCore *lc){
                lc->initial_subscribes_sent=TRUE;
        }
 
-       if (one_second_elapsed && lp_config_needs_commit(lc->config)){
-               lp_config_sync(lc->config);
+       if (one_second_elapsed) {
+               if (lp_config_needs_commit(lc->config)) {
+                       lp_config_sync(lc->config);
+               }
        }
 }
 
@@ -2310,6 +2402,8 @@ int linphone_core_proceed_with_invite_if_ready(LinphoneCore *lc, LinphoneCall *c
        } else {
                upnp_ready = TRUE;
        }
+#else
+       upnp_ready=TRUE;
 #endif //BUILD_UPNP
        if (call->ping_op != NULL) {
                if (call->ping_replied == TRUE) ping_ready = TRUE;
@@ -2535,15 +2629,23 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const
        }
 
        if (call->dest_proxy==NULL && lc->sip_conf.ping_with_options==TRUE){
-               /*defer the start of the call after the OPTIONS ping*/
-               call->ping_replied=FALSE;
-               call->ping_op=sal_op_new(lc->sal);
-               sal_ping(call->ping_op,from,real_url);
-               sal_op_set_user_pointer(call->ping_op,call);
-               call->start_time=time(NULL);
-       }else{
-               if (defer==FALSE) linphone_core_start_invite(lc,call);
+#ifdef BUILD_UPNP
+               if (lc->upnp != NULL && linphone_core_get_firewall_policy(lc)==LinphonePolicyUseUpnp &&
+                       linphone_upnp_context_get_state(lc->upnp) == LinphoneUpnpStateOk) {
+#else //BUILD_UPNP
+               {
+#endif //BUILD_UPNP
+                       /*defer the start of the call after the OPTIONS ping*/
+                       call->ping_replied=FALSE;
+                       call->ping_op=sal_op_new(lc->sal);
+                       sal_ping(call->ping_op,from,real_url);
+                       sal_op_set_user_pointer(call->ping_op,call);
+                       call->start_time=time(NULL);
+                       defer = TRUE;
+               }
        }
+       
+       if (defer==FALSE) linphone_core_start_invite(lc,call);
 
        if (real_url!=NULL) ms_free(real_url);
        return call;
@@ -2673,7 +2775,7 @@ void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call){
        }else{
                /* else play a tone within the context of the current call */
                call->ringing_beep=TRUE;
-               linphone_core_play_tone(lc);
+               linphone_core_play_named_tone(lc,LinphoneToneCallWaiting);
        }
 
        linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call");
@@ -2754,8 +2856,8 @@ int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const Linpho
                        }
 #endif //BUILD_UPNP
                }
-
-               call->params = *params;
+               
+               _linphone_call_params_copy(&call->params,params);
                linphone_call_make_local_media_description(lc, call);
 
                // Video adding
@@ -2920,7 +3022,7 @@ int linphone_core_accept_call_update(LinphoneCore *lc, LinphoneCall *call, const
 #endif //VIDEO_ENABLED
        }
 
-#if BUILD_UPNP
+#ifdef BUILD_UPNP
        if(call->upnp_session != NULL) {
                linphone_core_update_upnp_from_remote_media_description(call, sal_call_get_remote_media_description(call->op));
 #ifdef VIDEO_ENABLED
@@ -3034,7 +3136,7 @@ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call,
 
        if (params){
                const SalMediaDescription *md = sal_call_get_remote_media_description(call->op);
-               call->params=*params;
+               _linphone_call_params_copy(&call->params,params);
                // There might not be a md if the INVITE was lacking an SDP
                // In this case we use the parameters as is.
                if (md) call->params.has_video &= linphone_core_media_description_contains_video_stream(md);
@@ -3224,8 +3326,7 @@ bool_t linphone_core_in_call(const LinphoneCore *lc){
  *
  * @ingroup call_control
 **/
-LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
-{
+LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc){
        return lc->current_call;
 }
 
@@ -3235,7 +3336,14 @@ LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
  *
  * @ingroup call_control
 **/
-int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call)
+int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call){
+       int err=_linphone_core_pause_call(lc,call);
+       if (err==0)  call->paused_by_app=TRUE;
+       return err;
+}
+
+/* Internal version that does not play tone indication*/
+int _linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call)
 {
        const char *subject=NULL;
 
@@ -3273,6 +3381,7 @@ int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call)
                lc->vtable.display_status(lc,_("Pausing the current call..."));
        if (call->audiostream || call->videostream)
                linphone_call_stop_media_streams (call);
+       call->paused_by_app=FALSE;
        return 0;
 }
 
@@ -3286,7 +3395,7 @@ int linphone_core_pause_all_calls(LinphoneCore *lc){
                LinphoneCall *call=(LinphoneCall *)elem->data;
                LinphoneCallState cs=linphone_call_get_state(call);
                if (cs==LinphoneCallStreamsRunning || cs==LinphoneCallPausedByRemote){
-                       linphone_core_pause_call(lc,call);
+                       _linphone_core_pause_call(lc,call);
                }
        }
        return 0;
@@ -3301,7 +3410,11 @@ void linphone_core_preempt_sound_resources(LinphoneCore *lc){
        current_call=linphone_core_get_current_call(lc);
        if(current_call != NULL){
                ms_message("Pausing automatically the current call.");
-               linphone_core_pause_call(lc,current_call);
+               _linphone_core_pause_call(lc,current_call);
+       }
+       if (lc->ringstream){
+               ring_stop(lc->ringstream);
+               lc->ringstream=NULL;
        }
 }
 
@@ -3426,6 +3539,26 @@ int linphone_core_get_in_call_timeout(LinphoneCore *lc){
        return lc->sip_conf.in_call_timeout;
 }
 
+/**
+ * Returns the delayed timeout
+ *
+ * @ingroup call_control
+ * See linphone_core_set_delayed_timeout() for details.
+**/
+int linphone_core_get_delayed_timeout(LinphoneCore *lc){
+       return lc->sip_conf.delayed_timeout;
+}
+
+/**
+ * Set the in delayed timeout in seconds.
+ *
+ * @ingroup call_control
+ * After this timeout period, a delayed call (internal call initialisation or resolution) is resumed.
+**/
+void linphone_core_set_delayed_timeout(LinphoneCore *lc, int seconds){
+       lc->sip_conf.delayed_timeout=seconds;
+}
+
 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
                                                                                                        const char *contact,
                                                                                                        LinphoneOnlineStatus presence_mode)
@@ -4055,6 +4188,31 @@ const char * linphone_core_get_stun_server(const LinphoneCore *lc){
        return lc->net_conf.stun_server;
 }
 
+bool_t linphone_core_upnp_available(const LinphoneCore *lc){
+#ifdef BUILD_UPNP
+       return TRUE;
+#else
+       return FALSE;
+#endif //BUILD_UPNP
+}
+
+LinphoneUpnpState linphone_core_get_upnp_state(const LinphoneCore *lc){
+#ifdef BUILD_UPNP
+       return linphone_upnp_context_get_state(lc->upnp);
+#else
+       return LinphoneUpnpStateNotAvailable;
+#endif //BUILD_UPNP
+}
+
+const char * linphone_core_get_upnp_external_ipaddress(const LinphoneCore *lc){
+#ifdef BUILD_UPNP
+       return linphone_upnp_context_get_external_ipaddress(lc->upnp);
+#else
+       return NULL;
+#endif //BUILD_UPNP
+}
+
+
 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
        return lc->net_conf.relay;
 }
@@ -4111,7 +4269,26 @@ const char *linphone_core_get_nat_address_resolved(LinphoneCore *lc)
 }
 
 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
+#ifndef BUILD_UPNP
+       if(pol == LinphonePolicyUseUpnp) {
+               ms_warning("UPNP is not available, reset firewall policy to no firewall");
+               pol = LinphonePolicyNoFirewall;
+       }
+#endif //BUILD_UPNP
        lc->net_conf.firewall_policy=pol;
+#ifdef BUILD_UPNP
+       if(pol == LinphonePolicyUseUpnp) {
+               if(lc->upnp == NULL) {
+                       lc->upnp = linphone_upnp_context_new(lc);
+               }
+       } else {
+               if(lc->upnp != NULL) {
+                       linphone_upnp_context_destroy(lc->upnp);
+                       lc->upnp = NULL;
+               }
+       }
+       linphone_core_enable_keep_alive(lc, (lc->sip_conf.keepalive_period > 0));
+#endif //BUILD_UPNP
        if (lc->sip_conf.contact) update_primary_contact(lc);
        if (linphone_core_ready(lc))
                lp_config_set_int(lc->config,"net","firewall_policy",pol);
@@ -4548,7 +4725,7 @@ int linphone_core_get_device_rotation(LinphoneCore *lc ) {
  *
 **/
 void linphone_core_set_device_rotation(LinphoneCore *lc, int rotation) {
-ms_message("%s : rotation=%d\n", __FUNCTION__, rotation);
+       ms_message("%s : rotation=%d\n", __FUNCTION__, rotation);
        lc->device_rotation = rotation;
 #ifdef VIDEO_ENABLED
        LinphoneCall *call=linphone_core_get_current_call(lc);
@@ -4685,7 +4862,8 @@ void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
  * Sets a wav file where incoming stream is to be recorded,
  * when files are used instead of soundcards (see linphone_core_use_files()).
  *
- * The file must be a 16 bit linear wav file.
+ * This feature is different from call recording (linphone_call_params_set_record_file())
+ * The file will be a 16 bit linear wav file.
 **/
 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
        LinphoneCall *call=linphone_core_get_current_call(lc);
@@ -4759,13 +4937,54 @@ void linphone_core_play_tone(LinphoneCore *lc){
                ms_error("No dtmf generator at this time !");
                return;
        }
+       memset(&def,0,sizeof(def));
        def.duration=300;
-       def.frequency=500;
+       def.frequencies[0]=500;
        def.amplitude=1;
        def.interval=2000;
        ms_filter_call_method(f, MS_DTMF_GEN_PLAY_CUSTOM,&def);
 }
 
+void linphone_core_play_named_tone(LinphoneCore *lc, LinphoneToneID toneid){
+       if (linphone_core_tone_indications_enabled(lc)){
+               MSFilter *f=get_dtmf_gen(lc);
+               MSDtmfGenCustomTone def;
+               if (f==NULL){
+                       ms_error("No dtmf generator at this time !");
+                       return;
+               }
+               memset(&def,0,sizeof(def));
+               def.amplitude=1;
+               /*these are french tones, excepted the failed one, which is USA congestion tone (does not exist in France)*/
+               switch(toneid){
+                       case LinphoneToneCallOnHold:
+                       case LinphoneToneCallWaiting:
+                               def.duration=300;
+                               def.frequencies[0]=440;
+                               def.interval=2000;
+                       break;
+                       case LinphoneToneBusy:
+                               def.duration=500;
+                               def.frequencies[0]=440;
+                               def.interval=500;
+                               def.repeat_count=3;
+                       break;
+                       case LinphoneToneCallFailed:
+                               def.duration=250;
+                               def.frequencies[0]=480;
+                               def.frequencies[0]=620;
+                               def.interval=250;
+                               def.repeat_count=3;
+                               
+                       break;
+                       default:
+                               ms_warning("Unhandled tone id.");
+               }
+               if (def.duration>0)
+                       ms_filter_call_method(f, MS_DTMF_GEN_PLAY_CUSTOM,&def);
+       }
+}
+
 /**
  * @ingroup media_parameters
  *
@@ -4904,11 +5123,12 @@ void sip_config_uninit(LinphoneCore *lc)
        lp_config_set_string(lc->config,"sip","contact",config->contact);
        lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
        lp_config_set_int(lc->config,"sip","in_call_timeout",config->in_call_timeout);
+       lp_config_set_int(lc->config,"sip","delayed_timeout",config->delayed_timeout);
        lp_config_set_int(lc->config,"sip","use_info",config->use_info);
        lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
        lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
        lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
-
+       lp_config_set_int(lc->config,"sip","register_only_when_upnp_is_ok",config->register_only_when_upnp_is_ok);
 
        
 
@@ -5066,11 +5286,12 @@ static void linphone_core_uninit(LinphoneCore *lc)
                usleep(50000);
 #endif
        }
-
 #ifdef BUILD_UPNP
-       linphone_upnp_context_destroy(lc->upnp);
-       lc->upnp = NULL;
-#endif  //BUILD_UPNP
+       if(lc->upnp != NULL) {
+               linphone_upnp_context_destroy(lc->upnp);
+               lc->upnp = NULL;
+       }
+#endif //BUILD_UPNP
 
        if (lc->friends)
                ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
@@ -5102,8 +5323,21 @@ static void linphone_core_uninit(LinphoneCore *lc)
        
        ms_list_for_each(lc->last_recv_msg_ids,ms_free);
        lc->last_recv_msg_ids=ms_list_free(lc->last_recv_msg_ids);
+       
+       // Free struct variable
+       if(lc->zrtp_secrets_cache != NULL) {
+               ms_free(lc->zrtp_secrets_cache);
+       }
+       if(lc->play_file!=NULL){
+               ms_free(lc->play_file);
+       }
+       if(lc->rec_file!=NULL){
+               ms_free(lc->rec_file);
+       }
 
        linphone_core_free_payload_types(lc);
+       
+       linphone_core_message_storage_close(lc);
        ortp_exit();
        linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
 #ifdef TUNNEL_ENABLED
@@ -5127,9 +5361,22 @@ static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t cu
        }
        lc->netup_time=curtime;
        lc->network_reachable=isReachable;
+       
        if(!isReachable) {
                sal_reset_transports(lc->sal);
        }
+#ifdef BUILD_UPNP
+       if(lc->upnp == NULL) {
+               if(isReachable && lc->net_conf.firewall_policy == LinphonePolicyUseUpnp) {
+                       lc->upnp = linphone_upnp_context_new(lc);       
+               }
+       } else {
+               if(!isReachable && lc->net_conf.firewall_policy == LinphonePolicyUseUpnp) {
+                       linphone_upnp_context_destroy(lc->upnp);
+                       lc->upnp = NULL;
+               }
+       }
+#endif 
 }
 
 void linphone_core_refresh_registers(LinphoneCore* lc) {
@@ -5336,6 +5583,11 @@ const char *linphone_error_to_string(LinphoneReason err){
  * Enables signaling keep alive
  */
 void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) {
+#ifdef BUILD_UPNP
+       if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseUpnp) {
+               enable = FALSE;
+       }
+#endif //BUILD_UPNP
        if (enable > 0) {
                sal_use_tcp_tls_keepalive(lc->sal,lc->sip_conf.tcp_tls_keepalive);
                sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
@@ -5404,7 +5656,7 @@ void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook
        for(elem=lc->hooks;elem!=NULL;elem=elem->next){
                Hook *h=(Hook*)elem->data;
                if (h->fun==hook && h->data==hook_data){
-                       ms_list_remove_link(lc->hooks,elem);
+                       lc->hooks = ms_list_remove_link(lc->hooks,elem);
                        ms_free(h);
                        return;
                }
@@ -5536,8 +5788,6 @@ void linphone_core_init_default_params(LinphoneCore*lc, LinphoneCallParams *para
        params->in_conference=FALSE;
 }
 
-
-
 void linphone_core_set_device_identifier(LinphoneCore *lc,const char* device_id) {
        if (lc->device_id) ms_free(lc->device_id);
        lc->device_id=ms_strdup(device_id);
@@ -5618,3 +5868,24 @@ void linphone_core_set_video_dscp(LinphoneCore *lc, int dscp){
 int linphone_core_get_video_dscp(const LinphoneCore *lc){
        return lp_config_get_int(lc->config,"rtp","video_dscp",0x2e);
 }
+
+
+/**
+ * Sets the database filename where chat messages will be stored.
+ * If the file does not exist, it will be created.
+ * @ingroup initializing
+ * @param lc the linphone core
+ * @param path filesystem path
+**/
+void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path){
+       if (lc->chat_db_file){
+               ms_free(lc->chat_db_file);
+               lc->chat_db_file=NULL;
+       }
+       if (path) {
+               lc->chat_db_file=ms_strdup(path);
+               linphone_core_message_storage_init(lc);
+       }
+}
+
+