summaryrefslogtreecommitdiff
path: root/apps/drwho/PMC_Usr.cpp
blob: ec5738044c32a1b1dfe739b1292b51a9e005aa95 (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
// $Id$

#include "Options.h"
#include "SL_Client.h"
#include "PMC_Usr.h"

int
PMC_Usr::encode (char *packet, int &packet_length)
{
  if (Options::get_opt (Options::DEBUG) != 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::strecpy (buf_ptr,
                          this->get_next_friend ()->get_login ());

  packet_length = buf_ptr - packet;

  if (Options::get_opt (Options::DEBUG) != 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::DEBUG) != 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)
{
}