00001 /************************************************************************* 00002 * File:cms_srv.hh 00003 * Authors: Fred Proctor, Will Shackleford 00004 * Purpose: C++ Header file for server that reads and writes 00005 * to a local CMS buffer for remote processes. 00006 * Includes: 00007 * 1. class CMS_SERVER 00008 * 2. class CMS_SERVER_LOCAL_PORT 00009 *************************************************************************/ 00010 00011 #ifndef CMS_SERVER_HH 00012 #define CMS_SERVER_HH 00013 00014 #include "rcs_defs.hh" /* EXTERN_C_STD_HEADERS */ 00015 #include "sokintrf.h" // all the socket junk 00016 #include "cms_user.hh" /* class CMS, CMS_STATUS */ 00017 #include "cms_cfg.hh" /* CMS_CONFIG_LINELEN */ 00018 #include "linklist.hh" /* class RCS_LINKED_LIST */ 00019 #include "rem_msg.hh" /* struct REMOTE_READ_REQUEST, */ 00020 /* struct REMOTE_WRITE_REQUEST, */ 00021 00022 #ifdef WIN32 00023 00024 #if defined(WIN32) && !defined(USE_OLD_WINSOCK) 00025 /* Lame problem if windows.h is included before winsock2.h many redefined 00026 compiler errors result. */ 00027 #include <winsock2.h> 00028 #endif 00029 00030 #include <windows.h> // HANDLE 00031 #endif 00032 00033 00034 extern int cms_server_count; 00035 extern void wait_for_servers (int); 00036 00037 #ifdef VXWORKS 00038 extern int cms_server_task_priority; 00039 extern int cms_server_task_stack_size; 00040 #endif 00041 00042 00043 extern RCS_LINKED_LIST *cms_server_list; 00044 00045 #ifdef VXWORKS 00046 #include <semLib.h> 00047 extern SEM_ID cms_server_list_mutex; 00048 #endif 00049 00050 class RCS_EXPORT CMS_SERVER; 00051 class RCS_EXPORT CMS_DIAG_PROC_INFO; 00052 00053 class RCS_EXPORT CMS_SERVER_LOCAL_PORT:public virtual CMS_USER 00054 { 00055 protected: 00056 long buffer_number; 00057 int list_id; 00058 int security_enabled; 00059 friend class CMS_SERVER; 00060 CMS_DIAG_PROC_INFO *orig_info; 00061 00062 /* virtual functions for accessing local buffer. */ 00063 virtual REMOTE_READ_REPLY *reader (REMOTE_READ_REQUEST * req); 00064 virtual REMOTE_READ_REPLY *blocking_read (REMOTE_READ_REQUEST * req); 00065 virtual REMOTE_WRITE_REPLY *writer (REMOTE_WRITE_REQUEST * buf); 00066 virtual REMOTE_SET_DIAG_INFO_REPLY 00067 * set_diag_info (REMOTE_SET_DIAG_INFO_REQUEST * buf); 00068 virtual REMOTE_GET_DIAG_INFO_REPLY 00069 * get_diag_info (REMOTE_GET_DIAG_INFO_REQUEST * buf); 00070 virtual REMOTE_GET_MSG_COUNT_REPLY 00071 * get_msg_count (REMOTE_GET_DIAG_INFO_REQUEST * buf); 00072 virtual void reset_diag_info (); 00073 REMOTE_READ_REPLY read_reply; 00074 REMOTE_WRITE_REPLY write_reply; 00075 REMOTE_GET_BUF_NAME_REPLY namereply; 00076 REMOTE_GET_DIAG_INFO_REPLY get_diag_info_reply; 00077 00078 00079 public: 00080 CMS_SERVER_LOCAL_PORT (CMS * _cms); 00081 virtual ~ CMS_SERVER_LOCAL_PORT (); 00082 int local_channel_reused; 00083 00084 }; 00085 00086 class CMS_USER_INFO; 00087 00088 struct CMS_USER_CONNECT_STRUCT 00089 { 00090 CMS_USER_CONNECT_STRUCT (); 00091 CMS_USER_INFO *user_info; 00092 int fd; 00093 }; 00094 00095 00096 class RCS_EXPORT CMS_SERVER_REMOTE_PORT 00097 { 00098 public: 00099 CMS_SERVER_REMOTE_PORT (CMS_SERVER *); 00100 virtual ~ CMS_SERVER_REMOTE_PORT (); 00101 virtual void run () = 0; 00102 virtual void register_port (); 00103 virtual void unregister_port (); 00104 virtual int accept_local_port_cms (CMS * cms); 00105 int port_registered; 00106 CMS_USER_INFO *current_user_info; 00107 CMS_USER_INFO *get_connected_user (int); 00108 void add_connected_user (int); 00109 00110 protected: 00111 RCS_LINKED_LIST * connected_users; 00112 CMS_USER_CONNECT_STRUCT *current_connected_user_struct; 00113 int security_enabled; 00114 CMS_SERVER *cms_server_parent; 00115 static CMS_SERVER *find_server (long _pid, long _tid = 0); 00116 static void print_servers (); 00117 friend class CMS_SERVER; 00118 double min_compatible_version; 00119 int confirm_write; 00120 public: 00121 int running; 00122 int max_total_subdivisions; 00123 int port_num; 00124 int max_clients; 00125 int current_clients; 00126 }; 00127 00128 00129 class RCS_EXPORT CMS_SERVER 00130 { 00131 public: 00132 int security_enabled; 00133 REMOTE_CMS_REQUEST *request; 00134 int server_spawned; 00135 int server_registered; 00136 int list_id; 00137 RCS_LINKED_LIST *cms_local_ports; 00138 00139 CMS_SERVER_LOCAL_PORT *find_local_port (long _buffer_num); 00140 REMOTE_CHECK_IF_READ_REPLY cir_reply; 00141 REMOTE_CLEAR_REPLY clear_reply_struct; 00142 int using_passwd_file; 00143 int get_access_type (); 00144 long get_message_type (); 00145 const char *get_buffer_name (int _buf_num); 00146 int requests_processed; 00147 #ifndef UNDER_CE 00148 void read_passwd_file (); 00149 #endif 00150 00151 public: 00152 int get_total_subdivisions (long _buffer_num); 00153 CMS_SERVER_REMOTE_PORT *remote_port; 00154 #ifndef UNDER_CE 00155 void gen_random_key (char key[], int len); 00156 int security_check (CMS_USER_INFO * user_info, int _buf_num); 00157 int is_using_passwd_file (); 00158 CMS_USER_INFO *get_user_info (const char *name, const char *passwd); 00159 int get_user_keys (const char *name, char *key1, char *key2); 00160 #endif 00161 00162 static void clean (int); 00163 00164 #if defined(WIN32) && !defined(gnuwin32) 00165 DWORD current_pid; 00166 DWORD current_tid; 00167 DWORD creator_pid; 00168 DWORD creator_tid; 00169 DWORD spawner_pid; 00170 DWORD spawner_tid; 00171 DWORD server_pid; 00172 DWORD server_tid; 00173 #else 00174 00175 long current_pid; 00176 long current_tid; 00177 long creator_pid; 00178 long creator_tid; 00179 long spawner_pid; 00180 long spawner_tid; 00181 long server_pid; 00182 long server_tid; 00183 #endif 00184 00185 #if defined(WIN32) 00186 HANDLE server_thread_handle; 00187 #endif 00188 00189 long maximum_cms_size; 00190 REMOTE_CMS_REPLY *process_request (REMOTE_CMS_REQUEST *); 00191 void register_server (int setup_CC_signal_handler = 1); 00192 void unregister_server (); 00193 void run (int setup_CC_signal_handler = 1); 00194 int spawn (); 00195 void kill_server (); 00196 CMS_SERVER (); 00197 void add_local_port (CMS_SERVER_LOCAL_PORT *); 00198 void delete_all_local_ports (); 00199 virtual void delete_from_list (); 00200 virtual ~ CMS_SERVER (); 00201 virtual void initialize_write_request_space (); 00202 virtual int accept_local_port_cms (CMS *); 00203 REMOTE_READ_REQUEST read_req; 00204 REMOTE_WRITE_REQUEST write_req; 00205 REMOTE_GET_KEYS_REQUEST get_keys_req; 00206 REMOTE_LOGIN_REQUEST login_req; 00207 REMOTE_SET_SUBSCRIPTION_REQUEST set_subscription_req; 00208 REMOTE_CHECK_IF_READ_REQUEST check_if_read_req; 00209 REMOTE_CLEAR_REQUEST clear_req; 00210 REMOTE_SET_DIAG_INFO_REQUEST set_diag_info_req; 00211 REMOTE_GET_DIAG_INFO_REQUEST get_diag_info_req; 00212 REMOTE_GET_MSG_COUNT_REQUEST get_msg_count_req; 00213 REMOTE_READ_REPLY *read_reply; 00214 REMOTE_WRITE_REPLY *write_reply; 00215 REMOTE_GET_KEYS_REPLY *get_keys_reply; 00216 REMOTE_GET_KEYS_REPLY perm_get_keys_reply; 00217 REMOTE_LOGIN_REPLY *login_reply; 00218 REMOTE_LOGIN_REPLY perm_login_reply; 00219 REMOTE_SET_SUBSCRIPTION_REPLY *set_subscription_reply; 00220 REMOTE_SET_SUBSCRIPTION_REPLY perm_set_subscription_reply; 00221 REMOTE_CHECK_IF_READ_REPLY *check_if_read_reply; 00222 REMOTE_CLEAR_REPLY *clear_reply; 00223 REMOTE_SET_DIAG_INFO_REPLY *set_diag_info_reply; 00224 REMOTE_GET_DIAG_INFO_REPLY *get_diag_info_reply; 00225 REMOTE_GET_MSG_COUNT_REPLY *get_msg_count_reply; 00226 CMS_SERVER_LOCAL_PORT *last_local_port_used; 00227 int diag_enabled; 00228 char set_diag_info_buf[0x400]; 00229 int max_total_subdivisions; 00230 virtual void set_diag_info (REMOTE_SET_DIAG_INFO_REQUEST * _diag_info); 00231 virtual void reset_diag_info (int buffer_number); 00232 00233 private: 00234 double time_of_last_key_request; 00235 RCS_LINKED_LIST *known_users; 00236 char passwd_file[256]; 00237 CMS_USER_INFO *find_user (const char *); 00238 int guest_can_read; 00239 int guest_can_write; 00240 00241 }; 00242 00243 extern "C" void cms_print_servers (); 00244 00245 extern int (*detailed_security_check) (const char *user_name, 00246 const char *buffer_name, 00247 long msg_type, int access_type); 00248 00249 00250 #endif /* !CMS_SERVER_HH */