]> sjero.net Git - linphone/blobdiff - coreapi/linphonecore.c
Merge remote-tracking branch 'private/dev_videoios'
[linphone] / coreapi / linphonecore.c
index 49dad24ff7fbf35c37027c6eaa3cb61eaffbc616..2106e6c51873fbb5919b58b03f5504cc1f400f79 100644 (file)
@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "private.h"
 
 #include <ortp/telephonyevents.h>
+#include <ortp/zrtp.h>
 #include "mediastreamer2/mediastream.h"
 #include "mediastreamer2/mseventqueue.h"
 #include "mediastreamer2/msvolume.h"
@@ -35,6 +36,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #endif
 #endif
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 /*#define UNSTANDART_GSM_11K 1*/
 
 #define ROOT_CA_FILE PACKAGE_DATA_DIR "/linphone/rootca.pem"
@@ -523,7 +528,7 @@ static void sip_config_read(LinphoneCore *lc)
 #else
        sal_root_ca(lc->sal, lp_config_get_string(lc->config,"sip","root_ca", ROOT_CA_FILE));
 #endif
-
+       
        tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
        linphone_core_set_guess_hostname(lc,tmp);
 
@@ -554,6 +559,8 @@ static void sip_config_read(LinphoneCore *lc)
                        break;
                }
        }
+       /*this is to filter out unsupported encryption schemes*/
+       linphone_core_set_media_encryption(lc,linphone_core_get_media_encryption(lc));
 
        /*for tuning or test*/
        lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
@@ -4266,7 +4273,7 @@ LinphoneGlobalState linphone_core_get_global_state(const LinphoneCore *lc){
 
 LinphoneCallParams *linphone_core_create_default_call_parameters(LinphoneCore *lc){
        LinphoneCallParams *p=ms_new0(LinphoneCallParams,1);
-       p->has_video=linphone_core_video_enabled(lc);
+       linphone_core_init_default_params(lc, p);
        return p;
 }
 
@@ -4317,7 +4324,9 @@ void linphone_core_stop_dtmf_stream(LinphoneCore* lc) {
 int linphone_core_get_max_calls(LinphoneCore *lc) {
        return lc->max_calls;
 }
-
+void linphone_core_set_max_calls(LinphoneCore *lc, int max) {
+       lc->max_calls=max;
+}
 
 typedef struct Hook{
        LinphoneCoreIterateHook fun;
@@ -4369,7 +4378,6 @@ void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){
        lc->zrtp_secrets_cache=file ? ms_strdup(file) : NULL;
 }
 
-//                             if (stringUri.equals(call.getRemoteAddress().asStringUriOnly())) {
 const LinphoneCall* linphone_core_find_call_from_uri(LinphoneCore *lc, const char *uri) {
        if (uri == NULL) return NULL;
        MSList *calls=lc->calls;
@@ -4387,3 +4395,99 @@ const LinphoneCall* linphone_core_find_call_from_uri(LinphoneCore *lc, const cha
        }
        return NULL;
 }
+
+
+/**
+ * Check if a call will need the sound resources.
+ *
+ * @ingroup call_control
+ * @param lc The LinphoneCore
+**/
+bool_t linphone_core_sound_resources_locked(LinphoneCore *lc){
+       MSList *calls=lc->calls;
+       while(calls) {
+               LinphoneCall *c=(LinphoneCall*)calls->data;
+               calls=calls->next;
+               switch (c->state) {
+                       case LinphoneCallOutgoingInit:
+                       case LinphoneCallOutgoingProgress:
+                       case LinphoneCallOutgoingRinging:
+                       case LinphoneCallOutgoingEarlyMedia:
+                       case LinphoneCallConnected:
+                       case LinphoneCallRefered:
+                       case LinphoneCallIncomingEarlyMedia:
+                       case LinphoneCallUpdated:
+                               return TRUE;
+                       default:
+                               break;
+               }
+       }
+       return FALSE;
+}
+
+void linphone_core_set_srtp_enabled(LinphoneCore *lc, bool_t enabled) {
+       lp_config_set_int(lc->config,"sip","srtp",(int)enabled);
+}
+
+/**
+ * Returns whether a media encryption scheme is supported by the LinphoneCore engine
+**/
+bool_t linphone_core_media_encryption_supported(const LinphoneCore *lc, LinphoneMediaEncryption menc){
+       switch(menc){
+               case LinphoneMediaEncryptionSRTP:
+                       return ortp_srtp_supported();
+               case LinphoneMediaEncryptionZRTP:
+                       return ortp_zrtp_available();
+               case LinphoneMediaEncryptionNone:
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+int linphone_core_set_media_encryption(LinphoneCore *lc, enum LinphoneMediaEncryption menc) {
+       const char *type="none";
+       int ret=0;
+       if (menc == LinphoneMediaEncryptionSRTP){
+               if (!ortp_srtp_supported()){
+                       ms_warning("SRTP not supported by library.");
+                       type="none";
+                       ret=-1;
+               }else type="srtp";
+       }else if (menc == LinphoneMediaEncryptionZRTP){
+               if (!ortp_zrtp_available()){
+                       ms_warning("ZRTP not supported by library.");
+                       type="none";
+                       ret=-1;
+               }else type="zrtp";
+       }
+       lp_config_set_string(lc->config,"sip","media_encryption",type);
+       return ret;
+}
+
+LinphoneMediaEncryption linphone_core_get_media_encryption(LinphoneCore *lc) {
+       const char* menc = lp_config_get_string(lc->config, "sip", "media_encryption", NULL);
+       
+       if (menc == NULL)
+               return LinphoneMediaEncryptionNone;
+       else if (strcmp(menc, "srtp")==0)
+               return LinphoneMediaEncryptionSRTP;
+       else if (strcmp(menc, "zrtp")==0)
+               return LinphoneMediaEncryptionZRTP;
+       else
+               return LinphoneMediaEncryptionNone;
+}
+
+bool_t linphone_core_is_media_encryption_mandatory(LinphoneCore *lc) {
+       return (bool_t)lp_config_get_int(lc->config, "sip", "media_encryption_mandatory", 0);
+}
+
+void linphone_core_set_media_encryption_mandatory(LinphoneCore *lc, bool_t m) {
+       lp_config_set_int(lc->config, "sip", "media_encryption_mandatory", (int)m);
+}
+
+void linphone_core_init_default_params(LinphoneCore*lc, LinphoneCallParams *params) {
+       params->has_video=linphone_core_video_enabled(lc);
+       params->media_encryption=linphone_core_get_media_encryption(lc);        
+       params->in_conference=FALSE;
+}
+