summaryrefslogtreecommitdiff
path: root/ACE/apps/drwho/PMC_Usr.cpp
blob: a31edb5e7c6f7add2ce7534bd983a58a5f160923 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// $Id$

#include "Options.h"
#include "SL_Client.h"
#include "PMC_Usr.h"
#include "ace/ACE.h"
#include "ace/Log_Msg.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_Memory.h"

int
PMC_Usr::encode (char *packet, int &packet_length)
{
  if (Options::get_opt (Options::DEBUGGING) != 0)
    ACE_DEBUG ((LM_DEBUG,
                "in PMC_Usr::encode"));

  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_OS::strecpy (buf_ptr,
                             this->get_next_friend ()->get_login ());

  packet_length = buf_ptr - packet;

  if (Options::get_opt (Options::DEBUGGING) != 0)
    {
      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.

int
PMC_Usr::decode (char *packet, int &packet_length)
{
  if (Options::get_opt (Options::DEBUGGING) != 0)
    {
      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;

  if (*cp != '\n')
    {
      char *login_name = cp;

      for (cp = (char *) ACE::strend (cp);
           *(cp = this->handle_protocol_entries (cp, login_name)) != '\t';
           )
	continue;
    }

  return 1;
}

void
PMC_Usr::process (void)
{
  Protocol_Record *prp = this->get_each_friend ();
  Drwho_Node *np  = prp->get_drwho_list ();

  if (np == 0)
    ACE_DEBUG ((LM_DEBUG,
                "<unknown>"));
  else
    {
      // First try to get a login session that is active...

      for (; np != 0; np = np->next_)
	if (np->active_count_ > 0)
	  {
	    ACE_DEBUG ((LM_DEBUG,
                        "%s ",
                        np->get_host_name ()));

	    if (Options::get_opt (Options::USE_VERBOSE_FORMAT) == 0)
	      return;
	  }

      for (np = prp->get_drwho_list ();
           np != 0;
           np = np->next_)
	if (np->active_count_ == 0)
	  {
	    ACE_DEBUG ((LM_DEBUG,
                        "%s ",
                        np->get_host_name ()));

	    if (Options::get_opt (Options::USE_VERBOSE_FORMAT) == 0)
	      return;
	  }
    }
}

PMC_Usr::PMC_Usr (char *u_name)
  : usr_name (u_name)
{
}