websUrlParse GoAhead WebServer API GoAhead EMF

Synopsis

Parse a URL into its component parts

Prototype

#include "webs.h" 

int websUrlParse(char_t *url, char_t **buf, char_t **host, 
    char_t **path, char_t **port, char_t **query, char_t **proto, 
    char_t **tag, char_t **ext);

Parameters

url Source URL to parse
buf Pointer to buffer used to hold the parsed components
host Host name
path URL path portion after the host name and optional port
query Optional query string portion after "?"
proto Protocol. Usually "http"
tag Optional tag portion after "#"
ext Document file name extension

Description

The websUrlParse procedure cracks the URL into its constituent components. To store the parts, websUrlParse allocates a dynamic buffer. This must eventually be freed via bfree by the caller.

websUrlParse stores pointers to the URL components in host, path, port, query, proto, tag and ext. If any of these parameters contains NULL, that component is ignored.

Note: tag parsing is not fully supported.

Return Value

Returns 0 if successful. Returns -1 if memory cannot be allocated to hold the results.

Example

char_t *host, *port, *buf;

websUrlParse(url, &buf, &host, NULL, &port, NULL, NULL, NULL, NULL);

See Also

balloc, bfree, websUrlType