url.c File Reference

#include "nsd.h"

Functions

char * Ns_RelativeUrl (char *url, char *location)
int Ns_ParseUrl (char *url, char **pprotocol, char **phost, char **pport, char **ppath, char **ptail)
int Ns_AbsoluteUrl (Ns_DString *dsPtr, char *url, char *base)

Function Documentation

int Ns_AbsoluteUrl ( Ns_DString *  dsPtr,
char *  url,
char *  base 
)

----------------------------------------------------------------------

Ns_AbsoluteUrl --

Construct an URL based on baseurl but with as many parts of the incomplete url as possible.

Results: NS_OK or NS_ERROR.

Side effects: None.

----------------------------------------------------------------------

Copy the URL's to allow Ns_ParseUrl to destory them.

int Ns_ParseUrl ( char *  url,
char **  pprotocol,
char **  phost,
char **  pport,
char **  ppath,
char **  ptail 
)

----------------------------------------------------------------------

Ns_ParseUrl --

Parse a URL into its component parts

Results: NS_OK or NS_ERROR

Side effects: Pointers to the protocol, host, port, path, and "tail" (last path element) will be set by reference in the passed-in pointers. The passed-in url will be modified.

----------------------------------------------------------------------

Set end to the end of the protocol http://www.foo.com:8000/baz/blah/spoo.html ^ +--end

There is a protocol specified. Clear out the colon. Set pprotocol to the start of the protocol, and url to the first character after the colon.

http//www.foo.com:8000/baz/blah/spoo.html ^ ^ ^ | | +-- url | +-- end +-------- *pprotocol

There are two slashes, which means a host is specified. Advance url past that and set *phost.

http//www.foo.com:8000/baz/blah/spoo.html ^ ^ ^ | | +-- url, *phost | +-- end +-------- *pprotocol

Look for a port number, which is optional.

A port was specified. Clear the colon and set *pport to the first digit.

http//www.foo.com/baz/blah/spoo.html ^ ^ ^ ^ | +-- *phost | +------ url, *pport +----- *pprotocol +--- end

Move up to the slash which starts the path/tail. Clear out the dividing slash.

http//www.foo.com/blah/spoo.html ^ ^ ^ ^ ^ | | | | +-- url | +-- *phost | +-- end +----- *pprotocol +-- *pport

No path or tail specified. Return.

The URL must have been an odd one without a hostname. Move the URL up past the dividing slash.

http\0/baz/blah/spoo.html ^ ^ ^ | | +-- url | +-- end +-------- *pprotocol

Set the path to URL and advance to the last slash. Set ptail to the character after that, or if there is none, it becomes path and path becomes an empty string.

http//www.foo.com/blah/spoo.html ^ ^ ^ ^ ^ ^^ | | | | | |+-- *ptail | | | | | +-- end | | | | +-- *ppath | +-- *phost | +-- end +----- *pprotocol +-- *pport

This URL does not have a colon. If it begins with a slash, then separate the tail from the path, otherwise it's all tail.

Find the last slash on the right and everything after that becomes tail; if there are no slashes then it's all tail and path is an empty string.

Just set the tail, there are no slashes.

char* Ns_RelativeUrl ( char *  url,
char *  location 
)

----------------------------------------------------------------------

Ns_RelativeUrl --

If the url passed in is for this server, then the initial part of the URL is stripped off. e.g., on a server whose location is http://www.foo.com, Ns_RelativeUrl of "http://www.foo.com/hello" will return "/hello".

Results: A pointer to the beginning of the relative url in the passed-in url, or NULL if error.

Side effects: Will set errno on error.

----------------------------------------------------------------------

Ns_Match will return the point in URL where location stops being equal to it because location ends.

e.g., if location = "http://www.foo.com" and url="http://www.foo.com/a/b" then after the call, v="/a/b", or NULL if there's a mismatch.


Generated on Tue Sep 4 19:58:56 2007 by  doxygen 1.5.1