Hey Paulo,
                    Thanks for clearing the basic concepts. In your second
point you say "different callback for different method". Can't I use a
single callback and using switch case do the function calling. Could you
please explain.

I am using NUA now. But when I send a SUBSCRIBE message to the server I get
two 401 Unauthorize, I couldn't make out why I am having this problem. I
would be thankful to you, if you have a look on my code and make out what's
the problem.

Thanks for clearing my doubts,
Mayur





Hello,

    I took a look at your code and I noticed that (1) you call su_root_run()
several times and breaks it. su_root_run() is supposed to be called only
once and the loop should be broken (by calling su_root_break()) only when
you want to exit your app.

    (2) You can call a request method inside the callback. Once you're
inside the callback, you must not worry about the event loop, because it is
already running (this is why your second call to su_root_run() won't work).
You should provide a different callback for a specific method or provide
some information through the magic pointer so that your app keeps track of
calls' states.

    (3) Have you considered using NUA instead of NTA? There are a lot of
things that NUA will handle automatically that NTA won't. If you really need
NTA, authentication is nothing but, to respond to the challenge with the
correct hash. You may need to search for any library to calculate the MD5
authorization digests or build your own. <
http://en.wikipedia.org/wiki/Digest_access_authentication>

    Regards,

    Paulo.









On Fri, Jul 23, 2010 at 10:21 PM, Mayur Mahajan
<mayurmahajan...@gmail.com>wrote:

> Hi,
>
>       When I send a request to the server through my NTA client, I get the
> response of the message(407 Unauthorized) in the callback. So, when the
> callback function gets the 407 message it invokes authorize_ua() method. The
> problem is I am not able to send the request which authorizes me.  Could you
> please help me in the following things :-
>
> 1)  Please see why I am not able to send an authorizing request message
> "again"(authorize_ua() ). I am not at all getting any response.
>      In the authorize_ua func the su_root_run(context->c_root) statement
> doesn't run.
>
> 2)  Can I call a request method from inside of callback function (using
> switch case)?
> 3) Lastly, .What is the alternative of nua_authenticate() in NTA ? I
> couldn't find any function like nta_authenticate etc...
>
>
> Please find the attachment.
>
> Thank You,
> Mayur
>
void Send_Subscribe(application *appl, char const *o_to, char const 
*o_username, char const *o_password,
                      char const *o_server_ip, char const *o_server_port, char 
const *o_contact_port)
{


      /* initialize system utilities */
      su_init();

      /* initialize memory handling */
      su_home_init(appl->home);

      /* initialize root object */
      appl->root = su_root_create(appl);

      //su_root_threading(appl->root, 0);

      to_header = sip_to_create(appl->home, (url_string_t *)o_to);

      to_domain = strchr( o_to , '@');
      int a = sprintf(url_from, "sip:%s%s:%s", o_username,  to_domain, 
o_contact_port);
      from_url = url_make (appl->home, url_from);
      from_header = sip_from_create(appl->home, from_url );

      int b = sprintf(str_url_cont , "sip:%...@%s:%s", o_username, 
get_local_ip(), o_contact_port);
      contact_url = url_make(appl->home, str_url_cont);
      contact_header = sip_contact_create(appl->home, contact_url, TAG_END());

      int c = sprintf(str_route_url , "sip:%s:%s;lr", o_server_ip,  
o_server_port);
      route_url = url_make(appl->home, str_route_url);
      route_header = sip_route_create(appl->home, route_url, NULL);


      sip_event_t *sip_event = sip_event_make(appl->home, "sip_event");
//      sip_content_type_t  *sip_content_type_header = 
sip_content_type_make(appl->home, "sip_content_type");
      sip_payload_t *sip_payload_message = sip_payload_make(appl->home, 
"sip_message");
      sip_expires_t *sip_expire = sip_expires_make(appl->home, "3600");
      sip_accept_t *sip_accept = sip_accept_make (appl->home, 
"application/pidf+xml");
      sip_call_id_t *sip_call_id = sip_call_id_make (appl->home, "1200");
      sip_cseq_t *sip_cseq = sip_cseq_make (appl->home, "SUBSCRIBE");
      sip_content_length_t *sip_content_length = sip_content_length_make 
(appl->home, "1000");

     if (appl->root != NULL)
       {
      /* create NUA stack */
        appl->nua = nua_create(appl->root,app_callback,appl,

     SIPTAG_FROM_STR(url_from),
//                  NUTAG_URL("sip:117.97.73.41:5060"),
                   TAG_END());


                if (appl->nua != NULL)
                       {
                         op->handle = nua_handle(appl->nua,
                         appl, SIPTAG_FROM(from_header),SIPTAG_TO(to_header),
                               SIPTAG_USER_AGENT_STR("ABC XYZ"),
                               SIPTAG_HEADER_STR(NULL),
                               
//SIPTAG_CALL_ID(sip_call_id),SIPTAG_CALL_ID_STR("12000"),
                               SIPTAG_ACCEPT(sip_accept) 
,SIPTAG_ACCEPT_STR(NULL),
                               //SIPTAG_CSEQ(sip_cseq), 
SIPTAG_CSEQ_STR("SUBSCRIBE"),
                              SIPTAG_EVENT(sip_event), 
SIPTAG_EVENT_STR("presence.account;x-intl-include=im-telephony-account-hotdesk"),
                              SIPTAG_ROUTE(route_header),SIPTAG_ROUTE_STR(NULL),
      //                       SIPTAG_CONTENT_LENGTH(sip_content_length), 
SIPTAG_CONTENT_LENGTH_STR("1000"),
                               SIPTAG_CONTACT(contact_header), 
SIPTAG_CONTACT_STR(NULL),
                               SIPTAG_EXPIRES(sip_expire) 
,SIPTAG_EXPIRES_STR("1800"),
                               //SIPTAG_PAYLOAD(sip_payload_message), 
SIPTAG_PAYLOAD_STR("Hello r"),
                               TAG_END());


                         if(op->handle)
                           {
                              nua_subscribe(op->handle, 
NUTAG_M_DISPLAY("SUBSCRIBE"),TAG_END());

                              /* enter main loop for processing of messages */
                              su_root_run(appl->root);

                              /* destroy NUA stack */
                              nua_destroy(appl->nua);
                           }
                        }

       su_root_destroy(appl->root);
       appl->root = NULL;
       }

       /* deinitialize memory handling */
       su_home_deinit(appl->home);

       /* deinitialize system utilities */
       su_deinit();

       return 0;
 }


