Commit 7aa0ca38 authored by Pekka Pessi's avatar Pekka Pessi

Updated compression interface in tport.

Added tport_compressor_t type, tport_delivered_with_comp().
Removed tpac_sigcomp_accept() and tport_delivered_using_udvm().

darcs-hash:20060417233320-65a35-8a2571e39146a82f57e58d5e97c126392840c873.gz
parent 4b225fbc
......@@ -99,9 +99,6 @@ typedef struct {
char const [], unsigned,
tport_t const *, tp_client_t *);
/** Ask stack to accept/reject early SigComp message */
int (*tpac_sigcomp_accept)(tp_stack_t *, tport_t *, msg_t *);
/** Indicate stack that address has changed */
void (*tpac_address)(tp_stack_t *, tport_t *);
......@@ -336,9 +333,11 @@ int tport_keepalive(tport_t *tp, su_addrinfo_t const *ai,
/* ---------------------------------------------------------------------- */
/* SigComp-related functions */
TPORT_DLL
struct sigcomp_compartment *tport_init_comp(tport_t *self,
char const *algorithm_name);
#ifndef TPORT_COMPRESSOR
#define TPORT_COMPRESSOR struct tport_compressor
#endif
typedef TPORT_COMPRESSOR tport_compressor_t;
TPORT_DLL int tport_can_send_sigcomp(tport_t const *self);
TPORT_DLL int tport_can_recv_sigcomp(tport_t const *self);
......@@ -377,11 +376,10 @@ tport_sigcomp_accept(tport_t *self,
struct sigcomp_compartment *cc,
msg_t *msg);
/** Get UDVM with which the request was delivered */
/** Get compressor context with which the request was delivered */
TPORT_DLL int
tport_delivered_using_udvm(tport_t *tp, msg_t const *msg,
struct sigcomp_udvm **return_pointer_to_udvm,
int remove);
tport_delivered_with_comp(tport_t *tp, msg_t const *msg,
tport_compressor_t **return_compressor);
/** Shutdown SigComp compartment */
TPORT_DLL int
......
......@@ -58,12 +58,6 @@ SOFIAPUBFUN int tport_plug_in_stun_server(tport_stun_server_vtable_t const *);
/* -- SigComp Plugin ---------------------------------------------------- */
#ifndef TPORT_COMP_T
#define TPORT_COMP_T struct tport_compress
#endif
typedef TPORT_COMP_T tport_comp_t;
/* We already use these SigComp types in applications */
struct sigcomp_udvm;
......@@ -71,6 +65,99 @@ struct sigcomp_compartment;
typedef struct tport_comp_vtable_s tport_comp_vtable_t;
struct tport_comp_vtable_s {
/* NOTE: this will change! Unstable! Do not use! */
int vsc_size;
char const *vsc_compname;
size_t vsc_sizeof_context;
int (*vsc_init_comp)(tp_stack_t *,
tport_t *,
tport_compressor_t *,
char const *comp_name,
tagi_t const *tags);
void (*vsc_deinit_comp)(tp_stack_t *,
tport_t *,
tport_compressor_t *);
char const *(*vsc_comp_name)(tport_compressor_t const *master_sc,
char const *compression,
tagi_t const *tags);
/* Mapping of public tport API */
int (*vsc_can_send_comp)(tport_compressor_t const *);
int (*vsc_can_recv_comp)(tport_compressor_t const *);
int (*vsc_set_comp_name)(tport_t const *self,
tport_compressor_t const *return_sc,
char const *comp);
int (*vsc_sigcomp_option)(tport_t const *self,
struct sigcomp_compartment *cc,
char const *option);
struct sigcomp_compartment *
(*vsc_sigcomp_compartment)(tport_t *self,
char const *name, int namelen,
int create_if_needed);
struct sigcomp_compartment *
(*vsc_compartment_incref)(struct sigcomp_compartment *cc);
void (*vsc_compartment_decref)(struct sigcomp_compartment **pointer_to_cc);
int (*vsc_sigcomp_assign)(tport_t *self,
tport_compressor_t **,
struct sigcomp_compartment *);
int (*vsc_has_sigcomp_assigned)(tport_compressor_t const *comp);
int (*vsc_sigcomp_accept)(tport_t *self,
tport_compressor_t const *comp,
struct sigcomp_compartment *cc,
msg_t *msg);
int (*vsc_delivered_using_udvm)(tport_t *tp,
msg_t const *msg,
struct sigcomp_udvm **return_pointer_to_udvm,
int remove);
int (*vsc_sigcomp_close)(tport_t *self,
struct sigcomp_compartment *cc,
int how);
int (*vsc_sigcomp_lifetime)(tport_t *self,
struct sigcomp_compartment *,
unsigned lifetime_in_ms,
int only_expand);
/* Internal API */
struct sigcomp_udvm **(*vsc_get_udvm_slot)(tport_t *self);
struct sigcomp_compartment *
(*vsc_sigcomp_assign_if_needed)(tport_t *self,
struct sigcomp_compartment *cc);
void (*vsc_accept_incomplete)(tport_t const *self,
tport_compressor_t *sc,
msg_t *msg);
int (*vsc_recv_comp)(tport_t const *self, int N);
int (*vsc_send_comp)(tport_t const *self,
msg_t *msg,
msg_iovec_t iov[],
int iovused,
struct sigcomp_compartment *cc,
tport_compressor_t *sc);
};
SOFIAPUBFUN int tport_plug_in_comp(tport_comp_vtable_t const *);
#endif /* !defined(TPORT_PLUGINS_H) */
......@@ -86,10 +86,6 @@ static char const __func__[] = "tport";
(tp)->tp_master->mr_tpac->tpac_error((tp)->tp_master->mr_stack, (tp), \
(errcode), (dstname))
#define STACK_SIGCOMP_ACCEPT(tp, msg) \
(tp)->tp_master->mr_tpac-> \
tpac_sigcomp_accept((tp)->tp_master->mr_stack, (tp), (msg))
#define STACK_ADDRESS(tp) \
(tp)->tp_master->mr_tpac->tpac_address((tp)->tp_master->mr_stack, (tp))
......@@ -485,7 +481,6 @@ void tport_destroy(tport_t *self)
/* tpac_recv */ tport_destroy_recv,
/* tpac_error */ tport_destroy_error,
/* tpac_alloc */ tport_destroy_alloc,
/* tpac_comp_accept */ NULL
}};
SU_DEBUG_7(("%s(%p)\n", __func__, self));
......@@ -503,7 +498,6 @@ void tport_destroy(tport_t *self)
while (mr->mr_primaries)
tport_zap_primary(mr->mr_primaries);
tport_deinit_comp(mr);
tport_deinit_stun_server(mr);
if (mr->mr_dump_file)
......@@ -2649,7 +2643,7 @@ static void tport_parse(tport_t *self, int complete, su_time_t now)
else
next = NULL;
tport_deliver(self, msg, next, tport_get_udvm_slot(self), now);
tport_deliver(self, msg, next, self->tp_comp, now);
if (streaming && next == NULL)
break;
......@@ -2665,8 +2659,10 @@ static void tport_parse(tport_t *self, int complete, su_time_t now)
}
/** Deliver message to the protocol stack */
void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
struct sigcomp_udvm **in_out_udvm,
void tport_deliver(tport_t *self,
msg_t *msg,
msg_t *next,
tport_compressor_t *sc,
su_time_t now)
{
tport_t *ref;
......@@ -2679,7 +2675,6 @@ void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
d->d_tport = self;
d->d_msg = msg;
d->d_udvm = in_out_udvm;
*d->d_from = *self->tp_name;
if (tport_is_primary(self)) {
......@@ -2703,7 +2698,8 @@ void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
d->d_from->tpn_host = ipaddr;
}
if (!in_out_udvm || !*in_out_udvm)
d->d_comp = sc;
if (!sc)
d->d_from->tpn_comp = NULL;
error = msg_has_error(msg);
......@@ -2770,23 +2766,14 @@ int tport_delivered_from(tport_t *tp, msg_t const *msg, tp_name_t name[1])
/** Return UDVM used to decompress the message. */
int
tport_delivered_using_udvm(tport_t *tp, msg_t const *msg,
struct sigcomp_udvm **return_udvm,
int remove)
tport_delivered_with_comp(tport_t *tp, msg_t const *msg,
tport_compressor_t **return_compressor)
{
if (tp == NULL || msg == NULL || msg != tp->tp_master->mr_delivery->d_msg)
return -1;
if (return_udvm) {
if (tp->tp_master->mr_delivery->d_udvm) {
*return_udvm = *tp->tp_master->mr_delivery->d_udvm;
if (remove)
tp->tp_master->mr_delivery->d_udvm = NULL;
}
else {
*return_udvm = NULL;
}
}
if (return_compressor)
*return_compressor = tp->tp_master->mr_delivery->d_comp;
return 0;
}
......
......@@ -75,8 +75,6 @@
SOFIA_BEGIN_DECLS
#undef HAVE_SIGCOMP
typedef struct tport_master tport_master_t;
typedef struct tport_pending_s tport_pending_t;
typedef struct tport_threadpool tport_threadpool_t;
......@@ -199,7 +197,7 @@ struct tport_s {
/* ==== Extensions ===================================================== */
tport_comp_t *tp_comp;
tport_compressor_t *tp_comp;
/* ==== Statistics ===================================================== */
......@@ -273,16 +271,12 @@ struct tport_master {
unsigned mr_bindv6only:1; /**< We can bind separately to IPv6/4 */
unsigned :0;
#if HAVE_SIGCOMP
struct sigcomp_compartment *mr_compartment;
#endif
/* Delivery context */
struct tport_delivery {
tport_t *d_tport;
msg_t *d_msg;
tp_name_t d_from[1];
struct sigcomp_udvm **d_udvm;
tport_compressor_t *d_comp;
} mr_delivery[1];
tport_stun_server_t *mr_stun_server;
......@@ -403,7 +397,7 @@ int tport_send_msg(tport_t *self, msg_t *msg,
struct sigcomp_compartment *cc);
void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
struct sigcomp_udvm **pointer_to_udvm,
tport_compressor_t *comp,
su_time_t now);
void tport_base_deliver(tport_t *self, msg_t *msg, su_time_t now);
......@@ -472,8 +466,6 @@ typedef int const *(tport_set_f)(tport_master_t *mr,
/* STUN plugin */
extern tport_stun_server_vtable_t const *tport_stun_server_vtable;
int tport_init_stun_server(tport_master_t *mr, tagi_t const *tags);
void tport_deinit_stun_server(tport_master_t *mr);
int tport_recv_stun_dgram(tport_t const *self, int N);
......@@ -481,13 +473,16 @@ int tport_recv_stun_dgram(tport_t const *self, int N);
int tport_stun_server_add_socket(tport_t *tp);
int tport_stun_server_remove_socket(tport_t *tp);
/* SigComp plugin */
/* ---------------------------------------------------------------------- */
/* Compressor plugin */
extern tport_comp_vtable_t const *tport_comp_vtable;
char const *tport_canonize_comp(char const *comp);
void tport_deinit_comp(tport_master_t *mr);
int tport_init_compressor(tport_t *,
char const *comp_name,
tagi_t const *tags);
void tport_deinit_compressor(tport_t *);
struct sigcomp_compartment *
tport_sigcomp_assign_if_needed(tport_t *self,
......@@ -504,7 +499,7 @@ int tport_send_comp(tport_t const *self,
msg_iovec_t iov[],
int iovused,
struct sigcomp_compartment *cc,
tport_comp_t *sc);
tport_compressor_t *sc);
SOFIA_END_DECLS
......
......@@ -33,93 +33,6 @@
#include "tport_internal.h"
struct tport_comp_vtable_s {
/* NOTE: this will change! Unstable! Do not use! */
int vsc_size;
struct sigcomp_compartment *
(*vsc_init_comp)(tport_t *master_tport,
tport_comp_t **inout_sc,
char const *algorithm);
void (*vsc_deinit_comp)(tport_t *master_tport,
tport_comp_t **in_sc);
char const *(*vsc_comp_name)(tport_comp_t const *master_sc,
char const *compression,
tagi_t const *tags);
/* Mapping of public tport API */
int (*vsc_can_send_comp)(tport_comp_t const *);
int (*vsc_can_recv_comp)(tport_comp_t const *);
int (*vsc_set_comp_name)(tport_t const *self,
tport_comp_t const *return_sc,
char const *comp);
int (*vsc_sigcomp_option)(tport_t const *self,
struct sigcomp_compartment *cc,
char const *option);
struct sigcomp_compartment *
(*vsc_sigcomp_compartment)(tport_t *self,
char const *name, int namelen,
int create_if_needed);
struct sigcomp_compartment *
(*vsc_compartment_incref)(struct sigcomp_compartment *cc);
void (*vsc_compartment_decref)(struct sigcomp_compartment **pointer_to_cc);
int (*vsc_sigcomp_assign)(tport_t *self,
tport_comp_t **,
struct sigcomp_compartment *);
int (*vsc_has_sigcomp_assigned)(tport_comp_t const *comp);
int (*vsc_sigcomp_accept)(tport_t *self,
tport_comp_t const *comp,
struct sigcomp_compartment *cc,
msg_t *msg);
int (*vsc_delivered_using_udvm)(tport_t *tp,
msg_t const *msg,
struct sigcomp_udvm **return_pointer_to_udvm,
int remove);
int (*vsc_sigcomp_close)(tport_t *self,
struct sigcomp_compartment *cc,
int how);
int (*vsc_sigcomp_lifetime)(tport_t *self,
struct sigcomp_compartment *,
unsigned lifetime_in_ms,
int only_expand);
/* Internal API */
struct sigcomp_udvm **(*vsc_get_udvm_slot)(tport_t *self);
struct sigcomp_compartment *
(*vsc_sigcomp_assign_if_needed)(tport_t *self,
struct sigcomp_compartment *cc);
void (*vsc_try_accept_sigcomp)(tport_t const *self,
tport_comp_t *sc,
msg_t *msg);
int (*vsc_recv_comp)(tport_t const *self, int N);
int (*vsc_send_comp)(tport_t const *self,
msg_t *msg,
msg_iovec_t iov[],
int iovused,
struct sigcomp_compartment *cc,
tport_comp_t *sc);
};
tport_comp_vtable_t const *tport_comp_vtable = NULL;
int tport_plug_in_compress(tport_comp_vtable_t const *vsc)
......@@ -132,37 +45,59 @@ char const tport_sigcomp_name[] = "sigcomp";
/** Canonize compression string */
char const *tport_canonize_comp(char const *comp)
{
if (comp && strcasecmp(comp, tport_sigcomp_name) == 0)
if (tport_comp_vtable && comp && strcasecmp(comp, tport_sigcomp_name) == 0)
return tport_sigcomp_name;
return NULL;
}
/** Initialize Sigcomp and the master compartment */
struct sigcomp_compartment *
tport_init_comp(tport_t *mr, char const *algorithm_name)
int tport_init_compressor(tport_t *tp,
char const *comp_name,
tagi_t const *tags)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
tport_master_t *mr = tp ? tp->tp_master : NULL;
tport_compressor_t *tcc;
if (vsc && tport_is_master(mr))
return vsc->vsc_init_comp(mr, &mr->tp_comp, algorithm_name);
if (vsc == NULL)
return -1;
if (mr == NULL)
return -1;
return NULL;
if (tp->tp_comp)
return 0;
tcc = su_zalloc(tp->tp_home, vsc->vsc_sizeof_context);
if (tcc == NULL)
return -1;
if (vsc->vsc_init_comp(mr->mr_stack, tp, tcc, comp_name, tags) < 0) {
vsc->vsc_deinit_comp(mr->mr_stack, tp, tcc);
return -1;
}
tp->tp_comp = tcc;
return 0;
}
void tport_deinit_comp(tport_master_t *mr)
void tport_deinit_compressor(tport_t *tp)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
tport_master_t *mr = tp ? tp->tp_master : NULL;
if (vsc)
vsc->vsc_deinit_comp(mr->mr_master, &mr->mr_master->tp_comp);
if (vsc && mr && tp->tp_comp) {
vsc->vsc_deinit_comp(mr->mr_stack, tp, tp->tp_comp);
su_free(tp->tp_home, tp->tp_comp), tp->tp_comp = NULL;
}
}
char const *tport_comp_name(tport_primary_t *pri,
char const *name,
tagi_t const *tags)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
tport_comp_t const *comp = pri->pri_master->mr_master->tp_comp;
tport_compressor_t const *comp = pri->pri_master->mr_master->tp_comp;
if (vsc)
return vsc->vsc_comp_name(comp, name, tags);
......@@ -170,6 +105,7 @@ char const *tport_comp_name(tport_primary_t *pri,
return NULL;
}
/** Check if transport can receive compressed messages */
int tport_can_recv_sigcomp(tport_t const *self)
{
......@@ -238,6 +174,19 @@ int tport_sigcomp_assign(tport_t *self, struct sigcomp_compartment *cc)
return 0;
}
struct sigcomp_compartment *
tport_sigcomp_assign_if_needed(tport_t *self,
struct sigcomp_compartment *cc)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
if (vsc)
return vsc->vsc_sigcomp_assign_if_needed(self, cc);
return NULL;
}
/** Test if tport has a SigComp compartment assigned to it. */
int tport_has_sigcomp_assigned(tport_t const *self)
{
......@@ -267,12 +216,14 @@ tport_sigcomp_accept(tport_t *self,
/* Internal API */
void tport_try_accept_sigcomp(tport_t *self, msg_t *msg)
/** This function is called when the application message is still incomplete
but a complete SigComp message could have been received */
void tport_accept_incomplete(tport_t *self, msg_t *msg)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
if (vsc)
vsc->vsc_try_accept_sigcomp(self, self->tp_comp, msg);
if (vsc && self->tp_comp)
vsc->vsc_accept_incomplete(self, self->tp_comp, msg);
}
struct sigcomp_udvm **tport_get_udvm_slot(tport_t *self)
......@@ -285,18 +236,6 @@ struct sigcomp_udvm **tport_get_udvm_slot(tport_t *self)
return NULL;
}
struct sigcomp_compartment *
tport_sigcomp_assign_if_needed(tport_t *self,
struct sigcomp_compartment *cc)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
if (vsc)
return vsc->vsc_sigcomp_assign_if_needed(self, cc);
return NULL;
}
/** Receive data from datagram using SigComp. */
int tport_recv_comp_dgram(tport_t *self, int N)
{
......@@ -319,7 +258,7 @@ int tport_send_comp(tport_t const *self,
msg_iovec_t iov[],
int iovused,
struct sigcomp_compartment *cc,
tport_comp_t *comp)
tport_compressor_t *comp)
{
tport_comp_vtable_t const *vsc = tport_comp_vtable;
......
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