Hi,
I have made a shorter version of my mail.
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...
int main(int argc, char *argv[])
{
...
....
if(strcmp(o_method,"MESSAGE")==0)
{
send_message(context, o_to, o_method, o_username, o_password,
o_server_ip, o_server_port, o_contact_port);
exit(0);
}
}
int send_message(context_t *context, char const *o_to, char const *o_method,
char const *o_username, char const *o_password,
char const *o_server_ip, char const *o_server_port,
char const *o_contact_port)
{
char *extra = NULL;
char *o_bind = NULL;
char *o_http_proxy = NULL;
char *o_from = NULL;
char *s, *v;
char *to_domain;
char url_from[1024];
char *str_url_cont;
char *ipconfig_local;
char *str_route_url;
sip_addr_t *from, *to;
url_string_t *r_uri;
sip_method_t method = sip_method_message;
su_init();
su_home_init(context->c_home);
context->c_root = su_root_create(context);
context->c_retval = 2;
su_root_threading(context->c_root, 0);
if (context->c_root)
{
context->c_agent = nta_agent_create(context->c_root,
URL_STRING_MAKE(o_bind),
callback, context,
TPTAG_HTTP_CONNECT(o_http_proxy),
TAG_END());
if (context->c_agent)
{
to = sip_to_create(context->c_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 = sip_from_create(context->c_home, url_from );
int b = sprintf(str_url_cont , "sip:%...@%s:%s", o_username,
get_local_ip(), o_contact_port);
url_t *url_cont = url_make(context->c_home, str_url_cont);
sip_contact_t *contact_header = sip_contact_create(context->c_home,
url_cont, TAG_END());
int c = sprintf(str_route_url , "sip:%s:%s;lr", o_server_ip,
o_server_port);
url_t *route_url = url_make(context->c_home, str_route_url);
method = sip_method_code(o_method);
r_uri = (url_string_t *)url_hdup(context->c_home, to->a_url);
tag_from_header(context->c_agent, context->c_home, from);
sip_aor_strip(to->a_url);
sip_aor_strip(from->a_url);
context->c_username = from->a_url->url_user;
context->c_password = from->a_url->url_password;
from->a_url->url_password = NULL;
context->c_proxy = url_hdup(context->c_home, (url_t
*)getenv("sip_proxy"));
nta_agent_set_params(context->c_agent,
NTATAG_SIPFLAGS(MSG_FLG_EXTRACT_COPY),
NTATAG_DEFAULT_PROXY(context->c_proxy), TAG_END());
context->c_leg = nta_leg_tcreate(context->c_agent, NULL, context,
SIPTAG_FROM(from), SIPTAG_TO(to), TAG_END());
if (context->c_leg)
{
sip_event_t *sip_event = sip_event_make(context->c_home,
"sip_event");
sip_content_type_t *sip_content_type_header =
sip_content_type_make(context->c_home, "sip_content_type");
sip_payload_t *sip_payload_message =
sip_payload_make(context->c_home, "sip_message");
sip_separator_t *separator_line =
sip_separator_make(context->c_home,"sip_saperator");
sip_route_t *route_header = sip_route_create(context->c_home,
route_url, NULL);
context->c_orq = nta_outgoing_tcreate(context->c_leg,
callback, context,
to->a_url,
method, o_method, r_uri,
SIPTAG_USER_AGENT_STR("ABC XYZ"),
SIPTAG_HEADER_STR(extra),
SIPTAG_ROUTE(route_header),SIPTAG_ROUTE_STR(NULL),
SIPTAG_CONTACT(contact_header), SIPTAG_CONTACT_STR(NULL),
SIPTAG_EVENT(sip_event), SIPTAG_EVENT_STR("CPIM"),
SIPTAG_CONTENT_TYPE(sip_content_type_header),
SIPTAG_CONTENT_TYPE_STR("text/plain"),
SIPTAG_SEPARATOR(separator_line),SIPTAG_SEPARATOR_STR(NULL),
SIPTAG_PAYLOAD(sip_payload_message), SIPTAG_PAYLOAD_STR("Hello
World"),
TAG_END());
if (context->c_orq)
{
su_root_run(context->c_root);
nta_outgoing_destroy(context->c_orq), context->c_orq = NULL;
}
nta_leg_destroy(context->c_leg), context->c_leg = NULL;
}
nta_agent_destroy(context->c_agent), context->c_agent = NULL;
}
} su_root_destroy(context->c_root);
su_deinit();
return context->c_retval;
}
static int callback(context_t *context, nta_outgoing_t *oreq, sip_t const
*sip)
{
if (proxy_authenticate(context, oreq, sip, callback))
return 0;
if (server_authenticate(context, oreq, sip, callback))
return 0;
if (sip->sip_status->st_status >= 200 || context->c_pre)
{
sip_header_t *h = (sip_header_t *)sip->sip_status;
char hname[64];
printf("\n\n");
for (; h; h = (sip_header_t *)h->sh_succ)
{
if (!context->c_all)
{
if (sip_is_from(h) ||
sip_is_via(h) ||
sip_is_call_id(h) ||
sip_is_cseq(h) ||
sip_is_content_length(h))
continue;
}
if (h->sh_class->hc_name)
{
snprintf(hname, sizeof hname, "%s:%%s\n", h->sh_class->hc_name);
sl_header_print(stdout, hname, h);
}
else
{
sl_header_print(stdout, NULL, h);
}
}
}
printf("\n\n");
if (sip->sip_status->st_status >= 200)
{
context->c_retval = sip->sip_status->st_status >= 300;
su_root_break(context->c_root);
}
switch(sip->sip_status->st_status)
{
case 401 : authorize_ua(context, oreq, sip); break;
default : break;
}
if (sip->sip_status->st_status >= 200)
{
context->c_retval = sip->sip_status->st_status >= 300;
su_root_break(context->c_root);
}
}
void authorize_ua(context_t *context, nta_outgoing_t *oreq, sip_t const
*sip)
{
url_string_t *r_uri;
char *auth_str;
if (context->c_root)
{
sip_method_t method = sip_method_message;
char const *o_method = "MESSAGE";
r_uri = (url_string_t *)url_hdup(context->c_home, sip->sip_to->a_url);
sip_www_authenticate_t const *wa = sip->sip_www_authenticate;
msg_param_t const *au_params = wa->au_params;
const char *realm = msg_params_find(au_params, "realm=");
const char *nonce = msg_params_find(au_params, "nonce=");
const char *scheme= "MD5";
const char *o_username = "abc";
const char *o_password = "abc";
auth_str = su_sprintf(context->c_home, "%s:%s:%s:%s", scheme , realm,
o_username, o_password);
context->c_proxy = url_hdup(context->c_home, (url_t *)getenv("sip_proxy"));
nta_agent_set_params(context->c_agent,
NTATAG_SIPFLAGS(MSG_FLG_EXTRACT_COPY),
NTATAG_DEFAULT_PROXY(context->c_proxy),
TAG_END());
char url_from[1024];
int a = sprintf(url_from, "sip:a...@abplrt.com:5060");
sip_addr_t *from;
from = sip_from_create(context->c_home, url_from );
tag_from_header(context->c_agent, context->c_home, from);
nta_leg_destroy(context->c_leg), context->c_leg = NULL;
if (context->c_leg)
{ context->c_orq =
nta_outgoing_tcreate(context->c_leg,
callback, context,
sip->sip_to->a_url,
method, o_method , r_uri,
SIPTAG_USER_AGENT_STR("ABC XYZ"),
SIPTAG_HEADER_STR(NULL),
SIPTAG_ROUTE(sip->sip_route),SIPTAG_ROUTE_STR(NULL),
SIPTAG_CONTACT(sip->sip_contact),
SIPTAG_CONTACT_STR(NULL),
SIPTAG_EVENT(sip->sip_event),
SIPTAG_EVENT_STR("CPIM"),
SIPTAG_CONTENT_TYPE(sip->sip_content_type),
SIPTAG_CONTENT_TYPE_STR("text/plain"),
SIPTAG_SEPARATOR(sip->sip_separator),SIPTAG_SEPARATOR_STR(NULL),
SIPTAG_PAYLOAD(sip->sip_payload),
SIPTAG_PAYLOAD_STR("Authentic!"),
// SIPTAG_AUTHORIZATION(sip->sip_authorization)
, SIPTAG_AUTHORIZATION_STR(auth_str),
TAG_END());
if (context->c_orq)
{
su_root_run(context->c_root);
nta_outgoing_destroy(context->c_orq), context->c_orq = NULL;
nta_leg_destroy(context->c_leg), context->c_leg = NULL;
}
printf("%s\n","Out !");
}
}
}
Thank You,
Mayur
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel