Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / apps / drwho / PMS_All.cpp
blob6379074467d74e0dfbb55f474d6c3655f5c82958
1 #include "Options.h"
2 #include "HT_Server.h"
3 #include "PMS_All.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"
12 // This function packs the located friends userids, plus the machines
13 // they are logged into (along with the inactive and active counts on
14 // each machine) into a buffer that is subsequently transmitted back
15 // to the client across the network. Note that this function encodes
16 // the REAL_NAME of the user in the packet.
18 int
19 PMS_All::encode (char *packet, int &packet_length)
21 if (Options::get_opt (Options::DEBUGGING) != 0)
22 ACE_DEBUG ((LM_DEBUG,
23 "in PMS_All::encode"));
25 Protocol_Record *prp;
26 char *buf_ptr = packet;
28 ACE_OS::sprintf (buf_ptr,
29 "Users %d",
30 this->get_total_users ());
31 buf_ptr += ACE_OS::strlen (buf_ptr) + 1;
33 // We only send back info on friends that we actually see logged in.
35 for (;
36 (prp = this->get_next_friend ()) != 0;
37 *buf_ptr++ = '\t')
38 buf_ptr =
39 this->handle_protocol_entries (ACE_OS::strecpy
40 (ACE_OS::strecpy (buf_ptr,
41 prp->get_login ()),
42 prp->get_real ()),
43 prp->get_drwho_list ());
45 *buf_ptr++ = '\n';
46 packet_length = buf_ptr - packet;
48 if (Options::get_opt (Options::DEBUGGING) != 0)
50 ACE_DEBUG ((LM_DEBUG,
51 "packet_length = %d\n",
52 packet_length));
53 ACE_OS::write (ACE_STDERR, packet, packet_length);
54 ACE_DEBUG ((LM_DEBUG,
55 "\n"));
57 return 1;
60 // This function takes a packet received from the client and calls the
61 // appropriate Protocol_Manager routine to build the local table of
62 // friends.
64 int
65 PMS_All::decode (char *, int &packet_length)
67 if (Options::get_opt (Options::DEBUGGING) != 0)
68 ACE_DEBUG ((LM_DEBUG,
69 "in PMS_All::decode, packet_length = %d\n",
70 packet_length));
72 ACE_NEW_RETURN (this->ss,
73 HT_Server,
74 -1);
75 return 1;
78 // We only want the user's real name, not the gecos junk after the
79 // first leading ','. However, if the real-name is not in the
80 // password file, just return the login name instead.
82 Protocol_Record *
83 PMS_All::insert_protocol_info (Protocol_Record &protocol_record)
85 Protocol_Record *prp = PM_Server::insert_protocol_info (protocol_record);
86 passwd *pwent = ACE_OS::getpwnam (prp->get_login ());
87 char *cp = (char *) ACE_OS::strchr (prp->set_real
88 (pwent == 0
89 ? prp->get_login () :
90 ACE::strnew (pwent->pw_gecos)),
91 ',');
92 if (cp != 0)
93 *cp = '\0';
95 return prp;
98 PMS_All::PMS_All ()