Commit 92824f5f authored by Pekka Pessi's avatar Pekka Pessi
Browse files

nua, soa: Adding Warnings to the response if appropriate.

darcs-hash:20060510195203-65a35-c486bd4ced9b289c336c37713b357531f5efa66c.gz
parent 70a4dd01
......@@ -480,7 +480,6 @@ int nua_stack_ack(nua_t *nua, nua_handle_t *nh, nua_event_t e,
if (soa_generate_answer(nh->nh_soa, NULL) < 0 ||
session_include_description(nh->nh_soa, msg, sip) < 0) {
reason = soa_error_as_sip_reason(nh->nh_soa);
/* XXX */
status = 900, phrase = "Internal media error";
reason = "SIP;cause=500;text=\"Internal media error\"";
}
......@@ -1004,12 +1003,13 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
sip_t *sip;
int reliable;
int original_status = status;
sip_warning_t *warning = NULL;
nua_dialog_state_t *ds = nh->nh_ds;
nua_session_state_t *ss = nh->nh_ss;
nua_server_request_t *sr = ss->ss_srequest;
int autoanswer = 0, offer = 0, answer = 0;
enter;
if (ss->ss_srequest->sr_irq == NULL ||
......@@ -1062,8 +1062,20 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
(sr->sr_offer_sent && !sr->sr_answer_recv))
/* Nothing to do */;
else if (sr->sr_offer_recv && !sr->sr_answer_sent) {
if (soa_generate_answer(nh->nh_soa, NULL) < 0)
if (soa_generate_answer(nh->nh_soa, NULL) < 0) {
int wcode;
char const *text;
char const *host = "invalid.";
status = soa_error_as_sip_response(nh->nh_soa, &phrase);
wcode = soa_get_warning(nh->nh_soa, &text);
if (wcode) {
if (sip->sip_contact)
host = sip->sip_contact->m_url->url_host;
warning = sip_warning_format(home, "%u %s \"%s\"",
wcode, host, text);
}
}
else {
answer = 1;
soa_activate(nh->nh_soa, NULL);
......@@ -1121,6 +1133,7 @@ void respond_to_invite(nua_t *nua, nua_handle_t *nh,
ss->ss_srequest->sr_respond = NULL;
nta_incoming_treply(ss->ss_srequest->sr_irq,
status, phrase,
SIPTAG_WARNING(warning),
TAG_END());
msg_destroy(msg), msg = NULL;
}
......
......@@ -653,27 +653,55 @@ int soa_error_as_sip_response(soa_session_t *ss,
SU_DEBUG_9(("soa_error_as_sip_response(%s::%p, ...) called\n",
ss ? ss->ss_actions->soa_name : "", ss));
if (ss == NULL) {
if (ss == NULL || ss->ss_status < 400 || ss->ss_status >= 700) {
if (return_phrase)
*return_phrase = sip_500_Internal_server_error;
return 500;
}
if (return_phrase)
*return_phrase = sip_501_Not_implemented;
return 501;
*return_phrase = ss->ss_phrase;
return ss->ss_status;
}
char const *soa_error_as_sip_reason(soa_session_t *ss)
{
char const *phrase;
int status;
char *reason;
SU_DEBUG_9(("soa_error_as_sip_reason(%s::%p) called\n",
ss ? ss->ss_actions->soa_name : "", ss));
return "SIP;cause=501;text=\"Unimplemented media\"";
if (ss == NULL)
return "SIP;cause=500;text=\"Internal Server Error\"";
status = soa_error_as_sip_response(ss, &phrase);
reason = su_sprintf(ss->ss_home, "SIP;cause=%u;text=\"%s\"", status, phrase);
if (ss->ss_reason)
su_free(ss->ss_home, reason);
return ss->ss_reason = reason;
}
/** Return warning code and text */
int soa_get_warning(soa_session_t *ss, char const **return_text)
{
if (!ss)
return 0;
if (!ss->ss_wcode)
return 0;
if (return_text)
*return_text = ss->ss_warning;
return ss->ss_wcode;
}
/** Return SDP description of capabilities.
*
* @retval 0 if there is no description to return
......@@ -1400,8 +1428,17 @@ int soa_is_remote_chat_active(soa_session_t const *ss)
int soa_set_status(soa_session_t *ss, int status, char const *phrase)
{
if (ss)
if (ss) {
ss->ss_status = status, ss->ss_phrase = phrase;
ss->ss_wcode = 0, ss->ss_warning = NULL;
}
return -1;
}
int soa_set_warning(soa_session_t *ss, int code, char const *text)
{
if (ss)
ss->ss_wcode = code, ss->ss_warning = text;
return -1;
}
......
......@@ -71,6 +71,8 @@ int soa_error_as_sip_response(soa_session_t *soa,
char const *soa_error_as_sip_reason(soa_session_t *soa);
int soa_get_warning(soa_session_t *ss, char const **return_phrase);
int soa_set_capability_sdp(soa_session_t *ss,
struct sdp_session_s const *sdp,
char const *str, int len);
......
......@@ -193,7 +193,8 @@ struct soa_session
int ss_status; /**< Status from last media operation */
char const *ss_phrase; /**< Phrase from last media operation */
char const *ss_warning; /**< Warnings from last media operation */
char *ss_reason; /**< Reason generated by media operation */
/* Media parameters */
char const *ss_address;
......@@ -210,6 +211,9 @@ struct soa_session
unsigned ss_srtp_enable:1,
ss_srtp_confidentiality:1,
ss_srtp_integrity:1;
int ss_wcode; /**< Warning code from last media operation */
char const *ss_warning; /**< Warnings text from last media operation */
};
/* ====================================================================== */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment