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.
20 PMS_Ruser::encode (char *packet
, int &packet_length
)
22 if (Options::get_opt (Options::DEBUGGING
) != 0)
24 "in PMS_Ruser::encode"));
27 char *buf_ptr
= packet
;
29 ACE_OS::sprintf (buf_ptr
,
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.
37 (prp
= this->get_next_friend ()) != 0;
39 buf_ptr
= this->handle_protocol_entries (ACE_OS::strecpy (buf_ptr
,
41 prp
->get_drwho_list ());
44 packet_length
= buf_ptr
- packet
;
46 if (Options::get_opt (Options::DEBUGGING
) != 0)
49 "packet_length = %d\n",
51 ACE_OS::write (ACE_STDERR
, packet
, packet_length
);
58 // This function takes a packet received from the client and crusers
59 // the appropriate Protocol_Manager routine to build the local table
63 PMS_Ruser::decode (char *packet
, int &packet_length
)
65 if (Options::get_opt (Options::DEBUGGING
) != 0)
67 "in PMS_Ruser::decode, packet_length = %d\n",
71 Options::set_opt (Options::PRINT_LOGIN_NAME
);
73 ACE_NEW_RETURN (this->ss
,
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 (),
85 Drwho_Node
*np
= this->get_drwho_node (ACE::strnnew (protocol_record
.get_login (),
89 if (Options::get_opt (Options::PRINT_LOGIN_NAME
))
90 np
->set_real_name ("");
93 passwd
*pwent
= ACE_OS::getpwnam (np
->get_login_name ());
95 (char *) ACE_OS::strchr (np
->set_real_name (pwent
== 0
96 ? np
->get_login_name ()
97 : ACE::strnew (pwent
->pw_gecos
)),
103 if (current_node
->get_idle_time () >= MAX_USER_TIMEOUT
)
104 np
->inactive_count_
++;
112 PMS_Ruser::handle_protocol_entries (char *buf_ptr
,
115 for (; np
!= 0; np
= np
->next_
)
117 ACE_OS::sprintf (buf_ptr
,
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 ());
131 PMS_Ruser::PMS_Ruser ()