Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / apps / drwho / PMC_Ruser.cpp
blob5e764bfdc349a8b4236f452a86800a274ac38678
1 #include "global.h"
2 #include "Options.h"
3 #include "HT_Client.h"
4 #include "PMC_Ruser.h"
5 #include "ace/ACE.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/OS_NS_stdlib.h"
10 #include "ace/OS_Memory.h"
11 #include "ace/os_include/os_netdb.h"
13 // This function is pretty much a no-op that just sets up the
14 // appropriate lookup function to use.
16 int
17 PMC_Ruser::encode (char *packet, int &packet_length)
19 if (Options::get_opt (Options::DEBUGGING) != 0)
20 ACE_DEBUG ((LM_DEBUG,
21 "in PMC_Ruser::encode\n"));
23 ACE_NEW_RETURN (this->ss,
24 HT_Client,
25 -1);
27 SET_PACKET_TYPE (packet, Options::PROTO_RUSER);
29 char *buf_ptr = SKIP_PACKET_TYPE (packet);
31 *buf_ptr++ = char (Options::get_opt (Options::PRINT_LOGIN_NAME));
33 packet_length = buf_ptr - packet;
34 return 1;
37 // This method is responsible for transforming the msg from the server
38 // back into a form usable by the client. Note that it reads the
39 // REAL_NAME from the packet (since the server placed it there)...
41 int
42 PMC_Ruser::decode (char *packet, int &packet_length)
44 if (Options::get_opt (Options::DEBUGGING) != 0)
46 ACE_DEBUG ((LM_DEBUG,
47 "in PMC_Ruser::decode, packet_length = %d\n",
48 packet_length));
49 ACE_OS::write (ACE_STDERR, packet, packet_length);
50 ACE_DEBUG ((LM_DEBUG,
51 "\n"));
53 char *cp = packet;
54 int remote_users = 0;
56 sscanf (cp,
57 "Users %d",
58 &remote_users);
60 this->increment_total_users (remote_users);
62 for (cp = (char *) ACE::strend (cp);
63 *cp != '\n';
64 cp++)
66 char *host_name = cp;
68 for (cp = (char *) ACE::strend (cp);
69 *(cp = this->handle_protocol_entries (cp, host_name)) != '\t'; )
70 continue;
73 return 1;
76 Protocol_Record *
77 PMC_Ruser::insert_protocol_info (Protocol_Record &protocol_record)
79 Protocol_Record *prp = this->ss->insert (protocol_record.get_host (),
80 MAXHOSTNAMELEN);
81 Drwho_Node *current_node = protocol_record.get_drwho_list ();
82 Drwho_Node *np = this->get_drwho_node (ACE::strnnew (current_node->get_login_name (),
83 MAXUSERIDNAMELEN),
84 prp->drwho_list_);
85 int length = ACE_OS::strlen (prp->get_host ());
87 np->set_real_name (ACE::strnew (current_node->get_real_name ()));
89 if (np->get_active_count () < current_node->get_active_count ())
90 np->set_active_count (current_node->get_active_count ());
91 if (np->get_inactive_count () < current_node->get_inactive_count())
92 np->set_inactive_count (current_node->get_inactive_count ());
94 if (length > this->max_key_length)
95 this->max_key_length = length;
97 return prp;
100 char *
101 PMC_Ruser::handle_protocol_entries (const char *cp,
102 const char *host_name,
103 const char *)
105 static Protocol_Record protocol_record (1);
106 Drwho_Node *current_node = protocol_record.get_drwho_list ();
108 protocol_record.set_host (host_name);
109 current_node->set_inactive_count (ACE_OS::atoi (cp));
110 current_node->set_active_count (ACE_OS::atoi (cp = ACE_OS::strchr (cp, ' ') + 1));
111 current_node->set_login_name (cp = ACE_OS::strchr (cp, ' ') + 1);
112 current_node->set_real_name (cp = ACE_OS::strchr (cp, '\0') + 1);
114 this->insert_protocol_info (protocol_record);
116 return (char *) ACE::strend (cp);
119 void
120 PMC_Ruser::process ()
122 const char *(Drwho_Node::*get_name)();
124 if (Options::get_opt (Options::PRINT_LOGIN_NAME))
125 get_name = &Drwho_Node::get_login_name;
126 else
127 get_name = &Drwho_Node::get_real_name;
129 for (Protocol_Record *prp;
130 (prp = this->Protocol_Manager::get_each_friend ()) != 0;
133 ACE_DEBUG ((LM_DEBUG,
134 "%-*s ",
135 this->max_key_length,
136 prp->get_host ()));
138 for (Drwho_Node *np = prp->get_drwho_list (); ;)
140 ACE_DEBUG ((LM_DEBUG,
141 "%s",
142 (np->*get_name) ()));
144 if (np->get_inactive_count () != 0)
146 if (np->get_active_count () != 0)
147 ACE_DEBUG ((LM_DEBUG,
148 "*(%d)",
149 np->get_active_count ()));
151 else if (np->get_active_count () > 1)
152 ACE_DEBUG ((LM_DEBUG,
153 "*(%d)",
154 np->get_active_count ()));
155 else if (np->get_active_count () == 1)
156 ACE_DEBUG ((LM_DEBUG,
157 "*"));
159 np = np->next_;
160 if (np == 0)
161 break;
162 else if (Options::get_opt (Options::PRINT_LOGIN_NAME))
163 ACE_DEBUG ((LM_DEBUG,
164 " "));
165 else
166 ACE_DEBUG ((LM_DEBUG,
167 ", "));
170 ACE_DEBUG ((LM_DEBUG,
171 "\n"));
175 PMC_Ruser::PMC_Ruser ()