1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/cplus/rcnetdb.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** Base class definitions for network access functions (ref: prnetdb.h) 1.11 +*/ 1.12 + 1.13 +#if defined(_RCNETDB_H) 1.14 +#else 1.15 +#define _RCNETDB_H 1.16 + 1.17 +#include "rclock.h" 1.18 +#include "rcbase.h" 1.19 + 1.20 +#include <prnetdb.h> 1.21 + 1.22 +class PR_IMPLEMENT(RCNetAddr): public RCBase 1.23 +{ 1.24 +public: 1.25 + typedef enum { 1.26 + any = PR_IpAddrAny, /* assign logical INADDR_ANY */ 1.27 + loopback = PR_IpAddrLoopback /* assign logical INADDR_LOOPBACK */ 1.28 + } HostValue; 1.29 + 1.30 + RCNetAddr(); /* default constructor is unit'd object */ 1.31 + RCNetAddr(const RCNetAddr&); /* copy constructor */ 1.32 + RCNetAddr(HostValue, PRUint16 port);/* init'd w/ 'special' assignments */ 1.33 + RCNetAddr(const RCNetAddr&, PRUint16 port); 1.34 + /* copy w/ port reassigment */ 1.35 + 1.36 + virtual ~RCNetAddr(); 1.37 + 1.38 + void operator=(const RCNetAddr&); 1.39 + 1.40 + virtual PRBool operator==(const RCNetAddr&) const; 1.41 + /* compare of all relavent fields */ 1.42 + virtual PRBool EqualHost(const RCNetAddr&) const; 1.43 + /* compare of just host field */ 1.44 + 1.45 + 1.46 +public: 1.47 + 1.48 + void operator=(const PRNetAddr*); /* construction from more primitive data */ 1.49 + operator const PRNetAddr*() const; /* extraction of underlying representation */ 1.50 + virtual PRStatus FromString(const char* string); 1.51 + /* initialization from an ASCII string */ 1.52 + virtual PRStatus ToString(char *string, PRSize size) const; 1.53 + /* convert internal fromat to a string */ 1.54 + 1.55 +private: 1.56 + 1.57 + PRNetAddr address; 1.58 + 1.59 +}; /* RCNetAddr */ 1.60 + 1.61 +/* 1.62 +** Class: RCHostLookup 1.63 +** 1.64 +** Abstractions to look up host names and addresses. 1.65 +** 1.66 +** This is a stateful class. One looks up the host by name or by 1.67 +** address, then enumerates over a possibly empty array of network 1.68 +** addresses. The storage for the addresses is owned by the class. 1.69 +*/ 1.70 + 1.71 +class RCHostLookup: public RCBase 1.72 +{ 1.73 +public: 1.74 + virtual ~RCHostLookup(); 1.75 + 1.76 + RCHostLookup(); 1.77 + 1.78 + virtual PRStatus ByName(const char* name); 1.79 + virtual PRStatus ByAddress(const RCNetAddr&); 1.80 + 1.81 + virtual const RCNetAddr* operator[](PRUintn); 1.82 + 1.83 +private: 1.84 + RCLock ml; 1.85 + PRIntn max_index; 1.86 + RCNetAddr* address; 1.87 + 1.88 + RCHostLookup(const RCHostLookup&); 1.89 + RCHostLookup& operator=(const RCHostLookup&); 1.90 +}; 1.91 + 1.92 +inline RCNetAddr::RCNetAddr(): RCBase() { } 1.93 +inline RCNetAddr::operator const PRNetAddr*() const { return &address; } 1.94 + 1.95 + 1.96 +#endif /* defined(_RCNETDB_H) */ 1.97 + 1.98 +/* RCNetdb.h */ 1.99 + 1.100 +