summaryrefslogtreecommitdiff
path: root/apps/Gateway/Gateway/Config_Files.cpp
blob: 12328282242a043241e667e436511001da559ce0 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// $Id$

#define ACE_BUILD_SVC_DLL

#include "Config_Files.h"
#include "Options.h"

ACE_RCSID(Gateway, Config_Files, "$Id$")

// This fixes a nasty bug with cfront-based compilers (like
// Centerline).
typedef FP::Return_Type FP_RETURN_TYPE;

FP_RETURN_TYPE
Consumer_Config_File_Parser::read_entry (Consumer_Config_Info &entry,
                                         int &line_number)
{
  FP_RETURN_TYPE result;

  // Increment the line count.
  line_number++;

  // Ignore comments, check for EOF and EOLINE if this succeeds, we
  // have our connection id.

  while ((result = this->getint (entry.connection_id_)) != FP::RT_SUCCESS)
    if (result == FP::RT_EOFILE)
      return FP::RT_EOFILE;
    else if (result == FP::RT_EOLINE
             || result == FP::RT_COMMENT)
      line_number++;

  // Get the payload type.
  result = this->getint (entry.type_);
  if (result != FP::RT_SUCCESS)
    return result;

  // get all the consumers.
  entry.total_consumers_ = 0;

  while ((result = this->getint
          (entry.consumers_[entry.total_consumers_])) == FP::RT_SUCCESS)
    ++entry.total_consumers_; // do nothing (should check against max...)

  if (result == FP::RT_EOLINE || result == FP::RT_EOFILE)
    return FP::RT_SUCCESS;
  else
    return result;
}

FP_RETURN_TYPE
Connection_Config_File_Parser::read_entry (Connection_Config_Info &entry,
                                           int &line_number)
{
  char buf[BUFSIZ];
  FP_RETURN_TYPE result;

  // Increment the line count.
  line_number++;

  // Ignore comments, check for EOF and EOLINE if this succeeds, we
  // have our connection id

  while ((result = this->getint (entry.connection_id_)) != FP::RT_SUCCESS)
    if (result == FP::RT_EOFILE)
      return FP::RT_EOFILE;
    else if (result == FP::RT_EOLINE
             || result == FP::RT_COMMENT)
      line_number++;

  // Get the hostname.
  result = this->getword (entry.host_);
  if (result != FP::RT_SUCCESS)
    return result;

  ACE_INT32 port;

  // Get the port number.
  result = this->getint (port);
  if (result == FP::RT_DEFAULT)
    {
      // Get the proxy role, i.e., 'C' (Consumer) or 'S' (Supplier).
      result = this->getword (buf);
      if (result != FP::RT_SUCCESS)
        return result;
      else
        entry.connection_role_ = buf[0];

      if (entry.connection_role_ == 'C')
        entry.remote_port_ = Options::instance ()->consumer_connector_port ();
      else if (entry.connection_role_ == 'S')
        entry.remote_port_ = Options::instance ()->supplier_connector_port ();
      else
        // Yikes, this is a *weird* error!
        entry.remote_port_ = 0;
    }
  else if (result != FP::RT_SUCCESS)
    return result;
  else
    {
      entry.remote_port_ = (unsigned short) port;

      // Get the proxy role, i.e., 'C' (Consumer) or 'S' (Supplier).
      result = this->getword (buf);
      if (result != FP::RT_SUCCESS)
        return result;
      else
        entry.connection_role_ = buf[0];
    }

  // Get the max retry delay.
  result = this->getint (entry.max_retry_timeout_);
  if (result == FP::RT_DEFAULT)
    entry.max_retry_timeout_ = Options::instance ()->max_timeout ();
  else if (result != FP::RT_SUCCESS)
    return result;

  // Get the local port number.
  result = this->getint (port);
  if (result == FP::RT_DEFAULT)
    entry.local_port_ = 0; // @@ Should make this an option.
  else if (result != FP::RT_SUCCESS)
    return result;
  else
    entry.local_port_ = (unsigned short) port;

  ACE_INT32 priority;

  // Get the priority.
  result = this->getint (priority);
  if (result != FP::RT_SUCCESS)
    return result;
  else
    entry.priority_ = priority;

  return FP::RT_SUCCESS;
}

#if defined (DEBUGGING)
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  FP_RETURN_TYPE result;
  int line_number = 0;

  {
    Connection_Config_Info entry;
    Connection_Config_File_Parser connection_config_file;

    connection_config_file.open (argc > 1 ? argv[1] : "connection_config");

    int line_number = 0;

    ACE_DEBUG ((LM_DEBUG,
                "ConnID\tHost\t\tRPort\tRole\tRetry\tLPort\tPriority\n"));

    // Read config file line at a time.
    while ((result = connection_config_file.read_entry (entry, line_number)) != FP::RT_EOFILE)
      if (result == FP::RT_PARSE_ERROR)
        ACE_DEBUG ((LM_DEBUG,
                    "Error line %d.\n",
                    line_number));
      else
        ACE_DEBUG ((LM_DEBUG,
                    "%d\t%s\t%d\t%c\t%d\t%d\t%d\n",
                    entry.connection_id_,
                    entry.host_,
                    entry.remote_port_,
                    entry.connection_role_,
                    entry.max_retry_timeout_,
                    entry.local_port_,
                    entry.priority_));

    connection_config_file.close ();
  }

  {
    Consumer_Config_Info entry;
    Consumer_Config_File_Parser consumer_config_file;

    consumer_config_file.open (argc > 2 ? argv[2] : "consumer_config");

    line_number = 0;

    ACE_DEBUG ((LM_DEBUG,
                "\nConnID\tLogic\tPayload\tDestinations\n"));

    // Read config file line at a time.
    while ((result = consumer_config_file.read_entry (entry, line_number)) != FP::RT_EOFILE)
      if (result == FP::RT_PARSE_ERROR)
        ACE_DEBUG ((LM_DEBUG,
                    "Error line %d.\n",
                    line_number));
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      "%d\t%d\t",
                      entry.connection_id_,
                      entry.type_));

          while (--entry.total_consumers_ >= 0)
            ACE_DEBUG ((LM_DEBUG,
                        "%d,",
                        entry.consumers_[entry.total_consumers_]));
          ACE_DEBUG ((LM_DEBUG,
                      "\n"));
        }

    consumer_config_file.close ();
  }

  return 0;
}
#endif /* DEBUGGING */