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