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_plugin.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 */
31 #ifndef GENPLUGIN_H_
32 #define GENPLUGIN_H_
33 #include <iostream>
34 #include <string>
35 using namespace std;
36 #include <openssl/ssl.h>
37 #include <openssl/err.h>
38 #ifdef CRYPTOPP
39 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
40 #include "cryptlib.h"
41 #include "smartptr.h"
42 #include "algparam.h"
43 #include "hex.h"
44 #include "files.h"
45 #include "hex.h"
46 #include "base32.h"
47 #include "base64.h"
48 #include "modes.h"
49 #include "cbcmac.h"
50 #include "dmac.h"
51 #include "idea.h"
52 #include "des.h"
53 #include "rc2.h"
54 #include "arc4.h"
55 #include "rc5.h"
56 #include "blowfish.h"
57 #include "3way.h"
58 #include "safer.h"
59 #include "gost.h"
60 #include "shark.h"
61 #include "cast.h"
62 #include "square.h"
63 #include "seal.h"
64 #include "rc6.h"
65 #include "mars.h"
66 #include "rijndael.h"
67 #include "twofish.h"
68 #include "serpent.h"
69 #include "skipjack.h"
70 #include "shacal2.h"
71 #include "camellia.h"
72 #include "osrng.h"
73 #include "zdeflate.h"
74 #include "cpu.h"
75 #include "crc.h"
76 using namespace CryptoPP;
77 #endif
78 using namespace std;
79 #ifndef WINDOWS
80 
81 #define SOCKET int
82 #define sprintf_s snprintf
83 #define _stat stat
84 #define SOCKET_ERROR -1
85 #define INVALID_SOCKET -1
86 #define SD_SEND 2
87 #endif
88 #define CONTINUE_SESSION 0xFF
89 #define TERMINATE_SESSION 0x00
90 #define PLUGIN_SIGNATURE 0xDEDDAECF
91 #define HEX 0
92 #define BIN 1
93 
94 #ifdef WINDOWS
95 #pragma warning(disable:4251)
96 #define GEN_PLUGIN_MUTEX HANDLE
97 #define INIT_MUTEX CreateMutex( NULL, FALSE, NULL );
98 #else
99 #define GEN_PLUGIN_MUTEX pthread_mutex_t
100 #define INIT_MUTEX PTHREAD_MUTEX_INITIALIZER;
101 #endif
102 #ifdef WINDOWS
104 class LIBTYPE generic_plugin
105 {
106 friend LIBTYPE ostream& operator<<(ostream& output, generic_plugin& p);
107 #else
109 {
110 friend ostream& operator<<(ostream& output, generic_plugin& p);
111 #endif
112 protected:
119  int port,tls_enabled,thread_id;
120  char *local_ip_address;
121  string plugin_type;
122  string plugin_name;
123  string plugin_number;
124  string plugin_lib_path;
125  unsigned int networking,verbose_level;
133  vector<string> v_plugin_aliases;
134  int log(unsigned int,char *);
135  int log(unsigned int,string );
136 
137 public:
139  unsigned long pinstance;
140  string plugin_conf_file;
141  string generic_plugin_version();
142  generic_plugin(void);
143  generic_plugin(char *,int);
144  generic_plugin(char *,char *,int);
147  GEN_PLUGIN_MUTEX create_mutex(void);
150  int lock_mutex(GEN_PLUGIN_MUTEX *);
153  int rel_mutex(GEN_PLUGIN_MUTEX *);
154  bool get_validate_plugin(void);
155  virtual unsigned short get_session(void) {return(0);};
163  virtual int plugin_init(int thread_no) {return(0);};
172  virtual int get_plugin_params(string line);
183  virtual int process_request(void *buffer, void *out_buff,unsigned int &size) {return(0);};
197  virtual int server_init(void){return(1);};
203  virtual int server_shutdown(void){return(1);};
204  virtual string get_plugin_version(void) {return("UNKNOWN");};
215  virtual int shutdown_plugin(void) {return(1);};
224 virtual string bootstrap_name(void);
237  virtual bool bootstrap_init(string);
242  virtual bool bootstrap_terminate(string){return(true);};
243  SOCKET get_socket();
244  int get_port();
245  int get_thread_id();
246  int get_tls_flag();
247  string get_plugin();
248  string get_plugin_name();
249  string get_plugin_number();
250  string get_plugin_path();
251  int set_plugin(string);
252  int set_plugin_name(string);
253  int set_plugin_number(string);
254  int set_port(int);
255  int set_tls_flag(int);
256  int set_thread_id(int);
257  int set_socket(SOCKET);
258  int set_plugin_path(string);
259  int add_plugin_alias(string);
260  int clear_aliases();
261  int aliases_count();
262  string pop_alias();
263  bool find_plugin_alias(string);
265  SOCKET initialize_socket(string port);
266  int set_client_socket(SOCKET);
267  int set_conf_file(string);
268  string get_conf_file();
269  SOCKET get_client_socket(void);
270  generic_plugin &operator=(const generic_plugin &);
271  bool operator<(generic_plugin a)
272  {
273  return this->get_port() < a.get_port();
274  }
275  bool operator==(generic_plugin a)
276  {
277  return this->get_port() == a.get_port();
278  }
279  virtual ~generic_plugin() {};
280 };
282 
283 #endif
vector< string > v_plugin_aliases
virtual int shutdown_plugin(void)
This component provides functionality that are common across plug-ins. Framework would instantiate an...
virtual int server_shutdown(void)
virtual int plugin_init(int thread_no)
virtual int process_request(void *buffer, void *out_buff, unsigned int &size)
virtual bool bootstrap_terminate(string)
unsigned long pinstance
Pointer to 'framework' object.
virtual int server_init(void)