Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / apps / drwho / PMS_Ruser.cpp
blobe029fda6c9865caaf10d18ad7a86d0109ccea9a1
1 #include "Options.h"
2 #include "HT_Server.h"
3 #include "PMS_Ruser.h"
4 #include "ace/ACE.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_pwd.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/OS_NS_stdio.h"
10 #include "ace/OS_Memory.h"
11 #include "ace/os_include/os_netdb.h"
13 // This function packs the located friends userids, plus the machines
14 // they are logged into (along with the inactive and active counts on
15 // each machine) into a buffer that is subsequently transmitted back
16 // to the client across the network. Note that this function encodes
17 // the REAL_NAME of the user in the packet.
19 int
20 PMS_Ruser::encode (char *packet, int &packet_length)
22 if (Options::get_opt (Options::DEBUGGING) != 0)
23 ACE_DEBUG ((LM_DEBUG,
24 "in PMS_Ruser::encode"));
26 Protocol_Record *prp;
27 char *buf_ptr = packet;
29 ACE_OS::sprintf (buf_ptr,
30 "Users %d",
31 this->get_total_users ());
32 buf_ptr += ACE_OS::strlen (buf_ptr) + 1;
34 // We only send back info on hosts that we actually see.
36 for (;
37 (prp = this->get_next_friend ()) != 0;
38 *buf_ptr++ = '\t')
39 buf_ptr = this->handle_protocol_entries (ACE_OS::strecpy (buf_ptr,
40 prp->get_host ()),
41 prp->get_drwho_list ());
43 *buf_ptr++ = '\n';
44 packet_length = buf_ptr - packet;
46 if (Options::get_opt (Options::DEBUGGING) != 0)
48 ACE_DEBUG ((LM_DEBUG,
49 "packet_length = %d\n",
50 packet_length));
51 ACE_OS::write (ACE_STDERR, packet, packet_length);
52 ACE_DEBUG ((LM_DEBUG,
53 "\n"));
55 return 1;
58 // This function takes a packet received from the client and crusers
59 // the appropriate Protocol_Manager routine to build the local table
60 // of friends.
62 int
63 PMS_Ruser::decode (char *packet, int &packet_length)
65 if (Options::get_opt (Options::DEBUGGING) != 0)
66 ACE_DEBUG ((LM_DEBUG,
67 "in PMS_Ruser::decode, packet_length = %d\n",
68 packet_length));
70 if (*packet)
71 Options::set_opt (Options::PRINT_LOGIN_NAME);
73 ACE_NEW_RETURN (this->ss,
74 HT_Server,
75 -1);
76 return 1;
79 Protocol_Record *
80 PMS_Ruser::insert_protocol_info (Protocol_Record &protocol_record)
82 Drwho_Node *current_node = protocol_record.get_drwho_list ();
83 Protocol_Record *prp = this->ss->insert (current_node->get_host_name (),
84 MAXHOSTNAMELEN);
85 Drwho_Node *np = this->get_drwho_node (ACE::strnnew (protocol_record.get_login (),
86 MAXUSERIDNAMELEN),
87 prp->drwho_list_);
89 if (Options::get_opt (Options::PRINT_LOGIN_NAME))
90 np->set_real_name ("");
91 else
93 passwd *pwent = ACE_OS::getpwnam (np->get_login_name ());
94 char *cp =
95 (char *) ACE_OS::strchr (np->set_real_name (pwent == 0
96 ? np->get_login_name ()
97 : ACE::strnew (pwent->pw_gecos)),
98 ',');
99 if (cp != 0)
100 *cp = '\0';
103 if (current_node->get_idle_time () >= MAX_USER_TIMEOUT)
104 np->inactive_count_++;
105 else
106 np->active_count_++;
108 return prp;
111 char *
112 PMS_Ruser::handle_protocol_entries (char *buf_ptr,
113 Drwho_Node *np)
115 for (; np != 0; np = np->next_)
117 ACE_OS::sprintf (buf_ptr,
118 "%d %d ",
119 np->get_inactive_count (),
120 np->get_active_count ());
121 buf_ptr += ACE_OS::strlen (buf_ptr);
123 buf_ptr = ACE_OS::strecpy (ACE_OS::strecpy (buf_ptr,
124 np->get_login_name ()),
125 np->get_real_name ());
128 return buf_ptr;
131 PMS_Ruser::PMS_Ruser ()