VoIPGRID / VialerSIPLib

An Objective-c wrapper for PJSIP
GNU General Public License v3.0
133 stars 69 forks source link

pjsua_acc_set_registration always returns PJ_SUCCESS #162

Closed ismaiI1 closed 5 years ago

ismaiI1 commented 5 years ago

Version

3.3.4 ( same in 3.4.0 )

File / Feature

VSLAccount.m

Expected behavior

if username or password invalid, it must return false (i think)

Actual behavior

it returns success when username or password was wrong..

Other info

if registration address isn't valid it's returning error code.

redmerloen commented 5 years ago

Good point! I will see if this is possible to add

ismaiI1 commented 5 years ago

I think, if account registration failed, it should be removed from VSLEndPoint.accounts. Is't it ? So we can change account name, password or domain and re-send register. Am i wrong?

redmerloen commented 5 years ago

@invisible66 I've created a PR that would fix this issue in the next release. When there is a "403" error code during the registration it will return a failed through the completion block.

ismaiI1 commented 5 years ago

I tried PR codes but it didn't call registrationCompletionBlock in VSLAccount.m. I add else statement to if (self.shouldReregister) { and called registrationCompletionBlock. is it wrong?

 if (code == 0 || (code != PJSIP_SC_FORBIDDEN && accountInfo.expires == -1)) {
    self.accountState = VSLAccountStateDisconnected;
    if (self.shouldReregister) {
        [self registerAccountWithCompletion:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                VSLLogInfo(@"Account was re-registerd after a sucessfull unregister.");
                self.shouldReregister = NO;
                [self reinviteActiveCalls];
            } else {
                VSLLogWarning(@"Unable to re-register account");
                self.shouldReregister = NO;
            }
        }];
    } else {
        if (self.registrationCompletionBlock) {
            VSLLogVerbose(@"Account not registered");
            self.registrationCompletionBlock(NO, nil);
            self.registrationCompletionBlock = nil;
        }
    }
    self.registrationInProgress = NO;
}
redmerloen commented 5 years ago

Can you check your sip messages? Or print the output of code?

ismaiI1 commented 5 years ago

code returns PJSIP_SC_UNAUTHORIZED.

ekran resmi 2018-11-07 16 02 54

I changed my code as below, and it worked perfectly 👍 Thanks..

  .
  .
  if (code == 0 || (code != PJSIP_SC_FORBIDDEN && code != PJSIP_SC_UNAUTHORIZED && accountInfo.expires == -1)) {

  .
  .
  } else {
    self.accountState = VSLAccountStateDisconnected;
    if (code == PJSIP_SC_FORBIDDEN || code == PJSIP_SC_UNAUTHORIZED) {
redmerloen commented 5 years ago

Thanks, i will expand the check for me w wrong password returned a forbidden

redmerloen commented 5 years ago

Cool, i will create a new version of the Library soon. So this can be added in the next release

redmerloen commented 5 years ago

The release is made to 3.4.1 so if you update the library it should be there!

ismaiI1 commented 5 years ago

Perfect. Thanks :)

ismaiI1 commented 5 years ago

Hey, There is a new error i guess :(

If register failed it's working but if i re-send same password, i got Assertion Failed in pjsua_acc_get_info

 - (NSInteger)registrationStatus {
     if (self.accountId == PJSUA_INVALID_ID) {
         return 0;
     }
     pjsua_acc_info accountInfo;
     pj_status_t status;

     status = pjsua_acc_get_info((pjsua_acc_id)self.accountId, &accountInfo);
     if (status != PJ_SUCCESS) {
         return 0;
     }
     return accountInfo.status;
 }
ismaiI1 commented 5 years ago

@redmerloen did you see my above answer?

redmerloen commented 5 years ago

Yes i have seen it, i will see what is happening soon

redmerloen commented 5 years ago

@invisible66 Are you using the methods in the VialerSIPLib.h to register an account?

ismaiI1 commented 5 years ago

@invisible66 Are you using the methods in the VialerSIPLib.h to register an account?

i guess.. I tried your example project..

redmerloen commented 5 years ago

This is if (self.accountId == PJSUA_INVALID_ID) { should catch that assertion error.

ismaiI1 commented 5 years ago

PJSUA_INVALID_ID is -1 but self.accountId = 0. So i think it can not catch

ezgif-1-4791b67b2875

redmerloen commented 5 years ago

Can you test this branch feature/invalid-accounts see if that is fixing anything?

ismaiI1 commented 5 years ago

Hey dude congratulations :) It's perfectly working..