Info-Mac Archive Downloads: dev/src/ SourceCode

Back to dev/src/ SourceCode

(url-helper-10d1.hqx)

Download url-helper-10d1.hqx (273,399 KB)


Hi all,
I'm sorry if some of you got this message twice. :)

I'm one of the moderators at info-mac. One thing we really want to start doing is adding URLs to the digests instead of the [Archived as...] line. This brings up some real problems, however, as sumex-aim is already greatly overloaded and to have everyone who reads info-mac in newswatcher pounding it for a file... well, that would be "bad". I think that mac.archive at umich has the same problem.

To solve this both archives have a fairly large set of mirror sites. Each person has their own fav mirror site for info-mac and the umich archive. Great. I thought it would be great if all the various gopher/etc. programs would do automatic mirror subsititution.

This package I've written, "URL Helper", attempts to do just that. It is a combination of a small library and a component. The component keeps track of a list of mirrors for each main site. When a program has a URL it wants to look up, it hands the URL to the component. The component sees if that URL matches any of its known mirror sites -- in some mirror list. So something like "ftp://sumex-aim.stanford.edu/info-mac/..." would match a site on the info-mac mirror list. The calling program can then retreive the various enabled mirrors for that site. Path translations, etc. are taken care of.

It is all done with text subsitution. Here is a short example. I didn't use the real info-mac mirror list, just a made up one. Here is what the internal mirror list looks like for info-mac:

"\p^0://sumex-aim.stanford.edu/info-mac/^1"
"\p^0://mac.archive.edu/pub/info-mac/^1"
"\p^0://mit.mit.edu/pub/mirrors/im/^1"

The "^N" are substitution characters. They can be in any order or any position in a mirror string.

And, when I run the test program, I get back the following (this is output of a test in the file main.c).

Full Test on: 'ftp://sumex-aim.stanford.edu/info-mac/grf/util/mac-graphics.hqx'
-> 'ftp://mit.mit.edu/pub/mirrors/im/grf/util/mac-graphics.hqx'
-> 'ftp://mac.archive.edu/pub/info-mac/grf/util/mac-graphics.hqx'

Where the "Full test on " line whas the input URL. The "->" are the resulting mirror URLS. Note that sumex-aim.stanford.edu doesn't appear in the output. That is because that was specified as a "no use" mirror...

The code to do this is pretty simple, when the library is used:
¥ To get only the first mirror (the primary mirror):
URLHLibGetFirstMirror (string, mirror);

where "string" is the original url, and "mirror" is a pointer to a new mirror url.

¥ To get all of the mirrors back, one by one:

short index;
URLHParseRef parseRef;
Str255 mirror;

parseRef = URLHLibNewParseState (string);
index = 1;
while (URLHLibGetIndexedMirror (parseRef, index, mirror)) {
index++;
}
URLHLibDisposeParseState (parseRef);

The library has been designed to work weather or not the component is in place.

Basically, that is it. I don't want to develop this any further until I get a reaction from the people who are going to use it. Is this api any good? Does it have enough flexability? You can look at the full source; I've uploaded it to my personal archive site (it is in ftp://sumex-aim.stanford.edu/dev/src/url-helper-10d1.hqx -- it should move all the mirrors by tomorrow morning -- or send a note to me and I'll send you the .hqx). The biggest thing it is currently lacking is that it dosen't save the mirror lists to a prefs file. I didn't want to spend more time if people decide it won't be worth it. I even volenteer(sp) to do the UI for the internet prefs app (if it ever gets written!).

I would think that programs like Anarchie, Fetch, mac gopher, etc. would use this, not a program like NewsWatcher. But, it could be one has a mirror list that would convert "ftp://" into "gopher://".. and it would be bad for Fetch to end up with a gopher URL! Whatever.

Oh -- I do plan, if people like it, to write a set of routines that will parse a gopher/ftp address so that the author need not be bothered with that parsing (this thing only works on complete URLs right now). Also note that I've sidestepped the issue of automatically figuring out which mirror is closest. That can be added (if ever) later. What we really need is a better internet archive system, instead of stop-gap systems like this... :)

Cheers,
Gordon.