github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_4_58/include/http_protocol.h (about)

     1  /* Licensed to the Apache Software Foundation (ASF) under one or more
     2   * contributor license agreements.  See the NOTICE file distributed with
     3   * this work for additional information regarding copyright ownership.
     4   * The ASF licenses this file to You under the Apache License, Version 2.0
     5   * (the "License"); you may not use this file except in compliance with
     6   * the License.  You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  /**
    18   * @file  http_protocol.h
    19   * @brief HTTP protocol handling
    20   *
    21   * @defgroup APACHE_CORE_PROTO HTTP Protocol Handling
    22   * @ingroup  APACHE_CORE
    23   * @{
    24   */
    25  
    26  #ifndef APACHE_HTTP_PROTOCOL_H
    27  #define APACHE_HTTP_PROTOCOL_H
    28  
    29  #include "httpd.h"
    30  #include "apr_portable.h"
    31  #include "apr_mmap.h"
    32  #include "apr_buckets.h"
    33  #include "util_filter.h"
    34  
    35  #ifdef __cplusplus
    36  extern "C" {
    37  #endif
    38  
    39  /**
    40   * This hook allows modules to insert filters for the current error response
    41   * @param r the current request
    42   * @ingroup hooks
    43   */
    44  AP_DECLARE_HOOK(void,insert_error_filter,(request_rec *r))
    45  
    46  /** This is an optimization.  We keep a record of the filter_rec that
    47   * stores the old_write filter, so that we can avoid strcmp's later.
    48   */
    49  AP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func;
    50  
    51  /*
    52   * Prototypes for routines which either talk directly back to the user,
    53   * or control the ones that eventually do.
    54   */
    55  
    56  /**
    57   * Read an empty request and set reasonable defaults.
    58   * @param c The current connection
    59   * @return The new request_rec
    60   */
    61  AP_DECLARE(request_rec *) ap_create_request(conn_rec *c);
    62  
    63  /**
    64   * Read a request and fill in the fields.
    65   * @param c The current connection
    66   * @return The new request_rec
    67   */
    68  request_rec *ap_read_request(conn_rec *c);
    69  
    70  /**
    71   * Parse and validate the request line.
    72   * @param r The current request
    73   * @return 1 on success, 0 on failure
    74   */
    75  AP_DECLARE(int) ap_parse_request_line(request_rec *r);
    76  
    77  /**
    78   * Validate the request header and select vhost.
    79   * @param r The current request
    80   * @return 1 on success, 0 on failure
    81   */
    82  AP_DECLARE(int) ap_check_request_header(request_rec *r);
    83  
    84  /**
    85   * Read the mime-encoded headers.
    86   * @param r The current request
    87   */
    88  AP_DECLARE(void) ap_get_mime_headers(request_rec *r);
    89  
    90  /**
    91   * Optimized version of ap_get_mime_headers() that requires a
    92   * temporary brigade to work with
    93   * @param r The current request
    94   * @param bb temp brigade
    95   */
    96  AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r,
    97                                            apr_bucket_brigade *bb);
    98  
    99  /**
   100   * Run post_read_request hook and validate.
   101   * @param r The current request
   102   * @return OK or HTTP_...
   103   */
   104  AP_DECLARE(int) ap_post_read_request(request_rec *r);
   105  
   106  /* Finish up stuff after a request */
   107  
   108  /**
   109   * Called at completion of sending the response.  It sends the terminating
   110   * protocol information.
   111   * @param r The current request
   112   */
   113  AP_DECLARE(void) ap_finalize_request_protocol(request_rec *r);
   114  
   115  /**
   116   * Send error back to client.
   117   * @param r The current request
   118   * @param recursive_error last arg indicates error status in case we get
   119   *      an error in the process of trying to deal with an ErrorDocument
   120   *      to handle some other error.  In that case, we print the default
   121   *      report for the first thing that went wrong, and more briefly report
   122   *      on the problem with the ErrorDocument.
   123   */
   124  AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
   125  
   126  /* Set last modified header line from the lastmod date of the associated file.
   127   * Also, set content length.
   128   *
   129   * May return an error status, typically HTTP_NOT_MODIFIED (that when the
   130   * permit_cache argument is set to one).
   131   */
   132  
   133  /**
   134   * Set the content length for this request
   135   * @param r The current request
   136   * @param length The new content length
   137   */
   138  AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length);
   139  
   140  /**
   141   * Set the keepalive status for this request
   142   * @param r The current request
   143   * @return 1 if keepalive can be set, 0 otherwise
   144   */
   145  AP_DECLARE(int) ap_set_keepalive(request_rec *r);
   146  
   147  /**
   148   * Return the latest rational time from a request/mtime pair.  Mtime is
   149   * returned unless it's in the future, in which case we return the current time.
   150   * @param r The current request
   151   * @param mtime The last modified time
   152   * @return the latest rational time.
   153   */
   154  AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime);
   155  
   156  /**
   157   * Build the content-type that should be sent to the client from the
   158   * content-type specified.  The following rules are followed:
   159   *    - if type is NULL or "", return NULL (do not set content-type).
   160   *    - if charset adding is disabled, stop processing and return type.
   161   *    - then, if there are no parameters on type, add the default charset
   162   *    - return type
   163   * @param r The current request
   164   * @param type The content type
   165   * @return The content-type
   166   */
   167  AP_DECLARE(const char *) ap_make_content_type(request_rec *r,
   168                                                const char *type);
   169  
   170  /**
   171   * Precompile metadata structures used by ap_make_content_type()
   172   * @param pool The pool to use for allocations
   173   */
   174  AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
   175  
   176  /** A structure with the ingredients for a file based etag */
   177  typedef struct etag_rec etag_rec;
   178  
   179  /**
   180   * @brief A structure with the ingredients for a file based etag
   181   */
   182  struct etag_rec {
   183      /** Optional vary list validator */
   184      const char *vlist_validator;
   185      /** Time when the request started */
   186      apr_time_t request_time;
   187      /** finfo.protection (st_mode) set to zero if no such file */
   188      apr_finfo_t *finfo;
   189      /** File pathname used when generating a digest */
   190      const char *pathname;
   191      /** File descriptor used when generating a digest */
   192      apr_file_t *fd;
   193      /** Force a non-digest etag to be weak */
   194      int force_weak;
   195  };
   196  
   197  /**
   198   * Construct an entity tag from the resource information.  If it's a real
   199   * file, build in some of the file characteristics.
   200   * @param r The current request
   201   * @param force_weak Force the entity tag to be weak - it could be modified
   202   *                   again in as short an interval.
   203   * @return The entity tag
   204   */
   205  AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
   206  
   207  /**
   208   * Construct an entity tag from information provided in the etag_rec
   209   * structure.
   210   * @param r The current request
   211   * @param er The etag record, containing ingredients for the etag.
   212   */
   213  AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er);
   214  
   215  /**
   216   * Set the E-tag outgoing header
   217   * @param r The current request
   218   */
   219  AP_DECLARE(void) ap_set_etag(request_rec *r);
   220  
   221  /**
   222   * Set the E-tag outgoing header, with the option of forcing a strong ETag.
   223   * @param r The current request
   224   * @param fd The file descriptor
   225   */
   226  AP_DECLARE(void) ap_set_etag_fd(request_rec *r, apr_file_t *fd);
   227  
   228  /**
   229   * Set the last modified time for the file being sent
   230   * @param r The current request
   231   */
   232  AP_DECLARE(void) ap_set_last_modified(request_rec *r);
   233  
   234  typedef enum {
   235      AP_CONDITION_NONE,
   236      AP_CONDITION_NOMATCH,
   237      AP_CONDITION_WEAK,
   238      AP_CONDITION_STRONG
   239  } ap_condition_e;
   240  
   241  /**
   242   * Tests conditional request rules for the If-Match header.
   243   * @param r The current request
   244   * @param headers The response headers to check against
   245   * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
   246   *         if the header does not match, AP_CONDITION_STRONG for a strong
   247   *         match. Weak matches are not permitted for the If-Match header.
   248   */
   249  AP_DECLARE(ap_condition_e) ap_condition_if_match(request_rec *r,
   250          apr_table_t *headers);
   251  
   252  /**
   253   * Tests conditional request rules for the If-Unmodified-Since header.
   254   * @param r The current request
   255   * @param headers The response headers to check against
   256   * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
   257   *         if the header does not match, AP_CONDITION_WEAK if a weak match
   258   *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
   259   *         strong match.
   260   */
   261  AP_DECLARE(ap_condition_e) ap_condition_if_unmodified_since(request_rec *r,
   262          apr_table_t *headers);
   263  
   264  /**
   265   * Tests conditional request rules for the If-None-Match header.
   266   * @param r The current request
   267   * @param headers The response headers to check against
   268   * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
   269   *         if the header does not match, AP_CONDITION_WEAK if a weak match
   270   *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
   271   *         strong match.
   272   */
   273  AP_DECLARE(ap_condition_e) ap_condition_if_none_match(request_rec *r,
   274          apr_table_t *headers);
   275  
   276  /**
   277   * Tests conditional request rules for the If-Modified-Since header.
   278   * @param r The current request
   279   * @param headers The response headers to check against
   280   * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
   281   *         if the header does not match, AP_CONDITION_WEAK if a weak match
   282   *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
   283   *         strong match.
   284   */
   285  AP_DECLARE(ap_condition_e) ap_condition_if_modified_since(request_rec *r,
   286          apr_table_t *headers);
   287  
   288  /**
   289   * Tests conditional request rules for the If-Range header.
   290   * @param r The current request
   291   * @param headers The response headers to check against
   292   * @return AP_CONDITION_NONE if either the If-Range or Range header is
   293   *         missing, AP_CONDITION_NOMATCH if the header does not match,
   294   *         AP_CONDITION_STRONG for a strong match. Weak matches are not
   295   *         permitted for the If-Range header.
   296   */
   297  AP_DECLARE(ap_condition_e) ap_condition_if_range(request_rec *r,
   298          apr_table_t *headers);
   299  
   300  /**
   301   * Implements condition GET rules for HTTP/1.1 specification.  This function
   302   * inspects the client headers and determines if the response fulfills
   303   * the requirements specified.
   304   * @param r The current request
   305   * @return OK if the response fulfills the condition GET rules, some
   306   *         other status code otherwise
   307   */
   308  AP_DECLARE(int) ap_meets_conditions(request_rec *r);
   309  
   310  /* Other ways to send stuff at the client.  All of these keep track
   311   * of bytes_sent automatically.  This indirection is intended to make
   312   * it a little more painless to slide things like HTTP-NG packetization
   313   * underneath the main body of the code later.  In the meantime, it lets
   314   * us centralize a bit of accounting (bytes_sent).
   315   *
   316   * These also return the number of bytes written by the call.
   317   * They should only be called with a timeout registered, for obvious reaasons.
   318   * (Ditto the send_header stuff).
   319   */
   320  
   321  /**
   322   * Send an entire file to the client, using sendfile if supported by the
   323   * current platform
   324   * @param fd The file to send.
   325   * @param r The current request
   326   * @param offset Offset into the file to start sending.
   327   * @param length Amount of data to send
   328   * @param nbytes Amount of data actually sent
   329   */
   330  AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset,
   331                                     apr_size_t length, apr_size_t *nbytes);
   332  
   333  #if APR_HAS_MMAP
   334  /**
   335   * Send an MMAP'ed file to the client
   336   * @param mm The MMAP'ed file to send
   337   * @param r The current request
   338   * @param offset The offset into the MMAP to start sending
   339   * @param length The amount of data to send
   340   * @return The number of bytes sent
   341   */
   342  AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm,
   343                                      request_rec *r,
   344                                      apr_size_t offset,
   345                                      apr_size_t length);
   346  #endif
   347  
   348  
   349  /**
   350   * Register a new request method, and return the offset that will be
   351   * associated with that method.
   352   *
   353   * @param p        The pool to create registered method numbers from.
   354   * @param methname The name of the new method to register.
   355   * @return         An int value representing an offset into a bitmask.
   356   */
   357  AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
   358  
   359  /**
   360   * Initialize the method_registry and allocate memory for it.
   361   *
   362   * @param p Pool to allocate memory for the registry from.
   363   */
   364  AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p);
   365  
   366  /**
   367   * This is a convenience macro to ease with checking a mask
   368   * against a method name.
   369   */
   370  #define AP_METHOD_CHECK_ALLOWED(mask, methname) \
   371      ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
   372  
   373  /**
   374   * Create a new method list with the specified number of preallocated
   375   * slots for extension methods.
   376   *
   377   * @param   p       Pointer to a pool in which the structure should be
   378   *                  allocated.
   379   * @param   nelts   Number of preallocated extension slots
   380   * @return  Pointer to the newly created structure.
   381   */
   382  AP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts);
   383  
   384  
   385  /**
   386   * Copy a method list
   387   *
   388   * @param   dest List to copy to
   389   * @param   src  List to copy from
   390   */
   391  AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest,
   392                                       ap_method_list_t *src);
   393  
   394  /**
   395   * Search for an HTTP method name in an ap_method_list_t structure, and
   396   * return true if found.
   397   *
   398   * @param   method  String containing the name of the method to check.
   399   * @param   l       Pointer to a method list, such as r->allowed_methods.
   400   * @return  1 if method is in the list, otherwise 0
   401   */
   402  AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method);
   403  
   404  /**
   405   * Add an HTTP method name to an ap_method_list_t structure if it isn't
   406   * already listed.
   407   *
   408   * @param   method  String containing the name of the method to check.
   409   * @param   l       Pointer to a method list, such as r->allowed_methods.
   410   * @return  None.
   411   */
   412  AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method);
   413  
   414  /**
   415   * Remove an HTTP method name from an ap_method_list_t structure.
   416   *
   417   * @param   l       Pointer to a method list, such as r->allowed_methods.
   418   * @param   method  String containing the name of the method to remove.
   419   * @return  None.
   420   */
   421  AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l,
   422                                         const char *method);
   423  
   424  /**
   425   * Reset a method list to be completely empty.
   426   *
   427   * @param   l       Pointer to a method list, such as r->allowed_methods.
   428   * @return  None.
   429   */
   430  AP_DECLARE(void) ap_clear_method_list(ap_method_list_t *l);
   431  
   432  /**
   433   * Set the content type for this request (r->content_type).
   434   * @param r The current request
   435   * @param ct The new content type
   436   * @warning This function must be called to set r->content_type in order
   437   * for the AddOutputFilterByType directive to work correctly.
   438   */
   439  AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
   440  
   441  /**
   442   * Set the Accept-Ranges header for this response
   443   * @param r The current request
   444   */
   445  AP_DECLARE(void) ap_set_accept_ranges(request_rec *r);
   446  
   447  
   448  /* Hmmm... could macrofy these for now, and maybe forever, though the
   449   * definitions of the macros would get a whole lot hairier.
   450   */
   451  
   452  /**
   453   * Output one character for this request
   454   * @param c the character to output
   455   * @param r the current request
   456   * @return The number of bytes sent
   457   */
   458  AP_DECLARE(int) ap_rputc(int c, request_rec *r);
   459  
   460  /**
   461   * Write a buffer for the current request
   462   * @param buf The buffer to write
   463   * @param nbyte The number of bytes to send from the buffer
   464   * @param r The current request
   465   * @return The number of bytes sent
   466   */
   467  AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
   468  
   469  /**
   470   * Output a string for the current request
   471   * @param str The string to output
   472   * @param r The current request
   473   * @return The number of bytes sent
   474   * @note ap_rputs may be implemented as macro or inline function
   475   */
   476  static APR_INLINE int ap_rputs(const char *str, request_rec *r)
   477  {
   478      apr_size_t len;
   479  
   480      len = strlen(str);
   481  
   482      for (;;) {
   483          if (len <= INT_MAX) {
   484              return ap_rwrite(str, (int)len, r);
   485          }
   486          else {
   487              int rc;
   488  
   489              rc = ap_rwrite(str, INT_MAX, r);
   490              if (rc < 0) {
   491                  return rc;
   492              }
   493              else {
   494                  str += INT_MAX;
   495                  len -= INT_MAX;
   496              }
   497          }
   498      }
   499  }
   500  
   501  /**
   502   * Write an unspecified number of strings to the request
   503   * @param r The current request
   504   * @param ... The strings to write
   505   * @return The number of bytes sent
   506   */
   507  AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...)
   508                         AP_FN_ATTR_SENTINEL;
   509  
   510  /**
   511   * Output data to the client in a printf format
   512   * @param r The current request
   513   * @param fmt The format string
   514   * @param vlist The arguments to use to fill out the format string
   515   * @return The number of bytes sent
   516   */
   517  AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
   518  
   519  /**
   520   * Output data to the client in a printf format
   521   * @param r The current request
   522   * @param fmt The format string
   523   * @param ... The arguments to use to fill out the format string
   524   * @return The number of bytes sent
   525   */
   526  AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
   527                                  __attribute__((format(printf,2,3)));
   528  
   529  /**
   530   * Flush all of the data for the current request to the client
   531   * @param r The current request
   532   * @return 0 on success, -1 if an error occurred
   533   */
   534  AP_DECLARE(int) ap_rflush(request_rec *r);
   535  
   536  /**
   537   * Index used in custom_responses array for a specific error code
   538   * (only use outside protocol.c is in getting them configured).
   539   * @param status HTTP status code
   540   * @return The index of the response
   541   */
   542  AP_DECLARE(int) ap_index_of_response(int status);
   543  
   544  /**
   545   * Return the Status-Line for a given status code (excluding the
   546   * HTTP-Version field). If an invalid or unknown status code is
   547   * passed, "500 Internal Server Error" will be returned.
   548   * @param status The HTTP status code
   549   * @return The Status-Line
   550   */
   551  AP_DECLARE(const char *) ap_get_status_line(int status);
   552  
   553  /**
   554   * Return the Status-Line for a given status code (excluding the
   555   * HTTP-Version field). If an invalid status code is passed,
   556   * "500 Internal Server Error" will be returned, whereas an unknown
   557   * status will be returned like "xxx Status xxx".
   558   * @param p The pool to allocate from when status is unknown
   559   * @param status The HTTP status code
   560   * @return The Status-Line
   561   */
   562  AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status);
   563  
   564  /* Reading a block of data from the client connection (e.g., POST arg) */
   565  
   566  /**
   567   * Setup the client to allow Apache to read the request body.
   568   * @param r The current request
   569   * @param read_policy How the server should interpret a chunked
   570   *                    transfer-encoding.  One of: <pre>
   571   *    REQUEST_NO_BODY          Send 413 error if message has any body
   572   *    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
   573   *    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
   574   * </pre>
   575   * @return either OK or an error code
   576   */
   577  AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy);
   578  
   579  /**
   580   * Determine if the client has sent any data.  This also sends a
   581   * 100 Continue response to HTTP/1.1 clients, so modules should not be called
   582   * until the module is ready to read content.
   583   * @warning Never call this function more than once.
   584   * @param r The current request
   585   * @return 0 if there is no message to read, 1 otherwise
   586   */
   587  AP_DECLARE(int) ap_should_client_block(request_rec *r);
   588  
   589  /**
   590   * Call this in a loop.  It will put data into a buffer and return the length
   591   * of the input block
   592   * @param r The current request
   593   * @param buffer The buffer in which to store the data
   594   * @param bufsiz The size of the buffer
   595   * @return Number of bytes inserted into the buffer.  When done reading, 0
   596   *         if EOF, or -1 if there was an error
   597   */
   598  AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz);
   599  
   600  /**
   601   * Map specific APR codes returned by the filter stack to HTTP error
   602   * codes, or the default status code provided. Use it as follows:
   603   *
   604   * return ap_map_http_request_error(rv, HTTP_BAD_REQUEST);
   605   *
   606   * If the filter has already handled the error, AP_FILTER_ERROR will
   607   * be returned, which is cleanly passed through.
   608   *
   609   * These mappings imply that the filter stack is reading from the
   610   * downstream client, the proxy will map these codes differently.
   611   * @param rv APR status code
   612   * @param status Default HTTP code should the APR code not be recognised
   613   * @return Mapped HTTP status code
   614   */
   615  AP_DECLARE(int) ap_map_http_request_error(apr_status_t rv, int status);
   616  
   617  /**
   618   * In HTTP/1.1, any method can have a body.  However, most GET handlers
   619   * wouldn't know what to do with a request body if they received one.
   620   * This helper routine tests for and reads any message body in the request,
   621   * simply discarding whatever it receives.  We need to do this because
   622   * failing to read the request body would cause it to be interpreted
   623   * as the next request on a persistent connection.
   624   * @param r The current request
   625   * @return error status if request is malformed, OK otherwise
   626   */
   627  AP_DECLARE(int) ap_discard_request_body(request_rec *r);
   628  
   629  /**
   630   * Setup the output headers so that the client knows how to authenticate
   631   * itself the next time, if an authentication request failed.
   632   * @param r The current request
   633   */
   634  AP_DECLARE(void) ap_note_auth_failure(request_rec *r);
   635  
   636  /**
   637   * @deprecated @see ap_note_auth_failure
   638   */
   639  AP_DECLARE(void) ap_note_basic_auth_failure(request_rec *r);
   640  
   641  /**
   642   * @deprecated @see ap_note_auth_failure
   643   */
   644  AP_DECLARE(void) ap_note_digest_auth_failure(request_rec *r);
   645  
   646  /**
   647   * This hook allows modules to add support for a specific auth type to
   648   * ap_note_auth_failure
   649   * @param r the current request
   650   * @param auth_type the configured auth_type
   651   * @return OK, DECLINED
   652   */
   653  AP_DECLARE_HOOK(int, note_auth_failure, (request_rec *r, const char *auth_type))
   654  
   655  /**
   656   * Get the password from the request headers. This function has multiple side
   657   * effects due to its prior use in the old authentication framework.
   658   * ap_get_basic_auth_components() should be preferred.
   659   *
   660   * @deprecated @see ap_get_basic_auth_components
   661   * @param r The current request
   662   * @param pw The password as set in the headers
   663   * @return 0 (OK) if it set the 'pw' argument (and assured
   664   *         a correct value in r->user); otherwise it returns
   665   *         an error code, either HTTP_INTERNAL_SERVER_ERROR if things are
   666   *         really confused, HTTP_UNAUTHORIZED if no authentication at all
   667   *         seemed to be in use, or DECLINED if there was authentication but
   668   *         it wasn't Basic (in which case, the caller should presumably
   669   *         decline as well).
   670   */
   671  AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
   672  
   673  #define AP_GET_BASIC_AUTH_PW_NOTE "AP_GET_BASIC_AUTH_PW_NOTE"
   674  
   675  /**
   676   * Get the username and/or password from the request's Basic authentication
   677   * headers. Unlike ap_get_basic_auth_pw(), calling this function has no side
   678   * effects on the passed request_rec.
   679   *
   680   * @param r The current request
   681   * @param username If not NULL, set to the username sent by the client
   682   * @param password If not NULL, set to the password sent by the client
   683   * @return APR_SUCCESS if the credentials were successfully parsed and returned;
   684   *         APR_EINVAL if there was no authentication header sent or if the
   685   *         client was not using the Basic authentication scheme. username and
   686   *         password are unchanged on failure.
   687   */
   688  AP_DECLARE(apr_status_t) ap_get_basic_auth_components(const request_rec *r,
   689                                                        const char **username,
   690                                                        const char **password);
   691  
   692  /**
   693   * parse_uri: break apart the uri
   694   * @warning Side Effects:
   695   *    @li sets r->args to rest after '?' (or NULL if no '?')
   696   *    @li sets r->uri to request uri (without r->args part)
   697   *    @li sets r->hostname (if not set already) from request (scheme://host:port)
   698   * @param r The current request
   699   * @param uri The uri to break apart
   700   */
   701  AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
   702  
   703  #define AP_GETLINE_FOLD 1 /* Whether to merge continuation lines */
   704  #define AP_GETLINE_CRLF 2 /* Whether line ends must be in the form CR LF */
   705  #define AP_GETLINE_NOSPC_EOL 4 /* Whether to consume up to and including the
   706                                    end of line on APR_ENOSPC */
   707  
   708  /**
   709   * Get the next line of input for the request
   710   * @param s The buffer into which to read the line
   711   * @param n The size of the buffer
   712   * @param r The request
   713   * @param flags Bit flag of multiple parsing options
   714   *              AP_GETLINE_FOLD Whether to merge continuation lines
   715   *              AP_GETLINE_CRLF Whether line ends must be in the form CR LF
   716   * @return The length of the line, if successful
   717   *         n, if the line is too big to fit in the buffer
   718   *         -1 for miscellaneous errors
   719   */
   720  AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags);
   721  
   722  /**
   723   * Get the next line of input for the request
   724   *
   725   * Note: on ASCII boxes, ap_rgetline is a macro which simply calls
   726   *       ap_rgetline_core to get the line of input.
   727   *
   728   *       on EBCDIC boxes, ap_rgetline is a wrapper function which
   729   *       translates ASCII protocol lines to the local EBCDIC code page
   730   *       after getting the line of input.
   731   *
   732   * @param s Pointer to the pointer to the buffer into which the line
   733   *          should be read; if *s==NULL, a buffer of the necessary size
   734   *          to hold the data will be allocated from the request pool
   735   * @param n The size of the buffer
   736   * @param read The length of the line.
   737   * @param r The request
   738   * @param flags Bit flag of multiple parsing options
   739   *              AP_GETLINE_FOLD Whether to merge continuation lines
   740   *              AP_GETLINE_CRLF Whether line ends must be in the form CR LF
   741   * @param bb Working brigade to use when reading buckets
   742   * @return APR_SUCCESS, if successful
   743   *         APR_ENOSPC, if the line is too big to fit in the buffer
   744   *         Other errors where appropriate
   745   */
   746  #if APR_CHARSET_EBCDIC
   747  AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
   748                                       apr_size_t *read,
   749                                       request_rec *r, int flags,
   750                                       apr_bucket_brigade *bb);
   751  #else /* ASCII box */
   752  #define ap_rgetline(s, n, read, r, fold, bb) \
   753          ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
   754  #endif
   755  
   756  /** @see ap_rgetline */
   757  AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
   758                                            apr_size_t *read,
   759                                            request_rec *r, int flags,
   760                                            apr_bucket_brigade *bb);
   761  
   762  /**
   763   * Get the method number associated with the given string, assumed to
   764   * contain an HTTP method.  Returns M_INVALID if not recognized.
   765   * @param method A string containing a valid HTTP method
   766   * @return The method number
   767   */
   768  AP_DECLARE(int) ap_method_number_of(const char *method);
   769  
   770  /**
   771   * Get the method name associated with the given internal method
   772   * number.  Returns NULL if not recognized.
   773   * @param p A pool to use for temporary allocations.
   774   * @param methnum An integer value corresponding to an internal method number
   775   * @return The name corresponding to the method number
   776   */
   777  AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum);
   778  
   779  
   780  /* Hooks */
   781  /*
   782   * pre_read_request --- run right before read_request_line(),
   783   *                  and not run during any subrequests.
   784   */
   785  /**
   786   * This hook allows modules to affect the request or connection immediately before
   787   * the request has been read, and before any other phases have been processes.
   788   * @param r The current request of the soon-to-be-read request
   789   * @param c The connection
   790   * @return None/void
   791   */
   792  AP_DECLARE_HOOK(void,pre_read_request,(request_rec *r, conn_rec *c))
   793  
   794  /*
   795   * post_read_request --- run right after read_request or internal_redirect,
   796   *                  and not run during any subrequests.
   797   */
   798  /**
   799   * This hook allows modules to affect the request immediately after the request
   800   * has been read, and before any other phases have been processes.  This allows
   801   * modules to make decisions based upon the input header fields
   802   * @param r The current request
   803   * @return OK or DECLINED
   804   */
   805  AP_DECLARE_HOOK(int,post_read_request,(request_rec *r))
   806  
   807  /**
   808   * This hook allows modules to perform any module-specific logging activities
   809   * over and above the normal server things.
   810   * @param r The current request
   811   * @return OK, DECLINED, or HTTP_...
   812   */
   813  AP_DECLARE_HOOK(int,log_transaction,(request_rec *r))
   814  
   815  /**
   816   * This hook allows modules to retrieve the http scheme for a request.  This
   817   * allows Apache modules to easily extend the schemes that Apache understands
   818   * @param r The current request
   819   * @return The http scheme from the request
   820   */
   821  AP_DECLARE_HOOK(const char *,http_scheme,(const request_rec *r))
   822  
   823  /**
   824   * Return the default port from the current request
   825   * @param r The current request
   826   * @return The current port
   827   */
   828  AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r))
   829  
   830  
   831  #define AP_PROTOCOL_HTTP1        "http/1.1"
   832  
   833  /**
   834   * Determine the list of protocols available for a connection/request. This may
   835   * be collected with or without any request sent, in which case the request is 
   836   * NULL. Or it may be triggered by the request received, e.g. through the 
   837   * "Upgrade" header.
   838   *
   839   * This hook will be run whenever protocols are being negotiated (ALPN as
   840   * one example). It may also be invoked at other times, e.g. when the server
   841   * wants to advertise protocols it is capable of switching to.
   842   * 
   843   * The identifiers for protocols are taken from the TLS extension type ALPN:
   844   * https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xml
   845   *
   846   * If no protocols are added to the proposals, the server not perform any
   847   * switch. If the protocol selected from the proposals is the protocol
   848   * already in place, also no protocol switch will be invoked.
   849   *
   850   * The client may already have announced the protocols it is willing to
   851   * accept. These will then be listed as offers. This parameter may also
   852   * be NULL, indicating that offers from the client are not known and
   853   * the hooks should propose all protocols that are valid for the
   854   * current connection/request.
   855   *
   856   * All hooks are run, unless one returns an error. Proposals may contain
   857   * duplicates. The order in which proposals are added is usually ignored.
   858   * 
   859   * @param c The current connection
   860   * @param r The current request or NULL
   861   * @param s The server/virtual host selected
   862   * @param offers A list of protocol identifiers offered by the client or
   863   *               NULL to indicated that the hooks are free to propose 
   864   * @param proposals The list of protocol identifiers proposed by the hooks
   865   * @return OK or DECLINED
   866   * @bug This API or implementation and order of operations should be considered
   867   * experimental and will continue to evolve in future 2.4 releases, with
   868   * a corresponding minor module magic number (MMN) bump to indicate the
   869   * API revision level.
   870   */
   871  AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r,
   872                                        server_rec *s,
   873                                        const apr_array_header_t *offers,
   874                                        apr_array_header_t *proposals))
   875  
   876  /**
   877   * Perform a protocol switch on the connection. The exact requirements for
   878   * that depend on the protocol in place and the one switched to. The first 
   879   * protocol module to handle the switch is the last module run.
   880   * 
   881   * For a connection level switch (r == NULL), the handler must on return
   882   * leave the conn_rec in a state suitable for processing the switched
   883   * protocol, e.g. correct filters in place.
   884   *
   885   * For a request triggered switch (r != NULL), the protocol switch is done
   886   * before the response is sent out. When switching from "http/1.1" via Upgrade
   887   * header, the 101 intermediate response will have been sent. The
   888   * hook needs then to process the connection until it can be closed. Which
   889   * the server will enforce on hook return.
   890   * Any error the hook might encounter must already be sent by the hook itself
   891   * to the client in whatever form the new protocol requires.
   892   *
   893   * @param c The current connection
   894   * @param r The current request or NULL
   895   * @param s The server/virtual host selected
   896   * @param protocol The protocol identifier we try to switch to
   897   * @return OK or DECLINED
   898   * @bug This API or implementation and order of operations should be considered
   899   * experimental and will continue to evolve in future 2.4 releases, with
   900   * a corresponding minor module magic number (MMN) bump to indicate the
   901   * API revision level.
   902   */
   903  AP_DECLARE_HOOK(int,protocol_switch,(conn_rec *c, request_rec *r,
   904                                       server_rec *s,
   905                                       const char *protocol))
   906  
   907  /**
   908   * Return the protocol used on the connection. Modules implementing
   909   * protocol switching must register here and return the correct protocol
   910   * identifier for connections they switched.
   911   *
   912   * To find out the protocol for the current connection, better call
   913   * @see ap_get_protocol which internally uses this hook.
   914   *
   915   * @param c The current connection
   916   * @return The identifier of the protocol in place or NULL
   917   * @bug This API or implementation and order of operations should be considered
   918   * experimental and will continue to evolve in future 2.4 releases, with
   919   * a corresponding minor module magic number (MMN) bump to indicate the
   920   * API revision level.
   921   */
   922  AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
   923  
   924  /**
   925   * Get the protocols that the connection and optional request may
   926   * upgrade to - besides the protocol currently active on the connection. These
   927   * values may be used to announce to a client what choices it has.
   928   *
   929   * If report_all == 0, only protocols more preferable than the one currently
   930   * being used, are reported. Otherwise, all available protocols beside the
   931   * current one are being reported.
   932   *
   933   * @param c The current connection
   934   * @param r The current request or NULL
   935   * @param s The server/virtual host selected or NULL
   936   * @param report_all include also protocols less preferred than the current one
   937   * @param pupgrades on return, possible protocols to upgrade to in descending order 
   938   *                 of preference. Maybe NULL if none are available.    
   939   * @bug This API or implementation and order of operations should be considered
   940   * experimental and will continue to evolve in future 2.4 releases, with
   941   * a corresponding minor module magic number (MMN) bump to indicate the
   942   * API revision level.
   943   */
   944  AP_DECLARE(apr_status_t) ap_get_protocol_upgrades(conn_rec *c, request_rec *r, 
   945                                                    server_rec *s, int report_all, 
   946                                                    const apr_array_header_t **pupgrades);
   947                                                    
   948  /**
   949   * Select a protocol for the given connection and optional request. Will return
   950   * the protocol identifier selected which may be the protocol already in place
   951   * on the connection. The selected protocol will be NULL if non of the given
   952   * choices could be agreed upon (e.g. no proposal as made).
   953   *
   954   * A special case is where the choices itself is NULL (instead of empty). In
   955   * this case there are no restrictions imposed on protocol selection.
   956   *
   957   * @param c The current connection
   958   * @param r The current request or NULL
   959   * @param s The server/virtual host selected
   960   * @param choices A list of protocol identifiers, normally the clients whishes
   961   * @return The selected protocol or NULL if no protocol could be agreed upon
   962   * @bug This API or implementation and order of operations should be considered
   963   * experimental and will continue to evolve in future 2.4 releases, with
   964   * a corresponding minor module magic number (MMN) bump to indicate the
   965   * API revision level.
   966   */
   967  AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, 
   968                                              server_rec *s,
   969                                              const apr_array_header_t *choices);
   970  
   971  /**
   972   * Perform the actual protocol switch. The protocol given must have been
   973   * selected before on the very same connection and request pair.
   974   *
   975   * @param c The current connection
   976   * @param r The current request or NULL
   977   * @param s The server/virtual host selected
   978   * @param protocol the protocol to switch to
   979   * @return APR_SUCCESS, if caller may continue processing as usual
   980   *         APR_EOF,     if caller needs to stop processing the connection
   981   *         APR_EINVAL,  if the protocol is already in place
   982   *         APR_NOTIMPL, if no module performed the switch
   983   *         Other errors where appropriate
   984   * @bug This API or implementation and order of operations should be considered
   985   * experimental and will continue to evolve in future 2.4 releases, with
   986   * a corresponding minor module magic number (MMN) bump to indicate the
   987   * API revision level.
   988   */
   989  AP_DECLARE(apr_status_t) ap_switch_protocol(conn_rec *c, request_rec *r, 
   990                                              server_rec *s,
   991                                              const char *protocol);
   992  
   993  /**
   994   * Call the protocol_get hook to determine the protocol currently in use
   995   * for the given connection.
   996   *
   997   * Unless another protocol has been switch to, will default to
   998   * @see AP_PROTOCOL_HTTP1 and modules implementing a  new protocol must
   999   * report a switched connection via the protocol_get hook.
  1000   *
  1001   * @param c The connection to determine the protocol for
  1002   * @return the protocol in use, never NULL
  1003   * @bug This API or implementation and order of operations should be considered
  1004   * experimental and will continue to evolve in future 2.4 releases, with
  1005   * a corresponding minor module magic number (MMN) bump to indicate the
  1006   * API revision level.
  1007   */
  1008  AP_DECLARE(const char *) ap_get_protocol(conn_rec *c);
  1009  
  1010  /**
  1011   * Check if the given protocol is an allowed choice on the given
  1012   * combination of connection, request and server. 
  1013   *
  1014   * When server is NULL, it is taken from request_rec, unless
  1015   * request_rec is NULL. Then it is taken from the connection base
  1016   * server.
  1017   *
  1018   * @param c The current connection
  1019   * @param r The current request or NULL
  1020   * @param s The server/virtual host selected or NULL
  1021   * @param protocol the protocol to switch to
  1022   * @return != 0 iff protocol is allowed
  1023   * @bug This API or implementation and order of operations should be considered
  1024   * experimental and will continue to evolve in future 2.4 releases, with
  1025   * a corresponding minor module magic number (MMN) bump to indicate the
  1026   * API revision level.
  1027   */
  1028  AP_DECLARE(int) ap_is_allowed_protocol(conn_rec *c, request_rec *r,
  1029                                         server_rec *s, const char *protocol);
  1030  
  1031  /** @see ap_bucket_type_error */
  1032  typedef struct ap_bucket_error ap_bucket_error;
  1033  
  1034  /**
  1035   * @struct ap_bucket_error
  1036   * @brief  A bucket referring to an HTTP error
  1037   *
  1038   * This bucket can be passed down the filter stack to indicate that an
  1039   * HTTP error occurred while running a filter.  In order for this bucket
  1040   * to be used successfully, it MUST be sent as the first bucket in the
  1041   * first brigade to be sent from a given filter.
  1042   */
  1043  struct ap_bucket_error {
  1044      /** Number of buckets using this memory */
  1045      apr_bucket_refcount refcount;
  1046      /** The error code */
  1047      int status;
  1048      /** The error string */
  1049      const char    *data;
  1050  };
  1051  
  1052  /** @see ap_bucket_type_error */
  1053  AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error;
  1054  
  1055  /**
  1056   * Determine if a bucket is an error bucket
  1057   * @param e The bucket to inspect
  1058   * @return true or false
  1059   */
  1060  #define AP_BUCKET_IS_ERROR(e)         (e->type == &ap_bucket_type_error)
  1061  
  1062  /**
  1063   * Make the bucket passed in an error bucket
  1064   * @param b The bucket to make into an error bucket
  1065   * @param error The HTTP error code to put in the bucket.
  1066   * @param buf An optional error string to put in the bucket.
  1067   * @param p A pool to allocate out of.
  1068   * @return The new bucket, or NULL if allocation failed
  1069   */
  1070  AP_DECLARE(apr_bucket *) ap_bucket_error_make(apr_bucket *b, int error,
  1071                  const char *buf, apr_pool_t *p);
  1072  
  1073  /**
  1074   * Create a bucket referring to an HTTP error.
  1075   * @param error The HTTP error code to put in the bucket.
  1076   * @param buf An optional error string to put in the bucket.
  1077   * @param p A pool to allocate the error string out of.
  1078   * @param list The bucket allocator from which to allocate the bucket
  1079   * @return The new bucket, or NULL if allocation failed
  1080   */
  1081  AP_DECLARE(apr_bucket *) ap_bucket_error_create(int error, const char *buf,
  1082                                                  apr_pool_t *p,
  1083                                                  apr_bucket_alloc_t *list);
  1084  
  1085  AP_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b);
  1086  AP_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b);
  1087  AP_DECLARE_NONSTD(apr_status_t) ap_content_length_filter(ap_filter_t *,
  1088                                                                apr_bucket_brigade *);
  1089  AP_DECLARE_NONSTD(apr_status_t) ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b);
  1090  
  1091  /**
  1092   * Sett up the protocol fields for subsidiary requests
  1093   * @param rnew New Sub Request
  1094   * @param r current request
  1095   */
  1096  AP_DECLARE(void) ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r);
  1097  
  1098  /**
  1099   * A wrapup function to keep the internal accounting straight.
  1100   * Indicates that there is no more content coming.
  1101   * @param sub_r Subrequest that is now compete
  1102   */
  1103  AP_DECLARE(void) ap_finalize_sub_req_protocol(request_rec *sub_r);
  1104  
  1105  /**
  1106   * Send an interim (HTTP 1xx) response immediately.
  1107   * @param r The request
  1108   * @param send_headers Whether to send&clear headers in r->headers_out
  1109   */
  1110  AP_DECLARE(void) ap_send_interim_response(request_rec *r, int send_headers);
  1111  
  1112  
  1113  
  1114  #ifdef __cplusplus
  1115  }
  1116  #endif
  1117  
  1118  #endif  /* !APACHE_HTTP_PROTOCOL_H */
  1119  /** @} */