1 /**********************************************************************
2 * l7vs_module.h May 2007
4 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
5 * Copyright (C) 2005 NTT COMWARE Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 **********************************************************************/
29 #include "l7vs_service.h"
30 #include "logger_wrapper.h"
34 struct l7vs_service_arg;
39 char modname[L7VS_MODNAME_LEN+1];
44 int ( *create )( void*, uint32_t );
45 int ( *compare )( uint32_t, uint32_t );
46 int ( *select_dest )( struct l7vs_service*, struct l7vs_conn*, char*, size_t*, struct l7vs_dest** );
47 int ( *analyze_cldata )( struct l7vs_service*, struct l7vs_conn*, char*, size_t* );
48 int ( *analyze_rsdata )( struct l7vs_service*, struct l7vs_conn*, char*, size_t* );
49 int ( *destroy )( uint32_t );
51 void* ( *create_sa )( struct l7vs_service_arg* );
52 int ( *service_arg )( struct l7vs_service_arg_multi*, uint32_t );
53 int ( *parse )( void*, int, char** );
54 void ( *destroy_sa )( void** );
55 int ( *initialize )( struct l7vs_service*, struct l7vs_conn*, char*, size_t, struct l7vs_dest** );
56 int ( *finalize )( struct l7vs_service*, struct l7vs_conn*, char*, size_t, struct l7vs_dest**, int );
57 enum LOG_LEVEL_TAG ( *get_log_level )( const enum LOG_CATEGORY_TAG );
58 void ( *put_log_debug )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
59 void ( *put_log_info )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
60 void ( *put_log_warn )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
61 void ( *put_log_error )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
62 void ( *put_log_fatal )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
63 void* ( *replication_pay_memory )( char*, unsigned int* );
66 extern char l7vs_module_path[];
72 extern struct l7vs_protomod* l7vs_protomod_get( char* );
73 extern void l7vs_protomod_put( struct l7vs_protomod* );
74 extern struct l7vs_protomod* l7vs_protomod_lookup( char* );
75 extern int l7vs_module_init( char* );
76 extern void l7vs_module_fini();
77 extern void* l7vs_module_load( char*, char* );
78 extern void l7vs_module_unload( void* );
79 extern void l7vs_module_register( GList**, void* );
80 extern void l7vs_module_remove( GList**, void* );
81 extern void* l7vs_module_lookup( GList*, void*, GCompareFunc );
83 #define PUT_LOG_FATAL(mod, cat, message_id, message, arg...) { \
84 if (mod.get_log_level != NULL && mod.put_log_fatal != NULL && \
85 LOG_LV_FATAL >= mod.get_log_level(cat)) { \
87 snprintf(buf, BUF_LEN, message, ##arg); \
88 mod.put_log_fatal(cat, message_id, __FILE__, __LINE__, buf); }}
90 #define PUT_LOG_ERROR(mod, cat, message_id, message, arg...) { \
91 if (mod.get_log_level != NULL && mod.put_log_error != NULL && \
92 LOG_LV_ERROR >= mod.get_log_level(cat)) { \
94 snprintf(buf, BUF_LEN, message, ##arg); \
95 mod.put_log_error(cat, message_id, __FILE__, __LINE__, buf); }}
97 #define PUT_LOG_WARN(mod, cat, message_id, message, arg...) { \
98 if (mod.get_log_level != NULL && mod.put_log_warn != NULL && \
99 LOG_LV_WARN >= mod.get_log_level(cat)) { \
101 snprintf(buf, BUF_LEN, message, ##arg); \
102 mod.put_log_warn(cat, message_id, __FILE__, __LINE__, buf); }}
104 #define PUT_LOG_INFO(mod, cat, message_id, message, arg...) { \
105 if (mod.get_log_level != NULL && mod.put_log_info != NULL && \
106 LOG_LV_INFO >= mod.get_log_level(cat)) { \
108 snprintf(buf, BUF_LEN, message, ##arg); \
109 mod.put_log_info(cat, message_id, __FILE__, __LINE__, buf); }}
111 #define PUT_LOG_DEBUG(mod, cat, message_id, message, arg...) { \
112 if (mod.put_log_debug != NULL) { \
114 snprintf(buf, BUF_LEN, message, ##arg); \
115 mod.put_log_debug(cat, message_id, __FILE__, __LINE__, buf); }}
117 template <typename T> enum LOG_LEVEL_TAG IS_DEBUG( const T &obj, enum LOG_CATEGORY_TAG tag ){
118 if( obj.get_log_level ){
119 return obj.get_log_level(tag);
121 if( obj.put_log_debug ){
122 obj.put_log_debug( tag, 0 , __FILE__, __LINE__, "oops pointer is NULL!!" );
128 * Extract struct l7vs_protomod to strings for debug log.
130 * @return l7vs_protomod struct
132 inline void l7vs_protomod_c_str(char* buf, struct l7vs_protomod* proto) {
134 snprintf(buf, DEBUG_STR_LEN, "NULL");
137 snprintf(buf, DEBUG_STR_LEN, "handle: %p, modname: %s, refcnt: %d, create: %p, compare: %p, "
138 "select_dest: %p, analyze_cldata: %p, analyze_rsdata: %p, destroy: %p, fini: %p, create_sa: %p, "
139 "service_arg: %p, parse: %p, destroy_sa: %p, initialize: %p, finalize: %p, get_log_level: %p, "
140 "put_log_debug: %p, put_log_info: %p, put_log_warn: %p, put_log_error: %p, put_log_fatal: %p",
141 proto->handle, proto->modname, proto->refcnt, proto->create, proto->compare, proto->select_dest,
142 proto->analyze_cldata, proto->analyze_rsdata, proto->destroy, proto->fini, proto->create_sa,
143 proto->service_arg, proto->parse, proto->destroy_sa, proto->initialize, proto->finalize,
144 proto->get_log_level, proto->put_log_debug, proto->put_log_info, proto->put_log_warn,
145 proto->put_log_error, proto->put_log_fatal);
149 #endif //L7VS_MODULE_H