GENERIC_SERVER  0.0.0.9
A light-weight, cross-platform, pluggable, extensible and secure framework for deploying C++ plug-ins.
 All Classes Files Functions Variables Typedefs Pages
generic_server.h
Go to the documentation of this file.
1 /*
2  Copyright 2013 Broadcom Corporation
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License version 2.1 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public
14  License along with this library; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
33 #ifndef GENERIC_SERVER_H
34 #define GENERIC_SERVER_H
35 
36 #include <map>
37 #include <vector>
38 #include <iostream>
39 #include <iomanip>
40 #include <fstream>
41 using namespace std;
42 #ifndef WINDOWS
43 #include <pthread.h>
44 #else
45 #include "XEventLog.h"
46 #endif
47 #include "sslserver.h"
48 #define NO_LOG 0
49 #define LOG_LOW 1
50 #define LOG_MEDIUM 2
51 #define LOG_HI 3
52 #define MAX_THREADS 100
53 #define PLUGIN_NAME 0
54 #define PLUGIN_TYPE 1
55 #define PORT 2
56 #define PLUGIN_NUMBER 3
57 #define SHARED_LIB_PATH 4
58 #define TLS_FLAG 5
59 #define PLUGIN_CONF 6
60 #define INIT 1
61 #define RELOAD 2
62 #define THREAD_FREE 0
63 #define THREAD_COMPLETED 2
64 #define THREAD_ALLOCATED 1
65 #define MAX_SZ 10000
66 #define MIN_REQUEST_NO 0
67 #define MAX_REQUEST_NO 100
68 typedef struct thread_info
70 {
71  int state;
72 #ifdef WINDOWS
73  HANDLE th;
74 #else
75  pthread_t th;
76 #endif
77 } THREAD_INFO;
78 typedef GENERIC_PLUGIN* (*create_fp)();
80 #ifdef WINDOWS
81 class LIBTYPE generic_server
82 #else
84 #endif
85 {
86 public:
88  static generic_server *instance(void);
92  int init();
94  int log(unsigned int,unsigned int,char *);
96  int log(unsigned int,unsigned int,string );
97  int get_log_size(void);
99  int rollover_logs(void);
100  int close_log(void);
102  int sock_init(void);
104  int swap_bytes(unsigned char *key);
112  int bb_getline(char *sav_buffer,size_t length,size_t conn_s);
113  int bb_getline(char *sav_buffer,size_t length,size_t conn_s,int);
114  int get_status(unsigned char *buff);
115  string get_cur_time(void);
116  string trim(const std::string&);
117  int socket_close(SOCKET);
118  int close_thread_ids(void);
125  SOCKET create_socket(int);
126  bool get_verify_client(void);
127  int set_verify_client(bool);
128  int check_enabled_plugin(string);
129  int check_allocated_port(string in_plugin_id,string in_plugin_port);
130  int set_conf_file(char *cfile);
131  int set_process_name(char *cfile);
132  int reload_conf_file(void);
133  int get_command_port(void);
134  int plugin_read_conf_file(GENERIC_PLUGIN *,int thread_no);
135  int syslog_msg(unsigned int debug_level,unsigned int verbose_level,string data);
136  string get_framework_version(void) {return("0_0_0_9");};
137  int print_key_message();
138  int get_thread_id();
139  int rel_thread_id(int);
145  bool check_plugin_aliases(vector<string> &alias);
146  int set_plugins_path(vector<string> &plugin_parms);
147  string get_plugins_path();
148  int setnonblocking(SOCKET);
149  int setblocking(SOCKET);
150  int get_thread_sync_mutex(void);
151  int rel_thread_sync_mutex(void);
152  int ssl_async_write(SSL *ssl,char *buf,int size);
153  int ssl_async_read(SSL *ssl,char *buf,int size);
154  int ssl_async_accept(SSL *ssl);
155 #ifdef WINDOWS
156  BOOL get_exe_directory(TCHAR *obuf, size_t osize);
157 #endif
158  vector<string> split(const string& s, const string& delim, const bool keep_empty);
166  GENERIC_PLUGIN *load_shared_lib(string library_image,string);
167  int unload_shared_lib(string plugin_type);
168  vector <GENERIC_PLUGIN *>::iterator get_start_iterator(void);
169  vector <GENERIC_PLUGIN *>::iterator get_end_iterator(void);
170  vector <GENERIC_PLUGIN *>::iterator itr;
172  vector <GENERIC_PLUGIN *> v;
173 
174  unsigned int timeout_seconds;
175  int max_threads,command_port;
176  ofstream log_file;
177  string logname;
178 #ifdef WINDOWS
179  map <string,HANDLE> dll_handles;
180  HANDLE hThread;
181 #else
182  map <string,void *> dll_handles;
183 #endif
184  map <int,THREAD_INFO> thread_ids;
189  map <string,create_fp> factory;
190  SSLServer sslserver;
191  bool syslog_flag;
192  // STL to hold do-only-once bootstapping across plugins
193  map <string,bool> bootstrap_jobs;
195  string server_cert,rsa_private_key,ca_certificate;
196 private:
197  generic_server(void);
198  int get_log_file_mutex(void);
199  int rel_log_file_mutex(void);
200  int get_server_params(string,int);
202  int tls_setup(void);
204  int remove_plugins(map <string,int> &new_ports);
205  int remove_all_aliases();
213  GENERIC_PLUGIN *initialize_plugin_object(vector<string> plugin_parms,GENERIC_PLUGIN *plugin);
215  int tls_initialize();
216  int set_access_control(char daemon_flag);
217  unsigned int iResult,tls_setup_reqd;
218  string conf_file,process_name,plugins_path;
219 #ifdef WINDOWS
220  CXEventLog el;
221  HANDLE log_file_mutex,thread_cnt_mutex,thread_sync_mutex;
222 #else
223  pthread_mutex_t log_file_mutex,thread_cnt_mutex,thread_sync_mutex;
224 #endif
225  unsigned long max_log_size;
226  int max_logs_saved;
227  bool verify_client;
228 };
230 typedef GENERIC_PLUGIN* (*create_fp)();
231 #endif
string server_cert
TLS certificate stuff.
static generic_server * pinstance
Pointer to singleton framework instance.
Utility class for TLS. Please refer excellent documentation at: http://www.openssl.org/docs/ssl/ssl.html.
Definition: sslserver.h:50
This is a singleton class and provides framework functionality.
This component provides functionality that are common across plug-ins. Framework would instantiate an...
OS agnostic thread handle.
struct thread_info THREAD_INFO
OS agnostic thread handle.
vector< GENERIC_PLUGIN * > v
Vector to hold all plug-ins.
map< string, create_fp > factory
Map that has function pointers to 'create_instance()' factory method for all plug-in libraries...
Utility class for TLS. Please refer excellent documentation at: http://www.openssl.org/docs/ssl/ssl.html.