From: Willy Tarreau Date: Sun, 6 Jun 2010 14:06:52 +0000 (+0200) Subject: [MINOR] stick_table: provide functions to return stksess data from a type X-Git-Tag: v1.5-dev8~562 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68129b90eb16e1281848b614f97ab6c8564a5662;p=thirdparty%2Fhaproxy.git [MINOR] stick_table: provide functions to return stksess data from a type This function does the indirection job in the table to find the pointer to the real data matching the requested type. --- diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h index 4200d97faa..e1a324d732 100644 --- a/include/proto/stick_table.h +++ b/include/proto/stick_table.h @@ -25,6 +25,9 @@ #include +#define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type)) +#define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->type + struct stksess *stksess_new(struct stktable *t, struct stktable_key *key); void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key); void stksess_free(struct stktable *t, struct stksess *ts); @@ -57,4 +60,21 @@ static inline int stktable_alloc_data_type(struct stktable *t, int type) return 1; } +/* return pointer for data type in sticky session of table , or + * NULL if either is NULL or the type is not stored. + */ +static inline void *stktable_data_ptr(struct stktable *t, struct stksess *ts, int type) +{ + if (type >= STKTABLE_DATA_TYPES) + return NULL; + + if (!t->data_ofs[type]) /* type not stored */ + return NULL; + + if (!ts) + return NULL; + + return (void *)ts + t->data_ofs[type]; +} + #endif /* _PROTO_STICK_TABLE_H */ diff --git a/include/types/stick_table.h b/include/types/stick_table.h index a43c110136..3e27b8f271 100644 --- a/include/types/stick_table.h +++ b/include/types/stick_table.h @@ -50,9 +50,6 @@ union stktable_data { unsigned int conn_cum; }; -#define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type)) -#define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->type - /* known data types */ struct stktable_data_type { const char *name; /* name of the data type */ diff --git a/src/stick_table.c b/src/stick_table.c index a86f48f41a..994fbebef8 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -22,11 +22,10 @@ #include #include -#include - #include #include #include +#include #include