Back to index

lightning-sunbird  0.9+nobinonly
rcnetdb.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** Base class definitions for network access functions (ref: prnetdb.h)
00040 */
00041 
00042 #if defined(_RCNETDB_H)
00043 #else
00044 #define _RCNETDB_H
00045 
00046 #include "rclock.h"
00047 #include "rcbase.h"
00048 
00049 #include <prnetdb.h>
00050 
00051 class PR_IMPLEMENT(RCNetAddr): public RCBase
00052 {
00053 public:
00054     typedef enum {
00055         any = PR_IpAddrAny,             /* assign logical INADDR_ANY */
00056         loopback = PR_IpAddrLoopback    /* assign logical INADDR_LOOPBACK */
00057     } HostValue;
00058 
00059     RCNetAddr();                        /* default constructor is unit'd object */
00060     RCNetAddr(const RCNetAddr&);        /* copy constructor */
00061     RCNetAddr(HostValue, PRUint16 port);/* init'd w/ 'special' assignments */
00062     RCNetAddr(const RCNetAddr&, PRUint16 port);
00063                                         /* copy w/ port reassigment */
00064 
00065     virtual ~RCNetAddr();
00066 
00067     void operator=(const RCNetAddr&);
00068 
00069     virtual PRBool operator==(const RCNetAddr&) const;
00070                                         /* compare of all relavent fields */
00071     virtual PRBool EqualHost(const RCNetAddr&) const;
00072                                         /* compare of just host field */
00073 
00074 
00075 public:
00076 
00077     void operator=(const PRNetAddr*);   /* construction from more primitive data */
00078     operator const PRNetAddr*() const;  /* extraction of underlying representation */
00079     virtual PRStatus FromString(const char* string);
00080                                         /* initialization from an ASCII string */
00081     virtual PRStatus ToString(char *string, PRSize size) const;
00082                                         /* convert internal fromat to a string */
00083 
00084 private:
00085 
00086     PRNetAddr address;
00087 
00088 };  /* RCNetAddr */
00089 
00090 /*
00091 ** Class: RCHostLookup
00092 **
00093 ** Abstractions to look up host names and addresses.
00094 **
00095 ** This is a stateful class. One looks up the host by name or by
00096 ** address, then enumerates over a possibly empty array of network
00097 ** addresses. The storage for the addresses is owned by the class.
00098 */
00099 
00100 class RCHostLookup: public RCBase
00101 {
00102 public:
00103     virtual ~RCHostLookup();
00104 
00105     RCHostLookup();
00106 
00107     virtual PRStatus ByName(const char* name);
00108     virtual PRStatus ByAddress(const RCNetAddr&);
00109 
00110     virtual const RCNetAddr* operator[](PRUintn);
00111 
00112 private:
00113     RCLock ml;
00114     PRIntn max_index;
00115     RCNetAddr* address;
00116 
00117     RCHostLookup(const RCHostLookup&);
00118     RCHostLookup& operator=(const RCHostLookup&);
00119 };
00120 
00121 inline RCNetAddr::RCNetAddr(): RCBase() { }
00122 inline RCNetAddr::operator const PRNetAddr*() const { return &address; }
00123 
00124 
00125 #endif /* defined(_RCNETDB_H) */
00126 
00127 /* RCNetdb.h */
00128 
00129