[英]How to add custom header with sip REGISTER request
Yesterday I took the latest linphone
code and successfully compiled it for Android
. 昨天,我获得了最新的
linphone
代码,并成功地将其编译为Android
。 I am able to register successfully and i am able to make calls. 我能够成功注册,并且能够拨打电话。
Now I am trying to use our server with some custom header
. 现在,我尝试将我们的服务器与一些
custom header
一起使用。 I was trying to find a way to add custom header in REGISTER
request. 我试图找到一种在
REGISTER
请求中添加自定义标头的方法。 But failed. 但失败了。
I have done this in iPhone using "linphone_proxy_config_get_custom_header" directly. 我已经在iPhone中直接使用“ linphone_proxy_config_get_custom_header”完成了此操作。
But in Android, the method itself not available in linphonecore_jni.cc. 但是在Android中,该方法本身在linphonecore_jni.cc中不可用。 Also "addCustomHeader" in "LinphoneProxyConfig.java" file.
在“ LinphoneProxyConfig.java”文件中也为“ addCustomHeader”。
But I can see other implementation like; 但我可以看到其他实现,例如;
1. Java_org_linphone_core_LinphoneInfoMessageImpl_addHeader
2. Java_org_linphone_core_LinphoneCallParamsImpl_addCustomHeader
3. Java_org_linphone_core_LinphoneCallParamsImpl_addCustomSdpAttribute
4. Java_org_linphone_core_LinphoneCallParamsImpl_addCustomSdpMediaAttribute
5. Java_org_linphone_core_LinphoneEventImpl_addCustomHeader
6. Java_org_linphone_core_LinphoneChatMessageImpl_addCustomHeader
I don't know how to resolved this issue. 我不知道如何解决这个问题。
Any idea. 任何想法。
I have resolved this issue. 我已经解决了这个问题。
I modified 3 files to fix this issue. 我修改了3个文件来解决此问题。
1.
I added the below code in linphonecore_jni.cc
file. 1.
我在linphonecore_jni.cc
文件中添加了以下代码。
extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getCustomHeader(JNIEnv* env ,jobject thiz ,jlong ptr, jstring jheader_name) { const char *name=env->GetStringUTFChars(jheader_name,NULL); const char *value=linphone_proxy_config_get_custom_header((LinphoneProxyConfig*)ptr,name); env->ReleaseStringUTFChars(jheader_name, name); return value ? env->NewStringUTF(value) : NULL; } extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_addCustomHeader(JNIEnv* env ,jobject thiz ,jlong ptr, jstring jheader_name, jstring jheader_value) { const char *name=env->GetStringUTFChars(jheader_name,NULL); const char *value=env->GetStringUTFChars(jheader_value,NULL); linphone_proxy_config_set_custom_header((LinphoneProxyConfig*)ptr,name,value); env->ReleaseStringUTFChars(jheader_name, name); env->ReleaseStringUTFChars(jheader_value, value); }
2.
Then added below code in LinphoneProxyConfigImpl.java
file: 2.
然后在LinphoneProxyConfigImpl.java
文件中添加以下代码:
private native void addCustomHeader(long nativePtr, String key,String value); public void addCustomHeader(String key,String value) { isValid(); addCustomHeader(nativePtr, key, value); } private native String getCustomHeader(long nativePtr, String key); public String getCustomHeader(String key) { isValid(); return getCustomHeader(nativePtr, key); }
3.
Then, added below code in LinphoneProxyConfig
file. 3.
然后,在LinphoneProxyConfig
文件中添加以下代码。
void addCustomHeader(String key,String value); String getCustomHeader(String key);
In my code, I am adding the x-header
as below: 在我的代码中,我添加了如下的
x-header
:
LinphoneProxyConfig proxyConfig = linphoneCore.createProxyConfig(----); proxyConfig.addCustomHeader("X-Test1", "testing"); proxyConfig.addCustomHeader("X-Test2", "2nd test");
There is a method called setCustomHeader
in latest linphone
source. 最新的
linphone
源代码中有一个名为setCustomHeader
的方法。
proxyConfig.setCustomHeader("X-Test1", "testing"); proxyConfig.setCustomHeader("X-Test2", "2nd test");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.