SynopsisDefine a new URL handler. Prototype#include "webs.h" int websUrlHandlerDefine(char_t *path, int (*fn)(webs_t wp, char_t *url, char_t *path, char_t *query), int flags); Parameters
DescriptionThe websUrlHandlerDefine procedure adds a new URL handler by associating a URL path segment with a processing function. URL handlers are called in sorted order beginning with the handlers with longer path segments. For example, the handler for "/myUrl" would be called before the handler for "/my". The flags parameter can specify two special sorting values:
If specified, the flags modify the calling order of the handler. Multiple handlers may specify these flags, in which case the order of all the handlers specifying WEBS_HANDLER_FIRST is undefined. This is the same for multiple handlers using WEBS_HANDLER_LAST. A URL handler is a C procedure according to the following prototype: int myHandler(webs_t wp, char_t *url, char_t *path, char_t *query); The url parameter contains the entire URL. The path parameter holds the URL portion after the hostname and port number. The query parameter holds any optional query. The URL handler must return 1 if it elects to process the URL. Otherwise, it should return 0 to indicate that a later URL handler should process the URL. A handler may modify the URL request using any of the websSetRequest APIs. In this case, if it returns 0, a subsequent URL handler will process the modified request. Return ValueReturns 0 if successful, otherwise it returns -1. Exampleint myHandler(webs_t wp, char_t *url, char_t *path, char_t *query) { /* * Processing here */ return 1; } websUrlHandlerDefine("", myHandler, WEBS_HANDLER_FIRST); websUrlHandlerDefine ("/mypath", myOtherHandler, 0); Stability ClassificationStable. See Also |