michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** Base class definitions for network access functions (ref: prnetdb.h) michael@0: */ michael@0: michael@0: #if defined(_RCNETDB_H) michael@0: #else michael@0: #define _RCNETDB_H michael@0: michael@0: #include "rclock.h" michael@0: #include "rcbase.h" michael@0: michael@0: #include michael@0: michael@0: class PR_IMPLEMENT(RCNetAddr): public RCBase michael@0: { michael@0: public: michael@0: typedef enum { michael@0: any = PR_IpAddrAny, /* assign logical INADDR_ANY */ michael@0: loopback = PR_IpAddrLoopback /* assign logical INADDR_LOOPBACK */ michael@0: } HostValue; michael@0: michael@0: RCNetAddr(); /* default constructor is unit'd object */ michael@0: RCNetAddr(const RCNetAddr&); /* copy constructor */ michael@0: RCNetAddr(HostValue, PRUint16 port);/* init'd w/ 'special' assignments */ michael@0: RCNetAddr(const RCNetAddr&, PRUint16 port); michael@0: /* copy w/ port reassigment */ michael@0: michael@0: virtual ~RCNetAddr(); michael@0: michael@0: void operator=(const RCNetAddr&); michael@0: michael@0: virtual PRBool operator==(const RCNetAddr&) const; michael@0: /* compare of all relavent fields */ michael@0: virtual PRBool EqualHost(const RCNetAddr&) const; michael@0: /* compare of just host field */ michael@0: michael@0: michael@0: public: michael@0: michael@0: void operator=(const PRNetAddr*); /* construction from more primitive data */ michael@0: operator const PRNetAddr*() const; /* extraction of underlying representation */ michael@0: virtual PRStatus FromString(const char* string); michael@0: /* initialization from an ASCII string */ michael@0: virtual PRStatus ToString(char *string, PRSize size) const; michael@0: /* convert internal fromat to a string */ michael@0: michael@0: private: michael@0: michael@0: PRNetAddr address; michael@0: michael@0: }; /* RCNetAddr */ michael@0: michael@0: /* michael@0: ** Class: RCHostLookup michael@0: ** michael@0: ** Abstractions to look up host names and addresses. michael@0: ** michael@0: ** This is a stateful class. One looks up the host by name or by michael@0: ** address, then enumerates over a possibly empty array of network michael@0: ** addresses. The storage for the addresses is owned by the class. michael@0: */ michael@0: michael@0: class RCHostLookup: public RCBase michael@0: { michael@0: public: michael@0: virtual ~RCHostLookup(); michael@0: michael@0: RCHostLookup(); michael@0: michael@0: virtual PRStatus ByName(const char* name); michael@0: virtual PRStatus ByAddress(const RCNetAddr&); michael@0: michael@0: virtual const RCNetAddr* operator[](PRUintn); michael@0: michael@0: private: michael@0: RCLock ml; michael@0: PRIntn max_index; michael@0: RCNetAddr* address; michael@0: michael@0: RCHostLookup(const RCHostLookup&); michael@0: RCHostLookup& operator=(const RCHostLookup&); michael@0: }; michael@0: michael@0: inline RCNetAddr::RCNetAddr(): RCBase() { } michael@0: inline RCNetAddr::operator const PRNetAddr*() const { return &address; } michael@0: michael@0: michael@0: #endif /* defined(_RCNETDB_H) */ michael@0: michael@0: /* RCNetdb.h */ michael@0: michael@0: