47#define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), to_print)
85#define CAST_UP(type) \
86 const type *temp = dynamic_cast<const type *>(&compare_in); \
87 if (!temp) return false; \
88 const type &to_compare = *temp;
95 const astring &host,
int port_in)
96{
fill(ip, host, port_in); }
108 FUNCDEF(
"ip_appropriate_number");
110 for (
int i = indy; (i < indy + 3) && (i < to_check.
length()); i++) {
115 if (i == indy)
return false;
118 accum += to_check[i];
120 if (!accum.
length())
return false;
133 for (
int i = 0; i < to_check.
length(); i++) {
144 if (nums_seen >= 4) {
145 ip_found += num_found;
149 int period_indy = to_check.
find(
'.', i);
150 if (
negative(period_indy) || (period_indy > i + 3) ) hosed =
true;
152 for (
int x = i; x < period_indy; x++) {
159 ip_found += to_check.
substring(i, period_indy);
197 if (remote.
t())
return remote;
206 return sizeof(
port) +
237 for (
int i = 0; i < mini; i++)
ip_address[i] = ip[i];
260 to_print +=
"ip_addr=";
303 if (
ip_address[i] != to_compare.ip_address[i])
321 return port == to_compare.port;
335 FIND(
"address", addr);
348 int current_byte = addr.convert(
int(0));
349 ip_found +=
abyte(current_byte);
353 int indy = addr.find(
'.');
359 GRAB(
"port", port_t);
360 int port = port_t.convert(0);
379 bool print_ip =
false;
387 ip_addr.
zap(ip_addr.
end(), ip_addr.
end());
388 ADD(
"address", ip_addr);
399 for (
int i = 0; i < to_check.
length(); i++) {
400 char curr = to_check[i];
401 if (curr ==
'.')
continue;
402 if ( (curr >=
'0') && (curr <=
'9') )
continue;
423 if ( (to_check[0] ==
'.') || (to_check[to_check.
end()] ==
'.') )
427 if (to_check.
contains(
".."))
return false;
430 char *p = strtok(tmpstr.
s(),
".");
437 if ( (nTemp < 0) || (nTemp > 255) )
return false;
440 ip_form += (
abyte)nTemp;
449 for (
int i = 0; i < ip_form.
length(); i++)
450 if (ip_form[i]) { all_zeros =
false;
break; }
#define GRAB(name, value)
#define FIND(name, value)
a_sprintf is a specialization of astring that provides printf style support.
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
int length() const
Returns the current reported length of the allocated C array.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
outcome stuff(int length, contents *to_stuff) const
Copies at most "length" elements from this into the array "to_stuff".
Provides a dynamically resizable ASCII character string.
astring lower() const
like to_lower(), but returns a new string rather than modifying this.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
int convert(int default_value) const
Converts the string into a corresponding integer.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
virtual void text_form(base_string &state_fill) const
Provides a text view of all the important info owned by this object.
void stuff(char *to_stuff, int count) const
a synonym for copy().
void reset()
clears out the contents string.
bool equal_to(const char *that) const
returns true if "that" is equal to this.
int end() const
returns the index of the last (non-null) character in the string.
int length() const
Returns the current length of the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
bool contains(const astring &to_find) const
Returns true if "to_find" is contained in this string or false if not.
void to_lower()
to_lower modifies "this" by replacing capitals with lower-case.
A very common template for a dynamic array of bytes.
machine_uid convert() const
static bool has_ip_address(const basis::astring &to_check, basis::astring &ip_found)
returns true if "to_check" has an IP address in it somewhere.
basis::astring tokenize() const
bool is_nil_address() const
static bool valid_address(const basis::astring &to_check)
basis::astring normalize_host() const
basis::astring text_form() const
static const basis::byte_array & nil_address()
static basis::astring ip_address_text_form(const basis::byte_array &ip_address)
void fill(const basis::byte_array &ip_address, const basis::astring &host, int port)
void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
char hostname[MAXIMUM_HOSTNAME_LENGTH]
bool detokenize(const basis::astring &info)
bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
bool is_localhost() const
bool same_host(const base_address &to_compare) const
static bool ip_appropriate_number(const basis::astring &to_check, int indy, basis::astring &accum)
returns true if "to_check" has a number at "indy" that works in ipv4.
virtual int packed_size() const
Estimates the space needed for the packed structure.
bool shareable(const base_address &to_compare) const
static bool is_valid_internet_address(const basis::astring &to_check, basis::byte_array &ip_form, bool &all_zeros)
static const basis::byte_array & localhost()
static bool appropriate_for_ip(const basis::astring &to_check)
@ MAXIMUM_HOSTNAME_LENGTH
bool same_port(const base_address &to_compare) const
base_address * create_copy() const
static bool is_numeric(char look_at)
returns true if "look_at" is a valid numerical character.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
type minimum(type a, type b)
maximum returns the greater of two values.
bool negative(const type &a)
negative returns true if "a" is less than zero.
A logger that sends to the console screen using the standard output device.
Provides access to the operating system's socket methods.
const abyte localhosts_bytes[]
const abyte nil_address_bytes[]
A dynamic container class that holds any kind of object via pointers.
#define SAFE_STATIC_CONST(type, func_name, parms)
this version returns a constant object instead.