赞
踩
这个主要是被linphonecore调用,其数据是存储在文件中的.
从上一篇开始, 本系列作为linphone下c语言的函数追踪, 一是对整体的代码结构做一些了解, 二是按着顺序来做体会一下c的代码,有更深一层次的了解, 三是把本系列作为后面分析逻辑的时候,作为工具字典进行使用.
内容比较长, 先给自己打一个定海神针. 本系列就是作为工具用的.所以慢慢坚持下来慢慢找.
/**
* The LinphoneProxyConfig object represents a proxy configuration to be used by the LinphoneCore object. Its fields must not be used directly in favour of the accessors methods.
* Once created and filled properly the LinphoneProxyConfig can be given to LinphoneCore with {@link LinphoneCore#addProxyConfig(LinphoneProxyConfig)}. This will automatically triggers the registration, if enabled.
*<br>The proxy configuration are persistent to restarts because they are saved in the configuration file. As a consequence, after {@link LinphoneCoreFactory#createLinphoneCore(LinphoneCoreListener, String, String, Object)} there might already be a default proxy that can be examined with {@link LinphoneCore#getDefaultProxyConfig()} .
*
*/
解释
private native void finalize(long ptr);
private native int getState(long nativePtr);
private native void setExpires(long nativePtr, int delay);
private native int getExpires(long nativePtr);
private native long createProxyConfig( long nativePtr);
private native long newLinphoneProxyConfig();
private native void edit(long ptr);
private native void done(long ptr);
private native void setIdentity(long ptr,String identity);
private native String getIdentity(long ptr);
private native void setAddress(long ptr, long address);
private native long getAddress(long ptr);
private native int setProxy(long ptr,String proxy);
private native String getProxy(long ptr);
private native void enableRegister(long ptr,boolean value);
private native boolean isRegisterEnabled(long ptr);
private native boolean isRegistered(long ptr);
private native void setDialPrefix(long ptr, String prefix);
private native String getDialPrefix(long ptr);
private native String normalizePhoneNumber(long ptr,String number);
private native long normalizeSipUri(long ptr,String username);
private native String getDomain(long ptr);
private native void setDialEscapePlus(long ptr, boolean value);
private native boolean getDialEscapePlus(long ptr);
private native String getRoute(long ptr);
private native int setRoute(long ptr,String uri);
private native void enablePublish(long ptr,boolean enable);
private native boolean publishEnabled(long ptr);
private native void setContactParameters(long ptr, String params);
private native int lookupCCCFromIso(long nativePtr, String iso);
private native int lookupCCCFromE164(long nativePtr, String e164);
private native int getError(long nativeptr);
private native void setPrivacy(long nativePtr, int mask);
private native int getPrivacy(long nativePtr);
private native void enableAvpf(long nativePtr, boolean enable);
private native boolean avpfEnabled(long nativePtr);
private native void setAvpfRRInterval(long nativePtr, int interval);
private native int getAvpfRRInterval(long nativePtr);
private native String getContactParameters(long ptr);
private native void setContactUriParameters(long ptr, String params);
private native String getContactUriParameters(long ptr);
private native long getErrorInfo(long nativePtr);
private native void enableQualityReporting(long nativePtr, boolean enable);
private native boolean qualityReportingEnabled(long nativePtr);
private native void setQualityReportingInterval(long nativePtr, int interval);
private native int getQualityReportingInterval(long nativePtr);
private native void setQualityReportingCollector(long nativePtr, String collector);
private native String getQualityReportingCollector(long nativePtr);
private native void setRealm(long nativePtr, String realm);
private native String getRealm(long nativePtr);
private native void setPublishExpires(long nativePtr, int expires);
private native int getPublishExpires(long nativePtr);
private native boolean isPhoneNumber(long nativePtr,String username);
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_finalize(JNIEnv* env
,jobject thiz
,jlong ptr) {
LinphoneProxyConfig *proxy=(LinphoneProxyConfig*)ptr;
linphone_proxy_config_set_user_data(proxy,NULL);
linphone_proxy_config_unref(proxy);
}
submodules/linphone/coreapi/private.h:struct _LinphoneProxyConfig
struct _LinphoneProxyConfig
{
belle_sip_object_t base;
void *user_data;
struct _LinphoneCore *lc;
char *reg_proxy;
char *reg_identity;
LinphoneAddress* identity_address;
char *reg_route;
char *quality_reporting_collector;
char *realm;
char *contact_params;
char *contact_uri_params;
int expires;
int publish_expires;
SalOp *op;
SalCustomHeader *sent_headers;
char *type;
struct _SipSetupContext *ssctx;
int auth_failures;
char *dial_prefix;
LinphoneRegistrationState state;
LinphoneAVPFMode avpf_mode;
bool_t commit;
bool_t reg_sendregister;
bool_t publish;
bool_t dial_escape_plus;
bool_t send_publish;
bool_t quality_reporting_enabled;
uint8_t avpf_rr_interval;
uint8_t quality_reporting_interval;
time_t deletion_date;
LinphonePrivacyMask privacy;
/*use to check if server config has changed between edit() and done()*/
LinphoneAddress *saved_proxy;
LinphoneAddress *saved_identity;
/*---*/
LinphoneAddress *pending_contact; /*use to store previous contact in case of network failure*/
LinphoneEvent *long_term_event;
unsigned long long previous_publish_config_hash[2];
};
submodules/linphone/include/sal/sal.h:struct SalCustomHeader;
submodules/linphone/include/sal/sal.h:typedef struct SalCustomHeader SalCustomHeader;
submodules/linphone/coreapi/linphonecore.h:typedef enum _LinphoneRegistrationState{
submodules/linphone/coreapi/linphonecore.h:}LinphoneRegistrationState;
/**
* LinphoneRegistrationState describes proxy registration states.
**/
typedef enum _LinphoneRegistrationState{
LinphoneRegistrationNone, /**<Initial state for registrations */
LinphoneRegistrationProgress, /**<Registration is in progress */
LinphoneRegistrationOk, /**< Registration is successful */
LinphoneRegistrationCleared, /**< Unregistration succeeded */
LinphoneRegistrationFailed /**<Registration failed */
}LinphoneRegistrationState;
/**
* Enum describing RTP AVPF activation modes.
**/
enum _LinphoneAVPFMode{
LinphoneAVPFDefault=-1, /**<Use default value defined at upper level*/
LinphoneAVPFDisabled, /**<AVPF is disabled*/
LinphoneAVPFEnabled /**<AVPF is enabled */
};
submodules/linphone/coreapi/linphonecore.h:typedef unsigned int LinphonePrivacyMask;
submodules/linphone/coreapi/event.h:struct _LinphoneEvent;
submodules/linphone/coreapi/event.h:typedef struct _LinphoneEvent LinphoneEvent;
submodules/linphone/coreapi/private.h:struct _LinphoneEvent{
struct _LinphoneEvent{
belle_sip_object_t base;
LinphoneSubscriptionDir dir;
LinphoneCore *lc;
SalOp *op;
SalCustomHeader *send_custom_headers;
LinphoneSubscriptionState subscription_state;
LinphonePublishState publish_state;
void *userdata;
char *name;
int expires;
bool_t terminating;
bool_t is_out_of_dialog_op; /*used for out of dialog notify*/
bool_t internal;
};
submodules/linphone/coreapi/linphone_proxy_config.h:LINPHONE_PUBLIC void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud);
submodules/linphone/coreapi/proxy.c:void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud) {
void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud) {
cfg->user_data = ud;
}
extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState( JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jint)linphone_call_get_state((LinphoneCall*)ptr);
}
submodules/linphone/coreapi/linphonecall.c:LinphoneCallState linphone_call_get_state(const LinphoneCall *call){
/**
* Retrieves the call's current state.
**/
LinphoneCallState linphone_call_get_state(const LinphoneCall *call){
return call->state;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv* env,jobject thiz,jlong ptr,jint delay) {
linphone_proxy_config_set_expires((LinphoneProxyConfig *) ptr, (int) delay);
}
submodules/linphone/coreapi/proxy.c:void linphone_proxy_config_set_expires(LinphoneProxyConfig *cfg, int val){
void linphone_proxy_config_set_expires(LinphoneProxyConfig *cfg, int val){
if (val<0) val=600;
cfg->expires=val;
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_getExpires(JNIEnv* env,jobject thiz,jlong ptr) {
return linphone_proxy_config_get_expires((LinphoneProxyConfig *) ptr);
}
submodules/linphone/coreapi/linphone_proxy_config.h:LINPHONE_PUBLIC int linphone_proxy_config_get_expires(const LinphoneProxyConfig *cfg);
submodules/linphone/coreapi/proxy.c:int linphone_proxy_config_get_expires(const LinphoneProxyConfig *cfg){
submodules/linphone/coreapi/proxy.c:int linphone_proxy_config_get_expires(const LinphoneProxyConfig *cfg){
/**
* @return the duration of registration.
**/
int linphone_proxy_config_get_expires(const LinphoneProxyConfig *cfg){
return cfg->expires;
}
//ProxyConfig
extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_createProxyConfig(JNIEnv* env, jobject thiz, jlong lc) {
LinphoneProxyConfig* proxy = linphone_core_create_proxy_config((LinphoneCore *)lc);
linphone_proxy_config_set_user_data(proxy,env->NewWeakGlobalRef(thiz));
return (jlong) proxy;
}
submodules/linphone/coreapi/proxy.c:LinphoneProxyConfig * linphone_core_create_proxy_config(LinphoneCore *lc) {
LinphoneProxyConfig * linphone_core_create_proxy_config(LinphoneCore *lc) {
LinphoneProxyConfig *cfg = belle_sip_object_new(LinphoneProxyConfig);
linphone_proxy_config_init(lc,cfg);
return cfg;
}
linphone_proxy_config_init
static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *cfg) {
const char *dial_prefix = lc ? lp_config_get_default_string(lc->config,"proxy","dial_prefix",NULL) : NULL;
const char *identity = lc ? lp_config_get_default_string(lc->config, "proxy", "reg_identity", NULL) : NULL;
const char *proxy = lc ? lp_config_get_default_string(lc->config, "proxy", "reg_proxy", NULL) : NULL;
const char *route = lc ? lp_config_get_default_string(lc->config, "proxy", "reg_route", NULL) : NULL;
const char *realm = lc ? lp_config_get_default_string(lc->config, "proxy", "realm", NULL) : NULL;
const char *quality_reporting_collector = lc ? lp_config_get_default_string(lc->config, "proxy", "quality_reporting_collector", NULL) : NULL;
const char *contact_params = lc ? lp_config_get_default_string(lc->config, "proxy", "contact_parameters", NULL) : NULL;
const char *contact_uri_params = lc ? lp_config_get_default_string(lc->config, "proxy", "contact_uri_parameters", NULL) : NULL;
cfg->expires = lc ? lp_config_get_default_int(lc->config, "proxy", "reg_expires", 3600) : 3600;
cfg->reg_sendregister = lc ? lp_config_get_default_int(lc->config, "proxy", "reg_sendregister", 1) : 1;
cfg->dial_prefix = dial_prefix ? ms_strdup(dial_prefix) : NULL;
cfg->dial_escape_plus = lc ? lp_config_get_default_int(lc->config, "proxy", "dial_escape_plus", 0) : 0;
cfg->privacy = lc ? lp_config_get_default_int(lc->config, "proxy", "privacy", LinphonePrivacyDefault) : LinphonePrivacyDefault;
cfg->identity_address = identity ? linphone_address_new(identity) : NULL;
cfg->reg_identity = cfg->identity_address ? linphone_address_as_string(cfg->identity_address) : NULL;
cfg->reg_proxy = proxy ? ms_strdup(proxy) : NULL;
cfg->reg_route = route ? ms_strdup(route) : NULL;
cfg->realm = realm ? ms_strdup(realm) : NULL;
cfg->quality_reporting_enabled = lc ? lp_config_get_default_int(lc->config, "proxy", "quality_reporting_enabled", 0) : 0;
cfg->quality_reporting_collector = quality_reporting_collector ? ms_strdup(quality_reporting_collector) : NULL;
cfg->quality_reporting_interval = lc ? lp_config_get_default_int(lc->config, "proxy", "quality_reporting_interval", 0) : 0;
cfg->contact_params = contact_params ? ms_strdup(contact_params) : NULL;
cfg->contact_uri_params = contact_uri_params ? ms_strdup(contact_uri_params) : NULL;
cfg->avpf_mode = lc ? lp_config_get_default_int(lc->config, "proxy", "avpf", LinphoneAVPFDefault) : LinphoneAVPFDefault;
cfg->avpf_rr_interval = lc ? lp_config_get_default_int(lc->config, "proxy", "avpf_rr_interval", 5) : 5;
cfg->publish_expires=-1;
}
void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud) {
cfg->user_data = ud;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
}
void linphone_proxy_config_edit(LinphoneProxyConfig *cfg){
/*store current config related to server location*/
linphone_proxy_config_store_server_config(cfg);
linphone_proxy_config_compute_publish_params_hash(cfg);
if (cfg->publish && cfg->long_term_event){
linphone_event_pause_publish(cfg->long_term_event);
}
/*stop refresher in any case*/
linphone_proxy_config_pause_register(cfg);
}
/*store current config related to server location*/
static void linphone_proxy_config_store_server_config(LinphoneProxyConfig* cfg) {
if (cfg->saved_identity) linphone_address_destroy(cfg->saved_identity);
if (cfg->identity_address)
cfg->saved_identity = linphone_address_clone(cfg->identity_address);
else
cfg->saved_identity = NULL;
if (cfg->saved_proxy) linphone_address_destroy(cfg->saved_proxy);
if (cfg->reg_proxy)
cfg->saved_proxy = linphone_address_new(cfg->reg_proxy);
else
cfg->saved_proxy = NULL;
}
/*
* return true if computed value has changed
*/
bool_t linphone_proxy_config_compute_publish_params_hash(LinphoneProxyConfig * cfg) {
char * source = NULL;
char hash[33];
char saved;
unsigned long long previous_hash[2];
previous_hash[0] = cfg->previous_publish_config_hash[0];
previous_hash[1] = cfg->previous_publish_config_hash[1];
source = ms_strcat_printf(source, "%i",cfg->privacy);
source=append_linphone_address(cfg->identity_address, source);
source=append_string(cfg->reg_proxy,source);
source=append_string(cfg->reg_route,source);
source=append_string(cfg->realm,source);
source = ms_strcat_printf(source, "%i",cfg->publish_expires);
source = ms_strcat_printf(source, "%i",cfg->publish);
belle_sip_auth_helper_compute_ha1(source, "dummy", "dummy", hash);
ms_free(source);
saved = hash[16];
hash[16] = '\0';
cfg->previous_publish_config_hash[0] = strtoull(hash, (char **)NULL, 16);
hash[16] = saved;
cfg->previous_publish_config_hash[1] = strtoull(&hash[16], (char **)NULL, 16);
return previous_hash[0] != cfg->previous_publish_config_hash[0] || previous_hash[1] != cfg->previous_publish_config_hash[1];
}
submodules/linphone/coreapi/event.h:LINPHONE_PUBLIC void linphone_event_pause_publish(LinphoneEvent *lev);
submodules/linphone/coreapi/proxy.c: linphone_event_pause_publish(cfg->long_term_event);
submodules/linphone/coreapi/event.c:void linphone_event_pause_publish(LinphoneEvent *lev) {
void linphone_proxy_config_pause_register(LinphoneProxyConfig *cfg){
if (cfg->op) sal_op_stop_refreshing(cfg->op);
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
}
/**
* Commits modification made to the proxy configuration.
**/
int linphone_proxy_config_done(LinphoneProxyConfig *cfg)
{
LinphoneProxyConfigAddressComparisonResult res;
if (!linphone_proxy_config_check(cfg->lc,cfg))
return -1;
/*check if server address as changed*/
res = linphone_proxy_config_is_server_config_changed(cfg);
if (res != LinphoneProxyConfigAddressEqual) {
/* server config has changed, need to unregister from previous first*/
if (cfg->op) {
if (res == LinphoneProxyConfigAddressDifferent) {
_linphone_proxy_config_unregister(cfg);
}
sal_op_set_user_pointer(cfg->op,NULL); /*we don't want to receive status for this un register*/
sal_op_unref(cfg->op); /*but we keep refresher to handle authentication if needed*/
cfg->op=NULL;
}
if (cfg->long_term_event) {
if (res == LinphoneProxyConfigAddressDifferent) {
_linphone_proxy_config_unpublish(cfg);
}
}
}
if (linphone_proxy_config_compute_publish_params_hash(cfg)) {
ms_message("Publish params have changed on proxy config [%p]",cfg);
if (cfg->long_term_event) {
if (!cfg->publish) {
/*publish is terminated*/
linphone_event_terminate(cfg->long_term_event);
}
linphone_event_unref(cfg->long_term_event);
cfg->long_term_event = NULL;
}
if (cfg->publish) cfg->send_publish=TRUE;
} else {
ms_message("Publish params have not changed on proxy config [%p]",cfg);
}
cfg->commit=TRUE;
linphone_proxy_config_write_all_to_config_file(cfg->lc);
return 0;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
const char* identity = env->GetStringUTFChars(jidentity, NULL);
linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
env->ReleaseStringUTFChars(jidentity, identity);
}
int linphone_proxy_config_set_identity_address(LinphoneProxyConfig *cfg, const LinphoneAddress *addr){
if (!addr || linphone_address_get_username(addr)==NULL){
char* as_string = addr ? linphone_address_as_string(addr) : ms_strdup("NULL");
ms_warning("Invalid sip identity: %s", as_string);
ms_free(as_string);
return -1;
}
if (cfg->identity_address != NULL) {
linphone_address_destroy(cfg->identity_address);
}
cfg->identity_address=linphone_address_clone(addr);
if (cfg->reg_identity!=NULL) {
ms_free(cfg->reg_identity);
}
cfg->reg_identity= linphone_address_as_string(cfg->identity_address);
return 0;
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
if (identity) {
return env->NewStringUTF(identity);
} else {
return NULL;
}
}
const char *linphone_proxy_config_get_identity(const LinphoneProxyConfig *cfg){
return cfg->reg_identity;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setAddress(JNIEnv* env,jobject thiz,jlong proxyCfg,jlong jidentity) {
linphone_proxy_config_set_identity_address((LinphoneProxyConfig*)proxyCfg, (LinphoneAddress*) jidentity);
}
int linphone_proxy_config_set_identity_address(LinphoneProxyConfig *cfg, const LinphoneAddress *addr){
if (!addr || linphone_address_get_username(addr)==NULL){
char* as_string = addr ? linphone_address_as_string(addr) : ms_strdup("NULL");
ms_warning("Invalid sip identity: %s", as_string);
ms_free(as_string);
return -1;
}
if (cfg->identity_address != NULL) {
linphone_address_destroy(cfg->identity_address);
}
cfg->identity_address=linphone_address_clone(addr);
if (cfg->reg_identity!=NULL) {
ms_free(cfg->reg_identity);
}
cfg->reg_identity= linphone_address_as_string(cfg->identity_address);
return 0;
}
extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env
,jobject thiz
,jlong ptr) {
return (jlong)linphone_friend_get_address((LinphoneFriend*)ptr);
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
const char* proxy = env->GetStringUTFChars(jproxy, NULL);
jint err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
env->ReleaseStringUTFChars(jproxy, proxy);
return err;
}
int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *cfg, const char *server_addr){
LinphoneAddress *addr=NULL;
char *modified=NULL;
if (cfg->reg_proxy!=NULL) ms_free(cfg->reg_proxy);
cfg->reg_proxy=NULL;
if (server_addr!=NULL && strlen(server_addr)>0){
if (strstr(server_addr,"sip:")==NULL && strstr(server_addr,"sips:")==NULL){
modified=ms_strdup_printf("sip:%s",server_addr);
addr=linphone_address_new(modified);
ms_free(modified);
}
if (addr==NULL)
addr=linphone_address_new(server_addr);
if (addr){
cfg->reg_proxy=linphone_address_as_string(addr);
linphone_address_destroy(addr);
}else{
ms_warning("Could not parse %s",server_addr);
return -1;
}
}
return 0;
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
if (proxy) {
return env->NewStringUTF(proxy);
} else {
return NULL;
}
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
}
submodules/linphone/coreapi/linphone_proxy_config.h:LINPHONE_PUBLIC void linphone_proxy_config_enable_register(LinphoneProxyConfig *cfg, bool_t val);
submodules/linphone/coreapi/linphone_proxy_config.h:#define linphone_proxy_config_enableregister linphone_proxy_config_enable_register
linphone_proxy_config_enableregister
submodules/linphone/coreapi/proxy.c:void linphone_proxy_config_enableregister(LinphoneProxyConfig *cfg, bool_t val){
void linphone_proxy_config_enableregister(LinphoneProxyConfig *cfg, bool_t val){
cfg->reg_sendregister=val;
}
extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
return (jboolean)linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
}
bool_t linphone_proxy_config_register_enabled(const LinphoneProxyConfig *cfg){
return cfg->reg_sendregister;
}
extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
return (jboolean)linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
}
bool_t linphone_proxy_config_is_registered(const LinphoneProxyConfig *cfg){
return cfg->state == LinphoneRegistrationOk;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
,jobject thiz
,jlong proxyCfg
,jstring jprefix) {
const char* prefix = env->GetStringUTFChars(jprefix, NULL);
linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
env->ReleaseStringUTFChars(jprefix, prefix);
}
void linphone_proxy_config_set_dial_prefix(LinphoneProxyConfig *cfg, const char *prefix){
if (cfg->dial_prefix!=NULL){
ms_free(cfg->dial_prefix);
cfg->dial_prefix=NULL;
}
if (prefix && prefix[0]!='\0') cfg->dial_prefix=ms_strdup(prefix);
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDialPrefix(JNIEnv* env,jobject thiz,jlong proxyCfg) {
const char * prefix = linphone_proxy_config_get_dial_prefix((LinphoneProxyConfig*)proxyCfg);
return prefix ? env->NewStringUTF(prefix) : NULL;
}
const char *linphone_proxy_config_get_dial_prefix(const LinphoneProxyConfig *cfg){
return cfg->dial_prefix;
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
if (jnumber == 0) {
ms_error("cannot normalized null number");
}
char * normalized_phone;
const char* number = env->GetStringUTFChars(jnumber, NULL);
int len = env->GetStringLength(jnumber);
if (len == 0) {
ms_warning("cannot normalize empty number");
return jnumber;
}
normalized_phone = linphone_proxy_config_normalize_phone_number((LinphoneProxyConfig*)proxyCfg,number);
jstring normalizedNumber = env->NewStringUTF(normalized_phone ? normalized_phone : number);
env->ReleaseStringUTFChars(jnumber, number);
ms_free(normalized_phone);
return normalizedNumber;
}
char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, const char *username) {
LinphoneProxyConfig *tmpproxy = proxy ? proxy : linphone_proxy_config_new();
char* result = NULL;
if (linphone_proxy_config_is_phone_number(tmpproxy, username)){
dial_plan_t dialplan = {0};
char * flatten=flatten_number(username);
ms_debug("Flattened number is '%s' for '%s'",flatten, username);
/*if proxy has a dial prefix, modify phonenumber accordingly*/
if (tmpproxy->dial_prefix!=NULL && tmpproxy->dial_prefix[0]!='\0'){
lookup_dial_plan_by_ccc(tmpproxy->dial_prefix,&dialplan);
ms_debug("Using dial plan '%s'",dialplan.country);
/* the number already starts with + or international prefix*/
if (flatten[0]=='+'||strstr(flatten,dialplan.icp)==flatten){
ms_debug("Prefix already present.");
if (tmpproxy->dial_escape_plus) {
result = replace_plus_with_icp(flatten,dialplan.icp);
} else {
result = replace_icp_with_plus(flatten,dialplan.icp);
}
}else{
/*0. keep at most national number significant digits */
char* flatten_start = flatten + MAX(0, (int)strlen(flatten) - (int)dialplan.nnl);
ms_debug("Prefix not present. Keeping at most %d digits: %s", dialplan.nnl, flatten_start);
/*1. First prepend international calling prefix or +*/
/*2. Second add prefix*/
/*3. Finally add user digits */
result = ms_strdup_printf("%s%s%s"
, tmpproxy->dial_escape_plus ? dialplan.icp : "+"
, dialplan.ccc
, flatten_start);
ms_debug("Prepended prefix resulted in %s", result);
}
}
if (result==NULL) {
result = flatten;
} else {
ms_free(flatten);
}
}
if (proxy==NULL) linphone_proxy_config_destroy(tmpproxy);
return result;
}
linphone_proxy_config_is_phone_number
bool_t linphone_proxy_config_is_phone_number(LinphoneProxyConfig *proxy, const char *username){
const char *p;
for(p=username;*p!='\0';++p){
if (isdigit(*p) ||
*p==' ' ||
*p=='.' ||
*p=='-' ||
*p==')' ||
*p=='(' ||
*p=='/' ||
*p=='+' ||
(unsigned char)*p==0xca || (unsigned char)*p==0xc2 || (unsigned char)*p==0xa0 // non-breakable space (iOS uses it to format contacts phone number)
) {
continue;
}
return FALSE;
}
return TRUE;
}
dial_plan_t
*
* http://en.wikipedia.org/wiki/Telephone_numbering_plan
* http://en.wikipedia.org/wiki/Telephone_numbers_in_Europe
*/
typedef struct dial_plan{
const char *country;
const char* iso_country_code; /* ISO 3166-1 alpha-2 code, ex: FR for France*/
char ccc[8]; /*country calling code*/
int nnl; /*maximum national number length*/
const char * icp; /*international call prefix, ex: 00 in europe*/
}dial_plan_t;
flatten_number
//remove anything but [0-9] and +
static char *flatten_number(const char *number){
char *result=ms_malloc0(strlen(number)+1);
char *w=result;
const char *r;
for(r=number;*r!='\0';++r){
if (*r=='+' || isdigit(*r)){
*w++=*r;
}
}
*w++='\0';
return result;
}
lookup_dial_plan_by_ccc
static bool_t lookup_dial_plan_by_ccc(const char *ccc, dial_plan_t *plan){
int i;
for(i=0;dial_plans[i].country!=NULL;++i){
if (strcmp(ccc,dial_plans[i].ccc)==0){
*plan=dial_plans[i];
return TRUE;
}
}
/*else return a generic "most common" dial plan*/
*plan=most_common_dialplan;
strcpy(plan->ccc,ccc);
return FALSE;
}
replace_plus_with_icp
static char* replace_plus_with_icp(char *phone, const char* icp){
return (icp && phone[0]=='+') ? ms_strdup_printf("%s%s", icp, phone+1) : ms_strdup(phone);
}
replace_icp_with_plus
static char* replace_icp_with_plus(char *phone, const char *icp){
return (strstr(phone, icp) == phone) ? ms_strdup_printf("+%s", phone+strlen(icp)) : ms_strdup(phone);
}
linphone_proxy_config_destroy
static void _linphone_proxy_config_destroy(LinphoneProxyConfig *cfg);
void _linphone_proxy_config_destroy(LinphoneProxyConfig *cfg){
if (cfg->reg_proxy!=NULL) ms_free(cfg->reg_proxy);
if (cfg->reg_identity!=NULL) ms_free(cfg->reg_identity);
if (cfg->identity_address!=NULL) linphone_address_destroy(cfg->identity_address);
if (cfg->reg_route!=NULL) ms_free(cfg->reg_route);
if (cfg->quality_reporting_collector!=NULL) ms_free(cfg->quality_reporting_collector);
if (cfg->ssctx!=NULL) sip_setup_context_free(cfg->ssctx);
if (cfg->realm!=NULL) ms_free(cfg->realm);
if (cfg->type!=NULL) ms_free(cfg->type);
if (cfg->dial_prefix!=NULL) ms_free(cfg->dial_prefix);
if (cfg->contact_params) ms_free(cfg->contact_params);
if (cfg->contact_uri_params) ms_free(cfg->contact_uri_params);
if (cfg->saved_proxy!=NULL) linphone_address_destroy(cfg->saved_proxy);
if (cfg->saved_identity!=NULL) linphone_address_destroy(cfg->saved_identity);
if (cfg->sent_headers!=NULL) sal_custom_header_free(cfg->sent_headers);
if (cfg->pending_contact) linphone_address_unref(cfg->pending_contact);
_linphone_proxy_config_release_ops(cfg);
}
extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_normalizeSipUri(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jusername) {
const char* username = env->GetStringUTFChars(jusername, NULL);
LinphoneAddress *addr = linphone_proxy_config_normalize_sip_uri((LinphoneProxyConfig*)proxyCfg, username);
env->ReleaseStringUTFChars(jusername, username);
return (jlong) addr;
}
LinphoneAddress* linphone_proxy_config_normalize_sip_uri(LinphoneProxyConfig *proxy, const char *username) {
enum_lookup_res_t *enumres=NULL;
char *enum_domain=NULL;
char *tmpurl;
LinphoneAddress *uri;
if (!username || *username=='\0') return NULL;
if (is_enum(username,&enum_domain)){
if (proxy) {
linphone_core_notify_display_status(proxy->lc,_("Looking for telephone number destination..."));
}
if (enum_lookup(enum_domain,&enumres)<0){
if (proxy) {
linphone_core_notify_display_status(proxy->lc,_("Could not resolve this number."));
}
ms_free(enum_domain);
return NULL;
}
ms_free(enum_domain);
tmpurl=enumres->sip_address[0];
uri=linphone_address_new(tmpurl);
enum_lookup_res_free(enumres);
return _linphone_core_destroy_addr_if_not_sip(uri);
}
/* check if we have a "sip:" or a "sips:" */
if ( (strstr(username,"sip:")==NULL) && (strstr(username,"sips:")==NULL) ){
/* this doesn't look like a true sip uri */
if (strchr(username,'@')!=NULL){
/* seems like sip: is missing !*/
tmpurl=ms_strdup_printf("sip:%s",username);
uri=linphone_address_new(tmpurl);
ms_free(tmpurl);
if (uri){
return _linphone_core_destroy_addr_if_not_sip(uri);
}
}
if (proxy!=NULL){
/* append the proxy domain suffix but remove any custom parameters/headers */
LinphoneAddress *uri=linphone_address_clone(linphone_proxy_config_get_identity_address(proxy));
linphone_address_clean(uri);
if (uri==NULL){
return NULL;
} else {
linphone_address_set_display_name(uri,NULL);
linphone_address_set_username(uri,username);
return _linphone_core_destroy_addr_if_not_sip(uri);
}
} else {
return NULL;
}
}
uri=linphone_address_new(username);
if (uri!=NULL){
return _linphone_core_destroy_addr_if_not_sip(uri);
}
return NULL;
}
submodules/linphone/coreapi/vtables.c:void linphone_core_notify_display_status(LinphoneCore *lc, const char *message) {
void linphone_core_notify_display_status(LinphoneCore *lc, const char *message) {
NOTIFY_IF_EXIST(display_status, lc,message);
cleanup_dead_vtable_refs(lc);
}
NOTIFY_IF_EXIST
#define NOTIFY_IF_EXIST(function_name, ...) \
MSList* iterator; \
VTableReference *ref; \
bool_t has_cb = FALSE; \
for (iterator=lc->vtable_refs; iterator!=NULL; iterator=iterator->next)\
if ((ref=(VTableReference*)iterator->data)->valid && (lc->current_vtable=ref->vtable)->function_name) {\
lc->current_vtable->function_name(__VA_ARGS__);\
has_cb = TRUE;\
}\
if (has_cb) ms_message("Linphone core [%p] notifying [%s]",lc,#function_name)
cleanup_dead_vtable_refs
static void cleanup_dead_vtable_refs(LinphoneCore *lc){
MSList *it,*next_it;
for(it=lc->vtable_refs; it!=NULL; ){
VTableReference *ref=(VTableReference*)it->data;
next_it=it->next;
if (ref->valid==0){
ref->valid=0;
lc->vtable_refs=ms_list_remove_link(lc->vtable_refs, it);
ms_free(ref);
}
it=next_it;
}
}
submodules/linphone/coreapi/vtables.c:static void cleanup_dead_vtable_refs(LinphoneCore *lc)
static void cleanup_dead_vtable_refs(LinphoneCore *lc){
MSList *it,*next_it;
for(it=lc->vtable_refs; it!=NULL; ){
VTableReference *ref=(VTableReference*)it->data;
next_it=it->next;
if (ref->valid==0){
ref->valid=0;
lc->vtable_refs=ms_list_remove_link(lc->vtable_refs, it);
ms_free(ref);
}
it=next_it;
}
}
static LinphoneAddress* _linphone_core_destroy_addr_if_not_sip( LinphoneAddress* addr ){
if( linphone_address_is_sip(addr) ) {
return addr;
} else {
linphone_address_destroy(addr);
return NULL;
}
}
linphone_address_is_sip
/**
* returns true if address is a routable sip address
*/
bool_t linphone_address_is_sip(const LinphoneAddress *uri){
return sal_address_is_sip(uri);
}
linphone_address_destroy
/**
* Destroys a LinphoneAddress object (actually calls linphone_address_unref()).
* @deprecated Use linphone_address_unref() instead
**/
void linphone_address_destroy(LinphoneAddress *u){
sal_address_unref(u);
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
,jobject thiz
,jlong proxyCfg) {
const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
if (domain) {
return env->NewStringUTF(domain);
} else {
return NULL;
}
}
const char *linphone_proxy_config_get_domain(const LinphoneProxyConfig *cfg){
return cfg->identity_address ? linphone_address_get_domain(cfg->identity_address) : NULL;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
}
void linphone_proxy_config_set_dial_escape_plus(LinphoneProxyConfig *cfg, bool_t val){
cfg->dial_escape_plus=val;
}
extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_getDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg) {
return (jboolean) linphone_proxy_config_get_dial_escape_plus((LinphoneProxyConfig*)proxyCfg);
}
bool_t linphone_proxy_config_get_dial_escape_plus(const LinphoneProxyConfig *cfg){
return cfg->dial_escape_plus;
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
if (route) {
return env->NewStringUTF(route);
} else {
return NULL;
}
}
const char *linphone_proxy_config_get_route(const LinphoneProxyConfig *cfg){
return cfg->reg_route;
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
if (jroute != NULL) {
const char* route = env->GetStringUTFChars(jroute, NULL);
jint err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
env->ReleaseStringUTFChars(jroute, route);
return err;
} else {
return (jint)linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
}
}
int linphone_proxy_config_set_route(LinphoneProxyConfig *cfg, const char *route)
{
if (cfg->reg_route!=NULL){
ms_free(cfg->reg_route);
cfg->reg_route=NULL;
}
if (route!=NULL && route[0] !='\0'){
SalAddress *addr;
char *tmp;
/*try to prepend 'sip:' */
if (strstr(route,"sip:")==NULL && strstr(route,"sips:")==NULL){
tmp=ms_strdup_printf("sip:%s",route);
}else tmp=ms_strdup(route);
addr=sal_address_new(tmp);
if (addr!=NULL){
sal_address_destroy(addr);
cfg->reg_route=tmp;
return 0;
}else{
ms_free(tmp);
return -1;
}
} else {
return 0;
}
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
,jobject thiz
,jlong proxyCfg
,jboolean val) {
linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
}
void linphone_proxy_config_enable_publish(LinphoneProxyConfig *cfg, bool_t val){
cfg->publish=val;
}
extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
return (jboolean)linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
}
bool_t linphone_proxy_config_publish_enabled(const LinphoneProxyConfig *cfg){
return cfg->publish;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setContactParameters(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jparams) {
const char* params = jparams ? env->GetStringUTFChars(jparams, NULL) : NULL;
linphone_proxy_config_set_contact_parameters((LinphoneProxyConfig*)proxyCfg, params);
if (jparams) env->ReleaseStringUTFChars(jparams, params);
}
void linphone_proxy_config_set_contact_parameters(LinphoneProxyConfig *cfg, const char *contact_params){
if (cfg->contact_params) {
ms_free(cfg->contact_params);
cfg->contact_params=NULL;
}
if (contact_params){
cfg->contact_params=ms_strdup(contact_params);
}
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_lookupCCCFromIso(JNIEnv* env, jobject thiz, jlong proxyCfg, jstring jiso) {
const char* iso = env->GetStringUTFChars(jiso, NULL);
int prefix = linphone_dial_plan_lookup_ccc_from_iso(iso);
env->ReleaseStringUTFChars(jiso, iso);
return (jint) prefix;
}
int linphone_dial_plan_lookup_ccc_from_iso(const char* iso) {
dial_plan_t* dial_plan;
for (dial_plan=(dial_plan_t*)dial_plans; dial_plan->country!=NULL; dial_plan++) {
if (strcmp(iso, dial_plan->iso_country_code)==0) {
return atoi(dial_plan->ccc);
}
}
return -1;
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_lookupCCCFromE164(JNIEnv* env, jobject thiz, jlong proxyCfg, jstring je164) {
const char* e164 = env->GetStringUTFChars(je164, NULL);
int prefix = linphone_dial_plan_lookup_ccc_from_e164(e164);
env->ReleaseStringUTFChars(je164, e164);
return (jint) prefix;
}
int linphone_dial_plan_lookup_ccc_from_e164(const char* e164) {
dial_plan_t* dial_plan;
dial_plan_t* elected_dial_plan=NULL;
unsigned int found;
unsigned int i=0;
if (e164[1]=='1') {
/*USA case*/
return 1;
}
do {
found=0;
i++;
for (dial_plan=(dial_plan_t*)dial_plans; dial_plan->country!=NULL; dial_plan++) {
if (strncmp(dial_plan->ccc,&e164[1],i) == 0) {
elected_dial_plan=dial_plan;
found++;
}
}
} while ((found>1 || found==0) && i < sizeof(dial_plan->ccc));
if (found==1) {
return atoi(elected_dial_plan->ccc);
} else {
return -1; /*not found */
}
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_getError(JNIEnv* env,jobject thiz,jlong ptr) {
return linphone_proxy_config_get_error((LinphoneProxyConfig *) ptr);
}
LinphoneReason linphone_proxy_config_get_error(const LinphoneProxyConfig *cfg) {
return linphone_error_info_get_reason(linphone_proxy_config_get_error_info(cfg));
}
submodules/linphone/coreapi/misc.c:LinphoneReason linphone_error_info_get_reason(const LinphoneErrorInfo *ei){
linphone_error_info_get_reason
/**
* Get reason code from the error info.
* @param ei the error info.
* @return a #LinphoneReason
* @ingroup misc
**/
LinphoneReason linphone_error_info_get_reason(const LinphoneErrorInfo *ei){
const SalErrorInfo *sei=(const SalErrorInfo*)ei;
return linphone_reason_from_sal(sei->reason);
}
linphone_reason_from_sal
LinphoneReason linphone_reason_from_sal(SalReason r){
LinphoneReason ret=LinphoneReasonNone;
switch(r){
case SalReasonNone:
ret=LinphoneReasonNone;
break;
case SalReasonIOError:
ret=LinphoneReasonIOError;
break;
case SalReasonUnknown:
case SalReasonInternalError:
ret=LinphoneReasonUnknown;
break;
case SalReasonBusy:
ret=LinphoneReasonBusy;
break;
case SalReasonDeclined:
ret=LinphoneReasonDeclined;
break;
case SalReasonDoNotDisturb:
ret=LinphoneReasonDoNotDisturb;
break;
case SalReasonForbidden:
ret=LinphoneReasonBadCredentials;
break;
case SalReasonNotAcceptable:
ret=LinphoneReasonNotAcceptable;
break;
case SalReasonNotFound:
ret=LinphoneReasonNotFound;
break;
case SalReasonRedirect:
ret=LinphoneReasonNone;
break;
case SalReasonTemporarilyUnavailable:
ret=LinphoneReasonTemporarilyUnavailable;
break;
case SalReasonServiceUnavailable:
ret=LinphoneReasonIOError;
break;
case SalReasonRequestPending:
ret=LinphoneReasonTemporarilyUnavailable; /*might not be exactly the perfect matching, but better than LinphoneReasonNone*/
break;
case SalReasonUnauthorized:
ret=LinphoneReasonUnauthorized;
break;
case SalReasonUnsupportedContent:
ret=LinphoneReasonUnsupportedContent;
break;
case SalReasonNoMatch:
ret=LinphoneReasonNoMatch;
break;
case SalReasonRequestTimeout:
ret=LinphoneReasonNotAnswered;
break;
case SalReasonMovedPermanently:
ret=LinphoneReasonMovedPermanently;
break;
case SalReasonGone:
ret=LinphoneReasonGone;
break;
case SalReasonAddressIncomplete:
ret=LinphoneReasonAddressIncomplete;
break;
case SalReasonNotImplemented:
ret=LinphoneReasonNotImplemented;
break;
case SalReasonBadGateway:
ret=LinphoneReasonBadGateway;
break;
case SalReasonServerTimeout:
ret=LinphoneReasonServerTimeout;
break;
}
return ret;
}
extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setPrivacy(JNIEnv* env
,jobject thiz
,jlong cp
,jint privacy) {
linphone_call_params_set_privacy((LinphoneCallParams*)cp,privacy);
}
submodules/linphone/coreapi/call_params.h:LINPHONE_PUBLIC void linphone_call_params_set_privacy(LinphoneCallParams *params, LinphonePrivacyMask privacy);
submodules/linphone/coreapi/call_params.c:void linphone_call_params_set_privacy(LinphoneCallParams *params, LinphonePrivacyMask privacy) {
void linphone_call_params_set_privacy(LinphoneCallParams *params, LinphonePrivacyMask privacy) {
params->privacy=privacy;
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_getPrivacy(JNIEnv* env,jobject thiz,jlong ptr) {
return linphone_proxy_config_get_privacy((LinphoneProxyConfig *) ptr);
}
LinphonePrivacyMask linphone_proxy_config_get_privacy(const LinphoneProxyConfig *params) {
return params->privacy;
}
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_enableAvpf(JNIEnv *env, jobject thiz, jlong ptr, jboolean enable) {
linphone_proxy_config_enable_avpf((LinphoneProxyConfig *)ptr, (bool)enable);
}
void linphone_proxy_config_enable_avpf(LinphoneProxyConfig *cfg, bool_t enable) {
cfg->avpf_mode=enable ? LinphoneAVPFEnabled : LinphoneAVPFDisabled;
}
JNIEXPORT jboolean JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_avpfEnabled(JNIEnv *env, jobject thiz, jlong ptr) {
return linphone_proxy_config_avpf_enabled((LinphoneProxyConfig *)ptr);
}
bool_t linphone_proxy_config_avpf_enabled(LinphoneProxyConfig *cfg) {
if (cfg->avpf_mode==LinphoneAVPFDefault && cfg->lc){
return linphone_core_get_avpf_mode(cfg->lc)==LinphoneAVPFEnabled;
}
return cfg->avpf_mode == LinphoneAVPFEnabled;
}
submodules/linphone/coreapi/linphonecore.c:LinphoneAVPFMode linphone_core_get_avpf_mode(const LinphoneCore *lc){
/**
* Return AVPF enablement. See linphone_core_set_avpf_mode() .
* @param lc the core
* @return the avpf enablement mode.
* @ingroup media_parameters
**/
LinphoneAVPFMode linphone_core_get_avpf_mode(const LinphoneCore *lc){
return lc->rtp_conf.avpf_mode;
}
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_setAvpfRRInterval(JNIEnv *env, jobject thiz, jlong ptr, jint interval) {
linphone_proxy_config_set_avpf_rr_interval((LinphoneProxyConfig *)ptr, (uint8_t)interval);
}
void linphone_proxy_config_set_avpf_rr_interval(LinphoneProxyConfig *cfg, uint8_t interval) {
if (interval > 5) interval = 5;
cfg->avpf_rr_interval = interval;
}
JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_getAvpfRRInterval(JNIEnv *env, jobject thiz, jlong ptr) {
return (jint)linphone_proxy_config_get_avpf_rr_interval((LinphoneProxyConfig *)ptr);
}
uint8_t linphone_proxy_config_get_avpf_rr_interval(const LinphoneProxyConfig *cfg) {
return cfg->avpf_rr_interval;
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getContactParameters(JNIEnv* env,jobject thiz,jlong proxyCfg) {
const char* params = linphone_proxy_config_get_contact_parameters((LinphoneProxyConfig*)proxyCfg);
return params ? env->NewStringUTF(params) : NULL;
}
const char *linphone_proxy_config_get_contact_parameters(const LinphoneProxyConfig *cfg){
return cfg->contact_params;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setContactUriParameters(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jparams) {
const char* params = jparams ? env->GetStringUTFChars(jparams, NULL) : NULL;
linphone_proxy_config_set_contact_uri_parameters((LinphoneProxyConfig*)proxyCfg, params);
if (jparams) env->ReleaseStringUTFChars(jparams, params);
}
void linphone_proxy_config_set_contact_uri_parameters(LinphoneProxyConfig *cfg, const char *contact_uri_params){
if (cfg->contact_uri_params) {
ms_free(cfg->contact_uri_params);
cfg->contact_uri_params=NULL;
}
if (contact_uri_params){
cfg->contact_uri_params=ms_strdup(contact_uri_params);
}
}
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getContactUriParameters(JNIEnv* env,jobject thiz,jlong proxyCfg) {
const char* params = linphone_proxy_config_get_contact_uri_parameters((LinphoneProxyConfig*)proxyCfg);
return params ? env->NewStringUTF(params) : NULL;
}
const char *linphone_proxy_config_get_contact_uri_parameters(const LinphoneProxyConfig *cfg){
return cfg->contact_uri_params;
}
extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_getErrorInfo(JNIEnv* env,jobject thiz,jlong ptr) {
return (jlong)linphone_proxy_config_get_error_info((LinphoneProxyConfig *) ptr);
}
const LinphoneErrorInfo *linphone_proxy_config_get_error_info(const LinphoneProxyConfig *cfg){
return linphone_error_info_from_sal_op(cfg->op);
}
submodules/linphone/coreapi/private.h:static MS2_INLINE const LinphoneErrorInfo *linphone_error_info_from_sal_op(const SalOp *op){
static MS2_INLINE const LinphoneErrorInfo *linphone_error_info_from_sal_op(const SalOp *op){
if (op==NULL) return (LinphoneErrorInfo*)sal_error_info_none();
return (const LinphoneErrorInfo*)sal_op_get_error_info(op);
}
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_enableQualityReporting(JNIEnv *env, jobject thiz, jlong ptr, jboolean enable) {
linphone_proxy_config_enable_quality_reporting((LinphoneProxyConfig *)ptr, (bool)enable);
}
void linphone_proxy_config_enable_quality_reporting(LinphoneProxyConfig *cfg, bool_t val){
cfg->quality_reporting_enabled = val;
}
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_setQualityReportingInterval(JNIEnv *env, jobject thiz, jlong ptr, jint interval) {
linphone_proxy_config_set_quality_reporting_interval((LinphoneProxyConfig *)ptr, (uint8_t)interval);
}
void linphone_proxy_config_set_quality_reporting_interval(LinphoneProxyConfig *cfg, uint8_t interval) {
cfg->quality_reporting_interval = interval;
}
JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_getQualityReportingInterval(JNIEnv *env, jobject thiz, jlong ptr) {
return (jint)linphone_proxy_config_get_quality_reporting_interval((LinphoneProxyConfig *)ptr);
}
int linphone_proxy_config_get_quality_reporting_interval(LinphoneProxyConfig *cfg) {
return cfg->quality_reporting_interval;
}
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_setQualityReportingCollector(JNIEnv *env, jobject thiz, jlong ptr, jstring jcollector) {
if (jcollector){
const char *collector=env->GetStringUTFChars(jcollector, NULL);
linphone_proxy_config_set_quality_reporting_collector((LinphoneProxyConfig *)ptr, collector);
env->ReleaseStringUTFChars(jcollector,collector);
}
}
void linphone_proxy_config_set_quality_reporting_collector(LinphoneProxyConfig *cfg, const char *collector){
if (collector!=NULL && strlen(collector)>0){
LinphoneAddress *addr=linphone_address_new(collector);
if (!addr){
ms_error("Invalid SIP collector URI: %s. Quality reporting will be DISABLED.",collector);
} else {
if (cfg->quality_reporting_collector != NULL){
ms_free(cfg->quality_reporting_collector);
}
cfg->quality_reporting_collector = ms_strdup(collector);
}
if (addr){
linphone_address_destroy(addr);
}
}
}
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_getQualityReportingCollector(JNIEnv *env, jobject thiz, jlong ptr) {
jstring jvalue = env->NewStringUTF(linphone_proxy_config_get_quality_reporting_collector((LinphoneProxyConfig *)ptr));
return jvalue;
}
const char *linphone_proxy_config_get_quality_reporting_collector(const LinphoneProxyConfig *cfg){
return cfg->quality_reporting_collector;
}
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_setRealm(JNIEnv *env, jobject thiz, jlong ptr, jstring jrealm) {
if (jrealm){
const char *realm=env->GetStringUTFChars(jrealm, NULL);
linphone_proxy_config_set_realm((LinphoneProxyConfig *)ptr, realm);
env->ReleaseStringUTFChars(jrealm,realm);
}
}
void linphone_proxy_config_set_realm(LinphoneProxyConfig *cfg, const char *realm)
{
if (cfg->realm!=NULL) {
ms_free(cfg->realm);
}
cfg->realm=ms_strdup(realm);
}
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_getRealm(JNIEnv *env, jobject thiz, jlong ptr) {
jstring jvalue = env->NewStringUTF(linphone_proxy_config_get_realm((LinphoneProxyConfig *)ptr));
return jvalue;
}
const char* linphone_proxy_config_get_realm(const LinphoneProxyConfig *cfg)
{
return cfg?cfg->realm:NULL;
}
extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setPublishExpires(JNIEnv* env
,jobject thiz
,jlong ptr
,jint jval) {
linphone_proxy_config_set_publish_expires((LinphoneProxyConfig *) ptr, jval);
}
void linphone_proxy_config_set_publish_expires(LinphoneProxyConfig *cfg, int expires) {
cfg->publish_expires=expires;
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_getPublishExpires(JNIEnv* env,jobject thiz,jlong ptr) {
return (jint)linphone_proxy_config_get_publish_expires((LinphoneProxyConfig *) ptr);
}
int linphone_proxy_config_get_publish_expires(const LinphoneProxyConfig *cfg) {
if (cfg->publish_expires<0) {
return cfg->expires; /*default value is same as register*/
} else {
return cfg->publish_expires;
}
}
JNIEXPORT jboolean JNICALL Java_org_linphone_core_LinphoneProxyConfigImpl_isPhoneNumber(JNIEnv *env, jobject thiz, jlong ptr, jstring jusername) {
if(jusername){
const char *username=env->GetStringUTFChars(jusername, NULL);
bool_t res = linphone_proxy_config_is_phone_number((LinphoneProxyConfig *)ptr, username);
env->ReleaseStringUTFChars(jusername,username);
return (jboolean) res;
} else {
return JNI_FALSE;
}
}
bool_t linphone_proxy_config_is_phone_number(LinphoneProxyConfig *proxy, const char *username){
const char *p;
for(p=username;*p!='\0';++p){
if (isdigit(*p) ||
*p==' ' ||
*p=='.' ||
*p=='-' ||
*p==')' ||
*p=='(' ||
*p=='/' ||
*p=='+' ||
(unsigned char)*p==0xca || (unsigned char)*p==0xc2 || (unsigned char)*p==0xa0 // non-breakable space (iOS uses it to format contacts phone number)
) {
continue;
}
return FALSE;
}
return TRUE;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。