By switch case in my callback function I reach to app_r_subscribe function.


void app_r_subscribe(int           status,   char const   *phrase,           
nua_magic_t  *magic,
                  nua_handle_t *nh,          nua_hmagic_t *hmagic,              
  sip_t const  *sip,
                  tagi_t        tags[])
{
 if(status==401)
  {
     operation *op;

     sip_www_authenticate_t const *wa = sip->sip_www_authenticate;
     sip_proxy_authenticate_t const *pa = sip->sip_proxy_authenticate;

     const char *method = NULL;
     const char *realm = NULL;
     const char *nonce = NULL;
     const char *user =  NULL;
     const char *password =  NULL;

     const char *auth[1024];

      if (wa)
       {
        realm = msg_params_find(wa->au_params, "realm=");
        nonce = msg_params_find(wa->au_params, "nonce=");
        method = wa->au_scheme;
       }


      user = "abc";
      password =  "abc";

      if (realm != NULL)
       {
         sprintf(auth,"%s:%s:%s:%s", method, realm, user ,password);
         printf("%s",auth);
         nua_authenticate(nh , NUTAG_AUTH(auth), TAG_END());
       }
       else
       {
        printf("%s", "No Realm Provided");
       }
   }
  else if(status==200)
   {
    exit(0);
   }

}
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to