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 | Private Attributes | List of all members
sample2_plugin Class Reference

Derived from GENERIC_PLUGIN. Implements virtual functions and all plug-in specific functionality. More...

#include <sample2.h>

Inheritance diagram for sample2_plugin:
generic_plugin

Public Member Functions

 sample2_plugin (char *, int)
 
int shutdown_plugin (void)
 
int plugin_init (int)
 
int server_init (void)
 
int server_shutdown (void)
 
int process_request (void *, void *, unsigned int &)
 
int init (void)
 
int init (int)
 
string get_plugin_version (void)
 
int get_plugin_params (string line)
 
sample2_pluginoperator= (const sample2_plugin &)
 
- Public Member Functions inherited from generic_plugin
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 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)
 

Private Attributes

ofstream new_file
 
string ftp_dir
 
string fname
 

Additional Inherited Members

- Public Attributes inherited from generic_plugin
unsigned long pinstance
 Pointer to 'framework' object.
 
string plugin_conf_file
 
- Protected Member Functions inherited from generic_plugin
int log (unsigned int, char *)
 
int log (unsigned int, string)
 
- Protected Attributes inherited from generic_plugin
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
 

Detailed Description

Derived from GENERIC_PLUGIN. Implements virtual functions and all plug-in specific functionality.

Definition at line 41 of file sample2.h.

Member Function Documentation

int sample2_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 from generic_plugin.

Definition at line 227 of file sample2.cpp.

References generic_plugin::get_plugin_params().

228 {
230  if (line.size() > 8 && line.compare(0,8,"FTP_DIR=") == 0)
231  {
232  ftp_dir = line.substr(8);
233  return(0);
234  }
235  return(1);
236 }
virtual int get_plugin_params(string line)
int sample2_plugin::plugin_init ( int  thread_no)
virtual

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 from generic_plugin.

Definition at line 79 of file sample2.cpp.

80 {
81  ostringstream oss;
82 
83  try
84  {
85  oss << " Thr.ID:" << thread_no << " Plugin:" << plugin_name << " Successfully initialized session.";
86  log(LOG_HI,oss.str());
87  return(1);
88  }
89  catch(const exception& er)
90  {
91  oss << " Thr.ID:" << thread_no << " Plugin:" << plugin_name << " " << er.what();
92  log(LOG_HI,oss.str());
93  return(0);
94  }
95 }
int sample2_plugin::process_request ( void *  buffer,
void *  out_buff,
unsigned int &  size 
)
virtual

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 from generic_plugin.

Definition at line 168 of file sample2.cpp.

References generic_plugin::pinstance.

169 {
171  ostringstream oss;
172  unsigned char *req_type;
173  // Simple file transfer messaging
174  // REQUEST_TYPE - 1 byte
175  // PLUGIN_DATA - variable/optional,based on REQUEST_TYPE
176  // REQUEST_TYPE:
177  // 1 - set file name; plugin will create a file on server on receipt of this request
178  // Example: 1file_to_transfer.jpg
179  // 2 - file data; plugin will append data to file created earlier
180  // Example: 2file_data
181  // 3 - close file; plugin will close file created
182 
183  req_type = static_cast<unsigned char *>(buffer);
184  switch(*req_type)
185  {
186  case SET_FILENAME:
187  fname = ftp_dir + "/" + string((char *)buffer+1,size-1);
188  new_file.open(fname.c_str(),ios::binary);
189  if(!new_file.rdbuf()->is_open())
190  {
191  size = 0;
192  return(TERMINATE_SESSION);
193  }
194  oss.clear();
195  oss.str("");
196  oss << " Thr.ID:" << thread_id << " Plugin:" << plugin_name << " Creating new file: " << fname;
197  log(LOG_LOW,oss.str());
198  size = 0;
199  return(CONTINUE_SESSION);
200 
201  case FILE_DATA:
202  new_file << string((char *)buffer+1,size-1);
203  return(CONTINUE_SESSION);
204 
205  case CLOSE_FILE:
206  new_file.close();
207  oss.clear();
208  oss.str("");
209  oss << " Thr.ID:" << thread_id << " Plugin:" << plugin_name << " Closing file: " << fname;
210  log(LOG_LOW,oss.str());
211  size = 0;
212  return(TERMINATE_SESSION);
213 
214  default:
215  return(TERMINATE_SESSION);
216  }
217 return(CONTINUE_SESSION);
218 }
This is a singleton class and provides framework functionality.
unsigned long pinstance
Pointer to 'framework' object.
int sample2_plugin::server_init ( void  )
virtual

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 from generic_plugin.

Definition at line 130 of file sample2.cpp.

131 {
132  ostringstream oss;
133 
134  try
135  {
136  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " Successfully initialized sample2 server.";
137  log(LOG_HI,oss.str());
138  return(1);
139  }
140  catch(const exception& er)
141  {
142  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " " << er.what();
143  log(LOG_HI,oss.str());
144  return(0);
145  }
146 }
int sample2_plugin::server_shutdown ( void  )
virtual

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 from generic_plugin.

Definition at line 149 of file sample2.cpp.

150 {
151  ostringstream oss;
152 
153  try
154  {
155  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " Successfully shutdown sample2 server.";
156  log(LOG_HI,oss.str());
157  return(1);
158  }
159  catch(const exception& er)
160  {
161  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " " << er.what();
162  log(LOG_HI,oss.str());
163  return(0);
164  }
165 }
int sample2_plugin::shutdown_plugin ( void  )
virtual

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 from generic_plugin.

Definition at line 109 of file sample2.cpp.

References generic_plugin::pinstance.

110 {
111  ostringstream oss;
113 
114  try
115  {
116 // Do plug-in cleanup here..
117  oss << " Thr.ID:" << thread_id << " Plugin:" << plugin_name << " Successfully shutdown session.";
118  log(LOG_HI,oss.str());
119  }
120  catch(const exception& er)
121  {
122  oss << " Thr.ID: MAIN Plugin:" << plugin_name << " " << er.what();
123  log(LOG_HI,oss.str());
124  return 0;
125  }
126  return(1);
127 }
This is a singleton class and provides framework functionality.
unsigned long pinstance
Pointer to 'framework' object.

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