Commit 70a4dd01 authored by Pekka Pessi's avatar Pekka Pessi

Refactored outbound code in nua module.

Added outbound.c, outbound.h.

darcs-hash:20060510184252-65a35-4718eb68e874fce9da70cc6746479a99acaccbd6.gz
parent 4252571f
......@@ -45,6 +45,7 @@ nobase_include_sofia_HEADERS = \
libnua_la_SOURCES = nua.c nua_stack.h nua_common.c nua_stack.c \
nua_dialog.c nua_dialog.h \
outbound.c outbound.h \
nua_params.c nua_params.h \
nua_register.c nua_session.c nua_options.c \
nua_message.c nua_publish.c nua_subnotref.c \
......
......@@ -107,11 +107,14 @@ int nua_stack_process_options(nua_t *nua,
{
msg_t *msg;
int status = 200; char const *phrase = sip_200_OK;
int status; char const *phrase;
/* Hook to outbound */
if (outbound_connect_check_accept(sip->sip_accept))
return outbound_connect_process_options(nua->nua_registrations, irq, sip);
status = nua_registration_process_request(nua->nua_registrations, irq, sip);
if (status)
return status;
SET_STATUS1(SIP_200_OK);
if (nh == NULL)
nh = nua->nua_dhandle;
......
......@@ -155,7 +155,9 @@ int nua_stack_set_from(nua_t *nua, int initial, tagi_t const *tags)
*f0 = *f, f = f0, f->a_params = NULL;
}
else {
sip_contact_t const *m = nua_contact_by_aor(nua, NULL, 0);
sip_contact_t const *m;
m = nua_stack_get_contact(nua->nua_registrations);
if (m) {
f0->a_display = m->m_display;
......@@ -802,7 +804,7 @@ int nua_stack_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
media_params = soa_get_paramlist(nh->nh_soa, TAG_END());
m = nua_contact_by_aor(nh->nh_nua, NULL, 0);
m = nua_stack_get_contact(nua->nua_registrations);
/* Include tag in list returned to user
* if it has been earlier set (by user) */
......
This diff is collapsed.
......@@ -912,7 +912,8 @@ int nh_challenge(nua_handle_t *nh, sip_t const *sip)
* @param name
* @param tag, value, ... list of tag-value pairs
*/
msg_t *nua_creq_msg(nua_t *nua, nua_handle_t *nh,
msg_t *nua_creq_msg(nua_t *nua,
nua_handle_t *nh,
struct nua_client_request *cr,
int restart,
sip_method_t method, char const *name,
......@@ -1045,9 +1046,11 @@ msg_t *nua_creq_msg(nua_t *nua, nua_handle_t *nh,
tl_find(ta_args(ta), siptag_contact_str))
add_contact = 0;
if (add_contact || add_service_route)
nua_add_contact_by_aor(nh, sip->sip_request->rq_url, msg, sip,
add_contact, add_service_route);
if (add_contact || add_service_route) {
if (nua_registration_add_contact(nh, msg, sip,
add_contact, add_service_route) < 0)
goto error;
}
if (!sip->sip_user_agent && NH_PGET(nh, user_agent))
sip_add_dup(msg, sip, (sip_header_t *)NH_PGET(nh, user_agent));
......@@ -1131,17 +1134,10 @@ msg_t *nh_make_response(nua_t *nua, nua_handle_t *nh,
ta_list ta;
msg_t *msg = nta_msg_create(nua->nua_nta, 0);
sip_t *sip = sip_object(msg);
sip_contact_t const *m;
int add_contact = 0;
m = nua_contact_by_aor(nua, nta_incoming_url(irq), 0);
tagi_t const *t;
ta_start(ta, tag, value);
tl_gets(ta_args(ta),
NUTAG_ADD_CONTACT_REF(add_contact),
TAG_END());
if (!msg)
return NULL;
else if (nta_msg_response_complete(msg, irq, status, phrase) < 0)
......@@ -1150,9 +1146,6 @@ msg_t *nh_make_response(nua_t *nua, nua_handle_t *nh,
msg_destroy(msg);
else if (sip_complete_message(msg) < 0)
msg_destroy(msg);
else if (add_contact && !sip->sip_contact &&
sip_add_dup(msg, sip, (sip_header_t *)m) < 0)
msg_destroy(msg);
else if (!sip->sip_supported && NH_PGET(nh, supported) &&
sip_add_dup(msg, sip, (sip_header_t *)NH_PGET(nh, supported)) < 0)
msg_destroy(msg);
......@@ -1165,6 +1158,10 @@ msg_t *nh_make_response(nua_t *nua, nua_handle_t *nh,
else if (!sip->sip_allow && NH_PGET(nh, allow) &&
sip_add_dup(msg, sip, (sip_header_t*)NH_PGET(nh, allow)) < 0)
msg_destroy(msg);
else if (!sip->sip_contact &&
(t = tl_find(ta_args(ta), _nutag_add_contact)) &&
nua_registration_add_contact(nh, msg, sip, t->t_value, 0) < 0)
msg_destroy(msg);
else
return msg;
......
......@@ -97,7 +97,7 @@ typedef struct nua_server_request nua_server_request_t;
typedef void nua_creq_restart_f(nua_handle_t *, tagi_t *tags);
typedef struct outbound_connect nua_registration_t;
typedef struct register_usage nua_registration_t;
struct nua_client_request
{
......@@ -366,9 +366,14 @@ int nua_stack_init_transport(nua_t *nua, tagi_t const *tags);
int nua_stack_init_registrations(nua_t *nua);
int outbound_connect_check_accept(sip_accept_t const *accept);
nua_registration_t *nua_registration_by_aor(nua_registration_t const *list,
sip_from_t const *aor,
url_t const *remote_uri,
int only_default);
int outbound_connect_process_options(struct outbound_connect *usages,
sip_contact_t const *nua_registration_contact(nua_registration_t const *nr);
int nua_registration_process_request(nua_registration_t *nr,
nta_incoming_t *irq,
sip_t const *sip);
......@@ -469,16 +474,13 @@ int nua_creq_restart(nua_handle_t *nh,
void nua_creq_deinit(struct nua_client_request *cr, nta_outgoing_t *orq);
sip_contact_t const *nua_contact_by_aor(nua_t *nua,
url_t const *aor,
int only_default);
sip_contact_t const *nua_stack_get_contact(nua_registration_t const *nr);
int nua_add_contact_by_aor(nua_handle_t *nh,
url_t const *aor,
msg_t *msg,
sip_t *sip,
int add_contact,
int add_service_route);
int nua_registration_add_contact(nua_handle_t *nh,
msg_t *msg,
sip_t *sip,
int add_contact,
int add_service_route);
msg_t *nh_make_response(nua_t *nua, nua_handle_t *nh,
nta_incoming_t *irq,
......
......@@ -441,9 +441,10 @@ int nua_stack_process_subsribe(nua_t *nua,
nua_dialog_usage_t *du = NULL;
struct event_usage *eu;
sip_event_t *o = sip->sip_event;
sip_contact_t const *m;
sip_contact_t const *m = NULL;
int status; char const *phrase;
unsigned long expires, refer_expires;
nua_registration_t *nr;
enter;
......@@ -499,10 +500,16 @@ int nua_stack_process_subsribe(nua_t *nua,
else
SET_STATUS1(SIP_200_OK);
m = nua_contact_by_aor(nua, nta_incoming_url(irq), 0);
if (status < 300 && m == NULL) {
SET_STATUS1(SIP_500_INTERNAL_SERVER_ERROR);
eu->eu_substate = nua_substate_terminated;
if (status < 300) {
nr = nua_registration_by_aor(nua->nua_registrations,
sip->sip_to,
sip->sip_request->rq_url,
0);
m = nua_registration_contact(nr);
if (m == NULL) {
SET_STATUS1(SIP_500_INTERNAL_SERVER_ERROR);
eu->eu_substate = nua_substate_terminated;
}
}
nta_incoming_treply(irq, status, phrase, SIPTAG_CONTACT(m), NULL);
......
This diff is collapsed.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2006 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef OUTBOUND_H /** Defined when <outbound.h> has been included. */
#define OUTBOUND_H
/**@IFILE outbound.h
*
* @brief Interface to SIP NAT traversal and outbound
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Wed May 10 12:01:38 EEST 2006 ppessi
*/
#ifndef SU_CONFIG_H
#include <su_config.h>
#endif
#ifndef NTA_H
#include <sofia-sip/nta.h>
#endif
#ifndef AUTH_CLIENT_H
#include <sofia-sip/auth_client.h>
#endif
#define SU_LOG (nua_log)
#include <sofia-sip/su_debug.h>
SOFIA_BEGIN_DECLS
/* ====================================================================== */
/* Outbound connection */
#ifndef OUTBOUND_OWNER_T
#define OUTBOUND_OWNER_T struct nua_handle_s /* Just for now */
#endif
typedef struct outbound outbound_t;
typedef struct outbound_owner_vtable outbound_owner_vtable;
typedef OUTBOUND_OWNER_T outbound_owner_t;
outbound_t *outbound_new(outbound_owner_t *owner,
outbound_owner_vtable const *owner_methods,
su_root_t *root,
nta_agent_t *agent,
char const *instance);
void outbound_unref(outbound_t *ob);
int outbound_set_options(outbound_t *ob,
char const *options,
unsigned dgram_interval,
unsigned stream_interval);
int outbound_set_features(outbound_t *ob, char *features);
nta_outgoing_t *outbound_register_request(outbound_t *ob, int terminating,
sip_contact_t *stack_contact,
nta_agent_t *nta,
nta_response_f *callback,
nta_outgoing_magic_t *magic,
url_string_t *next_hop,
msg_t *msg,
tag_type_t tag, tag_value_t value,
...);
int outbound_register_response(outbound_t *ob,
int terminating,
sip_t const *request,
sip_t const *response);
/** Return values for outbound_register_response(). */
enum {
ob_register_error = -1, /* Or anything below zero */
ob_register_ok = 0, /* No need to re-register */
ob_reregister = 1, /* Re-register when oo_refresh() is called */
ob_reregister_now = 2 /* Re-register immediately */
};
int outbound_set_contact(outbound_t *ob,
sip_contact_t const *application_contact,
sip_contact_t const *stack_contact,
int terminating);
sip_contact_t const *outbound_dialog_contact(outbound_t const *ob);
int outbound_gruuize(outbound_t *ob, sip_t const *sip);
void outbound_start_keepalive(outbound_t *ob,
nta_outgoing_t *register_trans);
void outbound_stop_keepalive(outbound_t *ob);
int outbound_targeted_request(sip_t const *sip);
int outbound_process_request(outbound_t *ob,
nta_incoming_t *irq,
sip_t const *sip);
void outbound_peer_info(outbound_t *ob, sip_t const *sip);
struct outbound_owner_vtable
{
int oo_size;
int (*oo_refresh)(outbound_owner_t *, outbound_t *ob);
int (*oo_status)(outbound_owner_t *, outbound_t *ob,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
int (*oo_probe_error)(outbound_owner_t *, outbound_t *ob,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
int (*oo_keepalive_error)(outbound_owner_t *, outbound_t *ob,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
int (*oo_credentials)(outbound_owner_t *, auth_client_t **auc);
};
SOFIA_END_DECLS
#endif /* OUTBOUND_H */
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