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 ( *match_cldata )( struct l7vs_service*, struct l7vs_conn*, char*, size_t*, struct l7vs_dest**, int* );
47 int ( *analyze_rsdata )( struct l7vs_service*, struct l7vs_conn*, char*, size_t* );
48 int ( *destroy )( uint32_t );
50 void* ( *create_sa )( struct l7vs_service_arg* );
51 int ( *service_arg )( struct l7vs_service_arg_multi*, uint32_t );
52 int ( *parse )( void*, int, char** );
53 void ( *destroy_sa )( void** );
54 int ( *initialize )( struct l7vs_service*, struct l7vs_conn*, char*, size_t, struct l7vs_dest** );
55 int ( *finalize )( struct l7vs_service*, struct l7vs_conn*, char*, size_t, struct l7vs_dest**, int );
56 enum LOG_LEVEL_TAG ( *get_log_level )( const enum LOG_CATEGORY_TAG );
57 void ( *put_log_debug )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
58 void ( *put_log_info )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
59 void ( *put_log_warn )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
60 void ( *put_log_error )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
61 void ( *put_log_fatal )( const enum LOG_CATEGORY_TAG, const unsigned int, char*, int, const char* );
62 void* ( *replication_pay_memory )( char*, unsigned int* );
65 extern char l7vs_module_path[];
71 extern struct l7vs_protomod* l7vs_protomod_get( char* );
72 extern void l7vs_protomod_put( struct l7vs_protomod* );
73 extern struct l7vs_protomod* l7vs_protomod_lookup( char* );
74 extern int l7vs_module_init( char* );
75 extern void l7vs_module_fini();
76 extern void* l7vs_module_load( char*, char* );
77 extern void l7vs_module_unload( void* );
78 extern void l7vs_module_register( GList**, void* );
79 extern void l7vs_module_remove( GList**, void* );
80 extern void* l7vs_module_lookup( GList*, void*, GCompareFunc );
82 #define PUT_LOG_FATAL(mod, cat, message_id, message, arg...) { \
83 if (mod.get_log_level != NULL && mod.put_log_fatal != NULL && \
84 LOG_LV_FATAL >= mod.get_log_level(cat)) { \
86 snprintf(buf, BUF_LEN, message, ##arg); \
87 mod.put_log_fatal(cat, message_id, __FILE__, __LINE__, buf); }}
89 #define PUT_LOG_ERROR(mod, cat, message_id, message, arg...) { \
90 if (mod.get_log_level != NULL && mod.put_log_error != NULL && \
91 LOG_LV_ERROR >= mod.get_log_level(cat)) { \
93 snprintf(buf, BUF_LEN, message, ##arg); \
94 mod.put_log_error(cat, message_id, __FILE__, __LINE__, buf); }}
96 #define PUT_LOG_WARN(mod, cat, message_id, message, arg...) { \
97 if (mod.get_log_level != NULL && mod.put_log_warn != NULL && \
98 LOG_LV_WARN >= mod.get_log_level(cat)) { \
100 snprintf(buf, BUF_LEN, message, ##arg); \
101 mod.put_log_warn(cat, message_id, __FILE__, __LINE__, buf); }}
103 #define PUT_LOG_INFO(mod, cat, message_id, message, arg...) { \
104 if (mod.get_log_level != NULL && mod.put_log_info != NULL && \
105 LOG_LV_INFO >= mod.get_log_level(cat)) { \
107 snprintf(buf, BUF_LEN, message, ##arg); \
108 mod.put_log_info(cat, message_id, __FILE__, __LINE__, buf); }}
110 #define PUT_LOG_DEBUG(mod, cat, message_id, message, arg...) { \
111 if (mod.put_log_debug != NULL) { \
113 snprintf(buf, BUF_LEN, message, ##arg); \
114 mod.put_log_debug(cat, message_id, __FILE__, __LINE__, buf); }}
116 template <typename T> enum LOG_LEVEL_TAG IS_DEBUG( const T &obj, enum LOG_CATEGORY_TAG tag ){
117 if( obj.get_log_level ){
118 return obj.get_log_level(tag);
120 if( obj.put_log_debug ){
121 obj.put_log_debug( tag, 0 , __FILE__, __LINE__, "opps pointer is NULL!!" );
127 * Extract struct l7vs_protomod to strings for debug log.
129 * @return l7vs_protomod struct
131 inline void l7vs_protomod_c_str(char* buf, struct l7vs_protomod* proto) {
133 snprintf(buf, DEBUG_STR_LEN, "NULL");
136 snprintf(buf, DEBUG_STR_LEN, "handle: %p, modname: %s, refcnt: %d, create: %p, compare: %p, "
137 "match_cldata: %p, analyze_rsdata: %p, destroy: %p, fini: %p, create_sa: %p, service_arg: %p, "
138 "parse: %p, destroy_sa: %p, initialize: %p, finalize: %p, get_log_level: %p, put_log_debug: %p, "
139 "put_log_info: %p, put_log_warn: %p, put_log_error: %p, put_log_fatal: %p",
140 proto->handle, proto->modname, proto->refcnt, proto->create, proto->compare, proto->match_cldata,
141 proto->analyze_rsdata, proto->destroy, proto->fini, proto->create_sa, proto->service_arg,
142 proto->parse, proto->destroy_sa, proto->initialize, proto->finalize, proto->get_log_level,
143 proto->put_log_debug, proto->put_log_info, proto->put_log_warn, proto->put_log_error,
144 proto->put_log_fatal);
148 #endif //L7VS_MODULE_H