📄 htaautil.c
字号:
*(colon++) = '\0'; /* Chop off port number */ port = atoi(colon); } tree = HTUTree_find(proxy_access ? AA_PROXY_TREE : AA_TREE, host,port); HT_FREE(host); if (!tree) { HTTRACE(AUTH_TRACE, "Auth Engine. No information\n"); return NULL; } } /* Find a matching AA element (if any) */ { char * path = HTParse(url, "", PARSE_PATH | PARSE_PUNCTUATION); HTAAElement *element = (HTAAElement*)HTUTree_findNode(tree,realm,path); HT_FREE(path); return element; } return NULL;}/* Add a AA context to the URL tree** --------------------------------** Each node in the AA URL tree is a list of the modules we must call** for this particular node.*/PUBLIC void * HTAA_updateNode (BOOL proxy_access, char const * scheme, const char * realm, const char * url, void * context){ HTUTree * tree = NULL; HTAAModule * module = NULL; if (!scheme || !url) { HTTRACE(AUTH_TRACE, "Auth Engine. Bad argument\n"); return NULL; } HTTRACE(AUTH_TRACE, "Auth Engine. Adding info for `%s'\n" _ url); /* Find the AA module with this name */ if ((module = HTAA_findModule(scheme)) == NULL) { HTTRACE(AUTH_TRACE, "Auth Engine. Module `%s\' not registered\n" _ scheme ? scheme : "<null>"); return NULL; } /* Find an existing URL Tree or create a new one */ { char * host = HTParse(url, "", PARSE_HOST); char * colon = strchr(host, ':'); int port = DEFAULT_PORT; if (colon ) { *(colon++) = '\0'; /* Chop off port number */ port = atoi(colon); } tree = HTUTree_new(proxy_access ? AA_PROXY_TREE : AA_TREE, host, port, HTAA_deleteElement); HT_FREE(host); if (!tree) { HTTRACE(AUTH_TRACE, "Auth Engine. Can't create tree\n"); return NULL; } } /* Find a matching AA element or create a new one */ { char * path = HTParse(url, "", PARSE_PATH | PARSE_PUNCTUATION); HTAAElement * element = NULL; BOOL status; if ((element = (HTAAElement *) HTUTree_findNode(tree, realm, path)) && element->scheme && !strcasecomp (element->scheme, scheme)) status = HTAA_updateElement(element, scheme, context); else { /* create the new element */ element = HTAA_newElement(scheme, context); status = HTUTree_addNode(tree, realm, path, element); } HT_FREE(path); return status==YES ? element->context : NULL; }}/* Delete a AA context from the URL tree** -------------------------------------** Each node in the AA URL tree is a list of the modules we must call** for this particular node.*/PUBLIC BOOL HTAA_deleteNode (BOOL proxy_access, char const * scheme, const char * realm, const char * url){ HTUTree * tree = NULL; HTAAModule * module = NULL; if (!scheme || !url) { HTTRACE(AUTH_TRACE, "Auth Engine. Bad argument\n"); return NO; } HTTRACE(AUTH_TRACE, "Auth Engine. Deleting info for `%s'\n" _ url); /* Find the AA module with this name */ if ((module = HTAA_findModule(scheme)) == NULL) { HTTRACE(AUTH_TRACE, "Auth Engine. Module `%s\' not registered\n" _ scheme ? scheme : "<null>"); return NO; } /* Find an existing URL Tree or create a new one */ { char * host = HTParse(url, "", PARSE_HOST); char * colon = strchr(host, ':'); int port = DEFAULT_PORT; if (colon ) { *(colon++) = '\0'; /* Chop off port number */ port = atoi(colon); } tree = HTUTree_new(proxy_access ? AA_PROXY_TREE : AA_TREE, host, port, HTAA_deleteElement); HT_FREE(host); if (!tree) { HTTRACE(AUTH_TRACE, "Auth Engine. Can't create tree\n"); return NO; } } /* Delete any existing node */ { char * path = HTParse(url, "", PARSE_PATH | PARSE_PUNCTUATION); BOOL status = HTUTree_deleteNode(tree, realm, path); HT_FREE(path); return status; }}/* ------------------------------------------------------------------------- *//* AUTHENTICATION ENGINE *//* ------------------------------------------------------------------------- *//* HTAA_beforeFilter** ------------------** Make a lookup in the URL tree to find any context for this node,** If no context is found then we assume that we don't know anything about** this URL and hence we don't call any BEFORE filters at all.** Return HT_OK or whatever callback returns*/PUBLIC int HTAA_beforeFilter (HTRequest * request, void * param, int mode){ char * url = HTAnchor_address((HTAnchor *) HTRequest_anchor(request)); const char * realm = HTRequest_realm(request); HTAAElement * element = HTAA_findElement(NO, realm, url); HT_FREE(url); /* If we have an element then call the before filter with this scheme */ if (element) { HTAAModule * module = HTAA_findModule(element->scheme); if (module) { HTTRACE(AUTH_TRACE, "Auth Engine. Found BEFORE filter %p\n" _ module->before); return (*module->before)(request, element->context, mode); } } return HT_OK;}/* HTAA_afterFilter** -----------------** Call the AFTER filter that knows how to handle this scheme.** Return YES or whatever callback returns*/PUBLIC int HTAA_afterFilter (HTRequest * request, HTResponse * response, void * param, int status){ const char * scheme = HTResponse_scheme(response); HTAAModule * module = NULL; HTTRACE(AUTH_TRACE, "Auth Engine. After filter status %d\n" _ status); /* ** If we don't have a scheme then the server has made an error. We ** try to make up for it by creating our own "noop" realm and use basic. */ if (!scheme) { HTResponse_addChallenge(response, "basic", "realm LIBWWW-UNKNOWN"); scheme = "basic"; } if ((module = HTAA_findModule(scheme)) != NULL) { HTTRACE(AUTH_TRACE, "Auth Engine. Found AFTER filter %p\n" _ module->after); HTRequest_deleteCredentialsAll(request); HTRequest_addAARetry (request); return (*module->after)(request, response, NULL, status); } return HT_ERROR;}/* HTAA_UpdateFilter** -----------------** Call the Update filter that knows how to handle this scheme.** Return YES or whatever callback returns*/PUBLIC int HTAA_updateFilter (HTRequest * request, HTResponse * response, void * param, int status){ const char * scheme = HTResponse_scheme(response); HTAAModule * module = NULL; HTTRACE(AUTH_TRACE, "Auth Engine. Update filter status %d\n" _ status); /* ** If we don't have a scheme then the server has made an error. We ** try to make up for it by creating our own "noop" realm and use basic. */ if (!scheme) { HTResponse_addChallenge(response, "basic", "realm LIBWWW-UNKNOWN"); scheme = "basic"; } if ((module = HTAA_findModule(scheme)) != NULL) { /* we don't call this module systematically, as it could hamper the execution of Basic authentication requests for nothing */ if (module->update) { HTTRACE(AUTH_TRACE, "Auth Engine. Found Update filter %p\n" _ module->update); HTRequest_deleteCredentialsAll(request); return (*module->update)(request, response, NULL, status); } return HT_OK; } return HT_ERROR;}/* HTAA_proxybeforeFilter** ----------------------** Make a lookup in the proxy URL tree to find any context for this node,** If no context is found then we assume that we don't know anything about** this URL and hence we don't call any BEFORE filters at all.** Return HT_OK or whatever callback returns*/PUBLIC int HTAA_proxyBeforeFilter (HTRequest * request, void * param, int mode){ char * url = HTRequest_proxy(request); /* ** We may not have a proxy - for example if it has been disabled for this ** request or it isn't a proxied access method. */ if (url) { const char * realm = HTRequest_realm(request); HTAAElement * element = HTAA_findElement(YES, realm, url); /* If we have an element then call the before filter with the scheme */ if (element) { HTAAModule * module = HTAA_findModule(element->scheme); if (module) { HTTRACE(AUTH_TRACE, "Auth Engine. Found Proxy BEFORE filter %p with context %p\n" _ module->before _ element->context); return (*module->before)(request, element->context, HT_NO_PROXY_ACCESS); } } } return HT_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -