Set asked password when user agent is created
This commit is contained in:
@@ -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,
|
static void ua_event_handler(struct ua *ua, enum ua_event ev,
|
||||||
struct call *call, const char *prm, void *arg)
|
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:
|
case UA_EVENT_MWI_NOTIFY:
|
||||||
len = re_snprintf(event_buf, sizeof event_buf, "mwi notify,%s", prm);
|
len = re_snprintf(event_buf, sizeof event_buf, "mwi notify,%s", prm);
|
||||||
break;
|
break;
|
||||||
case UA_EVENT_CUSTOM:
|
|
||||||
get_password((char *)ua, (char *)call);
|
|
||||||
return;
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ class Account(val accp: Long) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
|
if (authPass == "")
|
||||||
|
authPass = NO_AUTH_PASS
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
val ob = Api.account_outbound(accp, i)
|
val ob = Api.account_outbound(accp, i)
|
||||||
|
|||||||
@@ -536,12 +536,24 @@ class BaresipService: Service() {
|
|||||||
val ev = event.split(",")
|
val ev = event.split(",")
|
||||||
|
|
||||||
if (ev[0] == "create") {
|
if (ev[0] == "create") {
|
||||||
|
|
||||||
val ua = UserAgent(uap)
|
val ua = UserAgent(uap)
|
||||||
ua.status = if (ua.account.regint == 0)
|
ua.status = if (ua.account.regint == 0)
|
||||||
R.drawable.dot_white
|
R.drawable.dot_white
|
||||||
else
|
else
|
||||||
R.drawable.dot_yellow
|
R.drawable.dot_yellow
|
||||||
uas.add(ua)
|
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
|
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
|
@Keep
|
||||||
fun started() {
|
fun started() {
|
||||||
Log.d(TAG, "Received 'started' from baresip")
|
Log.d(TAG, "Received 'started' from baresip")
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ const val SAVE_REQ_CODE = 10
|
|||||||
const val DELETE_REQ_CODE = 11
|
const val DELETE_REQ_CODE = 11
|
||||||
|
|
||||||
const val REGISTRATION_INTERVAL = 900
|
const val REGISTRATION_INTERVAL = 900
|
||||||
|
const val NO_AUTH_PASS = "t%Qa?~?J8,~6"
|
||||||
|
|||||||
Reference in New Issue
Block a user