httpd.h 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507
  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. * @file httpd.h
  18. * @brief HTTP Daemon routines
  19. *
  20. * @defgroup APACHE Apache HTTP Server
  21. *
  22. * Top level group of which all other groups are a member
  23. * @{
  24. *
  25. * @defgroup APACHE_MODS Loadable modules
  26. * Top level group for modules
  27. * @defgroup APACHE_OS Operating System Specific
  28. * @defgroup APACHE_INTERNAL Internal interfaces
  29. * @defgroup APACHE_CORE Core routines
  30. * @{
  31. * @defgroup APACHE_CORE_DAEMON HTTP Daemon Routine
  32. * @{
  33. */
  34. #ifndef APACHE_HTTPD_H
  35. #define APACHE_HTTPD_H
  36. /* XXX - We need to push more stuff to other .h files, or even .c files, to
  37. * make this file smaller
  38. */
  39. /* Headers in which EVERYONE has an interest... */
  40. #include "ap_config.h"
  41. #include "ap_mmn.h"
  42. #include "ap_release.h"
  43. #include "apr.h"
  44. #include "apr_general.h"
  45. #include "apr_tables.h"
  46. #include "apr_pools.h"
  47. #include "apr_time.h"
  48. #include "apr_network_io.h"
  49. #include "apr_buckets.h"
  50. #include "apr_poll.h"
  51. #include "apr_thread_proc.h"
  52. #include "os.h"
  53. #include "ap_regex.h"
  54. #if APR_HAVE_STDLIB_H
  55. #include <stdlib.h>
  56. #endif
  57. /* Note: apr_uri.h is also included, see below */
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /* ----------------------------- config dir ------------------------------ */
  62. /** Define this to be the default server home dir. Most things later in this
  63. * file with a relative pathname will have this added.
  64. */
  65. #ifndef HTTPD_ROOT
  66. #ifdef OS2
  67. /** Set default for OS/2 file system */
  68. #define HTTPD_ROOT "/os2httpd"
  69. #elif defined(WIN32)
  70. /** Set default for Windows file system */
  71. #define HTTPD_ROOT "/apache"
  72. #elif defined (NETWARE)
  73. /** Set the default for NetWare */
  74. #define HTTPD_ROOT "/apache"
  75. #else
  76. /** Set for all other OSs */
  77. #define HTTPD_ROOT "/usr/local/apache"
  78. #endif
  79. #endif /* HTTPD_ROOT */
  80. /*
  81. * --------- You shouldn't have to edit anything below this line ----------
  82. *
  83. * Any modifications to any defaults not defined above should be done in the
  84. * respective configuration file.
  85. *
  86. */
  87. /**
  88. * Default location of documents. Can be overridden by the DocumentRoot
  89. * directive.
  90. */
  91. #ifndef DOCUMENT_LOCATION
  92. #ifdef OS2
  93. /* Set default for OS/2 file system */
  94. #define DOCUMENT_LOCATION HTTPD_ROOT "/docs"
  95. #else
  96. /* Set default for non OS/2 file system */
  97. #define DOCUMENT_LOCATION HTTPD_ROOT "/htdocs"
  98. #endif
  99. #endif /* DOCUMENT_LOCATION */
  100. /** Maximum number of dynamically loaded modules */
  101. #ifndef DYNAMIC_MODULE_LIMIT
  102. #define DYNAMIC_MODULE_LIMIT 256
  103. #endif
  104. /** Default administrator's address */
  105. #define DEFAULT_ADMIN "[no address given]"
  106. /** The name of the log files */
  107. #ifndef DEFAULT_ERRORLOG
  108. #if defined(OS2) || defined(WIN32)
  109. #define DEFAULT_ERRORLOG "logs/error.log"
  110. #else
  111. #define DEFAULT_ERRORLOG "logs/error_log"
  112. #endif
  113. #endif /* DEFAULT_ERRORLOG */
  114. /** Define this to be what your per-directory security files are called */
  115. #ifndef DEFAULT_ACCESS_FNAME
  116. #ifdef OS2
  117. /* Set default for OS/2 file system */
  118. #define DEFAULT_ACCESS_FNAME "htaccess"
  119. #else
  120. #define DEFAULT_ACCESS_FNAME ".htaccess"
  121. #endif
  122. #endif /* DEFAULT_ACCESS_FNAME */
  123. /** The name of the server config file */
  124. #ifndef SERVER_CONFIG_FILE
  125. #define SERVER_CONFIG_FILE "conf/httpd.conf"
  126. #endif
  127. /** The default path for CGI scripts if none is currently set */
  128. #ifndef DEFAULT_PATH
  129. #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
  130. #endif
  131. /** The path to the suExec wrapper, can be overridden in Configuration */
  132. #ifndef SUEXEC_BIN
  133. #define SUEXEC_BIN HTTPD_ROOT "/bin/suexec"
  134. #endif
  135. /** The timeout for waiting for messages */
  136. #ifndef DEFAULT_TIMEOUT
  137. #define DEFAULT_TIMEOUT 60
  138. #endif
  139. /** The timeout for waiting for keepalive timeout until next request */
  140. #ifndef DEFAULT_KEEPALIVE_TIMEOUT
  141. #define DEFAULT_KEEPALIVE_TIMEOUT 5
  142. #endif
  143. /** The number of requests to entertain per connection */
  144. #ifndef DEFAULT_KEEPALIVE
  145. #define DEFAULT_KEEPALIVE 100
  146. #endif
  147. /*
  148. * Limits on the size of various request items. These limits primarily
  149. * exist to prevent simple denial-of-service attacks on a server based
  150. * on misuse of the protocol. The recommended values will depend on the
  151. * nature of the server resources -- CGI scripts and database backends
  152. * might require large values, but most servers could get by with much
  153. * smaller limits than we use below. The request message body size can
  154. * be limited by the per-dir config directive LimitRequestBody.
  155. *
  156. * Internal buffer sizes are two bytes more than the DEFAULT_LIMIT_REQUEST_LINE
  157. * and DEFAULT_LIMIT_REQUEST_FIELDSIZE below, which explains the 8190.
  158. * These two limits can be lowered or raised by the server config
  159. * directives LimitRequestLine and LimitRequestFieldsize, respectively.
  160. *
  161. * DEFAULT_LIMIT_REQUEST_FIELDS can be modified or disabled (set = 0) by
  162. * the server config directive LimitRequestFields.
  163. */
  164. /** default limit on bytes in Request-Line (Method+URI+HTTP-version) */
  165. #ifndef DEFAULT_LIMIT_REQUEST_LINE
  166. #define DEFAULT_LIMIT_REQUEST_LINE 8190
  167. #endif
  168. /** default limit on bytes in any one header field */
  169. #ifndef DEFAULT_LIMIT_REQUEST_FIELDSIZE
  170. #define DEFAULT_LIMIT_REQUEST_FIELDSIZE 8190
  171. #endif
  172. /** default limit on number of request header fields */
  173. #ifndef DEFAULT_LIMIT_REQUEST_FIELDS
  174. #define DEFAULT_LIMIT_REQUEST_FIELDS 100
  175. #endif
  176. /** default/hard limit on number of leading/trailing empty lines */
  177. #ifndef DEFAULT_LIMIT_BLANK_LINES
  178. #define DEFAULT_LIMIT_BLANK_LINES 10
  179. #endif
  180. /**
  181. * The default default character set name to add if AddDefaultCharset is
  182. * enabled. Overridden with AddDefaultCharsetName.
  183. */
  184. #define DEFAULT_ADD_DEFAULT_CHARSET_NAME "iso-8859-1"
  185. /** default HTTP Server protocol */
  186. #define AP_SERVER_PROTOCOL "HTTP/1.1"
  187. /* ------------------ stuff that modules are allowed to look at ----------- */
  188. /** Define this to be what your HTML directory content files are called */
  189. #ifndef AP_DEFAULT_INDEX
  190. #define AP_DEFAULT_INDEX "index.html"
  191. #endif
  192. /** The name of the MIME types file */
  193. #ifndef AP_TYPES_CONFIG_FILE
  194. #define AP_TYPES_CONFIG_FILE "conf/mime.types"
  195. #endif
  196. /*
  197. * Define the HTML doctype strings centrally.
  198. */
  199. /** HTML 2.0 Doctype */
  200. #define DOCTYPE_HTML_2_0 "<!DOCTYPE HTML PUBLIC \"-//IETF//" \
  201. "DTD HTML 2.0//EN\">\n"
  202. /** HTML 3.2 Doctype */
  203. #define DOCTYPE_HTML_3_2 "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
  204. "DTD HTML 3.2 Final//EN\">\n"
  205. /** HTML 4.0 Strict Doctype */
  206. #define DOCTYPE_HTML_4_0S "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
  207. "DTD HTML 4.0//EN\"\n" \
  208. "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
  209. /** HTML 4.0 Transitional Doctype */
  210. #define DOCTYPE_HTML_4_0T "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
  211. "DTD HTML 4.0 Transitional//EN\"\n" \
  212. "\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"
  213. /** HTML 4.0 Frameset Doctype */
  214. #define DOCTYPE_HTML_4_0F "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
  215. "DTD HTML 4.0 Frameset//EN\"\n" \
  216. "\"http://www.w3.org/TR/REC-html40/frameset.dtd\">\n"
  217. /** XHTML 1.0 Strict Doctype */
  218. #define DOCTYPE_XHTML_1_0S "<!DOCTYPE html PUBLIC \"-//W3C//" \
  219. "DTD XHTML 1.0 Strict//EN\"\n" \
  220. "\"http://www.w3.org/TR/xhtml1/DTD/" \
  221. "xhtml1-strict.dtd\">\n"
  222. /** XHTML 1.0 Transitional Doctype */
  223. #define DOCTYPE_XHTML_1_0T "<!DOCTYPE html PUBLIC \"-//W3C//" \
  224. "DTD XHTML 1.0 Transitional//EN\"\n" \
  225. "\"http://www.w3.org/TR/xhtml1/DTD/" \
  226. "xhtml1-transitional.dtd\">\n"
  227. /** XHTML 1.0 Frameset Doctype */
  228. #define DOCTYPE_XHTML_1_0F "<!DOCTYPE html PUBLIC \"-//W3C//" \
  229. "DTD XHTML 1.0 Frameset//EN\"\n" \
  230. "\"http://www.w3.org/TR/xhtml1/DTD/" \
  231. "xhtml1-frameset.dtd\">"
  232. /** Internal representation for a HTTP protocol number, e.g., HTTP/1.1 */
  233. #define HTTP_VERSION(major,minor) (1000*(major)+(minor))
  234. /** Major part of HTTP protocol */
  235. #define HTTP_VERSION_MAJOR(number) ((number)/1000)
  236. /** Minor part of HTTP protocol */
  237. #define HTTP_VERSION_MINOR(number) ((number)%1000)
  238. /* -------------- Port number for server running standalone --------------- */
  239. /** default HTTP Port */
  240. #define DEFAULT_HTTP_PORT 80
  241. /** default HTTPS Port */
  242. #define DEFAULT_HTTPS_PORT 443
  243. /**
  244. * Check whether @a port is the default port for the request @a r.
  245. * @param port The port number
  246. * @param r The request
  247. * @see #ap_default_port
  248. */
  249. #define ap_is_default_port(port,r) ((port) == ap_default_port(r))
  250. /**
  251. * Get the default port for a request (which depends on the scheme).
  252. * @param r The request
  253. */
  254. #define ap_default_port(r) ap_run_default_port(r)
  255. /**
  256. * Get the scheme for a request.
  257. * @param r The request
  258. */
  259. #define ap_http_scheme(r) ap_run_http_scheme(r)
  260. /** The default string length */
  261. #define MAX_STRING_LEN HUGE_STRING_LEN
  262. /** The length of a Huge string */
  263. #define HUGE_STRING_LEN 8192
  264. /** The size of the server's internal read-write buffers */
  265. #define AP_IOBUFSIZE 8192
  266. /** The max number of regex captures that can be expanded by ap_pregsub */
  267. #define AP_MAX_REG_MATCH 10
  268. /**
  269. * APR_HAS_LARGE_FILES introduces the problem of spliting sendfile into
  270. * multiple buckets, no greater than MAX(apr_size_t), and more granular
  271. * than that in case the brigade code/filters attempt to read it directly.
  272. * ### 16mb is an invention, no idea if it is reasonable.
  273. */
  274. #define AP_MAX_SENDFILE 16777216 /* 2^24 */
  275. /**
  276. * MPM child process exit status values
  277. * The MPM parent process may check the status to see if special
  278. * error handling is required.
  279. */
  280. /** a normal exit */
  281. #define APEXIT_OK 0x0
  282. /** A fatal error arising during the server's init sequence */
  283. #define APEXIT_INIT 0x2
  284. /** The child died during its init sequence */
  285. #define APEXIT_CHILDINIT 0x3
  286. /**
  287. * The child exited due to a resource shortage.
  288. * The parent should limit the rate of forking until
  289. * the situation is resolved.
  290. */
  291. #define APEXIT_CHILDSICK 0x7
  292. /**
  293. * A fatal error, resulting in the whole server aborting.
  294. * If a child exits with this error, the parent process
  295. * considers this a server-wide fatal error and aborts.
  296. */
  297. #define APEXIT_CHILDFATAL 0xf
  298. #ifndef AP_DECLARE
  299. /**
  300. * Stuff marked #AP_DECLARE is part of the API, and intended for use
  301. * by modules. Its purpose is to allow us to add attributes that
  302. * particular platforms or compilers require to every exported function.
  303. */
  304. # define AP_DECLARE(type) type
  305. #endif
  306. #ifndef AP_DECLARE_NONSTD
  307. /**
  308. * Stuff marked #AP_DECLARE_NONSTD is part of the API, and intended for
  309. * use by modules. The difference between #AP_DECLARE and
  310. * #AP_DECLARE_NONSTD is that the latter is required for any functions
  311. * which use varargs or are used via indirect function call. This
  312. * is to accommodate the two calling conventions in windows dlls.
  313. */
  314. # define AP_DECLARE_NONSTD(type) type
  315. #endif
  316. #ifndef AP_DECLARE_DATA
  317. # define AP_DECLARE_DATA
  318. #endif
  319. #ifndef AP_MODULE_DECLARE
  320. # define AP_MODULE_DECLARE(type) type
  321. #endif
  322. #ifndef AP_MODULE_DECLARE_NONSTD
  323. # define AP_MODULE_DECLARE_NONSTD(type) type
  324. #endif
  325. #ifndef AP_MODULE_DECLARE_DATA
  326. # define AP_MODULE_DECLARE_DATA
  327. #endif
  328. /**
  329. * @internal
  330. * modules should not use functions marked AP_CORE_DECLARE
  331. */
  332. #ifndef AP_CORE_DECLARE
  333. # define AP_CORE_DECLARE AP_DECLARE
  334. #endif
  335. /**
  336. * @internal
  337. * modules should not use functions marked AP_CORE_DECLARE_NONSTD
  338. */
  339. #ifndef AP_CORE_DECLARE_NONSTD
  340. # define AP_CORE_DECLARE_NONSTD AP_DECLARE_NONSTD
  341. #endif
  342. /**
  343. * @defgroup APACHE_APR_STATUS_T HTTPD specific values of apr_status_t
  344. * @{
  345. */
  346. #define AP_START_USERERR (APR_OS_START_USERERR + 2000)
  347. #define AP_USERERR_LEN 1000
  348. /** The function declines to handle the request */
  349. #define AP_DECLINED (AP_START_USERERR + 0)
  350. /** @} */
  351. /**
  352. * @brief The numeric version information is broken out into fields within this
  353. * structure.
  354. */
  355. typedef struct {
  356. int major; /**< major number */
  357. int minor; /**< minor number */
  358. int patch; /**< patch number */
  359. const char *add_string; /**< additional string like "-dev" */
  360. } ap_version_t;
  361. /**
  362. * Return httpd's version information in a numeric form.
  363. *
  364. * @param version Pointer to a version structure for returning the version
  365. * information.
  366. */
  367. AP_DECLARE(void) ap_get_server_revision(ap_version_t *version);
  368. /**
  369. * Get the server banner in a form suitable for sending over the
  370. * network, with the level of information controlled by the
  371. * ServerTokens directive.
  372. * @return The server banner
  373. */
  374. AP_DECLARE(const char *) ap_get_server_banner(void);
  375. /**
  376. * Get the server description in a form suitable for local displays,
  377. * status reports, or logging. This includes the detailed server
  378. * version and information about some modules. It is not affected
  379. * by the ServerTokens directive.
  380. * @return The server description
  381. */
  382. AP_DECLARE(const char *) ap_get_server_description(void);
  383. /**
  384. * Add a component to the server description and banner strings
  385. * @param pconf The pool to allocate the component from
  386. * @param component The string to add
  387. */
  388. AP_DECLARE(void) ap_add_version_component(apr_pool_t *pconf, const char *component);
  389. /**
  390. * Get the date a time that the server was built
  391. * @return The server build time string
  392. */
  393. AP_DECLARE(const char *) ap_get_server_built(void);
  394. /* non-HTTP status codes returned by hooks */
  395. #define OK 0 /**< Module has handled this stage. */
  396. #define DECLINED -1 /**< Module declines to handle */
  397. #define DONE -2 /**< Module has served the response completely
  398. * - it's safe to die() with no more output
  399. */
  400. #define SUSPENDED -3 /**< Module will handle the remainder of the request.
  401. * The core will never invoke the request again, */
  402. /** Returned by the bottom-most filter if no data was written.
  403. * @see ap_pass_brigade(). */
  404. #define AP_NOBODY_WROTE -100
  405. /** Returned by the bottom-most filter if no data was read.
  406. * @see ap_get_brigade(). */
  407. #define AP_NOBODY_READ -101
  408. /** Returned by any filter if the filter chain encounters an error
  409. * and has already dealt with the error response.
  410. */
  411. #define AP_FILTER_ERROR -102
  412. /**
  413. * @defgroup HTTP_Status HTTP Status Codes
  414. * @{
  415. */
  416. /**
  417. * The size of the static status_lines array in http_protocol.c for
  418. * storing all of the potential response status-lines (a sparse table).
  419. * When adding a new code here add it to status_lines as well.
  420. * A future version should dynamically generate the apr_table_t at startup.
  421. */
  422. #define RESPONSE_CODES 103
  423. #define HTTP_CONTINUE 100
  424. #define HTTP_SWITCHING_PROTOCOLS 101
  425. #define HTTP_PROCESSING 102
  426. #define HTTP_OK 200
  427. #define HTTP_CREATED 201
  428. #define HTTP_ACCEPTED 202
  429. #define HTTP_NON_AUTHORITATIVE 203
  430. #define HTTP_NO_CONTENT 204
  431. #define HTTP_RESET_CONTENT 205
  432. #define HTTP_PARTIAL_CONTENT 206
  433. #define HTTP_MULTI_STATUS 207
  434. #define HTTP_ALREADY_REPORTED 208
  435. #define HTTP_IM_USED 226
  436. #define HTTP_MULTIPLE_CHOICES 300
  437. #define HTTP_MOVED_PERMANENTLY 301
  438. #define HTTP_MOVED_TEMPORARILY 302
  439. #define HTTP_SEE_OTHER 303
  440. #define HTTP_NOT_MODIFIED 304
  441. #define HTTP_USE_PROXY 305
  442. #define HTTP_TEMPORARY_REDIRECT 307
  443. #define HTTP_PERMANENT_REDIRECT 308
  444. #define HTTP_BAD_REQUEST 400
  445. #define HTTP_UNAUTHORIZED 401
  446. #define HTTP_PAYMENT_REQUIRED 402
  447. #define HTTP_FORBIDDEN 403
  448. #define HTTP_NOT_FOUND 404
  449. #define HTTP_METHOD_NOT_ALLOWED 405
  450. #define HTTP_NOT_ACCEPTABLE 406
  451. #define HTTP_PROXY_AUTHENTICATION_REQUIRED 407
  452. #define HTTP_REQUEST_TIME_OUT 408
  453. #define HTTP_CONFLICT 409
  454. #define HTTP_GONE 410
  455. #define HTTP_LENGTH_REQUIRED 411
  456. #define HTTP_PRECONDITION_FAILED 412
  457. #define HTTP_REQUEST_ENTITY_TOO_LARGE 413
  458. #define HTTP_REQUEST_URI_TOO_LARGE 414
  459. #define HTTP_UNSUPPORTED_MEDIA_TYPE 415
  460. #define HTTP_RANGE_NOT_SATISFIABLE 416
  461. #define HTTP_EXPECTATION_FAILED 417
  462. #define HTTP_MISDIRECTED_REQUEST 421
  463. #define HTTP_UNPROCESSABLE_ENTITY 422
  464. #define HTTP_LOCKED 423
  465. #define HTTP_FAILED_DEPENDENCY 424
  466. #define HTTP_UPGRADE_REQUIRED 426
  467. #define HTTP_PRECONDITION_REQUIRED 428
  468. #define HTTP_TOO_MANY_REQUESTS 429
  469. #define HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE 431
  470. #define HTTP_UNAVAILABLE_FOR_LEGAL_REASONS 451
  471. #define HTTP_INTERNAL_SERVER_ERROR 500
  472. #define HTTP_NOT_IMPLEMENTED 501
  473. #define HTTP_BAD_GATEWAY 502
  474. #define HTTP_SERVICE_UNAVAILABLE 503
  475. #define HTTP_GATEWAY_TIME_OUT 504
  476. #define HTTP_VERSION_NOT_SUPPORTED 505
  477. #define HTTP_VARIANT_ALSO_VARIES 506
  478. #define HTTP_INSUFFICIENT_STORAGE 507
  479. #define HTTP_LOOP_DETECTED 508
  480. #define HTTP_NOT_EXTENDED 510
  481. #define HTTP_NETWORK_AUTHENTICATION_REQUIRED 511
  482. /** is the status code informational */
  483. #define ap_is_HTTP_INFO(x) (((x) >= 100)&&((x) < 200))
  484. /** is the status code OK ?*/
  485. #define ap_is_HTTP_SUCCESS(x) (((x) >= 200)&&((x) < 300))
  486. /** is the status code a redirect */
  487. #define ap_is_HTTP_REDIRECT(x) (((x) >= 300)&&((x) < 400))
  488. /** is the status code a error (client or server) */
  489. #define ap_is_HTTP_ERROR(x) (((x) >= 400)&&((x) < 600))
  490. /** is the status code a client error */
  491. #define ap_is_HTTP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500))
  492. /** is the status code a server error */
  493. #define ap_is_HTTP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600))
  494. /** is the status code a (potentially) valid response code? */
  495. #define ap_is_HTTP_VALID_RESPONSE(x) (((x) >= 100)&&((x) < 600))
  496. /** should the status code drop the connection */
  497. #define ap_status_drops_connection(x) \
  498. (((x) == HTTP_BAD_REQUEST) || \
  499. ((x) == HTTP_REQUEST_TIME_OUT) || \
  500. ((x) == HTTP_LENGTH_REQUIRED) || \
  501. ((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \
  502. ((x) == HTTP_REQUEST_URI_TOO_LARGE) || \
  503. ((x) == HTTP_INTERNAL_SERVER_ERROR) || \
  504. ((x) == HTTP_SERVICE_UNAVAILABLE) || \
  505. ((x) == HTTP_NOT_IMPLEMENTED))
  506. /** does the status imply header only response (i.e. never w/ a body)? */
  507. #define AP_STATUS_IS_HEADER_ONLY(x) ((x) == HTTP_NO_CONTENT || \
  508. (x) == HTTP_NOT_MODIFIED)
  509. /** @} */
  510. /**
  511. * @defgroup Methods List of Methods recognized by the server
  512. * @ingroup APACHE_CORE_DAEMON
  513. * @{
  514. *
  515. * @brief Methods recognized (but not necessarily handled) by the server.
  516. *
  517. * These constants are used in bit shifting masks of size int, so it is
  518. * unsafe to have more methods than bits in an int. HEAD == M_GET.
  519. * This list must be tracked by the list in http_protocol.c in routine
  520. * ap_method_name_of().
  521. *
  522. */
  523. #define M_GET 0 /** RFC 2616: HTTP */
  524. #define M_PUT 1 /* : */
  525. #define M_POST 2
  526. #define M_DELETE 3
  527. #define M_CONNECT 4
  528. #define M_OPTIONS 5
  529. #define M_TRACE 6 /** RFC 2616: HTTP */
  530. #define M_PATCH 7 /** RFC 5789: PATCH Method for HTTP */
  531. #define M_PROPFIND 8 /** RFC 2518: WebDAV */
  532. #define M_PROPPATCH 9 /* : */
  533. #define M_MKCOL 10
  534. #define M_COPY 11
  535. #define M_MOVE 12
  536. #define M_LOCK 13
  537. #define M_UNLOCK 14 /** RFC 2518: WebDAV */
  538. #define M_VERSION_CONTROL 15 /** RFC 3253: WebDAV Versioning */
  539. #define M_CHECKOUT 16 /* : */
  540. #define M_UNCHECKOUT 17
  541. #define M_CHECKIN 18
  542. #define M_UPDATE 19
  543. #define M_LABEL 20
  544. #define M_REPORT 21
  545. #define M_MKWORKSPACE 22
  546. #define M_MKACTIVITY 23
  547. #define M_BASELINE_CONTROL 24
  548. #define M_MERGE 25
  549. #define M_INVALID 26 /** no valid method */
  550. /**
  551. * METHODS needs to be equal to the number of bits
  552. * we are using for limit masks.
  553. */
  554. #define METHODS 64
  555. /**
  556. * The method mask bit to shift for anding with a bitmask.
  557. */
  558. #define AP_METHOD_BIT ((apr_int64_t)1)
  559. /** @} */
  560. /** @see ap_method_list_t */
  561. typedef struct ap_method_list_t ap_method_list_t;
  562. /**
  563. * @struct ap_method_list_t
  564. * @brief Structure for handling HTTP methods.
  565. *
  566. * Methods known to the server are accessed via a bitmask shortcut;
  567. * extension methods are handled by an array.
  568. */
  569. struct ap_method_list_t {
  570. /** The bitmask used for known methods */
  571. apr_int64_t method_mask;
  572. /** the array used for extension methods */
  573. apr_array_header_t *method_list;
  574. };
  575. /**
  576. * @defgroup module_magic Module Magic mime types
  577. * @{
  578. */
  579. /** Magic for mod_cgi[d] */
  580. #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
  581. /** Magic for mod_include */
  582. #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
  583. /** Magic for mod_include */
  584. #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
  585. /** Magic for mod_dir */
  586. #define DIR_MAGIC_TYPE "httpd/unix-directory"
  587. /** Default for r->handler if no content-type set by type_checker */
  588. #define AP_DEFAULT_HANDLER_NAME ""
  589. #define AP_IS_DEFAULT_HANDLER_NAME(x) (*x == '\0')
  590. /** @} */
  591. /* Just in case your linefeed isn't the one the other end is expecting. */
  592. #if !APR_CHARSET_EBCDIC
  593. /** linefeed */
  594. #define LF 10
  595. /** carrige return */
  596. #define CR 13
  597. /** carrige return /Line Feed Combo */
  598. #define CRLF "\015\012"
  599. #else /* APR_CHARSET_EBCDIC */
  600. /* For platforms using the EBCDIC charset, the transition ASCII->EBCDIC is done
  601. * in the buff package (bread/bputs/bwrite). Everywhere else, we use
  602. * "native EBCDIC" CR and NL characters. These are therefore
  603. * defined as
  604. * '\r' and '\n'.
  605. */
  606. #define CR '\r'
  607. #define LF '\n'
  608. #define CRLF "\r\n"
  609. #endif /* APR_CHARSET_EBCDIC */
  610. /** Useful for common code with either platform charset. */
  611. #define CRLF_ASCII "\015\012"
  612. /**
  613. * @defgroup values_request_rec_body Possible values for request_rec.read_body
  614. * @{
  615. * Possible values for request_rec.read_body (set by handling module):
  616. */
  617. /** Send 413 error if message has any body */
  618. #define REQUEST_NO_BODY 0
  619. /** Send 411 error if body without Content-Length */
  620. #define REQUEST_CHUNKED_ERROR 1
  621. /** If chunked, remove the chunks for me. */
  622. #define REQUEST_CHUNKED_DECHUNK 2
  623. /** @} // values_request_rec_body */
  624. /**
  625. * @defgroup values_request_rec_used_path_info Possible values for request_rec.used_path_info
  626. * @ingroup APACHE_CORE_DAEMON
  627. * @{
  628. * Possible values for request_rec.used_path_info:
  629. */
  630. /** Accept the path_info from the request */
  631. #define AP_REQ_ACCEPT_PATH_INFO 0
  632. /** Return a 404 error if path_info was given */
  633. #define AP_REQ_REJECT_PATH_INFO 1
  634. /** Module may chose to use the given path_info */
  635. #define AP_REQ_DEFAULT_PATH_INFO 2
  636. /** @} // values_request_rec_used_path_info */
  637. /*
  638. * Things which may vary per file-lookup WITHIN a request ---
  639. * e.g., state of MIME config. Basically, the name of an object, info
  640. * about the object, and any other info we may ahve which may need to
  641. * change as we go poking around looking for it (e.g., overridden by
  642. * .htaccess files).
  643. *
  644. * Note how the default state of almost all these things is properly
  645. * zero, so that allocating it with pcalloc does the right thing without
  646. * a whole lot of hairy initialization... so long as we are willing to
  647. * make the (fairly) portable assumption that the bit pattern of a NULL
  648. * pointer is, in fact, zero.
  649. */
  650. /**
  651. * @brief This represents the result of calling htaccess; these are cached for
  652. * each request.
  653. */
  654. struct htaccess_result {
  655. /** the directory to which this applies */
  656. const char *dir;
  657. /** the overrides allowed for the .htaccess file */
  658. int override;
  659. /** the override options allowed for the .htaccess file */
  660. int override_opts;
  661. /** Table of allowed directives for override */
  662. apr_table_t *override_list;
  663. /** the configuration directives */
  664. struct ap_conf_vector_t *htaccess;
  665. /** the next one, or NULL if no more; N.B. never change this */
  666. const struct htaccess_result *next;
  667. };
  668. /* The following four types define a hierarchy of activities, so that
  669. * given a request_rec r you can write r->connection->server->process
  670. * to get to the process_rec. While this reduces substantially the
  671. * number of arguments that various hooks require beware that in
  672. * threaded versions of the server you must consider multiplexing
  673. * issues. */
  674. /** A structure that represents one process */
  675. typedef struct process_rec process_rec;
  676. /** A structure that represents a virtual server */
  677. typedef struct server_rec server_rec;
  678. /** A structure that represents one connection */
  679. typedef struct conn_rec conn_rec;
  680. /** A structure that represents the current request */
  681. typedef struct request_rec request_rec;
  682. /** A structure that represents the status of the current connection */
  683. typedef struct conn_state_t conn_state_t;
  684. /* ### would be nice to not include this from httpd.h ... */
  685. /* This comes after we have defined the request_rec type */
  686. #include "apr_uri.h"
  687. /**
  688. * @brief A structure that represents one process
  689. */
  690. struct process_rec {
  691. /** Global pool. Cleared upon normal exit */
  692. apr_pool_t *pool;
  693. /** Configuration pool. Cleared upon restart */
  694. apr_pool_t *pconf;
  695. /** The program name used to execute the program */
  696. const char *short_name;
  697. /** The command line arguments */
  698. const char * const *argv;
  699. /** Number of command line arguments passed to the program */
  700. int argc;
  701. };
  702. /**
  703. * @brief A structure that represents the current request
  704. */
  705. struct request_rec {
  706. /** The pool associated with the request */
  707. apr_pool_t *pool;
  708. /** The connection to the client */
  709. conn_rec *connection;
  710. /** The virtual host for this request */
  711. server_rec *server;
  712. /** Pointer to the redirected request if this is an external redirect */
  713. request_rec *next;
  714. /** Pointer to the previous request if this is an internal redirect */
  715. request_rec *prev;
  716. /** Pointer to the main request if this is a sub-request
  717. * (see http_request.h) */
  718. request_rec *main;
  719. /* Info about the request itself... we begin with stuff that only
  720. * protocol.c should ever touch...
  721. */
  722. /** First line of request */
  723. char *the_request;
  724. /** HTTP/0.9, "simple" request (e.g. GET /foo\n w/no headers) */
  725. int assbackwards;
  726. /** A proxy request (calculated during post_read_request/translate_name)
  727. * possible values PROXYREQ_NONE, PROXYREQ_PROXY, PROXYREQ_REVERSE,
  728. * PROXYREQ_RESPONSE
  729. */
  730. int proxyreq;
  731. /** HEAD request, as opposed to GET */
  732. int header_only;
  733. /** Protocol version number of protocol; 1.1 = 1001 */
  734. int proto_num;
  735. /** Protocol string, as given to us, or HTTP/0.9 */
  736. char *protocol;
  737. /** Host, as set by full URI or Host: header.
  738. * For literal IPv6 addresses, this does NOT include the surrounding [ ]
  739. */
  740. const char *hostname;
  741. /** Time when the request started */
  742. apr_time_t request_time;
  743. /** Status line, if set by script */
  744. const char *status_line;
  745. /** Status line */
  746. int status;
  747. /* Request method, two ways; also, protocol, etc.. Outside of protocol.c,
  748. * look, but don't touch.
  749. */
  750. /** M_GET, M_POST, etc. */
  751. int method_number;
  752. /** Request method (eg. GET, HEAD, POST, etc.) */
  753. const char *method;
  754. /**
  755. * 'allowed' is a bitvector of the allowed methods.
  756. *
  757. * A handler must ensure that the request method is one that
  758. * it is capable of handling. Generally modules should DECLINE
  759. * any request methods they do not handle. Prior to aborting the
  760. * handler like this the handler should set r->allowed to the list
  761. * of methods that it is willing to handle. This bitvector is used
  762. * to construct the "Allow:" header required for OPTIONS requests,
  763. * and HTTP_METHOD_NOT_ALLOWED and HTTP_NOT_IMPLEMENTED status codes.
  764. *
  765. * Since the default_handler deals with OPTIONS, all modules can
  766. * usually decline to deal with OPTIONS. TRACE is always allowed,
  767. * modules don't need to set it explicitly.
  768. *
  769. * Since the default_handler will always handle a GET, a
  770. * module which does *not* implement GET should probably return
  771. * HTTP_METHOD_NOT_ALLOWED. Unfortunately this means that a Script GET
  772. * handler can't be installed by mod_actions.
  773. */
  774. apr_int64_t allowed;
  775. /** Array of extension methods */
  776. apr_array_header_t *allowed_xmethods;
  777. /** List of allowed methods */
  778. ap_method_list_t *allowed_methods;
  779. /** byte count in stream is for body */
  780. apr_off_t sent_bodyct;
  781. /** body byte count, for easy access */
  782. apr_off_t bytes_sent;
  783. /** Last modified time of the requested resource */
  784. apr_time_t mtime;
  785. /* HTTP/1.1 connection-level features */
  786. /** The Range: header */
  787. const char *range;
  788. /** The "real" content length */
  789. apr_off_t clength;
  790. /** sending chunked transfer-coding */
  791. int chunked;
  792. /** Method for reading the request body
  793. * (eg. REQUEST_CHUNKED_ERROR, REQUEST_NO_BODY,
  794. * REQUEST_CHUNKED_DECHUNK, etc...) */
  795. int read_body;
  796. /** reading chunked transfer-coding */
  797. int read_chunked;
  798. /** is client waiting for a 100 response? */
  799. unsigned expecting_100;
  800. /** The optional kept body of the request. */
  801. apr_bucket_brigade *kept_body;
  802. /** For ap_body_to_table(): parsed body */
  803. /* XXX: ap_body_to_table has been removed. Remove body_table too or
  804. * XXX: keep it to reintroduce ap_body_to_table without major bump? */
  805. apr_table_t *body_table;
  806. /** Remaining bytes left to read from the request body */
  807. apr_off_t remaining;
  808. /** Number of bytes that have been read from the request body */
  809. apr_off_t read_length;
  810. /* MIME header environments, in and out. Also, an array containing
  811. * environment variables to be passed to subprocesses, so people can
  812. * write modules to add to that environment.
  813. *
  814. * The difference between headers_out and err_headers_out is that the
  815. * latter are printed even on error, and persist across internal redirects
  816. * (so the headers printed for ErrorDocument handlers will have them).
  817. *
  818. * The 'notes' apr_table_t is for notes from one module to another, with no
  819. * other set purpose in mind...
  820. */
  821. /** MIME header environment from the request */
  822. apr_table_t *headers_in;
  823. /** MIME header environment for the response */
  824. apr_table_t *headers_out;
  825. /** MIME header environment for the response, printed even on errors and
  826. * persist across internal redirects */
  827. apr_table_t *err_headers_out;
  828. /** Array of environment variables to be used for sub processes */
  829. apr_table_t *subprocess_env;
  830. /** Notes from one module to another */
  831. apr_table_t *notes;
  832. /* content_type, handler, content_encoding, and all content_languages
  833. * MUST be lowercased strings. They may be pointers to static strings;
  834. * they should not be modified in place.
  835. */
  836. /** The content-type for the current request */
  837. const char *content_type; /* Break these out --- we dispatch on 'em */
  838. /** The handler string that we use to call a handler function */
  839. const char *handler; /* What we *really* dispatch on */
  840. /** How to encode the data */
  841. const char *content_encoding;
  842. /** Array of strings representing the content languages */
  843. apr_array_header_t *content_languages;
  844. /** variant list validator (if negotiated) */
  845. char *vlist_validator;
  846. /** If an authentication check was made, this gets set to the user name. */
  847. char *user;
  848. /** If an authentication check was made, this gets set to the auth type. */
  849. char *ap_auth_type;
  850. /* What object is being requested (either directly, or via include
  851. * or content-negotiation mapping).
  852. */
  853. /** The URI without any parsing performed */
  854. char *unparsed_uri;
  855. /** The path portion of the URI, or "/" if no path provided */
  856. char *uri;
  857. /** The filename on disk corresponding to this response */
  858. char *filename;
  859. /** The true filename stored in the filesystem, as in the true alpha case
  860. * and alias correction, e.g. "Image.jpeg" not "IMAGE$1.JPE" on Windows.
  861. * The core map_to_storage canonicalizes r->filename when they mismatch */
  862. char *canonical_filename;
  863. /** The PATH_INFO extracted from this request */
  864. char *path_info;
  865. /** The QUERY_ARGS extracted from this request */
  866. char *args;
  867. /**
  868. * Flag for the handler to accept or reject path_info on
  869. * the current request. All modules should respect the
  870. * AP_REQ_ACCEPT_PATH_INFO and AP_REQ_REJECT_PATH_INFO
  871. * values, while AP_REQ_DEFAULT_PATH_INFO indicates they
  872. * may follow existing conventions. This is set to the
  873. * user's preference upon HOOK_VERY_FIRST of the fixups.
  874. */
  875. int used_path_info;
  876. /** A flag to determine if the eos bucket has been sent yet */
  877. int eos_sent;
  878. /* Various other config info which may change with .htaccess files
  879. * These are config vectors, with one void* pointer for each module
  880. * (the thing pointed to being the module's business).
  881. */
  882. /** Options set in config files, etc. */
  883. struct ap_conf_vector_t *per_dir_config;
  884. /** Notes on *this* request */
  885. struct ap_conf_vector_t *request_config;
  886. /** Optional request log level configuration. Will usually point
  887. * to a server or per_dir config, i.e. must be copied before
  888. * modifying */
  889. const struct ap_logconf *log;
  890. /** Id to identify request in access and error log. Set when the first
  891. * error log entry for this request is generated.
  892. */
  893. const char *log_id;
  894. /**
  895. * A linked list of the .htaccess configuration directives
  896. * accessed by this request.
  897. * N.B. always add to the head of the list, _never_ to the end.
  898. * that way, a sub request's list can (temporarily) point to a parent's list
  899. */
  900. const struct htaccess_result *htaccess;
  901. /** A list of output filters to be used for this request */
  902. struct ap_filter_t *output_filters;
  903. /** A list of input filters to be used for this request */
  904. struct ap_filter_t *input_filters;
  905. /** A list of protocol level output filters to be used for this
  906. * request */
  907. struct ap_filter_t *proto_output_filters;
  908. /** A list of protocol level input filters to be used for this
  909. * request */
  910. struct ap_filter_t *proto_input_filters;
  911. /** This response can not be cached */
  912. int no_cache;
  913. /** There is no local copy of this response */
  914. int no_local_copy;
  915. /** Mutex protect callbacks registered with ap_mpm_register_timed_callback
  916. * from being run before the original handler finishes running
  917. */
  918. apr_thread_mutex_t *invoke_mtx;
  919. /** A struct containing the components of URI */
  920. apr_uri_t parsed_uri;
  921. /** finfo.protection (st_mode) set to zero if no such file */
  922. apr_finfo_t finfo;
  923. /** remote address information from conn_rec, can be overridden if
  924. * necessary by a module.
  925. * This is the address that originated the request.
  926. */
  927. apr_sockaddr_t *useragent_addr;
  928. char *useragent_ip;
  929. /** MIME trailer environment from the request */
  930. apr_table_t *trailers_in;
  931. /** MIME trailer environment from the response */
  932. apr_table_t *trailers_out;
  933. /** Originator's DNS name, if known. NULL if DNS hasn't been checked,
  934. * "" if it has and no address was found. N.B. Only access this though
  935. * ap_get_useragent_host() */
  936. char *useragent_host;
  937. /** have we done double-reverse DNS? -1 yes/failure, 0 not yet,
  938. * 1 yes/success
  939. */
  940. int double_reverse;
  941. };
  942. /**
  943. * @defgroup ProxyReq Proxy request types
  944. *
  945. * Possible values of request_rec->proxyreq. A request could be normal,
  946. * proxied or reverse proxied. Normally proxied and reverse proxied are
  947. * grouped together as just "proxied", but sometimes it's necessary to
  948. * tell the difference between the two, such as for authentication.
  949. * @{
  950. */
  951. #define PROXYREQ_NONE 0 /**< No proxy */
  952. #define PROXYREQ_PROXY 1 /**< Standard proxy */
  953. #define PROXYREQ_REVERSE 2 /**< Reverse proxy */
  954. #define PROXYREQ_RESPONSE 3 /**< Origin response */
  955. /* @} */
  956. /**
  957. * @brief Enumeration of connection keepalive options
  958. */
  959. typedef enum {
  960. AP_CONN_UNKNOWN,
  961. AP_CONN_CLOSE,
  962. AP_CONN_KEEPALIVE
  963. } ap_conn_keepalive_e;
  964. /**
  965. * @brief Structure to store things which are per connection
  966. */
  967. struct conn_rec {
  968. /** Pool associated with this connection */
  969. apr_pool_t *pool;
  970. /** Physical vhost this conn came in on */
  971. server_rec *base_server;
  972. /** used by http_vhost.c */
  973. void *vhost_lookup_data;
  974. /* Information about the connection itself */
  975. /** local address */
  976. apr_sockaddr_t *local_addr;
  977. /** remote address; this is the end-point of the next hop, for the address
  978. * of the request creator, see useragent_addr in request_rec
  979. */
  980. apr_sockaddr_t *client_addr;
  981. /** Client's IP address; this is the end-point of the next hop, for the
  982. * IP of the request creator, see useragent_ip in request_rec
  983. */
  984. char *client_ip;
  985. /** Client's DNS name, if known. NULL if DNS hasn't been checked,
  986. * "" if it has and no address was found. N.B. Only access this though
  987. * get_remote_host() */
  988. char *remote_host;
  989. /** Only ever set if doing rfc1413 lookups. N.B. Only access this through
  990. * get_remote_logname() */
  991. char *remote_logname;
  992. /** server IP address */
  993. char *local_ip;
  994. /** used for ap_get_server_name when UseCanonicalName is set to DNS
  995. * (ignores setting of HostnameLookups) */
  996. char *local_host;
  997. /** ID of this connection; unique at any point in time */
  998. long id;
  999. /** Config vector containing pointers to connections per-server
  1000. * config structures. */
  1001. struct ap_conf_vector_t *conn_config;
  1002. /** Notes on *this* connection: send note from one module to
  1003. * another. must remain valid for all requests on this conn */
  1004. apr_table_t *notes;
  1005. /** A list of input filters to be used for this connection */
  1006. struct ap_filter_t *input_filters;
  1007. /** A list of output filters to be used for this connection */
  1008. struct ap_filter_t *output_filters;
  1009. /** handle to scoreboard information for this connection */
  1010. void *sbh;
  1011. /** The bucket allocator to use for all bucket/brigade creations */
  1012. struct apr_bucket_alloc_t *bucket_alloc;
  1013. /** The current state of this connection; may be NULL if not used by MPM */
  1014. conn_state_t *cs;
  1015. /** Is there data pending in the input filters? */
  1016. int data_in_input_filters;
  1017. /** Is there data pending in the output filters? */
  1018. int data_in_output_filters;
  1019. /** Are there any filters that clogg/buffer the input stream, breaking
  1020. * the event mpm.
  1021. */
  1022. unsigned int clogging_input_filters:1;
  1023. /** have we done double-reverse DNS? -1 yes/failure, 0 not yet,
  1024. * 1 yes/success */
  1025. signed int double_reverse:2;
  1026. /** Are we still talking? */
  1027. unsigned aborted;
  1028. /** Are we going to keep the connection alive for another request?
  1029. * @see ap_conn_keepalive_e */
  1030. ap_conn_keepalive_e keepalive;
  1031. /** How many times have we used it? */
  1032. int keepalives;
  1033. /** Optional connection log level configuration. May point to a server or
  1034. * per_dir config, i.e. must be copied before modifying */
  1035. const struct ap_logconf *log;
  1036. /** Id to identify this connection in error log. Set when the first
  1037. * error log entry for this connection is generated.
  1038. */
  1039. const char *log_id;
  1040. /** This points to the current thread being used to process this request,
  1041. * over the lifetime of a request, the value may change. Users of the connection
  1042. * record should not rely upon it staying the same between calls that involve
  1043. * the MPM.
  1044. */
  1045. #if APR_HAS_THREADS
  1046. apr_thread_t *current_thread;
  1047. #endif
  1048. /** The "real" master connection. NULL if I am the master. */
  1049. conn_rec *master;
  1050. };
  1051. /**
  1052. * Enumeration of connection states
  1053. * The two states CONN_STATE_LINGER_NORMAL and CONN_STATE_LINGER_SHORT may
  1054. * only be set by the MPM. Use CONN_STATE_LINGER outside of the MPM.
  1055. */
  1056. typedef enum {
  1057. CONN_STATE_CHECK_REQUEST_LINE_READABLE,
  1058. CONN_STATE_READ_REQUEST_LINE,
  1059. CONN_STATE_HANDLER,
  1060. CONN_STATE_WRITE_COMPLETION,
  1061. CONN_STATE_SUSPENDED,
  1062. CONN_STATE_LINGER, /* connection may be closed with lingering */
  1063. CONN_STATE_LINGER_NORMAL, /* MPM has started lingering close with normal timeout */
  1064. CONN_STATE_LINGER_SHORT, /* MPM has started lingering close with short timeout */
  1065. CONN_STATE_NUM /* Number of states (keep/kept last) */
  1066. } conn_state_e;
  1067. typedef enum {
  1068. CONN_SENSE_DEFAULT,
  1069. CONN_SENSE_WANT_READ, /* next event must be read */
  1070. CONN_SENSE_WANT_WRITE /* next event must be write */
  1071. } conn_sense_e;
  1072. /**
  1073. * @brief A structure to contain connection state information
  1074. */
  1075. struct conn_state_t {
  1076. /** Current state of the connection */
  1077. conn_state_e state;
  1078. /** Whether to read instead of write, or write instead of read */
  1079. conn_sense_e sense;
  1080. };
  1081. /* Per-vhost config... */
  1082. /**
  1083. * The address 255.255.255.255, when used as a virtualhost address,
  1084. * will become the "default" server when the ip doesn't match other vhosts.
  1085. */
  1086. #define DEFAULT_VHOST_ADDR 0xfffffffful
  1087. /**
  1088. * @struct server_addr_rec
  1089. * @brief A structure to be used for Per-vhost config
  1090. */
  1091. typedef struct server_addr_rec server_addr_rec;
  1092. struct server_addr_rec {
  1093. /** The next server in the list */
  1094. server_addr_rec *next;
  1095. /** The name given in "<VirtualHost>" */
  1096. char *virthost;
  1097. /** The bound address, for this server */
  1098. apr_sockaddr_t *host_addr;
  1099. /** The bound port, for this server */
  1100. apr_port_t host_port;
  1101. };
  1102. struct ap_logconf {
  1103. /** The per-module log levels */
  1104. signed char *module_levels;
  1105. /** The log level for this server */
  1106. int level;
  1107. };
  1108. /**
  1109. * @brief A structure to store information for each virtual server
  1110. */
  1111. struct server_rec {
  1112. /** The process this server is running in */
  1113. process_rec *process;
  1114. /** The next server in the list */
  1115. server_rec *next;
  1116. /* Log files --- note that transfer log is now in the modules... */
  1117. /** The name of the error log */
  1118. char *error_fname;
  1119. /** A file descriptor that references the error log */
  1120. apr_file_t *error_log;
  1121. /** The log level configuration */
  1122. struct ap_logconf log;
  1123. /* Module-specific configuration for server, and defaults... */
  1124. /** Config vector containing pointers to modules' per-server config
  1125. * structures. */
  1126. struct ap_conf_vector_t *module_config;
  1127. /** MIME type info, etc., before we start checking per-directory info */
  1128. struct ap_conf_vector_t *lookup_defaults;
  1129. /** The name of the server */
  1130. const char *defn_name;
  1131. /** The line of the config file that the server was defined on */
  1132. unsigned defn_line_number;
  1133. /** true if this is the virtual server */
  1134. char is_virtual;
  1135. /* Information for redirects */
  1136. /** for redirects, etc. */
  1137. apr_port_t port;
  1138. /** The server request scheme for redirect responses */
  1139. const char *server_scheme;
  1140. /* Contact information */
  1141. /** The admin's contact information */
  1142. char *server_admin;
  1143. /** The server hostname */
  1144. char *server_hostname;
  1145. /* Transaction handling */
  1146. /** I haven't got a clue */
  1147. server_addr_rec *addrs;
  1148. /** Timeout, as an apr interval, before we give up */
  1149. apr_interval_time_t timeout;
  1150. /** The apr interval we will wait for another request */
  1151. apr_interval_time_t keep_alive_timeout;
  1152. /** Maximum requests per connection */
  1153. int keep_alive_max;
  1154. /** Use persistent connections? */
  1155. int keep_alive;
  1156. /** Normal names for ServerAlias servers */
  1157. apr_array_header_t *names;
  1158. /** Wildcarded names for ServerAlias servers */
  1159. apr_array_header_t *wild_names;
  1160. /** Pathname for ServerPath */
  1161. const char *path;
  1162. /** Length of path */
  1163. int pathlen;
  1164. /** limit on size of the HTTP request line */
  1165. int limit_req_line;
  1166. /** limit on size of any request header field */
  1167. int limit_req_fieldsize;
  1168. /** limit on number of request header fields */
  1169. int limit_req_fields;
  1170. /** Opaque storage location */
  1171. void *context;
  1172. /** Whether the keepalive timeout is explicit (1) or
  1173. * inherited (0) from the base server (either first
  1174. * server on the same IP:port or main server) */
  1175. unsigned int keep_alive_timeout_set:1;
  1176. };
  1177. /**
  1178. * @struct ap_sload_t
  1179. * @brief A structure to hold server load params
  1180. */
  1181. typedef struct ap_sload_t ap_sload_t;
  1182. struct ap_sload_t {
  1183. /* percentage of process/threads ready/idle (0->100)*/
  1184. int idle;
  1185. /* percentage of process/threads busy (0->100) */
  1186. int busy;
  1187. /* total bytes served */
  1188. apr_off_t bytes_served;
  1189. /* total access count */
  1190. unsigned long access_count;
  1191. };
  1192. /**
  1193. * @struct ap_loadavg_t
  1194. * @brief A structure to hold various server loadavg
  1195. */
  1196. typedef struct ap_loadavg_t ap_loadavg_t;
  1197. struct ap_loadavg_t {
  1198. /* current loadavg, ala getloadavg() */
  1199. float loadavg;
  1200. /* 5 min loadavg */
  1201. float loadavg5;
  1202. /* 15 min loadavg */
  1203. float loadavg15;
  1204. };
  1205. /**
  1206. * Get the context_document_root for a request. This is a generalization of
  1207. * the document root, which is too limited in the presence of mappers like
  1208. * mod_userdir and mod_alias. The context_document_root is the directory
  1209. * on disk that maps to the context_prefix URI prefix.
  1210. * @param r The request
  1211. * @note For resources that do not map to the file system or for very complex
  1212. * mappings, this information may still be wrong.
  1213. */
  1214. AP_DECLARE(const char *) ap_context_document_root(request_rec *r);
  1215. /**
  1216. * Get the context_prefix for a request. The context_prefix URI prefix
  1217. * maps to the context_document_root on disk.
  1218. * @param r The request
  1219. */
  1220. AP_DECLARE(const char *) ap_context_prefix(request_rec *r);
  1221. /** Set context_prefix and context_document_root for a request.
  1222. * @param r The request
  1223. * @param prefix the URI prefix, without trailing slash
  1224. * @param document_root the corresponding directory on disk, without trailing
  1225. * slash
  1226. * @note If one of prefix of document_root is NULL, the corrsponding
  1227. * property will not be changed.
  1228. */
  1229. AP_DECLARE(void) ap_set_context_info(request_rec *r, const char *prefix,
  1230. const char *document_root);
  1231. /** Set per-request document root. This is for mass virtual hosting modules
  1232. * that want to provide the correct DOCUMENT_ROOT value to scripts.
  1233. * @param r The request
  1234. * @param document_root the document root for the request.
  1235. */
  1236. AP_DECLARE(void) ap_set_document_root(request_rec *r, const char *document_root);
  1237. /**
  1238. * Examine a field value (such as a media-/content-type) string and return
  1239. * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
  1240. * @param p Pool to allocate memory from
  1241. * @param intype The field to examine
  1242. * @return A copy of the field minus any parameters
  1243. */
  1244. AP_DECLARE(char *) ap_field_noparam(apr_pool_t *p, const char *intype);
  1245. /**
  1246. * Convert a time from an integer into a string in a specified format
  1247. * @param p The pool to allocate memory from
  1248. * @param t The time to convert
  1249. * @param fmt The format to use for the conversion
  1250. * @param gmt Convert the time for GMT?
  1251. * @return The string that represents the specified time
  1252. */
  1253. AP_DECLARE(char *) ap_ht_time(apr_pool_t *p, apr_time_t t, const char *fmt, int gmt);
  1254. /* String handling. The *_nc variants allow you to use non-const char **s as
  1255. arguments (unfortunately C won't automatically convert a char ** to a const
  1256. char **) */
  1257. /**
  1258. * Get the characters until the first occurrence of a specified character
  1259. * @param p The pool to allocate memory from
  1260. * @param line The string to get the characters from
  1261. * @param stop The character to stop at
  1262. * @return A copy of the characters up to the first stop character
  1263. */
  1264. AP_DECLARE(char *) ap_getword(apr_pool_t *p, const char **line, char stop);
  1265. /**
  1266. * Get the characters until the first occurrence of a specified character
  1267. * @param p The pool to allocate memory from
  1268. * @param line The string to get the characters from
  1269. * @param stop The character to stop at
  1270. * @return A copy of the characters up to the first stop character
  1271. * @note This is the same as ap_getword(), except it doesn't use const char **.
  1272. */
  1273. AP_DECLARE(char *) ap_getword_nc(apr_pool_t *p, char **line, char stop);
  1274. /**
  1275. * Get the first word from a given string. A word is defined as all characters
  1276. * up to the first whitespace.
  1277. * @param p The pool to allocate memory from
  1278. * @param line The string to traverse
  1279. * @return The first word in the line
  1280. */
  1281. AP_DECLARE(char *) ap_getword_white(apr_pool_t *p, const char **line);
  1282. /**
  1283. * Get the first word from a given string. A word is defined as all characters
  1284. * up to the first whitespace.
  1285. * @param p The pool to allocate memory from
  1286. * @param line The string to traverse
  1287. * @return The first word in the line
  1288. * @note The same as ap_getword_white(), except it doesn't use const char**
  1289. */
  1290. AP_DECLARE(char *) ap_getword_white_nc(apr_pool_t *p, char **line);
  1291. /**
  1292. * Get all characters from the first occurrence of @a stop to the first "\0"
  1293. * @param p The pool to allocate memory from
  1294. * @param line The line to traverse
  1295. * @param stop The character to start at
  1296. * @return A copy of all characters after the first occurrence of the specified
  1297. * character
  1298. */
  1299. AP_DECLARE(char *) ap_getword_nulls(apr_pool_t *p, const char **line,
  1300. char stop);
  1301. /**
  1302. * Get all characters from the first occurrence of @a stop to the first "\0"
  1303. * @param p The pool to allocate memory from
  1304. * @param line The line to traverse
  1305. * @param stop The character to start at
  1306. * @return A copy of all characters after the first occurrence of the specified
  1307. * character
  1308. * @note The same as ap_getword_nulls(), except it doesn't use const char **.
  1309. */
  1310. AP_DECLARE(char *) ap_getword_nulls_nc(apr_pool_t *p, char **line, char stop);
  1311. /**
  1312. * Get the second word in the string paying attention to quoting
  1313. * @param p The pool to allocate from
  1314. * @param line The line to traverse
  1315. * @return A copy of the string
  1316. */
  1317. AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line);
  1318. /**
  1319. * Get the second word in the string paying attention to quoting
  1320. * @param p The pool to allocate from
  1321. * @param line The line to traverse
  1322. * @return A copy of the string
  1323. * @note The same as ap_getword_conf(), except it doesn't use const char **.
  1324. */
  1325. AP_DECLARE(char *) ap_getword_conf_nc(apr_pool_t *p, char **line);
  1326. /**
  1327. * Get the second word in the string paying attention to quoting,
  1328. * with {...} supported as well as "..." and '...'
  1329. * @param p The pool to allocate from
  1330. * @param line The line to traverse
  1331. * @return A copy of the string
  1332. */
  1333. AP_DECLARE(char *) ap_getword_conf2(apr_pool_t *p, const char **line);
  1334. /**
  1335. * Get the second word in the string paying attention to quoting,
  1336. * with {...} supported as well as "..." and '...'
  1337. * @param p The pool to allocate from
  1338. * @param line The line to traverse
  1339. * @return A copy of the string
  1340. * @note The same as ap_getword_conf2(), except it doesn't use const char **.
  1341. */
  1342. AP_DECLARE(char *) ap_getword_conf2_nc(apr_pool_t *p, char **line);
  1343. /**
  1344. * Check a string for any config define or environment variable construct
  1345. * and replace each of them by the value of that variable, if it exists.
  1346. * The default syntax of the constructs is ${ENV} but can be changed by
  1347. * setting the define::* config defines. If the variable does not exist,
  1348. * leave the ${ENV} construct alone but print a warning.
  1349. * @param p The pool to allocate from
  1350. * @param word The string to check
  1351. * @return The string with the replaced environment variables
  1352. */
  1353. AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word);
  1354. /**
  1355. * Size an HTTP header field list item, as separated by a comma.
  1356. * @param field The field to size
  1357. * @param len The length of the field
  1358. * @return The return value is a pointer to the beginning of the non-empty
  1359. * list item within the original string (or NULL if there is none) and the
  1360. * address of field is shifted to the next non-comma, non-whitespace
  1361. * character. len is the length of the item excluding any beginning whitespace.
  1362. */
  1363. AP_DECLARE(const char *) ap_size_list_item(const char **field, int *len);
  1364. /**
  1365. * Retrieve an HTTP header field list item, as separated by a comma,
  1366. * while stripping insignificant whitespace and lowercasing anything not in
  1367. * a quoted string or comment.
  1368. * @param p The pool to allocate from
  1369. * @param field The field to retrieve
  1370. * @return The return value is a new string containing the converted list
  1371. * item (or NULL if none) and the address pointed to by field is
  1372. * shifted to the next non-comma, non-whitespace.
  1373. */
  1374. AP_DECLARE(char *) ap_get_list_item(apr_pool_t *p, const char **field);
  1375. /**
  1376. * Find an item in canonical form (lowercase, no extra spaces) within
  1377. * an HTTP field value list.
  1378. * @param p The pool to allocate from
  1379. * @param line The field value list to search
  1380. * @param tok The token to search for
  1381. * @return 1 if found, 0 if not found.
  1382. */
  1383. AP_DECLARE(int) ap_find_list_item(apr_pool_t *p, const char *line, const char *tok);
  1384. /**
  1385. * Do a weak ETag comparison within an HTTP field value list.
  1386. * @param p The pool to allocate from
  1387. * @param line The field value list to search
  1388. * @param tok The token to search for
  1389. * @return 1 if found, 0 if not found.
  1390. */
  1391. AP_DECLARE(int) ap_find_etag_weak(apr_pool_t *p, const char *line, const char *tok);
  1392. /**
  1393. * Do a strong ETag comparison within an HTTP field value list.
  1394. * @param p The pool to allocate from
  1395. * @param line The field value list to search
  1396. * @param tok The token to search for
  1397. * @return 1 if found, 0 if not found.
  1398. */
  1399. AP_DECLARE(int) ap_find_etag_strong(apr_pool_t *p, const char *line, const char *tok);
  1400. /* Scan a string for field content chars, as defined by RFC7230 section 3.2
  1401. * including VCHAR/obs-text, as well as HT and SP
  1402. * @param ptr The string to scan
  1403. * @return A pointer to the first (non-HT) ASCII ctrl character.
  1404. * @note lws and trailing whitespace are scanned, the caller is responsible
  1405. * for trimming leading and trailing whitespace
  1406. */
  1407. AP_DECLARE(const char *) ap_scan_http_field_content(const char *ptr);
  1408. /* Scan a string for token characters, as defined by RFC7230 section 3.2.6
  1409. * @param ptr The string to scan
  1410. * @return A pointer to the first non-token character.
  1411. */
  1412. AP_DECLARE(const char *) ap_scan_http_token(const char *ptr);
  1413. /* Scan a string for visible ASCII (0x21-0x7E) or obstext (0x80+)
  1414. * and return a pointer to the first SP/CTL/NUL character encountered.
  1415. * @param ptr The string to scan
  1416. * @return A pointer to the first SP/CTL character.
  1417. */
  1418. AP_DECLARE(const char *) ap_scan_vchar_obstext(const char *ptr);
  1419. /**
  1420. * Retrieve an array of tokens in the format "1#token" defined in RFC2616. Only
  1421. * accepts ',' as a delimiter, does not accept quoted strings, and errors on
  1422. * any separator.
  1423. * @param p The pool to allocate from
  1424. * @param tok The line to read tokens from
  1425. * @param tokens Pointer to an array of tokens. If not NULL, must be an array
  1426. * of char*, otherwise it will be allocated on @a p when a token is found
  1427. * @param skip_invalid If true, when an invalid separator is encountered, it
  1428. * will be ignored.
  1429. * @return NULL on success, an error string otherwise.
  1430. * @remark *tokens may be NULL on output if NULL in input and no token is found
  1431. */
  1432. AP_DECLARE(const char *) ap_parse_token_list_strict(apr_pool_t *p, const char *tok,
  1433. apr_array_header_t **tokens,
  1434. int skip_invalid);
  1435. /**
  1436. * Retrieve a token, spacing over it and adjusting the pointer to
  1437. * the first non-white byte afterwards. Note that these tokens
  1438. * are delimited by semis and commas and can also be delimited
  1439. * by whitespace at the caller's option.
  1440. * @param p The pool to allocate from
  1441. * @param accept_line The line to retrieve the token from (adjusted afterwards)
  1442. * @param accept_white Is it delimited by whitespace
  1443. * @return the token
  1444. */
  1445. AP_DECLARE(char *) ap_get_token(apr_pool_t *p, const char **accept_line, int accept_white);
  1446. /**
  1447. * Find http tokens, see the definition of token from RFC2068
  1448. * @param p The pool to allocate from
  1449. * @param line The line to find the token
  1450. * @param tok The token to find
  1451. * @return 1 if the token is found, 0 otherwise
  1452. */
  1453. AP_DECLARE(int) ap_find_token(apr_pool_t *p, const char *line, const char *tok);
  1454. /**
  1455. * find http tokens from the end of the line
  1456. * @param p The pool to allocate from
  1457. * @param line The line to find the token
  1458. * @param tok The token to find
  1459. * @return 1 if the token is found, 0 otherwise
  1460. */
  1461. AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line, const char *tok);
  1462. /**
  1463. * Check for an Absolute URI syntax
  1464. * @param u The string to check
  1465. * @return 1 if URI, 0 otherwise
  1466. */
  1467. AP_DECLARE(int) ap_is_url(const char *u);
  1468. /**
  1469. * Unescape a string
  1470. * @param url The string to unescape
  1471. * @return 0 on success, non-zero otherwise
  1472. */
  1473. AP_DECLARE(int) ap_unescape_all(char *url);
  1474. /**
  1475. * Unescape a URL
  1476. * @param url The url to unescape
  1477. * @return 0 on success, non-zero otherwise
  1478. */
  1479. AP_DECLARE(int) ap_unescape_url(char *url);
  1480. /**
  1481. * Unescape a URL, but leaving %2f (slashes) escaped
  1482. * @param url The url to unescape
  1483. * @param decode_slashes Whether or not slashes should be decoded
  1484. * @return 0 on success, non-zero otherwise
  1485. */
  1486. AP_DECLARE(int) ap_unescape_url_keep2f(char *url, int decode_slashes);
  1487. /**
  1488. * Unescape an application/x-www-form-urlencoded string
  1489. * @param query The query to unescape
  1490. * @return 0 on success, non-zero otherwise
  1491. */
  1492. AP_DECLARE(int) ap_unescape_urlencoded(char *query);
  1493. /**
  1494. * Convert all double slashes to single slashes, except where significant
  1495. * to the filesystem on the current platform.
  1496. * @param name The string to convert, assumed to be a filesystem path
  1497. */
  1498. AP_DECLARE(void) ap_no2slash(char *name);
  1499. /**
  1500. * Convert all double slashes to single slashes, except where significant
  1501. * to the filesystem on the current platform.
  1502. * @param name The string to convert
  1503. * @param is_fs_path if set to 0, the significance of any double-slashes is
  1504. * ignored.
  1505. */
  1506. AP_DECLARE(void) ap_no2slash_ex(char *name, int is_fs_path);
  1507. /**
  1508. * Remove all ./ and xx/../ substrings from a file name. Also remove
  1509. * any leading ../ or /../ substrings.
  1510. * @param name the file name to parse
  1511. */
  1512. AP_DECLARE(void) ap_getparents(char *name);
  1513. /**
  1514. * Escape a path segment, as defined in RFC 1808
  1515. * @param p The pool to allocate from
  1516. * @param s The path to convert
  1517. * @return The converted URL
  1518. */
  1519. AP_DECLARE(char *) ap_escape_path_segment(apr_pool_t *p, const char *s);
  1520. /**
  1521. * Escape a path segment, as defined in RFC 1808, to a preallocated buffer.
  1522. * @param c The preallocated buffer to write to
  1523. * @param s The path to convert
  1524. * @return The converted URL (c)
  1525. */
  1526. AP_DECLARE(char *) ap_escape_path_segment_buffer(char *c, const char *s);
  1527. /**
  1528. * convert an OS path to a URL in an OS dependent way.
  1529. * @param p The pool to allocate from
  1530. * @param path The path to convert
  1531. * @param partial if set, assume that the path will be appended to something
  1532. * with a '/' in it (and thus does not prefix "./")
  1533. * @return The converted URL
  1534. */
  1535. AP_DECLARE(char *) ap_os_escape_path(apr_pool_t *p, const char *path, int partial);
  1536. /** @see ap_os_escape_path */
  1537. #define ap_escape_uri(ppool,path) ap_os_escape_path(ppool,path,1)
  1538. /**
  1539. * Escape a string as application/x-www-form-urlencoded
  1540. * @param p The pool to allocate from
  1541. * @param s The path to convert
  1542. * @return The converted URL
  1543. */
  1544. AP_DECLARE(char *) ap_escape_urlencoded(apr_pool_t *p, const char *s);
  1545. /**
  1546. * Escape a string as application/x-www-form-urlencoded, to a preallocated buffer
  1547. * @param c The preallocated buffer to write to
  1548. * @param s The path to convert
  1549. * @return The converted URL (c)
  1550. */
  1551. AP_DECLARE(char *) ap_escape_urlencoded_buffer(char *c, const char *s);
  1552. /**
  1553. * Escape an html string
  1554. * @param p The pool to allocate from
  1555. * @param s The html to escape
  1556. * @return The escaped string
  1557. */
  1558. #define ap_escape_html(p,s) ap_escape_html2(p,s,0)
  1559. /**
  1560. * Escape an html string
  1561. * @param p The pool to allocate from
  1562. * @param s The html to escape
  1563. * @param toasc Whether to escape all non-ASCII chars to \&\#nnn;
  1564. * @return The escaped string
  1565. */
  1566. AP_DECLARE(char *) ap_escape_html2(apr_pool_t *p, const char *s, int toasc);
  1567. /**
  1568. * Escape a string for logging
  1569. * @param p The pool to allocate from
  1570. * @param str The string to escape
  1571. * @return The escaped string
  1572. */
  1573. AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str);
  1574. /**
  1575. * Escape a string for logging into the error log (without a pool)
  1576. * @param dest The buffer to write to
  1577. * @param source The string to escape
  1578. * @param buflen The buffer size for the escaped string (including "\0")
  1579. * @return The len of the escaped string (always < maxlen)
  1580. */
  1581. AP_DECLARE(apr_size_t) ap_escape_errorlog_item(char *dest, const char *source,
  1582. apr_size_t buflen);
  1583. /**
  1584. * Construct a full hostname
  1585. * @param p The pool to allocate from
  1586. * @param hostname The hostname of the server
  1587. * @param port The port the server is running on
  1588. * @param r The current request
  1589. * @return The server's hostname
  1590. */
  1591. AP_DECLARE(char *) ap_construct_server(apr_pool_t *p, const char *hostname,
  1592. apr_port_t port, const request_rec *r);
  1593. /**
  1594. * Escape a shell command
  1595. * @param p The pool to allocate from
  1596. * @param s The command to escape
  1597. * @return The escaped shell command
  1598. */
  1599. AP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *s);
  1600. /**
  1601. * Count the number of directories in a path
  1602. * @param path The path to count
  1603. * @return The number of directories
  1604. */
  1605. AP_DECLARE(int) ap_count_dirs(const char *path);
  1606. /**
  1607. * Copy at most @a n leading directories of @a s into @a d. @a d
  1608. * should be at least as large as @a s plus 1 extra byte
  1609. *
  1610. * @param d The location to copy to
  1611. * @param s The location to copy from
  1612. * @param n The number of directories to copy
  1613. * @return value is the ever useful pointer to the trailing "\0" of d
  1614. * @note on platforms with drive letters, n = 0 returns the "/" root,
  1615. * whereas n = 1 returns the "d:/" root. On all other platforms, n = 0
  1616. * returns the empty string. */
  1617. AP_DECLARE(char *) ap_make_dirstr_prefix(char *d, const char *s, int n);
  1618. /**
  1619. * Return the parent directory name (including trailing /) of the file
  1620. * @a s
  1621. * @param p The pool to allocate from
  1622. * @param s The file to get the parent of
  1623. * @return A copy of the file's parent directory
  1624. */
  1625. AP_DECLARE(char *) ap_make_dirstr_parent(apr_pool_t *p, const char *s);
  1626. /**
  1627. * Given a directory and filename, create a single path from them. This
  1628. * function is smart enough to ensure that there is a single '/' between the
  1629. * directory and file names
  1630. * @param a The pool to allocate from
  1631. * @param dir The directory name
  1632. * @param f The filename
  1633. * @return A copy of the full path
  1634. * @note Never consider using this function if you are dealing with filesystem
  1635. * names that need to remain canonical, unless you are merging an apr_dir_read
  1636. * path and returned filename. Otherwise, the result is not canonical.
  1637. */
  1638. AP_DECLARE(char *) ap_make_full_path(apr_pool_t *a, const char *dir, const char *f);
  1639. /**
  1640. * Test if the given path has an absolute path.
  1641. * @param p The pool to allocate from
  1642. * @param dir The directory name
  1643. * @note The converse is not necessarily true, some OS's (Win32/OS2/Netware) have
  1644. * multiple forms of absolute paths. This only reports if the path is absolute
  1645. * in a canonical sense.
  1646. */
  1647. AP_DECLARE(int) ap_os_is_path_absolute(apr_pool_t *p, const char *dir);
  1648. /**
  1649. * Does the provided string contain wildcard characters? This is useful
  1650. * for determining if the string should be passed to strcmp_match or to strcmp.
  1651. * The only wildcard characters recognized are '?' and '*'
  1652. * @param str The string to check
  1653. * @return 1 if the string has wildcards, 0 otherwise
  1654. */
  1655. AP_DECLARE(int) ap_is_matchexp(const char *str);
  1656. /**
  1657. * Determine if a string matches a pattern containing the wildcards '?' or '*'
  1658. * @param str The string to check
  1659. * @param expected The pattern to match against
  1660. * @return 0 if the two strings match, 1 otherwise
  1661. */
  1662. AP_DECLARE(int) ap_strcmp_match(const char *str, const char *expected);
  1663. /**
  1664. * Determine if a string matches a pattern containing the wildcards '?' or '*',
  1665. * ignoring case
  1666. * @param str The string to check
  1667. * @param expected The pattern to match against
  1668. * @return 0 if the two strings match, 1 otherwise
  1669. */
  1670. AP_DECLARE(int) ap_strcasecmp_match(const char *str, const char *expected);
  1671. /**
  1672. * Find the first occurrence of the substring s2 in s1, regardless of case
  1673. * @param s1 The string to search
  1674. * @param s2 The substring to search for
  1675. * @return A pointer to the beginning of the substring
  1676. * @remark See apr_strmatch() for a faster alternative
  1677. */
  1678. AP_DECLARE(char *) ap_strcasestr(const char *s1, const char *s2);
  1679. /**
  1680. * Return a pointer to the location inside of bigstring immediately after prefix
  1681. * @param bigstring The input string
  1682. * @param prefix The prefix to strip away
  1683. * @return A pointer relative to bigstring after prefix
  1684. */
  1685. AP_DECLARE(const char *) ap_stripprefix(const char *bigstring,
  1686. const char *prefix);
  1687. /**
  1688. * Decode a base64 encoded string into memory allocated from a pool
  1689. * @param p The pool to allocate from
  1690. * @param bufcoded The encoded string
  1691. * @return The decoded string
  1692. */
  1693. AP_DECLARE(char *) ap_pbase64decode(apr_pool_t *p, const char *bufcoded);
  1694. /**
  1695. * Encode a string into memory allocated from a pool in base 64 format
  1696. * @param p The pool to allocate from
  1697. * @param string The plaintext string
  1698. * @return The encoded string
  1699. */
  1700. AP_DECLARE(char *) ap_pbase64encode(apr_pool_t *p, char *string);
  1701. /**
  1702. * Compile a regular expression to be used later. The regex is freed when
  1703. * the pool is destroyed.
  1704. * @param p The pool to allocate from
  1705. * @param pattern the regular expression to compile
  1706. * @param cflags The bitwise or of one or more of the following:
  1707. * @li REG_EXTENDED - Use POSIX extended Regular Expressions
  1708. * @li REG_ICASE - Ignore case
  1709. * @li REG_NOSUB - Support for substring addressing of matches
  1710. * not required
  1711. * @li REG_NEWLINE - Match-any-character operators don't match new-line
  1712. * @return The compiled regular expression
  1713. */
  1714. AP_DECLARE(ap_regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern,
  1715. int cflags);
  1716. /**
  1717. * Free the memory associated with a compiled regular expression
  1718. * @param p The pool the regex was allocated from
  1719. * @param reg The regular expression to free
  1720. * @note This function is only necessary if the regex should be cleaned
  1721. * up before the pool
  1722. */
  1723. AP_DECLARE(void) ap_pregfree(apr_pool_t *p, ap_regex_t *reg);
  1724. /**
  1725. * After performing a successful regex match, you may use this function to
  1726. * perform a series of string substitutions based on subexpressions that were
  1727. * matched during the call to ap_regexec. This function is limited to
  1728. * result strings of 64K. Consider using ap_pregsub_ex() instead.
  1729. * @param p The pool to allocate from
  1730. * @param input An arbitrary string containing $1 through $9. These are
  1731. * replaced with the corresponding matched sub-expressions
  1732. * @param source The string that was originally matched to the regex
  1733. * @param nmatch the nmatch returned from ap_pregex
  1734. * @param pmatch the pmatch array returned from ap_pregex
  1735. * @return The substituted string, or NULL on error
  1736. */
  1737. AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input,
  1738. const char *source, apr_size_t nmatch,
  1739. ap_regmatch_t pmatch[]);
  1740. /**
  1741. * After performing a successful regex match, you may use this function to
  1742. * perform a series of string substitutions based on subexpressions that were
  1743. * matched during the call to ap_regexec
  1744. * @param p The pool to allocate from
  1745. * @param result where to store the result, will be set to NULL on error
  1746. * @param input An arbitrary string containing $1 through $9. These are
  1747. * replaced with the corresponding matched sub-expressions
  1748. * @param source The string that was originally matched to the regex
  1749. * @param nmatch the nmatch returned from ap_pregex
  1750. * @param pmatch the pmatch array returned from ap_pregex
  1751. * @param maxlen the maximum string length to return, 0 for unlimited
  1752. * @return APR_SUCCESS if successful, APR_ENOMEM or other error code otherwise.
  1753. */
  1754. AP_DECLARE(apr_status_t) ap_pregsub_ex(apr_pool_t *p, char **result,
  1755. const char *input, const char *source,
  1756. apr_size_t nmatch,
  1757. ap_regmatch_t pmatch[],
  1758. apr_size_t maxlen);
  1759. /**
  1760. * We want to downcase the type/subtype for comparison purposes
  1761. * but nothing else because ;parameter=foo values are case sensitive.
  1762. * @param s The content-type to convert to lowercase
  1763. */
  1764. AP_DECLARE(void) ap_content_type_tolower(char *s);
  1765. /**
  1766. * convert a string to all lowercase
  1767. * @param s The string to convert to lowercase
  1768. */
  1769. AP_DECLARE(void) ap_str_tolower(char *s);
  1770. /**
  1771. * convert a string to all uppercase
  1772. * @param s The string to convert to uppercase
  1773. */
  1774. AP_DECLARE(void) ap_str_toupper(char *s);
  1775. /**
  1776. * Search a string from left to right for the first occurrence of a
  1777. * specific character
  1778. * @param str The string to search
  1779. * @param c The character to search for
  1780. * @return The index of the first occurrence of c in str
  1781. */
  1782. AP_DECLARE(int) ap_ind(const char *str, char c); /* Sigh... */
  1783. /**
  1784. * Search a string from right to left for the first occurrence of a
  1785. * specific character
  1786. * @param str The string to search
  1787. * @param c The character to search for
  1788. * @return The index of the first occurrence of c in str
  1789. */
  1790. AP_DECLARE(int) ap_rind(const char *str, char c);
  1791. /**
  1792. * Given a string, replace any bare &quot; with \\&quot; .
  1793. * @param p The pool to allocate memory from
  1794. * @param instring The string to search for &quot;
  1795. * @return A copy of the string with escaped quotes
  1796. */
  1797. AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring);
  1798. /**
  1799. * Given a string, append the PID deliminated by delim.
  1800. * Usually used to create a pid-appended filepath name
  1801. * (eg: /a/b/foo -> /a/b/foo.6726). A function, and not
  1802. * a macro, to avoid unistd.h dependency
  1803. * @param p The pool to allocate memory from
  1804. * @param string The string to append the PID to
  1805. * @param delim The string to use to deliminate the string from the PID
  1806. * @return A copy of the string with the PID appended
  1807. */
  1808. AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string,
  1809. const char *delim);
  1810. /**
  1811. * Parse a given timeout parameter string into an apr_interval_time_t value.
  1812. * The unit of the time interval is given as postfix string to the numeric
  1813. * string. Currently the following units are understood:
  1814. *
  1815. * ms : milliseconds
  1816. * s : seconds
  1817. * mi[n] : minutes
  1818. * h : hours
  1819. *
  1820. * If no unit is contained in the given timeout parameter the default_time_unit
  1821. * will be used instead.
  1822. * @param timeout_parameter The string containing the timeout parameter.
  1823. * @param timeout The timeout value to be returned.
  1824. * @param default_time_unit The default time unit to use if none is specified
  1825. * in timeout_parameter.
  1826. * @return Status value indicating whether the parsing was successful or not.
  1827. */
  1828. AP_DECLARE(apr_status_t) ap_timeout_parameter_parse(
  1829. const char *timeout_parameter,
  1830. apr_interval_time_t *timeout,
  1831. const char *default_time_unit);
  1832. /**
  1833. * Determine if a request has a request body or not.
  1834. *
  1835. * @param r the request_rec of the request
  1836. * @return truth value
  1837. */
  1838. AP_DECLARE(int) ap_request_has_body(request_rec *r);
  1839. /**
  1840. * Cleanup a string (mainly to be filesystem safe)
  1841. * We only allow '_' and alphanumeric chars. Non-printable
  1842. * map to 'x' and all others map to '_'
  1843. *
  1844. * @param p pool to use to allocate dest
  1845. * @param src string to clean up
  1846. * @param dest cleaned up, allocated string
  1847. * @return Status value indicating whether the cleaning was successful or not.
  1848. */
  1849. AP_DECLARE(apr_status_t) ap_pstr2_alnum(apr_pool_t *p, const char *src,
  1850. const char **dest);
  1851. /**
  1852. * Cleanup a string (mainly to be filesystem safe)
  1853. * We only allow '_' and alphanumeric chars. Non-printable
  1854. * map to 'x' and all others map to '_'
  1855. *
  1856. * @param src string to clean up
  1857. * @param dest cleaned up, pre-allocated string
  1858. * @return Status value indicating whether the cleaning was successful or not.
  1859. */
  1860. AP_DECLARE(apr_status_t) ap_str2_alnum(const char *src, char *dest);
  1861. /**
  1862. * Structure to store the contents of an HTTP form of the type
  1863. * application/x-www-form-urlencoded.
  1864. *
  1865. * Currently it contains the name as a char* of maximum length
  1866. * HUGE_STRING_LEN, and a value in the form of a bucket brigade
  1867. * of arbitrary length.
  1868. */
  1869. typedef struct {
  1870. const char *name;
  1871. apr_bucket_brigade *value;
  1872. } ap_form_pair_t;
  1873. /**
  1874. * Read the body and parse any form found, which must be of the
  1875. * type application/x-www-form-urlencoded.
  1876. * @param r request containing POSTed form data
  1877. * @param f filter
  1878. * @param ptr returned array of ap_form_pair_t
  1879. * @param num max num of params or -1 for unlimited
  1880. * @param size max size allowed for parsed data
  1881. * @return OK or HTTP error
  1882. */
  1883. AP_DECLARE(int) ap_parse_form_data(request_rec *r, struct ap_filter_t *f,
  1884. apr_array_header_t **ptr,
  1885. apr_size_t num, apr_size_t size);
  1886. /* Misc system hackery */
  1887. /**
  1888. * Given the name of an object in the file system determine if it is a directory
  1889. * @param p The pool to allocate from
  1890. * @param name The name of the object to check
  1891. * @return 1 if it is a directory, 0 otherwise
  1892. */
  1893. AP_DECLARE(int) ap_is_rdirectory(apr_pool_t *p, const char *name);
  1894. /**
  1895. * Given the name of an object in the file system determine if it is a directory - this version is symlink aware
  1896. * @param p The pool to allocate from
  1897. * @param name The name of the object to check
  1898. * @return 1 if it is a directory, 0 otherwise
  1899. */
  1900. AP_DECLARE(int) ap_is_directory(apr_pool_t *p, const char *name);
  1901. #ifdef _OSD_POSIX
  1902. extern int os_init_job_environment(server_rec *s, const char *user_name, int one_process);
  1903. #endif /* _OSD_POSIX */
  1904. /**
  1905. * Determine the local host name for the current machine
  1906. * @param p The pool to allocate from
  1907. * @return A copy of the local host name
  1908. */
  1909. char *ap_get_local_host(apr_pool_t *p);
  1910. /**
  1911. * Log an assertion to the error log
  1912. * @param szExp The assertion that failed
  1913. * @param szFile The file the assertion is in
  1914. * @param nLine The line the assertion is defined on
  1915. */
  1916. AP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile, int nLine)
  1917. __attribute__((noreturn));
  1918. /**
  1919. * @internal Internal Assert function
  1920. */
  1921. #define ap_assert(exp) ((exp) ? (void)0 : ap_log_assert(#exp,__FILE__,__LINE__))
  1922. /**
  1923. * Redefine assert() to something more useful for an Apache...
  1924. *
  1925. * Use ap_assert() if the condition should always be checked.
  1926. * Use AP_DEBUG_ASSERT() if the condition should only be checked when AP_DEBUG
  1927. * is defined.
  1928. */
  1929. #ifdef AP_DEBUG
  1930. #define AP_DEBUG_ASSERT(exp) ap_assert(exp)
  1931. #else
  1932. #define AP_DEBUG_ASSERT(exp) ((void)0)
  1933. #endif
  1934. /**
  1935. * @defgroup stopsignal Flags which indicate places where the server should stop for debugging.
  1936. * @{
  1937. * A set of flags which indicate places where the server should raise(SIGSTOP).
  1938. * This is useful for debugging, because you can then attach to that process
  1939. * with gdb and continue. This is important in cases where one_process
  1940. * debugging isn't possible.
  1941. */
  1942. /** stop on a Detach */
  1943. #define SIGSTOP_DETACH 1
  1944. /** stop making a child process */
  1945. #define SIGSTOP_MAKE_CHILD 2
  1946. /** stop spawning a child process */
  1947. #define SIGSTOP_SPAWN_CHILD 4
  1948. /** stop spawning a child process with a piped log */
  1949. #define SIGSTOP_PIPED_LOG_SPAWN 8
  1950. /** stop spawning a CGI child process */
  1951. #define SIGSTOP_CGI_CHILD 16
  1952. /** Macro to get GDB started */
  1953. #ifdef DEBUG_SIGSTOP
  1954. extern int raise_sigstop_flags;
  1955. #define RAISE_SIGSTOP(x) do { \
  1956. if (raise_sigstop_flags & SIGSTOP_##x) raise(SIGSTOP);\
  1957. } while (0)
  1958. #else
  1959. #define RAISE_SIGSTOP(x)
  1960. #endif
  1961. /** @} */
  1962. /**
  1963. * Get HTML describing the address and (optionally) admin of the server.
  1964. * @param prefix Text which is prepended to the return value
  1965. * @param r The request_rec
  1966. * @return HTML describing the server, allocated in @a r's pool.
  1967. */
  1968. AP_DECLARE(const char *) ap_psignature(const char *prefix, request_rec *r);
  1969. /* The C library has functions that allow const to be silently dropped ...
  1970. these macros detect the drop in maintainer mode, but use the native
  1971. methods for normal builds
  1972. Note that on some platforms (e.g., AIX with gcc, Solaris with gcc), string.h needs
  1973. to be included before the macros are defined or compilation will fail.
  1974. */
  1975. #include <string.h>
  1976. AP_DECLARE(char *) ap_strchr(char *s, int c);
  1977. AP_DECLARE(const char *) ap_strchr_c(const char *s, int c);
  1978. AP_DECLARE(char *) ap_strrchr(char *s, int c);
  1979. AP_DECLARE(const char *) ap_strrchr_c(const char *s, int c);
  1980. AP_DECLARE(char *) ap_strstr(char *s, const char *c);
  1981. AP_DECLARE(const char *) ap_strstr_c(const char *s, const char *c);
  1982. #ifdef AP_DEBUG
  1983. #undef strchr
  1984. # define strchr(s, c) ap_strchr(s,c)
  1985. #undef strrchr
  1986. # define strrchr(s, c) ap_strrchr(s,c)
  1987. #undef strstr
  1988. # define strstr(s, c) ap_strstr(s,c)
  1989. #else
  1990. /** use this instead of strchr */
  1991. # define ap_strchr(s, c) strchr(s, c)
  1992. /** use this instead of strchr */
  1993. # define ap_strchr_c(s, c) strchr(s, c)
  1994. /** use this instead of strrchr */
  1995. # define ap_strrchr(s, c) strrchr(s, c)
  1996. /** use this instead of strrchr */
  1997. # define ap_strrchr_c(s, c) strrchr(s, c)
  1998. /** use this instead of strrstr*/
  1999. # define ap_strstr(s, c) strstr(s, c)
  2000. /** use this instead of strrstr*/
  2001. # define ap_strstr_c(s, c) strstr(s, c)
  2002. #endif
  2003. /**
  2004. * Generate pseudo random bytes.
  2005. * This is a convenience interface to apr_random. It is cheaper but less
  2006. * secure than apr_generate_random_bytes().
  2007. * @param buf where to store the bytes
  2008. * @param size number of bytes to generate
  2009. * @note ap_random_insecure_bytes() is thread-safe, it uses a mutex on
  2010. * threaded MPMs.
  2011. */
  2012. AP_DECLARE(void) ap_random_insecure_bytes(void *buf, apr_size_t size);
  2013. /**
  2014. * Get a pseudo random number in a range.
  2015. * @param min low end of range
  2016. * @param max high end of range
  2017. * @return a number in the range
  2018. */
  2019. AP_DECLARE(apr_uint32_t) ap_random_pick(apr_uint32_t min, apr_uint32_t max);
  2020. /**
  2021. * Abort with a error message signifying out of memory
  2022. */
  2023. AP_DECLARE(void) ap_abort_on_oom(void) __attribute__((noreturn));
  2024. /**
  2025. * Wrapper for malloc() that calls ap_abort_on_oom() if out of memory
  2026. * @param size size of the memory block
  2027. * @return pointer to the allocated memory
  2028. * @note ap_malloc may be implemented as a macro
  2029. */
  2030. AP_DECLARE(void *) ap_malloc(size_t size)
  2031. __attribute__((malloc))
  2032. AP_FN_ATTR_ALLOC_SIZE(1);
  2033. /**
  2034. * Wrapper for calloc() that calls ap_abort_on_oom() if out of memory
  2035. * @param nelem number of elements to allocate memory for
  2036. * @param size size of a single element
  2037. * @return pointer to the allocated memory
  2038. * @note ap_calloc may be implemented as a macro
  2039. */
  2040. AP_DECLARE(void *) ap_calloc(size_t nelem, size_t size)
  2041. __attribute__((malloc))
  2042. AP_FN_ATTR_ALLOC_SIZE2(1,2);
  2043. /**
  2044. * Wrapper for realloc() that calls ap_abort_on_oom() if out of memory
  2045. * @param ptr pointer to the old memory block (or NULL)
  2046. * @param size new size of the memory block
  2047. * @return pointer to the reallocated memory
  2048. * @note ap_realloc may be implemented as a macro
  2049. */
  2050. AP_DECLARE(void *) ap_realloc(void *ptr, size_t size)
  2051. AP_FN_ATTR_WARN_UNUSED_RESULT
  2052. AP_FN_ATTR_ALLOC_SIZE(2);
  2053. /**
  2054. * Get server load params
  2055. * @param ld struct to populate: -1 in fields means error
  2056. */
  2057. AP_DECLARE(void) ap_get_sload(ap_sload_t *ld);
  2058. /**
  2059. * Get server load averages (ala getloadavg)
  2060. * @param ld struct to populate: -1 in fields means error
  2061. */
  2062. AP_DECLARE(void) ap_get_loadavg(ap_loadavg_t *ld);
  2063. /**
  2064. * Convert binary data into a hex string
  2065. * @param src pointer to the data
  2066. * @param srclen length of the data
  2067. * @param dest pointer to buffer of length (2 * srclen + 1). The resulting
  2068. * string will be NUL-terminated.
  2069. */
  2070. AP_DECLARE(void) ap_bin2hex(const void *src, apr_size_t srclen, char *dest);
  2071. /**
  2072. * Short function to execute a command and return the first line of
  2073. * output minus \r \n. Useful for "obscuring" passwords via exec calls
  2074. * @param p the pool to allocate from
  2075. * @param cmd the command to execute
  2076. * @param argv the arguments to pass to the cmd
  2077. * @return ptr to characters or NULL on any error
  2078. */
  2079. AP_DECLARE(char *) ap_get_exec_line(apr_pool_t *p,
  2080. const char *cmd,
  2081. const char * const *argv);
  2082. #define AP_NORESTART APR_OS_START_USEERR + 1
  2083. /**
  2084. * Get the first index of the string in the array or -1 if not found. Start
  2085. * searching a start.
  2086. * @param array The array the check
  2087. * @param s The string to find
  2088. * @param start Start index for search. If start is out of bounds (negative or
  2089. equal to array length or greater), -1 will be returned.
  2090. * @return index of string in array or -1
  2091. */
  2092. AP_DECLARE(int) ap_array_str_index(const apr_array_header_t *array,
  2093. const char *s,
  2094. int start);
  2095. /**
  2096. * Check if the string is member of the given array by strcmp.
  2097. * @param array The array the check
  2098. * @param s The string to find
  2099. * @return !=0 iff string is member of array (via strcmp)
  2100. */
  2101. AP_DECLARE(int) ap_array_str_contains(const apr_array_header_t *array,
  2102. const char *s);
  2103. /**
  2104. * Perform a case-insensitive comparison of two strings @a str1 and @a str2,
  2105. * treating upper and lower case values of the 26 standard C/POSIX alphabetic
  2106. * characters as equivalent. Extended latin characters outside of this set
  2107. * are treated as unique octets, irrespective of the current locale.
  2108. *
  2109. * Returns in integer greater than, equal to, or less than 0,
  2110. * according to whether @a str1 is considered greater than, equal to,
  2111. * or less than @a str2.
  2112. *
  2113. * @note Same code as apr_cstr_casecmp, which arrives in APR 1.6
  2114. */
  2115. AP_DECLARE(int) ap_cstr_casecmp(const char *s1, const char *s2);
  2116. /**
  2117. * Perform a case-insensitive comparison of two strings @a str1 and @a str2,
  2118. * treating upper and lower case values of the 26 standard C/POSIX alphabetic
  2119. * characters as equivalent. Extended latin characters outside of this set
  2120. * are treated as unique octets, irrespective of the current locale.
  2121. *
  2122. * Returns in integer greater than, equal to, or less than 0,
  2123. * according to whether @a str1 is considered greater than, equal to,
  2124. * or less than @a str2.
  2125. *
  2126. * @note Same code as apr_cstr_casecmpn, which arrives in APR 1.6
  2127. */
  2128. AP_DECLARE(int) ap_cstr_casecmpn(const char *s1, const char *s2, apr_size_t n);
  2129. /**
  2130. * Default flags for ap_dir_*fnmatch().
  2131. */
  2132. #define AP_DIR_FLAG_NONE 0
  2133. /**
  2134. * If set, wildcards that match no files or directories will be ignored, otherwise
  2135. * an error is triggered.
  2136. */
  2137. #define AP_DIR_FLAG_OPTIONAL 1
  2138. /**
  2139. * If set, and the wildcard resolves to a directory, recursively find all files
  2140. * below that directory, otherwise return the directory.
  2141. */
  2142. #define AP_DIR_FLAG_RECURSIVE 2
  2143. /**
  2144. * Structure to provide the state of a directory match.
  2145. */
  2146. typedef struct ap_dir_match_t ap_dir_match_t;
  2147. /**
  2148. * Concrete structure to provide the state of a directory match.
  2149. */
  2150. struct ap_dir_match_t {
  2151. /** Pool to use for allocating the result */
  2152. apr_pool_t *p;
  2153. /** Temporary pool used for directory traversal */
  2154. apr_pool_t *ptemp;
  2155. /** Prefix for log messages */
  2156. const char *prefix;
  2157. /** Callback for each file found that matches the wildcard. Return NULL on success, an error string on error. */
  2158. const char *(*cb)(ap_dir_match_t *w, const char *fname);
  2159. /** Context for the callback */
  2160. void *ctx;
  2161. /** Flags to indicate whether optional or recursive */
  2162. int flags;
  2163. /** Recursion depth safety check */
  2164. unsigned int depth;
  2165. };
  2166. /**
  2167. * Search for files given a non wildcard filename with non native separators.
  2168. *
  2169. * If the provided filename points at a file, the callback within ap_dir_match_t is
  2170. * triggered for that file, and this function returns the result of the callback.
  2171. *
  2172. * If the provided filename points at a directory, and recursive within ap_dir_match_t
  2173. * is true, the callback will be triggered for every file found recursively beneath
  2174. * that directory, otherwise the callback is triggered once for the directory itself.
  2175. * This function returns the result of the callback.
  2176. *
  2177. * If the provided path points to neither a file nor a directory, and optional within
  2178. * ap_dir_match_t is true, this function returns NULL. If optional within ap_dir_match_t
  2179. * is false, this function will return an error string indicating that the path does not
  2180. * exist.
  2181. *
  2182. * @param w Directory match structure containing callback and context.
  2183. * @param fname The name of the file or directory, with non native separators.
  2184. * @return NULL on success, or a string describing the error.
  2185. */
  2186. AP_DECLARE(const char *)ap_dir_nofnmatch(ap_dir_match_t *w, const char *fname)
  2187. __attribute__((nonnull(1,2)));
  2188. /**
  2189. * Search for files given a wildcard filename with non native separators.
  2190. *
  2191. * If the filename contains a wildcard, all files and directories that match the wildcard
  2192. * will be returned.
  2193. *
  2194. * ap_dir_nofnmatch() is called for each directory and file found, and the callback
  2195. * within ap_dir_match_t triggered as described above.
  2196. *
  2197. * Wildcards may appear in both directory and file components in the path, and
  2198. * wildcards may appear more than once.
  2199. *
  2200. * @param w Directory match structure containing callback and context.
  2201. * @param path Path prefix for search, with non native separators and no wildcards.
  2202. * @param fname The name of the file or directory, with non native separators and
  2203. * optional wildcards.
  2204. * @return NULL on success, or a string describing the error.
  2205. */
  2206. AP_DECLARE(const char *)ap_dir_fnmatch(ap_dir_match_t *w, const char *path,
  2207. const char *fname) __attribute__((nonnull(1,3)));
  2208. #ifdef __cplusplus
  2209. }
  2210. #endif
  2211. #endif /* !APACHE_HTTPD_H */
  2212. /** @} //APACHE Daemon */
  2213. /** @} //APACHE Core */
  2214. /** @} //APACHE super group */