microhttpd.h 247 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525
  1. /*
  2. This file is part of libmicrohttpd
  3. Copyright (C) 2006-2021 Christian Grothoff (and other contributing authors)
  4. Copyright (C) 2014-2023 Evgeny Grin (Karlson2k)
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. /**
  18. * @file microhttpd.h
  19. * @brief public interface to libmicrohttpd
  20. * @author Christian Grothoff
  21. * @author Karlson2k (Evgeny Grin)
  22. * @author Chris GauthierDickey
  23. *
  24. * All symbols defined in this header start with MHD. MHD is a small
  25. * HTTP daemon library. As such, it does not have any API for logging
  26. * errors (you can only enable or disable logging to stderr). Also,
  27. * it may not support all of the HTTP features directly, where
  28. * applicable, portions of HTTP may have to be handled by clients of
  29. * the library.
  30. *
  31. * The library is supposed to handle everything that it must handle
  32. * (because the API would not allow clients to do this), such as basic
  33. * connection management; however, detailed interpretations of headers
  34. * -- such as range requests -- and HTTP methods are left to clients.
  35. * The library does understand HEAD and will only send the headers of
  36. * the response and not the body, even if the client supplied a body.
  37. * The library also understands headers that control connection
  38. * management (specifically, "Connection: close" and "Expect: 100
  39. * continue" are understood and handled automatically).
  40. *
  41. * MHD understands POST data and is able to decode certain formats
  42. * (at the moment only "application/x-www-form-urlencoded" and
  43. * "multipart/formdata"). Unsupported encodings and large POST
  44. * submissions may require the application to manually process
  45. * the stream, which is provided to the main application (and thus can be
  46. * processed, just not conveniently by MHD).
  47. *
  48. * The header file defines various constants used by the HTTP protocol.
  49. * This does not mean that MHD actually interprets all of these
  50. * values. The provided constants are exported as a convenience
  51. * for users of the library. MHD does not verify that transmitted
  52. * HTTP headers are part of the standard specification; users of the
  53. * library are free to define their own extensions of the HTTP
  54. * standard and use those with MHD.
  55. *
  56. * All functions are guaranteed to be completely reentrant and
  57. * thread-safe (with the exception of #MHD_set_connection_value,
  58. * which must only be used in a particular context).
  59. *
  60. *
  61. * @defgroup event event-loop control
  62. * MHD API to start and stop the HTTP server and manage the event loop.
  63. * @defgroup response generation of responses
  64. * MHD API used to generate responses.
  65. * @defgroup request handling of requests
  66. * MHD API used to access information about requests.
  67. * @defgroup authentication HTTP authentication
  68. * MHD API related to basic and digest HTTP authentication.
  69. * @defgroup logging logging
  70. * MHD API to mange logging and error handling
  71. * @defgroup specialized misc. specialized functions
  72. * This group includes functions that do not fit into any particular
  73. * category and that are rarely used.
  74. */
  75. #ifndef MHD_MICROHTTPD_H
  76. #define MHD_MICROHTTPD_H
  77. #ifdef __cplusplus
  78. extern "C"
  79. {
  80. #if 0 /* keep Emacsens' auto-indent happy */
  81. }
  82. #endif
  83. #endif
  84. /**
  85. * Current version of the library in packed BCD form.
  86. * @note Version number components are coded as Simple Binary-Coded Decimal
  87. * (also called Natural BCD or BCD 8421). While they are hexadecimal numbers,
  88. * they are parsed as decimal numbers.
  89. * Example: 0x01093001 = 1.9.30-1.
  90. */
  91. #define MHD_VERSION 0x01000100
  92. /* If generic headers don't work on your platform, include headers
  93. which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t',
  94. 'uint8_t', 'uint16_t', 'int32_t', 'uint32_t', 'int64_t', 'uint64_t',
  95. 'struct sockaddr', 'socklen_t', 'fd_set' and "#define MHD_PLATFORM_H" before
  96. including "microhttpd.h". Then the following "standard"
  97. includes won't be used (which might be a good idea, especially
  98. on platforms where they do not exist).
  99. */
  100. #ifndef MHD_PLATFORM_H
  101. #if defined(_WIN32) && ! defined(__CYGWIN__) && \
  102. ! defined(_CRT_DECLARE_NONSTDC_NAMES)
  103. /* Declare POSIX-compatible names */
  104. #define _CRT_DECLARE_NONSTDC_NAMES 1
  105. #endif /* _WIN32 && ! __CYGWIN__ && ! _CRT_DECLARE_NONSTDC_NAMES */
  106. #include <stdarg.h>
  107. #include <stdint.h>
  108. #include <sys/types.h>
  109. #if ! defined(_WIN32) || defined(__CYGWIN__)
  110. #include <unistd.h>
  111. #include <sys/time.h>
  112. #include <sys/socket.h>
  113. #else /* _WIN32 && ! __CYGWIN__ */
  114. #include <ws2tcpip.h>
  115. #if defined(_MSC_FULL_VER) && ! defined(_SSIZE_T_DEFINED)
  116. #define _SSIZE_T_DEFINED
  117. typedef intptr_t ssize_t;
  118. #endif /* !_SSIZE_T_DEFINED */
  119. #endif /* _WIN32 && ! __CYGWIN__ */
  120. #endif
  121. #if defined(__CYGWIN__) && ! defined(_SYS_TYPES_FD_SET)
  122. /* Do not define __USE_W32_SOCKETS under Cygwin! */
  123. #error Cygwin with winsock fd_set is not supported
  124. #endif
  125. #ifdef __has_attribute
  126. #if __has_attribute (flag_enum)
  127. #define _MHD_FLAGS_ENUM __attribute__((flag_enum))
  128. #endif /* flag_enum */
  129. #if __has_attribute (enum_extensibility)
  130. #define _MHD_FIXED_ENUM __attribute__((enum_extensibility (closed)))
  131. #endif /* enum_extensibility */
  132. #endif /* __has_attribute */
  133. #ifndef _MHD_FLAGS_ENUM
  134. #define _MHD_FLAGS_ENUM
  135. #endif /* _MHD_FLAGS_ENUM */
  136. #ifndef _MHD_FIXED_ENUM
  137. #define _MHD_FIXED_ENUM
  138. #endif /* _MHD_FIXED_ENUM */
  139. #define _MHD_FIXED_FLAGS_ENUM _MHD_FIXED_ENUM _MHD_FLAGS_ENUM
  140. /**
  141. * Operational results from MHD calls.
  142. */
  143. enum MHD_Result
  144. {
  145. /**
  146. * MHD result code for "NO".
  147. */
  148. MHD_NO = 0,
  149. /**
  150. * MHD result code for "YES".
  151. */
  152. MHD_YES = 1
  153. } _MHD_FIXED_ENUM;
  154. /**
  155. * Constant used to indicate unknown size (use when
  156. * creating a response).
  157. */
  158. #ifdef UINT64_MAX
  159. #define MHD_SIZE_UNKNOWN UINT64_MAX
  160. #else
  161. #define MHD_SIZE_UNKNOWN ((uint64_t) -1LL)
  162. #endif
  163. #define MHD_CONTENT_READER_END_OF_STREAM ((ssize_t) -1)
  164. #define MHD_CONTENT_READER_END_WITH_ERROR ((ssize_t) -2)
  165. #ifndef _MHD_EXTERN
  166. #if defined(_WIN32) && defined(MHD_W32LIB)
  167. #define _MHD_EXTERN extern
  168. #elif defined(_WIN32) && defined(MHD_W32DLL)
  169. /* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */
  170. #define _MHD_EXTERN __declspec(dllimport)
  171. #else
  172. #define _MHD_EXTERN extern
  173. #endif
  174. #endif
  175. #ifndef MHD_SOCKET_DEFINED
  176. /**
  177. * MHD_socket is type for socket FDs
  178. */
  179. #if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
  180. #define MHD_POSIX_SOCKETS 1
  181. typedef int MHD_socket;
  182. #define MHD_INVALID_SOCKET (-1)
  183. #else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
  184. #define MHD_WINSOCK_SOCKETS 1
  185. #include <winsock2.h>
  186. typedef SOCKET MHD_socket;
  187. #define MHD_INVALID_SOCKET (INVALID_SOCKET)
  188. #endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
  189. #define MHD_SOCKET_DEFINED 1
  190. #endif /* MHD_SOCKET_DEFINED */
  191. /**
  192. * Define MHD_NO_DEPRECATION before including "microhttpd.h" to disable deprecation messages
  193. */
  194. #ifdef MHD_NO_DEPRECATION
  195. #define _MHD_DEPR_MACRO(msg)
  196. #define _MHD_NO_DEPR_IN_MACRO 1
  197. #define _MHD_DEPR_IN_MACRO(msg)
  198. #define _MHD_NO_DEPR_FUNC 1
  199. #define _MHD_DEPR_FUNC(msg)
  200. #endif /* MHD_NO_DEPRECATION */
  201. #ifndef _MHD_DEPR_MACRO
  202. #if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1500
  203. /* VS 2008 or later */
  204. /* Stringify macros */
  205. #define _MHD_INSTRMACRO(a) #a
  206. #define _MHD_STRMACRO(a) _MHD_INSTRMACRO (a)
  207. /* deprecation message */
  208. #define _MHD_DEPR_MACRO(msg) \
  209. __pragma(message (__FILE__ "(" _MHD_STRMACRO ( __LINE__) "): warning: " msg))
  210. #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
  211. #elif defined(__clang__) || defined(__GNUC_PATCHLEVEL__)
  212. /* clang or GCC since 3.0 */
  213. #define _MHD_GCC_PRAG(x) _Pragma(#x)
  214. #if (defined(__clang__) && \
  215. (__clang_major__ + 0 >= 5 || \
  216. (! defined(__apple_build_version__) && \
  217. (__clang_major__ + 0 > 3 || \
  218. (__clang_major__ + 0 == 3 && __clang_minor__ >= 3))))) || \
  219. __GNUC__ + 0 > 4 || (__GNUC__ + 0 == 4 && __GNUC_MINOR__ + 0 >= 8)
  220. /* clang >= 3.3 (or XCode's clang >= 5.0) or
  221. GCC >= 4.8 */
  222. #define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (GCC warning msg)
  223. #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
  224. #else /* older clang or GCC */
  225. /* clang < 3.3, XCode's clang < 5.0, 3.0 <= GCC < 4.8 */
  226. #define _MHD_DEPR_MACRO(msg) _MHD_GCC_PRAG (message msg)
  227. #if (defined(__clang__) && \
  228. (__clang_major__ + 0 > 2 || \
  229. (__clang_major__ + 0 == 2 && __clang_minor__ >= 9))) /* clang >= 2.9 */
  230. /* clang handles inline pragmas better than GCC */
  231. #define _MHD_DEPR_IN_MACRO(msg) _MHD_DEPR_MACRO (msg)
  232. #endif /* clang >= 2.9 */
  233. #endif /* older clang or GCC */
  234. /* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
  235. #endif /* clang || GCC >= 3.0 */
  236. #endif /* !_MHD_DEPR_MACRO */
  237. #ifndef _MHD_DEPR_MACRO
  238. #define _MHD_DEPR_MACRO(msg)
  239. #endif /* !_MHD_DEPR_MACRO */
  240. #ifndef _MHD_DEPR_IN_MACRO
  241. #define _MHD_NO_DEPR_IN_MACRO 1
  242. #define _MHD_DEPR_IN_MACRO(msg)
  243. #endif /* !_MHD_DEPR_IN_MACRO */
  244. #ifndef _MHD_DEPR_FUNC
  245. #if defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1400
  246. /* VS 2005 or later */
  247. #define _MHD_DEPR_FUNC(msg) __declspec(deprecated (msg))
  248. #elif defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1310
  249. /* VS .NET 2003 deprecation does not support custom messages */
  250. #define _MHD_DEPR_FUNC(msg) __declspec(deprecated)
  251. #elif (__GNUC__ + 0 >= 5) || (defined(__clang__) && \
  252. (__clang_major__ + 0 > 2 || \
  253. (__clang_major__ + 0 == 2 && __clang_minor__ >= 9)))
  254. /* GCC >= 5.0 or clang >= 2.9 */
  255. #define _MHD_DEPR_FUNC(msg) __attribute__((deprecated (msg)))
  256. #elif defined(__clang__) || __GNUC__ + 0 > 3 || \
  257. (__GNUC__ + 0 == 3 && __GNUC_MINOR__ + 0 >= 1)
  258. /* 3.1 <= GCC < 5.0 or clang < 2.9 */
  259. /* old GCC-style deprecation does not support custom messages */
  260. #define _MHD_DEPR_FUNC(msg) __attribute__((__deprecated__))
  261. /* #elif defined(SOMEMACRO) */ /* add compiler-specific macros here if required */
  262. #endif /* clang < 2.9 || GCC >= 3.1 */
  263. #endif /* !_MHD_DEPR_FUNC */
  264. #ifndef _MHD_DEPR_FUNC
  265. #define _MHD_NO_DEPR_FUNC 1
  266. #define _MHD_DEPR_FUNC(msg)
  267. #endif /* !_MHD_DEPR_FUNC */
  268. /**
  269. * Not all architectures and `printf()`'s support the `long long` type.
  270. * This gives the ability to replace `long long` with just a `long`,
  271. * standard `int` or a `short`.
  272. */
  273. #ifndef MHD_LONG_LONG
  274. /**
  275. * @deprecated use #MHD_UNSIGNED_LONG_LONG instead!
  276. */
  277. #define MHD_LONG_LONG long long
  278. #define MHD_UNSIGNED_LONG_LONG unsigned long long
  279. #else /* MHD_LONG_LONG */
  280. _MHD_DEPR_MACRO ( \
  281. "Macro MHD_LONG_LONG is deprecated, use MHD_UNSIGNED_LONG_LONG")
  282. #endif
  283. /**
  284. * Format string for printing a variable of type #MHD_LONG_LONG.
  285. * You should only redefine this if you also define #MHD_LONG_LONG.
  286. */
  287. #ifndef MHD_LONG_LONG_PRINTF
  288. /**
  289. * @deprecated use #MHD_UNSIGNED_LONG_LONG_PRINTF instead!
  290. */
  291. #define MHD_LONG_LONG_PRINTF "ll"
  292. #define MHD_UNSIGNED_LONG_LONG_PRINTF "%llu"
  293. #else /* MHD_LONG_LONG_PRINTF */
  294. _MHD_DEPR_MACRO ( \
  295. "Macro MHD_LONG_LONG_PRINTF is deprecated, use MHD_UNSIGNED_LONG_LONG_PRINTF")
  296. #endif
  297. /**
  298. * @defgroup httpcode HTTP response codes.
  299. * These are the status codes defined for HTTP responses.
  300. * See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  301. * Registry export date: 2023-09-29
  302. * @{
  303. */
  304. /* 100 "Continue". RFC9110, Section 15.2.1. */
  305. #define MHD_HTTP_CONTINUE 100
  306. /* 101 "Switching Protocols". RFC9110, Section 15.2.2. */
  307. #define MHD_HTTP_SWITCHING_PROTOCOLS 101
  308. /* 102 "Processing". RFC2518. */
  309. #define MHD_HTTP_PROCESSING 102
  310. /* 103 "Early Hints". RFC8297. */
  311. #define MHD_HTTP_EARLY_HINTS 103
  312. /* 200 "OK". RFC9110, Section 15.3.1. */
  313. #define MHD_HTTP_OK 200
  314. /* 201 "Created". RFC9110, Section 15.3.2. */
  315. #define MHD_HTTP_CREATED 201
  316. /* 202 "Accepted". RFC9110, Section 15.3.3. */
  317. #define MHD_HTTP_ACCEPTED 202
  318. /* 203 "Non-Authoritative Information". RFC9110, Section 15.3.4. */
  319. #define MHD_HTTP_NON_AUTHORITATIVE_INFORMATION 203
  320. /* 204 "No Content". RFC9110, Section 15.3.5. */
  321. #define MHD_HTTP_NO_CONTENT 204
  322. /* 205 "Reset Content". RFC9110, Section 15.3.6. */
  323. #define MHD_HTTP_RESET_CONTENT 205
  324. /* 206 "Partial Content". RFC9110, Section 15.3.7. */
  325. #define MHD_HTTP_PARTIAL_CONTENT 206
  326. /* 207 "Multi-Status". RFC4918. */
  327. #define MHD_HTTP_MULTI_STATUS 207
  328. /* 208 "Already Reported". RFC5842. */
  329. #define MHD_HTTP_ALREADY_REPORTED 208
  330. /* 226 "IM Used". RFC3229. */
  331. #define MHD_HTTP_IM_USED 226
  332. /* 300 "Multiple Choices". RFC9110, Section 15.4.1. */
  333. #define MHD_HTTP_MULTIPLE_CHOICES 300
  334. /* 301 "Moved Permanently". RFC9110, Section 15.4.2. */
  335. #define MHD_HTTP_MOVED_PERMANENTLY 301
  336. /* 302 "Found". RFC9110, Section 15.4.3. */
  337. #define MHD_HTTP_FOUND 302
  338. /* 303 "See Other". RFC9110, Section 15.4.4. */
  339. #define MHD_HTTP_SEE_OTHER 303
  340. /* 304 "Not Modified". RFC9110, Section 15.4.5. */
  341. #define MHD_HTTP_NOT_MODIFIED 304
  342. /* 305 "Use Proxy". RFC9110, Section 15.4.6. */
  343. #define MHD_HTTP_USE_PROXY 305
  344. /* 306 "Switch Proxy". Not used! RFC9110, Section 15.4.7. */
  345. #define MHD_HTTP_SWITCH_PROXY 306
  346. /* 307 "Temporary Redirect". RFC9110, Section 15.4.8. */
  347. #define MHD_HTTP_TEMPORARY_REDIRECT 307
  348. /* 308 "Permanent Redirect". RFC9110, Section 15.4.9. */
  349. #define MHD_HTTP_PERMANENT_REDIRECT 308
  350. /* 400 "Bad Request". RFC9110, Section 15.5.1. */
  351. #define MHD_HTTP_BAD_REQUEST 400
  352. /* 401 "Unauthorized". RFC9110, Section 15.5.2. */
  353. #define MHD_HTTP_UNAUTHORIZED 401
  354. /* 402 "Payment Required". RFC9110, Section 15.5.3. */
  355. #define MHD_HTTP_PAYMENT_REQUIRED 402
  356. /* 403 "Forbidden". RFC9110, Section 15.5.4. */
  357. #define MHD_HTTP_FORBIDDEN 403
  358. /* 404 "Not Found". RFC9110, Section 15.5.5. */
  359. #define MHD_HTTP_NOT_FOUND 404
  360. /* 405 "Method Not Allowed". RFC9110, Section 15.5.6. */
  361. #define MHD_HTTP_METHOD_NOT_ALLOWED 405
  362. /* 406 "Not Acceptable". RFC9110, Section 15.5.7. */
  363. #define MHD_HTTP_NOT_ACCEPTABLE 406
  364. /* 407 "Proxy Authentication Required". RFC9110, Section 15.5.8. */
  365. #define MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
  366. /* 408 "Request Timeout". RFC9110, Section 15.5.9. */
  367. #define MHD_HTTP_REQUEST_TIMEOUT 408
  368. /* 409 "Conflict". RFC9110, Section 15.5.10. */
  369. #define MHD_HTTP_CONFLICT 409
  370. /* 410 "Gone". RFC9110, Section 15.5.11. */
  371. #define MHD_HTTP_GONE 410
  372. /* 411 "Length Required". RFC9110, Section 15.5.12. */
  373. #define MHD_HTTP_LENGTH_REQUIRED 411
  374. /* 412 "Precondition Failed". RFC9110, Section 15.5.13. */
  375. #define MHD_HTTP_PRECONDITION_FAILED 412
  376. /* 413 "Content Too Large". RFC9110, Section 15.5.14. */
  377. #define MHD_HTTP_CONTENT_TOO_LARGE 413
  378. /* 414 "URI Too Long". RFC9110, Section 15.5.15. */
  379. #define MHD_HTTP_URI_TOO_LONG 414
  380. /* 415 "Unsupported Media Type". RFC9110, Section 15.5.16. */
  381. #define MHD_HTTP_UNSUPPORTED_MEDIA_TYPE 415
  382. /* 416 "Range Not Satisfiable". RFC9110, Section 15.5.17. */
  383. #define MHD_HTTP_RANGE_NOT_SATISFIABLE 416
  384. /* 417 "Expectation Failed". RFC9110, Section 15.5.18. */
  385. #define MHD_HTTP_EXPECTATION_FAILED 417
  386. /* 421 "Misdirected Request". RFC9110, Section 15.5.20. */
  387. #define MHD_HTTP_MISDIRECTED_REQUEST 421
  388. /* 422 "Unprocessable Content". RFC9110, Section 15.5.21. */
  389. #define MHD_HTTP_UNPROCESSABLE_CONTENT 422
  390. /* 423 "Locked". RFC4918. */
  391. #define MHD_HTTP_LOCKED 423
  392. /* 424 "Failed Dependency". RFC4918. */
  393. #define MHD_HTTP_FAILED_DEPENDENCY 424
  394. /* 425 "Too Early". RFC8470. */
  395. #define MHD_HTTP_TOO_EARLY 425
  396. /* 426 "Upgrade Required". RFC9110, Section 15.5.22. */
  397. #define MHD_HTTP_UPGRADE_REQUIRED 426
  398. /* 428 "Precondition Required". RFC6585. */
  399. #define MHD_HTTP_PRECONDITION_REQUIRED 428
  400. /* 429 "Too Many Requests". RFC6585. */
  401. #define MHD_HTTP_TOO_MANY_REQUESTS 429
  402. /* 431 "Request Header Fields Too Large". RFC6585. */
  403. #define MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE 431
  404. /* 451 "Unavailable For Legal Reasons". RFC7725. */
  405. #define MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS 451
  406. /* 500 "Internal Server Error". RFC9110, Section 15.6.1. */
  407. #define MHD_HTTP_INTERNAL_SERVER_ERROR 500
  408. /* 501 "Not Implemented". RFC9110, Section 15.6.2. */
  409. #define MHD_HTTP_NOT_IMPLEMENTED 501
  410. /* 502 "Bad Gateway". RFC9110, Section 15.6.3. */
  411. #define MHD_HTTP_BAD_GATEWAY 502
  412. /* 503 "Service Unavailable". RFC9110, Section 15.6.4. */
  413. #define MHD_HTTP_SERVICE_UNAVAILABLE 503
  414. /* 504 "Gateway Timeout". RFC9110, Section 15.6.5. */
  415. #define MHD_HTTP_GATEWAY_TIMEOUT 504
  416. /* 505 "HTTP Version Not Supported". RFC9110, Section 15.6.6. */
  417. #define MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED 505
  418. /* 506 "Variant Also Negotiates". RFC2295. */
  419. #define MHD_HTTP_VARIANT_ALSO_NEGOTIATES 506
  420. /* 507 "Insufficient Storage". RFC4918. */
  421. #define MHD_HTTP_INSUFFICIENT_STORAGE 507
  422. /* 508 "Loop Detected". RFC5842. */
  423. #define MHD_HTTP_LOOP_DETECTED 508
  424. /* 510 "Not Extended". (OBSOLETED) RFC2774; status-change-http-experiments-to-historic. */
  425. #define MHD_HTTP_NOT_EXTENDED 510
  426. /* 511 "Network Authentication Required". RFC6585. */
  427. #define MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED 511
  428. /* Not registered non-standard codes */
  429. /* 449 "Reply With". MS IIS extension. */
  430. #define MHD_HTTP_RETRY_WITH 449
  431. /* 450 "Blocked by Windows Parental Controls". MS extension. */
  432. #define MHD_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS 450
  433. /* 509 "Bandwidth Limit Exceeded". Apache extension. */
  434. #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
  435. /* Deprecated names and codes */
  436. /** @deprecated */
  437. #define MHD_HTTP_METHOD_NOT_ACCEPTABLE _MHD_DEPR_IN_MACRO (\
  438. "Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE" \
  439. ) 406
  440. /** @deprecated */
  441. #define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE _MHD_DEPR_IN_MACRO (\
  442. "Value MHD_HTTP_REQUEST_ENTITY_TOO_LARGE is deprecated, use MHD_HTTP_CONTENT_TOO_LARGE"\
  443. ) 413
  444. /** @deprecated */
  445. #define MHD_HTTP_PAYLOAD_TOO_LARGE _MHD_DEPR_IN_MACRO (\
  446. "Value MHD_HTTP_PAYLOAD_TOO_LARGE is deprecated use MHD_HTTP_CONTENT_TOO_LARGE" \
  447. ) 413
  448. /** @deprecated */
  449. #define MHD_HTTP_REQUEST_URI_TOO_LONG _MHD_DEPR_IN_MACRO (\
  450. "Value MHD_HTTP_REQUEST_URI_TOO_LONG is deprecated, use MHD_HTTP_URI_TOO_LONG" \
  451. ) 414
  452. /** @deprecated */
  453. #define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE _MHD_DEPR_IN_MACRO (\
  454. "Value MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE is deprecated, use MHD_HTTP_RANGE_NOT_SATISFIABLE" \
  455. ) 416
  456. /** @deprecated */
  457. #define MHD_HTTP_UNPROCESSABLE_ENTITY _MHD_DEPR_IN_MACRO (\
  458. "Value MHD_HTTP_UNPROCESSABLE_ENTITY is deprecated, use MHD_HTTP_UNPROCESSABLE_CONTENT" \
  459. ) 422
  460. /** @deprecated */
  461. #define MHD_HTTP_UNORDERED_COLLECTION _MHD_DEPR_IN_MACRO (\
  462. "Value MHD_HTTP_UNORDERED_COLLECTION is deprecated as it was removed from RFC" \
  463. ) 425
  464. /** @deprecated */
  465. #define MHD_HTTP_NO_RESPONSE _MHD_DEPR_IN_MACRO (\
  466. "Value MHD_HTTP_NO_RESPONSE is deprecated as it is nginx internal code for logs only"\
  467. ) 444
  468. /** @} */ /* end of group httpcode */
  469. /**
  470. * Returns the string reason phrase for a response code.
  471. *
  472. * If message string is not available for a status code,
  473. * "Unknown" string will be returned.
  474. */
  475. _MHD_EXTERN const char *
  476. MHD_get_reason_phrase_for (unsigned int code);
  477. /**
  478. * Returns the length of the string reason phrase for a response code.
  479. *
  480. * If message string is not available for a status code,
  481. * 0 is returned.
  482. */
  483. _MHD_EXTERN size_t
  484. MHD_get_reason_phrase_len_for (unsigned int code);
  485. /**
  486. * Flag to be or-ed with MHD_HTTP status code for
  487. * SHOUTcast. This will cause the response to begin
  488. * with the SHOUTcast "ICY" line instead of "HTTP/1.x".
  489. * @ingroup specialized
  490. */
  491. #define MHD_ICY_FLAG ((uint32_t) (((uint32_t) 1) << 31))
  492. /**
  493. * @defgroup headers HTTP headers
  494. * The standard headers found in HTTP requests and responses.
  495. * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml
  496. * Registry export date: 2023-10-02
  497. * @{
  498. */
  499. /* Main HTTP headers. */
  500. /* Permanent. RFC9110, Section 12.5.1: HTTP Semantics */
  501. #define MHD_HTTP_HEADER_ACCEPT "Accept"
  502. /* Deprecated. RFC9110, Section 12.5.2: HTTP Semantics */
  503. #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
  504. /* Permanent. RFC9110, Section 12.5.3: HTTP Semantics */
  505. #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
  506. /* Permanent. RFC9110, Section 12.5.4: HTTP Semantics */
  507. #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
  508. /* Permanent. RFC9110, Section 14.3: HTTP Semantics */
  509. #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
  510. /* Permanent. RFC9111, Section 5.1: HTTP Caching */
  511. #define MHD_HTTP_HEADER_AGE "Age"
  512. /* Permanent. RFC9110, Section 10.2.1: HTTP Semantics */
  513. #define MHD_HTTP_HEADER_ALLOW "Allow"
  514. /* Permanent. RFC9110, Section 11.6.3: HTTP Semantics */
  515. #define MHD_HTTP_HEADER_AUTHENTICATION_INFO "Authentication-Info"
  516. /* Permanent. RFC9110, Section 11.6.2: HTTP Semantics */
  517. #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
  518. /* Permanent. RFC9111, Section 5.2 */
  519. #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
  520. /* Permanent. RFC9112, Section 9.6: HTTP/1.1 */
  521. #define MHD_HTTP_HEADER_CLOSE "Close"
  522. /* Permanent. RFC9110, Section 7.6.1: HTTP Semantics */
  523. #define MHD_HTTP_HEADER_CONNECTION "Connection"
  524. /* Permanent. RFC9110, Section 8.4: HTTP Semantics */
  525. #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
  526. /* Permanent. RFC9110, Section 8.5: HTTP Semantics */
  527. #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
  528. /* Permanent. RFC9110, Section 8.6: HTTP Semantics */
  529. #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
  530. /* Permanent. RFC9110, Section 8.7: HTTP Semantics */
  531. #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
  532. /* Permanent. RFC9110, Section 14.4: HTTP Semantics */
  533. #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
  534. /* Permanent. RFC9110, Section 8.3: HTTP Semantics */
  535. #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
  536. /* Permanent. RFC9110, Section 6.6.1: HTTP Semantics */
  537. #define MHD_HTTP_HEADER_DATE "Date"
  538. /* Permanent. RFC9110, Section 8.8.3: HTTP Semantics */
  539. #define MHD_HTTP_HEADER_ETAG "ETag"
  540. /* Permanent. RFC9110, Section 10.1.1: HTTP Semantics */
  541. #define MHD_HTTP_HEADER_EXPECT "Expect"
  542. /* Permanent. RFC9111, Section 5.3: HTTP Caching */
  543. #define MHD_HTTP_HEADER_EXPIRES "Expires"
  544. /* Permanent. RFC9110, Section 10.1.2: HTTP Semantics */
  545. #define MHD_HTTP_HEADER_FROM "From"
  546. /* Permanent. RFC9110, Section 7.2: HTTP Semantics */
  547. #define MHD_HTTP_HEADER_HOST "Host"
  548. /* Permanent. RFC9110, Section 13.1.1: HTTP Semantics */
  549. #define MHD_HTTP_HEADER_IF_MATCH "If-Match"
  550. /* Permanent. RFC9110, Section 13.1.3: HTTP Semantics */
  551. #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
  552. /* Permanent. RFC9110, Section 13.1.2: HTTP Semantics */
  553. #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
  554. /* Permanent. RFC9110, Section 13.1.5: HTTP Semantics */
  555. #define MHD_HTTP_HEADER_IF_RANGE "If-Range"
  556. /* Permanent. RFC9110, Section 13.1.4: HTTP Semantics */
  557. #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
  558. /* Permanent. RFC9110, Section 8.8.2: HTTP Semantics */
  559. #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
  560. /* Permanent. RFC9110, Section 10.2.2: HTTP Semantics */
  561. #define MHD_HTTP_HEADER_LOCATION "Location"
  562. /* Permanent. RFC9110, Section 7.6.2: HTTP Semantics */
  563. #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
  564. /* Permanent. RFC9112, Appendix B.1: HTTP/1.1 */
  565. #define MHD_HTTP_HEADER_MIME_VERSION "MIME-Version"
  566. /* Deprecated. RFC9111, Section 5.4: HTTP Caching */
  567. #define MHD_HTTP_HEADER_PRAGMA "Pragma"
  568. /* Permanent. RFC9110, Section 11.7.1: HTTP Semantics */
  569. #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
  570. /* Permanent. RFC9110, Section 11.7.3: HTTP Semantics */
  571. #define MHD_HTTP_HEADER_PROXY_AUTHENTICATION_INFO "Proxy-Authentication-Info"
  572. /* Permanent. RFC9110, Section 11.7.2: HTTP Semantics */
  573. #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
  574. /* Permanent. RFC9110, Section 14.2: HTTP Semantics */
  575. #define MHD_HTTP_HEADER_RANGE "Range"
  576. /* Permanent. RFC9110, Section 10.1.3: HTTP Semantics */
  577. #define MHD_HTTP_HEADER_REFERER "Referer"
  578. /* Permanent. RFC9110, Section 10.2.3: HTTP Semantics */
  579. #define MHD_HTTP_HEADER_RETRY_AFTER "Retry-After"
  580. /* Permanent. RFC9110, Section 10.2.4: HTTP Semantics */
  581. #define MHD_HTTP_HEADER_SERVER "Server"
  582. /* Permanent. RFC9110, Section 10.1.4: HTTP Semantics */
  583. #define MHD_HTTP_HEADER_TE "TE"
  584. /* Permanent. RFC9110, Section 6.6.2: HTTP Semantics */
  585. #define MHD_HTTP_HEADER_TRAILER "Trailer"
  586. /* Permanent. RFC9112, Section 6.1: HTTP Semantics */
  587. #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
  588. /* Permanent. RFC9110, Section 7.8: HTTP Semantics */
  589. #define MHD_HTTP_HEADER_UPGRADE "Upgrade"
  590. /* Permanent. RFC9110, Section 10.1.5: HTTP Semantics */
  591. #define MHD_HTTP_HEADER_USER_AGENT "User-Agent"
  592. /* Permanent. RFC9110, Section 12.5.5: HTTP Semantics */
  593. #define MHD_HTTP_HEADER_VARY "Vary"
  594. /* Permanent. RFC9110, Section 7.6.3: HTTP Semantics */
  595. #define MHD_HTTP_HEADER_VIA "Via"
  596. /* Permanent. RFC9110, Section 11.6.1: HTTP Semantics */
  597. #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
  598. /* Permanent. RFC9110, Section 12.5.5: HTTP Semantics */
  599. #define MHD_HTTP_HEADER_ASTERISK "*"
  600. /* Additional HTTP headers. */
  601. /* Permanent. RFC 3229: Delta encoding in HTTP */
  602. #define MHD_HTTP_HEADER_A_IM "A-IM"
  603. /* Permanent. RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) */
  604. #define MHD_HTTP_HEADER_ACCEPT_ADDITIONS "Accept-Additions"
  605. /* Permanent. RFC 8942, Section 3.1: HTTP Client Hints */
  606. #define MHD_HTTP_HEADER_ACCEPT_CH "Accept-CH"
  607. /* Permanent. RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
  608. #define MHD_HTTP_HEADER_ACCEPT_DATETIME "Accept-Datetime"
  609. /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */
  610. #define MHD_HTTP_HEADER_ACCEPT_FEATURES "Accept-Features"
  611. /* Permanent. RFC 5789: PATCH Method for HTTP */
  612. #define MHD_HTTP_HEADER_ACCEPT_PATCH "Accept-Patch"
  613. /* Permanent. Linked Data Platform 1.0 */
  614. #define MHD_HTTP_HEADER_ACCEPT_POST "Accept-Post"
  615. /* Permanent. RFC-ietf-httpbis-message-signatures-19, Section 5.1: HTTP Message Signatures */
  616. #define MHD_HTTP_HEADER_ACCEPT_SIGNATURE "Accept-Signature"
  617. /* Permanent. Fetch */
  618. #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS \
  619. "Access-Control-Allow-Credentials"
  620. /* Permanent. Fetch */
  621. #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS \
  622. "Access-Control-Allow-Headers"
  623. /* Permanent. Fetch */
  624. #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS \
  625. "Access-Control-Allow-Methods"
  626. /* Permanent. Fetch */
  627. #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \
  628. "Access-Control-Allow-Origin"
  629. /* Permanent. Fetch */
  630. #define MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS \
  631. "Access-Control-Expose-Headers"
  632. /* Permanent. Fetch */
  633. #define MHD_HTTP_HEADER_ACCESS_CONTROL_MAX_AGE "Access-Control-Max-Age"
  634. /* Permanent. Fetch */
  635. #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS \
  636. "Access-Control-Request-Headers"
  637. /* Permanent. Fetch */
  638. #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD \
  639. "Access-Control-Request-Method"
  640. /* Permanent. RFC 7639, Section 2: The ALPN HTTP Header Field */
  641. #define MHD_HTTP_HEADER_ALPN "ALPN"
  642. /* Permanent. RFC 7838: HTTP Alternative Services */
  643. #define MHD_HTTP_HEADER_ALT_SVC "Alt-Svc"
  644. /* Permanent. RFC 7838: HTTP Alternative Services */
  645. #define MHD_HTTP_HEADER_ALT_USED "Alt-Used"
  646. /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */
  647. #define MHD_HTTP_HEADER_ALTERNATES "Alternates"
  648. /* Permanent. RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
  649. #define MHD_HTTP_HEADER_APPLY_TO_REDIRECT_REF "Apply-To-Redirect-Ref"
  650. /* Permanent. RFC 8053, Section 4: HTTP Authentication Extensions for Interactive Clients */
  651. #define MHD_HTTP_HEADER_AUTHENTICATION_CONTROL "Authentication-Control"
  652. /* Permanent. RFC9211: The Cache-Status HTTP Response Header Field */
  653. #define MHD_HTTP_HEADER_CACHE_STATUS "Cache-Status"
  654. /* Permanent. RFC 8607, Section 5.1: Calendaring Extensions to WebDAV (CalDAV): Managed Attachments */
  655. #define MHD_HTTP_HEADER_CAL_MANAGED_ID "Cal-Managed-ID"
  656. /* Permanent. RFC 7809, Section 7.1: Calendaring Extensions to WebDAV (CalDAV): Time Zones by Reference */
  657. #define MHD_HTTP_HEADER_CALDAV_TIMEZONES "CalDAV-Timezones"
  658. /* Permanent. RFC9297 */
  659. #define MHD_HTTP_HEADER_CAPSULE_PROTOCOL "Capsule-Protocol"
  660. /* Permanent. RFC9213: Targeted HTTP Cache Control */
  661. #define MHD_HTTP_HEADER_CDN_CACHE_CONTROL "CDN-Cache-Control"
  662. /* Permanent. RFC 8586: Loop Detection in Content Delivery Networks (CDNs) */
  663. #define MHD_HTTP_HEADER_CDN_LOOP "CDN-Loop"
  664. /* Permanent. RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
  665. #define MHD_HTTP_HEADER_CERT_NOT_AFTER "Cert-Not-After"
  666. /* Permanent. RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
  667. #define MHD_HTTP_HEADER_CERT_NOT_BEFORE "Cert-Not-Before"
  668. /* Permanent. Clear Site Data */
  669. #define MHD_HTTP_HEADER_CLEAR_SITE_DATA "Clear-Site-Data"
  670. /* Permanent. RFC9440, Section 2: Client-Cert HTTP Header Field */
  671. #define MHD_HTTP_HEADER_CLIENT_CERT "Client-Cert"
  672. /* Permanent. RFC9440, Section 2: Client-Cert HTTP Header Field */
  673. #define MHD_HTTP_HEADER_CLIENT_CERT_CHAIN "Client-Cert-Chain"
  674. /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 2: Digest Fields */
  675. #define MHD_HTTP_HEADER_CONTENT_DIGEST "Content-Digest"
  676. /* Permanent. RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) */
  677. #define MHD_HTTP_HEADER_CONTENT_DISPOSITION "Content-Disposition"
  678. /* Permanent. The HTTP Distribution and Replication Protocol */
  679. #define MHD_HTTP_HEADER_CONTENT_ID "Content-ID"
  680. /* Permanent. Content Security Policy Level 3 */
  681. #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY "Content-Security-Policy"
  682. /* Permanent. Content Security Policy Level 3 */
  683. #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY_REPORT_ONLY \
  684. "Content-Security-Policy-Report-Only"
  685. /* Permanent. RFC 6265: HTTP State Management Mechanism */
  686. #define MHD_HTTP_HEADER_COOKIE "Cookie"
  687. /* Permanent. HTML */
  688. #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY \
  689. "Cross-Origin-Embedder-Policy"
  690. /* Permanent. HTML */
  691. #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY_REPORT_ONLY \
  692. "Cross-Origin-Embedder-Policy-Report-Only"
  693. /* Permanent. HTML */
  694. #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY "Cross-Origin-Opener-Policy"
  695. /* Permanent. HTML */
  696. #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY_REPORT_ONLY \
  697. "Cross-Origin-Opener-Policy-Report-Only"
  698. /* Permanent. Fetch */
  699. #define MHD_HTTP_HEADER_CROSS_ORIGIN_RESOURCE_POLICY \
  700. "Cross-Origin-Resource-Policy"
  701. /* Permanent. RFC 5323: Web Distributed Authoring and Versioning (WebDAV) SEARCH */
  702. #define MHD_HTTP_HEADER_DASL "DASL"
  703. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  704. #define MHD_HTTP_HEADER_DAV "DAV"
  705. /* Permanent. RFC 3229: Delta encoding in HTTP */
  706. #define MHD_HTTP_HEADER_DELTA_BASE "Delta-Base"
  707. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  708. #define MHD_HTTP_HEADER_DEPTH "Depth"
  709. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  710. #define MHD_HTTP_HEADER_DESTINATION "Destination"
  711. /* Permanent. The HTTP Distribution and Replication Protocol */
  712. #define MHD_HTTP_HEADER_DIFFERENTIAL_ID "Differential-ID"
  713. /* Permanent. RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
  714. #define MHD_HTTP_HEADER_DPOP "DPoP"
  715. /* Permanent. RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
  716. #define MHD_HTTP_HEADER_DPOP_NONCE "DPoP-Nonce"
  717. /* Permanent. RFC 8470: Using Early Data in HTTP */
  718. #define MHD_HTTP_HEADER_EARLY_DATA "Early-Data"
  719. /* Permanent. RFC9163: Expect-CT Extension for HTTP */
  720. #define MHD_HTTP_HEADER_EXPECT_CT "Expect-CT"
  721. /* Permanent. RFC 7239: Forwarded HTTP Extension */
  722. #define MHD_HTTP_HEADER_FORWARDED "Forwarded"
  723. /* Permanent. RFC 7486, Section 6.1.1: HTTP Origin-Bound Authentication (HOBA) */
  724. #define MHD_HTTP_HEADER_HOBAREG "Hobareg"
  725. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  726. #define MHD_HTTP_HEADER_IF "If"
  727. /* Permanent. RFC 6338: Scheduling Extensions to CalDAV */
  728. #define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match"
  729. /* Permanent. RFC 3229: Delta encoding in HTTP */
  730. #define MHD_HTTP_HEADER_IM "IM"
  731. /* Permanent. RFC 8473: Token Binding over HTTP */
  732. #define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID \
  733. "Include-Referred-Token-Binding-ID"
  734. /* Permanent. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
  735. #define MHD_HTTP_HEADER_KEEP_ALIVE "Keep-Alive"
  736. /* Permanent. RFC 3253: Versioning Extensions to WebDAV: (Web Distributed Authoring and Versioning) */
  737. #define MHD_HTTP_HEADER_LABEL "Label"
  738. /* Permanent. HTML */
  739. #define MHD_HTTP_HEADER_LAST_EVENT_ID "Last-Event-ID"
  740. /* Permanent. RFC 8288: Web Linking */
  741. #define MHD_HTTP_HEADER_LINK "Link"
  742. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  743. #define MHD_HTTP_HEADER_LOCK_TOKEN "Lock-Token"
  744. /* Permanent. RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
  745. #define MHD_HTTP_HEADER_MEMENTO_DATETIME "Memento-Datetime"
  746. /* Permanent. RFC 2227: Simple Hit-Metering and Usage-Limiting for HTTP */
  747. #define MHD_HTTP_HEADER_METER "Meter"
  748. /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */
  749. #define MHD_HTTP_HEADER_NEGOTIATE "Negotiate"
  750. /* Permanent. Network Error Logging */
  751. #define MHD_HTTP_HEADER_NEL "NEL"
  752. /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
  753. #define MHD_HTTP_HEADER_ODATA_ENTITYID "OData-EntityId"
  754. /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
  755. #define MHD_HTTP_HEADER_ODATA_ISOLATION "OData-Isolation"
  756. /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
  757. #define MHD_HTTP_HEADER_ODATA_MAXVERSION "OData-MaxVersion"
  758. /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
  759. #define MHD_HTTP_HEADER_ODATA_VERSION "OData-Version"
  760. /* Permanent. RFC 8053, Section 3: HTTP Authentication Extensions for Interactive Clients */
  761. #define MHD_HTTP_HEADER_OPTIONAL_WWW_AUTHENTICATE "Optional-WWW-Authenticate"
  762. /* Permanent. RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
  763. #define MHD_HTTP_HEADER_ORDERING_TYPE "Ordering-Type"
  764. /* Permanent. RFC 6454: The Web Origin Concept */
  765. #define MHD_HTTP_HEADER_ORIGIN "Origin"
  766. /* Permanent. HTML */
  767. #define MHD_HTTP_HEADER_ORIGIN_AGENT_CLUSTER "Origin-Agent-Cluster"
  768. /* Permanent. RFC 8613, Section 11.1: Object Security for Constrained RESTful Environments (OSCORE) */
  769. #define MHD_HTTP_HEADER_OSCORE "OSCORE"
  770. /* Permanent. OASIS Project Specification 01; OASIS; Chet_Ensign */
  771. #define MHD_HTTP_HEADER_OSLC_CORE_VERSION "OSLC-Core-Version"
  772. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  773. #define MHD_HTTP_HEADER_OVERWRITE "Overwrite"
  774. /* Permanent. HTML */
  775. #define MHD_HTTP_HEADER_PING_FROM "Ping-From"
  776. /* Permanent. HTML */
  777. #define MHD_HTTP_HEADER_PING_TO "Ping-To"
  778. /* Permanent. RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
  779. #define MHD_HTTP_HEADER_POSITION "Position"
  780. /* Permanent. RFC 7240: Prefer Header for HTTP */
  781. #define MHD_HTTP_HEADER_PREFER "Prefer"
  782. /* Permanent. RFC 7240: Prefer Header for HTTP */
  783. #define MHD_HTTP_HEADER_PREFERENCE_APPLIED "Preference-Applied"
  784. /* Permanent. RFC9218: Extensible Prioritization Scheme for HTTP */
  785. #define MHD_HTTP_HEADER_PRIORITY "Priority"
  786. /* Permanent. RFC9209: The Proxy-Status HTTP Response Header Field */
  787. #define MHD_HTTP_HEADER_PROXY_STATUS "Proxy-Status"
  788. /* Permanent. RFC 7469: Public Key Pinning Extension for HTTP */
  789. #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins"
  790. /* Permanent. RFC 7469: Public Key Pinning Extension for HTTP */
  791. #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \
  792. "Public-Key-Pins-Report-Only"
  793. /* Permanent. RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
  794. #define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref"
  795. /* Permanent. HTML */
  796. #define MHD_HTTP_HEADER_REFRESH "Refresh"
  797. /* Permanent. RFC 8555, Section 6.5.1: Automatic Certificate Management Environment (ACME) */
  798. #define MHD_HTTP_HEADER_REPLAY_NONCE "Replay-Nonce"
  799. /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 3: Digest Fields */
  800. #define MHD_HTTP_HEADER_REPR_DIGEST "Repr-Digest"
  801. /* Permanent. RFC 6638: Scheduling Extensions to CalDAV */
  802. #define MHD_HTTP_HEADER_SCHEDULE_REPLY "Schedule-Reply"
  803. /* Permanent. RFC 6338: Scheduling Extensions to CalDAV */
  804. #define MHD_HTTP_HEADER_SCHEDULE_TAG "Schedule-Tag"
  805. /* Permanent. Fetch */
  806. #define MHD_HTTP_HEADER_SEC_PURPOSE "Sec-Purpose"
  807. /* Permanent. RFC 8473: Token Binding over HTTP */
  808. #define MHD_HTTP_HEADER_SEC_TOKEN_BINDING "Sec-Token-Binding"
  809. /* Permanent. RFC 6455: The WebSocket Protocol */
  810. #define MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT "Sec-WebSocket-Accept"
  811. /* Permanent. RFC 6455: The WebSocket Protocol */
  812. #define MHD_HTTP_HEADER_SEC_WEBSOCKET_EXTENSIONS "Sec-WebSocket-Extensions"
  813. /* Permanent. RFC 6455: The WebSocket Protocol */
  814. #define MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY "Sec-WebSocket-Key"
  815. /* Permanent. RFC 6455: The WebSocket Protocol */
  816. #define MHD_HTTP_HEADER_SEC_WEBSOCKET_PROTOCOL "Sec-WebSocket-Protocol"
  817. /* Permanent. RFC 6455: The WebSocket Protocol */
  818. #define MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION "Sec-WebSocket-Version"
  819. /* Permanent. Server Timing */
  820. #define MHD_HTTP_HEADER_SERVER_TIMING "Server-Timing"
  821. /* Permanent. RFC 6265: HTTP State Management Mechanism */
  822. #define MHD_HTTP_HEADER_SET_COOKIE "Set-Cookie"
  823. /* Permanent. RFC-ietf-httpbis-message-signatures-19, Section 4.2: HTTP Message Signatures */
  824. #define MHD_HTTP_HEADER_SIGNATURE "Signature"
  825. /* Permanent. RFC-ietf-httpbis-message-signatures-19, Section 4.1: HTTP Message Signatures */
  826. #define MHD_HTTP_HEADER_SIGNATURE_INPUT "Signature-Input"
  827. /* Permanent. RFC 5023: The Atom Publishing Protocol */
  828. #define MHD_HTTP_HEADER_SLUG "SLUG"
  829. /* Permanent. Simple Object Access Protocol (SOAP) 1.1 */
  830. #define MHD_HTTP_HEADER_SOAPACTION "SoapAction"
  831. /* Permanent. RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV */
  832. #define MHD_HTTP_HEADER_STATUS_URI "Status-URI"
  833. /* Permanent. RFC 6797: HTTP Strict Transport Security (HSTS) */
  834. #define MHD_HTTP_HEADER_STRICT_TRANSPORT_SECURITY "Strict-Transport-Security"
  835. /* Permanent. RFC 8594: The Sunset HTTP Header Field */
  836. #define MHD_HTTP_HEADER_SUNSET "Sunset"
  837. /* Permanent. Edge Architecture Specification */
  838. #define MHD_HTTP_HEADER_SURROGATE_CAPABILITY "Surrogate-Capability"
  839. /* Permanent. Edge Architecture Specification */
  840. #define MHD_HTTP_HEADER_SURROGATE_CONTROL "Surrogate-Control"
  841. /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */
  842. #define MHD_HTTP_HEADER_TCN "TCN"
  843. /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
  844. #define MHD_HTTP_HEADER_TIMEOUT "Timeout"
  845. /* Permanent. RFC 8030, Section 5.4: Generic Event Delivery Using HTTP Push */
  846. #define MHD_HTTP_HEADER_TOPIC "Topic"
  847. /* Permanent. Trace Context */
  848. #define MHD_HTTP_HEADER_TRACEPARENT "Traceparent"
  849. /* Permanent. Trace Context */
  850. #define MHD_HTTP_HEADER_TRACESTATE "Tracestate"
  851. /* Permanent. RFC 8030, Section 5.2: Generic Event Delivery Using HTTP Push */
  852. #define MHD_HTTP_HEADER_TTL "TTL"
  853. /* Permanent. RFC 8030, Section 5.3: Generic Event Delivery Using HTTP Push */
  854. #define MHD_HTTP_HEADER_URGENCY "Urgency"
  855. /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */
  856. #define MHD_HTTP_HEADER_VARIANT_VARY "Variant-Vary"
  857. /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
  858. #define MHD_HTTP_HEADER_WANT_CONTENT_DIGEST "Want-Content-Digest"
  859. /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
  860. #define MHD_HTTP_HEADER_WANT_REPR_DIGEST "Want-Repr-Digest"
  861. /* Permanent. Fetch */
  862. #define MHD_HTTP_HEADER_X_CONTENT_TYPE_OPTIONS "X-Content-Type-Options"
  863. /* Permanent. HTML */
  864. #define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options"
  865. /* Provisional. AMP-Cache-Transform HTTP request header */
  866. #define MHD_HTTP_HEADER_AMP_CACHE_TRANSFORM "AMP-Cache-Transform"
  867. /* Provisional. OSLC Configuration Management Version 1.0. Part 3: Configuration Specification */
  868. #define MHD_HTTP_HEADER_CONFIGURATION_CONTEXT "Configuration-Context"
  869. /* Provisional. RFC 6017: Electronic Data Interchange - Internet Integration (EDIINT) Features Header Field */
  870. #define MHD_HTTP_HEADER_EDIINT_FEATURES "EDIINT-Features"
  871. /* Provisional. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
  872. #define MHD_HTTP_HEADER_ISOLATION "Isolation"
  873. /* Provisional. Permissions Policy */
  874. #define MHD_HTTP_HEADER_PERMISSIONS_POLICY "Permissions-Policy"
  875. /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
  876. #define MHD_HTTP_HEADER_REPEATABILITY_CLIENT_ID "Repeatability-Client-ID"
  877. /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
  878. #define MHD_HTTP_HEADER_REPEATABILITY_FIRST_SENT "Repeatability-First-Sent"
  879. /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
  880. #define MHD_HTTP_HEADER_REPEATABILITY_REQUEST_ID "Repeatability-Request-ID"
  881. /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
  882. #define MHD_HTTP_HEADER_REPEATABILITY_RESULT "Repeatability-Result"
  883. /* Provisional. Reporting API */
  884. #define MHD_HTTP_HEADER_REPORTING_ENDPOINTS "Reporting-Endpoints"
  885. /* Provisional. Global Privacy Control (GPC) */
  886. #define MHD_HTTP_HEADER_SEC_GPC "Sec-GPC"
  887. /* Provisional. Resource Timing Level 1 */
  888. #define MHD_HTTP_HEADER_TIMING_ALLOW_ORIGIN "Timing-Allow-Origin"
  889. /* Deprecated. PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
  890. #define MHD_HTTP_HEADER_C_PEP_INFO "C-PEP-Info"
  891. /* Deprecated. White Paper: Joint Electronic Payment Initiative */
  892. #define MHD_HTTP_HEADER_PROTOCOL_INFO "Protocol-Info"
  893. /* Deprecated. White Paper: Joint Electronic Payment Initiative */
  894. #define MHD_HTTP_HEADER_PROTOCOL_QUERY "Protocol-Query"
  895. /* Obsoleted. Access Control for Cross-site Requests */
  896. #define MHD_HTTP_HEADER_ACCESS_CONTROL "Access-Control"
  897. /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
  898. #define MHD_HTTP_HEADER_C_EXT "C-Ext"
  899. /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
  900. #define MHD_HTTP_HEADER_C_MAN "C-Man"
  901. /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
  902. #define MHD_HTTP_HEADER_C_OPT "C-Opt"
  903. /* Obsoleted. PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
  904. #define MHD_HTTP_HEADER_C_PEP "C-PEP"
  905. /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1; RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 */
  906. #define MHD_HTTP_HEADER_CONTENT_BASE "Content-Base"
  907. /* Obsoleted. RFC 2616, Section 14.15: Hypertext Transfer Protocol -- HTTP/1.1; RFC 7231, Appendix B: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content */
  908. #define MHD_HTTP_HEADER_CONTENT_MD5 "Content-MD5"
  909. /* Obsoleted. HTML 4.01 Specification */
  910. #define MHD_HTTP_HEADER_CONTENT_SCRIPT_TYPE "Content-Script-Type"
  911. /* Obsoleted. HTML 4.01 Specification */
  912. #define MHD_HTTP_HEADER_CONTENT_STYLE_TYPE "Content-Style-Type"
  913. /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
  914. #define MHD_HTTP_HEADER_CONTENT_VERSION "Content-Version"
  915. /* Obsoleted. RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
  916. #define MHD_HTTP_HEADER_COOKIE2 "Cookie2"
  917. /* Obsoleted. HTML 4.01 Specification */
  918. #define MHD_HTTP_HEADER_DEFAULT_STYLE "Default-Style"
  919. /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
  920. #define MHD_HTTP_HEADER_DERIVED_FROM "Derived-From"
  921. /* Obsoleted. RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
  922. #define MHD_HTTP_HEADER_DIGEST "Digest"
  923. /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
  924. #define MHD_HTTP_HEADER_EXT "Ext"
  925. /* Obsoleted. Implementation of OPS Over HTTP */
  926. #define MHD_HTTP_HEADER_GETPROFILE "GetProfile"
  927. /* Obsoleted. RFC 7540, Section 3.2.1: Hypertext Transfer Protocol Version 2 (HTTP/2) */
  928. #define MHD_HTTP_HEADER_HTTP2_SETTINGS "HTTP2-Settings"
  929. /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
  930. #define MHD_HTTP_HEADER_MAN "Man"
  931. /* Obsoleted. Access Control for Cross-site Requests */
  932. #define MHD_HTTP_HEADER_METHOD_CHECK "Method-Check"
  933. /* Obsoleted. Access Control for Cross-site Requests */
  934. #define MHD_HTTP_HEADER_METHOD_CHECK_EXPIRES "Method-Check-Expires"
  935. /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
  936. #define MHD_HTTP_HEADER_OPT "Opt"
  937. /* Obsoleted. The Platform for Privacy Preferences 1.0 (P3P1.0) Specification */
  938. #define MHD_HTTP_HEADER_P3P "P3P"
  939. /* Obsoleted. PEP - an Extension Mechanism for HTTP */
  940. #define MHD_HTTP_HEADER_PEP "PEP"
  941. /* Obsoleted. PEP - an Extension Mechanism for HTTP */
  942. #define MHD_HTTP_HEADER_PEP_INFO "Pep-Info"
  943. /* Obsoleted. PICS Label Distribution Label Syntax and Communication Protocols */
  944. #define MHD_HTTP_HEADER_PICS_LABEL "PICS-Label"
  945. /* Obsoleted. Implementation of OPS Over HTTP */
  946. #define MHD_HTTP_HEADER_PROFILEOBJECT "ProfileObject"
  947. /* Obsoleted. PICS Label Distribution Label Syntax and Communication Protocols */
  948. #define MHD_HTTP_HEADER_PROTOCOL "Protocol"
  949. /* Obsoleted. PICS Label Distribution Label Syntax and Communication Protocols */
  950. #define MHD_HTTP_HEADER_PROTOCOL_REQUEST "Protocol-Request"
  951. /* Obsoleted. Notification for Proxy Caches */
  952. #define MHD_HTTP_HEADER_PROXY_FEATURES "Proxy-Features"
  953. /* Obsoleted. Notification for Proxy Caches */
  954. #define MHD_HTTP_HEADER_PROXY_INSTRUCTION "Proxy-Instruction"
  955. /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
  956. #define MHD_HTTP_HEADER_PUBLIC "Public"
  957. /* Obsoleted. Access Control for Cross-site Requests */
  958. #define MHD_HTTP_HEADER_REFERER_ROOT "Referer-Root"
  959. /* Obsoleted. RFC 2310: The Safe Response Header Field; status-change-http-experiments-to-historic */
  960. #define MHD_HTTP_HEADER_SAFE "Safe"
  961. /* Obsoleted. RFC 2660: The Secure HyperText Transfer Protocol; status-change-http-experiments-to-historic */
  962. #define MHD_HTTP_HEADER_SECURITY_SCHEME "Security-Scheme"
  963. /* Obsoleted. RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
  964. #define MHD_HTTP_HEADER_SET_COOKIE2 "Set-Cookie2"
  965. /* Obsoleted. Implementation of OPS Over HTTP */
  966. #define MHD_HTTP_HEADER_SETPROFILE "SetProfile"
  967. /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
  968. #define MHD_HTTP_HEADER_URI "URI"
  969. /* Obsoleted. RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
  970. #define MHD_HTTP_HEADER_WANT_DIGEST "Want-Digest"
  971. /* Obsoleted. RFC9111, Section 5.5: HTTP Caching */
  972. #define MHD_HTTP_HEADER_WARNING "Warning"
  973. /* Headers removed from the registry. Do not use! */
  974. /* Obsoleted. RFC4229 */
  975. #define MHD_HTTP_HEADER_COMPLIANCE "Compliance"
  976. /* Obsoleted. RFC4229 */
  977. #define MHD_HTTP_HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
  978. /* Obsoleted. RFC4229 */
  979. #define MHD_HTTP_HEADER_COST "Cost"
  980. /* Obsoleted. RFC4229 */
  981. #define MHD_HTTP_HEADER_MESSAGE_ID "Message-ID"
  982. /* Obsoleted. RFC4229 */
  983. #define MHD_HTTP_HEADER_NON_COMPLIANCE "Non-Compliance"
  984. /* Obsoleted. RFC4229 */
  985. #define MHD_HTTP_HEADER_OPTIONAL "Optional"
  986. /* Obsoleted. RFC4229 */
  987. #define MHD_HTTP_HEADER_RESOLUTION_HINT "Resolution-Hint"
  988. /* Obsoleted. RFC4229 */
  989. #define MHD_HTTP_HEADER_RESOLVER_LOCATION "Resolver-Location"
  990. /* Obsoleted. RFC4229 */
  991. #define MHD_HTTP_HEADER_SUBOK "SubOK"
  992. /* Obsoleted. RFC4229 */
  993. #define MHD_HTTP_HEADER_SUBST "Subst"
  994. /* Obsoleted. RFC4229 */
  995. #define MHD_HTTP_HEADER_TITLE "Title"
  996. /* Obsoleted. RFC4229 */
  997. #define MHD_HTTP_HEADER_UA_COLOR "UA-Color"
  998. /* Obsoleted. RFC4229 */
  999. #define MHD_HTTP_HEADER_UA_MEDIA "UA-Media"
  1000. /* Obsoleted. RFC4229 */
  1001. #define MHD_HTTP_HEADER_UA_PIXELS "UA-Pixels"
  1002. /* Obsoleted. RFC4229 */
  1003. #define MHD_HTTP_HEADER_UA_RESOLUTION "UA-Resolution"
  1004. /* Obsoleted. RFC4229 */
  1005. #define MHD_HTTP_HEADER_UA_WINDOWPIXELS "UA-Windowpixels"
  1006. /* Obsoleted. RFC4229 */
  1007. #define MHD_HTTP_HEADER_VERSION "Version"
  1008. /* Obsoleted. W3C Mobile Web Best Practices Working Group */
  1009. #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT "X-Device-Accept"
  1010. /* Obsoleted. W3C Mobile Web Best Practices Working Group */
  1011. #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_CHARSET "X-Device-Accept-Charset"
  1012. /* Obsoleted. W3C Mobile Web Best Practices Working Group */
  1013. #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_ENCODING "X-Device-Accept-Encoding"
  1014. /* Obsoleted. W3C Mobile Web Best Practices Working Group */
  1015. #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_LANGUAGE "X-Device-Accept-Language"
  1016. /* Obsoleted. W3C Mobile Web Best Practices Working Group */
  1017. #define MHD_HTTP_HEADER_X_DEVICE_USER_AGENT "X-Device-User-Agent"
  1018. /** @} */ /* end of group headers */
  1019. /**
  1020. * @defgroup versions HTTP versions
  1021. * These strings should be used to match against the first line of the
  1022. * HTTP header.
  1023. * @{
  1024. */
  1025. #define MHD_HTTP_VERSION_1_0 "HTTP/1.0"
  1026. #define MHD_HTTP_VERSION_1_1 "HTTP/1.1"
  1027. /** @} */ /* end of group versions */
  1028. /**
  1029. * @defgroup methods HTTP methods
  1030. * HTTP methods (as strings).
  1031. * See: https://www.iana.org/assignments/http-methods/http-methods.xml
  1032. * Registry export date: 2023-10-02
  1033. * @{
  1034. */
  1035. /* Main HTTP methods. */
  1036. /* Safe. Idempotent. RFC9110, Section 9.3.1. */
  1037. #define MHD_HTTP_METHOD_GET "GET"
  1038. /* Safe. Idempotent. RFC9110, Section 9.3.2. */
  1039. #define MHD_HTTP_METHOD_HEAD "HEAD"
  1040. /* Not safe. Not idempotent. RFC9110, Section 9.3.3. */
  1041. #define MHD_HTTP_METHOD_POST "POST"
  1042. /* Not safe. Idempotent. RFC9110, Section 9.3.4. */
  1043. #define MHD_HTTP_METHOD_PUT "PUT"
  1044. /* Not safe. Idempotent. RFC9110, Section 9.3.5. */
  1045. #define MHD_HTTP_METHOD_DELETE "DELETE"
  1046. /* Not safe. Not idempotent. RFC9110, Section 9.3.6. */
  1047. #define MHD_HTTP_METHOD_CONNECT "CONNECT"
  1048. /* Safe. Idempotent. RFC9110, Section 9.3.7. */
  1049. #define MHD_HTTP_METHOD_OPTIONS "OPTIONS"
  1050. /* Safe. Idempotent. RFC9110, Section 9.3.8. */
  1051. #define MHD_HTTP_METHOD_TRACE "TRACE"
  1052. /* Additional HTTP methods. */
  1053. /* Not safe. Idempotent. RFC3744, Section 8.1. */
  1054. #define MHD_HTTP_METHOD_ACL "ACL"
  1055. /* Not safe. Idempotent. RFC3253, Section 12.6. */
  1056. #define MHD_HTTP_METHOD_BASELINE_CONTROL "BASELINE-CONTROL"
  1057. /* Not safe. Idempotent. RFC5842, Section 4. */
  1058. #define MHD_HTTP_METHOD_BIND "BIND"
  1059. /* Not safe. Idempotent. RFC3253, Section 4.4, Section 9.4. */
  1060. #define MHD_HTTP_METHOD_CHECKIN "CHECKIN"
  1061. /* Not safe. Idempotent. RFC3253, Section 4.3, Section 8.8. */
  1062. #define MHD_HTTP_METHOD_CHECKOUT "CHECKOUT"
  1063. /* Not safe. Idempotent. RFC4918, Section 9.8. */
  1064. #define MHD_HTTP_METHOD_COPY "COPY"
  1065. /* Not safe. Idempotent. RFC3253, Section 8.2. */
  1066. #define MHD_HTTP_METHOD_LABEL "LABEL"
  1067. /* Not safe. Idempotent. RFC2068, Section 19.6.1.2. */
  1068. #define MHD_HTTP_METHOD_LINK "LINK"
  1069. /* Not safe. Not idempotent. RFC4918, Section 9.10. */
  1070. #define MHD_HTTP_METHOD_LOCK "LOCK"
  1071. /* Not safe. Idempotent. RFC3253, Section 11.2. */
  1072. #define MHD_HTTP_METHOD_MERGE "MERGE"
  1073. /* Not safe. Idempotent. RFC3253, Section 13.5. */
  1074. #define MHD_HTTP_METHOD_MKACTIVITY "MKACTIVITY"
  1075. /* Not safe. Idempotent. RFC4791, Section 5.3.1; RFC8144, Section 2.3. */
  1076. #define MHD_HTTP_METHOD_MKCALENDAR "MKCALENDAR"
  1077. /* Not safe. Idempotent. RFC4918, Section 9.3; RFC5689, Section 3; RFC8144, Section 2.3. */
  1078. #define MHD_HTTP_METHOD_MKCOL "MKCOL"
  1079. /* Not safe. Idempotent. RFC4437, Section 6. */
  1080. #define MHD_HTTP_METHOD_MKREDIRECTREF "MKREDIRECTREF"
  1081. /* Not safe. Idempotent. RFC3253, Section 6.3. */
  1082. #define MHD_HTTP_METHOD_MKWORKSPACE "MKWORKSPACE"
  1083. /* Not safe. Idempotent. RFC4918, Section 9.9. */
  1084. #define MHD_HTTP_METHOD_MOVE "MOVE"
  1085. /* Not safe. Idempotent. RFC3648, Section 7. */
  1086. #define MHD_HTTP_METHOD_ORDERPATCH "ORDERPATCH"
  1087. /* Not safe. Not idempotent. RFC5789, Section 2. */
  1088. #define MHD_HTTP_METHOD_PATCH "PATCH"
  1089. /* Safe. Idempotent. RFC9113, Section 3.4. */
  1090. #define MHD_HTTP_METHOD_PRI "PRI"
  1091. /* Safe. Idempotent. RFC4918, Section 9.1; RFC8144, Section 2.1. */
  1092. #define MHD_HTTP_METHOD_PROPFIND "PROPFIND"
  1093. /* Not safe. Idempotent. RFC4918, Section 9.2; RFC8144, Section 2.2. */
  1094. #define MHD_HTTP_METHOD_PROPPATCH "PROPPATCH"
  1095. /* Not safe. Idempotent. RFC5842, Section 6. */
  1096. #define MHD_HTTP_METHOD_REBIND "REBIND"
  1097. /* Safe. Idempotent. RFC3253, Section 3.6; RFC8144, Section 2.1. */
  1098. #define MHD_HTTP_METHOD_REPORT "REPORT"
  1099. /* Safe. Idempotent. RFC5323, Section 2. */
  1100. #define MHD_HTTP_METHOD_SEARCH "SEARCH"
  1101. /* Not safe. Idempotent. RFC5842, Section 5. */
  1102. #define MHD_HTTP_METHOD_UNBIND "UNBIND"
  1103. /* Not safe. Idempotent. RFC3253, Section 4.5. */
  1104. #define MHD_HTTP_METHOD_UNCHECKOUT "UNCHECKOUT"
  1105. /* Not safe. Idempotent. RFC2068, Section 19.6.1.3. */
  1106. #define MHD_HTTP_METHOD_UNLINK "UNLINK"
  1107. /* Not safe. Idempotent. RFC4918, Section 9.11. */
  1108. #define MHD_HTTP_METHOD_UNLOCK "UNLOCK"
  1109. /* Not safe. Idempotent. RFC3253, Section 7.1. */
  1110. #define MHD_HTTP_METHOD_UPDATE "UPDATE"
  1111. /* Not safe. Idempotent. RFC4437, Section 7. */
  1112. #define MHD_HTTP_METHOD_UPDATEREDIRECTREF "UPDATEREDIRECTREF"
  1113. /* Not safe. Idempotent. RFC3253, Section 3.5. */
  1114. #define MHD_HTTP_METHOD_VERSION_CONTROL "VERSION-CONTROL"
  1115. /* Not safe. Not idempotent. RFC9110, Section 18.2. */
  1116. #define MHD_HTTP_METHOD_ASTERISK "*"
  1117. /** @} */ /* end of group methods */
  1118. /**
  1119. * @defgroup postenc HTTP POST encodings
  1120. * See also: http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
  1121. * @{
  1122. */
  1123. #define MHD_HTTP_POST_ENCODING_FORM_URLENCODED \
  1124. "application/x-www-form-urlencoded"
  1125. #define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
  1126. /** @} */ /* end of group postenc */
  1127. /**
  1128. * @brief Handle for the daemon (listening on a socket for HTTP traffic).
  1129. * @ingroup event
  1130. */
  1131. struct MHD_Daemon;
  1132. /**
  1133. * @brief Handle for a connection / HTTP request.
  1134. *
  1135. * With HTTP/1.1, multiple requests can be run over the same
  1136. * connection. However, MHD will only show one request per TCP
  1137. * connection to the client at any given time.
  1138. * @ingroup request
  1139. */
  1140. struct MHD_Connection;
  1141. /**
  1142. * @brief Handle for a response.
  1143. * @ingroup response
  1144. */
  1145. struct MHD_Response;
  1146. /**
  1147. * @brief Handle for POST processing.
  1148. * @ingroup response
  1149. */
  1150. struct MHD_PostProcessor;
  1151. /**
  1152. * @brief Flags for the `struct MHD_Daemon`.
  1153. *
  1154. * Note that MHD will run automatically in background thread(s) only
  1155. * if #MHD_USE_INTERNAL_POLLING_THREAD is used. Otherwise caller (application)
  1156. * must use #MHD_run() or #MHD_run_from_select() to have MHD processed
  1157. * network connections and data.
  1158. *
  1159. * Starting the daemon may also fail if a particular option is not
  1160. * implemented or not supported on the target platform (i.e. no
  1161. * support for TLS, epoll or IPv6).
  1162. */
  1163. enum MHD_FLAG
  1164. {
  1165. /**
  1166. * No options selected.
  1167. */
  1168. MHD_NO_FLAG = 0,
  1169. /**
  1170. * Print errors messages to custom error logger or to `stderr` if
  1171. * custom error logger is not set.
  1172. * @sa ::MHD_OPTION_EXTERNAL_LOGGER
  1173. */
  1174. MHD_USE_ERROR_LOG = 1,
  1175. /**
  1176. * Run in debug mode. If this flag is used, the library should
  1177. * print error messages and warnings to `stderr`.
  1178. */
  1179. MHD_USE_DEBUG = 1,
  1180. /**
  1181. * Run in HTTPS mode. The modern protocol is called TLS.
  1182. */
  1183. MHD_USE_TLS = 2,
  1184. /** @deprecated */
  1185. MHD_USE_SSL = 2,
  1186. #if 0
  1187. /* let's do this later once versions that define MHD_USE_TLS a more widely deployed. */
  1188. #define MHD_USE_SSL \
  1189. _MHD_DEPR_IN_MACRO ("Value MHD_USE_SSL is deprecated, use MHD_USE_TLS") \
  1190. MHD_USE_TLS
  1191. #endif
  1192. /**
  1193. * Run using one thread per connection.
  1194. * Must be used only with #MHD_USE_INTERNAL_POLLING_THREAD.
  1195. *
  1196. * If #MHD_USE_ITC is also not used, closed and expired connections may only
  1197. * be cleaned up internally when a new connection is received.
  1198. * Consider adding of #MHD_USE_ITC flag to have faster internal cleanups
  1199. * at very minor increase in system resources usage.
  1200. */
  1201. MHD_USE_THREAD_PER_CONNECTION = 4,
  1202. /**
  1203. * Run using an internal thread (or thread pool) for sockets sending
  1204. * and receiving and data processing. Without this flag MHD will not
  1205. * run automatically in background thread(s).
  1206. * If this flag is set, #MHD_run() and #MHD_run_from_select() couldn't
  1207. * be used.
  1208. * This flag is set explicitly by #MHD_USE_POLL_INTERNAL_THREAD and
  1209. * by #MHD_USE_EPOLL_INTERNAL_THREAD.
  1210. * When this flag is not set, MHD run in "external" polling mode.
  1211. */
  1212. MHD_USE_INTERNAL_POLLING_THREAD = 8,
  1213. /** @deprecated */
  1214. MHD_USE_SELECT_INTERNALLY = 8,
  1215. #if 0 /* Will be marked for real deprecation later. */
  1216. #define MHD_USE_SELECT_INTERNALLY \
  1217. _MHD_DEPR_IN_MACRO ( \
  1218. "Value MHD_USE_SELECT_INTERNALLY is deprecated, use MHD_USE_INTERNAL_POLLING_THREAD instead") \
  1219. MHD_USE_INTERNAL_POLLING_THREAD
  1220. #endif /* 0 */
  1221. /**
  1222. * Run using the IPv6 protocol (otherwise, MHD will just support
  1223. * IPv4). If you want MHD to support IPv4 and IPv6 using a single
  1224. * socket, pass #MHD_USE_DUAL_STACK, otherwise, if you only pass
  1225. * this option, MHD will try to bind to IPv6-only (resulting in
  1226. * no IPv4 support).
  1227. */
  1228. MHD_USE_IPv6 = 16,
  1229. /**
  1230. * Be pedantic about the protocol (as opposed to as tolerant as
  1231. * possible).
  1232. * This flag is equivalent to setting 1 as #MHD_OPTION_CLIENT_DISCIPLINE_LVL
  1233. * value.
  1234. * @sa #MHD_OPTION_CLIENT_DISCIPLINE_LVL
  1235. */
  1236. MHD_USE_PEDANTIC_CHECKS = 32,
  1237. #if 0 /* Will be marked for real deprecation later. */
  1238. #define MHD_USE_PEDANTIC_CHECKS \
  1239. _MHD_DEPR_IN_MACRO ( \
  1240. "Flag MHD_USE_PEDANTIC_CHECKS is deprecated, " \
  1241. "use option MHD_OPTION_CLIENT_DISCIPLINE_LVL instead") \
  1242. 32
  1243. #endif /* 0 */
  1244. /**
  1245. * Use `poll()` instead of `select()` for polling sockets.
  1246. * This allows sockets with `fd >= FD_SETSIZE`.
  1247. * This option is not compatible with an "external" polling mode
  1248. * (as there is no API to get the file descriptors for the external
  1249. * poll() from MHD) and must also not be used in combination
  1250. * with #MHD_USE_EPOLL.
  1251. * @sa ::MHD_FEATURE_POLL, #MHD_USE_POLL_INTERNAL_THREAD
  1252. */
  1253. MHD_USE_POLL = 64,
  1254. /**
  1255. * Run using an internal thread (or thread pool) doing `poll()`.
  1256. * @sa ::MHD_FEATURE_POLL, #MHD_USE_POLL, #MHD_USE_INTERNAL_POLLING_THREAD
  1257. */
  1258. MHD_USE_POLL_INTERNAL_THREAD = MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD,
  1259. /** @deprecated */
  1260. MHD_USE_POLL_INTERNALLY = MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD,
  1261. #if 0 /* Will be marked for real deprecation later. */
  1262. #define MHD_USE_POLL_INTERNALLY \
  1263. _MHD_DEPR_IN_MACRO ( \
  1264. "Value MHD_USE_POLL_INTERNALLY is deprecated, use MHD_USE_POLL_INTERNAL_THREAD instead") \
  1265. MHD_USE_POLL_INTERNAL_THREAD
  1266. #endif /* 0 */
  1267. /**
  1268. * Suppress (automatically) adding the 'Date:' header to HTTP responses.
  1269. * This option should ONLY be used on systems that do not have a clock
  1270. * and that DO provide other mechanisms for cache control. See also
  1271. * RFC 2616, section 14.18 (exception 3).
  1272. */
  1273. MHD_USE_SUPPRESS_DATE_NO_CLOCK = 128,
  1274. /** @deprecated */
  1275. MHD_SUPPRESS_DATE_NO_CLOCK = 128,
  1276. #if 0 /* Will be marked for real deprecation later. */
  1277. #define MHD_SUPPRESS_DATE_NO_CLOCK \
  1278. _MHD_DEPR_IN_MACRO ( \
  1279. "Value MHD_SUPPRESS_DATE_NO_CLOCK is deprecated, use MHD_USE_SUPPRESS_DATE_NO_CLOCK instead") \
  1280. MHD_USE_SUPPRESS_DATE_NO_CLOCK
  1281. #endif /* 0 */
  1282. /**
  1283. * Run without a listen socket. This option only makes sense if
  1284. * #MHD_add_connection is to be used exclusively to connect HTTP
  1285. * clients to the HTTP server. This option is incompatible with
  1286. * using a thread pool; if it is used, #MHD_OPTION_THREAD_POOL_SIZE
  1287. * is ignored.
  1288. */
  1289. MHD_USE_NO_LISTEN_SOCKET = 256,
  1290. /**
  1291. * Use `epoll()` instead of `select()` or `poll()` for the event loop.
  1292. * This option is only available on some systems; using the option on
  1293. * systems without epoll will cause #MHD_start_daemon to fail. Using
  1294. * this option is not supported with #MHD_USE_THREAD_PER_CONNECTION.
  1295. * @sa ::MHD_FEATURE_EPOLL
  1296. */
  1297. MHD_USE_EPOLL = 512,
  1298. /** @deprecated */
  1299. MHD_USE_EPOLL_LINUX_ONLY = 512,
  1300. #if 0 /* Will be marked for real deprecation later. */
  1301. #define MHD_USE_EPOLL_LINUX_ONLY \
  1302. _MHD_DEPR_IN_MACRO ( \
  1303. "Value MHD_USE_EPOLL_LINUX_ONLY is deprecated, use MHD_USE_EPOLL") \
  1304. MHD_USE_EPOLL
  1305. #endif /* 0 */
  1306. /**
  1307. * Run using an internal thread (or thread pool) doing `epoll` polling.
  1308. * This option is only available on certain platforms; using the option on
  1309. * platform without `epoll` support will cause #MHD_start_daemon to fail.
  1310. * @sa ::MHD_FEATURE_EPOLL, #MHD_USE_EPOLL, #MHD_USE_INTERNAL_POLLING_THREAD
  1311. */
  1312. MHD_USE_EPOLL_INTERNAL_THREAD = MHD_USE_EPOLL
  1313. | MHD_USE_INTERNAL_POLLING_THREAD,
  1314. /** @deprecated */
  1315. MHD_USE_EPOLL_INTERNALLY = MHD_USE_EPOLL | MHD_USE_INTERNAL_POLLING_THREAD,
  1316. /** @deprecated */
  1317. MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY = MHD_USE_EPOLL
  1318. | MHD_USE_INTERNAL_POLLING_THREAD,
  1319. #if 0 /* Will be marked for real deprecation later. */
  1320. #define MHD_USE_EPOLL_INTERNALLY \
  1321. _MHD_DEPR_IN_MACRO ( \
  1322. "Value MHD_USE_EPOLL_INTERNALLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \
  1323. MHD_USE_EPOLL_INTERNAL_THREAD
  1324. /** @deprecated */
  1325. #define MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY \
  1326. _MHD_DEPR_IN_MACRO ( \
  1327. "Value MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY is deprecated, use MHD_USE_EPOLL_INTERNAL_THREAD") \
  1328. MHD_USE_EPOLL_INTERNAL_THREAD
  1329. #endif /* 0 */
  1330. /**
  1331. * Use inter-thread communication channel.
  1332. * #MHD_USE_ITC can be used with #MHD_USE_INTERNAL_POLLING_THREAD
  1333. * and is ignored with any "external" sockets polling.
  1334. * It's required for use of #MHD_quiesce_daemon
  1335. * or #MHD_add_connection.
  1336. * This option is enforced by #MHD_ALLOW_SUSPEND_RESUME or
  1337. * #MHD_USE_NO_LISTEN_SOCKET.
  1338. * #MHD_USE_ITC is always used automatically on platforms
  1339. * where select()/poll()/other ignore shutdown of listen
  1340. * socket.
  1341. */
  1342. MHD_USE_ITC = 1024,
  1343. /** @deprecated */
  1344. MHD_USE_PIPE_FOR_SHUTDOWN = 1024,
  1345. #if 0 /* Will be marked for real deprecation later. */
  1346. #define MHD_USE_PIPE_FOR_SHUTDOWN \
  1347. _MHD_DEPR_IN_MACRO ( \
  1348. "Value MHD_USE_PIPE_FOR_SHUTDOWN is deprecated, use MHD_USE_ITC") \
  1349. MHD_USE_ITC
  1350. #endif /* 0 */
  1351. /**
  1352. * Use a single socket for IPv4 and IPv6.
  1353. */
  1354. MHD_USE_DUAL_STACK = MHD_USE_IPv6 | 2048,
  1355. /**
  1356. * Enable `turbo`. Disables certain calls to `shutdown()`,
  1357. * enables aggressive non-blocking optimistic reads and
  1358. * other potentially unsafe optimizations.
  1359. * Most effects only happen with #MHD_USE_EPOLL.
  1360. */
  1361. MHD_USE_TURBO = 4096,
  1362. /** @deprecated */
  1363. MHD_USE_EPOLL_TURBO = 4096,
  1364. #if 0 /* Will be marked for real deprecation later. */
  1365. #define MHD_USE_EPOLL_TURBO \
  1366. _MHD_DEPR_IN_MACRO ( \
  1367. "Value MHD_USE_EPOLL_TURBO is deprecated, use MHD_USE_TURBO") \
  1368. MHD_USE_TURBO
  1369. #endif /* 0 */
  1370. /**
  1371. * Enable suspend/resume functions, which also implies setting up
  1372. * ITC to signal resume.
  1373. */
  1374. MHD_ALLOW_SUSPEND_RESUME = 8192 | MHD_USE_ITC,
  1375. /** @deprecated */
  1376. MHD_USE_SUSPEND_RESUME = 8192 | MHD_USE_ITC,
  1377. #if 0 /* Will be marked for real deprecation later. */
  1378. #define MHD_USE_SUSPEND_RESUME \
  1379. _MHD_DEPR_IN_MACRO ( \
  1380. "Value MHD_USE_SUSPEND_RESUME is deprecated, use MHD_ALLOW_SUSPEND_RESUME instead") \
  1381. MHD_ALLOW_SUSPEND_RESUME
  1382. #endif /* 0 */
  1383. /**
  1384. * Enable TCP_FASTOPEN option. This option is only available on Linux with a
  1385. * kernel >= 3.6. On other systems, using this option cases #MHD_start_daemon
  1386. * to fail.
  1387. */
  1388. MHD_USE_TCP_FASTOPEN = 16384,
  1389. /**
  1390. * You need to set this option if you want to use HTTP "Upgrade".
  1391. * "Upgrade" may require usage of additional internal resources,
  1392. * which we do not want to use unless necessary.
  1393. */
  1394. MHD_ALLOW_UPGRADE = 32768,
  1395. /**
  1396. * Automatically use best available polling function.
  1397. * Choice of polling function is also depend on other daemon options.
  1398. * If #MHD_USE_INTERNAL_POLLING_THREAD is specified then epoll, poll() or
  1399. * select() will be used (listed in decreasing preference order, first
  1400. * function available on system will be used).
  1401. * If #MHD_USE_THREAD_PER_CONNECTION is specified then poll() or select()
  1402. * will be used.
  1403. * If those flags are not specified then epoll or select() will be
  1404. * used (as the only suitable for MHD_get_fdset())
  1405. */
  1406. MHD_USE_AUTO = 65536,
  1407. /**
  1408. * Run using an internal thread (or thread pool) with best available on
  1409. * system polling function.
  1410. * This is combination of #MHD_USE_AUTO and #MHD_USE_INTERNAL_POLLING_THREAD
  1411. * flags.
  1412. */
  1413. MHD_USE_AUTO_INTERNAL_THREAD = MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
  1414. /**
  1415. * Flag set to enable post-handshake client authentication
  1416. * (only useful in combination with #MHD_USE_TLS).
  1417. */
  1418. MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT = 1U << 17,
  1419. /**
  1420. * Flag set to enable TLS 1.3 early data. This has
  1421. * security implications, be VERY careful when using this.
  1422. */
  1423. MHD_USE_INSECURE_TLS_EARLY_DATA = 1U << 18,
  1424. /**
  1425. * Indicates that MHD daemon will be used by application in single-threaded
  1426. * mode only. When this flag is set then application must call any MHD
  1427. * function only within a single thread.
  1428. * This flag turns off some internal thread-safety and allows MHD making
  1429. * some of the internal optimisations suitable only for single-threaded
  1430. * environment.
  1431. * Not compatible with #MHD_USE_INTERNAL_POLLING_THREAD.
  1432. * @note Available since #MHD_VERSION 0x00097707
  1433. */
  1434. MHD_USE_NO_THREAD_SAFETY = 1U << 19
  1435. };
  1436. /**
  1437. * Type of a callback function used for logging by MHD.
  1438. *
  1439. * @param cls closure
  1440. * @param fm format string (`printf()`-style)
  1441. * @param ap arguments to @a fm
  1442. * @ingroup logging
  1443. */
  1444. typedef void
  1445. (*MHD_LogCallback)(void *cls,
  1446. const char *fm,
  1447. va_list ap);
  1448. /**
  1449. * Function called to lookup the pre shared key (@a psk) for a given
  1450. * HTTP connection based on the @a username.
  1451. *
  1452. * @param cls closure
  1453. * @param connection the HTTPS connection
  1454. * @param username the user name claimed by the other side
  1455. * @param[out] psk to be set to the pre-shared-key; should be allocated with malloc(),
  1456. * will be freed by MHD
  1457. * @param[out] psk_size to be set to the number of bytes in @a psk
  1458. * @return 0 on success, -1 on errors
  1459. */
  1460. typedef int
  1461. (*MHD_PskServerCredentialsCallback)(void *cls,
  1462. const struct MHD_Connection *connection,
  1463. const char *username,
  1464. void **psk,
  1465. size_t *psk_size);
  1466. /**
  1467. * Values for #MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE.
  1468. *
  1469. * These values can limit the scope of validity of MHD-generated nonces.
  1470. * Values can be combined with bitwise OR.
  1471. * Any value, except #MHD_DAUTH_BIND_NONCE_NONE, enforce function
  1472. * #MHD_digest_auth_check3() (and similar functions) to check nonce by
  1473. * re-generating it again with the same parameters, which is CPU-intensive
  1474. * operation.
  1475. * @note Available since #MHD_VERSION 0x00097701
  1476. */
  1477. enum MHD_DAuthBindNonce
  1478. {
  1479. /**
  1480. * Generated nonces are valid for any request from any client until expired.
  1481. * This is default and recommended value.
  1482. * #MHD_digest_auth_check3() (and similar functions) would check only whether
  1483. * the nonce value that is used by client has been generated by MHD and not
  1484. * expired yet.
  1485. * It is recommended because RFC 7616 allows clients to use the same nonce
  1486. * for any request in the same "protection space".
  1487. * When checking client's authorisation requests CPU is loaded less if this
  1488. * value is used.
  1489. * This mode gives MHD maximum flexibility for nonces generation and can
  1490. * prevent possible nonce collisions (and corresponding log warning messages)
  1491. * when clients' requests are intensive.
  1492. * This value cannot be biwise-OR combined with other values.
  1493. */
  1494. MHD_DAUTH_BIND_NONCE_NONE = 0,
  1495. /**
  1496. * Generated nonces are valid only for the same realm.
  1497. */
  1498. MHD_DAUTH_BIND_NONCE_REALM = 1 << 0,
  1499. /**
  1500. * Generated nonces are valid only for the same URI (excluding parameters
  1501. * after '?' in URI) and request method (GET, POST etc).
  1502. * Not recommended unless "protection space" is limited to a single URI as
  1503. * RFC 7616 allows clients to re-use server-generated nonces for any URI
  1504. * in the same "protection space" which by default consists of all server
  1505. * URIs.
  1506. * Before #MHD_VERSION 0x00097701 this was default (and only supported)
  1507. * nonce bind type.
  1508. */
  1509. MHD_DAUTH_BIND_NONCE_URI = 1 << 1,
  1510. /**
  1511. * Generated nonces are valid only for the same URI including URI parameters
  1512. * and request method (GET, POST etc).
  1513. * This value implies #MHD_DAUTH_BIND_NONCE_URI.
  1514. * Not recommended for that same reasons as #MHD_DAUTH_BIND_NONCE_URI.
  1515. */
  1516. MHD_DAUTH_BIND_NONCE_URI_PARAMS = 1 << 2,
  1517. /**
  1518. * Generated nonces are valid only for the single client's IP.
  1519. * While it looks like security improvement, in practice the same client may
  1520. * jump from one IP to another (mobile or Wi-Fi handover, DHCP re-assignment,
  1521. * Multi-NAT, different proxy chain and other reasons), while IP address
  1522. * spoofing could be used relatively easily.
  1523. */
  1524. MHD_DAUTH_BIND_NONCE_CLIENT_IP = 1 << 3
  1525. } _MHD_FLAGS_ENUM;
  1526. /**
  1527. * @brief MHD options.
  1528. *
  1529. * Passed in the varargs portion of #MHD_start_daemon.
  1530. */
  1531. enum MHD_OPTION
  1532. {
  1533. /**
  1534. * No more options / last option. This is used
  1535. * to terminate the VARARGs list.
  1536. */
  1537. MHD_OPTION_END = 0,
  1538. /**
  1539. * Maximum memory size per connection (followed by a `size_t`).
  1540. * Default is 32 kb (#MHD_POOL_SIZE_DEFAULT).
  1541. * Values above 128k are unlikely to result in much benefit, as half
  1542. * of the memory will be typically used for IO, and TCP buffers are
  1543. * unlikely to support window sizes above 64k on most systems.
  1544. * Values below 64 bytes are completely unusable.
  1545. * Since #MHD_VERSION 0x00097710 silently ignored if followed by zero value.
  1546. */
  1547. MHD_OPTION_CONNECTION_MEMORY_LIMIT = 1,
  1548. /**
  1549. * Maximum number of concurrent connections to
  1550. * accept (followed by an `unsigned int`).
  1551. */
  1552. MHD_OPTION_CONNECTION_LIMIT = 2,
  1553. /**
  1554. * After how many seconds of inactivity should a
  1555. * connection automatically be timed out? (followed
  1556. * by an `unsigned int`; use zero for no timeout).
  1557. * Values larger than (UINT64_MAX / 2000 - 1) will
  1558. * be clipped to this number.
  1559. */
  1560. MHD_OPTION_CONNECTION_TIMEOUT = 3,
  1561. /**
  1562. * Register a function that should be called whenever a request has
  1563. * been completed (this can be used for application-specific clean
  1564. * up). Requests that have never been presented to the application
  1565. * (via #MHD_AccessHandlerCallback) will not result in
  1566. * notifications.
  1567. *
  1568. * This option should be followed by TWO pointers. First a pointer
  1569. * to a function of type #MHD_RequestCompletedCallback and second a
  1570. * pointer to a closure to pass to the request completed callback.
  1571. * The second pointer may be NULL.
  1572. */
  1573. MHD_OPTION_NOTIFY_COMPLETED = 4,
  1574. /**
  1575. * Limit on the number of (concurrent) connections made to the
  1576. * server from the same IP address. Can be used to prevent one
  1577. * IP from taking over all of the allowed connections. If the
  1578. * same IP tries to establish more than the specified number of
  1579. * connections, they will be immediately rejected. The option
  1580. * should be followed by an `unsigned int`. The default is
  1581. * zero, which means no limit on the number of connections
  1582. * from the same IP address.
  1583. */
  1584. MHD_OPTION_PER_IP_CONNECTION_LIMIT = 5,
  1585. /**
  1586. * Bind daemon to the supplied `struct sockaddr`. This option should
  1587. * be followed by a `struct sockaddr *`. If #MHD_USE_IPv6 is
  1588. * specified, the `struct sockaddr*` should point to a `struct
  1589. * sockaddr_in6`, otherwise to a `struct sockaddr_in`.
  1590. * Silently ignored if followed by NULL pointer.
  1591. * @deprecated Use #MHD_OPTION_SOCK_ADDR_LEN
  1592. */
  1593. MHD_OPTION_SOCK_ADDR = 6,
  1594. /**
  1595. * Specify a function that should be called before parsing the URI from
  1596. * the client. The specified callback function can be used for processing
  1597. * the URI (including the options) before it is parsed. The URI after
  1598. * parsing will no longer contain the options, which maybe inconvenient for
  1599. * logging. This option should be followed by two arguments, the first
  1600. * one must be of the form
  1601. *
  1602. * void * my_logger(void *cls, const char *uri, struct MHD_Connection *con)
  1603. *
  1604. * where the return value will be passed as
  1605. * (`* req_cls`) in calls to the #MHD_AccessHandlerCallback
  1606. * when this request is processed later; returning a
  1607. * value of NULL has no special significance (however,
  1608. * note that if you return non-NULL, you can no longer
  1609. * rely on the first call to the access handler having
  1610. * `NULL == *req_cls` on entry;)
  1611. * "cls" will be set to the second argument following
  1612. * #MHD_OPTION_URI_LOG_CALLBACK. Finally, uri will
  1613. * be the 0-terminated URI of the request.
  1614. *
  1615. * Note that during the time of this call, most of the connection's
  1616. * state is not initialized (as we have not yet parsed the headers).
  1617. * However, information about the connecting client (IP, socket)
  1618. * is available.
  1619. *
  1620. * The specified function is called only once per request, therefore some
  1621. * programmers may use it to instantiate their own request objects, freeing
  1622. * them in the notifier #MHD_OPTION_NOTIFY_COMPLETED.
  1623. */
  1624. MHD_OPTION_URI_LOG_CALLBACK = 7,
  1625. /**
  1626. * Memory pointer for the private key (key.pem) to be used by the
  1627. * HTTPS daemon. This option should be followed by a
  1628. * `const char *` argument.
  1629. * This should be used in conjunction with #MHD_OPTION_HTTPS_MEM_CERT.
  1630. */
  1631. MHD_OPTION_HTTPS_MEM_KEY = 8,
  1632. /**
  1633. * Memory pointer for the certificate (cert.pem) to be used by the
  1634. * HTTPS daemon. This option should be followed by a
  1635. * `const char *` argument.
  1636. * This should be used in conjunction with #MHD_OPTION_HTTPS_MEM_KEY.
  1637. */
  1638. MHD_OPTION_HTTPS_MEM_CERT = 9,
  1639. /**
  1640. * Daemon credentials type.
  1641. * Followed by an argument of type
  1642. * `gnutls_credentials_type_t`.
  1643. */
  1644. MHD_OPTION_HTTPS_CRED_TYPE = 10,
  1645. /**
  1646. * Memory pointer to a `const char *` specifying the GnuTLS priorities string.
  1647. * If this options is not specified, then MHD will try the following strings:
  1648. * * "@LIBMICROHTTPD" (application-specific system-wide configuration)
  1649. * * "@SYSTEM" (system-wide configuration)
  1650. * * default GnuTLS priorities string
  1651. * * "NORMAL"
  1652. * The first configuration accepted by GnuTLS will be used.
  1653. * For more details see GnuTLS documentation for "Application-specific
  1654. * priority strings".
  1655. */
  1656. MHD_OPTION_HTTPS_PRIORITIES = 11,
  1657. /**
  1658. * Pass a listen socket for MHD to use (systemd-style). If this
  1659. * option is used, MHD will not open its own listen socket(s). The
  1660. * argument passed must be of type `MHD_socket` and refer to an
  1661. * existing socket that has been bound to a port and is listening.
  1662. * If followed by MHD_INVALID_SOCKET value, MHD ignores this option
  1663. * and creates socket by itself.
  1664. */
  1665. MHD_OPTION_LISTEN_SOCKET = 12,
  1666. /**
  1667. * Use the given function for logging error messages. This option
  1668. * must be followed by two arguments; the first must be a pointer to
  1669. * a function of type #MHD_LogCallback and the second a pointer
  1670. * `void *` which will be passed as the first argument to the log
  1671. * callback.
  1672. * Should be specified as the first option, otherwise some messages
  1673. * may be printed by standard MHD logger during daemon startup.
  1674. *
  1675. * Note that MHD will not generate any log messages
  1676. * if it was compiled without the "--enable-messages"
  1677. * flag being set.
  1678. */
  1679. MHD_OPTION_EXTERNAL_LOGGER = 13,
  1680. /**
  1681. * Number (`unsigned int`) of threads in thread pool. Enable
  1682. * thread pooling by setting this value to to something
  1683. * greater than 1.
  1684. * Can be used only for daemons started with #MHD_USE_INTERNAL_POLLING_THREAD.
  1685. * Ignored if followed by zero value.
  1686. */
  1687. MHD_OPTION_THREAD_POOL_SIZE = 14,
  1688. /**
  1689. * Additional options given in an array of `struct MHD_OptionItem`.
  1690. * The array must be terminated with an entry `{MHD_OPTION_END, 0, NULL}`.
  1691. * An example for code using #MHD_OPTION_ARRAY is:
  1692. *
  1693. * struct MHD_OptionItem ops[] = {
  1694. * { MHD_OPTION_CONNECTION_LIMIT, 100, NULL },
  1695. * { MHD_OPTION_CONNECTION_TIMEOUT, 10, NULL },
  1696. * { MHD_OPTION_END, 0, NULL }
  1697. * };
  1698. * d = MHD_start_daemon (0, 8080, NULL, NULL, dh, NULL,
  1699. * MHD_OPTION_ARRAY, ops,
  1700. * MHD_OPTION_END);
  1701. *
  1702. * For options that expect a single pointer argument, the
  1703. * 'value' member of the `struct MHD_OptionItem` is ignored.
  1704. * For options that expect two pointer arguments, the first
  1705. * argument must be cast to `intptr_t`.
  1706. */
  1707. MHD_OPTION_ARRAY = 15,
  1708. /**
  1709. * Specify a function that should be called for unescaping escape
  1710. * sequences in URIs and URI arguments. Note that this function
  1711. * will NOT be used by the `struct MHD_PostProcessor`. If this
  1712. * option is not specified, the default method will be used which
  1713. * decodes escape sequences of the form "%HH". This option should
  1714. * be followed by two arguments, the first one must be of the form
  1715. *
  1716. * size_t my_unescaper(void *cls,
  1717. * struct MHD_Connection *c,
  1718. * char *s)
  1719. *
  1720. * where the return value must be the length of the value left in
  1721. * "s" (without the 0-terminator) and "s" should be updated. Note
  1722. * that the unescape function must not lengthen "s" (the result must
  1723. * be shorter than the input and must still be 0-terminated).
  1724. * However, it may also include binary zeros before the
  1725. * 0-termination. "cls" will be set to the second argument
  1726. * following #MHD_OPTION_UNESCAPE_CALLBACK.
  1727. */
  1728. MHD_OPTION_UNESCAPE_CALLBACK = 16,
  1729. /**
  1730. * Memory pointer for the random values to be used by the Digest
  1731. * Auth module. This option should be followed by two arguments.
  1732. * First an integer of type `size_t` which specifies the size
  1733. * of the buffer pointed to by the second argument in bytes.
  1734. * The recommended size is between 8 and 32. If size is four or less
  1735. * then security could be lowered. Sizes more then 32 (or, probably
  1736. * more than 16 - debatable) will not increase security.
  1737. * Note that the application must ensure that the buffer of the
  1738. * second argument remains allocated and unmodified while the
  1739. * daemon is running.
  1740. * @sa #MHD_OPTION_DIGEST_AUTH_RANDOM_COPY
  1741. */
  1742. MHD_OPTION_DIGEST_AUTH_RANDOM = 17,
  1743. /**
  1744. * Size of the internal array holding the map of the nonce and
  1745. * the nonce counter. This option should be followed by an `unsigend int`
  1746. * argument.
  1747. * The map size is 4 by default, which is enough to communicate with
  1748. * a single client at any given moment of time, but not enough to
  1749. * handle several clients simultaneously.
  1750. * If Digest Auth is not used, this option can be set to zero to minimise
  1751. * memory allocation.
  1752. */
  1753. MHD_OPTION_NONCE_NC_SIZE = 18,
  1754. /**
  1755. * Desired size of the stack for threads created by MHD. Followed
  1756. * by an argument of type `size_t`. Use 0 for system default.
  1757. */
  1758. MHD_OPTION_THREAD_STACK_SIZE = 19,
  1759. /**
  1760. * Memory pointer for the certificate (ca.pem) to be used by the
  1761. * HTTPS daemon for client authentication.
  1762. * This option should be followed by a `const char *` argument.
  1763. */
  1764. MHD_OPTION_HTTPS_MEM_TRUST = 20,
  1765. /**
  1766. * Increment to use for growing the read buffer (followed by a
  1767. * `size_t`).
  1768. * Must not be higher than 1/4 of #MHD_OPTION_CONNECTION_MEMORY_LIMIT.
  1769. * Since #MHD_VERSION 0x00097710 silently ignored if followed by zero value.
  1770. */
  1771. MHD_OPTION_CONNECTION_MEMORY_INCREMENT = 21,
  1772. /**
  1773. * Use a callback to determine which X.509 certificate should be
  1774. * used for a given HTTPS connection. This option should be
  1775. * followed by a argument of type `gnutls_certificate_retrieve_function2 *`.
  1776. * This option provides an
  1777. * alternative to #MHD_OPTION_HTTPS_MEM_KEY,
  1778. * #MHD_OPTION_HTTPS_MEM_CERT. You must use this version if
  1779. * multiple domains are to be hosted at the same IP address using
  1780. * TLS's Server Name Indication (SNI) extension. In this case,
  1781. * the callback is expected to select the correct certificate
  1782. * based on the SNI information provided. The callback is expected
  1783. * to access the SNI data using `gnutls_server_name_get()`.
  1784. * Using this option requires GnuTLS 3.0 or higher.
  1785. */
  1786. MHD_OPTION_HTTPS_CERT_CALLBACK = 22,
  1787. /**
  1788. * When using #MHD_USE_TCP_FASTOPEN, this option changes the default TCP
  1789. * fastopen queue length of 50. Note that having a larger queue size can
  1790. * cause resource exhaustion attack as the TCP stack has to now allocate
  1791. * resources for the SYN packet along with its DATA. This option should be
  1792. * followed by an `unsigned int` argument.
  1793. */
  1794. MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE = 23,
  1795. /**
  1796. * Memory pointer for the Diffie-Hellman parameters (dh.pem) to be used by the
  1797. * HTTPS daemon for key exchange.
  1798. * This option must be followed by a `const char *` argument.
  1799. */
  1800. MHD_OPTION_HTTPS_MEM_DHPARAMS = 24,
  1801. /**
  1802. * If present and set to true, allow reusing address:port socket
  1803. * (by using SO_REUSEPORT on most platform, or platform-specific ways).
  1804. * If present and set to false, disallow reusing address:port socket
  1805. * (does nothing on most platform, but uses SO_EXCLUSIVEADDRUSE on Windows).
  1806. * This option must be followed by a `unsigned int` argument.
  1807. */
  1808. MHD_OPTION_LISTENING_ADDRESS_REUSE = 25,
  1809. /**
  1810. * Memory pointer for a password that decrypts the private key (key.pem)
  1811. * to be used by the HTTPS daemon. This option should be followed by a
  1812. * `const char *` argument.
  1813. * This should be used in conjunction with #MHD_OPTION_HTTPS_MEM_KEY.
  1814. * @sa ::MHD_FEATURE_HTTPS_KEY_PASSWORD
  1815. */
  1816. MHD_OPTION_HTTPS_KEY_PASSWORD = 26,
  1817. /**
  1818. * Register a function that should be called whenever a connection is
  1819. * started or closed.
  1820. *
  1821. * This option should be followed by TWO pointers. First a pointer
  1822. * to a function of type #MHD_NotifyConnectionCallback and second a
  1823. * pointer to a closure to pass to the request completed callback.
  1824. * The second pointer may be NULL.
  1825. */
  1826. MHD_OPTION_NOTIFY_CONNECTION = 27,
  1827. /**
  1828. * Allow to change maximum length of the queue of pending connections on
  1829. * listen socket. If not present than default platform-specific SOMAXCONN
  1830. * value is used. This option should be followed by an `unsigned int`
  1831. * argument.
  1832. */
  1833. MHD_OPTION_LISTEN_BACKLOG_SIZE = 28,
  1834. /**
  1835. * If set to 1 - be strict about the protocol. Use -1 to be
  1836. * as tolerant as possible.
  1837. *
  1838. * The more flexible option #MHD_OPTION_CLIENT_DISCIPLINE_LVL is recommended
  1839. * instead of this option.
  1840. *
  1841. * The values mapping table:
  1842. * #MHD_OPTION_STRICT_FOR_CLIENT | #MHD_OPTION_CLIENT_DISCIPLINE_LVL
  1843. * -----------------------------:|:---------------------------------
  1844. * 1 | 1
  1845. * 0 | 0
  1846. * -1 | -3
  1847. *
  1848. * This option should be followed by an `int` argument.
  1849. * @sa #MHD_OPTION_CLIENT_DISCIPLINE_LVL
  1850. */
  1851. MHD_OPTION_STRICT_FOR_CLIENT = 29,
  1852. /**
  1853. * This should be a pointer to callback of type
  1854. * gnutls_psk_server_credentials_function that will be given to
  1855. * gnutls_psk_set_server_credentials_function. It is used to
  1856. * retrieve the shared key for a given username.
  1857. */
  1858. MHD_OPTION_GNUTLS_PSK_CRED_HANDLER = 30,
  1859. /**
  1860. * Use a callback to determine which X.509 certificate should be
  1861. * used for a given HTTPS connection. This option should be
  1862. * followed by a argument of type `gnutls_certificate_retrieve_function3 *`.
  1863. * This option provides an
  1864. * alternative/extension to #MHD_OPTION_HTTPS_CERT_CALLBACK.
  1865. * You must use this version if you want to use OCSP stapling.
  1866. * Using this option requires GnuTLS 3.6.3 or higher.
  1867. */
  1868. MHD_OPTION_HTTPS_CERT_CALLBACK2 = 31,
  1869. /**
  1870. * Allows the application to disable certain sanity precautions
  1871. * in MHD. With these, the client can break the HTTP protocol,
  1872. * so this should never be used in production. The options are,
  1873. * however, useful for testing HTTP clients against "broken"
  1874. * server implementations.
  1875. * This argument must be followed by an "unsigned int", corresponding
  1876. * to an `enum MHD_DisableSanityCheck`.
  1877. */
  1878. MHD_OPTION_SERVER_INSANITY = 32,
  1879. /**
  1880. * If followed by value '1' informs MHD that SIGPIPE is suppressed or
  1881. * handled by application. Allows MHD to use network functions that could
  1882. * generate SIGPIPE, like `sendfile()`.
  1883. * Valid only for daemons without #MHD_USE_INTERNAL_POLLING_THREAD as
  1884. * MHD automatically suppresses SIGPIPE for threads started by MHD.
  1885. * This option should be followed by an `int` argument.
  1886. * @note Available since #MHD_VERSION 0x00097205
  1887. */
  1888. MHD_OPTION_SIGPIPE_HANDLED_BY_APP = 33,
  1889. /**
  1890. * If followed by 'int' with value '1' disables usage of ALPN for TLS
  1891. * connections even if supported by TLS library.
  1892. * Valid only for daemons with #MHD_USE_TLS.
  1893. * This option should be followed by an `int` argument.
  1894. * @note Available since #MHD_VERSION 0x00097207
  1895. */
  1896. MHD_OPTION_TLS_NO_ALPN = 34,
  1897. /**
  1898. * Memory pointer for the random values to be used by the Digest
  1899. * Auth module. This option should be followed by two arguments.
  1900. * First an integer of type `size_t` which specifies the size
  1901. * of the buffer pointed to by the second argument in bytes.
  1902. * The recommended size is between 8 and 32. If size is four or less
  1903. * then security could be lowered. Sizes more then 32 (or, probably
  1904. * more than 16 - debatable) will not increase security.
  1905. * An internal copy of the buffer will be made, the data do not
  1906. * need to be static.
  1907. * @sa #MHD_OPTION_DIGEST_AUTH_RANDOM
  1908. * @note Available since #MHD_VERSION 0x00097701
  1909. */
  1910. MHD_OPTION_DIGEST_AUTH_RANDOM_COPY = 35,
  1911. /**
  1912. * Allow to controls the scope of validity of MHD-generated nonces.
  1913. * This regulates how "nonces" are generated and how "nonces" are checked by
  1914. * #MHD_digest_auth_check3() and similar functions.
  1915. * This option should be followed by an 'unsigned int` argument with value
  1916. * formed as bitwise OR combination of #MHD_DAuthBindNonce values.
  1917. * When not specified, default value #MHD_DAUTH_BIND_NONCE_NONE is used.
  1918. * @note Available since #MHD_VERSION 0x00097701
  1919. */
  1920. MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE = 36,
  1921. /**
  1922. * Memory pointer to a `const char *` specifying the GnuTLS priorities to be
  1923. * appended to default priorities.
  1924. * This allow some specific options to be enabled/disabled, while leaving
  1925. * the rest of the settings to their defaults.
  1926. * The string does not have to start with a colon ':' character.
  1927. * See #MHD_OPTION_HTTPS_PRIORITIES description for details of automatic
  1928. * default priorities.
  1929. * @note Available since #MHD_VERSION 0x00097701
  1930. */
  1931. MHD_OPTION_HTTPS_PRIORITIES_APPEND = 37,
  1932. /**
  1933. * Sets specified client discipline level (i.e. HTTP protocol parsing
  1934. * strictness level).
  1935. *
  1936. * The following basic values are supported:
  1937. * 0 - default MHD level, a balance between extra security and broader
  1938. * compatibility, as allowed by RFCs for HTTP servers;
  1939. * 1 - more strict protocol interpretation, within the limits set by
  1940. * RFCs for HTTP servers;
  1941. * -1 - more lenient protocol interpretation, within the limits set by
  1942. * RFCs for HTTP servers.
  1943. * The following extended values could be used as well:
  1944. * 2 - stricter protocol interpretation, even stricter then allowed
  1945. * by RFCs for HTTP servers, however it should be absolutely compatible
  1946. * with clients following at least RFCs' "MUST" type of requirements
  1947. * for HTTP clients;
  1948. * 3 - strictest protocol interpretation, even stricter then allowed
  1949. * by RFCs for HTTP servers, however it should be absolutely compatible
  1950. * with clients following RFCs' "SHOULD" and "MUST" types of requirements
  1951. * for HTTP clients;
  1952. * -2 - more relaxed protocol interpretation, violating RFCs' "SHOULD" type
  1953. * of requirements for HTTP servers;
  1954. * -3 - the most flexible protocol interpretation, beyond RFCs' "MUST" type of
  1955. * requirements for HTTP server.
  1956. * Values higher than "3" or lower than "-3" are interpreted as "3" or "-3"
  1957. * respectively.
  1958. *
  1959. * Higher values are more secure, lower values are more compatible with
  1960. * various HTTP clients.
  1961. *
  1962. * The default value ("0") could be used in most cases.
  1963. * Value "1" is suitable for highly loaded public servers.
  1964. * Values "2" and "3" are generally recommended only for testing of HTTP
  1965. * clients against MHD.
  1966. * Value "2" may be used for security-centric application, however it is
  1967. * slight violation of RFCs' requirements.
  1968. * Negative values are not recommended for public servers.
  1969. * Values "-1" and "-2" could be used for servers in isolated environment.
  1970. * Value "-3" is not recommended unless it is absolutely necessary to
  1971. * communicate with some client(s) with badly broken HTTP implementation.
  1972. *
  1973. * This option should be followed by an `int` argument.
  1974. * @note Available since #MHD_VERSION 0x00097701
  1975. */
  1976. MHD_OPTION_CLIENT_DISCIPLINE_LVL = 38,
  1977. /**
  1978. * Specifies value of FD_SETSIZE used by application. Only For external
  1979. * polling modes (without MHD internal threads).
  1980. * Some platforms (FreeBSD, Solaris, W32 etc.) allow overriding of FD_SETSIZE
  1981. * value. When polling by select() is used, MHD rejects sockets with numbers
  1982. * equal or higher than FD_SETSIZE. If this option is used, MHD treats this
  1983. * value as a limitation for socket number instead of FD_SETSIZE value which
  1984. * was used for building MHD.
  1985. * When external polling is used with #MHD_get_fdset2() (or #MHD_get_fdset()
  1986. * macro) and #MHD_run_from_select() interfaces, it is recommended to always
  1987. * use this option.
  1988. * It is safe to use this option on platforms with fixed FD_SETSIZE (like
  1989. * GNU/Linux) if system value of FD_SETSIZE is used as the argument.
  1990. * Can be used only for daemons without #MHD_USE_INTERNAL_POLLING_THREAD, i.e.
  1991. * only when external sockets polling is used.
  1992. * On W32 it is silently ignored, as W32 does not limit the socket number in
  1993. * fd_sets.
  1994. * This option should be followed by a positive 'int' argument.
  1995. * @note Available since #MHD_VERSION 0x00097705
  1996. */
  1997. MHD_OPTION_APP_FD_SETSIZE = 39,
  1998. /**
  1999. * Bind daemon to the supplied 'struct sockaddr'. This option should
  2000. * be followed by two parameters: 'socklen_t' the size of memory at the next
  2001. * pointer and the pointer 'const struct sockaddr *'.
  2002. * Note: the order of the arguments is not the same as for system bind() and
  2003. * other network functions.
  2004. * If #MHD_USE_IPv6 is specified, the 'struct sockaddr*' should
  2005. * point to a 'struct sockaddr_in6'.
  2006. * The socket domain (protocol family) is detected from provided
  2007. * 'struct sockaddr'. IP, IPv6 and UNIX sockets are supported (if supported
  2008. * by the platform). Other types may work occasionally.
  2009. * Silently ignored if followed by zero size and NULL pointer.
  2010. * @note Available since #MHD_VERSION 0x00097706
  2011. */
  2012. MHD_OPTION_SOCK_ADDR_LEN = 40
  2013. ,
  2014. /**
  2015. * Default nonce timeout value used for Digest Auth.
  2016. * This option should be followed by an 'unsigned int' argument.
  2017. * Silently ignored if followed by zero value.
  2018. * @see #MHD_digest_auth_check3(), MHD_digest_auth_check_digest3()
  2019. * @note Available since #MHD_VERSION 0x00097709
  2020. */
  2021. MHD_OPTION_DIGEST_AUTH_DEFAULT_NONCE_TIMEOUT = 41
  2022. ,
  2023. /**
  2024. * Default maximum nc (nonce count) value used for Digest Auth.
  2025. * This option should be followed by an 'uint32_t' argument.
  2026. * Silently ignored if followed by zero value.
  2027. * @see #MHD_digest_auth_check3(), MHD_digest_auth_check_digest3()
  2028. * @note Available since #MHD_VERSION 0x00097709
  2029. */
  2030. MHD_OPTION_DIGEST_AUTH_DEFAULT_MAX_NC = 42
  2031. } _MHD_FIXED_ENUM;
  2032. /**
  2033. * Bitfield for the #MHD_OPTION_SERVER_INSANITY specifying
  2034. * which santiy checks should be disabled.
  2035. */
  2036. enum MHD_DisableSanityCheck
  2037. {
  2038. /**
  2039. * All sanity checks are enabled.
  2040. */
  2041. MHD_DSC_SANE = 0
  2042. } _MHD_FIXED_FLAGS_ENUM;
  2043. /**
  2044. * Entry in an #MHD_OPTION_ARRAY.
  2045. */
  2046. struct MHD_OptionItem
  2047. {
  2048. /**
  2049. * Which option is being given. Use #MHD_OPTION_END
  2050. * to terminate the array.
  2051. */
  2052. enum MHD_OPTION option;
  2053. /**
  2054. * Option value (for integer arguments, and for options requiring
  2055. * two pointer arguments); should be 0 for options that take no
  2056. * arguments or only a single pointer argument.
  2057. */
  2058. intptr_t value;
  2059. /**
  2060. * Pointer option value (use NULL for options taking no arguments
  2061. * or only an integer option).
  2062. */
  2063. void *ptr_value;
  2064. };
  2065. /**
  2066. * The `enum MHD_ValueKind` specifies the source of
  2067. * the key-value pairs in the HTTP protocol.
  2068. */
  2069. enum MHD_ValueKind
  2070. {
  2071. /**
  2072. * Response header
  2073. * @deprecated
  2074. */
  2075. MHD_RESPONSE_HEADER_KIND = 0,
  2076. #define MHD_RESPONSE_HEADER_KIND \
  2077. _MHD_DEPR_IN_MACRO ( \
  2078. "Value MHD_RESPONSE_HEADER_KIND is deprecated and not used") \
  2079. MHD_RESPONSE_HEADER_KIND
  2080. /**
  2081. * HTTP header (request/response).
  2082. */
  2083. MHD_HEADER_KIND = 1,
  2084. /**
  2085. * Cookies. Note that the original HTTP header containing
  2086. * the cookie(s) will still be available and intact.
  2087. */
  2088. MHD_COOKIE_KIND = 2,
  2089. /**
  2090. * POST data. This is available only if a content encoding
  2091. * supported by MHD is used (currently only URL encoding),
  2092. * and only if the posted content fits within the available
  2093. * memory pool. Note that in that case, the upload data
  2094. * given to the #MHD_AccessHandlerCallback will be
  2095. * empty (since it has already been processed).
  2096. */
  2097. MHD_POSTDATA_KIND = 4,
  2098. /**
  2099. * GET (URI) arguments.
  2100. */
  2101. MHD_GET_ARGUMENT_KIND = 8,
  2102. /**
  2103. * HTTP footer (only for HTTP 1.1 chunked encodings).
  2104. */
  2105. MHD_FOOTER_KIND = 16
  2106. } _MHD_FIXED_ENUM;
  2107. /**
  2108. * The `enum MHD_RequestTerminationCode` specifies reasons
  2109. * why a request has been terminated (or completed).
  2110. * @ingroup request
  2111. */
  2112. enum MHD_RequestTerminationCode
  2113. {
  2114. /**
  2115. * We finished sending the response.
  2116. * @ingroup request
  2117. */
  2118. MHD_REQUEST_TERMINATED_COMPLETED_OK = 0,
  2119. /**
  2120. * Error handling the connection (resources
  2121. * exhausted, application error accepting request,
  2122. * decrypt error (for HTTPS), connection died when
  2123. * sending the response etc.)
  2124. * @ingroup request
  2125. */
  2126. MHD_REQUEST_TERMINATED_WITH_ERROR = 1,
  2127. /**
  2128. * No activity on the connection for the number
  2129. * of seconds specified using
  2130. * #MHD_OPTION_CONNECTION_TIMEOUT.
  2131. * @ingroup request
  2132. */
  2133. MHD_REQUEST_TERMINATED_TIMEOUT_REACHED = 2,
  2134. /**
  2135. * We had to close the session since MHD was being
  2136. * shut down.
  2137. * @ingroup request
  2138. */
  2139. MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3,
  2140. /**
  2141. * We tried to read additional data, but the connection became broken or
  2142. * the other side hard closed the connection.
  2143. * This error is similar to #MHD_REQUEST_TERMINATED_WITH_ERROR, but
  2144. * specific to the case where the connection died before request completely
  2145. * received.
  2146. * @ingroup request
  2147. */
  2148. MHD_REQUEST_TERMINATED_READ_ERROR = 4,
  2149. /**
  2150. * The client terminated the connection by closing the socket
  2151. * for writing (TCP half-closed) while still sending request.
  2152. * @ingroup request
  2153. */
  2154. MHD_REQUEST_TERMINATED_CLIENT_ABORT = 5
  2155. } _MHD_FIXED_ENUM;
  2156. /**
  2157. * The `enum MHD_ConnectionNotificationCode` specifies types
  2158. * of connection notifications.
  2159. * @ingroup request
  2160. */
  2161. enum MHD_ConnectionNotificationCode
  2162. {
  2163. /**
  2164. * A new connection has been started.
  2165. * @ingroup request
  2166. */
  2167. MHD_CONNECTION_NOTIFY_STARTED = 0,
  2168. /**
  2169. * A connection is closed.
  2170. * @ingroup request
  2171. */
  2172. MHD_CONNECTION_NOTIFY_CLOSED = 1
  2173. } _MHD_FIXED_ENUM;
  2174. /**
  2175. * Information about a connection.
  2176. */
  2177. union MHD_ConnectionInfo
  2178. {
  2179. /**
  2180. * Cipher algorithm used, of type "enum gnutls_cipher_algorithm".
  2181. */
  2182. int /* enum gnutls_cipher_algorithm */ cipher_algorithm;
  2183. /**
  2184. * Protocol used, of type "enum gnutls_protocol".
  2185. */
  2186. int /* enum gnutls_protocol */ protocol;
  2187. /**
  2188. * The suspended status of a connection.
  2189. */
  2190. int /* MHD_YES or MHD_NO */ suspended;
  2191. /**
  2192. * Amount of second that connection could spend in idle state
  2193. * before automatically disconnected.
  2194. * Zero for no timeout (unlimited idle time).
  2195. */
  2196. unsigned int connection_timeout;
  2197. /**
  2198. * HTTP status queued with the response, for #MHD_CONNECTION_INFO_HTTP_STATUS.
  2199. */
  2200. unsigned int http_status;
  2201. /**
  2202. * Connect socket
  2203. */
  2204. MHD_socket connect_fd;
  2205. /**
  2206. * Size of the client's HTTP header.
  2207. * It includes the request line, all request headers, the header section
  2208. * terminating empty line, with all CRLF (or LF) characters.
  2209. */
  2210. size_t header_size;
  2211. /**
  2212. * GNUtls session handle, of type "gnutls_session_t".
  2213. */
  2214. void * /* gnutls_session_t */ tls_session;
  2215. /**
  2216. * GNUtls client certificate handle, of type "gnutls_x509_crt_t".
  2217. */
  2218. void * /* gnutls_x509_crt_t */ client_cert;
  2219. /**
  2220. * Address information for the client.
  2221. */
  2222. struct sockaddr *client_addr;
  2223. /**
  2224. * Which daemon manages this connection (useful in case there are many
  2225. * daemons running).
  2226. */
  2227. struct MHD_Daemon *daemon;
  2228. /**
  2229. * Socket-specific client context. Points to the same address as
  2230. * the "socket_context" of the #MHD_NotifyConnectionCallback.
  2231. */
  2232. void *socket_context;
  2233. };
  2234. /**
  2235. * I/O vector type. Provided for use with #MHD_create_response_from_iovec().
  2236. * @note Available since #MHD_VERSION 0x00097204
  2237. */
  2238. struct MHD_IoVec
  2239. {
  2240. /**
  2241. * The pointer to the memory region for I/O.
  2242. */
  2243. const void *iov_base;
  2244. /**
  2245. * The size in bytes of the memory region for I/O.
  2246. */
  2247. size_t iov_len;
  2248. };
  2249. /**
  2250. * Values of this enum are used to specify what
  2251. * information about a connection is desired.
  2252. * @ingroup request
  2253. */
  2254. enum MHD_ConnectionInfoType
  2255. {
  2256. /**
  2257. * What cipher algorithm is being used.
  2258. * Takes no extra arguments.
  2259. * @ingroup request
  2260. */
  2261. MHD_CONNECTION_INFO_CIPHER_ALGO,
  2262. /**
  2263. *
  2264. * Takes no extra arguments.
  2265. * @ingroup request
  2266. */
  2267. MHD_CONNECTION_INFO_PROTOCOL,
  2268. /**
  2269. * Obtain IP address of the client. Takes no extra arguments.
  2270. * Returns essentially a `struct sockaddr **` (since the API returns
  2271. * a `union MHD_ConnectionInfo *` and that union contains a `struct
  2272. * sockaddr *`).
  2273. * @ingroup request
  2274. */
  2275. MHD_CONNECTION_INFO_CLIENT_ADDRESS,
  2276. /**
  2277. * Get the gnuTLS session handle.
  2278. * @ingroup request
  2279. */
  2280. MHD_CONNECTION_INFO_GNUTLS_SESSION,
  2281. /**
  2282. * Get the gnuTLS client certificate handle. Dysfunctional (never
  2283. * implemented, deprecated). Use #MHD_CONNECTION_INFO_GNUTLS_SESSION
  2284. * to get the `gnutls_session_t` and then call
  2285. * gnutls_certificate_get_peers().
  2286. */
  2287. MHD_CONNECTION_INFO_GNUTLS_CLIENT_CERT,
  2288. /**
  2289. * Get the `struct MHD_Daemon *` responsible for managing this connection.
  2290. * @ingroup request
  2291. */
  2292. MHD_CONNECTION_INFO_DAEMON,
  2293. /**
  2294. * Request the file descriptor for the connection socket.
  2295. * MHD sockets are always in non-blocking mode.
  2296. * No extra arguments should be passed.
  2297. * @ingroup request
  2298. */
  2299. MHD_CONNECTION_INFO_CONNECTION_FD,
  2300. /**
  2301. * Returns the client-specific pointer to a `void *` that was (possibly)
  2302. * set during a #MHD_NotifyConnectionCallback when the socket was
  2303. * first accepted.
  2304. * Note that this is NOT the same as the "req_cls" argument of
  2305. * the #MHD_AccessHandlerCallback. The "req_cls" is fresh for each
  2306. * HTTP request, while the "socket_context" is fresh for each socket.
  2307. */
  2308. MHD_CONNECTION_INFO_SOCKET_CONTEXT,
  2309. /**
  2310. * Check whether the connection is suspended.
  2311. * @ingroup request
  2312. */
  2313. MHD_CONNECTION_INFO_CONNECTION_SUSPENDED,
  2314. /**
  2315. * Get connection timeout
  2316. * @ingroup request
  2317. */
  2318. MHD_CONNECTION_INFO_CONNECTION_TIMEOUT,
  2319. /**
  2320. * Return length of the client's HTTP request header.
  2321. * @ingroup request
  2322. */
  2323. MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE,
  2324. /**
  2325. * Return HTTP status queued with the response. NULL
  2326. * if no HTTP response has been queued yet.
  2327. */
  2328. MHD_CONNECTION_INFO_HTTP_STATUS
  2329. } _MHD_FIXED_ENUM;
  2330. /**
  2331. * Values of this enum are used to specify what
  2332. * information about a daemon is desired.
  2333. */
  2334. enum MHD_DaemonInfoType
  2335. {
  2336. /**
  2337. * No longer supported (will return NULL).
  2338. */
  2339. MHD_DAEMON_INFO_KEY_SIZE,
  2340. /**
  2341. * No longer supported (will return NULL).
  2342. */
  2343. MHD_DAEMON_INFO_MAC_KEY_SIZE,
  2344. /**
  2345. * Request the file descriptor for the listening socket.
  2346. * No extra arguments should be passed.
  2347. */
  2348. MHD_DAEMON_INFO_LISTEN_FD,
  2349. /**
  2350. * Request the file descriptor for the "external" sockets polling
  2351. * when 'epoll' mode is used.
  2352. * No extra arguments should be passed.
  2353. *
  2354. * Waiting on epoll FD must not block longer than value
  2355. * returned by #MHD_get_timeout() otherwise connections
  2356. * will "hung" with unprocessed data in network buffers
  2357. * and timed-out connections will not be closed.
  2358. *
  2359. * @sa #MHD_get_timeout(), #MHD_run()
  2360. */
  2361. MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY,
  2362. MHD_DAEMON_INFO_EPOLL_FD = MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY,
  2363. /**
  2364. * Request the number of current connections handled by the daemon.
  2365. * No extra arguments should be passed.
  2366. * Note: when using MHD in "external" polling mode, this type of request
  2367. * could be used only when #MHD_run()/#MHD_run_from_select is not
  2368. * working in other thread at the same time.
  2369. */
  2370. MHD_DAEMON_INFO_CURRENT_CONNECTIONS,
  2371. /**
  2372. * Request the daemon flags.
  2373. * No extra arguments should be passed.
  2374. * Note: flags may differ from original 'flags' specified for
  2375. * daemon, especially if #MHD_USE_AUTO was set.
  2376. */
  2377. MHD_DAEMON_INFO_FLAGS,
  2378. /**
  2379. * Request the port number of daemon's listen socket.
  2380. * No extra arguments should be passed.
  2381. * Note: if port '0' was specified for #MHD_start_daemon(), returned
  2382. * value will be real port number.
  2383. */
  2384. MHD_DAEMON_INFO_BIND_PORT
  2385. } _MHD_FIXED_ENUM;
  2386. /**
  2387. * Callback for serious error condition. The default action is to print
  2388. * an error message and `abort()`.
  2389. *
  2390. * @param cls user specified value
  2391. * @param file where the error occurred, may be NULL if MHD was built without
  2392. * messages support
  2393. * @param line where the error occurred
  2394. * @param reason error detail, may be NULL
  2395. * @ingroup logging
  2396. */
  2397. typedef void
  2398. (*MHD_PanicCallback) (void *cls,
  2399. const char *file,
  2400. unsigned int line,
  2401. const char *reason);
  2402. /**
  2403. * Allow or deny a client to connect.
  2404. *
  2405. * @param cls closure
  2406. * @param addr address information from the client
  2407. * @param addrlen length of @a addr
  2408. * @return #MHD_YES if connection is allowed, #MHD_NO if not
  2409. */
  2410. typedef enum MHD_Result
  2411. (*MHD_AcceptPolicyCallback)(void *cls,
  2412. const struct sockaddr *addr,
  2413. socklen_t addrlen);
  2414. /**
  2415. * A client has requested the given @a url using the given @a method
  2416. * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, #MHD_HTTP_METHOD_DELETE,
  2417. * #MHD_HTTP_METHOD_POST, etc).
  2418. *
  2419. * The callback must call MHD function MHD_queue_response() to provide content
  2420. * to give back to the client and return an HTTP status code (i.e.
  2421. * #MHD_HTTP_OK, #MHD_HTTP_NOT_FOUND, etc.). The response can be created
  2422. * in this callback or prepared in advance.
  2423. * Alternatively, callback may call MHD_suspend_connection() to temporarily
  2424. * suspend data processing for this connection.
  2425. *
  2426. * As soon as response is provided this callback will not be called anymore
  2427. * for the current request.
  2428. *
  2429. * For each HTTP request this callback is called several times:
  2430. * * after request headers are fully received and decoded,
  2431. * * for each received part of request body (optional, if request has body),
  2432. * * when request is fully received.
  2433. *
  2434. * If response is provided before request is fully received, the rest
  2435. * of the request is discarded and connection is automatically closed
  2436. * after sending response.
  2437. *
  2438. * If the request is fully received, but response hasn't been provided and
  2439. * connection is not suspended, the callback can be called again immediately.
  2440. *
  2441. * The response cannot be queued when this callback is called to process
  2442. * the client upload data (when @a upload_data is not NULL).
  2443. *
  2444. * @param cls argument given together with the function
  2445. * pointer when the handler was registered with MHD
  2446. * @param connection the connection handle
  2447. * @param url the requested url
  2448. * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
  2449. * #MHD_HTTP_METHOD_PUT, etc.)
  2450. * @param version the HTTP version string (i.e.
  2451. * #MHD_HTTP_VERSION_1_1)
  2452. * @param upload_data the data being uploaded (excluding HEADERS,
  2453. * for a POST that fits into memory and that is encoded
  2454. * with a supported encoding, the POST data will NOT be
  2455. * given in upload_data and is instead available as
  2456. * part of #MHD_get_connection_values; very large POST
  2457. * data *will* be made available incrementally in
  2458. * @a upload_data)
  2459. * @param[in,out] upload_data_size set initially to the size of the
  2460. * @a upload_data provided; the method must update this
  2461. * value to the number of bytes NOT processed;
  2462. * @param[in,out] req_cls pointer that the callback can set to some
  2463. * address and that will be preserved by MHD for future
  2464. * calls for this request; since the access handler may
  2465. * be called many times (i.e., for a PUT/POST operation
  2466. * with plenty of upload data) this allows the application
  2467. * to easily associate some request-specific state.
  2468. * If necessary, this state can be cleaned up in the
  2469. * global #MHD_RequestCompletedCallback (which
  2470. * can be set with the #MHD_OPTION_NOTIFY_COMPLETED).
  2471. * Initially, `*req_cls` will be NULL.
  2472. * @return #MHD_YES if the connection was handled successfully,
  2473. * #MHD_NO if the socket must be closed due to a serious
  2474. * error while handling the request
  2475. *
  2476. * @sa #MHD_queue_response()
  2477. */
  2478. typedef enum MHD_Result
  2479. (*MHD_AccessHandlerCallback)(void *cls,
  2480. struct MHD_Connection *connection,
  2481. const char *url,
  2482. const char *method,
  2483. const char *version,
  2484. const char *upload_data,
  2485. size_t *upload_data_size,
  2486. void **req_cls);
  2487. /**
  2488. * Signature of the callback used by MHD to notify the
  2489. * application about completed requests.
  2490. *
  2491. * @param cls client-defined closure
  2492. * @param connection connection handle
  2493. * @param req_cls value as set by the last call to
  2494. * the #MHD_AccessHandlerCallback
  2495. * @param toe reason for request termination
  2496. * @see #MHD_OPTION_NOTIFY_COMPLETED
  2497. * @ingroup request
  2498. */
  2499. typedef void
  2500. (*MHD_RequestCompletedCallback) (void *cls,
  2501. struct MHD_Connection *connection,
  2502. void **req_cls,
  2503. enum MHD_RequestTerminationCode toe);
  2504. /**
  2505. * Signature of the callback used by MHD to notify the
  2506. * application about started/stopped connections
  2507. *
  2508. * @param cls client-defined closure
  2509. * @param connection connection handle
  2510. * @param socket_context socket-specific pointer where the
  2511. * client can associate some state specific
  2512. * to the TCP connection; note that this is
  2513. * different from the "req_cls" which is per
  2514. * HTTP request. The client can initialize
  2515. * during #MHD_CONNECTION_NOTIFY_STARTED and
  2516. * cleanup during #MHD_CONNECTION_NOTIFY_CLOSED
  2517. * and access in the meantime using
  2518. * #MHD_CONNECTION_INFO_SOCKET_CONTEXT.
  2519. * @param toe reason for connection notification
  2520. * @see #MHD_OPTION_NOTIFY_CONNECTION
  2521. * @ingroup request
  2522. */
  2523. typedef void
  2524. (*MHD_NotifyConnectionCallback) (void *cls,
  2525. struct MHD_Connection *connection,
  2526. void **socket_context,
  2527. enum MHD_ConnectionNotificationCode toe);
  2528. /**
  2529. * Iterator over key-value pairs. This iterator
  2530. * can be used to iterate over all of the cookies,
  2531. * headers, or POST-data fields of a request, and
  2532. * also to iterate over the headers that have been
  2533. * added to a response.
  2534. *
  2535. * @param cls closure
  2536. * @param kind kind of the header we are looking at
  2537. * @param key key for the value, can be an empty string
  2538. * @param value corresponding value, can be NULL
  2539. * @return #MHD_YES to continue iterating,
  2540. * #MHD_NO to abort the iteration
  2541. * @ingroup request
  2542. */
  2543. typedef enum MHD_Result
  2544. (*MHD_KeyValueIterator)(void *cls,
  2545. enum MHD_ValueKind kind,
  2546. const char *key,
  2547. const char *value);
  2548. /**
  2549. * Iterator over key-value pairs with size parameters.
  2550. * This iterator can be used to iterate over all of
  2551. * the cookies, headers, or POST-data fields of a
  2552. * request, and also to iterate over the headers that
  2553. * have been added to a response.
  2554. * @note Available since #MHD_VERSION 0x00096303
  2555. *
  2556. * @param cls closure
  2557. * @param kind kind of the header we are looking at
  2558. * @param key key for the value, can be an empty string
  2559. * @param value corresponding value, can be NULL
  2560. * @param value_size number of bytes in @a value;
  2561. * for C-strings, the length excludes the 0-terminator
  2562. * @return #MHD_YES to continue iterating,
  2563. * #MHD_NO to abort the iteration
  2564. * @ingroup request
  2565. */
  2566. typedef enum MHD_Result
  2567. (*MHD_KeyValueIteratorN)(void *cls,
  2568. enum MHD_ValueKind kind,
  2569. const char *key,
  2570. size_t key_size,
  2571. const char *value,
  2572. size_t value_size);
  2573. /**
  2574. * Callback used by libmicrohttpd in order to obtain content.
  2575. *
  2576. * The callback is to copy at most @a max bytes of content into @a buf.
  2577. * The total number of bytes that has been placed into @a buf should be
  2578. * returned.
  2579. *
  2580. * Note that returning zero will cause libmicrohttpd to try again.
  2581. * Thus, returning zero should only be used in conjunction
  2582. * with MHD_suspend_connection() to avoid busy waiting.
  2583. *
  2584. * @param cls extra argument to the callback
  2585. * @param pos position in the datastream to access;
  2586. * note that if a `struct MHD_Response` object is re-used,
  2587. * it is possible for the same content reader to
  2588. * be queried multiple times for the same data;
  2589. * however, if a `struct MHD_Response` is not re-used,
  2590. * libmicrohttpd guarantees that "pos" will be
  2591. * the sum of all non-negative return values
  2592. * obtained from the content reader so far.
  2593. * @param buf where to copy the data
  2594. * @param max maximum number of bytes to copy to @a buf (size of @a buf)
  2595. * @return number of bytes written to @a buf;
  2596. * 0 is legal unless MHD is started in "internal" sockets polling mode
  2597. * (since this would cause busy-waiting); 0 in "external" sockets
  2598. * polling mode will cause this function to be called again once
  2599. * any MHD_run*() function is called;
  2600. * #MHD_CONTENT_READER_END_OF_STREAM (-1) for the regular
  2601. * end of transmission (with chunked encoding, MHD will then
  2602. * terminate the chunk and send any HTTP footers that might be
  2603. * present; without chunked encoding and given an unknown
  2604. * response size, MHD will simply close the connection; note
  2605. * that while returning #MHD_CONTENT_READER_END_OF_STREAM is not technically
  2606. * legal if a response size was specified, MHD accepts this
  2607. * and treats it just as #MHD_CONTENT_READER_END_WITH_ERROR;
  2608. * #MHD_CONTENT_READER_END_WITH_ERROR (-2) to indicate a server
  2609. * error generating the response; this will cause MHD to simply
  2610. * close the connection immediately. If a response size was
  2611. * given or if chunked encoding is in use, this will indicate
  2612. * an error to the client. Note, however, that if the client
  2613. * does not know a response size and chunked encoding is not in
  2614. * use, then clients will not be able to tell the difference between
  2615. * #MHD_CONTENT_READER_END_WITH_ERROR and #MHD_CONTENT_READER_END_OF_STREAM.
  2616. * This is not a limitation of MHD but rather of the HTTP protocol.
  2617. */
  2618. typedef ssize_t
  2619. (*MHD_ContentReaderCallback) (void *cls,
  2620. uint64_t pos,
  2621. char *buf,
  2622. size_t max);
  2623. /**
  2624. * This method is called by libmicrohttpd if we
  2625. * are done with a content reader. It should
  2626. * be used to free resources associated with the
  2627. * content reader.
  2628. *
  2629. * @param cls closure
  2630. * @ingroup response
  2631. */
  2632. typedef void
  2633. (*MHD_ContentReaderFreeCallback) (void *cls);
  2634. /**
  2635. * Iterator over key-value pairs where the value
  2636. * may be made available in increments and/or may
  2637. * not be zero-terminated. Used for processing
  2638. * POST data.
  2639. *
  2640. * @param cls user-specified closure
  2641. * @param kind type of the value, always #MHD_POSTDATA_KIND when called from MHD
  2642. * @param key 0-terminated key for the value, NULL if not known. This value
  2643. * is never NULL for url-encoded POST data.
  2644. * @param filename name of the uploaded file, NULL if not known
  2645. * @param content_type mime-type of the data, NULL if not known
  2646. * @param transfer_encoding encoding of the data, NULL if not known
  2647. * @param data pointer to @a size bytes of data at the
  2648. * specified offset
  2649. * @param off offset of data in the overall value
  2650. * @param size number of bytes in @a data available
  2651. * @return #MHD_YES to continue iterating,
  2652. * #MHD_NO to abort the iteration
  2653. */
  2654. typedef enum MHD_Result
  2655. (*MHD_PostDataIterator)(void *cls,
  2656. enum MHD_ValueKind kind,
  2657. const char *key,
  2658. const char *filename,
  2659. const char *content_type,
  2660. const char *transfer_encoding,
  2661. const char *data,
  2662. uint64_t off,
  2663. size_t size);
  2664. /* **************** Daemon handling functions ***************** */
  2665. /**
  2666. * Start a webserver on the given port.
  2667. *
  2668. * @param flags combination of `enum MHD_FLAG` values
  2669. * @param port port to bind to (in host byte order),
  2670. * use '0' to bind to random free port,
  2671. * ignored if MHD_OPTION_SOCK_ADDR or
  2672. * MHD_OPTION_LISTEN_SOCKET is provided
  2673. * or MHD_USE_NO_LISTEN_SOCKET is specified
  2674. * @param apc callback to call to check which clients
  2675. * will be allowed to connect; you can pass NULL
  2676. * in which case connections from any IP will be
  2677. * accepted
  2678. * @param apc_cls extra argument to apc
  2679. * @param dh handler called for all requests (repeatedly)
  2680. * @param dh_cls extra argument to @a dh
  2681. * @param ap list of options (type-value pairs,
  2682. * terminated with #MHD_OPTION_END).
  2683. * @return NULL on error, handle to daemon on success
  2684. * @ingroup event
  2685. */
  2686. _MHD_EXTERN struct MHD_Daemon *
  2687. MHD_start_daemon_va (unsigned int flags,
  2688. uint16_t port,
  2689. MHD_AcceptPolicyCallback apc, void *apc_cls,
  2690. MHD_AccessHandlerCallback dh, void *dh_cls,
  2691. va_list ap);
  2692. /**
  2693. * Start a webserver on the given port. Variadic version of
  2694. * #MHD_start_daemon_va.
  2695. *
  2696. * @param flags combination of `enum MHD_FLAG` values
  2697. * @param port port to bind to (in host byte order),
  2698. * use '0' to bind to random free port,
  2699. * ignored if MHD_OPTION_SOCK_ADDR or
  2700. * MHD_OPTION_LISTEN_SOCKET is provided
  2701. * or MHD_USE_NO_LISTEN_SOCKET is specified
  2702. * @param apc callback to call to check which clients
  2703. * will be allowed to connect; you can pass NULL
  2704. * in which case connections from any IP will be
  2705. * accepted
  2706. * @param apc_cls extra argument to apc
  2707. * @param dh handler called for all requests (repeatedly)
  2708. * @param dh_cls extra argument to @a dh
  2709. * @return NULL on error, handle to daemon on success
  2710. * @ingroup event
  2711. */
  2712. _MHD_EXTERN struct MHD_Daemon *
  2713. MHD_start_daemon (unsigned int flags,
  2714. uint16_t port,
  2715. MHD_AcceptPolicyCallback apc, void *apc_cls,
  2716. MHD_AccessHandlerCallback dh, void *dh_cls,
  2717. ...);
  2718. /**
  2719. * Stop accepting connections from the listening socket. Allows
  2720. * clients to continue processing, but stops accepting new
  2721. * connections. Note that the caller is responsible for closing the
  2722. * returned socket; however, if MHD is run using threads (anything but
  2723. * "external" sockets polling mode), it must not be closed until AFTER
  2724. * #MHD_stop_daemon has been called (as it is theoretically possible
  2725. * that an existing thread is still using it).
  2726. *
  2727. * Note that some thread modes require the caller to have passed
  2728. * #MHD_USE_ITC when using this API. If this daemon is
  2729. * in one of those modes and this option was not given to
  2730. * #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
  2731. *
  2732. * @param daemon daemon to stop accepting new connections for
  2733. * @return old listen socket on success, #MHD_INVALID_SOCKET if
  2734. * the daemon was already not listening anymore
  2735. * @ingroup specialized
  2736. */
  2737. _MHD_EXTERN MHD_socket
  2738. MHD_quiesce_daemon (struct MHD_Daemon *daemon);
  2739. /**
  2740. * Shutdown an HTTP daemon.
  2741. *
  2742. * @param daemon daemon to stop
  2743. * @ingroup event
  2744. */
  2745. _MHD_EXTERN void
  2746. MHD_stop_daemon (struct MHD_Daemon *daemon);
  2747. /**
  2748. * Add another client connection to the set of connections managed by
  2749. * MHD. This API is usually not needed (since MHD will accept inbound
  2750. * connections on the server socket). Use this API in special cases,
  2751. * for example if your HTTP server is behind NAT and needs to connect
  2752. * out to the HTTP client, or if you are building a proxy.
  2753. *
  2754. * If you use this API in conjunction with an "internal" socket polling,
  2755. * you must set the option #MHD_USE_ITC to ensure that the freshly added
  2756. * connection is immediately processed by MHD.
  2757. *
  2758. * The given client socket will be managed (and closed!) by MHD after
  2759. * this call and must no longer be used directly by the application
  2760. * afterwards.
  2761. *
  2762. * @param daemon daemon that manages the connection
  2763. * @param client_socket socket to manage (MHD will expect
  2764. * to receive an HTTP request from this socket next).
  2765. * @param addr IP address of the client
  2766. * @param addrlen number of bytes in @a addr
  2767. * @return #MHD_YES on success, #MHD_NO if this daemon could
  2768. * not handle the connection (i.e. `malloc()` failed, etc).
  2769. * The socket will be closed in any case; `errno` is
  2770. * set to indicate further details about the error.
  2771. * @ingroup specialized
  2772. */
  2773. _MHD_EXTERN enum MHD_Result
  2774. MHD_add_connection (struct MHD_Daemon *daemon,
  2775. MHD_socket client_socket,
  2776. const struct sockaddr *addr,
  2777. socklen_t addrlen);
  2778. /**
  2779. * Obtain the `select()` sets for this daemon.
  2780. * Daemon's FDs will be added to fd_sets. To get only
  2781. * daemon FDs in fd_sets, call FD_ZERO for each fd_set
  2782. * before calling this function. FD_SETSIZE is assumed
  2783. * to be platform's default.
  2784. *
  2785. * This function should be called only when MHD is configured to
  2786. * use "external" sockets polling with 'select()' or with 'epoll'.
  2787. * In the latter case, it will only add the single 'epoll' file
  2788. * descriptor used by MHD to the sets.
  2789. * It's necessary to use #MHD_get_timeout() to get maximum timeout
  2790. * value for `select()`. Usage of `select()` with indefinite timeout
  2791. * (or timeout larger than returned by #MHD_get_timeout()) will
  2792. * violate MHD API and may results in pending unprocessed data.
  2793. *
  2794. * This function must be called only for daemon started
  2795. * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  2796. *
  2797. * @param daemon daemon to get sets from
  2798. * @param read_fd_set read set
  2799. * @param write_fd_set write set
  2800. * @param except_fd_set except set
  2801. * @param max_fd increased to largest FD added (if larger
  2802. * than existing value); can be NULL
  2803. * @return #MHD_YES on success, #MHD_NO if this
  2804. * daemon was not started with the right
  2805. * options for this call or any FD didn't
  2806. * fit fd_set.
  2807. * @ingroup event
  2808. */
  2809. _MHD_EXTERN enum MHD_Result
  2810. MHD_get_fdset (struct MHD_Daemon *daemon,
  2811. fd_set *read_fd_set,
  2812. fd_set *write_fd_set,
  2813. fd_set *except_fd_set,
  2814. MHD_socket *max_fd);
  2815. /**
  2816. * Obtain the `select()` sets for this daemon.
  2817. * Daemon's FDs will be added to fd_sets. To get only
  2818. * daemon FDs in fd_sets, call FD_ZERO for each fd_set
  2819. * before calling this function.
  2820. *
  2821. * Passing custom FD_SETSIZE as @a fd_setsize allow usage of
  2822. * larger/smaller than platform's default fd_sets.
  2823. *
  2824. * This function should be called only when MHD is configured to
  2825. * use "external" sockets polling with 'select()' or with 'epoll'.
  2826. * In the latter case, it will only add the single 'epoll' file
  2827. * descriptor used by MHD to the sets.
  2828. * It's necessary to use #MHD_get_timeout() to get maximum timeout
  2829. * value for `select()`. Usage of `select()` with indefinite timeout
  2830. * (or timeout larger than returned by #MHD_get_timeout()) will
  2831. * violate MHD API and may results in pending unprocessed data.
  2832. *
  2833. * This function must be called only for daemon started
  2834. * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  2835. *
  2836. * @param daemon daemon to get sets from
  2837. * @param read_fd_set read set
  2838. * @param write_fd_set write set
  2839. * @param except_fd_set except set
  2840. * @param max_fd increased to largest FD added (if larger
  2841. * than existing value); can be NULL
  2842. * @param fd_setsize value of FD_SETSIZE
  2843. * @return #MHD_YES on success, #MHD_NO if this
  2844. * daemon was not started with the right
  2845. * options for this call or any FD didn't
  2846. * fit fd_set.
  2847. * @ingroup event
  2848. */
  2849. _MHD_EXTERN enum MHD_Result
  2850. MHD_get_fdset2 (struct MHD_Daemon *daemon,
  2851. fd_set *read_fd_set,
  2852. fd_set *write_fd_set,
  2853. fd_set *except_fd_set,
  2854. MHD_socket *max_fd,
  2855. unsigned int fd_setsize);
  2856. /**
  2857. * Obtain the `select()` sets for this daemon.
  2858. * Daemon's FDs will be added to fd_sets. To get only
  2859. * daemon FDs in fd_sets, call FD_ZERO for each fd_set
  2860. * before calling this function. Size of fd_set is
  2861. * determined by current value of FD_SETSIZE.
  2862. *
  2863. * This function should be called only when MHD is configured to
  2864. * use "external" sockets polling with 'select()' or with 'epoll'.
  2865. * In the latter case, it will only add the single 'epoll' file
  2866. * descriptor used by MHD to the sets.
  2867. * It's necessary to use #MHD_get_timeout() to get maximum timeout
  2868. * value for `select()`. Usage of `select()` with indefinite timeout
  2869. * (or timeout larger than returned by #MHD_get_timeout()) will
  2870. * violate MHD API and may results in pending unprocessed data.
  2871. *
  2872. * This function must be called only for daemon started
  2873. * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  2874. *
  2875. * @param daemon daemon to get sets from
  2876. * @param read_fd_set read set
  2877. * @param write_fd_set write set
  2878. * @param except_fd_set except set
  2879. * @param max_fd increased to largest FD added (if larger
  2880. * than existing value); can be NULL
  2881. * @return #MHD_YES on success, #MHD_NO if this
  2882. * daemon was not started with the right
  2883. * options for this call or any FD didn't
  2884. * fit fd_set.
  2885. * @ingroup event
  2886. */
  2887. #define MHD_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \
  2888. MHD_get_fdset2 ((daemon),(read_fd_set),(write_fd_set),(except_fd_set), \
  2889. (max_fd),FD_SETSIZE)
  2890. /**
  2891. * Obtain timeout value for polling function for this daemon.
  2892. *
  2893. * This function set value to the amount of milliseconds for which polling
  2894. * function (`select()`, `poll()` or epoll) should at most block, not the
  2895. * timeout value set for connections.
  2896. *
  2897. * Any "external" sockets polling function must be called with the timeout
  2898. * value provided by this function. Smaller timeout values can be used for
  2899. * polling function if it is required for any reason, but using larger
  2900. * timeout value or no timeout (indefinite timeout) when this function
  2901. * return #MHD_YES will break MHD processing logic and result in "hung"
  2902. * connections with data pending in network buffers and other problems.
  2903. *
  2904. * It is important to always use this function (or #MHD_get_timeout64(),
  2905. * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external"
  2906. * polling is used.
  2907. * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select())
  2908. * must be called right after return from polling function, regardless of
  2909. * the states of MHD FDs.
  2910. *
  2911. * In practice, if #MHD_YES is returned then #MHD_run() (or
  2912. * #MHD_run_from_select()) must be called not later than @a timeout
  2913. * millisecond even if no activity is detected on sockets by sockets
  2914. * polling function.
  2915. *
  2916. * @param daemon daemon to query for timeout
  2917. * @param[out] timeout set to the timeout (in milliseconds)
  2918. * @return #MHD_YES on success, #MHD_NO if timeouts are
  2919. * not used and no data processing is pending.
  2920. * @ingroup event
  2921. */
  2922. _MHD_EXTERN enum MHD_Result
  2923. MHD_get_timeout (struct MHD_Daemon *daemon,
  2924. MHD_UNSIGNED_LONG_LONG *timeout);
  2925. /**
  2926. * Free the memory allocated by MHD.
  2927. *
  2928. * If any MHD function explicitly mentions that returned pointer must be
  2929. * freed by this function, then no other method must be used to free
  2930. * the memory.
  2931. *
  2932. * @param ptr the pointer to free.
  2933. * @sa #MHD_digest_auth_get_username(), #MHD_basic_auth_get_username_password3()
  2934. * @sa #MHD_basic_auth_get_username_password()
  2935. * @note Available since #MHD_VERSION 0x00095600
  2936. * @ingroup specialized
  2937. */
  2938. _MHD_EXTERN void
  2939. MHD_free (void *ptr);
  2940. /**
  2941. * Obtain timeout value for external polling function for this daemon.
  2942. *
  2943. * This function set value to the amount of milliseconds for which polling
  2944. * function (`select()`, `poll()` or epoll) should at most block, not the
  2945. * timeout value set for connections.
  2946. *
  2947. * Any "external" sockets polling function must be called with the timeout
  2948. * value provided by this function. Smaller timeout values can be used for
  2949. * polling function if it is required for any reason, but using larger
  2950. * timeout value or no timeout (indefinite timeout) when this function
  2951. * return #MHD_YES will break MHD processing logic and result in "hung"
  2952. * connections with data pending in network buffers and other problems.
  2953. *
  2954. * It is important to always use this function (or #MHD_get_timeout(),
  2955. * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external"
  2956. * polling is used.
  2957. * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select())
  2958. * must be called right after return from polling function, regardless of
  2959. * the states of MHD FDs.
  2960. *
  2961. * In practice, if #MHD_YES is returned then #MHD_run() (or
  2962. * #MHD_run_from_select()) must be called not later than @a timeout
  2963. * millisecond even if no activity is detected on sockets by sockets
  2964. * polling function.
  2965. *
  2966. * @param daemon daemon to query for timeout
  2967. * @param[out] timeout64 the pointer to the variable to be set to the
  2968. * timeout (in milliseconds)
  2969. * @return #MHD_YES if timeout value has been set,
  2970. * #MHD_NO if timeouts are not used and no data processing is pending.
  2971. * @note Available since #MHD_VERSION 0x00097701
  2972. * @ingroup event
  2973. */
  2974. _MHD_EXTERN enum MHD_Result
  2975. MHD_get_timeout64 (struct MHD_Daemon *daemon,
  2976. uint64_t *timeout);
  2977. /**
  2978. * Obtain timeout value for external polling function for this daemon.
  2979. *
  2980. * This function set value to the amount of milliseconds for which polling
  2981. * function (`select()`, `poll()` or epoll) should at most block, not the
  2982. * timeout value set for connections.
  2983. *
  2984. * Any "external" sockets polling function must be called with the timeout
  2985. * value provided by this function (if returned value is non-negative).
  2986. * Smaller timeout values can be used for polling function if it is required
  2987. * for any reason, but using larger timeout value or no timeout (indefinite
  2988. * timeout) when this function returns non-negative value will break MHD
  2989. * processing logic and result in "hung" connections with data pending in
  2990. * network buffers and other problems.
  2991. *
  2992. * It is important to always use this function (or #MHD_get_timeout(),
  2993. * #MHD_get_timeout64(), #MHD_get_timeout_i() functions) when "external"
  2994. * polling is used.
  2995. * If this function returns non-negative value then #MHD_run() (or
  2996. * #MHD_run_from_select()) must be called right after return from polling
  2997. * function, regardless of the states of MHD FDs.
  2998. *
  2999. * In practice, if zero or positive value is returned then #MHD_run() (or
  3000. * #MHD_run_from_select()) must be called not later than returned amount of
  3001. * millisecond even if no activity is detected on sockets by sockets
  3002. * polling function.
  3003. *
  3004. * @param daemon the daemon to query for timeout
  3005. * @return -1 if connections' timeouts are not set and no data processing
  3006. * is pending, so external polling function may wait for sockets
  3007. * activity for indefinite amount of time,
  3008. * otherwise returned value is the the maximum amount of millisecond
  3009. * that external polling function must wait for the activity of FDs.
  3010. * @note Available since #MHD_VERSION 0x00097701
  3011. * @ingroup event
  3012. */
  3013. _MHD_EXTERN int64_t
  3014. MHD_get_timeout64s (struct MHD_Daemon *daemon);
  3015. /**
  3016. * Obtain timeout value for external polling function for this daemon.
  3017. *
  3018. * This function set value to the amount of milliseconds for which polling
  3019. * function (`select()`, `poll()` or epoll) should at most block, not the
  3020. * timeout value set for connections.
  3021. *
  3022. * Any "external" sockets polling function must be called with the timeout
  3023. * value provided by this function (if returned value is non-negative).
  3024. * Smaller timeout values can be used for polling function if it is required
  3025. * for any reason, but using larger timeout value or no timeout (indefinite
  3026. * timeout) when this function returns non-negative value will break MHD
  3027. * processing logic and result in "hung" connections with data pending in
  3028. * network buffers and other problems.
  3029. *
  3030. * It is important to always use this function (or #MHD_get_timeout(),
  3031. * #MHD_get_timeout64(), #MHD_get_timeout64s() functions) when "external"
  3032. * polling is used.
  3033. * If this function returns non-negative value then #MHD_run() (or
  3034. * #MHD_run_from_select()) must be called right after return from polling
  3035. * function, regardless of the states of MHD FDs.
  3036. *
  3037. * In practice, if zero or positive value is returned then #MHD_run() (or
  3038. * #MHD_run_from_select()) must be called not later than returned amount of
  3039. * millisecond even if no activity is detected on sockets by sockets
  3040. * polling function.
  3041. *
  3042. * @param daemon the daemon to query for timeout
  3043. * @return -1 if connections' timeouts are not set and no data processing
  3044. * is pending, so external polling function may wait for sockets
  3045. * activity for indefinite amount of time,
  3046. * otherwise returned value is the the maximum amount of millisecond
  3047. * (capped at INT_MAX) that external polling function must wait
  3048. * for the activity of FDs.
  3049. * @note Available since #MHD_VERSION 0x00097701
  3050. * @ingroup event
  3051. */
  3052. _MHD_EXTERN int
  3053. MHD_get_timeout_i (struct MHD_Daemon *daemon);
  3054. /**
  3055. * Run webserver operations (without blocking unless in client callbacks).
  3056. *
  3057. * This method should be called by clients in combination with
  3058. * #MHD_get_fdset() (or #MHD_get_daemon_info() with MHD_DAEMON_INFO_EPOLL_FD
  3059. * if epoll is used) and #MHD_get_timeout() if the client-controlled
  3060. * connection polling method is used (i.e. daemon was started without
  3061. * #MHD_USE_INTERNAL_POLLING_THREAD flag).
  3062. *
  3063. * This function is a convenience method, which is useful if the
  3064. * fd_sets from #MHD_get_fdset were not directly passed to `select()`;
  3065. * with this function, MHD will internally do the appropriate `select()`
  3066. * call itself again. While it is acceptable to call #MHD_run (if
  3067. * #MHD_USE_INTERNAL_POLLING_THREAD is not set) at any moment, you should
  3068. * call #MHD_run_from_select() if performance is important (as it saves an
  3069. * expensive call to `select()`).
  3070. *
  3071. * If #MHD_get_timeout() returned #MHD_YES, than this function must be called
  3072. * right after polling function returns regardless of detected activity on
  3073. * the daemon's FDs.
  3074. *
  3075. * @param daemon daemon to run
  3076. * @return #MHD_YES on success, #MHD_NO if this
  3077. * daemon was not started with the right
  3078. * options for this call.
  3079. * @ingroup event
  3080. */
  3081. _MHD_EXTERN enum MHD_Result
  3082. MHD_run (struct MHD_Daemon *daemon);
  3083. /**
  3084. * Run websever operation with possible blocking.
  3085. *
  3086. * This function does the following: waits for any network event not more than
  3087. * specified number of milliseconds, processes all incoming and outgoing data,
  3088. * processes new connections, processes any timed-out connection, and does
  3089. * other things required to run webserver.
  3090. * Once all connections are processed, function returns.
  3091. *
  3092. * This function is useful for quick and simple (lazy) webserver implementation
  3093. * if application needs to run a single thread only and does not have any other
  3094. * network activity.
  3095. *
  3096. * This function calls MHD_get_timeout() internally and use returned value as
  3097. * maximum wait time if it less than value of @a millisec parameter.
  3098. *
  3099. * It is expected that the "external" socket polling function is not used in
  3100. * conjunction with this function unless the @a millisec is set to zero.
  3101. *
  3102. * @param daemon the daemon to run
  3103. * @param millisec the maximum time in milliseconds to wait for network and
  3104. * other events. Note: there is no guarantee that function
  3105. * blocks for the specified amount of time. The real processing
  3106. * time can be shorter (if some data or connection timeout
  3107. * comes earlier) or longer (if data processing requires more
  3108. * time, especially in user callbacks).
  3109. * If set to '0' then function does not block and processes
  3110. * only already available data (if any).
  3111. * If set to '-1' then function waits for events
  3112. * indefinitely (blocks until next network activity or
  3113. * connection timeout).
  3114. * @return #MHD_YES on success, #MHD_NO if this
  3115. * daemon was not started with the right
  3116. * options for this call or some serious
  3117. * unrecoverable error occurs.
  3118. * @note Available since #MHD_VERSION 0x00097206
  3119. * @ingroup event
  3120. */
  3121. _MHD_EXTERN enum MHD_Result
  3122. MHD_run_wait (struct MHD_Daemon *daemon,
  3123. int32_t millisec);
  3124. /**
  3125. * Run webserver operations. This method should be called by clients
  3126. * in combination with #MHD_get_fdset and #MHD_get_timeout() if the
  3127. * client-controlled select method is used.
  3128. *
  3129. * You can use this function instead of #MHD_run if you called
  3130. * `select()` on the result from #MHD_get_fdset. File descriptors in
  3131. * the sets that are not controlled by MHD will be ignored. Calling
  3132. * this function instead of #MHD_run is more efficient as MHD will
  3133. * not have to call `select()` again to determine which operations are
  3134. * ready.
  3135. *
  3136. * If #MHD_get_timeout() returned #MHD_YES, than this function must be
  3137. * called right after `select()` returns regardless of detected activity
  3138. * on the daemon's FDs.
  3139. *
  3140. * This function cannot be used with daemon started with
  3141. * #MHD_USE_INTERNAL_POLLING_THREAD flag.
  3142. *
  3143. * @param daemon daemon to run select loop for
  3144. * @param read_fd_set read set
  3145. * @param write_fd_set write set
  3146. * @param except_fd_set except set
  3147. * @return #MHD_NO on serious errors, #MHD_YES on success
  3148. * @ingroup event
  3149. */
  3150. _MHD_EXTERN enum MHD_Result
  3151. MHD_run_from_select (struct MHD_Daemon *daemon,
  3152. const fd_set *read_fd_set,
  3153. const fd_set *write_fd_set,
  3154. const fd_set *except_fd_set);
  3155. /**
  3156. * Run webserver operations. This method should be called by clients
  3157. * in combination with #MHD_get_fdset and #MHD_get_timeout() if the
  3158. * client-controlled select method is used.
  3159. * This function specifies FD_SETSIZE used when provided fd_sets were
  3160. * created. It is important on platforms where FD_SETSIZE can be
  3161. * overridden.
  3162. *
  3163. * You can use this function instead of #MHD_run if you called
  3164. * 'select()' on the result from #MHD_get_fdset2(). File descriptors in
  3165. * the sets that are not controlled by MHD will be ignored. Calling
  3166. * this function instead of #MHD_run() is more efficient as MHD will
  3167. * not have to call 'select()' again to determine which operations are
  3168. * ready.
  3169. *
  3170. * If #MHD_get_timeout() returned #MHD_YES, than this function must be
  3171. * called right after 'select()' returns regardless of detected activity
  3172. * on the daemon's FDs.
  3173. *
  3174. * This function cannot be used with daemon started with
  3175. * #MHD_USE_INTERNAL_POLLING_THREAD flag.
  3176. *
  3177. * @param daemon the daemon to run select loop for
  3178. * @param read_fd_set the read set
  3179. * @param write_fd_set the write set
  3180. * @param except_fd_set the except set
  3181. * @param fd_setsize the value of FD_SETSIZE
  3182. * @return #MHD_NO on serious errors, #MHD_YES on success
  3183. * @sa #MHD_get_fdset2(), #MHD_OPTION_APP_FD_SETSIZE
  3184. * @ingroup event
  3185. */
  3186. _MHD_EXTERN enum MHD_Result
  3187. MHD_run_from_select2 (struct MHD_Daemon *daemon,
  3188. const fd_set *read_fd_set,
  3189. const fd_set *write_fd_set,
  3190. const fd_set *except_fd_set,
  3191. unsigned int fd_setsize);
  3192. /**
  3193. * Run webserver operations. This method should be called by clients
  3194. * in combination with #MHD_get_fdset and #MHD_get_timeout() if the
  3195. * client-controlled select method is used.
  3196. * This macro automatically substitutes current FD_SETSIZE value.
  3197. * It is important on platforms where FD_SETSIZE can be overridden.
  3198. *
  3199. * You can use this function instead of #MHD_run if you called
  3200. * 'select()' on the result from #MHD_get_fdset2(). File descriptors in
  3201. * the sets that are not controlled by MHD will be ignored. Calling
  3202. * this function instead of #MHD_run() is more efficient as MHD will
  3203. * not have to call 'select()' again to determine which operations are
  3204. * ready.
  3205. *
  3206. * If #MHD_get_timeout() returned #MHD_YES, than this function must be
  3207. * called right after 'select()' returns regardless of detected activity
  3208. * on the daemon's FDs.
  3209. *
  3210. * This function cannot be used with daemon started with
  3211. * #MHD_USE_INTERNAL_POLLING_THREAD flag.
  3212. *
  3213. * @param daemon the daemon to run select loop for
  3214. * @param read_fd_set the read set
  3215. * @param write_fd_set the write set
  3216. * @param except_fd_set the except set
  3217. * @param fd_setsize the value of FD_SETSIZE
  3218. * @return #MHD_NO on serious errors, #MHD_YES on success
  3219. * @sa #MHD_get_fdset2(), #MHD_OPTION_APP_FD_SETSIZE
  3220. * @ingroup event
  3221. */
  3222. #define MHD_run_from_select(d,r,w,e) \
  3223. MHD_run_from_select2((d),(r),(w),(e),(unsigned int)(FD_SETSIZE))
  3224. /* **************** Connection handling functions ***************** */
  3225. /**
  3226. * Get all of the headers from the request.
  3227. *
  3228. * @param connection connection to get values from
  3229. * @param kind types of values to iterate over, can be a bitmask
  3230. * @param iterator callback to call on each header;
  3231. * may be NULL (then just count headers)
  3232. * @param iterator_cls extra argument to @a iterator
  3233. * @return number of entries iterated over,
  3234. * -1 if connection is NULL.
  3235. * @ingroup request
  3236. */
  3237. _MHD_EXTERN int
  3238. MHD_get_connection_values (struct MHD_Connection *connection,
  3239. enum MHD_ValueKind kind,
  3240. MHD_KeyValueIterator iterator,
  3241. void *iterator_cls);
  3242. /**
  3243. * Get all of the headers from the request.
  3244. *
  3245. * @param connection connection to get values from
  3246. * @param kind types of values to iterate over, can be a bitmask
  3247. * @param iterator callback to call on each header;
  3248. * may be NULL (then just count headers)
  3249. * @param iterator_cls extra argument to @a iterator
  3250. * @return number of entries iterated over,
  3251. * -1 if connection is NULL.
  3252. * @note Available since #MHD_VERSION 0x00096400
  3253. * @ingroup request
  3254. */
  3255. _MHD_EXTERN int
  3256. MHD_get_connection_values_n (struct MHD_Connection *connection,
  3257. enum MHD_ValueKind kind,
  3258. MHD_KeyValueIteratorN iterator,
  3259. void *iterator_cls);
  3260. /**
  3261. * This function can be used to add an entry to the HTTP headers of a
  3262. * connection (so that the #MHD_get_connection_values function will
  3263. * return them -- and the `struct MHD_PostProcessor` will also see
  3264. * them). This maybe required in certain situations (see Mantis
  3265. * #1399) where (broken) HTTP implementations fail to supply values
  3266. * needed by the post processor (or other parts of the application).
  3267. *
  3268. * This function MUST only be called from within the
  3269. * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
  3270. * synchronized). Furthermore, the client must guarantee that the key
  3271. * and value arguments are 0-terminated strings that are NOT freed
  3272. * until the connection is closed. (The easiest way to do this is by
  3273. * passing only arguments to permanently allocated strings.).
  3274. *
  3275. * @param connection the connection for which a
  3276. * value should be set
  3277. * @param kind kind of the value
  3278. * @param key key for the value
  3279. * @param value the value itself
  3280. * @return #MHD_NO if the operation could not be
  3281. * performed due to insufficient memory;
  3282. * #MHD_YES on success
  3283. * @ingroup request
  3284. */
  3285. _MHD_EXTERN enum MHD_Result
  3286. MHD_set_connection_value (struct MHD_Connection *connection,
  3287. enum MHD_ValueKind kind,
  3288. const char *key,
  3289. const char *value);
  3290. /**
  3291. * This function can be used to add an arbitrary entry to connection.
  3292. * This function could add entry with binary zero, which is allowed
  3293. * for #MHD_GET_ARGUMENT_KIND. For other kind on entries it is
  3294. * recommended to use #MHD_set_connection_value.
  3295. *
  3296. * This function MUST only be called from within the
  3297. * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
  3298. * synchronized). Furthermore, the client must guarantee that the key
  3299. * and value arguments are 0-terminated strings that are NOT freed
  3300. * until the connection is closed. (The easiest way to do this is by
  3301. * passing only arguments to permanently allocated strings.).
  3302. *
  3303. * @param connection the connection for which a
  3304. * value should be set
  3305. * @param kind kind of the value
  3306. * @param key key for the value, must be zero-terminated
  3307. * @param key_size number of bytes in @a key (excluding 0-terminator)
  3308. * @param value the value itself, must be zero-terminated
  3309. * @param value_size number of bytes in @a value (excluding 0-terminator)
  3310. * @return #MHD_NO if the operation could not be
  3311. * performed due to insufficient memory;
  3312. * #MHD_YES on success
  3313. * @note Available since #MHD_VERSION 0x00096400
  3314. * @ingroup request
  3315. */
  3316. _MHD_EXTERN enum MHD_Result
  3317. MHD_set_connection_value_n (struct MHD_Connection *connection,
  3318. enum MHD_ValueKind kind,
  3319. const char *key,
  3320. size_t key_size,
  3321. const char *value,
  3322. size_t value_size);
  3323. /**
  3324. * Sets the global error handler to a different implementation.
  3325. *
  3326. * @a cb will only be called in the case of typically fatal, serious internal
  3327. * consistency issues or serious system failures like failed lock of mutex.
  3328. *
  3329. * These issues should only arise in the case of serious memory corruption or
  3330. * similar problems with the architecture, there is no safe way to continue
  3331. * even for closing of the application.
  3332. *
  3333. * The default implementation that is used if no panic function is set simply
  3334. * prints an error message and calls `abort()`.
  3335. * Alternative implementations might call `exit()` or other similar functions.
  3336. *
  3337. * @param cb new error handler or NULL to use default handler
  3338. * @param cls passed to @a cb
  3339. * @ingroup logging
  3340. */
  3341. _MHD_EXTERN void
  3342. MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
  3343. /**
  3344. * Process escape sequences ('%HH') Updates val in place; the
  3345. * result cannot be larger than the input.
  3346. * The result is still be 0-terminated.
  3347. *
  3348. * @param val value to unescape (modified in the process)
  3349. * @return length of the resulting val (`strlen(val)` may be
  3350. * shorter afterwards due to elimination of escape sequences)
  3351. */
  3352. _MHD_EXTERN size_t
  3353. MHD_http_unescape (char *val);
  3354. /**
  3355. * Get a particular header value. If multiple
  3356. * values match the kind, return any one of them.
  3357. *
  3358. * @param connection connection to get values from
  3359. * @param kind what kind of value are we looking for
  3360. * @param key the header to look for, NULL to lookup 'trailing' value without a key
  3361. * @return NULL if no such item was found
  3362. * @ingroup request
  3363. */
  3364. _MHD_EXTERN const char *
  3365. MHD_lookup_connection_value (struct MHD_Connection *connection,
  3366. enum MHD_ValueKind kind,
  3367. const char *key);
  3368. /**
  3369. * Get a particular header value. If multiple
  3370. * values match the kind, return any one of them.
  3371. * @note Since MHD_VERSION 0x00096304
  3372. *
  3373. * @param connection connection to get values from
  3374. * @param kind what kind of value are we looking for
  3375. * @param key the header to look for, NULL to lookup 'trailing' value without a key
  3376. * @param key_size the length of @a key in bytes
  3377. * @param[out] value_ptr the pointer to variable, which will be set to found value,
  3378. * will not be updated if key not found,
  3379. * could be NULL to just check for presence of @a key
  3380. * @param[out] value_size_ptr the pointer variable, which will set to found value,
  3381. * will not be updated if key not found,
  3382. * could be NULL
  3383. * @return #MHD_YES if key is found,
  3384. * #MHD_NO otherwise.
  3385. * @ingroup request
  3386. */
  3387. _MHD_EXTERN enum MHD_Result
  3388. MHD_lookup_connection_value_n (struct MHD_Connection *connection,
  3389. enum MHD_ValueKind kind,
  3390. const char *key,
  3391. size_t key_size,
  3392. const char **value_ptr,
  3393. size_t *value_size_ptr);
  3394. /**
  3395. * Queue a response to be transmitted to the client (as soon as
  3396. * possible but after #MHD_AccessHandlerCallback returns).
  3397. *
  3398. * For any active connection this function must be called
  3399. * only by #MHD_AccessHandlerCallback callback.
  3400. *
  3401. * For suspended connection this function can be called at any moment (this
  3402. * behaviour is deprecated and will be removed!). Response will be sent
  3403. * as soon as connection is resumed.
  3404. *
  3405. * For single thread environment, when MHD is used in "external polling" mode
  3406. * (without MHD_USE_SELECT_INTERNALLY) this function can be called any
  3407. * time (this behaviour is deprecated and will be removed!).
  3408. *
  3409. * If HTTP specifications require use no body in reply, like @a status_code with
  3410. * value 1xx, the response body is automatically not sent even if it is present
  3411. * in the response. No "Content-Length" or "Transfer-Encoding" headers are
  3412. * generated and added.
  3413. *
  3414. * When the response is used to respond HEAD request or used with @a status_code
  3415. * #MHD_HTTP_NOT_MODIFIED, then response body is not sent, but "Content-Length"
  3416. * header is added automatically based the size of the body in the response.
  3417. * If body size it set to #MHD_SIZE_UNKNOWN or chunked encoding is enforced
  3418. * then "Transfer-Encoding: chunked" header (for HTTP/1.1 only) is added instead
  3419. * of "Content-Length" header. For example, if response with zero-size body is
  3420. * used for HEAD request, then "Content-Length: 0" is added automatically to
  3421. * reply headers.
  3422. * @sa #MHD_RF_HEAD_ONLY_RESPONSE
  3423. *
  3424. * In situations, where reply body is required, like answer for the GET request
  3425. * with @a status_code #MHD_HTTP_OK, headers "Content-Length" (for known body
  3426. * size) or "Transfer-Encoding: chunked" (for #MHD_SIZE_UNKNOWN with HTTP/1.1)
  3427. * are added automatically.
  3428. * In practice, the same response object can be used to respond to both HEAD and
  3429. * GET requests.
  3430. *
  3431. * @param connection the connection identifying the client
  3432. * @param status_code HTTP status code (i.e. #MHD_HTTP_OK)
  3433. * @param response response to transmit, the NULL is tolerated
  3434. * @return #MHD_NO on error (reply already sent, response is NULL),
  3435. * #MHD_YES on success or if message has been queued
  3436. * @ingroup response
  3437. * @sa #MHD_AccessHandlerCallback
  3438. */
  3439. _MHD_EXTERN enum MHD_Result
  3440. MHD_queue_response (struct MHD_Connection *connection,
  3441. unsigned int status_code,
  3442. struct MHD_Response *response);
  3443. /**
  3444. * Suspend handling of network data for a given connection.
  3445. * This can be used to dequeue a connection from MHD's event loop
  3446. * (not applicable to thread-per-connection!) for a while.
  3447. *
  3448. * If you use this API in conjunction with an "internal" socket polling,
  3449. * you must set the option #MHD_USE_ITC to ensure that a resumed
  3450. * connection is immediately processed by MHD.
  3451. *
  3452. * Suspended connections continue to count against the total number of
  3453. * connections allowed (per daemon, as well as per IP, if such limits
  3454. * are set). Suspended connections will NOT time out; timeouts will
  3455. * restart when the connection handling is resumed. While a
  3456. * connection is suspended, MHD will not detect disconnects by the
  3457. * client.
  3458. *
  3459. * The only safe way to call this function is to call it from the
  3460. * #MHD_AccessHandlerCallback or #MHD_ContentReaderCallback.
  3461. *
  3462. * Finally, it is an API violation to call #MHD_stop_daemon while
  3463. * having suspended connections (this will at least create memory and
  3464. * socket leaks or lead to undefined behavior). You must explicitly
  3465. * resume all connections before stopping the daemon.
  3466. *
  3467. * @param connection the connection to suspend
  3468. *
  3469. * @sa #MHD_AccessHandlerCallback
  3470. */
  3471. _MHD_EXTERN void
  3472. MHD_suspend_connection (struct MHD_Connection *connection);
  3473. /**
  3474. * Resume handling of network data for suspended connection. It is
  3475. * safe to resume a suspended connection at any time. Calling this
  3476. * function on a connection that was not previously suspended will
  3477. * result in undefined behavior.
  3478. *
  3479. * If you are using this function in "external" sockets polling mode, you must
  3480. * make sure to run #MHD_run() and #MHD_get_timeout() afterwards (before
  3481. * again calling #MHD_get_fdset()), as otherwise the change may not be
  3482. * reflected in the set returned by #MHD_get_fdset() and you may end up
  3483. * with a connection that is stuck until the next network activity.
  3484. *
  3485. * @param connection the connection to resume
  3486. */
  3487. _MHD_EXTERN void
  3488. MHD_resume_connection (struct MHD_Connection *connection);
  3489. /* **************** Response manipulation functions ***************** */
  3490. /**
  3491. * Flags for special handling of responses.
  3492. */
  3493. enum MHD_ResponseFlags
  3494. {
  3495. /**
  3496. * Default: no special flags.
  3497. * @note Available since #MHD_VERSION 0x00093701
  3498. */
  3499. MHD_RF_NONE = 0,
  3500. /**
  3501. * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
  3502. * Response still use HTTP/1.1 version in header, but always close
  3503. * the connection after sending the response and do not use chunked
  3504. * encoding for the response.
  3505. * You can also set the #MHD_RF_HTTP_1_0_SERVER flag to force
  3506. * HTTP/1.0 version in the response.
  3507. * Responses are still compatible with HTTP/1.1.
  3508. * This option can be used to communicate with some broken client, which
  3509. * does not implement HTTP/1.1 features, but advertises HTTP/1.1 support.
  3510. * @note Available since #MHD_VERSION 0x00097308
  3511. */
  3512. MHD_RF_HTTP_1_0_COMPATIBLE_STRICT = 1 << 0,
  3513. /**
  3514. * The same as #MHD_RF_HTTP_1_0_COMPATIBLE_STRICT
  3515. * @note Available since #MHD_VERSION 0x00093701
  3516. */
  3517. MHD_RF_HTTP_VERSION_1_0_ONLY = 1 << 0,
  3518. /**
  3519. * Only respond in HTTP 1.0-mode.
  3520. * Contrary to the #MHD_RF_HTTP_1_0_COMPATIBLE_STRICT flag, the response's
  3521. * HTTP version will always be set to 1.0 and keep-alive connections
  3522. * will be used if explicitly requested by the client.
  3523. * The "Connection:" header will be added for both "close" and "keep-alive"
  3524. * connections.
  3525. * Chunked encoding will not be used for the response.
  3526. * Due to backward compatibility, responses still can be used with
  3527. * HTTP/1.1 clients.
  3528. * This option can be used to emulate HTTP/1.0 server (for response part
  3529. * only as chunked encoding in requests (if any) is processed by MHD).
  3530. * @note Available since #MHD_VERSION 0x00097308
  3531. */
  3532. MHD_RF_HTTP_1_0_SERVER = 1 << 1,
  3533. /**
  3534. * The same as #MHD_RF_HTTP_1_0_SERVER
  3535. * @note Available since #MHD_VERSION 0x00096000
  3536. */
  3537. MHD_RF_HTTP_VERSION_1_0_RESPONSE = 1 << 1,
  3538. /**
  3539. * Disable sanity check preventing clients from manually
  3540. * setting the HTTP content length option.
  3541. * Allow to set several "Content-Length" headers. These headers will
  3542. * be used even with replies without body.
  3543. * @note Available since #MHD_VERSION 0x00096702
  3544. */
  3545. MHD_RF_INSANITY_HEADER_CONTENT_LENGTH = 1 << 2,
  3546. /**
  3547. * Enable sending of "Connection: keep-alive" header even for
  3548. * HTTP/1.1 clients when "Keep-Alive" connection is used.
  3549. * Disabled by default for HTTP/1.1 clients as per RFC.
  3550. * @note Available since #MHD_VERSION 0x00097310
  3551. */
  3552. MHD_RF_SEND_KEEP_ALIVE_HEADER = 1 << 3,
  3553. /**
  3554. * Enable special processing of the response as body-less (with undefined
  3555. * body size). No automatic "Content-Length" or "Transfer-Encoding: chunked"
  3556. * headers are added when the response is used with #MHD_HTTP_NOT_MODIFIED
  3557. * code or to respond to HEAD request.
  3558. * The flag also allow to set arbitrary "Content-Length" by
  3559. * MHD_add_response_header() function.
  3560. * This flag value can be used only with responses created without body
  3561. * (zero-size body).
  3562. * Responses with this flag enabled cannot be used in situations where
  3563. * reply body must be sent to the client.
  3564. * This flag is primarily intended to be used when automatic "Content-Length"
  3565. * header is undesirable in response to HEAD requests.
  3566. * @note Available since #MHD_VERSION 0x00097701
  3567. */
  3568. MHD_RF_HEAD_ONLY_RESPONSE = 1 << 4
  3569. } _MHD_FIXED_FLAGS_ENUM;
  3570. /**
  3571. * MHD options (for future extensions).
  3572. */
  3573. enum MHD_ResponseOptions
  3574. {
  3575. /**
  3576. * End of the list of options.
  3577. */
  3578. MHD_RO_END = 0
  3579. } _MHD_FIXED_ENUM;
  3580. /**
  3581. * Set special flags and options for a response.
  3582. *
  3583. * @param response the response to modify
  3584. * @param flags to set for the response
  3585. * @param ... #MHD_RO_END terminated list of options
  3586. * @return #MHD_YES on success, #MHD_NO on error
  3587. */
  3588. _MHD_EXTERN enum MHD_Result
  3589. MHD_set_response_options (struct MHD_Response *response,
  3590. enum MHD_ResponseFlags flags,
  3591. ...);
  3592. /**
  3593. * Create a response object.
  3594. * The response object can be extended with header information and then be used
  3595. * any number of times.
  3596. *
  3597. * If response object is used to answer HEAD request then the body of the
  3598. * response is not used, while all headers (including automatic headers) are
  3599. * used.
  3600. *
  3601. * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
  3602. * @param block_size preferred block size for querying crc (advisory only,
  3603. * MHD may still call @a crc using smaller chunks); this
  3604. * is essentially the buffer size used for IO, clients
  3605. * should pick a value that is appropriate for IO and
  3606. * memory performance requirements
  3607. * @param crc callback to use to obtain response data
  3608. * @param crc_cls extra argument to @a crc
  3609. * @param crfc callback to call to free @a crc_cls resources
  3610. * @return NULL on error (i.e. invalid arguments, out of memory)
  3611. * @ingroup response
  3612. */
  3613. _MHD_EXTERN struct MHD_Response *
  3614. MHD_create_response_from_callback (uint64_t size,
  3615. size_t block_size,
  3616. MHD_ContentReaderCallback crc, void *crc_cls,
  3617. MHD_ContentReaderFreeCallback crfc);
  3618. /**
  3619. * Create a response object.
  3620. * The response object can be extended with header information and then be used
  3621. * any number of times.
  3622. *
  3623. * If response object is used to answer HEAD request then the body of the
  3624. * response is not used, while all headers (including automatic headers) are
  3625. * used.
  3626. *
  3627. * @param size size of the @a data portion of the response
  3628. * @param data the data itself
  3629. * @param must_free libmicrohttpd should free data when done
  3630. * @param must_copy libmicrohttpd must make a copy of @a data
  3631. * right away, the data may be released anytime after
  3632. * this call returns
  3633. * @return NULL on error (i.e. invalid arguments, out of memory)
  3634. * @deprecated use #MHD_create_response_from_buffer instead
  3635. * @ingroup response
  3636. */
  3637. _MHD_DEPR_FUNC ("MHD_create_response_from_data() is deprecated, " \
  3638. "use MHD_create_response_from_buffer()") \
  3639. _MHD_EXTERN struct MHD_Response *
  3640. MHD_create_response_from_data (size_t size,
  3641. void *data,
  3642. int must_free,
  3643. int must_copy);
  3644. /**
  3645. * Specification for how MHD should treat the memory buffer
  3646. * given for the response.
  3647. * @ingroup response
  3648. */
  3649. enum MHD_ResponseMemoryMode
  3650. {
  3651. /**
  3652. * Buffer is a persistent (static/global) buffer that won't change
  3653. * for at least the lifetime of the response, MHD should just use
  3654. * it, not free it, not copy it, just keep an alias to it.
  3655. * @ingroup response
  3656. */
  3657. MHD_RESPMEM_PERSISTENT,
  3658. /**
  3659. * Buffer is heap-allocated with `malloc()` (or equivalent) and
  3660. * should be freed by MHD after processing the response has
  3661. * concluded (response reference counter reaches zero).
  3662. * The more portable way to automatically free the buffer is function
  3663. * MHD_create_response_from_buffer_with_free_callback() with '&free' as
  3664. * crfc parameter as it does not require to use the same runtime library.
  3665. * @warning It is critical to make sure that the same C-runtime library
  3666. * is used by both application and MHD (especially
  3667. * important for W32).
  3668. * @ingroup response
  3669. */
  3670. MHD_RESPMEM_MUST_FREE,
  3671. /**
  3672. * Buffer is in transient memory, but not on the heap (for example,
  3673. * on the stack or non-`malloc()` allocated) and only valid during the
  3674. * call to #MHD_create_response_from_buffer. MHD must make its
  3675. * own private copy of the data for processing.
  3676. * @ingroup response
  3677. */
  3678. MHD_RESPMEM_MUST_COPY
  3679. } _MHD_FIXED_ENUM;
  3680. /**
  3681. * Create a response object with the content of provided buffer used as
  3682. * the response body.
  3683. *
  3684. * The response object can be extended with header information and then
  3685. * be used any number of times.
  3686. *
  3687. * If response object is used to answer HEAD request then the body
  3688. * of the response is not used, while all headers (including automatic
  3689. * headers) are used.
  3690. *
  3691. * @param size size of the data portion of the response
  3692. * @param buffer size bytes containing the response's data portion
  3693. * @param mode flags for buffer management
  3694. * @return NULL on error (i.e. invalid arguments, out of memory)
  3695. * @ingroup response
  3696. */
  3697. _MHD_EXTERN struct MHD_Response *
  3698. MHD_create_response_from_buffer (size_t size,
  3699. void *buffer,
  3700. enum MHD_ResponseMemoryMode mode);
  3701. /**
  3702. * Create a response object with the content of provided statically allocated
  3703. * buffer used as the response body.
  3704. *
  3705. * The buffer must be valid for the lifetime of the response. The easiest way
  3706. * to achieve this is to use a statically allocated buffer.
  3707. *
  3708. * The response object can be extended with header information and then
  3709. * be used any number of times.
  3710. *
  3711. * If response object is used to answer HEAD request then the body
  3712. * of the response is not used, while all headers (including automatic
  3713. * headers) are used.
  3714. *
  3715. * @param size the size of the data in @a buffer, can be zero
  3716. * @param buffer the buffer with the data for the response body, can be NULL
  3717. * if @a size is zero
  3718. * @return NULL on error (i.e. invalid arguments, out of memory)
  3719. * @note Available since #MHD_VERSION 0x00097701
  3720. * @ingroup response
  3721. */
  3722. _MHD_EXTERN struct MHD_Response *
  3723. MHD_create_response_from_buffer_static (size_t size,
  3724. const void *buffer);
  3725. /**
  3726. * Create a response object with the content of provided temporal buffer
  3727. * used as the response body.
  3728. *
  3729. * An internal copy of the buffer will be made automatically, so buffer have
  3730. * to be valid only during the call of this function (as a typical example:
  3731. * buffer is a local (non-static) array).
  3732. *
  3733. * The response object can be extended with header information and then
  3734. * be used any number of times.
  3735. *
  3736. * If response object is used to answer HEAD request then the body
  3737. * of the response is not used, while all headers (including automatic
  3738. * headers) are used.
  3739. *
  3740. * @param size the size of the data in @a buffer, can be zero
  3741. * @param buffer the buffer with the data for the response body, can be NULL
  3742. * if @a size is zero
  3743. * @return NULL on error (i.e. invalid arguments, out of memory)
  3744. * @note Available since #MHD_VERSION 0x00097701
  3745. * @ingroup response
  3746. */
  3747. _MHD_EXTERN struct MHD_Response *
  3748. MHD_create_response_from_buffer_copy (size_t size,
  3749. const void *buffer);
  3750. /**
  3751. * Create a response object with the content of provided buffer used as
  3752. * the response body.
  3753. *
  3754. * The response object can be extended with header information and then
  3755. * be used any number of times.
  3756. *
  3757. * If response object is used to answer HEAD request then the body
  3758. * of the response is not used, while all headers (including automatic
  3759. * headers) are used.
  3760. *
  3761. * @param size size of the data portion of the response
  3762. * @param buffer size bytes containing the response's data portion
  3763. * @param crfc function to call to free the @a buffer
  3764. * @return NULL on error (i.e. invalid arguments, out of memory)
  3765. * @note Available since #MHD_VERSION 0x00096000
  3766. * @ingroup response
  3767. */
  3768. _MHD_EXTERN struct MHD_Response *
  3769. MHD_create_response_from_buffer_with_free_callback (size_t size,
  3770. void *buffer,
  3771. MHD_ContentReaderFreeCallback
  3772. crfc);
  3773. /**
  3774. * Create a response object with the content of provided buffer used as
  3775. * the response body.
  3776. *
  3777. * The response object can be extended with header information and then
  3778. * be used any number of times.
  3779. *
  3780. * If response object is used to answer HEAD request then the body
  3781. * of the response is not used, while all headers (including automatic
  3782. * headers) are used.
  3783. *
  3784. * @param size size of the data portion of the response
  3785. * @param buffer size bytes containing the response's data portion
  3786. * @param crfc function to call to cleanup, if set to NULL then callback
  3787. * is not called
  3788. * @param crfc_cls an argument for @a crfc
  3789. * @return NULL on error (i.e. invalid arguments, out of memory)
  3790. * @note Available since #MHD_VERSION 0x00097302
  3791. * @note 'const' qualifier is used for @a buffer since #MHD_VERSION 0x00097701
  3792. * @ingroup response
  3793. */
  3794. _MHD_EXTERN struct MHD_Response *
  3795. MHD_create_response_from_buffer_with_free_callback_cls (size_t size,
  3796. const void *buffer,
  3797. MHD_ContentReaderFreeCallback
  3798. crfc,
  3799. void *crfc_cls);
  3800. /**
  3801. * Create a response object with the content of provided file used as
  3802. * the response body.
  3803. *
  3804. * The response object can be extended with header information and then
  3805. * be used any number of times.
  3806. *
  3807. * If response object is used to answer HEAD request then the body
  3808. * of the response is not used, while all headers (including automatic
  3809. * headers) are used.
  3810. *
  3811. * @param size size of the data portion of the response
  3812. * @param fd file descriptor referring to a file on disk with the
  3813. * data; will be closed when response is destroyed;
  3814. * fd should be in 'blocking' mode
  3815. * @return NULL on error (i.e. invalid arguments, out of memory)
  3816. * @ingroup response
  3817. */
  3818. _MHD_EXTERN struct MHD_Response *
  3819. MHD_create_response_from_fd (size_t size,
  3820. int fd);
  3821. /**
  3822. * Create a response object with the response body created by reading
  3823. * the provided pipe.
  3824. *
  3825. * The response object can be extended with header information and
  3826. * then be used ONLY ONCE.
  3827. *
  3828. * If response object is used to answer HEAD request then the body
  3829. * of the response is not used, while all headers (including automatic
  3830. * headers) are used.
  3831. *
  3832. * @param fd file descriptor referring to a read-end of a pipe with the
  3833. * data; will be closed when response is destroyed;
  3834. * fd should be in 'blocking' mode
  3835. * @return NULL on error (i.e. invalid arguments, out of memory)
  3836. * @note Available since #MHD_VERSION 0x00097102
  3837. * @ingroup response
  3838. */
  3839. _MHD_EXTERN struct MHD_Response *
  3840. MHD_create_response_from_pipe (int fd);
  3841. /**
  3842. * Create a response object with the content of provided file used as
  3843. * the response body.
  3844. *
  3845. * The response object can be extended with header information and then
  3846. * be used any number of times.
  3847. *
  3848. * If response object is used to answer HEAD request then the body
  3849. * of the response is not used, while all headers (including automatic
  3850. * headers) are used.
  3851. *
  3852. * @param size size of the data portion of the response;
  3853. * sizes larger than 2 GiB may be not supported by OS or
  3854. * MHD build; see ::MHD_FEATURE_LARGE_FILE
  3855. * @param fd file descriptor referring to a file on disk with the
  3856. * data; will be closed when response is destroyed;
  3857. * fd should be in 'blocking' mode
  3858. * @return NULL on error (i.e. invalid arguments, out of memory)
  3859. * @ingroup response
  3860. */
  3861. _MHD_EXTERN struct MHD_Response *
  3862. MHD_create_response_from_fd64 (uint64_t size,
  3863. int fd);
  3864. /**
  3865. * Create a response object with the content of provided file with
  3866. * specified offset used as the response body.
  3867. *
  3868. * The response object can be extended with header information and then
  3869. * be used any number of times.
  3870. *
  3871. * If response object is used to answer HEAD request then the body
  3872. * of the response is not used, while all headers (including automatic
  3873. * headers) are used.
  3874. *
  3875. * @param size size of the data portion of the response
  3876. * @param fd file descriptor referring to a file on disk with the
  3877. * data; will be closed when response is destroyed;
  3878. * fd should be in 'blocking' mode
  3879. * @param offset offset to start reading from in the file;
  3880. * Be careful! `off_t` may have been compiled to be a
  3881. * 64-bit variable for MHD, in which case your application
  3882. * also has to be compiled using the same options! Read
  3883. * the MHD manual for more details.
  3884. * @return NULL on error (i.e. invalid arguments, out of memory)
  3885. * @ingroup response
  3886. */
  3887. _MHD_DEPR_FUNC ("Function MHD_create_response_from_fd_at_offset() is " \
  3888. "deprecated, use MHD_create_response_from_fd_at_offset64()") \
  3889. _MHD_EXTERN struct MHD_Response *
  3890. MHD_create_response_from_fd_at_offset (size_t size,
  3891. int fd,
  3892. off_t offset);
  3893. #if ! defined(_MHD_NO_DEPR_IN_MACRO) || defined(_MHD_NO_DEPR_FUNC)
  3894. /* Substitute MHD_create_response_from_fd_at_offset64() instead of MHD_create_response_from_fd_at_offset()
  3895. to minimize potential problems with different off_t sizes */
  3896. #define MHD_create_response_from_fd_at_offset(size,fd,offset) \
  3897. _MHD_DEPR_IN_MACRO ( \
  3898. "Usage of MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") \
  3899. MHD_create_response_from_fd_at_offset64 ((size),(fd),(offset))
  3900. #endif /* !_MHD_NO_DEPR_IN_MACRO || _MHD_NO_DEPR_FUNC */
  3901. /**
  3902. * Create a response object with the content of provided file with
  3903. * specified offset used as the response body.
  3904. *
  3905. * The response object can be extended with header information and then
  3906. * be used any number of times.
  3907. *
  3908. * If response object is used to answer HEAD request then the body
  3909. * of the response is not used, while all headers (including automatic
  3910. * headers) are used.
  3911. *
  3912. * @param size size of the data portion of the response;
  3913. * sizes larger than 2 GiB may be not supported by OS or
  3914. * MHD build; see ::MHD_FEATURE_LARGE_FILE
  3915. * @param fd file descriptor referring to a file on disk with the
  3916. * data; will be closed when response is destroyed;
  3917. * fd should be in 'blocking' mode
  3918. * @param offset offset to start reading from in the file;
  3919. * reading file beyond 2 GiB may be not supported by OS or
  3920. * MHD build; see ::MHD_FEATURE_LARGE_FILE
  3921. * @return NULL on error (i.e. invalid arguments, out of memory)
  3922. * @ingroup response
  3923. */
  3924. _MHD_EXTERN struct MHD_Response *
  3925. MHD_create_response_from_fd_at_offset64 (uint64_t size,
  3926. int fd,
  3927. uint64_t offset);
  3928. /**
  3929. * Create a response object with an array of memory buffers
  3930. * used as the response body.
  3931. *
  3932. * The response object can be extended with header information and then
  3933. * be used any number of times.
  3934. *
  3935. * If response object is used to answer HEAD request then the body
  3936. * of the response is not used, while all headers (including automatic
  3937. * headers) are used.
  3938. *
  3939. * @param iov the array for response data buffers, an internal copy of this
  3940. * will be made
  3941. * @param iovcnt the number of elements in @a iov
  3942. * @param free_cb the callback to clean up any data associated with @a iov when
  3943. * the response is destroyed.
  3944. * @param cls the argument passed to @a free_cb
  3945. * @return NULL on error (i.e. invalid arguments, out of memory)
  3946. * @note Available since #MHD_VERSION 0x00097204
  3947. * @ingroup response
  3948. */
  3949. _MHD_EXTERN struct MHD_Response *
  3950. MHD_create_response_from_iovec (const struct MHD_IoVec *iov,
  3951. unsigned int iovcnt,
  3952. MHD_ContentReaderFreeCallback free_cb,
  3953. void *cls);
  3954. /**
  3955. * Create a response object with empty (zero size) body.
  3956. *
  3957. * The response object can be extended with header information and then be used
  3958. * any number of times.
  3959. *
  3960. * This function is a faster equivalent of #MHD_create_response_from_buffer call
  3961. * with zero size combined with call of #MHD_set_response_options.
  3962. *
  3963. * @param flags the flags for the new response object
  3964. * @return NULL on error (i.e. invalid arguments, out of memory),
  3965. * the pointer to the created response object otherwise
  3966. * @note Available since #MHD_VERSION 0x00097701
  3967. * @ingroup response
  3968. */
  3969. _MHD_EXTERN struct MHD_Response *
  3970. MHD_create_response_empty (enum MHD_ResponseFlags flags);
  3971. /**
  3972. * Enumeration for actions MHD should perform on the underlying socket
  3973. * of the upgrade. This API is not finalized, and in particular
  3974. * the final set of actions is yet to be decided. This is just an
  3975. * idea for what we might want.
  3976. */
  3977. enum MHD_UpgradeAction
  3978. {
  3979. /**
  3980. * Close the socket, the application is done with it.
  3981. *
  3982. * Takes no extra arguments.
  3983. */
  3984. MHD_UPGRADE_ACTION_CLOSE = 0,
  3985. /**
  3986. * Enable CORKing on the underlying socket.
  3987. */
  3988. MHD_UPGRADE_ACTION_CORK_ON = 1,
  3989. /**
  3990. * Disable CORKing on the underlying socket.
  3991. */
  3992. MHD_UPGRADE_ACTION_CORK_OFF = 2
  3993. } _MHD_FIXED_ENUM;
  3994. /**
  3995. * Handle given to the application to manage special
  3996. * actions relating to MHD responses that "upgrade"
  3997. * the HTTP protocol (i.e. to WebSockets).
  3998. */
  3999. struct MHD_UpgradeResponseHandle;
  4000. /**
  4001. * This connection-specific callback is provided by MHD to
  4002. * applications (unusual) during the #MHD_UpgradeHandler.
  4003. * It allows applications to perform 'special' actions on
  4004. * the underlying socket from the upgrade.
  4005. *
  4006. * @param urh the handle identifying the connection to perform
  4007. * the upgrade @a action on.
  4008. * @param action which action should be performed
  4009. * @param ... arguments to the action (depends on the action)
  4010. * @return #MHD_NO on error, #MHD_YES on success
  4011. */
  4012. _MHD_EXTERN enum MHD_Result
  4013. MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
  4014. enum MHD_UpgradeAction action,
  4015. ...);
  4016. /**
  4017. * Function called after a protocol "upgrade" response was sent
  4018. * successfully and the socket should now be controlled by some
  4019. * protocol other than HTTP.
  4020. *
  4021. * Any data already received on the socket will be made available in
  4022. * @e extra_in. This can happen if the application sent extra data
  4023. * before MHD send the upgrade response. The application should
  4024. * treat data from @a extra_in as if it had read it from the socket.
  4025. *
  4026. * Note that the application must not close() @a sock directly,
  4027. * but instead use #MHD_upgrade_action() for special operations
  4028. * on @a sock.
  4029. *
  4030. * Data forwarding to "upgraded" @a sock will be started as soon
  4031. * as this function return.
  4032. *
  4033. * Except when in 'thread-per-connection' mode, implementations
  4034. * of this function should never block (as it will still be called
  4035. * from within the main event loop).
  4036. *
  4037. * @param cls closure, whatever was given to #MHD_create_response_for_upgrade().
  4038. * @param connection original HTTP connection handle,
  4039. * giving the function a last chance
  4040. * to inspect the original HTTP request
  4041. * @param req_cls last value left in `req_cls` of the `MHD_AccessHandlerCallback`
  4042. * @param extra_in if we happened to have read bytes after the
  4043. * HTTP header already (because the client sent
  4044. * more than the HTTP header of the request before
  4045. * we sent the upgrade response),
  4046. * these are the extra bytes already read from @a sock
  4047. * by MHD. The application should treat these as if
  4048. * it had read them from @a sock.
  4049. * @param extra_in_size number of bytes in @a extra_in
  4050. * @param sock socket to use for bi-directional communication
  4051. * with the client. For HTTPS, this may not be a socket
  4052. * that is directly connected to the client and thus certain
  4053. * operations (TCP-specific setsockopt(), getsockopt(), etc.)
  4054. * may not work as expected (as the socket could be from a
  4055. * socketpair() or a TCP-loopback). The application is expected
  4056. * to perform read()/recv() and write()/send() calls on the socket.
  4057. * The application may also call shutdown(), but must not call
  4058. * close() directly.
  4059. * @param urh argument for #MHD_upgrade_action()s on this @a connection.
  4060. * Applications must eventually use this callback to (indirectly)
  4061. * perform the close() action on the @a sock.
  4062. */
  4063. typedef void
  4064. (*MHD_UpgradeHandler)(void *cls,
  4065. struct MHD_Connection *connection,
  4066. void *req_cls,
  4067. const char *extra_in,
  4068. size_t extra_in_size,
  4069. MHD_socket sock,
  4070. struct MHD_UpgradeResponseHandle *urh);
  4071. /**
  4072. * Create a response object that can be used for 101 UPGRADE
  4073. * responses, for example to implement WebSockets. After sending the
  4074. * response, control over the data stream is given to the callback (which
  4075. * can then, for example, start some bi-directional communication).
  4076. * If the response is queued for multiple connections, the callback
  4077. * will be called for each connection. The callback
  4078. * will ONLY be called after the response header was successfully passed
  4079. * to the OS; if there are communication errors before, the usual MHD
  4080. * connection error handling code will be performed.
  4081. *
  4082. * Setting the correct HTTP code (i.e. MHD_HTTP_SWITCHING_PROTOCOLS)
  4083. * and setting correct HTTP headers for the upgrade must be done
  4084. * manually (this way, it is possible to implement most existing
  4085. * WebSocket versions using this API; in fact, this API might be useful
  4086. * for any protocol switch, not just WebSockets). Note that
  4087. * draft-ietf-hybi-thewebsocketprotocol-00 cannot be implemented this
  4088. * way as the header "HTTP/1.1 101 WebSocket Protocol Handshake"
  4089. * cannot be generated; instead, MHD will always produce "HTTP/1.1 101
  4090. * Switching Protocols" (if the response code 101 is used).
  4091. *
  4092. * As usual, the response object can be extended with header
  4093. * information and then be used any number of times (as long as the
  4094. * header information is not connection-specific).
  4095. *
  4096. * @param upgrade_handler function to call with the "upgraded" socket
  4097. * @param upgrade_handler_cls closure for @a upgrade_handler
  4098. * @return NULL on error (i.e. invalid arguments, out of memory)
  4099. */
  4100. _MHD_EXTERN struct MHD_Response *
  4101. MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
  4102. void *upgrade_handler_cls);
  4103. /**
  4104. * Destroy a response object and associated resources. Note that
  4105. * libmicrohttpd may keep some of the resources around if the response
  4106. * is still in the queue for some clients, so the memory may not
  4107. * necessarily be freed immediately.
  4108. *
  4109. * @param response response to destroy
  4110. * @ingroup response
  4111. */
  4112. _MHD_EXTERN void
  4113. MHD_destroy_response (struct MHD_Response *response);
  4114. /**
  4115. * Add a header line to the response.
  4116. *
  4117. * When reply is generated with queued response, some headers are generated
  4118. * automatically. Automatically generated headers are only sent to the client,
  4119. * but not added back to the response object.
  4120. *
  4121. * The list of automatic headers:
  4122. * + "Date" header is added automatically unless already set by
  4123. * this function
  4124. * @see #MHD_USE_SUPPRESS_DATE_NO_CLOCK
  4125. * + "Content-Length" is added automatically when required, attempt to set
  4126. * it manually by this function is ignored.
  4127. * @see #MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
  4128. * + "Transfer-Encoding" with value "chunked" is added automatically,
  4129. * when chunked transfer encoding is used automatically. Same header with
  4130. * the same value can be set manually by this function to enforce chunked
  4131. * encoding, however for HTTP/1.0 clients chunked encoding will not be used
  4132. * and manually set "Transfer-Encoding" header is automatically removed
  4133. * for HTTP/1.0 clients
  4134. * + "Connection" may be added automatically with value "Keep-Alive" (only
  4135. * for HTTP/1.0 clients) or "Close". The header "Connection" with value
  4136. * "Close" could be set by this function to enforce closure of
  4137. * the connection after sending this response. "Keep-Alive" cannot be
  4138. * enforced and will be removed automatically.
  4139. * @see #MHD_RF_SEND_KEEP_ALIVE_HEADER
  4140. *
  4141. * Some headers are pre-processed by this function:
  4142. * * "Connection" headers are combined into single header entry, value is
  4143. * normilised, "Keep-Alive" tokens are removed.
  4144. * * "Transfer-Encoding" header: the only one header is allowed, the only
  4145. * allowed value is "chunked".
  4146. * * "Date" header: the only one header is allowed, the second added header
  4147. * replaces the first one.
  4148. * * "Content-Length" application-defined header is not allowed.
  4149. * @see #MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
  4150. *
  4151. * Headers are used in order as they were added.
  4152. *
  4153. * @param response the response to add a header to
  4154. * @param header the header name to add, no need to be static, an internal copy
  4155. * will be created automatically
  4156. * @param content the header value to add, no need to be static, an internal
  4157. * copy will be created automatically
  4158. * @return #MHD_YES on success,
  4159. * #MHD_NO on error (i.e. invalid header or content format),
  4160. * or out of memory
  4161. * @ingroup response
  4162. */
  4163. _MHD_EXTERN enum MHD_Result
  4164. MHD_add_response_header (struct MHD_Response *response,
  4165. const char *header,
  4166. const char *content);
  4167. /**
  4168. * Add a footer line to the response.
  4169. *
  4170. * @param response response to remove a header from
  4171. * @param footer the footer to delete
  4172. * @param content value to delete
  4173. * @return #MHD_NO on error (i.e. invalid footer or content format).
  4174. * @ingroup response
  4175. */
  4176. _MHD_EXTERN enum MHD_Result
  4177. MHD_add_response_footer (struct MHD_Response *response,
  4178. const char *footer,
  4179. const char *content);
  4180. /**
  4181. * Delete a header (or footer) line from the response.
  4182. *
  4183. * For "Connection" headers this function remove all tokens from existing
  4184. * value. Successful result means that at least one token has been removed.
  4185. * If all tokens are removed from "Connection" header, the empty "Connection"
  4186. * header removed.
  4187. *
  4188. * @param response response to remove a header from
  4189. * @param header the header to delete
  4190. * @param content value to delete
  4191. * @return #MHD_NO on error (no such header known)
  4192. * @ingroup response
  4193. */
  4194. _MHD_EXTERN enum MHD_Result
  4195. MHD_del_response_header (struct MHD_Response *response,
  4196. const char *header,
  4197. const char *content);
  4198. /**
  4199. * Get all of the headers (and footers) added to a response.
  4200. *
  4201. * @param response response to query
  4202. * @param iterator callback to call on each header;
  4203. * may be NULL (then just count headers)
  4204. * @param iterator_cls extra argument to @a iterator
  4205. * @return number of entries iterated over
  4206. * @ingroup response
  4207. */
  4208. _MHD_EXTERN int
  4209. MHD_get_response_headers (struct MHD_Response *response,
  4210. MHD_KeyValueIterator iterator,
  4211. void *iterator_cls);
  4212. /**
  4213. * Get a particular header (or footer) from the response.
  4214. *
  4215. * @param response response to query
  4216. * @param key which header to get
  4217. * @return NULL if header does not exist
  4218. * @ingroup response
  4219. */
  4220. _MHD_EXTERN const char *
  4221. MHD_get_response_header (struct MHD_Response *response,
  4222. const char *key);
  4223. /* ********************** PostProcessor functions ********************** */
  4224. /**
  4225. * Create a `struct MHD_PostProcessor`.
  4226. *
  4227. * A `struct MHD_PostProcessor` can be used to (incrementally) parse
  4228. * the data portion of a POST request. Note that some buggy browsers
  4229. * fail to set the encoding type. If you want to support those, you
  4230. * may have to call #MHD_set_connection_value with the proper encoding
  4231. * type before creating a post processor (if no supported encoding
  4232. * type is set, this function will fail).
  4233. *
  4234. * @param connection the connection on which the POST is
  4235. * happening (used to determine the POST format)
  4236. * @param buffer_size maximum number of bytes to use for
  4237. * internal buffering (used only for the parsing,
  4238. * specifically the parsing of the keys). A
  4239. * tiny value (256-1024) should be sufficient.
  4240. * Do NOT use a value smaller than 256. For good
  4241. * performance, use 32 or 64k (i.e. 65536).
  4242. * @param iter iterator to be called with the parsed data,
  4243. * Must NOT be NULL.
  4244. * @param iter_cls first argument to @a iter
  4245. * @return NULL on error (out of memory, unsupported encoding),
  4246. * otherwise a PP handle
  4247. * @ingroup request
  4248. */
  4249. _MHD_EXTERN struct MHD_PostProcessor *
  4250. MHD_create_post_processor (struct MHD_Connection *connection,
  4251. size_t buffer_size,
  4252. MHD_PostDataIterator iter, void *iter_cls);
  4253. /**
  4254. * Parse and process POST data. Call this function when POST data is
  4255. * available (usually during an #MHD_AccessHandlerCallback) with the
  4256. * "upload_data" and "upload_data_size". Whenever possible, this will
  4257. * then cause calls to the #MHD_PostDataIterator.
  4258. *
  4259. * @param pp the post processor
  4260. * @param post_data @a post_data_len bytes of POST data
  4261. * @param post_data_len length of @a post_data
  4262. * @return #MHD_YES on success, #MHD_NO on error
  4263. * (out-of-memory, iterator aborted, parse error)
  4264. * @ingroup request
  4265. */
  4266. _MHD_EXTERN enum MHD_Result
  4267. MHD_post_process (struct MHD_PostProcessor *pp,
  4268. const char *post_data,
  4269. size_t post_data_len);
  4270. /**
  4271. * Release PostProcessor resources.
  4272. *
  4273. * @param pp the PostProcessor to destroy
  4274. * @return #MHD_YES if processing completed nicely,
  4275. * #MHD_NO if there were spurious characters / formatting
  4276. * problems; it is common to ignore the return
  4277. * value of this function
  4278. * @ingroup request
  4279. */
  4280. _MHD_EXTERN enum MHD_Result
  4281. MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
  4282. /* ********************* Digest Authentication functions *************** */
  4283. /**
  4284. * Length of the binary output of the MD5 hash function.
  4285. * @sa #MHD_digest_get_hash_size()
  4286. * @ingroup authentication
  4287. */
  4288. #define MHD_MD5_DIGEST_SIZE 16
  4289. /**
  4290. * Length of the binary output of the SHA-256 hash function.
  4291. * @sa #MHD_digest_get_hash_size()
  4292. * @ingroup authentication
  4293. */
  4294. #define MHD_SHA256_DIGEST_SIZE 32
  4295. /**
  4296. * Length of the binary output of the SHA-512/256 hash function.
  4297. * @warning While this value is the same as the #MHD_SHA256_DIGEST_SIZE,
  4298. * the calculated digests for SHA-256 and SHA-512/256 are different.
  4299. * @sa #MHD_digest_get_hash_size()
  4300. * @note Available since #MHD_VERSION 0x00097701
  4301. * @ingroup authentication
  4302. */
  4303. #define MHD_SHA512_256_DIGEST_SIZE 32
  4304. /**
  4305. * Base type of hash calculation.
  4306. * Used as part of #MHD_DigestAuthAlgo3 values.
  4307. *
  4308. * @warning Not used directly by MHD API.
  4309. * @note Available since #MHD_VERSION 0x00097701
  4310. */
  4311. enum MHD_DigestBaseAlgo
  4312. {
  4313. /**
  4314. * Invalid hash algorithm value
  4315. */
  4316. MHD_DIGEST_BASE_ALGO_INVALID = 0,
  4317. /**
  4318. * MD5 hash algorithm.
  4319. * As specified by RFC1321
  4320. */
  4321. MHD_DIGEST_BASE_ALGO_MD5 = (1 << 0),
  4322. /**
  4323. * SHA-256 hash algorithm.
  4324. * As specified by FIPS PUB 180-4
  4325. */
  4326. MHD_DIGEST_BASE_ALGO_SHA256 = (1 << 1),
  4327. /**
  4328. * SHA-512/256 hash algorithm.
  4329. * As specified by FIPS PUB 180-4
  4330. */
  4331. MHD_DIGEST_BASE_ALGO_SHA512_256 = (1 << 2)
  4332. } _MHD_FIXED_FLAGS_ENUM;
  4333. /**
  4334. * The flag indicating non-session algorithm types,
  4335. * like 'MD5', 'SHA-256' or 'SHA-512-256'.
  4336. * @note Available since #MHD_VERSION 0x00097701
  4337. */
  4338. #define MHD_DIGEST_AUTH_ALGO3_NON_SESSION (1 << 6)
  4339. /**
  4340. * The flag indicating session algorithm types,
  4341. * like 'MD5-sess', 'SHA-256-sess' or 'SHA-512-256-sess'.
  4342. * @note Available since #MHD_VERSION 0x00097701
  4343. */
  4344. #define MHD_DIGEST_AUTH_ALGO3_SESSION (1 << 7)
  4345. /**
  4346. * Digest algorithm identification
  4347. * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
  4348. * which uses other values!
  4349. * @note Available since #MHD_VERSION 0x00097701
  4350. */
  4351. enum MHD_DigestAuthAlgo3
  4352. {
  4353. /**
  4354. * Unknown or wrong algorithm type.
  4355. * Used in struct MHD_DigestAuthInfo to indicate client value that
  4356. * cannot by identified.
  4357. */
  4358. MHD_DIGEST_AUTH_ALGO3_INVALID = 0,
  4359. /**
  4360. * The 'MD5' algorithm, non-session version.
  4361. */
  4362. MHD_DIGEST_AUTH_ALGO3_MD5 =
  4363. MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
  4364. /**
  4365. * The 'MD5-sess' algorithm.
  4366. * Not supported by MHD for authentication.
  4367. */
  4368. MHD_DIGEST_AUTH_ALGO3_MD5_SESSION =
  4369. MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO3_SESSION,
  4370. /**
  4371. * The 'SHA-256' algorithm, non-session version.
  4372. */
  4373. MHD_DIGEST_AUTH_ALGO3_SHA256 =
  4374. MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
  4375. /**
  4376. * The 'SHA-256-sess' algorithm.
  4377. * Not supported by MHD for authentication.
  4378. */
  4379. MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION =
  4380. MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO3_SESSION,
  4381. /**
  4382. * The 'SHA-512-256' (SHA-512/256) algorithm.
  4383. */
  4384. MHD_DIGEST_AUTH_ALGO3_SHA512_256 =
  4385. MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
  4386. /**
  4387. * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
  4388. * Not supported by MHD for authentication.
  4389. */
  4390. MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION =
  4391. MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO3_SESSION
  4392. };
  4393. /**
  4394. * Get digest size for specified algorithm.
  4395. *
  4396. * The size of the digest specifies the size of the userhash, userdigest
  4397. * and other parameters which size depends on used hash algorithm.
  4398. * @param algo3 the algorithm to check
  4399. * @return the size of the digest (either #MHD_MD5_DIGEST_SIZE or
  4400. * #MHD_SHA256_DIGEST_SIZE/MHD_SHA512_256_DIGEST_SIZE)
  4401. * or zero if the input value is not supported or not valid
  4402. * @sa #MHD_digest_auth_calc_userdigest()
  4403. * @sa #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_calc_userhash_hex()
  4404. * @note Available since #MHD_VERSION 0x00097701
  4405. * @ingroup authentication
  4406. */
  4407. _MHD_EXTERN size_t
  4408. MHD_digest_get_hash_size (enum MHD_DigestAuthAlgo3 algo3);
  4409. /**
  4410. * Digest algorithm identification, allow multiple selection.
  4411. *
  4412. * #MHD_DigestAuthAlgo3 always can be casted to #MHD_DigestAuthMultiAlgo3, but
  4413. * not vice versa.
  4414. *
  4415. * @note Available since #MHD_VERSION 0x00097701
  4416. */
  4417. enum MHD_DigestAuthMultiAlgo3
  4418. {
  4419. /**
  4420. * Unknown or wrong algorithm type.
  4421. */
  4422. MHD_DIGEST_AUTH_MULT_ALGO3_INVALID = MHD_DIGEST_AUTH_ALGO3_INVALID,
  4423. /**
  4424. * The 'MD5' algorithm, non-session version.
  4425. */
  4426. MHD_DIGEST_AUTH_MULT_ALGO3_MD5 = MHD_DIGEST_AUTH_ALGO3_MD5,
  4427. /**
  4428. * The 'MD5-sess' algorithm.
  4429. * Not supported by MHD for authentication.
  4430. * Reserved value.
  4431. */
  4432. MHD_DIGEST_AUTH_MULT_ALGO3_MD5_SESSION = MHD_DIGEST_AUTH_ALGO3_MD5_SESSION,
  4433. /**
  4434. * The 'SHA-256' algorithm, non-session version.
  4435. */
  4436. MHD_DIGEST_AUTH_MULT_ALGO3_SHA256 = MHD_DIGEST_AUTH_ALGO3_SHA256,
  4437. /**
  4438. * The 'SHA-256-sess' algorithm.
  4439. * Not supported by MHD for authentication.
  4440. * Reserved value.
  4441. */
  4442. MHD_DIGEST_AUTH_MULT_ALGO3_SHA256_SESSION =
  4443. MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION,
  4444. /**
  4445. * The 'SHA-512-256' (SHA-512/256) algorithm, non-session version.
  4446. */
  4447. MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256 = MHD_DIGEST_AUTH_ALGO3_SHA512_256,
  4448. /**
  4449. * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
  4450. * Not supported by MHD for authentication.
  4451. * Reserved value.
  4452. */
  4453. MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256_SESSION =
  4454. MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION,
  4455. /**
  4456. * SHA-256 or SHA-512/256 non-session algorithm, MHD will choose
  4457. * the preferred or the matching one.
  4458. */
  4459. MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_NON_SESSION =
  4460. MHD_DIGEST_AUTH_ALGO3_SHA256 | MHD_DIGEST_AUTH_ALGO3_SHA512_256,
  4461. /**
  4462. * Any non-session algorithm, MHD will choose the preferred or
  4463. * the matching one.
  4464. */
  4465. MHD_DIGEST_AUTH_MULT_ALGO3_ANY_NON_SESSION =
  4466. (0x3F) | MHD_DIGEST_AUTH_ALGO3_NON_SESSION,
  4467. /**
  4468. * The SHA-256 or SHA-512/256 session algorithm.
  4469. * Not supported by MHD.
  4470. * Reserved value.
  4471. */
  4472. MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_SESSION =
  4473. MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION
  4474. | MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION,
  4475. /**
  4476. * Any session algorithm.
  4477. * Not supported by MHD.
  4478. * Reserved value.
  4479. */
  4480. MHD_DIGEST_AUTH_MULT_ALGO3_ANY_SESSION =
  4481. (0x3F) | MHD_DIGEST_AUTH_ALGO3_SESSION,
  4482. /**
  4483. * The MD5 algorithm, session or non-session.
  4484. * Currently supported as non-session only.
  4485. */
  4486. MHD_DIGEST_AUTH_MULT_ALGO3_MD5_ANY =
  4487. MHD_DIGEST_AUTH_MULT_ALGO3_MD5 | MHD_DIGEST_AUTH_MULT_ALGO3_MD5_SESSION,
  4488. /**
  4489. * The SHA-256 algorithm, session or non-session.
  4490. * Currently supported as non-session only.
  4491. */
  4492. MHD_DIGEST_AUTH_MULT_ALGO3_SHA256_ANY =
  4493. MHD_DIGEST_AUTH_MULT_ALGO3_SHA256
  4494. | MHD_DIGEST_AUTH_MULT_ALGO3_SHA256_SESSION,
  4495. /**
  4496. * The SHA-512/256 algorithm, session or non-session.
  4497. * Currently supported as non-session only.
  4498. */
  4499. MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256_ANY =
  4500. MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256
  4501. | MHD_DIGEST_AUTH_MULT_ALGO3_SHA512_256_SESSION,
  4502. /**
  4503. * The SHA-256 or SHA-512/256 algorithm, session or non-session.
  4504. * Currently supported as non-session only.
  4505. */
  4506. MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_ANY =
  4507. MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_NON_SESSION
  4508. | MHD_DIGEST_AUTH_MULT_ALGO3_SHA_ANY_SESSION,
  4509. /**
  4510. * Any algorithm, MHD will choose the preferred or the matching one.
  4511. */
  4512. MHD_DIGEST_AUTH_MULT_ALGO3_ANY =
  4513. (0x3F) | MHD_DIGEST_AUTH_ALGO3_NON_SESSION | MHD_DIGEST_AUTH_ALGO3_SESSION
  4514. };
  4515. /**
  4516. * Calculate "userhash", return it as binary data.
  4517. *
  4518. * The "userhash" is the hash of the string "username:realm".
  4519. *
  4520. * The "userhash" could be used to avoid sending username in cleartext in Digest
  4521. * Authorization client's header.
  4522. *
  4523. * Userhash is not designed to hide the username in local database or files,
  4524. * as username in cleartext is required for #MHD_digest_auth_check3() function
  4525. * to check the response, but it can be used to hide username in HTTP headers.
  4526. *
  4527. * This function could be used when the new username is added to the username
  4528. * database to save the "userhash" alongside with the username (preferably) or
  4529. * when loading list of the usernames to generate the userhash for every loaded
  4530. * username (this will cause delays at the start with the long lists).
  4531. *
  4532. * Once "userhash" is generated it could be used to identify users by clients
  4533. * with "userhash" support.
  4534. * Avoid repetitive usage of this function for the same username/realm
  4535. * combination as it will cause excessive CPU load; save and re-use the result
  4536. * instead.
  4537. *
  4538. * @param algo3 the algorithm for userhash calculations
  4539. * @param username the username
  4540. * @param realm the realm
  4541. * @param[out] userhash_bin the output buffer for userhash as binary data;
  4542. * if this function succeeds, then this buffer has
  4543. * #MHD_digest_get_hash_size(algo3) bytes of userhash
  4544. * upon return
  4545. * @param bin_buf_size the size of the @a userhash_bin buffer, must be
  4546. * at least #MHD_digest_get_hash_size(algo3) bytes long
  4547. * @return MHD_YES on success,
  4548. * MHD_NO if @a bin_buf_size is too small or if @a algo3 algorithm is
  4549. * not supported (or external error has occurred,
  4550. * see #MHD_FEATURE_EXTERN_HASH)
  4551. * @sa #MHD_digest_auth_calc_userhash_hex()
  4552. * @note Available since #MHD_VERSION 0x00097701
  4553. * @ingroup authentication
  4554. */
  4555. _MHD_EXTERN enum MHD_Result
  4556. MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo3 algo3,
  4557. const char *username,
  4558. const char *realm,
  4559. void *userhash_bin,
  4560. size_t bin_buf_size);
  4561. /**
  4562. * Calculate "userhash", return it as hexadecimal string.
  4563. *
  4564. * The "userhash" is the hash of the string "username:realm".
  4565. *
  4566. * The "userhash" could be used to avoid sending username in cleartext in Digest
  4567. * Authorization client's header.
  4568. *
  4569. * Userhash is not designed to hide the username in local database or files,
  4570. * as username in cleartext is required for #MHD_digest_auth_check3() function
  4571. * to check the response, but it can be used to hide username in HTTP headers.
  4572. *
  4573. * This function could be used when the new username is added to the username
  4574. * database to save the "userhash" alongside with the username (preferably) or
  4575. * when loading list of the usernames to generate the userhash for every loaded
  4576. * username (this will cause delays at the start with the long lists).
  4577. *
  4578. * Once "userhash" is generated it could be used to identify users by clients
  4579. * with "userhash" support.
  4580. * Avoid repetitive usage of this function for the same username/realm
  4581. * combination as it will cause excessive CPU load; save and re-use the result
  4582. * instead.
  4583. *
  4584. * @param algo3 the algorithm for userhash calculations
  4585. * @param username the username
  4586. * @param realm the realm
  4587. * @param[out] userhash_hex the output buffer for userhash as hex string;
  4588. * if this function succeeds, then this buffer has
  4589. * #MHD_digest_get_hash_size(algo3)*2 chars long
  4590. * userhash zero-terminated string
  4591. * @param bin_buf_size the size of the @a userhash_bin buffer, must be
  4592. * at least #MHD_digest_get_hash_size(algo3)*2+1 chars long
  4593. * @return MHD_YES on success,
  4594. * MHD_NO if @a bin_buf_size is too small or if @a algo3 algorithm is
  4595. * not supported (or external error has occurred,
  4596. * see #MHD_FEATURE_EXTERN_HASH).
  4597. * @sa #MHD_digest_auth_calc_userhash()
  4598. * @note Available since #MHD_VERSION 0x00097701
  4599. * @ingroup authentication
  4600. */
  4601. _MHD_EXTERN enum MHD_Result
  4602. MHD_digest_auth_calc_userhash_hex (enum MHD_DigestAuthAlgo3 algo3,
  4603. const char *username,
  4604. const char *realm,
  4605. char *userhash_hex,
  4606. size_t hex_buf_size);
  4607. /**
  4608. * The type of username used by client in Digest Authorization header
  4609. *
  4610. * Values are sorted so simplified checks could be used.
  4611. * For example:
  4612. * * (value <= MHD_DIGEST_AUTH_UNAME_TYPE_INVALID) is true if no valid username
  4613. * is provided by the client
  4614. * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH) is true if username is
  4615. * provided in any form
  4616. * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD) is true if username is
  4617. * provided in clear text (no userhash matching is needed)
  4618. *
  4619. * @note Available since #MHD_VERSION 0x00097701
  4620. */
  4621. enum MHD_DigestAuthUsernameType
  4622. {
  4623. /**
  4624. * No username parameter in in Digest Authorization header.
  4625. * This should be treated as an error.
  4626. */
  4627. MHD_DIGEST_AUTH_UNAME_TYPE_MISSING = 0,
  4628. /**
  4629. * The 'username' parameter is used to specify the username.
  4630. */
  4631. MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD = (1 << 2),
  4632. /**
  4633. * The username is specified by 'username*' parameter with
  4634. * the extended notation (see RFC 5987 #section-3.2.1).
  4635. * The only difference between standard and extended types is
  4636. * the way how username value is encoded in the header.
  4637. */
  4638. MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED = (1 << 3),
  4639. /**
  4640. * The username provided in form of 'userhash' as
  4641. * specified by RFC 7616 #section-3.4.4.
  4642. * @sa #MHD_digest_auth_calc_userhash_hex(), #MHD_digest_auth_calc_userhash()
  4643. */
  4644. MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH = (1 << 1),
  4645. /**
  4646. * The invalid combination of username parameters are used by client.
  4647. * Either:
  4648. * * both 'username' and 'username*' are used
  4649. * * 'username*' is used with 'userhash=true'
  4650. * * 'username*' used with invalid extended notation
  4651. * * 'username' is not hexadecimal string, while 'userhash' set to 'true'
  4652. */
  4653. MHD_DIGEST_AUTH_UNAME_TYPE_INVALID = (1 << 0)
  4654. } _MHD_FIXED_ENUM;
  4655. /**
  4656. * The QOP ('quality of protection') types.
  4657. * @note Available since #MHD_VERSION 0x00097701
  4658. */
  4659. enum MHD_DigestAuthQOP
  4660. {
  4661. /**
  4662. * Invalid/unknown QOP.
  4663. * Used in struct MHD_DigestAuthInfo to indicate client value that
  4664. * cannot by identified.
  4665. */
  4666. MHD_DIGEST_AUTH_QOP_INVALID = 0,
  4667. /**
  4668. * No QOP parameter.
  4669. * As described in old RFC 2069 original specification.
  4670. * This mode is not allowed by latest RFCs and should be used only to
  4671. * communicate with clients that do not support more modern modes (with QOP
  4672. * parameter).
  4673. * This mode is less secure than other modes and inefficient.
  4674. */
  4675. MHD_DIGEST_AUTH_QOP_NONE = 1 << 0,
  4676. /**
  4677. * The 'auth' QOP type.
  4678. */
  4679. MHD_DIGEST_AUTH_QOP_AUTH = 1 << 1,
  4680. /**
  4681. * The 'auth-int' QOP type.
  4682. * Not supported by MHD for authentication.
  4683. */
  4684. MHD_DIGEST_AUTH_QOP_AUTH_INT = 1 << 2
  4685. } _MHD_FIXED_FLAGS_ENUM;
  4686. /**
  4687. * The QOP ('quality of protection') types, multiple selection.
  4688. *
  4689. * #MHD_DigestAuthQOP always can be casted to #MHD_DigestAuthMultiQOP, but
  4690. * not vice versa.
  4691. *
  4692. * @note Available since #MHD_VERSION 0x00097701
  4693. */
  4694. enum MHD_DigestAuthMultiQOP
  4695. {
  4696. /**
  4697. * Invalid/unknown QOP.
  4698. */
  4699. MHD_DIGEST_AUTH_MULT_QOP_INVALID = MHD_DIGEST_AUTH_QOP_INVALID,
  4700. /**
  4701. * No QOP parameter.
  4702. * As described in old RFC 2069 original specification.
  4703. * This mode is not allowed by latest RFCs and should be used only to
  4704. * communicate with clients that do not support more modern modes (with QOP
  4705. * parameter).
  4706. * This mode is less secure than other modes and inefficient.
  4707. */
  4708. MHD_DIGEST_AUTH_MULT_QOP_NONE = MHD_DIGEST_AUTH_QOP_NONE,
  4709. /**
  4710. * The 'auth' QOP type.
  4711. */
  4712. MHD_DIGEST_AUTH_MULT_QOP_AUTH = MHD_DIGEST_AUTH_QOP_AUTH,
  4713. /**
  4714. * The 'auth-int' QOP type.
  4715. * Not supported by MHD.
  4716. * Reserved value.
  4717. */
  4718. MHD_DIGEST_AUTH_MULT_QOP_AUTH_INT = MHD_DIGEST_AUTH_QOP_AUTH_INT,
  4719. /**
  4720. * The 'auth' QOP type OR the old RFC2069 (no QOP) type.
  4721. * In other words: any types except 'auth-int'.
  4722. * RFC2069-compatible mode is allowed, thus this value should be used only
  4723. * when it is really necessary.
  4724. */
  4725. MHD_DIGEST_AUTH_MULT_QOP_ANY_NON_INT =
  4726. MHD_DIGEST_AUTH_QOP_NONE | MHD_DIGEST_AUTH_QOP_AUTH,
  4727. /**
  4728. * Any 'auth' QOP type ('auth' or 'auth-int').
  4729. * Currently supported as 'auth' QOP type only.
  4730. */
  4731. MHD_DIGEST_AUTH_MULT_QOP_AUTH_ANY =
  4732. MHD_DIGEST_AUTH_QOP_AUTH | MHD_DIGEST_AUTH_QOP_AUTH_INT
  4733. } _MHD_FIXED_ENUM;
  4734. /**
  4735. * The invalid value of 'nc' parameter in client Digest Authorization header.
  4736. * @note Available since #MHD_VERSION 0x00097701
  4737. */
  4738. #define MHD_DIGEST_AUTH_INVALID_NC_VALUE (0)
  4739. /**
  4740. * Information from Digest Authorization client's header.
  4741. *
  4742. * All buffers pointed by any struct members are freed when #MHD_free() is
  4743. * called for pointer to this structure.
  4744. *
  4745. * Application may modify buffers as needed until #MHD_free() is called for
  4746. * pointer to this structure
  4747. * @note Available since #MHD_VERSION 0x00097701
  4748. */
  4749. struct MHD_DigestAuthInfo
  4750. {
  4751. /**
  4752. * The algorithm as defined by client.
  4753. * Set automatically to MD5 if not specified by client.
  4754. * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
  4755. * which uses other values!
  4756. */
  4757. enum MHD_DigestAuthAlgo3 algo3;
  4758. /**
  4759. * The type of username used by client.
  4760. */
  4761. enum MHD_DigestAuthUsernameType uname_type;
  4762. /**
  4763. * The username string.
  4764. * Used only if username type is standard or extended, always NULL otherwise.
  4765. * If extended notation is used, this string is pct-decoded string
  4766. * with charset and language tag removed (i.e. it is original username
  4767. * extracted from the extended notation).
  4768. * When userhash is used by the client, this member is NULL and
  4769. * @a userhash_hex and @a userhash_bin are set.
  4770. * The buffer pointed by the @a username becomes invalid when the pointer
  4771. * to the structure is freed by #MHD_free().
  4772. */
  4773. char *username;
  4774. /**
  4775. * The length of the @a username.
  4776. * When the @a username is NULL, this member is always zero.
  4777. */
  4778. size_t username_len;
  4779. /**
  4780. * The userhash string.
  4781. * Valid only if username type is userhash.
  4782. * This is unqoted string without decoding of the hexadecimal
  4783. * digits (as provided by the client).
  4784. * The buffer pointed by the @a userhash_hex becomes invalid when the pointer
  4785. * to the structure is freed by #MHD_free().
  4786. * @sa #MHD_digest_auth_calc_userhash_hex()
  4787. */
  4788. char *userhash_hex;
  4789. /**
  4790. * The length of the @a userhash_hex in characters.
  4791. * The valid size should be #MHD_digest_get_hash_size(algo3) * 2 characters.
  4792. * When the @a userhash_hex is NULL, this member is always zero.
  4793. */
  4794. size_t userhash_hex_len;
  4795. /**
  4796. * The userhash decoded to binary form.
  4797. * Used only if username type is userhash, always NULL otherwise.
  4798. * When not NULL, this points to binary sequence @a userhash_hex_len /2 bytes
  4799. * long.
  4800. * The valid size should be #MHD_digest_get_hash_size(algo3) bytes.
  4801. * The buffer pointed by the @a userhash_bin becomes invalid when the pointer
  4802. * to the structure is freed by #MHD_free().
  4803. * @warning This is a binary data, no zero termination.
  4804. * @warning To avoid buffer overruns, always check the size of the data before
  4805. * use, because @a userhash_bin can point even to zero-sized
  4806. * data.
  4807. * @sa #MHD_digest_auth_calc_userhash()
  4808. */
  4809. uint8_t *userhash_bin;
  4810. /**
  4811. * The 'opaque' parameter value, as specified by client.
  4812. * NULL if not specified by client.
  4813. * The buffer pointed by the @a opaque becomes invalid when the pointer
  4814. * to the structure is freed by #MHD_free().
  4815. */
  4816. char *opaque;
  4817. /**
  4818. * The length of the @a opaque.
  4819. * When the @a opaque is NULL, this member is always zero.
  4820. */
  4821. size_t opaque_len;
  4822. /**
  4823. * The 'realm' parameter value, as specified by client.
  4824. * NULL if not specified by client.
  4825. * The buffer pointed by the @a realm becomes invalid when the pointer
  4826. * to the structure is freed by #MHD_free().
  4827. */
  4828. char *realm;
  4829. /**
  4830. * The length of the @a realm.
  4831. * When the @a realm is NULL, this member is always zero.
  4832. */
  4833. size_t realm_len;
  4834. /**
  4835. * The 'qop' parameter value.
  4836. */
  4837. enum MHD_DigestAuthQOP qop;
  4838. /**
  4839. * The length of the 'cnonce' parameter value, including possible
  4840. * backslash-escape characters.
  4841. * 'cnonce' is used in hash calculation, which is CPU-intensive procedure.
  4842. * An application may want to reject too large cnonces to limit the CPU load.
  4843. * A few kilobytes is a reasonable limit, typically cnonce is just 32-160
  4844. * characters long.
  4845. */
  4846. size_t cnonce_len;
  4847. /**
  4848. * The nc parameter value.
  4849. * Can be used by application to limit the number of nonce re-uses. If @a nc
  4850. * is higher than application wants to allow, then "auth required" response
  4851. * with 'stale=true' could be used to force client to retry with the fresh
  4852. * 'nonce'.
  4853. * If not specified by client or does not have hexadecimal digits only, the
  4854. * value is #MHD_DIGEST_AUTH_INVALID_NC_VALUE.
  4855. */
  4856. uint32_t nc;
  4857. };
  4858. /**
  4859. * Get information about Digest Authorization client's header.
  4860. *
  4861. * @param connection The MHD connection structure
  4862. * @return NULL if no valid Digest Authorization header is used in the request;
  4863. * a pointer to the structure with information if the valid request
  4864. * header found, free using #MHD_free().
  4865. * @sa #MHD_digest_auth_get_username3()
  4866. * @note Available since #MHD_VERSION 0x00097701
  4867. * @ingroup authentication
  4868. */
  4869. _MHD_EXTERN struct MHD_DigestAuthInfo *
  4870. MHD_digest_auth_get_request_info3 (struct MHD_Connection *connection);
  4871. /**
  4872. * Information from Digest Authorization client's header.
  4873. *
  4874. * All buffers pointed by any struct members are freed when #MHD_free() is
  4875. * called for pointer to this structure.
  4876. *
  4877. * Application may modify buffers as needed until #MHD_free() is called for
  4878. * pointer to this structure
  4879. * @note Available since #MHD_VERSION 0x00097701
  4880. */
  4881. struct MHD_DigestAuthUsernameInfo
  4882. {
  4883. /**
  4884. * The algorithm as defined by client.
  4885. * Set automatically to MD5 if not specified by client.
  4886. * @warning Do not be confused with #MHD_DigestAuthAlgorithm,
  4887. * which uses other values!
  4888. */
  4889. enum MHD_DigestAuthAlgo3 algo3;
  4890. /**
  4891. * The type of username used by client.
  4892. * The 'invalid' and 'missing' types are not used in this structure,
  4893. * instead NULL is returned by #MHD_digest_auth_get_username3().
  4894. */
  4895. enum MHD_DigestAuthUsernameType uname_type;
  4896. /**
  4897. * The username string.
  4898. * Used only if username type is standard or extended, always NULL otherwise.
  4899. * If extended notation is used, this string is pct-decoded string
  4900. * with charset and language tag removed (i.e. it is original username
  4901. * extracted from the extended notation).
  4902. * When userhash is used by the client, this member is NULL and
  4903. * @a userhash_hex and @a userhash_bin are set.
  4904. * The buffer pointed by the @a username becomes invalid when the pointer
  4905. * to the structure is freed by #MHD_free().
  4906. */
  4907. char *username;
  4908. /**
  4909. * The length of the @a username.
  4910. * When the @a username is NULL, this member is always zero.
  4911. */
  4912. size_t username_len;
  4913. /**
  4914. * The userhash string.
  4915. * Valid only if username type is userhash.
  4916. * This is unqoted string without decoding of the hexadecimal
  4917. * digits (as provided by the client).
  4918. * The buffer pointed by the @a userhash_hex becomes invalid when the pointer
  4919. * to the structure is freed by #MHD_free().
  4920. * @sa #MHD_digest_auth_calc_userhash_hex()
  4921. */
  4922. char *userhash_hex;
  4923. /**
  4924. * The length of the @a userhash_hex in characters.
  4925. * The valid size should be #MHD_digest_get_hash_size(algo3) * 2 characters.
  4926. * When the @a userhash_hex is NULL, this member is always zero.
  4927. */
  4928. size_t userhash_hex_len;
  4929. /**
  4930. * The userhash decoded to binary form.
  4931. * Used only if username type is userhash, always NULL otherwise.
  4932. * When not NULL, this points to binary sequence @a userhash_hex_len /2 bytes
  4933. * long.
  4934. * The valid size should be #MHD_digest_get_hash_size(algo3) bytes.
  4935. * The buffer pointed by the @a userhash_bin becomes invalid when the pointer
  4936. * to the structure is freed by #MHD_free().
  4937. * @warning This is a binary data, no zero termination.
  4938. * @warning To avoid buffer overruns, always check the size of the data before
  4939. * use, because @a userhash_bin can point even to zero-sized
  4940. * data.
  4941. * @sa #MHD_digest_auth_calc_userhash()
  4942. */
  4943. uint8_t *userhash_bin;
  4944. };
  4945. /**
  4946. * Get the username from Digest Authorization client's header.
  4947. *
  4948. * @param connection The MHD connection structure
  4949. * @return NULL if no valid Digest Authorization header is used in the request,
  4950. * or no username parameter is present in the header, or username is
  4951. * provided incorrectly by client (see description for
  4952. * #MHD_DIGEST_AUTH_UNAME_TYPE_INVALID);
  4953. * a pointer structure with information if the valid request header
  4954. * found, free using #MHD_free().
  4955. * @sa #MHD_digest_auth_get_request_info3() provides more complete information
  4956. * @note Available since #MHD_VERSION 0x00097701
  4957. * @ingroup authentication
  4958. */
  4959. _MHD_EXTERN struct MHD_DigestAuthUsernameInfo *
  4960. MHD_digest_auth_get_username3 (struct MHD_Connection *connection);
  4961. /**
  4962. * The result of digest authentication of the client.
  4963. *
  4964. * All error values are zero or negative.
  4965. *
  4966. * @note Available since #MHD_VERSION 0x00097701
  4967. */
  4968. enum MHD_DigestAuthResult
  4969. {
  4970. /**
  4971. * Authentication OK.
  4972. */
  4973. MHD_DAUTH_OK = 1,
  4974. /**
  4975. * General error, like "out of memory".
  4976. */
  4977. MHD_DAUTH_ERROR = 0,
  4978. /**
  4979. * No "Authorization" header or wrong format of the header.
  4980. * Also may be returned if required parameters in client Authorisation header
  4981. * are missing or broken (in invalid format).
  4982. */
  4983. MHD_DAUTH_WRONG_HEADER = -1,
  4984. /**
  4985. * Wrong 'username'.
  4986. */
  4987. MHD_DAUTH_WRONG_USERNAME = -2,
  4988. /**
  4989. * Wrong 'realm'.
  4990. */
  4991. MHD_DAUTH_WRONG_REALM = -3,
  4992. /**
  4993. * Wrong 'URI' (or URI parameters).
  4994. */
  4995. MHD_DAUTH_WRONG_URI = -4,
  4996. /**
  4997. * Wrong 'qop'.
  4998. */
  4999. MHD_DAUTH_WRONG_QOP = -5,
  5000. /**
  5001. * Wrong 'algorithm'.
  5002. */
  5003. MHD_DAUTH_WRONG_ALGO = -6,
  5004. /**
  5005. * Too large (>64 KiB) Authorization parameter value.
  5006. */
  5007. MHD_DAUTH_TOO_LARGE = -15,
  5008. /* The different form of naming is intentionally used for the results below,
  5009. * as they are more important */
  5010. /**
  5011. * The 'nonce' is too old. Suggest the client to retry with the same
  5012. * username and password to get the fresh 'nonce'.
  5013. * The validity of the 'nonce' may be not checked.
  5014. */
  5015. MHD_DAUTH_NONCE_STALE = -17,
  5016. /**
  5017. * The 'nonce' was generated by MHD for other conditions.
  5018. * This value is only returned if #MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE
  5019. * is set to anything other than #MHD_DAUTH_BIND_NONCE_NONE.
  5020. * The interpretation of this code could be different. For example, if
  5021. * #MHD_DAUTH_BIND_NONCE_URI is set and client just used the same 'nonce' for
  5022. * another URI, the code could be handled as #MHD_DAUTH_NONCE_STALE as
  5023. * RFCs allow nonces re-using for other URIs in the same "protection
  5024. * space". However, if only #MHD_DAUTH_BIND_NONCE_CLIENT_IP bit is set and
  5025. * it is know that clients have fixed IP addresses, this return code could
  5026. * be handled like #MHD_DAUTH_NONCE_WRONG.
  5027. */
  5028. MHD_DAUTH_NONCE_OTHER_COND = -18,
  5029. /**
  5030. * The 'nonce' is wrong. May indicate an attack attempt.
  5031. */
  5032. MHD_DAUTH_NONCE_WRONG = -33,
  5033. /**
  5034. * The 'response' is wrong. Typically it means that wrong password used.
  5035. * May indicate an attack attempt.
  5036. */
  5037. MHD_DAUTH_RESPONSE_WRONG = -34
  5038. };
  5039. /**
  5040. * Authenticates the authorization header sent by the client.
  5041. *
  5042. * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
  5043. * @a mqop and the client uses this mode, then server generated nonces are
  5044. * used as one-time nonces because nonce-count is not supported in this old RFC.
  5045. * Communication in this mode is very inefficient, especially if the client
  5046. * requests several resources one-by-one as for every request a new nonce must
  5047. * be generated and client repeats all requests twice (first time to get a new
  5048. * nonce and second time to perform an authorised request).
  5049. *
  5050. * @param connection the MHD connection structure
  5051. * @param realm the realm for authorization of the client
  5052. * @param username the username to be authenticated, must be in clear text
  5053. * even if userhash is used by the client
  5054. * @param password the password matching the @a username (and the @a realm)
  5055. * @param nonce_timeout the period of seconds since nonce generation, when
  5056. * the nonce is recognised as valid and not stale;
  5057. * if zero is specified then daemon default value is used.
  5058. * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
  5059. * exceeds the specified value then MHD_DAUTH_NONCE_STALE is
  5060. * returned;
  5061. * if zero is specified then daemon default value is used.
  5062. * @param mqop the QOP to use
  5063. * @param malgo3 digest algorithms allowed to use, fail if algorithm used
  5064. * by the client is not allowed by this parameter
  5065. * @return #MHD_DAUTH_OK if authenticated,
  5066. * the error code otherwise
  5067. * @note Available since #MHD_VERSION 0x00097708
  5068. * @ingroup authentication
  5069. */
  5070. _MHD_EXTERN enum MHD_DigestAuthResult
  5071. MHD_digest_auth_check3 (struct MHD_Connection *connection,
  5072. const char *realm,
  5073. const char *username,
  5074. const char *password,
  5075. unsigned int nonce_timeout,
  5076. uint32_t max_nc,
  5077. enum MHD_DigestAuthMultiQOP mqop,
  5078. enum MHD_DigestAuthMultiAlgo3 malgo3);
  5079. /**
  5080. * Calculate userdigest, return it as a binary data.
  5081. *
  5082. * The "userdigest" is the hash of the "username:realm:password" string.
  5083. *
  5084. * The "userdigest" can be used to avoid storing the password in clear text
  5085. * in database/files
  5086. *
  5087. * This function is designed to improve security of stored credentials,
  5088. * the "userdigest" does not improve security of the authentication process.
  5089. *
  5090. * The results can be used to store username & userdigest pairs instead of
  5091. * username & password pairs. To further improve security, application may
  5092. * store username & userhash & userdigest triplets.
  5093. *
  5094. * @param algo3 the digest algorithm
  5095. * @param username the username
  5096. * @param realm the realm
  5097. * @param password the password
  5098. * @param[out] userdigest_bin the output buffer for userdigest;
  5099. * if this function succeeds, then this buffer has
  5100. * #MHD_digest_get_hash_size(algo3) bytes of
  5101. * userdigest upon return
  5102. * @param bin_buf_size the size of the @a userdigest_bin buffer, must be
  5103. * at least #MHD_digest_get_hash_size(algo3) bytes long
  5104. * @return MHD_YES on success,
  5105. * MHD_NO if @a userdigest_bin is too small or if @a algo3 algorithm is
  5106. * not supported (or external error has occurred,
  5107. * see #MHD_FEATURE_EXTERN_HASH).
  5108. * @sa #MHD_digest_auth_check_digest3()
  5109. * @note Available since #MHD_VERSION 0x00097701
  5110. * @ingroup authentication
  5111. */
  5112. _MHD_EXTERN enum MHD_Result
  5113. MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo3 algo3,
  5114. const char *username,
  5115. const char *realm,
  5116. const char *password,
  5117. void *userdigest_bin,
  5118. size_t bin_buf_size);
  5119. /**
  5120. * Authenticates the authorization header sent by the client by using
  5121. * hash of "username:realm:password".
  5122. *
  5123. * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
  5124. * @a mqop and the client uses this mode, then server generated nonces are
  5125. * used as one-time nonces because nonce-count is not supported in this old RFC.
  5126. * Communication in this mode is very inefficient, especially if the client
  5127. * requests several resources one-by-one as for every request a new nonce must
  5128. * be generated and client repeats all requests twice (first time to get a new
  5129. * nonce and second time to perform an authorised request).
  5130. *
  5131. * @param connection the MHD connection structure
  5132. * @param realm the realm for authorization of the client
  5133. * @param username the username to be authenticated, must be in clear text
  5134. * even if userhash is used by the client
  5135. * @param userdigest the precalculated binary hash of the string
  5136. * "username:realm:password",
  5137. * see #MHD_digest_auth_calc_userdigest()
  5138. * @param userdigest_size the size of the @a userdigest in bytes, must match the
  5139. * hashing algorithm (see #MHD_MD5_DIGEST_SIZE,
  5140. * #MHD_SHA256_DIGEST_SIZE, #MHD_SHA512_256_DIGEST_SIZE,
  5141. * #MHD_digest_get_hash_size())
  5142. * @param nonce_timeout the period of seconds since nonce generation, when
  5143. * the nonce is recognised as valid and not stale;
  5144. * if zero is specified then daemon default value is used.
  5145. * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
  5146. * exceeds the specified value then MHD_DAUTH_NONCE_STALE is
  5147. * returned;
  5148. * if zero is specified then daemon default value is used.
  5149. * @param mqop the QOP to use
  5150. * @param malgo3 digest algorithms allowed to use, fail if algorithm used
  5151. * by the client is not allowed by this parameter;
  5152. * more than one base algorithms (MD5, SHA-256, SHA-512/256)
  5153. * cannot be used at the same time for this function
  5154. * as @a userdigest must match specified algorithm
  5155. * @return #MHD_DAUTH_OK if authenticated,
  5156. * the error code otherwise
  5157. * @sa #MHD_digest_auth_calc_userdigest()
  5158. * @note Available since #MHD_VERSION 0x00097701
  5159. * @ingroup authentication
  5160. */
  5161. _MHD_EXTERN enum MHD_DigestAuthResult
  5162. MHD_digest_auth_check_digest3 (struct MHD_Connection *connection,
  5163. const char *realm,
  5164. const char *username,
  5165. const void *userdigest,
  5166. size_t userdigest_size,
  5167. unsigned int nonce_timeout,
  5168. uint32_t max_nc,
  5169. enum MHD_DigestAuthMultiQOP mqop,
  5170. enum MHD_DigestAuthMultiAlgo3 malgo3);
  5171. /**
  5172. * Queues a response to request authentication from the client
  5173. *
  5174. * This function modifies provided @a response. The @a response must not be
  5175. * reused and should be destroyed (by #MHD_destroy_response()) after call of
  5176. * this function.
  5177. *
  5178. * If @a mqop allows both RFC 2069 (MHD_DIGEST_AUTH_QOP_NONE) and QOP with
  5179. * value, then response is formed like if MHD_DIGEST_AUTH_QOP_NONE bit was
  5180. * not set, because such response should be backward-compatible with RFC 2069.
  5181. *
  5182. * If @a mqop allows only MHD_DIGEST_AUTH_MULT_QOP_NONE, then the response is
  5183. * formed in strict accordance with RFC 2069 (no 'qop', no 'userhash', no
  5184. * 'charset'). For better compatibility with clients, it is recommended (but
  5185. * not required) to set @a domain to NULL in this mode.
  5186. *
  5187. * @param connection the MHD connection structure
  5188. * @param realm the realm presented to the client
  5189. * @param opaque the string for opaque value, can be NULL, but NULL is
  5190. * not recommended for better compatibility with clients;
  5191. * the recommended format is hex or Base64 encoded string
  5192. * @param domain the optional space-separated list of URIs for which the
  5193. * same authorisation could be used, URIs can be in form
  5194. * "path-absolute" (the path for the same host with initial slash)
  5195. * or in form "absolute-URI" (the full path with protocol), in
  5196. * any case client may assume that URI is in the same "protection
  5197. * space" if it starts with any of values specified here;
  5198. * could be NULL (clients typically assume that the same
  5199. * credentials could be used for any URI on the same host);
  5200. * this list provides information for the client only and does
  5201. * not actually restrict anything on the server side
  5202. * @param response the reply to send; should contain the "access denied"
  5203. * body;
  5204. * note: this function sets the "WWW Authenticate" header and
  5205. * the caller should not set this header;
  5206. * the NULL is tolerated
  5207. * @param signal_stale if set to #MHD_YES then indication of stale nonce used in
  5208. * the client's request is signalled by adding 'stale=true'
  5209. * to the authentication header, this instructs the client
  5210. * to retry immediately with the new nonce and the same
  5211. * credentials, without asking user for the new password
  5212. * @param mqop the QOP to use
  5213. * @param malgo3 digest algorithm to use; if several algorithms are allowed
  5214. * then MD5 is preferred (currently, may be changed in next
  5215. * versions)
  5216. * @param userhash_support if set to non-zero value (#MHD_YES) then support of
  5217. * userhash is indicated, allowing client to provide
  5218. * hash("username:realm") instead of the username in
  5219. * clear text;
  5220. * note that clients are allowed to provide the username
  5221. * in cleartext even if this parameter set to non-zero;
  5222. * when userhash is used, application must be ready to
  5223. * identify users by provided userhash value instead of
  5224. * username; see #MHD_digest_auth_calc_userhash() and
  5225. * #MHD_digest_auth_calc_userhash_hex()
  5226. * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is
  5227. * added, indicating for the client that UTF-8 encoding for
  5228. * the username is preferred
  5229. * @return #MHD_YES on success, #MHD_NO otherwise
  5230. * @note Available since #MHD_VERSION 0x00097701
  5231. * @ingroup authentication
  5232. */
  5233. _MHD_EXTERN enum MHD_Result
  5234. MHD_queue_auth_required_response3 (struct MHD_Connection *connection,
  5235. const char *realm,
  5236. const char *opaque,
  5237. const char *domain,
  5238. struct MHD_Response *response,
  5239. int signal_stale,
  5240. enum MHD_DigestAuthMultiQOP mqop,
  5241. enum MHD_DigestAuthMultiAlgo3 algo,
  5242. int userhash_support,
  5243. int prefer_utf8);
  5244. /**
  5245. * Constant to indicate that the nonce of the provided
  5246. * authentication code was wrong.
  5247. * Used as return code by #MHD_digest_auth_check(), #MHD_digest_auth_check2(),
  5248. * #MHD_digest_auth_check_digest(), #MHD_digest_auth_check_digest2().
  5249. * @ingroup authentication
  5250. */
  5251. #define MHD_INVALID_NONCE -1
  5252. /**
  5253. * Get the username from the authorization header sent by the client
  5254. *
  5255. * This function supports username in standard and extended notations.
  5256. * "userhash" is not supported by this function.
  5257. *
  5258. * @param connection The MHD connection structure
  5259. * @return NULL if no username could be found, username provided as
  5260. * "userhash", extended notation broken or memory allocation error
  5261. * occurs;
  5262. * a pointer to the username if found, free using #MHD_free().
  5263. * @warning Returned value must be freed by #MHD_free().
  5264. * @sa #MHD_digest_auth_get_username3()
  5265. * @ingroup authentication
  5266. */
  5267. _MHD_EXTERN char *
  5268. MHD_digest_auth_get_username (struct MHD_Connection *connection);
  5269. /**
  5270. * Which digest algorithm should MHD use for HTTP digest authentication?
  5271. * Used as parameter for #MHD_digest_auth_check2(),
  5272. * #MHD_digest_auth_check_digest2(), #MHD_queue_auth_fail_response2().
  5273. */
  5274. enum MHD_DigestAuthAlgorithm
  5275. {
  5276. /**
  5277. * MHD should pick (currently defaults to MD5).
  5278. */
  5279. MHD_DIGEST_ALG_AUTO = 0,
  5280. /**
  5281. * Force use of MD5.
  5282. */
  5283. MHD_DIGEST_ALG_MD5,
  5284. /**
  5285. * Force use of SHA-256.
  5286. */
  5287. MHD_DIGEST_ALG_SHA256
  5288. } _MHD_FIXED_ENUM;
  5289. /**
  5290. * Authenticates the authorization header sent by the client.
  5291. *
  5292. * @param connection The MHD connection structure
  5293. * @param realm The realm presented to the client
  5294. * @param username The username needs to be authenticated
  5295. * @param password The password used in the authentication
  5296. * @param nonce_timeout The amount of time for a nonce to be
  5297. * invalid in seconds
  5298. * @param algo digest algorithms allowed for verification
  5299. * @return #MHD_YES if authenticated, #MHD_NO if not,
  5300. * #MHD_INVALID_NONCE if nonce is invalid or stale
  5301. * @note Available since #MHD_VERSION 0x00096200
  5302. * @deprecated use MHD_digest_auth_check3()
  5303. * @ingroup authentication
  5304. */
  5305. _MHD_EXTERN int
  5306. MHD_digest_auth_check2 (struct MHD_Connection *connection,
  5307. const char *realm,
  5308. const char *username,
  5309. const char *password,
  5310. unsigned int nonce_timeout,
  5311. enum MHD_DigestAuthAlgorithm algo);
  5312. /**
  5313. * Authenticates the authorization header sent by the client.
  5314. * Uses #MHD_DIGEST_ALG_MD5 (for now, for backwards-compatibility).
  5315. * Note that this MAY change to #MHD_DIGEST_ALG_AUTO in the future.
  5316. * If you want to be sure you get MD5, use #MHD_digest_auth_check2()
  5317. * and specify MD5 explicitly.
  5318. *
  5319. * @param connection The MHD connection structure
  5320. * @param realm The realm presented to the client
  5321. * @param username The username needs to be authenticated
  5322. * @param password The password used in the authentication
  5323. * @param nonce_timeout The amount of time for a nonce to be
  5324. * invalid in seconds
  5325. * @return #MHD_YES if authenticated, #MHD_NO if not,
  5326. * #MHD_INVALID_NONCE if nonce is invalid or stale
  5327. * @deprecated use MHD_digest_auth_check3()
  5328. * @ingroup authentication
  5329. */
  5330. _MHD_EXTERN int
  5331. MHD_digest_auth_check (struct MHD_Connection *connection,
  5332. const char *realm,
  5333. const char *username,
  5334. const char *password,
  5335. unsigned int nonce_timeout);
  5336. /**
  5337. * Authenticates the authorization header sent by the client.
  5338. *
  5339. * @param connection The MHD connection structure
  5340. * @param realm The realm presented to the client
  5341. * @param username The username needs to be authenticated
  5342. * @param digest An `unsigned char *' pointer to the binary MD5 sum
  5343. * for the precalculated hash value "username:realm:password"
  5344. * of @a digest_size bytes
  5345. * @param digest_size number of bytes in @a digest (size must match @a algo!)
  5346. * @param nonce_timeout The amount of time for a nonce to be
  5347. * invalid in seconds
  5348. * @param algo digest algorithms allowed for verification
  5349. * @return #MHD_YES if authenticated, #MHD_NO if not,
  5350. * #MHD_INVALID_NONCE if nonce is invalid or stale
  5351. * @note Available since #MHD_VERSION 0x00096200
  5352. * @deprecated use MHD_digest_auth_check_digest3()
  5353. * @ingroup authentication
  5354. */
  5355. _MHD_EXTERN int
  5356. MHD_digest_auth_check_digest2 (struct MHD_Connection *connection,
  5357. const char *realm,
  5358. const char *username,
  5359. const uint8_t *digest,
  5360. size_t digest_size,
  5361. unsigned int nonce_timeout,
  5362. enum MHD_DigestAuthAlgorithm algo);
  5363. /**
  5364. * Authenticates the authorization header sent by the client
  5365. * Uses #MHD_DIGEST_ALG_MD5 (required, as @a digest is of fixed
  5366. * size).
  5367. *
  5368. * @param connection The MHD connection structure
  5369. * @param realm The realm presented to the client
  5370. * @param username The username needs to be authenticated
  5371. * @param digest An `unsigned char *' pointer to the binary hash
  5372. * for the precalculated hash value "username:realm:password";
  5373. * length must be #MHD_MD5_DIGEST_SIZE bytes
  5374. * @param nonce_timeout The amount of time for a nonce to be
  5375. * invalid in seconds
  5376. * @return #MHD_YES if authenticated, #MHD_NO if not,
  5377. * #MHD_INVALID_NONCE if nonce is invalid or stale
  5378. * @note Available since #MHD_VERSION 0x00096000
  5379. * @deprecated use #MHD_digest_auth_check_digest3()
  5380. * @ingroup authentication
  5381. */
  5382. _MHD_EXTERN int
  5383. MHD_digest_auth_check_digest (struct MHD_Connection *connection,
  5384. const char *realm,
  5385. const char *username,
  5386. const uint8_t digest[MHD_MD5_DIGEST_SIZE],
  5387. unsigned int nonce_timeout);
  5388. /**
  5389. * Queues a response to request authentication from the client
  5390. *
  5391. * This function modifies provided @a response. The @a response must not be
  5392. * reused and should be destroyed after call of this function.
  5393. *
  5394. * @param connection The MHD connection structure
  5395. * @param realm the realm presented to the client
  5396. * @param opaque string to user for opaque value
  5397. * @param response reply to send; should contain the "access denied"
  5398. * body; note that this function will set the "WWW Authenticate"
  5399. * header and that the caller should not do this; the NULL is tolerated
  5400. * @param signal_stale #MHD_YES if the nonce is stale to add
  5401. * 'stale=true' to the authentication header
  5402. * @param algo digest algorithm to use
  5403. * @return #MHD_YES on success, #MHD_NO otherwise
  5404. * @note Available since #MHD_VERSION 0x00096200
  5405. * @deprecated use MHD_queue_auth_required_response3()
  5406. * @ingroup authentication
  5407. */
  5408. _MHD_EXTERN enum MHD_Result
  5409. MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
  5410. const char *realm,
  5411. const char *opaque,
  5412. struct MHD_Response *response,
  5413. int signal_stale,
  5414. enum MHD_DigestAuthAlgorithm algo);
  5415. /**
  5416. * Queues a response to request authentication from the client.
  5417. * For now uses MD5 (for backwards-compatibility). Still, if you
  5418. * need to be sure, use #MHD_queue_auth_fail_response2().
  5419. *
  5420. * This function modifies provided @a response. The @a response must not be
  5421. * reused and should be destroyed after call of this function.
  5422. *
  5423. * @param connection The MHD connection structure
  5424. * @param realm the realm presented to the client
  5425. * @param opaque string to user for opaque value
  5426. * @param response reply to send; should contain the "access denied"
  5427. * body; note that this function will set the "WWW Authenticate"
  5428. * header and that the caller should not do this; the NULL is tolerated
  5429. * @param signal_stale #MHD_YES if the nonce is stale to add
  5430. * 'stale=true' to the authentication header
  5431. * @return #MHD_YES on success, #MHD_NO otherwise
  5432. * @deprecated use MHD_queue_auth_required_response3()
  5433. * @ingroup authentication
  5434. */
  5435. _MHD_EXTERN enum MHD_Result
  5436. MHD_queue_auth_fail_response (struct MHD_Connection *connection,
  5437. const char *realm,
  5438. const char *opaque,
  5439. struct MHD_Response *response,
  5440. int signal_stale);
  5441. /* ********************* Basic Authentication functions *************** */
  5442. /**
  5443. * Information decoded from Basic Authentication client's header.
  5444. *
  5445. * The username and the password are technically allowed to have binary zeros,
  5446. * username_len and password_len could be used to detect such situations.
  5447. *
  5448. * The buffers pointed by username and password members are freed
  5449. * when #MHD_free() is called for pointer to this structure.
  5450. *
  5451. * Application may modify buffers as needed until #MHD_free() is called for
  5452. * pointer to this structure
  5453. */
  5454. struct MHD_BasicAuthInfo
  5455. {
  5456. /**
  5457. * The username, cannot be NULL.
  5458. * The buffer pointed by the @a username becomes invalid when the pointer
  5459. * to the structure is freed by #MHD_free().
  5460. */
  5461. char *username;
  5462. /**
  5463. * The length of the @a username, not including zero-termination
  5464. */
  5465. size_t username_len;
  5466. /**
  5467. * The password, may be NULL if password is not encoded by the client.
  5468. * The buffer pointed by the @a password becomes invalid when the pointer
  5469. * to the structure is freed by #MHD_free().
  5470. */
  5471. char *password;
  5472. /**
  5473. * The length of the @a password, not including zero-termination;
  5474. * when the @a password is NULL, the length is always zero.
  5475. */
  5476. size_t password_len;
  5477. };
  5478. /**
  5479. * Get the username and password from the Basic Authorisation header
  5480. * sent by the client
  5481. *
  5482. * @param connection the MHD connection structure
  5483. * @return NULL if no valid Basic Authentication header is present in
  5484. * current request, or
  5485. * pointer to structure with username and password, which must be
  5486. * freed by #MHD_free().
  5487. * @note Available since #MHD_VERSION 0x00097701
  5488. * @ingroup authentication
  5489. */
  5490. _MHD_EXTERN struct MHD_BasicAuthInfo *
  5491. MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection);
  5492. /**
  5493. * Queues a response to request basic authentication from the client.
  5494. *
  5495. * The given response object is expected to include the payload for
  5496. * the response; the "WWW-Authenticate" header will be added and the
  5497. * response queued with the 'UNAUTHORIZED' status code.
  5498. *
  5499. * See RFC 7617#section-2 for details.
  5500. *
  5501. * The @a response is modified by this function. The modified response object
  5502. * can be used to respond subsequent requests by #MHD_queue_response()
  5503. * function with status code #MHD_HTTP_UNAUTHORIZED and must not be used again
  5504. * with MHD_queue_basic_auth_required_response3() function. The response could
  5505. * be destroyed right after call of this function.
  5506. *
  5507. * @param connection the MHD connection structure
  5508. * @param realm the realm presented to the client
  5509. * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
  5510. * be added, indicating for client that UTF-8 encoding
  5511. * is preferred
  5512. * @param response the response object to modify and queue; the NULL
  5513. * is tolerated
  5514. * @return #MHD_YES on success, #MHD_NO otherwise
  5515. * @note Available since #MHD_VERSION 0x00097704
  5516. * @ingroup authentication
  5517. */
  5518. _MHD_EXTERN enum MHD_Result
  5519. MHD_queue_basic_auth_required_response3 (struct MHD_Connection *connection,
  5520. const char *realm,
  5521. int prefer_utf8,
  5522. struct MHD_Response *response);
  5523. /**
  5524. * Get the username and password from the basic authorization header sent by the client
  5525. *
  5526. * @param connection The MHD connection structure
  5527. * @param[out] password a pointer for the password, free using #MHD_free().
  5528. * @return NULL if no username could be found, a pointer
  5529. * to the username if found, free using #MHD_free().
  5530. * @deprecated use #MHD_basic_auth_get_username_password3()
  5531. * @ingroup authentication
  5532. */
  5533. _MHD_EXTERN char *
  5534. MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
  5535. char **password);
  5536. /**
  5537. * Queues a response to request basic authentication from the client
  5538. * The given response object is expected to include the payload for
  5539. * the response; the "WWW-Authenticate" header will be added and the
  5540. * response queued with the 'UNAUTHORIZED' status code.
  5541. *
  5542. * @param connection The MHD connection structure
  5543. * @param realm the realm presented to the client
  5544. * @param response response object to modify and queue; the NULL is tolerated
  5545. * @return #MHD_YES on success, #MHD_NO otherwise
  5546. * @deprecated use MHD_queue_basic_auth_required_response3()
  5547. * @ingroup authentication
  5548. */
  5549. _MHD_EXTERN enum MHD_Result
  5550. MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
  5551. const char *realm,
  5552. struct MHD_Response *response);
  5553. /* ********************** generic query functions ********************** */
  5554. /**
  5555. * Obtain information about the given connection.
  5556. * The returned pointer is invalidated with the next call of this function or
  5557. * when the connection is closed.
  5558. *
  5559. * @param connection what connection to get information about
  5560. * @param info_type what information is desired?
  5561. * @param ... depends on @a info_type
  5562. * @return NULL if this information is not available
  5563. * (or if the @a info_type is unknown)
  5564. * @ingroup specialized
  5565. */
  5566. _MHD_EXTERN const union MHD_ConnectionInfo *
  5567. MHD_get_connection_info (struct MHD_Connection *connection,
  5568. enum MHD_ConnectionInfoType info_type,
  5569. ...);
  5570. /**
  5571. * MHD connection options. Given to #MHD_set_connection_option to
  5572. * set custom options for a particular connection.
  5573. */
  5574. enum MHD_CONNECTION_OPTION
  5575. {
  5576. /**
  5577. * Set a custom timeout for the given connection. Specified
  5578. * as the number of seconds, given as an `unsigned int`. Use
  5579. * zero for no timeout.
  5580. * If timeout was set to zero (or unset) before, setup of new value by
  5581. * MHD_set_connection_option() will reset timeout timer.
  5582. * Values larger than (UINT64_MAX / 2000 - 1) will
  5583. * be clipped to this number.
  5584. */
  5585. MHD_CONNECTION_OPTION_TIMEOUT
  5586. } _MHD_FIXED_ENUM;
  5587. /**
  5588. * Set a custom option for the given connection, overriding defaults.
  5589. *
  5590. * @param connection connection to modify
  5591. * @param option option to set
  5592. * @param ... arguments to the option, depending on the option type
  5593. * @return #MHD_YES on success, #MHD_NO if setting the option failed
  5594. * @ingroup specialized
  5595. */
  5596. _MHD_EXTERN enum MHD_Result
  5597. MHD_set_connection_option (struct MHD_Connection *connection,
  5598. enum MHD_CONNECTION_OPTION option,
  5599. ...);
  5600. /**
  5601. * Information about an MHD daemon.
  5602. */
  5603. union MHD_DaemonInfo
  5604. {
  5605. /**
  5606. * Size of the key, no longer supported.
  5607. * @deprecated
  5608. */
  5609. size_t key_size;
  5610. /**
  5611. * Size of the mac key, no longer supported.
  5612. * @deprecated
  5613. */
  5614. size_t mac_key_size;
  5615. /**
  5616. * Socket, returned for #MHD_DAEMON_INFO_LISTEN_FD.
  5617. */
  5618. MHD_socket listen_fd;
  5619. /**
  5620. * Bind port number, returned for #MHD_DAEMON_INFO_BIND_PORT.
  5621. */
  5622. uint16_t port;
  5623. /**
  5624. * epoll FD, returned for #MHD_DAEMON_INFO_EPOLL_FD.
  5625. */
  5626. int epoll_fd;
  5627. /**
  5628. * Number of active connections, for #MHD_DAEMON_INFO_CURRENT_CONNECTIONS.
  5629. */
  5630. unsigned int num_connections;
  5631. /**
  5632. * Combination of #MHD_FLAG values, for #MHD_DAEMON_INFO_FLAGS.
  5633. * This value is actually a bitfield.
  5634. * Note: flags may differ from original 'flags' specified for
  5635. * daemon, especially if #MHD_USE_AUTO was set.
  5636. */
  5637. enum MHD_FLAG flags;
  5638. };
  5639. /**
  5640. * Obtain information about the given daemon.
  5641. * The returned pointer is invalidated with the next call of this function or
  5642. * when the daemon is stopped.
  5643. *
  5644. * @param daemon what daemon to get information about
  5645. * @param info_type what information is desired?
  5646. * @param ... depends on @a info_type
  5647. * @return NULL if this information is not available
  5648. * (or if the @a info_type is unknown)
  5649. * @ingroup specialized
  5650. */
  5651. _MHD_EXTERN const union MHD_DaemonInfo *
  5652. MHD_get_daemon_info (struct MHD_Daemon *daemon,
  5653. enum MHD_DaemonInfoType info_type,
  5654. ...);
  5655. /**
  5656. * Obtain the version of this library
  5657. *
  5658. * @return static version string, e.g. "0.9.9"
  5659. * @ingroup specialized
  5660. */
  5661. _MHD_EXTERN const char *
  5662. MHD_get_version (void);
  5663. /**
  5664. * Obtain the version of this library as a binary value.
  5665. *
  5666. * @return version binary value, e.g. "0x00090900" (#MHD_VERSION of
  5667. * compiled MHD binary)
  5668. * @note Available since #MHD_VERSION 0x00097601
  5669. * @ingroup specialized
  5670. */
  5671. _MHD_EXTERN uint32_t
  5672. MHD_get_version_bin (void);
  5673. /**
  5674. * Types of information about MHD features,
  5675. * used by #MHD_is_feature_supported().
  5676. */
  5677. enum MHD_FEATURE
  5678. {
  5679. /**
  5680. * Get whether messages are supported. If supported then in debug
  5681. * mode messages can be printed to stderr or to external logger.
  5682. */
  5683. MHD_FEATURE_MESSAGES = 1,
  5684. /**
  5685. * Get whether HTTPS is supported. If supported then flag
  5686. * #MHD_USE_TLS and options #MHD_OPTION_HTTPS_MEM_KEY,
  5687. * #MHD_OPTION_HTTPS_MEM_CERT, #MHD_OPTION_HTTPS_MEM_TRUST,
  5688. * #MHD_OPTION_HTTPS_MEM_DHPARAMS, #MHD_OPTION_HTTPS_CRED_TYPE,
  5689. * #MHD_OPTION_HTTPS_PRIORITIES can be used.
  5690. */
  5691. MHD_FEATURE_TLS = 2,
  5692. MHD_FEATURE_SSL = 2,
  5693. /**
  5694. * Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is
  5695. * supported.
  5696. */
  5697. MHD_FEATURE_HTTPS_CERT_CALLBACK = 3,
  5698. /**
  5699. * Get whether IPv6 is supported. If supported then flag
  5700. * #MHD_USE_IPv6 can be used.
  5701. */
  5702. MHD_FEATURE_IPv6 = 4,
  5703. /**
  5704. * Get whether IPv6 without IPv4 is supported. If not supported
  5705. * then IPv4 is always enabled in IPv6 sockets and
  5706. * flag #MHD_USE_DUAL_STACK is always used when #MHD_USE_IPv6 is
  5707. * specified.
  5708. */
  5709. MHD_FEATURE_IPv6_ONLY = 5,
  5710. /**
  5711. * Get whether `poll()` is supported. If supported then flag
  5712. * #MHD_USE_POLL can be used.
  5713. */
  5714. MHD_FEATURE_POLL = 6,
  5715. /**
  5716. * Get whether `epoll()` is supported. If supported then Flags
  5717. * #MHD_USE_EPOLL and
  5718. * #MHD_USE_EPOLL_INTERNAL_THREAD can be used.
  5719. */
  5720. MHD_FEATURE_EPOLL = 7,
  5721. /**
  5722. * Get whether shutdown on listen socket to signal other
  5723. * threads is supported. If not supported flag
  5724. * #MHD_USE_ITC is automatically forced.
  5725. */
  5726. MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET = 8,
  5727. /**
  5728. * Get whether socketpair is used internally instead of pipe to
  5729. * signal other threads.
  5730. */
  5731. MHD_FEATURE_SOCKETPAIR = 9,
  5732. /**
  5733. * Get whether TCP Fast Open is supported. If supported then
  5734. * flag #MHD_USE_TCP_FASTOPEN and option
  5735. * #MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used.
  5736. */
  5737. MHD_FEATURE_TCP_FASTOPEN = 10,
  5738. /**
  5739. * Get whether HTTP Basic authorization is supported. If supported
  5740. * then functions #MHD_basic_auth_get_username_password and
  5741. * #MHD_queue_basic_auth_fail_response can be used.
  5742. */
  5743. MHD_FEATURE_BASIC_AUTH = 11,
  5744. /**
  5745. * Get whether HTTP Digest authorization is supported. If
  5746. * supported then options #MHD_OPTION_DIGEST_AUTH_RANDOM,
  5747. * #MHD_OPTION_NONCE_NC_SIZE and
  5748. * #MHD_digest_auth_check() can be used.
  5749. */
  5750. MHD_FEATURE_DIGEST_AUTH = 12,
  5751. /**
  5752. * Get whether postprocessor is supported. If supported then
  5753. * functions #MHD_create_post_processor(), #MHD_post_process() and
  5754. * #MHD_destroy_post_processor() can
  5755. * be used.
  5756. */
  5757. MHD_FEATURE_POSTPROCESSOR = 13,
  5758. /**
  5759. * Get whether password encrypted private key for HTTPS daemon is
  5760. * supported. If supported then option
  5761. * ::MHD_OPTION_HTTPS_KEY_PASSWORD can be used.
  5762. */
  5763. MHD_FEATURE_HTTPS_KEY_PASSWORD = 14,
  5764. /**
  5765. * Get whether reading files beyond 2 GiB boundary is supported.
  5766. * If supported then #MHD_create_response_from_fd(),
  5767. * #MHD_create_response_from_fd64 #MHD_create_response_from_fd_at_offset()
  5768. * and #MHD_create_response_from_fd_at_offset64() can be used with sizes and
  5769. * offsets larger than 2 GiB. If not supported value of size+offset is
  5770. * limited to 2 GiB.
  5771. */
  5772. MHD_FEATURE_LARGE_FILE = 15,
  5773. /**
  5774. * Get whether MHD set names on generated threads.
  5775. */
  5776. MHD_FEATURE_THREAD_NAMES = 16,
  5777. MHD_THREAD_NAMES = 16,
  5778. /**
  5779. * Get whether HTTP "Upgrade" is supported.
  5780. * If supported then #MHD_ALLOW_UPGRADE, #MHD_upgrade_action() and
  5781. * #MHD_create_response_for_upgrade() can be used.
  5782. */
  5783. MHD_FEATURE_UPGRADE = 17,
  5784. /**
  5785. * Get whether it's safe to use same FD for multiple calls of
  5786. * #MHD_create_response_from_fd() and whether it's safe to use single
  5787. * response generated by #MHD_create_response_from_fd() with multiple
  5788. * connections at same time.
  5789. * If #MHD_is_feature_supported() return #MHD_NO for this feature then
  5790. * usage of responses with same file FD in multiple parallel threads may
  5791. * results in incorrect data sent to remote client.
  5792. * It's always safe to use same file FD in multiple responses if MHD
  5793. * is run in any single thread mode.
  5794. */
  5795. MHD_FEATURE_RESPONSES_SHARED_FD = 18,
  5796. /**
  5797. * Get whether MHD support automatic detection of bind port number.
  5798. * @sa #MHD_DAEMON_INFO_BIND_PORT
  5799. */
  5800. MHD_FEATURE_AUTODETECT_BIND_PORT = 19,
  5801. /**
  5802. * Get whether MHD supports automatic SIGPIPE suppression.
  5803. * If SIGPIPE suppression is not supported, application must handle
  5804. * SIGPIPE signal by itself.
  5805. */
  5806. MHD_FEATURE_AUTOSUPPRESS_SIGPIPE = 20,
  5807. /**
  5808. * Get whether MHD use system's sendfile() function to send
  5809. * file-FD based responses over non-TLS connections.
  5810. * @note Since v0.9.56
  5811. */
  5812. MHD_FEATURE_SENDFILE = 21,
  5813. /**
  5814. * Get whether MHD supports threads.
  5815. */
  5816. MHD_FEATURE_THREADS = 22,
  5817. /**
  5818. * Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK2 is
  5819. * supported.
  5820. */
  5821. MHD_FEATURE_HTTPS_CERT_CALLBACK2 = 23,
  5822. /**
  5823. * Get whether automatic parsing of HTTP Cookie header is supported.
  5824. * If disabled, no MHD_COOKIE_KIND will be generated by MHD.
  5825. * MHD versions before 0x00097701 always support cookie parsing.
  5826. * @note Available since #MHD_VERSION 0x00097701
  5827. */
  5828. MHD_FEATURE_HTTPS_COOKIE_PARSING = 24,
  5829. /**
  5830. * Get whether the early version the Digest Authorization (RFC 2069) is
  5831. * supported (digest authorisation without QOP parameter).
  5832. * Since #MHD_VERSION 0x00097701 it is always supported if Digest Auth
  5833. * module is built.
  5834. * @note Available since #MHD_VERSION 0x00097701
  5835. */
  5836. MHD_FEATURE_DIGEST_AUTH_RFC2069 = 25,
  5837. /**
  5838. * Get whether the MD5-based hashing algorithms are supported for Digest
  5839. * Authorization.
  5840. * Currently it is always supported if Digest Auth module is built
  5841. * unless manually disabled in a custom build.
  5842. * @note Available since #MHD_VERSION 0x00097701
  5843. */
  5844. MHD_FEATURE_DIGEST_AUTH_MD5 = 26,
  5845. /**
  5846. * Get whether the SHA-256-based hashing algorithms are supported for Digest
  5847. * Authorization.
  5848. * It is always supported since #MHD_VERSION 0x00096200 if Digest Auth
  5849. * module is built unless manually disabled in a custom build.
  5850. * @note Available since #MHD_VERSION 0x00097701
  5851. */
  5852. MHD_FEATURE_DIGEST_AUTH_SHA256 = 27,
  5853. /**
  5854. * Get whether the SHA-512/256-based hashing algorithms are supported
  5855. * for Digest Authorization.
  5856. * It it always supported since #MHD_VERSION 0x00097701 if Digest Auth
  5857. * module is built unless manually disabled in a custom build.
  5858. * @note Available since #MHD_VERSION 0x00097701
  5859. */
  5860. MHD_FEATURE_DIGEST_AUTH_SHA512_256 = 28,
  5861. /**
  5862. * Get whether QOP with value 'auth-int' (authentication with integrity
  5863. * protection) is supported for Digest Authorization.
  5864. * Currently it is always not supported.
  5865. * @note Available since #MHD_VERSION 0x00097701
  5866. */
  5867. MHD_FEATURE_DIGEST_AUTH_AUTH_INT = 29,
  5868. /**
  5869. * Get whether 'session' algorithms (like 'MD5-sess') are supported for Digest
  5870. * Authorization.
  5871. * Currently it is always not supported.
  5872. * @note Available since #MHD_VERSION 0x00097701
  5873. */
  5874. MHD_FEATURE_DIGEST_AUTH_ALGO_SESSION = 30,
  5875. /**
  5876. * Get whether 'userhash' is supported for Digest Authorization.
  5877. * It is always supported since #MHD_VERSION 0x00097701 if Digest Auth
  5878. * module is built.
  5879. * @note Available since #MHD_VERSION 0x00097701
  5880. */
  5881. MHD_FEATURE_DIGEST_AUTH_USERHASH = 31,
  5882. /**
  5883. * Get whether any of hashing algorithms is implemented by external
  5884. * function (like TLS library) and may fail due to external conditions,
  5885. * like "out-of-memory".
  5886. *
  5887. * If result is #MHD_YES then functions which use hash calculations
  5888. * like #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_check3() and others
  5889. * potentially may fail even with valid input because of out-of-memory error
  5890. * or crypto accelerator device failure, however in practice such fails are
  5891. * unlikely.
  5892. * @note Available since #MHD_VERSION 0x00097701
  5893. */
  5894. MHD_FEATURE_EXTERN_HASH = 32,
  5895. /**
  5896. * Get whether MHD was built with asserts enabled.
  5897. * For debug builds the error log is always enabled even if #MHD_USE_ERROR_LOG
  5898. * is not specified for daemon.
  5899. * @note Available since #MHD_VERSION 0x00097701
  5900. */
  5901. MHD_FEATURE_DEBUG_BUILD = 33,
  5902. /**
  5903. * Get whether MHD was build with support for overridable FD_SETSIZE.
  5904. * This feature should be always available when the relevant platform ability
  5905. * is detected.
  5906. * @sa #MHD_OPTION_APP_FD_SETSIZE
  5907. * @note Available since #MHD_VERSION 0x00097705
  5908. */
  5909. MHD_FEATURE_FLEXIBLE_FD_SETSIZE = 34
  5910. };
  5911. /**
  5912. * Get information about supported MHD features.
  5913. * Indicate that MHD was compiled with or without support for
  5914. * particular feature. Some features require additional support
  5915. * by kernel. Kernel support is not checked by this function.
  5916. *
  5917. * @param feature type of requested information
  5918. * @return #MHD_YES if feature is supported by MHD, #MHD_NO if
  5919. * feature is not supported or feature is unknown.
  5920. * @ingroup specialized
  5921. */
  5922. _MHD_EXTERN enum MHD_Result
  5923. MHD_is_feature_supported (enum MHD_FEATURE feature);
  5924. #ifdef __cplusplus
  5925. #if 0 /* keep Emacsens' auto-indent happy */
  5926. {
  5927. #endif
  5928. }
  5929. #endif
  5930. #endif