00001
00002
00003
00004
00005
00006
00007 #include "rcs_defs.hh"
00008 #include "sokintrf.h"
00009 #include "timer.hh"
00010 #include "dbg_mem.h"
00011
00012 #ifdef EXTERN_C_STD_HEADERS
00013 extern "C"
00014 {
00015 #endif
00016
00017 #include <string.h>
00018 #include <errno.h>
00019 #include <stdlib.h>
00020 #ifdef UNIX_LIKE_PLAT
00021 #include <unistd.h>
00022 #endif
00023
00024 #ifdef EXTERN_C_STD_HEADERS
00025 }
00026 #endif
00027
00028 #include "cms.hh"
00029 #include "stcpsvr.hh"
00030 #include "rcs_prnt.hh"
00031 #include "linklist.hh"
00032 #include "stcpopts.hh"
00033
00034 extern "C"
00035 {
00036 #include "recvline.h"
00037 #include "sendline.h"
00038 }
00039
00040 CMS_SERVER_REMOTE_STCP_PORT::CMS_SERVER_REMOTE_STCP_PORT (CMS_SERVER *
00041 _cms_server):CMS_SERVER_REMOTE_PORT
00042 (_cms_server)
00043 {
00044 client_ports = (RCS_LINKED_LIST *) NULL;
00045 connection_socket = 0;
00046 connection_port = 0;
00047 maxfdpl = 0;
00048 temp_buffer = NULL;
00049 temp_buffer_size = 0;
00050 if (load_socket_interface () < 0)
00051 {
00052 rcs_print_error ("Can't load socket interface.\n");
00053 return;
00054 }
00055
00056 memset (&server_socket_address, 0, sizeof (server_socket_address));
00057 server_socket_address.sin_family = AF_INET;
00058 server_socket_address.sin_addr.s_addr = dl_htonl (INADDR_ANY);
00059 server_socket_address.sin_port = 0;
00060
00061 client_ports = new RCS_LINKED_LIST;
00062 if (NULL == client_ports)
00063 {
00064 rcs_print_error ("Can not create linked list for client ports.\n");
00065 return;
00066 }
00067
00068 }
00069
00070 CMS_SERVER_REMOTE_STCP_PORT::~CMS_SERVER_REMOTE_STCP_PORT ()
00071 {
00072 unregister_port ();
00073 if (NULL != client_ports)
00074 {
00075 delete client_ports;
00076 client_ports = (RCS_LINKED_LIST *) NULL;
00077 }
00078 if (NULL != temp_buffer)
00079 {
00080 delete temp_buffer;
00081 temp_buffer = NULL;
00082 }
00083 }
00084
00085 void
00086 CMS_SERVER_REMOTE_STCP_PORT::unregister_port ()
00087 {
00088 CLIENT_STCP_PORT *client;
00089 int clients_to_close = 0;
00090 client = (CLIENT_STCP_PORT *) client_ports->get_head ();
00091 while (NULL != client)
00092 {
00093 rcs_print ("\nPlease shutdown the client on %s.\n",
00094 dl_inet_ntoa (client->address.sin_addr));
00095 if (client->socket_fd > 0)
00096 {
00097 sendline (client->socket_fd, "ERR:Shutdown NOW!!!", 0, 1.0);
00098 }
00099 clients_to_close++;
00100 client = (CLIENT_STCP_PORT *) client_ports->get_next ();
00101 }
00102 if (clients_to_close > 0)
00103 {
00104 rcs_print
00105 ("Waiting 15 seconds for you to close %d remote client connection(s).\n",
00106 clients_to_close);
00107 esleep (15.0);
00108 }
00109 client = (CLIENT_STCP_PORT *) client_ports->get_head ();
00110 while (NULL != client)
00111 {
00112 if (client->socket_fd > 0)
00113 {
00114 clean_prev_read_info (client->socket_fd);
00115 dl_closesocket (client->socket_fd);
00116 }
00117 client_ports->delete_current_node ();
00118 client = (CLIENT_STCP_PORT *) client_ports->get_next ();
00119 }
00120 if (clients_to_close > 0)
00121 {
00122 esleep (2.0);
00123 }
00124 if (connection_socket > 0)
00125 {
00126 dl_closesocket (connection_socket);
00127 connection_socket = 0;
00128 }
00129 }
00130
00131 int
00132 CMS_SERVER_REMOTE_STCP_PORT::accept_local_port_cms (CMS * _cms)
00133 {
00134 if (NULL == _cms)
00135 {
00136 return 0;
00137 }
00138 if (_cms->remote_port_type != CMS_STCP_REMOTE_PORT_TYPE)
00139 {
00140 return 0;
00141 }
00142
00143 if (server_socket_address.sin_port == 0)
00144 {
00145 server_socket_address.sin_port =
00146 dl_htons (((u_short) _cms->stcp_port_number));
00147 buffer_number = _cms->buffer_number;
00148 temp_buffer =
00149 (char *) DEBUG_MALLOC (cms_encoded_data_explosion_factor *
00150 _cms->size);
00151 if (temp_buffer != NULL)
00152 {
00153 temp_buffer_size = cms_encoded_data_explosion_factor * _cms->size;
00154 }
00155 else
00156 {
00157 rcs_print_error ("Out of memory.\n");
00158 }
00159 if (CMS_DISPLAY_ASCII_ENCODING != _cms->neutral_encoding_method)
00160 {
00161 rcs_print_error
00162 ("The neutral_encoding_method must be ASCII_DISPLAY_ENCODING to use the simplified STCP protocol.\n");
00163 rcs_print_error
00164 (" This server will not provide access to the %s buffer.\n",
00165 _cms->BufferName);
00166 return 0;
00167 }
00168 return 1;
00169 }
00170
00171 if (server_socket_address.sin_port ==
00172 dl_htons (((u_short) _cms->stcp_port_number)))
00173 {
00174 #if 0
00175 rcs_print_error
00176 ("Only 1 buffer can be served on a single port with the Stcp compatible interface.\n");
00177 rcs_print_error
00178 ("There appear to be more than 1 configured for port = %d.\n",
00179 _cms->stcp_port_number);
00180 return 0;
00181 #endif
00182 return 1;
00183 }
00184
00185 return 0;
00186 }
00187
00188 void
00189 CMS_SERVER_REMOTE_STCP_PORT::register_port ()
00190 {
00191 port_registered = 0;
00192 int bind_error;
00193 rcs_print_debug (PRINT_CMS_CONFIG_INFO,
00194 "Registering server on STCP port %d.\n",
00195 dl_ntohs (server_socket_address.sin_port));
00196 if (server_socket_address.sin_port == 0)
00197 {
00198 rcs_print_error ("server can not register on port number 0.\n");
00199 return;
00200 }
00201 if ((connection_socket = dl_socket (AF_INET, SOCK_STREAM, 0)) < 0)
00202 {
00203 rcs_print_error ("Server can not open stream socket.\n");
00204 return;
00205 }
00206
00207 int old_stcp_nonblocking = stcp_nonblocking;
00208 stcp_nonblocking = 0;
00209 if (set_stcp_socket_options (connection_socket) < 0)
00210 {
00211 stcp_nonblocking = old_stcp_nonblocking;
00212 return;
00213 }
00214 stcp_nonblocking = old_stcp_nonblocking;
00215
00216 if (dl_bind (connection_socket, (struct sockaddr *) &server_socket_address,
00217 sizeof (server_socket_address)) < 0)
00218 {
00219 #if defined(_Windows) && !defined(gnuwin32)
00220 bind_error = dl_WSAGetLastError ();
00221 #else
00222 bind_error = errno;
00223 #endif
00224 rcs_print_error ("Can not bind port %d. errno = %d -- %s\n",
00225 dl_ntohs (server_socket_address.sin_port),
00226 bind_error, strerror (bind_error));
00227 dl_closesocket (connection_socket);
00228 connection_socket = 0;
00229 return;
00230 }
00231 if (dl_listen (connection_socket, 5) < 0)
00232 {
00233 rcs_print_error ("STCP Server: error on call to listen.\n");
00234 return;
00235 }
00236 port_registered = 1;
00237
00238 }
00239
00240 void
00241 CMS_SERVER_REMOTE_STCP_PORT::run ()
00242 {
00243 unsigned long bytes_ready;
00244 int ready_descriptors;
00245 int unfinished = 0;
00246 if (NULL == client_ports)
00247 {
00248 rcs_print_error ("CMS_SERVER: List of client ports is NULL.\n");
00249 }
00250 CLIENT_STCP_PORT new_client_port, *client_port_to_check;
00251 FD_ZERO (&read_fd_set);
00252 FD_ZERO (&write_fd_set);
00253 RCS_FD_SET (connection_socket, &read_fd_set);
00254 maxfdpl = connection_socket + 1;
00255 rcs_print_debug (PRINT_CMS_CONFIG_INFO,
00256 "running server for STCP port %d (connection_socket = %d).\n",
00257 dl_ntohs (server_socket_address.sin_port),
00258 connection_socket);
00259 cms_server_count++;
00260
00261 while (1)
00262 {
00263 ready_descriptors =
00264 dl_select (maxfdpl, &read_fd_set, &write_fd_set, (fd_set *) NULL,
00265 (timeval *) NULL);
00266 if (ready_descriptors < 0)
00267 {
00268 rcs_print_error ("server: select error.(errno = %d | %s)\n",
00269 errno, strerror (errno));
00270 }
00271 unfinished = 0;
00272 client_port_to_check = (CLIENT_STCP_PORT *) client_ports->get_head ();
00273 while (NULL != client_port_to_check)
00274 {
00275 if (dl_fd_isset (client_port_to_check->socket_fd, &read_fd_set))
00276 {
00277 #if defined(WIN32) && !defined(gnuwin32)
00278 dl_ioctlsocket (client_port_to_check->socket_fd, FIONREAD,
00279 &bytes_ready);
00280 #else
00281 #ifndef VXWORKS
00282 ioctl (client_port_to_check->socket_fd, FIONREAD,
00283 (caddr_t) & bytes_ready);
00284 #else
00285 ioctl (client_port_to_check->socket_fd, FIONREAD,
00286 (int) &bytes_ready);
00287 #endif
00288 #endif
00289 if (bytes_ready == 0)
00290 {
00291 rcs_print_debug (PRINT_SOCKET_CONNECT,
00292 "Socket closed by host with IP address %s using connection %d.\n",
00293 dl_inet_ntoa
00294 (client_port_to_check->address.sin_addr),
00295 client_port_to_check->socket_fd);
00296 clean_prev_read_info (client_port_to_check->socket_fd);
00297 dl_closesocket (client_port_to_check->socket_fd);
00298 RCS_FD_CLR (client_port_to_check->socket_fd, &read_fd_set);
00299 client_ports->delete_current_node ();
00300
00301 }
00302 else
00303 {
00304 handle_request (client_port_to_check);
00305 if (!handle_request_error_occured)
00306 {
00307 if (get_bytes_already_read
00308 (client_port_to_check->socket_fd) > 0)
00309 {
00310 unfinished = 1;
00311 }
00312 }
00313 }
00314 ready_descriptors--;
00315 }
00316 else
00317 {
00318 RCS_FD_SET (client_port_to_check->socket_fd, &read_fd_set);
00319 }
00320 client_port_to_check =
00321 (CLIENT_STCP_PORT *) client_ports->get_next ();
00322 }
00323 if (dl_fd_isset (connection_socket, &read_fd_set)
00324 && ready_descriptors > 0)
00325 {
00326 ready_descriptors--;
00327 int client_address_length;
00328 client_address_length = sizeof (new_client_port.address);
00329
00330 memset (&new_client_port, 0, sizeof (new_client_port));
00331
00332 new_client_port.errors = 0;
00333 new_client_port.max_errors = 2;
00334 new_client_port.last_write_id = -1;
00335 new_client_port.socket_fd = -1;
00336 new_client_port.address.sin_family = AF_INET;
00337 new_client_port.address.sin_addr.s_addr = dl_htonl (INADDR_ANY);
00338 new_client_port.address.sin_port = 0;
00339 new_client_port.socket_fd = dl_accept (connection_socket,
00340 (struct sockaddr *)
00341 &new_client_port.address,
00342 &client_address_length);
00343 clean_prev_read_info (new_client_port.socket_fd);
00344 if (new_client_port.socket_fd < 0)
00345 {
00346 rcs_print_error ("server: accept error %d -- %s\n", errno,
00347 strerror (errno));
00348 continue;
00349 }
00350 rcs_print_debug (PRINT_SOCKET_CONNECT,
00351 "Socket opened to host with IP address %s using connection %d.\n",
00352 dl_inet_ntoa (new_client_port.address.sin_addr),
00353 new_client_port.socket_fd);
00354 if (NULL != client_ports)
00355 {
00356 client_ports->store_at_tail (&new_client_port,
00357 sizeof (new_client_port), 1);
00358 }
00359 if (maxfdpl < new_client_port.socket_fd + 1)
00360 {
00361 maxfdpl = new_client_port.socket_fd + 1;
00362 }
00363 RCS_FD_SET (new_client_port.socket_fd, &read_fd_set);
00364 }
00365 else
00366 {
00367 RCS_FD_SET (connection_socket, &read_fd_set);
00368 }
00369 if (0 != ready_descriptors)
00370 {
00371 rcs_print_error ("%d descriptors ready but not serviced.\n",
00372 ready_descriptors);
00373 }
00374 int unfinished_cycles = 0;
00375 while (unfinished && unfinished_cycles < 10)
00376 {
00377 unfinished_cycles++;
00378 client_port_to_check =
00379 (CLIENT_STCP_PORT *) client_ports->get_head ();
00380 unfinished = 0;
00381 while (NULL != client_port_to_check)
00382 {
00383 #if defined(WIN32) && !defined(gnuwin32)
00384 dl_ioctlsocket (client_port_to_check->socket_fd, FIONREAD,
00385 &bytes_ready);
00386 #else
00387 #ifndef VXWORKS
00388 ioctl (client_port_to_check->socket_fd, FIONREAD,
00389 (caddr_t) & bytes_ready);
00390 #else
00391 ioctl (client_port_to_check->socket_fd, FIONREAD,
00392 (int) &bytes_ready);
00393 #endif
00394 #endif
00395 if (get_bytes_already_read (client_port_to_check->socket_fd) > 0
00396 || bytes_ready > 0)
00397 {
00398 handle_request (client_port_to_check);
00399 if (!handle_request_error_occured)
00400 {
00401 if (get_bytes_already_read
00402 (client_port_to_check->socket_fd) > 0)
00403 {
00404 unfinished = 1;
00405 }
00406 }
00407 }
00408 client_port_to_check =
00409 (CLIENT_STCP_PORT *) client_ports->get_next ();
00410 }
00411 }
00412 }
00413 }
00414
00415 void
00416 CMS_SERVER_REMOTE_STCP_PORT::handle_request (CLIENT_STCP_PORT *
00417 _client_stcp_port)
00418 {
00419 CLIENT_STCP_PORT *client_port_to_check;
00420 handle_request_error_occured = 0;
00421 #if defined(WIN32) && !defined(gnuwin32)
00422 DWORD pid = GetCurrentProcessId ();
00423 DWORD tid = GetCurrentThreadId ();
00424 #else
00425 #ifdef VXWORKS
00426 int pid = taskIdSelf ();
00427 int tid = 0;
00428 #else
00429 pid_t pid = getpid ();
00430 pid_t tid = 0;
00431 #endif
00432 #endif
00433 CMS_SERVER *server;
00434 server = find_server (pid, tid);
00435 if (NULL == server)
00436 {
00437 rcs_print_error
00438 ("Cannot find server object associated with this process/task ( %d (0x%X), %d (0x%X)).\n",
00439 pid, pid, tid, tid);
00440 print_servers ();
00441 return;
00442 }
00443
00444
00445 if (_client_stcp_port->errors >= _client_stcp_port->max_errors)
00446 {
00447 int temp_socket_fd = _client_stcp_port->socket_fd;
00448 rcs_print_error ("Too many errors - closing connection(%d)\n",
00449 _client_stcp_port->socket_fd);
00450 client_port_to_check = (CLIENT_STCP_PORT *) client_ports->get_head ();
00451 while (NULL != client_port_to_check)
00452 {
00453 if (client_port_to_check->socket_fd == temp_socket_fd)
00454 {
00455 client_ports->delete_current_node ();
00456 }
00457 client_port_to_check =
00458 (CLIENT_STCP_PORT *) client_ports->get_next ();
00459 }
00460 dl_closesocket (temp_socket_fd);
00461 RCS_FD_CLR (temp_socket_fd, &read_fd_set);
00462 handle_request_error_occured = 1;
00463 return;
00464 }
00465
00466 if (NULL == temp_buffer)
00467 {
00468 rcs_print_error ("temp_buffer is NULL");
00469 _client_stcp_port->errors++;
00470 handle_request_error_occured = 1;
00471 return;
00472 }
00473
00474 if (recvline
00475 (_client_stcp_port->socket_fd, temp_buffer, temp_buffer_size, 0, -1,
00476 NULL) < 0)
00477 {
00478 rcs_print_error ("Can not read from client port.\n");
00479 _client_stcp_port->errors++;
00480 handle_request_error_occured = 1;
00481 return;
00482 }
00483 if (server->using_passwd_file)
00484 {
00485 current_user_info = get_connected_user (_client_stcp_port->socket_fd);
00486 }
00487
00488 if (!strncmp (temp_buffer, "read", 4))
00489 {
00490 if (temp_buffer[4] == '(')
00491 {
00492 buffer_number = strtol (temp_buffer + 5, NULL, 0);
00493 }
00494 server->read_req.buffer_number = buffer_number;
00495 server->read_req.access_type = CMS_READ_ACCESS;
00496 server->read_req.last_id_read = _client_stcp_port->last_write_id;
00497 server->read_reply =
00498 (REMOTE_READ_REPLY *) server->process_request (&server->read_req);
00499 if (NULL == server->read_reply)
00500 {
00501 rcs_print_error ("Server could not process request.\n");
00502 sendline (_client_stcp_port->socket_fd,
00503 "ERR: -1 = Process Request Error", 0, 1.0);
00504 return;
00505 }
00506 _client_stcp_port->last_write_id = server->read_reply->write_id;
00507 if (server->read_reply->size > 0)
00508 {
00509 if (sendline
00510 (_client_stcp_port->socket_fd,
00511 (char *) server->read_reply->data, 0, -1) < 0)
00512 {
00513 _client_stcp_port->errors++;
00514 handle_request_error_occured = 1;
00515 return;
00516 }
00517 }
00518 else
00519 {
00520 sendline (_client_stcp_port->socket_fd, "ERR: 0 = No data.", 0,
00521 1.0);
00522 }
00523 }
00524 else if (!strncmp (temp_buffer, "peek", 4))
00525 {
00526 if (temp_buffer[4] == '(')
00527 {
00528 buffer_number = strtol (temp_buffer + 5, NULL, 0);
00529 }
00530 server->read_req.buffer_number = buffer_number;
00531 server->read_req.access_type = CMS_PEEK_ACCESS;
00532 server->read_req.last_id_read = _client_stcp_port->last_write_id;
00533 server->read_reply =
00534 (REMOTE_READ_REPLY *) server->process_request (&server->read_req);
00535 if (NULL == server->read_reply)
00536 {
00537 rcs_print_error ("Server could not process request.\n");
00538 sendline (_client_stcp_port->socket_fd,
00539 "ERR: -1 = Process Request Error", 0, 1.0);
00540 return;
00541 }
00542 _client_stcp_port->last_write_id = server->read_reply->write_id;
00543 if (server->read_reply->size > 0)
00544 {
00545 if (sendline
00546 (_client_stcp_port->socket_fd,
00547 (char *) server->read_reply->data, 0, -1) < 0)
00548 {
00549 _client_stcp_port->errors++;
00550 handle_request_error_occured = 1;
00551 return;
00552 }
00553 }
00554 else
00555 {
00556 sendline (_client_stcp_port->socket_fd, "ERR: 0 = No data", 0, 1.0);
00557 }
00558
00559 }
00560 else if (!strncmp (temp_buffer, "write_if_read", 13))
00561 {
00562 if (temp_buffer[13] == '(')
00563 {
00564 buffer_number = strtol (temp_buffer + 14, NULL, 0);
00565 }
00566 server->write_req.buffer_number = buffer_number;
00567 server->write_req.access_type = CMS_WRITE_IF_READ_ACCESS;
00568 char *write_if_read_data = strchr (temp_buffer, ':') + 1;
00569 server->write_req.size = strlen (write_if_read_data);
00570 strcpy ((char *) server->write_req.data, write_if_read_data);
00571 server->write_reply =
00572 (REMOTE_WRITE_REPLY *) server->process_request (&server->write_req);
00573 if (NULL == server->write_reply)
00574 {
00575 rcs_print_error ("Server could not process write request.\n");
00576 sendline (_client_stcp_port->socket_fd, "write_if_read_failed:1", 0,
00577 1.0);
00578 }
00579 else
00580 {
00581 if (server->write_reply->was_read)
00582 {
00583 sendline (_client_stcp_port->socket_fd,
00584 "write_if_read_succeeded:1", 0, 1.0);
00585 }
00586 else
00587 {
00588 sendline (_client_stcp_port->socket_fd,
00589 "write_if_read_succeeded:0", 0, 1.0);
00590 }
00591 }
00592 }
00593 else if (!strncmp (temp_buffer, "write", 5))
00594 {
00595 if (temp_buffer[5] == '(')
00596 {
00597 buffer_number = strtol (temp_buffer + 6, NULL, 0);
00598 }
00599 server->write_req.buffer_number = buffer_number;
00600 server->write_req.access_type = CMS_WRITE_ACCESS;
00601 char *write_data = strchr (temp_buffer, ':');
00602 if (NULL == write_data)
00603 {
00604 rcs_print_error ("Server could not process write request.\n");
00605 }
00606 else
00607 {
00608 write_data++;
00609 server->write_req.size = strlen (write_data);
00610 strcpy ((char *) server->write_req.data, write_data);
00611 server->write_reply =
00612 (REMOTE_WRITE_REPLY *) server->process_request (&server->
00613 write_req);
00614 if (NULL == server->write_reply)
00615 {
00616 rcs_print_error ("Server could not process write request.\n");
00617 }
00618 }
00619 }
00620 else if (!strncmp (temp_buffer, "check_if_read", 13))
00621 {
00622 if (temp_buffer[13] == '(')
00623 {
00624 buffer_number = strtol (temp_buffer + 14, NULL, 0);
00625 }
00626 server->check_if_read_req.buffer_number = buffer_number;
00627 server->check_if_read_reply = (REMOTE_CHECK_IF_READ_REPLY *)
00628 server->process_request (&server->check_if_read_req);
00629 if (NULL == server->check_if_read_reply)
00630 {
00631 rcs_print_error
00632 ("Server could not process check_if_read request.\n");
00633 sendline (_client_stcp_port->socket_fd, "check_if_read_failed", 0,
00634 1.0);
00635 }
00636 else
00637 {
00638 if (server->check_if_read_reply->was_read)
00639 {
00640 sendline (_client_stcp_port->socket_fd, "was_read", 0, 1.0);
00641 }
00642 else
00643 {
00644 sendline (_client_stcp_port->socket_fd, "not_read", 0, 1.0);
00645 }
00646 }
00647 }
00648 else if (!strncmp (temp_buffer, "get_keys", 8))
00649 {
00650 if (temp_buffer[9] == '(')
00651 {
00652 buffer_number = strtol (temp_buffer + 10, NULL, 0);
00653 }
00654 server->get_keys_req.buffer_number = buffer_number;
00655 char *get_keys_data = strchr (temp_buffer, ':') + 1;
00656 while (*get_keys_data == ' ')
00657 {
00658 get_keys_data++;
00659 }
00660 strncpy ((char *) server->get_keys_req.name, get_keys_data, 16);
00661 server->get_keys_reply =
00662 (REMOTE_GET_KEYS_REPLY *) server->process_request (&server->
00663 get_keys_req);
00664 if (NULL == server->get_keys_reply)
00665 {
00666 rcs_print_error ("Server could not process request.\n");
00667 memset (temp_buffer, 0, temp_buffer_size);
00668 server->gen_random_key (((char *) temp_buffer), 2);
00669 server->gen_random_key (((char *) temp_buffer) + 8, 2);
00670 if (temp_buffer_size < 64)
00671 {
00672 sendline (_client_stcp_port->socket_fd, "keys:sd:b8", 0, 1.0);
00673 }
00674 else
00675 {
00676 sprintf (((char *) temp_buffer) + 16, "keys:%s:%s",
00677 ((char *) temp_buffer), ((char *) temp_buffer) + 8);
00678 sendline (_client_stcp_port->socket_fd,
00679 ((char *) temp_buffer) + 16, 0, 1.0);
00680 }
00681 return;
00682 }
00683 sprintf (((char *) temp_buffer) + 16, "keys:%s:%s",
00684 server->get_keys_reply->key1, server->get_keys_reply->key2);
00685 sendline (_client_stcp_port->socket_fd, ((char *) temp_buffer) + 16, 0,
00686 1.0);
00687 return;
00688 }
00689 else if (!strncmp (temp_buffer, "login", 5))
00690 {
00691 if (temp_buffer[6] == '(')
00692 {
00693 buffer_number = strtol (temp_buffer + 7, NULL, 0);
00694 }
00695 server->login_req.buffer_number = buffer_number;
00696 char *login_data = NULL;
00697 login_data = strchr (temp_buffer, ':') + 1;
00698 if (NULL != login_data)
00699 {
00700 while (*login_data == ' ')
00701 {
00702 login_data++;
00703 }
00704 strncpy ((char *) server->login_req.name, login_data, 16);
00705 char *bad_char = strpbrk (server->login_req.name, "\r\n\t :");
00706 if (NULL != bad_char)
00707 {
00708 *bad_char = 0;
00709 }
00710 login_data = strchr (login_data, ':') + 1;
00711 while (*login_data == ' ')
00712 {
00713 login_data++;
00714 }
00715 strncpy ((char *) server->login_req.passwd, login_data, 16);
00716 bad_char = strpbrk (server->login_req.passwd, "\r\n\t :");
00717 if (NULL != bad_char)
00718 {
00719 *bad_char = 0;
00720 }
00721 server->login_reply =
00722 (REMOTE_LOGIN_REPLY *) server->process_request (&server->
00723 login_req);
00724 if (NULL == server->login_reply)
00725 {
00726 rcs_print_error ("Server could not process request.\n");
00727 sendline (_client_stcp_port->socket_fd, "login failed", 0, 1.0);
00728 return;
00729 }
00730 if (server->login_reply->success)
00731 {
00732 sendline (_client_stcp_port->socket_fd, "login succeeded", 0,
00733 1.0);
00734 return;
00735 }
00736 else
00737 {
00738 sendline (_client_stcp_port->socket_fd, "login failed", 0, 1.0);
00739 return;
00740 }
00741 }
00742 else
00743 {
00744 sendline (_client_stcp_port->socket_fd, "login failed", 0, 1.0);
00745 return;
00746 }
00747
00748 return;
00749 }
00750 }