Set asked password when user agent is created

This commit is contained in:
Juha Heinanen
2022-07-03 17:40:42 +03:00
parent 62965faf0a
commit 0df91b1bc3
4 changed files with 16 additions and 38 deletions

View File

@ -137,30 +137,6 @@ static const char *translate_errorcode(uint16_t scode)
}
}
static void get_password(char *aor, char *password)
{
LOGD("getting password of AoR %s\n", aor);
JavaVM *javaVM = g_ctx.javaVM;
JNIEnv *env;
jint res = (*javaVM)->GetEnv(javaVM, (void**)&env, JNI_VERSION_1_6);
if (res != JNI_OK) {
res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL);
if (JNI_OK != res) {
LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res);
return;
}
}
jmethodID methodId = (*env)->GetMethodID(env, g_ctx.mainActivityClz, "getPassword",
"(Ljava/lang/String;)Ljava/lang/String;");
jstring javaAoR = (*env)->NewStringUTF(env, aor);
jstring javaPassword = (*env)->CallObjectMethod(env, g_ctx.mainActivityObj, methodId, javaAoR);
const char *pwd = (*env)->GetStringUTFChars(env, javaPassword, 0);
strcpy(password, pwd);
(*env)->ReleaseStringUTFChars(env, javaPassword, pwd);
}
static void ua_event_handler(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg)
{
@ -247,9 +223,6 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
case UA_EVENT_MWI_NOTIFY:
len = re_snprintf(event_buf, sizeof event_buf, "mwi notify,%s", prm);
break;
case UA_EVENT_CUSTOM:
get_password((char *)ua, (char *)call);
return;
default:
return;
}

View File

@ -37,6 +37,9 @@ class Account(val accp: Long) {
init {
if (authPass == "")
authPass = NO_AUTH_PASS
var i = 0
while (true) {
val ob = Api.account_outbound(accp, i)

View File

@ -536,12 +536,24 @@ class BaresipService: Service() {
val ev = event.split(",")
if (ev[0] == "create") {
val ua = UserAgent(uap)
ua.status = if (ua.account.regint == 0)
R.drawable.dot_white
else
R.drawable.dot_yellow
uas.add(ua)
val acc = ua.account
if (acc.authUser != "" && acc.authPass == NO_AUTH_PASS) {
val password = if (MainActivity.aorPasswords[acc.aor] != null)
MainActivity.aorPasswords[acc.aor]!!
else
""
Api.account_set_auth_pass(acc.accp, password)
acc.authPass = Api.account_auth_pass(ua.account.accp)
}
return
}
@ -1039,16 +1051,6 @@ class BaresipService: Service() {
}
}
@Keep
fun getPassword(aor: String): String {
if (!isServiceRunning) return ""
Log.d(TAG, "getPassword of $aor")
return if (MainActivity.aorPasswords[aor] != null)
MainActivity.aorPasswords[aor]!!
else
""
}
@Keep
fun started() {
Log.d(TAG, "Received 'started' from baresip")

View File

@ -27,4 +27,4 @@ const val SAVE_REQ_CODE = 10
const val DELETE_REQ_CODE = 11
const val REGISTRATION_INTERVAL = 900
const val NO_AUTH_PASS = "t%Qa?~?J8,~6"