]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] stick_table: provide functions to return stksess data from a type
authorWilly Tarreau <w@1wt.eu>
Sun, 6 Jun 2010 14:06:52 +0000 (16:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 13:10:25 +0000 (15:10 +0200)
This function does the indirection job in the table to find the pointer
to the real data matching the requested type.

include/proto/stick_table.h
include/types/stick_table.h
src/stick_table.c

index 4200d97faa91f353d44270ddb49ac331bf3f25f2..e1a324d732835a697401bf27e43be7a73832aa43 100644 (file)
@@ -25,6 +25,9 @@
 
 #include <types/stick_table.h>
 
+#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 <type> in sticky session <ts> of table <t>, or
+ * NULL if either <ts> 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 */
index a43c1101367aff3f56f693adae827ec50a35a143..3e27b8f2716c738daf6e75ab6c7ca0edc71cba40 100644 (file)
@@ -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 */
index a86f48f41a587f63f614b024094888c447ee9a3d..994fbebef83d1db247195b7201a25ad56cdd7bc2 100644 (file)
 #include <ebmbtree.h>
 #include <ebsttree.h>
 
-#include <types/stick_table.h>
-
 #include <proto/pattern.h>
 #include <proto/proxy.h>
 #include <proto/session.h>
+#include <proto/stick_table.h>
 #include <proto/task.h>