🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.inetsdk.programming.wininet
Article #8

Re: WinInet - InternetCombineURL alternative

#8
From: Richard Heathfield
Date: Thu, 27 Sep 2001 06:00
72 lines
3913 bytes
Adam wrote:
> 
> When you say "portable" most systems have wininet.dll installed.

I just checked my Linux installation and hey, what do you know, it's not
there. In comp.programming (which is where I'm reading this), "portable"
means more than just "portable to Windows".

> It is part
> of the OS in Win '98 and >. But for users with Win '95 - all they need is IE
> 4 or >.

<shrug>

> "justin chan" <jayc@start.com.au> wrote in message
> news:16379a2c.0109251629.5566caa3@posting.google.com...
> > Hi,
> >
> > Currently I'm using 'InternetCombineURL' function from WinInet to
> > combine a base and relative URL into a single URL.
> > eg. Base: http://www.myserver.com/folder/
> >     Relative: ../file.html
> >     Result: http://www.myserver.com/file.html
> >
> > However, because I want to make my application portable, I'm removing
> > dependencies on WinInet.

Excellent.

> >
> > Does anyone know if there is an alternative to 'InternetCombineURL'
> > and does not rely on WinInet??

Yes, Justin, it's called "programming".  :-)

Start off with your base URL. Parse on the / character. This gives you
tokens http: (in your example), www.myserver.com, and folder.

Build a data structure that represents that relationship:

      www.myserver.com
            ^
            |
            |
            |
            V
          folder

This rather simple example doesn't explain things very well, but
basically you'd have each node pointing to an array of child nodes and
also to a parent node (with the server node itself having a parent of
NULL). That would enable you to build up a picture of the server as you
go.

Anyway, from that start, finding a relative path is trivial. Start at
the "current" directory - in your case, www.myserver.com/folder - and
parse, again on the / character. If you hit a . on its own, you can
discard it. If you hit on .. on their own, you need to go one place
nearer the root. If you hit a token terminated by a /, you need to
change into that directory (possibly creating a new node in your data
structure in order to represent it), and if you hit a non-empty token
not ending in / at the end, that's the file you're after.

It's really relatively simple, but also relatively interesting, and well
worth the exercise of programming for yourself.


-- 
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Technical Details
Message-ID: <3BB2C06D.5537E07E@eton.powernet.co.uk>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!demon!easynet-monga!easynet-melon!easynet.net!btnet-feed5!btnet!news.power.net.uk
References: <16379a2c.0109251629.5566caa3@posting.google.com> <9otpac$2e9$1@bugstomper.ihug.com.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 108717,725b2bc82b6740ad
X-Google-Attributes: gid108717,public
X-Google-Thread: 115f11,725b2bc82b6740ad
X-Google-Attributes: gid115f11,public
X-Google-Thread: 1091e5,725b2bc82b6740ad
X-Google-Attributes: gid1091e5,public
X-Google-ArrivalTime: 2001-09-26 23:13:29 PST
Message-ID: <3BB2C06D.5537E07E@eton.powernet.co.uk>
Date: Thu, 27 Sep 2001 07:00:13 +0100
From: Richard Heathfield <binary@eton.powernet.co.uk>
Organization: Eton Computer Systems Ltd
X-Mailer: Mozilla 4.6 [en-gb]C-CCK-MCD NetscapeOnline.co.uk  (WinNT; I)
X-Accept-Language: en-GB,en
MIME-Version: 1.0
Newsgroups: microsoft.public.inetsdk.programming.wininet,borland.public.delphi.winapi,comp.programming
Subject: Re: WinInet - InternetCombineURL alternative
References: <16379a2c.0109251629.5566caa3@posting.google.com> <9otpac$2e9$1@bugstomper.ihug.com.au>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 195.60.5.121
X-Trace: news.power.net.uk 1001571206 195.60.5.121 (27 Sep 2001 07:13:26 +0100)
Lines: 74
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!demon!easynet-monga!easynet-melon!easynet.net!btnet-feed5!btnet!news.power.net.uk