00001 #ifndef NETWORK_ADDRESS_CLASS
00002 #define NETWORK_ADDRESS_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "address_base.h"
00025
00026
00027 class configurator;
00028 class machine_uid;
00029
00030
00031
00032
00033
00034
00035
00037
00038 class SOCKETS_CLASS_STYLE internet_address : public address_base
00039 {
00040 public:
00041 enum internet_address_constraints {
00042 ADDRESS_SIZE = 4,
00043 MAXIMUM_HOSTNAME_LENGTH = 128
00044 };
00045
00046 typedef byte address_array[ADDRESS_SIZE];
00047 address_array ip_address;
00048 int port;
00049
00050 char hostname[MAXIMUM_HOSTNAME_LENGTH];
00051
00052
00053
00054 internet_address();
00055 internet_address(const byte_array &ip_address, const istring &host,
00056 int port);
00057
00058 IMPLEMENT_CLASS_NAME("internet_address");
00059
00060 machine_uid convert() const;
00061
00062
00063 void fill(const byte_array &ip_address, const istring &host, int port);
00064
00065 bool same_host(const address_base &to_compare) const;
00066 bool same_port(const address_base &to_compare) const;
00067 bool shareable(const address_base &to_compare) const;
00068
00069 inline bool operator == (const internet_address &to_compare) const {
00070 return same_host(to_compare) && same_port(to_compare);
00071 }
00072
00073 istring text_form() const;
00074
00075 istring tokenize() const;
00076 bool detokenize(const istring &info);
00077
00078 istring normalize_host() const;
00079
00080
00081
00082
00083 static const byte_array &nil_address();
00084
00085
00086 bool is_nil_address() const;
00087
00088
00089 static bool is_nil_address(const address_array &ip_address);
00090
00091
00092 static bool valid_address(const istring &to_check);
00093
00094
00095
00096 static bool is_valid_internet_address(const istring &to_check,
00097 byte_array &ip_form, bool &all_zeros);
00098
00099
00100
00101
00102
00103
00104 static bool ip_appropriate_number(const istring &to_check, int indy,
00105 istring &accum);
00107
00116 static bool has_ip_address(const istring &to_check, istring &ip_found);
00118
00121 static istring ip_address_text_form(const byte_array &ip_address);
00122
00123
00124
00125
00126 static const byte_array &localhost();
00127
00128
00129
00130 bool is_localhost() const;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 address_base *create_copy() const;
00141
00142 void pack(byte_array &packed_form) const;
00143 bool unpack(byte_array &packed_form);
00144
00145 virtual int packed_size() const;
00146 };
00147
00148 #ifndef EMBEDDED_BUILD
00149
00151
00152 class SOCKETS_CLASS_STYLE serial_port_address : public address_base
00153 {
00154 public:
00155 enum parity_type
00156 { NONE = 'N', EVEN = 'E', ODD = 'O', MARK = 'M', SPACE = 'S' };
00157
00158 enum stop_bits_type {
00159 ZERO_SB = 0,
00160 ONE_SB = 1,
00161 ONE_POINT_FIVE_SB = 9,
00162 TWO_SB = 2
00163 };
00164
00165 int port;
00166 int baud_rate;
00167 byte data_bits;
00168 char parity;
00169 byte stop_bits;
00170
00171 serial_port_address();
00172 serial_port_address(int port, int baud_rate, byte data_bits, char parity,
00173 byte stop_bits);
00174
00175 void fill(int port, int baud_rate, byte data_bits, char parity,
00176 byte stop_bits);
00177
00178 IMPLEMENT_CLASS_NAME("serial_port_address");
00179
00180 bool same_host(const address_base &to_compare) const;
00181 bool same_port(const address_base &to_compare) const;
00182 bool shareable(const address_base &to_compare) const;
00183
00184 istring text_form() const;
00185
00186 istring tokenize() const;
00187 bool detokenize(const istring &info);
00188
00189 address_base *create_copy() const;
00190
00191 void pack(byte_array &packed_form) const;
00192 bool unpack(byte_array &packed_form);
00193
00194 virtual machine_uid convert() const;
00195
00196 virtual int packed_size() const;
00197
00198
00199
00200
00201
00202 static istring GET_DSR();
00203 static istring GET_CTS();
00204 static istring SET_DTR();
00205 static istring SET_RTS();
00206 static istring USE_MARK_SPACE();
00207
00208
00209
00210 };
00211
00213
00214 class SOCKETS_CLASS_STYLE ipc_address : public address_base
00215 {
00216 public:
00217 enum ipc_address_constraints {
00218 MAXIMUM_IPC_NAME_LENGTH = 42
00219 };
00220
00221 char service[MAXIMUM_IPC_NAME_LENGTH];
00222 char topic[MAXIMUM_IPC_NAME_LENGTH];
00223
00224 ipc_address();
00225 ipc_address(const istring &service, const istring &topic);
00226
00227 void fill(const istring &service, const istring &topic);
00228
00229 bool same_host(const address_base &to_compare) const;
00230 bool same_port(const address_base &to_compare) const;
00231 bool shareable(const address_base &to_compare) const;
00232
00233 istring text_form() const;
00234
00235 IMPLEMENT_CLASS_NAME("ipc_address");
00236
00237 istring tokenize() const;
00238 bool detokenize(const istring &info);
00239
00240 virtual machine_uid convert() const;
00241
00242 address_base *create_copy() const;
00243
00244 void pack(byte_array &packed_form) const;
00245 bool unpack(byte_array &packed_form);
00246
00247 virtual int packed_size() const;
00248 };
00249
00250 #endif // embedded
00251
00253
00254
00255
00256 class SOCKETS_CLASS_STYLE network_address : public packable
00257 {
00258 public:
00259 network_address();
00260 network_address(const network_address &to_copy);
00261
00262 network_address(const internet_address &address);
00263 #ifndef EMBEDDED_BUILD
00264 network_address(const serial_port_address &address);
00265 network_address(const ipc_address &address);
00266 #endif
00267
00268 ~network_address();
00269
00270 IMPLEMENT_CLASS_NAME("network_address");
00271
00272 network_address &operator =(const network_address &to_copy);
00273
00274
00275
00276 enum address_type {
00277 ADDRESS_SENTINEL_BEGIN = 0,
00278 UNINITIALIZED_ADDRESS = 0,
00279 INVALID_ADDRESS = UNINITIALIZED_ADDRESS,
00280 IPC_ADDRESS,
00281 INTERNET_ADDRESS,
00282 SERIAL_PORT_ADDRESS,
00283 ADDRESS_SENTINEL_END
00284 };
00285
00286 bool valid() const;
00287
00288
00289 inline const char *type_name() const {
00290 return (_type == UNINITIALIZED_ADDRESS)? "UninitializedAddress"
00291 : _addr->class_name();
00292 }
00293
00294 address_type type() const { return address_type(_type); }
00295 static istring text_for_type(address_type type);
00296 static address_type type_from_text(const istring &text);
00297
00298
00299
00300
00301 internet_address *internet();
00302 const internet_address *internet() const;
00303 #ifndef EMBEDDED_BUILD
00304 serial_port_address *serial();
00305 const serial_port_address *serial() const;
00306 ipc_address *ipc();
00307 const ipc_address *ipc() const;
00308 #endif
00309
00310 bool comparable(address_type a, address_type b) const;
00311
00312
00313 bool same_host(const network_address &to_compare) const;
00314
00315
00316 bool same_port(const network_address &to_compare) const;
00317
00318
00319 bool operator == (const network_address &to_compare) const;
00320
00321
00322 bool operator != (const network_address &to_compare) const
00323 { return !(*this == to_compare); }
00324 bool shareable(const network_address &to_compare) const;
00325
00326
00327
00328
00329
00330 istring text_form(bool show_type = true) const;
00331
00332
00333
00334
00335 istring tokenize() const;
00336 bool detokenize(const istring &info);
00337
00338
00339
00340
00341 static network_address load(configurator &config, const istring §ion,
00342 const istring &name, const network_address &default_address);
00343
00344
00345
00346
00347
00348 static bool store(configurator &config, const istring §ion,
00349 const istring &name, const network_address &to_store);
00350
00351
00352
00353
00354 void parse_pack(byte_array &packed_form) const;
00355 bool parse_unpack(byte_array &packed_form);
00356
00357 machine_uid convert() const;
00358
00359
00360 istring unified_hostname() const;
00361
00362
00363
00364 virtual int packed_size() const;
00365
00366
00367 void pack(byte_array &packed_form) const;
00368 bool unpack(byte_array &packed_form);
00369
00370 private:
00371 int _type;
00372 address_base *_addr;
00373 };
00374
00375 #endif
00376