1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
* include/proto/obj_type.h
* This file contains function prototypes to manipulate object types
*
* Copyright (C) 2000-2013 Willy Tarreau - w@1wt.eu
*
* 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, version 2.1
* exclusively.
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _PROTO_OBJ_TYPE_H
#define _PROTO_OBJ_TYPE_H
#include <common/config.h>
#include <common/memory.h>
#include <types/connection.h>
#include <types/listener.h>
#include <types/obj_type.h>
#include <types/proxy.h>
#include <types/server.h>
#include <types/stream_interface.h>
static inline enum obj_type obj_type(enum obj_type *t)
{
if (!t || *t >= OBJ_TYPE_ENTRIES)
return OBJ_TYPE_NONE;
return *t;
}
static inline const char *obj_type_name(enum obj_type *t)
{
switch (obj_type(t)) {
case OBJ_TYPE_LISTENER: return "LISTENER";
case OBJ_TYPE_PROXY: return "PROXY";
case OBJ_TYPE_SERVER: return "SERVER";
case OBJ_TYPE_APPLET: return "APPLET";
case OBJ_TYPE_APPCTX: return "APPCTX";
case OBJ_TYPE_CONN: return "CONN";
default: return "NONE";
}
}
/* Note: for convenience, we provide two versions of each function :
* - __objt_<type> : converts the pointer without any control of its
* value nor type.
* - objt_<type> : same as above except that if the pointer is NULL
* or points to a non-matching type, NULL is returned instead.
*/
static inline struct listener *__objt_listener(enum obj_type *t)
{
return container_of(t, struct listener, obj_type);
}
static inline struct listener *objt_listener(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_LISTENER)
return NULL;
return __objt_listener(t);
}
static inline struct proxy *__objt_proxy(enum obj_type *t)
{
return container_of(t, struct proxy, obj_type);
}
static inline struct proxy *objt_proxy(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_PROXY)
return NULL;
return __objt_proxy(t);
}
static inline struct server *__objt_server(enum obj_type *t)
{
return container_of(t, struct server, obj_type);
}
static inline struct server *objt_server(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_SERVER)
return NULL;
return __objt_server(t);
}
static inline struct si_applet *__objt_applet(enum obj_type *t)
{
return container_of(t, struct si_applet, obj_type);
}
static inline struct si_applet *objt_applet(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_APPLET)
return NULL;
return __objt_applet(t);
}
static inline struct appctx *__objt_appctx(enum obj_type *t)
{
return container_of(t, struct appctx, obj_type);
}
static inline struct appctx *objt_appctx(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_APPCTX)
return NULL;
return __objt_appctx(t);
}
static inline struct connection *__objt_conn(enum obj_type *t)
{
return container_of(t, struct connection, obj_type);
}
static inline struct connection *objt_conn(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_CONN)
return NULL;
return __objt_conn(t);
}
static inline void *obj_base_ptr(enum obj_type *t)
{
switch (obj_type(t)) {
case OBJ_TYPE_LISTENER: return __objt_listener(t);
case OBJ_TYPE_PROXY: return __objt_proxy(t);
case OBJ_TYPE_SERVER: return __objt_server(t);
case OBJ_TYPE_APPLET: return __objt_applet(t);
case OBJ_TYPE_APPCTX: return __objt_appctx(t);
case OBJ_TYPE_CONN: return __objt_conn(t);
default: return NULL;
}
}
#endif /* _PROTO_OBJ_TYPE_H */
/*
* Local variables:
* c-indent-level: 8
* c-basic-offset: 8
* End:
*/
|