libmicrohttpd.texi 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385
  1. \input texinfo
  2. @setfilename libmicrohttpd.info
  3. @documentencoding UTF-8
  4. @include version.texi
  5. @settitle The GNU libmicrohttpd Reference Manual
  6. @c Unify all the indices into concept index.
  7. @syncodeindex vr cp
  8. @syncodeindex ky cp
  9. @syncodeindex pg cp
  10. @copying
  11. This manual is for GNU libmicrohttpd
  12. (version @value{VERSION}, @value{UPDATED}), a library for embedding
  13. an HTTP(S) server into C applications.
  14. Copyright @copyright{} 2007--2019 Christian Grothoff
  15. @quotation
  16. Permission is granted to copy, distribute and/or modify this document
  17. under the terms of the GNU Free Documentation License, Version 1.3
  18. or any later version published by the Free Software Foundation;
  19. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  20. Texts. A copy of the license is included in the section entitled "GNU
  21. Free Documentation License".
  22. @end quotation
  23. @end copying
  24. @dircategory Software libraries
  25. @direntry
  26. * libmicrohttpd: (libmicrohttpd). Embedded HTTP server library.
  27. @end direntry
  28. @c
  29. @c Titlepage
  30. @c
  31. @titlepage
  32. @title The GNU libmicrohttpd Reference Manual
  33. @subtitle Version @value{VERSION}
  34. @subtitle @value{UPDATED}
  35. @author Marco Maggi (@email{marco.maggi-ipsu@@poste.it})
  36. @author Christian Grothoff (@email{christian@@grothoff.org})
  37. @page
  38. @vskip 0pt plus 1filll
  39. @insertcopying
  40. @end titlepage
  41. @summarycontents
  42. @contents
  43. @c ------------------------------------------------------------
  44. @ifnottex
  45. @node Top
  46. @top The GNU libmicrohttpd Library
  47. @insertcopying
  48. @end ifnottex
  49. @menu
  50. * microhttpd-intro:: Introduction.
  51. * microhttpd-const:: Constants.
  52. * microhttpd-struct:: Structures type definition.
  53. * microhttpd-cb:: Callback functions definition.
  54. * microhttpd-init:: Starting and stopping the server.
  55. * microhttpd-inspect:: Implementing external @code{select}.
  56. * microhttpd-requests:: Handling requests.
  57. * microhttpd-responses:: Building responses to requests.
  58. * microhttpd-flow:: Flow control.
  59. * microhttpd-dauth:: Utilizing Authentication.
  60. * microhttpd-post:: Adding a @code{POST} processor.
  61. * microhttpd-info:: Obtaining and modifying status information.
  62. * microhttpd-util:: Utilities.
  63. Appendices
  64. * GNU-LGPL:: The GNU Lesser General Public License says how you
  65. can copy and share almost all of `libmicrohttpd'.
  66. * eCos License:: The eCos License says how you can copy and share some parts of `libmicrohttpd'.
  67. * GNU-GPL:: The GNU General Public License (with eCos extension) says how you can copy and share some parts of `libmicrohttpd'.
  68. * GNU-FDL:: The GNU Free Documentation License says how you
  69. can copy and share the documentation of `libmicrohttpd'.
  70. Indices
  71. * Concept Index:: Index of concepts and programs.
  72. * Function and Data Index:: Index of functions, variables and data types.
  73. * Type Index:: Index of data types.
  74. @end menu
  75. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  76. @c ------------------------------------------------------------
  77. @node microhttpd-intro
  78. @chapter Introduction
  79. @noindent
  80. All symbols defined in the public API start with @code{MHD_}. MHD
  81. is a small HTTP daemon library. As such, it does not have any API
  82. for logging errors (you can only enable or disable logging to stderr).
  83. Also, it may not support all of the HTTP features directly, where
  84. applicable, portions of HTTP may have to be handled by clients of the
  85. library.
  86. The library is supposed to handle everything that it must handle
  87. (because the API would not allow clients to do this), such as basic
  88. connection management. However, detailed interpretations of headers,
  89. such as range requests, are left to the main application. In
  90. particular, if an application developer wants to support range
  91. requests, he needs to explicitly indicate support in responses and
  92. also explicitly parse the range header and generate a response (for
  93. example, using the @code{MHD_create_response_from_fd_at_offset} call
  94. to serve ranges from a file). MHD does understands headers that
  95. control connection management (specifically, @code{Connection: close}
  96. and @code{Expect: 100 continue} are understood and handled
  97. automatically). @code{Connection: upgrade} is supported by passing
  98. control over the socket (or something that behaves like the real
  99. socket in the case of TLS) to the application (after sending the
  100. desired HTTP response header).
  101. MHD largely ignores the semantics of the different HTTP methods,
  102. so clients are left to handle those. One exception is that MHD does
  103. understand @code{HEAD} and will only send the headers of the response
  104. and not the body, even if the client supplied a body. (In fact,
  105. clients do need to construct a response with the correct length, even
  106. for @code{HEAD} request.)
  107. MHD understands @code{POST} data and is able to decode certain
  108. formats (at the moment only @code{application/x-www-form-urlencoded}
  109. and @code{multipart/form-data}) using the post processor API. The
  110. data stream of a POST is also provided directly to the main
  111. application, so unsupported encodings could still be processed, just
  112. not conveniently by MHD.
  113. The header file defines various constants used by the HTTP protocol.
  114. This does not mean that MHD actually interprets all of these values.
  115. The provided constants are exported as a convenience for users of the
  116. library. MHD does not verify that transmitted HTTP headers are
  117. part of the standard specification; users of the library are free to
  118. define their own extensions of the HTTP standard and use those with
  119. MHD.
  120. All functions are guaranteed to be completely reentrant and
  121. thread-safe. MHD checks for allocation failures and tries to
  122. recover gracefully (for example, by closing the connection).
  123. Additionally, clients can specify resource limits on the overall
  124. number of connections, number of connections per IP address and memory
  125. used per connection to avoid resource exhaustion.
  126. @section Scope
  127. MHD is currently used in a wide range of implementations.
  128. Examples based on reports we've received from developers include:
  129. @itemize
  130. @item Embedded HTTP server on a cortex M3 (128 KB code space)
  131. @item Large-scale multimedia server (reportedly serving at the
  132. simulator limit of 7.5 GB/s)
  133. @item Administrative console (via HTTP/HTTPS) for network appliances
  134. @c If you have other interesting examples, please let us know
  135. @end itemize
  136. @section Thread modes and event loops
  137. @cindex poll
  138. @cindex epoll
  139. @cindex select
  140. MHD supports four basic thread modes and up to three event loop
  141. styles.
  142. The four basic thread modes are external sockets polling (MHD creates
  143. no threads, event loop is fully managed by the application), internal
  144. polling (MHD creates one thread for all connections), polling in
  145. thread pool (MHD creates a thread pool which is used to process all
  146. connections) and thread-per-connection (MHD creates one thread for
  147. listen sockets and then one thread per accepted connection).
  148. These thread modes are then combined with the evet loop styles
  149. (polling function type). MHD support select, poll and epoll. select
  150. is available on all platforms, epoll and poll may not be available on
  151. some platforms. Note that it is possible to combine MHD using epoll
  152. with an external select-based event loop.
  153. The default (if no other option is passed) is ``external select''.
  154. The highest performance can typically be obtained with a thread pool
  155. using @code{epoll}. Apache Benchmark (ab) was used to compare the
  156. performance of @code{select} and @code{epoll} when using a thread pool
  157. and a large number of connections. @ref{fig:performance} shows the
  158. resulting plot from the @code{benchmark.c} example, which measures the
  159. latency between an incoming request and the completion of the
  160. transmission of the response. In this setting, the @code{epoll}
  161. thread pool with four threads was able to handle more than 45,000
  162. connections per second on loopback (with Apache Benchmark running
  163. three processes on the same machine).
  164. @cindex performance
  165. @float Figure,fig:performance
  166. @image{libmicrohttpd_performance_data,400pt,300pt,Data,.png}
  167. @caption{Performance measurements for select vs. epoll (with thread-pool).}
  168. @end float
  169. Not all combinations of thread modes and event loop styles are
  170. supported. This is partially to keep the API simple, and partially
  171. because some combinations simply make no sense as others are strictly
  172. superior. Note that the choice of style depends first of all on the
  173. application logic, and then on the performance requirements.
  174. Applications that perform a blocking operation while handling a
  175. request within the callbacks from MHD must use a thread per
  176. connection. This is typically rather costly. Applications that do
  177. not support threads or that must run on embedded devices without
  178. thread-support must use the external mode. Using @code{epoll} is only
  179. supported on some platform, thus portable applications must at least
  180. have a fallback option available. @ref{tbl:supported} lists the sane
  181. combinations.
  182. @float Table,tbl:supported
  183. @multitable {@b{thread-per-connection}} {@b{select}} {@b{poll}} {@b{epoll}}
  184. @item @tab @b{select} @tab @b{poll} @tab @b{epoll}
  185. @item @b{external} @tab yes @tab no @tab yes
  186. @item @b{internal} @tab yes @tab yes @tab yes
  187. @item @b{thread pool} @tab yes @tab yes @tab yes
  188. @item @b{thread-per-connection} @tab yes @tab yes @tab no
  189. @end multitable
  190. @caption{Supported combinations of event styles and thread modes.}
  191. @end float
  192. @section Compiling GNU libmicrohttpd
  193. @cindex compilation
  194. @cindex embedded systems
  195. @cindex portability
  196. MHD uses the standard GNU system where the usual build process
  197. involves running
  198. @verbatim
  199. $ ./configure
  200. $ make
  201. $ make install
  202. @end verbatim
  203. MHD supports various options to be given to configure to tailor the
  204. binary to a specific situation. Note that some of these options will
  205. remove portions of the MHD code that are required for
  206. binary-compatibility. They should only be used on embedded systems
  207. with tight resource constraints and no concerns about library
  208. versioning. Standard distributions including MHD are expected to
  209. always ship with all features enabled, otherwise unexpected
  210. incompatibilities can arise!
  211. Here is a list of MHD-specific options that can be given to configure
  212. (canonical configure options such as ``--prefix'' are also supported, for a
  213. full list of options run ``./configure --help''):
  214. @table @code
  215. @item ``--disable-curl''
  216. disable running testcases using libcurl
  217. @item ``--disable-largefile''
  218. disable support for 64-bit files
  219. @item ``--disable-messages''
  220. disable logging of error messages (smaller binary size, not so much fun for debugging)
  221. @item ``--disable-https''
  222. disable HTTPS support, even if GNUtls is found; this option must be used if eCOS license is desired as an option (in all cases the resulting binary falls under a GNU LGPL-only license)
  223. @item ``--disable-postprocessor''
  224. do not include the post processor API (results in binary incompatibility)
  225. @item ``--disable-dauth''
  226. do not include the authentication APIs (results in binary incompatibility)
  227. @item ``--disable-httpupgrade''
  228. do not build code for HTTP ``Upgrade'' (smaller binary size, binary incompatible library)
  229. @item ``--disable-epoll''
  230. do not include epoll support, even if it supported (minimally smaller binary size, good for portability testing)
  231. @item ``--enable-coverage''
  232. set flags for analysis of code-coverage with gcc/gcov (results in slow, large binaries)
  233. @item ``--with-threads=posix,w32,none,auto''
  234. sets threading library to use. With use ``none'' to not support threads. In this case, MHD will only support the ``external'' threading modes and not perform any locking of data structures! Use @code{MHD_is_feature_supported(MHD_FEATURE_THREADS)} to test if threads are available. Default is ``auto''.
  235. @item ``--with-gcrypt=PATH''
  236. specifies path to libgcrypt installation
  237. @item ``--with-gnutls=PATH''
  238. specifies path to libgnutls installation
  239. @end table
  240. To cross-compile MHD for Android, install the Android NDK and use:
  241. @verbatim
  242. ./configure --target=arm-linux-androideabi --host=arm-linux-androideabi --disable-doc --disable-examples
  243. make
  244. @end verbatim
  245. Similar build commands should work for cross-compilation to other platforms.
  246. Note that you may have to first cross-compile GnuTLS to get MHD with TLS support.
  247. @section Validity of pointers
  248. MHD will give applications access to its internal data structures
  249. via pointers via arguments and return values from its API. This
  250. creates the question as to how long those pointers are assured to
  251. stay valid.
  252. Most MHD data structures are associated with the connection of an
  253. HTTP client. Thus, pointers associated with a connection are
  254. typically valid until the connection is finished, at which point
  255. MHD will call the @code{MHD_RequestCompletedCallback} if one is
  256. registered. Applications that have such a callback registered
  257. may assume that keys and values from the
  258. @code{MHD_KeyValueIterator}, return values from
  259. @code{MHD_lookup_connection_value} and the @code{url},
  260. @code{method} and @code{version} arguments to the
  261. @code{MHD_AccessHandlerCallback} will remain valid until the
  262. respective @code{MHD_RequestCompletedCallback} is invoked.
  263. In contrast, the @code{upload_data} argument of
  264. @code{MHD_RequestCompletedCallback} as well as all pointers
  265. from the @code{MHD_PostDataIterator} are only valid for the
  266. duration of the callback.
  267. Pointers returned from @code{MHD_get_response_header} are
  268. valid as long as the response itself is valid.
  269. @section Including the microhttpd.h header
  270. @cindex portability
  271. @cindex microhttpd.h
  272. Ideally, before including "microhttpd.h" you should add the necessary
  273. includes to define the @code{uint64_t}, @code{size_t}, @code{fd_set},
  274. @code{socklen_t} and @code{struct sockaddr} data types. Which
  275. specific headers are needed may depend on your platform and your build
  276. system might include some tests to provide you with the necessary
  277. conditional operations. For possible suggestions consult
  278. @code{platform.h} and @code{configure.ac} in the MHD distribution.
  279. Once you have ensured that you manually (!) included the right headers
  280. for your platform before "microhttpd.h", you should also add a line
  281. with @code{#define MHD_PLATFORM_H} which will prevent the
  282. "microhttpd.h" header from trying (and, depending on your platform,
  283. failing) to include the right headers.
  284. If you do not define MHD_PLATFORM_H, the "microhttpd.h" header will
  285. automatically include headers needed on GNU/Linux systems (possibly
  286. causing problems when porting to other platforms).
  287. @section SIGPIPE
  288. @cindex signals
  289. MHD does not install a signal handler for SIGPIPE. On platforms where
  290. this is possible (such as GNU/Linux), it disables SIGPIPE for its I/O
  291. operations (by passing MSG_NOSIGNAL or similar). On other platforms,
  292. SIGPIPE signals may be generated from network operations by MHD and
  293. will cause the process to die unless the developer explicitly installs
  294. a signal handler for SIGPIPE.
  295. Hence portable code using MHD must install a SIGPIPE handler or
  296. explicitly block the SIGPIPE signal. MHD does not do so in order to
  297. avoid messing with other parts of the application that may need to
  298. handle SIGPIPE in a particular way. You can make your application
  299. handle SIGPIPE by calling the following function in @code{main}:
  300. @verbatim
  301. static void
  302. catcher (int sig)
  303. {
  304. }
  305. static void
  306. ignore_sigpipe ()
  307. {
  308. struct sigaction oldsig;
  309. struct sigaction sig;
  310. sig.sa_handler = &catcher;
  311. sigemptyset (&sig.sa_mask);
  312. #ifdef SA_INTERRUPT
  313. sig.sa_flags = SA_INTERRUPT; /* SunOS */
  314. #else
  315. sig.sa_flags = SA_RESTART;
  316. #endif
  317. if (0 != sigaction (SIGPIPE, &sig, &oldsig))
  318. fprintf (stderr,
  319. "Failed to install SIGPIPE handler: %s\n", strerror (errno));
  320. }
  321. @end verbatim
  322. @section MHD_UNSIGNED_LONG_LONG
  323. @cindex long long
  324. @cindex MHD_LONG_LONG
  325. @cindex IAR
  326. @cindex ARM
  327. @cindex cortex m3
  328. @cindex embedded systems
  329. Some platforms do not support @code{long long}. Hence MHD defines a
  330. macro @code{MHD_UNSIGNED LONG_LONG} which will default to
  331. @code{unsigned long long}. For standard desktop operating systems,
  332. this is all you need to know.
  333. However, if your platform does not support @code{unsigned long long},
  334. you should change "platform.h" to define @code{MHD_LONG_LONG} and
  335. @code{MHD_UNSIGNED_LONG_LONG} to an appropriate alternative type and
  336. also define @code{MHD_LONG_LONG_PRINTF} and
  337. @code{MHD_UNSIGNED_LONG_LONG_PRINTF} to the corresponding format
  338. string for printing such a data type. Note that the ``signed''
  339. versions are deprecated. Also, for historical reasons,
  340. @code{MHD_LONG_LONG_PRINTF} is without the percent sign, whereas
  341. @code{MHD_UNSIGNED_LONG_LONG_PRINTF} is with the percent sign. Newly
  342. written code should only use the unsigned versions. However, you need
  343. to define both in "platform.h" if you need to change the definition
  344. for the specific platform.
  345. @section Portability to W32
  346. libmicrohttpd in general ported well to W32. Most libmicrohttpd features
  347. are supported. W32 do not support some functions, like epoll and
  348. corresponding MHD features are not available on W32.
  349. @section Portability to z/OS
  350. To compile MHD on z/OS, extract the archive and run
  351. @verbatim
  352. iconv -f UTF-8 -t IBM-1047 contrib/ascebc > /tmp/ascebc.sh
  353. chmod +x /tmp/ascebc.sh
  354. for n in `find * -type f`
  355. do
  356. /tmp/ascebc.sh $n
  357. done
  358. @end verbatim
  359. to convert all source files to EBCDIC. Note that you must run
  360. @code{configure} from the directory where the configure script is
  361. located. Otherwise, configure will fail to find the
  362. @code{contrib/xcc} script (which is a wrapper around the z/OS c89
  363. compiler).
  364. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  365. @c ------------------------------------------------------------
  366. @node microhttpd-const
  367. @chapter Constants
  368. @deftp {Enumeration} MHD_FLAG
  369. Options for the MHD daemon.
  370. Note that MHD will run automatically in background thread(s) only if
  371. @code{MHD_USE_INTERNAL_POLLING_THREAD} is used. Otherwise caller
  372. (application) must use @code{MHD_run} or @code{MHD_run_from_select} to
  373. have MHD processed network connections and data.
  374. Starting the daemon may also fail if a particular option is not
  375. implemented or not supported on the target platform (i.e. no support
  376. for @acronym{TLS}, threads or IPv6). TLS support generally depends on
  377. options given during MHD compilation.
  378. @table @code
  379. @item MHD_NO_FLAG
  380. No options selected.
  381. @item MHD_USE_ERROR_LOG
  382. If this flag is used, the library should print error messages and
  383. warnings to stderr (or to custom error printer if it's specified by
  384. options). Note that for this run-time option to have any effect, MHD
  385. needs to be compiled with messages enabled. This is done by default
  386. except you ran configure with the @code{--disable-messages} flag set.
  387. @item MHD_USE_DEBUG
  388. @cindex debugging
  389. Currently the same as @code{MHD_USE_ERROR_LOG}.
  390. @item MHD_USE_TLS
  391. @cindex TLS
  392. @cindex SSL
  393. Run in HTTPS-mode. If you specify @code{MHD_USE_TLS} and MHD was
  394. compiled without SSL support, @code{MHD_start_daemon} will return
  395. NULL.
  396. @item MHD_USE_THREAD_PER_CONNECTION
  397. Run using one thread per connection.
  398. @item MHD_USE_INTERNAL_POLLING_THREAD
  399. Run using an internal thread doing @code{SELECT}.
  400. @item MHD_USE_IPv6
  401. @cindex IPv6
  402. Run using the IPv6 protocol (otherwise, MHD will just support IPv4).
  403. If you specify @code{MHD_USE_IPV6} and the local platform does not
  404. support it, @code{MHD_start_daemon} will return NULL.
  405. If you want MHD to support IPv4 and IPv6 using a single socket, pass
  406. MHD_USE_DUAL_STACK, otherwise, if you only pass this option, MHD will
  407. try to bind to IPv6-only (resulting in no IPv4 support).
  408. @item MHD_USE_DUAL_STACK
  409. @cindex IPv6
  410. Use a single socket for IPv4 and IPv6. Note that this will mean
  411. that IPv4 addresses are returned by MHD in the IPv6-mapped format
  412. (the 'struct sockaddr_in6' format will be used for IPv4 and IPv6).
  413. @item MHD_USE_PEDANTIC_CHECKS
  414. @cindex deprecated
  415. Deprecated (use @code{MHD_OPTION_STRICT_FOR_CLIENT}).
  416. Be pedantic about the protocol.
  417. Specifically, at the moment, this flag causes MHD to reject HTTP
  418. 1.1 connections without a @code{Host} header. This is required by the
  419. standard, but of course in violation of the ``be as liberal as possible
  420. in what you accept'' norm. It is recommended to turn this @strong{ON}
  421. if you are testing clients against MHD, and @strong{OFF} in
  422. production.
  423. @item MHD_USE_POLL
  424. @cindex FD_SETSIZE
  425. @cindex poll
  426. @cindex select
  427. Use @code{poll()} instead of @code{select()}. This allows sockets with
  428. descriptors @code{>= FD_SETSIZE}. This option currently only works in
  429. conjunction with @code{MHD_USE_INTERNAL_POLLING_THREAD} (at this point).
  430. If you specify @code{MHD_USE_POLL} and the local platform does not
  431. support it, @code{MHD_start_daemon} will return NULL.
  432. @item MHD_USE_EPOLL
  433. @cindex FD_SETSIZE
  434. @cindex epoll
  435. @cindex select
  436. Use @code{epoll()} instead of @code{poll()} or @code{select()}. This
  437. allows sockets with descriptors @code{>= FD_SETSIZE}. This option is
  438. only available on some systems and does not work in conjunction with
  439. @code{MHD_USE_THREAD_PER_CONNECTION} (at this point). If you specify
  440. @code{MHD_USE_EPOLL} and the local platform does not support it,
  441. @code{MHD_start_daemon} will return NULL. Using @code{epoll()}
  442. instead of @code{select()} or @code{poll()} can in some situations
  443. result in significantly higher performance as the system call has
  444. fundamentally lower complexity (O(1) for @code{epoll()} vs. O(n) for
  445. @code{select()}/@code{poll()} where n is the number of open
  446. connections).
  447. @item MHD_USE_TURBO
  448. @cindex performance
  449. Enable optimizations to aggressively improve performance.
  450. Currently, the optimizations this option enables are based on
  451. opportunistic reads and writes. Basically, MHD will simply try to
  452. read or write or accept on a socket before checking that the socket is
  453. ready for IO using the event loop mechanism. As the sockets are
  454. non-blocking, this may fail (at a loss of performance), but generally
  455. MHD does this in situations where the operation is likely to succeed,
  456. in which case performance is improved. Setting the flag should generally
  457. be safe (even though the code is slightly more experimental). You may
  458. want to benchmark your application to see if this makes any difference
  459. for you.
  460. @item MHD_USE_SUPPRESS_DATE_NO_CLOCK
  461. @cindex date
  462. @cindex clock
  463. @cindex embedded systems
  464. Suppress (automatically) adding the 'Date:' header to HTTP responses.
  465. This option should ONLY be used on systems that do not have a clock
  466. and that DO provide other mechanisms for cache control. See also
  467. RFC 2616, section 14.18 (exception 3).
  468. @item MHD_USE_NO_LISTEN_SOCKET
  469. @cindex listen
  470. @cindex proxy
  471. @cindex embedded systems
  472. Run the HTTP server without any listen socket. This option only makes
  473. sense if @code{MHD_add_connection} is going to be used exclusively to
  474. connect HTTP clients to the HTTP server. This option is incompatible
  475. with using a thread pool; if it is used,
  476. @code{MHD_OPTION_THREAD_POOL_SIZE} is ignored.
  477. @item MHD_USE_ITC
  478. @cindex quiesce
  479. Force MHD to use a signal inter-thread communication channel to notify
  480. the event loop (of threads) of our shutdown and other events. This is
  481. required if an application uses @code{MHD_USE_INTERNAL_POLLING_THREAD}
  482. and then performs @code{MHD_quiesce_daemon} (which eliminates our
  483. ability to signal termination via the listen socket). In these modes,
  484. @code{MHD_quiesce_daemon} will fail if this option was not set. Also,
  485. use of this option is automatic (as in, you do not even have to
  486. specify it), if @code{MHD_USE_NO_LISTEN_SOCKET} is specified. In
  487. "external" select mode, this option is always simply ignored.
  488. Using this option also guarantees that MHD will not call
  489. @code{shutdown()} on the listen socket, which means a parent
  490. process can continue to use the socket.
  491. @item MHD_ALLOW_SUSPEND_RESUME
  492. Enables using @code{MHD_suspend_connection} and
  493. @code{MHD_resume_connection}, as performing these calls requires some
  494. additional inter-thred communication channels to be created, and code
  495. not using these calls should not pay the cost.
  496. @item MHD_USE_TCP_FASTOPEN
  497. @cindex listen
  498. Enable TCP_FASTOPEN on the listen socket. TCP_FASTOPEN is currently
  499. supported on Linux >= 3.6. On other systems using this option with
  500. cause @code{MHD_start_daemon} to fail.
  501. @item MHD_ALLOW_UPGRADE
  502. @cindex upgrade
  503. This option must be set if you want to upgrade connections
  504. (via ``101 Switching Protocols'' responses). This requires MHD to
  505. allocate additional resources, and hence we require this
  506. special flag so we only use the resources that are really needed.
  507. @item MHD_USE_AUTO
  508. Automatically select best event loop style (polling function)
  509. depending on requested mode by other MHD flags and functions available
  510. on platform. If application doesn't have requirements for any
  511. specific polling function, it's recommended to use this flag. This
  512. flag is very convenient for multiplatform applications.
  513. @item MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT
  514. Tell the TLS library to support post handshake client authentication.
  515. Only useful in combination with @code{MHD_USE_TLS}.
  516. This option will only work if the underlying TLS library
  517. supports it (i.e. GnuTLS after 3.6.3). If the TLS library
  518. does not support it, MHD may ignore the option and proceed
  519. without supporting this features.
  520. @item MHD_USE_INSECURE_TLS_EARLY_DATA
  521. Tell the TLS library to support TLS v1.3 early data (0-RTT) with the
  522. resulting security drawbacks. Only enable this if you really know what
  523. you are doing. MHD currently does NOT enforce that this only affects
  524. GET requests! You have been warned.
  525. This option will only work if the underlying TLS library
  526. supports it (i.e. GnuTLS after 3.6.3). If the TLS library
  527. does not support it, MHD may ignore the option and proceed
  528. without supporting this features.
  529. @end table
  530. @end deftp
  531. @deftp {Enumeration} MHD_OPTION
  532. MHD options. Passed in the varargs portion of
  533. @code{MHD_start_daemon()}.
  534. @table @code
  535. @item MHD_OPTION_END
  536. No more options / last option. This is used to terminate the VARARGs
  537. list.
  538. @item MHD_OPTION_CONNECTION_MEMORY_LIMIT
  539. @cindex memory, limiting memory utilization
  540. Maximum memory size per connection (followed by a @code{size_t}). The
  541. default is 32 kB (32*1024 bytes) as defined by the internal constant
  542. @code{MHD_POOL_SIZE_DEFAULT}. Values above 128k are unlikely to
  543. result in much benefit, as half of the memory will be typically used
  544. for IO, and TCP buffers are unlikely to support window sizes above 64k
  545. on most systems.
  546. @item MHD_OPTION_CONNECTION_MEMORY_INCREMENT
  547. @cindex memory
  548. Increment to use for growing the read buffer (followed by a
  549. @code{size_t}). The default is 1024 (bytes). Increasing this value
  550. will make MHD use memory for reading more aggressively, which can
  551. reduce the number of @code{recvfrom} calls but may increase the number
  552. of @code{sendto} calls. The given value must fit within
  553. MHD_OPTION_CONNECTION_MEMORY_LIMIT.
  554. @item MHD_OPTION_CONNECTION_LIMIT
  555. @cindex connection, limiting number of connections
  556. Maximum number of concurrent connections to accept (followed by an
  557. @code{unsigned int}). The default is @code{FD_SETSIZE - 4} (the
  558. maximum number of file descriptors supported by @code{select} minus
  559. four for @code{stdin}, @code{stdout}, @code{stderr} and the server
  560. socket). In other words, the default is as large as possible.
  561. If the connection limit is reached, MHD's behavior depends a bit on
  562. other options. If @code{MHD_USE_ITC} was given, MHD
  563. will stop accepting connections on the listen socket. This will cause
  564. the operating system to queue connections (up to the @code{listen()}
  565. limit) above the connection limit. Those connections will be held
  566. until MHD is done processing at least one of the active connections.
  567. If @code{MHD_USE_ITC} is not set, then MHD will continue
  568. to @code{accept()} and immediately @code{close()} these connections.
  569. Note that if you set a low connection limit, you can easily get into
  570. trouble with browsers doing request pipelining. For example, if your
  571. connection limit is ``1'', a browser may open a first connection to
  572. access your ``index.html'' file, keep it open but use a second
  573. connection to retrieve CSS files, images and the like. In fact, modern
  574. browsers are typically by default configured for up to 15 parallel
  575. connections to a single server. If this happens, MHD will refuse to
  576. even accept the second connection until the first connection is
  577. closed --- which does not happen until timeout. As a result, the
  578. browser will fail to render the page and seem to hang. If you expect
  579. your server to operate close to the connection limit, you should
  580. first consider using a lower timeout value and also possibly add
  581. a ``Connection: close'' header to your response to ensure that
  582. request pipelining is not used and connections are closed immediately
  583. after the request has completed:
  584. @example
  585. MHD_add_response_header (response,
  586. MHD_HTTP_HEADER_CONNECTION,
  587. "close");
  588. @end example
  589. @item MHD_OPTION_CONNECTION_TIMEOUT
  590. @cindex timeout
  591. After how many seconds of inactivity should a connection automatically
  592. be timed out? (followed by an @code{unsigned int}; use zero for no
  593. timeout). The default is zero (no timeout).
  594. @item MHD_OPTION_NOTIFY_COMPLETED
  595. Register a function that should be called whenever a request has been
  596. completed (this can be used for application-specific clean up).
  597. Requests that have never been presented to the application (via
  598. @code{MHD_AccessHandlerCallback()}) will not result in
  599. notifications.
  600. This option should be followed by @strong{TWO} pointers. First a
  601. pointer to a function of type @code{MHD_RequestCompletedCallback()}
  602. and second a pointer to a closure to pass to the request completed
  603. callback. The second pointer maybe @code{NULL}.
  604. @item MHD_OPTION_NOTIFY_CONNECTION
  605. Register a function that should be called when the TCP connection to a
  606. client is opened or closed. Note that
  607. @code{MHD_OPTION_NOTIFY_COMPLETED} and the @code{con_cls} argument to
  608. the @code{MHD_AccessHandlerCallback} are per HTTP request (and there
  609. can be multiple HTTP requests per TCP connection). The registered
  610. callback is called twice per TCP connection, with
  611. @code{MHD_CONNECTION_NOTIFY_STARTED} and
  612. @code{MHD_CONNECTION_NOTIFY_CLOSED} respectively. An additional
  613. argument can be used to store TCP connection specific information,
  614. which can be retrieved using @code{MHD_CONNECTION_INFO_SOCKET_CONTEXT}
  615. during the lifetime of the TCP connection. The respective location is
  616. not the same as the HTTP-request-specific @code{con_cls} from the
  617. @code{MHD_AccessHandlerCallback}.
  618. This option should be followed by @strong{TWO} pointers. First a
  619. pointer to a function of type @code{MHD_NotifyConnectionCallback()}
  620. and second a pointer to a closure to pass to the request completed
  621. callback. The second pointer maybe @code{NULL}.
  622. @item MHD_OPTION_PER_IP_CONNECTION_LIMIT
  623. Limit on the number of (concurrent) connections made to the
  624. server from the same IP address. Can be used to prevent one
  625. IP from taking over all of the allowed connections. If the
  626. same IP tries to establish more than the specified number of
  627. connections, they will be immediately rejected. The option
  628. should be followed by an @code{unsigned int}. The default is
  629. zero, which means no limit on the number of connections
  630. from the same IP address.
  631. @item MHD_OPTION_LISTEN_BACKLOG_SIZE
  632. Set the size of the @code{listen()} back log queue of the TCP socket.
  633. Takes an @code{unsigned int} as the argument. Default is the
  634. platform-specific value of @code{SOMAXCONN}.
  635. @item MHD_OPTION_STRICT_FOR_CLIENT
  636. Specify how strict we should enforce the HTTP protocol.
  637. Takes an @code{int} as the argument. Default is zero.
  638. If set to 1, MHD will be strict about the protocol. Specifically, at
  639. the moment, this flag uses MHD to reject HTTP 1.1 connections without
  640. a "Host" header. This is required by the standard, but of course in
  641. violation of the "be as liberal as possible in what you accept" norm.
  642. It is recommended to set this to 1 if you are testing clients against
  643. MHD, and 0 in production.
  644. If set to -1 MHD will be permissive about the protocol, allowing
  645. slight deviations that are technically not allowed by the
  646. RFC. Specifically, at the moment, this flag causes MHD to allow spaces
  647. in header field names. This is disallowed by the standard.
  648. It is not recommended to set it to -1 on publicly available servers as
  649. it may potentially lower level of protection.
  650. @item MHD_OPTION_SERVER_INSANITY
  651. @cindex testing
  652. Allows the application to disable certain sanity precautions in MHD. With
  653. these, the client can break the HTTP protocol, so this should never be used in
  654. production. The options are, however, useful for testing HTTP clients against
  655. "broken" server implementations. This argument must be followed by an
  656. @code{unsigned int}, corresponding to an @code{enum MHD_DisableSanityCheck}.
  657. Right now, no sanity checks can be disabled.
  658. @item MHD_OPTION_SOCK_ADDR
  659. @cindex bind, restricting bind
  660. Bind daemon to the supplied socket address. This option should be followed by a
  661. @code{struct sockaddr *}. If @code{MHD_USE_IPv6} is specified,
  662. the @code{struct sockaddr*} should point to a @code{struct sockaddr_in6},
  663. otherwise to a @code{struct sockaddr_in}. If this option is not specified,
  664. the daemon will listen to incoming connections from anywhere. If you use this
  665. option, the 'port' argument from @code{MHD_start_daemon} is ignored and the port
  666. from the given @code{struct sockaddr *} will be used instead.
  667. @item MHD_OPTION_URI_LOG_CALLBACK
  668. @cindex debugging
  669. @cindex logging
  670. @cindex query string
  671. Specify a function that should be called before parsing the URI from
  672. the client. The specified callback function can be used for processing
  673. the URI (including the options) before it is parsed. The URI after
  674. parsing will no longer contain the options, which maybe inconvenient for
  675. logging. This option should be followed by two arguments, the first
  676. one must be of the form
  677. @example
  678. void * my_logger(void * cls, const char * uri, struct MHD_Connection *con)
  679. @end example
  680. where the return value will be passed as
  681. @code{*con_cls} in calls to the @code{MHD_AccessHandlerCallback}
  682. when this request is processed later; returning a
  683. value of @code{NULL} has no special significance; (however,
  684. note that if you return non-@code{NULL}, you can no longer
  685. rely on the first call to the access handler having
  686. @code{NULL == *con_cls} on entry)
  687. @code{cls} will be set to the second argument following
  688. MHD_OPTION_URI_LOG_CALLBACK. Finally, @code{uri} will
  689. be the 0-terminated URI of the request.
  690. Note that during the time of this call, most of the connection's state
  691. is not initialized (as we have not yet parsed he headers). However,
  692. information about the connecting client (IP, socket) is available.
  693. @item MHD_OPTION_HTTPS_MEM_KEY
  694. @cindex SSL
  695. @cindex TLS
  696. Memory pointer to the private key to be used by the
  697. HTTPS daemon. This option should be followed by an
  698. "const char*" argument.
  699. This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_CERT'.
  700. @item MHD_OPTION_HTTPS_KEY_PASSWORD
  701. @cindex SSL
  702. @cindex TLS
  703. Memory pointer to the password that decrypts the
  704. private key to be used by the HTTPS daemon.
  705. This option should be followed by an
  706. "const char*" argument.
  707. This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
  708. The password (or passphrase) is only used immediately during
  709. @code{MHD_start_daemon()}. Thus, the application may want to
  710. erase it from memory afterwards for additional security.
  711. @item MHD_OPTION_HTTPS_MEM_CERT
  712. @cindex SSL
  713. @cindex TLS
  714. Memory pointer to the certificate to be used by the
  715. HTTPS daemon. This option should be followed by an
  716. "const char*" argument.
  717. This should be used in conjunction with 'MHD_OPTION_HTTPS_MEM_KEY'.
  718. @item MHD_OPTION_HTTPS_MEM_TRUST
  719. @cindex SSL
  720. @cindex TLS
  721. Memory pointer to the CA certificate to be used by the
  722. HTTPS daemon to authenticate and trust clients certificates.
  723. This option should be followed by an "const char*" argument.
  724. The presence of this option activates the request of certificate
  725. to the client. The request to the client is marked optional, and
  726. it is the responsibility of the server to check the presence
  727. of the certificate if needed.
  728. Note that most browsers will only present a client certificate
  729. only if they have one matching the specified CA, not sending
  730. any certificate otherwise.
  731. @item MHD_OPTION_HTTPS_CRED_TYPE
  732. @cindex SSL
  733. @cindex TLS
  734. Daemon credentials type. Either certificate or anonymous,
  735. this option should be followed by one of the values listed in
  736. "enum gnutls_credentials_type_t".
  737. @item MHD_OPTION_HTTPS_PRIORITIES
  738. @cindex SSL
  739. @cindex TLS
  740. @cindex cipher
  741. SSL/TLS protocol version and ciphers.
  742. This option must be followed by an "const char *" argument
  743. specifying the SSL/TLS protocol versions and ciphers that
  744. are acceptable for the application. The string is passed
  745. unchanged to gnutls_priority_init. If this option is not
  746. specified, ``NORMAL'' is used.
  747. @item MHD_OPTION_HTTPS_CERT_CALLBACK
  748. @cindex SSL
  749. @cindex TLS
  750. @cindex SNI
  751. Use a callback to determine which X.509 certificate should be used for
  752. a given HTTPS connection. This option should be followed by a
  753. argument of type "gnutls_certificate_retrieve_function2 *". This
  754. option provides an alternative to MHD_OPTION_HTTPS_MEM_KEY and
  755. MHD_OPTION_HTTPS_MEM_CERT. You must use this version if multiple
  756. domains are to be hosted at the same IP address using TLS's Server
  757. Name Indication (SNI) extension. In this case, the callback is
  758. expected to select the correct certificate based on the SNI
  759. information provided. The callback is expected to access the SNI data
  760. using gnutls_server_name_get(). Using this option requires GnuTLS 3.0
  761. or higher.
  762. @item MHD_OPTION_HTTPS_CERT_CALLBACK2
  763. @cindex SSL
  764. @cindex TLS
  765. @cindex SNI
  766. @cindex OCSP
  767. Use a callback to determine which X.509 certificate should be
  768. used for a given HTTPS connection. This option should be
  769. followed by a argument of type `gnutls_certificate_retrieve_function3 *`.
  770. This option provides an
  771. alternative/extension to #MHD_OPTION_HTTPS_CERT_CALLBACK.
  772. You must use this version if you want to use OCSP stapling.
  773. Using this option requires GnuTLS 3.6.3 or higher.
  774. @item MHD_OPTION_GNUTLS_PSK_CRED_HANDLER
  775. @cindex SSL
  776. @cindex TLS
  777. @cindex PSK
  778. Use pre-shared key for TLS credentials.
  779. Pass a pointer to callback of type
  780. @code{MHD_PskServerCredentialsCallback} and a closure.
  781. The function will be called to
  782. retrieve the shared key for a given username.
  783. @item MHD_OPTION_DIGEST_AUTH_RANDOM
  784. @cindex digest auth
  785. @cindex random
  786. Digest Authentication nonce's seed.
  787. This option should be followed by two arguments. First an integer of
  788. type "size_t" which specifies the size of the buffer pointed to by the
  789. second argument in bytes. Note that the application must ensure that
  790. the buffer of the second argument remains allocated and unmodified
  791. while the daemon is running. For security, you SHOULD provide a fresh
  792. random nonce when using MHD with Digest Authentication.
  793. @item MHD_OPTION_NONCE_NC_SIZE
  794. @cindex digest auth
  795. @cindex replay attack
  796. Size of an array of nonce and nonce counter map. This option must be
  797. followed by an "unsigned int" argument that have the size (number of
  798. elements) of a map of a nonce and a nonce-counter. If this option
  799. is not specified, a default value of 4 will be used (which might be
  800. too small for servers handling many requests). If you do not use
  801. digest authentication at all, you can specify a value of zero to
  802. save some memory.
  803. You should calculate the value of NC_SIZE based on the number of
  804. connections per second multiplied by your expected session duration
  805. plus a factor of about two for hash table collisions. For example, if
  806. you expect 100 digest-authenticated connections per second and the
  807. average user to stay on your site for 5 minutes, then you likely need
  808. a value of about 60000. On the other hand, if you can only expect
  809. only 10 digest-authenticated connections per second, tolerate browsers
  810. getting a fresh nonce for each request and expect a HTTP request
  811. latency of 250 ms, then a value of about 5 should be fine.
  812. @item MHD_OPTION_LISTEN_SOCKET
  813. @cindex systemd
  814. Listen socket to use. Pass a listen socket for MHD to use
  815. (systemd-style). If this option is used, MHD will not open its own
  816. listen socket(s). The argument passed must be of type "int" and refer
  817. to an existing socket that has been bound to a port and is listening.
  818. @item MHD_OPTION_EXTERNAL_LOGGER
  819. @cindex logging
  820. Use the given function for logging error messages.
  821. This option must be followed by two arguments; the
  822. first must be a pointer to a function
  823. of type 'void fun(void * arg, const char * fmt, va_list ap)'
  824. and the second a pointer of type 'void*' which will
  825. be passed as the "arg" argument to "fun".
  826. Note that MHD will not generate any log messages without
  827. the MHD_USE_ERROR_LOG flag set and if MHD was compiled
  828. with the "--disable-messages" flag.
  829. @item MHD_OPTION_THREAD_POOL_SIZE
  830. @cindex performance
  831. Number (unsigned int) of threads in thread pool. Enable
  832. thread pooling by setting this value to to something
  833. greater than 1. Currently, thread mode must be
  834. MHD_USE_INTERNAL_POLLING_THREAD if thread pooling is enabled
  835. (@code{MHD_start_daemon} returns @code{NULL} for an unsupported thread
  836. mode).
  837. @item MHD_OPTION_ARRAY
  838. @cindex options
  839. @cindex foreign-function interface
  840. This option can be used for initializing MHD using options from an
  841. array. A common use for this is writing an FFI for MHD. The actual
  842. options given are in an array of 'struct MHD_OptionItem', so this
  843. option requires a single argument of type 'struct MHD_OptionItem'.
  844. The array must be terminated with an entry @code{MHD_OPTION_END}.
  845. An example for code using MHD_OPTION_ARRAY is:
  846. @example
  847. struct MHD_OptionItem ops[] = @{
  848. @{ MHD_OPTION_CONNECTION_LIMIT, 100, NULL @},
  849. @{ MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL @},
  850. @{ MHD_OPTION_END, 0, NULL @}
  851. @};
  852. d = MHD_start_daemon(0, 8080, NULL, NULL, dh, NULL,
  853. MHD_OPTION_ARRAY, ops,
  854. MHD_OPTION_END);
  855. @end example
  856. For options that expect a single pointer argument, the
  857. second member of the @code{struct MHD_OptionItem} is ignored.
  858. For options that expect two pointer arguments, the first
  859. argument must be cast to @code{intptr_t}.
  860. @item MHD_OPTION_UNESCAPE_CALLBACK
  861. @cindex internationalization
  862. @cindex escaping
  863. Specify a function that should be called for unescaping escape
  864. sequences in URIs and URI arguments. Note that this function will NOT
  865. be used by the MHD_PostProcessor. If this option is not specified,
  866. the default method will be used which decodes escape sequences of the
  867. form "%HH". This option should be followed by two arguments, the
  868. first one must be of the form
  869. @example
  870. size_t my_unescaper(void * cls, struct MHD_Connection *c, char *s)
  871. @end example
  872. where the return value must be @code{strlen(s)} and @code{s} should be
  873. updated. Note that the unescape function must not lengthen @code{s}
  874. (the result must be shorter than the input and still be 0-terminated).
  875. @code{cls} will be set to the second argument following
  876. MHD_OPTION_UNESCAPE_CALLBACK.
  877. @item MHD_OPTION_THREAD_STACK_SIZE
  878. @cindex stack
  879. @cindex thread
  880. @cindex pthread
  881. @cindex embedded systems
  882. Maximum stack size for threads created by MHD. This option must be
  883. followed by a @code{size_t}). Not specifying this option or using
  884. a value of zero means using the system default (which is likely to
  885. differ based on your platform).
  886. @item MHD_OPTION_TCP_FASTQUEUE_QUEUE_SIZE
  887. @cindex listen
  888. When the flag @code{MHD_USE_TCP_FASTOPEN} is used, this option sets the
  889. connection handshake queue size for the TCP FASTOPEN connections. Note
  890. that a TCP FASTOPEN connection handshake occupies more resources than a
  891. TCP handshake as the SYN packets also contain DATA which is kept in the
  892. associate state until handshake is completed. If this option is not
  893. given the queue size is set to a default value of 10. This option must
  894. be followed by a @code{unsigned int}.
  895. @item MHD_OPTION_HTTPS_MEM_DHPARAMS
  896. @cindex TLS
  897. @cindex SSL
  898. @cindex DH
  899. Memory pointer for the Diffie-Hellman parameters (dh.pem) to be used
  900. by the HTTPS daemon for key exchange. This option must be followed by
  901. a @code{const char *} argument. The argument would be a zero-terminated
  902. string with a PEM encoded PKCS3 DH parameters structure suitable
  903. for passing to @code{gnutls_dh_parms_import_pkcs3}.
  904. @item MHD_OPTION_LISTENING_ADDRESS_REUSE
  905. @cindex bind, restricting bind
  906. @cindex reusing listening address
  907. This option must be followed by a @code{unsigned int} argument.
  908. If this option is present and true (nonzero) parameter is given, allow reusing
  909. the address:port of the listening socket (using @code{SO_REUSEPORT} on most
  910. platforms, and @code{SO_REUSEADDR} on Windows). If a false (zero) parameter is
  911. given, disallow reusing the the address:port of the listening socket (this
  912. usually requires no special action, but @code{SO_EXCLUSIVEADDRUSE} is needed on
  913. Windows). If this option is not present @code{SO_REUSEADDR} is used on all
  914. platforms except Windows so reusing of address:port is disallowed.
  915. @end table
  916. @end deftp
  917. @deftp {C Struct} MHD_OptionItem
  918. Entry in an MHD_OPTION_ARRAY. See the @code{MHD_OPTION_ARRAY} option
  919. argument for its use.
  920. The @code{option} member is used to specify which option is specified
  921. in the array. The other members specify the respective argument.
  922. Note that for options taking only a single pointer, the
  923. @code{ptr_value} member should be set. For options taking two pointer
  924. arguments, the first pointer must be cast to @code{intptr_t} and both
  925. the @code{value} and the @code{ptr_value} members should be used to
  926. pass the two pointers.
  927. @end deftp
  928. @deftp {Enumeration} MHD_ValueKind
  929. The @code{MHD_ValueKind} specifies the source of the key-value pairs in
  930. the HTTP protocol.
  931. @table @code
  932. @item MHD_HEADER_KIND
  933. HTTP header.
  934. @item MHD_COOKIE_KIND
  935. @cindex cookie
  936. Cookies. Note that the original HTTP header containing the cookie(s)
  937. will still be available and intact.
  938. @item MHD_POSTDATA_KIND
  939. @cindex POST method
  940. @code{POST} data. This is available only if a content encoding
  941. supported by MHD is used (currently only @acronym{URL} encoding), and
  942. only if the posted content fits within the available memory pool. Note
  943. that in that case, the upload data given to the
  944. @code{MHD_AccessHandlerCallback()} will be empty (since it has
  945. already been processed).
  946. @item MHD_GET_ARGUMENT_KIND
  947. @code{GET} (URI) arguments.
  948. @item MHD_FOOTER_KIND
  949. HTTP footer (only for http 1.1 chunked encodings).
  950. @end table
  951. @end deftp
  952. @deftp {Enumeration} MHD_RequestTerminationCode
  953. The @code{MHD_RequestTerminationCode} specifies reasons why a request
  954. has been terminated (or completed).
  955. @table @code
  956. @item MHD_REQUEST_TERMINATED_COMPLETED_OK
  957. We finished sending the response.
  958. @item MHD_REQUEST_TERMINATED_WITH_ERROR
  959. Error handling the connection (resources exhausted, other side closed
  960. connection, application error accepting request, etc.)
  961. @item MHD_REQUEST_TERMINATED_TIMEOUT_REACHED
  962. No activity on the connection for the number of seconds specified using
  963. @code{MHD_OPTION_CONNECTION_TIMEOUT}.
  964. @item MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN
  965. We had to close the session since MHD was being shut down.
  966. @end table
  967. @end deftp
  968. @deftp {Enumeration} MHD_ResponseMemoryMode
  969. The @code{MHD_ResponeMemoryMode} specifies how MHD should treat
  970. the memory buffer given for the response in
  971. @code{MHD_create_response_from_buffer}.
  972. @table @code
  973. @item MHD_RESPMEM_PERSISTENT
  974. Buffer is a persistent (static/global) buffer that won't change
  975. for at least the lifetime of the response, MHD should just use
  976. it, not free it, not copy it, just keep an alias to it.
  977. @item MHD_RESPMEM_MUST_FREE
  978. Buffer is heap-allocated with @code{malloc} (or equivalent) and
  979. should be freed by MHD after processing the response has
  980. concluded (response reference counter reaches zero).
  981. @item MHD_RESPMEM_MUST_COPY
  982. Buffer is in transient memory, but not on the heap (for example,
  983. on the stack or non-malloc allocated) and only valid during the
  984. call to @code{MHD_create_response_from_buffer}. MHD must make its
  985. own private copy of the data for processing.
  986. @end table
  987. @end deftp
  988. @deftp {Enumeration} MHD_ResponseFlags
  989. Response-specific flags. Passed as an argument to
  990. @code{MHD_set_response_options()}.
  991. @table @code
  992. @item MHD_RF_NONE
  993. No special handling.
  994. @item MHD_RF_HTTP_VERSION_1_0_ONLY
  995. Only respond in conservative HTTP 1.0-mode. In particular,
  996. do not (automatically) sent "Connection" headers and always
  997. close the connection after generating the response.
  998. By default, MHD will respond using the same HTTP version which
  999. was set in the request. You can also set the
  1000. @code{MHD_RF_HTTP_VERSION_1_0_RESPONSE} flag to force version 1.0
  1001. in the response.
  1002. @item MHD_RF_HTTP_VERSION_1_0_RESPONSE
  1003. Only respond in HTTP 1.0-mode. Contrary to the
  1004. @code{MHD_RF_HTTP_VERSION_1_0_ONLY} flag, the response's HTTP version will
  1005. always be set to 1.0 and ``Connection'' headers are still supported.
  1006. You can even combine this option with MHD_RF_HTTP_VERSION_1_0_ONLY to
  1007. change the response's HTTP version while maintaining strict compliance
  1008. with HTTP 1.0 regarding connection management.
  1009. This solution is not perfect as this flag is set on the response which
  1010. is created after header processing. So MHD will behave as a HTTP 1.1
  1011. server until the response is queued. It means that an invalid HTTP 1.1
  1012. request will fail even if the response is sent with HTTP 1.0 and the
  1013. request would be valid if interpreted with this version. For example,
  1014. this request will fail in strict mode:
  1015. @verbatim
  1016. GET / HTTP/1.1
  1017. @end verbatim
  1018. as the ``Host'' header is missing and is mandatory in HTTP 1.1, but it
  1019. should succeed when interpreted with HTTP 1.0.
  1020. @item MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
  1021. Disable sanity check preventing clients from manually
  1022. setting the HTTP content length option.
  1023. @end table
  1024. @end deftp
  1025. @deftp {Enumeration} MHD_ResponseOptions
  1026. Response-specific options. Passed in the varargs portion of
  1027. @code{MHD_set_response_options()}.
  1028. @table @code
  1029. @item MHD_RO_END
  1030. No more options / last option. This is used to terminate the VARARGs
  1031. list.
  1032. @end table
  1033. @end deftp
  1034. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1035. @c ------------------------------------------------------------
  1036. @node microhttpd-struct
  1037. @chapter Structures type definition
  1038. @deftp {C Struct} MHD_Daemon
  1039. Handle for the daemon (listening on a socket for HTTP traffic).
  1040. @end deftp
  1041. @deftp {C Struct} MHD_Connection
  1042. Handle for a connection / HTTP request. With HTTP/1.1, multiple
  1043. requests can be run over the same connection. However, MHD will only
  1044. show one request per TCP connection to the client at any given time.
  1045. @end deftp
  1046. @deftp {C Struct} MHD_Response
  1047. Handle for a response.
  1048. @end deftp
  1049. @deftp {C Struct} MHD_IoVec
  1050. An element of an array of memory buffers.
  1051. @end deftp
  1052. @deftp {C Struct} MHD_PostProcessor
  1053. @cindex POST method
  1054. Handle for @code{POST} processing.
  1055. @end deftp
  1056. @deftp {C Union} MHD_ConnectionInfo
  1057. Information about a connection.
  1058. @end deftp
  1059. @deftp {C Union} MHD_DaemonInfo
  1060. Information about an MHD daemon.
  1061. @end deftp
  1062. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1063. @c ------------------------------------------------------------
  1064. @node microhttpd-cb
  1065. @chapter Callback functions definition
  1066. @deftypefn {Function Pointer} enum MHD_Result {*MHD_AcceptPolicyCallback} (void *cls, const struct sockaddr * addr, socklen_t addrlen)
  1067. Invoked in the context of a connection to allow or deny a client to
  1068. connect. This callback return @code{MHD_YES} if connection is allowed,
  1069. @code{MHD_NO} if not.
  1070. @table @var
  1071. @item cls
  1072. custom value selected at callback registration time;
  1073. @item addr
  1074. address information from the client;
  1075. @item addrlen
  1076. length of the address information.
  1077. @end table
  1078. @end deftypefn
  1079. @deftypefn {Function Pointer} enum MHD_Result {*MHD_AccessHandlerCallback} (void *cls, struct MHD_Connection * connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
  1080. Invoked in the context of a connection to answer a request from the
  1081. client. This callback must call MHD functions (example: the
  1082. @code{MHD_Response} ones) to provide content to give back to the client
  1083. and return an HTTP status code (i.e. @code{200} for OK, @code{404},
  1084. etc.).
  1085. @ref{microhttpd-post}, for details on how to code this callback.
  1086. Must return @code{MHD_YES} if the connection was handled successfully,
  1087. @code{MHD_NO} if the socket must be closed due to a serious error while
  1088. handling the request
  1089. @table @var
  1090. @item cls
  1091. custom value selected at callback registration time;
  1092. @item url
  1093. the URL requested by the client;
  1094. @item method
  1095. the HTTP method used by the client (@code{GET}, @code{PUT},
  1096. @code{DELETE}, @code{POST}, etc.);
  1097. @item version
  1098. the HTTP version string (i.e. @code{HTTP/1.1});
  1099. @item upload_data
  1100. the data being uploaded (excluding headers):
  1101. @cindex POST method
  1102. @cindex PUT method
  1103. @code{POST} data @strong{will} be made available
  1104. incrementally in @var{upload_data}; even if @code{POST}
  1105. data is available, the first time the callback is
  1106. invoked there won't be upload data, as this is done
  1107. just after MHD parses the headers. If supported by
  1108. the client and the HTTP version, the application can
  1109. at this point queue an error response to possibly
  1110. avoid the upload entirely. If no response is generated,
  1111. MHD will (if required) automatically send a 100 CONTINUE
  1112. reply to the client.
  1113. Afterwards, POST data will be passed to the callback
  1114. to be processed incrementally by the application. The
  1115. application may return @code{MHD_NO} to forcefully
  1116. terminate the TCP connection without generating a
  1117. proper HTTP response. Once all of the upload data has
  1118. been provided to the application, the application
  1119. will be called again with 0 bytes of upload data.
  1120. At this point, a response should be queued to complete
  1121. the handling of the request.
  1122. @item upload_data_size
  1123. set initially to the size of the @var{upload_data} provided; this
  1124. callback must update this value to the number of bytes @strong{NOT}
  1125. processed; unless external select is used, the callback maybe
  1126. required to process at least some data. If the callback fails to
  1127. process data in multi-threaded or internal-select mode and if the
  1128. read-buffer is already at the maximum size that MHD is willing to
  1129. use for reading (about half of the maximum amount of memory allowed
  1130. for the connection), then MHD will abort handling the connection
  1131. and return an internal server error to the client. In order to
  1132. avoid this, clients must be able to process upload data incrementally
  1133. and reduce the value of @code{upload_data_size}.
  1134. @item con_cls
  1135. reference to a pointer, initially set to @code{NULL}, that this callback can
  1136. set to some address and that will be preserved by MHD for future
  1137. calls for this request;
  1138. since the access handler may be called many times (i.e., for a
  1139. @code{PUT}/@code{POST} operation with plenty of upload data) this allows
  1140. the application to easily associate some request-specific state;
  1141. if necessary, this state can be cleaned up in the global
  1142. @code{MHD_RequestCompletedCallback} (which can be set with the
  1143. @code{MHD_OPTION_NOTIFY_COMPLETED}).
  1144. @end table
  1145. @end deftypefn
  1146. @deftypefn {Function Pointer} void {*MHD_RequestCompletedCallback} (void *cls, struct MHD_Connectionconnection, void **con_cls, enum MHD_RequestTerminationCode toe)
  1147. Signature of the callback used by MHD to notify the application about
  1148. completed requests.
  1149. @table @var
  1150. @item cls
  1151. custom value selected at callback registration time;
  1152. @item connection
  1153. connection handle;
  1154. @item con_cls
  1155. value as set by the last call to the
  1156. @code{MHD_AccessHandlerCallback};
  1157. @item toe
  1158. reason for request termination see @code{MHD_OPTION_NOTIFY_COMPLETED}.
  1159. @end table
  1160. @end deftypefn
  1161. @deftypefn {Function Pointer} enum MHD_Result {*MHD_KeyValueIterator} (void *cls, enum MHD_ValueKind kind, const char *key, const char *value, size_t value_size)
  1162. Iterator over key-value pairs. This iterator can be used to iterate
  1163. over all of the cookies, headers, or @code{POST}-data fields of a
  1164. request, and also to iterate over the headers that have been added to a
  1165. response.
  1166. @table @var
  1167. @item cls
  1168. custom value specified when iteration was triggered;
  1169. @item kind
  1170. kind of the header we are looking at
  1171. @item key
  1172. key for the value, can be an empty string
  1173. @item value
  1174. value corresponding value, can be NULL
  1175. @item value_size
  1176. number of bytes in @code{value}. This argument was introduced in
  1177. @code{MHD_VERSION} 0x00096301 to allow applications to use binary
  1178. zeros in values. Applications using this argument must ensure that
  1179. they are using a sufficiently recent version of MHD, i.e. by testing
  1180. @code{MHD_get_version()} for values above or equal to 0.9.64.
  1181. Applications that do not need zeros in values and that want to compile
  1182. without warnings against newer versions of MHD should not declare this
  1183. argument and cast the function pointer argument to
  1184. @code{MHD_KeyValueIterator}.
  1185. @end table
  1186. Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
  1187. iteration.
  1188. @end deftypefn
  1189. @deftypefn {Function Pointer} ssize_t {*MHD_ContentReaderCallback} (void *cls, uint64_t pos, char *buf, size_t max)
  1190. Callback used by MHD in order to obtain content. The callback has to
  1191. copy at most @var{max} bytes of content into @var{buf}. The total
  1192. number of bytes that has been placed into @var{buf} should be returned.
  1193. Note that returning zero will cause MHD to try again.
  1194. Thus, returning zero should only be used in conjunction
  1195. with @code{MHD_suspend_connection()} to avoid busy waiting.
  1196. While usually the callback simply returns the number of bytes written
  1197. into @var{buf}, there are two special return value:
  1198. @code{MHD_CONTENT_READER_END_OF_STREAM} (-1) should be returned
  1199. for the regular end of transmission (with chunked encoding, MHD will then
  1200. terminate the chunk and send any HTTP footers that might be
  1201. present; without chunked encoding and given an unknown
  1202. response size, MHD will simply close the connection; note
  1203. that while returning @code{MHD_CONTENT_READER_END_OF_STREAM} is not technically
  1204. legal if a response size was specified, MHD accepts this
  1205. and treats it just as @code{MHD_CONTENT_READER_END_WITH_ERROR}.
  1206. @code{MHD_CONTENT_READER_END_WITH_ERROR} (-2) is used to indicate a server
  1207. error generating the response; this will cause MHD to simply
  1208. close the connection immediately. If a response size was
  1209. given or if chunked encoding is in use, this will indicate
  1210. an error to the client. Note, however, that if the client
  1211. does not know a response size and chunked encoding is not in
  1212. use, then clients will not be able to tell the difference between
  1213. @code{MHD_CONTENT_READER_END_WITH_ERROR} and
  1214. @code{MHD_CONTENT_READER_END_OF_STREAM}.
  1215. This is not a limitation of MHD but rather of the HTTP protocol.
  1216. @table @var
  1217. @item cls
  1218. custom value selected at callback registration time;
  1219. @item pos
  1220. position in the datastream to access; note that if an
  1221. @code{MHD_Response} object is re-used, it is possible for the same
  1222. content reader to be queried multiple times for the same data; however,
  1223. if an @code{MHD_Response} is not re-used, MHD guarantees that
  1224. @var{pos} will be the sum of all non-negative return values obtained
  1225. from the content reader so far.
  1226. @end table
  1227. Return @code{-1} on error (MHD will no longer try to read content and
  1228. instead close the connection with the client).
  1229. @end deftypefn
  1230. @deftypefn {Function Pointer} void {*MHD_ContentReaderFreeCallback} (void *cls)
  1231. This method is called by MHD if we are done with a content reader.
  1232. It should be used to free resources associated with the content reader.
  1233. @end deftypefn
  1234. @deftypefn {Function Pointer} enum MHD_Result {*MHD_PostDataIterator} (void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
  1235. Iterator over key-value pairs where the value maybe made available in
  1236. increments and/or may not be zero-terminated. Used for processing
  1237. @code{POST} data.
  1238. @table @var
  1239. @item cls
  1240. custom value selected at callback registration time;
  1241. @item kind
  1242. type of the value;
  1243. @item key
  1244. zero-terminated key for the value;
  1245. @item filename
  1246. name of the uploaded file, @code{NULL} if not known;
  1247. @item content_type
  1248. mime-type of the data, @code{NULL} if not known;
  1249. @item transfer_encoding
  1250. encoding of the data, @code{NULL} if not known;
  1251. @item data
  1252. pointer to size bytes of data at the specified offset;
  1253. @item off
  1254. offset of data in the overall value;
  1255. @item size
  1256. number of bytes in data available.
  1257. @end table
  1258. Return @code{MHD_YES} to continue iterating, @code{MHD_NO} to abort the
  1259. iteration.
  1260. @end deftypefn
  1261. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1262. @c ------------------------------------------------------------
  1263. @node microhttpd-init
  1264. @chapter Starting and stopping the server
  1265. @deftypefun {void} MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
  1266. Set a handler for fatal errors.
  1267. @table @var
  1268. @item cb
  1269. function to call if MHD encounters a fatal internal error. If no handler was set explicitly, MHD will call @code{abort}.
  1270. @item cls
  1271. closure argument for cb; the other arguments are the name of the source file, line number and a string describing the nature of the fatal error (which can be @code{NULL})
  1272. @end table
  1273. @end deftypefun
  1274. @deftypefun {struct MHD_Daemon *} MHD_start_daemon (unsigned int flags, unsigned short port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, ...)
  1275. Start a webserver on the given port.
  1276. @table @var
  1277. @item flags
  1278. OR-ed combination of @code{MHD_FLAG} values;
  1279. @item port
  1280. port to bind to;
  1281. @item apc
  1282. callback to call to check which clients will be allowed to connect; you
  1283. can pass @code{NULL} in which case connections from any @acronym{IP} will be
  1284. accepted;
  1285. @item apc_cls
  1286. extra argument to @var{apc};
  1287. @item dh
  1288. default handler for all URIs;
  1289. @item dh_cls
  1290. extra argument to @var{dh}.
  1291. @end table
  1292. Additional arguments are a list of options (type-value pairs,
  1293. terminated with @code{MHD_OPTION_END}). It is mandatory to use
  1294. @code{MHD_OPTION_END} as last argument, even when there are no
  1295. additional arguments.
  1296. Return @code{NULL} on error, handle to daemon on success.
  1297. @end deftypefun
  1298. @deftypefun MHD_socket MHD_quiesce_daemon (struct MHD_Daemon *daemon)
  1299. @cindex quiesce
  1300. Stop accepting connections from the listening socket. Allows clients
  1301. to continue processing, but stops accepting new connections. Note
  1302. that the caller is responsible for closing the returned socket;
  1303. however, if MHD is run using threads (anything but external select
  1304. mode), it must not be closed until AFTER @code{MHD_stop_daemon} has
  1305. been called (as it is theoretically possible that an existing thread
  1306. is still using it).
  1307. This function is useful in the special case that a listen socket
  1308. is to be migrated to another process (i.e. a newer version of the
  1309. HTTP server) while existing connections should continue to be
  1310. processed until they are finished.
  1311. Return @code{-1} on error (daemon not listening), the handle to the
  1312. listen socket otherwise.
  1313. @end deftypefun
  1314. @deftypefun void MHD_stop_daemon (struct MHD_Daemon *daemon)
  1315. Shutdown an HTTP daemon.
  1316. @end deftypefun
  1317. @deftypefun enum MHD_Result MHD_run (struct MHD_Daemon *daemon)
  1318. Run webserver operations (without blocking unless in client callbacks).
  1319. This method should be called by clients in combination with
  1320. @code{MHD_get_fdset()} if the client-controlled @code{select}-method is used.
  1321. @cindex select
  1322. @cindex poll
  1323. This function will work for external @code{poll} and @code{select} mode.
  1324. However, if using external @code{select} mode, you may want to
  1325. instead use @code{MHD_run_from_select}, as it is more efficient.
  1326. @table @var
  1327. @item daemon
  1328. daemon to process connections of
  1329. @end table
  1330. Return @code{MHD_YES} on success, @code{MHD_NO} if this daemon was not
  1331. started with the right options for this call.
  1332. @end deftypefun
  1333. @deftypefun enum MHD_Result MHD_run_from_select (struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
  1334. Run webserver operations given sets of ready socket handles.
  1335. @cindex select
  1336. This method should be called by clients in combination with
  1337. @code{MHD_get_fdset} if the client-controlled (external)
  1338. select method is used.
  1339. You can use this function instead of @code{MHD_run} if you called
  1340. @code{select} on the result from @code{MHD_get_fdset}. File descriptors in
  1341. the sets that are not controlled by MHD will be ignored. Calling
  1342. this function instead of @code{MHD_run} is more efficient as MHD will
  1343. not have to call @code{select} again to determine which operations are
  1344. ready.
  1345. @table @var
  1346. @item daemon
  1347. daemon to process connections of
  1348. @item read_fd_set
  1349. set of descriptors that must be ready for reading without blocking
  1350. @item write_fd_set
  1351. set of descriptors that must be ready for writing without blocking
  1352. @item except_fd_set
  1353. ignored, can be NULL
  1354. @end table
  1355. Return @code{MHD_YES} on success, @code{MHD_NO} on serious internal
  1356. errors.
  1357. @end deftypefun
  1358. @deftypefun void MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
  1359. Add another client connection to the set of connections
  1360. managed by MHD. This API is usually not needed (since
  1361. MHD will accept inbound connections on the server socket).
  1362. Use this API in special cases, for example if your HTTP
  1363. server is behind NAT and needs to connect out to the
  1364. HTTP client, or if you are building a proxy.
  1365. If you use this API in conjunction with a internal select or a thread
  1366. pool, you must set the option @code{MHD_USE_ITC} to
  1367. ensure that the freshly added connection is immediately processed by
  1368. MHD.
  1369. The given client socket will be managed (and closed!) by MHD after
  1370. this call and must no longer be used directly by the application
  1371. afterwards.
  1372. @table @var
  1373. @item daemon
  1374. daemon that manages the connection
  1375. @item client_socket
  1376. socket to manage (MHD will expect to receive an HTTP request from this socket next).
  1377. @item addr
  1378. IP address of the client
  1379. @item addrlen
  1380. number of bytes in addr
  1381. @end table
  1382. This function will return @code{MHD_YES} on success,
  1383. @code{MHD_NO} if this daemon could
  1384. not handle the connection (i.e. malloc failed, etc).
  1385. The socket will be closed in any case; 'errno' is set
  1386. to indicate further details about the error.
  1387. @end deftypefun
  1388. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1389. @c -----------------------------------------------------------
  1390. @node microhttpd-inspect
  1391. @chapter Implementing external @code{select}
  1392. @deftypefun enum MHD_Result MHD_get_fdset (struct MHD_Daemon *daemon, fd_set * read_fd_set, fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd)
  1393. Obtain the @code{select()} sets for this daemon. The daemon's socket
  1394. is added to @var{read_fd_set}. The list of currently existent
  1395. connections is scanned and their file descriptors added to the correct
  1396. set.
  1397. When calling this function, FD_SETSIZE is assumed to be platform's
  1398. default. If you changed FD_SETSIZE for your application,
  1399. you should use @code{MHD_get_fdset2()} instead.
  1400. This function should only be called in when MHD is configured to use
  1401. external select with @code{select()} or with @code{epoll()}. In
  1402. the latter case, it will only add the single @code{epoll()} file
  1403. descriptor used by MHD to the sets.
  1404. After the call completed successfully: the variable referenced by
  1405. @var{max_fd} references the file descriptor with highest integer
  1406. identifier. The variable must be set to zero before invoking this
  1407. function.
  1408. Return @code{MHD_YES} on success, @code{MHD_NO} if: the arguments are
  1409. invalid (example: @code{NULL} pointers); this daemon was not started with
  1410. the right options for this call.
  1411. @end deftypefun
  1412. @deftypefun enum MHD_Result MHD_get_fdset2 (struct MHD_Daemon *daemon, fd_set * read_fd_set, fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd, unsigned int fd_setsize)
  1413. Like @code{MHD_get_fdset()}, except that you can manually specify the value of FD_SETSIZE used by your application.
  1414. @end deftypefun
  1415. @deftypefun enum MHD_Result MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long *timeout)
  1416. @cindex timeout
  1417. Obtain timeout value for select for this daemon (only needed if
  1418. connection timeout is used). The returned value is how many
  1419. milliseconds @code{select} should at most block, not the timeout value
  1420. set for connections. This function must not be called if the
  1421. @code{MHD_USE_THREAD_PER_CONNECTION} mode is in use (since then it is
  1422. not meaningful to ask for a timeout, after all, there is concurrenct
  1423. activity). The function must also not be called by user-code if
  1424. @code{MHD_USE_INTERNAL_POLLING_THREAD} is in use. In the latter case, the
  1425. behavior is undefined.
  1426. @table @var
  1427. @item daemon
  1428. which daemon to obtain the timeout from.
  1429. @item timeout
  1430. will be set to the timeout (in milliseconds).
  1431. @end table
  1432. Return @code{MHD_YES} on success, @code{MHD_NO} if timeouts are not used
  1433. (or no connections exist that would necessitate the use of a timeout
  1434. right now).
  1435. @end deftypefun
  1436. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1437. @c -----------------------------------------------------------
  1438. @node microhttpd-requests
  1439. @chapter Handling requests
  1440. @deftypefun int MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
  1441. Get all the headers matching @var{kind} from the request. The @var{kind}
  1442. argument can be a bitmask, ORing the various header kinds that are
  1443. requested.
  1444. The @var{iterator} callback is invoked once for each header, with
  1445. @var{iterator_cls} as first argument. After version 0.9.19, the
  1446. headers are iterated in the same order as they were received from
  1447. the network; previous versions iterated over the headers in reverse
  1448. order.
  1449. @code{MHD_get_connection_values} returns the number of entries
  1450. iterated over; this can be less than the number of headers if, while
  1451. iterating, @var{iterator} returns @code{MHD_NO}.
  1452. @var{iterator} can be @code{NULL}: in this case this function just counts
  1453. and returns the number of headers.
  1454. In the case of @code{MHD_GET_ARGUMENT_KIND}, the @var{value} argument
  1455. will be @code{NULL} if the URL contained a key without an equals operator.
  1456. For example, for a HTTP request to the URL ``http://foo/bar?key'', the
  1457. @var{value} argument is @code{NULL}; in contrast, a HTTP request to the URL
  1458. ``http://foo/bar?key='', the @var{value} argument is the empty string.
  1459. The normal case is that the URL contains ``http://foo/bar?key=value''
  1460. in which case @var{value} would be the string ``value'' and @var{key}
  1461. would contain the string ``key''.
  1462. @end deftypefun
  1463. @deftypefun enum MHD_Result MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
  1464. This function can be used to append an entry to
  1465. the list of HTTP headers of a connection (so that the
  1466. @code{MHD_get_connection_values function} will return
  1467. them -- and the MHD PostProcessor will also
  1468. see them). This maybe required in certain
  1469. situations (see Mantis #1399) where (broken)
  1470. HTTP implementations fail to supply values needed
  1471. by the post processor (or other parts of the
  1472. application).
  1473. This function MUST only be called from within
  1474. the MHD_AccessHandlerCallback (otherwise, access
  1475. maybe improperly synchronized). Furthermore,
  1476. the client must guarantee that the key and
  1477. value arguments are 0-terminated strings that
  1478. are NOT freed until the connection is closed.
  1479. (The easiest way to do this is by passing only
  1480. arguments to permanently allocated strings.).
  1481. @var{connection} is the connection for which
  1482. the entry for @var{key} of the given @var{kind}
  1483. should be set to the given @var{value}.
  1484. The function returns @code{MHD_NO} if the operation
  1485. could not be performed due to insufficient memory
  1486. and @code{MHD_YES} on success.
  1487. @end deftypefun
  1488. @deftypefun {const char *} MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
  1489. Get a particular header value. If multiple values match the
  1490. @var{kind}, return one of them (the ``first'', whatever that means).
  1491. @var{key} must reference a zero-terminated ASCII-coded string
  1492. representing the header to look for: it is compared against the
  1493. headers using (basically) @code{strcasecmp()}, so case is ignored.
  1494. @end deftypefun
  1495. @deftypefun {const char *} MHD_lookup_connection_value_n (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, size_t key_size, const char **value_ptr, size_t *value_size_ptr)
  1496. Get a particular header value. If multiple values match the
  1497. @var{kind}, return one of them (the ``first'', whatever that means).
  1498. @var{key} must reference an ASCII-coded string
  1499. representing the header to look for: it is compared against the
  1500. headers using (basically) @code{strncasecmp()}, so case is ignored.
  1501. The @var{value_ptr} is set to the address of the value found,
  1502. and @var{value_size_ptr} is set to the number of bytes in the
  1503. value.
  1504. @end deftypefun
  1505. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1506. @c ------------------------------------------------------------
  1507. @node microhttpd-responses
  1508. @chapter Building responses to requests
  1509. @noindent
  1510. Response objects handling by MHD is asynchronous with respect to the
  1511. application execution flow. Instances of the @code{MHD_Response}
  1512. structure are not associated to a daemon and neither to a client
  1513. connection: they are managed with reference counting.
  1514. In the simplest case: we allocate a new @code{MHD_Response} structure
  1515. for each response, we use it once and finally we destroy it.
  1516. MHD allows more efficient resources usages.
  1517. Example: we allocate a new @code{MHD_Response} structure for each
  1518. response @strong{kind}, we use it every time we have to give that
  1519. response and we finally destroy it only when the daemon shuts down.
  1520. @menu
  1521. * microhttpd-response enqueue:: Enqueuing a response.
  1522. * microhttpd-response create:: Creating a response object.
  1523. * microhttpd-response headers:: Adding headers to a response.
  1524. * microhttpd-response options:: Setting response options.
  1525. * microhttpd-response inspect:: Inspecting a response object.
  1526. * microhttpd-response upgrade:: Creating a response for protocol upgrades.
  1527. @end menu
  1528. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1529. @c ------------------------------------------------------------
  1530. @node microhttpd-response enqueue
  1531. @section Enqueuing a response
  1532. @deftypefun enum MHD_Result MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
  1533. Queue a response to be transmitted to the client as soon as possible
  1534. but only after MHD_AccessHandlerCallback returns. This function
  1535. checks that it is legal to queue a response at this time for the
  1536. given connection. It also increments the internal reference
  1537. counter for the response object (the counter will be decremented
  1538. automatically once the response has been transmitted).
  1539. @table @var
  1540. @item connection
  1541. the connection identifying the client;
  1542. @item status_code
  1543. HTTP status code (i.e. @code{200} for OK);
  1544. @item response
  1545. response to transmit.
  1546. @end table
  1547. Return @code{MHD_YES} on success or if message has been queued. Return
  1548. @code{MHD_NO}: if arguments are invalid (example: @code{NULL} pointer); on
  1549. error (i.e. reply already sent).
  1550. @end deftypefun
  1551. @deftypefun void MHD_destroy_response (struct MHD_Response *response)
  1552. Destroy a response object and associated resources (decrement the
  1553. reference counter). Note that MHD may keep some of the resources
  1554. around if the response is still in the queue for some clients, so the
  1555. memory may not necessarily be freed immediately.
  1556. @end deftypefun
  1557. An explanation of reference counting@footnote{Note to readers acquainted
  1558. to the Tcl API: reference counting on @code{MHD_Connection}
  1559. structures is handled in the same way as Tcl handles @code{Tcl_Obj}
  1560. structures through @code{Tcl_IncrRefCount()} and
  1561. @code{Tcl_DecrRefCount()}.}:
  1562. @enumerate
  1563. @item
  1564. a @code{MHD_Response} object is allocated:
  1565. @example
  1566. struct MHD_Response * response = MHD_create_response_from_buffer(...);
  1567. /* here: reference counter = 1 */
  1568. @end example
  1569. @item
  1570. the @code{MHD_Response} object is enqueued in a @code{MHD_Connection}:
  1571. @example
  1572. MHD_queue_response(connection, , response);
  1573. /* here: reference counter = 2 */
  1574. @end example
  1575. @item
  1576. the creator of the response object discharges responsibility for it:
  1577. @example
  1578. MHD_destroy_response(response);
  1579. /* here: reference counter = 1 */
  1580. @end example
  1581. @item
  1582. the daemon handles the connection sending the response's data to the
  1583. client then decrements the reference counter by calling
  1584. @code{MHD_destroy_response()}: the counter's value drops to zero and
  1585. the @code{MHD_Response} object is released.
  1586. @end enumerate
  1587. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1588. @c ------------------------------------------------------------
  1589. @node microhttpd-response create
  1590. @section Creating a response object
  1591. @deftypefun {struct MHD_Response *} MHD_create_response_from_callback (uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
  1592. Create a response object. The response object can be extended with
  1593. header information and then it can be used any number of times.
  1594. @table @var
  1595. @item size
  1596. size of the data portion of the response, @code{-1} for unknown;
  1597. @item block_size
  1598. preferred block size for querying @var{crc} (advisory only, MHD may
  1599. still call @var{crc} using smaller chunks); this is essentially the
  1600. buffer size used for @acronym{IO}, clients should pick a value that is
  1601. appropriate for @acronym{IO} and memory performance requirements;
  1602. @item crc
  1603. callback to use to obtain response data;
  1604. @item crc_cls
  1605. extra argument to @var{crc};
  1606. @item crfc
  1607. callback to call to free @var{crc_cls} resources.
  1608. @end table
  1609. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1610. @end deftypefun
  1611. @deftypefun {struct MHD_Response *} MHD_create_response_from_fd (uint64_t size, int fd)
  1612. Create a response object. The response object can be extended with
  1613. header information and then it can be used any number of times.
  1614. @table @var
  1615. @item size
  1616. size of the data portion of the response (should be smaller or equal to the
  1617. size of the file)
  1618. @item fd
  1619. file descriptor referring to a file on disk with the data; will be
  1620. closed when response is destroyed; note that 'fd' must be an actual
  1621. file descriptor (not a pipe or socket) since MHD might use 'sendfile'
  1622. or 'seek' on it. The descriptor should be in blocking-IO mode.
  1623. @end table
  1624. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1625. @end deftypefun
  1626. @deftypefun {struct MHD_Response *} MHD_create_response_from_pipe (uint64_t size, int fd)
  1627. Create a response object. The response object can be extended with
  1628. header information and then it can be used ONLY ONCE.
  1629. @table @var
  1630. @item fd
  1631. file descriptor of the read-end of the pipe; will be
  1632. closed when response is destroyed.
  1633. The descriptor should be in blocking-IO mode.
  1634. @end table
  1635. Return @code{NULL} on error (i.e. out of memory).
  1636. @end deftypefun
  1637. @deftypefun {struct MHD_Response *} MHD_create_response_from_fd_at_offset (size_t size, int fd, off_t offset)
  1638. Create a response object. The response object can be extended with
  1639. header information and then it can be used any number of times.
  1640. Note that you need to be a bit careful about @code{off_t} when
  1641. writing this code. Depending on your platform, MHD is likely
  1642. to have been compiled with support for 64-bit files. When you
  1643. compile your own application, you must make sure that @code{off_t}
  1644. is also a 64-bit value. If not, your compiler may pass a 32-bit
  1645. value as @code{off_t}, which will result in 32-bits of garbage.
  1646. If you use the autotools, use the @code{AC_SYS_LARGEFILE} autoconf
  1647. macro and make sure to include the generated @file{config.h} file
  1648. before @file{microhttpd.h} to avoid problems. If you do not have a
  1649. build system and only want to run on a GNU/Linux system, you could
  1650. also use
  1651. @verbatim
  1652. #define _FILE_OFFSET_BITS 64
  1653. #include <sys/types.h>
  1654. #include <sys/stat.h>
  1655. #include <fcntl.h>
  1656. #include <microhttpd.h>
  1657. @end verbatim
  1658. to ensure 64-bit @code{off_t}. Note that if your operating system
  1659. does not support 64-bit files, MHD will be compiled with a 32-bit
  1660. @code{off_t} (in which case the above would be wrong).
  1661. @table @var
  1662. @item size
  1663. size of the data portion of the response (number of bytes to transmit from the
  1664. file starting at offset).
  1665. @item fd
  1666. file descriptor referring to a file on disk with the data; will be
  1667. closed when response is destroyed; note that 'fd' must be an actual
  1668. file descriptor (not a pipe or socket) since MHD might use 'sendfile'
  1669. or 'seek' on it. The descriptor should be in blocking-IO mode.
  1670. @item offset
  1671. offset to start reading from in the file
  1672. @end table
  1673. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1674. @end deftypefun
  1675. @deftypefun {struct MHD_Response *} MHD_create_response_from_buffer (size_t size, void *data, enum MHD_ResponseMemoryMode mode)
  1676. Create a response object. The response object can be extended with
  1677. header information and then it can be used any number of times.
  1678. @table @var
  1679. @item size
  1680. size of the data portion of the response;
  1681. @item buffer
  1682. the data itself;
  1683. @item mode
  1684. memory management options for buffer; use
  1685. MHD_RESPMEM_PERSISTENT if the buffer is static/global memory,
  1686. use MHD_RESPMEM_MUST_FREE if the buffer is heap-allocated and
  1687. should be freed by MHD and MHD_RESPMEM_MUST_COPY if the
  1688. buffer is in transient memory (i.e. on the stack) and must
  1689. be copied by MHD;
  1690. @end table
  1691. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1692. @end deftypefun
  1693. @deftypefun {struct MHD_Response *} MHD_create_response_from_buffer_with_free_callback (size_t size, void *data, MHD_ContentReaderFreeCallback crfc)
  1694. Create a response object. The buffer at the end must be free'd
  1695. by calling the @var{crfc} function.
  1696. @table @var
  1697. @item size
  1698. size of the data portion of the response;
  1699. @item buffer
  1700. the data itself;
  1701. @item crfc
  1702. function to call at the end to free memory allocated at @var{buffer}.
  1703. @end table
  1704. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1705. @end deftypefun
  1706. @deftypefun {struct MHD_Response *} MHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy)
  1707. Create a response object. The response object can be extended with
  1708. header information and then it can be used any number of times.
  1709. This function is deprecated, use @code{MHD_create_response_from_buffer} instead.
  1710. @table @var
  1711. @item size
  1712. size of the data portion of the response;
  1713. @item data
  1714. the data itself;
  1715. @item must_free
  1716. if true: MHD should free data when done;
  1717. @item must_copy
  1718. if true: MHD allocates a block of memory and use it to make a copy of
  1719. @var{data} embedded in the returned @code{MHD_Response} structure;
  1720. handling of the embedded memory is responsibility of MHD; @var{data}
  1721. can be released anytime after this call returns.
  1722. @end table
  1723. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1724. @end deftypefun
  1725. Example: create a response from a statically allocated string:
  1726. @example
  1727. const char * data = "<html><body><p>Error!</p></body></html>";
  1728. struct MHD_Connection * connection = ...;
  1729. struct MHD_Response * response;
  1730. response = MHD_create_response_from_buffer (strlen(data), data,
  1731. MHD_RESPMEM_PERSISTENT);
  1732. MHD_queue_response(connection, 404, response);
  1733. MHD_destroy_response(response);
  1734. @end example
  1735. @deftypefun {struct MHD_Response *} MHD_create_response_from_iovec (const struct MHD_IoVec *iov, int iovcnt, MHD_ContentReaderFreeCallback crfc, void *cls)
  1736. Create a response object from an array of memory buffers.
  1737. The response object can be extended with header information and then be used
  1738. any number of times.
  1739. @table @var
  1740. @item iov
  1741. the array for response data buffers, an internal copy of this will be made; however, note that the data pointed to by the @var{iov} is not copied and must be preserved unchanged at the given locations until the response is no longer in use and the @var{crfc} is called;
  1742. @item iovcnt
  1743. the number of elements in @var{iov};
  1744. @item crfc
  1745. the callback to call to free resources associated with @var{iov};
  1746. @item cls
  1747. the argument to @var{crfc};
  1748. @end table
  1749. Return @code{NULL} on error (i.e. invalid arguments, out of memory).
  1750. @end deftypefun
  1751. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1752. @c ------------------------------------------------------------
  1753. @node microhttpd-response headers
  1754. @section Adding headers to a response
  1755. @deftypefun enum MHD_Result MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content)
  1756. Add a header line to the response. The strings referenced by
  1757. @var{header} and @var{content} must be zero-terminated and they are
  1758. duplicated into memory blocks embedded in @var{response}.
  1759. Notice that the strings must not hold newlines, carriage returns or tab
  1760. chars.
  1761. MHD_add_response_header() prevents applications from setting a
  1762. ``Transfer-Encoding'' header to values other than ``identity'' or
  1763. ``chunked'' as other transfer encodings are not supported by MHD. Note
  1764. that usually MHD will pick the transfer encoding correctly
  1765. automatically, but applications can use the header to force a
  1766. particular behavior.
  1767. MHD_add_response_header() also prevents applications from setting a
  1768. ``Content-Length'' header. MHD will automatically set a correct
  1769. ``Content-Length'' header if it is possible and allowed.
  1770. Return @code{MHD_NO} on error (i.e. invalid header or content format or
  1771. memory allocation error).
  1772. @end deftypefun
  1773. @deftypefun enum MHD_Result MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
  1774. Add a footer line to the response. The strings referenced by
  1775. @var{footer} and @var{content} must be zero-terminated and they are
  1776. duplicated into memory blocks embedded in @var{response}.
  1777. Notice that the strings must not hold newlines, carriage returns or tab
  1778. chars. You can add response footers at any time before signalling the
  1779. end of the response to MHD (not just before calling 'MHD_queue_response').
  1780. Footers are useful for adding cryptographic checksums to the reply or to
  1781. signal errors encountered during data generation. This call was introduced
  1782. in MHD 0.9.3.
  1783. Return @code{MHD_NO} on error (i.e. invalid header or content format or
  1784. memory allocation error).
  1785. @end deftypefun
  1786. @deftypefun enum MHD_Result MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content)
  1787. Delete a header (or footer) line from the response. Return @code{MHD_NO} on error
  1788. (arguments are invalid or no such header known).
  1789. @end deftypefun
  1790. @c ------------------------------------------------------------
  1791. @node microhttpd-response options
  1792. @section Setting response options
  1793. @deftypefun enum MHD_Result MHD_set_response_options (struct MHD_Response *response, enum MHD_ResponseFlags flags, ...)
  1794. Set special flags and options for a response.
  1795. Calling this functions sets the given flags and options for the response.
  1796. @table @var
  1797. @item response
  1798. which response should be modified;
  1799. @item flags
  1800. flags to set for the response;
  1801. @end table
  1802. Additional arguments are a list of options (type-value pairs,
  1803. terminated with @code{MHD_RO_END}). It is mandatory to use
  1804. @code{MHD_RO_END} as last argument, even when there are no
  1805. additional arguments.
  1806. Return @code{MHD_NO} on error, @code{MHD_YES} on success.
  1807. @end deftypefun
  1808. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1809. @c ------------------------------------------------------------
  1810. @node microhttpd-response inspect
  1811. @section Inspecting a response object
  1812. @deftypefun int MHD_get_response_headers (struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
  1813. Get all of the headers added to a response.
  1814. Invoke the @var{iterator} callback for each header in the response,
  1815. using @var{iterator_cls} as first argument. Return number of entries
  1816. iterated over. @var{iterator} can be @code{NULL}: in this case the function
  1817. just counts headers.
  1818. @var{iterator} should not modify the its key and value arguments, unless
  1819. we know what we are doing.
  1820. @end deftypefun
  1821. @deftypefun {const char *} MHD_get_response_header (struct MHD_Response *response, const char *key)
  1822. Find and return a pointer to the value of a particular header from the
  1823. response. @var{key} must reference a zero-terminated string
  1824. representing the header to look for. The search is case sensitive.
  1825. Return @code{NULL} if header does not exist or @var{key} is @code{NULL}.
  1826. We should not modify the value, unless we know what we are doing.
  1827. @end deftypefun
  1828. @c ------------------------------------------------------------
  1829. @node microhttpd-response upgrade
  1830. @section Creating a response for protocol upgrades
  1831. @cindex WebSockets
  1832. @cindex Upgrade
  1833. @cindex HTTP2
  1834. @cindex RFC2817
  1835. With RFC 2817 a mechanism to switch protocols within HTTP was
  1836. introduced. Here, a client sends a request with a ``Connection:
  1837. Upgrade'' header. The server responds with a ``101 Switching
  1838. Protocols'' response header, after which the two parties begin to
  1839. speak a different (non-HTTP) protocol over the TCP connection.
  1840. This mechanism is used for upgrading HTTP 1.1 connections to HTTP2 or
  1841. HTTPS, as well as for implementing WebSockets. Which protocol
  1842. upgrade is performed is negotiated between server and client in
  1843. additional headers, in particular the ``Upgrade'' header.
  1844. MHD supports switching protocols using this mechanism only if the
  1845. @code{MHD_ALLOW_SUSPEND_RESUME} flag has been set when starting
  1846. the daemon. If this flag has been set, applications can upgrade
  1847. a connection by queueing a response (using the
  1848. @code{MHD_HTTP_SWITCHING_PROTOCOLS} status code) which must
  1849. have been created with the following function:
  1850. @deftypefun enum MHD_Result MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls)
  1851. Create a response suitable for switching protocols. Returns @code{MHD_YES} on success. @code{upgrade_handler} must not be @code{NULL}.
  1852. When creating this type of response, the ``Connection: Upgrade''
  1853. header will be set automatically for you. MHD requires that you
  1854. additionally set an ``Upgrade:'' header. The ``Upgrade'' header
  1855. must simply exist, the specific value is completely up to the
  1856. application.
  1857. @end deftypefun
  1858. The @code{upgrade_handler} argument to the above has the following type:
  1859. @deftypefn {Function Pointer} void {*MHD_UpgradeHandler} (void *cls, struct MHD_Connection *connection, const char *extra_in, size_t extra_in_size, MHD_socket sock, struct MHD_UpgradeResponseHandle *urh)
  1860. This function will be called once MHD has transmitted the header of the response to the connection that is being upgraded. At this point, the application is expected to take over the socket @code{sock} and speak the non-HTTP protocol to which the connection was upgraded. MHD will no longer use the socket; this includes handling timeouts. The application must call @code{MHD_upgrade_action} with an upgrade action of @code{MHD_UPGRADE_ACTION_CLOSE} when it is done processing the connection to close the socket. The application must not call @code{MHD_stop_daemon} on the respective daemon as long as it is still handling the connection. The arguments given to the @code{upgrade_handler} have the following meaning:
  1861. @table @var
  1862. @item cls
  1863. matches the @code{upgrade_handler_cls} that was given to @code{MHD_create_response_for_upgrade}
  1864. @item connection
  1865. identifies the connection that is being upgraded;
  1866. @item con_cls
  1867. last value left in `*con_cls` in the `MHD_AccessHandlerCallback`
  1868. @item extra_in
  1869. buffer of bytes MHD read ``by accident'' from the socket already. This can happen if the client eagerly transmits more than just the HTTP request. The application should treat these as if it had read them from the socket.
  1870. @item extra_in_size
  1871. number of bytes in @code{extra_in}
  1872. @item sock
  1873. the socket which the application can now use directly for some bi-directional communication with the client. The application can henceforth use @code{recv()} and @code{send()} or @code{read()} and @code{write()} system calls on the socket. However, @code{ioctl()} and @code{setsockopt()} functions will not work as expected when using HTTPS. Such operations may be supported in the future via @code{MHD_upgrade_action}. Most importantly, the application must never call @code{close()} on this socket. Closing the socket must be done using @code{MHD_upgrade_action}. However, while close is forbidden, the application may call @code{shutdown()} on the socket.
  1874. @item urh
  1875. argument for calls to @code{MHD_upgrade_action}. Applications must eventually use this function to perform the @code{close()} action on the socket.
  1876. @end table
  1877. @end deftypefn
  1878. @deftypefun enum MHD_Result MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, enum MHD_UpgradeAction action, ...)
  1879. Perform special operations related to upgraded connections.
  1880. @table @var
  1881. @item urh
  1882. identifies the upgraded connection to perform an action on
  1883. @item action
  1884. specifies the action to perform; further arguments to the function depend on the specifics of the action.
  1885. @end table
  1886. @end deftypefun
  1887. @deftp {Enumeration} MHD_UpgradeAction
  1888. Set of actions to be performed on upgraded connections. Passed as an argument to
  1889. @code{MHD_upgrade_action()}.
  1890. @table @code
  1891. @item MHD_UPGRADE_ACTION_CLOSE
  1892. Closes the connection. Must be called once the application is done with the client. Takes no additional arguments.
  1893. @item MHD_UPGRADE_ACTION_CORK_ON
  1894. Enable corking on the underlying socket.
  1895. @item MHD_UPGRADE_ACTION_CORK_OFF
  1896. Disable corking on the underlying socket.
  1897. @end table
  1898. @end deftp
  1899. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1900. @c ------------------------------------------------------------
  1901. @node microhttpd-flow
  1902. @chapter Flow control.
  1903. @noindent
  1904. Sometimes it may be possible that clients upload data faster
  1905. than an application can process it, or that an application
  1906. needs an extended period of time to generate a response.
  1907. If @code{MHD_USE_THREAD_PER_CONNECTION} is used, applications
  1908. can simply deal with this by performing their logic within the
  1909. thread and thus effectively blocking connection processing
  1910. by MHD. In all other modes, blocking logic must not be
  1911. placed within the callbacks invoked by MHD as this would also
  1912. block processing of other requests, as a single thread may be
  1913. responsible for tens of thousands of connections.
  1914. Instead, applications using thread modes other than
  1915. @code{MHD_USE_THREAD_PER_CONNECTION} should use the
  1916. following functions to perform flow control.
  1917. @deftypefun enum MHD_Result MHD_suspend_connection (struct MHD_Connection *connection)
  1918. Suspend handling of network data for a given connection. This can
  1919. be used to dequeue a connection from MHD's event loop (external
  1920. select, internal select or thread pool; not applicable to
  1921. thread-per-connection!) for a while.
  1922. If you use this API in conjunction with a internal select or a
  1923. thread pool, you must set the option @code{MHD_ALLOW_SUSPEND_RESUME} to
  1924. ensure that a resumed connection is immediately processed by MHD.
  1925. Suspended connections continue to count against the total number of
  1926. connections allowed (per daemon, as well as per IP, if such limits
  1927. are set). Suspended connections will NOT time out; timeouts will
  1928. restart when the connection handling is resumed. While a
  1929. connection is suspended, MHD will not detect disconnects by the
  1930. client.
  1931. The only safe time to suspend a connection is from the
  1932. @code{MHD_AccessHandlerCallback} or from the respective
  1933. @code{MHD_ContentReaderCallback} (but in this case the
  1934. response object must not be shared among multiple
  1935. connections).
  1936. Finally, it is an API violation to call @code{MHD_stop_daemon} while
  1937. having suspended connections (this will at least create memory and
  1938. socket leaks or lead to undefined behavior). You must explicitly
  1939. resume all connections before stopping the daemon.
  1940. @table @var
  1941. @item connection
  1942. the connection to suspend
  1943. @end table
  1944. @end deftypefun
  1945. @deftypefun enum MHD_Result MHD_resume_connection (struct MHD_Connection *connection)
  1946. Resume handling of network data for suspended connection. It is safe
  1947. to resume a suspended connection at any time. Calling this function
  1948. on a connection that was not previously suspended will result in
  1949. undefined behavior.
  1950. If you are using this function in ``external'' select mode, you must
  1951. make sure to run @code{MHD_run} afterwards (before again calling
  1952. @code{MHD_get_fdset}), as otherwise the change may not be reflected in
  1953. the set returned by @code{MHD_get_fdset} and you may end up with a
  1954. connection that is stuck until the next network activity.
  1955. You can check whether a connection is currently suspended using
  1956. @code{MHD_get_connection_info} by querying for
  1957. @code{MHD_CONNECTION_INFO_CONNECTION_SUSPENDED}.
  1958. @table @var
  1959. @item connection
  1960. the connection to resume
  1961. @end table
  1962. @end deftypefun
  1963. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1964. @c ------------------------------------------------------------
  1965. @node microhttpd-dauth
  1966. @chapter Utilizing Authentication
  1967. @noindent
  1968. MHD support three types of client authentication.
  1969. Basic authentication uses a simple authentication method based
  1970. on BASE64 algorithm. Username and password are exchanged in clear
  1971. between the client and the server, so this method must only be used
  1972. for non-sensitive content or when the session is protected with https.
  1973. When using basic authentication MHD will have access to the clear
  1974. password, possibly allowing to create a chained authentication
  1975. toward an external authentication server.
  1976. Digest authentication uses a one-way authentication method based
  1977. on MD5 hash algorithm. Only the hash will transit over the network,
  1978. hence protecting the user password. The nonce will prevent replay
  1979. attacks. This method is appropriate for general use, especially
  1980. when https is not used to encrypt the session.
  1981. Client certificate authentication uses a X.509 certificate from
  1982. the client. This is the strongest authentication mechanism but it
  1983. requires the use of HTTPS. Client certificate authentication can
  1984. be used simultaneously with Basic or Digest Authentication in order
  1985. to provide a two levels authentication (like for instance separate
  1986. machine and user authentication). A code example for using
  1987. client certificates is presented in the MHD tutorial.
  1988. @menu
  1989. * microhttpd-dauth basic:: Using Basic Authentication.
  1990. * microhttpd-dauth digest:: Using Digest Authentication.
  1991. @end menu
  1992. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1993. @c ------------------------------------------------------------
  1994. @node microhttpd-dauth basic
  1995. @section Using Basic Authentication
  1996. @deftypefun {void} MHD_free (void *ptr)
  1997. Free the memory given at @code{ptr}. Used to free data structures allocated by MHD. Calls @code{free(ptr)}.
  1998. @end deftypefun
  1999. @deftypefun {char *} MHD_basic_auth_get_username_password (struct MHD_Connection *connection, char** password)
  2000. Get the username and password from the basic authorization header sent by the client.
  2001. Return @code{NULL} if no username could be found, a pointer to the username if found.
  2002. If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
  2003. @var{password} reference a buffer to store the password. It can be @code{NULL}.
  2004. If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
  2005. @end deftypefun
  2006. @deftypefun {enum MHD_Result} MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, const char *realm, struct MHD_Response *response)
  2007. Queues a response to request basic authentication from the client.
  2008. Return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
  2009. @var{realm} must reference to a zero-terminated string representing the realm.
  2010. @var{response} a response structure to specify what shall be presented to the
  2011. client with a 401 HTTP status.
  2012. @end deftypefun
  2013. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2014. @c ------------------------------------------------------------
  2015. @node microhttpd-dauth digest
  2016. @section Using Digest Authentication
  2017. MHD supports MD5 (deprecated by IETF) and SHA-256 hash algorithms
  2018. for digest authentication. The @code{MHD_DigestAuthAlgorithm} enumeration
  2019. is used to specify which algorithm should be used.
  2020. @deftp {Enumeration} MHD_DigestAuthAlgorithm
  2021. Which digest algorithm should be used. Must be used consistently.
  2022. @table @code
  2023. @item MHD_DIGEST_ALG_AUTO
  2024. Have MHD pick an algorithm currently considered secure. For now defaults to SHA-256.
  2025. @item MHD_DIGEST_ALG_MD5
  2026. Force use of (deprecated, ancient, insecure) MD5.
  2027. @item MHD_DIGEST_ALG_SHA256
  2028. Force use of SHA-256.
  2029. @end table
  2030. @end deftp
  2031. @deftypefun {char *} MHD_digest_auth_get_username (struct MHD_Connection *connection)
  2032. Find and return a pointer to the username value from the request header.
  2033. Return @code{NULL} if the value is not found or header does not exist.
  2034. If returned value is not @code{NULL}, the value must be @code{MHD_free()}'ed.
  2035. @end deftypefun
  2036. @deftypefun int MHD_digest_auth_check2 (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo)
  2037. Checks if the provided values in the WWW-Authenticate header are valid
  2038. and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
  2039. @var{realm} must reference to a zero-terminated string representing the realm.
  2040. @var{username} must reference to a zero-terminated string representing the username,
  2041. it is usually the returned value from MHD_digest_auth_get_username.
  2042. @var{password} must reference to a zero-terminated string representing the password,
  2043. most probably it will be the result of a lookup of the username against a local database.
  2044. @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
  2045. Most of the time it is sound to specify 300 seconds as its values.
  2046. @var{algo} which digest algorithm should we use.
  2047. @end deftypefun
  2048. @deftypefun int MHD_digest_auth_check (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout)
  2049. Checks if the provided values in the WWW-Authenticate header are valid
  2050. and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
  2051. Deprecated, use @code{MHD_digest_auth_check2} instead.
  2052. @var{realm} must reference to a zero-terminated string representing the realm.
  2053. @var{username} must reference to a zero-terminated string representing the username,
  2054. it is usually the returned value from MHD_digest_auth_get_username.
  2055. @var{password} must reference to a zero-terminated string representing the password,
  2056. most probably it will be the result of a lookup of the username against a local database.
  2057. @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
  2058. Most of the time it is sound to specify 300 seconds as its values.
  2059. @end deftypefun
  2060. @deftypefun int MHD_digest_auth_check_digest2 (struct MHD_Connection *connection, const char *realm, const char *username, const uint8_t *digest, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo)
  2061. Checks if the provided values in the WWW-Authenticate header are valid
  2062. and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
  2063. @var{realm} must reference to a zero-terminated string representing the realm.
  2064. @var{username} must reference to a zero-terminated string representing the username,
  2065. it is usually the returned value from MHD_digest_auth_get_username.
  2066. @var{digest} pointer to the binary MD5 sum for the precalculated hash value ``userame:realm:password''. The size must match the selected @var{algo}!
  2067. @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
  2068. Most of the time it is sound to specify 300 seconds as its values.
  2069. @var{algo} digest authentication algorithm to use.
  2070. @end deftypefun
  2071. @deftypefun int MHD_digest_auth_check_digest (struct MHD_Connection *connection, const char *realm, const char *username, const unsigned char digest[MHD_MD5_DIGEST_SIZE], unsigned int nonce_timeout)
  2072. Checks if the provided values in the WWW-Authenticate header are valid
  2073. and sound according to RFC2716. If valid return @code{MHD_YES}, otherwise return @code{MHD_NO}.
  2074. Deprecated, use @code{MHD_digest_auth_check_digest2} instead.
  2075. @var{realm} must reference to a zero-terminated string representing the realm.
  2076. @var{username} must reference to a zero-terminated string representing the username,
  2077. it is usually the returned value from MHD_digest_auth_get_username.
  2078. @var{digest} pointer to the binary MD5 sum for the precalculated hash value ``userame:realm:password'' of @code{MHD_MD5_DIGEST_SIZE} bytes.
  2079. @var{nonce_timeout} is the amount of time in seconds for a nonce to be invalid.
  2080. Most of the time it is sound to specify 300 seconds as its values.
  2081. @end deftypefun
  2082. @deftypefun enum MHD_Result MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale, enum MHD_DigestAuthAlgorithm algo)
  2083. Queues a response to request authentication from the client,
  2084. return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
  2085. @var{realm} must reference to a zero-terminated string representing the realm.
  2086. @var{opaque} must reference to a zero-terminated string representing a value
  2087. that gets passed to the client and expected to be passed again to the server
  2088. as-is. This value can be a hexadecimal or base64 string.
  2089. @var{response} a response structure to specify what shall be presented to the
  2090. client with a 401 HTTP status.
  2091. @var{signal_stale} a value that signals "stale=true" in the response header to
  2092. indicate the invalidity of the nonce and no need to ask for authentication
  2093. parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new
  2094. nonce, @code{MHD_NO} to ask for authentication parameters.
  2095. @var{algo} which digest algorithm should we use. The same algorithm
  2096. must then be selected when checking digests received from clients!
  2097. @end deftypefun
  2098. @deftypefun enum MHD_Result MHD_queue_auth_fail_response (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale)
  2099. Queues a response to request authentication from the client,
  2100. return @code{MHD_YES} if successful, otherwise @code{MHD_NO}.
  2101. @var{realm} must reference to a zero-terminated string representing the realm.
  2102. @var{opaque} must reference to a zero-terminated string representing a value
  2103. that gets passed to the client and expected to be passed again to the server
  2104. as-is. This value can be a hexadecimal or base64 string.
  2105. @var{response} a response structure to specify what shall be presented to the
  2106. client with a 401 HTTP status.
  2107. @var{signal_stale} a value that signals "stale=true" in the response header to
  2108. indicate the invalidity of the nonce and no need to ask for authentication
  2109. parameters and only a new nonce gets generated. @code{MHD_YES} to generate a new
  2110. nonce, @code{MHD_NO} to ask for authentication parameters.
  2111. @end deftypefun
  2112. Example: handling digest authentication requests and responses.
  2113. @example
  2114. #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
  2115. #define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
  2116. #define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
  2117. static int
  2118. ahc_echo (void *cls,
  2119. struct MHD_Connection *connection,
  2120. const char *url,
  2121. const char *method,
  2122. const char *version,
  2123. const char *upload_data, size_t *upload_data_size, void **ptr)
  2124. @{
  2125. struct MHD_Response *response;
  2126. char *username;
  2127. const char *password = "testpass";
  2128. const char *realm = "test@@example.com";
  2129. int ret;
  2130. username = MHD_digest_auth_get_username (connection);
  2131. if (username == NULL)
  2132. @{
  2133. response = MHD_create_response_from_buffer(strlen (DENIED),
  2134. DENIED,
  2135. MHD_RESPMEM_PERSISTENT);
  2136. ret = MHD_queue_auth_fail_response2 (connection,
  2137. realm,
  2138. OPAQUE,
  2139. response,
  2140. MHD_NO,
  2141. MHD_DIGEST_ALG_SHA256);
  2142. MHD_destroy_response(response);
  2143. return ret;
  2144. @}
  2145. ret = MHD_digest_auth_check2 (connection,
  2146. realm,
  2147. username,
  2148. password,
  2149. 300,
  2150. MHD_DIGEST_ALG_SHA256);
  2151. free(username);
  2152. if ( (ret == MHD_INVALID_NONCE) ||
  2153. (ret == MHD_NO) )
  2154. @{
  2155. response = MHD_create_response_from_buffer(strlen (DENIED),
  2156. DENIED,
  2157. MHD_RESPMEM_PERSISTENT);
  2158. if (NULL == response)
  2159. return MHD_NO;
  2160. ret = MHD_queue_auth_fail_response2 (connection,
  2161. realm,
  2162. OPAQUE,
  2163. response,
  2164. (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO,
  2165. MHD_DIGEST_ALG_SHA256);
  2166. MHD_destroy_response(response);
  2167. return ret;
  2168. @}
  2169. response = MHD_create_response_from_buffer (strlen(PAGE),
  2170. PAGE,
  2171. MHD_RESPMEM_PERSISTENT);
  2172. ret = MHD_queue_response (connection,
  2173. MHD_HTTP_OK,
  2174. response);
  2175. MHD_destroy_response(response);
  2176. return ret;
  2177. @}
  2178. @end example
  2179. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2180. @c ------------------------------------------------------------
  2181. @node microhttpd-post
  2182. @chapter Adding a @code{POST} processor
  2183. @cindex POST method
  2184. @menu
  2185. * microhttpd-post api:: Programming interface for the
  2186. @code{POST} processor.
  2187. @end menu
  2188. @noindent
  2189. MHD provides the post processor API to make it easier for applications to
  2190. parse the data of a client's @code{POST} request: the
  2191. @code{MHD_AccessHandlerCallback} will be invoked multiple times to
  2192. process data as it arrives; at each invocation a new chunk of data must
  2193. be processed. The arguments @var{upload_data} and @var{upload_data_size}
  2194. are used to reference the chunk of data.
  2195. When @code{MHD_AccessHandlerCallback} is invoked for a new connection:
  2196. its @code{*@var{con_cls}} argument is set to @code{NULL}. When @code{POST}
  2197. data comes in the upload buffer it is @strong{mandatory} to use the
  2198. @var{con_cls} to store a reference to per-connection data. The fact
  2199. that the pointer was initially @code{NULL} can be used to detect that
  2200. this is a new request.
  2201. One method to detect that a new connection was established is
  2202. to set @code{*con_cls} to an unused integer:
  2203. @example
  2204. int
  2205. access_handler (void *cls,
  2206. struct MHD_Connection * connection,
  2207. const char *url,
  2208. const char *method, const char *version,
  2209. const char *upload_data, size_t *upload_data_size,
  2210. void **con_cls)
  2211. @{
  2212. static int old_connection_marker;
  2213. int new_connection = (NULL == *con_cls);
  2214. if (new_connection)
  2215. @{
  2216. /* new connection with POST */
  2217. *con_cls = &old_connection_marker;
  2218. @}
  2219. ...
  2220. @}
  2221. @end example
  2222. @noindent
  2223. In contrast to the previous example, for @code{POST} requests in particular,
  2224. it is more common to use the value of @code{*con_cls} to keep track of
  2225. actual state used during processing, such as the post processor (or a
  2226. struct containing a post processor):
  2227. @example
  2228. int
  2229. access_handler (void *cls,
  2230. struct MHD_Connection * connection,
  2231. const char *url,
  2232. const char *method, const char *version,
  2233. const char *upload_data, size_t *upload_data_size,
  2234. void **con_cls)
  2235. @{
  2236. struct MHD_PostProcessor * pp = *con_cls;
  2237. if (pp == NULL)
  2238. @{
  2239. pp = MHD_create_post_processor(connection, ...);
  2240. *con_cls = pp;
  2241. return MHD_YES;
  2242. @}
  2243. if (*upload_data_size)
  2244. @{
  2245. MHD_post_process(pp, upload_data, *upload_data_size);
  2246. *upload_data_size = 0;
  2247. return MHD_YES;
  2248. @}
  2249. else
  2250. @{
  2251. MHD_destroy_post_processor(pp);
  2252. return MHD_queue_response(...);
  2253. @}
  2254. @}
  2255. @end example
  2256. Note that the callback from @code{MHD_OPTION_NOTIFY_COMPLETED}
  2257. should be used to destroy the post processor. This cannot be
  2258. done inside of the access handler since the connection may not
  2259. always terminate normally.
  2260. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2261. @c ------------------------------------------------------------
  2262. @node microhttpd-post api
  2263. @section Programming interface for the @code{POST} processor
  2264. @cindex POST method
  2265. @deftypefun {struct MHD_PostProcessor *} MHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iterator, void *iterator_cls)
  2266. Create a PostProcessor. A PostProcessor can be used to (incrementally)
  2267. parse the data portion of a @code{POST} request.
  2268. @table @var
  2269. @item connection
  2270. the connection on which the @code{POST} is happening (used to determine
  2271. the @code{POST} format);
  2272. @item buffer_size
  2273. maximum number of bytes to use for internal buffering (used only for the
  2274. parsing, specifically the parsing of the keys). A tiny value (256-1024)
  2275. should be sufficient; do @strong{NOT} use a value smaller than 256;
  2276. for good performance, use 32k or 64k (i.e. 65536).
  2277. @item iterator
  2278. iterator to be called with the parsed data; must @strong{NOT} be
  2279. @code{NULL};
  2280. @item iterator_cls
  2281. custom value to be used as first argument to @var{iterator}.
  2282. @end table
  2283. Return @code{NULL} on error (out of memory, unsupported encoding), otherwise
  2284. a PP handle.
  2285. @end deftypefun
  2286. @deftypefun enum MHD_Result MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
  2287. Parse and process @code{POST} data. Call this function when @code{POST}
  2288. data is available (usually during an @code{MHD_AccessHandlerCallback})
  2289. with the @var{upload_data} and @var{upload_data_size}. Whenever
  2290. possible, this will then cause calls to the
  2291. @code{MHD_IncrementalKeyValueIterator}.
  2292. @table @var
  2293. @item pp
  2294. the post processor;
  2295. @item post_data
  2296. @var{post_data_len} bytes of @code{POST} data;
  2297. @item post_data_len
  2298. length of @var{post_data}.
  2299. @end table
  2300. Return @code{MHD_YES} on success, @code{MHD_NO} on error
  2301. (out-of-memory, iterator aborted, parse error).
  2302. @end deftypefun
  2303. @deftypefun enum MHD_Result MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
  2304. Release PostProcessor resources. After this function is being called,
  2305. the PostProcessor is guaranteed to no longer call its iterator. There
  2306. is no special call to the iterator to indicate the end of the post processing
  2307. stream. After destroying the PostProcessor, the programmer should
  2308. perform any necessary work to complete the processing of the iterator.
  2309. Return @code{MHD_YES} if processing completed nicely, @code{MHD_NO}
  2310. if there were spurious characters or formatting problems with
  2311. the post request. It is common to ignore the return value
  2312. of this function.
  2313. @end deftypefun
  2314. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2315. @c ------------------------------------------------------------
  2316. @node microhttpd-info
  2317. @chapter Obtaining and modifying status information.
  2318. @menu
  2319. * microhttpd-info daemon:: State information about an MHD daemon
  2320. * microhttpd-info conn:: State information about a connection
  2321. * microhttpd-option conn:: Modify per-connection options
  2322. @end menu
  2323. @c ------------------------------------------------------------
  2324. @node microhttpd-info daemon
  2325. @section Obtaining state information about an MHD daemon
  2326. @deftypefun {const union MHD_DaemonInfo *} MHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType infoType, ...)
  2327. Obtain information about the given daemon. This function
  2328. is currently not fully implemented.
  2329. @table @var
  2330. @item daemon
  2331. the daemon about which information is desired;
  2332. @item infoType
  2333. type of information that is desired
  2334. @item ...
  2335. additional arguments about the desired information (depending on
  2336. infoType)
  2337. @end table
  2338. Returns a union with the respective member (depending on
  2339. infoType) set to the desired information), or @code{NULL}
  2340. in case the desired information is not available or
  2341. applicable.
  2342. @end deftypefun
  2343. @deftp {Enumeration} MHD_DaemonInfoType
  2344. Values of this enum are used to specify what
  2345. information about a daemon is desired.
  2346. @table @code
  2347. @item MHD_DAEMON_INFO_KEY_SIZE
  2348. Request information about the key size for a particular cipher
  2349. algorithm. The cipher algorithm should be passed as an extra argument
  2350. (of type 'enum MHD_GNUTLS_CipherAlgorithm'). No longer supported,
  2351. using this value will cause @code{MHD_get_daemon_info} to return NULL.
  2352. @item MHD_DAEMON_INFO_MAC_KEY_SIZE
  2353. Request information about the key size for a particular cipher
  2354. algorithm. The cipher algorithm should be passed as an extra argument
  2355. (of type 'enum MHD_GNUTLS_HashAlgorithm'). No longer supported,
  2356. using this value will cause @code{MHD_get_daemon_info} to return NULL.
  2357. @item MHD_DAEMON_INFO_LISTEN_FD
  2358. @cindex listen
  2359. Request the file-descriptor number that MHD is using to listen to the
  2360. server socket. This can be useful if no port
  2361. was specified and a client needs to learn what port
  2362. is actually being used by MHD.
  2363. No extra arguments should be passed.
  2364. @item MHD_DAEMON_INFO_EPOLL_FD
  2365. @cindex epoll
  2366. Request the file-descriptor number that MHD is using for epoll. If
  2367. the build is not supporting epoll, NULL is returned; if we are using a
  2368. thread pool or this daemon was not started with
  2369. @code{MHD_USE_EPOLL}, (a pointer to) -1 is returned. If we are
  2370. using @code{MHD_USE_INTERNAL_POLLING_THREAD} or are in 'external' select mode, the
  2371. internal epoll FD is returned. This function must be used in external
  2372. select mode with epoll to obtain the FD to call epoll on. No extra
  2373. arguments should be passed.
  2374. @item MHD_DAEMON_INFO_CURRENT_CONNECTIONS
  2375. @cindex connection, limiting number of connections
  2376. Request the number of current connections handled by the daemon. No
  2377. extra arguments should be passed and a pointer to a @code{union
  2378. MHD_DaemonInfo} value is returned, with the @code{num_connections}
  2379. member of type @code{unsigned int} set to the number of active
  2380. connections.
  2381. Note that in multi-threaded or internal-select mode, the real number of current
  2382. connections may already be different when @code{MHD_get_daemon_info} returns.
  2383. The number of current connections can be used (even in multi-threaded and
  2384. internal-select mode) after @code{MHD_quiesce_daemon} to detect whether all
  2385. connections have been handled.
  2386. @end table
  2387. @end deftp
  2388. @c ------------------------------------------------------------
  2389. @node microhttpd-info conn
  2390. @section Obtaining state information about a connection
  2391. @deftypefun {const union MHD_ConnectionInfo *} MHD_get_connection_info (struct MHD_Connection *connection, enum MHD_ConnectionInfoType infoType, ...)
  2392. Obtain information about the given connection.
  2393. @table @var
  2394. @item connection
  2395. the connection about which information is desired;
  2396. @item infoType
  2397. type of information that is desired
  2398. @item ...
  2399. additional arguments about the desired information (depending on
  2400. infoType)
  2401. @end table
  2402. Returns a union with the respective member (depending on
  2403. infoType) set to the desired information), or @code{NULL}
  2404. in case the desired information is not available or
  2405. applicable.
  2406. @end deftypefun
  2407. @deftp {Enumeration} MHD_ConnectionInfoType
  2408. Values of this enum are used to specify what information about a
  2409. connection is desired.
  2410. @table @code
  2411. @item MHD_CONNECTION_INFO_CIPHER_ALGO
  2412. What cipher algorithm is being used (HTTPS connections only).
  2413. @code{NULL} is returned for non-HTTPS connections.
  2414. Takes no extra arguments.
  2415. @item MHD_CONNECTION_INFO_PROTOCOL,
  2416. Allows finding out the TLS/SSL protocol used
  2417. (HTTPS connections only).
  2418. @code{NULL} is returned for non-HTTPS connections.
  2419. Takes no extra arguments.
  2420. @item MHD_CONNECTION_INFO_CLIENT_ADDRESS
  2421. Returns information about the address of the client. Returns
  2422. essentially a @code{struct sockaddr **} (since the API returns
  2423. a @code{union MHD_ConnectionInfo *} and that union contains
  2424. a @code{struct sockaddr *}).
  2425. Takes no extra arguments.
  2426. @item MHD_CONNECTION_INFO_GNUTLS_SESSION,
  2427. Takes no extra arguments. Allows access to the underlying GNUtls session,
  2428. including access to the underlying GNUtls client certificate
  2429. (HTTPS connections only). Takes no extra arguments.
  2430. @code{NULL} is returned for non-HTTPS connections.
  2431. Takes no extra arguments.
  2432. @item MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
  2433. Dysfunctional (never implemented, deprecated). Use
  2434. MHD_CONNECTION_INFO_GNUTLS_SESSION to get the @code{gnutls_session_t}
  2435. and then call @code{gnutls_certificate_get_peers()}.
  2436. @item MHD_CONNECTION_INFO_DAEMON
  2437. Returns information about @code{struct MHD_Daemon} which manages
  2438. this connection.
  2439. Takes no extra arguments.
  2440. @item MHD_CONNECTION_INFO_CONNECTION_FD
  2441. Returns the file descriptor (usually a TCP socket) associated with
  2442. this connection (in the ``connect-fd'' member of the returned struct).
  2443. Note that manipulating the descriptor directly can have problematic
  2444. consequences (as in, break HTTP). Applications might use this access
  2445. to manipulate TCP options, for example to set the ``TCP-NODELAY''
  2446. option for COMET-like applications. Note that MHD will set TCP-CORK
  2447. after sending the HTTP header and clear it after finishing the footers
  2448. automatically (if the platform supports it). As the connection
  2449. callbacks are invoked in between, those might be used to set different
  2450. values for TCP-CORK and TCP-NODELAY in the meantime.
  2451. Takes no extra arguments.
  2452. @item MHD_CONNECTION_INFO_CONNECTION_SUSPENDED
  2453. Returns pointer to an integer that is @code{MHD_YES} if the connection
  2454. is currently suspended (and thus can be safely resumed) and
  2455. @code{MHD_NO} otherwise.
  2456. Takes no extra arguments.
  2457. @item MHD_CONNECTION_INFO_SOCKET_CONTEXT
  2458. Returns the client-specific pointer to a @code{void *} that was
  2459. (possibly) set during a @code{MHD_NotifyConnectionCallback} when the
  2460. socket was first accepted. Note that this is NOT the same as the
  2461. @code{con_cls} argument of the @code{MHD_AccessHandlerCallback}. The
  2462. @code{con_cls} is fresh for each HTTP request, while the
  2463. @code{socket_context} is fresh for each socket.
  2464. Takes no extra arguments.
  2465. @item MHD_CONNECTION_INFO_CONNECTION_TIMEOUT
  2466. Returns pointer to an @code{unsigned int} that is the current timeout
  2467. used for the connection (in seconds, 0 for no timeout). Note that
  2468. while suspended connections will not timeout, the timeout value
  2469. returned for suspended connections will be the timeout that the
  2470. connection will use after it is resumed, and thus might not be zero.
  2471. Takes no extra arguments.
  2472. @item MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE
  2473. @cindex performance
  2474. Returns pointer to an @code{size_t} that represents the size of the
  2475. HTTP header received from the client. Only valid after the first callback
  2476. to the access handler.
  2477. Takes no extra arguments.
  2478. @end table
  2479. @end deftp
  2480. @c ------------------------------------------------------------
  2481. @node microhttpd-option conn
  2482. @section Setting custom options for an individual connection
  2483. @cindex timeout
  2484. @deftypefun {int} MHD_set_connection_option (struct MHD_Connection *daemon, enum MHD_CONNECTION_OPTION option, ...)
  2485. Set a custom option for the given connection.
  2486. @table @var
  2487. @item connection
  2488. the connection for which an option should be set or modified;
  2489. @item option
  2490. option to set
  2491. @item ...
  2492. additional arguments for the option (depending on option)
  2493. @end table
  2494. Returns @code{MHD_YES} on success, @code{MHD_NO} for errors
  2495. (i.e. option argument invalid or option unknown).
  2496. @end deftypefun
  2497. @deftp {Enumeration} MHD_CONNECTION_OPTION
  2498. Values of this enum are used to specify which option for a
  2499. connection should be changed.
  2500. @table @code
  2501. @item MHD_CONNECTION_OPTION_TIMEOUT
  2502. Set a custom timeout for the given connection. Specified
  2503. as the number of seconds, given as an @code{unsigned int}. Use
  2504. zero for no timeout.
  2505. @end table
  2506. @end deftp
  2507. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2508. @c ------------------------------------------------------------
  2509. @node microhttpd-util
  2510. @chapter Utility functions.
  2511. @menu
  2512. * microhttpd-util feature:: Test supported MHD features
  2513. * microhttpd-util unescape:: Unescape strings
  2514. @end menu
  2515. @c ------------------------------------------------------------
  2516. @node microhttpd-util feature
  2517. @section Testing for supported MHD features
  2518. @deftp {Enumeration} MHD_FEATURE
  2519. Values of this enum are used to specify what
  2520. information about a daemon is desired.
  2521. @table @code
  2522. @item MHD_FEATURE_MESSAGES
  2523. Get whether messages are supported. If supported then in debug
  2524. mode messages can be printed to stderr or to external logger.
  2525. @item MHD_FEATURE_SSL
  2526. Get whether HTTPS is supported. If supported then flag
  2527. MHD_USE_SSL and options MHD_OPTION_HTTPS_MEM_KEY,
  2528. MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_TRUST,
  2529. MHD_OPTION_HTTPS_MEM_DHPARAMS, MHD_OPTION_HTTPS_CRED_TYPE,
  2530. MHD_OPTION_HTTPS_PRIORITIES can be used.
  2531. @item MHD_FEATURE_HTTPS_CERT_CALLBACK
  2532. Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is
  2533. supported.
  2534. @item MHD_FEATURE_IPv6
  2535. Get whether IPv6 is supported. If supported then flag
  2536. MHD_USE_IPv6 can be used.
  2537. @item MHD_FEATURE_IPv6_ONLY
  2538. Get whether IPv6 without IPv4 is supported. If not supported
  2539. then IPv4 is always enabled in IPv6 sockets and
  2540. flag MHD_USE_DUAL_STACK if always used when MHD_USE_IPv6 is
  2541. specified.
  2542. @item MHD_FEATURE_POLL
  2543. Get whether @code{poll()} is supported. If supported then flag
  2544. MHD_USE_POLL can be used.
  2545. @item MHD_FEATURE_EPOLL
  2546. Get whether @code{epoll()} is supported. If supported then Flags
  2547. MHD_USE_EPOLL and
  2548. MHD_USE_EPOLL_INTERNAL_THREAD can be used.
  2549. @item MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
  2550. Get whether shutdown on listen socket to signal other
  2551. threads is supported. If not supported flag
  2552. MHD_USE_ITC is automatically forced.
  2553. @item MHD_FEATURE_SOCKETPAIR
  2554. Get whether a @code{socketpair()} is used internally instead of
  2555. a @code{pipe()} to signal other threads.
  2556. @item MHD_FEATURE_TCP_FASTOPEN
  2557. Get whether TCP Fast Open is supported. If supported then
  2558. flag MHD_USE_TCP_FASTOPEN and option
  2559. MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used.
  2560. @item MHD_FEATURE_BASIC_AUTH
  2561. Get whether HTTP Basic authorization is supported. If supported
  2562. then functions @code{MHD_basic_auth_get_username_password()} and
  2563. @code{MHD_queue_basic_auth_fail_response()} can be used.
  2564. @item MHD_FEATURE_DIGEST_AUTH
  2565. Get whether HTTP Digest authorization is supported. If
  2566. supported then options MHD_OPTION_DIGEST_AUTH_RANDOM,
  2567. MHD_OPTION_NONCE_NC_SIZE and functions @code{MHD_digest_auth_check()},
  2568. can be used.
  2569. @item MHD_FEATURE_POSTPROCESSOR
  2570. Get whether postprocessor is supported. If supported then
  2571. functions @code{MHD_create_post_processor()},
  2572. @code{MHD_post_process()}, @code{MHD_destroy_post_processor()}
  2573. can be used.
  2574. @item MHD_FEATURE_SENDFILE
  2575. Get whether @code{sendfile()} is supported.
  2576. @end table
  2577. @end deftp
  2578. @deftypefun {int} MHD_is_feature_supported (enum MHD_FEATURE feature)
  2579. Get information about supported MHD features. Indicate that MHD was
  2580. compiled with or without support for particular feature. Some features
  2581. require additional support by the kernel. However, kernel support is not
  2582. checked by this function.
  2583. @table @var
  2584. @item feature
  2585. type of requested information
  2586. @end table
  2587. Returns @code{MHD_YES} if the feature is supported,
  2588. and @code{MHD_NO} if not.
  2589. @end deftypefun
  2590. @c ------------------------------------------------------------
  2591. @node microhttpd-util unescape
  2592. @section Unescape strings
  2593. @deftypefun {size_t} MHD_http_unescape (char *val)
  2594. Process escape sequences ('%HH') Updates val in place; the result
  2595. should be UTF-8 encoded and cannot be larger than the input. The
  2596. result must also still be 0-terminated.
  2597. @table @var
  2598. @item val
  2599. value to unescape (modified in the process), must be
  2600. a 0-terminated UTF-8 string.
  2601. @end table
  2602. Returns length of the resulting val (@code{strlen(val)} may be
  2603. shorter afterwards due to elimination of escape sequences).
  2604. @end deftypefun
  2605. @c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2606. @c **********************************************************
  2607. @c ******************* Appendices *************************
  2608. @c **********************************************************
  2609. @node GNU-LGPL
  2610. @unnumbered GNU-LGPL
  2611. @cindex license
  2612. @include lgpl.texi
  2613. @node eCos License
  2614. @unnumbered eCos License
  2615. @cindex license
  2616. @include ecos.texi
  2617. @node GNU-GPL
  2618. @unnumbered GNU General Public License
  2619. @cindex license
  2620. @include gpl-2.0.texi
  2621. @node GNU-FDL
  2622. @unnumbered GNU-FDL
  2623. @cindex license
  2624. @include fdl-1.3.texi
  2625. @node Concept Index
  2626. @unnumbered Concept Index
  2627. @printindex cp
  2628. @node Function and Data Index
  2629. @unnumbered Function and Data Index
  2630. @printindex fn
  2631. @node Type Index
  2632. @unnumbered Type Index
  2633. @printindex tp
  2634. @bye