|   | ![[ Previous ]](navbprev.gif)  ![[ Contents ]](navbhome.gif)  ![[ Index ]](navbhelp.gif)  ![[ Next ]](navbnext.gif)  | 
    typedef int (Ns_FilterProc) (void *context, Ns_Conn *conn, int 
why);
    
    Ns_ProcHandle Ns_RegisterFilter(
    char *hServer,
    char *method,
    char *URLpatterns,
    Ns_FilterProc *proc,
    int why,
    void *context
    );
This function will register a filter procedure for a method/URL combination on a server. This function will be called at the specified stage of a connection, if the method/URL combination for the filter matches the method/URL combination for the connection using glob style matching. The procedures are run in last-registered last-run order. A filter procedure is often used for logging.
The why argument can be any of the following, or some combination of them by bitwise OR-ing (with "|") them together:
Using pre-authorization, the procedure will be called (assuming that the method/URL combination matches) just before authorization. If the procedure returns:
Using post-authorization, the procedure will be called (assuming that the method/URL combination matches) just after successful authorization. If the procedure returns:
Using trace, the procedure will be called (assuming that the method/URL combination match) after the connection has been totally processed and closed. If the procedure returns:
The URLpatterns can contain standard string-matching characters. For example, these are valid URLpatterns:
    static int
    ReportUse(void *context, Ns_Conn *conn, int why){
     int status=NS_OK;
     switch(why){
      case NS_FILTER_PRE_AUTH:
       Ns_Log(Notice, "User trying to access %s",conn->request->url);
         break;
        case NS_FILTER_POST_AUTH:
          Ns_Log(Notice, "User authorized to access %s",conn->request-
>url);
          break;
        case NS_FILTER_TRACE:
          Ns_Log(Notice, "User has retrieved %s",conn->request->url);
          break;
        default:
          status=NS_ERROR;
      }
      return status;
    }
    int
    Ns_ModuleInit(char *hServer, char *hModule){
      Ns_RegisterFilter(hServer, "GET", "/test/a*", ReportUse,
        Ns_FILTER_PRE_AUTH, NULL);
      Ns_RegisterFilter(hServer, "GET", "/test/b*", ReportUse,
        Ns_FILTER_POST_AUTH, NULL);
      Ns_RegisterFilter(hServer, "GET", "/test/c*", ReportUse,
        Ns_FILTER_TRACE, NULL);
      Ns_RegisterFilter(hServer, "GET", "/test/d*", ReportUse,
        Ns_FILTER_PRE_AUTH | NS_FILTER_POST_AUTH, NULL);
      Ns_RegisterFilter(hServer, "GET", "/test/e*", ReportUse,
        Ns_FILTER_POST_AUTH | NS_FILTER_TRACE, NULL);
      Ns_RegisterFilter(hServer, "GET", "/test/f*", ReportUse,
        Ns_FILTER_PRE_AUTH | Ns_FILTER_POST_AUTH | NS_FILTER_TRACE, 
NULL);