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
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
generic_plugin Class Reference

This component provides functionality that are common across plug-ins. Framework would instantiate and load objects of type GENERIC_PLUGIN to framework system from plugin shared library. More...

#include <generic_plugin.h>

Inheritance diagram for generic_plugin:
sample2_plugin sample_plugin

Public Member Functions

string generic_plugin_version ()
 
 generic_plugin (char *, int)
 
 generic_plugin (char *, char *, int)
 
GEN_PLUGIN_MUTEX create_mutex (void)
 
int lock_mutex (GEN_PLUGIN_MUTEX *)
 
int rel_mutex (GEN_PLUGIN_MUTEX *)
 
bool get_validate_plugin (void)
 
virtual unsigned short get_session (void)
 
virtual int plugin_init (int thread_no)
 
virtual int get_plugin_params (string line)
 
virtual int process_request (void *buffer, void *out_buff, unsigned int &size)
 
virtual int server_init (void)
 
virtual int server_shutdown (void)
 
virtual string get_plugin_version (void)
 
virtual int shutdown_plugin (void)
 
virtual string bootstrap_name (void)
 
virtual bool bootstrap_init (string)
 
virtual bool bootstrap_terminate (string)
 
SOCKET get_socket ()
 
int get_port ()
 
int get_thread_id ()
 
int get_tls_flag ()
 
string get_plugin ()
 
string get_plugin_name ()
 
string get_plugin_number ()
 
string get_plugin_path ()
 
int set_plugin (string)
 
int set_plugin_name (string)
 
int set_plugin_number (string)
 
int set_port (int)
 
int set_tls_flag (int)
 
int set_thread_id (int)
 
int set_socket (SOCKET)
 
int set_plugin_path (string)
 
int add_plugin_alias (string)
 
int clear_aliases ()
 
int aliases_count ()
 
string pop_alias ()
 
bool find_plugin_alias (string)
 
SOCKET initialize_socket (string port)
 Binds socket to TCP port, set options on new socket and do socket listen.
 
int set_client_socket (SOCKET)
 
int set_conf_file (string)
 
string get_conf_file ()
 
SOCKET get_client_socket (void)
 
generic_pluginoperator= (const generic_plugin &)
 
bool operator< (generic_plugin a)
 
bool operator== (generic_plugin a)
 

Public Attributes

unsigned long pinstance
 Pointer to 'framework' object.
 
string plugin_conf_file
 

Protected Member Functions

int log (unsigned int, char *)
 
int log (unsigned int, string)
 

Protected Attributes

SOCKET server_socket
 
SOCKET client_socket
 
int port
 
int tls_enabled
 
int thread_id
 
char * local_ip_address
 
string plugin_type
 
string plugin_name
 
string plugin_number
 
string plugin_lib_path
 
unsigned int networking
 
unsigned int verbose_level
 
bool validate_plugin
 
vector< string > v_plugin_aliases
 

Friends

ostream & operator<< (ostream &output, generic_plugin &p)
 

Detailed Description

This component provides functionality that are common across plug-ins. Framework would instantiate and load objects of type GENERIC_PLUGIN to framework system from plugin shared library.

Definition at line 108 of file generic_plugin.h.

Member Function Documentation

bool generic_plugin::bootstrap_init ( string  str)
virtual

This method gets invoked by the framework when it is being booted up. This method is invoked only once per 'bootstrap_name', each time framework is started up. If there are three plug-ins in generic_server conf file, all of them belonging to different plug-in types and each of them defines the same 'bootstrap_name', then this method gets called only once when the first plug-in is loaded Please note, this method gets invoked during framework start-up time - not during client session initiation. This would be the place to do stuff like:

  • Any one-time initialization (not per session) required by plug-ins belonging to different plug-in types
  • Dynamically load any shared library required by any plug-in

Reimplemented in sample_plugin.

Definition at line 505 of file generic_plugin.cpp.

Referenced by generic_server::initialize_plugin_object().

506 {
507  return(true);
508 }
string generic_plugin::bootstrap_name ( void  )
virtual

GENERIC_SERVER framework provides a feature where plug-ins could request framework to call one or more bootstrap methods when framework is being bootsrapped. Any plug-in could implement 'bootstrap' methods. 'bootstrap_name' is the name associated with a specific 'bootstrap' method. Plug-ins should be co-operative and set differnet bootstrap_names to identify and implement different tasks. Under no circumstances should different plug-ins define the same 'bootstrap_name', if such a case should ever occur, framework will ignore the latter defined and implemented bootstrap method.

Reimplemented in sample_plugin.

Definition at line 499 of file generic_plugin.cpp.

Referenced by generic_server::initialize_plugin_object().

500 {
501  return("");
502 }
virtual bool generic_plugin::bootstrap_terminate ( string  )
inlinevirtual

This is the opposite of 'bootstrap_init()', framework invokes this method once for a 'bootstrap_name' when framework is being terminated.

Reimplemented in sample_plugin.

Definition at line 242 of file generic_plugin.h.

242 {return(true);};
GEN_PLUGIN_MUTEX generic_plugin::create_mutex ( void  )

OS agnostic wrapper API to create mutex

Definition at line 448 of file generic_plugin.cpp.

449 {
450  GEN_PLUGIN_MUTEX mutex;
451 #ifdef WINDOWS
452  mutex = CreateMutex( NULL, FALSE, NULL);
453 #else
454  pthread_mutex_init(&mutex,NULL);
455 #endif
456  return(mutex);
457 }
int generic_plugin::get_plugin_params ( string  line)
virtual

Read plug-in configuration data

Framework presents configuration information from plug-in conf file to be processed.
This method will be invoked once per line in plug-in conf file.
Parameters
[in]lineOne line from plug-in conf file.
Returns
1 on success, 0 on failure.

Reimplemented in sample2_plugin, and sample_plugin.

Definition at line 422 of file generic_plugin.cpp.

Referenced by sample_plugin::get_plugin_params(), and sample2_plugin::get_plugin_params().

423 {
425 
426  if(line.size() > 11 && line.compare(0,11,"NETWORKING=") == 0)
427  {
428  networking = atoi(line.substr(11).c_str());
429  return(0);
430  }
431  if(line.size() > 14 && line.compare(0,14,"VERBOSE_LEVEL=") == 0)
432  {
433  verbose_level = atoi(line.substr(14).c_str());
434  return(0);
435  }
436  if (line.size() > 16 && line.compare(0,16,"VALIDATE_PLUGIN=") == 0)
437  {
438  if(atoi(line.substr(16).c_str()) )
439  validate_plugin = true;
440  else
441  validate_plugin = false;
442  return(0);
443  }
444  return(1);
445 }
This is a singleton class and provides framework functionality.
unsigned long pinstance
Pointer to 'framework' object.
int generic_plugin::lock_mutex ( GEN_PLUGIN_MUTEX *  mutex)

OS agnostic wrapper API to lock mutex

Definition at line 460 of file generic_plugin.cpp.

461 {// not using pthread_cond variable, since Windows does not support cond. variables
462 #ifdef WINDOWS
463 DWORD dwWaitResult;
464  dwWaitResult = WaitForSingleObject(*mutex,INFINITE);
465 #else
466  pthread_mutex_lock(mutex);
467 #endif
468  return(1);
469 }
virtual int generic_plugin::plugin_init ( int  thread_no)
inlinevirtual

Initialize plug-in

This method gets invoked whenever a new client session gets initiated.
Parameters
[in]thread_noThe thread number assigned to plug-in.
Returns
1 on success, 0 on failure.

Reimplemented in sample2_plugin, and sample_plugin.

Definition at line 163 of file generic_plugin.h.

163 {return(0);};
virtual int generic_plugin::process_request ( void *  buffer,
void *  out_buff,
unsigned int &  size 
)
inlinevirtual

Handle client request

Framework presents client input data to plug-in to process.
Parameters
[in]bufferRequest sent by client.
[out]outbuffResponse to be sent back to client.
[in,out]send_bytesSize of input buffer sent by client, function sets this to size of outbuff.
Returns
TERMINATE_SESSION to indicate plug-in done with the session with client or CONTINUE_SESSION to indicate plug-in want to continue session with client and process more requests.

Reimplemented in sample2_plugin, and sample_plugin.

Definition at line 183 of file generic_plugin.h.

183 {return(0);};
int generic_plugin::rel_mutex ( GEN_PLUGIN_MUTEX *  mutex)

OS agnostic wrapper API to release mutex

Definition at line 472 of file generic_plugin.cpp.

473 {
474 #ifdef WINDOWS
475  ReleaseMutex(mutex);
476 #else
477  pthread_mutex_unlock(mutex);
478 #endif
479  return(1);
480 }
virtual int generic_plugin::server_init ( void  )
inlinevirtual

This method gets invoked by the framework once per plug-in type when it is getting started. Please note, this method is invoked only ONCE for a particular plug-in type. If there are three plug-ins in generic_server conf file, all of them belonging to same plug-in_type, then this method gets called only once when the first plug-in is loaded. Please note, this method gets invoked during framework start-up in the MAIN thread. This would be the place to do stuff like:

  • Any one-time initialization (not per session) required by one or plug-in(s) belonging to same plug-in type
  • Store any information required to be shared across multiple instances of a plug-in into plug-in object as 'static' variable(s)

Reimplemented in sample2_plugin, and sample_plugin.

Definition at line 197 of file generic_plugin.h.

Referenced by generic_server::initialize_plugin_object().

197 {return(1);};
virtual int generic_plugin::server_shutdown ( void  )
inlinevirtual

This is the opposite of 'server_init()', framework invokes this method when a plug-in is removed from generic_server conf file. Similar to 'server_init()', 'server_shutdown()' gets invoked only once when the last plug-in of a plug-in_type is removed.

Reimplemented in sample2_plugin, and sample_plugin.

Definition at line 203 of file generic_plugin.h.

203 {return(1);};
virtual int generic_plugin::shutdown_plugin ( void  )
inlinevirtual

Terminate plug-in session

This method gets invoked whenever a client session gets terminated.
Returns
1 on success, 0 on failure. This is the opposite of 'plugin_init()', framework invokes this method when a client session is getting terminated.

Reimplemented in sample2_plugin, and sample_plugin.

Definition at line 215 of file generic_plugin.h.

Referenced by terminate_client_session(), and terminate_ssl_client_session().

215 {return(1);};

Member Data Documentation

SOCKET generic_plugin::client_socket
protected

socket passed on to plug-ins by framework after a successful client connect.

Definition at line 118 of file generic_plugin.h.

SOCKET generic_plugin::server_socket
protected

socket used by framework to LISTEN/SELECT clients.

Definition at line 115 of file generic_plugin.h.

vector<string> generic_plugin::v_plugin_aliases
protected

A plug-in can have one or more 'alias' plug-ins. Essentially, one port,plug-in_type get multi-plexed for all alias plug-ins.

Definition at line 133 of file generic_plugin.h.

bool generic_plugin::validate_plugin
protected

Flag to indcate whether framework should authorize any client request to this plug-in.

Definition at line 128 of file generic_plugin.h.


The documentation for this class was generated from the following files: