diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-09-13 00:28:23 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-09-13 00:28:23 +0000 |
commit | 40c229c8bd507b8ad25125e75c5d477800273068 (patch) | |
tree | 0099758312186731c20a74437a2a888dfc8bb6d2 /apps/drwho | |
parent | b83d24d85a208c4ee539b428d3fc5e361bc2aeca (diff) | |
download | ATCD-40c229c8bd507b8ad25125e75c5d477800273068.tar.gz |
*** empty log message ***
Diffstat (limited to 'apps/drwho')
76 files changed, 1929 insertions, 1603 deletions
diff --git a/apps/drwho/BS_Client.cpp b/apps/drwho/BS_Client.cpp index 24626112402..ba4c4379c5d 100644 --- a/apps/drwho/BS_Client.cpp +++ b/apps/drwho/BS_Client.cpp @@ -1,7 +1,6 @@ // $Id$ #include "Options.h" -#include "new.h" #include "File_Manager.h" #include "BS_Client.h" diff --git a/apps/drwho/BS_Client.h b/apps/drwho/BS_Client.h index bab7cd2f76f..1c184501c62 100644 --- a/apps/drwho/BS_Client.h +++ b/apps/drwho/BS_Client.h @@ -9,9 +9,6 @@ // = FILENAME // BS_Client.h // -// = DESCRIPTION -// Provides the client's binary search lookup table abstraction. -// // = AUTHOR // Douglas C. Schmidt // diff --git a/apps/drwho/BS_Server.cpp b/apps/drwho/BS_Server.cpp index 16e344b7cb2..163f3026774 100644 --- a/apps/drwho/BS_Server.cpp +++ b/apps/drwho/BS_Server.cpp @@ -1,6 +1,6 @@ // $Id$ + #include "BS_Server.h" -#include "new.h" // This constructor takes a message of sorted login names and loads up // the symbol table on the server's side. It assumes that the number @@ -14,10 +14,11 @@ BS_Server::BS_Server (char *packet) this->count_ = atoi (packet); this->buffer_ = buf_ptr; - this->protocol_record_ = - new (PRIVATE_POOL) Protocol_Record[this->count_]; - this->sorted_record_ = - new (PRIVATE_POOL) Protocol_Record *[this->count_]; + + ACE_NEW (this->protocol_record_, + Protocol_Record[this->count_]); + ACE_NEW (this->sorted_record_, + Protocol_Record *[this->count_]); for (int i = 0; i < this->count_; i++) { @@ -83,7 +84,8 @@ BS_Server::insert (char *key_name, int max_len) } // This line is very subtle... ;-) - if (!(cmp == 0 || ACE_OS::strncmp (key_name, buffer[--mid]->get_login (), max_len) == 0)) + if (!(cmp == 0 + || ACE_OS::strncmp (key_name, buffer[--mid]->get_login (), max_len) == 0)) { result = 0; return 0; @@ -103,9 +105,9 @@ BS_Server::insert (char *key_name, int max_len) Protocol_Record * BS_Server::get_next_entry (void) { - Protocol_Record *frp; - - while ((frp = Binary_Search::get_next_entry ()) != 0) + for (Protocol_Record *frp = Binary_Search::get_next_entry (); + frp != 0; + frp = Binary_Search::get_next_entry ()) if (frp->get_drwho_list () != 0) return frp; diff --git a/apps/drwho/BS_Server.h b/apps/drwho/BS_Server.h index d821acc7cf5..5d7dfdb674c 100644 --- a/apps/drwho/BS_Server.h +++ b/apps/drwho/BS_Server.h @@ -23,9 +23,9 @@ #include "Binary_Search.h" class BS_Server : public Binary_Search +{ // = TITLE // Provides the server's binary search lookup table abstraction. -{ public: // = Initialization. BS_Server (char *packet); diff --git a/apps/drwho/Binary_Search.cpp b/apps/drwho/Binary_Search.cpp index 237ea882875..70fc9e84465 100644 --- a/apps/drwho/Binary_Search.cpp +++ b/apps/drwho/Binary_Search.cpp @@ -1,4 +1,5 @@ // $Id$ + #include "Options.h" #include "Binary_Search.h" @@ -6,7 +7,7 @@ // login names for two friends. int -Binary_Search::name_compare (void *s1, void *s2) +Binary_Search::name_compare (const void *s1, const void *s2) { return ACE_OS::strcmp ((*(Protocol_Record **) s1)->key_name1_, (*(Protocol_Record **) s2)->key_name1_); @@ -65,7 +66,8 @@ Binary_Search::get_each_entry (void) Binary_Search::~Binary_Search (void) { if (Options::get_opt (Options::DEBUG)) - ACE_DEBUG ((LM_DEBUG, "disposing Binary_Search\n")); + ACE_DEBUG ((LM_DEBUG, + "disposing Binary_Search\n")); } // Used to initialize the values for the iterators... diff --git a/apps/drwho/CM_Client.cpp b/apps/drwho/CM_Client.cpp index 88783288ec1..f7968a4b976 100644 --- a/apps/drwho/CM_Client.cpp +++ b/apps/drwho/CM_Client.cpp @@ -1,4 +1,5 @@ // $Id$ + #include "global.h" #include "Options.h" #include "Multicast_Manager.h" @@ -16,7 +17,9 @@ CM_Client::open (short port_number) if (Comm_Manager::sokfd == ACE_INVALID_HANDLE) return -1; - ACE_OS::memset ((char *) &this->sin, 0, sizeof this->sin); + ACE_OS::memset ((char *) &this->sin, + 0, + sizeof this->sin); this->sin.sin_family = AF_INET; this->sin.sin_port = htons (port_number); @@ -38,8 +41,10 @@ CM_Client::receive (int timeout) while (Multicast_Manager::outstanding_hosts_remain ()) { - if (ACE_OS:;select (Comm_Manager::sokfd + 1, - &this->read_fd_, 0, 0, + if (ACE_OS::select (Comm_Manager::sokfd + 1, + &this->read_fd_, + 0, + 0, this->top_) <= 0) break; else @@ -50,7 +55,6 @@ CM_Client::receive (int timeout) 0, (sockaddr *) &this->sin, &sin_len); - if (n < 0) return -1; else @@ -108,7 +112,12 @@ CM_Client::send (void) inet_ntoa (this->sin.sin_addr))); } - if (sendto (Comm_Manager::sokfd, this->send_packet, packet_length, 0, (sockaddr *) &this->sin, sizeof this->sin) < 0) + if (sendto (Comm_Manager::sokfd, + this->send_packet, + packet_length, + 0, + (sockaddr *) &this->sin, + sizeof this->sin) < 0) return -1; } return 1; @@ -122,7 +131,8 @@ CM_Client::CM_Client (void) CM_Client::~CM_Client (void) { if (Options::get_opt (Options::DEBUG)) - ACE_DEBUG ((LM_DEBUG, "disposing CM_Client\n")); + ACE_DEBUG ((LM_DEBUG, + "disposing CM_Client\n")); ACE_OS::closesocket (Comm_Manager::sokfd); } diff --git a/apps/drwho/CM_Client.h b/apps/drwho/CM_Client.h index 02c386d6e8d..30e58de5d52 100644 --- a/apps/drwho/CM_Client.h +++ b/apps/drwho/CM_Client.h @@ -21,7 +21,6 @@ #if defined (_CM_CLIENT_H) #define _CM_CLIENT_H -#include "ace/OS.h" #include "global.h" #include "Comm_Manager.h" @@ -29,7 +28,7 @@ class CM_Client : public Comm_Manager { // = TITLE // Provides a virtual communcations layer for the client in the - // drwho program. + // drwho program. public: // = Initialization and termination. CM_Client (void); diff --git a/apps/drwho/CM_Server.cpp b/apps/drwho/CM_Server.cpp index f9306553269..4fd30308af3 100644 --- a/apps/drwho/CM_Server.cpp +++ b/apps/drwho/CM_Server.cpp @@ -1,33 +1,38 @@ // $Id$ + #include "global.h" #include "Options.h" #include "CM_Server.h" -/* Creates and binds a UDP socket... */ +// Creates and binds a UDP socket... int CM_Server::open (short port_number) { int max_packet_size = UDP_PACKET_SIZE; - if ((this->sokfd = socket (PF_INET, SOCK_DGRAM, 0)) < 0) + this->sokfd = socket (PF_INET, SOCK_DGRAM, 0); + + if (this->sokfd < 0) return -1; - bzero (&this->sin, sizeof this->sin); - this->sin.sin_family = AF_INET; - this->sin.sin_port = htons (port_number); + ACE_OS::memset (&this->sin, sizeof this->sin, 0); + this->sin.sin_family = AF_INET; + this->sin.sin_port = htons (port_number); this->sin.sin_addr.s_addr = INADDR_ANY; - /* This call fails if an rflo daemon is already running. */ - if (bind (this->sokfd, (sockaddr *) &this->sin, sizeof this->sin) < 0) + // This call fails if an rflo daemon is already running. + if (ACE_OS::bind (this->sokfd, + (sockaddr *) &this->sin, + sizeof this->sin) < 0) return -1; -#ifndef i386 - /* Allow for very large datagrams. */ - - if (setsockopt (this->sokfd, SOL_SOCKET, SO_SNDBUF, (char *) &max_packet_size, sizeof max_packet_size) < 0) + if (ACE_OS::setsockopt (this->sokfd, + SOL_SOCKET, + SO_SNDBUF, + (char *) &max_packet_size, + sizeof max_packet_size) < 0) return -1; -#endif return 1; } @@ -35,18 +40,24 @@ CM_Server::open (short port_number) int CM_Server::receive (int) { - /* SUPPRESS 175 */ - int sin_len = sizeof this->sin; - int n; + int sin_len = sizeof this->sin; if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "waiting for client to send...\n"); - - if ((n = recvfrom (this->sokfd, this->recv_packet, UDP_PACKET_SIZE, 0, (sockaddr *) &this->sin, &sin_len)) < 0) + ACE_DEBUG ((LM_DEBUG, "waiting for client to send...\n")); + + ssize_t n = recvfrom (this->sokfd, + this->recv_packet, + UDP_PACKET_SIZE, + 0, + (sockaddr *) &this->sin, + &sin_len); + if (n == -1) return -1; if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "receiving from client host %s\n", inet_ntoa (this->sin.sin_addr)); + ACE_DEBUG ((LM_DEBUG, + "receiving from client host %s\n", + ACE_OS::inet_ntoa (this->sin.sin_addr))); if (this->demux (this->recv_packet, n) < 0) return -1; @@ -57,29 +68,37 @@ CM_Server::receive (int) int CM_Server::send (void) { - /* SUPPRESS 175 */ int packet_length = 0; - if (this->mux (this->send_packet, packet_length) < 0) + if (this->mux (this->send_packet, + packet_length) < 0) return -1; if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "sending to client host %s\n", inet_ntoa (this->sin.sin_addr)); - - if (sendto (this->sokfd, this->send_packet, packet_length, 0, (sockaddr *) &this->sin, sizeof this->sin) < 0) + ACE_DEBUG ((LM_DEBUG, + "sending to client host %s\n", + ACE_OS::inet_ntoa (this->sin.sin_addr))); + + if (sendto (this->sokfd, + this->send_packet, + packet_length, + 0, + (sockaddr *) &this->sin, + sizeof this->sin) < 0) return -1; return 1; } -#ifndef __OPTIMIZE__ CM_Server::CM_Server (void) -{} +{ +} CM_Server::~CM_Server (void) { if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "CM_Server\n"); - close (this->sokfd); + ACE_DEBUG ((LM_DEBUG, + "CM_Server\n")); + + ACE_OS::closesocket (this->sokfd); } -#endif /* __OPTIMIZE__ */ diff --git a/apps/drwho/CM_Server.h b/apps/drwho/CM_Server.h index db0cea2a33f..0e944db3064 100644 --- a/apps/drwho/CM_Server.h +++ b/apps/drwho/CM_Server.h @@ -1,22 +1,33 @@ /* -*- C++ -*- */ // $Id$ -/* Provides a virtual communcations layer for the server in the drwho - program. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// CM_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _CM_SERVER_H +#if !defined (_CM_SERVER_H) #define _CM_SERVER_H #include "Options.h" -#include "ace/OS.h" #include "global.h" #include "Comm_Manager.h" class CM_Server : public Comm_Manager { + // = TITLE + // Provides a virtual communcations layer for the server in drwho. public: - CM_Server (void); - virtual ~CM_Server (void); + CM_Server (void); + virtual ~CM_Server (void); virtual int open (short port_number); virtual int receive (int timeout = 0); @@ -25,17 +36,4 @@ public: virtual int demux (char *packet, int &packet_length) = 0; }; -#ifdef __OPTIMIZE__ -inline -CM_Server::CM_Server (void) -{} - -inline -CM_Server::~CM_Server (void) -{ - if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "CM_Server\n"); - close (this->sokfd); -} -#endif /* __OPTIMIZE__ */ -#endif _CM_SERVER_H +#endif /* _CM_SERVER_H */ diff --git a/apps/drwho/Comm_Manager.h b/apps/drwho/Comm_Manager.h index 98f33a28d39..21d44ec5f63 100644 --- a/apps/drwho/Comm_Manager.h +++ b/apps/drwho/Comm_Manager.h @@ -1,26 +1,39 @@ /* -*- C++ -*- */ // $Id$ -/* Provides a virtual communcations layer for the drwho program. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Comm_Manager.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _COMM_MANAGER_H +#if !defined (_COMM_MANAGER_H) #define _COMM_MANAGER_H -#include "ace/OS.h" #include "global.h" class Comm_Manager { + // = TITLE + // Provides a virtual communcations layer for the drwho program. protected: - char recv_packet[UDP_PACKET_SIZE]; - char send_packet[UDP_PACKET_SIZE]; + char recv_packet[UDP_PACKET_SIZE]; + char send_packet[UDP_PACKET_SIZE]; sockaddr_in sin; - int sokfd; + int sokfd; - virtual int mux (char *packet, int &packet_length) = 0; - virtual int demux (char *packet, int &packet_length) = 0; - virtual int open (short port_number) = 0; - virtual int receive (int timeout = 0) = 0; - virtual int send (void) = 0; + virtual int mux (char *packet, int &packet_length) = 0; + virtual int demux (char *packet, int &packet_length) = 0; + virtual int open (short port_number) = 0; + virtual int receive (int timeout = 0) = 0; + virtual int send (void) = 0; }; -#endif _COMM_MANAGER_H + +#endif /* _COMM_MANAGER_H */ diff --git a/apps/drwho/Drwho_Node.cpp b/apps/drwho/Drwho_Node.cpp index 7b3cb3867a5..93ac6f1d751 100644 --- a/apps/drwho/Drwho_Node.cpp +++ b/apps/drwho/Drwho_Node.cpp @@ -1,15 +1,23 @@ // $Id$ -#include "Drwho_Node.h" -#ifndef __OPTIMIZE__ -/* Create a Drwho_Node object */ +#include "Drwho_Node.h" Drwho_Node::Drwho_Node (char *h_name, Drwho_Node *n) - : next (n), inactive_count (0), active_count (0), key_name1 (h_name), key_name2 (0) + : next (n), + inactive_count (0), + active_count (0), + key_name1 (h_name), + key_name2 (0) {} Drwho_Node::Drwho_Node (void) - : next (0), inactive_count (0), active_count (0), key_name1 (0), tty_name (0), idle_time (0), key_name2 (0) + : next (0), + inactive_count (0), + active_count (0), + key_name1 (0), + tty_name (0), + idle_time (0), + key_name2 (0) {} char * @@ -57,7 +65,7 @@ Drwho_Node::get_active_count (void) int Drwho_Node::get_inactive_count (void) { - return this->active_count; + return this->inactive_count; } int @@ -73,9 +81,9 @@ Drwho_Node::set_inactive_count (int count) } int -Drwho_Node::set_idle_time (int it) +Drwho_Node::set_idle_time (int idle_time) { - return this->idle_time = it; + return this->idle_time = idle_time; } int @@ -83,5 +91,3 @@ Drwho_Node::get_idle_time (void) { return this->idle_time; } -#endif /* __OPTIMIZE__ */ - diff --git a/apps/drwho/Drwho_Node.h b/apps/drwho/Drwho_Node.h index e067525500d..c7395bf5e34 100644 --- a/apps/drwho/Drwho_Node.h +++ b/apps/drwho/Drwho_Node.h @@ -1,121 +1,52 @@ /* -*- C++ -*- */ // $Id$ -/* Stores information about a host for a specific friend. */ - -#ifndef _DRWHO_NODE_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Drwho_Node.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_DRWHO_NODE_H) #define _DRWHO_NODE_H -#include "ace/OS.h" #include "global.h" -struct Drwho_Node -{ - char *key_name1; - char *key_name2; - char *tty_name; - int idle_time; - int active_count; - int inactive_count; - Drwho_Node *next; - - Drwho_Node (char *host, Drwho_Node *next); - Drwho_Node (void); - int get_active_count (void); - int get_inactive_count (void); - int set_active_count (int count); - int set_inactive_count (int count); - int set_idle_time (int idle_time); - int get_idle_time (void); - char *get_host_name (void); - char *set_host_name (char *str); - char *get_login_name (void); - char *set_login_name (char *); - char *get_real_name (void); - char *set_real_name (char *); +class Drwho_Node +{ + // = TITLE + // Stores information about a host for a specific friend. +public: + Drwho_Node (char *host, Drwho_Node *next); + Drwho_Node (void); + + int get_active_count (void); + int get_inactive_count (void); + int set_active_count (int count); + int set_inactive_count (int count); + int set_idle_time (int idle_time); + int get_idle_time (void); + char *get_host_name (void); + char *set_host_name (char *str); + char *get_login_name (void); + char *set_login_name (char *); + char *get_real_name (void); + char *set_real_name (char *); + + char *key_name1; + char *key_name2; + char *tty_name; + int idle_time; + int active_count; + int inactive_count; + Drwho_Node *next; }; -#ifdef __OPTIMIZE__ -inline -Drwho_Node::Drwho_Node (char *h_name, Drwho_Node *n) - : next (n), inactive_count (0), active_count (0), key_name1 (h_name), key_name2 (0) -{} - -inline -Drwho_Node::Drwho_Node (void) - : next (0), inactive_count (0), active_count (0), key_name1 (0), tty_name (0), idle_time (0), key_name2 (0) -{} - -inline char * -Drwho_Node::get_login_name (void) -{ - return this->key_name1; -} - -inline char * -Drwho_Node::set_login_name (char *str) -{ - return this->key_name1 = str; -} - -inline char * -Drwho_Node::get_real_name (void) -{ - return this->key_name2; -} - -inline char * -Drwho_Node::set_real_name (char *str) -{ - return this->key_name2 = str; -} - -inline char * -Drwho_Node::get_host_name (void) -{ - return this->key_name1; -} - -inline char * -Drwho_Node::set_host_name (char *str) -{ - return this->key_name1 = str; -} - -inline int -Drwho_Node::get_active_count (void) -{ - return this->active_count; -} - -inline int -Drwho_Node::get_inactive_count (void) -{ - return this->inactive_count; -} - -inline int -Drwho_Node::set_active_count (int count) -{ - return this->active_count = count; -} - -inline int -Drwho_Node::set_inactive_count (int count) -{ - return this->inactive_count = count; -} - -inline int -Drwho_Node::set_idle_time (int idle_time) -{ - return this->idle_time = idle_time; -} - -inline int -Drwho_Node::get_idle_time (void) -{ - return this->idle_time; -} -#endif /* __OPTIMIZE__ */ #endif /* _DRWHO_NODE_H */ diff --git a/apps/drwho/File_Manager.cpp b/apps/drwho/File_Manager.cpp index c93b6398a50..f4426664242 100644 --- a/apps/drwho/File_Manager.cpp +++ b/apps/drwho/File_Manager.cpp @@ -1,29 +1,29 @@ // $Id$ -#include "global.h" -#include "ace/Mem_Map.h" + #include "File_Manager.h" +#include "ace/Mem_Map.h" -/* Initialize statics... */ +// Initialize statics... char *File_Manager::current_ptr = 0; -int File_Manager::number_of_friends = 0; -int File_Manager::max_key_length = 0; +int File_Manager::number_of_friends = 0; +int File_Manager::max_key_length = 0; char *File_Manager::buffer_ptr = 0; -int File_Manager::buffer_size = 0; +int File_Manager::buffer_size = 0; -/* Either opens the friends file (if FILE_NAME is not a NULL pointer) - or opens up the password file. In either case, the number of - entries in the file are returned, i.e., number of friends... */ +// Either opens the friends file (if FILE_NAME is not a NULL pointer) +// or opens up the password file. In either case, the number of +// entries in the file are returned, i.e., number of friends... int -File_Manager::open_file (char *file_name) +File_Manager::open_file (const char *file_name) { - return file_name == '\0' + return file_name == 0 ? File_Manager::open_passwd_file () : File_Manager::open_friends_file (file_name); } -/* Returns the next LOGIN_NAME and REAL_NAME from the file. */ +// Returns the next LOGIN_NAME and REAL_NAME from the file. int File_Manager::get_login_and_real_name (char *&login_name, char *&real_name) @@ -32,14 +32,14 @@ File_Manager::get_login_and_real_name (char *&login_name, char *&real_name) login_name = buf_ptr; - /* Skip to the end of the login name. */ + // Skip to the end of the login name. while (isalnum (*buf_ptr)) buf_ptr++; *buf_ptr++ = '\0'; - /* Now skip over white space to *start* of real name! */ + // Now skip over white space to *start* of real name! while (isspace (*buf_ptr) || *buf_ptr == '\0') buf_ptr++; @@ -47,14 +47,14 @@ File_Manager::get_login_and_real_name (char *&login_name, char *&real_name) real_name = buf_ptr; while (*buf_ptr++ != '\n') - ; + continue; - /* Clear the trailing blanks and junk. */ + // Clear the trailing blanks and junk. for (char *tmp_ptr = buf_ptr - 1; isspace (*tmp_ptr); tmp_ptr--) *tmp_ptr = '\0'; - /* Skip over consecutive blank lines. */ + // Skip over consecutive blank lines. while (*buf_ptr == '\n') buf_ptr++; @@ -63,21 +63,21 @@ File_Manager::get_login_and_real_name (char *&login_name, char *&real_name) return 1; } -/* Open up the yp passwd file and slurp all the users in! */ +// Open up the yp passwd file and slurp all the users in! int File_Manager::open_passwd_file (void) { - FILE *fp; - char *file_name; - struct passwd *pwent; - - file_name = tmpnam ((char *) 0); - - if ((fp = fopen (file_name, "w")) == 0) + const char *file_name = ACE_OS::tempnam (); + FILE *fp = fopen (file_name, "w"); + + if (fp == 0) return -1; - for (setpwent (); (pwent = getpwent ()) != 0; ) + passwd *pwent; + + for (ACE_OS::setpwent (); + (pwent = ACE_OS::getpwent ()) != 0; ) if (*pwent->pw_gecos != '\0') { char *cp = strchr (pwent->pw_gecos, ','); @@ -85,13 +85,16 @@ File_Manager::open_passwd_file (void) if (cp != 0) *cp = '\0'; - fprintf (fp, "%-8.8s %s\n", pwent->pw_name, pwent->pw_gecos); + ACE_OS::fprintf (fp, + "%-8.8s %s\n", + pwent->pw_name, + pwent->pw_gecos); File_Manager::number_of_friends++; } - endpwent (); + ACE_OS::endpwent (); - fclose (fp); + ACE_OS::fclose (fp); ACE_Mem_Map mmap (file_name); @@ -103,32 +106,35 @@ File_Manager::open_passwd_file (void) File_Manager::current_ptr = File_Manager::buffer_ptr; return File_Manager::number_of_friends; } + return -1; } -/* This function opens up FILE_NAME and memory maps it in our address space. */ +// This function opens up FILE_NAME and memory maps it in our address +// space. int -File_Manager::open_friends_file (char *file_name) +File_Manager::open_friends_file (const char *file_name) { - char *fnp = file_name; - int fd; + ACE_HANDLE fd; - /* Split file_name into directory/file_name. */ + char *fnp = ACE_OS::strrchr (file_name, '/'); - if ((fnp = strrchr (file_name, '/')) != 0) - fd = open (file_name, O_RDONLY); + // Split file_name into directory/file_name. + + if (fnp != 0) + fd = ACE_OS::open (file_name, O_RDONLY); else { char directory[MAXPATHLEN]; - strcpy (directory, getenv ("HOME")); - strcat (directory, "/"); - strcat (directory, file_name); - fd = open (directory, O_RDONLY); + ACE_OS::strcpy (directory, ACE_OS::getenv ("HOME")); + ACE_OS::strcat (directory, "/"); + ACE_OS::strcat (directory, file_name); + fd = ACE_OS::open (directory, O_RDONLY); } - /* Do the mmaping if we got the file opened correctly... */ + // Do the mmaping if we got the file opened correctly... if (fd < 0) return -1; @@ -142,7 +148,7 @@ File_Manager::open_friends_file (char *file_name) File_Manager::buffer_size = mmap.size (); File_Manager::current_ptr = File_Manager::buffer_ptr; - /* Determine how many friends there are by counting the newlines. */ + // Determine how many friends there are by counting the newlines. for (char *cp = File_Manager::buffer_ptr + File_Manager::buffer_size; cp > File_Manager::buffer_ptr @@ -155,8 +161,10 @@ File_Manager::open_friends_file (char *file_name) while (cp[-1] == '\n') --cp; } + return File_Manager::number_of_friends; } + return -1; } diff --git a/apps/drwho/File_Manager.h b/apps/drwho/File_Manager.h index 04dd2e2a099..d5826582ede 100644 --- a/apps/drwho/File_Manager.h +++ b/apps/drwho/File_Manager.h @@ -1,31 +1,43 @@ /* -*- C++ -*- */ // $Id$ -/* This module presents a file ADT for our friends info. */ - -#ifndef _FILE_MANAGER_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// File_Manager.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_FILE_MANAGER_H) #define _FILE_MANAGER_H -#include "ace/OS.h" +#include "global.h" class File_Manager { -private: - static int number_of_friends; - static int max_key_length; + // = TITLE + // This class provides a file ADT for our friends info. +public: + static int open_file (const char *filename); + static int get_login_and_real_name (char *&login_name, + char *&real_name); - static char *buffer_ptr; - static char *current_ptr; - static int buffer_size; +private: + static int number_of_friends; + static int max_key_length; - static int open_friends_file (char *filename); - static int open_passwd_file (void); + static char *buffer_ptr; + static char *current_ptr; + static int buffer_size; -public: - static int open_file (char *filename); - static int get_login_and_real_name (char *&login_name, char *&real_name); + static int open_friends_file (const char *filename); + static int open_passwd_file (void); }; -#ifdef __OPTIMIZE__ -#endif /* __OPTIMIZE__ */ #endif /* _FILE_MANAGER_H */ diff --git a/apps/drwho/HT_Client.cpp b/apps/drwho/HT_Client.cpp index b829f1e2a96..ff307195dba 100644 --- a/apps/drwho/HT_Client.cpp +++ b/apps/drwho/HT_Client.cpp @@ -1,26 +1,34 @@ // $Id$ -#include "new.h" + #include "HT_Client.h" -/* Insert a KEY_NAME into the hash table, if it doesn't already exist there. - What gets returned is a pointer to the node inserted. Note that we do our - own memory allocation here... */ +// Insert a KEY_NAME into the hash table, if it doesn't already exist +// there. What gets returned is a pointer to the node inserted. Note +// that we do our own memory allocation here... Protocol_Record * HT_Client::insert (char *key_name, int max_len) { - /* This is tricky... */ + Protocol_Record **frpp = 0; + + // This is tricky... - for (Protocol_Record **frpp = &this->hash_table[this->hash (key_name)]; - *frpp != 0 && strncmp ((*frpp)->get_login (), key_name, max_len) != 0; + for (frpp = &this->hash_table[ACE::hash_pjw (key_name)]; + *frpp != 0 + && ACE_OS::strncmp ((*frpp)->get_login (), + key_name, max_len) != 0; frpp = &(*frpp)->next) - ; + continue; if (*frpp == 0) { - *frpp = new (PRIVATE_POOL) Protocol_Record (ACE::strnew (key_name), *frpp); + ACE_NEW_RETURN (*frpp, + Protocol_Record (ACE::strnew (key_name), + *frpp), + 0); this->count++; } + return *frpp; } diff --git a/apps/drwho/HT_Client.h b/apps/drwho/HT_Client.h index 0831eb461bb..9e1512a0b80 100644 --- a/apps/drwho/HT_Client.h +++ b/apps/drwho/HT_Client.h @@ -1,16 +1,31 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's hash table abstraction. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// HT_Client.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _HT_CLIENT_H +#if !defined (_HT_CLIENT_H) #define _HT_CLIENT_H #include "Hash_Table.h" class HT_Client : public Hash_Table { + // = TITLE + // Provides the client's hash table abstraction. public: - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN); + virtual Protocol_Record *insert (char *key_name, + int max_len = MAXUSERIDNAMELEN); }; + #endif /* _HT_CLIENT_H */ diff --git a/apps/drwho/HT_Server.cpp b/apps/drwho/HT_Server.cpp index 6b8f0b9d6fe..cd1e0fe4489 100644 --- a/apps/drwho/HT_Server.cpp +++ b/apps/drwho/HT_Server.cpp @@ -1,29 +1,36 @@ // $Id$ -#include "new.h" + #include "HT_Server.h" -/* Insert a KEY_NAME into the hash table, if it doesn't already exist there. - What gets returned is a pointer to the node inserted. Note that we do our - own memory allocation here... */ +// Insert a KEY_NAME into the hash table, if it doesn't already exist +// there. What gets returned is a pointer to the node inserted. Note +// that we do our own memory allocation here... Protocol_Record * HT_Server::insert (char *key_name, int max_len) { - /* This is tricky... */ + Protocol_Record **frpp = 0; + + // This is tricky... - for (Protocol_Record **frpp = &this->hash_table[this->hash (key_name)]; + for (frpp = &this->hash_table[ACE::hash_pjw (key_name)]; *frpp != 0 && strncmp ((*frpp)->get_login (), key_name, max_len) != 0; frpp = &(*frpp)->next) - ; + continue; if (*frpp == 0) { - /* Remember, the server must be very careful about stuff it - receives from the rwho manager, since it may not be NUL-terminated. - That's why we use ACE::strnnew ()... */ + // Remember, the server must be very careful about stuff it + // receives from the rwho manager, since it may not be + // NUL-terminated. That's why we use ACE::strnnew ()... - *frpp = new (PRIVATE_POOL) Protocol_Record (ACE::strnnew (key_name, max_len), *frpp); + ACE_NEW_RETURN (*frpp, + Protocol_Record (ACE::strnnew (key_name, + max_len), + *frpp), + 0); this->count++; } + return *frpp; } diff --git a/apps/drwho/HT_Server.h b/apps/drwho/HT_Server.h index a5dc1987a78..777331efc33 100644 --- a/apps/drwho/HT_Server.h +++ b/apps/drwho/HT_Server.h @@ -1,16 +1,32 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the server's hash table abstraction. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// HT_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _HT_SERVER_H +#if !defined (_HT_SERVER_H) #define _HT_SERVER_H #include "Hash_Table.h" class HT_Server : public Hash_Table { + // = TITLE + // Provides the server's hash table abstraction. + public: - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN); + virtual Protocol_Record *insert (char *key_name, + int max_len = MAXUSERIDNAMELEN); }; + #endif /* _HT_SERVER_H */ diff --git a/apps/drwho/Hash_Table.cpp b/apps/drwho/Hash_Table.cpp index 15fb314370c..91f7d933ec5 100644 --- a/apps/drwho/Hash_Table.cpp +++ b/apps/drwho/Hash_Table.cpp @@ -1,45 +1,26 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "Hash_Table.h" -Hash_Table::Hash_Table (void): current_ptr (0), current_index (0), hash_table_size (HASH_TABLE_SIZE) +Hash_Table::Hash_Table (void) + : current_ptr (0), + current_index (0), + hash_table_size (HASH_TABLE_SIZE) { - this->hash_table = new (PRIVATE_POOL) Protocol_Record *[this->hash_table_size]; - + ACE_NEW (this->hash_table, + Protocol_Record *[this->hash_table_size]); ACE_OS::memset (this->hash_table, 0, this->hash_table_size * sizeof *this->hash_table); } -/* Hash using the "Hash PJW" algorithm. */ - -unsigned int -Hash_Table::hash (char *s) -{ - char *temp = s; - unsigned g; - unsigned hash = 0; - - for (int i = 0; i < MAXUSERIDNAMELEN && *temp != 0; i++) - { - hash = (hash << 4) + (*temp++ * 13); - if (g = hash & 0xf0000000) - { - hash ^= (g >> 24); - hash ^= g; - } - } - - return hash % this->hash_table_size; -} - -/* Iterate through the hash table returning one node at a time... */ +// Iterate through the hash table returning one node at a time... Protocol_Record * Hash_Table::get_next_entry (void) { - /* Reset the iterator if we are starting from the beginning. */ + // Reset the iterator if we are starting from the beginning. if (this->current_index == -1) this->current_index = 0; @@ -56,6 +37,7 @@ Hash_Table::get_next_entry (void) this->current_ptr = frp->next; return frp; } + this->current_index = -1; return 0; } @@ -73,18 +55,19 @@ Hash_Table::get_each_entry (void) return this->get_next_entry (); } -/* Frees up all the dynamic memory in the hash table. */ +// Frees up all the dynamic memory in the hash table. Hash_Table::~Hash_Table (void) { if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "disposing Hash_Table\n"); + ACE_DEBUG ((LM_DEBUG, + "disposing Hash_Table\n")); for (int i = 0; i < this->hash_table_size; i++) - for (Protocol_Record *frp = this->hash_table[i]; frp != 0; ) + for (Protocol_Record *frp = this->hash_table[i]; + frp != 0; ) { Protocol_Record *tmp = frp; - frp = frp->next; + frp = frp->next; } - } diff --git a/apps/drwho/Hash_Table.h b/apps/drwho/Hash_Table.h index 2df70290d31..327c55b74dd 100644 --- a/apps/drwho/Hash_Table.h +++ b/apps/drwho/Hash_Table.h @@ -1,30 +1,45 @@ /* -*- C++ -*- */ // $Id$ -/* Provides a hash function lookup abstraction for friend records. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// HT_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _HASH_TABLE_H +#if !defined (_HASH_TABLE_H) #define _HASH_TABLE_H #include "Search_Struct.h" class Hash_Table : public Search_Struct { -protected: - enum {HASH_TABLE_SIZE = 500}; - - Protocol_Record **hash_table; - Protocol_Record *current_ptr; - int current_index; - int hash_table_size; - - unsigned int hash (char *s); - + // = TITLE + // Provides a hash function lookup abstraction for friend records. public: - Hash_Table (void); - virtual ~Hash_Table (void); - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN) = 0; - virtual Protocol_Record *get_next_entry (void); + Hash_Table (void); + virtual ~Hash_Table (void); + virtual Protocol_Record *insert (const char *key_name, + int max_len = MAXUSERIDNAMELEN) = 0; + virtual Protocol_Record *get_next_entry (void); virtual Protocol_Record *get_each_entry (void); + +protected: + enum + { + HASH_TABLE_SIZE = 500 + }; + + Protocol_Record **hash_table; + Protocol_Record *current_ptr; + int current_index; + int hash_table_size; }; #endif /* _HASH_TABLE_H */ diff --git a/apps/drwho/Makefile b/apps/drwho/Makefile index ed75fe64512..9ad081d4dc8 100644 --- a/apps/drwho/Makefile +++ b/apps/drwho/Makefile @@ -18,8 +18,8 @@ SHARED-SRC = Protocol_Manager \ Hash_Table \ Binary_Search \ Search_Struct \ - Single_Lookup \ - new + Single_Lookup + SHARED-OBJ = $(addsuffix .o,$(SHARED-SRC)) CLIENT-SRC = PM_Client \ diff --git a/apps/drwho/Multicast_Manager.cpp b/apps/drwho/Multicast_Manager.cpp index 11a3b5a742f..51327a5917b 100644 --- a/apps/drwho/Multicast_Manager.cpp +++ b/apps/drwho/Multicast_Manager.cpp @@ -1,46 +1,36 @@ // $Id$ -#include "ACE_Mem_Map.h" -#include "new.h" + #include "Multicast_Manager.h" -#include "global.h" +#include "ACE_Mem_Map.h" // Initialize all the static member vars. -int Multicast_Manager::received_host_count = 0; -Multicast_Manager::Host_Elem *Multicast_Manager::drwho_list = 0; -Multicast_Manager::Host_Elem *Multicast_Manager::current_ptr = 0; +int Multicast_Manager::received_host_count = 0; +Multicast_Manager::Host_Elem *Multicast_Manager::drwho_list = 0; +Multicast_Manager::Host_Elem *Multicast_Manager::current_ptr = 0; -/* Names of hosts to query for friend info. */ +// Names of hosts to query for friend info. char *Multicast_Manager::host_names[] = { - "mabillon.ics.uci.edu", /* "128.195.14.4", */ - "beaver.ics.uci.edu", /* "128.195.2.1", */ - "convention.ics.uci.edu", /* "128.195.8.9", */ - "valentine.ics.uci.edu", /* "128.200.38.10", */ - "abp.ics.uci.edu", /* "128.200.39.23", */ - "cress.ics.uci.edu", /* "128.195.5.8", */ -#if 0 - "murphy.ics.uci.edu", /* "128.195.4.11", */ - "madeleine.ics.uci.edu", /* "128.200.32.2", */ - "liege.ics.uci.edu", /* "128.195.13.1", */ - "ics.uci.edu", /* "128.195.1.1", */ - "128.195.10.16", /* vlsi.ics.uci.edu */ -#endif - 0 /* The NULL entry... ;-) */ + "tango.cs.wustl.edu", + 0 // The NULL entry... }; void Multicast_Manager::insert_default_hosts (void) { - /* Enter the static list of hosts into the dynamic table! */ + // Enter the static list of hosts into the dynamic table! - for (char **np = host_names; *np != 0; np++) + for (char **np = host_names; + *np != 0; + np++) Multicast_Manager::add_host (*np); } -/* Inserts all the names in FILENAME into the list of hosts to contact. */ +// Inserts all the names in FILENAME into the list of hosts to +// contact. int -Multicast_Manager::insert_hosts_from_file (char *filename) +Multicast_Manager::insert_hosts_from_file (const char *filename) { ACE_Mem_Map mmap (filename); char *host_ptr = mmap.addr (); @@ -49,8 +39,9 @@ Multicast_Manager::insert_hosts_from_file (char *filename) return -1; else { - - for (char *end_ptr = host_ptr + mmap.size (); host_ptr < end_ptr; ) + for (char *end_ptr = host_ptr + mmap.size (); + host_ptr < end_ptr; + ) { Multicast_Manager::add_host (host_ptr); @@ -64,73 +55,86 @@ Multicast_Manager::insert_hosts_from_file (char *filename) } } -/* Returns the IP host address for the next unexamined host in the list. - If no more unexamined hosts remain a 0 is returned, else a 1. */ +// Returns the IP host address for the next unexamined host in the +// list. If no more unexamined hosts remain a 0 is returned, else a +// 1. int Multicast_Manager::get_next_host_addr (in_addr &host_addr) { for (Multicast_Manager::current_ptr = Multicast_Manager::current_ptr == 0 ? Multicast_Manager::drwho_list : Multicast_Manager::current_ptr->next; + Multicast_Manager::current_ptr != 0; Multicast_Manager::current_ptr = Multicast_Manager::current_ptr->next) - - { - hostent *hp; - char *host_name = Multicast_Manager::current_ptr->host_name; - - if ((hp = Multicast_Manager::get_host_entry (host_name)) == 0) - { - fprintf (stderr, "%s: host unknown.\n", host_name); - continue; - } - - Multicast_Manager::received_host_count++; - ACE_OS::memcpy (&host_addr, - hp->h_addr, - sizeof host_addr); - ACE_OS::memcpy (&Multicast_Manager::current_ptr->host_addr, - hp->h_addr, - sizeof host_addr); - return 1; - } + { + char *host_name = Multicast_Manager::current_ptr->host_name; + hostent *hp = Multicast_Manager::get_host_entry (host_name); + + if (hp == 0) + { + ACE_ERROR ((LM_ERROR, + "%s: host unknown.\n", + host_name)); + continue; + } + + Multicast_Manager::received_host_count++; + ACE_OS::memcpy (&host_addr, + hp->h_addr, + sizeof host_addr); + ACE_OS::memcpy (&Multicast_Manager::current_ptr->host_addr, + hp->h_addr, + sizeof host_addr); + return 1; + } return 0; } -/* This function attempts to get the internet address for either a - hostname or hostnumber. The function makes the simplifying - assumption that hostnames begin with an alphabetic character! */ +// This function attempts to get the internet address for either a +// hostname or hostnumber. The function makes the simplifying +// assumption that hostnames begin with an alphabetic character! hostent * -Multicast_Manager::get_host_entry (char *host) +Multicast_Manager::get_host_entry (const char *host) { static hostent host_entry; - auto hostent *hp; + hostent *hp; - if (isdigit (*host)) /* IP address. */ + if (isdigit (*host)) // IP address. { - unsigned long ia = inet_addr (host); - - hp = ia == (unsigned long) -1 ? 0 : gethostbyaddr ((char *) &ia, sizeof ia, AF_INET); + u_long ia = ACE_OS::inet_addr (host); + + if (ia == (u_long) -1) + hp = 0; + else + hp = ACE_OS::gethostbyaddr ((char *) &ia, + sizeof ia, + AF_INET); } - else /* Host name. */ - hp = gethostbyname (host); + else + // Host name. + hp = ACE_OS::gethostbyname (host); + return hp == 0 ? 0 : (hostent *) memcpy (&host_entry, hp, sizeof *hp); } -/* Adds an additional new host to the list of host machines. */ +// Adds an additional new host to the list of host machines. void -Multicast_Manager::add_host (char *host_name) +Multicast_Manager::add_host (const char *host_name) { - Multicast_Manager::drwho_list = new (PRIVATE_POOL) Host_Elem (host_name, Multicast_Manager::drwho_list); + ACE_NEW (Multicast_Manager::drwho_list, + Host_Elem (host_name, Multicast_Manager::drwho_list)); } void Multicast_Manager::checkoff_host (in_addr host_addr) { - for (Host_Elem *tmp = Multicast_Manager::drwho_list; tmp != 0; tmp = tmp->next) + for (Host_Elem *tmp = Multicast_Manager::drwho_list; + tmp != 0; + tmp = tmp->next) if (ACE_OS::memcmp (&tmp->host_addr.s_addr, &host_addr.s_addr, sizeof host_addr.s_addr) == 0) @@ -147,7 +151,7 @@ Multicast_Manager::get_next_non_responding_host (char *&host_name) for (Multicast_Manager::current_ptr = Multicast_Manager::current_ptr == 0 ? Multicast_Manager::drwho_list : Multicast_Manager::current_ptr->next; Multicast_Manager::current_ptr != 0; Multicast_Manager::current_ptr = Multicast_Manager::current_ptr->next) - if (!Multicast_Manager::current_ptr->checked_off) + if (Multicast_Manager::current_ptr->checked_off == 0) { host_name = Multicast_Manager::current_ptr->host_name; return 1; @@ -156,9 +160,11 @@ Multicast_Manager::get_next_non_responding_host (char *&host_name) return 0; } -#if !defined (__OPTIMIZE__) -Multicast_Manager::Host_Elem::Host_Elem (char *h_name, Multicast_Manager::Host_Elem *n) -: host_name (h_name), checked_off (0), next (n) +Multicast_Manager::Host_Elem::Host_Elem (const char *h_name, + Multicast_Manager::Host_Elem *n) + : host_name (h_name), + checked_off (0), + next (n) { } @@ -167,4 +173,4 @@ Multicast_Manager::outstanding_hosts_remain (void) { return Multicast_Manager::received_host_count > 0; } -#endif /* __OPTIMIZE__ */ + diff --git a/apps/drwho/Multicast_Manager.h b/apps/drwho/Multicast_Manager.h index e0b97de488a..0215d1ad1e5 100644 --- a/apps/drwho/Multicast_Manager.h +++ b/apps/drwho/Multicast_Manager.h @@ -1,13 +1,23 @@ /* -*- C++ -*- */ // $Id$ -/* This file handles all the operations upon host machines names - and addresses. */ - -#ifndef _HOST_MANAGER_H -#define _HOST_MANAGER_H - -#include "ace/OS.h" +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Multicast_Manager.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_MULTICAST_MANAGER_H) +#define _MULTICAST_MANAGER_H + +#include "global.h" struct Host_Elem { @@ -21,35 +31,25 @@ struct Host_Elem class Multicast_Manager { + // = TITLE + // This file handles all the operations upon host machines names + // and addresses. public: - static void add_host (char *host_name); - static void checkoff_host (in_addr host_addr); - static int get_next_host_addr (in_addr &host_addr); - static int outstanding_hosts_remain (void); - static int get_next_non_responding_host (char *&host_name); - static int insert_hosts_from_file (char *filename); - static void insert_default_hosts (void); + static void add_host (const char *host_name); + static void checkoff_host (in_addr host_addr); + static int get_next_host_addr (in_addr &host_addr); + static int outstanding_hosts_remain (void); + static int get_next_non_responding_host (char *&host_name); + static int insert_hosts_from_file (char *filename); + static void insert_default_hosts (void); private: - static hostent *get_host_entry (char *host); + static hostent *get_host_entry (const char *host); - static int received_host_count; - static char *host_names[]; - static Host_Elem *drwho_list; - static Host_Elem *current_ptr; + static int received_host_count; + static char *host_names[]; + static Host_Elem *drwho_list; + static Host_Elem *current_ptr; }; -#ifdef __OPTIMIZE__ -inline -Multicast_Manager::Host_Elem::Host_Elem (char *h_name, Multicast_Manager::Host_Elem *n) - : host_name (h_name), checked_off (0), next (n) -{ -} - -inline int -Multicast_Manager::outstanding_hosts_remain (void) -{ - return Multicast_Manager::received_host_count > 0; -} -#endif /* __OPTIMIZE__ */ -#endif /* _HOST_MANAGER_H */ +#endif /* _MULTICAST_MANAGER_H */ diff --git a/apps/drwho/Options.cpp b/apps/drwho/Options.cpp index bb102b3f6b1..aff066c72ad 100644 --- a/apps/drwho/Options.cpp +++ b/apps/drwho/Options.cpp @@ -1,63 +1,64 @@ // $Id$ + #include "global.h" -#include "new.h" #include "Multicast_Manager.h" #include "ace/Get_Opt.h" #include "Options.h" -/* Initialize all the static variables. */ +// Initialize all the static variables. -/* Contains bit-mask for options. */ -unsigned int Options::option_word = 0; +// Contains bit-mask for options. +u_int Options::option_word = 0; -/* Which protocol are we using? */ +// Which protocol are we using? Options::Protocol_Types Options::protocol_type = Options::PROTO_FLO; -/* User name for quick lookups. */ +// User name for quick lookups. char *Options::user_name = 0; -/* Port number for client/server. */ +// Port number for client/server. short Options::port_number = PORT_NUMBER; -/* Maximum time the client waits for servers to timeout. */ +// Maximum time the client waits for servers to timeout. int Options::max_server_timeout = 5; -/* Name of the program. */ +// Name of the program. char *Options::program_name; -/* Default name of file that stores friend info. */ +// Default name of file that stores friend info. char *Options::friend_file = FRIEND_FILE; void Options::print_usage_and_die (int long_msg) { - fprintf (stderr, "usage: %s %s", program_name, - long_msg - ? "\n" - "-?\tprints a short usage message\n" - "-A\tappend the following hostname to the list of predefined hostnames.\n" - "-a\treturn information on *all* users remotely logged in (uses yp passwd).\n" - "-b\trun the server in the background (i.e., as a daemon).\n" - "-d\tturn on debugging.\n" - "-F\tuse the following file contents to initialize the host list.\n" - "-f\tuse the following file contents to initialize the friends database.\n" - "-H\tuse the following hostname as part of the new list of hostnames.\n" - "\t(this option overwrites the existing default names).\n" - "-h\tprint a long usage message.\n" - "-L\tprint the login name rather than the real name (which is the default).\n" - "-l\tprint information in long format (works for all protocols).\n" - "-p\tset the port number (server must correspond).\n" - "-r\tdo the remote lookups (i.e., local operations are the default).\n" - "-R\tprint info using the rusers format.\n" - "-s\tsort the output by login name.\n" - "-S\tsort the output by real name.\n" - "-t\tset the amount of time we wait for servers to timeout.\n" - "-w\treturn information on just one user.\n" - : "[-?haAbdfFHhLlpRrtw]\n"); - exit (1); + ACE_DEBUG ((LM_DEBUG, + "usage: %s %s", + program_name, + long_msg + ? "\n" + "-?\tprints a short usage message\n" + "-A\tappend the following hostname to the list of predefined hostnames.\n" + "-a\treturn information on *all* users remotely logged in (uses yp passwd).\n" + "-b\trun the server in the background (i.e., as a daemon).\n" + "-d\tturn on debugging.\n" + "-F\tuse the following file contents to initialize the host list.\n" + "-f\tuse the following file contents to initialize the friends database.\n" + "-H\tuse the following hostname as part of the new list of hostnames.\n" + "\t(this option overwrites the existing default names).\n" + "-h\tprint a long usage message.\n" + "-L\tprint the login name rather than the real name (which is the default).\n" + "-l\tprint information in long format (works for all protocols).\n" + "-p\tset the port number (server must correspond).\n" + "-r\tdo the remote lookups (i.e., local operations are the default).\n" + "-R\tprint info using the rusers format.\n" + "-s\tsort the output by login name.\n" + "-S\tsort the output by real name.\n" + "-t\tset the amount of time we wait for servers to timeout.\n" + "-w\treturn information on just one user.\n" + : "[-?haAbdfFHhLlpRrtw]\n")); + ACE_OS::exit (1); } -#ifndef __OPTIMIZE__ void Options::set_opt (Option_Types opt) { @@ -69,7 +70,6 @@ Options::get_opt (Option_Types opt) { return (Options::option_word & opt) != 0; } -#endif /* __OPTIMIZE__ */ void Options::set_options (int argc, char *argv[]) @@ -104,7 +104,10 @@ Options::set_options (int argc, char *argv[]) break; case 'F': if (Multicast_Manager::insert_hosts_from_file (getopt.optarg) < 0) - perror (Options::program_name), exit (1); + ACE_DEBUG ((LM_DEBUG, + "%p%a\n", + Options::program_name, + 1)); add_default_hosts = 0; break; case 'H': @@ -139,7 +142,7 @@ Options::set_options (int argc, char *argv[]) Options::max_server_timeout = atoi (getopt.optarg); break; case 'w': - Options::user_name = getopt.optarg; + Options::user_name = getopt.optarg; Options::protocol_type = PROTO_USR; break; default: diff --git a/apps/drwho/Options.h b/apps/drwho/Options.h index 1d9153cc974..f94e0e61936 100644 --- a/apps/drwho/Options.h +++ b/apps/drwho/Options.h @@ -1,71 +1,64 @@ /* -*- C++ -*- */ // $Id$ -/* This file is used to provide a consolidated Options.handling facility. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Options.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _OPTIONS_H +#if !defined (_OPTIONS_H) #define _OPTIONS_H -/* Silly macros for handling message types. */ -#define GET_PACKET_TYPE(P) (ntohs (*((short *) P))) -#define SET_PACKET_TYPE(P,T) ((*(short *) P) = ntohs (T)) -#define SKIP_PACKET_TYPE(P) ((P) + sizeof (short)) -#define SUBTRACT_PACKET_TYPE(L) ((L) - sizeof (short)) - class Options { - static void print_usage_and_die (int long_msg); - static unsigned int option_word; - + // = TITLE + // This file is used to provide a consolidated Options handling facility. public: enum Option_Types - { - REMOTE_USAGE = 01, - PRINT_LOGIN_NAME = 02, - DEBUG = 04, - STAND_ALONE_SERVER = 010, - SORT_BY_LOGIN_NAME = 020, - SORT_BY_REAL_NAME = 040, - USE_VERBOSE_FORMAT = 0100, - BE_A_DAEMON = 0200 - }; + { + REMOTE_USAGE = 01, + PRINT_LOGIN_NAME = 02, + DEBUG = 04, + STAND_ALONE_SERVER = 010, + SORT_BY_LOGIN_NAME = 020, + SORT_BY_REAL_NAME = 040, + USE_VERBOSE_FORMAT = 0100, + BE_A_DAEMON = 0200 + }; - /* Different types of messages. */ + // Different types of messages. enum Protocol_Types - { - PROTO_USR = 1, /* Only return info on one user. */ - PROTO_ALL = 2, /* Return info on all users logged in around the system. */ - PROTO_FLO = 3, /* Return info on friends logged in. */ - PROTO_RUSER = 4, /* Return info in ruser format! */ - - PROTO_RWHO = 5, /* Return info in rwho format. */ - PROTO_WHO = 6, /* Return info in who format. */ - PROTO_RUPTIME = 7 /* Return info in ruptime format. */ - }; + { + PROTO_USR = 1, // Only return info on one user. + PROTO_ALL = 2, // Return info on all users logged in around the system. + PROTO_FLO = 3, // Return info on friends logged in. + PROTO_RUSER = 4, // Return info in ruser format! + PROTO_RWHO = 5, // Return info in rwho format. + PROTO_WHO = 6, // Return info in who format. + PROTO_RUPTIME = 7 // Return info in ruptime format. + }; - static void set_options (int argc, char *argv[]); - static void set_opt (Option_Types opt); - static int get_opt (Option_Types opt); + static void set_options (int argc, char *argv[]); + static void set_opt (Option_Types opt); + static int get_opt (Option_Types opt); - static short port_number; + static short port_number; static Protocol_Types protocol_type; - static int max_server_timeout; - static char *program_name; - static char *friend_file; - static char *user_name; -}; + static int max_server_timeout; + static char *program_name; + static char *friend_file; + static char *user_name; -#ifdef __OPTIMIZE__ -inline void -Options::set_opt (Option_Types opt) -{ - Options::option_word |= opt; -} + static void print_usage_and_die (int long_msg); + static u_int option_word; +}; -inline int -Options::get_opt (Option_Types opt) -{ - return Options::option_word & opt; -} -#endif /* __OPTIMIZE__ */ -#endif /* _OPTIONS_H */ +#endif /* _OPTIONS_H */ diff --git a/apps/drwho/PMC_All.cpp b/apps/drwho/PMC_All.cpp index 9758c6c0625..5041adb8aea 100644 --- a/apps/drwho/PMC_All.cpp +++ b/apps/drwho/PMC_All.cpp @@ -1,20 +1,23 @@ // $Id$ + #include "global.h" -#include "new.h" #include "Options.h" #include "HT_Client.h" #include "PMC_All.h" -/* This function is pretty much a no-op that just sets up the appropriate - lookup function to use. */ +// This function is pretty much a no-op that just sets up the +// appropriate lookup function to use. int PMC_All::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMC_All::encode\n"); + ACE_DEBUG ((LM_DEBUG, + "in PMC_All::encode\n")); - this->ss = new (PRIVATE_POOL) HT_Client; + ACE_NEW_RETURN (this->ss, + HT_Client, + -1); SET_PACKET_TYPE (packet, Options::PROTO_ALL); @@ -24,37 +27,42 @@ PMC_All::encode (char *packet, int &packet_length) return 1; } -/* This method is responsible for transforming the msg from the server - back into a form usable by the client. Note that it reads the REAL_NAME - from the packet (since the server placed it there)... */ +// This method is responsible for transforming the msg from the server +// back into a form usable by the client. Note that it reads the +// REAL_NAME from the packet (since the server placed it there)... int PMC_All::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, "in PMC_All::decode, packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "in PMC_All::decode, packet_length = %d\n", + packet_length)); + + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUB ((LM_DEBUG, "\n")); } - char *cp = packet; - int remote_users = 0; + char *cp = packet; + int remote_users = 0; - sscanf (cp, "Users %d", &remote_users); + sscanf (cp, + "Users %d", + &remote_users); this->increment_total_users (remote_users); for (cp = ACE::strend (cp); *cp != '\n'; cp++) { - /* Skip over the LOGIN_NAME. */ + // Skip over the LOGIN_NAME. char *login_name = cp; char *real_name = cp = ACE::strend (cp); for (cp = ACE::strend (cp); - *(cp = this->handle_protocol_entries (cp, login_name, real_name)) != '\t' - ;) - ; + *(cp = this->handle_protocol_entries (cp, login_name, real_name)) != '\t'; + ) + continue; } return 1; @@ -63,8 +71,8 @@ PMC_All::decode (char *packet, int &packet_length) Protocol_Record * PMC_All::insert_protocol_info (Protocol_Record &protocol_record) { - Protocol_Record *frp = PM_Client::insert_protocol_info (protocol_record); - int length = strlen (frp->set_real (ACE::strnew (protocol_record.get_real ()))); + Protocol_Record *frp = PM_Client::insert_protocol_info (protocol_record); + int length = ACE_OS::strlen (frp->set_real (ACE::strnew (protocol_record.get_real ()))); if (length > this->max_key_length) this->max_key_length = length; @@ -75,11 +83,11 @@ PMC_All::insert_protocol_info (Protocol_Record &protocol_record) void PMC_All::process (void) { - printf ("remote users logged on\n"); + ACE_DEBUG ((LM_DEBUG, + "remote users logged on\n")); PM_Client::process (); } -#ifndef __OPTIMIZE__ PMC_All::PMC_All (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PMC_All.h b/apps/drwho/PMC_All.h index 0fd2a1e6192..6f7578b492a 100644 --- a/apps/drwho/PMC_All.h +++ b/apps/drwho/PMC_All.h @@ -1,28 +1,37 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's lookup table abstraction for `all' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMC_All.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMC_ALL_H -#define _FMC_ALL_H +#if !defined (_PMC_ALL_H) +#define _PMC_ALL_H #include "PM_Client.h" class PMC_All : public PM_Client { + // = TITLE + // Provides the client's lookup table abstraction for `all' users... + protected: - Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); public: - PMC_All (void); - virtual void process (void); + PMC_All (void); + virtual void process (void); }; -#ifdef __OPTIMIZE__ -inline -PMC_All::PMC_All (void) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMC_ALL_H */ +#endif /* _PMC_ALL_H */ diff --git a/apps/drwho/PMC_Flo.cpp b/apps/drwho/PMC_Flo.cpp index 13dd5206934..5104d58a588 100644 --- a/apps/drwho/PMC_Flo.cpp +++ b/apps/drwho/PMC_Flo.cpp @@ -1,74 +1,95 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "BS_Client.h" #include "PMC_Flo.h" -/* This function "encodes" a list of friends by putting the userid's in - a contiguous block. This block can then be transmitted over to the - network to servers on other subnets. Several things are added to - make decoding easier on the other end: - - * A count of the number of friends is prepended (assumption: there - are no more than 9999999 friends... ;-)) - * The login userids are separated by a single space. */ +// This function "encodes" a list of friends by putting the userid's +// in a contiguous block. This block can then be transmitted over to +// the network to servers on other subnets. Several things are added +// to make decoding easier on the other end: +// +// * A count of the number of friends is prepended (assumption: there +// are no more than 9999999 friends... ;-)) +// * The login userids are separated by a single space. */ int PMC_Flo::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMC_Flo::encode"); + ACE_DEBUG ((LM_DEBUG, + "in PMC_Flo::encode")); - this->ss = new (PRIVATE_POOL) BS_Client; + ACE_NEW_RETURN (this->ss, + BS_Client, + -1); SET_PACKET_TYPE (packet, Options::PROTO_FLO); - char *buf_ptr = SKIP_PACKET_TYPE (packet); + char *buf_ptr = SKIP_PACKET_TYPE (packet); - sprintf (buf_ptr, "%d", this->friend_count ()); + sprintf (buf_ptr, + "%d", + this->friend_count ()); buf_ptr += MAXUSERIDNAMELEN; - - /* Loop through all the friends, copying them into the packet buffer. */ + + // Iterate through all the friends, copying them into the packet + // buffer. for (Protocol_Record *frp; (frp = this->get_next_friend ()) != 0; ) - buf_ptr = ACE::strecpy (buf_ptr, frp->get_login ()); + buf_ptr = ACE::strecpy (buf_ptr, + frp->get_login ()); packet_length = buf_ptr - packet; if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, ", packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } + return 1; } -/* This method is responsible for transforming the msg from the server - back into a form usable by the client. */ +// This method is responsible for transforming the msg from the server +// back into a form usable by the client. int PMC_Flo::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, "in PMC_Flo::decode, packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "in PMC_Flo::decode, packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } - char *cp = packet; - int remote_users = 0; - sscanf (cp, "Users %d", &remote_users); + char *cp = packet; + int remote_users = 0; + + sscanf (cp, + "Users %d", + &remote_users); this->increment_total_users (remote_users); - for (cp = ACE::strend (cp); *cp != '\n'; cp++) + for (cp = ACE::strend (cp); + *cp != '\n'; + cp++) { char *login_name = cp; - for (cp = ACE::strend (cp); *(cp = this->handle_protocol_entries (cp, login_name)) != '\t'; ) - ; + for (cp = ACE::strend (cp); + *(cp = this->handle_protocol_entries (cp, login_name)) != '\t'; +) + continue; } return 1; @@ -77,8 +98,8 @@ PMC_Flo::decode (char *packet, int &packet_length) Protocol_Record * PMC_Flo::insert_protocol_info (Protocol_Record &protocol_record) { - Protocol_Record *frp = PM_Client::insert_protocol_info (protocol_record); - int length = strlen (frp->get_real ()); + Protocol_Record *frp = PM_Client::insert_protocol_info (protocol_record); + int length = strlen (frp->get_real ()); if (length > this->max_key_length) this->max_key_length = length; @@ -89,11 +110,11 @@ PMC_Flo::insert_protocol_info (Protocol_Record &protocol_record) void PMC_Flo::process (void) { - printf ("remote friends logged on\n"); + ACE_DEBUG ((LM_DEBUG, + "remote friends logged on\n")); PM_Client::process (); } -#ifndef __OPTIMIZE__ PMC_Flo::PMC_Flo (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PMC_Flo.h b/apps/drwho/PMC_Flo.h index 06ef2295495..88f534023be 100644 --- a/apps/drwho/PMC_Flo.h +++ b/apps/drwho/PMC_Flo.h @@ -1,28 +1,37 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's lookup table abstraction for `flo' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMC_Flo.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMC_FLO_H -#define _FMC_FLO_H +#if !defined (_PMC_FLO_H) +#define _PMC_FLO_H #include "PM_Client.h" class PMC_Flo : public PM_Client { -protected: - virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); + // = TITLE + // Provides the client's lookup table abstraction for `flo' users... public: - PMC_Flo (void); - virtual void process (void); + PMC_Flo (void); + virtual void process (void); + +protected: + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); }; -#ifdef __OPTIMIZE__ -inline -PMC_Flo::PMC_Flo (void) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMC_FLO_H */ +#endif /* _PMC_FLO_H */ diff --git a/apps/drwho/PMC_Ruser.cpp b/apps/drwho/PMC_Ruser.cpp index de71941f940..7f13b23728c 100644 --- a/apps/drwho/PMC_Ruser.cpp +++ b/apps/drwho/PMC_Ruser.cpp @@ -1,20 +1,23 @@ // $Id$ + #include "global.h" -#include "new.h" #include "Options.h" #include "HT_Client.h" #include "PMC_Ruser.h" -/* This function is pretty much a no-op that just sets up the appropriate - lookup function to use. */ +// This function is pretty much a no-op that just sets up the +// appropriate lookup function to use. int PMC_Ruser::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMC_Ruser::encode\n"); + ACE_DEBUG ((LM_DEBUG, + "in PMC_Ruser::encode\n")); - this->ss = new (PRIVATE_POOL) HT_Client; + ACE_NEW_RETURN (this->ss, + HT_Client, + -1); SET_PACKET_TYPE (packet, Options::PROTO_RUSER); @@ -26,32 +29,40 @@ PMC_Ruser::encode (char *packet, int &packet_length) return 1; } -/* This method is responsible for transforming the msg from the server - back into a form usable by the client. Note that it reads the REAL_NAME - from the packet (since the server placed it there)... */ +// This method is responsible for transforming the msg from the server +// back into a form usable by the client. Note that it reads the +// REAL_NAME from the packet (since the server placed it there)... int PMC_Ruser::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, "in PMC_Ruser::decode, packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "in PMC_Ruser::decode, packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } - char *cp = packet; - int remote_users = 0; + char *cp = packet; + int remote_users = 0; - sscanf (cp, "Users %d", &remote_users); + sscanf (cp, + "Users %d", + &remote_users); this->increment_total_users (remote_users); - for (cp = ACE::strend (cp); *cp != '\n'; cp++) + for (cp = ACE::strend (cp); + *cp != '\n'; + cp++) { char *host_name = cp; - for (cp = ACE::strend (cp); *(cp = this->handle_protocol_entries (cp, host_name)) != '\t'; ) - ; + for (cp = ACE::strend (cp); + *(cp = this->handle_protocol_entries (cp, host_name)) != '\t'; ) + continue; } return 1; @@ -60,10 +71,13 @@ PMC_Ruser::decode (char *packet, int &packet_length) Protocol_Record * PMC_Ruser::insert_protocol_info (Protocol_Record &protocol_record) { - Protocol_Record *frp = this->ss->insert (protocol_record.get_host (), MAXHOSTNAMELEN); - Drwho_Node *current_node = protocol_record.get_drwho_list (); - Drwho_Node *np = this->get_drwho_node (ACE::strnnew (current_node->get_login_name (), MAXUSERIDNAMELEN), frp->drwho_list); - int length = strlen (frp->get_host ()); + Protocol_Record *frp = this->ss->insert (protocol_record.get_host (), + MAXHOSTNAMELEN); + Drwho_Node *current_node = protocol_record.get_drwho_list (); + Drwho_Node *np = this->get_drwho_node (ACE::strnnew (current_node->get_login_name (), + MAXUSERIDNAMELEN), + frp->drwho_list); + int length = ACE_OS::strlen (frp->get_host ()); np->set_real_name (ACE::strnew (current_node->get_real_name ())); @@ -79,10 +93,12 @@ PMC_Ruser::insert_protocol_info (Protocol_Record &protocol_record) } char * -PMC_Ruser::handle_protocol_entries (char *cp, char *host_name, char *) +PMC_Ruser::handle_protocol_entries (const char *cp, + const char *host_name, + const char *) { static Protocol_Record protocol_record (1); - auto Drwho_Node *current_node = protocol_record.get_drwho_list (); + Drwho_Node *current_node = protocol_record.get_drwho_list (); protocol_record.set_host (host_name); current_node->set_inactive_count (atoi (cp)); @@ -98,40 +114,60 @@ PMC_Ruser::handle_protocol_entries (char *cp, char *host_name, char *) void PMC_Ruser::process (void) { - auto char *(Drwho_Node::*get_name)(void) = - Options::get_opt (Options::PRINT_LOGIN_NAME) ? &Drwho_Node::get_login_name : &Drwho_Node::get_real_name; + char *(Drwho_Node::*get_name)(void); + + if (Options::get_opt (Options::PRINT_LOGIN_NAME)) + get_name = &Drwho_Node::get_login_name: + else + get_name = &Drwho_Node::get_real_name; - for (Protocol_Record *frp; (frp = this->Protocol_Manager::get_each_friend ()) != 0; ) + for (Protocol_Record *frp; + (frp = this->Protocol_Manager::get_each_friend ()) != 0; + ) { - printf ("%-*s ", this->max_key_length, frp->get_host ()); + ACE_DEBUG ((LM_DEBUG, + "%-*s ", + this->max_key_length, + frp->get_host ())); for (Drwho_Node *np = frp->get_drwho_list (); ;) { - fputs ((np->*get_name) (), stdout); + ACE_DEBUG ((LM_DEBUG, + "%s", + (np->*get_name) ())); if (np->get_inactive_count () != 0) { if (np->get_active_count () != 0) - printf ("*(%d)", np->get_active_count ()); + ACE_DEBUG ((LM_DEBUG, + "*(%d)", + np->get_active_count ())); } else if (np->get_active_count () > 1) - printf ("*(%d)", np->get_active_count ()); + ACE_DEBUG ((LM_DEBUG, + "*(%d)", + np->get_active_count ())); else if (np->get_active_count () == 1) - putchar ('*'); + ACE_DEBUG ((LM_DEBUG, + "*")); - if ((np = np->next) == 0) + np = np->next; + if (np == 0) break; else if (Options::get_opt (Options::PRINT_LOGIN_NAME)) - putchar (' '); + ACE_DEBUG ((LM_DEBUG, + " ")); else - printf (", "); + ACE_DEBUG ((LM_DEBUG, + ", ")); } - putchar ('\n'); + ACE_DEBUG ((LM_DEBUG, + "\n")); } } -#ifndef __OPTIMIZE__ PMC_Ruser::PMC_Ruser (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} + diff --git a/apps/drwho/PMC_Ruser.h b/apps/drwho/PMC_Ruser.h index 936f29854d0..f121fc95be7 100644 --- a/apps/drwho/PMC_Ruser.h +++ b/apps/drwho/PMC_Ruser.h @@ -1,29 +1,40 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's lookup table abstraction for `ruser' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMC_Ruser.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMC_RUSER_H -#define _FMC_RUSER_H +#if !defined (_PMC_RUSER_H) +#define _PMC_RUSER_H #include "PM_Client.h" class PMC_Ruser : public PM_Client { -protected: - char *handle_protocol_entries (char *cp, char *host_name, char * = 0); - Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); + // = TITLE + // Provides the client's lookup table abstraction for `ruser' users... public: - PMC_Ruser (void); - virtual void process (void); + PMC_Ruser (void); + virtual void process (void); + +protected: + char *handle_protocol_entries (const char *cp, + const char *host_name, + const char * = 0); + Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); }; -#ifdef __OPTIMIZE__ -inline -PMC_Ruser::PMC_Ruser (void) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMC_RUSER_H */ +#endif /* _PMC_RUSER_H */ diff --git a/apps/drwho/PMC_Usr.cpp b/apps/drwho/PMC_Usr.cpp index f6a1a7d2d33..95978018afc 100644 --- a/apps/drwho/PMC_Usr.cpp +++ b/apps/drwho/PMC_Usr.cpp @@ -1,6 +1,6 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "SL_Client.h" #include "PMC_Usr.h" @@ -8,38 +8,48 @@ int PMC_Usr::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMC_Usr::encode"); + ACE_DEBUG ((LM_DEBUG, + "in PMC_Usr::encode")); - this->ss = new (PRIVATE_POOL) SL_Client (this->usr_name); + ACE_NEW_RETURN (this->ss, + SL_Client (this->usr_name), + -1); SET_PACKET_TYPE (packet, Options::PROTO_USR); char *buf_ptr = SKIP_PACKET_TYPE (packet); - buf_ptr = ACE::strecpy (buf_ptr, this->get_next_friend ()->get_login ()); + buf_ptr = ACE::strecpy (buf_ptr, + this->get_next_friend ()->get_login ()); packet_length = buf_ptr - packet; if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, ", packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } return 1; } -/* This method is responsible for transforming the msg from the server - back into a form usable by the client. */ +// This method is responsible for transforming the msg from the server +// back into a form usable by the client. int PMC_Usr::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, "in PMC_Usr::decode, packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "in PMC_Usr::decode, packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } char *cp = packet; @@ -48,9 +58,12 @@ PMC_Usr::decode (char *packet, int &packet_length) { char *login_name = cp; - for (cp = ACE::strend (cp); *(cp = this->handle_protocol_entries (cp, login_name)) != '\t'; ) - ; + for (cp = ACE::strend (cp); + *(cp = this->handle_protocol_entries (cp, login_name)) != '\t'; + ) + continue; } + return 1; } @@ -58,28 +71,34 @@ void PMC_Usr::process (void) { Protocol_Record *frp = this->get_each_friend (); - Drwho_Node *np = frp->get_drwho_list (); + Drwho_Node *np = frp->get_drwho_list (); if (np == 0) - fputs ("<unknown>", stdout); + ACE_DEBUG ((LM_DEBUG, + "<unknown>")); else { - - /* First try to get a login session that is active... */ + // First try to get a login session that is active... for (; np != 0; np = np->next) if (np->active_count > 0) { - printf ("%s ", np->get_host_name ()); + ACE_DEBUG ((LM_DEBUG, + "%s ", + np->get_host_name ())); if (Options::get_opt (Options::USE_VERBOSE_FORMAT) == 0) return; } - for (np = frp->get_drwho_list (); np != 0; np = np->next) + for (np = frp->get_drwho_list (); + np != 0; + np = np->next) if (np->active_count == 0) { - printf ("%s ", np->get_host_name ()); + ACE_DEBUG ((LM_DEBUG, + "%s ", + np->get_host_name ())); if (Options::get_opt (Options::USE_VERBOSE_FORMAT) == 0) return; @@ -87,7 +106,7 @@ PMC_Usr::process (void) } } -#ifndef __OPTIMIZE__ -PMC_Usr::PMC_Usr (char *u_name): usr_name (u_name) -{} -#endif /* __OPTIMIZE__ */ +PMC_Usr::PMC_Usr (char *u_name) + : usr_name (u_name) +{ +} diff --git a/apps/drwho/PMC_Usr.h b/apps/drwho/PMC_Usr.h index 03195f12586..09edd37fa28 100644 --- a/apps/drwho/PMC_Usr.h +++ b/apps/drwho/PMC_Usr.h @@ -1,30 +1,38 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's lookup table abstraction for `Usr' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMC_Usr.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMC_USR_H -#define _FMC_USR_H +#if !defined (_PMC_USR_H) +#define _PMC_USR_H #include "PM_Client.h" class PMC_Usr : public PM_Client { -private: - char *usr_name; + // = TITLE + // Provides the client's lookup table abstraction for `Usr' users... +public: + PMC_Usr (char *usr_name); + virtual void process (void); protected: - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); -public: - PMC_Usr (char *usr_name); - virtual void process (void); +private: + char *usr_name; }; -#ifdef __OPTIMIZE__ -inline -PMC_Usr::PMC_Usr (char *u_name): usr_name (u_name) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMC_USR_H */ +#endif /* _PMC_USR_H */ diff --git a/apps/drwho/PMS_All.cpp b/apps/drwho/PMS_All.cpp index d28f21f9bcc..de05c322ad1 100644 --- a/apps/drwho/PMS_All.cpp +++ b/apps/drwho/PMS_All.cpp @@ -1,76 +1,93 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "HT_Server.h" #include "PMS_All.h" -/* This function packs the located friends userids, plus the machines - they are logged into (along with the inactive and active counts on - each machine) into a buffer that is subsequently transmitted back - to the client across the network. Note that this function encodes - the REAL_NAME of the user in the packet. */ +// This function packs the located friends userids, plus the machines +// they are logged into (along with the inactive and active counts on +// each machine) into a buffer that is subsequently transmitted back +// to the client across the network. Note that this function encodes +// the REAL_NAME of the user in the packet. int PMS_All::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_All::encode"); + ACE_DEBUG ((LM_DEBUG, + "in PMS_All::encode")); Protocol_Record *frp; - char *buf_ptr = packet; + char *buf_ptr = packet; - sprintf (buf_ptr, "Users %d", this->get_total_users ()); - buf_ptr += strlen (buf_ptr) + 1; + sprintf (buf_ptr, + "Users %d", + this->get_total_users ()); + buf_ptr += ACE_OS::strlen (buf_ptr) + 1; - /* We only send back info on friends that we actually see logged in. */ + // We only send back info on friends that we actually see logged in. - for (; (frp = this->get_next_friend ()) != 0; *buf_ptr++ = '\t') - buf_ptr = this->handle_protocol_entries (ACE::strecpy (ACE::strecpy (buf_ptr, frp->get_login ()), frp->get_real ()), frp->get_drwho_list ()); + for (; + (frp = this->get_next_friend ()) != 0; + *buf_ptr++ = '\t') + buf_ptr = this->handle_protocol_entries (ACE::strecpy (ACE::strecpy (buf_ptr, + frp->get_login ()), + frp->get_real ()), + frp->get_drwho_list ()); - *buf_ptr++ = '\n'; + *buf_ptr++ = '\n'; packet_length = buf_ptr - packet; if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, ", packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } return 1; } -/* This function takes a packet received from the client and calls - the appropriate Protocol_Manager routine to build the local table of - friends. */ +// This function takes a packet received from the client and calls the +// appropriate Protocol_Manager routine to build the local table of +// friends. int PMS_All::decode (char *, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_All::decode, packet_length = %d\n", packet_length); + ACE_DEBUG ((LM_DEBUG, + "in PMS_All::decode, packet_length = %d\n", + packet_length)); - this->ss = new (PRIVATE_POOL) HT_Server; + ACE_NEW_RETURN (this->ss, + HT_Server, + -1); return 1; } -/* We only want the user's real name, not the gecos junk after the first leading ','. - However, if the real-name is not in the password file, just return the login name - instead. */ +// We only want the user's real name, not the gecos junk after the +// first leading ','. However, if the real-name is not in the +// password file, just return the login name instead. Protocol_Record * PMS_All::insert_protocol_info (Protocol_Record &protocol_record) { - Protocol_Record *frp = PM_Server::insert_protocol_info (protocol_record); - passwd *pwent = getpwnam (frp->get_login ()); - char *cp; - - if ((cp = strchr (frp->set_real (pwent == 0 ? frp->get_login () : ACE::strnew (pwent->pw_gecos)), ',')) != 0) + Protocol_Record *frp = PM_Server::insert_protocol_info (protocol_record); + passwd *pwent = getpwnam (frp->get_login ()); + char *cp = ACE_OS::strchr (frp->set_real + (pwent == 0 + ? frp->get_login () : + ACE::strnew (pwent->pw_gecos)), + ','); + if (cp != 0) *cp = '\0'; return frp; } -#ifndef __OPTIMIZE__ PMS_All::PMS_All (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PMS_All.h b/apps/drwho/PMS_All.h index 559e7674eea..b4de614d5df 100644 --- a/apps/drwho/PMS_All.h +++ b/apps/drwho/PMS_All.h @@ -1,27 +1,35 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the server's lookup table abstraction for `all' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMS_All.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMS_ALL_H -#define _FMS_ALL_H +#if !defined (_PMS_ALL_H) +#define _PMS_ALL_H #include "PM_Server.h" class PMS_All : public PM_Server { -protected: - virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); - + // = TITLE + // Provides the server's lookup table abstraction for `all' users... public: - PMS_All (void); + PMS_All (void); + +protected: + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); }; -#ifdef __OPTIMIZE__ -inline -PMS_All::PMS_All (void) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMS_ALL_H */ +#endif /* _PMS_ALL_H */ diff --git a/apps/drwho/PMS_Flo.cpp b/apps/drwho/PMS_Flo.cpp index 692d316b7cf..7cf2dd73785 100644 --- a/apps/drwho/PMS_Flo.cpp +++ b/apps/drwho/PMS_Flo.cpp @@ -1,58 +1,72 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "BS_Server.h" #include "PMS_Flo.h" -/* This function packs the located friends userids, plus the machines - they are logged into (along with the inactive and active counts on - each machine) into a buffer that is subsequently transmitted back - to the client across the network. */ +// This function packs the located friends userids, plus the machines +// they are logged into (along with the inactive and active counts on +// each machine) into a buffer that is subsequently transmitted back +// to the client across the network. int PMS_Flo::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_Flo::encode"); + ACE_DEBUG ((LM_DEBUG, + "in PMS_Flo::encode")); Protocol_Record *frp; - char *buf_ptr = packet; + char *buf_ptr = packet; - sprintf (buf_ptr, "Users %d", this->get_total_users ()); - buf_ptr += strlen (buf_ptr) + 1; + sprintf (buf_ptr, + "Users %d", + this->get_total_users ()); + buf_ptr += ACE_OS::strlen (buf_ptr) + 1; - /* We only send back info on friends that we actually see logged in. */ + // We only send back info on friends that we actually see logged in. - for (; (frp = this->get_next_friend ()) != 0; *buf_ptr++ = '\t') - buf_ptr = this->handle_protocol_entries (ACE::strecpy (buf_ptr, frp->get_login ()), frp->get_drwho_list ()); + for (; + (frp = this->get_next_friend ()) != 0; + *buf_ptr++ = '\t') + buf_ptr = this->handle_protocol_entries (ACE::strecpy (buf_ptr, + frp->get_login ()), + frp->get_drwho_list ()); - *buf_ptr++ = '\n'; + *buf_ptr++ = '\n'; packet_length = buf_ptr - packet; if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, ", packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } + return 1; } -/* This function takes a packet received from the client and calls - the appropriate Protocol_Manager routine to build the local table of - friends. */ +// This function takes a packet received from the client and calls the +// appropriate Protocol_Manager routine to build the local table of +// friends. int PMS_Flo::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_Flo::decode, packet_length = %d\n", packet_length); + ACE_DEBUG ((LM_DEBUG, + "in PMS_Flo::decode, packet_length = %d\n", + packet_length)); - this->ss = new (PRIVATE_POOL) BS_Server (packet); + ACE_NEW_RETURN (this->ss, + BS_Server (packet), + -1); return 1; } -#ifndef __OPTIMIZE__ PMS_Flo::PMS_Flo (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PMS_Flo.h b/apps/drwho/PMS_Flo.h index e095b5f4ec6..5ef36641015 100644 --- a/apps/drwho/PMS_Flo.h +++ b/apps/drwho/PMS_Flo.h @@ -1,26 +1,35 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the server's lookup table abstraction for `flo' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMS_Flo.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMS_FLO_H -#define _FMS_FLO_H +#if !defined (_PMS_FLO_H) +#define _PMS_FLO_H #include "PM_Server.h" class PMS_Flo : public PM_Server { + // = TITLE + // Provides the server's lookup table abstraction for `flo' users... + +public: + PMS_Flo (void); + protected: virtual int encode (char *packet, int &total_bytes); virtual int decode (char *packet, int &total_bytes); - -public: - PMS_Flo (void); }; -#ifdef __OPTIMIZE__ -inline -PMS_Flo::PMS_Flo (void) -{} -#endif /* __OPTIMIZE__ */ -#endif +#endif /* _PMS_FLO_H */ diff --git a/apps/drwho/PMS_Ruser.cpp b/apps/drwho/PMS_Ruser.cpp index ca49e998a3c..272f57d7976 100644 --- a/apps/drwho/PMS_Ruser.cpp +++ b/apps/drwho/PMS_Ruser.cpp @@ -1,76 +1,95 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "HT_Server.h" #include "PMS_Ruser.h" -/* This function packs the located friends userids, plus the machines - they are logged into (along with the inactive and active counts on - each machine) into a buffer that is subsequently transmitted back - to the client across the network. Note that this function encodes - the REAL_NAME of the user in the packet. */ +// This function packs the located friends userids, plus the machines +// they are logged into (along with the inactive and active counts on +// each machine) into a buffer that is subsequently transmitted back +// to the client across the network. Note that this function encodes +// the REAL_NAME of the user in the packet. int PMS_Ruser::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_Ruser::encode"); + ACE_DEBUG ((LM_DEBUG, + "in PMS_Ruser::encode")); Protocol_Record *frp; - char *buf_ptr = packet; + char *buf_ptr = packet; - sprintf (buf_ptr, "Users %d", this->get_total_users ()); - buf_ptr += strlen (buf_ptr) + 1; + sprintf (buf_ptr, + "Users %d", + this->get_total_users ()); + buf_ptr += ACE_OS::strlen (buf_ptr) + 1; - /* We only send back info on hosts that we actually see. */ + // We only send back info on hosts that we actually see. - for (; (frp = this->get_next_friend ()) != 0; *buf_ptr++ = '\t') - buf_ptr = this->handle_protocol_entries (ACE::strecpy (buf_ptr, frp->get_host ()), frp->get_drwho_list ()); + for (; + (frp = this->get_next_friend ()) != 0; + *buf_ptr++ = '\t') + buf_ptr = this->handle_protocol_entries (ACE::strecpy (buf_ptr, + frp->get_host ()), + frp->get_drwho_list ()); - *buf_ptr++ = '\n'; + *buf_ptr++ = '\n'; packet_length = buf_ptr - packet; if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, ", packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } return 1; } -/* This function takes a packet received from the client and crusers - the appropriate Protocol_Manager routine to build the local table of - friends. */ +// This function takes a packet received from the client and crusers +// the appropriate Protocol_Manager routine to build the local table +// of friends. int PMS_Ruser::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_Ruser::decode, packet_length = %d\n", packet_length); + ACE_DEBUG ((LM_DEBUG, + "in PMS_Ruser::decode, packet_length = %d\n", + packet_length)); if (*packet) Options::set_opt (Options::PRINT_LOGIN_NAME); - this->ss = new (PRIVATE_POOL) HT_Server; + ACE_NEW_RETURN (this->ss, + HT_Server, + -1); return 1; } Protocol_Record * PMS_Ruser::insert_protocol_info (Protocol_Record &protocol_record) { - Drwho_Node *current_node = protocol_record.get_drwho_list (); - Protocol_Record *frp = this->ss->insert (current_node->get_host_name (), MAXHOSTNAMELEN); - Drwho_Node *np = this->get_drwho_node (ACE::strnnew (protocol_record.get_login (), MAXUSERIDNAMELEN), frp->drwho_list); + Drwho_Node *current_node = protocol_record.get_drwho_list (); + Protocol_Record *frp = this->ss->insert (current_node->get_host_name (), + MAXHOSTNAMELEN); + Drwho_Node *np = this->get_drwho_node (ACE::strnnew (protocol_record.get_login (), + MAXUSERIDNAMELEN), + frp->drwho_list); if (Options::get_opt (Options::PRINT_LOGIN_NAME)) np->set_real_name (""); else { - passwd *pwent = getpwnam (np->get_login_name ()); - char *cp; - - if ((cp = strchr (np->set_real_name (pwent == 0 ? np->get_login_name () : ACE::strnew (pwent->pw_gecos)), ',')) != 0) + passwd *pwent = getpwnam (np->get_login_name ()); + char *cp = ACE_OS::strchr (np->set_real_name (pwent == 0 + ? np->get_login_name () + : ACE::strnew (pwent->pw_gecos)), + ','); + if (cp != 0) *cp = '\0'; } @@ -85,19 +104,22 @@ PMS_Ruser::insert_protocol_info (Protocol_Record &protocol_record) char * PMS_Ruser::handle_protocol_entries (char *buf_ptr, Drwho_Node *np) { - for (; np != 0; np = np->next) { - sprintf (buf_ptr, "%d %d ", np->get_inactive_count (), np->get_active_count ()); - buf_ptr += strlen (buf_ptr); - - buf_ptr = ACE::strecpy (ACE::strecpy (buf_ptr, np->get_login_name ()), np->get_real_name ()); + sprintf (buf_ptr, + "%d %d ", + np->get_inactive_count (), + np->get_active_count ()); + buf_ptr += ACE_OS::strlen (buf_ptr); + + buf_ptr = ACE::strecpy (ACE::strecpy (buf_ptr, + np->get_login_name ()), + np->get_real_name ()); } return buf_ptr; } -#ifndef __OPTIMIZE__ PMS_Ruser::PMS_Ruser (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PMS_Ruser.h b/apps/drwho/PMS_Ruser.h index 0111580c3f9..d7ca896cb51 100644 --- a/apps/drwho/PMS_Ruser.h +++ b/apps/drwho/PMS_Ruser.h @@ -1,28 +1,37 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the server's lookup table abstraction for `ruser' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMS_Ruser.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMS_RUSER_H -#define _FMS_RUSER_H +#if !defined (_PMS_RUSER_H) +#define _PMS_RUSER_H #include "PM_Server.h" class PMS_Ruser : public PM_Server { -protected: - virtual char *handle_protocol_entries (char *bp, Drwho_Node *hp); - virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); + // = TITLE + // Provides the server's lookup table abstraction for `ruser' users... public: PMS_Ruser (void); + +protected: + virtual char *handle_protocol_entries (const char *bp, Drwho_Node *hp); + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); }; -#ifdef __OPTIMIZE__ -inline -PMS_Ruser::PMS_Ruser (void) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMS_RUSER_H */ +#endif /* _PMS_RUSER_H */ diff --git a/apps/drwho/PMS_Usr.cpp b/apps/drwho/PMS_Usr.cpp index 900bec14dfa..ad21913760d 100644 --- a/apps/drwho/PMS_Usr.cpp +++ b/apps/drwho/PMS_Usr.cpp @@ -1,33 +1,36 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "SL_Server.h" #include "PMS_Usr.h" -/* This function "encodes" a list of friends by putting the userid's in - a contiguous block. This block can then be transmitted over to the - network to servers on other subnets. Several things are added to - make decoding easier on the other end: - - * A count of the number of friends is prepended (assumption: there - are no more than 9999999 friends... ;-)) - * The login userids are separated by a single space. */ +// This function "encodes" a list of friends by putting the userid's in +// a contiguous block. This block can then be transmitted over to the +// network to servers on other subnets. Several things are added to +// make decoding easier on the other end: +// +// * A count of the number of friends is prepended (assumption: there +// are no more than 9999999 friends... ;-)) +// * The login userids are separated by a single space. */ int PMS_Usr::encode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) - fprintf (stderr, "in PMS_Usr::encode"); + ACE_DEBUG ((LM_DEBUG, + "in PMS_Usr::encode")); char *buf_ptr = packet; - /* We only send back info on friend that is actually logged in. */ + // We only send back info on friend that is actually logged in. Protocol_Record *frp = this->get_next_friend (); if (frp) { - buf_ptr = this->handle_protocol_entries (ACE::strecpy (buf_ptr, frp->get_login ()), frp->get_drwho_list ()); + buf_ptr = this->handle_protocol_entries (ACE::strecpy (buf_ptr, + frp->get_login ()), + frp->get_drwho_list ()); *buf_ptr++ = '\t'; } @@ -36,31 +39,40 @@ PMS_Usr::encode (char *packet, int &packet_length) if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, ", packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } + return 1; } -/* This function takes a packet received from the client and calls - the appropriate Protocol_Manager routine to build the local table of - friends. */ +// This function takes a packet received from the client and calls the +// appropriate Protocol_Manager routine to build the local table of +// friends. int PMS_Usr::decode (char *packet, int &packet_length) { if (Options::get_opt (Options::DEBUG) != 0) { - fprintf (stderr, "in PMS_Usr::decode, packet_length = %d\n", packet_length); - write (2, packet, packet_length); - putc ('\n', stderr); + ACE_DEBUG ((LM_DEBUG, + "in PMS_Usr::decode, packet_length = %d\n", + packet_length)); + ACE_OS::write (ACE_STDERR, packet, packet_length); + ACE_DEBUG ((LM_DEBUG, + "\n")); } - this->ss = new (PRIVATE_POOL) SL_Server (packet); + + ACE_NEW_RTURN (this->ss, + SL_Server (packet), + -1); return 1; } -#ifndef __OPTIMIZE__ PMS_Usr::PMS_Usr (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PMS_Usr.h b/apps/drwho/PMS_Usr.h index d9cd7094da1..2d1df1f3d46 100644 --- a/apps/drwho/PMS_Usr.h +++ b/apps/drwho/PMS_Usr.h @@ -1,26 +1,35 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's lookup table abstraction for `Usr' users... */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PMS_Usr.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _FMS_USR_H -#define _FMS_USR_H +#if !defined (_PMS_USR_H) +#define _PMS_USR_H #include "PM_Server.h" class PMS_Usr : public PM_Server { -protected: - virtual int encode (char *packet, int &total_bytes); - virtual int decode (char *packet, int &total_bytes); + // = TITLE + // Provides the client's lookup table abstraction for `Usr' users... public: - PMS_Usr (void); + PMS_Usr (void); + +protected: + virtual int encode (char *packet, int &total_bytes); + virtual int decode (char *packet, int &total_bytes); }; -#ifdef __OPTIMIZE__ -inline -PMS_Usr::PMS_Usr (void) -{} -#endif /* __OPTIMIZE__ */ -#endif /* _FMS_USR_H */ +#endif /* _PMS_USR_H */ diff --git a/apps/drwho/PM_Client.cpp b/apps/drwho/PM_Client.cpp index ba37746484f..ed087344ba2 100644 --- a/apps/drwho/PM_Client.cpp +++ b/apps/drwho/PM_Client.cpp @@ -3,88 +3,115 @@ #include "PM_Server.h" #include "PM_Client.h" -/* This function is used to merge the LOGIN_NAME from server HOST_NAME - into the userids kept on the client's side. Note that we must - allocate memory for HOST_NAME... */ +// This function is used to merge the LOGIN_NAME from server HOST_NAME +// into the userids kept on the client's side. Note that we must +// allocate memory for HOST_NAME... Protocol_Record * PM_Client::insert_protocol_info (Protocol_Record &protocol_record) { - Protocol_Record *frp = this->ss->insert (protocol_record.get_login ()); - Drwho_Node *current_node = protocol_record.get_drwho_list (); - Drwho_Node *np = this->get_drwho_node (ACE::strnew (current_node->get_host_name ()), frp->drwho_list); + Protocol_Record *frp = this->ss->insert (protocol_record.get_login ()); + Drwho_Node *current_node = protocol_record.get_drwho_list (); + Drwho_Node *np = this->get_drwho_node (ACE::strnew (current_node->get_host_name ()), + frp->drwho_list); - /* Update the active and inactive counts. */ + // Update the active and inactive counts. if (np->get_active_count () < current_node->get_active_count ()) { np->set_active_count (current_node->get_active_count ()); frp->is_active = 1; } + if (np->get_inactive_count () < current_node->get_inactive_count()) np->set_inactive_count (current_node->get_inactive_count ()); return frp; } -/* This routine does all the dirty work, and actually prints out the - friends info in a nicely formatted manner. */ +// This routine does all the dirty work, and actually prints out the +// friends info in a nicely formatted manner. void PM_Client::process (void) { - char *(Protocol_Record::*get_name)(void) = Options::get_opt (Options::PRINT_LOGIN_NAME) ? &Protocol_Record::get_login : &Protocol_Record::get_real; + char *(Protocol_Record::*get_name)(void); + + if (Options::get_opt (Options::PRINT_LOGIN_NAME)) + get_name = &Protocol_Record::get_login; + else + get_name = &Protocol_Record::get_real; int active_friends = 0; - int users = this->Protocol_Manager::get_total_users (); + int users = this->Protocol_Manager::get_total_users (); - printf ("------------------------\n"); + ACE_DEBUG ((LM_DEBUG, + "------------------------\n")); if (Options::get_opt (Options::PRINT_LOGIN_NAME)) this->max_key_length = MAXUSERIDNAMELEN; - /* Goes through the queue of all the logged in friends and prints - out the associated information. */ + // Goes through the queue of all the logged in friends and prints + // out the associated information. - for (Protocol_Record *frp; (frp = this->Protocol_Manager::get_each_friend ()) != 0; ) + for (Protocol_Record *frp = this->Protocol_Manager::get_each_friend () + frp != 0; + frp = this->Protocol_Manager::get_each_friend ()) { - printf ("%c%-*s [", (frp->is_active != 0 ? '*' : ' '), - this->max_key_length, (frp->*get_name) ()); + ACE_DEBUG ((LM_DEBUG, + "%c%-*s [", (frp->is_active != 0 ? '*' : ' '), + this->max_key_length, + (frp->*get_name) ())); for (Drwho_Node *np = frp->get_drwho_list (); ;) { - fputs (np->get_host_name (), stdout); + ACE_DEBUG ((LM_DEBUG, + np->get_host_name (), + stdout)); active_friends += np->get_active_count (); if (np->get_inactive_count () != 0) { if (np->get_active_count () != 0) - printf ("*(%d)", np->get_active_count ()); + ACE_DEBUG ((LM_DEBUG, + "*(%d)", + np->get_active_count ())); } else if (np->get_active_count () > 1) - printf ("*(%d)", np->get_active_count ()); + ACE_DEBUG ((LM_DEBUG, + "*(%d)", + np->get_active_count ())); else if (np->get_active_count () == 1) - putchar ('*'); + ACE_DEBUG ((LM_DEBUG, + "*")); if ((np = np->next) == 0) break; else - putchar (' '); + ACE_DEBUG ((LM_DEBUG + " ")); } - printf ("]\n"); + ACE_DEBUG ((LM_DEBUG + "]\n")); } - printf ("------------------------\n"); - printf ("friends: %d\tusers: %d\n", active_friends, users); + ACE_DEBUG ((LM_DEBUG, + "------------------------\n")); + ACE_DEBUG ((LM_DEBUG, + "friends: %d\tusers: %d\n", + active_friends, + users)); } char * -PM_Client::handle_protocol_entries (char *cp, char *login_name, char *real_name) +PM_Client::handle_protocol_entries (const char *cp, + const char *login_name, + const char *real_name) { static Protocol_Record protocol_record (1); - Drwho_Node *current_node = protocol_record.get_drwho_list (); + Drwho_Node *current_node = protocol_record.get_drwho_list (); protocol_record.set_login (login_name); protocol_record.set_real (real_name); @@ -97,10 +124,12 @@ PM_Client::handle_protocol_entries (char *cp, char *login_name, char *real_name) return ACE::strend (cp); } -#ifndef __OPTIMIZE__ -PM_Client::PM_Client (void): max_key_length (0) -{} +PM_Client::PM_Client (void) + : max_key_length (0) +{ +} PM_Client::~PM_Client (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} + diff --git a/apps/drwho/PM_Client.h b/apps/drwho/PM_Client.h index ff1c20f32fa..6c7b3c90660 100644 --- a/apps/drwho/PM_Client.h +++ b/apps/drwho/PM_Client.h @@ -1,37 +1,45 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client side of the friend manager lookup table abstraction. */ - -#ifndef _PM_CLIENT_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PM_Client.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_PM_CLIENT_H) #define _PM_CLIENT_H #include "Protocol_Manager.h" class PM_Client : public Protocol_Manager { + // = TITLE + // Provides the client side of the friend manager lookup table abstraction. +public: + PM_Client (void); + virtual ~PM_Client (void); + + virtual int encode (char *packet, int &total_bytes) = 0; + virtual int decode (char *packet, int &total_bytes) = 0; + virtual void process (void); + protected: - int max_key_length; + int max_key_length; - virtual char *handle_protocol_entries (char *cp, char *key_name1, char *key_name2 = 0); - virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); -public: - PM_Client (void); - virtual ~PM_Client (void); + virtual char *handle_protocol_entries (const char *cp, + const char *key_name1, + const char *key_name2 = 0); - virtual int encode (char *packet, int &total_bytes) = 0; - virtual int decode (char *packet, int &total_bytes) = 0; - virtual void process (void); + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); }; -#ifdef __OPTIMIZE__ -inline -PM_Client::PM_Client (void): max_key_length (0) -{} - -inline -PM_Client::~PM_Client (void) -{} -#endif /* __OPTIMIZE__ */ #endif /* _PM_CLIENT_H */ diff --git a/apps/drwho/PM_Server.cpp b/apps/drwho/PM_Server.cpp index bd47013606b..38d29992c6e 100644 --- a/apps/drwho/PM_Server.cpp +++ b/apps/drwho/PM_Server.cpp @@ -1,19 +1,20 @@ // $Id$ + #include "Options.h" #include "Rwho_DB_Manager.h" #include "PM_Server.h" -/* This is the main method for the server side of things. It - reads the RWHO file on the local machine and inserts HOST_NAME - information for each LOGIN_NAME that is a friend into the DRWHO_LIST. - This function is also responsible for determining whether a given - LOGIN_NAME is currently idle or not. */ +// This is the main method for the server side of things. It reads +// the RWHO file on the local machine and inserts HOST_NAME +// information for each LOGIN_NAME that is a friend into the +// DRWHO_LIST. This function is also responsible for determining +// whether a given LOGIN_NAME is currently idle or not. int PM_Server::process (void) { RWho_DB_Manager ru; - Protocol_Record protocol_record (1); + Protocol_Record protocol_record (1); while (ru.get_next_user (protocol_record) > 0) this->insert_protocol_info (protocol_record); @@ -21,9 +22,9 @@ PM_Server::process (void) return 1; } -/* Insert the HOST_NAME into the server's lookup table on behalf of - user LOGIN_NAME. Note that we need to allocate memory for - HOST_NAME... */ +// Insert the HOST_NAME into the server's lookup table on behalf of +// user LOGIN_NAME. Note that we need to allocate memory for +// HOST_NAME... Protocol_Record * PM_Server::insert_protocol_info (Protocol_Record &protocol_record) @@ -37,7 +38,9 @@ PM_Server::insert_protocol_info (Protocol_Record &protocol_record) if (frp) { - Drwho_Node *np = this->get_drwho_node (ACE::strnew (current_node->get_host_name ()), frp->drwho_list); + Drwho_Node *np = + this->get_drwho_node (ACE::strnew (current_node->get_host_name ()), + frp->drwho_list); if (current_node->get_idle_time () >= MAX_USER_TIMEOUT) np->inactive_count++; @@ -48,7 +51,8 @@ PM_Server::insert_protocol_info (Protocol_Record &protocol_record) return frp; } -/* Put the inactive and active counts, plus the hostname into the packet. */ +// Put the inactive and active counts, plus the hostname into the +// packet. char * PM_Server::handle_protocol_entries (char *buf_ptr, Drwho_Node *np) @@ -56,17 +60,21 @@ PM_Server::handle_protocol_entries (char *buf_ptr, Drwho_Node *np) for (; np != 0; np = np->next) { - sprintf (buf_ptr, "%d %d %s", np->get_inactive_count (), np->get_active_count (), np->get_host_name ()); + sprintf (buf_ptr, + "%d %d %s", + np->get_inactive_count (), + np->get_active_count (), + np->get_host_name ()); buf_ptr += strlen (buf_ptr) + 1; } return buf_ptr; } -#ifndef __OPTIMIZE__ PM_Server::PM_Server (void) -{} +{ +} PM_Server::~PM_Server (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/PM_Server.h b/apps/drwho/PM_Server.h index 2b9b497aee4..4b9ec51063e 100644 --- a/apps/drwho/PM_Server.h +++ b/apps/drwho/PM_Server.h @@ -1,35 +1,40 @@ /* -*- C++ -*- */ // $Id$ -/* Handle the server's lookup table abstraction. */ - -#ifndef _PM_SERVER_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// PM_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_PM_SERVER_H) #define _PM_SERVER_H #include "Protocol_Manager.h" class PM_Server : public Protocol_Manager { -protected: - virtual char *handle_protocol_entries (char *bp, Drwho_Node *hp); - virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); + // = TITLE + // Handle the server's lookup table abstraction. public: - PM_Server (void); - virtual ~PM_Server (void); + PM_Server (void); + virtual ~PM_Server (void); - virtual int encode (char *packet, int &total_bytes) = 0; - virtual int decode (char *packet, int &total_bytes) = 0; - virtual int process (void); -}; + virtual int encode (char *packet, int &total_bytes) = 0; + virtual int decode (char *packet, int &total_bytes) = 0; + virtual int process (void); -#ifdef __OPTIMIZE__ -inline -PM_Server::PM_Server (void) -{} +protected: + virtual char *handle_protocol_entries (char *bp, Drwho_Node *hp); + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record); +}; -inline -PM_Server::~PM_Server (void) -{} -#endif /* __OPTIMIZE__ */ -#endif +#endif /* _PM_SERVER_H */ diff --git a/apps/drwho/Protocol_Manager.cpp b/apps/drwho/Protocol_Manager.cpp index a31f4041d10..cc6b0d1838e 100644 --- a/apps/drwho/Protocol_Manager.cpp +++ b/apps/drwho/Protocol_Manager.cpp @@ -3,49 +3,51 @@ #include "new.h" #include "Protocol_Manager.h" -#if 0 -/* Static initializers. */ -int Protocol_Manager::total_users = 0; -Search_Struct *Protocol_Manager::ss = 0; -#endif - -/* Functions shared between client and server. */ - -/* Returns a pointer to the Drwho_Node associated with HOST_NAME (if - it exists, otherwise a new node is created. Note that if a - Drwho_Node is found it is moved to the front of the list so that - subsequent finds are faster (i.e., self-organizing!) */ +// Returns a pointer to the Drwho_Node associated with HOST_NAME (if +// it exists, otherwise a new node is created. Note that if a +// Drwho_Node is found it is moved to the front of the list so that +// subsequent finds are faster (i.e., self-organizing!) Drwho_Node * Protocol_Manager::get_drwho_node (char *key_name, Drwho_Node *&head) { - for (Drwho_Node **temp = &head; *temp != 0; temp = &(*temp)->next) - if (strcmp (key_name, (*temp)->get_login_name ()) == 0) + for (Drwho_Node **temp = &head; + *temp != 0; + temp = &(*temp)->next) + if (ACE_OS::strcmp (key_name, + (*temp)->get_login_name ()) == 0) break; if (*temp == 0) - return head = new (PRIVATE_POOL) Drwho_Node (key_name, head); + ACE_NEW_RETURN (head, + Drwho_Node (key_name, head), + 0); else { Drwho_Node *t = *temp; *temp = (*temp)->next; t->next = head; - return head = t; + + head = t; } + + return head; } -#ifndef __OPTIMIZE__ -Protocol_Manager::Protocol_Manager (void): total_users (0) -{} +Protocol_Manager::Protocol_Manager (void) + : total_users (0) +{ +} Protocol_Manager::~Protocol_Manager (void) { if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "disposing Protocol_Manager\n"); + ACE_DEBUG ((LM_DEBUG, + "disposing Protocol_Manager\n")); } -/* Returns the next friend in the sequence of sorted friends. */ +// Returns the next friend in the sequence of sorted friends. Protocol_Record * Protocol_Manager::get_next_friend (void) @@ -59,7 +61,7 @@ Protocol_Manager::get_each_friend (void) return this->ss->get_each_entry (); } -/* Returns the number of friends. */ +// Returns the number of friends. int Protocol_Manager::friend_count (void) @@ -67,7 +69,7 @@ Protocol_Manager::friend_count (void) return this->ss->n_elems (); } -/* Returns total number of users logged in throughout the system. */ +// Returns total number of users logged in throughout the system. int Protocol_Manager::get_total_users (void) @@ -80,4 +82,3 @@ Protocol_Manager::increment_total_users (int remote_users) { Protocol_Manager::total_users += remote_users; } -#endif /* __OPTIMIZE__ */ diff --git a/apps/drwho/Protocol_Manager.h b/apps/drwho/Protocol_Manager.h index 705a1e81657..63f95d9b342 100644 --- a/apps/drwho/Protocol_Manager.h +++ b/apps/drwho/Protocol_Manager.h @@ -1,11 +1,21 @@ /* -*- C++ -*- */ // $Id$ -/* A base class that consolidates friend management functionality - shared by both clients and servers. */ - -#ifndef _FRIEND_MANAGER_H -#define _FRIEND_MANAGER_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Protocol_Manager.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_PROTOCOL_MANAGER_H) +#define _PROTOCOL_MANAGER_H #include "ace/OS.h" #include "Options.h" @@ -14,73 +24,30 @@ class Protocol_Manager { -protected: - int total_users; - Search_Struct *ss; - - int friend_count (void); - - Drwho_Node *get_drwho_node (char *host_name, Drwho_Node *&head); - int get_total_users (void); - void increment_total_users (int remote_users = 1); - - Protocol_Record *get_next_friend (void); - Protocol_Record *get_each_friend (void); - - virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record) = 0; - + // = TITLE + // A base class that consolidates friend management functionality + // shared by both clients and servers. public: - Protocol_Manager (void); - virtual ~Protocol_Manager (void); + Protocol_Manager (void); + virtual ~Protocol_Manager (void); - virtual int encode (char *packet, int &total_bytes) = 0; - virtual int decode (char *packet, int &total_bytes) = 0; -}; + virtual int encode (char *packet, int &total_bytes) = 0; + virtual int decode (char *packet, int &total_bytes) = 0; -#ifdef __OPTIMIZE__ -inline -Protocol_Manager::Protocol_Manager (void): total_users (0) -{} - -inline -Protocol_Manager::~Protocol_Manager (void) -{ - if (Options::DEBUG) - fprintf (stderr, "disposing Protocol_Manager\n"); -} +protected: + int total_users; + Search_Struct *ss; -/* Returns the next friend in the sequence of sorted friends. */ + int friend_count (void); -inline Protocol_Record * -Protocol_Manager::get_next_friend (void) -{ - return this->ss->get_next_entry (); -} + Drwho_Node *get_drwho_node (char *host_name, Drwho_Node *&head); + int get_total_users (void); + void increment_total_users (int remote_users = 1); -inline Protocol_Record * -Protocol_Manager::get_each_friend (void) -{ - return this->ss->get_each_entry (); -} + Protocol_Record *get_next_friend (void); + Protocol_Record *get_each_friend (void); -/* Returns the number of friends. */ - -inline int -Protocol_Manager::friend_count (void) -{ - return this->ss->n_elems (); -} - -inline int -Protocol_Manager::get_total_users (void) -{ - return this->total_users; -} + virtual Protocol_Record *insert_protocol_info (Protocol_Record &protocol_record) = 0; +}; -inline void -Protocol_Manager::increment_total_users (int remote_users) -{ - this->total_users += remote_users; -} -#endif /* __OPTIMIZE__ */ -#endif /* _FRIEND_MANAGER_H */ +#endif /* _PROTOCOL_MANAGER_H */ diff --git a/apps/drwho/Protocol_Record.cpp b/apps/drwho/Protocol_Record.cpp index c62350f03ff..fda6fc8314d 100644 --- a/apps/drwho/Protocol_Record.cpp +++ b/apps/drwho/Protocol_Record.cpp @@ -1,35 +1,49 @@ // $Id$ + #include "Options.h" #include "Protocol_Record.h" -/* Static initialization. */ +// Static initialization. Drwho_Node Protocol_Record::drwho_node; Protocol_Record::~Protocol_Record (void) { if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "disposing Protocol_Record\n"); + ACE_DEBUG ((LM_DEBUG, + "disposing Protocol_Record\n")); - for (Drwho_Node *np = this->get_drwho_list (); np != 0; ) + for (Drwho_Node *np = this->get_drwho_list (); + np != 0; ) { Drwho_Node *t = np; - np = np->next; + np = np->next; + delete t; } } -#ifndef __OPTIMIZE__ Protocol_Record::Protocol_Record (void) - : is_active (0), drwho_list (0), key_name1 (0), key_name2 (0), next (0) -{} + : is_active (0), + drwho_list (0), + key_name1 (0), + key_name2 (0), + next (0) +{ +} Protocol_Record::Protocol_Record (int) - : is_active (0), drwho_list (&Protocol_Record::drwho_node), key_name1 (0), key_name2 (0), next (0) -{} - + : is_active (0), + drwho_list (&Protocol_Record::drwho_node), + key_name1 (0), + key_name2 (0), + next (0) +{ +} Protocol_Record::Protocol_Record (char *kn1, Protocol_Record *next) - : is_active (0), drwho_list (0), key_name2 (0) + : is_active (0), + drwho_list (0), + key_name2 (0) { this->key_name1 = kn1; this->next = next; @@ -62,13 +76,15 @@ Protocol_Record::get_host (void) char * Protocol_Record::set_host (char *str) { - return this->key_name1 = str; + this->key_name1 = str; + return str; } char * Protocol_Record::set_real (char *str) { - return this->key_name2 = str; + this->key_name2 = str + return str; } Drwho_Node * @@ -76,4 +92,3 @@ Protocol_Record::get_drwho_list (void) { return this->drwho_list; } -#endif /* __OPTIMIZE__ */ diff --git a/apps/drwho/Protocol_Record.h b/apps/drwho/Protocol_Record.h index 05afa16f8e6..4af413cf411 100644 --- a/apps/drwho/Protocol_Record.h +++ b/apps/drwho/Protocol_Record.h @@ -1,95 +1,49 @@ /* -*- C++ -*- */ // $Id$ -/* Stores information about a single friend's status. */ - -#ifndef _FRIEND_RECORD_H -#define _FRIEND_RECORD_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Protocol_Record.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_PROTOCOL_RECORD_H) +#define _PROTOCOL_RECORD_H #include "Drwho_Node.h" class Protocol_Record { + // = TITLE + // Stores information about a single friend's status. + public: - static Drwho_Node drwho_node; - char *key_name1; - char *key_name2; - Drwho_Node *drwho_list; - Protocol_Record *next; - int is_active; + Protocol_Record (void); + Protocol_Record (int use_dummy); + Protocol_Record (char *key_name1, + Protocol_Record *next = 0); + ~Protocol_Record (void); + char *get_host (void); + char *set_host (char *str); + char *get_login (void); + char *set_login (char *str); + char *get_real (void); + char *set_real (char *str); + Drwho_Node *get_drwho_list (void); - Protocol_Record (void); - Protocol_Record (int use_dummy); - Protocol_Record (char *key_name1, Protocol_Record *next = 0); - ~Protocol_Record (void); - char *get_host (void); - char *set_host (char *str); - char *get_login (void); - char *set_login (char *str); - char *get_real (void); - char *set_real (char *str); - Drwho_Node *get_drwho_list (void); + static Drwho_Node drwho_node; + char *key_name1; + char *key_name2; + Drwho_Node *drwho_list; + Protocol_Record *next; + int is_active; }; -#ifdef __OPTIMIZE__ -inline -Protocol_Record::Protocol_Record (void) - : is_active (0), drwho_list (0), key_name1 (0), key_name2 (0), next (0) -{} - -inline -Protocol_Record::Protocol_Record (int use_dummy) - : is_active (0), drwho_list (&Protocol_Record::drwho_node), key_name1 (0), key_name2 (0), next (0) -{} - -inline -Protocol_Record::Protocol_Record (char *key_name1, Protocol_Record *next) - : is_active (0), drwho_list (0), key_name2 (0) -{ - this->key_name1 = key_name1; - this->next = next; -} - -inline char * -Protocol_Record::get_login (void) -{ - return this->key_name1; -} - -inline char * -Protocol_Record::set_login (char *str) -{ - return this->key_name1 = str; -} - -inline char * -Protocol_Record::get_real (void) -{ - return this->key_name2; -} - -inline char * -Protocol_Record::get_host (void) -{ - return this->key_name1; -} - -inline char * -Protocol_Record::set_host (char *str) -{ - return this->key_name1 = str; -} - -inline char * -Protocol_Record::set_real (char *str) -{ - return this->key_name2 = str; -} - -inline Drwho_Node * -Protocol_Record::get_drwho_list (void) -{ - return this->drwho_list; -} -#endif /* __OPTIMIZE__ */ -#endif /* _FRIEND_RECORD_H */ +#endif /* _PROTOCOL_RECORD_H */ diff --git a/apps/drwho/Rwho_DB_Manager.cpp b/apps/drwho/Rwho_DB_Manager.cpp index e67d6ded666..59cb2dc3c6e 100644 --- a/apps/drwho/Rwho_DB_Manager.cpp +++ b/apps/drwho/Rwho_DB_Manager.cpp @@ -3,99 +3,116 @@ #include "Options.h" #include "Rwho_DB_Manager.h" -/* Change to the RWHO directory to speed up and simplify later - processing. This requires opening the directory - for reading with the directory iterator abstraction and then - skipping the first two files in the directory, which are assumed to - be "." and ".." (this function needs to be changed if this - assumption does not hold!) */ +// Change to the RWHO directory to speed up and simplify later +// processing. This requires opening the directory for reading with +// the directory iterator abstraction and then skipping the first two +// files in the directory, which are assumed to be "." and ".." (this +// function needs to be changed if this assumption does not hold!) RWho_DB_Manager::RWho_DB_Manager (void) - : number_of_users (0), current_user (0), rwho_dir_name (RWHODIR), - WHOD_HEADER_SIZE (sizeof host_data - sizeof host_data.wd_we) + : number_of_users (0), + current_user (0), + rwho_dir_name (RWHODIR), + WHOD_HEADER_SIZE (sizeof host_data - sizeof host_data.wd_we) { - if (getcwd (this->original_pathname, MAXPATHLEN + 1) == 0) - perror (Options::program_name), exit (1); - - if (chdir (this->rwho_dir_name) < 0) - perror (this->rwho_dir_name), exit (1); + if (ACE_OS::getcwd (this->original_pathname, MAXPATHLEN + 1) == 0) + ACE_ERROR ((LM_ERROR, + "%p\n%a", + Options::program_name, + 1)); + + if (ACE_OS::chdir (this->rwho_dir_name) < 0) + ACE_ERROR ((LM_ERROR, + "%p\n%a", + this->rwho_dir_name, + 1)); this->rwho_dir.opendir (this->rwho_dir_name); - /* Skip "." and ".." */ + // Skip "." and ".." this->rwho_dir.readdir (); this->rwho_dir.readdir (); } -/* The destructor cleans up the RWHOD_DIR handle. */ +// The destructor cleans up the RWHOD_DIR handle. RWho_DB_Manager::~RWho_DB_Manager (void) { - if (chdir (this->original_pathname) < 0) - perror (Options::program_name), exit (1); + if (ACE_OS::chdir (this->original_pathname) < 0) + ACE_ERROR ((LM_ERROR, + "%p\n%a", + Options::program_name, + 1)); if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "disposing the RWho-Manager\n"); + ACE_DEBUG ((LM_DEBUG, + "disposing the RWho_DB_Manager\n")); } -/* This procedure looks through the rwhod directory until it finds the next - valid user file. - - The requirements for user files are: - 1) The file is at least MIN_HOST_DATA_SIZE bytes long - 2) It was received within the last MAX_HOST_TIMEOUT seconds - - Return: - Are there any more hosts? */ +// This procedure looks through the rwhod directory until it finds the next +// valid user file. +// +// The requirements for user files are: +// 1) The file is at least MIN_HOST_DATA_SIZE bytes long +// 2) It was received within the last MAX_HOST_TIMEOUT seconds +// Return: +// Are there any more hosts? */ int RWho_DB_Manager::get_next_host (void) { - dirent *dir_ptr; - long current_time; + long current_time; - time (¤t_time); + ACE_OS::time (¤t_time); - /* Go through each file in the directory looking for valid entries */ - - while ((dir_ptr = this->rwho_dir.readdir ()) != 0) + // Go through each file in the directory looking for valid entries. + + for (dirent *dir_ptr = this->rwho_dir.readdir (); + dir_ptr != 0; + dir_ptr = this->rwho_dir.readdir ()) { - int user_file; - int host_data_length; + ACE_HANDLE user_file = ACE_OS::open (dir_ptr->d_name, O_RDONLY); - if ((user_file = open (dir_ptr->d_name, O_RDONLY)) < 0) + if (user_file < 0) return -1; - host_data_length = read (user_file, (char *) &this->host_data, sizeof this->host_data); + int host_data_length = + ACE_OS::read (user_file, + (char *) &this->host_data, + sizeof this->host_data); - if (host_data_length > WHOD_HEADER_SIZE && current_time - this->host_data.wd_recvtime < MAX_HOST_TIMEOUT) + if (host_data_length > WHOD_HEADER_SIZE + && current_time - this->host_data.wd_recvtime < MAX_HOST_TIMEOUT) { - this->current_user = 0; + this->current_user = 0; this->number_of_users = (host_data_length - WHOD_HEADER_SIZE) / sizeof *this->host_data.wd_we; - close (user_file); - return 1; /* We found a good host, so return it */ + ACE_OS::close (user_file); + return 1; // We found a good host, so return it. } else - close (user_file); + ACE_OS::close (user_file); } - return 0; /* There are no more hosts, so return False */ + // There are no more hosts, so return False. + return 0; } -/* Returns the next user's information. Note that for efficiency - only pointers are copied, i.e., this info must be used before we - call this function again. */ +// Returns the next user's information. Note that for efficiency only +// pointers are copied, i.e., this info must be used before we call +// this function again. int RWho_DB_Manager::get_next_user (Protocol_Record &protocol_record) { - /* Get the next host file if necessary */ - if (this->current_user >= this->number_of_users && this->get_next_host () == 0) + // Get the next host file if necessary + if (this->current_user >= this->number_of_users + && this->get_next_host () == 0) return 0; Drwho_Node *current_node = protocol_record.get_drwho_list (); protocol_record.set_login (this->host_data.wd_we[current_user].we_utmp.out_name); + current_node->set_host_name (this->host_data.wd_hostname); current_node->set_idle_time (this->host_data.wd_we[current_user].we_idle); this->current_user++; diff --git a/apps/drwho/Rwho_DB_Manager.h b/apps/drwho/Rwho_DB_Manager.h index 7925c695bd5..2af48c6564c 100644 --- a/apps/drwho/Rwho_DB_Manager.h +++ b/apps/drwho/Rwho_DB_Manager.h @@ -1,9 +1,20 @@ /* -*- C++ -*- */ // $Id$ -/* This class returns the user/machine pairs one at a time from the rwho database. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Rwho_DB_Manager.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _RWHO_DB_MANAGER_H +#if !defined (_RWHO_DB_MANAGER_H) #define _RWHO_DB_MANAGER_H #include "rwhod.h" @@ -12,20 +23,25 @@ class RWho_DB_Manager { -private: - Dirent rwho_dir; - whod host_data; - int number_of_users; - int current_user; - const int WHOD_HEADER_SIZE; - char original_pathname[MAXPATHLEN + 1]; - char *rwho_dir_name; - - int get_next_host (void); + // = TITLE + // This class returns the user/machine pairs one at a time from + // the rwho database. public: - RWho_DB_Manager (void); - ~RWho_DB_Manager (void); - int get_next_user (Protocol_Record &protocol_record); + RWho_DB_Manager (void); + ~RWho_DB_Manager (void); + int get_next_user (Protocol_Record &protocol_record); + +private: + Dirent rwho_dir; + whod host_data; + int number_of_users; + int current_user; + const int WHOD_HEADER_SIZE; + char original_pathname[MAXPATHLEN + 1]; + char *rwho_dir_name; + + int get_next_host (void); }; + #endif /* _RWHO_DB_MANAGER_H */ diff --git a/apps/drwho/SL_Client.cpp b/apps/drwho/SL_Client.cpp index d2c62c942c6..32db2e03d43 100644 --- a/apps/drwho/SL_Client.cpp +++ b/apps/drwho/SL_Client.cpp @@ -1,14 +1,15 @@ // $Id$ + #include "Options.h" #include "SL_Client.h" -#ifndef __OPTIMIZE__ -SL_Client::SL_Client (char *usr_name): Single_Lookup (usr_name) -{} +SL_Client::SL_Client (char *usr_name) + : Single_Lookup (usr_name) +{ +} Protocol_Record * SL_Client::insert (char *, int) { return this->frp; } -#endif /* __OPTIMIZE__ */ diff --git a/apps/drwho/SL_Client.h b/apps/drwho/SL_Client.h index f00e9939f02..2ab19f7413b 100644 --- a/apps/drwho/SL_Client.h +++ b/apps/drwho/SL_Client.h @@ -1,29 +1,33 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's single user lookup table abstraction. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SL_Client.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _SL_CLIENT_H +#if !defined (_SL_CLIENT_H) #define _SL_CLIENT_H #include "Single_Lookup.h" class SL_Client : public Single_Lookup { + // = TITLE + // Provides the client's single user lookup table abstraction. + public: - SL_Client (char *usr_name); - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN); + SL_Client (char *usr_name); + virtual Protocol_Record *insert (char *key_name, + int max_len = MAXUSERIDNAMELEN); }; -#ifdef __OPTIMIZE__ -inline -SL_Client::SL_Client (char *usr_name): Single_Lookup (usr_name) -{} - -inline Protocol_Record * -SL_Client::insert (char *key_name, int) -{ - return this->frp; -} -#endif /* __OPTIMIZE__ */ #endif /* _SL_CLIENT_H */ diff --git a/apps/drwho/SL_Server.cpp b/apps/drwho/SL_Server.cpp index a55a02323c6..3df3fbb2ea4 100644 --- a/apps/drwho/SL_Server.cpp +++ b/apps/drwho/SL_Server.cpp @@ -1,10 +1,12 @@ // $Id$ + #include "global.h" #include "SL_Server.h" -#ifndef __OPTIMIZE__ -SL_Server::SL_Server (char *usr_name): Single_Lookup (usr_name) -{} +SL_Server::SL_Server (char *usr_name) + : Single_Lookup (usr_name) +{ +} Protocol_Record * SL_Server::get_each_entry (void) @@ -16,6 +18,8 @@ SL_Server::get_each_entry (void) Protocol_Record * SL_Server::insert (char *key_name, int max_len) { - return strncmp (key_name, this->frp->get_login (), max_len) == 0 ? this->frp : 0; + return ACE_OS::strncmp (key_name, + this->frp->get_login (), + max_len) == 0 ? this->frp : 0; } -#endif /* __OPTIMIZE__ */ + diff --git a/apps/drwho/SL_Server.h b/apps/drwho/SL_Server.h index 55738c554e1..44ab117828a 100644 --- a/apps/drwho/SL_Server.h +++ b/apps/drwho/SL_Server.h @@ -1,37 +1,34 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the server's single user lookup table abstraction. */ +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SL_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ -#ifndef _SL_SERVER_H +#if !defined (_SL_SERVER_H) #define _SL_SERVER_H #include "Single_Lookup.h" class SL_Server : public Single_Lookup { + // = TITLE + // Provides the server's single user lookup table abstraction. + public: - SL_Server (char *packet); - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN); + SL_Server (char *packet); + virtual Protocol_Record *insert (char *key_name, + int max_len = MAXUSERIDNAMELEN); virtual Protocol_Record *get_each_entry (void); }; -#ifdef __OPTIMIZE__ -inline -SL_Server::SL_Server (char *usr_name): Single_Lookup (usr_name) -{} - -inline Protocol_Record * -SL_Server::get_each_entry (void) -{ - Protocol_Record *frp = Single_Lookup::get_each_entry (); - return frp->get_drwho_list () == 0 ? 0 : frp; -} - -inline Protocol_Record * -SL_Server::insert (char *key_name, int max_len) -{ - return strncmp (key_name, this->frp->get_login (), max_len) == 0 ? this->frp : 0; -} -#endif /* __OPTIMIZE__ */ #endif /* _SL_SERVER_H */ diff --git a/apps/drwho/SML_Client.cpp b/apps/drwho/SML_Client.cpp index b097064e156..f5edc3600f9 100644 --- a/apps/drwho/SML_Client.cpp +++ b/apps/drwho/SML_Client.cpp @@ -1,4 +1,5 @@ // $Id$ + #include "Options.h" #include "SML_Client.h" @@ -26,10 +27,10 @@ SML_Client::send (void) return 1; } -#ifndef __OPTIMIZE__ SML_Client::SML_Client (void) -{} +{ +} SML_Client::~SML_Client (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/SML_Client.h b/apps/drwho/SML_Client.h index 462310b99a8..42dedf46248 100644 --- a/apps/drwho/SML_Client.h +++ b/apps/drwho/SML_Client.h @@ -1,7 +1,20 @@ /* -*- C++ -*- */ // $Id$ -#ifndef _SML_CLIENT_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SML_Client.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SML_CLIENT_H) #define _SML_CLIENT_H #include "SM_Client.h" @@ -9,24 +22,15 @@ class SML_Client : public SM_Client { -private: - SML_Server sml_server; - int packet_length; - public: - SML_Client (void); - virtual ~SML_Client (void); + SML_Client (void); + virtual ~SML_Client (void); virtual int receive (int timeout = 0); virtual int send (void); -}; -#ifdef __OPTIMIZE__ -inline -SML_Client::SML_Client (void) -{} +private: + SML_Server sml_server; + int packet_length; +}; -inline -SML_Client::~SML_Client (void) -{} -#endif /* __OPTIMIZE__ */ #endif /* _SML_CLIENT_H */ diff --git a/apps/drwho/SML_Server.cpp b/apps/drwho/SML_Server.cpp index e1ddcb83990..4e9e15aaa86 100644 --- a/apps/drwho/SML_Server.cpp +++ b/apps/drwho/SML_Server.cpp @@ -1,10 +1,10 @@ // $Id$ #include "SML_Server.h" -#ifndef __OPTIMIZE__ SML_Server::SML_Server (void) -{} +{ +} SML_Server::~SML_Server (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/SML_Server.h b/apps/drwho/SML_Server.h index b5ab3474a80..cb1f1d0d80e 100644 --- a/apps/drwho/SML_Server.h +++ b/apps/drwho/SML_Server.h @@ -1,7 +1,20 @@ /* -*- C++ -*- */ // $Id$ -#ifndef _SML_SERVER_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SML_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SML_SERVER_H) #define _SML_SERVER_H #include "SM_Server.h" @@ -9,17 +22,8 @@ class SML_Server : public SM_Server { public: - SML_Server (void); - virtual ~SML_Server (void); + SML_Server (void); + virtual ~SML_Server (void); }; -#ifdef __OPTIMIZE__ -inline -SML_Server::SML_Server (void) -{} - -inline -SML_Server::~SML_Server (void) -{} -#endif /* __OPTIMIZE__ */ #endif /* _SML_SERVER_H */ diff --git a/apps/drwho/SMR_Client.cpp b/apps/drwho/SMR_Client.cpp index cd3d97717d5..f0c9c777db9 100644 --- a/apps/drwho/SMR_Client.cpp +++ b/apps/drwho/SMR_Client.cpp @@ -1,19 +1,21 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "PMC_All.h" #include "PMC_Flo.h" #include "PMC_Usr.h" #include "PMC_Ruser.h" #include "SMR_Client.h" -#ifndef __OPTIMIZE__ SMR_Client::SMR_Client (short port_number) { if (CM_Client::open (port_number) < 0) - perror (Options::program_name), exit (1); + ACE_ERROR ((LM_ERROR, + "%p\n%a", + Options::program_name, + 1)); } SMR_Client::~SMR_Client (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/SMR_Client.h b/apps/drwho/SMR_Client.h index 11a8b7cbf9b..dc3081f1210 100644 --- a/apps/drwho/SMR_Client.h +++ b/apps/drwho/SMR_Client.h @@ -1,7 +1,20 @@ /* -*- C++ -*- */ // $Id$ -#ifndef _SMR_CLIENT_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SMR_Client.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SMR_CLIENT_H) #define _SMR_CLIENT_H #include "SM_Client.h" @@ -9,20 +22,8 @@ class SMR_Client : public SM_Client { public: - SMR_Client (short port_number); - virtual ~SMR_Client (void); + SMR_Client (short port_number); + virtual ~SMR_Client (void); }; -#ifdef __OPTIMIZE__ -inline -SMR_Client::SMR_Client (short port_number) -{ - if (CM_Client::open (port_number) < 0) - perror (Options::program_name), exit (1); -} - -inline -SMR_Client::~SMR_Client (void) -{} -#endif /* __OPTIMIZE__ */ #endif /* _SMR_CLIENT_H */ diff --git a/apps/drwho/SMR_Server.cpp b/apps/drwho/SMR_Server.cpp index 0c43d480b86..109e432fa81 100644 --- a/apps/drwho/SMR_Server.cpp +++ b/apps/drwho/SMR_Server.cpp @@ -1,14 +1,17 @@ // $Id$ + #include "Options.h" #include "SMR_Server.h" -#ifndef __OPTIMIZE__ SMR_Server::SMR_Server (short port_number) { if (CM_Server::open (port_number) < 0) - perror (Options::program_name), exit (1); + ACE_ERROR ((LM_ERROR, + "%p\n%a", + Options::program_name, + 1)); } SMR_Server::~SMR_Server (void) -{} -#endif /* __OPTIMIZE__ */ +{ +} diff --git a/apps/drwho/SMR_Server.h b/apps/drwho/SMR_Server.h index 29c4281af7d..d471245aeae 100644 --- a/apps/drwho/SMR_Server.h +++ b/apps/drwho/SMR_Server.h @@ -1,7 +1,20 @@ /* -*- C++ -*- */ // $Id$ -#ifndef _SMR_SERVER_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SMR_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SMR_SERVER_H) #define _SMR_SERVER_H #include "SM_Server.h" @@ -9,20 +22,8 @@ class SMR_Server : public SM_Server { public: - SMR_Server (short port_number); - ~SMR_Server (void); + SMR_Server (short port_number); + ~SMR_Server (void); }; -#ifdef __OPTIMIZE__ -inline -SMR_Server::SMR_Server (short port_number) -{ - if (CM_Server::open (port_number) < 0) - perror (Options::program_name), exit (1); -} - -inline -SMR_Server::~SMR_Server (void) -{} -#endif /* __OPTIMIZE__ */ #endif /* _SMR_SERVER_H */ diff --git a/apps/drwho/SM_Client.cpp b/apps/drwho/SM_Client.cpp index 074684076c0..3d32834f8e1 100644 --- a/apps/drwho/SM_Client.cpp +++ b/apps/drwho/SM_Client.cpp @@ -1,23 +1,25 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "PMC_All.h" #include "PMC_Flo.h" #include "PMC_Usr.h" #include "PMC_Ruser.h" #include "SM_Client.h" -/* Call-back function that invokes the appropriate decode function. */ +// Call-back function that invokes the appropriate decode function. int -SM_Client::demux (char *packet, int &packet_length) +SM_Client::demux (char *packet, + int &packet_length) { if (this->pm_client->decode (packet, packet_length) < 0) return -1; - return 1; + else + return 1; } -/* Call-back function that invokes the appropriate encode function. */ +// Call-back function that invokes the appropriate encode function. int SM_Client::mux (char *packet, int &packet_length) @@ -25,19 +27,29 @@ SM_Client::mux (char *packet, int &packet_length) switch (Options::protocol_type) { case Options::PROTO_USR: - this->pm_client = new (PRIVATE_POOL) PMC_Usr (Options::user_name); + ACE_NEW_RETURN (this->pm_client, + PMC_Usr (Options::user_name), + -1); break; case Options::PROTO_ALL: - this->pm_client = new (PRIVATE_POOL) PMC_All; + ACE_NEW_RETURN (this->pm_client, + PMC_All, + -1); break; case Options::PROTO_FLO: - this->pm_client = new (PRIVATE_POOL) PMC_Flo; + ACE_NEW_RETURN (this->pm_client, + PMC_Flo, + -1); break; case Options::PROTO_RUSER: - this->pm_client = new (PRIVATE_POOL) PMC_Ruser; + ACE_NEW_RETURN (this->pm_client, + PMC_Ruser, + -1); break; default: - fprintf (stderr, "%s: bad protocol\n", Options::program_name); + ACE_DEBUG ((LM_DEBUG, + "%s: bad protocol\n", + Options::program_name)); return -1; } @@ -46,16 +58,16 @@ SM_Client::mux (char *packet, int &packet_length) return 1; } -#ifndef __OPTIMIZE__ SM_Client::SM_Client (void) -{} +{ +} SM_Client::~SM_Client (void) -{} +{ +} void SM_Client::process (void) { this->pm_client->process (); } -#endif /* __OPTIMIZE__ */ diff --git a/apps/drwho/SM_Client.h b/apps/drwho/SM_Client.h index 3c33f3bd45e..884ad94b4de 100644 --- a/apps/drwho/SM_Client.h +++ b/apps/drwho/SM_Client.h @@ -1,7 +1,20 @@ /* -*- C++ -*- */ // $Id$ -#ifndef _SM_CLIENT_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SM_Client.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SM_CLIENT_H) #define _SM_CLIENT_H #include "PM_Client.h" @@ -10,30 +23,16 @@ class SM_Client : public Select_Manager, public CM_Client { -private: - PM_Client *pm_client; - public: - SM_Client (void); - virtual int mux (char *packet, int &packet_length); - virtual int demux (char *packet, int &packet_length); - virtual void process (void); - virtual ~SM_Client (void); -}; + SM_Client (void); + virtual ~SM_Client (void); -#ifdef __OPTIMIZE__ -inline -SM_Client::SM_Client (void) -{} + virtual int mux (char *packet, int &packet_length); + virtual int demux (char *packet, int &packet_length); + virtual void process (void); -inline -SM_Client::~SM_Client (void) -{} +private: + PM_Client *pm_client; +}; -inline void -SM_Client::process (void) -{ - this->pm_client->process (); -} -#endif /* __OPTIMIZE__ */ #endif /* _SM_CLIENT_H */ diff --git a/apps/drwho/SM_Server.cpp b/apps/drwho/SM_Server.cpp index 8709f6132d4..95fe8bb2b65 100644 --- a/apps/drwho/SM_Server.cpp +++ b/apps/drwho/SM_Server.cpp @@ -1,5 +1,5 @@ // $Id$ -#include "new.h" + #include "Options.h" #include "PMS_All.h" #include "PMS_Flo.h" @@ -10,26 +10,37 @@ int SM_Server::demux (char *packet, int &packet_length) { - /* SUPPRESS 112 */ switch (GET_PACKET_TYPE (packet)) { case Options::PROTO_USR: - this->pm_server = new (PRIVATE_POOL) PMS_Usr; + ACE_NEW_RETURN (this->pm_server, + PMS_Usr, + -1); break; case Options::PROTO_ALL: - this->pm_server = new (PRIVATE_POOL) PMS_All; + ACE_NEW_RETURN (this->pm_server, + PMS_All, + -1); break; case Options::PROTO_FLO: - this->pm_server = new (PRIVATE_POOL) PMS_Flo; + ACE_NEW_RETURN (this->pm_server, + PMS_Flo, + -1); break; case Options::PROTO_RUSER: - this->pm_server = new (PRIVATE_POOL) PMS_Ruser; + ACE_NEW_RETURN (this->pm_server, + PMS_Ruser, + -1); break; default: + ACE_DEBUG ((LM_DEBUG, + "%s: bad protocol\n", + Options::program_name)); return -1; } - if (pm_server->decode (SKIP_PACKET_TYPE (packet), SUBTRACT_PACKET_TYPE (packet_length)) < 0) + if (pm_server->decode (SKIP_PACKET_TYPE (packet), + SUBTRACT_PACKET_TYPE (packet_length)) < 0) return -1; if (pm_server->process () < 0) @@ -39,21 +50,16 @@ SM_Server::demux (char *packet, int &packet_length) } int -SM_Server::mux (char *packet, int &packet_length) +SM_Server::mux (char *packet, + int &packet_length) { - int status = pm_server->encode (packet, packet_length); - - /* Hum... should this really go here? */ - if (Options::get_opt (Options::STAND_ALONE_SERVER)) - release_memory (); - return status; + return pm_server->encode (packet, packet_length); } -#ifndef __OPTIMIZE__ SM_Server::SM_Server (void) -{} +{ +} SM_Server::~SM_Server (void) -{} -#endif /* __OPTIMIZE__ */ - +{ +} diff --git a/apps/drwho/SM_Server.h b/apps/drwho/SM_Server.h index fbad338adf9..83aa063cd72 100644 --- a/apps/drwho/SM_Server.h +++ b/apps/drwho/SM_Server.h @@ -1,7 +1,20 @@ /* -*- C++ -*- */ // $Id$ -#ifndef _SM_SERVER_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// SM_Server.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SM_SERVER_H) #define _SM_SERVER_H #include "PM_Server.h" @@ -10,23 +23,14 @@ class SM_Server : public Select_Manager, public CM_Server { -private: - PM_Server *pm_server; - public: - SM_Server (void); - virtual ~SM_Server (void); + SM_Server (void); + virtual ~SM_Server (void); virtual int mux (char *packet, int &packet_length); virtual int demux (char *packet, int &packet_length); -}; -#ifdef __OPTIMIZE__ -inline -SM_Server::SM_Server (void) -{} +private: + PM_Server *pm_server; +}; -inline -SM_Server::~SM_Server (void) -{} -#endif /* __OPTIMIZE__ */ #endif /* _SM_SERVER_H */ diff --git a/apps/drwho/Search_Struct.cpp b/apps/drwho/Search_Struct.cpp index eb1a52ba71e..e796353b987 100644 --- a/apps/drwho/Search_Struct.cpp +++ b/apps/drwho/Search_Struct.cpp @@ -1,20 +1,22 @@ // $Id$ + #include "Options.h" #include "Search_Struct.h" -#ifndef __OPTIMIZE__ Search_Struct::~Search_Struct (void) { if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "disposing Search_Struct\n"); + ACE_DEBUG ((LM_DEBUG, + "disposing Search_Struct\n")); } -Search_Struct::Search_Struct (void): count (0) +Search_Struct::Search_Struct (void) + : count_ (0) {} int Search_Struct::n_elems (void) { - return this->count; + return this->count_; } -#endif /* __OPTIMIZE__ */ + diff --git a/apps/drwho/Search_Struct.h b/apps/drwho/Search_Struct.h index e8f8e6b0a48..6f476c2b4c0 100644 --- a/apps/drwho/Search_Struct.h +++ b/apps/drwho/Search_Struct.h @@ -1,42 +1,41 @@ /* -*- C++ -*- */ // $Id$ -/* Provides an "Abstract Base Class" lookup table abstraction that - stores and manipulates friend records. */ - -#ifndef _SEARCH_STRUCT_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Search_Struct.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SEARCH_STRUCT_H) #define _SEARCH_STRUCT_H #include "Protocol_Record.h" class Search_Struct { -protected: - int count; - + // = TITLE + // Provides an "Abstract Base Class" lookup table abstraction that + // stores and manipulates friend records. public: - Search_Struct (void); - virtual ~Search_Struct (void); - virtual int n_elems (void); - - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN) = 0; - virtual Protocol_Record *get_next_entry (void) = 0; - virtual Protocol_Record *get_each_entry (void) = 0; -}; + Search_Struct (void); + virtual ~Search_Struct (void); + virtual int n_elems (void); -#ifdef __OPTIMIZE__ -inline -Search_Struct::~Search_Struct (void) -{} + virtual Protocol_Record *insert (char *key_name, + int max_len = MAXUSERIDNAMELEN) = 0; + virtual Protocol_Record *get_next_entry (void) = 0; + virtual Protocol_Record *get_each_entry (void) = 0; -inline -Search_Struct::Search_Struct (void): count (0) -{} +protected: + int count_; +}; -inline int -Search_Struct::n_elems (void) -{ - return this->count; -} -#endif /* __OPTIMIZE__ */ #endif /* _SEARCH_STRUCT_H */ diff --git a/apps/drwho/Select_Manager.h b/apps/drwho/Select_Manager.h index 0c06d47dc3f..c4f89b7e57b 100644 --- a/apps/drwho/Select_Manager.h +++ b/apps/drwho/Select_Manager.h @@ -1,12 +1,30 @@ -// $Id$ /* -*- C++ -*- */ -#ifndef _SELECT_MANAGER_H +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Select_Manager.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SELECT_MANAGER_H) #define _SELECT_MANAGER_H class Select_Manager { public: - virtual int mux (char *packet, int &packet_length) = 0 ; - virtual int demux (char *packet, int &packet_length) = 0; + virtual int mux (char *packet, + int &packet_length) = 0 ; + + virtual int demux (char *packet, + int &packet_length) = 0; }; + #endif /* _SELECT_MANAGER_H */ diff --git a/apps/drwho/Single_Lookup.cpp b/apps/drwho/Single_Lookup.cpp index 55751170bc9..92f6a79115b 100644 --- a/apps/drwho/Single_Lookup.cpp +++ b/apps/drwho/Single_Lookup.cpp @@ -1,18 +1,19 @@ // $Id$ + #include "Options.h" -#include "new.h" #include "Single_Lookup.h" -#ifndef __OPTIMIZE__ Single_Lookup::Single_Lookup (char *usr_name) { - this->frp = new (PRIVATE_POOL) Protocol_Record (ACE::strnew (usr_name)); + ACE_NEW (this->frp, + Protocol_Record (ACE::strnew (usr_name))); } Single_Lookup::~Single_Lookup (void) { if (Options::get_opt (Options::DEBUG)) - fprintf (stderr, "disposing Single_Lookup\n"); + ACE_DEBUG ((LM_DEBUG, + "disposing Single_Lookup\n")); } Protocol_Record * @@ -26,4 +27,3 @@ Single_Lookup::get_next_entry (void) { return this->get_each_entry (); } -#endif /* __OPTIMIZE__ */ diff --git a/apps/drwho/Single_Lookup.h b/apps/drwho/Single_Lookup.h index e114b172656..754619bc201 100644 --- a/apps/drwho/Single_Lookup.h +++ b/apps/drwho/Single_Lookup.h @@ -1,9 +1,20 @@ /* -*- C++ -*- */ // $Id$ -/* Provides the client's single user lookup table abstraction. */ - -#ifndef _SINGLE_LOOKUP_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// Single_Lookup.h +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_SINGLE_LOOKUP_H) #define _SINGLE_LOOKUP_H #include "Options.h" @@ -11,41 +22,18 @@ class Single_Lookup : public Search_Struct { -protected: - Protocol_Record *frp; - + // = DESCRIPTION + // Provides the client's single user lookup table abstraction. public: - Single_Lookup (char *usr_name); - virtual ~Single_Lookup (void); - virtual Protocol_Record *insert (char *key_name, int max_len = MAXUSERIDNAMELEN) = 0; + Single_Lookup (char *usr_name); + virtual ~Single_Lookup (void); + virtual Protocol_Record *insert (char *key_name, + int max_len = MAXUSERIDNAMELEN) = 0; virtual Protocol_Record *get_next_entry (void); virtual Protocol_Record *get_each_entry (void); -}; - -#ifdef __OPTIMIZE__ -inline -Single_Lookup::Single_Lookup (char *usr_name) -{ - this->frp = new Protocol_Record (ACE::strnew (usr_name)); -} -inline -Single_Lookup::~Single_Lookup (void) -{ - if (Options::DEBUG) - fprintf (stderr, "disposing Single_Lookup\n"); -} - -inline Protocol_Record * -Single_Lookup::get_each_entry (void) -{ - return this->frp; -} +protected: + Protocol_Record *frp; +}; -inline Protocol_Record * -Single_Lookup::get_next_entry (void) -{ - return this->get_each_entry (); -} -#endif /* __OPTIMIZE__ */ #endif /* _SINGLE_LOOKUP_H */ diff --git a/apps/drwho/client.cpp b/apps/drwho/client.cpp index f1b51483a1e..d5af3907ae9 100644 --- a/apps/drwho/client.cpp +++ b/apps/drwho/client.cpp @@ -1,5 +1,4 @@ // $Id$ -// $Id$ // ============================================================================ // @@ -17,9 +16,7 @@ // // ============================================================================ -#include "ace/OS.h" #include "Options.h" -#include "new.h" #include "SML_Client.h" #include "SMR_Client.h" @@ -28,10 +25,18 @@ static SM_Client * make_client (void) { + SM_Client *client = 0; + if (Options::get_opt (Options::REMOTE_USAGE) == 0) - return new (PRIVATE_POOL) SML_Client; + + ACE_NEW_RETURN (client, + SML_Client, + 0); else - return new (PRIVATE_POOL) SMR_Client (Options::port_number); + ACE_NEW_RETURN (client, + SMR_Client (Options::port_number), + 0); + return client; } int @@ -39,8 +44,6 @@ main (int argc, char *argv[]) { Options::set_options (argc, argv); - mark_memory (); - SM_Client *sm_client = make_client (); if (sm_client->send () < 0) diff --git a/apps/drwho/global.h b/apps/drwho/global.h index 0352ca36e31..090b20b5b33 100644 --- a/apps/drwho/global.h +++ b/apps/drwho/global.h @@ -1,35 +1,48 @@ /* -*- C++ -*- */ // $Id$ -/* Here are all the declarations that are needed throughout the program. */ - -#ifndef _GLOBAL_H +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// global.h +// +// = DESCRIPTION +// Here are all the declarations that are needed throughout the program. */ +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + +#if !defined (_GLOBAL_H) #define _GLOBAL_H -/* These constants are used throughout the program... */ +#include "ace/OS.h" + +// These constants are used throughout drwho. enum { - MAXUSERIDNAMELEN = 8, - MAX_USER_TIMEOUT = 300, - MAX_HOST_TIMEOUT = 300, -#ifdef i386 - UDP_PACKET_SIZE = 0x2000, -#else - UDP_PACKET_SIZE = 0x4000, -#endif - PORT_NUMBER = 12344 -/* MAXPATHLEN = 1024, - MAXHOSTNAMELEN = 64 + 1 */ + MAXUSERIDNAMELEN = 8, + MAX_USER_TIMEOUT = 300, + MAX_HOST_TIMEOUT = 300, + UDP_PACKET_SIZE = 1024 * 8, + PORT_NUMBER = 12344 }; -/* Default name of file where friends info is stored. */ +// Default name of file where friends info is stored. #define FRIEND_FILE ".friends.dta" -/* Default name where rwho info is stored. */ +// Default name where rwho info is stored. #define RWHODIR "/usr/spool/rwho" -/* Daemon creator. */ -extern void daemon_start (int ignsigcld); +// Macros for handling message types. +#define GET_PACKET_TYPE(P) (ntohs (*((short *) P))) +#define SET_PACKET_TYPE(P,T) ((*(short *) P) = ntohs (T)) +#define SKIP_PACKET_TYPE(P) ((P) + sizeof (short)) +#define SUBTRACT_PACKET_TYPE(L) ((L) - sizeof (short)) #endif /* _GLOBAL_H */ diff --git a/apps/drwho/rwhod.h b/apps/drwho/rwhod.h deleted file mode 100644 index d884f5cd27a..00000000000 --- a/apps/drwho/rwhod.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -/* The /usr/include/protocols/rwhod.h header breaks cfront 2.0... */ - -#ifndef _RWHOD_H -#define _RWHOD_H - -struct outmp -{ - char out_line[8]; /* tty name */ - char out_name[8]; /* user id */ - long out_time; /* time on */ -}; - -struct whoent -{ - outmp we_utmp; /* active tty info */ - int we_idle; /* tty idle time */ -}; - -struct whod -{ - char wd_vers; /* protocol version # */ - char wd_type; /* packet type, see below */ - char wd_pad[2]; - int wd_sendtime; /* time stamp by sender */ - int wd_recvtime; /* time stamp applied by receiver */ - char wd_hostname[32]; /* hosts's name */ - int wd_loadav[3]; /* load average as in uptime */ - int wd_boottime; /* time system booted */ - whoent wd_we[1024 / sizeof (struct whoent)]; -}; - -#define WHODVERSION 1 -#define WHODTYPE_STATUS 1 /* host status */ - -#endif /* _RWHOD_H */ diff --git a/apps/drwho/server.cpp b/apps/drwho/server.cpp index 3ae1adb6919..e3ce637f2e0 100644 --- a/apps/drwho/server.cpp +++ b/apps/drwho/server.cpp @@ -1,72 +1,90 @@ // $Id$ -/* Driver program for the server. Note that it is easy to reuse the - server for other distributed programs. Pretty much all that must - change are the functions registered with the communciations - manager. */ -#include "ace/OS.h" +// ============================================================================ +// +// = LIBRARY +// drwho +// +// = FILENAME +// server.cpp +// +// = DESCRIPTION +// Driver program for the server. Note that it is easy to reuse the +// server for other distributed programs. Pretty much all that must +// change are the functions registered with the communciations +// manager. +// +// = AUTHOR +// Douglas C. Schmidt +// +// ============================================================================ + #include "Options.h" -#include "new.h" #include "SMR_Server.h" static char * tstamp (void) { - long time_now; - char *temp; + long time_now; + char *temp; - time_now = time (0); - temp = asctime (localtime (&time_now)); + time_now = ACE_OS::time (0); + temp = ACE_OS::asctime (ACE_OS::localtime (&time_now)); temp[12] = 0; return temp; } -/* Catch the obvious signals and die with dignity... */ +// Catch the obvious signals and die with dignity... static void exit_server (int sig) { - char buffer[80]; - sprintf (buffer, "%s exiting on signal", tstamp ()); - psignal (sig, buffer); - monitor (0); - exit (0); + ACE_DEBUG ((LM_DEBUG, + "%s exiting on signal %S", + tstamp (), + sig)); + ACE_OS::exit (0); } -/* Returns TRUE if the program was started by INETD. */ +// Returns TRUE if the program was started by INETD. static int started_by_inetd (void) { - /* SUPPRESS 175 */ - sockaddr_in sin; - int size = sizeof sin; + sockaddr_in sin; + int size = sizeof sin; - return getsockname (0, (sockaddr *) &sin, &size) == 0; + return ACE_OS::getsockname (0, + (sockaddr *) &sin, + &size) == 0; } -/* Does the drwho service. */ +// Does the drwho service. static void do_drwho (SMR_Server &smr_server) { if (smr_server.receive () == -1) - perror (Options::program_name); + ACE_ERROR ((LM_ERROR, + "%p\n", + Options::program_name)); if (smr_server.send () == -1) - perror (Options::program_name); + ACE_ERROR ((LM_ERROR, + "%p\n", + Options::program_name)); } -/* If the server is started with any argument at all then it doesn't - fork off a child process to do the work. This is useful when - debugging! */ +// If the server is started with any argument at all then it doesn't +// fork off a child process to do the work. This is useful when +// debugging! int main (int argc, char *argv[]) { - signal (SIGTERM, SIG_PF (exit_server)); - signal (SIGINT, SIG_PF (exit_server)); - signal (SIGQUIT, SIG_PF (exit_server)); + ACE_OS::signal (SIGTERM, exit_server); + ACE_OS::signal (SIGINT, exit_server); + ACE_OS::signal (SIGQUIT, exit_server); Options::set_options (argc, argv); Options::set_opt (Options::STAND_ALONE_SERVER); @@ -74,14 +92,10 @@ main (int argc, char *argv[]) int inetd_controlled = started_by_inetd (); if (!inetd_controlled && Options::get_opt (Options::BE_A_DAEMON)) - daemon_start (1); - - mark_memory (); + ACE::daemonize (); SMR_Server smr_server (Options::port_number); - /* I'm not sure what this should do yet... */ - if (inetd_controlled) do_drwho (smr_server); else @@ -92,5 +106,6 @@ main (int argc, char *argv[]) /* NOTREACHED */ } - exit (0); + + return 0; } |