WvStreams
wvurl.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * WvURL is a simple URL-parsing class with built-in (though still somewhat
00006  * inconvenient) DNS resolution.
00007  */ 
00008 #ifndef __WVURL_H
00009 #define __WVURL_H
00010 
00011 #include "wvstring.h"
00012 #include "wvresolver.h"
00013 
00014 class WvIPPortAddr;
00015 
00016 class WvUrl
00017 {
00018 public:
00019     WvUrl(WvStringParm url);
00020     WvUrl(const WvUrl &url);
00021     ~WvUrl();
00022     
00023     bool isok() const
00024         { return port != 0 && (resolving || addr != NULL); }
00025     WvStringParm errstr() const
00026         { return err; }
00027     bool resolve(); // dns-resolve the hostname (returns true if done)
00028 
00029     operator WvString () const;
00030     
00031     // not actually defined - this just prevents accidental copying
00032     const WvUrl &operator= (const WvUrl &);
00033     
00034     WvStringParm getproto() const
00035         { return proto; }
00036     
00037     // this one is ONLY valid if resolve() returns true!
00038     const WvIPPortAddr getaddr() const
00039         { return addr ? *addr : WvIPPortAddr(); }
00040     
00041     WvStringParm getfile() const
00042         { return file; }
00043     WvStringParm gethost() const
00044         { return hostname; }
00045     int getport() const
00046         { return port; }
00047     WvStringParm getuser() const
00048         { return user; }
00049     WvStringParm getpassword() const
00050         { return password; }
00051 
00052 protected:
00053     WvString proto, hostname, user, password;
00054     int port;
00055     bool resolving;
00056     WvResolver dns;
00057     WvIPPortAddr *addr;
00058     WvString file, err;
00059 };
00060 
00061 
00062 // backwards compatibility
00063 typedef WvUrl WvURL;
00064 
00065 #endif // __WVURL_H