/packages/httpd13/src/http_protocol.inc

https://github.com/slibre/freepascal · Pascal · 239 lines · 82 code · 62 blank · 95 comment · 0 complexity · bedb594d9698685e7026f3c08ff2a2cc MD5 · raw file

  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. * Prototypes for routines which either talk directly back to the user,
  18. * or control the ones that eventually do.
  19. }
  20. { Read a request and fill in the fields. }
  21. function ap_read_request(c: Pconn_rec): Prequest_rec;
  22. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  23. { Send a single HTTP header field }
  24. function ap_send_header_field(r: Prequest_rec; const fieldname, fieldval: PChar): cint;
  25. cdecl; external LibHTTPD;
  26. { Send the minimal part of an HTTP response header... but modules should be
  27. * very careful about using this, and should prefer ap_send_http_header().
  28. * Much of the HTTP/1.1 implementation correctness depends on code in
  29. * ap_send_http_header().
  30. }
  31. procedure ap_basic_http_header(r: Prequest_rec);
  32. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  33. { Send the Status-Line and header fields for HTTP response }
  34. procedure ap_send_http_header(l: Prequest_rec);
  35. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  36. { Send the response to special method requests }
  37. function ap_send_http_trace(r: Prequest_rec): cint;
  38. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  39. function ap_send_http_options(r: Prequest_rec): cint;
  40. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  41. { Finish up stuff after a request }
  42. procedure ap_finalize_request_protocol(r: Prequest_rec);
  43. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  44. { Send error back to client... last arg indicates error status in case
  45. * we get an error in the process of trying to deal with an ErrorDocument
  46. * to handle some other error. In that case, we print the default report
  47. * for the first thing that went wrong, and more briefly report on the
  48. * problem with the ErrorDocument.
  49. }
  50. procedure ap_send_error_response(r: Prequest_rec; recursive_error: cint);
  51. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  52. { Set last modified header line from the lastmod date of the associated file.
  53. * Also, set content length.
  54. *
  55. * May return an error status, typically USE_LOCAL_COPY (that when the
  56. * permit_cache argument is set to one).
  57. }
  58. function ap_set_content_length(r: Prequest_rec; length: clong): cint;
  59. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  60. function ap_set_keepalive(r: Prequest_rec): cint;
  61. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  62. function ap_rationalize_mtime(r: Prequest_rec; mtime: time_t): time_t;
  63. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  64. function ap_make_etag(r: Prequest_rec; force_weak: cint): PChar;
  65. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  66. procedure ap_set_etag(r: Prequest_rec);
  67. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  68. procedure ap_set_last_modified(r: Prequest_rec);
  69. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  70. function ap_meets_conditions(r: Prequest_rec): cint;
  71. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  72. { Other ways to send stuff at the client. All of these keep track
  73. * of bytes_sent automatically. This indirection is intended to make
  74. * it a little more painless to slide things like HTTP-NG packetization
  75. * underneath the main body of the code later. In the meantime, it lets
  76. * us centralize a bit of accounting (bytes_sent).
  77. *
  78. * These also return the number of bytes written by the call.
  79. * They should only be called with a timeout registered, for obvious reaasons.
  80. * (Ditto the send_header stuff).
  81. }
  82. //function ap_send_fd(f: PFILE; r: Prequest_rec): clong;
  83. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  84. //function ap_send_fd_length(f: PFILE; r: Prequest_rec; length: clong): clong;
  85. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  86. function ap_send_fb(f: PBUFF; r: Prequest_rec): clong;
  87. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  88. function ap_send_fb_length(f: PBUFF; r: Prequest_rec): clong;
  89. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  90. function ap_send_mmap(mm: Pointer; r: Prequest_rec; offset, length: size_t): size_t;
  91. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  92. { Hmmm... could macrofy these for now, and maybe forever, though the
  93. * definitions of the macros would get a whole lot hairier.
  94. }
  95. function ap_rputc(c: cint; r: Prequest_rec): cint;
  96. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  97. function ap_rputs(const str: PChar; r: Prequest_rec): cint;
  98. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  99. function ap_rwrite(const buf: Pointer; nbyte: cint; r: Prequest_rec): cint;
  100. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  101. function ap_rvputs(r: Prequest_rec; others: array of const): cint;
  102. cdecl; external LibHTTPD;
  103. function ap_vrprintf(r: Prequest_rec; const fmt: PChar; vlist: va_list): cint;
  104. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  105. function ap_rprintf(r: Prequest_rec; const fmt: PChar; others: array of const): cint;
  106. cdecl; external LibHTTPD;
  107. { __attribute__((format(printf,2,3)));}
  108. function ap_rflush(r: Prequest_rec): cint;
  109. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  110. {
  111. * Index used in custom_responses array for a specific error code
  112. * (only use outside protocol.c is in getting them configured).
  113. }
  114. function ap_index_of_response(status: cint): cint;
  115. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  116. { Reading a block of data from the client connection (e.g., POST arg) }
  117. function ap_setup_client_block(r: Prequest_rec; read_policy: cint): cint;
  118. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  119. function ap_should_client_block(r: Prequest_rec): cint;
  120. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  121. function ap_get_client_block(r: Prequest_rec; buffer: PChar; bufsiz: cint): clong;
  122. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  123. function ap_discard_request_body(r: Prequest_rec): cint;
  124. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  125. { Sending a byterange }
  126. function ap_set_byterange(r: Prequest_rec): cint;
  127. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  128. function ap_each_byterange(r: Prequest_rec; offset, length: Pclong): cint;
  129. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  130. { Support for the Basic authentication protocol. Note that there's
  131. * nothing that prevents these from being in mod_auth.c, except that other
  132. * modules which wanted to provide their own variants on finding users and
  133. * passwords for Basic auth (a fairly common request) would then require
  134. * mod_auth to be loaded or they wouldn't work.
  135. *
  136. * get_basic_auth_pw returns 0 (OK) if it set the 'pw' argument (and assured
  137. * a correct value in r->connection->user); otherwise it returns an error
  138. * code, either SERVER_ERROR if things are really confused, AUTH_REQUIRED
  139. * if no authentication at all seemed to be in use, or DECLINED if there
  140. * was authentication but it wasn't Basic (in which case, the caller should
  141. * presumably decline as well).
  142. *
  143. * note_basic_auth_failure arranges for the right stuff to be scribbled on
  144. * the HTTP return so that the client knows how to authenticate itself the
  145. * next time. As does note_digest_auth_failure for Digest auth.
  146. *
  147. * note_auth_failure does the same thing, but will call the correct one
  148. * based on the authentication type in use.
  149. *
  150. }
  151. procedure ap_note_auth_failure(r: Prequest_rec);
  152. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  153. procedure ap_note_basic_auth_failure(r: Prequest_rec);
  154. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  155. procedure ap_note_digest_auth_failure(r: Prequest_rec);
  156. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  157. function ap_get_basic_auth_pw(r: Prequest_rec; const pw: PPChar): cint;
  158. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  159. {
  160. * Setting up the protocol fields for subsidiary requests...
  161. * Also, a wrapup function to keep the internal accounting straight.
  162. }
  163. procedure ap_set_sub_req_protocol(rnew, r: Prequest_rec);
  164. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  165. procedure ap_finalize_sub_req_protocol(sub_r: Prequest_rec);
  166. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  167. { This is also useful for putting sub_reqs and internal_redirects together }
  168. //CORE_EXPORT(void) ap_parse_uri(request_rec *r, const char *uri);
  169. { Get the method number associated with the given string, assumed to
  170. * contain an HTTP method. Returns M_INVALID if not recognized.
  171. }
  172. function ap_method_number_of(const method: PChar): cint;
  173. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  174. function ap_getline(s: PChar; n: cint; in_: PBUFF; fold: cint): cint;
  175. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  176. function ap_get_chunk_size(b: PChar): clong;
  177. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;