On 06/13/2013 09:34 AM, ThanhTruong wrote:
>   
> For handling register authentication in callback I used:
>   
> if(evt == nua_r_register && (status == 401 || status == 407))
>                {
>                       if (sip && sip->sip_www_authenticate && 
> sip->sip_www_authenticate->au_params)
>                       {
>                             const char realm[] = "realm=\"";
>                             for (const char *param = (const 
> char*)sip->sip_www_authenticate->au_params[0]; param != NULL; ++param)
>                             {
>                                    size_t param_strlen = strlen(param);
>                                    if (param_strlen > sizeof(realm) && 
> strncmp(realm, param, sizeof(realm) - 1) == 0)
>                                    {
>                                           std::string realm_val(param + 
> sizeof(realm) - 1, param_strlen - sizeof(realm));
>                                            std::stringstream digest;
>                                           digest << "Digest:\"" << realm_val 
> << "\"" << ":" << m_userName << ":" << m_passWord;
>                                           
> nua_authenticate(m_registrationHandle, NUTAG_AUTH(digest.str().c_str()), 
> TAG_END());
>                                    }
>                             }
>                       }
>                }
>   
>

Hey there!

Nothing to do with the problem but I just wanted to say that you can 
simplify/strengthen
the code for building the auth string by doing it like this code:

"sip" is of type <sip_t const* sip>, which is delivered by NUA to the 
callback:

sip_www_authenticate_t const* www_auth = sip->sip_www_authenticate;
char const* scheme = www_auth->au_scheme;
const char* realm = msg_params_find( www_auth->au_params, "realm=" );
char auth_str[ 8192 ] = { 0 };
snprintf( auth_str, 8192, "%s:%s:%s:%s",
               scheme, realm,
               "USERNAME",
               "PASSWORD" );
nua_authenticate( nh, NUTAG_AUTH( auth_str ), TAG_END() );


Hope it helps :-)


Regards,

Andreas


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to